kindeditor-all.js 402 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2013 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.10 (2013-11-23)
  9. *******************************************************************************/
  10. (function (window, undefined) {
  11. if (window.KindEditor) {
  12. return;
  13. }
  14. if (!window.console) {
  15. window.console = {};
  16. }
  17. if (!console.log) {
  18. console.log = function () { };
  19. }
  20. var _VERSION = '4.1.10 (2013-11-23)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  24. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  25. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  26. _OPERA = _ua.indexOf('opera') > -1,
  27. _MOBILE = _ua.indexOf('mobile') > -1,
  28. _IOS = /ipad|iphone|ipod/.test(_ua),
  29. _QUIRKS = document.compatMode != 'CSS1Compat',
  30. _IERANGE = !window.getSelection,
  31. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  32. _V = _matches ? _matches[1] : '0',
  33. _TIME = new Date().getTime();
  34. function _isArray(val) {
  35. if (!val) {
  36. return false;
  37. }
  38. return Object.prototype.toString.call(val) === '[object Array]';
  39. }
  40. function _isFunction(val) {
  41. if (!val) {
  42. return false;
  43. }
  44. return Object.prototype.toString.call(val) === '[object Function]';
  45. }
  46. function _inArray(val, arr) {
  47. for (var i = 0, len = arr.length; i < len; i++) {
  48. if (val === arr[i]) {
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. function _each(obj, fn) {
  55. if (_isArray(obj)) {
  56. for (var i = 0, len = obj.length; i < len; i++) {
  57. if (fn.call(obj[i], i, obj[i]) === false) {
  58. break;
  59. }
  60. }
  61. } else {
  62. for (var key in obj) {
  63. if (obj.hasOwnProperty(key)) {
  64. if (fn.call(obj[key], key, obj[key]) === false) {
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. function _trim(str) {
  72. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  73. }
  74. function _inString(val, str, delimiter) {
  75. delimiter = delimiter === undefined ? ',' : delimiter;
  76. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  77. }
  78. function _addUnit(val, unit) {
  79. unit = unit || 'px';
  80. return val && /^\d+$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function (key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function ($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function (key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10) ; i <= parseInt(match[2], 10) ; i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () { };
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function (key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG: false,
  180. VERSION: _VERSION,
  181. IE: _IE,
  182. GECKO: _GECKO,
  183. WEBKIT: _WEBKIT,
  184. OPERA: _OPERA,
  185. V: _V,
  186. TIME: _TIME,
  187. each: _each,
  188. isArray: _isArray,
  189. isFunction: _isFunction,
  190. inArray: _inArray,
  191. inString: _inString,
  192. trim: _trim,
  193. addUnit: _addUnit,
  194. removeUnit: _removeUnit,
  195. escape: _escape,
  196. unescape: _unescape,
  197. toCamel: _toCamel,
  198. toHex: _toHex,
  199. toMap: _toMap,
  200. toArray: _toArray,
  201. undef: _undef,
  202. invalidUrl: _invalidUrl,
  203. addParam: _addParam,
  204. extend: _extend,
  205. json: _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. designMode: true,
  230. fullscreenMode: false,
  231. filterMode: true,
  232. wellFormatMode: true,
  233. shadowMode: true,
  234. loadStyleMode: true,
  235. basePath: K.basePath,
  236. themesPath: K.basePath + 'themes/',
  237. langPath: K.basePath + 'lang/',
  238. pluginsPath: K.basePath + 'plugins/',
  239. themeType: 'default',
  240. langType: 'zh_CN',
  241. urlType: '',
  242. newlineTag: 'p',
  243. resizeType: 2,
  244. syncType: 'form',
  245. pasteType: 2,
  246. dialogAlignType: 'page',
  247. useContextmenu: true,
  248. fullscreenShortcut: false,
  249. bodyClass: 'ke-content',
  250. indentChar: '\t',
  251. cssPath: '',
  252. cssData: '',
  253. minWidth: 650,
  254. minHeight: 100,
  255. minChangeSize: 50,
  256. zIndex: 811213,
  257. items: [
  258. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  259. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  260. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  261. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  262. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  263. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  264. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  265. 'anchor', 'link', 'unlink', '|', 'about'
  266. ],
  267. noDisableItems: ['source', 'fullscreen'],
  268. colorTable: [
  269. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  270. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  271. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  272. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  273. ],
  274. fontSizeTable: ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  275. htmlTags: {
  276. font: ['id', 'class', 'color', 'size', 'face', '.background-color'],
  277. span: [
  278. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  279. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  280. ],
  281. div: [
  282. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  283. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  284. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  285. ],
  286. table: [
  287. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  288. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  289. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  290. '.width', '.height', '.border-collapse'
  291. ],
  292. 'td,th': [
  293. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  294. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  295. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  296. ],
  297. a: ['id', 'class', 'href', 'target', 'name'],
  298. embed: ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  299. img: ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  300. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6': [
  301. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  302. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  303. ],
  304. pre: ['id', 'class'],
  305. hr: ['id', 'class', '.page-break-after'],
  306. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del': ['id', 'class'],
  307. iframe: ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  308. },
  309. layout: '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  310. };
  311. var _useCapture = false;
  312. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  313. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  314. var _CHANGE_KEY_MAP = {};
  315. _each(_INPUT_KEY_MAP, function (key, val) {
  316. _CHANGE_KEY_MAP[key] = val;
  317. });
  318. _each(_CURSORMOVE_KEY_MAP, function (key, val) {
  319. _CHANGE_KEY_MAP[key] = val;
  320. });
  321. function _bindEvent(el, type, fn) {
  322. if (el.addEventListener) {
  323. el.addEventListener(type, fn, _useCapture);
  324. } else if (el.attachEvent) {
  325. el.attachEvent('on' + type, fn);
  326. }
  327. }
  328. function _unbindEvent(el, type, fn) {
  329. if (el.removeEventListener) {
  330. el.removeEventListener(type, fn, _useCapture);
  331. } else if (el.detachEvent) {
  332. el.detachEvent('on' + type, fn);
  333. }
  334. }
  335. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  336. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  337. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  338. function KEvent(el, event) {
  339. this.init(el, event);
  340. }
  341. _extend(KEvent, {
  342. init: function (el, event) {
  343. var self = this, doc = el.ownerDocument || el.document || el;
  344. self.event = event;
  345. _each(_EVENT_PROPS, function (key, val) {
  346. self[val] = event[val];
  347. });
  348. if (!self.target) {
  349. self.target = self.srcElement || doc;
  350. }
  351. if (self.target.nodeType === 3) {
  352. self.target = self.target.parentNode;
  353. }
  354. if (!self.relatedTarget && self.fromElement) {
  355. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  356. }
  357. if (self.pageX == null && self.clientX != null) {
  358. var d = doc.documentElement, body = doc.body;
  359. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  360. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  361. }
  362. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  363. self.which = self.charCode || self.keyCode;
  364. }
  365. if (!self.metaKey && self.ctrlKey) {
  366. self.metaKey = self.ctrlKey;
  367. }
  368. if (!self.which && self.button !== undefined) {
  369. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  370. }
  371. switch (self.which) {
  372. case 186:
  373. self.which = 59;
  374. break;
  375. case 187:
  376. case 107:
  377. case 43:
  378. self.which = 61;
  379. break;
  380. case 189:
  381. case 45:
  382. self.which = 109;
  383. break;
  384. case 42:
  385. self.which = 106;
  386. break;
  387. case 47:
  388. self.which = 111;
  389. break;
  390. case 78:
  391. self.which = 110;
  392. break;
  393. }
  394. if (self.which >= 96 && self.which <= 105) {
  395. self.which -= 48;
  396. }
  397. },
  398. preventDefault: function () {
  399. var ev = this.event;
  400. if (ev.preventDefault) {
  401. ev.preventDefault();
  402. } else {
  403. ev.returnValue = false;
  404. }
  405. },
  406. stopPropagation: function () {
  407. var ev = this.event;
  408. if (ev.stopPropagation) {
  409. ev.stopPropagation();
  410. } else {
  411. ev.cancelBubble = true;
  412. }
  413. },
  414. stop: function () {
  415. this.preventDefault();
  416. this.stopPropagation();
  417. }
  418. });
  419. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  420. function _getId(el) {
  421. return el[_eventExpendo] || null;
  422. }
  423. function _setId(el) {
  424. el[_eventExpendo] = ++_eventId;
  425. return _eventId;
  426. }
  427. function _removeId(el) {
  428. try {
  429. delete el[_eventExpendo];
  430. } catch (e) {
  431. if (el.removeAttribute) {
  432. el.removeAttribute(_eventExpendo);
  433. }
  434. }
  435. }
  436. function _bind(el, type, fn) {
  437. if (type.indexOf(',') >= 0) {
  438. _each(type.split(','), function () {
  439. _bind(el, this, fn);
  440. });
  441. return;
  442. }
  443. var id = _getId(el);
  444. if (!id) {
  445. id = _setId(el);
  446. }
  447. if (_eventData[id] === undefined) {
  448. _eventData[id] = {};
  449. }
  450. var events = _eventData[id][type];
  451. if (events && events.length > 0) {
  452. _unbindEvent(el, type, events[0]);
  453. } else {
  454. _eventData[id][type] = [];
  455. _eventData[id].el = el;
  456. }
  457. events = _eventData[id][type];
  458. if (events.length === 0) {
  459. events[0] = function (e) {
  460. var kevent = e ? new KEvent(el, e) : undefined;
  461. _each(events, function (i, event) {
  462. if (i > 0 && event) {
  463. event.call(el, kevent);
  464. }
  465. });
  466. };
  467. }
  468. if (_inArray(fn, events) < 0) {
  469. events.push(fn);
  470. }
  471. _bindEvent(el, type, events[0]);
  472. }
  473. function _unbind(el, type, fn) {
  474. if (type && type.indexOf(',') >= 0) {
  475. _each(type.split(','), function () {
  476. _unbind(el, this, fn);
  477. });
  478. return;
  479. }
  480. var id = _getId(el);
  481. if (!id) {
  482. return;
  483. }
  484. if (type === undefined) {
  485. if (id in _eventData) {
  486. _each(_eventData[id], function (key, events) {
  487. if (key != 'el' && events.length > 0) {
  488. _unbindEvent(el, key, events[0]);
  489. }
  490. });
  491. delete _eventData[id];
  492. _removeId(el);
  493. }
  494. return;
  495. }
  496. if (!_eventData[id]) {
  497. return;
  498. }
  499. var events = _eventData[id][type];
  500. if (events && events.length > 0) {
  501. if (fn === undefined) {
  502. _unbindEvent(el, type, events[0]);
  503. delete _eventData[id][type];
  504. } else {
  505. _each(events, function (i, event) {
  506. if (i > 0 && event === fn) {
  507. events.splice(i, 1);
  508. }
  509. });
  510. if (events.length == 1) {
  511. _unbindEvent(el, type, events[0]);
  512. delete _eventData[id][type];
  513. }
  514. }
  515. var count = 0;
  516. _each(_eventData[id], function () {
  517. count++;
  518. });
  519. if (count < 2) {
  520. delete _eventData[id];
  521. _removeId(el);
  522. }
  523. }
  524. }
  525. function _fire(el, type) {
  526. if (type.indexOf(',') >= 0) {
  527. _each(type.split(','), function () {
  528. _fire(el, this);
  529. });
  530. return;
  531. }
  532. var id = _getId(el);
  533. if (!id) {
  534. return;
  535. }
  536. var events = _eventData[id][type];
  537. if (_eventData[id] && events && events.length > 0) {
  538. events[0]();
  539. }
  540. }
  541. function _ctrl(el, key, fn) {
  542. var self = this;
  543. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  544. _bind(el, 'keydown', function (e) {
  545. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  546. fn.call(el);
  547. e.stop();
  548. }
  549. });
  550. }
  551. var _readyFinished = false;
  552. function _ready(fn) {
  553. if (_readyFinished) {
  554. fn(KindEditor);
  555. return;
  556. }
  557. var loaded = false;
  558. function readyFunc() {
  559. if (!loaded) {
  560. loaded = true;
  561. fn(KindEditor);
  562. _readyFinished = true;
  563. }
  564. }
  565. function ieReadyFunc() {
  566. if (!loaded) {
  567. try {
  568. document.documentElement.doScroll('left');
  569. } catch (e) {
  570. setTimeout(ieReadyFunc, 100);
  571. return;
  572. }
  573. readyFunc();
  574. }
  575. }
  576. function ieReadyStateFunc() {
  577. if (document.readyState === 'complete') {
  578. readyFunc();
  579. }
  580. }
  581. if (document.addEventListener) {
  582. _bind(document, 'DOMContentLoaded', readyFunc);
  583. } else if (document.attachEvent) {
  584. _bind(document, 'readystatechange', ieReadyStateFunc);
  585. var toplevel = false;
  586. try {
  587. toplevel = window.frameElement == null;
  588. } catch (e) { }
  589. if (document.documentElement.doScroll && toplevel) {
  590. ieReadyFunc();
  591. }
  592. }
  593. _bind(window, 'load', readyFunc);
  594. }
  595. if (_IE) {
  596. window.attachEvent('onunload', function () {
  597. _each(_eventData, function (key, events) {
  598. if (events.el) {
  599. _unbind(events.el);
  600. }
  601. });
  602. });
  603. }
  604. K.ctrl = _ctrl;
  605. K.ready = _ready;
  606. function _getCssList(css) {
  607. var list = {},
  608. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  609. match;
  610. while ((match = reg.exec(css))) {
  611. var key = _trim(match[1].toLowerCase()),
  612. val = _trim(_toHex(match[2]));
  613. list[key] = val;
  614. }
  615. return list;
  616. }
  617. function _getAttrList(tag) {
  618. var list = {},
  619. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  620. match;
  621. while ((match = reg.exec(tag))) {
  622. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  623. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  624. list[key] = val;
  625. }
  626. return list;
  627. }
  628. function _addClassToTag(tag, className) {
  629. if (/\s+class\s*=/.test(tag)) {
  630. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function ($0, $1, $2, $3) {
  631. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  632. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  633. } else {
  634. return $0;
  635. }
  636. });
  637. } else {
  638. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  639. }
  640. return tag;
  641. }
  642. function _formatCss(css) {
  643. var str = '';
  644. _each(_getCssList(css), function (key, val) {
  645. str += key + ':' + val + ';';
  646. });
  647. return str;
  648. }
  649. function _formatUrl(url, mode, host, pathname) {
  650. mode = _undef(mode, '').toLowerCase();
  651. if (url.substr(0, 5) != 'data:') {
  652. url = url.replace(/([^:])\/\//g, '$1/');
  653. }
  654. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  655. return url;
  656. }
  657. host = host || location.protocol + '//' + location.host;
  658. if (pathname === undefined) {
  659. var m = location.pathname.match(/^(\/.*)\//);
  660. pathname = m ? m[1] : '';
  661. }
  662. var match;
  663. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  664. if (match[1] !== host) {
  665. return url;
  666. }
  667. } else if (/^\w+:/.test(url)) {
  668. return url;
  669. }
  670. function getRealPath(path) {
  671. var parts = path.split('/'), paths = [];
  672. for (var i = 0, len = parts.length; i < len; i++) {
  673. var part = parts[i];
  674. if (part == '..') {
  675. if (paths.length > 0) {
  676. paths.pop();
  677. }
  678. } else if (part !== '' && part != '.') {
  679. paths.push(part);
  680. }
  681. }
  682. return '/' + paths.join('/');
  683. }
  684. if (/^\//.test(url)) {
  685. url = host + getRealPath(url.substr(1));
  686. } else if (!/^\w+:\/\//.test(url)) {
  687. url = host + getRealPath(pathname + '/' + url);
  688. }
  689. function getRelativePath(path, depth) {
  690. if (url.substr(0, path.length) === path) {
  691. var arr = [];
  692. for (var i = 0; i < depth; i++) {
  693. arr.push('..');
  694. }
  695. var prefix = '.';
  696. if (arr.length > 0) {
  697. prefix += '/' + arr.join('/');
  698. }
  699. if (pathname == '/') {
  700. prefix += '/';
  701. }
  702. return prefix + url.substr(path.length);
  703. } else {
  704. if ((match = /^(.*)\//.exec(path))) {
  705. return getRelativePath(match[1], ++depth);
  706. }
  707. }
  708. }
  709. if (mode === 'relative') {
  710. url = getRelativePath(host + pathname, 0).substr(2);
  711. } else if (mode === 'absolute') {
  712. if (url.substr(0, host.length) === host) {
  713. url = url.substr(host.length);
  714. }
  715. }
  716. return url;
  717. }
  718. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  719. if (html == null) {
  720. html = '';
  721. }
  722. urlType = urlType || '';
  723. wellFormatted = _undef(wellFormatted, false);
  724. indentChar = _undef(indentChar, '\t');
  725. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  726. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function ($0, $1, $2, $3) {
  727. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  728. });
  729. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  730. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  731. html = html.replace(/\u200B/g, '');
  732. html = html.replace(/\u00A9/g, '&copy;');
  733. html = html.replace(/\u00AE/g, '&reg;');
  734. html = html.replace(/<[^>]+/g, function ($0) {
  735. return $0.replace(/\s+/g, ' ');
  736. });
  737. var htmlTagMap = {};
  738. if (htmlTags) {
  739. _each(htmlTags, function (key, val) {
  740. var arr = key.split(',');
  741. for (var i = 0, len = arr.length; i < len; i++) {
  742. htmlTagMap[arr[i]] = _toMap(val);
  743. }
  744. });
  745. if (!htmlTagMap.script) {
  746. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  747. }
  748. if (!htmlTagMap.style) {
  749. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  750. }
  751. }
  752. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  753. var tagStack = [];
  754. html = html.replace(re, function ($0, $1, $2, $3, $4, $5, $6) {
  755. var full = $0,
  756. startNewline = $1 || '',
  757. startSlash = $2 || '',
  758. tagName = $3.toLowerCase(),
  759. attr = $4 || '',
  760. endSlash = $5 ? ' ' + $5 : '',
  761. endNewline = $6 || '';
  762. if (htmlTags && !htmlTagMap[tagName]) {
  763. return '';
  764. }
  765. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  766. endSlash = ' /';
  767. }
  768. if (_INLINE_TAG_MAP[tagName]) {
  769. if (startNewline) {
  770. startNewline = ' ';
  771. }
  772. if (endNewline) {
  773. endNewline = ' ';
  774. }
  775. }
  776. if (_PRE_TAG_MAP[tagName]) {
  777. if (startSlash) {
  778. endNewline = '\n';
  779. } else {
  780. startNewline = '\n';
  781. }
  782. }
  783. if (wellFormatted && tagName == 'br') {
  784. endNewline = '\n';
  785. }
  786. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  787. if (wellFormatted) {
  788. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  789. tagStack.pop();
  790. } else {
  791. tagStack.push(tagName);
  792. }
  793. startNewline = '\n';
  794. endNewline = '\n';
  795. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  796. startNewline += indentChar;
  797. if (!startSlash) {
  798. endNewline += indentChar;
  799. }
  800. }
  801. if (endSlash) {
  802. tagStack.pop();
  803. } else if (!startSlash) {
  804. endNewline += indentChar;
  805. }
  806. } else {
  807. startNewline = endNewline = '';
  808. }
  809. }
  810. if (attr !== '') {
  811. var attrMap = _getAttrList(full);
  812. if (tagName === 'font') {
  813. var fontStyleMap = {}, fontStyle = '';
  814. _each(attrMap, function (key, val) {
  815. if (key === 'color') {
  816. fontStyleMap.color = val;
  817. delete attrMap[key];
  818. }
  819. if (key === 'size') {
  820. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  821. delete attrMap[key];
  822. }
  823. if (key === 'face') {
  824. fontStyleMap['font-family'] = val;
  825. delete attrMap[key];
  826. }
  827. if (key === 'style') {
  828. fontStyle = val;
  829. }
  830. });
  831. if (fontStyle && !/;$/.test(fontStyle)) {
  832. fontStyle += ';';
  833. }
  834. _each(fontStyleMap, function (key, val) {
  835. if (val === '') {
  836. return;
  837. }
  838. if (/\s/.test(val)) {
  839. val = "'" + val + "'";
  840. }
  841. fontStyle += key + ':' + val + ';';
  842. });
  843. attrMap.style = fontStyle;
  844. }
  845. _each(attrMap, function (key, val) {
  846. if (_FILL_ATTR_MAP[key]) {
  847. attrMap[key] = key;
  848. }
  849. if (_inArray(key, ['src', 'href']) >= 0) {
  850. attrMap[key] = _formatUrl(val, urlType);
  851. }
  852. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  853. tagName === 'body' && key === 'contenteditable' ||
  854. /^kindeditor_\d+$/.test(key)) {
  855. delete attrMap[key];
  856. }
  857. if (key === 'style' && val !== '') {
  858. var styleMap = _getCssList(val);
  859. _each(styleMap, function (k, v) {
  860. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  861. delete styleMap[k];
  862. }
  863. });
  864. var style = '';
  865. _each(styleMap, function (k, v) {
  866. style += k + ':' + v + ';';
  867. });
  868. attrMap.style = style;
  869. }
  870. });
  871. attr = '';
  872. _each(attrMap, function (key, val) {
  873. if (key === 'style' && val === '') {
  874. return;
  875. }
  876. val = val.replace(/"/g, '&quot;');
  877. attr += ' ' + key + '="' + val + '"';
  878. });
  879. }
  880. if (tagName === 'font') {
  881. tagName = 'span';
  882. }
  883. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  884. });
  885. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function ($0, $1, $2, $3) {
  886. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  887. });
  888. html = html.replace(/\n\s*\n/g, '\n');
  889. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  890. return _trim(html);
  891. }
  892. function _clearMsWord(html, htmlTags) {
  893. html = html.replace(/<meta[\s\S]*?>/ig, '')
  894. .replace(/<![\s\S]*?>/ig, '')
  895. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  896. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  897. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  898. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  899. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  900. .replace(/<(?:table|td)[^>]*>/ig, function (full) {
  901. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  902. });
  903. return _formatHtml(html, htmlTags);
  904. }
  905. function _mediaType(src) {
  906. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  907. return 'audio/x-pn-realaudio-plugin';
  908. }
  909. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  910. return 'application/x-shockwave-flash';
  911. }
  912. return 'video/x-ms-asf-plugin';
  913. }
  914. function _mediaClass(type) {
  915. if (/realaudio/i.test(type)) {
  916. return 'ke-rm';
  917. }
  918. if (/flash/i.test(type)) {
  919. return 'ke-flash';
  920. }
  921. return 'ke-media';
  922. }
  923. function _mediaAttrs(srcTag) {
  924. return _getAttrList(unescape(srcTag));
  925. }
  926. function _mediaEmbed(attrs) {
  927. var html = '<embed ';
  928. _each(attrs, function (key, val) {
  929. html += key + '="' + val + '" ';
  930. });
  931. html += '/>';
  932. return html;
  933. }
  934. function _mediaImg(blankPath, attrs) {
  935. var width = attrs.width,
  936. height = attrs.height,
  937. type = attrs.type || _mediaType(attrs.src),
  938. srcTag = _mediaEmbed(attrs),
  939. style = '';
  940. if (/\D/.test(width)) {
  941. style += 'width:' + width + ';';
  942. } else if (width > 0) {
  943. style += 'width:' + width + 'px;';
  944. }
  945. if (/\D/.test(height)) {
  946. style += 'height:' + height + ';';
  947. } else if (height > 0) {
  948. style += 'height:' + height + 'px;';
  949. }
  950. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  951. if (style !== '') {
  952. html += 'style="' + style + '" ';
  953. }
  954. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  955. return html;
  956. }
  957. function _tmpl(str, data) {
  958. var fn = new Function("obj",
  959. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  960. "with(obj){p.push('" +
  961. str.replace(/[\r\t\n]/g, " ")
  962. .split("<%").join("\t")
  963. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  964. .replace(/\t=(.*?)%>/g, "',$1,'")
  965. .split("\t").join("');")
  966. .split("%>").join("p.push('")
  967. .split("\r").join("\\'") + "');}return p.join('');");
  968. return data ? fn(data) : fn;
  969. }
  970. K.formatUrl = _formatUrl;
  971. K.formatHtml = _formatHtml;
  972. K.getCssList = _getCssList;
  973. K.getAttrList = _getAttrList;
  974. K.mediaType = _mediaType;
  975. K.mediaAttrs = _mediaAttrs;
  976. K.mediaEmbed = _mediaEmbed;
  977. K.mediaImg = _mediaImg;
  978. K.clearMsWord = _clearMsWord;
  979. K.tmpl = _tmpl;
  980. function _contains(nodeA, nodeB) {
  981. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  982. return true;
  983. }
  984. while ((nodeB = nodeB.parentNode)) {
  985. if (nodeB == nodeA) {
  986. return true;
  987. }
  988. }
  989. return false;
  990. }
  991. var _getSetAttrDiv = document.createElement('div');
  992. _getSetAttrDiv.setAttribute('className', 't');
  993. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  994. function _getAttr(el, key) {
  995. key = key.toLowerCase();
  996. var val = null;
  997. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  998. var div = el.ownerDocument.createElement('div');
  999. div.appendChild(el.cloneNode(false));
  1000. var list = _getAttrList(_unescape(div.innerHTML));
  1001. if (key in list) {
  1002. val = list[key];
  1003. }
  1004. } else {
  1005. try {
  1006. val = el.getAttribute(key, 2);
  1007. } catch (e) {
  1008. val = el.getAttribute(key, 1);
  1009. }
  1010. }
  1011. if (key === 'style' && val !== null) {
  1012. val = _formatCss(val);
  1013. }
  1014. return val;
  1015. }
  1016. function _queryAll(expr, root) {
  1017. var exprList = expr.split(',');
  1018. if (exprList.length > 1) {
  1019. var mergedResults = [];
  1020. _each(exprList, function () {
  1021. _each(_queryAll(this, root), function () {
  1022. if (_inArray(this, mergedResults) < 0) {
  1023. mergedResults.push(this);
  1024. }
  1025. });
  1026. });
  1027. return mergedResults;
  1028. }
  1029. root = root || document;
  1030. function escape(str) {
  1031. if (typeof str != 'string') {
  1032. return str;
  1033. }
  1034. return str.replace(/([^\w\-])/g, '\\$1');
  1035. }
  1036. function stripslashes(str) {
  1037. return str.replace(/\\/g, '');
  1038. }
  1039. function cmpTag(tagA, tagB) {
  1040. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1041. }
  1042. function byId(id, tag, root) {
  1043. var arr = [],
  1044. doc = root.ownerDocument || root,
  1045. el = doc.getElementById(stripslashes(id));
  1046. if (el) {
  1047. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1048. arr.push(el);
  1049. }
  1050. }
  1051. return arr;
  1052. }
  1053. function byClass(className, tag, root) {
  1054. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1055. if (root.getElementsByClassName) {
  1056. els = root.getElementsByClassName(stripslashes(className));
  1057. for (i = 0, len = els.length; i < len; i++) {
  1058. el = els[i];
  1059. if (cmpTag(tag, el.nodeName)) {
  1060. arr.push(el);
  1061. }
  1062. }
  1063. } else if (doc.querySelectorAll) {
  1064. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1065. for (i = 0, len = els.length; i < len; i++) {
  1066. el = els[i];
  1067. if (_contains(root, el)) {
  1068. arr.push(el);
  1069. }
  1070. }
  1071. } else {
  1072. els = root.getElementsByTagName(tag);
  1073. className = ' ' + className + ' ';
  1074. for (i = 0, len = els.length; i < len; i++) {
  1075. el = els[i];
  1076. if (el.nodeType == 1) {
  1077. var cls = el.className;
  1078. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1079. arr.push(el);
  1080. }
  1081. }
  1082. }
  1083. }
  1084. return arr;
  1085. }
  1086. function byName(name, tag, root) {
  1087. var arr = [], doc = root.ownerDocument || root,
  1088. els = doc.getElementsByName(stripslashes(name)), el;
  1089. for (var i = 0, len = els.length; i < len; i++) {
  1090. el = els[i];
  1091. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1092. if (el.getAttribute('name') !== null) {
  1093. arr.push(el);
  1094. }
  1095. }
  1096. }
  1097. return arr;
  1098. }
  1099. function byAttr(key, val, tag, root) {
  1100. var arr = [], els = root.getElementsByTagName(tag), el;
  1101. for (var i = 0, len = els.length; i < len; i++) {
  1102. el = els[i];
  1103. if (el.nodeType == 1) {
  1104. if (val === null) {
  1105. if (_getAttr(el, key) !== null) {
  1106. arr.push(el);
  1107. }
  1108. } else {
  1109. if (val === escape(_getAttr(el, key))) {
  1110. arr.push(el);
  1111. }
  1112. }
  1113. }
  1114. }
  1115. return arr;
  1116. }
  1117. function select(expr, root) {
  1118. var arr = [], matches;
  1119. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1120. var tag = matches ? matches[1] : '*';
  1121. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1122. arr = byId(matches[1], tag, root);
  1123. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1124. arr = byClass(matches[1], tag, root);
  1125. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1126. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1127. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1128. var key = matches[1].toLowerCase(), val = matches[2];
  1129. if (key === 'id') {
  1130. arr = byId(val, tag, root);
  1131. } else if (key === 'class') {
  1132. arr = byClass(val, tag, root);
  1133. } else if (key === 'name') {
  1134. arr = byName(val, tag, root);
  1135. } else {
  1136. arr = byAttr(key, val, tag, root);
  1137. }
  1138. } else {
  1139. var els = root.getElementsByTagName(tag), el;
  1140. for (var i = 0, len = els.length; i < len; i++) {
  1141. el = els[i];
  1142. if (el.nodeType == 1) {
  1143. arr.push(el);
  1144. }
  1145. }
  1146. }
  1147. return arr;
  1148. }
  1149. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1150. while ((arr = re.exec(expr))) {
  1151. if (arr[1] !== ' ') {
  1152. parts.push(arr[1]);
  1153. }
  1154. }
  1155. var results = [];
  1156. if (parts.length == 1) {
  1157. return select(parts[0], root);
  1158. }
  1159. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1160. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1161. part = parts[i];
  1162. if (part === '>') {
  1163. isChild = true;
  1164. continue;
  1165. }
  1166. if (i > 0) {
  1167. els = [];
  1168. for (j = 0, len = results.length; j < len; j++) {
  1169. val = results[j];
  1170. subResults = select(part, val);
  1171. for (k = 0, l = subResults.length; k < l; k++) {
  1172. v = subResults[k];
  1173. if (isChild) {
  1174. if (val === v.parentNode) {
  1175. els.push(v);
  1176. }
  1177. } else {
  1178. els.push(v);
  1179. }
  1180. }
  1181. }
  1182. results = els;
  1183. } else {
  1184. results = select(part, root);
  1185. }
  1186. if (results.length === 0) {
  1187. return [];
  1188. }
  1189. }
  1190. return results;
  1191. }
  1192. function _query(expr, root) {
  1193. var arr = _queryAll(expr, root);
  1194. return arr.length > 0 ? arr[0] : null;
  1195. }
  1196. K.query = _query;
  1197. K.queryAll = _queryAll;
  1198. function _get(val) {
  1199. return K(val)[0];
  1200. }
  1201. function _getDoc(node) {
  1202. if (!node) {
  1203. return document;
  1204. }
  1205. return node.ownerDocument || node.document || node;
  1206. }
  1207. function _getWin(node) {
  1208. if (!node) {
  1209. return window;
  1210. }
  1211. var doc = _getDoc(node);
  1212. return doc.parentWindow || doc.defaultView;
  1213. }
  1214. function _setHtml(el, html) {
  1215. if (el.nodeType != 1) {
  1216. return;
  1217. }
  1218. var doc = _getDoc(el);
  1219. try {
  1220. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1221. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1222. temp.parentNode.removeChild(temp);
  1223. } catch (e) {
  1224. K(el).empty();
  1225. K('@' + html, doc).each(function () {
  1226. el.appendChild(this);
  1227. });
  1228. }
  1229. }
  1230. function _hasClass(el, cls) {
  1231. return _inString(cls, el.className, ' ');
  1232. }
  1233. function _setAttr(el, key, val) {
  1234. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1235. key = 'className';
  1236. }
  1237. el.setAttribute(key, '' + val);
  1238. }
  1239. function _removeAttr(el, key) {
  1240. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1241. key = 'className';
  1242. }
  1243. _setAttr(el, key, '');
  1244. el.removeAttribute(key);
  1245. }
  1246. function _getNodeName(node) {
  1247. if (!node || !node.nodeName) {
  1248. return '';
  1249. }
  1250. return node.nodeName.toLowerCase();
  1251. }
  1252. function _computedCss(el, key) {
  1253. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1254. if (win.getComputedStyle) {
  1255. var style = win.getComputedStyle(el, null);
  1256. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1257. } else if (el.currentStyle) {
  1258. val = el.currentStyle[camelKey] || el.style[camelKey];
  1259. }
  1260. return val;
  1261. }
  1262. function _hasVal(node) {
  1263. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1264. }
  1265. function _docElement(doc) {
  1266. doc = doc || document;
  1267. return _QUIRKS ? doc.body : doc.documentElement;
  1268. }
  1269. function _docHeight(doc) {
  1270. var el = _docElement(doc);
  1271. return Math.max(el.scrollHeight, el.clientHeight);
  1272. }
  1273. function _docWidth(doc) {
  1274. var el = _docElement(doc);
  1275. return Math.max(el.scrollWidth, el.clientWidth);
  1276. }
  1277. function _getScrollPos(doc) {
  1278. doc = doc || document;
  1279. var x, y;
  1280. if (_IE || _NEWIE || _OPERA) {
  1281. x = _docElement(doc).scrollLeft;
  1282. y = _docElement(doc).scrollTop;
  1283. } else {
  1284. x = _getWin(doc).scrollX;
  1285. y = _getWin(doc).scrollY;
  1286. }
  1287. return { x: x, y: y };
  1288. }
  1289. function KNode(node) {
  1290. this.init(node);
  1291. }
  1292. _extend(KNode, {
  1293. init: function (node) {
  1294. var self = this;
  1295. node = _isArray(node) ? node : [node];
  1296. var length = 0;
  1297. for (var i = 0, len = node.length; i < len; i++) {
  1298. if (node[i]) {
  1299. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1300. length++;
  1301. }
  1302. }
  1303. self.length = length;
  1304. self.doc = _getDoc(self[0]);
  1305. self.name = _getNodeName(self[0]);
  1306. self.type = self.length > 0 ? self[0].nodeType : null;
  1307. self.win = _getWin(self[0]);
  1308. },
  1309. each: function (fn) {
  1310. var self = this;
  1311. for (var i = 0; i < self.length; i++) {
  1312. if (fn.call(self[i], i, self[i]) === false) {
  1313. return self;
  1314. }
  1315. }
  1316. return self;
  1317. },
  1318. bind: function (type, fn) {
  1319. this.each(function () {
  1320. _bind(this, type, fn);
  1321. });
  1322. return this;
  1323. },
  1324. unbind: function (type, fn) {
  1325. this.each(function () {
  1326. _unbind(this, type, fn);
  1327. });
  1328. return this;
  1329. },
  1330. fire: function (type) {
  1331. if (this.length < 1) {
  1332. return this;
  1333. }
  1334. _fire(this[0], type);
  1335. return this;
  1336. },
  1337. hasAttr: function (key) {
  1338. if (this.length < 1) {
  1339. return false;
  1340. }
  1341. return !!_getAttr(this[0], key);
  1342. },
  1343. attr: function (key, val) {
  1344. var self = this;
  1345. if (key === undefined) {
  1346. return _getAttrList(self.outer());
  1347. }
  1348. if (typeof key === 'object') {
  1349. _each(key, function (k, v) {
  1350. self.attr(k, v);
  1351. });
  1352. return self;
  1353. }
  1354. if (val === undefined) {
  1355. val = self.length < 1 ? null : _getAttr(self[0], key);
  1356. return val === null ? '' : val;
  1357. }
  1358. self.each(function () {
  1359. _setAttr(this, key, val);
  1360. });
  1361. return self;
  1362. },
  1363. removeAttr: function (key) {
  1364. this.each(function () {
  1365. _removeAttr(this, key);
  1366. });
  1367. return this;
  1368. },
  1369. get: function (i) {
  1370. if (this.length < 1) {
  1371. return null;
  1372. }
  1373. return this[i || 0];
  1374. },
  1375. eq: function (i) {
  1376. if (this.length < 1) {
  1377. return null;
  1378. }
  1379. return this[i] ? new KNode(this[i]) : null;
  1380. },
  1381. hasClass: function (cls) {
  1382. if (this.length < 1) {
  1383. return false;
  1384. }
  1385. return _hasClass(this[0], cls);
  1386. },
  1387. addClass: function (cls) {
  1388. this.each(function () {
  1389. if (!_hasClass(this, cls)) {
  1390. this.className = _trim(this.className + ' ' + cls);
  1391. }
  1392. });
  1393. return this;
  1394. },
  1395. removeClass: function (cls) {
  1396. this.each(function () {
  1397. if (_hasClass(this, cls)) {
  1398. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1399. }
  1400. });
  1401. return this;
  1402. },
  1403. html: function (val) {
  1404. var self = this;
  1405. if (val === undefined) {
  1406. if (self.length < 1 || self.type != 1) {
  1407. return '';
  1408. }
  1409. return _formatHtml(self[0].innerHTML);
  1410. }
  1411. self.each(function () {
  1412. _setHtml(this, val);
  1413. });
  1414. return self;
  1415. },
  1416. text: function () {
  1417. var self = this;
  1418. if (self.length < 1) {
  1419. return '';
  1420. }
  1421. return _IE ? self[0].innerText : self[0].textContent;
  1422. },
  1423. hasVal: function () {
  1424. if (this.length < 1) {
  1425. return false;
  1426. }
  1427. return _hasVal(this[0]);
  1428. },
  1429. val: function (val) {
  1430. var self = this;
  1431. if (val === undefined) {
  1432. if (self.length < 1) {
  1433. return '';
  1434. }
  1435. return self.hasVal() ? self[0].value : self.attr('value');
  1436. } else {
  1437. self.each(function () {
  1438. if (_hasVal(this)) {
  1439. this.value = val;
  1440. } else {
  1441. _setAttr(this, 'value', val);
  1442. }
  1443. });
  1444. return self;
  1445. }
  1446. },
  1447. css: function (key, val) {
  1448. var self = this;
  1449. if (key === undefined) {
  1450. return _getCssList(self.attr('style'));
  1451. }
  1452. if (typeof key === 'object') {
  1453. _each(key, function (k, v) {
  1454. self.css(k, v);
  1455. });
  1456. return self;
  1457. }
  1458. if (val === undefined) {
  1459. if (self.length < 1) {
  1460. return '';
  1461. }
  1462. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1463. }
  1464. self.each(function () {
  1465. this.style[_toCamel(key)] = val;
  1466. });
  1467. return self;
  1468. },
  1469. width: function (val) {
  1470. var self = this;
  1471. if (val === undefined) {
  1472. if (self.length < 1) {
  1473. return 0;
  1474. }
  1475. return self[0].offsetWidth;
  1476. }
  1477. return self.css('width', _addUnit(val));
  1478. },
  1479. height: function (val) {
  1480. var self = this;
  1481. if (val === undefined) {
  1482. if (self.length < 1) {
  1483. return 0;
  1484. }
  1485. return self[0].offsetHeight;
  1486. }
  1487. return self.css('height', _addUnit(val));
  1488. },
  1489. opacity: function (val) {
  1490. this.each(function () {
  1491. if (this.style.opacity === undefined) {
  1492. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1493. } else {
  1494. this.style.opacity = val == 1 ? '' : val;
  1495. }
  1496. });
  1497. return this;
  1498. },
  1499. data: function (key, val) {
  1500. var self = this;
  1501. key = 'kindeditor_data_' + key;
  1502. if (val === undefined) {
  1503. if (self.length < 1) {
  1504. return null;
  1505. }
  1506. return self[0][key];
  1507. }
  1508. this.each(function () {
  1509. this[key] = val;
  1510. });
  1511. return self;
  1512. },
  1513. pos: function () {
  1514. var self = this, node = self[0], x = 0, y = 0;
  1515. if (node) {
  1516. if (node.getBoundingClientRect) {
  1517. var box = node.getBoundingClientRect(),
  1518. pos = _getScrollPos(self.doc);
  1519. x = box.left + pos.x;
  1520. y = box.top + pos.y;
  1521. } else {
  1522. while (node) {
  1523. x += node.offsetLeft;
  1524. y += node.offsetTop;
  1525. node = node.offsetParent;
  1526. }
  1527. }
  1528. }
  1529. return { x: _round(x), y: _round(y) };
  1530. },
  1531. clone: function (bool) {
  1532. if (this.length < 1) {
  1533. return new KNode([]);
  1534. }
  1535. return new KNode(this[0].cloneNode(bool));
  1536. },
  1537. append: function (expr) {
  1538. this.each(function () {
  1539. if (this.appendChild) {
  1540. this.appendChild(_get(expr));
  1541. }
  1542. });
  1543. return this;
  1544. },
  1545. appendTo: function (expr) {
  1546. this.each(function () {
  1547. _get(expr).appendChild(this);
  1548. });
  1549. return this;
  1550. },
  1551. before: function (expr) {
  1552. this.each(function () {
  1553. this.parentNode.insertBefore(_get(expr), this);
  1554. });
  1555. return this;
  1556. },
  1557. after: function (expr) {
  1558. this.each(function () {
  1559. if (this.nextSibling) {
  1560. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1561. } else {
  1562. this.parentNode.appendChild(_get(expr));
  1563. }
  1564. });
  1565. return this;
  1566. },
  1567. replaceWith: function (expr) {
  1568. var nodes = [];
  1569. this.each(function (i, node) {
  1570. _unbind(node);
  1571. var newNode = _get(expr);
  1572. node.parentNode.replaceChild(newNode, node);
  1573. nodes.push(newNode);
  1574. });
  1575. return K(nodes);
  1576. },
  1577. empty: function () {
  1578. var self = this;
  1579. self.each(function (i, node) {
  1580. var child = node.firstChild;
  1581. while (child) {
  1582. if (!node.parentNode) {
  1583. return;
  1584. }
  1585. var next = child.nextSibling;
  1586. child.parentNode.removeChild(child);
  1587. child = next;
  1588. }
  1589. });
  1590. return self;
  1591. },
  1592. remove: function (keepChilds) {
  1593. var self = this;
  1594. self.each(function (i, node) {
  1595. if (!node.parentNode) {
  1596. return;
  1597. }
  1598. _unbind(node);
  1599. if (keepChilds) {
  1600. var child = node.firstChild;
  1601. while (child) {
  1602. var next = child.nextSibling;
  1603. node.parentNode.insertBefore(child, node);
  1604. child = next;
  1605. }
  1606. }
  1607. node.parentNode.removeChild(node);
  1608. delete self[i];
  1609. });
  1610. self.length = 0;
  1611. return self;
  1612. },
  1613. show: function (val) {
  1614. var self = this;
  1615. if (val === undefined) {
  1616. val = self._originDisplay || '';
  1617. }
  1618. if (self.css('display') != 'none') {
  1619. return self;
  1620. }
  1621. return self.css('display', val);
  1622. },
  1623. hide: function () {
  1624. var self = this;
  1625. if (self.length < 1) {
  1626. return self;
  1627. }
  1628. self._originDisplay = self[0].style.display;
  1629. return self.css('display', 'none');
  1630. },
  1631. outer: function () {
  1632. var self = this;
  1633. if (self.length < 1) {
  1634. return '';
  1635. }
  1636. var div = self.doc.createElement('div'), html;
  1637. div.appendChild(self[0].cloneNode(true));
  1638. html = _formatHtml(div.innerHTML);
  1639. div = null;
  1640. return html;
  1641. },
  1642. isSingle: function () {
  1643. return !!_SINGLE_TAG_MAP[this.name];
  1644. },
  1645. isInline: function () {
  1646. return !!_INLINE_TAG_MAP[this.name];
  1647. },
  1648. isBlock: function () {
  1649. return !!_BLOCK_TAG_MAP[this.name];
  1650. },
  1651. isStyle: function () {
  1652. return !!_STYLE_TAG_MAP[this.name];
  1653. },
  1654. isControl: function () {
  1655. return !!_CONTROL_TAG_MAP[this.name];
  1656. },
  1657. contains: function (otherNode) {
  1658. if (this.length < 1) {
  1659. return false;
  1660. }
  1661. return _contains(this[0], _get(otherNode));
  1662. },
  1663. parent: function () {
  1664. if (this.length < 1) {
  1665. return null;
  1666. }
  1667. var node = this[0].parentNode;
  1668. return node ? new KNode(node) : null;
  1669. },
  1670. children: function () {
  1671. if (this.length < 1) {
  1672. return new KNode([]);
  1673. }
  1674. var list = [], child = this[0].firstChild;
  1675. while (child) {
  1676. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1677. list.push(child);
  1678. }
  1679. child = child.nextSibling;
  1680. }
  1681. return new KNode(list);
  1682. },
  1683. first: function () {
  1684. var list = this.children();
  1685. return list.length > 0 ? list.eq(0) : null;
  1686. },
  1687. last: function () {
  1688. var list = this.children();
  1689. return list.length > 0 ? list.eq(list.length - 1) : null;
  1690. },
  1691. index: function () {
  1692. if (this.length < 1) {
  1693. return -1;
  1694. }
  1695. var i = -1, sibling = this[0];
  1696. while (sibling) {
  1697. i++;
  1698. sibling = sibling.previousSibling;
  1699. }
  1700. return i;
  1701. },
  1702. prev: function () {
  1703. if (this.length < 1) {
  1704. return null;
  1705. }
  1706. var node = this[0].previousSibling;
  1707. return node ? new KNode(node) : null;
  1708. },
  1709. next: function () {
  1710. if (this.length < 1) {
  1711. return null;
  1712. }
  1713. var node = this[0].nextSibling;
  1714. return node ? new KNode(node) : null;
  1715. },
  1716. scan: function (fn, order) {
  1717. if (this.length < 1) {
  1718. return;
  1719. }
  1720. order = (order === undefined) ? true : order;
  1721. function walk(node) {
  1722. var n = order ? node.firstChild : node.lastChild;
  1723. while (n) {
  1724. var next = order ? n.nextSibling : n.previousSibling;
  1725. if (fn(n) === false) {
  1726. return false;
  1727. }
  1728. if (walk(n) === false) {
  1729. return false;
  1730. }
  1731. n = next;
  1732. }
  1733. }
  1734. walk(this[0]);
  1735. return this;
  1736. }
  1737. });
  1738. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1739. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1740. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function (i, type) {
  1741. KNode.prototype[type] = function (fn) {
  1742. return fn ? this.bind(type, fn) : this.fire(type);
  1743. };
  1744. });
  1745. var _K = K;
  1746. K = function (expr, root) {
  1747. if (expr === undefined || expr === null) {
  1748. return;
  1749. }
  1750. function newNode(node) {
  1751. if (!node[0]) {
  1752. node = [];
  1753. }
  1754. return new KNode(node);
  1755. }
  1756. if (typeof expr === 'string') {
  1757. if (root) {
  1758. root = _get(root);
  1759. }
  1760. var length = expr.length;
  1761. if (expr.charAt(0) === '@') {
  1762. expr = expr.substr(1);
  1763. }
  1764. if (expr.length !== length || /<.+>/.test(expr)) {
  1765. var doc = root ? root.ownerDocument || root : document,
  1766. div = doc.createElement('div'), list = [];
  1767. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1768. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1769. var child = div.childNodes[i];
  1770. if (child.id == '__kindeditor_temp_tag__') {
  1771. continue;
  1772. }
  1773. list.push(child);
  1774. }
  1775. return newNode(list);
  1776. }
  1777. return newNode(_queryAll(expr, root));
  1778. }
  1779. if (expr && expr.constructor === KNode) {
  1780. return expr;
  1781. }
  1782. if (expr.toArray) {
  1783. expr = expr.toArray();
  1784. }
  1785. if (_isArray(expr)) {
  1786. return newNode(expr);
  1787. }
  1788. return newNode(_toArray(arguments));
  1789. };
  1790. _each(_K, function (key, val) {
  1791. K[key] = val;
  1792. });
  1793. K.NodeClass = KNode;
  1794. window.KindEditor = K;
  1795. var _START_TO_START = 0,
  1796. _START_TO_END = 1,
  1797. _END_TO_END = 2,
  1798. _END_TO_START = 3,
  1799. _BOOKMARK_ID = 0;
  1800. function _updateCollapsed(range) {
  1801. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1802. return range;
  1803. }
  1804. function _copyAndDelete(range, isCopy, isDelete) {
  1805. var doc = range.doc, nodeList = [];
  1806. function splitTextNode(node, startOffset, endOffset) {
  1807. var length = node.nodeValue.length, centerNode;
  1808. if (isCopy) {
  1809. var cloneNode = node.cloneNode(true);
  1810. if (startOffset > 0) {
  1811. centerNode = cloneNode.splitText(startOffset);
  1812. } else {
  1813. centerNode = cloneNode;
  1814. }
  1815. if (endOffset < length) {
  1816. centerNode.splitText(endOffset - startOffset);
  1817. }
  1818. }
  1819. if (isDelete) {
  1820. var center = node;
  1821. if (startOffset > 0) {
  1822. center = node.splitText(startOffset);
  1823. range.setStart(node, startOffset);
  1824. }
  1825. if (endOffset < length) {
  1826. var right = center.splitText(endOffset - startOffset);
  1827. range.setEnd(right, 0);
  1828. }
  1829. nodeList.push(center);
  1830. }
  1831. return centerNode;
  1832. }
  1833. function removeNodes() {
  1834. if (isDelete) {
  1835. range.up().collapse(true);
  1836. }
  1837. for (var i = 0, len = nodeList.length; i < len; i++) {
  1838. var node = nodeList[i];
  1839. if (node.parentNode) {
  1840. node.parentNode.removeChild(node);
  1841. }
  1842. }
  1843. }
  1844. var copyRange = range.cloneRange().down();
  1845. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1846. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1847. if (ancestor.nodeType == 3) {
  1848. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1849. if (isCopy) {
  1850. frag.appendChild(textNode);
  1851. }
  1852. removeNodes();
  1853. return isCopy ? frag : range;
  1854. }
  1855. function extractNodes(parent, frag) {
  1856. var node = parent.firstChild, nextNode;
  1857. while (node) {
  1858. var testRange = new KRange(doc).selectNode(node);
  1859. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1860. if (start >= 0 && incStart <= 0) {
  1861. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1862. }
  1863. if (incStart >= 0 && incEnd <= 0) {
  1864. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1865. }
  1866. if (incEnd >= 0 && end <= 0) {
  1867. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1868. }
  1869. if (end >= 0) {
  1870. return false;
  1871. }
  1872. nextNode = node.nextSibling;
  1873. if (start > 0) {
  1874. if (node.nodeType == 1) {
  1875. if (incStart >= 0 && incEnd <= 0) {
  1876. if (isCopy) {
  1877. frag.appendChild(node.cloneNode(true));
  1878. }
  1879. if (isDelete) {
  1880. nodeList.push(node);
  1881. }
  1882. } else {
  1883. var childFlag;
  1884. if (isCopy) {
  1885. childFlag = node.cloneNode(false);
  1886. frag.appendChild(childFlag);
  1887. }
  1888. if (extractNodes(node, childFlag) === false) {
  1889. return false;
  1890. }
  1891. }
  1892. } else if (node.nodeType == 3) {
  1893. var textNode;
  1894. if (node == copyRange.startContainer) {
  1895. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1896. } else if (node == copyRange.endContainer) {
  1897. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1898. } else {
  1899. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1900. }
  1901. if (isCopy) {
  1902. try {
  1903. frag.appendChild(textNode);
  1904. } catch (e) { }
  1905. }
  1906. }
  1907. }
  1908. node = nextNode;
  1909. }
  1910. }
  1911. extractNodes(ancestor, frag);
  1912. if (isDelete) {
  1913. range.up().collapse(true);
  1914. }
  1915. for (var i = 0, len = nodeList.length; i < len; i++) {
  1916. var node = nodeList[i];
  1917. if (node.parentNode) {
  1918. node.parentNode.removeChild(node);
  1919. }
  1920. }
  1921. return isCopy ? frag : range;
  1922. }
  1923. function _moveToElementText(range, el) {
  1924. var node = el;
  1925. while (node) {
  1926. var knode = K(node);
  1927. if (knode.name == 'marquee' || knode.name == 'select') {
  1928. return;
  1929. }
  1930. node = node.parentNode;
  1931. }
  1932. try {
  1933. range.moveToElementText(el);
  1934. } catch (e) { }
  1935. }
  1936. function _getStartEnd(rng, isStart) {
  1937. var doc = rng.parentElement().ownerDocument,
  1938. pointRange = rng.duplicate();
  1939. pointRange.collapse(isStart);
  1940. var parent = pointRange.parentElement(),
  1941. nodes = parent.childNodes;
  1942. if (nodes.length === 0) {
  1943. return { node: parent.parentNode, offset: K(parent).index() };
  1944. }
  1945. var startNode = doc, startPos = 0, cmp = -1;
  1946. var testRange = rng.duplicate();
  1947. _moveToElementText(testRange, parent);
  1948. for (var i = 0, len = nodes.length; i < len; i++) {
  1949. var node = nodes[i];
  1950. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1951. if (cmp === 0) {
  1952. return { node: node.parentNode, offset: i };
  1953. }
  1954. if (node.nodeType == 1) {
  1955. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1956. if (knode.isControl()) {
  1957. dummy = doc.createElement('span');
  1958. knode.after(dummy);
  1959. newNode = dummy;
  1960. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1961. }
  1962. _moveToElementText(nodeRange, newNode);
  1963. testRange.setEndPoint('StartToEnd', nodeRange);
  1964. if (cmp > 0) {
  1965. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1966. } else {
  1967. startPos = 0;
  1968. }
  1969. if (dummy) {
  1970. K(dummy).remove();
  1971. }
  1972. } else if (node.nodeType == 3) {
  1973. testRange.moveStart('character', node.nodeValue.length);
  1974. startPos += node.nodeValue.length;
  1975. }
  1976. if (cmp < 0) {
  1977. startNode = node;
  1978. }
  1979. }
  1980. if (cmp < 0 && startNode.nodeType == 1) {
  1981. return { node: parent, offset: K(parent.lastChild).index() + 1 };
  1982. }
  1983. if (cmp > 0) {
  1984. while (startNode.nextSibling && startNode.nodeType == 1) {
  1985. startNode = startNode.nextSibling;
  1986. }
  1987. }
  1988. testRange = rng.duplicate();
  1989. _moveToElementText(testRange, parent);
  1990. testRange.setEndPoint('StartToEnd', pointRange);
  1991. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1992. if (cmp > 0 && startNode.nodeType == 3) {
  1993. var prevNode = startNode.previousSibling;
  1994. while (prevNode && prevNode.nodeType == 3) {
  1995. startPos -= prevNode.nodeValue.length;
  1996. prevNode = prevNode.previousSibling;
  1997. }
  1998. }
  1999. return { node: startNode, offset: startPos };
  2000. }
  2001. function _getEndRange(node, offset) {
  2002. var doc = node.ownerDocument || node,
  2003. range = doc.body.createTextRange();
  2004. if (doc == node) {
  2005. range.collapse(true);
  2006. return range;
  2007. }
  2008. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2009. var children = node.childNodes, isStart, child;
  2010. if (offset === 0) {
  2011. child = children[0];
  2012. isStart = true;
  2013. } else {
  2014. child = children[offset - 1];
  2015. isStart = false;
  2016. }
  2017. if (!child) {
  2018. return range;
  2019. }
  2020. if (K(child).name === 'head') {
  2021. if (offset === 1) {
  2022. isStart = true;
  2023. }
  2024. if (offset === 2) {
  2025. isStart = false;
  2026. }
  2027. range.collapse(isStart);
  2028. return range;
  2029. }
  2030. if (child.nodeType == 1) {
  2031. var kchild = K(child), span;
  2032. if (kchild.isControl()) {
  2033. span = doc.createElement('span');
  2034. if (isStart) {
  2035. kchild.before(span);
  2036. } else {
  2037. kchild.after(span);
  2038. }
  2039. child = span;
  2040. }
  2041. _moveToElementText(range, child);
  2042. range.collapse(isStart);
  2043. if (span) {
  2044. K(span).remove();
  2045. }
  2046. return range;
  2047. }
  2048. node = child;
  2049. offset = isStart ? 0 : child.nodeValue.length;
  2050. }
  2051. var dummy = doc.createElement('span');
  2052. K(node).before(dummy);
  2053. _moveToElementText(range, dummy);
  2054. range.moveStart('character', offset);
  2055. K(dummy).remove();
  2056. return range;
  2057. }
  2058. function _toRange(rng) {
  2059. var doc, range;
  2060. function tr2td(start) {
  2061. if (K(start.node).name == 'tr') {
  2062. start.node = start.node.cells[start.offset];
  2063. start.offset = 0;
  2064. }
  2065. }
  2066. if (_IERANGE) {
  2067. if (rng.item) {
  2068. doc = _getDoc(rng.item(0));
  2069. range = new KRange(doc);
  2070. range.selectNode(rng.item(0));
  2071. return range;
  2072. }
  2073. doc = rng.parentElement().ownerDocument;
  2074. var start = _getStartEnd(rng, true),
  2075. end = _getStartEnd(rng, false);
  2076. tr2td(start);
  2077. tr2td(end);
  2078. range = new KRange(doc);
  2079. range.setStart(start.node, start.offset);
  2080. range.setEnd(end.node, end.offset);
  2081. return range;
  2082. }
  2083. var startContainer = rng.startContainer;
  2084. doc = startContainer.ownerDocument || startContainer;
  2085. range = new KRange(doc);
  2086. range.setStart(startContainer, rng.startOffset);
  2087. range.setEnd(rng.endContainer, rng.endOffset);
  2088. return range;
  2089. }
  2090. function KRange(doc) {
  2091. this.init(doc);
  2092. }
  2093. _extend(KRange, {
  2094. init: function (doc) {
  2095. var self = this;
  2096. self.startContainer = doc;
  2097. self.startOffset = 0;
  2098. self.endContainer = doc;
  2099. self.endOffset = 0;
  2100. self.collapsed = true;
  2101. self.doc = doc;
  2102. },
  2103. commonAncestor: function () {
  2104. function getParents(node) {
  2105. var parents = [];
  2106. while (node) {
  2107. parents.push(node);
  2108. node = node.parentNode;
  2109. }
  2110. return parents;
  2111. }
  2112. var parentsA = getParents(this.startContainer),
  2113. parentsB = getParents(this.endContainer),
  2114. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2115. while (++i) {
  2116. parentA = parentsA[lenA - i];
  2117. parentB = parentsB[lenB - i];
  2118. if (!parentA || !parentB || parentA !== parentB) {
  2119. break;
  2120. }
  2121. }
  2122. return parentsA[lenA - i + 1];
  2123. },
  2124. setStart: function (node, offset) {
  2125. var self = this, doc = self.doc;
  2126. self.startContainer = node;
  2127. self.startOffset = offset;
  2128. if (self.endContainer === doc) {
  2129. self.endContainer = node;
  2130. self.endOffset = offset;
  2131. }
  2132. return _updateCollapsed(this);
  2133. },
  2134. setEnd: function (node, offset) {
  2135. var self = this, doc = self.doc;
  2136. self.endContainer = node;
  2137. self.endOffset = offset;
  2138. if (self.startContainer === doc) {
  2139. self.startContainer = node;
  2140. self.startOffset = offset;
  2141. }
  2142. return _updateCollapsed(this);
  2143. },
  2144. setStartBefore: function (node) {
  2145. return this.setStart(node.parentNode || this.doc, K(node).index());
  2146. },
  2147. setStartAfter: function (node) {
  2148. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2149. },
  2150. setEndBefore: function (node) {
  2151. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2152. },
  2153. setEndAfter: function (node) {
  2154. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2155. },
  2156. selectNode: function (node) {
  2157. return this.setStartBefore(node).setEndAfter(node);
  2158. },
  2159. selectNodeContents: function (node) {
  2160. var knode = K(node);
  2161. if (knode.type == 3 || knode.isSingle()) {
  2162. return this.selectNode(node);
  2163. }
  2164. var children = knode.children();
  2165. if (children.length > 0) {
  2166. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2167. }
  2168. return this.setStart(node, 0).setEnd(node, 0);
  2169. },
  2170. collapse: function (toStart) {
  2171. if (toStart) {
  2172. return this.setEnd(this.startContainer, this.startOffset);
  2173. }
  2174. return this.setStart(this.endContainer, this.endOffset);
  2175. },
  2176. compareBoundaryPoints: function (how, range) {
  2177. var rangeA = this.get(), rangeB = range.get();
  2178. if (_IERANGE) {
  2179. var arr = {};
  2180. arr[_START_TO_START] = 'StartToStart';
  2181. arr[_START_TO_END] = 'EndToStart';
  2182. arr[_END_TO_END] = 'EndToEnd';
  2183. arr[_END_TO_START] = 'StartToEnd';
  2184. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2185. if (cmp !== 0) {
  2186. return cmp;
  2187. }
  2188. var nodeA, nodeB, nodeC, posA, posB;
  2189. if (how === _START_TO_START || how === _END_TO_START) {
  2190. nodeA = this.startContainer;
  2191. posA = this.startOffset;
  2192. }
  2193. if (how === _START_TO_END || how === _END_TO_END) {
  2194. nodeA = this.endContainer;
  2195. posA = this.endOffset;
  2196. }
  2197. if (how === _START_TO_START || how === _START_TO_END) {
  2198. nodeB = range.startContainer;
  2199. posB = range.startOffset;
  2200. }
  2201. if (how === _END_TO_END || how === _END_TO_START) {
  2202. nodeB = range.endContainer;
  2203. posB = range.endOffset;
  2204. }
  2205. if (nodeA === nodeB) {
  2206. var diff = posA - posB;
  2207. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2208. }
  2209. nodeC = nodeB;
  2210. while (nodeC && nodeC.parentNode !== nodeA) {
  2211. nodeC = nodeC.parentNode;
  2212. }
  2213. if (nodeC) {
  2214. return K(nodeC).index() >= posA ? -1 : 1;
  2215. }
  2216. nodeC = nodeA;
  2217. while (nodeC && nodeC.parentNode !== nodeB) {
  2218. nodeC = nodeC.parentNode;
  2219. }
  2220. if (nodeC) {
  2221. return K(nodeC).index() >= posB ? 1 : -1;
  2222. }
  2223. nodeC = K(nodeB).next();
  2224. if (nodeC && nodeC.contains(nodeA)) {
  2225. return 1;
  2226. }
  2227. nodeC = K(nodeA).next();
  2228. if (nodeC && nodeC.contains(nodeB)) {
  2229. return -1;
  2230. }
  2231. } else {
  2232. return rangeA.compareBoundaryPoints(how, rangeB);
  2233. }
  2234. },
  2235. cloneRange: function () {
  2236. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2237. },
  2238. toString: function () {
  2239. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2240. return str.replace(/\r\n|\n|\r/g, '');
  2241. },
  2242. cloneContents: function () {
  2243. return _copyAndDelete(this, true, false);
  2244. },
  2245. deleteContents: function () {
  2246. return _copyAndDelete(this, false, true);
  2247. },
  2248. extractContents: function () {
  2249. return _copyAndDelete(this, true, true);
  2250. },
  2251. insertNode: function (node) {
  2252. var self = this,
  2253. sc = self.startContainer, so = self.startOffset,
  2254. ec = self.endContainer, eo = self.endOffset,
  2255. firstChild, lastChild, c, nodeCount = 1;
  2256. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2257. firstChild = node.firstChild;
  2258. lastChild = node.lastChild;
  2259. nodeCount = node.childNodes.length;
  2260. }
  2261. if (sc.nodeType == 1) {
  2262. c = sc.childNodes[so];
  2263. if (c) {
  2264. sc.insertBefore(node, c);
  2265. if (sc === ec) {
  2266. eo += nodeCount;
  2267. }
  2268. } else {
  2269. sc.appendChild(node);
  2270. }
  2271. } else if (sc.nodeType == 3) {
  2272. if (so === 0) {
  2273. sc.parentNode.insertBefore(node, sc);
  2274. if (sc.parentNode === ec) {
  2275. eo += nodeCount;
  2276. }
  2277. } else if (so >= sc.nodeValue.length) {
  2278. if (sc.nextSibling) {
  2279. sc.parentNode.insertBefore(node, sc.nextSibling);
  2280. } else {
  2281. sc.parentNode.appendChild(node);
  2282. }
  2283. } else {
  2284. if (so > 0) {
  2285. c = sc.splitText(so);
  2286. } else {
  2287. c = sc;
  2288. }
  2289. sc.parentNode.insertBefore(node, c);
  2290. if (sc === ec) {
  2291. ec = c;
  2292. eo -= so;
  2293. }
  2294. }
  2295. }
  2296. if (firstChild) {
  2297. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2298. } else {
  2299. self.selectNode(node);
  2300. }
  2301. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2302. return self;
  2303. }
  2304. return self.setEnd(ec, eo);
  2305. },
  2306. surroundContents: function (node) {
  2307. node.appendChild(this.extractContents());
  2308. return this.insertNode(node).selectNode(node);
  2309. },
  2310. isControl: function () {
  2311. var self = this,
  2312. sc = self.startContainer, so = self.startOffset,
  2313. ec = self.endContainer, eo = self.endOffset, rng;
  2314. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2315. },
  2316. get: function (hasControlRange) {
  2317. var self = this, doc = self.doc, node, rng;
  2318. if (!_IERANGE) {
  2319. rng = doc.createRange();
  2320. try {
  2321. rng.setStart(self.startContainer, self.startOffset);
  2322. rng.setEnd(self.endContainer, self.endOffset);
  2323. } catch (e) { }
  2324. return rng;
  2325. }
  2326. if (hasControlRange && self.isControl()) {
  2327. rng = doc.body.createControlRange();
  2328. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2329. return rng;
  2330. }
  2331. var range = self.cloneRange().down();
  2332. rng = doc.body.createTextRange();
  2333. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2334. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2335. return rng;
  2336. },
  2337. html: function () {
  2338. return K(this.cloneContents()).outer();
  2339. },
  2340. down: function () {
  2341. var self = this;
  2342. function downPos(node, pos, isStart) {
  2343. if (node.nodeType != 1) {
  2344. return;
  2345. }
  2346. var children = K(node).children();
  2347. if (children.length === 0) {
  2348. return;
  2349. }
  2350. var left, right, child, offset;
  2351. if (pos > 0) {
  2352. left = children.eq(pos - 1);
  2353. }
  2354. if (pos < children.length) {
  2355. right = children.eq(pos);
  2356. }
  2357. if (left && left.type == 3) {
  2358. child = left[0];
  2359. offset = child.nodeValue.length;
  2360. }
  2361. if (right && right.type == 3) {
  2362. child = right[0];
  2363. offset = 0;
  2364. }
  2365. if (!child) {
  2366. return;
  2367. }
  2368. if (isStart) {
  2369. self.setStart(child, offset);
  2370. } else {
  2371. self.setEnd(child, offset);
  2372. }
  2373. }
  2374. downPos(self.startContainer, self.startOffset, true);
  2375. downPos(self.endContainer, self.endOffset, false);
  2376. return self;
  2377. },
  2378. up: function () {
  2379. var self = this;
  2380. function upPos(node, pos, isStart) {
  2381. if (node.nodeType != 3) {
  2382. return;
  2383. }
  2384. if (pos === 0) {
  2385. if (isStart) {
  2386. self.setStartBefore(node);
  2387. } else {
  2388. self.setEndBefore(node);
  2389. }
  2390. } else if (pos == node.nodeValue.length) {
  2391. if (isStart) {
  2392. self.setStartAfter(node);
  2393. } else {
  2394. self.setEndAfter(node);
  2395. }
  2396. }
  2397. }
  2398. upPos(self.startContainer, self.startOffset, true);
  2399. upPos(self.endContainer, self.endOffset, false);
  2400. return self;
  2401. },
  2402. enlarge: function (toBlock) {
  2403. var self = this;
  2404. self.up();
  2405. function enlargePos(node, pos, isStart) {
  2406. var knode = K(node), parent;
  2407. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2408. return;
  2409. }
  2410. if (pos === 0) {
  2411. while (!knode.prev()) {
  2412. parent = knode.parent();
  2413. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2414. break;
  2415. }
  2416. knode = parent;
  2417. }
  2418. if (isStart) {
  2419. self.setStartBefore(knode[0]);
  2420. } else {
  2421. self.setEndBefore(knode[0]);
  2422. }
  2423. } else if (pos == knode.children().length) {
  2424. while (!knode.next()) {
  2425. parent = knode.parent();
  2426. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2427. break;
  2428. }
  2429. knode = parent;
  2430. }
  2431. if (isStart) {
  2432. self.setStartAfter(knode[0]);
  2433. } else {
  2434. self.setEndAfter(knode[0]);
  2435. }
  2436. }
  2437. }
  2438. enlargePos(self.startContainer, self.startOffset, true);
  2439. enlargePos(self.endContainer, self.endOffset, false);
  2440. return self;
  2441. },
  2442. shrink: function () {
  2443. var self = this, child, collapsed = self.collapsed;
  2444. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2445. self.setStart(child, 0);
  2446. }
  2447. if (collapsed) {
  2448. return self.collapse(collapsed);
  2449. }
  2450. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2451. self.setEnd(child, child.childNodes.length);
  2452. }
  2453. return self;
  2454. },
  2455. createBookmark: function (serialize) {
  2456. var self = this, doc = self.doc, endNode,
  2457. startNode = K('<span style="display:none;"></span>', doc)[0];
  2458. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2459. if (!self.collapsed) {
  2460. endNode = startNode.cloneNode(true);
  2461. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2462. }
  2463. if (endNode) {
  2464. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2465. }
  2466. self.insertNode(startNode).setStartAfter(startNode);
  2467. return {
  2468. start: serialize ? '#' + startNode.id : startNode,
  2469. end: endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2470. };
  2471. },
  2472. moveToBookmark: function (bookmark) {
  2473. var self = this, doc = self.doc,
  2474. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2475. if (!start || start.length < 1) {
  2476. return self;
  2477. }
  2478. self.setStartBefore(start[0]);
  2479. start.remove();
  2480. if (end && end.length > 0) {
  2481. self.setEndBefore(end[0]);
  2482. end.remove();
  2483. } else {
  2484. self.collapse(true);
  2485. }
  2486. return self;
  2487. },
  2488. dump: function () {
  2489. console.log('--------------------');
  2490. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2491. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2492. }
  2493. });
  2494. function _range(mixed) {
  2495. if (!mixed.nodeName) {
  2496. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2497. }
  2498. return new KRange(mixed);
  2499. }
  2500. K.RangeClass = KRange;
  2501. K.range = _range;
  2502. K.START_TO_START = _START_TO_START;
  2503. K.START_TO_END = _START_TO_END;
  2504. K.END_TO_END = _END_TO_END;
  2505. K.END_TO_START = _END_TO_START;
  2506. function _nativeCommand(doc, key, val) {
  2507. try {
  2508. doc.execCommand(key, false, val);
  2509. } catch (e) { }
  2510. }
  2511. function _nativeCommandValue(doc, key) {
  2512. var val = '';
  2513. try {
  2514. val = doc.queryCommandValue(key);
  2515. } catch (e) { }
  2516. if (typeof val !== 'string') {
  2517. val = '';
  2518. }
  2519. return val;
  2520. }
  2521. function _getSel(doc) {
  2522. var win = _getWin(doc);
  2523. return _IERANGE ? doc.selection : win.getSelection();
  2524. }
  2525. function _getRng(doc) {
  2526. var sel = _getSel(doc), rng;
  2527. try {
  2528. if (sel.rangeCount > 0) {
  2529. rng = sel.getRangeAt(0);
  2530. } else {
  2531. rng = sel.createRange();
  2532. }
  2533. } catch (e) { }
  2534. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2535. return null;
  2536. }
  2537. return rng;
  2538. }
  2539. function _singleKeyMap(map) {
  2540. var newMap = {}, arr, v;
  2541. _each(map, function (key, val) {
  2542. arr = key.split(',');
  2543. for (var i = 0, len = arr.length; i < len; i++) {
  2544. v = arr[i];
  2545. newMap[v] = val;
  2546. }
  2547. });
  2548. return newMap;
  2549. }
  2550. function _hasAttrOrCss(knode, map) {
  2551. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2552. }
  2553. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2554. mapKey = mapKey || knode.name;
  2555. if (knode.type !== 1) {
  2556. return false;
  2557. }
  2558. var newMap = _singleKeyMap(map);
  2559. if (!newMap[mapKey]) {
  2560. return false;
  2561. }
  2562. var arr = newMap[mapKey].split(',');
  2563. for (var i = 0, len = arr.length; i < len; i++) {
  2564. var key = arr[i];
  2565. if (key === '*') {
  2566. return true;
  2567. }
  2568. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2569. var method = match[1] ? 'css' : 'attr';
  2570. key = match[2];
  2571. var val = match[3] || '';
  2572. if (val === '' && knode[method](key) !== '') {
  2573. return true;
  2574. }
  2575. if (val !== '' && knode[method](key) === val) {
  2576. return true;
  2577. }
  2578. }
  2579. return false;
  2580. }
  2581. function _removeAttrOrCss(knode, map) {
  2582. if (knode.type != 1) {
  2583. return;
  2584. }
  2585. _removeAttrOrCssByKey(knode, map, '*');
  2586. _removeAttrOrCssByKey(knode, map);
  2587. }
  2588. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2589. mapKey = mapKey || knode.name;
  2590. if (knode.type !== 1) {
  2591. return;
  2592. }
  2593. var newMap = _singleKeyMap(map);
  2594. if (!newMap[mapKey]) {
  2595. return;
  2596. }
  2597. var arr = newMap[mapKey].split(','), allFlag = false;
  2598. for (var i = 0, len = arr.length; i < len; i++) {
  2599. var key = arr[i];
  2600. if (key === '*') {
  2601. allFlag = true;
  2602. break;
  2603. }
  2604. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2605. key = match[2];
  2606. if (match[1]) {
  2607. key = _toCamel(key);
  2608. if (knode[0].style[key]) {
  2609. knode[0].style[key] = '';
  2610. }
  2611. } else {
  2612. knode.removeAttr(key);
  2613. }
  2614. }
  2615. if (allFlag) {
  2616. knode.remove(true);
  2617. }
  2618. }
  2619. function _getInnerNode(knode) {
  2620. var inner = knode;
  2621. while (inner.first()) {
  2622. inner = inner.first();
  2623. }
  2624. return inner;
  2625. }
  2626. function _isEmptyNode(knode) {
  2627. if (knode.type != 1 || knode.isSingle()) {
  2628. return false;
  2629. }
  2630. return knode.html().replace(/<[^>]+>/g, '') === '';
  2631. }
  2632. function _mergeWrapper(a, b) {
  2633. a = a.clone(true);
  2634. var lastA = _getInnerNode(a), childA = a, merged = false;
  2635. while (b) {
  2636. while (childA) {
  2637. if (childA.name === b.name) {
  2638. _mergeAttrs(childA, b.attr(), b.css());
  2639. merged = true;
  2640. }
  2641. childA = childA.first();
  2642. }
  2643. if (!merged) {
  2644. lastA.append(b.clone(false));
  2645. }
  2646. merged = false;
  2647. b = b.first();
  2648. }
  2649. return a;
  2650. }
  2651. function _wrapNode(knode, wrapper) {
  2652. wrapper = wrapper.clone(true);
  2653. if (knode.type == 3) {
  2654. _getInnerNode(wrapper).append(knode.clone(false));
  2655. knode.replaceWith(wrapper);
  2656. return wrapper;
  2657. }
  2658. var nodeWrapper = knode, child;
  2659. while ((child = knode.first()) && child.children().length == 1) {
  2660. knode = child;
  2661. }
  2662. child = knode.first();
  2663. var frag = knode.doc.createDocumentFragment();
  2664. while (child) {
  2665. frag.appendChild(child[0]);
  2666. child = child.next();
  2667. }
  2668. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2669. if (frag.firstChild) {
  2670. _getInnerNode(wrapper).append(frag);
  2671. }
  2672. nodeWrapper.replaceWith(wrapper);
  2673. return wrapper;
  2674. }
  2675. function _mergeAttrs(knode, attrs, styles) {
  2676. _each(attrs, function (key, val) {
  2677. if (key !== 'style') {
  2678. knode.attr(key, val);
  2679. }
  2680. });
  2681. _each(styles, function (key, val) {
  2682. knode.css(key, val);
  2683. });
  2684. }
  2685. function _inPreElement(knode) {
  2686. while (knode && knode.name != 'body') {
  2687. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2688. return true;
  2689. }
  2690. knode = knode.parent();
  2691. }
  2692. return false;
  2693. }
  2694. function KCmd(range) {
  2695. this.init(range);
  2696. }
  2697. _extend(KCmd, {
  2698. init: function (range) {
  2699. var self = this, doc = range.doc;
  2700. self.doc = doc;
  2701. self.win = _getWin(doc);
  2702. self.sel = _getSel(doc);
  2703. self.range = range;
  2704. },
  2705. selection: function (forceReset) {
  2706. var self = this, doc = self.doc, rng = _getRng(doc);
  2707. self.sel = _getSel(doc);
  2708. if (rng) {
  2709. self.range = _range(rng);
  2710. if (K(self.range.startContainer).name == 'html') {
  2711. self.range.selectNodeContents(doc.body).collapse(false);
  2712. }
  2713. return self;
  2714. }
  2715. if (forceReset) {
  2716. self.range.selectNodeContents(doc.body).collapse(false);
  2717. }
  2718. return self;
  2719. },
  2720. select: function (hasDummy) {
  2721. hasDummy = _undef(hasDummy, true);
  2722. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2723. sc = range.startContainer, so = range.startOffset,
  2724. ec = range.endContainer, eo = range.endOffset,
  2725. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2726. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2727. if (_IERANGE) {
  2728. var dummy = K('<span>&nbsp;</span>', doc);
  2729. range.insertNode(dummy[0]);
  2730. rng = doc.body.createTextRange();
  2731. try {
  2732. rng.moveToElementText(dummy[0]);
  2733. } catch (ex) { }
  2734. rng.collapse(false);
  2735. rng.select();
  2736. dummy.remove();
  2737. win.focus();
  2738. return self;
  2739. }
  2740. if (_WEBKIT) {
  2741. var children = sc.childNodes;
  2742. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2743. range.insertNode(doc.createTextNode('\u200B'));
  2744. hasU200b = true;
  2745. }
  2746. }
  2747. }
  2748. if (_IERANGE) {
  2749. try {
  2750. rng = range.get(true);
  2751. rng.select();
  2752. } catch (e) { }
  2753. } else {
  2754. if (hasU200b) {
  2755. range.collapse(false);
  2756. }
  2757. rng = range.get(true);
  2758. sel.removeAllRanges();
  2759. sel.addRange(rng);
  2760. if (doc !== document) {
  2761. var pos = K(rng.endContainer).pos();
  2762. win.scrollTo(pos.x, pos.y);
  2763. }
  2764. }
  2765. win.focus();
  2766. return self;
  2767. },
  2768. wrap: function (val) {
  2769. var self = this, doc = self.doc, range = self.range, wrapper;
  2770. wrapper = K(val, doc);
  2771. if (range.collapsed) {
  2772. range.shrink();
  2773. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2774. return self;
  2775. }
  2776. if (wrapper.isBlock()) {
  2777. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2778. while (child.first()) {
  2779. child = child.first();
  2780. }
  2781. child.append(range.extractContents());
  2782. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2783. return self;
  2784. }
  2785. range.enlarge();
  2786. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2787. K(ancestor).scan(function (node) {
  2788. if (!isStart && node == bookmark.start) {
  2789. isStart = true;
  2790. return;
  2791. }
  2792. if (isStart) {
  2793. if (node == bookmark.end) {
  2794. return false;
  2795. }
  2796. var knode = K(node);
  2797. if (_inPreElement(knode)) {
  2798. return;
  2799. }
  2800. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2801. var parent;
  2802. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2803. knode = parent;
  2804. }
  2805. _wrapNode(knode, wrapper);
  2806. }
  2807. }
  2808. });
  2809. range.moveToBookmark(bookmark);
  2810. return self;
  2811. },
  2812. split: function (isStart, map) {
  2813. var range = this.range, doc = range.doc;
  2814. var tempRange = range.cloneRange().collapse(isStart);
  2815. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2816. parent = node.nodeType == 3 ? node.parentNode : node,
  2817. needSplit = false, knode;
  2818. while (parent && parent.parentNode) {
  2819. knode = K(parent);
  2820. if (map) {
  2821. if (!knode.isStyle()) {
  2822. break;
  2823. }
  2824. if (!_hasAttrOrCss(knode, map)) {
  2825. break;
  2826. }
  2827. } else {
  2828. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2829. break;
  2830. }
  2831. }
  2832. needSplit = true;
  2833. parent = parent.parentNode;
  2834. }
  2835. if (needSplit) {
  2836. var dummy = doc.createElement('span');
  2837. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2838. if (isStart) {
  2839. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2840. } else {
  2841. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2842. }
  2843. var frag = tempRange.extractContents(),
  2844. first = frag.firstChild, last = frag.lastChild;
  2845. if (isStart) {
  2846. tempRange.insertNode(frag);
  2847. range.setStartAfter(last).setEndBefore(dummy);
  2848. } else {
  2849. parent.appendChild(frag);
  2850. range.setStartBefore(dummy).setEndBefore(first);
  2851. }
  2852. var dummyParent = dummy.parentNode;
  2853. if (dummyParent == range.endContainer) {
  2854. var prev = K(dummy).prev(), next = K(dummy).next();
  2855. if (prev && next && prev.type == 3 && next.type == 3) {
  2856. range.setEnd(prev[0], prev[0].nodeValue.length);
  2857. } else if (!isStart) {
  2858. range.setEnd(range.endContainer, range.endOffset - 1);
  2859. }
  2860. }
  2861. dummyParent.removeChild(dummy);
  2862. }
  2863. return this;
  2864. },
  2865. remove: function (map) {
  2866. var self = this, doc = self.doc, range = self.range;
  2867. range.enlarge();
  2868. if (range.startOffset === 0) {
  2869. var ksc = K(range.startContainer), parent;
  2870. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2871. ksc = parent;
  2872. }
  2873. range.setStart(ksc[0], 0);
  2874. ksc = K(range.startContainer);
  2875. if (ksc.isBlock()) {
  2876. _removeAttrOrCss(ksc, map);
  2877. }
  2878. var kscp = ksc.parent();
  2879. if (kscp && kscp.isBlock()) {
  2880. _removeAttrOrCss(kscp, map);
  2881. }
  2882. }
  2883. var sc, so;
  2884. if (range.collapsed) {
  2885. self.split(true, map);
  2886. sc = range.startContainer;
  2887. so = range.startOffset;
  2888. if (so > 0) {
  2889. var sb = K(sc.childNodes[so - 1]);
  2890. if (sb && _isEmptyNode(sb)) {
  2891. sb.remove();
  2892. range.setStart(sc, so - 1);
  2893. }
  2894. }
  2895. var sa = K(sc.childNodes[so]);
  2896. if (sa && _isEmptyNode(sa)) {
  2897. sa.remove();
  2898. }
  2899. if (_isEmptyNode(sc)) {
  2900. range.startBefore(sc);
  2901. sc.remove();
  2902. }
  2903. range.collapse(true);
  2904. return self;
  2905. }
  2906. self.split(true, map);
  2907. self.split(false, map);
  2908. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2909. range.cloneRange().collapse(false).insertNode(endDummy);
  2910. range.cloneRange().collapse(true).insertNode(startDummy);
  2911. var nodeList = [], cmpStart = false;
  2912. K(range.commonAncestor()).scan(function (node) {
  2913. if (!cmpStart && node == startDummy) {
  2914. cmpStart = true;
  2915. return;
  2916. }
  2917. if (node == endDummy) {
  2918. return false;
  2919. }
  2920. if (cmpStart) {
  2921. nodeList.push(node);
  2922. }
  2923. });
  2924. K(startDummy).remove();
  2925. K(endDummy).remove();
  2926. sc = range.startContainer;
  2927. so = range.startOffset;
  2928. var ec = range.endContainer, eo = range.endOffset;
  2929. if (so > 0) {
  2930. var startBefore = K(sc.childNodes[so - 1]);
  2931. if (startBefore && _isEmptyNode(startBefore)) {
  2932. startBefore.remove();
  2933. range.setStart(sc, so - 1);
  2934. if (sc == ec) {
  2935. range.setEnd(ec, eo - 1);
  2936. }
  2937. }
  2938. var startAfter = K(sc.childNodes[so]);
  2939. if (startAfter && _isEmptyNode(startAfter)) {
  2940. startAfter.remove();
  2941. if (sc == ec) {
  2942. range.setEnd(ec, eo - 1);
  2943. }
  2944. }
  2945. }
  2946. var endAfter = K(ec.childNodes[range.endOffset]);
  2947. if (endAfter && _isEmptyNode(endAfter)) {
  2948. endAfter.remove();
  2949. }
  2950. var bookmark = range.createBookmark(true);
  2951. _each(nodeList, function (i, node) {
  2952. _removeAttrOrCss(K(node), map);
  2953. });
  2954. range.moveToBookmark(bookmark);
  2955. return self;
  2956. },
  2957. commonNode: function (map) {
  2958. var range = this.range;
  2959. var ec = range.endContainer, eo = range.endOffset,
  2960. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2961. function find(node) {
  2962. var child = node, parent = node;
  2963. while (parent) {
  2964. if (_hasAttrOrCss(K(parent), map)) {
  2965. return K(parent);
  2966. }
  2967. parent = parent.parentNode;
  2968. }
  2969. while (child && (child = child.lastChild)) {
  2970. if (_hasAttrOrCss(K(child), map)) {
  2971. return K(child);
  2972. }
  2973. }
  2974. return null;
  2975. }
  2976. var cNode = find(node);
  2977. if (cNode) {
  2978. return cNode;
  2979. }
  2980. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2981. var prev = K(node).prev();
  2982. if (prev) {
  2983. return find(prev);
  2984. }
  2985. }
  2986. return null;
  2987. },
  2988. commonAncestor: function (tagName) {
  2989. var range = this.range,
  2990. sc = range.startContainer, so = range.startOffset,
  2991. ec = range.endContainer, eo = range.endOffset,
  2992. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2993. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2994. function find(node) {
  2995. while (node) {
  2996. if (node.nodeType == 1) {
  2997. if (node.tagName.toLowerCase() === tagName) {
  2998. return node;
  2999. }
  3000. }
  3001. node = node.parentNode;
  3002. }
  3003. return null;
  3004. }
  3005. var start = find(startNode), end = find(endNode);
  3006. if (start && end && start === end) {
  3007. return K(start);
  3008. }
  3009. return null;
  3010. },
  3011. state: function (key) {
  3012. var self = this, doc = self.doc, bool = false;
  3013. try {
  3014. bool = doc.queryCommandState(key);
  3015. } catch (e) { }
  3016. return bool;
  3017. },
  3018. val: function (key) {
  3019. var self = this, doc = self.doc, range = self.range;
  3020. function lc(val) {
  3021. return val.toLowerCase();
  3022. }
  3023. key = lc(key);
  3024. var val = '', knode;
  3025. if (key === 'fontfamily' || key === 'fontname') {
  3026. val = _nativeCommandValue(doc, 'fontname');
  3027. val = val.replace(/['"]/g, '');
  3028. return lc(val);
  3029. }
  3030. if (key === 'formatblock') {
  3031. val = _nativeCommandValue(doc, key);
  3032. if (val === '') {
  3033. knode = self.commonNode({ 'h1,h2,h3,h4,h5,h6,p,div,pre,address': '*' });
  3034. if (knode) {
  3035. val = knode.name;
  3036. }
  3037. }
  3038. if (val === 'Normal') {
  3039. val = 'p';
  3040. }
  3041. return lc(val);
  3042. }
  3043. if (key === 'fontsize') {
  3044. knode = self.commonNode({ '*': '.font-size' });
  3045. if (knode) {
  3046. val = knode.css('font-size');
  3047. }
  3048. return lc(val);
  3049. }
  3050. if (key === 'forecolor') {
  3051. knode = self.commonNode({ '*': '.color' });
  3052. if (knode) {
  3053. val = knode.css('color');
  3054. }
  3055. val = _toHex(val);
  3056. if (val === '') {
  3057. val = 'default';
  3058. }
  3059. return lc(val);
  3060. }
  3061. if (key === 'hilitecolor') {
  3062. knode = self.commonNode({ '*': '.background-color' });
  3063. if (knode) {
  3064. val = knode.css('background-color');
  3065. }
  3066. val = _toHex(val);
  3067. if (val === '') {
  3068. val = 'default';
  3069. }
  3070. return lc(val);
  3071. }
  3072. return val;
  3073. },
  3074. toggle: function (wrapper, map) {
  3075. var self = this;
  3076. if (self.commonNode(map)) {
  3077. self.remove(map);
  3078. } else {
  3079. self.wrap(wrapper);
  3080. }
  3081. return self.select();
  3082. },
  3083. bold: function () {
  3084. return this.toggle('<strong></strong>', {
  3085. span: '.font-weight=bold',
  3086. strong: '*',
  3087. b: '*'
  3088. });
  3089. },
  3090. italic: function () {
  3091. return this.toggle('<em></em>', {
  3092. span: '.font-style=italic',
  3093. em: '*',
  3094. i: '*'
  3095. });
  3096. },
  3097. underline: function () {
  3098. return this.toggle('<u></u>', {
  3099. span: '.text-decoration=underline',
  3100. u: '*'
  3101. });
  3102. },
  3103. strikethrough: function () {
  3104. return this.toggle('<s></s>', {
  3105. span: '.text-decoration=line-through',
  3106. s: '*'
  3107. });
  3108. },
  3109. forecolor: function (val) {
  3110. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3111. },
  3112. hilitecolor: function (val) {
  3113. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3114. },
  3115. fontsize: function (val) {
  3116. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3117. },
  3118. fontname: function (val) {
  3119. return this.fontfamily(val);
  3120. },
  3121. fontfamily: function (val) {
  3122. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3123. },
  3124. removeformat: function () {
  3125. var map = {
  3126. '*': '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3127. },
  3128. tags = _STYLE_TAG_MAP;
  3129. _each(tags, function (key, val) {
  3130. map[key] = '*';
  3131. });
  3132. this.remove(map);
  3133. return this.select();
  3134. },
  3135. inserthtml: function (val, quickMode) {
  3136. var self = this, range = self.range;
  3137. if (val === '') {
  3138. return self;
  3139. }
  3140. function pasteHtml(range, val) {
  3141. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3142. var rng = range.get();
  3143. if (rng.item) {
  3144. rng.item(0).outerHTML = val;
  3145. } else {
  3146. rng.pasteHTML(val);
  3147. }
  3148. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3149. temp.parentNode.removeChild(temp);
  3150. var newRange = _toRange(rng);
  3151. range.setEnd(newRange.endContainer, newRange.endOffset);
  3152. range.collapse(false);
  3153. self.select(false);
  3154. }
  3155. function insertHtml(range, val) {
  3156. var doc = range.doc,
  3157. frag = doc.createDocumentFragment();
  3158. K('@' + val, doc).each(function () {
  3159. frag.appendChild(this);
  3160. });
  3161. range.deleteContents();
  3162. range.insertNode(frag);
  3163. range.collapse(false);
  3164. self.select(false);
  3165. }
  3166. if (_IERANGE && quickMode) {
  3167. try {
  3168. pasteHtml(range, val);
  3169. } catch (e) {
  3170. insertHtml(range, val);
  3171. }
  3172. return self;
  3173. }
  3174. insertHtml(range, val);
  3175. return self;
  3176. },
  3177. hr: function () {
  3178. return this.inserthtml('<hr />');
  3179. },
  3180. print: function () {
  3181. this.win.print();
  3182. return this;
  3183. },
  3184. insertimage: function (url, title, width, height, border, align) {
  3185. title = _undef(title, '');
  3186. border = _undef(border, 0);
  3187. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3188. if (width) {
  3189. html += 'width="' + _escape(width) + '" ';
  3190. }
  3191. if (height) {
  3192. html += 'height="' + _escape(height) + '" ';
  3193. }
  3194. if (title) {
  3195. html += 'title="' + _escape(title) + '" ';
  3196. }
  3197. if (align) {
  3198. html += 'align="' + _escape(align) + '" ';
  3199. }
  3200. html += 'alt="' + _escape(title) + '" ';
  3201. html += '/>';
  3202. return this.inserthtml(html);
  3203. },
  3204. createlink: function (url, type) {
  3205. var self = this, doc = self.doc, range = self.range;
  3206. self.select();
  3207. var a = self.commonNode({ a: '*' });
  3208. if (a && !range.isControl()) {
  3209. range.selectNode(a.get());
  3210. self.select();
  3211. }
  3212. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3213. if (type) {
  3214. html += ' target="' + _escape(type) + '"';
  3215. }
  3216. if (range.collapsed) {
  3217. html += '>' + _escape(url) + '</a>';
  3218. return self.inserthtml(html);
  3219. }
  3220. if (range.isControl()) {
  3221. var node = K(range.startContainer.childNodes[range.startOffset]);
  3222. html += '></a>';
  3223. node.after(K(html, doc));
  3224. node.next().append(node);
  3225. range.selectNode(node[0]);
  3226. return self.select();
  3227. }
  3228. function setAttr(node, url, type) {
  3229. K(node).attr('href', url).attr('data-ke-src', url);
  3230. if (type) {
  3231. K(node).attr('target', type);
  3232. } else {
  3233. K(node).removeAttr('target');
  3234. }
  3235. }
  3236. var sc = range.startContainer, so = range.startOffset,
  3237. ec = range.endContainer, eo = range.endOffset;
  3238. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3239. var child = sc.childNodes[so];
  3240. if (child.nodeName.toLowerCase() == 'a') {
  3241. setAttr(child, url, type);
  3242. return self;
  3243. }
  3244. }
  3245. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3246. K('a[href="__kindeditor_temp_url__"]', doc).each(function () {
  3247. setAttr(this, url, type);
  3248. });
  3249. return self;
  3250. },
  3251. unlink: function () {
  3252. var self = this, doc = self.doc, range = self.range;
  3253. self.select();
  3254. if (range.collapsed) {
  3255. var a = self.commonNode({ a: '*' });
  3256. if (a) {
  3257. range.selectNode(a.get());
  3258. self.select();
  3259. }
  3260. _nativeCommand(doc, 'unlink', null);
  3261. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3262. var parent = K(range.startContainer).parent();
  3263. if (parent.name === 'a') {
  3264. parent.remove(true);
  3265. }
  3266. }
  3267. } else {
  3268. _nativeCommand(doc, 'unlink', null);
  3269. }
  3270. return self;
  3271. }
  3272. });
  3273. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3274. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function (i, name) {
  3275. KCmd.prototype[name] = function (val) {
  3276. var self = this;
  3277. self.select();
  3278. _nativeCommand(self.doc, name, val);
  3279. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3280. self.selection();
  3281. }
  3282. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3283. self.selection();
  3284. }
  3285. return self;
  3286. };
  3287. });
  3288. _each('cut,copy,paste'.split(','), function (i, name) {
  3289. KCmd.prototype[name] = function () {
  3290. var self = this;
  3291. if (!self.doc.queryCommandSupported(name)) {
  3292. throw 'not supported';
  3293. }
  3294. self.select();
  3295. _nativeCommand(self.doc, name, null);
  3296. return self;
  3297. };
  3298. });
  3299. function _cmd(mixed) {
  3300. if (mixed.nodeName) {
  3301. var doc = _getDoc(mixed);
  3302. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3303. }
  3304. return new KCmd(mixed);
  3305. }
  3306. K.CmdClass = KCmd;
  3307. K.cmd = _cmd;
  3308. function _drag(options) {
  3309. var moveEl = options.moveEl,
  3310. moveFn = options.moveFn,
  3311. clickEl = options.clickEl || moveEl,
  3312. beforeDrag = options.beforeDrag,
  3313. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3314. var docs = [document];
  3315. if (iframeFix) {
  3316. K('iframe').each(function () {
  3317. var src = _formatUrl(this.src || '', 'absolute');
  3318. if (/^https?:\/\//.test(src)) {
  3319. return;
  3320. }
  3321. var doc;
  3322. try {
  3323. doc = _iframeDoc(this);
  3324. } catch (e) { }
  3325. if (doc) {
  3326. var pos = K(this).pos();
  3327. K(doc).data('pos-x', pos.x);
  3328. K(doc).data('pos-y', pos.y);
  3329. docs.push(doc);
  3330. }
  3331. });
  3332. }
  3333. clickEl.mousedown(function (e) {
  3334. e.stopPropagation();
  3335. var self = clickEl.get(),
  3336. x = _removeUnit(moveEl.css('left')),
  3337. y = _removeUnit(moveEl.css('top')),
  3338. width = moveEl.width(),
  3339. height = moveEl.height(),
  3340. pageX = e.pageX,
  3341. pageY = e.pageY;
  3342. if (beforeDrag) {
  3343. beforeDrag();
  3344. }
  3345. function moveListener(e) {
  3346. e.preventDefault();
  3347. var kdoc = K(_getDoc(e.target));
  3348. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3349. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3350. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3351. }
  3352. function selectListener(e) {
  3353. e.preventDefault();
  3354. }
  3355. function upListener(e) {
  3356. e.preventDefault();
  3357. K(docs).unbind('mousemove', moveListener)
  3358. .unbind('mouseup', upListener)
  3359. .unbind('selectstart', selectListener);
  3360. if (self.releaseCapture) {
  3361. self.releaseCapture();
  3362. }
  3363. }
  3364. K(docs).mousemove(moveListener)
  3365. .mouseup(upListener)
  3366. .bind('selectstart', selectListener);
  3367. if (self.setCapture) {
  3368. self.setCapture();
  3369. }
  3370. });
  3371. }
  3372. function KWidget(options) {
  3373. this.init(options);
  3374. }
  3375. _extend(KWidget, {
  3376. init: function (options) {
  3377. var self = this;
  3378. self.name = options.name || '';
  3379. self.doc = options.doc || document;
  3380. self.win = _getWin(self.doc);
  3381. self.x = _addUnit(options.x);
  3382. self.y = _addUnit(options.y);
  3383. self.z = options.z;
  3384. self.width = _addUnit(options.width);
  3385. self.height = _addUnit(options.height);
  3386. self.div = K('<div style="display:block;"></div>');
  3387. self.options = options;
  3388. self._alignEl = options.alignEl;
  3389. if (self.width) {
  3390. self.div.css('width', self.width);
  3391. }
  3392. if (self.height) {
  3393. self.div.css('height', self.height);
  3394. }
  3395. if (self.z) {
  3396. self.div.css({
  3397. position: 'absolute',
  3398. left: self.x,
  3399. top: self.y,
  3400. 'z-index': self.z
  3401. });
  3402. }
  3403. if (self.z && (self.x === undefined || self.y === undefined)) {
  3404. self.autoPos(self.width, self.height);
  3405. }
  3406. if (options.cls) {
  3407. self.div.addClass(options.cls);
  3408. }
  3409. if (options.shadowMode) {
  3410. self.div.addClass('ke-shadow');
  3411. }
  3412. if (options.css) {
  3413. self.div.css(options.css);
  3414. }
  3415. if (options.src) {
  3416. K(options.src).replaceWith(self.div);
  3417. } else {
  3418. K(self.doc.body).append(self.div);
  3419. }
  3420. if (options.html) {
  3421. self.div.html(options.html);
  3422. }
  3423. if (options.autoScroll) {
  3424. if (_IE && _V < 7 || _QUIRKS) {
  3425. var scrollPos = _getScrollPos();
  3426. K(self.win).bind('scroll', function (e) {
  3427. var pos = _getScrollPos(),
  3428. diffX = pos.x - scrollPos.x,
  3429. diffY = pos.y - scrollPos.y;
  3430. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3431. });
  3432. } else {
  3433. self.div.css('position', 'fixed');
  3434. }
  3435. }
  3436. },
  3437. pos: function (x, y, updateProp) {
  3438. var self = this;
  3439. updateProp = _undef(updateProp, true);
  3440. if (x !== null) {
  3441. x = x < 0 ? 0 : _addUnit(x);
  3442. self.div.css('left', x);
  3443. if (updateProp) {
  3444. self.x = x;
  3445. }
  3446. }
  3447. if (y !== null) {
  3448. y = y < 0 ? 0 : _addUnit(y);
  3449. self.div.css('top', y);
  3450. if (updateProp) {
  3451. self.y = y;
  3452. }
  3453. }
  3454. return self;
  3455. },
  3456. autoPos: function (width, height) {
  3457. var self = this,
  3458. w = _removeUnit(width) || 0,
  3459. h = _removeUnit(height) || 0,
  3460. scrollPos = _getScrollPos();
  3461. if (self._alignEl) {
  3462. var knode = K(self._alignEl),
  3463. pos = knode.pos(),
  3464. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3465. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3466. x = diffX < 0 ? pos.x : pos.x + diffX;
  3467. y = diffY < 0 ? pos.y : pos.y + diffY;
  3468. } else {
  3469. var docEl = _docElement(self.doc);
  3470. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3471. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3472. }
  3473. if (!(_IE && _V < 7 || _QUIRKS)) {
  3474. x -= scrollPos.x;
  3475. y -= scrollPos.y;
  3476. }
  3477. return self.pos(x, y);
  3478. },
  3479. remove: function () {
  3480. var self = this;
  3481. if (_IE && _V < 7 || _QUIRKS) {
  3482. K(self.win).unbind('scroll');
  3483. }
  3484. self.div.remove();
  3485. _each(self, function (i) {
  3486. self[i] = null;
  3487. });
  3488. return this;
  3489. },
  3490. show: function () {
  3491. this.div.show();
  3492. return this;
  3493. },
  3494. hide: function () {
  3495. this.div.hide();
  3496. return this;
  3497. },
  3498. draggable: function (options) {
  3499. var self = this;
  3500. options = options || {};
  3501. options.moveEl = self.div;
  3502. options.moveFn = function (x, y, width, height, diffX, diffY) {
  3503. if ((x = x + diffX) < 0) {
  3504. x = 0;
  3505. }
  3506. if ((y = y + diffY) < 0) {
  3507. y = 0;
  3508. }
  3509. self.pos(x, y);
  3510. };
  3511. _drag(options);
  3512. return self;
  3513. }
  3514. });
  3515. function _widget(options) {
  3516. return new KWidget(options);
  3517. }
  3518. K.WidgetClass = KWidget;
  3519. K.widget = _widget;
  3520. function _iframeDoc(iframe) {
  3521. iframe = _get(iframe);
  3522. return iframe.contentDocument || iframe.contentWindow.document;
  3523. }
  3524. var html, _direction = '';
  3525. if ((html = document.getElementsByTagName('html'))) {
  3526. _direction = html[0].dir;
  3527. }
  3528. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3529. var arr = [
  3530. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3531. '<head><meta charset="utf-8" /><title></title>',
  3532. '<style>',
  3533. 'html {margin:0;padding:0;}',
  3534. 'body {margin:0;padding:5px;}',
  3535. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3536. 'body, p, div {word-wrap: break-word;}',
  3537. 'p {margin:5px 0;}',
  3538. 'table {border-collapse:collapse;}',
  3539. 'img {border:0;}',
  3540. 'noscript {display:none;}',
  3541. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3542. 'img.ke-flash {',
  3543. ' border:1px solid #AAA;',
  3544. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3545. ' background-position:center center;',
  3546. ' background-repeat:no-repeat;',
  3547. ' width:100px;',
  3548. ' height:100px;',
  3549. '}',
  3550. 'img.ke-rm {',
  3551. ' border:1px solid #AAA;',
  3552. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3553. ' background-position:center center;',
  3554. ' background-repeat:no-repeat;',
  3555. ' width:100px;',
  3556. ' height:100px;',
  3557. '}',
  3558. 'img.ke-media {',
  3559. ' border:1px solid #AAA;',
  3560. ' background-image:url(' + themesPath + 'common/media.gif);',
  3561. ' background-position:center center;',
  3562. ' background-repeat:no-repeat;',
  3563. ' width:100px;',
  3564. ' height:100px;',
  3565. '}',
  3566. 'img.ke-anchor {',
  3567. ' border:1px dashed #666;',
  3568. ' width:16px;',
  3569. ' height:16px;',
  3570. '}',
  3571. '.ke-script, .ke-noscript, .ke-display-none {',
  3572. ' display:none;',
  3573. ' font-size:0;',
  3574. ' width:0;',
  3575. ' height:0;',
  3576. '}',
  3577. '.ke-pagebreak {',
  3578. ' border:1px dotted #AAA;',
  3579. ' font-size:0;',
  3580. ' height:2px;',
  3581. '}',
  3582. '::-webkit-scrollbar{width:16px;height:14px}',
  3583. '::-webkit-scrollbar-track,::-webkit-scrollbar-thumb{border-radius:999px;border:5px solid transparent}',
  3584. '::-webkit-scrollbar-track{box-shadow:1px 1px 5px rgba(0,0,0,.2) inset}',
  3585. '::-webkit-scrollbar-thumb{min-height:20px;-moz-background-clip:content-box;-webkit-background-clip:content-box;background-clip:content-box;box-shadow:0 0 0 5px rgba(0,0,0,.2) inset}',
  3586. '::-webkit-scrollbar-corner{background:transparent}',
  3587. '</style>'
  3588. ];
  3589. if (!_isArray(cssPath)) {
  3590. cssPath = [cssPath];
  3591. }
  3592. _each(cssPath, function (i, path) {
  3593. if (path) {
  3594. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3595. }
  3596. });
  3597. if (cssData) {
  3598. arr.push('<style>' + cssData + '</style>');
  3599. }
  3600. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3601. return arr.join('\n');
  3602. }
  3603. function _elementVal(knode, val) {
  3604. if (knode.hasVal()) {
  3605. if (val === undefined) {
  3606. var html = knode.val();
  3607. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3608. return html;
  3609. }
  3610. return knode.val(val);
  3611. }
  3612. return knode.html(val);
  3613. }
  3614. function KEdit(options) {
  3615. this.init(options);
  3616. }
  3617. _extend(KEdit, KWidget, {
  3618. init: function (options) {
  3619. var self = this;
  3620. KEdit.parent.init.call(self, options);
  3621. self.srcElement = K(options.srcElement);
  3622. self.div.addClass('ke-edit');
  3623. self.designMode = _undef(options.designMode, true);
  3624. self.beforeGetHtml = options.beforeGetHtml;
  3625. self.beforeSetHtml = options.beforeSetHtml;
  3626. self.afterSetHtml = options.afterSetHtml;
  3627. var themesPath = _undef(options.themesPath, ''),
  3628. bodyClass = options.bodyClass,
  3629. cssPath = options.cssPath,
  3630. cssData = options.cssData,
  3631. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3632. srcScript = ('document.open();' +
  3633. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3634. 'document.close();'),
  3635. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3636. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3637. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3638. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3639. self.iframe.attr('tabindex', self.tabIndex);
  3640. self.textarea.attr('tabindex', self.tabIndex);
  3641. if (self.width) {
  3642. self.setWidth(self.width);
  3643. }
  3644. if (self.height) {
  3645. self.setHeight(self.height);
  3646. }
  3647. if (self.designMode) {
  3648. self.textarea.hide();
  3649. } else {
  3650. self.iframe.hide();
  3651. }
  3652. function ready() {
  3653. var doc = _iframeDoc(self.iframe);
  3654. doc.open();
  3655. if (isDocumentDomain) {
  3656. doc.domain = document.domain;
  3657. }
  3658. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3659. doc.close();
  3660. self.win = self.iframe[0].contentWindow;
  3661. self.doc = doc;
  3662. var cmd = _cmd(doc);
  3663. self.afterChange(function (e) {
  3664. cmd.selection();
  3665. });
  3666. if (_WEBKIT) {
  3667. K(doc).click(function (e) {
  3668. if (K(e.target).name === 'img') {
  3669. cmd.selection(true);
  3670. cmd.range.selectNode(e.target);
  3671. cmd.select();
  3672. }
  3673. });
  3674. }
  3675. if (_IE) {
  3676. self._mousedownHandler = function () {
  3677. var newRange = cmd.range.cloneRange();
  3678. newRange.shrink();
  3679. if (newRange.isControl()) {
  3680. self.blur();
  3681. }
  3682. };
  3683. K(document).mousedown(self._mousedownHandler);
  3684. K(doc).keydown(function (e) {
  3685. if (e.which == 8) {
  3686. cmd.selection();
  3687. var rng = cmd.range;
  3688. if (rng.isControl()) {
  3689. rng.collapse(true);
  3690. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3691. e.preventDefault();
  3692. }
  3693. }
  3694. });
  3695. }
  3696. self.cmd = cmd;
  3697. self.html(_elementVal(self.srcElement));
  3698. if (_IE) {
  3699. doc.body.disabled = true;
  3700. doc.body.contentEditable = true;
  3701. doc.body.removeAttribute('disabled');
  3702. } else {
  3703. doc.designMode = 'on';
  3704. }
  3705. if (options.afterCreate) {
  3706. options.afterCreate.call(self);
  3707. }
  3708. }
  3709. if (isDocumentDomain) {
  3710. self.iframe.bind('load', function (e) {
  3711. self.iframe.unbind('load');
  3712. if (_IE) {
  3713. ready();
  3714. } else {
  3715. setTimeout(ready, 0);
  3716. }
  3717. });
  3718. }
  3719. self.div.append(self.iframe);
  3720. self.div.append(self.textarea);
  3721. self.srcElement.hide();
  3722. !isDocumentDomain && ready();
  3723. },
  3724. setWidth: function (val) {
  3725. var self = this;
  3726. val = _addUnit(val);
  3727. self.width = val;
  3728. self.div.css('width', val);
  3729. return self;
  3730. },
  3731. setHeight: function (val) {
  3732. var self = this;
  3733. val = _addUnit(val);
  3734. self.height = val;
  3735. self.div.css('height', val);
  3736. self.iframe.css('height', val);
  3737. if ((_IE && _V < 8) || _QUIRKS) {
  3738. val = _addUnit(_removeUnit(val) - 2);
  3739. }
  3740. self.textarea.css('height', val);
  3741. return self;
  3742. },
  3743. remove: function () {
  3744. var self = this, doc = self.doc;
  3745. K(doc.body).unbind();
  3746. K(doc).unbind();
  3747. K(self.win).unbind();
  3748. if (self._mousedownHandler) {
  3749. K(document).unbind('mousedown', self._mousedownHandler);
  3750. }
  3751. _elementVal(self.srcElement, self.html());
  3752. self.srcElement.show();
  3753. doc.write('');
  3754. self.iframe.unbind();
  3755. self.textarea.unbind();
  3756. KEdit.parent.remove.call(self);
  3757. },
  3758. html: function (val, isFull) {
  3759. var self = this, doc = self.doc;
  3760. if (self.designMode) {
  3761. var body = doc.body;
  3762. if (val === undefined) {
  3763. if (isFull) {
  3764. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3765. } else {
  3766. val = body.innerHTML;
  3767. }
  3768. if (self.beforeGetHtml) {
  3769. val = self.beforeGetHtml(val);
  3770. }
  3771. if (_GECKO && val == '<br />') {
  3772. val = '';
  3773. }
  3774. return val;
  3775. }
  3776. if (self.beforeSetHtml) {
  3777. val = self.beforeSetHtml(val);
  3778. }
  3779. if (_IE && _V >= 9) {
  3780. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3781. }
  3782. K(body).html(val);
  3783. if (self.afterSetHtml) {
  3784. self.afterSetHtml();
  3785. }
  3786. return self;
  3787. }
  3788. if (val === undefined) {
  3789. return self.textarea.val();
  3790. }
  3791. self.textarea.val(val);
  3792. return self;
  3793. },
  3794. design: function (bool) {
  3795. var self = this, val;
  3796. if (bool === undefined ? !self.designMode : bool) {
  3797. if (!self.designMode) {
  3798. val = self.html();
  3799. self.designMode = true;
  3800. self.html(val);
  3801. self.textarea.hide();
  3802. self.iframe.show();
  3803. }
  3804. } else {
  3805. if (self.designMode) {
  3806. val = self.html();
  3807. self.designMode = false;
  3808. self.html(val);
  3809. self.iframe.hide();
  3810. self.textarea.show();
  3811. }
  3812. }
  3813. return self.focus();
  3814. },
  3815. focus: function () {
  3816. var self = this;
  3817. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3818. return self;
  3819. },
  3820. blur: function () {
  3821. var self = this;
  3822. if (_IE) {
  3823. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3824. self.div.append(input);
  3825. input[0].focus();
  3826. input.remove();
  3827. } else {
  3828. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3829. }
  3830. return self;
  3831. },
  3832. afterChange: function (fn) {
  3833. var self = this, doc = self.doc, body = doc.body;
  3834. K(doc).keyup(function (e) {
  3835. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3836. fn(e);
  3837. }
  3838. });
  3839. K(doc).mouseup(fn).contextmenu(fn);
  3840. K(self.win).blur(fn);
  3841. function timeoutHandler(e) {
  3842. setTimeout(function () {
  3843. fn(e);
  3844. }, 1);
  3845. }
  3846. K(body).bind('paste', timeoutHandler);
  3847. K(body).bind('cut', timeoutHandler);
  3848. return self;
  3849. }
  3850. });
  3851. function _edit(options) {
  3852. return new KEdit(options);
  3853. }
  3854. K.EditClass = KEdit;
  3855. K.edit = _edit;
  3856. K.iframeDoc = _iframeDoc;
  3857. function _selectToolbar(name, fn) {
  3858. var self = this,
  3859. knode = self.get(name);
  3860. if (knode) {
  3861. if (knode.hasClass('ke-disabled')) {
  3862. return;
  3863. }
  3864. fn(knode);
  3865. }
  3866. }
  3867. function KToolbar(options) {
  3868. this.init(options);
  3869. }
  3870. _extend(KToolbar, KWidget, {
  3871. init: function (options) {
  3872. var self = this;
  3873. KToolbar.parent.init.call(self, options);
  3874. self.disableMode = _undef(options.disableMode, false);
  3875. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3876. self._itemMap = {};
  3877. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function (e) {
  3878. e.preventDefault();
  3879. }).attr('unselectable', 'on');
  3880. function find(target) {
  3881. var knode = K(target);
  3882. if (knode.hasClass('ke-outline')) {
  3883. return knode;
  3884. }
  3885. if (knode.hasClass('ke-toolbar-icon')) {
  3886. return knode.parent();
  3887. }
  3888. }
  3889. function hover(e, method) {
  3890. var knode = find(e.target);
  3891. if (knode) {
  3892. if (knode.hasClass('ke-disabled')) {
  3893. return;
  3894. }
  3895. if (knode.hasClass('ke-selected')) {
  3896. return;
  3897. }
  3898. knode[method]('ke-on');
  3899. }
  3900. }
  3901. self.div.mouseover(function (e) {
  3902. hover(e, 'addClass');
  3903. })
  3904. .mouseout(function (e) {
  3905. hover(e, 'removeClass');
  3906. })
  3907. .click(function (e) {
  3908. var knode = find(e.target);
  3909. if (knode) {
  3910. if (knode.hasClass('ke-disabled')) {
  3911. return;
  3912. }
  3913. self.options.click.call(this, e, knode.attr('data-name'));
  3914. }
  3915. });
  3916. },
  3917. get: function (name) {
  3918. if (this._itemMap[name]) {
  3919. return this._itemMap[name];
  3920. }
  3921. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3922. },
  3923. select: function (name) {
  3924. _selectToolbar.call(this, name, function (knode) {
  3925. knode.addClass('ke-selected');
  3926. });
  3927. return self;
  3928. },
  3929. unselect: function (name) {
  3930. _selectToolbar.call(this, name, function (knode) {
  3931. knode.removeClass('ke-selected').removeClass('ke-on');
  3932. });
  3933. return self;
  3934. },
  3935. enable: function (name) {
  3936. var self = this,
  3937. knode = name.get ? name : self.get(name);
  3938. if (knode) {
  3939. knode.removeClass('ke-disabled');
  3940. knode.opacity(1);
  3941. }
  3942. return self;
  3943. },
  3944. disable: function (name) {
  3945. var self = this,
  3946. knode = name.get ? name : self.get(name);
  3947. if (knode) {
  3948. knode.removeClass('ke-selected').addClass('ke-disabled');
  3949. knode.opacity(0.5);
  3950. }
  3951. return self;
  3952. },
  3953. disableAll: function (bool, noDisableItems) {
  3954. var self = this, map = self.noDisableItemMap, item;
  3955. if (noDisableItems) {
  3956. map = _toMap(noDisableItems);
  3957. }
  3958. if (bool === undefined ? !self.disableMode : bool) {
  3959. K('span.ke-outline', self.div).each(function () {
  3960. var knode = K(this),
  3961. name = knode[0].getAttribute('data-name', 2);
  3962. if (!map[name]) {
  3963. self.disable(knode);
  3964. }
  3965. });
  3966. self.disableMode = true;
  3967. } else {
  3968. K('span.ke-outline', self.div).each(function () {
  3969. var knode = K(this),
  3970. name = knode[0].getAttribute('data-name', 2);
  3971. if (!map[name]) {
  3972. self.enable(knode);
  3973. }
  3974. });
  3975. self.disableMode = false;
  3976. }
  3977. return self;
  3978. }
  3979. });
  3980. function _toolbar(options) {
  3981. return new KToolbar(options);
  3982. }
  3983. K.ToolbarClass = KToolbar;
  3984. K.toolbar = _toolbar;
  3985. function KMenu(options) {
  3986. this.init(options);
  3987. }
  3988. _extend(KMenu, KWidget, {
  3989. init: function (options) {
  3990. var self = this;
  3991. options.z = options.z || 811213;
  3992. KMenu.parent.init.call(self, options);
  3993. self.centerLineMode = _undef(options.centerLineMode, true);
  3994. self.div.addClass('ke-menu').bind('click,mousedown', function (e) {
  3995. e.stopPropagation();
  3996. }).attr('unselectable', 'on');
  3997. },
  3998. addItem: function (item) {
  3999. var self = this;
  4000. if (item.title === '-') {
  4001. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4002. return;
  4003. }
  4004. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4005. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4006. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4007. height = _addUnit(item.height),
  4008. iconClass = _undef(item.iconClass, '');
  4009. self.div.append(itemDiv);
  4010. if (height) {
  4011. itemDiv.css('height', height);
  4012. rightDiv.css('line-height', height);
  4013. }
  4014. var centerDiv;
  4015. if (self.centerLineMode) {
  4016. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4017. if (height) {
  4018. centerDiv.css('height', height);
  4019. }
  4020. }
  4021. itemDiv.mouseover(function (e) {
  4022. K(this).addClass('ke-menu-item-on');
  4023. if (centerDiv) {
  4024. centerDiv.addClass('ke-menu-item-center-on');
  4025. }
  4026. })
  4027. .mouseout(function (e) {
  4028. K(this).removeClass('ke-menu-item-on');
  4029. if (centerDiv) {
  4030. centerDiv.removeClass('ke-menu-item-center-on');
  4031. }
  4032. })
  4033. .click(function (e) {
  4034. item.click.call(K(this));
  4035. e.stopPropagation();
  4036. })
  4037. .append(leftDiv);
  4038. if (centerDiv) {
  4039. itemDiv.append(centerDiv);
  4040. }
  4041. itemDiv.append(rightDiv);
  4042. if (item.checked) {
  4043. iconClass = 'ke-icon-checked';
  4044. }
  4045. if (iconClass !== '') {
  4046. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4047. }
  4048. rightDiv.html(item.title);
  4049. return self;
  4050. },
  4051. remove: function () {
  4052. var self = this;
  4053. if (self.options.beforeRemove) {
  4054. self.options.beforeRemove.call(self);
  4055. }
  4056. K('.ke-menu-item', self.div[0]).unbind();
  4057. KMenu.parent.remove.call(self);
  4058. return self;
  4059. }
  4060. });
  4061. function _menu(options) {
  4062. return new KMenu(options);
  4063. }
  4064. K.MenuClass = KMenu;
  4065. K.menu = _menu;
  4066. function KColorPicker(options) {
  4067. this.init(options);
  4068. }
  4069. _extend(KColorPicker, KWidget, {
  4070. init: function (options) {
  4071. var self = this;
  4072. options.z = options.z || 811213;
  4073. KColorPicker.parent.init.call(self, options);
  4074. var colors = options.colors || [
  4075. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4076. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4077. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4078. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4079. ];
  4080. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4081. self._cells = [];
  4082. self.div.addClass('ke-colorpicker').bind('click,mousedown', function (e) {
  4083. e.stopPropagation();
  4084. }).attr('unselectable', 'on');
  4085. var table = self.doc.createElement('table');
  4086. self.div.append(table);
  4087. table.className = 'ke-colorpicker-table';
  4088. table.cellPadding = 0;
  4089. table.cellSpacing = 0;
  4090. table.border = 0;
  4091. var row = table.insertRow(0), cell = row.insertCell(0);
  4092. cell.colSpan = colors[0].length;
  4093. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4094. for (var i = 0; i < colors.length; i++) {
  4095. row = table.insertRow(i + 1);
  4096. for (var j = 0; j < colors[i].length; j++) {
  4097. cell = row.insertCell(j);
  4098. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4099. }
  4100. }
  4101. },
  4102. _addAttr: function (cell, color, cls) {
  4103. var self = this;
  4104. cell = K(cell).addClass(cls);
  4105. if (self.selectedColor === color.toLowerCase()) {
  4106. cell.addClass('ke-colorpicker-cell-selected');
  4107. }
  4108. cell.attr('title', color || self.options.noColor);
  4109. cell.mouseover(function (e) {
  4110. K(this).addClass('ke-colorpicker-cell-on');
  4111. });
  4112. cell.mouseout(function (e) {
  4113. K(this).removeClass('ke-colorpicker-cell-on');
  4114. });
  4115. cell.click(function (e) {
  4116. e.stop();
  4117. self.options.click.call(K(this), color);
  4118. });
  4119. if (color) {
  4120. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4121. } else {
  4122. cell.html(self.options.noColor);
  4123. }
  4124. K(cell).attr('unselectable', 'on');
  4125. self._cells.push(cell);
  4126. },
  4127. remove: function () {
  4128. var self = this;
  4129. _each(self._cells, function () {
  4130. this.unbind();
  4131. });
  4132. KColorPicker.parent.remove.call(self);
  4133. return self;
  4134. }
  4135. });
  4136. function _colorpicker(options) {
  4137. return new KColorPicker(options);
  4138. }
  4139. K.ColorPickerClass = KColorPicker;
  4140. K.colorpicker = _colorpicker;
  4141. function KUploadButton(options) {
  4142. this.init(options);
  4143. }
  4144. _extend(KUploadButton, {
  4145. init: function (options) {
  4146. var self = this,
  4147. button = K(options.button),
  4148. fieldName = options.fieldName || 'file',
  4149. url = options.url || '',
  4150. title = button.val(),
  4151. extraParams = options.extraParams || {},
  4152. cls = button[0].className || '',
  4153. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4154. options.afterError = options.afterError || function (str) {
  4155. alert(str);
  4156. };
  4157. var hiddenElements = [];
  4158. for (var k in extraParams) {
  4159. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4160. }
  4161. var html = [
  4162. '<div class="ke-inline-block ' + cls + '">',
  4163. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4164. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4165. '<span class="ke-button-common">',
  4166. hiddenElements.join(''),
  4167. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4168. '</span>',
  4169. '<input type="file" class="ke-upload-file" id="NameToTitle" name="' + fieldName + '" tabindex="-1" />',
  4170. (options.form ? '</div>' : '</form>'),
  4171. '</div>'].join('');
  4172. var div = K(html, button.doc);
  4173. button.hide();
  4174. button.before(div);
  4175. self.div = div;
  4176. self.button = button;
  4177. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4178. self.form = options.form ? K(options.form) : K('form', div);
  4179. self.fileBox = K('.ke-upload-file', div);
  4180. var width = options.width || K('.ke-button-common', div).width();
  4181. K('.ke-upload-area', div).width(width);
  4182. self.options = options;
  4183. },
  4184. submit: function () {
  4185. var self = this,
  4186. iframe = self.iframe;
  4187. iframe.bind('load', function () {
  4188. iframe.unbind();
  4189. var tempForm = document.createElement('form');
  4190. self.fileBox.before(tempForm);
  4191. K(tempForm).append(self.fileBox);
  4192. tempForm.reset();
  4193. K(tempForm).remove(true);
  4194. var doc = K.iframeDoc(iframe),
  4195. pre = doc.getElementsByTagName('pre')[0],
  4196. str = '', data;
  4197. if (pre) {
  4198. str = pre.innerHTML;
  4199. } else {
  4200. str = doc.body.innerHTML;
  4201. }
  4202. str = _unescape(str);
  4203. iframe[0].src = 'javascript:false';
  4204. try {
  4205. data = K.json(str);
  4206. } catch (e) {
  4207. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4208. }
  4209. if (data) {
  4210. self.options.afterUpload.call(self, data);
  4211. }
  4212. });
  4213. self.form[0].submit();
  4214. return self;
  4215. },
  4216. remove: function () {
  4217. var self = this;
  4218. if (self.fileBox) {
  4219. self.fileBox.unbind();
  4220. }
  4221. self.iframe.remove();
  4222. self.div.remove();
  4223. self.button.show();
  4224. return self;
  4225. }
  4226. });
  4227. function _uploadbutton(options) {
  4228. return new KUploadButton(options);
  4229. }
  4230. K.UploadButtonClass = KUploadButton;
  4231. K.uploadbutton = _uploadbutton;
  4232. function _createButton(arg) {
  4233. arg = arg || {};
  4234. var name = arg.name || '',
  4235. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4236. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4237. if (arg.click) {
  4238. btn.click(arg.click);
  4239. }
  4240. span.append(btn);
  4241. return span;
  4242. }
  4243. function KDialog(options) {
  4244. this.init(options);
  4245. }
  4246. _extend(KDialog, KWidget, {
  4247. init: function (options) {
  4248. var self = this;
  4249. var shadowMode = _undef(options.shadowMode, true);
  4250. options.z = options.z || 811213;
  4251. options.shadowMode = false;
  4252. options.autoScroll = _undef(options.autoScroll, true);
  4253. KDialog.parent.init.call(self, options);
  4254. var title = options.title,
  4255. body = K(options.body, self.doc),
  4256. previewBtn = options.previewBtn,
  4257. yesBtn = options.yesBtn,
  4258. noBtn = options.noBtn,
  4259. closeBtn = options.closeBtn,
  4260. showMask = _undef(options.showMask, true);
  4261. self.div.addClass('ke-dialog').bind('click,mousedown', function (e) {
  4262. e.stopPropagation();
  4263. });
  4264. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4265. if (_IE && _V < 7) {
  4266. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4267. } else if (shadowMode) {
  4268. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4269. }
  4270. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4271. contentDiv.append(headerDiv);
  4272. headerDiv.html(title);
  4273. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4274. headerDiv.append(self.closeIcon);
  4275. self.draggable({
  4276. clickEl: headerDiv,
  4277. beforeDrag: options.beforeDrag
  4278. });
  4279. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4280. contentDiv.append(bodyDiv);
  4281. bodyDiv.append(body);
  4282. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4283. if (previewBtn || yesBtn || noBtn) {
  4284. contentDiv.append(footerDiv);
  4285. }
  4286. _each([
  4287. { btn: previewBtn, name: 'preview' },
  4288. { btn: yesBtn, name: 'yes' },
  4289. { btn: noBtn, name: 'no' }
  4290. ], function () {
  4291. if (this.btn) {
  4292. var button = _createButton(this.btn);
  4293. button.addClass('ke-dialog-' + this.name);
  4294. footerDiv.append(button);
  4295. }
  4296. });
  4297. if (self.height) {
  4298. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4299. }
  4300. self.div.width(self.div.width());
  4301. self.div.height(self.div.height());
  4302. self.mask = null;
  4303. if (showMask) {
  4304. var docEl = _docElement(self.doc),
  4305. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4306. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4307. self.mask = _widget({
  4308. x: 0,
  4309. y: 0,
  4310. z: self.z - 1,
  4311. cls: 'ke-dialog-mask',
  4312. width: docWidth,
  4313. height: docHeight
  4314. });
  4315. }
  4316. self.autoPos(self.div.width(), self.div.height());
  4317. self.footerDiv = footerDiv;
  4318. self.bodyDiv = bodyDiv;
  4319. self.headerDiv = headerDiv;
  4320. self.isLoading = false;
  4321. },
  4322. setMaskIndex: function (z) {
  4323. var self = this;
  4324. self.mask.div.css('z-index', z);
  4325. },
  4326. showLoading: function (msg) {
  4327. msg = _undef(msg, '');
  4328. var self = this, body = self.bodyDiv;
  4329. 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>')
  4330. .width(body.width()).height(body.height())
  4331. .css('top', self.headerDiv.height() + 'px');
  4332. body.css('visibility', 'hidden').after(self.loading);
  4333. self.isLoading = true;
  4334. return self;
  4335. },
  4336. hideLoading: function () {
  4337. this.loading && this.loading.remove();
  4338. this.bodyDiv.css('visibility', 'visible');
  4339. this.isLoading = false;
  4340. return this;
  4341. },
  4342. remove: function () {
  4343. var self = this;
  4344. if (self.options.beforeRemove) {
  4345. self.options.beforeRemove.call(self);
  4346. }
  4347. self.mask && self.mask.remove();
  4348. self.iframeMask && self.iframeMask.remove();
  4349. self.closeIcon.unbind();
  4350. K('input', self.div).unbind();
  4351. K('button', self.div).unbind();
  4352. self.footerDiv.unbind();
  4353. self.bodyDiv.unbind();
  4354. self.headerDiv.unbind();
  4355. K('iframe', self.div).each(function () {
  4356. K(this).remove();
  4357. });
  4358. KDialog.parent.remove.call(self);
  4359. return self;
  4360. }
  4361. });
  4362. function _dialog(options) {
  4363. return new KDialog(options);
  4364. }
  4365. K.DialogClass = KDialog;
  4366. K.dialog = _dialog;
  4367. function _tabs(options) {
  4368. var self = _widget(options),
  4369. remove = self.remove,
  4370. afterSelect = options.afterSelect,
  4371. div = self.div,
  4372. liList = [];
  4373. div.addClass('ke-tabs')
  4374. .bind('contextmenu,mousedown,mousemove', function (e) {
  4375. e.preventDefault();
  4376. });
  4377. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4378. div.append(ul);
  4379. self.add = function (tab) {
  4380. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4381. li.data('tab', tab);
  4382. liList.push(li);
  4383. ul.append(li);
  4384. };
  4385. self.selectedIndex = 0;
  4386. self.select = function (index) {
  4387. self.selectedIndex = index;
  4388. _each(liList, function (i, li) {
  4389. li.unbind();
  4390. if (i === index) {
  4391. li.addClass('ke-tabs-li-selected');
  4392. K(li.data('tab').panel).show('');
  4393. } else {
  4394. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4395. .mouseover(function () {
  4396. K(this).addClass('ke-tabs-li-on');
  4397. })
  4398. .mouseout(function () {
  4399. K(this).removeClass('ke-tabs-li-on');
  4400. })
  4401. .click(function () {
  4402. self.select(i);
  4403. });
  4404. K(li.data('tab').panel).hide();
  4405. }
  4406. });
  4407. if (afterSelect) {
  4408. afterSelect.call(self, index);
  4409. }
  4410. };
  4411. self.remove = function () {
  4412. _each(liList, function () {
  4413. this.remove();
  4414. });
  4415. ul.remove();
  4416. remove.call(self);
  4417. };
  4418. return self;
  4419. }
  4420. K.tabs = _tabs;
  4421. function _loadScript(url, fn) {
  4422. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4423. script = document.createElement('script');
  4424. head.appendChild(script);
  4425. script.src = url;
  4426. script.charset = 'utf-8';
  4427. script.onload = script.onreadystatechange = function () {
  4428. if (!this.readyState || this.readyState === 'loaded') {
  4429. if (fn) {
  4430. fn();
  4431. }
  4432. script.onload = script.onreadystatechange = null;
  4433. head.removeChild(script);
  4434. }
  4435. };
  4436. }
  4437. function _chopQuery(url) {
  4438. var index = url.indexOf('?');
  4439. return index > 0 ? url.substr(0, index) : url;
  4440. }
  4441. function _loadStyle(url) {
  4442. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4443. link = document.createElement('link'),
  4444. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4445. var links = K('link[rel="stylesheet"]', head);
  4446. for (var i = 0, len = links.length; i < len; i++) {
  4447. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4448. return;
  4449. }
  4450. }
  4451. head.appendChild(link);
  4452. link.href = url;
  4453. link.rel = 'stylesheet';
  4454. }
  4455. function _ajax(url, fn, method, param, dataType) {
  4456. method = method || 'GET';
  4457. dataType = dataType || 'json';
  4458. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4459. xhr.open(method, url, true);
  4460. xhr.onreadystatechange = function () {
  4461. if (xhr.readyState == 4 && xhr.status == 200) {
  4462. if (fn) {
  4463. var data = _trim(xhr.responseText);
  4464. if (dataType == 'json') {
  4465. data = _json(data);
  4466. }
  4467. fn(data);
  4468. }
  4469. }
  4470. };
  4471. if (method == 'POST') {
  4472. var params = [];
  4473. _each(param, function (key, val) {
  4474. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4475. });
  4476. try {
  4477. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4478. } catch (e) { }
  4479. xhr.send(params.join('&'));
  4480. } else {
  4481. xhr.send(null);
  4482. }
  4483. }
  4484. K.loadScript = _loadScript;
  4485. K.loadStyle = _loadStyle;
  4486. K.ajax = _ajax;
  4487. var _plugins = {};
  4488. function _plugin(name, fn) {
  4489. if (name === undefined) {
  4490. return _plugins;
  4491. }
  4492. if (!fn) {
  4493. return _plugins[name];
  4494. }
  4495. _plugins[name] = fn;
  4496. }
  4497. var _language = {};
  4498. function _parseLangKey(key) {
  4499. var match, ns = 'core';
  4500. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4501. ns = match[1];
  4502. key = match[2];
  4503. }
  4504. return { ns: ns, key: key };
  4505. }
  4506. function _lang(mixed, langType) {
  4507. langType = langType === undefined ? K.options.langType : langType;
  4508. if (typeof mixed === 'string') {
  4509. if (!_language[langType]) {
  4510. return 'no language';
  4511. }
  4512. var pos = mixed.length - 1;
  4513. if (mixed.substr(pos) === '.') {
  4514. return _language[langType][mixed.substr(0, pos)];
  4515. }
  4516. var obj = _parseLangKey(mixed);
  4517. return _language[langType][obj.ns][obj.key];
  4518. }
  4519. _each(mixed, function (key, val) {
  4520. var obj = _parseLangKey(key);
  4521. if (!_language[langType]) {
  4522. _language[langType] = {};
  4523. }
  4524. if (!_language[langType][obj.ns]) {
  4525. _language[langType][obj.ns] = {};
  4526. }
  4527. _language[langType][obj.ns][obj.key] = val;
  4528. });
  4529. }
  4530. function _getImageFromRange(range, fn) {
  4531. if (range.collapsed) {
  4532. return;
  4533. }
  4534. range = range.cloneRange().up();
  4535. var sc = range.startContainer, so = range.startOffset;
  4536. if (!_WEBKIT && !range.isControl()) {
  4537. return;
  4538. }
  4539. var img = K(sc.childNodes[so]);
  4540. if (!img || img.name != 'img') {
  4541. return;
  4542. }
  4543. if (fn(img)) {
  4544. return img;
  4545. }
  4546. }
  4547. function _bindContextmenuEvent() {
  4548. var self = this, doc = self.edit.doc;
  4549. K(doc).contextmenu(function (e) {
  4550. if (self.menu) {
  4551. self.hideMenu();
  4552. }
  4553. if (!self.useContextmenu) {
  4554. e.preventDefault();
  4555. return;
  4556. }
  4557. if (self._contextmenus.length === 0) {
  4558. return;
  4559. }
  4560. var maxWidth = 0, items = [];
  4561. _each(self._contextmenus, function () {
  4562. if (this.title == '-') {
  4563. items.push(this);
  4564. return;
  4565. }
  4566. if (this.cond && this.cond()) {
  4567. items.push(this);
  4568. if (this.width && this.width > maxWidth) {
  4569. maxWidth = this.width;
  4570. }
  4571. }
  4572. });
  4573. while (items.length > 0 && items[0].title == '-') {
  4574. items.shift();
  4575. }
  4576. while (items.length > 0 && items[items.length - 1].title == '-') {
  4577. items.pop();
  4578. }
  4579. var prevItem = null;
  4580. _each(items, function (i) {
  4581. if (this.title == '-' && prevItem.title == '-') {
  4582. delete items[i];
  4583. }
  4584. prevItem = this;
  4585. });
  4586. if (items.length > 0) {
  4587. e.preventDefault();
  4588. var pos = K(self.edit.iframe).pos(),
  4589. menu = _menu({
  4590. x: pos.x + e.clientX,
  4591. y: pos.y + e.clientY,
  4592. width: maxWidth,
  4593. css: { visibility: 'hidden' },
  4594. shadowMode: self.shadowMode
  4595. });
  4596. _each(items, function () {
  4597. if (this.title) {
  4598. menu.addItem(this);
  4599. }
  4600. });
  4601. var docEl = _docElement(menu.doc),
  4602. menuHeight = menu.div.height();
  4603. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4604. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4605. }
  4606. menu.div.css('visibility', 'visible');
  4607. self.menu = menu;
  4608. }
  4609. });
  4610. }
  4611. function _bindNewlineEvent() {
  4612. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4613. if (_IE && newlineTag !== 'br') {
  4614. return;
  4615. }
  4616. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4617. return;
  4618. }
  4619. if (_OPERA && _V < 9) {
  4620. return;
  4621. }
  4622. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4623. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4624. function getAncestorTagName(range) {
  4625. var ancestor = K(range.commonAncestor());
  4626. while (ancestor) {
  4627. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4628. break;
  4629. }
  4630. ancestor = ancestor.parent();
  4631. }
  4632. return ancestor.name;
  4633. }
  4634. K(doc).keydown(function (e) {
  4635. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4636. return;
  4637. }
  4638. self.cmd.selection();
  4639. var tagName = getAncestorTagName(self.cmd.range);
  4640. if (tagName == 'marquee' || tagName == 'select') {
  4641. return;
  4642. }
  4643. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4644. e.preventDefault();
  4645. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4646. return;
  4647. }
  4648. if (!pSkipTagMap[tagName]) {
  4649. _nativeCommand(doc, 'formatblock', '<p>');
  4650. }
  4651. });
  4652. K(doc).keyup(function (e) {
  4653. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4654. return;
  4655. }
  4656. if (newlineTag == 'br') {
  4657. return;
  4658. }
  4659. if (_GECKO) {
  4660. var root = self.cmd.commonAncestor('p');
  4661. var a = self.cmd.commonAncestor('a');
  4662. if (a && a.text() == '') {
  4663. a.remove(true);
  4664. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4665. self.cmd.select();
  4666. }
  4667. return;
  4668. }
  4669. self.cmd.selection();
  4670. var tagName = getAncestorTagName(self.cmd.range);
  4671. if (tagName == 'marquee' || tagName == 'select') {
  4672. return;
  4673. }
  4674. if (!pSkipTagMap[tagName]) {
  4675. _nativeCommand(doc, 'formatblock', '<p>');
  4676. }
  4677. var div = self.cmd.commonAncestor('div');
  4678. if (div) {
  4679. var p = K('<p></p>'),
  4680. child = div[0].firstChild;
  4681. while (child) {
  4682. var next = child.nextSibling;
  4683. p.append(child);
  4684. child = next;
  4685. }
  4686. div.before(p);
  4687. div.remove();
  4688. self.cmd.range.selectNodeContents(p[0]);
  4689. self.cmd.select();
  4690. }
  4691. });
  4692. }
  4693. function _bindTabEvent() {
  4694. var self = this, doc = self.edit.doc;
  4695. K(doc).keydown(function (e) {
  4696. if (e.which == 9) {
  4697. e.preventDefault();
  4698. if (self.afterTab) {
  4699. self.afterTab.call(self, e);
  4700. return;
  4701. }
  4702. var cmd = self.cmd, range = cmd.range;
  4703. range.shrink();
  4704. if (range.collapsed && range.startContainer.nodeType == 1) {
  4705. range.insertNode(K('@&nbsp;', doc)[0]);
  4706. cmd.select();
  4707. }
  4708. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4709. }
  4710. });
  4711. }
  4712. function _bindFocusEvent() {
  4713. var self = this;
  4714. K(self.edit.textarea[0], self.edit.win).focus(function (e) {
  4715. if (self.afterFocus) {
  4716. self.afterFocus.call(self, e);
  4717. }
  4718. }).blur(function (e) {
  4719. if (self.afterBlur) {
  4720. self.afterBlur.call(self, e);
  4721. }
  4722. });
  4723. }
  4724. function _removeBookmarkTag(html) {
  4725. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4726. }
  4727. function _removeTempTag(html) {
  4728. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4729. }
  4730. function _addBookmarkToStack(stack, bookmark) {
  4731. if (stack.length === 0) {
  4732. stack.push(bookmark);
  4733. return;
  4734. }
  4735. var prev = stack[stack.length - 1];
  4736. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4737. stack.push(bookmark);
  4738. }
  4739. }
  4740. function _undoToRedo(fromStack, toStack) {
  4741. var self = this, edit = self.edit,
  4742. body = edit.doc.body,
  4743. range, bookmark;
  4744. if (fromStack.length === 0) {
  4745. return self;
  4746. }
  4747. if (edit.designMode) {
  4748. range = self.cmd.range;
  4749. bookmark = range.createBookmark(true);
  4750. bookmark.html = body.innerHTML;
  4751. } else {
  4752. bookmark = {
  4753. html: body.innerHTML
  4754. };
  4755. }
  4756. _addBookmarkToStack(toStack, bookmark);
  4757. var prev = fromStack.pop();
  4758. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4759. prev = fromStack.pop();
  4760. }
  4761. if (edit.designMode) {
  4762. edit.html(prev.html);
  4763. if (prev.start) {
  4764. range.moveToBookmark(prev);
  4765. self.select();
  4766. }
  4767. } else {
  4768. K(body).html(_removeBookmarkTag(prev.html));
  4769. }
  4770. return self;
  4771. }
  4772. function KEditor(options) {
  4773. var self = this;
  4774. self.options = {};
  4775. function setOption(key, val) {
  4776. if (KEditor.prototype[key] === undefined) {
  4777. self[key] = val;
  4778. }
  4779. self.options[key] = val;
  4780. }
  4781. _each(options, function (key, val) {
  4782. setOption(key, options[key]);
  4783. });
  4784. _each(K.options, function (key, val) {
  4785. if (self[key] === undefined) {
  4786. setOption(key, val);
  4787. }
  4788. });
  4789. var se = K(self.srcElement || '<textarea/>');
  4790. if (!self.width) {
  4791. self.width = se[0].style.width || se.width();
  4792. }
  4793. if (!self.height) {
  4794. self.height = se[0].style.height || se.height();
  4795. }
  4796. setOption('width', _undef(self.width, self.minWidth));
  4797. setOption('height', _undef(self.height, self.minHeight));
  4798. setOption('width', _addUnit(self.width));
  4799. setOption('height', _addUnit(self.height));
  4800. if (_MOBILE && (!_IOS || _V < 534)) {
  4801. self.designMode = false;
  4802. }
  4803. self.srcElement = se;
  4804. self.initContent = '';
  4805. self.plugin = {};
  4806. self.isCreated = false;
  4807. self._handlers = {};
  4808. self._contextmenus = [];
  4809. self._undoStack = [];
  4810. self._redoStack = [];
  4811. self._firstAddBookmark = true;
  4812. self.menu = self.contextmenu = null;
  4813. self.dialogs = [];
  4814. }
  4815. KEditor.prototype = {
  4816. lang: function (mixed) {
  4817. return _lang(mixed, this.langType);
  4818. },
  4819. loadPlugin: function (name, fn) {
  4820. var self = this;
  4821. if (_plugins[name]) {
  4822. if (!_isFunction(_plugins[name])) {
  4823. setTimeout(function () {
  4824. self.loadPlugin(name, fn);
  4825. }, 100);
  4826. return self;
  4827. }
  4828. _plugins[name].call(self, KindEditor);
  4829. if (fn) {
  4830. fn.call(self);
  4831. }
  4832. return self;
  4833. }
  4834. _plugins[name] = 'loading';
  4835. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function () {
  4836. setTimeout(function () {
  4837. if (_plugins[name]) {
  4838. self.loadPlugin(name, fn);
  4839. }
  4840. }, 0);
  4841. });
  4842. return self;
  4843. },
  4844. handler: function (key, fn) {
  4845. var self = this;
  4846. if (!self._handlers[key]) {
  4847. self._handlers[key] = [];
  4848. }
  4849. if (_isFunction(fn)) {
  4850. self._handlers[key].push(fn);
  4851. return self;
  4852. }
  4853. _each(self._handlers[key], function () {
  4854. fn = this.call(self, fn);
  4855. });
  4856. return fn;
  4857. },
  4858. clickToolbar: function (name, fn) {
  4859. var self = this, key = 'clickToolbar' + name;
  4860. if (fn === undefined) {
  4861. if (name == "insertfile") {
  4862. setTimeout(function () {
  4863. document.getElementById("NameToTitle").addEventListener('change', function (e) {
  4864. document.getElementById("keTitle").value = e.target.files[0].name;
  4865. })
  4866. }, 1)
  4867. }
  4868. if (self._handlers[key]) {
  4869. return self.handler(key);
  4870. }
  4871. self.loadPlugin(name, function () {
  4872. self.handler(key);
  4873. });
  4874. return self;
  4875. }
  4876. return self.handler(key, fn);
  4877. },
  4878. updateState: function () {
  4879. var self = this;
  4880. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4881. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function (i, name) {
  4882. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4883. });
  4884. return self;
  4885. },
  4886. addContextmenu: function (item) {
  4887. this._contextmenus.push(item);
  4888. return this;
  4889. },
  4890. afterCreate: function (fn) {
  4891. return this.handler('afterCreate', fn);
  4892. },
  4893. beforeRemove: function (fn) {
  4894. return this.handler('beforeRemove', fn);
  4895. },
  4896. beforeGetHtml: function (fn) {
  4897. return this.handler('beforeGetHtml', fn);
  4898. },
  4899. beforeSetHtml: function (fn) {
  4900. return this.handler('beforeSetHtml', fn);
  4901. },
  4902. afterSetHtml: function (fn) {
  4903. return this.handler('afterSetHtml', fn);
  4904. },
  4905. create: function () {
  4906. var self = this, fullscreenMode = self.fullscreenMode;
  4907. if (self.isCreated) {
  4908. return self;
  4909. }
  4910. if (self.srcElement.data('kindeditor')) {
  4911. return self;
  4912. }
  4913. self.srcElement.data('kindeditor', 'true');
  4914. if (fullscreenMode) {
  4915. _docElement().style.overflow = 'hidden';
  4916. } else {
  4917. _docElement().style.overflow = '';
  4918. }
  4919. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4920. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4921. if ((_IE && _V < 8) || _QUIRKS) {
  4922. height = _addUnit(_removeUnit(height) + 2);
  4923. }
  4924. var container = self.container = K(self.layout);
  4925. if (fullscreenMode) {
  4926. K(document.body).append(container);
  4927. } else {
  4928. self.srcElement.before(container);
  4929. }
  4930. var toolbarDiv = K('.toolbar', container),
  4931. editDiv = K('.edit', container),
  4932. statusbar = self.statusbar = K('.statusbar', container);
  4933. container.removeClass('container')
  4934. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4935. if (fullscreenMode) {
  4936. container.css({
  4937. position: 'absolute',
  4938. left: 0,
  4939. top: 0,
  4940. 'z-index': 811211
  4941. });
  4942. if (!_GECKO) {
  4943. self._scrollPos = _getScrollPos();
  4944. }
  4945. window.scrollTo(0, 0);
  4946. K(document.body).css({
  4947. 'height': '1px',
  4948. 'overflow': 'hidden'
  4949. });
  4950. K(document.body.parentNode).css('overflow', 'hidden');
  4951. self._fullscreenExecuted = true;
  4952. } else {
  4953. if (self._fullscreenExecuted) {
  4954. K(document.body).css({
  4955. 'height': '',
  4956. 'overflow': ''
  4957. });
  4958. K(document.body.parentNode).css('overflow', '');
  4959. }
  4960. if (self._scrollPos) {
  4961. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4962. }
  4963. }
  4964. var htmlList = [];
  4965. K.each(self.items, function (i, name) {
  4966. if (name == '|') {
  4967. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4968. } else if (name == '/') {
  4969. htmlList.push('<div class="ke-hr"></div>');
  4970. } else {
  4971. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4972. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4973. }
  4974. });
  4975. var toolbar = self.toolbar = _toolbar({
  4976. src: toolbarDiv,
  4977. html: htmlList.join(''),
  4978. noDisableItems: self.noDisableItems,
  4979. click: function (e, name) {
  4980. e.stop();
  4981. if (self.menu) {
  4982. var menuName = self.menu.name;
  4983. self.hideMenu();
  4984. if (menuName === name) {
  4985. return;
  4986. }
  4987. }
  4988. self.clickToolbar(name);
  4989. }
  4990. });
  4991. var editHeight = _removeUnit(height) - toolbar.div.height();
  4992. var edit = self.edit = _edit({
  4993. height: editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  4994. src: editDiv,
  4995. srcElement: self.srcElement,
  4996. designMode: self.designMode,
  4997. themesPath: self.themesPath,
  4998. bodyClass: self.bodyClass,
  4999. cssPath: self.cssPath,
  5000. cssData: self.cssData,
  5001. beforeGetHtml: function (html) {
  5002. html = self.beforeGetHtml(html);
  5003. html = _removeBookmarkTag(_removeTempTag(html));
  5004. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5005. },
  5006. beforeSetHtml: function (html) {
  5007. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5008. return self.beforeSetHtml(html);
  5009. },
  5010. afterSetHtml: function () {
  5011. self.edit = edit = this;
  5012. self.afterSetHtml();
  5013. },
  5014. afterCreate: function () {
  5015. self.edit = edit = this;
  5016. self.cmd = edit.cmd;
  5017. self._docMousedownFn = function (e) {
  5018. if (self.menu) {
  5019. self.hideMenu();
  5020. }
  5021. };
  5022. K(edit.doc, document).mousedown(self._docMousedownFn);
  5023. _bindContextmenuEvent.call(self);
  5024. _bindNewlineEvent.call(self);
  5025. _bindTabEvent.call(self);
  5026. _bindFocusEvent.call(self);
  5027. edit.afterChange(function (e) {
  5028. if (!edit.designMode) {
  5029. return;
  5030. }
  5031. self.updateState();
  5032. self.addBookmark();
  5033. if (self.options.afterChange) {
  5034. self.options.afterChange.call(self);
  5035. }
  5036. });
  5037. edit.textarea.keyup(function (e) {
  5038. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5039. if (self.options.afterChange) {
  5040. self.options.afterChange.call(self);
  5041. }
  5042. }
  5043. });
  5044. if (self.readonlyMode) {
  5045. self.readonly();
  5046. }
  5047. self.isCreated = true;
  5048. if (self.initContent === '') {
  5049. self.initContent = self.html();
  5050. }
  5051. if (self._undoStack.length > 0) {
  5052. var prev = self._undoStack.pop();
  5053. if (prev.start) {
  5054. self.html(prev.html);
  5055. edit.cmd.range.moveToBookmark(prev);
  5056. self.select();
  5057. }
  5058. }
  5059. self.afterCreate();
  5060. if (self.options.afterCreate) {
  5061. self.options.afterCreate.call(self);
  5062. }
  5063. }
  5064. });
  5065. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5066. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5067. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5068. if (self._fullscreenResizeHandler) {
  5069. K(window).unbind('resize', self._fullscreenResizeHandler);
  5070. self._fullscreenResizeHandler = null;
  5071. }
  5072. function initResize() {
  5073. if (statusbar.height() === 0) {
  5074. setTimeout(initResize, 100);
  5075. return;
  5076. }
  5077. self.resize(width, height, false);
  5078. }
  5079. initResize();
  5080. if (fullscreenMode) {
  5081. self._fullscreenResizeHandler = function (e) {
  5082. if (self.isCreated) {
  5083. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5084. }
  5085. };
  5086. K(window).bind('resize', self._fullscreenResizeHandler);
  5087. toolbar.select('fullscreen');
  5088. statusbar.first().css('visibility', 'hidden');
  5089. statusbar.last().css('visibility', 'hidden');
  5090. } else {
  5091. if (_GECKO) {
  5092. K(window).bind('scroll', function (e) {
  5093. self._scrollPos = _getScrollPos();
  5094. });
  5095. }
  5096. if (self.resizeType > 0) {
  5097. _drag({
  5098. moveEl: container,
  5099. clickEl: statusbar,
  5100. moveFn: function (x, y, width, height, diffX, diffY) {
  5101. height += diffY;
  5102. self.resize(null, height);
  5103. }
  5104. });
  5105. } else {
  5106. statusbar.first().css('visibility', 'hidden');
  5107. }
  5108. if (self.resizeType === 2) {
  5109. _drag({
  5110. moveEl: container,
  5111. clickEl: statusbar.last(),
  5112. moveFn: function (x, y, width, height, diffX, diffY) {
  5113. width += diffX;
  5114. height += diffY;
  5115. self.resize(width, height);
  5116. }
  5117. });
  5118. } else {
  5119. statusbar.last().css('visibility', 'hidden');
  5120. }
  5121. }
  5122. return self;
  5123. },
  5124. remove: function () {
  5125. var self = this;
  5126. if (!self.isCreated) {
  5127. return self;
  5128. }
  5129. self.beforeRemove();
  5130. self.srcElement.data('kindeditor', '');
  5131. if (self.menu) {
  5132. self.hideMenu();
  5133. }
  5134. _each(self.dialogs, function () {
  5135. self.hideDialog();
  5136. });
  5137. K(document).unbind('mousedown', self._docMousedownFn);
  5138. self.toolbar.remove();
  5139. self.edit.remove();
  5140. self.statusbar.last().unbind();
  5141. self.statusbar.unbind();
  5142. self.container.remove();
  5143. self.container = self.toolbar = self.edit = self.menu = null;
  5144. self.dialogs = [];
  5145. self.isCreated = false;
  5146. return self;
  5147. },
  5148. resize: function (width, height, updateProp) {
  5149. var self = this;
  5150. updateProp = _undef(updateProp, true);
  5151. if (width) {
  5152. if (!/%/.test(width)) {
  5153. width = _removeUnit(width);
  5154. width = width < self.minWidth ? self.minWidth : width;
  5155. }
  5156. self.container.css('width', _addUnit(width));
  5157. if (updateProp) {
  5158. self.width = _addUnit(width);
  5159. }
  5160. }
  5161. if (height) {
  5162. height = _removeUnit(height);
  5163. editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5164. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5165. self.edit.setHeight(editHeight);
  5166. if (updateProp) {
  5167. self.height = _addUnit(height);
  5168. }
  5169. }
  5170. return self;
  5171. },
  5172. select: function () {
  5173. this.isCreated && this.cmd.select();
  5174. return this;
  5175. },
  5176. html: function (val) {
  5177. var self = this;
  5178. if (val === undefined) {
  5179. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5180. }
  5181. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5182. if (self.isCreated) {
  5183. self.cmd.selection();
  5184. }
  5185. return self;
  5186. },
  5187. fullHtml: function () {
  5188. return this.isCreated ? this.edit.html(undefined, true) : '';
  5189. },
  5190. text: function (val) {
  5191. var self = this;
  5192. if (val === undefined) {
  5193. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5194. } else {
  5195. return self.html(_escape(val));
  5196. }
  5197. },
  5198. isEmpty: function () {
  5199. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5200. },
  5201. isDirty: function () {
  5202. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5203. },
  5204. selectedHtml: function () {
  5205. var val = this.isCreated ? this.cmd.range.html() : '';
  5206. val = _removeBookmarkTag(_removeTempTag(val));
  5207. return val;
  5208. },
  5209. count: function (mode) {
  5210. var self = this;
  5211. mode = (mode || 'html').toLowerCase();
  5212. if (mode === 'html') {
  5213. return self.html().length;
  5214. }
  5215. if (mode === 'text') {
  5216. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5217. }
  5218. return 0;
  5219. },
  5220. exec: function (key) {
  5221. key = key.toLowerCase();
  5222. var self = this, cmd = self.cmd,
  5223. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5224. if (changeFlag) {
  5225. self.addBookmark(false);
  5226. }
  5227. cmd[key].apply(cmd, _toArray(arguments, 1));
  5228. if (changeFlag) {
  5229. self.updateState();
  5230. self.addBookmark(false);
  5231. if (self.options.afterChange) {
  5232. self.options.afterChange.call(self);
  5233. }
  5234. }
  5235. return self;
  5236. },
  5237. insertHtml: function (val, quickMode) {
  5238. if (!this.isCreated) {
  5239. return this;
  5240. }
  5241. val = this.beforeSetHtml(val);
  5242. this.exec('inserthtml', val, quickMode);
  5243. return this;
  5244. },
  5245. appendHtml: function (val) {
  5246. this.html(this.html() + val);
  5247. if (this.isCreated) {
  5248. var cmd = this.cmd;
  5249. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5250. cmd.select();
  5251. }
  5252. return this;
  5253. },
  5254. sync: function () {
  5255. _elementVal(this.srcElement, this.html());
  5256. return this;
  5257. },
  5258. focus: function () {
  5259. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5260. return this;
  5261. },
  5262. blur: function () {
  5263. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5264. return this;
  5265. },
  5266. addBookmark: function (checkSize) {
  5267. checkSize = _undef(checkSize, true);
  5268. var self = this, edit = self.edit,
  5269. body = edit.doc.body,
  5270. html = _removeTempTag(body.innerHTML), bookmark;
  5271. if (checkSize && self._undoStack.length > 0) {
  5272. var prev = self._undoStack[self._undoStack.length - 1];
  5273. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5274. return self;
  5275. }
  5276. }
  5277. if (edit.designMode && !self._firstAddBookmark) {
  5278. var range = self.cmd.range;
  5279. bookmark = range.createBookmark(true);
  5280. bookmark.html = _removeTempTag(body.innerHTML);
  5281. range.moveToBookmark(bookmark);
  5282. } else {
  5283. bookmark = {
  5284. html: html
  5285. };
  5286. }
  5287. self._firstAddBookmark = false;
  5288. _addBookmarkToStack(self._undoStack, bookmark);
  5289. return self;
  5290. },
  5291. undo: function () {
  5292. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5293. },
  5294. redo: function () {
  5295. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5296. },
  5297. fullscreen: function (bool) {
  5298. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5299. this.addBookmark(false);
  5300. return this.remove().create();
  5301. },
  5302. readonly: function (isReadonly) {
  5303. isReadonly = _undef(isReadonly, true);
  5304. var self = this, edit = self.edit, doc = edit.doc;
  5305. if (self.designMode) {
  5306. self.toolbar.disableAll(isReadonly, []);
  5307. } else {
  5308. _each(self.noDisableItems, function () {
  5309. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5310. });
  5311. }
  5312. if (_IE) {
  5313. doc.body.contentEditable = !isReadonly;
  5314. } else {
  5315. doc.designMode = isReadonly ? 'off' : 'on';
  5316. }
  5317. edit.textarea[0].disabled = isReadonly;
  5318. },
  5319. createMenu: function (options) {
  5320. var self = this,
  5321. name = options.name,
  5322. knode = self.toolbar.get(name),
  5323. pos = knode.pos();
  5324. options.x = pos.x;
  5325. options.y = pos.y + knode.height();
  5326. options.z = self.options.zIndex;
  5327. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5328. if (options.selectedColor !== undefined) {
  5329. options.cls = 'ke-colorpicker-' + self.themeType;
  5330. options.noColor = self.lang('noColor');
  5331. self.menu = _colorpicker(options);
  5332. } else {
  5333. options.cls = 'ke-menu-' + self.themeType;
  5334. options.centerLineMode = false;
  5335. self.menu = _menu(options);
  5336. }
  5337. return self.menu;
  5338. },
  5339. hideMenu: function () {
  5340. this.menu.remove();
  5341. this.menu = null;
  5342. return this;
  5343. },
  5344. hideContextmenu: function () {
  5345. this.contextmenu.remove();
  5346. this.contextmenu = null;
  5347. return this;
  5348. },
  5349. createDialog: function (options) {
  5350. var self = this, name = options.name;
  5351. options.z = self.options.zIndex;
  5352. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5353. options.closeBtn = _undef(options.closeBtn, {
  5354. name: self.lang('close'),
  5355. click: function (e) {
  5356. self.hideDialog();
  5357. if (_IE && self.cmd) {
  5358. self.cmd.select();
  5359. }
  5360. }
  5361. });
  5362. options.noBtn = _undef(options.noBtn, {
  5363. name: self.lang(options.yesBtn ? 'no' : 'close'),
  5364. click: function (e) {
  5365. self.hideDialog();
  5366. if (_IE && self.cmd) {
  5367. self.cmd.select();
  5368. }
  5369. }
  5370. });
  5371. if (self.dialogAlignType != 'page') {
  5372. options.alignEl = self.container;
  5373. }
  5374. options.cls = 'ke-dialog-' + self.themeType;
  5375. if (self.dialogs.length > 0) {
  5376. var firstDialog = self.dialogs[0],
  5377. parentDialog = self.dialogs[self.dialogs.length - 1];
  5378. firstDialog.setMaskIndex(parentDialog.z + 2);
  5379. options.z = parentDialog.z + 3;
  5380. options.showMask = false;
  5381. }
  5382. var dialog = _dialog(options);
  5383. self.dialogs.push(dialog);
  5384. return dialog;
  5385. },
  5386. hideDialog: function () {
  5387. var self = this;
  5388. if (self.dialogs.length > 0) {
  5389. self.dialogs.pop().remove();
  5390. }
  5391. if (self.dialogs.length > 0) {
  5392. var firstDialog = self.dialogs[0],
  5393. parentDialog = self.dialogs[self.dialogs.length - 1];
  5394. firstDialog.setMaskIndex(parentDialog.z - 1);
  5395. }
  5396. return self;
  5397. },
  5398. errorDialog: function (html) {
  5399. var self = this;
  5400. var dialog = self.createDialog({
  5401. width: 750,
  5402. title: self.lang('uploadError'),
  5403. body: '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5404. });
  5405. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5406. doc.open();
  5407. doc.write(html);
  5408. doc.close();
  5409. K(doc.body).css('background-color', '#FFF');
  5410. iframe[0].contentWindow.focus();
  5411. return self;
  5412. }
  5413. };
  5414. function _editor(options) {
  5415. return new KEditor(options);
  5416. }
  5417. _instances = [];
  5418. function _create(expr, options) {
  5419. options = options || {};
  5420. options.basePath = _undef(options.basePath, K.basePath);
  5421. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5422. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5423. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5424. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5425. var themeType = _undef(options.themeType, K.options.themeType);
  5426. _loadStyle(options.themesPath + 'default/default.css');
  5427. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5428. }
  5429. function create(editor) {
  5430. _each(_plugins, function (name, fn) {
  5431. if (_isFunction(fn)) {
  5432. fn.call(editor, KindEditor);
  5433. }
  5434. });
  5435. return editor.create();
  5436. }
  5437. var knode = K(expr);
  5438. if (!knode || knode.length === 0) {
  5439. return;
  5440. }
  5441. if (knode.length > 1) {
  5442. knode.each(function () {
  5443. _create(this, options);
  5444. });
  5445. return _instances[0];
  5446. }
  5447. options.srcElement = knode[0];
  5448. var editor = new KEditor(options);
  5449. _instances.push(editor);
  5450. if (_language[editor.langType]) {
  5451. return create(editor);
  5452. }
  5453. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function () {
  5454. create(editor);
  5455. });
  5456. return editor;
  5457. }
  5458. function _eachEditor(expr, fn) {
  5459. K(expr).each(function (i, el) {
  5460. K.each(_instances, function (j, editor) {
  5461. if (editor && editor.srcElement[0] == el) {
  5462. fn.call(editor, j);
  5463. return false;
  5464. }
  5465. });
  5466. });
  5467. }
  5468. K.remove = function (expr) {
  5469. _eachEditor(expr, function (i) {
  5470. this.remove();
  5471. _instances.splice(i, 1);
  5472. });
  5473. };
  5474. K.sync = function (expr) {
  5475. _eachEditor(expr, function () {
  5476. this.sync();
  5477. });
  5478. };
  5479. K.html = function (expr, val) {
  5480. _eachEditor(expr, function () {
  5481. this.html(val);
  5482. });
  5483. };
  5484. K.insertHtml = function (expr, val) {
  5485. _eachEditor(expr, function () {
  5486. this.insertHtml(val);
  5487. });
  5488. };
  5489. K.appendHtml = function (expr, val) {
  5490. _eachEditor(expr, function () {
  5491. this.appendHtml(val);
  5492. });
  5493. };
  5494. if (_IE && _V < 7) {
  5495. _nativeCommand(document, 'BackgroundImageCache', true);
  5496. }
  5497. K.EditorClass = KEditor;
  5498. K.editor = _editor;
  5499. K.create = _create;
  5500. K.instances = _instances;
  5501. K.plugin = _plugin;
  5502. K.lang = _lang;
  5503. _plugin('core', function (K) {
  5504. var self = this,
  5505. shortcutKeys = {
  5506. undo: 'Z', redo: 'Y', bold: 'B', italic: 'I', underline: 'U', print: 'P', selectall: 'A'
  5507. };
  5508. self.afterSetHtml(function () {
  5509. if (self.options.afterChange) {
  5510. self.options.afterChange.call(self);
  5511. }
  5512. });
  5513. self.afterCreate(function () {
  5514. if (self.syncType != 'form') {
  5515. return;
  5516. }
  5517. var el = K(self.srcElement), hasForm = false;
  5518. while ((el = el.parent())) {
  5519. if (el.name == 'form') {
  5520. hasForm = true;
  5521. break;
  5522. }
  5523. }
  5524. if (hasForm) {
  5525. el.bind('submit', function (e) {
  5526. self.sync();
  5527. K(window).bind('unload', function () {
  5528. self.edit.textarea.remove();
  5529. });
  5530. });
  5531. var resetBtn = K('[type="reset"]', el);
  5532. resetBtn.click(function () {
  5533. self.html(self.initContent);
  5534. self.cmd.selection();
  5535. });
  5536. self.beforeRemove(function () {
  5537. el.unbind();
  5538. resetBtn.unbind();
  5539. });
  5540. }
  5541. });
  5542. self.clickToolbar('source', function () {
  5543. if (self.edit.designMode) {
  5544. self.toolbar.disableAll(true);
  5545. self.edit.design(false);
  5546. self.toolbar.select('source');
  5547. } else {
  5548. self.toolbar.disableAll(false);
  5549. self.edit.design(true);
  5550. self.toolbar.unselect('source');
  5551. if (_GECKO) {
  5552. setTimeout(function () {
  5553. self.cmd.selection();
  5554. }, 0);
  5555. } else {
  5556. self.cmd.selection();
  5557. }
  5558. }
  5559. self.designMode = self.edit.designMode;
  5560. });
  5561. self.afterCreate(function () {
  5562. if (!self.designMode) {
  5563. self.toolbar.disableAll(true).select('source');
  5564. }
  5565. });
  5566. self.clickToolbar('fullscreen', function () {
  5567. self.fullscreen();
  5568. });
  5569. if (self.fullscreenShortcut) {
  5570. var loaded = false;
  5571. self.afterCreate(function () {
  5572. K(self.edit.doc, self.edit.textarea).keyup(function (e) {
  5573. if (e.which == 27) {
  5574. setTimeout(function () {
  5575. self.fullscreen();
  5576. }, 0);
  5577. }
  5578. });
  5579. if (loaded) {
  5580. if (_IE && !self.designMode) {
  5581. return;
  5582. }
  5583. self.focus();
  5584. }
  5585. if (!loaded) {
  5586. loaded = true;
  5587. }
  5588. });
  5589. }
  5590. _each('undo,redo'.split(','), function (i, name) {
  5591. if (shortcutKeys[name]) {
  5592. self.afterCreate(function () {
  5593. _ctrl(this.edit.doc, shortcutKeys[name], function () {
  5594. self.clickToolbar(name);
  5595. });
  5596. });
  5597. }
  5598. self.clickToolbar(name, function () {
  5599. self[name]();
  5600. });
  5601. });
  5602. self.clickToolbar('formatblock', function () {
  5603. var blocks = self.lang('formatblock.formatBlock'),
  5604. heights = {
  5605. h1: 28,
  5606. h2: 24,
  5607. h3: 18,
  5608. H4: 14,
  5609. p: 12
  5610. },
  5611. curVal = self.cmd.val('formatblock'),
  5612. menu = self.createMenu({
  5613. name: 'formatblock',
  5614. width: self.langType == 'en' ? 200 : 150
  5615. });
  5616. _each(blocks, function (key, val) {
  5617. var style = 'font-size:' + heights[key] + 'px;';
  5618. if (key.charAt(0) === 'h') {
  5619. style += 'font-weight:bold;';
  5620. }
  5621. menu.addItem({
  5622. title: '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5623. height: heights[key] + 12,
  5624. checked: (curVal === key || curVal === val),
  5625. click: function () {
  5626. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5627. }
  5628. });
  5629. });
  5630. });
  5631. self.clickToolbar('fontname', function () {
  5632. var curVal = self.cmd.val('fontname'),
  5633. menu = self.createMenu({
  5634. name: 'fontname',
  5635. width: 150
  5636. });
  5637. _each(self.lang('fontname.fontName'), function (key, val) {
  5638. menu.addItem({
  5639. title: '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5640. checked: (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5641. click: function () {
  5642. self.exec('fontname', key).hideMenu();
  5643. }
  5644. });
  5645. });
  5646. });
  5647. self.clickToolbar('fontsize', function () {
  5648. var curVal = self.cmd.val('fontsize'),
  5649. menu = self.createMenu({
  5650. name: 'fontsize',
  5651. width: 150
  5652. });
  5653. _each(self.fontSizeTable, function (i, val) {
  5654. menu.addItem({
  5655. title: '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5656. height: _removeUnit(val) + 12,
  5657. checked: curVal === val,
  5658. click: function () {
  5659. self.exec('fontsize', val).hideMenu();
  5660. }
  5661. });
  5662. });
  5663. });
  5664. _each('forecolor,hilitecolor'.split(','), function (i, name) {
  5665. self.clickToolbar(name, function () {
  5666. self.createMenu({
  5667. name: name,
  5668. selectedColor: self.cmd.val(name) || 'default',
  5669. colors: self.colorTable,
  5670. click: function (color) {
  5671. self.exec(name, color).hideMenu();
  5672. }
  5673. });
  5674. });
  5675. });
  5676. _each(('cut,copy,paste').split(','), function (i, name) {
  5677. self.clickToolbar(name, function () {
  5678. self.focus();
  5679. try {
  5680. self.exec(name, null);
  5681. } catch (e) {
  5682. alert(self.lang(name + 'Error'));
  5683. }
  5684. });
  5685. });
  5686. self.clickToolbar('about', function () {
  5687. var html = '<div style="margin:20px;">' +
  5688. '<div>KindEditor ' + _VERSION + '</div>' +
  5689. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5690. '</div>';
  5691. self.createDialog({
  5692. name: 'about',
  5693. width: 350,
  5694. title: self.lang('about'),
  5695. body: html
  5696. });
  5697. });
  5698. self.plugin.getSelectedLink = function () {
  5699. return self.cmd.commonAncestor('a');
  5700. };
  5701. self.plugin.getSelectedImage = function () {
  5702. return _getImageFromRange(self.edit.cmd.range, function (img) {
  5703. return !/^ke-\w+$/i.test(img[0].className);
  5704. });
  5705. };
  5706. self.plugin.getSelectedFlash = function () {
  5707. return _getImageFromRange(self.edit.cmd.range, function (img) {
  5708. return img[0].className == 'ke-flash';
  5709. });
  5710. };
  5711. self.plugin.getSelectedMedia = function () {
  5712. return _getImageFromRange(self.edit.cmd.range, function (img) {
  5713. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5714. });
  5715. };
  5716. self.plugin.getSelectedAnchor = function () {
  5717. return _getImageFromRange(self.edit.cmd.range, function (img) {
  5718. return img[0].className == 'ke-anchor';
  5719. });
  5720. };
  5721. _each('link,image,flash,media,anchor'.split(','), function (i, name) {
  5722. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5723. _each('edit,delete'.split(','), function (j, val) {
  5724. self.addContextmenu({
  5725. title: self.lang(val + uName),
  5726. click: function () {
  5727. self.loadPlugin(name, function () {
  5728. self.plugin[name][val]();
  5729. self.hideMenu();
  5730. });
  5731. },
  5732. cond: self.plugin['getSelected' + uName],
  5733. width: 150,
  5734. iconClass: val == 'edit' ? 'ke-icon-' + name : undefined
  5735. });
  5736. });
  5737. self.addContextmenu({ title: '-' });
  5738. });
  5739. self.plugin.getSelectedTable = function () {
  5740. return self.cmd.commonAncestor('table');
  5741. };
  5742. self.plugin.getSelectedRow = function () {
  5743. return self.cmd.commonAncestor('tr');
  5744. };
  5745. self.plugin.getSelectedCell = function () {
  5746. return self.cmd.commonAncestor('td');
  5747. };
  5748. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5749. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function (i, val) {
  5750. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5751. self.addContextmenu({
  5752. title: self.lang('table' + val),
  5753. click: function () {
  5754. self.loadPlugin('table', function () {
  5755. self.plugin.table[val]();
  5756. self.hideMenu();
  5757. });
  5758. },
  5759. cond: cond,
  5760. width: 170,
  5761. iconClass: 'ke-icon-table' + val
  5762. });
  5763. });
  5764. self.addContextmenu({ title: '-' });
  5765. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5766. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5767. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function (i, name) {
  5768. if (shortcutKeys[name]) {
  5769. self.afterCreate(function () {
  5770. _ctrl(this.edit.doc, shortcutKeys[name], function () {
  5771. self.cmd.selection();
  5772. self.clickToolbar(name);
  5773. });
  5774. });
  5775. }
  5776. self.clickToolbar(name, function () {
  5777. self.focus().exec(name, null);
  5778. });
  5779. });
  5780. self.afterCreate(function () {
  5781. var doc = self.edit.doc, cmd, bookmark, div,
  5782. cls = '__kindeditor_paste__', pasting = false;
  5783. function movePastedData() {
  5784. cmd.range.moveToBookmark(bookmark);
  5785. cmd.select();
  5786. if (_WEBKIT) {
  5787. K('div.' + cls, div).each(function () {
  5788. K(this).after('<br />').remove(true);
  5789. });
  5790. K('span.Apple-style-span', div).remove(true);
  5791. K('span.Apple-tab-span', div).remove(true);
  5792. K('span[style]', div).each(function () {
  5793. if (K(this).css('white-space') == 'nowrap') {
  5794. K(this).remove(true);
  5795. }
  5796. });
  5797. K('meta', div).remove();
  5798. }
  5799. var html = div[0].innerHTML;
  5800. div.remove();
  5801. if (html === '') {
  5802. return;
  5803. }
  5804. if (_WEBKIT) {
  5805. html = html.replace(/(<br>)\1/ig, '$1');
  5806. }
  5807. if (self.pasteType === 2) {
  5808. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5809. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5810. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5811. } else {
  5812. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5813. html = self.beforeSetHtml(html);
  5814. }
  5815. }
  5816. if (self.pasteType === 1) {
  5817. html = html.replace(/&nbsp;/ig, ' ');
  5818. html = html.replace(/\n\s*\n/g, '\n');
  5819. html = html.replace(/<br[^>]*>/ig, '\n');
  5820. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5821. html = html.replace(/<[^>]+>/g, '');
  5822. html = html.replace(/ {2}/g, ' &nbsp;');
  5823. if (self.newlineTag == 'p') {
  5824. if (/\n/.test(html)) {
  5825. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5826. }
  5827. } else {
  5828. html = html.replace(/\n/g, '<br />$&');
  5829. }
  5830. }
  5831. self.insertHtml(html, true);
  5832. }
  5833. K(doc.body).bind('paste', function (e) {
  5834. if (self.pasteType === 0) {
  5835. e.stop();
  5836. return;
  5837. }
  5838. if (pasting) {
  5839. return;
  5840. }
  5841. pasting = true;
  5842. K('div.' + cls, doc).remove();
  5843. cmd = self.cmd.selection();
  5844. bookmark = cmd.range.createBookmark();
  5845. div = K('<div class="' + cls + '"></div>', doc).css({
  5846. position: 'absolute',
  5847. width: '1px',
  5848. height: '1px',
  5849. overflow: 'hidden',
  5850. left: '-1981px',
  5851. top: K(bookmark.start).pos().y + 'px',
  5852. 'white-space': 'nowrap'
  5853. });
  5854. K(doc.body).append(div);
  5855. if (_IE) {
  5856. var rng = cmd.range.get(true);
  5857. rng.moveToElementText(div[0]);
  5858. rng.select();
  5859. rng.execCommand('paste');
  5860. e.preventDefault();
  5861. } else {
  5862. cmd.range.selectNodeContents(div[0]);
  5863. cmd.select();
  5864. }
  5865. setTimeout(function () {
  5866. movePastedData();
  5867. pasting = false;
  5868. }, 0);
  5869. });
  5870. });
  5871. self.beforeGetHtml(function (html) {
  5872. if (_IE && _V <= 8) {
  5873. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function (full, tag) {
  5874. return unescape(tag);
  5875. });
  5876. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function ($0, $1, $2) {
  5877. if (!/\s+type="[^"]+"/i.test($0)) {
  5878. return $1 + ' type="text"' + $2;
  5879. }
  5880. return $0;
  5881. });
  5882. }
  5883. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function ($0, $1, $2, $3) {
  5884. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5885. })
  5886. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function (full) {
  5887. var imgAttrs = _getAttrList(full);
  5888. var styles = _getCssList(imgAttrs.style || '');
  5889. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5890. var width = _undef(styles.width, '');
  5891. var height = _undef(styles.height, '');
  5892. if (/px/i.test(width)) {
  5893. width = _removeUnit(width);
  5894. }
  5895. if (/px/i.test(height)) {
  5896. height = _removeUnit(height);
  5897. }
  5898. attrs.width = _undef(imgAttrs.width, width);
  5899. attrs.height = _undef(imgAttrs.height, height);
  5900. return _mediaEmbed(attrs);
  5901. })
  5902. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function (full) {
  5903. var imgAttrs = _getAttrList(full);
  5904. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5905. })
  5906. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function (full, attr, code) {
  5907. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5908. })
  5909. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function (full, attr, code) {
  5910. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5911. })
  5912. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function (full, start, src, end) {
  5913. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function ($0, $1, $2) {
  5914. return $1 + _unescape(src) + $2;
  5915. });
  5916. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5917. return full;
  5918. })
  5919. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function (full, start, end) {
  5920. return start + end;
  5921. });
  5922. });
  5923. self.beforeSetHtml(function (html) {
  5924. if (_IE && _V <= 8) {
  5925. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function (full) {
  5926. var attrs = _getAttrList(full);
  5927. var styles = _getCssList(attrs.style || '');
  5928. if (styles.display == 'none') {
  5929. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5930. }
  5931. return full;
  5932. });
  5933. }
  5934. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function (full) {
  5935. var attrs = _getAttrList(full);
  5936. attrs.src = _undef(attrs.src, '');
  5937. attrs.width = _undef(attrs.width, 0);
  5938. attrs.height = _undef(attrs.height, 0);
  5939. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5940. })
  5941. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function (full) {
  5942. var attrs = _getAttrList(full);
  5943. if (attrs.href !== undefined) {
  5944. return full;
  5945. }
  5946. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5947. })
  5948. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function (full, attr, code) {
  5949. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5950. })
  5951. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function (full, attr, code) {
  5952. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5953. })
  5954. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function (full, start, key, src, end) {
  5955. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5956. return full;
  5957. }
  5958. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5959. return full;
  5960. })
  5961. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function (full, start, end) {
  5962. return start + 'data-ke-' + end;
  5963. })
  5964. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function (full) {
  5965. if (full.indexOf('ke-zeroborder') >= 0) {
  5966. return full;
  5967. }
  5968. return _addClassToTag(full, 'ke-zeroborder');
  5969. });
  5970. });
  5971. });
  5972. })(window);
  5973. /*******************************************************************************
  5974. * KindEditor - WYSIWYG HTML Editor for Internet
  5975. * Copyright (C) 2006-2011 kindsoft.net
  5976. *
  5977. * @author Roddy <luolonghao@gmail.com>
  5978. * @site http://www.kindsoft.net/
  5979. * @licence http://www.kindsoft.net/license.php
  5980. *******************************************************************************/
  5981. KindEditor.lang({
  5982. source: 'HTML代码',
  5983. preview: '预览',
  5984. undo: '后退(Ctrl+Z)',
  5985. redo: '前进(Ctrl+Y)',
  5986. cut: '剪切(Ctrl+X)',
  5987. copy: '复制(Ctrl+C)',
  5988. paste: '粘贴(Ctrl+V)',
  5989. plainpaste: '粘贴为无格式文本',
  5990. wordpaste: '从Word粘贴',
  5991. selectall: '全选(Ctrl+A)',
  5992. justifyleft: '左对齐',
  5993. justifycenter: '居中',
  5994. justifyright: '右对齐',
  5995. justifyfull: '两端对齐',
  5996. insertorderedlist: '编号',
  5997. insertunorderedlist: '项目符号',
  5998. indent: '增加缩进',
  5999. outdent: '减少缩进',
  6000. subscript: '下标',
  6001. superscript: '上标',
  6002. formatblock: '段落',
  6003. fontname: '字体',
  6004. fontsize: '文字大小',
  6005. forecolor: '文字颜色',
  6006. hilitecolor: '文字背景',
  6007. bold: '粗体(Ctrl+B)',
  6008. italic: '斜体(Ctrl+I)',
  6009. underline: '下划线(Ctrl+U)',
  6010. strikethrough: '删除线',
  6011. removeformat: '删除格式',
  6012. image: '图片',
  6013. multiimage: '批量图片上传',
  6014. flash: 'Flash',
  6015. media: '视音频',
  6016. table: '表格',
  6017. tablecell: '单元格',
  6018. hr: '插入横线',
  6019. emoticons: '插入表情',
  6020. link: '超级链接',
  6021. unlink: '取消超级链接',
  6022. fullscreen: '全屏显示',
  6023. about: '关于',
  6024. print: '打印(Ctrl+P)',
  6025. filemanager: '文件空间',
  6026. code: '插入程序代码',
  6027. map: 'Google地图',
  6028. baidumap: '百度地图',
  6029. lineheight: '行距',
  6030. clearhtml: '清理HTML代码',
  6031. pagebreak: '插入分页符',
  6032. quickformat: '一键排版',
  6033. insertfile: '插入文件',
  6034. template: '插入模板',
  6035. anchor: '锚点',
  6036. yes: '确定',
  6037. no: '取消',
  6038. close: '关闭',
  6039. editImage: '图片属性',
  6040. deleteImage: '删除图片',
  6041. editFlash: 'Flash属性',
  6042. deleteFlash: '删除Flash',
  6043. editMedia: '视音频属性',
  6044. deleteMedia: '删除视音频',
  6045. editLink: '超级链接属性',
  6046. deleteLink: '取消超级链接',
  6047. editAnchor: '锚点属性',
  6048. deleteAnchor: '删除锚点',
  6049. tableprop: '表格属性',
  6050. tablecellprop: '单元格属性',
  6051. tableinsert: '插入表格',
  6052. tabledelete: '删除表格',
  6053. tablecolinsertleft: '左侧插入列',
  6054. tablecolinsertright: '右侧插入列',
  6055. tablerowinsertabove: '上方插入行',
  6056. tablerowinsertbelow: '下方插入行',
  6057. tablerowmerge: '向下合并单元格',
  6058. tablecolmerge: '向右合并单元格',
  6059. tablerowsplit: '拆分行',
  6060. tablecolsplit: '拆分列',
  6061. tablecoldelete: '删除列',
  6062. tablerowdelete: '删除行',
  6063. noColor: '无颜色',
  6064. pleaseSelectFile: '请选择文件。',
  6065. invalidImg: "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6066. invalidMedia: "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6067. invalidWidth: "宽度必须为数字。",
  6068. invalidHeight: "高度必须为数字。",
  6069. invalidBorder: "边框必须为数字。",
  6070. invalidUrl: "请输入有效的URL地址。",
  6071. invalidRows: '行数为必选项,只允许输入大于0的数字。',
  6072. invalidCols: '列数为必选项,只允许输入大于0的数字。',
  6073. invalidPadding: '边距必须为数字。',
  6074. invalidSpacing: '间距必须为数字。',
  6075. invalidJson: '服务器发生故障。',
  6076. uploadSuccess: '上传成功。',
  6077. cutError: '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6078. copyError: '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6079. pasteError: '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6080. ajaxLoading: '加载中,请稍候 ...',
  6081. uploadLoading: '上传中,请稍候 ...',
  6082. uploadError: '上传错误',
  6083. 'plainpaste.comment': '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6084. 'wordpaste.comment': '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6085. 'code.pleaseInput': '请输入程序代码。',
  6086. 'link.url': 'URL',
  6087. 'link.linkType': '打开类型',
  6088. 'link.newWindow': '新窗口',
  6089. 'link.selfWindow': '当前窗口',
  6090. 'flash.url': 'URL',
  6091. 'flash.width': '宽度',
  6092. 'flash.height': '高度',
  6093. 'flash.upload': '上传',
  6094. 'flash.viewServer': '文件空间',
  6095. 'media.url': 'URL',
  6096. 'media.width': '宽度',
  6097. 'media.height': '高度',
  6098. 'media.autostart': '自动播放',
  6099. 'media.upload': '上传',
  6100. 'media.viewServer': '文件空间',
  6101. 'image.remoteImage': '网络图片',
  6102. 'image.localImage': '本地上传',
  6103. 'image.remoteUrl': '图片地址',
  6104. 'image.localUrl': '上传文件',
  6105. 'image.size': '图片大小',
  6106. 'image.width': '宽',
  6107. 'image.height': '高',
  6108. 'image.resetSize': '重置大小',
  6109. 'image.align': '对齐方式',
  6110. 'image.defaultAlign': '默认方式',
  6111. 'image.leftAlign': '左对齐',
  6112. 'image.rightAlign': '右对齐',
  6113. 'image.imgTitle': '图片说明',
  6114. 'image.upload': '浏览...',
  6115. 'image.viewServer': '图片空间',
  6116. 'multiimage.uploadDesc': '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6117. 'multiimage.startUpload': '开始上传',
  6118. 'multiimage.clearAll': '全部清空',
  6119. 'multiimage.insertAll': '全部插入',
  6120. 'multiimage.queueLimitExceeded': '文件数量超过限制。',
  6121. 'multiimage.fileExceedsSizeLimit': '文件大小超过限制。',
  6122. 'multiimage.zeroByteFile': '无法上传空文件。',
  6123. 'multiimage.invalidFiletype': '文件类型不正确。',
  6124. 'multiimage.unknownError': '发生异常,无法上传。',
  6125. 'multiimage.pending': '等待上传',
  6126. 'multiimage.uploadError': '上传失败',
  6127. 'filemanager.emptyFolder': '空文件夹',
  6128. 'filemanager.moveup': '移到上一级文件夹',
  6129. 'filemanager.viewType': '显示方式:',
  6130. 'filemanager.viewImage': '缩略图',
  6131. 'filemanager.listImage': '详细信息',
  6132. 'filemanager.orderType': '排序方式:',
  6133. 'filemanager.fileName': '名称',
  6134. 'filemanager.fileSize': '大小',
  6135. 'filemanager.fileType': '类型',
  6136. 'insertfile.url': 'URL',
  6137. 'insertfile.title': '文件说明',
  6138. 'insertfile.upload': '上传',
  6139. 'insertfile.viewServer': '文件空间',
  6140. 'table.cells': '单元格数',
  6141. 'table.rows': '行数',
  6142. 'table.cols': '列数',
  6143. 'table.size': '大小',
  6144. 'table.width': '宽度',
  6145. 'table.height': '高度',
  6146. 'table.percent': '%',
  6147. 'table.px': 'px',
  6148. 'table.space': '边距间距',
  6149. 'table.padding': '边距',
  6150. 'table.spacing': '间距',
  6151. 'table.align': '对齐方式',
  6152. 'table.textAlign': '水平对齐',
  6153. 'table.verticalAlign': '垂直对齐',
  6154. 'table.alignDefault': '默认',
  6155. 'table.alignLeft': '左对齐',
  6156. 'table.alignCenter': '居中',
  6157. 'table.alignRight': '右对齐',
  6158. 'table.alignTop': '顶部',
  6159. 'table.alignMiddle': '中部',
  6160. 'table.alignBottom': '底部',
  6161. 'table.alignBaseline': '基线',
  6162. 'table.border': '边框',
  6163. 'table.borderWidth': '边框',
  6164. 'table.borderColor': '颜色',
  6165. 'table.backgroundColor': '背景颜色',
  6166. 'map.address': '地址: ',
  6167. 'map.search': '搜索',
  6168. 'baidumap.address': '地址: ',
  6169. 'baidumap.search': '搜索',
  6170. 'baidumap.insertDynamicMap': '插入动态地图',
  6171. 'anchor.name': '锚点名称',
  6172. 'formatblock.formatBlock': {
  6173. h1: '标题 1',
  6174. h2: '标题 2',
  6175. h3: '标题 3',
  6176. h4: '标题 4',
  6177. p: '正 文'
  6178. },
  6179. 'fontname.fontName': {
  6180. 'SimSun': '宋体',
  6181. 'NSimSun': '新宋体',
  6182. 'FangSong_GB2312': '仿宋_GB2312',
  6183. 'KaiTi_GB2312': '楷体_GB2312',
  6184. 'SimHei': '黑体',
  6185. 'Microsoft YaHei': '微软雅黑',
  6186. 'Arial': 'Arial',
  6187. 'Arial Black': 'Arial Black',
  6188. 'Times New Roman': 'Times New Roman',
  6189. 'Courier New': 'Courier New',
  6190. 'Tahoma': 'Tahoma',
  6191. 'Verdana': 'Verdana'
  6192. },
  6193. 'lineheight.lineHeight': [
  6194. { '1': '单倍行距' },
  6195. { '1.5': '1.5倍行距' },
  6196. { '2': '2倍行距' },
  6197. { '2.5': '2.5倍行距' },
  6198. { '3': '3倍行距' }
  6199. ],
  6200. 'template.selectTemplate': '可选模板',
  6201. 'template.replaceContent': '替换当前内容',
  6202. 'template.fileList': {
  6203. '1.html': '图片和文字',
  6204. '2.html': '表格',
  6205. '3.html': '项目编号'
  6206. }
  6207. }, 'zh_CN');
  6208. /*******************************************************************************
  6209. * KindEditor - WYSIWYG HTML Editor for Internet
  6210. * Copyright (C) 2006-2011 kindsoft.net
  6211. *
  6212. * @author Roddy <luolonghao@gmail.com>
  6213. * @site http://www.kindsoft.net/
  6214. * @licence http://www.kindsoft.net/license.php
  6215. *******************************************************************************/
  6216. KindEditor.plugin('anchor', function (K) {
  6217. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6218. self.plugin.anchor = {
  6219. edit: function () {
  6220. var html = ['<div style="padding:20px;">',
  6221. '<div class="ke-dialog-row">',
  6222. '<label for="keName">' + lang.name + '</label>',
  6223. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6224. '</div>',
  6225. '</div>'].join('');
  6226. var dialog = self.createDialog({
  6227. name: name,
  6228. width: 300,
  6229. title: self.lang(name),
  6230. body: html,
  6231. yesBtn: {
  6232. name: self.lang('yes'),
  6233. click: function (e) {
  6234. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6235. }
  6236. }
  6237. });
  6238. var div = dialog.div,
  6239. nameBox = K('input[name="name"]', div);
  6240. var img = self.plugin.getSelectedAnchor();
  6241. if (img) {
  6242. nameBox.val(unescape(img.attr('data-ke-name')));
  6243. }
  6244. nameBox[0].focus();
  6245. nameBox[0].select();
  6246. },
  6247. 'delete': function () {
  6248. self.plugin.getSelectedAnchor().remove();
  6249. }
  6250. };
  6251. self.clickToolbar(name, self.plugin.anchor.edit);
  6252. });
  6253. /*******************************************************************************
  6254. * KindEditor - WYSIWYG HTML Editor for Internet
  6255. * Copyright (C) 2006-2011 kindsoft.net
  6256. *
  6257. * @author Roddy <luolonghao@gmail.com>
  6258. * @site http://www.kindsoft.net/
  6259. * @licence http://www.kindsoft.net/license.php
  6260. *******************************************************************************/
  6261. KindEditor.plugin('autoheight', function (K) {
  6262. var self = this;
  6263. if (!self.autoHeightMode) {
  6264. return;
  6265. }
  6266. var minHeight;
  6267. function hideScroll() {
  6268. var edit = self.edit;
  6269. var body = edit.doc.body;
  6270. edit.iframe[0].scroll = 'no';
  6271. body.style.overflowY = 'hidden';
  6272. }
  6273. function resetHeight() {
  6274. var edit = self.edit;
  6275. var body = edit.doc.body;
  6276. edit.iframe.height(minHeight);
  6277. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6278. }
  6279. function init() {
  6280. minHeight = K.removeUnit(self.height);
  6281. self.edit.afterChange(resetHeight);
  6282. hideScroll();
  6283. resetHeight();
  6284. }
  6285. if (self.isCreated) {
  6286. init();
  6287. } else {
  6288. self.afterCreate(init);
  6289. }
  6290. });
  6291. /*
  6292. * 如何实现真正的自动高度?
  6293. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6294. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6295. * 由此就实现了真正的自动高度
  6296. * 测试:chrome、firefox、IE9、IE8
  6297. * */
  6298. /*******************************************************************************
  6299. * KindEditor - WYSIWYG HTML Editor for Internet
  6300. * Copyright (C) 2006-2011 kindsoft.net
  6301. *
  6302. * @author Roddy <luolonghao@gmail.com>
  6303. * @site http://www.kindsoft.net/
  6304. * @licence http://www.kindsoft.net/license.php
  6305. *******************************************************************************/
  6306. // Baidu Maps: http://dev.baidu.com/wiki/map/index.php?title=%E9%A6%96%E9%A1%B5
  6307. KindEditor.plugin('baidumap', function (K) {
  6308. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6309. var mapWidth = K.undef(self.mapWidth, 558);
  6310. var mapHeight = K.undef(self.mapHeight, 360);
  6311. self.clickToolbar(name, function () {
  6312. var html = ['<div style="padding:10px 20px;">',
  6313. '<div class="ke-header">',
  6314. // left start
  6315. '<div class="ke-left">',
  6316. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6317. '<span class="ke-button-common ke-button-outer">',
  6318. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6319. '</span>',
  6320. '</div>',
  6321. // right start
  6322. '<div class="ke-right">',
  6323. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6324. '</div>',
  6325. '<div class="ke-clearfix"></div>',
  6326. '</div>',
  6327. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6328. '</div>'].join('');
  6329. var dialog = self.createDialog({
  6330. name: name,
  6331. width: mapWidth + 42,
  6332. title: self.lang(name),
  6333. body: html,
  6334. yesBtn: {
  6335. name: self.lang('yes'),
  6336. click: function (e) {
  6337. var map = win.map;
  6338. var centerObj = map.getCenter();
  6339. var center = centerObj.lng + ',' + centerObj.lat;
  6340. var zoom = map.getZoom();
  6341. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6342. '?center=' + encodeURIComponent(center),
  6343. '&zoom=' + encodeURIComponent(zoom),
  6344. '&width=' + mapWidth,
  6345. '&height=' + mapHeight,
  6346. '&markers=' + encodeURIComponent(center),
  6347. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6348. if (checkbox[0].checked) {
  6349. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6350. } else {
  6351. self.exec('insertimage', url);
  6352. }
  6353. self.hideDialog().focus();
  6354. }
  6355. },
  6356. beforeRemove: function () {
  6357. searchBtn.remove();
  6358. if (doc) {
  6359. doc.write('');
  6360. }
  6361. iframe.remove();
  6362. }
  6363. });
  6364. var div = dialog.div,
  6365. addressBox = K('[name="address"]', div),
  6366. searchBtn = K('[name="searchBtn"]', div),
  6367. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6368. win, doc;
  6369. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6370. function ready() {
  6371. win = iframe[0].contentWindow;
  6372. doc = K.iframeDoc(iframe);
  6373. }
  6374. iframe.bind('load', function () {
  6375. iframe.unbind('load');
  6376. if (K.IE) {
  6377. ready();
  6378. } else {
  6379. setTimeout(ready, 0);
  6380. }
  6381. });
  6382. K('.ke-map', div).replaceWith(iframe);
  6383. // search map
  6384. searchBtn.click(function () {
  6385. win.search(addressBox.val());
  6386. });
  6387. });
  6388. });
  6389. /*******************************************************************************
  6390. * KindEditor - WYSIWYG HTML Editor for Internet
  6391. * Copyright (C) 2006-2011 kindsoft.net
  6392. *
  6393. * @author Roddy <luolonghao@gmail.com>
  6394. * @site http://www.kindsoft.net/
  6395. * @licence http://www.kindsoft.net/license.php
  6396. *******************************************************************************/
  6397. KindEditor.plugin('clearhtml', function (K) {
  6398. var self = this, name = 'clearhtml';
  6399. self.clickToolbar(name, function () {
  6400. self.focus();
  6401. var html = self.html();
  6402. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6403. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6404. html = K.formatHtml(html, {
  6405. a: ['href', 'target'],
  6406. embed: ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6407. img: ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6408. table: ['border'],
  6409. 'td,th': ['rowspan', 'colspan'],
  6410. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6': []
  6411. });
  6412. self.html(html);
  6413. self.cmd.selection(true);
  6414. self.addBookmark();
  6415. });
  6416. });
  6417. /*******************************************************************************
  6418. * KindEditor - WYSIWYG HTML Editor for Internet
  6419. * Copyright (C) 2006-2011 kindsoft.net
  6420. *
  6421. * @author Roddy <luolonghao@gmail.com>
  6422. * @site http://www.kindsoft.net/
  6423. * @licence http://www.kindsoft.net/license.php
  6424. *******************************************************************************/
  6425. // google code prettify: http://google-code-prettify.googlecode.com/
  6426. // http://google-code-prettify.googlecode.com/
  6427. KindEditor.plugin('code', function (K) {
  6428. var self = this, name = 'code';
  6429. self.clickToolbar(name, function () {
  6430. var lang = self.lang(name + '.'),
  6431. html = ['<div style="padding:10px 20px;">',
  6432. '<div class="ke-dialog-row">',
  6433. '<select class="ke-code-type">',
  6434. '<option value="js">JavaScript</option>',
  6435. '<option value="html">HTML</option>',
  6436. '<option value="css">CSS</option>',
  6437. '<option value="php">PHP</option>',
  6438. '<option value="pl">Perl</option>',
  6439. '<option value="py">Python</option>',
  6440. '<option value="rb">Ruby</option>',
  6441. '<option value="java">Java</option>',
  6442. '<option value="vb">ASP/VB</option>',
  6443. '<option value="cpp">C/C++</option>',
  6444. '<option value="cs">C#</option>',
  6445. '<option value="xml">XML</option>',
  6446. '<option value="bsh">Shell</option>',
  6447. '<option value="">Other</option>',
  6448. '</select>',
  6449. '</div>',
  6450. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6451. '</div>'].join(''),
  6452. dialog = self.createDialog({
  6453. name: name,
  6454. width: 450,
  6455. title: self.lang(name),
  6456. body: html,
  6457. yesBtn: {
  6458. name: self.lang('yes'),
  6459. click: function (e) {
  6460. var type = K('.ke-code-type', dialog.div).val(),
  6461. code = textarea.val(),
  6462. cls = type === '' ? '' : ' lang-' + type,
  6463. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6464. if (K.trim(code) === '') {
  6465. alert(lang.pleaseInput);
  6466. textarea[0].focus();
  6467. return;
  6468. }
  6469. self.insertHtml(html).hideDialog().focus();
  6470. }
  6471. }
  6472. }),
  6473. textarea = K('textarea', dialog.div);
  6474. textarea[0].focus();
  6475. });
  6476. });
  6477. /*******************************************************************************
  6478. * KindEditor - WYSIWYG HTML Editor for Internet
  6479. * Copyright (C) 2006-2011 kindsoft.net
  6480. *
  6481. * @author Roddy <luolonghao@gmail.com>
  6482. * @site http://www.kindsoft.net/
  6483. * @licence http://www.kindsoft.net/license.php
  6484. *******************************************************************************/
  6485. KindEditor.plugin('emoticons', function (K) {
  6486. var self = this, name = 'emoticons',
  6487. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6488. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6489. currentPageNum = 1;
  6490. self.clickToolbar(name, function () {
  6491. var rows = 5, cols = 9, total = 135, startNum = 0,
  6492. cells = rows * cols, pages = Math.ceil(total / cells),
  6493. colsHalf = Math.floor(cols / 2),
  6494. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6495. elements = [],
  6496. menu = self.createMenu({
  6497. name: name,
  6498. beforeRemove: function () {
  6499. removeEvent();
  6500. }
  6501. });
  6502. menu.div.append(wrapperDiv);
  6503. var previewDiv, previewImg;
  6504. if (allowPreview) {
  6505. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6506. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6507. wrapperDiv.append(previewDiv);
  6508. previewDiv.append(previewImg);
  6509. }
  6510. function bindCellEvent(cell, j, num) {
  6511. if (previewDiv) {
  6512. cell.mouseover(function () {
  6513. if (j > colsHalf) {
  6514. previewDiv.css('left', 0);
  6515. previewDiv.css('right', '');
  6516. } else {
  6517. previewDiv.css('left', '');
  6518. previewDiv.css('right', 0);
  6519. }
  6520. previewImg.attr('src', path + num + '.gif');
  6521. K(this).addClass('ke-on');
  6522. });
  6523. } else {
  6524. cell.mouseover(function () {
  6525. K(this).addClass('ke-on');
  6526. });
  6527. }
  6528. cell.mouseout(function () {
  6529. K(this).removeClass('ke-on');
  6530. });
  6531. cell.click(function (e) {
  6532. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6533. e.stop();
  6534. });
  6535. }
  6536. function createEmoticonsTable(pageNum, parentDiv) {
  6537. var table = document.createElement('table');
  6538. parentDiv.append(table);
  6539. if (previewDiv) {
  6540. K(table).mouseover(function () {
  6541. previewDiv.show('block');
  6542. });
  6543. K(table).mouseout(function () {
  6544. previewDiv.hide();
  6545. });
  6546. elements.push(K(table));
  6547. }
  6548. table.className = 'ke-table';
  6549. table.cellPadding = 0;
  6550. table.cellSpacing = 0;
  6551. table.border = 0;
  6552. var num = (pageNum - 1) * cells + startNum;
  6553. for (var i = 0; i < rows; i++) {
  6554. var row = table.insertRow(i);
  6555. for (var j = 0; j < cols; j++) {
  6556. var cell = K(row.insertCell(j));
  6557. cell.addClass('ke-cell');
  6558. bindCellEvent(cell, j, num);
  6559. var span = K('<span class="ke-img"></span>')
  6560. .css('background-position', '-' + (24 * num) + 'px 0px')
  6561. .css('background-image', 'url(' + path + 'static.gif)');
  6562. cell.append(span);
  6563. elements.push(cell);
  6564. num++;
  6565. }
  6566. }
  6567. return table;
  6568. }
  6569. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6570. function removeEvent() {
  6571. K.each(elements, function () {
  6572. this.unbind();
  6573. });
  6574. }
  6575. var pageDiv;
  6576. function bindPageEvent(el, pageNum) {
  6577. el.click(function (e) {
  6578. removeEvent();
  6579. table.parentNode.removeChild(table);
  6580. pageDiv.remove();
  6581. table = createEmoticonsTable(pageNum, wrapperDiv);
  6582. createPageTable(pageNum);
  6583. currentPageNum = pageNum;
  6584. e.stop();
  6585. });
  6586. }
  6587. function createPageTable(currentPageNum) {
  6588. pageDiv = K('<div class="ke-page"></div>');
  6589. wrapperDiv.append(pageDiv);
  6590. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6591. if (currentPageNum !== pageNum) {
  6592. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6593. bindPageEvent(a, pageNum);
  6594. pageDiv.append(a);
  6595. elements.push(a);
  6596. } else {
  6597. pageDiv.append(K('@[' + pageNum + ']'));
  6598. }
  6599. pageDiv.append(K('@&nbsp;'));
  6600. }
  6601. }
  6602. createPageTable(currentPageNum);
  6603. });
  6604. });
  6605. /*******************************************************************************
  6606. * KindEditor - WYSIWYG HTML Editor for Internet
  6607. * Copyright (C) 2006-2011 kindsoft.net
  6608. *
  6609. * @author Roddy <luolonghao@gmail.com>
  6610. * @site http://www.kindsoft.net/
  6611. * @licence http://www.kindsoft.net/license.php
  6612. *******************************************************************************/
  6613. KindEditor.plugin('filemanager', function (K) {
  6614. var self = this, name = 'filemanager',
  6615. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6616. imgPath = self.pluginsPath + name + '/images/',
  6617. lang = self.lang(name + '.');
  6618. function makeFileTitle(filename, filesize, datetime) {
  6619. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6620. }
  6621. function bindTitle(el, data) {
  6622. if (data.is_dir) {
  6623. el.attr('title', data.filename);
  6624. } else {
  6625. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6626. }
  6627. }
  6628. self.plugin.filemanagerDialog = function (options) {
  6629. var width = K.undef(options.width, 650),
  6630. height = K.undef(options.height, 510),
  6631. dirName = K.undef(options.dirName, ''),
  6632. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(), // "LIST" or "VIEW"
  6633. clickFn = options.clickFn;
  6634. var html = [
  6635. '<div style="padding:10px 20px;">',
  6636. // header start
  6637. '<div class="ke-plugin-filemanager-header">',
  6638. // left start
  6639. '<div class="ke-left">',
  6640. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6641. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6642. '</div>',
  6643. // right start
  6644. '<div class="ke-right">',
  6645. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6646. '<option value="VIEW">' + lang.viewImage + '</option>',
  6647. '<option value="LIST">' + lang.listImage + '</option>',
  6648. '</select> ',
  6649. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6650. '<option value="NAME">' + lang.fileName + '</option>',
  6651. '<option value="SIZE">' + lang.fileSize + '</option>',
  6652. '<option value="TYPE">' + lang.fileType + '</option>',
  6653. '</select>',
  6654. '</div>',
  6655. '<div class="ke-clearfix"></div>',
  6656. '</div>',
  6657. // body start
  6658. '<div class="ke-plugin-filemanager-body"></div>',
  6659. '</div>'
  6660. ].join('');
  6661. var dialog = self.createDialog({
  6662. name: name,
  6663. width: width,
  6664. height: height,
  6665. title: self.lang(name),
  6666. body: html
  6667. }),
  6668. div = dialog.div,
  6669. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6670. moveupImg = K('[name="moveupImg"]', div),
  6671. moveupLink = K('[name="moveupLink"]', div),
  6672. viewServerBtn = K('[name="viewServer"]', div),
  6673. viewTypeBox = K('[name="viewType"]', div),
  6674. orderTypeBox = K('[name="orderType"]', div);
  6675. function reloadPage(path, order, func) {
  6676. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6677. dialog.showLoading(self.lang('ajaxLoading'));
  6678. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function (data) {
  6679. dialog.hideLoading();
  6680. func(data);
  6681. });
  6682. }
  6683. var elList = [];
  6684. function bindEvent(el, result, data, createFunc) {
  6685. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6686. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6687. if (data.is_dir) {
  6688. el.click(function (e) {
  6689. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6690. });
  6691. } else if (data.is_photo) {
  6692. el.click(function (e) {
  6693. clickFn.call(this, fileUrl, data.filename);
  6694. });
  6695. } else {
  6696. el.click(function (e) {
  6697. clickFn.call(this, fileUrl, data.filename);
  6698. });
  6699. }
  6700. elList.push(el);
  6701. }
  6702. function createCommon(result, createFunc) {
  6703. // remove events
  6704. K.each(elList, function () {
  6705. this.unbind();
  6706. });
  6707. moveupLink.unbind();
  6708. viewTypeBox.unbind();
  6709. orderTypeBox.unbind();
  6710. // add events
  6711. if (result.current_dir_path) {
  6712. moveupLink.click(function (e) {
  6713. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6714. });
  6715. }
  6716. function changeFunc() {
  6717. if (viewTypeBox.val() == 'VIEW') {
  6718. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6719. } else {
  6720. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6721. }
  6722. }
  6723. viewTypeBox.change(changeFunc);
  6724. orderTypeBox.change(changeFunc);
  6725. bodyDiv.html('');
  6726. }
  6727. function createList(result) {
  6728. createCommon(result, createList);
  6729. var table = document.createElement('table');
  6730. table.className = 'ke-table';
  6731. table.cellPadding = 0;
  6732. table.cellSpacing = 0;
  6733. table.border = 0;
  6734. bodyDiv.append(table);
  6735. var fileList = result.file_list;
  6736. for (var i = 0, len = fileList.length; i < len; i++) {
  6737. var data = fileList[i], row = K(table.insertRow(i));
  6738. row.mouseover(function (e) {
  6739. K(this).addClass('ke-on');
  6740. })
  6741. .mouseout(function (e) {
  6742. K(this).removeClass('ke-on');
  6743. });
  6744. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6745. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6746. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6747. if (!data.is_dir || data.has_file) {
  6748. row.css('cursor', 'pointer');
  6749. cell0.attr('title', data.filename);
  6750. bindEvent(cell0, result, data, createList);
  6751. } else {
  6752. cell0.attr('title', lang.emptyFolder);
  6753. }
  6754. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6755. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6756. }
  6757. }
  6758. function createView(result) {
  6759. createCommon(result, createView);
  6760. var fileList = result.file_list;
  6761. for (var i = 0, len = fileList.length; i < len; i++) {
  6762. var data = fileList[i],
  6763. div = K('<div class="ke-inline-block ke-item"></div>');
  6764. bodyDiv.append(div);
  6765. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6766. .mouseover(function (e) {
  6767. K(this).addClass('ke-on');
  6768. })
  6769. .mouseout(function (e) {
  6770. K(this).removeClass('ke-on');
  6771. });
  6772. div.append(photoDiv);
  6773. var fileUrl = result.current_url + data.filename,
  6774. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6775. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6776. if (!data.is_dir || data.has_file) {
  6777. photoDiv.css('cursor', 'pointer');
  6778. bindTitle(photoDiv, data);
  6779. bindEvent(photoDiv, result, data, createView);
  6780. } else {
  6781. photoDiv.attr('title', lang.emptyFolder);
  6782. }
  6783. photoDiv.append(img);
  6784. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6785. }
  6786. }
  6787. viewTypeBox.val(viewType);
  6788. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6789. return dialog;
  6790. }
  6791. });
  6792. /*******************************************************************************
  6793. * KindEditor - WYSIWYG HTML Editor for Internet
  6794. * Copyright (C) 2006-2011 kindsoft.net
  6795. *
  6796. * @author Roddy <luolonghao@gmail.com>
  6797. * @site http://www.kindsoft.net/
  6798. * @licence http://www.kindsoft.net/license.php
  6799. *******************************************************************************/
  6800. KindEditor.plugin('flash', function (K) {
  6801. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6802. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6803. allowFileManager = K.undef(self.allowFileManager, false),
  6804. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6805. extraParams = K.undef(self.extraFileUploadParams, {}),
  6806. filePostName = K.undef(self.filePostName, 'imgFile'),
  6807. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  6808. self.plugin.flash = {
  6809. edit: function () {
  6810. var html = [
  6811. '<div style="padding:20px;">',
  6812. //url
  6813. '<div class="ke-dialog-row">',
  6814. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6815. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6816. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6817. '<span class="ke-button-common ke-button-outer">',
  6818. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6819. '</span>',
  6820. '</div>',
  6821. //width
  6822. '<div class="ke-dialog-row">',
  6823. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6824. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6825. '</div>',
  6826. //height
  6827. '<div class="ke-dialog-row">',
  6828. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6829. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6830. '</div>',
  6831. '</div>'
  6832. ].join('');
  6833. var dialog = self.createDialog({
  6834. name: name,
  6835. width: 450,
  6836. title: self.lang(name),
  6837. body: html,
  6838. yesBtn: {
  6839. name: self.lang('yes'),
  6840. click: function (e) {
  6841. var url = K.trim(urlBox.val()),
  6842. width = widthBox.val(),
  6843. height = heightBox.val();
  6844. if (url == 'http://' || K.invalidUrl(url)) {
  6845. alert(self.lang('invalidUrl'));
  6846. urlBox[0].focus();
  6847. return;
  6848. }
  6849. if (!/^\d*$/.test(width)) {
  6850. alert(self.lang('invalidWidth'));
  6851. widthBox[0].focus();
  6852. return;
  6853. }
  6854. if (!/^\d*$/.test(height)) {
  6855. alert(self.lang('invalidHeight'));
  6856. heightBox[0].focus();
  6857. return;
  6858. }
  6859. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6860. src: url,
  6861. type: K.mediaType('.swf'),
  6862. width: width,
  6863. height: height,
  6864. quality: 'high'
  6865. });
  6866. self.insertHtml(html).hideDialog().focus();
  6867. }
  6868. }
  6869. }),
  6870. div = dialog.div,
  6871. urlBox = K('[name="url"]', div),
  6872. viewServerBtn = K('[name="viewServer"]', div),
  6873. widthBox = K('[name="width"]', div),
  6874. heightBox = K('[name="height"]', div);
  6875. urlBox.val('http://');
  6876. if (allowFlashUpload) {
  6877. var uploadbutton = K.uploadbutton({
  6878. button: K('.ke-upload-button', div)[0],
  6879. fieldName: filePostName,
  6880. extraParams: extraParams,
  6881. url: K.addParam(uploadJson, 'dir=flash'),
  6882. afterUpload: function (data) {
  6883. dialog.hideLoading();
  6884. if (data.error === 0) {
  6885. //var url = data.url;
  6886. var url = "/g2work" + data.url;
  6887. if (formatUploadUrl) {
  6888. url = K.formatUrl(url, 'absolute');
  6889. }
  6890. urlBox.val(url);
  6891. if (self.afterUpload) {
  6892. self.afterUpload.call(self, url, data, name);
  6893. }
  6894. alert(self.lang('uploadSuccess'));
  6895. } else {
  6896. alert(data.message);
  6897. }
  6898. },
  6899. afterError: function (html) {
  6900. dialog.hideLoading();
  6901. self.errorDialog(html);
  6902. }
  6903. });
  6904. uploadbutton.fileBox.change(function (e) {
  6905. dialog.showLoading(self.lang('uploadLoading'));
  6906. uploadbutton.submit();
  6907. });
  6908. } else {
  6909. K('.ke-upload-button', div).hide();
  6910. }
  6911. if (allowFileManager) {
  6912. viewServerBtn.click(function (e) {
  6913. self.loadPlugin('filemanager', function () {
  6914. self.plugin.filemanagerDialog({
  6915. viewType: 'LIST',
  6916. dirName: 'flash',
  6917. clickFn: function (url, title) {
  6918. if (self.dialogs.length > 1) {
  6919. K('[name="url"]', div).val(url);
  6920. if (self.afterSelectFile) {
  6921. self.afterSelectFile.call(self, url);
  6922. }
  6923. self.hideDialog();
  6924. }
  6925. }
  6926. });
  6927. });
  6928. });
  6929. } else {
  6930. viewServerBtn.hide();
  6931. }
  6932. var img = self.plugin.getSelectedFlash();
  6933. if (img) {
  6934. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  6935. urlBox.val(attrs.src);
  6936. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  6937. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  6938. }
  6939. urlBox[0].focus();
  6940. urlBox[0].select();
  6941. },
  6942. 'delete': function () {
  6943. self.plugin.getSelectedFlash().remove();
  6944. // [IE] 删除图片后立即点击图片按钮出错
  6945. self.addBookmark();
  6946. }
  6947. };
  6948. self.clickToolbar(name, self.plugin.flash.edit);
  6949. });
  6950. /*******************************************************************************
  6951. * KindEditor - WYSIWYG HTML Editor for Internet
  6952. * Copyright (C) 2006-2011 kindsoft.net
  6953. *
  6954. * @author Roddy <luolonghao@gmail.com>
  6955. * @site http://www.kindsoft.net/
  6956. * @licence http://www.kindsoft.net/license.php
  6957. *******************************************************************************/
  6958. KindEditor.plugin('image', function (K) {
  6959. var self = this, name = 'image',
  6960. allowImageUpload = K.undef(self.allowImageUpload, true),
  6961. allowImageRemote = K.undef(self.allowImageRemote, true),
  6962. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6963. allowFileManager = K.undef(self.allowFileManager, false),
  6964. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  6965. imageTabIndex = K.undef(self.imageTabIndex, 0),
  6966. imgPath = self.pluginsPath + 'image/images/',
  6967. extraParams = K.undef(self.extraFileUploadParams, {}),
  6968. filePostName = K.undef(self.filePostName, 'imgFile'),
  6969. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  6970. lang = self.lang(name + '.');
  6971. self.plugin.imageDialog = function (options) {
  6972. var imageUrl = options.imageUrl,
  6973. imageWidth = K.undef(options.imageWidth, ''),
  6974. imageHeight = K.undef(options.imageHeight, ''),
  6975. imageTitle = K.undef(options.imageTitle, ''),
  6976. imageAlign = K.undef(options.imageAlign, ''),
  6977. showRemote = K.undef(options.showRemote, true),
  6978. showLocal = K.undef(options.showLocal, true),
  6979. tabIndex = K.undef(options.tabIndex, 0),
  6980. clickFn = options.clickFn;
  6981. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  6982. var hiddenElements = [];
  6983. for (var k in extraParams) {
  6984. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  6985. }
  6986. var html = [
  6987. '<div style="padding:20px;">',
  6988. //tabs
  6989. '<div class="tabs"></div>',
  6990. //remote image - start
  6991. '<div class="tab1" style="display:none;">',
  6992. //url
  6993. '<div class="ke-dialog-row">',
  6994. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  6995. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  6996. '<span class="ke-button-common ke-button-outer">',
  6997. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6998. '</span>',
  6999. '</div>',
  7000. //size
  7001. '<div class="ke-dialog-row">',
  7002. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7003. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7004. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7005. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7006. '</div>',
  7007. //align
  7008. '<div class="ke-dialog-row">',
  7009. '<label style="width:60px;">' + lang.align + '</label>',
  7010. '<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="" />',
  7011. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7012. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7013. '</div>',
  7014. //title
  7015. '<div class="ke-dialog-row">',
  7016. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7017. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7018. '</div>',
  7019. '</div>',
  7020. //remote image - end
  7021. //local upload - start
  7022. '<div class="tab2" style="display:none;">',
  7023. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7024. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7025. //file
  7026. '<div class="ke-dialog-row">',
  7027. hiddenElements.join(''),
  7028. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7029. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7030. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7031. '</div>',
  7032. '</form>',
  7033. '</div>',
  7034. //local upload - end
  7035. '</div>'
  7036. ].join('');
  7037. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7038. dialogHeight = showLocal && showRemote ? 300 : 250;
  7039. var dialog = self.createDialog({
  7040. name: name,
  7041. width: dialogWidth,
  7042. height: dialogHeight,
  7043. title: self.lang(name),
  7044. body: html,
  7045. yesBtn: {
  7046. name: self.lang('yes'),
  7047. click: function (e) {
  7048. // Bugfix: http://code.google.com/p/kindeditor/issues/detail?id=319
  7049. if (dialog.isLoading) {
  7050. return;
  7051. }
  7052. // insert local image
  7053. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7054. if (uploadbutton.fileBox.val() == '') {
  7055. alert(self.lang('pleaseSelectFile'));
  7056. return;
  7057. }
  7058. dialog.showLoading(self.lang('uploadLoading'));
  7059. uploadbutton.submit();
  7060. localUrlBox.val('');
  7061. return;
  7062. }
  7063. // insert remote image
  7064. var url = K.trim(urlBox.val()),
  7065. width = widthBox.val(),
  7066. height = heightBox.val(),
  7067. title = titleBox.val(),
  7068. align = '';
  7069. alignBox.each(function () {
  7070. if (this.checked) {
  7071. align = this.value;
  7072. return false;
  7073. }
  7074. });
  7075. if (url == 'http://' || K.invalidUrl(url)) {
  7076. alert(self.lang('invalidUrl'));
  7077. urlBox[0].focus();
  7078. return;
  7079. }
  7080. if (!/^\d*$/.test(width)) {
  7081. alert(self.lang('invalidWidth'));
  7082. widthBox[0].focus();
  7083. return;
  7084. }
  7085. if (!/^\d*$/.test(height)) {
  7086. alert(self.lang('invalidHeight'));
  7087. heightBox[0].focus();
  7088. return;
  7089. }
  7090. clickFn.call(self, url, title, width, height, 0, align);
  7091. }
  7092. },
  7093. beforeRemove: function () {
  7094. viewServerBtn.unbind();
  7095. widthBox.unbind();
  7096. heightBox.unbind();
  7097. refreshBtn.unbind();
  7098. }
  7099. }),
  7100. div = dialog.div;
  7101. var urlBox = K('[name="url"]', div),
  7102. localUrlBox = K('[name="localUrl"]', div),
  7103. viewServerBtn = K('[name="viewServer"]', div),
  7104. widthBox = K('.tab1 [name="width"]', div),
  7105. heightBox = K('.tab1 [name="height"]', div),
  7106. refreshBtn = K('.ke-refresh-btn', div),
  7107. titleBox = K('.tab1 [name="title"]', div),
  7108. alignBox = K('.tab1 [name="align"]', div);
  7109. var tabs;
  7110. if (showRemote && showLocal) {
  7111. tabs = K.tabs({
  7112. src: K('.tabs', div),
  7113. afterSelect: function (i) { }
  7114. });
  7115. tabs.add({
  7116. title: lang.remoteImage,
  7117. panel: K('.tab1', div)
  7118. });
  7119. tabs.add({
  7120. title: lang.localImage,
  7121. panel: K('.tab2', div)
  7122. });
  7123. tabs.select(tabIndex);
  7124. } else if (showRemote) {
  7125. K('.tab1', div).show();
  7126. } else if (showLocal) {
  7127. K('.tab2', div).show();
  7128. }
  7129. var uploadbutton = K.uploadbutton({
  7130. button: K('.ke-upload-button', div)[0],
  7131. fieldName: filePostName,
  7132. form: K('.ke-form', div),
  7133. target: target,
  7134. width: 60,
  7135. afterUpload: function (data) {
  7136. dialog.hideLoading();
  7137. if (data.error === 0) {
  7138. //var url = data.url;
  7139. var url = "/g2work" + data.url;
  7140. if (formatUploadUrl) {
  7141. url = K.formatUrl(url, 'absolute');
  7142. }
  7143. if (self.afterUpload) {
  7144. self.afterUpload.call(self, url, data, name);
  7145. }
  7146. if (!fillDescAfterUploadImage) {
  7147. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7148. } else {
  7149. K(".ke-dialog-row #remoteUrl", div).val(url);
  7150. K(".ke-tabs-li", div)[0].click();
  7151. K(".ke-refresh-btn", div).click();
  7152. }
  7153. } else {
  7154. alert(data.message);
  7155. }
  7156. },
  7157. afterError: function (html) {
  7158. dialog.hideLoading();
  7159. self.errorDialog(html);
  7160. }
  7161. });
  7162. uploadbutton.fileBox.change(function (e) {
  7163. localUrlBox.val(uploadbutton.fileBox.val());
  7164. });
  7165. if (allowFileManager) {
  7166. viewServerBtn.click(function (e) {
  7167. self.loadPlugin('filemanager', function () {
  7168. self.plugin.filemanagerDialog({
  7169. viewType: 'VIEW',
  7170. dirName: 'image',
  7171. clickFn: function (url, title) {
  7172. if (self.dialogs.length > 1) {
  7173. K('[name="url"]', div).val(url);
  7174. if (self.afterSelectFile) {
  7175. self.afterSelectFile.call(self, url);
  7176. }
  7177. self.hideDialog();
  7178. }
  7179. }
  7180. });
  7181. });
  7182. });
  7183. } else {
  7184. viewServerBtn.hide();
  7185. }
  7186. var originalWidth = 0, originalHeight = 0;
  7187. function setSize(width, height) {
  7188. widthBox.val(width);
  7189. heightBox.val(height);
  7190. originalWidth = width;
  7191. originalHeight = height;
  7192. }
  7193. refreshBtn.click(function (e) {
  7194. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7195. position: 'absolute',
  7196. visibility: 'hidden',
  7197. top: 0,
  7198. left: '-1000px'
  7199. });
  7200. tempImg.bind('load', function () {
  7201. setSize(tempImg.width(), tempImg.height());
  7202. tempImg.remove();
  7203. });
  7204. K(document.body).append(tempImg);
  7205. });
  7206. widthBox.change(function (e) {
  7207. if (originalWidth > 0) {
  7208. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7209. }
  7210. });
  7211. heightBox.change(function (e) {
  7212. if (originalHeight > 0) {
  7213. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7214. }
  7215. });
  7216. urlBox.val(options.imageUrl);
  7217. setSize(options.imageWidth, options.imageHeight);
  7218. titleBox.val(options.imageTitle);
  7219. alignBox.each(function () {
  7220. if (this.value === options.imageAlign) {
  7221. this.checked = true;
  7222. return false;
  7223. }
  7224. });
  7225. if (showRemote && tabIndex === 0) {
  7226. urlBox[0].focus();
  7227. urlBox[0].select();
  7228. }
  7229. return dialog;
  7230. };
  7231. self.plugin.image = {
  7232. edit: function () {
  7233. var img = self.plugin.getSelectedImage();
  7234. self.plugin.imageDialog({
  7235. imageUrl: img ? img.attr('data-ke-src') : 'http://',
  7236. imageWidth: img ? img.width() : '',
  7237. imageHeight: img ? img.height() : '',
  7238. imageTitle: img ? img.attr('title') : '',
  7239. imageAlign: img ? img.attr('align') : '',
  7240. showRemote: allowImageRemote,
  7241. showLocal: allowImageUpload,
  7242. tabIndex: img ? 0 : imageTabIndex,
  7243. clickFn: function (url, title, width, height, border, align) {
  7244. if (img) {
  7245. img.attr('src', url);
  7246. img.attr('data-ke-src', url);
  7247. img.attr('width', width);
  7248. img.attr('height', height);
  7249. img.attr('title', title);
  7250. img.attr('align', align);
  7251. img.attr('alt', title);
  7252. } else {
  7253. self.exec('insertimage', url, title, width, height, border, align);
  7254. }
  7255. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  7256. setTimeout(function () {
  7257. self.hideDialog().focus();
  7258. }, 0);
  7259. }
  7260. });
  7261. },
  7262. 'delete': function () {
  7263. var target = self.plugin.getSelectedImage();
  7264. if (target.parent().name == 'a') {
  7265. target = target.parent();
  7266. }
  7267. target.remove();
  7268. // [IE] 删除图片后立即点击图片按钮出错
  7269. self.addBookmark();
  7270. }
  7271. };
  7272. self.clickToolbar(name, self.plugin.image.edit);
  7273. });
  7274. /*******************************************************************************
  7275. * KindEditor - WYSIWYG HTML Editor for Internet
  7276. * Copyright (C) 2006-2011 kindsoft.net
  7277. *
  7278. * @author Roddy <luolonghao@gmail.com>
  7279. * @site http://www.kindsoft.net/
  7280. * @licence http://www.kindsoft.net/license.php
  7281. *******************************************************************************/
  7282. KindEditor.plugin('insertfile', function (K) {
  7283. var self = this, name = 'insertfile',
  7284. allowFileUpload = K.undef(self.allowFileUpload, true),
  7285. allowFileManager = K.undef(self.allowFileManager, false),
  7286. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7287. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7288. extraParams = K.undef(self.extraFileUploadParams, {}),
  7289. filePostName = K.undef(self.filePostName, 'imgFile'),
  7290. lang = self.lang(name + '.');
  7291. self.plugin.fileDialog = function (options) {
  7292. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7293. fileTitle = K.undef(options.fileTitle, ''),
  7294. clickFn = options.clickFn;
  7295. var html = [
  7296. '<div style="padding:20px;">',
  7297. '<div class="ke-dialog-row">',
  7298. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7299. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7300. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7301. '<span class="ke-button-common ke-button-outer">',
  7302. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7303. '</span>',
  7304. '</div>',
  7305. //title
  7306. '<div class="ke-dialog-row">',
  7307. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7308. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7309. '</div>',
  7310. //form end
  7311. '</form>',
  7312. '</div>'
  7313. ].join('');
  7314. var dialog = self.createDialog({
  7315. name: name,
  7316. width: 450,
  7317. title: self.lang(name),
  7318. body: html,
  7319. yesBtn: {
  7320. name: self.lang('yes'),
  7321. click: function (e) {
  7322. var url = K.trim(urlBox.val()),
  7323. title = titleBox.val();
  7324. if (url == 'http://' || K.invalidUrl(url)) {
  7325. alert(self.lang('invalidUrl'));
  7326. urlBox[0].focus();
  7327. return;
  7328. }
  7329. if (K.trim(title) === '') {
  7330. title = url;
  7331. }
  7332. clickFn.call(self, url, title);
  7333. }
  7334. }
  7335. }),
  7336. div = dialog.div;
  7337. var urlBox = K('[name="url"]', div),
  7338. viewServerBtn = K('[name="viewServer"]', div),
  7339. titleBox = K('[name="title"]', div);
  7340. if (allowFileUpload) {
  7341. var uploadbutton = K.uploadbutton({
  7342. button: K('.ke-upload-button', div)[0],
  7343. fieldName: filePostName,
  7344. url: K.addParam(uploadJson, 'dir=file'),
  7345. extraParams: extraParams,
  7346. afterUpload: function (data) {
  7347. dialog.hideLoading();
  7348. if (data.error === 0) {
  7349. //var url = data.url;
  7350. var url = "/g2work" + data.url;
  7351. if (formatUploadUrl) {
  7352. url = K.formatUrl(url, 'absolute');
  7353. }
  7354. urlBox.val(url);
  7355. if (self.afterUpload) {
  7356. self.afterUpload.call(self, url, data, name);
  7357. }
  7358. alert(self.lang('uploadSuccess'));
  7359. } else {
  7360. alert(data.message);
  7361. }
  7362. },
  7363. afterError: function (html) {
  7364. dialog.hideLoading();
  7365. self.errorDialog(html);
  7366. }
  7367. });
  7368. uploadbutton.fileBox.change(function (e) {
  7369. dialog.showLoading(self.lang('uploadLoading'));
  7370. uploadbutton.submit();
  7371. });
  7372. } else {
  7373. K('.ke-upload-button', div).hide();
  7374. }
  7375. if (allowFileManager) {
  7376. viewServerBtn.click(function (e) {
  7377. self.loadPlugin('filemanager', function () {
  7378. self.plugin.filemanagerDialog({
  7379. viewType: 'LIST',
  7380. dirName: 'file',
  7381. clickFn: function (url, title) {
  7382. if (self.dialogs.length > 1) {
  7383. K('[name="url"]', div).val(url);
  7384. if (self.afterSelectFile) {
  7385. self.afterSelectFile.call(self, url);
  7386. }
  7387. self.hideDialog();
  7388. }
  7389. }
  7390. });
  7391. });
  7392. });
  7393. } else {
  7394. viewServerBtn.hide();
  7395. }
  7396. urlBox.val(fileUrl);
  7397. titleBox.val(fileTitle);
  7398. urlBox[0].focus();
  7399. urlBox[0].select();
  7400. };
  7401. self.clickToolbar(name, function () {
  7402. self.plugin.fileDialog({
  7403. clickFn: function (url, title) {
  7404. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7405. self.insertHtml(html).hideDialog().focus();
  7406. }
  7407. });
  7408. });
  7409. });
  7410. /*******************************************************************************
  7411. * KindEditor - WYSIWYG HTML Editor for Internet
  7412. * Copyright (C) 2006-2011 kindsoft.net
  7413. *
  7414. * @author Roddy <luolonghao@gmail.com>
  7415. * @site http://www.kindsoft.net/
  7416. * @licence http://www.kindsoft.net/license.php
  7417. *******************************************************************************/
  7418. KindEditor.plugin('lineheight', function (K) {
  7419. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7420. self.clickToolbar(name, function () {
  7421. var curVal = '', commonNode = self.cmd.commonNode({ '*': '.line-height' });
  7422. if (commonNode) {
  7423. curVal = commonNode.css('line-height');
  7424. }
  7425. var menu = self.createMenu({
  7426. name: name,
  7427. width: 150
  7428. });
  7429. K.each(lang.lineHeight, function (i, row) {
  7430. K.each(row, function (key, val) {
  7431. menu.addItem({
  7432. title: val,
  7433. checked: curVal === key,
  7434. click: function () {
  7435. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7436. span: '.line-height=' + key
  7437. });
  7438. self.updateState();
  7439. self.addBookmark();
  7440. self.hideMenu();
  7441. }
  7442. });
  7443. });
  7444. });
  7445. });
  7446. });
  7447. /*******************************************************************************
  7448. * KindEditor - WYSIWYG HTML Editor for Internet
  7449. * Copyright (C) 2006-2011 kindsoft.net
  7450. *
  7451. * @author Roddy <luolonghao@gmail.com>
  7452. * @site http://www.kindsoft.net/
  7453. * @licence http://www.kindsoft.net/license.php
  7454. *******************************************************************************/
  7455. KindEditor.plugin('link', function (K) {
  7456. var self = this, name = 'link';
  7457. self.plugin.link = {
  7458. edit: function () {
  7459. var lang = self.lang(name + '.'),
  7460. html = '<div style="padding:20px;">' +
  7461. //url
  7462. '<div class="ke-dialog-row">' +
  7463. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7464. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7465. //type
  7466. '<div class="ke-dialog-row"">' +
  7467. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7468. '<select id="keType" name="type"></select>' +
  7469. '</div>' +
  7470. '</div>',
  7471. dialog = self.createDialog({
  7472. name: name,
  7473. width: 450,
  7474. title: self.lang(name),
  7475. body: html,
  7476. yesBtn: {
  7477. name: self.lang('yes'),
  7478. click: function (e) {
  7479. var url = K.trim(urlBox.val());
  7480. if (url == 'http://' || K.invalidUrl(url)) {
  7481. alert(self.lang('invalidUrl'));
  7482. urlBox[0].focus();
  7483. return;
  7484. }
  7485. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7486. }
  7487. }
  7488. }),
  7489. div = dialog.div,
  7490. urlBox = K('input[name="url"]', div),
  7491. typeBox = K('select[name="type"]', div);
  7492. urlBox.val('http://');
  7493. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7494. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7495. self.cmd.selection();
  7496. var a = self.plugin.getSelectedLink();
  7497. if (a) {
  7498. self.cmd.range.selectNode(a[0]);
  7499. self.cmd.select();
  7500. urlBox.val(a.attr('data-ke-src'));
  7501. typeBox.val(a.attr('target'));
  7502. }
  7503. urlBox[0].focus();
  7504. urlBox[0].select();
  7505. },
  7506. 'delete': function () {
  7507. self.exec('unlink', null);
  7508. }
  7509. };
  7510. self.clickToolbar(name, self.plugin.link.edit);
  7511. });
  7512. /*******************************************************************************
  7513. * KindEditor - WYSIWYG HTML Editor for Internet
  7514. * Copyright (C) 2006-2011 kindsoft.net
  7515. *
  7516. * @author Roddy <luolonghao@gmail.com>
  7517. * @site http://www.kindsoft.net/
  7518. * @licence http://www.kindsoft.net/license.php
  7519. *******************************************************************************/
  7520. // Google Maps: http://code.google.com/apis/maps/index.html
  7521. KindEditor.plugin('map', function (K) {
  7522. var self = this, name = 'map', lang = self.lang(name + '.');
  7523. self.clickToolbar(name, function () {
  7524. var html = ['<div style="padding:10px 20px;">',
  7525. '<div class="ke-dialog-row">',
  7526. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  7527. '<span class="ke-button-common ke-button-outer">',
  7528. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  7529. '</span>',
  7530. '</div>',
  7531. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  7532. '</div>'].join('');
  7533. var dialog = self.createDialog({
  7534. name: name,
  7535. width: 600,
  7536. title: self.lang(name),
  7537. body: html,
  7538. yesBtn: {
  7539. name: self.lang('yes'),
  7540. click: function (e) {
  7541. var geocoder = win.geocoder,
  7542. map = win.map,
  7543. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  7544. zoom = map.getZoom(),
  7545. maptype = map.getMapTypeId(),
  7546. url = 'http://maps.googleapis.com/maps/api/staticmap';
  7547. url += '?center=' + encodeURIComponent(center);
  7548. url += '&zoom=' + encodeURIComponent(zoom);
  7549. url += '&size=558x360';
  7550. url += '&maptype=' + encodeURIComponent(maptype);
  7551. url += '&markers=' + encodeURIComponent(center);
  7552. url += '&language=' + self.langType;
  7553. url += '&sensor=false';
  7554. self.exec('insertimage', url).hideDialog().focus();
  7555. }
  7556. },
  7557. beforeRemove: function () {
  7558. searchBtn.remove();
  7559. if (doc) {
  7560. doc.write('');
  7561. }
  7562. iframe.remove();
  7563. }
  7564. });
  7565. var div = dialog.div,
  7566. addressBox = K('[name="address"]', div),
  7567. searchBtn = K('[name="searchBtn"]', div),
  7568. win, doc;
  7569. var iframeHtml = ['<!doctype html><html><head>',
  7570. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  7571. '<style>',
  7572. ' html { height: 100% }',
  7573. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  7574. ' #map_canvas { height: 100% }',
  7575. '</style>',
  7576. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  7577. '<script>',
  7578. 'var map, geocoder;',
  7579. 'function initialize() {',
  7580. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  7581. ' var options = {',
  7582. ' zoom: 11,',
  7583. ' center: latlng,',
  7584. ' disableDefaultUI: true,',
  7585. ' panControl: true,',
  7586. ' zoomControl: true,',
  7587. ' mapTypeControl: true,',
  7588. ' scaleControl: true,',
  7589. ' streetViewControl: false,',
  7590. ' overviewMapControl: true,',
  7591. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  7592. ' };',
  7593. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  7594. ' geocoder = new google.maps.Geocoder();',
  7595. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  7596. ' if (status == google.maps.GeocoderStatus.OK) {',
  7597. ' if (results[3]) {',
  7598. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  7599. ' }',
  7600. ' }',
  7601. ' });',
  7602. '}',
  7603. 'function search(address) {',
  7604. ' if (!map) return;',
  7605. ' geocoder.geocode({address : address}, function(results, status) {',
  7606. ' if (status == google.maps.GeocoderStatus.OK) {',
  7607. ' map.setZoom(11);',
  7608. ' map.setCenter(results[0].geometry.location);',
  7609. ' var marker = new google.maps.Marker({',
  7610. ' map: map,',
  7611. ' position: results[0].geometry.location',
  7612. ' });',
  7613. ' } else {',
  7614. ' alert("Invalid address: " + address);',
  7615. ' }',
  7616. ' });',
  7617. '}',
  7618. '</script>',
  7619. '</head>',
  7620. '<body onload="initialize();">',
  7621. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  7622. '</body></html>'].join('\n');
  7623. // TODO:用doc.write(iframeHtml)方式加载时,在IE6上第一次加载报错,暂时使用src方式
  7624. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  7625. function ready() {
  7626. win = iframe[0].contentWindow;
  7627. doc = K.iframeDoc(iframe);
  7628. //doc.open();
  7629. //doc.write(iframeHtml);
  7630. //doc.close();
  7631. }
  7632. iframe.bind('load', function () {
  7633. iframe.unbind('load');
  7634. if (K.IE) {
  7635. ready();
  7636. } else {
  7637. setTimeout(ready, 0);
  7638. }
  7639. });
  7640. K('.ke-map', div).replaceWith(iframe);
  7641. // search map
  7642. searchBtn.click(function () {
  7643. win.search(addressBox.val());
  7644. });
  7645. });
  7646. });
  7647. /*******************************************************************************
  7648. * KindEditor - WYSIWYG HTML Editor for Internet
  7649. * Copyright (C) 2006-2011 kindsoft.net
  7650. *
  7651. * @author Roddy <luolonghao@gmail.com>
  7652. * @site http://www.kindsoft.net/
  7653. * @licence http://www.kindsoft.net/license.php
  7654. *******************************************************************************/
  7655. KindEditor.plugin('media', function (K) {
  7656. var self = this, name = 'media', lang = self.lang(name + '.'),
  7657. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7658. allowFileManager = K.undef(self.allowFileManager, false),
  7659. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7660. extraParams = K.undef(self.extraFileUploadParams, {}),
  7661. filePostName = K.undef(self.filePostName, 'imgFile'),
  7662. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7663. self.plugin.media = {
  7664. edit: function () {
  7665. var html = [
  7666. '<div style="padding:20px;">',
  7667. //url
  7668. '<div class="ke-dialog-row">',
  7669. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7670. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7671. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7672. '<span class="ke-button-common ke-button-outer">',
  7673. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7674. '</span>',
  7675. '</div>',
  7676. //width
  7677. '<div class="ke-dialog-row">',
  7678. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7679. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7680. '</div>',
  7681. //height
  7682. '<div class="ke-dialog-row">',
  7683. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7684. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7685. '</div>',
  7686. //autostart
  7687. '<div class="ke-dialog-row">',
  7688. '<label for="keAutostart">' + lang.autostart + '</label>',
  7689. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7690. '</div>',
  7691. '</div>'
  7692. ].join('');
  7693. var dialog = self.createDialog({
  7694. name: name,
  7695. width: 450,
  7696. height: 230,
  7697. title: self.lang(name),
  7698. body: html,
  7699. yesBtn: {
  7700. name: self.lang('yes'),
  7701. click: function (e) {
  7702. var url = K.trim(urlBox.val()),
  7703. width = widthBox.val(),
  7704. height = heightBox.val();
  7705. if (url == 'http://' || K.invalidUrl(url)) {
  7706. alert(self.lang('invalidUrl'));
  7707. urlBox[0].focus();
  7708. return;
  7709. }
  7710. if (!/^\d*$/.test(width)) {
  7711. alert(self.lang('invalidWidth'));
  7712. widthBox[0].focus();
  7713. return;
  7714. }
  7715. if (!/^\d*$/.test(height)) {
  7716. alert(self.lang('invalidHeight'));
  7717. heightBox[0].focus();
  7718. return;
  7719. }
  7720. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7721. src: url,
  7722. type: K.mediaType(url),
  7723. width: width,
  7724. height: height,
  7725. autostart: autostartBox[0].checked ? 'true' : 'false',
  7726. loop: 'true'
  7727. });
  7728. self.insertHtml(html).hideDialog().focus();
  7729. }
  7730. }
  7731. }),
  7732. div = dialog.div,
  7733. urlBox = K('[name="url"]', div),
  7734. viewServerBtn = K('[name="viewServer"]', div),
  7735. widthBox = K('[name="width"]', div),
  7736. heightBox = K('[name="height"]', div),
  7737. autostartBox = K('[name="autostart"]', div);
  7738. urlBox.val('http://');
  7739. if (allowMediaUpload) {
  7740. var uploadbutton = K.uploadbutton({
  7741. button: K('.ke-upload-button', div)[0],
  7742. fieldName: filePostName,
  7743. extraParams: extraParams,
  7744. url: K.addParam(uploadJson, 'dir=media'),
  7745. afterUpload: function (data) {
  7746. dialog.hideLoading();
  7747. if (data.error === 0) {
  7748. //var url = data.url;
  7749. var url = "/g2work" + data.url;
  7750. if (formatUploadUrl) {
  7751. url = K.formatUrl(url, 'absolute');
  7752. }
  7753. urlBox.val(url);
  7754. if (self.afterUpload) {
  7755. self.afterUpload.call(self, url, data, name);
  7756. }
  7757. alert(self.lang('uploadSuccess'));
  7758. } else {
  7759. alert(data.message);
  7760. }
  7761. },
  7762. afterError: function (html) {
  7763. dialog.hideLoading();
  7764. self.errorDialog(html);
  7765. }
  7766. });
  7767. uploadbutton.fileBox.change(function (e) {
  7768. dialog.showLoading(self.lang('uploadLoading'));
  7769. uploadbutton.submit();
  7770. });
  7771. } else {
  7772. K('.ke-upload-button', div).hide();
  7773. }
  7774. if (allowFileManager) {
  7775. viewServerBtn.click(function (e) {
  7776. self.loadPlugin('filemanager', function () {
  7777. self.plugin.filemanagerDialog({
  7778. viewType: 'LIST',
  7779. dirName: 'media',
  7780. clickFn: function (url, title) {
  7781. if (self.dialogs.length > 1) {
  7782. K('[name="url"]', div).val(url);
  7783. if (self.afterSelectFile) {
  7784. self.afterSelectFile.call(self, url);
  7785. }
  7786. self.hideDialog();
  7787. }
  7788. }
  7789. });
  7790. });
  7791. });
  7792. } else {
  7793. viewServerBtn.hide();
  7794. }
  7795. var img = self.plugin.getSelectedMedia();
  7796. if (img) {
  7797. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7798. urlBox.val(attrs.src);
  7799. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7800. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7801. autostartBox[0].checked = (attrs.autostart === 'true');
  7802. }
  7803. urlBox[0].focus();
  7804. urlBox[0].select();
  7805. },
  7806. 'delete': function () {
  7807. self.plugin.getSelectedMedia().remove();
  7808. // [IE] 删除图片后立即点击图片按钮出错
  7809. self.addBookmark();
  7810. }
  7811. };
  7812. self.clickToolbar(name, self.plugin.media.edit);
  7813. });
  7814. /*******************************************************************************
  7815. * KindEditor - WYSIWYG HTML Editor for Internet
  7816. * Copyright (C) 2006-2011 kindsoft.net
  7817. *
  7818. * @author Roddy <luolonghao@gmail.com>
  7819. * @site http://www.kindsoft.net/
  7820. * @licence http://www.kindsoft.net/license.php
  7821. *******************************************************************************/
  7822. (function (K) {
  7823. function KSWFUpload(options) {
  7824. this.init(options);
  7825. }
  7826. K.extend(KSWFUpload, {
  7827. init: function (options) {
  7828. var self = this;
  7829. options.afterError = options.afterError || function (str) {
  7830. alert(str);
  7831. };
  7832. self.options = options;
  7833. self.progressbars = {};
  7834. // template
  7835. self.div = K(options.container).html([
  7836. '<div class="ke-swfupload">',
  7837. '<div class="ke-swfupload-top">',
  7838. '<div class="ke-inline-block ke-swfupload-button">',
  7839. '<input type="button" value="Browse" />',
  7840. '</div>',
  7841. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7842. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7843. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7844. '</span>',
  7845. '</div>',
  7846. '<div class="ke-swfupload-body"></div>',
  7847. '</div>'
  7848. ].join(''));
  7849. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7850. function showError(itemDiv, msg) {
  7851. K('.ke-status > div', itemDiv).hide();
  7852. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7853. }
  7854. var settings = {
  7855. debug: false,
  7856. upload_url: options.uploadUrl,
  7857. flash_url: options.flashUrl,
  7858. file_post_name: options.filePostName,
  7859. button_placeholder: K('.ke-swfupload-button > input', self.div)[0],
  7860. button_image_url: options.buttonImageUrl,
  7861. button_width: options.buttonWidth,
  7862. button_height: options.buttonHeight,
  7863. button_cursor: SWFUpload.CURSOR.HAND,
  7864. file_types: options.fileTypes,
  7865. file_types_description: options.fileTypesDesc,
  7866. file_upload_limit: options.fileUploadLimit,
  7867. file_size_limit: options.fileSizeLimit,
  7868. post_params: options.postParams,
  7869. file_queued_handler: function (file) {
  7870. file.url = self.options.fileIconUrl;
  7871. self.appendFile(file);
  7872. },
  7873. file_queue_error_handler: function (file, errorCode, message) {
  7874. var errorName = '';
  7875. switch (errorCode) {
  7876. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7877. errorName = options.queueLimitExceeded;
  7878. break;
  7879. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7880. errorName = options.fileExceedsSizeLimit;
  7881. break;
  7882. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7883. errorName = options.zeroByteFile;
  7884. break;
  7885. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7886. errorName = options.invalidFiletype;
  7887. break;
  7888. default:
  7889. errorName = options.unknownError;
  7890. break;
  7891. }
  7892. K.DEBUG && alert(errorName);
  7893. },
  7894. upload_start_handler: function (file) {
  7895. var self = this;
  7896. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7897. K('.ke-status > div', itemDiv).hide();
  7898. K('.ke-progressbar', itemDiv).show();
  7899. },
  7900. upload_progress_handler: function (file, bytesLoaded, bytesTotal) {
  7901. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7902. var progressbar = self.progressbars[file.id];
  7903. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7904. progressbar.percent.html(percent + '%');
  7905. },
  7906. upload_error_handler: function (file, errorCode, message) {
  7907. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7908. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7909. showError(itemDiv, self.options.errorMessage);
  7910. }
  7911. },
  7912. upload_success_handler: function (file, serverData) {
  7913. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7914. var data = {};
  7915. try {
  7916. data = K.json(serverData);
  7917. } catch (e) {
  7918. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7919. }
  7920. if (data.error !== 0) {
  7921. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7922. return;
  7923. }
  7924. file.url = data.url;
  7925. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7926. K('.ke-status > div', itemDiv).hide();
  7927. }
  7928. };
  7929. self.swfu = new SWFUpload(settings);
  7930. K('.ke-swfupload-startupload input', self.div).click(function () {
  7931. self.swfu.startUpload();
  7932. });
  7933. },
  7934. getUrlList: function () {
  7935. var list = [];
  7936. K('.ke-img', self.bodyDiv).each(function () {
  7937. var img = K(this);
  7938. var status = img.attr('data-status');
  7939. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7940. list.push(img.data('data'));
  7941. }
  7942. });
  7943. return list;
  7944. },
  7945. removeFile: function (fileId) {
  7946. var self = this;
  7947. self.swfu.cancelUpload(fileId);
  7948. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7949. K('.ke-photo', itemDiv).unbind();
  7950. K('.ke-delete', itemDiv).unbind();
  7951. itemDiv.remove();
  7952. },
  7953. removeFiles: function () {
  7954. var self = this;
  7955. K('.ke-item', self.bodyDiv).each(function () {
  7956. self.removeFile(K(this).attr('data-id'));
  7957. });
  7958. },
  7959. appendFile: function (file) {
  7960. var self = this;
  7961. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7962. self.bodyDiv.append(itemDiv);
  7963. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7964. .mouseover(function (e) {
  7965. K(this).addClass('ke-on');
  7966. })
  7967. .mouseout(function (e) {
  7968. K(this).removeClass('ke-on');
  7969. });
  7970. itemDiv.append(photoDiv);
  7971. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7972. photoDiv.append(img);
  7973. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function () {
  7974. self.removeFile(file.id);
  7975. });
  7976. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7977. // progressbar
  7978. K(['<div class="ke-progressbar">',
  7979. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7980. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7981. // message
  7982. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7983. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7984. self.progressbars[file.id] = {
  7985. bar: K('.ke-progressbar-bar-inner', photoDiv),
  7986. percent: K('.ke-progressbar-percent', photoDiv)
  7987. };
  7988. },
  7989. remove: function () {
  7990. this.removeFiles();
  7991. this.swfu.destroy();
  7992. this.div.html('');
  7993. }
  7994. });
  7995. K.swfupload = function (element, options) {
  7996. return new KSWFUpload(element, options);
  7997. };
  7998. })(KindEditor);
  7999. KindEditor.plugin('multiimage', function (K) {
  8000. var self = this, name = 'multiimage',
  8001. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8002. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8003. imgPath = self.pluginsPath + 'multiimage/images/',
  8004. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8005. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8006. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8007. filePostName = K.undef(self.filePostName, 'imgFile'),
  8008. lang = self.lang(name + '.');
  8009. self.plugin.multiImageDialog = function (options) {
  8010. var clickFn = options.clickFn,
  8011. uploadDesc = K.tmpl(lang.uploadDesc, { uploadLimit: imageUploadLimit, sizeLimit: imageSizeLimit });
  8012. var html = [
  8013. '<div style="padding:20px;">',
  8014. '<div class="swfupload">',
  8015. '</div>',
  8016. '</div>'
  8017. ].join('');
  8018. var dialog = self.createDialog({
  8019. name: name,
  8020. width: 650,
  8021. height: 510,
  8022. title: self.lang(name),
  8023. body: html,
  8024. previewBtn: {
  8025. name: lang.insertAll,
  8026. click: function (e) {
  8027. clickFn.call(self, swfupload.getUrlList());
  8028. }
  8029. },
  8030. yesBtn: {
  8031. name: lang.clearAll,
  8032. click: function (e) {
  8033. swfupload.removeFiles();
  8034. }
  8035. },
  8036. beforeRemove: function () {
  8037. // IE9 bugfix: https://github.com/kindsoft/kindeditor/issues/72
  8038. if (!K.IE || K.V <= 8) {
  8039. swfupload.remove();
  8040. }
  8041. }
  8042. }),
  8043. div = dialog.div;
  8044. var swfupload = K.swfupload({
  8045. container: K('.swfupload', div),
  8046. buttonImageUrl: imgPath + (self.langType == 'zh_CN' ? 'select-files-zh_CN.png' : 'select-files-en.png'),
  8047. buttonWidth: self.langType == 'zh_CN' ? 72 : 88,
  8048. buttonHeight: 23,
  8049. fileIconUrl: imgPath + 'image.png',
  8050. uploadDesc: uploadDesc,
  8051. startButtonValue: lang.startUpload,
  8052. uploadUrl: K.addParam(uploadJson, 'dir=image'),
  8053. flashUrl: imgPath + 'swfupload.swf',
  8054. filePostName: filePostName,
  8055. fileTypes: '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8056. fileTypesDesc: 'Image Files',
  8057. fileUploadLimit: imageUploadLimit,
  8058. fileSizeLimit: imageSizeLimit,
  8059. postParams: K.undef(self.extraFileUploadParams, {}),
  8060. queueLimitExceeded: lang.queueLimitExceeded,
  8061. fileExceedsSizeLimit: lang.fileExceedsSizeLimit,
  8062. zeroByteFile: lang.zeroByteFile,
  8063. invalidFiletype: lang.invalidFiletype,
  8064. unknownError: lang.unknownError,
  8065. pendingMessage: lang.pending,
  8066. errorMessage: lang.uploadError,
  8067. afterError: function (html) {
  8068. self.errorDialog(html);
  8069. }
  8070. });
  8071. return dialog;
  8072. };
  8073. self.clickToolbar(name, function () {
  8074. self.plugin.multiImageDialog({
  8075. clickFn: function (urlList) {
  8076. if (urlList.length === 0) {
  8077. return;
  8078. }
  8079. K.each(urlList, function (i, data) {
  8080. if (self.afterUpload) {
  8081. self.afterUpload.call(self, data.url, data, 'multiimage');
  8082. }
  8083. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8084. });
  8085. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  8086. setTimeout(function () {
  8087. self.hideDialog().focus();
  8088. }, 0);
  8089. }
  8090. });
  8091. });
  8092. });
  8093. /**
  8094. * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
  8095. *
  8096. * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
  8097. *
  8098. * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz閚 and Mammon Media and is released under the MIT License:
  8099. * http://www.opensource.org/licenses/mit-license.php
  8100. *
  8101. * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
  8102. * http://www.opensource.org/licenses/mit-license.php
  8103. *
  8104. */
  8105. /* ******************* */
  8106. /* Constructor & Init */
  8107. /* ******************* */
  8108. (function () {
  8109. window.SWFUpload = function (settings) {
  8110. this.initSWFUpload(settings);
  8111. };
  8112. SWFUpload.prototype.initSWFUpload = function (settings) {
  8113. try {
  8114. this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
  8115. this.settings = settings;
  8116. this.eventQueue = [];
  8117. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8118. this.movieElement = null;
  8119. // Setup global control tracking
  8120. SWFUpload.instances[this.movieName] = this;
  8121. // Load the settings. Load the Flash movie.
  8122. this.initSettings();
  8123. this.loadFlash();
  8124. this.displayDebugInfo();
  8125. } catch (ex) {
  8126. delete SWFUpload.instances[this.movieName];
  8127. throw ex;
  8128. }
  8129. };
  8130. /* *************** */
  8131. /* Static Members */
  8132. /* *************** */
  8133. SWFUpload.instances = {};
  8134. SWFUpload.movieCount = 0;
  8135. SWFUpload.version = "2.2.0 2009-03-25";
  8136. SWFUpload.QUEUE_ERROR = {
  8137. QUEUE_LIMIT_EXCEEDED: -100,
  8138. FILE_EXCEEDS_SIZE_LIMIT: -110,
  8139. ZERO_BYTE_FILE: -120,
  8140. INVALID_FILETYPE: -130
  8141. };
  8142. SWFUpload.UPLOAD_ERROR = {
  8143. HTTP_ERROR: -200,
  8144. MISSING_UPLOAD_URL: -210,
  8145. IO_ERROR: -220,
  8146. SECURITY_ERROR: -230,
  8147. UPLOAD_LIMIT_EXCEEDED: -240,
  8148. UPLOAD_FAILED: -250,
  8149. SPECIFIED_FILE_ID_NOT_FOUND: -260,
  8150. FILE_VALIDATION_FAILED: -270,
  8151. FILE_CANCELLED: -280,
  8152. UPLOAD_STOPPED: -290
  8153. };
  8154. SWFUpload.FILE_STATUS = {
  8155. QUEUED: -1,
  8156. IN_PROGRESS: -2,
  8157. ERROR: -3,
  8158. COMPLETE: -4,
  8159. CANCELLED: -5
  8160. };
  8161. SWFUpload.BUTTON_ACTION = {
  8162. SELECT_FILE: -100,
  8163. SELECT_FILES: -110,
  8164. START_UPLOAD: -120
  8165. };
  8166. SWFUpload.CURSOR = {
  8167. ARROW: -1,
  8168. HAND: -2
  8169. };
  8170. SWFUpload.WINDOW_MODE = {
  8171. WINDOW: "window",
  8172. TRANSPARENT: "transparent",
  8173. OPAQUE: "opaque"
  8174. };
  8175. // Private: takes a URL, determines if it is relative and converts to an absolute URL
  8176. // using the current site. Only processes the URL if it can, otherwise returns the URL untouched
  8177. SWFUpload.completeURL = function (url) {
  8178. if (typeof (url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8179. return url;
  8180. }
  8181. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8182. var indexSlash = window.location.pathname.lastIndexOf("/");
  8183. if (indexSlash <= 0) {
  8184. path = "/";
  8185. } else {
  8186. path = window.location.pathname.substr(0, indexSlash) + "/";
  8187. }
  8188. return /*currentURL +*/ path + url;
  8189. };
  8190. /* ******************** */
  8191. /* Instance Members */
  8192. /* ******************** */
  8193. // Private: initSettings ensures that all the
  8194. // settings are set, getting a default value if one was not assigned.
  8195. SWFUpload.prototype.initSettings = function () {
  8196. this.ensureDefault = function (settingName, defaultValue) {
  8197. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8198. };
  8199. // Upload backend settings
  8200. this.ensureDefault("upload_url", "");
  8201. this.ensureDefault("preserve_relative_urls", false);
  8202. this.ensureDefault("file_post_name", "Filedata");
  8203. this.ensureDefault("post_params", {});
  8204. this.ensureDefault("use_query_string", false);
  8205. this.ensureDefault("requeue_on_error", false);
  8206. this.ensureDefault("http_success", []);
  8207. this.ensureDefault("assume_success_timeout", 0);
  8208. // File Settings
  8209. this.ensureDefault("file_types", "*.*");
  8210. this.ensureDefault("file_types_description", "All Files");
  8211. this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
  8212. this.ensureDefault("file_upload_limit", 0);
  8213. this.ensureDefault("file_queue_limit", 0);
  8214. // Flash Settings
  8215. this.ensureDefault("flash_url", "swfupload.swf");
  8216. this.ensureDefault("prevent_swf_caching", true);
  8217. // Button Settings
  8218. this.ensureDefault("button_image_url", "");
  8219. this.ensureDefault("button_width", 1);
  8220. this.ensureDefault("button_height", 1);
  8221. this.ensureDefault("button_text", "");
  8222. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8223. this.ensureDefault("button_text_top_padding", 0);
  8224. this.ensureDefault("button_text_left_padding", 0);
  8225. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8226. this.ensureDefault("button_disabled", false);
  8227. this.ensureDefault("button_placeholder_id", "");
  8228. this.ensureDefault("button_placeholder", null);
  8229. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8230. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8231. // Debug Settings
  8232. this.ensureDefault("debug", false);
  8233. this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
  8234. // Event Handlers
  8235. this.settings.return_upload_start_handler = this.returnUploadStart;
  8236. this.ensureDefault("swfupload_loaded_handler", null);
  8237. this.ensureDefault("file_dialog_start_handler", null);
  8238. this.ensureDefault("file_queued_handler", null);
  8239. this.ensureDefault("file_queue_error_handler", null);
  8240. this.ensureDefault("file_dialog_complete_handler", null);
  8241. this.ensureDefault("upload_start_handler", null);
  8242. this.ensureDefault("upload_progress_handler", null);
  8243. this.ensureDefault("upload_error_handler", null);
  8244. this.ensureDefault("upload_success_handler", null);
  8245. this.ensureDefault("upload_complete_handler", null);
  8246. this.ensureDefault("debug_handler", this.debugMessage);
  8247. this.ensureDefault("custom_settings", {});
  8248. // Other settings
  8249. this.customSettings = this.settings.custom_settings;
  8250. // Update the flash url if needed
  8251. if (!!this.settings.prevent_swf_caching) {
  8252. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8253. }
  8254. if (!this.settings.preserve_relative_urls) {
  8255. //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it
  8256. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8257. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8258. }
  8259. delete this.ensureDefault;
  8260. };
  8261. // Private: loadFlash replaces the button_placeholder element with the flash movie.
  8262. SWFUpload.prototype.loadFlash = function () {
  8263. var targetElement, tempParent;
  8264. // Make sure an element with the ID we are going to use doesn't already exist
  8265. if (document.getElementById(this.movieName) !== null) {
  8266. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8267. }
  8268. // Get the element where we will be placing the flash movie
  8269. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8270. if (targetElement == undefined) {
  8271. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8272. }
  8273. // Append the container and load the flash
  8274. tempParent = document.createElement("div");
  8275. tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
  8276. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8277. // Fix IE Flash/Form bug
  8278. if (window[this.movieName] == undefined) {
  8279. window[this.movieName] = this.getMovieElement();
  8280. }
  8281. };
  8282. // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
  8283. SWFUpload.prototype.getFlashHTML = function () {
  8284. // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  8285. // Fix bug for IE9
  8286. // http://www.kindsoft.net/view.php?bbsid=7&postid=5825&pagenum=1
  8287. var classid = '';
  8288. if (KindEditor.IE && KindEditor.V > 8) {
  8289. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8290. }
  8291. 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">',
  8292. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8293. '<param name="movie" value="', this.settings.flash_url, '" />',
  8294. '<param name="quality" value="high" />',
  8295. '<param name="menu" value="false" />',
  8296. '<param name="allowScriptAccess" value="always" />',
  8297. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8298. '</object>'].join("");
  8299. };
  8300. // Private: getFlashVars builds the parameter string that will be passed
  8301. // to flash in the flashvars param.
  8302. SWFUpload.prototype.getFlashVars = function () {
  8303. // Build a string from the post param object
  8304. var paramString = this.buildParamString();
  8305. var httpSuccessString = this.settings.http_success.join(",");
  8306. // Build the parameter string
  8307. return ["movieName=", encodeURIComponent(this.movieName),
  8308. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8309. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8310. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8311. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8312. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8313. "&amp;params=", encodeURIComponent(paramString),
  8314. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8315. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8316. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8317. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8318. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8319. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8320. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8321. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8322. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8323. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8324. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8325. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8326. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8327. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8328. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8329. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8330. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8331. ].join("");
  8332. };
  8333. // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
  8334. // The element is cached after the first lookup
  8335. SWFUpload.prototype.getMovieElement = function () {
  8336. if (this.movieElement == undefined) {
  8337. this.movieElement = document.getElementById(this.movieName);
  8338. }
  8339. if (this.movieElement === null) {
  8340. throw "Could not find Flash element";
  8341. }
  8342. return this.movieElement;
  8343. };
  8344. // Private: buildParamString takes the name/value pairs in the post_params setting object
  8345. // and joins them up in to a string formatted "name=value&amp;name=value"
  8346. SWFUpload.prototype.buildParamString = function () {
  8347. var postParams = this.settings.post_params;
  8348. var paramStringPairs = [];
  8349. if (typeof (postParams) === "object") {
  8350. for (var name in postParams) {
  8351. if (postParams.hasOwnProperty(name)) {
  8352. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8353. }
  8354. }
  8355. }
  8356. return paramStringPairs.join("&amp;");
  8357. };
  8358. // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
  8359. // all references to the SWF, and other objects so memory is properly freed.
  8360. // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
  8361. // Credits: Major improvements provided by steffen
  8362. SWFUpload.prototype.destroy = function () {
  8363. try {
  8364. // Make sure Flash is done before we try to remove it
  8365. this.cancelUpload(null, false);
  8366. // Remove the SWFUpload DOM nodes
  8367. var movieElement = null;
  8368. movieElement = this.getMovieElement();
  8369. if (movieElement && typeof (movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8370. // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
  8371. for (var i in movieElement) {
  8372. try {
  8373. if (typeof (movieElement[i]) === "function") {
  8374. movieElement[i] = null;
  8375. }
  8376. } catch (ex1) { }
  8377. }
  8378. // Remove the Movie Element from the page
  8379. try {
  8380. movieElement.parentNode.removeChild(movieElement);
  8381. } catch (ex) { }
  8382. }
  8383. // Remove IE form fix reference
  8384. window[this.movieName] = null;
  8385. // Destroy other references
  8386. SWFUpload.instances[this.movieName] = null;
  8387. delete SWFUpload.instances[this.movieName];
  8388. this.movieElement = null;
  8389. this.settings = null;
  8390. this.customSettings = null;
  8391. this.eventQueue = null;
  8392. this.movieName = null;
  8393. return true;
  8394. } catch (ex2) {
  8395. return false;
  8396. }
  8397. };
  8398. // Public: displayDebugInfo prints out settings and configuration
  8399. // information about this SWFUpload instance.
  8400. // This function (and any references to it) can be deleted when placing
  8401. // SWFUpload in production.
  8402. SWFUpload.prototype.displayDebugInfo = function () {
  8403. this.debug(
  8404. [
  8405. "---SWFUpload Instance Info---\n",
  8406. "Version: ", SWFUpload.version, "\n",
  8407. "Movie Name: ", this.movieName, "\n",
  8408. "Settings:\n",
  8409. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8410. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8411. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8412. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8413. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8414. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8415. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8416. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8417. "\t", "file_types: ", this.settings.file_types, "\n",
  8418. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8419. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8420. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8421. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8422. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8423. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8424. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8425. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8426. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8427. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8428. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8429. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8430. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8431. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8432. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8433. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8434. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8435. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8436. "Event Handlers:\n",
  8437. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8438. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8439. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8440. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8441. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8442. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8443. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8444. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8445. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8446. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8447. ].join("")
  8448. );
  8449. };
  8450. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8451. the maintain v2 API compatibility
  8452. */
  8453. // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
  8454. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8455. if (value == undefined) {
  8456. return (this.settings[name] = default_value);
  8457. } else {
  8458. return (this.settings[name] = value);
  8459. }
  8460. };
  8461. // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
  8462. SWFUpload.prototype.getSetting = function (name) {
  8463. if (this.settings[name] != undefined) {
  8464. return this.settings[name];
  8465. }
  8466. return "";
  8467. };
  8468. // Private: callFlash handles function calls made to the Flash element.
  8469. // Calls are made with a setTimeout for some functions to work around
  8470. // bugs in the ExternalInterface library.
  8471. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8472. argumentArray = argumentArray || [];
  8473. var movieElement = this.getMovieElement();
  8474. var returnValue, returnString;
  8475. // Flash's method if calling ExternalInterface methods (code adapted from MooTools).
  8476. try {
  8477. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8478. returnValue = eval(returnString);
  8479. } catch (ex) {
  8480. throw "Call to " + functionName + " failed";
  8481. }
  8482. // Unescape file post param values
  8483. if (returnValue != undefined && typeof returnValue.post === "object") {
  8484. returnValue = this.unescapeFilePostParams(returnValue);
  8485. }
  8486. return returnValue;
  8487. };
  8488. /* *****************************
  8489. -- Flash control methods --
  8490. Your UI should use these
  8491. to operate SWFUpload
  8492. ***************************** */
  8493. // WARNING: this function does not work in Flash Player 10
  8494. // Public: selectFile causes a File Selection Dialog window to appear. This
  8495. // dialog only allows 1 file to be selected.
  8496. SWFUpload.prototype.selectFile = function () {
  8497. this.callFlash("SelectFile");
  8498. };
  8499. // WARNING: this function does not work in Flash Player 10
  8500. // Public: selectFiles causes a File Selection Dialog window to appear/ This
  8501. // dialog allows the user to select any number of files
  8502. // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
  8503. // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
  8504. // for this bug.
  8505. SWFUpload.prototype.selectFiles = function () {
  8506. this.callFlash("SelectFiles");
  8507. };
  8508. // Public: startUpload starts uploading the first file in the queue unless
  8509. // the optional parameter 'fileID' specifies the ID
  8510. SWFUpload.prototype.startUpload = function (fileID) {
  8511. this.callFlash("StartUpload", [fileID]);
  8512. };
  8513. // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
  8514. // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
  8515. // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
  8516. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8517. if (triggerErrorEvent !== false) {
  8518. triggerErrorEvent = true;
  8519. }
  8520. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8521. };
  8522. // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
  8523. // If nothing is currently uploading then nothing happens.
  8524. SWFUpload.prototype.stopUpload = function () {
  8525. this.callFlash("StopUpload");
  8526. };
  8527. /* ************************
  8528. * Settings methods
  8529. * These methods change the SWFUpload settings.
  8530. * SWFUpload settings should not be changed directly on the settings object
  8531. * since many of the settings need to be passed to Flash in order to take
  8532. * effect.
  8533. * *********************** */
  8534. // Public: getStats gets the file statistics object.
  8535. SWFUpload.prototype.getStats = function () {
  8536. return this.callFlash("GetStats");
  8537. };
  8538. // Public: setStats changes the SWFUpload statistics. You shouldn't need to
  8539. // change the statistics but you can. Changing the statistics does not
  8540. // affect SWFUpload accept for the successful_uploads count which is used
  8541. // by the upload_limit setting to determine how many files the user may upload.
  8542. SWFUpload.prototype.setStats = function (statsObject) {
  8543. this.callFlash("SetStats", [statsObject]);
  8544. };
  8545. // Public: getFile retrieves a File object by ID or Index. If the file is
  8546. // not found then 'null' is returned.
  8547. SWFUpload.prototype.getFile = function (fileID) {
  8548. if (typeof (fileID) === "number") {
  8549. return this.callFlash("GetFileByIndex", [fileID]);
  8550. } else {
  8551. return this.callFlash("GetFile", [fileID]);
  8552. }
  8553. };
  8554. // Public: addFileParam sets a name/value pair that will be posted with the
  8555. // file specified by the Files ID. If the name already exists then the
  8556. // exiting value will be overwritten.
  8557. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8558. return this.callFlash("AddFileParam", [fileID, name, value]);
  8559. };
  8560. // Public: removeFileParam removes a previously set (by addFileParam) name/value
  8561. // pair from the specified file.
  8562. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8563. this.callFlash("RemoveFileParam", [fileID, name]);
  8564. };
  8565. // Public: setUploadUrl changes the upload_url setting.
  8566. SWFUpload.prototype.setUploadURL = function (url) {
  8567. this.settings.upload_url = url.toString();
  8568. this.callFlash("SetUploadURL", [url]);
  8569. };
  8570. // Public: setPostParams changes the post_params setting
  8571. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8572. this.settings.post_params = paramsObject;
  8573. this.callFlash("SetPostParams", [paramsObject]);
  8574. };
  8575. // Public: addPostParam adds post name/value pair. Each name can have only one value.
  8576. SWFUpload.prototype.addPostParam = function (name, value) {
  8577. this.settings.post_params[name] = value;
  8578. this.callFlash("SetPostParams", [this.settings.post_params]);
  8579. };
  8580. // Public: removePostParam deletes post name/value pair.
  8581. SWFUpload.prototype.removePostParam = function (name) {
  8582. delete this.settings.post_params[name];
  8583. this.callFlash("SetPostParams", [this.settings.post_params]);
  8584. };
  8585. // Public: setFileTypes changes the file_types setting and the file_types_description setting
  8586. SWFUpload.prototype.setFileTypes = function (types, description) {
  8587. this.settings.file_types = types;
  8588. this.settings.file_types_description = description;
  8589. this.callFlash("SetFileTypes", [types, description]);
  8590. };
  8591. // Public: setFileSizeLimit changes the file_size_limit setting
  8592. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8593. this.settings.file_size_limit = fileSizeLimit;
  8594. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8595. };
  8596. // Public: setFileUploadLimit changes the file_upload_limit setting
  8597. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8598. this.settings.file_upload_limit = fileUploadLimit;
  8599. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8600. };
  8601. // Public: setFileQueueLimit changes the file_queue_limit setting
  8602. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8603. this.settings.file_queue_limit = fileQueueLimit;
  8604. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8605. };
  8606. // Public: setFilePostName changes the file_post_name setting
  8607. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8608. this.settings.file_post_name = filePostName;
  8609. this.callFlash("SetFilePostName", [filePostName]);
  8610. };
  8611. // Public: setUseQueryString changes the use_query_string setting
  8612. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8613. this.settings.use_query_string = useQueryString;
  8614. this.callFlash("SetUseQueryString", [useQueryString]);
  8615. };
  8616. // Public: setRequeueOnError changes the requeue_on_error setting
  8617. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8618. this.settings.requeue_on_error = requeueOnError;
  8619. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8620. };
  8621. // Public: setHTTPSuccess changes the http_success setting
  8622. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8623. if (typeof http_status_codes === "string") {
  8624. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8625. }
  8626. this.settings.http_success = http_status_codes;
  8627. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8628. };
  8629. // Public: setHTTPSuccess changes the http_success setting
  8630. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8631. this.settings.assume_success_timeout = timeout_seconds;
  8632. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8633. };
  8634. // Public: setDebugEnabled changes the debug_enabled setting
  8635. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8636. this.settings.debug_enabled = debugEnabled;
  8637. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8638. };
  8639. // Public: setButtonImageURL loads a button image sprite
  8640. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8641. if (buttonImageURL == undefined) {
  8642. buttonImageURL = "";
  8643. }
  8644. this.settings.button_image_url = buttonImageURL;
  8645. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8646. };
  8647. // Public: setButtonDimensions resizes the Flash Movie and button
  8648. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8649. this.settings.button_width = width;
  8650. this.settings.button_height = height;
  8651. var movie = this.getMovieElement();
  8652. if (movie != undefined) {
  8653. movie.style.width = width + "px";
  8654. movie.style.height = height + "px";
  8655. }
  8656. this.callFlash("SetButtonDimensions", [width, height]);
  8657. };
  8658. // Public: setButtonText Changes the text overlaid on the button
  8659. SWFUpload.prototype.setButtonText = function (html) {
  8660. this.settings.button_text = html;
  8661. this.callFlash("SetButtonText", [html]);
  8662. };
  8663. // Public: setButtonTextPadding changes the top and left padding of the text overlay
  8664. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8665. this.settings.button_text_top_padding = top;
  8666. this.settings.button_text_left_padding = left;
  8667. this.callFlash("SetButtonTextPadding", [left, top]);
  8668. };
  8669. // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
  8670. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8671. this.settings.button_text_style = css;
  8672. this.callFlash("SetButtonTextStyle", [css]);
  8673. };
  8674. // Public: setButtonDisabled disables/enables the button
  8675. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8676. this.settings.button_disabled = isDisabled;
  8677. this.callFlash("SetButtonDisabled", [isDisabled]);
  8678. };
  8679. // Public: setButtonAction sets the action that occurs when the button is clicked
  8680. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8681. this.settings.button_action = buttonAction;
  8682. this.callFlash("SetButtonAction", [buttonAction]);
  8683. };
  8684. // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
  8685. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8686. this.settings.button_cursor = cursor;
  8687. this.callFlash("SetButtonCursor", [cursor]);
  8688. };
  8689. /* *******************************
  8690. Flash Event Interfaces
  8691. These functions are used by Flash to trigger the various
  8692. events.
  8693. All these functions a Private.
  8694. Because the ExternalInterface library is buggy the event calls
  8695. are added to a queue and the queue then executed by a setTimeout.
  8696. This ensures that events are executed in a determinate order and that
  8697. the ExternalInterface bugs are avoided.
  8698. ******************************* */
  8699. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8700. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8701. if (argumentArray == undefined) {
  8702. argumentArray = [];
  8703. } else if (!(argumentArray instanceof Array)) {
  8704. argumentArray = [argumentArray];
  8705. }
  8706. var self = this;
  8707. if (typeof this.settings[handlerName] === "function") {
  8708. // Queue the event
  8709. this.eventQueue.push(function () {
  8710. this.settings[handlerName].apply(this, argumentArray);
  8711. });
  8712. // Execute the next queued event
  8713. setTimeout(function () {
  8714. self.executeNextEvent();
  8715. }, 0);
  8716. } else if (this.settings[handlerName] !== null) {
  8717. throw "Event handler " + handlerName + " is unknown or is not a function";
  8718. }
  8719. };
  8720. // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
  8721. // we must queue them in order to garentee that they are executed in order.
  8722. SWFUpload.prototype.executeNextEvent = function () {
  8723. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8724. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8725. if (typeof (f) === "function") {
  8726. f.apply(this);
  8727. }
  8728. };
  8729. // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
  8730. // properties that contain characters that are not valid for JavaScript identifiers. To work around this
  8731. // the Flash Component escapes the parameter names and we must unescape again before passing them along.
  8732. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8733. var reg = /[$]([0-9a-f]{4})/i;
  8734. var unescapedPost = {};
  8735. var uk;
  8736. if (file != undefined) {
  8737. for (var k in file.post) {
  8738. if (file.post.hasOwnProperty(k)) {
  8739. uk = k;
  8740. var match;
  8741. while ((match = reg.exec(uk)) !== null) {
  8742. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8743. }
  8744. unescapedPost[uk] = file.post[k];
  8745. }
  8746. }
  8747. file.post = unescapedPost;
  8748. }
  8749. return file;
  8750. };
  8751. // Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working)
  8752. SWFUpload.prototype.testExternalInterface = function () {
  8753. try {
  8754. return this.callFlash("TestExternalInterface");
  8755. } catch (ex) {
  8756. return false;
  8757. }
  8758. };
  8759. // Private: This event is called by Flash when it has finished loading. Don't modify this.
  8760. // Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded.
  8761. SWFUpload.prototype.flashReady = function () {
  8762. // Check that the movie element is loaded correctly with its ExternalInterface methods defined
  8763. var movieElement = this.getMovieElement();
  8764. if (!movieElement) {
  8765. this.debug("Flash called back ready but the flash movie can't be found.");
  8766. return;
  8767. }
  8768. this.cleanUp(movieElement);
  8769. this.queueEvent("swfupload_loaded_handler");
  8770. };
  8771. // Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
  8772. // This function is called by Flash each time the ExternalInterface functions are created.
  8773. SWFUpload.prototype.cleanUp = function (movieElement) {
  8774. // Pro-actively unhook all the Flash functions
  8775. try {
  8776. if (this.movieElement && typeof (movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8777. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8778. for (var key in movieElement) {
  8779. try {
  8780. if (typeof (movieElement[key]) === "function") {
  8781. movieElement[key] = null;
  8782. }
  8783. } catch (ex) {
  8784. }
  8785. }
  8786. }
  8787. } catch (ex1) {
  8788. }
  8789. // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
  8790. // it doesn't display errors.
  8791. window["__flash__removeCallback"] = function (instance, name) {
  8792. try {
  8793. if (instance) {
  8794. instance[name] = null;
  8795. }
  8796. } catch (flashEx) {
  8797. }
  8798. };
  8799. };
  8800. /* This is a chance to do something before the browse window opens */
  8801. SWFUpload.prototype.fileDialogStart = function () {
  8802. this.queueEvent("file_dialog_start_handler");
  8803. };
  8804. /* Called when a file is successfully added to the queue. */
  8805. SWFUpload.prototype.fileQueued = function (file) {
  8806. file = this.unescapeFilePostParams(file);
  8807. this.queueEvent("file_queued_handler", file);
  8808. };
  8809. /* Handle errors that occur when an attempt to queue a file fails. */
  8810. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8811. file = this.unescapeFilePostParams(file);
  8812. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8813. };
  8814. /* Called after the file dialog has closed and the selected files have been queued.
  8815. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8816. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8817. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8818. };
  8819. SWFUpload.prototype.uploadStart = function (file) {
  8820. file = this.unescapeFilePostParams(file);
  8821. this.queueEvent("return_upload_start_handler", file);
  8822. };
  8823. SWFUpload.prototype.returnUploadStart = function (file) {
  8824. var returnValue;
  8825. if (typeof this.settings.upload_start_handler === "function") {
  8826. file = this.unescapeFilePostParams(file);
  8827. returnValue = this.settings.upload_start_handler.call(this, file);
  8828. } else if (this.settings.upload_start_handler != undefined) {
  8829. throw "upload_start_handler must be a function";
  8830. }
  8831. // Convert undefined to true so if nothing is returned from the upload_start_handler it is
  8832. // interpretted as 'true'.
  8833. if (returnValue === undefined) {
  8834. returnValue = true;
  8835. }
  8836. returnValue = !!returnValue;
  8837. this.callFlash("ReturnUploadStart", [returnValue]);
  8838. };
  8839. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8840. file = this.unescapeFilePostParams(file);
  8841. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8842. };
  8843. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8844. file = this.unescapeFilePostParams(file);
  8845. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8846. };
  8847. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8848. file = this.unescapeFilePostParams(file);
  8849. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8850. };
  8851. SWFUpload.prototype.uploadComplete = function (file) {
  8852. file = this.unescapeFilePostParams(file);
  8853. this.queueEvent("upload_complete_handler", file);
  8854. };
  8855. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8856. internal debug console. You can override this event and have messages written where you want. */
  8857. SWFUpload.prototype.debug = function (message) {
  8858. this.queueEvent("debug_handler", message);
  8859. };
  8860. /* **********************************
  8861. Debug Console
  8862. The debug console is a self contained, in page location
  8863. for debug message to be sent. The Debug Console adds
  8864. itself to the body if necessary.
  8865. The console is automatically scrolled as messages appear.
  8866. If you are using your own debug handler or when you deploy to production and
  8867. have debug disabled you can remove these functions to reduce the file size
  8868. and complexity.
  8869. ********************************** */
  8870. // Private: debugMessage is the default debug_handler. If you want to print debug messages
  8871. // call the debug() function. When overriding the function your own function should
  8872. // check to see if the debug setting is true before outputting debug information.
  8873. SWFUpload.prototype.debugMessage = function (message) {
  8874. if (this.settings.debug) {
  8875. var exceptionMessage, exceptionValues = [];
  8876. // Check for an exception object and print it nicely
  8877. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8878. for (var key in message) {
  8879. if (message.hasOwnProperty(key)) {
  8880. exceptionValues.push(key + ": " + message[key]);
  8881. }
  8882. }
  8883. exceptionMessage = exceptionValues.join("\n") || "";
  8884. exceptionValues = exceptionMessage.split("\n");
  8885. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8886. SWFUpload.Console.writeLine(exceptionMessage);
  8887. } else {
  8888. SWFUpload.Console.writeLine(message);
  8889. }
  8890. }
  8891. };
  8892. SWFUpload.Console = {};
  8893. SWFUpload.Console.writeLine = function (message) {
  8894. var console, documentForm;
  8895. try {
  8896. console = document.getElementById("SWFUpload_Console");
  8897. if (!console) {
  8898. documentForm = document.createElement("form");
  8899. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8900. console = document.createElement("textarea");
  8901. console.id = "SWFUpload_Console";
  8902. console.style.fontFamily = "monospace";
  8903. console.setAttribute("wrap", "off");
  8904. console.wrap = "off";
  8905. console.style.overflow = "auto";
  8906. console.style.width = "700px";
  8907. console.style.height = "350px";
  8908. console.style.margin = "5px";
  8909. documentForm.appendChild(console);
  8910. }
  8911. console.value += message + "\n";
  8912. console.scrollTop = console.scrollHeight - console.clientHeight;
  8913. } catch (ex) {
  8914. alert("Exception: " + ex.name + " Message: " + ex.message);
  8915. }
  8916. };
  8917. })();
  8918. (function () {
  8919. /*
  8920. Queue Plug-in
  8921. Features:
  8922. *Adds a cancelQueue() method for cancelling the entire queue.
  8923. *All queued files are uploaded when startUpload() is called.
  8924. *If false is returned from uploadComplete then the queue upload is stopped.
  8925. If false is not returned (strict comparison) then the queue upload is continued.
  8926. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8927. Set the event handler with the queue_complete_handler setting.
  8928. */
  8929. if (typeof (SWFUpload) === "function") {
  8930. SWFUpload.queue = {};
  8931. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8932. return function () {
  8933. if (typeof (oldInitSettings) === "function") {
  8934. oldInitSettings.call(this);
  8935. }
  8936. this.queueSettings = {};
  8937. this.queueSettings.queue_cancelled_flag = false;
  8938. this.queueSettings.queue_upload_count = 0;
  8939. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8940. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8941. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8942. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8943. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8944. };
  8945. })(SWFUpload.prototype.initSettings);
  8946. SWFUpload.prototype.startUpload = function (fileID) {
  8947. this.queueSettings.queue_cancelled_flag = false;
  8948. this.callFlash("StartUpload", [fileID]);
  8949. };
  8950. SWFUpload.prototype.cancelQueue = function () {
  8951. this.queueSettings.queue_cancelled_flag = true;
  8952. this.stopUpload();
  8953. var stats = this.getStats();
  8954. while (stats.files_queued > 0) {
  8955. this.cancelUpload();
  8956. stats = this.getStats();
  8957. }
  8958. };
  8959. SWFUpload.queue.uploadStartHandler = function (file) {
  8960. var returnValue;
  8961. if (typeof (this.queueSettings.user_upload_start_handler) === "function") {
  8962. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8963. }
  8964. // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
  8965. returnValue = (returnValue === false) ? false : true;
  8966. this.queueSettings.queue_cancelled_flag = !returnValue;
  8967. return returnValue;
  8968. };
  8969. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8970. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8971. var continueUpload;
  8972. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8973. this.queueSettings.queue_upload_count++;
  8974. }
  8975. if (typeof (user_upload_complete_handler) === "function") {
  8976. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8977. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8978. // If the file was stopped and re-queued don't restart the upload
  8979. continueUpload = false;
  8980. } else {
  8981. continueUpload = true;
  8982. }
  8983. if (continueUpload) {
  8984. var stats = this.getStats();
  8985. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8986. this.startUpload();
  8987. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8988. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8989. this.queueSettings.queue_upload_count = 0;
  8990. } else {
  8991. this.queueSettings.queue_cancelled_flag = false;
  8992. this.queueSettings.queue_upload_count = 0;
  8993. }
  8994. }
  8995. };
  8996. }
  8997. })();
  8998. /*******************************************************************************
  8999. * KindEditor - WYSIWYG HTML Editor for Internet
  9000. * Copyright (C) 2006-2011 kindsoft.net
  9001. *
  9002. * @author Roddy <luolonghao@gmail.com>
  9003. * @site http://www.kindsoft.net/
  9004. * @licence http://www.kindsoft.net/license.php
  9005. *******************************************************************************/
  9006. KindEditor.plugin('pagebreak', function (K) {
  9007. var self = this;
  9008. var name = 'pagebreak';
  9009. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  9010. self.clickToolbar(name, function () {
  9011. var cmd = self.cmd, range = cmd.range;
  9012. self.focus();
  9013. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  9014. self.insertHtml(pagebreakHtml + tail);
  9015. if (tail !== '') {
  9016. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9017. range.selectNodeContents(p[0]);
  9018. p.removeAttr('id');
  9019. cmd.select();
  9020. }
  9021. });
  9022. });
  9023. /*******************************************************************************
  9024. * KindEditor - WYSIWYG HTML Editor for Internet
  9025. * Copyright (C) 2006-2011 kindsoft.net
  9026. *
  9027. * @author Roddy <luolonghao@gmail.com>
  9028. * @site http://www.kindsoft.net/
  9029. * @licence http://www.kindsoft.net/license.php
  9030. *******************************************************************************/
  9031. KindEditor.plugin('plainpaste', function (K) {
  9032. var self = this, name = 'plainpaste';
  9033. self.clickToolbar(name, function () {
  9034. var lang = self.lang(name + '.'),
  9035. html = '<div style="padding:10px 20px;">' +
  9036. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9037. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9038. '</div>',
  9039. dialog = self.createDialog({
  9040. name: name,
  9041. width: 450,
  9042. title: self.lang(name),
  9043. body: html,
  9044. yesBtn: {
  9045. name: self.lang('yes'),
  9046. click: function (e) {
  9047. var html = textarea.val();
  9048. html = K.escape(html);
  9049. html = html.replace(/ {2}/g, ' &nbsp;');
  9050. if (self.newlineTag == 'p') {
  9051. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9052. } else {
  9053. html = html.replace(/\n/g, '<br />$&');
  9054. }
  9055. self.insertHtml(html).hideDialog().focus();
  9056. }
  9057. }
  9058. }),
  9059. textarea = K('textarea', dialog.div);
  9060. textarea[0].focus();
  9061. });
  9062. });
  9063. /*******************************************************************************
  9064. * KindEditor - WYSIWYG HTML Editor for Internet
  9065. * Copyright (C) 2006-2011 kindsoft.net
  9066. *
  9067. * @author Roddy <luolonghao@gmail.com>
  9068. * @site http://www.kindsoft.net/
  9069. * @licence http://www.kindsoft.net/license.php
  9070. *******************************************************************************/
  9071. KindEditor.plugin('preview', function (K) {
  9072. var self = this, name = 'preview', undefined;
  9073. self.clickToolbar(name, function () {
  9074. var lang = self.lang(name + '.'),
  9075. html = '<div style="padding:10px 20px;">' +
  9076. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9077. '</div>',
  9078. dialog = self.createDialog({
  9079. name: name,
  9080. width: 750,
  9081. title: self.lang(name),
  9082. body: html
  9083. }),
  9084. iframe = K('iframe', dialog.div),
  9085. doc = K.iframeDoc(iframe);
  9086. doc.open();
  9087. doc.write(self.fullHtml());
  9088. doc.close();
  9089. K(doc.body).css('background-color', '#FFF');
  9090. iframe[0].contentWindow.focus();
  9091. });
  9092. });
  9093. /*******************************************************************************
  9094. * KindEditor - WYSIWYG HTML Editor for Internet
  9095. * Copyright (C) 2006-2011 kindsoft.net
  9096. *
  9097. * @author Roddy <luolonghao@gmail.com>
  9098. * @site http://www.kindsoft.net/
  9099. * @licence http://www.kindsoft.net/license.php
  9100. *******************************************************************************/
  9101. KindEditor.plugin('quickformat', function (K) {
  9102. var self = this, name = 'quickformat',
  9103. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9104. function getFirstChild(knode) {
  9105. var child = knode.first();
  9106. while (child && child.first()) {
  9107. child = child.first();
  9108. }
  9109. return child;
  9110. }
  9111. self.clickToolbar(name, function () {
  9112. self.focus();
  9113. var doc = self.edit.doc,
  9114. range = self.cmd.range,
  9115. child = K(doc.body).first(), next,
  9116. nodeList = [], subList = [],
  9117. bookmark = range.createBookmark(true);
  9118. while (child) {
  9119. next = child.next();
  9120. var firstChild = getFirstChild(child);
  9121. if (!firstChild || firstChild.name != 'img') {
  9122. if (blockMap[child.name]) {
  9123. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9124. child.css('text-indent', '2em');
  9125. } else {
  9126. subList.push(child);
  9127. }
  9128. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9129. if (subList.length > 0) {
  9130. nodeList.push(subList);
  9131. }
  9132. subList = [];
  9133. }
  9134. }
  9135. child = next;
  9136. }
  9137. K.each(nodeList, function (i, subList) {
  9138. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9139. subList[0].before(wrapper);
  9140. K.each(subList, function (i, knode) {
  9141. wrapper.append(knode);
  9142. });
  9143. });
  9144. range.moveToBookmark(bookmark);
  9145. self.addBookmark();
  9146. });
  9147. });
  9148. /**
  9149. --------------------------
  9150. abcd<br />
  9151. 1234<br />
  9152. to
  9153. <p style="text-indent:2em;">
  9154. abcd<br />
  9155. 1234<br />
  9156. </p>
  9157. --------------------------
  9158. &nbsp; abcd<img>1233
  9159. <p>1234</p>
  9160. to
  9161. <p style="text-indent:2em;">abcd<img>1233</p>
  9162. <p style="text-indent:2em;">1234</p>
  9163. --------------------------
  9164. *//*******************************************************************************
  9165. * KindEditor - WYSIWYG HTML Editor for Internet
  9166. * Copyright (C) 2006-2011 kindsoft.net
  9167. *
  9168. * @author Roddy <luolonghao@gmail.com>
  9169. * @site http://www.kindsoft.net/
  9170. * @licence http://www.kindsoft.net/license.php
  9171. *******************************************************************************/
  9172. KindEditor.plugin('table', function (K) {
  9173. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9174. // 设置颜色
  9175. function _setColor(box, color) {
  9176. color = color.toUpperCase();
  9177. box.css('background-color', color);
  9178. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9179. box.html(color);
  9180. }
  9181. // 初始化取色器
  9182. var pickerList = [];
  9183. function _initColorPicker(dialogDiv, colorBox) {
  9184. colorBox.bind('click,mousedown', function (e) {
  9185. e.stopPropagation();
  9186. });
  9187. function removePicker() {
  9188. K.each(pickerList, function () {
  9189. this.remove();
  9190. });
  9191. pickerList = [];
  9192. K(document).unbind('click,mousedown', removePicker);
  9193. dialogDiv.unbind('click,mousedown', removePicker);
  9194. }
  9195. colorBox.click(function (e) {
  9196. removePicker();
  9197. var box = K(this),
  9198. pos = box.pos();
  9199. var picker = K.colorpicker({
  9200. x: pos.x,
  9201. y: pos.y + box.height(),
  9202. z: 811214,
  9203. selectedColor: K(this).html(),
  9204. colors: self.colorTable,
  9205. noColor: self.lang('noColor'),
  9206. shadowMode: self.shadowMode,
  9207. click: function (color) {
  9208. _setColor(box, color);
  9209. removePicker();
  9210. }
  9211. });
  9212. pickerList.push(picker);
  9213. K(document).bind('click,mousedown', removePicker);
  9214. dialogDiv.bind('click,mousedown', removePicker);
  9215. });
  9216. }
  9217. // 取得下一行cell的index
  9218. function _getCellIndex(table, row, cell) {
  9219. var rowSpanCount = 0;
  9220. for (var i = 0, len = row.cells.length; i < len; i++) {
  9221. if (row.cells[i] == cell) {
  9222. break;
  9223. }
  9224. rowSpanCount += row.cells[i].rowSpan - 1;
  9225. }
  9226. return cell.cellIndex - rowSpanCount;
  9227. }
  9228. self.plugin.table = {
  9229. //insert or modify table
  9230. prop: function (isInsert) {
  9231. var html = [
  9232. '<div style="padding:20px;">',
  9233. //rows, cols
  9234. '<div class="ke-dialog-row">',
  9235. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9236. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9237. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9238. '</div>',
  9239. //width, height
  9240. '<div class="ke-dialog-row">',
  9241. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9242. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9243. '<select name="widthType">',
  9244. '<option value="%">' + lang.percent + '</option>',
  9245. '<option value="px">' + lang.px + '</option>',
  9246. '</select> &nbsp; ',
  9247. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9248. '<select name="heightType">',
  9249. '<option value="%">' + lang.percent + '</option>',
  9250. '<option value="px">' + lang.px + '</option>',
  9251. '</select>',
  9252. '</div>',
  9253. //space, padding
  9254. '<div class="ke-dialog-row">',
  9255. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9256. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9257. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9258. '</div>',
  9259. //align
  9260. '<div class="ke-dialog-row">',
  9261. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9262. '<select id="keAlign" name="align">',
  9263. '<option value="">' + lang.alignDefault + '</option>',
  9264. '<option value="left">' + lang.alignLeft + '</option>',
  9265. '<option value="center">' + lang.alignCenter + '</option>',
  9266. '<option value="right">' + lang.alignRight + '</option>',
  9267. '</select>',
  9268. '</div>',
  9269. //border
  9270. '<div class="ke-dialog-row">',
  9271. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9272. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9273. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9274. '</div>',
  9275. //background color
  9276. '<div class="ke-dialog-row">',
  9277. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9278. '<span class="ke-inline-block ke-input-color"></span>',
  9279. '</div>',
  9280. '</div>'
  9281. ].join('');
  9282. var bookmark = self.cmd.range.createBookmark();
  9283. var dialog = self.createDialog({
  9284. name: name,
  9285. width: 500,
  9286. title: self.lang(name),
  9287. body: html,
  9288. beforeRemove: function () {
  9289. colorBox.unbind();
  9290. },
  9291. yesBtn: {
  9292. name: self.lang('yes'),
  9293. click: function (e) {
  9294. var rows = rowsBox.val(),
  9295. cols = colsBox.val(),
  9296. width = widthBox.val(),
  9297. height = heightBox.val(),
  9298. widthType = widthTypeBox.val(),
  9299. heightType = heightTypeBox.val(),
  9300. padding = paddingBox.val(),
  9301. spacing = spacingBox.val(),
  9302. align = alignBox.val(),
  9303. border = borderBox.val(),
  9304. borderColor = K(colorBox[0]).html() || '',
  9305. bgColor = K(colorBox[1]).html() || '';
  9306. if (rows == 0 || !/^\d+$/.test(rows)) {
  9307. alert(self.lang('invalidRows'));
  9308. rowsBox[0].focus();
  9309. return;
  9310. }
  9311. if (cols == 0 || !/^\d+$/.test(cols)) {
  9312. alert(self.lang('invalidRows'));
  9313. colsBox[0].focus();
  9314. return;
  9315. }
  9316. if (!/^\d*$/.test(width)) {
  9317. alert(self.lang('invalidWidth'));
  9318. widthBox[0].focus();
  9319. return;
  9320. }
  9321. if (!/^\d*$/.test(height)) {
  9322. alert(self.lang('invalidHeight'));
  9323. heightBox[0].focus();
  9324. return;
  9325. }
  9326. if (!/^\d*$/.test(padding)) {
  9327. alert(self.lang('invalidPadding'));
  9328. paddingBox[0].focus();
  9329. return;
  9330. }
  9331. if (!/^\d*$/.test(spacing)) {
  9332. alert(self.lang('invalidSpacing'));
  9333. spacingBox[0].focus();
  9334. return;
  9335. }
  9336. if (!/^\d*$/.test(border)) {
  9337. alert(self.lang('invalidBorder'));
  9338. borderBox[0].focus();
  9339. return;
  9340. }
  9341. //modify table
  9342. if (table) {
  9343. if (width !== '') {
  9344. table.width(width + widthType);
  9345. } else {
  9346. table.css('width', '');
  9347. }
  9348. if (table[0].width !== undefined) {
  9349. table.removeAttr('width');
  9350. }
  9351. if (height !== '') {
  9352. table.height(height + heightType);
  9353. } else {
  9354. table.css('height', '');
  9355. }
  9356. if (table[0].height !== undefined) {
  9357. table.removeAttr('height');
  9358. }
  9359. table.css('background-color', bgColor);
  9360. if (table[0].bgColor !== undefined) {
  9361. table.removeAttr('bgColor');
  9362. }
  9363. if (padding !== '') {
  9364. table[0].cellPadding = padding;
  9365. } else {
  9366. table.removeAttr('cellPadding');
  9367. }
  9368. if (spacing !== '') {
  9369. table[0].cellSpacing = spacing;
  9370. } else {
  9371. table.removeAttr('cellSpacing');
  9372. }
  9373. if (align !== '') {
  9374. table[0].align = align;
  9375. } else {
  9376. table.removeAttr('align');
  9377. }
  9378. if (border !== '') {
  9379. table.attr('border', border);
  9380. } else {
  9381. table.removeAttr('border');
  9382. }
  9383. if (border === '' || border === '0') {
  9384. table.addClass(zeroborder);
  9385. } else {
  9386. table.removeClass(zeroborder);
  9387. }
  9388. if (borderColor !== '') {
  9389. table.attr('borderColor', borderColor);
  9390. } else {
  9391. table.removeAttr('borderColor');
  9392. }
  9393. self.hideDialog().focus();
  9394. self.cmd.range.moveToBookmark(bookmark);
  9395. self.cmd.select();
  9396. self.addBookmark();
  9397. return;
  9398. }
  9399. //insert new table
  9400. var style = '';
  9401. if (width !== '') {
  9402. style += 'width:' + width + widthType + ';';
  9403. }
  9404. if (height !== '') {
  9405. style += 'height:' + height + heightType + ';';
  9406. }
  9407. if (bgColor !== '') {
  9408. style += 'background-color:' + bgColor + ';';
  9409. }
  9410. var html = '<table';
  9411. if (style !== '') {
  9412. html += ' style="' + style + '"';
  9413. }
  9414. if (padding !== '') {
  9415. html += ' cellpadding="' + padding + '"';
  9416. }
  9417. if (spacing !== '') {
  9418. html += ' cellspacing="' + spacing + '"';
  9419. }
  9420. if (align !== '') {
  9421. html += ' align="' + align + '"';
  9422. }
  9423. if (border !== '') {
  9424. html += ' border="' + border + '"';
  9425. }
  9426. if (border === '' || border === '0') {
  9427. html += ' class="' + zeroborder + '"';
  9428. }
  9429. if (borderColor !== '') {
  9430. html += ' bordercolor="' + borderColor + '"';
  9431. }
  9432. html += '>';
  9433. for (var i = 0; i < rows; i++) {
  9434. html += '<tr>';
  9435. for (var j = 0; j < cols; j++) {
  9436. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9437. }
  9438. html += '</tr>';
  9439. }
  9440. html += '</table>';
  9441. if (!K.IE) {
  9442. html += '<br />';
  9443. }
  9444. self.insertHtml(html);
  9445. self.select().hideDialog().focus();
  9446. self.addBookmark();
  9447. }
  9448. }
  9449. }),
  9450. div = dialog.div,
  9451. rowsBox = K('[name="rows"]', div).val(3),
  9452. colsBox = K('[name="cols"]', div).val(2),
  9453. widthBox = K('[name="width"]', div).val(100),
  9454. heightBox = K('[name="height"]', div),
  9455. widthTypeBox = K('[name="widthType"]', div),
  9456. heightTypeBox = K('[name="heightType"]', div),
  9457. paddingBox = K('[name="padding"]', div).val(2),
  9458. spacingBox = K('[name="spacing"]', div).val(0),
  9459. alignBox = K('[name="align"]', div),
  9460. borderBox = K('[name="border"]', div).val(1),
  9461. colorBox = K('.ke-input-color', div);
  9462. _initColorPicker(div, colorBox.eq(0));
  9463. _initColorPicker(div, colorBox.eq(1));
  9464. _setColor(colorBox.eq(0), '#000000');
  9465. _setColor(colorBox.eq(1), '');
  9466. // foucs and select
  9467. rowsBox[0].focus();
  9468. rowsBox[0].select();
  9469. var table;
  9470. if (isInsert) {
  9471. return;
  9472. }
  9473. //get selected table node
  9474. table = self.plugin.getSelectedTable();
  9475. if (table) {
  9476. rowsBox.val(table[0].rows.length);
  9477. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9478. rowsBox.attr('disabled', true);
  9479. colsBox.attr('disabled', true);
  9480. var match,
  9481. tableWidth = table[0].style.width || table[0].width,
  9482. tableHeight = table[0].style.height || table[0].height;
  9483. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9484. widthBox.val(match[1]);
  9485. widthTypeBox.val(match[2]);
  9486. } else {
  9487. widthBox.val('');
  9488. }
  9489. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9490. heightBox.val(match[1]);
  9491. heightTypeBox.val(match[2]);
  9492. }
  9493. paddingBox.val(table[0].cellPadding || '');
  9494. spacingBox.val(table[0].cellSpacing || '');
  9495. alignBox.val(table[0].align || '');
  9496. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9497. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9498. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9499. widthBox[0].focus();
  9500. widthBox[0].select();
  9501. }
  9502. },
  9503. //modify cell
  9504. cellprop: function () {
  9505. var html = [
  9506. '<div style="padding:20px;">',
  9507. //width, height
  9508. '<div class="ke-dialog-row">',
  9509. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9510. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9511. '<select name="widthType">',
  9512. '<option value="%">' + lang.percent + '</option>',
  9513. '<option value="px">' + lang.px + '</option>',
  9514. '</select> &nbsp; ',
  9515. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9516. '<select name="heightType">',
  9517. '<option value="%">' + lang.percent + '</option>',
  9518. '<option value="px">' + lang.px + '</option>',
  9519. '</select>',
  9520. '</div>',
  9521. //align
  9522. '<div class="ke-dialog-row">',
  9523. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9524. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9525. '<option value="">' + lang.alignDefault + '</option>',
  9526. '<option value="left">' + lang.alignLeft + '</option>',
  9527. '<option value="center">' + lang.alignCenter + '</option>',
  9528. '<option value="right">' + lang.alignRight + '</option>',
  9529. '</select> ',
  9530. lang.verticalAlign + ' <select name="verticalAlign">',
  9531. '<option value="">' + lang.alignDefault + '</option>',
  9532. '<option value="top">' + lang.alignTop + '</option>',
  9533. '<option value="middle">' + lang.alignMiddle + '</option>',
  9534. '<option value="bottom">' + lang.alignBottom + '</option>',
  9535. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9536. '</select>',
  9537. '</div>',
  9538. //border
  9539. '<div class="ke-dialog-row">',
  9540. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9541. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9542. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9543. '</div>',
  9544. //background color
  9545. '<div class="ke-dialog-row">',
  9546. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9547. '<span class="ke-inline-block ke-input-color"></span>',
  9548. '</div>',
  9549. '</div>'
  9550. ].join('');
  9551. var bookmark = self.cmd.range.createBookmark();
  9552. var dialog = self.createDialog({
  9553. name: name,
  9554. width: 500,
  9555. title: self.lang('tablecell'),
  9556. body: html,
  9557. beforeRemove: function () {
  9558. colorBox.unbind();
  9559. },
  9560. yesBtn: {
  9561. name: self.lang('yes'),
  9562. click: function (e) {
  9563. var width = widthBox.val(),
  9564. height = heightBox.val(),
  9565. widthType = widthTypeBox.val(),
  9566. heightType = heightTypeBox.val(),
  9567. padding = paddingBox.val(),
  9568. spacing = spacingBox.val(),
  9569. textAlign = textAlignBox.val(),
  9570. verticalAlign = verticalAlignBox.val(),
  9571. border = borderBox.val(),
  9572. borderColor = K(colorBox[0]).html() || '',
  9573. bgColor = K(colorBox[1]).html() || '';
  9574. if (!/^\d*$/.test(width)) {
  9575. alert(self.lang('invalidWidth'));
  9576. widthBox[0].focus();
  9577. return;
  9578. }
  9579. if (!/^\d*$/.test(height)) {
  9580. alert(self.lang('invalidHeight'));
  9581. heightBox[0].focus();
  9582. return;
  9583. }
  9584. if (!/^\d*$/.test(border)) {
  9585. alert(self.lang('invalidBorder'));
  9586. borderBox[0].focus();
  9587. return;
  9588. }
  9589. cell.css({
  9590. width: width !== '' ? (width + widthType) : '',
  9591. height: height !== '' ? (height + heightType) : '',
  9592. 'background-color': bgColor,
  9593. 'text-align': textAlign,
  9594. 'vertical-align': verticalAlign,
  9595. 'border-width': border,
  9596. 'border-style': border !== '' ? 'solid' : '',
  9597. 'border-color': borderColor
  9598. });
  9599. self.hideDialog().focus();
  9600. self.cmd.range.moveToBookmark(bookmark);
  9601. self.cmd.select();
  9602. self.addBookmark();
  9603. }
  9604. }
  9605. }),
  9606. div = dialog.div,
  9607. widthBox = K('[name="width"]', div).val(100),
  9608. heightBox = K('[name="height"]', div),
  9609. widthTypeBox = K('[name="widthType"]', div),
  9610. heightTypeBox = K('[name="heightType"]', div),
  9611. paddingBox = K('[name="padding"]', div).val(2),
  9612. spacingBox = K('[name="spacing"]', div).val(0),
  9613. textAlignBox = K('[name="textAlign"]', div),
  9614. verticalAlignBox = K('[name="verticalAlign"]', div),
  9615. borderBox = K('[name="border"]', div).val(1),
  9616. colorBox = K('.ke-input-color', div);
  9617. _initColorPicker(div, colorBox.eq(0));
  9618. _initColorPicker(div, colorBox.eq(1));
  9619. _setColor(colorBox.eq(0), '#000000');
  9620. _setColor(colorBox.eq(1), '');
  9621. // foucs and select
  9622. widthBox[0].focus();
  9623. widthBox[0].select();
  9624. // get selected cell
  9625. var cell = self.plugin.getSelectedCell();
  9626. var match,
  9627. cellWidth = cell[0].style.width || cell[0].width || '',
  9628. cellHeight = cell[0].style.height || cell[0].height || '';
  9629. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9630. widthBox.val(match[1]);
  9631. widthTypeBox.val(match[2]);
  9632. } else {
  9633. widthBox.val('');
  9634. }
  9635. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9636. heightBox.val(match[1]);
  9637. heightTypeBox.val(match[2]);
  9638. }
  9639. textAlignBox.val(cell[0].style.textAlign || '');
  9640. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9641. var border = cell[0].style.borderWidth || '';
  9642. if (border) {
  9643. border = parseInt(border);
  9644. }
  9645. borderBox.val(border);
  9646. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9647. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9648. widthBox[0].focus();
  9649. widthBox[0].select();
  9650. },
  9651. insert: function () {
  9652. this.prop(true);
  9653. },
  9654. 'delete': function () {
  9655. var table = self.plugin.getSelectedTable();
  9656. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9657. self.cmd.select();
  9658. table.remove();
  9659. self.addBookmark();
  9660. },
  9661. colinsert: function (offset) {
  9662. var table = self.plugin.getSelectedTable()[0],
  9663. row = self.plugin.getSelectedRow()[0],
  9664. cell = self.plugin.getSelectedCell()[0],
  9665. index = cell.cellIndex + offset;
  9666. // 取得第一行的index
  9667. index += table.rows[0].cells.length - row.cells.length;
  9668. for (var i = 0, len = table.rows.length; i < len; i++) {
  9669. var newRow = table.rows[i],
  9670. newCell = newRow.insertCell(index);
  9671. newCell.innerHTML = K.IE ? '' : '<br />';
  9672. // 调整下一行的单元格index
  9673. index = _getCellIndex(table, newRow, newCell);
  9674. }
  9675. self.cmd.range.selectNodeContents(cell).collapse(true);
  9676. self.cmd.select();
  9677. self.addBookmark();
  9678. },
  9679. colinsertleft: function () {
  9680. this.colinsert(0);
  9681. },
  9682. colinsertright: function () {
  9683. this.colinsert(1);
  9684. },
  9685. rowinsert: function (offset) {
  9686. var table = self.plugin.getSelectedTable()[0],
  9687. row = self.plugin.getSelectedRow()[0],
  9688. cell = self.plugin.getSelectedCell()[0];
  9689. var rowIndex = row.rowIndex;
  9690. if (offset === 1) {
  9691. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9692. }
  9693. var newRow = table.insertRow(rowIndex);
  9694. for (var i = 0, len = row.cells.length; i < len; i++) {
  9695. // 调整cell个数
  9696. if (row.cells[i].rowSpan > 1) {
  9697. len -= row.cells[i].rowSpan - 1;
  9698. }
  9699. var newCell = newRow.insertCell(i);
  9700. // copy colspan
  9701. if (offset === 1 && row.cells[i].colSpan > 1) {
  9702. newCell.colSpan = row.cells[i].colSpan;
  9703. }
  9704. newCell.innerHTML = K.IE ? '' : '<br />';
  9705. }
  9706. // 调整rowspan
  9707. for (var j = rowIndex; j >= 0; j--) {
  9708. var cells = table.rows[j].cells;
  9709. if (cells.length > i) {
  9710. for (var k = cell.cellIndex; k >= 0; k--) {
  9711. if (cells[k].rowSpan > 1) {
  9712. cells[k].rowSpan += 1;
  9713. }
  9714. }
  9715. break;
  9716. }
  9717. }
  9718. self.cmd.range.selectNodeContents(cell).collapse(true);
  9719. self.cmd.select();
  9720. self.addBookmark();
  9721. },
  9722. rowinsertabove: function () {
  9723. this.rowinsert(0);
  9724. },
  9725. rowinsertbelow: function () {
  9726. this.rowinsert(1);
  9727. },
  9728. rowmerge: function () {
  9729. var table = self.plugin.getSelectedTable()[0],
  9730. row = self.plugin.getSelectedRow()[0],
  9731. cell = self.plugin.getSelectedCell()[0],
  9732. rowIndex = row.rowIndex, // 当前行的index
  9733. nextRowIndex = rowIndex + cell.rowSpan, // 下一行的index
  9734. nextRow = table.rows[nextRowIndex]; // 下一行
  9735. // 最后一行不能合并
  9736. if (table.rows.length <= nextRowIndex) {
  9737. return;
  9738. }
  9739. var cellIndex = cell.cellIndex; // 下一行单元格的index
  9740. if (nextRow.cells.length <= cellIndex) {
  9741. return;
  9742. }
  9743. var nextCell = nextRow.cells[cellIndex]; // 下一行单元格
  9744. // 上下行的colspan不一致时不能合并
  9745. if (cell.colSpan !== nextCell.colSpan) {
  9746. return;
  9747. }
  9748. cell.rowSpan += nextCell.rowSpan;
  9749. nextRow.deleteCell(cellIndex);
  9750. self.cmd.range.selectNodeContents(cell).collapse(true);
  9751. self.cmd.select();
  9752. self.addBookmark();
  9753. },
  9754. colmerge: function () {
  9755. var table = self.plugin.getSelectedTable()[0],
  9756. row = self.plugin.getSelectedRow()[0],
  9757. cell = self.plugin.getSelectedCell()[0],
  9758. rowIndex = row.rowIndex, // 当前行的index
  9759. cellIndex = cell.cellIndex,
  9760. nextCellIndex = cellIndex + 1;
  9761. // 最后一列不能合并
  9762. if (row.cells.length <= nextCellIndex) {
  9763. return;
  9764. }
  9765. var nextCell = row.cells[nextCellIndex];
  9766. // 左右列的rowspan不一致时不能合并
  9767. if (cell.rowSpan !== nextCell.rowSpan) {
  9768. return;
  9769. }
  9770. cell.colSpan += nextCell.colSpan;
  9771. row.deleteCell(nextCellIndex);
  9772. self.cmd.range.selectNodeContents(cell).collapse(true);
  9773. self.cmd.select();
  9774. self.addBookmark();
  9775. },
  9776. rowsplit: function () {
  9777. var table = self.plugin.getSelectedTable()[0],
  9778. row = self.plugin.getSelectedRow()[0],
  9779. cell = self.plugin.getSelectedCell()[0],
  9780. rowIndex = row.rowIndex;
  9781. // 不是可分割单元格
  9782. if (cell.rowSpan === 1) {
  9783. return;
  9784. }
  9785. var cellIndex = _getCellIndex(table, row, cell);
  9786. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9787. var newRow = table.rows[rowIndex + i],
  9788. newCell = newRow.insertCell(cellIndex);
  9789. if (cell.colSpan > 1) {
  9790. newCell.colSpan = cell.colSpan;
  9791. }
  9792. newCell.innerHTML = K.IE ? '' : '<br />';
  9793. // 调整下一行的单元格index
  9794. cellIndex = _getCellIndex(table, newRow, newCell);
  9795. }
  9796. K(cell).removeAttr('rowSpan');
  9797. self.cmd.range.selectNodeContents(cell).collapse(true);
  9798. self.cmd.select();
  9799. self.addBookmark();
  9800. },
  9801. colsplit: function () {
  9802. var table = self.plugin.getSelectedTable()[0],
  9803. row = self.plugin.getSelectedRow()[0],
  9804. cell = self.plugin.getSelectedCell()[0],
  9805. cellIndex = cell.cellIndex;
  9806. // 不是可分割单元格
  9807. if (cell.colSpan === 1) {
  9808. return;
  9809. }
  9810. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9811. var newCell = row.insertCell(cellIndex + i);
  9812. if (cell.rowSpan > 1) {
  9813. newCell.rowSpan = cell.rowSpan;
  9814. }
  9815. newCell.innerHTML = K.IE ? '' : '<br />';
  9816. }
  9817. K(cell).removeAttr('colSpan');
  9818. self.cmd.range.selectNodeContents(cell).collapse(true);
  9819. self.cmd.select();
  9820. self.addBookmark();
  9821. },
  9822. coldelete: function () {
  9823. var table = self.plugin.getSelectedTable()[0],
  9824. row = self.plugin.getSelectedRow()[0],
  9825. cell = self.plugin.getSelectedCell()[0],
  9826. index = cell.cellIndex;
  9827. for (var i = 0, len = table.rows.length; i < len; i++) {
  9828. var newRow = table.rows[i],
  9829. newCell = newRow.cells[index];
  9830. if (newCell.colSpan > 1) {
  9831. newCell.colSpan -= 1;
  9832. if (newCell.colSpan === 1) {
  9833. K(newCell).removeAttr('colSpan');
  9834. }
  9835. } else {
  9836. newRow.deleteCell(index);
  9837. }
  9838. // 跳过不需要删除的行
  9839. if (newCell.rowSpan > 1) {
  9840. i += newCell.rowSpan - 1;
  9841. }
  9842. }
  9843. if (row.cells.length === 0) {
  9844. self.cmd.range.setStartBefore(table).collapse(true);
  9845. self.cmd.select();
  9846. K(table).remove();
  9847. } else {
  9848. self.cmd.selection(true);
  9849. }
  9850. self.addBookmark();
  9851. },
  9852. rowdelete: function () {
  9853. var table = self.plugin.getSelectedTable()[0],
  9854. row = self.plugin.getSelectedRow()[0],
  9855. cell = self.plugin.getSelectedCell()[0],
  9856. rowIndex = row.rowIndex;
  9857. // 从下到上删除
  9858. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9859. table.deleteRow(rowIndex + i);
  9860. }
  9861. if (table.rows.length === 0) {
  9862. self.cmd.range.setStartBefore(table).collapse(true);
  9863. self.cmd.select();
  9864. K(table).remove();
  9865. } else {
  9866. self.cmd.selection(true);
  9867. }
  9868. self.addBookmark();
  9869. }
  9870. };
  9871. self.clickToolbar(name, self.plugin.table.prop);
  9872. });
  9873. /*******************************************************************************
  9874. * KindEditor - WYSIWYG HTML Editor for Internet
  9875. * Copyright (C) 2006-2011 kindsoft.net
  9876. *
  9877. * @author Roddy <luolonghao@gmail.com>
  9878. * @site http://www.kindsoft.net/
  9879. * @licence http://www.kindsoft.net/license.php
  9880. *******************************************************************************/
  9881. KindEditor.plugin('template', function (K) {
  9882. var self = this, name = 'template', lang = self.lang(name + '.'),
  9883. htmlPath = self.pluginsPath + name + '/html/';
  9884. function getFilePath(fileName) {
  9885. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9886. }
  9887. self.clickToolbar(name, function () {
  9888. var lang = self.lang(name + '.'),
  9889. arr = ['<div style="padding:10px 20px;">',
  9890. '<div class="ke-header">',
  9891. // left start
  9892. '<div class="ke-left">',
  9893. lang.selectTemplate + ' <select>'];
  9894. K.each(lang.fileList, function (key, val) {
  9895. arr.push('<option value="' + key + '">' + val + '</option>');
  9896. });
  9897. html = [arr.join(''),
  9898. '</select></div>',
  9899. // right start
  9900. '<div class="ke-right">',
  9901. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9902. '</div>',
  9903. '<div class="ke-clearfix"></div>',
  9904. '</div>',
  9905. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9906. '</div>'].join('');
  9907. var dialog = self.createDialog({
  9908. name: name,
  9909. width: 500,
  9910. title: self.lang(name),
  9911. body: html,
  9912. yesBtn: {
  9913. name: self.lang('yes'),
  9914. click: function (e) {
  9915. var doc = K.iframeDoc(iframe);
  9916. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9917. }
  9918. }
  9919. });
  9920. var selectBox = K('select', dialog.div),
  9921. checkbox = K('[name="replaceFlag"]', dialog.div),
  9922. iframe = K('iframe', dialog.div);
  9923. checkbox[0].checked = true;
  9924. iframe.attr('src', getFilePath(selectBox.val()));
  9925. selectBox.change(function () {
  9926. iframe.attr('src', getFilePath(this.value));
  9927. });
  9928. });
  9929. });
  9930. /*******************************************************************************
  9931. * KindEditor - WYSIWYG HTML Editor for Internet
  9932. * Copyright (C) 2006-2011 kindsoft.net
  9933. *
  9934. * @author Roddy <luolonghao@gmail.com>
  9935. * @site http://www.kindsoft.net/
  9936. * @licence http://www.kindsoft.net/license.php
  9937. *******************************************************************************/
  9938. KindEditor.plugin('wordpaste', function (K) {
  9939. var self = this, name = 'wordpaste';
  9940. self.clickToolbar(name, function () {
  9941. var lang = self.lang(name + '.'),
  9942. html = '<div style="padding:10px 20px;">' +
  9943. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9944. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9945. '</div>',
  9946. dialog = self.createDialog({
  9947. name: name,
  9948. width: 450,
  9949. title: self.lang(name),
  9950. body: html,
  9951. yesBtn: {
  9952. name: self.lang('yes'),
  9953. click: function (e) {
  9954. var str = doc.body.innerHTML;
  9955. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9956. self.insertHtml(str).hideDialog().focus();
  9957. }
  9958. }
  9959. }),
  9960. div = dialog.div,
  9961. iframe = K('iframe', div),
  9962. doc = K.iframeDoc(iframe);
  9963. if (!K.IE) {
  9964. doc.designMode = 'on';
  9965. }
  9966. doc.open();
  9967. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9968. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9969. if (!K.IE) {
  9970. doc.write('<br />');
  9971. }
  9972. doc.write('</body></html>');
  9973. doc.close();
  9974. if (K.IE) {
  9975. doc.body.contentEditable = 'true';
  9976. }
  9977. iframe[0].contentWindow.focus();
  9978. });
  9979. });