kindeditor-all-min.js 296 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2017 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.12 (2017-04-12)
  9. *******************************************************************************/
  10. (function (window, undefined) {
  11. if (window.KindEditor) {
  12. return;
  13. }
  14. if (!window.console) {
  15. window.console = {};
  16. }
  17. if (!console.log) {
  18. console.log = function () {};
  19. }
  20. var _VERSION = '4.1.12 (2017-04-12)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  24. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  25. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  26. _OPERA = _ua.indexOf('opera') > -1,
  27. _MOBILE = _ua.indexOf('mobile') > -1,
  28. _IOS = /ipad|iphone|ipod/.test(_ua),
  29. _QUIRKS = document.compatMode != 'CSS1Compat',
  30. _IERANGE = !window.getSelection,
  31. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  32. _V = _matches ? _matches[1] : '0',
  33. _TIME = new Date().getTime();
  34. function _isArray(val) {
  35. if (!val) {
  36. return false;
  37. }
  38. return Object.prototype.toString.call(val) === '[object Array]';
  39. }
  40. function _isFunction(val) {
  41. if (!val) {
  42. return false;
  43. }
  44. return Object.prototype.toString.call(val) === '[object Function]';
  45. }
  46. function _inArray(val, arr) {
  47. for (var i = 0, len = arr.length; i < len; i++) {
  48. if (val === arr[i]) {
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. function _each(obj, fn) {
  55. if (_isArray(obj)) {
  56. for (var i = 0, len = obj.length; i < len; i++) {
  57. if (fn.call(obj[i], i, obj[i]) === false) {
  58. break;
  59. }
  60. }
  61. } else {
  62. for (var key in obj) {
  63. if (obj.hasOwnProperty(key)) {
  64. if (fn.call(obj[key], key, obj[key]) === false) {
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. function _trim(str) {
  72. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  73. }
  74. function _inString(val, str, delimiter) {
  75. delimiter = delimiter === undefined ? ',' : delimiter;
  76. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  77. }
  78. function _addUnit(val, unit) {
  79. unit = unit || 'px';
  80. return val && /^-?\d+(?:\.\d+)?$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function(key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function(key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () {};
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function(key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG : false,
  180. VERSION : _VERSION,
  181. IE : _IE,
  182. GECKO : _GECKO,
  183. WEBKIT : _WEBKIT,
  184. OPERA : _OPERA,
  185. V : _V,
  186. TIME : _TIME,
  187. each : _each,
  188. isArray : _isArray,
  189. isFunction : _isFunction,
  190. inArray : _inArray,
  191. inString : _inString,
  192. trim : _trim,
  193. addUnit : _addUnit,
  194. removeUnit : _removeUnit,
  195. escape : _escape,
  196. unescape : _unescape,
  197. toCamel : _toCamel,
  198. toHex : _toHex,
  199. toMap : _toMap,
  200. toArray : _toArray,
  201. undef : _undef,
  202. invalidUrl : _invalidUrl,
  203. addParam : _addParam,
  204. extend : _extend,
  205. json : _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. index : 0,
  230. designMode : true,
  231. fullscreenMode : false,
  232. filterMode : true,
  233. wellFormatMode : true,
  234. shadowMode : true,
  235. loadStyleMode : true,
  236. basePath : K.basePath,
  237. themesPath : K.basePath + 'themes/',
  238. langPath : K.basePath + 'lang/',
  239. pluginsPath : K.basePath + 'plugins/',
  240. themeType : 'default',
  241. langType : 'zh-CN',
  242. urlType : '',
  243. newlineTag : 'p',
  244. resizeType : 2,
  245. syncType : 'form',
  246. pasteType : 2,
  247. dialogAlignType : 'page',
  248. useContextmenu : true,
  249. fullscreenShortcut : false,
  250. bodyClass : 'ke-content',
  251. indentChar : '\t',
  252. cssPath : '',
  253. cssData : '',
  254. minWidth : 650,
  255. minHeight : 100,
  256. minChangeSize : 50,
  257. zIndex : 811213,
  258. items : [
  259. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  260. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  261. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  262. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  263. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  264. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  265. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  266. 'anchor', 'link', 'unlink', '|', 'about'
  267. ],
  268. noDisableItems : ['source', 'fullscreen'],
  269. colorTable : [
  270. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  271. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  272. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  273. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  274. ],
  275. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  276. htmlTags : {
  277. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  278. span : [
  279. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  280. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  281. ],
  282. div : [
  283. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  284. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  285. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  286. ],
  287. table: [
  288. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  289. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  290. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  291. '.width', '.height', '.border-collapse'
  292. ],
  293. 'td,th': [
  294. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  295. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  296. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  297. ],
  298. a : ['id', 'class', 'href', 'target', 'name'],
  299. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  300. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  301. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  302. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  303. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  304. ],
  305. pre : ['id', 'class'],
  306. hr : ['id', 'class', '.page-break-after'],
  307. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  308. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  309. },
  310. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  311. };
  312. var _useCapture = false;
  313. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  314. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  315. var _CHANGE_KEY_MAP = {};
  316. _each(_INPUT_KEY_MAP, function(key, val) {
  317. _CHANGE_KEY_MAP[key] = val;
  318. });
  319. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  320. _CHANGE_KEY_MAP[key] = val;
  321. });
  322. function _bindEvent(el, type, fn) {
  323. if (el.addEventListener){
  324. el.addEventListener(type, fn, _useCapture);
  325. } else if (el.attachEvent){
  326. el.attachEvent('on' + type, fn);
  327. }
  328. }
  329. function _unbindEvent(el, type, fn) {
  330. if (el.removeEventListener){
  331. el.removeEventListener(type, fn, _useCapture);
  332. } else if (el.detachEvent){
  333. el.detachEvent('on' + type, fn);
  334. }
  335. }
  336. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  337. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  338. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  339. function KEvent(el, event) {
  340. this.init(el, event);
  341. }
  342. _extend(KEvent, {
  343. init : function(el, event) {
  344. var self = this, doc = el.ownerDocument || el.document || el;
  345. self.event = event;
  346. _each(_EVENT_PROPS, function(key, val) {
  347. self[val] = event[val];
  348. });
  349. if (!self.target) {
  350. self.target = self.srcElement || doc;
  351. }
  352. if (self.target.nodeType === 3) {
  353. self.target = self.target.parentNode;
  354. }
  355. if (!self.relatedTarget && self.fromElement) {
  356. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  357. }
  358. if (self.pageX == null && self.clientX != null) {
  359. var d = doc.documentElement, body = doc.body;
  360. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  361. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  362. }
  363. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  364. self.which = self.charCode || self.keyCode;
  365. }
  366. if (!self.metaKey && self.ctrlKey) {
  367. self.metaKey = self.ctrlKey;
  368. }
  369. if (!self.which && self.button !== undefined) {
  370. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  371. }
  372. switch (self.which) {
  373. case 186 :
  374. self.which = 59;
  375. break;
  376. case 187 :
  377. case 107 :
  378. case 43 :
  379. self.which = 61;
  380. break;
  381. case 189 :
  382. case 45 :
  383. self.which = 109;
  384. break;
  385. case 42 :
  386. self.which = 106;
  387. break;
  388. case 47 :
  389. self.which = 111;
  390. break;
  391. case 78 :
  392. self.which = 110;
  393. break;
  394. }
  395. if (self.which >= 96 && self.which <= 105) {
  396. self.which -= 48;
  397. }
  398. },
  399. preventDefault : function() {
  400. var ev = this.event;
  401. if (ev.preventDefault) {
  402. ev.preventDefault();
  403. } else {
  404. ev.returnValue = false;
  405. }
  406. },
  407. stopPropagation : function() {
  408. var ev = this.event;
  409. if (ev.stopPropagation) {
  410. ev.stopPropagation();
  411. } else {
  412. ev.cancelBubble = true;
  413. }
  414. },
  415. stop : function() {
  416. this.preventDefault();
  417. this.stopPropagation();
  418. }
  419. });
  420. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  421. function _getId(el) {
  422. return el[_eventExpendo] || null;
  423. }
  424. function _setId(el) {
  425. el[_eventExpendo] = ++_eventId;
  426. return _eventId;
  427. }
  428. function _removeId(el) {
  429. try {
  430. delete el[_eventExpendo];
  431. } catch(e) {
  432. if (el.removeAttribute) {
  433. el.removeAttribute(_eventExpendo);
  434. }
  435. }
  436. }
  437. function _bind(el, type, fn) {
  438. if (type.indexOf(',') >= 0) {
  439. _each(type.split(','), function() {
  440. _bind(el, this, fn);
  441. });
  442. return;
  443. }
  444. var id = _getId(el);
  445. if (!id) {
  446. id = _setId(el);
  447. }
  448. if (_eventData[id] === undefined) {
  449. _eventData[id] = {};
  450. }
  451. var events = _eventData[id][type];
  452. if (events && events.length > 0) {
  453. _unbindEvent(el, type, events[0]);
  454. } else {
  455. _eventData[id][type] = [];
  456. _eventData[id].el = el;
  457. }
  458. events = _eventData[id][type];
  459. if (events.length === 0) {
  460. events[0] = function(e) {
  461. var kevent = e ? new KEvent(el, e) : undefined;
  462. _each(events, function(i, event) {
  463. if (i > 0 && event) {
  464. event.call(el, kevent);
  465. }
  466. });
  467. };
  468. }
  469. if (_inArray(fn, events) < 0) {
  470. events.push(fn);
  471. }
  472. _bindEvent(el, type, events[0]);
  473. }
  474. function _unbind(el, type, fn) {
  475. if (type && type.indexOf(',') >= 0) {
  476. _each(type.split(','), function() {
  477. _unbind(el, this, fn);
  478. });
  479. return;
  480. }
  481. var id = _getId(el);
  482. if (!id) {
  483. return;
  484. }
  485. if (type === undefined) {
  486. if (id in _eventData) {
  487. _each(_eventData[id], function(key, events) {
  488. if (key != 'el' && events.length > 0) {
  489. _unbindEvent(el, key, events[0]);
  490. }
  491. });
  492. delete _eventData[id];
  493. _removeId(el);
  494. }
  495. return;
  496. }
  497. if (!_eventData[id]) {
  498. return;
  499. }
  500. var events = _eventData[id][type];
  501. if (events && events.length > 0) {
  502. if (fn === undefined) {
  503. _unbindEvent(el, type, events[0]);
  504. delete _eventData[id][type];
  505. } else {
  506. _each(events, function(i, event) {
  507. if (i > 0 && event === fn) {
  508. events.splice(i, 1);
  509. }
  510. });
  511. if (events.length == 1) {
  512. _unbindEvent(el, type, events[0]);
  513. delete _eventData[id][type];
  514. }
  515. }
  516. var count = 0;
  517. _each(_eventData[id], function() {
  518. count++;
  519. });
  520. if (count < 2) {
  521. delete _eventData[id];
  522. _removeId(el);
  523. }
  524. }
  525. }
  526. function _fire(el, type) {
  527. if (type.indexOf(',') >= 0) {
  528. _each(type.split(','), function() {
  529. _fire(el, this);
  530. });
  531. return;
  532. }
  533. var id = _getId(el);
  534. if (!id) {
  535. return;
  536. }
  537. var events = _eventData[id][type];
  538. if (_eventData[id] && events && events.length > 0) {
  539. events[0]();
  540. }
  541. }
  542. function _ctrl(el, key, fn) {
  543. var self = this;
  544. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  545. _bind(el, 'keydown', function(e) {
  546. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  547. fn.call(el);
  548. e.stop();
  549. }
  550. });
  551. }
  552. var _readyFinished = false;
  553. function _ready(fn) {
  554. if (_readyFinished) {
  555. fn(KindEditor);
  556. return;
  557. }
  558. var loaded = false;
  559. function readyFunc() {
  560. if (!loaded) {
  561. loaded = true;
  562. fn(KindEditor);
  563. _readyFinished = true;
  564. }
  565. }
  566. function ieReadyFunc() {
  567. if (!loaded) {
  568. try {
  569. document.documentElement.doScroll('left');
  570. } catch(e) {
  571. setTimeout(ieReadyFunc, 100);
  572. return;
  573. }
  574. readyFunc();
  575. }
  576. }
  577. function ieReadyStateFunc() {
  578. if (document.readyState === 'complete') {
  579. readyFunc();
  580. }
  581. }
  582. if (document.addEventListener) {
  583. _bind(document, 'DOMContentLoaded', readyFunc);
  584. } else if (document.attachEvent) {
  585. _bind(document, 'readystatechange', ieReadyStateFunc);
  586. var toplevel = false;
  587. try {
  588. toplevel = window.frameElement == null;
  589. } catch(e) {}
  590. if (document.documentElement.doScroll && toplevel) {
  591. ieReadyFunc();
  592. }
  593. }
  594. _bind(window, 'load', readyFunc);
  595. }
  596. if (window.attachEvent) {
  597. window.attachEvent('onunload', function() {
  598. _each(_eventData, function(key, events) {
  599. if (events.el) {
  600. _unbind(events.el);
  601. }
  602. });
  603. });
  604. }
  605. K.ctrl = _ctrl;
  606. K.ready = _ready;
  607. function _getCssList(css) {
  608. css = css.replace(/&quot;/g, '"');
  609. var list = {},
  610. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  611. match;
  612. while ((match = reg.exec(css))) {
  613. var key = _trim(match[1].toLowerCase()),
  614. val = _trim(_toHex(match[2]));
  615. list[key] = val;
  616. }
  617. return list;
  618. }
  619. function _getAttrList(tag) {
  620. var list = {},
  621. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  622. match;
  623. while ((match = reg.exec(tag))) {
  624. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  625. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  626. list[key] = val;
  627. }
  628. return list;
  629. }
  630. function _addClassToTag(tag, className) {
  631. if (/\s+class\s*=/.test(tag)) {
  632. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  633. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  634. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  635. } else {
  636. return $0;
  637. }
  638. });
  639. } else {
  640. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  641. }
  642. return tag;
  643. }
  644. function _formatCss(css) {
  645. var str = '';
  646. _each(_getCssList(css), function(key, val) {
  647. str += key + ':' + val + ';';
  648. });
  649. return str;
  650. }
  651. function _formatUrl(url, mode, host, pathname) {
  652. return url;
  653. mode = _undef(mode, '').toLowerCase();
  654. if (url.substr(0, 5) != 'data:') {
  655. url = url.replace(/([^:])\/\//g, '$1/');
  656. }
  657. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  658. return url;
  659. }
  660. host = host || location.protocol + '//' + location.host;
  661. if (pathname === undefined) {
  662. var m = location.pathname.match(/^(\/.*)\//);
  663. pathname = m ? m[1] : '';
  664. }
  665. var match;
  666. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  667. if (match[1] !== host) {
  668. return url;
  669. }
  670. } else if (/^\w+:/.test(url)) {
  671. return url;
  672. }
  673. function getRealPath(path) {
  674. var parts = path.split('/'), paths = [];
  675. for (var i = 0, len = parts.length; i < len; i++) {
  676. var part = parts[i];
  677. if (part == '..') {
  678. if (paths.length > 0) {
  679. paths.pop();
  680. }
  681. } else if (part !== '' && part != '.') {
  682. paths.push(part);
  683. }
  684. }
  685. return '/' + paths.join('/');
  686. }
  687. if (/^\//.test(url)) {
  688. url = host + getRealPath(url.substr(1));
  689. } else if (!/^\w+:\/\//.test(url)) {
  690. url = host + getRealPath(pathname + '/' + url);
  691. }
  692. function getRelativePath(path, depth) {
  693. if (url.substr(0, path.length) === path) {
  694. var arr = [];
  695. for (var i = 0; i < depth; i++) {
  696. arr.push('..');
  697. }
  698. var prefix = '.';
  699. if (arr.length > 0) {
  700. prefix += '/' + arr.join('/');
  701. }
  702. if (pathname == '/') {
  703. prefix += '/';
  704. }
  705. return prefix + url.substr(path.length);
  706. } else {
  707. if ((match = /^(.*)\//.exec(path))) {
  708. return getRelativePath(match[1], ++depth);
  709. }
  710. }
  711. }
  712. if (mode === 'relative') {
  713. url = getRelativePath(host + pathname, 0).substr(2);
  714. } else if (mode === 'absolute') {
  715. if (url.substr(0, host.length) === host) {
  716. url = url.substr(host.length);
  717. }
  718. }
  719. return url;
  720. }
  721. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  722. if (html == null) {
  723. html = '';
  724. }
  725. urlType = urlType || '';
  726. wellFormatted = _undef(wellFormatted, false);
  727. indentChar = _undef(indentChar, '\t');
  728. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  729. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  730. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  731. });
  732. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  733. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  734. html = html.replace(/\u200B/g, '');
  735. html = html.replace(/\u00A9/g, '&copy;');
  736. html = html.replace(/\u00AE/g, '&reg;');
  737. html = html.replace(/\u2003/g, '&emsp;');
  738. html = html.replace(/\u3000/g, '&emsp;');
  739. html = html.replace(/&quot;/g, '');
  740. html = html.replace(/<[^>]+/g, function($0) {
  741. return $0.replace(/\s+/g, ' ');
  742. });
  743. var htmlTagMap = {};
  744. if (htmlTags) {
  745. _each(htmlTags, function(key, val) {
  746. var arr = key.split(',');
  747. for (var i = 0, len = arr.length; i < len; i++) {
  748. htmlTagMap[arr[i]] = _toMap(val);
  749. }
  750. });
  751. if (!htmlTagMap.script) {
  752. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  753. }
  754. if (!htmlTagMap.style) {
  755. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  756. }
  757. }
  758. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  759. var tagStack = [];
  760. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  761. var full = $0,
  762. startNewline = $1 || '',
  763. startSlash = $2 || '',
  764. tagName = $3.toLowerCase(),
  765. attr = $4 || '',
  766. endSlash = $5 ? ' ' + $5 : '',
  767. endNewline = $6 || '';
  768. if (htmlTags && !htmlTagMap[tagName]) {
  769. return '';
  770. }
  771. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  772. endSlash = ' /';
  773. }
  774. if (_INLINE_TAG_MAP[tagName]) {
  775. if (startNewline) {
  776. startNewline = ' ';
  777. }
  778. if (endNewline) {
  779. endNewline = ' ';
  780. }
  781. }
  782. if (_PRE_TAG_MAP[tagName]) {
  783. if (startSlash) {
  784. endNewline = '\n';
  785. } else {
  786. startNewline = '\n';
  787. }
  788. }
  789. if (wellFormatted && tagName == 'br') {
  790. endNewline = '\n';
  791. }
  792. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  793. if (wellFormatted) {
  794. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  795. tagStack.pop();
  796. } else {
  797. tagStack.push(tagName);
  798. }
  799. startNewline = '\n';
  800. endNewline = '\n';
  801. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  802. startNewline += indentChar;
  803. if (!startSlash) {
  804. endNewline += indentChar;
  805. }
  806. }
  807. if (endSlash) {
  808. tagStack.pop();
  809. } else if (!startSlash) {
  810. endNewline += indentChar;
  811. }
  812. } else {
  813. startNewline = endNewline = '';
  814. }
  815. }
  816. if (attr !== '') {
  817. var attrMap = _getAttrList(full);
  818. if (tagName === 'font') {
  819. var fontStyleMap = {}, fontStyle = '';
  820. _each(attrMap, function(key, val) {
  821. if (key === 'color') {
  822. fontStyleMap.color = val;
  823. delete attrMap[key];
  824. }
  825. if (key === 'size') {
  826. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  827. delete attrMap[key];
  828. }
  829. if (key === 'face') {
  830. fontStyleMap['font-family'] = val;
  831. delete attrMap[key];
  832. }
  833. if (key === 'style') {
  834. fontStyle = val;
  835. }
  836. });
  837. if (fontStyle && !/;$/.test(fontStyle)) {
  838. fontStyle += ';';
  839. }
  840. _each(fontStyleMap, function(key, val) {
  841. if (val === '') {
  842. return;
  843. }
  844. if (/\s/.test(val)) {
  845. val = "'" + val + "'";
  846. }
  847. fontStyle += key + ':' + val + ';';
  848. });
  849. attrMap.style = fontStyle;
  850. }
  851. _each(attrMap, function(key, val) {
  852. if (_FILL_ATTR_MAP[key]) {
  853. attrMap[key] = key;
  854. }
  855. if (_inArray(key, ['src', 'href']) >= 0) {
  856. attrMap[key] = _formatUrl(val, urlType);
  857. }
  858. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  859. tagName === 'body' && key === 'contenteditable' ||
  860. /^kindeditor_\d+$/.test(key)) {
  861. delete attrMap[key];
  862. }
  863. if (key === 'style' && val !== '') {
  864. var styleMap = _getCssList(val);
  865. _each(styleMap, function(k, v) {
  866. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  867. delete styleMap[k];
  868. }
  869. });
  870. var style = '';
  871. _each(styleMap, function(k, v) {
  872. style += k + ':' + v + ';';
  873. });
  874. attrMap.style = style;
  875. }
  876. });
  877. attr = '';
  878. _each(attrMap, function(key, val) {
  879. if (key === 'style' && val === '') {
  880. return;
  881. }
  882. val = val.replace(/"/g, '&quot;');
  883. attr += ' ' + key + '="' + val + '"';
  884. });
  885. }
  886. if (tagName === 'font') {
  887. tagName = 'span';
  888. }
  889. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  890. });
  891. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  892. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  893. });
  894. html = html.replace(/\n\s*\n/g, '\n');
  895. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  896. return _trim(html);
  897. }
  898. function _clearMsWord(html, htmlTags) {
  899. html = html.replace(/<meta[\s\S]*?>/ig, '')
  900. .replace(/<![\s\S]*?>/ig, '')
  901. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  902. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  903. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  904. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  905. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  906. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  907. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  908. });
  909. return _formatHtml(html, htmlTags);
  910. }
  911. function _mediaType(src) {
  912. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  913. return 'audio/x-pn-realaudio-plugin';
  914. }
  915. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  916. return 'application/x-shockwave-flash';
  917. }
  918. return 'video/x-ms-asf-plugin';
  919. }
  920. function _mediaClass(type) {
  921. if (/realaudio/i.test(type)) {
  922. return 'ke-rm';
  923. }
  924. if (/flash/i.test(type)) {
  925. return 'ke-flash';
  926. }
  927. return 'ke-media';
  928. }
  929. function _mediaAttrs(srcTag) {
  930. return _getAttrList(unescape(srcTag));
  931. }
  932. function _mediaEmbed(attrs) {
  933. var html = '<embed ';
  934. _each(attrs, function(key, val) {
  935. html += key + '="' + val + '" ';
  936. });
  937. html += '/>';
  938. return html;
  939. }
  940. function _mediaImg(blankPath, attrs) {
  941. var width = attrs.width,
  942. height = attrs.height,
  943. type = attrs.type || _mediaType(attrs.src),
  944. srcTag = _mediaEmbed(attrs),
  945. style = '';
  946. if (/\D/.test(width)) {
  947. style += 'width:' + width + ';';
  948. } else if (width > 0) {
  949. style += 'width:' + width + 'px;';
  950. }
  951. if (/\D/.test(height)) {
  952. style += 'height:' + height + ';';
  953. } else if (height > 0) {
  954. style += 'height:' + height + 'px;';
  955. }
  956. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  957. if (style !== '') {
  958. html += 'style="' + style + '" ';
  959. }
  960. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  961. return html;
  962. }
  963. function _tmpl(str, data) {
  964. var fn = new Function("obj",
  965. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  966. "with(obj){p.push('" +
  967. str.replace(/[\r\t\n]/g, " ")
  968. .split("<%").join("\t")
  969. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  970. .replace(/\t=(.*?)%>/g, "',$1,'")
  971. .split("\t").join("');")
  972. .split("%>").join("p.push('")
  973. .split("\r").join("\\'") + "');}return p.join('');");
  974. return data ? fn(data) : fn;
  975. }
  976. K.formatUrl = _formatUrl;
  977. K.formatHtml = _formatHtml;
  978. K.getCssList = _getCssList;
  979. K.getAttrList = _getAttrList;
  980. K.mediaType = _mediaType;
  981. K.mediaAttrs = _mediaAttrs;
  982. K.mediaEmbed = _mediaEmbed;
  983. K.mediaImg = _mediaImg;
  984. K.clearMsWord = _clearMsWord;
  985. K.tmpl = _tmpl;
  986. function _contains(nodeA, nodeB) {
  987. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  988. return true;
  989. }
  990. while ((nodeB = nodeB.parentNode)) {
  991. if (nodeB == nodeA) {
  992. return true;
  993. }
  994. }
  995. return false;
  996. }
  997. var _getSetAttrDiv = document.createElement('div');
  998. _getSetAttrDiv.setAttribute('className', 't');
  999. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1000. function _getAttr(el, key) {
  1001. key = key.toLowerCase();
  1002. var val = null;
  1003. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1004. var div = el.ownerDocument.createElement('div');
  1005. div.appendChild(el.cloneNode(false));
  1006. var list = _getAttrList(_unescape(div.innerHTML));
  1007. if (key in list) {
  1008. val = list[key];
  1009. }
  1010. } else {
  1011. try {
  1012. val = el.getAttribute(key, 2);
  1013. } catch(e) {
  1014. val = el.getAttribute(key, 1);
  1015. }
  1016. }
  1017. if (key === 'style' && val !== null) {
  1018. val = _formatCss(val);
  1019. }
  1020. return val;
  1021. }
  1022. function _queryAll(expr, root) {
  1023. var exprList = expr.split(',');
  1024. if (exprList.length > 1) {
  1025. var mergedResults = [];
  1026. _each(exprList, function() {
  1027. _each(_queryAll(this, root), function() {
  1028. if (_inArray(this, mergedResults) < 0) {
  1029. mergedResults.push(this);
  1030. }
  1031. });
  1032. });
  1033. return mergedResults;
  1034. }
  1035. root = root || document;
  1036. function escape(str) {
  1037. if (typeof str != 'string') {
  1038. return str;
  1039. }
  1040. return str.replace(/([^\w\-])/g, '\\$1');
  1041. }
  1042. function stripslashes(str) {
  1043. return str.replace(/\\/g, '');
  1044. }
  1045. function cmpTag(tagA, tagB) {
  1046. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1047. }
  1048. function byId(id, tag, root) {
  1049. var arr = [],
  1050. doc = root.ownerDocument || root,
  1051. el = doc.getElementById(stripslashes(id));
  1052. if (el) {
  1053. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1054. arr.push(el);
  1055. }
  1056. }
  1057. return arr;
  1058. }
  1059. function byClass(className, tag, root) {
  1060. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1061. if (root.getElementsByClassName) {
  1062. els = root.getElementsByClassName(stripslashes(className));
  1063. for (i = 0, len = els.length; i < len; i++) {
  1064. el = els[i];
  1065. if (cmpTag(tag, el.nodeName)) {
  1066. arr.push(el);
  1067. }
  1068. }
  1069. } else if (doc.querySelectorAll) {
  1070. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1071. for (i = 0, len = els.length; i < len; i++) {
  1072. el = els[i];
  1073. if (_contains(root, el)) {
  1074. arr.push(el);
  1075. }
  1076. }
  1077. } else {
  1078. els = root.getElementsByTagName(tag);
  1079. className = ' ' + className + ' ';
  1080. for (i = 0, len = els.length; i < len; i++) {
  1081. el = els[i];
  1082. if (el.nodeType == 1) {
  1083. var cls = el.className;
  1084. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1085. arr.push(el);
  1086. }
  1087. }
  1088. }
  1089. }
  1090. return arr;
  1091. }
  1092. function byName(name, tag, root) {
  1093. var arr = [], doc = root.ownerDocument || root,
  1094. els = doc.getElementsByName(stripslashes(name)), el;
  1095. for (var i = 0, len = els.length; i < len; i++) {
  1096. el = els[i];
  1097. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1098. if (el.getAttribute('name') !== null) {
  1099. arr.push(el);
  1100. }
  1101. }
  1102. }
  1103. return arr;
  1104. }
  1105. function byAttr(key, val, tag, root) {
  1106. var arr = [], els = root.getElementsByTagName(tag), el;
  1107. for (var i = 0, len = els.length; i < len; i++) {
  1108. el = els[i];
  1109. if (el.nodeType == 1) {
  1110. if (val === null) {
  1111. if (_getAttr(el, key) !== null) {
  1112. arr.push(el);
  1113. }
  1114. } else {
  1115. if (val === escape(_getAttr(el, key))) {
  1116. arr.push(el);
  1117. }
  1118. }
  1119. }
  1120. }
  1121. return arr;
  1122. }
  1123. function select(expr, root) {
  1124. var arr = [], matches;
  1125. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1126. var tag = matches ? matches[1] : '*';
  1127. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1128. arr = byId(matches[1], tag, root);
  1129. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1130. arr = byClass(matches[1], tag, root);
  1131. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1132. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1133. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1134. var key = matches[1].toLowerCase(), val = matches[2];
  1135. if (key === 'id') {
  1136. arr = byId(val, tag, root);
  1137. } else if (key === 'class') {
  1138. arr = byClass(val, tag, root);
  1139. } else if (key === 'name') {
  1140. arr = byName(val, tag, root);
  1141. } else {
  1142. arr = byAttr(key, val, tag, root);
  1143. }
  1144. } else {
  1145. var els = root.getElementsByTagName(tag), el;
  1146. for (var i = 0, len = els.length; i < len; i++) {
  1147. el = els[i];
  1148. if (el.nodeType == 1) {
  1149. arr.push(el);
  1150. }
  1151. }
  1152. }
  1153. return arr;
  1154. }
  1155. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1156. while ((arr = re.exec(expr))) {
  1157. if (arr[1] !== ' ') {
  1158. parts.push(arr[1]);
  1159. }
  1160. }
  1161. var results = [];
  1162. if (parts.length == 1) {
  1163. return select(parts[0], root);
  1164. }
  1165. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1166. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1167. part = parts[i];
  1168. if (part === '>') {
  1169. isChild = true;
  1170. continue;
  1171. }
  1172. if (i > 0) {
  1173. els = [];
  1174. for (j = 0, len = results.length; j < len; j++) {
  1175. val = results[j];
  1176. subResults = select(part, val);
  1177. for (k = 0, l = subResults.length; k < l; k++) {
  1178. v = subResults[k];
  1179. if (isChild) {
  1180. if (val === v.parentNode) {
  1181. els.push(v);
  1182. }
  1183. } else {
  1184. els.push(v);
  1185. }
  1186. }
  1187. }
  1188. results = els;
  1189. } else {
  1190. results = select(part, root);
  1191. }
  1192. if (results.length === 0) {
  1193. return [];
  1194. }
  1195. }
  1196. return results;
  1197. }
  1198. function _query(expr, root) {
  1199. var arr = _queryAll(expr, root);
  1200. return arr.length > 0 ? arr[0] : null;
  1201. }
  1202. K.query = _query;
  1203. K.queryAll = _queryAll;
  1204. function _get(val) {
  1205. return K(val)[0];
  1206. }
  1207. function _getDoc(node) {
  1208. if (!node) {
  1209. return document;
  1210. }
  1211. return node.ownerDocument || node.document || node;
  1212. }
  1213. function _getWin(node) {
  1214. if (!node) {
  1215. return window;
  1216. }
  1217. var doc = _getDoc(node);
  1218. return doc.parentWindow || doc.defaultView;
  1219. }
  1220. function _setHtml(el, html) {
  1221. if (el.nodeType != 1) {
  1222. return;
  1223. }
  1224. var doc = _getDoc(el);
  1225. try {
  1226. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1227. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1228. temp.parentNode.removeChild(temp);
  1229. } catch(e) {
  1230. K(el).empty();
  1231. K('@' + html, doc).each(function() {
  1232. el.appendChild(this);
  1233. });
  1234. }
  1235. }
  1236. function _hasClass(el, cls) {
  1237. return _inString(cls, el.className, ' ');
  1238. }
  1239. function _setAttr(el, key, val) {
  1240. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1241. key = 'className';
  1242. }
  1243. el.setAttribute(key, '' + val);
  1244. }
  1245. function _removeAttr(el, key) {
  1246. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1247. key = 'className';
  1248. }
  1249. _setAttr(el, key, '');
  1250. el.removeAttribute(key);
  1251. }
  1252. function _getNodeName(node) {
  1253. if (!node || !node.nodeName) {
  1254. return '';
  1255. }
  1256. return node.nodeName.toLowerCase();
  1257. }
  1258. function _computedCss(el, key) {
  1259. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1260. if (win.getComputedStyle) {
  1261. var style = win.getComputedStyle(el, null);
  1262. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1263. } else if (el.currentStyle) {
  1264. val = el.currentStyle[camelKey] || el.style[camelKey];
  1265. }
  1266. return val;
  1267. }
  1268. function _hasVal(node) {
  1269. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1270. }
  1271. function _docElement(doc) {
  1272. doc = doc || document;
  1273. return _QUIRKS ? doc.body : doc.documentElement;
  1274. }
  1275. function _docHeight(doc) {
  1276. var el = _docElement(doc);
  1277. return Math.max(el.scrollHeight, el.clientHeight);
  1278. }
  1279. function _docWidth(doc) {
  1280. var el = _docElement(doc);
  1281. return Math.max(el.scrollWidth, el.clientWidth);
  1282. }
  1283. function _getScrollPos(doc) {
  1284. doc = doc || document;
  1285. var x, y;
  1286. if (_IE || _NEWIE || _OPERA) {
  1287. x = _docElement(doc).scrollLeft;
  1288. y = _docElement(doc).scrollTop;
  1289. } else {
  1290. x = _getWin(doc).scrollX;
  1291. y = _getWin(doc).scrollY;
  1292. }
  1293. return {x : x, y : y};
  1294. }
  1295. function KNode(node) {
  1296. this.init(node);
  1297. }
  1298. _extend(KNode, {
  1299. init : function(node) {
  1300. var self = this;
  1301. node = _isArray(node) ? node : [node];
  1302. var length = 0;
  1303. for (var i = 0, len = node.length; i < len; i++) {
  1304. if (node[i]) {
  1305. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1306. length++;
  1307. }
  1308. }
  1309. self.length = length;
  1310. self.doc = _getDoc(self[0]);
  1311. self.name = _getNodeName(self[0]);
  1312. self.type = self.length > 0 ? self[0].nodeType : null;
  1313. self.win = _getWin(self[0]);
  1314. },
  1315. each : function(fn) {
  1316. var self = this;
  1317. for (var i = 0; i < self.length; i++) {
  1318. if (fn.call(self[i], i, self[i]) === false) {
  1319. return self;
  1320. }
  1321. }
  1322. return self;
  1323. },
  1324. bind : function(type, fn) {
  1325. this.each(function() {
  1326. _bind(this, type, fn);
  1327. });
  1328. return this;
  1329. },
  1330. unbind : function(type, fn) {
  1331. this.each(function() {
  1332. _unbind(this, type, fn);
  1333. });
  1334. return this;
  1335. },
  1336. fire : function(type) {
  1337. if (this.length < 1) {
  1338. return this;
  1339. }
  1340. _fire(this[0], type);
  1341. return this;
  1342. },
  1343. hasAttr : function(key) {
  1344. if (this.length < 1) {
  1345. return false;
  1346. }
  1347. return !!_getAttr(this[0], key);
  1348. },
  1349. attr : function(key, val) {
  1350. var self = this;
  1351. if (key === undefined) {
  1352. return _getAttrList(self.outer());
  1353. }
  1354. if (typeof key === 'object') {
  1355. _each(key, function(k, v) {
  1356. self.attr(k, v);
  1357. });
  1358. return self;
  1359. }
  1360. if (val === undefined) {
  1361. val = self.length < 1 ? null : _getAttr(self[0], key);
  1362. return val === null ? '' : val;
  1363. }
  1364. self.each(function() {
  1365. _setAttr(this, key, val);
  1366. });
  1367. return self;
  1368. },
  1369. removeAttr : function(key) {
  1370. this.each(function() {
  1371. _removeAttr(this, key);
  1372. });
  1373. return this;
  1374. },
  1375. get : function(i) {
  1376. if (this.length < 1) {
  1377. return null;
  1378. }
  1379. return this[i || 0];
  1380. },
  1381. eq : function(i) {
  1382. if (this.length < 1) {
  1383. return null;
  1384. }
  1385. return this[i] ? new KNode(this[i]) : null;
  1386. },
  1387. hasClass : function(cls) {
  1388. if (this.length < 1) {
  1389. return false;
  1390. }
  1391. return _hasClass(this[0], cls);
  1392. },
  1393. addClass : function(cls) {
  1394. this.each(function() {
  1395. if (!_hasClass(this, cls)) {
  1396. this.className = _trim(this.className + ' ' + cls);
  1397. }
  1398. });
  1399. return this;
  1400. },
  1401. removeClass : function(cls) {
  1402. this.each(function() {
  1403. if (_hasClass(this, cls)) {
  1404. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1405. }
  1406. });
  1407. return this;
  1408. },
  1409. html : function(val) {
  1410. var self = this;
  1411. if (val === undefined) {
  1412. if (self.length < 1 || self.type != 1) {
  1413. return '';
  1414. }
  1415. return _formatHtml(self[0].innerHTML);
  1416. }
  1417. self.each(function() {
  1418. _setHtml(this, val);
  1419. });
  1420. return self;
  1421. },
  1422. text : function() {
  1423. var self = this;
  1424. if (self.length < 1) {
  1425. return '';
  1426. }
  1427. return _IE ? self[0].innerText : self[0].textContent;
  1428. },
  1429. hasVal : function() {
  1430. if (this.length < 1) {
  1431. return false;
  1432. }
  1433. return _hasVal(this[0]);
  1434. },
  1435. val : function(val) {
  1436. var self = this;
  1437. if (val === undefined) {
  1438. if (self.length < 1) {
  1439. return '';
  1440. }
  1441. return self.hasVal() ? self[0].value : self.attr('value');
  1442. } else {
  1443. self.each(function() {
  1444. if (_hasVal(this)) {
  1445. this.value = val;
  1446. } else {
  1447. _setAttr(this, 'value' , val);
  1448. }
  1449. });
  1450. return self;
  1451. }
  1452. },
  1453. css : function(key, val) {
  1454. var self = this;
  1455. if (key === undefined) {
  1456. return _getCssList(self.attr('style'));
  1457. }
  1458. if (typeof key === 'object') {
  1459. _each(key, function(k, v) {
  1460. self.css(k, v);
  1461. });
  1462. return self;
  1463. }
  1464. if (val === undefined) {
  1465. if (self.length < 1) {
  1466. return '';
  1467. }
  1468. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1469. }
  1470. self.each(function() {
  1471. this.style[_toCamel(key)] = val;
  1472. });
  1473. return self;
  1474. },
  1475. width : function(val) {
  1476. var self = this;
  1477. if (val === undefined) {
  1478. if (self.length < 1) {
  1479. return 0;
  1480. }
  1481. return self[0].offsetWidth;
  1482. }
  1483. return self.css('width', _addUnit(val));
  1484. },
  1485. height : function(val) {
  1486. var self = this;
  1487. if (val === undefined) {
  1488. if (self.length < 1) {
  1489. return 0;
  1490. }
  1491. return self[0].offsetHeight;
  1492. }
  1493. return self.css('height', _addUnit(val));
  1494. },
  1495. opacity : function(val) {
  1496. this.each(function() {
  1497. if (this.style.opacity === undefined) {
  1498. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1499. } else {
  1500. this.style.opacity = val == 1 ? '' : val;
  1501. }
  1502. });
  1503. return this;
  1504. },
  1505. data : function(key, val) {
  1506. var self = this;
  1507. key = 'kindeditor_data_' + key;
  1508. if (val === undefined) {
  1509. if (self.length < 1) {
  1510. return null;
  1511. }
  1512. return self[0][key];
  1513. }
  1514. this.each(function() {
  1515. this[key] = val;
  1516. });
  1517. return self;
  1518. },
  1519. pos : function() {
  1520. var self = this, node = self[0], x = 0, y = 0;
  1521. if (node) {
  1522. if (node.getBoundingClientRect) {
  1523. var box = node.getBoundingClientRect(),
  1524. pos = _getScrollPos(self.doc);
  1525. x = box.left + pos.x;
  1526. y = box.top + pos.y;
  1527. } else {
  1528. while (node) {
  1529. x += node.offsetLeft;
  1530. y += node.offsetTop;
  1531. node = node.offsetParent;
  1532. }
  1533. }
  1534. }
  1535. return {x : _round(x), y : _round(y)};
  1536. },
  1537. clone : function(bool) {
  1538. if (this.length < 1) {
  1539. return new KNode([]);
  1540. }
  1541. return new KNode(this[0].cloneNode(bool));
  1542. },
  1543. append : function(expr) {
  1544. this.each(function() {
  1545. if (this.appendChild) {
  1546. this.appendChild(_get(expr));
  1547. }
  1548. });
  1549. return this;
  1550. },
  1551. appendTo : function(expr) {
  1552. this.each(function() {
  1553. _get(expr).appendChild(this);
  1554. });
  1555. return this;
  1556. },
  1557. before : function(expr) {
  1558. this.each(function() {
  1559. this.parentNode.insertBefore(_get(expr), this);
  1560. });
  1561. return this;
  1562. },
  1563. after : function(expr) {
  1564. this.each(function() {
  1565. if (this.nextSibling) {
  1566. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1567. } else {
  1568. this.parentNode.appendChild(_get(expr));
  1569. }
  1570. });
  1571. return this;
  1572. },
  1573. replaceWith : function(expr) {
  1574. var nodes = [];
  1575. this.each(function(i, node) {
  1576. _unbind(node);
  1577. var newNode = _get(expr);
  1578. node.parentNode.replaceChild(newNode, node);
  1579. nodes.push(newNode);
  1580. });
  1581. return K(nodes);
  1582. },
  1583. empty : function() {
  1584. var self = this;
  1585. self.each(function(i, node) {
  1586. var child = node.firstChild;
  1587. while (child) {
  1588. if (!node.parentNode) {
  1589. return;
  1590. }
  1591. var next = child.nextSibling;
  1592. child.parentNode.removeChild(child);
  1593. child = next;
  1594. }
  1595. });
  1596. return self;
  1597. },
  1598. remove : function(keepChilds) {
  1599. var self = this;
  1600. self.each(function(i, node) {
  1601. if (!node.parentNode) {
  1602. return;
  1603. }
  1604. _unbind(node);
  1605. if (keepChilds) {
  1606. var child = node.firstChild;
  1607. while (child) {
  1608. var next = child.nextSibling;
  1609. node.parentNode.insertBefore(child, node);
  1610. child = next;
  1611. }
  1612. }
  1613. node.parentNode.removeChild(node);
  1614. delete self[i];
  1615. });
  1616. self.length = 0;
  1617. return self;
  1618. },
  1619. show : function(val) {
  1620. var self = this;
  1621. if (val === undefined) {
  1622. val = self._originDisplay || '';
  1623. }
  1624. if (self.css('display') != 'none') {
  1625. return self;
  1626. }
  1627. return self.css('display', val);
  1628. },
  1629. hide : function() {
  1630. var self = this;
  1631. if (self.length < 1) {
  1632. return self;
  1633. }
  1634. self._originDisplay = self[0].style.display;
  1635. return self.css('display', 'none');
  1636. },
  1637. outer : function() {
  1638. var self = this;
  1639. if (self.length < 1) {
  1640. return '';
  1641. }
  1642. var div = self.doc.createElement('div'), html;
  1643. div.appendChild(self[0].cloneNode(true));
  1644. html = _formatHtml(div.innerHTML);
  1645. div = null;
  1646. return html;
  1647. },
  1648. isSingle : function() {
  1649. return !!_SINGLE_TAG_MAP[this.name];
  1650. },
  1651. isInline : function() {
  1652. return !!_INLINE_TAG_MAP[this.name];
  1653. },
  1654. isBlock : function() {
  1655. return !!_BLOCK_TAG_MAP[this.name];
  1656. },
  1657. isStyle : function() {
  1658. return !!_STYLE_TAG_MAP[this.name];
  1659. },
  1660. isControl : function() {
  1661. return !!_CONTROL_TAG_MAP[this.name];
  1662. },
  1663. contains : function(otherNode) {
  1664. if (this.length < 1) {
  1665. return false;
  1666. }
  1667. return _contains(this[0], _get(otherNode));
  1668. },
  1669. parent : function() {
  1670. if (this.length < 1) {
  1671. return null;
  1672. }
  1673. var node = this[0].parentNode;
  1674. return node ? new KNode(node) : null;
  1675. },
  1676. children : function() {
  1677. if (this.length < 1) {
  1678. return new KNode([]);
  1679. }
  1680. var list = [], child = this[0].firstChild;
  1681. while (child) {
  1682. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1683. list.push(child);
  1684. }
  1685. child = child.nextSibling;
  1686. }
  1687. return new KNode(list);
  1688. },
  1689. first : function() {
  1690. var list = this.children();
  1691. return list.length > 0 ? list.eq(0) : null;
  1692. },
  1693. last : function() {
  1694. var list = this.children();
  1695. return list.length > 0 ? list.eq(list.length - 1) : null;
  1696. },
  1697. index : function() {
  1698. if (this.length < 1) {
  1699. return -1;
  1700. }
  1701. var i = -1, sibling = this[0];
  1702. while (sibling) {
  1703. i++;
  1704. sibling = sibling.previousSibling;
  1705. }
  1706. return i;
  1707. },
  1708. prev : function() {
  1709. if (this.length < 1) {
  1710. return null;
  1711. }
  1712. var node = this[0].previousSibling;
  1713. return node ? new KNode(node) : null;
  1714. },
  1715. next : function() {
  1716. if (this.length < 1) {
  1717. return null;
  1718. }
  1719. var node = this[0].nextSibling;
  1720. return node ? new KNode(node) : null;
  1721. },
  1722. scan : function(fn, order) {
  1723. if (this.length < 1) {
  1724. return;
  1725. }
  1726. order = (order === undefined) ? true : order;
  1727. function walk(node) {
  1728. var n = order ? node.firstChild : node.lastChild;
  1729. while (n) {
  1730. var next = order ? n.nextSibling : n.previousSibling;
  1731. if (fn(n) === false) {
  1732. return false;
  1733. }
  1734. if (walk(n) === false) {
  1735. return false;
  1736. }
  1737. n = next;
  1738. }
  1739. }
  1740. walk(this[0]);
  1741. return this;
  1742. }
  1743. });
  1744. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1745. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1746. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1747. KNode.prototype[type] = function(fn) {
  1748. return fn ? this.bind(type, fn) : this.fire(type);
  1749. };
  1750. });
  1751. var _K = K;
  1752. K = function(expr, root) {
  1753. if (expr === undefined || expr === null) {
  1754. return;
  1755. }
  1756. function newNode(node) {
  1757. if (!node[0]) {
  1758. node = [];
  1759. }
  1760. return new KNode(node);
  1761. }
  1762. if (typeof expr === 'string') {
  1763. if (root) {
  1764. root = _get(root);
  1765. }
  1766. var length = expr.length;
  1767. if (expr.charAt(0) === '@') {
  1768. expr = expr.substr(1);
  1769. }
  1770. if (expr.length !== length || /<.+>/.test(expr)) {
  1771. var doc = root ? root.ownerDocument || root : document,
  1772. div = doc.createElement('div'), list = [];
  1773. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1774. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1775. var child = div.childNodes[i];
  1776. if (child.id == '__kindeditor_temp_tag__') {
  1777. continue;
  1778. }
  1779. list.push(child);
  1780. }
  1781. return newNode(list);
  1782. }
  1783. return newNode(_queryAll(expr, root));
  1784. }
  1785. if (expr && expr.constructor === KNode) {
  1786. return expr;
  1787. }
  1788. if (expr.toArray) {
  1789. expr = expr.toArray();
  1790. }
  1791. if (_isArray(expr)) {
  1792. return newNode(expr);
  1793. }
  1794. return newNode(_toArray(arguments));
  1795. };
  1796. _each(_K, function(key, val) {
  1797. K[key] = val;
  1798. });
  1799. K.NodeClass = KNode;
  1800. window.KindEditor = K;
  1801. var _START_TO_START = 0,
  1802. _START_TO_END = 1,
  1803. _END_TO_END = 2,
  1804. _END_TO_START = 3,
  1805. _BOOKMARK_ID = 0;
  1806. function _updateCollapsed(range) {
  1807. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1808. return range;
  1809. }
  1810. function _copyAndDelete(range, isCopy, isDelete) {
  1811. var doc = range.doc, nodeList = [];
  1812. function splitTextNode(node, startOffset, endOffset) {
  1813. var length = node.nodeValue.length, centerNode;
  1814. if (isCopy) {
  1815. var cloneNode = node.cloneNode(true);
  1816. if (startOffset > 0) {
  1817. centerNode = cloneNode.splitText(startOffset);
  1818. } else {
  1819. centerNode = cloneNode;
  1820. }
  1821. if (endOffset < length) {
  1822. centerNode.splitText(endOffset - startOffset);
  1823. }
  1824. }
  1825. if (isDelete) {
  1826. var center = node;
  1827. if (startOffset > 0) {
  1828. center = node.splitText(startOffset);
  1829. range.setStart(node, startOffset);
  1830. }
  1831. if (endOffset < length) {
  1832. var right = center.splitText(endOffset - startOffset);
  1833. range.setEnd(right, 0);
  1834. }
  1835. nodeList.push(center);
  1836. }
  1837. return centerNode;
  1838. }
  1839. function removeNodes() {
  1840. if (isDelete) {
  1841. range.up().collapse(true);
  1842. }
  1843. for (var i = 0, len = nodeList.length; i < len; i++) {
  1844. var node = nodeList[i];
  1845. if (node.parentNode) {
  1846. node.parentNode.removeChild(node);
  1847. }
  1848. }
  1849. }
  1850. var copyRange = range.cloneRange().down();
  1851. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1852. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1853. if (ancestor.nodeType == 3) {
  1854. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1855. if (isCopy) {
  1856. frag.appendChild(textNode);
  1857. }
  1858. removeNodes();
  1859. return isCopy ? frag : range;
  1860. }
  1861. function extractNodes(parent, frag) {
  1862. var node = parent.firstChild, nextNode;
  1863. while (node) {
  1864. var testRange = new KRange(doc).selectNode(node);
  1865. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1866. if (start >= 0 && incStart <= 0) {
  1867. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1868. }
  1869. if (incStart >= 0 && incEnd <= 0) {
  1870. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1871. }
  1872. if (incEnd >= 0 && end <= 0) {
  1873. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1874. }
  1875. if (end >= 0) {
  1876. return false;
  1877. }
  1878. nextNode = node.nextSibling;
  1879. if (start > 0) {
  1880. if (node.nodeType == 1) {
  1881. if (incStart >= 0 && incEnd <= 0) {
  1882. if (isCopy) {
  1883. frag.appendChild(node.cloneNode(true));
  1884. }
  1885. if (isDelete) {
  1886. nodeList.push(node);
  1887. }
  1888. } else {
  1889. var childFlag;
  1890. if (isCopy) {
  1891. childFlag = node.cloneNode(false);
  1892. frag.appendChild(childFlag);
  1893. }
  1894. if (extractNodes(node, childFlag) === false) {
  1895. return false;
  1896. }
  1897. }
  1898. } else if (node.nodeType == 3) {
  1899. var textNode;
  1900. if (node == copyRange.startContainer) {
  1901. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1902. } else if (node == copyRange.endContainer) {
  1903. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1904. } else {
  1905. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1906. }
  1907. if (isCopy) {
  1908. try {
  1909. frag.appendChild(textNode);
  1910. } catch(e) {}
  1911. }
  1912. }
  1913. }
  1914. node = nextNode;
  1915. }
  1916. }
  1917. extractNodes(ancestor, frag);
  1918. if (isDelete) {
  1919. range.up().collapse(true);
  1920. }
  1921. for (var i = 0, len = nodeList.length; i < len; i++) {
  1922. var node = nodeList[i];
  1923. if (node.parentNode) {
  1924. node.parentNode.removeChild(node);
  1925. }
  1926. }
  1927. return isCopy ? frag : range;
  1928. }
  1929. function _moveToElementText(range, el) {
  1930. var node = el;
  1931. while (node) {
  1932. var knode = K(node);
  1933. if (knode.name == 'marquee' || knode.name == 'select') {
  1934. return;
  1935. }
  1936. node = node.parentNode;
  1937. }
  1938. try {
  1939. range.moveToElementText(el);
  1940. } catch(e) {}
  1941. }
  1942. function _getStartEnd(rng, isStart) {
  1943. var doc = rng.parentElement().ownerDocument,
  1944. pointRange = rng.duplicate();
  1945. pointRange.collapse(isStart);
  1946. var parent = pointRange.parentElement(),
  1947. nodes = parent.childNodes;
  1948. if (nodes.length === 0) {
  1949. return {node: parent.parentNode, offset: K(parent).index()};
  1950. }
  1951. var startNode = doc, startPos = 0, cmp = -1;
  1952. var testRange = rng.duplicate();
  1953. _moveToElementText(testRange, parent);
  1954. for (var i = 0, len = nodes.length; i < len; i++) {
  1955. var node = nodes[i];
  1956. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1957. if (cmp === 0) {
  1958. return {node: node.parentNode, offset: i};
  1959. }
  1960. if (node.nodeType == 1) {
  1961. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1962. if (knode.isControl()) {
  1963. dummy = doc.createElement('span');
  1964. knode.after(dummy);
  1965. newNode = dummy;
  1966. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1967. }
  1968. _moveToElementText(nodeRange, newNode);
  1969. testRange.setEndPoint('StartToEnd', nodeRange);
  1970. if (cmp > 0) {
  1971. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1972. } else {
  1973. startPos = 0;
  1974. }
  1975. if (dummy) {
  1976. K(dummy).remove();
  1977. }
  1978. } else if (node.nodeType == 3) {
  1979. testRange.moveStart('character', node.nodeValue.length);
  1980. startPos += node.nodeValue.length;
  1981. }
  1982. if (cmp < 0) {
  1983. startNode = node;
  1984. }
  1985. }
  1986. if (cmp < 0 && startNode.nodeType == 1) {
  1987. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1988. }
  1989. if (cmp > 0) {
  1990. while (startNode.nextSibling && startNode.nodeType == 1) {
  1991. startNode = startNode.nextSibling;
  1992. }
  1993. }
  1994. testRange = rng.duplicate();
  1995. _moveToElementText(testRange, parent);
  1996. testRange.setEndPoint('StartToEnd', pointRange);
  1997. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1998. if (cmp > 0 && startNode.nodeType == 3) {
  1999. var prevNode = startNode.previousSibling;
  2000. while (prevNode && prevNode.nodeType == 3) {
  2001. startPos -= prevNode.nodeValue.length;
  2002. prevNode = prevNode.previousSibling;
  2003. }
  2004. }
  2005. return {node: startNode, offset: startPos};
  2006. }
  2007. function _getEndRange(node, offset) {
  2008. var doc = node.ownerDocument || node,
  2009. range = doc.body.createTextRange();
  2010. if (doc == node) {
  2011. range.collapse(true);
  2012. return range;
  2013. }
  2014. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2015. var children = node.childNodes, isStart, child;
  2016. if (offset === 0) {
  2017. child = children[0];
  2018. isStart = true;
  2019. } else {
  2020. child = children[offset - 1];
  2021. isStart = false;
  2022. }
  2023. if (!child) {
  2024. return range;
  2025. }
  2026. if (K(child).name === 'head') {
  2027. if (offset === 1) {
  2028. isStart = true;
  2029. }
  2030. if (offset === 2) {
  2031. isStart = false;
  2032. }
  2033. range.collapse(isStart);
  2034. return range;
  2035. }
  2036. if (child.nodeType == 1) {
  2037. var kchild = K(child), span;
  2038. if (kchild.isControl()) {
  2039. span = doc.createElement('span');
  2040. if (isStart) {
  2041. kchild.before(span);
  2042. } else {
  2043. kchild.after(span);
  2044. }
  2045. child = span;
  2046. }
  2047. _moveToElementText(range, child);
  2048. range.collapse(isStart);
  2049. if (span) {
  2050. K(span).remove();
  2051. }
  2052. return range;
  2053. }
  2054. node = child;
  2055. offset = isStart ? 0 : child.nodeValue.length;
  2056. }
  2057. var dummy = doc.createElement('span');
  2058. K(node).before(dummy);
  2059. _moveToElementText(range, dummy);
  2060. range.moveStart('character', offset);
  2061. K(dummy).remove();
  2062. return range;
  2063. }
  2064. function _toRange(rng) {
  2065. var doc, range;
  2066. function tr2td(start) {
  2067. if (K(start.node).name == 'tr') {
  2068. start.node = start.node.cells[start.offset];
  2069. start.offset = 0;
  2070. }
  2071. }
  2072. if (_IERANGE) {
  2073. if (rng.item) {
  2074. doc = _getDoc(rng.item(0));
  2075. range = new KRange(doc);
  2076. range.selectNode(rng.item(0));
  2077. return range;
  2078. }
  2079. doc = rng.parentElement().ownerDocument;
  2080. var start = _getStartEnd(rng, true),
  2081. end = _getStartEnd(rng, false);
  2082. tr2td(start);
  2083. tr2td(end);
  2084. range = new KRange(doc);
  2085. range.setStart(start.node, start.offset);
  2086. range.setEnd(end.node, end.offset);
  2087. return range;
  2088. }
  2089. var startContainer = rng.startContainer;
  2090. doc = startContainer.ownerDocument || startContainer;
  2091. range = new KRange(doc);
  2092. range.setStart(startContainer, rng.startOffset);
  2093. range.setEnd(rng.endContainer, rng.endOffset);
  2094. return range;
  2095. }
  2096. function KRange(doc) {
  2097. this.init(doc);
  2098. }
  2099. _extend(KRange, {
  2100. init : function(doc) {
  2101. var self = this;
  2102. self.startContainer = doc;
  2103. self.startOffset = 0;
  2104. self.endContainer = doc;
  2105. self.endOffset = 0;
  2106. self.collapsed = true;
  2107. self.doc = doc;
  2108. },
  2109. commonAncestor : function() {
  2110. function getParents(node) {
  2111. var parents = [];
  2112. while (node) {
  2113. parents.push(node);
  2114. node = node.parentNode;
  2115. }
  2116. return parents;
  2117. }
  2118. var parentsA = getParents(this.startContainer),
  2119. parentsB = getParents(this.endContainer),
  2120. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2121. while (++i) {
  2122. parentA = parentsA[lenA - i];
  2123. parentB = parentsB[lenB - i];
  2124. if (!parentA || !parentB || parentA !== parentB) {
  2125. break;
  2126. }
  2127. }
  2128. return parentsA[lenA - i + 1];
  2129. },
  2130. setStart : function(node, offset) {
  2131. var self = this, doc = self.doc;
  2132. self.startContainer = node;
  2133. self.startOffset = offset;
  2134. if (self.endContainer === doc) {
  2135. self.endContainer = node;
  2136. self.endOffset = offset;
  2137. }
  2138. return _updateCollapsed(this);
  2139. },
  2140. setEnd : function(node, offset) {
  2141. var self = this, doc = self.doc;
  2142. self.endContainer = node;
  2143. self.endOffset = offset;
  2144. if (self.startContainer === doc) {
  2145. self.startContainer = node;
  2146. self.startOffset = offset;
  2147. }
  2148. return _updateCollapsed(this);
  2149. },
  2150. setStartBefore : function(node) {
  2151. return this.setStart(node.parentNode || this.doc, K(node).index());
  2152. },
  2153. setStartAfter : function(node) {
  2154. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2155. },
  2156. setEndBefore : function(node) {
  2157. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2158. },
  2159. setEndAfter : function(node) {
  2160. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2161. },
  2162. selectNode : function(node) {
  2163. return this.setStartBefore(node).setEndAfter(node);
  2164. },
  2165. selectNodeContents : function(node) {
  2166. var knode = K(node);
  2167. if (knode.type == 3 || knode.isSingle()) {
  2168. return this.selectNode(node);
  2169. }
  2170. var children = knode.children();
  2171. if (children.length > 0) {
  2172. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2173. }
  2174. return this.setStart(node, 0).setEnd(node, 0);
  2175. },
  2176. collapse : function(toStart) {
  2177. if (toStart) {
  2178. return this.setEnd(this.startContainer, this.startOffset);
  2179. }
  2180. return this.setStart(this.endContainer, this.endOffset);
  2181. },
  2182. compareBoundaryPoints : function(how, range) {
  2183. var rangeA = this.get(), rangeB = range.get();
  2184. if (_IERANGE) {
  2185. var arr = {};
  2186. arr[_START_TO_START] = 'StartToStart';
  2187. arr[_START_TO_END] = 'EndToStart';
  2188. arr[_END_TO_END] = 'EndToEnd';
  2189. arr[_END_TO_START] = 'StartToEnd';
  2190. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2191. if (cmp !== 0) {
  2192. return cmp;
  2193. }
  2194. var nodeA, nodeB, nodeC, posA, posB;
  2195. if (how === _START_TO_START || how === _END_TO_START) {
  2196. nodeA = this.startContainer;
  2197. posA = this.startOffset;
  2198. }
  2199. if (how === _START_TO_END || how === _END_TO_END) {
  2200. nodeA = this.endContainer;
  2201. posA = this.endOffset;
  2202. }
  2203. if (how === _START_TO_START || how === _START_TO_END) {
  2204. nodeB = range.startContainer;
  2205. posB = range.startOffset;
  2206. }
  2207. if (how === _END_TO_END || how === _END_TO_START) {
  2208. nodeB = range.endContainer;
  2209. posB = range.endOffset;
  2210. }
  2211. if (nodeA === nodeB) {
  2212. var diff = posA - posB;
  2213. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2214. }
  2215. nodeC = nodeB;
  2216. while (nodeC && nodeC.parentNode !== nodeA) {
  2217. nodeC = nodeC.parentNode;
  2218. }
  2219. if (nodeC) {
  2220. return K(nodeC).index() >= posA ? -1 : 1;
  2221. }
  2222. nodeC = nodeA;
  2223. while (nodeC && nodeC.parentNode !== nodeB) {
  2224. nodeC = nodeC.parentNode;
  2225. }
  2226. if (nodeC) {
  2227. return K(nodeC).index() >= posB ? 1 : -1;
  2228. }
  2229. nodeC = K(nodeB).next();
  2230. if (nodeC && nodeC.contains(nodeA)) {
  2231. return 1;
  2232. }
  2233. nodeC = K(nodeA).next();
  2234. if (nodeC && nodeC.contains(nodeB)) {
  2235. return -1;
  2236. }
  2237. } else {
  2238. return rangeA.compareBoundaryPoints(how, rangeB);
  2239. }
  2240. },
  2241. cloneRange : function() {
  2242. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2243. },
  2244. toString : function() {
  2245. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2246. return str.replace(/\r\n|\n|\r/g, '');
  2247. },
  2248. cloneContents : function() {
  2249. return _copyAndDelete(this, true, false);
  2250. },
  2251. deleteContents : function() {
  2252. return _copyAndDelete(this, false, true);
  2253. },
  2254. extractContents : function() {
  2255. return _copyAndDelete(this, true, true);
  2256. },
  2257. insertNode : function(node) {
  2258. var self = this,
  2259. sc = self.startContainer, so = self.startOffset,
  2260. ec = self.endContainer, eo = self.endOffset,
  2261. firstChild, lastChild, c, nodeCount = 1;
  2262. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2263. firstChild = node.firstChild;
  2264. lastChild = node.lastChild;
  2265. nodeCount = node.childNodes.length;
  2266. }
  2267. if (sc.nodeType == 1) {
  2268. c = sc.childNodes[so];
  2269. if (c) {
  2270. sc.insertBefore(node, c);
  2271. if (sc === ec) {
  2272. eo += nodeCount;
  2273. }
  2274. } else {
  2275. sc.appendChild(node);
  2276. }
  2277. } else if (sc.nodeType == 3) {
  2278. if (so === 0) {
  2279. sc.parentNode.insertBefore(node, sc);
  2280. if (sc.parentNode === ec) {
  2281. eo += nodeCount;
  2282. }
  2283. } else if (so >= sc.nodeValue.length) {
  2284. if (sc.nextSibling) {
  2285. sc.parentNode.insertBefore(node, sc.nextSibling);
  2286. } else {
  2287. sc.parentNode.appendChild(node);
  2288. }
  2289. } else {
  2290. if (so > 0) {
  2291. c = sc.splitText(so);
  2292. } else {
  2293. c = sc;
  2294. }
  2295. sc.parentNode.insertBefore(node, c);
  2296. if (sc === ec) {
  2297. ec = c;
  2298. eo -= so;
  2299. }
  2300. }
  2301. }
  2302. if (firstChild) {
  2303. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2304. } else {
  2305. self.selectNode(node);
  2306. }
  2307. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2308. return self;
  2309. }
  2310. return self.setEnd(ec, eo);
  2311. },
  2312. surroundContents : function(node) {
  2313. node.appendChild(this.extractContents());
  2314. return this.insertNode(node).selectNode(node);
  2315. },
  2316. isControl : function() {
  2317. var self = this,
  2318. sc = self.startContainer, so = self.startOffset,
  2319. ec = self.endContainer, eo = self.endOffset, rng;
  2320. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2321. },
  2322. get : function(hasControlRange) {
  2323. var self = this, doc = self.doc, node, rng;
  2324. if (!_IERANGE) {
  2325. rng = doc.createRange();
  2326. try {
  2327. rng.setStart(self.startContainer, self.startOffset);
  2328. rng.setEnd(self.endContainer, self.endOffset);
  2329. } catch (e) {}
  2330. return rng;
  2331. }
  2332. if (hasControlRange && self.isControl()) {
  2333. rng = doc.body.createControlRange();
  2334. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2335. return rng;
  2336. }
  2337. var range = self.cloneRange().down();
  2338. rng = doc.body.createTextRange();
  2339. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2340. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2341. return rng;
  2342. },
  2343. html : function() {
  2344. return K(this.cloneContents()).outer();
  2345. },
  2346. down : function() {
  2347. var self = this;
  2348. function downPos(node, pos, isStart) {
  2349. if (node.nodeType != 1) {
  2350. return;
  2351. }
  2352. var children = K(node).children();
  2353. if (children.length === 0) {
  2354. return;
  2355. }
  2356. var left, right, child, offset;
  2357. if (pos > 0) {
  2358. left = children.eq(pos - 1);
  2359. }
  2360. if (pos < children.length) {
  2361. right = children.eq(pos);
  2362. }
  2363. if (left && left.type == 3) {
  2364. child = left[0];
  2365. offset = child.nodeValue.length;
  2366. }
  2367. if (right && right.type == 3) {
  2368. child = right[0];
  2369. offset = 0;
  2370. }
  2371. if (!child) {
  2372. return;
  2373. }
  2374. if (isStart) {
  2375. self.setStart(child, offset);
  2376. } else {
  2377. self.setEnd(child, offset);
  2378. }
  2379. }
  2380. downPos(self.startContainer, self.startOffset, true);
  2381. downPos(self.endContainer, self.endOffset, false);
  2382. return self;
  2383. },
  2384. up : function() {
  2385. var self = this;
  2386. function upPos(node, pos, isStart) {
  2387. if (node.nodeType != 3) {
  2388. return;
  2389. }
  2390. if (pos === 0) {
  2391. if (isStart) {
  2392. self.setStartBefore(node);
  2393. } else {
  2394. self.setEndBefore(node);
  2395. }
  2396. } else if (pos == node.nodeValue.length) {
  2397. if (isStart) {
  2398. self.setStartAfter(node);
  2399. } else {
  2400. self.setEndAfter(node);
  2401. }
  2402. }
  2403. }
  2404. upPos(self.startContainer, self.startOffset, true);
  2405. upPos(self.endContainer, self.endOffset, false);
  2406. return self;
  2407. },
  2408. enlarge : function(toBlock) {
  2409. var self = this;
  2410. self.up();
  2411. function enlargePos(node, pos, isStart) {
  2412. var knode = K(node), parent;
  2413. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2414. return;
  2415. }
  2416. if (pos === 0) {
  2417. while (!knode.prev()) {
  2418. parent = knode.parent();
  2419. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2420. break;
  2421. }
  2422. knode = parent;
  2423. }
  2424. if (isStart) {
  2425. self.setStartBefore(knode[0]);
  2426. } else {
  2427. self.setEndBefore(knode[0]);
  2428. }
  2429. } else if (pos == knode.children().length) {
  2430. while (!knode.next()) {
  2431. parent = knode.parent();
  2432. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2433. break;
  2434. }
  2435. knode = parent;
  2436. }
  2437. if (isStart) {
  2438. self.setStartAfter(knode[0]);
  2439. } else {
  2440. self.setEndAfter(knode[0]);
  2441. }
  2442. }
  2443. }
  2444. enlargePos(self.startContainer, self.startOffset, true);
  2445. enlargePos(self.endContainer, self.endOffset, false);
  2446. return self;
  2447. },
  2448. shrink : function() {
  2449. var self = this, child, collapsed = self.collapsed;
  2450. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2451. self.setStart(child, 0);
  2452. }
  2453. if (collapsed) {
  2454. return self.collapse(collapsed);
  2455. }
  2456. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2457. self.setEnd(child, child.childNodes.length);
  2458. }
  2459. return self;
  2460. },
  2461. createBookmark : function(serialize) {
  2462. var self = this, doc = self.doc, endNode,
  2463. startNode = K('<span style="display:none;"></span>', doc)[0];
  2464. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2465. if (!self.collapsed) {
  2466. endNode = startNode.cloneNode(true);
  2467. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2468. }
  2469. if (endNode) {
  2470. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2471. }
  2472. self.insertNode(startNode).setStartAfter(startNode);
  2473. return {
  2474. start : serialize ? '#' + startNode.id : startNode,
  2475. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2476. };
  2477. },
  2478. moveToBookmark : function(bookmark) {
  2479. var self = this, doc = self.doc,
  2480. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2481. if (!start || start.length < 1) {
  2482. return self;
  2483. }
  2484. self.setStartBefore(start[0]);
  2485. start.remove();
  2486. if (end && end.length > 0) {
  2487. self.setEndBefore(end[0]);
  2488. end.remove();
  2489. } else {
  2490. self.collapse(true);
  2491. }
  2492. return self;
  2493. },
  2494. dump : function() {
  2495. console.log('--------------------');
  2496. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2497. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2498. }
  2499. });
  2500. function _range(mixed) {
  2501. if (!mixed.nodeName) {
  2502. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2503. }
  2504. return new KRange(mixed);
  2505. }
  2506. K.RangeClass = KRange;
  2507. K.range = _range;
  2508. K.START_TO_START = _START_TO_START;
  2509. K.START_TO_END = _START_TO_END;
  2510. K.END_TO_END = _END_TO_END;
  2511. K.END_TO_START = _END_TO_START;
  2512. function _nativeCommand(doc, key, val) {
  2513. try {
  2514. doc.execCommand(key, false, val);
  2515. } catch(e) {}
  2516. }
  2517. function _nativeCommandValue(doc, key) {
  2518. var val = '';
  2519. try {
  2520. val = doc.queryCommandValue(key);
  2521. } catch (e) {}
  2522. if (typeof val !== 'string') {
  2523. val = '';
  2524. }
  2525. return val;
  2526. }
  2527. function _getSel(doc) {
  2528. var win = _getWin(doc);
  2529. return _IERANGE ? doc.selection : win.getSelection();
  2530. }
  2531. function _getRng(doc) {
  2532. var sel = _getSel(doc), rng;
  2533. try {
  2534. if (sel.rangeCount > 0) {
  2535. rng = sel.getRangeAt(0);
  2536. } else {
  2537. rng = sel.createRange();
  2538. }
  2539. } catch(e) {}
  2540. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2541. return null;
  2542. }
  2543. return rng;
  2544. }
  2545. function _singleKeyMap(map) {
  2546. var newMap = {}, arr, v;
  2547. _each(map, function(key, val) {
  2548. arr = key.split(',');
  2549. for (var i = 0, len = arr.length; i < len; i++) {
  2550. v = arr[i];
  2551. newMap[v] = val;
  2552. }
  2553. });
  2554. return newMap;
  2555. }
  2556. function _hasAttrOrCss(knode, map) {
  2557. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2558. }
  2559. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2560. mapKey = mapKey || knode.name;
  2561. if (knode.type !== 1) {
  2562. return false;
  2563. }
  2564. var newMap = _singleKeyMap(map);
  2565. if (!newMap[mapKey]) {
  2566. return false;
  2567. }
  2568. var arr = newMap[mapKey].split(',');
  2569. for (var i = 0, len = arr.length; i < len; i++) {
  2570. var key = arr[i];
  2571. if (key === '*') {
  2572. return true;
  2573. }
  2574. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2575. var method = match[1] ? 'css' : 'attr';
  2576. key = match[2];
  2577. var val = match[3] || '';
  2578. if (val === '' && knode[method](key) !== '') {
  2579. return true;
  2580. }
  2581. if (val !== '' && knode[method](key) === val) {
  2582. return true;
  2583. }
  2584. }
  2585. return false;
  2586. }
  2587. function _removeAttrOrCss(knode, map) {
  2588. if (knode.type != 1) {
  2589. return;
  2590. }
  2591. _removeAttrOrCssByKey(knode, map, '*');
  2592. _removeAttrOrCssByKey(knode, map);
  2593. }
  2594. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2595. mapKey = mapKey || knode.name;
  2596. if (knode.type !== 1) {
  2597. return;
  2598. }
  2599. var newMap = _singleKeyMap(map);
  2600. if (!newMap[mapKey]) {
  2601. return;
  2602. }
  2603. var arr = newMap[mapKey].split(','), allFlag = false;
  2604. for (var i = 0, len = arr.length; i < len; i++) {
  2605. var key = arr[i];
  2606. if (key === '*') {
  2607. allFlag = true;
  2608. break;
  2609. }
  2610. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2611. key = match[2];
  2612. if (match[1]) {
  2613. key = _toCamel(key);
  2614. if (knode[0].style[key]) {
  2615. knode[0].style[key] = '';
  2616. }
  2617. } else {
  2618. knode.removeAttr(key);
  2619. }
  2620. }
  2621. if (allFlag) {
  2622. knode.remove(true);
  2623. }
  2624. }
  2625. function _getInnerNode(knode) {
  2626. var inner = knode;
  2627. while (inner.first()) {
  2628. inner = inner.first();
  2629. }
  2630. return inner;
  2631. }
  2632. function _isEmptyNode(knode) {
  2633. if (knode.type != 1 || knode.isSingle()) {
  2634. return false;
  2635. }
  2636. return knode.html().replace(/<[^>]+>/g, '') === '';
  2637. }
  2638. function _mergeWrapper(a, b) {
  2639. a = a.clone(true);
  2640. var lastA = _getInnerNode(a), childA = a, merged = false;
  2641. while (b) {
  2642. while (childA) {
  2643. if (childA.name === b.name) {
  2644. _mergeAttrs(childA, b.attr(), b.css());
  2645. merged = true;
  2646. }
  2647. childA = childA.first();
  2648. }
  2649. if (!merged) {
  2650. lastA.append(b.clone(false));
  2651. }
  2652. merged = false;
  2653. b = b.first();
  2654. }
  2655. return a;
  2656. }
  2657. function _wrapNode(knode, wrapper) {
  2658. wrapper = wrapper.clone(true);
  2659. if (knode.type == 3) {
  2660. _getInnerNode(wrapper).append(knode.clone(false));
  2661. knode.replaceWith(wrapper);
  2662. return wrapper;
  2663. }
  2664. var nodeWrapper = knode, child;
  2665. while ((child = knode.first()) && child.children().length == 1) {
  2666. knode = child;
  2667. }
  2668. child = knode.first();
  2669. var frag = knode.doc.createDocumentFragment();
  2670. while (child) {
  2671. frag.appendChild(child[0]);
  2672. child = child.next();
  2673. }
  2674. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2675. if (frag.firstChild) {
  2676. _getInnerNode(wrapper).append(frag);
  2677. }
  2678. nodeWrapper.replaceWith(wrapper);
  2679. return wrapper;
  2680. }
  2681. function _mergeAttrs(knode, attrs, styles) {
  2682. _each(attrs, function(key, val) {
  2683. if (key !== 'style') {
  2684. knode.attr(key, val);
  2685. }
  2686. });
  2687. _each(styles, function(key, val) {
  2688. knode.css(key, val);
  2689. });
  2690. }
  2691. function _inPreElement(knode) {
  2692. while (knode && knode.name != 'body') {
  2693. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2694. return true;
  2695. }
  2696. knode = knode.parent();
  2697. }
  2698. return false;
  2699. }
  2700. function KCmd(range) {
  2701. this.init(range);
  2702. }
  2703. _extend(KCmd, {
  2704. init : function(range) {
  2705. var self = this, doc = range.doc;
  2706. self.doc = doc;
  2707. self.win = _getWin(doc);
  2708. self.sel = _getSel(doc);
  2709. self.range = range;
  2710. },
  2711. selection : function(forceReset) {
  2712. var self = this, doc = self.doc, rng = _getRng(doc);
  2713. self.sel = _getSel(doc);
  2714. if (rng) {
  2715. self.range = _range(rng);
  2716. if (K(self.range.startContainer).name == 'html') {
  2717. self.range.selectNodeContents(doc.body).collapse(false);
  2718. }
  2719. return self;
  2720. }
  2721. if (forceReset) {
  2722. self.range.selectNodeContents(doc.body).collapse(false);
  2723. }
  2724. return self;
  2725. },
  2726. select : function(hasDummy) {
  2727. hasDummy = _undef(hasDummy, true);
  2728. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2729. sc = range.startContainer, so = range.startOffset,
  2730. ec = range.endContainer, eo = range.endOffset,
  2731. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2732. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2733. if (_IERANGE) {
  2734. var dummy = K('<span>&nbsp;</span>', doc);
  2735. range.insertNode(dummy[0]);
  2736. rng = doc.body.createTextRange();
  2737. try {
  2738. rng.moveToElementText(dummy[0]);
  2739. } catch(ex) {}
  2740. rng.collapse(false);
  2741. rng.select();
  2742. dummy.remove();
  2743. win.focus();
  2744. return self;
  2745. }
  2746. if (_WEBKIT) {
  2747. var children = sc.childNodes;
  2748. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2749. range.insertNode(doc.createTextNode('\u200B'));
  2750. hasU200b = true;
  2751. }
  2752. }
  2753. }
  2754. if (_IERANGE) {
  2755. try {
  2756. rng = range.get(true);
  2757. rng.select();
  2758. } catch(e) {}
  2759. } else {
  2760. if (hasU200b) {
  2761. range.collapse(false);
  2762. }
  2763. rng = range.get(true);
  2764. sel.removeAllRanges();
  2765. sel.addRange(rng);
  2766. if (doc !== document) {
  2767. var pos = K(rng.endContainer).pos();
  2768. win.scrollTo(pos.x, pos.y);
  2769. }
  2770. }
  2771. win.focus();
  2772. return self;
  2773. },
  2774. wrap : function(val) {
  2775. var self = this, doc = self.doc, range = self.range, wrapper;
  2776. wrapper = K(val, doc);
  2777. if (range.collapsed) {
  2778. range.shrink();
  2779. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2780. return self;
  2781. }
  2782. if (wrapper.isBlock()) {
  2783. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2784. while (child.first()) {
  2785. child = child.first();
  2786. }
  2787. child.append(range.extractContents());
  2788. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2789. return self;
  2790. }
  2791. range.enlarge();
  2792. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2793. K(ancestor).scan(function(node) {
  2794. if (!isStart && node == bookmark.start) {
  2795. isStart = true;
  2796. return;
  2797. }
  2798. if (isStart) {
  2799. if (node == bookmark.end) {
  2800. return false;
  2801. }
  2802. var knode = K(node);
  2803. if (_inPreElement(knode)) {
  2804. return;
  2805. }
  2806. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2807. var parent;
  2808. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2809. knode = parent;
  2810. }
  2811. _wrapNode(knode, wrapper);
  2812. }
  2813. }
  2814. });
  2815. range.moveToBookmark(bookmark);
  2816. return self;
  2817. },
  2818. split : function(isStart, map) {
  2819. var range = this.range, doc = range.doc;
  2820. var tempRange = range.cloneRange().collapse(isStart);
  2821. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2822. parent = node.nodeType == 3 ? node.parentNode : node,
  2823. needSplit = false, knode;
  2824. while (parent && parent.parentNode) {
  2825. knode = K(parent);
  2826. if (map) {
  2827. if (!knode.isStyle()) {
  2828. break;
  2829. }
  2830. if (!_hasAttrOrCss(knode, map)) {
  2831. break;
  2832. }
  2833. } else {
  2834. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2835. break;
  2836. }
  2837. }
  2838. needSplit = true;
  2839. parent = parent.parentNode;
  2840. }
  2841. if (needSplit) {
  2842. var dummy = doc.createElement('span');
  2843. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2844. if (isStart) {
  2845. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2846. } else {
  2847. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2848. }
  2849. var frag = tempRange.extractContents(),
  2850. first = frag.firstChild, last = frag.lastChild;
  2851. if (isStart) {
  2852. tempRange.insertNode(frag);
  2853. range.setStartAfter(last).setEndBefore(dummy);
  2854. } else {
  2855. parent.appendChild(frag);
  2856. range.setStartBefore(dummy).setEndBefore(first);
  2857. }
  2858. var dummyParent = dummy.parentNode;
  2859. if (dummyParent == range.endContainer) {
  2860. var prev = K(dummy).prev(), next = K(dummy).next();
  2861. if (prev && next && prev.type == 3 && next.type == 3) {
  2862. range.setEnd(prev[0], prev[0].nodeValue.length);
  2863. } else if (!isStart) {
  2864. range.setEnd(range.endContainer, range.endOffset - 1);
  2865. }
  2866. }
  2867. dummyParent.removeChild(dummy);
  2868. }
  2869. return this;
  2870. },
  2871. remove : function(map) {
  2872. var self = this, doc = self.doc, range = self.range;
  2873. range.enlarge();
  2874. if (range.startOffset === 0) {
  2875. var ksc = K(range.startContainer), parent;
  2876. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2877. ksc = parent;
  2878. }
  2879. range.setStart(ksc[0], 0);
  2880. ksc = K(range.startContainer);
  2881. if (ksc.isBlock()) {
  2882. _removeAttrOrCss(ksc, map);
  2883. }
  2884. var kscp = ksc.parent();
  2885. if (kscp && kscp.isBlock()) {
  2886. _removeAttrOrCss(kscp, map);
  2887. }
  2888. }
  2889. var sc, so;
  2890. if (range.collapsed) {
  2891. self.split(true, map);
  2892. sc = range.startContainer;
  2893. so = range.startOffset;
  2894. if (so > 0) {
  2895. var sb = K(sc.childNodes[so - 1]);
  2896. if (sb && _isEmptyNode(sb)) {
  2897. sb.remove();
  2898. range.setStart(sc, so - 1);
  2899. }
  2900. }
  2901. var sa = K(sc.childNodes[so]);
  2902. if (sa && _isEmptyNode(sa)) {
  2903. sa.remove();
  2904. }
  2905. if (_isEmptyNode(sc)) {
  2906. range.startBefore(sc);
  2907. sc.remove();
  2908. }
  2909. range.collapse(true);
  2910. return self;
  2911. }
  2912. self.split(true, map);
  2913. self.split(false, map);
  2914. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2915. range.cloneRange().collapse(false).insertNode(endDummy);
  2916. range.cloneRange().collapse(true).insertNode(startDummy);
  2917. var nodeList = [], cmpStart = false;
  2918. K(range.commonAncestor()).scan(function(node) {
  2919. if (!cmpStart && node == startDummy) {
  2920. cmpStart = true;
  2921. return;
  2922. }
  2923. if (node == endDummy) {
  2924. return false;
  2925. }
  2926. if (cmpStart) {
  2927. nodeList.push(node);
  2928. }
  2929. });
  2930. K(startDummy).remove();
  2931. K(endDummy).remove();
  2932. sc = range.startContainer;
  2933. so = range.startOffset;
  2934. var ec = range.endContainer, eo = range.endOffset;
  2935. if (so > 0) {
  2936. var startBefore = K(sc.childNodes[so - 1]);
  2937. if (startBefore && _isEmptyNode(startBefore)) {
  2938. startBefore.remove();
  2939. range.setStart(sc, so - 1);
  2940. if (sc == ec) {
  2941. range.setEnd(ec, eo - 1);
  2942. }
  2943. }
  2944. var startAfter = K(sc.childNodes[so]);
  2945. if (startAfter && _isEmptyNode(startAfter)) {
  2946. startAfter.remove();
  2947. if (sc == ec) {
  2948. range.setEnd(ec, eo - 1);
  2949. }
  2950. }
  2951. }
  2952. var endAfter = K(ec.childNodes[range.endOffset]);
  2953. if (endAfter && _isEmptyNode(endAfter)) {
  2954. endAfter.remove();
  2955. }
  2956. var bookmark = range.createBookmark(true);
  2957. _each(nodeList, function(i, node) {
  2958. _removeAttrOrCss(K(node), map);
  2959. });
  2960. range.moveToBookmark(bookmark);
  2961. return self;
  2962. },
  2963. commonNode : function(map) {
  2964. var range = this.range;
  2965. var ec = range.endContainer, eo = range.endOffset,
  2966. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2967. function find(node) {
  2968. var child = node, parent = node;
  2969. while (parent) {
  2970. if (_hasAttrOrCss(K(parent), map)) {
  2971. return K(parent);
  2972. }
  2973. parent = parent.parentNode;
  2974. }
  2975. while (child && (child = child.lastChild)) {
  2976. if (_hasAttrOrCss(K(child), map)) {
  2977. return K(child);
  2978. }
  2979. }
  2980. return null;
  2981. }
  2982. var cNode = find(node);
  2983. if (cNode) {
  2984. return cNode;
  2985. }
  2986. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2987. var prev = K(node).prev();
  2988. if (prev) {
  2989. return find(prev);
  2990. }
  2991. }
  2992. return null;
  2993. },
  2994. commonAncestor : function(tagName) {
  2995. var range = this.range,
  2996. sc = range.startContainer, so = range.startOffset,
  2997. ec = range.endContainer, eo = range.endOffset,
  2998. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2999. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3000. function find(node) {
  3001. while (node) {
  3002. if (node.nodeType == 1) {
  3003. if (node.tagName.toLowerCase() === tagName) {
  3004. return node;
  3005. }
  3006. }
  3007. node = node.parentNode;
  3008. }
  3009. return null;
  3010. }
  3011. var start = find(startNode), end = find(endNode);
  3012. if (start && end && start === end) {
  3013. return K(start);
  3014. }
  3015. return null;
  3016. },
  3017. state : function(key) {
  3018. var self = this, doc = self.doc, bool = false;
  3019. try {
  3020. bool = doc.queryCommandState(key);
  3021. } catch (e) {}
  3022. return bool;
  3023. },
  3024. val : function(key) {
  3025. var self = this, doc = self.doc, range = self.range;
  3026. function lc(val) {
  3027. return val.toLowerCase();
  3028. }
  3029. key = lc(key);
  3030. var val = '', knode;
  3031. if (key === 'fontfamily' || key === 'fontname') {
  3032. val = _nativeCommandValue(doc, 'fontname');
  3033. val = val.replace(/['"]/g, '');
  3034. return lc(val);
  3035. }
  3036. if (key === 'formatblock') {
  3037. val = _nativeCommandValue(doc, key);
  3038. if (val === '') {
  3039. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3040. if (knode) {
  3041. val = knode.name;
  3042. }
  3043. }
  3044. if (val === 'Normal') {
  3045. val = 'p';
  3046. }
  3047. return lc(val);
  3048. }
  3049. if (key === 'fontsize') {
  3050. knode = self.commonNode({'*' : '.font-size'});
  3051. if (knode) {
  3052. val = knode.css('font-size');
  3053. }
  3054. return lc(val);
  3055. }
  3056. if (key === 'forecolor') {
  3057. knode = self.commonNode({'*' : '.color'});
  3058. if (knode) {
  3059. val = knode.css('color');
  3060. }
  3061. val = _toHex(val);
  3062. if (val === '') {
  3063. val = 'default';
  3064. }
  3065. return lc(val);
  3066. }
  3067. if (key === 'hilitecolor') {
  3068. knode = self.commonNode({'*' : '.background-color'});
  3069. if (knode) {
  3070. val = knode.css('background-color');
  3071. }
  3072. val = _toHex(val);
  3073. if (val === '') {
  3074. val = 'default';
  3075. }
  3076. return lc(val);
  3077. }
  3078. return val;
  3079. },
  3080. toggle : function(wrapper, map) {
  3081. var self = this;
  3082. if (self.commonNode(map)) {
  3083. self.remove(map);
  3084. } else {
  3085. self.wrap(wrapper);
  3086. }
  3087. return self.select();
  3088. },
  3089. bold : function() {
  3090. return this.toggle('<strong></strong>', {
  3091. span : '.font-weight=bold',
  3092. strong : '*',
  3093. b : '*'
  3094. });
  3095. },
  3096. italic : function() {
  3097. return this.toggle('<em></em>', {
  3098. span : '.font-style=italic',
  3099. em : '*',
  3100. i : '*'
  3101. });
  3102. },
  3103. underline : function() {
  3104. return this.toggle('<u></u>', {
  3105. span : '.text-decoration=underline',
  3106. u : '*'
  3107. });
  3108. },
  3109. strikethrough : function() {
  3110. return this.toggle('<s></s>', {
  3111. span : '.text-decoration=line-through',
  3112. s : '*'
  3113. });
  3114. },
  3115. forecolor : function(val) {
  3116. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3117. },
  3118. hilitecolor : function(val) {
  3119. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3120. },
  3121. fontsize : function(val) {
  3122. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3123. },
  3124. fontname : function(val) {
  3125. return this.fontfamily(val);
  3126. },
  3127. fontfamily : function(val) {
  3128. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3129. },
  3130. removeformat : function() {
  3131. var map = {
  3132. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3133. },
  3134. tags = _STYLE_TAG_MAP;
  3135. _each(tags, function(key, val) {
  3136. map[key] = '*';
  3137. });
  3138. this.remove(map);
  3139. return this.select();
  3140. },
  3141. inserthtml : function(val, quickMode) {
  3142. var self = this, range = self.range;
  3143. if (val === '') {
  3144. return self;
  3145. }
  3146. function pasteHtml(range, val) {
  3147. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3148. var rng = range.get();
  3149. if (rng.item) {
  3150. rng.item(0).outerHTML = val;
  3151. } else {
  3152. rng.pasteHTML(val);
  3153. }
  3154. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3155. temp.parentNode.removeChild(temp);
  3156. var newRange = _toRange(rng);
  3157. range.setEnd(newRange.endContainer, newRange.endOffset);
  3158. range.collapse(false);
  3159. self.select(false);
  3160. }
  3161. function insertHtml(range, val) {
  3162. var doc = range.doc,
  3163. frag = doc.createDocumentFragment();
  3164. K('@' + val, doc).each(function() {
  3165. frag.appendChild(this);
  3166. });
  3167. range.deleteContents();
  3168. range.insertNode(frag);
  3169. range.collapse(false);
  3170. self.select(false);
  3171. }
  3172. if (_IERANGE && quickMode) {
  3173. try {
  3174. pasteHtml(range, val);
  3175. } catch(e) {
  3176. insertHtml(range, val);
  3177. }
  3178. return self;
  3179. }
  3180. insertHtml(range, val);
  3181. return self;
  3182. },
  3183. hr : function() {
  3184. return this.inserthtml('<hr />');
  3185. },
  3186. print : function() {
  3187. this.win.print();
  3188. return this;
  3189. },
  3190. insertimage : function(url, title, width, height, border, align) {
  3191. title = _undef(title, '');
  3192. border = _undef(border, 0);
  3193. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3194. if (width) {
  3195. html += 'width="' + _escape(width) + '" ';
  3196. }
  3197. if (height) {
  3198. html += 'height="' + _escape(height) + '" ';
  3199. }
  3200. if (title) {
  3201. html += 'title="' + _escape(title) + '" ';
  3202. }
  3203. if (align) {
  3204. html += 'align="' + _escape(align) + '" ';
  3205. }
  3206. html += 'alt="' + _escape(title) + '" ';
  3207. html += '/>';
  3208. return this.inserthtml(html);
  3209. },
  3210. createlink : function(url, type) {
  3211. var self = this, doc = self.doc, range = self.range;
  3212. self.select();
  3213. var a = self.commonNode({ a : '*' });
  3214. if (a && !range.isControl()) {
  3215. range.selectNode(a.get());
  3216. self.select();
  3217. }
  3218. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3219. if (type) {
  3220. html += ' target="' + _escape(type) + '"';
  3221. }
  3222. if (range.collapsed) {
  3223. html += '>' + _escape(url) + '</a>';
  3224. return self.inserthtml(html);
  3225. }
  3226. if (range.isControl()) {
  3227. var node = K(range.startContainer.childNodes[range.startOffset]);
  3228. html += '></a>';
  3229. node.after(K(html, doc));
  3230. node.next().append(node);
  3231. range.selectNode(node[0]);
  3232. return self.select();
  3233. }
  3234. function setAttr(node, url, type) {
  3235. K(node).attr('href', url).attr('data-ke-src', url);
  3236. if (type) {
  3237. K(node).attr('target', type);
  3238. } else {
  3239. K(node).removeAttr('target');
  3240. }
  3241. }
  3242. var sc = range.startContainer, so = range.startOffset,
  3243. ec = range.endContainer, eo = range.endOffset;
  3244. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3245. var child = sc.childNodes[so];
  3246. if (child.nodeName.toLowerCase() == 'a') {
  3247. setAttr(child, url, type);
  3248. return self;
  3249. }
  3250. }
  3251. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3252. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3253. setAttr(this, url, type);
  3254. });
  3255. return self;
  3256. },
  3257. unlink : function() {
  3258. var self = this, doc = self.doc, range = self.range;
  3259. self.select();
  3260. if (range.collapsed) {
  3261. var a = self.commonNode({ a : '*' });
  3262. if (a) {
  3263. range.selectNode(a.get());
  3264. self.select();
  3265. }
  3266. _nativeCommand(doc, 'unlink', null);
  3267. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3268. var parent = K(range.startContainer).parent();
  3269. if (parent.name === 'a') {
  3270. parent.remove(true);
  3271. }
  3272. }
  3273. } else {
  3274. _nativeCommand(doc, 'unlink', null);
  3275. }
  3276. return self;
  3277. }
  3278. });
  3279. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3280. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3281. KCmd.prototype[name] = function(val) {
  3282. var self = this;
  3283. self.select();
  3284. _nativeCommand(self.doc, name, val);
  3285. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3286. self.selection();
  3287. }
  3288. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3289. self.selection();
  3290. }
  3291. return self;
  3292. };
  3293. });
  3294. _each('cut,copy,paste'.split(','), function(i, name) {
  3295. KCmd.prototype[name] = function() {
  3296. var self = this;
  3297. if (!self.doc.queryCommandSupported(name)) {
  3298. throw 'not supported';
  3299. }
  3300. self.select();
  3301. _nativeCommand(self.doc, name, null);
  3302. return self;
  3303. };
  3304. });
  3305. function _cmd(mixed) {
  3306. if (mixed.nodeName) {
  3307. var doc = _getDoc(mixed);
  3308. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3309. }
  3310. return new KCmd(mixed);
  3311. }
  3312. K.CmdClass = KCmd;
  3313. K.cmd = _cmd;
  3314. function _drag(options) {
  3315. var moveEl = options.moveEl,
  3316. moveFn = options.moveFn,
  3317. clickEl = options.clickEl || moveEl,
  3318. beforeDrag = options.beforeDrag,
  3319. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3320. var docs = [document];
  3321. if (iframeFix) {
  3322. K('iframe').each(function() {
  3323. var src = _formatUrl(this.src || '', 'absolute');
  3324. if (/^https?:\/\//.test(src)) {
  3325. return;
  3326. }
  3327. var doc;
  3328. try {
  3329. doc = _iframeDoc(this);
  3330. } catch(e) {}
  3331. if (doc) {
  3332. var pos = K(this).pos();
  3333. K(doc).data('pos-x', pos.x);
  3334. K(doc).data('pos-y', pos.y);
  3335. docs.push(doc);
  3336. }
  3337. });
  3338. }
  3339. clickEl.mousedown(function(e) {
  3340. if(e.button !== 0 && e.button !== 1) {
  3341. return;
  3342. }
  3343. e.stopPropagation();
  3344. var self = clickEl.get(),
  3345. x = _removeUnit(moveEl.css('left')),
  3346. y = _removeUnit(moveEl.css('top')),
  3347. width = moveEl.width(),
  3348. height = moveEl.height(),
  3349. pageX = e.pageX,
  3350. pageY = e.pageY;
  3351. if (beforeDrag) {
  3352. beforeDrag();
  3353. }
  3354. function moveListener(e) {
  3355. e.preventDefault();
  3356. var kdoc = K(_getDoc(e.target));
  3357. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3358. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3359. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3360. }
  3361. function selectListener(e) {
  3362. e.preventDefault();
  3363. }
  3364. function upListener(e) {
  3365. e.preventDefault();
  3366. K(docs).unbind('mousemove', moveListener)
  3367. .unbind('mouseup', upListener)
  3368. .unbind('selectstart', selectListener);
  3369. if (self.releaseCapture) {
  3370. self.releaseCapture();
  3371. }
  3372. }
  3373. K(docs).mousemove(moveListener)
  3374. .mouseup(upListener)
  3375. .bind('selectstart', selectListener);
  3376. if (self.setCapture) {
  3377. self.setCapture();
  3378. }
  3379. });
  3380. }
  3381. function KWidget(options) {
  3382. this.init(options);
  3383. }
  3384. _extend(KWidget, {
  3385. init : function(options) {
  3386. var self = this;
  3387. self.name = options.name || '';
  3388. self.doc = options.doc || document;
  3389. self.win = _getWin(self.doc);
  3390. self.x = _addUnit(options.x);
  3391. self.y = _addUnit(options.y);
  3392. self.z = options.z;
  3393. self.width = _addUnit(options.width);
  3394. self.height = _addUnit(options.height);
  3395. self.index = _addUnit(options.index);
  3396. self.div = K('<div style="display:block;"></div>');
  3397. self.options = options;
  3398. self._alignEl = options.alignEl;
  3399. if (self.width) {
  3400. self.div.css('width', self.width);
  3401. }
  3402. if (self.height) {
  3403. self.div.css('height', self.height);
  3404. }
  3405. if (self.z) {
  3406. self.div.css({
  3407. position : 'absolute',
  3408. left : self.x,
  3409. top : self.y,
  3410. 'z-index' : self.z
  3411. });
  3412. }
  3413. if (self.z && (self.x === undefined || self.y === undefined)) {
  3414. self.autoPos(self.width, self.height);
  3415. }
  3416. if (options.cls) {
  3417. self.div.addClass(options.cls);
  3418. }
  3419. if (options.shadowMode) {
  3420. self.div.addClass('ke-shadow');
  3421. }
  3422. if (options.css) {
  3423. self.div.css(options.css);
  3424. }
  3425. if (options.src) {
  3426. K(options.src).replaceWith(self.div);
  3427. } else {
  3428. K(self.doc.body).append(self.div);
  3429. }
  3430. if (options.html) {
  3431. self.div.html(options.html);
  3432. }
  3433. if (options.autoScroll) {
  3434. if (_IE && _V < 7 || _QUIRKS) {
  3435. var scrollPos = _getScrollPos();
  3436. K(self.win).bind('scroll', function(e) {
  3437. var pos = _getScrollPos(),
  3438. diffX = pos.x - scrollPos.x,
  3439. diffY = pos.y - scrollPos.y;
  3440. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3441. });
  3442. } else {
  3443. self.div.css('position', 'fixed');
  3444. }
  3445. }
  3446. },
  3447. pos : function(x, y, updateProp) {
  3448. var self = this;
  3449. updateProp = _undef(updateProp, true);
  3450. if (x !== null) {
  3451. x = x < 0 ? 0 : _addUnit(x);
  3452. self.div.css('left', x);
  3453. if (updateProp) {
  3454. self.x = x;
  3455. }
  3456. }
  3457. if (y !== null) {
  3458. y = y < 0 ? 0 : _addUnit(y);
  3459. self.div.css('top', y);
  3460. if (updateProp) {
  3461. self.y = y;
  3462. }
  3463. }
  3464. return self;
  3465. },
  3466. autoPos : function(width, height) {
  3467. var x, y, self = this,
  3468. w = _removeUnit(width) || 0,
  3469. h = _removeUnit(height) || 0,
  3470. scrollPos = _getScrollPos();
  3471. if (self._alignEl) {
  3472. var knode = K(self._alignEl),
  3473. pos = knode.pos(),
  3474. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3475. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3476. x = diffX < 0 ? pos.x : pos.x + diffX;
  3477. y = diffY < 0 ? pos.y : pos.y + diffY;
  3478. } else {
  3479. var docEl = _docElement(self.doc);
  3480. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3481. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3482. }
  3483. if (!(_IE && _V < 7 || _QUIRKS)) {
  3484. x -= scrollPos.x;
  3485. y -= scrollPos.y;
  3486. }
  3487. return self.pos(x, y);
  3488. },
  3489. remove : function() {
  3490. var self = this;
  3491. if (_IE && _V < 7 || _QUIRKS) {
  3492. K(self.win).unbind('scroll');
  3493. }
  3494. self.div.remove();
  3495. _each(self, function(i) {
  3496. self[i] = null;
  3497. });
  3498. return this;
  3499. },
  3500. show : function() {
  3501. this.div.show();
  3502. return this;
  3503. },
  3504. hide : function() {
  3505. this.div.hide();
  3506. return this;
  3507. },
  3508. draggable : function(options) {
  3509. var self = this;
  3510. options = options || {};
  3511. options.moveEl = self.div;
  3512. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3513. if ((x = x + diffX) < 0) {
  3514. x = 0;
  3515. }
  3516. if ((y = y + diffY) < 0) {
  3517. y = 0;
  3518. }
  3519. self.pos(x, y);
  3520. };
  3521. _drag(options);
  3522. return self;
  3523. }
  3524. });
  3525. function _widget(options) {
  3526. return new KWidget(options);
  3527. }
  3528. K.WidgetClass = KWidget;
  3529. K.widget = _widget;
  3530. function _iframeDoc(iframe) {
  3531. iframe = _get(iframe);
  3532. return iframe.contentDocument || iframe.contentWindow.document;
  3533. }
  3534. var html, _direction = '';
  3535. if ((html = document.getElementsByTagName('html'))) {
  3536. _direction = html[0].dir;
  3537. }
  3538. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3539. var arr = [
  3540. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3541. '<head><meta charset="utf-8" /><title></title>',
  3542. '<style>',
  3543. 'html {margin:0;padding:0;}',
  3544. 'body {margin:0;padding:5px;}',
  3545. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3546. 'body, p, div {word-wrap: break-word;}',
  3547. 'p {margin:5px 0;}',
  3548. 'table {border-collapse:collapse;}',
  3549. 'img {border:0;}',
  3550. 'noscript {display:none;}',
  3551. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3552. 'img.ke-flash {',
  3553. ' border:1px solid #AAA;',
  3554. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3555. ' background-position:center center;',
  3556. ' background-repeat:no-repeat;',
  3557. ' width:100px;',
  3558. ' height:100px;',
  3559. '}',
  3560. 'img.ke-rm {',
  3561. ' border:1px solid #AAA;',
  3562. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3563. ' background-position:center center;',
  3564. ' background-repeat:no-repeat;',
  3565. ' width:100px;',
  3566. ' height:100px;',
  3567. '}',
  3568. 'img.ke-media {',
  3569. ' border:1px solid #AAA;',
  3570. ' background-image:url(' + themesPath + 'common/media.gif);',
  3571. ' background-position:center center;',
  3572. ' background-repeat:no-repeat;',
  3573. ' width:100px;',
  3574. ' height:100px;',
  3575. '}',
  3576. 'img.ke-anchor {',
  3577. ' border:1px dashed #666;',
  3578. ' width:16px;',
  3579. ' height:16px;',
  3580. '}',
  3581. '.ke-script, .ke-noscript, .ke-display-none {',
  3582. ' display:none;',
  3583. ' font-size:0;',
  3584. ' width:0;',
  3585. ' height:0;',
  3586. '}',
  3587. '.ke-pagebreak {',
  3588. ' border:1px dotted #AAA;',
  3589. ' font-size:0;',
  3590. ' height:2px;',
  3591. '}',
  3592. '</style>'
  3593. ];
  3594. if (!_isArray(cssPath)) {
  3595. cssPath = [cssPath];
  3596. }
  3597. _each(cssPath, function(i, path) {
  3598. if (path) {
  3599. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3600. }
  3601. });
  3602. if (cssData) {
  3603. arr.push('<style>' + cssData + '</style>');
  3604. }
  3605. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3606. return arr.join('\n');
  3607. }
  3608. function _elementVal(knode, val) {
  3609. if (knode.hasVal()) {
  3610. if (val === undefined) {
  3611. var html = knode.val();
  3612. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3613. return html;
  3614. }
  3615. return knode.val(val);
  3616. }
  3617. return knode.html(val);
  3618. }
  3619. function KEdit(options) {
  3620. this.init(options);
  3621. }
  3622. _extend(KEdit, KWidget, {
  3623. init : function(options) {
  3624. var self = this;
  3625. KEdit.parent.init.call(self, options);
  3626. self.srcElement = K(options.srcElement);
  3627. self.div.addClass('ke-edit');
  3628. self.designMode = _undef(options.designMode, true);
  3629. self.beforeGetHtml = options.beforeGetHtml;
  3630. self.beforeSetHtml = options.beforeSetHtml;
  3631. self.afterSetHtml = options.afterSetHtml;
  3632. var themesPath = _undef(options.themesPath, ''),
  3633. bodyClass = options.bodyClass,
  3634. cssPath = options.cssPath,
  3635. cssData = options.cssData,
  3636. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3637. srcScript = ('document.open();' +
  3638. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3639. 'document.close();'),
  3640. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3641. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3642. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3643. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3644. self.iframe.attr('tabindex', self.tabIndex);
  3645. self.textarea.attr('tabindex', self.tabIndex);
  3646. if (self.width) {
  3647. self.setWidth(self.width);
  3648. }
  3649. if (self.height) {
  3650. self.setHeight(self.height);
  3651. }
  3652. if (self.designMode) {
  3653. self.textarea.hide();
  3654. } else {
  3655. self.iframe.hide();
  3656. }
  3657. function ready() {
  3658. var doc = _iframeDoc(self.iframe);
  3659. doc.open();
  3660. if (isDocumentDomain) {
  3661. doc.domain = document.domain;
  3662. }
  3663. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3664. doc.close();
  3665. self.win = self.iframe[0].contentWindow;
  3666. self.doc = doc;
  3667. var cmd = _cmd(doc);
  3668. self.afterChange(function(e) {
  3669. cmd.selection();
  3670. });
  3671. if (_WEBKIT) {
  3672. K(doc).click(function(e) {
  3673. if (K(e.target).name === 'img') {
  3674. cmd.selection(true);
  3675. cmd.range.selectNode(e.target);
  3676. cmd.select();
  3677. }
  3678. });
  3679. }
  3680. if (_IE) {
  3681. self._mousedownHandler = function() {
  3682. var newRange = cmd.range.cloneRange();
  3683. newRange.shrink();
  3684. if (newRange.isControl()) {
  3685. self.blur();
  3686. }
  3687. };
  3688. K(document).mousedown(self._mousedownHandler);
  3689. K(doc).keydown(function(e) {
  3690. if (e.which == 8) {
  3691. cmd.selection();
  3692. var rng = cmd.range;
  3693. if (rng.isControl()) {
  3694. rng.collapse(true);
  3695. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3696. e.preventDefault();
  3697. }
  3698. }
  3699. });
  3700. }
  3701. self.cmd = cmd;
  3702. self.html(_elementVal(self.srcElement));
  3703. if (_IE) {
  3704. doc.body.disabled = true;
  3705. doc.body.contentEditable = true;
  3706. doc.body.removeAttribute('disabled');
  3707. } else {
  3708. doc.designMode = 'on';
  3709. }
  3710. if (options.afterCreate) {
  3711. options.afterCreate.call(self);
  3712. }
  3713. }
  3714. if (isDocumentDomain) {
  3715. self.iframe.bind('load', function(e) {
  3716. self.iframe.unbind('load');
  3717. if (_IE) {
  3718. ready();
  3719. } else {
  3720. setTimeout(ready, 0);
  3721. }
  3722. });
  3723. }
  3724. self.div.append(self.iframe);
  3725. self.div.append(self.textarea);
  3726. self.srcElement.hide();
  3727. !isDocumentDomain && ready();
  3728. },
  3729. setWidth : function(val) {
  3730. var self = this;
  3731. val = _addUnit(val);
  3732. self.width = val;
  3733. self.div.css('width', val);
  3734. return self;
  3735. },
  3736. setHeight : function(val) {
  3737. var self = this;
  3738. val = _addUnit(val);
  3739. self.height = val;
  3740. self.div.css('height', val);
  3741. self.iframe.css('height', val);
  3742. if ((_IE && _V < 8) || _QUIRKS) {
  3743. val = _addUnit(_removeUnit(val) - 2);
  3744. }
  3745. self.textarea.css('height', val);
  3746. return self;
  3747. },
  3748. remove : function() {
  3749. var self = this, doc = self.doc;
  3750. K(doc.body).unbind();
  3751. K(doc).unbind();
  3752. K(self.win).unbind();
  3753. if (self._mousedownHandler) {
  3754. K(document).unbind('mousedown', self._mousedownHandler);
  3755. }
  3756. _elementVal(self.srcElement, self.html());
  3757. self.srcElement.show();
  3758. self.iframe.unbind();
  3759. self.textarea.unbind();
  3760. KEdit.parent.remove.call(self);
  3761. },
  3762. html : function(val, isFull) {
  3763. var self = this, doc = self.doc;
  3764. if (self.designMode) {
  3765. var body = doc.body;
  3766. if (val === undefined) {
  3767. if (isFull) {
  3768. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3769. } else {
  3770. val = body.innerHTML;
  3771. }
  3772. if (self.beforeGetHtml) {
  3773. val = self.beforeGetHtml(val);
  3774. }
  3775. if (_GECKO && val == '<br />') {
  3776. val = '';
  3777. }
  3778. return val;
  3779. }
  3780. if (self.beforeSetHtml) {
  3781. val = self.beforeSetHtml(val);
  3782. }
  3783. if (_IE && _V >= 9) {
  3784. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3785. }
  3786. K(body).html(val);
  3787. if (self.afterSetHtml) {
  3788. self.afterSetHtml();
  3789. }
  3790. return self;
  3791. }
  3792. if (val === undefined) {
  3793. return self.textarea.val();
  3794. }
  3795. self.textarea.val(val);
  3796. return self;
  3797. },
  3798. design : function(bool) {
  3799. var self = this, val;
  3800. if (bool === undefined ? !self.designMode : bool) {
  3801. if (!self.designMode) {
  3802. val = self.html();
  3803. self.designMode = true;
  3804. self.textarea.hide();
  3805. self.html(val);
  3806. var iframe = self.iframe;
  3807. var height = _removeUnit(self.height);
  3808. iframe.height(height - 2);
  3809. iframe.show();
  3810. setTimeout(function() {
  3811. iframe.height(height);
  3812. }, 0);
  3813. }
  3814. } else {
  3815. if (self.designMode) {
  3816. val = self.html();
  3817. self.designMode = false;
  3818. self.html(val);
  3819. self.iframe.hide();
  3820. self.textarea.show();
  3821. }
  3822. }
  3823. return self.focus();
  3824. },
  3825. focus : function() {
  3826. var self = this;
  3827. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3828. return self;
  3829. },
  3830. blur : function() {
  3831. var self = this;
  3832. if (_IE) {
  3833. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3834. self.div.append(input);
  3835. input[0].focus();
  3836. input.remove();
  3837. } else {
  3838. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3839. }
  3840. return self;
  3841. },
  3842. afterChange : function(fn) {
  3843. var self = this, doc = self.doc, body = doc.body;
  3844. K(doc).keyup(function(e) {
  3845. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3846. fn(e);
  3847. }
  3848. });
  3849. K(doc).mouseup(fn).contextmenu(fn);
  3850. K(self.win).blur(fn);
  3851. function timeoutHandler(e) {
  3852. setTimeout(function() {
  3853. fn(e);
  3854. }, 1);
  3855. }
  3856. K(body).bind('paste', timeoutHandler);
  3857. K(body).bind('cut', timeoutHandler);
  3858. return self;
  3859. }
  3860. });
  3861. function _edit(options) {
  3862. return new KEdit(options);
  3863. }
  3864. K.EditClass = KEdit;
  3865. K.edit = _edit;
  3866. K.iframeDoc = _iframeDoc;
  3867. function _selectToolbar(name, fn) {
  3868. var self = this,
  3869. knode = self.get(name);
  3870. if (knode) {
  3871. if (knode.hasClass('ke-disabled')) {
  3872. return;
  3873. }
  3874. fn(knode);
  3875. }
  3876. }
  3877. function KToolbar(options) {
  3878. this.init(options);
  3879. }
  3880. _extend(KToolbar, KWidget, {
  3881. init : function(options) {
  3882. var self = this;
  3883. KToolbar.parent.init.call(self, options);
  3884. self.disableMode = _undef(options.disableMode, false);
  3885. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3886. self._itemMap = {};
  3887. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3888. e.preventDefault();
  3889. }).attr('unselectable', 'on');
  3890. function find(target) {
  3891. var knode = K(target);
  3892. if (knode.hasClass('ke-outline')) {
  3893. return knode;
  3894. }
  3895. if (knode.hasClass('ke-toolbar-icon')) {
  3896. return knode.parent();
  3897. }
  3898. }
  3899. function hover(e, method) {
  3900. var knode = find(e.target);
  3901. if (knode) {
  3902. if (knode.hasClass('ke-disabled')) {
  3903. return;
  3904. }
  3905. if (knode.hasClass('ke-selected')) {
  3906. return;
  3907. }
  3908. knode[method]('ke-on');
  3909. }
  3910. }
  3911. self.div.mouseover(function(e) {
  3912. hover(e, 'addClass');
  3913. })
  3914. .mouseout(function(e) {
  3915. hover(e, 'removeClass');
  3916. })
  3917. .click(function(e) {
  3918. var knode = find(e.target);
  3919. if (knode) {
  3920. if (knode.hasClass('ke-disabled')) {
  3921. return;
  3922. }
  3923. self.options.click.call(this, e, knode.attr('data-name'));
  3924. }
  3925. });
  3926. },
  3927. get : function(name) {
  3928. if (this._itemMap[name]) {
  3929. return this._itemMap[name];
  3930. }
  3931. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3932. },
  3933. select : function(name) {
  3934. _selectToolbar.call(this, name, function(knode) {
  3935. knode.addClass('ke-selected');
  3936. });
  3937. return self;
  3938. },
  3939. unselect : function(name) {
  3940. _selectToolbar.call(this, name, function(knode) {
  3941. knode.removeClass('ke-selected').removeClass('ke-on');
  3942. });
  3943. return self;
  3944. },
  3945. enable : function(name) {
  3946. var self = this,
  3947. knode = name.get ? name : self.get(name);
  3948. if (knode) {
  3949. knode.removeClass('ke-disabled');
  3950. knode.opacity(1);
  3951. }
  3952. return self;
  3953. },
  3954. disable : function(name) {
  3955. var self = this,
  3956. knode = name.get ? name : self.get(name);
  3957. if (knode) {
  3958. knode.removeClass('ke-selected').addClass('ke-disabled');
  3959. knode.opacity(0.5);
  3960. }
  3961. return self;
  3962. },
  3963. disableAll : function(bool, noDisableItems) {
  3964. var self = this, map = self.noDisableItemMap, item;
  3965. if (noDisableItems) {
  3966. map = _toMap(noDisableItems);
  3967. }
  3968. if (bool === undefined ? !self.disableMode : bool) {
  3969. K('span.ke-outline', self.div).each(function() {
  3970. var knode = K(this),
  3971. name = knode[0].getAttribute('data-name', 2);
  3972. if (!map[name]) {
  3973. self.disable(knode);
  3974. }
  3975. });
  3976. self.disableMode = true;
  3977. } else {
  3978. K('span.ke-outline', self.div).each(function() {
  3979. var knode = K(this),
  3980. name = knode[0].getAttribute('data-name', 2);
  3981. if (!map[name]) {
  3982. self.enable(knode);
  3983. }
  3984. });
  3985. self.disableMode = false;
  3986. }
  3987. return self;
  3988. }
  3989. });
  3990. function _toolbar(options) {
  3991. return new KToolbar(options);
  3992. }
  3993. K.ToolbarClass = KToolbar;
  3994. K.toolbar = _toolbar;
  3995. function KMenu(options) {
  3996. this.init(options);
  3997. }
  3998. _extend(KMenu, KWidget, {
  3999. init : function(options) {
  4000. var self = this;
  4001. options.z = options.z || 811213;
  4002. KMenu.parent.init.call(self, options);
  4003. self.centerLineMode = _undef(options.centerLineMode, true);
  4004. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4005. e.stopPropagation();
  4006. }).attr('unselectable', 'on');
  4007. },
  4008. addItem : function(item) {
  4009. var self = this;
  4010. if (item.title === '-') {
  4011. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4012. return;
  4013. }
  4014. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4015. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4016. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4017. height = _addUnit(item.height),
  4018. iconClass = _undef(item.iconClass, '');
  4019. self.div.append(itemDiv);
  4020. if (height) {
  4021. itemDiv.css('height', height);
  4022. rightDiv.css('line-height', height);
  4023. }
  4024. var centerDiv;
  4025. if (self.centerLineMode) {
  4026. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4027. if (height) {
  4028. centerDiv.css('height', height);
  4029. }
  4030. }
  4031. itemDiv.mouseover(function(e) {
  4032. K(this).addClass('ke-menu-item-on');
  4033. if (centerDiv) {
  4034. centerDiv.addClass('ke-menu-item-center-on');
  4035. }
  4036. })
  4037. .mouseout(function(e) {
  4038. K(this).removeClass('ke-menu-item-on');
  4039. if (centerDiv) {
  4040. centerDiv.removeClass('ke-menu-item-center-on');
  4041. }
  4042. })
  4043. .click(function(e) {
  4044. item.click.call(K(this));
  4045. e.stopPropagation();
  4046. })
  4047. .append(leftDiv);
  4048. if (centerDiv) {
  4049. itemDiv.append(centerDiv);
  4050. }
  4051. itemDiv.append(rightDiv);
  4052. if (item.checked) {
  4053. iconClass = 'ke-icon-checked';
  4054. }
  4055. if (iconClass !== '') {
  4056. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4057. }
  4058. rightDiv.html(item.title);
  4059. return self;
  4060. },
  4061. remove : function() {
  4062. var self = this;
  4063. if (self.options.beforeRemove) {
  4064. self.options.beforeRemove.call(self);
  4065. }
  4066. K('.ke-menu-item', self.div[0]).unbind();
  4067. KMenu.parent.remove.call(self);
  4068. return self;
  4069. }
  4070. });
  4071. function _menu(options) {
  4072. return new KMenu(options);
  4073. }
  4074. K.MenuClass = KMenu;
  4075. K.menu = _menu;
  4076. function KColorPicker(options) {
  4077. this.init(options);
  4078. }
  4079. _extend(KColorPicker, KWidget, {
  4080. init : function(options) {
  4081. var self = this;
  4082. options.z = options.z || 811213;
  4083. KColorPicker.parent.init.call(self, options);
  4084. var colors = options.colors || [
  4085. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4086. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4087. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4088. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4089. ];
  4090. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4091. self._cells = [];
  4092. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4093. e.stopPropagation();
  4094. }).attr('unselectable', 'on');
  4095. var table = self.doc.createElement('table');
  4096. self.div.append(table);
  4097. table.className = 'ke-colorpicker-table';
  4098. table.cellPadding = 0;
  4099. table.cellSpacing = 0;
  4100. table.border = 0;
  4101. var row = table.insertRow(0), cell = row.insertCell(0);
  4102. cell.colSpan = colors[0].length;
  4103. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4104. for (var i = 0; i < colors.length; i++) {
  4105. row = table.insertRow(i + 1);
  4106. for (var j = 0; j < colors[i].length; j++) {
  4107. cell = row.insertCell(j);
  4108. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4109. }
  4110. }
  4111. },
  4112. _addAttr : function(cell, color, cls) {
  4113. var self = this;
  4114. cell = K(cell).addClass(cls);
  4115. if (self.selectedColor === color.toLowerCase()) {
  4116. cell.addClass('ke-colorpicker-cell-selected');
  4117. }
  4118. cell.attr('title', color || self.options.noColor);
  4119. cell.mouseover(function(e) {
  4120. K(this).addClass('ke-colorpicker-cell-on');
  4121. });
  4122. cell.mouseout(function(e) {
  4123. K(this).removeClass('ke-colorpicker-cell-on');
  4124. });
  4125. cell.click(function(e) {
  4126. e.stop();
  4127. self.options.click.call(K(this), color);
  4128. });
  4129. if (color) {
  4130. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4131. } else {
  4132. cell.html(self.options.noColor);
  4133. }
  4134. K(cell).attr('unselectable', 'on');
  4135. self._cells.push(cell);
  4136. },
  4137. remove : function() {
  4138. var self = this;
  4139. _each(self._cells, function() {
  4140. this.unbind();
  4141. });
  4142. KColorPicker.parent.remove.call(self);
  4143. return self;
  4144. }
  4145. });
  4146. function _colorpicker(options) {
  4147. return new KColorPicker(options);
  4148. }
  4149. K.ColorPickerClass = KColorPicker;
  4150. K.colorpicker = _colorpicker;
  4151. function KUploadButton(options) {
  4152. this.init(options);
  4153. }
  4154. _extend(KUploadButton, {
  4155. init : function(options) {
  4156. var self = this,
  4157. button = K(options.button),
  4158. fieldName = options.fieldName || 'file',
  4159. url = options.url || '',
  4160. title = button.val(),
  4161. extraParams = options.extraParams || {},
  4162. cls = button[0].className || '',
  4163. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4164. options.afterError = options.afterError || function(str) {
  4165. alert(str);
  4166. };
  4167. var hiddenElements = [];
  4168. for(var k in extraParams){
  4169. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4170. }
  4171. var html = [
  4172. '<div class="ke-inline-block ' + cls + '">',
  4173. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4174. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4175. '<span class="ke-button-common">',
  4176. hiddenElements.join(''),
  4177. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4178. '</span>',
  4179. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4180. (options.form ? '</div>' : '</form>'),
  4181. '</div>'].join('');
  4182. var div = K(html, button.doc);
  4183. button.hide();
  4184. button.before(div);
  4185. self.div = div;
  4186. self.button = button;
  4187. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4188. self.form = options.form ? K(options.form) : K('form', div);
  4189. self.fileBox = K('.ke-upload-file', div);
  4190. var width = options.width || K('.ke-button-common', div).width();
  4191. K('.ke-upload-area', div).width(width);
  4192. self.options = options;
  4193. },
  4194. submit : function() {
  4195. var self = this,
  4196. iframe = self.iframe;
  4197. iframe.bind('load', function() {
  4198. iframe.unbind();
  4199. var tempForm = document.createElement('form');
  4200. self.fileBox.before(tempForm);
  4201. K(tempForm).append(self.fileBox);
  4202. tempForm.reset();
  4203. K(tempForm).remove(true);
  4204. var doc = K.iframeDoc(iframe),
  4205. pre = doc.getElementsByTagName('pre')[0],
  4206. str = '', data;
  4207. if (pre) {
  4208. str = pre.innerHTML;
  4209. } else {
  4210. str = doc.body.innerHTML;
  4211. }
  4212. str = _unescape(str);
  4213. iframe[0].src = 'javascript:false';
  4214. try {
  4215. data = K.json(str);
  4216. } catch (e) {
  4217. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4218. }
  4219. if (data) {
  4220. self.options.afterUpload.call(self, data);
  4221. }
  4222. });
  4223. self.form[0].submit();
  4224. return self;
  4225. },
  4226. remove : function() {
  4227. var self = this;
  4228. if (self.fileBox) {
  4229. self.fileBox.unbind();
  4230. }
  4231. self.iframe.remove();
  4232. self.div.remove();
  4233. self.button.show();
  4234. return self;
  4235. }
  4236. });
  4237. function _uploadbutton(options) {
  4238. return new KUploadButton(options);
  4239. }
  4240. K.UploadButtonClass = KUploadButton;
  4241. K.uploadbutton = _uploadbutton;
  4242. function _createButton(arg) {
  4243. arg = arg || {};
  4244. var name = arg.name || '',
  4245. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4246. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4247. if (arg.click) {
  4248. btn.click(arg.click);
  4249. }
  4250. span.append(btn);
  4251. return span;
  4252. }
  4253. function KDialog(options) {
  4254. this.init(options);
  4255. }
  4256. _extend(KDialog, KWidget, {
  4257. init : function(options) {
  4258. var self = this;
  4259. var shadowMode = _undef(options.shadowMode, true);
  4260. options.z = options.z || 811213;
  4261. options.shadowMode = false;
  4262. options.autoScroll = _undef(options.autoScroll, true);
  4263. KDialog.parent.init.call(self, options);
  4264. var title = options.title,
  4265. body = K(options.body, self.doc),
  4266. previewBtn = options.previewBtn,
  4267. yesBtn = options.yesBtn,
  4268. noBtn = options.noBtn,
  4269. closeBtn = options.closeBtn,
  4270. showMask = _undef(options.showMask, true);
  4271. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4272. e.stopPropagation();
  4273. });
  4274. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4275. if (_IE && _V < 7) {
  4276. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4277. } else if (shadowMode) {
  4278. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4279. }
  4280. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4281. contentDiv.append(headerDiv);
  4282. headerDiv.html(title);
  4283. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4284. headerDiv.append(self.closeIcon);
  4285. self.draggable({
  4286. clickEl : headerDiv,
  4287. beforeDrag : options.beforeDrag
  4288. });
  4289. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4290. contentDiv.append(bodyDiv);
  4291. bodyDiv.append(body);
  4292. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4293. if (previewBtn || yesBtn || noBtn) {
  4294. contentDiv.append(footerDiv);
  4295. }
  4296. _each([
  4297. { btn : previewBtn, name : 'preview' },
  4298. { btn : yesBtn, name : 'yes' },
  4299. { btn : noBtn, name : 'no' }
  4300. ], function() {
  4301. if (this.btn) {
  4302. var button = _createButton(this.btn);
  4303. button.addClass('ke-dialog-' + this.name);
  4304. footerDiv.append(button);
  4305. }
  4306. });
  4307. if (self.height) {
  4308. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4309. }
  4310. self.div.width(self.div.width());
  4311. self.div.height(self.div.height());
  4312. self.mask = null;
  4313. if (showMask) {
  4314. var docEl = _docElement(self.doc),
  4315. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4316. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4317. self.mask = _widget({
  4318. x : 0,
  4319. y : 0,
  4320. z : self.z - 1,
  4321. cls : 'ke-dialog-mask',
  4322. width : docWidth,
  4323. height : docHeight
  4324. });
  4325. }
  4326. self.autoPos(self.div.width(), self.div.height());
  4327. self.footerDiv = footerDiv;
  4328. self.bodyDiv = bodyDiv;
  4329. self.headerDiv = headerDiv;
  4330. self.isLoading = false;
  4331. },
  4332. setMaskIndex : function(z) {
  4333. var self = this;
  4334. self.mask.div.css('z-index', z);
  4335. },
  4336. showLoading : function(msg) {
  4337. msg = _undef(msg, '');
  4338. var self = this, body = self.bodyDiv;
  4339. 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>')
  4340. .width(body.width()).height(body.height())
  4341. .css('top', self.headerDiv.height() + 'px');
  4342. body.css('visibility', 'hidden').after(self.loading);
  4343. self.isLoading = true;
  4344. return self;
  4345. },
  4346. hideLoading : function() {
  4347. this.loading && this.loading.remove();
  4348. this.bodyDiv.css('visibility', 'visible');
  4349. this.isLoading = false;
  4350. return this;
  4351. },
  4352. remove : function() {
  4353. var self = this;
  4354. if (self.options.beforeRemove) {
  4355. self.options.beforeRemove.call(self);
  4356. }
  4357. self.mask && self.mask.remove();
  4358. self.iframeMask && self.iframeMask.remove();
  4359. self.closeIcon.unbind();
  4360. K('input', self.div).unbind();
  4361. K('button', self.div).unbind();
  4362. self.footerDiv.unbind();
  4363. self.bodyDiv.unbind();
  4364. self.headerDiv.unbind();
  4365. K('iframe', self.div).each(function() {
  4366. K(this).remove();
  4367. });
  4368. KDialog.parent.remove.call(self);
  4369. return self;
  4370. }
  4371. });
  4372. function _dialog(options) {
  4373. return new KDialog(options);
  4374. }
  4375. K.DialogClass = KDialog;
  4376. K.dialog = _dialog;
  4377. function _tabs(options) {
  4378. var self = _widget(options),
  4379. remove = self.remove,
  4380. afterSelect = options.afterSelect,
  4381. div = self.div,
  4382. liList = [];
  4383. div.addClass('ke-tabs')
  4384. .bind('contextmenu,mousedown,mousemove', function(e) {
  4385. e.preventDefault();
  4386. });
  4387. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4388. div.append(ul);
  4389. self.add = function(tab) {
  4390. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4391. li.data('tab', tab);
  4392. liList.push(li);
  4393. ul.append(li);
  4394. };
  4395. self.selectedIndex = 0;
  4396. self.select = function(index) {
  4397. self.selectedIndex = index;
  4398. _each(liList, function(i, li) {
  4399. li.unbind();
  4400. if (i === index) {
  4401. li.addClass('ke-tabs-li-selected');
  4402. K(li.data('tab').panel).show('');
  4403. } else {
  4404. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4405. .mouseover(function() {
  4406. K(this).addClass('ke-tabs-li-on');
  4407. })
  4408. .mouseout(function() {
  4409. K(this).removeClass('ke-tabs-li-on');
  4410. })
  4411. .click(function() {
  4412. self.select(i);
  4413. });
  4414. K(li.data('tab').panel).hide();
  4415. }
  4416. });
  4417. if (afterSelect) {
  4418. afterSelect.call(self, index);
  4419. }
  4420. };
  4421. self.remove = function() {
  4422. _each(liList, function() {
  4423. this.remove();
  4424. });
  4425. ul.remove();
  4426. remove.call(self);
  4427. };
  4428. return self;
  4429. }
  4430. K.tabs = _tabs;
  4431. function _loadScript(url, fn) {
  4432. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4433. script = document.createElement('script');
  4434. head.appendChild(script);
  4435. script.src = url;
  4436. script.charset = 'utf-8';
  4437. script.onload = script.onreadystatechange = function() {
  4438. if (!this.readyState || this.readyState === 'loaded') {
  4439. if (fn) {
  4440. fn();
  4441. }
  4442. script.onload = script.onreadystatechange = null;
  4443. head.removeChild(script);
  4444. }
  4445. };
  4446. }
  4447. function _chopQuery(url) {
  4448. var index = url.indexOf('?');
  4449. return index > 0 ? url.substr(0, index) : url;
  4450. }
  4451. function _loadStyle(url) {
  4452. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4453. link = document.createElement('link'),
  4454. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4455. var links = K('link[rel="stylesheet"]', head);
  4456. for (var i = 0, len = links.length; i < len; i++) {
  4457. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4458. return;
  4459. }
  4460. }
  4461. head.appendChild(link);
  4462. link.href = url;
  4463. link.rel = 'stylesheet';
  4464. }
  4465. function _ajax(url, fn, method, param, dataType) {
  4466. method = method || 'GET';
  4467. dataType = dataType || 'json';
  4468. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4469. xhr.open(method, url, true);
  4470. xhr.onreadystatechange = function () {
  4471. if (xhr.readyState == 4 && xhr.status == 200) {
  4472. if (fn) {
  4473. var data = _trim(xhr.responseText);
  4474. if (dataType == 'json') {
  4475. data = _json(data);
  4476. }
  4477. fn(data);
  4478. }
  4479. }
  4480. };
  4481. if (method == 'POST') {
  4482. var params = [];
  4483. _each(param, function(key, val) {
  4484. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4485. });
  4486. try {
  4487. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4488. } catch (e) {}
  4489. xhr.send(params.join('&'));
  4490. } else {
  4491. xhr.send(null);
  4492. }
  4493. }
  4494. K.loadScript = _loadScript;
  4495. K.loadStyle = _loadStyle;
  4496. K.ajax = _ajax;
  4497. var _plugins = {};
  4498. function _plugin(name, fn) {
  4499. if (name === undefined) {
  4500. return _plugins;
  4501. }
  4502. if (!fn) {
  4503. return _plugins[name];
  4504. }
  4505. _plugins[name] = fn;
  4506. }
  4507. var _language = {};
  4508. function _parseLangKey(key) {
  4509. var match, ns = 'core';
  4510. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4511. ns = match[1];
  4512. key = match[2];
  4513. }
  4514. return { ns : ns, key : key };
  4515. }
  4516. function _lang(mixed, langType) {
  4517. langType = langType === undefined ? K.options.langType : langType;
  4518. if (typeof mixed === 'string') {
  4519. if (!_language[langType]) {
  4520. return 'no language';
  4521. }
  4522. var pos = mixed.length - 1;
  4523. if (mixed.substr(pos) === '.') {
  4524. return _language[langType][mixed.substr(0, pos)];
  4525. }
  4526. var obj = _parseLangKey(mixed);
  4527. return _language[langType][obj.ns][obj.key];
  4528. }
  4529. _each(mixed, function(key, val) {
  4530. var obj = _parseLangKey(key);
  4531. if (!_language[langType]) {
  4532. _language[langType] = {};
  4533. }
  4534. if (!_language[langType][obj.ns]) {
  4535. _language[langType][obj.ns] = {};
  4536. }
  4537. _language[langType][obj.ns][obj.key] = val;
  4538. });
  4539. }
  4540. function _getImageFromRange(range, fn) {
  4541. if (range.collapsed) {
  4542. return;
  4543. }
  4544. range = range.cloneRange().up();
  4545. var sc = range.startContainer, so = range.startOffset;
  4546. if (!_WEBKIT && !range.isControl()) {
  4547. return;
  4548. }
  4549. var img = K(sc.childNodes[so]);
  4550. if (!img || img.name != 'img') {
  4551. return;
  4552. }
  4553. if (fn(img)) {
  4554. return img;
  4555. }
  4556. }
  4557. function _bindContextmenuEvent() {
  4558. var self = this, doc = self.edit.doc;
  4559. K(doc).contextmenu(function(e) {
  4560. if (self.menu) {
  4561. self.hideMenu();
  4562. }
  4563. if (!self.useContextmenu) {
  4564. e.preventDefault();
  4565. return;
  4566. }
  4567. if (self._contextmenus.length === 0) {
  4568. return;
  4569. }
  4570. var maxWidth = 0, items = [];
  4571. _each(self._contextmenus, function() {
  4572. if (this.title == '-') {
  4573. items.push(this);
  4574. return;
  4575. }
  4576. if (this.cond && this.cond()) {
  4577. items.push(this);
  4578. if (this.width && this.width > maxWidth) {
  4579. maxWidth = this.width;
  4580. }
  4581. }
  4582. });
  4583. while (items.length > 0 && items[0].title == '-') {
  4584. items.shift();
  4585. }
  4586. while (items.length > 0 && items[items.length - 1].title == '-') {
  4587. items.pop();
  4588. }
  4589. var prevItem = null;
  4590. _each(items, function(i) {
  4591. if (this.title == '-' && prevItem.title == '-') {
  4592. delete items[i];
  4593. }
  4594. prevItem = this;
  4595. });
  4596. if (items.length > 0) {
  4597. e.preventDefault();
  4598. var pos = K(self.edit.iframe).pos(),
  4599. menu = _menu({
  4600. x : pos.x + e.clientX,
  4601. y : pos.y + e.clientY,
  4602. width : maxWidth,
  4603. css : { visibility: 'hidden' },
  4604. shadowMode : self.shadowMode
  4605. });
  4606. _each(items, function() {
  4607. if (this.title) {
  4608. menu.addItem(this);
  4609. }
  4610. });
  4611. var docEl = _docElement(menu.doc),
  4612. menuHeight = menu.div.height();
  4613. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4614. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4615. }
  4616. menu.div.css('visibility', 'visible');
  4617. self.menu = menu;
  4618. }
  4619. });
  4620. }
  4621. function _bindNewlineEvent() {
  4622. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4623. if (_IE && newlineTag !== 'br') {
  4624. return;
  4625. }
  4626. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4627. return;
  4628. }
  4629. if (_OPERA && _V < 9) {
  4630. return;
  4631. }
  4632. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4633. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4634. function getAncestorTagName(range) {
  4635. var ancestor = K(range.commonAncestor());
  4636. while (ancestor) {
  4637. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4638. break;
  4639. }
  4640. ancestor = ancestor.parent();
  4641. }
  4642. return ancestor.name;
  4643. }
  4644. K(doc).keydown(function(e) {
  4645. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4646. autoImg(self);
  4647. return;
  4648. }
  4649. self.cmd.selection();
  4650. var tagName = getAncestorTagName(self.cmd.range);
  4651. if (tagName == 'marquee' || tagName == 'select') {
  4652. return;
  4653. }
  4654. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4655. e.preventDefault();
  4656. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4657. return;
  4658. }
  4659. if (!pSkipTagMap[tagName]) {
  4660. _nativeCommand(doc, 'formatblock', '<p>');
  4661. }
  4662. });
  4663. K(doc).keyup(function(e) {
  4664. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4665. return;
  4666. }
  4667. if (newlineTag == 'br') {
  4668. return;
  4669. }
  4670. if (_GECKO) {
  4671. var root = self.cmd.commonAncestor('p');
  4672. var a = self.cmd.commonAncestor('a');
  4673. if (a && a.text() == '') {
  4674. a.remove(true);
  4675. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4676. self.cmd.select();
  4677. }
  4678. return;
  4679. }
  4680. self.cmd.selection();
  4681. var tagName = getAncestorTagName(self.cmd.range);
  4682. if (tagName == 'marquee' || tagName == 'select') {
  4683. return;
  4684. }
  4685. if (!pSkipTagMap[tagName]) {
  4686. _nativeCommand(doc, 'formatblock', '<p>');
  4687. }
  4688. var div = self.cmd.commonAncestor('div');
  4689. if (div) {
  4690. var p = K('<p></p>'),
  4691. child = div[0].firstChild;
  4692. while (child) {
  4693. var next = child.nextSibling;
  4694. p.append(child);
  4695. child = next;
  4696. }
  4697. div.before(p);
  4698. div.remove();
  4699. self.cmd.range.selectNodeContents(p[0]);
  4700. self.cmd.select();
  4701. }
  4702. });
  4703. }
  4704. function _bindTabEvent() {
  4705. var self = this, doc = self.edit.doc;
  4706. K(doc).keydown(function(e) {
  4707. if (e.which == 9) {
  4708. e.preventDefault();
  4709. if (self.afterTab) {
  4710. self.afterTab.call(self, e);
  4711. return;
  4712. }
  4713. var cmd = self.cmd, range = cmd.range;
  4714. range.shrink();
  4715. if (range.collapsed && range.startContainer.nodeType == 1) {
  4716. range.insertNode(K('@&nbsp;', doc)[0]);
  4717. cmd.select();
  4718. }
  4719. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4720. }
  4721. });
  4722. }
  4723. function _bindFocusEvent() {
  4724. var self = this;
  4725. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4726. if (self.afterFocus) {
  4727. self.afterFocus.call(self, e);
  4728. }
  4729. }).blur(function(e) {
  4730. if (self.afterBlur) {
  4731. self.afterBlur.call(self, e);
  4732. }
  4733. });
  4734. }
  4735. function _removeBookmarkTag(html) {
  4736. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4737. }
  4738. function _removeTempTag(html) {
  4739. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4740. }
  4741. function _addBookmarkToStack(stack, bookmark) {
  4742. if (stack.length === 0) {
  4743. stack.push(bookmark);
  4744. return;
  4745. }
  4746. var prev = stack[stack.length - 1];
  4747. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4748. stack.push(bookmark);
  4749. }
  4750. }
  4751. function _undoToRedo(fromStack, toStack) {
  4752. var self = this, edit = self.edit,
  4753. body = edit.doc.body,
  4754. range, bookmark;
  4755. if (fromStack.length === 0) {
  4756. return self;
  4757. }
  4758. if (edit.designMode) {
  4759. range = self.cmd.range;
  4760. bookmark = range.createBookmark(true);
  4761. bookmark.html = body.innerHTML;
  4762. } else {
  4763. bookmark = {
  4764. html : body.innerHTML
  4765. };
  4766. }
  4767. _addBookmarkToStack(toStack, bookmark);
  4768. var prev = fromStack.pop();
  4769. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4770. prev = fromStack.pop();
  4771. }
  4772. if (edit.designMode) {
  4773. edit.html(prev.html);
  4774. if (prev.start) {
  4775. range.moveToBookmark(prev);
  4776. self.select();
  4777. }
  4778. } else {
  4779. K(body).html(_removeBookmarkTag(prev.html));
  4780. }
  4781. return self;
  4782. }
  4783. function KEditor(options) {
  4784. var self = this;
  4785. self.options = {};
  4786. function setOption(key, val) {
  4787. if (KEditor.prototype[key] === undefined) {
  4788. self[key] = val;
  4789. }
  4790. self.options[key] = val;
  4791. }
  4792. _each(options, function(key, val) {
  4793. setOption(key, options[key]);
  4794. });
  4795. _each(K.options, function(key, val) {
  4796. if (self[key] === undefined) {
  4797. setOption(key, val);
  4798. }
  4799. });
  4800. var se = K(self.srcElement || '<textarea/>');
  4801. if (!self.width) {
  4802. self.width = se[0].style.width || se.width();
  4803. }
  4804. if (!self.height) {
  4805. self.height = se[0].style.height || se.height();
  4806. }
  4807. setOption('width', _undef(self.width, self.minWidth));
  4808. setOption('height', _undef(self.height, self.minHeight));
  4809. setOption('width', _addUnit(self.width));
  4810. setOption('height', _addUnit(self.height));
  4811. if (_MOBILE && (!_IOS || _V < 534)) {
  4812. self.designMode = false;
  4813. }
  4814. self.srcElement = se;
  4815. self.initContent = '';
  4816. self.plugin = {};
  4817. self.isCreated = false;
  4818. self._handlers = {};
  4819. self._contextmenus = [];
  4820. self._undoStack = [];
  4821. self._redoStack = [];
  4822. self._firstAddBookmark = true;
  4823. self.menu = self.contextmenu = null;
  4824. self.dialogs = [];
  4825. }
  4826. KEditor.prototype = {
  4827. lang : function(mixed) {
  4828. return _lang(mixed, this.langType);
  4829. },
  4830. loadPlugin : function(name, fn) {
  4831. var self = this;
  4832. var _pluginStatus = this._pluginStatus;
  4833. if (!_pluginStatus) {
  4834. _pluginStatus = this._pluginStatus = {};
  4835. }
  4836. if (_plugins[name]) {
  4837. if (!_isFunction(_plugins[name])) {
  4838. setTimeout(function() {
  4839. self.loadPlugin(name, fn);
  4840. }, 100);
  4841. return self;
  4842. }
  4843. if(!_pluginStatus[name]) {
  4844. _plugins[name].call(self, KindEditor);
  4845. _pluginStatus[name] = 'inited';
  4846. }
  4847. if (fn) {
  4848. fn.call(self);
  4849. }
  4850. return self;
  4851. }
  4852. _plugins[name] = 'loading';
  4853. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4854. setTimeout(function() {
  4855. if (_plugins[name]) {
  4856. self.loadPlugin(name, fn);
  4857. }
  4858. }, 0);
  4859. });
  4860. return self;
  4861. },
  4862. handler : function(key, fn) {
  4863. var self = this;
  4864. if (!self._handlers[key]) {
  4865. self._handlers[key] = [];
  4866. }
  4867. if (_isFunction(fn)) {
  4868. self._handlers[key].push(fn);
  4869. return self;
  4870. }
  4871. _each(self._handlers[key], function() {
  4872. fn = this.call(self, fn);
  4873. });
  4874. return fn;
  4875. },
  4876. clickToolbar : function(name, fn) {
  4877. var self = this, key = 'clickToolbar' + name;
  4878. if (fn === undefined) {
  4879. if (self._handlers[key]) {
  4880. return self.handler(key);
  4881. }
  4882. self.loadPlugin(name, function() {
  4883. self.handler(key);
  4884. });
  4885. return self;
  4886. }
  4887. return self.handler(key, fn);
  4888. },
  4889. updateState : function() {
  4890. var self = this;
  4891. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4892. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4893. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4894. });
  4895. return self;
  4896. },
  4897. addContextmenu : function(item) {
  4898. this._contextmenus.push(item);
  4899. return this;
  4900. },
  4901. afterCreate : function(fn) {
  4902. return this.handler('afterCreate', fn);
  4903. },
  4904. beforeRemove : function(fn) {
  4905. return this.handler('beforeRemove', fn);
  4906. },
  4907. beforeGetHtml : function(fn) {
  4908. return this.handler('beforeGetHtml', fn);
  4909. },
  4910. beforeSetHtml : function(fn) {
  4911. return this.handler('beforeSetHtml', fn);
  4912. },
  4913. afterSetHtml : function(fn) {
  4914. return this.handler('afterSetHtml', fn);
  4915. },
  4916. create : function() {
  4917. var self = this, fullscreenMode = self.fullscreenMode;
  4918. if (self.isCreated) {
  4919. return self;
  4920. }
  4921. if (self.srcElement.data('kindeditor')) {
  4922. return self;
  4923. }
  4924. self.srcElement.data('kindeditor', 'true');
  4925. if (fullscreenMode) {
  4926. _docElement().style.overflow = 'hidden';
  4927. } else {
  4928. _docElement().style.overflow = '';
  4929. }
  4930. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4931. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4932. if ((_IE && _V < 8) || _QUIRKS) {
  4933. height = _addUnit(_removeUnit(height) + 2);
  4934. }
  4935. var container = self.container = K(self.layout);
  4936. if (fullscreenMode) {
  4937. K(document.body).append(container);
  4938. } else {
  4939. self.srcElement.before(container);
  4940. }
  4941. var toolbarDiv = K('.toolbar', container),
  4942. editDiv = K('.edit', container),
  4943. statusbar = self.statusbar = K('.statusbar', container);
  4944. container.removeClass('container')
  4945. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4946. if (fullscreenMode) {
  4947. container.css({
  4948. position : 'absolute',
  4949. left : 0,
  4950. top : 0,
  4951. 'z-index' : 811211
  4952. });
  4953. if (!_GECKO) {
  4954. self._scrollPos = _getScrollPos();
  4955. }
  4956. window.scrollTo(0, 0);
  4957. K(document.body).css({
  4958. 'height' : '1px',
  4959. 'overflow' : 'hidden'
  4960. });
  4961. K(document.body.parentNode).css('overflow', 'hidden');
  4962. self._fullscreenExecuted = true;
  4963. } else {
  4964. if (self._fullscreenExecuted) {
  4965. K(document.body).css({
  4966. 'height' : '',
  4967. 'overflow' : ''
  4968. });
  4969. K(document.body.parentNode).css('overflow', '');
  4970. }
  4971. if (self._scrollPos) {
  4972. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4973. }
  4974. }
  4975. var htmlList = [];
  4976. K.each(self.items, function(i, name) {
  4977. if (name == '|') {
  4978. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4979. } else if (name == '/') {
  4980. htmlList.push('<div class="ke-hr"></div>');
  4981. } else {
  4982. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4983. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4984. }
  4985. });
  4986. var toolbar = self.toolbar = _toolbar({
  4987. src : toolbarDiv,
  4988. html : htmlList.join(''),
  4989. noDisableItems : self.noDisableItems,
  4990. click : function(e, name) {
  4991. e.stop();
  4992. if (self.menu) {
  4993. var menuName = self.menu.name;
  4994. self.hideMenu();
  4995. if (menuName === name) {
  4996. return;
  4997. }
  4998. }
  4999. self.clickToolbar(name);
  5000. }
  5001. });
  5002. var editHeight = _removeUnit(height) - toolbar.div.height();
  5003. var edit = self.edit = _edit({
  5004. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5005. src : editDiv,
  5006. srcElement : self.srcElement,
  5007. designMode : self.designMode,
  5008. themesPath : self.themesPath,
  5009. bodyClass : self.bodyClass,
  5010. cssPath : self.cssPath,
  5011. cssData : self.cssData,
  5012. beforeGetHtml : function(html) {
  5013. html = self.beforeGetHtml(html);
  5014. html = _removeBookmarkTag(_removeTempTag(html));
  5015. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5016. },
  5017. beforeSetHtml : function(html) {
  5018. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5019. return self.beforeSetHtml(html);
  5020. },
  5021. afterSetHtml : function() {
  5022. self.edit = edit = this;
  5023. self.afterSetHtml();
  5024. },
  5025. afterCreate : function() {
  5026. self.edit = edit = this;
  5027. self.cmd = edit.cmd;
  5028. self._docMousedownFn = function(e) {
  5029. if (self.menu) {
  5030. self.hideMenu();
  5031. }
  5032. };
  5033. K(edit.doc, document).mousedown(self._docMousedownFn);
  5034. _bindContextmenuEvent.call(self);
  5035. _bindNewlineEvent.call(self);
  5036. _bindTabEvent.call(self);
  5037. _bindFocusEvent.call(self);
  5038. edit.afterChange(function(e) {
  5039. if (!edit.designMode) {
  5040. return;
  5041. }
  5042. self.updateState();
  5043. self.addBookmark();
  5044. if (self.options.afterChange) {
  5045. self.options.afterChange.call(self);
  5046. }
  5047. });
  5048. edit.textarea.keyup(function(e) {
  5049. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5050. if (self.options.afterChange) {
  5051. self.options.afterChange.call(self);
  5052. }
  5053. }
  5054. });
  5055. if (self.readonlyMode) {
  5056. self.readonly();
  5057. }
  5058. self.isCreated = true;
  5059. if (self.initContent === '') {
  5060. self.initContent = self.html();
  5061. }
  5062. if (self._undoStack.length > 0) {
  5063. var prev = self._undoStack.pop();
  5064. if (prev.start) {
  5065. self.html(prev.html);
  5066. edit.cmd.range.moveToBookmark(prev);
  5067. self.select();
  5068. }
  5069. }
  5070. self.afterCreate();
  5071. if (self.options.afterCreate) {
  5072. self.options.afterCreate.call(self);
  5073. }
  5074. }
  5075. });
  5076. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5077. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5078. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5079. if (self._fullscreenResizeHandler) {
  5080. K(window).unbind('resize', self._fullscreenResizeHandler);
  5081. self._fullscreenResizeHandler = null;
  5082. }
  5083. function initResize() {
  5084. if (statusbar.height() === 0) {
  5085. setTimeout(initResize, 100);
  5086. return;
  5087. }
  5088. self.resize(width, height, false);
  5089. }
  5090. initResize();
  5091. if (fullscreenMode) {
  5092. self._fullscreenResizeHandler = function(e) {
  5093. if (self.isCreated) {
  5094. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5095. }
  5096. };
  5097. K(window).bind('resize', self._fullscreenResizeHandler);
  5098. toolbar.select('fullscreen');
  5099. statusbar.first().css('visibility', 'hidden');
  5100. statusbar.last().css('visibility', 'hidden');
  5101. } else {
  5102. if (_GECKO) {
  5103. K(window).bind('scroll', function(e) {
  5104. self._scrollPos = _getScrollPos();
  5105. });
  5106. }
  5107. if (self.resizeType > 0) {
  5108. _drag({
  5109. moveEl : container,
  5110. clickEl : statusbar,
  5111. moveFn : function(x, y, width, height, diffX, diffY) {
  5112. height += diffY;
  5113. self.resize(null, height);
  5114. }
  5115. });
  5116. } else {
  5117. statusbar.first().css('visibility', 'hidden');
  5118. }
  5119. if (self.resizeType === 2) {
  5120. _drag({
  5121. moveEl : container,
  5122. clickEl : statusbar.last(),
  5123. moveFn : function(x, y, width, height, diffX, diffY) {
  5124. width += diffX;
  5125. height += diffY;
  5126. self.resize(width, height);
  5127. }
  5128. });
  5129. } else {
  5130. statusbar.last().css('visibility', 'hidden');
  5131. }
  5132. }
  5133. return self;
  5134. },
  5135. remove : function() {
  5136. var self = this;
  5137. if (!self.isCreated) {
  5138. return self;
  5139. }
  5140. self.beforeRemove();
  5141. self.srcElement.data('kindeditor', '');
  5142. if (self.menu) {
  5143. self.hideMenu();
  5144. }
  5145. _each(self.dialogs, function() {
  5146. self.hideDialog();
  5147. });
  5148. K(document).unbind('mousedown', self._docMousedownFn);
  5149. self.toolbar.remove();
  5150. self.edit.remove();
  5151. self.statusbar.last().unbind();
  5152. self.statusbar.unbind();
  5153. self.container.remove();
  5154. self.container = self.toolbar = self.edit = self.menu = null;
  5155. self.dialogs = [];
  5156. self.isCreated = false;
  5157. return self;
  5158. },
  5159. resize : function(width, height, updateProp) {
  5160. var self = this;
  5161. updateProp = _undef(updateProp, true);
  5162. if (width) {
  5163. if (!/%/.test(width)) {
  5164. width = _removeUnit(width);
  5165. width = width < self.minWidth ? self.minWidth : width;
  5166. }
  5167. self.container.css('width', _addUnit(width));
  5168. if (updateProp) {
  5169. self.width = _addUnit(width);
  5170. }
  5171. }
  5172. if (height) {
  5173. height = _removeUnit(height);
  5174. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5175. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5176. self.edit.setHeight(editHeight);
  5177. if (updateProp) {
  5178. self.height = _addUnit(height);
  5179. }
  5180. }
  5181. return self;
  5182. },
  5183. select : function() {
  5184. this.isCreated && this.cmd.select();
  5185. return this;
  5186. },
  5187. html : function(val) {
  5188. var self = this;
  5189. if (val === undefined) {
  5190. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5191. }
  5192. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5193. if (self.isCreated) {
  5194. self.cmd.selection();
  5195. }
  5196. return self;
  5197. },
  5198. fullHtml : function() {
  5199. return this.isCreated ? this.edit.html(undefined, true) : '';
  5200. },
  5201. text : function(val) {
  5202. var self = this;
  5203. if (val === undefined) {
  5204. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5205. } else {
  5206. return self.html(_escape(val));
  5207. }
  5208. },
  5209. isEmpty : function() {
  5210. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5211. },
  5212. isDirty : function() {
  5213. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5214. },
  5215. selectedHtml : function() {
  5216. var val = this.isCreated ? this.cmd.range.html() : '';
  5217. val = _removeBookmarkTag(_removeTempTag(val));
  5218. return val;
  5219. },
  5220. count : function(mode) {
  5221. var self = this;
  5222. mode = (mode || 'html').toLowerCase();
  5223. if (mode === 'html') {
  5224. return self.html().length;
  5225. }
  5226. if (mode === 'text') {
  5227. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5228. }
  5229. return 0;
  5230. },
  5231. exec : function(key) {
  5232. key = key.toLowerCase();
  5233. var self = this, cmd = self.cmd,
  5234. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5235. if (changeFlag) {
  5236. self.addBookmark(false);
  5237. }
  5238. cmd[key].apply(cmd, _toArray(arguments, 1));
  5239. if (changeFlag) {
  5240. self.updateState();
  5241. self.addBookmark(false);
  5242. if (self.options.afterChange) {
  5243. self.options.afterChange.call(self);
  5244. }
  5245. }
  5246. return self;
  5247. },
  5248. insertHtml : function(val, quickMode) {
  5249. if (!this.isCreated) {
  5250. return this;
  5251. }
  5252. val = this.beforeSetHtml(val);
  5253. this.exec('inserthtml', val, quickMode);
  5254. return this;
  5255. },
  5256. appendHtml : function(val) {
  5257. this.html(this.html() + val);
  5258. if (this.isCreated) {
  5259. var cmd = this.cmd;
  5260. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5261. cmd.select();
  5262. }
  5263. return this;
  5264. },
  5265. sync : function() {
  5266. _elementVal(this.srcElement, this.html());
  5267. return this;
  5268. },
  5269. focus : function() {
  5270. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5271. return this;
  5272. },
  5273. blur : function() {
  5274. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5275. return this;
  5276. },
  5277. addBookmark : function(checkSize) {
  5278. checkSize = _undef(checkSize, true);
  5279. var self = this, edit = self.edit,
  5280. body = edit.doc.body,
  5281. html = _removeTempTag(body.innerHTML), bookmark;
  5282. if (checkSize && self._undoStack.length > 0) {
  5283. var prev = self._undoStack[self._undoStack.length - 1];
  5284. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5285. return self;
  5286. }
  5287. }
  5288. if (edit.designMode && !self._firstAddBookmark) {
  5289. var range = self.cmd.range;
  5290. bookmark = range.createBookmark(true);
  5291. bookmark.html = _removeTempTag(body.innerHTML);
  5292. range.moveToBookmark(bookmark);
  5293. } else {
  5294. bookmark = {
  5295. html : html
  5296. };
  5297. }
  5298. self._firstAddBookmark = false;
  5299. _addBookmarkToStack(self._undoStack, bookmark);
  5300. return self;
  5301. },
  5302. undo : function() {
  5303. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5304. },
  5305. redo : function() {
  5306. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5307. },
  5308. fullscreen : function(bool) {
  5309. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5310. this.addBookmark(false);
  5311. return this.remove().create();
  5312. },
  5313. readonly : function(isReadonly) {
  5314. isReadonly = _undef(isReadonly, true);
  5315. var self = this, edit = self.edit, doc = edit.doc;
  5316. if (self.designMode) {
  5317. self.toolbar.disableAll(isReadonly, []);
  5318. } else {
  5319. _each(self.noDisableItems, function() {
  5320. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5321. });
  5322. }
  5323. if (_IE) {
  5324. doc.body.contentEditable = !isReadonly;
  5325. } else {
  5326. doc.designMode = isReadonly ? 'off' : 'on';
  5327. }
  5328. edit.textarea[0].disabled = isReadonly;
  5329. },
  5330. createMenu : function(options) {
  5331. var self = this,
  5332. name = options.name,
  5333. knode = self.toolbar.get(name),
  5334. pos = knode.pos();
  5335. options.x = pos.x;
  5336. options.y = pos.y + knode.height();
  5337. options.z = self.options.zIndex;
  5338. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5339. if (options.selectedColor !== undefined) {
  5340. options.cls = 'ke-colorpicker-' + self.themeType;
  5341. options.noColor = self.lang('noColor');
  5342. self.menu = _colorpicker(options);
  5343. } else {
  5344. options.cls = 'ke-menu-' + self.themeType;
  5345. options.centerLineMode = false;
  5346. self.menu = _menu(options);
  5347. }
  5348. return self.menu;
  5349. },
  5350. hideMenu : function() {
  5351. this.menu.remove();
  5352. this.menu = null;
  5353. return this;
  5354. },
  5355. hideContextmenu : function() {
  5356. this.contextmenu.remove();
  5357. this.contextmenu = null;
  5358. return this;
  5359. },
  5360. createDialog : function(options) {
  5361. var self = this, name = options.name;
  5362. options.z = self.options.zIndex;
  5363. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5364. options.closeBtn = _undef(options.closeBtn, {
  5365. name : self.lang('close'),
  5366. click : function(e) {
  5367. self.hideDialog();
  5368. if (_IE && self.cmd) {
  5369. self.cmd.select();
  5370. }
  5371. }
  5372. });
  5373. options.noBtn = _undef(options.noBtn, {
  5374. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5375. click : function(e) {
  5376. self.hideDialog();
  5377. if (_IE && self.cmd) {
  5378. self.cmd.select();
  5379. }
  5380. }
  5381. });
  5382. if (self.dialogAlignType != 'page') {
  5383. options.alignEl = self.container;
  5384. }
  5385. options.cls = 'ke-dialog-' + self.themeType;
  5386. if (self.dialogs.length > 0) {
  5387. var firstDialog = self.dialogs[0],
  5388. parentDialog = self.dialogs[self.dialogs.length - 1];
  5389. firstDialog.setMaskIndex(parentDialog.z + 2);
  5390. options.z = parentDialog.z + 3;
  5391. options.showMask = false;
  5392. }
  5393. var dialog = _dialog(options);
  5394. self.dialogs.push(dialog);
  5395. return dialog;
  5396. },
  5397. hideDialog : function() {
  5398. var self = this;
  5399. if (self.dialogs.length > 0) {
  5400. self.dialogs.pop().remove();
  5401. }
  5402. if (self.dialogs.length > 0) {
  5403. var firstDialog = self.dialogs[0],
  5404. parentDialog = self.dialogs[self.dialogs.length - 1];
  5405. firstDialog.setMaskIndex(parentDialog.z - 1);
  5406. }
  5407. return self;
  5408. },
  5409. errorDialog : function(html) {
  5410. var self = this;
  5411. var dialog = self.createDialog({
  5412. width : 750,
  5413. title : self.lang('uploadError'),
  5414. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5415. });
  5416. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5417. doc.open();
  5418. doc.write(html);
  5419. doc.close();
  5420. K(doc.body).css('background-color', '#FFF');
  5421. iframe[0].contentWindow.focus();
  5422. return self;
  5423. }
  5424. };
  5425. function _editor(options) {
  5426. return new KEditor(options);
  5427. }
  5428. var _instances = [];
  5429. function _create(expr, options) {
  5430. options = options || {};
  5431. options.basePath = _undef(options.basePath, K.basePath);
  5432. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5433. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5434. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5435. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5436. var themeType = _undef(options.themeType, K.options.themeType);
  5437. _loadStyle(options.themesPath + 'default/default.css');
  5438. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5439. }
  5440. function create(editor) {
  5441. _each(_plugins, function(name, fn) {
  5442. if (_isFunction(fn)) {
  5443. fn.call(editor, KindEditor);
  5444. if (!editor._pluginStatus) {
  5445. editor._pluginStatus = {};
  5446. }
  5447. editor._pluginStatus[name] = 'inited';
  5448. }
  5449. });
  5450. return editor.create();
  5451. }
  5452. var knode = K(expr);
  5453. if (!knode || knode.length === 0) {
  5454. return;
  5455. }
  5456. if (knode.length > 1) {
  5457. knode.each(function() {
  5458. _create(this, options);
  5459. });
  5460. return _instances[0];
  5461. }
  5462. options.srcElement = knode[0];
  5463. var editor = new KEditor(options);
  5464. _instances.push(editor);
  5465. if (_language[editor.langType]) {
  5466. return create(editor);
  5467. }
  5468. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5469. create(editor);
  5470. });
  5471. return editor;
  5472. }
  5473. function _eachEditor(expr, fn) {
  5474. K(expr).each(function(i, el) {
  5475. K.each(_instances, function(j, editor) {
  5476. if (editor && editor.srcElement[0] == el) {
  5477. fn.call(editor, j);
  5478. return false;
  5479. }
  5480. });
  5481. });
  5482. }
  5483. K.remove = function(expr) {
  5484. _eachEditor(expr, function(i) {
  5485. this.remove();
  5486. _instances.splice(i, 1);
  5487. });
  5488. };
  5489. K.sync = function(expr) {
  5490. _eachEditor(expr, function() {
  5491. this.sync();
  5492. });
  5493. };
  5494. K.html = function(expr, val) {
  5495. _eachEditor(expr, function() {
  5496. this.html(val);
  5497. });
  5498. };
  5499. K.insertHtml = function(expr, val) {
  5500. _eachEditor(expr, function() {
  5501. this.insertHtml(val);
  5502. });
  5503. };
  5504. K.appendHtml = function(expr, val) {
  5505. _eachEditor(expr, function() {
  5506. this.appendHtml(val);
  5507. });
  5508. };
  5509. if (_IE && _V < 7) {
  5510. _nativeCommand(document, 'BackgroundImageCache', true);
  5511. }
  5512. K.EditorClass = KEditor;
  5513. K.editor = _editor;
  5514. K.create = _create;
  5515. K.instances = _instances;
  5516. K.plugin = _plugin;
  5517. K.lang = _lang;
  5518. _plugin('core', function(K) {
  5519. var self = this,
  5520. shortcutKeys = {
  5521. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5522. };
  5523. self.afterSetHtml(function() {
  5524. if (self.options.afterChange) {
  5525. self.options.afterChange.call(self);
  5526. }
  5527. });
  5528. self.afterCreate(function() {
  5529. if (self.syncType != 'form') {
  5530. return;
  5531. }
  5532. var el = K(self.srcElement), hasForm = false;
  5533. while ((el = el.parent())) {
  5534. if (el.name == 'form') {
  5535. hasForm = true;
  5536. break;
  5537. }
  5538. }
  5539. if (hasForm) {
  5540. el.bind('submit', function(e) {
  5541. self.sync();
  5542. K(window).bind('unload', function() {
  5543. self.edit.textarea.remove();
  5544. });
  5545. });
  5546. var resetBtn = K('[type="reset"]', el);
  5547. resetBtn.click(function() {
  5548. self.html(self.initContent);
  5549. self.cmd.selection();
  5550. });
  5551. self.beforeRemove(function() {
  5552. el.unbind();
  5553. resetBtn.unbind();
  5554. });
  5555. }
  5556. });
  5557. self.clickToolbar('source', function() {
  5558. if (self.edit.designMode) {
  5559. self.toolbar.disableAll(true);
  5560. self.edit.design(false);
  5561. self.toolbar.select('source');
  5562. } else {
  5563. self.toolbar.disableAll(false);
  5564. self.edit.design(true);
  5565. self.toolbar.unselect('source');
  5566. if (_GECKO) {
  5567. setTimeout(function() {
  5568. self.cmd.selection();
  5569. }, 0);
  5570. } else {
  5571. self.cmd.selection();
  5572. }
  5573. }
  5574. self.designMode = self.edit.designMode;
  5575. });
  5576. self.afterCreate(function() {
  5577. if (!self.designMode) {
  5578. self.toolbar.disableAll(true).select('source');
  5579. }
  5580. });
  5581. self.clickToolbar('fullscreen', function() {
  5582. self.fullscreen();
  5583. });
  5584. if (self.fullscreenShortcut) {
  5585. var loaded = false;
  5586. self.afterCreate(function() {
  5587. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5588. if (e.which == 27) {
  5589. setTimeout(function() {
  5590. self.fullscreen();
  5591. }, 0);
  5592. }
  5593. });
  5594. if (loaded) {
  5595. if (_IE && !self.designMode) {
  5596. return;
  5597. }
  5598. self.focus();
  5599. }
  5600. if (!loaded) {
  5601. loaded = true;
  5602. }
  5603. });
  5604. }
  5605. _each('undo,redo'.split(','), function(i, name) {
  5606. if (shortcutKeys[name]) {
  5607. self.afterCreate(function() {
  5608. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5609. self.clickToolbar(name);
  5610. });
  5611. });
  5612. }
  5613. self.clickToolbar(name, function() {
  5614. self[name]();
  5615. });
  5616. });
  5617. self.clickToolbar('formatblock', function() {
  5618. var blocks = self.lang('formatblock.formatBlock'),
  5619. heights = {
  5620. h1 : 28,
  5621. h2 : 24,
  5622. h3 : 18,
  5623. H4 : 14,
  5624. p : 12
  5625. },
  5626. curVal = self.cmd.val('formatblock'),
  5627. menu = self.createMenu({
  5628. name : 'formatblock',
  5629. width : self.langType == 'en' ? 200 : 150
  5630. });
  5631. _each(blocks, function(key, val) {
  5632. var style = 'font-size:' + heights[key] + 'px;';
  5633. if (key.charAt(0) === 'h') {
  5634. style += 'font-weight:bold;';
  5635. }
  5636. menu.addItem({
  5637. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5638. height : heights[key] + 12,
  5639. checked : (curVal === key || curVal === val),
  5640. click : function() {
  5641. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5642. }
  5643. });
  5644. });
  5645. });
  5646. self.clickToolbar('fontname', function() {
  5647. var curVal = self.cmd.val('fontname'),
  5648. menu = self.createMenu({
  5649. name : 'fontname',
  5650. width : 150
  5651. });
  5652. _each(self.lang('fontname.fontName'), function(key, val) {
  5653. menu.addItem({
  5654. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5655. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5656. click : function() {
  5657. self.exec('fontname', key).hideMenu();
  5658. }
  5659. });
  5660. });
  5661. });
  5662. self.clickToolbar('fontsize', function() {
  5663. var curVal = self.cmd.val('fontsize'),
  5664. menu = self.createMenu({
  5665. name : 'fontsize',
  5666. width : 150
  5667. });
  5668. _each(self.fontSizeTable, function(i, val) {
  5669. menu.addItem({
  5670. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5671. height : _removeUnit(val) + 12,
  5672. checked : curVal === val,
  5673. click : function() {
  5674. self.exec('fontsize', val).hideMenu();
  5675. }
  5676. });
  5677. });
  5678. });
  5679. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5680. self.clickToolbar(name, function() {
  5681. self.createMenu({
  5682. name : name,
  5683. selectedColor : self.cmd.val(name) || 'default',
  5684. colors : self.colorTable,
  5685. click : function(color) {
  5686. self.exec(name, color).hideMenu();
  5687. }
  5688. });
  5689. });
  5690. });
  5691. _each(('cut,copy,paste').split(','), function(i, name) {
  5692. self.clickToolbar(name, function() {
  5693. self.focus();
  5694. try {
  5695. self.exec(name, null);
  5696. } catch(e) {
  5697. alert(self.lang(name + 'Error'));
  5698. }
  5699. });
  5700. });
  5701. self.clickToolbar('about', function() {
  5702. var html = '<div style="margin:20px;">' +
  5703. '<div>KindEditor ' + _VERSION + '</div>' +
  5704. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5705. '</div>';
  5706. self.createDialog({
  5707. name : 'about',
  5708. width : 350,
  5709. title : self.lang('about'),
  5710. body : html
  5711. });
  5712. });
  5713. self.plugin.getSelectedLink = function() {
  5714. return self.cmd.commonAncestor('a');
  5715. };
  5716. self.plugin.getSelectedImage = function() {
  5717. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5718. return !/^ke-\w+$/i.test(img[0].className);
  5719. });
  5720. };
  5721. self.plugin.getSelectedFlash = function() {
  5722. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5723. return img[0].className == 'ke-flash';
  5724. });
  5725. };
  5726. self.plugin.getSelectedMedia = function() {
  5727. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5728. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5729. });
  5730. };
  5731. self.plugin.getSelectedAnchor = function() {
  5732. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5733. return img[0].className == 'ke-anchor';
  5734. });
  5735. };
  5736. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5737. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5738. _each('edit,delete'.split(','), function(j, val) {
  5739. self.addContextmenu({
  5740. title : self.lang(val + uName),
  5741. click : function() {
  5742. self.loadPlugin(name, function() {
  5743. self.plugin[name][val]();
  5744. self.hideMenu();
  5745. });
  5746. },
  5747. cond : self.plugin['getSelected' + uName],
  5748. width : 150,
  5749. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5750. });
  5751. });
  5752. self.addContextmenu({ title : '-' });
  5753. });
  5754. self.plugin.getSelectedTable = function() {
  5755. return self.cmd.commonAncestor('table');
  5756. };
  5757. self.plugin.getSelectedRow = function() {
  5758. return self.cmd.commonAncestor('tr');
  5759. };
  5760. self.plugin.getSelectedCell = function() {
  5761. return self.cmd.commonAncestor('td');
  5762. };
  5763. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5764. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5765. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5766. self.addContextmenu({
  5767. title : self.lang('table' + val),
  5768. click : function() {
  5769. self.loadPlugin('table', function() {
  5770. self.plugin.table[val]();
  5771. self.hideMenu();
  5772. });
  5773. },
  5774. cond : cond,
  5775. width : 170,
  5776. iconClass : 'ke-icon-table' + val
  5777. });
  5778. });
  5779. self.addContextmenu({ title : '-' });
  5780. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5781. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5782. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5783. if (shortcutKeys[name]) {
  5784. self.afterCreate(function() {
  5785. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5786. self.cmd.selection();
  5787. self.clickToolbar(name);
  5788. });
  5789. });
  5790. }
  5791. self.clickToolbar(name, function() {
  5792. self.focus().exec(name, null);
  5793. });
  5794. });
  5795. self.afterCreate(function() {
  5796. var doc = self.edit.doc, cmd, bookmark, div,
  5797. cls = '__kindeditor_paste__', pasting = false;
  5798. function movePastedData() {
  5799. cmd.range.moveToBookmark(bookmark);
  5800. cmd.select();
  5801. if (_WEBKIT) {
  5802. K('div.' + cls, div).each(function() {
  5803. K(this).after('<br />').remove(true);
  5804. });
  5805. K('span.Apple-style-span', div).remove(true);
  5806. K('span.Apple-tab-span', div).remove(true);
  5807. K('span[style]', div).each(function() {
  5808. if (K(this).css('white-space') == 'nowrap') {
  5809. K(this).remove(true);
  5810. }
  5811. });
  5812. K('meta', div).remove();
  5813. }
  5814. var html = div[0].innerHTML;
  5815. div.remove();
  5816. if (html === '') {
  5817. return;
  5818. }
  5819. if (_WEBKIT) {
  5820. html = html.replace(/(<br>)\1/ig, '$1');
  5821. }
  5822. if (self.pasteType === 2) {
  5823. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5824. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5825. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5826. } else {
  5827. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5828. html = self.beforeSetHtml(html);
  5829. }
  5830. }
  5831. if (self.pasteType === 1) {
  5832. html = html.replace(/&nbsp;/ig, ' ');
  5833. html = html.replace(/\n\s*\n/g, '\n');
  5834. html = html.replace(/<br[^>]*>/ig, '\n');
  5835. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5836. html = html.replace(/<[^>]+>/g, '');
  5837. html = html.replace(/ {2}/g, ' &nbsp;');
  5838. if (self.newlineTag == 'p') {
  5839. if (/\n/.test(html)) {
  5840. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5841. }
  5842. } else {
  5843. html = html.replace(/\n/g, '<br />$&');
  5844. }
  5845. }
  5846. self.insertHtml(html, true);
  5847. }
  5848. K(doc.body).bind('paste', function(e){
  5849. //处理IE11,Chrome粘贴图片上传
  5850. function dopasteImg() {
  5851. //debugger;
  5852. var file = null;
  5853. if (window.clipboardData) {//ie
  5854. if (clipboardData.files && clipboardData.files.length)//IE11
  5855. file = clipboardData.files[0];
  5856. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5857. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5858. return true;
  5859. }
  5860. } else {
  5861. if (e.event.clipboardData.items)//chrome
  5862. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5863. if (e.event.clipboardData.items[i].kind === "file") {
  5864. file = e.event.clipboardData.items[i];
  5865. break;
  5866. }
  5867. }
  5868. if (file == null) {
  5869. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5870. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5871. return true;
  5872. }
  5873. }
  5874. }
  5875. if (file) {
  5876. if (!K.undef(self.allowImageUpload, true)) {
  5877. alert("编辑器禁止上传图片,请与有关人员联系!");
  5878. return true;
  5879. }
  5880. //获取File Blob
  5881. //debugger;
  5882. var blb;
  5883. if (file.getAsFile) {//Chrome
  5884. blb = file.getAsFile();
  5885. if (blb.size === 0) {
  5886. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5887. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5888. return true;
  5889. }
  5890. sendfile(blb, file.type);
  5891. } else {
  5892. var fr = new FileReader();
  5893. if (fr.readAsArrayBuffer) {//ie
  5894. fr.onloadend = function (evt) {
  5895. blb = evt.target.result;
  5896. sendfile(blb, file.type);
  5897. }
  5898. fr.readAsArrayBuffer(file);
  5899. }
  5900. }
  5901. function sendfile(b, t) {
  5902. var xhr = new XMLHttpRequest();
  5903. var formData = new FormData();
  5904. var isImg = t.indexOf("image/") === 0;
  5905. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5906. //formData.append('imgFile', b);
  5907. var myBlob = new Blob([b], { "type": t });
  5908. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5909. //formData.append('imgFile', b);
  5910. formData.append('dir', isImg ? 'image' : 'file');
  5911. xhr.open('POST', self.uploadJson);
  5912. xhr.onreadystatechange = function () {
  5913. if (xhr.readyState == 4&&xhr.status == 200) {
  5914. // if (fn) {
  5915. var data = _trim(xhr.responseText);
  5916. //if (dataType == 'json') {
  5917. data = _json(data);
  5918. if (data.error) {
  5919. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5920. $.messager.alert('Error', data.message, 'warning');
  5921. } else {
  5922. alert(data.message);
  5923. }
  5924. } else {
  5925. //self.exec('insertimage', url, title, width, height, border, align);
  5926. if(K.undef(self.formatUploadUrl, true))
  5927. data.url =K.formatUrl(data.url, 'absolute');
  5928. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5929. }
  5930. //}
  5931. // fn(data);
  5932. // }
  5933. }
  5934. }
  5935. xhr.send(formData);
  5936. }
  5937. return true;
  5938. }
  5939. }
  5940. //debugger;
  5941. if (dopasteImg())
  5942. e.stop();
  5943. //处理粘贴结束5825
  5944. if (self.pasteType === 0) {
  5945. e.stop();
  5946. return;
  5947. }
  5948. if (pasting) {
  5949. return;
  5950. }
  5951. pasting = true;
  5952. K('div.' + cls, doc).remove();
  5953. cmd = self.cmd.selection();
  5954. bookmark = cmd.range.createBookmark();
  5955. div = K('<div class="' + cls + '"></div>', doc).css({
  5956. position : 'absolute',
  5957. width : '1px',
  5958. height : '1px',
  5959. overflow : 'hidden',
  5960. left : '-1981px',
  5961. top : K(bookmark.start).pos().y + 'px',
  5962. 'white-space' : 'nowrap'
  5963. });
  5964. K(doc.body).append(div);
  5965. if (_IE) {
  5966. var rng = cmd.range.get(true);
  5967. rng.moveToElementText(div[0]);
  5968. rng.select();
  5969. rng.execCommand('paste');
  5970. e.preventDefault();
  5971. } else {
  5972. cmd.range.selectNodeContents(div[0]);
  5973. cmd.select();
  5974. div[0].tabIndex = -1;
  5975. div[0].focus();
  5976. }
  5977. setTimeout(function() {
  5978. movePastedData();
  5979. pasting = false;
  5980. }, 0);
  5981. });
  5982. });
  5983. self.beforeGetHtml(function(html) {
  5984. if (_IE && _V <= 8) {
  5985. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5986. return unescape(tag);
  5987. });
  5988. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5989. if (!/\s+type="[^"]+"/i.test($0)) {
  5990. return $1 + ' type="text"' + $2;
  5991. }
  5992. return $0;
  5993. });
  5994. }
  5995. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5996. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5997. })
  5998. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5999. var imgAttrs = _getAttrList(full);
  6000. var styles = _getCssList(imgAttrs.style || '');
  6001. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6002. var width = _undef(styles.width, '');
  6003. var height = _undef(styles.height, '');
  6004. if (/px/i.test(width)) {
  6005. width = _removeUnit(width);
  6006. }
  6007. if (/px/i.test(height)) {
  6008. height = _removeUnit(height);
  6009. }
  6010. attrs.width = _undef(imgAttrs.width, width);
  6011. attrs.height = _undef(imgAttrs.height, height);
  6012. return _mediaEmbed(attrs);
  6013. })
  6014. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6015. var imgAttrs = _getAttrList(full);
  6016. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6017. })
  6018. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6019. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6020. })
  6021. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6022. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6023. })
  6024. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6025. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6026. return $1 + _unescape(src) + $2;
  6027. });
  6028. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6029. return full;
  6030. })
  6031. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6032. return start + end;
  6033. });
  6034. });
  6035. self.beforeSetHtml(function(html) {
  6036. if (_IE && _V <= 8) {
  6037. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6038. var attrs = _getAttrList(full);
  6039. var styles = _getCssList(attrs.style || '');
  6040. if (styles.display == 'none') {
  6041. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6042. }
  6043. return full;
  6044. });
  6045. }
  6046. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6047. var attrs = _getAttrList(full);
  6048. attrs.src = _undef(attrs.src, '');
  6049. attrs.width = _undef(attrs.width, 0);
  6050. attrs.height = _undef(attrs.height, 0);
  6051. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6052. })
  6053. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6054. var attrs = _getAttrList(full);
  6055. if (attrs.href !== undefined) {
  6056. return full;
  6057. }
  6058. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6059. })
  6060. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6061. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6062. })
  6063. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6064. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6065. })
  6066. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6067. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6068. return full;
  6069. }
  6070. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6071. return full;
  6072. })
  6073. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6074. return start + 'data-ke-' + end;
  6075. })
  6076. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6077. if (full.indexOf('ke-zeroborder') >= 0) {
  6078. return full;
  6079. }
  6080. return _addClassToTag(full, 'ke-zeroborder');
  6081. });
  6082. });
  6083. });
  6084. })(window);
  6085. /*******************************************************************************
  6086. * KindEditor - WYSIWYG HTML Editor for Internet
  6087. * Copyright (C) 2006-2011 kindsoft.net
  6088. *
  6089. * @author Roddy <luolonghao@gmail.com>
  6090. * @site http://www.kindsoft.net/
  6091. * @licence http://www.kindsoft.net/license.php
  6092. *******************************************************************************/
  6093. KindEditor.lang({
  6094. source : 'HTML代码',
  6095. preview : '预览',
  6096. undo : '后退(Ctrl+Z)',
  6097. redo : '前进(Ctrl+Y)',
  6098. cut : '剪切(Ctrl+X)',
  6099. copy : '复制(Ctrl+C)',
  6100. paste : '粘贴(Ctrl+V)',
  6101. plainpaste : '粘贴为无格式文本',
  6102. wordpaste : '从Word粘贴',
  6103. selectall : '全选(Ctrl+A)',
  6104. justifyleft : '左对齐',
  6105. justifycenter : '居中',
  6106. justifyright : '右对齐',
  6107. justifyfull : '两端对齐',
  6108. insertorderedlist : '编号',
  6109. insertunorderedlist : '项目符号',
  6110. indent : '增加缩进',
  6111. outdent : '减少缩进',
  6112. subscript : '下标',
  6113. superscript : '上标',
  6114. formatblock : '段落',
  6115. fontname : '字体',
  6116. fontsize : '文字大小',
  6117. forecolor : '文字颜色',
  6118. hilitecolor : '文字背景',
  6119. bold : '粗体(Ctrl+B)',
  6120. italic : '斜体(Ctrl+I)',
  6121. underline : '下划线(Ctrl+U)',
  6122. strikethrough : '删除线',
  6123. removeformat : '删除格式',
  6124. image : '图片',
  6125. multiimage : '批量图片上传',
  6126. flash : 'Flash',
  6127. media : '视音频',
  6128. table : '表格',
  6129. tablecell : '单元格',
  6130. hr : '插入横线',
  6131. emoticons : '插入表情',
  6132. link : '超级链接',
  6133. unlink : '取消超级链接',
  6134. fullscreen : '全屏显示',
  6135. about : '关于',
  6136. print : '打印(Ctrl+P)',
  6137. filemanager : '文件空间',
  6138. code : '插入程序代码',
  6139. map : 'Google地图',
  6140. baidumap : '百度地图',
  6141. lineheight : '行距',
  6142. clearhtml : '清理HTML代码',
  6143. pagebreak : '插入分页符',
  6144. quickformat : '一键排版',
  6145. insertfile : '插入文件',
  6146. template : '插入模板',
  6147. anchor : '锚点',
  6148. yes : '确定',
  6149. no : '取消',
  6150. close : '关闭',
  6151. editImage : '图片属性',
  6152. deleteImage : '删除图片',
  6153. editFlash : 'Flash属性',
  6154. deleteFlash : '删除Flash',
  6155. editMedia : '视音频属性',
  6156. deleteMedia : '删除视音频',
  6157. editLink : '超级链接属性',
  6158. deleteLink : '取消超级链接',
  6159. editAnchor : '锚点属性',
  6160. deleteAnchor : '删除锚点',
  6161. tableprop : '表格属性',
  6162. tablecellprop : '单元格属性',
  6163. tableinsert : '插入表格',
  6164. tabledelete : '删除表格',
  6165. tablecolinsertleft : '左侧插入列',
  6166. tablecolinsertright : '右侧插入列',
  6167. tablerowinsertabove : '上方插入行',
  6168. tablerowinsertbelow : '下方插入行',
  6169. tablerowmerge : '向下合并单元格',
  6170. tablecolmerge : '向右合并单元格',
  6171. tablerowsplit : '拆分行',
  6172. tablecolsplit : '拆分列',
  6173. tablecoldelete : '删除列',
  6174. tablerowdelete : '删除行',
  6175. noColor : '无颜色',
  6176. pleaseSelectFile : '请选择文件。',
  6177. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6178. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6179. invalidWidth : "宽度必须为数字。",
  6180. invalidHeight : "高度必须为数字。",
  6181. invalidBorder : "边框必须为数字。",
  6182. invalidUrl : "请输入有效的URL地址。",
  6183. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6184. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6185. invalidPadding : '边距必须为数字。',
  6186. invalidSpacing : '间距必须为数字。',
  6187. invalidJson : '服务器发生故障。',
  6188. uploadSuccess : '上传成功。',
  6189. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6190. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6191. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6192. ajaxLoading : '加载中,请稍候 ...',
  6193. uploadLoading : '上传中,请稍候 ...',
  6194. uploadError : '上传错误',
  6195. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6196. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6197. 'code.pleaseInput' : '请输入程序代码。',
  6198. 'link.url' : 'URL',
  6199. 'link.linkType' : '打开类型',
  6200. 'link.newWindow' : '新窗口',
  6201. 'link.selfWindow' : '当前窗口',
  6202. 'flash.url' : 'URL',
  6203. 'flash.width' : '宽度',
  6204. 'flash.height' : '高度',
  6205. 'flash.upload' : '上传',
  6206. 'flash.viewServer' : '文件空间',
  6207. 'media.url' : 'URL',
  6208. 'media.width' : '宽度',
  6209. 'media.height' : '高度',
  6210. 'media.autostart' : '自动播放',
  6211. 'media.upload' : '上传',
  6212. 'media.viewServer' : '文件空间',
  6213. 'image.remoteImage' : '网络图片',
  6214. 'image.localImage' : '本地上传',
  6215. 'image.remoteUrl' : '图片地址',
  6216. 'image.localUrl' : '上传文件',
  6217. 'image.size' : '图片大小',
  6218. 'image.width' : '宽',
  6219. 'image.height' : '高',
  6220. 'image.resetSize' : '重置大小',
  6221. 'image.align' : '对齐方式',
  6222. 'image.defaultAlign' : '默认方式',
  6223. 'image.leftAlign' : '左对齐',
  6224. 'image.rightAlign' : '右对齐',
  6225. 'image.imgTitle' : '图片说明',
  6226. 'image.upload' : '浏览...',
  6227. 'image.viewServer' : '图片空间',
  6228. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6229. 'multiimage.startUpload' : '开始上传',
  6230. 'multiimage.clearAll' : '全部清空',
  6231. 'multiimage.insertAll' : '全部插入',
  6232. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6233. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6234. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6235. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6236. 'multiimage.unknownError' : '发生异常,无法上传。',
  6237. 'multiimage.pending' : '等待上传',
  6238. 'multiimage.uploadError' : '上传失败',
  6239. 'filemanager.emptyFolder' : '空文件夹',
  6240. 'filemanager.moveup' : '移到上一级文件夹',
  6241. 'filemanager.viewType' : '显示方式:',
  6242. 'filemanager.viewImage' : '缩略图',
  6243. 'filemanager.listImage' : '详细信息',
  6244. 'filemanager.orderType' : '排序方式:',
  6245. 'filemanager.fileName' : '名称',
  6246. 'filemanager.fileSize' : '大小',
  6247. 'filemanager.fileType' : '类型',
  6248. 'insertfile.url' : 'URL',
  6249. 'insertfile.title' : '文件说明',
  6250. 'insertfile.upload' : '上传',
  6251. 'insertfile.viewServer' : '文件空间',
  6252. 'table.cells' : '单元格数',
  6253. 'table.rows' : '行数',
  6254. 'table.cols' : '列数',
  6255. 'table.size' : '大小',
  6256. 'table.width' : '宽度',
  6257. 'table.height' : '高度',
  6258. 'table.percent' : '%',
  6259. 'table.px' : 'px',
  6260. 'table.space' : '边距间距',
  6261. 'table.padding' : '边距',
  6262. 'table.spacing' : '间距',
  6263. 'table.align' : '对齐方式',
  6264. 'table.textAlign' : '水平对齐',
  6265. 'table.verticalAlign' : '垂直对齐',
  6266. 'table.alignDefault' : '默认',
  6267. 'table.alignLeft' : '左对齐',
  6268. 'table.alignCenter' : '居中',
  6269. 'table.alignRight' : '右对齐',
  6270. 'table.alignTop' : '顶部',
  6271. 'table.alignMiddle' : '中部',
  6272. 'table.alignBottom' : '底部',
  6273. 'table.alignBaseline' : '基线',
  6274. 'table.border' : '边框',
  6275. 'table.borderWidth' : '边框',
  6276. 'table.borderColor' : '颜色',
  6277. 'table.backgroundColor' : '背景颜色',
  6278. 'map.address' : '地址: ',
  6279. 'map.search' : '搜索',
  6280. 'baidumap.address' : '地址: ',
  6281. 'baidumap.search' : '搜索',
  6282. 'baidumap.insertDynamicMap' : '插入动态地图',
  6283. 'anchor.name' : '锚点名称',
  6284. 'formatblock.formatBlock' : {
  6285. h1 : '标题 1',
  6286. h2 : '标题 2',
  6287. h3 : '标题 3',
  6288. h4 : '标题 4',
  6289. p : '正 文'
  6290. },
  6291. 'fontname.fontName' : {
  6292. 'SimSun' : '宋体',
  6293. 'NSimSun' : '新宋体',
  6294. 'FangSong_GB2312' : '仿宋_GB2312',
  6295. 'KaiTi_GB2312' : '楷体_GB2312',
  6296. 'SimHei' : '黑体',
  6297. 'Microsoft YaHei' : '微软雅黑',
  6298. 'Arial' : 'Arial',
  6299. 'Arial Black' : 'Arial Black',
  6300. 'Times New Roman' : 'Times New Roman',
  6301. 'Courier New' : 'Courier New',
  6302. 'Tahoma' : 'Tahoma',
  6303. 'Verdana' : 'Verdana'
  6304. },
  6305. 'lineheight.lineHeight' : [
  6306. {'1' : '单倍行距'},
  6307. {'1.5' : '1.5倍行距'},
  6308. {'2' : '2倍行距'},
  6309. {'2.5' : '2.5倍行距'},
  6310. {'3' : '3倍行距'}
  6311. ],
  6312. 'template.selectTemplate' : '可选模板',
  6313. 'template.replaceContent' : '替换当前内容',
  6314. 'template.fileList' : {
  6315. '1.html' : '图片和文字',
  6316. '2.html' : '表格',
  6317. '3.html' : '项目编号'
  6318. }
  6319. }, 'zh-CN');
  6320. KindEditor.options.langType = 'zh-CN';
  6321. /*******************************************************************************
  6322. * KindEditor - WYSIWYG HTML Editor for Internet
  6323. * Copyright (C) 2006-2011 kindsoft.net
  6324. *
  6325. * @author Roddy <luolonghao@gmail.com>
  6326. * @site http://www.kindsoft.net/
  6327. * @licence http://www.kindsoft.net/license.php
  6328. *******************************************************************************/
  6329. KindEditor.plugin('anchor', function(K) {
  6330. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6331. self.plugin.anchor = {
  6332. edit : function() {
  6333. var html = ['<div style="padding:20px;">',
  6334. '<div class="ke-dialog-row">',
  6335. '<label for="keName">' + lang.name + '</label>',
  6336. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6337. '</div>',
  6338. '</div>'].join('');
  6339. var dialog = self.createDialog({
  6340. name : name,
  6341. width : 300,
  6342. title : self.lang(name),
  6343. body : html,
  6344. yesBtn : {
  6345. name : self.lang('yes'),
  6346. click : function(e) {
  6347. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6348. }
  6349. }
  6350. });
  6351. var div = dialog.div,
  6352. nameBox = K('input[name="name"]', div);
  6353. var img = self.plugin.getSelectedAnchor();
  6354. if (img) {
  6355. nameBox.val(unescape(img.attr('data-ke-name')));
  6356. }
  6357. nameBox[0].focus();
  6358. nameBox[0].select();
  6359. },
  6360. 'delete' : function() {
  6361. self.plugin.getSelectedAnchor().remove();
  6362. }
  6363. };
  6364. self.clickToolbar(name, self.plugin.anchor.edit);
  6365. });
  6366. /*******************************************************************************
  6367. * KindEditor - WYSIWYG HTML Editor for Internet
  6368. * Copyright (C) 2006-2011 kindsoft.net
  6369. *
  6370. * @author Roddy <luolonghao@gmail.com>
  6371. * @site http://www.kindsoft.net/
  6372. * @licence http://www.kindsoft.net/license.php
  6373. *******************************************************************************/
  6374. KindEditor.plugin('autoheight', function(K) {
  6375. var self = this;
  6376. if (!self.autoHeightMode) {
  6377. return;
  6378. }
  6379. var minHeight;
  6380. function hideScroll() {
  6381. var edit = self.edit;
  6382. var body = edit.doc.body;
  6383. edit.iframe[0].scroll = 'no';
  6384. body.style.overflowY = 'hidden';
  6385. }
  6386. function resetHeight() {
  6387. if(self.fullscreenMode){
  6388. return;
  6389. }
  6390. var edit = self.edit;
  6391. var body = edit.doc.body;
  6392. edit.iframe.height(minHeight);
  6393. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6394. }
  6395. function init() {
  6396. minHeight = K.removeUnit(self.height);
  6397. self.edit.afterChange(resetHeight);
  6398. if(!self.fullscreenMode){
  6399. hideScroll();
  6400. }
  6401. resetHeight();
  6402. }
  6403. if (self.isCreated) {
  6404. init();
  6405. } else {
  6406. self.afterCreate(init);
  6407. }
  6408. });
  6409. /*
  6410. * 如何实现真正的自动高度?
  6411. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6412. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6413. * 由此就实现了真正的自动高度
  6414. * 测试:chrome、firefox、IE9、IE8
  6415. * */
  6416. /*******************************************************************************
  6417. * KindEditor - WYSIWYG HTML Editor for Internet
  6418. * Copyright (C) 2006-2011 kindsoft.net
  6419. *
  6420. * @author Roddy <luolonghao@gmail.com>
  6421. * @site http://www.kindsoft.net/
  6422. * @licence http://www.kindsoft.net/license.php
  6423. *******************************************************************************/
  6424. KindEditor.plugin('baidumap', function(K) {
  6425. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6426. var mapWidth = K.undef(self.mapWidth, 558);
  6427. var mapHeight = K.undef(self.mapHeight, 360);
  6428. self.clickToolbar(name, function() {
  6429. var html = ['<div style="padding:10px 20px;">',
  6430. '<div class="ke-header">',
  6431. '<div class="ke-left">',
  6432. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6433. '<span class="ke-button-common ke-button-outer">',
  6434. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6435. '</span>',
  6436. '</div>',
  6437. '<div class="ke-right">',
  6438. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6439. '</div>',
  6440. '<div class="ke-clearfix"></div>',
  6441. '</div>',
  6442. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6443. '</div>'].join('');
  6444. var dialog = self.createDialog({
  6445. name : name,
  6446. width : mapWidth + 42,
  6447. title : self.lang(name),
  6448. body : html,
  6449. yesBtn : {
  6450. name : self.lang('yes'),
  6451. click : function(e) {
  6452. var map = win.map;
  6453. var centerObj = map.getCenter();
  6454. var center = centerObj.lng + ',' + centerObj.lat;
  6455. var zoom = map.getZoom();
  6456. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6457. '?center=' + encodeURIComponent(center),
  6458. '&zoom=' + encodeURIComponent(zoom),
  6459. '&width=' + mapWidth,
  6460. '&height=' + mapHeight,
  6461. '&markers=' + encodeURIComponent(center),
  6462. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6463. if (checkbox[0].checked) {
  6464. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6465. } else {
  6466. self.exec('insertimage', url);
  6467. }
  6468. self.hideDialog().focus();
  6469. }
  6470. },
  6471. beforeRemove : function() {
  6472. searchBtn.remove();
  6473. if (doc) {
  6474. doc.write('');
  6475. }
  6476. iframe.remove();
  6477. }
  6478. });
  6479. var div = dialog.div,
  6480. addressBox = K('[name="address"]', div),
  6481. searchBtn = K('[name="searchBtn"]', div),
  6482. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6483. win, doc;
  6484. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6485. function ready() {
  6486. win = iframe[0].contentWindow;
  6487. doc = K.iframeDoc(iframe);
  6488. }
  6489. iframe.bind('load', function() {
  6490. iframe.unbind('load');
  6491. if (K.IE) {
  6492. ready();
  6493. } else {
  6494. setTimeout(ready, 0);
  6495. }
  6496. });
  6497. K('.ke-map', div).replaceWith(iframe);
  6498. searchBtn.click(function() {
  6499. win.search(addressBox.val());
  6500. });
  6501. });
  6502. });
  6503. /*******************************************************************************
  6504. * KindEditor - WYSIWYG HTML Editor for Internet
  6505. * Copyright (C) 2006-2011 kindsoft.net
  6506. *
  6507. * @author Roddy <luolonghao@gmail.com>
  6508. * @site http://www.kindsoft.net/
  6509. * @licence http://www.kindsoft.net/license.php
  6510. *******************************************************************************/
  6511. KindEditor.plugin('map', function(K) {
  6512. var self = this, name = 'map', lang = self.lang(name + '.');
  6513. self.clickToolbar(name, function() {
  6514. var html = ['<div style="padding:10px 20px;">',
  6515. '<div class="ke-dialog-row">',
  6516. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6517. '<span class="ke-button-common ke-button-outer">',
  6518. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6519. '</span>',
  6520. '</div>',
  6521. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6522. '</div>'].join('');
  6523. var dialog = self.createDialog({
  6524. name : name,
  6525. width : 600,
  6526. title : self.lang(name),
  6527. body : html,
  6528. yesBtn : {
  6529. name : self.lang('yes'),
  6530. click : function(e) {
  6531. var geocoder = win.geocoder,
  6532. map = win.map,
  6533. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6534. zoom = map.getZoom(),
  6535. maptype = map.getMapTypeId(),
  6536. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6537. url += '?center=' + encodeURIComponent(center);
  6538. url += '&zoom=' + encodeURIComponent(zoom);
  6539. url += '&size=558x360';
  6540. url += '&maptype=' + encodeURIComponent(maptype);
  6541. url += '&markers=' + encodeURIComponent(center);
  6542. url += '&language=' + self.langType;
  6543. url += '&sensor=false';
  6544. self.exec('insertimage', url).hideDialog().focus();
  6545. }
  6546. },
  6547. beforeRemove : function() {
  6548. searchBtn.remove();
  6549. if (doc) {
  6550. doc.write('');
  6551. }
  6552. iframe.remove();
  6553. }
  6554. });
  6555. var div = dialog.div,
  6556. addressBox = K('[name="address"]', div),
  6557. searchBtn = K('[name="searchBtn"]', div),
  6558. win, doc;
  6559. var iframeHtml = ['<!doctype html><html><head>',
  6560. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6561. '<style>',
  6562. ' html { height: 100% }',
  6563. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6564. ' #map_canvas { height: 100% }',
  6565. '</style>',
  6566. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6567. '<script>',
  6568. 'var map, geocoder;',
  6569. 'function initialize() {',
  6570. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6571. ' var options = {',
  6572. ' zoom: 11,',
  6573. ' center: latlng,',
  6574. ' disableDefaultUI: true,',
  6575. ' panControl: true,',
  6576. ' zoomControl: true,',
  6577. ' mapTypeControl: true,',
  6578. ' scaleControl: true,',
  6579. ' streetViewControl: false,',
  6580. ' overviewMapControl: true,',
  6581. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6582. ' };',
  6583. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6584. ' geocoder = new google.maps.Geocoder();',
  6585. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6586. ' if (status == google.maps.GeocoderStatus.OK) {',
  6587. ' if (results[3]) {',
  6588. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6589. ' }',
  6590. ' }',
  6591. ' });',
  6592. '}',
  6593. 'function search(address) {',
  6594. ' if (!map) return;',
  6595. ' geocoder.geocode({address : address}, function(results, status) {',
  6596. ' if (status == google.maps.GeocoderStatus.OK) {',
  6597. ' map.setZoom(11);',
  6598. ' map.setCenter(results[0].geometry.location);',
  6599. ' var marker = new google.maps.Marker({',
  6600. ' map: map,',
  6601. ' position: results[0].geometry.location',
  6602. ' });',
  6603. ' } else {',
  6604. ' alert("Invalid address: " + address);',
  6605. ' }',
  6606. ' });',
  6607. '}',
  6608. '</script>',
  6609. '</head>',
  6610. '<body onload="initialize();">',
  6611. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6612. '</body></html>'].join('\n');
  6613. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6614. function ready() {
  6615. win = iframe[0].contentWindow;
  6616. doc = K.iframeDoc(iframe);
  6617. }
  6618. iframe.bind('load', function() {
  6619. iframe.unbind('load');
  6620. if (K.IE) {
  6621. ready();
  6622. } else {
  6623. setTimeout(ready, 0);
  6624. }
  6625. });
  6626. K('.ke-map', div).replaceWith(iframe);
  6627. searchBtn.click(function() {
  6628. win.search(addressBox.val());
  6629. });
  6630. });
  6631. });
  6632. /*******************************************************************************
  6633. * KindEditor - WYSIWYG HTML Editor for Internet
  6634. * Copyright (C) 2006-2011 kindsoft.net
  6635. *
  6636. * @author Roddy <luolonghao@gmail.com>
  6637. * @site http://www.kindsoft.net/
  6638. * @licence http://www.kindsoft.net/license.php
  6639. *******************************************************************************/
  6640. KindEditor.plugin('clearhtml', function(K) {
  6641. var self = this, name = 'clearhtml';
  6642. self.clickToolbar(name, function() {
  6643. self.focus();
  6644. var html = self.html();
  6645. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6646. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6647. html = K.formatHtml(html, {
  6648. a : ['href', 'target'],
  6649. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6650. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6651. table : ['border'],
  6652. 'td,th' : ['rowspan', 'colspan'],
  6653. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6654. });
  6655. self.html(html);
  6656. self.cmd.selection(true);
  6657. self.addBookmark();
  6658. });
  6659. });
  6660. /*******************************************************************************
  6661. * KindEditor - WYSIWYG HTML Editor for Internet
  6662. * Copyright (C) 2006-2011 kindsoft.net
  6663. *
  6664. * @author Roddy <luolonghao@gmail.com>
  6665. * @site http://www.kindsoft.net/
  6666. * @licence http://www.kindsoft.net/license.php
  6667. *******************************************************************************/
  6668. KindEditor.plugin('code', function(K) {
  6669. var self = this, name = 'code';
  6670. self.clickToolbar(name, function() {
  6671. var lang = self.lang(name + '.'),
  6672. html = ['<div style="padding:10px 20px;">',
  6673. '<div class="ke-dialog-row">',
  6674. '<select class="ke-code-type">',
  6675. '<option value="js">JavaScript</option>',
  6676. '<option value="html">HTML</option>',
  6677. '<option value="css">CSS</option>',
  6678. '<option value="php">PHP</option>',
  6679. '<option value="pl">Perl</option>',
  6680. '<option value="py">Python</option>',
  6681. '<option value="rb">Ruby</option>',
  6682. '<option value="java">Java</option>',
  6683. '<option value="vb">ASP/VB</option>',
  6684. '<option value="cpp">C/C++</option>',
  6685. '<option value="cs">C#</option>',
  6686. '<option value="xml">XML</option>',
  6687. '<option value="bsh">Shell</option>',
  6688. '<option value="">Other</option>',
  6689. '</select>',
  6690. '</div>',
  6691. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6692. '</div>'].join(''),
  6693. dialog = self.createDialog({
  6694. name : name,
  6695. width : 450,
  6696. title : self.lang(name),
  6697. body : html,
  6698. yesBtn : {
  6699. name : self.lang('yes'),
  6700. click : function(e) {
  6701. var type = K('.ke-code-type', dialog.div).val(),
  6702. code = textarea.val(),
  6703. cls = type === '' ? '' : ' lang-' + type,
  6704. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6705. if (K.trim(code) === '') {
  6706. alert(lang.pleaseInput);
  6707. textarea[0].focus();
  6708. return;
  6709. }
  6710. self.insertHtml(html).hideDialog().focus();
  6711. }
  6712. }
  6713. }),
  6714. textarea = K('textarea', dialog.div);
  6715. textarea[0].focus();
  6716. });
  6717. });
  6718. /*******************************************************************************
  6719. * KindEditor - WYSIWYG HTML Editor for Internet
  6720. * Copyright (C) 2006-2011 kindsoft.net
  6721. *
  6722. * @author Roddy <luolonghao@gmail.com>
  6723. * @site http://www.kindsoft.net/
  6724. * @licence http://www.kindsoft.net/license.php
  6725. *******************************************************************************/
  6726. KindEditor.plugin('emoticons', function(K) {
  6727. var self = this, name = 'emoticons',
  6728. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6729. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6730. currentPageNum = 1;
  6731. self.clickToolbar(name, function() {
  6732. var rows = 5, cols = 9, total = 135, startNum = 0,
  6733. cells = rows * cols, pages = Math.ceil(total / cells),
  6734. colsHalf = Math.floor(cols / 2),
  6735. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6736. elements = [],
  6737. menu = self.createMenu({
  6738. name : name,
  6739. beforeRemove : function() {
  6740. removeEvent();
  6741. }
  6742. });
  6743. menu.div.append(wrapperDiv);
  6744. var previewDiv, previewImg;
  6745. if (allowPreview) {
  6746. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6747. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6748. wrapperDiv.append(previewDiv);
  6749. previewDiv.append(previewImg);
  6750. }
  6751. function bindCellEvent(cell, j, num) {
  6752. if (previewDiv) {
  6753. cell.mouseover(function() {
  6754. if (j > colsHalf) {
  6755. previewDiv.css('left', 0);
  6756. previewDiv.css('right', '');
  6757. } else {
  6758. previewDiv.css('left', '');
  6759. previewDiv.css('right', 0);
  6760. }
  6761. previewImg.attr('src', path + num + '.gif');
  6762. K(this).addClass('ke-on');
  6763. });
  6764. } else {
  6765. cell.mouseover(function() {
  6766. K(this).addClass('ke-on');
  6767. });
  6768. }
  6769. cell.mouseout(function() {
  6770. K(this).removeClass('ke-on');
  6771. });
  6772. cell.click(function(e) {
  6773. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6774. e.stop();
  6775. });
  6776. }
  6777. function createEmoticonsTable(pageNum, parentDiv) {
  6778. var table = document.createElement('table');
  6779. parentDiv.append(table);
  6780. if (previewDiv) {
  6781. K(table).mouseover(function() {
  6782. previewDiv.show('block');
  6783. });
  6784. K(table).mouseout(function() {
  6785. previewDiv.hide();
  6786. });
  6787. elements.push(K(table));
  6788. }
  6789. table.className = 'ke-table';
  6790. table.cellPadding = 0;
  6791. table.cellSpacing = 0;
  6792. table.border = 0;
  6793. var num = (pageNum - 1) * cells + startNum;
  6794. for (var i = 0; i < rows; i++) {
  6795. var row = table.insertRow(i);
  6796. for (var j = 0; j < cols; j++) {
  6797. var cell = K(row.insertCell(j));
  6798. cell.addClass('ke-cell');
  6799. bindCellEvent(cell, j, num);
  6800. var span = K('<span class="ke-img"></span>')
  6801. .css('background-position', '-' + (24 * num) + 'px 0px')
  6802. .css('background-image', 'url(' + path + 'static.gif)');
  6803. cell.append(span);
  6804. elements.push(cell);
  6805. num++;
  6806. }
  6807. }
  6808. return table;
  6809. }
  6810. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6811. function removeEvent() {
  6812. K.each(elements, function() {
  6813. this.unbind();
  6814. });
  6815. }
  6816. var pageDiv;
  6817. function bindPageEvent(el, pageNum) {
  6818. el.click(function(e) {
  6819. removeEvent();
  6820. table.parentNode.removeChild(table);
  6821. pageDiv.remove();
  6822. table = createEmoticonsTable(pageNum, wrapperDiv);
  6823. createPageTable(pageNum);
  6824. currentPageNum = pageNum;
  6825. e.stop();
  6826. });
  6827. }
  6828. function createPageTable(currentPageNum) {
  6829. pageDiv = K('<div class="ke-page"></div>');
  6830. wrapperDiv.append(pageDiv);
  6831. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6832. if (currentPageNum !== pageNum) {
  6833. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6834. bindPageEvent(a, pageNum);
  6835. pageDiv.append(a);
  6836. elements.push(a);
  6837. } else {
  6838. pageDiv.append(K('@[' + pageNum + ']'));
  6839. }
  6840. pageDiv.append(K('@&nbsp;'));
  6841. }
  6842. }
  6843. createPageTable(currentPageNum);
  6844. });
  6845. });
  6846. /*******************************************************************************
  6847. * KindEditor - WYSIWYG HTML Editor for Internet
  6848. * Copyright (C) 2006-2011 kindsoft.net
  6849. *
  6850. * @author Roddy <luolonghao@gmail.com>
  6851. * @site http://www.kindsoft.net/
  6852. * @licence http://www.kindsoft.net/license.php
  6853. *******************************************************************************/
  6854. KindEditor.plugin('filemanager', function(K) {
  6855. var self = this, name = 'filemanager',
  6856. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6857. imgPath = self.pluginsPath + name + '/images/',
  6858. lang = self.lang(name + '.');
  6859. function makeFileTitle(filename, filesize, datetime) {
  6860. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6861. }
  6862. function bindTitle(el, data) {
  6863. if (data.is_dir) {
  6864. el.attr('title', data.filename);
  6865. } else {
  6866. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6867. }
  6868. }
  6869. self.plugin.filemanagerDialog = function(options) {
  6870. var width = K.undef(options.width, 650),
  6871. height = K.undef(options.height, 510),
  6872. dirName = K.undef(options.dirName, ''),
  6873. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6874. clickFn = options.clickFn;
  6875. var html = [
  6876. '<div style="padding:10px 20px;">',
  6877. '<div class="ke-plugin-filemanager-header">',
  6878. '<div class="ke-left">',
  6879. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6880. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6881. '</div>',
  6882. '<div class="ke-right">',
  6883. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6884. '<option value="VIEW">' + lang.viewImage + '</option>',
  6885. '<option value="LIST">' + lang.listImage + '</option>',
  6886. '</select> ',
  6887. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6888. '<option value="NAME">' + lang.fileName + '</option>',
  6889. '<option value="SIZE">' + lang.fileSize + '</option>',
  6890. '<option value="TYPE">' + lang.fileType + '</option>',
  6891. '</select>',
  6892. '</div>',
  6893. '<div class="ke-clearfix"></div>',
  6894. '</div>',
  6895. '<div class="ke-plugin-filemanager-body"></div>',
  6896. '</div>'
  6897. ].join('');
  6898. var dialog = self.createDialog({
  6899. name : name,
  6900. width : width,
  6901. height : height,
  6902. title : self.lang(name),
  6903. body : html
  6904. }),
  6905. div = dialog.div,
  6906. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6907. moveupImg = K('[name="moveupImg"]', div),
  6908. moveupLink = K('[name="moveupLink"]', div),
  6909. viewServerBtn = K('[name="viewServer"]', div),
  6910. viewTypeBox = K('[name="viewType"]', div),
  6911. orderTypeBox = K('[name="orderType"]', div);
  6912. function reloadPage(path, order, func) {
  6913. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6914. dialog.showLoading(self.lang('ajaxLoading'));
  6915. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6916. dialog.hideLoading();
  6917. func(data);
  6918. });
  6919. }
  6920. var elList = [];
  6921. function bindEvent(el, result, data, createFunc) {
  6922. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6923. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6924. if (data.is_dir) {
  6925. el.click(function(e) {
  6926. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6927. });
  6928. } else if (data.is_photo) {
  6929. el.click(function(e) {
  6930. clickFn.call(this, fileUrl, data.filename);
  6931. });
  6932. } else {
  6933. el.click(function(e) {
  6934. clickFn.call(this, fileUrl, data.filename);
  6935. });
  6936. }
  6937. elList.push(el);
  6938. }
  6939. function createCommon(result, createFunc) {
  6940. K.each(elList, function() {
  6941. this.unbind();
  6942. });
  6943. moveupLink.unbind();
  6944. viewTypeBox.unbind();
  6945. orderTypeBox.unbind();
  6946. if (result.current_dir_path) {
  6947. moveupLink.click(function(e) {
  6948. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6949. });
  6950. }
  6951. function changeFunc() {
  6952. if (viewTypeBox.val() == 'VIEW') {
  6953. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6954. } else {
  6955. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6956. }
  6957. }
  6958. viewTypeBox.change(changeFunc);
  6959. orderTypeBox.change(changeFunc);
  6960. bodyDiv.html('');
  6961. }
  6962. function createList(result) {
  6963. createCommon(result, createList);
  6964. var table = document.createElement('table');
  6965. table.className = 'ke-table';
  6966. table.cellPadding = 0;
  6967. table.cellSpacing = 0;
  6968. table.border = 0;
  6969. bodyDiv.append(table);
  6970. var fileList = result.file_list;
  6971. for (var i = 0, len = fileList.length; i < len; i++) {
  6972. var data = fileList[i], row = K(table.insertRow(i));
  6973. row.mouseover(function(e) {
  6974. K(this).addClass('ke-on');
  6975. })
  6976. .mouseout(function(e) {
  6977. K(this).removeClass('ke-on');
  6978. });
  6979. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6980. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6981. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6982. if (!data.is_dir || data.has_file) {
  6983. row.css('cursor', 'pointer');
  6984. cell0.attr('title', data.filename);
  6985. bindEvent(cell0, result, data, createList);
  6986. } else {
  6987. cell0.attr('title', lang.emptyFolder);
  6988. }
  6989. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6990. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6991. }
  6992. }
  6993. function createView(result) {
  6994. createCommon(result, createView);
  6995. var fileList = result.file_list;
  6996. for (var i = 0, len = fileList.length; i < len; i++) {
  6997. var data = fileList[i],
  6998. div = K('<div class="ke-inline-block ke-item"></div>');
  6999. bodyDiv.append(div);
  7000. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7001. .mouseover(function(e) {
  7002. K(this).addClass('ke-on');
  7003. })
  7004. .mouseout(function(e) {
  7005. K(this).removeClass('ke-on');
  7006. });
  7007. div.append(photoDiv);
  7008. var fileUrl = result.current_url + data.filename,
  7009. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7010. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7011. if (!data.is_dir || data.has_file) {
  7012. photoDiv.css('cursor', 'pointer');
  7013. bindTitle(photoDiv, data);
  7014. bindEvent(photoDiv, result, data, createView);
  7015. } else {
  7016. photoDiv.attr('title', lang.emptyFolder);
  7017. }
  7018. photoDiv.append(img);
  7019. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7020. }
  7021. }
  7022. viewTypeBox.val(viewType);
  7023. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7024. return dialog;
  7025. }
  7026. });
  7027. /*******************************************************************************
  7028. * KindEditor - WYSIWYG HTML Editor for Internet
  7029. * Copyright (C) 2006-2011 kindsoft.net
  7030. *
  7031. * @author Roddy <luolonghao@gmail.com>
  7032. * @site http://www.kindsoft.net/
  7033. * @licence http://www.kindsoft.net/license.php
  7034. *******************************************************************************/
  7035. KindEditor.plugin('flash', function(K) {
  7036. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7037. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7038. allowFileManager = K.undef(self.allowFileManager, false),
  7039. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7040. extraParams = K.undef(self.extraFileUploadParams, {}),
  7041. filePostName = K.undef(self.filePostName, 'imgFile'),
  7042. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7043. self.plugin.flash = {
  7044. edit : function() {
  7045. var html = [
  7046. '<div style="padding:20px;">',
  7047. '<div class="ke-dialog-row">',
  7048. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7049. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7050. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7051. '<span class="ke-button-common ke-button-outer">',
  7052. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7053. '</span>',
  7054. '</div>',
  7055. '<div class="ke-dialog-row">',
  7056. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7057. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7058. '</div>',
  7059. '<div class="ke-dialog-row">',
  7060. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7061. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7062. '</div>',
  7063. '</div>'
  7064. ].join('');
  7065. var dialog = self.createDialog({
  7066. name : name,
  7067. width : 450,
  7068. title : self.lang(name),
  7069. body : html,
  7070. yesBtn : {
  7071. name : self.lang('yes'),
  7072. click : function(e) {
  7073. var url = K.trim(urlBox.val()),
  7074. width = widthBox.val(),
  7075. height = heightBox.val();
  7076. if (url == 'http://' || K.invalidUrl(url)) {
  7077. alert(self.lang('invalidUrl'));
  7078. urlBox[0].focus();
  7079. return;
  7080. }
  7081. if (!/^\d*$/.test(width)) {
  7082. alert(self.lang('invalidWidth'));
  7083. widthBox[0].focus();
  7084. return;
  7085. }
  7086. if (!/^\d*$/.test(height)) {
  7087. alert(self.lang('invalidHeight'));
  7088. heightBox[0].focus();
  7089. return;
  7090. }
  7091. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7092. src : url,
  7093. type : K.mediaType('.swf'),
  7094. width : width,
  7095. height : height,
  7096. quality : 'high'
  7097. });
  7098. self.insertHtml(html).hideDialog().focus();
  7099. }
  7100. }
  7101. }),
  7102. div = dialog.div,
  7103. urlBox = K('[name="url"]', div),
  7104. viewServerBtn = K('[name="viewServer"]', div),
  7105. widthBox = K('[name="width"]', div),
  7106. heightBox = K('[name="height"]', div);
  7107. urlBox.val('http://');
  7108. if (allowFlashUpload) {
  7109. var uploadbutton = K.uploadbutton({
  7110. button : K('.ke-upload-button', div)[0],
  7111. fieldName : filePostName,
  7112. extraParams : extraParams,
  7113. url : K.addParam(uploadJson, 'dir=flash'),
  7114. afterUpload : function(data) {
  7115. dialog.hideLoading();
  7116. if (data.error === 0) {
  7117. var url = data.url;
  7118. if (formatUploadUrl) {
  7119. url = K.formatUrl(url, 'absolute');
  7120. }
  7121. urlBox.val(url);
  7122. if (self.afterUpload) {
  7123. self.afterUpload.call(self, url, data, name);
  7124. }
  7125. alert(self.lang('uploadSuccess'));
  7126. } else {
  7127. alert(data.message);
  7128. }
  7129. },
  7130. afterError : function(html) {
  7131. dialog.hideLoading();
  7132. self.errorDialog(html);
  7133. }
  7134. });
  7135. uploadbutton.fileBox.change(function(e) {
  7136. dialog.showLoading(self.lang('uploadLoading'));
  7137. uploadbutton.submit();
  7138. });
  7139. } else {
  7140. K('.ke-upload-button', div).hide();
  7141. }
  7142. if (allowFileManager) {
  7143. viewServerBtn.click(function(e) {
  7144. self.loadPlugin('filemanager', function() {
  7145. self.plugin.filemanagerDialog({
  7146. viewType : 'LIST',
  7147. dirName : 'flash',
  7148. clickFn : function(url, title) {
  7149. if (self.dialogs.length > 1) {
  7150. K('[name="url"]', div).val(url);
  7151. if (self.afterSelectFile) {
  7152. self.afterSelectFile.call(self, url);
  7153. }
  7154. self.hideDialog();
  7155. }
  7156. }
  7157. });
  7158. });
  7159. });
  7160. } else {
  7161. viewServerBtn.hide();
  7162. }
  7163. var img = self.plugin.getSelectedFlash();
  7164. if (img) {
  7165. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7166. urlBox.val(attrs.src);
  7167. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7168. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7169. }
  7170. urlBox[0].focus();
  7171. urlBox[0].select();
  7172. },
  7173. 'delete' : function() {
  7174. self.plugin.getSelectedFlash().remove();
  7175. self.addBookmark();
  7176. }
  7177. };
  7178. self.clickToolbar(name, self.plugin.flash.edit);
  7179. });
  7180. /*******************************************************************************
  7181. * KindEditor - WYSIWYG HTML Editor for Internet
  7182. * Copyright (C) 2006-2011 kindsoft.net
  7183. *
  7184. * @author Roddy <luolonghao@gmail.com>
  7185. * @site http://www.kindsoft.net/
  7186. * @licence http://www.kindsoft.net/license.php
  7187. *******************************************************************************/
  7188. KindEditor.plugin('image', function(K) {
  7189. var self = this, name = 'image',
  7190. allowImageUpload = K.undef(self.allowImageUpload, true),
  7191. allowImageRemote = K.undef(self.allowImageRemote, true),
  7192. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7193. allowFileManager = K.undef(self.allowFileManager, false),
  7194. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7195. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7196. imgPath = self.pluginsPath + 'image/images/',
  7197. extraParams = K.undef(self.extraFileUploadParams, {}),
  7198. filePostName = K.undef(self.filePostName, 'imgFile'),
  7199. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7200. lang = self.lang(name + '.');
  7201. self.plugin.imageDialog = function(options) {
  7202. var imageUrl = options.imageUrl,
  7203. imageWidth = K.undef(options.imageWidth, ''),
  7204. imageHeight = K.undef(options.imageHeight, ''),
  7205. imageTitle = K.undef(options.imageTitle, ''),
  7206. imageAlign = K.undef(options.imageAlign, ''),
  7207. showRemote = K.undef(options.showRemote, true),
  7208. showLocal = K.undef(options.showLocal, true),
  7209. tabIndex = K.undef(options.tabIndex, 0),
  7210. clickFn = options.clickFn;
  7211. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7212. var hiddenElements = [];
  7213. for(var k in extraParams){
  7214. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7215. }
  7216. var html = [
  7217. '<div style="padding:20px;">',
  7218. '<div class="tabs"></div>',
  7219. '<div class="tab1" style="display:none;">',
  7220. '<div class="ke-dialog-row">',
  7221. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7222. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7223. '<span class="ke-button-common ke-button-outer">',
  7224. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7225. '</span>',
  7226. '</div>',
  7227. '<div class="ke-dialog-row">',
  7228. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7229. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7230. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7231. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7232. '</div>',
  7233. '<div class="ke-dialog-row">',
  7234. '<label style="width:60px;">' + lang.align + '</label>',
  7235. '<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="" />',
  7236. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7237. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7238. '</div>',
  7239. '<div class="ke-dialog-row">',
  7240. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7241. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7242. '</div>',
  7243. '</div>',
  7244. '<div class="tab2" style="display:none;">',
  7245. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7246. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7247. '<div class="ke-dialog-row">',
  7248. hiddenElements.join(''),
  7249. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7250. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7251. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7252. '</div>',
  7253. '</form>',
  7254. '</div>',
  7255. '</div>'
  7256. ].join('');
  7257. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7258. dialogHeight = showLocal && showRemote ? 300 : 250;
  7259. var dialog = self.createDialog({
  7260. name : name,
  7261. width : dialogWidth,
  7262. height : dialogHeight,
  7263. title : self.lang(name),
  7264. body : html,
  7265. yesBtn : {
  7266. name : self.lang('yes'),
  7267. click : function(e) {
  7268. if (dialog.isLoading) {
  7269. return;
  7270. }
  7271. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7272. if (uploadbutton.fileBox.val() == '') {
  7273. alert(self.lang('pleaseSelectFile'));
  7274. return;
  7275. }
  7276. dialog.showLoading(self.lang('uploadLoading'));
  7277. uploadbutton.submit();
  7278. localUrlBox.val('');
  7279. return;
  7280. }
  7281. var url = K.trim(urlBox.val()),
  7282. width = widthBox.val(),
  7283. height = heightBox.val(),
  7284. title = titleBox.val(),
  7285. align = '';
  7286. alignBox.each(function() {
  7287. if (this.checked) {
  7288. align = this.value;
  7289. return false;
  7290. }
  7291. });
  7292. if (url == 'http://' || K.invalidUrl(url)) {
  7293. alert(self.lang('invalidUrl'));
  7294. urlBox[0].focus();
  7295. return;
  7296. }
  7297. if (!/^\d*$/.test(width)) {
  7298. alert(self.lang('invalidWidth'));
  7299. widthBox[0].focus();
  7300. return;
  7301. }
  7302. if (!/^\d*$/.test(height)) {
  7303. alert(self.lang('invalidHeight'));
  7304. heightBox[0].focus();
  7305. return;
  7306. }
  7307. clickFn.call(self, url, title, width, height, 0, align);
  7308. }
  7309. },
  7310. beforeRemove : function() {
  7311. viewServerBtn.unbind();
  7312. widthBox.unbind();
  7313. heightBox.unbind();
  7314. refreshBtn.unbind();
  7315. }
  7316. }),
  7317. div = dialog.div;
  7318. var urlBox = K('[name="url"]', div),
  7319. localUrlBox = K('[name="localUrl"]', div),
  7320. viewServerBtn = K('[name="viewServer"]', div),
  7321. widthBox = K('.tab1 [name="width"]', div),
  7322. heightBox = K('.tab1 [name="height"]', div),
  7323. refreshBtn = K('.ke-refresh-btn', div),
  7324. titleBox = K('.tab1 [name="title"]', div),
  7325. alignBox = K('.tab1 [name="align"]', div);
  7326. var tabs;
  7327. if (showRemote && showLocal) {
  7328. tabs = K.tabs({
  7329. src : K('.tabs', div),
  7330. afterSelect : function(i) {}
  7331. });
  7332. tabs.add({
  7333. title : lang.remoteImage,
  7334. panel : K('.tab1', div)
  7335. });
  7336. tabs.add({
  7337. title : lang.localImage,
  7338. panel : K('.tab2', div)
  7339. });
  7340. tabs.select(tabIndex);
  7341. } else if (showRemote) {
  7342. K('.tab1', div).show();
  7343. } else if (showLocal) {
  7344. K('.tab2', div).show();
  7345. }
  7346. var uploadbutton = K.uploadbutton({
  7347. button : K('.ke-upload-button', div)[0],
  7348. fieldName : filePostName,
  7349. form : K('.ke-form', div),
  7350. target : target,
  7351. width: 60,
  7352. afterUpload : function(data) {
  7353. dialog.hideLoading();
  7354. if (data.error === 0) {
  7355. var url = data.url;
  7356. if (formatUploadUrl) {
  7357. url = K.formatUrl(url, 'absolute');
  7358. }
  7359. if (self.afterUpload) {
  7360. self.afterUpload.call(self, url, data, name);
  7361. }
  7362. if (!fillDescAfterUploadImage) {
  7363. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7364. } else {
  7365. K(".ke-dialog-row #remoteUrl", div).val(url);
  7366. K(".ke-tabs-li", div)[0].click();
  7367. K(".ke-refresh-btn", div).click();
  7368. }
  7369. } else {
  7370. alert(data.message);
  7371. }
  7372. },
  7373. afterError : function(html) {
  7374. dialog.hideLoading();
  7375. self.errorDialog(html);
  7376. }
  7377. });
  7378. uploadbutton.fileBox.change(function(e) {
  7379. localUrlBox.val(uploadbutton.fileBox.val());
  7380. });
  7381. if (allowFileManager) {
  7382. viewServerBtn.click(function(e) {
  7383. self.loadPlugin('filemanager', function() {
  7384. self.plugin.filemanagerDialog({
  7385. viewType : 'VIEW',
  7386. dirName : 'image',
  7387. clickFn : function(url, title) {
  7388. if (self.dialogs.length > 1) {
  7389. K('[name="url"]', div).val(url);
  7390. if (self.afterSelectFile) {
  7391. self.afterSelectFile.call(self, url);
  7392. }
  7393. self.hideDialog();
  7394. }
  7395. }
  7396. });
  7397. });
  7398. });
  7399. } else {
  7400. viewServerBtn.hide();
  7401. }
  7402. var originalWidth = 0, originalHeight = 0;
  7403. function setSize(width, height) {
  7404. widthBox.val(width);
  7405. heightBox.val(height);
  7406. originalWidth = width;
  7407. originalHeight = height;
  7408. }
  7409. refreshBtn.click(function(e) {
  7410. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7411. position : 'absolute',
  7412. visibility : 'hidden',
  7413. top : 0,
  7414. left : '-1000px'
  7415. });
  7416. tempImg.bind('load', function() {
  7417. setSize(tempImg.width(), tempImg.height());
  7418. tempImg.remove();
  7419. });
  7420. K(document.body).append(tempImg);
  7421. });
  7422. widthBox.change(function(e) {
  7423. if (originalWidth > 0) {
  7424. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7425. }
  7426. });
  7427. heightBox.change(function(e) {
  7428. if (originalHeight > 0) {
  7429. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7430. }
  7431. });
  7432. urlBox.val(options.imageUrl);
  7433. setSize(options.imageWidth, options.imageHeight);
  7434. titleBox.val(options.imageTitle);
  7435. alignBox.each(function() {
  7436. if (this.value === options.imageAlign) {
  7437. this.checked = true;
  7438. return false;
  7439. }
  7440. });
  7441. if (showRemote && tabIndex === 0) {
  7442. urlBox[0].focus();
  7443. urlBox[0].select();
  7444. }
  7445. return dialog;
  7446. };
  7447. self.plugin.image = {
  7448. edit : function() {
  7449. var img = self.plugin.getSelectedImage();
  7450. self.plugin.imageDialog({
  7451. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7452. imageWidth : img ? img.width() : '',
  7453. imageHeight : img ? img.height() : '',
  7454. imageTitle : img ? img.attr('title') : '',
  7455. imageAlign : img ? img.attr('align') : '',
  7456. showRemote : allowImageRemote,
  7457. showLocal : allowImageUpload,
  7458. tabIndex: img ? 0 : imageTabIndex,
  7459. clickFn : function(url, title, width, height, border, align) {
  7460. if (img) {
  7461. img.attr('src', url);
  7462. img.attr('data-ke-src', url);
  7463. img.attr('width', width);
  7464. img.attr('height', height);
  7465. img.attr('title', title);
  7466. img.attr('align', align);
  7467. img.attr('alt', title);
  7468. } else {
  7469. self.exec('insertimage', url, title, width, height, border, align);
  7470. }
  7471. setTimeout(function() {
  7472. self.hideDialog().focus();
  7473. }, 0);
  7474. }
  7475. });
  7476. },
  7477. 'delete' : function() {
  7478. var target = self.plugin.getSelectedImage();
  7479. if (target.parent().name == 'a') {
  7480. target = target.parent();
  7481. }
  7482. target.remove();
  7483. self.addBookmark();
  7484. }
  7485. };
  7486. self.clickToolbar(name, self.plugin.image.edit);
  7487. });
  7488. /*******************************************************************************
  7489. * KindEditor - WYSIWYG HTML Editor for Internet
  7490. * Copyright (C) 2006-2011 kindsoft.net
  7491. *
  7492. * @author Roddy <luolonghao@gmail.com>
  7493. * @site http://www.kindsoft.net/
  7494. * @licence http://www.kindsoft.net/license.php
  7495. *******************************************************************************/
  7496. KindEditor.plugin('insertfile', function(K) {
  7497. var self = this, name = 'insertfile',
  7498. allowFileUpload = K.undef(self.allowFileUpload, true),
  7499. allowFileManager = K.undef(self.allowFileManager, false),
  7500. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7501. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7502. extraParams = K.undef(self.extraFileUploadParams, {}),
  7503. filePostName = K.undef(self.filePostName, 'imgFile'),
  7504. lang = self.lang(name + '.');
  7505. self.plugin.fileDialog = function(options) {
  7506. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7507. fileTitle = K.undef(options.fileTitle, ''),
  7508. clickFn = options.clickFn;
  7509. var html = [
  7510. '<div style="padding:20px;">',
  7511. '<div class="ke-dialog-row">',
  7512. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7513. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7514. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7515. '<span class="ke-button-common ke-button-outer">',
  7516. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7517. '</span>',
  7518. '</div>',
  7519. '<div class="ke-dialog-row">',
  7520. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7521. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7522. '</div>',
  7523. '</form>',
  7524. '</div>'
  7525. ].join('');
  7526. var dialog = self.createDialog({
  7527. name : name,
  7528. width : 450,
  7529. title : self.lang(name),
  7530. body : html,
  7531. yesBtn : {
  7532. name : self.lang('yes'),
  7533. click : function(e) {
  7534. var url = K.trim(urlBox.val()),
  7535. title = titleBox.val();
  7536. if (url == 'http://' || K.invalidUrl(url)) {
  7537. alert(self.lang('invalidUrl'));
  7538. urlBox[0].focus();
  7539. return;
  7540. }
  7541. if (K.trim(title) === '') {
  7542. title = url;
  7543. }
  7544. clickFn.call(self, url, title);
  7545. }
  7546. }
  7547. }),
  7548. div = dialog.div;
  7549. var urlBox = K('[name="url"]', div),
  7550. viewServerBtn = K('[name="viewServer"]', div),
  7551. titleBox = K('[name="title"]', div);
  7552. if (allowFileUpload) {
  7553. var uploadbutton = K.uploadbutton({
  7554. button : K('.ke-upload-button', div)[0],
  7555. fieldName : filePostName,
  7556. url : K.addParam(uploadJson, 'dir=file'),
  7557. extraParams : extraParams,
  7558. afterUpload : function(data) {
  7559. dialog.hideLoading();
  7560. if (data.error === 0) {
  7561. var url = data.url;
  7562. if (formatUploadUrl) {
  7563. url = K.formatUrl(url, 'absolute');
  7564. }
  7565. urlBox.val(url);
  7566. if (self.afterUpload) {
  7567. self.afterUpload.call(self, url, data, name);
  7568. }
  7569. alert(self.lang('uploadSuccess'));
  7570. } else {
  7571. alert(data.message);
  7572. }
  7573. },
  7574. afterError : function(html) {
  7575. dialog.hideLoading();
  7576. self.errorDialog(html);
  7577. }
  7578. });
  7579. uploadbutton.fileBox.change(function(e) {
  7580. dialog.showLoading(self.lang('uploadLoading'));
  7581. uploadbutton.submit();
  7582. });
  7583. } else {
  7584. K('.ke-upload-button', div).hide();
  7585. }
  7586. if (allowFileManager) {
  7587. viewServerBtn.click(function(e) {
  7588. self.loadPlugin('filemanager', function() {
  7589. self.plugin.filemanagerDialog({
  7590. viewType : 'LIST',
  7591. dirName : 'file',
  7592. clickFn : function(url, title) {
  7593. if (self.dialogs.length > 1) {
  7594. K('[name="url"]', div).val(url);
  7595. if (self.afterSelectFile) {
  7596. self.afterSelectFile.call(self, url);
  7597. }
  7598. self.hideDialog();
  7599. }
  7600. }
  7601. });
  7602. });
  7603. });
  7604. } else {
  7605. viewServerBtn.hide();
  7606. }
  7607. urlBox.val(fileUrl);
  7608. titleBox.val(fileTitle);
  7609. urlBox[0].focus();
  7610. urlBox[0].select();
  7611. };
  7612. self.clickToolbar(name, function() {
  7613. self.plugin.fileDialog({
  7614. clickFn : function(url, title) {
  7615. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7616. self.insertHtml(html).hideDialog().focus();
  7617. }
  7618. });
  7619. });
  7620. });
  7621. /*******************************************************************************
  7622. * KindEditor - WYSIWYG HTML Editor for Internet
  7623. * Copyright (C) 2006-2011 kindsoft.net
  7624. *
  7625. * @author Roddy <luolonghao@gmail.com>
  7626. * @site http://www.kindsoft.net/
  7627. * @licence http://www.kindsoft.net/license.php
  7628. *******************************************************************************/
  7629. KindEditor.plugin('lineheight', function(K) {
  7630. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7631. self.clickToolbar(name, function() {
  7632. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7633. if (commonNode) {
  7634. curVal = commonNode.css('line-height');
  7635. }
  7636. var menu = self.createMenu({
  7637. name : name,
  7638. width : 150
  7639. });
  7640. K.each(lang.lineHeight, function(i, row) {
  7641. K.each(row, function(key, val) {
  7642. menu.addItem({
  7643. title : val,
  7644. checked : curVal === key,
  7645. click : function() {
  7646. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7647. span : '.line-height=' + key
  7648. });
  7649. self.updateState();
  7650. self.addBookmark();
  7651. self.hideMenu();
  7652. }
  7653. });
  7654. });
  7655. });
  7656. });
  7657. });
  7658. /*******************************************************************************
  7659. * KindEditor - WYSIWYG HTML Editor for Internet
  7660. * Copyright (C) 2006-2011 kindsoft.net
  7661. *
  7662. * @author Roddy <luolonghao@gmail.com>
  7663. * @site http://www.kindsoft.net/
  7664. * @licence http://www.kindsoft.net/license.php
  7665. *******************************************************************************/
  7666. KindEditor.plugin('link', function(K) {
  7667. var self = this, name = 'link';
  7668. self.plugin.link = {
  7669. edit : function() {
  7670. var lang = self.lang(name + '.'),
  7671. html = '<div style="padding:20px;">' +
  7672. '<div class="ke-dialog-row">' +
  7673. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7674. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7675. '<div class="ke-dialog-row"">' +
  7676. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7677. '<select id="keType" name="type"></select>' +
  7678. '</div>' +
  7679. '</div>',
  7680. dialog = self.createDialog({
  7681. name : name,
  7682. width : 450,
  7683. title : self.lang(name),
  7684. body : html,
  7685. yesBtn : {
  7686. name : self.lang('yes'),
  7687. click : function(e) {
  7688. var url = K.trim(urlBox.val());
  7689. if (url == 'http://' || K.invalidUrl(url)) {
  7690. alert(self.lang('invalidUrl'));
  7691. urlBox[0].focus();
  7692. return;
  7693. }
  7694. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7695. }
  7696. }
  7697. }),
  7698. div = dialog.div,
  7699. urlBox = K('input[name="url"]', div),
  7700. typeBox = K('select[name="type"]', div);
  7701. urlBox.val('http://');
  7702. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7703. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7704. self.cmd.selection();
  7705. var a = self.plugin.getSelectedLink();
  7706. if (a) {
  7707. self.cmd.range.selectNode(a[0]);
  7708. self.cmd.select();
  7709. urlBox.val(a.attr('data-ke-src'));
  7710. typeBox.val(a.attr('target'));
  7711. }
  7712. urlBox[0].focus();
  7713. urlBox[0].select();
  7714. },
  7715. 'delete' : function() {
  7716. self.exec('unlink', null);
  7717. }
  7718. };
  7719. self.clickToolbar(name, self.plugin.link.edit);
  7720. });
  7721. /*******************************************************************************
  7722. * KindEditor - WYSIWYG HTML Editor for Internet
  7723. * Copyright (C) 2006-2011 kindsoft.net
  7724. *
  7725. * @author Roddy <luolonghao@gmail.com>
  7726. * @site http://www.kindsoft.net/
  7727. * @licence http://www.kindsoft.net/license.php
  7728. *******************************************************************************/
  7729. KindEditor.plugin('media', function(K) {
  7730. var self = this, name = 'media', lang = self.lang(name + '.'),
  7731. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7732. allowFileManager = K.undef(self.allowFileManager, false),
  7733. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7734. extraParams = K.undef(self.extraFileUploadParams, {}),
  7735. filePostName = K.undef(self.filePostName, 'imgFile'),
  7736. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7737. self.plugin.media = {
  7738. edit : function() {
  7739. var html = [
  7740. '<div style="padding:20px;">',
  7741. '<div class="ke-dialog-row">',
  7742. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7743. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7744. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7745. '<span class="ke-button-common ke-button-outer">',
  7746. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7747. '</span>',
  7748. '</div>',
  7749. '<div class="ke-dialog-row">',
  7750. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7751. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7752. '</div>',
  7753. '<div class="ke-dialog-row">',
  7754. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7755. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7756. '</div>',
  7757. '<div class="ke-dialog-row">',
  7758. '<label for="keAutostart">' + lang.autostart + '</label>',
  7759. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7760. '</div>',
  7761. '</div>'
  7762. ].join('');
  7763. var dialog = self.createDialog({
  7764. name : name,
  7765. width : 450,
  7766. height : 230,
  7767. title : self.lang(name),
  7768. body : html,
  7769. yesBtn : {
  7770. name : self.lang('yes'),
  7771. click : function(e) {
  7772. var url = K.trim(urlBox.val()),
  7773. width = widthBox.val(),
  7774. height = heightBox.val();
  7775. if (url == 'http://' || K.invalidUrl(url)) {
  7776. alert(self.lang('invalidUrl'));
  7777. urlBox[0].focus();
  7778. return;
  7779. }
  7780. if (!/^\d*$/.test(width)) {
  7781. alert(self.lang('invalidWidth'));
  7782. widthBox[0].focus();
  7783. return;
  7784. }
  7785. if (!/^\d*$/.test(height)) {
  7786. alert(self.lang('invalidHeight'));
  7787. heightBox[0].focus();
  7788. return;
  7789. }
  7790. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7791. src : url,
  7792. type : K.mediaType(url),
  7793. width : width,
  7794. height : height,
  7795. autostart : autostartBox[0].checked ? 'true' : 'false',
  7796. loop : 'true'
  7797. });
  7798. self.insertHtml(html).hideDialog().focus();
  7799. }
  7800. }
  7801. }),
  7802. div = dialog.div,
  7803. urlBox = K('[name="url"]', div),
  7804. viewServerBtn = K('[name="viewServer"]', div),
  7805. widthBox = K('[name="width"]', div),
  7806. heightBox = K('[name="height"]', div),
  7807. autostartBox = K('[name="autostart"]', div);
  7808. urlBox.val('http://');
  7809. if (allowMediaUpload) {
  7810. var uploadbutton = K.uploadbutton({
  7811. button : K('.ke-upload-button', div)[0],
  7812. fieldName : filePostName,
  7813. extraParams : extraParams,
  7814. url : K.addParam(uploadJson, 'dir=media'),
  7815. afterUpload : function(data) {
  7816. dialog.hideLoading();
  7817. if (data.error === 0) {
  7818. var url = data.url;
  7819. if (formatUploadUrl) {
  7820. url = K.formatUrl(url, 'absolute');
  7821. }
  7822. urlBox.val(url);
  7823. if (self.afterUpload) {
  7824. self.afterUpload.call(self, url, data, name);
  7825. }
  7826. alert(self.lang('uploadSuccess'));
  7827. } else {
  7828. alert(data.message);
  7829. }
  7830. },
  7831. afterError : function(html) {
  7832. dialog.hideLoading();
  7833. self.errorDialog(html);
  7834. }
  7835. });
  7836. uploadbutton.fileBox.change(function(e) {
  7837. dialog.showLoading(self.lang('uploadLoading'));
  7838. uploadbutton.submit();
  7839. });
  7840. } else {
  7841. K('.ke-upload-button', div).hide();
  7842. }
  7843. if (allowFileManager) {
  7844. viewServerBtn.click(function(e) {
  7845. self.loadPlugin('filemanager', function() {
  7846. self.plugin.filemanagerDialog({
  7847. viewType : 'LIST',
  7848. dirName : 'media',
  7849. clickFn : function(url, title) {
  7850. if (self.dialogs.length > 1) {
  7851. K('[name="url"]', div).val(url);
  7852. if (self.afterSelectFile) {
  7853. self.afterSelectFile.call(self, url);
  7854. }
  7855. self.hideDialog();
  7856. }
  7857. }
  7858. });
  7859. });
  7860. });
  7861. } else {
  7862. viewServerBtn.hide();
  7863. }
  7864. var img = self.plugin.getSelectedMedia();
  7865. if (img) {
  7866. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7867. urlBox.val(attrs.src);
  7868. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7869. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7870. autostartBox[0].checked = (attrs.autostart === 'true');
  7871. }
  7872. urlBox[0].focus();
  7873. urlBox[0].select();
  7874. },
  7875. 'delete' : function() {
  7876. self.plugin.getSelectedMedia().remove();
  7877. self.addBookmark();
  7878. }
  7879. };
  7880. self.clickToolbar(name, self.plugin.media.edit);
  7881. });
  7882. /*******************************************************************************
  7883. * KindEditor - WYSIWYG HTML Editor for Internet
  7884. * Copyright (C) 2006-2011 kindsoft.net
  7885. *
  7886. * @author Roddy <luolonghao@gmail.com>
  7887. * @site http://www.kindsoft.net/
  7888. * @licence http://www.kindsoft.net/license.php
  7889. *******************************************************************************/
  7890. (function(K) {
  7891. function KSWFUpload(options) {
  7892. this.init(options);
  7893. }
  7894. K.extend(KSWFUpload, {
  7895. init : function(options) {
  7896. var self = this;
  7897. options.afterError = options.afterError || function(str) {
  7898. alert(str);
  7899. };
  7900. self.options = options;
  7901. self.progressbars = {};
  7902. self.div = K(options.container).html([
  7903. '<div class="ke-swfupload">',
  7904. '<div class="ke-swfupload-top">',
  7905. '<div class="ke-inline-block ke-swfupload-button">',
  7906. '<input type="button" value="Browse" />',
  7907. '</div>',
  7908. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7909. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7910. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7911. '</span>',
  7912. '</div>',
  7913. '<div class="ke-swfupload-body"></div>',
  7914. '</div>'
  7915. ].join(''));
  7916. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7917. function showError(itemDiv, msg) {
  7918. K('.ke-status > div', itemDiv).hide();
  7919. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7920. }
  7921. var settings = {
  7922. debug : false,
  7923. upload_url : options.uploadUrl,
  7924. flash_url : options.flashUrl,
  7925. file_post_name : options.filePostName,
  7926. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7927. button_image_url: options.buttonImageUrl,
  7928. button_width: options.buttonWidth,
  7929. button_height: options.buttonHeight,
  7930. button_cursor : SWFUpload.CURSOR.HAND,
  7931. file_types : options.fileTypes,
  7932. file_types_description : options.fileTypesDesc,
  7933. file_upload_limit : options.fileUploadLimit,
  7934. file_size_limit : options.fileSizeLimit,
  7935. post_params : options.postParams,
  7936. file_queued_handler : function(file) {
  7937. file.url = self.options.fileIconUrl;
  7938. self.appendFile(file);
  7939. },
  7940. file_queue_error_handler : function(file, errorCode, message) {
  7941. var errorName = '';
  7942. switch (errorCode) {
  7943. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7944. errorName = options.queueLimitExceeded;
  7945. break;
  7946. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7947. errorName = options.fileExceedsSizeLimit;
  7948. break;
  7949. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7950. errorName = options.zeroByteFile;
  7951. break;
  7952. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7953. errorName = options.invalidFiletype;
  7954. break;
  7955. default:
  7956. errorName = options.unknownError;
  7957. break;
  7958. }
  7959. K.DEBUG && alert(errorName);
  7960. },
  7961. upload_start_handler : function(file) {
  7962. var self = this;
  7963. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7964. K('.ke-status > div', itemDiv).hide();
  7965. K('.ke-progressbar', itemDiv).show();
  7966. },
  7967. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7968. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7969. var progressbar = self.progressbars[file.id];
  7970. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7971. progressbar.percent.html(percent + '%');
  7972. },
  7973. upload_error_handler : function(file, errorCode, message) {
  7974. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7975. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7976. showError(itemDiv, self.options.errorMessage);
  7977. }
  7978. },
  7979. upload_success_handler : function(file, serverData) {
  7980. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7981. var data = {};
  7982. try {
  7983. data = K.json(serverData);
  7984. } catch (e) {
  7985. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7986. }
  7987. if (data.error !== 0) {
  7988. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7989. return;
  7990. }
  7991. file.url = data.url;
  7992. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7993. K('.ke-status > div', itemDiv).hide();
  7994. }
  7995. };
  7996. self.swfu = new SWFUpload(settings);
  7997. K('.ke-swfupload-startupload input', self.div).click(function() {
  7998. self.swfu.startUpload();
  7999. });
  8000. },
  8001. getUrlList : function() {
  8002. var list = [];
  8003. K('.ke-img', self.bodyDiv).each(function() {
  8004. var img = K(this);
  8005. var status = img.attr('data-status');
  8006. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8007. list.push(img.data('data'));
  8008. }
  8009. });
  8010. return list;
  8011. },
  8012. removeFile : function(fileId) {
  8013. var self = this;
  8014. self.swfu.cancelUpload(fileId);
  8015. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8016. K('.ke-photo', itemDiv).unbind();
  8017. K('.ke-delete', itemDiv).unbind();
  8018. itemDiv.remove();
  8019. },
  8020. removeFiles : function() {
  8021. var self = this;
  8022. K('.ke-item', self.bodyDiv).each(function() {
  8023. self.removeFile(K(this).attr('data-id'));
  8024. });
  8025. },
  8026. appendFile : function(file) {
  8027. var self = this;
  8028. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8029. self.bodyDiv.append(itemDiv);
  8030. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8031. .mouseover(function(e) {
  8032. K(this).addClass('ke-on');
  8033. })
  8034. .mouseout(function(e) {
  8035. K(this).removeClass('ke-on');
  8036. });
  8037. itemDiv.append(photoDiv);
  8038. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8039. photoDiv.append(img);
  8040. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8041. self.removeFile(file.id);
  8042. });
  8043. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8044. K(['<div class="ke-progressbar">',
  8045. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8046. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8047. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8048. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8049. self.progressbars[file.id] = {
  8050. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8051. percent : K('.ke-progressbar-percent', photoDiv)
  8052. };
  8053. },
  8054. remove : function() {
  8055. this.removeFiles();
  8056. this.swfu.destroy();
  8057. this.div.html('');
  8058. }
  8059. });
  8060. K.swfupload = function(element, options) {
  8061. return new KSWFUpload(element, options);
  8062. };
  8063. })(KindEditor);
  8064. KindEditor.plugin('multiimage', function(K) {
  8065. var self = this, name = 'multiimage',
  8066. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8067. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8068. imgPath = self.pluginsPath + 'multiimage/images/',
  8069. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8070. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8071. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8072. filePostName = K.undef(self.filePostName, 'imgFile'),
  8073. lang = self.lang(name + '.');
  8074. self.plugin.multiImageDialog = function(options) {
  8075. var clickFn = options.clickFn,
  8076. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8077. var html = [
  8078. '<div style="padding:20px;">',
  8079. '<div class="swfupload">',
  8080. '</div>',
  8081. '</div>'
  8082. ].join('');
  8083. var dialog = self.createDialog({
  8084. name : name,
  8085. width : 650,
  8086. height : 510,
  8087. title : self.lang(name),
  8088. body : html,
  8089. previewBtn : {
  8090. name : lang.insertAll,
  8091. click : function(e) {
  8092. clickFn.call(self, swfupload.getUrlList());
  8093. }
  8094. },
  8095. yesBtn : {
  8096. name : lang.clearAll,
  8097. click : function(e) {
  8098. swfupload.removeFiles();
  8099. }
  8100. },
  8101. beforeRemove : function() {
  8102. if (!K.IE || K.V <= 8) {
  8103. swfupload.remove();
  8104. }
  8105. }
  8106. }),
  8107. div = dialog.div;
  8108. var swfupload = K.swfupload({
  8109. container : K('.swfupload', div),
  8110. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8111. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8112. buttonHeight : 23,
  8113. fileIconUrl : imgPath + 'image.png',
  8114. uploadDesc : uploadDesc,
  8115. startButtonValue : lang.startUpload,
  8116. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8117. flashUrl : imgPath + 'swfupload.swf',
  8118. filePostName : filePostName,
  8119. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8120. fileTypesDesc : 'Image Files',
  8121. fileUploadLimit : imageUploadLimit,
  8122. fileSizeLimit : imageSizeLimit,
  8123. postParams : K.undef(self.extraFileUploadParams, {}),
  8124. queueLimitExceeded : lang.queueLimitExceeded,
  8125. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8126. zeroByteFile : lang.zeroByteFile,
  8127. invalidFiletype : lang.invalidFiletype,
  8128. unknownError : lang.unknownError,
  8129. pendingMessage : lang.pending,
  8130. errorMessage : lang.uploadError,
  8131. afterError : function(html) {
  8132. self.errorDialog(html);
  8133. }
  8134. });
  8135. return dialog;
  8136. };
  8137. self.clickToolbar(name, function() {
  8138. self.plugin.multiImageDialog({
  8139. clickFn : function (urlList) {
  8140. if (urlList.length === 0) {
  8141. return;
  8142. }
  8143. K.each(urlList, function(i, data) {
  8144. if (self.afterUpload) {
  8145. self.afterUpload.call(self, data.url, data, 'multiimage');
  8146. }
  8147. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8148. });
  8149. setTimeout(function() {
  8150. self.hideDialog().focus();
  8151. }, 0);
  8152. }
  8153. });
  8154. });
  8155. });
  8156. /* ******************* */
  8157. /* Constructor & Init */
  8158. /* ******************* */
  8159. (function() {
  8160. window.SWFUpload = function (settings) {
  8161. this.initSWFUpload(settings);
  8162. };
  8163. SWFUpload.prototype.initSWFUpload = function (settings) {
  8164. try {
  8165. this.customSettings = {};
  8166. this.settings = settings;
  8167. this.eventQueue = [];
  8168. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8169. this.movieElement = null;
  8170. SWFUpload.instances[this.movieName] = this;
  8171. this.initSettings();
  8172. this.loadFlash();
  8173. this.displayDebugInfo();
  8174. } catch (ex) {
  8175. delete SWFUpload.instances[this.movieName];
  8176. throw ex;
  8177. }
  8178. };
  8179. /* *************** */
  8180. /* Static Members */
  8181. /* *************** */
  8182. SWFUpload.instances = {};
  8183. SWFUpload.movieCount = 0;
  8184. SWFUpload.version = "2.2.0 2009-03-25";
  8185. SWFUpload.QUEUE_ERROR = {
  8186. QUEUE_LIMIT_EXCEEDED : -100,
  8187. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8188. ZERO_BYTE_FILE : -120,
  8189. INVALID_FILETYPE : -130
  8190. };
  8191. SWFUpload.UPLOAD_ERROR = {
  8192. HTTP_ERROR : -200,
  8193. MISSING_UPLOAD_URL : -210,
  8194. IO_ERROR : -220,
  8195. SECURITY_ERROR : -230,
  8196. UPLOAD_LIMIT_EXCEEDED : -240,
  8197. UPLOAD_FAILED : -250,
  8198. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8199. FILE_VALIDATION_FAILED : -270,
  8200. FILE_CANCELLED : -280,
  8201. UPLOAD_STOPPED : -290
  8202. };
  8203. SWFUpload.FILE_STATUS = {
  8204. QUEUED : -1,
  8205. IN_PROGRESS : -2,
  8206. ERROR : -3,
  8207. COMPLETE : -4,
  8208. CANCELLED : -5
  8209. };
  8210. SWFUpload.BUTTON_ACTION = {
  8211. SELECT_FILE : -100,
  8212. SELECT_FILES : -110,
  8213. START_UPLOAD : -120
  8214. };
  8215. SWFUpload.CURSOR = {
  8216. ARROW : -1,
  8217. HAND : -2
  8218. };
  8219. SWFUpload.WINDOW_MODE = {
  8220. WINDOW : "window",
  8221. TRANSPARENT : "transparent",
  8222. OPAQUE : "opaque"
  8223. };
  8224. SWFUpload.completeURL = function(url) {
  8225. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8226. return url;
  8227. }
  8228. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8229. var indexSlash = window.location.pathname.lastIndexOf("/");
  8230. var path;
  8231. if (indexSlash <= 0) {
  8232. path = "/";
  8233. } else {
  8234. path = window.location.pathname.substr(0, indexSlash) + "/";
  8235. }
  8236. return /*currentURL +*/ path + url;
  8237. };
  8238. /* ******************** */
  8239. /* Instance Members */
  8240. /* ******************** */
  8241. SWFUpload.prototype.initSettings = function () {
  8242. this.ensureDefault = function (settingName, defaultValue) {
  8243. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8244. };
  8245. this.ensureDefault("upload_url", "");
  8246. this.ensureDefault("preserve_relative_urls", false);
  8247. this.ensureDefault("file_post_name", "Filedata");
  8248. this.ensureDefault("post_params", {});
  8249. this.ensureDefault("use_query_string", false);
  8250. this.ensureDefault("requeue_on_error", false);
  8251. this.ensureDefault("http_success", []);
  8252. this.ensureDefault("assume_success_timeout", 0);
  8253. this.ensureDefault("file_types", "*.*");
  8254. this.ensureDefault("file_types_description", "All Files");
  8255. this.ensureDefault("file_size_limit", 0);
  8256. this.ensureDefault("file_upload_limit", 0);
  8257. this.ensureDefault("file_queue_limit", 0);
  8258. this.ensureDefault("flash_url", "swfupload.swf");
  8259. this.ensureDefault("prevent_swf_caching", true);
  8260. this.ensureDefault("button_image_url", "");
  8261. this.ensureDefault("button_width", 1);
  8262. this.ensureDefault("button_height", 1);
  8263. this.ensureDefault("button_text", "");
  8264. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8265. this.ensureDefault("button_text_top_padding", 0);
  8266. this.ensureDefault("button_text_left_padding", 0);
  8267. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8268. this.ensureDefault("button_disabled", false);
  8269. this.ensureDefault("button_placeholder_id", "");
  8270. this.ensureDefault("button_placeholder", null);
  8271. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8272. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8273. this.ensureDefault("debug", false);
  8274. this.settings.debug_enabled = this.settings.debug;
  8275. this.settings.return_upload_start_handler = this.returnUploadStart;
  8276. this.ensureDefault("swfupload_loaded_handler", null);
  8277. this.ensureDefault("file_dialog_start_handler", null);
  8278. this.ensureDefault("file_queued_handler", null);
  8279. this.ensureDefault("file_queue_error_handler", null);
  8280. this.ensureDefault("file_dialog_complete_handler", null);
  8281. this.ensureDefault("upload_start_handler", null);
  8282. this.ensureDefault("upload_progress_handler", null);
  8283. this.ensureDefault("upload_error_handler", null);
  8284. this.ensureDefault("upload_success_handler", null);
  8285. this.ensureDefault("upload_complete_handler", null);
  8286. this.ensureDefault("debug_handler", this.debugMessage);
  8287. this.ensureDefault("custom_settings", {});
  8288. this.customSettings = this.settings.custom_settings;
  8289. if (!!this.settings.prevent_swf_caching) {
  8290. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8291. }
  8292. if (!this.settings.preserve_relative_urls) {
  8293. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8294. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8295. }
  8296. delete this.ensureDefault;
  8297. };
  8298. SWFUpload.prototype.loadFlash = function () {
  8299. var targetElement, tempParent;
  8300. if (document.getElementById(this.movieName) !== null) {
  8301. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8302. }
  8303. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8304. if (targetElement == undefined) {
  8305. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8306. }
  8307. tempParent = document.createElement("div");
  8308. tempParent.innerHTML = this.getFlashHTML();
  8309. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8310. if (window[this.movieName] == undefined) {
  8311. window[this.movieName] = this.getMovieElement();
  8312. }
  8313. };
  8314. SWFUpload.prototype.getFlashHTML = function () {
  8315. var classid = '';
  8316. if (KindEditor.IE && KindEditor.V > 8) {
  8317. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8318. }
  8319. 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">',
  8320. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8321. '<param name="movie" value="', this.settings.flash_url, '" />',
  8322. '<param name="quality" value="high" />',
  8323. '<param name="menu" value="false" />',
  8324. '<param name="allowScriptAccess" value="always" />',
  8325. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8326. '</object>'].join("");
  8327. };
  8328. SWFUpload.prototype.getFlashVars = function () {
  8329. var paramString = this.buildParamString();
  8330. var httpSuccessString = this.settings.http_success.join(",");
  8331. return ["movieName=", encodeURIComponent(this.movieName),
  8332. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8333. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8334. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8335. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8336. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8337. "&amp;params=", encodeURIComponent(paramString),
  8338. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8339. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8340. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8341. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8342. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8343. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8344. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8345. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8346. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8347. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8348. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8349. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8350. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8351. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8352. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8353. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8354. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8355. ].join("");
  8356. };
  8357. SWFUpload.prototype.getMovieElement = function () {
  8358. if (this.movieElement == undefined) {
  8359. this.movieElement = document.getElementById(this.movieName);
  8360. }
  8361. if (this.movieElement === null) {
  8362. throw "Could not find Flash element";
  8363. }
  8364. return this.movieElement;
  8365. };
  8366. SWFUpload.prototype.buildParamString = function () {
  8367. var postParams = this.settings.post_params;
  8368. var paramStringPairs = [];
  8369. if (typeof(postParams) === "object") {
  8370. for (var name in postParams) {
  8371. if (postParams.hasOwnProperty(name)) {
  8372. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8373. }
  8374. }
  8375. }
  8376. return paramStringPairs.join("&amp;");
  8377. };
  8378. SWFUpload.prototype.destroy = function () {
  8379. try {
  8380. this.cancelUpload(null, false);
  8381. var movieElement = null;
  8382. movieElement = this.getMovieElement();
  8383. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8384. for (var i in movieElement) {
  8385. try {
  8386. if (typeof(movieElement[i]) === "function") {
  8387. movieElement[i] = null;
  8388. }
  8389. } catch (ex1) {}
  8390. }
  8391. try {
  8392. movieElement.parentNode.removeChild(movieElement);
  8393. } catch (ex) {}
  8394. }
  8395. window[this.movieName] = null;
  8396. SWFUpload.instances[this.movieName] = null;
  8397. delete SWFUpload.instances[this.movieName];
  8398. this.movieElement = null;
  8399. this.settings = null;
  8400. this.customSettings = null;
  8401. this.eventQueue = null;
  8402. this.movieName = null;
  8403. return true;
  8404. } catch (ex2) {
  8405. return false;
  8406. }
  8407. };
  8408. SWFUpload.prototype.displayDebugInfo = function () {
  8409. this.debug(
  8410. [
  8411. "---SWFUpload Instance Info---\n",
  8412. "Version: ", SWFUpload.version, "\n",
  8413. "Movie Name: ", this.movieName, "\n",
  8414. "Settings:\n",
  8415. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8416. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8417. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8418. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8419. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8420. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8421. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8422. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8423. "\t", "file_types: ", this.settings.file_types, "\n",
  8424. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8425. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8426. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8427. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8428. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8429. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8430. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8431. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8432. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8433. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8434. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8435. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8436. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8437. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8438. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8439. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8440. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8441. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8442. "Event Handlers:\n",
  8443. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8444. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8445. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8446. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8447. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8448. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8449. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8450. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8451. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8452. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8453. ].join("")
  8454. );
  8455. };
  8456. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8457. the maintain v2 API compatibility
  8458. */
  8459. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8460. if (value == undefined) {
  8461. return (this.settings[name] = default_value);
  8462. } else {
  8463. return (this.settings[name] = value);
  8464. }
  8465. };
  8466. SWFUpload.prototype.getSetting = function (name) {
  8467. if (this.settings[name] != undefined) {
  8468. return this.settings[name];
  8469. }
  8470. return "";
  8471. };
  8472. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8473. argumentArray = argumentArray || [];
  8474. var movieElement = this.getMovieElement();
  8475. var returnValue, returnString;
  8476. try {
  8477. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8478. returnValue = eval(returnString);
  8479. } catch (ex) {
  8480. throw "Call to " + functionName + " failed";
  8481. }
  8482. if (returnValue != undefined && typeof returnValue.post === "object") {
  8483. returnValue = this.unescapeFilePostParams(returnValue);
  8484. }
  8485. return returnValue;
  8486. };
  8487. /* *****************************
  8488. -- Flash control methods --
  8489. Your UI should use these
  8490. to operate SWFUpload
  8491. ***************************** */
  8492. SWFUpload.prototype.selectFile = function () {
  8493. this.callFlash("SelectFile");
  8494. };
  8495. SWFUpload.prototype.selectFiles = function () {
  8496. this.callFlash("SelectFiles");
  8497. };
  8498. SWFUpload.prototype.startUpload = function (fileID) {
  8499. this.callFlash("StartUpload", [fileID]);
  8500. };
  8501. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8502. if (triggerErrorEvent !== false) {
  8503. triggerErrorEvent = true;
  8504. }
  8505. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8506. };
  8507. SWFUpload.prototype.stopUpload = function () {
  8508. this.callFlash("StopUpload");
  8509. };
  8510. /* ************************
  8511. * Settings methods
  8512. * These methods change the SWFUpload settings.
  8513. * SWFUpload settings should not be changed directly on the settings object
  8514. * since many of the settings need to be passed to Flash in order to take
  8515. * effect.
  8516. * *********************** */
  8517. SWFUpload.prototype.getStats = function () {
  8518. return this.callFlash("GetStats");
  8519. };
  8520. SWFUpload.prototype.setStats = function (statsObject) {
  8521. this.callFlash("SetStats", [statsObject]);
  8522. };
  8523. SWFUpload.prototype.getFile = function (fileID) {
  8524. if (typeof(fileID) === "number") {
  8525. return this.callFlash("GetFileByIndex", [fileID]);
  8526. } else {
  8527. return this.callFlash("GetFile", [fileID]);
  8528. }
  8529. };
  8530. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8531. return this.callFlash("AddFileParam", [fileID, name, value]);
  8532. };
  8533. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8534. this.callFlash("RemoveFileParam", [fileID, name]);
  8535. };
  8536. SWFUpload.prototype.setUploadURL = function (url) {
  8537. this.settings.upload_url = url.toString();
  8538. this.callFlash("SetUploadURL", [url]);
  8539. };
  8540. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8541. this.settings.post_params = paramsObject;
  8542. this.callFlash("SetPostParams", [paramsObject]);
  8543. };
  8544. SWFUpload.prototype.addPostParam = function (name, value) {
  8545. this.settings.post_params[name] = value;
  8546. this.callFlash("SetPostParams", [this.settings.post_params]);
  8547. };
  8548. SWFUpload.prototype.removePostParam = function (name) {
  8549. delete this.settings.post_params[name];
  8550. this.callFlash("SetPostParams", [this.settings.post_params]);
  8551. };
  8552. SWFUpload.prototype.setFileTypes = function (types, description) {
  8553. this.settings.file_types = types;
  8554. this.settings.file_types_description = description;
  8555. this.callFlash("SetFileTypes", [types, description]);
  8556. };
  8557. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8558. this.settings.file_size_limit = fileSizeLimit;
  8559. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8560. };
  8561. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8562. this.settings.file_upload_limit = fileUploadLimit;
  8563. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8564. };
  8565. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8566. this.settings.file_queue_limit = fileQueueLimit;
  8567. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8568. };
  8569. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8570. this.settings.file_post_name = filePostName;
  8571. this.callFlash("SetFilePostName", [filePostName]);
  8572. };
  8573. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8574. this.settings.use_query_string = useQueryString;
  8575. this.callFlash("SetUseQueryString", [useQueryString]);
  8576. };
  8577. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8578. this.settings.requeue_on_error = requeueOnError;
  8579. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8580. };
  8581. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8582. if (typeof http_status_codes === "string") {
  8583. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8584. }
  8585. this.settings.http_success = http_status_codes;
  8586. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8587. };
  8588. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8589. this.settings.assume_success_timeout = timeout_seconds;
  8590. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8591. };
  8592. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8593. this.settings.debug_enabled = debugEnabled;
  8594. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8595. };
  8596. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8597. if (buttonImageURL == undefined) {
  8598. buttonImageURL = "";
  8599. }
  8600. this.settings.button_image_url = buttonImageURL;
  8601. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8602. };
  8603. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8604. this.settings.button_width = width;
  8605. this.settings.button_height = height;
  8606. var movie = this.getMovieElement();
  8607. if (movie != undefined) {
  8608. movie.style.width = width + "px";
  8609. movie.style.height = height + "px";
  8610. }
  8611. this.callFlash("SetButtonDimensions", [width, height]);
  8612. };
  8613. SWFUpload.prototype.setButtonText = function (html) {
  8614. this.settings.button_text = html;
  8615. this.callFlash("SetButtonText", [html]);
  8616. };
  8617. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8618. this.settings.button_text_top_padding = top;
  8619. this.settings.button_text_left_padding = left;
  8620. this.callFlash("SetButtonTextPadding", [left, top]);
  8621. };
  8622. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8623. this.settings.button_text_style = css;
  8624. this.callFlash("SetButtonTextStyle", [css]);
  8625. };
  8626. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8627. this.settings.button_disabled = isDisabled;
  8628. this.callFlash("SetButtonDisabled", [isDisabled]);
  8629. };
  8630. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8631. this.settings.button_action = buttonAction;
  8632. this.callFlash("SetButtonAction", [buttonAction]);
  8633. };
  8634. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8635. this.settings.button_cursor = cursor;
  8636. this.callFlash("SetButtonCursor", [cursor]);
  8637. };
  8638. /* *******************************
  8639. Flash Event Interfaces
  8640. These functions are used by Flash to trigger the various
  8641. events.
  8642. All these functions a Private.
  8643. Because the ExternalInterface library is buggy the event calls
  8644. are added to a queue and the queue then executed by a setTimeout.
  8645. This ensures that events are executed in a determinate order and that
  8646. the ExternalInterface bugs are avoided.
  8647. ******************************* */
  8648. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8649. if (argumentArray == undefined) {
  8650. argumentArray = [];
  8651. } else if (!(argumentArray instanceof Array)) {
  8652. argumentArray = [argumentArray];
  8653. }
  8654. var self = this;
  8655. if (typeof this.settings[handlerName] === "function") {
  8656. this.eventQueue.push(function () {
  8657. this.settings[handlerName].apply(this, argumentArray);
  8658. });
  8659. setTimeout(function () {
  8660. self.executeNextEvent();
  8661. }, 0);
  8662. } else if (this.settings[handlerName] !== null) {
  8663. throw "Event handler " + handlerName + " is unknown or is not a function";
  8664. }
  8665. };
  8666. SWFUpload.prototype.executeNextEvent = function () {
  8667. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8668. if (typeof(f) === "function") {
  8669. f.apply(this);
  8670. }
  8671. };
  8672. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8673. var reg = /[$]([0-9a-f]{4})/i;
  8674. var unescapedPost = {};
  8675. var uk;
  8676. if (file != undefined) {
  8677. for (var k in file.post) {
  8678. if (file.post.hasOwnProperty(k)) {
  8679. uk = k;
  8680. var match;
  8681. while ((match = reg.exec(uk)) !== null) {
  8682. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8683. }
  8684. unescapedPost[uk] = file.post[k];
  8685. }
  8686. }
  8687. file.post = unescapedPost;
  8688. }
  8689. return file;
  8690. };
  8691. SWFUpload.prototype.testExternalInterface = function () {
  8692. try {
  8693. return this.callFlash("TestExternalInterface");
  8694. } catch (ex) {
  8695. return false;
  8696. }
  8697. };
  8698. SWFUpload.prototype.flashReady = function () {
  8699. var movieElement = this.getMovieElement();
  8700. if (!movieElement) {
  8701. this.debug("Flash called back ready but the flash movie can't be found.");
  8702. return;
  8703. }
  8704. this.cleanUp(movieElement);
  8705. this.queueEvent("swfupload_loaded_handler");
  8706. };
  8707. SWFUpload.prototype.cleanUp = function (movieElement) {
  8708. try {
  8709. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8710. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8711. for (var key in movieElement) {
  8712. try {
  8713. if (typeof(movieElement[key]) === "function") {
  8714. movieElement[key] = null;
  8715. }
  8716. } catch (ex) {
  8717. }
  8718. }
  8719. }
  8720. } catch (ex1) {
  8721. }
  8722. window["__flash__removeCallback"] = function (instance, name) {
  8723. try {
  8724. if (instance) {
  8725. instance[name] = null;
  8726. }
  8727. } catch (flashEx) {
  8728. }
  8729. };
  8730. };
  8731. /* This is a chance to do something before the browse window opens */
  8732. SWFUpload.prototype.fileDialogStart = function () {
  8733. this.queueEvent("file_dialog_start_handler");
  8734. };
  8735. /* Called when a file is successfully added to the queue. */
  8736. SWFUpload.prototype.fileQueued = function (file) {
  8737. file = this.unescapeFilePostParams(file);
  8738. this.queueEvent("file_queued_handler", file);
  8739. };
  8740. /* Handle errors that occur when an attempt to queue a file fails. */
  8741. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8742. file = this.unescapeFilePostParams(file);
  8743. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8744. };
  8745. /* Called after the file dialog has closed and the selected files have been queued.
  8746. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8747. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8748. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8749. };
  8750. SWFUpload.prototype.uploadStart = function (file) {
  8751. file = this.unescapeFilePostParams(file);
  8752. this.queueEvent("return_upload_start_handler", file);
  8753. };
  8754. SWFUpload.prototype.returnUploadStart = function (file) {
  8755. var returnValue;
  8756. if (typeof this.settings.upload_start_handler === "function") {
  8757. file = this.unescapeFilePostParams(file);
  8758. returnValue = this.settings.upload_start_handler.call(this, file);
  8759. } else if (this.settings.upload_start_handler != undefined) {
  8760. throw "upload_start_handler must be a function";
  8761. }
  8762. if (returnValue === undefined) {
  8763. returnValue = true;
  8764. }
  8765. returnValue = !!returnValue;
  8766. this.callFlash("ReturnUploadStart", [returnValue]);
  8767. };
  8768. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8769. file = this.unescapeFilePostParams(file);
  8770. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8771. };
  8772. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8773. file = this.unescapeFilePostParams(file);
  8774. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8775. };
  8776. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8777. file = this.unescapeFilePostParams(file);
  8778. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8779. };
  8780. SWFUpload.prototype.uploadComplete = function (file) {
  8781. file = this.unescapeFilePostParams(file);
  8782. this.queueEvent("upload_complete_handler", file);
  8783. };
  8784. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8785. internal debug console. You can override this event and have messages written where you want. */
  8786. SWFUpload.prototype.debug = function (message) {
  8787. this.queueEvent("debug_handler", message);
  8788. };
  8789. /* **********************************
  8790. Debug Console
  8791. The debug console is a self contained, in page location
  8792. for debug message to be sent. The Debug Console adds
  8793. itself to the body if necessary.
  8794. The console is automatically scrolled as messages appear.
  8795. If you are using your own debug handler or when you deploy to production and
  8796. have debug disabled you can remove these functions to reduce the file size
  8797. and complexity.
  8798. ********************************** */
  8799. SWFUpload.prototype.debugMessage = function (message) {
  8800. if (this.settings.debug) {
  8801. var exceptionMessage, exceptionValues = [];
  8802. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8803. for (var key in message) {
  8804. if (message.hasOwnProperty(key)) {
  8805. exceptionValues.push(key + ": " + message[key]);
  8806. }
  8807. }
  8808. exceptionMessage = exceptionValues.join("\n") || "";
  8809. exceptionValues = exceptionMessage.split("\n");
  8810. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8811. SWFUpload.Console.writeLine(exceptionMessage);
  8812. } else {
  8813. SWFUpload.Console.writeLine(message);
  8814. }
  8815. }
  8816. };
  8817. SWFUpload.Console = {};
  8818. SWFUpload.Console.writeLine = function (message) {
  8819. var console, documentForm;
  8820. try {
  8821. console = document.getElementById("SWFUpload_Console");
  8822. if (!console) {
  8823. documentForm = document.createElement("form");
  8824. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8825. console = document.createElement("textarea");
  8826. console.id = "SWFUpload_Console";
  8827. console.style.fontFamily = "monospace";
  8828. console.setAttribute("wrap", "off");
  8829. console.wrap = "off";
  8830. console.style.overflow = "auto";
  8831. console.style.width = "700px";
  8832. console.style.height = "350px";
  8833. console.style.margin = "5px";
  8834. documentForm.appendChild(console);
  8835. }
  8836. console.value += message + "\n";
  8837. console.scrollTop = console.scrollHeight - console.clientHeight;
  8838. } catch (ex) {
  8839. alert("Exception: " + ex.name + " Message: " + ex.message);
  8840. }
  8841. };
  8842. })();
  8843. (function() {
  8844. /*
  8845. Queue Plug-in
  8846. Features:
  8847. *Adds a cancelQueue() method for cancelling the entire queue.
  8848. *All queued files are uploaded when startUpload() is called.
  8849. *If false is returned from uploadComplete then the queue upload is stopped.
  8850. If false is not returned (strict comparison) then the queue upload is continued.
  8851. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8852. Set the event handler with the queue_complete_handler setting.
  8853. */
  8854. if (typeof(SWFUpload) === "function") {
  8855. SWFUpload.queue = {};
  8856. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8857. return function () {
  8858. if (typeof(oldInitSettings) === "function") {
  8859. oldInitSettings.call(this);
  8860. }
  8861. this.queueSettings = {};
  8862. this.queueSettings.queue_cancelled_flag = false;
  8863. this.queueSettings.queue_upload_count = 0;
  8864. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8865. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8866. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8867. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8868. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8869. };
  8870. })(SWFUpload.prototype.initSettings);
  8871. SWFUpload.prototype.startUpload = function (fileID) {
  8872. this.queueSettings.queue_cancelled_flag = false;
  8873. this.callFlash("StartUpload", [fileID]);
  8874. };
  8875. SWFUpload.prototype.cancelQueue = function () {
  8876. this.queueSettings.queue_cancelled_flag = true;
  8877. this.stopUpload();
  8878. var stats = this.getStats();
  8879. while (stats.files_queued > 0) {
  8880. this.cancelUpload();
  8881. stats = this.getStats();
  8882. }
  8883. };
  8884. SWFUpload.queue.uploadStartHandler = function (file) {
  8885. var returnValue;
  8886. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8887. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8888. }
  8889. returnValue = (returnValue === false) ? false : true;
  8890. this.queueSettings.queue_cancelled_flag = !returnValue;
  8891. return returnValue;
  8892. };
  8893. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8894. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8895. var continueUpload;
  8896. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8897. this.queueSettings.queue_upload_count++;
  8898. }
  8899. if (typeof(user_upload_complete_handler) === "function") {
  8900. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8901. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8902. continueUpload = false;
  8903. } else {
  8904. continueUpload = true;
  8905. }
  8906. if (continueUpload) {
  8907. var stats = this.getStats();
  8908. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8909. this.startUpload();
  8910. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8911. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8912. this.queueSettings.queue_upload_count = 0;
  8913. } else {
  8914. this.queueSettings.queue_cancelled_flag = false;
  8915. this.queueSettings.queue_upload_count = 0;
  8916. }
  8917. }
  8918. };
  8919. }
  8920. })();
  8921. /*******************************************************************************
  8922. * KindEditor - WYSIWYG HTML Editor for Internet
  8923. * Copyright (C) 2006-2011 kindsoft.net
  8924. *
  8925. * @author Roddy <luolonghao@gmail.com>
  8926. * @site http://www.kindsoft.net/
  8927. * @licence http://www.kindsoft.net/license.php
  8928. *******************************************************************************/
  8929. KindEditor.plugin('pagebreak', function(K) {
  8930. var self = this;
  8931. var name = 'pagebreak';
  8932. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8933. self.clickToolbar(name, function() {
  8934. var cmd = self.cmd, range = cmd.range;
  8935. self.focus();
  8936. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8937. self.insertHtml(pagebreakHtml + tail);
  8938. if (tail !== '') {
  8939. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8940. range.selectNodeContents(p[0]);
  8941. p.removeAttr('id');
  8942. cmd.select();
  8943. }
  8944. });
  8945. });
  8946. /*******************************************************************************
  8947. * KindEditor - WYSIWYG HTML Editor for Internet
  8948. * Copyright (C) 2006-2011 kindsoft.net
  8949. *
  8950. * @author Roddy <luolonghao@gmail.com>
  8951. * @site http://www.kindsoft.net/
  8952. * @licence http://www.kindsoft.net/license.php
  8953. *******************************************************************************/
  8954. KindEditor.plugin('plainpaste', function(K) {
  8955. var self = this, name = 'plainpaste';
  8956. self.clickToolbar(name, function() {
  8957. var lang = self.lang(name + '.'),
  8958. html = '<div style="padding:10px 20px;">' +
  8959. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  8960. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  8961. '</div>',
  8962. dialog = self.createDialog({
  8963. name : name,
  8964. width : 450,
  8965. title : self.lang(name),
  8966. body : html,
  8967. yesBtn : {
  8968. name : self.lang('yes'),
  8969. click : function(e) {
  8970. var html = textarea.val();
  8971. html = K.escape(html);
  8972. html = html.replace(/ {2}/g, ' &nbsp;');
  8973. if (self.newlineTag == 'p') {
  8974. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  8975. } else {
  8976. html = html.replace(/\n/g, '<br />$&');
  8977. }
  8978. self.insertHtml(html).hideDialog().focus();
  8979. }
  8980. }
  8981. }),
  8982. textarea = K('textarea', dialog.div);
  8983. textarea[0].focus();
  8984. });
  8985. });
  8986. /*******************************************************************************
  8987. * KindEditor - WYSIWYG HTML Editor for Internet
  8988. * Copyright (C) 2006-2011 kindsoft.net
  8989. *
  8990. * @author Roddy <luolonghao@gmail.com>
  8991. * @site http://www.kindsoft.net/
  8992. * @licence http://www.kindsoft.net/license.php
  8993. *******************************************************************************/
  8994. KindEditor.plugin('preview', function(K) {
  8995. var self = this, name = 'preview', undefined;
  8996. self.clickToolbar(name, function() {
  8997. var lang = self.lang(name + '.'),
  8998. html = '<div style="padding:10px 20px;">' +
  8999. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9000. '</div>',
  9001. dialog = self.createDialog({
  9002. name : name,
  9003. width : 750,
  9004. title : self.lang(name),
  9005. body : html
  9006. }),
  9007. iframe = K('iframe', dialog.div),
  9008. doc = K.iframeDoc(iframe);
  9009. doc.open();
  9010. doc.write(self.fullHtml());
  9011. doc.close();
  9012. K(doc.body).css('background-color', '#FFF');
  9013. iframe[0].contentWindow.focus();
  9014. });
  9015. });
  9016. /*******************************************************************************
  9017. * KindEditor - WYSIWYG HTML Editor for Internet
  9018. * Copyright (C) 2006-2011 kindsoft.net
  9019. *
  9020. * @author Roddy <luolonghao@gmail.com>
  9021. * @site http://www.kindsoft.net/
  9022. * @licence http://www.kindsoft.net/license.php
  9023. *******************************************************************************/
  9024. KindEditor.plugin('quickformat', function(K) {
  9025. var self = this, name = 'quickformat',
  9026. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9027. function getFirstChild(knode) {
  9028. var child = knode.first();
  9029. while (child && child.first()) {
  9030. child = child.first();
  9031. }
  9032. return child;
  9033. }
  9034. self.clickToolbar(name, function() {
  9035. self.focus();
  9036. var doc = self.edit.doc,
  9037. range = self.cmd.range,
  9038. child = K(doc.body).first(), next,
  9039. nodeList = [], subList = [],
  9040. bookmark = range.createBookmark(true);
  9041. while(child) {
  9042. next = child.next();
  9043. var firstChild = getFirstChild(child);
  9044. if (!firstChild || firstChild.name != 'img') {
  9045. if (blockMap[child.name]) {
  9046. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9047. child.css('text-indent', '2em');
  9048. } else {
  9049. subList.push(child);
  9050. }
  9051. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9052. if (subList.length > 0) {
  9053. nodeList.push(subList);
  9054. }
  9055. subList = [];
  9056. }
  9057. }
  9058. child = next;
  9059. }
  9060. K.each(nodeList, function(i, subList) {
  9061. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9062. subList[0].before(wrapper);
  9063. K.each(subList, function(i, knode) {
  9064. wrapper.append(knode);
  9065. });
  9066. });
  9067. range.moveToBookmark(bookmark);
  9068. self.addBookmark();
  9069. });
  9070. });
  9071. /*******************************************************************************
  9072. * KindEditor - WYSIWYG HTML Editor for Internet
  9073. * Copyright (C) 2006-2011 kindsoft.net
  9074. *
  9075. * @author Roddy <luolonghao@gmail.com>
  9076. * @site http://www.kindsoft.net/
  9077. * @licence http://www.kindsoft.net/license.php
  9078. *******************************************************************************/
  9079. KindEditor.plugin('table', function(K) {
  9080. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9081. function _setColor(box, color) {
  9082. color = color.toUpperCase();
  9083. box.css('background-color', color);
  9084. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9085. box.html(color);
  9086. }
  9087. var pickerList = [];
  9088. function _initColorPicker(dialogDiv, colorBox) {
  9089. colorBox.bind('click,mousedown', function(e){
  9090. e.stopPropagation();
  9091. });
  9092. function removePicker() {
  9093. K.each(pickerList, function() {
  9094. this.remove();
  9095. });
  9096. pickerList = [];
  9097. K(document).unbind('click,mousedown', removePicker);
  9098. dialogDiv.unbind('click,mousedown', removePicker);
  9099. }
  9100. colorBox.click(function(e) {
  9101. removePicker();
  9102. var box = K(this),
  9103. pos = box.pos();
  9104. var picker = K.colorpicker({
  9105. x : pos.x,
  9106. y : pos.y + box.height(),
  9107. z : 811214,
  9108. selectedColor : K(this).html(),
  9109. colors : self.colorTable,
  9110. noColor : self.lang('noColor'),
  9111. shadowMode : self.shadowMode,
  9112. click : function(color) {
  9113. _setColor(box, color);
  9114. removePicker();
  9115. }
  9116. });
  9117. pickerList.push(picker);
  9118. K(document).bind('click,mousedown', removePicker);
  9119. dialogDiv.bind('click,mousedown', removePicker);
  9120. });
  9121. }
  9122. function _getCellIndex(table, row, cell) {
  9123. var rowSpanCount = 0;
  9124. for (var i = 0, len = row.cells.length; i < len; i++) {
  9125. if (row.cells[i] == cell) {
  9126. break;
  9127. }
  9128. rowSpanCount += row.cells[i].rowSpan - 1;
  9129. }
  9130. return cell.cellIndex - rowSpanCount;
  9131. }
  9132. self.plugin.table = {
  9133. prop : function(isInsert) {
  9134. var html = [
  9135. '<div style="padding:20px;">',
  9136. '<div class="ke-dialog-row">',
  9137. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9138. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9139. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9140. '</div>',
  9141. '<div class="ke-dialog-row">',
  9142. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9143. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9144. '<select name="widthType">',
  9145. '<option value="%">' + lang.percent + '</option>',
  9146. '<option value="px">' + lang.px + '</option>',
  9147. '</select> &nbsp; ',
  9148. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9149. '<select name="heightType">',
  9150. '<option value="%">' + lang.percent + '</option>',
  9151. '<option value="px">' + lang.px + '</option>',
  9152. '</select>',
  9153. '</div>',
  9154. '<div class="ke-dialog-row">',
  9155. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9156. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9157. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9158. '</div>',
  9159. '<div class="ke-dialog-row">',
  9160. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9161. '<select id="keAlign" name="align">',
  9162. '<option value="">' + lang.alignDefault + '</option>',
  9163. '<option value="left">' + lang.alignLeft + '</option>',
  9164. '<option value="center">' + lang.alignCenter + '</option>',
  9165. '<option value="right">' + lang.alignRight + '</option>',
  9166. '</select>',
  9167. '</div>',
  9168. '<div class="ke-dialog-row">',
  9169. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9170. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9171. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9172. '</div>',
  9173. '<div class="ke-dialog-row">',
  9174. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9175. '<span class="ke-inline-block ke-input-color"></span>',
  9176. '</div>',
  9177. '</div>'
  9178. ].join('');
  9179. var bookmark = self.cmd.range.createBookmark();
  9180. var dialog = self.createDialog({
  9181. name : name,
  9182. width : 500,
  9183. title : self.lang(name),
  9184. body : html,
  9185. beforeRemove : function() {
  9186. colorBox.unbind();
  9187. },
  9188. yesBtn : {
  9189. name : self.lang('yes'),
  9190. click : function(e) {
  9191. var rows = rowsBox.val(),
  9192. cols = colsBox.val(),
  9193. width = widthBox.val(),
  9194. height = heightBox.val(),
  9195. widthType = widthTypeBox.val(),
  9196. heightType = heightTypeBox.val(),
  9197. padding = paddingBox.val(),
  9198. spacing = spacingBox.val(),
  9199. align = alignBox.val(),
  9200. border = borderBox.val(),
  9201. borderColor = K(colorBox[0]).html() || '',
  9202. bgColor = K(colorBox[1]).html() || '';
  9203. if (rows == 0 || !/^\d+$/.test(rows)) {
  9204. alert(self.lang('invalidRows'));
  9205. rowsBox[0].focus();
  9206. return;
  9207. }
  9208. if (cols == 0 || !/^\d+$/.test(cols)) {
  9209. alert(self.lang('invalidRows'));
  9210. colsBox[0].focus();
  9211. return;
  9212. }
  9213. if (!/^\d*$/.test(width)) {
  9214. alert(self.lang('invalidWidth'));
  9215. widthBox[0].focus();
  9216. return;
  9217. }
  9218. if (!/^\d*$/.test(height)) {
  9219. alert(self.lang('invalidHeight'));
  9220. heightBox[0].focus();
  9221. return;
  9222. }
  9223. if (!/^\d*$/.test(padding)) {
  9224. alert(self.lang('invalidPadding'));
  9225. paddingBox[0].focus();
  9226. return;
  9227. }
  9228. if (!/^\d*$/.test(spacing)) {
  9229. alert(self.lang('invalidSpacing'));
  9230. spacingBox[0].focus();
  9231. return;
  9232. }
  9233. if (!/^\d*$/.test(border)) {
  9234. alert(self.lang('invalidBorder'));
  9235. borderBox[0].focus();
  9236. return;
  9237. }
  9238. if (table) {
  9239. if (width !== '') {
  9240. table.width(width + widthType);
  9241. } else {
  9242. table.css('width', '');
  9243. }
  9244. if (table[0].width !== undefined) {
  9245. table.removeAttr('width');
  9246. }
  9247. if (height !== '') {
  9248. table.height(height + heightType);
  9249. } else {
  9250. table.css('height', '');
  9251. }
  9252. if (table[0].height !== undefined) {
  9253. table.removeAttr('height');
  9254. }
  9255. table.css('background-color', bgColor);
  9256. if (table[0].bgColor !== undefined) {
  9257. table.removeAttr('bgColor');
  9258. }
  9259. if (padding !== '') {
  9260. table[0].cellPadding = padding;
  9261. } else {
  9262. table.removeAttr('cellPadding');
  9263. }
  9264. if (spacing !== '') {
  9265. table[0].cellSpacing = spacing;
  9266. } else {
  9267. table.removeAttr('cellSpacing');
  9268. }
  9269. if (align !== '') {
  9270. table[0].align = align;
  9271. } else {
  9272. table.removeAttr('align');
  9273. }
  9274. if (border !== '') {
  9275. table.attr('border', border);
  9276. } else {
  9277. table.removeAttr('border');
  9278. }
  9279. if (border === '' || border === '0') {
  9280. table.addClass(zeroborder);
  9281. } else {
  9282. table.removeClass(zeroborder);
  9283. }
  9284. if (borderColor !== '') {
  9285. table.attr('borderColor', borderColor);
  9286. } else {
  9287. table.removeAttr('borderColor');
  9288. }
  9289. self.hideDialog().focus();
  9290. self.cmd.range.moveToBookmark(bookmark);
  9291. self.cmd.select();
  9292. self.addBookmark();
  9293. return;
  9294. }
  9295. var style = '';
  9296. if (width !== '') {
  9297. style += 'width:' + width + widthType + ';';
  9298. }
  9299. if (height !== '') {
  9300. style += 'height:' + height + heightType + ';';
  9301. }
  9302. if (bgColor !== '') {
  9303. style += 'background-color:' + bgColor + ';';
  9304. }
  9305. var html = '<table';
  9306. if (style !== '') {
  9307. html += ' style="' + style + '"';
  9308. }
  9309. if (padding !== '') {
  9310. html += ' cellpadding="' + padding + '"';
  9311. }
  9312. if (spacing !== '') {
  9313. html += ' cellspacing="' + spacing + '"';
  9314. }
  9315. if (align !== '') {
  9316. html += ' align="' + align + '"';
  9317. }
  9318. if (border !== '') {
  9319. html += ' border="' + border + '"';
  9320. }
  9321. if (border === '' || border === '0') {
  9322. html += ' class="' + zeroborder + '"';
  9323. }
  9324. if (borderColor !== '') {
  9325. html += ' bordercolor="' + borderColor + '"';
  9326. }
  9327. html += '>';
  9328. for (var i = 0; i < rows; i++) {
  9329. html += '<tr>';
  9330. for (var j = 0; j < cols; j++) {
  9331. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9332. }
  9333. html += '</tr>';
  9334. }
  9335. html += '</table>';
  9336. if (!K.IE) {
  9337. html += '<br />';
  9338. }
  9339. self.insertHtml(html);
  9340. self.select().hideDialog().focus();
  9341. self.addBookmark();
  9342. }
  9343. }
  9344. }),
  9345. div = dialog.div,
  9346. rowsBox = K('[name="rows"]', div).val(3),
  9347. colsBox = K('[name="cols"]', div).val(2),
  9348. widthBox = K('[name="width"]', div).val(100),
  9349. heightBox = K('[name="height"]', div),
  9350. widthTypeBox = K('[name="widthType"]', div),
  9351. heightTypeBox = K('[name="heightType"]', div),
  9352. paddingBox = K('[name="padding"]', div).val(2),
  9353. spacingBox = K('[name="spacing"]', div).val(0),
  9354. alignBox = K('[name="align"]', div),
  9355. borderBox = K('[name="border"]', div).val(1),
  9356. colorBox = K('.ke-input-color', div);
  9357. _initColorPicker(div, colorBox.eq(0));
  9358. _initColorPicker(div, colorBox.eq(1));
  9359. _setColor(colorBox.eq(0), '#000000');
  9360. _setColor(colorBox.eq(1), '');
  9361. rowsBox[0].focus();
  9362. rowsBox[0].select();
  9363. var table;
  9364. if (isInsert) {
  9365. return;
  9366. }
  9367. table = self.plugin.getSelectedTable();
  9368. if (table) {
  9369. rowsBox.val(table[0].rows.length);
  9370. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9371. rowsBox.attr('disabled', true);
  9372. colsBox.attr('disabled', true);
  9373. var match,
  9374. tableWidth = table[0].style.width || table[0].width,
  9375. tableHeight = table[0].style.height || table[0].height;
  9376. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9377. widthBox.val(match[1]);
  9378. widthTypeBox.val(match[2]);
  9379. } else {
  9380. widthBox.val('');
  9381. }
  9382. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9383. heightBox.val(match[1]);
  9384. heightTypeBox.val(match[2]);
  9385. }
  9386. paddingBox.val(table[0].cellPadding || '');
  9387. spacingBox.val(table[0].cellSpacing || '');
  9388. alignBox.val(table[0].align || '');
  9389. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9390. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9391. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9392. widthBox[0].focus();
  9393. widthBox[0].select();
  9394. }
  9395. },
  9396. cellprop : function() {
  9397. var html = [
  9398. '<div style="padding:20px;">',
  9399. '<div class="ke-dialog-row">',
  9400. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9401. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9402. '<select name="widthType">',
  9403. '<option value="%">' + lang.percent + '</option>',
  9404. '<option value="px">' + lang.px + '</option>',
  9405. '</select> &nbsp; ',
  9406. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9407. '<select name="heightType">',
  9408. '<option value="%">' + lang.percent + '</option>',
  9409. '<option value="px">' + lang.px + '</option>',
  9410. '</select>',
  9411. '</div>',
  9412. '<div class="ke-dialog-row">',
  9413. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9414. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9415. '<option value="">' + lang.alignDefault + '</option>',
  9416. '<option value="left">' + lang.alignLeft + '</option>',
  9417. '<option value="center">' + lang.alignCenter + '</option>',
  9418. '<option value="right">' + lang.alignRight + '</option>',
  9419. '</select> ',
  9420. lang.verticalAlign + ' <select name="verticalAlign">',
  9421. '<option value="">' + lang.alignDefault + '</option>',
  9422. '<option value="top">' + lang.alignTop + '</option>',
  9423. '<option value="middle">' + lang.alignMiddle + '</option>',
  9424. '<option value="bottom">' + lang.alignBottom + '</option>',
  9425. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9426. '</select>',
  9427. '</div>',
  9428. '<div class="ke-dialog-row">',
  9429. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9430. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9431. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9432. '</div>',
  9433. '<div class="ke-dialog-row">',
  9434. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9435. '<span class="ke-inline-block ke-input-color"></span>',
  9436. '</div>',
  9437. '</div>'
  9438. ].join('');
  9439. var bookmark = self.cmd.range.createBookmark();
  9440. var dialog = self.createDialog({
  9441. name : name,
  9442. width : 500,
  9443. title : self.lang('tablecell'),
  9444. body : html,
  9445. beforeRemove : function() {
  9446. colorBox.unbind();
  9447. },
  9448. yesBtn : {
  9449. name : self.lang('yes'),
  9450. click : function(e) {
  9451. var width = widthBox.val(),
  9452. height = heightBox.val(),
  9453. widthType = widthTypeBox.val(),
  9454. heightType = heightTypeBox.val(),
  9455. padding = paddingBox.val(),
  9456. spacing = spacingBox.val(),
  9457. textAlign = textAlignBox.val(),
  9458. verticalAlign = verticalAlignBox.val(),
  9459. border = borderBox.val(),
  9460. borderColor = K(colorBox[0]).html() || '',
  9461. bgColor = K(colorBox[1]).html() || '';
  9462. if (!/^\d*$/.test(width)) {
  9463. alert(self.lang('invalidWidth'));
  9464. widthBox[0].focus();
  9465. return;
  9466. }
  9467. if (!/^\d*$/.test(height)) {
  9468. alert(self.lang('invalidHeight'));
  9469. heightBox[0].focus();
  9470. return;
  9471. }
  9472. if (!/^\d*$/.test(border)) {
  9473. alert(self.lang('invalidBorder'));
  9474. borderBox[0].focus();
  9475. return;
  9476. }
  9477. cell.css({
  9478. width : width !== '' ? (width + widthType) : '',
  9479. height : height !== '' ? (height + heightType) : '',
  9480. 'background-color' : bgColor,
  9481. 'text-align' : textAlign,
  9482. 'vertical-align' : verticalAlign,
  9483. 'border-width' : border,
  9484. 'border-style' : border !== '' ? 'solid' : '',
  9485. 'border-color' : borderColor
  9486. });
  9487. self.hideDialog().focus();
  9488. self.cmd.range.moveToBookmark(bookmark);
  9489. self.cmd.select();
  9490. self.addBookmark();
  9491. }
  9492. }
  9493. }),
  9494. div = dialog.div,
  9495. widthBox = K('[name="width"]', div).val(100),
  9496. heightBox = K('[name="height"]', div),
  9497. widthTypeBox = K('[name="widthType"]', div),
  9498. heightTypeBox = K('[name="heightType"]', div),
  9499. paddingBox = K('[name="padding"]', div).val(2),
  9500. spacingBox = K('[name="spacing"]', div).val(0),
  9501. textAlignBox = K('[name="textAlign"]', div),
  9502. verticalAlignBox = K('[name="verticalAlign"]', div),
  9503. borderBox = K('[name="border"]', div).val(1),
  9504. colorBox = K('.ke-input-color', div);
  9505. _initColorPicker(div, colorBox.eq(0));
  9506. _initColorPicker(div, colorBox.eq(1));
  9507. _setColor(colorBox.eq(0), '#000000');
  9508. _setColor(colorBox.eq(1), '');
  9509. widthBox[0].focus();
  9510. widthBox[0].select();
  9511. var cell = self.plugin.getSelectedCell();
  9512. var match,
  9513. cellWidth = cell[0].style.width || cell[0].width || '',
  9514. cellHeight = cell[0].style.height || cell[0].height || '';
  9515. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9516. widthBox.val(match[1]);
  9517. widthTypeBox.val(match[2]);
  9518. } else {
  9519. widthBox.val('');
  9520. }
  9521. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9522. heightBox.val(match[1]);
  9523. heightTypeBox.val(match[2]);
  9524. }
  9525. textAlignBox.val(cell[0].style.textAlign || '');
  9526. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9527. var border = cell[0].style.borderWidth || '';
  9528. if (border) {
  9529. border = parseInt(border);
  9530. }
  9531. borderBox.val(border);
  9532. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9533. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9534. widthBox[0].focus();
  9535. widthBox[0].select();
  9536. },
  9537. insert : function() {
  9538. this.prop(true);
  9539. },
  9540. 'delete' : function() {
  9541. var table = self.plugin.getSelectedTable();
  9542. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9543. self.cmd.select();
  9544. table.remove();
  9545. self.addBookmark();
  9546. },
  9547. colinsert : function(offset) {
  9548. var table = self.plugin.getSelectedTable()[0],
  9549. row = self.plugin.getSelectedRow()[0],
  9550. cell = self.plugin.getSelectedCell()[0],
  9551. index = cell.cellIndex + offset;
  9552. index += table.rows[0].cells.length - row.cells.length;
  9553. for (var i = 0, len = table.rows.length; i < len; i++) {
  9554. var newRow = table.rows[i],
  9555. newCell = newRow.insertCell(index);
  9556. newCell.innerHTML = K.IE ? '' : '<br />';
  9557. index = _getCellIndex(table, newRow, newCell);
  9558. }
  9559. self.cmd.range.selectNodeContents(cell).collapse(true);
  9560. self.cmd.select();
  9561. self.addBookmark();
  9562. },
  9563. colinsertleft : function() {
  9564. this.colinsert(0);
  9565. },
  9566. colinsertright : function() {
  9567. this.colinsert(1);
  9568. },
  9569. rowinsert : function(offset) {
  9570. var table = self.plugin.getSelectedTable()[0],
  9571. row = self.plugin.getSelectedRow()[0],
  9572. cell = self.plugin.getSelectedCell()[0];
  9573. var rowIndex = row.rowIndex;
  9574. if (offset === 1) {
  9575. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9576. }
  9577. var newRow = table.insertRow(rowIndex);
  9578. for (var i = 0, len = row.cells.length; i < len; i++) {
  9579. if (row.cells[i].rowSpan > 1) {
  9580. len -= row.cells[i].rowSpan - 1;
  9581. }
  9582. var newCell = newRow.insertCell(i);
  9583. if (offset === 1 && row.cells[i].colSpan > 1) {
  9584. newCell.colSpan = row.cells[i].colSpan;
  9585. }
  9586. newCell.innerHTML = K.IE ? '' : '<br />';
  9587. }
  9588. for (var j = rowIndex; j >= 0; j--) {
  9589. var cells = table.rows[j].cells;
  9590. if (cells.length > i) {
  9591. for (var k = cell.cellIndex; k >= 0; k--) {
  9592. if (cells[k].rowSpan > 1) {
  9593. cells[k].rowSpan += 1;
  9594. }
  9595. }
  9596. break;
  9597. }
  9598. }
  9599. self.cmd.range.selectNodeContents(cell).collapse(true);
  9600. self.cmd.select();
  9601. self.addBookmark();
  9602. },
  9603. rowinsertabove : function() {
  9604. this.rowinsert(0);
  9605. },
  9606. rowinsertbelow : function() {
  9607. this.rowinsert(1);
  9608. },
  9609. rowmerge : function() {
  9610. var table = self.plugin.getSelectedTable()[0],
  9611. row = self.plugin.getSelectedRow()[0],
  9612. cell = self.plugin.getSelectedCell()[0],
  9613. rowIndex = row.rowIndex,
  9614. nextRowIndex = rowIndex + cell.rowSpan,
  9615. nextRow = table.rows[nextRowIndex];
  9616. if (table.rows.length <= nextRowIndex) {
  9617. return;
  9618. }
  9619. var cellIndex = cell.cellIndex;
  9620. if (nextRow.cells.length <= cellIndex) {
  9621. return;
  9622. }
  9623. var nextCell = nextRow.cells[cellIndex];
  9624. if (cell.colSpan !== nextCell.colSpan) {
  9625. return;
  9626. }
  9627. cell.rowSpan += nextCell.rowSpan;
  9628. nextRow.deleteCell(cellIndex);
  9629. self.cmd.range.selectNodeContents(cell).collapse(true);
  9630. self.cmd.select();
  9631. self.addBookmark();
  9632. },
  9633. colmerge : function() {
  9634. var table = self.plugin.getSelectedTable()[0],
  9635. row = self.plugin.getSelectedRow()[0],
  9636. cell = self.plugin.getSelectedCell()[0],
  9637. rowIndex = row.rowIndex,
  9638. cellIndex = cell.cellIndex,
  9639. nextCellIndex = cellIndex + 1;
  9640. if (row.cells.length <= nextCellIndex) {
  9641. return;
  9642. }
  9643. var nextCell = row.cells[nextCellIndex];
  9644. if (cell.rowSpan !== nextCell.rowSpan) {
  9645. return;
  9646. }
  9647. cell.colSpan += nextCell.colSpan;
  9648. row.deleteCell(nextCellIndex);
  9649. self.cmd.range.selectNodeContents(cell).collapse(true);
  9650. self.cmd.select();
  9651. self.addBookmark();
  9652. },
  9653. rowsplit : function() {
  9654. var table = self.plugin.getSelectedTable()[0],
  9655. row = self.plugin.getSelectedRow()[0],
  9656. cell = self.plugin.getSelectedCell()[0],
  9657. rowIndex = row.rowIndex;
  9658. if (cell.rowSpan === 1) {
  9659. return;
  9660. }
  9661. var cellIndex = _getCellIndex(table, row, cell);
  9662. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9663. var newRow = table.rows[rowIndex + i],
  9664. newCell = newRow.insertCell(cellIndex);
  9665. if (cell.colSpan > 1) {
  9666. newCell.colSpan = cell.colSpan;
  9667. }
  9668. newCell.innerHTML = K.IE ? '' : '<br />';
  9669. cellIndex = _getCellIndex(table, newRow, newCell);
  9670. }
  9671. K(cell).removeAttr('rowSpan');
  9672. self.cmd.range.selectNodeContents(cell).collapse(true);
  9673. self.cmd.select();
  9674. self.addBookmark();
  9675. },
  9676. colsplit : function() {
  9677. var table = self.plugin.getSelectedTable()[0],
  9678. row = self.plugin.getSelectedRow()[0],
  9679. cell = self.plugin.getSelectedCell()[0],
  9680. cellIndex = cell.cellIndex;
  9681. if (cell.colSpan === 1) {
  9682. return;
  9683. }
  9684. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9685. var newCell = row.insertCell(cellIndex + i);
  9686. if (cell.rowSpan > 1) {
  9687. newCell.rowSpan = cell.rowSpan;
  9688. }
  9689. newCell.innerHTML = K.IE ? '' : '<br />';
  9690. }
  9691. K(cell).removeAttr('colSpan');
  9692. self.cmd.range.selectNodeContents(cell).collapse(true);
  9693. self.cmd.select();
  9694. self.addBookmark();
  9695. },
  9696. coldelete : function() {
  9697. var table = self.plugin.getSelectedTable()[0],
  9698. row = self.plugin.getSelectedRow()[0],
  9699. cell = self.plugin.getSelectedCell()[0],
  9700. index = cell.cellIndex;
  9701. for (var i = 0, len = table.rows.length; i < len; i++) {
  9702. var newRow = table.rows[i],
  9703. newCell = newRow.cells[index];
  9704. if (newCell.colSpan > 1) {
  9705. newCell.colSpan -= 1;
  9706. if (newCell.colSpan === 1) {
  9707. K(newCell).removeAttr('colSpan');
  9708. }
  9709. } else {
  9710. newRow.deleteCell(index);
  9711. }
  9712. if (newCell.rowSpan > 1) {
  9713. i += newCell.rowSpan - 1;
  9714. }
  9715. }
  9716. if (row.cells.length === 0) {
  9717. self.cmd.range.setStartBefore(table).collapse(true);
  9718. self.cmd.select();
  9719. K(table).remove();
  9720. } else {
  9721. self.cmd.selection(true);
  9722. }
  9723. self.addBookmark();
  9724. },
  9725. rowdelete : function() {
  9726. var table = self.plugin.getSelectedTable()[0],
  9727. row = self.plugin.getSelectedRow()[0],
  9728. cell = self.plugin.getSelectedCell()[0],
  9729. rowIndex = row.rowIndex;
  9730. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9731. table.deleteRow(rowIndex + i);
  9732. }
  9733. if (table.rows.length === 0) {
  9734. self.cmd.range.setStartBefore(table).collapse(true);
  9735. self.cmd.select();
  9736. K(table).remove();
  9737. } else {
  9738. self.cmd.selection(true);
  9739. }
  9740. self.addBookmark();
  9741. }
  9742. };
  9743. self.clickToolbar(name, self.plugin.table.prop);
  9744. });
  9745. /*******************************************************************************
  9746. * KindEditor - WYSIWYG HTML Editor for Internet
  9747. * Copyright (C) 2006-2011 kindsoft.net
  9748. *
  9749. * @author Roddy <luolonghao@gmail.com>
  9750. * @site http://www.kindsoft.net/
  9751. * @licence http://www.kindsoft.net/license.php
  9752. *******************************************************************************/
  9753. KindEditor.plugin('template', function(K) {
  9754. var self = this, name = 'template', lang = self.lang(name + '.'),
  9755. htmlPath = self.pluginsPath + name + '/html/';
  9756. function getFilePath(fileName) {
  9757. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9758. }
  9759. self.clickToolbar(name, function() {
  9760. var lang = self.lang(name + '.'),
  9761. arr = ['<div style="padding:10px 20px;">',
  9762. '<div class="ke-header">',
  9763. '<div class="ke-left">',
  9764. lang. selectTemplate + ' <select>'];
  9765. K.each(lang.fileList, function(key, val) {
  9766. arr.push('<option value="' + key + '">' + val + '</option>');
  9767. });
  9768. html = [arr.join(''),
  9769. '</select></div>',
  9770. '<div class="ke-right">',
  9771. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9772. '</div>',
  9773. '<div class="ke-clearfix"></div>',
  9774. '</div>',
  9775. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9776. '</div>'].join('');
  9777. var dialog = self.createDialog({
  9778. name : name,
  9779. width : 500,
  9780. title : self.lang(name),
  9781. body : html,
  9782. yesBtn : {
  9783. name : self.lang('yes'),
  9784. click : function(e) {
  9785. var doc = K.iframeDoc(iframe);
  9786. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9787. }
  9788. }
  9789. });
  9790. var selectBox = K('select', dialog.div),
  9791. checkbox = K('[name="replaceFlag"]', dialog.div),
  9792. iframe = K('iframe', dialog.div);
  9793. checkbox[0].checked = true;
  9794. iframe.attr('src', getFilePath(selectBox.val()));
  9795. selectBox.change(function() {
  9796. iframe.attr('src', getFilePath(this.value));
  9797. });
  9798. });
  9799. });
  9800. /*******************************************************************************
  9801. * KindEditor - WYSIWYG HTML Editor for Internet
  9802. * Copyright (C) 2006-2011 kindsoft.net
  9803. *
  9804. * @author Roddy <luolonghao@gmail.com>
  9805. * @site http://www.kindsoft.net/
  9806. * @licence http://www.kindsoft.net/license.php
  9807. *******************************************************************************/
  9808. KindEditor.plugin('wordpaste', function(K) {
  9809. var self = this, name = 'wordpaste';
  9810. self.clickToolbar(name, function() {
  9811. var lang = self.lang(name + '.'),
  9812. html = '<div style="padding:10px 20px;">' +
  9813. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9814. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9815. '</div>',
  9816. dialog = self.createDialog({
  9817. name : name,
  9818. width : 450,
  9819. title : self.lang(name),
  9820. body : html,
  9821. yesBtn : {
  9822. name : self.lang('yes'),
  9823. click : function(e) {
  9824. var str = doc.body.innerHTML;
  9825. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9826. self.insertHtml(str).hideDialog().focus();
  9827. }
  9828. }
  9829. }),
  9830. div = dialog.div,
  9831. iframe = K('iframe', div),
  9832. doc = K.iframeDoc(iframe);
  9833. if (!K.IE) {
  9834. doc.designMode = 'on';
  9835. }
  9836. doc.open();
  9837. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9838. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9839. if (!K.IE) {
  9840. doc.write('<br />');
  9841. }
  9842. doc.write('</body></html>');
  9843. doc.close();
  9844. if (K.IE) {
  9845. doc.body.contentEditable = 'true';
  9846. }
  9847. iframe[0].contentWindow.focus();
  9848. });
  9849. });
  9850. KindEditor.plugin('fixtoolbar', function (K) {
  9851. var self = this;
  9852. if (!self.fixToolBar) {
  9853. return;
  9854. }
  9855. function init() {
  9856. var toolbar = K('.ke-toolbar');
  9857. var originY = toolbar.pos().y;
  9858. K(window).bind('scroll', function () {
  9859. if (toolbar.css('position') == 'fixed') {
  9860. if(document.body.scrollTop - originY < 0){
  9861. toolbar.css('position', 'static');
  9862. toolbar.css('top', 'auto');
  9863. }
  9864. } else {
  9865. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9866. toolbar.css('position', 'fixed');
  9867. toolbar.css('top', 0);
  9868. }
  9869. }
  9870. });
  9871. }
  9872. if (self.isCreated) {
  9873. init();
  9874. } else {
  9875. self.afterCreate(init);
  9876. }
  9877. });
  9878. function autoImg(self) {
  9879. var index = self.index;
  9880. var haspicContainer = document.getElementById("has_pic_" + index);
  9881. if (haspicContainer == null) {
  9882. haspicContainer = document.createElement("div");
  9883. haspicContainer.id = "has_pic_" + index;
  9884. haspicContainer.innerHTML = "<input type='text' id='piclist_"+index+"' value='' style='display:none;'/><div id='upload_"+index+"'><b>您有图片需要上传到服务器</b>&nbsp;&nbsp;<a href='javascript:uploadpic(\""+self.uploadJson+"\", \""+self.filePostName+"\", \""+index+"\");' >上传</a></div><div id='confirm_"+index+"'></div>";
  9885. $(".ke-toolbar").eq(index).after(haspicContainer);
  9886. }
  9887. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  9888. var piccount = 0;
  9889. var sstr = '';
  9890. $(img).each(function (i) {
  9891. var that = $(this);
  9892. var host = gethost(self.uploadJson);
  9893. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  9894. var n = gethost(that.attr("src"));
  9895. if (host != n) {
  9896. piccount++;
  9897. if (i == $(img).length - 1)
  9898. sstr += that.attr("src");
  9899. else
  9900. sstr += that.attr("src") + ",";
  9901. }
  9902. }
  9903. });
  9904. $("#piclist_" + index).val(encodeURIComponent(sstr));
  9905. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  9906. }
  9907. function closeupload(index) {
  9908. $("#has_pic_" + index).hide();
  9909. $("#upload_" + index).show();
  9910. }
  9911. function uploadpic(url, name, index) {
  9912. var piclist = encodeURI($("#piclist_" + index).val());
  9913. if (piclist.length == 0) return false;
  9914. $.ajax({
  9915. url: url.replace('kindeditor', 'copys') + '&json=1',
  9916. data: name + "=" + piclist,
  9917. type: "POST",
  9918. dataType: "json",
  9919. beforeSend: function () {
  9920. $("#upload_" + index).hide();
  9921. $("#confirm_" + index).text("正在上传中...");
  9922. },
  9923. success: function (msg) {
  9924. var url = msg.data;
  9925. if (url !== "") {
  9926. var str = new Array();
  9927. str = url.split(',');
  9928. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  9929. $(img).each(function (i) {
  9930. var that = $(this);
  9931. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  9932. that.attr("src", str[i]);
  9933. that.attr("data-ke-src", str[i]);
  9934. }
  9935. });
  9936. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  9937. }
  9938. else $("#confirm_" + index).text("上传失败!");
  9939. }
  9940. });
  9941. }
  9942. function gethost(url){
  9943. var reg = /^http(s)?:\/\/(.*?)\//;
  9944. return reg.exec(url)[2];
  9945. }