kindeditor-all.js 296 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2013 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.7 (2013-04-21)
  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.7 (2013-04-21)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  24. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  25. _OPERA = _ua.indexOf('opera') > -1,
  26. _MOBILE = _ua.indexOf('mobile') > -1,
  27. _IOS = /ipad|iphone|ipod/.test(_ua),
  28. _QUIRKS = document.compatMode != 'CSS1Compat',
  29. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  30. _V = _matches ? _matches[1] : '0',
  31. _TIME = new Date().getTime();
  32. function _isArray(val) {
  33. if (!val) {
  34. return false;
  35. }
  36. return Object.prototype.toString.call(val) === '[object Array]';
  37. }
  38. function _isFunction(val) {
  39. if (!val) {
  40. return false;
  41. }
  42. return Object.prototype.toString.call(val) === '[object Function]';
  43. }
  44. function _inArray(val, arr) {
  45. for (var i = 0, len = arr.length; i < len; i++) {
  46. if (val === arr[i]) {
  47. return i;
  48. }
  49. }
  50. return -1;
  51. }
  52. function _each(obj, fn) {
  53. if (_isArray(obj)) {
  54. for (var i = 0, len = obj.length; i < len; i++) {
  55. if (fn.call(obj[i], i, obj[i]) === false) {
  56. break;
  57. }
  58. }
  59. } else {
  60. for (var key in obj) {
  61. if (obj.hasOwnProperty(key)) {
  62. if (fn.call(obj[key], key, obj[key]) === false) {
  63. break;
  64. }
  65. }
  66. }
  67. }
  68. }
  69. function _trim(str) {
  70. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  71. }
  72. function _inString(val, str, delimiter) {
  73. delimiter = delimiter === undefined ? ',' : delimiter;
  74. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  75. }
  76. function _addUnit(val, unit) {
  77. unit = unit || 'px';
  78. return val && /^\d+$/.test(val) ? val + unit : val;
  79. }
  80. function _removeUnit(val) {
  81. var match;
  82. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  83. }
  84. function _escape(val) {
  85. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  86. }
  87. function _unescape(val) {
  88. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  89. }
  90. function _toCamel(str) {
  91. var arr = str.split('-');
  92. str = '';
  93. _each(arr, function(key, val) {
  94. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  95. });
  96. return str;
  97. }
  98. function _toHex(val) {
  99. function hex(d) {
  100. var s = parseInt(d, 10).toString(16).toUpperCase();
  101. return s.length > 1 ? s : '0' + s;
  102. }
  103. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  104. function($0, $1, $2, $3) {
  105. return '#' + hex($1) + hex($2) + hex($3);
  106. }
  107. );
  108. }
  109. function _toMap(val, delimiter) {
  110. delimiter = delimiter === undefined ? ',' : delimiter;
  111. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  112. _each(arr, function(key, val) {
  113. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  114. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  115. map[i.toString()] = true;
  116. }
  117. } else {
  118. map[val] = true;
  119. }
  120. });
  121. return map;
  122. }
  123. function _toArray(obj, offset) {
  124. return Array.prototype.slice.call(obj, offset || 0);
  125. }
  126. function _undef(val, defaultVal) {
  127. return val === undefined ? defaultVal : val;
  128. }
  129. function _invalidUrl(url) {
  130. return !url || /[<>"]/.test(url);
  131. }
  132. function _addParam(url, param) {
  133. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  134. }
  135. function _extend(child, parent, proto) {
  136. if (!proto) {
  137. proto = parent;
  138. parent = null;
  139. }
  140. var childProto;
  141. if (parent) {
  142. var fn = function () {};
  143. fn.prototype = parent.prototype;
  144. childProto = new fn();
  145. _each(proto, function(key, val) {
  146. childProto[key] = val;
  147. });
  148. } else {
  149. childProto = proto;
  150. }
  151. childProto.constructor = child;
  152. child.prototype = childProto;
  153. child.parent = parent ? parent.prototype : null;
  154. }
  155. function _json(text) {
  156. var match;
  157. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  158. text = match[0];
  159. }
  160. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  161. cx.lastIndex = 0;
  162. if (cx.test(text)) {
  163. text = text.replace(cx, function (a) {
  164. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  165. });
  166. }
  167. if (/^[\],:{}\s]*$/.
  168. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  169. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  170. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  171. return eval('(' + text + ')');
  172. }
  173. throw 'JSON parse error';
  174. }
  175. var _round = Math.round;
  176. var K = {
  177. DEBUG : false,
  178. VERSION : _VERSION,
  179. IE : _IE,
  180. GECKO : _GECKO,
  181. WEBKIT : _WEBKIT,
  182. OPERA : _OPERA,
  183. V : _V,
  184. TIME : _TIME,
  185. each : _each,
  186. isArray : _isArray,
  187. isFunction : _isFunction,
  188. inArray : _inArray,
  189. inString : _inString,
  190. trim : _trim,
  191. addUnit : _addUnit,
  192. removeUnit : _removeUnit,
  193. escape : _escape,
  194. unescape : _unescape,
  195. toCamel : _toCamel,
  196. toHex : _toHex,
  197. toMap : _toMap,
  198. toArray : _toArray,
  199. undef : _undef,
  200. invalidUrl : _invalidUrl,
  201. addParam : _addParam,
  202. extend : _extend,
  203. json : _json
  204. };
  205. 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'),
  206. _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'),
  207. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  208. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  209. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  210. _PRE_TAG_MAP = _toMap('pre,style,script'),
  211. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  212. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  213. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  214. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  215. function _getBasePath() {
  216. var els = document.getElementsByTagName('script'), src;
  217. for (var i = 0, len = els.length; i < len; i++) {
  218. src = els[i].src || '';
  219. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  220. return src.substring(0, src.lastIndexOf('/') + 1);
  221. }
  222. }
  223. return '';
  224. }
  225. K.basePath = _getBasePath();
  226. K.options = {
  227. designMode : true,
  228. fullscreenMode : false,
  229. filterMode : true,
  230. wellFormatMode : true,
  231. shadowMode : true,
  232. loadStyleMode : true,
  233. basePath : K.basePath,
  234. themesPath : K.basePath + 'themes/',
  235. langPath : K.basePath + 'lang/',
  236. pluginsPath : K.basePath + 'plugins/',
  237. themeType : 'default',
  238. langType : 'zh_CN',
  239. urlType : '',
  240. newlineTag : 'p',
  241. resizeType : 2,
  242. syncType : 'form',
  243. pasteType : 2,
  244. dialogAlignType : 'page',
  245. useContextmenu : true,
  246. fullscreenShortcut : false,
  247. bodyClass : 'ke-content',
  248. indentChar : '\t',
  249. cssPath : '',
  250. cssData : '',
  251. minWidth : 650,
  252. minHeight : 100,
  253. minChangeSize : 50,
  254. zIndex : 811213,
  255. items : [
  256. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  257. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  258. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  259. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  260. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  261. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  262. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  263. 'anchor', 'link', 'unlink', '|', 'about'
  264. ],
  265. noDisableItems : ['source', 'fullscreen'],
  266. colorTable : [
  267. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  268. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  269. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  270. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  271. ],
  272. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  273. htmlTags : {
  274. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  275. span : [
  276. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  277. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  278. ],
  279. div : [
  280. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  281. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  282. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  283. ],
  284. table: [
  285. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  286. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  287. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  288. '.width', '.height', '.border-collapse'
  289. ],
  290. 'td,th': [
  291. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  292. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  293. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  294. ],
  295. a : ['id', 'class', 'href', 'target', 'name'],
  296. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  297. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  298. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  299. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  300. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  301. ],
  302. pre : ['id', 'class'],
  303. hr : ['id', 'class', '.page-break-after'],
  304. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  305. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  306. },
  307. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  308. };
  309. var _useCapture = false;
  310. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  311. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  312. var _CHANGE_KEY_MAP = {};
  313. _each(_INPUT_KEY_MAP, function(key, val) {
  314. _CHANGE_KEY_MAP[key] = val;
  315. });
  316. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  317. _CHANGE_KEY_MAP[key] = val;
  318. });
  319. function _bindEvent(el, type, fn) {
  320. if (el.addEventListener){
  321. el.addEventListener(type, fn, _useCapture);
  322. } else if (el.attachEvent){
  323. el.attachEvent('on' + type, fn);
  324. }
  325. }
  326. function _unbindEvent(el, type, fn) {
  327. if (el.removeEventListener){
  328. el.removeEventListener(type, fn, _useCapture);
  329. } else if (el.detachEvent){
  330. el.detachEvent('on' + type, fn);
  331. }
  332. }
  333. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  334. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  335. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  336. function KEvent(el, event) {
  337. this.init(el, event);
  338. }
  339. _extend(KEvent, {
  340. init : function(el, event) {
  341. var self = this, doc = el.ownerDocument || el.document || el;
  342. self.event = event;
  343. _each(_EVENT_PROPS, function(key, val) {
  344. self[val] = event[val];
  345. });
  346. if (!self.target) {
  347. self.target = self.srcElement || doc;
  348. }
  349. if (self.target.nodeType === 3) {
  350. self.target = self.target.parentNode;
  351. }
  352. if (!self.relatedTarget && self.fromElement) {
  353. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  354. }
  355. if (self.pageX == null && self.clientX != null) {
  356. var d = doc.documentElement, body = doc.body;
  357. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  358. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  359. }
  360. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  361. self.which = self.charCode || self.keyCode;
  362. }
  363. if (!self.metaKey && self.ctrlKey) {
  364. self.metaKey = self.ctrlKey;
  365. }
  366. if (!self.which && self.button !== undefined) {
  367. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  368. }
  369. switch (self.which) {
  370. case 186 :
  371. self.which = 59;
  372. break;
  373. case 187 :
  374. case 107 :
  375. case 43 :
  376. self.which = 61;
  377. break;
  378. case 189 :
  379. case 45 :
  380. self.which = 109;
  381. break;
  382. case 42 :
  383. self.which = 106;
  384. break;
  385. case 47 :
  386. self.which = 111;
  387. break;
  388. case 78 :
  389. self.which = 110;
  390. break;
  391. }
  392. if (self.which >= 96 && self.which <= 105) {
  393. self.which -= 48;
  394. }
  395. },
  396. preventDefault : function() {
  397. var ev = this.event;
  398. if (ev.preventDefault) {
  399. ev.preventDefault();
  400. }
  401. ev.returnValue = false;
  402. },
  403. stopPropagation : function() {
  404. var ev = this.event;
  405. if (ev.stopPropagation) {
  406. ev.stopPropagation();
  407. }
  408. ev.cancelBubble = true;
  409. },
  410. stop : function() {
  411. this.preventDefault();
  412. this.stopPropagation();
  413. }
  414. });
  415. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  416. function _getId(el) {
  417. return el[_eventExpendo] || null;
  418. }
  419. function _setId(el) {
  420. el[_eventExpendo] = ++_eventId;
  421. return _eventId;
  422. }
  423. function _removeId(el) {
  424. try {
  425. delete el[_eventExpendo];
  426. } catch(e) {
  427. if (el.removeAttribute) {
  428. el.removeAttribute(_eventExpendo);
  429. }
  430. }
  431. }
  432. function _bind(el, type, fn) {
  433. if (type.indexOf(',') >= 0) {
  434. _each(type.split(','), function() {
  435. _bind(el, this, fn);
  436. });
  437. return;
  438. }
  439. var id = _getId(el);
  440. if (!id) {
  441. id = _setId(el);
  442. }
  443. if (_eventData[id] === undefined) {
  444. _eventData[id] = {};
  445. }
  446. var events = _eventData[id][type];
  447. if (events && events.length > 0) {
  448. _unbindEvent(el, type, events[0]);
  449. } else {
  450. _eventData[id][type] = [];
  451. _eventData[id].el = el;
  452. }
  453. events = _eventData[id][type];
  454. if (events.length === 0) {
  455. events[0] = function(e) {
  456. var kevent = e ? new KEvent(el, e) : undefined;
  457. _each(events, function(i, event) {
  458. if (i > 0 && event) {
  459. event.call(el, kevent);
  460. }
  461. });
  462. };
  463. }
  464. if (_inArray(fn, events) < 0) {
  465. events.push(fn);
  466. }
  467. _bindEvent(el, type, events[0]);
  468. }
  469. function _unbind(el, type, fn) {
  470. if (type && type.indexOf(',') >= 0) {
  471. _each(type.split(','), function() {
  472. _unbind(el, this, fn);
  473. });
  474. return;
  475. }
  476. var id = _getId(el);
  477. if (!id) {
  478. return;
  479. }
  480. if (type === undefined) {
  481. if (id in _eventData) {
  482. _each(_eventData[id], function(key, events) {
  483. if (key != 'el' && events.length > 0) {
  484. _unbindEvent(el, key, events[0]);
  485. }
  486. });
  487. delete _eventData[id];
  488. _removeId(el);
  489. }
  490. return;
  491. }
  492. if (!_eventData[id]) {
  493. return;
  494. }
  495. var events = _eventData[id][type];
  496. if (events && events.length > 0) {
  497. if (fn === undefined) {
  498. _unbindEvent(el, type, events[0]);
  499. delete _eventData[id][type];
  500. } else {
  501. _each(events, function(i, event) {
  502. if (i > 0 && event === fn) {
  503. events.splice(i, 1);
  504. }
  505. });
  506. if (events.length == 1) {
  507. _unbindEvent(el, type, events[0]);
  508. delete _eventData[id][type];
  509. }
  510. }
  511. var count = 0;
  512. _each(_eventData[id], function() {
  513. count++;
  514. });
  515. if (count < 2) {
  516. delete _eventData[id];
  517. _removeId(el);
  518. }
  519. }
  520. }
  521. function _fire(el, type) {
  522. if (type.indexOf(',') >= 0) {
  523. _each(type.split(','), function() {
  524. _fire(el, this);
  525. });
  526. return;
  527. }
  528. var id = _getId(el);
  529. if (!id) {
  530. return;
  531. }
  532. var events = _eventData[id][type];
  533. if (_eventData[id] && events && events.length > 0) {
  534. events[0]();
  535. }
  536. }
  537. function _ctrl(el, key, fn) {
  538. var self = this;
  539. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  540. _bind(el, 'keydown', function(e) {
  541. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  542. fn.call(el);
  543. e.stop();
  544. }
  545. });
  546. }
  547. function _ready(fn) {
  548. var loaded = false;
  549. function readyFunc() {
  550. if (!loaded) {
  551. loaded = true;
  552. fn(KindEditor);
  553. }
  554. }
  555. function ieReadyFunc() {
  556. if (!loaded) {
  557. try {
  558. document.documentElement.doScroll('left');
  559. } catch(e) {
  560. setTimeout(ieReadyFunc, 100);
  561. return;
  562. }
  563. readyFunc();
  564. }
  565. }
  566. function ieReadyStateFunc() {
  567. if (document.readyState === 'complete') {
  568. readyFunc();
  569. }
  570. }
  571. if (document.addEventListener) {
  572. _bind(document, 'DOMContentLoaded', readyFunc);
  573. } else if (document.attachEvent) {
  574. _bind(document, 'readystatechange', ieReadyStateFunc);
  575. var toplevel = false;
  576. try {
  577. toplevel = window.frameElement == null;
  578. } catch(e) {}
  579. if (document.documentElement.doScroll && toplevel) {
  580. ieReadyFunc();
  581. }
  582. }
  583. _bind(window, 'load', readyFunc);
  584. }
  585. if (_IE) {
  586. window.attachEvent('onunload', function() {
  587. _each(_eventData, function(key, events) {
  588. if (events.el) {
  589. _unbind(events.el);
  590. }
  591. });
  592. });
  593. }
  594. K.ctrl = _ctrl;
  595. K.ready = _ready;
  596. function _getCssList(css) {
  597. var list = {},
  598. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  599. match;
  600. while ((match = reg.exec(css))) {
  601. var key = _trim(match[1].toLowerCase()),
  602. val = _trim(_toHex(match[2]));
  603. list[key] = val;
  604. }
  605. return list;
  606. }
  607. function _getAttrList(tag) {
  608. var list = {},
  609. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  610. match;
  611. while ((match = reg.exec(tag))) {
  612. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  613. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  614. list[key] = val;
  615. }
  616. return list;
  617. }
  618. function _addClassToTag(tag, className) {
  619. if (/\s+class\s*=/.test(tag)) {
  620. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  621. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  622. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  623. } else {
  624. return $0;
  625. }
  626. });
  627. } else {
  628. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  629. }
  630. return tag;
  631. }
  632. function _formatCss(css) {
  633. var str = '';
  634. _each(_getCssList(css), function(key, val) {
  635. str += key + ':' + val + ';';
  636. });
  637. return str;
  638. }
  639. function _formatUrl(url, mode, host, pathname) {
  640. mode = _undef(mode, '').toLowerCase();
  641. if (url.substr(0, 5) != 'data:') {
  642. url = url.replace(/([^:])\/\//g, '$1/');
  643. }
  644. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  645. return url;
  646. }
  647. host = host || location.protocol + '//' + location.host;
  648. if (pathname === undefined) {
  649. var m = location.pathname.match(/^(\/.*)\//);
  650. pathname = m ? m[1] : '';
  651. }
  652. var match;
  653. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  654. if (match[1] !== host) {
  655. return url;
  656. }
  657. } else if (/^\w+:/.test(url)) {
  658. return url;
  659. }
  660. function getRealPath(path) {
  661. var parts = path.split('/'), paths = [];
  662. for (var i = 0, len = parts.length; i < len; i++) {
  663. var part = parts[i];
  664. if (part == '..') {
  665. if (paths.length > 0) {
  666. paths.pop();
  667. }
  668. } else if (part !== '' && part != '.') {
  669. paths.push(part);
  670. }
  671. }
  672. return '/' + paths.join('/');
  673. }
  674. if (/^\//.test(url)) {
  675. url = host + getRealPath(url.substr(1));
  676. } else if (!/^\w+:\/\//.test(url)) {
  677. url = host + getRealPath(pathname + '/' + url);
  678. }
  679. function getRelativePath(path, depth) {
  680. if (url.substr(0, path.length) === path) {
  681. var arr = [];
  682. for (var i = 0; i < depth; i++) {
  683. arr.push('..');
  684. }
  685. var prefix = '.';
  686. if (arr.length > 0) {
  687. prefix += '/' + arr.join('/');
  688. }
  689. if (pathname == '/') {
  690. prefix += '/';
  691. }
  692. return prefix + url.substr(path.length);
  693. } else {
  694. if ((match = /^(.*)\//.exec(path))) {
  695. return getRelativePath(match[1], ++depth);
  696. }
  697. }
  698. }
  699. if (mode === 'relative') {
  700. url = getRelativePath(host + pathname, 0).substr(2);
  701. } else if (mode === 'absolute') {
  702. if (url.substr(0, host.length) === host) {
  703. url = url.substr(host.length);
  704. }
  705. }
  706. return url;
  707. }
  708. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  709. urlType = urlType || '';
  710. wellFormatted = _undef(wellFormatted, false);
  711. indentChar = _undef(indentChar, '\t');
  712. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  713. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  714. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  715. });
  716. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  717. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  718. html = html.replace(/\u200B/g, '');
  719. html = html.replace(/\u00A9/g, '&copy;');
  720. var htmlTagMap = {};
  721. if (htmlTags) {
  722. _each(htmlTags, function(key, val) {
  723. var arr = key.split(',');
  724. for (var i = 0, len = arr.length; i < len; i++) {
  725. htmlTagMap[arr[i]] = _toMap(val);
  726. }
  727. });
  728. if (!htmlTagMap.script) {
  729. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  730. }
  731. if (!htmlTagMap.style) {
  732. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  733. }
  734. }
  735. var re = /([ \t\n\r]*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>([ \t\n\r]*)/g;
  736. var tagStack = [];
  737. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  738. var full = $0,
  739. startNewline = $1 || '',
  740. startSlash = $2 || '',
  741. tagName = $3.toLowerCase(),
  742. attr = $4 || '',
  743. endSlash = $5 ? ' ' + $5 : '',
  744. endNewline = $6 || '';
  745. if (htmlTags && !htmlTagMap[tagName]) {
  746. return '';
  747. }
  748. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  749. endSlash = ' /';
  750. }
  751. if (_INLINE_TAG_MAP[tagName]) {
  752. if (startNewline) {
  753. startNewline = ' ';
  754. }
  755. if (endNewline) {
  756. endNewline = ' ';
  757. }
  758. }
  759. if (_PRE_TAG_MAP[tagName]) {
  760. if (startSlash) {
  761. endNewline = '\n';
  762. } else {
  763. startNewline = '\n';
  764. }
  765. }
  766. if (wellFormatted && tagName == 'br') {
  767. endNewline = '\n';
  768. }
  769. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  770. if (wellFormatted) {
  771. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  772. tagStack.pop();
  773. } else {
  774. tagStack.push(tagName);
  775. }
  776. startNewline = '\n';
  777. endNewline = '\n';
  778. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  779. startNewline += indentChar;
  780. if (!startSlash) {
  781. endNewline += indentChar;
  782. }
  783. }
  784. if (endSlash) {
  785. tagStack.pop();
  786. } else if (!startSlash) {
  787. endNewline += indentChar;
  788. }
  789. } else {
  790. startNewline = endNewline = '';
  791. }
  792. }
  793. if (attr !== '') {
  794. var attrMap = _getAttrList(full);
  795. if (tagName === 'font') {
  796. var fontStyleMap = {}, fontStyle = '';
  797. _each(attrMap, function(key, val) {
  798. if (key === 'color') {
  799. fontStyleMap.color = val;
  800. delete attrMap[key];
  801. }
  802. if (key === 'size') {
  803. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  804. delete attrMap[key];
  805. }
  806. if (key === 'face') {
  807. fontStyleMap['font-family'] = val;
  808. delete attrMap[key];
  809. }
  810. if (key === 'style') {
  811. fontStyle = val;
  812. }
  813. });
  814. if (fontStyle && !/;$/.test(fontStyle)) {
  815. fontStyle += ';';
  816. }
  817. _each(fontStyleMap, function(key, val) {
  818. if (val === '') {
  819. return;
  820. }
  821. if (/\s/.test(val)) {
  822. val = "'" + val + "'";
  823. }
  824. fontStyle += key + ':' + val + ';';
  825. });
  826. attrMap.style = fontStyle;
  827. }
  828. _each(attrMap, function(key, val) {
  829. if (_FILL_ATTR_MAP[key]) {
  830. attrMap[key] = key;
  831. }
  832. if (_inArray(key, ['src', 'href']) >= 0) {
  833. attrMap[key] = _formatUrl(val, urlType);
  834. }
  835. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  836. tagName === 'body' && key === 'contenteditable' ||
  837. /^kindeditor_\d+$/.test(key)) {
  838. delete attrMap[key];
  839. }
  840. if (key === 'style' && val !== '') {
  841. var styleMap = _getCssList(val);
  842. _each(styleMap, function(k, v) {
  843. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  844. delete styleMap[k];
  845. }
  846. });
  847. var style = '';
  848. _each(styleMap, function(k, v) {
  849. style += k + ':' + v + ';';
  850. });
  851. attrMap.style = style;
  852. }
  853. });
  854. attr = '';
  855. _each(attrMap, function(key, val) {
  856. if (key === 'style' && val === '') {
  857. return;
  858. }
  859. val = val.replace(/"/g, '&quot;');
  860. attr += ' ' + key + '="' + val + '"';
  861. });
  862. }
  863. if (tagName === 'font') {
  864. tagName = 'span';
  865. }
  866. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  867. });
  868. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  869. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  870. });
  871. html = html.replace(/\n\s*\n/g, '\n');
  872. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  873. return _trim(html);
  874. }
  875. function _clearMsWord(html, htmlTags) {
  876. html = html.replace(/<meta[\s\S]*?>/ig, '')
  877. .replace(/<![\s\S]*?>/ig, '')
  878. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  879. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  880. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  881. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  882. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  883. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  884. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  885. });
  886. return _formatHtml(html, htmlTags);
  887. }
  888. function _mediaType(src) {
  889. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  890. return 'audio/x-pn-realaudio-plugin';
  891. }
  892. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  893. return 'application/x-shockwave-flash';
  894. }
  895. return 'video/x-ms-asf-plugin';
  896. }
  897. function _mediaClass(type) {
  898. if (/realaudio/i.test(type)) {
  899. return 'ke-rm';
  900. }
  901. if (/flash/i.test(type)) {
  902. return 'ke-flash';
  903. }
  904. return 'ke-media';
  905. }
  906. function _mediaAttrs(srcTag) {
  907. return _getAttrList(unescape(srcTag));
  908. }
  909. function _mediaEmbed(attrs) {
  910. var html = '<embed ';
  911. _each(attrs, function(key, val) {
  912. html += key + '="' + val + '" ';
  913. });
  914. html += '/>';
  915. return html;
  916. }
  917. function _mediaImg(blankPath, attrs) {
  918. var width = attrs.width,
  919. height = attrs.height,
  920. type = attrs.type || _mediaType(attrs.src),
  921. srcTag = _mediaEmbed(attrs),
  922. style = '';
  923. if (width > 0) {
  924. style += 'width:' + width + 'px;';
  925. }
  926. if (height > 0) {
  927. style += 'height:' + height + 'px;';
  928. }
  929. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  930. if (style !== '') {
  931. html += 'style="' + style + '" ';
  932. }
  933. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  934. return html;
  935. }
  936. function _tmpl(str, data) {
  937. var fn = new Function("obj",
  938. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  939. "with(obj){p.push('" +
  940. str.replace(/[\r\t\n]/g, " ")
  941. .split("<%").join("\t")
  942. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  943. .replace(/\t=(.*?)%>/g, "',$1,'")
  944. .split("\t").join("');")
  945. .split("%>").join("p.push('")
  946. .split("\r").join("\\'") + "');}return p.join('');");
  947. return data ? fn(data) : fn;
  948. }
  949. K.formatUrl = _formatUrl;
  950. K.formatHtml = _formatHtml;
  951. K.getCssList = _getCssList;
  952. K.getAttrList = _getAttrList;
  953. K.mediaType = _mediaType;
  954. K.mediaAttrs = _mediaAttrs;
  955. K.mediaEmbed = _mediaEmbed;
  956. K.mediaImg = _mediaImg;
  957. K.clearMsWord = _clearMsWord;
  958. K.tmpl = _tmpl;
  959. function _contains(nodeA, nodeB) {
  960. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  961. return true;
  962. }
  963. while ((nodeB = nodeB.parentNode)) {
  964. if (nodeB == nodeA) {
  965. return true;
  966. }
  967. }
  968. return false;
  969. }
  970. var _getSetAttrDiv = document.createElement('div');
  971. _getSetAttrDiv.setAttribute('className', 't');
  972. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  973. function _getAttr(el, key) {
  974. key = key.toLowerCase();
  975. var val = null;
  976. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  977. var div = el.ownerDocument.createElement('div');
  978. div.appendChild(el.cloneNode(false));
  979. var list = _getAttrList(_unescape(div.innerHTML));
  980. if (key in list) {
  981. val = list[key];
  982. }
  983. } else {
  984. try {
  985. val = el.getAttribute(key, 2);
  986. } catch(e) {
  987. val = el.getAttribute(key, 1);
  988. }
  989. }
  990. if (key === 'style' && val !== null) {
  991. val = _formatCss(val);
  992. }
  993. return val;
  994. }
  995. function _queryAll(expr, root) {
  996. var exprList = expr.split(',');
  997. if (exprList.length > 1) {
  998. var mergedResults = [];
  999. _each(exprList, function() {
  1000. _each(_queryAll(this, root), function() {
  1001. if (_inArray(this, mergedResults) < 0) {
  1002. mergedResults.push(this);
  1003. }
  1004. });
  1005. });
  1006. return mergedResults;
  1007. }
  1008. root = root || document;
  1009. function escape(str) {
  1010. if (typeof str != 'string') {
  1011. return str;
  1012. }
  1013. return str.replace(/([^\w\-])/g, '\\$1');
  1014. }
  1015. function stripslashes(str) {
  1016. return str.replace(/\\/g, '');
  1017. }
  1018. function cmpTag(tagA, tagB) {
  1019. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1020. }
  1021. function byId(id, tag, root) {
  1022. var arr = [],
  1023. doc = root.ownerDocument || root,
  1024. el = doc.getElementById(stripslashes(id));
  1025. if (el) {
  1026. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1027. arr.push(el);
  1028. }
  1029. }
  1030. return arr;
  1031. }
  1032. function byClass(className, tag, root) {
  1033. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1034. if (root.getElementsByClassName) {
  1035. els = root.getElementsByClassName(stripslashes(className));
  1036. for (i = 0, len = els.length; i < len; i++) {
  1037. el = els[i];
  1038. if (cmpTag(tag, el.nodeName)) {
  1039. arr.push(el);
  1040. }
  1041. }
  1042. } else if (doc.querySelectorAll) {
  1043. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1044. for (i = 0, len = els.length; i < len; i++) {
  1045. el = els[i];
  1046. if (_contains(root, el)) {
  1047. arr.push(el);
  1048. }
  1049. }
  1050. } else {
  1051. els = root.getElementsByTagName(tag);
  1052. className = ' ' + className + ' ';
  1053. for (i = 0, len = els.length; i < len; i++) {
  1054. el = els[i];
  1055. if (el.nodeType == 1) {
  1056. var cls = el.className;
  1057. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1058. arr.push(el);
  1059. }
  1060. }
  1061. }
  1062. }
  1063. return arr;
  1064. }
  1065. function byName(name, tag, root) {
  1066. var arr = [], doc = root.ownerDocument || root,
  1067. els = doc.getElementsByName(stripslashes(name)), el;
  1068. for (var i = 0, len = els.length; i < len; i++) {
  1069. el = els[i];
  1070. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1071. if (el.getAttributeNode('name')) {
  1072. arr.push(el);
  1073. }
  1074. }
  1075. }
  1076. return arr;
  1077. }
  1078. function byAttr(key, val, tag, root) {
  1079. var arr = [], els = root.getElementsByTagName(tag), el;
  1080. for (var i = 0, len = els.length; i < len; i++) {
  1081. el = els[i];
  1082. if (el.nodeType == 1) {
  1083. if (val === null) {
  1084. if (_getAttr(el, key) !== null) {
  1085. arr.push(el);
  1086. }
  1087. } else {
  1088. if (val === escape(_getAttr(el, key))) {
  1089. arr.push(el);
  1090. }
  1091. }
  1092. }
  1093. }
  1094. return arr;
  1095. }
  1096. function select(expr, root) {
  1097. var arr = [], matches;
  1098. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1099. var tag = matches ? matches[1] : '*';
  1100. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1101. arr = byId(matches[1], tag, root);
  1102. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1103. arr = byClass(matches[1], tag, root);
  1104. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1105. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1106. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1107. var key = matches[1].toLowerCase(), val = matches[2];
  1108. if (key === 'id') {
  1109. arr = byId(val, tag, root);
  1110. } else if (key === 'class') {
  1111. arr = byClass(val, tag, root);
  1112. } else if (key === 'name') {
  1113. arr = byName(val, tag, root);
  1114. } else {
  1115. arr = byAttr(key, val, tag, root);
  1116. }
  1117. } else {
  1118. var els = root.getElementsByTagName(tag), el;
  1119. for (var i = 0, len = els.length; i < len; i++) {
  1120. el = els[i];
  1121. if (el.nodeType == 1) {
  1122. arr.push(el);
  1123. }
  1124. }
  1125. }
  1126. return arr;
  1127. }
  1128. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1129. while ((arr = re.exec(expr))) {
  1130. if (arr[1] !== ' ') {
  1131. parts.push(arr[1]);
  1132. }
  1133. }
  1134. var results = [];
  1135. if (parts.length == 1) {
  1136. return select(parts[0], root);
  1137. }
  1138. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1139. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1140. part = parts[i];
  1141. if (part === '>') {
  1142. isChild = true;
  1143. continue;
  1144. }
  1145. if (i > 0) {
  1146. els = [];
  1147. for (j = 0, len = results.length; j < len; j++) {
  1148. val = results[j];
  1149. subResults = select(part, val);
  1150. for (k = 0, l = subResults.length; k < l; k++) {
  1151. v = subResults[k];
  1152. if (isChild) {
  1153. if (val === v.parentNode) {
  1154. els.push(v);
  1155. }
  1156. } else {
  1157. els.push(v);
  1158. }
  1159. }
  1160. }
  1161. results = els;
  1162. } else {
  1163. results = select(part, root);
  1164. }
  1165. if (results.length === 0) {
  1166. return [];
  1167. }
  1168. }
  1169. return results;
  1170. }
  1171. function _query(expr, root) {
  1172. var arr = _queryAll(expr, root);
  1173. return arr.length > 0 ? arr[0] : null;
  1174. }
  1175. K.query = _query;
  1176. K.queryAll = _queryAll;
  1177. function _get(val) {
  1178. return K(val)[0];
  1179. }
  1180. function _getDoc(node) {
  1181. if (!node) {
  1182. return document;
  1183. }
  1184. return node.ownerDocument || node.document || node;
  1185. }
  1186. function _getWin(node) {
  1187. if (!node) {
  1188. return window;
  1189. }
  1190. var doc = _getDoc(node);
  1191. return doc.parentWindow || doc.defaultView;
  1192. }
  1193. function _setHtml(el, html) {
  1194. if (el.nodeType != 1) {
  1195. return;
  1196. }
  1197. var doc = _getDoc(el);
  1198. try {
  1199. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1200. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1201. temp.parentNode.removeChild(temp);
  1202. } catch(e) {
  1203. K(el).empty();
  1204. K('@' + html, doc).each(function() {
  1205. el.appendChild(this);
  1206. });
  1207. }
  1208. }
  1209. function _hasClass(el, cls) {
  1210. return _inString(cls, el.className, ' ');
  1211. }
  1212. function _setAttr(el, key, val) {
  1213. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1214. key = 'className';
  1215. }
  1216. el.setAttribute(key, '' + val);
  1217. }
  1218. function _removeAttr(el, key) {
  1219. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1220. key = 'className';
  1221. }
  1222. _setAttr(el, key, '');
  1223. el.removeAttribute(key);
  1224. }
  1225. function _getNodeName(node) {
  1226. if (!node || !node.nodeName) {
  1227. return '';
  1228. }
  1229. return node.nodeName.toLowerCase();
  1230. }
  1231. function _computedCss(el, key) {
  1232. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1233. if (win.getComputedStyle) {
  1234. var style = win.getComputedStyle(el, null);
  1235. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1236. } else if (el.currentStyle) {
  1237. val = el.currentStyle[camelKey] || el.style[camelKey];
  1238. }
  1239. return val;
  1240. }
  1241. function _hasVal(node) {
  1242. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1243. }
  1244. function _docElement(doc) {
  1245. doc = doc || document;
  1246. return _QUIRKS ? doc.body : doc.documentElement;
  1247. }
  1248. function _docHeight(doc) {
  1249. var el = _docElement(doc);
  1250. return Math.max(el.scrollHeight, el.clientHeight);
  1251. }
  1252. function _docWidth(doc) {
  1253. var el = _docElement(doc);
  1254. return Math.max(el.scrollWidth, el.clientWidth);
  1255. }
  1256. function _getScrollPos(doc) {
  1257. doc = doc || document;
  1258. var x, y;
  1259. if (_IE || _OPERA) {
  1260. x = _docElement(doc).scrollLeft;
  1261. y = _docElement(doc).scrollTop;
  1262. } else {
  1263. x = _getWin(doc).scrollX;
  1264. y = _getWin(doc).scrollY;
  1265. }
  1266. return {x : x, y : y};
  1267. }
  1268. function KNode(node) {
  1269. this.init(node);
  1270. }
  1271. _extend(KNode, {
  1272. init : function(node) {
  1273. var self = this;
  1274. node = _isArray(node) ? node : [node];
  1275. var length = 0;
  1276. for (var i = 0, len = node.length; i < len; i++) {
  1277. if (node[i]) {
  1278. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1279. length++;
  1280. }
  1281. }
  1282. self.length = length;
  1283. self.doc = _getDoc(self[0]);
  1284. self.name = _getNodeName(self[0]);
  1285. self.type = self.length > 0 ? self[0].nodeType : null;
  1286. self.win = _getWin(self[0]);
  1287. },
  1288. each : function(fn) {
  1289. var self = this;
  1290. for (var i = 0; i < self.length; i++) {
  1291. if (fn.call(self[i], i, self[i]) === false) {
  1292. return self;
  1293. }
  1294. }
  1295. return self;
  1296. },
  1297. bind : function(type, fn) {
  1298. this.each(function() {
  1299. _bind(this, type, fn);
  1300. });
  1301. return this;
  1302. },
  1303. unbind : function(type, fn) {
  1304. this.each(function() {
  1305. _unbind(this, type, fn);
  1306. });
  1307. return this;
  1308. },
  1309. fire : function(type) {
  1310. if (this.length < 1) {
  1311. return this;
  1312. }
  1313. _fire(this[0], type);
  1314. return this;
  1315. },
  1316. hasAttr : function(key) {
  1317. if (this.length < 1) {
  1318. return false;
  1319. }
  1320. return !!_getAttr(this[0], key);
  1321. },
  1322. attr : function(key, val) {
  1323. var self = this;
  1324. if (key === undefined) {
  1325. return _getAttrList(self.outer());
  1326. }
  1327. if (typeof key === 'object') {
  1328. _each(key, function(k, v) {
  1329. self.attr(k, v);
  1330. });
  1331. return self;
  1332. }
  1333. if (val === undefined) {
  1334. val = self.length < 1 ? null : _getAttr(self[0], key);
  1335. return val === null ? '' : val;
  1336. }
  1337. self.each(function() {
  1338. _setAttr(this, key, val);
  1339. });
  1340. return self;
  1341. },
  1342. removeAttr : function(key) {
  1343. this.each(function() {
  1344. _removeAttr(this, key);
  1345. });
  1346. return this;
  1347. },
  1348. get : function(i) {
  1349. if (this.length < 1) {
  1350. return null;
  1351. }
  1352. return this[i || 0];
  1353. },
  1354. eq : function(i) {
  1355. if (this.length < 1) {
  1356. return null;
  1357. }
  1358. return this[i] ? new KNode(this[i]) : null;
  1359. },
  1360. hasClass : function(cls) {
  1361. if (this.length < 1) {
  1362. return false;
  1363. }
  1364. return _hasClass(this[0], cls);
  1365. },
  1366. addClass : function(cls) {
  1367. this.each(function() {
  1368. if (!_hasClass(this, cls)) {
  1369. this.className = _trim(this.className + ' ' + cls);
  1370. }
  1371. });
  1372. return this;
  1373. },
  1374. removeClass : function(cls) {
  1375. this.each(function() {
  1376. if (_hasClass(this, cls)) {
  1377. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1378. }
  1379. });
  1380. return this;
  1381. },
  1382. html : function(val) {
  1383. var self = this;
  1384. if (val === undefined) {
  1385. if (self.length < 1 || self.type != 1) {
  1386. return '';
  1387. }
  1388. return _formatHtml(self[0].innerHTML);
  1389. }
  1390. self.each(function() {
  1391. _setHtml(this, val);
  1392. });
  1393. return self;
  1394. },
  1395. text : function() {
  1396. var self = this;
  1397. if (self.length < 1) {
  1398. return '';
  1399. }
  1400. return _IE ? self[0].innerText : self[0].textContent;
  1401. },
  1402. hasVal : function() {
  1403. if (this.length < 1) {
  1404. return false;
  1405. }
  1406. return _hasVal(this[0]);
  1407. },
  1408. val : function(val) {
  1409. var self = this;
  1410. if (val === undefined) {
  1411. if (self.length < 1) {
  1412. return '';
  1413. }
  1414. return self.hasVal() ? self[0].value : self.attr('value');
  1415. } else {
  1416. self.each(function() {
  1417. if (_hasVal(this)) {
  1418. this.value = val;
  1419. } else {
  1420. _setAttr(this, 'value' , val);
  1421. }
  1422. });
  1423. return self;
  1424. }
  1425. },
  1426. css : function(key, val) {
  1427. var self = this;
  1428. if (key === undefined) {
  1429. return _getCssList(self.attr('style'));
  1430. }
  1431. if (typeof key === 'object') {
  1432. _each(key, function(k, v) {
  1433. self.css(k, v);
  1434. });
  1435. return self;
  1436. }
  1437. if (val === undefined) {
  1438. if (self.length < 1) {
  1439. return '';
  1440. }
  1441. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1442. }
  1443. self.each(function() {
  1444. this.style[_toCamel(key)] = val;
  1445. });
  1446. return self;
  1447. },
  1448. width : function(val) {
  1449. var self = this;
  1450. if (val === undefined) {
  1451. if (self.length < 1) {
  1452. return 0;
  1453. }
  1454. return self[0].offsetWidth;
  1455. }
  1456. return self.css('width', _addUnit(val));
  1457. },
  1458. height : function(val) {
  1459. var self = this;
  1460. if (val === undefined) {
  1461. if (self.length < 1) {
  1462. return 0;
  1463. }
  1464. return self[0].offsetHeight;
  1465. }
  1466. return self.css('height', _addUnit(val));
  1467. },
  1468. opacity : function(val) {
  1469. this.each(function() {
  1470. if (this.style.opacity === undefined) {
  1471. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1472. } else {
  1473. this.style.opacity = val == 1 ? '' : val;
  1474. }
  1475. });
  1476. return this;
  1477. },
  1478. data : function(key, val) {
  1479. var self = this;
  1480. key = 'kindeditor_data_' + key;
  1481. if (val === undefined) {
  1482. if (self.length < 1) {
  1483. return null;
  1484. }
  1485. return self[0][key];
  1486. }
  1487. this.each(function() {
  1488. this[key] = val;
  1489. });
  1490. return self;
  1491. },
  1492. pos : function() {
  1493. var self = this, node = self[0], x = 0, y = 0;
  1494. if (node) {
  1495. if (node.getBoundingClientRect) {
  1496. var box = node.getBoundingClientRect(),
  1497. pos = _getScrollPos(self.doc);
  1498. x = box.left + pos.x;
  1499. y = box.top + pos.y;
  1500. } else {
  1501. while (node) {
  1502. x += node.offsetLeft;
  1503. y += node.offsetTop;
  1504. node = node.offsetParent;
  1505. }
  1506. }
  1507. }
  1508. return {x : _round(x), y : _round(y)};
  1509. },
  1510. clone : function(bool) {
  1511. if (this.length < 1) {
  1512. return new KNode([]);
  1513. }
  1514. return new KNode(this[0].cloneNode(bool));
  1515. },
  1516. append : function(expr) {
  1517. this.each(function() {
  1518. if (this.appendChild) {
  1519. this.appendChild(_get(expr));
  1520. }
  1521. });
  1522. return this;
  1523. },
  1524. appendTo : function(expr) {
  1525. this.each(function() {
  1526. _get(expr).appendChild(this);
  1527. });
  1528. return this;
  1529. },
  1530. before : function(expr) {
  1531. this.each(function() {
  1532. this.parentNode.insertBefore(_get(expr), this);
  1533. });
  1534. return this;
  1535. },
  1536. after : function(expr) {
  1537. this.each(function() {
  1538. if (this.nextSibling) {
  1539. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1540. } else {
  1541. this.parentNode.appendChild(_get(expr));
  1542. }
  1543. });
  1544. return this;
  1545. },
  1546. replaceWith : function(expr) {
  1547. var nodes = [];
  1548. this.each(function(i, node) {
  1549. _unbind(node);
  1550. var newNode = _get(expr);
  1551. node.parentNode.replaceChild(newNode, node);
  1552. nodes.push(newNode);
  1553. });
  1554. return K(nodes);
  1555. },
  1556. empty : function() {
  1557. var self = this;
  1558. self.each(function(i, node) {
  1559. var child = node.firstChild;
  1560. while (child) {
  1561. if (!node.parentNode) {
  1562. return;
  1563. }
  1564. var next = child.nextSibling;
  1565. child.parentNode.removeChild(child);
  1566. child = next;
  1567. }
  1568. });
  1569. return self;
  1570. },
  1571. remove : function(keepChilds) {
  1572. var self = this;
  1573. self.each(function(i, node) {
  1574. if (!node.parentNode) {
  1575. return;
  1576. }
  1577. _unbind(node);
  1578. if (keepChilds) {
  1579. var child = node.firstChild;
  1580. while (child) {
  1581. var next = child.nextSibling;
  1582. node.parentNode.insertBefore(child, node);
  1583. child = next;
  1584. }
  1585. }
  1586. node.parentNode.removeChild(node);
  1587. delete self[i];
  1588. });
  1589. self.length = 0;
  1590. return self;
  1591. },
  1592. show : function(val) {
  1593. var self = this;
  1594. if (val === undefined) {
  1595. val = self._originDisplay || '';
  1596. }
  1597. if (self.css('display') != 'none') {
  1598. return self;
  1599. }
  1600. return self.css('display', val);
  1601. },
  1602. hide : function() {
  1603. var self = this;
  1604. if (self.length < 1) {
  1605. return self;
  1606. }
  1607. self._originDisplay = self[0].style.display;
  1608. return self.css('display', 'none');
  1609. },
  1610. outer : function() {
  1611. var self = this;
  1612. if (self.length < 1) {
  1613. return '';
  1614. }
  1615. var div = self.doc.createElement('div'), html;
  1616. div.appendChild(self[0].cloneNode(true));
  1617. html = _formatHtml(div.innerHTML);
  1618. div = null;
  1619. return html;
  1620. },
  1621. isSingle : function() {
  1622. return !!_SINGLE_TAG_MAP[this.name];
  1623. },
  1624. isInline : function() {
  1625. return !!_INLINE_TAG_MAP[this.name];
  1626. },
  1627. isBlock : function() {
  1628. return !!_BLOCK_TAG_MAP[this.name];
  1629. },
  1630. isStyle : function() {
  1631. return !!_STYLE_TAG_MAP[this.name];
  1632. },
  1633. isControl : function() {
  1634. return !!_CONTROL_TAG_MAP[this.name];
  1635. },
  1636. contains : function(otherNode) {
  1637. if (this.length < 1) {
  1638. return false;
  1639. }
  1640. return _contains(this[0], _get(otherNode));
  1641. },
  1642. parent : function() {
  1643. if (this.length < 1) {
  1644. return null;
  1645. }
  1646. var node = this[0].parentNode;
  1647. return node ? new KNode(node) : null;
  1648. },
  1649. children : function() {
  1650. if (this.length < 1) {
  1651. return new KNode([]);
  1652. }
  1653. var list = [], child = this[0].firstChild;
  1654. while (child) {
  1655. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1656. list.push(child);
  1657. }
  1658. child = child.nextSibling;
  1659. }
  1660. return new KNode(list);
  1661. },
  1662. first : function() {
  1663. var list = this.children();
  1664. return list.length > 0 ? list.eq(0) : null;
  1665. },
  1666. last : function() {
  1667. var list = this.children();
  1668. return list.length > 0 ? list.eq(list.length - 1) : null;
  1669. },
  1670. index : function() {
  1671. if (this.length < 1) {
  1672. return -1;
  1673. }
  1674. var i = -1, sibling = this[0];
  1675. while (sibling) {
  1676. i++;
  1677. sibling = sibling.previousSibling;
  1678. }
  1679. return i;
  1680. },
  1681. prev : function() {
  1682. if (this.length < 1) {
  1683. return null;
  1684. }
  1685. var node = this[0].previousSibling;
  1686. return node ? new KNode(node) : null;
  1687. },
  1688. next : function() {
  1689. if (this.length < 1) {
  1690. return null;
  1691. }
  1692. var node = this[0].nextSibling;
  1693. return node ? new KNode(node) : null;
  1694. },
  1695. scan : function(fn, order) {
  1696. if (this.length < 1) {
  1697. return;
  1698. }
  1699. order = (order === undefined) ? true : order;
  1700. function walk(node) {
  1701. var n = order ? node.firstChild : node.lastChild;
  1702. while (n) {
  1703. var next = order ? n.nextSibling : n.previousSibling;
  1704. if (fn(n) === false) {
  1705. return false;
  1706. }
  1707. if (walk(n) === false) {
  1708. return false;
  1709. }
  1710. n = next;
  1711. }
  1712. }
  1713. walk(this[0]);
  1714. return this;
  1715. }
  1716. });
  1717. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1718. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1719. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1720. KNode.prototype[type] = function(fn) {
  1721. return fn ? this.bind(type, fn) : this.fire(type);
  1722. };
  1723. });
  1724. var _K = K;
  1725. K = function(expr, root) {
  1726. if (expr === undefined || expr === null) {
  1727. return;
  1728. }
  1729. function newNode(node) {
  1730. if (!node[0]) {
  1731. node = [];
  1732. }
  1733. return new KNode(node);
  1734. }
  1735. if (typeof expr === 'string') {
  1736. if (root) {
  1737. root = _get(root);
  1738. }
  1739. var length = expr.length;
  1740. if (expr.charAt(0) === '@') {
  1741. expr = expr.substr(1);
  1742. }
  1743. if (expr.length !== length || /<.+>/.test(expr)) {
  1744. var doc = root ? root.ownerDocument || root : document,
  1745. div = doc.createElement('div'), list = [];
  1746. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1747. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1748. var child = div.childNodes[i];
  1749. if (child.id == '__kindeditor_temp_tag__') {
  1750. continue;
  1751. }
  1752. list.push(child);
  1753. }
  1754. return newNode(list);
  1755. }
  1756. return newNode(_queryAll(expr, root));
  1757. }
  1758. if (expr && expr.constructor === KNode) {
  1759. return expr;
  1760. }
  1761. if (expr.toArray) {
  1762. expr = expr.toArray();
  1763. }
  1764. if (_isArray(expr)) {
  1765. return newNode(expr);
  1766. }
  1767. return newNode(_toArray(arguments));
  1768. };
  1769. _each(_K, function(key, val) {
  1770. K[key] = val;
  1771. });
  1772. K.NodeClass = KNode;
  1773. window.KindEditor = K;
  1774. var _START_TO_START = 0,
  1775. _START_TO_END = 1,
  1776. _END_TO_END = 2,
  1777. _END_TO_START = 3,
  1778. _BOOKMARK_ID = 0;
  1779. function _updateCollapsed(range) {
  1780. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1781. return range;
  1782. }
  1783. function _copyAndDelete(range, isCopy, isDelete) {
  1784. var doc = range.doc, nodeList = [];
  1785. function splitTextNode(node, startOffset, endOffset) {
  1786. var length = node.nodeValue.length, centerNode;
  1787. if (isCopy) {
  1788. var cloneNode = node.cloneNode(true);
  1789. if (startOffset > 0) {
  1790. centerNode = cloneNode.splitText(startOffset);
  1791. } else {
  1792. centerNode = cloneNode;
  1793. }
  1794. if (endOffset < length) {
  1795. centerNode.splitText(endOffset - startOffset);
  1796. }
  1797. }
  1798. if (isDelete) {
  1799. var center = node;
  1800. if (startOffset > 0) {
  1801. center = node.splitText(startOffset);
  1802. range.setStart(node, startOffset);
  1803. }
  1804. if (endOffset < length) {
  1805. var right = center.splitText(endOffset - startOffset);
  1806. range.setEnd(right, 0);
  1807. }
  1808. nodeList.push(center);
  1809. }
  1810. return centerNode;
  1811. }
  1812. function removeNodes() {
  1813. if (isDelete) {
  1814. range.up().collapse(true);
  1815. }
  1816. for (var i = 0, len = nodeList.length; i < len; i++) {
  1817. var node = nodeList[i];
  1818. if (node.parentNode) {
  1819. node.parentNode.removeChild(node);
  1820. }
  1821. }
  1822. }
  1823. var copyRange = range.cloneRange().down();
  1824. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1825. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1826. if (ancestor.nodeType == 3) {
  1827. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1828. if (isCopy) {
  1829. frag.appendChild(textNode);
  1830. }
  1831. removeNodes();
  1832. return isCopy ? frag : range;
  1833. }
  1834. function extractNodes(parent, frag) {
  1835. var node = parent.firstChild, nextNode;
  1836. while (node) {
  1837. var testRange = new KRange(doc).selectNode(node);
  1838. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1839. if (start >= 0 && incStart <= 0) {
  1840. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1841. }
  1842. if (incStart >= 0 && incEnd <= 0) {
  1843. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1844. }
  1845. if (incEnd >= 0 && end <= 0) {
  1846. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1847. }
  1848. if (end >= 0) {
  1849. return false;
  1850. }
  1851. nextNode = node.nextSibling;
  1852. if (start > 0) {
  1853. if (node.nodeType == 1) {
  1854. if (incStart >= 0 && incEnd <= 0) {
  1855. if (isCopy) {
  1856. frag.appendChild(node.cloneNode(true));
  1857. }
  1858. if (isDelete) {
  1859. nodeList.push(node);
  1860. }
  1861. } else {
  1862. var childFlag;
  1863. if (isCopy) {
  1864. childFlag = node.cloneNode(false);
  1865. frag.appendChild(childFlag);
  1866. }
  1867. if (extractNodes(node, childFlag) === false) {
  1868. return false;
  1869. }
  1870. }
  1871. } else if (node.nodeType == 3) {
  1872. var textNode;
  1873. if (node == copyRange.startContainer) {
  1874. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1875. } else if (node == copyRange.endContainer) {
  1876. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1877. } else {
  1878. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1879. }
  1880. if (isCopy) {
  1881. try {
  1882. frag.appendChild(textNode);
  1883. } catch(e) {}
  1884. }
  1885. }
  1886. }
  1887. node = nextNode;
  1888. }
  1889. }
  1890. extractNodes(ancestor, frag);
  1891. if (isDelete) {
  1892. range.up().collapse(true);
  1893. }
  1894. for (var i = 0, len = nodeList.length; i < len; i++) {
  1895. var node = nodeList[i];
  1896. if (node.parentNode) {
  1897. node.parentNode.removeChild(node);
  1898. }
  1899. }
  1900. return isCopy ? frag : range;
  1901. }
  1902. function _moveToElementText(range, el) {
  1903. var node = el;
  1904. while (node) {
  1905. var knode = K(node);
  1906. if (knode.name == 'marquee' || knode.name == 'select') {
  1907. return;
  1908. }
  1909. node = node.parentNode;
  1910. }
  1911. try {
  1912. range.moveToElementText(el);
  1913. } catch(e) {}
  1914. }
  1915. function _getStartEnd(rng, isStart) {
  1916. var doc = rng.parentElement().ownerDocument,
  1917. pointRange = rng.duplicate();
  1918. pointRange.collapse(isStart);
  1919. var parent = pointRange.parentElement(),
  1920. nodes = parent.childNodes;
  1921. if (nodes.length === 0) {
  1922. return {node: parent.parentNode, offset: K(parent).index()};
  1923. }
  1924. var startNode = doc, startPos = 0, cmp = -1;
  1925. var testRange = rng.duplicate();
  1926. _moveToElementText(testRange, parent);
  1927. for (var i = 0, len = nodes.length; i < len; i++) {
  1928. var node = nodes[i];
  1929. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1930. if (cmp === 0) {
  1931. return {node: node.parentNode, offset: i};
  1932. }
  1933. if (node.nodeType == 1) {
  1934. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1935. if (knode.isControl()) {
  1936. dummy = doc.createElement('span');
  1937. knode.after(dummy);
  1938. newNode = dummy;
  1939. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1940. }
  1941. _moveToElementText(nodeRange, newNode);
  1942. testRange.setEndPoint('StartToEnd', nodeRange);
  1943. if (cmp > 0) {
  1944. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1945. } else {
  1946. startPos = 0;
  1947. }
  1948. if (dummy) {
  1949. K(dummy).remove();
  1950. }
  1951. } else if (node.nodeType == 3) {
  1952. testRange.moveStart('character', node.nodeValue.length);
  1953. startPos += node.nodeValue.length;
  1954. }
  1955. if (cmp < 0) {
  1956. startNode = node;
  1957. }
  1958. }
  1959. if (cmp < 0 && startNode.nodeType == 1) {
  1960. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1961. }
  1962. if (cmp > 0) {
  1963. while (startNode.nextSibling && startNode.nodeType == 1) {
  1964. startNode = startNode.nextSibling;
  1965. }
  1966. }
  1967. testRange = rng.duplicate();
  1968. _moveToElementText(testRange, parent);
  1969. testRange.setEndPoint('StartToEnd', pointRange);
  1970. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1971. if (cmp > 0 && startNode.nodeType == 3) {
  1972. var prevNode = startNode.previousSibling;
  1973. while (prevNode && prevNode.nodeType == 3) {
  1974. startPos -= prevNode.nodeValue.length;
  1975. prevNode = prevNode.previousSibling;
  1976. }
  1977. }
  1978. return {node: startNode, offset: startPos};
  1979. }
  1980. function _getEndRange(node, offset) {
  1981. var doc = node.ownerDocument || node,
  1982. range = doc.body.createTextRange();
  1983. if (doc == node) {
  1984. range.collapse(true);
  1985. return range;
  1986. }
  1987. if (node.nodeType == 1 && node.childNodes.length > 0) {
  1988. var children = node.childNodes, isStart, child;
  1989. if (offset === 0) {
  1990. child = children[0];
  1991. isStart = true;
  1992. } else {
  1993. child = children[offset - 1];
  1994. isStart = false;
  1995. }
  1996. if (!child) {
  1997. return range;
  1998. }
  1999. if (K(child).name === 'head') {
  2000. if (offset === 1) {
  2001. isStart = true;
  2002. }
  2003. if (offset === 2) {
  2004. isStart = false;
  2005. }
  2006. range.collapse(isStart);
  2007. return range;
  2008. }
  2009. if (child.nodeType == 1) {
  2010. var kchild = K(child), span;
  2011. if (kchild.isControl()) {
  2012. span = doc.createElement('span');
  2013. if (isStart) {
  2014. kchild.before(span);
  2015. } else {
  2016. kchild.after(span);
  2017. }
  2018. child = span;
  2019. }
  2020. _moveToElementText(range, child);
  2021. range.collapse(isStart);
  2022. if (span) {
  2023. K(span).remove();
  2024. }
  2025. return range;
  2026. }
  2027. node = child;
  2028. offset = isStart ? 0 : child.nodeValue.length;
  2029. }
  2030. var dummy = doc.createElement('span');
  2031. K(node).before(dummy);
  2032. _moveToElementText(range, dummy);
  2033. range.moveStart('character', offset);
  2034. K(dummy).remove();
  2035. return range;
  2036. }
  2037. function _toRange(rng) {
  2038. var doc, range;
  2039. function tr2td(start) {
  2040. if (K(start.node).name == 'tr') {
  2041. start.node = start.node.cells[start.offset];
  2042. start.offset = 0;
  2043. }
  2044. }
  2045. if (_IE) {
  2046. if (rng.item) {
  2047. doc = _getDoc(rng.item(0));
  2048. range = new KRange(doc);
  2049. range.selectNode(rng.item(0));
  2050. return range;
  2051. }
  2052. doc = rng.parentElement().ownerDocument;
  2053. var start = _getStartEnd(rng, true),
  2054. end = _getStartEnd(rng, false);
  2055. tr2td(start);
  2056. tr2td(end);
  2057. range = new KRange(doc);
  2058. range.setStart(start.node, start.offset);
  2059. range.setEnd(end.node, end.offset);
  2060. return range;
  2061. }
  2062. var startContainer = rng.startContainer;
  2063. doc = startContainer.ownerDocument || startContainer;
  2064. range = new KRange(doc);
  2065. range.setStart(startContainer, rng.startOffset);
  2066. range.setEnd(rng.endContainer, rng.endOffset);
  2067. return range;
  2068. }
  2069. function KRange(doc) {
  2070. this.init(doc);
  2071. }
  2072. _extend(KRange, {
  2073. init : function(doc) {
  2074. var self = this;
  2075. self.startContainer = doc;
  2076. self.startOffset = 0;
  2077. self.endContainer = doc;
  2078. self.endOffset = 0;
  2079. self.collapsed = true;
  2080. self.doc = doc;
  2081. },
  2082. commonAncestor : function() {
  2083. function getParents(node) {
  2084. var parents = [];
  2085. while (node) {
  2086. parents.push(node);
  2087. node = node.parentNode;
  2088. }
  2089. return parents;
  2090. }
  2091. var parentsA = getParents(this.startContainer),
  2092. parentsB = getParents(this.endContainer),
  2093. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2094. while (++i) {
  2095. parentA = parentsA[lenA - i];
  2096. parentB = parentsB[lenB - i];
  2097. if (!parentA || !parentB || parentA !== parentB) {
  2098. break;
  2099. }
  2100. }
  2101. return parentsA[lenA - i + 1];
  2102. },
  2103. setStart : function(node, offset) {
  2104. var self = this, doc = self.doc;
  2105. self.startContainer = node;
  2106. self.startOffset = offset;
  2107. if (self.endContainer === doc) {
  2108. self.endContainer = node;
  2109. self.endOffset = offset;
  2110. }
  2111. return _updateCollapsed(this);
  2112. },
  2113. setEnd : function(node, offset) {
  2114. var self = this, doc = self.doc;
  2115. self.endContainer = node;
  2116. self.endOffset = offset;
  2117. if (self.startContainer === doc) {
  2118. self.startContainer = node;
  2119. self.startOffset = offset;
  2120. }
  2121. return _updateCollapsed(this);
  2122. },
  2123. setStartBefore : function(node) {
  2124. return this.setStart(node.parentNode || this.doc, K(node).index());
  2125. },
  2126. setStartAfter : function(node) {
  2127. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2128. },
  2129. setEndBefore : function(node) {
  2130. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2131. },
  2132. setEndAfter : function(node) {
  2133. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2134. },
  2135. selectNode : function(node) {
  2136. return this.setStartBefore(node).setEndAfter(node);
  2137. },
  2138. selectNodeContents : function(node) {
  2139. var knode = K(node);
  2140. if (knode.type == 3 || knode.isSingle()) {
  2141. return this.selectNode(node);
  2142. }
  2143. var children = knode.children();
  2144. if (children.length > 0) {
  2145. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2146. }
  2147. return this.setStart(node, 0).setEnd(node, 0);
  2148. },
  2149. collapse : function(toStart) {
  2150. if (toStart) {
  2151. return this.setEnd(this.startContainer, this.startOffset);
  2152. }
  2153. return this.setStart(this.endContainer, this.endOffset);
  2154. },
  2155. compareBoundaryPoints : function(how, range) {
  2156. var rangeA = this.get(), rangeB = range.get();
  2157. if (_IE) {
  2158. var arr = {};
  2159. arr[_START_TO_START] = 'StartToStart';
  2160. arr[_START_TO_END] = 'EndToStart';
  2161. arr[_END_TO_END] = 'EndToEnd';
  2162. arr[_END_TO_START] = 'StartToEnd';
  2163. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2164. if (cmp !== 0) {
  2165. return cmp;
  2166. }
  2167. var nodeA, nodeB, nodeC, posA, posB;
  2168. if (how === _START_TO_START || how === _END_TO_START) {
  2169. nodeA = this.startContainer;
  2170. posA = this.startOffset;
  2171. }
  2172. if (how === _START_TO_END || how === _END_TO_END) {
  2173. nodeA = this.endContainer;
  2174. posA = this.endOffset;
  2175. }
  2176. if (how === _START_TO_START || how === _START_TO_END) {
  2177. nodeB = range.startContainer;
  2178. posB = range.startOffset;
  2179. }
  2180. if (how === _END_TO_END || how === _END_TO_START) {
  2181. nodeB = range.endContainer;
  2182. posB = range.endOffset;
  2183. }
  2184. if (nodeA === nodeB) {
  2185. var diff = posA - posB;
  2186. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2187. }
  2188. nodeC = nodeB;
  2189. while (nodeC && nodeC.parentNode !== nodeA) {
  2190. nodeC = nodeC.parentNode;
  2191. }
  2192. if (nodeC) {
  2193. return K(nodeC).index() >= posA ? -1 : 1;
  2194. }
  2195. nodeC = nodeA;
  2196. while (nodeC && nodeC.parentNode !== nodeB) {
  2197. nodeC = nodeC.parentNode;
  2198. }
  2199. if (nodeC) {
  2200. return K(nodeC).index() >= posB ? 1 : -1;
  2201. }
  2202. nodeC = K(nodeB).next();
  2203. if (nodeC && nodeC.contains(nodeA)) {
  2204. return 1;
  2205. }
  2206. nodeC = K(nodeA).next();
  2207. if (nodeC && nodeC.contains(nodeB)) {
  2208. return -1;
  2209. }
  2210. } else {
  2211. return rangeA.compareBoundaryPoints(how, rangeB);
  2212. }
  2213. },
  2214. cloneRange : function() {
  2215. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2216. },
  2217. toString : function() {
  2218. var rng = this.get(), str = _IE ? rng.text : rng.toString();
  2219. return str.replace(/\r\n|\n|\r/g, '');
  2220. },
  2221. cloneContents : function() {
  2222. return _copyAndDelete(this, true, false);
  2223. },
  2224. deleteContents : function() {
  2225. return _copyAndDelete(this, false, true);
  2226. },
  2227. extractContents : function() {
  2228. return _copyAndDelete(this, true, true);
  2229. },
  2230. insertNode : function(node) {
  2231. var self = this,
  2232. sc = self.startContainer, so = self.startOffset,
  2233. ec = self.endContainer, eo = self.endOffset,
  2234. firstChild, lastChild, c, nodeCount = 1;
  2235. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2236. firstChild = node.firstChild;
  2237. lastChild = node.lastChild;
  2238. nodeCount = node.childNodes.length;
  2239. }
  2240. if (sc.nodeType == 1) {
  2241. c = sc.childNodes[so];
  2242. if (c) {
  2243. sc.insertBefore(node, c);
  2244. if (sc === ec) {
  2245. eo += nodeCount;
  2246. }
  2247. } else {
  2248. sc.appendChild(node);
  2249. }
  2250. } else if (sc.nodeType == 3) {
  2251. if (so === 0) {
  2252. sc.parentNode.insertBefore(node, sc);
  2253. if (sc.parentNode === ec) {
  2254. eo += nodeCount;
  2255. }
  2256. } else if (so >= sc.nodeValue.length) {
  2257. if (sc.nextSibling) {
  2258. sc.parentNode.insertBefore(node, sc.nextSibling);
  2259. } else {
  2260. sc.parentNode.appendChild(node);
  2261. }
  2262. } else {
  2263. if (so > 0) {
  2264. c = sc.splitText(so);
  2265. } else {
  2266. c = sc;
  2267. }
  2268. sc.parentNode.insertBefore(node, c);
  2269. if (sc === ec) {
  2270. ec = c;
  2271. eo -= so;
  2272. }
  2273. }
  2274. }
  2275. if (firstChild) {
  2276. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2277. } else {
  2278. self.selectNode(node);
  2279. }
  2280. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2281. return self;
  2282. }
  2283. return self.setEnd(ec, eo);
  2284. },
  2285. surroundContents : function(node) {
  2286. node.appendChild(this.extractContents());
  2287. return this.insertNode(node).selectNode(node);
  2288. },
  2289. isControl : function() {
  2290. var self = this,
  2291. sc = self.startContainer, so = self.startOffset,
  2292. ec = self.endContainer, eo = self.endOffset, rng;
  2293. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2294. },
  2295. get : function(hasControlRange) {
  2296. var self = this, doc = self.doc, node, rng;
  2297. if (!_IE) {
  2298. rng = doc.createRange();
  2299. try {
  2300. rng.setStart(self.startContainer, self.startOffset);
  2301. rng.setEnd(self.endContainer, self.endOffset);
  2302. } catch (e) {}
  2303. return rng;
  2304. }
  2305. if (hasControlRange && self.isControl()) {
  2306. rng = doc.body.createControlRange();
  2307. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2308. return rng;
  2309. }
  2310. var range = self.cloneRange().down();
  2311. rng = doc.body.createTextRange();
  2312. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2313. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2314. return rng;
  2315. },
  2316. html : function() {
  2317. return K(this.cloneContents()).outer();
  2318. },
  2319. down : function() {
  2320. var self = this;
  2321. function downPos(node, pos, isStart) {
  2322. if (node.nodeType != 1) {
  2323. return;
  2324. }
  2325. var children = K(node).children();
  2326. if (children.length === 0) {
  2327. return;
  2328. }
  2329. var left, right, child, offset;
  2330. if (pos > 0) {
  2331. left = children.eq(pos - 1);
  2332. }
  2333. if (pos < children.length) {
  2334. right = children.eq(pos);
  2335. }
  2336. if (left && left.type == 3) {
  2337. child = left[0];
  2338. offset = child.nodeValue.length;
  2339. }
  2340. if (right && right.type == 3) {
  2341. child = right[0];
  2342. offset = 0;
  2343. }
  2344. if (!child) {
  2345. return;
  2346. }
  2347. if (isStart) {
  2348. self.setStart(child, offset);
  2349. } else {
  2350. self.setEnd(child, offset);
  2351. }
  2352. }
  2353. downPos(self.startContainer, self.startOffset, true);
  2354. downPos(self.endContainer, self.endOffset, false);
  2355. return self;
  2356. },
  2357. up : function() {
  2358. var self = this;
  2359. function upPos(node, pos, isStart) {
  2360. if (node.nodeType != 3) {
  2361. return;
  2362. }
  2363. if (pos === 0) {
  2364. if (isStart) {
  2365. self.setStartBefore(node);
  2366. } else {
  2367. self.setEndBefore(node);
  2368. }
  2369. } else if (pos == node.nodeValue.length) {
  2370. if (isStart) {
  2371. self.setStartAfter(node);
  2372. } else {
  2373. self.setEndAfter(node);
  2374. }
  2375. }
  2376. }
  2377. upPos(self.startContainer, self.startOffset, true);
  2378. upPos(self.endContainer, self.endOffset, false);
  2379. return self;
  2380. },
  2381. enlarge : function(toBlock) {
  2382. var self = this;
  2383. self.up();
  2384. function enlargePos(node, pos, isStart) {
  2385. var knode = K(node), parent;
  2386. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2387. return;
  2388. }
  2389. if (pos === 0) {
  2390. while (!knode.prev()) {
  2391. parent = knode.parent();
  2392. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2393. break;
  2394. }
  2395. knode = parent;
  2396. }
  2397. if (isStart) {
  2398. self.setStartBefore(knode[0]);
  2399. } else {
  2400. self.setEndBefore(knode[0]);
  2401. }
  2402. } else if (pos == knode.children().length) {
  2403. while (!knode.next()) {
  2404. parent = knode.parent();
  2405. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2406. break;
  2407. }
  2408. knode = parent;
  2409. }
  2410. if (isStart) {
  2411. self.setStartAfter(knode[0]);
  2412. } else {
  2413. self.setEndAfter(knode[0]);
  2414. }
  2415. }
  2416. }
  2417. enlargePos(self.startContainer, self.startOffset, true);
  2418. enlargePos(self.endContainer, self.endOffset, false);
  2419. return self;
  2420. },
  2421. shrink : function() {
  2422. var self = this, child, collapsed = self.collapsed;
  2423. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2424. self.setStart(child, 0);
  2425. }
  2426. if (collapsed) {
  2427. return self.collapse(collapsed);
  2428. }
  2429. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2430. self.setEnd(child, child.childNodes.length);
  2431. }
  2432. return self;
  2433. },
  2434. createBookmark : function(serialize) {
  2435. var self = this, doc = self.doc, endNode,
  2436. startNode = K('<span style="display:none;"></span>', doc)[0];
  2437. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2438. if (!self.collapsed) {
  2439. endNode = startNode.cloneNode(true);
  2440. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2441. }
  2442. if (endNode) {
  2443. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2444. }
  2445. self.insertNode(startNode).setStartAfter(startNode);
  2446. return {
  2447. start : serialize ? '#' + startNode.id : startNode,
  2448. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2449. };
  2450. },
  2451. moveToBookmark : function(bookmark) {
  2452. var self = this, doc = self.doc,
  2453. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2454. if (!start || start.length < 1) {
  2455. return self;
  2456. }
  2457. self.setStartBefore(start[0]);
  2458. start.remove();
  2459. if (end && end.length > 0) {
  2460. self.setEndBefore(end[0]);
  2461. end.remove();
  2462. } else {
  2463. self.collapse(true);
  2464. }
  2465. return self;
  2466. },
  2467. dump : function() {
  2468. console.log('--------------------');
  2469. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2470. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2471. }
  2472. });
  2473. function _range(mixed) {
  2474. if (!mixed.nodeName) {
  2475. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2476. }
  2477. return new KRange(mixed);
  2478. }
  2479. K.RangeClass = KRange;
  2480. K.range = _range;
  2481. K.START_TO_START = _START_TO_START;
  2482. K.START_TO_END = _START_TO_END;
  2483. K.END_TO_END = _END_TO_END;
  2484. K.END_TO_START = _END_TO_START;
  2485. function _nativeCommand(doc, key, val) {
  2486. try {
  2487. doc.execCommand(key, false, val);
  2488. } catch(e) {}
  2489. }
  2490. function _nativeCommandValue(doc, key) {
  2491. var val = '';
  2492. try {
  2493. val = doc.queryCommandValue(key);
  2494. } catch (e) {}
  2495. if (typeof val !== 'string') {
  2496. val = '';
  2497. }
  2498. return val;
  2499. }
  2500. function _getSel(doc) {
  2501. var win = _getWin(doc);
  2502. return doc.selection || win.getSelection();
  2503. }
  2504. function _getRng(doc) {
  2505. var sel = _getSel(doc), rng;
  2506. try {
  2507. if (sel.rangeCount > 0) {
  2508. rng = sel.getRangeAt(0);
  2509. } else {
  2510. rng = sel.createRange();
  2511. }
  2512. } catch(e) {}
  2513. if (_IE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2514. return null;
  2515. }
  2516. return rng;
  2517. }
  2518. function _singleKeyMap(map) {
  2519. var newMap = {}, arr, v;
  2520. _each(map, function(key, val) {
  2521. arr = key.split(',');
  2522. for (var i = 0, len = arr.length; i < len; i++) {
  2523. v = arr[i];
  2524. newMap[v] = val;
  2525. }
  2526. });
  2527. return newMap;
  2528. }
  2529. function _hasAttrOrCss(knode, map) {
  2530. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2531. }
  2532. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2533. mapKey = mapKey || knode.name;
  2534. if (knode.type !== 1) {
  2535. return false;
  2536. }
  2537. var newMap = _singleKeyMap(map);
  2538. if (!newMap[mapKey]) {
  2539. return false;
  2540. }
  2541. var arr = newMap[mapKey].split(',');
  2542. for (var i = 0, len = arr.length; i < len; i++) {
  2543. var key = arr[i];
  2544. if (key === '*') {
  2545. return true;
  2546. }
  2547. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2548. var method = match[1] ? 'css' : 'attr';
  2549. key = match[2];
  2550. var val = match[3] || '';
  2551. if (val === '' && knode[method](key) !== '') {
  2552. return true;
  2553. }
  2554. if (val !== '' && knode[method](key) === val) {
  2555. return true;
  2556. }
  2557. }
  2558. return false;
  2559. }
  2560. function _removeAttrOrCss(knode, map) {
  2561. if (knode.type != 1) {
  2562. return;
  2563. }
  2564. _removeAttrOrCssByKey(knode, map, '*');
  2565. _removeAttrOrCssByKey(knode, map);
  2566. }
  2567. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2568. mapKey = mapKey || knode.name;
  2569. if (knode.type !== 1) {
  2570. return;
  2571. }
  2572. var newMap = _singleKeyMap(map);
  2573. if (!newMap[mapKey]) {
  2574. return;
  2575. }
  2576. var arr = newMap[mapKey].split(','), allFlag = false;
  2577. for (var i = 0, len = arr.length; i < len; i++) {
  2578. var key = arr[i];
  2579. if (key === '*') {
  2580. allFlag = true;
  2581. break;
  2582. }
  2583. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2584. key = match[2];
  2585. if (match[1]) {
  2586. key = _toCamel(key);
  2587. if (knode[0].style[key]) {
  2588. knode[0].style[key] = '';
  2589. }
  2590. } else {
  2591. knode.removeAttr(key);
  2592. }
  2593. }
  2594. if (allFlag) {
  2595. knode.remove(true);
  2596. }
  2597. }
  2598. function _getInnerNode(knode) {
  2599. var inner = knode;
  2600. while (inner.first()) {
  2601. inner = inner.first();
  2602. }
  2603. return inner;
  2604. }
  2605. function _isEmptyNode(knode) {
  2606. if (knode.type != 1 || knode.isSingle()) {
  2607. return false;
  2608. }
  2609. return knode.html().replace(/<[^>]+>/g, '') === '';
  2610. }
  2611. function _mergeWrapper(a, b) {
  2612. a = a.clone(true);
  2613. var lastA = _getInnerNode(a), childA = a, merged = false;
  2614. while (b) {
  2615. while (childA) {
  2616. if (childA.name === b.name) {
  2617. _mergeAttrs(childA, b.attr(), b.css());
  2618. merged = true;
  2619. }
  2620. childA = childA.first();
  2621. }
  2622. if (!merged) {
  2623. lastA.append(b.clone(false));
  2624. }
  2625. merged = false;
  2626. b = b.first();
  2627. }
  2628. return a;
  2629. }
  2630. function _wrapNode(knode, wrapper) {
  2631. wrapper = wrapper.clone(true);
  2632. if (knode.type == 3) {
  2633. _getInnerNode(wrapper).append(knode.clone(false));
  2634. knode.replaceWith(wrapper);
  2635. return wrapper;
  2636. }
  2637. var nodeWrapper = knode, child;
  2638. while ((child = knode.first()) && child.children().length == 1) {
  2639. knode = child;
  2640. }
  2641. child = knode.first();
  2642. var frag = knode.doc.createDocumentFragment();
  2643. while (child) {
  2644. frag.appendChild(child[0]);
  2645. child = child.next();
  2646. }
  2647. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2648. if (frag.firstChild) {
  2649. _getInnerNode(wrapper).append(frag);
  2650. }
  2651. nodeWrapper.replaceWith(wrapper);
  2652. return wrapper;
  2653. }
  2654. function _mergeAttrs(knode, attrs, styles) {
  2655. _each(attrs, function(key, val) {
  2656. if (key !== 'style') {
  2657. knode.attr(key, val);
  2658. }
  2659. });
  2660. _each(styles, function(key, val) {
  2661. knode.css(key, val);
  2662. });
  2663. }
  2664. function _inPreElement(knode) {
  2665. while (knode && knode.name != 'body') {
  2666. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2667. return true;
  2668. }
  2669. knode = knode.parent();
  2670. }
  2671. return false;
  2672. }
  2673. function KCmd(range) {
  2674. this.init(range);
  2675. }
  2676. _extend(KCmd, {
  2677. init : function(range) {
  2678. var self = this, doc = range.doc;
  2679. self.doc = doc;
  2680. self.win = _getWin(doc);
  2681. self.sel = _getSel(doc);
  2682. self.range = range;
  2683. },
  2684. selection : function(forceReset) {
  2685. var self = this, doc = self.doc, rng = _getRng(doc);
  2686. self.sel = _getSel(doc);
  2687. if (rng) {
  2688. self.range = _range(rng);
  2689. if (K(self.range.startContainer).name == 'html') {
  2690. self.range.selectNodeContents(doc.body).collapse(false);
  2691. }
  2692. return self;
  2693. }
  2694. if (forceReset) {
  2695. self.range.selectNodeContents(doc.body).collapse(false);
  2696. }
  2697. return self;
  2698. },
  2699. select : function(hasDummy) {
  2700. hasDummy = _undef(hasDummy, true);
  2701. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2702. sc = range.startContainer, so = range.startOffset,
  2703. ec = range.endContainer, eo = range.endOffset,
  2704. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2705. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2706. if (_IE) {
  2707. var dummy = K('<span>&nbsp;</span>', doc);
  2708. range.insertNode(dummy[0]);
  2709. rng = doc.body.createTextRange();
  2710. try {
  2711. rng.moveToElementText(dummy[0]);
  2712. } catch(ex) {}
  2713. rng.collapse(false);
  2714. rng.select();
  2715. dummy.remove();
  2716. win.focus();
  2717. return self;
  2718. }
  2719. if (_WEBKIT) {
  2720. var children = sc.childNodes;
  2721. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2722. range.insertNode(doc.createTextNode('\u200B'));
  2723. hasU200b = true;
  2724. }
  2725. }
  2726. }
  2727. if (_IE) {
  2728. try {
  2729. rng = range.get(true);
  2730. rng.select();
  2731. } catch(e) {}
  2732. } else {
  2733. if (hasU200b) {
  2734. range.collapse(false);
  2735. }
  2736. rng = range.get(true);
  2737. sel.removeAllRanges();
  2738. sel.addRange(rng);
  2739. if (doc !== document) {
  2740. var pos = K(rng.endContainer).pos();
  2741. win.scrollTo(pos.x, pos.y);
  2742. }
  2743. }
  2744. win.focus();
  2745. return self;
  2746. },
  2747. wrap : function(val) {
  2748. var self = this, doc = self.doc, range = self.range, wrapper;
  2749. wrapper = K(val, doc);
  2750. if (range.collapsed) {
  2751. range.shrink();
  2752. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2753. return self;
  2754. }
  2755. if (wrapper.isBlock()) {
  2756. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2757. while (child.first()) {
  2758. child = child.first();
  2759. }
  2760. child.append(range.extractContents());
  2761. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2762. return self;
  2763. }
  2764. range.enlarge();
  2765. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2766. K(ancestor).scan(function(node) {
  2767. if (!isStart && node == bookmark.start) {
  2768. isStart = true;
  2769. return;
  2770. }
  2771. if (isStart) {
  2772. if (node == bookmark.end) {
  2773. return false;
  2774. }
  2775. var knode = K(node);
  2776. if (_inPreElement(knode)) {
  2777. return;
  2778. }
  2779. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2780. var parent;
  2781. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2782. knode = parent;
  2783. }
  2784. _wrapNode(knode, wrapper);
  2785. }
  2786. }
  2787. });
  2788. range.moveToBookmark(bookmark);
  2789. return self;
  2790. },
  2791. split : function(isStart, map) {
  2792. var range = this.range, doc = range.doc;
  2793. var tempRange = range.cloneRange().collapse(isStart);
  2794. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2795. parent = node.nodeType == 3 ? node.parentNode : node,
  2796. needSplit = false, knode;
  2797. while (parent && parent.parentNode) {
  2798. knode = K(parent);
  2799. if (map) {
  2800. if (!knode.isStyle()) {
  2801. break;
  2802. }
  2803. if (!_hasAttrOrCss(knode, map)) {
  2804. break;
  2805. }
  2806. } else {
  2807. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2808. break;
  2809. }
  2810. }
  2811. needSplit = true;
  2812. parent = parent.parentNode;
  2813. }
  2814. if (needSplit) {
  2815. var dummy = doc.createElement('span');
  2816. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2817. if (isStart) {
  2818. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2819. } else {
  2820. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2821. }
  2822. var frag = tempRange.extractContents(),
  2823. first = frag.firstChild, last = frag.lastChild;
  2824. if (isStart) {
  2825. tempRange.insertNode(frag);
  2826. range.setStartAfter(last).setEndBefore(dummy);
  2827. } else {
  2828. parent.appendChild(frag);
  2829. range.setStartBefore(dummy).setEndBefore(first);
  2830. }
  2831. var dummyParent = dummy.parentNode;
  2832. if (dummyParent == range.endContainer) {
  2833. var prev = K(dummy).prev(), next = K(dummy).next();
  2834. if (prev && next && prev.type == 3 && next.type == 3) {
  2835. range.setEnd(prev[0], prev[0].nodeValue.length);
  2836. } else if (!isStart) {
  2837. range.setEnd(range.endContainer, range.endOffset - 1);
  2838. }
  2839. }
  2840. dummyParent.removeChild(dummy);
  2841. }
  2842. return this;
  2843. },
  2844. remove : function(map) {
  2845. var self = this, doc = self.doc, range = self.range;
  2846. range.enlarge();
  2847. if (range.startOffset === 0) {
  2848. var ksc = K(range.startContainer), parent;
  2849. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2850. ksc = parent;
  2851. }
  2852. range.setStart(ksc[0], 0);
  2853. ksc = K(range.startContainer);
  2854. if (ksc.isBlock()) {
  2855. _removeAttrOrCss(ksc, map);
  2856. }
  2857. var kscp = ksc.parent();
  2858. if (kscp && kscp.isBlock()) {
  2859. _removeAttrOrCss(kscp, map);
  2860. }
  2861. }
  2862. var sc, so;
  2863. if (range.collapsed) {
  2864. self.split(true, map);
  2865. sc = range.startContainer;
  2866. so = range.startOffset;
  2867. if (so > 0) {
  2868. var sb = K(sc.childNodes[so - 1]);
  2869. if (sb && _isEmptyNode(sb)) {
  2870. sb.remove();
  2871. range.setStart(sc, so - 1);
  2872. }
  2873. }
  2874. var sa = K(sc.childNodes[so]);
  2875. if (sa && _isEmptyNode(sa)) {
  2876. sa.remove();
  2877. }
  2878. if (_isEmptyNode(sc)) {
  2879. range.startBefore(sc);
  2880. sc.remove();
  2881. }
  2882. range.collapse(true);
  2883. return self;
  2884. }
  2885. self.split(true, map);
  2886. self.split(false, map);
  2887. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2888. range.cloneRange().collapse(false).insertNode(endDummy);
  2889. range.cloneRange().collapse(true).insertNode(startDummy);
  2890. var nodeList = [], cmpStart = false;
  2891. K(range.commonAncestor()).scan(function(node) {
  2892. if (!cmpStart && node == startDummy) {
  2893. cmpStart = true;
  2894. return;
  2895. }
  2896. if (node == endDummy) {
  2897. return false;
  2898. }
  2899. if (cmpStart) {
  2900. nodeList.push(node);
  2901. }
  2902. });
  2903. K(startDummy).remove();
  2904. K(endDummy).remove();
  2905. sc = range.startContainer;
  2906. so = range.startOffset;
  2907. var ec = range.endContainer, eo = range.endOffset;
  2908. if (so > 0) {
  2909. var startBefore = K(sc.childNodes[so - 1]);
  2910. if (startBefore && _isEmptyNode(startBefore)) {
  2911. startBefore.remove();
  2912. range.setStart(sc, so - 1);
  2913. if (sc == ec) {
  2914. range.setEnd(ec, eo - 1);
  2915. }
  2916. }
  2917. var startAfter = K(sc.childNodes[so]);
  2918. if (startAfter && _isEmptyNode(startAfter)) {
  2919. startAfter.remove();
  2920. if (sc == ec) {
  2921. range.setEnd(ec, eo - 1);
  2922. }
  2923. }
  2924. }
  2925. var endAfter = K(ec.childNodes[range.endOffset]);
  2926. if (endAfter && _isEmptyNode(endAfter)) {
  2927. endAfter.remove();
  2928. }
  2929. var bookmark = range.createBookmark(true);
  2930. _each(nodeList, function(i, node) {
  2931. _removeAttrOrCss(K(node), map);
  2932. });
  2933. range.moveToBookmark(bookmark);
  2934. return self;
  2935. },
  2936. commonNode : function(map) {
  2937. var range = this.range;
  2938. var ec = range.endContainer, eo = range.endOffset,
  2939. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2940. function find(node) {
  2941. var child = node, parent = node;
  2942. while (parent) {
  2943. if (_hasAttrOrCss(K(parent), map)) {
  2944. return K(parent);
  2945. }
  2946. parent = parent.parentNode;
  2947. }
  2948. while (child && (child = child.lastChild)) {
  2949. if (_hasAttrOrCss(K(child), map)) {
  2950. return K(child);
  2951. }
  2952. }
  2953. return null;
  2954. }
  2955. var cNode = find(node);
  2956. if (cNode) {
  2957. return cNode;
  2958. }
  2959. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2960. var prev = K(node).prev();
  2961. if (prev) {
  2962. return find(prev);
  2963. }
  2964. }
  2965. return null;
  2966. },
  2967. commonAncestor : function(tagName) {
  2968. var range = this.range,
  2969. sc = range.startContainer, so = range.startOffset,
  2970. ec = range.endContainer, eo = range.endOffset,
  2971. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2972. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2973. function find(node) {
  2974. while (node) {
  2975. if (node.nodeType == 1) {
  2976. if (node.tagName.toLowerCase() === tagName) {
  2977. return node;
  2978. }
  2979. }
  2980. node = node.parentNode;
  2981. }
  2982. return null;
  2983. }
  2984. var start = find(startNode), end = find(endNode);
  2985. if (start && end && start === end) {
  2986. return K(start);
  2987. }
  2988. return null;
  2989. },
  2990. state : function(key) {
  2991. var self = this, doc = self.doc, bool = false;
  2992. try {
  2993. bool = doc.queryCommandState(key);
  2994. } catch (e) {}
  2995. return bool;
  2996. },
  2997. val : function(key) {
  2998. var self = this, doc = self.doc, range = self.range;
  2999. function lc(val) {
  3000. return val.toLowerCase();
  3001. }
  3002. key = lc(key);
  3003. var val = '', knode;
  3004. if (key === 'fontfamily' || key === 'fontname') {
  3005. val = _nativeCommandValue(doc, 'fontname');
  3006. val = val.replace(/['"]/g, '');
  3007. return lc(val);
  3008. }
  3009. if (key === 'formatblock') {
  3010. val = _nativeCommandValue(doc, key);
  3011. if (val === '') {
  3012. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3013. if (knode) {
  3014. val = knode.name;
  3015. }
  3016. }
  3017. if (val === 'Normal') {
  3018. val = 'p';
  3019. }
  3020. return lc(val);
  3021. }
  3022. if (key === 'fontsize') {
  3023. knode = self.commonNode({'*' : '.font-size'});
  3024. if (knode) {
  3025. val = knode.css('font-size');
  3026. }
  3027. return lc(val);
  3028. }
  3029. if (key === 'forecolor') {
  3030. knode = self.commonNode({'*' : '.color'});
  3031. if (knode) {
  3032. val = knode.css('color');
  3033. }
  3034. val = _toHex(val);
  3035. if (val === '') {
  3036. val = 'default';
  3037. }
  3038. return lc(val);
  3039. }
  3040. if (key === 'hilitecolor') {
  3041. knode = self.commonNode({'*' : '.background-color'});
  3042. if (knode) {
  3043. val = knode.css('background-color');
  3044. }
  3045. val = _toHex(val);
  3046. if (val === '') {
  3047. val = 'default';
  3048. }
  3049. return lc(val);
  3050. }
  3051. return val;
  3052. },
  3053. toggle : function(wrapper, map) {
  3054. var self = this;
  3055. if (self.commonNode(map)) {
  3056. self.remove(map);
  3057. } else {
  3058. self.wrap(wrapper);
  3059. }
  3060. return self.select();
  3061. },
  3062. bold : function() {
  3063. return this.toggle('<strong></strong>', {
  3064. span : '.font-weight=bold',
  3065. strong : '*',
  3066. b : '*'
  3067. });
  3068. },
  3069. italic : function() {
  3070. return this.toggle('<em></em>', {
  3071. span : '.font-style=italic',
  3072. em : '*',
  3073. i : '*'
  3074. });
  3075. },
  3076. underline : function() {
  3077. return this.toggle('<u></u>', {
  3078. span : '.text-decoration=underline',
  3079. u : '*'
  3080. });
  3081. },
  3082. strikethrough : function() {
  3083. return this.toggle('<s></s>', {
  3084. span : '.text-decoration=line-through',
  3085. s : '*'
  3086. });
  3087. },
  3088. forecolor : function(val) {
  3089. return this.toggle('<span style="color:' + val + ';"></span>', {
  3090. span : '.color=' + val,
  3091. font : 'color'
  3092. });
  3093. },
  3094. hilitecolor : function(val) {
  3095. return this.toggle('<span style="background-color:' + val + ';"></span>', {
  3096. span : '.background-color=' + val
  3097. });
  3098. },
  3099. fontsize : function(val) {
  3100. return this.toggle('<span style="font-size:' + val + ';"></span>', {
  3101. span : '.font-size=' + val,
  3102. font : 'size'
  3103. });
  3104. },
  3105. fontname : function(val) {
  3106. return this.fontfamily(val);
  3107. },
  3108. fontfamily : function(val) {
  3109. return this.toggle('<span style="font-family:' + val + ';"></span>', {
  3110. span : '.font-family=' + val,
  3111. font : 'face'
  3112. });
  3113. },
  3114. removeformat : function() {
  3115. var map = {
  3116. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3117. },
  3118. tags = _STYLE_TAG_MAP;
  3119. _each(tags, function(key, val) {
  3120. map[key] = '*';
  3121. });
  3122. this.remove(map);
  3123. return this.select();
  3124. },
  3125. inserthtml : function(val, quickMode) {
  3126. var self = this, range = self.range;
  3127. if (val === '') {
  3128. return self;
  3129. }
  3130. function pasteHtml(range, val) {
  3131. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3132. var rng = range.get();
  3133. if (rng.item) {
  3134. rng.item(0).outerHTML = val;
  3135. } else {
  3136. rng.pasteHTML(val);
  3137. }
  3138. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3139. temp.parentNode.removeChild(temp);
  3140. var newRange = _toRange(rng);
  3141. range.setEnd(newRange.endContainer, newRange.endOffset);
  3142. range.collapse(false);
  3143. self.select(false);
  3144. }
  3145. function insertHtml(range, val) {
  3146. var doc = range.doc,
  3147. frag = doc.createDocumentFragment();
  3148. K('@' + val, doc).each(function() {
  3149. frag.appendChild(this);
  3150. });
  3151. range.deleteContents();
  3152. range.insertNode(frag);
  3153. range.collapse(false);
  3154. self.select(false);
  3155. }
  3156. if (_IE && quickMode) {
  3157. try {
  3158. pasteHtml(range, val);
  3159. } catch(e) {
  3160. insertHtml(range, val);
  3161. }
  3162. return self;
  3163. }
  3164. insertHtml(range, val);
  3165. return self;
  3166. },
  3167. hr : function() {
  3168. return this.inserthtml('<hr />');
  3169. },
  3170. print : function() {
  3171. this.win.print();
  3172. return this;
  3173. },
  3174. insertimage : function(url, title, width, height, border, align) {
  3175. title = _undef(title, '');
  3176. border = _undef(border, 0);
  3177. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3178. if (width) {
  3179. html += 'width="' + _escape(width) + '" ';
  3180. }
  3181. if (height) {
  3182. html += 'height="' + _escape(height) + '" ';
  3183. }
  3184. if (title) {
  3185. html += 'title="' + _escape(title) + '" ';
  3186. }
  3187. if (align) {
  3188. html += 'align="' + _escape(align) + '" ';
  3189. }
  3190. html += 'alt="' + _escape(title) + '" ';
  3191. html += '/>';
  3192. return this.inserthtml(html);
  3193. },
  3194. createlink : function(url, type) {
  3195. var self = this, doc = self.doc, range = self.range;
  3196. self.select();
  3197. var a = self.commonNode({ a : '*' });
  3198. if (a && !range.isControl()) {
  3199. range.selectNode(a.get());
  3200. self.select();
  3201. }
  3202. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3203. if (type) {
  3204. html += ' target="' + _escape(type) + '"';
  3205. }
  3206. if (range.collapsed) {
  3207. html += '>' + _escape(url) + '</a>';
  3208. return self.inserthtml(html);
  3209. }
  3210. if (range.isControl()) {
  3211. var node = K(range.startContainer.childNodes[range.startOffset]);
  3212. html += '></a>';
  3213. node.after(K(html, doc));
  3214. node.next().append(node);
  3215. range.selectNode(node[0]);
  3216. return self.select();
  3217. }
  3218. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3219. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3220. K(this).attr('href', url).attr('data-ke-src', url);
  3221. if (type) {
  3222. K(this).attr('target', type);
  3223. } else {
  3224. K(this).removeAttr('target');
  3225. }
  3226. });
  3227. return self;
  3228. },
  3229. unlink : function() {
  3230. var self = this, doc = self.doc, range = self.range;
  3231. self.select();
  3232. if (range.collapsed) {
  3233. var a = self.commonNode({ a : '*' });
  3234. if (a) {
  3235. range.selectNode(a.get());
  3236. self.select();
  3237. }
  3238. _nativeCommand(doc, 'unlink', null);
  3239. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3240. var parent = K(range.startContainer).parent();
  3241. if (parent.name === 'a') {
  3242. parent.remove(true);
  3243. }
  3244. }
  3245. } else {
  3246. _nativeCommand(doc, 'unlink', null);
  3247. }
  3248. return self;
  3249. }
  3250. });
  3251. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3252. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3253. KCmd.prototype[name] = function(val) {
  3254. var self = this;
  3255. self.select();
  3256. _nativeCommand(self.doc, name, val);
  3257. if (!_IE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3258. self.selection();
  3259. }
  3260. return self;
  3261. };
  3262. });
  3263. _each('cut,copy,paste'.split(','), function(i, name) {
  3264. KCmd.prototype[name] = function() {
  3265. var self = this;
  3266. if (!self.doc.queryCommandSupported(name)) {
  3267. throw 'not supported';
  3268. }
  3269. self.select();
  3270. _nativeCommand(self.doc, name, null);
  3271. return self;
  3272. };
  3273. });
  3274. function _cmd(mixed) {
  3275. if (mixed.nodeName) {
  3276. var doc = _getDoc(mixed);
  3277. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3278. }
  3279. return new KCmd(mixed);
  3280. }
  3281. K.CmdClass = KCmd;
  3282. K.cmd = _cmd;
  3283. function _drag(options) {
  3284. var moveEl = options.moveEl,
  3285. moveFn = options.moveFn,
  3286. clickEl = options.clickEl || moveEl,
  3287. beforeDrag = options.beforeDrag,
  3288. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3289. var docs = [document];
  3290. if (iframeFix) {
  3291. K('iframe').each(function() {
  3292. var src = _formatUrl(this.src || '', 'absolute');
  3293. if (/^https?:\/\//.test(src)) {
  3294. return;
  3295. }
  3296. var doc;
  3297. try {
  3298. doc = _iframeDoc(this);
  3299. } catch(e) {}
  3300. if (doc) {
  3301. var pos = K(this).pos();
  3302. K(doc).data('pos-x', pos.x);
  3303. K(doc).data('pos-y', pos.y);
  3304. docs.push(doc);
  3305. }
  3306. });
  3307. }
  3308. clickEl.mousedown(function(e) {
  3309. e.stopPropagation();
  3310. var self = clickEl.get(),
  3311. x = _removeUnit(moveEl.css('left')),
  3312. y = _removeUnit(moveEl.css('top')),
  3313. width = moveEl.width(),
  3314. height = moveEl.height(),
  3315. pageX = e.pageX,
  3316. pageY = e.pageY;
  3317. if (beforeDrag) {
  3318. beforeDrag();
  3319. }
  3320. function moveListener(e) {
  3321. e.preventDefault();
  3322. var kdoc = K(_getDoc(e.target));
  3323. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3324. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3325. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3326. }
  3327. function selectListener(e) {
  3328. e.preventDefault();
  3329. }
  3330. function upListener(e) {
  3331. e.preventDefault();
  3332. K(docs).unbind('mousemove', moveListener)
  3333. .unbind('mouseup', upListener)
  3334. .unbind('selectstart', selectListener);
  3335. if (self.releaseCapture) {
  3336. self.releaseCapture();
  3337. }
  3338. }
  3339. K(docs).mousemove(moveListener)
  3340. .mouseup(upListener)
  3341. .bind('selectstart', selectListener);
  3342. if (self.setCapture) {
  3343. self.setCapture();
  3344. }
  3345. });
  3346. }
  3347. function KWidget(options) {
  3348. this.init(options);
  3349. }
  3350. _extend(KWidget, {
  3351. init : function(options) {
  3352. var self = this;
  3353. self.name = options.name || '';
  3354. self.doc = options.doc || document;
  3355. self.win = _getWin(self.doc);
  3356. self.x = _addUnit(options.x);
  3357. self.y = _addUnit(options.y);
  3358. self.z = options.z;
  3359. self.width = _addUnit(options.width);
  3360. self.height = _addUnit(options.height);
  3361. self.div = K('<div style="display:block;"></div>');
  3362. self.options = options;
  3363. self._alignEl = options.alignEl;
  3364. if (self.width) {
  3365. self.div.css('width', self.width);
  3366. }
  3367. if (self.height) {
  3368. self.div.css('height', self.height);
  3369. }
  3370. if (self.z) {
  3371. self.div.css({
  3372. position : 'absolute',
  3373. left : self.x,
  3374. top : self.y,
  3375. 'z-index' : self.z
  3376. });
  3377. }
  3378. if (self.z && (self.x === undefined || self.y === undefined)) {
  3379. self.autoPos(self.width, self.height);
  3380. }
  3381. if (options.cls) {
  3382. self.div.addClass(options.cls);
  3383. }
  3384. if (options.shadowMode) {
  3385. self.div.addClass('ke-shadow');
  3386. }
  3387. if (options.css) {
  3388. self.div.css(options.css);
  3389. }
  3390. if (options.src) {
  3391. K(options.src).replaceWith(self.div);
  3392. } else {
  3393. K(self.doc.body).append(self.div);
  3394. }
  3395. if (options.html) {
  3396. self.div.html(options.html);
  3397. }
  3398. if (options.autoScroll) {
  3399. if (_IE && _V < 7 || _QUIRKS) {
  3400. var scrollPos = _getScrollPos();
  3401. K(self.win).bind('scroll', function(e) {
  3402. var pos = _getScrollPos(),
  3403. diffX = pos.x - scrollPos.x,
  3404. diffY = pos.y - scrollPos.y;
  3405. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3406. });
  3407. } else {
  3408. self.div.css('position', 'fixed');
  3409. }
  3410. }
  3411. },
  3412. pos : function(x, y, updateProp) {
  3413. var self = this;
  3414. updateProp = _undef(updateProp, true);
  3415. if (x !== null) {
  3416. x = x < 0 ? 0 : _addUnit(x);
  3417. self.div.css('left', x);
  3418. if (updateProp) {
  3419. self.x = x;
  3420. }
  3421. }
  3422. if (y !== null) {
  3423. y = y < 0 ? 0 : _addUnit(y);
  3424. self.div.css('top', y);
  3425. if (updateProp) {
  3426. self.y = y;
  3427. }
  3428. }
  3429. return self;
  3430. },
  3431. autoPos : function(width, height) {
  3432. var self = this,
  3433. w = _removeUnit(width) || 0,
  3434. h = _removeUnit(height) || 0,
  3435. scrollPos = _getScrollPos();
  3436. if (self._alignEl) {
  3437. var knode = K(self._alignEl),
  3438. pos = knode.pos(),
  3439. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3440. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3441. x = diffX < 0 ? pos.x : pos.x + diffX;
  3442. y = diffY < 0 ? pos.y : pos.y + diffY;
  3443. } else {
  3444. var docEl = _docElement(self.doc);
  3445. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3446. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3447. }
  3448. if (!(_IE && _V < 7 || _QUIRKS)) {
  3449. x -= scrollPos.x;
  3450. y -= scrollPos.y;
  3451. }
  3452. return self.pos(x, y);
  3453. },
  3454. remove : function() {
  3455. var self = this;
  3456. if (_IE && _V < 7 || _QUIRKS) {
  3457. K(self.win).unbind('scroll');
  3458. }
  3459. self.div.remove();
  3460. _each(self, function(i) {
  3461. self[i] = null;
  3462. });
  3463. return this;
  3464. },
  3465. show : function() {
  3466. this.div.show();
  3467. return this;
  3468. },
  3469. hide : function() {
  3470. this.div.hide();
  3471. return this;
  3472. },
  3473. draggable : function(options) {
  3474. var self = this;
  3475. options = options || {};
  3476. options.moveEl = self.div;
  3477. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3478. if ((x = x + diffX) < 0) {
  3479. x = 0;
  3480. }
  3481. if ((y = y + diffY) < 0) {
  3482. y = 0;
  3483. }
  3484. self.pos(x, y);
  3485. };
  3486. _drag(options);
  3487. return self;
  3488. }
  3489. });
  3490. function _widget(options) {
  3491. return new KWidget(options);
  3492. }
  3493. K.WidgetClass = KWidget;
  3494. K.widget = _widget;
  3495. function _iframeDoc(iframe) {
  3496. iframe = _get(iframe);
  3497. return iframe.contentDocument || iframe.contentWindow.document;
  3498. }
  3499. var html, _direction = '';
  3500. if ((html = document.getElementsByTagName('html'))) {
  3501. _direction = html[0].dir;
  3502. }
  3503. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3504. var arr = [
  3505. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3506. '<head><meta charset="utf-8" /><title></title>',
  3507. '<style>',
  3508. 'html {margin:0;padding:0;}',
  3509. 'body {margin:0;padding:5px;}',
  3510. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3511. 'body, p, div {word-wrap: break-word;}',
  3512. 'p {margin:5px 0;}',
  3513. 'table {border-collapse:collapse;}',
  3514. 'img {border:0;}',
  3515. 'noscript {display:none;}',
  3516. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3517. 'img.ke-flash {',
  3518. ' border:1px solid #AAA;',
  3519. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3520. ' background-position:center center;',
  3521. ' background-repeat:no-repeat;',
  3522. ' width:100px;',
  3523. ' height:100px;',
  3524. '}',
  3525. 'img.ke-rm {',
  3526. ' border:1px solid #AAA;',
  3527. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3528. ' background-position:center center;',
  3529. ' background-repeat:no-repeat;',
  3530. ' width:100px;',
  3531. ' height:100px;',
  3532. '}',
  3533. 'img.ke-media {',
  3534. ' border:1px solid #AAA;',
  3535. ' background-image:url(' + themesPath + 'common/media.gif);',
  3536. ' background-position:center center;',
  3537. ' background-repeat:no-repeat;',
  3538. ' width:100px;',
  3539. ' height:100px;',
  3540. '}',
  3541. 'img.ke-anchor {',
  3542. ' border:1px dashed #666;',
  3543. ' width:16px;',
  3544. ' height:16px;',
  3545. '}',
  3546. '.ke-script, .ke-noscript, .ke-display-none {',
  3547. ' display:none;',
  3548. ' font-size:0;',
  3549. ' width:0;',
  3550. ' height:0;',
  3551. '}',
  3552. '.ke-pagebreak {',
  3553. ' border:1px dotted #AAA;',
  3554. ' font-size:0;',
  3555. ' height:2px;',
  3556. '}',
  3557. '</style>'
  3558. ];
  3559. if (!_isArray(cssPath)) {
  3560. cssPath = [cssPath];
  3561. }
  3562. _each(cssPath, function(i, path) {
  3563. if (path) {
  3564. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3565. }
  3566. });
  3567. if (cssData) {
  3568. arr.push('<style>' + cssData + '</style>');
  3569. }
  3570. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3571. return arr.join('\n');
  3572. }
  3573. function _elementVal(knode, val) {
  3574. if (knode.hasVal()) {
  3575. if (val === undefined) {
  3576. var html = knode.val();
  3577. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3578. return html;
  3579. }
  3580. return knode.val(val);
  3581. }
  3582. return knode.html(val);
  3583. }
  3584. function KEdit(options) {
  3585. this.init(options);
  3586. }
  3587. _extend(KEdit, KWidget, {
  3588. init : function(options) {
  3589. var self = this;
  3590. KEdit.parent.init.call(self, options);
  3591. self.srcElement = K(options.srcElement);
  3592. self.div.addClass('ke-edit');
  3593. self.designMode = _undef(options.designMode, true);
  3594. self.beforeGetHtml = options.beforeGetHtml;
  3595. self.beforeSetHtml = options.beforeSetHtml;
  3596. self.afterSetHtml = options.afterSetHtml;
  3597. var themesPath = _undef(options.themesPath, ''),
  3598. bodyClass = options.bodyClass,
  3599. cssPath = options.cssPath,
  3600. cssData = options.cssData,
  3601. isDocumentDomain = location.host.replace(/:\d+/, '') !== document.domain,
  3602. srcScript = ('document.open();' +
  3603. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3604. 'document.close();'),
  3605. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3606. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3607. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3608. if (self.width) {
  3609. self.setWidth(self.width);
  3610. }
  3611. if (self.height) {
  3612. self.setHeight(self.height);
  3613. }
  3614. if (self.designMode) {
  3615. self.textarea.hide();
  3616. } else {
  3617. self.iframe.hide();
  3618. }
  3619. function ready() {
  3620. var doc = _iframeDoc(self.iframe);
  3621. doc.open();
  3622. if (isDocumentDomain) {
  3623. doc.domain = document.domain;
  3624. }
  3625. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3626. doc.close();
  3627. self.win = self.iframe[0].contentWindow;
  3628. self.doc = doc;
  3629. var cmd = _cmd(doc);
  3630. self.afterChange(function(e) {
  3631. cmd.selection();
  3632. });
  3633. if (_WEBKIT) {
  3634. K(doc).click(function(e) {
  3635. if (K(e.target).name === 'img') {
  3636. cmd.selection(true);
  3637. cmd.range.selectNode(e.target);
  3638. cmd.select();
  3639. }
  3640. });
  3641. }
  3642. if (_IE) {
  3643. self._mousedownHandler = function() {
  3644. var newRange = cmd.range.cloneRange();
  3645. newRange.shrink();
  3646. if (newRange.isControl()) {
  3647. self.blur();
  3648. }
  3649. };
  3650. K(document).mousedown(self._mousedownHandler);
  3651. K(doc).keydown(function(e) {
  3652. if (e.which == 8) {
  3653. cmd.selection();
  3654. var rng = cmd.range;
  3655. if (rng.isControl()) {
  3656. rng.collapse(true);
  3657. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3658. e.preventDefault();
  3659. }
  3660. }
  3661. });
  3662. }
  3663. self.cmd = cmd;
  3664. self.html(_elementVal(self.srcElement));
  3665. if (_IE) {
  3666. doc.body.disabled = true;
  3667. doc.body.contentEditable = true;
  3668. doc.body.removeAttribute('disabled');
  3669. } else {
  3670. doc.designMode = 'on';
  3671. }
  3672. if (options.afterCreate) {
  3673. options.afterCreate.call(self);
  3674. }
  3675. }
  3676. if (isDocumentDomain) {
  3677. self.iframe.bind('load', function(e) {
  3678. self.iframe.unbind('load');
  3679. if (_IE) {
  3680. ready();
  3681. } else {
  3682. setTimeout(ready, 0);
  3683. }
  3684. });
  3685. }
  3686. self.div.append(self.iframe);
  3687. self.div.append(self.textarea);
  3688. self.srcElement.hide();
  3689. !isDocumentDomain && ready();
  3690. },
  3691. setWidth : function(val) {
  3692. this.div.css('width', _addUnit(val));
  3693. return this;
  3694. },
  3695. setHeight : function(val) {
  3696. var self = this;
  3697. val = _addUnit(val);
  3698. self.div.css('height', val);
  3699. self.iframe.css('height', val);
  3700. if ((_IE && _V < 8) || _QUIRKS) {
  3701. val = _addUnit(_removeUnit(val) - 2);
  3702. }
  3703. self.textarea.css('height', val);
  3704. return self;
  3705. },
  3706. remove : function() {
  3707. var self = this, doc = self.doc;
  3708. K(doc.body).unbind();
  3709. K(doc).unbind();
  3710. K(self.win).unbind();
  3711. if (self._mousedownHandler) {
  3712. K(document).unbind('mousedown', self._mousedownHandler);
  3713. }
  3714. _elementVal(self.srcElement, self.html());
  3715. self.srcElement.show();
  3716. doc.write('');
  3717. self.iframe.unbind();
  3718. self.textarea.unbind();
  3719. KEdit.parent.remove.call(self);
  3720. },
  3721. html : function(val, isFull) {
  3722. var self = this, doc = self.doc;
  3723. if (self.designMode) {
  3724. var body = doc.body;
  3725. if (val === undefined) {
  3726. if (isFull) {
  3727. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3728. } else {
  3729. val = body.innerHTML;
  3730. }
  3731. if (self.beforeGetHtml) {
  3732. val = self.beforeGetHtml(val);
  3733. }
  3734. if (_GECKO && val == '<br />') {
  3735. val = '';
  3736. }
  3737. return val;
  3738. }
  3739. if (self.beforeSetHtml) {
  3740. val = self.beforeSetHtml(val);
  3741. }
  3742. if (_IE && _V >= 9) {
  3743. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3744. }
  3745. K(body).html(val);
  3746. if (self.afterSetHtml) {
  3747. self.afterSetHtml();
  3748. }
  3749. return self;
  3750. }
  3751. if (val === undefined) {
  3752. return self.textarea.val();
  3753. }
  3754. self.textarea.val(val);
  3755. return self;
  3756. },
  3757. design : function(bool) {
  3758. var self = this, val;
  3759. if (bool === undefined ? !self.designMode : bool) {
  3760. if (!self.designMode) {
  3761. val = self.html();
  3762. self.designMode = true;
  3763. self.html(val);
  3764. self.textarea.hide();
  3765. self.iframe.show();
  3766. }
  3767. } else {
  3768. if (self.designMode) {
  3769. val = self.html();
  3770. self.designMode = false;
  3771. self.html(val);
  3772. self.iframe.hide();
  3773. self.textarea.show();
  3774. }
  3775. }
  3776. return self.focus();
  3777. },
  3778. focus : function() {
  3779. var self = this;
  3780. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3781. return self;
  3782. },
  3783. blur : function() {
  3784. var self = this;
  3785. if (_IE) {
  3786. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3787. self.div.append(input);
  3788. input[0].focus();
  3789. input.remove();
  3790. } else {
  3791. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3792. }
  3793. return self;
  3794. },
  3795. afterChange : function(fn) {
  3796. var self = this, doc = self.doc, body = doc.body;
  3797. K(doc).keyup(function(e) {
  3798. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3799. fn(e);
  3800. }
  3801. });
  3802. K(doc).mouseup(fn).contextmenu(fn);
  3803. K(self.win).blur(fn);
  3804. function timeoutHandler(e) {
  3805. setTimeout(function() {
  3806. fn(e);
  3807. }, 1);
  3808. }
  3809. K(body).bind('paste', timeoutHandler);
  3810. K(body).bind('cut', timeoutHandler);
  3811. return self;
  3812. }
  3813. });
  3814. function _edit(options) {
  3815. return new KEdit(options);
  3816. }
  3817. K.EditClass = KEdit;
  3818. K.edit = _edit;
  3819. K.iframeDoc = _iframeDoc;
  3820. function _selectToolbar(name, fn) {
  3821. var self = this,
  3822. knode = self.get(name);
  3823. if (knode) {
  3824. if (knode.hasClass('ke-disabled')) {
  3825. return;
  3826. }
  3827. fn(knode);
  3828. }
  3829. }
  3830. function KToolbar(options) {
  3831. this.init(options);
  3832. }
  3833. _extend(KToolbar, KWidget, {
  3834. init : function(options) {
  3835. var self = this;
  3836. KToolbar.parent.init.call(self, options);
  3837. self.disableMode = _undef(options.disableMode, false);
  3838. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3839. self._itemMap = {};
  3840. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3841. e.preventDefault();
  3842. }).attr('unselectable', 'on');
  3843. function find(target) {
  3844. var knode = K(target);
  3845. if (knode.hasClass('ke-outline')) {
  3846. return knode;
  3847. }
  3848. if (knode.hasClass('ke-toolbar-icon')) {
  3849. return knode.parent();
  3850. }
  3851. }
  3852. function hover(e, method) {
  3853. var knode = find(e.target);
  3854. if (knode) {
  3855. if (knode.hasClass('ke-disabled')) {
  3856. return;
  3857. }
  3858. if (knode.hasClass('ke-selected')) {
  3859. return;
  3860. }
  3861. knode[method]('ke-on');
  3862. }
  3863. }
  3864. self.div.mouseover(function(e) {
  3865. hover(e, 'addClass');
  3866. })
  3867. .mouseout(function(e) {
  3868. hover(e, 'removeClass');
  3869. })
  3870. .click(function(e) {
  3871. var knode = find(e.target);
  3872. if (knode) {
  3873. if (knode.hasClass('ke-disabled')) {
  3874. return;
  3875. }
  3876. self.options.click.call(this, e, knode.attr('data-name'));
  3877. }
  3878. });
  3879. },
  3880. get : function(name) {
  3881. if (this._itemMap[name]) {
  3882. return this._itemMap[name];
  3883. }
  3884. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3885. },
  3886. select : function(name) {
  3887. _selectToolbar.call(this, name, function(knode) {
  3888. knode.addClass('ke-selected');
  3889. });
  3890. return self;
  3891. },
  3892. unselect : function(name) {
  3893. _selectToolbar.call(this, name, function(knode) {
  3894. knode.removeClass('ke-selected').removeClass('ke-on');
  3895. });
  3896. return self;
  3897. },
  3898. enable : function(name) {
  3899. var self = this,
  3900. knode = name.get ? name : self.get(name);
  3901. if (knode) {
  3902. knode.removeClass('ke-disabled');
  3903. knode.opacity(1);
  3904. }
  3905. return self;
  3906. },
  3907. disable : function(name) {
  3908. var self = this,
  3909. knode = name.get ? name : self.get(name);
  3910. if (knode) {
  3911. knode.removeClass('ke-selected').addClass('ke-disabled');
  3912. knode.opacity(0.5);
  3913. }
  3914. return self;
  3915. },
  3916. disableAll : function(bool, noDisableItems) {
  3917. var self = this, map = self.noDisableItemMap, item;
  3918. if (noDisableItems) {
  3919. map = _toMap(noDisableItems);
  3920. }
  3921. if (bool === undefined ? !self.disableMode : bool) {
  3922. K('span.ke-outline', self.div).each(function() {
  3923. var knode = K(this),
  3924. name = knode[0].getAttribute('data-name', 2);
  3925. if (!map[name]) {
  3926. self.disable(knode);
  3927. }
  3928. });
  3929. self.disableMode = true;
  3930. } else {
  3931. K('span.ke-outline', self.div).each(function() {
  3932. var knode = K(this),
  3933. name = knode[0].getAttribute('data-name', 2);
  3934. if (!map[name]) {
  3935. self.enable(knode);
  3936. }
  3937. });
  3938. self.disableMode = false;
  3939. }
  3940. return self;
  3941. }
  3942. });
  3943. function _toolbar(options) {
  3944. return new KToolbar(options);
  3945. }
  3946. K.ToolbarClass = KToolbar;
  3947. K.toolbar = _toolbar;
  3948. function KMenu(options) {
  3949. this.init(options);
  3950. }
  3951. _extend(KMenu, KWidget, {
  3952. init : function(options) {
  3953. var self = this;
  3954. options.z = options.z || 811213;
  3955. KMenu.parent.init.call(self, options);
  3956. self.centerLineMode = _undef(options.centerLineMode, true);
  3957. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  3958. e.stopPropagation();
  3959. }).attr('unselectable', 'on');
  3960. },
  3961. addItem : function(item) {
  3962. var self = this;
  3963. if (item.title === '-') {
  3964. self.div.append(K('<div class="ke-menu-separator"></div>'));
  3965. return;
  3966. }
  3967. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  3968. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  3969. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  3970. height = _addUnit(item.height),
  3971. iconClass = _undef(item.iconClass, '');
  3972. self.div.append(itemDiv);
  3973. if (height) {
  3974. itemDiv.css('height', height);
  3975. rightDiv.css('line-height', height);
  3976. }
  3977. var centerDiv;
  3978. if (self.centerLineMode) {
  3979. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  3980. if (height) {
  3981. centerDiv.css('height', height);
  3982. }
  3983. }
  3984. itemDiv.mouseover(function(e) {
  3985. K(this).addClass('ke-menu-item-on');
  3986. if (centerDiv) {
  3987. centerDiv.addClass('ke-menu-item-center-on');
  3988. }
  3989. })
  3990. .mouseout(function(e) {
  3991. K(this).removeClass('ke-menu-item-on');
  3992. if (centerDiv) {
  3993. centerDiv.removeClass('ke-menu-item-center-on');
  3994. }
  3995. })
  3996. .click(function(e) {
  3997. item.click.call(K(this));
  3998. e.stopPropagation();
  3999. })
  4000. .append(leftDiv);
  4001. if (centerDiv) {
  4002. itemDiv.append(centerDiv);
  4003. }
  4004. itemDiv.append(rightDiv);
  4005. if (item.checked) {
  4006. iconClass = 'ke-icon-checked';
  4007. }
  4008. if (iconClass !== '') {
  4009. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4010. }
  4011. rightDiv.html(item.title);
  4012. return self;
  4013. },
  4014. remove : function() {
  4015. var self = this;
  4016. if (self.options.beforeRemove) {
  4017. self.options.beforeRemove.call(self);
  4018. }
  4019. K('.ke-menu-item', self.div[0]).unbind();
  4020. KMenu.parent.remove.call(self);
  4021. return self;
  4022. }
  4023. });
  4024. function _menu(options) {
  4025. return new KMenu(options);
  4026. }
  4027. K.MenuClass = KMenu;
  4028. K.menu = _menu;
  4029. function KColorPicker(options) {
  4030. this.init(options);
  4031. }
  4032. _extend(KColorPicker, KWidget, {
  4033. init : function(options) {
  4034. var self = this;
  4035. options.z = options.z || 811213;
  4036. KColorPicker.parent.init.call(self, options);
  4037. var colors = options.colors || [
  4038. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4039. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4040. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4041. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4042. ];
  4043. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4044. self._cells = [];
  4045. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4046. e.stopPropagation();
  4047. }).attr('unselectable', 'on');
  4048. var table = self.doc.createElement('table');
  4049. self.div.append(table);
  4050. table.className = 'ke-colorpicker-table';
  4051. table.cellPadding = 0;
  4052. table.cellSpacing = 0;
  4053. table.border = 0;
  4054. var row = table.insertRow(0), cell = row.insertCell(0);
  4055. cell.colSpan = colors[0].length;
  4056. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4057. for (var i = 0; i < colors.length; i++) {
  4058. row = table.insertRow(i + 1);
  4059. for (var j = 0; j < colors[i].length; j++) {
  4060. cell = row.insertCell(j);
  4061. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4062. }
  4063. }
  4064. },
  4065. _addAttr : function(cell, color, cls) {
  4066. var self = this;
  4067. cell = K(cell).addClass(cls);
  4068. if (self.selectedColor === color.toLowerCase()) {
  4069. cell.addClass('ke-colorpicker-cell-selected');
  4070. }
  4071. cell.attr('title', color || self.options.noColor);
  4072. cell.mouseover(function(e) {
  4073. K(this).addClass('ke-colorpicker-cell-on');
  4074. });
  4075. cell.mouseout(function(e) {
  4076. K(this).removeClass('ke-colorpicker-cell-on');
  4077. });
  4078. cell.click(function(e) {
  4079. e.stop();
  4080. self.options.click.call(K(this), color);
  4081. });
  4082. if (color) {
  4083. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4084. } else {
  4085. cell.html(self.options.noColor);
  4086. }
  4087. K(cell).attr('unselectable', 'on');
  4088. self._cells.push(cell);
  4089. },
  4090. remove : function() {
  4091. var self = this;
  4092. _each(self._cells, function() {
  4093. this.unbind();
  4094. });
  4095. KColorPicker.parent.remove.call(self);
  4096. return self;
  4097. }
  4098. });
  4099. function _colorpicker(options) {
  4100. return new KColorPicker(options);
  4101. }
  4102. K.ColorPickerClass = KColorPicker;
  4103. K.colorpicker = _colorpicker;
  4104. function KUploadButton(options) {
  4105. this.init(options);
  4106. }
  4107. _extend(KUploadButton, {
  4108. init : function(options) {
  4109. var self = this,
  4110. button = K(options.button),
  4111. fieldName = options.fieldName || 'file',
  4112. url = options.url || '',
  4113. title = button.val(),
  4114. extraParams = options.extraParams || {},
  4115. cls = button[0].className || '',
  4116. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4117. options.afterError = options.afterError || function(str) {
  4118. alert(str);
  4119. };
  4120. var hiddenElements = [];
  4121. for(var k in extraParams){
  4122. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4123. }
  4124. var html = [
  4125. '<div class="ke-inline-block ' + cls + '">',
  4126. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4127. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4128. '<span class="ke-button-common">',
  4129. hiddenElements.join(''),
  4130. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4131. '</span>',
  4132. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4133. (options.form ? '</div>' : '</form>'),
  4134. '</div>'].join('');
  4135. var div = K(html, button.doc);
  4136. button.hide();
  4137. button.before(div);
  4138. self.div = div;
  4139. self.button = button;
  4140. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4141. self.form = options.form ? K(options.form) : K('form', div);
  4142. var width = options.width || K('.ke-button-common', div).width();
  4143. self.fileBox = K('.ke-upload-file', div).width(width);
  4144. self.options = options;
  4145. },
  4146. submit : function() {
  4147. var self = this,
  4148. iframe = self.iframe;
  4149. iframe.bind('load', function() {
  4150. iframe.unbind();
  4151. var tempForm = document.createElement('form');
  4152. self.fileBox.before(tempForm);
  4153. K(tempForm).append(self.fileBox);
  4154. tempForm.reset();
  4155. K(tempForm).remove(true);
  4156. var doc = K.iframeDoc(iframe),
  4157. pre = doc.getElementsByTagName('pre')[0],
  4158. str = '', data;
  4159. if (pre) {
  4160. str = pre.innerHTML;
  4161. } else {
  4162. str = doc.body.innerHTML;
  4163. }
  4164. str = _unescape(str);
  4165. iframe[0].src = 'javascript:false';
  4166. try {
  4167. data = K.json(str);
  4168. } catch (e) {
  4169. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4170. }
  4171. if (data) {
  4172. self.options.afterUpload.call(self, data);
  4173. }
  4174. });
  4175. self.form[0].submit();
  4176. return self;
  4177. },
  4178. remove : function() {
  4179. var self = this;
  4180. if (self.fileBox) {
  4181. self.fileBox.unbind();
  4182. }
  4183. self.iframe.remove();
  4184. self.div.remove();
  4185. self.button.show();
  4186. return self;
  4187. }
  4188. });
  4189. function _uploadbutton(options) {
  4190. return new KUploadButton(options);
  4191. }
  4192. K.UploadButtonClass = KUploadButton;
  4193. K.uploadbutton = _uploadbutton;
  4194. function _createButton(arg) {
  4195. arg = arg || {};
  4196. var name = arg.name || '',
  4197. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4198. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4199. if (arg.click) {
  4200. btn.click(arg.click);
  4201. }
  4202. span.append(btn);
  4203. return span;
  4204. }
  4205. function KDialog(options) {
  4206. this.init(options);
  4207. }
  4208. _extend(KDialog, KWidget, {
  4209. init : function(options) {
  4210. var self = this;
  4211. var shadowMode = _undef(options.shadowMode, true);
  4212. options.z = options.z || 811213;
  4213. options.shadowMode = false;
  4214. options.autoScroll = _undef(options.autoScroll, true);
  4215. KDialog.parent.init.call(self, options);
  4216. var title = options.title,
  4217. body = K(options.body, self.doc),
  4218. previewBtn = options.previewBtn,
  4219. yesBtn = options.yesBtn,
  4220. noBtn = options.noBtn,
  4221. closeBtn = options.closeBtn,
  4222. showMask = _undef(options.showMask, true);
  4223. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4224. e.stopPropagation();
  4225. });
  4226. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4227. if (_IE && _V < 7) {
  4228. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4229. } else if (shadowMode) {
  4230. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4231. }
  4232. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4233. contentDiv.append(headerDiv);
  4234. headerDiv.html(title);
  4235. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4236. headerDiv.append(self.closeIcon);
  4237. self.draggable({
  4238. clickEl : headerDiv,
  4239. beforeDrag : options.beforeDrag
  4240. });
  4241. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4242. contentDiv.append(bodyDiv);
  4243. bodyDiv.append(body);
  4244. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4245. if (previewBtn || yesBtn || noBtn) {
  4246. contentDiv.append(footerDiv);
  4247. }
  4248. _each([
  4249. { btn : previewBtn, name : 'preview' },
  4250. { btn : yesBtn, name : 'yes' },
  4251. { btn : noBtn, name : 'no' }
  4252. ], function() {
  4253. if (this.btn) {
  4254. var button = _createButton(this.btn);
  4255. button.addClass('ke-dialog-' + this.name);
  4256. footerDiv.append(button);
  4257. }
  4258. });
  4259. if (self.height) {
  4260. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4261. }
  4262. self.div.width(self.div.width());
  4263. self.div.height(self.div.height());
  4264. self.mask = null;
  4265. if (showMask) {
  4266. var docEl = _docElement(self.doc),
  4267. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4268. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4269. self.mask = _widget({
  4270. x : 0,
  4271. y : 0,
  4272. z : self.z - 1,
  4273. cls : 'ke-dialog-mask',
  4274. width : docWidth,
  4275. height : docHeight
  4276. });
  4277. }
  4278. self.autoPos(self.div.width(), self.div.height());
  4279. self.footerDiv = footerDiv;
  4280. self.bodyDiv = bodyDiv;
  4281. self.headerDiv = headerDiv;
  4282. self.isLoading = false;
  4283. },
  4284. setMaskIndex : function(z) {
  4285. var self = this;
  4286. self.mask.div.css('z-index', z);
  4287. },
  4288. showLoading : function(msg) {
  4289. msg = _undef(msg, '');
  4290. var self = this, body = self.bodyDiv;
  4291. 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>')
  4292. .width(body.width()).height(body.height())
  4293. .css('top', self.headerDiv.height() + 'px');
  4294. body.css('visibility', 'hidden').after(self.loading);
  4295. self.isLoading = true;
  4296. return self;
  4297. },
  4298. hideLoading : function() {
  4299. this.loading && this.loading.remove();
  4300. this.bodyDiv.css('visibility', 'visible');
  4301. this.isLoading = false;
  4302. return this;
  4303. },
  4304. remove : function() {
  4305. var self = this;
  4306. if (self.options.beforeRemove) {
  4307. self.options.beforeRemove.call(self);
  4308. }
  4309. self.mask && self.mask.remove();
  4310. self.iframeMask && self.iframeMask.remove();
  4311. self.closeIcon.unbind();
  4312. K('input', self.div).unbind();
  4313. K('button', self.div).unbind();
  4314. self.footerDiv.unbind();
  4315. self.bodyDiv.unbind();
  4316. self.headerDiv.unbind();
  4317. K('iframe', self.div).each(function() {
  4318. K(this).remove();
  4319. });
  4320. KDialog.parent.remove.call(self);
  4321. return self;
  4322. }
  4323. });
  4324. function _dialog(options) {
  4325. return new KDialog(options);
  4326. }
  4327. K.DialogClass = KDialog;
  4328. K.dialog = _dialog;
  4329. function _tabs(options) {
  4330. var self = _widget(options),
  4331. remove = self.remove,
  4332. afterSelect = options.afterSelect,
  4333. div = self.div,
  4334. liList = [];
  4335. div.addClass('ke-tabs')
  4336. .bind('contextmenu,mousedown,mousemove', function(e) {
  4337. e.preventDefault();
  4338. });
  4339. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4340. div.append(ul);
  4341. self.add = function(tab) {
  4342. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4343. li.data('tab', tab);
  4344. liList.push(li);
  4345. ul.append(li);
  4346. };
  4347. self.selectedIndex = 0;
  4348. self.select = function(index) {
  4349. self.selectedIndex = index;
  4350. _each(liList, function(i, li) {
  4351. li.unbind();
  4352. if (i === index) {
  4353. li.addClass('ke-tabs-li-selected');
  4354. K(li.data('tab').panel).show('');
  4355. } else {
  4356. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4357. .mouseover(function() {
  4358. K(this).addClass('ke-tabs-li-on');
  4359. })
  4360. .mouseout(function() {
  4361. K(this).removeClass('ke-tabs-li-on');
  4362. })
  4363. .click(function() {
  4364. self.select(i);
  4365. });
  4366. K(li.data('tab').panel).hide();
  4367. }
  4368. });
  4369. if (afterSelect) {
  4370. afterSelect.call(self, index);
  4371. }
  4372. };
  4373. self.remove = function() {
  4374. _each(liList, function() {
  4375. this.remove();
  4376. });
  4377. ul.remove();
  4378. remove.call(self);
  4379. };
  4380. return self;
  4381. }
  4382. K.tabs = _tabs;
  4383. function _loadScript(url, fn) {
  4384. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4385. script = document.createElement('script');
  4386. head.appendChild(script);
  4387. script.src = url;
  4388. script.charset = 'utf-8';
  4389. script.onload = script.onreadystatechange = function() {
  4390. if (!this.readyState || this.readyState === 'loaded') {
  4391. if (fn) {
  4392. fn();
  4393. }
  4394. script.onload = script.onreadystatechange = null;
  4395. head.removeChild(script);
  4396. }
  4397. };
  4398. }
  4399. function _chopQuery(url) {
  4400. var index = url.indexOf('?');
  4401. return index > 0 ? url.substr(0, index) : url;
  4402. }
  4403. function _loadStyle(url) {
  4404. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4405. link = document.createElement('link'),
  4406. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4407. var links = K('link[rel="stylesheet"]', head);
  4408. for (var i = 0, len = links.length; i < len; i++) {
  4409. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4410. return;
  4411. }
  4412. }
  4413. head.appendChild(link);
  4414. link.href = url;
  4415. link.rel = 'stylesheet';
  4416. }
  4417. function _ajax(url, fn, method, param, dataType) {
  4418. method = method || 'GET';
  4419. dataType = dataType || 'json';
  4420. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4421. xhr.open(method, url, true);
  4422. xhr.onreadystatechange = function () {
  4423. if (xhr.readyState == 4 && xhr.status == 200) {
  4424. if (fn) {
  4425. var data = _trim(xhr.responseText);
  4426. if (dataType == 'json') {
  4427. data = _json(data);
  4428. }
  4429. fn(data);
  4430. }
  4431. }
  4432. };
  4433. if (method == 'POST') {
  4434. var params = [];
  4435. _each(param, function(key, val) {
  4436. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4437. });
  4438. try {
  4439. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4440. } catch (e) {}
  4441. xhr.send(params.join('&'));
  4442. } else {
  4443. xhr.send(null);
  4444. }
  4445. }
  4446. K.loadScript = _loadScript;
  4447. K.loadStyle = _loadStyle;
  4448. K.ajax = _ajax;
  4449. var _plugins = {};
  4450. function _plugin(name, fn) {
  4451. if (name === undefined) {
  4452. return _plugins;
  4453. }
  4454. if (!fn) {
  4455. return _plugins[name];
  4456. }
  4457. _plugins[name] = fn;
  4458. }
  4459. var _language = {};
  4460. function _parseLangKey(key) {
  4461. var match, ns = 'core';
  4462. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4463. ns = match[1];
  4464. key = match[2];
  4465. }
  4466. return { ns : ns, key : key };
  4467. }
  4468. function _lang(mixed, langType) {
  4469. langType = langType === undefined ? K.options.langType : langType;
  4470. if (typeof mixed === 'string') {
  4471. if (!_language[langType]) {
  4472. return 'no language';
  4473. }
  4474. var pos = mixed.length - 1;
  4475. if (mixed.substr(pos) === '.') {
  4476. return _language[langType][mixed.substr(0, pos)];
  4477. }
  4478. var obj = _parseLangKey(mixed);
  4479. return _language[langType][obj.ns][obj.key];
  4480. }
  4481. _each(mixed, function(key, val) {
  4482. var obj = _parseLangKey(key);
  4483. if (!_language[langType]) {
  4484. _language[langType] = {};
  4485. }
  4486. if (!_language[langType][obj.ns]) {
  4487. _language[langType][obj.ns] = {};
  4488. }
  4489. _language[langType][obj.ns][obj.key] = val;
  4490. });
  4491. }
  4492. function _getImageFromRange(range, fn) {
  4493. if (range.collapsed) {
  4494. return;
  4495. }
  4496. range = range.cloneRange().up();
  4497. var sc = range.startContainer, so = range.startOffset;
  4498. if (!_WEBKIT && !range.isControl()) {
  4499. return;
  4500. }
  4501. var img = K(sc.childNodes[so]);
  4502. if (!img || img.name != 'img') {
  4503. return;
  4504. }
  4505. if (fn(img)) {
  4506. return img;
  4507. }
  4508. }
  4509. function _bindContextmenuEvent() {
  4510. var self = this, doc = self.edit.doc;
  4511. K(doc).contextmenu(function(e) {
  4512. if (self.menu) {
  4513. self.hideMenu();
  4514. }
  4515. if (!self.useContextmenu) {
  4516. e.preventDefault();
  4517. return;
  4518. }
  4519. if (self._contextmenus.length === 0) {
  4520. return;
  4521. }
  4522. var maxWidth = 0, items = [];
  4523. _each(self._contextmenus, function() {
  4524. if (this.title == '-') {
  4525. items.push(this);
  4526. return;
  4527. }
  4528. if (this.cond && this.cond()) {
  4529. items.push(this);
  4530. if (this.width && this.width > maxWidth) {
  4531. maxWidth = this.width;
  4532. }
  4533. }
  4534. });
  4535. while (items.length > 0 && items[0].title == '-') {
  4536. items.shift();
  4537. }
  4538. while (items.length > 0 && items[items.length - 1].title == '-') {
  4539. items.pop();
  4540. }
  4541. var prevItem = null;
  4542. _each(items, function(i) {
  4543. if (this.title == '-' && prevItem.title == '-') {
  4544. delete items[i];
  4545. }
  4546. prevItem = this;
  4547. });
  4548. if (items.length > 0) {
  4549. e.preventDefault();
  4550. var pos = K(self.edit.iframe).pos(),
  4551. menu = _menu({
  4552. x : pos.x + e.clientX,
  4553. y : pos.y + e.clientY,
  4554. width : maxWidth,
  4555. css : { visibility: 'hidden' },
  4556. shadowMode : self.shadowMode
  4557. });
  4558. _each(items, function() {
  4559. if (this.title) {
  4560. menu.addItem(this);
  4561. }
  4562. });
  4563. var docEl = _docElement(menu.doc),
  4564. menuHeight = menu.div.height();
  4565. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4566. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4567. }
  4568. menu.div.css('visibility', 'visible');
  4569. self.menu = menu;
  4570. }
  4571. });
  4572. }
  4573. function _bindNewlineEvent() {
  4574. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4575. if (_IE && newlineTag !== 'br') {
  4576. return;
  4577. }
  4578. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4579. return;
  4580. }
  4581. if (_OPERA && _V < 9) {
  4582. return;
  4583. }
  4584. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4585. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4586. function getAncestorTagName(range) {
  4587. var ancestor = K(range.commonAncestor());
  4588. while (ancestor) {
  4589. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4590. break;
  4591. }
  4592. ancestor = ancestor.parent();
  4593. }
  4594. return ancestor.name;
  4595. }
  4596. K(doc).keydown(function(e) {
  4597. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4598. return;
  4599. }
  4600. self.cmd.selection();
  4601. var tagName = getAncestorTagName(self.cmd.range);
  4602. if (tagName == 'marquee' || tagName == 'select') {
  4603. return;
  4604. }
  4605. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4606. e.preventDefault();
  4607. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4608. return;
  4609. }
  4610. if (!pSkipTagMap[tagName]) {
  4611. _nativeCommand(doc, 'formatblock', '<p>');
  4612. }
  4613. });
  4614. K(doc).keyup(function(e) {
  4615. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4616. return;
  4617. }
  4618. if (newlineTag == 'br') {
  4619. return;
  4620. }
  4621. if (_GECKO) {
  4622. var root = self.cmd.commonAncestor('p');
  4623. var a = self.cmd.commonAncestor('a');
  4624. if (a && a.text() == '') {
  4625. a.remove(true);
  4626. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4627. self.cmd.select();
  4628. }
  4629. return;
  4630. }
  4631. self.cmd.selection();
  4632. var tagName = getAncestorTagName(self.cmd.range);
  4633. if (tagName == 'marquee' || tagName == 'select') {
  4634. return;
  4635. }
  4636. if (!pSkipTagMap[tagName]) {
  4637. _nativeCommand(doc, 'formatblock', '<p>');
  4638. }
  4639. var div = self.cmd.commonAncestor('div');
  4640. if (div) {
  4641. var p = K('<p></p>'),
  4642. child = div[0].firstChild;
  4643. while (child) {
  4644. var next = child.nextSibling;
  4645. p.append(child);
  4646. child = next;
  4647. }
  4648. div.before(p);
  4649. div.remove();
  4650. self.cmd.range.selectNodeContents(p[0]);
  4651. self.cmd.select();
  4652. }
  4653. });
  4654. }
  4655. function _bindTabEvent() {
  4656. var self = this, doc = self.edit.doc;
  4657. K(doc).keydown(function(e) {
  4658. if (e.which == 9) {
  4659. e.preventDefault();
  4660. if (self.afterTab) {
  4661. self.afterTab.call(self, e);
  4662. return;
  4663. }
  4664. var cmd = self.cmd, range = cmd.range;
  4665. range.shrink();
  4666. if (range.collapsed && range.startContainer.nodeType == 1) {
  4667. range.insertNode(K('@&nbsp;', doc)[0]);
  4668. cmd.select();
  4669. }
  4670. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4671. }
  4672. });
  4673. }
  4674. function _bindFocusEvent() {
  4675. var self = this;
  4676. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4677. if (self.afterFocus) {
  4678. self.afterFocus.call(self, e);
  4679. }
  4680. }).blur(function(e) {
  4681. if (self.afterBlur) {
  4682. self.afterBlur.call(self, e);
  4683. }
  4684. });
  4685. }
  4686. function _removeBookmarkTag(html) {
  4687. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4688. }
  4689. function _removeTempTag(html) {
  4690. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4691. }
  4692. function _addBookmarkToStack(stack, bookmark) {
  4693. if (stack.length === 0) {
  4694. stack.push(bookmark);
  4695. return;
  4696. }
  4697. var prev = stack[stack.length - 1];
  4698. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4699. stack.push(bookmark);
  4700. }
  4701. }
  4702. function _undoToRedo(fromStack, toStack) {
  4703. var self = this, edit = self.edit,
  4704. body = edit.doc.body,
  4705. range, bookmark;
  4706. if (fromStack.length === 0) {
  4707. return self;
  4708. }
  4709. if (edit.designMode) {
  4710. range = self.cmd.range;
  4711. bookmark = range.createBookmark(true);
  4712. bookmark.html = body.innerHTML;
  4713. } else {
  4714. bookmark = {
  4715. html : body.innerHTML
  4716. };
  4717. }
  4718. _addBookmarkToStack(toStack, bookmark);
  4719. var prev = fromStack.pop();
  4720. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4721. prev = fromStack.pop();
  4722. }
  4723. if (edit.designMode) {
  4724. edit.html(prev.html);
  4725. if (prev.start) {
  4726. range.moveToBookmark(prev);
  4727. self.select();
  4728. }
  4729. } else {
  4730. K(body).html(_removeBookmarkTag(prev.html));
  4731. }
  4732. return self;
  4733. }
  4734. function KEditor(options) {
  4735. var self = this;
  4736. self.options = {};
  4737. function setOption(key, val) {
  4738. if (KEditor.prototype[key] === undefined) {
  4739. self[key] = val;
  4740. }
  4741. self.options[key] = val;
  4742. }
  4743. _each(options, function(key, val) {
  4744. setOption(key, options[key]);
  4745. });
  4746. _each(K.options, function(key, val) {
  4747. if (self[key] === undefined) {
  4748. setOption(key, val);
  4749. }
  4750. });
  4751. var se = K(self.srcElement || '<textarea/>');
  4752. if (!self.width) {
  4753. self.width = se[0].style.width || se.width();
  4754. }
  4755. if (!self.height) {
  4756. self.height = se[0].style.height || se.height();
  4757. }
  4758. setOption('width', _undef(self.width, self.minWidth));
  4759. setOption('height', _undef(self.height, self.minHeight));
  4760. setOption('width', _addUnit(self.width));
  4761. setOption('height', _addUnit(self.height));
  4762. if (_MOBILE && (!_IOS || _V < 534)) {
  4763. self.designMode = false;
  4764. }
  4765. self.srcElement = se;
  4766. self.initContent = '';
  4767. self.plugin = {};
  4768. self.isCreated = false;
  4769. self.isLoading = false;
  4770. self._handlers = {};
  4771. self._contextmenus = [];
  4772. self._undoStack = [];
  4773. self._redoStack = [];
  4774. self._calledPlugins = {};
  4775. self._firstAddBookmark = true;
  4776. self.menu = self.contextmenu = null;
  4777. self.dialogs = [];
  4778. }
  4779. KEditor.prototype = {
  4780. lang : function(mixed) {
  4781. return _lang(mixed, this.langType);
  4782. },
  4783. loadPlugin : function(name, fn) {
  4784. var self = this;
  4785. if (_plugins[name]) {
  4786. if (self._calledPlugins[name]) {
  4787. if (fn) {
  4788. fn.call(self);
  4789. }
  4790. return self;
  4791. }
  4792. _plugins[name].call(self, KindEditor);
  4793. if (fn) {
  4794. fn.call(self);
  4795. }
  4796. self._calledPlugins[name] = true;
  4797. return self;
  4798. }
  4799. if (self.isLoading) {
  4800. return self;
  4801. }
  4802. self.isLoading = true;
  4803. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4804. self.isLoading = false;
  4805. if (_plugins[name]) {
  4806. self.loadPlugin(name, fn);
  4807. }
  4808. });
  4809. return self;
  4810. },
  4811. handler : function(key, fn) {
  4812. var self = this;
  4813. if (!self._handlers[key]) {
  4814. self._handlers[key] = [];
  4815. }
  4816. if (_isFunction(fn)) {
  4817. self._handlers[key].push(fn);
  4818. return self;
  4819. }
  4820. _each(self._handlers[key], function() {
  4821. fn = this.call(self, fn);
  4822. });
  4823. return fn;
  4824. },
  4825. clickToolbar : function(name, fn) {
  4826. var self = this, key = 'clickToolbar' + name;
  4827. if (fn === undefined) {
  4828. if (self._handlers[key]) {
  4829. return self.handler(key);
  4830. }
  4831. self.loadPlugin(name, function() {
  4832. self.handler(key);
  4833. });
  4834. return self;
  4835. }
  4836. return self.handler(key, fn);
  4837. },
  4838. updateState : function() {
  4839. var self = this;
  4840. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4841. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4842. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4843. });
  4844. return self;
  4845. },
  4846. addContextmenu : function(item) {
  4847. this._contextmenus.push(item);
  4848. return this;
  4849. },
  4850. afterCreate : function(fn) {
  4851. return this.handler('afterCreate', fn);
  4852. },
  4853. beforeRemove : function(fn) {
  4854. return this.handler('beforeRemove', fn);
  4855. },
  4856. beforeGetHtml : function(fn) {
  4857. return this.handler('beforeGetHtml', fn);
  4858. },
  4859. beforeSetHtml : function(fn) {
  4860. return this.handler('beforeSetHtml', fn);
  4861. },
  4862. afterSetHtml : function(fn) {
  4863. return this.handler('afterSetHtml', fn);
  4864. },
  4865. create : function() {
  4866. var self = this, fullscreenMode = self.fullscreenMode;
  4867. if (self.isCreated) {
  4868. return self;
  4869. }
  4870. if (self.srcElement.data('kindeditor')) {
  4871. return self;
  4872. }
  4873. self.srcElement.data('kindeditor', 'true');
  4874. if (fullscreenMode) {
  4875. _docElement().style.overflow = 'hidden';
  4876. } else {
  4877. _docElement().style.overflow = '';
  4878. }
  4879. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4880. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4881. if ((_IE && _V < 8) || _QUIRKS) {
  4882. height = _addUnit(_removeUnit(height) + 2);
  4883. }
  4884. var container = self.container = K(self.layout);
  4885. if (fullscreenMode) {
  4886. K(document.body).append(container);
  4887. } else {
  4888. self.srcElement.before(container);
  4889. }
  4890. var toolbarDiv = K('.toolbar', container),
  4891. editDiv = K('.edit', container),
  4892. statusbar = self.statusbar = K('.statusbar', container);
  4893. container.removeClass('container')
  4894. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4895. if (fullscreenMode) {
  4896. container.css({
  4897. position : 'absolute',
  4898. left : 0,
  4899. top : 0,
  4900. 'z-index' : 811211
  4901. });
  4902. if (!_GECKO) {
  4903. self._scrollPos = _getScrollPos();
  4904. }
  4905. window.scrollTo(0, 0);
  4906. K(document.body).css({
  4907. 'height' : '1px',
  4908. 'overflow' : 'hidden'
  4909. });
  4910. K(document.body.parentNode).css('overflow', 'hidden');
  4911. self._fullscreenExecuted = true;
  4912. } else {
  4913. if (self._fullscreenExecuted) {
  4914. K(document.body).css({
  4915. 'height' : '',
  4916. 'overflow' : ''
  4917. });
  4918. K(document.body.parentNode).css('overflow', '');
  4919. }
  4920. if (self._scrollPos) {
  4921. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4922. }
  4923. }
  4924. var htmlList = [];
  4925. K.each(self.items, function(i, name) {
  4926. if (name == '|') {
  4927. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4928. } else if (name == '/') {
  4929. htmlList.push('<div class="ke-hr"></div>');
  4930. } else {
  4931. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4932. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4933. }
  4934. });
  4935. var toolbar = self.toolbar = _toolbar({
  4936. src : toolbarDiv,
  4937. html : htmlList.join(''),
  4938. noDisableItems : self.noDisableItems,
  4939. click : function(e, name) {
  4940. e.stop();
  4941. if (self.menu) {
  4942. var menuName = self.menu.name;
  4943. self.hideMenu();
  4944. if (menuName === name) {
  4945. return;
  4946. }
  4947. }
  4948. self.clickToolbar(name);
  4949. }
  4950. });
  4951. var editHeight = _removeUnit(height) - toolbar.div.height();
  4952. var edit = self.edit = _edit({
  4953. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  4954. src : editDiv,
  4955. srcElement : self.srcElement,
  4956. designMode : self.designMode,
  4957. themesPath : self.themesPath,
  4958. bodyClass : self.bodyClass,
  4959. cssPath : self.cssPath,
  4960. cssData : self.cssData,
  4961. beforeGetHtml : function(html) {
  4962. html = self.beforeGetHtml(html);
  4963. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  4964. },
  4965. beforeSetHtml : function(html) {
  4966. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  4967. return self.beforeSetHtml(html);
  4968. },
  4969. afterSetHtml : function() {
  4970. self.edit = edit = this;
  4971. self.afterSetHtml();
  4972. },
  4973. afterCreate : function() {
  4974. self.edit = edit = this;
  4975. self.cmd = edit.cmd;
  4976. self._docMousedownFn = function(e) {
  4977. if (self.menu) {
  4978. self.hideMenu();
  4979. }
  4980. };
  4981. K(edit.doc, document).mousedown(self._docMousedownFn);
  4982. _bindContextmenuEvent.call(self);
  4983. _bindNewlineEvent.call(self);
  4984. _bindTabEvent.call(self);
  4985. _bindFocusEvent.call(self);
  4986. edit.afterChange(function(e) {
  4987. if (!edit.designMode) {
  4988. return;
  4989. }
  4990. self.updateState();
  4991. self.addBookmark();
  4992. if (self.options.afterChange) {
  4993. self.options.afterChange.call(self);
  4994. }
  4995. });
  4996. edit.textarea.keyup(function(e) {
  4997. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  4998. if (self.options.afterChange) {
  4999. self.options.afterChange.call(self);
  5000. }
  5001. }
  5002. });
  5003. if (self.readonlyMode) {
  5004. self.readonly();
  5005. }
  5006. self.isCreated = true;
  5007. if (self.initContent === '') {
  5008. self.initContent = self.html();
  5009. }
  5010. self.afterCreate();
  5011. if (self.options.afterCreate) {
  5012. self.options.afterCreate.call(self);
  5013. }
  5014. }
  5015. });
  5016. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5017. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5018. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5019. if (self._fullscreenResizeHandler) {
  5020. K(window).unbind('resize', self._fullscreenResizeHandler);
  5021. self._fullscreenResizeHandler = null;
  5022. }
  5023. function initResize() {
  5024. if (statusbar.height() === 0) {
  5025. setTimeout(initResize, 100);
  5026. return;
  5027. }
  5028. self.resize(width, height, false);
  5029. }
  5030. initResize();
  5031. if (fullscreenMode) {
  5032. self._fullscreenResizeHandler = function(e) {
  5033. if (self.isCreated) {
  5034. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5035. }
  5036. };
  5037. K(window).bind('resize', self._fullscreenResizeHandler);
  5038. toolbar.select('fullscreen');
  5039. statusbar.first().css('visibility', 'hidden');
  5040. statusbar.last().css('visibility', 'hidden');
  5041. } else {
  5042. if (_GECKO) {
  5043. K(window).bind('scroll', function(e) {
  5044. self._scrollPos = _getScrollPos();
  5045. });
  5046. }
  5047. if (self.resizeType > 0) {
  5048. _drag({
  5049. moveEl : container,
  5050. clickEl : statusbar,
  5051. moveFn : function(x, y, width, height, diffX, diffY) {
  5052. height += diffY;
  5053. self.resize(null, height);
  5054. }
  5055. });
  5056. } else {
  5057. statusbar.first().css('visibility', 'hidden');
  5058. }
  5059. if (self.resizeType === 2) {
  5060. _drag({
  5061. moveEl : container,
  5062. clickEl : statusbar.last(),
  5063. moveFn : function(x, y, width, height, diffX, diffY) {
  5064. width += diffX;
  5065. height += diffY;
  5066. self.resize(width, height);
  5067. }
  5068. });
  5069. } else {
  5070. statusbar.last().css('visibility', 'hidden');
  5071. }
  5072. }
  5073. return self;
  5074. },
  5075. remove : function() {
  5076. var self = this;
  5077. if (!self.isCreated) {
  5078. return self;
  5079. }
  5080. self.beforeRemove();
  5081. self.srcElement.data('kindeditor', '');
  5082. if (self.menu) {
  5083. self.hideMenu();
  5084. }
  5085. _each(self.dialogs, function() {
  5086. self.hideDialog();
  5087. });
  5088. K(document).unbind('mousedown', self._docMousedownFn);
  5089. self.toolbar.remove();
  5090. self.edit.remove();
  5091. self.statusbar.last().unbind();
  5092. self.statusbar.unbind();
  5093. self.container.remove();
  5094. self.container = self.toolbar = self.edit = self.menu = null;
  5095. self.dialogs = [];
  5096. self.isCreated = false;
  5097. return self;
  5098. },
  5099. resize : function(width, height, updateProp) {
  5100. var self = this;
  5101. updateProp = _undef(updateProp, true);
  5102. if (width) {
  5103. if (!/%/.test(width)) {
  5104. width = _removeUnit(width);
  5105. width = width < self.minWidth ? self.minWidth : width;
  5106. }
  5107. self.container.css('width', _addUnit(width));
  5108. if (updateProp) {
  5109. self.width = _addUnit(width);
  5110. }
  5111. }
  5112. if (height) {
  5113. height = _removeUnit(height);
  5114. editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5115. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5116. self.edit.setHeight(editHeight);
  5117. if (updateProp) {
  5118. self.height = _addUnit(height);
  5119. }
  5120. }
  5121. return self;
  5122. },
  5123. select : function() {
  5124. this.isCreated && this.cmd.select();
  5125. return this;
  5126. },
  5127. html : function(val) {
  5128. var self = this;
  5129. if (val === undefined) {
  5130. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5131. }
  5132. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5133. if (self.isCreated) {
  5134. self.cmd.selection();
  5135. }
  5136. return self;
  5137. },
  5138. fullHtml : function() {
  5139. return this.isCreated ? this.edit.html(undefined, true) : '';
  5140. },
  5141. text : function(val) {
  5142. var self = this;
  5143. if (val === undefined) {
  5144. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5145. } else {
  5146. return self.html(_escape(val));
  5147. }
  5148. },
  5149. isEmpty : function() {
  5150. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5151. },
  5152. isDirty : function() {
  5153. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5154. },
  5155. selectedHtml : function() {
  5156. return this.isCreated ? this.cmd.range.html() : '';
  5157. },
  5158. count : function(mode) {
  5159. var self = this;
  5160. mode = (mode || 'html').toLowerCase();
  5161. if (mode === 'html') {
  5162. return _removeBookmarkTag(_removeTempTag(self.html())).length;
  5163. }
  5164. if (mode === 'text') {
  5165. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5166. }
  5167. return 0;
  5168. },
  5169. exec : function(key) {
  5170. key = key.toLowerCase();
  5171. var self = this, cmd = self.cmd,
  5172. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5173. if (changeFlag) {
  5174. self.addBookmark(false);
  5175. }
  5176. cmd[key].apply(cmd, _toArray(arguments, 1));
  5177. if (changeFlag) {
  5178. self.updateState();
  5179. self.addBookmark(false);
  5180. if (self.options.afterChange) {
  5181. self.options.afterChange.call(self);
  5182. }
  5183. }
  5184. return self;
  5185. },
  5186. insertHtml : function(val, quickMode) {
  5187. if (!this.isCreated) {
  5188. return this;
  5189. }
  5190. val = this.beforeSetHtml(val);
  5191. this.exec('inserthtml', val, quickMode);
  5192. return this;
  5193. },
  5194. appendHtml : function(val) {
  5195. this.html(this.html() + val);
  5196. if (this.isCreated) {
  5197. var cmd = this.cmd;
  5198. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5199. cmd.select();
  5200. }
  5201. return this;
  5202. },
  5203. sync : function() {
  5204. _elementVal(this.srcElement, this.html());
  5205. return this;
  5206. },
  5207. focus : function() {
  5208. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5209. return this;
  5210. },
  5211. blur : function() {
  5212. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5213. return this;
  5214. },
  5215. addBookmark : function(checkSize) {
  5216. checkSize = _undef(checkSize, true);
  5217. var self = this, edit = self.edit,
  5218. body = edit.doc.body,
  5219. html = _removeTempTag(body.innerHTML), bookmark;
  5220. if (checkSize && self._undoStack.length > 0) {
  5221. var prev = self._undoStack[self._undoStack.length - 1];
  5222. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5223. return self;
  5224. }
  5225. }
  5226. if (edit.designMode && !self._firstAddBookmark) {
  5227. var range = self.cmd.range;
  5228. bookmark = range.createBookmark(true);
  5229. bookmark.html = _removeTempTag(body.innerHTML);
  5230. range.moveToBookmark(bookmark);
  5231. } else {
  5232. bookmark = {
  5233. html : html
  5234. };
  5235. }
  5236. self._firstAddBookmark = false;
  5237. _addBookmarkToStack(self._undoStack, bookmark);
  5238. return self;
  5239. },
  5240. undo : function() {
  5241. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5242. },
  5243. redo : function() {
  5244. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5245. },
  5246. fullscreen : function(bool) {
  5247. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5248. return this.remove().create();
  5249. },
  5250. readonly : function(isReadonly) {
  5251. isReadonly = _undef(isReadonly, true);
  5252. var self = this, edit = self.edit, doc = edit.doc;
  5253. if (self.designMode) {
  5254. self.toolbar.disableAll(isReadonly, []);
  5255. } else {
  5256. _each(self.noDisableItems, function() {
  5257. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5258. });
  5259. }
  5260. if (_IE) {
  5261. doc.body.contentEditable = !isReadonly;
  5262. } else {
  5263. doc.designMode = isReadonly ? 'off' : 'on';
  5264. }
  5265. edit.textarea[0].disabled = isReadonly;
  5266. },
  5267. createMenu : function(options) {
  5268. var self = this,
  5269. name = options.name,
  5270. knode = self.toolbar.get(name),
  5271. pos = knode.pos();
  5272. options.x = pos.x;
  5273. options.y = pos.y + knode.height();
  5274. options.z = self.options.zIndex;
  5275. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5276. if (options.selectedColor !== undefined) {
  5277. options.cls = 'ke-colorpicker-' + self.themeType;
  5278. options.noColor = self.lang('noColor');
  5279. self.menu = _colorpicker(options);
  5280. } else {
  5281. options.cls = 'ke-menu-' + self.themeType;
  5282. options.centerLineMode = false;
  5283. self.menu = _menu(options);
  5284. }
  5285. return self.menu;
  5286. },
  5287. hideMenu : function() {
  5288. this.menu.remove();
  5289. this.menu = null;
  5290. return this;
  5291. },
  5292. hideContextmenu : function() {
  5293. this.contextmenu.remove();
  5294. this.contextmenu = null;
  5295. return this;
  5296. },
  5297. createDialog : function(options) {
  5298. var self = this, name = options.name;
  5299. options.z = self.options.zIndex;
  5300. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5301. options.closeBtn = _undef(options.closeBtn, {
  5302. name : self.lang('close'),
  5303. click : function(e) {
  5304. self.hideDialog();
  5305. if (_IE && self.cmd) {
  5306. self.cmd.select();
  5307. }
  5308. }
  5309. });
  5310. options.noBtn = _undef(options.noBtn, {
  5311. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5312. click : function(e) {
  5313. self.hideDialog();
  5314. if (_IE && self.cmd) {
  5315. self.cmd.select();
  5316. }
  5317. }
  5318. });
  5319. if (self.dialogAlignType != 'page') {
  5320. options.alignEl = self.container;
  5321. }
  5322. options.cls = 'ke-dialog-' + self.themeType;
  5323. if (self.dialogs.length > 0) {
  5324. var firstDialog = self.dialogs[0],
  5325. parentDialog = self.dialogs[self.dialogs.length - 1];
  5326. firstDialog.setMaskIndex(parentDialog.z + 2);
  5327. options.z = parentDialog.z + 3;
  5328. options.showMask = false;
  5329. }
  5330. var dialog = _dialog(options);
  5331. self.dialogs.push(dialog);
  5332. return dialog;
  5333. },
  5334. hideDialog : function() {
  5335. var self = this;
  5336. if (self.dialogs.length > 0) {
  5337. self.dialogs.pop().remove();
  5338. }
  5339. if (self.dialogs.length > 0) {
  5340. var firstDialog = self.dialogs[0],
  5341. parentDialog = self.dialogs[self.dialogs.length - 1];
  5342. firstDialog.setMaskIndex(parentDialog.z - 1);
  5343. }
  5344. return self;
  5345. },
  5346. errorDialog : function(html) {
  5347. var self = this;
  5348. var dialog = self.createDialog({
  5349. width : 750,
  5350. title : self.lang('uploadError'),
  5351. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5352. });
  5353. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5354. doc.open();
  5355. doc.write(html);
  5356. doc.close();
  5357. K(doc.body).css('background-color', '#FFF');
  5358. iframe[0].contentWindow.focus();
  5359. return self;
  5360. }
  5361. };
  5362. function _editor(options) {
  5363. return new KEditor(options);
  5364. }
  5365. _instances = [];
  5366. function _create(expr, options) {
  5367. options = options || {};
  5368. options.basePath = _undef(options.basePath, K.basePath);
  5369. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5370. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5371. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5372. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5373. var themeType = _undef(options.themeType, K.options.themeType);
  5374. _loadStyle(options.themesPath + 'default/default.css');
  5375. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5376. }
  5377. function create(editor) {
  5378. _each(_plugins, function(name, fn) {
  5379. fn.call(editor, KindEditor);
  5380. });
  5381. return editor.create();
  5382. }
  5383. var knode = K(expr);
  5384. if (!knode || knode.length === 0) {
  5385. return;
  5386. }
  5387. if (knode.length > 1) {
  5388. knode.each(function() {
  5389. _create(this, options);
  5390. });
  5391. return _instances[0];
  5392. }
  5393. options.srcElement = knode[0];
  5394. var editor = new KEditor(options);
  5395. _instances.push(editor);
  5396. if (_language[editor.langType]) {
  5397. return create(editor);
  5398. }
  5399. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5400. create(editor);
  5401. });
  5402. return editor;
  5403. }
  5404. function _eachEditor(expr, fn) {
  5405. K(expr).each(function(i, el) {
  5406. K.each(_instances, function(j, editor) {
  5407. if (editor && editor.srcElement[0] == el) {
  5408. fn.call(editor, j, editor);
  5409. return false;
  5410. }
  5411. });
  5412. });
  5413. }
  5414. K.remove = function(expr) {
  5415. _eachEditor(expr, function(i) {
  5416. this.remove();
  5417. _instances.splice(i, 1);
  5418. });
  5419. };
  5420. K.sync = function(expr) {
  5421. _eachEditor(expr, function() {
  5422. this.sync();
  5423. });
  5424. };
  5425. if (_IE && _V < 7) {
  5426. _nativeCommand(document, 'BackgroundImageCache', true);
  5427. }
  5428. K.EditorClass = KEditor;
  5429. K.editor = _editor;
  5430. K.create = _create;
  5431. K.instances = _instances;
  5432. K.plugin = _plugin;
  5433. K.lang = _lang;
  5434. _plugin('core', function(K) {
  5435. var self = this,
  5436. shortcutKeys = {
  5437. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5438. };
  5439. self.afterSetHtml(function() {
  5440. if (self.options.afterChange) {
  5441. self.options.afterChange.call(self);
  5442. }
  5443. });
  5444. self.afterCreate(function() {
  5445. if (self.syncType != 'form') {
  5446. return;
  5447. }
  5448. var el = K(self.srcElement), hasForm = false;
  5449. while ((el = el.parent())) {
  5450. if (el.name == 'form') {
  5451. hasForm = true;
  5452. break;
  5453. }
  5454. }
  5455. if (hasForm) {
  5456. el.bind('submit', function(e) {
  5457. self.sync();
  5458. K(window).bind('unload', function() {
  5459. self.edit.textarea.remove();
  5460. });
  5461. });
  5462. var resetBtn = K('[type="reset"]', el);
  5463. resetBtn.click(function() {
  5464. self.html(self.initContent);
  5465. self.cmd.selection();
  5466. });
  5467. self.beforeRemove(function() {
  5468. el.unbind();
  5469. resetBtn.unbind();
  5470. });
  5471. }
  5472. });
  5473. self.clickToolbar('source', function() {
  5474. if (self.edit.designMode) {
  5475. self.toolbar.disableAll(true);
  5476. self.edit.design(false);
  5477. self.toolbar.select('source');
  5478. } else {
  5479. self.toolbar.disableAll(false);
  5480. self.edit.design(true);
  5481. self.toolbar.unselect('source');
  5482. self.cmd.selection();
  5483. }
  5484. self.designMode = self.edit.designMode;
  5485. });
  5486. self.afterCreate(function() {
  5487. if (!self.designMode) {
  5488. self.toolbar.disableAll(true).select('source');
  5489. }
  5490. });
  5491. self.clickToolbar('fullscreen', function() {
  5492. self.fullscreen();
  5493. });
  5494. if (self.fullscreenShortcut) {
  5495. var loaded = false;
  5496. self.afterCreate(function() {
  5497. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5498. if (e.which == 27) {
  5499. setTimeout(function() {
  5500. self.fullscreen();
  5501. }, 0);
  5502. }
  5503. });
  5504. if (loaded) {
  5505. if (_IE && !self.designMode) {
  5506. return;
  5507. }
  5508. self.focus();
  5509. }
  5510. if (!loaded) {
  5511. loaded = true;
  5512. }
  5513. });
  5514. }
  5515. _each('undo,redo'.split(','), function(i, name) {
  5516. if (shortcutKeys[name]) {
  5517. self.afterCreate(function() {
  5518. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5519. self.clickToolbar(name);
  5520. });
  5521. });
  5522. }
  5523. self.clickToolbar(name, function() {
  5524. self[name]();
  5525. });
  5526. });
  5527. self.clickToolbar('formatblock', function() {
  5528. var blocks = self.lang('formatblock.formatBlock'),
  5529. heights = {
  5530. h1 : 28,
  5531. h2 : 24,
  5532. h3 : 18,
  5533. H4 : 14,
  5534. p : 12
  5535. },
  5536. curVal = self.cmd.val('formatblock'),
  5537. menu = self.createMenu({
  5538. name : 'formatblock',
  5539. width : self.langType == 'en' ? 200 : 150
  5540. });
  5541. _each(blocks, function(key, val) {
  5542. var style = 'font-size:' + heights[key] + 'px;';
  5543. if (key.charAt(0) === 'h') {
  5544. style += 'font-weight:bold;';
  5545. }
  5546. menu.addItem({
  5547. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5548. height : heights[key] + 12,
  5549. checked : (curVal === key || curVal === val),
  5550. click : function() {
  5551. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5552. }
  5553. });
  5554. });
  5555. });
  5556. self.clickToolbar('fontname', function() {
  5557. var curVal = self.cmd.val('fontname'),
  5558. menu = self.createMenu({
  5559. name : 'fontname',
  5560. width : 150
  5561. });
  5562. _each(self.lang('fontname.fontName'), function(key, val) {
  5563. menu.addItem({
  5564. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5565. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5566. click : function() {
  5567. self.exec('fontname', key).hideMenu();
  5568. }
  5569. });
  5570. });
  5571. });
  5572. self.clickToolbar('fontsize', function() {
  5573. var curVal = self.cmd.val('fontsize'),
  5574. menu = self.createMenu({
  5575. name : 'fontsize',
  5576. width : 150
  5577. });
  5578. _each(self.fontSizeTable, function(i, val) {
  5579. menu.addItem({
  5580. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5581. height : _removeUnit(val) + 12,
  5582. checked : curVal === val,
  5583. click : function() {
  5584. self.exec('fontsize', val).hideMenu();
  5585. }
  5586. });
  5587. });
  5588. });
  5589. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5590. self.clickToolbar(name, function() {
  5591. self.createMenu({
  5592. name : name,
  5593. selectedColor : self.cmd.val(name) || 'default',
  5594. colors : self.colorTable,
  5595. click : function(color) {
  5596. self.exec(name, color).hideMenu();
  5597. }
  5598. });
  5599. });
  5600. });
  5601. _each(('cut,copy,paste').split(','), function(i, name) {
  5602. self.clickToolbar(name, function() {
  5603. self.focus();
  5604. try {
  5605. self.exec(name, null);
  5606. } catch(e) {
  5607. alert(self.lang(name + 'Error'));
  5608. }
  5609. });
  5610. });
  5611. self.clickToolbar('about', function() {
  5612. var html = '<div style="margin:20px;">' +
  5613. '<div>KindEditor ' + _VERSION + '</div>' +
  5614. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5615. '</div>';
  5616. self.createDialog({
  5617. name : 'about',
  5618. width : 350,
  5619. title : self.lang('about'),
  5620. body : html
  5621. });
  5622. });
  5623. self.plugin.getSelectedLink = function() {
  5624. return self.cmd.commonAncestor('a');
  5625. };
  5626. self.plugin.getSelectedImage = function() {
  5627. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5628. return !/^ke-\w+$/i.test(img[0].className);
  5629. });
  5630. };
  5631. self.plugin.getSelectedFlash = function() {
  5632. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5633. return img[0].className == 'ke-flash';
  5634. });
  5635. };
  5636. self.plugin.getSelectedMedia = function() {
  5637. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5638. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5639. });
  5640. };
  5641. self.plugin.getSelectedAnchor = function() {
  5642. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5643. return img[0].className == 'ke-anchor';
  5644. });
  5645. };
  5646. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5647. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5648. _each('edit,delete'.split(','), function(j, val) {
  5649. self.addContextmenu({
  5650. title : self.lang(val + uName),
  5651. click : function() {
  5652. self.loadPlugin(name, function() {
  5653. self.plugin[name][val]();
  5654. self.hideMenu();
  5655. });
  5656. },
  5657. cond : self.plugin['getSelected' + uName],
  5658. width : 150,
  5659. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5660. });
  5661. });
  5662. self.addContextmenu({ title : '-' });
  5663. });
  5664. self.plugin.getSelectedTable = function() {
  5665. return self.cmd.commonAncestor('table');
  5666. };
  5667. self.plugin.getSelectedRow = function() {
  5668. return self.cmd.commonAncestor('tr');
  5669. };
  5670. self.plugin.getSelectedCell = function() {
  5671. return self.cmd.commonAncestor('td');
  5672. };
  5673. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5674. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5675. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5676. self.addContextmenu({
  5677. title : self.lang('table' + val),
  5678. click : function() {
  5679. self.loadPlugin('table', function() {
  5680. self.plugin.table[val]();
  5681. self.hideMenu();
  5682. });
  5683. },
  5684. cond : cond,
  5685. width : 170,
  5686. iconClass : 'ke-icon-table' + val
  5687. });
  5688. });
  5689. self.addContextmenu({ title : '-' });
  5690. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5691. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5692. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5693. if (shortcutKeys[name]) {
  5694. self.afterCreate(function() {
  5695. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5696. self.cmd.selection();
  5697. self.clickToolbar(name);
  5698. });
  5699. });
  5700. }
  5701. self.clickToolbar(name, function() {
  5702. self.focus().exec(name, null);
  5703. });
  5704. });
  5705. self.afterCreate(function() {
  5706. var doc = self.edit.doc, cmd, bookmark, div,
  5707. cls = '__kindeditor_paste__', pasting = false;
  5708. function movePastedData() {
  5709. cmd.range.moveToBookmark(bookmark);
  5710. cmd.select();
  5711. if (_WEBKIT) {
  5712. K('div.' + cls, div).each(function() {
  5713. K(this).after('<br />').remove(true);
  5714. });
  5715. K('span.Apple-style-span', div).remove(true);
  5716. K('span.Apple-tab-span', div).remove(true);
  5717. K('span[style]', div).each(function() {
  5718. if (K(this).css('white-space') == 'nowrap') {
  5719. K(this).remove(true);
  5720. }
  5721. });
  5722. K('meta', div).remove();
  5723. }
  5724. var html = div[0].innerHTML;
  5725. div.remove();
  5726. if (html === '') {
  5727. return;
  5728. }
  5729. if (_WEBKIT) {
  5730. html = html.replace(/(<br>)\1/ig, '$1');
  5731. }
  5732. if (self.pasteType === 2) {
  5733. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5734. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5735. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5736. } else {
  5737. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5738. html = self.beforeSetHtml(html);
  5739. }
  5740. }
  5741. if (self.pasteType === 1) {
  5742. html = html.replace(/&nbsp;/ig, ' ');
  5743. html = html.replace(/\n\s*\n/g, '\n');
  5744. html = html.replace(/<br[^>]*>/ig, '\n');
  5745. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5746. html = html.replace(/<[^>]+>/g, '');
  5747. html = html.replace(/ {2}/g, ' &nbsp;');
  5748. if (self.newlineTag == 'p') {
  5749. if (/\n/.test(html)) {
  5750. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5751. }
  5752. } else {
  5753. html = html.replace(/\n/g, '<br />$&');
  5754. }
  5755. }
  5756. self.insertHtml(html, true);
  5757. }
  5758. K(doc.body).bind('paste', function(e){
  5759. if (self.pasteType === 0) {
  5760. e.stop();
  5761. return;
  5762. }
  5763. if (pasting) {
  5764. return;
  5765. }
  5766. pasting = true;
  5767. K('div.' + cls, doc).remove();
  5768. cmd = self.cmd.selection();
  5769. bookmark = cmd.range.createBookmark();
  5770. div = K('<div class="' + cls + '"></div>', doc).css({
  5771. position : 'absolute',
  5772. width : '1px',
  5773. height : '1px',
  5774. overflow : 'hidden',
  5775. left : '-1981px',
  5776. top : K(bookmark.start).pos().y + 'px',
  5777. 'white-space' : 'nowrap'
  5778. });
  5779. K(doc.body).append(div);
  5780. if (_IE) {
  5781. var rng = cmd.range.get(true);
  5782. rng.moveToElementText(div[0]);
  5783. rng.select();
  5784. rng.execCommand('paste');
  5785. e.preventDefault();
  5786. } else {
  5787. cmd.range.selectNodeContents(div[0]);
  5788. cmd.select();
  5789. }
  5790. setTimeout(function() {
  5791. movePastedData();
  5792. pasting = false;
  5793. }, 0);
  5794. });
  5795. });
  5796. self.beforeGetHtml(function(html) {
  5797. if (_IE && _V <= 8) {
  5798. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5799. return unescape(tag);
  5800. });
  5801. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5802. if (!/\s+type="[^"]+"/i.test($0)) {
  5803. return $1 + ' type="text"' + $2;
  5804. }
  5805. return $0;
  5806. });
  5807. }
  5808. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5809. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5810. })
  5811. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5812. var imgAttrs = _getAttrList(full),
  5813. styles = _getCssList(imgAttrs.style || ''),
  5814. attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5815. attrs.width = _undef(imgAttrs.width, _removeUnit(_undef(styles.width, '')));
  5816. attrs.height = _undef(imgAttrs.height, _removeUnit(_undef(styles.height, '')));
  5817. return _mediaEmbed(attrs);
  5818. })
  5819. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  5820. var imgAttrs = _getAttrList(full);
  5821. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5822. })
  5823. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5824. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5825. })
  5826. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5827. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5828. })
  5829. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  5830. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  5831. return $1 + _unescape(src) + $2;
  5832. });
  5833. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5834. return full;
  5835. })
  5836. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5837. return start + end;
  5838. });
  5839. });
  5840. self.beforeSetHtml(function(html) {
  5841. if (_IE && _V <= 8) {
  5842. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  5843. var attrs = _getAttrList(full);
  5844. var styles = _getCssList(attrs.style || '');
  5845. if (styles.display == 'none') {
  5846. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5847. }
  5848. return full;
  5849. });
  5850. }
  5851. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  5852. var attrs = _getAttrList(full);
  5853. attrs.src = _undef(attrs.src, '');
  5854. attrs.width = _undef(attrs.width, 0);
  5855. attrs.height = _undef(attrs.height, 0);
  5856. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5857. })
  5858. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  5859. var attrs = _getAttrList(full);
  5860. if (attrs.href !== undefined) {
  5861. return full;
  5862. }
  5863. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5864. })
  5865. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  5866. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5867. })
  5868. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  5869. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5870. })
  5871. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  5872. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5873. return full;
  5874. }
  5875. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5876. return full;
  5877. })
  5878. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5879. return start + 'data-ke-' + end;
  5880. })
  5881. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  5882. if (full.indexOf('ke-zeroborder') >= 0) {
  5883. return full;
  5884. }
  5885. return _addClassToTag(full, 'ke-zeroborder');
  5886. });
  5887. });
  5888. });
  5889. })(window);
  5890. /*******************************************************************************
  5891. * KindEditor - WYSIWYG HTML Editor for Internet
  5892. * Copyright (C) 2006-2011 kindsoft.net
  5893. *
  5894. * @author Roddy <luolonghao@gmail.com>
  5895. * @site http://www.kindsoft.net/
  5896. * @licence http://www.kindsoft.net/license.php
  5897. *******************************************************************************/
  5898. KindEditor.lang({
  5899. source : 'HTML代码',
  5900. preview : '预览',
  5901. undo : '后退(Ctrl+Z)',
  5902. redo : '前进(Ctrl+Y)',
  5903. cut : '剪切(Ctrl+X)',
  5904. copy : '复制(Ctrl+C)',
  5905. paste : '粘贴(Ctrl+V)',
  5906. plainpaste : '粘贴为无格式文本',
  5907. wordpaste : '从Word粘贴',
  5908. selectall : '全选(Ctrl+A)',
  5909. justifyleft : '左对齐',
  5910. justifycenter : '居中',
  5911. justifyright : '右对齐',
  5912. justifyfull : '两端对齐',
  5913. insertorderedlist : '编号',
  5914. insertunorderedlist : '项目符号',
  5915. indent : '增加缩进',
  5916. outdent : '减少缩进',
  5917. subscript : '下标',
  5918. superscript : '上标',
  5919. formatblock : '段落',
  5920. fontname : '字体',
  5921. fontsize : '文字大小',
  5922. forecolor : '文字颜色',
  5923. hilitecolor : '文字背景',
  5924. bold : '粗体(Ctrl+B)',
  5925. italic : '斜体(Ctrl+I)',
  5926. underline : '下划线(Ctrl+U)',
  5927. strikethrough : '删除线',
  5928. removeformat : '删除格式',
  5929. image : '图片',
  5930. multiimage : '批量图片上传',
  5931. flash : 'Flash',
  5932. media : '视音频',
  5933. table : '表格',
  5934. tablecell : '单元格',
  5935. hr : '插入横线',
  5936. emoticons : '插入表情',
  5937. link : '超级链接',
  5938. unlink : '取消超级链接',
  5939. fullscreen : '全屏显示',
  5940. about : '关于',
  5941. print : '打印(Ctrl+P)',
  5942. filemanager : '文件空间',
  5943. code : '插入程序代码',
  5944. map : 'Google地图',
  5945. baidumap : '百度地图',
  5946. lineheight : '行距',
  5947. clearhtml : '清理HTML代码',
  5948. pagebreak : '插入分页符',
  5949. quickformat : '一键排版',
  5950. insertfile : '插入文件',
  5951. template : '插入模板',
  5952. anchor : '锚点',
  5953. yes : '确定',
  5954. no : '取消',
  5955. close : '关闭',
  5956. editImage : '图片属性',
  5957. deleteImage : '删除图片',
  5958. editFlash : 'Flash属性',
  5959. deleteFlash : '删除Flash',
  5960. editMedia : '视音频属性',
  5961. deleteMedia : '删除视音频',
  5962. editLink : '超级链接属性',
  5963. deleteLink : '取消超级链接',
  5964. editAnchor : '锚点属性',
  5965. deleteAnchor : '删除锚点',
  5966. tableprop : '表格属性',
  5967. tablecellprop : '单元格属性',
  5968. tableinsert : '插入表格',
  5969. tabledelete : '删除表格',
  5970. tablecolinsertleft : '左侧插入列',
  5971. tablecolinsertright : '右侧插入列',
  5972. tablerowinsertabove : '上方插入行',
  5973. tablerowinsertbelow : '下方插入行',
  5974. tablerowmerge : '向下合并单元格',
  5975. tablecolmerge : '向右合并单元格',
  5976. tablerowsplit : '拆分行',
  5977. tablecolsplit : '拆分列',
  5978. tablecoldelete : '删除列',
  5979. tablerowdelete : '删除行',
  5980. noColor : '无颜色',
  5981. pleaseSelectFile : '请选择文件。',
  5982. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  5983. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  5984. invalidWidth : "宽度必须为数字。",
  5985. invalidHeight : "高度必须为数字。",
  5986. invalidBorder : "边框必须为数字。",
  5987. invalidUrl : "请输入有效的URL地址。",
  5988. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  5989. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  5990. invalidPadding : '边距必须为数字。',
  5991. invalidSpacing : '间距必须为数字。',
  5992. invalidJson : '服务器发生故障。',
  5993. uploadSuccess : '上传成功。',
  5994. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  5995. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  5996. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  5997. ajaxLoading : '加载中,请稍候 ...',
  5998. uploadLoading : '上传中,请稍候 ...',
  5999. uploadError : '上传错误',
  6000. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6001. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6002. 'code.pleaseInput' : '请输入程序代码。',
  6003. 'link.url' : 'URL',
  6004. 'link.linkType' : '打开类型',
  6005. 'link.newWindow' : '新窗口',
  6006. 'link.selfWindow' : '当前窗口',
  6007. 'flash.url' : 'URL',
  6008. 'flash.width' : '宽度',
  6009. 'flash.height' : '高度',
  6010. 'flash.upload' : '上传',
  6011. 'flash.viewServer' : '文件空间',
  6012. 'media.url' : 'URL',
  6013. 'media.width' : '宽度',
  6014. 'media.height' : '高度',
  6015. 'media.autostart' : '自动播放',
  6016. 'media.upload' : '上传',
  6017. 'media.viewServer' : '文件空间',
  6018. 'image.remoteImage' : '网络图片',
  6019. 'image.localImage' : '本地上传',
  6020. 'image.remoteUrl' : '图片地址',
  6021. 'image.localUrl' : '上传文件',
  6022. 'image.size' : '图片大小',
  6023. 'image.width' : '宽',
  6024. 'image.height' : '高',
  6025. 'image.resetSize' : '重置大小',
  6026. 'image.align' : '对齐方式',
  6027. 'image.defaultAlign' : '默认方式',
  6028. 'image.leftAlign' : '左对齐',
  6029. 'image.rightAlign' : '右对齐',
  6030. 'image.imgTitle' : '图片说明',
  6031. 'image.upload' : '浏览...',
  6032. 'image.viewServer' : '图片空间',
  6033. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6034. 'multiimage.startUpload' : '开始上传',
  6035. 'multiimage.clearAll' : '全部清空',
  6036. 'multiimage.insertAll' : '全部插入',
  6037. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6038. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6039. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6040. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6041. 'multiimage.unknownError' : '发生异常,无法上传。',
  6042. 'multiimage.pending' : '等待上传',
  6043. 'multiimage.uploadError' : '上传失败',
  6044. 'filemanager.emptyFolder' : '空文件夹',
  6045. 'filemanager.moveup' : '移到上一级文件夹',
  6046. 'filemanager.viewType' : '显示方式:',
  6047. 'filemanager.viewImage' : '缩略图',
  6048. 'filemanager.listImage' : '详细信息',
  6049. 'filemanager.orderType' : '排序方式:',
  6050. 'filemanager.fileName' : '名称',
  6051. 'filemanager.fileSize' : '大小',
  6052. 'filemanager.fileType' : '类型',
  6053. 'insertfile.url' : 'URL',
  6054. 'insertfile.title' : '文件说明',
  6055. 'insertfile.upload' : '上传',
  6056. 'insertfile.viewServer' : '文件空间',
  6057. 'table.cells' : '单元格数',
  6058. 'table.rows' : '行数',
  6059. 'table.cols' : '列数',
  6060. 'table.size' : '大小',
  6061. 'table.width' : '宽度',
  6062. 'table.height' : '高度',
  6063. 'table.percent' : '%',
  6064. 'table.px' : 'px',
  6065. 'table.space' : '边距间距',
  6066. 'table.padding' : '边距',
  6067. 'table.spacing' : '间距',
  6068. 'table.align' : '对齐方式',
  6069. 'table.textAlign' : '水平对齐',
  6070. 'table.verticalAlign' : '垂直对齐',
  6071. 'table.alignDefault' : '默认',
  6072. 'table.alignLeft' : '左对齐',
  6073. 'table.alignCenter' : '居中',
  6074. 'table.alignRight' : '右对齐',
  6075. 'table.alignTop' : '顶部',
  6076. 'table.alignMiddle' : '中部',
  6077. 'table.alignBottom' : '底部',
  6078. 'table.alignBaseline' : '基线',
  6079. 'table.border' : '边框',
  6080. 'table.borderWidth' : '边框',
  6081. 'table.borderColor' : '颜色',
  6082. 'table.backgroundColor' : '背景颜色',
  6083. 'map.address' : '地址: ',
  6084. 'map.search' : '搜索',
  6085. 'baidumap.address' : '地址: ',
  6086. 'baidumap.search' : '搜索',
  6087. 'baidumap.insertDynamicMap' : '插入动态地图',
  6088. 'anchor.name' : '锚点名称',
  6089. 'formatblock.formatBlock' : {
  6090. h1 : '标题 1',
  6091. h2 : '标题 2',
  6092. h3 : '标题 3',
  6093. h4 : '标题 4',
  6094. p : '正 文'
  6095. },
  6096. 'fontname.fontName' : {
  6097. 'SimSun' : '宋体',
  6098. 'NSimSun' : '新宋体',
  6099. 'FangSong_GB2312' : '仿宋_GB2312',
  6100. 'KaiTi_GB2312' : '楷体_GB2312',
  6101. 'SimHei' : '黑体',
  6102. 'Microsoft YaHei' : '微软雅黑',
  6103. 'Arial' : 'Arial',
  6104. 'Arial Black' : 'Arial Black',
  6105. 'Times New Roman' : 'Times New Roman',
  6106. 'Courier New' : 'Courier New',
  6107. 'Tahoma' : 'Tahoma',
  6108. 'Verdana' : 'Verdana'
  6109. },
  6110. 'lineheight.lineHeight' : [
  6111. {'1' : '单倍行距'},
  6112. {'1.5' : '1.5倍行距'},
  6113. {'2' : '2倍行距'},
  6114. {'2.5' : '2.5倍行距'},
  6115. {'3' : '3倍行距'}
  6116. ],
  6117. 'template.selectTemplate' : '可选模板',
  6118. 'template.replaceContent' : '替换当前内容',
  6119. 'template.fileList' : {
  6120. '1.html' : '图片和文字',
  6121. '2.html' : '表格',
  6122. '3.html' : '项目编号'
  6123. }
  6124. }, 'zh_CN');
  6125. /*******************************************************************************
  6126. * KindEditor - WYSIWYG HTML Editor for Internet
  6127. * Copyright (C) 2006-2011 kindsoft.net
  6128. *
  6129. * @author Roddy <luolonghao@gmail.com>
  6130. * @site http://www.kindsoft.net/
  6131. * @licence http://www.kindsoft.net/license.php
  6132. *******************************************************************************/
  6133. KindEditor.plugin('anchor', function(K) {
  6134. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6135. self.plugin.anchor = {
  6136. edit : function() {
  6137. var html = ['<div style="padding:20px;">',
  6138. '<div class="ke-dialog-row">',
  6139. '<label for="keName">' + lang.name + '</label>',
  6140. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6141. '</div>',
  6142. '</div>'].join('');
  6143. var dialog = self.createDialog({
  6144. name : name,
  6145. width : 300,
  6146. title : self.lang(name),
  6147. body : html,
  6148. yesBtn : {
  6149. name : self.lang('yes'),
  6150. click : function(e) {
  6151. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6152. }
  6153. }
  6154. });
  6155. var div = dialog.div,
  6156. nameBox = K('input[name="name"]', div);
  6157. var img = self.plugin.getSelectedAnchor();
  6158. if (img) {
  6159. nameBox.val(unescape(img.attr('data-ke-name')));
  6160. }
  6161. nameBox[0].focus();
  6162. nameBox[0].select();
  6163. },
  6164. 'delete' : function() {
  6165. self.plugin.getSelectedAnchor().remove();
  6166. }
  6167. };
  6168. self.clickToolbar(name, self.plugin.anchor.edit);
  6169. });
  6170. /*******************************************************************************
  6171. * KindEditor - WYSIWYG HTML Editor for Internet
  6172. * Copyright (C) 2006-2011 kindsoft.net
  6173. *
  6174. * @author Roddy <luolonghao@gmail.com>
  6175. * @site http://www.kindsoft.net/
  6176. * @licence http://www.kindsoft.net/license.php
  6177. *******************************************************************************/
  6178. // Baidu Maps: http://dev.baidu.com/wiki/map/index.php?title=%E9%A6%96%E9%A1%B5
  6179. KindEditor.plugin('baidumap', function(K) {
  6180. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6181. var mapWidth = K.undef(self.mapWidth, 558);
  6182. var mapHeight = K.undef(self.mapHeight, 360);
  6183. self.clickToolbar(name, function() {
  6184. var html = ['<div style="padding:10px 20px;">',
  6185. '<div class="ke-header">',
  6186. // left start
  6187. '<div class="ke-left">',
  6188. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6189. '<span class="ke-button-common ke-button-outer">',
  6190. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6191. '</span>',
  6192. '</div>',
  6193. // right start
  6194. '<div class="ke-right">',
  6195. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6196. '</div>',
  6197. '<div class="ke-clearfix"></div>',
  6198. '</div>',
  6199. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6200. '</div>'].join('');
  6201. var dialog = self.createDialog({
  6202. name : name,
  6203. width : mapWidth + 42,
  6204. title : self.lang(name),
  6205. body : html,
  6206. yesBtn : {
  6207. name : self.lang('yes'),
  6208. click : function(e) {
  6209. var map = win.map;
  6210. var centerObj = map.getCenter();
  6211. var center = centerObj.lng + ',' + centerObj.lat;
  6212. var zoom = map.getZoom();
  6213. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6214. '?center=' + encodeURIComponent(center),
  6215. '&zoom=' + encodeURIComponent(zoom),
  6216. '&width=' + mapWidth,
  6217. '&height=' + mapHeight,
  6218. '&markers=' + encodeURIComponent(center),
  6219. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6220. if (checkbox[0].checked) {
  6221. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6222. } else {
  6223. self.exec('insertimage', url);
  6224. }
  6225. self.hideDialog().focus();
  6226. }
  6227. },
  6228. beforeRemove : function() {
  6229. searchBtn.remove();
  6230. if (doc) {
  6231. doc.write('');
  6232. }
  6233. iframe.remove();
  6234. }
  6235. });
  6236. var div = dialog.div,
  6237. addressBox = K('[name="address"]', div),
  6238. searchBtn = K('[name="searchBtn"]', div),
  6239. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6240. win, doc;
  6241. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6242. function ready() {
  6243. win = iframe[0].contentWindow;
  6244. doc = K.iframeDoc(iframe);
  6245. }
  6246. iframe.bind('load', function() {
  6247. iframe.unbind('load');
  6248. if (K.IE) {
  6249. ready();
  6250. } else {
  6251. setTimeout(ready, 0);
  6252. }
  6253. });
  6254. K('.ke-map', div).replaceWith(iframe);
  6255. // search map
  6256. searchBtn.click(function() {
  6257. win.search(addressBox.val());
  6258. });
  6259. });
  6260. });
  6261. /*******************************************************************************
  6262. * KindEditor - WYSIWYG HTML Editor for Internet
  6263. * Copyright (C) 2006-2011 kindsoft.net
  6264. *
  6265. * @author Roddy <luolonghao@gmail.com>
  6266. * @site http://www.kindsoft.net/
  6267. * @licence http://www.kindsoft.net/license.php
  6268. *******************************************************************************/
  6269. KindEditor.plugin('clearhtml', function(K) {
  6270. var self = this, name = 'clearhtml';
  6271. self.clickToolbar(name, function() {
  6272. self.focus();
  6273. var html = self.html();
  6274. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6275. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6276. html = K.formatHtml(html, {
  6277. a : ['href', 'target'],
  6278. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6279. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6280. table : ['border'],
  6281. 'td,th' : ['rowspan', 'colspan'],
  6282. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6283. });
  6284. self.html(html);
  6285. self.cmd.selection(true);
  6286. self.addBookmark();
  6287. });
  6288. });
  6289. /*******************************************************************************
  6290. * KindEditor - WYSIWYG HTML Editor for Internet
  6291. * Copyright (C) 2006-2011 kindsoft.net
  6292. *
  6293. * @author Roddy <luolonghao@gmail.com>
  6294. * @site http://www.kindsoft.net/
  6295. * @licence http://www.kindsoft.net/license.php
  6296. *******************************************************************************/
  6297. // google code prettify: http://google-code-prettify.googlecode.com/
  6298. // http://google-code-prettify.googlecode.com/
  6299. KindEditor.plugin('code', function(K) {
  6300. var self = this, name = 'code';
  6301. self.clickToolbar(name, function() {
  6302. var lang = self.lang(name + '.'),
  6303. html = ['<div style="padding:10px 20px;">',
  6304. '<div class="ke-dialog-row">',
  6305. '<select class="ke-code-type">',
  6306. '<option value="js">JavaScript</option>',
  6307. '<option value="html">HTML</option>',
  6308. '<option value="css">CSS</option>',
  6309. '<option value="php">PHP</option>',
  6310. '<option value="pl">Perl</option>',
  6311. '<option value="py">Python</option>',
  6312. '<option value="rb">Ruby</option>',
  6313. '<option value="java">Java</option>',
  6314. '<option value="vb">ASP/VB</option>',
  6315. '<option value="cpp">C/C++</option>',
  6316. '<option value="cs">C#</option>',
  6317. '<option value="xml">XML</option>',
  6318. '<option value="bsh">Shell</option>',
  6319. '<option value="">Other</option>',
  6320. '</select>',
  6321. '</div>',
  6322. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6323. '</div>'].join(''),
  6324. dialog = self.createDialog({
  6325. name : name,
  6326. width : 450,
  6327. title : self.lang(name),
  6328. body : html,
  6329. yesBtn : {
  6330. name : self.lang('yes'),
  6331. click : function(e) {
  6332. var type = K('.ke-code-type', dialog.div).val(),
  6333. code = textarea.val(),
  6334. cls = type === '' ? '' : ' lang-' + type,
  6335. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6336. if (K.trim(code) === '') {
  6337. alert(lang.pleaseInput);
  6338. textarea[0].focus();
  6339. return;
  6340. }
  6341. self.insertHtml(html).hideDialog().focus();
  6342. }
  6343. }
  6344. }),
  6345. textarea = K('textarea', dialog.div);
  6346. textarea[0].focus();
  6347. });
  6348. });
  6349. /*******************************************************************************
  6350. * KindEditor - WYSIWYG HTML Editor for Internet
  6351. * Copyright (C) 2006-2011 kindsoft.net
  6352. *
  6353. * @author Roddy <luolonghao@gmail.com>
  6354. * @site http://www.kindsoft.net/
  6355. * @licence http://www.kindsoft.net/license.php
  6356. *******************************************************************************/
  6357. KindEditor.plugin('emoticons', function(K) {
  6358. var self = this, name = 'emoticons',
  6359. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6360. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6361. currentPageNum = 1;
  6362. self.clickToolbar(name, function() {
  6363. var rows = 5, cols = 9, total = 135, startNum = 0,
  6364. cells = rows * cols, pages = Math.ceil(total / cells),
  6365. colsHalf = Math.floor(cols / 2),
  6366. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6367. elements = [],
  6368. menu = self.createMenu({
  6369. name : name,
  6370. beforeRemove : function() {
  6371. removeEvent();
  6372. }
  6373. });
  6374. menu.div.append(wrapperDiv);
  6375. var previewDiv, previewImg;
  6376. if (allowPreview) {
  6377. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6378. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6379. wrapperDiv.append(previewDiv);
  6380. previewDiv.append(previewImg);
  6381. }
  6382. function bindCellEvent(cell, j, num) {
  6383. if (previewDiv) {
  6384. cell.mouseover(function() {
  6385. if (j > colsHalf) {
  6386. previewDiv.css('left', 0);
  6387. previewDiv.css('right', '');
  6388. } else {
  6389. previewDiv.css('left', '');
  6390. previewDiv.css('right', 0);
  6391. }
  6392. previewImg.attr('src', path + num + '.gif');
  6393. K(this).addClass('ke-on');
  6394. });
  6395. } else {
  6396. cell.mouseover(function() {
  6397. K(this).addClass('ke-on');
  6398. });
  6399. }
  6400. cell.mouseout(function() {
  6401. K(this).removeClass('ke-on');
  6402. });
  6403. cell.click(function(e) {
  6404. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6405. e.stop();
  6406. });
  6407. }
  6408. function createEmoticonsTable(pageNum, parentDiv) {
  6409. var table = document.createElement('table');
  6410. parentDiv.append(table);
  6411. if (previewDiv) {
  6412. K(table).mouseover(function() {
  6413. previewDiv.show('block');
  6414. });
  6415. K(table).mouseout(function() {
  6416. previewDiv.hide();
  6417. });
  6418. elements.push(K(table));
  6419. }
  6420. table.className = 'ke-table';
  6421. table.cellPadding = 0;
  6422. table.cellSpacing = 0;
  6423. table.border = 0;
  6424. var num = (pageNum - 1) * cells + startNum;
  6425. for (var i = 0; i < rows; i++) {
  6426. var row = table.insertRow(i);
  6427. for (var j = 0; j < cols; j++) {
  6428. var cell = K(row.insertCell(j));
  6429. cell.addClass('ke-cell');
  6430. bindCellEvent(cell, j, num);
  6431. var span = K('<span class="ke-img"></span>')
  6432. .css('background-position', '-' + (24 * num) + 'px 0px')
  6433. .css('background-image', 'url(' + path + 'static.gif)');
  6434. cell.append(span);
  6435. elements.push(cell);
  6436. num++;
  6437. }
  6438. }
  6439. return table;
  6440. }
  6441. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6442. function removeEvent() {
  6443. K.each(elements, function() {
  6444. this.unbind();
  6445. });
  6446. }
  6447. var pageDiv;
  6448. function bindPageEvent(el, pageNum) {
  6449. el.click(function(e) {
  6450. removeEvent();
  6451. table.parentNode.removeChild(table);
  6452. pageDiv.remove();
  6453. table = createEmoticonsTable(pageNum, wrapperDiv);
  6454. createPageTable(pageNum);
  6455. currentPageNum = pageNum;
  6456. e.stop();
  6457. });
  6458. }
  6459. function createPageTable(currentPageNum) {
  6460. pageDiv = K('<div class="ke-page"></div>');
  6461. wrapperDiv.append(pageDiv);
  6462. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6463. if (currentPageNum !== pageNum) {
  6464. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6465. bindPageEvent(a, pageNum);
  6466. pageDiv.append(a);
  6467. elements.push(a);
  6468. } else {
  6469. pageDiv.append(K('@[' + pageNum + ']'));
  6470. }
  6471. pageDiv.append(K('@&nbsp;'));
  6472. }
  6473. }
  6474. createPageTable(currentPageNum);
  6475. });
  6476. });
  6477. /*******************************************************************************
  6478. * KindEditor - WYSIWYG HTML Editor for Internet
  6479. * Copyright (C) 2006-2011 kindsoft.net
  6480. *
  6481. * @author Roddy <luolonghao@gmail.com>
  6482. * @site http://www.kindsoft.net/
  6483. * @licence http://www.kindsoft.net/license.php
  6484. *******************************************************************************/
  6485. KindEditor.plugin('filemanager', function(K) {
  6486. var self = this, name = 'filemanager',
  6487. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6488. imgPath = self.pluginsPath + name + '/images/',
  6489. lang = self.lang(name + '.');
  6490. function makeFileTitle(filename, filesize, datetime) {
  6491. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6492. }
  6493. function bindTitle(el, data) {
  6494. if (data.is_dir) {
  6495. el.attr('title', data.filename);
  6496. } else {
  6497. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6498. }
  6499. }
  6500. self.plugin.filemanagerDialog = function(options) {
  6501. var width = K.undef(options.width, 650),
  6502. height = K.undef(options.height, 510),
  6503. dirName = K.undef(options.dirName, ''),
  6504. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(), // "LIST" or "VIEW"
  6505. clickFn = options.clickFn;
  6506. var html = [
  6507. '<div style="padding:10px 20px;">',
  6508. // header start
  6509. '<div class="ke-plugin-filemanager-header">',
  6510. // left start
  6511. '<div class="ke-left">',
  6512. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6513. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6514. '</div>',
  6515. // right start
  6516. '<div class="ke-right">',
  6517. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6518. '<option value="VIEW">' + lang.viewImage + '</option>',
  6519. '<option value="LIST">' + lang.listImage + '</option>',
  6520. '</select> ',
  6521. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6522. '<option value="NAME">' + lang.fileName + '</option>',
  6523. '<option value="SIZE">' + lang.fileSize + '</option>',
  6524. '<option value="TYPE">' + lang.fileType + '</option>',
  6525. '</select>',
  6526. '</div>',
  6527. '<div class="ke-clearfix"></div>',
  6528. '</div>',
  6529. // body start
  6530. '<div class="ke-plugin-filemanager-body"></div>',
  6531. '</div>'
  6532. ].join('');
  6533. var dialog = self.createDialog({
  6534. name : name,
  6535. width : width,
  6536. height : height,
  6537. title : self.lang(name),
  6538. body : html
  6539. }),
  6540. div = dialog.div,
  6541. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6542. moveupImg = K('[name="moveupImg"]', div),
  6543. moveupLink = K('[name="moveupLink"]', div),
  6544. viewServerBtn = K('[name="viewServer"]', div),
  6545. viewTypeBox = K('[name="viewType"]', div),
  6546. orderTypeBox = K('[name="orderType"]', div);
  6547. function reloadPage(path, order, func) {
  6548. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6549. dialog.showLoading(self.lang('ajaxLoading'));
  6550. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6551. dialog.hideLoading();
  6552. func(data);
  6553. });
  6554. }
  6555. var elList = [];
  6556. function bindEvent(el, result, data, createFunc) {
  6557. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6558. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6559. if (data.is_dir) {
  6560. el.click(function(e) {
  6561. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6562. });
  6563. } else if (data.is_photo) {
  6564. el.click(function(e) {
  6565. clickFn.call(this, fileUrl, data.filename);
  6566. });
  6567. } else {
  6568. el.click(function(e) {
  6569. clickFn.call(this, fileUrl, data.filename);
  6570. });
  6571. }
  6572. elList.push(el);
  6573. }
  6574. function createCommon(result, createFunc) {
  6575. // remove events
  6576. K.each(elList, function() {
  6577. this.unbind();
  6578. });
  6579. moveupLink.unbind();
  6580. viewTypeBox.unbind();
  6581. orderTypeBox.unbind();
  6582. // add events
  6583. if (result.current_dir_path) {
  6584. moveupLink.click(function(e) {
  6585. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6586. });
  6587. }
  6588. function changeFunc() {
  6589. if (viewTypeBox.val() == 'VIEW') {
  6590. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6591. } else {
  6592. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6593. }
  6594. }
  6595. viewTypeBox.change(changeFunc);
  6596. orderTypeBox.change(changeFunc);
  6597. bodyDiv.html('');
  6598. }
  6599. function createList(result) {
  6600. createCommon(result, createList);
  6601. var table = document.createElement('table');
  6602. table.className = 'ke-table';
  6603. table.cellPadding = 0;
  6604. table.cellSpacing = 0;
  6605. table.border = 0;
  6606. bodyDiv.append(table);
  6607. var fileList = result.file_list;
  6608. for (var i = 0, len = fileList.length; i < len; i++) {
  6609. var data = fileList[i], row = K(table.insertRow(i));
  6610. row.mouseover(function(e) {
  6611. K(this).addClass('ke-on');
  6612. })
  6613. .mouseout(function(e) {
  6614. K(this).removeClass('ke-on');
  6615. });
  6616. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6617. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6618. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6619. if (!data.is_dir || data.has_file) {
  6620. row.css('cursor', 'pointer');
  6621. cell0.attr('title', data.filename);
  6622. bindEvent(cell0, result, data, createList);
  6623. } else {
  6624. cell0.attr('title', lang.emptyFolder);
  6625. }
  6626. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6627. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6628. }
  6629. }
  6630. function createView(result) {
  6631. createCommon(result, createView);
  6632. var fileList = result.file_list;
  6633. for (var i = 0, len = fileList.length; i < len; i++) {
  6634. var data = fileList[i],
  6635. div = K('<div class="ke-inline-block ke-item"></div>');
  6636. bodyDiv.append(div);
  6637. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6638. .mouseover(function(e) {
  6639. K(this).addClass('ke-on');
  6640. })
  6641. .mouseout(function(e) {
  6642. K(this).removeClass('ke-on');
  6643. });
  6644. div.append(photoDiv);
  6645. var fileUrl = result.current_url + data.filename,
  6646. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6647. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6648. if (!data.is_dir || data.has_file) {
  6649. photoDiv.css('cursor', 'pointer');
  6650. bindTitle(photoDiv, data);
  6651. bindEvent(photoDiv, result, data, createView);
  6652. } else {
  6653. photoDiv.attr('title', lang.emptyFolder);
  6654. }
  6655. photoDiv.append(img);
  6656. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6657. }
  6658. }
  6659. viewTypeBox.val(viewType);
  6660. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6661. return dialog;
  6662. }
  6663. });
  6664. /*******************************************************************************
  6665. * KindEditor - WYSIWYG HTML Editor for Internet
  6666. * Copyright (C) 2006-2011 kindsoft.net
  6667. *
  6668. * @author Roddy <luolonghao@gmail.com>
  6669. * @site http://www.kindsoft.net/
  6670. * @licence http://www.kindsoft.net/license.php
  6671. *******************************************************************************/
  6672. KindEditor.plugin('flash', function(K) {
  6673. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6674. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6675. allowFileManager = K.undef(self.allowFileManager, false),
  6676. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6677. extraParams = K.undef(self.extraFileUploadParams, {}),
  6678. filePostName = K.undef(self.filePostName, 'imgFile'),
  6679. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  6680. self.plugin.flash = {
  6681. edit : function() {
  6682. var html = [
  6683. '<div style="padding:20px;">',
  6684. //url
  6685. '<div class="ke-dialog-row">',
  6686. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6687. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6688. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6689. '<span class="ke-button-common ke-button-outer">',
  6690. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6691. '</span>',
  6692. '</div>',
  6693. //width
  6694. '<div class="ke-dialog-row">',
  6695. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6696. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6697. '</div>',
  6698. //height
  6699. '<div class="ke-dialog-row">',
  6700. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6701. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6702. '</div>',
  6703. '</div>'
  6704. ].join('');
  6705. var dialog = self.createDialog({
  6706. name : name,
  6707. width : 450,
  6708. title : self.lang(name),
  6709. body : html,
  6710. yesBtn : {
  6711. name : self.lang('yes'),
  6712. click : function(e) {
  6713. var url = K.trim(urlBox.val()),
  6714. width = widthBox.val(),
  6715. height = heightBox.val();
  6716. if (url == 'http://' || K.invalidUrl(url)) {
  6717. alert(self.lang('invalidUrl'));
  6718. urlBox[0].focus();
  6719. return;
  6720. }
  6721. if (!/^\d*$/.test(width)) {
  6722. alert(self.lang('invalidWidth'));
  6723. widthBox[0].focus();
  6724. return;
  6725. }
  6726. if (!/^\d*$/.test(height)) {
  6727. alert(self.lang('invalidHeight'));
  6728. heightBox[0].focus();
  6729. return;
  6730. }
  6731. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6732. src : url,
  6733. type : K.mediaType('.swf'),
  6734. width : width,
  6735. height : height,
  6736. quality : 'high'
  6737. });
  6738. self.insertHtml(html).hideDialog().focus();
  6739. }
  6740. }
  6741. }),
  6742. div = dialog.div,
  6743. urlBox = K('[name="url"]', div),
  6744. viewServerBtn = K('[name="viewServer"]', div),
  6745. widthBox = K('[name="width"]', div),
  6746. heightBox = K('[name="height"]', div);
  6747. urlBox.val('http://');
  6748. if (allowFlashUpload) {
  6749. var uploadbutton = K.uploadbutton({
  6750. button : K('.ke-upload-button', div)[0],
  6751. fieldName : filePostName,
  6752. extraParams : extraParams,
  6753. url : K.addParam(uploadJson, 'dir=flash'),
  6754. afterUpload : function(data) {
  6755. dialog.hideLoading();
  6756. if (data.error === 0) {
  6757. var url = data.url;
  6758. if (formatUploadUrl) {
  6759. url = K.formatUrl(url, 'absolute');
  6760. }
  6761. urlBox.val(url);
  6762. if (self.afterUpload) {
  6763. self.afterUpload.call(self, url, data, name);
  6764. }
  6765. alert(self.lang('uploadSuccess'));
  6766. } else {
  6767. alert(data.message);
  6768. }
  6769. },
  6770. afterError : function(html) {
  6771. dialog.hideLoading();
  6772. self.errorDialog(html);
  6773. }
  6774. });
  6775. uploadbutton.fileBox.change(function(e) {
  6776. dialog.showLoading(self.lang('uploadLoading'));
  6777. uploadbutton.submit();
  6778. });
  6779. } else {
  6780. K('.ke-upload-button', div).hide();
  6781. }
  6782. if (allowFileManager) {
  6783. viewServerBtn.click(function(e) {
  6784. self.loadPlugin('filemanager', function() {
  6785. self.plugin.filemanagerDialog({
  6786. viewType : 'LIST',
  6787. dirName : 'flash',
  6788. clickFn : function(url, title) {
  6789. if (self.dialogs.length > 1) {
  6790. K('[name="url"]', div).val(url);
  6791. if (self.afterSelectFile) {
  6792. self.afterSelectFile.call(self, url);
  6793. }
  6794. self.hideDialog();
  6795. }
  6796. }
  6797. });
  6798. });
  6799. });
  6800. } else {
  6801. viewServerBtn.hide();
  6802. }
  6803. var img = self.plugin.getSelectedFlash();
  6804. if (img) {
  6805. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  6806. urlBox.val(attrs.src);
  6807. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  6808. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  6809. }
  6810. urlBox[0].focus();
  6811. urlBox[0].select();
  6812. },
  6813. 'delete' : function() {
  6814. self.plugin.getSelectedFlash().remove();
  6815. // [IE] 删除图片后立即点击图片按钮出错
  6816. self.addBookmark();
  6817. }
  6818. };
  6819. self.clickToolbar(name, self.plugin.flash.edit);
  6820. });
  6821. /*******************************************************************************
  6822. * KindEditor - WYSIWYG HTML Editor for Internet
  6823. * Copyright (C) 2006-2011 kindsoft.net
  6824. *
  6825. * @author Roddy <luolonghao@gmail.com>
  6826. * @site http://www.kindsoft.net/
  6827. * @licence http://www.kindsoft.net/license.php
  6828. *******************************************************************************/
  6829. KindEditor.plugin('image', function(K) {
  6830. var self = this, name = 'image',
  6831. allowImageUpload = K.undef(self.allowImageUpload, true),
  6832. allowImageRemote = K.undef(self.allowImageRemote, true),
  6833. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6834. allowFileManager = K.undef(self.allowFileManager, false),
  6835. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  6836. imageTabIndex = K.undef(self.imageTabIndex, 0),
  6837. imgPath = self.pluginsPath + 'image/images/',
  6838. extraParams = K.undef(self.extraFileUploadParams, {}),
  6839. filePostName = K.undef(self.filePostName, 'imgFile'),
  6840. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  6841. lang = self.lang(name + '.');
  6842. self.plugin.imageDialog = function(options) {
  6843. var imageUrl = options.imageUrl,
  6844. imageWidth = K.undef(options.imageWidth, ''),
  6845. imageHeight = K.undef(options.imageHeight, ''),
  6846. imageTitle = K.undef(options.imageTitle, ''),
  6847. imageAlign = K.undef(options.imageAlign, ''),
  6848. showRemote = K.undef(options.showRemote, true),
  6849. showLocal = K.undef(options.showLocal, true),
  6850. tabIndex = K.undef(options.tabIndex, 0),
  6851. clickFn = options.clickFn;
  6852. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  6853. var hiddenElements = [];
  6854. for(var k in extraParams){
  6855. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  6856. }
  6857. var html = [
  6858. '<div style="padding:20px;">',
  6859. //tabs
  6860. '<div class="tabs"></div>',
  6861. //remote image - start
  6862. '<div class="tab1" style="display:none;">',
  6863. //url
  6864. '<div class="ke-dialog-row">',
  6865. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  6866. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  6867. '<span class="ke-button-common ke-button-outer">',
  6868. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6869. '</span>',
  6870. '</div>',
  6871. //size
  6872. '<div class="ke-dialog-row">',
  6873. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  6874. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  6875. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  6876. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  6877. '</div>',
  6878. //align
  6879. '<div class="ke-dialog-row">',
  6880. '<label style="width:60px;">' + lang.align + '</label>',
  6881. '<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="" />',
  6882. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  6883. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  6884. '</div>',
  6885. //title
  6886. '<div class="ke-dialog-row">',
  6887. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  6888. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  6889. '</div>',
  6890. '</div>',
  6891. //remote image - end
  6892. //local upload - start
  6893. '<div class="tab2" style="display:none;">',
  6894. '<iframe name="' + target + '" style="display:none;"></iframe>',
  6895. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  6896. //file
  6897. '<div class="ke-dialog-row">',
  6898. hiddenElements.join(''),
  6899. '<label style="width:60px;">' + lang.localUrl + '</label>',
  6900. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  6901. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  6902. '</div>',
  6903. '</form>',
  6904. '</div>',
  6905. //local upload - end
  6906. '</div>'
  6907. ].join('');
  6908. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  6909. dialogHeight = showLocal && showRemote ? 300 : 250;
  6910. var dialog = self.createDialog({
  6911. name : name,
  6912. width : dialogWidth,
  6913. height : dialogHeight,
  6914. title : self.lang(name),
  6915. body : html,
  6916. yesBtn : {
  6917. name : self.lang('yes'),
  6918. click : function(e) {
  6919. // Bugfix: http://code.google.com/p/kindeditor/issues/detail?id=319
  6920. if (dialog.isLoading) {
  6921. return;
  6922. }
  6923. // insert local image
  6924. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  6925. if (uploadbutton.fileBox.val() == '') {
  6926. alert(self.lang('pleaseSelectFile'));
  6927. return;
  6928. }
  6929. dialog.showLoading(self.lang('uploadLoading'));
  6930. uploadbutton.submit();
  6931. localUrlBox.val('');
  6932. return;
  6933. }
  6934. // insert remote image
  6935. var url = K.trim(urlBox.val()),
  6936. width = widthBox.val(),
  6937. height = heightBox.val(),
  6938. title = titleBox.val(),
  6939. align = '';
  6940. alignBox.each(function() {
  6941. if (this.checked) {
  6942. align = this.value;
  6943. return false;
  6944. }
  6945. });
  6946. if (url == 'http://' || K.invalidUrl(url)) {
  6947. alert(self.lang('invalidUrl'));
  6948. urlBox[0].focus();
  6949. return;
  6950. }
  6951. if (!/^\d*$/.test(width)) {
  6952. alert(self.lang('invalidWidth'));
  6953. widthBox[0].focus();
  6954. return;
  6955. }
  6956. if (!/^\d*$/.test(height)) {
  6957. alert(self.lang('invalidHeight'));
  6958. heightBox[0].focus();
  6959. return;
  6960. }
  6961. clickFn.call(self, url, title, width, height, 0, align);
  6962. }
  6963. },
  6964. beforeRemove : function() {
  6965. viewServerBtn.unbind();
  6966. widthBox.unbind();
  6967. heightBox.unbind();
  6968. refreshBtn.unbind();
  6969. }
  6970. }),
  6971. div = dialog.div;
  6972. var urlBox = K('[name="url"]', div),
  6973. localUrlBox = K('[name="localUrl"]', div),
  6974. viewServerBtn = K('[name="viewServer"]', div),
  6975. widthBox = K('.tab1 [name="width"]', div),
  6976. heightBox = K('.tab1 [name="height"]', div),
  6977. refreshBtn = K('.ke-refresh-btn', div),
  6978. titleBox = K('.tab1 [name="title"]', div),
  6979. alignBox = K('.tab1 [name="align"]', div);
  6980. var tabs;
  6981. if (showRemote && showLocal) {
  6982. tabs = K.tabs({
  6983. src : K('.tabs', div),
  6984. afterSelect : function(i) {}
  6985. });
  6986. tabs.add({
  6987. title : lang.remoteImage,
  6988. panel : K('.tab1', div)
  6989. });
  6990. tabs.add({
  6991. title : lang.localImage,
  6992. panel : K('.tab2', div)
  6993. });
  6994. tabs.select(tabIndex);
  6995. } else if (showRemote) {
  6996. K('.tab1', div).show();
  6997. } else if (showLocal) {
  6998. K('.tab2', div).show();
  6999. }
  7000. var uploadbutton = K.uploadbutton({
  7001. button : K('.ke-upload-button', div)[0],
  7002. fieldName : filePostName,
  7003. form : K('.ke-form', div),
  7004. target : target,
  7005. width: 60,
  7006. afterUpload : function(data) {
  7007. dialog.hideLoading();
  7008. if (data.error === 0) {
  7009. var url = data.url;
  7010. if (formatUploadUrl) {
  7011. url = K.formatUrl(url, 'absolute');
  7012. }
  7013. if (self.afterUpload) {
  7014. self.afterUpload.call(self, url, data, name);
  7015. }
  7016. if (!fillDescAfterUploadImage) {
  7017. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7018. } else {
  7019. K(".ke-dialog-row #remoteUrl", div).val(url);
  7020. K(".ke-tabs-li", div)[0].click();
  7021. K(".ke-refresh-btn", div).click();
  7022. }
  7023. } else {
  7024. alert(data.message);
  7025. }
  7026. },
  7027. afterError : function(html) {
  7028. dialog.hideLoading();
  7029. self.errorDialog(html);
  7030. }
  7031. });
  7032. uploadbutton.fileBox.change(function(e) {
  7033. localUrlBox.val(uploadbutton.fileBox.val());
  7034. });
  7035. if (allowFileManager) {
  7036. viewServerBtn.click(function(e) {
  7037. self.loadPlugin('filemanager', function() {
  7038. self.plugin.filemanagerDialog({
  7039. viewType : 'VIEW',
  7040. dirName : 'image',
  7041. clickFn : function(url, title) {
  7042. if (self.dialogs.length > 1) {
  7043. K('[name="url"]', div).val(url);
  7044. if (self.afterSelectFile) {
  7045. self.afterSelectFile.call(self, url);
  7046. }
  7047. self.hideDialog();
  7048. }
  7049. }
  7050. });
  7051. });
  7052. });
  7053. } else {
  7054. viewServerBtn.hide();
  7055. }
  7056. var originalWidth = 0, originalHeight = 0;
  7057. function setSize(width, height) {
  7058. widthBox.val(width);
  7059. heightBox.val(height);
  7060. originalWidth = width;
  7061. originalHeight = height;
  7062. }
  7063. refreshBtn.click(function(e) {
  7064. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7065. position : 'absolute',
  7066. visibility : 'hidden',
  7067. top : 0,
  7068. left : '-1000px'
  7069. });
  7070. tempImg.bind('load', function() {
  7071. setSize(tempImg.width(), tempImg.height());
  7072. tempImg.remove();
  7073. });
  7074. K(document.body).append(tempImg);
  7075. });
  7076. widthBox.change(function(e) {
  7077. if (originalWidth > 0) {
  7078. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7079. }
  7080. });
  7081. heightBox.change(function(e) {
  7082. if (originalHeight > 0) {
  7083. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7084. }
  7085. });
  7086. urlBox.val(options.imageUrl);
  7087. setSize(options.imageWidth, options.imageHeight);
  7088. titleBox.val(options.imageTitle);
  7089. alignBox.each(function() {
  7090. if (this.value === options.imageAlign) {
  7091. this.checked = true;
  7092. return false;
  7093. }
  7094. });
  7095. if (showRemote && tabIndex === 0) {
  7096. urlBox[0].focus();
  7097. urlBox[0].select();
  7098. }
  7099. return dialog;
  7100. };
  7101. self.plugin.image = {
  7102. edit : function() {
  7103. var img = self.plugin.getSelectedImage();
  7104. self.plugin.imageDialog({
  7105. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7106. imageWidth : img ? img.width() : '',
  7107. imageHeight : img ? img.height() : '',
  7108. imageTitle : img ? img.attr('title') : '',
  7109. imageAlign : img ? img.attr('align') : '',
  7110. showRemote : allowImageRemote,
  7111. showLocal : allowImageUpload,
  7112. tabIndex: img ? 0 : imageTabIndex,
  7113. clickFn : function(url, title, width, height, border, align) {
  7114. self.exec('insertimage', url, title, width, height, border, align);
  7115. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  7116. setTimeout(function() {
  7117. self.hideDialog().focus();
  7118. }, 0);
  7119. }
  7120. });
  7121. },
  7122. 'delete' : function() {
  7123. var target = self.plugin.getSelectedImage();
  7124. if (target.parent().name == 'a') {
  7125. target = target.parent();
  7126. }
  7127. target.remove();
  7128. // [IE] 删除图片后立即点击图片按钮出错
  7129. self.addBookmark();
  7130. }
  7131. };
  7132. self.clickToolbar(name, self.plugin.image.edit);
  7133. });
  7134. /*******************************************************************************
  7135. * KindEditor - WYSIWYG HTML Editor for Internet
  7136. * Copyright (C) 2006-2011 kindsoft.net
  7137. *
  7138. * @author Roddy <luolonghao@gmail.com>
  7139. * @site http://www.kindsoft.net/
  7140. * @licence http://www.kindsoft.net/license.php
  7141. *******************************************************************************/
  7142. KindEditor.plugin('insertfile', function(K) {
  7143. var self = this, name = 'insertfile',
  7144. allowFileUpload = K.undef(self.allowFileUpload, true),
  7145. allowFileManager = K.undef(self.allowFileManager, false),
  7146. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7147. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7148. extraParams = K.undef(self.extraFileUploadParams, {}),
  7149. filePostName = K.undef(self.filePostName, 'imgFile'),
  7150. lang = self.lang(name + '.');
  7151. self.plugin.fileDialog = function(options) {
  7152. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7153. fileTitle = K.undef(options.fileTitle, ''),
  7154. clickFn = options.clickFn;
  7155. var html = [
  7156. '<div style="padding:20px;">',
  7157. '<div class="ke-dialog-row">',
  7158. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7159. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7160. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7161. '<span class="ke-button-common ke-button-outer">',
  7162. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7163. '</span>',
  7164. '</div>',
  7165. //title
  7166. '<div class="ke-dialog-row">',
  7167. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7168. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7169. '</div>',
  7170. //form end
  7171. '</form>',
  7172. '</div>'
  7173. ].join('');
  7174. var dialog = self.createDialog({
  7175. name : name,
  7176. width : 450,
  7177. title : self.lang(name),
  7178. body : html,
  7179. yesBtn : {
  7180. name : self.lang('yes'),
  7181. click : function(e) {
  7182. var url = K.trim(urlBox.val()),
  7183. title = titleBox.val();
  7184. if (url == 'http://' || K.invalidUrl(url)) {
  7185. alert(self.lang('invalidUrl'));
  7186. urlBox[0].focus();
  7187. return;
  7188. }
  7189. if (K.trim(title) === '') {
  7190. title = url;
  7191. }
  7192. clickFn.call(self, url, title);
  7193. }
  7194. }
  7195. }),
  7196. div = dialog.div;
  7197. var urlBox = K('[name="url"]', div),
  7198. viewServerBtn = K('[name="viewServer"]', div),
  7199. titleBox = K('[name="title"]', div);
  7200. if (allowFileUpload) {
  7201. var uploadbutton = K.uploadbutton({
  7202. button : K('.ke-upload-button', div)[0],
  7203. fieldName : filePostName,
  7204. url : K.addParam(uploadJson, 'dir=file'),
  7205. extraParams : extraParams,
  7206. afterUpload : function(data) {
  7207. dialog.hideLoading();
  7208. if (data.error === 0) {
  7209. var url = data.url;
  7210. if (formatUploadUrl) {
  7211. url = K.formatUrl(url, 'absolute');
  7212. }
  7213. urlBox.val(url);
  7214. if (self.afterUpload) {
  7215. self.afterUpload.call(self, url, data, name);
  7216. }
  7217. alert(self.lang('uploadSuccess'));
  7218. } else {
  7219. alert(data.message);
  7220. }
  7221. },
  7222. afterError : function(html) {
  7223. dialog.hideLoading();
  7224. self.errorDialog(html);
  7225. }
  7226. });
  7227. uploadbutton.fileBox.change(function(e) {
  7228. dialog.showLoading(self.lang('uploadLoading'));
  7229. uploadbutton.submit();
  7230. });
  7231. } else {
  7232. K('.ke-upload-button', div).hide();
  7233. }
  7234. if (allowFileManager) {
  7235. viewServerBtn.click(function(e) {
  7236. self.loadPlugin('filemanager', function() {
  7237. self.plugin.filemanagerDialog({
  7238. viewType : 'LIST',
  7239. dirName : 'file',
  7240. clickFn : function(url, title) {
  7241. if (self.dialogs.length > 1) {
  7242. K('[name="url"]', div).val(url);
  7243. if (self.afterSelectFile) {
  7244. self.afterSelectFile.call(self, url);
  7245. }
  7246. self.hideDialog();
  7247. }
  7248. }
  7249. });
  7250. });
  7251. });
  7252. } else {
  7253. viewServerBtn.hide();
  7254. }
  7255. urlBox.val(fileUrl);
  7256. titleBox.val(fileTitle);
  7257. urlBox[0].focus();
  7258. urlBox[0].select();
  7259. };
  7260. self.clickToolbar(name, function() {
  7261. self.plugin.fileDialog({
  7262. clickFn : function(url, title) {
  7263. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7264. self.insertHtml(html).hideDialog().focus();
  7265. }
  7266. });
  7267. });
  7268. });
  7269. /*******************************************************************************
  7270. * KindEditor - WYSIWYG HTML Editor for Internet
  7271. * Copyright (C) 2006-2011 kindsoft.net
  7272. *
  7273. * @author Roddy <luolonghao@gmail.com>
  7274. * @site http://www.kindsoft.net/
  7275. * @licence http://www.kindsoft.net/license.php
  7276. *******************************************************************************/
  7277. KindEditor.plugin('lineheight', function(K) {
  7278. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7279. self.clickToolbar(name, function() {
  7280. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7281. if (commonNode) {
  7282. curVal = commonNode.css('line-height');
  7283. }
  7284. var menu = self.createMenu({
  7285. name : name,
  7286. width : 150
  7287. });
  7288. K.each(lang.lineHeight, function(i, row) {
  7289. K.each(row, function(key, val) {
  7290. menu.addItem({
  7291. title : val,
  7292. checked : curVal === key,
  7293. click : function() {
  7294. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7295. span : '.line-height=' + key
  7296. });
  7297. self.updateState();
  7298. self.addBookmark();
  7299. self.hideMenu();
  7300. }
  7301. });
  7302. });
  7303. });
  7304. });
  7305. });
  7306. /*******************************************************************************
  7307. * KindEditor - WYSIWYG HTML Editor for Internet
  7308. * Copyright (C) 2006-2011 kindsoft.net
  7309. *
  7310. * @author Roddy <luolonghao@gmail.com>
  7311. * @site http://www.kindsoft.net/
  7312. * @licence http://www.kindsoft.net/license.php
  7313. *******************************************************************************/
  7314. KindEditor.plugin('link', function(K) {
  7315. var self = this, name = 'link';
  7316. self.plugin.link = {
  7317. edit : function() {
  7318. var lang = self.lang(name + '.'),
  7319. html = '<div style="padding:20px;">' +
  7320. //url
  7321. '<div class="ke-dialog-row">' +
  7322. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7323. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7324. //type
  7325. '<div class="ke-dialog-row"">' +
  7326. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7327. '<select id="keType" name="type"></select>' +
  7328. '</div>' +
  7329. '</div>',
  7330. dialog = self.createDialog({
  7331. name : name,
  7332. width : 450,
  7333. title : self.lang(name),
  7334. body : html,
  7335. yesBtn : {
  7336. name : self.lang('yes'),
  7337. click : function(e) {
  7338. var url = K.trim(urlBox.val());
  7339. if (url == 'http://' || K.invalidUrl(url)) {
  7340. alert(self.lang('invalidUrl'));
  7341. urlBox[0].focus();
  7342. return;
  7343. }
  7344. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7345. }
  7346. }
  7347. }),
  7348. div = dialog.div,
  7349. urlBox = K('input[name="url"]', div),
  7350. typeBox = K('select[name="type"]', div);
  7351. urlBox.val('http://');
  7352. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7353. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7354. self.cmd.selection();
  7355. var a = self.plugin.getSelectedLink();
  7356. if (a) {
  7357. self.cmd.range.selectNode(a[0]);
  7358. self.cmd.select();
  7359. urlBox.val(a.attr('data-ke-src'));
  7360. typeBox.val(a.attr('target'));
  7361. }
  7362. urlBox[0].focus();
  7363. urlBox[0].select();
  7364. },
  7365. 'delete' : function() {
  7366. self.exec('unlink', null);
  7367. }
  7368. };
  7369. self.clickToolbar(name, self.plugin.link.edit);
  7370. });
  7371. /*******************************************************************************
  7372. * KindEditor - WYSIWYG HTML Editor for Internet
  7373. * Copyright (C) 2006-2011 kindsoft.net
  7374. *
  7375. * @author Roddy <luolonghao@gmail.com>
  7376. * @site http://www.kindsoft.net/
  7377. * @licence http://www.kindsoft.net/license.php
  7378. *******************************************************************************/
  7379. // Google Maps: http://code.google.com/apis/maps/index.html
  7380. KindEditor.plugin('map', function(K) {
  7381. var self = this, name = 'map', lang = self.lang(name + '.');
  7382. self.clickToolbar(name, function() {
  7383. var html = ['<div style="padding:10px 20px;">',
  7384. '<div class="ke-dialog-row">',
  7385. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  7386. '<span class="ke-button-common ke-button-outer">',
  7387. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  7388. '</span>',
  7389. '</div>',
  7390. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  7391. '</div>'].join('');
  7392. var dialog = self.createDialog({
  7393. name : name,
  7394. width : 600,
  7395. title : self.lang(name),
  7396. body : html,
  7397. yesBtn : {
  7398. name : self.lang('yes'),
  7399. click : function(e) {
  7400. var geocoder = win.geocoder,
  7401. map = win.map,
  7402. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  7403. zoom = map.getZoom(),
  7404. maptype = map.getMapTypeId(),
  7405. url = 'http://maps.googleapis.com/maps/api/staticmap';
  7406. url += '?center=' + encodeURIComponent(center);
  7407. url += '&zoom=' + encodeURIComponent(zoom);
  7408. url += '&size=558x360';
  7409. url += '&maptype=' + encodeURIComponent(maptype);
  7410. url += '&markers=' + encodeURIComponent(center);
  7411. url += '&language=' + self.langType;
  7412. url += '&sensor=false';
  7413. self.exec('insertimage', url).hideDialog().focus();
  7414. }
  7415. },
  7416. beforeRemove : function() {
  7417. searchBtn.remove();
  7418. if (doc) {
  7419. doc.write('');
  7420. }
  7421. iframe.remove();
  7422. }
  7423. });
  7424. var div = dialog.div,
  7425. addressBox = K('[name="address"]', div),
  7426. searchBtn = K('[name="searchBtn"]', div),
  7427. win, doc;
  7428. var iframeHtml = ['<!doctype html><html><head>',
  7429. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  7430. '<style>',
  7431. ' html { height: 100% }',
  7432. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  7433. ' #map_canvas { height: 100% }',
  7434. '</style>',
  7435. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  7436. '<script>',
  7437. 'var map, geocoder;',
  7438. 'function initialize() {',
  7439. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  7440. ' var options = {',
  7441. ' zoom: 11,',
  7442. ' center: latlng,',
  7443. ' disableDefaultUI: true,',
  7444. ' panControl: true,',
  7445. ' zoomControl: true,',
  7446. ' mapTypeControl: true,',
  7447. ' scaleControl: true,',
  7448. ' streetViewControl: false,',
  7449. ' overviewMapControl: true,',
  7450. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  7451. ' };',
  7452. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  7453. ' geocoder = new google.maps.Geocoder();',
  7454. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  7455. ' if (status == google.maps.GeocoderStatus.OK) {',
  7456. ' if (results[3]) {',
  7457. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  7458. ' }',
  7459. ' }',
  7460. ' });',
  7461. '}',
  7462. 'function search(address) {',
  7463. ' if (!map) return;',
  7464. ' geocoder.geocode({address : address}, function(results, status) {',
  7465. ' if (status == google.maps.GeocoderStatus.OK) {',
  7466. ' map.setZoom(11);',
  7467. ' map.setCenter(results[0].geometry.location);',
  7468. ' var marker = new google.maps.Marker({',
  7469. ' map: map,',
  7470. ' position: results[0].geometry.location',
  7471. ' });',
  7472. ' } else {',
  7473. ' alert("Invalid address: " + address);',
  7474. ' }',
  7475. ' });',
  7476. '}',
  7477. '</script>',
  7478. '</head>',
  7479. '<body onload="initialize();">',
  7480. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  7481. '</body></html>'].join('\n');
  7482. // TODO:用doc.write(iframeHtml)方式加载时,在IE6上第一次加载报错,暂时使用src方式
  7483. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  7484. function ready() {
  7485. win = iframe[0].contentWindow;
  7486. doc = K.iframeDoc(iframe);
  7487. //doc.open();
  7488. //doc.write(iframeHtml);
  7489. //doc.close();
  7490. }
  7491. iframe.bind('load', function() {
  7492. iframe.unbind('load');
  7493. if (K.IE) {
  7494. ready();
  7495. } else {
  7496. setTimeout(ready, 0);
  7497. }
  7498. });
  7499. K('.ke-map', div).replaceWith(iframe);
  7500. // search map
  7501. searchBtn.click(function() {
  7502. win.search(addressBox.val());
  7503. });
  7504. });
  7505. });
  7506. /*******************************************************************************
  7507. * KindEditor - WYSIWYG HTML Editor for Internet
  7508. * Copyright (C) 2006-2011 kindsoft.net
  7509. *
  7510. * @author Roddy <luolonghao@gmail.com>
  7511. * @site http://www.kindsoft.net/
  7512. * @licence http://www.kindsoft.net/license.php
  7513. *******************************************************************************/
  7514. KindEditor.plugin('media', function(K) {
  7515. var self = this, name = 'media', lang = self.lang(name + '.'),
  7516. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7517. allowFileManager = K.undef(self.allowFileManager, false),
  7518. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7519. extraParams = K.undef(self.extraFileUploadParams, {}),
  7520. filePostName = K.undef(self.filePostName, 'imgFile'),
  7521. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7522. self.plugin.media = {
  7523. edit : function() {
  7524. var html = [
  7525. '<div style="padding:20px;">',
  7526. //url
  7527. '<div class="ke-dialog-row">',
  7528. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7529. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7530. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7531. '<span class="ke-button-common ke-button-outer">',
  7532. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7533. '</span>',
  7534. '</div>',
  7535. //width
  7536. '<div class="ke-dialog-row">',
  7537. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7538. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7539. '</div>',
  7540. //height
  7541. '<div class="ke-dialog-row">',
  7542. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7543. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7544. '</div>',
  7545. //autostart
  7546. '<div class="ke-dialog-row">',
  7547. '<label for="keAutostart">' + lang.autostart + '</label>',
  7548. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7549. '</div>',
  7550. '</div>'
  7551. ].join('');
  7552. var dialog = self.createDialog({
  7553. name : name,
  7554. width : 450,
  7555. height : 230,
  7556. title : self.lang(name),
  7557. body : html,
  7558. yesBtn : {
  7559. name : self.lang('yes'),
  7560. click : function(e) {
  7561. var url = K.trim(urlBox.val()),
  7562. width = widthBox.val(),
  7563. height = heightBox.val();
  7564. if (url == 'http://' || K.invalidUrl(url)) {
  7565. alert(self.lang('invalidUrl'));
  7566. urlBox[0].focus();
  7567. return;
  7568. }
  7569. if (!/^\d*$/.test(width)) {
  7570. alert(self.lang('invalidWidth'));
  7571. widthBox[0].focus();
  7572. return;
  7573. }
  7574. if (!/^\d*$/.test(height)) {
  7575. alert(self.lang('invalidHeight'));
  7576. heightBox[0].focus();
  7577. return;
  7578. }
  7579. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7580. src : url,
  7581. type : K.mediaType(url),
  7582. width : width,
  7583. height : height,
  7584. autostart : autostartBox[0].checked ? 'true' : 'false',
  7585. loop : 'true'
  7586. });
  7587. self.insertHtml(html).hideDialog().focus();
  7588. }
  7589. }
  7590. }),
  7591. div = dialog.div,
  7592. urlBox = K('[name="url"]', div),
  7593. viewServerBtn = K('[name="viewServer"]', div),
  7594. widthBox = K('[name="width"]', div),
  7595. heightBox = K('[name="height"]', div),
  7596. autostartBox = K('[name="autostart"]', div);
  7597. urlBox.val('http://');
  7598. if (allowMediaUpload) {
  7599. var uploadbutton = K.uploadbutton({
  7600. button : K('.ke-upload-button', div)[0],
  7601. fieldName : filePostName,
  7602. extraParams : extraParams,
  7603. url : K.addParam(uploadJson, 'dir=media'),
  7604. afterUpload : function(data) {
  7605. dialog.hideLoading();
  7606. if (data.error === 0) {
  7607. var url = data.url;
  7608. if (formatUploadUrl) {
  7609. url = K.formatUrl(url, 'absolute');
  7610. }
  7611. urlBox.val(url);
  7612. if (self.afterUpload) {
  7613. self.afterUpload.call(self, url, data, name);
  7614. }
  7615. alert(self.lang('uploadSuccess'));
  7616. } else {
  7617. alert(data.message);
  7618. }
  7619. },
  7620. afterError : function(html) {
  7621. dialog.hideLoading();
  7622. self.errorDialog(html);
  7623. }
  7624. });
  7625. uploadbutton.fileBox.change(function(e) {
  7626. dialog.showLoading(self.lang('uploadLoading'));
  7627. uploadbutton.submit();
  7628. });
  7629. } else {
  7630. K('.ke-upload-button', div).hide();
  7631. }
  7632. if (allowFileManager) {
  7633. viewServerBtn.click(function(e) {
  7634. self.loadPlugin('filemanager', function() {
  7635. self.plugin.filemanagerDialog({
  7636. viewType : 'LIST',
  7637. dirName : 'media',
  7638. clickFn : function(url, title) {
  7639. if (self.dialogs.length > 1) {
  7640. K('[name="url"]', div).val(url);
  7641. if (self.afterSelectFile) {
  7642. self.afterSelectFile.call(self, url);
  7643. }
  7644. self.hideDialog();
  7645. }
  7646. }
  7647. });
  7648. });
  7649. });
  7650. } else {
  7651. viewServerBtn.hide();
  7652. }
  7653. var img = self.plugin.getSelectedMedia();
  7654. if (img) {
  7655. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7656. urlBox.val(attrs.src);
  7657. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7658. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7659. autostartBox[0].checked = (attrs.autostart === 'true');
  7660. }
  7661. urlBox[0].focus();
  7662. urlBox[0].select();
  7663. },
  7664. 'delete' : function() {
  7665. self.plugin.getSelectedMedia().remove();
  7666. // [IE] 删除图片后立即点击图片按钮出错
  7667. self.addBookmark();
  7668. }
  7669. };
  7670. self.clickToolbar(name, self.plugin.media.edit);
  7671. });
  7672. /*******************************************************************************
  7673. * KindEditor - WYSIWYG HTML Editor for Internet
  7674. * Copyright (C) 2006-2011 kindsoft.net
  7675. *
  7676. * @author Roddy <luolonghao@gmail.com>
  7677. * @site http://www.kindsoft.net/
  7678. * @licence http://www.kindsoft.net/license.php
  7679. *******************************************************************************/
  7680. (function(K) {
  7681. function KSWFUpload(options) {
  7682. this.init(options);
  7683. }
  7684. K.extend(KSWFUpload, {
  7685. init : function(options) {
  7686. var self = this;
  7687. options.afterError = options.afterError || function(str) {
  7688. alert(str);
  7689. };
  7690. self.options = options;
  7691. self.progressbars = {};
  7692. // template
  7693. self.div = K(options.container).html([
  7694. '<div class="ke-swfupload">',
  7695. '<div class="ke-swfupload-top">',
  7696. '<div class="ke-inline-block ke-swfupload-button">',
  7697. '<input type="button" value="Browse" />',
  7698. '</div>',
  7699. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7700. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7701. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7702. '</span>',
  7703. '</div>',
  7704. '<div class="ke-swfupload-body"></div>',
  7705. '</div>'
  7706. ].join(''));
  7707. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7708. function showError(itemDiv, msg) {
  7709. K('.ke-status > div', itemDiv).hide();
  7710. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7711. }
  7712. var settings = {
  7713. debug : false,
  7714. upload_url : options.uploadUrl,
  7715. flash_url : options.flashUrl,
  7716. file_post_name : options.filePostName,
  7717. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7718. button_image_url: options.buttonImageUrl,
  7719. button_width: options.buttonWidth,
  7720. button_height: options.buttonHeight,
  7721. button_cursor : SWFUpload.CURSOR.HAND,
  7722. file_types : options.fileTypes,
  7723. file_types_description : options.fileTypesDesc,
  7724. file_upload_limit : options.fileUploadLimit,
  7725. file_size_limit : options.fileSizeLimit,
  7726. post_params : options.postParams,
  7727. file_queued_handler : function(file) {
  7728. file.url = self.options.fileIconUrl;
  7729. self.appendFile(file);
  7730. },
  7731. file_queue_error_handler : function(file, errorCode, message) {
  7732. var errorName = '';
  7733. switch (errorCode) {
  7734. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7735. errorName = options.queueLimitExceeded;
  7736. break;
  7737. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7738. errorName = options.fileExceedsSizeLimit;
  7739. break;
  7740. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7741. errorName = options.zeroByteFile;
  7742. break;
  7743. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7744. errorName = options.invalidFiletype;
  7745. break;
  7746. default:
  7747. errorName = options.unknownError;
  7748. break;
  7749. }
  7750. K.DEBUG && alert(errorName);
  7751. },
  7752. upload_start_handler : function(file) {
  7753. var self = this;
  7754. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7755. K('.ke-status > div', itemDiv).hide();
  7756. K('.ke-progressbar', itemDiv).show();
  7757. },
  7758. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7759. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7760. var progressbar = self.progressbars[file.id];
  7761. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7762. progressbar.percent.html(percent + '%');
  7763. },
  7764. upload_error_handler : function(file, errorCode, message) {
  7765. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7766. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7767. showError(itemDiv, self.options.errorMessage);
  7768. }
  7769. },
  7770. upload_success_handler : function(file, serverData) {
  7771. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7772. var data = {};
  7773. try {
  7774. data = K.json(serverData);
  7775. } catch (e) {
  7776. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7777. }
  7778. if (data.error !== 0) {
  7779. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7780. return;
  7781. }
  7782. file.url = data.url;
  7783. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7784. K('.ke-status > div', itemDiv).hide();
  7785. }
  7786. };
  7787. self.swfu = new SWFUpload(settings);
  7788. K('.ke-swfupload-startupload input', self.div).click(function() {
  7789. self.swfu.startUpload();
  7790. });
  7791. },
  7792. getUrlList : function() {
  7793. var list = [];
  7794. K('.ke-img', self.bodyDiv).each(function() {
  7795. var img = K(this);
  7796. var status = img.attr('data-status');
  7797. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7798. list.push(img.data('data'));
  7799. }
  7800. });
  7801. return list;
  7802. },
  7803. removeFile : function(fileId) {
  7804. var self = this;
  7805. self.swfu.cancelUpload(fileId);
  7806. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7807. K('.ke-photo', itemDiv).unbind();
  7808. K('.ke-delete', itemDiv).unbind();
  7809. itemDiv.remove();
  7810. },
  7811. removeFiles : function() {
  7812. var self = this;
  7813. K('.ke-item', self.bodyDiv).each(function() {
  7814. self.removeFile(K(this).attr('data-id'));
  7815. });
  7816. },
  7817. appendFile : function(file) {
  7818. var self = this;
  7819. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7820. self.bodyDiv.append(itemDiv);
  7821. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7822. .mouseover(function(e) {
  7823. K(this).addClass('ke-on');
  7824. })
  7825. .mouseout(function(e) {
  7826. K(this).removeClass('ke-on');
  7827. });
  7828. itemDiv.append(photoDiv);
  7829. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7830. photoDiv.append(img);
  7831. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  7832. self.removeFile(file.id);
  7833. });
  7834. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7835. // progressbar
  7836. K(['<div class="ke-progressbar">',
  7837. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7838. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7839. // message
  7840. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7841. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7842. self.progressbars[file.id] = {
  7843. bar : K('.ke-progressbar-bar-inner', photoDiv),
  7844. percent : K('.ke-progressbar-percent', photoDiv)
  7845. };
  7846. },
  7847. remove : function() {
  7848. this.removeFiles();
  7849. this.swfu.destroy();
  7850. this.div.html('');
  7851. }
  7852. });
  7853. K.swfupload = function(element, options) {
  7854. return new KSWFUpload(element, options);
  7855. };
  7856. })(KindEditor);
  7857. KindEditor.plugin('multiimage', function(K) {
  7858. var self = this, name = 'multiimage',
  7859. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7860. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7861. imgPath = self.pluginsPath + 'multiimage/images/',
  7862. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  7863. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  7864. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  7865. filePostName = K.undef(self.filePostName, 'imgFile'),
  7866. lang = self.lang(name + '.');
  7867. self.plugin.multiImageDialog = function(options) {
  7868. var clickFn = options.clickFn,
  7869. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  7870. var html = [
  7871. '<div style="padding:20px;">',
  7872. '<div class="swfupload">',
  7873. '</div>',
  7874. '</div>'
  7875. ].join('');
  7876. var dialog = self.createDialog({
  7877. name : name,
  7878. width : 650,
  7879. height : 510,
  7880. title : self.lang(name),
  7881. body : html,
  7882. previewBtn : {
  7883. name : lang.insertAll,
  7884. click : function(e) {
  7885. clickFn.call(self, swfupload.getUrlList());
  7886. }
  7887. },
  7888. yesBtn : {
  7889. name : lang.clearAll,
  7890. click : function(e) {
  7891. swfupload.removeFiles();
  7892. }
  7893. },
  7894. beforeRemove : function() {
  7895. // IE9 bugfix: https://github.com/kindsoft/kindeditor/issues/72
  7896. if (!K.IE || K.V <= 8) {
  7897. swfupload.remove();
  7898. }
  7899. }
  7900. }),
  7901. div = dialog.div;
  7902. var swfupload = K.swfupload({
  7903. container : K('.swfupload', div),
  7904. buttonImageUrl : imgPath + (self.langType == 'zh_CN' ? 'select-files-zh_CN.png' : 'select-files-en.png'),
  7905. buttonWidth : self.langType == 'zh_CN' ? 72 : 88,
  7906. buttonHeight : 23,
  7907. fileIconUrl : imgPath + 'image.png',
  7908. uploadDesc : uploadDesc,
  7909. startButtonValue : lang.startUpload,
  7910. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  7911. flashUrl : imgPath + 'swfupload.swf',
  7912. filePostName : filePostName,
  7913. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  7914. fileTypesDesc : 'Image Files',
  7915. fileUploadLimit : imageUploadLimit,
  7916. fileSizeLimit : imageSizeLimit,
  7917. postParams : K.undef(self.extraFileUploadParams, {}),
  7918. queueLimitExceeded : lang.queueLimitExceeded,
  7919. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  7920. zeroByteFile : lang.zeroByteFile,
  7921. invalidFiletype : lang.invalidFiletype,
  7922. unknownError : lang.unknownError,
  7923. pendingMessage : lang.pending,
  7924. errorMessage : lang.uploadError,
  7925. afterError : function(html) {
  7926. self.errorDialog(html);
  7927. }
  7928. });
  7929. return dialog;
  7930. };
  7931. self.clickToolbar(name, function() {
  7932. self.plugin.multiImageDialog({
  7933. clickFn : function (urlList) {
  7934. if (urlList.length === 0) {
  7935. return;
  7936. }
  7937. K.each(urlList, function(i, data) {
  7938. if (self.afterUpload) {
  7939. self.afterUpload.call(self, data.url, data, 'multiimage');
  7940. }
  7941. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  7942. });
  7943. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  7944. setTimeout(function() {
  7945. self.hideDialog().focus();
  7946. }, 0);
  7947. }
  7948. });
  7949. });
  7950. });
  7951. /**
  7952. * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
  7953. *
  7954. * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
  7955. *
  7956. * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz閚 and Mammon Media and is released under the MIT License:
  7957. * http://www.opensource.org/licenses/mit-license.php
  7958. *
  7959. * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
  7960. * http://www.opensource.org/licenses/mit-license.php
  7961. *
  7962. */
  7963. /* ******************* */
  7964. /* Constructor & Init */
  7965. /* ******************* */
  7966. (function() {
  7967. if (window.SWFUpload) {
  7968. return;
  7969. }
  7970. window.SWFUpload = function (settings) {
  7971. this.initSWFUpload(settings);
  7972. };
  7973. SWFUpload.prototype.initSWFUpload = function (settings) {
  7974. try {
  7975. this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
  7976. this.settings = settings;
  7977. this.eventQueue = [];
  7978. this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
  7979. this.movieElement = null;
  7980. // Setup global control tracking
  7981. SWFUpload.instances[this.movieName] = this;
  7982. // Load the settings. Load the Flash movie.
  7983. this.initSettings();
  7984. this.loadFlash();
  7985. this.displayDebugInfo();
  7986. } catch (ex) {
  7987. delete SWFUpload.instances[this.movieName];
  7988. throw ex;
  7989. }
  7990. };
  7991. /* *************** */
  7992. /* Static Members */
  7993. /* *************** */
  7994. SWFUpload.instances = {};
  7995. SWFUpload.movieCount = 0;
  7996. SWFUpload.version = "2.2.0 2009-03-25";
  7997. SWFUpload.QUEUE_ERROR = {
  7998. QUEUE_LIMIT_EXCEEDED : -100,
  7999. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8000. ZERO_BYTE_FILE : -120,
  8001. INVALID_FILETYPE : -130
  8002. };
  8003. SWFUpload.UPLOAD_ERROR = {
  8004. HTTP_ERROR : -200,
  8005. MISSING_UPLOAD_URL : -210,
  8006. IO_ERROR : -220,
  8007. SECURITY_ERROR : -230,
  8008. UPLOAD_LIMIT_EXCEEDED : -240,
  8009. UPLOAD_FAILED : -250,
  8010. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8011. FILE_VALIDATION_FAILED : -270,
  8012. FILE_CANCELLED : -280,
  8013. UPLOAD_STOPPED : -290
  8014. };
  8015. SWFUpload.FILE_STATUS = {
  8016. QUEUED : -1,
  8017. IN_PROGRESS : -2,
  8018. ERROR : -3,
  8019. COMPLETE : -4,
  8020. CANCELLED : -5
  8021. };
  8022. SWFUpload.BUTTON_ACTION = {
  8023. SELECT_FILE : -100,
  8024. SELECT_FILES : -110,
  8025. START_UPLOAD : -120
  8026. };
  8027. SWFUpload.CURSOR = {
  8028. ARROW : -1,
  8029. HAND : -2
  8030. };
  8031. SWFUpload.WINDOW_MODE = {
  8032. WINDOW : "window",
  8033. TRANSPARENT : "transparent",
  8034. OPAQUE : "opaque"
  8035. };
  8036. // Private: takes a URL, determines if it is relative and converts to an absolute URL
  8037. // using the current site. Only processes the URL if it can, otherwise returns the URL untouched
  8038. SWFUpload.completeURL = function(url) {
  8039. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8040. return url;
  8041. }
  8042. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8043. var indexSlash = window.location.pathname.lastIndexOf("/");
  8044. if (indexSlash <= 0) {
  8045. path = "/";
  8046. } else {
  8047. path = window.location.pathname.substr(0, indexSlash) + "/";
  8048. }
  8049. return /*currentURL +*/ path + url;
  8050. };
  8051. /* ******************** */
  8052. /* Instance Members */
  8053. /* ******************** */
  8054. // Private: initSettings ensures that all the
  8055. // settings are set, getting a default value if one was not assigned.
  8056. SWFUpload.prototype.initSettings = function () {
  8057. this.ensureDefault = function (settingName, defaultValue) {
  8058. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8059. };
  8060. // Upload backend settings
  8061. this.ensureDefault("upload_url", "");
  8062. this.ensureDefault("preserve_relative_urls", false);
  8063. this.ensureDefault("file_post_name", "Filedata");
  8064. this.ensureDefault("post_params", {});
  8065. this.ensureDefault("use_query_string", false);
  8066. this.ensureDefault("requeue_on_error", false);
  8067. this.ensureDefault("http_success", []);
  8068. this.ensureDefault("assume_success_timeout", 0);
  8069. // File Settings
  8070. this.ensureDefault("file_types", "*.*");
  8071. this.ensureDefault("file_types_description", "All Files");
  8072. this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
  8073. this.ensureDefault("file_upload_limit", 0);
  8074. this.ensureDefault("file_queue_limit", 0);
  8075. // Flash Settings
  8076. this.ensureDefault("flash_url", "swfupload.swf");
  8077. this.ensureDefault("prevent_swf_caching", true);
  8078. // Button Settings
  8079. this.ensureDefault("button_image_url", "");
  8080. this.ensureDefault("button_width", 1);
  8081. this.ensureDefault("button_height", 1);
  8082. this.ensureDefault("button_text", "");
  8083. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8084. this.ensureDefault("button_text_top_padding", 0);
  8085. this.ensureDefault("button_text_left_padding", 0);
  8086. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8087. this.ensureDefault("button_disabled", false);
  8088. this.ensureDefault("button_placeholder_id", "");
  8089. this.ensureDefault("button_placeholder", null);
  8090. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8091. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8092. // Debug Settings
  8093. this.ensureDefault("debug", false);
  8094. this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
  8095. // Event Handlers
  8096. this.settings.return_upload_start_handler = this.returnUploadStart;
  8097. this.ensureDefault("swfupload_loaded_handler", null);
  8098. this.ensureDefault("file_dialog_start_handler", null);
  8099. this.ensureDefault("file_queued_handler", null);
  8100. this.ensureDefault("file_queue_error_handler", null);
  8101. this.ensureDefault("file_dialog_complete_handler", null);
  8102. this.ensureDefault("upload_start_handler", null);
  8103. this.ensureDefault("upload_progress_handler", null);
  8104. this.ensureDefault("upload_error_handler", null);
  8105. this.ensureDefault("upload_success_handler", null);
  8106. this.ensureDefault("upload_complete_handler", null);
  8107. this.ensureDefault("debug_handler", this.debugMessage);
  8108. this.ensureDefault("custom_settings", {});
  8109. // Other settings
  8110. this.customSettings = this.settings.custom_settings;
  8111. // Update the flash url if needed
  8112. if (!!this.settings.prevent_swf_caching) {
  8113. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8114. }
  8115. if (!this.settings.preserve_relative_urls) {
  8116. //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it
  8117. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8118. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8119. }
  8120. delete this.ensureDefault;
  8121. };
  8122. // Private: loadFlash replaces the button_placeholder element with the flash movie.
  8123. SWFUpload.prototype.loadFlash = function () {
  8124. var targetElement, tempParent;
  8125. // Make sure an element with the ID we are going to use doesn't already exist
  8126. if (document.getElementById(this.movieName) !== null) {
  8127. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8128. }
  8129. // Get the element where we will be placing the flash movie
  8130. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8131. if (targetElement == undefined) {
  8132. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8133. }
  8134. // Append the container and load the flash
  8135. tempParent = document.createElement("div");
  8136. tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
  8137. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8138. // Fix IE Flash/Form bug
  8139. if (window[this.movieName] == undefined) {
  8140. window[this.movieName] = this.getMovieElement();
  8141. }
  8142. };
  8143. // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
  8144. SWFUpload.prototype.getFlashHTML = function () {
  8145. // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  8146. // Fix bug for IE9
  8147. // http://www.kindsoft.net/view.php?bbsid=7&postid=5825&pagenum=1
  8148. var classid = '';
  8149. if (KindEditor.IE && KindEditor.V > 8) {
  8150. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8151. }
  8152. 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">',
  8153. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8154. '<param name="movie" value="', this.settings.flash_url, '" />',
  8155. '<param name="quality" value="high" />',
  8156. '<param name="menu" value="false" />',
  8157. '<param name="allowScriptAccess" value="always" />',
  8158. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8159. '</object>'].join("");
  8160. };
  8161. // Private: getFlashVars builds the parameter string that will be passed
  8162. // to flash in the flashvars param.
  8163. SWFUpload.prototype.getFlashVars = function () {
  8164. // Build a string from the post param object
  8165. var paramString = this.buildParamString();
  8166. var httpSuccessString = this.settings.http_success.join(",");
  8167. // Build the parameter string
  8168. return ["movieName=", encodeURIComponent(this.movieName),
  8169. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8170. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8171. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8172. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8173. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8174. "&amp;params=", encodeURIComponent(paramString),
  8175. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8176. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8177. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8178. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8179. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8180. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8181. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8182. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8183. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8184. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8185. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8186. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8187. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8188. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8189. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8190. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8191. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8192. ].join("");
  8193. };
  8194. // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
  8195. // The element is cached after the first lookup
  8196. SWFUpload.prototype.getMovieElement = function () {
  8197. if (this.movieElement == undefined) {
  8198. this.movieElement = document.getElementById(this.movieName);
  8199. }
  8200. if (this.movieElement === null) {
  8201. throw "Could not find Flash element";
  8202. }
  8203. return this.movieElement;
  8204. };
  8205. // Private: buildParamString takes the name/value pairs in the post_params setting object
  8206. // and joins them up in to a string formatted "name=value&amp;name=value"
  8207. SWFUpload.prototype.buildParamString = function () {
  8208. var postParams = this.settings.post_params;
  8209. var paramStringPairs = [];
  8210. if (typeof(postParams) === "object") {
  8211. for (var name in postParams) {
  8212. if (postParams.hasOwnProperty(name)) {
  8213. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8214. }
  8215. }
  8216. }
  8217. return paramStringPairs.join("&amp;");
  8218. };
  8219. // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
  8220. // all references to the SWF, and other objects so memory is properly freed.
  8221. // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
  8222. // Credits: Major improvements provided by steffen
  8223. SWFUpload.prototype.destroy = function () {
  8224. try {
  8225. // Make sure Flash is done before we try to remove it
  8226. this.cancelUpload(null, false);
  8227. // Remove the SWFUpload DOM nodes
  8228. var movieElement = null;
  8229. movieElement = this.getMovieElement();
  8230. if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8231. // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
  8232. for (var i in movieElement) {
  8233. try {
  8234. if (typeof(movieElement[i]) === "function") {
  8235. movieElement[i] = null;
  8236. }
  8237. } catch (ex1) {}
  8238. }
  8239. // Remove the Movie Element from the page
  8240. try {
  8241. movieElement.parentNode.removeChild(movieElement);
  8242. } catch (ex) {}
  8243. }
  8244. // Remove IE form fix reference
  8245. window[this.movieName] = null;
  8246. // Destroy other references
  8247. SWFUpload.instances[this.movieName] = null;
  8248. delete SWFUpload.instances[this.movieName];
  8249. this.movieElement = null;
  8250. this.settings = null;
  8251. this.customSettings = null;
  8252. this.eventQueue = null;
  8253. this.movieName = null;
  8254. return true;
  8255. } catch (ex2) {
  8256. return false;
  8257. }
  8258. };
  8259. // Public: displayDebugInfo prints out settings and configuration
  8260. // information about this SWFUpload instance.
  8261. // This function (and any references to it) can be deleted when placing
  8262. // SWFUpload in production.
  8263. SWFUpload.prototype.displayDebugInfo = function () {
  8264. this.debug(
  8265. [
  8266. "---SWFUpload Instance Info---\n",
  8267. "Version: ", SWFUpload.version, "\n",
  8268. "Movie Name: ", this.movieName, "\n",
  8269. "Settings:\n",
  8270. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8271. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8272. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8273. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8274. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8275. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8276. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8277. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8278. "\t", "file_types: ", this.settings.file_types, "\n",
  8279. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8280. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8281. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8282. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8283. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8284. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8285. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8286. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8287. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8288. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8289. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8290. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8291. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8292. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8293. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8294. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8295. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8296. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8297. "Event Handlers:\n",
  8298. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8299. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8300. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8301. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8302. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8303. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8304. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8305. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8306. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8307. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8308. ].join("")
  8309. );
  8310. };
  8311. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8312. the maintain v2 API compatibility
  8313. */
  8314. // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
  8315. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8316. if (value == undefined) {
  8317. return (this.settings[name] = default_value);
  8318. } else {
  8319. return (this.settings[name] = value);
  8320. }
  8321. };
  8322. // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
  8323. SWFUpload.prototype.getSetting = function (name) {
  8324. if (this.settings[name] != undefined) {
  8325. return this.settings[name];
  8326. }
  8327. return "";
  8328. };
  8329. // Private: callFlash handles function calls made to the Flash element.
  8330. // Calls are made with a setTimeout for some functions to work around
  8331. // bugs in the ExternalInterface library.
  8332. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8333. argumentArray = argumentArray || [];
  8334. var movieElement = this.getMovieElement();
  8335. var returnValue, returnString;
  8336. // Flash's method if calling ExternalInterface methods (code adapted from MooTools).
  8337. try {
  8338. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8339. returnValue = eval(returnString);
  8340. } catch (ex) {
  8341. throw "Call to " + functionName + " failed";
  8342. }
  8343. // Unescape file post param values
  8344. if (returnValue != undefined && typeof returnValue.post === "object") {
  8345. returnValue = this.unescapeFilePostParams(returnValue);
  8346. }
  8347. return returnValue;
  8348. };
  8349. /* *****************************
  8350. -- Flash control methods --
  8351. Your UI should use these
  8352. to operate SWFUpload
  8353. ***************************** */
  8354. // WARNING: this function does not work in Flash Player 10
  8355. // Public: selectFile causes a File Selection Dialog window to appear. This
  8356. // dialog only allows 1 file to be selected.
  8357. SWFUpload.prototype.selectFile = function () {
  8358. this.callFlash("SelectFile");
  8359. };
  8360. // WARNING: this function does not work in Flash Player 10
  8361. // Public: selectFiles causes a File Selection Dialog window to appear/ This
  8362. // dialog allows the user to select any number of files
  8363. // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
  8364. // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
  8365. // for this bug.
  8366. SWFUpload.prototype.selectFiles = function () {
  8367. this.callFlash("SelectFiles");
  8368. };
  8369. // Public: startUpload starts uploading the first file in the queue unless
  8370. // the optional parameter 'fileID' specifies the ID
  8371. SWFUpload.prototype.startUpload = function (fileID) {
  8372. this.callFlash("StartUpload", [fileID]);
  8373. };
  8374. // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
  8375. // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
  8376. // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
  8377. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8378. if (triggerErrorEvent !== false) {
  8379. triggerErrorEvent = true;
  8380. }
  8381. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8382. };
  8383. // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
  8384. // If nothing is currently uploading then nothing happens.
  8385. SWFUpload.prototype.stopUpload = function () {
  8386. this.callFlash("StopUpload");
  8387. };
  8388. /* ************************
  8389. * Settings methods
  8390. * These methods change the SWFUpload settings.
  8391. * SWFUpload settings should not be changed directly on the settings object
  8392. * since many of the settings need to be passed to Flash in order to take
  8393. * effect.
  8394. * *********************** */
  8395. // Public: getStats gets the file statistics object.
  8396. SWFUpload.prototype.getStats = function () {
  8397. return this.callFlash("GetStats");
  8398. };
  8399. // Public: setStats changes the SWFUpload statistics. You shouldn't need to
  8400. // change the statistics but you can. Changing the statistics does not
  8401. // affect SWFUpload accept for the successful_uploads count which is used
  8402. // by the upload_limit setting to determine how many files the user may upload.
  8403. SWFUpload.prototype.setStats = function (statsObject) {
  8404. this.callFlash("SetStats", [statsObject]);
  8405. };
  8406. // Public: getFile retrieves a File object by ID or Index. If the file is
  8407. // not found then 'null' is returned.
  8408. SWFUpload.prototype.getFile = function (fileID) {
  8409. if (typeof(fileID) === "number") {
  8410. return this.callFlash("GetFileByIndex", [fileID]);
  8411. } else {
  8412. return this.callFlash("GetFile", [fileID]);
  8413. }
  8414. };
  8415. // Public: addFileParam sets a name/value pair that will be posted with the
  8416. // file specified by the Files ID. If the name already exists then the
  8417. // exiting value will be overwritten.
  8418. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8419. return this.callFlash("AddFileParam", [fileID, name, value]);
  8420. };
  8421. // Public: removeFileParam removes a previously set (by addFileParam) name/value
  8422. // pair from the specified file.
  8423. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8424. this.callFlash("RemoveFileParam", [fileID, name]);
  8425. };
  8426. // Public: setUploadUrl changes the upload_url setting.
  8427. SWFUpload.prototype.setUploadURL = function (url) {
  8428. this.settings.upload_url = url.toString();
  8429. this.callFlash("SetUploadURL", [url]);
  8430. };
  8431. // Public: setPostParams changes the post_params setting
  8432. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8433. this.settings.post_params = paramsObject;
  8434. this.callFlash("SetPostParams", [paramsObject]);
  8435. };
  8436. // Public: addPostParam adds post name/value pair. Each name can have only one value.
  8437. SWFUpload.prototype.addPostParam = function (name, value) {
  8438. this.settings.post_params[name] = value;
  8439. this.callFlash("SetPostParams", [this.settings.post_params]);
  8440. };
  8441. // Public: removePostParam deletes post name/value pair.
  8442. SWFUpload.prototype.removePostParam = function (name) {
  8443. delete this.settings.post_params[name];
  8444. this.callFlash("SetPostParams", [this.settings.post_params]);
  8445. };
  8446. // Public: setFileTypes changes the file_types setting and the file_types_description setting
  8447. SWFUpload.prototype.setFileTypes = function (types, description) {
  8448. this.settings.file_types = types;
  8449. this.settings.file_types_description = description;
  8450. this.callFlash("SetFileTypes", [types, description]);
  8451. };
  8452. // Public: setFileSizeLimit changes the file_size_limit setting
  8453. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8454. this.settings.file_size_limit = fileSizeLimit;
  8455. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8456. };
  8457. // Public: setFileUploadLimit changes the file_upload_limit setting
  8458. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8459. this.settings.file_upload_limit = fileUploadLimit;
  8460. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8461. };
  8462. // Public: setFileQueueLimit changes the file_queue_limit setting
  8463. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8464. this.settings.file_queue_limit = fileQueueLimit;
  8465. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8466. };
  8467. // Public: setFilePostName changes the file_post_name setting
  8468. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8469. this.settings.file_post_name = filePostName;
  8470. this.callFlash("SetFilePostName", [filePostName]);
  8471. };
  8472. // Public: setUseQueryString changes the use_query_string setting
  8473. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8474. this.settings.use_query_string = useQueryString;
  8475. this.callFlash("SetUseQueryString", [useQueryString]);
  8476. };
  8477. // Public: setRequeueOnError changes the requeue_on_error setting
  8478. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8479. this.settings.requeue_on_error = requeueOnError;
  8480. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8481. };
  8482. // Public: setHTTPSuccess changes the http_success setting
  8483. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8484. if (typeof http_status_codes === "string") {
  8485. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8486. }
  8487. this.settings.http_success = http_status_codes;
  8488. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8489. };
  8490. // Public: setHTTPSuccess changes the http_success setting
  8491. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8492. this.settings.assume_success_timeout = timeout_seconds;
  8493. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8494. };
  8495. // Public: setDebugEnabled changes the debug_enabled setting
  8496. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8497. this.settings.debug_enabled = debugEnabled;
  8498. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8499. };
  8500. // Public: setButtonImageURL loads a button image sprite
  8501. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8502. if (buttonImageURL == undefined) {
  8503. buttonImageURL = "";
  8504. }
  8505. this.settings.button_image_url = buttonImageURL;
  8506. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8507. };
  8508. // Public: setButtonDimensions resizes the Flash Movie and button
  8509. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8510. this.settings.button_width = width;
  8511. this.settings.button_height = height;
  8512. var movie = this.getMovieElement();
  8513. if (movie != undefined) {
  8514. movie.style.width = width + "px";
  8515. movie.style.height = height + "px";
  8516. }
  8517. this.callFlash("SetButtonDimensions", [width, height]);
  8518. };
  8519. // Public: setButtonText Changes the text overlaid on the button
  8520. SWFUpload.prototype.setButtonText = function (html) {
  8521. this.settings.button_text = html;
  8522. this.callFlash("SetButtonText", [html]);
  8523. };
  8524. // Public: setButtonTextPadding changes the top and left padding of the text overlay
  8525. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8526. this.settings.button_text_top_padding = top;
  8527. this.settings.button_text_left_padding = left;
  8528. this.callFlash("SetButtonTextPadding", [left, top]);
  8529. };
  8530. // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
  8531. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8532. this.settings.button_text_style = css;
  8533. this.callFlash("SetButtonTextStyle", [css]);
  8534. };
  8535. // Public: setButtonDisabled disables/enables the button
  8536. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8537. this.settings.button_disabled = isDisabled;
  8538. this.callFlash("SetButtonDisabled", [isDisabled]);
  8539. };
  8540. // Public: setButtonAction sets the action that occurs when the button is clicked
  8541. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8542. this.settings.button_action = buttonAction;
  8543. this.callFlash("SetButtonAction", [buttonAction]);
  8544. };
  8545. // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
  8546. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8547. this.settings.button_cursor = cursor;
  8548. this.callFlash("SetButtonCursor", [cursor]);
  8549. };
  8550. /* *******************************
  8551. Flash Event Interfaces
  8552. These functions are used by Flash to trigger the various
  8553. events.
  8554. All these functions a Private.
  8555. Because the ExternalInterface library is buggy the event calls
  8556. are added to a queue and the queue then executed by a setTimeout.
  8557. This ensures that events are executed in a determinate order and that
  8558. the ExternalInterface bugs are avoided.
  8559. ******************************* */
  8560. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8561. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8562. if (argumentArray == undefined) {
  8563. argumentArray = [];
  8564. } else if (!(argumentArray instanceof Array)) {
  8565. argumentArray = [argumentArray];
  8566. }
  8567. var self = this;
  8568. if (typeof this.settings[handlerName] === "function") {
  8569. // Queue the event
  8570. this.eventQueue.push(function () {
  8571. this.settings[handlerName].apply(this, argumentArray);
  8572. });
  8573. // Execute the next queued event
  8574. setTimeout(function () {
  8575. self.executeNextEvent();
  8576. }, 0);
  8577. } else if (this.settings[handlerName] !== null) {
  8578. throw "Event handler " + handlerName + " is unknown or is not a function";
  8579. }
  8580. };
  8581. // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
  8582. // we must queue them in order to garentee that they are executed in order.
  8583. SWFUpload.prototype.executeNextEvent = function () {
  8584. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8585. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8586. if (typeof(f) === "function") {
  8587. f.apply(this);
  8588. }
  8589. };
  8590. // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
  8591. // properties that contain characters that are not valid for JavaScript identifiers. To work around this
  8592. // the Flash Component escapes the parameter names and we must unescape again before passing them along.
  8593. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8594. var reg = /[$]([0-9a-f]{4})/i;
  8595. var unescapedPost = {};
  8596. var uk;
  8597. if (file != undefined) {
  8598. for (var k in file.post) {
  8599. if (file.post.hasOwnProperty(k)) {
  8600. uk = k;
  8601. var match;
  8602. while ((match = reg.exec(uk)) !== null) {
  8603. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8604. }
  8605. unescapedPost[uk] = file.post[k];
  8606. }
  8607. }
  8608. file.post = unescapedPost;
  8609. }
  8610. return file;
  8611. };
  8612. // Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working)
  8613. SWFUpload.prototype.testExternalInterface = function () {
  8614. try {
  8615. return this.callFlash("TestExternalInterface");
  8616. } catch (ex) {
  8617. return false;
  8618. }
  8619. };
  8620. // Private: This event is called by Flash when it has finished loading. Don't modify this.
  8621. // Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded.
  8622. SWFUpload.prototype.flashReady = function () {
  8623. // Check that the movie element is loaded correctly with its ExternalInterface methods defined
  8624. var movieElement = this.getMovieElement();
  8625. if (!movieElement) {
  8626. this.debug("Flash called back ready but the flash movie can't be found.");
  8627. return;
  8628. }
  8629. this.cleanUp(movieElement);
  8630. this.queueEvent("swfupload_loaded_handler");
  8631. };
  8632. // Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
  8633. // This function is called by Flash each time the ExternalInterface functions are created.
  8634. SWFUpload.prototype.cleanUp = function (movieElement) {
  8635. // Pro-actively unhook all the Flash functions
  8636. try {
  8637. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8638. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8639. for (var key in movieElement) {
  8640. try {
  8641. if (typeof(movieElement[key]) === "function") {
  8642. movieElement[key] = null;
  8643. }
  8644. } catch (ex) {
  8645. }
  8646. }
  8647. }
  8648. } catch (ex1) {
  8649. }
  8650. // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
  8651. // it doesn't display errors.
  8652. window["__flash__removeCallback"] = function (instance, name) {
  8653. try {
  8654. if (instance) {
  8655. instance[name] = null;
  8656. }
  8657. } catch (flashEx) {
  8658. }
  8659. };
  8660. };
  8661. /* This is a chance to do something before the browse window opens */
  8662. SWFUpload.prototype.fileDialogStart = function () {
  8663. this.queueEvent("file_dialog_start_handler");
  8664. };
  8665. /* Called when a file is successfully added to the queue. */
  8666. SWFUpload.prototype.fileQueued = function (file) {
  8667. file = this.unescapeFilePostParams(file);
  8668. this.queueEvent("file_queued_handler", file);
  8669. };
  8670. /* Handle errors that occur when an attempt to queue a file fails. */
  8671. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8672. file = this.unescapeFilePostParams(file);
  8673. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8674. };
  8675. /* Called after the file dialog has closed and the selected files have been queued.
  8676. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8677. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8678. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8679. };
  8680. SWFUpload.prototype.uploadStart = function (file) {
  8681. file = this.unescapeFilePostParams(file);
  8682. this.queueEvent("return_upload_start_handler", file);
  8683. };
  8684. SWFUpload.prototype.returnUploadStart = function (file) {
  8685. var returnValue;
  8686. if (typeof this.settings.upload_start_handler === "function") {
  8687. file = this.unescapeFilePostParams(file);
  8688. returnValue = this.settings.upload_start_handler.call(this, file);
  8689. } else if (this.settings.upload_start_handler != undefined) {
  8690. throw "upload_start_handler must be a function";
  8691. }
  8692. // Convert undefined to true so if nothing is returned from the upload_start_handler it is
  8693. // interpretted as 'true'.
  8694. if (returnValue === undefined) {
  8695. returnValue = true;
  8696. }
  8697. returnValue = !!returnValue;
  8698. this.callFlash("ReturnUploadStart", [returnValue]);
  8699. };
  8700. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8701. file = this.unescapeFilePostParams(file);
  8702. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8703. };
  8704. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8705. file = this.unescapeFilePostParams(file);
  8706. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8707. };
  8708. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8709. file = this.unescapeFilePostParams(file);
  8710. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8711. };
  8712. SWFUpload.prototype.uploadComplete = function (file) {
  8713. file = this.unescapeFilePostParams(file);
  8714. this.queueEvent("upload_complete_handler", file);
  8715. };
  8716. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8717. internal debug console. You can override this event and have messages written where you want. */
  8718. SWFUpload.prototype.debug = function (message) {
  8719. this.queueEvent("debug_handler", message);
  8720. };
  8721. /* **********************************
  8722. Debug Console
  8723. The debug console is a self contained, in page location
  8724. for debug message to be sent. The Debug Console adds
  8725. itself to the body if necessary.
  8726. The console is automatically scrolled as messages appear.
  8727. If you are using your own debug handler or when you deploy to production and
  8728. have debug disabled you can remove these functions to reduce the file size
  8729. and complexity.
  8730. ********************************** */
  8731. // Private: debugMessage is the default debug_handler. If you want to print debug messages
  8732. // call the debug() function. When overriding the function your own function should
  8733. // check to see if the debug setting is true before outputting debug information.
  8734. SWFUpload.prototype.debugMessage = function (message) {
  8735. if (this.settings.debug) {
  8736. var exceptionMessage, exceptionValues = [];
  8737. // Check for an exception object and print it nicely
  8738. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8739. for (var key in message) {
  8740. if (message.hasOwnProperty(key)) {
  8741. exceptionValues.push(key + ": " + message[key]);
  8742. }
  8743. }
  8744. exceptionMessage = exceptionValues.join("\n") || "";
  8745. exceptionValues = exceptionMessage.split("\n");
  8746. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8747. SWFUpload.Console.writeLine(exceptionMessage);
  8748. } else {
  8749. SWFUpload.Console.writeLine(message);
  8750. }
  8751. }
  8752. };
  8753. SWFUpload.Console = {};
  8754. SWFUpload.Console.writeLine = function (message) {
  8755. var console, documentForm;
  8756. try {
  8757. console = document.getElementById("SWFUpload_Console");
  8758. if (!console) {
  8759. documentForm = document.createElement("form");
  8760. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8761. console = document.createElement("textarea");
  8762. console.id = "SWFUpload_Console";
  8763. console.style.fontFamily = "monospace";
  8764. console.setAttribute("wrap", "off");
  8765. console.wrap = "off";
  8766. console.style.overflow = "auto";
  8767. console.style.width = "700px";
  8768. console.style.height = "350px";
  8769. console.style.margin = "5px";
  8770. documentForm.appendChild(console);
  8771. }
  8772. console.value += message + "\n";
  8773. console.scrollTop = console.scrollHeight - console.clientHeight;
  8774. } catch (ex) {
  8775. alert("Exception: " + ex.name + " Message: " + ex.message);
  8776. }
  8777. };
  8778. })();
  8779. (function() {
  8780. /*
  8781. Queue Plug-in
  8782. Features:
  8783. *Adds a cancelQueue() method for cancelling the entire queue.
  8784. *All queued files are uploaded when startUpload() is called.
  8785. *If false is returned from uploadComplete then the queue upload is stopped.
  8786. If false is not returned (strict comparison) then the queue upload is continued.
  8787. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8788. Set the event handler with the queue_complete_handler setting.
  8789. */
  8790. if (typeof(SWFUpload) === "function") {
  8791. SWFUpload.queue = {};
  8792. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8793. return function () {
  8794. if (typeof(oldInitSettings) === "function") {
  8795. oldInitSettings.call(this);
  8796. }
  8797. this.queueSettings = {};
  8798. this.queueSettings.queue_cancelled_flag = false;
  8799. this.queueSettings.queue_upload_count = 0;
  8800. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8801. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8802. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8803. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8804. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8805. };
  8806. })(SWFUpload.prototype.initSettings);
  8807. SWFUpload.prototype.startUpload = function (fileID) {
  8808. this.queueSettings.queue_cancelled_flag = false;
  8809. this.callFlash("StartUpload", [fileID]);
  8810. };
  8811. SWFUpload.prototype.cancelQueue = function () {
  8812. this.queueSettings.queue_cancelled_flag = true;
  8813. this.stopUpload();
  8814. var stats = this.getStats();
  8815. while (stats.files_queued > 0) {
  8816. this.cancelUpload();
  8817. stats = this.getStats();
  8818. }
  8819. };
  8820. SWFUpload.queue.uploadStartHandler = function (file) {
  8821. var returnValue;
  8822. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8823. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8824. }
  8825. // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
  8826. returnValue = (returnValue === false) ? false : true;
  8827. this.queueSettings.queue_cancelled_flag = !returnValue;
  8828. return returnValue;
  8829. };
  8830. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8831. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8832. var continueUpload;
  8833. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8834. this.queueSettings.queue_upload_count++;
  8835. }
  8836. if (typeof(user_upload_complete_handler) === "function") {
  8837. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8838. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8839. // If the file was stopped and re-queued don't restart the upload
  8840. continueUpload = false;
  8841. } else {
  8842. continueUpload = true;
  8843. }
  8844. if (continueUpload) {
  8845. var stats = this.getStats();
  8846. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8847. this.startUpload();
  8848. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8849. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8850. this.queueSettings.queue_upload_count = 0;
  8851. } else {
  8852. this.queueSettings.queue_cancelled_flag = false;
  8853. this.queueSettings.queue_upload_count = 0;
  8854. }
  8855. }
  8856. };
  8857. }
  8858. })();
  8859. /*******************************************************************************
  8860. * KindEditor - WYSIWYG HTML Editor for Internet
  8861. * Copyright (C) 2006-2011 kindsoft.net
  8862. *
  8863. * @author Roddy <luolonghao@gmail.com>
  8864. * @site http://www.kindsoft.net/
  8865. * @licence http://www.kindsoft.net/license.php
  8866. *******************************************************************************/
  8867. KindEditor.plugin('pagebreak', function(K) {
  8868. var self = this;
  8869. var name = 'pagebreak';
  8870. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8871. self.clickToolbar(name, function() {
  8872. var cmd = self.cmd, range = cmd.range;
  8873. self.focus();
  8874. range.enlarge(true);
  8875. cmd.split(true);
  8876. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<p id="__kindeditor_tail_tag__"></p>';
  8877. self.insertHtml(pagebreakHtml + tail);
  8878. if (tail !== '') {
  8879. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8880. range.selectNodeContents(p[0]);
  8881. p.removeAttr('id');
  8882. cmd.select();
  8883. }
  8884. });
  8885. });
  8886. /*******************************************************************************
  8887. * KindEditor - WYSIWYG HTML Editor for Internet
  8888. * Copyright (C) 2006-2011 kindsoft.net
  8889. *
  8890. * @author Roddy <luolonghao@gmail.com>
  8891. * @site http://www.kindsoft.net/
  8892. * @licence http://www.kindsoft.net/license.php
  8893. *******************************************************************************/
  8894. KindEditor.plugin('plainpaste', function(K) {
  8895. var self = this, name = 'plainpaste';
  8896. self.clickToolbar(name, function() {
  8897. var lang = self.lang(name + '.'),
  8898. html = '<div style="padding:10px 20px;">' +
  8899. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  8900. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  8901. '</div>',
  8902. dialog = self.createDialog({
  8903. name : name,
  8904. width : 450,
  8905. title : self.lang(name),
  8906. body : html,
  8907. yesBtn : {
  8908. name : self.lang('yes'),
  8909. click : function(e) {
  8910. var html = textarea.val();
  8911. html = K.escape(html);
  8912. html = html.replace(/ {2}/g, ' &nbsp;');
  8913. if (self.newlineTag == 'p') {
  8914. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  8915. } else {
  8916. html = html.replace(/\n/g, '<br />$&');
  8917. }
  8918. self.insertHtml(html).hideDialog().focus();
  8919. }
  8920. }
  8921. }),
  8922. textarea = K('textarea', dialog.div);
  8923. textarea[0].focus();
  8924. });
  8925. });
  8926. /*******************************************************************************
  8927. * KindEditor - WYSIWYG HTML Editor for Internet
  8928. * Copyright (C) 2006-2011 kindsoft.net
  8929. *
  8930. * @author Roddy <luolonghao@gmail.com>
  8931. * @site http://www.kindsoft.net/
  8932. * @licence http://www.kindsoft.net/license.php
  8933. *******************************************************************************/
  8934. KindEditor.plugin('preview', function(K) {
  8935. var self = this, name = 'preview', undefined;
  8936. self.clickToolbar(name, function() {
  8937. var lang = self.lang(name + '.'),
  8938. html = '<div style="padding:10px 20px;">' +
  8939. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  8940. '</div>',
  8941. dialog = self.createDialog({
  8942. name : name,
  8943. width : 750,
  8944. title : self.lang(name),
  8945. body : html
  8946. }),
  8947. iframe = K('iframe', dialog.div),
  8948. doc = K.iframeDoc(iframe);
  8949. doc.open();
  8950. doc.write(self.fullHtml());
  8951. doc.close();
  8952. K(doc.body).css('background-color', '#FFF');
  8953. iframe[0].contentWindow.focus();
  8954. });
  8955. });
  8956. /*******************************************************************************
  8957. * KindEditor - WYSIWYG HTML Editor for Internet
  8958. * Copyright (C) 2006-2011 kindsoft.net
  8959. *
  8960. * @author Roddy <luolonghao@gmail.com>
  8961. * @site http://www.kindsoft.net/
  8962. * @licence http://www.kindsoft.net/license.php
  8963. *******************************************************************************/
  8964. KindEditor.plugin('quickformat', function(K) {
  8965. var self = this, name = 'quickformat',
  8966. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  8967. function getFirstChild(knode) {
  8968. var child = knode.first();
  8969. while (child && child.first()) {
  8970. child = child.first();
  8971. }
  8972. return child;
  8973. }
  8974. self.clickToolbar(name, function() {
  8975. self.focus();
  8976. var doc = self.edit.doc,
  8977. range = self.cmd.range,
  8978. child = K(doc.body).first(), next,
  8979. nodeList = [], subList = [],
  8980. bookmark = range.createBookmark(true);
  8981. while(child) {
  8982. next = child.next();
  8983. var firstChild = getFirstChild(child);
  8984. if (!firstChild || firstChild.name != 'img') {
  8985. if (blockMap[child.name]) {
  8986. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  8987. child.css('text-indent', '2em');
  8988. } else {
  8989. subList.push(child);
  8990. }
  8991. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  8992. if (subList.length > 0) {
  8993. nodeList.push(subList);
  8994. }
  8995. subList = [];
  8996. }
  8997. }
  8998. child = next;
  8999. }
  9000. K.each(nodeList, function(i, subList) {
  9001. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9002. subList[0].before(wrapper);
  9003. K.each(subList, function(i, knode) {
  9004. wrapper.append(knode);
  9005. });
  9006. });
  9007. range.moveToBookmark(bookmark);
  9008. self.addBookmark();
  9009. });
  9010. });
  9011. /**
  9012. --------------------------
  9013. abcd<br />
  9014. 1234<br />
  9015. to
  9016. <p style="text-indent:2em;">
  9017. abcd<br />
  9018. 1234<br />
  9019. </p>
  9020. --------------------------
  9021. &nbsp; abcd<img>1233
  9022. <p>1234</p>
  9023. to
  9024. <p style="text-indent:2em;">abcd<img>1233</p>
  9025. <p style="text-indent:2em;">1234</p>
  9026. --------------------------
  9027. *//*******************************************************************************
  9028. * KindEditor - WYSIWYG HTML Editor for Internet
  9029. * Copyright (C) 2006-2011 kindsoft.net
  9030. *
  9031. * @author Roddy <luolonghao@gmail.com>
  9032. * @site http://www.kindsoft.net/
  9033. * @licence http://www.kindsoft.net/license.php
  9034. *******************************************************************************/
  9035. KindEditor.plugin('table', function(K) {
  9036. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9037. // 设置颜色
  9038. function _setColor(box, color) {
  9039. color = color.toUpperCase();
  9040. box.css('background-color', color);
  9041. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9042. box.html(color);
  9043. }
  9044. // 初始化取色器
  9045. var pickerList = [];
  9046. function _initColorPicker(dialogDiv, colorBox) {
  9047. colorBox.bind('click,mousedown', function(e){
  9048. e.stopPropagation();
  9049. });
  9050. function removePicker() {
  9051. K.each(pickerList, function() {
  9052. this.remove();
  9053. });
  9054. pickerList = [];
  9055. K(document).unbind('click,mousedown', removePicker);
  9056. dialogDiv.unbind('click,mousedown', removePicker);
  9057. }
  9058. colorBox.click(function(e) {
  9059. removePicker();
  9060. var box = K(this),
  9061. pos = box.pos();
  9062. var picker = K.colorpicker({
  9063. x : pos.x,
  9064. y : pos.y + box.height(),
  9065. z : 811214,
  9066. selectedColor : K(this).html(),
  9067. colors : self.colorTable,
  9068. noColor : self.lang('noColor'),
  9069. shadowMode : self.shadowMode,
  9070. click : function(color) {
  9071. _setColor(box, color);
  9072. removePicker();
  9073. }
  9074. });
  9075. pickerList.push(picker);
  9076. K(document).bind('click,mousedown', removePicker);
  9077. dialogDiv.bind('click,mousedown', removePicker);
  9078. });
  9079. }
  9080. // 取得下一行cell的index
  9081. function _getCellIndex(table, row, cell) {
  9082. var rowSpanCount = 0;
  9083. for (var i = 0, len = row.cells.length; i < len; i++) {
  9084. if (row.cells[i] == cell) {
  9085. break;
  9086. }
  9087. rowSpanCount += row.cells[i].rowSpan - 1;
  9088. }
  9089. return cell.cellIndex - rowSpanCount;
  9090. }
  9091. self.plugin.table = {
  9092. //insert or modify table
  9093. prop : function(isInsert) {
  9094. var html = [
  9095. '<div style="padding:20px;">',
  9096. //rows, cols
  9097. '<div class="ke-dialog-row">',
  9098. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9099. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9100. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9101. '</div>',
  9102. //width, height
  9103. '<div class="ke-dialog-row">',
  9104. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9105. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9106. '<select name="widthType">',
  9107. '<option value="%">' + lang.percent + '</option>',
  9108. '<option value="px">' + lang.px + '</option>',
  9109. '</select> &nbsp; ',
  9110. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9111. '<select name="heightType">',
  9112. '<option value="%">' + lang.percent + '</option>',
  9113. '<option value="px">' + lang.px + '</option>',
  9114. '</select>',
  9115. '</div>',
  9116. //space, padding
  9117. '<div class="ke-dialog-row">',
  9118. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9119. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9120. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9121. '</div>',
  9122. //align
  9123. '<div class="ke-dialog-row">',
  9124. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9125. '<select id="keAlign" name="align">',
  9126. '<option value="">' + lang.alignDefault + '</option>',
  9127. '<option value="left">' + lang.alignLeft + '</option>',
  9128. '<option value="center">' + lang.alignCenter + '</option>',
  9129. '<option value="right">' + lang.alignRight + '</option>',
  9130. '</select>',
  9131. '</div>',
  9132. //border
  9133. '<div class="ke-dialog-row">',
  9134. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9135. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9136. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9137. '</div>',
  9138. //background color
  9139. '<div class="ke-dialog-row">',
  9140. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9141. '<span class="ke-inline-block ke-input-color"></span>',
  9142. '</div>',
  9143. '</div>'
  9144. ].join('');
  9145. var dialog = self.createDialog({
  9146. name : name,
  9147. width : 500,
  9148. title : self.lang(name),
  9149. body : html,
  9150. beforeRemove : function() {
  9151. colorBox.unbind();
  9152. },
  9153. yesBtn : {
  9154. name : self.lang('yes'),
  9155. click : function(e) {
  9156. var rows = rowsBox.val(),
  9157. cols = colsBox.val(),
  9158. width = widthBox.val(),
  9159. height = heightBox.val(),
  9160. widthType = widthTypeBox.val(),
  9161. heightType = heightTypeBox.val(),
  9162. padding = paddingBox.val(),
  9163. spacing = spacingBox.val(),
  9164. align = alignBox.val(),
  9165. border = borderBox.val(),
  9166. borderColor = K(colorBox[0]).html() || '',
  9167. bgColor = K(colorBox[1]).html() || '';
  9168. if (rows == 0 || !/^\d+$/.test(rows)) {
  9169. alert(self.lang('invalidRows'));
  9170. rowsBox[0].focus();
  9171. return;
  9172. }
  9173. if (cols == 0 || !/^\d+$/.test(cols)) {
  9174. alert(self.lang('invalidRows'));
  9175. colsBox[0].focus();
  9176. return;
  9177. }
  9178. if (!/^\d*$/.test(width)) {
  9179. alert(self.lang('invalidWidth'));
  9180. widthBox[0].focus();
  9181. return;
  9182. }
  9183. if (!/^\d*$/.test(height)) {
  9184. alert(self.lang('invalidHeight'));
  9185. heightBox[0].focus();
  9186. return;
  9187. }
  9188. if (!/^\d*$/.test(padding)) {
  9189. alert(self.lang('invalidPadding'));
  9190. paddingBox[0].focus();
  9191. return;
  9192. }
  9193. if (!/^\d*$/.test(spacing)) {
  9194. alert(self.lang('invalidSpacing'));
  9195. spacingBox[0].focus();
  9196. return;
  9197. }
  9198. if (!/^\d*$/.test(border)) {
  9199. alert(self.lang('invalidBorder'));
  9200. borderBox[0].focus();
  9201. return;
  9202. }
  9203. //modify table
  9204. if (table) {
  9205. if (width !== '') {
  9206. table.width(width + widthType);
  9207. } else {
  9208. table.css('width', '');
  9209. }
  9210. if (table[0].width !== undefined) {
  9211. table.removeAttr('width');
  9212. }
  9213. if (height !== '') {
  9214. table.height(height + heightType);
  9215. } else {
  9216. table.css('height', '');
  9217. }
  9218. if (table[0].height !== undefined) {
  9219. table.removeAttr('height');
  9220. }
  9221. table.css('background-color', bgColor);
  9222. if (table[0].bgColor !== undefined) {
  9223. table.removeAttr('bgColor');
  9224. }
  9225. if (padding !== '') {
  9226. table[0].cellPadding = padding;
  9227. } else {
  9228. table.removeAttr('cellPadding');
  9229. }
  9230. if (spacing !== '') {
  9231. table[0].cellSpacing = spacing;
  9232. } else {
  9233. table.removeAttr('cellSpacing');
  9234. }
  9235. if (align !== '') {
  9236. table[0].align = align;
  9237. } else {
  9238. table.removeAttr('align');
  9239. }
  9240. if (border !== '') {
  9241. table.attr('border', border);
  9242. } else {
  9243. table.removeAttr('border');
  9244. }
  9245. if (border === '' || border === '0') {
  9246. table.addClass(zeroborder);
  9247. } else {
  9248. table.removeClass(zeroborder);
  9249. }
  9250. if (borderColor !== '') {
  9251. table.attr('borderColor', borderColor);
  9252. } else {
  9253. table.removeAttr('borderColor');
  9254. }
  9255. self.hideDialog().focus();
  9256. return;
  9257. }
  9258. //insert new table
  9259. var style = '';
  9260. if (width !== '') {
  9261. style += 'width:' + width + widthType + ';';
  9262. }
  9263. if (height !== '') {
  9264. style += 'height:' + height + heightType + ';';
  9265. }
  9266. if (bgColor !== '') {
  9267. style += 'background-color:' + bgColor + ';';
  9268. }
  9269. var html = '<table';
  9270. if (style !== '') {
  9271. html += ' style="' + style + '"';
  9272. }
  9273. if (padding !== '') {
  9274. html += ' cellpadding="' + padding + '"';
  9275. }
  9276. if (spacing !== '') {
  9277. html += ' cellspacing="' + spacing + '"';
  9278. }
  9279. if (align !== '') {
  9280. html += ' align="' + align + '"';
  9281. }
  9282. if (border !== '') {
  9283. html += ' border="' + border + '"';
  9284. }
  9285. if (border === '' || border === '0') {
  9286. html += ' class="' + zeroborder + '"';
  9287. }
  9288. if (borderColor !== '') {
  9289. html += ' bordercolor="' + borderColor + '"';
  9290. }
  9291. html += '>';
  9292. for (var i = 0; i < rows; i++) {
  9293. html += '<tr>';
  9294. for (var j = 0; j < cols; j++) {
  9295. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9296. }
  9297. html += '</tr>';
  9298. }
  9299. html += '</table>';
  9300. if (!K.IE) {
  9301. html += '<br />';
  9302. }
  9303. self.insertHtml(html);
  9304. self.select().hideDialog().focus();
  9305. self.addBookmark();
  9306. }
  9307. }
  9308. }),
  9309. div = dialog.div,
  9310. rowsBox = K('[name="rows"]', div).val(3),
  9311. colsBox = K('[name="cols"]', div).val(2),
  9312. widthBox = K('[name="width"]', div).val(100),
  9313. heightBox = K('[name="height"]', div),
  9314. widthTypeBox = K('[name="widthType"]', div),
  9315. heightTypeBox = K('[name="heightType"]', div),
  9316. paddingBox = K('[name="padding"]', div).val(2),
  9317. spacingBox = K('[name="spacing"]', div).val(0),
  9318. alignBox = K('[name="align"]', div),
  9319. borderBox = K('[name="border"]', div).val(1),
  9320. colorBox = K('.ke-input-color', div);
  9321. _initColorPicker(div, colorBox.eq(0));
  9322. _initColorPicker(div, colorBox.eq(1));
  9323. _setColor(colorBox.eq(0), '#000000');
  9324. _setColor(colorBox.eq(1), '');
  9325. // foucs and select
  9326. rowsBox[0].focus();
  9327. rowsBox[0].select();
  9328. var table;
  9329. if (isInsert) {
  9330. return;
  9331. }
  9332. //get selected table node
  9333. table = self.plugin.getSelectedTable();
  9334. if (table) {
  9335. rowsBox.val(table[0].rows.length);
  9336. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9337. rowsBox.attr('disabled', true);
  9338. colsBox.attr('disabled', true);
  9339. var match,
  9340. tableWidth = table[0].style.width || table[0].width,
  9341. tableHeight = table[0].style.height || table[0].height;
  9342. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9343. widthBox.val(match[1]);
  9344. widthTypeBox.val(match[2]);
  9345. } else {
  9346. widthBox.val('');
  9347. }
  9348. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9349. heightBox.val(match[1]);
  9350. heightTypeBox.val(match[2]);
  9351. }
  9352. paddingBox.val(table[0].cellPadding || '');
  9353. spacingBox.val(table[0].cellSpacing || '');
  9354. alignBox.val(table[0].align || '');
  9355. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9356. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9357. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9358. widthBox[0].focus();
  9359. widthBox[0].select();
  9360. }
  9361. },
  9362. //modify cell
  9363. cellprop : function() {
  9364. var html = [
  9365. '<div style="padding:20px;">',
  9366. //width, height
  9367. '<div class="ke-dialog-row">',
  9368. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9369. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9370. '<select name="widthType">',
  9371. '<option value="%">' + lang.percent + '</option>',
  9372. '<option value="px">' + lang.px + '</option>',
  9373. '</select> &nbsp; ',
  9374. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9375. '<select name="heightType">',
  9376. '<option value="%">' + lang.percent + '</option>',
  9377. '<option value="px">' + lang.px + '</option>',
  9378. '</select>',
  9379. '</div>',
  9380. //align
  9381. '<div class="ke-dialog-row">',
  9382. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9383. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9384. '<option value="">' + lang.alignDefault + '</option>',
  9385. '<option value="left">' + lang.alignLeft + '</option>',
  9386. '<option value="center">' + lang.alignCenter + '</option>',
  9387. '<option value="right">' + lang.alignRight + '</option>',
  9388. '</select> ',
  9389. lang.verticalAlign + ' <select name="verticalAlign">',
  9390. '<option value="">' + lang.alignDefault + '</option>',
  9391. '<option value="top">' + lang.alignTop + '</option>',
  9392. '<option value="middle">' + lang.alignMiddle + '</option>',
  9393. '<option value="bottom">' + lang.alignBottom + '</option>',
  9394. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9395. '</select>',
  9396. '</div>',
  9397. //border
  9398. '<div class="ke-dialog-row">',
  9399. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9400. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9401. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9402. '</div>',
  9403. //background color
  9404. '<div class="ke-dialog-row">',
  9405. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9406. '<span class="ke-inline-block ke-input-color"></span>',
  9407. '</div>',
  9408. '</div>'
  9409. ].join('');
  9410. var dialog = self.createDialog({
  9411. name : name,
  9412. width : 500,
  9413. title : self.lang('tablecell'),
  9414. body : html,
  9415. beforeRemove : function() {
  9416. colorBox.unbind();
  9417. },
  9418. yesBtn : {
  9419. name : self.lang('yes'),
  9420. click : function(e) {
  9421. var width = widthBox.val(),
  9422. height = heightBox.val(),
  9423. widthType = widthTypeBox.val(),
  9424. heightType = heightTypeBox.val(),
  9425. padding = paddingBox.val(),
  9426. spacing = spacingBox.val(),
  9427. textAlign = textAlignBox.val(),
  9428. verticalAlign = verticalAlignBox.val(),
  9429. border = borderBox.val(),
  9430. borderColor = K(colorBox[0]).html() || '',
  9431. bgColor = K(colorBox[1]).html() || '';
  9432. if (!/^\d*$/.test(width)) {
  9433. alert(self.lang('invalidWidth'));
  9434. widthBox[0].focus();
  9435. return;
  9436. }
  9437. if (!/^\d*$/.test(height)) {
  9438. alert(self.lang('invalidHeight'));
  9439. heightBox[0].focus();
  9440. return;
  9441. }
  9442. if (!/^\d*$/.test(border)) {
  9443. alert(self.lang('invalidBorder'));
  9444. borderBox[0].focus();
  9445. return;
  9446. }
  9447. cell.css({
  9448. width : width !== '' ? (width + widthType) : '',
  9449. height : height !== '' ? (height + heightType) : '',
  9450. 'background-color' : bgColor,
  9451. 'text-align' : textAlign,
  9452. 'vertical-align' : verticalAlign,
  9453. 'border-width' : border,
  9454. 'border-style' : border !== '' ? 'solid' : '',
  9455. 'border-color' : borderColor
  9456. });
  9457. self.hideDialog().focus();
  9458. self.addBookmark();
  9459. }
  9460. }
  9461. }),
  9462. div = dialog.div,
  9463. widthBox = K('[name="width"]', div).val(100),
  9464. heightBox = K('[name="height"]', div),
  9465. widthTypeBox = K('[name="widthType"]', div),
  9466. heightTypeBox = K('[name="heightType"]', div),
  9467. paddingBox = K('[name="padding"]', div).val(2),
  9468. spacingBox = K('[name="spacing"]', div).val(0),
  9469. textAlignBox = K('[name="textAlign"]', div),
  9470. verticalAlignBox = K('[name="verticalAlign"]', div),
  9471. borderBox = K('[name="border"]', div).val(1),
  9472. colorBox = K('.ke-input-color', div);
  9473. _initColorPicker(div, colorBox.eq(0));
  9474. _initColorPicker(div, colorBox.eq(1));
  9475. _setColor(colorBox.eq(0), '#000000');
  9476. _setColor(colorBox.eq(1), '');
  9477. // foucs and select
  9478. widthBox[0].focus();
  9479. widthBox[0].select();
  9480. // get selected cell
  9481. var cell = self.plugin.getSelectedCell();
  9482. var match,
  9483. cellWidth = cell[0].style.width || cell[0].width || '',
  9484. cellHeight = cell[0].style.height || cell[0].height || '';
  9485. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9486. widthBox.val(match[1]);
  9487. widthTypeBox.val(match[2]);
  9488. } else {
  9489. widthBox.val('');
  9490. }
  9491. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9492. heightBox.val(match[1]);
  9493. heightTypeBox.val(match[2]);
  9494. }
  9495. textAlignBox.val(cell[0].style.textAlign || '');
  9496. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9497. var border = cell[0].style.borderWidth || '';
  9498. if (border) {
  9499. border = parseInt(border);
  9500. }
  9501. borderBox.val(border);
  9502. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9503. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9504. widthBox[0].focus();
  9505. widthBox[0].select();
  9506. },
  9507. insert : function() {
  9508. this.prop(true);
  9509. },
  9510. 'delete' : function() {
  9511. var table = self.plugin.getSelectedTable();
  9512. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9513. self.cmd.select();
  9514. table.remove();
  9515. self.addBookmark();
  9516. },
  9517. colinsert : function(offset) {
  9518. var table = self.plugin.getSelectedTable()[0],
  9519. row = self.plugin.getSelectedRow()[0],
  9520. cell = self.plugin.getSelectedCell()[0],
  9521. index = cell.cellIndex + offset;
  9522. // 取得第一行的index
  9523. index += table.rows[0].cells.length - row.cells.length;
  9524. for (var i = 0, len = table.rows.length; i < len; i++) {
  9525. var newRow = table.rows[i],
  9526. newCell = newRow.insertCell(index);
  9527. newCell.innerHTML = K.IE ? '' : '<br />';
  9528. // 调整下一行的单元格index
  9529. index = _getCellIndex(table, newRow, newCell);
  9530. }
  9531. self.cmd.range.selectNodeContents(cell).collapse(true);
  9532. self.cmd.select();
  9533. self.addBookmark();
  9534. },
  9535. colinsertleft : function() {
  9536. this.colinsert(0);
  9537. },
  9538. colinsertright : function() {
  9539. this.colinsert(1);
  9540. },
  9541. rowinsert : function(offset) {
  9542. var table = self.plugin.getSelectedTable()[0],
  9543. row = self.plugin.getSelectedRow()[0],
  9544. cell = self.plugin.getSelectedCell()[0];
  9545. var rowIndex = row.rowIndex;
  9546. if (offset === 1) {
  9547. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9548. }
  9549. var newRow = table.insertRow(rowIndex);
  9550. for (var i = 0, len = row.cells.length; i < len; i++) {
  9551. // 调整cell个数
  9552. if (row.cells[i].rowSpan > 1) {
  9553. len -= row.cells[i].rowSpan - 1;
  9554. }
  9555. var newCell = newRow.insertCell(i);
  9556. // copy colspan
  9557. if (offset === 1 && row.cells[i].colSpan > 1) {
  9558. newCell.colSpan = row.cells[i].colSpan;
  9559. }
  9560. newCell.innerHTML = K.IE ? '' : '<br />';
  9561. }
  9562. // 调整rowspan
  9563. for (var j = rowIndex; j >= 0; j--) {
  9564. var cells = table.rows[j].cells;
  9565. if (cells.length > i) {
  9566. for (var k = cell.cellIndex; k >= 0; k--) {
  9567. if (cells[k].rowSpan > 1) {
  9568. cells[k].rowSpan += 1;
  9569. }
  9570. }
  9571. break;
  9572. }
  9573. }
  9574. self.cmd.range.selectNodeContents(cell).collapse(true);
  9575. self.cmd.select();
  9576. self.addBookmark();
  9577. },
  9578. rowinsertabove : function() {
  9579. this.rowinsert(0);
  9580. },
  9581. rowinsertbelow : function() {
  9582. this.rowinsert(1);
  9583. },
  9584. rowmerge : function() {
  9585. var table = self.plugin.getSelectedTable()[0],
  9586. row = self.plugin.getSelectedRow()[0],
  9587. cell = self.plugin.getSelectedCell()[0],
  9588. rowIndex = row.rowIndex, // 当前行的index
  9589. nextRowIndex = rowIndex + cell.rowSpan, // 下一行的index
  9590. nextRow = table.rows[nextRowIndex]; // 下一行
  9591. // 最后一行不能合并
  9592. if (table.rows.length <= nextRowIndex) {
  9593. return;
  9594. }
  9595. var cellIndex = cell.cellIndex; // 下一行单元格的index
  9596. if (nextRow.cells.length <= cellIndex) {
  9597. return;
  9598. }
  9599. var nextCell = nextRow.cells[cellIndex]; // 下一行单元格
  9600. // 上下行的colspan不一致时不能合并
  9601. if (cell.colSpan !== nextCell.colSpan) {
  9602. return;
  9603. }
  9604. cell.rowSpan += nextCell.rowSpan;
  9605. nextRow.deleteCell(cellIndex);
  9606. self.cmd.range.selectNodeContents(cell).collapse(true);
  9607. self.cmd.select();
  9608. self.addBookmark();
  9609. },
  9610. colmerge : function() {
  9611. var table = self.plugin.getSelectedTable()[0],
  9612. row = self.plugin.getSelectedRow()[0],
  9613. cell = self.plugin.getSelectedCell()[0],
  9614. rowIndex = row.rowIndex, // 当前行的index
  9615. cellIndex = cell.cellIndex,
  9616. nextCellIndex = cellIndex + 1;
  9617. // 最后一列不能合并
  9618. if (row.cells.length <= nextCellIndex) {
  9619. return;
  9620. }
  9621. var nextCell = row.cells[nextCellIndex];
  9622. // 左右列的rowspan不一致时不能合并
  9623. if (cell.rowSpan !== nextCell.rowSpan) {
  9624. return;
  9625. }
  9626. cell.colSpan += nextCell.colSpan;
  9627. row.deleteCell(nextCellIndex);
  9628. self.cmd.range.selectNodeContents(cell).collapse(true);
  9629. self.cmd.select();
  9630. self.addBookmark();
  9631. },
  9632. rowsplit : function() {
  9633. var table = self.plugin.getSelectedTable()[0],
  9634. row = self.plugin.getSelectedRow()[0],
  9635. cell = self.plugin.getSelectedCell()[0],
  9636. rowIndex = row.rowIndex;
  9637. // 不是可分割单元格
  9638. if (cell.rowSpan === 1) {
  9639. return;
  9640. }
  9641. var cellIndex = _getCellIndex(table, row, cell);
  9642. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9643. var newRow = table.rows[rowIndex + i],
  9644. newCell = newRow.insertCell(cellIndex);
  9645. if (cell.colSpan > 1) {
  9646. newCell.colSpan = cell.colSpan;
  9647. }
  9648. newCell.innerHTML = K.IE ? '' : '<br />';
  9649. // 调整下一行的单元格index
  9650. cellIndex = _getCellIndex(table, newRow, newCell);
  9651. }
  9652. K(cell).removeAttr('rowSpan');
  9653. self.cmd.range.selectNodeContents(cell).collapse(true);
  9654. self.cmd.select();
  9655. self.addBookmark();
  9656. },
  9657. colsplit : function() {
  9658. var table = self.plugin.getSelectedTable()[0],
  9659. row = self.plugin.getSelectedRow()[0],
  9660. cell = self.plugin.getSelectedCell()[0],
  9661. cellIndex = cell.cellIndex;
  9662. // 不是可分割单元格
  9663. if (cell.colSpan === 1) {
  9664. return;
  9665. }
  9666. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9667. var newCell = row.insertCell(cellIndex + i);
  9668. if (cell.rowSpan > 1) {
  9669. newCell.rowSpan = cell.rowSpan;
  9670. }
  9671. newCell.innerHTML = K.IE ? '' : '<br />';
  9672. }
  9673. K(cell).removeAttr('colSpan');
  9674. self.cmd.range.selectNodeContents(cell).collapse(true);
  9675. self.cmd.select();
  9676. self.addBookmark();
  9677. },
  9678. coldelete : function() {
  9679. var table = self.plugin.getSelectedTable()[0],
  9680. row = self.plugin.getSelectedRow()[0],
  9681. cell = self.plugin.getSelectedCell()[0],
  9682. index = cell.cellIndex;
  9683. for (var i = 0, len = table.rows.length; i < len; i++) {
  9684. var newRow = table.rows[i],
  9685. newCell = newRow.cells[index];
  9686. if (newCell.colSpan > 1) {
  9687. newCell.colSpan -= 1;
  9688. if (newCell.colSpan === 1) {
  9689. K(newCell).removeAttr('colSpan');
  9690. }
  9691. } else {
  9692. newRow.deleteCell(index);
  9693. }
  9694. // 跳过不需要删除的行
  9695. if (newCell.rowSpan > 1) {
  9696. i += newCell.rowSpan - 1;
  9697. }
  9698. }
  9699. if (row.cells.length === 0) {
  9700. self.cmd.range.setStartBefore(table).collapse(true);
  9701. self.cmd.select();
  9702. K(table).remove();
  9703. } else {
  9704. self.cmd.selection(true);
  9705. }
  9706. self.addBookmark();
  9707. },
  9708. rowdelete : function() {
  9709. var table = self.plugin.getSelectedTable()[0],
  9710. row = self.plugin.getSelectedRow()[0],
  9711. cell = self.plugin.getSelectedCell()[0],
  9712. rowIndex = row.rowIndex;
  9713. // 从下到上删除
  9714. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9715. table.deleteRow(rowIndex + i);
  9716. }
  9717. if (table.rows.length === 0) {
  9718. self.cmd.range.setStartBefore(table).collapse(true);
  9719. self.cmd.select();
  9720. K(table).remove();
  9721. } else {
  9722. self.cmd.selection(true);
  9723. }
  9724. self.addBookmark();
  9725. }
  9726. };
  9727. self.clickToolbar(name, self.plugin.table.prop);
  9728. });
  9729. /*******************************************************************************
  9730. * KindEditor - WYSIWYG HTML Editor for Internet
  9731. * Copyright (C) 2006-2011 kindsoft.net
  9732. *
  9733. * @author Roddy <luolonghao@gmail.com>
  9734. * @site http://www.kindsoft.net/
  9735. * @licence http://www.kindsoft.net/license.php
  9736. *******************************************************************************/
  9737. KindEditor.plugin('template', function(K) {
  9738. var self = this, name = 'template', lang = self.lang(name + '.'),
  9739. htmlPath = self.pluginsPath + name + '/html/';
  9740. function getFilePath(fileName) {
  9741. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9742. }
  9743. self.clickToolbar(name, function() {
  9744. var lang = self.lang(name + '.'),
  9745. arr = ['<div style="padding:10px 20px;">',
  9746. '<div class="ke-header">',
  9747. // left start
  9748. '<div class="ke-left">',
  9749. lang. selectTemplate + ' <select>'];
  9750. K.each(lang.fileList, function(key, val) {
  9751. arr.push('<option value="' + key + '">' + val + '</option>');
  9752. });
  9753. html = [arr.join(''),
  9754. '</select></div>',
  9755. // right start
  9756. '<div class="ke-right">',
  9757. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9758. '</div>',
  9759. '<div class="ke-clearfix"></div>',
  9760. '</div>',
  9761. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9762. '</div>'].join('');
  9763. var dialog = self.createDialog({
  9764. name : name,
  9765. width : 500,
  9766. title : self.lang(name),
  9767. body : html,
  9768. yesBtn : {
  9769. name : self.lang('yes'),
  9770. click : function(e) {
  9771. var doc = K.iframeDoc(iframe);
  9772. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9773. }
  9774. }
  9775. });
  9776. var selectBox = K('select', dialog.div),
  9777. checkbox = K('[name="replaceFlag"]', dialog.div),
  9778. iframe = K('iframe', dialog.div);
  9779. checkbox[0].checked = true;
  9780. iframe.attr('src', getFilePath(selectBox.val()));
  9781. selectBox.change(function() {
  9782. iframe.attr('src', getFilePath(this.value));
  9783. });
  9784. });
  9785. });
  9786. /*******************************************************************************
  9787. * KindEditor - WYSIWYG HTML Editor for Internet
  9788. * Copyright (C) 2006-2011 kindsoft.net
  9789. *
  9790. * @author Roddy <luolonghao@gmail.com>
  9791. * @site http://www.kindsoft.net/
  9792. * @licence http://www.kindsoft.net/license.php
  9793. *******************************************************************************/
  9794. KindEditor.plugin('wordpaste', function(K) {
  9795. var self = this, name = 'wordpaste';
  9796. self.clickToolbar(name, function() {
  9797. var lang = self.lang(name + '.'),
  9798. html = '<div style="padding:10px 20px;">' +
  9799. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9800. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9801. '</div>',
  9802. dialog = self.createDialog({
  9803. name : name,
  9804. width : 450,
  9805. title : self.lang(name),
  9806. body : html,
  9807. yesBtn : {
  9808. name : self.lang('yes'),
  9809. click : function(e) {
  9810. var str = doc.body.innerHTML;
  9811. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9812. self.insertHtml(str).hideDialog().focus();
  9813. }
  9814. }
  9815. }),
  9816. div = dialog.div,
  9817. iframe = K('iframe', div),
  9818. doc = K.iframeDoc(iframe);
  9819. if (!K.IE) {
  9820. doc.designMode = 'on';
  9821. }
  9822. doc.open();
  9823. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9824. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9825. if (!K.IE) {
  9826. doc.write('<br />');
  9827. }
  9828. doc.write('</body></html>');
  9829. doc.close();
  9830. if (K.IE) {
  9831. doc.body.contentEditable = 'true';
  9832. }
  9833. iframe[0].contentWindow.focus();
  9834. });
  9835. });