kindeditor-all-min.js 299 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171
  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(/, " helvetica=""(.*?)"="/g, '');
  741. html = html.replace(/<[^>]+/g, function($0) {
  742. return $0.replace(/\s+/g, ' ');
  743. });
  744. var htmlTagMap = {};
  745. if (htmlTags) {
  746. _each(htmlTags, function(key, val) {
  747. var arr = key.split(',');
  748. for (var i = 0, len = arr.length; i < len; i++) {
  749. htmlTagMap[arr[i]] = _toMap(val);
  750. }
  751. });
  752. if (!htmlTagMap.script) {
  753. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  754. }
  755. if (!htmlTagMap.style) {
  756. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  757. }
  758. }
  759. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  760. var tagStack = [];
  761. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  762. var full = $0,
  763. startNewline = $1 || '',
  764. startSlash = $2 || '',
  765. tagName = $3.toLowerCase(),
  766. attr = $4 || '',
  767. endSlash = $5 ? ' ' + $5 : '',
  768. endNewline = $6 || '';
  769. if (htmlTags && !htmlTagMap[tagName]) {
  770. return '';
  771. }
  772. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  773. endSlash = ' /';
  774. }
  775. if (_INLINE_TAG_MAP[tagName]) {
  776. if (startNewline) {
  777. startNewline = ' ';
  778. }
  779. if (endNewline) {
  780. endNewline = ' ';
  781. }
  782. }
  783. if (_PRE_TAG_MAP[tagName]) {
  784. if (startSlash) {
  785. endNewline = '\n';
  786. } else {
  787. startNewline = '\n';
  788. }
  789. }
  790. if (wellFormatted && tagName == 'br') {
  791. endNewline = '\n';
  792. }
  793. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  794. if (wellFormatted) {
  795. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  796. tagStack.pop();
  797. } else {
  798. tagStack.push(tagName);
  799. }
  800. startNewline = '\n';
  801. endNewline = '\n';
  802. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  803. startNewline += indentChar;
  804. if (!startSlash) {
  805. endNewline += indentChar;
  806. }
  807. }
  808. if (endSlash) {
  809. tagStack.pop();
  810. } else if (!startSlash) {
  811. endNewline += indentChar;
  812. }
  813. } else {
  814. startNewline = endNewline = '';
  815. }
  816. }
  817. if (attr !== '') {
  818. var attrMap = _getAttrList(full);
  819. if (tagName === 'font') {
  820. var fontStyleMap = {}, fontStyle = '';
  821. _each(attrMap, function(key, val) {
  822. if (key === 'color') {
  823. fontStyleMap.color = val;
  824. delete attrMap[key];
  825. }
  826. if (key === 'size') {
  827. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  828. delete attrMap[key];
  829. }
  830. if (key === 'face') {
  831. fontStyleMap['font-family'] = val;
  832. delete attrMap[key];
  833. }
  834. if (key === 'style') {
  835. fontStyle = val;
  836. }
  837. });
  838. if (fontStyle && !/;$/.test(fontStyle)) {
  839. fontStyle += ';';
  840. }
  841. _each(fontStyleMap, function(key, val) {
  842. if (val === '') {
  843. return;
  844. }
  845. if (/\s/.test(val)) {
  846. val = "'" + val + "'";
  847. }
  848. fontStyle += key + ':' + val + ';';
  849. });
  850. attrMap.style = fontStyle;
  851. }
  852. _each(attrMap, function(key, val) {
  853. if (_FILL_ATTR_MAP[key]) {
  854. attrMap[key] = key;
  855. }
  856. if (_inArray(key, ['src', 'href']) >= 0) {
  857. attrMap[key] = _formatUrl(val, urlType);
  858. }
  859. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  860. tagName === 'body' && key === 'contenteditable' ||
  861. /^kindeditor_\d+$/.test(key)) {
  862. delete attrMap[key];
  863. }
  864. if (key === 'style' && val !== '') {
  865. var styleMap = _getCssList(val);
  866. _each(styleMap, function(k, v) {
  867. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  868. delete styleMap[k];
  869. }
  870. });
  871. var style = '';
  872. _each(styleMap, function(k, v) {
  873. style += k + ':' + v + ';';
  874. });
  875. attrMap.style = style;
  876. }
  877. });
  878. attr = '';
  879. _each(attrMap, function(key, val) {
  880. if (key === 'style' && val === '') {
  881. return;
  882. }
  883. val = val.replace(/"/g, '&quot;');
  884. attr += ' ' + key + '="' + val + '"';
  885. });
  886. }
  887. if (tagName === 'font') {
  888. tagName = 'span';
  889. }
  890. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  891. });
  892. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  893. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  894. });
  895. html = html.replace(/\n\s*\n/g, '\n');
  896. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  897. return _trim(html);
  898. }
  899. function _clearMsWord(html, htmlTags) {
  900. html = html.replace(/<meta[\s\S]*?>/ig, '')
  901. .replace(/<![\s\S]*?>/ig, '')
  902. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  903. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  904. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  905. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  906. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  907. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  908. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  909. });
  910. return _formatHtml(html, htmlTags);
  911. }
  912. function _mediaType(src) {
  913. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  914. return 'audio/x-pn-realaudio-plugin';
  915. }
  916. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  917. return 'application/x-shockwave-flash';
  918. }
  919. return 'video/x-ms-asf-plugin';
  920. }
  921. function _mediaClass(type) {
  922. if (/realaudio/i.test(type)) {
  923. return 'ke-rm';
  924. }
  925. if (/flash/i.test(type)) {
  926. return 'ke-flash';
  927. }
  928. return 'ke-media';
  929. }
  930. function _mediaAttrs(srcTag) {
  931. return _getAttrList(unescape(srcTag));
  932. }
  933. function _mediaEmbed(attrs) {
  934. var html = '<embed ';
  935. _each(attrs, function(key, val) {
  936. html += key + '="' + val + '" ';
  937. });
  938. html += '/>';
  939. return html;
  940. }
  941. function _mediaImg(blankPath, attrs) {
  942. var width = attrs.width,
  943. height = attrs.height,
  944. type = attrs.type || _mediaType(attrs.src),
  945. srcTag = _mediaEmbed(attrs),
  946. style = '';
  947. if (/\D/.test(width)) {
  948. style += 'width:' + width + ';';
  949. } else if (width > 0) {
  950. style += 'width:' + width + 'px;';
  951. }
  952. if (/\D/.test(height)) {
  953. style += 'height:' + height + ';';
  954. } else if (height > 0) {
  955. style += 'height:' + height + 'px;';
  956. }
  957. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  958. if (style !== '') {
  959. html += 'style="' + style + '" ';
  960. }
  961. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  962. return html;
  963. }
  964. function _tmpl(str, data) {
  965. var fn = new Function("obj",
  966. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  967. "with(obj){p.push('" +
  968. str.replace(/[\r\t\n]/g, " ")
  969. .split("<%").join("\t")
  970. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  971. .replace(/\t=(.*?)%>/g, "',$1,'")
  972. .split("\t").join("');")
  973. .split("%>").join("p.push('")
  974. .split("\r").join("\\'") + "');}return p.join('');");
  975. return data ? fn(data) : fn;
  976. }
  977. K.formatUrl = _formatUrl;
  978. K.formatHtml = _formatHtml;
  979. K.getCssList = _getCssList;
  980. K.getAttrList = _getAttrList;
  981. K.mediaType = _mediaType;
  982. K.mediaAttrs = _mediaAttrs;
  983. K.mediaEmbed = _mediaEmbed;
  984. K.mediaImg = _mediaImg;
  985. K.clearMsWord = _clearMsWord;
  986. K.tmpl = _tmpl;
  987. function _contains(nodeA, nodeB) {
  988. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  989. return true;
  990. }
  991. while ((nodeB = nodeB.parentNode)) {
  992. if (nodeB == nodeA) {
  993. return true;
  994. }
  995. }
  996. return false;
  997. }
  998. var _getSetAttrDiv = document.createElement('div');
  999. _getSetAttrDiv.setAttribute('className', 't');
  1000. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1001. function _getAttr(el, key) {
  1002. key = key.toLowerCase();
  1003. var val = null;
  1004. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1005. var div = el.ownerDocument.createElement('div');
  1006. div.appendChild(el.cloneNode(false));
  1007. var list = _getAttrList(_unescape(div.innerHTML));
  1008. if (key in list) {
  1009. val = list[key];
  1010. }
  1011. } else {
  1012. try {
  1013. val = el.getAttribute(key, 2);
  1014. } catch(e) {
  1015. val = el.getAttribute(key, 1);
  1016. }
  1017. }
  1018. if (key === 'style' && val !== null) {
  1019. val = _formatCss(val);
  1020. }
  1021. return val;
  1022. }
  1023. function _queryAll(expr, root) {
  1024. var exprList = expr.split(',');
  1025. if (exprList.length > 1) {
  1026. var mergedResults = [];
  1027. _each(exprList, function() {
  1028. _each(_queryAll(this, root), function() {
  1029. if (_inArray(this, mergedResults) < 0) {
  1030. mergedResults.push(this);
  1031. }
  1032. });
  1033. });
  1034. return mergedResults;
  1035. }
  1036. root = root || document;
  1037. function escape(str) {
  1038. if (typeof str != 'string') {
  1039. return str;
  1040. }
  1041. return str.replace(/([^\w\-])/g, '\\$1');
  1042. }
  1043. function stripslashes(str) {
  1044. return str.replace(/\\/g, '');
  1045. }
  1046. function cmpTag(tagA, tagB) {
  1047. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1048. }
  1049. function byId(id, tag, root) {
  1050. var arr = [],
  1051. doc = root.ownerDocument || root,
  1052. el = doc.getElementById(stripslashes(id));
  1053. if (el) {
  1054. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1055. arr.push(el);
  1056. }
  1057. }
  1058. return arr;
  1059. }
  1060. function byClass(className, tag, root) {
  1061. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1062. if (root.getElementsByClassName) {
  1063. els = root.getElementsByClassName(stripslashes(className));
  1064. for (i = 0, len = els.length; i < len; i++) {
  1065. el = els[i];
  1066. if (cmpTag(tag, el.nodeName)) {
  1067. arr.push(el);
  1068. }
  1069. }
  1070. } else if (doc.querySelectorAll) {
  1071. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1072. for (i = 0, len = els.length; i < len; i++) {
  1073. el = els[i];
  1074. if (_contains(root, el)) {
  1075. arr.push(el);
  1076. }
  1077. }
  1078. } else {
  1079. els = root.getElementsByTagName(tag);
  1080. className = ' ' + className + ' ';
  1081. for (i = 0, len = els.length; i < len; i++) {
  1082. el = els[i];
  1083. if (el.nodeType == 1) {
  1084. var cls = el.className;
  1085. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1086. arr.push(el);
  1087. }
  1088. }
  1089. }
  1090. }
  1091. return arr;
  1092. }
  1093. function byName(name, tag, root) {
  1094. var arr = [], doc = root.ownerDocument || root,
  1095. els = doc.getElementsByName(stripslashes(name)), el;
  1096. for (var i = 0, len = els.length; i < len; i++) {
  1097. el = els[i];
  1098. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1099. if (el.getAttribute('name') !== null) {
  1100. arr.push(el);
  1101. }
  1102. }
  1103. }
  1104. return arr;
  1105. }
  1106. function byAttr(key, val, tag, root) {
  1107. var arr = [], els = root.getElementsByTagName(tag), el;
  1108. for (var i = 0, len = els.length; i < len; i++) {
  1109. el = els[i];
  1110. if (el.nodeType == 1) {
  1111. if (val === null) {
  1112. if (_getAttr(el, key) !== null) {
  1113. arr.push(el);
  1114. }
  1115. } else {
  1116. if (val === escape(_getAttr(el, key))) {
  1117. arr.push(el);
  1118. }
  1119. }
  1120. }
  1121. }
  1122. return arr;
  1123. }
  1124. function select(expr, root) {
  1125. var arr = [], matches;
  1126. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1127. var tag = matches ? matches[1] : '*';
  1128. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1129. arr = byId(matches[1], tag, root);
  1130. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1131. arr = byClass(matches[1], tag, root);
  1132. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1133. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1134. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1135. var key = matches[1].toLowerCase(), val = matches[2];
  1136. if (key === 'id') {
  1137. arr = byId(val, tag, root);
  1138. } else if (key === 'class') {
  1139. arr = byClass(val, tag, root);
  1140. } else if (key === 'name') {
  1141. arr = byName(val, tag, root);
  1142. } else {
  1143. arr = byAttr(key, val, tag, root);
  1144. }
  1145. } else {
  1146. var els = root.getElementsByTagName(tag), el;
  1147. for (var i = 0, len = els.length; i < len; i++) {
  1148. el = els[i];
  1149. if (el.nodeType == 1) {
  1150. arr.push(el);
  1151. }
  1152. }
  1153. }
  1154. return arr;
  1155. }
  1156. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1157. while ((arr = re.exec(expr))) {
  1158. if (arr[1] !== ' ') {
  1159. parts.push(arr[1]);
  1160. }
  1161. }
  1162. var results = [];
  1163. if (parts.length == 1) {
  1164. return select(parts[0], root);
  1165. }
  1166. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1167. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1168. part = parts[i];
  1169. if (part === '>') {
  1170. isChild = true;
  1171. continue;
  1172. }
  1173. if (i > 0) {
  1174. els = [];
  1175. for (j = 0, len = results.length; j < len; j++) {
  1176. val = results[j];
  1177. subResults = select(part, val);
  1178. for (k = 0, l = subResults.length; k < l; k++) {
  1179. v = subResults[k];
  1180. if (isChild) {
  1181. if (val === v.parentNode) {
  1182. els.push(v);
  1183. }
  1184. } else {
  1185. els.push(v);
  1186. }
  1187. }
  1188. }
  1189. results = els;
  1190. } else {
  1191. results = select(part, root);
  1192. }
  1193. if (results.length === 0) {
  1194. return [];
  1195. }
  1196. }
  1197. return results;
  1198. }
  1199. function _query(expr, root) {
  1200. var arr = _queryAll(expr, root);
  1201. return arr.length > 0 ? arr[0] : null;
  1202. }
  1203. K.query = _query;
  1204. K.queryAll = _queryAll;
  1205. function _get(val) {
  1206. return K(val)[0];
  1207. }
  1208. function _getDoc(node) {
  1209. if (!node) {
  1210. return document;
  1211. }
  1212. return node.ownerDocument || node.document || node;
  1213. }
  1214. function _getWin(node) {
  1215. if (!node) {
  1216. return window;
  1217. }
  1218. var doc = _getDoc(node);
  1219. return doc.parentWindow || doc.defaultView;
  1220. }
  1221. function _setHtml(el, html) {
  1222. if (el.nodeType != 1) {
  1223. return;
  1224. }
  1225. var doc = _getDoc(el);
  1226. try {
  1227. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1228. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1229. temp.parentNode.removeChild(temp);
  1230. } catch(e) {
  1231. K(el).empty();
  1232. K('@' + html, doc).each(function() {
  1233. el.appendChild(this);
  1234. });
  1235. }
  1236. }
  1237. function _hasClass(el, cls) {
  1238. return _inString(cls, el.className, ' ');
  1239. }
  1240. function _setAttr(el, key, val) {
  1241. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1242. key = 'className';
  1243. }
  1244. el.setAttribute(key, '' + val);
  1245. }
  1246. function _removeAttr(el, key) {
  1247. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1248. key = 'className';
  1249. }
  1250. _setAttr(el, key, '');
  1251. el.removeAttribute(key);
  1252. }
  1253. function _getNodeName(node) {
  1254. if (!node || !node.nodeName) {
  1255. return '';
  1256. }
  1257. return node.nodeName.toLowerCase();
  1258. }
  1259. function _computedCss(el, key) {
  1260. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1261. if (win.getComputedStyle) {
  1262. var style = win.getComputedStyle(el, null);
  1263. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1264. } else if (el.currentStyle) {
  1265. val = el.currentStyle[camelKey] || el.style[camelKey];
  1266. }
  1267. return val;
  1268. }
  1269. function _hasVal(node) {
  1270. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1271. }
  1272. function _docElement(doc) {
  1273. doc = doc || document;
  1274. return _QUIRKS ? doc.body : doc.documentElement;
  1275. }
  1276. function _docHeight(doc) {
  1277. var el = _docElement(doc);
  1278. return Math.max(el.scrollHeight, el.clientHeight);
  1279. }
  1280. function _docWidth(doc) {
  1281. var el = _docElement(doc);
  1282. return Math.max(el.scrollWidth, el.clientWidth);
  1283. }
  1284. function _getScrollPos(doc) {
  1285. doc = doc || document;
  1286. var x, y;
  1287. if (_IE || _NEWIE || _OPERA) {
  1288. x = _docElement(doc).scrollLeft;
  1289. y = _docElement(doc).scrollTop;
  1290. } else {
  1291. x = _getWin(doc).scrollX;
  1292. y = _getWin(doc).scrollY;
  1293. }
  1294. return {x : x, y : y};
  1295. }
  1296. function KNode(node) {
  1297. this.init(node);
  1298. }
  1299. _extend(KNode, {
  1300. init : function(node) {
  1301. var self = this;
  1302. node = _isArray(node) ? node : [node];
  1303. var length = 0;
  1304. for (var i = 0, len = node.length; i < len; i++) {
  1305. if (node[i]) {
  1306. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1307. length++;
  1308. }
  1309. }
  1310. self.length = length;
  1311. self.doc = _getDoc(self[0]);
  1312. self.name = _getNodeName(self[0]);
  1313. self.type = self.length > 0 ? self[0].nodeType : null;
  1314. self.win = _getWin(self[0]);
  1315. },
  1316. each : function(fn) {
  1317. var self = this;
  1318. for (var i = 0; i < self.length; i++) {
  1319. if (fn.call(self[i], i, self[i]) === false) {
  1320. return self;
  1321. }
  1322. }
  1323. return self;
  1324. },
  1325. bind : function(type, fn) {
  1326. this.each(function() {
  1327. _bind(this, type, fn);
  1328. });
  1329. return this;
  1330. },
  1331. unbind : function(type, fn) {
  1332. this.each(function() {
  1333. _unbind(this, type, fn);
  1334. });
  1335. return this;
  1336. },
  1337. fire : function(type) {
  1338. if (this.length < 1) {
  1339. return this;
  1340. }
  1341. _fire(this[0], type);
  1342. return this;
  1343. },
  1344. hasAttr : function(key) {
  1345. if (this.length < 1) {
  1346. return false;
  1347. }
  1348. return !!_getAttr(this[0], key);
  1349. },
  1350. attr : function(key, val) {
  1351. var self = this;
  1352. if (key === undefined) {
  1353. return _getAttrList(self.outer());
  1354. }
  1355. if (typeof key === 'object') {
  1356. _each(key, function(k, v) {
  1357. self.attr(k, v);
  1358. });
  1359. return self;
  1360. }
  1361. if (val === undefined) {
  1362. val = self.length < 1 ? null : _getAttr(self[0], key);
  1363. return val === null ? '' : val;
  1364. }
  1365. self.each(function() {
  1366. _setAttr(this, key, val);
  1367. });
  1368. return self;
  1369. },
  1370. removeAttr : function(key) {
  1371. this.each(function() {
  1372. _removeAttr(this, key);
  1373. });
  1374. return this;
  1375. },
  1376. get : function(i) {
  1377. if (this.length < 1) {
  1378. return null;
  1379. }
  1380. return this[i || 0];
  1381. },
  1382. eq : function(i) {
  1383. if (this.length < 1) {
  1384. return null;
  1385. }
  1386. return this[i] ? new KNode(this[i]) : null;
  1387. },
  1388. hasClass : function(cls) {
  1389. if (this.length < 1) {
  1390. return false;
  1391. }
  1392. return _hasClass(this[0], cls);
  1393. },
  1394. addClass : function(cls) {
  1395. this.each(function() {
  1396. if (!_hasClass(this, cls)) {
  1397. this.className = _trim(this.className + ' ' + cls);
  1398. }
  1399. });
  1400. return this;
  1401. },
  1402. removeClass : function(cls) {
  1403. this.each(function() {
  1404. if (_hasClass(this, cls)) {
  1405. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1406. }
  1407. });
  1408. return this;
  1409. },
  1410. html : function(val) {
  1411. var self = this;
  1412. if (val === undefined) {
  1413. if (self.length < 1 || self.type != 1) {
  1414. return '';
  1415. }
  1416. return _formatHtml(self[0].innerHTML);
  1417. }
  1418. self.each(function() {
  1419. _setHtml(this, val);
  1420. });
  1421. return self;
  1422. },
  1423. text : function() {
  1424. var self = this;
  1425. if (self.length < 1) {
  1426. return '';
  1427. }
  1428. return _IE ? self[0].innerText : self[0].textContent;
  1429. },
  1430. hasVal : function() {
  1431. if (this.length < 1) {
  1432. return false;
  1433. }
  1434. return _hasVal(this[0]);
  1435. },
  1436. val : function(val) {
  1437. var self = this;
  1438. if (val === undefined) {
  1439. if (self.length < 1) {
  1440. return '';
  1441. }
  1442. return self.hasVal() ? self[0].value : self.attr('value');
  1443. } else {
  1444. self.each(function() {
  1445. if (_hasVal(this)) {
  1446. this.value = val;
  1447. } else {
  1448. _setAttr(this, 'value' , val);
  1449. }
  1450. });
  1451. return self;
  1452. }
  1453. },
  1454. css : function(key, val) {
  1455. var self = this;
  1456. if (key === undefined) {
  1457. return _getCssList(self.attr('style'));
  1458. }
  1459. if (typeof key === 'object') {
  1460. _each(key, function(k, v) {
  1461. self.css(k, v);
  1462. });
  1463. return self;
  1464. }
  1465. if (val === undefined) {
  1466. if (self.length < 1) {
  1467. return '';
  1468. }
  1469. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1470. }
  1471. self.each(function() {
  1472. this.style[_toCamel(key)] = val;
  1473. });
  1474. return self;
  1475. },
  1476. width : function(val) {
  1477. var self = this;
  1478. if (val === undefined) {
  1479. if (self.length < 1) {
  1480. return 0;
  1481. }
  1482. return self[0].offsetWidth;
  1483. }
  1484. return self.css('width', _addUnit(val));
  1485. },
  1486. height : function(val) {
  1487. var self = this;
  1488. if (val === undefined) {
  1489. if (self.length < 1) {
  1490. return 0;
  1491. }
  1492. return self[0].offsetHeight;
  1493. }
  1494. return self.css('height', _addUnit(val));
  1495. },
  1496. opacity : function(val) {
  1497. this.each(function() {
  1498. if (this.style.opacity === undefined) {
  1499. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1500. } else {
  1501. this.style.opacity = val == 1 ? '' : val;
  1502. }
  1503. });
  1504. return this;
  1505. },
  1506. data : function(key, val) {
  1507. var self = this;
  1508. key = 'kindeditor_data_' + key;
  1509. if (val === undefined) {
  1510. if (self.length < 1) {
  1511. return null;
  1512. }
  1513. return self[0][key];
  1514. }
  1515. this.each(function() {
  1516. this[key] = val;
  1517. });
  1518. return self;
  1519. },
  1520. pos : function() {
  1521. var self = this, node = self[0], x = 0, y = 0;
  1522. if (node) {
  1523. if (node.getBoundingClientRect) {
  1524. var box = node.getBoundingClientRect(),
  1525. pos = _getScrollPos(self.doc);
  1526. x = box.left + pos.x;
  1527. y = box.top + pos.y;
  1528. } else {
  1529. while (node) {
  1530. x += node.offsetLeft;
  1531. y += node.offsetTop;
  1532. node = node.offsetParent;
  1533. }
  1534. }
  1535. }
  1536. return {x : _round(x), y : _round(y)};
  1537. },
  1538. clone : function(bool) {
  1539. if (this.length < 1) {
  1540. return new KNode([]);
  1541. }
  1542. return new KNode(this[0].cloneNode(bool));
  1543. },
  1544. append : function(expr) {
  1545. this.each(function() {
  1546. if (this.appendChild) {
  1547. this.appendChild(_get(expr));
  1548. }
  1549. });
  1550. return this;
  1551. },
  1552. appendTo : function(expr) {
  1553. this.each(function() {
  1554. _get(expr).appendChild(this);
  1555. });
  1556. return this;
  1557. },
  1558. before : function(expr) {
  1559. this.each(function() {
  1560. this.parentNode.insertBefore(_get(expr), this);
  1561. });
  1562. return this;
  1563. },
  1564. after : function(expr) {
  1565. this.each(function() {
  1566. if (this.nextSibling) {
  1567. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1568. } else {
  1569. this.parentNode.appendChild(_get(expr));
  1570. }
  1571. });
  1572. return this;
  1573. },
  1574. replaceWith : function(expr) {
  1575. var nodes = [];
  1576. this.each(function(i, node) {
  1577. _unbind(node);
  1578. var newNode = _get(expr);
  1579. node.parentNode.replaceChild(newNode, node);
  1580. nodes.push(newNode);
  1581. });
  1582. return K(nodes);
  1583. },
  1584. empty : function() {
  1585. var self = this;
  1586. self.each(function(i, node) {
  1587. var child = node.firstChild;
  1588. while (child) {
  1589. if (!node.parentNode) {
  1590. return;
  1591. }
  1592. var next = child.nextSibling;
  1593. child.parentNode.removeChild(child);
  1594. child = next;
  1595. }
  1596. });
  1597. return self;
  1598. },
  1599. remove : function(keepChilds) {
  1600. var self = this;
  1601. self.each(function(i, node) {
  1602. if (!node.parentNode) {
  1603. return;
  1604. }
  1605. _unbind(node);
  1606. if (keepChilds) {
  1607. var child = node.firstChild;
  1608. while (child) {
  1609. var next = child.nextSibling;
  1610. node.parentNode.insertBefore(child, node);
  1611. child = next;
  1612. }
  1613. }
  1614. node.parentNode.removeChild(node);
  1615. delete self[i];
  1616. });
  1617. self.length = 0;
  1618. return self;
  1619. },
  1620. show : function(val) {
  1621. var self = this;
  1622. if (val === undefined) {
  1623. val = self._originDisplay || '';
  1624. }
  1625. if (self.css('display') != 'none') {
  1626. return self;
  1627. }
  1628. return self.css('display', val);
  1629. },
  1630. hide : function() {
  1631. var self = this;
  1632. if (self.length < 1) {
  1633. return self;
  1634. }
  1635. self._originDisplay = self[0].style.display;
  1636. return self.css('display', 'none');
  1637. },
  1638. outer : function() {
  1639. var self = this;
  1640. if (self.length < 1) {
  1641. return '';
  1642. }
  1643. var div = self.doc.createElement('div'), html;
  1644. div.appendChild(self[0].cloneNode(true));
  1645. html = _formatHtml(div.innerHTML);
  1646. div = null;
  1647. return html;
  1648. },
  1649. isSingle : function() {
  1650. return !!_SINGLE_TAG_MAP[this.name];
  1651. },
  1652. isInline : function() {
  1653. return !!_INLINE_TAG_MAP[this.name];
  1654. },
  1655. isBlock : function() {
  1656. return !!_BLOCK_TAG_MAP[this.name];
  1657. },
  1658. isStyle : function() {
  1659. return !!_STYLE_TAG_MAP[this.name];
  1660. },
  1661. isControl : function() {
  1662. return !!_CONTROL_TAG_MAP[this.name];
  1663. },
  1664. contains : function(otherNode) {
  1665. if (this.length < 1) {
  1666. return false;
  1667. }
  1668. return _contains(this[0], _get(otherNode));
  1669. },
  1670. parent : function() {
  1671. if (this.length < 1) {
  1672. return null;
  1673. }
  1674. var node = this[0].parentNode;
  1675. return node ? new KNode(node) : null;
  1676. },
  1677. children : function() {
  1678. if (this.length < 1) {
  1679. return new KNode([]);
  1680. }
  1681. var list = [], child = this[0].firstChild;
  1682. while (child) {
  1683. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1684. list.push(child);
  1685. }
  1686. child = child.nextSibling;
  1687. }
  1688. return new KNode(list);
  1689. },
  1690. first : function() {
  1691. var list = this.children();
  1692. return list.length > 0 ? list.eq(0) : null;
  1693. },
  1694. last : function() {
  1695. var list = this.children();
  1696. return list.length > 0 ? list.eq(list.length - 1) : null;
  1697. },
  1698. index : function() {
  1699. if (this.length < 1) {
  1700. return -1;
  1701. }
  1702. var i = -1, sibling = this[0];
  1703. while (sibling) {
  1704. i++;
  1705. sibling = sibling.previousSibling;
  1706. }
  1707. return i;
  1708. },
  1709. prev : function() {
  1710. if (this.length < 1) {
  1711. return null;
  1712. }
  1713. var node = this[0].previousSibling;
  1714. return node ? new KNode(node) : null;
  1715. },
  1716. next : function() {
  1717. if (this.length < 1) {
  1718. return null;
  1719. }
  1720. var node = this[0].nextSibling;
  1721. return node ? new KNode(node) : null;
  1722. },
  1723. scan : function(fn, order) {
  1724. if (this.length < 1) {
  1725. return;
  1726. }
  1727. order = (order === undefined) ? true : order;
  1728. function walk(node) {
  1729. var n = order ? node.firstChild : node.lastChild;
  1730. while (n) {
  1731. var next = order ? n.nextSibling : n.previousSibling;
  1732. if (fn(n) === false) {
  1733. return false;
  1734. }
  1735. if (walk(n) === false) {
  1736. return false;
  1737. }
  1738. n = next;
  1739. }
  1740. }
  1741. walk(this[0]);
  1742. return this;
  1743. }
  1744. });
  1745. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1746. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1747. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1748. KNode.prototype[type] = function(fn) {
  1749. return fn ? this.bind(type, fn) : this.fire(type);
  1750. };
  1751. });
  1752. var _K = K;
  1753. K = function(expr, root) {
  1754. if (expr === undefined || expr === null) {
  1755. return;
  1756. }
  1757. function newNode(node) {
  1758. if (!node[0]) {
  1759. node = [];
  1760. }
  1761. return new KNode(node);
  1762. }
  1763. if (typeof expr === 'string') {
  1764. if (root) {
  1765. root = _get(root);
  1766. }
  1767. var length = expr.length;
  1768. if (expr.charAt(0) === '@') {
  1769. expr = expr.substr(1);
  1770. }
  1771. if (expr.length !== length || /<.+>/.test(expr)) {
  1772. var doc = root ? root.ownerDocument || root : document,
  1773. div = doc.createElement('div'), list = [];
  1774. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1775. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1776. var child = div.childNodes[i];
  1777. if (child.id == '__kindeditor_temp_tag__') {
  1778. continue;
  1779. }
  1780. list.push(child);
  1781. }
  1782. return newNode(list);
  1783. }
  1784. return newNode(_queryAll(expr, root));
  1785. }
  1786. if (expr && expr.constructor === KNode) {
  1787. return expr;
  1788. }
  1789. if (expr.toArray) {
  1790. expr = expr.toArray();
  1791. }
  1792. if (_isArray(expr)) {
  1793. return newNode(expr);
  1794. }
  1795. return newNode(_toArray(arguments));
  1796. };
  1797. _each(_K, function(key, val) {
  1798. K[key] = val;
  1799. });
  1800. K.NodeClass = KNode;
  1801. window.KindEditor = K;
  1802. var _START_TO_START = 0,
  1803. _START_TO_END = 1,
  1804. _END_TO_END = 2,
  1805. _END_TO_START = 3,
  1806. _BOOKMARK_ID = 0;
  1807. function _updateCollapsed(range) {
  1808. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1809. return range;
  1810. }
  1811. function _copyAndDelete(range, isCopy, isDelete) {
  1812. var doc = range.doc, nodeList = [];
  1813. function splitTextNode(node, startOffset, endOffset) {
  1814. var length = node.nodeValue.length, centerNode;
  1815. if (isCopy) {
  1816. var cloneNode = node.cloneNode(true);
  1817. if (startOffset > 0) {
  1818. centerNode = cloneNode.splitText(startOffset);
  1819. } else {
  1820. centerNode = cloneNode;
  1821. }
  1822. if (endOffset < length) {
  1823. centerNode.splitText(endOffset - startOffset);
  1824. }
  1825. }
  1826. if (isDelete) {
  1827. var center = node;
  1828. if (startOffset > 0) {
  1829. center = node.splitText(startOffset);
  1830. range.setStart(node, startOffset);
  1831. }
  1832. if (endOffset < length) {
  1833. var right = center.splitText(endOffset - startOffset);
  1834. range.setEnd(right, 0);
  1835. }
  1836. nodeList.push(center);
  1837. }
  1838. return centerNode;
  1839. }
  1840. function removeNodes() {
  1841. if (isDelete) {
  1842. range.up().collapse(true);
  1843. }
  1844. for (var i = 0, len = nodeList.length; i < len; i++) {
  1845. var node = nodeList[i];
  1846. if (node.parentNode) {
  1847. node.parentNode.removeChild(node);
  1848. }
  1849. }
  1850. }
  1851. var copyRange = range.cloneRange().down();
  1852. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1853. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1854. if (ancestor.nodeType == 3) {
  1855. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1856. if (isCopy) {
  1857. frag.appendChild(textNode);
  1858. }
  1859. removeNodes();
  1860. return isCopy ? frag : range;
  1861. }
  1862. function extractNodes(parent, frag) {
  1863. var node = parent.firstChild, nextNode;
  1864. while (node) {
  1865. var testRange = new KRange(doc).selectNode(node);
  1866. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1867. if (start >= 0 && incStart <= 0) {
  1868. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1869. }
  1870. if (incStart >= 0 && incEnd <= 0) {
  1871. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1872. }
  1873. if (incEnd >= 0 && end <= 0) {
  1874. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1875. }
  1876. if (end >= 0) {
  1877. return false;
  1878. }
  1879. nextNode = node.nextSibling;
  1880. if (start > 0) {
  1881. if (node.nodeType == 1) {
  1882. if (incStart >= 0 && incEnd <= 0) {
  1883. if (isCopy) {
  1884. frag.appendChild(node.cloneNode(true));
  1885. }
  1886. if (isDelete) {
  1887. nodeList.push(node);
  1888. }
  1889. } else {
  1890. var childFlag;
  1891. if (isCopy) {
  1892. childFlag = node.cloneNode(false);
  1893. frag.appendChild(childFlag);
  1894. }
  1895. if (extractNodes(node, childFlag) === false) {
  1896. return false;
  1897. }
  1898. }
  1899. } else if (node.nodeType == 3) {
  1900. var textNode;
  1901. if (node == copyRange.startContainer) {
  1902. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1903. } else if (node == copyRange.endContainer) {
  1904. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1905. } else {
  1906. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1907. }
  1908. if (isCopy) {
  1909. try {
  1910. frag.appendChild(textNode);
  1911. } catch(e) {}
  1912. }
  1913. }
  1914. }
  1915. node = nextNode;
  1916. }
  1917. }
  1918. extractNodes(ancestor, frag);
  1919. if (isDelete) {
  1920. range.up().collapse(true);
  1921. }
  1922. for (var i = 0, len = nodeList.length; i < len; i++) {
  1923. var node = nodeList[i];
  1924. if (node.parentNode) {
  1925. node.parentNode.removeChild(node);
  1926. }
  1927. }
  1928. return isCopy ? frag : range;
  1929. }
  1930. function _moveToElementText(range, el) {
  1931. var node = el;
  1932. while (node) {
  1933. var knode = K(node);
  1934. if (knode.name == 'marquee' || knode.name == 'select') {
  1935. return;
  1936. }
  1937. node = node.parentNode;
  1938. }
  1939. try {
  1940. range.moveToElementText(el);
  1941. } catch(e) {}
  1942. }
  1943. function _getStartEnd(rng, isStart) {
  1944. var doc = rng.parentElement().ownerDocument,
  1945. pointRange = rng.duplicate();
  1946. pointRange.collapse(isStart);
  1947. var parent = pointRange.parentElement(),
  1948. nodes = parent.childNodes;
  1949. if (nodes.length === 0) {
  1950. return {node: parent.parentNode, offset: K(parent).index()};
  1951. }
  1952. var startNode = doc, startPos = 0, cmp = -1;
  1953. var testRange = rng.duplicate();
  1954. _moveToElementText(testRange, parent);
  1955. for (var i = 0, len = nodes.length; i < len; i++) {
  1956. var node = nodes[i];
  1957. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1958. if (cmp === 0) {
  1959. return {node: node.parentNode, offset: i};
  1960. }
  1961. if (node.nodeType == 1) {
  1962. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1963. if (knode.isControl()) {
  1964. dummy = doc.createElement('span');
  1965. knode.after(dummy);
  1966. newNode = dummy;
  1967. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1968. }
  1969. _moveToElementText(nodeRange, newNode);
  1970. testRange.setEndPoint('StartToEnd', nodeRange);
  1971. if (cmp > 0) {
  1972. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1973. } else {
  1974. startPos = 0;
  1975. }
  1976. if (dummy) {
  1977. K(dummy).remove();
  1978. }
  1979. } else if (node.nodeType == 3) {
  1980. testRange.moveStart('character', node.nodeValue.length);
  1981. startPos += node.nodeValue.length;
  1982. }
  1983. if (cmp < 0) {
  1984. startNode = node;
  1985. }
  1986. }
  1987. if (cmp < 0 && startNode.nodeType == 1) {
  1988. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1989. }
  1990. if (cmp > 0) {
  1991. while (startNode.nextSibling && startNode.nodeType == 1) {
  1992. startNode = startNode.nextSibling;
  1993. }
  1994. }
  1995. testRange = rng.duplicate();
  1996. _moveToElementText(testRange, parent);
  1997. testRange.setEndPoint('StartToEnd', pointRange);
  1998. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1999. if (cmp > 0 && startNode.nodeType == 3) {
  2000. var prevNode = startNode.previousSibling;
  2001. while (prevNode && prevNode.nodeType == 3) {
  2002. startPos -= prevNode.nodeValue.length;
  2003. prevNode = prevNode.previousSibling;
  2004. }
  2005. }
  2006. return {node: startNode, offset: startPos};
  2007. }
  2008. function _getEndRange(node, offset) {
  2009. var doc = node.ownerDocument || node,
  2010. range = doc.body.createTextRange();
  2011. if (doc == node) {
  2012. range.collapse(true);
  2013. return range;
  2014. }
  2015. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2016. var children = node.childNodes, isStart, child;
  2017. if (offset === 0) {
  2018. child = children[0];
  2019. isStart = true;
  2020. } else {
  2021. child = children[offset - 1];
  2022. isStart = false;
  2023. }
  2024. if (!child) {
  2025. return range;
  2026. }
  2027. if (K(child).name === 'head') {
  2028. if (offset === 1) {
  2029. isStart = true;
  2030. }
  2031. if (offset === 2) {
  2032. isStart = false;
  2033. }
  2034. range.collapse(isStart);
  2035. return range;
  2036. }
  2037. if (child.nodeType == 1) {
  2038. var kchild = K(child), span;
  2039. if (kchild.isControl()) {
  2040. span = doc.createElement('span');
  2041. if (isStart) {
  2042. kchild.before(span);
  2043. } else {
  2044. kchild.after(span);
  2045. }
  2046. child = span;
  2047. }
  2048. _moveToElementText(range, child);
  2049. range.collapse(isStart);
  2050. if (span) {
  2051. K(span).remove();
  2052. }
  2053. return range;
  2054. }
  2055. node = child;
  2056. offset = isStart ? 0 : child.nodeValue.length;
  2057. }
  2058. var dummy = doc.createElement('span');
  2059. K(node).before(dummy);
  2060. _moveToElementText(range, dummy);
  2061. range.moveStart('character', offset);
  2062. K(dummy).remove();
  2063. return range;
  2064. }
  2065. function _toRange(rng) {
  2066. var doc, range;
  2067. function tr2td(start) {
  2068. if (K(start.node).name == 'tr') {
  2069. start.node = start.node.cells[start.offset];
  2070. start.offset = 0;
  2071. }
  2072. }
  2073. if (_IERANGE) {
  2074. if (rng.item) {
  2075. doc = _getDoc(rng.item(0));
  2076. range = new KRange(doc);
  2077. range.selectNode(rng.item(0));
  2078. return range;
  2079. }
  2080. doc = rng.parentElement().ownerDocument;
  2081. var start = _getStartEnd(rng, true),
  2082. end = _getStartEnd(rng, false);
  2083. tr2td(start);
  2084. tr2td(end);
  2085. range = new KRange(doc);
  2086. range.setStart(start.node, start.offset);
  2087. range.setEnd(end.node, end.offset);
  2088. return range;
  2089. }
  2090. var startContainer = rng.startContainer;
  2091. doc = startContainer.ownerDocument || startContainer;
  2092. range = new KRange(doc);
  2093. range.setStart(startContainer, rng.startOffset);
  2094. range.setEnd(rng.endContainer, rng.endOffset);
  2095. return range;
  2096. }
  2097. function KRange(doc) {
  2098. this.init(doc);
  2099. }
  2100. _extend(KRange, {
  2101. init : function(doc) {
  2102. var self = this;
  2103. self.startContainer = doc;
  2104. self.startOffset = 0;
  2105. self.endContainer = doc;
  2106. self.endOffset = 0;
  2107. self.collapsed = true;
  2108. self.doc = doc;
  2109. },
  2110. commonAncestor : function() {
  2111. function getParents(node) {
  2112. var parents = [];
  2113. while (node) {
  2114. parents.push(node);
  2115. node = node.parentNode;
  2116. }
  2117. return parents;
  2118. }
  2119. var parentsA = getParents(this.startContainer),
  2120. parentsB = getParents(this.endContainer),
  2121. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2122. while (++i) {
  2123. parentA = parentsA[lenA - i];
  2124. parentB = parentsB[lenB - i];
  2125. if (!parentA || !parentB || parentA !== parentB) {
  2126. break;
  2127. }
  2128. }
  2129. return parentsA[lenA - i + 1];
  2130. },
  2131. setStart : function(node, offset) {
  2132. var self = this, doc = self.doc;
  2133. self.startContainer = node;
  2134. self.startOffset = offset;
  2135. if (self.endContainer === doc) {
  2136. self.endContainer = node;
  2137. self.endOffset = offset;
  2138. }
  2139. return _updateCollapsed(this);
  2140. },
  2141. setEnd : function(node, offset) {
  2142. var self = this, doc = self.doc;
  2143. self.endContainer = node;
  2144. self.endOffset = offset;
  2145. if (self.startContainer === doc) {
  2146. self.startContainer = node;
  2147. self.startOffset = offset;
  2148. }
  2149. return _updateCollapsed(this);
  2150. },
  2151. setStartBefore : function(node) {
  2152. return this.setStart(node.parentNode || this.doc, K(node).index());
  2153. },
  2154. setStartAfter : function(node) {
  2155. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2156. },
  2157. setEndBefore : function(node) {
  2158. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2159. },
  2160. setEndAfter : function(node) {
  2161. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2162. },
  2163. selectNode : function(node) {
  2164. return this.setStartBefore(node).setEndAfter(node);
  2165. },
  2166. selectNodeContents : function(node) {
  2167. var knode = K(node);
  2168. if (knode.type == 3 || knode.isSingle()) {
  2169. return this.selectNode(node);
  2170. }
  2171. var children = knode.children();
  2172. if (children.length > 0) {
  2173. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2174. }
  2175. return this.setStart(node, 0).setEnd(node, 0);
  2176. },
  2177. collapse : function(toStart) {
  2178. if (toStart) {
  2179. return this.setEnd(this.startContainer, this.startOffset);
  2180. }
  2181. return this.setStart(this.endContainer, this.endOffset);
  2182. },
  2183. compareBoundaryPoints : function(how, range) {
  2184. var rangeA = this.get(), rangeB = range.get();
  2185. if (_IERANGE) {
  2186. var arr = {};
  2187. arr[_START_TO_START] = 'StartToStart';
  2188. arr[_START_TO_END] = 'EndToStart';
  2189. arr[_END_TO_END] = 'EndToEnd';
  2190. arr[_END_TO_START] = 'StartToEnd';
  2191. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2192. if (cmp !== 0) {
  2193. return cmp;
  2194. }
  2195. var nodeA, nodeB, nodeC, posA, posB;
  2196. if (how === _START_TO_START || how === _END_TO_START) {
  2197. nodeA = this.startContainer;
  2198. posA = this.startOffset;
  2199. }
  2200. if (how === _START_TO_END || how === _END_TO_END) {
  2201. nodeA = this.endContainer;
  2202. posA = this.endOffset;
  2203. }
  2204. if (how === _START_TO_START || how === _START_TO_END) {
  2205. nodeB = range.startContainer;
  2206. posB = range.startOffset;
  2207. }
  2208. if (how === _END_TO_END || how === _END_TO_START) {
  2209. nodeB = range.endContainer;
  2210. posB = range.endOffset;
  2211. }
  2212. if (nodeA === nodeB) {
  2213. var diff = posA - posB;
  2214. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2215. }
  2216. nodeC = nodeB;
  2217. while (nodeC && nodeC.parentNode !== nodeA) {
  2218. nodeC = nodeC.parentNode;
  2219. }
  2220. if (nodeC) {
  2221. return K(nodeC).index() >= posA ? -1 : 1;
  2222. }
  2223. nodeC = nodeA;
  2224. while (nodeC && nodeC.parentNode !== nodeB) {
  2225. nodeC = nodeC.parentNode;
  2226. }
  2227. if (nodeC) {
  2228. return K(nodeC).index() >= posB ? 1 : -1;
  2229. }
  2230. nodeC = K(nodeB).next();
  2231. if (nodeC && nodeC.contains(nodeA)) {
  2232. return 1;
  2233. }
  2234. nodeC = K(nodeA).next();
  2235. if (nodeC && nodeC.contains(nodeB)) {
  2236. return -1;
  2237. }
  2238. } else {
  2239. return rangeA.compareBoundaryPoints(how, rangeB);
  2240. }
  2241. },
  2242. cloneRange : function() {
  2243. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2244. },
  2245. toString : function() {
  2246. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2247. return str.replace(/\r\n|\n|\r/g, '');
  2248. },
  2249. cloneContents : function() {
  2250. return _copyAndDelete(this, true, false);
  2251. },
  2252. deleteContents : function() {
  2253. return _copyAndDelete(this, false, true);
  2254. },
  2255. extractContents : function() {
  2256. return _copyAndDelete(this, true, true);
  2257. },
  2258. insertNode : function(node) {
  2259. var self = this,
  2260. sc = self.startContainer, so = self.startOffset,
  2261. ec = self.endContainer, eo = self.endOffset,
  2262. firstChild, lastChild, c, nodeCount = 1;
  2263. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2264. firstChild = node.firstChild;
  2265. lastChild = node.lastChild;
  2266. nodeCount = node.childNodes.length;
  2267. }
  2268. if (sc.nodeType == 1) {
  2269. c = sc.childNodes[so];
  2270. if (c) {
  2271. sc.insertBefore(node, c);
  2272. if (sc === ec) {
  2273. eo += nodeCount;
  2274. }
  2275. } else {
  2276. sc.appendChild(node);
  2277. }
  2278. } else if (sc.nodeType == 3) {
  2279. if (so === 0) {
  2280. sc.parentNode.insertBefore(node, sc);
  2281. if (sc.parentNode === ec) {
  2282. eo += nodeCount;
  2283. }
  2284. } else if (so >= sc.nodeValue.length) {
  2285. if (sc.nextSibling) {
  2286. sc.parentNode.insertBefore(node, sc.nextSibling);
  2287. } else {
  2288. sc.parentNode.appendChild(node);
  2289. }
  2290. } else {
  2291. if (so > 0) {
  2292. c = sc.splitText(so);
  2293. } else {
  2294. c = sc;
  2295. }
  2296. sc.parentNode.insertBefore(node, c);
  2297. if (sc === ec) {
  2298. ec = c;
  2299. eo -= so;
  2300. }
  2301. }
  2302. }
  2303. if (firstChild) {
  2304. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2305. } else {
  2306. self.selectNode(node);
  2307. }
  2308. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2309. return self;
  2310. }
  2311. return self.setEnd(ec, eo);
  2312. },
  2313. surroundContents : function(node) {
  2314. node.appendChild(this.extractContents());
  2315. return this.insertNode(node).selectNode(node);
  2316. },
  2317. isControl : function() {
  2318. var self = this,
  2319. sc = self.startContainer, so = self.startOffset,
  2320. ec = self.endContainer, eo = self.endOffset, rng;
  2321. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2322. },
  2323. get : function(hasControlRange) {
  2324. var self = this, doc = self.doc, node, rng;
  2325. if (!_IERANGE) {
  2326. rng = doc.createRange();
  2327. try {
  2328. rng.setStart(self.startContainer, self.startOffset);
  2329. rng.setEnd(self.endContainer, self.endOffset);
  2330. } catch (e) {}
  2331. return rng;
  2332. }
  2333. if (hasControlRange && self.isControl()) {
  2334. rng = doc.body.createControlRange();
  2335. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2336. return rng;
  2337. }
  2338. var range = self.cloneRange().down();
  2339. rng = doc.body.createTextRange();
  2340. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2341. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2342. return rng;
  2343. },
  2344. html : function() {
  2345. return K(this.cloneContents()).outer();
  2346. },
  2347. down : function() {
  2348. var self = this;
  2349. function downPos(node, pos, isStart) {
  2350. if (node.nodeType != 1) {
  2351. return;
  2352. }
  2353. var children = K(node).children();
  2354. if (children.length === 0) {
  2355. return;
  2356. }
  2357. var left, right, child, offset;
  2358. if (pos > 0) {
  2359. left = children.eq(pos - 1);
  2360. }
  2361. if (pos < children.length) {
  2362. right = children.eq(pos);
  2363. }
  2364. if (left && left.type == 3) {
  2365. child = left[0];
  2366. offset = child.nodeValue.length;
  2367. }
  2368. if (right && right.type == 3) {
  2369. child = right[0];
  2370. offset = 0;
  2371. }
  2372. if (!child) {
  2373. return;
  2374. }
  2375. if (isStart) {
  2376. self.setStart(child, offset);
  2377. } else {
  2378. self.setEnd(child, offset);
  2379. }
  2380. }
  2381. downPos(self.startContainer, self.startOffset, true);
  2382. downPos(self.endContainer, self.endOffset, false);
  2383. return self;
  2384. },
  2385. up : function() {
  2386. var self = this;
  2387. function upPos(node, pos, isStart) {
  2388. if (node.nodeType != 3) {
  2389. return;
  2390. }
  2391. if (pos === 0) {
  2392. if (isStart) {
  2393. self.setStartBefore(node);
  2394. } else {
  2395. self.setEndBefore(node);
  2396. }
  2397. } else if (pos == node.nodeValue.length) {
  2398. if (isStart) {
  2399. self.setStartAfter(node);
  2400. } else {
  2401. self.setEndAfter(node);
  2402. }
  2403. }
  2404. }
  2405. upPos(self.startContainer, self.startOffset, true);
  2406. upPos(self.endContainer, self.endOffset, false);
  2407. return self;
  2408. },
  2409. enlarge : function(toBlock) {
  2410. var self = this;
  2411. self.up();
  2412. function enlargePos(node, pos, isStart) {
  2413. var knode = K(node), parent;
  2414. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2415. return;
  2416. }
  2417. if (pos === 0) {
  2418. while (!knode.prev()) {
  2419. parent = knode.parent();
  2420. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2421. break;
  2422. }
  2423. knode = parent;
  2424. }
  2425. if (isStart) {
  2426. self.setStartBefore(knode[0]);
  2427. } else {
  2428. self.setEndBefore(knode[0]);
  2429. }
  2430. } else if (pos == knode.children().length) {
  2431. while (!knode.next()) {
  2432. parent = knode.parent();
  2433. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2434. break;
  2435. }
  2436. knode = parent;
  2437. }
  2438. if (isStart) {
  2439. self.setStartAfter(knode[0]);
  2440. } else {
  2441. self.setEndAfter(knode[0]);
  2442. }
  2443. }
  2444. }
  2445. enlargePos(self.startContainer, self.startOffset, true);
  2446. enlargePos(self.endContainer, self.endOffset, false);
  2447. return self;
  2448. },
  2449. shrink : function() {
  2450. var self = this, child, collapsed = self.collapsed;
  2451. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2452. self.setStart(child, 0);
  2453. }
  2454. if (collapsed) {
  2455. return self.collapse(collapsed);
  2456. }
  2457. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2458. self.setEnd(child, child.childNodes.length);
  2459. }
  2460. return self;
  2461. },
  2462. createBookmark : function(serialize) {
  2463. var self = this, doc = self.doc, endNode,
  2464. startNode = K('<span style="display:none;"></span>', doc)[0];
  2465. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2466. if (!self.collapsed) {
  2467. endNode = startNode.cloneNode(true);
  2468. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2469. }
  2470. if (endNode) {
  2471. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2472. }
  2473. self.insertNode(startNode).setStartAfter(startNode);
  2474. return {
  2475. start : serialize ? '#' + startNode.id : startNode,
  2476. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2477. };
  2478. },
  2479. moveToBookmark : function(bookmark) {
  2480. var self = this, doc = self.doc,
  2481. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2482. if (!start || start.length < 1) {
  2483. return self;
  2484. }
  2485. self.setStartBefore(start[0]);
  2486. start.remove();
  2487. if (end && end.length > 0) {
  2488. self.setEndBefore(end[0]);
  2489. end.remove();
  2490. } else {
  2491. self.collapse(true);
  2492. }
  2493. return self;
  2494. },
  2495. dump : function() {
  2496. console.log('--------------------');
  2497. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2498. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2499. }
  2500. });
  2501. function _range(mixed) {
  2502. if (!mixed.nodeName) {
  2503. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2504. }
  2505. return new KRange(mixed);
  2506. }
  2507. K.RangeClass = KRange;
  2508. K.range = _range;
  2509. K.START_TO_START = _START_TO_START;
  2510. K.START_TO_END = _START_TO_END;
  2511. K.END_TO_END = _END_TO_END;
  2512. K.END_TO_START = _END_TO_START;
  2513. function _nativeCommand(doc, key, val) {
  2514. try {
  2515. doc.execCommand(key, false, val);
  2516. } catch(e) {}
  2517. }
  2518. function _nativeCommandValue(doc, key) {
  2519. var val = '';
  2520. try {
  2521. val = doc.queryCommandValue(key);
  2522. } catch (e) {}
  2523. if (typeof val !== 'string') {
  2524. val = '';
  2525. }
  2526. return val;
  2527. }
  2528. function _getSel(doc) {
  2529. var win = _getWin(doc);
  2530. return _IERANGE ? doc.selection : win.getSelection();
  2531. }
  2532. function _getRng(doc) {
  2533. var sel = _getSel(doc), rng;
  2534. try {
  2535. if (sel.rangeCount > 0) {
  2536. rng = sel.getRangeAt(0);
  2537. } else {
  2538. rng = sel.createRange();
  2539. }
  2540. } catch(e) {}
  2541. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2542. return null;
  2543. }
  2544. return rng;
  2545. }
  2546. function _singleKeyMap(map) {
  2547. var newMap = {}, arr, v;
  2548. _each(map, function(key, val) {
  2549. arr = key.split(',');
  2550. for (var i = 0, len = arr.length; i < len; i++) {
  2551. v = arr[i];
  2552. newMap[v] = val;
  2553. }
  2554. });
  2555. return newMap;
  2556. }
  2557. function _hasAttrOrCss(knode, map) {
  2558. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2559. }
  2560. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2561. mapKey = mapKey || knode.name;
  2562. if (knode.type !== 1) {
  2563. return false;
  2564. }
  2565. var newMap = _singleKeyMap(map);
  2566. if (!newMap[mapKey]) {
  2567. return false;
  2568. }
  2569. var arr = newMap[mapKey].split(',');
  2570. for (var i = 0, len = arr.length; i < len; i++) {
  2571. var key = arr[i];
  2572. if (key === '*') {
  2573. return true;
  2574. }
  2575. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2576. var method = match[1] ? 'css' : 'attr';
  2577. key = match[2];
  2578. var val = match[3] || '';
  2579. if (val === '' && knode[method](key) !== '') {
  2580. return true;
  2581. }
  2582. if (val !== '' && knode[method](key) === val) {
  2583. return true;
  2584. }
  2585. }
  2586. return false;
  2587. }
  2588. function _removeAttrOrCss(knode, map) {
  2589. if (knode.type != 1) {
  2590. return;
  2591. }
  2592. _removeAttrOrCssByKey(knode, map, '*');
  2593. _removeAttrOrCssByKey(knode, map);
  2594. }
  2595. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2596. mapKey = mapKey || knode.name;
  2597. if (knode.type !== 1) {
  2598. return;
  2599. }
  2600. var newMap = _singleKeyMap(map);
  2601. if (!newMap[mapKey]) {
  2602. return;
  2603. }
  2604. var arr = newMap[mapKey].split(','), allFlag = false;
  2605. for (var i = 0, len = arr.length; i < len; i++) {
  2606. var key = arr[i];
  2607. if (key === '*') {
  2608. allFlag = true;
  2609. break;
  2610. }
  2611. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2612. key = match[2];
  2613. if (match[1]) {
  2614. key = _toCamel(key);
  2615. if (knode[0].style[key]) {
  2616. knode[0].style[key] = '';
  2617. }
  2618. } else {
  2619. knode.removeAttr(key);
  2620. }
  2621. }
  2622. if (allFlag) {
  2623. knode.remove(true);
  2624. }
  2625. }
  2626. function _getInnerNode(knode) {
  2627. var inner = knode;
  2628. while (inner.first()) {
  2629. inner = inner.first();
  2630. }
  2631. return inner;
  2632. }
  2633. function _isEmptyNode(knode) {
  2634. if (knode.type != 1 || knode.isSingle()) {
  2635. return false;
  2636. }
  2637. return knode.html().replace(/<[^>]+>/g, '') === '';
  2638. }
  2639. function _mergeWrapper(a, b) {
  2640. a = a.clone(true);
  2641. var lastA = _getInnerNode(a), childA = a, merged = false;
  2642. while (b) {
  2643. while (childA) {
  2644. if (childA.name === b.name) {
  2645. _mergeAttrs(childA, b.attr(), b.css());
  2646. merged = true;
  2647. }
  2648. childA = childA.first();
  2649. }
  2650. if (!merged) {
  2651. lastA.append(b.clone(false));
  2652. }
  2653. merged = false;
  2654. b = b.first();
  2655. }
  2656. return a;
  2657. }
  2658. function _wrapNode(knode, wrapper) {
  2659. wrapper = wrapper.clone(true);
  2660. if (knode.type == 3) {
  2661. _getInnerNode(wrapper).append(knode.clone(false));
  2662. knode.replaceWith(wrapper);
  2663. return wrapper;
  2664. }
  2665. var nodeWrapper = knode, child;
  2666. while ((child = knode.first()) && child.children().length == 1) {
  2667. knode = child;
  2668. }
  2669. child = knode.first();
  2670. var frag = knode.doc.createDocumentFragment();
  2671. while (child) {
  2672. frag.appendChild(child[0]);
  2673. child = child.next();
  2674. }
  2675. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2676. if (frag.firstChild) {
  2677. _getInnerNode(wrapper).append(frag);
  2678. }
  2679. nodeWrapper.replaceWith(wrapper);
  2680. return wrapper;
  2681. }
  2682. function _mergeAttrs(knode, attrs, styles) {
  2683. _each(attrs, function(key, val) {
  2684. if (key !== 'style') {
  2685. knode.attr(key, val);
  2686. }
  2687. });
  2688. _each(styles, function(key, val) {
  2689. knode.css(key, val);
  2690. });
  2691. }
  2692. function _inPreElement(knode) {
  2693. while (knode && knode.name != 'body') {
  2694. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2695. return true;
  2696. }
  2697. knode = knode.parent();
  2698. }
  2699. return false;
  2700. }
  2701. function KCmd(range) {
  2702. this.init(range);
  2703. }
  2704. _extend(KCmd, {
  2705. init : function(range) {
  2706. var self = this, doc = range.doc;
  2707. self.doc = doc;
  2708. self.win = _getWin(doc);
  2709. self.sel = _getSel(doc);
  2710. self.range = range;
  2711. },
  2712. selection : function(forceReset) {
  2713. var self = this, doc = self.doc, rng = _getRng(doc);
  2714. self.sel = _getSel(doc);
  2715. if (rng) {
  2716. self.range = _range(rng);
  2717. if (K(self.range.startContainer).name == 'html') {
  2718. self.range.selectNodeContents(doc.body).collapse(false);
  2719. }
  2720. return self;
  2721. }
  2722. if (forceReset) {
  2723. self.range.selectNodeContents(doc.body).collapse(false);
  2724. }
  2725. return self;
  2726. },
  2727. select : function(hasDummy) {
  2728. hasDummy = _undef(hasDummy, true);
  2729. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2730. sc = range.startContainer, so = range.startOffset,
  2731. ec = range.endContainer, eo = range.endOffset,
  2732. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2733. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2734. if (_IERANGE) {
  2735. var dummy = K('<span>&nbsp;</span>', doc);
  2736. range.insertNode(dummy[0]);
  2737. rng = doc.body.createTextRange();
  2738. try {
  2739. rng.moveToElementText(dummy[0]);
  2740. } catch(ex) {}
  2741. rng.collapse(false);
  2742. rng.select();
  2743. dummy.remove();
  2744. win.focus();
  2745. return self;
  2746. }
  2747. if (_WEBKIT) {
  2748. var children = sc.childNodes;
  2749. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2750. range.insertNode(doc.createTextNode('\u200B'));
  2751. hasU200b = true;
  2752. }
  2753. }
  2754. }
  2755. if (_IERANGE) {
  2756. try {
  2757. rng = range.get(true);
  2758. rng.select();
  2759. } catch(e) {}
  2760. } else {
  2761. if (hasU200b) {
  2762. range.collapse(false);
  2763. }
  2764. rng = range.get(true);
  2765. sel.removeAllRanges();
  2766. sel.addRange(rng);
  2767. if (doc !== document) {
  2768. var pos = K(rng.endContainer).pos();
  2769. win.scrollTo(pos.x, pos.y);
  2770. }
  2771. }
  2772. win.focus();
  2773. return self;
  2774. },
  2775. wrap : function(val) {
  2776. var self = this, doc = self.doc, range = self.range, wrapper;
  2777. wrapper = K(val, doc);
  2778. if (range.collapsed) {
  2779. range.shrink();
  2780. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2781. return self;
  2782. }
  2783. if (wrapper.isBlock()) {
  2784. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2785. while (child.first()) {
  2786. child = child.first();
  2787. }
  2788. child.append(range.extractContents());
  2789. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2790. return self;
  2791. }
  2792. range.enlarge();
  2793. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2794. K(ancestor).scan(function(node) {
  2795. if (!isStart && node == bookmark.start) {
  2796. isStart = true;
  2797. return;
  2798. }
  2799. if (isStart) {
  2800. if (node == bookmark.end) {
  2801. return false;
  2802. }
  2803. var knode = K(node);
  2804. if (_inPreElement(knode)) {
  2805. return;
  2806. }
  2807. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2808. var parent;
  2809. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2810. knode = parent;
  2811. }
  2812. _wrapNode(knode, wrapper);
  2813. }
  2814. }
  2815. });
  2816. range.moveToBookmark(bookmark);
  2817. return self;
  2818. },
  2819. split : function(isStart, map) {
  2820. var range = this.range, doc = range.doc;
  2821. var tempRange = range.cloneRange().collapse(isStart);
  2822. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2823. parent = node.nodeType == 3 ? node.parentNode : node,
  2824. needSplit = false, knode;
  2825. while (parent && parent.parentNode) {
  2826. knode = K(parent);
  2827. if (map) {
  2828. if (!knode.isStyle()) {
  2829. break;
  2830. }
  2831. if (!_hasAttrOrCss(knode, map)) {
  2832. break;
  2833. }
  2834. } else {
  2835. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2836. break;
  2837. }
  2838. }
  2839. needSplit = true;
  2840. parent = parent.parentNode;
  2841. }
  2842. if (needSplit) {
  2843. var dummy = doc.createElement('span');
  2844. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2845. if (isStart) {
  2846. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2847. } else {
  2848. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2849. }
  2850. var frag = tempRange.extractContents(),
  2851. first = frag.firstChild, last = frag.lastChild;
  2852. if (isStart) {
  2853. tempRange.insertNode(frag);
  2854. range.setStartAfter(last).setEndBefore(dummy);
  2855. } else {
  2856. parent.appendChild(frag);
  2857. range.setStartBefore(dummy).setEndBefore(first);
  2858. }
  2859. var dummyParent = dummy.parentNode;
  2860. if (dummyParent == range.endContainer) {
  2861. var prev = K(dummy).prev(), next = K(dummy).next();
  2862. if (prev && next && prev.type == 3 && next.type == 3) {
  2863. range.setEnd(prev[0], prev[0].nodeValue.length);
  2864. } else if (!isStart) {
  2865. range.setEnd(range.endContainer, range.endOffset - 1);
  2866. }
  2867. }
  2868. dummyParent.removeChild(dummy);
  2869. }
  2870. return this;
  2871. },
  2872. remove : function(map) {
  2873. var self = this, doc = self.doc, range = self.range;
  2874. range.enlarge();
  2875. if (range.startOffset === 0) {
  2876. var ksc = K(range.startContainer), parent;
  2877. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2878. ksc = parent;
  2879. }
  2880. range.setStart(ksc[0], 0);
  2881. ksc = K(range.startContainer);
  2882. if (ksc.isBlock()) {
  2883. _removeAttrOrCss(ksc, map);
  2884. }
  2885. var kscp = ksc.parent();
  2886. if (kscp && kscp.isBlock()) {
  2887. _removeAttrOrCss(kscp, map);
  2888. }
  2889. }
  2890. var sc, so;
  2891. if (range.collapsed) {
  2892. self.split(true, map);
  2893. sc = range.startContainer;
  2894. so = range.startOffset;
  2895. if (so > 0) {
  2896. var sb = K(sc.childNodes[so - 1]);
  2897. if (sb && _isEmptyNode(sb)) {
  2898. sb.remove();
  2899. range.setStart(sc, so - 1);
  2900. }
  2901. }
  2902. var sa = K(sc.childNodes[so]);
  2903. if (sa && _isEmptyNode(sa)) {
  2904. sa.remove();
  2905. }
  2906. if (_isEmptyNode(sc)) {
  2907. range.startBefore(sc);
  2908. sc.remove();
  2909. }
  2910. range.collapse(true);
  2911. return self;
  2912. }
  2913. self.split(true, map);
  2914. self.split(false, map);
  2915. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2916. range.cloneRange().collapse(false).insertNode(endDummy);
  2917. range.cloneRange().collapse(true).insertNode(startDummy);
  2918. var nodeList = [], cmpStart = false;
  2919. K(range.commonAncestor()).scan(function(node) {
  2920. if (!cmpStart && node == startDummy) {
  2921. cmpStart = true;
  2922. return;
  2923. }
  2924. if (node == endDummy) {
  2925. return false;
  2926. }
  2927. if (cmpStart) {
  2928. nodeList.push(node);
  2929. }
  2930. });
  2931. K(startDummy).remove();
  2932. K(endDummy).remove();
  2933. sc = range.startContainer;
  2934. so = range.startOffset;
  2935. var ec = range.endContainer, eo = range.endOffset;
  2936. if (so > 0) {
  2937. var startBefore = K(sc.childNodes[so - 1]);
  2938. if (startBefore && _isEmptyNode(startBefore)) {
  2939. startBefore.remove();
  2940. range.setStart(sc, so - 1);
  2941. if (sc == ec) {
  2942. range.setEnd(ec, eo - 1);
  2943. }
  2944. }
  2945. var startAfter = K(sc.childNodes[so]);
  2946. if (startAfter && _isEmptyNode(startAfter)) {
  2947. startAfter.remove();
  2948. if (sc == ec) {
  2949. range.setEnd(ec, eo - 1);
  2950. }
  2951. }
  2952. }
  2953. var endAfter = K(ec.childNodes[range.endOffset]);
  2954. if (endAfter && _isEmptyNode(endAfter)) {
  2955. endAfter.remove();
  2956. }
  2957. var bookmark = range.createBookmark(true);
  2958. _each(nodeList, function(i, node) {
  2959. _removeAttrOrCss(K(node), map);
  2960. });
  2961. range.moveToBookmark(bookmark);
  2962. return self;
  2963. },
  2964. commonNode : function(map) {
  2965. var range = this.range;
  2966. var ec = range.endContainer, eo = range.endOffset,
  2967. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2968. function find(node) {
  2969. var child = node, parent = node;
  2970. while (parent) {
  2971. if (_hasAttrOrCss(K(parent), map)) {
  2972. return K(parent);
  2973. }
  2974. parent = parent.parentNode;
  2975. }
  2976. while (child && (child = child.lastChild)) {
  2977. if (_hasAttrOrCss(K(child), map)) {
  2978. return K(child);
  2979. }
  2980. }
  2981. return null;
  2982. }
  2983. var cNode = find(node);
  2984. if (cNode) {
  2985. return cNode;
  2986. }
  2987. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2988. var prev = K(node).prev();
  2989. if (prev) {
  2990. return find(prev);
  2991. }
  2992. }
  2993. return null;
  2994. },
  2995. commonAncestor : function(tagName) {
  2996. var range = this.range,
  2997. sc = range.startContainer, so = range.startOffset,
  2998. ec = range.endContainer, eo = range.endOffset,
  2999. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3000. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3001. function find(node) {
  3002. while (node) {
  3003. if (node.nodeType == 1) {
  3004. if (node.tagName.toLowerCase() === tagName) {
  3005. return node;
  3006. }
  3007. }
  3008. node = node.parentNode;
  3009. }
  3010. return null;
  3011. }
  3012. var start = find(startNode), end = find(endNode);
  3013. if (start && end && start === end) {
  3014. return K(start);
  3015. }
  3016. return null;
  3017. },
  3018. state : function(key) {
  3019. var self = this, doc = self.doc, bool = false;
  3020. try {
  3021. bool = doc.queryCommandState(key);
  3022. } catch (e) {}
  3023. return bool;
  3024. },
  3025. val : function(key) {
  3026. var self = this, doc = self.doc, range = self.range;
  3027. function lc(val) {
  3028. return val.toLowerCase();
  3029. }
  3030. key = lc(key);
  3031. var val = '', knode;
  3032. if (key === 'fontfamily' || key === 'fontname') {
  3033. val = _nativeCommandValue(doc, 'fontname');
  3034. val = val.replace(/['"]/g, '');
  3035. return lc(val);
  3036. }
  3037. if (key === 'formatblock') {
  3038. val = _nativeCommandValue(doc, key);
  3039. if (val === '') {
  3040. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3041. if (knode) {
  3042. val = knode.name;
  3043. }
  3044. }
  3045. if (val === 'Normal') {
  3046. val = 'p';
  3047. }
  3048. return lc(val);
  3049. }
  3050. if (key === 'fontsize') {
  3051. knode = self.commonNode({'*' : '.font-size'});
  3052. if (knode) {
  3053. val = knode.css('font-size');
  3054. }
  3055. return lc(val);
  3056. }
  3057. if (key === 'forecolor') {
  3058. knode = self.commonNode({'*' : '.color'});
  3059. if (knode) {
  3060. val = knode.css('color');
  3061. }
  3062. val = _toHex(val);
  3063. if (val === '') {
  3064. val = 'default';
  3065. }
  3066. return lc(val);
  3067. }
  3068. if (key === 'hilitecolor') {
  3069. knode = self.commonNode({'*' : '.background-color'});
  3070. if (knode) {
  3071. val = knode.css('background-color');
  3072. }
  3073. val = _toHex(val);
  3074. if (val === '') {
  3075. val = 'default';
  3076. }
  3077. return lc(val);
  3078. }
  3079. return val;
  3080. },
  3081. toggle : function(wrapper, map) {
  3082. var self = this;
  3083. if (self.commonNode(map)) {
  3084. self.remove(map);
  3085. } else {
  3086. self.wrap(wrapper);
  3087. }
  3088. return self.select();
  3089. },
  3090. bold : function() {
  3091. return this.toggle('<strong></strong>', {
  3092. span : '.font-weight=bold',
  3093. strong : '*',
  3094. b : '*'
  3095. });
  3096. },
  3097. italic : function() {
  3098. return this.toggle('<em></em>', {
  3099. span : '.font-style=italic',
  3100. em : '*',
  3101. i : '*'
  3102. });
  3103. },
  3104. underline : function() {
  3105. return this.toggle('<u></u>', {
  3106. span : '.text-decoration=underline',
  3107. u : '*'
  3108. });
  3109. },
  3110. strikethrough : function() {
  3111. return this.toggle('<s></s>', {
  3112. span : '.text-decoration=line-through',
  3113. s : '*'
  3114. });
  3115. },
  3116. forecolor : function(val) {
  3117. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3118. },
  3119. hilitecolor : function(val) {
  3120. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3121. },
  3122. fontsize : function(val) {
  3123. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3124. },
  3125. fontname : function(val) {
  3126. return this.fontfamily(val);
  3127. },
  3128. fontfamily : function(val) {
  3129. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3130. },
  3131. removeformat : function() {
  3132. var map = {
  3133. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3134. },
  3135. tags = _STYLE_TAG_MAP;
  3136. _each(tags, function(key, val) {
  3137. map[key] = '*';
  3138. });
  3139. this.remove(map);
  3140. return this.select();
  3141. },
  3142. inserthtml : function(val, quickMode) {
  3143. var self = this, range = self.range;
  3144. if (val === '') {
  3145. return self;
  3146. }
  3147. function pasteHtml(range, val) {
  3148. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3149. var rng = range.get();
  3150. if (rng.item) {
  3151. rng.item(0).outerHTML = val;
  3152. } else {
  3153. rng.pasteHTML(val);
  3154. }
  3155. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3156. temp.parentNode.removeChild(temp);
  3157. var newRange = _toRange(rng);
  3158. range.setEnd(newRange.endContainer, newRange.endOffset);
  3159. range.collapse(false);
  3160. self.select(false);
  3161. }
  3162. function insertHtml(range, val) {
  3163. var doc = range.doc,
  3164. frag = doc.createDocumentFragment();
  3165. K('@' + val, doc).each(function() {
  3166. frag.appendChild(this);
  3167. });
  3168. range.deleteContents();
  3169. range.insertNode(frag);
  3170. range.collapse(false);
  3171. self.select(false);
  3172. }
  3173. if (_IERANGE && quickMode) {
  3174. try {
  3175. pasteHtml(range, val);
  3176. } catch(e) {
  3177. insertHtml(range, val);
  3178. }
  3179. return self;
  3180. }
  3181. insertHtml(range, val);
  3182. return self;
  3183. },
  3184. hr : function() {
  3185. return this.inserthtml('<hr />');
  3186. },
  3187. print : function() {
  3188. this.win.print();
  3189. return this;
  3190. },
  3191. insertimage : function(url, title, width, height, border, align) {
  3192. title = _undef(title, '');
  3193. border = _undef(border, 0);
  3194. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3195. if (width) {
  3196. html += 'width="' + _escape(width) + '" ';
  3197. }
  3198. if (height) {
  3199. html += 'height="' + _escape(height) + '" ';
  3200. }
  3201. if (title) {
  3202. html += 'title="' + _escape(title) + '" ';
  3203. }
  3204. if (align) {
  3205. html += 'align="' + _escape(align) + '" ';
  3206. }
  3207. html += 'alt="' + _escape(title) + '" ';
  3208. html += '/>';
  3209. return this.inserthtml(html);
  3210. },
  3211. createlink : function(url, type) {
  3212. var self = this, doc = self.doc, range = self.range;
  3213. self.select();
  3214. var a = self.commonNode({ a : '*' });
  3215. if (a && !range.isControl()) {
  3216. range.selectNode(a.get());
  3217. self.select();
  3218. }
  3219. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3220. if (type) {
  3221. html += ' target="' + _escape(type) + '"';
  3222. }
  3223. if (range.collapsed) {
  3224. html += '>' + _escape(url) + '</a>';
  3225. return self.inserthtml(html);
  3226. }
  3227. if (range.isControl()) {
  3228. var node = K(range.startContainer.childNodes[range.startOffset]);
  3229. html += '></a>';
  3230. node.after(K(html, doc));
  3231. node.next().append(node);
  3232. range.selectNode(node[0]);
  3233. return self.select();
  3234. }
  3235. function setAttr(node, url, type) {
  3236. K(node).attr('href', url).attr('data-ke-src', url);
  3237. if (type) {
  3238. K(node).attr('target', type);
  3239. } else {
  3240. K(node).removeAttr('target');
  3241. }
  3242. }
  3243. var sc = range.startContainer, so = range.startOffset,
  3244. ec = range.endContainer, eo = range.endOffset;
  3245. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3246. var child = sc.childNodes[so];
  3247. if (child.nodeName.toLowerCase() == 'a') {
  3248. setAttr(child, url, type);
  3249. return self;
  3250. }
  3251. }
  3252. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3253. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3254. setAttr(this, url, type);
  3255. });
  3256. return self;
  3257. },
  3258. unlink : function() {
  3259. var self = this, doc = self.doc, range = self.range;
  3260. self.select();
  3261. if (range.collapsed) {
  3262. var a = self.commonNode({ a : '*' });
  3263. if (a) {
  3264. range.selectNode(a.get());
  3265. self.select();
  3266. }
  3267. _nativeCommand(doc, 'unlink', null);
  3268. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3269. var parent = K(range.startContainer).parent();
  3270. if (parent.name === 'a') {
  3271. parent.remove(true);
  3272. }
  3273. }
  3274. } else {
  3275. _nativeCommand(doc, 'unlink', null);
  3276. }
  3277. return self;
  3278. }
  3279. });
  3280. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3281. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3282. KCmd.prototype[name] = function(val) {
  3283. var self = this;
  3284. self.select();
  3285. _nativeCommand(self.doc, name, val);
  3286. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3287. self.selection();
  3288. }
  3289. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3290. self.selection();
  3291. }
  3292. return self;
  3293. };
  3294. });
  3295. _each('cut,copy,paste'.split(','), function(i, name) {
  3296. KCmd.prototype[name] = function() {
  3297. var self = this;
  3298. if (!self.doc.queryCommandSupported(name)) {
  3299. throw 'not supported';
  3300. }
  3301. self.select();
  3302. _nativeCommand(self.doc, name, null);
  3303. return self;
  3304. };
  3305. });
  3306. function _cmd(mixed) {
  3307. if (mixed.nodeName) {
  3308. var doc = _getDoc(mixed);
  3309. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3310. }
  3311. return new KCmd(mixed);
  3312. }
  3313. K.CmdClass = KCmd;
  3314. K.cmd = _cmd;
  3315. function _drag(options) {
  3316. var moveEl = options.moveEl,
  3317. moveFn = options.moveFn,
  3318. clickEl = options.clickEl || moveEl,
  3319. beforeDrag = options.beforeDrag,
  3320. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3321. var docs = [document];
  3322. if (iframeFix) {
  3323. K('iframe').each(function() {
  3324. var src = _formatUrl(this.src || '', 'absolute');
  3325. if (/^https?:\/\//.test(src)) {
  3326. return;
  3327. }
  3328. var doc;
  3329. try {
  3330. doc = _iframeDoc(this);
  3331. } catch(e) {}
  3332. if (doc) {
  3333. var pos = K(this).pos();
  3334. K(doc).data('pos-x', pos.x);
  3335. K(doc).data('pos-y', pos.y);
  3336. docs.push(doc);
  3337. }
  3338. });
  3339. }
  3340. clickEl.mousedown(function(e) {
  3341. if(e.button !== 0 && e.button !== 1) {
  3342. return;
  3343. }
  3344. e.stopPropagation();
  3345. var self = clickEl.get(),
  3346. x = _removeUnit(moveEl.css('left')),
  3347. y = _removeUnit(moveEl.css('top')),
  3348. width = moveEl.width(),
  3349. height = moveEl.height(),
  3350. pageX = e.pageX,
  3351. pageY = e.pageY;
  3352. if (beforeDrag) {
  3353. beforeDrag();
  3354. }
  3355. function moveListener(e) {
  3356. e.preventDefault();
  3357. var kdoc = K(_getDoc(e.target));
  3358. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3359. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3360. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3361. }
  3362. function selectListener(e) {
  3363. e.preventDefault();
  3364. }
  3365. function upListener(e) {
  3366. e.preventDefault();
  3367. K(docs).unbind('mousemove', moveListener)
  3368. .unbind('mouseup', upListener)
  3369. .unbind('selectstart', selectListener);
  3370. if (self.releaseCapture) {
  3371. self.releaseCapture();
  3372. }
  3373. }
  3374. K(docs).mousemove(moveListener)
  3375. .mouseup(upListener)
  3376. .bind('selectstart', selectListener);
  3377. if (self.setCapture) {
  3378. self.setCapture();
  3379. }
  3380. });
  3381. }
  3382. function KWidget(options) {
  3383. this.init(options);
  3384. }
  3385. _extend(KWidget, {
  3386. init : function(options) {
  3387. var self = this;
  3388. self.name = options.name || '';
  3389. self.doc = options.doc || document;
  3390. self.win = _getWin(self.doc);
  3391. self.x = _addUnit(options.x);
  3392. self.y = _addUnit(options.y);
  3393. self.z = options.z;
  3394. self.width = _addUnit(options.width);
  3395. self.height = _addUnit(options.height);
  3396. self.index = _addUnit(options.index);
  3397. self.div = K('<div style="display:block;"></div>');
  3398. self.options = options;
  3399. self._alignEl = options.alignEl;
  3400. if (self.width) {
  3401. self.div.css('width', self.width);
  3402. }
  3403. if (self.height) {
  3404. self.div.css('height', self.height);
  3405. }
  3406. if (self.z) {
  3407. self.div.css({
  3408. position : 'absolute',
  3409. left : self.x,
  3410. top : self.y,
  3411. 'z-index' : self.z
  3412. });
  3413. }
  3414. if (self.z && (self.x === undefined || self.y === undefined)) {
  3415. self.autoPos(self.width, self.height);
  3416. }
  3417. if (options.cls) {
  3418. self.div.addClass(options.cls);
  3419. }
  3420. if (options.shadowMode) {
  3421. self.div.addClass('ke-shadow');
  3422. }
  3423. if (options.css) {
  3424. self.div.css(options.css);
  3425. }
  3426. if (options.src) {
  3427. K(options.src).replaceWith(self.div);
  3428. } else {
  3429. K(self.doc.body).append(self.div);
  3430. }
  3431. if (options.html) {
  3432. self.div.html(options.html);
  3433. }
  3434. if (options.autoScroll) {
  3435. if (_IE && _V < 7 || _QUIRKS) {
  3436. var scrollPos = _getScrollPos();
  3437. K(self.win).bind('scroll', function(e) {
  3438. var pos = _getScrollPos(),
  3439. diffX = pos.x - scrollPos.x,
  3440. diffY = pos.y - scrollPos.y;
  3441. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3442. });
  3443. } else {
  3444. self.div.css('position', 'fixed');
  3445. }
  3446. }
  3447. },
  3448. pos : function(x, y, updateProp) {
  3449. var self = this;
  3450. updateProp = _undef(updateProp, true);
  3451. if (x !== null) {
  3452. x = x < 0 ? 0 : _addUnit(x);
  3453. self.div.css('left', x);
  3454. if (updateProp) {
  3455. self.x = x;
  3456. }
  3457. }
  3458. if (y !== null) {
  3459. y = y < 0 ? 0 : _addUnit(y);
  3460. self.div.css('top', y);
  3461. if (updateProp) {
  3462. self.y = y;
  3463. }
  3464. }
  3465. return self;
  3466. },
  3467. autoPos : function(width, height) {
  3468. var x, y, self = this,
  3469. w = _removeUnit(width) || 0,
  3470. h = _removeUnit(height) || 0,
  3471. scrollPos = _getScrollPos();
  3472. if (self._alignEl) {
  3473. var knode = K(self._alignEl),
  3474. pos = knode.pos(),
  3475. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3476. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3477. x = diffX < 0 ? pos.x : pos.x + diffX;
  3478. y = diffY < 0 ? pos.y : pos.y + diffY;
  3479. } else {
  3480. var docEl = _docElement(self.doc);
  3481. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3482. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3483. }
  3484. if (!(_IE && _V < 7 || _QUIRKS)) {
  3485. x -= scrollPos.x;
  3486. y -= scrollPos.y;
  3487. }
  3488. return self.pos(x, y);
  3489. },
  3490. remove : function() {
  3491. var self = this;
  3492. if (_IE && _V < 7 || _QUIRKS) {
  3493. K(self.win).unbind('scroll');
  3494. }
  3495. self.div.remove();
  3496. _each(self, function(i) {
  3497. self[i] = null;
  3498. });
  3499. return this;
  3500. },
  3501. show : function() {
  3502. this.div.show();
  3503. return this;
  3504. },
  3505. hide : function() {
  3506. this.div.hide();
  3507. return this;
  3508. },
  3509. draggable : function(options) {
  3510. var self = this;
  3511. options = options || {};
  3512. options.moveEl = self.div;
  3513. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3514. if ((x = x + diffX) < 0) {
  3515. x = 0;
  3516. }
  3517. if ((y = y + diffY) < 0) {
  3518. y = 0;
  3519. }
  3520. self.pos(x, y);
  3521. };
  3522. _drag(options);
  3523. return self;
  3524. }
  3525. });
  3526. function _widget(options) {
  3527. return new KWidget(options);
  3528. }
  3529. K.WidgetClass = KWidget;
  3530. K.widget = _widget;
  3531. function _iframeDoc(iframe) {
  3532. iframe = _get(iframe);
  3533. return iframe.contentDocument || iframe.contentWindow.document;
  3534. }
  3535. var html, _direction = '';
  3536. if ((html = document.getElementsByTagName('html'))) {
  3537. _direction = html[0].dir;
  3538. }
  3539. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3540. var arr = [
  3541. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3542. '<head><meta charset="utf-8" /><title></title>',
  3543. '<style>',
  3544. 'html {margin:0;padding:0;}',
  3545. 'body {margin:0;padding:5px;}',
  3546. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3547. 'body, p, div {word-wrap: break-word;}',
  3548. 'p {margin:5px 0;}',
  3549. 'table {border-collapse:collapse;}',
  3550. 'img {border:0;}',
  3551. 'noscript {display:none;}',
  3552. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3553. 'img.ke-flash {',
  3554. ' border:1px solid #AAA;',
  3555. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3556. ' background-position:center center;',
  3557. ' background-repeat:no-repeat;',
  3558. ' width:100px;',
  3559. ' height:100px;',
  3560. '}',
  3561. 'img.ke-rm {',
  3562. ' border:1px solid #AAA;',
  3563. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3564. ' background-position:center center;',
  3565. ' background-repeat:no-repeat;',
  3566. ' width:100px;',
  3567. ' height:100px;',
  3568. '}',
  3569. 'img.ke-media {',
  3570. ' border:1px solid #AAA;',
  3571. ' background-image:url(' + themesPath + 'common/media.gif);',
  3572. ' background-position:center center;',
  3573. ' background-repeat:no-repeat;',
  3574. ' width:100px;',
  3575. ' height:100px;',
  3576. '}',
  3577. 'img.ke-anchor {',
  3578. ' border:1px dashed #666;',
  3579. ' width:16px;',
  3580. ' height:16px;',
  3581. '}',
  3582. '.ke-script, .ke-noscript, .ke-display-none {',
  3583. ' display:none;',
  3584. ' font-size:0;',
  3585. ' width:0;',
  3586. ' height:0;',
  3587. '}',
  3588. '.ke-pagebreak {',
  3589. ' border:1px dotted #AAA;',
  3590. ' font-size:0;',
  3591. ' height:2px;',
  3592. '}',
  3593. '</style>'
  3594. ];
  3595. if (!_isArray(cssPath)) {
  3596. cssPath = [cssPath];
  3597. }
  3598. _each(cssPath, function(i, path) {
  3599. if (path) {
  3600. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3601. }
  3602. });
  3603. if (cssData) {
  3604. arr.push('<style>' + cssData + '</style>');
  3605. }
  3606. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3607. return arr.join('\n');
  3608. }
  3609. function _elementVal(knode, val) {
  3610. if (knode.hasVal()) {
  3611. if (val === undefined) {
  3612. var html = knode.val();
  3613. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3614. return html;
  3615. }
  3616. return knode.val(val);
  3617. }
  3618. return knode.html(val);
  3619. }
  3620. function KEdit(options) {
  3621. this.init(options);
  3622. }
  3623. _extend(KEdit, KWidget, {
  3624. init : function(options) {
  3625. var self = this;
  3626. KEdit.parent.init.call(self, options);
  3627. self.srcElement = K(options.srcElement);
  3628. self.div.addClass('ke-edit');
  3629. self.designMode = _undef(options.designMode, true);
  3630. self.beforeGetHtml = options.beforeGetHtml;
  3631. self.beforeSetHtml = options.beforeSetHtml;
  3632. self.afterSetHtml = options.afterSetHtml;
  3633. var themesPath = _undef(options.themesPath, ''),
  3634. bodyClass = options.bodyClass,
  3635. cssPath = options.cssPath,
  3636. cssData = options.cssData,
  3637. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3638. srcScript = ('document.open();' +
  3639. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3640. 'document.close();'),
  3641. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3642. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3643. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3644. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3645. self.iframe.attr('tabindex', self.tabIndex);
  3646. self.textarea.attr('tabindex', self.tabIndex);
  3647. if (self.width) {
  3648. self.setWidth(self.width);
  3649. }
  3650. if (self.height) {
  3651. self.setHeight(self.height);
  3652. }
  3653. if (self.designMode) {
  3654. self.textarea.hide();
  3655. } else {
  3656. self.iframe.hide();
  3657. }
  3658. function ready() {
  3659. var doc = _iframeDoc(self.iframe);
  3660. doc.open();
  3661. if (isDocumentDomain) {
  3662. doc.domain = document.domain;
  3663. }
  3664. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3665. doc.close();
  3666. self.win = self.iframe[0].contentWindow;
  3667. self.doc = doc;
  3668. var cmd = _cmd(doc);
  3669. self.afterChange(function(e) {
  3670. cmd.selection();
  3671. });
  3672. if (_WEBKIT) {
  3673. K(doc).click(function(e) {
  3674. if (K(e.target).name === 'img') {
  3675. cmd.selection(true);
  3676. cmd.range.selectNode(e.target);
  3677. cmd.select();
  3678. }
  3679. });
  3680. }
  3681. if (_IE) {
  3682. self._mousedownHandler = function() {
  3683. var newRange = cmd.range.cloneRange();
  3684. newRange.shrink();
  3685. if (newRange.isControl()) {
  3686. self.blur();
  3687. }
  3688. };
  3689. K(document).mousedown(self._mousedownHandler);
  3690. K(doc).keydown(function(e) {
  3691. if (e.which == 8) {
  3692. cmd.selection();
  3693. var rng = cmd.range;
  3694. if (rng.isControl()) {
  3695. rng.collapse(true);
  3696. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3697. e.preventDefault();
  3698. }
  3699. }
  3700. });
  3701. }
  3702. self.cmd = cmd;
  3703. self.html(_elementVal(self.srcElement));
  3704. if (_IE) {
  3705. doc.body.disabled = true;
  3706. doc.body.contentEditable = true;
  3707. doc.body.removeAttribute('disabled');
  3708. } else {
  3709. doc.designMode = 'on';
  3710. }
  3711. if (options.afterCreate) {
  3712. options.afterCreate.call(self);
  3713. }
  3714. }
  3715. if (isDocumentDomain) {
  3716. self.iframe.bind('load', function(e) {
  3717. self.iframe.unbind('load');
  3718. if (_IE) {
  3719. ready();
  3720. } else {
  3721. setTimeout(ready, 0);
  3722. }
  3723. });
  3724. }
  3725. self.div.append(self.iframe);
  3726. self.div.append(self.textarea);
  3727. self.srcElement.hide();
  3728. !isDocumentDomain && ready();
  3729. },
  3730. setWidth : function(val) {
  3731. var self = this;
  3732. val = _addUnit(val);
  3733. self.width = val;
  3734. self.div.css('width', val);
  3735. return self;
  3736. },
  3737. setHeight : function(val) {
  3738. var self = this;
  3739. val = _addUnit(val);
  3740. self.height = val;
  3741. self.div.css('height', val);
  3742. self.iframe.css('height', val);
  3743. if ((_IE && _V < 8) || _QUIRKS) {
  3744. val = _addUnit(_removeUnit(val) - 2);
  3745. }
  3746. self.textarea.css('height', val);
  3747. return self;
  3748. },
  3749. remove : function() {
  3750. var self = this, doc = self.doc;
  3751. K(doc.body).unbind();
  3752. K(doc).unbind();
  3753. K(self.win).unbind();
  3754. if (self._mousedownHandler) {
  3755. K(document).unbind('mousedown', self._mousedownHandler);
  3756. }
  3757. _elementVal(self.srcElement, self.html());
  3758. self.srcElement.show();
  3759. self.iframe.unbind();
  3760. self.textarea.unbind();
  3761. KEdit.parent.remove.call(self);
  3762. },
  3763. html : function(val, isFull) {
  3764. var self = this, doc = self.doc;
  3765. if (self.designMode) {
  3766. var body = doc.body;
  3767. if (val === undefined) {
  3768. if (isFull) {
  3769. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3770. } else {
  3771. val = body.innerHTML;
  3772. }
  3773. if (self.beforeGetHtml) {
  3774. val = self.beforeGetHtml(val);
  3775. }
  3776. if (_GECKO && val == '<br />') {
  3777. val = '';
  3778. }
  3779. return val;
  3780. }
  3781. if (self.beforeSetHtml) {
  3782. val = self.beforeSetHtml(val);
  3783. }
  3784. if (_IE && _V >= 9) {
  3785. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3786. }
  3787. K(body).html(val);
  3788. if (self.afterSetHtml) {
  3789. self.afterSetHtml();
  3790. }
  3791. return self;
  3792. }
  3793. if (val === undefined) {
  3794. return self.textarea.val();
  3795. }
  3796. self.textarea.val(val);
  3797. return self;
  3798. },
  3799. design : function(bool) {
  3800. var self = this, val;
  3801. if (bool === undefined ? !self.designMode : bool) {
  3802. if (!self.designMode) {
  3803. val = self.html();
  3804. self.designMode = true;
  3805. self.textarea.hide();
  3806. self.html(val);
  3807. var iframe = self.iframe;
  3808. var height = _removeUnit(self.height);
  3809. iframe.height(height - 2);
  3810. iframe.show();
  3811. setTimeout(function() {
  3812. iframe.height(height);
  3813. }, 0);
  3814. }
  3815. } else {
  3816. if (self.designMode) {
  3817. val = self.html();
  3818. self.designMode = false;
  3819. self.html(val);
  3820. self.iframe.hide();
  3821. self.textarea.show();
  3822. }
  3823. }
  3824. return self.focus();
  3825. },
  3826. focus : function() {
  3827. var self = this;
  3828. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3829. return self;
  3830. },
  3831. blur : function() {
  3832. var self = this;
  3833. if (_IE) {
  3834. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3835. self.div.append(input);
  3836. input[0].focus();
  3837. input.remove();
  3838. } else {
  3839. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3840. }
  3841. return self;
  3842. },
  3843. afterChange : function(fn) {
  3844. var self = this, doc = self.doc, body = doc.body;
  3845. K(doc).keyup(function(e) {
  3846. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3847. fn(e);
  3848. }
  3849. });
  3850. K(doc).mouseup(fn).contextmenu(fn);
  3851. K(self.win).blur(fn);
  3852. function timeoutHandler(e) {
  3853. setTimeout(function() {
  3854. fn(e);
  3855. }, 1);
  3856. }
  3857. K(body).bind('paste', timeoutHandler);
  3858. K(body).bind('cut', timeoutHandler);
  3859. return self;
  3860. }
  3861. });
  3862. function _edit(options) {
  3863. return new KEdit(options);
  3864. }
  3865. K.EditClass = KEdit;
  3866. K.edit = _edit;
  3867. K.iframeDoc = _iframeDoc;
  3868. function _selectToolbar(name, fn) {
  3869. var self = this,
  3870. knode = self.get(name);
  3871. if (knode) {
  3872. if (knode.hasClass('ke-disabled')) {
  3873. return;
  3874. }
  3875. fn(knode);
  3876. }
  3877. }
  3878. function KToolbar(options) {
  3879. this.init(options);
  3880. }
  3881. _extend(KToolbar, KWidget, {
  3882. init : function(options) {
  3883. var self = this;
  3884. KToolbar.parent.init.call(self, options);
  3885. self.disableMode = _undef(options.disableMode, false);
  3886. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3887. self._itemMap = {};
  3888. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3889. e.preventDefault();
  3890. }).attr('unselectable', 'on');
  3891. function find(target) {
  3892. var knode = K(target);
  3893. if (knode.hasClass('ke-outline')) {
  3894. return knode;
  3895. }
  3896. if (knode.hasClass('ke-toolbar-icon')) {
  3897. return knode.parent();
  3898. }
  3899. }
  3900. function hover(e, method) {
  3901. var knode = find(e.target);
  3902. if (knode) {
  3903. if (knode.hasClass('ke-disabled')) {
  3904. return;
  3905. }
  3906. if (knode.hasClass('ke-selected')) {
  3907. return;
  3908. }
  3909. knode[method]('ke-on');
  3910. }
  3911. }
  3912. self.div.mouseover(function(e) {
  3913. hover(e, 'addClass');
  3914. })
  3915. .mouseout(function(e) {
  3916. hover(e, 'removeClass');
  3917. })
  3918. .click(function(e) {
  3919. var knode = find(e.target);
  3920. if (knode) {
  3921. if (knode.hasClass('ke-disabled')) {
  3922. return;
  3923. }
  3924. self.options.click.call(this, e, knode.attr('data-name'));
  3925. }
  3926. });
  3927. },
  3928. get : function(name) {
  3929. if (this._itemMap[name]) {
  3930. return this._itemMap[name];
  3931. }
  3932. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3933. },
  3934. select : function(name) {
  3935. _selectToolbar.call(this, name, function(knode) {
  3936. knode.addClass('ke-selected');
  3937. });
  3938. return self;
  3939. },
  3940. unselect : function(name) {
  3941. _selectToolbar.call(this, name, function(knode) {
  3942. knode.removeClass('ke-selected').removeClass('ke-on');
  3943. });
  3944. return self;
  3945. },
  3946. enable : function(name) {
  3947. var self = this,
  3948. knode = name.get ? name : self.get(name);
  3949. if (knode) {
  3950. knode.removeClass('ke-disabled');
  3951. knode.opacity(1);
  3952. }
  3953. return self;
  3954. },
  3955. disable : function(name) {
  3956. var self = this,
  3957. knode = name.get ? name : self.get(name);
  3958. if (knode) {
  3959. knode.removeClass('ke-selected').addClass('ke-disabled');
  3960. knode.opacity(0.5);
  3961. }
  3962. return self;
  3963. },
  3964. disableAll : function(bool, noDisableItems) {
  3965. var self = this, map = self.noDisableItemMap, item;
  3966. if (noDisableItems) {
  3967. map = _toMap(noDisableItems);
  3968. }
  3969. if (bool === undefined ? !self.disableMode : bool) {
  3970. K('span.ke-outline', self.div).each(function() {
  3971. var knode = K(this),
  3972. name = knode[0].getAttribute('data-name', 2);
  3973. if (!map[name]) {
  3974. self.disable(knode);
  3975. }
  3976. });
  3977. self.disableMode = true;
  3978. } else {
  3979. K('span.ke-outline', self.div).each(function() {
  3980. var knode = K(this),
  3981. name = knode[0].getAttribute('data-name', 2);
  3982. if (!map[name]) {
  3983. self.enable(knode);
  3984. }
  3985. });
  3986. self.disableMode = false;
  3987. }
  3988. return self;
  3989. }
  3990. });
  3991. function _toolbar(options) {
  3992. return new KToolbar(options);
  3993. }
  3994. K.ToolbarClass = KToolbar;
  3995. K.toolbar = _toolbar;
  3996. function KMenu(options) {
  3997. this.init(options);
  3998. }
  3999. _extend(KMenu, KWidget, {
  4000. init : function(options) {
  4001. var self = this;
  4002. options.z = options.z || 811213;
  4003. KMenu.parent.init.call(self, options);
  4004. self.centerLineMode = _undef(options.centerLineMode, true);
  4005. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4006. e.stopPropagation();
  4007. }).attr('unselectable', 'on');
  4008. },
  4009. addItem : function(item) {
  4010. var self = this;
  4011. if (item.title === '-') {
  4012. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4013. return;
  4014. }
  4015. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4016. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4017. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4018. height = _addUnit(item.height),
  4019. iconClass = _undef(item.iconClass, '');
  4020. self.div.append(itemDiv);
  4021. if (height) {
  4022. itemDiv.css('height', height);
  4023. rightDiv.css('line-height', height);
  4024. }
  4025. var centerDiv;
  4026. if (self.centerLineMode) {
  4027. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4028. if (height) {
  4029. centerDiv.css('height', height);
  4030. }
  4031. }
  4032. itemDiv.mouseover(function(e) {
  4033. K(this).addClass('ke-menu-item-on');
  4034. if (centerDiv) {
  4035. centerDiv.addClass('ke-menu-item-center-on');
  4036. }
  4037. })
  4038. .mouseout(function(e) {
  4039. K(this).removeClass('ke-menu-item-on');
  4040. if (centerDiv) {
  4041. centerDiv.removeClass('ke-menu-item-center-on');
  4042. }
  4043. })
  4044. .click(function(e) {
  4045. item.click.call(K(this));
  4046. e.stopPropagation();
  4047. })
  4048. .append(leftDiv);
  4049. if (centerDiv) {
  4050. itemDiv.append(centerDiv);
  4051. }
  4052. itemDiv.append(rightDiv);
  4053. if (item.checked) {
  4054. iconClass = 'ke-icon-checked';
  4055. }
  4056. if (iconClass !== '') {
  4057. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4058. }
  4059. rightDiv.html(item.title);
  4060. return self;
  4061. },
  4062. remove : function() {
  4063. var self = this;
  4064. if (self.options.beforeRemove) {
  4065. self.options.beforeRemove.call(self);
  4066. }
  4067. K('.ke-menu-item', self.div[0]).unbind();
  4068. KMenu.parent.remove.call(self);
  4069. return self;
  4070. }
  4071. });
  4072. function _menu(options) {
  4073. return new KMenu(options);
  4074. }
  4075. K.MenuClass = KMenu;
  4076. K.menu = _menu;
  4077. function KColorPicker(options) {
  4078. this.init(options);
  4079. }
  4080. _extend(KColorPicker, KWidget, {
  4081. init : function(options) {
  4082. var self = this;
  4083. options.z = options.z || 811213;
  4084. KColorPicker.parent.init.call(self, options);
  4085. var colors = options.colors || [
  4086. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4087. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4088. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4089. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4090. ];
  4091. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4092. self._cells = [];
  4093. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4094. e.stopPropagation();
  4095. }).attr('unselectable', 'on');
  4096. var table = self.doc.createElement('table');
  4097. self.div.append(table);
  4098. table.className = 'ke-colorpicker-table';
  4099. table.cellPadding = 0;
  4100. table.cellSpacing = 0;
  4101. table.border = 0;
  4102. var row = table.insertRow(0), cell = row.insertCell(0);
  4103. cell.colSpan = colors[0].length;
  4104. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4105. for (var i = 0; i < colors.length; i++) {
  4106. row = table.insertRow(i + 1);
  4107. for (var j = 0; j < colors[i].length; j++) {
  4108. cell = row.insertCell(j);
  4109. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4110. }
  4111. }
  4112. },
  4113. _addAttr : function(cell, color, cls) {
  4114. var self = this;
  4115. cell = K(cell).addClass(cls);
  4116. if (self.selectedColor === color.toLowerCase()) {
  4117. cell.addClass('ke-colorpicker-cell-selected');
  4118. }
  4119. cell.attr('title', color || self.options.noColor);
  4120. cell.mouseover(function(e) {
  4121. K(this).addClass('ke-colorpicker-cell-on');
  4122. });
  4123. cell.mouseout(function(e) {
  4124. K(this).removeClass('ke-colorpicker-cell-on');
  4125. });
  4126. cell.click(function(e) {
  4127. e.stop();
  4128. self.options.click.call(K(this), color);
  4129. });
  4130. if (color) {
  4131. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4132. } else {
  4133. cell.html(self.options.noColor);
  4134. }
  4135. K(cell).attr('unselectable', 'on');
  4136. self._cells.push(cell);
  4137. },
  4138. remove : function() {
  4139. var self = this;
  4140. _each(self._cells, function() {
  4141. this.unbind();
  4142. });
  4143. KColorPicker.parent.remove.call(self);
  4144. return self;
  4145. }
  4146. });
  4147. function _colorpicker(options) {
  4148. return new KColorPicker(options);
  4149. }
  4150. K.ColorPickerClass = KColorPicker;
  4151. K.colorpicker = _colorpicker;
  4152. function KUploadButton(options) {
  4153. this.init(options);
  4154. }
  4155. _extend(KUploadButton, {
  4156. init : function(options) {
  4157. var self = this,
  4158. button = K(options.button),
  4159. fieldName = options.fieldName || 'file',
  4160. url = options.url || '',
  4161. title = button.val(),
  4162. extraParams = options.extraParams || {},
  4163. cls = button[0].className || '',
  4164. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4165. options.afterError = options.afterError || function(str) {
  4166. alert(str);
  4167. };
  4168. var hiddenElements = [];
  4169. for(var k in extraParams){
  4170. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4171. }
  4172. var html = [
  4173. '<div class="ke-inline-block ' + cls + '">',
  4174. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4175. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4176. '<span class="ke-button-common">',
  4177. hiddenElements.join(''),
  4178. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4179. '</span>',
  4180. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4181. (options.form ? '</div>' : '</form>'),
  4182. '</div>'].join('');
  4183. var div = K(html, button.doc);
  4184. button.hide();
  4185. button.before(div);
  4186. self.div = div;
  4187. self.button = button;
  4188. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4189. self.form = options.form ? K(options.form) : K('form', div);
  4190. self.fileBox = K('.ke-upload-file', div);
  4191. var width = options.width || K('.ke-button-common', div).width();
  4192. K('.ke-upload-area', div).width(width);
  4193. self.options = options;
  4194. },
  4195. submit : function() {
  4196. var self = this,
  4197. iframe = self.iframe;
  4198. iframe.bind('load', function() {
  4199. iframe.unbind();
  4200. var tempForm = document.createElement('form');
  4201. self.fileBox.before(tempForm);
  4202. K(tempForm).append(self.fileBox);
  4203. tempForm.reset();
  4204. K(tempForm).remove(true);
  4205. var doc = K.iframeDoc(iframe),
  4206. pre = doc.getElementsByTagName('pre')[0],
  4207. str = '', data;
  4208. if (pre) {
  4209. str = pre.innerHTML;
  4210. } else {
  4211. str = doc.body.innerHTML;
  4212. }
  4213. str = _unescape(str);
  4214. iframe[0].src = 'javascript:false';
  4215. try {
  4216. data = K.json(str);
  4217. } catch (e) {
  4218. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4219. }
  4220. if (data) {
  4221. self.options.afterUpload.call(self, data);
  4222. }
  4223. });
  4224. self.form[0].submit();
  4225. return self;
  4226. },
  4227. remove : function() {
  4228. var self = this;
  4229. if (self.fileBox) {
  4230. self.fileBox.unbind();
  4231. }
  4232. self.iframe.remove();
  4233. self.div.remove();
  4234. self.button.show();
  4235. return self;
  4236. }
  4237. });
  4238. function _uploadbutton(options) {
  4239. return new KUploadButton(options);
  4240. }
  4241. K.UploadButtonClass = KUploadButton;
  4242. K.uploadbutton = _uploadbutton;
  4243. function _createButton(arg) {
  4244. arg = arg || {};
  4245. var name = arg.name || '',
  4246. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4247. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4248. if (arg.click) {
  4249. btn.click(arg.click);
  4250. }
  4251. span.append(btn);
  4252. return span;
  4253. }
  4254. function KDialog(options) {
  4255. this.init(options);
  4256. }
  4257. _extend(KDialog, KWidget, {
  4258. init : function(options) {
  4259. var self = this;
  4260. var shadowMode = _undef(options.shadowMode, true);
  4261. options.z = options.z || 811213;
  4262. options.shadowMode = false;
  4263. options.autoScroll = _undef(options.autoScroll, true);
  4264. KDialog.parent.init.call(self, options);
  4265. var title = options.title,
  4266. body = K(options.body, self.doc),
  4267. previewBtn = options.previewBtn,
  4268. yesBtn = options.yesBtn,
  4269. noBtn = options.noBtn,
  4270. closeBtn = options.closeBtn,
  4271. showMask = _undef(options.showMask, true);
  4272. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4273. e.stopPropagation();
  4274. });
  4275. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4276. if (_IE && _V < 7) {
  4277. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4278. } else if (shadowMode) {
  4279. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4280. }
  4281. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4282. contentDiv.append(headerDiv);
  4283. headerDiv.html(title);
  4284. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4285. headerDiv.append(self.closeIcon);
  4286. self.draggable({
  4287. clickEl : headerDiv,
  4288. beforeDrag : options.beforeDrag
  4289. });
  4290. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4291. contentDiv.append(bodyDiv);
  4292. bodyDiv.append(body);
  4293. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4294. if (previewBtn || yesBtn || noBtn) {
  4295. contentDiv.append(footerDiv);
  4296. }
  4297. _each([
  4298. { btn : previewBtn, name : 'preview' },
  4299. { btn : yesBtn, name : 'yes' },
  4300. { btn : noBtn, name : 'no' }
  4301. ], function() {
  4302. if (this.btn) {
  4303. var button = _createButton(this.btn);
  4304. button.addClass('ke-dialog-' + this.name);
  4305. footerDiv.append(button);
  4306. }
  4307. });
  4308. if (self.height) {
  4309. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4310. }
  4311. self.div.width(self.div.width());
  4312. self.div.height(self.div.height());
  4313. self.mask = null;
  4314. if (showMask) {
  4315. var docEl = _docElement(self.doc),
  4316. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4317. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4318. self.mask = _widget({
  4319. x : 0,
  4320. y : 0,
  4321. z : self.z - 1,
  4322. cls : 'ke-dialog-mask',
  4323. width : docWidth,
  4324. height : docHeight
  4325. });
  4326. }
  4327. self.autoPos(self.div.width(), self.div.height());
  4328. self.footerDiv = footerDiv;
  4329. self.bodyDiv = bodyDiv;
  4330. self.headerDiv = headerDiv;
  4331. self.isLoading = false;
  4332. },
  4333. setMaskIndex : function(z) {
  4334. var self = this;
  4335. self.mask.div.css('z-index', z);
  4336. },
  4337. showLoading : function(msg) {
  4338. msg = _undef(msg, '');
  4339. var self = this, body = self.bodyDiv;
  4340. self.loading = K('<div class="ke-dialog-loading"><div class="ke-inline-block ke-dialog-loading-content" style="margin-top:' + Math.round(body.height() / 3) + 'px;">' + msg + '</div></div>')
  4341. .width(body.width()).height(body.height())
  4342. .css('top', self.headerDiv.height() + 'px');
  4343. body.css('visibility', 'hidden').after(self.loading);
  4344. self.isLoading = true;
  4345. return self;
  4346. },
  4347. hideLoading : function() {
  4348. this.loading && this.loading.remove();
  4349. this.bodyDiv.css('visibility', 'visible');
  4350. this.isLoading = false;
  4351. return this;
  4352. },
  4353. remove : function() {
  4354. var self = this;
  4355. if (self.options.beforeRemove) {
  4356. self.options.beforeRemove.call(self);
  4357. }
  4358. self.mask && self.mask.remove();
  4359. self.iframeMask && self.iframeMask.remove();
  4360. self.closeIcon.unbind();
  4361. K('input', self.div).unbind();
  4362. K('button', self.div).unbind();
  4363. self.footerDiv.unbind();
  4364. self.bodyDiv.unbind();
  4365. self.headerDiv.unbind();
  4366. K('iframe', self.div).each(function() {
  4367. K(this).remove();
  4368. });
  4369. KDialog.parent.remove.call(self);
  4370. return self;
  4371. }
  4372. });
  4373. function _dialog(options) {
  4374. return new KDialog(options);
  4375. }
  4376. K.DialogClass = KDialog;
  4377. K.dialog = _dialog;
  4378. function _tabs(options) {
  4379. var self = _widget(options),
  4380. remove = self.remove,
  4381. afterSelect = options.afterSelect,
  4382. div = self.div,
  4383. liList = [];
  4384. div.addClass('ke-tabs')
  4385. .bind('contextmenu,mousedown,mousemove', function(e) {
  4386. e.preventDefault();
  4387. });
  4388. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4389. div.append(ul);
  4390. self.add = function(tab) {
  4391. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4392. li.data('tab', tab);
  4393. liList.push(li);
  4394. ul.append(li);
  4395. };
  4396. self.selectedIndex = 0;
  4397. self.select = function(index) {
  4398. self.selectedIndex = index;
  4399. _each(liList, function(i, li) {
  4400. li.unbind();
  4401. if (i === index) {
  4402. li.addClass('ke-tabs-li-selected');
  4403. K(li.data('tab').panel).show('');
  4404. } else {
  4405. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4406. .mouseover(function() {
  4407. K(this).addClass('ke-tabs-li-on');
  4408. })
  4409. .mouseout(function() {
  4410. K(this).removeClass('ke-tabs-li-on');
  4411. })
  4412. .click(function() {
  4413. self.select(i);
  4414. });
  4415. K(li.data('tab').panel).hide();
  4416. }
  4417. });
  4418. if (afterSelect) {
  4419. afterSelect.call(self, index);
  4420. }
  4421. };
  4422. self.remove = function() {
  4423. _each(liList, function() {
  4424. this.remove();
  4425. });
  4426. ul.remove();
  4427. remove.call(self);
  4428. };
  4429. return self;
  4430. }
  4431. K.tabs = _tabs;
  4432. function _loadScript(url, fn) {
  4433. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4434. script = document.createElement('script');
  4435. head.appendChild(script);
  4436. script.src = url;
  4437. script.charset = 'utf-8';
  4438. script.onload = script.onreadystatechange = function() {
  4439. if (!this.readyState || this.readyState === 'loaded') {
  4440. if (fn) {
  4441. fn();
  4442. }
  4443. script.onload = script.onreadystatechange = null;
  4444. head.removeChild(script);
  4445. }
  4446. };
  4447. }
  4448. function _chopQuery(url) {
  4449. var index = url.indexOf('?');
  4450. return index > 0 ? url.substr(0, index) : url;
  4451. }
  4452. function _loadStyle(url) {
  4453. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4454. link = document.createElement('link'),
  4455. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4456. var links = K('link[rel="stylesheet"]', head);
  4457. for (var i = 0, len = links.length; i < len; i++) {
  4458. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4459. return;
  4460. }
  4461. }
  4462. head.appendChild(link);
  4463. link.href = url;
  4464. link.rel = 'stylesheet';
  4465. }
  4466. function _ajax(url, fn, method, param, dataType) {
  4467. method = method || 'GET';
  4468. dataType = dataType || 'json';
  4469. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4470. xhr.open(method, url, true);
  4471. xhr.onreadystatechange = function () {
  4472. if (xhr.readyState == 4 && xhr.status == 200) {
  4473. if (fn) {
  4474. var data = _trim(xhr.responseText);
  4475. if (dataType == 'json') {
  4476. data = _json(data);
  4477. }
  4478. fn(data);
  4479. }
  4480. }
  4481. };
  4482. if (method == 'POST') {
  4483. var params = [];
  4484. _each(param, function(key, val) {
  4485. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4486. });
  4487. try {
  4488. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4489. } catch (e) {}
  4490. xhr.send(params.join('&'));
  4491. } else {
  4492. xhr.send(null);
  4493. }
  4494. }
  4495. K.loadScript = _loadScript;
  4496. K.loadStyle = _loadStyle;
  4497. K.ajax = _ajax;
  4498. var _plugins = {};
  4499. function _plugin(name, fn) {
  4500. if (name === undefined) {
  4501. return _plugins;
  4502. }
  4503. if (!fn) {
  4504. return _plugins[name];
  4505. }
  4506. _plugins[name] = fn;
  4507. }
  4508. var _language = {};
  4509. function _parseLangKey(key) {
  4510. var match, ns = 'core';
  4511. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4512. ns = match[1];
  4513. key = match[2];
  4514. }
  4515. return { ns : ns, key : key };
  4516. }
  4517. function _lang(mixed, langType) {
  4518. langType = langType === undefined ? K.options.langType : langType;
  4519. if (typeof mixed === 'string') {
  4520. if (!_language[langType]) {
  4521. return 'no language';
  4522. }
  4523. var pos = mixed.length - 1;
  4524. if (mixed.substr(pos) === '.') {
  4525. return _language[langType][mixed.substr(0, pos)];
  4526. }
  4527. var obj = _parseLangKey(mixed);
  4528. return _language[langType][obj.ns][obj.key];
  4529. }
  4530. _each(mixed, function(key, val) {
  4531. var obj = _parseLangKey(key);
  4532. if (!_language[langType]) {
  4533. _language[langType] = {};
  4534. }
  4535. if (!_language[langType][obj.ns]) {
  4536. _language[langType][obj.ns] = {};
  4537. }
  4538. _language[langType][obj.ns][obj.key] = val;
  4539. });
  4540. }
  4541. function _getImageFromRange(range, fn) {
  4542. if (range.collapsed) {
  4543. return;
  4544. }
  4545. range = range.cloneRange().up();
  4546. var sc = range.startContainer, so = range.startOffset;
  4547. if (!_WEBKIT && !range.isControl()) {
  4548. return;
  4549. }
  4550. var img = K(sc.childNodes[so]);
  4551. if (!img || img.name != 'img') {
  4552. return;
  4553. }
  4554. if (fn(img)) {
  4555. return img;
  4556. }
  4557. }
  4558. function _bindContextmenuEvent() {
  4559. var self = this, doc = self.edit.doc;
  4560. K(doc).contextmenu(function(e) {
  4561. if (self.menu) {
  4562. self.hideMenu();
  4563. }
  4564. if (!self.useContextmenu) {
  4565. e.preventDefault();
  4566. return;
  4567. }
  4568. if (self._contextmenus.length === 0) {
  4569. return;
  4570. }
  4571. var maxWidth = 0, items = [];
  4572. _each(self._contextmenus, function() {
  4573. if (this.title == '-') {
  4574. items.push(this);
  4575. return;
  4576. }
  4577. if (this.cond && this.cond()) {
  4578. items.push(this);
  4579. if (this.width && this.width > maxWidth) {
  4580. maxWidth = this.width;
  4581. }
  4582. }
  4583. });
  4584. while (items.length > 0 && items[0].title == '-') {
  4585. items.shift();
  4586. }
  4587. while (items.length > 0 && items[items.length - 1].title == '-') {
  4588. items.pop();
  4589. }
  4590. var prevItem = null;
  4591. _each(items, function(i) {
  4592. if (this.title == '-' && prevItem.title == '-') {
  4593. delete items[i];
  4594. }
  4595. prevItem = this;
  4596. });
  4597. if (items.length > 0) {
  4598. e.preventDefault();
  4599. var pos = K(self.edit.iframe).pos(),
  4600. menu = _menu({
  4601. x : pos.x + e.clientX,
  4602. y : pos.y + e.clientY,
  4603. width : maxWidth,
  4604. css : { visibility: 'hidden' },
  4605. shadowMode : self.shadowMode
  4606. });
  4607. _each(items, function() {
  4608. if (this.title) {
  4609. menu.addItem(this);
  4610. }
  4611. });
  4612. var docEl = _docElement(menu.doc),
  4613. menuHeight = menu.div.height();
  4614. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4615. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4616. }
  4617. menu.div.css('visibility', 'visible');
  4618. self.menu = menu;
  4619. }
  4620. });
  4621. }
  4622. function _bindNewlineEvent() {
  4623. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4624. if (_IE && newlineTag !== 'br') {
  4625. return;
  4626. }
  4627. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4628. return;
  4629. }
  4630. if (_OPERA && _V < 9) {
  4631. return;
  4632. }
  4633. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4634. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4635. function getAncestorTagName(range) {
  4636. var ancestor = K(range.commonAncestor());
  4637. while (ancestor) {
  4638. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4639. break;
  4640. }
  4641. ancestor = ancestor.parent();
  4642. }
  4643. return ancestor.name;
  4644. }
  4645. K(doc).keydown(function(e) {
  4646. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4647. autoImg(self);
  4648. return;
  4649. }
  4650. self.cmd.selection();
  4651. var tagName = getAncestorTagName(self.cmd.range);
  4652. if (tagName == 'marquee' || tagName == 'select') {
  4653. return;
  4654. }
  4655. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4656. e.preventDefault();
  4657. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4658. return;
  4659. }
  4660. if (!pSkipTagMap[tagName]) {
  4661. _nativeCommand(doc, 'formatblock', '<p>');
  4662. }
  4663. });
  4664. K(doc).keyup(function(e) {
  4665. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4666. return;
  4667. }
  4668. if (newlineTag == 'br') {
  4669. return;
  4670. }
  4671. if (_GECKO) {
  4672. var root = self.cmd.commonAncestor('p');
  4673. var a = self.cmd.commonAncestor('a');
  4674. if (a && a.text() == '') {
  4675. a.remove(true);
  4676. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4677. self.cmd.select();
  4678. }
  4679. return;
  4680. }
  4681. self.cmd.selection();
  4682. var tagName = getAncestorTagName(self.cmd.range);
  4683. if (tagName == 'marquee' || tagName == 'select') {
  4684. return;
  4685. }
  4686. if (!pSkipTagMap[tagName]) {
  4687. _nativeCommand(doc, 'formatblock', '<p>');
  4688. }
  4689. var div = self.cmd.commonAncestor('div');
  4690. if (div) {
  4691. var p = K('<p></p>'),
  4692. child = div[0].firstChild;
  4693. while (child) {
  4694. var next = child.nextSibling;
  4695. p.append(child);
  4696. child = next;
  4697. }
  4698. div.before(p);
  4699. div.remove();
  4700. self.cmd.range.selectNodeContents(p[0]);
  4701. self.cmd.select();
  4702. }
  4703. });
  4704. }
  4705. function _bindTabEvent() {
  4706. var self = this, doc = self.edit.doc;
  4707. K(doc).keydown(function(e) {
  4708. if (e.which == 9) {
  4709. e.preventDefault();
  4710. if (self.afterTab) {
  4711. self.afterTab.call(self, e);
  4712. return;
  4713. }
  4714. var cmd = self.cmd, range = cmd.range;
  4715. range.shrink();
  4716. if (range.collapsed && range.startContainer.nodeType == 1) {
  4717. range.insertNode(K('@&nbsp;', doc)[0]);
  4718. cmd.select();
  4719. }
  4720. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4721. }
  4722. });
  4723. }
  4724. function _bindFocusEvent() {
  4725. var self = this;
  4726. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4727. if (self.afterFocus) {
  4728. self.afterFocus.call(self, e);
  4729. }
  4730. }).blur(function(e) {
  4731. if (self.afterBlur) {
  4732. self.afterBlur.call(self, e);
  4733. }
  4734. });
  4735. }
  4736. function _removeBookmarkTag(html) {
  4737. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4738. }
  4739. function _removeTempTag(html) {
  4740. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4741. }
  4742. function _addBookmarkToStack(stack, bookmark) {
  4743. if (stack.length === 0) {
  4744. stack.push(bookmark);
  4745. return;
  4746. }
  4747. var prev = stack[stack.length - 1];
  4748. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4749. stack.push(bookmark);
  4750. }
  4751. }
  4752. function _undoToRedo(fromStack, toStack) {
  4753. var self = this, edit = self.edit,
  4754. body = edit.doc.body,
  4755. range, bookmark;
  4756. if (fromStack.length === 0) {
  4757. return self;
  4758. }
  4759. if (edit.designMode) {
  4760. range = self.cmd.range;
  4761. bookmark = range.createBookmark(true);
  4762. bookmark.html = body.innerHTML;
  4763. } else {
  4764. bookmark = {
  4765. html : body.innerHTML
  4766. };
  4767. }
  4768. _addBookmarkToStack(toStack, bookmark);
  4769. var prev = fromStack.pop();
  4770. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4771. prev = fromStack.pop();
  4772. }
  4773. if (edit.designMode) {
  4774. edit.html(prev.html);
  4775. if (prev.start) {
  4776. range.moveToBookmark(prev);
  4777. self.select();
  4778. }
  4779. } else {
  4780. K(body).html(_removeBookmarkTag(prev.html));
  4781. }
  4782. return self;
  4783. }
  4784. function KEditor(options) {
  4785. var self = this;
  4786. self.options = {};
  4787. function setOption(key, val) {
  4788. if (KEditor.prototype[key] === undefined) {
  4789. self[key] = val;
  4790. }
  4791. self.options[key] = val;
  4792. }
  4793. _each(options, function(key, val) {
  4794. setOption(key, options[key]);
  4795. });
  4796. _each(K.options, function(key, val) {
  4797. if (self[key] === undefined) {
  4798. setOption(key, val);
  4799. }
  4800. });
  4801. var se = K(self.srcElement || '<textarea/>');
  4802. if (!self.width) {
  4803. self.width = se[0].style.width || se.width();
  4804. }
  4805. if (!self.height) {
  4806. self.height = se[0].style.height || se.height();
  4807. }
  4808. setOption('width', _undef(self.width, self.minWidth));
  4809. setOption('height', _undef(self.height, self.minHeight));
  4810. setOption('width', _addUnit(self.width));
  4811. setOption('height', _addUnit(self.height));
  4812. if (_MOBILE && (!_IOS || _V < 534)) {
  4813. //self.designMode = false;
  4814. }
  4815. self.srcElement = se;
  4816. self.initContent = '';
  4817. self.plugin = {};
  4818. self.isCreated = false;
  4819. self._handlers = {};
  4820. self._contextmenus = [];
  4821. self._undoStack = [];
  4822. self._redoStack = [];
  4823. self._firstAddBookmark = true;
  4824. self.menu = self.contextmenu = null;
  4825. self.dialogs = [];
  4826. }
  4827. KEditor.prototype = {
  4828. lang : function(mixed) {
  4829. return _lang(mixed, this.langType);
  4830. },
  4831. loadPlugin : function(name, fn) {
  4832. var self = this;
  4833. var _pluginStatus = this._pluginStatus;
  4834. if (!_pluginStatus) {
  4835. _pluginStatus = this._pluginStatus = {};
  4836. }
  4837. if (_plugins[name]) {
  4838. if (!_isFunction(_plugins[name])) {
  4839. setTimeout(function() {
  4840. self.loadPlugin(name, fn);
  4841. }, 100);
  4842. return self;
  4843. }
  4844. if(!_pluginStatus[name]) {
  4845. _plugins[name].call(self, KindEditor);
  4846. _pluginStatus[name] = 'inited';
  4847. }
  4848. if (fn) {
  4849. fn.call(self);
  4850. }
  4851. return self;
  4852. }
  4853. _plugins[name] = 'loading';
  4854. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4855. setTimeout(function() {
  4856. if (_plugins[name]) {
  4857. self.loadPlugin(name, fn);
  4858. }
  4859. }, 0);
  4860. });
  4861. return self;
  4862. },
  4863. handler : function(key, fn) {
  4864. var self = this;
  4865. if (!self._handlers[key]) {
  4866. self._handlers[key] = [];
  4867. }
  4868. if (_isFunction(fn)) {
  4869. self._handlers[key].push(fn);
  4870. return self;
  4871. }
  4872. _each(self._handlers[key], function() {
  4873. fn = this.call(self, fn);
  4874. });
  4875. return fn;
  4876. },
  4877. clickToolbar : function(name, fn) {
  4878. var self = this, key = 'clickToolbar' + name;
  4879. if (fn === undefined) {
  4880. if (self._handlers[key]) {
  4881. return self.handler(key);
  4882. }
  4883. self.loadPlugin(name, function() {
  4884. self.handler(key);
  4885. });
  4886. return self;
  4887. }
  4888. return self.handler(key, fn);
  4889. },
  4890. updateState : function() {
  4891. var self = this;
  4892. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4893. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4894. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4895. });
  4896. return self;
  4897. },
  4898. addContextmenu : function(item) {
  4899. this._contextmenus.push(item);
  4900. return this;
  4901. },
  4902. afterCreate : function(fn) {
  4903. return this.handler('afterCreate', fn);
  4904. },
  4905. beforeRemove : function(fn) {
  4906. return this.handler('beforeRemove', fn);
  4907. },
  4908. beforeGetHtml : function(fn) {
  4909. return this.handler('beforeGetHtml', fn);
  4910. },
  4911. beforeSetHtml : function(fn) {
  4912. return this.handler('beforeSetHtml', fn);
  4913. },
  4914. afterSetHtml : function(fn) {
  4915. return this.handler('afterSetHtml', fn);
  4916. },
  4917. create : function() {
  4918. var self = this, fullscreenMode = self.fullscreenMode;
  4919. if (self.isCreated) {
  4920. return self;
  4921. }
  4922. if (self.srcElement.data('kindeditor')) {
  4923. return self;
  4924. }
  4925. self.srcElement.data('kindeditor', 'true');
  4926. if (fullscreenMode) {
  4927. _docElement().style.overflow = 'hidden';
  4928. } else {
  4929. _docElement().style.overflow = '';
  4930. }
  4931. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4932. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4933. if ((_IE && _V < 8) || _QUIRKS) {
  4934. height = _addUnit(_removeUnit(height) + 2);
  4935. }
  4936. var container = self.container = K(self.layout);
  4937. if (fullscreenMode) {
  4938. K(document.body).append(container);
  4939. } else {
  4940. self.srcElement.before(container);
  4941. }
  4942. var toolbarDiv = K('.toolbar', container),
  4943. editDiv = K('.edit', container),
  4944. statusbar = self.statusbar = K('.statusbar', container);
  4945. container.removeClass('container')
  4946. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4947. if (fullscreenMode) {
  4948. container.css({
  4949. position : 'absolute',
  4950. left : 0,
  4951. top : 0,
  4952. 'z-index' : 811211
  4953. });
  4954. if (!_GECKO) {
  4955. self._scrollPos = _getScrollPos();
  4956. }
  4957. window.scrollTo(0, 0);
  4958. K(document.body).css({
  4959. 'height' : '1px',
  4960. 'overflow' : 'hidden'
  4961. });
  4962. K(document.body.parentNode).css('overflow', 'hidden');
  4963. self._fullscreenExecuted = true;
  4964. } else {
  4965. if (self._fullscreenExecuted) {
  4966. K(document.body).css({
  4967. 'height' : '',
  4968. 'overflow' : ''
  4969. });
  4970. K(document.body.parentNode).css('overflow', '');
  4971. }
  4972. if (self._scrollPos) {
  4973. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4974. }
  4975. }
  4976. var htmlList = [];
  4977. K.each(self.items, function(i, name) {
  4978. if (name == '|') {
  4979. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4980. } else if (name == '/') {
  4981. htmlList.push('<div class="ke-hr"></div>');
  4982. } else {
  4983. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4984. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4985. }
  4986. });
  4987. var toolbar = self.toolbar = _toolbar({
  4988. src : toolbarDiv,
  4989. html : htmlList.join(''),
  4990. noDisableItems : self.noDisableItems,
  4991. click : function(e, name) {
  4992. e.stop();
  4993. if (self.menu) {
  4994. var menuName = self.menu.name;
  4995. self.hideMenu();
  4996. if (menuName === name) {
  4997. return;
  4998. }
  4999. }
  5000. self.clickToolbar(name);
  5001. }
  5002. });
  5003. var editHeight = _removeUnit(height) - toolbar.div.height();
  5004. var edit = self.edit = _edit({
  5005. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5006. src : editDiv,
  5007. srcElement : self.srcElement,
  5008. designMode : self.designMode,
  5009. themesPath : self.themesPath,
  5010. bodyClass : self.bodyClass,
  5011. cssPath : self.cssPath,
  5012. cssData : self.cssData,
  5013. beforeGetHtml : function(html) {
  5014. html = self.beforeGetHtml(html);
  5015. html = _removeBookmarkTag(_removeTempTag(html));
  5016. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5017. },
  5018. beforeSetHtml : function(html) {
  5019. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5020. return self.beforeSetHtml(html);
  5021. },
  5022. afterSetHtml : function() {
  5023. self.edit = edit = this;
  5024. self.afterSetHtml();
  5025. },
  5026. afterCreate : function() {
  5027. self.edit = edit = this;
  5028. self.cmd = edit.cmd;
  5029. self._docMousedownFn = function(e) {
  5030. if (self.menu) {
  5031. self.hideMenu();
  5032. }
  5033. };
  5034. K(edit.doc, document).mousedown(self._docMousedownFn);
  5035. _bindContextmenuEvent.call(self);
  5036. _bindNewlineEvent.call(self);
  5037. _bindTabEvent.call(self);
  5038. _bindFocusEvent.call(self);
  5039. edit.afterChange(function(e) {
  5040. if (!edit.designMode) {
  5041. return;
  5042. }
  5043. self.updateState();
  5044. self.addBookmark();
  5045. if (self.options.afterChange) {
  5046. self.options.afterChange.call(self);
  5047. }
  5048. });
  5049. edit.textarea.keyup(function(e) {
  5050. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5051. if (self.options.afterChange) {
  5052. self.options.afterChange.call(self);
  5053. }
  5054. }
  5055. });
  5056. if (self.readonlyMode) {
  5057. self.readonly();
  5058. }
  5059. self.isCreated = true;
  5060. if (self.initContent === '') {
  5061. self.initContent = self.html();
  5062. }
  5063. if (self._undoStack.length > 0) {
  5064. var prev = self._undoStack.pop();
  5065. if (prev.start) {
  5066. self.html(prev.html);
  5067. edit.cmd.range.moveToBookmark(prev);
  5068. self.select();
  5069. }
  5070. }
  5071. self.afterCreate();
  5072. if (self.options.afterCreate) {
  5073. self.options.afterCreate.call(self);
  5074. }
  5075. }
  5076. });
  5077. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5078. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5079. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5080. if (self._fullscreenResizeHandler) {
  5081. K(window).unbind('resize', self._fullscreenResizeHandler);
  5082. self._fullscreenResizeHandler = null;
  5083. }
  5084. function initResize() {
  5085. if (statusbar.height() === 0) {
  5086. setTimeout(initResize, 100);
  5087. return;
  5088. }
  5089. self.resize(width, height, false);
  5090. }
  5091. initResize();
  5092. if (fullscreenMode) {
  5093. self._fullscreenResizeHandler = function(e) {
  5094. if (self.isCreated) {
  5095. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5096. }
  5097. };
  5098. K(window).bind('resize', self._fullscreenResizeHandler);
  5099. toolbar.select('fullscreen');
  5100. statusbar.first().css('visibility', 'hidden');
  5101. statusbar.last().css('visibility', 'hidden');
  5102. } else {
  5103. if (_GECKO) {
  5104. K(window).bind('scroll', function(e) {
  5105. self._scrollPos = _getScrollPos();
  5106. });
  5107. }
  5108. if (self.resizeType > 0) {
  5109. _drag({
  5110. moveEl : container,
  5111. clickEl : statusbar,
  5112. moveFn : function(x, y, width, height, diffX, diffY) {
  5113. height += diffY;
  5114. self.resize(null, height);
  5115. }
  5116. });
  5117. } else {
  5118. statusbar.first().css('visibility', 'hidden');
  5119. }
  5120. if (self.resizeType === 2) {
  5121. _drag({
  5122. moveEl : container,
  5123. clickEl : statusbar.last(),
  5124. moveFn : function(x, y, width, height, diffX, diffY) {
  5125. width += diffX;
  5126. height += diffY;
  5127. self.resize(width, height);
  5128. }
  5129. });
  5130. } else {
  5131. statusbar.last().css('visibility', 'hidden');
  5132. }
  5133. }
  5134. return self;
  5135. },
  5136. remove : function() {
  5137. var self = this;
  5138. if (!self.isCreated) {
  5139. return self;
  5140. }
  5141. self.beforeRemove();
  5142. self.srcElement.data('kindeditor', '');
  5143. if (self.menu) {
  5144. self.hideMenu();
  5145. }
  5146. _each(self.dialogs, function() {
  5147. self.hideDialog();
  5148. });
  5149. K(document).unbind('mousedown', self._docMousedownFn);
  5150. self.toolbar.remove();
  5151. self.edit.remove();
  5152. self.statusbar.last().unbind();
  5153. self.statusbar.unbind();
  5154. self.container.remove();
  5155. self.container = self.toolbar = self.edit = self.menu = null;
  5156. self.dialogs = [];
  5157. self.isCreated = false;
  5158. return self;
  5159. },
  5160. resize : function(width, height, updateProp) {
  5161. var self = this;
  5162. updateProp = _undef(updateProp, true);
  5163. if (width) {
  5164. if (!/%/.test(width)) {
  5165. width = _removeUnit(width);
  5166. width = width < self.minWidth ? self.minWidth : width;
  5167. }
  5168. self.container.css('width', _addUnit(width));
  5169. if (updateProp) {
  5170. self.width = _addUnit(width);
  5171. }
  5172. }
  5173. if (height) {
  5174. height = _removeUnit(height);
  5175. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5176. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5177. self.edit.setHeight(editHeight);
  5178. if (updateProp) {
  5179. self.height = _addUnit(height);
  5180. }
  5181. }
  5182. return self;
  5183. },
  5184. select : function() {
  5185. this.isCreated && this.cmd.select();
  5186. return this;
  5187. },
  5188. html : function(val) {
  5189. var self = this;
  5190. if (val === undefined) {
  5191. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5192. }
  5193. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5194. if (self.isCreated) {
  5195. self.cmd.selection();
  5196. }
  5197. return self;
  5198. },
  5199. fullHtml : function() {
  5200. return this.isCreated ? this.edit.html(undefined, true) : '';
  5201. },
  5202. text : function(val) {
  5203. var self = this;
  5204. if (val === undefined) {
  5205. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5206. } else {
  5207. return self.html(_escape(val));
  5208. }
  5209. },
  5210. isEmpty : function() {
  5211. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5212. },
  5213. isDirty : function() {
  5214. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5215. },
  5216. selectedHtml : function() {
  5217. var val = this.isCreated ? this.cmd.range.html() : '';
  5218. val = _removeBookmarkTag(_removeTempTag(val));
  5219. return val;
  5220. },
  5221. count : function(mode) {
  5222. var self = this;
  5223. mode = (mode || 'html').toLowerCase();
  5224. if (mode === 'html') {
  5225. return self.html().length;
  5226. }
  5227. if (mode === 'text') {
  5228. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5229. }
  5230. return 0;
  5231. },
  5232. exec : function(key) {
  5233. key = key.toLowerCase();
  5234. var self = this, cmd = self.cmd,
  5235. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5236. if (changeFlag) {
  5237. self.addBookmark(false);
  5238. }
  5239. cmd[key].apply(cmd, _toArray(arguments, 1));
  5240. if (changeFlag) {
  5241. self.updateState();
  5242. self.addBookmark(false);
  5243. if (self.options.afterChange) {
  5244. self.options.afterChange.call(self);
  5245. }
  5246. }
  5247. return self;
  5248. },
  5249. insertHtml : function(val, quickMode) {
  5250. if (!this.isCreated) {
  5251. return this;
  5252. }
  5253. val = this.beforeSetHtml(val);
  5254. this.exec('inserthtml', val, quickMode);
  5255. return this;
  5256. },
  5257. appendHtml : function(val) {
  5258. this.html(this.html() + val);
  5259. if (this.isCreated) {
  5260. var cmd = this.cmd;
  5261. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5262. cmd.select();
  5263. }
  5264. return this;
  5265. },
  5266. sync : function() {
  5267. _elementVal(this.srcElement, this.html());
  5268. return this;
  5269. },
  5270. focus : function() {
  5271. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5272. return this;
  5273. },
  5274. blur : function() {
  5275. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5276. return this;
  5277. },
  5278. addBookmark : function(checkSize) {
  5279. checkSize = _undef(checkSize, true);
  5280. var self = this, edit = self.edit,
  5281. body = edit.doc.body,
  5282. html = _removeTempTag(body.innerHTML), bookmark;
  5283. if (checkSize && self._undoStack.length > 0) {
  5284. var prev = self._undoStack[self._undoStack.length - 1];
  5285. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5286. return self;
  5287. }
  5288. }
  5289. if (edit.designMode && !self._firstAddBookmark) {
  5290. var range = self.cmd.range;
  5291. bookmark = range.createBookmark(true);
  5292. bookmark.html = _removeTempTag(body.innerHTML);
  5293. range.moveToBookmark(bookmark);
  5294. } else {
  5295. bookmark = {
  5296. html : html
  5297. };
  5298. }
  5299. self._firstAddBookmark = false;
  5300. _addBookmarkToStack(self._undoStack, bookmark);
  5301. return self;
  5302. },
  5303. undo : function() {
  5304. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5305. },
  5306. redo : function() {
  5307. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5308. },
  5309. fullscreen : function(bool) {
  5310. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5311. this.addBookmark(false);
  5312. return this.remove().create();
  5313. },
  5314. readonly : function(isReadonly) {
  5315. isReadonly = _undef(isReadonly, true);
  5316. var self = this, edit = self.edit, doc = edit.doc;
  5317. if (self.designMode) {
  5318. self.toolbar.disableAll(isReadonly, []);
  5319. } else {
  5320. _each(self.noDisableItems, function() {
  5321. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5322. });
  5323. }
  5324. if (_IE) {
  5325. doc.body.contentEditable = !isReadonly;
  5326. } else {
  5327. doc.designMode = isReadonly ? 'off' : 'on';
  5328. }
  5329. edit.textarea[0].disabled = isReadonly;
  5330. },
  5331. createMenu : function(options) {
  5332. var self = this,
  5333. name = options.name,
  5334. knode = self.toolbar.get(name),
  5335. pos = knode.pos();
  5336. options.x = pos.x;
  5337. options.y = pos.y + knode.height();
  5338. options.z = self.options.zIndex;
  5339. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5340. if (options.selectedColor !== undefined) {
  5341. options.cls = 'ke-colorpicker-' + self.themeType;
  5342. options.noColor = self.lang('noColor');
  5343. self.menu = _colorpicker(options);
  5344. } else {
  5345. options.cls = 'ke-menu-' + self.themeType;
  5346. options.centerLineMode = false;
  5347. self.menu = _menu(options);
  5348. }
  5349. return self.menu;
  5350. },
  5351. hideMenu : function() {
  5352. this.menu.remove();
  5353. this.menu = null;
  5354. return this;
  5355. },
  5356. hideContextmenu : function() {
  5357. this.contextmenu.remove();
  5358. this.contextmenu = null;
  5359. return this;
  5360. },
  5361. createDialog : function(options) {
  5362. var self = this, name = options.name;
  5363. options.z = self.options.zIndex;
  5364. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5365. options.closeBtn = _undef(options.closeBtn, {
  5366. name : self.lang('close'),
  5367. click : function(e) {
  5368. self.hideDialog();
  5369. if (_IE && self.cmd) {
  5370. self.cmd.select();
  5371. }
  5372. }
  5373. });
  5374. options.noBtn = _undef(options.noBtn, {
  5375. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5376. click : function(e) {
  5377. self.hideDialog();
  5378. if (_IE && self.cmd) {
  5379. self.cmd.select();
  5380. }
  5381. }
  5382. });
  5383. if (self.dialogAlignType != 'page') {
  5384. options.alignEl = self.container;
  5385. }
  5386. options.cls = 'ke-dialog-' + self.themeType;
  5387. if (self.dialogs.length > 0) {
  5388. var firstDialog = self.dialogs[0],
  5389. parentDialog = self.dialogs[self.dialogs.length - 1];
  5390. firstDialog.setMaskIndex(parentDialog.z + 2);
  5391. options.z = parentDialog.z + 3;
  5392. options.showMask = false;
  5393. }
  5394. var dialog = _dialog(options);
  5395. self.dialogs.push(dialog);
  5396. return dialog;
  5397. },
  5398. hideDialog : function() {
  5399. var self = this;
  5400. if (self.dialogs.length > 0) {
  5401. self.dialogs.pop().remove();
  5402. }
  5403. if (self.dialogs.length > 0) {
  5404. var firstDialog = self.dialogs[0],
  5405. parentDialog = self.dialogs[self.dialogs.length - 1];
  5406. firstDialog.setMaskIndex(parentDialog.z - 1);
  5407. }
  5408. return self;
  5409. },
  5410. errorDialog : function(html) {
  5411. var self = this;
  5412. var dialog = self.createDialog({
  5413. width : 750,
  5414. title : self.lang('uploadError'),
  5415. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5416. });
  5417. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5418. doc.open();
  5419. doc.write(html);
  5420. doc.close();
  5421. K(doc.body).css('background-color', '#FFF');
  5422. iframe[0].contentWindow.focus();
  5423. return self;
  5424. }
  5425. };
  5426. function _editor(options) {
  5427. return new KEditor(options);
  5428. }
  5429. var _instances = [];
  5430. function _create(expr, options) {
  5431. options = options || {};
  5432. options.basePath = _undef(options.basePath, K.basePath);
  5433. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5434. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5435. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5436. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5437. var themeType = _undef(options.themeType, K.options.themeType);
  5438. _loadStyle(options.themesPath + 'default/default.css');
  5439. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5440. }
  5441. function create(editor) {
  5442. _each(_plugins, function(name, fn) {
  5443. if (_isFunction(fn)) {
  5444. fn.call(editor, KindEditor);
  5445. if (!editor._pluginStatus) {
  5446. editor._pluginStatus = {};
  5447. }
  5448. editor._pluginStatus[name] = 'inited';
  5449. }
  5450. });
  5451. return editor.create();
  5452. }
  5453. var knode = K(expr);
  5454. if (!knode || knode.length === 0) {
  5455. return;
  5456. }
  5457. if (knode.length > 1) {
  5458. knode.each(function() {
  5459. _create(this, options);
  5460. });
  5461. return _instances[0];
  5462. }
  5463. options.srcElement = knode[0];
  5464. var editor = new KEditor(options);
  5465. _instances.push(editor);
  5466. if (_language[editor.langType]) {
  5467. return create(editor);
  5468. }
  5469. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5470. create(editor);
  5471. });
  5472. return editor;
  5473. }
  5474. function _eachEditor(expr, fn) {
  5475. K(expr).each(function(i, el) {
  5476. K.each(_instances, function(j, editor) {
  5477. if (editor && editor.srcElement[0] == el) {
  5478. fn.call(editor, j);
  5479. return false;
  5480. }
  5481. });
  5482. });
  5483. }
  5484. K.remove = function(expr) {
  5485. _eachEditor(expr, function(i) {
  5486. this.remove();
  5487. _instances.splice(i, 1);
  5488. });
  5489. };
  5490. K.sync = function(expr) {
  5491. _eachEditor(expr, function() {
  5492. this.sync();
  5493. });
  5494. };
  5495. K.html = function(expr, val) {
  5496. _eachEditor(expr, function() {
  5497. this.html(val);
  5498. });
  5499. };
  5500. K.insertHtml = function(expr, val) {
  5501. _eachEditor(expr, function() {
  5502. this.insertHtml(val);
  5503. });
  5504. };
  5505. K.appendHtml = function(expr, val) {
  5506. _eachEditor(expr, function() {
  5507. this.appendHtml(val);
  5508. });
  5509. };
  5510. if (_IE && _V < 7) {
  5511. _nativeCommand(document, 'BackgroundImageCache', true);
  5512. }
  5513. K.EditorClass = KEditor;
  5514. K.editor = _editor;
  5515. K.create = _create;
  5516. K.instances = _instances;
  5517. K.plugin = _plugin;
  5518. K.lang = _lang;
  5519. _plugin('core', function(K) {
  5520. var self = this,
  5521. shortcutKeys = {
  5522. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5523. };
  5524. self.afterSetHtml(function() {
  5525. if (self.options.afterChange) {
  5526. self.options.afterChange.call(self);
  5527. }
  5528. });
  5529. self.afterCreate(function() {
  5530. if (self.syncType != 'form') {
  5531. return;
  5532. }
  5533. var el = K(self.srcElement), hasForm = false;
  5534. while ((el = el.parent())) {
  5535. if (el.name == 'form') {
  5536. hasForm = true;
  5537. break;
  5538. }
  5539. }
  5540. if (hasForm) {
  5541. el.bind('submit', function(e) {
  5542. self.sync();
  5543. K(window).bind('unload', function() {
  5544. self.edit.textarea.remove();
  5545. });
  5546. });
  5547. var resetBtn = K('[type="reset"]', el);
  5548. resetBtn.click(function() {
  5549. self.html(self.initContent);
  5550. self.cmd.selection();
  5551. });
  5552. self.beforeRemove(function() {
  5553. el.unbind();
  5554. resetBtn.unbind();
  5555. });
  5556. }
  5557. });
  5558. self.clickToolbar('source', function() {
  5559. if (self.edit.designMode) {
  5560. self.toolbar.disableAll(true);
  5561. self.edit.design(false);
  5562. self.toolbar.select('source');
  5563. } else {
  5564. self.toolbar.disableAll(false);
  5565. self.edit.design(true);
  5566. self.toolbar.unselect('source');
  5567. if (_GECKO) {
  5568. setTimeout(function() {
  5569. self.cmd.selection();
  5570. }, 0);
  5571. } else {
  5572. self.cmd.selection();
  5573. }
  5574. }
  5575. self.designMode = self.edit.designMode;
  5576. });
  5577. self.afterCreate(function() {
  5578. if (!self.designMode) {
  5579. self.toolbar.disableAll(true).select('source');
  5580. }
  5581. });
  5582. self.clickToolbar('fullscreen', function() {
  5583. self.fullscreen();
  5584. });
  5585. if (self.fullscreenShortcut) {
  5586. var loaded = false;
  5587. self.afterCreate(function() {
  5588. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5589. if (e.which == 27) {
  5590. setTimeout(function() {
  5591. self.fullscreen();
  5592. }, 0);
  5593. }
  5594. });
  5595. if (loaded) {
  5596. if (_IE && !self.designMode) {
  5597. return;
  5598. }
  5599. self.focus();
  5600. }
  5601. if (!loaded) {
  5602. loaded = true;
  5603. }
  5604. });
  5605. }
  5606. _each('undo,redo'.split(','), function(i, name) {
  5607. if (shortcutKeys[name]) {
  5608. self.afterCreate(function() {
  5609. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5610. self.clickToolbar(name);
  5611. });
  5612. });
  5613. }
  5614. self.clickToolbar(name, function() {
  5615. self[name]();
  5616. });
  5617. });
  5618. self.clickToolbar('formatblock', function() {
  5619. var blocks = self.lang('formatblock.formatBlock'),
  5620. heights = {
  5621. h1 : 28,
  5622. h2 : 24,
  5623. h3 : 18,
  5624. H4 : 14,
  5625. p : 12
  5626. },
  5627. curVal = self.cmd.val('formatblock'),
  5628. menu = self.createMenu({
  5629. name : 'formatblock',
  5630. width : self.langType == 'en' ? 200 : 150
  5631. });
  5632. _each(blocks, function(key, val) {
  5633. var style = 'font-size:' + heights[key] + 'px;';
  5634. if (key.charAt(0) === 'h') {
  5635. style += 'font-weight:bold;';
  5636. }
  5637. menu.addItem({
  5638. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5639. height : heights[key] + 12,
  5640. checked : (curVal === key || curVal === val),
  5641. click : function() {
  5642. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5643. }
  5644. });
  5645. });
  5646. });
  5647. self.clickToolbar('fontname', function() {
  5648. var curVal = self.cmd.val('fontname'),
  5649. menu = self.createMenu({
  5650. name : 'fontname',
  5651. width : 150
  5652. });
  5653. _each(self.lang('fontname.fontName'), function(key, val) {
  5654. menu.addItem({
  5655. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5656. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5657. click : function() {
  5658. self.exec('fontname', key).hideMenu();
  5659. }
  5660. });
  5661. });
  5662. });
  5663. self.clickToolbar('fontsize', function() {
  5664. var curVal = self.cmd.val('fontsize'),
  5665. menu = self.createMenu({
  5666. name : 'fontsize',
  5667. width : 150
  5668. });
  5669. _each(self.fontSizeTable, function(i, val) {
  5670. menu.addItem({
  5671. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5672. height : _removeUnit(val) + 12,
  5673. checked : curVal === val,
  5674. click : function() {
  5675. self.exec('fontsize', val).hideMenu();
  5676. }
  5677. });
  5678. });
  5679. });
  5680. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5681. self.clickToolbar(name, function() {
  5682. self.createMenu({
  5683. name : name,
  5684. selectedColor : self.cmd.val(name) || 'default',
  5685. colors : self.colorTable,
  5686. click : function(color) {
  5687. self.exec(name, color).hideMenu();
  5688. }
  5689. });
  5690. });
  5691. });
  5692. _each(('cut,copy,paste').split(','), function(i, name) {
  5693. self.clickToolbar(name, function() {
  5694. self.focus();
  5695. try {
  5696. self.exec(name, null);
  5697. } catch(e) {
  5698. alert(self.lang(name + 'Error'));
  5699. }
  5700. });
  5701. });
  5702. self.clickToolbar('about', function() {
  5703. var html = '<div style="margin:20px;">' +
  5704. '<div>KindEditor ' + _VERSION + '</div>' +
  5705. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5706. '</div>';
  5707. self.createDialog({
  5708. name : 'about',
  5709. width : 350,
  5710. title : self.lang('about'),
  5711. body : html
  5712. });
  5713. });
  5714. self.plugin.getSelectedLink = function() {
  5715. return self.cmd.commonAncestor('a');
  5716. };
  5717. self.plugin.getSelectedImage = function() {
  5718. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5719. return !/^ke-\w+$/i.test(img[0].className);
  5720. });
  5721. };
  5722. self.plugin.getSelectedFlash = function() {
  5723. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5724. return img[0].className == 'ke-flash';
  5725. });
  5726. };
  5727. self.plugin.getSelectedMedia = function() {
  5728. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5729. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5730. });
  5731. };
  5732. self.plugin.getSelectedAnchor = function() {
  5733. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5734. return img[0].className == 'ke-anchor';
  5735. });
  5736. };
  5737. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5738. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5739. _each('edit,delete'.split(','), function(j, val) {
  5740. self.addContextmenu({
  5741. title : self.lang(val + uName),
  5742. click : function() {
  5743. self.loadPlugin(name, function() {
  5744. self.plugin[name][val]();
  5745. self.hideMenu();
  5746. });
  5747. },
  5748. cond : self.plugin['getSelected' + uName],
  5749. width : 150,
  5750. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5751. });
  5752. });
  5753. self.addContextmenu({ title : '-' });
  5754. });
  5755. self.plugin.getSelectedTable = function() {
  5756. return self.cmd.commonAncestor('table');
  5757. };
  5758. self.plugin.getSelectedRow = function() {
  5759. return self.cmd.commonAncestor('tr');
  5760. };
  5761. self.plugin.getSelectedCell = function() {
  5762. return self.cmd.commonAncestor('td');
  5763. };
  5764. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5765. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5766. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5767. self.addContextmenu({
  5768. title : self.lang('table' + val),
  5769. click : function() {
  5770. self.loadPlugin('table', function() {
  5771. self.plugin.table[val]();
  5772. self.hideMenu();
  5773. });
  5774. },
  5775. cond : cond,
  5776. width : 170,
  5777. iconClass : 'ke-icon-table' + val
  5778. });
  5779. });
  5780. self.addContextmenu({ title : '-' });
  5781. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5782. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5783. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5784. if (shortcutKeys[name]) {
  5785. self.afterCreate(function() {
  5786. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5787. self.cmd.selection();
  5788. self.clickToolbar(name);
  5789. });
  5790. });
  5791. }
  5792. self.clickToolbar(name, function() {
  5793. self.focus().exec(name, null);
  5794. });
  5795. });
  5796. self.afterCreate(function() {
  5797. var doc = self.edit.doc, cmd, bookmark, div,
  5798. cls = '__kindeditor_paste__', pasting = false;
  5799. function movePastedData() {
  5800. cmd.range.moveToBookmark(bookmark);
  5801. cmd.select();
  5802. if (_WEBKIT) {
  5803. K('div.' + cls, div).each(function() {
  5804. K(this).after('<br />').remove(true);
  5805. });
  5806. K('span.Apple-style-span', div).remove(true);
  5807. K('span.Apple-tab-span', div).remove(true);
  5808. K('span[style]', div).each(function() {
  5809. if (K(this).css('white-space') == 'nowrap') {
  5810. K(this).remove(true);
  5811. }
  5812. });
  5813. K('meta', div).remove();
  5814. }
  5815. var html = div[0].innerHTML;
  5816. div.remove();
  5817. if (html === '') {
  5818. return;
  5819. }
  5820. if (_WEBKIT) {
  5821. html = html.replace(/(<br>)\1/ig, '$1');
  5822. }
  5823. if (self.pasteType === 2) {
  5824. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5825. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5826. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5827. } else {
  5828. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5829. html = self.beforeSetHtml(html);
  5830. }
  5831. }
  5832. if (self.pasteType === 1) {
  5833. html = html.replace(/&nbsp;/ig, ' ');
  5834. html = html.replace(/\n\s*\n/g, '\n');
  5835. html = html.replace(/<br[^>]*>/ig, '\n');
  5836. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5837. html = html.replace(/<[^>]+>/g, '');
  5838. html = html.replace(/ {2}/g, ' &nbsp;');
  5839. if (self.newlineTag == 'p') {
  5840. if (/\n/.test(html)) {
  5841. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5842. }
  5843. } else {
  5844. html = html.replace(/\n/g, '<br />$&');
  5845. }
  5846. }
  5847. self.insertHtml(html, true);
  5848. }
  5849. K(doc.body).bind('paste', function(e){
  5850. //处理IE11,Chrome粘贴图片上传
  5851. function dopasteImg() {
  5852. //debugger;
  5853. var file = null;
  5854. if (window.clipboardData) {//ie
  5855. if (clipboardData.files && clipboardData.files.length)//IE11
  5856. file = clipboardData.files[0];
  5857. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5858. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5859. return true;
  5860. }
  5861. } else {
  5862. if (e.event.clipboardData.items)//chrome
  5863. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5864. if (e.event.clipboardData.items[i].kind === "file") {
  5865. file = e.event.clipboardData.items[i];
  5866. break;
  5867. }
  5868. }
  5869. if (file == null) {
  5870. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5871. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5872. return true;
  5873. }
  5874. }
  5875. }
  5876. if (file) {
  5877. if (!K.undef(self.allowImageUpload, true)) {
  5878. alert("编辑器禁止上传图片,请与有关人员联系!");
  5879. return true;
  5880. }
  5881. //获取File Blob
  5882. //debugger;
  5883. var blb;
  5884. if (file.getAsFile) {//Chrome
  5885. blb = file.getAsFile();
  5886. if (blb.size === 0) {
  5887. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5888. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5889. return true;
  5890. }
  5891. sendfile(blb, file.type);
  5892. } else {
  5893. var fr = new FileReader();
  5894. if (fr.readAsArrayBuffer) {//ie
  5895. fr.onloadend = function (evt) {
  5896. blb = evt.target.result;
  5897. sendfile(blb, file.type);
  5898. }
  5899. fr.readAsArrayBuffer(file);
  5900. }
  5901. }
  5902. function sendfile(b, t) {
  5903. var xhr = new XMLHttpRequest();
  5904. var formData = new FormData();
  5905. var isImg = t.indexOf("image/") === 0;
  5906. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5907. //formData.append('imgFile', b);
  5908. var myBlob = new Blob([b], { "type": t });
  5909. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5910. //formData.append('imgFile', b);
  5911. formData.append('dir', isImg ? 'image' : 'file');
  5912. xhr.open('POST', self.uploadJson);
  5913. xhr.onreadystatechange = function () {
  5914. if (xhr.readyState == 4&&xhr.status == 200) {
  5915. // if (fn) {
  5916. var data = _trim(xhr.responseText);
  5917. //if (dataType == 'json') {
  5918. data = _json(data);
  5919. if (data.error) {
  5920. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5921. $.messager.alert('Error', data.message, 'warning');
  5922. } else {
  5923. alert(data.message);
  5924. }
  5925. } else {
  5926. //self.exec('insertimage', url, title, width, height, border, align);
  5927. if(K.undef(self.formatUploadUrl, true))
  5928. data.url =K.formatUrl(data.url, 'absolute');
  5929. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5930. }
  5931. //}
  5932. // fn(data);
  5933. // }
  5934. }
  5935. }
  5936. xhr.send(formData);
  5937. }
  5938. return true;
  5939. }
  5940. }
  5941. //debugger;
  5942. if (dopasteImg())
  5943. e.stop();
  5944. //处理粘贴结束5825
  5945. if (self.pasteType === 0) {
  5946. e.stop();
  5947. return;
  5948. }
  5949. if (pasting) {
  5950. return;
  5951. }
  5952. pasting = true;
  5953. K('div.' + cls, doc).remove();
  5954. cmd = self.cmd.selection();
  5955. bookmark = cmd.range.createBookmark();
  5956. div = K('<div class="' + cls + '"></div>', doc).css({
  5957. position : 'absolute',
  5958. width : '1px',
  5959. height : '1px',
  5960. overflow : 'hidden',
  5961. left : '-1981px',
  5962. top : K(bookmark.start).pos().y + 'px',
  5963. 'white-space' : 'nowrap'
  5964. });
  5965. K(doc.body).append(div);
  5966. if (_IE) {
  5967. var rng = cmd.range.get(true);
  5968. rng.moveToElementText(div[0]);
  5969. rng.select();
  5970. rng.execCommand('paste');
  5971. e.preventDefault();
  5972. } else {
  5973. cmd.range.selectNodeContents(div[0]);
  5974. cmd.select();
  5975. div[0].tabIndex = -1;
  5976. div[0].focus();
  5977. }
  5978. setTimeout(function() {
  5979. movePastedData();
  5980. pasting = false;
  5981. }, 0);
  5982. });
  5983. });
  5984. self.beforeGetHtml(function(html) {
  5985. if (_IE && _V <= 8) {
  5986. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5987. return unescape(tag);
  5988. });
  5989. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5990. if (!/\s+type="[^"]+"/i.test($0)) {
  5991. return $1 + ' type="text"' + $2;
  5992. }
  5993. return $0;
  5994. });
  5995. }
  5996. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5997. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5998. })
  5999. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  6000. var imgAttrs = _getAttrList(full);
  6001. var styles = _getCssList(imgAttrs.style || '');
  6002. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6003. var width = _undef(styles.width, '');
  6004. var height = _undef(styles.height, '');
  6005. if (/px/i.test(width)) {
  6006. width = _removeUnit(width);
  6007. }
  6008. if (/px/i.test(height)) {
  6009. height = _removeUnit(height);
  6010. }
  6011. attrs.width = _undef(imgAttrs.width, width);
  6012. attrs.height = _undef(imgAttrs.height, height);
  6013. return _mediaEmbed(attrs);
  6014. })
  6015. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6016. var imgAttrs = _getAttrList(full);
  6017. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6018. })
  6019. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6020. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6021. })
  6022. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6023. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6024. })
  6025. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6026. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6027. return $1 + _unescape(src) + $2;
  6028. });
  6029. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6030. return full;
  6031. })
  6032. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6033. return start + end;
  6034. });
  6035. });
  6036. self.beforeSetHtml(function(html) {
  6037. if (_IE && _V <= 8) {
  6038. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6039. var attrs = _getAttrList(full);
  6040. var styles = _getCssList(attrs.style || '');
  6041. if (styles.display == 'none') {
  6042. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6043. }
  6044. return full;
  6045. });
  6046. }
  6047. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6048. var attrs = _getAttrList(full);
  6049. attrs.src = _undef(attrs.src, '');
  6050. attrs.width = _undef(attrs.width, 0);
  6051. attrs.height = _undef(attrs.height, 0);
  6052. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6053. })
  6054. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6055. var attrs = _getAttrList(full);
  6056. if (attrs.href !== undefined) {
  6057. return full;
  6058. }
  6059. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6060. })
  6061. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6062. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6063. })
  6064. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6065. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6066. })
  6067. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6068. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6069. return full;
  6070. }
  6071. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6072. return full;
  6073. })
  6074. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6075. return start + 'data-ke-' + end;
  6076. })
  6077. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6078. if (full.indexOf('ke-zeroborder') >= 0) {
  6079. return full;
  6080. }
  6081. return _addClassToTag(full, 'ke-zeroborder');
  6082. });
  6083. });
  6084. });
  6085. })(window);
  6086. /*******************************************************************************
  6087. * KindEditor - WYSIWYG HTML Editor for Internet
  6088. * Copyright (C) 2006-2011 kindsoft.net
  6089. *
  6090. * @author Roddy <luolonghao@gmail.com>
  6091. * @site http://www.kindsoft.net/
  6092. * @licence http://www.kindsoft.net/license.php
  6093. *******************************************************************************/
  6094. KindEditor.lang({
  6095. source : 'HTML代码',
  6096. preview : '预览',
  6097. undo : '后退(Ctrl+Z)',
  6098. redo : '前进(Ctrl+Y)',
  6099. cut : '剪切(Ctrl+X)',
  6100. copy : '复制(Ctrl+C)',
  6101. paste : '粘贴(Ctrl+V)',
  6102. plainpaste : '粘贴为无格式文本',
  6103. wordpaste : '从Word粘贴',
  6104. selectall : '全选(Ctrl+A)',
  6105. justifyleft : '左对齐',
  6106. justifycenter : '居中',
  6107. justifyright : '右对齐',
  6108. justifyfull : '两端对齐',
  6109. insertorderedlist : '编号',
  6110. insertunorderedlist : '项目符号',
  6111. indent : '增加缩进',
  6112. outdent : '减少缩进',
  6113. subscript : '下标',
  6114. superscript : '上标',
  6115. formatblock : '段落',
  6116. fontname : '字体',
  6117. fontsize : '文字大小',
  6118. forecolor : '文字颜色',
  6119. hilitecolor : '文字背景',
  6120. bold : '粗体(Ctrl+B)',
  6121. italic : '斜体(Ctrl+I)',
  6122. underline : '下划线(Ctrl+U)',
  6123. strikethrough : '删除线',
  6124. removeformat : '删除格式',
  6125. image : '图片',
  6126. multiimage : '批量图片上传',
  6127. flash : 'Flash',
  6128. media : '音频',
  6129. table : '表格',
  6130. tablecell : '单元格',
  6131. hr : '插入横线',
  6132. emoticons : '插入表情',
  6133. link : '超级链接',
  6134. unlink : '取消超级链接',
  6135. fullscreen : '全屏显示',
  6136. about : '关于',
  6137. print : '打印(Ctrl+P)',
  6138. filemanager : '文件库',
  6139. code : '插入程序代码',
  6140. map : 'Google地图',
  6141. baidumap : '百度地图',
  6142. lineheight : '行距',
  6143. clearhtml : '清理HTML代码',
  6144. pagebreak : '插入分页符',
  6145. quickformat : '一键排版',
  6146. insertfile : '插入文件',
  6147. template : '插入模板',
  6148. anchor : '锚点',
  6149. yes : '确定',
  6150. no : '取消',
  6151. close : '关闭',
  6152. editImage : '图片属性',
  6153. deleteImage : '删除图片',
  6154. editFlash : 'Flash属性',
  6155. deleteFlash : '删除Flash',
  6156. editMedia : '音频属性',
  6157. deleteMedia : '删除音频',
  6158. editLink : '超级链接属性',
  6159. deleteLink : '取消超级链接',
  6160. editAnchor : '锚点属性',
  6161. deleteAnchor : '删除锚点',
  6162. tableprop : '表格属性',
  6163. tablecellprop : '单元格属性',
  6164. tableinsert : '插入表格',
  6165. tabledelete : '删除表格',
  6166. tablecolinsertleft : '左侧插入列',
  6167. tablecolinsertright : '右侧插入列',
  6168. tablerowinsertabove : '上方插入行',
  6169. tablerowinsertbelow : '下方插入行',
  6170. tablerowmerge : '向下合并单元格',
  6171. tablecolmerge : '向右合并单元格',
  6172. tablerowsplit : '拆分行',
  6173. tablecolsplit : '拆分列',
  6174. tablecoldelete : '删除列',
  6175. tablerowdelete : '删除行',
  6176. noColor : '无颜色',
  6177. pleaseSelectFile : '请选择文件。',
  6178. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6179. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6180. invalidWidth : "宽度必须为数字。",
  6181. invalidHeight : "高度必须为数字。",
  6182. invalidBorder : "边框必须为数字。",
  6183. invalidUrl : "请输入有效的URL地址。",
  6184. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6185. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6186. invalidPadding : '边距必须为数字。',
  6187. invalidSpacing : '间距必须为数字。',
  6188. invalidJson : '服务器发生故障。',
  6189. uploadSuccess : '上传成功。',
  6190. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6191. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6192. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6193. ajaxLoading : '加载中,请稍候 ...',
  6194. uploadLoading : '上传中,请稍候 ...',
  6195. uploadError : '上传错误',
  6196. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6197. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6198. 'code.pleaseInput' : '请输入程序代码。',
  6199. 'link.url' : 'URL',
  6200. 'link.linkType' : '打开类型',
  6201. 'link.newWindow' : '新窗口',
  6202. 'link.selfWindow' : '当前窗口',
  6203. 'flash.url' : 'URL',
  6204. 'flash.width' : '宽度',
  6205. 'flash.height' : '高度',
  6206. 'flash.upload' : '上传',
  6207. 'flash.viewServer' : '文件空间',
  6208. 'media.url' : 'URL',
  6209. 'media.width' : '宽度',
  6210. 'media.height' : '高度',
  6211. 'media.autostart' : '自动播放',
  6212. 'media.upload' : '上传',
  6213. 'media.viewServer' : '文件空间',
  6214. 'image.remoteImage' : '网络图片',
  6215. 'image.localImage' : '本地上传',
  6216. 'image.remoteUrl' : '图片地址',
  6217. 'image.localUrl' : '上传文件',
  6218. 'image.size' : '图片大小',
  6219. 'image.width' : '宽',
  6220. 'image.height' : '高',
  6221. 'image.resetSize' : '重置大小',
  6222. 'image.align' : '对齐方式',
  6223. 'image.defaultAlign' : '默认方式',
  6224. 'image.leftAlign' : '左对齐',
  6225. 'image.rightAlign' : '右对齐',
  6226. 'image.imgTitle' : '图片说明',
  6227. 'image.upload' : '浏览...',
  6228. 'image.viewServer' : '图片空间',
  6229. //'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6230. 'multiimage.uploadDesc' : '',
  6231. 'multiimage.startUpload' : '开始上传',
  6232. 'multiimage.clearAll' : '全部清空',
  6233. 'multiimage.insertAll' : '全部插入',
  6234. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6235. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6236. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6237. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6238. 'multiimage.unknownError' : '发生异常,无法上传。',
  6239. 'multiimage.pending' : '等待上传',
  6240. 'multiimage.uploadError' : '上传失败',
  6241. 'filemanager.emptyFolder' : '空文件夹',
  6242. 'filemanager.moveup' : '移到上一级文件夹',
  6243. 'filemanager.viewType' : '显示方式:',
  6244. 'filemanager.viewImage' : '缩略图',
  6245. 'filemanager.listImage' : '详细信息',
  6246. 'filemanager.orderType' : '排序方式:',
  6247. 'filemanager.fileName' : '名称',
  6248. 'filemanager.fileSize' : '大小',
  6249. 'filemanager.fileType' : '类型',
  6250. 'insertfile.url' : 'URL',
  6251. 'insertfile.title' : '文件说明',
  6252. 'insertfile.upload' : '上传',
  6253. 'insertfile.viewServer' : '文件空间',
  6254. 'table.cells' : '单元格数',
  6255. 'table.rows' : '行数',
  6256. 'table.cols' : '列数',
  6257. 'table.size' : '大小',
  6258. 'table.width' : '宽度',
  6259. 'table.height' : '高度',
  6260. 'table.percent' : '%',
  6261. 'table.px' : 'px',
  6262. 'table.space' : '边距间距',
  6263. 'table.padding' : '边距',
  6264. 'table.spacing' : '间距',
  6265. 'table.align' : '对齐方式',
  6266. 'table.textAlign' : '水平对齐',
  6267. 'table.verticalAlign' : '垂直对齐',
  6268. 'table.alignDefault' : '默认',
  6269. 'table.alignLeft' : '左对齐',
  6270. 'table.alignCenter' : '居中',
  6271. 'table.alignRight' : '右对齐',
  6272. 'table.alignTop' : '顶部',
  6273. 'table.alignMiddle' : '中部',
  6274. 'table.alignBottom' : '底部',
  6275. 'table.alignBaseline' : '基线',
  6276. 'table.border' : '边框',
  6277. 'table.borderWidth' : '边框',
  6278. 'table.borderColor' : '颜色',
  6279. 'table.backgroundColor' : '背景颜色',
  6280. 'map.address' : '地址: ',
  6281. 'map.search' : '搜索',
  6282. 'baidumap.address' : '地址: ',
  6283. 'baidumap.search' : '搜索',
  6284. 'baidumap.insertDynamicMap' : '插入动态地图',
  6285. 'anchor.name' : '锚点名称',
  6286. 'formatblock.formatBlock' : {
  6287. h1 : '标题 1',
  6288. h2 : '标题 2',
  6289. h3 : '标题 3',
  6290. h4 : '标题 4',
  6291. p : '正 文'
  6292. },
  6293. 'fontname.fontName' : {
  6294. 'SimSun' : '宋体',
  6295. 'NSimSun' : '新宋体',
  6296. 'FangSong_GB2312' : '仿宋_GB2312',
  6297. 'KaiTi_GB2312' : '楷体_GB2312',
  6298. 'SimHei' : '黑体',
  6299. 'Microsoft YaHei' : '微软雅黑',
  6300. 'Arial' : 'Arial',
  6301. 'Arial Black' : 'Arial Black',
  6302. 'Times New Roman' : 'Times New Roman',
  6303. 'Courier New' : 'Courier New',
  6304. 'Tahoma' : 'Tahoma',
  6305. 'Verdana' : 'Verdana'
  6306. },
  6307. 'lineheight.lineHeight' : [
  6308. {'1' : '单倍行距'},
  6309. {'1.5' : '1.5倍行距'},
  6310. {'2' : '2倍行距'},
  6311. {'2.5' : '2.5倍行距'},
  6312. {'3' : '3倍行距'}
  6313. ],
  6314. 'template.selectTemplate' : '可选模板',
  6315. 'template.replaceContent' : '替换当前内容',
  6316. 'template.fileList' : {
  6317. '1.html' : '图片和文字',
  6318. '2.html' : '表格',
  6319. '3.html' : '项目编号'
  6320. }
  6321. }, 'zh-CN');
  6322. KindEditor.options.langType = 'zh-CN';
  6323. /*******************************************************************************
  6324. * KindEditor - WYSIWYG HTML Editor for Internet
  6325. * Copyright (C) 2006-2011 kindsoft.net
  6326. *
  6327. * @author Roddy <luolonghao@gmail.com>
  6328. * @site http://www.kindsoft.net/
  6329. * @licence http://www.kindsoft.net/license.php
  6330. *******************************************************************************/
  6331. KindEditor.plugin('anchor', function(K) {
  6332. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6333. self.plugin.anchor = {
  6334. edit : function() {
  6335. var html = ['<div style="padding:20px;">',
  6336. '<div class="ke-dialog-row">',
  6337. '<label for="keName">' + lang.name + '</label>',
  6338. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6339. '</div>',
  6340. '</div>'].join('');
  6341. var dialog = self.createDialog({
  6342. name : name,
  6343. width : 300,
  6344. title : self.lang(name),
  6345. body : html,
  6346. yesBtn : {
  6347. name : self.lang('yes'),
  6348. click : function(e) {
  6349. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6350. }
  6351. }
  6352. });
  6353. var div = dialog.div,
  6354. nameBox = K('input[name="name"]', div);
  6355. var img = self.plugin.getSelectedAnchor();
  6356. if (img) {
  6357. nameBox.val(unescape(img.attr('data-ke-name')));
  6358. }
  6359. nameBox[0].focus();
  6360. nameBox[0].select();
  6361. },
  6362. 'delete' : function() {
  6363. self.plugin.getSelectedAnchor().remove();
  6364. }
  6365. };
  6366. self.clickToolbar(name, self.plugin.anchor.edit);
  6367. });
  6368. /*******************************************************************************
  6369. * KindEditor - WYSIWYG HTML Editor for Internet
  6370. * Copyright (C) 2006-2011 kindsoft.net
  6371. *
  6372. * @author Roddy <luolonghao@gmail.com>
  6373. * @site http://www.kindsoft.net/
  6374. * @licence http://www.kindsoft.net/license.php
  6375. *******************************************************************************/
  6376. KindEditor.plugin('autoheight', function(K) {
  6377. var self = this;
  6378. if (!self.autoHeightMode) {
  6379. return;
  6380. }
  6381. var minHeight;
  6382. function hideScroll() {
  6383. var edit = self.edit;
  6384. var body = edit.doc.body;
  6385. edit.iframe[0].scroll = 'no';
  6386. body.style.overflowY = 'hidden';
  6387. }
  6388. function resetHeight() {
  6389. if(self.fullscreenMode){
  6390. return;
  6391. }
  6392. var edit = self.edit;
  6393. var body = edit.doc.body;
  6394. edit.iframe.height(minHeight);
  6395. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6396. }
  6397. function init() {
  6398. minHeight = K.removeUnit(self.height);
  6399. self.edit.afterChange(resetHeight);
  6400. if(!self.fullscreenMode){
  6401. hideScroll();
  6402. }
  6403. resetHeight();
  6404. }
  6405. if (self.isCreated) {
  6406. init();
  6407. } else {
  6408. self.afterCreate(init);
  6409. }
  6410. });
  6411. /*
  6412. * 如何实现真正的自动高度?
  6413. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6414. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6415. * 由此就实现了真正的自动高度
  6416. * 测试:chrome、firefox、IE9、IE8
  6417. * */
  6418. /*******************************************************************************
  6419. * KindEditor - WYSIWYG HTML Editor for Internet
  6420. * Copyright (C) 2006-2011 kindsoft.net
  6421. *
  6422. * @author Roddy <luolonghao@gmail.com>
  6423. * @site http://www.kindsoft.net/
  6424. * @licence http://www.kindsoft.net/license.php
  6425. *******************************************************************************/
  6426. KindEditor.plugin('baidumap', function(K) {
  6427. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6428. var mapWidth = K.undef(self.mapWidth, 558);
  6429. var mapHeight = K.undef(self.mapHeight, 360);
  6430. self.clickToolbar(name, function() {
  6431. var html = ['<div style="padding:10px 20px;">',
  6432. '<div class="ke-header">',
  6433. '<div class="ke-left">',
  6434. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6435. '<span class="ke-button-common ke-button-outer">',
  6436. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6437. '</span>',
  6438. '</div>',
  6439. '<div class="ke-right">',
  6440. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6441. '</div>',
  6442. '<div class="ke-clearfix"></div>',
  6443. '</div>',
  6444. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6445. '</div>'].join('');
  6446. var dialog = self.createDialog({
  6447. name : name,
  6448. width : mapWidth + 42,
  6449. title : self.lang(name),
  6450. body : html,
  6451. yesBtn : {
  6452. name : self.lang('yes'),
  6453. click : function(e) {
  6454. var map = win.map;
  6455. var centerObj = map.getCenter();
  6456. var center = centerObj.lng + ',' + centerObj.lat;
  6457. var zoom = map.getZoom();
  6458. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6459. '?center=' + encodeURIComponent(center),
  6460. '&zoom=' + encodeURIComponent(zoom),
  6461. '&width=' + mapWidth,
  6462. '&height=' + mapHeight,
  6463. '&markers=' + encodeURIComponent(center),
  6464. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6465. if (checkbox[0].checked) {
  6466. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6467. } else {
  6468. self.exec('insertimage', url);
  6469. }
  6470. self.hideDialog().focus();
  6471. }
  6472. },
  6473. beforeRemove : function() {
  6474. searchBtn.remove();
  6475. if (doc) {
  6476. doc.write('');
  6477. }
  6478. iframe.remove();
  6479. }
  6480. });
  6481. var div = dialog.div,
  6482. addressBox = K('[name="address"]', div),
  6483. searchBtn = K('[name="searchBtn"]', div),
  6484. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6485. win, doc;
  6486. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6487. function ready() {
  6488. win = iframe[0].contentWindow;
  6489. doc = K.iframeDoc(iframe);
  6490. }
  6491. iframe.bind('load', function() {
  6492. iframe.unbind('load');
  6493. if (K.IE) {
  6494. ready();
  6495. } else {
  6496. setTimeout(ready, 0);
  6497. }
  6498. });
  6499. K('.ke-map', div).replaceWith(iframe);
  6500. searchBtn.click(function() {
  6501. win.search(addressBox.val());
  6502. });
  6503. });
  6504. });
  6505. /*******************************************************************************
  6506. * KindEditor - WYSIWYG HTML Editor for Internet
  6507. * Copyright (C) 2006-2011 kindsoft.net
  6508. *
  6509. * @author Roddy <luolonghao@gmail.com>
  6510. * @site http://www.kindsoft.net/
  6511. * @licence http://www.kindsoft.net/license.php
  6512. *******************************************************************************/
  6513. KindEditor.plugin('map', function(K) {
  6514. var self = this, name = 'map', lang = self.lang(name + '.');
  6515. self.clickToolbar(name, function() {
  6516. var html = ['<div style="padding:10px 20px;">',
  6517. '<div class="ke-dialog-row">',
  6518. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6519. '<span class="ke-button-common ke-button-outer">',
  6520. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6521. '</span>',
  6522. '</div>',
  6523. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6524. '</div>'].join('');
  6525. var dialog = self.createDialog({
  6526. name : name,
  6527. width : 600,
  6528. title : self.lang(name),
  6529. body : html,
  6530. yesBtn : {
  6531. name : self.lang('yes'),
  6532. click : function(e) {
  6533. var geocoder = win.geocoder,
  6534. map = win.map,
  6535. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6536. zoom = map.getZoom(),
  6537. maptype = map.getMapTypeId(),
  6538. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6539. url += '?center=' + encodeURIComponent(center);
  6540. url += '&zoom=' + encodeURIComponent(zoom);
  6541. url += '&size=558x360';
  6542. url += '&maptype=' + encodeURIComponent(maptype);
  6543. url += '&markers=' + encodeURIComponent(center);
  6544. url += '&language=' + self.langType;
  6545. url += '&sensor=false';
  6546. self.exec('insertimage', url).hideDialog().focus();
  6547. }
  6548. },
  6549. beforeRemove : function() {
  6550. searchBtn.remove();
  6551. if (doc) {
  6552. doc.write('');
  6553. }
  6554. iframe.remove();
  6555. }
  6556. });
  6557. var div = dialog.div,
  6558. addressBox = K('[name="address"]', div),
  6559. searchBtn = K('[name="searchBtn"]', div),
  6560. win, doc;
  6561. var iframeHtml = ['<!doctype html><html><head>',
  6562. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6563. '<style>',
  6564. ' html { height: 100% }',
  6565. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6566. ' #map_canvas { height: 100% }',
  6567. '</style>',
  6568. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6569. '<script>',
  6570. 'var map, geocoder;',
  6571. 'function initialize() {',
  6572. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6573. ' var options = {',
  6574. ' zoom: 11,',
  6575. ' center: latlng,',
  6576. ' disableDefaultUI: true,',
  6577. ' panControl: true,',
  6578. ' zoomControl: true,',
  6579. ' mapTypeControl: true,',
  6580. ' scaleControl: true,',
  6581. ' streetViewControl: false,',
  6582. ' overviewMapControl: true,',
  6583. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6584. ' };',
  6585. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6586. ' geocoder = new google.maps.Geocoder();',
  6587. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6588. ' if (status == google.maps.GeocoderStatus.OK) {',
  6589. ' if (results[3]) {',
  6590. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6591. ' }',
  6592. ' }',
  6593. ' });',
  6594. '}',
  6595. 'function search(address) {',
  6596. ' if (!map) return;',
  6597. ' geocoder.geocode({address : address}, function(results, status) {',
  6598. ' if (status == google.maps.GeocoderStatus.OK) {',
  6599. ' map.setZoom(11);',
  6600. ' map.setCenter(results[0].geometry.location);',
  6601. ' var marker = new google.maps.Marker({',
  6602. ' map: map,',
  6603. ' position: results[0].geometry.location',
  6604. ' });',
  6605. ' } else {',
  6606. ' alert("Invalid address: " + address);',
  6607. ' }',
  6608. ' });',
  6609. '}',
  6610. '</script>',
  6611. '</head>',
  6612. '<body onload="initialize();">',
  6613. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6614. '</body></html>'].join('\n');
  6615. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6616. function ready() {
  6617. win = iframe[0].contentWindow;
  6618. doc = K.iframeDoc(iframe);
  6619. }
  6620. iframe.bind('load', function() {
  6621. iframe.unbind('load');
  6622. if (K.IE) {
  6623. ready();
  6624. } else {
  6625. setTimeout(ready, 0);
  6626. }
  6627. });
  6628. K('.ke-map', div).replaceWith(iframe);
  6629. searchBtn.click(function() {
  6630. win.search(addressBox.val());
  6631. });
  6632. });
  6633. });
  6634. /*******************************************************************************
  6635. * KindEditor - WYSIWYG HTML Editor for Internet
  6636. * Copyright (C) 2006-2011 kindsoft.net
  6637. *
  6638. * @author Roddy <luolonghao@gmail.com>
  6639. * @site http://www.kindsoft.net/
  6640. * @licence http://www.kindsoft.net/license.php
  6641. *******************************************************************************/
  6642. KindEditor.plugin('clearhtml', function(K) {
  6643. var self = this, name = 'clearhtml';
  6644. self.clickToolbar(name, function() {
  6645. self.focus();
  6646. var html = self.html();
  6647. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6648. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6649. html = K.formatHtml(html, {
  6650. a : ['href', 'target'],
  6651. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6652. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6653. table : ['border'],
  6654. 'td,th' : ['rowspan', 'colspan'],
  6655. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6656. });
  6657. self.html(html);
  6658. self.cmd.selection(true);
  6659. self.addBookmark();
  6660. });
  6661. });
  6662. /*******************************************************************************
  6663. * KindEditor - WYSIWYG HTML Editor for Internet
  6664. * Copyright (C) 2006-2011 kindsoft.net
  6665. *
  6666. * @author Roddy <luolonghao@gmail.com>
  6667. * @site http://www.kindsoft.net/
  6668. * @licence http://www.kindsoft.net/license.php
  6669. *******************************************************************************/
  6670. KindEditor.plugin('code', function(K) {
  6671. var self = this, name = 'code';
  6672. self.clickToolbar(name, function() {
  6673. var lang = self.lang(name + '.'),
  6674. html = ['<div style="padding:10px 20px;">',
  6675. '<div class="ke-dialog-row">',
  6676. '<select class="ke-code-type">',
  6677. '<option value="js">JavaScript</option>',
  6678. '<option value="html">HTML</option>',
  6679. '<option value="css">CSS</option>',
  6680. '<option value="php">PHP</option>',
  6681. '<option value="pl">Perl</option>',
  6682. '<option value="py">Python</option>',
  6683. '<option value="rb">Ruby</option>',
  6684. '<option value="java">Java</option>',
  6685. '<option value="vb">ASP/VB</option>',
  6686. '<option value="cpp">C/C++</option>',
  6687. '<option value="cs">C#</option>',
  6688. '<option value="xml">XML</option>',
  6689. '<option value="bsh">Shell</option>',
  6690. '<option value="">Other</option>',
  6691. '</select>',
  6692. '</div>',
  6693. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6694. '</div>'].join(''),
  6695. dialog = self.createDialog({
  6696. name : name,
  6697. width : 450,
  6698. title : self.lang(name),
  6699. body : html,
  6700. yesBtn : {
  6701. name : self.lang('yes'),
  6702. click : function(e) {
  6703. var type = K('.ke-code-type', dialog.div).val(),
  6704. code = textarea.val(),
  6705. cls = type === '' ? '' : ' lang-' + type,
  6706. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6707. if (K.trim(code) === '') {
  6708. alert(lang.pleaseInput);
  6709. textarea[0].focus();
  6710. return;
  6711. }
  6712. self.insertHtml(html).hideDialog().focus();
  6713. }
  6714. }
  6715. }),
  6716. textarea = K('textarea', dialog.div);
  6717. textarea[0].focus();
  6718. });
  6719. });
  6720. /*******************************************************************************
  6721. * KindEditor - WYSIWYG HTML Editor for Internet
  6722. * Copyright (C) 2006-2011 kindsoft.net
  6723. *
  6724. * @author Roddy <luolonghao@gmail.com>
  6725. * @site http://www.kindsoft.net/
  6726. * @licence http://www.kindsoft.net/license.php
  6727. *******************************************************************************/
  6728. KindEditor.plugin('emoticons', function(K) {
  6729. var self = this, name = 'emoticons',
  6730. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6731. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6732. currentPageNum = 1;
  6733. self.clickToolbar(name, function() {
  6734. var rows = 5, cols = 9, total = 135, startNum = 0,
  6735. cells = rows * cols, pages = Math.ceil(total / cells),
  6736. colsHalf = Math.floor(cols / 2),
  6737. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6738. elements = [],
  6739. menu = self.createMenu({
  6740. name : name,
  6741. beforeRemove : function() {
  6742. removeEvent();
  6743. }
  6744. });
  6745. menu.div.append(wrapperDiv);
  6746. var previewDiv, previewImg;
  6747. if (allowPreview) {
  6748. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6749. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6750. wrapperDiv.append(previewDiv);
  6751. previewDiv.append(previewImg);
  6752. }
  6753. function bindCellEvent(cell, j, num) {
  6754. if (previewDiv) {
  6755. cell.mouseover(function() {
  6756. if (j > colsHalf) {
  6757. previewDiv.css('left', 0);
  6758. previewDiv.css('right', '');
  6759. } else {
  6760. previewDiv.css('left', '');
  6761. previewDiv.css('right', 0);
  6762. }
  6763. previewImg.attr('src', path + num + '.gif');
  6764. K(this).addClass('ke-on');
  6765. });
  6766. } else {
  6767. cell.mouseover(function() {
  6768. K(this).addClass('ke-on');
  6769. });
  6770. }
  6771. cell.mouseout(function() {
  6772. K(this).removeClass('ke-on');
  6773. });
  6774. cell.click(function(e) {
  6775. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6776. e.stop();
  6777. });
  6778. }
  6779. function createEmoticonsTable(pageNum, parentDiv) {
  6780. var table = document.createElement('table');
  6781. parentDiv.append(table);
  6782. if (previewDiv) {
  6783. K(table).mouseover(function() {
  6784. previewDiv.show('block');
  6785. });
  6786. K(table).mouseout(function() {
  6787. previewDiv.hide();
  6788. });
  6789. elements.push(K(table));
  6790. }
  6791. table.className = 'ke-table';
  6792. table.cellPadding = 0;
  6793. table.cellSpacing = 0;
  6794. table.border = 0;
  6795. var num = (pageNum - 1) * cells + startNum;
  6796. for (var i = 0; i < rows; i++) {
  6797. var row = table.insertRow(i);
  6798. for (var j = 0; j < cols; j++) {
  6799. var cell = K(row.insertCell(j));
  6800. cell.addClass('ke-cell');
  6801. bindCellEvent(cell, j, num);
  6802. var span = K('<span class="ke-img"></span>')
  6803. .css('background-position', '-' + (24 * num) + 'px 0px')
  6804. .css('background-image', 'url(' + path + 'static.gif)');
  6805. cell.append(span);
  6806. elements.push(cell);
  6807. num++;
  6808. }
  6809. }
  6810. return table;
  6811. }
  6812. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6813. function removeEvent() {
  6814. K.each(elements, function() {
  6815. this.unbind();
  6816. });
  6817. }
  6818. var pageDiv;
  6819. function bindPageEvent(el, pageNum) {
  6820. el.click(function(e) {
  6821. removeEvent();
  6822. table.parentNode.removeChild(table);
  6823. pageDiv.remove();
  6824. table = createEmoticonsTable(pageNum, wrapperDiv);
  6825. createPageTable(pageNum);
  6826. currentPageNum = pageNum;
  6827. e.stop();
  6828. });
  6829. }
  6830. function createPageTable(currentPageNum) {
  6831. pageDiv = K('<div class="ke-page"></div>');
  6832. wrapperDiv.append(pageDiv);
  6833. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6834. if (currentPageNum !== pageNum) {
  6835. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6836. bindPageEvent(a, pageNum);
  6837. pageDiv.append(a);
  6838. elements.push(a);
  6839. } else {
  6840. pageDiv.append(K('@[' + pageNum + ']'));
  6841. }
  6842. pageDiv.append(K('@&nbsp;'));
  6843. }
  6844. }
  6845. createPageTable(currentPageNum);
  6846. });
  6847. });
  6848. /*******************************************************************************
  6849. * KindEditor - WYSIWYG HTML Editor for Internet
  6850. * Copyright (C) 2006-2011 kindsoft.net
  6851. *
  6852. * @author Roddy <luolonghao@gmail.com>
  6853. * @site http://www.kindsoft.net/
  6854. * @licence http://www.kindsoft.net/license.php
  6855. *******************************************************************************/
  6856. KindEditor.plugin('filemanager', function(K) {
  6857. var self = this, name = 'filemanager',
  6858. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6859. imgPath = self.pluginsPath + name + '/images/',
  6860. lang = self.lang(name + '.');
  6861. function makeFileTitle(filename, filesize, datetime) {
  6862. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6863. }
  6864. function bindTitle(el, data) {
  6865. if (data.is_dir) {
  6866. el.attr('title', data.filename);
  6867. } else {
  6868. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6869. }
  6870. }
  6871. self.plugin.filemanagerDialog = function(options) {
  6872. var width = K.undef(options.width, 650),
  6873. height = K.undef(options.height, 510),
  6874. dirName = K.undef(options.dirName, ''),
  6875. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6876. clickFn = options.clickFn;
  6877. var html = [
  6878. '<div style="padding:10px 20px;">',
  6879. '<div class="ke-plugin-filemanager-header">',
  6880. '<div class="ke-left">',
  6881. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6882. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6883. '</div>',
  6884. '<div class="ke-right">',
  6885. '标签 <input type="text" style="width:100px;" value="" name="viewTag">',
  6886. '分类 <select class="ke-inline-block" name="viewCate">',
  6887. '',
  6888. '</select> ',
  6889. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6890. '<option value="VIEW">' + lang.viewImage + '</option>',
  6891. '<option value="LIST">' + lang.listImage + '</option>',
  6892. '</select> ',
  6893. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6894. '<option value="NAME">' + lang.fileName + '</option>',
  6895. '<option value="SIZE">' + lang.fileSize + '</option>',
  6896. '<option value="TYPE">' + lang.fileType + '</option>',
  6897. '</select>',
  6898. '</div>',
  6899. '<div class="ke-clearfix"></div>',
  6900. '</div>',
  6901. '<div class="ke-plugin-filemanager-body"></div>',
  6902. '</div>'
  6903. ].join('');
  6904. var dialog = self.createDialog({
  6905. name : name,
  6906. width : width,
  6907. height : height,
  6908. title : self.lang(name),
  6909. body : html
  6910. }),
  6911. div = dialog.div,
  6912. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6913. moveupImg = K('[name="moveupImg"]', div),
  6914. moveupLink = K('[name="moveupLink"]', div),
  6915. viewServerBtn = K('[name="viewServer"]', div),
  6916. viewCateBox = K('[name="viewCate"]', div),
  6917. viewTagBox = K('[name="viewTag"]', div),
  6918. viewTypeBox = K('[name="viewType"]', div),
  6919. orderTypeBox = K('[name="orderType"]', div);
  6920. function reloadPage(path, order, func, cate, tag) {
  6921. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6922. if (cate) {
  6923. param += '&cate=' + cate;
  6924. }
  6925. if (tag) {
  6926. param += '&tag=' + tag;
  6927. }
  6928. dialog.showLoading(self.lang('ajaxLoading'));
  6929. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6930. dialog.hideLoading();
  6931. func(data);
  6932. });
  6933. }
  6934. var elList = [];
  6935. function bindEvent(el, result, data, createFunc) {
  6936. var fileUrl = K.formatUrl(result.current_url + data.file, 'absolute'),
  6937. dirPath = encodeURIComponent(result.current_dir_path + data.path + '/');
  6938. if (data.is_dir) {
  6939. el.click(function(e) {
  6940. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6941. });
  6942. } else if (data.is_photo) {
  6943. el.click(function(e) {
  6944. clickFn.call(this, fileUrl, data.file);
  6945. });
  6946. } else {
  6947. el.click(function(e) {
  6948. clickFn.call(this, fileUrl, data.file);
  6949. });
  6950. }
  6951. elList.push(el);
  6952. }
  6953. function createCommon(result, createFunc) {
  6954. K.each(elList, function() {
  6955. this.unbind();
  6956. });
  6957. moveupLink.unbind();
  6958. viewTypeBox.unbind();
  6959. orderTypeBox.unbind();
  6960. if (result.current_dir_path) {
  6961. moveupLink.click(function(e) {
  6962. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6963. });
  6964. }
  6965. function changeFunc() {
  6966. if (viewTypeBox.val() == 'VIEW') {
  6967. reloadPage(result.current_dir_path, orderTypeBox.val(), createView, viewCateBox.val(), viewTagBox.val());
  6968. } else {
  6969. reloadPage(result.current_dir_path, orderTypeBox.val(), createList, viewCateBox.val(), viewTagBox.val());
  6970. }
  6971. }
  6972. viewTypeBox.change(changeFunc);
  6973. orderTypeBox.change(changeFunc);
  6974. viewCateBox.change(changeFunc);
  6975. bodyDiv.html('');
  6976. }
  6977. function createList(result) {
  6978. createCommon(result, createList);
  6979. var table = document.createElement('table');
  6980. table.className = 'ke-table';
  6981. table.cellPadding = 0;
  6982. table.cellSpacing = 0;
  6983. table.border = 0;
  6984. bodyDiv.append(table);
  6985. var fileList = result.file_list;
  6986. for (var i = 0, len = fileList.length; i < len; i++) {
  6987. var data = fileList[i], row = K(table.insertRow(i));
  6988. row.mouseover(function(e) {
  6989. K(this).addClass('ke-on');
  6990. })
  6991. .mouseout(function(e) {
  6992. K(this).removeClass('ke-on');
  6993. });
  6994. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6995. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6996. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6997. if (!data.is_dir || data.has_file) {
  6998. row.css('cursor', 'pointer');
  6999. cell0.attr('title', data.filename);
  7000. bindEvent(cell0, result, data, createList);
  7001. } else {
  7002. cell0.attr('title', lang.emptyFolder);
  7003. }
  7004. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  7005. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  7006. }
  7007. }
  7008. function createView(result) {
  7009. createCommon(result, createView);
  7010. var fileList = result.file_list;
  7011. for (var i = 0, len = fileList.length; i < len; i++) {
  7012. var data = fileList[i],
  7013. div = K('<div class="ke-inline-block ke-item"></div>');
  7014. bodyDiv.append(div);
  7015. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7016. .mouseover(function(e) {
  7017. K(this).addClass('ke-on');
  7018. })
  7019. .mouseout(function(e) {
  7020. K(this).removeClass('ke-on');
  7021. });
  7022. div.append(photoDiv);
  7023. var fileUrl = result.current_url + data.file,
  7024. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7025. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7026. if (!data.is_dir || data.has_file) {
  7027. photoDiv.css('cursor', 'pointer');
  7028. bindTitle(photoDiv, data);
  7029. bindEvent(photoDiv, result, data, createView);
  7030. } else {
  7031. photoDiv.attr('title', lang.emptyFolder);
  7032. }
  7033. photoDiv.append(img);
  7034. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7035. }
  7036. }
  7037. viewTypeBox.val(viewType);
  7038. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7039. return dialog;
  7040. }
  7041. });
  7042. /*******************************************************************************
  7043. * KindEditor - WYSIWYG HTML Editor for Internet
  7044. * Copyright (C) 2006-2011 kindsoft.net
  7045. *
  7046. * @author Roddy <luolonghao@gmail.com>
  7047. * @site http://www.kindsoft.net/
  7048. * @licence http://www.kindsoft.net/license.php
  7049. *******************************************************************************/
  7050. KindEditor.plugin('flash', function(K) {
  7051. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7052. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7053. allowFileManager = K.undef(self.allowFileManager, false),
  7054. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7055. extraParams = K.undef(self.extraFileUploadParams, {}),
  7056. filePostName = K.undef(self.filePostName, 'imgFile'),
  7057. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7058. self.plugin.flash = {
  7059. edit : function() {
  7060. var html = [
  7061. '<div style="padding:20px;">',
  7062. '<div class="ke-dialog-row">',
  7063. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7064. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7065. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7066. '<span class="ke-button-common ke-button-outer">',
  7067. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7068. '</span>',
  7069. '</div>',
  7070. '<div class="ke-dialog-row">',
  7071. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7072. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7073. '</div>',
  7074. '<div class="ke-dialog-row">',
  7075. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7076. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7077. '</div>',
  7078. '</div>'
  7079. ].join('');
  7080. var dialog = self.createDialog({
  7081. name : name,
  7082. width : 450,
  7083. title : self.lang(name),
  7084. body : html,
  7085. yesBtn : {
  7086. name : self.lang('yes'),
  7087. click : function(e) {
  7088. var url = K.trim(urlBox.val()),
  7089. width = widthBox.val(),
  7090. height = heightBox.val();
  7091. if (url == 'http://' || K.invalidUrl(url)) {
  7092. alert(self.lang('invalidUrl'));
  7093. urlBox[0].focus();
  7094. return;
  7095. }
  7096. if (!/^\d*$/.test(width)) {
  7097. alert(self.lang('invalidWidth'));
  7098. widthBox[0].focus();
  7099. return;
  7100. }
  7101. if (!/^\d*$/.test(height)) {
  7102. alert(self.lang('invalidHeight'));
  7103. heightBox[0].focus();
  7104. return;
  7105. }
  7106. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7107. src : url,
  7108. type : K.mediaType('.swf'),
  7109. width : width,
  7110. height : height,
  7111. quality : 'high'
  7112. });
  7113. self.insertHtml(html).hideDialog().focus();
  7114. }
  7115. }
  7116. }),
  7117. div = dialog.div,
  7118. urlBox = K('[name="url"]', div),
  7119. viewServerBtn = K('[name="viewServer"]', div),
  7120. widthBox = K('[name="width"]', div),
  7121. heightBox = K('[name="height"]', div);
  7122. urlBox.val('http://');
  7123. if (allowFlashUpload) {
  7124. var uploadbutton = K.uploadbutton({
  7125. button : K('.ke-upload-button', div)[0],
  7126. fieldName : filePostName,
  7127. extraParams : extraParams,
  7128. url : K.addParam(uploadJson, 'dir=flash'),
  7129. afterUpload : function(data) {
  7130. dialog.hideLoading();
  7131. if (data.error === 0) {
  7132. var url = data.url;
  7133. if (formatUploadUrl) {
  7134. url = K.formatUrl(url, 'absolute');
  7135. }
  7136. urlBox.val(url);
  7137. if (self.afterUpload) {
  7138. self.afterUpload.call(self, url, data, name);
  7139. }
  7140. alert(self.lang('uploadSuccess'));
  7141. } else {
  7142. alert(data.message);
  7143. }
  7144. },
  7145. afterError : function(html) {
  7146. dialog.hideLoading();
  7147. self.errorDialog(html);
  7148. }
  7149. });
  7150. uploadbutton.fileBox.change(function(e) {
  7151. dialog.showLoading(self.lang('uploadLoading'));
  7152. uploadbutton.submit();
  7153. });
  7154. } else {
  7155. K('.ke-upload-button', div).hide();
  7156. }
  7157. if (allowFileManager) {
  7158. viewServerBtn.click(function(e) {
  7159. var clickFn = function(url, title, id) {
  7160. K('[name="url"]', div).val(url);
  7161. if (self.afterSelectFile) {
  7162. self.afterSelectFile.call(self, url);
  7163. }
  7164. };
  7165. var cur = K('[name="url"]', div).val();
  7166. editorShowUpload(cur, self.fileManagerJson, 'flash库', clickFn, this);
  7167. /*
  7168. self.loadPlugin('filemanager', function() {
  7169. self.plugin.filemanagerDialog({
  7170. viewType : 'LIST',
  7171. dirName : 'flash',
  7172. clickFn : function(url, title) {
  7173. if (self.dialogs.length > 1) {
  7174. K('[name="url"]', div).val(url);
  7175. if (self.afterSelectFile) {
  7176. self.afterSelectFile.call(self, url);
  7177. }
  7178. self.hideDialog();
  7179. }
  7180. }
  7181. });
  7182. });
  7183. */
  7184. });
  7185. } else {
  7186. viewServerBtn.hide();
  7187. }
  7188. var img = self.plugin.getSelectedFlash();
  7189. if (img) {
  7190. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7191. urlBox.val(attrs.src);
  7192. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7193. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7194. }
  7195. urlBox[0].focus();
  7196. urlBox[0].select();
  7197. },
  7198. 'delete' : function() {
  7199. self.plugin.getSelectedFlash().remove();
  7200. self.addBookmark();
  7201. }
  7202. };
  7203. self.clickToolbar(name, self.plugin.flash.edit);
  7204. });
  7205. /*******************************************************************************
  7206. * KindEditor - WYSIWYG HTML Editor for Internet
  7207. * Copyright (C) 2006-2011 kindsoft.net
  7208. *
  7209. * @author Roddy <luolonghao@gmail.com>
  7210. * @site http://www.kindsoft.net/
  7211. * @licence http://www.kindsoft.net/license.php
  7212. *******************************************************************************/
  7213. KindEditor.plugin('image', function(K) {
  7214. var self = this, name = 'image',
  7215. allowImageUpload = K.undef(self.allowImageUpload, true),
  7216. allowImageRemote = K.undef(self.allowImageRemote, true),
  7217. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7218. allowFileManager = K.undef(self.allowFileManager, false),
  7219. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7220. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7221. imgPath = self.pluginsPath + 'image/images/',
  7222. extraParams = K.undef(self.extraFileUploadParams, {}),
  7223. filePostName = K.undef(self.filePostName, 'imgFile'),
  7224. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7225. lang = self.lang(name + '.');
  7226. self.plugin.imageDialog = function(options) {
  7227. var imageUrl = options.imageUrl,
  7228. imageWidth = K.undef(options.imageWidth, ''),
  7229. imageHeight = K.undef(options.imageHeight, ''),
  7230. imageTitle = K.undef(options.imageTitle, ''),
  7231. imageAlign = K.undef(options.imageAlign, ''),
  7232. showRemote = K.undef(options.showRemote, true),
  7233. showLocal = K.undef(options.showLocal, true),
  7234. tabIndex = K.undef(options.tabIndex, 0),
  7235. clickFn = options.clickFn;
  7236. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7237. var hiddenElements = [];
  7238. for(var k in extraParams){
  7239. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7240. }
  7241. var html = [
  7242. '<div style="padding:20px;">',
  7243. '<div class="tabs"></div>',
  7244. '<div class="tab1" style="display:none;">',
  7245. '<div class="ke-dialog-row">',
  7246. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7247. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7248. '<span class="ke-button-common ke-button-outer">',
  7249. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7250. '</span>',
  7251. '</div>',
  7252. '<div class="ke-dialog-row">',
  7253. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7254. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7255. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7256. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7257. '</div>',
  7258. '<div class="ke-dialog-row">',
  7259. '<label style="width:60px;">' + lang.align + '</label>',
  7260. '<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="" />',
  7261. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7262. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7263. '</div>',
  7264. '<div class="ke-dialog-row">',
  7265. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7266. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7267. '</div>',
  7268. '</div>',
  7269. '<div class="tab2" style="display:none;">',
  7270. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7271. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7272. '<div class="ke-dialog-row">',
  7273. hiddenElements.join(''),
  7274. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7275. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7276. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7277. '</div>',
  7278. '</form>',
  7279. '</div>',
  7280. '</div>'
  7281. ].join('');
  7282. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7283. dialogHeight = showLocal && showRemote ? 300 : 250;
  7284. var dialog = self.createDialog({
  7285. name : name,
  7286. width : dialogWidth,
  7287. height : dialogHeight,
  7288. title : self.lang(name),
  7289. body : html,
  7290. yesBtn : {
  7291. name : self.lang('yes'),
  7292. click : function(e) {
  7293. if (dialog.isLoading) {
  7294. return;
  7295. }
  7296. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7297. if (uploadbutton.fileBox.val() == '') {
  7298. alert(self.lang('pleaseSelectFile'));
  7299. return;
  7300. }
  7301. dialog.showLoading(self.lang('uploadLoading'));
  7302. uploadbutton.submit();
  7303. localUrlBox.val('');
  7304. return;
  7305. }
  7306. var url = K.trim(urlBox.val()),
  7307. width = widthBox.val(),
  7308. height = heightBox.val(),
  7309. title = titleBox.val(),
  7310. align = '';
  7311. alignBox.each(function() {
  7312. if (this.checked) {
  7313. align = this.value;
  7314. return false;
  7315. }
  7316. });
  7317. if (url == 'http://' || K.invalidUrl(url)) {
  7318. alert(self.lang('invalidUrl'));
  7319. urlBox[0].focus();
  7320. return;
  7321. }
  7322. if (!/^\d*$/.test(width)) {
  7323. alert(self.lang('invalidWidth'));
  7324. widthBox[0].focus();
  7325. return;
  7326. }
  7327. if (!/^\d*$/.test(height)) {
  7328. alert(self.lang('invalidHeight'));
  7329. heightBox[0].focus();
  7330. return;
  7331. }
  7332. clickFn.call(self, url, title, width, height, 0, align);
  7333. }
  7334. },
  7335. beforeRemove : function() {
  7336. viewServerBtn.unbind();
  7337. widthBox.unbind();
  7338. heightBox.unbind();
  7339. refreshBtn.unbind();
  7340. }
  7341. }),
  7342. div = dialog.div;
  7343. var urlBox = K('[name="url"]', div),
  7344. localUrlBox = K('[name="localUrl"]', div),
  7345. viewServerBtn = K('[name="viewServer"]', div),
  7346. widthBox = K('.tab1 [name="width"]', div),
  7347. heightBox = K('.tab1 [name="height"]', div),
  7348. refreshBtn = K('.ke-refresh-btn', div),
  7349. titleBox = K('.tab1 [name="title"]', div),
  7350. alignBox = K('.tab1 [name="align"]', div);
  7351. var tabs;
  7352. if (showRemote && showLocal) {
  7353. tabs = K.tabs({
  7354. src : K('.tabs', div),
  7355. afterSelect : function(i) {}
  7356. });
  7357. tabs.add({
  7358. title : lang.remoteImage,
  7359. panel : K('.tab1', div)
  7360. });
  7361. tabs.add({
  7362. title : lang.localImage,
  7363. panel : K('.tab2', div)
  7364. });
  7365. tabs.select(1);
  7366. } else if (showRemote) {
  7367. K('.tab1', div).show();
  7368. } else if (showLocal) {
  7369. K('.tab2', div).show();
  7370. }
  7371. var uploadbutton = K.uploadbutton({
  7372. button : K('.ke-upload-button', div)[0],
  7373. fieldName : filePostName,
  7374. form : K('.ke-form', div),
  7375. target : target,
  7376. width: 60,
  7377. afterUpload : function(data) {
  7378. dialog.hideLoading();
  7379. if (data.error === 0) {
  7380. var url = data.url;
  7381. if (formatUploadUrl) {
  7382. url = K.formatUrl(url, 'absolute');
  7383. }
  7384. if (self.afterUpload) {
  7385. self.afterUpload.call(self, url, data, name);
  7386. }
  7387. if (!fillDescAfterUploadImage) {
  7388. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7389. } else {
  7390. K(".ke-dialog-row #remoteUrl", div).val(url);
  7391. K(".ke-tabs-li", div)[0].click();
  7392. K(".ke-refresh-btn", div).click();
  7393. }
  7394. } else {
  7395. alert(data.message);
  7396. }
  7397. },
  7398. afterError : function(html) {
  7399. dialog.hideLoading();
  7400. self.errorDialog(html);
  7401. }
  7402. });
  7403. uploadbutton.fileBox.change(function(e) {
  7404. localUrlBox.val(uploadbutton.fileBox.val());
  7405. });
  7406. if (allowFileManager) {
  7407. viewServerBtn.click(function(e) {
  7408. //clickFn.call(this, fileUrl, data.file);
  7409. var clickFn = function(url, title, id) {
  7410. K('[name="url"]', div).val(url);
  7411. if (self.afterSelectFile) {
  7412. self.afterSelectFile.call(self, url);
  7413. }
  7414. };
  7415. var cur = K('[name="url"]', div).val();
  7416. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  7417. /*
  7418. self.loadPlugin('filemanager', function() {
  7419. self.plugin.filemanagerDialog({
  7420. viewType : 'VIEW',
  7421. dirName : 'image',
  7422. clickFn : function(url, title) {
  7423. if (self.dialogs.length > 1) {
  7424. K('[name="url"]', div).val(url);
  7425. if (self.afterSelectFile) {
  7426. self.afterSelectFile.call(self, url);
  7427. }
  7428. self.hideDialog();
  7429. }
  7430. }
  7431. });
  7432. });
  7433. */
  7434. });
  7435. } else {
  7436. viewServerBtn.hide();
  7437. }
  7438. var originalWidth = 0, originalHeight = 0;
  7439. function setSize(width, height) {
  7440. widthBox.val(width);
  7441. heightBox.val(height);
  7442. originalWidth = width;
  7443. originalHeight = height;
  7444. }
  7445. refreshBtn.click(function(e) {
  7446. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7447. position : 'absolute',
  7448. visibility : 'hidden',
  7449. top : 0,
  7450. left : '-1000px'
  7451. });
  7452. tempImg.bind('load', function() {
  7453. setSize(tempImg.width(), tempImg.height());
  7454. tempImg.remove();
  7455. });
  7456. K(document.body).append(tempImg);
  7457. });
  7458. widthBox.change(function(e) {
  7459. if (originalWidth > 0) {
  7460. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7461. }
  7462. });
  7463. heightBox.change(function(e) {
  7464. if (originalHeight > 0) {
  7465. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7466. }
  7467. });
  7468. urlBox.val(options.imageUrl);
  7469. setSize(options.imageWidth, options.imageHeight);
  7470. titleBox.val(options.imageTitle);
  7471. alignBox.each(function() {
  7472. if (this.value === options.imageAlign) {
  7473. this.checked = true;
  7474. return false;
  7475. }
  7476. });
  7477. if (showRemote && tabIndex === 0) {
  7478. urlBox[0].focus();
  7479. urlBox[0].select();
  7480. }
  7481. return dialog;
  7482. };
  7483. self.plugin.image = {
  7484. edit : function() {
  7485. var img = self.plugin.getSelectedImage();
  7486. self.plugin.imageDialog({
  7487. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7488. imageWidth : img ? img.width() : '',
  7489. imageHeight : img ? img.height() : '',
  7490. imageTitle : img ? img.attr('title') : '',
  7491. imageAlign : img ? img.attr('align') : '',
  7492. showRemote : allowImageRemote,
  7493. showLocal : allowImageUpload,
  7494. tabIndex: img ? 0 : imageTabIndex,
  7495. clickFn : function(url, title, width, height, border, align) {
  7496. if (img) {
  7497. img.attr('src', url);
  7498. img.attr('data-ke-src', url);
  7499. img.attr('width', width);
  7500. img.attr('height', height);
  7501. img.attr('title', title);
  7502. img.attr('align', align);
  7503. img.attr('alt', title);
  7504. } else {
  7505. self.exec('insertimage', url, title, width, height, border, align);
  7506. }
  7507. setTimeout(function() {
  7508. self.hideDialog().focus();
  7509. }, 0);
  7510. }
  7511. });
  7512. },
  7513. 'delete' : function() {
  7514. var target = self.plugin.getSelectedImage();
  7515. if (target.parent().name == 'a') {
  7516. target = target.parent();
  7517. }
  7518. target.remove();
  7519. self.addBookmark();
  7520. }
  7521. };
  7522. self.clickToolbar(name, self.plugin.image.edit);
  7523. });
  7524. /*******************************************************************************
  7525. * KindEditor - WYSIWYG HTML Editor for Internet
  7526. * Copyright (C) 2006-2011 kindsoft.net
  7527. *
  7528. * @author Roddy <luolonghao@gmail.com>
  7529. * @site http://www.kindsoft.net/
  7530. * @licence http://www.kindsoft.net/license.php
  7531. *******************************************************************************/
  7532. KindEditor.plugin('insertfile', function(K) {
  7533. var self = this, name = 'insertfile',
  7534. allowFileUpload = K.undef(self.allowFileUpload, true),
  7535. allowFileManager = K.undef(self.allowFileManager, false),
  7536. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7537. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7538. extraParams = K.undef(self.extraFileUploadParams, {}),
  7539. filePostName = K.undef(self.filePostName, 'imgFile'),
  7540. lang = self.lang(name + '.');
  7541. self.plugin.fileDialog = function(options) {
  7542. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7543. fileTitle = K.undef(options.fileTitle, ''),
  7544. clickFn = options.clickFn;
  7545. var html = [
  7546. '<div style="padding:20px;">',
  7547. '<div class="ke-dialog-row">',
  7548. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7549. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7550. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7551. '<span class="ke-button-common ke-button-outer">',
  7552. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7553. '</span>',
  7554. '</div>',
  7555. '<div class="ke-dialog-row">',
  7556. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7557. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7558. '</div>',
  7559. '</form>',
  7560. '</div>'
  7561. ].join('');
  7562. var dialog = self.createDialog({
  7563. name : name,
  7564. width : 450,
  7565. title : self.lang(name),
  7566. body : html,
  7567. yesBtn : {
  7568. name : self.lang('yes'),
  7569. click : function(e) {
  7570. var url = K.trim(urlBox.val()),
  7571. title = titleBox.val();
  7572. if (url == 'http://' || K.invalidUrl(url)) {
  7573. alert(self.lang('invalidUrl'));
  7574. urlBox[0].focus();
  7575. return;
  7576. }
  7577. if (K.trim(title) === '') {
  7578. title = url;
  7579. }
  7580. clickFn.call(self, url, title);
  7581. }
  7582. }
  7583. }),
  7584. div = dialog.div;
  7585. var urlBox = K('[name="url"]', div),
  7586. viewServerBtn = K('[name="viewServer"]', div),
  7587. titleBox = K('[name="title"]', div);
  7588. if (allowFileUpload) {
  7589. var uploadbutton = K.uploadbutton({
  7590. button : K('.ke-upload-button', div)[0],
  7591. fieldName : filePostName,
  7592. url : K.addParam(uploadJson, 'dir=file'),
  7593. extraParams : extraParams,
  7594. afterUpload : function(data) {
  7595. dialog.hideLoading();
  7596. if (data.error === 0) {
  7597. var url = data.url;
  7598. if (formatUploadUrl) {
  7599. url = K.formatUrl(url, 'absolute');
  7600. }
  7601. urlBox.val(url);
  7602. if (self.afterUpload) {
  7603. self.afterUpload.call(self, url, data, name);
  7604. }
  7605. alert(self.lang('uploadSuccess'));
  7606. } else {
  7607. alert(data.message);
  7608. }
  7609. },
  7610. afterError : function(html) {
  7611. dialog.hideLoading();
  7612. self.errorDialog(html);
  7613. }
  7614. });
  7615. uploadbutton.fileBox.change(function(e) {
  7616. dialog.showLoading(self.lang('uploadLoading'));
  7617. uploadbutton.submit();
  7618. });
  7619. } else {
  7620. K('.ke-upload-button', div).hide();
  7621. }
  7622. if (allowFileManager) {
  7623. viewServerBtn.click(function(e) {
  7624. var clickFn = function(url, title, id) {
  7625. K('[name="url"]', div).val(url);
  7626. if (self.afterSelectFile) {
  7627. self.afterSelectFile.call(self, url);
  7628. }
  7629. };
  7630. var cur = K('[name="url"]', div).val();
  7631. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '文件库', clickFn, this);
  7632. /*
  7633. self.loadPlugin('filemanager', function() {
  7634. self.plugin.filemanagerDialog({
  7635. viewType : 'LIST',
  7636. dirName : 'file',
  7637. clickFn : function(url, title) {
  7638. if (self.dialogs.length > 1) {
  7639. self.hideDialog();
  7640. }
  7641. }
  7642. });
  7643. });
  7644. */
  7645. });
  7646. } else {
  7647. viewServerBtn.hide();
  7648. }
  7649. urlBox.val(fileUrl);
  7650. titleBox.val(fileTitle);
  7651. urlBox[0].focus();
  7652. urlBox[0].select();
  7653. };
  7654. self.clickToolbar(name, function() {
  7655. self.plugin.fileDialog({
  7656. clickFn : function(url, title) {
  7657. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7658. self.insertHtml(html).hideDialog().focus();
  7659. }
  7660. });
  7661. });
  7662. });
  7663. /*******************************************************************************
  7664. * KindEditor - WYSIWYG HTML Editor for Internet
  7665. * Copyright (C) 2006-2011 kindsoft.net
  7666. *
  7667. * @author Roddy <luolonghao@gmail.com>
  7668. * @site http://www.kindsoft.net/
  7669. * @licence http://www.kindsoft.net/license.php
  7670. *******************************************************************************/
  7671. KindEditor.plugin('lineheight', function(K) {
  7672. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7673. self.clickToolbar(name, function() {
  7674. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7675. if (commonNode) {
  7676. curVal = commonNode.css('line-height');
  7677. }
  7678. var menu = self.createMenu({
  7679. name : name,
  7680. width : 150
  7681. });
  7682. K.each(lang.lineHeight, function(i, row) {
  7683. K.each(row, function(key, val) {
  7684. menu.addItem({
  7685. title : val,
  7686. checked : curVal === key,
  7687. click : function() {
  7688. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7689. span : '.line-height=' + key
  7690. });
  7691. self.updateState();
  7692. self.addBookmark();
  7693. self.hideMenu();
  7694. }
  7695. });
  7696. });
  7697. });
  7698. });
  7699. });
  7700. /*******************************************************************************
  7701. * KindEditor - WYSIWYG HTML Editor for Internet
  7702. * Copyright (C) 2006-2011 kindsoft.net
  7703. *
  7704. * @author Roddy <luolonghao@gmail.com>
  7705. * @site http://www.kindsoft.net/
  7706. * @licence http://www.kindsoft.net/license.php
  7707. *******************************************************************************/
  7708. KindEditor.plugin('link', function(K) {
  7709. var self = this, name = 'link';
  7710. self.plugin.link = {
  7711. edit : function() {
  7712. var lang = self.lang(name + '.'),
  7713. html = '<div style="padding:20px;">' +
  7714. '<div class="ke-dialog-row">' +
  7715. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7716. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7717. '<div class="ke-dialog-row"">' +
  7718. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7719. '<select id="keType" name="type"></select>' +
  7720. '</div>' +
  7721. '</div>',
  7722. dialog = self.createDialog({
  7723. name : name,
  7724. width : 450,
  7725. title : self.lang(name),
  7726. body : html,
  7727. yesBtn : {
  7728. name : self.lang('yes'),
  7729. click : function(e) {
  7730. var url = K.trim(urlBox.val());
  7731. if (url == 'http://' || K.invalidUrl(url)) {
  7732. alert(self.lang('invalidUrl'));
  7733. urlBox[0].focus();
  7734. return;
  7735. }
  7736. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7737. }
  7738. }
  7739. }),
  7740. div = dialog.div,
  7741. urlBox = K('input[name="url"]', div),
  7742. typeBox = K('select[name="type"]', div);
  7743. urlBox.val('http://');
  7744. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7745. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7746. self.cmd.selection();
  7747. var a = self.plugin.getSelectedLink();
  7748. if (a) {
  7749. self.cmd.range.selectNode(a[0]);
  7750. self.cmd.select();
  7751. urlBox.val(a.attr('data-ke-src'));
  7752. typeBox.val(a.attr('target'));
  7753. }
  7754. urlBox[0].focus();
  7755. urlBox[0].select();
  7756. },
  7757. 'delete' : function() {
  7758. self.exec('unlink', null);
  7759. }
  7760. };
  7761. self.clickToolbar(name, self.plugin.link.edit);
  7762. });
  7763. /*******************************************************************************
  7764. * KindEditor - WYSIWYG HTML Editor for Internet
  7765. * Copyright (C) 2006-2011 kindsoft.net
  7766. *
  7767. * @author Roddy <luolonghao@gmail.com>
  7768. * @site http://www.kindsoft.net/
  7769. * @licence http://www.kindsoft.net/license.php
  7770. *******************************************************************************/
  7771. KindEditor.plugin('media', function(K) {
  7772. var self = this, name = 'media', lang = self.lang(name + '.'),
  7773. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7774. allowFileManager = K.undef(self.allowFileManager, false),
  7775. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7776. extraParams = K.undef(self.extraFileUploadParams, {}),
  7777. filePostName = K.undef(self.filePostName, 'imgFile'),
  7778. uploadJson = K.undef(self.uploadMediaJson, self.basePath + 'php/upload_json.php');
  7779. self.plugin.media = {
  7780. edit : function() {
  7781. var html = [
  7782. '<div style="padding:20px;">',
  7783. '<div class="ke-dialog-row">',
  7784. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7785. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7786. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7787. '<span class="ke-button-common ke-button-outer">',
  7788. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7789. '</span>',
  7790. '</div>',
  7791. '<div class="ke-dialog-row">',
  7792. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7793. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="450" maxlength="4" />',
  7794. '</div>',
  7795. '<div class="ke-dialog-row">',
  7796. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7797. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="100" maxlength="4" />',
  7798. '</div>',
  7799. '<div class="ke-dialog-row">',
  7800. '<label for="keAutostart">' + lang.autostart + '</label>',
  7801. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7802. '</div>',
  7803. '</div>'
  7804. ].join('');
  7805. var dialog = self.createDialog({
  7806. name : name,
  7807. width : 450,
  7808. height : 230,
  7809. title : self.lang(name),
  7810. body : html,
  7811. yesBtn : {
  7812. name : self.lang('yes'),
  7813. click : function(e) {
  7814. var url = K.trim(urlBox.val()),
  7815. width = widthBox.val(),
  7816. height = heightBox.val();
  7817. if (url == 'http://' || K.invalidUrl(url)) {
  7818. alert(self.lang('invalidUrl'));
  7819. urlBox[0].focus();
  7820. return;
  7821. }
  7822. if (!/^\d*$/.test(width)) {
  7823. alert(self.lang('invalidWidth'));
  7824. widthBox[0].focus();
  7825. return;
  7826. }
  7827. if (!/^\d*$/.test(height)) {
  7828. alert(self.lang('invalidHeight'));
  7829. heightBox[0].focus();
  7830. return;
  7831. }
  7832. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7833. src : url,
  7834. type : K.mediaType(url),
  7835. width : width,
  7836. height : height,
  7837. autostart : autostartBox[0].checked ? 'true' : 'false',
  7838. loop : 'true'
  7839. });
  7840. self.insertHtml(html).hideDialog().focus();
  7841. }
  7842. }
  7843. }),
  7844. div = dialog.div,
  7845. urlBox = K('[name="url"]', div),
  7846. viewServerBtn = K('[name="viewServer"]', div),
  7847. widthBox = K('[name="width"]', div),
  7848. heightBox = K('[name="height"]', div),
  7849. autostartBox = K('[name="autostart"]', div);
  7850. urlBox.val('http://');
  7851. if (allowMediaUpload) {
  7852. var uploadbutton = K.uploadbutton({
  7853. button : K('.ke-upload-button', div)[0],
  7854. fieldName : filePostName,
  7855. extraParams : extraParams,
  7856. url : K.addParam(uploadJson, 'dir=media'),
  7857. afterUpload : function(data) {
  7858. dialog.hideLoading();
  7859. if (data.error === 0) {
  7860. var url = data.url;
  7861. if (formatUploadUrl) {
  7862. url = K.formatUrl(url, 'absolute');
  7863. }
  7864. urlBox.val(url);
  7865. if (self.afterUpload) {
  7866. self.afterUpload.call(self, url, data, name);
  7867. }
  7868. alert(self.lang('uploadSuccess'));
  7869. } else {
  7870. alert(data.message);
  7871. }
  7872. },
  7873. afterError : function(html) {
  7874. dialog.hideLoading();
  7875. self.errorDialog(html);
  7876. }
  7877. });
  7878. uploadbutton.fileBox.change(function(e) {
  7879. dialog.showLoading(self.lang('uploadLoading'));
  7880. uploadbutton.submit();
  7881. });
  7882. } else {
  7883. K('.ke-upload-button', div).hide();
  7884. }
  7885. if (allowFileManager) {
  7886. viewServerBtn.click(function(e) {
  7887. var clickFn = function(url, title, id) {
  7888. K('[name="url"]', div).val(url);
  7889. if (self.afterSelectFile) {
  7890. self.afterSelectFile.call(self, url);
  7891. }
  7892. };
  7893. var cur = K('[name="url"]', div).val();
  7894. editorShowUpload(cur, self.fileManagerJson, '音频库', clickFn, this);
  7895. /*
  7896. self.loadPlugin('filemanager', function() {
  7897. self.plugin.filemanagerDialog({
  7898. viewType : 'LIST',
  7899. dirName : 'media',
  7900. clickFn : function(url, title) {
  7901. if (self.dialogs.length > 1) {
  7902. K('[name="url"]', div).val(url);
  7903. if (self.afterSelectFile) {
  7904. self.afterSelectFile.call(self, url);
  7905. }
  7906. self.hideDialog();
  7907. }
  7908. }
  7909. });
  7910. });
  7911. */
  7912. });
  7913. } else {
  7914. viewServerBtn.hide();
  7915. }
  7916. var img = self.plugin.getSelectedMedia();
  7917. if (img) {
  7918. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7919. urlBox.val(attrs.src);
  7920. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7921. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7922. autostartBox[0].checked = (attrs.autostart === 'true');
  7923. }
  7924. urlBox[0].focus();
  7925. urlBox[0].select();
  7926. },
  7927. 'delete' : function() {
  7928. self.plugin.getSelectedMedia().remove();
  7929. self.addBookmark();
  7930. }
  7931. };
  7932. self.clickToolbar(name, self.plugin.media.edit);
  7933. });
  7934. /*******************************************************************************
  7935. * KindEditor - WYSIWYG HTML Editor for Internet
  7936. * Copyright (C) 2006-2011 kindsoft.net
  7937. *
  7938. * @author Roddy <luolonghao@gmail.com>
  7939. * @site http://www.kindsoft.net/
  7940. * @licence http://www.kindsoft.net/license.php
  7941. *******************************************************************************/
  7942. (function(K) {
  7943. function KSWFUpload(options) {
  7944. this.init(options);
  7945. }
  7946. K.extend(KSWFUpload, {
  7947. init : function(options) {
  7948. var self = this;
  7949. options.afterError = options.afterError || function(str) {
  7950. alert(str);
  7951. };
  7952. self.options = options;
  7953. self.progressbars = {};
  7954. self.div = K(options.container).html([
  7955. '<div class="ke-swfupload">',
  7956. '<div class="ke-swfupload-top">',
  7957. '<div class="ke-inline-block ke-swfupload-button">',
  7958. '<input type="button" value="Browse" />',
  7959. '</div>',
  7960. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7961. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7962. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7963. '</span>',
  7964. '</div>',
  7965. '<div class="ke-swfupload-body"></div>',
  7966. '</div>'
  7967. ].join(''));
  7968. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7969. function showError(itemDiv, msg) {
  7970. K('.ke-status > div', itemDiv).hide();
  7971. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7972. }
  7973. var settings = {
  7974. debug : false,
  7975. upload_url : options.uploadUrl,
  7976. flash_url : options.flashUrl,
  7977. file_post_name : options.filePostName,
  7978. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7979. button_image_url: options.buttonImageUrl,
  7980. button_width: options.buttonWidth,
  7981. button_height: options.buttonHeight,
  7982. button_cursor : SWFUpload.CURSOR.HAND,
  7983. file_types : options.fileTypes,
  7984. file_types_description : options.fileTypesDesc,
  7985. file_upload_limit : options.fileUploadLimit,
  7986. file_size_limit : options.fileSizeLimit,
  7987. post_params : options.postParams,
  7988. file_queued_handler : function(file) {
  7989. file.url = self.options.fileIconUrl;
  7990. self.appendFile(file);
  7991. },
  7992. file_queue_error_handler : function(file, errorCode, message) {
  7993. var errorName = '';
  7994. switch (errorCode) {
  7995. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7996. errorName = options.queueLimitExceeded;
  7997. break;
  7998. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7999. errorName = options.fileExceedsSizeLimit;
  8000. break;
  8001. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  8002. errorName = options.zeroByteFile;
  8003. break;
  8004. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  8005. errorName = options.invalidFiletype;
  8006. break;
  8007. default:
  8008. errorName = options.unknownError;
  8009. break;
  8010. }
  8011. K.DEBUG && alert(errorName);
  8012. },
  8013. upload_start_handler : function(file) {
  8014. var self = this;
  8015. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  8016. K('.ke-status > div', itemDiv).hide();
  8017. K('.ke-progressbar', itemDiv).show();
  8018. },
  8019. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  8020. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  8021. var progressbar = self.progressbars[file.id];
  8022. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  8023. progressbar.percent.html(percent + '%');
  8024. },
  8025. upload_error_handler : function(file, errorCode, message) {
  8026. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  8027. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8028. showError(itemDiv, self.options.errorMessage);
  8029. }
  8030. },
  8031. upload_success_handler : function(file, serverData) {
  8032. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8033. var data = {};
  8034. try {
  8035. data = K.json(serverData);
  8036. } catch (e) {
  8037. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  8038. }
  8039. if (data.error !== 0) {
  8040. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  8041. return;
  8042. }
  8043. file.url = data.url;
  8044. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  8045. K('.ke-status > div', itemDiv).hide();
  8046. }
  8047. };
  8048. self.swfu = new SWFUpload(settings);
  8049. K('.ke-swfupload-startupload input', self.div).click(function() {
  8050. self.swfu.startUpload();
  8051. });
  8052. },
  8053. getUrlList : function() {
  8054. var list = [];
  8055. K('.ke-img', self.bodyDiv).each(function() {
  8056. var img = K(this);
  8057. var status = img.attr('data-status');
  8058. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8059. list.push(img.data('data'));
  8060. }
  8061. });
  8062. return list;
  8063. },
  8064. removeFile : function(fileId) {
  8065. var self = this;
  8066. self.swfu.cancelUpload(fileId);
  8067. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8068. K('.ke-photo', itemDiv).unbind();
  8069. K('.ke-delete', itemDiv).unbind();
  8070. itemDiv.remove();
  8071. },
  8072. removeFiles : function() {
  8073. var self = this;
  8074. K('.ke-item', self.bodyDiv).each(function() {
  8075. self.removeFile(K(this).attr('data-id'));
  8076. });
  8077. },
  8078. appendFile : function(file) {
  8079. var self = this;
  8080. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8081. self.bodyDiv.append(itemDiv);
  8082. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8083. .mouseover(function(e) {
  8084. K(this).addClass('ke-on');
  8085. })
  8086. .mouseout(function(e) {
  8087. K(this).removeClass('ke-on');
  8088. });
  8089. itemDiv.append(photoDiv);
  8090. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8091. photoDiv.append(img);
  8092. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8093. self.removeFile(file.id);
  8094. });
  8095. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8096. K(['<div class="ke-progressbar">',
  8097. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8098. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8099. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8100. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8101. self.progressbars[file.id] = {
  8102. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8103. percent : K('.ke-progressbar-percent', photoDiv)
  8104. };
  8105. },
  8106. remove : function() {
  8107. this.removeFiles();
  8108. this.swfu.destroy();
  8109. this.div.html('');
  8110. }
  8111. });
  8112. K.swfupload = function(element, options) {
  8113. return new KSWFUpload(element, options);
  8114. };
  8115. })(KindEditor);
  8116. KindEditor.plugin('multiimage', function(K) {
  8117. var self = this, name = 'multiimage',
  8118. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8119. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8120. imgPath = self.pluginsPath + 'multiimage/images/',
  8121. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8122. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8123. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8124. filePostName = K.undef(self.filePostName, 'imgFile'),
  8125. lang = self.lang(name + '.');
  8126. self.plugin.multiImageDialog = function(options) {
  8127. var clickFn = options.clickFn,
  8128. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8129. uploadDesc = '';
  8130. var html = [
  8131. '<div style="padding:20px;">',
  8132. '<div class="swfupload">',
  8133. '</div>',
  8134. '</div>'
  8135. ].join('');
  8136. var dialog = self.createDialog({
  8137. name : name,
  8138. width : 650,
  8139. height : 510,
  8140. title : self.lang(name),
  8141. body : html,
  8142. previewBtn : {
  8143. name : lang.insertAll,
  8144. click : function(e) {
  8145. clickFn.call(self, swfupload.getUrlList());
  8146. }
  8147. },
  8148. yesBtn : {
  8149. name : lang.clearAll,
  8150. click : function(e) {
  8151. swfupload.removeFiles();
  8152. }
  8153. },
  8154. beforeRemove : function() {
  8155. if (!K.IE || K.V <= 8) {
  8156. swfupload.remove();
  8157. }
  8158. }
  8159. }),
  8160. div = dialog.div;
  8161. var swfupload = K.swfupload({
  8162. container : K('.swfupload', div),
  8163. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8164. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8165. buttonHeight : 23,
  8166. fileIconUrl : imgPath + 'image.png',
  8167. uploadDesc : uploadDesc,
  8168. startButtonValue : lang.startUpload,
  8169. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8170. uploadMediaUrl : K.addParam(uploadMediaUrl, 'dir=media'),
  8171. flashUrl : imgPath + 'swfupload.swf',
  8172. filePostName : filePostName,
  8173. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8174. fileTypesDesc : 'Image Files',
  8175. fileUploadLimit : imageUploadLimit,
  8176. fileSizeLimit : imageSizeLimit,
  8177. postParams : K.undef(self.extraFileUploadParams, {}),
  8178. queueLimitExceeded : lang.queueLimitExceeded,
  8179. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8180. zeroByteFile : lang.zeroByteFile,
  8181. invalidFiletype : lang.invalidFiletype,
  8182. unknownError : lang.unknownError,
  8183. pendingMessage : lang.pending,
  8184. errorMessage : lang.uploadError,
  8185. afterError : function(html) {
  8186. self.errorDialog(html);
  8187. }
  8188. });
  8189. return dialog;
  8190. };
  8191. self.clickToolbar(name, function() {
  8192. self.plugin.multiImageDialog({
  8193. clickFn : function (urlList) {
  8194. if (urlList.length === 0) {
  8195. return;
  8196. }
  8197. K.each(urlList, function(i, data) {
  8198. if (self.afterUpload) {
  8199. self.afterUpload.call(self, data.url, data, 'multiimage');
  8200. }
  8201. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8202. });
  8203. setTimeout(function() {
  8204. self.hideDialog().focus();
  8205. }, 0);
  8206. }
  8207. });
  8208. });
  8209. });
  8210. /* ******************* */
  8211. /* Constructor & Init */
  8212. /* ******************* */
  8213. (function() {
  8214. window.SWFUpload = function (settings) {
  8215. this.initSWFUpload(settings);
  8216. };
  8217. SWFUpload.prototype.initSWFUpload = function (settings) {
  8218. try {
  8219. this.customSettings = {};
  8220. this.settings = settings;
  8221. this.eventQueue = [];
  8222. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8223. this.movieElement = null;
  8224. SWFUpload.instances[this.movieName] = this;
  8225. this.initSettings();
  8226. this.loadFlash();
  8227. this.displayDebugInfo();
  8228. } catch (ex) {
  8229. delete SWFUpload.instances[this.movieName];
  8230. throw ex;
  8231. }
  8232. };
  8233. /* *************** */
  8234. /* Static Members */
  8235. /* *************** */
  8236. SWFUpload.instances = {};
  8237. SWFUpload.movieCount = 0;
  8238. SWFUpload.version = "2.2.0 2009-03-25";
  8239. SWFUpload.QUEUE_ERROR = {
  8240. QUEUE_LIMIT_EXCEEDED : -100,
  8241. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8242. ZERO_BYTE_FILE : -120,
  8243. INVALID_FILETYPE : -130
  8244. };
  8245. SWFUpload.UPLOAD_ERROR = {
  8246. HTTP_ERROR : -200,
  8247. MISSING_UPLOAD_URL : -210,
  8248. IO_ERROR : -220,
  8249. SECURITY_ERROR : -230,
  8250. UPLOAD_LIMIT_EXCEEDED : -240,
  8251. UPLOAD_FAILED : -250,
  8252. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8253. FILE_VALIDATION_FAILED : -270,
  8254. FILE_CANCELLED : -280,
  8255. UPLOAD_STOPPED : -290
  8256. };
  8257. SWFUpload.FILE_STATUS = {
  8258. QUEUED : -1,
  8259. IN_PROGRESS : -2,
  8260. ERROR : -3,
  8261. COMPLETE : -4,
  8262. CANCELLED : -5
  8263. };
  8264. SWFUpload.BUTTON_ACTION = {
  8265. SELECT_FILE : -100,
  8266. SELECT_FILES : -110,
  8267. START_UPLOAD : -120
  8268. };
  8269. SWFUpload.CURSOR = {
  8270. ARROW : -1,
  8271. HAND : -2
  8272. };
  8273. SWFUpload.WINDOW_MODE = {
  8274. WINDOW : "window",
  8275. TRANSPARENT : "transparent",
  8276. OPAQUE : "opaque"
  8277. };
  8278. SWFUpload.completeURL = function(url) {
  8279. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8280. return url;
  8281. }
  8282. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8283. var indexSlash = window.location.pathname.lastIndexOf("/");
  8284. var path;
  8285. if (indexSlash <= 0) {
  8286. path = "/";
  8287. } else {
  8288. path = window.location.pathname.substr(0, indexSlash) + "/";
  8289. }
  8290. return /*currentURL +*/ path + url;
  8291. };
  8292. /* ******************** */
  8293. /* Instance Members */
  8294. /* ******************** */
  8295. SWFUpload.prototype.initSettings = function () {
  8296. this.ensureDefault = function (settingName, defaultValue) {
  8297. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8298. };
  8299. this.ensureDefault("upload_url", "");
  8300. this.ensureDefault("preserve_relative_urls", false);
  8301. this.ensureDefault("file_post_name", "Filedata");
  8302. this.ensureDefault("post_params", {});
  8303. this.ensureDefault("use_query_string", false);
  8304. this.ensureDefault("requeue_on_error", false);
  8305. this.ensureDefault("http_success", []);
  8306. this.ensureDefault("assume_success_timeout", 0);
  8307. this.ensureDefault("file_types", "*.*");
  8308. this.ensureDefault("file_types_description", "All Files");
  8309. this.ensureDefault("file_size_limit", 0);
  8310. this.ensureDefault("file_upload_limit", 0);
  8311. this.ensureDefault("file_queue_limit", 0);
  8312. this.ensureDefault("flash_url", "swfupload.swf");
  8313. this.ensureDefault("prevent_swf_caching", true);
  8314. this.ensureDefault("button_image_url", "");
  8315. this.ensureDefault("button_width", 1);
  8316. this.ensureDefault("button_height", 1);
  8317. this.ensureDefault("button_text", "");
  8318. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8319. this.ensureDefault("button_text_top_padding", 0);
  8320. this.ensureDefault("button_text_left_padding", 0);
  8321. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8322. this.ensureDefault("button_disabled", false);
  8323. this.ensureDefault("button_placeholder_id", "");
  8324. this.ensureDefault("button_placeholder", null);
  8325. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8326. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8327. this.ensureDefault("debug", false);
  8328. this.settings.debug_enabled = this.settings.debug;
  8329. this.settings.return_upload_start_handler = this.returnUploadStart;
  8330. this.ensureDefault("swfupload_loaded_handler", null);
  8331. this.ensureDefault("file_dialog_start_handler", null);
  8332. this.ensureDefault("file_queued_handler", null);
  8333. this.ensureDefault("file_queue_error_handler", null);
  8334. this.ensureDefault("file_dialog_complete_handler", null);
  8335. this.ensureDefault("upload_start_handler", null);
  8336. this.ensureDefault("upload_progress_handler", null);
  8337. this.ensureDefault("upload_error_handler", null);
  8338. this.ensureDefault("upload_success_handler", null);
  8339. this.ensureDefault("upload_complete_handler", null);
  8340. this.ensureDefault("debug_handler", this.debugMessage);
  8341. this.ensureDefault("custom_settings", {});
  8342. this.customSettings = this.settings.custom_settings;
  8343. if (!!this.settings.prevent_swf_caching) {
  8344. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8345. }
  8346. if (!this.settings.preserve_relative_urls) {
  8347. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8348. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8349. }
  8350. delete this.ensureDefault;
  8351. };
  8352. SWFUpload.prototype.loadFlash = function () {
  8353. var targetElement, tempParent;
  8354. if (document.getElementById(this.movieName) !== null) {
  8355. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8356. }
  8357. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8358. if (targetElement == undefined) {
  8359. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8360. }
  8361. tempParent = document.createElement("div");
  8362. tempParent.innerHTML = this.getFlashHTML();
  8363. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8364. if (window[this.movieName] == undefined) {
  8365. window[this.movieName] = this.getMovieElement();
  8366. }
  8367. };
  8368. SWFUpload.prototype.getFlashHTML = function () {
  8369. var classid = '';
  8370. if (KindEditor.IE && KindEditor.V > 8) {
  8371. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8372. }
  8373. 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">',
  8374. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8375. '<param name="movie" value="', this.settings.flash_url, '" />',
  8376. '<param name="quality" value="high" />',
  8377. '<param name="menu" value="false" />',
  8378. '<param name="allowScriptAccess" value="always" />',
  8379. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8380. '</object>'].join("");
  8381. };
  8382. SWFUpload.prototype.getFlashVars = function () {
  8383. var paramString = this.buildParamString();
  8384. var httpSuccessString = this.settings.http_success.join(",");
  8385. return ["movieName=", encodeURIComponent(this.movieName),
  8386. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8387. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8388. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8389. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8390. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8391. "&amp;params=", encodeURIComponent(paramString),
  8392. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8393. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8394. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8395. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8396. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8397. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8398. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8399. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8400. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8401. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8402. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8403. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8404. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8405. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8406. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8407. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8408. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8409. ].join("");
  8410. };
  8411. SWFUpload.prototype.getMovieElement = function () {
  8412. if (this.movieElement == undefined) {
  8413. this.movieElement = document.getElementById(this.movieName);
  8414. }
  8415. if (this.movieElement === null) {
  8416. throw "Could not find Flash element";
  8417. }
  8418. return this.movieElement;
  8419. };
  8420. SWFUpload.prototype.buildParamString = function () {
  8421. var postParams = this.settings.post_params;
  8422. var paramStringPairs = [];
  8423. if (typeof(postParams) === "object") {
  8424. for (var name in postParams) {
  8425. if (postParams.hasOwnProperty(name)) {
  8426. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8427. }
  8428. }
  8429. }
  8430. return paramStringPairs.join("&amp;");
  8431. };
  8432. SWFUpload.prototype.destroy = function () {
  8433. try {
  8434. this.cancelUpload(null, false);
  8435. var movieElement = null;
  8436. movieElement = this.getMovieElement();
  8437. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8438. for (var i in movieElement) {
  8439. try {
  8440. if (typeof(movieElement[i]) === "function") {
  8441. movieElement[i] = null;
  8442. }
  8443. } catch (ex1) {}
  8444. }
  8445. try {
  8446. movieElement.parentNode.removeChild(movieElement);
  8447. } catch (ex) {}
  8448. }
  8449. window[this.movieName] = null;
  8450. SWFUpload.instances[this.movieName] = null;
  8451. delete SWFUpload.instances[this.movieName];
  8452. this.movieElement = null;
  8453. this.settings = null;
  8454. this.customSettings = null;
  8455. this.eventQueue = null;
  8456. this.movieName = null;
  8457. return true;
  8458. } catch (ex2) {
  8459. return false;
  8460. }
  8461. };
  8462. SWFUpload.prototype.displayDebugInfo = function () {
  8463. this.debug(
  8464. [
  8465. "---SWFUpload Instance Info---\n",
  8466. "Version: ", SWFUpload.version, "\n",
  8467. "Movie Name: ", this.movieName, "\n",
  8468. "Settings:\n",
  8469. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8470. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8471. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8472. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8473. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8474. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8475. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8476. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8477. "\t", "file_types: ", this.settings.file_types, "\n",
  8478. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8479. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8480. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8481. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8482. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8483. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8484. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8485. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8486. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8487. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8488. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8489. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8490. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8491. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8492. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8493. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8494. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8495. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8496. "Event Handlers:\n",
  8497. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8498. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8499. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8500. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8501. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8502. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8503. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8504. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8505. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8506. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8507. ].join("")
  8508. );
  8509. };
  8510. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8511. the maintain v2 API compatibility
  8512. */
  8513. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8514. if (value == undefined) {
  8515. return (this.settings[name] = default_value);
  8516. } else {
  8517. return (this.settings[name] = value);
  8518. }
  8519. };
  8520. SWFUpload.prototype.getSetting = function (name) {
  8521. if (this.settings[name] != undefined) {
  8522. return this.settings[name];
  8523. }
  8524. return "";
  8525. };
  8526. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8527. argumentArray = argumentArray || [];
  8528. var movieElement = this.getMovieElement();
  8529. var returnValue, returnString;
  8530. try {
  8531. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8532. returnValue = eval(returnString);
  8533. } catch (ex) {
  8534. throw "Call to " + functionName + " failed";
  8535. }
  8536. if (returnValue != undefined && typeof returnValue.post === "object") {
  8537. returnValue = this.unescapeFilePostParams(returnValue);
  8538. }
  8539. return returnValue;
  8540. };
  8541. /* *****************************
  8542. -- Flash control methods --
  8543. Your UI should use these
  8544. to operate SWFUpload
  8545. ***************************** */
  8546. SWFUpload.prototype.selectFile = function () {
  8547. this.callFlash("SelectFile");
  8548. };
  8549. SWFUpload.prototype.selectFiles = function () {
  8550. this.callFlash("SelectFiles");
  8551. };
  8552. SWFUpload.prototype.startUpload = function (fileID) {
  8553. this.callFlash("StartUpload", [fileID]);
  8554. };
  8555. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8556. if (triggerErrorEvent !== false) {
  8557. triggerErrorEvent = true;
  8558. }
  8559. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8560. };
  8561. SWFUpload.prototype.stopUpload = function () {
  8562. this.callFlash("StopUpload");
  8563. };
  8564. /* ************************
  8565. * Settings methods
  8566. * These methods change the SWFUpload settings.
  8567. * SWFUpload settings should not be changed directly on the settings object
  8568. * since many of the settings need to be passed to Flash in order to take
  8569. * effect.
  8570. * *********************** */
  8571. SWFUpload.prototype.getStats = function () {
  8572. return this.callFlash("GetStats");
  8573. };
  8574. SWFUpload.prototype.setStats = function (statsObject) {
  8575. this.callFlash("SetStats", [statsObject]);
  8576. };
  8577. SWFUpload.prototype.getFile = function (fileID) {
  8578. if (typeof(fileID) === "number") {
  8579. return this.callFlash("GetFileByIndex", [fileID]);
  8580. } else {
  8581. return this.callFlash("GetFile", [fileID]);
  8582. }
  8583. };
  8584. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8585. return this.callFlash("AddFileParam", [fileID, name, value]);
  8586. };
  8587. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8588. this.callFlash("RemoveFileParam", [fileID, name]);
  8589. };
  8590. SWFUpload.prototype.setUploadURL = function (url) {
  8591. this.settings.upload_url = url.toString();
  8592. this.callFlash("SetUploadURL", [url]);
  8593. };
  8594. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8595. this.settings.post_params = paramsObject;
  8596. this.callFlash("SetPostParams", [paramsObject]);
  8597. };
  8598. SWFUpload.prototype.addPostParam = function (name, value) {
  8599. this.settings.post_params[name] = value;
  8600. this.callFlash("SetPostParams", [this.settings.post_params]);
  8601. };
  8602. SWFUpload.prototype.removePostParam = function (name) {
  8603. delete this.settings.post_params[name];
  8604. this.callFlash("SetPostParams", [this.settings.post_params]);
  8605. };
  8606. SWFUpload.prototype.setFileTypes = function (types, description) {
  8607. this.settings.file_types = types;
  8608. this.settings.file_types_description = description;
  8609. this.callFlash("SetFileTypes", [types, description]);
  8610. };
  8611. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8612. this.settings.file_size_limit = fileSizeLimit;
  8613. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8614. };
  8615. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8616. this.settings.file_upload_limit = fileUploadLimit;
  8617. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8618. };
  8619. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8620. this.settings.file_queue_limit = fileQueueLimit;
  8621. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8622. };
  8623. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8624. this.settings.file_post_name = filePostName;
  8625. this.callFlash("SetFilePostName", [filePostName]);
  8626. };
  8627. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8628. this.settings.use_query_string = useQueryString;
  8629. this.callFlash("SetUseQueryString", [useQueryString]);
  8630. };
  8631. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8632. this.settings.requeue_on_error = requeueOnError;
  8633. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8634. };
  8635. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8636. if (typeof http_status_codes === "string") {
  8637. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8638. }
  8639. this.settings.http_success = http_status_codes;
  8640. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8641. };
  8642. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8643. this.settings.assume_success_timeout = timeout_seconds;
  8644. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8645. };
  8646. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8647. this.settings.debug_enabled = debugEnabled;
  8648. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8649. };
  8650. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8651. if (buttonImageURL == undefined) {
  8652. buttonImageURL = "";
  8653. }
  8654. this.settings.button_image_url = buttonImageURL;
  8655. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8656. };
  8657. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8658. this.settings.button_width = width;
  8659. this.settings.button_height = height;
  8660. var movie = this.getMovieElement();
  8661. if (movie != undefined) {
  8662. movie.style.width = width + "px";
  8663. movie.style.height = height + "px";
  8664. }
  8665. this.callFlash("SetButtonDimensions", [width, height]);
  8666. };
  8667. SWFUpload.prototype.setButtonText = function (html) {
  8668. this.settings.button_text = html;
  8669. this.callFlash("SetButtonText", [html]);
  8670. };
  8671. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8672. this.settings.button_text_top_padding = top;
  8673. this.settings.button_text_left_padding = left;
  8674. this.callFlash("SetButtonTextPadding", [left, top]);
  8675. };
  8676. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8677. this.settings.button_text_style = css;
  8678. this.callFlash("SetButtonTextStyle", [css]);
  8679. };
  8680. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8681. this.settings.button_disabled = isDisabled;
  8682. this.callFlash("SetButtonDisabled", [isDisabled]);
  8683. };
  8684. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8685. this.settings.button_action = buttonAction;
  8686. this.callFlash("SetButtonAction", [buttonAction]);
  8687. };
  8688. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8689. this.settings.button_cursor = cursor;
  8690. this.callFlash("SetButtonCursor", [cursor]);
  8691. };
  8692. /* *******************************
  8693. Flash Event Interfaces
  8694. These functions are used by Flash to trigger the various
  8695. events.
  8696. All these functions a Private.
  8697. Because the ExternalInterface library is buggy the event calls
  8698. are added to a queue and the queue then executed by a setTimeout.
  8699. This ensures that events are executed in a determinate order and that
  8700. the ExternalInterface bugs are avoided.
  8701. ******************************* */
  8702. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8703. if (argumentArray == undefined) {
  8704. argumentArray = [];
  8705. } else if (!(argumentArray instanceof Array)) {
  8706. argumentArray = [argumentArray];
  8707. }
  8708. var self = this;
  8709. if (typeof this.settings[handlerName] === "function") {
  8710. this.eventQueue.push(function () {
  8711. this.settings[handlerName].apply(this, argumentArray);
  8712. });
  8713. setTimeout(function () {
  8714. self.executeNextEvent();
  8715. }, 0);
  8716. } else if (this.settings[handlerName] !== null) {
  8717. throw "Event handler " + handlerName + " is unknown or is not a function";
  8718. }
  8719. };
  8720. SWFUpload.prototype.executeNextEvent = function () {
  8721. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8722. if (typeof(f) === "function") {
  8723. f.apply(this);
  8724. }
  8725. };
  8726. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8727. var reg = /[$]([0-9a-f]{4})/i;
  8728. var unescapedPost = {};
  8729. var uk;
  8730. if (file != undefined) {
  8731. for (var k in file.post) {
  8732. if (file.post.hasOwnProperty(k)) {
  8733. uk = k;
  8734. var match;
  8735. while ((match = reg.exec(uk)) !== null) {
  8736. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8737. }
  8738. unescapedPost[uk] = file.post[k];
  8739. }
  8740. }
  8741. file.post = unescapedPost;
  8742. }
  8743. return file;
  8744. };
  8745. SWFUpload.prototype.testExternalInterface = function () {
  8746. try {
  8747. return this.callFlash("TestExternalInterface");
  8748. } catch (ex) {
  8749. return false;
  8750. }
  8751. };
  8752. SWFUpload.prototype.flashReady = function () {
  8753. var movieElement = this.getMovieElement();
  8754. if (!movieElement) {
  8755. this.debug("Flash called back ready but the flash movie can't be found.");
  8756. return;
  8757. }
  8758. this.cleanUp(movieElement);
  8759. this.queueEvent("swfupload_loaded_handler");
  8760. };
  8761. SWFUpload.prototype.cleanUp = function (movieElement) {
  8762. try {
  8763. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8764. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8765. for (var key in movieElement) {
  8766. try {
  8767. if (typeof(movieElement[key]) === "function") {
  8768. movieElement[key] = null;
  8769. }
  8770. } catch (ex) {
  8771. }
  8772. }
  8773. }
  8774. } catch (ex1) {
  8775. }
  8776. window["__flash__removeCallback"] = function (instance, name) {
  8777. try {
  8778. if (instance) {
  8779. instance[name] = null;
  8780. }
  8781. } catch (flashEx) {
  8782. }
  8783. };
  8784. };
  8785. /* This is a chance to do something before the browse window opens */
  8786. SWFUpload.prototype.fileDialogStart = function () {
  8787. this.queueEvent("file_dialog_start_handler");
  8788. };
  8789. /* Called when a file is successfully added to the queue. */
  8790. SWFUpload.prototype.fileQueued = function (file) {
  8791. file = this.unescapeFilePostParams(file);
  8792. this.queueEvent("file_queued_handler", file);
  8793. };
  8794. /* Handle errors that occur when an attempt to queue a file fails. */
  8795. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8796. file = this.unescapeFilePostParams(file);
  8797. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8798. };
  8799. /* Called after the file dialog has closed and the selected files have been queued.
  8800. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8801. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8802. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8803. };
  8804. SWFUpload.prototype.uploadStart = function (file) {
  8805. file = this.unescapeFilePostParams(file);
  8806. this.queueEvent("return_upload_start_handler", file);
  8807. };
  8808. SWFUpload.prototype.returnUploadStart = function (file) {
  8809. var returnValue;
  8810. if (typeof this.settings.upload_start_handler === "function") {
  8811. file = this.unescapeFilePostParams(file);
  8812. returnValue = this.settings.upload_start_handler.call(this, file);
  8813. } else if (this.settings.upload_start_handler != undefined) {
  8814. throw "upload_start_handler must be a function";
  8815. }
  8816. if (returnValue === undefined) {
  8817. returnValue = true;
  8818. }
  8819. returnValue = !!returnValue;
  8820. this.callFlash("ReturnUploadStart", [returnValue]);
  8821. };
  8822. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8823. file = this.unescapeFilePostParams(file);
  8824. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8825. };
  8826. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8827. file = this.unescapeFilePostParams(file);
  8828. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8829. };
  8830. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8831. file = this.unescapeFilePostParams(file);
  8832. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8833. };
  8834. SWFUpload.prototype.uploadComplete = function (file) {
  8835. file = this.unescapeFilePostParams(file);
  8836. this.queueEvent("upload_complete_handler", file);
  8837. };
  8838. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8839. internal debug console. You can override this event and have messages written where you want. */
  8840. SWFUpload.prototype.debug = function (message) {
  8841. this.queueEvent("debug_handler", message);
  8842. };
  8843. /* **********************************
  8844. Debug Console
  8845. The debug console is a self contained, in page location
  8846. for debug message to be sent. The Debug Console adds
  8847. itself to the body if necessary.
  8848. The console is automatically scrolled as messages appear.
  8849. If you are using your own debug handler or when you deploy to production and
  8850. have debug disabled you can remove these functions to reduce the file size
  8851. and complexity.
  8852. ********************************** */
  8853. SWFUpload.prototype.debugMessage = function (message) {
  8854. if (this.settings.debug) {
  8855. var exceptionMessage, exceptionValues = [];
  8856. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8857. for (var key in message) {
  8858. if (message.hasOwnProperty(key)) {
  8859. exceptionValues.push(key + ": " + message[key]);
  8860. }
  8861. }
  8862. exceptionMessage = exceptionValues.join("\n") || "";
  8863. exceptionValues = exceptionMessage.split("\n");
  8864. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8865. SWFUpload.Console.writeLine(exceptionMessage);
  8866. } else {
  8867. SWFUpload.Console.writeLine(message);
  8868. }
  8869. }
  8870. };
  8871. SWFUpload.Console = {};
  8872. SWFUpload.Console.writeLine = function (message) {
  8873. var console, documentForm;
  8874. try {
  8875. console = document.getElementById("SWFUpload_Console");
  8876. if (!console) {
  8877. documentForm = document.createElement("form");
  8878. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8879. console = document.createElement("textarea");
  8880. console.id = "SWFUpload_Console";
  8881. console.style.fontFamily = "monospace";
  8882. console.setAttribute("wrap", "off");
  8883. console.wrap = "off";
  8884. console.style.overflow = "auto";
  8885. console.style.width = "700px";
  8886. console.style.height = "350px";
  8887. console.style.margin = "5px";
  8888. documentForm.appendChild(console);
  8889. }
  8890. console.value += message + "\n";
  8891. console.scrollTop = console.scrollHeight - console.clientHeight;
  8892. } catch (ex) {
  8893. alert("Exception: " + ex.name + " Message: " + ex.message);
  8894. }
  8895. };
  8896. })();
  8897. (function() {
  8898. /*
  8899. Queue Plug-in
  8900. Features:
  8901. *Adds a cancelQueue() method for cancelling the entire queue.
  8902. *All queued files are uploaded when startUpload() is called.
  8903. *If false is returned from uploadComplete then the queue upload is stopped.
  8904. If false is not returned (strict comparison) then the queue upload is continued.
  8905. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8906. Set the event handler with the queue_complete_handler setting.
  8907. */
  8908. if (typeof(SWFUpload) === "function") {
  8909. SWFUpload.queue = {};
  8910. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8911. return function () {
  8912. if (typeof(oldInitSettings) === "function") {
  8913. oldInitSettings.call(this);
  8914. }
  8915. this.queueSettings = {};
  8916. this.queueSettings.queue_cancelled_flag = false;
  8917. this.queueSettings.queue_upload_count = 0;
  8918. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8919. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8920. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8921. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8922. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8923. };
  8924. })(SWFUpload.prototype.initSettings);
  8925. SWFUpload.prototype.startUpload = function (fileID) {
  8926. this.queueSettings.queue_cancelled_flag = false;
  8927. this.callFlash("StartUpload", [fileID]);
  8928. };
  8929. SWFUpload.prototype.cancelQueue = function () {
  8930. this.queueSettings.queue_cancelled_flag = true;
  8931. this.stopUpload();
  8932. var stats = this.getStats();
  8933. while (stats.files_queued > 0) {
  8934. this.cancelUpload();
  8935. stats = this.getStats();
  8936. }
  8937. };
  8938. SWFUpload.queue.uploadStartHandler = function (file) {
  8939. var returnValue;
  8940. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8941. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8942. }
  8943. returnValue = (returnValue === false) ? false : true;
  8944. this.queueSettings.queue_cancelled_flag = !returnValue;
  8945. return returnValue;
  8946. };
  8947. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8948. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8949. var continueUpload;
  8950. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8951. this.queueSettings.queue_upload_count++;
  8952. }
  8953. if (typeof(user_upload_complete_handler) === "function") {
  8954. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8955. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8956. continueUpload = false;
  8957. } else {
  8958. continueUpload = true;
  8959. }
  8960. if (continueUpload) {
  8961. var stats = this.getStats();
  8962. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8963. this.startUpload();
  8964. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8965. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8966. this.queueSettings.queue_upload_count = 0;
  8967. } else {
  8968. this.queueSettings.queue_cancelled_flag = false;
  8969. this.queueSettings.queue_upload_count = 0;
  8970. }
  8971. }
  8972. };
  8973. }
  8974. })();
  8975. /*******************************************************************************
  8976. * KindEditor - WYSIWYG HTML Editor for Internet
  8977. * Copyright (C) 2006-2011 kindsoft.net
  8978. *
  8979. * @author Roddy <luolonghao@gmail.com>
  8980. * @site http://www.kindsoft.net/
  8981. * @licence http://www.kindsoft.net/license.php
  8982. *******************************************************************************/
  8983. KindEditor.plugin('pagebreak', function(K) {
  8984. var self = this;
  8985. var name = 'pagebreak';
  8986. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8987. self.clickToolbar(name, function() {
  8988. var cmd = self.cmd, range = cmd.range;
  8989. self.focus();
  8990. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8991. self.insertHtml(pagebreakHtml + tail);
  8992. if (tail !== '') {
  8993. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8994. range.selectNodeContents(p[0]);
  8995. p.removeAttr('id');
  8996. cmd.select();
  8997. }
  8998. });
  8999. });
  9000. /*******************************************************************************
  9001. * KindEditor - WYSIWYG HTML Editor for Internet
  9002. * Copyright (C) 2006-2011 kindsoft.net
  9003. *
  9004. * @author Roddy <luolonghao@gmail.com>
  9005. * @site http://www.kindsoft.net/
  9006. * @licence http://www.kindsoft.net/license.php
  9007. *******************************************************************************/
  9008. KindEditor.plugin('plainpaste', function(K) {
  9009. var self = this, name = 'plainpaste';
  9010. self.clickToolbar(name, function() {
  9011. var lang = self.lang(name + '.'),
  9012. html = '<div style="padding:10px 20px;">' +
  9013. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9014. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9015. '</div>',
  9016. dialog = self.createDialog({
  9017. name : name,
  9018. width : 450,
  9019. title : self.lang(name),
  9020. body : html,
  9021. yesBtn : {
  9022. name : self.lang('yes'),
  9023. click : function(e) {
  9024. var html = textarea.val();
  9025. html = K.escape(html);
  9026. html = html.replace(/ {2}/g, ' &nbsp;');
  9027. if (self.newlineTag == 'p') {
  9028. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9029. } else {
  9030. html = html.replace(/\n/g, '<br />$&');
  9031. }
  9032. self.insertHtml(html).hideDialog().focus();
  9033. }
  9034. }
  9035. }),
  9036. textarea = K('textarea', dialog.div);
  9037. textarea[0].focus();
  9038. });
  9039. });
  9040. /*******************************************************************************
  9041. * KindEditor - WYSIWYG HTML Editor for Internet
  9042. * Copyright (C) 2006-2011 kindsoft.net
  9043. *
  9044. * @author Roddy <luolonghao@gmail.com>
  9045. * @site http://www.kindsoft.net/
  9046. * @licence http://www.kindsoft.net/license.php
  9047. *******************************************************************************/
  9048. KindEditor.plugin('preview', function(K) {
  9049. var self = this, name = 'preview', undefined;
  9050. self.clickToolbar(name, function() {
  9051. var lang = self.lang(name + '.'),
  9052. html = '<div style="padding:10px 20px;">' +
  9053. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9054. '</div>',
  9055. dialog = self.createDialog({
  9056. name : name,
  9057. width : 750,
  9058. title : self.lang(name),
  9059. body : html
  9060. }),
  9061. iframe = K('iframe', dialog.div),
  9062. doc = K.iframeDoc(iframe);
  9063. doc.open();
  9064. doc.write(self.fullHtml());
  9065. doc.close();
  9066. K(doc.body).css('background-color', '#FFF');
  9067. iframe[0].contentWindow.focus();
  9068. });
  9069. });
  9070. /*******************************************************************************
  9071. * KindEditor - WYSIWYG HTML Editor for Internet
  9072. * Copyright (C) 2006-2011 kindsoft.net
  9073. *
  9074. * @author Roddy <luolonghao@gmail.com>
  9075. * @site http://www.kindsoft.net/
  9076. * @licence http://www.kindsoft.net/license.php
  9077. *******************************************************************************/
  9078. KindEditor.plugin('quickformat', function(K) {
  9079. var self = this, name = 'quickformat',
  9080. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9081. function getFirstChild(knode) {
  9082. var child = knode.first();
  9083. while (child && child.first()) {
  9084. child = child.first();
  9085. }
  9086. return child;
  9087. }
  9088. self.clickToolbar(name, function() {
  9089. self.focus();
  9090. var doc = self.edit.doc,
  9091. range = self.cmd.range,
  9092. child = K(doc.body).first(), next,
  9093. nodeList = [], subList = [],
  9094. bookmark = range.createBookmark(true);
  9095. while(child) {
  9096. next = child.next();
  9097. var firstChild = getFirstChild(child);
  9098. if (!firstChild || firstChild.name != 'img') {
  9099. if (blockMap[child.name]) {
  9100. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9101. child.css('text-indent', '2em');
  9102. } else {
  9103. subList.push(child);
  9104. }
  9105. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9106. if (subList.length > 0) {
  9107. nodeList.push(subList);
  9108. }
  9109. subList = [];
  9110. }
  9111. }
  9112. child = next;
  9113. }
  9114. K.each(nodeList, function(i, subList) {
  9115. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9116. subList[0].before(wrapper);
  9117. K.each(subList, function(i, knode) {
  9118. wrapper.append(knode);
  9119. });
  9120. });
  9121. range.moveToBookmark(bookmark);
  9122. self.addBookmark();
  9123. });
  9124. });
  9125. /*******************************************************************************
  9126. * KindEditor - WYSIWYG HTML Editor for Internet
  9127. * Copyright (C) 2006-2011 kindsoft.net
  9128. *
  9129. * @author Roddy <luolonghao@gmail.com>
  9130. * @site http://www.kindsoft.net/
  9131. * @licence http://www.kindsoft.net/license.php
  9132. *******************************************************************************/
  9133. KindEditor.plugin('table', function(K) {
  9134. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9135. function _setColor(box, color) {
  9136. color = color.toUpperCase();
  9137. box.css('background-color', color);
  9138. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9139. box.html(color);
  9140. }
  9141. var pickerList = [];
  9142. function _initColorPicker(dialogDiv, colorBox) {
  9143. colorBox.bind('click,mousedown', function(e){
  9144. e.stopPropagation();
  9145. });
  9146. function removePicker() {
  9147. K.each(pickerList, function() {
  9148. this.remove();
  9149. });
  9150. pickerList = [];
  9151. K(document).unbind('click,mousedown', removePicker);
  9152. dialogDiv.unbind('click,mousedown', removePicker);
  9153. }
  9154. colorBox.click(function(e) {
  9155. removePicker();
  9156. var box = K(this),
  9157. pos = box.pos();
  9158. var picker = K.colorpicker({
  9159. x : pos.x,
  9160. y : pos.y + box.height(),
  9161. z : 811214,
  9162. selectedColor : K(this).html(),
  9163. colors : self.colorTable,
  9164. noColor : self.lang('noColor'),
  9165. shadowMode : self.shadowMode,
  9166. click : function(color) {
  9167. _setColor(box, color);
  9168. removePicker();
  9169. }
  9170. });
  9171. pickerList.push(picker);
  9172. K(document).bind('click,mousedown', removePicker);
  9173. dialogDiv.bind('click,mousedown', removePicker);
  9174. });
  9175. }
  9176. function _getCellIndex(table, row, cell) {
  9177. var rowSpanCount = 0;
  9178. for (var i = 0, len = row.cells.length; i < len; i++) {
  9179. if (row.cells[i] == cell) {
  9180. break;
  9181. }
  9182. rowSpanCount += row.cells[i].rowSpan - 1;
  9183. }
  9184. return cell.cellIndex - rowSpanCount;
  9185. }
  9186. self.plugin.table = {
  9187. prop : function(isInsert) {
  9188. var html = [
  9189. '<div style="padding:20px;">',
  9190. '<div class="ke-dialog-row">',
  9191. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9192. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9193. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9194. '</div>',
  9195. '<div class="ke-dialog-row">',
  9196. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9197. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9198. '<select name="widthType">',
  9199. '<option value="%">' + lang.percent + '</option>',
  9200. '<option value="px">' + lang.px + '</option>',
  9201. '</select> &nbsp; ',
  9202. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9203. '<select name="heightType">',
  9204. '<option value="%">' + lang.percent + '</option>',
  9205. '<option value="px">' + lang.px + '</option>',
  9206. '</select>',
  9207. '</div>',
  9208. '<div class="ke-dialog-row">',
  9209. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9210. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9211. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9212. '</div>',
  9213. '<div class="ke-dialog-row">',
  9214. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9215. '<select id="keAlign" name="align">',
  9216. '<option value="">' + lang.alignDefault + '</option>',
  9217. '<option value="left">' + lang.alignLeft + '</option>',
  9218. '<option value="center">' + lang.alignCenter + '</option>',
  9219. '<option value="right">' + lang.alignRight + '</option>',
  9220. '</select>',
  9221. '</div>',
  9222. '<div class="ke-dialog-row">',
  9223. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9224. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9225. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9226. '</div>',
  9227. '<div class="ke-dialog-row">',
  9228. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9229. '<span class="ke-inline-block ke-input-color"></span>',
  9230. '</div>',
  9231. '</div>'
  9232. ].join('');
  9233. var bookmark = self.cmd.range.createBookmark();
  9234. var dialog = self.createDialog({
  9235. name : name,
  9236. width : 500,
  9237. title : self.lang(name),
  9238. body : html,
  9239. beforeRemove : function() {
  9240. colorBox.unbind();
  9241. },
  9242. yesBtn : {
  9243. name : self.lang('yes'),
  9244. click : function(e) {
  9245. var rows = rowsBox.val(),
  9246. cols = colsBox.val(),
  9247. width = widthBox.val(),
  9248. height = heightBox.val(),
  9249. widthType = widthTypeBox.val(),
  9250. heightType = heightTypeBox.val(),
  9251. padding = paddingBox.val(),
  9252. spacing = spacingBox.val(),
  9253. align = alignBox.val(),
  9254. border = borderBox.val(),
  9255. borderColor = K(colorBox[0]).html() || '',
  9256. bgColor = K(colorBox[1]).html() || '';
  9257. if (rows == 0 || !/^\d+$/.test(rows)) {
  9258. alert(self.lang('invalidRows'));
  9259. rowsBox[0].focus();
  9260. return;
  9261. }
  9262. if (cols == 0 || !/^\d+$/.test(cols)) {
  9263. alert(self.lang('invalidRows'));
  9264. colsBox[0].focus();
  9265. return;
  9266. }
  9267. if (!/^\d*$/.test(width)) {
  9268. alert(self.lang('invalidWidth'));
  9269. widthBox[0].focus();
  9270. return;
  9271. }
  9272. if (!/^\d*$/.test(height)) {
  9273. alert(self.lang('invalidHeight'));
  9274. heightBox[0].focus();
  9275. return;
  9276. }
  9277. if (!/^\d*$/.test(padding)) {
  9278. alert(self.lang('invalidPadding'));
  9279. paddingBox[0].focus();
  9280. return;
  9281. }
  9282. if (!/^\d*$/.test(spacing)) {
  9283. alert(self.lang('invalidSpacing'));
  9284. spacingBox[0].focus();
  9285. return;
  9286. }
  9287. if (!/^\d*$/.test(border)) {
  9288. alert(self.lang('invalidBorder'));
  9289. borderBox[0].focus();
  9290. return;
  9291. }
  9292. if (table) {
  9293. if (width !== '') {
  9294. table.width(width + widthType);
  9295. } else {
  9296. table.css('width', '');
  9297. }
  9298. if (table[0].width !== undefined) {
  9299. table.removeAttr('width');
  9300. }
  9301. if (height !== '') {
  9302. table.height(height + heightType);
  9303. } else {
  9304. table.css('height', '');
  9305. }
  9306. if (table[0].height !== undefined) {
  9307. table.removeAttr('height');
  9308. }
  9309. table.css('background-color', bgColor);
  9310. if (table[0].bgColor !== undefined) {
  9311. table.removeAttr('bgColor');
  9312. }
  9313. if (padding !== '') {
  9314. table[0].cellPadding = padding;
  9315. } else {
  9316. table.removeAttr('cellPadding');
  9317. }
  9318. if (spacing !== '') {
  9319. table[0].cellSpacing = spacing;
  9320. } else {
  9321. table.removeAttr('cellSpacing');
  9322. }
  9323. if (align !== '') {
  9324. table[0].align = align;
  9325. } else {
  9326. table.removeAttr('align');
  9327. }
  9328. if (border !== '') {
  9329. table.attr('border', border);
  9330. } else {
  9331. table.removeAttr('border');
  9332. }
  9333. if (border === '' || border === '0') {
  9334. table.addClass(zeroborder);
  9335. } else {
  9336. table.removeClass(zeroborder);
  9337. }
  9338. if (borderColor !== '') {
  9339. table.attr('borderColor', borderColor);
  9340. } else {
  9341. table.removeAttr('borderColor');
  9342. }
  9343. self.hideDialog().focus();
  9344. self.cmd.range.moveToBookmark(bookmark);
  9345. self.cmd.select();
  9346. self.addBookmark();
  9347. return;
  9348. }
  9349. var style = '';
  9350. if (width !== '') {
  9351. style += 'width:' + width + widthType + ';';
  9352. }
  9353. if (height !== '') {
  9354. style += 'height:' + height + heightType + ';';
  9355. }
  9356. if (bgColor !== '') {
  9357. style += 'background-color:' + bgColor + ';';
  9358. }
  9359. var html = '<table';
  9360. if (style !== '') {
  9361. html += ' style="' + style + '"';
  9362. }
  9363. if (padding !== '') {
  9364. html += ' cellpadding="' + padding + '"';
  9365. }
  9366. if (spacing !== '') {
  9367. html += ' cellspacing="' + spacing + '"';
  9368. }
  9369. if (align !== '') {
  9370. html += ' align="' + align + '"';
  9371. }
  9372. if (border !== '') {
  9373. html += ' border="' + border + '"';
  9374. }
  9375. if (border === '' || border === '0') {
  9376. html += ' class="' + zeroborder + '"';
  9377. }
  9378. if (borderColor !== '') {
  9379. html += ' bordercolor="' + borderColor + '"';
  9380. }
  9381. html += '>';
  9382. for (var i = 0; i < rows; i++) {
  9383. html += '<tr>';
  9384. for (var j = 0; j < cols; j++) {
  9385. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9386. }
  9387. html += '</tr>';
  9388. }
  9389. html += '</table>';
  9390. if (!K.IE) {
  9391. html += '<br />';
  9392. }
  9393. self.insertHtml(html);
  9394. self.select().hideDialog().focus();
  9395. self.addBookmark();
  9396. }
  9397. }
  9398. }),
  9399. div = dialog.div,
  9400. rowsBox = K('[name="rows"]', div).val(3),
  9401. colsBox = K('[name="cols"]', div).val(2),
  9402. widthBox = K('[name="width"]', div).val(100),
  9403. heightBox = K('[name="height"]', div),
  9404. widthTypeBox = K('[name="widthType"]', div),
  9405. heightTypeBox = K('[name="heightType"]', div),
  9406. paddingBox = K('[name="padding"]', div).val(2),
  9407. spacingBox = K('[name="spacing"]', div).val(0),
  9408. alignBox = K('[name="align"]', div),
  9409. borderBox = K('[name="border"]', div).val(1),
  9410. colorBox = K('.ke-input-color', div);
  9411. _initColorPicker(div, colorBox.eq(0));
  9412. _initColorPicker(div, colorBox.eq(1));
  9413. _setColor(colorBox.eq(0), '#000000');
  9414. _setColor(colorBox.eq(1), '');
  9415. rowsBox[0].focus();
  9416. rowsBox[0].select();
  9417. var table;
  9418. if (isInsert) {
  9419. return;
  9420. }
  9421. table = self.plugin.getSelectedTable();
  9422. if (table) {
  9423. rowsBox.val(table[0].rows.length);
  9424. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9425. rowsBox.attr('disabled', true);
  9426. colsBox.attr('disabled', true);
  9427. var match,
  9428. tableWidth = table[0].style.width || table[0].width,
  9429. tableHeight = table[0].style.height || table[0].height;
  9430. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9431. widthBox.val(match[1]);
  9432. widthTypeBox.val(match[2]);
  9433. } else {
  9434. widthBox.val('');
  9435. }
  9436. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9437. heightBox.val(match[1]);
  9438. heightTypeBox.val(match[2]);
  9439. }
  9440. paddingBox.val(table[0].cellPadding || '');
  9441. spacingBox.val(table[0].cellSpacing || '');
  9442. alignBox.val(table[0].align || '');
  9443. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9444. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9445. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9446. widthBox[0].focus();
  9447. widthBox[0].select();
  9448. }
  9449. },
  9450. cellprop : function() {
  9451. var html = [
  9452. '<div style="padding:20px;">',
  9453. '<div class="ke-dialog-row">',
  9454. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9455. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9456. '<select name="widthType">',
  9457. '<option value="%">' + lang.percent + '</option>',
  9458. '<option value="px">' + lang.px + '</option>',
  9459. '</select> &nbsp; ',
  9460. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9461. '<select name="heightType">',
  9462. '<option value="%">' + lang.percent + '</option>',
  9463. '<option value="px">' + lang.px + '</option>',
  9464. '</select>',
  9465. '</div>',
  9466. '<div class="ke-dialog-row">',
  9467. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9468. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9469. '<option value="">' + lang.alignDefault + '</option>',
  9470. '<option value="left">' + lang.alignLeft + '</option>',
  9471. '<option value="center">' + lang.alignCenter + '</option>',
  9472. '<option value="right">' + lang.alignRight + '</option>',
  9473. '</select> ',
  9474. lang.verticalAlign + ' <select name="verticalAlign">',
  9475. '<option value="">' + lang.alignDefault + '</option>',
  9476. '<option value="top">' + lang.alignTop + '</option>',
  9477. '<option value="middle">' + lang.alignMiddle + '</option>',
  9478. '<option value="bottom">' + lang.alignBottom + '</option>',
  9479. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9480. '</select>',
  9481. '</div>',
  9482. '<div class="ke-dialog-row">',
  9483. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9484. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9485. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9486. '</div>',
  9487. '<div class="ke-dialog-row">',
  9488. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9489. '<span class="ke-inline-block ke-input-color"></span>',
  9490. '</div>',
  9491. '</div>'
  9492. ].join('');
  9493. var bookmark = self.cmd.range.createBookmark();
  9494. var dialog = self.createDialog({
  9495. name : name,
  9496. width : 500,
  9497. title : self.lang('tablecell'),
  9498. body : html,
  9499. beforeRemove : function() {
  9500. colorBox.unbind();
  9501. },
  9502. yesBtn : {
  9503. name : self.lang('yes'),
  9504. click : function(e) {
  9505. var width = widthBox.val(),
  9506. height = heightBox.val(),
  9507. widthType = widthTypeBox.val(),
  9508. heightType = heightTypeBox.val(),
  9509. padding = paddingBox.val(),
  9510. spacing = spacingBox.val(),
  9511. textAlign = textAlignBox.val(),
  9512. verticalAlign = verticalAlignBox.val(),
  9513. border = borderBox.val(),
  9514. borderColor = K(colorBox[0]).html() || '',
  9515. bgColor = K(colorBox[1]).html() || '';
  9516. if (!/^\d*$/.test(width)) {
  9517. alert(self.lang('invalidWidth'));
  9518. widthBox[0].focus();
  9519. return;
  9520. }
  9521. if (!/^\d*$/.test(height)) {
  9522. alert(self.lang('invalidHeight'));
  9523. heightBox[0].focus();
  9524. return;
  9525. }
  9526. if (!/^\d*$/.test(border)) {
  9527. alert(self.lang('invalidBorder'));
  9528. borderBox[0].focus();
  9529. return;
  9530. }
  9531. cell.css({
  9532. width : width !== '' ? (width + widthType) : '',
  9533. height : height !== '' ? (height + heightType) : '',
  9534. 'background-color' : bgColor,
  9535. 'text-align' : textAlign,
  9536. 'vertical-align' : verticalAlign,
  9537. 'border-width' : border,
  9538. 'border-style' : border !== '' ? 'solid' : '',
  9539. 'border-color' : borderColor
  9540. });
  9541. self.hideDialog().focus();
  9542. self.cmd.range.moveToBookmark(bookmark);
  9543. self.cmd.select();
  9544. self.addBookmark();
  9545. }
  9546. }
  9547. }),
  9548. div = dialog.div,
  9549. widthBox = K('[name="width"]', div).val(100),
  9550. heightBox = K('[name="height"]', div),
  9551. widthTypeBox = K('[name="widthType"]', div),
  9552. heightTypeBox = K('[name="heightType"]', div),
  9553. paddingBox = K('[name="padding"]', div).val(2),
  9554. spacingBox = K('[name="spacing"]', div).val(0),
  9555. textAlignBox = K('[name="textAlign"]', div),
  9556. verticalAlignBox = K('[name="verticalAlign"]', div),
  9557. borderBox = K('[name="border"]', div).val(1),
  9558. colorBox = K('.ke-input-color', div);
  9559. _initColorPicker(div, colorBox.eq(0));
  9560. _initColorPicker(div, colorBox.eq(1));
  9561. _setColor(colorBox.eq(0), '#000000');
  9562. _setColor(colorBox.eq(1), '');
  9563. widthBox[0].focus();
  9564. widthBox[0].select();
  9565. var cell = self.plugin.getSelectedCell();
  9566. var match,
  9567. cellWidth = cell[0].style.width || cell[0].width || '',
  9568. cellHeight = cell[0].style.height || cell[0].height || '';
  9569. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9570. widthBox.val(match[1]);
  9571. widthTypeBox.val(match[2]);
  9572. } else {
  9573. widthBox.val('');
  9574. }
  9575. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9576. heightBox.val(match[1]);
  9577. heightTypeBox.val(match[2]);
  9578. }
  9579. textAlignBox.val(cell[0].style.textAlign || '');
  9580. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9581. var border = cell[0].style.borderWidth || '';
  9582. if (border) {
  9583. border = parseInt(border);
  9584. }
  9585. borderBox.val(border);
  9586. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9587. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9588. widthBox[0].focus();
  9589. widthBox[0].select();
  9590. },
  9591. insert : function() {
  9592. this.prop(true);
  9593. },
  9594. 'delete' : function() {
  9595. var table = self.plugin.getSelectedTable();
  9596. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9597. self.cmd.select();
  9598. table.remove();
  9599. self.addBookmark();
  9600. },
  9601. colinsert : function(offset) {
  9602. var table = self.plugin.getSelectedTable()[0],
  9603. row = self.plugin.getSelectedRow()[0],
  9604. cell = self.plugin.getSelectedCell()[0],
  9605. index = cell.cellIndex + offset;
  9606. index += table.rows[0].cells.length - row.cells.length;
  9607. for (var i = 0, len = table.rows.length; i < len; i++) {
  9608. var newRow = table.rows[i],
  9609. newCell = newRow.insertCell(index);
  9610. newCell.innerHTML = K.IE ? '' : '<br />';
  9611. index = _getCellIndex(table, newRow, newCell);
  9612. }
  9613. self.cmd.range.selectNodeContents(cell).collapse(true);
  9614. self.cmd.select();
  9615. self.addBookmark();
  9616. },
  9617. colinsertleft : function() {
  9618. this.colinsert(0);
  9619. },
  9620. colinsertright : function() {
  9621. this.colinsert(1);
  9622. },
  9623. rowinsert : function(offset) {
  9624. var table = self.plugin.getSelectedTable()[0],
  9625. row = self.plugin.getSelectedRow()[0],
  9626. cell = self.plugin.getSelectedCell()[0];
  9627. var rowIndex = row.rowIndex;
  9628. if (offset === 1) {
  9629. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9630. }
  9631. var newRow = table.insertRow(rowIndex);
  9632. for (var i = 0, len = row.cells.length; i < len; i++) {
  9633. if (row.cells[i].rowSpan > 1) {
  9634. len -= row.cells[i].rowSpan - 1;
  9635. }
  9636. var newCell = newRow.insertCell(i);
  9637. if (offset === 1 && row.cells[i].colSpan > 1) {
  9638. newCell.colSpan = row.cells[i].colSpan;
  9639. }
  9640. newCell.innerHTML = K.IE ? '' : '<br />';
  9641. }
  9642. for (var j = rowIndex; j >= 0; j--) {
  9643. var cells = table.rows[j].cells;
  9644. if (cells.length > i) {
  9645. for (var k = cell.cellIndex; k >= 0; k--) {
  9646. if (cells[k].rowSpan > 1) {
  9647. cells[k].rowSpan += 1;
  9648. }
  9649. }
  9650. break;
  9651. }
  9652. }
  9653. self.cmd.range.selectNodeContents(cell).collapse(true);
  9654. self.cmd.select();
  9655. self.addBookmark();
  9656. },
  9657. rowinsertabove : function() {
  9658. this.rowinsert(0);
  9659. },
  9660. rowinsertbelow : function() {
  9661. this.rowinsert(1);
  9662. },
  9663. rowmerge : function() {
  9664. var table = self.plugin.getSelectedTable()[0],
  9665. row = self.plugin.getSelectedRow()[0],
  9666. cell = self.plugin.getSelectedCell()[0],
  9667. rowIndex = row.rowIndex,
  9668. nextRowIndex = rowIndex + cell.rowSpan,
  9669. nextRow = table.rows[nextRowIndex];
  9670. if (table.rows.length <= nextRowIndex) {
  9671. return;
  9672. }
  9673. var cellIndex = cell.cellIndex;
  9674. if (nextRow.cells.length <= cellIndex) {
  9675. return;
  9676. }
  9677. var nextCell = nextRow.cells[cellIndex];
  9678. if (cell.colSpan !== nextCell.colSpan) {
  9679. return;
  9680. }
  9681. cell.rowSpan += nextCell.rowSpan;
  9682. nextRow.deleteCell(cellIndex);
  9683. self.cmd.range.selectNodeContents(cell).collapse(true);
  9684. self.cmd.select();
  9685. self.addBookmark();
  9686. },
  9687. colmerge : function() {
  9688. var table = self.plugin.getSelectedTable()[0],
  9689. row = self.plugin.getSelectedRow()[0],
  9690. cell = self.plugin.getSelectedCell()[0],
  9691. rowIndex = row.rowIndex,
  9692. cellIndex = cell.cellIndex,
  9693. nextCellIndex = cellIndex + 1;
  9694. if (row.cells.length <= nextCellIndex) {
  9695. return;
  9696. }
  9697. var nextCell = row.cells[nextCellIndex];
  9698. if (cell.rowSpan !== nextCell.rowSpan) {
  9699. return;
  9700. }
  9701. cell.colSpan += nextCell.colSpan;
  9702. row.deleteCell(nextCellIndex);
  9703. self.cmd.range.selectNodeContents(cell).collapse(true);
  9704. self.cmd.select();
  9705. self.addBookmark();
  9706. },
  9707. rowsplit : function() {
  9708. var table = self.plugin.getSelectedTable()[0],
  9709. row = self.plugin.getSelectedRow()[0],
  9710. cell = self.plugin.getSelectedCell()[0],
  9711. rowIndex = row.rowIndex;
  9712. if (cell.rowSpan === 1) {
  9713. return;
  9714. }
  9715. var cellIndex = _getCellIndex(table, row, cell);
  9716. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9717. var newRow = table.rows[rowIndex + i],
  9718. newCell = newRow.insertCell(cellIndex);
  9719. if (cell.colSpan > 1) {
  9720. newCell.colSpan = cell.colSpan;
  9721. }
  9722. newCell.innerHTML = K.IE ? '' : '<br />';
  9723. cellIndex = _getCellIndex(table, newRow, newCell);
  9724. }
  9725. K(cell).removeAttr('rowSpan');
  9726. self.cmd.range.selectNodeContents(cell).collapse(true);
  9727. self.cmd.select();
  9728. self.addBookmark();
  9729. },
  9730. colsplit : function() {
  9731. var table = self.plugin.getSelectedTable()[0],
  9732. row = self.plugin.getSelectedRow()[0],
  9733. cell = self.plugin.getSelectedCell()[0],
  9734. cellIndex = cell.cellIndex;
  9735. if (cell.colSpan === 1) {
  9736. return;
  9737. }
  9738. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9739. var newCell = row.insertCell(cellIndex + i);
  9740. if (cell.rowSpan > 1) {
  9741. newCell.rowSpan = cell.rowSpan;
  9742. }
  9743. newCell.innerHTML = K.IE ? '' : '<br />';
  9744. }
  9745. K(cell).removeAttr('colSpan');
  9746. self.cmd.range.selectNodeContents(cell).collapse(true);
  9747. self.cmd.select();
  9748. self.addBookmark();
  9749. },
  9750. coldelete : function() {
  9751. var table = self.plugin.getSelectedTable()[0],
  9752. row = self.plugin.getSelectedRow()[0],
  9753. cell = self.plugin.getSelectedCell()[0],
  9754. index = cell.cellIndex;
  9755. for (var i = 0, len = table.rows.length; i < len; i++) {
  9756. var newRow = table.rows[i],
  9757. newCell = newRow.cells[index];
  9758. if (newCell.colSpan > 1) {
  9759. newCell.colSpan -= 1;
  9760. if (newCell.colSpan === 1) {
  9761. K(newCell).removeAttr('colSpan');
  9762. }
  9763. } else {
  9764. newRow.deleteCell(index);
  9765. }
  9766. if (newCell.rowSpan > 1) {
  9767. i += newCell.rowSpan - 1;
  9768. }
  9769. }
  9770. if (row.cells.length === 0) {
  9771. self.cmd.range.setStartBefore(table).collapse(true);
  9772. self.cmd.select();
  9773. K(table).remove();
  9774. } else {
  9775. self.cmd.selection(true);
  9776. }
  9777. self.addBookmark();
  9778. },
  9779. rowdelete : function() {
  9780. var table = self.plugin.getSelectedTable()[0],
  9781. row = self.plugin.getSelectedRow()[0],
  9782. cell = self.plugin.getSelectedCell()[0],
  9783. rowIndex = row.rowIndex;
  9784. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9785. table.deleteRow(rowIndex + i);
  9786. }
  9787. if (table.rows.length === 0) {
  9788. self.cmd.range.setStartBefore(table).collapse(true);
  9789. self.cmd.select();
  9790. K(table).remove();
  9791. } else {
  9792. self.cmd.selection(true);
  9793. }
  9794. self.addBookmark();
  9795. }
  9796. };
  9797. self.clickToolbar(name, self.plugin.table.prop);
  9798. });
  9799. /*******************************************************************************
  9800. * KindEditor - WYSIWYG HTML Editor for Internet
  9801. * Copyright (C) 2006-2011 kindsoft.net
  9802. *
  9803. * @author Roddy <luolonghao@gmail.com>
  9804. * @site http://www.kindsoft.net/
  9805. * @licence http://www.kindsoft.net/license.php
  9806. *******************************************************************************/
  9807. KindEditor.plugin('template', function(K) {
  9808. var self = this, name = 'template', lang = self.lang(name + '.'),
  9809. htmlPath = self.pluginsPath + name + '/html/';
  9810. function getFilePath(fileName) {
  9811. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9812. }
  9813. self.clickToolbar(name, function() {
  9814. var lang = self.lang(name + '.'),
  9815. arr = ['<div style="padding:10px 20px;">',
  9816. '<div class="ke-header">',
  9817. '<div class="ke-left">',
  9818. lang. selectTemplate + ' <select>'];
  9819. K.each(lang.fileList, function(key, val) {
  9820. arr.push('<option value="' + key + '">' + val + '</option>');
  9821. });
  9822. html = [arr.join(''),
  9823. '</select></div>',
  9824. '<div class="ke-right">',
  9825. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9826. '</div>',
  9827. '<div class="ke-clearfix"></div>',
  9828. '</div>',
  9829. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9830. '</div>'].join('');
  9831. var dialog = self.createDialog({
  9832. name : name,
  9833. width : 500,
  9834. title : self.lang(name),
  9835. body : html,
  9836. yesBtn : {
  9837. name : self.lang('yes'),
  9838. click : function(e) {
  9839. var doc = K.iframeDoc(iframe);
  9840. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9841. }
  9842. }
  9843. });
  9844. var selectBox = K('select', dialog.div),
  9845. checkbox = K('[name="replaceFlag"]', dialog.div),
  9846. iframe = K('iframe', dialog.div);
  9847. checkbox[0].checked = true;
  9848. iframe.attr('src', getFilePath(selectBox.val()));
  9849. selectBox.change(function() {
  9850. iframe.attr('src', getFilePath(this.value));
  9851. });
  9852. });
  9853. });
  9854. /*******************************************************************************
  9855. * KindEditor - WYSIWYG HTML Editor for Internet
  9856. * Copyright (C) 2006-2011 kindsoft.net
  9857. *
  9858. * @author Roddy <luolonghao@gmail.com>
  9859. * @site http://www.kindsoft.net/
  9860. * @licence http://www.kindsoft.net/license.php
  9861. *******************************************************************************/
  9862. KindEditor.plugin('wordpaste', function(K) {
  9863. var self = this, name = 'wordpaste';
  9864. self.clickToolbar(name, function() {
  9865. var lang = self.lang(name + '.'),
  9866. html = '<div style="padding:10px 20px;">' +
  9867. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9868. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9869. '</div>',
  9870. dialog = self.createDialog({
  9871. name : name,
  9872. width : 450,
  9873. title : self.lang(name),
  9874. body : html,
  9875. yesBtn : {
  9876. name : self.lang('yes'),
  9877. click : function(e) {
  9878. var str = doc.body.innerHTML;
  9879. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9880. self.insertHtml(str).hideDialog().focus();
  9881. }
  9882. }
  9883. }),
  9884. div = dialog.div,
  9885. iframe = K('iframe', div),
  9886. doc = K.iframeDoc(iframe);
  9887. if (!K.IE) {
  9888. doc.designMode = 'on';
  9889. }
  9890. doc.open();
  9891. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9892. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9893. if (!K.IE) {
  9894. doc.write('<br />');
  9895. }
  9896. doc.write('</body></html>');
  9897. doc.close();
  9898. if (K.IE) {
  9899. doc.body.contentEditable = 'true';
  9900. }
  9901. iframe[0].contentWindow.focus();
  9902. });
  9903. });
  9904. KindEditor.plugin('fixtoolbar', function (K) {
  9905. var self = this;
  9906. if (!self.fixToolBar) {
  9907. return;
  9908. }
  9909. function init() {
  9910. var toolbar = K('.ke-toolbar');
  9911. var originY = toolbar.pos().y;
  9912. K(window).bind('scroll', function () {
  9913. if (toolbar.css('position') == 'fixed') {
  9914. if(document.body.scrollTop - originY < 0){
  9915. toolbar.css('position', 'static');
  9916. toolbar.css('top', 'auto');
  9917. }
  9918. } else {
  9919. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9920. toolbar.css('position', 'fixed');
  9921. toolbar.css('top', 0);
  9922. }
  9923. }
  9924. });
  9925. }
  9926. if (self.isCreated) {
  9927. init();
  9928. } else {
  9929. self.afterCreate(init);
  9930. }
  9931. });
  9932. //自定义资源库
  9933. KindEditor.plugin('res', function(K) {
  9934. var self = this;
  9935. // 点击图标时执行
  9936. self.clickToolbar('res', function() {
  9937. var clickFn = function(url, title, id) {
  9938. var html = '<embed src="{url}" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" id="{id}"/>';
  9939. html = html.replace('{url}', url);
  9940. html = html.replace('{id}', id);
  9941. self.insertHtml(html);
  9942. };
  9943. editorShowUpload('', self.fileManagerJson, '视频库', clickFn, this);
  9944. });
  9945. });
  9946. function autoImg(self) {
  9947. var index = self.index;
  9948. var haspicContainer = document.getElementById("has_pic_" + index);
  9949. if (haspicContainer == null) {
  9950. haspicContainer = document.createElement("div");
  9951. haspicContainer.id = "has_pic_" + index;
  9952. 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>";
  9953. $(".ke-toolbar").eq(index).after(haspicContainer);
  9954. }
  9955. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  9956. var piccount = 0;
  9957. var sstr = '';
  9958. $(img).each(function (i) {
  9959. var that = $(this);
  9960. var host = gethost(self.uploadJson);
  9961. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  9962. var n = gethost(that.attr("src"));
  9963. if (host != n) {
  9964. piccount++;
  9965. if (i == $(img).length - 1)
  9966. sstr += that.attr("src");
  9967. else
  9968. sstr += that.attr("src") + ",";
  9969. }
  9970. }
  9971. });
  9972. $("#piclist_" + index).val(encodeURIComponent(sstr));
  9973. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  9974. }
  9975. function closeupload(index) {
  9976. $("#has_pic_" + index).hide();
  9977. $("#upload_" + index).show();
  9978. }
  9979. function uploadpic(url, name, index) {
  9980. var piclist = encodeURI($("#piclist_" + index).val());
  9981. if (piclist.length == 0) return false;
  9982. $.ajax({
  9983. url: url.replace('kindeditor', 'copys') + '&json=1',
  9984. data: name + "=" + piclist,
  9985. type: "POST",
  9986. dataType: "json",
  9987. beforeSend: function () {
  9988. $("#upload_" + index).hide();
  9989. $("#confirm_" + index).text("正在上传中...");
  9990. },
  9991. success: function (msg) {
  9992. var url = msg.data;
  9993. if (url !== "") {
  9994. var str = new Array();
  9995. str = url.split(',');
  9996. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  9997. $(img).each(function (i) {
  9998. var that = $(this);
  9999. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10000. that.attr("src", str[i]);
  10001. that.attr("data-ke-src", str[i]);
  10002. }
  10003. });
  10004. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  10005. }
  10006. else $("#confirm_" + index).text("上传失败!");
  10007. }
  10008. });
  10009. }
  10010. function gethost(url){
  10011. var reg = /^http(s)?:\/\/(.*?)\//;
  10012. return reg.exec(url)[2];
  10013. }