kindeditor-all.js 297 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2019 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 (2019-03-07)
  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 (2019-03-07)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  24. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  25. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  26. _OPERA = _ua.indexOf('opera') > -1,
  27. _MOBILE = _ua.indexOf('mobile') > -1,
  28. _IOS = /ipad|iphone|ipod/.test(_ua),
  29. _QUIRKS = document.compatMode != 'CSS1Compat',
  30. _IERANGE = !window.getSelection,
  31. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  32. _V = _matches ? _matches[1] : '0',
  33. _TIME = new Date().getTime();
  34. function _isArray(val) {
  35. if (!val) {
  36. return false;
  37. }
  38. return Object.prototype.toString.call(val) === '[object Array]';
  39. }
  40. function _isFunction(val) {
  41. if (!val) {
  42. return false;
  43. }
  44. return Object.prototype.toString.call(val) === '[object Function]';
  45. }
  46. function _inArray(val, arr) {
  47. for (var i = 0, len = arr.length; i < len; i++) {
  48. if (val === arr[i]) {
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. function _each(obj, fn) {
  55. if (_isArray(obj)) {
  56. for (var i = 0, len = obj.length; i < len; i++) {
  57. if (fn.call(obj[i], i, obj[i]) === false) {
  58. break;
  59. }
  60. }
  61. } else {
  62. for (var key in obj) {
  63. if (obj.hasOwnProperty(key)) {
  64. if (fn.call(obj[key], key, obj[key]) === false) {
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. function _trim(str) {
  72. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  73. }
  74. function _inString(val, str, delimiter) {
  75. delimiter = delimiter === undefined ? ',' : delimiter;
  76. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  77. }
  78. function _addUnit(val, unit) {
  79. unit = unit || 'px';
  80. return val && /^-?\d+(?:\.\d+)?$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function(key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function(key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () {};
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function(key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG : false,
  180. VERSION : _VERSION,
  181. IE : _IE,
  182. GECKO : _GECKO,
  183. WEBKIT : _WEBKIT,
  184. OPERA : _OPERA,
  185. V : _V,
  186. TIME : _TIME,
  187. each : _each,
  188. isArray : _isArray,
  189. isFunction : _isFunction,
  190. inArray : _inArray,
  191. inString : _inString,
  192. trim : _trim,
  193. addUnit : _addUnit,
  194. removeUnit : _removeUnit,
  195. escape : _escape,
  196. unescape : _unescape,
  197. toCamel : _toCamel,
  198. toHex : _toHex,
  199. toMap : _toMap,
  200. toArray : _toArray,
  201. undef : _undef,
  202. invalidUrl : _invalidUrl,
  203. addParam : _addParam,
  204. extend : _extend,
  205. json : _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. designMode : true,
  230. fullscreenMode : false,
  231. filterMode : true,
  232. wellFormatMode : true,
  233. shadowMode : true,
  234. loadStyleMode : true,
  235. basePath : K.basePath,
  236. themesPath : K.basePath + 'themes/',
  237. langPath : K.basePath + 'lang/',
  238. pluginsPath : K.basePath + 'plugins/',
  239. themeType : 'default',
  240. langType : 'zh-CN',
  241. urlType : '',
  242. newlineTag : 'p',
  243. resizeType : 2,
  244. syncType : 'form',
  245. pasteType : 2,
  246. dialogAlignType : 'page',
  247. useContextmenu : true,
  248. fullscreenShortcut : false,
  249. bodyClass : 'ke-content',
  250. indentChar : '\t',
  251. cssPath : '',
  252. cssData : '',
  253. minWidth : 650,
  254. minHeight : 100,
  255. minChangeSize : 50,
  256. zIndex : 811213,
  257. items : [
  258. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  259. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  260. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  261. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  262. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  263. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  264. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  265. 'anchor', 'link', 'unlink', '|', 'about'
  266. ],
  267. noDisableItems : ['source', 'fullscreen'],
  268. colorTable : [
  269. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  270. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  271. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  272. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  273. ],
  274. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  275. htmlTags : {
  276. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  277. span : [
  278. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  279. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  280. ],
  281. div : [
  282. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  283. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  284. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  285. ],
  286. table: [
  287. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  288. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  289. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  290. '.width', '.height', '.border-collapse'
  291. ],
  292. 'td,th': [
  293. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  294. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  295. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  296. ],
  297. a : ['id', 'class', 'href', 'target', 'name'],
  298. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  299. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  300. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  301. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  302. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  303. ],
  304. pre : ['id', 'class'],
  305. hr : ['id', 'class', '.page-break-after'],
  306. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  307. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  308. },
  309. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  310. };
  311. var _useCapture = false;
  312. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  313. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  314. var _CHANGE_KEY_MAP = {};
  315. _each(_INPUT_KEY_MAP, function(key, val) {
  316. _CHANGE_KEY_MAP[key] = val;
  317. });
  318. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  319. _CHANGE_KEY_MAP[key] = val;
  320. });
  321. function _bindEvent(el, type, fn) {
  322. if (el.addEventListener){
  323. el.addEventListener(type, fn, _useCapture);
  324. } else if (el.attachEvent){
  325. el.attachEvent('on' + type, fn);
  326. }
  327. }
  328. function _unbindEvent(el, type, fn) {
  329. if (el.removeEventListener){
  330. el.removeEventListener(type, fn, _useCapture);
  331. } else if (el.detachEvent){
  332. el.detachEvent('on' + type, fn);
  333. }
  334. }
  335. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  336. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  337. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  338. function KEvent(el, event) {
  339. this.init(el, event);
  340. }
  341. _extend(KEvent, {
  342. init : function(el, event) {
  343. var self = this, doc = el.ownerDocument || el.document || el;
  344. self.event = event;
  345. _each(_EVENT_PROPS, function(key, val) {
  346. self[val] = event[val];
  347. });
  348. if (!self.target) {
  349. self.target = self.srcElement || doc;
  350. }
  351. if (self.target.nodeType === 3) {
  352. self.target = self.target.parentNode;
  353. }
  354. if (!self.relatedTarget && self.fromElement) {
  355. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  356. }
  357. if (self.pageX == null && self.clientX != null) {
  358. var d = doc.documentElement, body = doc.body;
  359. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  360. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  361. }
  362. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  363. self.which = self.charCode || self.keyCode;
  364. }
  365. if (!self.metaKey && self.ctrlKey) {
  366. self.metaKey = self.ctrlKey;
  367. }
  368. if (!self.which && self.button !== undefined) {
  369. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  370. }
  371. switch (self.which) {
  372. case 186 :
  373. self.which = 59;
  374. break;
  375. case 187 :
  376. case 107 :
  377. case 43 :
  378. self.which = 61;
  379. break;
  380. case 189 :
  381. case 45 :
  382. self.which = 109;
  383. break;
  384. case 42 :
  385. self.which = 106;
  386. break;
  387. case 47 :
  388. self.which = 111;
  389. break;
  390. case 78 :
  391. self.which = 110;
  392. break;
  393. }
  394. if (self.which >= 96 && self.which <= 105) {
  395. self.which -= 48;
  396. }
  397. },
  398. preventDefault : function() {
  399. var ev = this.event;
  400. if (ev.preventDefault) {
  401. ev.preventDefault();
  402. } else {
  403. ev.returnValue = false;
  404. }
  405. },
  406. stopPropagation : function() {
  407. var ev = this.event;
  408. if (ev.stopPropagation) {
  409. ev.stopPropagation();
  410. } else {
  411. ev.cancelBubble = true;
  412. }
  413. },
  414. stop : function() {
  415. this.preventDefault();
  416. this.stopPropagation();
  417. }
  418. });
  419. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  420. function _getId(el) {
  421. return el[_eventExpendo] || null;
  422. }
  423. function _setId(el) {
  424. el[_eventExpendo] = ++_eventId;
  425. return _eventId;
  426. }
  427. function _removeId(el) {
  428. try {
  429. delete el[_eventExpendo];
  430. } catch(e) {
  431. if (el.removeAttribute) {
  432. el.removeAttribute(_eventExpendo);
  433. }
  434. }
  435. }
  436. function _bind(el, type, fn) {
  437. if (type.indexOf(',') >= 0) {
  438. _each(type.split(','), function() {
  439. _bind(el, this, fn);
  440. });
  441. return;
  442. }
  443. var id = _getId(el);
  444. if (!id) {
  445. id = _setId(el);
  446. }
  447. if (_eventData[id] === undefined) {
  448. _eventData[id] = {};
  449. }
  450. var events = _eventData[id][type];
  451. if (events && events.length > 0) {
  452. _unbindEvent(el, type, events[0]);
  453. } else {
  454. _eventData[id][type] = [];
  455. _eventData[id].el = el;
  456. }
  457. events = _eventData[id][type];
  458. if (events.length === 0) {
  459. events[0] = function(e) {
  460. var kevent = e ? new KEvent(el, e) : undefined;
  461. _each(events, function(i, event) {
  462. if (i > 0 && event) {
  463. event.call(el, kevent);
  464. }
  465. });
  466. };
  467. }
  468. if (_inArray(fn, events) < 0) {
  469. events.push(fn);
  470. }
  471. _bindEvent(el, type, events[0]);
  472. }
  473. function _unbind(el, type, fn) {
  474. if (type && type.indexOf(',') >= 0) {
  475. _each(type.split(','), function() {
  476. _unbind(el, this, fn);
  477. });
  478. return;
  479. }
  480. var id = _getId(el);
  481. if (!id) {
  482. return;
  483. }
  484. if (type === undefined) {
  485. if (id in _eventData) {
  486. _each(_eventData[id], function(key, events) {
  487. if (key != 'el' && events.length > 0) {
  488. _unbindEvent(el, key, events[0]);
  489. }
  490. });
  491. delete _eventData[id];
  492. _removeId(el);
  493. }
  494. return;
  495. }
  496. if (!_eventData[id]) {
  497. return;
  498. }
  499. var events = _eventData[id][type];
  500. if (events && events.length > 0) {
  501. if (fn === undefined) {
  502. _unbindEvent(el, type, events[0]);
  503. delete _eventData[id][type];
  504. } else {
  505. _each(events, function(i, event) {
  506. if (i > 0 && event === fn) {
  507. events.splice(i, 1);
  508. }
  509. });
  510. if (events.length == 1) {
  511. _unbindEvent(el, type, events[0]);
  512. delete _eventData[id][type];
  513. }
  514. }
  515. var count = 0;
  516. _each(_eventData[id], function() {
  517. count++;
  518. });
  519. if (count < 2) {
  520. delete _eventData[id];
  521. _removeId(el);
  522. }
  523. }
  524. }
  525. function _fire(el, type) {
  526. if (type.indexOf(',') >= 0) {
  527. _each(type.split(','), function() {
  528. _fire(el, this);
  529. });
  530. return;
  531. }
  532. var id = _getId(el);
  533. if (!id) {
  534. return;
  535. }
  536. var events = _eventData[id][type];
  537. if (_eventData[id] && events && events.length > 0) {
  538. events[0]();
  539. }
  540. }
  541. function _ctrl(el, key, fn) {
  542. var self = this;
  543. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  544. _bind(el, 'keydown', function(e) {
  545. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  546. fn.call(el);
  547. e.stop();
  548. }
  549. });
  550. }
  551. var _readyFinished = false;
  552. function _ready(fn) {
  553. if (_readyFinished) {
  554. fn(KindEditor);
  555. return;
  556. }
  557. var loaded = false;
  558. function readyFunc() {
  559. if (!loaded) {
  560. loaded = true;
  561. fn(KindEditor);
  562. _readyFinished = true;
  563. }
  564. }
  565. function ieReadyFunc() {
  566. if (!loaded) {
  567. try {
  568. document.documentElement.doScroll('left');
  569. } catch(e) {
  570. setTimeout(ieReadyFunc, 100);
  571. return;
  572. }
  573. readyFunc();
  574. }
  575. }
  576. function ieReadyStateFunc() {
  577. if (document.readyState === 'complete') {
  578. readyFunc();
  579. }
  580. }
  581. if (document.addEventListener) {
  582. _bind(document, 'DOMContentLoaded', readyFunc);
  583. } else if (document.attachEvent) {
  584. _bind(document, 'readystatechange', ieReadyStateFunc);
  585. var toplevel = false;
  586. try {
  587. toplevel = window.frameElement == null;
  588. } catch(e) {}
  589. if (document.documentElement.doScroll && toplevel) {
  590. ieReadyFunc();
  591. }
  592. }
  593. _bind(window, 'load', readyFunc);
  594. }
  595. if (window.attachEvent) {
  596. window.attachEvent('onunload', function() {
  597. _each(_eventData, function(key, events) {
  598. if (events.el) {
  599. _unbind(events.el);
  600. }
  601. });
  602. });
  603. }
  604. K.ctrl = _ctrl;
  605. K.ready = _ready;
  606. function _getCssList(css) {
  607. css = css.replace(/&quot;/g, '"');
  608. var list = {},
  609. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  610. match;
  611. while ((match = reg.exec(css))) {
  612. var key = _trim(match[1].toLowerCase()),
  613. val = _trim(_toHex(match[2]));
  614. list[key] = val;
  615. }
  616. return list;
  617. }
  618. function _getAttrList(tag) {
  619. var list = {},
  620. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  621. match;
  622. while ((match = reg.exec(tag))) {
  623. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  624. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  625. list[key] = val;
  626. }
  627. return list;
  628. }
  629. function _addClassToTag(tag, className) {
  630. if (/\s+class\s*=/.test(tag)) {
  631. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  632. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  633. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  634. } else {
  635. return $0;
  636. }
  637. });
  638. } else {
  639. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  640. }
  641. return tag;
  642. }
  643. function _formatCss(css) {
  644. var str = '';
  645. _each(_getCssList(css), function(key, val) {
  646. str += key + ':' + val + ';';
  647. });
  648. return str;
  649. }
  650. function _formatUrl(url, mode, host, pathname) {
  651. mode = _undef(mode, '').toLowerCase();
  652. if (url.substr(0, 5) != 'data:') {
  653. url = url.replace(/([^:])\/\//g, '$1/');
  654. }
  655. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  656. return url;
  657. }
  658. host = host || location.protocol + '//' + location.host;
  659. if (pathname === undefined) {
  660. var m = location.pathname.match(/^(\/.*)\//);
  661. pathname = m ? m[1] : '';
  662. }
  663. var match;
  664. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  665. if (match[1] !== host) {
  666. return url;
  667. }
  668. } else if (/^\w+:/.test(url)) {
  669. return url;
  670. }
  671. function getRealPath(path) {
  672. var parts = path.split('/'), paths = [];
  673. for (var i = 0, len = parts.length; i < len; i++) {
  674. var part = parts[i];
  675. if (part == '..') {
  676. if (paths.length > 0) {
  677. paths.pop();
  678. }
  679. } else if (part !== '' && part != '.') {
  680. paths.push(part);
  681. }
  682. }
  683. return '/' + paths.join('/');
  684. }
  685. if (/^\//.test(url)) {
  686. url = host + getRealPath(url.substr(1));
  687. } else if (!/^\w+:\/\//.test(url)) {
  688. url = host + getRealPath(pathname + '/' + url);
  689. }
  690. function getRelativePath(path, depth) {
  691. if (url.substr(0, path.length) === path) {
  692. var arr = [];
  693. for (var i = 0; i < depth; i++) {
  694. arr.push('..');
  695. }
  696. var prefix = '.';
  697. if (arr.length > 0) {
  698. prefix += '/' + arr.join('/');
  699. }
  700. if (pathname == '/') {
  701. prefix += '/';
  702. }
  703. return prefix + url.substr(path.length);
  704. } else {
  705. if ((match = /^(.*)\//.exec(path))) {
  706. return getRelativePath(match[1], ++depth);
  707. }
  708. }
  709. }
  710. if (mode === 'relative') {
  711. url = getRelativePath(host + pathname, 0).substr(2);
  712. } else if (mode === 'absolute') {
  713. if (url.substr(0, host.length) === host) {
  714. url = url.substr(host.length);
  715. }
  716. }
  717. return url;
  718. }
  719. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  720. if (html == null) {
  721. html = '';
  722. }
  723. urlType = urlType || '';
  724. wellFormatted = _undef(wellFormatted, false);
  725. indentChar = _undef(indentChar, '\t');
  726. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  727. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  728. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  729. });
  730. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  731. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  732. html = html.replace(/\u200B/g, '');
  733. html = html.replace(/\u00A9/g, '&copy;');
  734. html = html.replace(/\u00AE/g, '&reg;');
  735. html = html.replace(/\u2003/g, '&emsp;');
  736. html = html.replace(/\u3000/g, '&emsp;');
  737. html = html.replace(/<[^>]+/g, function($0) {
  738. return $0.replace(/\s+/g, ' ');
  739. });
  740. var htmlTagMap = {};
  741. if (htmlTags) {
  742. _each(htmlTags, function(key, val) {
  743. var arr = key.split(',');
  744. for (var i = 0, len = arr.length; i < len; i++) {
  745. htmlTagMap[arr[i]] = _toMap(val);
  746. }
  747. });
  748. if (!htmlTagMap.script) {
  749. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  750. }
  751. if (!htmlTagMap.style) {
  752. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  753. }
  754. }
  755. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  756. var tagStack = [];
  757. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  758. var full = $0,
  759. startNewline = $1 || '',
  760. startSlash = $2 || '',
  761. tagName = $3.toLowerCase(),
  762. attr = $4 || '',
  763. endSlash = $5 ? ' ' + $5 : '',
  764. endNewline = $6 || '';
  765. if (htmlTags && !htmlTagMap[tagName]) {
  766. return '';
  767. }
  768. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  769. endSlash = ' /';
  770. }
  771. if (_INLINE_TAG_MAP[tagName]) {
  772. if (startNewline) {
  773. startNewline = ' ';
  774. }
  775. if (endNewline) {
  776. endNewline = ' ';
  777. }
  778. }
  779. if (_PRE_TAG_MAP[tagName]) {
  780. if (startSlash) {
  781. endNewline = '\n';
  782. } else {
  783. startNewline = '\n';
  784. }
  785. }
  786. if (wellFormatted && tagName == 'br') {
  787. endNewline = '\n';
  788. }
  789. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  790. if (wellFormatted) {
  791. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  792. tagStack.pop();
  793. } else {
  794. tagStack.push(tagName);
  795. }
  796. startNewline = '\n';
  797. endNewline = '\n';
  798. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  799. startNewline += indentChar;
  800. if (!startSlash) {
  801. endNewline += indentChar;
  802. }
  803. }
  804. if (endSlash) {
  805. tagStack.pop();
  806. } else if (!startSlash) {
  807. endNewline += indentChar;
  808. }
  809. } else {
  810. startNewline = endNewline = '';
  811. }
  812. }
  813. if (attr !== '') {
  814. var attrMap = _getAttrList(full);
  815. if (tagName === 'font') {
  816. var fontStyleMap = {}, fontStyle = '';
  817. _each(attrMap, function(key, val) {
  818. if (key === 'color') {
  819. fontStyleMap.color = val;
  820. delete attrMap[key];
  821. }
  822. if (key === 'size') {
  823. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  824. delete attrMap[key];
  825. }
  826. if (key === 'face') {
  827. fontStyleMap['font-family'] = val;
  828. delete attrMap[key];
  829. }
  830. if (key === 'style') {
  831. fontStyle = val;
  832. }
  833. });
  834. if (fontStyle && !/;$/.test(fontStyle)) {
  835. fontStyle += ';';
  836. }
  837. _each(fontStyleMap, function(key, val) {
  838. if (val === '') {
  839. return;
  840. }
  841. if (/\s/.test(val)) {
  842. val = "'" + val + "'";
  843. }
  844. fontStyle += key + ':' + val + ';';
  845. });
  846. attrMap.style = fontStyle;
  847. }
  848. _each(attrMap, function(key, val) {
  849. if (_FILL_ATTR_MAP[key]) {
  850. attrMap[key] = key;
  851. }
  852. if (_inArray(key, ['src', 'href']) >= 0) {
  853. attrMap[key] = _formatUrl(val, urlType);
  854. }
  855. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  856. tagName === 'body' && key === 'contenteditable' ||
  857. /^kindeditor_\d+$/.test(key)) {
  858. delete attrMap[key];
  859. }
  860. if (key === 'style' && val !== '') {
  861. var styleMap = _getCssList(val);
  862. _each(styleMap, function(k, v) {
  863. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  864. delete styleMap[k];
  865. }
  866. });
  867. var style = '';
  868. _each(styleMap, function(k, v) {
  869. style += k + ':' + v + ';';
  870. });
  871. attrMap.style = style;
  872. }
  873. });
  874. attr = '';
  875. _each(attrMap, function(key, val) {
  876. if (key === 'style' && val === '') {
  877. return;
  878. }
  879. val = val.replace(/"/g, '&quot;');
  880. attr += ' ' + key + '="' + val + '"';
  881. });
  882. }
  883. if (tagName === 'font') {
  884. tagName = 'span';
  885. }
  886. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  887. });
  888. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  889. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  890. });
  891. html = html.replace(/\n\s*\n/g, '\n');
  892. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  893. return _trim(html);
  894. }
  895. function _clearMsWord(html, htmlTags) {
  896. html = html.replace(/<meta[\s\S]*?>/ig, '')
  897. .replace(/<![\s\S]*?>/ig, '')
  898. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  899. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  900. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  901. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  902. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  903. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  904. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  905. });
  906. return _formatHtml(html, htmlTags);
  907. }
  908. function _mediaType(src) {
  909. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  910. return 'audio/x-pn-realaudio-plugin';
  911. }
  912. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  913. return 'application/x-shockwave-flash';
  914. }
  915. return 'video/x-ms-asf-plugin';
  916. }
  917. function _mediaClass(type) {
  918. if (/realaudio/i.test(type)) {
  919. return 'ke-rm';
  920. }
  921. if (/flash/i.test(type)) {
  922. return 'ke-flash';
  923. }
  924. return 'ke-media';
  925. }
  926. function _mediaAttrs(srcTag) {
  927. return _getAttrList(unescape(srcTag));
  928. }
  929. function _mediaEmbed(attrs) {
  930. var html = '<embed ';
  931. _each(attrs, function(key, val) {
  932. html += key + '="' + val + '" ';
  933. });
  934. html += '/>';
  935. return html;
  936. }
  937. function _mediaImg(blankPath, attrs) {
  938. var width = attrs.width,
  939. height = attrs.height,
  940. type = attrs.type || _mediaType(attrs.src),
  941. srcTag = _mediaEmbed(attrs),
  942. style = '';
  943. if (/\D/.test(width)) {
  944. style += 'width:' + width + ';';
  945. } else if (width > 0) {
  946. style += 'width:' + width + 'px;';
  947. }
  948. if (/\D/.test(height)) {
  949. style += 'height:' + height + ';';
  950. } else if (height > 0) {
  951. style += 'height:' + height + 'px;';
  952. }
  953. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  954. if (style !== '') {
  955. html += 'style="' + style + '" ';
  956. }
  957. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  958. return html;
  959. }
  960. function _tmpl(str, data) {
  961. var fn = new Function("obj",
  962. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  963. "with(obj){p.push('" +
  964. str.replace(/[\r\t\n]/g, " ")
  965. .split("<%").join("\t")
  966. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  967. .replace(/\t=(.*?)%>/g, "',$1,'")
  968. .split("\t").join("');")
  969. .split("%>").join("p.push('")
  970. .split("\r").join("\\'") + "');}return p.join('');");
  971. return data ? fn(data) : fn;
  972. }
  973. K.formatUrl = _formatUrl;
  974. K.formatHtml = _formatHtml;
  975. K.getCssList = _getCssList;
  976. K.getAttrList = _getAttrList;
  977. K.mediaType = _mediaType;
  978. K.mediaAttrs = _mediaAttrs;
  979. K.mediaEmbed = _mediaEmbed;
  980. K.mediaImg = _mediaImg;
  981. K.clearMsWord = _clearMsWord;
  982. K.tmpl = _tmpl;
  983. function _contains(nodeA, nodeB) {
  984. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  985. return true;
  986. }
  987. while ((nodeB = nodeB.parentNode)) {
  988. if (nodeB == nodeA) {
  989. return true;
  990. }
  991. }
  992. return false;
  993. }
  994. var _getSetAttrDiv = document.createElement('div');
  995. _getSetAttrDiv.setAttribute('className', 't');
  996. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  997. function _getAttr(el, key) {
  998. key = key.toLowerCase();
  999. var val = null;
  1000. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1001. var div = el.ownerDocument.createElement('div');
  1002. div.appendChild(el.cloneNode(false));
  1003. var list = _getAttrList(_unescape(div.innerHTML));
  1004. if (key in list) {
  1005. val = list[key];
  1006. }
  1007. } else {
  1008. try {
  1009. val = el.getAttribute(key, 2);
  1010. } catch(e) {
  1011. val = el.getAttribute(key, 1);
  1012. }
  1013. }
  1014. if (key === 'style' && val !== null) {
  1015. val = _formatCss(val);
  1016. }
  1017. return val;
  1018. }
  1019. function _queryAll(expr, root) {
  1020. var exprList = expr.split(',');
  1021. if (exprList.length > 1) {
  1022. var mergedResults = [];
  1023. _each(exprList, function() {
  1024. _each(_queryAll(this, root), function() {
  1025. if (_inArray(this, mergedResults) < 0) {
  1026. mergedResults.push(this);
  1027. }
  1028. });
  1029. });
  1030. return mergedResults;
  1031. }
  1032. root = root || document;
  1033. function escape(str) {
  1034. if (typeof str != 'string') {
  1035. return str;
  1036. }
  1037. return str.replace(/([^\w\-])/g, '\\$1');
  1038. }
  1039. function stripslashes(str) {
  1040. return str.replace(/\\/g, '');
  1041. }
  1042. function cmpTag(tagA, tagB) {
  1043. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1044. }
  1045. function byId(id, tag, root) {
  1046. var arr = [],
  1047. doc = root.ownerDocument || root,
  1048. el = doc.getElementById(stripslashes(id));
  1049. if (el) {
  1050. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1051. arr.push(el);
  1052. }
  1053. }
  1054. return arr;
  1055. }
  1056. function byClass(className, tag, root) {
  1057. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1058. if (root.getElementsByClassName) {
  1059. els = root.getElementsByClassName(stripslashes(className));
  1060. for (i = 0, len = els.length; i < len; i++) {
  1061. el = els[i];
  1062. if (cmpTag(tag, el.nodeName)) {
  1063. arr.push(el);
  1064. }
  1065. }
  1066. } else if (doc.querySelectorAll) {
  1067. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1068. for (i = 0, len = els.length; i < len; i++) {
  1069. el = els[i];
  1070. if (_contains(root, el)) {
  1071. arr.push(el);
  1072. }
  1073. }
  1074. } else {
  1075. els = root.getElementsByTagName(tag);
  1076. className = ' ' + className + ' ';
  1077. for (i = 0, len = els.length; i < len; i++) {
  1078. el = els[i];
  1079. if (el.nodeType == 1) {
  1080. var cls = el.className;
  1081. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1082. arr.push(el);
  1083. }
  1084. }
  1085. }
  1086. }
  1087. return arr;
  1088. }
  1089. function byName(name, tag, root) {
  1090. var arr = [], doc = root.ownerDocument || root,
  1091. els = doc.getElementsByName(stripslashes(name)), el;
  1092. for (var i = 0, len = els.length; i < len; i++) {
  1093. el = els[i];
  1094. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1095. if (el.getAttribute('name') !== null) {
  1096. arr.push(el);
  1097. }
  1098. }
  1099. }
  1100. return arr;
  1101. }
  1102. function byAttr(key, val, tag, root) {
  1103. var arr = [], els = root.getElementsByTagName(tag), el;
  1104. for (var i = 0, len = els.length; i < len; i++) {
  1105. el = els[i];
  1106. if (el.nodeType == 1) {
  1107. if (val === null) {
  1108. if (_getAttr(el, key) !== null) {
  1109. arr.push(el);
  1110. }
  1111. } else {
  1112. if (val === escape(_getAttr(el, key))) {
  1113. arr.push(el);
  1114. }
  1115. }
  1116. }
  1117. }
  1118. return arr;
  1119. }
  1120. function select(expr, root) {
  1121. var arr = [], matches;
  1122. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1123. var tag = matches ? matches[1] : '*';
  1124. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1125. arr = byId(matches[1], tag, root);
  1126. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1127. arr = byClass(matches[1], tag, root);
  1128. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1129. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1130. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1131. var key = matches[1].toLowerCase(), val = matches[2];
  1132. if (key === 'id') {
  1133. arr = byId(val, tag, root);
  1134. } else if (key === 'class') {
  1135. arr = byClass(val, tag, root);
  1136. } else if (key === 'name') {
  1137. arr = byName(val, tag, root);
  1138. } else {
  1139. arr = byAttr(key, val, tag, root);
  1140. }
  1141. } else {
  1142. var els = root.getElementsByTagName(tag), el;
  1143. for (var i = 0, len = els.length; i < len; i++) {
  1144. el = els[i];
  1145. if (el.nodeType == 1) {
  1146. arr.push(el);
  1147. }
  1148. }
  1149. }
  1150. return arr;
  1151. }
  1152. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1153. while ((arr = re.exec(expr))) {
  1154. if (arr[1] !== ' ') {
  1155. parts.push(arr[1]);
  1156. }
  1157. }
  1158. var results = [];
  1159. if (parts.length == 1) {
  1160. return select(parts[0], root);
  1161. }
  1162. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1163. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1164. part = parts[i];
  1165. if (part === '>') {
  1166. isChild = true;
  1167. continue;
  1168. }
  1169. if (i > 0) {
  1170. els = [];
  1171. for (j = 0, len = results.length; j < len; j++) {
  1172. val = results[j];
  1173. subResults = select(part, val);
  1174. for (k = 0, l = subResults.length; k < l; k++) {
  1175. v = subResults[k];
  1176. if (isChild) {
  1177. if (val === v.parentNode) {
  1178. els.push(v);
  1179. }
  1180. } else {
  1181. els.push(v);
  1182. }
  1183. }
  1184. }
  1185. results = els;
  1186. } else {
  1187. results = select(part, root);
  1188. }
  1189. if (results.length === 0) {
  1190. return [];
  1191. }
  1192. }
  1193. return results;
  1194. }
  1195. function _query(expr, root) {
  1196. var arr = _queryAll(expr, root);
  1197. return arr.length > 0 ? arr[0] : null;
  1198. }
  1199. K.query = _query;
  1200. K.queryAll = _queryAll;
  1201. function _get(val) {
  1202. return K(val)[0];
  1203. }
  1204. function _getDoc(node) {
  1205. if (!node) {
  1206. return document;
  1207. }
  1208. return node.ownerDocument || node.document || node;
  1209. }
  1210. function _getWin(node) {
  1211. if (!node) {
  1212. return window;
  1213. }
  1214. var doc = _getDoc(node);
  1215. return doc.parentWindow || doc.defaultView;
  1216. }
  1217. function _setHtml(el, html) {
  1218. if (el.nodeType != 1) {
  1219. return;
  1220. }
  1221. var doc = _getDoc(el);
  1222. try {
  1223. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1224. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1225. temp.parentNode.removeChild(temp);
  1226. } catch(e) {
  1227. K(el).empty();
  1228. K('@' + html, doc).each(function() {
  1229. el.appendChild(this);
  1230. });
  1231. }
  1232. }
  1233. function _hasClass(el, cls) {
  1234. return _inString(cls, el.className, ' ');
  1235. }
  1236. function _setAttr(el, key, val) {
  1237. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1238. key = 'className';
  1239. }
  1240. el.setAttribute(key, '' + val);
  1241. }
  1242. function _removeAttr(el, key) {
  1243. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1244. key = 'className';
  1245. }
  1246. _setAttr(el, key, '');
  1247. el.removeAttribute(key);
  1248. }
  1249. function _getNodeName(node) {
  1250. if (!node || !node.nodeName) {
  1251. return '';
  1252. }
  1253. return node.nodeName.toLowerCase();
  1254. }
  1255. function _computedCss(el, key) {
  1256. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1257. if (win.getComputedStyle) {
  1258. var style = win.getComputedStyle(el, null);
  1259. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1260. } else if (el.currentStyle) {
  1261. val = el.currentStyle[camelKey] || el.style[camelKey];
  1262. }
  1263. return val;
  1264. }
  1265. function _hasVal(node) {
  1266. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1267. }
  1268. function _docElement(doc) {
  1269. doc = doc || document;
  1270. return _QUIRKS ? doc.body : doc.documentElement;
  1271. }
  1272. function _docHeight(doc) {
  1273. var el = _docElement(doc);
  1274. return Math.max(el.scrollHeight, el.clientHeight);
  1275. }
  1276. function _docWidth(doc) {
  1277. var el = _docElement(doc);
  1278. return Math.max(el.scrollWidth, el.clientWidth);
  1279. }
  1280. function _getScrollPos(doc) {
  1281. doc = doc || document;
  1282. var x, y;
  1283. if (_IE || _NEWIE || _OPERA) {
  1284. x = _docElement(doc).scrollLeft;
  1285. y = _docElement(doc).scrollTop;
  1286. } else {
  1287. x = _getWin(doc).scrollX;
  1288. y = _getWin(doc).scrollY;
  1289. }
  1290. return {x : x, y : y};
  1291. }
  1292. function KNode(node) {
  1293. this.init(node);
  1294. }
  1295. _extend(KNode, {
  1296. init : function(node) {
  1297. var self = this;
  1298. node = _isArray(node) ? node : [node];
  1299. var length = 0;
  1300. for (var i = 0, len = node.length; i < len; i++) {
  1301. if (node[i]) {
  1302. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1303. length++;
  1304. }
  1305. }
  1306. self.length = length;
  1307. self.doc = _getDoc(self[0]);
  1308. self.name = _getNodeName(self[0]);
  1309. self.type = self.length > 0 ? self[0].nodeType : null;
  1310. self.win = _getWin(self[0]);
  1311. },
  1312. each : function(fn) {
  1313. var self = this;
  1314. for (var i = 0; i < self.length; i++) {
  1315. if (fn.call(self[i], i, self[i]) === false) {
  1316. return self;
  1317. }
  1318. }
  1319. return self;
  1320. },
  1321. bind : function(type, fn) {
  1322. this.each(function() {
  1323. _bind(this, type, fn);
  1324. });
  1325. return this;
  1326. },
  1327. unbind : function(type, fn) {
  1328. this.each(function() {
  1329. _unbind(this, type, fn);
  1330. });
  1331. return this;
  1332. },
  1333. fire : function(type) {
  1334. if (this.length < 1) {
  1335. return this;
  1336. }
  1337. _fire(this[0], type);
  1338. return this;
  1339. },
  1340. hasAttr : function(key) {
  1341. if (this.length < 1) {
  1342. return false;
  1343. }
  1344. return !!_getAttr(this[0], key);
  1345. },
  1346. attr : function(key, val) {
  1347. var self = this;
  1348. if (key === undefined) {
  1349. return _getAttrList(self.outer());
  1350. }
  1351. if (typeof key === 'object') {
  1352. _each(key, function(k, v) {
  1353. self.attr(k, v);
  1354. });
  1355. return self;
  1356. }
  1357. if (val === undefined) {
  1358. val = self.length < 1 ? null : _getAttr(self[0], key);
  1359. return val === null ? '' : val;
  1360. }
  1361. self.each(function() {
  1362. _setAttr(this, key, val);
  1363. });
  1364. return self;
  1365. },
  1366. removeAttr : function(key) {
  1367. this.each(function() {
  1368. _removeAttr(this, key);
  1369. });
  1370. return this;
  1371. },
  1372. get : function(i) {
  1373. if (this.length < 1) {
  1374. return null;
  1375. }
  1376. return this[i || 0];
  1377. },
  1378. eq : function(i) {
  1379. if (this.length < 1) {
  1380. return null;
  1381. }
  1382. return this[i] ? new KNode(this[i]) : null;
  1383. },
  1384. hasClass : function(cls) {
  1385. if (this.length < 1) {
  1386. return false;
  1387. }
  1388. return _hasClass(this[0], cls);
  1389. },
  1390. addClass : function(cls) {
  1391. this.each(function() {
  1392. if (!_hasClass(this, cls)) {
  1393. this.className = _trim(this.className + ' ' + cls);
  1394. }
  1395. });
  1396. return this;
  1397. },
  1398. removeClass : function(cls) {
  1399. this.each(function() {
  1400. if (_hasClass(this, cls)) {
  1401. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1402. }
  1403. });
  1404. return this;
  1405. },
  1406. html : function(val) {
  1407. var self = this;
  1408. if (val === undefined) {
  1409. if (self.length < 1 || self.type != 1) {
  1410. return '';
  1411. }
  1412. return _formatHtml(self[0].innerHTML);
  1413. }
  1414. self.each(function() {
  1415. _setHtml(this, val);
  1416. });
  1417. return self;
  1418. },
  1419. text : function() {
  1420. var self = this;
  1421. if (self.length < 1) {
  1422. return '';
  1423. }
  1424. return _IE ? self[0].innerText : self[0].textContent;
  1425. },
  1426. hasVal : function() {
  1427. if (this.length < 1) {
  1428. return false;
  1429. }
  1430. return _hasVal(this[0]);
  1431. },
  1432. val : function(val) {
  1433. var self = this;
  1434. if (val === undefined) {
  1435. if (self.length < 1) {
  1436. return '';
  1437. }
  1438. return self.hasVal() ? self[0].value : self.attr('value');
  1439. } else {
  1440. self.each(function() {
  1441. if (_hasVal(this)) {
  1442. this.value = val;
  1443. } else {
  1444. _setAttr(this, 'value' , val);
  1445. }
  1446. });
  1447. return self;
  1448. }
  1449. },
  1450. css : function(key, val) {
  1451. var self = this;
  1452. if (key === undefined) {
  1453. return _getCssList(self.attr('style'));
  1454. }
  1455. if (typeof key === 'object') {
  1456. _each(key, function(k, v) {
  1457. self.css(k, v);
  1458. });
  1459. return self;
  1460. }
  1461. if (val === undefined) {
  1462. if (self.length < 1) {
  1463. return '';
  1464. }
  1465. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1466. }
  1467. self.each(function() {
  1468. this.style[_toCamel(key)] = val;
  1469. });
  1470. return self;
  1471. },
  1472. width : function(val) {
  1473. var self = this;
  1474. if (val === undefined) {
  1475. if (self.length < 1) {
  1476. return 0;
  1477. }
  1478. return self[0].offsetWidth;
  1479. }
  1480. return self.css('width', _addUnit(val));
  1481. },
  1482. height : function(val) {
  1483. var self = this;
  1484. if (val === undefined) {
  1485. if (self.length < 1) {
  1486. return 0;
  1487. }
  1488. return self[0].offsetHeight;
  1489. }
  1490. return self.css('height', _addUnit(val));
  1491. },
  1492. opacity : function(val) {
  1493. this.each(function() {
  1494. if (this.style.opacity === undefined) {
  1495. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1496. } else {
  1497. this.style.opacity = val == 1 ? '' : val;
  1498. }
  1499. });
  1500. return this;
  1501. },
  1502. data : function(key, val) {
  1503. var self = this;
  1504. key = 'kindeditor_data_' + key;
  1505. if (val === undefined) {
  1506. if (self.length < 1) {
  1507. return null;
  1508. }
  1509. return self[0][key];
  1510. }
  1511. this.each(function() {
  1512. this[key] = val;
  1513. });
  1514. return self;
  1515. },
  1516. pos : function() {
  1517. var self = this, node = self[0], x = 0, y = 0;
  1518. if (node) {
  1519. if (node.getBoundingClientRect) {
  1520. var box = node.getBoundingClientRect(),
  1521. pos = _getScrollPos(self.doc);
  1522. x = box.left + pos.x;
  1523. y = box.top + pos.y;
  1524. } else {
  1525. while (node) {
  1526. x += node.offsetLeft;
  1527. y += node.offsetTop;
  1528. node = node.offsetParent;
  1529. }
  1530. }
  1531. }
  1532. return {x : _round(x), y : _round(y)};
  1533. },
  1534. clone : function(bool) {
  1535. if (this.length < 1) {
  1536. return new KNode([]);
  1537. }
  1538. return new KNode(this[0].cloneNode(bool));
  1539. },
  1540. append : function(expr) {
  1541. this.each(function() {
  1542. if (this.appendChild) {
  1543. this.appendChild(_get(expr));
  1544. }
  1545. });
  1546. return this;
  1547. },
  1548. appendTo : function(expr) {
  1549. this.each(function() {
  1550. _get(expr).appendChild(this);
  1551. });
  1552. return this;
  1553. },
  1554. before : function(expr) {
  1555. this.each(function() {
  1556. this.parentNode.insertBefore(_get(expr), this);
  1557. });
  1558. return this;
  1559. },
  1560. after : function(expr) {
  1561. this.each(function() {
  1562. if (this.nextSibling) {
  1563. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1564. } else {
  1565. this.parentNode.appendChild(_get(expr));
  1566. }
  1567. });
  1568. return this;
  1569. },
  1570. replaceWith : function(expr) {
  1571. var nodes = [];
  1572. this.each(function(i, node) {
  1573. _unbind(node);
  1574. var newNode = _get(expr);
  1575. node.parentNode.replaceChild(newNode, node);
  1576. nodes.push(newNode);
  1577. });
  1578. return K(nodes);
  1579. },
  1580. empty : function() {
  1581. var self = this;
  1582. self.each(function(i, node) {
  1583. var child = node.firstChild;
  1584. while (child) {
  1585. if (!node.parentNode) {
  1586. return;
  1587. }
  1588. var next = child.nextSibling;
  1589. child.parentNode.removeChild(child);
  1590. child = next;
  1591. }
  1592. });
  1593. return self;
  1594. },
  1595. remove : function(keepChilds) {
  1596. var self = this;
  1597. self.each(function(i, node) {
  1598. if (!node.parentNode) {
  1599. return;
  1600. }
  1601. _unbind(node);
  1602. if (keepChilds) {
  1603. var child = node.firstChild;
  1604. while (child) {
  1605. var next = child.nextSibling;
  1606. node.parentNode.insertBefore(child, node);
  1607. child = next;
  1608. }
  1609. }
  1610. node.parentNode.removeChild(node);
  1611. delete self[i];
  1612. });
  1613. self.length = 0;
  1614. return self;
  1615. },
  1616. show : function(val) {
  1617. var self = this;
  1618. if (val === undefined) {
  1619. val = self._originDisplay || '';
  1620. }
  1621. if (self.css('display') != 'none') {
  1622. return self;
  1623. }
  1624. return self.css('display', val);
  1625. },
  1626. hide : function() {
  1627. var self = this;
  1628. if (self.length < 1) {
  1629. return self;
  1630. }
  1631. self._originDisplay = self[0].style.display;
  1632. return self.css('display', 'none');
  1633. },
  1634. outer : function() {
  1635. var self = this;
  1636. if (self.length < 1) {
  1637. return '';
  1638. }
  1639. var div = self.doc.createElement('div'), html;
  1640. div.appendChild(self[0].cloneNode(true));
  1641. html = _formatHtml(div.innerHTML);
  1642. div = null;
  1643. return html;
  1644. },
  1645. isSingle : function() {
  1646. return !!_SINGLE_TAG_MAP[this.name];
  1647. },
  1648. isInline : function() {
  1649. return !!_INLINE_TAG_MAP[this.name];
  1650. },
  1651. isBlock : function() {
  1652. return !!_BLOCK_TAG_MAP[this.name];
  1653. },
  1654. isStyle : function() {
  1655. return !!_STYLE_TAG_MAP[this.name];
  1656. },
  1657. isControl : function() {
  1658. return !!_CONTROL_TAG_MAP[this.name];
  1659. },
  1660. contains : function(otherNode) {
  1661. if (this.length < 1) {
  1662. return false;
  1663. }
  1664. return _contains(this[0], _get(otherNode));
  1665. },
  1666. parent : function() {
  1667. if (this.length < 1) {
  1668. return null;
  1669. }
  1670. var node = this[0].parentNode;
  1671. return node ? new KNode(node) : null;
  1672. },
  1673. children : function() {
  1674. if (this.length < 1) {
  1675. return new KNode([]);
  1676. }
  1677. var list = [], child = this[0].firstChild;
  1678. while (child) {
  1679. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1680. list.push(child);
  1681. }
  1682. child = child.nextSibling;
  1683. }
  1684. return new KNode(list);
  1685. },
  1686. first : function() {
  1687. var list = this.children();
  1688. return list.length > 0 ? list.eq(0) : null;
  1689. },
  1690. last : function() {
  1691. var list = this.children();
  1692. return list.length > 0 ? list.eq(list.length - 1) : null;
  1693. },
  1694. index : function() {
  1695. if (this.length < 1) {
  1696. return -1;
  1697. }
  1698. var i = -1, sibling = this[0];
  1699. while (sibling) {
  1700. i++;
  1701. sibling = sibling.previousSibling;
  1702. }
  1703. return i;
  1704. },
  1705. prev : function() {
  1706. if (this.length < 1) {
  1707. return null;
  1708. }
  1709. var node = this[0].previousSibling;
  1710. return node ? new KNode(node) : null;
  1711. },
  1712. next : function() {
  1713. if (this.length < 1) {
  1714. return null;
  1715. }
  1716. var node = this[0].nextSibling;
  1717. return node ? new KNode(node) : null;
  1718. },
  1719. scan : function(fn, order) {
  1720. if (this.length < 1) {
  1721. return;
  1722. }
  1723. order = (order === undefined) ? true : order;
  1724. function walk(node) {
  1725. var n = order ? node.firstChild : node.lastChild;
  1726. while (n) {
  1727. var next = order ? n.nextSibling : n.previousSibling;
  1728. if (fn(n) === false) {
  1729. return false;
  1730. }
  1731. if (walk(n) === false) {
  1732. return false;
  1733. }
  1734. n = next;
  1735. }
  1736. }
  1737. walk(this[0]);
  1738. return this;
  1739. }
  1740. });
  1741. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1742. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1743. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1744. KNode.prototype[type] = function(fn) {
  1745. return fn ? this.bind(type, fn) : this.fire(type);
  1746. };
  1747. });
  1748. var _K = K;
  1749. K = function(expr, root) {
  1750. if (expr === undefined || expr === null) {
  1751. return;
  1752. }
  1753. function newNode(node) {
  1754. if (!node[0]) {
  1755. node = [];
  1756. }
  1757. return new KNode(node);
  1758. }
  1759. if (typeof expr === 'string') {
  1760. if (root) {
  1761. root = _get(root);
  1762. }
  1763. var length = expr.length;
  1764. if (expr.charAt(0) === '@') {
  1765. expr = expr.substr(1);
  1766. }
  1767. if (expr.length !== length || /<.+>/.test(expr)) {
  1768. var doc = root ? root.ownerDocument || root : document,
  1769. div = doc.createElement('div'), list = [];
  1770. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1771. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1772. var child = div.childNodes[i];
  1773. if (child.id == '__kindeditor_temp_tag__') {
  1774. continue;
  1775. }
  1776. list.push(child);
  1777. }
  1778. return newNode(list);
  1779. }
  1780. return newNode(_queryAll(expr, root));
  1781. }
  1782. if (expr && expr.constructor === KNode) {
  1783. return expr;
  1784. }
  1785. if (expr.toArray) {
  1786. expr = expr.toArray();
  1787. }
  1788. if (_isArray(expr)) {
  1789. return newNode(expr);
  1790. }
  1791. return newNode(_toArray(arguments));
  1792. };
  1793. _each(_K, function(key, val) {
  1794. K[key] = val;
  1795. });
  1796. K.NodeClass = KNode;
  1797. window.KindEditor = K;
  1798. var _START_TO_START = 0,
  1799. _START_TO_END = 1,
  1800. _END_TO_END = 2,
  1801. _END_TO_START = 3,
  1802. _BOOKMARK_ID = 0;
  1803. function _updateCollapsed(range) {
  1804. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1805. return range;
  1806. }
  1807. function _copyAndDelete(range, isCopy, isDelete) {
  1808. var doc = range.doc, nodeList = [];
  1809. function splitTextNode(node, startOffset, endOffset) {
  1810. var length = node.nodeValue.length, centerNode;
  1811. if (isCopy) {
  1812. var cloneNode = node.cloneNode(true);
  1813. if (startOffset > 0) {
  1814. centerNode = cloneNode.splitText(startOffset);
  1815. } else {
  1816. centerNode = cloneNode;
  1817. }
  1818. if (endOffset < length) {
  1819. centerNode.splitText(endOffset - startOffset);
  1820. }
  1821. }
  1822. if (isDelete) {
  1823. var center = node;
  1824. if (startOffset > 0) {
  1825. center = node.splitText(startOffset);
  1826. range.setStart(node, startOffset);
  1827. }
  1828. if (endOffset < length) {
  1829. var right = center.splitText(endOffset - startOffset);
  1830. range.setEnd(right, 0);
  1831. }
  1832. nodeList.push(center);
  1833. }
  1834. return centerNode;
  1835. }
  1836. function removeNodes() {
  1837. if (isDelete) {
  1838. range.up().collapse(true);
  1839. }
  1840. for (var i = 0, len = nodeList.length; i < len; i++) {
  1841. var node = nodeList[i];
  1842. if (node.parentNode) {
  1843. node.parentNode.removeChild(node);
  1844. }
  1845. }
  1846. }
  1847. var copyRange = range.cloneRange().down();
  1848. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1849. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1850. if (ancestor.nodeType == 3) {
  1851. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1852. if (isCopy) {
  1853. frag.appendChild(textNode);
  1854. }
  1855. removeNodes();
  1856. return isCopy ? frag : range;
  1857. }
  1858. function extractNodes(parent, frag) {
  1859. var node = parent.firstChild, nextNode;
  1860. while (node) {
  1861. var testRange = new KRange(doc).selectNode(node);
  1862. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1863. if (start >= 0 && incStart <= 0) {
  1864. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1865. }
  1866. if (incStart >= 0 && incEnd <= 0) {
  1867. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1868. }
  1869. if (incEnd >= 0 && end <= 0) {
  1870. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1871. }
  1872. if (end >= 0) {
  1873. return false;
  1874. }
  1875. nextNode = node.nextSibling;
  1876. if (start > 0) {
  1877. if (node.nodeType == 1) {
  1878. if (incStart >= 0 && incEnd <= 0) {
  1879. if (isCopy) {
  1880. frag.appendChild(node.cloneNode(true));
  1881. }
  1882. if (isDelete) {
  1883. nodeList.push(node);
  1884. }
  1885. } else {
  1886. var childFlag;
  1887. if (isCopy) {
  1888. childFlag = node.cloneNode(false);
  1889. frag.appendChild(childFlag);
  1890. }
  1891. if (extractNodes(node, childFlag) === false) {
  1892. return false;
  1893. }
  1894. }
  1895. } else if (node.nodeType == 3) {
  1896. var textNode;
  1897. if (node == copyRange.startContainer) {
  1898. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1899. } else if (node == copyRange.endContainer) {
  1900. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1901. } else {
  1902. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1903. }
  1904. if (isCopy) {
  1905. try {
  1906. frag.appendChild(textNode);
  1907. } catch(e) {}
  1908. }
  1909. }
  1910. }
  1911. node = nextNode;
  1912. }
  1913. }
  1914. extractNodes(ancestor, frag);
  1915. if (isDelete) {
  1916. range.up().collapse(true);
  1917. }
  1918. for (var i = 0, len = nodeList.length; i < len; i++) {
  1919. var node = nodeList[i];
  1920. if (node.parentNode) {
  1921. node.parentNode.removeChild(node);
  1922. }
  1923. }
  1924. return isCopy ? frag : range;
  1925. }
  1926. function _moveToElementText(range, el) {
  1927. var node = el;
  1928. while (node) {
  1929. var knode = K(node);
  1930. if (knode.name == 'marquee' || knode.name == 'select') {
  1931. return;
  1932. }
  1933. node = node.parentNode;
  1934. }
  1935. try {
  1936. range.moveToElementText(el);
  1937. } catch(e) {}
  1938. }
  1939. function _getStartEnd(rng, isStart) {
  1940. var doc = rng.parentElement().ownerDocument,
  1941. pointRange = rng.duplicate();
  1942. pointRange.collapse(isStart);
  1943. var parent = pointRange.parentElement(),
  1944. nodes = parent.childNodes;
  1945. if (nodes.length === 0) {
  1946. return {node: parent.parentNode, offset: K(parent).index()};
  1947. }
  1948. var startNode = doc, startPos = 0, cmp = -1;
  1949. var testRange = rng.duplicate();
  1950. _moveToElementText(testRange, parent);
  1951. for (var i = 0, len = nodes.length; i < len; i++) {
  1952. var node = nodes[i];
  1953. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1954. if (cmp === 0) {
  1955. return {node: node.parentNode, offset: i};
  1956. }
  1957. if (node.nodeType == 1) {
  1958. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1959. if (knode.isControl()) {
  1960. dummy = doc.createElement('span');
  1961. knode.after(dummy);
  1962. newNode = dummy;
  1963. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1964. }
  1965. _moveToElementText(nodeRange, newNode);
  1966. testRange.setEndPoint('StartToEnd', nodeRange);
  1967. if (cmp > 0) {
  1968. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1969. } else {
  1970. startPos = 0;
  1971. }
  1972. if (dummy) {
  1973. K(dummy).remove();
  1974. }
  1975. } else if (node.nodeType == 3) {
  1976. testRange.moveStart('character', node.nodeValue.length);
  1977. startPos += node.nodeValue.length;
  1978. }
  1979. if (cmp < 0) {
  1980. startNode = node;
  1981. }
  1982. }
  1983. if (cmp < 0 && startNode.nodeType == 1) {
  1984. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1985. }
  1986. if (cmp > 0) {
  1987. while (startNode.nextSibling && startNode.nodeType == 1) {
  1988. startNode = startNode.nextSibling;
  1989. }
  1990. }
  1991. testRange = rng.duplicate();
  1992. _moveToElementText(testRange, parent);
  1993. testRange.setEndPoint('StartToEnd', pointRange);
  1994. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1995. if (cmp > 0 && startNode.nodeType == 3) {
  1996. var prevNode = startNode.previousSibling;
  1997. while (prevNode && prevNode.nodeType == 3) {
  1998. startPos -= prevNode.nodeValue.length;
  1999. prevNode = prevNode.previousSibling;
  2000. }
  2001. }
  2002. return {node: startNode, offset: startPos};
  2003. }
  2004. function _getEndRange(node, offset) {
  2005. var doc = node.ownerDocument || node,
  2006. range = doc.body.createTextRange();
  2007. if (doc == node) {
  2008. range.collapse(true);
  2009. return range;
  2010. }
  2011. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2012. var children = node.childNodes, isStart, child;
  2013. if (offset === 0) {
  2014. child = children[0];
  2015. isStart = true;
  2016. } else {
  2017. child = children[offset - 1];
  2018. isStart = false;
  2019. }
  2020. if (!child) {
  2021. return range;
  2022. }
  2023. if (K(child).name === 'head') {
  2024. if (offset === 1) {
  2025. isStart = true;
  2026. }
  2027. if (offset === 2) {
  2028. isStart = false;
  2029. }
  2030. range.collapse(isStart);
  2031. return range;
  2032. }
  2033. if (child.nodeType == 1) {
  2034. var kchild = K(child), span;
  2035. if (kchild.isControl()) {
  2036. span = doc.createElement('span');
  2037. if (isStart) {
  2038. kchild.before(span);
  2039. } else {
  2040. kchild.after(span);
  2041. }
  2042. child = span;
  2043. }
  2044. _moveToElementText(range, child);
  2045. range.collapse(isStart);
  2046. if (span) {
  2047. K(span).remove();
  2048. }
  2049. return range;
  2050. }
  2051. node = child;
  2052. offset = isStart ? 0 : child.nodeValue.length;
  2053. }
  2054. var dummy = doc.createElement('span');
  2055. K(node).before(dummy);
  2056. _moveToElementText(range, dummy);
  2057. range.moveStart('character', offset);
  2058. K(dummy).remove();
  2059. return range;
  2060. }
  2061. function _toRange(rng) {
  2062. var doc, range;
  2063. function tr2td(start) {
  2064. if (K(start.node).name == 'tr') {
  2065. start.node = start.node.cells[start.offset];
  2066. start.offset = 0;
  2067. }
  2068. }
  2069. if (_IERANGE) {
  2070. if (rng.item) {
  2071. doc = _getDoc(rng.item(0));
  2072. range = new KRange(doc);
  2073. range.selectNode(rng.item(0));
  2074. return range;
  2075. }
  2076. doc = rng.parentElement().ownerDocument;
  2077. var start = _getStartEnd(rng, true),
  2078. end = _getStartEnd(rng, false);
  2079. tr2td(start);
  2080. tr2td(end);
  2081. range = new KRange(doc);
  2082. range.setStart(start.node, start.offset);
  2083. range.setEnd(end.node, end.offset);
  2084. return range;
  2085. }
  2086. var startContainer = rng.startContainer;
  2087. doc = startContainer.ownerDocument || startContainer;
  2088. range = new KRange(doc);
  2089. range.setStart(startContainer, rng.startOffset);
  2090. range.setEnd(rng.endContainer, rng.endOffset);
  2091. return range;
  2092. }
  2093. function KRange(doc) {
  2094. this.init(doc);
  2095. }
  2096. _extend(KRange, {
  2097. init : function(doc) {
  2098. var self = this;
  2099. self.startContainer = doc;
  2100. self.startOffset = 0;
  2101. self.endContainer = doc;
  2102. self.endOffset = 0;
  2103. self.collapsed = true;
  2104. self.doc = doc;
  2105. },
  2106. commonAncestor : function() {
  2107. function getParents(node) {
  2108. var parents = [];
  2109. while (node) {
  2110. parents.push(node);
  2111. node = node.parentNode;
  2112. }
  2113. return parents;
  2114. }
  2115. var parentsA = getParents(this.startContainer),
  2116. parentsB = getParents(this.endContainer),
  2117. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2118. while (++i) {
  2119. parentA = parentsA[lenA - i];
  2120. parentB = parentsB[lenB - i];
  2121. if (!parentA || !parentB || parentA !== parentB) {
  2122. break;
  2123. }
  2124. }
  2125. return parentsA[lenA - i + 1];
  2126. },
  2127. setStart : function(node, offset) {
  2128. var self = this, doc = self.doc;
  2129. self.startContainer = node;
  2130. self.startOffset = offset;
  2131. if (self.endContainer === doc) {
  2132. self.endContainer = node;
  2133. self.endOffset = offset;
  2134. }
  2135. return _updateCollapsed(this);
  2136. },
  2137. setEnd : function(node, offset) {
  2138. var self = this, doc = self.doc;
  2139. self.endContainer = node;
  2140. self.endOffset = offset;
  2141. if (self.startContainer === doc) {
  2142. self.startContainer = node;
  2143. self.startOffset = offset;
  2144. }
  2145. return _updateCollapsed(this);
  2146. },
  2147. setStartBefore : function(node) {
  2148. return this.setStart(node.parentNode || this.doc, K(node).index());
  2149. },
  2150. setStartAfter : function(node) {
  2151. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2152. },
  2153. setEndBefore : function(node) {
  2154. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2155. },
  2156. setEndAfter : function(node) {
  2157. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2158. },
  2159. selectNode : function(node) {
  2160. return this.setStartBefore(node).setEndAfter(node);
  2161. },
  2162. selectNodeContents : function(node) {
  2163. var knode = K(node);
  2164. if (knode.type == 3 || knode.isSingle()) {
  2165. return this.selectNode(node);
  2166. }
  2167. var children = knode.children();
  2168. if (children.length > 0) {
  2169. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2170. }
  2171. return this.setStart(node, 0).setEnd(node, 0);
  2172. },
  2173. collapse : function(toStart) {
  2174. if (toStart) {
  2175. return this.setEnd(this.startContainer, this.startOffset);
  2176. }
  2177. return this.setStart(this.endContainer, this.endOffset);
  2178. },
  2179. compareBoundaryPoints : function(how, range) {
  2180. var rangeA = this.get(), rangeB = range.get();
  2181. if (_IERANGE) {
  2182. var arr = {};
  2183. arr[_START_TO_START] = 'StartToStart';
  2184. arr[_START_TO_END] = 'EndToStart';
  2185. arr[_END_TO_END] = 'EndToEnd';
  2186. arr[_END_TO_START] = 'StartToEnd';
  2187. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2188. if (cmp !== 0) {
  2189. return cmp;
  2190. }
  2191. var nodeA, nodeB, nodeC, posA, posB;
  2192. if (how === _START_TO_START || how === _END_TO_START) {
  2193. nodeA = this.startContainer;
  2194. posA = this.startOffset;
  2195. }
  2196. if (how === _START_TO_END || how === _END_TO_END) {
  2197. nodeA = this.endContainer;
  2198. posA = this.endOffset;
  2199. }
  2200. if (how === _START_TO_START || how === _START_TO_END) {
  2201. nodeB = range.startContainer;
  2202. posB = range.startOffset;
  2203. }
  2204. if (how === _END_TO_END || how === _END_TO_START) {
  2205. nodeB = range.endContainer;
  2206. posB = range.endOffset;
  2207. }
  2208. if (nodeA === nodeB) {
  2209. var diff = posA - posB;
  2210. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2211. }
  2212. nodeC = nodeB;
  2213. while (nodeC && nodeC.parentNode !== nodeA) {
  2214. nodeC = nodeC.parentNode;
  2215. }
  2216. if (nodeC) {
  2217. return K(nodeC).index() >= posA ? -1 : 1;
  2218. }
  2219. nodeC = nodeA;
  2220. while (nodeC && nodeC.parentNode !== nodeB) {
  2221. nodeC = nodeC.parentNode;
  2222. }
  2223. if (nodeC) {
  2224. return K(nodeC).index() >= posB ? 1 : -1;
  2225. }
  2226. nodeC = K(nodeB).next();
  2227. if (nodeC && nodeC.contains(nodeA)) {
  2228. return 1;
  2229. }
  2230. nodeC = K(nodeA).next();
  2231. if (nodeC && nodeC.contains(nodeB)) {
  2232. return -1;
  2233. }
  2234. } else {
  2235. return rangeA.compareBoundaryPoints(how, rangeB);
  2236. }
  2237. },
  2238. cloneRange : function() {
  2239. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2240. },
  2241. toString : function() {
  2242. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2243. return str.replace(/\r\n|\n|\r/g, '');
  2244. },
  2245. cloneContents : function() {
  2246. return _copyAndDelete(this, true, false);
  2247. },
  2248. deleteContents : function() {
  2249. return _copyAndDelete(this, false, true);
  2250. },
  2251. extractContents : function() {
  2252. return _copyAndDelete(this, true, true);
  2253. },
  2254. insertNode : function(node) {
  2255. var self = this,
  2256. sc = self.startContainer, so = self.startOffset,
  2257. ec = self.endContainer, eo = self.endOffset,
  2258. firstChild, lastChild, c, nodeCount = 1;
  2259. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2260. firstChild = node.firstChild;
  2261. lastChild = node.lastChild;
  2262. nodeCount = node.childNodes.length;
  2263. }
  2264. if (sc.nodeType == 1) {
  2265. c = sc.childNodes[so];
  2266. if (c) {
  2267. sc.insertBefore(node, c);
  2268. if (sc === ec) {
  2269. eo += nodeCount;
  2270. }
  2271. } else {
  2272. sc.appendChild(node);
  2273. }
  2274. } else if (sc.nodeType == 3) {
  2275. if (so === 0) {
  2276. sc.parentNode.insertBefore(node, sc);
  2277. if (sc.parentNode === ec) {
  2278. eo += nodeCount;
  2279. }
  2280. } else if (so >= sc.nodeValue.length) {
  2281. if (sc.nextSibling) {
  2282. sc.parentNode.insertBefore(node, sc.nextSibling);
  2283. } else {
  2284. sc.parentNode.appendChild(node);
  2285. }
  2286. } else {
  2287. if (so > 0) {
  2288. c = sc.splitText(so);
  2289. } else {
  2290. c = sc;
  2291. }
  2292. sc.parentNode.insertBefore(node, c);
  2293. if (sc === ec) {
  2294. ec = c;
  2295. eo -= so;
  2296. }
  2297. }
  2298. }
  2299. if (firstChild) {
  2300. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2301. } else {
  2302. self.selectNode(node);
  2303. }
  2304. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2305. return self;
  2306. }
  2307. return self.setEnd(ec, eo);
  2308. },
  2309. surroundContents : function(node) {
  2310. node.appendChild(this.extractContents());
  2311. return this.insertNode(node).selectNode(node);
  2312. },
  2313. isControl : function() {
  2314. var self = this,
  2315. sc = self.startContainer, so = self.startOffset,
  2316. ec = self.endContainer, eo = self.endOffset, rng;
  2317. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2318. },
  2319. get : function(hasControlRange) {
  2320. var self = this, doc = self.doc, node, rng;
  2321. if (!_IERANGE) {
  2322. rng = doc.createRange();
  2323. try {
  2324. rng.setStart(self.startContainer, self.startOffset);
  2325. rng.setEnd(self.endContainer, self.endOffset);
  2326. } catch (e) {}
  2327. return rng;
  2328. }
  2329. if (hasControlRange && self.isControl()) {
  2330. rng = doc.body.createControlRange();
  2331. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2332. return rng;
  2333. }
  2334. var range = self.cloneRange().down();
  2335. rng = doc.body.createTextRange();
  2336. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2337. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2338. return rng;
  2339. },
  2340. html : function() {
  2341. return K(this.cloneContents()).outer();
  2342. },
  2343. down : function() {
  2344. var self = this;
  2345. function downPos(node, pos, isStart) {
  2346. if (node.nodeType != 1) {
  2347. return;
  2348. }
  2349. var children = K(node).children();
  2350. if (children.length === 0) {
  2351. return;
  2352. }
  2353. var left, right, child, offset;
  2354. if (pos > 0) {
  2355. left = children.eq(pos - 1);
  2356. }
  2357. if (pos < children.length) {
  2358. right = children.eq(pos);
  2359. }
  2360. if (left && left.type == 3) {
  2361. child = left[0];
  2362. offset = child.nodeValue.length;
  2363. }
  2364. if (right && right.type == 3) {
  2365. child = right[0];
  2366. offset = 0;
  2367. }
  2368. if (!child) {
  2369. return;
  2370. }
  2371. if (isStart) {
  2372. self.setStart(child, offset);
  2373. } else {
  2374. self.setEnd(child, offset);
  2375. }
  2376. }
  2377. downPos(self.startContainer, self.startOffset, true);
  2378. downPos(self.endContainer, self.endOffset, false);
  2379. return self;
  2380. },
  2381. up : function() {
  2382. var self = this;
  2383. function upPos(node, pos, isStart) {
  2384. if (node.nodeType != 3) {
  2385. return;
  2386. }
  2387. if (pos === 0) {
  2388. if (isStart) {
  2389. self.setStartBefore(node);
  2390. } else {
  2391. self.setEndBefore(node);
  2392. }
  2393. } else if (pos == node.nodeValue.length) {
  2394. if (isStart) {
  2395. self.setStartAfter(node);
  2396. } else {
  2397. self.setEndAfter(node);
  2398. }
  2399. }
  2400. }
  2401. upPos(self.startContainer, self.startOffset, true);
  2402. upPos(self.endContainer, self.endOffset, false);
  2403. return self;
  2404. },
  2405. enlarge : function(toBlock) {
  2406. var self = this;
  2407. self.up();
  2408. function enlargePos(node, pos, isStart) {
  2409. var knode = K(node), parent;
  2410. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2411. return;
  2412. }
  2413. if (pos === 0) {
  2414. while (!knode.prev()) {
  2415. parent = knode.parent();
  2416. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2417. break;
  2418. }
  2419. knode = parent;
  2420. }
  2421. if (isStart) {
  2422. self.setStartBefore(knode[0]);
  2423. } else {
  2424. self.setEndBefore(knode[0]);
  2425. }
  2426. } else if (pos == knode.children().length) {
  2427. while (!knode.next()) {
  2428. parent = knode.parent();
  2429. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2430. break;
  2431. }
  2432. knode = parent;
  2433. }
  2434. if (isStart) {
  2435. self.setStartAfter(knode[0]);
  2436. } else {
  2437. self.setEndAfter(knode[0]);
  2438. }
  2439. }
  2440. }
  2441. enlargePos(self.startContainer, self.startOffset, true);
  2442. enlargePos(self.endContainer, self.endOffset, false);
  2443. return self;
  2444. },
  2445. shrink : function() {
  2446. var self = this, child, collapsed = self.collapsed;
  2447. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2448. self.setStart(child, 0);
  2449. }
  2450. if (collapsed) {
  2451. return self.collapse(collapsed);
  2452. }
  2453. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2454. self.setEnd(child, child.childNodes.length);
  2455. }
  2456. return self;
  2457. },
  2458. createBookmark : function(serialize) {
  2459. var self = this, doc = self.doc, endNode,
  2460. startNode = K('<span style="display:none;"></span>', doc)[0];
  2461. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2462. if (!self.collapsed) {
  2463. endNode = startNode.cloneNode(true);
  2464. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2465. }
  2466. if (endNode) {
  2467. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2468. }
  2469. self.insertNode(startNode).setStartAfter(startNode);
  2470. return {
  2471. start : serialize ? '#' + startNode.id : startNode,
  2472. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2473. };
  2474. },
  2475. moveToBookmark : function(bookmark) {
  2476. var self = this, doc = self.doc,
  2477. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2478. if (!start || start.length < 1) {
  2479. return self;
  2480. }
  2481. self.setStartBefore(start[0]);
  2482. start.remove();
  2483. if (end && end.length > 0) {
  2484. self.setEndBefore(end[0]);
  2485. end.remove();
  2486. } else {
  2487. self.collapse(true);
  2488. }
  2489. return self;
  2490. },
  2491. dump : function() {
  2492. console.log('--------------------');
  2493. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2494. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2495. }
  2496. });
  2497. function _range(mixed) {
  2498. if (!mixed.nodeName) {
  2499. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2500. }
  2501. return new KRange(mixed);
  2502. }
  2503. K.RangeClass = KRange;
  2504. K.range = _range;
  2505. K.START_TO_START = _START_TO_START;
  2506. K.START_TO_END = _START_TO_END;
  2507. K.END_TO_END = _END_TO_END;
  2508. K.END_TO_START = _END_TO_START;
  2509. function _nativeCommand(doc, key, val) {
  2510. try {
  2511. doc.execCommand(key, false, val);
  2512. } catch(e) {}
  2513. }
  2514. function _nativeCommandValue(doc, key) {
  2515. var val = '';
  2516. try {
  2517. val = doc.queryCommandValue(key);
  2518. } catch (e) {}
  2519. if (typeof val !== 'string') {
  2520. val = '';
  2521. }
  2522. return val;
  2523. }
  2524. function _getSel(doc) {
  2525. var win = _getWin(doc);
  2526. return _IERANGE ? doc.selection : win.getSelection();
  2527. }
  2528. function _getRng(doc) {
  2529. var sel = _getSel(doc), rng;
  2530. try {
  2531. if (sel.rangeCount > 0) {
  2532. rng = sel.getRangeAt(0);
  2533. } else {
  2534. rng = sel.createRange();
  2535. }
  2536. } catch(e) {}
  2537. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2538. return null;
  2539. }
  2540. return rng;
  2541. }
  2542. function _singleKeyMap(map) {
  2543. var newMap = {}, arr, v;
  2544. _each(map, function(key, val) {
  2545. arr = key.split(',');
  2546. for (var i = 0, len = arr.length; i < len; i++) {
  2547. v = arr[i];
  2548. newMap[v] = val;
  2549. }
  2550. });
  2551. return newMap;
  2552. }
  2553. function _hasAttrOrCss(knode, map) {
  2554. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2555. }
  2556. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2557. mapKey = mapKey || knode.name;
  2558. if (knode.type !== 1) {
  2559. return false;
  2560. }
  2561. var newMap = _singleKeyMap(map);
  2562. if (!newMap[mapKey]) {
  2563. return false;
  2564. }
  2565. var arr = newMap[mapKey].split(',');
  2566. for (var i = 0, len = arr.length; i < len; i++) {
  2567. var key = arr[i];
  2568. if (key === '*') {
  2569. return true;
  2570. }
  2571. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2572. var method = match[1] ? 'css' : 'attr';
  2573. key = match[2];
  2574. var val = match[3] || '';
  2575. if (val === '' && knode[method](key) !== '') {
  2576. return true;
  2577. }
  2578. if (val !== '' && knode[method](key) === val) {
  2579. return true;
  2580. }
  2581. }
  2582. return false;
  2583. }
  2584. function _removeAttrOrCss(knode, map) {
  2585. if (knode.type != 1) {
  2586. return;
  2587. }
  2588. _removeAttrOrCssByKey(knode, map, '*');
  2589. _removeAttrOrCssByKey(knode, map);
  2590. }
  2591. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2592. mapKey = mapKey || knode.name;
  2593. if (knode.type !== 1) {
  2594. return;
  2595. }
  2596. var newMap = _singleKeyMap(map);
  2597. if (!newMap[mapKey]) {
  2598. return;
  2599. }
  2600. var arr = newMap[mapKey].split(','), allFlag = false;
  2601. for (var i = 0, len = arr.length; i < len; i++) {
  2602. var key = arr[i];
  2603. if (key === '*') {
  2604. allFlag = true;
  2605. break;
  2606. }
  2607. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2608. key = match[2];
  2609. if (match[1]) {
  2610. key = _toCamel(key);
  2611. if (knode[0].style[key]) {
  2612. knode[0].style[key] = '';
  2613. }
  2614. } else {
  2615. knode.removeAttr(key);
  2616. }
  2617. }
  2618. if (allFlag) {
  2619. knode.remove(true);
  2620. }
  2621. }
  2622. function _getInnerNode(knode) {
  2623. var inner = knode;
  2624. while (inner.first()) {
  2625. inner = inner.first();
  2626. }
  2627. return inner;
  2628. }
  2629. function _isEmptyNode(knode) {
  2630. if (knode.type != 1 || knode.isSingle()) {
  2631. return false;
  2632. }
  2633. return knode.html().replace(/<[^>]+>/g, '') === '';
  2634. }
  2635. function _mergeWrapper(a, b) {
  2636. a = a.clone(true);
  2637. var lastA = _getInnerNode(a), childA = a, merged = false;
  2638. while (b) {
  2639. while (childA) {
  2640. if (childA.name === b.name) {
  2641. _mergeAttrs(childA, b.attr(), b.css());
  2642. merged = true;
  2643. }
  2644. childA = childA.first();
  2645. }
  2646. if (!merged) {
  2647. lastA.append(b.clone(false));
  2648. }
  2649. merged = false;
  2650. b = b.first();
  2651. }
  2652. return a;
  2653. }
  2654. function _wrapNode(knode, wrapper) {
  2655. wrapper = wrapper.clone(true);
  2656. if (knode.type == 3) {
  2657. _getInnerNode(wrapper).append(knode.clone(false));
  2658. knode.replaceWith(wrapper);
  2659. return wrapper;
  2660. }
  2661. var nodeWrapper = knode, child;
  2662. while ((child = knode.first()) && child.children().length == 1) {
  2663. knode = child;
  2664. }
  2665. child = knode.first();
  2666. var frag = knode.doc.createDocumentFragment();
  2667. while (child) {
  2668. frag.appendChild(child[0]);
  2669. child = child.next();
  2670. }
  2671. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2672. if (frag.firstChild) {
  2673. _getInnerNode(wrapper).append(frag);
  2674. }
  2675. nodeWrapper.replaceWith(wrapper);
  2676. return wrapper;
  2677. }
  2678. function _mergeAttrs(knode, attrs, styles) {
  2679. _each(attrs, function(key, val) {
  2680. if (key !== 'style') {
  2681. knode.attr(key, val);
  2682. }
  2683. });
  2684. _each(styles, function(key, val) {
  2685. knode.css(key, val);
  2686. });
  2687. }
  2688. function _inPreElement(knode) {
  2689. while (knode && knode.name != 'body') {
  2690. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2691. return true;
  2692. }
  2693. knode = knode.parent();
  2694. }
  2695. return false;
  2696. }
  2697. function KCmd(range) {
  2698. this.init(range);
  2699. }
  2700. _extend(KCmd, {
  2701. init : function(range) {
  2702. var self = this, doc = range.doc;
  2703. self.doc = doc;
  2704. self.win = _getWin(doc);
  2705. self.sel = _getSel(doc);
  2706. self.range = range;
  2707. },
  2708. selection : function(forceReset) {
  2709. var self = this, doc = self.doc, rng = _getRng(doc);
  2710. self.sel = _getSel(doc);
  2711. if (rng) {
  2712. self.range = _range(rng);
  2713. if (K(self.range.startContainer).name == 'html') {
  2714. self.range.selectNodeContents(doc.body).collapse(false);
  2715. }
  2716. return self;
  2717. }
  2718. if (forceReset) {
  2719. self.range.selectNodeContents(doc.body).collapse(false);
  2720. }
  2721. return self;
  2722. },
  2723. select : function(hasDummy) {
  2724. hasDummy = _undef(hasDummy, true);
  2725. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2726. sc = range.startContainer, so = range.startOffset,
  2727. ec = range.endContainer, eo = range.endOffset,
  2728. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2729. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2730. if (_IERANGE) {
  2731. var dummy = K('<span>&nbsp;</span>', doc);
  2732. range.insertNode(dummy[0]);
  2733. rng = doc.body.createTextRange();
  2734. try {
  2735. rng.moveToElementText(dummy[0]);
  2736. } catch(ex) {}
  2737. rng.collapse(false);
  2738. rng.select();
  2739. dummy.remove();
  2740. win.focus();
  2741. return self;
  2742. }
  2743. if (_WEBKIT) {
  2744. var children = sc.childNodes;
  2745. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2746. range.insertNode(doc.createTextNode('\u200B'));
  2747. hasU200b = true;
  2748. }
  2749. }
  2750. }
  2751. if (_IERANGE) {
  2752. try {
  2753. rng = range.get(true);
  2754. rng.select();
  2755. } catch(e) {}
  2756. } else {
  2757. if (hasU200b) {
  2758. range.collapse(false);
  2759. }
  2760. rng = range.get(true);
  2761. sel.removeAllRanges();
  2762. sel.addRange(rng);
  2763. if (doc !== document) {
  2764. var pos = K(rng.endContainer).pos();
  2765. win.scrollTo(pos.x, pos.y);
  2766. }
  2767. }
  2768. win.focus();
  2769. return self;
  2770. },
  2771. wrap : function(val) {
  2772. var self = this, doc = self.doc, range = self.range, wrapper;
  2773. wrapper = K(val, doc);
  2774. if (range.collapsed) {
  2775. range.shrink();
  2776. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2777. return self;
  2778. }
  2779. if (wrapper.isBlock()) {
  2780. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2781. while (child.first()) {
  2782. child = child.first();
  2783. }
  2784. child.append(range.extractContents());
  2785. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2786. return self;
  2787. }
  2788. range.enlarge();
  2789. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2790. K(ancestor).scan(function(node) {
  2791. if (!isStart && node == bookmark.start) {
  2792. isStart = true;
  2793. return;
  2794. }
  2795. if (isStart) {
  2796. if (node == bookmark.end) {
  2797. return false;
  2798. }
  2799. var knode = K(node);
  2800. if (_inPreElement(knode)) {
  2801. return;
  2802. }
  2803. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2804. var parent;
  2805. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2806. knode = parent;
  2807. }
  2808. _wrapNode(knode, wrapper);
  2809. }
  2810. }
  2811. });
  2812. range.moveToBookmark(bookmark);
  2813. return self;
  2814. },
  2815. split : function(isStart, map) {
  2816. var range = this.range, doc = range.doc;
  2817. var tempRange = range.cloneRange().collapse(isStart);
  2818. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2819. parent = node.nodeType == 3 ? node.parentNode : node,
  2820. needSplit = false, knode;
  2821. while (parent && parent.parentNode) {
  2822. knode = K(parent);
  2823. if (map) {
  2824. if (!knode.isStyle()) {
  2825. break;
  2826. }
  2827. if (!_hasAttrOrCss(knode, map)) {
  2828. break;
  2829. }
  2830. } else {
  2831. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2832. break;
  2833. }
  2834. }
  2835. needSplit = true;
  2836. parent = parent.parentNode;
  2837. }
  2838. if (needSplit) {
  2839. var dummy = doc.createElement('span');
  2840. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2841. if (isStart) {
  2842. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2843. } else {
  2844. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2845. }
  2846. var frag = tempRange.extractContents(),
  2847. first = frag.firstChild, last = frag.lastChild;
  2848. if (isStart) {
  2849. tempRange.insertNode(frag);
  2850. range.setStartAfter(last).setEndBefore(dummy);
  2851. } else {
  2852. parent.appendChild(frag);
  2853. range.setStartBefore(dummy).setEndBefore(first);
  2854. }
  2855. var dummyParent = dummy.parentNode;
  2856. if (dummyParent == range.endContainer) {
  2857. var prev = K(dummy).prev(), next = K(dummy).next();
  2858. if (prev && next && prev.type == 3 && next.type == 3) {
  2859. range.setEnd(prev[0], prev[0].nodeValue.length);
  2860. } else if (!isStart) {
  2861. range.setEnd(range.endContainer, range.endOffset - 1);
  2862. }
  2863. }
  2864. dummyParent.removeChild(dummy);
  2865. }
  2866. return this;
  2867. },
  2868. remove : function(map) {
  2869. var self = this, doc = self.doc, range = self.range;
  2870. range.enlarge();
  2871. if (range.startOffset === 0) {
  2872. var ksc = K(range.startContainer), parent;
  2873. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2874. ksc = parent;
  2875. }
  2876. range.setStart(ksc[0], 0);
  2877. ksc = K(range.startContainer);
  2878. if (ksc.isBlock()) {
  2879. _removeAttrOrCss(ksc, map);
  2880. }
  2881. var kscp = ksc.parent();
  2882. if (kscp && kscp.isBlock()) {
  2883. _removeAttrOrCss(kscp, map);
  2884. }
  2885. }
  2886. var sc, so;
  2887. if (range.collapsed) {
  2888. self.split(true, map);
  2889. sc = range.startContainer;
  2890. so = range.startOffset;
  2891. if (so > 0) {
  2892. var sb = K(sc.childNodes[so - 1]);
  2893. if (sb && _isEmptyNode(sb)) {
  2894. sb.remove();
  2895. range.setStart(sc, so - 1);
  2896. }
  2897. }
  2898. var sa = K(sc.childNodes[so]);
  2899. if (sa && _isEmptyNode(sa)) {
  2900. sa.remove();
  2901. }
  2902. if (_isEmptyNode(sc)) {
  2903. range.startBefore(sc);
  2904. sc.remove();
  2905. }
  2906. range.collapse(true);
  2907. return self;
  2908. }
  2909. self.split(true, map);
  2910. self.split(false, map);
  2911. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2912. range.cloneRange().collapse(false).insertNode(endDummy);
  2913. range.cloneRange().collapse(true).insertNode(startDummy);
  2914. var nodeList = [], cmpStart = false;
  2915. K(range.commonAncestor()).scan(function(node) {
  2916. if (!cmpStart && node == startDummy) {
  2917. cmpStart = true;
  2918. return;
  2919. }
  2920. if (node == endDummy) {
  2921. return false;
  2922. }
  2923. if (cmpStart) {
  2924. nodeList.push(node);
  2925. }
  2926. });
  2927. K(startDummy).remove();
  2928. K(endDummy).remove();
  2929. sc = range.startContainer;
  2930. so = range.startOffset;
  2931. var ec = range.endContainer, eo = range.endOffset;
  2932. if (so > 0) {
  2933. var startBefore = K(sc.childNodes[so - 1]);
  2934. if (startBefore && _isEmptyNode(startBefore)) {
  2935. startBefore.remove();
  2936. range.setStart(sc, so - 1);
  2937. if (sc == ec) {
  2938. range.setEnd(ec, eo - 1);
  2939. }
  2940. }
  2941. var startAfter = K(sc.childNodes[so]);
  2942. if (startAfter && _isEmptyNode(startAfter)) {
  2943. startAfter.remove();
  2944. if (sc == ec) {
  2945. range.setEnd(ec, eo - 1);
  2946. }
  2947. }
  2948. }
  2949. var endAfter = K(ec.childNodes[range.endOffset]);
  2950. if (endAfter && _isEmptyNode(endAfter)) {
  2951. endAfter.remove();
  2952. }
  2953. var bookmark = range.createBookmark(true);
  2954. _each(nodeList, function(i, node) {
  2955. _removeAttrOrCss(K(node), map);
  2956. });
  2957. range.moveToBookmark(bookmark);
  2958. return self;
  2959. },
  2960. commonNode : function(map) {
  2961. var range = this.range;
  2962. var ec = range.endContainer, eo = range.endOffset,
  2963. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2964. function find(node) {
  2965. var child = node, parent = node;
  2966. while (parent) {
  2967. if (_hasAttrOrCss(K(parent), map)) {
  2968. return K(parent);
  2969. }
  2970. parent = parent.parentNode;
  2971. }
  2972. while (child && (child = child.lastChild)) {
  2973. if (_hasAttrOrCss(K(child), map)) {
  2974. return K(child);
  2975. }
  2976. }
  2977. return null;
  2978. }
  2979. var cNode = find(node);
  2980. if (cNode) {
  2981. return cNode;
  2982. }
  2983. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2984. var prev = K(node).prev();
  2985. if (prev) {
  2986. return find(prev);
  2987. }
  2988. }
  2989. return null;
  2990. },
  2991. commonAncestor : function(tagName) {
  2992. var range = this.range,
  2993. sc = range.startContainer, so = range.startOffset,
  2994. ec = range.endContainer, eo = range.endOffset,
  2995. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2996. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2997. function find(node) {
  2998. while (node) {
  2999. if (node.nodeType == 1) {
  3000. if (node.tagName.toLowerCase() === tagName) {
  3001. return node;
  3002. }
  3003. }
  3004. node = node.parentNode;
  3005. }
  3006. return null;
  3007. }
  3008. var start = find(startNode), end = find(endNode);
  3009. if (start && end && start === end) {
  3010. return K(start);
  3011. }
  3012. return null;
  3013. },
  3014. state : function(key) {
  3015. var self = this, doc = self.doc, bool = false;
  3016. try {
  3017. bool = doc.queryCommandState(key);
  3018. } catch (e) {}
  3019. return bool;
  3020. },
  3021. val : function(key) {
  3022. var self = this, doc = self.doc, range = self.range;
  3023. function lc(val) {
  3024. return val.toLowerCase();
  3025. }
  3026. key = lc(key);
  3027. var val = '', knode;
  3028. if (key === 'fontfamily' || key === 'fontname') {
  3029. val = _nativeCommandValue(doc, 'fontname');
  3030. val = val.replace(/['"]/g, '');
  3031. return lc(val);
  3032. }
  3033. if (key === 'formatblock') {
  3034. val = _nativeCommandValue(doc, key);
  3035. if (val === '') {
  3036. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3037. if (knode) {
  3038. val = knode.name;
  3039. }
  3040. }
  3041. if (val === 'Normal') {
  3042. val = 'p';
  3043. }
  3044. return lc(val);
  3045. }
  3046. if (key === 'fontsize') {
  3047. knode = self.commonNode({'*' : '.font-size'});
  3048. if (knode) {
  3049. val = knode.css('font-size');
  3050. }
  3051. return lc(val);
  3052. }
  3053. if (key === 'forecolor') {
  3054. knode = self.commonNode({'*' : '.color'});
  3055. if (knode) {
  3056. val = knode.css('color');
  3057. }
  3058. val = _toHex(val);
  3059. if (val === '') {
  3060. val = 'default';
  3061. }
  3062. return lc(val);
  3063. }
  3064. if (key === 'hilitecolor') {
  3065. knode = self.commonNode({'*' : '.background-color'});
  3066. if (knode) {
  3067. val = knode.css('background-color');
  3068. }
  3069. val = _toHex(val);
  3070. if (val === '') {
  3071. val = 'default';
  3072. }
  3073. return lc(val);
  3074. }
  3075. return val;
  3076. },
  3077. toggle : function(wrapper, map) {
  3078. var self = this;
  3079. if (self.commonNode(map)) {
  3080. self.remove(map);
  3081. } else {
  3082. self.wrap(wrapper);
  3083. }
  3084. return self.select();
  3085. },
  3086. bold : function() {
  3087. return this.toggle('<strong></strong>', {
  3088. span : '.font-weight=bold',
  3089. strong : '*',
  3090. b : '*'
  3091. });
  3092. },
  3093. italic : function() {
  3094. return this.toggle('<em></em>', {
  3095. span : '.font-style=italic',
  3096. em : '*',
  3097. i : '*'
  3098. });
  3099. },
  3100. underline : function() {
  3101. return this.toggle('<u></u>', {
  3102. span : '.text-decoration=underline',
  3103. u : '*'
  3104. });
  3105. },
  3106. strikethrough : function() {
  3107. return this.toggle('<s></s>', {
  3108. span : '.text-decoration=line-through',
  3109. s : '*'
  3110. });
  3111. },
  3112. forecolor : function(val) {
  3113. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3114. },
  3115. hilitecolor : function(val) {
  3116. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3117. },
  3118. fontsize : function(val) {
  3119. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3120. },
  3121. fontname : function(val) {
  3122. return this.fontfamily(val);
  3123. },
  3124. fontfamily : function(val) {
  3125. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3126. },
  3127. removeformat : function() {
  3128. var map = {
  3129. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3130. },
  3131. tags = _STYLE_TAG_MAP;
  3132. _each(tags, function(key, val) {
  3133. map[key] = '*';
  3134. });
  3135. this.remove(map);
  3136. return this.select();
  3137. },
  3138. inserthtml : function(val, quickMode) {
  3139. var self = this, range = self.range;
  3140. if (val === '') {
  3141. return self;
  3142. }
  3143. function pasteHtml(range, val) {
  3144. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3145. var rng = range.get();
  3146. if (rng.item) {
  3147. rng.item(0).outerHTML = val;
  3148. } else {
  3149. rng.pasteHTML(val);
  3150. }
  3151. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3152. temp.parentNode.removeChild(temp);
  3153. var newRange = _toRange(rng);
  3154. range.setEnd(newRange.endContainer, newRange.endOffset);
  3155. range.collapse(false);
  3156. self.select(false);
  3157. }
  3158. function insertHtml(range, val) {
  3159. var doc = range.doc,
  3160. frag = doc.createDocumentFragment();
  3161. K('@' + val, doc).each(function() {
  3162. frag.appendChild(this);
  3163. });
  3164. range.deleteContents();
  3165. range.insertNode(frag);
  3166. range.collapse(false);
  3167. self.select(false);
  3168. }
  3169. if (_IERANGE && quickMode) {
  3170. try {
  3171. pasteHtml(range, val);
  3172. } catch(e) {
  3173. insertHtml(range, val);
  3174. }
  3175. return self;
  3176. }
  3177. insertHtml(range, val);
  3178. return self;
  3179. },
  3180. hr : function() {
  3181. return this.inserthtml('<hr />');
  3182. },
  3183. print : function() {
  3184. this.win.print();
  3185. return this;
  3186. },
  3187. insertimage : function(url, title, width, height, border, align) {
  3188. title = _undef(title, '');
  3189. border = _undef(border, 0);
  3190. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3191. if (width) {
  3192. html += 'width="' + _escape(width) + '" ';
  3193. }
  3194. if (height) {
  3195. html += 'height="' + _escape(height) + '" ';
  3196. }
  3197. if (title) {
  3198. html += 'title="' + _escape(title) + '" ';
  3199. }
  3200. if (align) {
  3201. html += 'align="' + _escape(align) + '" ';
  3202. }
  3203. html += 'alt="' + _escape(title) + '" ';
  3204. html += '/>';
  3205. return this.inserthtml(html);
  3206. },
  3207. createlink : function(url, type) {
  3208. var self = this, doc = self.doc, range = self.range;
  3209. self.select();
  3210. var a = self.commonNode({ a : '*' });
  3211. if (a && !range.isControl()) {
  3212. range.selectNode(a.get());
  3213. self.select();
  3214. }
  3215. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3216. if (type) {
  3217. html += ' target="' + _escape(type) + '"';
  3218. }
  3219. if (range.collapsed) {
  3220. html += '>' + _escape(url) + '</a>';
  3221. return self.inserthtml(html);
  3222. }
  3223. if (range.isControl()) {
  3224. var node = K(range.startContainer.childNodes[range.startOffset]);
  3225. html += '></a>';
  3226. node.after(K(html, doc));
  3227. node.next().append(node);
  3228. range.selectNode(node[0]);
  3229. return self.select();
  3230. }
  3231. function setAttr(node, url, type) {
  3232. K(node).attr('href', url).attr('data-ke-src', url);
  3233. if (type) {
  3234. K(node).attr('target', type);
  3235. } else {
  3236. K(node).removeAttr('target');
  3237. }
  3238. }
  3239. var sc = range.startContainer, so = range.startOffset,
  3240. ec = range.endContainer, eo = range.endOffset;
  3241. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3242. var child = sc.childNodes[so];
  3243. if (child.nodeName.toLowerCase() == 'a') {
  3244. setAttr(child, url, type);
  3245. return self;
  3246. }
  3247. }
  3248. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3249. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3250. setAttr(this, url, type);
  3251. });
  3252. return self;
  3253. },
  3254. unlink : function() {
  3255. var self = this, doc = self.doc, range = self.range;
  3256. self.select();
  3257. if (range.collapsed) {
  3258. var a = self.commonNode({ a : '*' });
  3259. if (a) {
  3260. range.selectNode(a.get());
  3261. self.select();
  3262. }
  3263. _nativeCommand(doc, 'unlink', null);
  3264. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3265. var parent = K(range.startContainer).parent();
  3266. if (parent.name === 'a') {
  3267. parent.remove(true);
  3268. }
  3269. }
  3270. } else {
  3271. _nativeCommand(doc, 'unlink', null);
  3272. }
  3273. return self;
  3274. }
  3275. });
  3276. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3277. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3278. KCmd.prototype[name] = function(val) {
  3279. var self = this;
  3280. self.select();
  3281. _nativeCommand(self.doc, name, val);
  3282. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3283. self.selection();
  3284. }
  3285. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3286. self.selection();
  3287. }
  3288. return self;
  3289. };
  3290. });
  3291. _each('cut,copy,paste'.split(','), function(i, name) {
  3292. KCmd.prototype[name] = function() {
  3293. var self = this;
  3294. if (!self.doc.queryCommandSupported(name)) {
  3295. throw 'not supported';
  3296. }
  3297. self.select();
  3298. _nativeCommand(self.doc, name, null);
  3299. return self;
  3300. };
  3301. });
  3302. function _cmd(mixed) {
  3303. if (mixed.nodeName) {
  3304. var doc = _getDoc(mixed);
  3305. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3306. }
  3307. return new KCmd(mixed);
  3308. }
  3309. K.CmdClass = KCmd;
  3310. K.cmd = _cmd;
  3311. function _drag(options) {
  3312. var moveEl = options.moveEl,
  3313. moveFn = options.moveFn,
  3314. clickEl = options.clickEl || moveEl,
  3315. beforeDrag = options.beforeDrag,
  3316. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3317. var docs = [document];
  3318. if (iframeFix) {
  3319. K('iframe').each(function() {
  3320. var src = _formatUrl(this.src || '', 'absolute');
  3321. if (/^https?:\/\//.test(src)) {
  3322. return;
  3323. }
  3324. var doc;
  3325. try {
  3326. doc = _iframeDoc(this);
  3327. } catch(e) {}
  3328. if (doc) {
  3329. var pos = K(this).pos();
  3330. K(doc).data('pos-x', pos.x);
  3331. K(doc).data('pos-y', pos.y);
  3332. docs.push(doc);
  3333. }
  3334. });
  3335. }
  3336. clickEl.mousedown(function(e) {
  3337. if(e.button !== 0 && e.button !== 1) {
  3338. return;
  3339. }
  3340. e.stopPropagation();
  3341. var self = clickEl.get(),
  3342. x = _removeUnit(moveEl.css('left')),
  3343. y = _removeUnit(moveEl.css('top')),
  3344. width = moveEl.width(),
  3345. height = moveEl.height(),
  3346. pageX = e.pageX,
  3347. pageY = e.pageY;
  3348. if (beforeDrag) {
  3349. beforeDrag();
  3350. }
  3351. function moveListener(e) {
  3352. e.preventDefault();
  3353. var kdoc = K(_getDoc(e.target));
  3354. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3355. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3356. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3357. }
  3358. function selectListener(e) {
  3359. e.preventDefault();
  3360. }
  3361. function upListener(e) {
  3362. e.preventDefault();
  3363. K(docs).unbind('mousemove', moveListener)
  3364. .unbind('mouseup', upListener)
  3365. .unbind('selectstart', selectListener);
  3366. if (self.releaseCapture) {
  3367. self.releaseCapture();
  3368. }
  3369. }
  3370. K(docs).mousemove(moveListener)
  3371. .mouseup(upListener)
  3372. .bind('selectstart', selectListener);
  3373. if (self.setCapture) {
  3374. self.setCapture();
  3375. }
  3376. });
  3377. }
  3378. function KWidget(options) {
  3379. this.init(options);
  3380. }
  3381. _extend(KWidget, {
  3382. init : function(options) {
  3383. var self = this;
  3384. self.name = options.name || '';
  3385. self.doc = options.doc || document;
  3386. self.win = _getWin(self.doc);
  3387. self.x = _addUnit(options.x);
  3388. self.y = _addUnit(options.y);
  3389. self.z = options.z;
  3390. self.width = _addUnit(options.width);
  3391. self.height = _addUnit(options.height);
  3392. self.div = K('<div style="display:block;"></div>');
  3393. self.options = options;
  3394. self._alignEl = options.alignEl;
  3395. if (self.width) {
  3396. self.div.css('width', self.width);
  3397. }
  3398. if (self.height) {
  3399. self.div.css('height', self.height);
  3400. }
  3401. if (self.z) {
  3402. self.div.css({
  3403. position : 'absolute',
  3404. left : self.x,
  3405. top : self.y,
  3406. 'z-index' : self.z
  3407. });
  3408. }
  3409. if (self.z && (self.x === undefined || self.y === undefined)) {
  3410. self.autoPos(self.width, self.height);
  3411. }
  3412. if (options.cls) {
  3413. self.div.addClass(options.cls);
  3414. }
  3415. if (options.shadowMode) {
  3416. self.div.addClass('ke-shadow');
  3417. }
  3418. if (options.css) {
  3419. self.div.css(options.css);
  3420. }
  3421. if (options.src) {
  3422. K(options.src).replaceWith(self.div);
  3423. } else {
  3424. K(self.doc.body).append(self.div);
  3425. }
  3426. if (options.html) {
  3427. self.div.html(options.html);
  3428. }
  3429. if (options.autoScroll) {
  3430. if (_IE && _V < 7 || _QUIRKS) {
  3431. var scrollPos = _getScrollPos();
  3432. K(self.win).bind('scroll', function(e) {
  3433. var pos = _getScrollPos(),
  3434. diffX = pos.x - scrollPos.x,
  3435. diffY = pos.y - scrollPos.y;
  3436. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3437. });
  3438. } else {
  3439. self.div.css('position', 'fixed');
  3440. }
  3441. }
  3442. },
  3443. pos : function(x, y, updateProp) {
  3444. var self = this;
  3445. updateProp = _undef(updateProp, true);
  3446. if (x !== null) {
  3447. x = x < 0 ? 0 : _addUnit(x);
  3448. self.div.css('left', x);
  3449. if (updateProp) {
  3450. self.x = x;
  3451. }
  3452. }
  3453. if (y !== null) {
  3454. y = y < 0 ? 0 : _addUnit(y);
  3455. self.div.css('top', y);
  3456. if (updateProp) {
  3457. self.y = y;
  3458. }
  3459. }
  3460. return self;
  3461. },
  3462. autoPos : function(width, height) {
  3463. var x, y, self = this,
  3464. w = _removeUnit(width) || 0,
  3465. h = _removeUnit(height) || 0,
  3466. scrollPos = _getScrollPos();
  3467. if (self._alignEl) {
  3468. var knode = K(self._alignEl),
  3469. pos = knode.pos(),
  3470. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3471. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3472. x = diffX < 0 ? pos.x : pos.x + diffX;
  3473. y = diffY < 0 ? pos.y : pos.y + diffY;
  3474. } else {
  3475. var docEl = _docElement(self.doc);
  3476. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3477. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3478. }
  3479. if (!(_IE && _V < 7 || _QUIRKS)) {
  3480. x -= scrollPos.x;
  3481. y -= scrollPos.y;
  3482. }
  3483. return self.pos(x, y);
  3484. },
  3485. remove : function() {
  3486. var self = this;
  3487. if (_IE && _V < 7 || _QUIRKS) {
  3488. K(self.win).unbind('scroll');
  3489. }
  3490. self.div.remove();
  3491. _each(self, function(i) {
  3492. self[i] = null;
  3493. });
  3494. return this;
  3495. },
  3496. show : function() {
  3497. this.div.show();
  3498. return this;
  3499. },
  3500. hide : function() {
  3501. this.div.hide();
  3502. return this;
  3503. },
  3504. draggable : function(options) {
  3505. var self = this;
  3506. options = options || {};
  3507. options.moveEl = self.div;
  3508. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3509. if ((x = x + diffX) < 0) {
  3510. x = 0;
  3511. }
  3512. if ((y = y + diffY) < 0) {
  3513. y = 0;
  3514. }
  3515. self.pos(x, y);
  3516. };
  3517. _drag(options);
  3518. return self;
  3519. }
  3520. });
  3521. function _widget(options) {
  3522. return new KWidget(options);
  3523. }
  3524. K.WidgetClass = KWidget;
  3525. K.widget = _widget;
  3526. function _iframeDoc(iframe) {
  3527. iframe = _get(iframe);
  3528. return iframe.contentDocument || iframe.contentWindow.document;
  3529. }
  3530. var html, _direction = '';
  3531. if ((html = document.getElementsByTagName('html'))) {
  3532. _direction = html[0].dir;
  3533. }
  3534. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3535. var arr = [
  3536. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3537. '<head><meta charset="utf-8" /><title></title>',
  3538. '<style>',
  3539. 'html {margin:0;padding:0;}',
  3540. 'body {margin:0;padding:5px;}',
  3541. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3542. 'body, p, div {word-wrap: break-word;}',
  3543. 'p {margin:5px 0;}',
  3544. 'table {border-collapse:collapse;}',
  3545. 'img {border:0;}',
  3546. 'noscript {display:none;}',
  3547. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3548. 'img.ke-flash {',
  3549. ' border:1px solid #AAA;',
  3550. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3551. ' background-position:center center;',
  3552. ' background-repeat:no-repeat;',
  3553. ' width:100px;',
  3554. ' height:100px;',
  3555. '}',
  3556. 'img.ke-rm {',
  3557. ' border:1px solid #AAA;',
  3558. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3559. ' background-position:center center;',
  3560. ' background-repeat:no-repeat;',
  3561. ' width:100px;',
  3562. ' height:100px;',
  3563. '}',
  3564. 'img.ke-media {',
  3565. ' border:1px solid #AAA;',
  3566. ' background-image:url(' + themesPath + 'common/media.gif);',
  3567. ' background-position:center center;',
  3568. ' background-repeat:no-repeat;',
  3569. ' width:100px;',
  3570. ' height:100px;',
  3571. '}',
  3572. 'img.ke-anchor {',
  3573. ' border:1px dashed #666;',
  3574. ' width:16px;',
  3575. ' height:16px;',
  3576. '}',
  3577. '.ke-script, .ke-noscript, .ke-display-none {',
  3578. ' display:none;',
  3579. ' font-size:0;',
  3580. ' width:0;',
  3581. ' height:0;',
  3582. '}',
  3583. '.ke-pagebreak {',
  3584. ' border:1px dotted #AAA;',
  3585. ' font-size:0;',
  3586. ' height:2px;',
  3587. '}',
  3588. '</style>'
  3589. ];
  3590. if (!_isArray(cssPath)) {
  3591. cssPath = [cssPath];
  3592. }
  3593. _each(cssPath, function(i, path) {
  3594. if (path) {
  3595. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3596. }
  3597. });
  3598. if (cssData) {
  3599. arr.push('<style>' + cssData + '</style>');
  3600. }
  3601. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3602. return arr.join('\n');
  3603. }
  3604. function _elementVal(knode, val) {
  3605. if (knode.hasVal()) {
  3606. if (val === undefined) {
  3607. var html = knode.val();
  3608. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3609. return html;
  3610. }
  3611. return knode.val(val);
  3612. }
  3613. return knode.html(val);
  3614. }
  3615. function KEdit(options) {
  3616. this.init(options);
  3617. }
  3618. _extend(KEdit, KWidget, {
  3619. init : function(options) {
  3620. var self = this;
  3621. KEdit.parent.init.call(self, options);
  3622. self.srcElement = K(options.srcElement);
  3623. self.div.addClass('ke-edit');
  3624. self.designMode = _undef(options.designMode, true);
  3625. self.beforeGetHtml = options.beforeGetHtml;
  3626. self.beforeSetHtml = options.beforeSetHtml;
  3627. self.afterSetHtml = options.afterSetHtml;
  3628. var themesPath = _undef(options.themesPath, ''),
  3629. bodyClass = options.bodyClass,
  3630. cssPath = options.cssPath,
  3631. cssData = options.cssData,
  3632. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3633. srcScript = ('document.open();' +
  3634. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3635. 'document.close();'),
  3636. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3637. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3638. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3639. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3640. self.iframe.attr('tabindex', self.tabIndex);
  3641. self.textarea.attr('tabindex', self.tabIndex);
  3642. if (self.width) {
  3643. self.setWidth(self.width);
  3644. }
  3645. if (self.height) {
  3646. self.setHeight(self.height);
  3647. }
  3648. if (self.designMode) {
  3649. self.textarea.hide();
  3650. } else {
  3651. self.iframe.hide();
  3652. }
  3653. function ready() {
  3654. var doc = _iframeDoc(self.iframe);
  3655. doc.open();
  3656. if (isDocumentDomain) {
  3657. doc.domain = document.domain;
  3658. }
  3659. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3660. doc.close();
  3661. self.win = self.iframe[0].contentWindow;
  3662. self.doc = doc;
  3663. var cmd = _cmd(doc);
  3664. self.afterChange(function(e) {
  3665. cmd.selection();
  3666. });
  3667. if (_WEBKIT) {
  3668. K(doc).click(function(e) {
  3669. if (K(e.target).name === 'img') {
  3670. cmd.selection(true);
  3671. cmd.range.selectNode(e.target);
  3672. cmd.select();
  3673. }
  3674. });
  3675. }
  3676. if (_IE) {
  3677. self._mousedownHandler = function() {
  3678. var newRange = cmd.range.cloneRange();
  3679. newRange.shrink();
  3680. if (newRange.isControl()) {
  3681. self.blur();
  3682. }
  3683. };
  3684. K(document).mousedown(self._mousedownHandler);
  3685. K(doc).keydown(function(e) {
  3686. if (e.which == 8) {
  3687. cmd.selection();
  3688. var rng = cmd.range;
  3689. if (rng.isControl()) {
  3690. rng.collapse(true);
  3691. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3692. e.preventDefault();
  3693. }
  3694. }
  3695. });
  3696. }
  3697. self.cmd = cmd;
  3698. self.html(_elementVal(self.srcElement));
  3699. if (_IE) {
  3700. doc.body.disabled = true;
  3701. doc.body.contentEditable = true;
  3702. doc.body.removeAttribute('disabled');
  3703. } else {
  3704. doc.designMode = 'on';
  3705. }
  3706. if (options.afterCreate) {
  3707. options.afterCreate.call(self);
  3708. }
  3709. }
  3710. if (isDocumentDomain) {
  3711. self.iframe.bind('load', function(e) {
  3712. self.iframe.unbind('load');
  3713. if (_IE) {
  3714. ready();
  3715. } else {
  3716. setTimeout(ready, 0);
  3717. }
  3718. });
  3719. }
  3720. self.div.append(self.iframe);
  3721. self.div.append(self.textarea);
  3722. self.srcElement.hide();
  3723. !isDocumentDomain && ready();
  3724. },
  3725. setWidth : function(val) {
  3726. var self = this;
  3727. val = _addUnit(val);
  3728. self.width = val;
  3729. self.div.css('width', val);
  3730. return self;
  3731. },
  3732. setHeight : function(val) {
  3733. var self = this;
  3734. val = _addUnit(val);
  3735. self.height = val;
  3736. self.div.css('height', val);
  3737. self.iframe.css('height', val);
  3738. if ((_IE && _V < 8) || _QUIRKS) {
  3739. val = _addUnit(_removeUnit(val) - 2);
  3740. }
  3741. self.textarea.css('height', val);
  3742. return self;
  3743. },
  3744. remove : function() {
  3745. var self = this, doc = self.doc;
  3746. K(doc.body).unbind();
  3747. K(doc).unbind();
  3748. K(self.win).unbind();
  3749. if (self._mousedownHandler) {
  3750. K(document).unbind('mousedown', self._mousedownHandler);
  3751. }
  3752. _elementVal(self.srcElement, self.html());
  3753. self.srcElement.show();
  3754. self.iframe.unbind();
  3755. self.textarea.unbind();
  3756. KEdit.parent.remove.call(self);
  3757. },
  3758. html : function(val, isFull) {
  3759. var self = this, doc = self.doc;
  3760. if (self.designMode) {
  3761. var body = doc.body;
  3762. if (val === undefined) {
  3763. if (isFull) {
  3764. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3765. } else {
  3766. val = body.innerHTML;
  3767. }
  3768. if (self.beforeGetHtml) {
  3769. val = self.beforeGetHtml(val);
  3770. }
  3771. if (_GECKO && val == '<br />') {
  3772. val = '';
  3773. }
  3774. return val;
  3775. }
  3776. if (self.beforeSetHtml) {
  3777. val = self.beforeSetHtml(val);
  3778. }
  3779. if (_IE && _V >= 9) {
  3780. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3781. }
  3782. K(body).html(val);
  3783. if (self.afterSetHtml) {
  3784. self.afterSetHtml();
  3785. }
  3786. return self;
  3787. }
  3788. if (val === undefined) {
  3789. return self.textarea.val();
  3790. }
  3791. self.textarea.val(val);
  3792. return self;
  3793. },
  3794. design : function(bool) {
  3795. var self = this, val;
  3796. if (bool === undefined ? !self.designMode : bool) {
  3797. if (!self.designMode) {
  3798. val = self.html();
  3799. self.designMode = true;
  3800. self.textarea.hide();
  3801. self.html(val);
  3802. var iframe = self.iframe;
  3803. var height = _removeUnit(self.height);
  3804. iframe.height(height - 2);
  3805. iframe.show();
  3806. setTimeout(function() {
  3807. iframe.height(height);
  3808. }, 0);
  3809. }
  3810. } else {
  3811. if (self.designMode) {
  3812. val = self.html();
  3813. self.designMode = false;
  3814. self.html(val);
  3815. self.iframe.hide();
  3816. self.textarea.show();
  3817. }
  3818. }
  3819. return self.focus();
  3820. },
  3821. focus : function() {
  3822. var self = this;
  3823. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3824. return self;
  3825. },
  3826. blur : function() {
  3827. var self = this;
  3828. if (_IE) {
  3829. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3830. self.div.append(input);
  3831. input[0].focus();
  3832. input.remove();
  3833. } else {
  3834. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3835. }
  3836. return self;
  3837. },
  3838. afterChange : function(fn) {
  3839. var self = this, doc = self.doc, body = doc.body;
  3840. K(doc).keyup(function(e) {
  3841. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3842. fn(e);
  3843. }
  3844. });
  3845. K(doc).mouseup(fn).contextmenu(fn);
  3846. K(self.win).blur(fn);
  3847. function timeoutHandler(e) {
  3848. setTimeout(function() {
  3849. fn(e);
  3850. }, 1);
  3851. }
  3852. K(body).bind('paste', timeoutHandler);
  3853. K(body).bind('cut', timeoutHandler);
  3854. return self;
  3855. }
  3856. });
  3857. function _edit(options) {
  3858. return new KEdit(options);
  3859. }
  3860. K.EditClass = KEdit;
  3861. K.edit = _edit;
  3862. K.iframeDoc = _iframeDoc;
  3863. function _selectToolbar(name, fn) {
  3864. var self = this,
  3865. knode = self.get(name);
  3866. if (knode) {
  3867. if (knode.hasClass('ke-disabled')) {
  3868. return;
  3869. }
  3870. fn(knode);
  3871. }
  3872. }
  3873. function KToolbar(options) {
  3874. this.init(options);
  3875. }
  3876. _extend(KToolbar, KWidget, {
  3877. init : function(options) {
  3878. var self = this;
  3879. KToolbar.parent.init.call(self, options);
  3880. self.disableMode = _undef(options.disableMode, false);
  3881. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3882. self._itemMap = {};
  3883. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3884. e.preventDefault();
  3885. }).attr('unselectable', 'on');
  3886. function find(target) {
  3887. var knode = K(target);
  3888. if (knode.hasClass('ke-outline')) {
  3889. return knode;
  3890. }
  3891. if (knode.hasClass('ke-toolbar-icon')) {
  3892. return knode.parent();
  3893. }
  3894. }
  3895. function hover(e, method) {
  3896. var knode = find(e.target);
  3897. if (knode) {
  3898. if (knode.hasClass('ke-disabled')) {
  3899. return;
  3900. }
  3901. if (knode.hasClass('ke-selected')) {
  3902. return;
  3903. }
  3904. knode[method]('ke-on');
  3905. }
  3906. }
  3907. self.div.mouseover(function(e) {
  3908. hover(e, 'addClass');
  3909. })
  3910. .mouseout(function(e) {
  3911. hover(e, 'removeClass');
  3912. })
  3913. .click(function(e) {
  3914. var knode = find(e.target);
  3915. if (knode) {
  3916. if (knode.hasClass('ke-disabled')) {
  3917. return;
  3918. }
  3919. self.options.click.call(this, e, knode.attr('data-name'));
  3920. }
  3921. });
  3922. },
  3923. get : function(name) {
  3924. if (this._itemMap[name]) {
  3925. return this._itemMap[name];
  3926. }
  3927. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3928. },
  3929. select : function(name) {
  3930. _selectToolbar.call(this, name, function(knode) {
  3931. knode.addClass('ke-selected');
  3932. });
  3933. return self;
  3934. },
  3935. unselect : function(name) {
  3936. _selectToolbar.call(this, name, function(knode) {
  3937. knode.removeClass('ke-selected').removeClass('ke-on');
  3938. });
  3939. return self;
  3940. },
  3941. enable : function(name) {
  3942. var self = this,
  3943. knode = name.get ? name : self.get(name);
  3944. if (knode) {
  3945. knode.removeClass('ke-disabled');
  3946. knode.opacity(1);
  3947. }
  3948. return self;
  3949. },
  3950. disable : function(name) {
  3951. var self = this,
  3952. knode = name.get ? name : self.get(name);
  3953. if (knode) {
  3954. knode.removeClass('ke-selected').addClass('ke-disabled');
  3955. knode.opacity(0.5);
  3956. }
  3957. return self;
  3958. },
  3959. disableAll : function(bool, noDisableItems) {
  3960. var self = this, map = self.noDisableItemMap, item;
  3961. if (noDisableItems) {
  3962. map = _toMap(noDisableItems);
  3963. }
  3964. if (bool === undefined ? !self.disableMode : bool) {
  3965. K('span.ke-outline', self.div).each(function() {
  3966. var knode = K(this),
  3967. name = knode[0].getAttribute('data-name', 2);
  3968. if (!map[name]) {
  3969. self.disable(knode);
  3970. }
  3971. });
  3972. self.disableMode = true;
  3973. } else {
  3974. K('span.ke-outline', self.div).each(function() {
  3975. var knode = K(this),
  3976. name = knode[0].getAttribute('data-name', 2);
  3977. if (!map[name]) {
  3978. self.enable(knode);
  3979. }
  3980. });
  3981. self.disableMode = false;
  3982. }
  3983. return self;
  3984. }
  3985. });
  3986. function _toolbar(options) {
  3987. return new KToolbar(options);
  3988. }
  3989. K.ToolbarClass = KToolbar;
  3990. K.toolbar = _toolbar;
  3991. function KMenu(options) {
  3992. this.init(options);
  3993. }
  3994. _extend(KMenu, KWidget, {
  3995. init : function(options) {
  3996. var self = this;
  3997. options.z = options.z || 811213;
  3998. KMenu.parent.init.call(self, options);
  3999. self.centerLineMode = _undef(options.centerLineMode, true);
  4000. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4001. e.stopPropagation();
  4002. }).attr('unselectable', 'on');
  4003. },
  4004. addItem : function(item) {
  4005. var self = this;
  4006. if (item.title === '-') {
  4007. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4008. return;
  4009. }
  4010. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4011. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4012. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4013. height = _addUnit(item.height),
  4014. iconClass = _undef(item.iconClass, '');
  4015. self.div.append(itemDiv);
  4016. if (height) {
  4017. itemDiv.css('height', height);
  4018. rightDiv.css('line-height', height);
  4019. }
  4020. var centerDiv;
  4021. if (self.centerLineMode) {
  4022. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4023. if (height) {
  4024. centerDiv.css('height', height);
  4025. }
  4026. }
  4027. itemDiv.mouseover(function(e) {
  4028. K(this).addClass('ke-menu-item-on');
  4029. if (centerDiv) {
  4030. centerDiv.addClass('ke-menu-item-center-on');
  4031. }
  4032. })
  4033. .mouseout(function(e) {
  4034. K(this).removeClass('ke-menu-item-on');
  4035. if (centerDiv) {
  4036. centerDiv.removeClass('ke-menu-item-center-on');
  4037. }
  4038. })
  4039. .click(function(e) {
  4040. item.click.call(K(this));
  4041. e.stopPropagation();
  4042. })
  4043. .append(leftDiv);
  4044. if (centerDiv) {
  4045. itemDiv.append(centerDiv);
  4046. }
  4047. itemDiv.append(rightDiv);
  4048. if (item.checked) {
  4049. iconClass = 'ke-icon-checked';
  4050. }
  4051. if (iconClass !== '') {
  4052. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4053. }
  4054. rightDiv.html(item.title);
  4055. return self;
  4056. },
  4057. remove : function() {
  4058. var self = this;
  4059. if (self.options.beforeRemove) {
  4060. self.options.beforeRemove.call(self);
  4061. }
  4062. K('.ke-menu-item', self.div[0]).unbind();
  4063. KMenu.parent.remove.call(self);
  4064. return self;
  4065. }
  4066. });
  4067. function _menu(options) {
  4068. return new KMenu(options);
  4069. }
  4070. K.MenuClass = KMenu;
  4071. K.menu = _menu;
  4072. function KColorPicker(options) {
  4073. this.init(options);
  4074. }
  4075. _extend(KColorPicker, KWidget, {
  4076. init : function(options) {
  4077. var self = this;
  4078. options.z = options.z || 811213;
  4079. KColorPicker.parent.init.call(self, options);
  4080. var colors = options.colors || [
  4081. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4082. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4083. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4084. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4085. ];
  4086. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4087. self._cells = [];
  4088. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4089. e.stopPropagation();
  4090. }).attr('unselectable', 'on');
  4091. var table = self.doc.createElement('table');
  4092. self.div.append(table);
  4093. table.className = 'ke-colorpicker-table';
  4094. table.cellPadding = 0;
  4095. table.cellSpacing = 0;
  4096. table.border = 0;
  4097. var row = table.insertRow(0), cell = row.insertCell(0);
  4098. cell.colSpan = colors[0].length;
  4099. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4100. for (var i = 0; i < colors.length; i++) {
  4101. row = table.insertRow(i + 1);
  4102. for (var j = 0; j < colors[i].length; j++) {
  4103. cell = row.insertCell(j);
  4104. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4105. }
  4106. }
  4107. },
  4108. _addAttr : function(cell, color, cls) {
  4109. var self = this;
  4110. cell = K(cell).addClass(cls);
  4111. if (self.selectedColor === color.toLowerCase()) {
  4112. cell.addClass('ke-colorpicker-cell-selected');
  4113. }
  4114. cell.attr('title', color || self.options.noColor);
  4115. cell.mouseover(function(e) {
  4116. K(this).addClass('ke-colorpicker-cell-on');
  4117. });
  4118. cell.mouseout(function(e) {
  4119. K(this).removeClass('ke-colorpicker-cell-on');
  4120. });
  4121. cell.click(function(e) {
  4122. e.stop();
  4123. self.options.click.call(K(this), color);
  4124. });
  4125. if (color) {
  4126. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4127. } else {
  4128. cell.html(self.options.noColor);
  4129. }
  4130. K(cell).attr('unselectable', 'on');
  4131. self._cells.push(cell);
  4132. },
  4133. remove : function() {
  4134. var self = this;
  4135. _each(self._cells, function() {
  4136. this.unbind();
  4137. });
  4138. KColorPicker.parent.remove.call(self);
  4139. return self;
  4140. }
  4141. });
  4142. function _colorpicker(options) {
  4143. return new KColorPicker(options);
  4144. }
  4145. K.ColorPickerClass = KColorPicker;
  4146. K.colorpicker = _colorpicker;
  4147. function KUploadButton(options) {
  4148. this.init(options);
  4149. }
  4150. _extend(KUploadButton, {
  4151. init : function(options) {
  4152. var self = this,
  4153. button = K(options.button),
  4154. fieldName = options.fieldName || 'file',
  4155. url = options.url || '',
  4156. title = button.val(),
  4157. extraParams = options.extraParams || {},
  4158. cls = button[0].className || '',
  4159. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4160. options.afterError = options.afterError || function(str) {
  4161. alert(str);
  4162. };
  4163. var hiddenElements = [];
  4164. for(var k in extraParams){
  4165. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4166. }
  4167. var html = [
  4168. '<div class="ke-inline-block ' + cls + '">',
  4169. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4170. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4171. '<span class="ke-button-common">',
  4172. hiddenElements.join(''),
  4173. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4174. '</span>',
  4175. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4176. (options.form ? '</div>' : '</form>'),
  4177. '</div>'].join('');
  4178. var div = K(html, button.doc);
  4179. button.hide();
  4180. button.before(div);
  4181. self.div = div;
  4182. self.button = button;
  4183. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4184. self.form = options.form ? K(options.form) : K('form', div);
  4185. self.fileBox = K('.ke-upload-file', div);
  4186. var width = options.width || K('.ke-button-common', div).width();
  4187. K('.ke-upload-area', div).width(width);
  4188. self.options = options;
  4189. },
  4190. submit : function() {
  4191. var self = this,
  4192. iframe = self.iframe;
  4193. iframe.bind('load', function() {
  4194. iframe.unbind();
  4195. var tempForm = document.createElement('form');
  4196. self.fileBox.before(tempForm);
  4197. K(tempForm).append(self.fileBox);
  4198. tempForm.reset();
  4199. K(tempForm).remove(true);
  4200. var doc = K.iframeDoc(iframe),
  4201. pre = doc.getElementsByTagName('pre')[0],
  4202. str = '', data;
  4203. if (pre) {
  4204. str = pre.innerHTML;
  4205. } else {
  4206. str = doc.body.innerHTML;
  4207. }
  4208. str = _unescape(str);
  4209. iframe[0].src = 'javascript:false';
  4210. try {
  4211. data = K.json(str);
  4212. } catch (e) {
  4213. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4214. }
  4215. if (data) {
  4216. self.options.afterUpload.call(self, data);
  4217. }
  4218. });
  4219. self.form[0].submit();
  4220. return self;
  4221. },
  4222. remove : function() {
  4223. var self = this;
  4224. if (self.fileBox) {
  4225. self.fileBox.unbind();
  4226. }
  4227. self.iframe.remove();
  4228. self.div.remove();
  4229. self.button.show();
  4230. return self;
  4231. }
  4232. });
  4233. function _uploadbutton(options) {
  4234. return new KUploadButton(options);
  4235. }
  4236. K.UploadButtonClass = KUploadButton;
  4237. K.uploadbutton = _uploadbutton;
  4238. function _createButton(arg) {
  4239. arg = arg || {};
  4240. var name = arg.name || '',
  4241. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4242. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4243. if (arg.click) {
  4244. btn.click(arg.click);
  4245. }
  4246. span.append(btn);
  4247. return span;
  4248. }
  4249. function KDialog(options) {
  4250. this.init(options);
  4251. }
  4252. _extend(KDialog, KWidget, {
  4253. init : function(options) {
  4254. var self = this;
  4255. var shadowMode = _undef(options.shadowMode, true);
  4256. options.z = options.z || 811213;
  4257. options.shadowMode = false;
  4258. options.autoScroll = _undef(options.autoScroll, true);
  4259. KDialog.parent.init.call(self, options);
  4260. var title = options.title,
  4261. body = K(options.body, self.doc),
  4262. previewBtn = options.previewBtn,
  4263. yesBtn = options.yesBtn,
  4264. noBtn = options.noBtn,
  4265. closeBtn = options.closeBtn,
  4266. showMask = _undef(options.showMask, true);
  4267. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4268. e.stopPropagation();
  4269. });
  4270. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4271. if (_IE && _V < 7) {
  4272. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4273. } else if (shadowMode) {
  4274. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4275. }
  4276. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4277. contentDiv.append(headerDiv);
  4278. headerDiv.html(title);
  4279. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4280. headerDiv.append(self.closeIcon);
  4281. self.draggable({
  4282. clickEl : headerDiv,
  4283. beforeDrag : options.beforeDrag
  4284. });
  4285. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4286. contentDiv.append(bodyDiv);
  4287. bodyDiv.append(body);
  4288. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4289. if (previewBtn || yesBtn || noBtn) {
  4290. contentDiv.append(footerDiv);
  4291. }
  4292. _each([
  4293. { btn : previewBtn, name : 'preview' },
  4294. { btn : yesBtn, name : 'yes' },
  4295. { btn : noBtn, name : 'no' }
  4296. ], function() {
  4297. if (this.btn) {
  4298. var button = _createButton(this.btn);
  4299. button.addClass('ke-dialog-' + this.name);
  4300. footerDiv.append(button);
  4301. }
  4302. });
  4303. if (self.height) {
  4304. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4305. }
  4306. self.div.width(self.div.width());
  4307. self.div.height(self.div.height());
  4308. self.mask = null;
  4309. if (showMask) {
  4310. var docEl = _docElement(self.doc),
  4311. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4312. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4313. self.mask = _widget({
  4314. x : 0,
  4315. y : 0,
  4316. z : self.z - 1,
  4317. cls : 'ke-dialog-mask',
  4318. width : docWidth,
  4319. height : docHeight
  4320. });
  4321. }
  4322. self.autoPos(self.div.width(), self.div.height());
  4323. self.footerDiv = footerDiv;
  4324. self.bodyDiv = bodyDiv;
  4325. self.headerDiv = headerDiv;
  4326. self.isLoading = false;
  4327. },
  4328. setMaskIndex : function(z) {
  4329. var self = this;
  4330. self.mask.div.css('z-index', z);
  4331. },
  4332. showLoading : function(msg) {
  4333. msg = _undef(msg, '');
  4334. var self = this, body = self.bodyDiv;
  4335. 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>')
  4336. .width(body.width()).height(body.height())
  4337. .css('top', self.headerDiv.height() + 'px');
  4338. body.css('visibility', 'hidden').after(self.loading);
  4339. self.isLoading = true;
  4340. return self;
  4341. },
  4342. hideLoading : function() {
  4343. this.loading && this.loading.remove();
  4344. this.bodyDiv.css('visibility', 'visible');
  4345. this.isLoading = false;
  4346. return this;
  4347. },
  4348. remove : function() {
  4349. var self = this;
  4350. if (self.options.beforeRemove) {
  4351. self.options.beforeRemove.call(self);
  4352. }
  4353. self.mask && self.mask.remove();
  4354. self.iframeMask && self.iframeMask.remove();
  4355. self.closeIcon.unbind();
  4356. K('input', self.div).unbind();
  4357. K('button', self.div).unbind();
  4358. self.footerDiv.unbind();
  4359. self.bodyDiv.unbind();
  4360. self.headerDiv.unbind();
  4361. K('iframe', self.div).each(function() {
  4362. K(this).remove();
  4363. });
  4364. KDialog.parent.remove.call(self);
  4365. return self;
  4366. }
  4367. });
  4368. function _dialog(options) {
  4369. return new KDialog(options);
  4370. }
  4371. K.DialogClass = KDialog;
  4372. K.dialog = _dialog;
  4373. function _tabs(options) {
  4374. var self = _widget(options),
  4375. remove = self.remove,
  4376. afterSelect = options.afterSelect,
  4377. div = self.div,
  4378. liList = [];
  4379. div.addClass('ke-tabs')
  4380. .bind('contextmenu,mousedown,mousemove', function(e) {
  4381. e.preventDefault();
  4382. });
  4383. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4384. div.append(ul);
  4385. self.add = function(tab) {
  4386. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4387. li.data('tab', tab);
  4388. liList.push(li);
  4389. ul.append(li);
  4390. };
  4391. self.selectedIndex = 0;
  4392. self.select = function(index) {
  4393. self.selectedIndex = index;
  4394. _each(liList, function(i, li) {
  4395. li.unbind();
  4396. if (i === index) {
  4397. li.addClass('ke-tabs-li-selected');
  4398. K(li.data('tab').panel).show('');
  4399. } else {
  4400. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4401. .mouseover(function() {
  4402. K(this).addClass('ke-tabs-li-on');
  4403. })
  4404. .mouseout(function() {
  4405. K(this).removeClass('ke-tabs-li-on');
  4406. })
  4407. .click(function() {
  4408. self.select(i);
  4409. });
  4410. K(li.data('tab').panel).hide();
  4411. }
  4412. });
  4413. if (afterSelect) {
  4414. afterSelect.call(self, index);
  4415. }
  4416. };
  4417. self.remove = function() {
  4418. _each(liList, function() {
  4419. this.remove();
  4420. });
  4421. ul.remove();
  4422. remove.call(self);
  4423. };
  4424. return self;
  4425. }
  4426. K.tabs = _tabs;
  4427. function _loadScript(url, fn) {
  4428. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4429. script = document.createElement('script');
  4430. head.appendChild(script);
  4431. script.src = url;
  4432. script.charset = 'utf-8';
  4433. script.onload = script.onreadystatechange = function() {
  4434. if (!this.readyState || this.readyState === 'loaded') {
  4435. if (fn) {
  4436. fn();
  4437. }
  4438. script.onload = script.onreadystatechange = null;
  4439. head.removeChild(script);
  4440. }
  4441. };
  4442. }
  4443. function _chopQuery(url) {
  4444. var index = url.indexOf('?');
  4445. return index > 0 ? url.substr(0, index) : url;
  4446. }
  4447. function _loadStyle(url) {
  4448. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4449. link = document.createElement('link'),
  4450. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4451. var links = K('link[rel="stylesheet"]', head);
  4452. for (var i = 0, len = links.length; i < len; i++) {
  4453. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4454. return;
  4455. }
  4456. }
  4457. head.appendChild(link);
  4458. link.href = url;
  4459. link.rel = 'stylesheet';
  4460. }
  4461. function _ajax(url, fn, method, param, dataType) {
  4462. method = method || 'GET';
  4463. dataType = dataType || 'json';
  4464. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4465. xhr.open(method, url, true);
  4466. xhr.onreadystatechange = function () {
  4467. if (xhr.readyState == 4 && xhr.status == 200) {
  4468. if (fn) {
  4469. var data = _trim(xhr.responseText);
  4470. if (dataType == 'json') {
  4471. data = _json(data);
  4472. }
  4473. fn(data);
  4474. }
  4475. }
  4476. };
  4477. if (method == 'POST') {
  4478. var params = [];
  4479. _each(param, function(key, val) {
  4480. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4481. });
  4482. try {
  4483. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4484. } catch (e) {}
  4485. xhr.send(params.join('&'));
  4486. } else {
  4487. xhr.send(null);
  4488. }
  4489. }
  4490. K.loadScript = _loadScript;
  4491. K.loadStyle = _loadStyle;
  4492. K.ajax = _ajax;
  4493. var _plugins = {};
  4494. function _plugin(name, fn) {
  4495. if (name === undefined) {
  4496. return _plugins;
  4497. }
  4498. if (!fn) {
  4499. return _plugins[name];
  4500. }
  4501. _plugins[name] = fn;
  4502. }
  4503. var _language = {};
  4504. function _parseLangKey(key) {
  4505. var match, ns = 'core';
  4506. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4507. ns = match[1];
  4508. key = match[2];
  4509. }
  4510. return { ns : ns, key : key };
  4511. }
  4512. function _lang(mixed, langType) {
  4513. langType = langType === undefined ? K.options.langType : langType;
  4514. if (typeof mixed === 'string') {
  4515. if (!_language[langType]) {
  4516. return 'no language';
  4517. }
  4518. var pos = mixed.length - 1;
  4519. if (mixed.substr(pos) === '.') {
  4520. return _language[langType][mixed.substr(0, pos)];
  4521. }
  4522. var obj = _parseLangKey(mixed);
  4523. return _language[langType][obj.ns][obj.key];
  4524. }
  4525. _each(mixed, function(key, val) {
  4526. var obj = _parseLangKey(key);
  4527. if (!_language[langType]) {
  4528. _language[langType] = {};
  4529. }
  4530. if (!_language[langType][obj.ns]) {
  4531. _language[langType][obj.ns] = {};
  4532. }
  4533. _language[langType][obj.ns][obj.key] = val;
  4534. });
  4535. }
  4536. function _getImageFromRange(range, fn) {
  4537. if (range.collapsed) {
  4538. return;
  4539. }
  4540. range = range.cloneRange().up();
  4541. var sc = range.startContainer, so = range.startOffset;
  4542. if (!_WEBKIT && !range.isControl()) {
  4543. return;
  4544. }
  4545. var img = K(sc.childNodes[so]);
  4546. if (!img || img.name != 'img') {
  4547. return;
  4548. }
  4549. if (fn(img)) {
  4550. return img;
  4551. }
  4552. }
  4553. function _bindContextmenuEvent() {
  4554. var self = this, doc = self.edit.doc;
  4555. K(doc).contextmenu(function(e) {
  4556. if (self.menu) {
  4557. self.hideMenu();
  4558. }
  4559. if (!self.useContextmenu) {
  4560. e.preventDefault();
  4561. return;
  4562. }
  4563. if (self._contextmenus.length === 0) {
  4564. return;
  4565. }
  4566. var maxWidth = 0, items = [];
  4567. _each(self._contextmenus, function() {
  4568. if (this.title == '-') {
  4569. items.push(this);
  4570. return;
  4571. }
  4572. if (this.cond && this.cond()) {
  4573. items.push(this);
  4574. if (this.width && this.width > maxWidth) {
  4575. maxWidth = this.width;
  4576. }
  4577. }
  4578. });
  4579. while (items.length > 0 && items[0].title == '-') {
  4580. items.shift();
  4581. }
  4582. while (items.length > 0 && items[items.length - 1].title == '-') {
  4583. items.pop();
  4584. }
  4585. var prevItem = null;
  4586. _each(items, function(i) {
  4587. if (this.title == '-' && prevItem.title == '-') {
  4588. delete items[i];
  4589. }
  4590. prevItem = this;
  4591. });
  4592. if (items.length > 0) {
  4593. e.preventDefault();
  4594. var pos = K(self.edit.iframe).pos(),
  4595. menu = _menu({
  4596. x : pos.x + e.clientX,
  4597. y : pos.y + e.clientY,
  4598. width : maxWidth,
  4599. css : { visibility: 'hidden' },
  4600. shadowMode : self.shadowMode
  4601. });
  4602. _each(items, function() {
  4603. if (this.title) {
  4604. menu.addItem(this);
  4605. }
  4606. });
  4607. var docEl = _docElement(menu.doc),
  4608. menuHeight = menu.div.height();
  4609. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4610. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4611. }
  4612. menu.div.css('visibility', 'visible');
  4613. self.menu = menu;
  4614. }
  4615. });
  4616. }
  4617. function _bindNewlineEvent() {
  4618. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4619. if (_IE && newlineTag !== 'br') {
  4620. return;
  4621. }
  4622. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4623. return;
  4624. }
  4625. if (_OPERA && _V < 9) {
  4626. return;
  4627. }
  4628. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4629. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4630. function getAncestorTagName(range) {
  4631. var ancestor = K(range.commonAncestor());
  4632. while (ancestor) {
  4633. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4634. break;
  4635. }
  4636. ancestor = ancestor.parent();
  4637. }
  4638. return ancestor.name;
  4639. }
  4640. K(doc).keydown(function(e) {
  4641. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4642. return;
  4643. }
  4644. self.cmd.selection();
  4645. var tagName = getAncestorTagName(self.cmd.range);
  4646. if (tagName == 'marquee' || tagName == 'select') {
  4647. return;
  4648. }
  4649. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4650. e.preventDefault();
  4651. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4652. return;
  4653. }
  4654. if (!pSkipTagMap[tagName]) {
  4655. _nativeCommand(doc, 'formatblock', '<p>');
  4656. }
  4657. });
  4658. K(doc).keyup(function(e) {
  4659. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4660. return;
  4661. }
  4662. if (newlineTag == 'br') {
  4663. return;
  4664. }
  4665. if (_GECKO) {
  4666. var root = self.cmd.commonAncestor('p');
  4667. var a = self.cmd.commonAncestor('a');
  4668. if (a && a.text() == '') {
  4669. a.remove(true);
  4670. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4671. self.cmd.select();
  4672. }
  4673. return;
  4674. }
  4675. self.cmd.selection();
  4676. var tagName = getAncestorTagName(self.cmd.range);
  4677. if (tagName == 'marquee' || tagName == 'select') {
  4678. return;
  4679. }
  4680. if (!pSkipTagMap[tagName]) {
  4681. _nativeCommand(doc, 'formatblock', '<p>');
  4682. }
  4683. });
  4684. }
  4685. function _bindTabEvent() {
  4686. var self = this, doc = self.edit.doc;
  4687. K(doc).keydown(function(e) {
  4688. if (e.which == 9) {
  4689. e.preventDefault();
  4690. if (self.afterTab) {
  4691. self.afterTab.call(self, e);
  4692. return;
  4693. }
  4694. var cmd = self.cmd, range = cmd.range;
  4695. range.shrink();
  4696. if (range.collapsed && range.startContainer.nodeType == 1) {
  4697. range.insertNode(K('@&nbsp;', doc)[0]);
  4698. cmd.select();
  4699. }
  4700. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4701. }
  4702. });
  4703. }
  4704. function _bindFocusEvent() {
  4705. var self = this;
  4706. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4707. if (self.afterFocus) {
  4708. self.afterFocus.call(self, e);
  4709. }
  4710. }).blur(function(e) {
  4711. if (self.afterBlur) {
  4712. self.afterBlur.call(self, e);
  4713. }
  4714. });
  4715. }
  4716. function _removeBookmarkTag(html) {
  4717. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4718. }
  4719. function _removeTempTag(html) {
  4720. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4721. }
  4722. function _addBookmarkToStack(stack, bookmark) {
  4723. if (stack.length === 0) {
  4724. stack.push(bookmark);
  4725. return;
  4726. }
  4727. var prev = stack[stack.length - 1];
  4728. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4729. stack.push(bookmark);
  4730. }
  4731. }
  4732. function _undoToRedo(fromStack, toStack) {
  4733. var self = this, edit = self.edit,
  4734. body = edit.doc.body,
  4735. range, bookmark;
  4736. if (fromStack.length === 0) {
  4737. return self;
  4738. }
  4739. if (edit.designMode) {
  4740. range = self.cmd.range;
  4741. bookmark = range.createBookmark(true);
  4742. bookmark.html = body.innerHTML;
  4743. } else {
  4744. bookmark = {
  4745. html : body.innerHTML
  4746. };
  4747. }
  4748. _addBookmarkToStack(toStack, bookmark);
  4749. var prev = fromStack.pop();
  4750. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4751. prev = fromStack.pop();
  4752. }
  4753. if (edit.designMode) {
  4754. edit.html(prev.html);
  4755. if (prev.start) {
  4756. range.moveToBookmark(prev);
  4757. self.select();
  4758. }
  4759. } else {
  4760. K(body).html(_removeBookmarkTag(prev.html));
  4761. }
  4762. return self;
  4763. }
  4764. function KEditor(options) {
  4765. var self = this;
  4766. self.options = {};
  4767. function setOption(key, val) {
  4768. if (KEditor.prototype[key] === undefined) {
  4769. self[key] = val;
  4770. }
  4771. self.options[key] = val;
  4772. }
  4773. _each(options, function(key, val) {
  4774. setOption(key, options[key]);
  4775. });
  4776. _each(K.options, function(key, val) {
  4777. if (self[key] === undefined) {
  4778. setOption(key, val);
  4779. }
  4780. });
  4781. var se = K(self.srcElement || '<textarea/>');
  4782. if (!self.width) {
  4783. self.width = se[0].style.width || se.width();
  4784. }
  4785. if (!self.height) {
  4786. self.height = se[0].style.height || se.height();
  4787. }
  4788. setOption('width', _undef(self.width, self.minWidth));
  4789. setOption('height', _undef(self.height, self.minHeight));
  4790. setOption('width', _addUnit(self.width));
  4791. setOption('height', _addUnit(self.height));
  4792. if (_MOBILE && (!_IOS || _V < 534)) {
  4793. self.designMode = false;
  4794. }
  4795. self.srcElement = se;
  4796. self.initContent = '';
  4797. self.plugin = {};
  4798. self.isCreated = false;
  4799. self._handlers = {};
  4800. self._contextmenus = [];
  4801. self._undoStack = [];
  4802. self._redoStack = [];
  4803. self._firstAddBookmark = true;
  4804. self.menu = self.contextmenu = null;
  4805. self.dialogs = [];
  4806. }
  4807. KEditor.prototype = {
  4808. lang : function(mixed) {
  4809. return _lang(mixed, this.langType);
  4810. },
  4811. loadPlugin : function(name, fn) {
  4812. var self = this;
  4813. var _pluginStatus = this._pluginStatus;
  4814. if (!_pluginStatus) {
  4815. _pluginStatus = this._pluginStatus = {};
  4816. }
  4817. if (_plugins[name]) {
  4818. if (!_isFunction(_plugins[name])) {
  4819. setTimeout(function() {
  4820. self.loadPlugin(name, fn);
  4821. }, 100);
  4822. return self;
  4823. }
  4824. if(!_pluginStatus[name]) {
  4825. _plugins[name].call(self, KindEditor);
  4826. _pluginStatus[name] = 'inited';
  4827. }
  4828. if (fn) {
  4829. fn.call(self);
  4830. }
  4831. return self;
  4832. }
  4833. _plugins[name] = 'loading';
  4834. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4835. setTimeout(function() {
  4836. if (_plugins[name]) {
  4837. self.loadPlugin(name, fn);
  4838. }
  4839. }, 0);
  4840. });
  4841. return self;
  4842. },
  4843. handler : function(key, fn) {
  4844. var self = this;
  4845. if (!self._handlers[key]) {
  4846. self._handlers[key] = [];
  4847. }
  4848. if (_isFunction(fn)) {
  4849. self._handlers[key].push(fn);
  4850. return self;
  4851. }
  4852. _each(self._handlers[key], function() {
  4853. fn = this.call(self, fn);
  4854. });
  4855. return fn;
  4856. },
  4857. clickToolbar : function(name, fn) {
  4858. var self = this, key = 'clickToolbar' + name;
  4859. if (fn === undefined) {
  4860. if (self._handlers[key]) {
  4861. return self.handler(key);
  4862. }
  4863. self.loadPlugin(name, function() {
  4864. self.handler(key);
  4865. });
  4866. return self;
  4867. }
  4868. return self.handler(key, fn);
  4869. },
  4870. updateState : function() {
  4871. var self = this;
  4872. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4873. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4874. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4875. });
  4876. return self;
  4877. },
  4878. addContextmenu : function(item) {
  4879. this._contextmenus.push(item);
  4880. return this;
  4881. },
  4882. afterCreate : function(fn) {
  4883. return this.handler('afterCreate', fn);
  4884. },
  4885. beforeRemove : function(fn) {
  4886. return this.handler('beforeRemove', fn);
  4887. },
  4888. beforeGetHtml : function(fn) {
  4889. return this.handler('beforeGetHtml', fn);
  4890. },
  4891. beforeSetHtml : function(fn) {
  4892. return this.handler('beforeSetHtml', fn);
  4893. },
  4894. afterSetHtml : function(fn) {
  4895. return this.handler('afterSetHtml', fn);
  4896. },
  4897. create : function() {
  4898. var self = this, fullscreenMode = self.fullscreenMode;
  4899. if (self.isCreated) {
  4900. return self;
  4901. }
  4902. if (self.srcElement.data('kindeditor')) {
  4903. return self;
  4904. }
  4905. self.srcElement.data('kindeditor', 'true');
  4906. if (fullscreenMode) {
  4907. _docElement().style.overflow = 'hidden';
  4908. } else {
  4909. _docElement().style.overflow = '';
  4910. }
  4911. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4912. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4913. if ((_IE && _V < 8) || _QUIRKS) {
  4914. height = _addUnit(_removeUnit(height) + 2);
  4915. }
  4916. var container = self.container = K(self.layout);
  4917. if (fullscreenMode) {
  4918. K(document.body).append(container);
  4919. } else {
  4920. self.srcElement.before(container);
  4921. }
  4922. var toolbarDiv = K('.toolbar', container),
  4923. editDiv = K('.edit', container),
  4924. statusbar = self.statusbar = K('.statusbar', container);
  4925. container.removeClass('container')
  4926. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4927. if (fullscreenMode) {
  4928. container.css({
  4929. position : 'absolute',
  4930. left : 0,
  4931. top : 0,
  4932. 'z-index' : 811211
  4933. });
  4934. if (!_GECKO) {
  4935. self._scrollPos = _getScrollPos();
  4936. }
  4937. window.scrollTo(0, 0);
  4938. K(document.body).css({
  4939. 'height' : '1px',
  4940. 'overflow' : 'hidden'
  4941. });
  4942. K(document.body.parentNode).css('overflow', 'hidden');
  4943. self._fullscreenExecuted = true;
  4944. } else {
  4945. if (self._fullscreenExecuted) {
  4946. K(document.body).css({
  4947. 'height' : '',
  4948. 'overflow' : ''
  4949. });
  4950. K(document.body.parentNode).css('overflow', '');
  4951. }
  4952. if (self._scrollPos) {
  4953. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4954. }
  4955. }
  4956. var htmlList = [];
  4957. K.each(self.items, function(i, name) {
  4958. if (name == '|') {
  4959. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4960. } else if (name == '/') {
  4961. htmlList.push('<div class="ke-hr"></div>');
  4962. } else {
  4963. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4964. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4965. }
  4966. });
  4967. var toolbar = self.toolbar = _toolbar({
  4968. src : toolbarDiv,
  4969. html : htmlList.join(''),
  4970. noDisableItems : self.noDisableItems,
  4971. click : function(e, name) {
  4972. e.stop();
  4973. if (self.menu) {
  4974. var menuName = self.menu.name;
  4975. self.hideMenu();
  4976. if (menuName === name) {
  4977. return;
  4978. }
  4979. }
  4980. self.clickToolbar(name);
  4981. }
  4982. });
  4983. var editHeight = _removeUnit(height) - toolbar.div.height();
  4984. var edit = self.edit = _edit({
  4985. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  4986. src : editDiv,
  4987. srcElement : self.srcElement,
  4988. designMode : self.designMode,
  4989. themesPath : self.themesPath,
  4990. bodyClass : self.bodyClass,
  4991. cssPath : self.cssPath,
  4992. cssData : self.cssData,
  4993. beforeGetHtml : function(html) {
  4994. html = self.beforeGetHtml(html);
  4995. html = _removeBookmarkTag(_removeTempTag(html));
  4996. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  4997. },
  4998. beforeSetHtml : function(html) {
  4999. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5000. return self.beforeSetHtml(html);
  5001. },
  5002. afterSetHtml : function() {
  5003. self.edit = edit = this;
  5004. self.afterSetHtml();
  5005. },
  5006. afterCreate : function() {
  5007. self.edit = edit = this;
  5008. self.cmd = edit.cmd;
  5009. self._docMousedownFn = function(e) {
  5010. if (self.menu) {
  5011. self.hideMenu();
  5012. }
  5013. };
  5014. K(edit.doc, document).mousedown(self._docMousedownFn);
  5015. _bindContextmenuEvent.call(self);
  5016. _bindNewlineEvent.call(self);
  5017. _bindTabEvent.call(self);
  5018. _bindFocusEvent.call(self);
  5019. edit.afterChange(function(e) {
  5020. if (!edit.designMode) {
  5021. return;
  5022. }
  5023. self.updateState();
  5024. self.addBookmark();
  5025. if (self.options.afterChange) {
  5026. self.options.afterChange.call(self);
  5027. }
  5028. });
  5029. edit.textarea.keyup(function(e) {
  5030. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5031. if (self.options.afterChange) {
  5032. self.options.afterChange.call(self);
  5033. }
  5034. }
  5035. });
  5036. if (self.readonlyMode) {
  5037. self.readonly();
  5038. }
  5039. self.isCreated = true;
  5040. if (self.initContent === '') {
  5041. self.initContent = self.html();
  5042. }
  5043. if (self._undoStack.length > 0) {
  5044. var prev = self._undoStack.pop();
  5045. if (prev.start) {
  5046. self.html(prev.html);
  5047. edit.cmd.range.moveToBookmark(prev);
  5048. self.select();
  5049. }
  5050. }
  5051. self.afterCreate();
  5052. if (self.options.afterCreate) {
  5053. self.options.afterCreate.call(self);
  5054. }
  5055. }
  5056. });
  5057. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5058. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5059. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5060. if (self._fullscreenResizeHandler) {
  5061. K(window).unbind('resize', self._fullscreenResizeHandler);
  5062. self._fullscreenResizeHandler = null;
  5063. }
  5064. function initResize() {
  5065. if (statusbar.height() === 0) {
  5066. setTimeout(initResize, 100);
  5067. return;
  5068. }
  5069. self.resize(width, height, false);
  5070. }
  5071. initResize();
  5072. if (fullscreenMode) {
  5073. self._fullscreenResizeHandler = function(e) {
  5074. if (self.isCreated) {
  5075. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5076. }
  5077. };
  5078. K(window).bind('resize', self._fullscreenResizeHandler);
  5079. toolbar.select('fullscreen');
  5080. statusbar.first().css('visibility', 'hidden');
  5081. statusbar.last().css('visibility', 'hidden');
  5082. } else {
  5083. if (_GECKO) {
  5084. K(window).bind('scroll', function(e) {
  5085. self._scrollPos = _getScrollPos();
  5086. });
  5087. }
  5088. if (self.resizeType > 0) {
  5089. _drag({
  5090. moveEl : container,
  5091. clickEl : statusbar,
  5092. moveFn : function(x, y, width, height, diffX, diffY) {
  5093. height += diffY;
  5094. self.resize(null, height);
  5095. }
  5096. });
  5097. } else {
  5098. statusbar.first().css('visibility', 'hidden');
  5099. }
  5100. if (self.resizeType === 2) {
  5101. _drag({
  5102. moveEl : container,
  5103. clickEl : statusbar.last(),
  5104. moveFn : function(x, y, width, height, diffX, diffY) {
  5105. width += diffX;
  5106. height += diffY;
  5107. self.resize(width, height);
  5108. }
  5109. });
  5110. } else {
  5111. statusbar.last().css('visibility', 'hidden');
  5112. }
  5113. }
  5114. return self;
  5115. },
  5116. remove : function() {
  5117. var self = this;
  5118. if (!self.isCreated) {
  5119. return self;
  5120. }
  5121. self.beforeRemove();
  5122. self.srcElement.data('kindeditor', '');
  5123. if (self.menu) {
  5124. self.hideMenu();
  5125. }
  5126. _each(self.dialogs, function() {
  5127. self.hideDialog();
  5128. });
  5129. K(document).unbind('mousedown', self._docMousedownFn);
  5130. self.toolbar.remove();
  5131. self.edit.remove();
  5132. self.statusbar.last().unbind();
  5133. self.statusbar.unbind();
  5134. self.container.remove();
  5135. self.container = self.toolbar = self.edit = self.menu = null;
  5136. self.dialogs = [];
  5137. self.isCreated = false;
  5138. return self;
  5139. },
  5140. resize : function(width, height, updateProp) {
  5141. var self = this;
  5142. updateProp = _undef(updateProp, true);
  5143. if (width) {
  5144. if (!/%/.test(width)) {
  5145. width = _removeUnit(width);
  5146. width = width < self.minWidth ? self.minWidth : width;
  5147. }
  5148. self.container.css('width', _addUnit(width));
  5149. if (updateProp) {
  5150. self.width = _addUnit(width);
  5151. }
  5152. }
  5153. if (height) {
  5154. height = _removeUnit(height);
  5155. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5156. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5157. self.edit.setHeight(editHeight);
  5158. if (updateProp) {
  5159. self.height = _addUnit(height);
  5160. }
  5161. }
  5162. return self;
  5163. },
  5164. select : function() {
  5165. this.isCreated && this.cmd.select();
  5166. return this;
  5167. },
  5168. html : function(val) {
  5169. var self = this;
  5170. if (val === undefined) {
  5171. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5172. }
  5173. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5174. if (self.isCreated) {
  5175. self.cmd.selection();
  5176. }
  5177. return self;
  5178. },
  5179. fullHtml : function() {
  5180. return this.isCreated ? this.edit.html(undefined, true) : '';
  5181. },
  5182. text : function(val) {
  5183. var self = this;
  5184. if (val === undefined) {
  5185. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5186. } else {
  5187. return self.html(_escape(val));
  5188. }
  5189. },
  5190. isEmpty : function() {
  5191. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5192. },
  5193. isDirty : function() {
  5194. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5195. },
  5196. selectedHtml : function() {
  5197. var val = this.isCreated ? this.cmd.range.html() : '';
  5198. val = _removeBookmarkTag(_removeTempTag(val));
  5199. return val;
  5200. },
  5201. count : function(mode) {
  5202. var self = this;
  5203. mode = (mode || 'html').toLowerCase();
  5204. if (mode === 'html') {
  5205. return self.html().length;
  5206. }
  5207. if (mode === 'text') {
  5208. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5209. }
  5210. return 0;
  5211. },
  5212. exec : function(key) {
  5213. key = key.toLowerCase();
  5214. var self = this, cmd = self.cmd,
  5215. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5216. if (changeFlag) {
  5217. self.addBookmark(false);
  5218. }
  5219. cmd[key].apply(cmd, _toArray(arguments, 1));
  5220. if (changeFlag) {
  5221. self.updateState();
  5222. self.addBookmark(false);
  5223. if (self.options.afterChange) {
  5224. self.options.afterChange.call(self);
  5225. }
  5226. }
  5227. return self;
  5228. },
  5229. insertHtml : function(val, quickMode) {
  5230. if (!this.isCreated) {
  5231. return this;
  5232. }
  5233. val = this.beforeSetHtml(val);
  5234. this.exec('inserthtml', val, quickMode);
  5235. return this;
  5236. },
  5237. appendHtml : function(val) {
  5238. this.html(this.html() + val);
  5239. if (this.isCreated) {
  5240. var cmd = this.cmd;
  5241. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5242. cmd.select();
  5243. }
  5244. return this;
  5245. },
  5246. sync : function() {
  5247. _elementVal(this.srcElement, this.html());
  5248. return this;
  5249. },
  5250. focus : function() {
  5251. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5252. return this;
  5253. },
  5254. blur : function() {
  5255. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5256. return this;
  5257. },
  5258. addBookmark : function(checkSize) {
  5259. checkSize = _undef(checkSize, true);
  5260. var self = this, edit = self.edit,
  5261. body = edit.doc.body,
  5262. html = _removeTempTag(body.innerHTML), bookmark;
  5263. if (checkSize && self._undoStack.length > 0) {
  5264. var prev = self._undoStack[self._undoStack.length - 1];
  5265. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5266. return self;
  5267. }
  5268. }
  5269. if (edit.designMode && !self._firstAddBookmark) {
  5270. var range = self.cmd.range;
  5271. bookmark = range.createBookmark(true);
  5272. bookmark.html = _removeTempTag(body.innerHTML);
  5273. range.moveToBookmark(bookmark);
  5274. } else {
  5275. bookmark = {
  5276. html : html
  5277. };
  5278. }
  5279. self._firstAddBookmark = false;
  5280. _addBookmarkToStack(self._undoStack, bookmark);
  5281. return self;
  5282. },
  5283. undo : function() {
  5284. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5285. },
  5286. redo : function() {
  5287. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5288. },
  5289. fullscreen : function(bool) {
  5290. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5291. this.addBookmark(false);
  5292. return this.remove().create();
  5293. },
  5294. readonly : function(isReadonly) {
  5295. isReadonly = _undef(isReadonly, true);
  5296. var self = this, edit = self.edit, doc = edit.doc;
  5297. if (self.designMode) {
  5298. self.toolbar.disableAll(isReadonly, []);
  5299. } else {
  5300. _each(self.noDisableItems, function() {
  5301. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5302. });
  5303. }
  5304. if (_IE) {
  5305. doc.body.contentEditable = !isReadonly;
  5306. } else {
  5307. doc.designMode = isReadonly ? 'off' : 'on';
  5308. }
  5309. edit.textarea[0].disabled = isReadonly;
  5310. },
  5311. createMenu : function(options) {
  5312. var self = this,
  5313. name = options.name,
  5314. knode = self.toolbar.get(name),
  5315. pos = knode.pos();
  5316. options.x = pos.x;
  5317. options.y = pos.y + knode.height();
  5318. options.z = self.options.zIndex;
  5319. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5320. if (options.selectedColor !== undefined) {
  5321. options.cls = 'ke-colorpicker-' + self.themeType;
  5322. options.noColor = self.lang('noColor');
  5323. self.menu = _colorpicker(options);
  5324. } else {
  5325. options.cls = 'ke-menu-' + self.themeType;
  5326. options.centerLineMode = false;
  5327. self.menu = _menu(options);
  5328. }
  5329. return self.menu;
  5330. },
  5331. hideMenu : function() {
  5332. this.menu.remove();
  5333. this.menu = null;
  5334. return this;
  5335. },
  5336. hideContextmenu : function() {
  5337. this.contextmenu.remove();
  5338. this.contextmenu = null;
  5339. return this;
  5340. },
  5341. createDialog : function(options) {
  5342. var self = this, name = options.name;
  5343. options.z = self.options.zIndex;
  5344. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5345. options.closeBtn = _undef(options.closeBtn, {
  5346. name : self.lang('close'),
  5347. click : function(e) {
  5348. self.hideDialog();
  5349. if (_IE && self.cmd) {
  5350. self.cmd.select();
  5351. }
  5352. }
  5353. });
  5354. options.noBtn = _undef(options.noBtn, {
  5355. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5356. click : function(e) {
  5357. self.hideDialog();
  5358. if (_IE && self.cmd) {
  5359. self.cmd.select();
  5360. }
  5361. }
  5362. });
  5363. if (self.dialogAlignType != 'page') {
  5364. options.alignEl = self.container;
  5365. }
  5366. options.cls = 'ke-dialog-' + self.themeType;
  5367. if (self.dialogs.length > 0) {
  5368. var firstDialog = self.dialogs[0],
  5369. parentDialog = self.dialogs[self.dialogs.length - 1];
  5370. firstDialog.setMaskIndex(parentDialog.z + 2);
  5371. options.z = parentDialog.z + 3;
  5372. options.showMask = false;
  5373. }
  5374. var dialog = _dialog(options);
  5375. self.dialogs.push(dialog);
  5376. return dialog;
  5377. },
  5378. hideDialog : function() {
  5379. var self = this;
  5380. if (self.dialogs.length > 0) {
  5381. self.dialogs.pop().remove();
  5382. }
  5383. if (self.dialogs.length > 0) {
  5384. var firstDialog = self.dialogs[0],
  5385. parentDialog = self.dialogs[self.dialogs.length - 1];
  5386. firstDialog.setMaskIndex(parentDialog.z - 1);
  5387. }
  5388. return self;
  5389. },
  5390. errorDialog : function(html) {
  5391. var self = this;
  5392. var dialog = self.createDialog({
  5393. width : 750,
  5394. title : self.lang('uploadError'),
  5395. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5396. });
  5397. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5398. doc.open();
  5399. doc.write(html);
  5400. doc.close();
  5401. K(doc.body).css('background-color', '#FFF');
  5402. iframe[0].contentWindow.focus();
  5403. return self;
  5404. }
  5405. };
  5406. function _editor(options) {
  5407. return new KEditor(options);
  5408. }
  5409. var _instances = [];
  5410. function _create(expr, options) {
  5411. options = options || {};
  5412. options.basePath = _undef(options.basePath, K.basePath);
  5413. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5414. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5415. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5416. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5417. var themeType = _undef(options.themeType, K.options.themeType);
  5418. _loadStyle(options.themesPath + 'default/default.css');
  5419. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5420. }
  5421. function create(editor) {
  5422. _each(_plugins, function(name, fn) {
  5423. if (_isFunction(fn)) {
  5424. fn.call(editor, KindEditor);
  5425. if (!editor._pluginStatus) {
  5426. editor._pluginStatus = {};
  5427. }
  5428. editor._pluginStatus[name] = 'inited';
  5429. }
  5430. });
  5431. return editor.create();
  5432. }
  5433. var knode = K(expr);
  5434. if (!knode || knode.length === 0) {
  5435. return;
  5436. }
  5437. if (knode.length > 1) {
  5438. knode.each(function() {
  5439. _create(this, options);
  5440. });
  5441. return _instances[0];
  5442. }
  5443. options.srcElement = knode[0];
  5444. var editor = new KEditor(options);
  5445. _instances.push(editor);
  5446. if (_language[editor.langType]) {
  5447. return create(editor);
  5448. }
  5449. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5450. create(editor);
  5451. });
  5452. return editor;
  5453. }
  5454. function _eachEditor(expr, fn) {
  5455. K(expr).each(function(i, el) {
  5456. K.each(_instances, function(j, editor) {
  5457. if (editor && editor.srcElement[0] == el) {
  5458. fn.call(editor, j);
  5459. return false;
  5460. }
  5461. });
  5462. });
  5463. }
  5464. K.remove = function(expr) {
  5465. _eachEditor(expr, function(i) {
  5466. this.remove();
  5467. _instances.splice(i, 1);
  5468. });
  5469. };
  5470. K.sync = function(expr) {
  5471. _eachEditor(expr, function() {
  5472. this.sync();
  5473. });
  5474. };
  5475. K.html = function(expr, val) {
  5476. _eachEditor(expr, function() {
  5477. this.html(val);
  5478. });
  5479. };
  5480. K.insertHtml = function(expr, val) {
  5481. _eachEditor(expr, function() {
  5482. this.insertHtml(val);
  5483. });
  5484. };
  5485. K.appendHtml = function(expr, val) {
  5486. _eachEditor(expr, function() {
  5487. this.appendHtml(val);
  5488. });
  5489. };
  5490. if (_IE && _V < 7) {
  5491. _nativeCommand(document, 'BackgroundImageCache', true);
  5492. }
  5493. K.EditorClass = KEditor;
  5494. K.editor = _editor;
  5495. K.create = _create;
  5496. K.instances = _instances;
  5497. K.plugin = _plugin;
  5498. K.lang = _lang;
  5499. _plugin('core', function(K) {
  5500. var self = this,
  5501. shortcutKeys = {
  5502. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5503. };
  5504. self.afterSetHtml(function() {
  5505. if (self.options.afterChange) {
  5506. self.options.afterChange.call(self);
  5507. }
  5508. });
  5509. self.afterCreate(function() {
  5510. if (self.syncType != 'form') {
  5511. return;
  5512. }
  5513. var el = K(self.srcElement), hasForm = false;
  5514. while ((el = el.parent())) {
  5515. if (el.name == 'form') {
  5516. hasForm = true;
  5517. break;
  5518. }
  5519. }
  5520. if (hasForm) {
  5521. el.bind('submit', function(e) {
  5522. self.sync();
  5523. K(window).bind('unload', function() {
  5524. self.edit.textarea.remove();
  5525. });
  5526. });
  5527. var resetBtn = K('[type="reset"]', el);
  5528. resetBtn.click(function() {
  5529. self.html(self.initContent);
  5530. self.cmd.selection();
  5531. });
  5532. self.beforeRemove(function() {
  5533. el.unbind();
  5534. resetBtn.unbind();
  5535. });
  5536. }
  5537. });
  5538. self.clickToolbar('source', function() {
  5539. if (self.edit.designMode) {
  5540. self.toolbar.disableAll(true);
  5541. self.edit.design(false);
  5542. self.toolbar.select('source');
  5543. } else {
  5544. self.toolbar.disableAll(false);
  5545. self.edit.design(true);
  5546. self.toolbar.unselect('source');
  5547. if (_GECKO) {
  5548. setTimeout(function() {
  5549. self.cmd.selection();
  5550. }, 0);
  5551. } else {
  5552. self.cmd.selection();
  5553. }
  5554. }
  5555. self.designMode = self.edit.designMode;
  5556. });
  5557. self.afterCreate(function() {
  5558. if (!self.designMode) {
  5559. self.toolbar.disableAll(true).select('source');
  5560. }
  5561. });
  5562. self.clickToolbar('fullscreen', function() {
  5563. self.fullscreen();
  5564. });
  5565. if (self.fullscreenShortcut) {
  5566. var loaded = false;
  5567. self.afterCreate(function() {
  5568. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5569. if (e.which == 27) {
  5570. setTimeout(function() {
  5571. self.fullscreen();
  5572. }, 0);
  5573. }
  5574. });
  5575. if (loaded) {
  5576. if (_IE && !self.designMode) {
  5577. return;
  5578. }
  5579. self.focus();
  5580. }
  5581. if (!loaded) {
  5582. loaded = true;
  5583. }
  5584. });
  5585. }
  5586. _each('undo,redo'.split(','), function(i, name) {
  5587. if (shortcutKeys[name]) {
  5588. self.afterCreate(function() {
  5589. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5590. self.clickToolbar(name);
  5591. });
  5592. });
  5593. }
  5594. self.clickToolbar(name, function() {
  5595. self[name]();
  5596. });
  5597. });
  5598. self.clickToolbar('formatblock', function() {
  5599. var blocks = self.lang('formatblock.formatBlock'),
  5600. heights = {
  5601. h1 : 28,
  5602. h2 : 24,
  5603. h3 : 18,
  5604. H4 : 14,
  5605. p : 12
  5606. },
  5607. curVal = self.cmd.val('formatblock'),
  5608. menu = self.createMenu({
  5609. name : 'formatblock',
  5610. width : self.langType == 'en' ? 200 : 150
  5611. });
  5612. _each(blocks, function(key, val) {
  5613. var style = 'font-size:' + heights[key] + 'px;';
  5614. if (key.charAt(0) === 'h') {
  5615. style += 'font-weight:bold;';
  5616. }
  5617. menu.addItem({
  5618. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5619. height : heights[key] + 12,
  5620. checked : (curVal === key || curVal === val),
  5621. click : function() {
  5622. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5623. }
  5624. });
  5625. });
  5626. });
  5627. self.clickToolbar('fontname', function() {
  5628. var curVal = self.cmd.val('fontname'),
  5629. menu = self.createMenu({
  5630. name : 'fontname',
  5631. width : 150
  5632. });
  5633. _each(self.lang('fontname.fontName'), function(key, val) {
  5634. menu.addItem({
  5635. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5636. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5637. click : function() {
  5638. self.exec('fontname', key).hideMenu();
  5639. }
  5640. });
  5641. });
  5642. });
  5643. self.clickToolbar('fontsize', function() {
  5644. var curVal = self.cmd.val('fontsize'),
  5645. menu = self.createMenu({
  5646. name : 'fontsize',
  5647. width : 150
  5648. });
  5649. _each(self.fontSizeTable, function(i, val) {
  5650. menu.addItem({
  5651. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5652. height : _removeUnit(val) + 12,
  5653. checked : curVal === val,
  5654. click : function() {
  5655. self.exec('fontsize', val).hideMenu();
  5656. }
  5657. });
  5658. });
  5659. });
  5660. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5661. self.clickToolbar(name, function() {
  5662. self.createMenu({
  5663. name : name,
  5664. selectedColor : self.cmd.val(name) || 'default',
  5665. colors : self.colorTable,
  5666. click : function(color) {
  5667. self.exec(name, color).hideMenu();
  5668. }
  5669. });
  5670. });
  5671. });
  5672. _each(('cut,copy,paste').split(','), function(i, name) {
  5673. self.clickToolbar(name, function() {
  5674. self.focus();
  5675. try {
  5676. self.exec(name, null);
  5677. } catch(e) {
  5678. alert(self.lang(name + 'Error'));
  5679. }
  5680. });
  5681. });
  5682. self.clickToolbar('about', function() {
  5683. var html = '<div style="margin:20px;">' +
  5684. '<div>KindEditor ' + _VERSION + '</div>' +
  5685. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5686. '</div>';
  5687. self.createDialog({
  5688. name : 'about',
  5689. width : 350,
  5690. title : self.lang('about'),
  5691. body : html
  5692. });
  5693. });
  5694. self.plugin.getSelectedLink = function() {
  5695. return self.cmd.commonAncestor('a');
  5696. };
  5697. self.plugin.getSelectedImage = function() {
  5698. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5699. return !/^ke-\w+$/i.test(img[0].className);
  5700. });
  5701. };
  5702. self.plugin.getSelectedFlash = function() {
  5703. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5704. return img[0].className == 'ke-flash';
  5705. });
  5706. };
  5707. self.plugin.getSelectedMedia = function() {
  5708. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5709. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5710. });
  5711. };
  5712. self.plugin.getSelectedAnchor = function() {
  5713. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5714. return img[0].className == 'ke-anchor';
  5715. });
  5716. };
  5717. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5718. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5719. _each('edit,delete'.split(','), function(j, val) {
  5720. self.addContextmenu({
  5721. title : self.lang(val + uName),
  5722. click : function() {
  5723. self.loadPlugin(name, function() {
  5724. self.plugin[name][val]();
  5725. self.hideMenu();
  5726. });
  5727. },
  5728. cond : self.plugin['getSelected' + uName],
  5729. width : 150,
  5730. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5731. });
  5732. });
  5733. self.addContextmenu({ title : '-' });
  5734. });
  5735. self.plugin.getSelectedTable = function() {
  5736. return self.cmd.commonAncestor('table');
  5737. };
  5738. self.plugin.getSelectedRow = function() {
  5739. return self.cmd.commonAncestor('tr');
  5740. };
  5741. self.plugin.getSelectedCell = function() {
  5742. return self.cmd.commonAncestor('td');
  5743. };
  5744. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5745. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5746. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5747. self.addContextmenu({
  5748. title : self.lang('table' + val),
  5749. click : function() {
  5750. self.loadPlugin('table', function() {
  5751. self.plugin.table[val]();
  5752. self.hideMenu();
  5753. });
  5754. },
  5755. cond : cond,
  5756. width : 170,
  5757. iconClass : 'ke-icon-table' + val
  5758. });
  5759. });
  5760. self.addContextmenu({ title : '-' });
  5761. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5762. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5763. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5764. if (shortcutKeys[name]) {
  5765. self.afterCreate(function() {
  5766. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5767. self.cmd.selection();
  5768. self.clickToolbar(name);
  5769. });
  5770. });
  5771. }
  5772. self.clickToolbar(name, function() {
  5773. self.focus().exec(name, null);
  5774. });
  5775. });
  5776. self.afterCreate(function() {
  5777. var doc = self.edit.doc, cmd, bookmark, div,
  5778. cls = '__kindeditor_paste__', pasting = false;
  5779. function movePastedData() {
  5780. cmd.range.moveToBookmark(bookmark);
  5781. cmd.select();
  5782. if (_WEBKIT) {
  5783. K('div.' + cls, div).each(function() {
  5784. K(this).after('<br />').remove(true);
  5785. });
  5786. K('span.Apple-style-span', div).remove(true);
  5787. K('span.Apple-tab-span', div).remove(true);
  5788. K('span[style]', div).each(function() {
  5789. if (K(this).css('white-space') == 'nowrap') {
  5790. K(this).remove(true);
  5791. }
  5792. });
  5793. K('meta', div).remove();
  5794. }
  5795. var html = div[0].innerHTML;
  5796. div.remove();
  5797. if (html === '') {
  5798. return;
  5799. }
  5800. if (_WEBKIT) {
  5801. html = html.replace(/(<br>)\1/ig, '$1');
  5802. }
  5803. if (self.pasteType === 2) {
  5804. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5805. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5806. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5807. } else {
  5808. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5809. html = self.beforeSetHtml(html);
  5810. }
  5811. }
  5812. if (self.pasteType === 1) {
  5813. html = html.replace(/&nbsp;/ig, ' ');
  5814. html = html.replace(/\n\s*\n/g, '\n');
  5815. html = html.replace(/<br[^>]*>/ig, '\n');
  5816. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5817. html = html.replace(/<[^>]+>/g, '');
  5818. html = html.replace(/ {2}/g, ' &nbsp;');
  5819. if (self.newlineTag == 'p') {
  5820. if (/\n/.test(html)) {
  5821. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5822. }
  5823. } else {
  5824. html = html.replace(/\n/g, '<br />$&');
  5825. }
  5826. }
  5827. self.insertHtml(html, true);
  5828. }
  5829. K(doc.body).bind('paste', function(e){
  5830. if (self.pasteType === 0) {
  5831. e.stop();
  5832. return;
  5833. }
  5834. if (pasting) {
  5835. return;
  5836. }
  5837. pasting = true;
  5838. K('div.' + cls, doc).remove();
  5839. cmd = self.cmd.selection();
  5840. bookmark = cmd.range.createBookmark();
  5841. div = K('<div class="' + cls + '"></div>', doc).css({
  5842. position : 'absolute',
  5843. width : '1px',
  5844. height : '1px',
  5845. overflow : 'hidden',
  5846. left : '-1981px',
  5847. top : K(bookmark.start).pos().y + 'px',
  5848. 'white-space' : 'nowrap'
  5849. });
  5850. K(doc.body).append(div);
  5851. if (_IE) {
  5852. var rng = cmd.range.get(true);
  5853. rng.moveToElementText(div[0]);
  5854. rng.select();
  5855. rng.execCommand('paste');
  5856. e.preventDefault();
  5857. } else {
  5858. cmd.range.selectNodeContents(div[0]);
  5859. cmd.select();
  5860. div[0].tabIndex = -1;
  5861. div[0].focus();
  5862. }
  5863. setTimeout(function() {
  5864. movePastedData();
  5865. pasting = false;
  5866. }, 0);
  5867. });
  5868. });
  5869. self.beforeGetHtml(function(html) {
  5870. if (_IE && _V <= 8) {
  5871. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5872. return unescape(tag);
  5873. });
  5874. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5875. if (!/\s+type="[^"]+"/i.test($0)) {
  5876. return $1 + ' type="text"' + $2;
  5877. }
  5878. return $0;
  5879. });
  5880. }
  5881. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5882. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5883. })
  5884. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5885. var imgAttrs = _getAttrList(full);
  5886. var styles = _getCssList(imgAttrs.style || '');
  5887. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5888. var width = _undef(styles.width, '');
  5889. var height = _undef(styles.height, '');
  5890. if (/px/i.test(width)) {
  5891. width = _removeUnit(width);
  5892. }
  5893. if (/px/i.test(height)) {
  5894. height = _removeUnit(height);
  5895. }
  5896. attrs.width = _undef(imgAttrs.width, width);
  5897. attrs.height = _undef(imgAttrs.height, height);
  5898. return _mediaEmbed(attrs);
  5899. })
  5900. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  5901. var imgAttrs = _getAttrList(full);
  5902. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5903. })
  5904. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5905. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5906. })
  5907. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5908. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5909. })
  5910. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  5911. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  5912. return $1 + _unescape(src) + $2;
  5913. });
  5914. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5915. return full;
  5916. })
  5917. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5918. return start + end;
  5919. });
  5920. });
  5921. self.beforeSetHtml(function(html) {
  5922. if (_IE && _V <= 8) {
  5923. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  5924. var attrs = _getAttrList(full);
  5925. var styles = _getCssList(attrs.style || '');
  5926. if (styles.display == 'none') {
  5927. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5928. }
  5929. return full;
  5930. });
  5931. }
  5932. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  5933. var attrs = _getAttrList(full);
  5934. attrs.src = _undef(attrs.src, '');
  5935. attrs.width = _undef(attrs.width, 0);
  5936. attrs.height = _undef(attrs.height, 0);
  5937. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5938. })
  5939. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  5940. var attrs = _getAttrList(full);
  5941. if (attrs.href !== undefined) {
  5942. return full;
  5943. }
  5944. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5945. })
  5946. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  5947. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5948. })
  5949. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  5950. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5951. })
  5952. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  5953. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5954. return full;
  5955. }
  5956. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5957. return full;
  5958. })
  5959. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5960. return start + 'data-ke-' + end;
  5961. })
  5962. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  5963. if (full.indexOf('ke-zeroborder') >= 0) {
  5964. return full;
  5965. }
  5966. return _addClassToTag(full, 'ke-zeroborder');
  5967. });
  5968. });
  5969. });
  5970. })(window);
  5971. /*******************************************************************************
  5972. * KindEditor - WYSIWYG HTML Editor for Internet
  5973. * Copyright (C) 2006-2011 kindsoft.net
  5974. *
  5975. * @author Roddy <luolonghao@gmail.com>
  5976. * @site http://www.kindsoft.net/
  5977. * @licence http://www.kindsoft.net/license.php
  5978. *******************************************************************************/
  5979. KindEditor.lang({
  5980. source : 'HTML代码',
  5981. preview : '预览',
  5982. undo : '后退(Ctrl+Z)',
  5983. redo : '前进(Ctrl+Y)',
  5984. cut : '剪切(Ctrl+X)',
  5985. copy : '复制(Ctrl+C)',
  5986. paste : '粘贴(Ctrl+V)',
  5987. plainpaste : '粘贴为无格式文本',
  5988. wordpaste : '从Word粘贴',
  5989. selectall : '全选(Ctrl+A)',
  5990. justifyleft : '左对齐',
  5991. justifycenter : '居中',
  5992. justifyright : '右对齐',
  5993. justifyfull : '两端对齐',
  5994. insertorderedlist : '编号',
  5995. insertunorderedlist : '项目符号',
  5996. indent : '增加缩进',
  5997. outdent : '减少缩进',
  5998. subscript : '下标',
  5999. superscript : '上标',
  6000. formatblock : '段落',
  6001. fontname : '字体',
  6002. fontsize : '文字大小',
  6003. forecolor : '文字颜色',
  6004. hilitecolor : '文字背景',
  6005. bold : '粗体(Ctrl+B)',
  6006. italic : '斜体(Ctrl+I)',
  6007. underline : '下划线(Ctrl+U)',
  6008. strikethrough : '删除线',
  6009. removeformat : '删除格式',
  6010. image : '图片',
  6011. multiimage : '批量图片上传',
  6012. flash : 'Flash',
  6013. media : '视音频',
  6014. table : '表格',
  6015. tablecell : '单元格',
  6016. hr : '插入横线',
  6017. emoticons : '插入表情',
  6018. link : '超级链接',
  6019. unlink : '取消超级链接',
  6020. fullscreen : '全屏显示',
  6021. about : '关于',
  6022. print : '打印(Ctrl+P)',
  6023. filemanager : '文件空间',
  6024. code : '插入程序代码',
  6025. map : 'Google地图',
  6026. baidumap : '百度地图',
  6027. lineheight : '行距',
  6028. clearhtml : '清理HTML代码',
  6029. pagebreak : '插入分页符',
  6030. quickformat : '一键排版',
  6031. insertfile : '插入文件',
  6032. template : '插入模板',
  6033. anchor : '锚点',
  6034. yes : '确定',
  6035. no : '取消',
  6036. close : '关闭',
  6037. editImage : '图片属性',
  6038. deleteImage : '删除图片',
  6039. editFlash : 'Flash属性',
  6040. deleteFlash : '删除Flash',
  6041. editMedia : '视音频属性',
  6042. deleteMedia : '删除视音频',
  6043. editLink : '超级链接属性',
  6044. deleteLink : '取消超级链接',
  6045. editAnchor : '锚点属性',
  6046. deleteAnchor : '删除锚点',
  6047. tableprop : '表格属性',
  6048. tablecellprop : '单元格属性',
  6049. tableinsert : '插入表格',
  6050. tabledelete : '删除表格',
  6051. tablecolinsertleft : '左侧插入列',
  6052. tablecolinsertright : '右侧插入列',
  6053. tablerowinsertabove : '上方插入行',
  6054. tablerowinsertbelow : '下方插入行',
  6055. tablerowmerge : '向下合并单元格',
  6056. tablecolmerge : '向右合并单元格',
  6057. tablerowsplit : '拆分行',
  6058. tablecolsplit : '拆分列',
  6059. tablecoldelete : '删除列',
  6060. tablerowdelete : '删除行',
  6061. noColor : '无颜色',
  6062. pleaseSelectFile : '请选择文件。',
  6063. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6064. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6065. invalidWidth : "宽度必须为数字。",
  6066. invalidHeight : "高度必须为数字。",
  6067. invalidBorder : "边框必须为数字。",
  6068. invalidUrl : "请输入有效的URL地址。",
  6069. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6070. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6071. invalidPadding : '边距必须为数字。',
  6072. invalidSpacing : '间距必须为数字。',
  6073. invalidJson : '服务器发生故障。',
  6074. uploadSuccess : '上传成功。',
  6075. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6076. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6077. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6078. ajaxLoading : '加载中,请稍候 ...',
  6079. uploadLoading : '上传中,请稍候 ...',
  6080. uploadError : '上传错误',
  6081. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6082. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6083. 'code.pleaseInput' : '请输入程序代码。',
  6084. 'link.url' : 'URL',
  6085. 'link.linkType' : '打开类型',
  6086. 'link.newWindow' : '新窗口',
  6087. 'link.selfWindow' : '当前窗口',
  6088. 'flash.url' : 'URL',
  6089. 'flash.width' : '宽度',
  6090. 'flash.height' : '高度',
  6091. 'flash.upload' : '上传',
  6092. 'flash.viewServer' : '文件空间',
  6093. 'media.url' : 'URL',
  6094. 'media.width' : '宽度',
  6095. 'media.height' : '高度',
  6096. 'media.autostart' : '自动播放',
  6097. 'media.upload' : '上传',
  6098. 'media.viewServer' : '文件空间',
  6099. 'image.remoteImage' : '网络图片',
  6100. 'image.localImage' : '本地上传',
  6101. 'image.remoteUrl' : '图片地址',
  6102. 'image.localUrl' : '上传文件',
  6103. 'image.size' : '图片大小',
  6104. 'image.width' : '宽',
  6105. 'image.height' : '高',
  6106. 'image.resetSize' : '重置大小',
  6107. 'image.align' : '对齐方式',
  6108. 'image.defaultAlign' : '默认方式',
  6109. 'image.leftAlign' : '左对齐',
  6110. 'image.rightAlign' : '右对齐',
  6111. 'image.imgTitle' : '图片说明',
  6112. 'image.upload' : '浏览...',
  6113. 'image.viewServer' : '图片空间',
  6114. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6115. 'multiimage.startUpload' : '开始上传',
  6116. 'multiimage.clearAll' : '全部清空',
  6117. 'multiimage.insertAll' : '全部插入',
  6118. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6119. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6120. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6121. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6122. 'multiimage.unknownError' : '发生异常,无法上传。',
  6123. 'multiimage.pending' : '等待上传',
  6124. 'multiimage.uploadError' : '上传失败',
  6125. 'filemanager.emptyFolder' : '空文件夹',
  6126. 'filemanager.moveup' : '移到上一级文件夹',
  6127. 'filemanager.viewType' : '显示方式:',
  6128. 'filemanager.viewImage' : '缩略图',
  6129. 'filemanager.listImage' : '详细信息',
  6130. 'filemanager.orderType' : '排序方式:',
  6131. 'filemanager.fileName' : '名称',
  6132. 'filemanager.fileSize' : '大小',
  6133. 'filemanager.fileType' : '类型',
  6134. 'insertfile.url' : 'URL',
  6135. 'insertfile.title' : '文件说明',
  6136. 'insertfile.upload' : '上传',
  6137. 'insertfile.viewServer' : '文件空间',
  6138. 'table.cells' : '单元格数',
  6139. 'table.rows' : '行数',
  6140. 'table.cols' : '列数',
  6141. 'table.size' : '大小',
  6142. 'table.width' : '宽度',
  6143. 'table.height' : '高度',
  6144. 'table.percent' : '%',
  6145. 'table.px' : 'px',
  6146. 'table.space' : '边距间距',
  6147. 'table.padding' : '边距',
  6148. 'table.spacing' : '间距',
  6149. 'table.align' : '对齐方式',
  6150. 'table.textAlign' : '水平对齐',
  6151. 'table.verticalAlign' : '垂直对齐',
  6152. 'table.alignDefault' : '默认',
  6153. 'table.alignLeft' : '左对齐',
  6154. 'table.alignCenter' : '居中',
  6155. 'table.alignRight' : '右对齐',
  6156. 'table.alignTop' : '顶部',
  6157. 'table.alignMiddle' : '中部',
  6158. 'table.alignBottom' : '底部',
  6159. 'table.alignBaseline' : '基线',
  6160. 'table.border' : '边框',
  6161. 'table.borderWidth' : '边框',
  6162. 'table.borderColor' : '颜色',
  6163. 'table.backgroundColor' : '背景颜色',
  6164. 'map.address' : '地址: ',
  6165. 'map.search' : '搜索',
  6166. 'baidumap.address' : '地址: ',
  6167. 'baidumap.search' : '搜索',
  6168. 'baidumap.insertDynamicMap' : '插入动态地图',
  6169. 'anchor.name' : '锚点名称',
  6170. 'formatblock.formatBlock' : {
  6171. h1 : '标题 1',
  6172. h2 : '标题 2',
  6173. h3 : '标题 3',
  6174. h4 : '标题 4',
  6175. p : '正 文'
  6176. },
  6177. 'fontname.fontName' : {
  6178. 'SimSun' : '宋体',
  6179. 'NSimSun' : '新宋体',
  6180. 'FangSong_GB2312' : '仿宋_GB2312',
  6181. 'KaiTi_GB2312' : '楷体_GB2312',
  6182. 'SimHei' : '黑体',
  6183. 'Microsoft YaHei' : '微软雅黑',
  6184. 'Arial' : 'Arial',
  6185. 'Arial Black' : 'Arial Black',
  6186. 'Times New Roman' : 'Times New Roman',
  6187. 'Courier New' : 'Courier New',
  6188. 'Tahoma' : 'Tahoma',
  6189. 'Verdana' : 'Verdana'
  6190. },
  6191. 'lineheight.lineHeight' : [
  6192. {'1' : '单倍行距'},
  6193. {'1.5' : '1.5倍行距'},
  6194. {'2' : '2倍行距'},
  6195. {'2.5' : '2.5倍行距'},
  6196. {'3' : '3倍行距'}
  6197. ],
  6198. 'template.selectTemplate' : '可选模板',
  6199. 'template.replaceContent' : '替换当前内容',
  6200. 'template.fileList' : {
  6201. '1.html' : '图片和文字',
  6202. '2.html' : '表格',
  6203. '3.html' : '项目编号'
  6204. }
  6205. }, 'zh-CN');
  6206. KindEditor.options.langType = 'zh-CN';
  6207. /*******************************************************************************
  6208. * KindEditor - WYSIWYG HTML Editor for Internet
  6209. * Copyright (C) 2006-2011 kindsoft.net
  6210. *
  6211. * @author Roddy <luolonghao@gmail.com>
  6212. * @site http://www.kindsoft.net/
  6213. * @licence http://www.kindsoft.net/license.php
  6214. *******************************************************************************/
  6215. KindEditor.plugin('anchor', function(K) {
  6216. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6217. self.plugin.anchor = {
  6218. edit : function() {
  6219. var html = ['<div style="padding:20px;">',
  6220. '<div class="ke-dialog-row">',
  6221. '<label for="keName">' + lang.name + '</label>',
  6222. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6223. '</div>',
  6224. '</div>'].join('');
  6225. var dialog = self.createDialog({
  6226. name : name,
  6227. width : 300,
  6228. title : self.lang(name),
  6229. body : html,
  6230. yesBtn : {
  6231. name : self.lang('yes'),
  6232. click : function(e) {
  6233. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6234. }
  6235. }
  6236. });
  6237. var div = dialog.div,
  6238. nameBox = K('input[name="name"]', div);
  6239. var img = self.plugin.getSelectedAnchor();
  6240. if (img) {
  6241. nameBox.val(unescape(img.attr('data-ke-name')));
  6242. }
  6243. nameBox[0].focus();
  6244. nameBox[0].select();
  6245. },
  6246. 'delete' : function() {
  6247. self.plugin.getSelectedAnchor().remove();
  6248. }
  6249. };
  6250. self.clickToolbar(name, self.plugin.anchor.edit);
  6251. });
  6252. /*******************************************************************************
  6253. * KindEditor - WYSIWYG HTML Editor for Internet
  6254. * Copyright (C) 2006-2011 kindsoft.net
  6255. *
  6256. * @author Roddy <luolonghao@gmail.com>
  6257. * @site http://www.kindsoft.net/
  6258. * @licence http://www.kindsoft.net/license.php
  6259. *******************************************************************************/
  6260. KindEditor.plugin('autoheight', function(K) {
  6261. var self = this;
  6262. if (!self.autoHeightMode) {
  6263. return;
  6264. }
  6265. var minHeight;
  6266. function hideScroll() {
  6267. var edit = self.edit;
  6268. var body = edit.doc.body;
  6269. edit.iframe[0].scroll = 'no';
  6270. body.style.overflowY = 'hidden';
  6271. }
  6272. function resetHeight() {
  6273. if(self.fullscreenMode){
  6274. return;
  6275. }
  6276. var edit = self.edit;
  6277. var body = edit.doc.body;
  6278. edit.iframe.height(minHeight);
  6279. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6280. }
  6281. function init() {
  6282. minHeight = K.removeUnit(self.height);
  6283. self.edit.afterChange(resetHeight);
  6284. if(!self.fullscreenMode){
  6285. hideScroll();
  6286. }
  6287. resetHeight();
  6288. }
  6289. if (self.isCreated) {
  6290. init();
  6291. } else {
  6292. self.afterCreate(init);
  6293. }
  6294. });
  6295. /*
  6296. * 如何实现真正的自动高度?
  6297. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6298. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6299. * 由此就实现了真正的自动高度
  6300. * 测试:chrome、firefox、IE9、IE8
  6301. * */
  6302. /*******************************************************************************
  6303. * KindEditor - WYSIWYG HTML Editor for Internet
  6304. * Copyright (C) 2006-2011 kindsoft.net
  6305. *
  6306. * @author Roddy <luolonghao@gmail.com>
  6307. * @site http://www.kindsoft.net/
  6308. * @licence http://www.kindsoft.net/license.php
  6309. *******************************************************************************/
  6310. KindEditor.plugin('baidumap', function(K) {
  6311. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6312. var mapWidth = K.undef(self.mapWidth, 558);
  6313. var mapHeight = K.undef(self.mapHeight, 360);
  6314. self.clickToolbar(name, function() {
  6315. var html = ['<div style="padding:10px 20px;">',
  6316. '<div class="ke-header">',
  6317. '<div class="ke-left">',
  6318. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6319. '<span class="ke-button-common ke-button-outer">',
  6320. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6321. '</span>',
  6322. '</div>',
  6323. '<div class="ke-right">',
  6324. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6325. '</div>',
  6326. '<div class="ke-clearfix"></div>',
  6327. '</div>',
  6328. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6329. '</div>'].join('');
  6330. var dialog = self.createDialog({
  6331. name : name,
  6332. width : mapWidth + 42,
  6333. title : self.lang(name),
  6334. body : html,
  6335. yesBtn : {
  6336. name : self.lang('yes'),
  6337. click : function(e) {
  6338. var map = win.map;
  6339. var centerObj = map.getCenter();
  6340. var center = centerObj.lng + ',' + centerObj.lat;
  6341. var zoom = map.getZoom();
  6342. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6343. '?center=' + encodeURIComponent(center),
  6344. '&zoom=' + encodeURIComponent(zoom),
  6345. '&width=' + mapWidth,
  6346. '&height=' + mapHeight,
  6347. '&markers=' + encodeURIComponent(center),
  6348. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6349. if (checkbox[0].checked) {
  6350. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6351. } else {
  6352. self.exec('insertimage', url);
  6353. }
  6354. self.hideDialog().focus();
  6355. }
  6356. },
  6357. beforeRemove : function() {
  6358. searchBtn.remove();
  6359. if (doc) {
  6360. doc.write('');
  6361. }
  6362. iframe.remove();
  6363. }
  6364. });
  6365. var div = dialog.div,
  6366. addressBox = K('[name="address"]', div),
  6367. searchBtn = K('[name="searchBtn"]', div),
  6368. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6369. win, doc;
  6370. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6371. function ready() {
  6372. win = iframe[0].contentWindow;
  6373. doc = K.iframeDoc(iframe);
  6374. }
  6375. iframe.bind('load', function() {
  6376. iframe.unbind('load');
  6377. if (K.IE) {
  6378. ready();
  6379. } else {
  6380. setTimeout(ready, 0);
  6381. }
  6382. });
  6383. K('.ke-map', div).replaceWith(iframe);
  6384. searchBtn.click(function() {
  6385. win.search(addressBox.val());
  6386. });
  6387. });
  6388. });
  6389. /*******************************************************************************
  6390. * KindEditor - WYSIWYG HTML Editor for Internet
  6391. * Copyright (C) 2006-2011 kindsoft.net
  6392. *
  6393. * @author Roddy <luolonghao@gmail.com>
  6394. * @site http://www.kindsoft.net/
  6395. * @licence http://www.kindsoft.net/license.php
  6396. *******************************************************************************/
  6397. KindEditor.plugin('map', function(K) {
  6398. var self = this, name = 'map', lang = self.lang(name + '.');
  6399. self.clickToolbar(name, function() {
  6400. var html = ['<div style="padding:10px 20px;">',
  6401. '<div class="ke-dialog-row">',
  6402. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6403. '<span class="ke-button-common ke-button-outer">',
  6404. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6405. '</span>',
  6406. '</div>',
  6407. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6408. '</div>'].join('');
  6409. var dialog = self.createDialog({
  6410. name : name,
  6411. width : 600,
  6412. title : self.lang(name),
  6413. body : html,
  6414. yesBtn : {
  6415. name : self.lang('yes'),
  6416. click : function(e) {
  6417. var geocoder = win.geocoder,
  6418. map = win.map,
  6419. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6420. zoom = map.getZoom(),
  6421. maptype = map.getMapTypeId(),
  6422. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6423. url += '?center=' + encodeURIComponent(center);
  6424. url += '&zoom=' + encodeURIComponent(zoom);
  6425. url += '&size=558x360';
  6426. url += '&maptype=' + encodeURIComponent(maptype);
  6427. url += '&markers=' + encodeURIComponent(center);
  6428. url += '&language=' + self.langType;
  6429. url += '&sensor=false';
  6430. self.exec('insertimage', url).hideDialog().focus();
  6431. }
  6432. },
  6433. beforeRemove : function() {
  6434. searchBtn.remove();
  6435. if (doc) {
  6436. doc.write('');
  6437. }
  6438. iframe.remove();
  6439. }
  6440. });
  6441. var div = dialog.div,
  6442. addressBox = K('[name="address"]', div),
  6443. searchBtn = K('[name="searchBtn"]', div),
  6444. win, doc;
  6445. var iframeHtml = ['<!doctype html><html><head>',
  6446. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6447. '<style>',
  6448. ' html { height: 100% }',
  6449. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6450. ' #map_canvas { height: 100% }',
  6451. '</style>',
  6452. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6453. '<script>',
  6454. 'var map, geocoder;',
  6455. 'function initialize() {',
  6456. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6457. ' var options = {',
  6458. ' zoom: 11,',
  6459. ' center: latlng,',
  6460. ' disableDefaultUI: true,',
  6461. ' panControl: true,',
  6462. ' zoomControl: true,',
  6463. ' mapTypeControl: true,',
  6464. ' scaleControl: true,',
  6465. ' streetViewControl: false,',
  6466. ' overviewMapControl: true,',
  6467. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6468. ' };',
  6469. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6470. ' geocoder = new google.maps.Geocoder();',
  6471. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6472. ' if (status == google.maps.GeocoderStatus.OK) {',
  6473. ' if (results[3]) {',
  6474. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6475. ' }',
  6476. ' }',
  6477. ' });',
  6478. '}',
  6479. 'function search(address) {',
  6480. ' if (!map) return;',
  6481. ' geocoder.geocode({address : address}, function(results, status) {',
  6482. ' if (status == google.maps.GeocoderStatus.OK) {',
  6483. ' map.setZoom(11);',
  6484. ' map.setCenter(results[0].geometry.location);',
  6485. ' var marker = new google.maps.Marker({',
  6486. ' map: map,',
  6487. ' position: results[0].geometry.location',
  6488. ' });',
  6489. ' } else {',
  6490. ' alert("Invalid address: " + address);',
  6491. ' }',
  6492. ' });',
  6493. '}',
  6494. '</script>',
  6495. '</head>',
  6496. '<body onload="initialize();">',
  6497. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6498. '</body></html>'].join('\n');
  6499. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6500. function ready() {
  6501. win = iframe[0].contentWindow;
  6502. doc = K.iframeDoc(iframe);
  6503. }
  6504. iframe.bind('load', function() {
  6505. iframe.unbind('load');
  6506. if (K.IE) {
  6507. ready();
  6508. } else {
  6509. setTimeout(ready, 0);
  6510. }
  6511. });
  6512. K('.ke-map', div).replaceWith(iframe);
  6513. searchBtn.click(function() {
  6514. win.search(addressBox.val());
  6515. });
  6516. });
  6517. });
  6518. /*******************************************************************************
  6519. * KindEditor - WYSIWYG HTML Editor for Internet
  6520. * Copyright (C) 2006-2011 kindsoft.net
  6521. *
  6522. * @author Roddy <luolonghao@gmail.com>
  6523. * @site http://www.kindsoft.net/
  6524. * @licence http://www.kindsoft.net/license.php
  6525. *******************************************************************************/
  6526. KindEditor.plugin('clearhtml', function(K) {
  6527. var self = this, name = 'clearhtml';
  6528. self.clickToolbar(name, function() {
  6529. self.focus();
  6530. var html = self.html();
  6531. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6532. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6533. html = K.formatHtml(html, {
  6534. a : ['href', 'target'],
  6535. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6536. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6537. table : ['border'],
  6538. 'td,th' : ['rowspan', 'colspan'],
  6539. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6540. });
  6541. self.html(html);
  6542. self.cmd.selection(true);
  6543. self.addBookmark();
  6544. });
  6545. });
  6546. /*******************************************************************************
  6547. * KindEditor - WYSIWYG HTML Editor for Internet
  6548. * Copyright (C) 2006-2011 kindsoft.net
  6549. *
  6550. * @author Roddy <luolonghao@gmail.com>
  6551. * @site http://www.kindsoft.net/
  6552. * @licence http://www.kindsoft.net/license.php
  6553. *******************************************************************************/
  6554. KindEditor.plugin('code', function(K) {
  6555. var self = this, name = 'code';
  6556. self.clickToolbar(name, function() {
  6557. var lang = self.lang(name + '.'),
  6558. html = ['<div style="padding:10px 20px;">',
  6559. '<div class="ke-dialog-row">',
  6560. '<select class="ke-code-type">',
  6561. '<option value="js">JavaScript</option>',
  6562. '<option value="html">HTML</option>',
  6563. '<option value="css">CSS</option>',
  6564. '<option value="php">PHP</option>',
  6565. '<option value="pl">Perl</option>',
  6566. '<option value="py">Python</option>',
  6567. '<option value="rb">Ruby</option>',
  6568. '<option value="java">Java</option>',
  6569. '<option value="vb">ASP/VB</option>',
  6570. '<option value="cpp">C/C++</option>',
  6571. '<option value="cs">C#</option>',
  6572. '<option value="xml">XML</option>',
  6573. '<option value="bsh">Shell</option>',
  6574. '<option value="">Other</option>',
  6575. '</select>',
  6576. '</div>',
  6577. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6578. '</div>'].join(''),
  6579. dialog = self.createDialog({
  6580. name : name,
  6581. width : 450,
  6582. title : self.lang(name),
  6583. body : html,
  6584. yesBtn : {
  6585. name : self.lang('yes'),
  6586. click : function(e) {
  6587. var type = K('.ke-code-type', dialog.div).val(),
  6588. code = textarea.val(),
  6589. cls = type === '' ? '' : ' lang-' + type,
  6590. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6591. if (K.trim(code) === '') {
  6592. alert(lang.pleaseInput);
  6593. textarea[0].focus();
  6594. return;
  6595. }
  6596. self.insertHtml(html).hideDialog().focus();
  6597. }
  6598. }
  6599. }),
  6600. textarea = K('textarea', dialog.div);
  6601. textarea[0].focus();
  6602. });
  6603. });
  6604. /*******************************************************************************
  6605. * KindEditor - WYSIWYG HTML Editor for Internet
  6606. * Copyright (C) 2006-2011 kindsoft.net
  6607. *
  6608. * @author Roddy <luolonghao@gmail.com>
  6609. * @site http://www.kindsoft.net/
  6610. * @licence http://www.kindsoft.net/license.php
  6611. *******************************************************************************/
  6612. KindEditor.plugin('emoticons', function(K) {
  6613. var self = this, name = 'emoticons',
  6614. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6615. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6616. currentPageNum = 1;
  6617. self.clickToolbar(name, function() {
  6618. var rows = 5, cols = 9, total = 135, startNum = 0,
  6619. cells = rows * cols, pages = Math.ceil(total / cells),
  6620. colsHalf = Math.floor(cols / 2),
  6621. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6622. elements = [],
  6623. menu = self.createMenu({
  6624. name : name,
  6625. beforeRemove : function() {
  6626. removeEvent();
  6627. }
  6628. });
  6629. menu.div.append(wrapperDiv);
  6630. var previewDiv, previewImg;
  6631. if (allowPreview) {
  6632. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6633. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6634. wrapperDiv.append(previewDiv);
  6635. previewDiv.append(previewImg);
  6636. }
  6637. function bindCellEvent(cell, j, num) {
  6638. if (previewDiv) {
  6639. cell.mouseover(function() {
  6640. if (j > colsHalf) {
  6641. previewDiv.css('left', 0);
  6642. previewDiv.css('right', '');
  6643. } else {
  6644. previewDiv.css('left', '');
  6645. previewDiv.css('right', 0);
  6646. }
  6647. previewImg.attr('src', path + num + '.gif');
  6648. K(this).addClass('ke-on');
  6649. });
  6650. } else {
  6651. cell.mouseover(function() {
  6652. K(this).addClass('ke-on');
  6653. });
  6654. }
  6655. cell.mouseout(function() {
  6656. K(this).removeClass('ke-on');
  6657. });
  6658. cell.click(function(e) {
  6659. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6660. e.stop();
  6661. });
  6662. }
  6663. function createEmoticonsTable(pageNum, parentDiv) {
  6664. var table = document.createElement('table');
  6665. parentDiv.append(table);
  6666. if (previewDiv) {
  6667. K(table).mouseover(function() {
  6668. previewDiv.show('block');
  6669. });
  6670. K(table).mouseout(function() {
  6671. previewDiv.hide();
  6672. });
  6673. elements.push(K(table));
  6674. }
  6675. table.className = 'ke-table';
  6676. table.cellPadding = 0;
  6677. table.cellSpacing = 0;
  6678. table.border = 0;
  6679. var num = (pageNum - 1) * cells + startNum;
  6680. for (var i = 0; i < rows; i++) {
  6681. var row = table.insertRow(i);
  6682. for (var j = 0; j < cols; j++) {
  6683. var cell = K(row.insertCell(j));
  6684. cell.addClass('ke-cell');
  6685. bindCellEvent(cell, j, num);
  6686. var span = K('<span class="ke-img"></span>')
  6687. .css('background-position', '-' + (24 * num) + 'px 0px')
  6688. .css('background-image', 'url(' + path + 'static.gif)');
  6689. cell.append(span);
  6690. elements.push(cell);
  6691. num++;
  6692. }
  6693. }
  6694. return table;
  6695. }
  6696. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6697. function removeEvent() {
  6698. K.each(elements, function() {
  6699. this.unbind();
  6700. });
  6701. }
  6702. var pageDiv;
  6703. function bindPageEvent(el, pageNum) {
  6704. el.click(function(e) {
  6705. removeEvent();
  6706. table.parentNode.removeChild(table);
  6707. pageDiv.remove();
  6708. table = createEmoticonsTable(pageNum, wrapperDiv);
  6709. createPageTable(pageNum);
  6710. currentPageNum = pageNum;
  6711. e.stop();
  6712. });
  6713. }
  6714. function createPageTable(currentPageNum) {
  6715. pageDiv = K('<div class="ke-page"></div>');
  6716. wrapperDiv.append(pageDiv);
  6717. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6718. if (currentPageNum !== pageNum) {
  6719. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6720. bindPageEvent(a, pageNum);
  6721. pageDiv.append(a);
  6722. elements.push(a);
  6723. } else {
  6724. pageDiv.append(K('@[' + pageNum + ']'));
  6725. }
  6726. pageDiv.append(K('@&nbsp;'));
  6727. }
  6728. }
  6729. createPageTable(currentPageNum);
  6730. });
  6731. });
  6732. /*******************************************************************************
  6733. * KindEditor - WYSIWYG HTML Editor for Internet
  6734. * Copyright (C) 2006-2011 kindsoft.net
  6735. *
  6736. * @author Roddy <luolonghao@gmail.com>
  6737. * @site http://www.kindsoft.net/
  6738. * @licence http://www.kindsoft.net/license.php
  6739. *******************************************************************************/
  6740. KindEditor.plugin('filemanager', function(K) {
  6741. var self = this, name = 'filemanager',
  6742. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6743. imgPath = self.pluginsPath + name + '/images/',
  6744. lang = self.lang(name + '.');
  6745. function makeFileTitle(filename, filesize, datetime) {
  6746. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6747. }
  6748. function bindTitle(el, data) {
  6749. if (data.is_dir) {
  6750. el.attr('title', data.filename);
  6751. } else {
  6752. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6753. }
  6754. }
  6755. self.plugin.filemanagerDialog = function(options) {
  6756. var width = K.undef(options.width, 650),
  6757. height = K.undef(options.height, 510),
  6758. dirName = K.undef(options.dirName, ''),
  6759. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6760. clickFn = options.clickFn;
  6761. var html = [
  6762. '<div style="padding:10px 20px;">',
  6763. '<div class="ke-plugin-filemanager-header">',
  6764. '<div class="ke-left">',
  6765. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6766. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6767. '</div>',
  6768. '<div class="ke-right">',
  6769. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6770. '<option value="VIEW">' + lang.viewImage + '</option>',
  6771. '<option value="LIST">' + lang.listImage + '</option>',
  6772. '</select> ',
  6773. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6774. '<option value="NAME">' + lang.fileName + '</option>',
  6775. '<option value="SIZE">' + lang.fileSize + '</option>',
  6776. '<option value="TYPE">' + lang.fileType + '</option>',
  6777. '</select>',
  6778. '</div>',
  6779. '<div class="ke-clearfix"></div>',
  6780. '</div>',
  6781. '<div class="ke-plugin-filemanager-body"></div>',
  6782. '</div>'
  6783. ].join('');
  6784. var dialog = self.createDialog({
  6785. name : name,
  6786. width : width,
  6787. height : height,
  6788. title : self.lang(name),
  6789. body : html
  6790. }),
  6791. div = dialog.div,
  6792. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6793. moveupImg = K('[name="moveupImg"]', div),
  6794. moveupLink = K('[name="moveupLink"]', div),
  6795. viewServerBtn = K('[name="viewServer"]', div),
  6796. viewTypeBox = K('[name="viewType"]', div),
  6797. orderTypeBox = K('[name="orderType"]', div);
  6798. function reloadPage(path, order, func) {
  6799. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6800. dialog.showLoading(self.lang('ajaxLoading'));
  6801. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6802. dialog.hideLoading();
  6803. func(data);
  6804. });
  6805. }
  6806. var elList = [];
  6807. function bindEvent(el, result, data, createFunc) {
  6808. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6809. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6810. if (data.is_dir) {
  6811. el.click(function(e) {
  6812. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6813. });
  6814. } else if (data.is_photo) {
  6815. el.click(function(e) {
  6816. clickFn.call(this, fileUrl, data.filename);
  6817. });
  6818. } else {
  6819. el.click(function(e) {
  6820. clickFn.call(this, fileUrl, data.filename);
  6821. });
  6822. }
  6823. elList.push(el);
  6824. }
  6825. function createCommon(result, createFunc) {
  6826. K.each(elList, function() {
  6827. this.unbind();
  6828. });
  6829. moveupLink.unbind();
  6830. viewTypeBox.unbind();
  6831. orderTypeBox.unbind();
  6832. if (result.current_dir_path) {
  6833. moveupLink.click(function(e) {
  6834. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6835. });
  6836. }
  6837. function changeFunc() {
  6838. if (viewTypeBox.val() == 'VIEW') {
  6839. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6840. } else {
  6841. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6842. }
  6843. }
  6844. viewTypeBox.change(changeFunc);
  6845. orderTypeBox.change(changeFunc);
  6846. bodyDiv.html('');
  6847. }
  6848. function createList(result) {
  6849. createCommon(result, createList);
  6850. var table = document.createElement('table');
  6851. table.className = 'ke-table';
  6852. table.cellPadding = 0;
  6853. table.cellSpacing = 0;
  6854. table.border = 0;
  6855. bodyDiv.append(table);
  6856. var fileList = result.file_list;
  6857. for (var i = 0, len = fileList.length; i < len; i++) {
  6858. var data = fileList[i], row = K(table.insertRow(i));
  6859. row.mouseover(function(e) {
  6860. K(this).addClass('ke-on');
  6861. })
  6862. .mouseout(function(e) {
  6863. K(this).removeClass('ke-on');
  6864. });
  6865. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6866. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6867. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6868. if (!data.is_dir || data.has_file) {
  6869. row.css('cursor', 'pointer');
  6870. cell0.attr('title', data.filename);
  6871. bindEvent(cell0, result, data, createList);
  6872. } else {
  6873. cell0.attr('title', lang.emptyFolder);
  6874. }
  6875. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6876. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6877. }
  6878. }
  6879. function createView(result) {
  6880. createCommon(result, createView);
  6881. var fileList = result.file_list;
  6882. for (var i = 0, len = fileList.length; i < len; i++) {
  6883. var data = fileList[i],
  6884. div = K('<div class="ke-inline-block ke-item"></div>');
  6885. bodyDiv.append(div);
  6886. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6887. .mouseover(function(e) {
  6888. K(this).addClass('ke-on');
  6889. })
  6890. .mouseout(function(e) {
  6891. K(this).removeClass('ke-on');
  6892. });
  6893. div.append(photoDiv);
  6894. var fileUrl = result.current_url + data.filename,
  6895. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6896. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6897. if (!data.is_dir || data.has_file) {
  6898. photoDiv.css('cursor', 'pointer');
  6899. bindTitle(photoDiv, data);
  6900. bindEvent(photoDiv, result, data, createView);
  6901. } else {
  6902. photoDiv.attr('title', lang.emptyFolder);
  6903. }
  6904. photoDiv.append(img);
  6905. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6906. }
  6907. }
  6908. viewTypeBox.val(viewType);
  6909. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6910. return dialog;
  6911. }
  6912. });
  6913. /*******************************************************************************
  6914. * KindEditor - WYSIWYG HTML Editor for Internet
  6915. * Copyright (C) 2006-2011 kindsoft.net
  6916. *
  6917. * @author Roddy <luolonghao@gmail.com>
  6918. * @site http://www.kindsoft.net/
  6919. * @licence http://www.kindsoft.net/license.php
  6920. *******************************************************************************/
  6921. KindEditor.plugin('flash', function(K) {
  6922. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6923. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6924. allowFileManager = K.undef(self.allowFileManager, false),
  6925. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6926. extraParams = K.undef(self.extraFileUploadParams, {}),
  6927. filePostName = K.undef(self.filePostName, 'imgFile'),
  6928. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  6929. self.plugin.flash = {
  6930. edit : function() {
  6931. var html = [
  6932. '<div style="padding:20px;">',
  6933. '<div class="ke-dialog-row">',
  6934. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6935. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6936. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6937. '<span class="ke-button-common ke-button-outer">',
  6938. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6939. '</span>',
  6940. '</div>',
  6941. '<div class="ke-dialog-row">',
  6942. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6943. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6944. '</div>',
  6945. '<div class="ke-dialog-row">',
  6946. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6947. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6948. '</div>',
  6949. '</div>'
  6950. ].join('');
  6951. var dialog = self.createDialog({
  6952. name : name,
  6953. width : 450,
  6954. title : self.lang(name),
  6955. body : html,
  6956. yesBtn : {
  6957. name : self.lang('yes'),
  6958. click : function(e) {
  6959. var url = K.trim(urlBox.val()),
  6960. width = widthBox.val(),
  6961. height = heightBox.val();
  6962. if (url == 'http://' || K.invalidUrl(url)) {
  6963. alert(self.lang('invalidUrl'));
  6964. urlBox[0].focus();
  6965. return;
  6966. }
  6967. if (!/^\d*$/.test(width)) {
  6968. alert(self.lang('invalidWidth'));
  6969. widthBox[0].focus();
  6970. return;
  6971. }
  6972. if (!/^\d*$/.test(height)) {
  6973. alert(self.lang('invalidHeight'));
  6974. heightBox[0].focus();
  6975. return;
  6976. }
  6977. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6978. src : url,
  6979. type : K.mediaType('.swf'),
  6980. width : width,
  6981. height : height,
  6982. quality : 'high'
  6983. });
  6984. self.insertHtml(html).hideDialog().focus();
  6985. }
  6986. }
  6987. }),
  6988. div = dialog.div,
  6989. urlBox = K('[name="url"]', div),
  6990. viewServerBtn = K('[name="viewServer"]', div),
  6991. widthBox = K('[name="width"]', div),
  6992. heightBox = K('[name="height"]', div);
  6993. urlBox.val('http://');
  6994. if (allowFlashUpload) {
  6995. var uploadbutton = K.uploadbutton({
  6996. button : K('.ke-upload-button', div)[0],
  6997. fieldName : filePostName,
  6998. extraParams : extraParams,
  6999. url : K.addParam(uploadJson, 'dir=flash'),
  7000. afterUpload : function(data) {
  7001. dialog.hideLoading();
  7002. if (data.error === 0) {
  7003. var url = data.url;
  7004. if (formatUploadUrl) {
  7005. url = K.formatUrl(url, 'absolute');
  7006. }
  7007. urlBox.val(url);
  7008. if (self.afterUpload) {
  7009. self.afterUpload.call(self, url, data, name);
  7010. }
  7011. alert(self.lang('uploadSuccess'));
  7012. } else {
  7013. alert(data.message);
  7014. }
  7015. },
  7016. afterError : function(html) {
  7017. dialog.hideLoading();
  7018. self.errorDialog(html);
  7019. }
  7020. });
  7021. uploadbutton.fileBox.change(function(e) {
  7022. dialog.showLoading(self.lang('uploadLoading'));
  7023. uploadbutton.submit();
  7024. });
  7025. } else {
  7026. K('.ke-upload-button', div).hide();
  7027. }
  7028. if (allowFileManager) {
  7029. viewServerBtn.click(function(e) {
  7030. self.loadPlugin('filemanager', function() {
  7031. self.plugin.filemanagerDialog({
  7032. viewType : 'LIST',
  7033. dirName : 'flash',
  7034. clickFn : function(url, title) {
  7035. if (self.dialogs.length > 1) {
  7036. K('[name="url"]', div).val(url);
  7037. if (self.afterSelectFile) {
  7038. self.afterSelectFile.call(self, url);
  7039. }
  7040. self.hideDialog();
  7041. }
  7042. }
  7043. });
  7044. });
  7045. });
  7046. } else {
  7047. viewServerBtn.hide();
  7048. }
  7049. var img = self.plugin.getSelectedFlash();
  7050. if (img) {
  7051. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7052. urlBox.val(attrs.src);
  7053. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7054. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7055. }
  7056. urlBox[0].focus();
  7057. urlBox[0].select();
  7058. },
  7059. 'delete' : function() {
  7060. self.plugin.getSelectedFlash().remove();
  7061. self.addBookmark();
  7062. }
  7063. };
  7064. self.clickToolbar(name, self.plugin.flash.edit);
  7065. });
  7066. /*******************************************************************************
  7067. * KindEditor - WYSIWYG HTML Editor for Internet
  7068. * Copyright (C) 2006-2011 kindsoft.net
  7069. *
  7070. * @author Roddy <luolonghao@gmail.com>
  7071. * @site http://www.kindsoft.net/
  7072. * @licence http://www.kindsoft.net/license.php
  7073. *******************************************************************************/
  7074. KindEditor.plugin('image', function(K) {
  7075. var self = this, name = 'image',
  7076. allowImageUpload = K.undef(self.allowImageUpload, true),
  7077. allowImageRemote = K.undef(self.allowImageRemote, true),
  7078. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7079. allowFileManager = K.undef(self.allowFileManager, false),
  7080. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7081. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7082. imgPath = self.pluginsPath + 'image/images/',
  7083. extraParams = K.undef(self.extraFileUploadParams, {}),
  7084. filePostName = K.undef(self.filePostName, 'imgFile'),
  7085. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7086. lang = self.lang(name + '.');
  7087. self.plugin.imageDialog = function(options) {
  7088. var imageUrl = options.imageUrl,
  7089. imageWidth = K.undef(options.imageWidth, ''),
  7090. imageHeight = K.undef(options.imageHeight, ''),
  7091. imageTitle = K.undef(options.imageTitle, ''),
  7092. imageAlign = K.undef(options.imageAlign, ''),
  7093. showRemote = K.undef(options.showRemote, true),
  7094. showLocal = K.undef(options.showLocal, true),
  7095. tabIndex = K.undef(options.tabIndex, 0),
  7096. clickFn = options.clickFn;
  7097. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7098. var hiddenElements = [];
  7099. for(var k in extraParams){
  7100. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7101. }
  7102. var html = [
  7103. '<div style="padding:20px;">',
  7104. '<div class="tabs"></div>',
  7105. '<div class="tab1" style="display:none;">',
  7106. '<div class="ke-dialog-row">',
  7107. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7108. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7109. '<span class="ke-button-common ke-button-outer">',
  7110. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7111. '</span>',
  7112. '</div>',
  7113. '<div class="ke-dialog-row">',
  7114. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7115. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7116. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7117. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7118. '</div>',
  7119. '<div class="ke-dialog-row">',
  7120. '<label style="width:60px;">' + lang.align + '</label>',
  7121. '<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="" />',
  7122. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7123. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7124. '</div>',
  7125. '<div class="ke-dialog-row">',
  7126. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7127. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7128. '</div>',
  7129. '</div>',
  7130. '<div class="tab2" style="display:none;">',
  7131. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7132. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7133. '<div class="ke-dialog-row">',
  7134. hiddenElements.join(''),
  7135. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7136. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7137. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7138. '</div>',
  7139. '</form>',
  7140. '</div>',
  7141. '</div>'
  7142. ].join('');
  7143. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7144. dialogHeight = showLocal && showRemote ? 300 : 250;
  7145. var dialog = self.createDialog({
  7146. name : name,
  7147. width : dialogWidth,
  7148. height : dialogHeight,
  7149. title : self.lang(name),
  7150. body : html,
  7151. yesBtn : {
  7152. name : self.lang('yes'),
  7153. click : function(e) {
  7154. if (dialog.isLoading) {
  7155. return;
  7156. }
  7157. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7158. if (uploadbutton.fileBox.val() == '') {
  7159. alert(self.lang('pleaseSelectFile'));
  7160. return;
  7161. }
  7162. dialog.showLoading(self.lang('uploadLoading'));
  7163. uploadbutton.submit();
  7164. localUrlBox.val('');
  7165. return;
  7166. }
  7167. var url = K.trim(urlBox.val()),
  7168. width = widthBox.val(),
  7169. height = heightBox.val(),
  7170. title = titleBox.val(),
  7171. align = '';
  7172. alignBox.each(function() {
  7173. if (this.checked) {
  7174. align = this.value;
  7175. return false;
  7176. }
  7177. });
  7178. if (url == 'http://' || K.invalidUrl(url)) {
  7179. alert(self.lang('invalidUrl'));
  7180. urlBox[0].focus();
  7181. return;
  7182. }
  7183. if (!/^\d*$/.test(width)) {
  7184. alert(self.lang('invalidWidth'));
  7185. widthBox[0].focus();
  7186. return;
  7187. }
  7188. if (!/^\d*$/.test(height)) {
  7189. alert(self.lang('invalidHeight'));
  7190. heightBox[0].focus();
  7191. return;
  7192. }
  7193. clickFn.call(self, url, title, width, height, 0, align);
  7194. }
  7195. },
  7196. beforeRemove : function() {
  7197. viewServerBtn.unbind();
  7198. widthBox.unbind();
  7199. heightBox.unbind();
  7200. refreshBtn.unbind();
  7201. }
  7202. }),
  7203. div = dialog.div;
  7204. var urlBox = K('[name="url"]', div),
  7205. localUrlBox = K('[name="localUrl"]', div),
  7206. viewServerBtn = K('[name="viewServer"]', div),
  7207. widthBox = K('.tab1 [name="width"]', div),
  7208. heightBox = K('.tab1 [name="height"]', div),
  7209. refreshBtn = K('.ke-refresh-btn', div),
  7210. titleBox = K('.tab1 [name="title"]', div),
  7211. alignBox = K('.tab1 [name="align"]', div);
  7212. var tabs;
  7213. if (showRemote && showLocal) {
  7214. tabs = K.tabs({
  7215. src : K('.tabs', div),
  7216. afterSelect : function(i) {}
  7217. });
  7218. tabs.add({
  7219. title : lang.remoteImage,
  7220. panel : K('.tab1', div)
  7221. });
  7222. tabs.add({
  7223. title : lang.localImage,
  7224. panel : K('.tab2', div)
  7225. });
  7226. tabs.select(tabIndex);
  7227. } else if (showRemote) {
  7228. K('.tab1', div).show();
  7229. } else if (showLocal) {
  7230. K('.tab2', div).show();
  7231. }
  7232. var uploadbutton = K.uploadbutton({
  7233. button : K('.ke-upload-button', div)[0],
  7234. fieldName : filePostName,
  7235. form : K('.ke-form', div),
  7236. target : target,
  7237. width: 60,
  7238. afterUpload : function(data) {
  7239. dialog.hideLoading();
  7240. if (data.error === 0) {
  7241. var url = data.url;
  7242. if (formatUploadUrl) {
  7243. url = K.formatUrl(url, 'absolute');
  7244. }
  7245. if (self.afterUpload) {
  7246. self.afterUpload.call(self, url, data, name);
  7247. }
  7248. if (!fillDescAfterUploadImage) {
  7249. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7250. } else {
  7251. K(".ke-dialog-row #remoteUrl", div).val(url);
  7252. K(".ke-tabs-li", div)[0].click();
  7253. K(".ke-refresh-btn", div).click();
  7254. }
  7255. } else {
  7256. alert(data.message);
  7257. }
  7258. },
  7259. afterError : function(html) {
  7260. dialog.hideLoading();
  7261. self.errorDialog(html);
  7262. }
  7263. });
  7264. uploadbutton.fileBox.change(function(e) {
  7265. localUrlBox.val(uploadbutton.fileBox.val());
  7266. });
  7267. if (allowFileManager) {
  7268. viewServerBtn.click(function(e) {
  7269. self.loadPlugin('filemanager', function() {
  7270. self.plugin.filemanagerDialog({
  7271. viewType : 'VIEW',
  7272. dirName : 'image',
  7273. clickFn : function(url, title) {
  7274. if (self.dialogs.length > 1) {
  7275. K('[name="url"]', div).val(url);
  7276. if (self.afterSelectFile) {
  7277. self.afterSelectFile.call(self, url);
  7278. }
  7279. self.hideDialog();
  7280. }
  7281. }
  7282. });
  7283. });
  7284. });
  7285. } else {
  7286. viewServerBtn.hide();
  7287. }
  7288. var originalWidth = 0, originalHeight = 0;
  7289. function setSize(width, height) {
  7290. widthBox.val(width);
  7291. heightBox.val(height);
  7292. originalWidth = width;
  7293. originalHeight = height;
  7294. }
  7295. refreshBtn.click(function(e) {
  7296. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7297. position : 'absolute',
  7298. visibility : 'hidden',
  7299. top : 0,
  7300. left : '-1000px'
  7301. });
  7302. tempImg.bind('load', function() {
  7303. setSize(tempImg.width(), tempImg.height());
  7304. tempImg.remove();
  7305. });
  7306. K(document.body).append(tempImg);
  7307. });
  7308. widthBox.change(function(e) {
  7309. if (originalWidth > 0) {
  7310. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7311. }
  7312. });
  7313. heightBox.change(function(e) {
  7314. if (originalHeight > 0) {
  7315. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7316. }
  7317. });
  7318. urlBox.val(options.imageUrl);
  7319. setSize(options.imageWidth, options.imageHeight);
  7320. titleBox.val(options.imageTitle);
  7321. alignBox.each(function() {
  7322. if (this.value === options.imageAlign) {
  7323. this.checked = true;
  7324. return false;
  7325. }
  7326. });
  7327. if (showRemote && tabIndex === 0) {
  7328. urlBox[0].focus();
  7329. urlBox[0].select();
  7330. }
  7331. return dialog;
  7332. };
  7333. self.plugin.image = {
  7334. edit : function() {
  7335. var img = self.plugin.getSelectedImage();
  7336. self.plugin.imageDialog({
  7337. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7338. imageWidth : img ? img.width() : '',
  7339. imageHeight : img ? img.height() : '',
  7340. imageTitle : img ? img.attr('title') : '',
  7341. imageAlign : img ? img.attr('align') : '',
  7342. showRemote : allowImageRemote,
  7343. showLocal : allowImageUpload,
  7344. tabIndex: img ? 0 : imageTabIndex,
  7345. clickFn : function(url, title, width, height, border, align) {
  7346. if (img) {
  7347. img.attr('src', url);
  7348. img.attr('data-ke-src', url);
  7349. img.attr('width', width);
  7350. img.attr('height', height);
  7351. img.attr('title', title);
  7352. img.attr('align', align);
  7353. img.attr('alt', title);
  7354. } else {
  7355. self.exec('insertimage', url, title, width, height, border, align);
  7356. }
  7357. setTimeout(function() {
  7358. self.hideDialog().focus();
  7359. }, 0);
  7360. }
  7361. });
  7362. },
  7363. 'delete' : function() {
  7364. var target = self.plugin.getSelectedImage();
  7365. if (target.parent().name == 'a') {
  7366. target = target.parent();
  7367. }
  7368. target.remove();
  7369. self.addBookmark();
  7370. }
  7371. };
  7372. self.clickToolbar(name, self.plugin.image.edit);
  7373. });
  7374. /*******************************************************************************
  7375. * KindEditor - WYSIWYG HTML Editor for Internet
  7376. * Copyright (C) 2006-2011 kindsoft.net
  7377. *
  7378. * @author Roddy <luolonghao@gmail.com>
  7379. * @site http://www.kindsoft.net/
  7380. * @licence http://www.kindsoft.net/license.php
  7381. *******************************************************************************/
  7382. KindEditor.plugin('insertfile', function(K) {
  7383. var self = this, name = 'insertfile',
  7384. allowFileUpload = K.undef(self.allowFileUpload, true),
  7385. allowFileManager = K.undef(self.allowFileManager, false),
  7386. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7387. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7388. extraParams = K.undef(self.extraFileUploadParams, {}),
  7389. filePostName = K.undef(self.filePostName, 'imgFile'),
  7390. lang = self.lang(name + '.');
  7391. self.plugin.fileDialog = function(options) {
  7392. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7393. fileTitle = K.undef(options.fileTitle, ''),
  7394. clickFn = options.clickFn;
  7395. var html = [
  7396. '<div style="padding:20px;">',
  7397. '<div class="ke-dialog-row">',
  7398. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7399. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7400. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7401. '<span class="ke-button-common ke-button-outer">',
  7402. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7403. '</span>',
  7404. '</div>',
  7405. '<div class="ke-dialog-row">',
  7406. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7407. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7408. '</div>',
  7409. '</form>',
  7410. '</div>'
  7411. ].join('');
  7412. var dialog = self.createDialog({
  7413. name : name,
  7414. width : 450,
  7415. title : self.lang(name),
  7416. body : html,
  7417. yesBtn : {
  7418. name : self.lang('yes'),
  7419. click : function(e) {
  7420. var url = K.trim(urlBox.val()),
  7421. title = titleBox.val();
  7422. if (url == 'http://' || K.invalidUrl(url)) {
  7423. alert(self.lang('invalidUrl'));
  7424. urlBox[0].focus();
  7425. return;
  7426. }
  7427. if (K.trim(title) === '') {
  7428. title = url;
  7429. }
  7430. clickFn.call(self, url, title);
  7431. }
  7432. }
  7433. }),
  7434. div = dialog.div;
  7435. var urlBox = K('[name="url"]', div),
  7436. viewServerBtn = K('[name="viewServer"]', div),
  7437. titleBox = K('[name="title"]', div);
  7438. if (allowFileUpload) {
  7439. var uploadbutton = K.uploadbutton({
  7440. button : K('.ke-upload-button', div)[0],
  7441. fieldName : filePostName,
  7442. url : K.addParam(uploadJson, 'dir=file'),
  7443. extraParams : extraParams,
  7444. afterUpload : function(data) {
  7445. dialog.hideLoading();
  7446. if (data.error === 0) {
  7447. var url = data.url;
  7448. if (formatUploadUrl) {
  7449. url = K.formatUrl(url, 'absolute');
  7450. }
  7451. urlBox.val(url);
  7452. if (self.afterUpload) {
  7453. self.afterUpload.call(self, url, data, name);
  7454. }
  7455. alert(self.lang('uploadSuccess'));
  7456. } else {
  7457. alert(data.message);
  7458. }
  7459. },
  7460. afterError : function(html) {
  7461. dialog.hideLoading();
  7462. self.errorDialog(html);
  7463. }
  7464. });
  7465. uploadbutton.fileBox.change(function(e) {
  7466. dialog.showLoading(self.lang('uploadLoading'));
  7467. uploadbutton.submit();
  7468. });
  7469. } else {
  7470. K('.ke-upload-button', div).hide();
  7471. }
  7472. if (allowFileManager) {
  7473. viewServerBtn.click(function(e) {
  7474. self.loadPlugin('filemanager', function() {
  7475. self.plugin.filemanagerDialog({
  7476. viewType : 'LIST',
  7477. dirName : 'file',
  7478. clickFn : function(url, title) {
  7479. if (self.dialogs.length > 1) {
  7480. K('[name="url"]', div).val(url);
  7481. if (self.afterSelectFile) {
  7482. self.afterSelectFile.call(self, url);
  7483. }
  7484. self.hideDialog();
  7485. }
  7486. }
  7487. });
  7488. });
  7489. });
  7490. } else {
  7491. viewServerBtn.hide();
  7492. }
  7493. urlBox.val(fileUrl);
  7494. titleBox.val(fileTitle);
  7495. urlBox[0].focus();
  7496. urlBox[0].select();
  7497. };
  7498. self.clickToolbar(name, function() {
  7499. self.plugin.fileDialog({
  7500. clickFn : function(url, title) {
  7501. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7502. self.insertHtml(html).hideDialog().focus();
  7503. }
  7504. });
  7505. });
  7506. });
  7507. /*******************************************************************************
  7508. * KindEditor - WYSIWYG HTML Editor for Internet
  7509. * Copyright (C) 2006-2011 kindsoft.net
  7510. *
  7511. * @author Roddy <luolonghao@gmail.com>
  7512. * @site http://www.kindsoft.net/
  7513. * @licence http://www.kindsoft.net/license.php
  7514. *******************************************************************************/
  7515. KindEditor.plugin('lineheight', function(K) {
  7516. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7517. self.clickToolbar(name, function() {
  7518. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7519. if (commonNode) {
  7520. curVal = commonNode.css('line-height');
  7521. }
  7522. var menu = self.createMenu({
  7523. name : name,
  7524. width : 150
  7525. });
  7526. K.each(lang.lineHeight, function(i, row) {
  7527. K.each(row, function(key, val) {
  7528. menu.addItem({
  7529. title : val,
  7530. checked : curVal === key,
  7531. click : function() {
  7532. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7533. span : '.line-height=' + key
  7534. });
  7535. self.updateState();
  7536. self.addBookmark();
  7537. self.hideMenu();
  7538. }
  7539. });
  7540. });
  7541. });
  7542. });
  7543. });
  7544. /*******************************************************************************
  7545. * KindEditor - WYSIWYG HTML Editor for Internet
  7546. * Copyright (C) 2006-2011 kindsoft.net
  7547. *
  7548. * @author Roddy <luolonghao@gmail.com>
  7549. * @site http://www.kindsoft.net/
  7550. * @licence http://www.kindsoft.net/license.php
  7551. *******************************************************************************/
  7552. KindEditor.plugin('link', function(K) {
  7553. var self = this, name = 'link';
  7554. self.plugin.link = {
  7555. edit : function() {
  7556. var lang = self.lang(name + '.'),
  7557. html = '<div style="padding:20px;">' +
  7558. '<div class="ke-dialog-row">' +
  7559. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7560. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7561. '<div class="ke-dialog-row"">' +
  7562. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7563. '<select id="keType" name="type"></select>' +
  7564. '</div>' +
  7565. '</div>',
  7566. dialog = self.createDialog({
  7567. name : name,
  7568. width : 450,
  7569. title : self.lang(name),
  7570. body : html,
  7571. yesBtn : {
  7572. name : self.lang('yes'),
  7573. click : function(e) {
  7574. var url = K.trim(urlBox.val());
  7575. if (url == 'http://' || K.invalidUrl(url)) {
  7576. alert(self.lang('invalidUrl'));
  7577. urlBox[0].focus();
  7578. return;
  7579. }
  7580. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7581. }
  7582. }
  7583. }),
  7584. div = dialog.div,
  7585. urlBox = K('input[name="url"]', div),
  7586. typeBox = K('select[name="type"]', div);
  7587. urlBox.val('http://');
  7588. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7589. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7590. self.cmd.selection();
  7591. var a = self.plugin.getSelectedLink();
  7592. if (a) {
  7593. self.cmd.range.selectNode(a[0]);
  7594. self.cmd.select();
  7595. urlBox.val(a.attr('data-ke-src'));
  7596. typeBox.val(a.attr('target'));
  7597. }
  7598. urlBox[0].focus();
  7599. urlBox[0].select();
  7600. },
  7601. 'delete' : function() {
  7602. self.exec('unlink', null);
  7603. }
  7604. };
  7605. self.clickToolbar(name, self.plugin.link.edit);
  7606. });
  7607. /*******************************************************************************
  7608. * KindEditor - WYSIWYG HTML Editor for Internet
  7609. * Copyright (C) 2006-2011 kindsoft.net
  7610. *
  7611. * @author Roddy <luolonghao@gmail.com>
  7612. * @site http://www.kindsoft.net/
  7613. * @licence http://www.kindsoft.net/license.php
  7614. *******************************************************************************/
  7615. KindEditor.plugin('media', function(K) {
  7616. var self = this, name = 'media', lang = self.lang(name + '.'),
  7617. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7618. allowFileManager = K.undef(self.allowFileManager, false),
  7619. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7620. extraParams = K.undef(self.extraFileUploadParams, {}),
  7621. filePostName = K.undef(self.filePostName, 'imgFile'),
  7622. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7623. self.plugin.media = {
  7624. edit : function() {
  7625. var html = [
  7626. '<div style="padding:20px;">',
  7627. '<div class="ke-dialog-row">',
  7628. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7629. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7630. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7631. '<span class="ke-button-common ke-button-outer">',
  7632. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7633. '</span>',
  7634. '</div>',
  7635. '<div class="ke-dialog-row">',
  7636. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7637. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7638. '</div>',
  7639. '<div class="ke-dialog-row">',
  7640. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7641. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7642. '</div>',
  7643. '<div class="ke-dialog-row">',
  7644. '<label for="keAutostart">' + lang.autostart + '</label>',
  7645. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7646. '</div>',
  7647. '</div>'
  7648. ].join('');
  7649. var dialog = self.createDialog({
  7650. name : name,
  7651. width : 450,
  7652. height : 230,
  7653. title : self.lang(name),
  7654. body : html,
  7655. yesBtn : {
  7656. name : self.lang('yes'),
  7657. click : function(e) {
  7658. var url = K.trim(urlBox.val()),
  7659. width = widthBox.val(),
  7660. height = heightBox.val();
  7661. if (url == 'http://' || K.invalidUrl(url)) {
  7662. alert(self.lang('invalidUrl'));
  7663. urlBox[0].focus();
  7664. return;
  7665. }
  7666. if (!/^\d*$/.test(width)) {
  7667. alert(self.lang('invalidWidth'));
  7668. widthBox[0].focus();
  7669. return;
  7670. }
  7671. if (!/^\d*$/.test(height)) {
  7672. alert(self.lang('invalidHeight'));
  7673. heightBox[0].focus();
  7674. return;
  7675. }
  7676. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7677. src : url,
  7678. type : K.mediaType(url),
  7679. width : width,
  7680. height : height,
  7681. autostart : autostartBox[0].checked ? 'true' : 'false',
  7682. loop : 'true'
  7683. });
  7684. self.insertHtml(html).hideDialog().focus();
  7685. }
  7686. }
  7687. }),
  7688. div = dialog.div,
  7689. urlBox = K('[name="url"]', div),
  7690. viewServerBtn = K('[name="viewServer"]', div),
  7691. widthBox = K('[name="width"]', div),
  7692. heightBox = K('[name="height"]', div),
  7693. autostartBox = K('[name="autostart"]', div);
  7694. urlBox.val('http://');
  7695. if (allowMediaUpload) {
  7696. var uploadbutton = K.uploadbutton({
  7697. button : K('.ke-upload-button', div)[0],
  7698. fieldName : filePostName,
  7699. extraParams : extraParams,
  7700. url : K.addParam(uploadJson, 'dir=media'),
  7701. afterUpload : function(data) {
  7702. dialog.hideLoading();
  7703. if (data.error === 0) {
  7704. var url = data.url;
  7705. if (formatUploadUrl) {
  7706. url = K.formatUrl(url, 'absolute');
  7707. }
  7708. urlBox.val(url);
  7709. if (self.afterUpload) {
  7710. self.afterUpload.call(self, url, data, name);
  7711. }
  7712. alert(self.lang('uploadSuccess'));
  7713. } else {
  7714. alert(data.message);
  7715. }
  7716. },
  7717. afterError : function(html) {
  7718. dialog.hideLoading();
  7719. self.errorDialog(html);
  7720. }
  7721. });
  7722. uploadbutton.fileBox.change(function(e) {
  7723. dialog.showLoading(self.lang('uploadLoading'));
  7724. uploadbutton.submit();
  7725. });
  7726. } else {
  7727. K('.ke-upload-button', div).hide();
  7728. }
  7729. if (allowFileManager) {
  7730. viewServerBtn.click(function(e) {
  7731. self.loadPlugin('filemanager', function() {
  7732. self.plugin.filemanagerDialog({
  7733. viewType : 'LIST',
  7734. dirName : 'media',
  7735. clickFn : function(url, title) {
  7736. if (self.dialogs.length > 1) {
  7737. K('[name="url"]', div).val(url);
  7738. if (self.afterSelectFile) {
  7739. self.afterSelectFile.call(self, url);
  7740. }
  7741. self.hideDialog();
  7742. }
  7743. }
  7744. });
  7745. });
  7746. });
  7747. } else {
  7748. viewServerBtn.hide();
  7749. }
  7750. var img = self.plugin.getSelectedMedia();
  7751. if (img) {
  7752. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7753. urlBox.val(attrs.src);
  7754. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7755. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7756. autostartBox[0].checked = (attrs.autostart === 'true');
  7757. }
  7758. urlBox[0].focus();
  7759. urlBox[0].select();
  7760. },
  7761. 'delete' : function() {
  7762. self.plugin.getSelectedMedia().remove();
  7763. self.addBookmark();
  7764. }
  7765. };
  7766. self.clickToolbar(name, self.plugin.media.edit);
  7767. });
  7768. /*******************************************************************************
  7769. * KindEditor - WYSIWYG HTML Editor for Internet
  7770. * Copyright (C) 2006-2011 kindsoft.net
  7771. *
  7772. * @author Roddy <luolonghao@gmail.com>
  7773. * @site http://www.kindsoft.net/
  7774. * @licence http://www.kindsoft.net/license.php
  7775. *******************************************************************************/
  7776. (function(K) {
  7777. function KSWFUpload(options) {
  7778. this.init(options);
  7779. }
  7780. K.extend(KSWFUpload, {
  7781. init : function(options) {
  7782. var self = this;
  7783. options.afterError = options.afterError || function(str) {
  7784. alert(str);
  7785. };
  7786. self.options = options;
  7787. self.progressbars = {};
  7788. self.div = K(options.container).html([
  7789. '<div class="ke-swfupload">',
  7790. '<div class="ke-swfupload-top">',
  7791. '<div class="ke-inline-block ke-swfupload-button">',
  7792. '<input type="button" value="Browse" />',
  7793. '</div>',
  7794. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7795. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7796. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7797. '</span>',
  7798. '</div>',
  7799. '<div class="ke-swfupload-body"></div>',
  7800. '</div>'
  7801. ].join(''));
  7802. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7803. function showError(itemDiv, msg) {
  7804. K('.ke-status > div', itemDiv).hide();
  7805. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7806. }
  7807. var settings = {
  7808. debug : false,
  7809. upload_url : options.uploadUrl,
  7810. flash_url : options.flashUrl,
  7811. file_post_name : options.filePostName,
  7812. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7813. button_image_url: options.buttonImageUrl,
  7814. button_width: options.buttonWidth,
  7815. button_height: options.buttonHeight,
  7816. button_cursor : SWFUpload.CURSOR.HAND,
  7817. file_types : options.fileTypes,
  7818. file_types_description : options.fileTypesDesc,
  7819. file_upload_limit : options.fileUploadLimit,
  7820. file_size_limit : options.fileSizeLimit,
  7821. post_params : options.postParams,
  7822. file_queued_handler : function(file) {
  7823. file.url = self.options.fileIconUrl;
  7824. self.appendFile(file);
  7825. },
  7826. file_queue_error_handler : function(file, errorCode, message) {
  7827. var errorName = '';
  7828. switch (errorCode) {
  7829. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7830. errorName = options.queueLimitExceeded;
  7831. break;
  7832. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7833. errorName = options.fileExceedsSizeLimit;
  7834. break;
  7835. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7836. errorName = options.zeroByteFile;
  7837. break;
  7838. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7839. errorName = options.invalidFiletype;
  7840. break;
  7841. default:
  7842. errorName = options.unknownError;
  7843. break;
  7844. }
  7845. K.DEBUG && alert(errorName);
  7846. },
  7847. upload_start_handler : function(file) {
  7848. var self = this;
  7849. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7850. K('.ke-status > div', itemDiv).hide();
  7851. K('.ke-progressbar', itemDiv).show();
  7852. },
  7853. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7854. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7855. var progressbar = self.progressbars[file.id];
  7856. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7857. progressbar.percent.html(percent + '%');
  7858. },
  7859. upload_error_handler : function(file, errorCode, message) {
  7860. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7861. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7862. showError(itemDiv, self.options.errorMessage);
  7863. }
  7864. },
  7865. upload_success_handler : function(file, serverData) {
  7866. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7867. var data = {};
  7868. try {
  7869. data = K.json(serverData);
  7870. } catch (e) {
  7871. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7872. }
  7873. if (data.error !== 0) {
  7874. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7875. return;
  7876. }
  7877. file.url = data.url;
  7878. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7879. K('.ke-status > div', itemDiv).hide();
  7880. }
  7881. };
  7882. self.swfu = new SWFUpload(settings);
  7883. K('.ke-swfupload-startupload input', self.div).click(function() {
  7884. self.swfu.startUpload();
  7885. });
  7886. },
  7887. getUrlList : function() {
  7888. var list = [];
  7889. K('.ke-img', self.bodyDiv).each(function() {
  7890. var img = K(this);
  7891. var status = img.attr('data-status');
  7892. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7893. list.push(img.data('data'));
  7894. }
  7895. });
  7896. return list;
  7897. },
  7898. removeFile : function(fileId) {
  7899. var self = this;
  7900. self.swfu.cancelUpload(fileId);
  7901. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7902. K('.ke-photo', itemDiv).unbind();
  7903. K('.ke-delete', itemDiv).unbind();
  7904. itemDiv.remove();
  7905. },
  7906. removeFiles : function() {
  7907. var self = this;
  7908. K('.ke-item', self.bodyDiv).each(function() {
  7909. self.removeFile(K(this).attr('data-id'));
  7910. });
  7911. },
  7912. appendFile : function(file) {
  7913. var self = this;
  7914. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7915. self.bodyDiv.append(itemDiv);
  7916. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7917. .mouseover(function(e) {
  7918. K(this).addClass('ke-on');
  7919. })
  7920. .mouseout(function(e) {
  7921. K(this).removeClass('ke-on');
  7922. });
  7923. itemDiv.append(photoDiv);
  7924. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7925. photoDiv.append(img);
  7926. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  7927. self.removeFile(file.id);
  7928. });
  7929. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7930. K(['<div class="ke-progressbar">',
  7931. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7932. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7933. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7934. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7935. self.progressbars[file.id] = {
  7936. bar : K('.ke-progressbar-bar-inner', photoDiv),
  7937. percent : K('.ke-progressbar-percent', photoDiv)
  7938. };
  7939. },
  7940. remove : function() {
  7941. this.removeFiles();
  7942. this.swfu.destroy();
  7943. this.div.html('');
  7944. }
  7945. });
  7946. K.swfupload = function(element, options) {
  7947. return new KSWFUpload(element, options);
  7948. };
  7949. })(KindEditor);
  7950. KindEditor.plugin('multiimage', function(K) {
  7951. var self = this, name = 'multiimage',
  7952. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7953. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7954. imgPath = self.pluginsPath + 'multiimage/images/',
  7955. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  7956. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  7957. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  7958. filePostName = K.undef(self.filePostName, 'imgFile'),
  7959. lang = self.lang(name + '.');
  7960. self.plugin.multiImageDialog = function(options) {
  7961. var clickFn = options.clickFn,
  7962. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  7963. var html = [
  7964. '<div style="padding:20px;">',
  7965. '<div class="swfupload">',
  7966. '</div>',
  7967. '</div>'
  7968. ].join('');
  7969. var dialog = self.createDialog({
  7970. name : name,
  7971. width : 650,
  7972. height : 510,
  7973. title : self.lang(name),
  7974. body : html,
  7975. previewBtn : {
  7976. name : lang.insertAll,
  7977. click : function(e) {
  7978. clickFn.call(self, swfupload.getUrlList());
  7979. }
  7980. },
  7981. yesBtn : {
  7982. name : lang.clearAll,
  7983. click : function(e) {
  7984. swfupload.removeFiles();
  7985. }
  7986. },
  7987. beforeRemove : function() {
  7988. if (!K.IE || K.V <= 8) {
  7989. swfupload.remove();
  7990. }
  7991. }
  7992. }),
  7993. div = dialog.div;
  7994. var swfupload = K.swfupload({
  7995. container : K('.swfupload', div),
  7996. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  7997. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  7998. buttonHeight : 23,
  7999. fileIconUrl : imgPath + 'image.png',
  8000. uploadDesc : uploadDesc,
  8001. startButtonValue : lang.startUpload,
  8002. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8003. flashUrl : imgPath + 'swfupload.swf',
  8004. filePostName : filePostName,
  8005. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8006. fileTypesDesc : 'Image Files',
  8007. fileUploadLimit : imageUploadLimit,
  8008. fileSizeLimit : imageSizeLimit,
  8009. postParams : K.undef(self.extraFileUploadParams, {}),
  8010. queueLimitExceeded : lang.queueLimitExceeded,
  8011. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8012. zeroByteFile : lang.zeroByteFile,
  8013. invalidFiletype : lang.invalidFiletype,
  8014. unknownError : lang.unknownError,
  8015. pendingMessage : lang.pending,
  8016. errorMessage : lang.uploadError,
  8017. afterError : function(html) {
  8018. self.errorDialog(html);
  8019. }
  8020. });
  8021. return dialog;
  8022. };
  8023. self.clickToolbar(name, function() {
  8024. self.plugin.multiImageDialog({
  8025. clickFn : function (urlList) {
  8026. if (urlList.length === 0) {
  8027. return;
  8028. }
  8029. K.each(urlList, function(i, data) {
  8030. if (self.afterUpload) {
  8031. self.afterUpload.call(self, data.url, data, 'multiimage');
  8032. }
  8033. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8034. });
  8035. setTimeout(function() {
  8036. self.hideDialog().focus();
  8037. }, 0);
  8038. }
  8039. });
  8040. });
  8041. });
  8042. /* ******************* */
  8043. /* Constructor & Init */
  8044. /* ******************* */
  8045. (function() {
  8046. window.SWFUpload = function (settings) {
  8047. this.initSWFUpload(settings);
  8048. };
  8049. SWFUpload.prototype.initSWFUpload = function (settings) {
  8050. try {
  8051. this.customSettings = {};
  8052. this.settings = settings;
  8053. this.eventQueue = [];
  8054. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8055. this.movieElement = null;
  8056. SWFUpload.instances[this.movieName] = this;
  8057. this.initSettings();
  8058. this.loadFlash();
  8059. this.displayDebugInfo();
  8060. } catch (ex) {
  8061. delete SWFUpload.instances[this.movieName];
  8062. throw ex;
  8063. }
  8064. };
  8065. /* *************** */
  8066. /* Static Members */
  8067. /* *************** */
  8068. SWFUpload.instances = {};
  8069. SWFUpload.movieCount = 0;
  8070. SWFUpload.version = "2.2.0 2009-03-25";
  8071. SWFUpload.QUEUE_ERROR = {
  8072. QUEUE_LIMIT_EXCEEDED : -100,
  8073. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8074. ZERO_BYTE_FILE : -120,
  8075. INVALID_FILETYPE : -130
  8076. };
  8077. SWFUpload.UPLOAD_ERROR = {
  8078. HTTP_ERROR : -200,
  8079. MISSING_UPLOAD_URL : -210,
  8080. IO_ERROR : -220,
  8081. SECURITY_ERROR : -230,
  8082. UPLOAD_LIMIT_EXCEEDED : -240,
  8083. UPLOAD_FAILED : -250,
  8084. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8085. FILE_VALIDATION_FAILED : -270,
  8086. FILE_CANCELLED : -280,
  8087. UPLOAD_STOPPED : -290
  8088. };
  8089. SWFUpload.FILE_STATUS = {
  8090. QUEUED : -1,
  8091. IN_PROGRESS : -2,
  8092. ERROR : -3,
  8093. COMPLETE : -4,
  8094. CANCELLED : -5
  8095. };
  8096. SWFUpload.BUTTON_ACTION = {
  8097. SELECT_FILE : -100,
  8098. SELECT_FILES : -110,
  8099. START_UPLOAD : -120
  8100. };
  8101. SWFUpload.CURSOR = {
  8102. ARROW : -1,
  8103. HAND : -2
  8104. };
  8105. SWFUpload.WINDOW_MODE = {
  8106. WINDOW : "window",
  8107. TRANSPARENT : "transparent",
  8108. OPAQUE : "opaque"
  8109. };
  8110. SWFUpload.completeURL = function(url) {
  8111. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8112. return url;
  8113. }
  8114. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8115. var indexSlash = window.location.pathname.lastIndexOf("/");
  8116. var path;
  8117. if (indexSlash <= 0) {
  8118. path = "/";
  8119. } else {
  8120. path = window.location.pathname.substr(0, indexSlash) + "/";
  8121. }
  8122. return /*currentURL +*/ path + url;
  8123. };
  8124. /* ******************** */
  8125. /* Instance Members */
  8126. /* ******************** */
  8127. SWFUpload.prototype.initSettings = function () {
  8128. this.ensureDefault = function (settingName, defaultValue) {
  8129. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8130. };
  8131. this.ensureDefault("upload_url", "");
  8132. this.ensureDefault("preserve_relative_urls", false);
  8133. this.ensureDefault("file_post_name", "Filedata");
  8134. this.ensureDefault("post_params", {});
  8135. this.ensureDefault("use_query_string", false);
  8136. this.ensureDefault("requeue_on_error", false);
  8137. this.ensureDefault("http_success", []);
  8138. this.ensureDefault("assume_success_timeout", 0);
  8139. this.ensureDefault("file_types", "*.*");
  8140. this.ensureDefault("file_types_description", "All Files");
  8141. this.ensureDefault("file_size_limit", 0);
  8142. this.ensureDefault("file_upload_limit", 0);
  8143. this.ensureDefault("file_queue_limit", 0);
  8144. this.ensureDefault("flash_url", "swfupload.swf");
  8145. this.ensureDefault("prevent_swf_caching", true);
  8146. this.ensureDefault("button_image_url", "");
  8147. this.ensureDefault("button_width", 1);
  8148. this.ensureDefault("button_height", 1);
  8149. this.ensureDefault("button_text", "");
  8150. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8151. this.ensureDefault("button_text_top_padding", 0);
  8152. this.ensureDefault("button_text_left_padding", 0);
  8153. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8154. this.ensureDefault("button_disabled", false);
  8155. this.ensureDefault("button_placeholder_id", "");
  8156. this.ensureDefault("button_placeholder", null);
  8157. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8158. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8159. this.ensureDefault("debug", false);
  8160. this.settings.debug_enabled = this.settings.debug;
  8161. this.settings.return_upload_start_handler = this.returnUploadStart;
  8162. this.ensureDefault("swfupload_loaded_handler", null);
  8163. this.ensureDefault("file_dialog_start_handler", null);
  8164. this.ensureDefault("file_queued_handler", null);
  8165. this.ensureDefault("file_queue_error_handler", null);
  8166. this.ensureDefault("file_dialog_complete_handler", null);
  8167. this.ensureDefault("upload_start_handler", null);
  8168. this.ensureDefault("upload_progress_handler", null);
  8169. this.ensureDefault("upload_error_handler", null);
  8170. this.ensureDefault("upload_success_handler", null);
  8171. this.ensureDefault("upload_complete_handler", null);
  8172. this.ensureDefault("debug_handler", this.debugMessage);
  8173. this.ensureDefault("custom_settings", {});
  8174. this.customSettings = this.settings.custom_settings;
  8175. if (!!this.settings.prevent_swf_caching) {
  8176. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8177. }
  8178. if (!this.settings.preserve_relative_urls) {
  8179. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8180. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8181. }
  8182. delete this.ensureDefault;
  8183. };
  8184. SWFUpload.prototype.loadFlash = function () {
  8185. var targetElement, tempParent;
  8186. if (document.getElementById(this.movieName) !== null) {
  8187. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8188. }
  8189. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8190. if (targetElement == undefined) {
  8191. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8192. }
  8193. tempParent = document.createElement("div");
  8194. tempParent.innerHTML = this.getFlashHTML();
  8195. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8196. if (window[this.movieName] == undefined) {
  8197. window[this.movieName] = this.getMovieElement();
  8198. }
  8199. };
  8200. SWFUpload.prototype.getFlashHTML = function () {
  8201. var classid = '';
  8202. if (KindEditor.IE && KindEditor.V > 8) {
  8203. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8204. }
  8205. 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">',
  8206. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8207. '<param name="movie" value="', this.settings.flash_url, '" />',
  8208. '<param name="quality" value="high" />',
  8209. '<param name="menu" value="false" />',
  8210. '<param name="allowScriptAccess" value="always" />',
  8211. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8212. '</object>'].join("");
  8213. };
  8214. SWFUpload.prototype.getFlashVars = function () {
  8215. var paramString = this.buildParamString();
  8216. var httpSuccessString = this.settings.http_success.join(",");
  8217. return ["movieName=", encodeURIComponent(this.movieName),
  8218. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8219. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8220. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8221. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8222. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8223. "&amp;params=", encodeURIComponent(paramString),
  8224. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8225. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8226. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8227. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8228. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8229. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8230. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8231. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8232. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8233. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8234. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8235. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8236. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8237. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8238. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8239. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8240. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8241. ].join("");
  8242. };
  8243. SWFUpload.prototype.getMovieElement = function () {
  8244. if (this.movieElement == undefined) {
  8245. this.movieElement = document.getElementById(this.movieName);
  8246. }
  8247. if (this.movieElement === null) {
  8248. throw "Could not find Flash element";
  8249. }
  8250. return this.movieElement;
  8251. };
  8252. SWFUpload.prototype.buildParamString = function () {
  8253. var postParams = this.settings.post_params;
  8254. var paramStringPairs = [];
  8255. if (typeof(postParams) === "object") {
  8256. for (var name in postParams) {
  8257. if (postParams.hasOwnProperty(name)) {
  8258. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8259. }
  8260. }
  8261. }
  8262. return paramStringPairs.join("&amp;");
  8263. };
  8264. SWFUpload.prototype.destroy = function () {
  8265. try {
  8266. this.cancelUpload(null, false);
  8267. var movieElement = null;
  8268. movieElement = this.getMovieElement();
  8269. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8270. for (var i in movieElement) {
  8271. try {
  8272. if (typeof(movieElement[i]) === "function") {
  8273. movieElement[i] = null;
  8274. }
  8275. } catch (ex1) {}
  8276. }
  8277. try {
  8278. movieElement.parentNode.removeChild(movieElement);
  8279. } catch (ex) {}
  8280. }
  8281. window[this.movieName] = null;
  8282. SWFUpload.instances[this.movieName] = null;
  8283. delete SWFUpload.instances[this.movieName];
  8284. this.movieElement = null;
  8285. this.settings = null;
  8286. this.customSettings = null;
  8287. this.eventQueue = null;
  8288. this.movieName = null;
  8289. return true;
  8290. } catch (ex2) {
  8291. return false;
  8292. }
  8293. };
  8294. SWFUpload.prototype.displayDebugInfo = function () {
  8295. this.debug(
  8296. [
  8297. "---SWFUpload Instance Info---\n",
  8298. "Version: ", SWFUpload.version, "\n",
  8299. "Movie Name: ", this.movieName, "\n",
  8300. "Settings:\n",
  8301. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8302. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8303. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8304. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8305. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8306. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8307. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8308. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8309. "\t", "file_types: ", this.settings.file_types, "\n",
  8310. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8311. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8312. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8313. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8314. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8315. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8316. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8317. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8318. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8319. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8320. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8321. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8322. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8323. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8324. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8325. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8326. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8327. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8328. "Event Handlers:\n",
  8329. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8330. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8331. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8332. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8333. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8334. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8335. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8336. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8337. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8338. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8339. ].join("")
  8340. );
  8341. };
  8342. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8343. the maintain v2 API compatibility
  8344. */
  8345. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8346. if (value == undefined) {
  8347. return (this.settings[name] = default_value);
  8348. } else {
  8349. return (this.settings[name] = value);
  8350. }
  8351. };
  8352. SWFUpload.prototype.getSetting = function (name) {
  8353. if (this.settings[name] != undefined) {
  8354. return this.settings[name];
  8355. }
  8356. return "";
  8357. };
  8358. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8359. argumentArray = argumentArray || [];
  8360. var movieElement = this.getMovieElement();
  8361. var returnValue, returnString;
  8362. try {
  8363. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8364. returnValue = eval(returnString);
  8365. } catch (ex) {
  8366. throw "Call to " + functionName + " failed";
  8367. }
  8368. if (returnValue != undefined && typeof returnValue.post === "object") {
  8369. returnValue = this.unescapeFilePostParams(returnValue);
  8370. }
  8371. return returnValue;
  8372. };
  8373. /* *****************************
  8374. -- Flash control methods --
  8375. Your UI should use these
  8376. to operate SWFUpload
  8377. ***************************** */
  8378. SWFUpload.prototype.selectFile = function () {
  8379. this.callFlash("SelectFile");
  8380. };
  8381. SWFUpload.prototype.selectFiles = function () {
  8382. this.callFlash("SelectFiles");
  8383. };
  8384. SWFUpload.prototype.startUpload = function (fileID) {
  8385. this.callFlash("StartUpload", [fileID]);
  8386. };
  8387. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8388. if (triggerErrorEvent !== false) {
  8389. triggerErrorEvent = true;
  8390. }
  8391. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8392. };
  8393. SWFUpload.prototype.stopUpload = function () {
  8394. this.callFlash("StopUpload");
  8395. };
  8396. /* ************************
  8397. * Settings methods
  8398. * These methods change the SWFUpload settings.
  8399. * SWFUpload settings should not be changed directly on the settings object
  8400. * since many of the settings need to be passed to Flash in order to take
  8401. * effect.
  8402. * *********************** */
  8403. SWFUpload.prototype.getStats = function () {
  8404. return this.callFlash("GetStats");
  8405. };
  8406. SWFUpload.prototype.setStats = function (statsObject) {
  8407. this.callFlash("SetStats", [statsObject]);
  8408. };
  8409. SWFUpload.prototype.getFile = function (fileID) {
  8410. if (typeof(fileID) === "number") {
  8411. return this.callFlash("GetFileByIndex", [fileID]);
  8412. } else {
  8413. return this.callFlash("GetFile", [fileID]);
  8414. }
  8415. };
  8416. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8417. return this.callFlash("AddFileParam", [fileID, name, value]);
  8418. };
  8419. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8420. this.callFlash("RemoveFileParam", [fileID, name]);
  8421. };
  8422. SWFUpload.prototype.setUploadURL = function (url) {
  8423. this.settings.upload_url = url.toString();
  8424. this.callFlash("SetUploadURL", [url]);
  8425. };
  8426. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8427. this.settings.post_params = paramsObject;
  8428. this.callFlash("SetPostParams", [paramsObject]);
  8429. };
  8430. SWFUpload.prototype.addPostParam = function (name, value) {
  8431. this.settings.post_params[name] = value;
  8432. this.callFlash("SetPostParams", [this.settings.post_params]);
  8433. };
  8434. SWFUpload.prototype.removePostParam = function (name) {
  8435. delete this.settings.post_params[name];
  8436. this.callFlash("SetPostParams", [this.settings.post_params]);
  8437. };
  8438. SWFUpload.prototype.setFileTypes = function (types, description) {
  8439. this.settings.file_types = types;
  8440. this.settings.file_types_description = description;
  8441. this.callFlash("SetFileTypes", [types, description]);
  8442. };
  8443. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8444. this.settings.file_size_limit = fileSizeLimit;
  8445. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8446. };
  8447. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8448. this.settings.file_upload_limit = fileUploadLimit;
  8449. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8450. };
  8451. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8452. this.settings.file_queue_limit = fileQueueLimit;
  8453. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8454. };
  8455. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8456. this.settings.file_post_name = filePostName;
  8457. this.callFlash("SetFilePostName", [filePostName]);
  8458. };
  8459. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8460. this.settings.use_query_string = useQueryString;
  8461. this.callFlash("SetUseQueryString", [useQueryString]);
  8462. };
  8463. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8464. this.settings.requeue_on_error = requeueOnError;
  8465. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8466. };
  8467. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8468. if (typeof http_status_codes === "string") {
  8469. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8470. }
  8471. this.settings.http_success = http_status_codes;
  8472. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8473. };
  8474. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8475. this.settings.assume_success_timeout = timeout_seconds;
  8476. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8477. };
  8478. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8479. this.settings.debug_enabled = debugEnabled;
  8480. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8481. };
  8482. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8483. if (buttonImageURL == undefined) {
  8484. buttonImageURL = "";
  8485. }
  8486. this.settings.button_image_url = buttonImageURL;
  8487. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8488. };
  8489. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8490. this.settings.button_width = width;
  8491. this.settings.button_height = height;
  8492. var movie = this.getMovieElement();
  8493. if (movie != undefined) {
  8494. movie.style.width = width + "px";
  8495. movie.style.height = height + "px";
  8496. }
  8497. this.callFlash("SetButtonDimensions", [width, height]);
  8498. };
  8499. SWFUpload.prototype.setButtonText = function (html) {
  8500. this.settings.button_text = html;
  8501. this.callFlash("SetButtonText", [html]);
  8502. };
  8503. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8504. this.settings.button_text_top_padding = top;
  8505. this.settings.button_text_left_padding = left;
  8506. this.callFlash("SetButtonTextPadding", [left, top]);
  8507. };
  8508. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8509. this.settings.button_text_style = css;
  8510. this.callFlash("SetButtonTextStyle", [css]);
  8511. };
  8512. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8513. this.settings.button_disabled = isDisabled;
  8514. this.callFlash("SetButtonDisabled", [isDisabled]);
  8515. };
  8516. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8517. this.settings.button_action = buttonAction;
  8518. this.callFlash("SetButtonAction", [buttonAction]);
  8519. };
  8520. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8521. this.settings.button_cursor = cursor;
  8522. this.callFlash("SetButtonCursor", [cursor]);
  8523. };
  8524. /* *******************************
  8525. Flash Event Interfaces
  8526. These functions are used by Flash to trigger the various
  8527. events.
  8528. All these functions a Private.
  8529. Because the ExternalInterface library is buggy the event calls
  8530. are added to a queue and the queue then executed by a setTimeout.
  8531. This ensures that events are executed in a determinate order and that
  8532. the ExternalInterface bugs are avoided.
  8533. ******************************* */
  8534. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8535. if (argumentArray == undefined) {
  8536. argumentArray = [];
  8537. } else if (!(argumentArray instanceof Array)) {
  8538. argumentArray = [argumentArray];
  8539. }
  8540. var self = this;
  8541. if (typeof this.settings[handlerName] === "function") {
  8542. this.eventQueue.push(function () {
  8543. this.settings[handlerName].apply(this, argumentArray);
  8544. });
  8545. setTimeout(function () {
  8546. self.executeNextEvent();
  8547. }, 0);
  8548. } else if (this.settings[handlerName] !== null) {
  8549. throw "Event handler " + handlerName + " is unknown or is not a function";
  8550. }
  8551. };
  8552. SWFUpload.prototype.executeNextEvent = function () {
  8553. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8554. if (typeof(f) === "function") {
  8555. f.apply(this);
  8556. }
  8557. };
  8558. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8559. var reg = /[$]([0-9a-f]{4})/i;
  8560. var unescapedPost = {};
  8561. var uk;
  8562. if (file != undefined) {
  8563. for (var k in file.post) {
  8564. if (file.post.hasOwnProperty(k)) {
  8565. uk = k;
  8566. var match;
  8567. while ((match = reg.exec(uk)) !== null) {
  8568. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8569. }
  8570. unescapedPost[uk] = file.post[k];
  8571. }
  8572. }
  8573. file.post = unescapedPost;
  8574. }
  8575. return file;
  8576. };
  8577. SWFUpload.prototype.testExternalInterface = function () {
  8578. try {
  8579. return this.callFlash("TestExternalInterface");
  8580. } catch (ex) {
  8581. return false;
  8582. }
  8583. };
  8584. SWFUpload.prototype.flashReady = function () {
  8585. var movieElement = this.getMovieElement();
  8586. if (!movieElement) {
  8587. this.debug("Flash called back ready but the flash movie can't be found.");
  8588. return;
  8589. }
  8590. this.cleanUp(movieElement);
  8591. this.queueEvent("swfupload_loaded_handler");
  8592. };
  8593. SWFUpload.prototype.cleanUp = function (movieElement) {
  8594. try {
  8595. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8596. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8597. for (var key in movieElement) {
  8598. try {
  8599. if (typeof(movieElement[key]) === "function") {
  8600. movieElement[key] = null;
  8601. }
  8602. } catch (ex) {
  8603. }
  8604. }
  8605. }
  8606. } catch (ex1) {
  8607. }
  8608. window["__flash__removeCallback"] = function (instance, name) {
  8609. try {
  8610. if (instance) {
  8611. instance[name] = null;
  8612. }
  8613. } catch (flashEx) {
  8614. }
  8615. };
  8616. };
  8617. /* This is a chance to do something before the browse window opens */
  8618. SWFUpload.prototype.fileDialogStart = function () {
  8619. this.queueEvent("file_dialog_start_handler");
  8620. };
  8621. /* Called when a file is successfully added to the queue. */
  8622. SWFUpload.prototype.fileQueued = function (file) {
  8623. file = this.unescapeFilePostParams(file);
  8624. this.queueEvent("file_queued_handler", file);
  8625. };
  8626. /* Handle errors that occur when an attempt to queue a file fails. */
  8627. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8628. file = this.unescapeFilePostParams(file);
  8629. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8630. };
  8631. /* Called after the file dialog has closed and the selected files have been queued.
  8632. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8633. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8634. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8635. };
  8636. SWFUpload.prototype.uploadStart = function (file) {
  8637. file = this.unescapeFilePostParams(file);
  8638. this.queueEvent("return_upload_start_handler", file);
  8639. };
  8640. SWFUpload.prototype.returnUploadStart = function (file) {
  8641. var returnValue;
  8642. if (typeof this.settings.upload_start_handler === "function") {
  8643. file = this.unescapeFilePostParams(file);
  8644. returnValue = this.settings.upload_start_handler.call(this, file);
  8645. } else if (this.settings.upload_start_handler != undefined) {
  8646. throw "upload_start_handler must be a function";
  8647. }
  8648. if (returnValue === undefined) {
  8649. returnValue = true;
  8650. }
  8651. returnValue = !!returnValue;
  8652. this.callFlash("ReturnUploadStart", [returnValue]);
  8653. };
  8654. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8655. file = this.unescapeFilePostParams(file);
  8656. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8657. };
  8658. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8659. file = this.unescapeFilePostParams(file);
  8660. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8661. };
  8662. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8663. file = this.unescapeFilePostParams(file);
  8664. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8665. };
  8666. SWFUpload.prototype.uploadComplete = function (file) {
  8667. file = this.unescapeFilePostParams(file);
  8668. this.queueEvent("upload_complete_handler", file);
  8669. };
  8670. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8671. internal debug console. You can override this event and have messages written where you want. */
  8672. SWFUpload.prototype.debug = function (message) {
  8673. this.queueEvent("debug_handler", message);
  8674. };
  8675. /* **********************************
  8676. Debug Console
  8677. The debug console is a self contained, in page location
  8678. for debug message to be sent. The Debug Console adds
  8679. itself to the body if necessary.
  8680. The console is automatically scrolled as messages appear.
  8681. If you are using your own debug handler or when you deploy to production and
  8682. have debug disabled you can remove these functions to reduce the file size
  8683. and complexity.
  8684. ********************************** */
  8685. SWFUpload.prototype.debugMessage = function (message) {
  8686. if (this.settings.debug) {
  8687. var exceptionMessage, exceptionValues = [];
  8688. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8689. for (var key in message) {
  8690. if (message.hasOwnProperty(key)) {
  8691. exceptionValues.push(key + ": " + message[key]);
  8692. }
  8693. }
  8694. exceptionMessage = exceptionValues.join("\n") || "";
  8695. exceptionValues = exceptionMessage.split("\n");
  8696. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8697. SWFUpload.Console.writeLine(exceptionMessage);
  8698. } else {
  8699. SWFUpload.Console.writeLine(message);
  8700. }
  8701. }
  8702. };
  8703. SWFUpload.Console = {};
  8704. SWFUpload.Console.writeLine = function (message) {
  8705. var console, documentForm;
  8706. try {
  8707. console = document.getElementById("SWFUpload_Console");
  8708. if (!console) {
  8709. documentForm = document.createElement("form");
  8710. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8711. console = document.createElement("textarea");
  8712. console.id = "SWFUpload_Console";
  8713. console.style.fontFamily = "monospace";
  8714. console.setAttribute("wrap", "off");
  8715. console.wrap = "off";
  8716. console.style.overflow = "auto";
  8717. console.style.width = "700px";
  8718. console.style.height = "350px";
  8719. console.style.margin = "5px";
  8720. documentForm.appendChild(console);
  8721. }
  8722. console.value += message + "\n";
  8723. console.scrollTop = console.scrollHeight - console.clientHeight;
  8724. } catch (ex) {
  8725. alert("Exception: " + ex.name + " Message: " + ex.message);
  8726. }
  8727. };
  8728. })();
  8729. (function() {
  8730. /*
  8731. Queue Plug-in
  8732. Features:
  8733. *Adds a cancelQueue() method for cancelling the entire queue.
  8734. *All queued files are uploaded when startUpload() is called.
  8735. *If false is returned from uploadComplete then the queue upload is stopped.
  8736. If false is not returned (strict comparison) then the queue upload is continued.
  8737. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8738. Set the event handler with the queue_complete_handler setting.
  8739. */
  8740. if (typeof(SWFUpload) === "function") {
  8741. SWFUpload.queue = {};
  8742. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8743. return function () {
  8744. if (typeof(oldInitSettings) === "function") {
  8745. oldInitSettings.call(this);
  8746. }
  8747. this.queueSettings = {};
  8748. this.queueSettings.queue_cancelled_flag = false;
  8749. this.queueSettings.queue_upload_count = 0;
  8750. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8751. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8752. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8753. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8754. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8755. };
  8756. })(SWFUpload.prototype.initSettings);
  8757. SWFUpload.prototype.startUpload = function (fileID) {
  8758. this.queueSettings.queue_cancelled_flag = false;
  8759. this.callFlash("StartUpload", [fileID]);
  8760. };
  8761. SWFUpload.prototype.cancelQueue = function () {
  8762. this.queueSettings.queue_cancelled_flag = true;
  8763. this.stopUpload();
  8764. var stats = this.getStats();
  8765. while (stats.files_queued > 0) {
  8766. this.cancelUpload();
  8767. stats = this.getStats();
  8768. }
  8769. };
  8770. SWFUpload.queue.uploadStartHandler = function (file) {
  8771. var returnValue;
  8772. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8773. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8774. }
  8775. returnValue = (returnValue === false) ? false : true;
  8776. this.queueSettings.queue_cancelled_flag = !returnValue;
  8777. return returnValue;
  8778. };
  8779. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8780. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8781. var continueUpload;
  8782. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8783. this.queueSettings.queue_upload_count++;
  8784. }
  8785. if (typeof(user_upload_complete_handler) === "function") {
  8786. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8787. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8788. continueUpload = false;
  8789. } else {
  8790. continueUpload = true;
  8791. }
  8792. if (continueUpload) {
  8793. var stats = this.getStats();
  8794. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8795. this.startUpload();
  8796. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8797. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8798. this.queueSettings.queue_upload_count = 0;
  8799. } else {
  8800. this.queueSettings.queue_cancelled_flag = false;
  8801. this.queueSettings.queue_upload_count = 0;
  8802. }
  8803. }
  8804. };
  8805. }
  8806. })();
  8807. /*******************************************************************************
  8808. * KindEditor - WYSIWYG HTML Editor for Internet
  8809. * Copyright (C) 2006-2011 kindsoft.net
  8810. *
  8811. * @author Roddy <luolonghao@gmail.com>
  8812. * @site http://www.kindsoft.net/
  8813. * @licence http://www.kindsoft.net/license.php
  8814. *******************************************************************************/
  8815. KindEditor.plugin('pagebreak', function(K) {
  8816. var self = this;
  8817. var name = 'pagebreak';
  8818. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8819. self.clickToolbar(name, function() {
  8820. var cmd = self.cmd, range = cmd.range;
  8821. self.focus();
  8822. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8823. self.insertHtml(pagebreakHtml + tail);
  8824. if (tail !== '') {
  8825. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8826. range.selectNodeContents(p[0]);
  8827. p.removeAttr('id');
  8828. cmd.select();
  8829. }
  8830. });
  8831. });
  8832. /*******************************************************************************
  8833. * KindEditor - WYSIWYG HTML Editor for Internet
  8834. * Copyright (C) 2006-2011 kindsoft.net
  8835. *
  8836. * @author Roddy <luolonghao@gmail.com>
  8837. * @site http://www.kindsoft.net/
  8838. * @licence http://www.kindsoft.net/license.php
  8839. *******************************************************************************/
  8840. KindEditor.plugin('plainpaste', function(K) {
  8841. var self = this, name = 'plainpaste';
  8842. self.clickToolbar(name, function() {
  8843. var lang = self.lang(name + '.'),
  8844. html = '<div style="padding:10px 20px;">' +
  8845. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  8846. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  8847. '</div>',
  8848. dialog = self.createDialog({
  8849. name : name,
  8850. width : 450,
  8851. title : self.lang(name),
  8852. body : html,
  8853. yesBtn : {
  8854. name : self.lang('yes'),
  8855. click : function(e) {
  8856. var html = textarea.val();
  8857. html = K.escape(html);
  8858. html = html.replace(/ {2}/g, ' &nbsp;');
  8859. if (self.newlineTag == 'p') {
  8860. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  8861. } else {
  8862. html = html.replace(/\n/g, '<br />$&');
  8863. }
  8864. self.insertHtml(html).hideDialog().focus();
  8865. }
  8866. }
  8867. }),
  8868. textarea = K('textarea', dialog.div);
  8869. textarea[0].focus();
  8870. });
  8871. });
  8872. /*******************************************************************************
  8873. * KindEditor - WYSIWYG HTML Editor for Internet
  8874. * Copyright (C) 2006-2011 kindsoft.net
  8875. *
  8876. * @author Roddy <luolonghao@gmail.com>
  8877. * @site http://www.kindsoft.net/
  8878. * @licence http://www.kindsoft.net/license.php
  8879. *******************************************************************************/
  8880. KindEditor.plugin('preview', function(K) {
  8881. var self = this, name = 'preview', undefined;
  8882. self.clickToolbar(name, function() {
  8883. var lang = self.lang(name + '.'),
  8884. html = '<div style="padding:10px 20px;">' +
  8885. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  8886. '</div>',
  8887. dialog = self.createDialog({
  8888. name : name,
  8889. width : 750,
  8890. title : self.lang(name),
  8891. body : html
  8892. }),
  8893. iframe = K('iframe', dialog.div),
  8894. doc = K.iframeDoc(iframe);
  8895. doc.open();
  8896. doc.write(self.fullHtml());
  8897. doc.close();
  8898. K(doc.body).css('background-color', '#FFF');
  8899. iframe[0].contentWindow.focus();
  8900. });
  8901. });
  8902. /*******************************************************************************
  8903. * KindEditor - WYSIWYG HTML Editor for Internet
  8904. * Copyright (C) 2006-2011 kindsoft.net
  8905. *
  8906. * @author Roddy <luolonghao@gmail.com>
  8907. * @site http://www.kindsoft.net/
  8908. * @licence http://www.kindsoft.net/license.php
  8909. *******************************************************************************/
  8910. KindEditor.plugin('quickformat', function(K) {
  8911. var self = this, name = 'quickformat',
  8912. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  8913. function getFirstChild(knode) {
  8914. var child = knode.first();
  8915. while (child && child.first()) {
  8916. child = child.first();
  8917. }
  8918. return child;
  8919. }
  8920. self.clickToolbar(name, function() {
  8921. self.focus();
  8922. var doc = self.edit.doc,
  8923. range = self.cmd.range,
  8924. child = K(doc.body).first(), next,
  8925. nodeList = [], subList = [],
  8926. bookmark = range.createBookmark(true);
  8927. while(child) {
  8928. next = child.next();
  8929. var firstChild = getFirstChild(child);
  8930. if (!firstChild || firstChild.name != 'img') {
  8931. if (blockMap[child.name]) {
  8932. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  8933. child.css('text-indent', '2em');
  8934. } else {
  8935. subList.push(child);
  8936. }
  8937. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  8938. if (subList.length > 0) {
  8939. nodeList.push(subList);
  8940. }
  8941. subList = [];
  8942. }
  8943. }
  8944. child = next;
  8945. }
  8946. K.each(nodeList, function(i, subList) {
  8947. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  8948. subList[0].before(wrapper);
  8949. K.each(subList, function(i, knode) {
  8950. wrapper.append(knode);
  8951. });
  8952. });
  8953. range.moveToBookmark(bookmark);
  8954. self.addBookmark();
  8955. });
  8956. });
  8957. /*******************************************************************************
  8958. * KindEditor - WYSIWYG HTML Editor for Internet
  8959. * Copyright (C) 2006-2011 kindsoft.net
  8960. *
  8961. * @author Roddy <luolonghao@gmail.com>
  8962. * @site http://www.kindsoft.net/
  8963. * @licence http://www.kindsoft.net/license.php
  8964. *******************************************************************************/
  8965. KindEditor.plugin('table', function(K) {
  8966. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  8967. function _setColor(box, color) {
  8968. color = color.toUpperCase();
  8969. box.css('background-color', color);
  8970. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  8971. box.html(color);
  8972. }
  8973. var pickerList = [];
  8974. function _initColorPicker(dialogDiv, colorBox) {
  8975. colorBox.bind('click,mousedown', function(e){
  8976. e.stopPropagation();
  8977. });
  8978. function removePicker() {
  8979. K.each(pickerList, function() {
  8980. this.remove();
  8981. });
  8982. pickerList = [];
  8983. K(document).unbind('click,mousedown', removePicker);
  8984. dialogDiv.unbind('click,mousedown', removePicker);
  8985. }
  8986. colorBox.click(function(e) {
  8987. removePicker();
  8988. var box = K(this),
  8989. pos = box.pos();
  8990. var picker = K.colorpicker({
  8991. x : pos.x,
  8992. y : pos.y + box.height(),
  8993. z : 811214,
  8994. selectedColor : K(this).html(),
  8995. colors : self.colorTable,
  8996. noColor : self.lang('noColor'),
  8997. shadowMode : self.shadowMode,
  8998. click : function(color) {
  8999. _setColor(box, color);
  9000. removePicker();
  9001. }
  9002. });
  9003. pickerList.push(picker);
  9004. K(document).bind('click,mousedown', removePicker);
  9005. dialogDiv.bind('click,mousedown', removePicker);
  9006. });
  9007. }
  9008. function _getCellIndex(table, row, cell) {
  9009. var rowSpanCount = 0;
  9010. for (var i = 0, len = row.cells.length; i < len; i++) {
  9011. if (row.cells[i] == cell) {
  9012. break;
  9013. }
  9014. rowSpanCount += row.cells[i].rowSpan - 1;
  9015. }
  9016. return cell.cellIndex - rowSpanCount;
  9017. }
  9018. self.plugin.table = {
  9019. prop : function(isInsert) {
  9020. var html = [
  9021. '<div style="padding:20px;">',
  9022. '<div class="ke-dialog-row">',
  9023. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9024. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9025. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9026. '</div>',
  9027. '<div class="ke-dialog-row">',
  9028. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9029. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9030. '<select name="widthType">',
  9031. '<option value="%">' + lang.percent + '</option>',
  9032. '<option value="px">' + lang.px + '</option>',
  9033. '</select> &nbsp; ',
  9034. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9035. '<select name="heightType">',
  9036. '<option value="%">' + lang.percent + '</option>',
  9037. '<option value="px">' + lang.px + '</option>',
  9038. '</select>',
  9039. '</div>',
  9040. '<div class="ke-dialog-row">',
  9041. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9042. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9043. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9044. '</div>',
  9045. '<div class="ke-dialog-row">',
  9046. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9047. '<select id="keAlign" name="align">',
  9048. '<option value="">' + lang.alignDefault + '</option>',
  9049. '<option value="left">' + lang.alignLeft + '</option>',
  9050. '<option value="center">' + lang.alignCenter + '</option>',
  9051. '<option value="right">' + lang.alignRight + '</option>',
  9052. '</select>',
  9053. '</div>',
  9054. '<div class="ke-dialog-row">',
  9055. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9056. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9057. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9058. '</div>',
  9059. '<div class="ke-dialog-row">',
  9060. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9061. '<span class="ke-inline-block ke-input-color"></span>',
  9062. '</div>',
  9063. '</div>'
  9064. ].join('');
  9065. var bookmark = self.cmd.range.createBookmark();
  9066. var dialog = self.createDialog({
  9067. name : name,
  9068. width : 500,
  9069. title : self.lang(name),
  9070. body : html,
  9071. beforeRemove : function() {
  9072. colorBox.unbind();
  9073. },
  9074. yesBtn : {
  9075. name : self.lang('yes'),
  9076. click : function(e) {
  9077. var rows = rowsBox.val(),
  9078. cols = colsBox.val(),
  9079. width = widthBox.val(),
  9080. height = heightBox.val(),
  9081. widthType = widthTypeBox.val(),
  9082. heightType = heightTypeBox.val(),
  9083. padding = paddingBox.val(),
  9084. spacing = spacingBox.val(),
  9085. align = alignBox.val(),
  9086. border = borderBox.val(),
  9087. borderColor = K(colorBox[0]).html() || '',
  9088. bgColor = K(colorBox[1]).html() || '';
  9089. if (rows == 0 || !/^\d+$/.test(rows)) {
  9090. alert(self.lang('invalidRows'));
  9091. rowsBox[0].focus();
  9092. return;
  9093. }
  9094. if (cols == 0 || !/^\d+$/.test(cols)) {
  9095. alert(self.lang('invalidRows'));
  9096. colsBox[0].focus();
  9097. return;
  9098. }
  9099. if (!/^\d*$/.test(width)) {
  9100. alert(self.lang('invalidWidth'));
  9101. widthBox[0].focus();
  9102. return;
  9103. }
  9104. if (!/^\d*$/.test(height)) {
  9105. alert(self.lang('invalidHeight'));
  9106. heightBox[0].focus();
  9107. return;
  9108. }
  9109. if (!/^\d*$/.test(padding)) {
  9110. alert(self.lang('invalidPadding'));
  9111. paddingBox[0].focus();
  9112. return;
  9113. }
  9114. if (!/^\d*$/.test(spacing)) {
  9115. alert(self.lang('invalidSpacing'));
  9116. spacingBox[0].focus();
  9117. return;
  9118. }
  9119. if (!/^\d*$/.test(border)) {
  9120. alert(self.lang('invalidBorder'));
  9121. borderBox[0].focus();
  9122. return;
  9123. }
  9124. if (table) {
  9125. if (width !== '') {
  9126. table.width(width + widthType);
  9127. } else {
  9128. table.css('width', '');
  9129. }
  9130. if (table[0].width !== undefined) {
  9131. table.removeAttr('width');
  9132. }
  9133. if (height !== '') {
  9134. table.height(height + heightType);
  9135. } else {
  9136. table.css('height', '');
  9137. }
  9138. if (table[0].height !== undefined) {
  9139. table.removeAttr('height');
  9140. }
  9141. table.css('background-color', bgColor);
  9142. if (table[0].bgColor !== undefined) {
  9143. table.removeAttr('bgColor');
  9144. }
  9145. if (padding !== '') {
  9146. table[0].cellPadding = padding;
  9147. } else {
  9148. table.removeAttr('cellPadding');
  9149. }
  9150. if (spacing !== '') {
  9151. table[0].cellSpacing = spacing;
  9152. } else {
  9153. table.removeAttr('cellSpacing');
  9154. }
  9155. if (align !== '') {
  9156. table[0].align = align;
  9157. } else {
  9158. table.removeAttr('align');
  9159. }
  9160. if (border !== '') {
  9161. table.attr('border', border);
  9162. } else {
  9163. table.removeAttr('border');
  9164. }
  9165. if (border === '' || border === '0') {
  9166. table.addClass(zeroborder);
  9167. } else {
  9168. table.removeClass(zeroborder);
  9169. }
  9170. if (borderColor !== '') {
  9171. table.attr('borderColor', borderColor);
  9172. } else {
  9173. table.removeAttr('borderColor');
  9174. }
  9175. self.hideDialog().focus();
  9176. self.cmd.range.moveToBookmark(bookmark);
  9177. self.cmd.select();
  9178. self.addBookmark();
  9179. return;
  9180. }
  9181. var style = '';
  9182. if (width !== '') {
  9183. style += 'width:' + width + widthType + ';';
  9184. }
  9185. if (height !== '') {
  9186. style += 'height:' + height + heightType + ';';
  9187. }
  9188. if (bgColor !== '') {
  9189. style += 'background-color:' + bgColor + ';';
  9190. }
  9191. var html = '<table';
  9192. if (style !== '') {
  9193. html += ' style="' + style + '"';
  9194. }
  9195. if (padding !== '') {
  9196. html += ' cellpadding="' + padding + '"';
  9197. }
  9198. if (spacing !== '') {
  9199. html += ' cellspacing="' + spacing + '"';
  9200. }
  9201. if (align !== '') {
  9202. html += ' align="' + align + '"';
  9203. }
  9204. if (border !== '') {
  9205. html += ' border="' + border + '"';
  9206. }
  9207. if (border === '' || border === '0') {
  9208. html += ' class="' + zeroborder + '"';
  9209. }
  9210. if (borderColor !== '') {
  9211. html += ' bordercolor="' + borderColor + '"';
  9212. }
  9213. html += '>';
  9214. for (var i = 0; i < rows; i++) {
  9215. html += '<tr>';
  9216. for (var j = 0; j < cols; j++) {
  9217. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9218. }
  9219. html += '</tr>';
  9220. }
  9221. html += '</table>';
  9222. if (!K.IE) {
  9223. html += '<br />';
  9224. }
  9225. self.insertHtml(html);
  9226. self.select().hideDialog().focus();
  9227. self.addBookmark();
  9228. }
  9229. }
  9230. }),
  9231. div = dialog.div,
  9232. rowsBox = K('[name="rows"]', div).val(3),
  9233. colsBox = K('[name="cols"]', div).val(2),
  9234. widthBox = K('[name="width"]', div).val(100),
  9235. heightBox = K('[name="height"]', div),
  9236. widthTypeBox = K('[name="widthType"]', div),
  9237. heightTypeBox = K('[name="heightType"]', div),
  9238. paddingBox = K('[name="padding"]', div).val(2),
  9239. spacingBox = K('[name="spacing"]', div).val(0),
  9240. alignBox = K('[name="align"]', div),
  9241. borderBox = K('[name="border"]', div).val(1),
  9242. colorBox = K('.ke-input-color', div);
  9243. _initColorPicker(div, colorBox.eq(0));
  9244. _initColorPicker(div, colorBox.eq(1));
  9245. _setColor(colorBox.eq(0), '#000000');
  9246. _setColor(colorBox.eq(1), '');
  9247. rowsBox[0].focus();
  9248. rowsBox[0].select();
  9249. var table;
  9250. if (isInsert) {
  9251. return;
  9252. }
  9253. table = self.plugin.getSelectedTable();
  9254. if (table) {
  9255. rowsBox.val(table[0].rows.length);
  9256. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9257. rowsBox.attr('disabled', true);
  9258. colsBox.attr('disabled', true);
  9259. var match,
  9260. tableWidth = table[0].style.width || table[0].width,
  9261. tableHeight = table[0].style.height || table[0].height;
  9262. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9263. widthBox.val(match[1]);
  9264. widthTypeBox.val(match[2]);
  9265. } else {
  9266. widthBox.val('');
  9267. }
  9268. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9269. heightBox.val(match[1]);
  9270. heightTypeBox.val(match[2]);
  9271. }
  9272. paddingBox.val(table[0].cellPadding || '');
  9273. spacingBox.val(table[0].cellSpacing || '');
  9274. alignBox.val(table[0].align || '');
  9275. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9276. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9277. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9278. widthBox[0].focus();
  9279. widthBox[0].select();
  9280. }
  9281. },
  9282. cellprop : function() {
  9283. var html = [
  9284. '<div style="padding:20px;">',
  9285. '<div class="ke-dialog-row">',
  9286. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9287. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9288. '<select name="widthType">',
  9289. '<option value="%">' + lang.percent + '</option>',
  9290. '<option value="px">' + lang.px + '</option>',
  9291. '</select> &nbsp; ',
  9292. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9293. '<select name="heightType">',
  9294. '<option value="%">' + lang.percent + '</option>',
  9295. '<option value="px">' + lang.px + '</option>',
  9296. '</select>',
  9297. '</div>',
  9298. '<div class="ke-dialog-row">',
  9299. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9300. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9301. '<option value="">' + lang.alignDefault + '</option>',
  9302. '<option value="left">' + lang.alignLeft + '</option>',
  9303. '<option value="center">' + lang.alignCenter + '</option>',
  9304. '<option value="right">' + lang.alignRight + '</option>',
  9305. '</select> ',
  9306. lang.verticalAlign + ' <select name="verticalAlign">',
  9307. '<option value="">' + lang.alignDefault + '</option>',
  9308. '<option value="top">' + lang.alignTop + '</option>',
  9309. '<option value="middle">' + lang.alignMiddle + '</option>',
  9310. '<option value="bottom">' + lang.alignBottom + '</option>',
  9311. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9312. '</select>',
  9313. '</div>',
  9314. '<div class="ke-dialog-row">',
  9315. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9316. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9317. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9318. '</div>',
  9319. '<div class="ke-dialog-row">',
  9320. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9321. '<span class="ke-inline-block ke-input-color"></span>',
  9322. '</div>',
  9323. '</div>'
  9324. ].join('');
  9325. var bookmark = self.cmd.range.createBookmark();
  9326. var dialog = self.createDialog({
  9327. name : name,
  9328. width : 500,
  9329. title : self.lang('tablecell'),
  9330. body : html,
  9331. beforeRemove : function() {
  9332. colorBox.unbind();
  9333. },
  9334. yesBtn : {
  9335. name : self.lang('yes'),
  9336. click : function(e) {
  9337. var width = widthBox.val(),
  9338. height = heightBox.val(),
  9339. widthType = widthTypeBox.val(),
  9340. heightType = heightTypeBox.val(),
  9341. padding = paddingBox.val(),
  9342. spacing = spacingBox.val(),
  9343. textAlign = textAlignBox.val(),
  9344. verticalAlign = verticalAlignBox.val(),
  9345. border = borderBox.val(),
  9346. borderColor = K(colorBox[0]).html() || '',
  9347. bgColor = K(colorBox[1]).html() || '';
  9348. if (!/^\d*$/.test(width)) {
  9349. alert(self.lang('invalidWidth'));
  9350. widthBox[0].focus();
  9351. return;
  9352. }
  9353. if (!/^\d*$/.test(height)) {
  9354. alert(self.lang('invalidHeight'));
  9355. heightBox[0].focus();
  9356. return;
  9357. }
  9358. if (!/^\d*$/.test(border)) {
  9359. alert(self.lang('invalidBorder'));
  9360. borderBox[0].focus();
  9361. return;
  9362. }
  9363. cell.css({
  9364. width : width !== '' ? (width + widthType) : '',
  9365. height : height !== '' ? (height + heightType) : '',
  9366. 'background-color' : bgColor,
  9367. 'text-align' : textAlign,
  9368. 'vertical-align' : verticalAlign,
  9369. 'border-width' : border,
  9370. 'border-style' : border !== '' ? 'solid' : '',
  9371. 'border-color' : borderColor
  9372. });
  9373. self.hideDialog().focus();
  9374. self.cmd.range.moveToBookmark(bookmark);
  9375. self.cmd.select();
  9376. self.addBookmark();
  9377. }
  9378. }
  9379. }),
  9380. div = dialog.div,
  9381. widthBox = K('[name="width"]', div).val(100),
  9382. heightBox = K('[name="height"]', div),
  9383. widthTypeBox = K('[name="widthType"]', div),
  9384. heightTypeBox = K('[name="heightType"]', div),
  9385. paddingBox = K('[name="padding"]', div).val(2),
  9386. spacingBox = K('[name="spacing"]', div).val(0),
  9387. textAlignBox = K('[name="textAlign"]', div),
  9388. verticalAlignBox = K('[name="verticalAlign"]', div),
  9389. borderBox = K('[name="border"]', div).val(1),
  9390. colorBox = K('.ke-input-color', div);
  9391. _initColorPicker(div, colorBox.eq(0));
  9392. _initColorPicker(div, colorBox.eq(1));
  9393. _setColor(colorBox.eq(0), '#000000');
  9394. _setColor(colorBox.eq(1), '');
  9395. widthBox[0].focus();
  9396. widthBox[0].select();
  9397. var cell = self.plugin.getSelectedCell();
  9398. var match,
  9399. cellWidth = cell[0].style.width || cell[0].width || '',
  9400. cellHeight = cell[0].style.height || cell[0].height || '';
  9401. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9402. widthBox.val(match[1]);
  9403. widthTypeBox.val(match[2]);
  9404. } else {
  9405. widthBox.val('');
  9406. }
  9407. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9408. heightBox.val(match[1]);
  9409. heightTypeBox.val(match[2]);
  9410. }
  9411. textAlignBox.val(cell[0].style.textAlign || '');
  9412. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9413. var border = cell[0].style.borderWidth || '';
  9414. if (border) {
  9415. border = parseInt(border);
  9416. }
  9417. borderBox.val(border);
  9418. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9419. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9420. widthBox[0].focus();
  9421. widthBox[0].select();
  9422. },
  9423. insert : function() {
  9424. this.prop(true);
  9425. },
  9426. 'delete' : function() {
  9427. var table = self.plugin.getSelectedTable();
  9428. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9429. self.cmd.select();
  9430. table.remove();
  9431. self.addBookmark();
  9432. },
  9433. colinsert : function(offset) {
  9434. var table = self.plugin.getSelectedTable()[0],
  9435. row = self.plugin.getSelectedRow()[0],
  9436. cell = self.plugin.getSelectedCell()[0],
  9437. index = cell.cellIndex + offset;
  9438. index += table.rows[0].cells.length - row.cells.length;
  9439. for (var i = 0, len = table.rows.length; i < len; i++) {
  9440. var newRow = table.rows[i],
  9441. newCell = newRow.insertCell(index);
  9442. newCell.innerHTML = K.IE ? '' : '<br />';
  9443. index = _getCellIndex(table, newRow, newCell);
  9444. }
  9445. self.cmd.range.selectNodeContents(cell).collapse(true);
  9446. self.cmd.select();
  9447. self.addBookmark();
  9448. },
  9449. colinsertleft : function() {
  9450. this.colinsert(0);
  9451. },
  9452. colinsertright : function() {
  9453. this.colinsert(1);
  9454. },
  9455. rowinsert : function(offset) {
  9456. var table = self.plugin.getSelectedTable()[0],
  9457. row = self.plugin.getSelectedRow()[0],
  9458. cell = self.plugin.getSelectedCell()[0];
  9459. var rowIndex = row.rowIndex;
  9460. if (offset === 1) {
  9461. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9462. }
  9463. var newRow = table.insertRow(rowIndex);
  9464. for (var i = 0, len = row.cells.length; i < len; i++) {
  9465. if (row.cells[i].rowSpan > 1) {
  9466. len -= row.cells[i].rowSpan - 1;
  9467. }
  9468. var newCell = newRow.insertCell(i);
  9469. if (offset === 1 && row.cells[i].colSpan > 1) {
  9470. newCell.colSpan = row.cells[i].colSpan;
  9471. }
  9472. newCell.innerHTML = K.IE ? '' : '<br />';
  9473. }
  9474. for (var j = rowIndex; j >= 0; j--) {
  9475. var cells = table.rows[j].cells;
  9476. if (cells.length > i) {
  9477. for (var k = cell.cellIndex; k >= 0; k--) {
  9478. if (cells[k].rowSpan > 1) {
  9479. cells[k].rowSpan += 1;
  9480. }
  9481. }
  9482. break;
  9483. }
  9484. }
  9485. self.cmd.range.selectNodeContents(cell).collapse(true);
  9486. self.cmd.select();
  9487. self.addBookmark();
  9488. },
  9489. rowinsertabove : function() {
  9490. this.rowinsert(0);
  9491. },
  9492. rowinsertbelow : function() {
  9493. this.rowinsert(1);
  9494. },
  9495. rowmerge : function() {
  9496. var table = self.plugin.getSelectedTable()[0],
  9497. row = self.plugin.getSelectedRow()[0],
  9498. cell = self.plugin.getSelectedCell()[0],
  9499. rowIndex = row.rowIndex,
  9500. nextRowIndex = rowIndex + cell.rowSpan,
  9501. nextRow = table.rows[nextRowIndex];
  9502. if (table.rows.length <= nextRowIndex) {
  9503. return;
  9504. }
  9505. var cellIndex = cell.cellIndex;
  9506. if (nextRow.cells.length <= cellIndex) {
  9507. return;
  9508. }
  9509. var nextCell = nextRow.cells[cellIndex];
  9510. if (cell.colSpan !== nextCell.colSpan) {
  9511. return;
  9512. }
  9513. cell.rowSpan += nextCell.rowSpan;
  9514. nextRow.deleteCell(cellIndex);
  9515. self.cmd.range.selectNodeContents(cell).collapse(true);
  9516. self.cmd.select();
  9517. self.addBookmark();
  9518. },
  9519. colmerge : function() {
  9520. var table = self.plugin.getSelectedTable()[0],
  9521. row = self.plugin.getSelectedRow()[0],
  9522. cell = self.plugin.getSelectedCell()[0],
  9523. rowIndex = row.rowIndex,
  9524. cellIndex = cell.cellIndex,
  9525. nextCellIndex = cellIndex + 1;
  9526. if (row.cells.length <= nextCellIndex) {
  9527. return;
  9528. }
  9529. var nextCell = row.cells[nextCellIndex];
  9530. if (cell.rowSpan !== nextCell.rowSpan) {
  9531. return;
  9532. }
  9533. cell.colSpan += nextCell.colSpan;
  9534. row.deleteCell(nextCellIndex);
  9535. self.cmd.range.selectNodeContents(cell).collapse(true);
  9536. self.cmd.select();
  9537. self.addBookmark();
  9538. },
  9539. rowsplit : function() {
  9540. var table = self.plugin.getSelectedTable()[0],
  9541. row = self.plugin.getSelectedRow()[0],
  9542. cell = self.plugin.getSelectedCell()[0],
  9543. rowIndex = row.rowIndex;
  9544. if (cell.rowSpan === 1) {
  9545. return;
  9546. }
  9547. var cellIndex = _getCellIndex(table, row, cell);
  9548. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9549. var newRow = table.rows[rowIndex + i],
  9550. newCell = newRow.insertCell(cellIndex);
  9551. if (cell.colSpan > 1) {
  9552. newCell.colSpan = cell.colSpan;
  9553. }
  9554. newCell.innerHTML = K.IE ? '' : '<br />';
  9555. cellIndex = _getCellIndex(table, newRow, newCell);
  9556. }
  9557. K(cell).removeAttr('rowSpan');
  9558. self.cmd.range.selectNodeContents(cell).collapse(true);
  9559. self.cmd.select();
  9560. self.addBookmark();
  9561. },
  9562. colsplit : function() {
  9563. var table = self.plugin.getSelectedTable()[0],
  9564. row = self.plugin.getSelectedRow()[0],
  9565. cell = self.plugin.getSelectedCell()[0],
  9566. cellIndex = cell.cellIndex;
  9567. if (cell.colSpan === 1) {
  9568. return;
  9569. }
  9570. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9571. var newCell = row.insertCell(cellIndex + i);
  9572. if (cell.rowSpan > 1) {
  9573. newCell.rowSpan = cell.rowSpan;
  9574. }
  9575. newCell.innerHTML = K.IE ? '' : '<br />';
  9576. }
  9577. K(cell).removeAttr('colSpan');
  9578. self.cmd.range.selectNodeContents(cell).collapse(true);
  9579. self.cmd.select();
  9580. self.addBookmark();
  9581. },
  9582. coldelete : function() {
  9583. var table = self.plugin.getSelectedTable()[0],
  9584. row = self.plugin.getSelectedRow()[0],
  9585. cell = self.plugin.getSelectedCell()[0],
  9586. index = cell.cellIndex;
  9587. for (var i = 0, len = table.rows.length; i < len; i++) {
  9588. var newRow = table.rows[i],
  9589. newCell = newRow.cells[index];
  9590. if (newCell.colSpan > 1) {
  9591. newCell.colSpan -= 1;
  9592. if (newCell.colSpan === 1) {
  9593. K(newCell).removeAttr('colSpan');
  9594. }
  9595. } else {
  9596. newRow.deleteCell(index);
  9597. }
  9598. if (newCell.rowSpan > 1) {
  9599. i += newCell.rowSpan - 1;
  9600. }
  9601. }
  9602. if (row.cells.length === 0) {
  9603. self.cmd.range.setStartBefore(table).collapse(true);
  9604. self.cmd.select();
  9605. K(table).remove();
  9606. } else {
  9607. self.cmd.selection(true);
  9608. }
  9609. self.addBookmark();
  9610. },
  9611. rowdelete : function() {
  9612. var table = self.plugin.getSelectedTable()[0],
  9613. row = self.plugin.getSelectedRow()[0],
  9614. cell = self.plugin.getSelectedCell()[0],
  9615. rowIndex = row.rowIndex;
  9616. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9617. table.deleteRow(rowIndex + i);
  9618. }
  9619. if (table.rows.length === 0) {
  9620. self.cmd.range.setStartBefore(table).collapse(true);
  9621. self.cmd.select();
  9622. K(table).remove();
  9623. } else {
  9624. self.cmd.selection(true);
  9625. }
  9626. self.addBookmark();
  9627. }
  9628. };
  9629. self.clickToolbar(name, self.plugin.table.prop);
  9630. });
  9631. /*******************************************************************************
  9632. * KindEditor - WYSIWYG HTML Editor for Internet
  9633. * Copyright (C) 2006-2011 kindsoft.net
  9634. *
  9635. * @author Roddy <luolonghao@gmail.com>
  9636. * @site http://www.kindsoft.net/
  9637. * @licence http://www.kindsoft.net/license.php
  9638. *******************************************************************************/
  9639. KindEditor.plugin('template', function(K) {
  9640. var self = this, name = 'template', lang = self.lang(name + '.'),
  9641. htmlPath = self.pluginsPath + name + '/html/';
  9642. function getFilePath(fileName) {
  9643. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9644. }
  9645. self.clickToolbar(name, function() {
  9646. var lang = self.lang(name + '.'),
  9647. arr = ['<div style="padding:10px 20px;">',
  9648. '<div class="ke-header">',
  9649. '<div class="ke-left">',
  9650. lang. selectTemplate + ' <select>'];
  9651. K.each(lang.fileList, function(key, val) {
  9652. arr.push('<option value="' + key + '">' + val + '</option>');
  9653. });
  9654. html = [arr.join(''),
  9655. '</select></div>',
  9656. '<div class="ke-right">',
  9657. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9658. '</div>',
  9659. '<div class="ke-clearfix"></div>',
  9660. '</div>',
  9661. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9662. '</div>'].join('');
  9663. var dialog = self.createDialog({
  9664. name : name,
  9665. width : 500,
  9666. title : self.lang(name),
  9667. body : html,
  9668. yesBtn : {
  9669. name : self.lang('yes'),
  9670. click : function(e) {
  9671. var doc = K.iframeDoc(iframe);
  9672. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9673. }
  9674. }
  9675. });
  9676. var selectBox = K('select', dialog.div),
  9677. checkbox = K('[name="replaceFlag"]', dialog.div),
  9678. iframe = K('iframe', dialog.div);
  9679. checkbox[0].checked = true;
  9680. iframe.attr('src', getFilePath(selectBox.val()));
  9681. selectBox.change(function() {
  9682. iframe.attr('src', getFilePath(this.value));
  9683. });
  9684. });
  9685. });
  9686. /*******************************************************************************
  9687. * KindEditor - WYSIWYG HTML Editor for Internet
  9688. * Copyright (C) 2006-2011 kindsoft.net
  9689. *
  9690. * @author Roddy <luolonghao@gmail.com>
  9691. * @site http://www.kindsoft.net/
  9692. * @licence http://www.kindsoft.net/license.php
  9693. *******************************************************************************/
  9694. KindEditor.plugin('wordpaste', function(K) {
  9695. var self = this, name = 'wordpaste';
  9696. self.clickToolbar(name, function() {
  9697. var lang = self.lang(name + '.'),
  9698. html = '<div style="padding:10px 20px;">' +
  9699. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9700. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9701. '</div>',
  9702. dialog = self.createDialog({
  9703. name : name,
  9704. width : 450,
  9705. title : self.lang(name),
  9706. body : html,
  9707. yesBtn : {
  9708. name : self.lang('yes'),
  9709. click : function(e) {
  9710. var str = doc.body.innerHTML;
  9711. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9712. self.insertHtml(str).hideDialog().focus();
  9713. }
  9714. }
  9715. }),
  9716. div = dialog.div,
  9717. iframe = K('iframe', div),
  9718. doc = K.iframeDoc(iframe);
  9719. if (!K.IE) {
  9720. doc.designMode = 'on';
  9721. }
  9722. doc.open();
  9723. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9724. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9725. if (!K.IE) {
  9726. doc.write('<br />');
  9727. }
  9728. doc.write('</body></html>');
  9729. doc.close();
  9730. if (K.IE) {
  9731. doc.body.contentEditable = 'true';
  9732. }
  9733. iframe[0].contentWindow.focus();
  9734. });
  9735. });
  9736. KindEditor.plugin('fixtoolbar', function (K) {
  9737. var self = this;
  9738. if (!self.fixToolBar) {
  9739. return;
  9740. }
  9741. function init() {
  9742. var toolbar = K('.ke-toolbar');
  9743. var originY = toolbar.pos().y;
  9744. K(window).bind('scroll', function () {
  9745. if (toolbar.css('position') == 'fixed') {
  9746. if(document.body.scrollTop - originY < 0){
  9747. toolbar.css('position', 'static');
  9748. toolbar.css('top', 'auto');
  9749. }
  9750. } else {
  9751. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9752. toolbar.css('position', 'fixed');
  9753. toolbar.css('top', 0);
  9754. }
  9755. }
  9756. });
  9757. }
  9758. if (self.isCreated) {
  9759. init();
  9760. } else {
  9761. self.afterCreate(init);
  9762. }
  9763. });