kindeditor-all-min.js 299 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2017 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.12 (2017-04-12)
  9. *******************************************************************************/
  10. (function (window, undefined) {
  11. if (window.KindEditor) {
  12. return;
  13. }
  14. if (!window.console) {
  15. window.console = {};
  16. }
  17. if (!console.log) {
  18. console.log = function () {};
  19. }
  20. var _VERSION = '4.1.12 (2017-04-12)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  24. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  25. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  26. _OPERA = _ua.indexOf('opera') > -1,
  27. _MOBILE = _ua.indexOf('mobile') > -1,
  28. _IOS = /ipad|iphone|ipod/.test(_ua),
  29. _QUIRKS = document.compatMode != 'CSS1Compat',
  30. _IERANGE = !window.getSelection,
  31. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  32. _V = _matches ? _matches[1] : '0',
  33. _TIME = new Date().getTime();
  34. function _isArray(val) {
  35. if (!val) {
  36. return false;
  37. }
  38. return Object.prototype.toString.call(val) === '[object Array]';
  39. }
  40. function _isFunction(val) {
  41. if (!val) {
  42. return false;
  43. }
  44. return Object.prototype.toString.call(val) === '[object Function]';
  45. }
  46. function _inArray(val, arr) {
  47. for (var i = 0, len = arr.length; i < len; i++) {
  48. if (val === arr[i]) {
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. function _each(obj, fn) {
  55. if (_isArray(obj)) {
  56. for (var i = 0, len = obj.length; i < len; i++) {
  57. if (fn.call(obj[i], i, obj[i]) === false) {
  58. break;
  59. }
  60. }
  61. } else {
  62. for (var key in obj) {
  63. if (obj.hasOwnProperty(key)) {
  64. if (fn.call(obj[key], key, obj[key]) === false) {
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. function _trim(str) {
  72. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  73. }
  74. function _inString(val, str, delimiter) {
  75. delimiter = delimiter === undefined ? ',' : delimiter;
  76. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  77. }
  78. function _addUnit(val, unit) {
  79. unit = unit || 'px';
  80. return val && /^-?\d+(?:\.\d+)?$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function(key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function(key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () {};
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function(key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG : false,
  180. VERSION : _VERSION,
  181. IE : _IE,
  182. GECKO : _GECKO,
  183. WEBKIT : _WEBKIT,
  184. OPERA : _OPERA,
  185. V : _V,
  186. TIME : _TIME,
  187. each : _each,
  188. isArray : _isArray,
  189. isFunction : _isFunction,
  190. inArray : _inArray,
  191. inString : _inString,
  192. trim : _trim,
  193. addUnit : _addUnit,
  194. removeUnit : _removeUnit,
  195. escape : _escape,
  196. unescape : _unescape,
  197. toCamel : _toCamel,
  198. toHex : _toHex,
  199. toMap : _toMap,
  200. toArray : _toArray,
  201. undef : _undef,
  202. invalidUrl : _invalidUrl,
  203. addParam : _addParam,
  204. extend : _extend,
  205. json : _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. index : 0,
  230. designMode : true,
  231. fullscreenMode : false,
  232. filterMode : true,
  233. wellFormatMode : true,
  234. shadowMode : true,
  235. loadStyleMode : true,
  236. basePath : K.basePath,
  237. themesPath : K.basePath + 'themes/',
  238. langPath : K.basePath + 'lang/',
  239. pluginsPath : K.basePath + 'plugins/',
  240. themeType : 'default',
  241. langType : 'zh-CN',
  242. urlType : '',
  243. newlineTag : 'p',
  244. resizeType : 2,
  245. syncType : 'form',
  246. pasteType : 2,
  247. dialogAlignType : 'page',
  248. useContextmenu : true,
  249. fullscreenShortcut : false,
  250. bodyClass : 'ke-content',
  251. indentChar : '\t',
  252. cssPath : '',
  253. cssData : '',
  254. minWidth : 650,
  255. minHeight : 100,
  256. minChangeSize : 50,
  257. zIndex : 19850426,
  258. items : [
  259. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  260. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  261. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  262. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  263. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  264. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  265. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  266. 'anchor', 'link', 'unlink', '|', 'about'
  267. ],
  268. noDisableItems : ['source', 'fullscreen'],
  269. colorTable : [
  270. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  271. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  272. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  273. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  274. ],
  275. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  276. htmlTags : {
  277. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  278. span : [
  279. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  280. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  281. ],
  282. div : [
  283. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  284. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  285. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  286. ],
  287. table: [
  288. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  289. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  290. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  291. '.width', '.height', '.border-collapse'
  292. ],
  293. 'td,th': [
  294. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  295. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  296. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  297. ],
  298. a : ['id', 'class', 'href', 'target', 'name'],
  299. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  300. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  301. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  302. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  303. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  304. ],
  305. pre : ['id', 'class'],
  306. hr : ['id', 'class', '.page-break-after'],
  307. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  308. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  309. },
  310. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  311. };
  312. var _useCapture = false;
  313. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  314. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  315. var _CHANGE_KEY_MAP = {};
  316. _each(_INPUT_KEY_MAP, function(key, val) {
  317. _CHANGE_KEY_MAP[key] = val;
  318. });
  319. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  320. _CHANGE_KEY_MAP[key] = val;
  321. });
  322. function _bindEvent(el, type, fn) {
  323. if (el.addEventListener){
  324. el.addEventListener(type, fn, _useCapture);
  325. } else if (el.attachEvent){
  326. el.attachEvent('on' + type, fn);
  327. }
  328. }
  329. function _unbindEvent(el, type, fn) {
  330. if (el.removeEventListener){
  331. el.removeEventListener(type, fn, _useCapture);
  332. } else if (el.detachEvent){
  333. el.detachEvent('on' + type, fn);
  334. }
  335. }
  336. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  337. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  338. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  339. function KEvent(el, event) {
  340. this.init(el, event);
  341. }
  342. _extend(KEvent, {
  343. init : function(el, event) {
  344. var self = this, doc = el.ownerDocument || el.document || el;
  345. self.event = event;
  346. _each(_EVENT_PROPS, function(key, val) {
  347. self[val] = event[val];
  348. });
  349. if (!self.target) {
  350. self.target = self.srcElement || doc;
  351. }
  352. if (self.target.nodeType === 3) {
  353. self.target = self.target.parentNode;
  354. }
  355. if (!self.relatedTarget && self.fromElement) {
  356. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  357. }
  358. if (self.pageX == null && self.clientX != null) {
  359. var d = doc.documentElement, body = doc.body;
  360. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  361. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  362. }
  363. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  364. self.which = self.charCode || self.keyCode;
  365. }
  366. if (!self.metaKey && self.ctrlKey) {
  367. self.metaKey = self.ctrlKey;
  368. }
  369. if (!self.which && self.button !== undefined) {
  370. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  371. }
  372. switch (self.which) {
  373. case 186 :
  374. self.which = 59;
  375. break;
  376. case 187 :
  377. case 107 :
  378. case 43 :
  379. self.which = 61;
  380. break;
  381. case 189 :
  382. case 45 :
  383. self.which = 109;
  384. break;
  385. case 42 :
  386. self.which = 106;
  387. break;
  388. case 47 :
  389. self.which = 111;
  390. break;
  391. case 78 :
  392. self.which = 110;
  393. break;
  394. }
  395. if (self.which >= 96 && self.which <= 105) {
  396. self.which -= 48;
  397. }
  398. },
  399. preventDefault : function() {
  400. var ev = this.event;
  401. if (ev.preventDefault) {
  402. ev.preventDefault();
  403. } else {
  404. ev.returnValue = false;
  405. }
  406. },
  407. stopPropagation : function() {
  408. var ev = this.event;
  409. if (ev.stopPropagation) {
  410. ev.stopPropagation();
  411. } else {
  412. ev.cancelBubble = true;
  413. }
  414. },
  415. stop : function() {
  416. this.preventDefault();
  417. this.stopPropagation();
  418. }
  419. });
  420. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  421. function _getId(el) {
  422. return el[_eventExpendo] || null;
  423. }
  424. function _setId(el) {
  425. el[_eventExpendo] = ++_eventId;
  426. return _eventId;
  427. }
  428. function _removeId(el) {
  429. try {
  430. delete el[_eventExpendo];
  431. } catch(e) {
  432. if (el.removeAttribute) {
  433. el.removeAttribute(_eventExpendo);
  434. }
  435. }
  436. }
  437. function _bind(el, type, fn) {
  438. if (type.indexOf(',') >= 0) {
  439. _each(type.split(','), function() {
  440. _bind(el, this, fn);
  441. });
  442. return;
  443. }
  444. var id = _getId(el);
  445. if (!id) {
  446. id = _setId(el);
  447. }
  448. if (_eventData[id] === undefined) {
  449. _eventData[id] = {};
  450. }
  451. var events = _eventData[id][type];
  452. if (events && events.length > 0) {
  453. _unbindEvent(el, type, events[0]);
  454. } else {
  455. _eventData[id][type] = [];
  456. _eventData[id].el = el;
  457. }
  458. events = _eventData[id][type];
  459. if (events.length === 0) {
  460. events[0] = function(e) {
  461. var kevent = e ? new KEvent(el, e) : undefined;
  462. _each(events, function(i, event) {
  463. if (i > 0 && event) {
  464. event.call(el, kevent);
  465. }
  466. });
  467. };
  468. }
  469. if (_inArray(fn, events) < 0) {
  470. events.push(fn);
  471. }
  472. _bindEvent(el, type, events[0]);
  473. }
  474. function _unbind(el, type, fn) {
  475. if (type && type.indexOf(',') >= 0) {
  476. _each(type.split(','), function() {
  477. _unbind(el, this, fn);
  478. });
  479. return;
  480. }
  481. var id = _getId(el);
  482. if (!id) {
  483. return;
  484. }
  485. if (type === undefined) {
  486. if (id in _eventData) {
  487. _each(_eventData[id], function(key, events) {
  488. if (key != 'el' && events.length > 0) {
  489. _unbindEvent(el, key, events[0]);
  490. }
  491. });
  492. delete _eventData[id];
  493. _removeId(el);
  494. }
  495. return;
  496. }
  497. if (!_eventData[id]) {
  498. return;
  499. }
  500. var events = _eventData[id][type];
  501. if (events && events.length > 0) {
  502. if (fn === undefined) {
  503. _unbindEvent(el, type, events[0]);
  504. delete _eventData[id][type];
  505. } else {
  506. _each(events, function(i, event) {
  507. if (i > 0 && event === fn) {
  508. events.splice(i, 1);
  509. }
  510. });
  511. if (events.length == 1) {
  512. _unbindEvent(el, type, events[0]);
  513. delete _eventData[id][type];
  514. }
  515. }
  516. var count = 0;
  517. _each(_eventData[id], function() {
  518. count++;
  519. });
  520. if (count < 2) {
  521. delete _eventData[id];
  522. _removeId(el);
  523. }
  524. }
  525. }
  526. function _fire(el, type) {
  527. if (type.indexOf(',') >= 0) {
  528. _each(type.split(','), function() {
  529. _fire(el, this);
  530. });
  531. return;
  532. }
  533. var id = _getId(el);
  534. if (!id) {
  535. return;
  536. }
  537. var events = _eventData[id][type];
  538. if (_eventData[id] && events && events.length > 0) {
  539. events[0]();
  540. }
  541. }
  542. function _ctrl(el, key, fn) {
  543. var self = this;
  544. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  545. _bind(el, 'keydown', function(e) {
  546. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  547. fn.call(el);
  548. e.stop();
  549. }
  550. });
  551. }
  552. var _readyFinished = false;
  553. function _ready(fn) {
  554. if (_readyFinished) {
  555. fn(KindEditor);
  556. return;
  557. }
  558. var loaded = false;
  559. function readyFunc() {
  560. if (!loaded) {
  561. loaded = true;
  562. fn(KindEditor);
  563. _readyFinished = true;
  564. }
  565. }
  566. function ieReadyFunc() {
  567. if (!loaded) {
  568. try {
  569. document.documentElement.doScroll('left');
  570. } catch(e) {
  571. setTimeout(ieReadyFunc, 100);
  572. return;
  573. }
  574. readyFunc();
  575. }
  576. }
  577. function ieReadyStateFunc() {
  578. if (document.readyState === 'complete') {
  579. readyFunc();
  580. }
  581. }
  582. if (document.addEventListener) {
  583. _bind(document, 'DOMContentLoaded', readyFunc);
  584. } else if (document.attachEvent) {
  585. _bind(document, 'readystatechange', ieReadyStateFunc);
  586. var toplevel = false;
  587. try {
  588. toplevel = window.frameElement == null;
  589. } catch(e) {}
  590. if (document.documentElement.doScroll && toplevel) {
  591. ieReadyFunc();
  592. }
  593. }
  594. _bind(window, 'load', readyFunc);
  595. }
  596. if (window.attachEvent) {
  597. window.attachEvent('onunload', function() {
  598. _each(_eventData, function(key, events) {
  599. if (events.el) {
  600. _unbind(events.el);
  601. }
  602. });
  603. });
  604. }
  605. K.ctrl = _ctrl;
  606. K.ready = _ready;
  607. function _getCssList(css) {
  608. css = css.replace(/&quot;/g, '"');
  609. var list = {},
  610. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  611. match;
  612. while ((match = reg.exec(css))) {
  613. var key = _trim(match[1].toLowerCase()),
  614. val = _trim(_toHex(match[2]));
  615. list[key] = val;
  616. }
  617. return list;
  618. }
  619. function _getAttrList(tag) {
  620. var list = {},
  621. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  622. match;
  623. while ((match = reg.exec(tag))) {
  624. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  625. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  626. list[key] = val;
  627. }
  628. return list;
  629. }
  630. function _addClassToTag(tag, className) {
  631. if (/\s+class\s*=/.test(tag)) {
  632. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  633. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  634. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  635. } else {
  636. return $0;
  637. }
  638. });
  639. } else {
  640. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  641. }
  642. return tag;
  643. }
  644. function _formatCss(css) {
  645. var str = '';
  646. _each(_getCssList(css), function(key, val) {
  647. str += key + ':' + val + ';';
  648. });
  649. return str;
  650. }
  651. function _formatUrl(url, mode, host, pathname) {
  652. return url;
  653. mode = _undef(mode, '').toLowerCase();
  654. if (url.substr(0, 5) != 'data:') {
  655. url = url.replace(/([^:])\/\//g, '$1/');
  656. }
  657. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  658. return url;
  659. }
  660. host = host || location.protocol + '//' + location.host;
  661. if (pathname === undefined) {
  662. var m = location.pathname.match(/^(\/.*)\//);
  663. pathname = m ? m[1] : '';
  664. }
  665. var match;
  666. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  667. if (match[1] !== host) {
  668. return url;
  669. }
  670. } else if (/^\w+:/.test(url)) {
  671. return url;
  672. }
  673. function getRealPath(path) {
  674. var parts = path.split('/'), paths = [];
  675. for (var i = 0, len = parts.length; i < len; i++) {
  676. var part = parts[i];
  677. if (part == '..') {
  678. if (paths.length > 0) {
  679. paths.pop();
  680. }
  681. } else if (part !== '' && part != '.') {
  682. paths.push(part);
  683. }
  684. }
  685. return '/' + paths.join('/');
  686. }
  687. if (/^\//.test(url)) {
  688. url = host + getRealPath(url.substr(1));
  689. } else if (!/^\w+:\/\//.test(url)) {
  690. url = host + getRealPath(pathname + '/' + url);
  691. }
  692. function getRelativePath(path, depth) {
  693. if (url.substr(0, path.length) === path) {
  694. var arr = [];
  695. for (var i = 0; i < depth; i++) {
  696. arr.push('..');
  697. }
  698. var prefix = '.';
  699. if (arr.length > 0) {
  700. prefix += '/' + arr.join('/');
  701. }
  702. if (pathname == '/') {
  703. prefix += '/';
  704. }
  705. return prefix + url.substr(path.length);
  706. } else {
  707. if ((match = /^(.*)\//.exec(path))) {
  708. return getRelativePath(match[1], ++depth);
  709. }
  710. }
  711. }
  712. if (mode === 'relative') {
  713. url = getRelativePath(host + pathname, 0).substr(2);
  714. } else if (mode === 'absolute') {
  715. if (url.substr(0, host.length) === host) {
  716. url = url.substr(host.length);
  717. }
  718. }
  719. return url;
  720. }
  721. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  722. if (html == null) {
  723. html = '';
  724. }
  725. urlType = urlType || '';
  726. wellFormatted = _undef(wellFormatted, false);
  727. indentChar = _undef(indentChar, '\t');
  728. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  729. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  730. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  731. });
  732. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  733. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  734. html = html.replace(/\u200B/g, '');
  735. html = html.replace(/\u00A9/g, '&copy;');
  736. html = html.replace(/\u00AE/g, '&reg;');
  737. html = html.replace(/\u2003/g, '&emsp;');
  738. html = html.replace(/\u3000/g, '&emsp;');
  739. html = html.replace(/&quot;/g, '');
  740. html = html.replace(/, " helvetica=""(.*?)"="/g, '');
  741. html = html.replace(/<[^>]+/g, function($0) {
  742. return $0.replace(/\s+/g, ' ');
  743. });
  744. var htmlTagMap = {};
  745. if (htmlTags) {
  746. _each(htmlTags, function(key, val) {
  747. var arr = key.split(',');
  748. for (var i = 0, len = arr.length; i < len; i++) {
  749. htmlTagMap[arr[i]] = _toMap(val);
  750. }
  751. });
  752. if (!htmlTagMap.script) {
  753. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  754. }
  755. if (!htmlTagMap.style) {
  756. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  757. }
  758. }
  759. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  760. var tagStack = [];
  761. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  762. var full = $0,
  763. startNewline = $1 || '',
  764. startSlash = $2 || '',
  765. tagName = $3.toLowerCase(),
  766. attr = $4 || '',
  767. endSlash = $5 ? ' ' + $5 : '',
  768. endNewline = $6 || '';
  769. if (htmlTags && !htmlTagMap[tagName]) {
  770. return '';
  771. }
  772. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  773. endSlash = ' /';
  774. }
  775. if (_INLINE_TAG_MAP[tagName]) {
  776. if (startNewline) {
  777. startNewline = ' ';
  778. }
  779. if (endNewline) {
  780. endNewline = ' ';
  781. }
  782. }
  783. if (_PRE_TAG_MAP[tagName]) {
  784. if (startSlash) {
  785. endNewline = '\n';
  786. } else {
  787. startNewline = '\n';
  788. }
  789. }
  790. if (wellFormatted && tagName == 'br') {
  791. endNewline = '\n';
  792. }
  793. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  794. if (wellFormatted) {
  795. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  796. tagStack.pop();
  797. } else {
  798. tagStack.push(tagName);
  799. }
  800. startNewline = '\n';
  801. endNewline = '\n';
  802. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  803. startNewline += indentChar;
  804. if (!startSlash) {
  805. endNewline += indentChar;
  806. }
  807. }
  808. if (endSlash) {
  809. tagStack.pop();
  810. } else if (!startSlash) {
  811. endNewline += indentChar;
  812. }
  813. } else {
  814. startNewline = endNewline = '';
  815. }
  816. }
  817. if (attr !== '') {
  818. var attrMap = _getAttrList(full);
  819. if (tagName === 'font') {
  820. var fontStyleMap = {}, fontStyle = '';
  821. _each(attrMap, function(key, val) {
  822. if (key === 'color') {
  823. fontStyleMap.color = val;
  824. delete attrMap[key];
  825. }
  826. if (key === 'size') {
  827. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  828. delete attrMap[key];
  829. }
  830. if (key === 'face') {
  831. fontStyleMap['font-family'] = val;
  832. delete attrMap[key];
  833. }
  834. if (key === 'style') {
  835. fontStyle = val;
  836. }
  837. });
  838. if (fontStyle && !/;$/.test(fontStyle)) {
  839. fontStyle += ';';
  840. }
  841. _each(fontStyleMap, function(key, val) {
  842. if (val === '') {
  843. return;
  844. }
  845. if (/\s/.test(val)) {
  846. val = "'" + val + "'";
  847. }
  848. fontStyle += key + ':' + val + ';';
  849. });
  850. attrMap.style = fontStyle;
  851. }
  852. _each(attrMap, function(key, val) {
  853. if (_FILL_ATTR_MAP[key]) {
  854. attrMap[key] = key;
  855. }
  856. if (_inArray(key, ['src', 'href']) >= 0) {
  857. attrMap[key] = _formatUrl(val, urlType);
  858. }
  859. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  860. tagName === 'body' && key === 'contenteditable' ||
  861. /^kindeditor_\d+$/.test(key)) {
  862. delete attrMap[key];
  863. }
  864. if (key === 'style' && val !== '') {
  865. var styleMap = _getCssList(val);
  866. _each(styleMap, function(k, v) {
  867. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  868. delete styleMap[k];
  869. }
  870. });
  871. var style = '';
  872. _each(styleMap, function(k, v) {
  873. style += k + ':' + v + ';';
  874. });
  875. attrMap.style = style;
  876. }
  877. });
  878. attr = '';
  879. _each(attrMap, function(key, val) {
  880. if (key === 'style' && val === '') {
  881. return;
  882. }
  883. val = val.replace(/"/g, '&quot;');
  884. attr += ' ' + key + '="' + val + '"';
  885. });
  886. }
  887. if (tagName === 'font') {
  888. tagName = 'span';
  889. }
  890. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  891. });
  892. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  893. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  894. });
  895. html = html.replace(/\n\s*\n/g, '\n');
  896. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  897. return _trim(html);
  898. }
  899. function _clearMsWord(html, htmlTags) {
  900. html = html.replace(/<meta[\s\S]*?>/ig, '')
  901. .replace(/<![\s\S]*?>/ig, '')
  902. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  903. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  904. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  905. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  906. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  907. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  908. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  909. });
  910. return _formatHtml(html, htmlTags);
  911. }
  912. function _mediaType(src) {
  913. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  914. return 'audio/x-pn-realaudio-plugin';
  915. }
  916. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  917. return 'application/x-shockwave-flash';
  918. }
  919. return 'video/x-ms-asf-plugin';
  920. }
  921. function _mediaClass(type) {
  922. if (/realaudio/i.test(type)) {
  923. return 'ke-rm';
  924. }
  925. if (/flash/i.test(type)) {
  926. return 'ke-flash';
  927. }
  928. return 'ke-media';
  929. }
  930. function _mediaAttrs(srcTag) {
  931. return _getAttrList(unescape(srcTag));
  932. }
  933. function _mediaEmbed(attrs) {
  934. var html = '<embed ';
  935. _each(attrs, function(key, val) {
  936. html += key + '="' + val + '" ';
  937. });
  938. html += '/>';
  939. return html;
  940. }
  941. function _mediaImg(blankPath, attrs) {
  942. var width = attrs.width,
  943. height = attrs.height,
  944. type = attrs.type || _mediaType(attrs.src),
  945. srcTag = _mediaEmbed(attrs),
  946. style = '';
  947. if (/\D/.test(width)) {
  948. style += 'width:' + width + ';';
  949. } else if (width > 0) {
  950. style += 'width:' + width + 'px;';
  951. }
  952. if (/\D/.test(height)) {
  953. style += 'height:' + height + ';';
  954. } else if (height > 0) {
  955. style += 'height:' + height + 'px;';
  956. }
  957. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  958. if (style !== '') {
  959. html += 'style="' + style + '" ';
  960. }
  961. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  962. return html;
  963. }
  964. function _tmpl(str, data) {
  965. var fn = new Function("obj",
  966. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  967. "with(obj){p.push('" +
  968. str.replace(/[\r\t\n]/g, " ")
  969. .split("<%").join("\t")
  970. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  971. .replace(/\t=(.*?)%>/g, "',$1,'")
  972. .split("\t").join("');")
  973. .split("%>").join("p.push('")
  974. .split("\r").join("\\'") + "');}return p.join('');");
  975. return data ? fn(data) : fn;
  976. }
  977. K.formatUrl = _formatUrl;
  978. K.formatHtml = _formatHtml;
  979. K.getCssList = _getCssList;
  980. K.getAttrList = _getAttrList;
  981. K.mediaType = _mediaType;
  982. K.mediaAttrs = _mediaAttrs;
  983. K.mediaEmbed = _mediaEmbed;
  984. K.mediaImg = _mediaImg;
  985. K.clearMsWord = _clearMsWord;
  986. K.tmpl = _tmpl;
  987. function _contains(nodeA, nodeB) {
  988. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  989. return true;
  990. }
  991. while ((nodeB = nodeB.parentNode)) {
  992. if (nodeB == nodeA) {
  993. return true;
  994. }
  995. }
  996. return false;
  997. }
  998. var _getSetAttrDiv = document.createElement('div');
  999. _getSetAttrDiv.setAttribute('className', 't');
  1000. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1001. function _getAttr(el, key) {
  1002. key = key.toLowerCase();
  1003. var val = null;
  1004. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1005. var div = el.ownerDocument.createElement('div');
  1006. div.appendChild(el.cloneNode(false));
  1007. var list = _getAttrList(_unescape(div.innerHTML));
  1008. if (key in list) {
  1009. val = list[key];
  1010. }
  1011. } else {
  1012. try {
  1013. val = el.getAttribute(key, 2);
  1014. } catch(e) {
  1015. val = el.getAttribute(key, 1);
  1016. }
  1017. }
  1018. if (key === 'style' && val !== null) {
  1019. val = _formatCss(val);
  1020. }
  1021. return val;
  1022. }
  1023. function _queryAll(expr, root) {
  1024. var exprList = expr.split(',');
  1025. if (exprList.length > 1) {
  1026. var mergedResults = [];
  1027. _each(exprList, function() {
  1028. _each(_queryAll(this, root), function() {
  1029. if (_inArray(this, mergedResults) < 0) {
  1030. mergedResults.push(this);
  1031. }
  1032. });
  1033. });
  1034. return mergedResults;
  1035. }
  1036. root = root || document;
  1037. function escape(str) {
  1038. if (typeof str != 'string') {
  1039. return str;
  1040. }
  1041. return str.replace(/([^\w\-])/g, '\\$1');
  1042. }
  1043. function stripslashes(str) {
  1044. return str.replace(/\\/g, '');
  1045. }
  1046. function cmpTag(tagA, tagB) {
  1047. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1048. }
  1049. function byId(id, tag, root) {
  1050. var arr = [],
  1051. doc = root.ownerDocument || root,
  1052. el = doc.getElementById(stripslashes(id));
  1053. if (el) {
  1054. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1055. arr.push(el);
  1056. }
  1057. }
  1058. return arr;
  1059. }
  1060. function byClass(className, tag, root) {
  1061. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1062. if (root.getElementsByClassName) {
  1063. els = root.getElementsByClassName(stripslashes(className));
  1064. for (i = 0, len = els.length; i < len; i++) {
  1065. el = els[i];
  1066. if (cmpTag(tag, el.nodeName)) {
  1067. arr.push(el);
  1068. }
  1069. }
  1070. } else if (doc.querySelectorAll) {
  1071. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1072. for (i = 0, len = els.length; i < len; i++) {
  1073. el = els[i];
  1074. if (_contains(root, el)) {
  1075. arr.push(el);
  1076. }
  1077. }
  1078. } else {
  1079. els = root.getElementsByTagName(tag);
  1080. className = ' ' + className + ' ';
  1081. for (i = 0, len = els.length; i < len; i++) {
  1082. el = els[i];
  1083. if (el.nodeType == 1) {
  1084. var cls = el.className;
  1085. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1086. arr.push(el);
  1087. }
  1088. }
  1089. }
  1090. }
  1091. return arr;
  1092. }
  1093. function byName(name, tag, root) {
  1094. var arr = [], doc = root.ownerDocument || root,
  1095. els = doc.getElementsByName(stripslashes(name)), el;
  1096. for (var i = 0, len = els.length; i < len; i++) {
  1097. el = els[i];
  1098. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1099. if (el.getAttribute('name') !== null) {
  1100. arr.push(el);
  1101. }
  1102. }
  1103. }
  1104. return arr;
  1105. }
  1106. function byAttr(key, val, tag, root) {
  1107. var arr = [], els = root.getElementsByTagName(tag), el;
  1108. for (var i = 0, len = els.length; i < len; i++) {
  1109. el = els[i];
  1110. if (el.nodeType == 1) {
  1111. if (val === null) {
  1112. if (_getAttr(el, key) !== null) {
  1113. arr.push(el);
  1114. }
  1115. } else {
  1116. if (val === escape(_getAttr(el, key))) {
  1117. arr.push(el);
  1118. }
  1119. }
  1120. }
  1121. }
  1122. return arr;
  1123. }
  1124. function select(expr, root) {
  1125. var arr = [], matches;
  1126. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1127. var tag = matches ? matches[1] : '*';
  1128. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1129. arr = byId(matches[1], tag, root);
  1130. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1131. arr = byClass(matches[1], tag, root);
  1132. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1133. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1134. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1135. var key = matches[1].toLowerCase(), val = matches[2];
  1136. if (key === 'id') {
  1137. arr = byId(val, tag, root);
  1138. } else if (key === 'class') {
  1139. arr = byClass(val, tag, root);
  1140. } else if (key === 'name') {
  1141. arr = byName(val, tag, root);
  1142. } else {
  1143. arr = byAttr(key, val, tag, root);
  1144. }
  1145. } else {
  1146. var els = root.getElementsByTagName(tag), el;
  1147. for (var i = 0, len = els.length; i < len; i++) {
  1148. el = els[i];
  1149. if (el.nodeType == 1) {
  1150. arr.push(el);
  1151. }
  1152. }
  1153. }
  1154. return arr;
  1155. }
  1156. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1157. while ((arr = re.exec(expr))) {
  1158. if (arr[1] !== ' ') {
  1159. parts.push(arr[1]);
  1160. }
  1161. }
  1162. var results = [];
  1163. if (parts.length == 1) {
  1164. return select(parts[0], root);
  1165. }
  1166. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1167. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1168. part = parts[i];
  1169. if (part === '>') {
  1170. isChild = true;
  1171. continue;
  1172. }
  1173. if (i > 0) {
  1174. els = [];
  1175. for (j = 0, len = results.length; j < len; j++) {
  1176. val = results[j];
  1177. subResults = select(part, val);
  1178. for (k = 0, l = subResults.length; k < l; k++) {
  1179. v = subResults[k];
  1180. if (isChild) {
  1181. if (val === v.parentNode) {
  1182. els.push(v);
  1183. }
  1184. } else {
  1185. els.push(v);
  1186. }
  1187. }
  1188. }
  1189. results = els;
  1190. } else {
  1191. results = select(part, root);
  1192. }
  1193. if (results.length === 0) {
  1194. return [];
  1195. }
  1196. }
  1197. return results;
  1198. }
  1199. function _query(expr, root) {
  1200. var arr = _queryAll(expr, root);
  1201. return arr.length > 0 ? arr[0] : null;
  1202. }
  1203. K.query = _query;
  1204. K.queryAll = _queryAll;
  1205. function _get(val) {
  1206. return K(val)[0];
  1207. }
  1208. function _getDoc(node) {
  1209. if (!node) {
  1210. return document;
  1211. }
  1212. return node.ownerDocument || node.document || node;
  1213. }
  1214. function _getWin(node) {
  1215. if (!node) {
  1216. return window;
  1217. }
  1218. var doc = _getDoc(node);
  1219. return doc.parentWindow || doc.defaultView;
  1220. }
  1221. function _setHtml(el, html) {
  1222. if (el.nodeType != 1) {
  1223. return;
  1224. }
  1225. var doc = _getDoc(el);
  1226. try {
  1227. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1228. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1229. temp.parentNode.removeChild(temp);
  1230. } catch(e) {
  1231. K(el).empty();
  1232. K('@' + html, doc).each(function() {
  1233. el.appendChild(this);
  1234. });
  1235. }
  1236. }
  1237. function _hasClass(el, cls) {
  1238. return _inString(cls, el.className, ' ');
  1239. }
  1240. function _setAttr(el, key, val) {
  1241. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1242. key = 'className';
  1243. }
  1244. el.setAttribute(key, '' + val);
  1245. }
  1246. function _removeAttr(el, key) {
  1247. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1248. key = 'className';
  1249. }
  1250. _setAttr(el, key, '');
  1251. el.removeAttribute(key);
  1252. }
  1253. function _getNodeName(node) {
  1254. if (!node || !node.nodeName) {
  1255. return '';
  1256. }
  1257. return node.nodeName.toLowerCase();
  1258. }
  1259. function _computedCss(el, key) {
  1260. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1261. if (win.getComputedStyle) {
  1262. var style = win.getComputedStyle(el, null);
  1263. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1264. } else if (el.currentStyle) {
  1265. val = el.currentStyle[camelKey] || el.style[camelKey];
  1266. }
  1267. return val;
  1268. }
  1269. function _hasVal(node) {
  1270. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1271. }
  1272. function _docElement(doc) {
  1273. doc = doc || document;
  1274. return _QUIRKS ? doc.body : doc.documentElement;
  1275. }
  1276. function _docHeight(doc) {
  1277. var el = _docElement(doc);
  1278. return Math.max(el.scrollHeight, el.clientHeight);
  1279. }
  1280. function _docWidth(doc) {
  1281. var el = _docElement(doc);
  1282. return Math.max(el.scrollWidth, el.clientWidth);
  1283. }
  1284. function _getScrollPos(doc) {
  1285. doc = doc || document;
  1286. var x, y;
  1287. if (_IE || _NEWIE || _OPERA) {
  1288. x = _docElement(doc).scrollLeft;
  1289. y = _docElement(doc).scrollTop;
  1290. } else {
  1291. x = _getWin(doc).scrollX;
  1292. y = _getWin(doc).scrollY;
  1293. }
  1294. return {x : x, y : y};
  1295. }
  1296. function KNode(node) {
  1297. this.init(node);
  1298. }
  1299. _extend(KNode, {
  1300. init : function(node) {
  1301. var self = this;
  1302. node = _isArray(node) ? node : [node];
  1303. var length = 0;
  1304. for (var i = 0, len = node.length; i < len; i++) {
  1305. if (node[i]) {
  1306. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1307. length++;
  1308. }
  1309. }
  1310. self.length = length;
  1311. self.doc = _getDoc(self[0]);
  1312. self.name = _getNodeName(self[0]);
  1313. self.type = self.length > 0 ? self[0].nodeType : null;
  1314. self.win = _getWin(self[0]);
  1315. },
  1316. each : function(fn) {
  1317. var self = this;
  1318. for (var i = 0; i < self.length; i++) {
  1319. if (fn.call(self[i], i, self[i]) === false) {
  1320. return self;
  1321. }
  1322. }
  1323. return self;
  1324. },
  1325. bind : function(type, fn) {
  1326. this.each(function() {
  1327. _bind(this, type, fn);
  1328. });
  1329. return this;
  1330. },
  1331. unbind : function(type, fn) {
  1332. this.each(function() {
  1333. _unbind(this, type, fn);
  1334. });
  1335. return this;
  1336. },
  1337. fire : function(type) {
  1338. if (this.length < 1) {
  1339. return this;
  1340. }
  1341. _fire(this[0], type);
  1342. return this;
  1343. },
  1344. hasAttr : function(key) {
  1345. if (this.length < 1) {
  1346. return false;
  1347. }
  1348. return !!_getAttr(this[0], key);
  1349. },
  1350. attr : function(key, val) {
  1351. var self = this;
  1352. if (key === undefined) {
  1353. return _getAttrList(self.outer());
  1354. }
  1355. if (typeof key === 'object') {
  1356. _each(key, function(k, v) {
  1357. self.attr(k, v);
  1358. });
  1359. return self;
  1360. }
  1361. if (val === undefined) {
  1362. val = self.length < 1 ? null : _getAttr(self[0], key);
  1363. return val === null ? '' : val;
  1364. }
  1365. self.each(function() {
  1366. _setAttr(this, key, val);
  1367. });
  1368. return self;
  1369. },
  1370. removeAttr : function(key) {
  1371. this.each(function() {
  1372. _removeAttr(this, key);
  1373. });
  1374. return this;
  1375. },
  1376. get : function(i) {
  1377. if (this.length < 1) {
  1378. return null;
  1379. }
  1380. return this[i || 0];
  1381. },
  1382. eq : function(i) {
  1383. if (this.length < 1) {
  1384. return null;
  1385. }
  1386. return this[i] ? new KNode(this[i]) : null;
  1387. },
  1388. hasClass : function(cls) {
  1389. if (this.length < 1) {
  1390. return false;
  1391. }
  1392. return _hasClass(this[0], cls);
  1393. },
  1394. addClass : function(cls) {
  1395. this.each(function() {
  1396. if (!_hasClass(this, cls)) {
  1397. this.className = _trim(this.className + ' ' + cls);
  1398. }
  1399. });
  1400. return this;
  1401. },
  1402. removeClass : function(cls) {
  1403. this.each(function() {
  1404. if (_hasClass(this, cls)) {
  1405. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1406. }
  1407. });
  1408. return this;
  1409. },
  1410. html : function(val) {
  1411. var self = this;
  1412. if (val === undefined) {
  1413. if (self.length < 1 || self.type != 1) {
  1414. return '';
  1415. }
  1416. return _formatHtml(self[0].innerHTML);
  1417. }
  1418. self.each(function() {
  1419. _setHtml(this, val);
  1420. });
  1421. return self;
  1422. },
  1423. text : function() {
  1424. var self = this;
  1425. if (self.length < 1) {
  1426. return '';
  1427. }
  1428. return _IE ? self[0].innerText : self[0].textContent;
  1429. },
  1430. hasVal : function() {
  1431. if (this.length < 1) {
  1432. return false;
  1433. }
  1434. return _hasVal(this[0]);
  1435. },
  1436. val : function(val) {
  1437. var self = this;
  1438. if (val === undefined) {
  1439. if (self.length < 1) {
  1440. return '';
  1441. }
  1442. return self.hasVal() ? self[0].value : self.attr('value');
  1443. } else {
  1444. self.each(function() {
  1445. if (_hasVal(this)) {
  1446. this.value = val;
  1447. } else {
  1448. _setAttr(this, 'value' , val);
  1449. }
  1450. });
  1451. return self;
  1452. }
  1453. },
  1454. css : function(key, val) {
  1455. var self = this;
  1456. if (key === undefined) {
  1457. return _getCssList(self.attr('style'));
  1458. }
  1459. if (typeof key === 'object') {
  1460. _each(key, function(k, v) {
  1461. self.css(k, v);
  1462. });
  1463. return self;
  1464. }
  1465. if (val === undefined) {
  1466. if (self.length < 1) {
  1467. return '';
  1468. }
  1469. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1470. }
  1471. self.each(function() {
  1472. this.style[_toCamel(key)] = val;
  1473. });
  1474. return self;
  1475. },
  1476. width : function(val) {
  1477. var self = this;
  1478. if (val === undefined) {
  1479. if (self.length < 1) {
  1480. return 0;
  1481. }
  1482. return self[0].offsetWidth;
  1483. }
  1484. return self.css('width', _addUnit(val));
  1485. },
  1486. height : function(val) {
  1487. var self = this;
  1488. if (val === undefined) {
  1489. if (self.length < 1) {
  1490. return 0;
  1491. }
  1492. return self[0].offsetHeight;
  1493. }
  1494. return self.css('height', _addUnit(val));
  1495. },
  1496. opacity : function(val) {
  1497. this.each(function() {
  1498. if (this.style.opacity === undefined) {
  1499. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1500. } else {
  1501. this.style.opacity = val == 1 ? '' : val;
  1502. }
  1503. });
  1504. return this;
  1505. },
  1506. data : function(key, val) {
  1507. var self = this;
  1508. key = 'kindeditor_data_' + key;
  1509. if (val === undefined) {
  1510. if (self.length < 1) {
  1511. return null;
  1512. }
  1513. return self[0][key];
  1514. }
  1515. this.each(function() {
  1516. this[key] = val;
  1517. });
  1518. return self;
  1519. },
  1520. pos : function() {
  1521. var self = this, node = self[0], x = 0, y = 0;
  1522. if (node) {
  1523. if (node.getBoundingClientRect) {
  1524. var box = node.getBoundingClientRect(),
  1525. pos = _getScrollPos(self.doc);
  1526. x = box.left + pos.x;
  1527. y = box.top + pos.y;
  1528. } else {
  1529. while (node) {
  1530. x += node.offsetLeft;
  1531. y += node.offsetTop;
  1532. node = node.offsetParent;
  1533. }
  1534. }
  1535. }
  1536. return {x : _round(x), y : _round(y)};
  1537. },
  1538. clone : function(bool) {
  1539. if (this.length < 1) {
  1540. return new KNode([]);
  1541. }
  1542. return new KNode(this[0].cloneNode(bool));
  1543. },
  1544. append : function(expr) {
  1545. this.each(function() {
  1546. if (this.appendChild) {
  1547. this.appendChild(_get(expr));
  1548. }
  1549. });
  1550. return this;
  1551. },
  1552. appendTo : function(expr) {
  1553. this.each(function() {
  1554. _get(expr).appendChild(this);
  1555. });
  1556. return this;
  1557. },
  1558. before : function(expr) {
  1559. this.each(function() {
  1560. this.parentNode.insertBefore(_get(expr), this);
  1561. });
  1562. return this;
  1563. },
  1564. after : function(expr) {
  1565. this.each(function() {
  1566. if (this.nextSibling) {
  1567. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1568. } else {
  1569. this.parentNode.appendChild(_get(expr));
  1570. }
  1571. });
  1572. return this;
  1573. },
  1574. replaceWith : function(expr) {
  1575. var nodes = [];
  1576. this.each(function(i, node) {
  1577. _unbind(node);
  1578. var newNode = _get(expr);
  1579. node.parentNode.replaceChild(newNode, node);
  1580. nodes.push(newNode);
  1581. });
  1582. return K(nodes);
  1583. },
  1584. empty : function() {
  1585. var self = this;
  1586. self.each(function(i, node) {
  1587. var child = node.firstChild;
  1588. while (child) {
  1589. if (!node.parentNode) {
  1590. return;
  1591. }
  1592. var next = child.nextSibling;
  1593. child.parentNode.removeChild(child);
  1594. child = next;
  1595. }
  1596. });
  1597. return self;
  1598. },
  1599. remove : function(keepChilds) {
  1600. var self = this;
  1601. self.each(function(i, node) {
  1602. if (!node.parentNode) {
  1603. return;
  1604. }
  1605. _unbind(node);
  1606. if (keepChilds) {
  1607. var child = node.firstChild;
  1608. while (child) {
  1609. var next = child.nextSibling;
  1610. node.parentNode.insertBefore(child, node);
  1611. child = next;
  1612. }
  1613. }
  1614. node.parentNode.removeChild(node);
  1615. delete self[i];
  1616. });
  1617. self.length = 0;
  1618. return self;
  1619. },
  1620. show : function(val) {
  1621. var self = this;
  1622. if (val === undefined) {
  1623. val = self._originDisplay || '';
  1624. }
  1625. if (self.css('display') != 'none') {
  1626. return self;
  1627. }
  1628. return self.css('display', val);
  1629. },
  1630. hide : function() {
  1631. var self = this;
  1632. if (self.length < 1) {
  1633. return self;
  1634. }
  1635. self._originDisplay = self[0].style.display;
  1636. return self.css('display', 'none');
  1637. },
  1638. outer : function() {
  1639. var self = this;
  1640. if (self.length < 1) {
  1641. return '';
  1642. }
  1643. var div = self.doc.createElement('div'), html;
  1644. div.appendChild(self[0].cloneNode(true));
  1645. html = _formatHtml(div.innerHTML);
  1646. div = null;
  1647. return html;
  1648. },
  1649. isSingle : function() {
  1650. return !!_SINGLE_TAG_MAP[this.name];
  1651. },
  1652. isInline : function() {
  1653. return !!_INLINE_TAG_MAP[this.name];
  1654. },
  1655. isBlock : function() {
  1656. return !!_BLOCK_TAG_MAP[this.name];
  1657. },
  1658. isStyle : function() {
  1659. return !!_STYLE_TAG_MAP[this.name];
  1660. },
  1661. isControl : function() {
  1662. return !!_CONTROL_TAG_MAP[this.name];
  1663. },
  1664. contains : function(otherNode) {
  1665. if (this.length < 1) {
  1666. return false;
  1667. }
  1668. return _contains(this[0], _get(otherNode));
  1669. },
  1670. parent : function() {
  1671. if (this.length < 1) {
  1672. return null;
  1673. }
  1674. var node = this[0].parentNode;
  1675. return node ? new KNode(node) : null;
  1676. },
  1677. children : function() {
  1678. if (this.length < 1) {
  1679. return new KNode([]);
  1680. }
  1681. var list = [], child = this[0].firstChild;
  1682. while (child) {
  1683. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1684. list.push(child);
  1685. }
  1686. child = child.nextSibling;
  1687. }
  1688. return new KNode(list);
  1689. },
  1690. first : function() {
  1691. var list = this.children();
  1692. return list.length > 0 ? list.eq(0) : null;
  1693. },
  1694. last : function() {
  1695. var list = this.children();
  1696. return list.length > 0 ? list.eq(list.length - 1) : null;
  1697. },
  1698. index : function() {
  1699. if (this.length < 1) {
  1700. return -1;
  1701. }
  1702. var i = -1, sibling = this[0];
  1703. while (sibling) {
  1704. i++;
  1705. sibling = sibling.previousSibling;
  1706. }
  1707. return i;
  1708. },
  1709. prev : function() {
  1710. if (this.length < 1) {
  1711. return null;
  1712. }
  1713. var node = this[0].previousSibling;
  1714. return node ? new KNode(node) : null;
  1715. },
  1716. next : function() {
  1717. if (this.length < 1) {
  1718. return null;
  1719. }
  1720. var node = this[0].nextSibling;
  1721. return node ? new KNode(node) : null;
  1722. },
  1723. scan : function(fn, order) {
  1724. if (this.length < 1) {
  1725. return;
  1726. }
  1727. order = (order === undefined) ? true : order;
  1728. function walk(node) {
  1729. var n = order ? node.firstChild : node.lastChild;
  1730. while (n) {
  1731. var next = order ? n.nextSibling : n.previousSibling;
  1732. if (fn(n) === false) {
  1733. return false;
  1734. }
  1735. if (walk(n) === false) {
  1736. return false;
  1737. }
  1738. n = next;
  1739. }
  1740. }
  1741. walk(this[0]);
  1742. return this;
  1743. }
  1744. });
  1745. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1746. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1747. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1748. KNode.prototype[type] = function(fn) {
  1749. return fn ? this.bind(type, fn) : this.fire(type);
  1750. };
  1751. });
  1752. var _K = K;
  1753. K = function(expr, root) {
  1754. if (expr === undefined || expr === null) {
  1755. return;
  1756. }
  1757. function newNode(node) {
  1758. if (!node[0]) {
  1759. node = [];
  1760. }
  1761. return new KNode(node);
  1762. }
  1763. if (typeof expr === 'string') {
  1764. if (root) {
  1765. root = _get(root);
  1766. }
  1767. var length = expr.length;
  1768. if (expr.charAt(0) === '@') {
  1769. expr = expr.substr(1);
  1770. }
  1771. if (expr.length !== length || /<.+>/.test(expr)) {
  1772. var doc = root ? root.ownerDocument || root : document,
  1773. div = doc.createElement('div'), list = [];
  1774. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1775. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1776. var child = div.childNodes[i];
  1777. if (child.id == '__kindeditor_temp_tag__') {
  1778. continue;
  1779. }
  1780. list.push(child);
  1781. }
  1782. return newNode(list);
  1783. }
  1784. return newNode(_queryAll(expr, root));
  1785. }
  1786. if (expr && expr.constructor === KNode) {
  1787. return expr;
  1788. }
  1789. if (expr.toArray) {
  1790. expr = expr.toArray();
  1791. }
  1792. if (_isArray(expr)) {
  1793. return newNode(expr);
  1794. }
  1795. return newNode(_toArray(arguments));
  1796. };
  1797. _each(_K, function(key, val) {
  1798. K[key] = val;
  1799. });
  1800. K.NodeClass = KNode;
  1801. window.KindEditor = K;
  1802. var _START_TO_START = 0,
  1803. _START_TO_END = 1,
  1804. _END_TO_END = 2,
  1805. _END_TO_START = 3,
  1806. _BOOKMARK_ID = 0;
  1807. function _updateCollapsed(range) {
  1808. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1809. return range;
  1810. }
  1811. function _copyAndDelete(range, isCopy, isDelete) {
  1812. var doc = range.doc, nodeList = [];
  1813. function splitTextNode(node, startOffset, endOffset) {
  1814. var length = node.nodeValue.length, centerNode;
  1815. if (isCopy) {
  1816. var cloneNode = node.cloneNode(true);
  1817. if (startOffset > 0) {
  1818. centerNode = cloneNode.splitText(startOffset);
  1819. } else {
  1820. centerNode = cloneNode;
  1821. }
  1822. if (endOffset < length) {
  1823. centerNode.splitText(endOffset - startOffset);
  1824. }
  1825. }
  1826. if (isDelete) {
  1827. var center = node;
  1828. if (startOffset > 0) {
  1829. center = node.splitText(startOffset);
  1830. range.setStart(node, startOffset);
  1831. }
  1832. if (endOffset < length) {
  1833. var right = center.splitText(endOffset - startOffset);
  1834. range.setEnd(right, 0);
  1835. }
  1836. nodeList.push(center);
  1837. }
  1838. return centerNode;
  1839. }
  1840. function removeNodes() {
  1841. if (isDelete) {
  1842. range.up().collapse(true);
  1843. }
  1844. for (var i = 0, len = nodeList.length; i < len; i++) {
  1845. var node = nodeList[i];
  1846. if (node.parentNode) {
  1847. node.parentNode.removeChild(node);
  1848. }
  1849. }
  1850. }
  1851. var copyRange = range.cloneRange().down();
  1852. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1853. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1854. if (ancestor.nodeType == 3) {
  1855. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1856. if (isCopy) {
  1857. frag.appendChild(textNode);
  1858. }
  1859. removeNodes();
  1860. return isCopy ? frag : range;
  1861. }
  1862. function extractNodes(parent, frag) {
  1863. var node = parent.firstChild, nextNode;
  1864. while (node) {
  1865. var testRange = new KRange(doc).selectNode(node);
  1866. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1867. if (start >= 0 && incStart <= 0) {
  1868. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1869. }
  1870. if (incStart >= 0 && incEnd <= 0) {
  1871. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1872. }
  1873. if (incEnd >= 0 && end <= 0) {
  1874. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1875. }
  1876. if (end >= 0) {
  1877. return false;
  1878. }
  1879. nextNode = node.nextSibling;
  1880. if (start > 0) {
  1881. if (node.nodeType == 1) {
  1882. if (incStart >= 0 && incEnd <= 0) {
  1883. if (isCopy) {
  1884. frag.appendChild(node.cloneNode(true));
  1885. }
  1886. if (isDelete) {
  1887. nodeList.push(node);
  1888. }
  1889. } else {
  1890. var childFlag;
  1891. if (isCopy) {
  1892. childFlag = node.cloneNode(false);
  1893. frag.appendChild(childFlag);
  1894. }
  1895. if (extractNodes(node, childFlag) === false) {
  1896. return false;
  1897. }
  1898. }
  1899. } else if (node.nodeType == 3) {
  1900. var textNode;
  1901. if (node == copyRange.startContainer) {
  1902. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1903. } else if (node == copyRange.endContainer) {
  1904. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1905. } else {
  1906. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1907. }
  1908. if (isCopy) {
  1909. try {
  1910. frag.appendChild(textNode);
  1911. } catch(e) {}
  1912. }
  1913. }
  1914. }
  1915. node = nextNode;
  1916. }
  1917. }
  1918. extractNodes(ancestor, frag);
  1919. if (isDelete) {
  1920. range.up().collapse(true);
  1921. }
  1922. for (var i = 0, len = nodeList.length; i < len; i++) {
  1923. var node = nodeList[i];
  1924. if (node.parentNode) {
  1925. node.parentNode.removeChild(node);
  1926. }
  1927. }
  1928. return isCopy ? frag : range;
  1929. }
  1930. function _moveToElementText(range, el) {
  1931. var node = el;
  1932. while (node) {
  1933. var knode = K(node);
  1934. if (knode.name == 'marquee' || knode.name == 'select') {
  1935. return;
  1936. }
  1937. node = node.parentNode;
  1938. }
  1939. try {
  1940. range.moveToElementText(el);
  1941. } catch(e) {}
  1942. }
  1943. function _getStartEnd(rng, isStart) {
  1944. var doc = rng.parentElement().ownerDocument,
  1945. pointRange = rng.duplicate();
  1946. pointRange.collapse(isStart);
  1947. var parent = pointRange.parentElement(),
  1948. nodes = parent.childNodes;
  1949. if (nodes.length === 0) {
  1950. return {node: parent.parentNode, offset: K(parent).index()};
  1951. }
  1952. var startNode = doc, startPos = 0, cmp = -1;
  1953. var testRange = rng.duplicate();
  1954. _moveToElementText(testRange, parent);
  1955. for (var i = 0, len = nodes.length; i < len; i++) {
  1956. var node = nodes[i];
  1957. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1958. if (cmp === 0) {
  1959. return {node: node.parentNode, offset: i};
  1960. }
  1961. if (node.nodeType == 1) {
  1962. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1963. if (knode.isControl()) {
  1964. dummy = doc.createElement('span');
  1965. knode.after(dummy);
  1966. newNode = dummy;
  1967. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1968. }
  1969. _moveToElementText(nodeRange, newNode);
  1970. testRange.setEndPoint('StartToEnd', nodeRange);
  1971. if (cmp > 0) {
  1972. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1973. } else {
  1974. startPos = 0;
  1975. }
  1976. if (dummy) {
  1977. K(dummy).remove();
  1978. }
  1979. } else if (node.nodeType == 3) {
  1980. testRange.moveStart('character', node.nodeValue.length);
  1981. startPos += node.nodeValue.length;
  1982. }
  1983. if (cmp < 0) {
  1984. startNode = node;
  1985. }
  1986. }
  1987. if (cmp < 0 && startNode.nodeType == 1) {
  1988. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1989. }
  1990. if (cmp > 0) {
  1991. while (startNode.nextSibling && startNode.nodeType == 1) {
  1992. startNode = startNode.nextSibling;
  1993. }
  1994. }
  1995. testRange = rng.duplicate();
  1996. _moveToElementText(testRange, parent);
  1997. testRange.setEndPoint('StartToEnd', pointRange);
  1998. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1999. if (cmp > 0 && startNode.nodeType == 3) {
  2000. var prevNode = startNode.previousSibling;
  2001. while (prevNode && prevNode.nodeType == 3) {
  2002. startPos -= prevNode.nodeValue.length;
  2003. prevNode = prevNode.previousSibling;
  2004. }
  2005. }
  2006. return {node: startNode, offset: startPos};
  2007. }
  2008. function _getEndRange(node, offset) {
  2009. var doc = node.ownerDocument || node,
  2010. range = doc.body.createTextRange();
  2011. if (doc == node) {
  2012. range.collapse(true);
  2013. return range;
  2014. }
  2015. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2016. var children = node.childNodes, isStart, child;
  2017. if (offset === 0) {
  2018. child = children[0];
  2019. isStart = true;
  2020. } else {
  2021. child = children[offset - 1];
  2022. isStart = false;
  2023. }
  2024. if (!child) {
  2025. return range;
  2026. }
  2027. if (K(child).name === 'head') {
  2028. if (offset === 1) {
  2029. isStart = true;
  2030. }
  2031. if (offset === 2) {
  2032. isStart = false;
  2033. }
  2034. range.collapse(isStart);
  2035. return range;
  2036. }
  2037. if (child.nodeType == 1) {
  2038. var kchild = K(child), span;
  2039. if (kchild.isControl()) {
  2040. span = doc.createElement('span');
  2041. if (isStart) {
  2042. kchild.before(span);
  2043. } else {
  2044. kchild.after(span);
  2045. }
  2046. child = span;
  2047. }
  2048. _moveToElementText(range, child);
  2049. range.collapse(isStart);
  2050. if (span) {
  2051. K(span).remove();
  2052. }
  2053. return range;
  2054. }
  2055. node = child;
  2056. offset = isStart ? 0 : child.nodeValue.length;
  2057. }
  2058. var dummy = doc.createElement('span');
  2059. K(node).before(dummy);
  2060. _moveToElementText(range, dummy);
  2061. range.moveStart('character', offset);
  2062. K(dummy).remove();
  2063. return range;
  2064. }
  2065. function _toRange(rng) {
  2066. var doc, range;
  2067. function tr2td(start) {
  2068. if (K(start.node).name == 'tr') {
  2069. start.node = start.node.cells[start.offset];
  2070. start.offset = 0;
  2071. }
  2072. }
  2073. if (_IERANGE) {
  2074. if (rng.item) {
  2075. doc = _getDoc(rng.item(0));
  2076. range = new KRange(doc);
  2077. range.selectNode(rng.item(0));
  2078. return range;
  2079. }
  2080. doc = rng.parentElement().ownerDocument;
  2081. var start = _getStartEnd(rng, true),
  2082. end = _getStartEnd(rng, false);
  2083. tr2td(start);
  2084. tr2td(end);
  2085. range = new KRange(doc);
  2086. range.setStart(start.node, start.offset);
  2087. range.setEnd(end.node, end.offset);
  2088. return range;
  2089. }
  2090. var startContainer = rng.startContainer;
  2091. doc = startContainer.ownerDocument || startContainer;
  2092. range = new KRange(doc);
  2093. range.setStart(startContainer, rng.startOffset);
  2094. range.setEnd(rng.endContainer, rng.endOffset);
  2095. return range;
  2096. }
  2097. function KRange(doc) {
  2098. this.init(doc);
  2099. }
  2100. _extend(KRange, {
  2101. init : function(doc) {
  2102. var self = this;
  2103. self.startContainer = doc;
  2104. self.startOffset = 0;
  2105. self.endContainer = doc;
  2106. self.endOffset = 0;
  2107. self.collapsed = true;
  2108. self.doc = doc;
  2109. },
  2110. commonAncestor : function() {
  2111. function getParents(node) {
  2112. var parents = [];
  2113. while (node) {
  2114. parents.push(node);
  2115. node = node.parentNode;
  2116. }
  2117. return parents;
  2118. }
  2119. var parentsA = getParents(this.startContainer),
  2120. parentsB = getParents(this.endContainer),
  2121. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2122. while (++i) {
  2123. parentA = parentsA[lenA - i];
  2124. parentB = parentsB[lenB - i];
  2125. if (!parentA || !parentB || parentA !== parentB) {
  2126. break;
  2127. }
  2128. }
  2129. return parentsA[lenA - i + 1];
  2130. },
  2131. setStart : function(node, offset) {
  2132. var self = this, doc = self.doc;
  2133. self.startContainer = node;
  2134. self.startOffset = offset;
  2135. if (self.endContainer === doc) {
  2136. self.endContainer = node;
  2137. self.endOffset = offset;
  2138. }
  2139. return _updateCollapsed(this);
  2140. },
  2141. setEnd : function(node, offset) {
  2142. var self = this, doc = self.doc;
  2143. self.endContainer = node;
  2144. self.endOffset = offset;
  2145. if (self.startContainer === doc) {
  2146. self.startContainer = node;
  2147. self.startOffset = offset;
  2148. }
  2149. return _updateCollapsed(this);
  2150. },
  2151. setStartBefore : function(node) {
  2152. return this.setStart(node.parentNode || this.doc, K(node).index());
  2153. },
  2154. setStartAfter : function(node) {
  2155. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2156. },
  2157. setEndBefore : function(node) {
  2158. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2159. },
  2160. setEndAfter : function(node) {
  2161. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2162. },
  2163. selectNode : function(node) {
  2164. return this.setStartBefore(node).setEndAfter(node);
  2165. },
  2166. selectNodeContents : function(node) {
  2167. var knode = K(node);
  2168. if (knode.type == 3 || knode.isSingle()) {
  2169. return this.selectNode(node);
  2170. }
  2171. var children = knode.children();
  2172. if (children.length > 0) {
  2173. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2174. }
  2175. return this.setStart(node, 0).setEnd(node, 0);
  2176. },
  2177. collapse : function(toStart) {
  2178. if (toStart) {
  2179. return this.setEnd(this.startContainer, this.startOffset);
  2180. }
  2181. return this.setStart(this.endContainer, this.endOffset);
  2182. },
  2183. compareBoundaryPoints : function(how, range) {
  2184. var rangeA = this.get(), rangeB = range.get();
  2185. if (_IERANGE) {
  2186. var arr = {};
  2187. arr[_START_TO_START] = 'StartToStart';
  2188. arr[_START_TO_END] = 'EndToStart';
  2189. arr[_END_TO_END] = 'EndToEnd';
  2190. arr[_END_TO_START] = 'StartToEnd';
  2191. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2192. if (cmp !== 0) {
  2193. return cmp;
  2194. }
  2195. var nodeA, nodeB, nodeC, posA, posB;
  2196. if (how === _START_TO_START || how === _END_TO_START) {
  2197. nodeA = this.startContainer;
  2198. posA = this.startOffset;
  2199. }
  2200. if (how === _START_TO_END || how === _END_TO_END) {
  2201. nodeA = this.endContainer;
  2202. posA = this.endOffset;
  2203. }
  2204. if (how === _START_TO_START || how === _START_TO_END) {
  2205. nodeB = range.startContainer;
  2206. posB = range.startOffset;
  2207. }
  2208. if (how === _END_TO_END || how === _END_TO_START) {
  2209. nodeB = range.endContainer;
  2210. posB = range.endOffset;
  2211. }
  2212. if (nodeA === nodeB) {
  2213. var diff = posA - posB;
  2214. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2215. }
  2216. nodeC = nodeB;
  2217. while (nodeC && nodeC.parentNode !== nodeA) {
  2218. nodeC = nodeC.parentNode;
  2219. }
  2220. if (nodeC) {
  2221. return K(nodeC).index() >= posA ? -1 : 1;
  2222. }
  2223. nodeC = nodeA;
  2224. while (nodeC && nodeC.parentNode !== nodeB) {
  2225. nodeC = nodeC.parentNode;
  2226. }
  2227. if (nodeC) {
  2228. return K(nodeC).index() >= posB ? 1 : -1;
  2229. }
  2230. nodeC = K(nodeB).next();
  2231. if (nodeC && nodeC.contains(nodeA)) {
  2232. return 1;
  2233. }
  2234. nodeC = K(nodeA).next();
  2235. if (nodeC && nodeC.contains(nodeB)) {
  2236. return -1;
  2237. }
  2238. } else {
  2239. return rangeA.compareBoundaryPoints(how, rangeB);
  2240. }
  2241. },
  2242. cloneRange : function() {
  2243. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2244. },
  2245. toString : function() {
  2246. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2247. return str.replace(/\r\n|\n|\r/g, '');
  2248. },
  2249. cloneContents : function() {
  2250. return _copyAndDelete(this, true, false);
  2251. },
  2252. deleteContents : function() {
  2253. return _copyAndDelete(this, false, true);
  2254. },
  2255. extractContents : function() {
  2256. return _copyAndDelete(this, true, true);
  2257. },
  2258. insertNode : function(node) {
  2259. var self = this,
  2260. sc = self.startContainer, so = self.startOffset,
  2261. ec = self.endContainer, eo = self.endOffset,
  2262. firstChild, lastChild, c, nodeCount = 1;
  2263. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2264. firstChild = node.firstChild;
  2265. lastChild = node.lastChild;
  2266. nodeCount = node.childNodes.length;
  2267. }
  2268. if (sc.nodeType == 1) {
  2269. c = sc.childNodes[so];
  2270. if (c) {
  2271. sc.insertBefore(node, c);
  2272. if (sc === ec) {
  2273. eo += nodeCount;
  2274. }
  2275. } else {
  2276. sc.appendChild(node);
  2277. }
  2278. } else if (sc.nodeType == 3) {
  2279. if (so === 0) {
  2280. sc.parentNode.insertBefore(node, sc);
  2281. if (sc.parentNode === ec) {
  2282. eo += nodeCount;
  2283. }
  2284. } else if (so >= sc.nodeValue.length) {
  2285. if (sc.nextSibling) {
  2286. sc.parentNode.insertBefore(node, sc.nextSibling);
  2287. } else {
  2288. sc.parentNode.appendChild(node);
  2289. }
  2290. } else {
  2291. if (so > 0) {
  2292. c = sc.splitText(so);
  2293. } else {
  2294. c = sc;
  2295. }
  2296. sc.parentNode.insertBefore(node, c);
  2297. if (sc === ec) {
  2298. ec = c;
  2299. eo -= so;
  2300. }
  2301. }
  2302. }
  2303. if (firstChild) {
  2304. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2305. } else {
  2306. self.selectNode(node);
  2307. }
  2308. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2309. return self;
  2310. }
  2311. return self.setEnd(ec, eo);
  2312. },
  2313. surroundContents : function(node) {
  2314. node.appendChild(this.extractContents());
  2315. return this.insertNode(node).selectNode(node);
  2316. },
  2317. isControl : function() {
  2318. var self = this,
  2319. sc = self.startContainer, so = self.startOffset,
  2320. ec = self.endContainer, eo = self.endOffset, rng;
  2321. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2322. },
  2323. get : function(hasControlRange) {
  2324. var self = this, doc = self.doc, node, rng;
  2325. if (!_IERANGE) {
  2326. rng = doc.createRange();
  2327. try {
  2328. rng.setStart(self.startContainer, self.startOffset);
  2329. rng.setEnd(self.endContainer, self.endOffset);
  2330. } catch (e) {}
  2331. return rng;
  2332. }
  2333. if (hasControlRange && self.isControl()) {
  2334. rng = doc.body.createControlRange();
  2335. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2336. return rng;
  2337. }
  2338. var range = self.cloneRange().down();
  2339. rng = doc.body.createTextRange();
  2340. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2341. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2342. return rng;
  2343. },
  2344. html : function() {
  2345. return K(this.cloneContents()).outer();
  2346. },
  2347. down : function() {
  2348. var self = this;
  2349. function downPos(node, pos, isStart) {
  2350. if (node.nodeType != 1) {
  2351. return;
  2352. }
  2353. var children = K(node).children();
  2354. if (children.length === 0) {
  2355. return;
  2356. }
  2357. var left, right, child, offset;
  2358. if (pos > 0) {
  2359. left = children.eq(pos - 1);
  2360. }
  2361. if (pos < children.length) {
  2362. right = children.eq(pos);
  2363. }
  2364. if (left && left.type == 3) {
  2365. child = left[0];
  2366. offset = child.nodeValue.length;
  2367. }
  2368. if (right && right.type == 3) {
  2369. child = right[0];
  2370. offset = 0;
  2371. }
  2372. if (!child) {
  2373. return;
  2374. }
  2375. if (isStart) {
  2376. self.setStart(child, offset);
  2377. } else {
  2378. self.setEnd(child, offset);
  2379. }
  2380. }
  2381. downPos(self.startContainer, self.startOffset, true);
  2382. downPos(self.endContainer, self.endOffset, false);
  2383. return self;
  2384. },
  2385. up : function() {
  2386. var self = this;
  2387. function upPos(node, pos, isStart) {
  2388. if (node.nodeType != 3) {
  2389. return;
  2390. }
  2391. if (pos === 0) {
  2392. if (isStart) {
  2393. self.setStartBefore(node);
  2394. } else {
  2395. self.setEndBefore(node);
  2396. }
  2397. } else if (pos == node.nodeValue.length) {
  2398. if (isStart) {
  2399. self.setStartAfter(node);
  2400. } else {
  2401. self.setEndAfter(node);
  2402. }
  2403. }
  2404. }
  2405. upPos(self.startContainer, self.startOffset, true);
  2406. upPos(self.endContainer, self.endOffset, false);
  2407. return self;
  2408. },
  2409. enlarge : function(toBlock) {
  2410. var self = this;
  2411. self.up();
  2412. function enlargePos(node, pos, isStart) {
  2413. var knode = K(node), parent;
  2414. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2415. return;
  2416. }
  2417. if (pos === 0) {
  2418. while (!knode.prev()) {
  2419. parent = knode.parent();
  2420. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2421. break;
  2422. }
  2423. knode = parent;
  2424. }
  2425. if (isStart) {
  2426. self.setStartBefore(knode[0]);
  2427. } else {
  2428. self.setEndBefore(knode[0]);
  2429. }
  2430. } else if (pos == knode.children().length) {
  2431. while (!knode.next()) {
  2432. parent = knode.parent();
  2433. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2434. break;
  2435. }
  2436. knode = parent;
  2437. }
  2438. if (isStart) {
  2439. self.setStartAfter(knode[0]);
  2440. } else {
  2441. self.setEndAfter(knode[0]);
  2442. }
  2443. }
  2444. }
  2445. enlargePos(self.startContainer, self.startOffset, true);
  2446. enlargePos(self.endContainer, self.endOffset, false);
  2447. return self;
  2448. },
  2449. shrink : function() {
  2450. var self = this, child, collapsed = self.collapsed;
  2451. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2452. self.setStart(child, 0);
  2453. }
  2454. if (collapsed) {
  2455. return self.collapse(collapsed);
  2456. }
  2457. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2458. self.setEnd(child, child.childNodes.length);
  2459. }
  2460. return self;
  2461. },
  2462. createBookmark : function(serialize) {
  2463. var self = this, doc = self.doc, endNode,
  2464. startNode = K('<span style="display:none;"></span>', doc)[0];
  2465. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2466. if (!self.collapsed) {
  2467. endNode = startNode.cloneNode(true);
  2468. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2469. }
  2470. if (endNode) {
  2471. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2472. }
  2473. self.insertNode(startNode).setStartAfter(startNode);
  2474. return {
  2475. start : serialize ? '#' + startNode.id : startNode,
  2476. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2477. };
  2478. },
  2479. moveToBookmark : function(bookmark) {
  2480. var self = this, doc = self.doc,
  2481. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2482. if (!start || start.length < 1) {
  2483. return self;
  2484. }
  2485. self.setStartBefore(start[0]);
  2486. start.remove();
  2487. if (end && end.length > 0) {
  2488. self.setEndBefore(end[0]);
  2489. end.remove();
  2490. } else {
  2491. self.collapse(true);
  2492. }
  2493. return self;
  2494. },
  2495. dump : function() {
  2496. console.log('--------------------');
  2497. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2498. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2499. }
  2500. });
  2501. function _range(mixed) {
  2502. if (!mixed.nodeName) {
  2503. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2504. }
  2505. return new KRange(mixed);
  2506. }
  2507. K.RangeClass = KRange;
  2508. K.range = _range;
  2509. K.START_TO_START = _START_TO_START;
  2510. K.START_TO_END = _START_TO_END;
  2511. K.END_TO_END = _END_TO_END;
  2512. K.END_TO_START = _END_TO_START;
  2513. function _nativeCommand(doc, key, val) {
  2514. try {
  2515. doc.execCommand(key, false, val);
  2516. } catch(e) {}
  2517. }
  2518. function _nativeCommandValue(doc, key) {
  2519. var val = '';
  2520. try {
  2521. val = doc.queryCommandValue(key);
  2522. } catch (e) {}
  2523. if (typeof val !== 'string') {
  2524. val = '';
  2525. }
  2526. return val;
  2527. }
  2528. function _getSel(doc) {
  2529. var win = _getWin(doc);
  2530. return _IERANGE ? doc.selection : win.getSelection();
  2531. }
  2532. function _getRng(doc) {
  2533. var sel = _getSel(doc), rng;
  2534. try {
  2535. if (sel.rangeCount > 0) {
  2536. rng = sel.getRangeAt(0);
  2537. } else {
  2538. rng = sel.createRange();
  2539. }
  2540. } catch(e) {}
  2541. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2542. return null;
  2543. }
  2544. return rng;
  2545. }
  2546. function _singleKeyMap(map) {
  2547. var newMap = {}, arr, v;
  2548. _each(map, function(key, val) {
  2549. arr = key.split(',');
  2550. for (var i = 0, len = arr.length; i < len; i++) {
  2551. v = arr[i];
  2552. newMap[v] = val;
  2553. }
  2554. });
  2555. return newMap;
  2556. }
  2557. function _hasAttrOrCss(knode, map) {
  2558. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2559. }
  2560. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2561. mapKey = mapKey || knode.name;
  2562. if (knode.type !== 1) {
  2563. return false;
  2564. }
  2565. var newMap = _singleKeyMap(map);
  2566. if (!newMap[mapKey]) {
  2567. return false;
  2568. }
  2569. var arr = newMap[mapKey].split(',');
  2570. for (var i = 0, len = arr.length; i < len; i++) {
  2571. var key = arr[i];
  2572. if (key === '*') {
  2573. return true;
  2574. }
  2575. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2576. var method = match[1] ? 'css' : 'attr';
  2577. key = match[2];
  2578. var val = match[3] || '';
  2579. if (val === '' && knode[method](key) !== '') {
  2580. return true;
  2581. }
  2582. if (val !== '' && knode[method](key) === val) {
  2583. return true;
  2584. }
  2585. }
  2586. return false;
  2587. }
  2588. function _removeAttrOrCss(knode, map) {
  2589. if (knode.type != 1) {
  2590. return;
  2591. }
  2592. _removeAttrOrCssByKey(knode, map, '*');
  2593. _removeAttrOrCssByKey(knode, map);
  2594. }
  2595. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2596. mapKey = mapKey || knode.name;
  2597. if (knode.type !== 1) {
  2598. return;
  2599. }
  2600. var newMap = _singleKeyMap(map);
  2601. if (!newMap[mapKey]) {
  2602. return;
  2603. }
  2604. var arr = newMap[mapKey].split(','), allFlag = false;
  2605. for (var i = 0, len = arr.length; i < len; i++) {
  2606. var key = arr[i];
  2607. if (key === '*') {
  2608. allFlag = true;
  2609. break;
  2610. }
  2611. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2612. key = match[2];
  2613. if (match[1]) {
  2614. key = _toCamel(key);
  2615. if (knode[0].style[key]) {
  2616. knode[0].style[key] = '';
  2617. }
  2618. } else {
  2619. knode.removeAttr(key);
  2620. }
  2621. }
  2622. if (allFlag) {
  2623. knode.remove(true);
  2624. }
  2625. }
  2626. function _getInnerNode(knode) {
  2627. var inner = knode;
  2628. while (inner.first()) {
  2629. inner = inner.first();
  2630. }
  2631. return inner;
  2632. }
  2633. function _isEmptyNode(knode) {
  2634. if (knode.type != 1 || knode.isSingle()) {
  2635. return false;
  2636. }
  2637. return knode.html().replace(/<[^>]+>/g, '') === '';
  2638. }
  2639. function _mergeWrapper(a, b) {
  2640. a = a.clone(true);
  2641. var lastA = _getInnerNode(a), childA = a, merged = false;
  2642. while (b) {
  2643. while (childA) {
  2644. if (childA.name === b.name) {
  2645. _mergeAttrs(childA, b.attr(), b.css());
  2646. merged = true;
  2647. }
  2648. childA = childA.first();
  2649. }
  2650. if (!merged) {
  2651. lastA.append(b.clone(false));
  2652. }
  2653. merged = false;
  2654. b = b.first();
  2655. }
  2656. return a;
  2657. }
  2658. function _wrapNode(knode, wrapper) {
  2659. wrapper = wrapper.clone(true);
  2660. if (knode.type == 3) {
  2661. _getInnerNode(wrapper).append(knode.clone(false));
  2662. knode.replaceWith(wrapper);
  2663. return wrapper;
  2664. }
  2665. var nodeWrapper = knode, child;
  2666. while ((child = knode.first()) && child.children().length == 1) {
  2667. knode = child;
  2668. }
  2669. child = knode.first();
  2670. var frag = knode.doc.createDocumentFragment();
  2671. while (child) {
  2672. frag.appendChild(child[0]);
  2673. child = child.next();
  2674. }
  2675. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2676. if (frag.firstChild) {
  2677. _getInnerNode(wrapper).append(frag);
  2678. }
  2679. nodeWrapper.replaceWith(wrapper);
  2680. return wrapper;
  2681. }
  2682. function _mergeAttrs(knode, attrs, styles) {
  2683. _each(attrs, function(key, val) {
  2684. if (key !== 'style') {
  2685. knode.attr(key, val);
  2686. }
  2687. });
  2688. _each(styles, function(key, val) {
  2689. knode.css(key, val);
  2690. });
  2691. }
  2692. function _inPreElement(knode) {
  2693. while (knode && knode.name != 'body') {
  2694. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2695. return true;
  2696. }
  2697. knode = knode.parent();
  2698. }
  2699. return false;
  2700. }
  2701. function KCmd(range) {
  2702. this.init(range);
  2703. }
  2704. _extend(KCmd, {
  2705. init : function(range) {
  2706. var self = this, doc = range.doc;
  2707. self.doc = doc;
  2708. self.win = _getWin(doc);
  2709. self.sel = _getSel(doc);
  2710. self.range = range;
  2711. },
  2712. selection : function(forceReset) {
  2713. var self = this, doc = self.doc, rng = _getRng(doc);
  2714. self.sel = _getSel(doc);
  2715. if (rng) {
  2716. self.range = _range(rng);
  2717. if (K(self.range.startContainer).name == 'html') {
  2718. self.range.selectNodeContents(doc.body).collapse(false);
  2719. }
  2720. return self;
  2721. }
  2722. if (forceReset) {
  2723. self.range.selectNodeContents(doc.body).collapse(false);
  2724. }
  2725. return self;
  2726. },
  2727. select : function(hasDummy) {
  2728. hasDummy = _undef(hasDummy, true);
  2729. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2730. sc = range.startContainer, so = range.startOffset,
  2731. ec = range.endContainer, eo = range.endOffset,
  2732. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2733. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2734. if (_IERANGE) {
  2735. var dummy = K('<span>&nbsp;</span>', doc);
  2736. range.insertNode(dummy[0]);
  2737. rng = doc.body.createTextRange();
  2738. try {
  2739. rng.moveToElementText(dummy[0]);
  2740. } catch(ex) {}
  2741. rng.collapse(false);
  2742. rng.select();
  2743. dummy.remove();
  2744. win.focus();
  2745. return self;
  2746. }
  2747. if (_WEBKIT) {
  2748. var children = sc.childNodes;
  2749. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2750. range.insertNode(doc.createTextNode('\u200B'));
  2751. hasU200b = true;
  2752. }
  2753. }
  2754. }
  2755. if (_IERANGE) {
  2756. try {
  2757. rng = range.get(true);
  2758. rng.select();
  2759. } catch(e) {}
  2760. } else {
  2761. if (hasU200b) {
  2762. range.collapse(false);
  2763. }
  2764. rng = range.get(true);
  2765. sel.removeAllRanges();
  2766. sel.addRange(rng);
  2767. if (doc !== document) {
  2768. var pos = K(rng.endContainer).pos();
  2769. win.scrollTo(pos.x, pos.y);
  2770. }
  2771. }
  2772. win.focus();
  2773. return self;
  2774. },
  2775. wrap : function(val) {
  2776. var self = this, doc = self.doc, range = self.range, wrapper;
  2777. wrapper = K(val, doc);
  2778. if (range.collapsed) {
  2779. range.shrink();
  2780. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2781. return self;
  2782. }
  2783. if (wrapper.isBlock()) {
  2784. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2785. while (child.first()) {
  2786. child = child.first();
  2787. }
  2788. child.append(range.extractContents());
  2789. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2790. return self;
  2791. }
  2792. range.enlarge();
  2793. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2794. K(ancestor).scan(function(node) {
  2795. if (!isStart && node == bookmark.start) {
  2796. isStart = true;
  2797. return;
  2798. }
  2799. if (isStart) {
  2800. if (node == bookmark.end) {
  2801. return false;
  2802. }
  2803. var knode = K(node);
  2804. if (_inPreElement(knode)) {
  2805. return;
  2806. }
  2807. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2808. var parent;
  2809. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2810. knode = parent;
  2811. }
  2812. _wrapNode(knode, wrapper);
  2813. }
  2814. }
  2815. });
  2816. range.moveToBookmark(bookmark);
  2817. return self;
  2818. },
  2819. split : function(isStart, map) {
  2820. var range = this.range, doc = range.doc;
  2821. var tempRange = range.cloneRange().collapse(isStart);
  2822. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2823. parent = node.nodeType == 3 ? node.parentNode : node,
  2824. needSplit = false, knode;
  2825. while (parent && parent.parentNode) {
  2826. knode = K(parent);
  2827. if (map) {
  2828. if (!knode.isStyle()) {
  2829. break;
  2830. }
  2831. if (!_hasAttrOrCss(knode, map)) {
  2832. break;
  2833. }
  2834. } else {
  2835. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2836. break;
  2837. }
  2838. }
  2839. needSplit = true;
  2840. parent = parent.parentNode;
  2841. }
  2842. if (needSplit) {
  2843. var dummy = doc.createElement('span');
  2844. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2845. if (isStart) {
  2846. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2847. } else {
  2848. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2849. }
  2850. var frag = tempRange.extractContents(),
  2851. first = frag.firstChild, last = frag.lastChild;
  2852. if (isStart) {
  2853. tempRange.insertNode(frag);
  2854. range.setStartAfter(last).setEndBefore(dummy);
  2855. } else {
  2856. parent.appendChild(frag);
  2857. range.setStartBefore(dummy).setEndBefore(first);
  2858. }
  2859. var dummyParent = dummy.parentNode;
  2860. if (dummyParent == range.endContainer) {
  2861. var prev = K(dummy).prev(), next = K(dummy).next();
  2862. if (prev && next && prev.type == 3 && next.type == 3) {
  2863. range.setEnd(prev[0], prev[0].nodeValue.length);
  2864. } else if (!isStart) {
  2865. range.setEnd(range.endContainer, range.endOffset - 1);
  2866. }
  2867. }
  2868. dummyParent.removeChild(dummy);
  2869. }
  2870. return this;
  2871. },
  2872. remove : function(map) {
  2873. var self = this, doc = self.doc, range = self.range;
  2874. range.enlarge();
  2875. if (range.startOffset === 0) {
  2876. var ksc = K(range.startContainer), parent;
  2877. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2878. ksc = parent;
  2879. }
  2880. range.setStart(ksc[0], 0);
  2881. ksc = K(range.startContainer);
  2882. if (ksc.isBlock()) {
  2883. _removeAttrOrCss(ksc, map);
  2884. }
  2885. var kscp = ksc.parent();
  2886. if (kscp && kscp.isBlock()) {
  2887. _removeAttrOrCss(kscp, map);
  2888. }
  2889. }
  2890. var sc, so;
  2891. if (range.collapsed) {
  2892. self.split(true, map);
  2893. sc = range.startContainer;
  2894. so = range.startOffset;
  2895. if (so > 0) {
  2896. var sb = K(sc.childNodes[so - 1]);
  2897. if (sb && _isEmptyNode(sb)) {
  2898. sb.remove();
  2899. range.setStart(sc, so - 1);
  2900. }
  2901. }
  2902. var sa = K(sc.childNodes[so]);
  2903. if (sa && _isEmptyNode(sa)) {
  2904. sa.remove();
  2905. }
  2906. if (_isEmptyNode(sc)) {
  2907. range.startBefore(sc);
  2908. sc.remove();
  2909. }
  2910. range.collapse(true);
  2911. return self;
  2912. }
  2913. self.split(true, map);
  2914. self.split(false, map);
  2915. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2916. range.cloneRange().collapse(false).insertNode(endDummy);
  2917. range.cloneRange().collapse(true).insertNode(startDummy);
  2918. var nodeList = [], cmpStart = false;
  2919. K(range.commonAncestor()).scan(function(node) {
  2920. if (!cmpStart && node == startDummy) {
  2921. cmpStart = true;
  2922. return;
  2923. }
  2924. if (node == endDummy) {
  2925. return false;
  2926. }
  2927. if (cmpStart) {
  2928. nodeList.push(node);
  2929. }
  2930. });
  2931. K(startDummy).remove();
  2932. K(endDummy).remove();
  2933. sc = range.startContainer;
  2934. so = range.startOffset;
  2935. var ec = range.endContainer, eo = range.endOffset;
  2936. if (so > 0) {
  2937. var startBefore = K(sc.childNodes[so - 1]);
  2938. if (startBefore && _isEmptyNode(startBefore)) {
  2939. startBefore.remove();
  2940. range.setStart(sc, so - 1);
  2941. if (sc == ec) {
  2942. range.setEnd(ec, eo - 1);
  2943. }
  2944. }
  2945. var startAfter = K(sc.childNodes[so]);
  2946. if (startAfter && _isEmptyNode(startAfter)) {
  2947. startAfter.remove();
  2948. if (sc == ec) {
  2949. range.setEnd(ec, eo - 1);
  2950. }
  2951. }
  2952. }
  2953. var endAfter = K(ec.childNodes[range.endOffset]);
  2954. if (endAfter && _isEmptyNode(endAfter)) {
  2955. endAfter.remove();
  2956. }
  2957. var bookmark = range.createBookmark(true);
  2958. _each(nodeList, function(i, node) {
  2959. _removeAttrOrCss(K(node), map);
  2960. });
  2961. range.moveToBookmark(bookmark);
  2962. return self;
  2963. },
  2964. commonNode : function(map) {
  2965. var range = this.range;
  2966. var ec = range.endContainer, eo = range.endOffset,
  2967. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2968. function find(node) {
  2969. var child = node, parent = node;
  2970. while (parent) {
  2971. if (_hasAttrOrCss(K(parent), map)) {
  2972. return K(parent);
  2973. }
  2974. parent = parent.parentNode;
  2975. }
  2976. while (child && (child = child.lastChild)) {
  2977. if (_hasAttrOrCss(K(child), map)) {
  2978. return K(child);
  2979. }
  2980. }
  2981. return null;
  2982. }
  2983. var cNode = find(node);
  2984. if (cNode) {
  2985. return cNode;
  2986. }
  2987. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2988. var prev = K(node).prev();
  2989. if (prev) {
  2990. return find(prev);
  2991. }
  2992. }
  2993. return null;
  2994. },
  2995. commonAncestor : function(tagName) {
  2996. var range = this.range,
  2997. sc = range.startContainer, so = range.startOffset,
  2998. ec = range.endContainer, eo = range.endOffset,
  2999. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3000. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3001. function find(node) {
  3002. while (node) {
  3003. if (node.nodeType == 1) {
  3004. if (node.tagName.toLowerCase() === tagName) {
  3005. return node;
  3006. }
  3007. }
  3008. node = node.parentNode;
  3009. }
  3010. return null;
  3011. }
  3012. var start = find(startNode), end = find(endNode);
  3013. if (start && end && start === end) {
  3014. return K(start);
  3015. }
  3016. return null;
  3017. },
  3018. state : function(key) {
  3019. var self = this, doc = self.doc, bool = false;
  3020. try {
  3021. bool = doc.queryCommandState(key);
  3022. } catch (e) {}
  3023. return bool;
  3024. },
  3025. val : function(key) {
  3026. var self = this, doc = self.doc, range = self.range;
  3027. function lc(val) {
  3028. return val.toLowerCase();
  3029. }
  3030. key = lc(key);
  3031. var val = '', knode;
  3032. if (key === 'fontfamily' || key === 'fontname') {
  3033. val = _nativeCommandValue(doc, 'fontname');
  3034. val = val.replace(/['"]/g, '');
  3035. return lc(val);
  3036. }
  3037. if (key === 'formatblock') {
  3038. val = _nativeCommandValue(doc, key);
  3039. if (val === '') {
  3040. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3041. if (knode) {
  3042. val = knode.name;
  3043. }
  3044. }
  3045. if (val === 'Normal') {
  3046. val = 'p';
  3047. }
  3048. return lc(val);
  3049. }
  3050. if (key === 'fontsize') {
  3051. knode = self.commonNode({'*' : '.font-size'});
  3052. if (knode) {
  3053. val = knode.css('font-size');
  3054. }
  3055. return lc(val);
  3056. }
  3057. if (key === 'forecolor') {
  3058. knode = self.commonNode({'*' : '.color'});
  3059. if (knode) {
  3060. val = knode.css('color');
  3061. }
  3062. val = _toHex(val);
  3063. if (val === '') {
  3064. val = 'default';
  3065. }
  3066. return lc(val);
  3067. }
  3068. if (key === 'hilitecolor') {
  3069. knode = self.commonNode({'*' : '.background-color'});
  3070. if (knode) {
  3071. val = knode.css('background-color');
  3072. }
  3073. val = _toHex(val);
  3074. if (val === '') {
  3075. val = 'default';
  3076. }
  3077. return lc(val);
  3078. }
  3079. return val;
  3080. },
  3081. toggle : function(wrapper, map) {
  3082. var self = this;
  3083. if (self.commonNode(map)) {
  3084. self.remove(map);
  3085. } else {
  3086. self.wrap(wrapper);
  3087. }
  3088. return self.select();
  3089. },
  3090. bold : function() {
  3091. return this.toggle('<strong></strong>', {
  3092. span : '.font-weight=bold',
  3093. strong : '*',
  3094. b : '*'
  3095. });
  3096. },
  3097. italic : function() {
  3098. return this.toggle('<em></em>', {
  3099. span : '.font-style=italic',
  3100. em : '*',
  3101. i : '*'
  3102. });
  3103. },
  3104. underline : function() {
  3105. return this.toggle('<u></u>', {
  3106. span : '.text-decoration=underline',
  3107. u : '*'
  3108. });
  3109. },
  3110. strikethrough : function() {
  3111. return this.toggle('<s></s>', {
  3112. span : '.text-decoration=line-through',
  3113. s : '*'
  3114. });
  3115. },
  3116. forecolor : function(val) {
  3117. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3118. },
  3119. hilitecolor : function(val) {
  3120. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3121. },
  3122. fontsize : function(val) {
  3123. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3124. },
  3125. fontname : function(val) {
  3126. return this.fontfamily(val);
  3127. },
  3128. fontfamily : function(val) {
  3129. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3130. },
  3131. removeformat : function() {
  3132. var map = {
  3133. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3134. },
  3135. tags = _STYLE_TAG_MAP;
  3136. _each(tags, function(key, val) {
  3137. map[key] = '*';
  3138. });
  3139. this.remove(map);
  3140. return this.select();
  3141. },
  3142. inserthtml : function(val, quickMode) {
  3143. var self = this, range = self.range;
  3144. if (val === '') {
  3145. return self;
  3146. }
  3147. function pasteHtml(range, val) {
  3148. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3149. var rng = range.get();
  3150. if (rng.item) {
  3151. rng.item(0).outerHTML = val;
  3152. } else {
  3153. rng.pasteHTML(val);
  3154. }
  3155. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3156. temp.parentNode.removeChild(temp);
  3157. var newRange = _toRange(rng);
  3158. range.setEnd(newRange.endContainer, newRange.endOffset);
  3159. range.collapse(false);
  3160. self.select(false);
  3161. }
  3162. function insertHtml(range, val) {
  3163. var doc = range.doc,
  3164. frag = doc.createDocumentFragment();
  3165. K('@' + val, doc).each(function() {
  3166. frag.appendChild(this);
  3167. });
  3168. range.deleteContents();
  3169. range.insertNode(frag);
  3170. range.collapse(false);
  3171. self.select(false);
  3172. }
  3173. if (_IERANGE && quickMode) {
  3174. try {
  3175. pasteHtml(range, val);
  3176. } catch(e) {
  3177. insertHtml(range, val);
  3178. }
  3179. return self;
  3180. }
  3181. insertHtml(range, val);
  3182. return self;
  3183. },
  3184. hr : function() {
  3185. return this.inserthtml('<hr />');
  3186. },
  3187. print : function() {
  3188. this.win.print();
  3189. return this;
  3190. },
  3191. insertimage : function(url, title, width, height, border, align) {
  3192. title = _undef(title, '');
  3193. border = _undef(border, 0);
  3194. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3195. if (width) {
  3196. html += 'width="' + _escape(width) + '" ';
  3197. }
  3198. if (height) {
  3199. html += 'height="' + _escape(height) + '" ';
  3200. }
  3201. if (title) {
  3202. html += 'title="' + _escape(title) + '" ';
  3203. }
  3204. if (align) {
  3205. html += 'align="' + _escape(align) + '" ';
  3206. }
  3207. html += 'alt="' + _escape(title) + '" ';
  3208. html += '/>';
  3209. return this.inserthtml(html);
  3210. },
  3211. createlink : function(url, type) {
  3212. var self = this, doc = self.doc, range = self.range;
  3213. self.select();
  3214. var a = self.commonNode({ a : '*' });
  3215. if (a && !range.isControl()) {
  3216. range.selectNode(a.get());
  3217. self.select();
  3218. }
  3219. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3220. if (type) {
  3221. html += ' target="' + _escape(type) + '"';
  3222. }
  3223. if (range.collapsed) {
  3224. html += '>' + _escape(url) + '</a>';
  3225. return self.inserthtml(html);
  3226. }
  3227. if (range.isControl()) {
  3228. var node = K(range.startContainer.childNodes[range.startOffset]);
  3229. html += '></a>';
  3230. node.after(K(html, doc));
  3231. node.next().append(node);
  3232. range.selectNode(node[0]);
  3233. return self.select();
  3234. }
  3235. function setAttr(node, url, type) {
  3236. K(node).attr('href', url).attr('data-ke-src', url);
  3237. if (type) {
  3238. K(node).attr('target', type);
  3239. } else {
  3240. K(node).removeAttr('target');
  3241. }
  3242. }
  3243. var sc = range.startContainer, so = range.startOffset,
  3244. ec = range.endContainer, eo = range.endOffset;
  3245. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3246. var child = sc.childNodes[so];
  3247. if (child.nodeName.toLowerCase() == 'a') {
  3248. setAttr(child, url, type);
  3249. return self;
  3250. }
  3251. }
  3252. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3253. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3254. setAttr(this, url, type);
  3255. });
  3256. return self;
  3257. },
  3258. unlink : function() {
  3259. var self = this, doc = self.doc, range = self.range;
  3260. self.select();
  3261. if (range.collapsed) {
  3262. var a = self.commonNode({ a : '*' });
  3263. if (a) {
  3264. range.selectNode(a.get());
  3265. self.select();
  3266. }
  3267. _nativeCommand(doc, 'unlink', null);
  3268. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3269. var parent = K(range.startContainer).parent();
  3270. if (parent.name === 'a') {
  3271. parent.remove(true);
  3272. }
  3273. }
  3274. } else {
  3275. _nativeCommand(doc, 'unlink', null);
  3276. }
  3277. return self;
  3278. }
  3279. });
  3280. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3281. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3282. KCmd.prototype[name] = function(val) {
  3283. var self = this;
  3284. self.select();
  3285. _nativeCommand(self.doc, name, val);
  3286. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3287. self.selection();
  3288. }
  3289. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3290. self.selection();
  3291. }
  3292. return self;
  3293. };
  3294. });
  3295. _each('cut,copy,paste'.split(','), function(i, name) {
  3296. KCmd.prototype[name] = function() {
  3297. var self = this;
  3298. if (!self.doc.queryCommandSupported(name)) {
  3299. throw 'not supported';
  3300. }
  3301. self.select();
  3302. _nativeCommand(self.doc, name, null);
  3303. return self;
  3304. };
  3305. });
  3306. function _cmd(mixed) {
  3307. if (mixed.nodeName) {
  3308. var doc = _getDoc(mixed);
  3309. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3310. }
  3311. return new KCmd(mixed);
  3312. }
  3313. K.CmdClass = KCmd;
  3314. K.cmd = _cmd;
  3315. function _drag(options) {
  3316. var moveEl = options.moveEl,
  3317. moveFn = options.moveFn,
  3318. clickEl = options.clickEl || moveEl,
  3319. beforeDrag = options.beforeDrag,
  3320. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3321. var docs = [document];
  3322. if (iframeFix) {
  3323. K('iframe').each(function() {
  3324. var src = _formatUrl(this.src || '', 'absolute');
  3325. if (/^https?:\/\//.test(src)) {
  3326. return;
  3327. }
  3328. var doc;
  3329. try {
  3330. doc = _iframeDoc(this);
  3331. } catch(e) {}
  3332. if (doc) {
  3333. var pos = K(this).pos();
  3334. K(doc).data('pos-x', pos.x);
  3335. K(doc).data('pos-y', pos.y);
  3336. docs.push(doc);
  3337. }
  3338. });
  3339. }
  3340. clickEl.mousedown(function(e) {
  3341. if(e.button !== 0 && e.button !== 1) {
  3342. return;
  3343. }
  3344. e.stopPropagation();
  3345. var self = clickEl.get(),
  3346. x = _removeUnit(moveEl.css('left')),
  3347. y = _removeUnit(moveEl.css('top')),
  3348. width = moveEl.width(),
  3349. height = moveEl.height(),
  3350. pageX = e.pageX,
  3351. pageY = e.pageY;
  3352. if (beforeDrag) {
  3353. beforeDrag();
  3354. }
  3355. function moveListener(e) {
  3356. e.preventDefault();
  3357. var kdoc = K(_getDoc(e.target));
  3358. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3359. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3360. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3361. }
  3362. function selectListener(e) {
  3363. e.preventDefault();
  3364. }
  3365. function upListener(e) {
  3366. e.preventDefault();
  3367. K(docs).unbind('mousemove', moveListener)
  3368. .unbind('mouseup', upListener)
  3369. .unbind('selectstart', selectListener);
  3370. if (self.releaseCapture) {
  3371. self.releaseCapture();
  3372. }
  3373. }
  3374. K(docs).mousemove(moveListener)
  3375. .mouseup(upListener)
  3376. .bind('selectstart', selectListener);
  3377. if (self.setCapture) {
  3378. self.setCapture();
  3379. }
  3380. });
  3381. }
  3382. function KWidget(options) {
  3383. this.init(options);
  3384. }
  3385. _extend(KWidget, {
  3386. init : function(options) {
  3387. var self = this;
  3388. self.name = options.name || '';
  3389. self.doc = options.doc || document;
  3390. self.win = _getWin(self.doc);
  3391. self.x = _addUnit(options.x);
  3392. self.y = _addUnit(options.y);
  3393. self.z = options.z;
  3394. self.width = _addUnit(options.width);
  3395. self.height = _addUnit(options.height);
  3396. self.index = _addUnit(options.index);
  3397. self.div = K('<div style="display:block;"></div>');
  3398. self.options = options;
  3399. self._alignEl = options.alignEl;
  3400. if (self.width) {
  3401. self.div.css('width', self.width);
  3402. }
  3403. if (self.height) {
  3404. self.div.css('height', self.height);
  3405. }
  3406. if (self.z) {
  3407. self.div.css({
  3408. position : 'absolute',
  3409. left : self.x,
  3410. top : self.y,
  3411. 'z-index' : self.z
  3412. });
  3413. }
  3414. if (self.z && (self.x === undefined || self.y === undefined)) {
  3415. self.autoPos(self.width, self.height);
  3416. }
  3417. if (options.cls) {
  3418. self.div.addClass(options.cls);
  3419. }
  3420. if (options.shadowMode) {
  3421. self.div.addClass('ke-shadow');
  3422. }
  3423. if (options.css) {
  3424. self.div.css(options.css);
  3425. }
  3426. if (options.src) {
  3427. K(options.src).replaceWith(self.div);
  3428. } else {
  3429. K(self.doc.body).append(self.div);
  3430. }
  3431. if (options.html) {
  3432. self.div.html(options.html);
  3433. }
  3434. if (options.autoScroll) {
  3435. if (_IE && _V < 7 || _QUIRKS) {
  3436. var scrollPos = _getScrollPos();
  3437. K(self.win).bind('scroll', function(e) {
  3438. var pos = _getScrollPos(),
  3439. diffX = pos.x - scrollPos.x,
  3440. diffY = pos.y - scrollPos.y;
  3441. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3442. });
  3443. } else {
  3444. self.div.css('position', 'fixed');
  3445. }
  3446. }
  3447. },
  3448. pos : function(x, y, updateProp) {
  3449. var self = this;
  3450. updateProp = _undef(updateProp, true);
  3451. if (x !== null) {
  3452. x = x < 0 ? 0 : _addUnit(x);
  3453. self.div.css('left', x);
  3454. if (updateProp) {
  3455. self.x = x;
  3456. }
  3457. }
  3458. if (y !== null) {
  3459. y = y < 0 ? 0 : _addUnit(y);
  3460. self.div.css('top', y);
  3461. if (updateProp) {
  3462. self.y = y;
  3463. }
  3464. }
  3465. return self;
  3466. },
  3467. autoPos : function(width, height) {
  3468. var x, y, self = this,
  3469. w = _removeUnit(width) || 0,
  3470. h = _removeUnit(height) || 0,
  3471. scrollPos = _getScrollPos();
  3472. if (self._alignEl) {
  3473. var knode = K(self._alignEl),
  3474. pos = knode.pos(),
  3475. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3476. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3477. x = diffX < 0 ? pos.x : pos.x + diffX;
  3478. y = diffY < 0 ? pos.y : pos.y + diffY;
  3479. } else {
  3480. var docEl = _docElement(self.doc);
  3481. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3482. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3483. }
  3484. if (!(_IE && _V < 7 || _QUIRKS)) {
  3485. x -= scrollPos.x;
  3486. y -= scrollPos.y;
  3487. }
  3488. return self.pos(x, y);
  3489. },
  3490. remove : function() {
  3491. var self = this;
  3492. if (_IE && _V < 7 || _QUIRKS) {
  3493. K(self.win).unbind('scroll');
  3494. }
  3495. self.div.remove();
  3496. _each(self, function(i) {
  3497. self[i] = null;
  3498. });
  3499. return this;
  3500. },
  3501. show : function() {
  3502. this.div.show();
  3503. return this;
  3504. },
  3505. hide : function() {
  3506. this.div.hide();
  3507. return this;
  3508. },
  3509. draggable : function(options) {
  3510. var self = this;
  3511. options = options || {};
  3512. options.moveEl = self.div;
  3513. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3514. if ((x = x + diffX) < 0) {
  3515. x = 0;
  3516. }
  3517. if ((y = y + diffY) < 0) {
  3518. y = 0;
  3519. }
  3520. self.pos(x, y);
  3521. };
  3522. _drag(options);
  3523. return self;
  3524. }
  3525. });
  3526. function _widget(options) {
  3527. return new KWidget(options);
  3528. }
  3529. K.WidgetClass = KWidget;
  3530. K.widget = _widget;
  3531. function _iframeDoc(iframe) {
  3532. iframe = _get(iframe);
  3533. return iframe.contentDocument || iframe.contentWindow.document;
  3534. }
  3535. var html, _direction = '';
  3536. if ((html = document.getElementsByTagName('html'))) {
  3537. _direction = html[0].dir;
  3538. }
  3539. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3540. var arr = [
  3541. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3542. '<head><meta charset="utf-8" /><title></title>',
  3543. '<style>',
  3544. 'html {margin:0;padding:0;}',
  3545. 'body {margin:0;padding:5px;}',
  3546. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3547. 'body, p, div {word-wrap: break-word;}',
  3548. 'p {margin:5px 0;}',
  3549. 'table {border-collapse:collapse;}',
  3550. 'img {border:0;}',
  3551. 'noscript {display:none;}',
  3552. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3553. 'img.ke-flash {',
  3554. ' border:1px solid #AAA;',
  3555. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3556. ' background-position:center center;',
  3557. ' background-repeat:no-repeat;',
  3558. ' width:100px;',
  3559. ' height:100px;',
  3560. '}',
  3561. 'img.ke-rm {',
  3562. ' border:1px solid #AAA;',
  3563. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3564. ' background-position:center center;',
  3565. ' background-repeat:no-repeat;',
  3566. ' width:100px;',
  3567. ' height:100px;',
  3568. '}',
  3569. 'img.ke-media {',
  3570. ' border:1px solid #AAA;',
  3571. ' background-image:url(' + themesPath + 'common/media.gif);',
  3572. ' background-position:center center;',
  3573. ' background-repeat:no-repeat;',
  3574. ' width:100px;',
  3575. ' height:100px;',
  3576. '}',
  3577. 'img.ke-anchor {',
  3578. ' border:1px dashed #666;',
  3579. ' width:16px;',
  3580. ' height:16px;',
  3581. '}',
  3582. '.ke-script, .ke-noscript, .ke-display-none {',
  3583. ' display:none;',
  3584. ' font-size:0;',
  3585. ' width:0;',
  3586. ' height:0;',
  3587. '}',
  3588. '.ke-pagebreak {',
  3589. ' border:1px dotted #AAA;',
  3590. ' font-size:0;',
  3591. ' height:2px;',
  3592. '}',
  3593. '</style>'
  3594. ];
  3595. if (!_isArray(cssPath)) {
  3596. cssPath = [cssPath];
  3597. }
  3598. _each(cssPath, function(i, path) {
  3599. if (path) {
  3600. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3601. }
  3602. });
  3603. if (cssData) {
  3604. arr.push('<style>' + cssData + '</style>');
  3605. }
  3606. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3607. return arr.join('\n');
  3608. }
  3609. function _elementVal(knode, val) {
  3610. if (knode.hasVal()) {
  3611. if (val === undefined) {
  3612. var html = knode.val();
  3613. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3614. return html;
  3615. }
  3616. return knode.val(val);
  3617. }
  3618. return knode.html(val);
  3619. }
  3620. function KEdit(options) {
  3621. this.init(options);
  3622. }
  3623. _extend(KEdit, KWidget, {
  3624. init : function(options) {
  3625. var self = this;
  3626. KEdit.parent.init.call(self, options);
  3627. self.srcElement = K(options.srcElement);
  3628. self.div.addClass('ke-edit');
  3629. self.designMode = _undef(options.designMode, true);
  3630. self.beforeGetHtml = options.beforeGetHtml;
  3631. self.beforeSetHtml = options.beforeSetHtml;
  3632. self.afterSetHtml = options.afterSetHtml;
  3633. var themesPath = _undef(options.themesPath, ''),
  3634. bodyClass = options.bodyClass,
  3635. cssPath = options.cssPath,
  3636. cssData = options.cssData,
  3637. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3638. srcScript = ('document.open();' +
  3639. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3640. 'document.close();'),
  3641. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3642. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3643. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3644. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3645. self.iframe.attr('tabindex', self.tabIndex);
  3646. self.textarea.attr('tabindex', self.tabIndex);
  3647. if (self.width) {
  3648. self.setWidth(self.width);
  3649. }
  3650. if (self.height) {
  3651. self.setHeight(self.height);
  3652. }
  3653. if (self.designMode) {
  3654. self.textarea.hide();
  3655. } else {
  3656. self.iframe.hide();
  3657. }
  3658. function ready() {
  3659. var doc = _iframeDoc(self.iframe);
  3660. doc.open();
  3661. if (isDocumentDomain) {
  3662. doc.domain = document.domain;
  3663. }
  3664. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3665. doc.close();
  3666. self.win = self.iframe[0].contentWindow;
  3667. self.doc = doc;
  3668. var cmd = _cmd(doc);
  3669. self.afterChange(function(e) {
  3670. cmd.selection();
  3671. });
  3672. if (_WEBKIT) {
  3673. K(doc).click(function(e) {
  3674. if (K(e.target).name === 'img') {
  3675. cmd.selection(true);
  3676. cmd.range.selectNode(e.target);
  3677. cmd.select();
  3678. }
  3679. });
  3680. }
  3681. if (_IE) {
  3682. self._mousedownHandler = function() {
  3683. var newRange = cmd.range.cloneRange();
  3684. newRange.shrink();
  3685. if (newRange.isControl()) {
  3686. self.blur();
  3687. }
  3688. };
  3689. K(document).mousedown(self._mousedownHandler);
  3690. K(doc).keydown(function(e) {
  3691. if (e.which == 8) {
  3692. cmd.selection();
  3693. var rng = cmd.range;
  3694. if (rng.isControl()) {
  3695. rng.collapse(true);
  3696. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3697. e.preventDefault();
  3698. }
  3699. }
  3700. });
  3701. }
  3702. self.cmd = cmd;
  3703. self.html(_elementVal(self.srcElement));
  3704. if (_IE) {
  3705. doc.body.disabled = true;
  3706. doc.body.contentEditable = true;
  3707. doc.body.removeAttribute('disabled');
  3708. } else {
  3709. doc.designMode = 'on';
  3710. }
  3711. if (options.afterCreate) {
  3712. options.afterCreate.call(self);
  3713. }
  3714. }
  3715. if (isDocumentDomain) {
  3716. self.iframe.bind('load', function(e) {
  3717. self.iframe.unbind('load');
  3718. if (_IE) {
  3719. ready();
  3720. } else {
  3721. setTimeout(ready, 0);
  3722. }
  3723. });
  3724. }
  3725. self.div.append(self.iframe);
  3726. self.div.append(self.textarea);
  3727. self.srcElement.hide();
  3728. !isDocumentDomain && ready();
  3729. },
  3730. setWidth : function(val) {
  3731. var self = this;
  3732. val = _addUnit(val);
  3733. self.width = val;
  3734. self.div.css('width', val);
  3735. return self;
  3736. },
  3737. setHeight : function(val) {
  3738. var self = this;
  3739. val = _addUnit(val);
  3740. self.height = val;
  3741. self.div.css('height', val);
  3742. self.iframe.css('height', val);
  3743. if ((_IE && _V < 8) || _QUIRKS) {
  3744. val = _addUnit(_removeUnit(val) - 2);
  3745. }
  3746. self.textarea.css('height', val);
  3747. return self;
  3748. },
  3749. remove : function() {
  3750. var self = this, doc = self.doc;
  3751. K(doc.body).unbind();
  3752. K(doc).unbind();
  3753. K(self.win).unbind();
  3754. if (self._mousedownHandler) {
  3755. K(document).unbind('mousedown', self._mousedownHandler);
  3756. }
  3757. _elementVal(self.srcElement, self.html());
  3758. self.srcElement.show();
  3759. self.iframe.unbind();
  3760. self.textarea.unbind();
  3761. KEdit.parent.remove.call(self);
  3762. },
  3763. html : function(val, isFull) {
  3764. var self = this, doc = self.doc;
  3765. if (self.designMode) {
  3766. var body = doc.body;
  3767. if (val === undefined) {
  3768. if (isFull) {
  3769. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3770. } else {
  3771. val = body.innerHTML;
  3772. }
  3773. if (self.beforeGetHtml) {
  3774. val = self.beforeGetHtml(val);
  3775. }
  3776. if (_GECKO && val == '<br />') {
  3777. val = '';
  3778. }
  3779. return val;
  3780. }
  3781. if (self.beforeSetHtml) {
  3782. val = self.beforeSetHtml(val);
  3783. }
  3784. if (_IE && _V >= 9) {
  3785. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3786. }
  3787. K(body).html(val);
  3788. if (self.afterSetHtml) {
  3789. self.afterSetHtml();
  3790. }
  3791. return self;
  3792. }
  3793. if (val === undefined) {
  3794. return self.textarea.val();
  3795. }
  3796. self.textarea.val(val);
  3797. return self;
  3798. },
  3799. design : function(bool) {
  3800. var self = this, val;
  3801. if (bool === undefined ? !self.designMode : bool) {
  3802. if (!self.designMode) {
  3803. val = self.html();
  3804. self.designMode = true;
  3805. self.textarea.hide();
  3806. self.html(val);
  3807. var iframe = self.iframe;
  3808. var height = _removeUnit(self.height);
  3809. iframe.height(height - 2);
  3810. iframe.show();
  3811. setTimeout(function() {
  3812. iframe.height(height);
  3813. }, 0);
  3814. }
  3815. } else {
  3816. if (self.designMode) {
  3817. val = self.html();
  3818. self.designMode = false;
  3819. self.html(val);
  3820. self.iframe.hide();
  3821. self.textarea.show();
  3822. }
  3823. }
  3824. return self.focus();
  3825. },
  3826. focus : function() {
  3827. var self = this;
  3828. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3829. return self;
  3830. },
  3831. blur : function() {
  3832. var self = this;
  3833. if (_IE) {
  3834. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3835. self.div.append(input);
  3836. input[0].focus();
  3837. input.remove();
  3838. } else {
  3839. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3840. }
  3841. return self;
  3842. },
  3843. afterChange : function(fn) {
  3844. var self = this, doc = self.doc, body = doc.body;
  3845. K(doc).keyup(function(e) {
  3846. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3847. fn(e);
  3848. }
  3849. });
  3850. K(doc).mouseup(fn).contextmenu(fn);
  3851. K(self.win).blur(fn);
  3852. function timeoutHandler(e) {
  3853. setTimeout(function() {
  3854. fn(e);
  3855. }, 1);
  3856. }
  3857. K(body).bind('paste', timeoutHandler);
  3858. K(body).bind('cut', timeoutHandler);
  3859. return self;
  3860. }
  3861. });
  3862. function _edit(options) {
  3863. return new KEdit(options);
  3864. }
  3865. K.EditClass = KEdit;
  3866. K.edit = _edit;
  3867. K.iframeDoc = _iframeDoc;
  3868. function _selectToolbar(name, fn) {
  3869. var self = this,
  3870. knode = self.get(name);
  3871. if (knode) {
  3872. if (knode.hasClass('ke-disabled')) {
  3873. return;
  3874. }
  3875. fn(knode);
  3876. }
  3877. }
  3878. function KToolbar(options) {
  3879. this.init(options);
  3880. }
  3881. _extend(KToolbar, KWidget, {
  3882. init : function(options) {
  3883. var self = this;
  3884. KToolbar.parent.init.call(self, options);
  3885. self.disableMode = _undef(options.disableMode, false);
  3886. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3887. self._itemMap = {};
  3888. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3889. e.preventDefault();
  3890. }).attr('unselectable', 'on');
  3891. function find(target) {
  3892. var knode = K(target);
  3893. if (knode.hasClass('ke-outline')) {
  3894. return knode;
  3895. }
  3896. if (knode.hasClass('ke-toolbar-icon')) {
  3897. return knode.parent();
  3898. }
  3899. }
  3900. function hover(e, method) {
  3901. var knode = find(e.target);
  3902. if (knode) {
  3903. if (knode.hasClass('ke-disabled')) {
  3904. return;
  3905. }
  3906. if (knode.hasClass('ke-selected')) {
  3907. return;
  3908. }
  3909. knode[method]('ke-on');
  3910. }
  3911. }
  3912. self.div.mouseover(function(e) {
  3913. hover(e, 'addClass');
  3914. })
  3915. .mouseout(function(e) {
  3916. hover(e, 'removeClass');
  3917. })
  3918. .click(function(e) {
  3919. var knode = find(e.target);
  3920. if (knode) {
  3921. if (knode.hasClass('ke-disabled')) {
  3922. return;
  3923. }
  3924. self.options.click.call(this, e, knode.attr('data-name'));
  3925. }
  3926. });
  3927. },
  3928. get : function(name) {
  3929. if (this._itemMap[name]) {
  3930. return this._itemMap[name];
  3931. }
  3932. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3933. },
  3934. select : function(name) {
  3935. _selectToolbar.call(this, name, function(knode) {
  3936. knode.addClass('ke-selected');
  3937. });
  3938. return self;
  3939. },
  3940. unselect : function(name) {
  3941. _selectToolbar.call(this, name, function(knode) {
  3942. knode.removeClass('ke-selected').removeClass('ke-on');
  3943. });
  3944. return self;
  3945. },
  3946. enable : function(name) {
  3947. var self = this,
  3948. knode = name.get ? name : self.get(name);
  3949. if (knode) {
  3950. knode.removeClass('ke-disabled');
  3951. knode.opacity(1);
  3952. }
  3953. return self;
  3954. },
  3955. disable : function(name) {
  3956. var self = this,
  3957. knode = name.get ? name : self.get(name);
  3958. if (knode) {
  3959. knode.removeClass('ke-selected').addClass('ke-disabled');
  3960. knode.opacity(0.5);
  3961. }
  3962. return self;
  3963. },
  3964. disableAll : function(bool, noDisableItems) {
  3965. var self = this, map = self.noDisableItemMap, item;
  3966. if (noDisableItems) {
  3967. map = _toMap(noDisableItems);
  3968. }
  3969. if (bool === undefined ? !self.disableMode : bool) {
  3970. K('span.ke-outline', self.div).each(function() {
  3971. var knode = K(this),
  3972. name = knode[0].getAttribute('data-name', 2);
  3973. if (!map[name]) {
  3974. self.disable(knode);
  3975. }
  3976. });
  3977. self.disableMode = true;
  3978. } else {
  3979. K('span.ke-outline', self.div).each(function() {
  3980. var knode = K(this),
  3981. name = knode[0].getAttribute('data-name', 2);
  3982. if (!map[name]) {
  3983. self.enable(knode);
  3984. }
  3985. });
  3986. self.disableMode = false;
  3987. }
  3988. return self;
  3989. }
  3990. });
  3991. function _toolbar(options) {
  3992. return new KToolbar(options);
  3993. }
  3994. K.ToolbarClass = KToolbar;
  3995. K.toolbar = _toolbar;
  3996. function KMenu(options) {
  3997. this.init(options);
  3998. }
  3999. _extend(KMenu, KWidget, {
  4000. init : function(options) {
  4001. var self = this;
  4002. options.z = options.z || 811213;
  4003. KMenu.parent.init.call(self, options);
  4004. self.centerLineMode = _undef(options.centerLineMode, true);
  4005. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4006. e.stopPropagation();
  4007. }).attr('unselectable', 'on');
  4008. },
  4009. addItem : function(item) {
  4010. var self = this;
  4011. if (item.title === '-') {
  4012. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4013. return;
  4014. }
  4015. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4016. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4017. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4018. height = _addUnit(item.height),
  4019. iconClass = _undef(item.iconClass, '');
  4020. self.div.append(itemDiv);
  4021. if (height) {
  4022. itemDiv.css('height', height);
  4023. rightDiv.css('line-height', height);
  4024. }
  4025. var centerDiv;
  4026. if (self.centerLineMode) {
  4027. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4028. if (height) {
  4029. centerDiv.css('height', height);
  4030. }
  4031. }
  4032. itemDiv.mouseover(function(e) {
  4033. K(this).addClass('ke-menu-item-on');
  4034. if (centerDiv) {
  4035. centerDiv.addClass('ke-menu-item-center-on');
  4036. }
  4037. })
  4038. .mouseout(function(e) {
  4039. K(this).removeClass('ke-menu-item-on');
  4040. if (centerDiv) {
  4041. centerDiv.removeClass('ke-menu-item-center-on');
  4042. }
  4043. })
  4044. .click(function(e) {
  4045. item.click.call(K(this));
  4046. e.stopPropagation();
  4047. })
  4048. .append(leftDiv);
  4049. if (centerDiv) {
  4050. itemDiv.append(centerDiv);
  4051. }
  4052. itemDiv.append(rightDiv);
  4053. if (item.checked) {
  4054. iconClass = 'ke-icon-checked';
  4055. }
  4056. if (iconClass !== '') {
  4057. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4058. }
  4059. rightDiv.html(item.title);
  4060. return self;
  4061. },
  4062. remove : function() {
  4063. var self = this;
  4064. if (self.options.beforeRemove) {
  4065. self.options.beforeRemove.call(self);
  4066. }
  4067. K('.ke-menu-item', self.div[0]).unbind();
  4068. KMenu.parent.remove.call(self);
  4069. return self;
  4070. }
  4071. });
  4072. function _menu(options) {
  4073. return new KMenu(options);
  4074. }
  4075. K.MenuClass = KMenu;
  4076. K.menu = _menu;
  4077. function KColorPicker(options) {
  4078. this.init(options);
  4079. }
  4080. _extend(KColorPicker, KWidget, {
  4081. init : function(options) {
  4082. var self = this;
  4083. options.z = options.z || 811213;
  4084. KColorPicker.parent.init.call(self, options);
  4085. var colors = options.colors || [
  4086. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4087. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4088. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4089. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4090. ];
  4091. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4092. self._cells = [];
  4093. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4094. e.stopPropagation();
  4095. }).attr('unselectable', 'on');
  4096. var table = self.doc.createElement('table');
  4097. self.div.append(table);
  4098. table.className = 'ke-colorpicker-table';
  4099. table.cellPadding = 0;
  4100. table.cellSpacing = 0;
  4101. table.border = 0;
  4102. var row = table.insertRow(0), cell = row.insertCell(0);
  4103. cell.colSpan = colors[0].length;
  4104. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4105. for (var i = 0; i < colors.length; i++) {
  4106. row = table.insertRow(i + 1);
  4107. for (var j = 0; j < colors[i].length; j++) {
  4108. cell = row.insertCell(j);
  4109. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4110. }
  4111. }
  4112. },
  4113. _addAttr : function(cell, color, cls) {
  4114. var self = this;
  4115. cell = K(cell).addClass(cls);
  4116. if (self.selectedColor === color.toLowerCase()) {
  4117. cell.addClass('ke-colorpicker-cell-selected');
  4118. }
  4119. cell.attr('title', color || self.options.noColor);
  4120. cell.mouseover(function(e) {
  4121. K(this).addClass('ke-colorpicker-cell-on');
  4122. });
  4123. cell.mouseout(function(e) {
  4124. K(this).removeClass('ke-colorpicker-cell-on');
  4125. });
  4126. cell.click(function(e) {
  4127. e.stop();
  4128. self.options.click.call(K(this), color);
  4129. });
  4130. if (color) {
  4131. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4132. } else {
  4133. cell.html(self.options.noColor);
  4134. }
  4135. K(cell).attr('unselectable', 'on');
  4136. self._cells.push(cell);
  4137. },
  4138. remove : function() {
  4139. var self = this;
  4140. _each(self._cells, function() {
  4141. this.unbind();
  4142. });
  4143. KColorPicker.parent.remove.call(self);
  4144. return self;
  4145. }
  4146. });
  4147. function _colorpicker(options) {
  4148. return new KColorPicker(options);
  4149. }
  4150. K.ColorPickerClass = KColorPicker;
  4151. K.colorpicker = _colorpicker;
  4152. function KUploadButton(options) {
  4153. this.init(options);
  4154. }
  4155. _extend(KUploadButton, {
  4156. init : function(options) {
  4157. var self = this,
  4158. button = K(options.button),
  4159. fieldName = options.fieldName || 'file',
  4160. url = options.url || '',
  4161. title = button.val(),
  4162. extraParams = options.extraParams || {},
  4163. cls = button[0].className || '',
  4164. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4165. options.afterError = options.afterError || function(str) {
  4166. alert(str);
  4167. };
  4168. var hiddenElements = [];
  4169. for(var k in extraParams){
  4170. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4171. }
  4172. var html = [
  4173. '<div class="ke-inline-block ' + cls + '">',
  4174. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4175. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4176. '<span class="ke-button-common">',
  4177. hiddenElements.join(''),
  4178. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4179. '</span>',
  4180. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4181. (options.form ? '</div>' : '</form>'),
  4182. '</div>'].join('');
  4183. var div = K(html, button.doc);
  4184. button.hide();
  4185. button.before(div);
  4186. self.div = div;
  4187. self.button = button;
  4188. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4189. self.form = options.form ? K(options.form) : K('form', div);
  4190. self.fileBox = K('.ke-upload-file', div);
  4191. var width = options.width || K('.ke-button-common', div).width();
  4192. K('.ke-upload-area', div).width(width);
  4193. self.options = options;
  4194. },
  4195. submit : function() {
  4196. var self = this,
  4197. iframe = self.iframe;
  4198. iframe.bind('load', function() {
  4199. iframe.unbind();
  4200. var tempForm = document.createElement('form');
  4201. self.fileBox.before(tempForm);
  4202. K(tempForm).append(self.fileBox);
  4203. tempForm.reset();
  4204. K(tempForm).remove(true);
  4205. var doc = K.iframeDoc(iframe),
  4206. pre = doc.getElementsByTagName('pre')[0],
  4207. str = '', data;
  4208. if (pre) {
  4209. str = pre.innerHTML;
  4210. } else {
  4211. str = doc.body.innerHTML;
  4212. }
  4213. str = _unescape(str);
  4214. iframe[0].src = 'javascript:false';
  4215. try {
  4216. data = K.json(str);
  4217. } catch (e) {
  4218. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4219. }
  4220. if (data) {
  4221. self.options.afterUpload.call(self, data);
  4222. }
  4223. });
  4224. self.form[0].submit();
  4225. return self;
  4226. },
  4227. remove : function() {
  4228. var self = this;
  4229. if (self.fileBox) {
  4230. self.fileBox.unbind();
  4231. }
  4232. self.iframe.remove();
  4233. self.div.remove();
  4234. self.button.show();
  4235. return self;
  4236. }
  4237. });
  4238. function _uploadbutton(options) {
  4239. return new KUploadButton(options);
  4240. }
  4241. K.UploadButtonClass = KUploadButton;
  4242. K.uploadbutton = _uploadbutton;
  4243. function _createButton(arg) {
  4244. arg = arg || {};
  4245. var name = arg.name || '',
  4246. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4247. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4248. if (arg.click) {
  4249. btn.click(arg.click);
  4250. }
  4251. span.append(btn);
  4252. return span;
  4253. }
  4254. function KDialog(options) {
  4255. this.init(options);
  4256. }
  4257. _extend(KDialog, KWidget, {
  4258. init : function(options) {
  4259. var self = this;
  4260. var shadowMode = _undef(options.shadowMode, true);
  4261. options.z = options.z || 811213;
  4262. options.shadowMode = false;
  4263. options.autoScroll = _undef(options.autoScroll, true);
  4264. KDialog.parent.init.call(self, options);
  4265. var title = options.title,
  4266. body = K(options.body, self.doc),
  4267. previewBtn = options.previewBtn,
  4268. yesBtn = options.yesBtn,
  4269. noBtn = options.noBtn,
  4270. closeBtn = options.closeBtn,
  4271. showMask = _undef(options.showMask, true);
  4272. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4273. e.stopPropagation();
  4274. });
  4275. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4276. if (_IE && _V < 7) {
  4277. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4278. } else if (shadowMode) {
  4279. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4280. }
  4281. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4282. contentDiv.append(headerDiv);
  4283. headerDiv.html(title);
  4284. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4285. headerDiv.append(self.closeIcon);
  4286. self.draggable({
  4287. clickEl : headerDiv,
  4288. beforeDrag : options.beforeDrag
  4289. });
  4290. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4291. contentDiv.append(bodyDiv);
  4292. bodyDiv.append(body);
  4293. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4294. if (previewBtn || yesBtn || noBtn) {
  4295. contentDiv.append(footerDiv);
  4296. }
  4297. _each([
  4298. { btn : previewBtn, name : 'preview' },
  4299. { btn : yesBtn, name : 'yes' },
  4300. { btn : noBtn, name : 'no' }
  4301. ], function() {
  4302. if (this.btn) {
  4303. var button = _createButton(this.btn);
  4304. button.addClass('ke-dialog-' + this.name);
  4305. footerDiv.append(button);
  4306. }
  4307. });
  4308. if (self.height) {
  4309. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4310. }
  4311. self.div.width(self.div.width());
  4312. self.div.height(self.div.height());
  4313. self.mask = null;
  4314. if (showMask) {
  4315. var docEl = _docElement(self.doc),
  4316. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4317. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4318. self.mask = _widget({
  4319. x : 0,
  4320. y : 0,
  4321. z : self.z - 1,
  4322. cls : 'ke-dialog-mask',
  4323. width : docWidth,
  4324. height : docHeight
  4325. });
  4326. }
  4327. self.autoPos(self.div.width(), self.div.height());
  4328. self.footerDiv = footerDiv;
  4329. self.bodyDiv = bodyDiv;
  4330. self.headerDiv = headerDiv;
  4331. self.isLoading = false;
  4332. },
  4333. setMaskIndex : function(z) {
  4334. var self = this;
  4335. self.mask.div.css('z-index', z);
  4336. },
  4337. showLoading : function(msg) {
  4338. msg = _undef(msg, '');
  4339. var self = this, body = self.bodyDiv;
  4340. 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>')
  4341. .width(body.width()).height(body.height())
  4342. .css('top', self.headerDiv.height() + 'px');
  4343. body.css('visibility', 'hidden').after(self.loading);
  4344. self.isLoading = true;
  4345. return self;
  4346. },
  4347. hideLoading : function() {
  4348. this.loading && this.loading.remove();
  4349. this.bodyDiv.css('visibility', 'visible');
  4350. this.isLoading = false;
  4351. return this;
  4352. },
  4353. remove : function() {
  4354. var self = this;
  4355. if (self.options.beforeRemove) {
  4356. self.options.beforeRemove.call(self);
  4357. }
  4358. self.mask && self.mask.remove();
  4359. self.iframeMask && self.iframeMask.remove();
  4360. self.closeIcon.unbind();
  4361. K('input', self.div).unbind();
  4362. K('button', self.div).unbind();
  4363. self.footerDiv.unbind();
  4364. self.bodyDiv.unbind();
  4365. self.headerDiv.unbind();
  4366. K('iframe', self.div).each(function() {
  4367. K(this).remove();
  4368. });
  4369. KDialog.parent.remove.call(self);
  4370. return self;
  4371. }
  4372. });
  4373. function _dialog(options) {
  4374. return new KDialog(options);
  4375. }
  4376. K.DialogClass = KDialog;
  4377. K.dialog = _dialog;
  4378. function _tabs(options) {
  4379. var self = _widget(options),
  4380. remove = self.remove,
  4381. afterSelect = options.afterSelect,
  4382. div = self.div,
  4383. liList = [];
  4384. div.addClass('ke-tabs')
  4385. .bind('contextmenu,mousedown,mousemove', function(e) {
  4386. e.preventDefault();
  4387. });
  4388. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4389. div.append(ul);
  4390. self.add = function(tab) {
  4391. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4392. li.data('tab', tab);
  4393. liList.push(li);
  4394. ul.append(li);
  4395. };
  4396. self.selectedIndex = 0;
  4397. self.select = function(index) {
  4398. self.selectedIndex = index;
  4399. _each(liList, function(i, li) {
  4400. li.unbind();
  4401. if (i === index) {
  4402. li.addClass('ke-tabs-li-selected');
  4403. K(li.data('tab').panel).show('');
  4404. } else {
  4405. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4406. .mouseover(function() {
  4407. K(this).addClass('ke-tabs-li-on');
  4408. })
  4409. .mouseout(function() {
  4410. K(this).removeClass('ke-tabs-li-on');
  4411. })
  4412. .click(function() {
  4413. self.select(i);
  4414. });
  4415. K(li.data('tab').panel).hide();
  4416. }
  4417. });
  4418. if (afterSelect) {
  4419. afterSelect.call(self, index);
  4420. }
  4421. };
  4422. self.remove = function() {
  4423. _each(liList, function() {
  4424. this.remove();
  4425. });
  4426. ul.remove();
  4427. remove.call(self);
  4428. };
  4429. return self;
  4430. }
  4431. K.tabs = _tabs;
  4432. function _loadScript(url, fn) {
  4433. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4434. script = document.createElement('script');
  4435. head.appendChild(script);
  4436. script.src = url;
  4437. script.charset = 'utf-8';
  4438. script.onload = script.onreadystatechange = function() {
  4439. if (!this.readyState || this.readyState === 'loaded') {
  4440. if (fn) {
  4441. fn();
  4442. }
  4443. script.onload = script.onreadystatechange = null;
  4444. head.removeChild(script);
  4445. }
  4446. };
  4447. }
  4448. function _chopQuery(url) {
  4449. var index = url.indexOf('?');
  4450. return index > 0 ? url.substr(0, index) : url;
  4451. }
  4452. function _loadStyle(url) {
  4453. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4454. link = document.createElement('link'),
  4455. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4456. var links = K('link[rel="stylesheet"]', head);
  4457. for (var i = 0, len = links.length; i < len; i++) {
  4458. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4459. return;
  4460. }
  4461. }
  4462. head.appendChild(link);
  4463. link.href = url;
  4464. link.rel = 'stylesheet';
  4465. }
  4466. function _ajax(url, fn, method, param, dataType) {
  4467. method = method || 'GET';
  4468. dataType = dataType || 'json';
  4469. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4470. xhr.open(method, url, true);
  4471. xhr.onreadystatechange = function () {
  4472. if (xhr.readyState == 4 && xhr.status == 200) {
  4473. if (fn) {
  4474. var data = _trim(xhr.responseText);
  4475. if (dataType == 'json') {
  4476. data = _json(data);
  4477. }
  4478. fn(data);
  4479. }
  4480. }
  4481. };
  4482. if (method == 'POST') {
  4483. var params = [];
  4484. _each(param, function(key, val) {
  4485. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4486. });
  4487. try {
  4488. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4489. } catch (e) {}
  4490. xhr.send(params.join('&'));
  4491. } else {
  4492. xhr.send(null);
  4493. }
  4494. }
  4495. K.loadScript = _loadScript;
  4496. K.loadStyle = _loadStyle;
  4497. K.ajax = _ajax;
  4498. var _plugins = {};
  4499. function _plugin(name, fn) {
  4500. if (name === undefined) {
  4501. return _plugins;
  4502. }
  4503. if (!fn) {
  4504. return _plugins[name];
  4505. }
  4506. _plugins[name] = fn;
  4507. }
  4508. var _language = {};
  4509. function _parseLangKey(key) {
  4510. var match, ns = 'core';
  4511. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4512. ns = match[1];
  4513. key = match[2];
  4514. }
  4515. return { ns : ns, key : key };
  4516. }
  4517. function _lang(mixed, langType) {
  4518. langType = langType === undefined ? K.options.langType : langType;
  4519. if (typeof mixed === 'string') {
  4520. if (!_language[langType]) {
  4521. return 'no language';
  4522. }
  4523. var pos = mixed.length - 1;
  4524. if (mixed.substr(pos) === '.') {
  4525. return _language[langType][mixed.substr(0, pos)];
  4526. }
  4527. var obj = _parseLangKey(mixed);
  4528. return _language[langType][obj.ns][obj.key];
  4529. }
  4530. _each(mixed, function(key, val) {
  4531. var obj = _parseLangKey(key);
  4532. if (!_language[langType]) {
  4533. _language[langType] = {};
  4534. }
  4535. if (!_language[langType][obj.ns]) {
  4536. _language[langType][obj.ns] = {};
  4537. }
  4538. _language[langType][obj.ns][obj.key] = val;
  4539. });
  4540. }
  4541. function _getImageFromRange(range, fn) {
  4542. if (range.collapsed) {
  4543. return;
  4544. }
  4545. range = range.cloneRange().up();
  4546. var sc = range.startContainer, so = range.startOffset;
  4547. if (!_WEBKIT && !range.isControl()) {
  4548. return;
  4549. }
  4550. var img = K(sc.childNodes[so]);
  4551. if (!img || img.name != 'img') {
  4552. return;
  4553. }
  4554. if (fn(img)) {
  4555. return img;
  4556. }
  4557. }
  4558. function _bindContextmenuEvent() {
  4559. var self = this, doc = self.edit.doc;
  4560. K(doc).contextmenu(function(e) {
  4561. if (self.menu) {
  4562. self.hideMenu();
  4563. }
  4564. if (!self.useContextmenu) {
  4565. e.preventDefault();
  4566. return;
  4567. }
  4568. if (self._contextmenus.length === 0) {
  4569. return;
  4570. }
  4571. var maxWidth = 0, items = [];
  4572. _each(self._contextmenus, function() {
  4573. if (this.title == '-') {
  4574. items.push(this);
  4575. return;
  4576. }
  4577. if (this.cond && this.cond()) {
  4578. items.push(this);
  4579. if (this.width && this.width > maxWidth) {
  4580. maxWidth = this.width;
  4581. }
  4582. }
  4583. });
  4584. while (items.length > 0 && items[0].title == '-') {
  4585. items.shift();
  4586. }
  4587. while (items.length > 0 && items[items.length - 1].title == '-') {
  4588. items.pop();
  4589. }
  4590. var prevItem = null;
  4591. _each(items, function(i) {
  4592. if (this.title == '-' && prevItem.title == '-') {
  4593. delete items[i];
  4594. }
  4595. prevItem = this;
  4596. });
  4597. if (items.length > 0) {
  4598. e.preventDefault();
  4599. var pos = K(self.edit.iframe).pos(),
  4600. menu = _menu({
  4601. x : pos.x + e.clientX,
  4602. y : pos.y + e.clientY,
  4603. width : maxWidth,
  4604. css : { visibility: 'hidden' },
  4605. shadowMode : self.shadowMode
  4606. });
  4607. _each(items, function() {
  4608. if (this.title) {
  4609. menu.addItem(this);
  4610. }
  4611. });
  4612. var docEl = _docElement(menu.doc),
  4613. menuHeight = menu.div.height();
  4614. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4615. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4616. }
  4617. menu.div.css('visibility', 'visible');
  4618. self.menu = menu;
  4619. }
  4620. });
  4621. }
  4622. function _bindNewlineEvent() {
  4623. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4624. if (_IE && newlineTag !== 'br') {
  4625. return;
  4626. }
  4627. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4628. return;
  4629. }
  4630. if (_OPERA && _V < 9) {
  4631. return;
  4632. }
  4633. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4634. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4635. function getAncestorTagName(range) {
  4636. var ancestor = K(range.commonAncestor());
  4637. while (ancestor) {
  4638. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4639. break;
  4640. }
  4641. ancestor = ancestor.parent();
  4642. }
  4643. return ancestor.name;
  4644. }
  4645. K(doc).keydown(function(e) {
  4646. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4647. autoImg(self);
  4648. return;
  4649. }
  4650. self.cmd.selection();
  4651. var tagName = getAncestorTagName(self.cmd.range);
  4652. if (tagName == 'marquee' || tagName == 'select') {
  4653. return;
  4654. }
  4655. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4656. e.preventDefault();
  4657. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4658. return;
  4659. }
  4660. if (!pSkipTagMap[tagName]) {
  4661. _nativeCommand(doc, 'formatblock', '<p>');
  4662. }
  4663. });
  4664. K(doc).keyup(function(e) {
  4665. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4666. return;
  4667. }
  4668. if (newlineTag == 'br') {
  4669. return;
  4670. }
  4671. if (_GECKO) {
  4672. var root = self.cmd.commonAncestor('p');
  4673. var a = self.cmd.commonAncestor('a');
  4674. if (a && a.text() == '') {
  4675. a.remove(true);
  4676. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4677. self.cmd.select();
  4678. }
  4679. return;
  4680. }
  4681. self.cmd.selection();
  4682. var tagName = getAncestorTagName(self.cmd.range);
  4683. if (tagName == 'marquee' || tagName == 'select') {
  4684. return;
  4685. }
  4686. if (!pSkipTagMap[tagName]) {
  4687. _nativeCommand(doc, 'formatblock', '<p>');
  4688. }
  4689. var div = self.cmd.commonAncestor('div');
  4690. if (div) {
  4691. var p = K('<p></p>'),
  4692. child = div[0].firstChild;
  4693. while (child) {
  4694. var next = child.nextSibling;
  4695. p.append(child);
  4696. child = next;
  4697. }
  4698. div.before(p);
  4699. div.remove();
  4700. self.cmd.range.selectNodeContents(p[0]);
  4701. self.cmd.select();
  4702. }
  4703. });
  4704. }
  4705. function _bindTabEvent() {
  4706. var self = this, doc = self.edit.doc;
  4707. K(doc).keydown(function(e) {
  4708. if (e.which == 9) {
  4709. e.preventDefault();
  4710. if (self.afterTab) {
  4711. self.afterTab.call(self, e);
  4712. return;
  4713. }
  4714. var cmd = self.cmd, range = cmd.range;
  4715. range.shrink();
  4716. if (range.collapsed && range.startContainer.nodeType == 1) {
  4717. range.insertNode(K('@&nbsp;', doc)[0]);
  4718. cmd.select();
  4719. }
  4720. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4721. }
  4722. });
  4723. }
  4724. function _bindFocusEvent() {
  4725. var self = this;
  4726. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4727. if (self.afterFocus) {
  4728. self.afterFocus.call(self, e);
  4729. }
  4730. }).blur(function(e) {
  4731. if (self.afterBlur) {
  4732. self.afterBlur.call(self, e);
  4733. }
  4734. });
  4735. }
  4736. function _removeBookmarkTag(html) {
  4737. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4738. }
  4739. function _removeTempTag(html) {
  4740. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4741. }
  4742. function _addBookmarkToStack(stack, bookmark) {
  4743. if (stack.length === 0) {
  4744. stack.push(bookmark);
  4745. return;
  4746. }
  4747. var prev = stack[stack.length - 1];
  4748. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4749. stack.push(bookmark);
  4750. }
  4751. }
  4752. function _undoToRedo(fromStack, toStack) {
  4753. var self = this, edit = self.edit,
  4754. body = edit.doc.body,
  4755. range, bookmark;
  4756. if (fromStack.length === 0) {
  4757. return self;
  4758. }
  4759. if (edit.designMode) {
  4760. range = self.cmd.range;
  4761. bookmark = range.createBookmark(true);
  4762. bookmark.html = body.innerHTML;
  4763. } else {
  4764. bookmark = {
  4765. html : body.innerHTML
  4766. };
  4767. }
  4768. _addBookmarkToStack(toStack, bookmark);
  4769. var prev = fromStack.pop();
  4770. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4771. prev = fromStack.pop();
  4772. }
  4773. if (edit.designMode) {
  4774. edit.html(prev.html);
  4775. if (prev.start) {
  4776. range.moveToBookmark(prev);
  4777. self.select();
  4778. }
  4779. } else {
  4780. K(body).html(_removeBookmarkTag(prev.html));
  4781. }
  4782. return self;
  4783. }
  4784. function KEditor(options) {
  4785. var self = this;
  4786. self.options = {};
  4787. function setOption(key, val) {
  4788. if (KEditor.prototype[key] === undefined) {
  4789. self[key] = val;
  4790. }
  4791. self.options[key] = val;
  4792. }
  4793. _each(options, function(key, val) {
  4794. setOption(key, options[key]);
  4795. });
  4796. _each(K.options, function(key, val) {
  4797. if (self[key] === undefined) {
  4798. setOption(key, val);
  4799. }
  4800. });
  4801. var se = K(self.srcElement || '<textarea/>');
  4802. if (!self.width) {
  4803. self.width = se[0].style.width || se.width();
  4804. if (!self.width) {
  4805. self.width = '700';
  4806. }
  4807. }
  4808. if (!self.height) {
  4809. self.height = se[0].style.height || se.height();
  4810. }
  4811. setOption('width', _undef(self.width, self.minWidth));
  4812. setOption('height', _undef(self.height, self.minHeight));
  4813. setOption('width', _addUnit(self.width));
  4814. setOption('height', _addUnit(self.height));
  4815. if (_MOBILE && (!_IOS || _V < 534)) {
  4816. //self.designMode = false;
  4817. }
  4818. self.srcElement = se;
  4819. self.initContent = '';
  4820. self.plugin = {};
  4821. self.isCreated = false;
  4822. self._handlers = {};
  4823. self._contextmenus = [];
  4824. self._undoStack = [];
  4825. self._redoStack = [];
  4826. self._firstAddBookmark = true;
  4827. self.menu = self.contextmenu = null;
  4828. self.dialogs = [];
  4829. }
  4830. KEditor.prototype = {
  4831. lang : function(mixed) {
  4832. return _lang(mixed, this.langType);
  4833. },
  4834. loadPlugin : function(name, fn) {
  4835. var self = this;
  4836. var _pluginStatus = this._pluginStatus;
  4837. if (!_pluginStatus) {
  4838. _pluginStatus = this._pluginStatus = {};
  4839. }
  4840. if (_plugins[name]) {
  4841. if (!_isFunction(_plugins[name])) {
  4842. setTimeout(function() {
  4843. self.loadPlugin(name, fn);
  4844. }, 100);
  4845. return self;
  4846. }
  4847. if(!_pluginStatus[name]) {
  4848. _plugins[name].call(self, KindEditor);
  4849. _pluginStatus[name] = 'inited';
  4850. }
  4851. if (fn) {
  4852. fn.call(self);
  4853. }
  4854. return self;
  4855. }
  4856. _plugins[name] = 'loading';
  4857. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4858. setTimeout(function() {
  4859. if (_plugins[name]) {
  4860. self.loadPlugin(name, fn);
  4861. }
  4862. }, 0);
  4863. });
  4864. return self;
  4865. },
  4866. handler : function(key, fn) {
  4867. var self = this;
  4868. if (!self._handlers[key]) {
  4869. self._handlers[key] = [];
  4870. }
  4871. if (_isFunction(fn)) {
  4872. self._handlers[key].push(fn);
  4873. return self;
  4874. }
  4875. _each(self._handlers[key], function() {
  4876. fn = this.call(self, fn);
  4877. });
  4878. return fn;
  4879. },
  4880. clickToolbar : function(name, fn) {
  4881. var self = this, key = 'clickToolbar' + name;
  4882. if (fn === undefined) {
  4883. if (self._handlers[key]) {
  4884. return self.handler(key);
  4885. }
  4886. self.loadPlugin(name, function() {
  4887. self.handler(key);
  4888. });
  4889. return self;
  4890. }
  4891. return self.handler(key, fn);
  4892. },
  4893. updateState : function() {
  4894. var self = this;
  4895. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4896. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4897. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4898. });
  4899. return self;
  4900. },
  4901. addContextmenu : function(item) {
  4902. this._contextmenus.push(item);
  4903. return this;
  4904. },
  4905. afterCreate : function(fn) {
  4906. return this.handler('afterCreate', fn);
  4907. },
  4908. beforeRemove : function(fn) {
  4909. return this.handler('beforeRemove', fn);
  4910. },
  4911. beforeGetHtml : function(fn) {
  4912. return this.handler('beforeGetHtml', fn);
  4913. },
  4914. beforeSetHtml : function(fn) {
  4915. return this.handler('beforeSetHtml', fn);
  4916. },
  4917. afterSetHtml : function(fn) {
  4918. return this.handler('afterSetHtml', fn);
  4919. },
  4920. create : function() {
  4921. var self = this, fullscreenMode = self.fullscreenMode;
  4922. if (self.isCreated) {
  4923. return self;
  4924. }
  4925. if (self.srcElement.data('kindeditor')) {
  4926. return self;
  4927. }
  4928. self.srcElement.data('kindeditor', 'true');
  4929. if (fullscreenMode) {
  4930. _docElement().style.overflow = 'hidden';
  4931. } else {
  4932. _docElement().style.overflow = '';
  4933. }
  4934. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4935. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4936. if ((_IE && _V < 8) || _QUIRKS) {
  4937. height = _addUnit(_removeUnit(height) + 2);
  4938. }
  4939. var container = self.container = K(self.layout);
  4940. if (fullscreenMode) {
  4941. K(document.body).append(container);
  4942. } else {
  4943. self.srcElement.before(container);
  4944. }
  4945. var toolbarDiv = K('.toolbar', container),
  4946. editDiv = K('.edit', container),
  4947. statusbar = self.statusbar = K('.statusbar', container);
  4948. container.removeClass('container')
  4949. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4950. if (fullscreenMode) {
  4951. container.css({
  4952. position : 'absolute',
  4953. left : 0,
  4954. top : 0,
  4955. 'z-index' : 811211
  4956. });
  4957. if (!_GECKO) {
  4958. self._scrollPos = _getScrollPos();
  4959. }
  4960. window.scrollTo(0, 0);
  4961. K(document.body).css({
  4962. 'height' : '1px',
  4963. 'overflow' : 'hidden'
  4964. });
  4965. K(document.body.parentNode).css('overflow', 'hidden');
  4966. self._fullscreenExecuted = true;
  4967. } else {
  4968. if (self._fullscreenExecuted) {
  4969. K(document.body).css({
  4970. 'height' : '',
  4971. 'overflow' : ''
  4972. });
  4973. K(document.body.parentNode).css('overflow', '');
  4974. }
  4975. if (self._scrollPos) {
  4976. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4977. }
  4978. }
  4979. var htmlList = [];
  4980. K.each(self.items, function(i, name) {
  4981. if (name == '|') {
  4982. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4983. } else if (name == '/') {
  4984. htmlList.push('<div class="ke-hr"></div>');
  4985. } else {
  4986. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4987. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4988. }
  4989. });
  4990. var toolbar = self.toolbar = _toolbar({
  4991. src : toolbarDiv,
  4992. html : htmlList.join(''),
  4993. noDisableItems : self.noDisableItems,
  4994. click : function(e, name) {
  4995. e.stop();
  4996. if (self.menu) {
  4997. var menuName = self.menu.name;
  4998. self.hideMenu();
  4999. if (menuName === name) {
  5000. return;
  5001. }
  5002. }
  5003. self.clickToolbar(name);
  5004. }
  5005. });
  5006. var editHeight = _removeUnit(height) - toolbar.div.height();
  5007. var edit = self.edit = _edit({
  5008. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5009. src : editDiv,
  5010. srcElement : self.srcElement,
  5011. designMode : self.designMode,
  5012. themesPath : self.themesPath,
  5013. bodyClass : self.bodyClass,
  5014. cssPath : self.cssPath,
  5015. cssData : self.cssData,
  5016. beforeGetHtml : function(html) {
  5017. html = self.beforeGetHtml(html);
  5018. html = _removeBookmarkTag(_removeTempTag(html));
  5019. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5020. },
  5021. beforeSetHtml : function(html) {
  5022. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5023. return self.beforeSetHtml(html);
  5024. },
  5025. afterSetHtml : function() {
  5026. self.edit = edit = this;
  5027. self.afterSetHtml();
  5028. },
  5029. afterCreate : function() {
  5030. self.edit = edit = this;
  5031. self.cmd = edit.cmd;
  5032. self._docMousedownFn = function(e) {
  5033. if (self.menu) {
  5034. self.hideMenu();
  5035. }
  5036. };
  5037. K(edit.doc, document).mousedown(self._docMousedownFn);
  5038. _bindContextmenuEvent.call(self);
  5039. _bindNewlineEvent.call(self);
  5040. _bindTabEvent.call(self);
  5041. _bindFocusEvent.call(self);
  5042. edit.afterChange(function(e) {
  5043. if (!edit.designMode) {
  5044. return;
  5045. }
  5046. self.updateState();
  5047. self.addBookmark();
  5048. if (self.options.afterChange) {
  5049. self.options.afterChange.call(self);
  5050. }
  5051. });
  5052. edit.textarea.keyup(function(e) {
  5053. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5054. if (self.options.afterChange) {
  5055. self.options.afterChange.call(self);
  5056. }
  5057. }
  5058. });
  5059. if (self.readonlyMode) {
  5060. self.readonly();
  5061. }
  5062. self.isCreated = true;
  5063. if (self.initContent === '') {
  5064. self.initContent = self.html();
  5065. }
  5066. if (self._undoStack.length > 0) {
  5067. var prev = self._undoStack.pop();
  5068. if (prev.start) {
  5069. self.html(prev.html);
  5070. edit.cmd.range.moveToBookmark(prev);
  5071. self.select();
  5072. }
  5073. }
  5074. self.afterCreate();
  5075. if (self.options.afterCreate) {
  5076. self.options.afterCreate.call(self);
  5077. }
  5078. }
  5079. });
  5080. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5081. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5082. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5083. if (self._fullscreenResizeHandler) {
  5084. K(window).unbind('resize', self._fullscreenResizeHandler);
  5085. self._fullscreenResizeHandler = null;
  5086. }
  5087. function initResize() {
  5088. if (statusbar.height() === 0) {
  5089. setTimeout(initResize, 100);
  5090. return;
  5091. }
  5092. self.resize(width, height, false);
  5093. }
  5094. initResize();
  5095. if (fullscreenMode) {
  5096. self._fullscreenResizeHandler = function(e) {
  5097. if (self.isCreated) {
  5098. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5099. }
  5100. };
  5101. K(window).bind('resize', self._fullscreenResizeHandler);
  5102. toolbar.select('fullscreen');
  5103. statusbar.first().css('visibility', 'hidden');
  5104. statusbar.last().css('visibility', 'hidden');
  5105. } else {
  5106. if (_GECKO) {
  5107. K(window).bind('scroll', function(e) {
  5108. self._scrollPos = _getScrollPos();
  5109. });
  5110. }
  5111. if (self.resizeType > 0) {
  5112. _drag({
  5113. moveEl : container,
  5114. clickEl : statusbar,
  5115. moveFn : function(x, y, width, height, diffX, diffY) {
  5116. height += diffY;
  5117. self.resize(null, height);
  5118. }
  5119. });
  5120. } else {
  5121. statusbar.first().css('visibility', 'hidden');
  5122. }
  5123. if (self.resizeType === 2) {
  5124. _drag({
  5125. moveEl : container,
  5126. clickEl : statusbar.last(),
  5127. moveFn : function(x, y, width, height, diffX, diffY) {
  5128. width += diffX;
  5129. height += diffY;
  5130. self.resize(width, height);
  5131. }
  5132. });
  5133. } else {
  5134. statusbar.last().css('visibility', 'hidden');
  5135. }
  5136. }
  5137. return self;
  5138. },
  5139. remove : function() {
  5140. var self = this;
  5141. if (!self.isCreated) {
  5142. return self;
  5143. }
  5144. self.beforeRemove();
  5145. self.srcElement.data('kindeditor', '');
  5146. if (self.menu) {
  5147. self.hideMenu();
  5148. }
  5149. _each(self.dialogs, function() {
  5150. self.hideDialog();
  5151. });
  5152. K(document).unbind('mousedown', self._docMousedownFn);
  5153. self.toolbar.remove();
  5154. self.edit.remove();
  5155. self.statusbar.last().unbind();
  5156. self.statusbar.unbind();
  5157. self.container.remove();
  5158. self.container = self.toolbar = self.edit = self.menu = null;
  5159. self.dialogs = [];
  5160. self.isCreated = false;
  5161. return self;
  5162. },
  5163. resize : function(width, height, updateProp) {
  5164. var self = this;
  5165. updateProp = _undef(updateProp, true);
  5166. if (width) {
  5167. if (!/%/.test(width)) {
  5168. width = _removeUnit(width);
  5169. width = width < self.minWidth ? self.minWidth : width;
  5170. }
  5171. self.container.css('width', _addUnit(width));
  5172. if (updateProp) {
  5173. self.width = _addUnit(width);
  5174. }
  5175. }
  5176. if (height) {
  5177. height = _removeUnit(height);
  5178. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5179. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5180. self.edit.setHeight(editHeight);
  5181. if (updateProp) {
  5182. self.height = _addUnit(height);
  5183. }
  5184. }
  5185. return self;
  5186. },
  5187. select : function() {
  5188. this.isCreated && this.cmd.select();
  5189. return this;
  5190. },
  5191. html : function(val) {
  5192. var self = this;
  5193. if (val === undefined) {
  5194. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5195. }
  5196. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5197. if (self.isCreated) {
  5198. self.cmd.selection();
  5199. }
  5200. return self;
  5201. },
  5202. fullHtml : function() {
  5203. return this.isCreated ? this.edit.html(undefined, true) : '';
  5204. },
  5205. text : function(val) {
  5206. var self = this;
  5207. if (val === undefined) {
  5208. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5209. } else {
  5210. return self.html(_escape(val));
  5211. }
  5212. },
  5213. isEmpty : function() {
  5214. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5215. },
  5216. isDirty : function() {
  5217. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5218. },
  5219. selectedHtml : function() {
  5220. var val = this.isCreated ? this.cmd.range.html() : '';
  5221. val = _removeBookmarkTag(_removeTempTag(val));
  5222. return val;
  5223. },
  5224. count : function(mode) {
  5225. var self = this;
  5226. mode = (mode || 'html').toLowerCase();
  5227. if (mode === 'html') {
  5228. return self.html().length;
  5229. }
  5230. if (mode === 'text') {
  5231. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5232. }
  5233. return 0;
  5234. },
  5235. exec : function(key) {
  5236. key = key.toLowerCase();
  5237. var self = this, cmd = self.cmd,
  5238. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5239. if (changeFlag) {
  5240. self.addBookmark(false);
  5241. }
  5242. cmd[key].apply(cmd, _toArray(arguments, 1));
  5243. if (changeFlag) {
  5244. self.updateState();
  5245. self.addBookmark(false);
  5246. if (self.options.afterChange) {
  5247. self.options.afterChange.call(self);
  5248. }
  5249. }
  5250. return self;
  5251. },
  5252. insertHtml : function(val, quickMode) {
  5253. if (!this.isCreated) {
  5254. return this;
  5255. }
  5256. val = this.beforeSetHtml(val);
  5257. this.exec('inserthtml', val, quickMode);
  5258. return this;
  5259. },
  5260. appendHtml : function(val) {
  5261. this.html(this.html() + val);
  5262. if (this.isCreated) {
  5263. var cmd = this.cmd;
  5264. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5265. cmd.select();
  5266. }
  5267. return this;
  5268. },
  5269. sync : function() {
  5270. _elementVal(this.srcElement, this.html());
  5271. return this;
  5272. },
  5273. focus : function() {
  5274. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5275. return this;
  5276. },
  5277. blur : function() {
  5278. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5279. return this;
  5280. },
  5281. addBookmark : function(checkSize) {
  5282. checkSize = _undef(checkSize, true);
  5283. var self = this, edit = self.edit,
  5284. body = edit.doc.body,
  5285. html = _removeTempTag(body.innerHTML), bookmark;
  5286. if (checkSize && self._undoStack.length > 0) {
  5287. var prev = self._undoStack[self._undoStack.length - 1];
  5288. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5289. return self;
  5290. }
  5291. }
  5292. if (edit.designMode && !self._firstAddBookmark) {
  5293. var range = self.cmd.range;
  5294. bookmark = range.createBookmark(true);
  5295. bookmark.html = _removeTempTag(body.innerHTML);
  5296. range.moveToBookmark(bookmark);
  5297. } else {
  5298. bookmark = {
  5299. html : html
  5300. };
  5301. }
  5302. self._firstAddBookmark = false;
  5303. _addBookmarkToStack(self._undoStack, bookmark);
  5304. return self;
  5305. },
  5306. undo : function() {
  5307. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5308. },
  5309. redo : function() {
  5310. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5311. },
  5312. fullscreen : function(bool) {
  5313. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5314. this.addBookmark(false);
  5315. return this.remove().create();
  5316. },
  5317. readonly : function(isReadonly) {
  5318. isReadonly = _undef(isReadonly, true);
  5319. var self = this, edit = self.edit, doc = edit.doc;
  5320. if (self.designMode) {
  5321. self.toolbar.disableAll(isReadonly, []);
  5322. } else {
  5323. _each(self.noDisableItems, function() {
  5324. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5325. });
  5326. }
  5327. if (_IE) {
  5328. doc.body.contentEditable = !isReadonly;
  5329. } else {
  5330. doc.designMode = isReadonly ? 'off' : 'on';
  5331. }
  5332. edit.textarea[0].disabled = isReadonly;
  5333. },
  5334. createMenu : function(options) {
  5335. var self = this,
  5336. name = options.name,
  5337. knode = self.toolbar.get(name),
  5338. pos = knode.pos();
  5339. options.x = pos.x;
  5340. options.y = pos.y + knode.height();
  5341. options.z = self.options.zIndex;
  5342. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5343. if (options.selectedColor !== undefined) {
  5344. options.cls = 'ke-colorpicker-' + self.themeType;
  5345. options.noColor = self.lang('noColor');
  5346. self.menu = _colorpicker(options);
  5347. } else {
  5348. options.cls = 'ke-menu-' + self.themeType;
  5349. options.centerLineMode = false;
  5350. self.menu = _menu(options);
  5351. }
  5352. return self.menu;
  5353. },
  5354. hideMenu : function() {
  5355. this.menu.remove();
  5356. this.menu = null;
  5357. return this;
  5358. },
  5359. hideContextmenu : function() {
  5360. this.contextmenu.remove();
  5361. this.contextmenu = null;
  5362. return this;
  5363. },
  5364. createDialog : function(options) {
  5365. var self = this, name = options.name;
  5366. options.z = self.options.zIndex;
  5367. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5368. options.closeBtn = _undef(options.closeBtn, {
  5369. name : self.lang('close'),
  5370. click : function(e) {
  5371. self.hideDialog();
  5372. if (_IE && self.cmd) {
  5373. self.cmd.select();
  5374. }
  5375. }
  5376. });
  5377. options.noBtn = _undef(options.noBtn, {
  5378. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5379. click : function(e) {
  5380. self.hideDialog();
  5381. if (_IE && self.cmd) {
  5382. self.cmd.select();
  5383. }
  5384. }
  5385. });
  5386. if (self.dialogAlignType != 'page') {
  5387. options.alignEl = self.container;
  5388. }
  5389. options.cls = 'ke-dialog-' + self.themeType;
  5390. if (self.dialogs.length > 0) {
  5391. var firstDialog = self.dialogs[0],
  5392. parentDialog = self.dialogs[self.dialogs.length - 1];
  5393. firstDialog.setMaskIndex(parentDialog.z + 2);
  5394. options.z = parentDialog.z + 3;
  5395. options.showMask = false;
  5396. }
  5397. var dialog = _dialog(options);
  5398. self.dialogs.push(dialog);
  5399. return dialog;
  5400. },
  5401. hideDialog : function() {
  5402. var self = this;
  5403. if (self.dialogs.length > 0) {
  5404. self.dialogs.pop().remove();
  5405. }
  5406. if (self.dialogs.length > 0) {
  5407. var firstDialog = self.dialogs[0],
  5408. parentDialog = self.dialogs[self.dialogs.length - 1];
  5409. firstDialog.setMaskIndex(parentDialog.z - 1);
  5410. }
  5411. return self;
  5412. },
  5413. errorDialog : function(html) {
  5414. var self = this;
  5415. var dialog = self.createDialog({
  5416. width : 750,
  5417. title : self.lang('uploadError'),
  5418. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5419. });
  5420. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5421. doc.open();
  5422. doc.write(html);
  5423. doc.close();
  5424. K(doc.body).css('background-color', '#FFF');
  5425. iframe[0].contentWindow.focus();
  5426. return self;
  5427. }
  5428. };
  5429. function _editor(options) {
  5430. return new KEditor(options);
  5431. }
  5432. var _instances = [];
  5433. function _create(expr, options) {
  5434. options = options || {};
  5435. options.basePath = _undef(options.basePath, K.basePath);
  5436. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5437. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5438. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5439. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5440. var themeType = _undef(options.themeType, K.options.themeType);
  5441. _loadStyle(options.themesPath + 'default/default.css');
  5442. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5443. }
  5444. function create(editor) {
  5445. _each(_plugins, function(name, fn) {
  5446. if (_isFunction(fn)) {
  5447. fn.call(editor, KindEditor);
  5448. if (!editor._pluginStatus) {
  5449. editor._pluginStatus = {};
  5450. }
  5451. editor._pluginStatus[name] = 'inited';
  5452. }
  5453. });
  5454. return editor.create();
  5455. }
  5456. var knode = K(expr);
  5457. if (!knode || knode.length === 0) {
  5458. return;
  5459. }
  5460. if (knode.length > 1) {
  5461. knode.each(function() {
  5462. _create(this, options);
  5463. });
  5464. return _instances[0];
  5465. }
  5466. options.srcElement = knode[0];
  5467. var editor = new KEditor(options);
  5468. _instances.push(editor);
  5469. if (_language[editor.langType]) {
  5470. return create(editor);
  5471. }
  5472. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5473. create(editor);
  5474. });
  5475. return editor;
  5476. }
  5477. function _eachEditor(expr, fn) {
  5478. K(expr).each(function(i, el) {
  5479. K.each(_instances, function(j, editor) {
  5480. if (editor && editor.srcElement[0] == el) {
  5481. fn.call(editor, j);
  5482. return false;
  5483. }
  5484. });
  5485. });
  5486. }
  5487. K.remove = function(expr) {
  5488. _eachEditor(expr, function(i) {
  5489. this.remove();
  5490. _instances.splice(i, 1);
  5491. });
  5492. };
  5493. K.sync = function(expr) {
  5494. _eachEditor(expr, function() {
  5495. this.sync();
  5496. });
  5497. };
  5498. K.html = function(expr, val) {
  5499. _eachEditor(expr, function() {
  5500. this.html(val);
  5501. });
  5502. };
  5503. K.insertHtml = function(expr, val) {
  5504. _eachEditor(expr, function() {
  5505. this.insertHtml(val);
  5506. });
  5507. };
  5508. K.appendHtml = function(expr, val) {
  5509. _eachEditor(expr, function() {
  5510. this.appendHtml(val);
  5511. });
  5512. };
  5513. if (_IE && _V < 7) {
  5514. _nativeCommand(document, 'BackgroundImageCache', true);
  5515. }
  5516. K.EditorClass = KEditor;
  5517. K.editor = _editor;
  5518. K.create = _create;
  5519. K.instances = _instances;
  5520. K.plugin = _plugin;
  5521. K.lang = _lang;
  5522. _plugin('core', function(K) {
  5523. var self = this,
  5524. shortcutKeys = {
  5525. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5526. };
  5527. self.afterSetHtml(function() {
  5528. if (self.options.afterChange) {
  5529. self.options.afterChange.call(self);
  5530. }
  5531. });
  5532. self.afterCreate(function() {
  5533. if (self.syncType != 'form') {
  5534. return;
  5535. }
  5536. var el = K(self.srcElement), hasForm = false;
  5537. while ((el = el.parent())) {
  5538. if (el.name == 'form') {
  5539. hasForm = true;
  5540. break;
  5541. }
  5542. }
  5543. if (hasForm) {
  5544. el.bind('submit', function(e) {
  5545. self.sync();
  5546. K(window).bind('unload', function() {
  5547. self.edit.textarea.remove();
  5548. });
  5549. });
  5550. var resetBtn = K('[type="reset"]', el);
  5551. resetBtn.click(function() {
  5552. self.html(self.initContent);
  5553. self.cmd.selection();
  5554. });
  5555. self.beforeRemove(function() {
  5556. el.unbind();
  5557. resetBtn.unbind();
  5558. });
  5559. }
  5560. });
  5561. self.clickToolbar('source', function() {
  5562. if (self.edit.designMode) {
  5563. self.toolbar.disableAll(true);
  5564. self.edit.design(false);
  5565. self.toolbar.select('source');
  5566. } else {
  5567. self.toolbar.disableAll(false);
  5568. self.edit.design(true);
  5569. self.toolbar.unselect('source');
  5570. if (_GECKO) {
  5571. setTimeout(function() {
  5572. self.cmd.selection();
  5573. }, 0);
  5574. } else {
  5575. self.cmd.selection();
  5576. }
  5577. }
  5578. self.designMode = self.edit.designMode;
  5579. });
  5580. self.afterCreate(function() {
  5581. if (!self.designMode) {
  5582. self.toolbar.disableAll(true).select('source');
  5583. }
  5584. });
  5585. self.clickToolbar('fullscreen', function() {
  5586. self.fullscreen();
  5587. });
  5588. if (self.fullscreenShortcut) {
  5589. var loaded = false;
  5590. self.afterCreate(function() {
  5591. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5592. if (e.which == 27) {
  5593. setTimeout(function() {
  5594. self.fullscreen();
  5595. }, 0);
  5596. }
  5597. });
  5598. if (loaded) {
  5599. if (_IE && !self.designMode) {
  5600. return;
  5601. }
  5602. self.focus();
  5603. }
  5604. if (!loaded) {
  5605. loaded = true;
  5606. }
  5607. });
  5608. }
  5609. _each('undo,redo'.split(','), function(i, name) {
  5610. if (shortcutKeys[name]) {
  5611. self.afterCreate(function() {
  5612. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5613. self.clickToolbar(name);
  5614. });
  5615. });
  5616. }
  5617. self.clickToolbar(name, function() {
  5618. self[name]();
  5619. });
  5620. });
  5621. self.clickToolbar('formatblock', function() {
  5622. var blocks = self.lang('formatblock.formatBlock'),
  5623. heights = {
  5624. h1 : 28,
  5625. h2 : 24,
  5626. h3 : 18,
  5627. H4 : 14,
  5628. p : 12
  5629. },
  5630. curVal = self.cmd.val('formatblock'),
  5631. menu = self.createMenu({
  5632. name : 'formatblock',
  5633. width : self.langType == 'en' ? 200 : 150
  5634. });
  5635. _each(blocks, function(key, val) {
  5636. var style = 'font-size:' + heights[key] + 'px;';
  5637. if (key.charAt(0) === 'h') {
  5638. style += 'font-weight:bold;';
  5639. }
  5640. menu.addItem({
  5641. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5642. height : heights[key] + 12,
  5643. checked : (curVal === key || curVal === val),
  5644. click : function() {
  5645. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5646. }
  5647. });
  5648. });
  5649. });
  5650. self.clickToolbar('fontname', function() {
  5651. var curVal = self.cmd.val('fontname'),
  5652. menu = self.createMenu({
  5653. name : 'fontname',
  5654. width : 150
  5655. });
  5656. _each(self.lang('fontname.fontName'), function(key, val) {
  5657. menu.addItem({
  5658. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5659. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5660. click : function() {
  5661. self.exec('fontname', key).hideMenu();
  5662. }
  5663. });
  5664. });
  5665. });
  5666. self.clickToolbar('fontsize', function() {
  5667. var curVal = self.cmd.val('fontsize'),
  5668. menu = self.createMenu({
  5669. name : 'fontsize',
  5670. width : 150
  5671. });
  5672. _each(self.fontSizeTable, function(i, val) {
  5673. menu.addItem({
  5674. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5675. height : _removeUnit(val) + 12,
  5676. checked : curVal === val,
  5677. click : function() {
  5678. self.exec('fontsize', val).hideMenu();
  5679. }
  5680. });
  5681. });
  5682. });
  5683. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5684. self.clickToolbar(name, function() {
  5685. self.createMenu({
  5686. name : name,
  5687. selectedColor : self.cmd.val(name) || 'default',
  5688. colors : self.colorTable,
  5689. click : function(color) {
  5690. self.exec(name, color).hideMenu();
  5691. }
  5692. });
  5693. });
  5694. });
  5695. _each(('cut,copy,paste').split(','), function(i, name) {
  5696. self.clickToolbar(name, function() {
  5697. self.focus();
  5698. try {
  5699. self.exec(name, null);
  5700. } catch(e) {
  5701. alert(self.lang(name + 'Error'));
  5702. }
  5703. });
  5704. });
  5705. self.clickToolbar('about', function() {
  5706. var html = '<div style="margin:20px;">' +
  5707. '<div>KindEditor ' + _VERSION + '</div>' +
  5708. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5709. '</div>';
  5710. self.createDialog({
  5711. name : 'about',
  5712. width : 350,
  5713. title : self.lang('about'),
  5714. body : html
  5715. });
  5716. });
  5717. self.plugin.getSelectedLink = function() {
  5718. return self.cmd.commonAncestor('a');
  5719. };
  5720. self.plugin.getSelectedImage = function() {
  5721. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5722. return !/^ke-\w+$/i.test(img[0].className);
  5723. });
  5724. };
  5725. self.plugin.getSelectedFlash = function() {
  5726. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5727. return img[0].className == 'ke-flash';
  5728. });
  5729. };
  5730. self.plugin.getSelectedMedia = function() {
  5731. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5732. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5733. });
  5734. };
  5735. self.plugin.getSelectedAnchor = function() {
  5736. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5737. return img[0].className == 'ke-anchor';
  5738. });
  5739. };
  5740. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5741. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5742. _each('edit,delete'.split(','), function(j, val) {
  5743. self.addContextmenu({
  5744. title : self.lang(val + uName),
  5745. click : function() {
  5746. self.loadPlugin(name, function() {
  5747. self.plugin[name][val]();
  5748. self.hideMenu();
  5749. });
  5750. },
  5751. cond : self.plugin['getSelected' + uName],
  5752. width : 150,
  5753. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5754. });
  5755. });
  5756. self.addContextmenu({ title : '-' });
  5757. });
  5758. self.plugin.getSelectedTable = function() {
  5759. return self.cmd.commonAncestor('table');
  5760. };
  5761. self.plugin.getSelectedRow = function() {
  5762. return self.cmd.commonAncestor('tr');
  5763. };
  5764. self.plugin.getSelectedCell = function() {
  5765. return self.cmd.commonAncestor('td');
  5766. };
  5767. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5768. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5769. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5770. self.addContextmenu({
  5771. title : self.lang('table' + val),
  5772. click : function() {
  5773. self.loadPlugin('table', function() {
  5774. self.plugin.table[val]();
  5775. self.hideMenu();
  5776. });
  5777. },
  5778. cond : cond,
  5779. width : 170,
  5780. iconClass : 'ke-icon-table' + val
  5781. });
  5782. });
  5783. self.addContextmenu({ title : '-' });
  5784. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5785. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5786. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5787. if (shortcutKeys[name]) {
  5788. self.afterCreate(function() {
  5789. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5790. self.cmd.selection();
  5791. self.clickToolbar(name);
  5792. });
  5793. });
  5794. }
  5795. self.clickToolbar(name, function() {
  5796. self.focus().exec(name, null);
  5797. });
  5798. });
  5799. self.afterCreate(function() {
  5800. var doc = self.edit.doc, cmd, bookmark, div,
  5801. cls = '__kindeditor_paste__', pasting = false;
  5802. function movePastedData() {
  5803. cmd.range.moveToBookmark(bookmark);
  5804. cmd.select();
  5805. if (_WEBKIT) {
  5806. K('div.' + cls, div).each(function() {
  5807. K(this).after('<br />').remove(true);
  5808. });
  5809. K('span.Apple-style-span', div).remove(true);
  5810. K('span.Apple-tab-span', div).remove(true);
  5811. K('span[style]', div).each(function() {
  5812. if (K(this).css('white-space') == 'nowrap') {
  5813. K(this).remove(true);
  5814. }
  5815. });
  5816. K('meta', div).remove();
  5817. }
  5818. var html = div[0].innerHTML;
  5819. div.remove();
  5820. if (html === '') {
  5821. return;
  5822. }
  5823. if (_WEBKIT) {
  5824. html = html.replace(/(<br>)\1/ig, '$1');
  5825. }
  5826. if (self.pasteType === 2) {
  5827. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5828. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5829. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5830. } else {
  5831. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5832. html = self.beforeSetHtml(html);
  5833. }
  5834. }
  5835. if (self.pasteType === 1) {
  5836. html = html.replace(/&nbsp;/ig, ' ');
  5837. html = html.replace(/\n\s*\n/g, '\n');
  5838. html = html.replace(/<br[^>]*>/ig, '\n');
  5839. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5840. html = html.replace(/<[^>]+>/g, '');
  5841. html = html.replace(/ {2}/g, ' &nbsp;');
  5842. if (self.newlineTag == 'p') {
  5843. if (/\n/.test(html)) {
  5844. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5845. }
  5846. } else {
  5847. html = html.replace(/\n/g, '<br />$&');
  5848. }
  5849. }
  5850. self.insertHtml(html, true);
  5851. }
  5852. K(doc.body).bind('paste', function(e){
  5853. //处理IE11,Chrome粘贴图片上传
  5854. function dopasteImg() {
  5855. //debugger;
  5856. var file = null;
  5857. if (window.clipboardData) {//ie
  5858. if (clipboardData.files && clipboardData.files.length)//IE11
  5859. file = clipboardData.files[0];
  5860. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5861. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5862. return true;
  5863. }
  5864. } else {
  5865. if (e.event.clipboardData.items)//chrome
  5866. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5867. if (e.event.clipboardData.items[i].kind === "file") {
  5868. file = e.event.clipboardData.items[i];
  5869. break;
  5870. }
  5871. }
  5872. if (file == null) {
  5873. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5874. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5875. return true;
  5876. }
  5877. }
  5878. }
  5879. if (file) {
  5880. if (!K.undef(self.allowImageUpload, true)) {
  5881. alert("编辑器禁止上传图片,请与有关人员联系!");
  5882. return true;
  5883. }
  5884. //获取File Blob
  5885. //debugger;
  5886. var blb;
  5887. if (file.getAsFile) {//Chrome
  5888. blb = file.getAsFile();
  5889. if (blb.size === 0) {
  5890. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5891. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5892. return true;
  5893. }
  5894. sendfile(blb, file.type);
  5895. } else {
  5896. var fr = new FileReader();
  5897. if (fr.readAsArrayBuffer) {//ie
  5898. fr.onloadend = function (evt) {
  5899. blb = evt.target.result;
  5900. sendfile(blb, file.type);
  5901. }
  5902. fr.readAsArrayBuffer(file);
  5903. }
  5904. }
  5905. function sendfile(b, t) {
  5906. var xhr = new XMLHttpRequest();
  5907. var formData = new FormData();
  5908. var isImg = t.indexOf("image/") === 0;
  5909. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5910. //formData.append('imgFile', b);
  5911. var myBlob = new Blob([b], { "type": t });
  5912. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5913. //formData.append('imgFile', b);
  5914. formData.append('dir', isImg ? 'image' : 'file');
  5915. if (self.uploadYunJson && self.uploadYunJson.domain) {
  5916. xhr.open('POST', self.uploadJson.domain);
  5917. } else {
  5918. xhr.open('POST', self.uploadJson);
  5919. }
  5920. xhr.onreadystatechange = function () {
  5921. if (xhr.readyState == 4&&xhr.status == 200) {
  5922. // if (fn) {
  5923. var data = _trim(xhr.responseText);
  5924. //if (dataType == 'json') {
  5925. data = _json(data);
  5926. if (data.error) {
  5927. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5928. $.messager.alert('Error', data.message, 'warning');
  5929. } else {
  5930. alert(data.message);
  5931. }
  5932. } else {
  5933. //self.exec('insertimage', url, title, width, height, border, align);
  5934. if(K.undef(self.formatUploadUrl, true))
  5935. data.url =K.formatUrl(data.url, 'absolute');
  5936. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5937. }
  5938. //}
  5939. // fn(data);
  5940. // }
  5941. }
  5942. }
  5943. xhr.send(formData);
  5944. }
  5945. return true;
  5946. }
  5947. }
  5948. //debugger;
  5949. if (dopasteImg())
  5950. e.stop();
  5951. //处理粘贴结束5825
  5952. if (self.pasteType === 0) {
  5953. e.stop();
  5954. return;
  5955. }
  5956. if (pasting) {
  5957. return;
  5958. }
  5959. pasting = true;
  5960. K('div.' + cls, doc).remove();
  5961. cmd = self.cmd.selection();
  5962. bookmark = cmd.range.createBookmark();
  5963. div = K('<div class="' + cls + '"></div>', doc).css({
  5964. position : 'absolute',
  5965. width : '1px',
  5966. height : '1px',
  5967. overflow : 'hidden',
  5968. left : '-1981px',
  5969. top : K(bookmark.start).pos().y + 'px',
  5970. 'white-space' : 'nowrap'
  5971. });
  5972. K(doc.body).append(div);
  5973. if (_IE) {
  5974. var rng = cmd.range.get(true);
  5975. rng.moveToElementText(div[0]);
  5976. rng.select();
  5977. rng.execCommand('paste');
  5978. e.preventDefault();
  5979. } else {
  5980. cmd.range.selectNodeContents(div[0]);
  5981. cmd.select();
  5982. div[0].tabIndex = -1;
  5983. div[0].focus();
  5984. }
  5985. setTimeout(function() {
  5986. movePastedData();
  5987. pasting = false;
  5988. }, 0);
  5989. });
  5990. });
  5991. self.beforeGetHtml(function(html) {
  5992. if (_IE && _V <= 8) {
  5993. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5994. return unescape(tag);
  5995. });
  5996. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5997. if (!/\s+type="[^"]+"/i.test($0)) {
  5998. return $1 + ' type="text"' + $2;
  5999. }
  6000. return $0;
  6001. });
  6002. }
  6003. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  6004. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  6005. })
  6006. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  6007. var imgAttrs = _getAttrList(full);
  6008. var styles = _getCssList(imgAttrs.style || '');
  6009. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6010. var width = _undef(styles.width, '');
  6011. var height = _undef(styles.height, '');
  6012. if (/px/i.test(width)) {
  6013. width = _removeUnit(width);
  6014. }
  6015. if (/px/i.test(height)) {
  6016. height = _removeUnit(height);
  6017. }
  6018. attrs.width = _undef(imgAttrs.width, width);
  6019. attrs.height = _undef(imgAttrs.height, height);
  6020. return _mediaEmbed(attrs);
  6021. })
  6022. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6023. var imgAttrs = _getAttrList(full);
  6024. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6025. })
  6026. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6027. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6028. })
  6029. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6030. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6031. })
  6032. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6033. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6034. return $1 + _unescape(src) + $2;
  6035. });
  6036. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6037. return full;
  6038. })
  6039. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6040. return start + end;
  6041. });
  6042. });
  6043. self.beforeSetHtml(function(html) {
  6044. if (_IE && _V <= 8) {
  6045. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6046. var attrs = _getAttrList(full);
  6047. var styles = _getCssList(attrs.style || '');
  6048. if (styles.display == 'none') {
  6049. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6050. }
  6051. return full;
  6052. });
  6053. }
  6054. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6055. var attrs = _getAttrList(full);
  6056. attrs.src = _undef(attrs.src, '');
  6057. attrs.width = _undef(attrs.width, 0);
  6058. attrs.height = _undef(attrs.height, 0);
  6059. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6060. })
  6061. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6062. var attrs = _getAttrList(full);
  6063. if (attrs.href !== undefined) {
  6064. return full;
  6065. }
  6066. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6067. })
  6068. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6069. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6070. })
  6071. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6072. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6073. })
  6074. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6075. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6076. return full;
  6077. }
  6078. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6079. return full;
  6080. })
  6081. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6082. return start + 'data-ke-' + end;
  6083. })
  6084. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6085. if (full.indexOf('ke-zeroborder') >= 0) {
  6086. return full;
  6087. }
  6088. return _addClassToTag(full, 'ke-zeroborder');
  6089. });
  6090. });
  6091. });
  6092. })(window);
  6093. /*******************************************************************************
  6094. * KindEditor - WYSIWYG HTML Editor for Internet
  6095. * Copyright (C) 2006-2011 kindsoft.net
  6096. *
  6097. * @author Roddy <luolonghao@gmail.com>
  6098. * @site http://www.kindsoft.net/
  6099. * @licence http://www.kindsoft.net/license.php
  6100. *******************************************************************************/
  6101. KindEditor.lang({
  6102. source : 'HTML代码',
  6103. preview : '预览',
  6104. undo : '后退(Ctrl+Z)',
  6105. redo : '前进(Ctrl+Y)',
  6106. cut : '剪切(Ctrl+X)',
  6107. copy : '复制(Ctrl+C)',
  6108. paste : '粘贴(Ctrl+V)',
  6109. plainpaste : '粘贴为无格式文本',
  6110. wordpaste : '从Word粘贴',
  6111. selectall : '全选(Ctrl+A)',
  6112. justifyleft : '左对齐',
  6113. justifycenter : '居中',
  6114. justifyright : '右对齐',
  6115. justifyfull : '两端对齐',
  6116. insertorderedlist : '编号',
  6117. insertunorderedlist : '项目符号',
  6118. indent : '增加缩进',
  6119. outdent : '减少缩进',
  6120. subscript : '下标',
  6121. superscript : '上标',
  6122. formatblock : '段落',
  6123. fontname : '字体',
  6124. fontsize : '文字大小',
  6125. forecolor : '文字颜色',
  6126. hilitecolor : '文字背景',
  6127. bold : '粗体(Ctrl+B)',
  6128. italic : '斜体(Ctrl+I)',
  6129. underline : '下划线(Ctrl+U)',
  6130. strikethrough : '删除线',
  6131. removeformat : '删除格式',
  6132. image : '图片',
  6133. multiimage : '批量图片上传',
  6134. flash : 'Flash',
  6135. media : '音频',
  6136. table : '表格',
  6137. tablecell : '单元格',
  6138. hr : '插入横线',
  6139. emoticons : '插入表情',
  6140. link : '超级链接',
  6141. unlink : '取消超级链接',
  6142. fullscreen : '全屏显示',
  6143. about : '关于',
  6144. print : '打印(Ctrl+P)',
  6145. filemanager : '文件库',
  6146. code : '插入程序代码',
  6147. map : 'Google地图',
  6148. baidumap : '百度地图',
  6149. lineheight : '行距',
  6150. clearhtml : '清理HTML代码',
  6151. pagebreak : '插入分页符',
  6152. quickformat : '一键排版',
  6153. insertfile : '插入文件',
  6154. template : '插入模板',
  6155. anchor : '锚点',
  6156. yes : '确定',
  6157. no : '取消',
  6158. close : '关闭',
  6159. editImage : '图片属性',
  6160. deleteImage : '删除图片',
  6161. editFlash : 'Flash属性',
  6162. deleteFlash : '删除Flash',
  6163. editMedia : '音频属性',
  6164. deleteMedia : '删除音频',
  6165. editLink : '超级链接属性',
  6166. deleteLink : '取消超级链接',
  6167. editAnchor : '锚点属性',
  6168. deleteAnchor : '删除锚点',
  6169. tableprop : '表格属性',
  6170. tablecellprop : '单元格属性',
  6171. tableinsert : '插入表格',
  6172. tabledelete : '删除表格',
  6173. tablecolinsertleft : '左侧插入列',
  6174. tablecolinsertright : '右侧插入列',
  6175. tablerowinsertabove : '上方插入行',
  6176. tablerowinsertbelow : '下方插入行',
  6177. tablerowmerge : '向下合并单元格',
  6178. tablecolmerge : '向右合并单元格',
  6179. tablerowsplit : '拆分行',
  6180. tablecolsplit : '拆分列',
  6181. tablecoldelete : '删除列',
  6182. tablerowdelete : '删除行',
  6183. noColor : '无颜色',
  6184. pleaseSelectFile : '请选择文件。',
  6185. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6186. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6187. invalidWidth : "宽度必须为数字。",
  6188. invalidHeight : "高度必须为数字。",
  6189. invalidBorder : "边框必须为数字。",
  6190. invalidUrl : "请输入有效的URL地址。",
  6191. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6192. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6193. invalidPadding : '边距必须为数字。',
  6194. invalidSpacing : '间距必须为数字。',
  6195. invalidJson : '服务器发生故障。',
  6196. uploadSuccess : '上传成功。',
  6197. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6198. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6199. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6200. ajaxLoading : '加载中,请稍候 ...',
  6201. uploadLoading : '上传中,请稍候 ...',
  6202. uploadError : '上传错误',
  6203. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6204. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6205. 'code.pleaseInput' : '请输入程序代码。',
  6206. 'link.url' : 'URL',
  6207. 'link.linkType' : '打开类型',
  6208. 'link.newWindow' : '新窗口',
  6209. 'link.selfWindow' : '当前窗口',
  6210. 'flash.url' : 'URL',
  6211. 'flash.width' : '宽度',
  6212. 'flash.height' : '高度',
  6213. 'flash.upload' : '上传',
  6214. 'flash.viewServer' : '文件空间',
  6215. 'media.url' : 'URL',
  6216. 'media.width' : '宽度',
  6217. 'media.height' : '高度',
  6218. 'media.autostart' : '自动播放',
  6219. 'media.upload' : '上传',
  6220. 'media.viewServer' : '文件空间',
  6221. 'image.remoteImage' : '网络图片',
  6222. 'image.localImage' : '本地上传',
  6223. 'image.remoteUrl' : '图片地址',
  6224. 'image.localUrl' : '上传文件',
  6225. 'image.size' : '图片大小',
  6226. 'image.width' : '宽',
  6227. 'image.height' : '高',
  6228. 'image.resetSize' : '重置大小',
  6229. 'image.align' : '对齐方式',
  6230. 'image.defaultAlign' : '默认方式',
  6231. 'image.leftAlign' : '左对齐',
  6232. 'image.rightAlign' : '右对齐',
  6233. 'image.imgTitle' : '图片说明',
  6234. 'image.upload' : '浏览...',
  6235. 'image.viewServer' : '图片空间',
  6236. //'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6237. 'multiimage.uploadDesc' : '',
  6238. 'multiimage.startUpload' : '开始上传',
  6239. 'multiimage.clearAll' : '全部清空',
  6240. 'multiimage.insertAll' : '全部插入',
  6241. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6242. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6243. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6244. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6245. 'multiimage.unknownError' : '发生异常,无法上传。',
  6246. 'multiimage.pending' : '等待上传',
  6247. 'multiimage.uploadError' : '上传失败',
  6248. 'filemanager.emptyFolder' : '空文件夹',
  6249. 'filemanager.moveup' : '移到上一级文件夹',
  6250. 'filemanager.viewType' : '显示方式:',
  6251. 'filemanager.viewImage' : '缩略图',
  6252. 'filemanager.listImage' : '详细信息',
  6253. 'filemanager.orderType' : '排序方式:',
  6254. 'filemanager.fileName' : '名称',
  6255. 'filemanager.fileSize' : '大小',
  6256. 'filemanager.fileType' : '类型',
  6257. 'insertfile.url' : 'URL',
  6258. 'insertfile.title' : '文件说明',
  6259. 'insertfile.upload' : '上传',
  6260. 'insertfile.viewServer' : '文件空间',
  6261. 'table.cells' : '单元格数',
  6262. 'table.rows' : '行数',
  6263. 'table.cols' : '列数',
  6264. 'table.size' : '大小',
  6265. 'table.width' : '宽度',
  6266. 'table.height' : '高度',
  6267. 'table.percent' : '%',
  6268. 'table.px' : 'px',
  6269. 'table.space' : '边距间距',
  6270. 'table.padding' : '边距',
  6271. 'table.spacing' : '间距',
  6272. 'table.align' : '对齐方式',
  6273. 'table.textAlign' : '水平对齐',
  6274. 'table.verticalAlign' : '垂直对齐',
  6275. 'table.alignDefault' : '默认',
  6276. 'table.alignLeft' : '左对齐',
  6277. 'table.alignCenter' : '居中',
  6278. 'table.alignRight' : '右对齐',
  6279. 'table.alignTop' : '顶部',
  6280. 'table.alignMiddle' : '中部',
  6281. 'table.alignBottom' : '底部',
  6282. 'table.alignBaseline' : '基线',
  6283. 'table.border' : '边框',
  6284. 'table.borderWidth' : '边框',
  6285. 'table.borderColor' : '颜色',
  6286. 'table.backgroundColor' : '背景颜色',
  6287. 'map.address' : '地址: ',
  6288. 'map.search' : '搜索',
  6289. 'baidumap.address' : '地址: ',
  6290. 'baidumap.search' : '搜索',
  6291. 'baidumap.insertDynamicMap' : '插入动态地图',
  6292. 'anchor.name' : '锚点名称',
  6293. 'formatblock.formatBlock' : {
  6294. h1 : '标题 1',
  6295. h2 : '标题 2',
  6296. h3 : '标题 3',
  6297. h4 : '标题 4',
  6298. p : '正 文'
  6299. },
  6300. 'fontname.fontName' : {
  6301. 'SimSun' : '宋体',
  6302. 'NSimSun' : '新宋体',
  6303. 'FangSong_GB2312' : '仿宋_GB2312',
  6304. 'KaiTi_GB2312' : '楷体_GB2312',
  6305. 'SimHei' : '黑体',
  6306. 'Microsoft YaHei' : '微软雅黑',
  6307. 'Arial' : 'Arial',
  6308. 'Arial Black' : 'Arial Black',
  6309. 'Times New Roman' : 'Times New Roman',
  6310. 'Courier New' : 'Courier New',
  6311. 'Tahoma' : 'Tahoma',
  6312. 'Verdana' : 'Verdana'
  6313. },
  6314. 'lineheight.lineHeight' : [
  6315. {'1' : '单倍行距'},
  6316. {'1.5' : '1.5倍行距'},
  6317. {'2' : '2倍行距'},
  6318. {'2.5' : '2.5倍行距'},
  6319. {'3' : '3倍行距'}
  6320. ],
  6321. 'template.selectTemplate' : '可选模板',
  6322. 'template.replaceContent' : '替换当前内容',
  6323. 'template.fileList' : {
  6324. '1.html' : '图片和文字',
  6325. '2.html' : '表格',
  6326. '3.html' : '项目编号'
  6327. }
  6328. }, 'zh-CN');
  6329. KindEditor.options.langType = 'zh-CN';
  6330. /*******************************************************************************
  6331. * KindEditor - WYSIWYG HTML Editor for Internet
  6332. * Copyright (C) 2006-2011 kindsoft.net
  6333. *
  6334. * @author Roddy <luolonghao@gmail.com>
  6335. * @site http://www.kindsoft.net/
  6336. * @licence http://www.kindsoft.net/license.php
  6337. *******************************************************************************/
  6338. KindEditor.plugin('anchor', function(K) {
  6339. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6340. self.plugin.anchor = {
  6341. edit : function() {
  6342. var html = ['<div style="padding:20px;">',
  6343. '<div class="ke-dialog-row">',
  6344. '<label for="keName">' + lang.name + '</label>',
  6345. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6346. '</div>',
  6347. '</div>'].join('');
  6348. var dialog = self.createDialog({
  6349. name : name,
  6350. width : 300,
  6351. title : self.lang(name),
  6352. body : html,
  6353. yesBtn : {
  6354. name : self.lang('yes'),
  6355. click : function(e) {
  6356. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6357. }
  6358. }
  6359. });
  6360. var div = dialog.div,
  6361. nameBox = K('input[name="name"]', div);
  6362. var img = self.plugin.getSelectedAnchor();
  6363. if (img) {
  6364. nameBox.val(unescape(img.attr('data-ke-name')));
  6365. }
  6366. nameBox[0].focus();
  6367. nameBox[0].select();
  6368. },
  6369. 'delete' : function() {
  6370. self.plugin.getSelectedAnchor().remove();
  6371. }
  6372. };
  6373. self.clickToolbar(name, self.plugin.anchor.edit);
  6374. });
  6375. /*******************************************************************************
  6376. * KindEditor - WYSIWYG HTML Editor for Internet
  6377. * Copyright (C) 2006-2011 kindsoft.net
  6378. *
  6379. * @author Roddy <luolonghao@gmail.com>
  6380. * @site http://www.kindsoft.net/
  6381. * @licence http://www.kindsoft.net/license.php
  6382. *******************************************************************************/
  6383. KindEditor.plugin('autoheight', function(K) {
  6384. var self = this;
  6385. if (!self.autoHeightMode) {
  6386. return;
  6387. }
  6388. var minHeight;
  6389. function hideScroll() {
  6390. var edit = self.edit;
  6391. var body = edit.doc.body;
  6392. edit.iframe[0].scroll = 'no';
  6393. body.style.overflowY = 'hidden';
  6394. }
  6395. function resetHeight() {
  6396. if(self.fullscreenMode){
  6397. return;
  6398. }
  6399. var edit = self.edit;
  6400. var body = edit.doc.body;
  6401. edit.iframe.height(minHeight);
  6402. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6403. }
  6404. function init() {
  6405. minHeight = K.removeUnit(self.height);
  6406. self.edit.afterChange(resetHeight);
  6407. if(!self.fullscreenMode){
  6408. hideScroll();
  6409. }
  6410. resetHeight();
  6411. }
  6412. if (self.isCreated) {
  6413. init();
  6414. } else {
  6415. self.afterCreate(init);
  6416. }
  6417. });
  6418. /*
  6419. * 如何实现真正的自动高度?
  6420. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6421. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6422. * 由此就实现了真正的自动高度
  6423. * 测试:chrome、firefox、IE9、IE8
  6424. * */
  6425. /*******************************************************************************
  6426. * KindEditor - WYSIWYG HTML Editor for Internet
  6427. * Copyright (C) 2006-2011 kindsoft.net
  6428. *
  6429. * @author Roddy <luolonghao@gmail.com>
  6430. * @site http://www.kindsoft.net/
  6431. * @licence http://www.kindsoft.net/license.php
  6432. *******************************************************************************/
  6433. KindEditor.plugin('baidumap', function(K) {
  6434. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6435. var mapWidth = K.undef(self.mapWidth, 558);
  6436. var mapHeight = K.undef(self.mapHeight, 360);
  6437. self.clickToolbar(name, function() {
  6438. var html = ['<div style="padding:10px 20px;">',
  6439. '<div class="ke-header">',
  6440. '<div class="ke-left">',
  6441. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6442. '<span class="ke-button-common ke-button-outer">',
  6443. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6444. '</span>',
  6445. '</div>',
  6446. '<div class="ke-right">',
  6447. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6448. '</div>',
  6449. '<div class="ke-clearfix"></div>',
  6450. '</div>',
  6451. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6452. '</div>'].join('');
  6453. var dialog = self.createDialog({
  6454. name : name,
  6455. width : mapWidth + 42,
  6456. title : self.lang(name),
  6457. body : html,
  6458. yesBtn : {
  6459. name : self.lang('yes'),
  6460. click : function(e) {
  6461. var map = win.map;
  6462. var centerObj = map.getCenter();
  6463. var center = centerObj.lng + ',' + centerObj.lat;
  6464. var zoom = map.getZoom();
  6465. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6466. '?center=' + encodeURIComponent(center),
  6467. '&zoom=' + encodeURIComponent(zoom),
  6468. '&width=' + mapWidth,
  6469. '&height=' + mapHeight,
  6470. '&markers=' + encodeURIComponent(center),
  6471. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6472. if (checkbox[0].checked) {
  6473. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6474. } else {
  6475. self.exec('insertimage', url);
  6476. }
  6477. self.hideDialog().focus();
  6478. }
  6479. },
  6480. beforeRemove : function() {
  6481. searchBtn.remove();
  6482. if (doc) {
  6483. doc.write('');
  6484. }
  6485. iframe.remove();
  6486. }
  6487. });
  6488. var div = dialog.div,
  6489. addressBox = K('[name="address"]', div),
  6490. searchBtn = K('[name="searchBtn"]', div),
  6491. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6492. win, doc;
  6493. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6494. function ready() {
  6495. win = iframe[0].contentWindow;
  6496. doc = K.iframeDoc(iframe);
  6497. }
  6498. iframe.bind('load', function() {
  6499. iframe.unbind('load');
  6500. if (K.IE) {
  6501. ready();
  6502. } else {
  6503. setTimeout(ready, 0);
  6504. }
  6505. });
  6506. K('.ke-map', div).replaceWith(iframe);
  6507. searchBtn.click(function() {
  6508. win.search(addressBox.val());
  6509. });
  6510. });
  6511. });
  6512. /*******************************************************************************
  6513. * KindEditor - WYSIWYG HTML Editor for Internet
  6514. * Copyright (C) 2006-2011 kindsoft.net
  6515. *
  6516. * @author Roddy <luolonghao@gmail.com>
  6517. * @site http://www.kindsoft.net/
  6518. * @licence http://www.kindsoft.net/license.php
  6519. *******************************************************************************/
  6520. KindEditor.plugin('map', function(K) {
  6521. var self = this, name = 'map', lang = self.lang(name + '.');
  6522. self.clickToolbar(name, function() {
  6523. var html = ['<div style="padding:10px 20px;">',
  6524. '<div class="ke-dialog-row">',
  6525. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6526. '<span class="ke-button-common ke-button-outer">',
  6527. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6528. '</span>',
  6529. '</div>',
  6530. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6531. '</div>'].join('');
  6532. var dialog = self.createDialog({
  6533. name : name,
  6534. width : 600,
  6535. title : self.lang(name),
  6536. body : html,
  6537. yesBtn : {
  6538. name : self.lang('yes'),
  6539. click : function(e) {
  6540. var geocoder = win.geocoder,
  6541. map = win.map,
  6542. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6543. zoom = map.getZoom(),
  6544. maptype = map.getMapTypeId(),
  6545. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6546. url += '?center=' + encodeURIComponent(center);
  6547. url += '&zoom=' + encodeURIComponent(zoom);
  6548. url += '&size=558x360';
  6549. url += '&maptype=' + encodeURIComponent(maptype);
  6550. url += '&markers=' + encodeURIComponent(center);
  6551. url += '&language=' + self.langType;
  6552. url += '&sensor=false';
  6553. self.exec('insertimage', url).hideDialog().focus();
  6554. }
  6555. },
  6556. beforeRemove : function() {
  6557. searchBtn.remove();
  6558. if (doc) {
  6559. doc.write('');
  6560. }
  6561. iframe.remove();
  6562. }
  6563. });
  6564. var div = dialog.div,
  6565. addressBox = K('[name="address"]', div),
  6566. searchBtn = K('[name="searchBtn"]', div),
  6567. win, doc;
  6568. var iframeHtml = ['<!doctype html><html><head>',
  6569. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6570. '<style>',
  6571. ' html { height: 100% }',
  6572. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6573. ' #map_canvas { height: 100% }',
  6574. '</style>',
  6575. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6576. '<script>',
  6577. 'var map, geocoder;',
  6578. 'function initialize() {',
  6579. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6580. ' var options = {',
  6581. ' zoom: 11,',
  6582. ' center: latlng,',
  6583. ' disableDefaultUI: true,',
  6584. ' panControl: true,',
  6585. ' zoomControl: true,',
  6586. ' mapTypeControl: true,',
  6587. ' scaleControl: true,',
  6588. ' streetViewControl: false,',
  6589. ' overviewMapControl: true,',
  6590. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6591. ' };',
  6592. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6593. ' geocoder = new google.maps.Geocoder();',
  6594. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6595. ' if (status == google.maps.GeocoderStatus.OK) {',
  6596. ' if (results[3]) {',
  6597. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6598. ' }',
  6599. ' }',
  6600. ' });',
  6601. '}',
  6602. 'function search(address) {',
  6603. ' if (!map) return;',
  6604. ' geocoder.geocode({address : address}, function(results, status) {',
  6605. ' if (status == google.maps.GeocoderStatus.OK) {',
  6606. ' map.setZoom(11);',
  6607. ' map.setCenter(results[0].geometry.location);',
  6608. ' var marker = new google.maps.Marker({',
  6609. ' map: map,',
  6610. ' position: results[0].geometry.location',
  6611. ' });',
  6612. ' } else {',
  6613. ' alert("Invalid address: " + address);',
  6614. ' }',
  6615. ' });',
  6616. '}',
  6617. '</script>',
  6618. '</head>',
  6619. '<body onload="initialize();">',
  6620. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6621. '</body></html>'].join('\n');
  6622. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6623. function ready() {
  6624. win = iframe[0].contentWindow;
  6625. doc = K.iframeDoc(iframe);
  6626. }
  6627. iframe.bind('load', function() {
  6628. iframe.unbind('load');
  6629. if (K.IE) {
  6630. ready();
  6631. } else {
  6632. setTimeout(ready, 0);
  6633. }
  6634. });
  6635. K('.ke-map', div).replaceWith(iframe);
  6636. searchBtn.click(function() {
  6637. win.search(addressBox.val());
  6638. });
  6639. });
  6640. });
  6641. /*******************************************************************************
  6642. * KindEditor - WYSIWYG HTML Editor for Internet
  6643. * Copyright (C) 2006-2011 kindsoft.net
  6644. *
  6645. * @author Roddy <luolonghao@gmail.com>
  6646. * @site http://www.kindsoft.net/
  6647. * @licence http://www.kindsoft.net/license.php
  6648. *******************************************************************************/
  6649. KindEditor.plugin('clearhtml', function(K) {
  6650. var self = this, name = 'clearhtml';
  6651. self.clickToolbar(name, function() {
  6652. self.focus();
  6653. var html = self.html();
  6654. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6655. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6656. html = K.formatHtml(html, {
  6657. a : ['href', 'target'],
  6658. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6659. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6660. table : ['border'],
  6661. 'td,th' : ['rowspan', 'colspan'],
  6662. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6663. });
  6664. self.html(html);
  6665. self.cmd.selection(true);
  6666. self.addBookmark();
  6667. });
  6668. });
  6669. /*******************************************************************************
  6670. * KindEditor - WYSIWYG HTML Editor for Internet
  6671. * Copyright (C) 2006-2011 kindsoft.net
  6672. *
  6673. * @author Roddy <luolonghao@gmail.com>
  6674. * @site http://www.kindsoft.net/
  6675. * @licence http://www.kindsoft.net/license.php
  6676. *******************************************************************************/
  6677. KindEditor.plugin('code', function(K) {
  6678. var self = this, name = 'code';
  6679. self.clickToolbar(name, function() {
  6680. var lang = self.lang(name + '.'),
  6681. html = ['<div style="padding:10px 20px;">',
  6682. '<div class="ke-dialog-row">',
  6683. '<select class="ke-code-type">',
  6684. '<option value="js">JavaScript</option>',
  6685. '<option value="html">HTML</option>',
  6686. '<option value="css">CSS</option>',
  6687. '<option value="php">PHP</option>',
  6688. '<option value="pl">Perl</option>',
  6689. '<option value="py">Python</option>',
  6690. '<option value="rb">Ruby</option>',
  6691. '<option value="java">Java</option>',
  6692. '<option value="vb">ASP/VB</option>',
  6693. '<option value="cpp">C/C++</option>',
  6694. '<option value="cs">C#</option>',
  6695. '<option value="xml">XML</option>',
  6696. '<option value="bsh">Shell</option>',
  6697. '<option value="">Other</option>',
  6698. '</select>',
  6699. '</div>',
  6700. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6701. '</div>'].join(''),
  6702. dialog = self.createDialog({
  6703. name : name,
  6704. width : 450,
  6705. title : self.lang(name),
  6706. body : html,
  6707. yesBtn : {
  6708. name : self.lang('yes'),
  6709. click : function(e) {
  6710. var type = K('.ke-code-type', dialog.div).val(),
  6711. code = textarea.val(),
  6712. cls = type === '' ? '' : ' lang-' + type,
  6713. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6714. if (K.trim(code) === '') {
  6715. alert(lang.pleaseInput);
  6716. textarea[0].focus();
  6717. return;
  6718. }
  6719. self.insertHtml(html).hideDialog().focus();
  6720. }
  6721. }
  6722. }),
  6723. textarea = K('textarea', dialog.div);
  6724. textarea[0].focus();
  6725. });
  6726. });
  6727. /*******************************************************************************
  6728. * KindEditor - WYSIWYG HTML Editor for Internet
  6729. * Copyright (C) 2006-2011 kindsoft.net
  6730. *
  6731. * @author Roddy <luolonghao@gmail.com>
  6732. * @site http://www.kindsoft.net/
  6733. * @licence http://www.kindsoft.net/license.php
  6734. *******************************************************************************/
  6735. KindEditor.plugin('emoticons', function(K) {
  6736. var self = this, name = 'emoticons',
  6737. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6738. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6739. currentPageNum = 1;
  6740. self.clickToolbar(name, function() {
  6741. var rows = 5, cols = 9, total = 135, startNum = 0,
  6742. cells = rows * cols, pages = Math.ceil(total / cells),
  6743. colsHalf = Math.floor(cols / 2),
  6744. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6745. elements = [],
  6746. menu = self.createMenu({
  6747. name : name,
  6748. beforeRemove : function() {
  6749. removeEvent();
  6750. }
  6751. });
  6752. menu.div.append(wrapperDiv);
  6753. var previewDiv, previewImg;
  6754. if (allowPreview) {
  6755. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6756. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6757. wrapperDiv.append(previewDiv);
  6758. previewDiv.append(previewImg);
  6759. }
  6760. function bindCellEvent(cell, j, num) {
  6761. if (previewDiv) {
  6762. cell.mouseover(function() {
  6763. if (j > colsHalf) {
  6764. previewDiv.css('left', 0);
  6765. previewDiv.css('right', '');
  6766. } else {
  6767. previewDiv.css('left', '');
  6768. previewDiv.css('right', 0);
  6769. }
  6770. previewImg.attr('src', path + num + '.gif');
  6771. K(this).addClass('ke-on');
  6772. });
  6773. } else {
  6774. cell.mouseover(function() {
  6775. K(this).addClass('ke-on');
  6776. });
  6777. }
  6778. cell.mouseout(function() {
  6779. K(this).removeClass('ke-on');
  6780. });
  6781. cell.click(function(e) {
  6782. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6783. e.stop();
  6784. });
  6785. }
  6786. function createEmoticonsTable(pageNum, parentDiv) {
  6787. var table = document.createElement('table');
  6788. parentDiv.append(table);
  6789. if (previewDiv) {
  6790. K(table).mouseover(function() {
  6791. previewDiv.show('block');
  6792. });
  6793. K(table).mouseout(function() {
  6794. previewDiv.hide();
  6795. });
  6796. elements.push(K(table));
  6797. }
  6798. table.className = 'ke-table';
  6799. table.cellPadding = 0;
  6800. table.cellSpacing = 0;
  6801. table.border = 0;
  6802. var num = (pageNum - 1) * cells + startNum;
  6803. for (var i = 0; i < rows; i++) {
  6804. var row = table.insertRow(i);
  6805. for (var j = 0; j < cols; j++) {
  6806. var cell = K(row.insertCell(j));
  6807. cell.addClass('ke-cell');
  6808. bindCellEvent(cell, j, num);
  6809. var span = K('<span class="ke-img"></span>')
  6810. .css('background-position', '-' + (24 * num) + 'px 0px')
  6811. .css('background-image', 'url(' + path + 'static.gif)');
  6812. cell.append(span);
  6813. elements.push(cell);
  6814. num++;
  6815. }
  6816. }
  6817. return table;
  6818. }
  6819. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6820. function removeEvent() {
  6821. K.each(elements, function() {
  6822. this.unbind();
  6823. });
  6824. }
  6825. var pageDiv;
  6826. function bindPageEvent(el, pageNum) {
  6827. el.click(function(e) {
  6828. removeEvent();
  6829. table.parentNode.removeChild(table);
  6830. pageDiv.remove();
  6831. table = createEmoticonsTable(pageNum, wrapperDiv);
  6832. createPageTable(pageNum);
  6833. currentPageNum = pageNum;
  6834. e.stop();
  6835. });
  6836. }
  6837. function createPageTable(currentPageNum) {
  6838. pageDiv = K('<div class="ke-page"></div>');
  6839. wrapperDiv.append(pageDiv);
  6840. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6841. if (currentPageNum !== pageNum) {
  6842. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6843. bindPageEvent(a, pageNum);
  6844. pageDiv.append(a);
  6845. elements.push(a);
  6846. } else {
  6847. pageDiv.append(K('@[' + pageNum + ']'));
  6848. }
  6849. pageDiv.append(K('@&nbsp;'));
  6850. }
  6851. }
  6852. createPageTable(currentPageNum);
  6853. });
  6854. });
  6855. /*******************************************************************************
  6856. * KindEditor - WYSIWYG HTML Editor for Internet
  6857. * Copyright (C) 2006-2011 kindsoft.net
  6858. *
  6859. * @author Roddy <luolonghao@gmail.com>
  6860. * @site http://www.kindsoft.net/
  6861. * @licence http://www.kindsoft.net/license.php
  6862. *******************************************************************************/
  6863. KindEditor.plugin('filemanager', function(K) {
  6864. var self = this, name = 'filemanager',
  6865. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6866. imgPath = self.pluginsPath + name + '/images/',
  6867. lang = self.lang(name + '.');
  6868. function makeFileTitle(filename, filesize, datetime) {
  6869. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6870. }
  6871. function bindTitle(el, data) {
  6872. if (data.is_dir) {
  6873. el.attr('title', data.filename);
  6874. } else {
  6875. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6876. }
  6877. }
  6878. self.plugin.filemanagerDialog = function(options) {
  6879. var width = K.undef(options.width, 650),
  6880. height = K.undef(options.height, 510),
  6881. dirName = K.undef(options.dirName, ''),
  6882. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6883. clickFn = options.clickFn;
  6884. var html = [
  6885. '<div style="padding:10px 20px;">',
  6886. '<div class="ke-plugin-filemanager-header">',
  6887. '<div class="ke-left">',
  6888. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6889. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6890. '</div>',
  6891. '<div class="ke-right">',
  6892. '标签 <input type="text" style="width:100px;" value="" name="viewTag">',
  6893. '分类 <select class="ke-inline-block" name="viewCate">',
  6894. '',
  6895. '</select> ',
  6896. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6897. '<option value="VIEW">' + lang.viewImage + '</option>',
  6898. '<option value="LIST">' + lang.listImage + '</option>',
  6899. '</select> ',
  6900. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6901. '<option value="NAME">' + lang.fileName + '</option>',
  6902. '<option value="SIZE">' + lang.fileSize + '</option>',
  6903. '<option value="TYPE">' + lang.fileType + '</option>',
  6904. '</select>',
  6905. '</div>',
  6906. '<div class="ke-clearfix"></div>',
  6907. '</div>',
  6908. '<div class="ke-plugin-filemanager-body"></div>',
  6909. '</div>'
  6910. ].join('');
  6911. var dialog = self.createDialog({
  6912. name : name,
  6913. width : width,
  6914. height : height,
  6915. title : self.lang(name),
  6916. body : html
  6917. }),
  6918. div = dialog.div,
  6919. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6920. moveupImg = K('[name="moveupImg"]', div),
  6921. moveupLink = K('[name="moveupLink"]', div),
  6922. viewServerBtn = K('[name="viewServer"]', div),
  6923. viewCateBox = K('[name="viewCate"]', div),
  6924. viewTagBox = K('[name="viewTag"]', div),
  6925. viewTypeBox = K('[name="viewType"]', div),
  6926. orderTypeBox = K('[name="orderType"]', div);
  6927. function reloadPage(path, order, func, cate, tag) {
  6928. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6929. if (cate) {
  6930. param += '&cate=' + cate;
  6931. }
  6932. if (tag) {
  6933. param += '&tag=' + tag;
  6934. }
  6935. dialog.showLoading(self.lang('ajaxLoading'));
  6936. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6937. dialog.hideLoading();
  6938. func(data);
  6939. });
  6940. }
  6941. var elList = [];
  6942. function bindEvent(el, result, data, createFunc) {
  6943. var fileUrl = K.formatUrl(result.current_url + data.file, 'absolute'),
  6944. dirPath = encodeURIComponent(result.current_dir_path + data.path + '/');
  6945. if (data.is_dir) {
  6946. el.click(function(e) {
  6947. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6948. });
  6949. } else if (data.is_photo) {
  6950. el.click(function(e) {
  6951. clickFn.call(this, fileUrl, data.file);
  6952. });
  6953. } else {
  6954. el.click(function(e) {
  6955. clickFn.call(this, fileUrl, data.file);
  6956. });
  6957. }
  6958. elList.push(el);
  6959. }
  6960. function createCommon(result, createFunc) {
  6961. K.each(elList, function() {
  6962. this.unbind();
  6963. });
  6964. moveupLink.unbind();
  6965. viewTypeBox.unbind();
  6966. orderTypeBox.unbind();
  6967. if (result.current_dir_path) {
  6968. moveupLink.click(function(e) {
  6969. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6970. });
  6971. }
  6972. function changeFunc() {
  6973. if (viewTypeBox.val() == 'VIEW') {
  6974. reloadPage(result.current_dir_path, orderTypeBox.val(), createView, viewCateBox.val(), viewTagBox.val());
  6975. } else {
  6976. reloadPage(result.current_dir_path, orderTypeBox.val(), createList, viewCateBox.val(), viewTagBox.val());
  6977. }
  6978. }
  6979. viewTypeBox.change(changeFunc);
  6980. orderTypeBox.change(changeFunc);
  6981. viewCateBox.change(changeFunc);
  6982. bodyDiv.html('');
  6983. }
  6984. function createList(result) {
  6985. createCommon(result, createList);
  6986. var table = document.createElement('table');
  6987. table.className = 'ke-table';
  6988. table.cellPadding = 0;
  6989. table.cellSpacing = 0;
  6990. table.border = 0;
  6991. bodyDiv.append(table);
  6992. var fileList = result.file_list;
  6993. for (var i = 0, len = fileList.length; i < len; i++) {
  6994. var data = fileList[i], row = K(table.insertRow(i));
  6995. row.mouseover(function(e) {
  6996. K(this).addClass('ke-on');
  6997. })
  6998. .mouseout(function(e) {
  6999. K(this).removeClass('ke-on');
  7000. });
  7001. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  7002. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  7003. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  7004. if (!data.is_dir || data.has_file) {
  7005. row.css('cursor', 'pointer');
  7006. cell0.attr('title', data.filename);
  7007. bindEvent(cell0, result, data, createList);
  7008. } else {
  7009. cell0.attr('title', lang.emptyFolder);
  7010. }
  7011. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  7012. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  7013. }
  7014. }
  7015. function createView(result) {
  7016. createCommon(result, createView);
  7017. var fileList = result.file_list;
  7018. for (var i = 0, len = fileList.length; i < len; i++) {
  7019. var data = fileList[i],
  7020. div = K('<div class="ke-inline-block ke-item"></div>');
  7021. bodyDiv.append(div);
  7022. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7023. .mouseover(function(e) {
  7024. K(this).addClass('ke-on');
  7025. })
  7026. .mouseout(function(e) {
  7027. K(this).removeClass('ke-on');
  7028. });
  7029. div.append(photoDiv);
  7030. var fileUrl = result.current_url + data.file,
  7031. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7032. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7033. if (!data.is_dir || data.has_file) {
  7034. photoDiv.css('cursor', 'pointer');
  7035. bindTitle(photoDiv, data);
  7036. bindEvent(photoDiv, result, data, createView);
  7037. } else {
  7038. photoDiv.attr('title', lang.emptyFolder);
  7039. }
  7040. photoDiv.append(img);
  7041. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7042. }
  7043. }
  7044. viewTypeBox.val(viewType);
  7045. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7046. return dialog;
  7047. }
  7048. });
  7049. /*******************************************************************************
  7050. * KindEditor - WYSIWYG HTML Editor for Internet
  7051. * Copyright (C) 2006-2011 kindsoft.net
  7052. *
  7053. * @author Roddy <luolonghao@gmail.com>
  7054. * @site http://www.kindsoft.net/
  7055. * @licence http://www.kindsoft.net/license.php
  7056. *******************************************************************************/
  7057. KindEditor.plugin('flash', function(K) {
  7058. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7059. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7060. allowFileManager = K.undef(self.allowFileManager, false),
  7061. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7062. extraParams = K.undef(self.extraFileUploadParams, {}),
  7063. filePostName = K.undef(self.filePostName, 'imgFile'),
  7064. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7065. self.plugin.flash = {
  7066. edit : function() {
  7067. var html = [
  7068. '<div style="padding:20px;">',
  7069. '<div class="ke-dialog-row">',
  7070. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7071. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7072. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7073. '<span class="ke-button-common ke-button-outer">',
  7074. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7075. '</span>',
  7076. '</div>',
  7077. '<div class="ke-dialog-row">',
  7078. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7079. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7080. '</div>',
  7081. '<div class="ke-dialog-row">',
  7082. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7083. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7084. '</div>',
  7085. '</div>'
  7086. ].join('');
  7087. var dialog = self.createDialog({
  7088. name : name,
  7089. width : 450,
  7090. title : self.lang(name),
  7091. body : html,
  7092. yesBtn : {
  7093. name : self.lang('yes'),
  7094. click : function(e) {
  7095. var url = K.trim(urlBox.val()),
  7096. width = widthBox.val(),
  7097. height = heightBox.val();
  7098. if (url == 'http://' || K.invalidUrl(url)) {
  7099. alert(self.lang('invalidUrl'));
  7100. urlBox[0].focus();
  7101. return;
  7102. }
  7103. if (!/^\d*$/.test(width)) {
  7104. alert(self.lang('invalidWidth'));
  7105. widthBox[0].focus();
  7106. return;
  7107. }
  7108. if (!/^\d*$/.test(height)) {
  7109. alert(self.lang('invalidHeight'));
  7110. heightBox[0].focus();
  7111. return;
  7112. }
  7113. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7114. src : url,
  7115. type : K.mediaType('.swf'),
  7116. width : width,
  7117. height : height,
  7118. quality : 'high'
  7119. });
  7120. self.insertHtml(html).hideDialog().focus();
  7121. }
  7122. }
  7123. }),
  7124. div = dialog.div,
  7125. urlBox = K('[name="url"]', div),
  7126. viewServerBtn = K('[name="viewServer"]', div),
  7127. widthBox = K('[name="width"]', div),
  7128. heightBox = K('[name="height"]', div);
  7129. urlBox.val('http://');
  7130. if (allowFlashUpload) {
  7131. var uploadbutton = K.uploadbutton({
  7132. button : K('.ke-upload-button', div)[0],
  7133. fieldName : filePostName,
  7134. extraParams : extraParams,
  7135. url : K.addParam(uploadJson, 'dir=flash'),
  7136. afterUpload : function(data) {
  7137. dialog.hideLoading();
  7138. if (data.error === 0) {
  7139. var url = data.url;
  7140. if (formatUploadUrl) {
  7141. url = K.formatUrl(url, 'absolute');
  7142. }
  7143. urlBox.val(url);
  7144. if (self.afterUpload) {
  7145. self.afterUpload.call(self, url, data, name);
  7146. }
  7147. alert(self.lang('uploadSuccess'));
  7148. } else {
  7149. alert(data.message);
  7150. }
  7151. },
  7152. afterError : function(html) {
  7153. dialog.hideLoading();
  7154. self.errorDialog(html);
  7155. }
  7156. });
  7157. uploadbutton.fileBox.change(function(e) {
  7158. dialog.showLoading(self.lang('uploadLoading'));
  7159. uploadbutton.submit();
  7160. });
  7161. } else {
  7162. K('.ke-upload-button', div).hide();
  7163. }
  7164. if (allowFileManager) {
  7165. viewServerBtn.click(function(e) {
  7166. var clickFn = function(url, title, id) {
  7167. K('[name="url"]', div).val(url);
  7168. if (self.afterSelectFile) {
  7169. self.afterSelectFile.call(self, url);
  7170. }
  7171. };
  7172. var cur = K('[name="url"]', div).val();
  7173. editorShowUpload(cur, self.fileManagerJson, 'flash库', clickFn, this);
  7174. /*
  7175. self.loadPlugin('filemanager', function() {
  7176. self.plugin.filemanagerDialog({
  7177. viewType : 'LIST',
  7178. dirName : 'flash',
  7179. clickFn : function(url, title) {
  7180. if (self.dialogs.length > 1) {
  7181. K('[name="url"]', div).val(url);
  7182. if (self.afterSelectFile) {
  7183. self.afterSelectFile.call(self, url);
  7184. }
  7185. self.hideDialog();
  7186. }
  7187. }
  7188. });
  7189. });
  7190. */
  7191. });
  7192. } else {
  7193. viewServerBtn.hide();
  7194. }
  7195. var img = self.plugin.getSelectedFlash();
  7196. if (img) {
  7197. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7198. urlBox.val(attrs.src);
  7199. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7200. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7201. }
  7202. urlBox[0].focus();
  7203. urlBox[0].select();
  7204. },
  7205. 'delete' : function() {
  7206. self.plugin.getSelectedFlash().remove();
  7207. self.addBookmark();
  7208. }
  7209. };
  7210. self.clickToolbar(name, self.plugin.flash.edit);
  7211. });
  7212. /*******************************************************************************
  7213. * KindEditor - WYSIWYG HTML Editor for Internet
  7214. * Copyright (C) 2006-2011 kindsoft.net
  7215. *
  7216. * @author Roddy <luolonghao@gmail.com>
  7217. * @site http://www.kindsoft.net/
  7218. * @licence http://www.kindsoft.net/license.php
  7219. *******************************************************************************/
  7220. KindEditor.plugin('image', function(K) {
  7221. var self = this, name = 'image',
  7222. allowImageUpload = K.undef(self.allowImageUpload, true),
  7223. allowImageRemote = K.undef(self.allowImageRemote, true),
  7224. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7225. allowFileManager = K.undef(self.allowFileManager, false),
  7226. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7227. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7228. imgPath = self.pluginsPath + 'image/images/',
  7229. extraParams = K.undef(self.extraFileUploadParams, {}),
  7230. filePostName = K.undef(self.filePostName, 'imgFile'),
  7231. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7232. lang = self.lang(name + '.');
  7233. self.plugin.imageDialog = function(options) {
  7234. var imageUrl = options.imageUrl,
  7235. imageWidth = K.undef(options.imageWidth, ''),
  7236. imageHeight = K.undef(options.imageHeight, ''),
  7237. imageTitle = K.undef(options.imageTitle, ''),
  7238. imageAlign = K.undef(options.imageAlign, ''),
  7239. showRemote = K.undef(options.showRemote, true),
  7240. showLocal = K.undef(options.showLocal, true),
  7241. tabIndex = K.undef(options.tabIndex, 0),
  7242. clickFn = options.clickFn;
  7243. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7244. var hiddenElements = [];
  7245. for(var k in extraParams){
  7246. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7247. }
  7248. var html = [
  7249. '<div style="padding:20px;">',
  7250. '<div class="tabs"></div>',
  7251. '<div class="tab1" style="display:none;">',
  7252. '<div class="ke-dialog-row">',
  7253. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7254. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7255. '<span class="ke-button-common ke-button-outer">',
  7256. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7257. '</span>',
  7258. '</div>',
  7259. '<div class="ke-dialog-row">',
  7260. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7261. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7262. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7263. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7264. '</div>',
  7265. '<div class="ke-dialog-row">',
  7266. '<label style="width:60px;">' + lang.align + '</label>',
  7267. '<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="" />',
  7268. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7269. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7270. '</div>',
  7271. '<div class="ke-dialog-row">',
  7272. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7273. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7274. '</div>',
  7275. '</div>',
  7276. '<div class="tab2" style="display:none;">',
  7277. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7278. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7279. '<div class="ke-dialog-row">',
  7280. hiddenElements.join(''),
  7281. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7282. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7283. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7284. '</div>',
  7285. '</form>',
  7286. '</div>',
  7287. '</div>'
  7288. ].join('');
  7289. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7290. dialogHeight = showLocal && showRemote ? 300 : 250;
  7291. var dialog = self.createDialog({
  7292. name : name,
  7293. width : dialogWidth,
  7294. height : dialogHeight,
  7295. title : self.lang(name),
  7296. body : html,
  7297. yesBtn : {
  7298. name : self.lang('yes'),
  7299. click : function(e) {
  7300. if (dialog.isLoading) {
  7301. return;
  7302. }
  7303. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7304. if (uploadbutton.fileBox.val() == '') {
  7305. alert(self.lang('pleaseSelectFile'));
  7306. return;
  7307. }
  7308. dialog.showLoading(self.lang('uploadLoading'));
  7309. uploadbutton.submit();
  7310. localUrlBox.val('');
  7311. return;
  7312. }
  7313. var url = K.trim(urlBox.val()),
  7314. width = widthBox.val(),
  7315. height = heightBox.val(),
  7316. title = titleBox.val(),
  7317. align = '';
  7318. alignBox.each(function() {
  7319. if (this.checked) {
  7320. align = this.value;
  7321. return false;
  7322. }
  7323. });
  7324. if (url == 'http://' || K.invalidUrl(url)) {
  7325. alert(self.lang('invalidUrl'));
  7326. urlBox[0].focus();
  7327. return;
  7328. }
  7329. if (!/^\d*$/.test(width)) {
  7330. alert(self.lang('invalidWidth'));
  7331. widthBox[0].focus();
  7332. return;
  7333. }
  7334. if (!/^\d*$/.test(height)) {
  7335. alert(self.lang('invalidHeight'));
  7336. heightBox[0].focus();
  7337. return;
  7338. }
  7339. clickFn.call(self, url, title, width, height, 0, align);
  7340. }
  7341. },
  7342. beforeRemove : function() {
  7343. viewServerBtn.unbind();
  7344. widthBox.unbind();
  7345. heightBox.unbind();
  7346. refreshBtn.unbind();
  7347. }
  7348. }),
  7349. div = dialog.div;
  7350. var urlBox = K('[name="url"]', div),
  7351. localUrlBox = K('[name="localUrl"]', div),
  7352. viewServerBtn = K('[name="viewServer"]', div),
  7353. widthBox = K('.tab1 [name="width"]', div),
  7354. heightBox = K('.tab1 [name="height"]', div),
  7355. refreshBtn = K('.ke-refresh-btn', div),
  7356. titleBox = K('.tab1 [name="title"]', div),
  7357. alignBox = K('.tab1 [name="align"]', div);
  7358. var tabs;
  7359. if (showRemote && showLocal) {
  7360. tabs = K.tabs({
  7361. src : K('.tabs', div),
  7362. afterSelect : function(i) {}
  7363. });
  7364. tabs.add({
  7365. title : lang.remoteImage,
  7366. panel : K('.tab1', div)
  7367. });
  7368. tabs.add({
  7369. title : lang.localImage,
  7370. panel : K('.tab2', div)
  7371. });
  7372. tabs.select(1);
  7373. } else if (showRemote) {
  7374. K('.tab1', div).show();
  7375. } else if (showLocal) {
  7376. K('.tab2', div).show();
  7377. }
  7378. var uploadbutton = K.uploadbutton({
  7379. button : K('.ke-upload-button', div)[0],
  7380. fieldName : filePostName,
  7381. form : K('.ke-form', div),
  7382. target : target,
  7383. width: 60,
  7384. afterUpload : function(data) {
  7385. dialog.hideLoading();
  7386. if (data.error === 0) {
  7387. var url = data.url;
  7388. if (formatUploadUrl) {
  7389. url = K.formatUrl(url, 'absolute');
  7390. }
  7391. if (self.afterUpload) {
  7392. self.afterUpload.call(self, url, data, name);
  7393. }
  7394. if (!fillDescAfterUploadImage) {
  7395. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7396. } else {
  7397. K(".ke-dialog-row #remoteUrl", div).val(url);
  7398. K(".ke-tabs-li", div)[0].click();
  7399. K(".ke-refresh-btn", div).click();
  7400. }
  7401. } else {
  7402. alert(data.message);
  7403. }
  7404. },
  7405. afterError : function(html) {
  7406. dialog.hideLoading();
  7407. self.errorDialog(html);
  7408. }
  7409. });
  7410. uploadbutton.fileBox.change(function(e) {
  7411. localUrlBox.val(uploadbutton.fileBox.val());
  7412. });
  7413. if (allowFileManager) {
  7414. viewServerBtn.click(function(e) {
  7415. //clickFn.call(this, fileUrl, data.file);
  7416. var clickFn = function(url, title, id) {
  7417. K('[name="url"]', div).val(url);
  7418. if (self.afterSelectFile) {
  7419. self.afterSelectFile.call(self, url);
  7420. }
  7421. };
  7422. var cur = K('[name="url"]', div).val();
  7423. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  7424. /*
  7425. self.loadPlugin('filemanager', function() {
  7426. self.plugin.filemanagerDialog({
  7427. viewType : 'VIEW',
  7428. dirName : 'image',
  7429. clickFn : function(url, title) {
  7430. if (self.dialogs.length > 1) {
  7431. K('[name="url"]', div).val(url);
  7432. if (self.afterSelectFile) {
  7433. self.afterSelectFile.call(self, url);
  7434. }
  7435. self.hideDialog();
  7436. }
  7437. }
  7438. });
  7439. });
  7440. */
  7441. });
  7442. } else {
  7443. viewServerBtn.hide();
  7444. }
  7445. var originalWidth = 0, originalHeight = 0;
  7446. function setSize(width, height) {
  7447. widthBox.val(width);
  7448. heightBox.val(height);
  7449. originalWidth = width;
  7450. originalHeight = height;
  7451. }
  7452. refreshBtn.click(function(e) {
  7453. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7454. position : 'absolute',
  7455. visibility : 'hidden',
  7456. top : 0,
  7457. left : '-1000px'
  7458. });
  7459. tempImg.bind('load', function() {
  7460. setSize(tempImg.width(), tempImg.height());
  7461. tempImg.remove();
  7462. });
  7463. K(document.body).append(tempImg);
  7464. });
  7465. widthBox.change(function(e) {
  7466. if (originalWidth > 0) {
  7467. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7468. }
  7469. });
  7470. heightBox.change(function(e) {
  7471. if (originalHeight > 0) {
  7472. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7473. }
  7474. });
  7475. urlBox.val(options.imageUrl);
  7476. setSize(options.imageWidth, options.imageHeight);
  7477. titleBox.val(options.imageTitle);
  7478. alignBox.each(function() {
  7479. if (this.value === options.imageAlign) {
  7480. this.checked = true;
  7481. return false;
  7482. }
  7483. });
  7484. if (showRemote && tabIndex === 0) {
  7485. urlBox[0].focus();
  7486. urlBox[0].select();
  7487. }
  7488. return dialog;
  7489. };
  7490. self.plugin.image = {
  7491. edit : function() {
  7492. var img = self.plugin.getSelectedImage();
  7493. self.plugin.imageDialog({
  7494. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7495. imageWidth : img ? img.width() : '',
  7496. imageHeight : img ? img.height() : '',
  7497. imageTitle : img ? img.attr('title') : '',
  7498. imageAlign : img ? img.attr('align') : '',
  7499. showRemote : allowImageRemote,
  7500. showLocal : allowImageUpload,
  7501. tabIndex: img ? 0 : imageTabIndex,
  7502. clickFn : function(url, title, width, height, border, align) {
  7503. if (img) {
  7504. img.attr('src', url);
  7505. img.attr('data-ke-src', url);
  7506. img.attr('width', width);
  7507. img.attr('height', height);
  7508. img.attr('title', title);
  7509. img.attr('align', align);
  7510. img.attr('alt', title);
  7511. } else {
  7512. self.exec('insertimage', url, title, width, height, border, align);
  7513. }
  7514. setTimeout(function() {
  7515. self.hideDialog().focus();
  7516. }, 0);
  7517. }
  7518. });
  7519. },
  7520. 'delete' : function() {
  7521. var target = self.plugin.getSelectedImage();
  7522. if (target.parent().name == 'a') {
  7523. target = target.parent();
  7524. }
  7525. target.remove();
  7526. self.addBookmark();
  7527. }
  7528. };
  7529. self.clickToolbar(name, self.plugin.image.edit);
  7530. });
  7531. /*******************************************************************************
  7532. * KindEditor - WYSIWYG HTML Editor for Internet
  7533. * Copyright (C) 2006-2011 kindsoft.net
  7534. *
  7535. * @author Roddy <luolonghao@gmail.com>
  7536. * @site http://www.kindsoft.net/
  7537. * @licence http://www.kindsoft.net/license.php
  7538. *******************************************************************************/
  7539. KindEditor.plugin('insertfile', function(K) {
  7540. var self = this, name = 'insertfile',
  7541. allowFileUpload = K.undef(self.allowFileUpload, true),
  7542. allowFileManager = K.undef(self.allowFileManager, false),
  7543. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7544. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7545. extraParams = K.undef(self.extraFileUploadParams, {}),
  7546. filePostName = K.undef(self.filePostName, 'imgFile'),
  7547. lang = self.lang(name + '.');
  7548. self.plugin.fileDialog = function(options) {
  7549. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7550. fileTitle = K.undef(options.fileTitle, ''),
  7551. clickFn = options.clickFn;
  7552. var html = [
  7553. '<div style="padding:20px;">',
  7554. '<div class="ke-dialog-row">',
  7555. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7556. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7557. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7558. '<span class="ke-button-common ke-button-outer">',
  7559. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7560. '</span>',
  7561. '</div>',
  7562. '<div class="ke-dialog-row">',
  7563. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7564. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7565. '</div>',
  7566. '</form>',
  7567. '</div>'
  7568. ].join('');
  7569. var dialog = self.createDialog({
  7570. name : name,
  7571. width : 450,
  7572. title : self.lang(name),
  7573. body : html,
  7574. yesBtn : {
  7575. name : self.lang('yes'),
  7576. click : function(e) {
  7577. var url = K.trim(urlBox.val()),
  7578. title = titleBox.val();
  7579. if (url == 'http://' || K.invalidUrl(url)) {
  7580. alert(self.lang('invalidUrl'));
  7581. urlBox[0].focus();
  7582. return;
  7583. }
  7584. if (K.trim(title) === '') {
  7585. title = url;
  7586. }
  7587. clickFn.call(self, url, title);
  7588. }
  7589. }
  7590. }),
  7591. div = dialog.div;
  7592. var urlBox = K('[name="url"]', div),
  7593. viewServerBtn = K('[name="viewServer"]', div),
  7594. titleBox = K('[name="title"]', div);
  7595. if (allowFileUpload) {
  7596. var uploadbutton = K.uploadbutton({
  7597. button : K('.ke-upload-button', div)[0],
  7598. fieldName : filePostName,
  7599. url : K.addParam(uploadJson, 'dir=file'),
  7600. extraParams : extraParams,
  7601. afterUpload : function(data) {
  7602. dialog.hideLoading();
  7603. if (data.error === 0) {
  7604. var url = data.url;
  7605. if (formatUploadUrl) {
  7606. url = K.formatUrl(url, 'absolute');
  7607. }
  7608. urlBox.val(url);
  7609. if (self.afterUpload) {
  7610. self.afterUpload.call(self, url, data, name);
  7611. }
  7612. alert(self.lang('uploadSuccess'));
  7613. } else {
  7614. alert(data.message);
  7615. }
  7616. },
  7617. afterError : function(html) {
  7618. dialog.hideLoading();
  7619. self.errorDialog(html);
  7620. }
  7621. });
  7622. uploadbutton.fileBox.change(function(e) {
  7623. dialog.showLoading(self.lang('uploadLoading'));
  7624. uploadbutton.submit();
  7625. });
  7626. } else {
  7627. K('.ke-upload-button', div).hide();
  7628. }
  7629. if (allowFileManager) {
  7630. viewServerBtn.click(function(e) {
  7631. var clickFn = function(url, title, id) {
  7632. K('[name="url"]', div).val(url);
  7633. if (self.afterSelectFile) {
  7634. self.afterSelectFile.call(self, url);
  7635. }
  7636. };
  7637. var cur = K('[name="url"]', div).val();
  7638. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '文件库', clickFn, this);
  7639. /*
  7640. self.loadPlugin('filemanager', function() {
  7641. self.plugin.filemanagerDialog({
  7642. viewType : 'LIST',
  7643. dirName : 'file',
  7644. clickFn : function(url, title) {
  7645. if (self.dialogs.length > 1) {
  7646. self.hideDialog();
  7647. }
  7648. }
  7649. });
  7650. });
  7651. */
  7652. });
  7653. } else {
  7654. viewServerBtn.hide();
  7655. }
  7656. urlBox.val(fileUrl);
  7657. titleBox.val(fileTitle);
  7658. urlBox[0].focus();
  7659. urlBox[0].select();
  7660. };
  7661. self.clickToolbar(name, function() {
  7662. self.plugin.fileDialog({
  7663. clickFn : function(url, title) {
  7664. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7665. self.insertHtml(html).hideDialog().focus();
  7666. }
  7667. });
  7668. });
  7669. });
  7670. /*******************************************************************************
  7671. * KindEditor - WYSIWYG HTML Editor for Internet
  7672. * Copyright (C) 2006-2011 kindsoft.net
  7673. *
  7674. * @author Roddy <luolonghao@gmail.com>
  7675. * @site http://www.kindsoft.net/
  7676. * @licence http://www.kindsoft.net/license.php
  7677. *******************************************************************************/
  7678. KindEditor.plugin('lineheight', function(K) {
  7679. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7680. self.clickToolbar(name, function() {
  7681. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7682. if (commonNode) {
  7683. curVal = commonNode.css('line-height');
  7684. }
  7685. var menu = self.createMenu({
  7686. name : name,
  7687. width : 150
  7688. });
  7689. K.each(lang.lineHeight, function(i, row) {
  7690. K.each(row, function(key, val) {
  7691. menu.addItem({
  7692. title : val,
  7693. checked : curVal === key,
  7694. click : function() {
  7695. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7696. span : '.line-height=' + key
  7697. });
  7698. self.updateState();
  7699. self.addBookmark();
  7700. self.hideMenu();
  7701. }
  7702. });
  7703. });
  7704. });
  7705. });
  7706. });
  7707. /*******************************************************************************
  7708. * KindEditor - WYSIWYG HTML Editor for Internet
  7709. * Copyright (C) 2006-2011 kindsoft.net
  7710. *
  7711. * @author Roddy <luolonghao@gmail.com>
  7712. * @site http://www.kindsoft.net/
  7713. * @licence http://www.kindsoft.net/license.php
  7714. *******************************************************************************/
  7715. KindEditor.plugin('link', function(K) {
  7716. var self = this, name = 'link';
  7717. self.plugin.link = {
  7718. edit : function() {
  7719. var lang = self.lang(name + '.'),
  7720. html = '<div style="padding:20px;">' +
  7721. '<div class="ke-dialog-row">' +
  7722. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7723. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7724. '<div class="ke-dialog-row"">' +
  7725. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7726. '<select id="keType" name="type"></select>' +
  7727. '</div>' +
  7728. '</div>',
  7729. dialog = self.createDialog({
  7730. name : name,
  7731. width : 450,
  7732. title : self.lang(name),
  7733. body : html,
  7734. yesBtn : {
  7735. name : self.lang('yes'),
  7736. click : function(e) {
  7737. var url = K.trim(urlBox.val());
  7738. if (url == 'http://' || K.invalidUrl(url)) {
  7739. alert(self.lang('invalidUrl'));
  7740. urlBox[0].focus();
  7741. return;
  7742. }
  7743. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7744. }
  7745. }
  7746. }),
  7747. div = dialog.div,
  7748. urlBox = K('input[name="url"]', div),
  7749. typeBox = K('select[name="type"]', div);
  7750. urlBox.val('http://');
  7751. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7752. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7753. self.cmd.selection();
  7754. var a = self.plugin.getSelectedLink();
  7755. if (a) {
  7756. self.cmd.range.selectNode(a[0]);
  7757. self.cmd.select();
  7758. urlBox.val(a.attr('data-ke-src'));
  7759. typeBox.val(a.attr('target'));
  7760. }
  7761. urlBox[0].focus();
  7762. urlBox[0].select();
  7763. },
  7764. 'delete' : function() {
  7765. self.exec('unlink', null);
  7766. }
  7767. };
  7768. self.clickToolbar(name, self.plugin.link.edit);
  7769. });
  7770. /*******************************************************************************
  7771. * KindEditor - WYSIWYG HTML Editor for Internet
  7772. * Copyright (C) 2006-2011 kindsoft.net
  7773. *
  7774. * @author Roddy <luolonghao@gmail.com>
  7775. * @site http://www.kindsoft.net/
  7776. * @licence http://www.kindsoft.net/license.php
  7777. *******************************************************************************/
  7778. KindEditor.plugin('media', function(K) {
  7779. var self = this, name = 'media', lang = self.lang(name + '.'),
  7780. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7781. allowFileManager = K.undef(self.allowFileManager, false),
  7782. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7783. extraParams = K.undef(self.extraFileUploadParams, {}),
  7784. filePostName = K.undef(self.filePostName, 'imgFile'),
  7785. uploadJson = K.undef(self.uploadMediaJson, self.basePath + 'php/upload_json.php');
  7786. self.plugin.media = {
  7787. edit : function() {
  7788. var html = [
  7789. '<div style="padding:20px;">',
  7790. '<div class="ke-dialog-row">',
  7791. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7792. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7793. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7794. '<span class="ke-button-common ke-button-outer">',
  7795. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7796. '</span>',
  7797. '</div>',
  7798. '<div class="ke-dialog-row">',
  7799. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7800. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="450" maxlength="4" />',
  7801. '</div>',
  7802. '<div class="ke-dialog-row">',
  7803. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7804. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="100" maxlength="4" />',
  7805. '</div>',
  7806. '<div class="ke-dialog-row">',
  7807. '<label for="keAutostart">' + lang.autostart + '</label>',
  7808. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7809. '</div>',
  7810. '</div>'
  7811. ].join('');
  7812. var dialog = self.createDialog({
  7813. name : name,
  7814. width : 450,
  7815. height : 230,
  7816. title : self.lang(name),
  7817. body : html,
  7818. yesBtn : {
  7819. name : self.lang('yes'),
  7820. click : function(e) {
  7821. var url = K.trim(urlBox.val()),
  7822. width = widthBox.val(),
  7823. height = heightBox.val();
  7824. if (url == 'http://' || K.invalidUrl(url)) {
  7825. alert(self.lang('invalidUrl'));
  7826. urlBox[0].focus();
  7827. return;
  7828. }
  7829. if (!/^\d*$/.test(width)) {
  7830. alert(self.lang('invalidWidth'));
  7831. widthBox[0].focus();
  7832. return;
  7833. }
  7834. if (!/^\d*$/.test(height)) {
  7835. alert(self.lang('invalidHeight'));
  7836. heightBox[0].focus();
  7837. return;
  7838. }
  7839. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7840. src : url,
  7841. type : K.mediaType(url),
  7842. width : width,
  7843. height : height,
  7844. autostart : autostartBox[0].checked ? 'true' : 'false',
  7845. loop : 'true'
  7846. });
  7847. self.insertHtml(html).hideDialog().focus();
  7848. }
  7849. }
  7850. }),
  7851. div = dialog.div,
  7852. urlBox = K('[name="url"]', div),
  7853. viewServerBtn = K('[name="viewServer"]', div),
  7854. widthBox = K('[name="width"]', div),
  7855. heightBox = K('[name="height"]', div),
  7856. autostartBox = K('[name="autostart"]', div);
  7857. urlBox.val('http://');
  7858. if (allowMediaUpload) {
  7859. var uploadbutton = K.uploadbutton({
  7860. button : K('.ke-upload-button', div)[0],
  7861. fieldName : filePostName,
  7862. extraParams : extraParams,
  7863. url : K.addParam(uploadJson, 'dir=media'),
  7864. afterUpload : function(data) {
  7865. dialog.hideLoading();
  7866. if (data.error === 0) {
  7867. var url = data.url;
  7868. if (formatUploadUrl) {
  7869. url = K.formatUrl(url, 'absolute');
  7870. }
  7871. urlBox.val(url);
  7872. if (self.afterUpload) {
  7873. self.afterUpload.call(self, url, data, name);
  7874. }
  7875. alert(self.lang('uploadSuccess'));
  7876. } else {
  7877. alert(data.message);
  7878. }
  7879. },
  7880. afterError : function(html) {
  7881. dialog.hideLoading();
  7882. self.errorDialog(html);
  7883. }
  7884. });
  7885. uploadbutton.fileBox.change(function(e) {
  7886. dialog.showLoading(self.lang('uploadLoading'));
  7887. uploadbutton.submit();
  7888. });
  7889. } else {
  7890. K('.ke-upload-button', div).hide();
  7891. }
  7892. if (allowFileManager) {
  7893. viewServerBtn.click(function(e) {
  7894. var clickFn = function(url, title, id) {
  7895. K('[name="url"]', div).val(url);
  7896. if (self.afterSelectFile) {
  7897. self.afterSelectFile.call(self, url);
  7898. }
  7899. };
  7900. var cur = K('[name="url"]', div).val();
  7901. editorShowUpload(cur, self.fileManagerJson, '音频库', clickFn, this);
  7902. /*
  7903. self.loadPlugin('filemanager', function() {
  7904. self.plugin.filemanagerDialog({
  7905. viewType : 'LIST',
  7906. dirName : 'media',
  7907. clickFn : function(url, title) {
  7908. if (self.dialogs.length > 1) {
  7909. K('[name="url"]', div).val(url);
  7910. if (self.afterSelectFile) {
  7911. self.afterSelectFile.call(self, url);
  7912. }
  7913. self.hideDialog();
  7914. }
  7915. }
  7916. });
  7917. });
  7918. */
  7919. });
  7920. } else {
  7921. viewServerBtn.hide();
  7922. }
  7923. var img = self.plugin.getSelectedMedia();
  7924. if (img) {
  7925. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7926. urlBox.val(attrs.src);
  7927. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7928. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7929. autostartBox[0].checked = (attrs.autostart === 'true');
  7930. }
  7931. urlBox[0].focus();
  7932. urlBox[0].select();
  7933. },
  7934. 'delete' : function() {
  7935. self.plugin.getSelectedMedia().remove();
  7936. self.addBookmark();
  7937. }
  7938. };
  7939. self.clickToolbar(name, self.plugin.media.edit);
  7940. });
  7941. /*******************************************************************************
  7942. * KindEditor - WYSIWYG HTML Editor for Internet
  7943. * Copyright (C) 2006-2011 kindsoft.net
  7944. *
  7945. * @author Roddy <luolonghao@gmail.com>
  7946. * @site http://www.kindsoft.net/
  7947. * @licence http://www.kindsoft.net/license.php
  7948. *******************************************************************************/
  7949. (function(K) {
  7950. function KSWFUpload(options) {
  7951. this.init(options);
  7952. }
  7953. K.extend(KSWFUpload, {
  7954. init : function(options) {
  7955. var self = this;
  7956. options.afterError = options.afterError || function(str) {
  7957. alert(str);
  7958. };
  7959. self.options = options;
  7960. self.progressbars = {};
  7961. self.div = K(options.container).html([
  7962. '<div class="ke-swfupload">',
  7963. '<div class="ke-swfupload-top">',
  7964. '<div class="ke-inline-block ke-swfupload-button">',
  7965. '<input type="button" value="Browse" />',
  7966. '</div>',
  7967. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7968. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7969. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7970. '</span>',
  7971. '</div>',
  7972. '<div class="ke-swfupload-body"></div>',
  7973. '</div>'
  7974. ].join(''));
  7975. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7976. function showError(itemDiv, msg) {
  7977. K('.ke-status > div', itemDiv).hide();
  7978. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7979. }
  7980. var settings = {
  7981. debug : false,
  7982. upload_url : options.uploadUrl,
  7983. flash_url : options.flashUrl,
  7984. file_post_name : options.filePostName,
  7985. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7986. button_image_url: options.buttonImageUrl,
  7987. button_width: options.buttonWidth,
  7988. button_height: options.buttonHeight,
  7989. button_cursor : SWFUpload.CURSOR.HAND,
  7990. file_types : options.fileTypes,
  7991. file_types_description : options.fileTypesDesc,
  7992. file_upload_limit : options.fileUploadLimit,
  7993. file_size_limit : options.fileSizeLimit,
  7994. post_params : options.postParams,
  7995. file_queued_handler : function(file) {
  7996. file.url = self.options.fileIconUrl;
  7997. self.appendFile(file);
  7998. },
  7999. file_queue_error_handler : function(file, errorCode, message) {
  8000. var errorName = '';
  8001. switch (errorCode) {
  8002. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  8003. errorName = options.queueLimitExceeded;
  8004. break;
  8005. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  8006. errorName = options.fileExceedsSizeLimit;
  8007. break;
  8008. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  8009. errorName = options.zeroByteFile;
  8010. break;
  8011. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  8012. errorName = options.invalidFiletype;
  8013. break;
  8014. default:
  8015. errorName = options.unknownError;
  8016. break;
  8017. }
  8018. K.DEBUG && alert(errorName);
  8019. },
  8020. upload_start_handler : function(file) {
  8021. var self = this;
  8022. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  8023. K('.ke-status > div', itemDiv).hide();
  8024. K('.ke-progressbar', itemDiv).show();
  8025. },
  8026. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  8027. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  8028. var progressbar = self.progressbars[file.id];
  8029. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  8030. progressbar.percent.html(percent + '%');
  8031. },
  8032. upload_error_handler : function(file, errorCode, message) {
  8033. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  8034. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8035. showError(itemDiv, self.options.errorMessage);
  8036. }
  8037. },
  8038. upload_success_handler : function(file, serverData) {
  8039. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8040. var data = {};
  8041. try {
  8042. data = K.json(serverData);
  8043. } catch (e) {
  8044. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  8045. }
  8046. if (data.error !== 0) {
  8047. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  8048. return;
  8049. }
  8050. file.url = data.url;
  8051. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  8052. K('.ke-status > div', itemDiv).hide();
  8053. }
  8054. };
  8055. self.swfu = new SWFUpload(settings);
  8056. K('.ke-swfupload-startupload input', self.div).click(function() {
  8057. self.swfu.startUpload();
  8058. });
  8059. },
  8060. getUrlList : function() {
  8061. var list = [];
  8062. K('.ke-img', self.bodyDiv).each(function() {
  8063. var img = K(this);
  8064. var status = img.attr('data-status');
  8065. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8066. list.push(img.data('data'));
  8067. }
  8068. });
  8069. return list;
  8070. },
  8071. removeFile : function(fileId) {
  8072. var self = this;
  8073. self.swfu.cancelUpload(fileId);
  8074. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8075. K('.ke-photo', itemDiv).unbind();
  8076. K('.ke-delete', itemDiv).unbind();
  8077. itemDiv.remove();
  8078. },
  8079. removeFiles : function() {
  8080. var self = this;
  8081. K('.ke-item', self.bodyDiv).each(function() {
  8082. self.removeFile(K(this).attr('data-id'));
  8083. });
  8084. },
  8085. appendFile : function(file) {
  8086. var self = this;
  8087. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8088. self.bodyDiv.append(itemDiv);
  8089. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8090. .mouseover(function(e) {
  8091. K(this).addClass('ke-on');
  8092. })
  8093. .mouseout(function(e) {
  8094. K(this).removeClass('ke-on');
  8095. });
  8096. itemDiv.append(photoDiv);
  8097. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8098. photoDiv.append(img);
  8099. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8100. self.removeFile(file.id);
  8101. });
  8102. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8103. K(['<div class="ke-progressbar">',
  8104. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8105. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8106. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8107. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8108. self.progressbars[file.id] = {
  8109. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8110. percent : K('.ke-progressbar-percent', photoDiv)
  8111. };
  8112. },
  8113. remove : function() {
  8114. this.removeFiles();
  8115. this.swfu.destroy();
  8116. this.div.html('');
  8117. }
  8118. });
  8119. K.swfupload = function(element, options) {
  8120. return new KSWFUpload(element, options);
  8121. };
  8122. })(KindEditor);
  8123. KindEditor.plugin('multiimage', function(K) {
  8124. var self = this, name = 'multiimage',
  8125. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8126. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8127. imgPath = self.pluginsPath + 'multiimage/images/',
  8128. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8129. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8130. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8131. filePostName = K.undef(self.filePostName, 'imgFile'),
  8132. lang = self.lang(name + '.');
  8133. self.plugin.multiImageDialog = function(options) {
  8134. var clickFn = options.clickFn,
  8135. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8136. uploadDesc = '';
  8137. var html = [
  8138. '<div style="padding:20px;">',
  8139. '<div class="swfupload">',
  8140. '</div>',
  8141. '</div>'
  8142. ].join('');
  8143. var dialog = self.createDialog({
  8144. name : name,
  8145. width : 650,
  8146. height : 510,
  8147. title : self.lang(name),
  8148. body : html,
  8149. previewBtn : {
  8150. name : lang.insertAll,
  8151. click : function(e) {
  8152. clickFn.call(self, swfupload.getUrlList());
  8153. }
  8154. },
  8155. yesBtn : {
  8156. name : lang.clearAll,
  8157. click : function(e) {
  8158. swfupload.removeFiles();
  8159. }
  8160. },
  8161. beforeRemove : function() {
  8162. if (!K.IE || K.V <= 8) {
  8163. swfupload.remove();
  8164. }
  8165. }
  8166. }),
  8167. div = dialog.div;
  8168. var swfupload = K.swfupload({
  8169. container : K('.swfupload', div),
  8170. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8171. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8172. buttonHeight : 23,
  8173. fileIconUrl : imgPath + 'image.png',
  8174. uploadDesc : uploadDesc,
  8175. startButtonValue : lang.startUpload,
  8176. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8177. //uploadMediaUrl : K.addParam(uploadMediaUrl, 'dir=media'),
  8178. flashUrl : imgPath + 'swfupload.swf',
  8179. filePostName : filePostName,
  8180. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8181. fileTypesDesc : 'Image Files',
  8182. fileUploadLimit : imageUploadLimit,
  8183. fileSizeLimit : imageSizeLimit,
  8184. postParams : K.undef(self.extraFileUploadParams, {}),
  8185. queueLimitExceeded : lang.queueLimitExceeded,
  8186. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8187. zeroByteFile : lang.zeroByteFile,
  8188. invalidFiletype : lang.invalidFiletype,
  8189. unknownError : lang.unknownError,
  8190. pendingMessage : lang.pending,
  8191. errorMessage : lang.uploadError,
  8192. afterError : function(html) {
  8193. self.errorDialog(html);
  8194. }
  8195. });
  8196. return dialog;
  8197. };
  8198. self.clickToolbar(name, function() {
  8199. self.plugin.multiImageDialog({
  8200. clickFn : function (urlList) {
  8201. if (urlList.length === 0) {
  8202. return;
  8203. }
  8204. K.each(urlList, function(i, data) {
  8205. if (self.afterUpload) {
  8206. self.afterUpload.call(self, data.url, data, 'multiimage');
  8207. }
  8208. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8209. });
  8210. setTimeout(function() {
  8211. self.hideDialog().focus();
  8212. }, 0);
  8213. }
  8214. });
  8215. });
  8216. });
  8217. /* ******************* */
  8218. /* Constructor & Init */
  8219. /* ******************* */
  8220. (function() {
  8221. window.SWFUpload = function (settings) {
  8222. this.initSWFUpload(settings);
  8223. };
  8224. SWFUpload.prototype.initSWFUpload = function (settings) {
  8225. try {
  8226. this.customSettings = {};
  8227. this.settings = settings;
  8228. this.eventQueue = [];
  8229. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8230. this.movieElement = null;
  8231. SWFUpload.instances[this.movieName] = this;
  8232. this.initSettings();
  8233. this.loadFlash();
  8234. this.displayDebugInfo();
  8235. } catch (ex) {
  8236. delete SWFUpload.instances[this.movieName];
  8237. throw ex;
  8238. }
  8239. };
  8240. /* *************** */
  8241. /* Static Members */
  8242. /* *************** */
  8243. SWFUpload.instances = {};
  8244. SWFUpload.movieCount = 0;
  8245. SWFUpload.version = "2.2.0 2009-03-25";
  8246. SWFUpload.QUEUE_ERROR = {
  8247. QUEUE_LIMIT_EXCEEDED : -100,
  8248. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8249. ZERO_BYTE_FILE : -120,
  8250. INVALID_FILETYPE : -130
  8251. };
  8252. SWFUpload.UPLOAD_ERROR = {
  8253. HTTP_ERROR : -200,
  8254. MISSING_UPLOAD_URL : -210,
  8255. IO_ERROR : -220,
  8256. SECURITY_ERROR : -230,
  8257. UPLOAD_LIMIT_EXCEEDED : -240,
  8258. UPLOAD_FAILED : -250,
  8259. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8260. FILE_VALIDATION_FAILED : -270,
  8261. FILE_CANCELLED : -280,
  8262. UPLOAD_STOPPED : -290
  8263. };
  8264. SWFUpload.FILE_STATUS = {
  8265. QUEUED : -1,
  8266. IN_PROGRESS : -2,
  8267. ERROR : -3,
  8268. COMPLETE : -4,
  8269. CANCELLED : -5
  8270. };
  8271. SWFUpload.BUTTON_ACTION = {
  8272. SELECT_FILE : -100,
  8273. SELECT_FILES : -110,
  8274. START_UPLOAD : -120
  8275. };
  8276. SWFUpload.CURSOR = {
  8277. ARROW : -1,
  8278. HAND : -2
  8279. };
  8280. SWFUpload.WINDOW_MODE = {
  8281. WINDOW : "window",
  8282. TRANSPARENT : "transparent",
  8283. OPAQUE : "opaque"
  8284. };
  8285. SWFUpload.completeURL = function(url) {
  8286. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8287. return url;
  8288. }
  8289. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8290. var indexSlash = window.location.pathname.lastIndexOf("/");
  8291. var path;
  8292. if (indexSlash <= 0) {
  8293. path = "/";
  8294. } else {
  8295. path = window.location.pathname.substr(0, indexSlash) + "/";
  8296. }
  8297. return /*currentURL +*/ path + url;
  8298. };
  8299. /* ******************** */
  8300. /* Instance Members */
  8301. /* ******************** */
  8302. SWFUpload.prototype.initSettings = function () {
  8303. this.ensureDefault = function (settingName, defaultValue) {
  8304. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8305. };
  8306. this.ensureDefault("upload_url", "");
  8307. this.ensureDefault("preserve_relative_urls", false);
  8308. this.ensureDefault("file_post_name", "Filedata");
  8309. this.ensureDefault("post_params", {});
  8310. this.ensureDefault("use_query_string", false);
  8311. this.ensureDefault("requeue_on_error", false);
  8312. this.ensureDefault("http_success", []);
  8313. this.ensureDefault("assume_success_timeout", 0);
  8314. this.ensureDefault("file_types", "*.*");
  8315. this.ensureDefault("file_types_description", "All Files");
  8316. this.ensureDefault("file_size_limit", 0);
  8317. this.ensureDefault("file_upload_limit", 0);
  8318. this.ensureDefault("file_queue_limit", 0);
  8319. this.ensureDefault("flash_url", "swfupload.swf");
  8320. this.ensureDefault("prevent_swf_caching", true);
  8321. this.ensureDefault("button_image_url", "");
  8322. this.ensureDefault("button_width", 1);
  8323. this.ensureDefault("button_height", 1);
  8324. this.ensureDefault("button_text", "");
  8325. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8326. this.ensureDefault("button_text_top_padding", 0);
  8327. this.ensureDefault("button_text_left_padding", 0);
  8328. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8329. this.ensureDefault("button_disabled", false);
  8330. this.ensureDefault("button_placeholder_id", "");
  8331. this.ensureDefault("button_placeholder", null);
  8332. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8333. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8334. this.ensureDefault("debug", false);
  8335. this.settings.debug_enabled = this.settings.debug;
  8336. this.settings.return_upload_start_handler = this.returnUploadStart;
  8337. this.ensureDefault("swfupload_loaded_handler", null);
  8338. this.ensureDefault("file_dialog_start_handler", null);
  8339. this.ensureDefault("file_queued_handler", null);
  8340. this.ensureDefault("file_queue_error_handler", null);
  8341. this.ensureDefault("file_dialog_complete_handler", null);
  8342. this.ensureDefault("upload_start_handler", null);
  8343. this.ensureDefault("upload_progress_handler", null);
  8344. this.ensureDefault("upload_error_handler", null);
  8345. this.ensureDefault("upload_success_handler", null);
  8346. this.ensureDefault("upload_complete_handler", null);
  8347. this.ensureDefault("debug_handler", this.debugMessage);
  8348. this.ensureDefault("custom_settings", {});
  8349. this.customSettings = this.settings.custom_settings;
  8350. if (!!this.settings.prevent_swf_caching) {
  8351. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8352. }
  8353. if (!this.settings.preserve_relative_urls) {
  8354. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8355. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8356. }
  8357. delete this.ensureDefault;
  8358. };
  8359. SWFUpload.prototype.loadFlash = function () {
  8360. var targetElement, tempParent;
  8361. if (document.getElementById(this.movieName) !== null) {
  8362. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8363. }
  8364. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8365. if (targetElement == undefined) {
  8366. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8367. }
  8368. tempParent = document.createElement("div");
  8369. tempParent.innerHTML = this.getFlashHTML();
  8370. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8371. if (window[this.movieName] == undefined) {
  8372. window[this.movieName] = this.getMovieElement();
  8373. }
  8374. };
  8375. SWFUpload.prototype.getFlashHTML = function () {
  8376. var classid = '';
  8377. if (KindEditor.IE && KindEditor.V > 8) {
  8378. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8379. }
  8380. 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">',
  8381. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8382. '<param name="movie" value="', this.settings.flash_url, '" />',
  8383. '<param name="quality" value="high" />',
  8384. '<param name="menu" value="false" />',
  8385. '<param name="allowScriptAccess" value="always" />',
  8386. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8387. '</object>'].join("");
  8388. };
  8389. SWFUpload.prototype.getFlashVars = function () {
  8390. var paramString = this.buildParamString();
  8391. var httpSuccessString = this.settings.http_success.join(",");
  8392. return ["movieName=", encodeURIComponent(this.movieName),
  8393. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8394. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8395. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8396. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8397. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8398. "&amp;params=", encodeURIComponent(paramString),
  8399. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8400. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8401. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8402. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8403. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8404. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8405. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8406. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8407. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8408. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8409. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8410. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8411. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8412. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8413. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8414. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8415. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8416. ].join("");
  8417. };
  8418. SWFUpload.prototype.getMovieElement = function () {
  8419. if (this.movieElement == undefined) {
  8420. this.movieElement = document.getElementById(this.movieName);
  8421. }
  8422. if (this.movieElement === null) {
  8423. throw "Could not find Flash element";
  8424. }
  8425. return this.movieElement;
  8426. };
  8427. SWFUpload.prototype.buildParamString = function () {
  8428. var postParams = this.settings.post_params;
  8429. var paramStringPairs = [];
  8430. if (typeof(postParams) === "object") {
  8431. for (var name in postParams) {
  8432. if (postParams.hasOwnProperty(name)) {
  8433. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8434. }
  8435. }
  8436. }
  8437. return paramStringPairs.join("&amp;");
  8438. };
  8439. SWFUpload.prototype.destroy = function () {
  8440. try {
  8441. this.cancelUpload(null, false);
  8442. var movieElement = null;
  8443. movieElement = this.getMovieElement();
  8444. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8445. for (var i in movieElement) {
  8446. try {
  8447. if (typeof(movieElement[i]) === "function") {
  8448. movieElement[i] = null;
  8449. }
  8450. } catch (ex1) {}
  8451. }
  8452. try {
  8453. movieElement.parentNode.removeChild(movieElement);
  8454. } catch (ex) {}
  8455. }
  8456. window[this.movieName] = null;
  8457. SWFUpload.instances[this.movieName] = null;
  8458. delete SWFUpload.instances[this.movieName];
  8459. this.movieElement = null;
  8460. this.settings = null;
  8461. this.customSettings = null;
  8462. this.eventQueue = null;
  8463. this.movieName = null;
  8464. return true;
  8465. } catch (ex2) {
  8466. return false;
  8467. }
  8468. };
  8469. SWFUpload.prototype.displayDebugInfo = function () {
  8470. this.debug(
  8471. [
  8472. "---SWFUpload Instance Info---\n",
  8473. "Version: ", SWFUpload.version, "\n",
  8474. "Movie Name: ", this.movieName, "\n",
  8475. "Settings:\n",
  8476. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8477. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8478. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8479. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8480. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8481. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8482. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8483. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8484. "\t", "file_types: ", this.settings.file_types, "\n",
  8485. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8486. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8487. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8488. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8489. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8490. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8491. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8492. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8493. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8494. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8495. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8496. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8497. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8498. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8499. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8500. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8501. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8502. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8503. "Event Handlers:\n",
  8504. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8505. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8506. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8507. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8508. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8509. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8510. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8511. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8512. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8513. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8514. ].join("")
  8515. );
  8516. };
  8517. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8518. the maintain v2 API compatibility
  8519. */
  8520. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8521. if (value == undefined) {
  8522. return (this.settings[name] = default_value);
  8523. } else {
  8524. return (this.settings[name] = value);
  8525. }
  8526. };
  8527. SWFUpload.prototype.getSetting = function (name) {
  8528. if (this.settings[name] != undefined) {
  8529. return this.settings[name];
  8530. }
  8531. return "";
  8532. };
  8533. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8534. argumentArray = argumentArray || [];
  8535. var movieElement = this.getMovieElement();
  8536. var returnValue, returnString;
  8537. try {
  8538. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8539. returnValue = eval(returnString);
  8540. } catch (ex) {
  8541. throw "Call to " + functionName + " failed";
  8542. }
  8543. if (returnValue != undefined && typeof returnValue.post === "object") {
  8544. returnValue = this.unescapeFilePostParams(returnValue);
  8545. }
  8546. return returnValue;
  8547. };
  8548. /* *****************************
  8549. -- Flash control methods --
  8550. Your UI should use these
  8551. to operate SWFUpload
  8552. ***************************** */
  8553. SWFUpload.prototype.selectFile = function () {
  8554. this.callFlash("SelectFile");
  8555. };
  8556. SWFUpload.prototype.selectFiles = function () {
  8557. this.callFlash("SelectFiles");
  8558. };
  8559. SWFUpload.prototype.startUpload = function (fileID) {
  8560. this.callFlash("StartUpload", [fileID]);
  8561. };
  8562. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8563. if (triggerErrorEvent !== false) {
  8564. triggerErrorEvent = true;
  8565. }
  8566. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8567. };
  8568. SWFUpload.prototype.stopUpload = function () {
  8569. this.callFlash("StopUpload");
  8570. };
  8571. /* ************************
  8572. * Settings methods
  8573. * These methods change the SWFUpload settings.
  8574. * SWFUpload settings should not be changed directly on the settings object
  8575. * since many of the settings need to be passed to Flash in order to take
  8576. * effect.
  8577. * *********************** */
  8578. SWFUpload.prototype.getStats = function () {
  8579. return this.callFlash("GetStats");
  8580. };
  8581. SWFUpload.prototype.setStats = function (statsObject) {
  8582. this.callFlash("SetStats", [statsObject]);
  8583. };
  8584. SWFUpload.prototype.getFile = function (fileID) {
  8585. if (typeof(fileID) === "number") {
  8586. return this.callFlash("GetFileByIndex", [fileID]);
  8587. } else {
  8588. return this.callFlash("GetFile", [fileID]);
  8589. }
  8590. };
  8591. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8592. return this.callFlash("AddFileParam", [fileID, name, value]);
  8593. };
  8594. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8595. this.callFlash("RemoveFileParam", [fileID, name]);
  8596. };
  8597. SWFUpload.prototype.setUploadURL = function (url) {
  8598. this.settings.upload_url = url.toString();
  8599. this.callFlash("SetUploadURL", [url]);
  8600. };
  8601. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8602. this.settings.post_params = paramsObject;
  8603. this.callFlash("SetPostParams", [paramsObject]);
  8604. };
  8605. SWFUpload.prototype.addPostParam = function (name, value) {
  8606. this.settings.post_params[name] = value;
  8607. this.callFlash("SetPostParams", [this.settings.post_params]);
  8608. };
  8609. SWFUpload.prototype.removePostParam = function (name) {
  8610. delete this.settings.post_params[name];
  8611. this.callFlash("SetPostParams", [this.settings.post_params]);
  8612. };
  8613. SWFUpload.prototype.setFileTypes = function (types, description) {
  8614. this.settings.file_types = types;
  8615. this.settings.file_types_description = description;
  8616. this.callFlash("SetFileTypes", [types, description]);
  8617. };
  8618. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8619. this.settings.file_size_limit = fileSizeLimit;
  8620. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8621. };
  8622. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8623. this.settings.file_upload_limit = fileUploadLimit;
  8624. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8625. };
  8626. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8627. this.settings.file_queue_limit = fileQueueLimit;
  8628. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8629. };
  8630. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8631. this.settings.file_post_name = filePostName;
  8632. this.callFlash("SetFilePostName", [filePostName]);
  8633. };
  8634. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8635. this.settings.use_query_string = useQueryString;
  8636. this.callFlash("SetUseQueryString", [useQueryString]);
  8637. };
  8638. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8639. this.settings.requeue_on_error = requeueOnError;
  8640. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8641. };
  8642. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8643. if (typeof http_status_codes === "string") {
  8644. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8645. }
  8646. this.settings.http_success = http_status_codes;
  8647. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8648. };
  8649. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8650. this.settings.assume_success_timeout = timeout_seconds;
  8651. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8652. };
  8653. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8654. this.settings.debug_enabled = debugEnabled;
  8655. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8656. };
  8657. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8658. if (buttonImageURL == undefined) {
  8659. buttonImageURL = "";
  8660. }
  8661. this.settings.button_image_url = buttonImageURL;
  8662. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8663. };
  8664. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8665. this.settings.button_width = width;
  8666. this.settings.button_height = height;
  8667. var movie = this.getMovieElement();
  8668. if (movie != undefined) {
  8669. movie.style.width = width + "px";
  8670. movie.style.height = height + "px";
  8671. }
  8672. this.callFlash("SetButtonDimensions", [width, height]);
  8673. };
  8674. SWFUpload.prototype.setButtonText = function (html) {
  8675. this.settings.button_text = html;
  8676. this.callFlash("SetButtonText", [html]);
  8677. };
  8678. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8679. this.settings.button_text_top_padding = top;
  8680. this.settings.button_text_left_padding = left;
  8681. this.callFlash("SetButtonTextPadding", [left, top]);
  8682. };
  8683. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8684. this.settings.button_text_style = css;
  8685. this.callFlash("SetButtonTextStyle", [css]);
  8686. };
  8687. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8688. this.settings.button_disabled = isDisabled;
  8689. this.callFlash("SetButtonDisabled", [isDisabled]);
  8690. };
  8691. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8692. this.settings.button_action = buttonAction;
  8693. this.callFlash("SetButtonAction", [buttonAction]);
  8694. };
  8695. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8696. this.settings.button_cursor = cursor;
  8697. this.callFlash("SetButtonCursor", [cursor]);
  8698. };
  8699. /* *******************************
  8700. Flash Event Interfaces
  8701. These functions are used by Flash to trigger the various
  8702. events.
  8703. All these functions a Private.
  8704. Because the ExternalInterface library is buggy the event calls
  8705. are added to a queue and the queue then executed by a setTimeout.
  8706. This ensures that events are executed in a determinate order and that
  8707. the ExternalInterface bugs are avoided.
  8708. ******************************* */
  8709. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8710. if (argumentArray == undefined) {
  8711. argumentArray = [];
  8712. } else if (!(argumentArray instanceof Array)) {
  8713. argumentArray = [argumentArray];
  8714. }
  8715. var self = this;
  8716. if (typeof this.settings[handlerName] === "function") {
  8717. this.eventQueue.push(function () {
  8718. this.settings[handlerName].apply(this, argumentArray);
  8719. });
  8720. setTimeout(function () {
  8721. self.executeNextEvent();
  8722. }, 0);
  8723. } else if (this.settings[handlerName] !== null) {
  8724. throw "Event handler " + handlerName + " is unknown or is not a function";
  8725. }
  8726. };
  8727. SWFUpload.prototype.executeNextEvent = function () {
  8728. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8729. if (typeof(f) === "function") {
  8730. f.apply(this);
  8731. }
  8732. };
  8733. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8734. var reg = /[$]([0-9a-f]{4})/i;
  8735. var unescapedPost = {};
  8736. var uk;
  8737. if (file != undefined) {
  8738. for (var k in file.post) {
  8739. if (file.post.hasOwnProperty(k)) {
  8740. uk = k;
  8741. var match;
  8742. while ((match = reg.exec(uk)) !== null) {
  8743. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8744. }
  8745. unescapedPost[uk] = file.post[k];
  8746. }
  8747. }
  8748. file.post = unescapedPost;
  8749. }
  8750. return file;
  8751. };
  8752. SWFUpload.prototype.testExternalInterface = function () {
  8753. try {
  8754. return this.callFlash("TestExternalInterface");
  8755. } catch (ex) {
  8756. return false;
  8757. }
  8758. };
  8759. SWFUpload.prototype.flashReady = function () {
  8760. var movieElement = this.getMovieElement();
  8761. if (!movieElement) {
  8762. this.debug("Flash called back ready but the flash movie can't be found.");
  8763. return;
  8764. }
  8765. this.cleanUp(movieElement);
  8766. this.queueEvent("swfupload_loaded_handler");
  8767. };
  8768. SWFUpload.prototype.cleanUp = function (movieElement) {
  8769. try {
  8770. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8771. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8772. for (var key in movieElement) {
  8773. try {
  8774. if (typeof(movieElement[key]) === "function") {
  8775. movieElement[key] = null;
  8776. }
  8777. } catch (ex) {
  8778. }
  8779. }
  8780. }
  8781. } catch (ex1) {
  8782. }
  8783. window["__flash__removeCallback"] = function (instance, name) {
  8784. try {
  8785. if (instance) {
  8786. instance[name] = null;
  8787. }
  8788. } catch (flashEx) {
  8789. }
  8790. };
  8791. };
  8792. /* This is a chance to do something before the browse window opens */
  8793. SWFUpload.prototype.fileDialogStart = function () {
  8794. this.queueEvent("file_dialog_start_handler");
  8795. };
  8796. /* Called when a file is successfully added to the queue. */
  8797. SWFUpload.prototype.fileQueued = function (file) {
  8798. file = this.unescapeFilePostParams(file);
  8799. this.queueEvent("file_queued_handler", file);
  8800. };
  8801. /* Handle errors that occur when an attempt to queue a file fails. */
  8802. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8803. file = this.unescapeFilePostParams(file);
  8804. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8805. };
  8806. /* Called after the file dialog has closed and the selected files have been queued.
  8807. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8808. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8809. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8810. };
  8811. SWFUpload.prototype.uploadStart = function (file) {
  8812. file = this.unescapeFilePostParams(file);
  8813. this.queueEvent("return_upload_start_handler", file);
  8814. };
  8815. SWFUpload.prototype.returnUploadStart = function (file) {
  8816. var returnValue;
  8817. if (typeof this.settings.upload_start_handler === "function") {
  8818. file = this.unescapeFilePostParams(file);
  8819. returnValue = this.settings.upload_start_handler.call(this, file);
  8820. } else if (this.settings.upload_start_handler != undefined) {
  8821. throw "upload_start_handler must be a function";
  8822. }
  8823. if (returnValue === undefined) {
  8824. returnValue = true;
  8825. }
  8826. returnValue = !!returnValue;
  8827. this.callFlash("ReturnUploadStart", [returnValue]);
  8828. };
  8829. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8830. file = this.unescapeFilePostParams(file);
  8831. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8832. };
  8833. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8834. file = this.unescapeFilePostParams(file);
  8835. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8836. };
  8837. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8838. file = this.unescapeFilePostParams(file);
  8839. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8840. };
  8841. SWFUpload.prototype.uploadComplete = function (file) {
  8842. file = this.unescapeFilePostParams(file);
  8843. this.queueEvent("upload_complete_handler", file);
  8844. };
  8845. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8846. internal debug console. You can override this event and have messages written where you want. */
  8847. SWFUpload.prototype.debug = function (message) {
  8848. this.queueEvent("debug_handler", message);
  8849. };
  8850. /* **********************************
  8851. Debug Console
  8852. The debug console is a self contained, in page location
  8853. for debug message to be sent. The Debug Console adds
  8854. itself to the body if necessary.
  8855. The console is automatically scrolled as messages appear.
  8856. If you are using your own debug handler or when you deploy to production and
  8857. have debug disabled you can remove these functions to reduce the file size
  8858. and complexity.
  8859. ********************************** */
  8860. SWFUpload.prototype.debugMessage = function (message) {
  8861. if (this.settings.debug) {
  8862. var exceptionMessage, exceptionValues = [];
  8863. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8864. for (var key in message) {
  8865. if (message.hasOwnProperty(key)) {
  8866. exceptionValues.push(key + ": " + message[key]);
  8867. }
  8868. }
  8869. exceptionMessage = exceptionValues.join("\n") || "";
  8870. exceptionValues = exceptionMessage.split("\n");
  8871. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8872. SWFUpload.Console.writeLine(exceptionMessage);
  8873. } else {
  8874. SWFUpload.Console.writeLine(message);
  8875. }
  8876. }
  8877. };
  8878. SWFUpload.Console = {};
  8879. SWFUpload.Console.writeLine = function (message) {
  8880. var console, documentForm;
  8881. try {
  8882. console = document.getElementById("SWFUpload_Console");
  8883. if (!console) {
  8884. documentForm = document.createElement("form");
  8885. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8886. console = document.createElement("textarea");
  8887. console.id = "SWFUpload_Console";
  8888. console.style.fontFamily = "monospace";
  8889. console.setAttribute("wrap", "off");
  8890. console.wrap = "off";
  8891. console.style.overflow = "auto";
  8892. console.style.width = "700px";
  8893. console.style.height = "350px";
  8894. console.style.margin = "5px";
  8895. documentForm.appendChild(console);
  8896. }
  8897. console.value += message + "\n";
  8898. console.scrollTop = console.scrollHeight - console.clientHeight;
  8899. } catch (ex) {
  8900. alert("Exception: " + ex.name + " Message: " + ex.message);
  8901. }
  8902. };
  8903. })();
  8904. (function() {
  8905. /*
  8906. Queue Plug-in
  8907. Features:
  8908. *Adds a cancelQueue() method for cancelling the entire queue.
  8909. *All queued files are uploaded when startUpload() is called.
  8910. *If false is returned from uploadComplete then the queue upload is stopped.
  8911. If false is not returned (strict comparison) then the queue upload is continued.
  8912. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8913. Set the event handler with the queue_complete_handler setting.
  8914. */
  8915. if (typeof(SWFUpload) === "function") {
  8916. SWFUpload.queue = {};
  8917. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8918. return function () {
  8919. if (typeof(oldInitSettings) === "function") {
  8920. oldInitSettings.call(this);
  8921. }
  8922. this.queueSettings = {};
  8923. this.queueSettings.queue_cancelled_flag = false;
  8924. this.queueSettings.queue_upload_count = 0;
  8925. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8926. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8927. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8928. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8929. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8930. };
  8931. })(SWFUpload.prototype.initSettings);
  8932. SWFUpload.prototype.startUpload = function (fileID) {
  8933. this.queueSettings.queue_cancelled_flag = false;
  8934. this.callFlash("StartUpload", [fileID]);
  8935. };
  8936. SWFUpload.prototype.cancelQueue = function () {
  8937. this.queueSettings.queue_cancelled_flag = true;
  8938. this.stopUpload();
  8939. var stats = this.getStats();
  8940. while (stats.files_queued > 0) {
  8941. this.cancelUpload();
  8942. stats = this.getStats();
  8943. }
  8944. };
  8945. SWFUpload.queue.uploadStartHandler = function (file) {
  8946. var returnValue;
  8947. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8948. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8949. }
  8950. returnValue = (returnValue === false) ? false : true;
  8951. this.queueSettings.queue_cancelled_flag = !returnValue;
  8952. return returnValue;
  8953. };
  8954. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8955. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8956. var continueUpload;
  8957. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8958. this.queueSettings.queue_upload_count++;
  8959. }
  8960. if (typeof(user_upload_complete_handler) === "function") {
  8961. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8962. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8963. continueUpload = false;
  8964. } else {
  8965. continueUpload = true;
  8966. }
  8967. if (continueUpload) {
  8968. var stats = this.getStats();
  8969. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8970. this.startUpload();
  8971. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8972. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8973. this.queueSettings.queue_upload_count = 0;
  8974. } else {
  8975. this.queueSettings.queue_cancelled_flag = false;
  8976. this.queueSettings.queue_upload_count = 0;
  8977. }
  8978. }
  8979. };
  8980. }
  8981. })();
  8982. /*******************************************************************************
  8983. * KindEditor - WYSIWYG HTML Editor for Internet
  8984. * Copyright (C) 2006-2011 kindsoft.net
  8985. *
  8986. * @author Roddy <luolonghao@gmail.com>
  8987. * @site http://www.kindsoft.net/
  8988. * @licence http://www.kindsoft.net/license.php
  8989. *******************************************************************************/
  8990. KindEditor.plugin('pagebreak', function(K) {
  8991. var self = this;
  8992. var name = 'pagebreak';
  8993. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8994. self.clickToolbar(name, function() {
  8995. var cmd = self.cmd, range = cmd.range;
  8996. self.focus();
  8997. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8998. self.insertHtml(pagebreakHtml + tail);
  8999. if (tail !== '') {
  9000. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9001. range.selectNodeContents(p[0]);
  9002. p.removeAttr('id');
  9003. cmd.select();
  9004. }
  9005. });
  9006. });
  9007. /*******************************************************************************
  9008. * KindEditor - WYSIWYG HTML Editor for Internet
  9009. * Copyright (C) 2006-2011 kindsoft.net
  9010. *
  9011. * @author Roddy <luolonghao@gmail.com>
  9012. * @site http://www.kindsoft.net/
  9013. * @licence http://www.kindsoft.net/license.php
  9014. *******************************************************************************/
  9015. KindEditor.plugin('plainpaste', function(K) {
  9016. var self = this, name = 'plainpaste';
  9017. self.clickToolbar(name, function() {
  9018. var lang = self.lang(name + '.'),
  9019. html = '<div style="padding:10px 20px;">' +
  9020. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9021. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9022. '</div>',
  9023. dialog = self.createDialog({
  9024. name : name,
  9025. width : 450,
  9026. title : self.lang(name),
  9027. body : html,
  9028. yesBtn : {
  9029. name : self.lang('yes'),
  9030. click : function(e) {
  9031. var html = textarea.val();
  9032. html = K.escape(html);
  9033. html = html.replace(/ {2}/g, ' &nbsp;');
  9034. if (self.newlineTag == 'p') {
  9035. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9036. } else {
  9037. html = html.replace(/\n/g, '<br />$&');
  9038. }
  9039. self.insertHtml(html).hideDialog().focus();
  9040. }
  9041. }
  9042. }),
  9043. textarea = K('textarea', dialog.div);
  9044. textarea[0].focus();
  9045. });
  9046. });
  9047. /*******************************************************************************
  9048. * KindEditor - WYSIWYG HTML Editor for Internet
  9049. * Copyright (C) 2006-2011 kindsoft.net
  9050. *
  9051. * @author Roddy <luolonghao@gmail.com>
  9052. * @site http://www.kindsoft.net/
  9053. * @licence http://www.kindsoft.net/license.php
  9054. *******************************************************************************/
  9055. KindEditor.plugin('preview', function(K) {
  9056. var self = this, name = 'preview', undefined;
  9057. self.clickToolbar(name, function() {
  9058. var lang = self.lang(name + '.'),
  9059. html = '<div style="padding:10px 20px;">' +
  9060. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9061. '</div>',
  9062. dialog = self.createDialog({
  9063. name : name,
  9064. width : 750,
  9065. title : self.lang(name),
  9066. body : html
  9067. }),
  9068. iframe = K('iframe', dialog.div),
  9069. doc = K.iframeDoc(iframe);
  9070. doc.open();
  9071. doc.write(self.fullHtml());
  9072. doc.close();
  9073. K(doc.body).css('background-color', '#FFF');
  9074. iframe[0].contentWindow.focus();
  9075. });
  9076. });
  9077. /*******************************************************************************
  9078. * KindEditor - WYSIWYG HTML Editor for Internet
  9079. * Copyright (C) 2006-2011 kindsoft.net
  9080. *
  9081. * @author Roddy <luolonghao@gmail.com>
  9082. * @site http://www.kindsoft.net/
  9083. * @licence http://www.kindsoft.net/license.php
  9084. *******************************************************************************/
  9085. KindEditor.plugin('quickformat', function(K) {
  9086. var self = this, name = 'quickformat',
  9087. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9088. function getFirstChild(knode) {
  9089. var child = knode.first();
  9090. while (child && child.first()) {
  9091. child = child.first();
  9092. }
  9093. return child;
  9094. }
  9095. self.clickToolbar(name, function() {
  9096. self.focus();
  9097. var doc = self.edit.doc,
  9098. range = self.cmd.range,
  9099. child = K(doc.body).first(), next,
  9100. nodeList = [], subList = [],
  9101. bookmark = range.createBookmark(true);
  9102. while(child) {
  9103. next = child.next();
  9104. var firstChild = getFirstChild(child);
  9105. if (!firstChild || firstChild.name != 'img') {
  9106. if (blockMap[child.name]) {
  9107. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9108. child.css('text-indent', '2em');
  9109. } else {
  9110. subList.push(child);
  9111. }
  9112. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9113. if (subList.length > 0) {
  9114. nodeList.push(subList);
  9115. }
  9116. subList = [];
  9117. }
  9118. }
  9119. child = next;
  9120. }
  9121. K.each(nodeList, function(i, subList) {
  9122. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9123. subList[0].before(wrapper);
  9124. K.each(subList, function(i, knode) {
  9125. wrapper.append(knode);
  9126. });
  9127. });
  9128. range.moveToBookmark(bookmark);
  9129. self.addBookmark();
  9130. });
  9131. });
  9132. /*******************************************************************************
  9133. * KindEditor - WYSIWYG HTML Editor for Internet
  9134. * Copyright (C) 2006-2011 kindsoft.net
  9135. *
  9136. * @author Roddy <luolonghao@gmail.com>
  9137. * @site http://www.kindsoft.net/
  9138. * @licence http://www.kindsoft.net/license.php
  9139. *******************************************************************************/
  9140. KindEditor.plugin('table', function(K) {
  9141. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9142. function _setColor(box, color) {
  9143. color = color.toUpperCase();
  9144. box.css('background-color', color);
  9145. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9146. box.html(color);
  9147. }
  9148. var pickerList = [];
  9149. function _initColorPicker(dialogDiv, colorBox) {
  9150. colorBox.bind('click,mousedown', function(e){
  9151. e.stopPropagation();
  9152. });
  9153. function removePicker() {
  9154. K.each(pickerList, function() {
  9155. this.remove();
  9156. });
  9157. pickerList = [];
  9158. K(document).unbind('click,mousedown', removePicker);
  9159. dialogDiv.unbind('click,mousedown', removePicker);
  9160. }
  9161. colorBox.click(function(e) {
  9162. removePicker();
  9163. var box = K(this),
  9164. pos = box.pos();
  9165. var picker = K.colorpicker({
  9166. x : pos.x,
  9167. y : pos.y + box.height(),
  9168. z : 811214,
  9169. selectedColor : K(this).html(),
  9170. colors : self.colorTable,
  9171. noColor : self.lang('noColor'),
  9172. shadowMode : self.shadowMode,
  9173. click : function(color) {
  9174. _setColor(box, color);
  9175. removePicker();
  9176. }
  9177. });
  9178. pickerList.push(picker);
  9179. K(document).bind('click,mousedown', removePicker);
  9180. dialogDiv.bind('click,mousedown', removePicker);
  9181. });
  9182. }
  9183. function _getCellIndex(table, row, cell) {
  9184. var rowSpanCount = 0;
  9185. for (var i = 0, len = row.cells.length; i < len; i++) {
  9186. if (row.cells[i] == cell) {
  9187. break;
  9188. }
  9189. rowSpanCount += row.cells[i].rowSpan - 1;
  9190. }
  9191. return cell.cellIndex - rowSpanCount;
  9192. }
  9193. self.plugin.table = {
  9194. prop : function(isInsert) {
  9195. var html = [
  9196. '<div style="padding:20px;">',
  9197. '<div class="ke-dialog-row">',
  9198. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9199. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9200. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9201. '</div>',
  9202. '<div class="ke-dialog-row">',
  9203. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9204. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9205. '<select name="widthType">',
  9206. '<option value="%">' + lang.percent + '</option>',
  9207. '<option value="px">' + lang.px + '</option>',
  9208. '</select> &nbsp; ',
  9209. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9210. '<select name="heightType">',
  9211. '<option value="%">' + lang.percent + '</option>',
  9212. '<option value="px">' + lang.px + '</option>',
  9213. '</select>',
  9214. '</div>',
  9215. '<div class="ke-dialog-row">',
  9216. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9217. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9218. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9219. '</div>',
  9220. '<div class="ke-dialog-row">',
  9221. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9222. '<select id="keAlign" name="align">',
  9223. '<option value="">' + lang.alignDefault + '</option>',
  9224. '<option value="left">' + lang.alignLeft + '</option>',
  9225. '<option value="center">' + lang.alignCenter + '</option>',
  9226. '<option value="right">' + lang.alignRight + '</option>',
  9227. '</select>',
  9228. '</div>',
  9229. '<div class="ke-dialog-row">',
  9230. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9231. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9232. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9233. '</div>',
  9234. '<div class="ke-dialog-row">',
  9235. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9236. '<span class="ke-inline-block ke-input-color"></span>',
  9237. '</div>',
  9238. '</div>'
  9239. ].join('');
  9240. var bookmark = self.cmd.range.createBookmark();
  9241. var dialog = self.createDialog({
  9242. name : name,
  9243. width : 500,
  9244. title : self.lang(name),
  9245. body : html,
  9246. beforeRemove : function() {
  9247. colorBox.unbind();
  9248. },
  9249. yesBtn : {
  9250. name : self.lang('yes'),
  9251. click : function(e) {
  9252. var rows = rowsBox.val(),
  9253. cols = colsBox.val(),
  9254. width = widthBox.val(),
  9255. height = heightBox.val(),
  9256. widthType = widthTypeBox.val(),
  9257. heightType = heightTypeBox.val(),
  9258. padding = paddingBox.val(),
  9259. spacing = spacingBox.val(),
  9260. align = alignBox.val(),
  9261. border = borderBox.val(),
  9262. borderColor = K(colorBox[0]).html() || '',
  9263. bgColor = K(colorBox[1]).html() || '';
  9264. if (rows == 0 || !/^\d+$/.test(rows)) {
  9265. alert(self.lang('invalidRows'));
  9266. rowsBox[0].focus();
  9267. return;
  9268. }
  9269. if (cols == 0 || !/^\d+$/.test(cols)) {
  9270. alert(self.lang('invalidRows'));
  9271. colsBox[0].focus();
  9272. return;
  9273. }
  9274. if (!/^\d*$/.test(width)) {
  9275. alert(self.lang('invalidWidth'));
  9276. widthBox[0].focus();
  9277. return;
  9278. }
  9279. if (!/^\d*$/.test(height)) {
  9280. alert(self.lang('invalidHeight'));
  9281. heightBox[0].focus();
  9282. return;
  9283. }
  9284. if (!/^\d*$/.test(padding)) {
  9285. alert(self.lang('invalidPadding'));
  9286. paddingBox[0].focus();
  9287. return;
  9288. }
  9289. if (!/^\d*$/.test(spacing)) {
  9290. alert(self.lang('invalidSpacing'));
  9291. spacingBox[0].focus();
  9292. return;
  9293. }
  9294. if (!/^\d*$/.test(border)) {
  9295. alert(self.lang('invalidBorder'));
  9296. borderBox[0].focus();
  9297. return;
  9298. }
  9299. if (table) {
  9300. if (width !== '') {
  9301. table.width(width + widthType);
  9302. } else {
  9303. table.css('width', '');
  9304. }
  9305. if (table[0].width !== undefined) {
  9306. table.removeAttr('width');
  9307. }
  9308. if (height !== '') {
  9309. table.height(height + heightType);
  9310. } else {
  9311. table.css('height', '');
  9312. }
  9313. if (table[0].height !== undefined) {
  9314. table.removeAttr('height');
  9315. }
  9316. table.css('background-color', bgColor);
  9317. if (table[0].bgColor !== undefined) {
  9318. table.removeAttr('bgColor');
  9319. }
  9320. if (padding !== '') {
  9321. table[0].cellPadding = padding;
  9322. } else {
  9323. table.removeAttr('cellPadding');
  9324. }
  9325. if (spacing !== '') {
  9326. table[0].cellSpacing = spacing;
  9327. } else {
  9328. table.removeAttr('cellSpacing');
  9329. }
  9330. if (align !== '') {
  9331. table[0].align = align;
  9332. } else {
  9333. table.removeAttr('align');
  9334. }
  9335. if (border !== '') {
  9336. table.attr('border', border);
  9337. } else {
  9338. table.removeAttr('border');
  9339. }
  9340. if (border === '' || border === '0') {
  9341. table.addClass(zeroborder);
  9342. } else {
  9343. table.removeClass(zeroborder);
  9344. }
  9345. if (borderColor !== '') {
  9346. table.attr('borderColor', borderColor);
  9347. } else {
  9348. table.removeAttr('borderColor');
  9349. }
  9350. self.hideDialog().focus();
  9351. self.cmd.range.moveToBookmark(bookmark);
  9352. self.cmd.select();
  9353. self.addBookmark();
  9354. return;
  9355. }
  9356. var style = '';
  9357. if (width !== '') {
  9358. style += 'width:' + width + widthType + ';';
  9359. }
  9360. if (height !== '') {
  9361. style += 'height:' + height + heightType + ';';
  9362. }
  9363. if (bgColor !== '') {
  9364. style += 'background-color:' + bgColor + ';';
  9365. }
  9366. var html = '<table';
  9367. if (style !== '') {
  9368. html += ' style="' + style + '"';
  9369. }
  9370. if (padding !== '') {
  9371. html += ' cellpadding="' + padding + '"';
  9372. }
  9373. if (spacing !== '') {
  9374. html += ' cellspacing="' + spacing + '"';
  9375. }
  9376. if (align !== '') {
  9377. html += ' align="' + align + '"';
  9378. }
  9379. if (border !== '') {
  9380. html += ' border="' + border + '"';
  9381. }
  9382. if (border === '' || border === '0') {
  9383. html += ' class="' + zeroborder + '"';
  9384. }
  9385. if (borderColor !== '') {
  9386. html += ' bordercolor="' + borderColor + '"';
  9387. }
  9388. html += '>';
  9389. for (var i = 0; i < rows; i++) {
  9390. html += '<tr>';
  9391. for (var j = 0; j < cols; j++) {
  9392. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9393. }
  9394. html += '</tr>';
  9395. }
  9396. html += '</table>';
  9397. if (!K.IE) {
  9398. html += '<br />';
  9399. }
  9400. self.insertHtml(html);
  9401. self.select().hideDialog().focus();
  9402. self.addBookmark();
  9403. }
  9404. }
  9405. }),
  9406. div = dialog.div,
  9407. rowsBox = K('[name="rows"]', div).val(3),
  9408. colsBox = K('[name="cols"]', div).val(2),
  9409. widthBox = K('[name="width"]', div).val(100),
  9410. heightBox = K('[name="height"]', div),
  9411. widthTypeBox = K('[name="widthType"]', div),
  9412. heightTypeBox = K('[name="heightType"]', div),
  9413. paddingBox = K('[name="padding"]', div).val(2),
  9414. spacingBox = K('[name="spacing"]', div).val(0),
  9415. alignBox = K('[name="align"]', div),
  9416. borderBox = K('[name="border"]', div).val(1),
  9417. colorBox = K('.ke-input-color', div);
  9418. _initColorPicker(div, colorBox.eq(0));
  9419. _initColorPicker(div, colorBox.eq(1));
  9420. _setColor(colorBox.eq(0), '#000000');
  9421. _setColor(colorBox.eq(1), '');
  9422. rowsBox[0].focus();
  9423. rowsBox[0].select();
  9424. var table;
  9425. if (isInsert) {
  9426. return;
  9427. }
  9428. table = self.plugin.getSelectedTable();
  9429. if (table) {
  9430. rowsBox.val(table[0].rows.length);
  9431. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9432. rowsBox.attr('disabled', true);
  9433. colsBox.attr('disabled', true);
  9434. var match,
  9435. tableWidth = table[0].style.width || table[0].width,
  9436. tableHeight = table[0].style.height || table[0].height;
  9437. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9438. widthBox.val(match[1]);
  9439. widthTypeBox.val(match[2]);
  9440. } else {
  9441. widthBox.val('');
  9442. }
  9443. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9444. heightBox.val(match[1]);
  9445. heightTypeBox.val(match[2]);
  9446. }
  9447. paddingBox.val(table[0].cellPadding || '');
  9448. spacingBox.val(table[0].cellSpacing || '');
  9449. alignBox.val(table[0].align || '');
  9450. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9451. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9452. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9453. widthBox[0].focus();
  9454. widthBox[0].select();
  9455. }
  9456. },
  9457. cellprop : function() {
  9458. var html = [
  9459. '<div style="padding:20px;">',
  9460. '<div class="ke-dialog-row">',
  9461. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9462. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9463. '<select name="widthType">',
  9464. '<option value="%">' + lang.percent + '</option>',
  9465. '<option value="px">' + lang.px + '</option>',
  9466. '</select> &nbsp; ',
  9467. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9468. '<select name="heightType">',
  9469. '<option value="%">' + lang.percent + '</option>',
  9470. '<option value="px">' + lang.px + '</option>',
  9471. '</select>',
  9472. '</div>',
  9473. '<div class="ke-dialog-row">',
  9474. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9475. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9476. '<option value="">' + lang.alignDefault + '</option>',
  9477. '<option value="left">' + lang.alignLeft + '</option>',
  9478. '<option value="center">' + lang.alignCenter + '</option>',
  9479. '<option value="right">' + lang.alignRight + '</option>',
  9480. '</select> ',
  9481. lang.verticalAlign + ' <select name="verticalAlign">',
  9482. '<option value="">' + lang.alignDefault + '</option>',
  9483. '<option value="top">' + lang.alignTop + '</option>',
  9484. '<option value="middle">' + lang.alignMiddle + '</option>',
  9485. '<option value="bottom">' + lang.alignBottom + '</option>',
  9486. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9487. '</select>',
  9488. '</div>',
  9489. '<div class="ke-dialog-row">',
  9490. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9491. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9492. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9493. '</div>',
  9494. '<div class="ke-dialog-row">',
  9495. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9496. '<span class="ke-inline-block ke-input-color"></span>',
  9497. '</div>',
  9498. '</div>'
  9499. ].join('');
  9500. var bookmark = self.cmd.range.createBookmark();
  9501. var dialog = self.createDialog({
  9502. name : name,
  9503. width : 500,
  9504. title : self.lang('tablecell'),
  9505. body : html,
  9506. beforeRemove : function() {
  9507. colorBox.unbind();
  9508. },
  9509. yesBtn : {
  9510. name : self.lang('yes'),
  9511. click : function(e) {
  9512. var width = widthBox.val(),
  9513. height = heightBox.val(),
  9514. widthType = widthTypeBox.val(),
  9515. heightType = heightTypeBox.val(),
  9516. padding = paddingBox.val(),
  9517. spacing = spacingBox.val(),
  9518. textAlign = textAlignBox.val(),
  9519. verticalAlign = verticalAlignBox.val(),
  9520. border = borderBox.val(),
  9521. borderColor = K(colorBox[0]).html() || '',
  9522. bgColor = K(colorBox[1]).html() || '';
  9523. if (!/^\d*$/.test(width)) {
  9524. alert(self.lang('invalidWidth'));
  9525. widthBox[0].focus();
  9526. return;
  9527. }
  9528. if (!/^\d*$/.test(height)) {
  9529. alert(self.lang('invalidHeight'));
  9530. heightBox[0].focus();
  9531. return;
  9532. }
  9533. if (!/^\d*$/.test(border)) {
  9534. alert(self.lang('invalidBorder'));
  9535. borderBox[0].focus();
  9536. return;
  9537. }
  9538. cell.css({
  9539. width : width !== '' ? (width + widthType) : '',
  9540. height : height !== '' ? (height + heightType) : '',
  9541. 'background-color' : bgColor,
  9542. 'text-align' : textAlign,
  9543. 'vertical-align' : verticalAlign,
  9544. 'border-width' : border,
  9545. 'border-style' : border !== '' ? 'solid' : '',
  9546. 'border-color' : borderColor
  9547. });
  9548. self.hideDialog().focus();
  9549. self.cmd.range.moveToBookmark(bookmark);
  9550. self.cmd.select();
  9551. self.addBookmark();
  9552. }
  9553. }
  9554. }),
  9555. div = dialog.div,
  9556. widthBox = K('[name="width"]', div).val(100),
  9557. heightBox = K('[name="height"]', div),
  9558. widthTypeBox = K('[name="widthType"]', div),
  9559. heightTypeBox = K('[name="heightType"]', div),
  9560. paddingBox = K('[name="padding"]', div).val(2),
  9561. spacingBox = K('[name="spacing"]', div).val(0),
  9562. textAlignBox = K('[name="textAlign"]', div),
  9563. verticalAlignBox = K('[name="verticalAlign"]', div),
  9564. borderBox = K('[name="border"]', div).val(1),
  9565. colorBox = K('.ke-input-color', div);
  9566. _initColorPicker(div, colorBox.eq(0));
  9567. _initColorPicker(div, colorBox.eq(1));
  9568. _setColor(colorBox.eq(0), '#000000');
  9569. _setColor(colorBox.eq(1), '');
  9570. widthBox[0].focus();
  9571. widthBox[0].select();
  9572. var cell = self.plugin.getSelectedCell();
  9573. var match,
  9574. cellWidth = cell[0].style.width || cell[0].width || '',
  9575. cellHeight = cell[0].style.height || cell[0].height || '';
  9576. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9577. widthBox.val(match[1]);
  9578. widthTypeBox.val(match[2]);
  9579. } else {
  9580. widthBox.val('');
  9581. }
  9582. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9583. heightBox.val(match[1]);
  9584. heightTypeBox.val(match[2]);
  9585. }
  9586. textAlignBox.val(cell[0].style.textAlign || '');
  9587. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9588. var border = cell[0].style.borderWidth || '';
  9589. if (border) {
  9590. border = parseInt(border);
  9591. }
  9592. borderBox.val(border);
  9593. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9594. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9595. widthBox[0].focus();
  9596. widthBox[0].select();
  9597. },
  9598. insert : function() {
  9599. this.prop(true);
  9600. },
  9601. 'delete' : function() {
  9602. var table = self.plugin.getSelectedTable();
  9603. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9604. self.cmd.select();
  9605. table.remove();
  9606. self.addBookmark();
  9607. },
  9608. colinsert : function(offset) {
  9609. var table = self.plugin.getSelectedTable()[0],
  9610. row = self.plugin.getSelectedRow()[0],
  9611. cell = self.plugin.getSelectedCell()[0],
  9612. index = cell.cellIndex + offset;
  9613. index += table.rows[0].cells.length - row.cells.length;
  9614. for (var i = 0, len = table.rows.length; i < len; i++) {
  9615. var newRow = table.rows[i],
  9616. newCell = newRow.insertCell(index);
  9617. newCell.innerHTML = K.IE ? '' : '<br />';
  9618. index = _getCellIndex(table, newRow, newCell);
  9619. }
  9620. self.cmd.range.selectNodeContents(cell).collapse(true);
  9621. self.cmd.select();
  9622. self.addBookmark();
  9623. },
  9624. colinsertleft : function() {
  9625. this.colinsert(0);
  9626. },
  9627. colinsertright : function() {
  9628. this.colinsert(1);
  9629. },
  9630. rowinsert : function(offset) {
  9631. var table = self.plugin.getSelectedTable()[0],
  9632. row = self.plugin.getSelectedRow()[0],
  9633. cell = self.plugin.getSelectedCell()[0];
  9634. var rowIndex = row.rowIndex;
  9635. if (offset === 1) {
  9636. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9637. }
  9638. var newRow = table.insertRow(rowIndex);
  9639. for (var i = 0, len = row.cells.length; i < len; i++) {
  9640. if (row.cells[i].rowSpan > 1) {
  9641. len -= row.cells[i].rowSpan - 1;
  9642. }
  9643. var newCell = newRow.insertCell(i);
  9644. if (offset === 1 && row.cells[i].colSpan > 1) {
  9645. newCell.colSpan = row.cells[i].colSpan;
  9646. }
  9647. newCell.innerHTML = K.IE ? '' : '<br />';
  9648. }
  9649. for (var j = rowIndex; j >= 0; j--) {
  9650. var cells = table.rows[j].cells;
  9651. if (cells.length > i) {
  9652. for (var k = cell.cellIndex; k >= 0; k--) {
  9653. if (cells[k].rowSpan > 1) {
  9654. cells[k].rowSpan += 1;
  9655. }
  9656. }
  9657. break;
  9658. }
  9659. }
  9660. self.cmd.range.selectNodeContents(cell).collapse(true);
  9661. self.cmd.select();
  9662. self.addBookmark();
  9663. },
  9664. rowinsertabove : function() {
  9665. this.rowinsert(0);
  9666. },
  9667. rowinsertbelow : function() {
  9668. this.rowinsert(1);
  9669. },
  9670. rowmerge : function() {
  9671. var table = self.plugin.getSelectedTable()[0],
  9672. row = self.plugin.getSelectedRow()[0],
  9673. cell = self.plugin.getSelectedCell()[0],
  9674. rowIndex = row.rowIndex,
  9675. nextRowIndex = rowIndex + cell.rowSpan,
  9676. nextRow = table.rows[nextRowIndex];
  9677. if (table.rows.length <= nextRowIndex) {
  9678. return;
  9679. }
  9680. var cellIndex = cell.cellIndex;
  9681. if (nextRow.cells.length <= cellIndex) {
  9682. return;
  9683. }
  9684. var nextCell = nextRow.cells[cellIndex];
  9685. if (cell.colSpan !== nextCell.colSpan) {
  9686. return;
  9687. }
  9688. cell.rowSpan += nextCell.rowSpan;
  9689. nextRow.deleteCell(cellIndex);
  9690. self.cmd.range.selectNodeContents(cell).collapse(true);
  9691. self.cmd.select();
  9692. self.addBookmark();
  9693. },
  9694. colmerge : function() {
  9695. var table = self.plugin.getSelectedTable()[0],
  9696. row = self.plugin.getSelectedRow()[0],
  9697. cell = self.plugin.getSelectedCell()[0],
  9698. rowIndex = row.rowIndex,
  9699. cellIndex = cell.cellIndex,
  9700. nextCellIndex = cellIndex + 1;
  9701. if (row.cells.length <= nextCellIndex) {
  9702. return;
  9703. }
  9704. var nextCell = row.cells[nextCellIndex];
  9705. if (cell.rowSpan !== nextCell.rowSpan) {
  9706. return;
  9707. }
  9708. cell.colSpan += nextCell.colSpan;
  9709. row.deleteCell(nextCellIndex);
  9710. self.cmd.range.selectNodeContents(cell).collapse(true);
  9711. self.cmd.select();
  9712. self.addBookmark();
  9713. },
  9714. rowsplit : function() {
  9715. var table = self.plugin.getSelectedTable()[0],
  9716. row = self.plugin.getSelectedRow()[0],
  9717. cell = self.plugin.getSelectedCell()[0],
  9718. rowIndex = row.rowIndex;
  9719. if (cell.rowSpan === 1) {
  9720. return;
  9721. }
  9722. var cellIndex = _getCellIndex(table, row, cell);
  9723. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9724. var newRow = table.rows[rowIndex + i],
  9725. newCell = newRow.insertCell(cellIndex);
  9726. if (cell.colSpan > 1) {
  9727. newCell.colSpan = cell.colSpan;
  9728. }
  9729. newCell.innerHTML = K.IE ? '' : '<br />';
  9730. cellIndex = _getCellIndex(table, newRow, newCell);
  9731. }
  9732. K(cell).removeAttr('rowSpan');
  9733. self.cmd.range.selectNodeContents(cell).collapse(true);
  9734. self.cmd.select();
  9735. self.addBookmark();
  9736. },
  9737. colsplit : function() {
  9738. var table = self.plugin.getSelectedTable()[0],
  9739. row = self.plugin.getSelectedRow()[0],
  9740. cell = self.plugin.getSelectedCell()[0],
  9741. cellIndex = cell.cellIndex;
  9742. if (cell.colSpan === 1) {
  9743. return;
  9744. }
  9745. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9746. var newCell = row.insertCell(cellIndex + i);
  9747. if (cell.rowSpan > 1) {
  9748. newCell.rowSpan = cell.rowSpan;
  9749. }
  9750. newCell.innerHTML = K.IE ? '' : '<br />';
  9751. }
  9752. K(cell).removeAttr('colSpan');
  9753. self.cmd.range.selectNodeContents(cell).collapse(true);
  9754. self.cmd.select();
  9755. self.addBookmark();
  9756. },
  9757. coldelete : function() {
  9758. var table = self.plugin.getSelectedTable()[0],
  9759. row = self.plugin.getSelectedRow()[0],
  9760. cell = self.plugin.getSelectedCell()[0],
  9761. index = cell.cellIndex;
  9762. for (var i = 0, len = table.rows.length; i < len; i++) {
  9763. var newRow = table.rows[i],
  9764. newCell = newRow.cells[index];
  9765. if (newCell.colSpan > 1) {
  9766. newCell.colSpan -= 1;
  9767. if (newCell.colSpan === 1) {
  9768. K(newCell).removeAttr('colSpan');
  9769. }
  9770. } else {
  9771. newRow.deleteCell(index);
  9772. }
  9773. if (newCell.rowSpan > 1) {
  9774. i += newCell.rowSpan - 1;
  9775. }
  9776. }
  9777. if (row.cells.length === 0) {
  9778. self.cmd.range.setStartBefore(table).collapse(true);
  9779. self.cmd.select();
  9780. K(table).remove();
  9781. } else {
  9782. self.cmd.selection(true);
  9783. }
  9784. self.addBookmark();
  9785. },
  9786. rowdelete : function() {
  9787. var table = self.plugin.getSelectedTable()[0],
  9788. row = self.plugin.getSelectedRow()[0],
  9789. cell = self.plugin.getSelectedCell()[0],
  9790. rowIndex = row.rowIndex;
  9791. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9792. table.deleteRow(rowIndex + i);
  9793. }
  9794. if (table.rows.length === 0) {
  9795. self.cmd.range.setStartBefore(table).collapse(true);
  9796. self.cmd.select();
  9797. K(table).remove();
  9798. } else {
  9799. self.cmd.selection(true);
  9800. }
  9801. self.addBookmark();
  9802. }
  9803. };
  9804. self.clickToolbar(name, self.plugin.table.prop);
  9805. });
  9806. /*******************************************************************************
  9807. * KindEditor - WYSIWYG HTML Editor for Internet
  9808. * Copyright (C) 2006-2011 kindsoft.net
  9809. *
  9810. * @author Roddy <luolonghao@gmail.com>
  9811. * @site http://www.kindsoft.net/
  9812. * @licence http://www.kindsoft.net/license.php
  9813. *******************************************************************************/
  9814. KindEditor.plugin('template', function(K) {
  9815. var self = this, name = 'template', lang = self.lang(name + '.'),
  9816. htmlPath = self.pluginsPath + name + '/html/';
  9817. function getFilePath(fileName) {
  9818. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9819. }
  9820. self.clickToolbar(name, function() {
  9821. var lang = self.lang(name + '.'),
  9822. arr = ['<div style="padding:10px 20px;">',
  9823. '<div class="ke-header">',
  9824. '<div class="ke-left">',
  9825. lang. selectTemplate + ' <select>'];
  9826. K.each(lang.fileList, function(key, val) {
  9827. arr.push('<option value="' + key + '">' + val + '</option>');
  9828. });
  9829. html = [arr.join(''),
  9830. '</select></div>',
  9831. '<div class="ke-right">',
  9832. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9833. '</div>',
  9834. '<div class="ke-clearfix"></div>',
  9835. '</div>',
  9836. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9837. '</div>'].join('');
  9838. var dialog = self.createDialog({
  9839. name : name,
  9840. width : 500,
  9841. title : self.lang(name),
  9842. body : html,
  9843. yesBtn : {
  9844. name : self.lang('yes'),
  9845. click : function(e) {
  9846. var doc = K.iframeDoc(iframe);
  9847. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9848. }
  9849. }
  9850. });
  9851. var selectBox = K('select', dialog.div),
  9852. checkbox = K('[name="replaceFlag"]', dialog.div),
  9853. iframe = K('iframe', dialog.div);
  9854. checkbox[0].checked = true;
  9855. iframe.attr('src', getFilePath(selectBox.val()));
  9856. selectBox.change(function() {
  9857. iframe.attr('src', getFilePath(this.value));
  9858. });
  9859. });
  9860. });
  9861. /*******************************************************************************
  9862. * KindEditor - WYSIWYG HTML Editor for Internet
  9863. * Copyright (C) 2006-2011 kindsoft.net
  9864. *
  9865. * @author Roddy <luolonghao@gmail.com>
  9866. * @site http://www.kindsoft.net/
  9867. * @licence http://www.kindsoft.net/license.php
  9868. *******************************************************************************/
  9869. KindEditor.plugin('wordpaste', function(K) {
  9870. var self = this, name = 'wordpaste';
  9871. self.clickToolbar(name, function() {
  9872. var lang = self.lang(name + '.'),
  9873. html = '<div style="padding:10px 20px;">' +
  9874. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9875. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9876. '</div>',
  9877. dialog = self.createDialog({
  9878. name : name,
  9879. width : 450,
  9880. title : self.lang(name),
  9881. body : html,
  9882. yesBtn : {
  9883. name : self.lang('yes'),
  9884. click : function(e) {
  9885. var str = doc.body.innerHTML;
  9886. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9887. self.insertHtml(str).hideDialog().focus();
  9888. }
  9889. }
  9890. }),
  9891. div = dialog.div,
  9892. iframe = K('iframe', div),
  9893. doc = K.iframeDoc(iframe);
  9894. if (!K.IE) {
  9895. doc.designMode = 'on';
  9896. }
  9897. doc.open();
  9898. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9899. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9900. if (!K.IE) {
  9901. doc.write('<br />');
  9902. }
  9903. doc.write('</body></html>');
  9904. doc.close();
  9905. if (K.IE) {
  9906. doc.body.contentEditable = 'true';
  9907. }
  9908. iframe[0].contentWindow.focus();
  9909. });
  9910. });
  9911. KindEditor.plugin('fixtoolbar', function (K) {
  9912. var self = this;
  9913. if (!self.fixToolBar) {
  9914. return;
  9915. }
  9916. function init() {
  9917. var toolbar = K('.ke-toolbar');
  9918. var originY = toolbar.pos().y;
  9919. K(window).bind('scroll', function () {
  9920. if (toolbar.css('position') == 'fixed') {
  9921. if(document.body.scrollTop - originY < 0){
  9922. toolbar.css('position', 'static');
  9923. toolbar.css('top', 'auto');
  9924. }
  9925. } else {
  9926. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9927. toolbar.css('position', 'fixed');
  9928. toolbar.css('top', 0);
  9929. }
  9930. }
  9931. });
  9932. }
  9933. if (self.isCreated) {
  9934. init();
  9935. } else {
  9936. self.afterCreate(init);
  9937. }
  9938. });
  9939. //自定义资源库
  9940. KindEditor.plugin('res', function(K) {
  9941. var self = this;
  9942. // 点击图标时执行
  9943. self.clickToolbar('res', function() {
  9944. var clickFn = function(url, title, id) {
  9945. var html = '<embed src="{url}" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" id="{id}"/>';
  9946. html = html.replace('{url}', url);
  9947. html = html.replace('{id}', id);
  9948. self.insertHtml(html);
  9949. };
  9950. editorShowUpload('', self.fileManagerJson, '视频库', clickFn, this);
  9951. });
  9952. });
  9953. function autoImg(self) {
  9954. var index = self.index;
  9955. var haspicContainer = document.getElementById("has_pic_" + index);
  9956. if (haspicContainer == null) {
  9957. haspicContainer = document.createElement("div");
  9958. haspicContainer.id = "has_pic_" + index;
  9959. haspicContainer.innerHTML = "<input type='text' id='piclist_"+index+"' value='' style='display:none;'/><div id='upload_"+index+"'><b>您有图片需要上传到服务器</b>&nbsp;&nbsp;<a href='javascript:uploadpic(\""+self.uploadJson+"\", \""+self.filePostName+"\", \""+index+"\");' >上传</a></div><div id='confirm_"+index+"'></div>";
  9960. $(".ke-toolbar").eq(index).after(haspicContainer);
  9961. }
  9962. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  9963. var piccount = 0;
  9964. var sstr = '';
  9965. $(img).each(function (i) {
  9966. var that = $(this);
  9967. var host = gethost(self.uploadJson);
  9968. if (self.uploadYunJson && self.uploadYunJson.host) {
  9969. var yhost = gethost(self.uploadYunJson.host);
  9970. }
  9971. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  9972. var n = gethost(that.attr("src"));
  9973. if (yhost) {
  9974. if (host != n && yhost != n) {
  9975. piccount++;
  9976. if (i == $(img).length - 1)
  9977. sstr += that.attr("src");
  9978. else
  9979. sstr += that.attr("src") + ",";
  9980. }
  9981. } else {
  9982. if (host != n) {
  9983. piccount++;
  9984. if (i == $(img).length - 1)
  9985. sstr += that.attr("src");
  9986. else
  9987. sstr += that.attr("src") + ",";
  9988. }
  9989. }
  9990. }
  9991. });
  9992. $("#piclist_" + index).val(encodeURIComponent(sstr));
  9993. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  9994. }
  9995. function closeupload(index) {
  9996. $("#has_pic_" + index).hide();
  9997. $("#upload_" + index).show();
  9998. }
  9999. function uploadpic(url, name, index) {
  10000. var piclist = encodeURI($("#piclist_" + index).val());
  10001. if (piclist.length == 0) return false;
  10002. $.ajax({
  10003. url: url.replace('kindeditor', 'copys') + '&json=1',
  10004. data: name + "=" + piclist,
  10005. type: "POST",
  10006. dataType: "json",
  10007. beforeSend: function () {
  10008. $("#upload_" + index).hide();
  10009. $("#confirm_" + index).text("正在上传中...");
  10010. },
  10011. success: function (msg) {
  10012. var url = msg.data;
  10013. if (url !== "") {
  10014. var str = new Array();
  10015. str = url.split(',');
  10016. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10017. $(img).each(function (i) {
  10018. var that = $(this);
  10019. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10020. that.attr("src", str[i]);
  10021. that.attr("data-ke-src", str[i]);
  10022. }
  10023. });
  10024. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  10025. }
  10026. else $("#confirm_" + index).text("上传失败!");
  10027. }
  10028. });
  10029. }
  10030. function gethost(url){
  10031. var reg = /^http(s)?:\/\/(.*?)\//;
  10032. return reg.exec(url)[2];
  10033. }