kindeditor-all.js 310 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2013 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.9 (2013-10-08)
  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.9 (2013-10-08)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  24. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  25. _OPERA = _ua.indexOf('opera') > -1,
  26. _MOBILE = _ua.indexOf('mobile') > -1,
  27. _IOS = /ipad|iphone|ipod/.test(_ua),
  28. _QUIRKS = document.compatMode != 'CSS1Compat',
  29. _IERANGE = !window.getSelection,
  30. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  31. _V = _matches ? _matches[1] : '0',
  32. _TIME = new Date().getTime();
  33. function _isArray(val) {
  34. if (!val) {
  35. return false;
  36. }
  37. return Object.prototype.toString.call(val) === '[object Array]';
  38. }
  39. function _isFunction(val) {
  40. if (!val) {
  41. return false;
  42. }
  43. return Object.prototype.toString.call(val) === '[object Function]';
  44. }
  45. function _inArray(val, arr) {
  46. for (var i = 0, len = arr.length; i < len; i++) {
  47. if (val === arr[i]) {
  48. return i;
  49. }
  50. }
  51. return -1;
  52. }
  53. function _each(obj, fn) {
  54. if (_isArray(obj)) {
  55. for (var i = 0, len = obj.length; i < len; i++) {
  56. if (fn.call(obj[i], i, obj[i]) === false) {
  57. break;
  58. }
  59. }
  60. } else {
  61. for (var key in obj) {
  62. if (obj.hasOwnProperty(key)) {
  63. if (fn.call(obj[key], key, obj[key]) === false) {
  64. break;
  65. }
  66. }
  67. }
  68. }
  69. }
  70. function _trim(str) {
  71. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  72. }
  73. function _inString(val, str, delimiter) {
  74. delimiter = delimiter === undefined ? ',' : delimiter;
  75. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  76. }
  77. function _addUnit(val, unit) {
  78. unit = unit || 'px';
  79. return val && /^\d+$/.test(val) ? val + unit : val;
  80. }
  81. function _removeUnit(val) {
  82. var match;
  83. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  84. }
  85. function _escape(val) {
  86. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  87. }
  88. function _unescape(val) {
  89. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  90. }
  91. function _toCamel(str) {
  92. var arr = str.split('-');
  93. str = '';
  94. _each(arr, function(key, val) {
  95. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  96. });
  97. return str;
  98. }
  99. function _toHex(val) {
  100. function hex(d) {
  101. var s = parseInt(d, 10).toString(16).toUpperCase();
  102. return s.length > 1 ? s : '0' + s;
  103. }
  104. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  105. function($0, $1, $2, $3) {
  106. return '#' + hex($1) + hex($2) + hex($3);
  107. }
  108. );
  109. }
  110. function _toMap(val, delimiter) {
  111. delimiter = delimiter === undefined ? ',' : delimiter;
  112. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  113. _each(arr, function(key, val) {
  114. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  115. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  116. map[i.toString()] = true;
  117. }
  118. } else {
  119. map[val] = true;
  120. }
  121. });
  122. return map;
  123. }
  124. function _toArray(obj, offset) {
  125. return Array.prototype.slice.call(obj, offset || 0);
  126. }
  127. function _undef(val, defaultVal) {
  128. return val === undefined ? defaultVal : val;
  129. }
  130. function _invalidUrl(url) {
  131. return !url || /[<>"]/.test(url);
  132. }
  133. function _addParam(url, param) {
  134. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  135. }
  136. function _extend(child, parent, proto) {
  137. if (!proto) {
  138. proto = parent;
  139. parent = null;
  140. }
  141. var childProto;
  142. if (parent) {
  143. var fn = function () {};
  144. fn.prototype = parent.prototype;
  145. childProto = new fn();
  146. _each(proto, function(key, val) {
  147. childProto[key] = val;
  148. });
  149. } else {
  150. childProto = proto;
  151. }
  152. childProto.constructor = child;
  153. child.prototype = childProto;
  154. child.parent = parent ? parent.prototype : null;
  155. }
  156. function _json(text) {
  157. var match;
  158. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  159. text = match[0];
  160. }
  161. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  162. cx.lastIndex = 0;
  163. if (cx.test(text)) {
  164. text = text.replace(cx, function (a) {
  165. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  166. });
  167. }
  168. if (/^[\],:{}\s]*$/.
  169. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  170. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  171. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  172. return eval('(' + text + ')');
  173. }
  174. throw 'JSON parse error';
  175. }
  176. var _round = Math.round;
  177. var K = {
  178. DEBUG : false,
  179. VERSION : _VERSION,
  180. IE : _IE,
  181. GECKO : _GECKO,
  182. WEBKIT : _WEBKIT,
  183. OPERA : _OPERA,
  184. V : _V,
  185. TIME : _TIME,
  186. each : _each,
  187. isArray : _isArray,
  188. isFunction : _isFunction,
  189. inArray : _inArray,
  190. inString : _inString,
  191. trim : _trim,
  192. addUnit : _addUnit,
  193. removeUnit : _removeUnit,
  194. escape : _escape,
  195. unescape : _unescape,
  196. toCamel : _toCamel,
  197. toHex : _toHex,
  198. toMap : _toMap,
  199. toArray : _toArray,
  200. undef : _undef,
  201. invalidUrl : _invalidUrl,
  202. addParam : _addParam,
  203. extend : _extend,
  204. json : _json
  205. };
  206. 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'),
  207. _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'),
  208. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  209. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  210. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  211. _PRE_TAG_MAP = _toMap('pre,style,script'),
  212. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  213. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  214. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  215. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  216. function _getBasePath() {
  217. var els = document.getElementsByTagName('script'), src;
  218. for (var i = 0, len = els.length; i < len; i++) {
  219. src = els[i].src || '';
  220. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  221. return src.substring(0, src.lastIndexOf('/') + 1);
  222. }
  223. }
  224. return '';
  225. }
  226. K.basePath = _getBasePath();
  227. K.options = {
  228. designMode : true,
  229. fullscreenMode : false,
  230. filterMode : true,
  231. wellFormatMode : true,
  232. shadowMode : true,
  233. loadStyleMode : true,
  234. basePath : K.basePath,
  235. themesPath : K.basePath + 'themes/',
  236. langPath : K.basePath + 'lang/',
  237. pluginsPath : K.basePath + 'plugins/',
  238. themeType : 'default',
  239. langType : 'zh_CN',
  240. urlType : '',
  241. newlineTag : 'p',
  242. resizeType : 2,
  243. syncType : 'form',
  244. pasteType : 2,
  245. dialogAlignType : 'page',
  246. useContextmenu : true,
  247. fullscreenShortcut : false,
  248. bodyClass : 'ke-content',
  249. indentChar : '\t',
  250. cssPath : '',
  251. cssData : '',
  252. minWidth : 650,
  253. minHeight : 100,
  254. minChangeSize : 50,
  255. zIndex : 811213,
  256. items : [
  257. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  258. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  259. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  260. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  261. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  262. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  263. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  264. 'anchor', 'link', 'unlink', '|', 'about'
  265. ],
  266. noDisableItems : ['source', 'fullscreen'],
  267. colorTable : [
  268. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  269. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  270. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  271. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  272. ],
  273. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  274. htmlTags : {
  275. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  276. span : [
  277. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  278. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  279. ],
  280. div : [
  281. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  282. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  283. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  284. ],
  285. table: [
  286. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  287. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  288. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  289. '.width', '.height', '.border-collapse'
  290. ],
  291. 'td,th': [
  292. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  293. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  294. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  295. ],
  296. a : ['id', 'class', 'href', 'target', 'name'],
  297. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  298. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  299. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  300. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  301. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  302. ],
  303. pre : ['id', 'class'],
  304. hr : ['id', 'class', '.page-break-after'],
  305. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  306. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  307. },
  308. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  309. };
  310. var _useCapture = false;
  311. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  312. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  313. var _CHANGE_KEY_MAP = {};
  314. _each(_INPUT_KEY_MAP, function(key, val) {
  315. _CHANGE_KEY_MAP[key] = val;
  316. });
  317. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  318. _CHANGE_KEY_MAP[key] = val;
  319. });
  320. function _bindEvent(el, type, fn) {
  321. if (el.addEventListener){
  322. el.addEventListener(type, fn, _useCapture);
  323. } else if (el.attachEvent){
  324. el.attachEvent('on' + type, fn);
  325. }
  326. }
  327. function _unbindEvent(el, type, fn) {
  328. if (el.removeEventListener){
  329. el.removeEventListener(type, fn, _useCapture);
  330. } else if (el.detachEvent){
  331. el.detachEvent('on' + type, fn);
  332. }
  333. }
  334. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  335. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  336. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  337. function KEvent(el, event) {
  338. this.init(el, event);
  339. }
  340. _extend(KEvent, {
  341. init : function(el, event) {
  342. var self = this, doc = el.ownerDocument || el.document || el;
  343. self.event = event;
  344. _each(_EVENT_PROPS, function(key, val) {
  345. self[val] = event[val];
  346. });
  347. if (!self.target) {
  348. self.target = self.srcElement || doc;
  349. }
  350. if (self.target.nodeType === 3) {
  351. self.target = self.target.parentNode;
  352. }
  353. if (!self.relatedTarget && self.fromElement) {
  354. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  355. }
  356. if (self.pageX == null && self.clientX != null) {
  357. var d = doc.documentElement, body = doc.body;
  358. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  359. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  360. }
  361. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  362. self.which = self.charCode || self.keyCode;
  363. }
  364. if (!self.metaKey && self.ctrlKey) {
  365. self.metaKey = self.ctrlKey;
  366. }
  367. if (!self.which && self.button !== undefined) {
  368. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  369. }
  370. switch (self.which) {
  371. case 186 :
  372. self.which = 59;
  373. break;
  374. case 187 :
  375. case 107 :
  376. case 43 :
  377. self.which = 61;
  378. break;
  379. case 189 :
  380. case 45 :
  381. self.which = 109;
  382. break;
  383. case 42 :
  384. self.which = 106;
  385. break;
  386. case 47 :
  387. self.which = 111;
  388. break;
  389. case 78 :
  390. self.which = 110;
  391. break;
  392. }
  393. if (self.which >= 96 && self.which <= 105) {
  394. self.which -= 48;
  395. }
  396. },
  397. preventDefault : function() {
  398. var ev = this.event;
  399. if (ev.preventDefault) {
  400. ev.preventDefault();
  401. }
  402. ev.returnValue = false;
  403. },
  404. stopPropagation : function() {
  405. var ev = this.event;
  406. if (ev.stopPropagation) {
  407. ev.stopPropagation();
  408. }
  409. ev.cancelBubble = true;
  410. },
  411. stop : function() {
  412. this.preventDefault();
  413. this.stopPropagation();
  414. }
  415. });
  416. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  417. function _getId(el) {
  418. return el[_eventExpendo] || null;
  419. }
  420. function _setId(el) {
  421. el[_eventExpendo] = ++_eventId;
  422. return _eventId;
  423. }
  424. function _removeId(el) {
  425. try {
  426. delete el[_eventExpendo];
  427. } catch(e) {
  428. if (el.removeAttribute) {
  429. el.removeAttribute(_eventExpendo);
  430. }
  431. }
  432. }
  433. function _bind(el, type, fn) {
  434. if (type.indexOf(',') >= 0) {
  435. _each(type.split(','), function() {
  436. _bind(el, this, fn);
  437. });
  438. return;
  439. }
  440. var id = _getId(el);
  441. if (!id) {
  442. id = _setId(el);
  443. }
  444. if (_eventData[id] === undefined) {
  445. _eventData[id] = {};
  446. }
  447. var events = _eventData[id][type];
  448. if (events && events.length > 0) {
  449. _unbindEvent(el, type, events[0]);
  450. } else {
  451. _eventData[id][type] = [];
  452. _eventData[id].el = el;
  453. }
  454. events = _eventData[id][type];
  455. if (events.length === 0) {
  456. events[0] = function(e) {
  457. var kevent = e ? new KEvent(el, e) : undefined;
  458. _each(events, function(i, event) {
  459. if (i > 0 && event) {
  460. event.call(el, kevent);
  461. }
  462. });
  463. };
  464. }
  465. if (_inArray(fn, events) < 0) {
  466. events.push(fn);
  467. }
  468. _bindEvent(el, type, events[0]);
  469. }
  470. function _unbind(el, type, fn) {
  471. if (type && type.indexOf(',') >= 0) {
  472. _each(type.split(','), function() {
  473. _unbind(el, this, fn);
  474. });
  475. return;
  476. }
  477. var id = _getId(el);
  478. if (!id) {
  479. return;
  480. }
  481. if (type === undefined) {
  482. if (id in _eventData) {
  483. _each(_eventData[id], function(key, events) {
  484. if (key != 'el' && events.length > 0) {
  485. _unbindEvent(el, key, events[0]);
  486. }
  487. });
  488. delete _eventData[id];
  489. _removeId(el);
  490. }
  491. return;
  492. }
  493. if (!_eventData[id]) {
  494. return;
  495. }
  496. var events = _eventData[id][type];
  497. if (events && events.length > 0) {
  498. if (fn === undefined) {
  499. _unbindEvent(el, type, events[0]);
  500. delete _eventData[id][type];
  501. } else {
  502. _each(events, function(i, event) {
  503. if (i > 0 && event === fn) {
  504. events.splice(i, 1);
  505. }
  506. });
  507. if (events.length == 1) {
  508. _unbindEvent(el, type, events[0]);
  509. delete _eventData[id][type];
  510. }
  511. }
  512. var count = 0;
  513. _each(_eventData[id], function() {
  514. count++;
  515. });
  516. if (count < 2) {
  517. delete _eventData[id];
  518. _removeId(el);
  519. }
  520. }
  521. }
  522. function _fire(el, type) {
  523. if (type.indexOf(',') >= 0) {
  524. _each(type.split(','), function() {
  525. _fire(el, this);
  526. });
  527. return;
  528. }
  529. var id = _getId(el);
  530. if (!id) {
  531. return;
  532. }
  533. var events = _eventData[id][type];
  534. if (_eventData[id] && events && events.length > 0) {
  535. events[0]();
  536. }
  537. }
  538. function _ctrl(el, key, fn) {
  539. var self = this;
  540. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  541. _bind(el, 'keydown', function(e) {
  542. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  543. fn.call(el);
  544. e.stop();
  545. }
  546. });
  547. }
  548. var _readyFinished = false;
  549. function _ready(fn) {
  550. if (_readyFinished) {
  551. fn(KindEditor);
  552. return;
  553. }
  554. var loaded = false;
  555. function readyFunc() {
  556. if (!loaded) {
  557. loaded = true;
  558. fn(KindEditor);
  559. _readyFinished = true;
  560. }
  561. }
  562. function ieReadyFunc() {
  563. if (!loaded) {
  564. try {
  565. document.documentElement.doScroll('left');
  566. } catch(e) {
  567. setTimeout(ieReadyFunc, 100);
  568. return;
  569. }
  570. readyFunc();
  571. }
  572. }
  573. function ieReadyStateFunc() {
  574. if (document.readyState === 'complete') {
  575. readyFunc();
  576. }
  577. }
  578. if (document.addEventListener) {
  579. _bind(document, 'DOMContentLoaded', readyFunc);
  580. } else if (document.attachEvent) {
  581. _bind(document, 'readystatechange', ieReadyStateFunc);
  582. var toplevel = false;
  583. try {
  584. toplevel = window.frameElement == null;
  585. } catch(e) {}
  586. if (document.documentElement.doScroll && toplevel) {
  587. ieReadyFunc();
  588. }
  589. }
  590. _bind(window, 'load', readyFunc);
  591. }
  592. if (_IE) {
  593. window.attachEvent('onunload', function() {
  594. _each(_eventData, function(key, events) {
  595. if (events.el) {
  596. _unbind(events.el);
  597. }
  598. });
  599. });
  600. }
  601. K.ctrl = _ctrl;
  602. K.ready = _ready;
  603. function _getCssList(css) {
  604. var list = {},
  605. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  606. match;
  607. while ((match = reg.exec(css))) {
  608. var key = _trim(match[1].toLowerCase()),
  609. val = _trim(_toHex(match[2]));
  610. list[key] = val;
  611. }
  612. return list;
  613. }
  614. function _getAttrList(tag) {
  615. var list = {},
  616. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  617. match;
  618. while ((match = reg.exec(tag))) {
  619. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  620. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  621. list[key] = val;
  622. }
  623. return list;
  624. }
  625. function _addClassToTag(tag, className) {
  626. if (/\s+class\s*=/.test(tag)) {
  627. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  628. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  629. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  630. } else {
  631. return $0;
  632. }
  633. });
  634. } else {
  635. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  636. }
  637. return tag;
  638. }
  639. function _formatCss(css) {
  640. var str = '';
  641. _each(_getCssList(css), function(key, val) {
  642. str += key + ':' + val + ';';
  643. });
  644. return str;
  645. }
  646. function _formatUrl(url, mode, host, pathname) {
  647. mode = 'domain';
  648. if (url.substr(0, 5) != 'data:') {
  649. url = url.replace(/([^:])\/\//g, '$1/');
  650. }
  651. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  652. return url;
  653. }
  654. host = host || location.protocol + '//' + location.host;
  655. if (pathname === undefined) {
  656. var m = location.pathname.match(/^(\/.*)\//);
  657. pathname = m ? m[1] : '';
  658. }
  659. var match;
  660. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  661. if (match[1] !== host) {
  662. return url;
  663. }
  664. } else if (/^\w+:/.test(url)) {
  665. return url;
  666. }
  667. function getRealPath(path) {
  668. var parts = path.split('/'), paths = [];
  669. for (var i = 0, len = parts.length; i < len; i++) {
  670. var part = parts[i];
  671. if (part == '..') {
  672. if (paths.length > 0) {
  673. paths.pop();
  674. }
  675. } else if (part !== '' && part != '.') {
  676. paths.push(part);
  677. }
  678. }
  679. return '/' + paths.join('/');
  680. }
  681. if (/^\//.test(url)) {
  682. url = host + getRealPath(url.substr(1));
  683. } else if (!/^\w+:\/\//.test(url)) {
  684. url = host + getRealPath(pathname + '/' + url);
  685. }
  686. function getRelativePath(path, depth) {
  687. if (url.substr(0, path.length) === path) {
  688. var arr = [];
  689. for (var i = 0; i < depth; i++) {
  690. arr.push('..');
  691. }
  692. var prefix = '.';
  693. if (arr.length > 0) {
  694. prefix += '/' + arr.join('/');
  695. }
  696. if (pathname == '/') {
  697. prefix += '/';
  698. }
  699. return prefix + url.substr(path.length);
  700. } else {
  701. if ((match = /^(.*)\//.exec(path))) {
  702. return getRelativePath(match[1], ++depth);
  703. }
  704. }
  705. }
  706. if (mode === 'relative') {
  707. url = getRelativePath(host + pathname, 0).substr(2);
  708. } else if (mode === 'absolute') {
  709. if (url.substr(0, host.length) === host) {
  710. url = url.substr(host.length);
  711. }
  712. }
  713. return url;
  714. }
  715. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  716. if (html == null) {
  717. html = '';
  718. }
  719. urlType = urlType || '';
  720. wellFormatted = _undef(wellFormatted, false);
  721. indentChar = _undef(indentChar, '\t');
  722. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  723. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  724. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  725. });
  726. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  727. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  728. html = html.replace(/\u200B/g, '');
  729. html = html.replace(/\u00A9/g, '&copy;');
  730. html = html.replace(/<[^>]+>/g, function($0) {
  731. return $0.replace(/\s+/g, ' ');
  732. });
  733. var htmlTagMap = {};
  734. if (htmlTags) {
  735. _each(htmlTags, function(key, val) {
  736. var arr = key.split(',');
  737. for (var i = 0, len = arr.length; i < len; i++) {
  738. htmlTagMap[arr[i]] = _toMap(val);
  739. }
  740. });
  741. if (!htmlTagMap.script) {
  742. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  743. }
  744. if (!htmlTagMap.style) {
  745. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  746. }
  747. }
  748. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  749. var tagStack = [];
  750. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  751. var full = $0,
  752. startNewline = $1 || '',
  753. startSlash = $2 || '',
  754. tagName = $3.toLowerCase(),
  755. attr = $4 || '',
  756. endSlash = $5 ? ' ' + $5 : '',
  757. endNewline = $6 || '';
  758. if (htmlTags && !htmlTagMap[tagName]) {
  759. return '';
  760. }
  761. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  762. endSlash = ' /';
  763. }
  764. if (_INLINE_TAG_MAP[tagName]) {
  765. if (startNewline) {
  766. startNewline = ' ';
  767. }
  768. if (endNewline) {
  769. endNewline = ' ';
  770. }
  771. }
  772. if (_PRE_TAG_MAP[tagName]) {
  773. if (startSlash) {
  774. endNewline = '\n';
  775. } else {
  776. startNewline = '\n';
  777. }
  778. }
  779. if (wellFormatted && tagName == 'br') {
  780. endNewline = '\n';
  781. }
  782. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  783. if (wellFormatted) {
  784. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  785. tagStack.pop();
  786. } else {
  787. tagStack.push(tagName);
  788. }
  789. startNewline = '\n';
  790. endNewline = '\n';
  791. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  792. startNewline += indentChar;
  793. if (!startSlash) {
  794. endNewline += indentChar;
  795. }
  796. }
  797. if (endSlash) {
  798. tagStack.pop();
  799. } else if (!startSlash) {
  800. endNewline += indentChar;
  801. }
  802. } else {
  803. startNewline = endNewline = '';
  804. }
  805. }
  806. if (attr !== '') {
  807. var attrMap = _getAttrList(full);
  808. if (tagName === 'font') {
  809. var fontStyleMap = {}, fontStyle = '';
  810. _each(attrMap, function(key, val) {
  811. if (key === 'color') {
  812. fontStyleMap.color = val;
  813. delete attrMap[key];
  814. }
  815. if (key === 'size') {
  816. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  817. delete attrMap[key];
  818. }
  819. if (key === 'face') {
  820. fontStyleMap['font-family'] = val;
  821. delete attrMap[key];
  822. }
  823. if (key === 'style') {
  824. fontStyle = val;
  825. }
  826. });
  827. if (fontStyle && !/;$/.test(fontStyle)) {
  828. fontStyle += ';';
  829. }
  830. _each(fontStyleMap, function(key, val) {
  831. if (val === '') {
  832. return;
  833. }
  834. if (/\s/.test(val)) {
  835. val = "'" + val + "'";
  836. }
  837. fontStyle += key + ':' + val + ';';
  838. });
  839. attrMap.style = fontStyle;
  840. }
  841. _each(attrMap, function(key, val) {
  842. if (_FILL_ATTR_MAP[key]) {
  843. attrMap[key] = key;
  844. }
  845. if (_inArray(key, ['src', 'href']) >= 0) {
  846. attrMap[key] = _formatUrl(val, urlType);
  847. }
  848. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  849. tagName === 'body' && key === 'contenteditable' ||
  850. /^kindeditor_\d+$/.test(key)) {
  851. delete attrMap[key];
  852. }
  853. if (key === 'style' && val !== '') {
  854. var styleMap = _getCssList(val);
  855. _each(styleMap, function(k, v) {
  856. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  857. delete styleMap[k];
  858. }
  859. });
  860. var style = '';
  861. _each(styleMap, function(k, v) {
  862. style += k + ':' + v + ';';
  863. });
  864. attrMap.style = style;
  865. }
  866. });
  867. attr = '';
  868. _each(attrMap, function(key, val) {
  869. if (key === 'style' && val === '') {
  870. return;
  871. }
  872. val = val.replace(/"/g, '&quot;');
  873. attr += ' ' + key + '="' + val + '"';
  874. });
  875. }
  876. if (tagName === 'font') {
  877. tagName = 'span';
  878. }
  879. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  880. });
  881. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  882. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  883. });
  884. html = html.replace(/\n\s*\n/g, '\n');
  885. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  886. return _trim(html);
  887. }
  888. function _clearMsWord(html, htmlTags) {
  889. html = html.replace(/<meta[\s\S]*?>/ig, '')
  890. .replace(/<![\s\S]*?>/ig, '')
  891. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  892. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  893. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  894. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  895. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  896. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  897. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  898. });
  899. return _formatHtml(html, htmlTags);
  900. }
  901. function _mediaType(src) {
  902. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  903. return 'audio/x-pn-realaudio-plugin';
  904. }
  905. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  906. return 'application/x-shockwave-flash';
  907. }
  908. return 'video/x-ms-asf-plugin';
  909. }
  910. function _mediaClass(type) {
  911. if (/realaudio/i.test(type)) {
  912. return 'ke-rm';
  913. }
  914. if (/flash/i.test(type)) {
  915. return 'ke-flash';
  916. }
  917. return 'ke-media';
  918. }
  919. function _mediaAttrs(srcTag) {
  920. return _getAttrList(unescape(srcTag));
  921. }
  922. function _mediaEmbed(attrs) {
  923. var html = '<embed ';
  924. _each(attrs, function(key, val) {
  925. html += key + '="' + val + '" ';
  926. });
  927. html += '/>';
  928. return html;
  929. }
  930. function _mediaImg(blankPath, attrs) {
  931. var width = attrs.width,
  932. height = attrs.height,
  933. type = attrs.type || _mediaType(attrs.src),
  934. srcTag = _mediaEmbed(attrs),
  935. style = '';
  936. if (/\D/.test(width)) {
  937. style += 'width:' + width + ';';
  938. } else if (width > 0) {
  939. style += 'width:' + width + 'px;';
  940. }
  941. if (/\D/.test(height)) {
  942. style += 'height:' + height + ';';
  943. } else if (height > 0) {
  944. style += 'height:' + height + 'px;';
  945. }
  946. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  947. if (style !== '') {
  948. html += 'style="' + style + '" ';
  949. }
  950. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  951. return html;
  952. }
  953. function _tmpl(str, data) {
  954. var fn = new Function("obj",
  955. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  956. "with(obj){p.push('" +
  957. str.replace(/[\r\t\n]/g, " ")
  958. .split("<%").join("\t")
  959. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  960. .replace(/\t=(.*?)%>/g, "',$1,'")
  961. .split("\t").join("');")
  962. .split("%>").join("p.push('")
  963. .split("\r").join("\\'") + "');}return p.join('');");
  964. return data ? fn(data) : fn;
  965. }
  966. K.formatUrl = _formatUrl;
  967. K.formatHtml = _formatHtml;
  968. K.getCssList = _getCssList;
  969. K.getAttrList = _getAttrList;
  970. K.mediaType = _mediaType;
  971. K.mediaAttrs = _mediaAttrs;
  972. K.mediaEmbed = _mediaEmbed;
  973. K.mediaImg = _mediaImg;
  974. K.clearMsWord = _clearMsWord;
  975. K.tmpl = _tmpl;
  976. function _contains(nodeA, nodeB) {
  977. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  978. return true;
  979. }
  980. while ((nodeB = nodeB.parentNode)) {
  981. if (nodeB == nodeA) {
  982. return true;
  983. }
  984. }
  985. return false;
  986. }
  987. var _getSetAttrDiv = document.createElement('div');
  988. _getSetAttrDiv.setAttribute('className', 't');
  989. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  990. function _getAttr(el, key) {
  991. key = key.toLowerCase();
  992. var val = null;
  993. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  994. var div = el.ownerDocument.createElement('div');
  995. div.appendChild(el.cloneNode(false));
  996. var list = _getAttrList(_unescape(div.innerHTML));
  997. if (key in list) {
  998. val = list[key];
  999. }
  1000. } else {
  1001. try {
  1002. val = el.getAttribute(key, 2);
  1003. } catch(e) {
  1004. val = el.getAttribute(key, 1);
  1005. }
  1006. }
  1007. if (key === 'style' && val !== null) {
  1008. val = _formatCss(val);
  1009. }
  1010. return val;
  1011. }
  1012. function _queryAll(expr, root) {
  1013. var exprList = expr.split(',');
  1014. if (exprList.length > 1) {
  1015. var mergedResults = [];
  1016. _each(exprList, function() {
  1017. _each(_queryAll(this, root), function() {
  1018. if (_inArray(this, mergedResults) < 0) {
  1019. mergedResults.push(this);
  1020. }
  1021. });
  1022. });
  1023. return mergedResults;
  1024. }
  1025. root = root || document;
  1026. function escape(str) {
  1027. if (typeof str != 'string') {
  1028. return str;
  1029. }
  1030. return str.replace(/([^\w\-])/g, '\\$1');
  1031. }
  1032. function stripslashes(str) {
  1033. return str.replace(/\\/g, '');
  1034. }
  1035. function cmpTag(tagA, tagB) {
  1036. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1037. }
  1038. function byId(id, tag, root) {
  1039. var arr = [],
  1040. doc = root.ownerDocument || root,
  1041. el = doc.getElementById(stripslashes(id));
  1042. if (el) {
  1043. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1044. arr.push(el);
  1045. }
  1046. }
  1047. return arr;
  1048. }
  1049. function byClass(className, tag, root) {
  1050. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1051. if (root.getElementsByClassName) {
  1052. els = root.getElementsByClassName(stripslashes(className));
  1053. for (i = 0, len = els.length; i < len; i++) {
  1054. el = els[i];
  1055. if (cmpTag(tag, el.nodeName)) {
  1056. arr.push(el);
  1057. }
  1058. }
  1059. } else if (doc.querySelectorAll) {
  1060. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1061. for (i = 0, len = els.length; i < len; i++) {
  1062. el = els[i];
  1063. if (_contains(root, el)) {
  1064. arr.push(el);
  1065. }
  1066. }
  1067. } else {
  1068. els = root.getElementsByTagName(tag);
  1069. className = ' ' + className + ' ';
  1070. for (i = 0, len = els.length; i < len; i++) {
  1071. el = els[i];
  1072. if (el.nodeType == 1) {
  1073. var cls = el.className;
  1074. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1075. arr.push(el);
  1076. }
  1077. }
  1078. }
  1079. }
  1080. return arr;
  1081. }
  1082. function byName(name, tag, root) {
  1083. var arr = [], doc = root.ownerDocument || root,
  1084. els = doc.getElementsByName(stripslashes(name)), el;
  1085. for (var i = 0, len = els.length; i < len; i++) {
  1086. el = els[i];
  1087. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1088. if (el.getAttribute('name') !== null) {
  1089. arr.push(el);
  1090. }
  1091. }
  1092. }
  1093. return arr;
  1094. }
  1095. function byAttr(key, val, tag, root) {
  1096. var arr = [], els = root.getElementsByTagName(tag), el;
  1097. for (var i = 0, len = els.length; i < len; i++) {
  1098. el = els[i];
  1099. if (el.nodeType == 1) {
  1100. if (val === null) {
  1101. if (_getAttr(el, key) !== null) {
  1102. arr.push(el);
  1103. }
  1104. } else {
  1105. if (val === escape(_getAttr(el, key))) {
  1106. arr.push(el);
  1107. }
  1108. }
  1109. }
  1110. }
  1111. return arr;
  1112. }
  1113. function select(expr, root) {
  1114. var arr = [], matches;
  1115. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1116. var tag = matches ? matches[1] : '*';
  1117. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1118. arr = byId(matches[1], tag, root);
  1119. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1120. arr = byClass(matches[1], tag, root);
  1121. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1122. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1123. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1124. var key = matches[1].toLowerCase(), val = matches[2];
  1125. if (key === 'id') {
  1126. arr = byId(val, tag, root);
  1127. } else if (key === 'class') {
  1128. arr = byClass(val, tag, root);
  1129. } else if (key === 'name') {
  1130. arr = byName(val, tag, root);
  1131. } else {
  1132. arr = byAttr(key, val, tag, root);
  1133. }
  1134. } else {
  1135. var els = root.getElementsByTagName(tag), el;
  1136. for (var i = 0, len = els.length; i < len; i++) {
  1137. el = els[i];
  1138. if (el.nodeType == 1) {
  1139. arr.push(el);
  1140. }
  1141. }
  1142. }
  1143. return arr;
  1144. }
  1145. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1146. while ((arr = re.exec(expr))) {
  1147. if (arr[1] !== ' ') {
  1148. parts.push(arr[1]);
  1149. }
  1150. }
  1151. var results = [];
  1152. if (parts.length == 1) {
  1153. return select(parts[0], root);
  1154. }
  1155. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1156. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1157. part = parts[i];
  1158. if (part === '>') {
  1159. isChild = true;
  1160. continue;
  1161. }
  1162. if (i > 0) {
  1163. els = [];
  1164. for (j = 0, len = results.length; j < len; j++) {
  1165. val = results[j];
  1166. subResults = select(part, val);
  1167. for (k = 0, l = subResults.length; k < l; k++) {
  1168. v = subResults[k];
  1169. if (isChild) {
  1170. if (val === v.parentNode) {
  1171. els.push(v);
  1172. }
  1173. } else {
  1174. els.push(v);
  1175. }
  1176. }
  1177. }
  1178. results = els;
  1179. } else {
  1180. results = select(part, root);
  1181. }
  1182. if (results.length === 0) {
  1183. return [];
  1184. }
  1185. }
  1186. return results;
  1187. }
  1188. function _query(expr, root) {
  1189. var arr = _queryAll(expr, root);
  1190. return arr.length > 0 ? arr[0] : null;
  1191. }
  1192. K.query = _query;
  1193. K.queryAll = _queryAll;
  1194. function _get(val) {
  1195. return K(val)[0];
  1196. }
  1197. function _getDoc(node) {
  1198. if (!node) {
  1199. return document;
  1200. }
  1201. return node.ownerDocument || node.document || node;
  1202. }
  1203. function _getWin(node) {
  1204. if (!node) {
  1205. return window;
  1206. }
  1207. var doc = _getDoc(node);
  1208. return doc.parentWindow || doc.defaultView;
  1209. }
  1210. function _setHtml(el, html) {
  1211. if (el.nodeType != 1) {
  1212. return;
  1213. }
  1214. var doc = _getDoc(el);
  1215. try {
  1216. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1217. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1218. temp.parentNode.removeChild(temp);
  1219. } catch(e) {
  1220. K(el).empty();
  1221. K('@' + html, doc).each(function() {
  1222. el.appendChild(this);
  1223. });
  1224. }
  1225. }
  1226. function _hasClass(el, cls) {
  1227. return _inString(cls, el.className, ' ');
  1228. }
  1229. function _setAttr(el, key, val) {
  1230. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1231. key = 'className';
  1232. }
  1233. el.setAttribute(key, '' + val);
  1234. }
  1235. function _removeAttr(el, key) {
  1236. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1237. key = 'className';
  1238. }
  1239. _setAttr(el, key, '');
  1240. el.removeAttribute(key);
  1241. }
  1242. function _getNodeName(node) {
  1243. if (!node || !node.nodeName) {
  1244. return '';
  1245. }
  1246. return node.nodeName.toLowerCase();
  1247. }
  1248. function _computedCss(el, key) {
  1249. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1250. if (win.getComputedStyle) {
  1251. var style = win.getComputedStyle(el, null);
  1252. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1253. } else if (el.currentStyle) {
  1254. val = el.currentStyle[camelKey] || el.style[camelKey];
  1255. }
  1256. return val;
  1257. }
  1258. function _hasVal(node) {
  1259. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1260. }
  1261. function _docElement(doc) {
  1262. doc = doc || document;
  1263. return _QUIRKS ? doc.body : doc.documentElement;
  1264. }
  1265. function _docHeight(doc) {
  1266. var el = _docElement(doc);
  1267. return Math.max(el.scrollHeight, el.clientHeight);
  1268. }
  1269. function _docWidth(doc) {
  1270. var el = _docElement(doc);
  1271. return Math.max(el.scrollWidth, el.clientWidth);
  1272. }
  1273. function _getScrollPos(doc) {
  1274. doc = doc || document;
  1275. var x, y;
  1276. if (_IE || _OPERA) {
  1277. x = _docElement(doc).scrollLeft;
  1278. y = _docElement(doc).scrollTop;
  1279. } else {
  1280. x = _getWin(doc).scrollX;
  1281. y = _getWin(doc).scrollY;
  1282. }
  1283. return {x : x, y : y};
  1284. }
  1285. function KNode(node) {
  1286. this.init(node);
  1287. }
  1288. _extend(KNode, {
  1289. init : function(node) {
  1290. var self = this;
  1291. node = _isArray(node) ? node : [node];
  1292. var length = 0;
  1293. for (var i = 0, len = node.length; i < len; i++) {
  1294. if (node[i]) {
  1295. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1296. length++;
  1297. }
  1298. }
  1299. self.length = length;
  1300. self.doc = _getDoc(self[0]);
  1301. self.name = _getNodeName(self[0]);
  1302. self.type = self.length > 0 ? self[0].nodeType : null;
  1303. self.win = _getWin(self[0]);
  1304. },
  1305. each : function(fn) {
  1306. var self = this;
  1307. for (var i = 0; i < self.length; i++) {
  1308. if (fn.call(self[i], i, self[i]) === false) {
  1309. return self;
  1310. }
  1311. }
  1312. return self;
  1313. },
  1314. bind : function(type, fn) {
  1315. this.each(function() {
  1316. _bind(this, type, fn);
  1317. });
  1318. return this;
  1319. },
  1320. unbind : function(type, fn) {
  1321. this.each(function() {
  1322. _unbind(this, type, fn);
  1323. });
  1324. return this;
  1325. },
  1326. fire : function(type) {
  1327. if (this.length < 1) {
  1328. return this;
  1329. }
  1330. _fire(this[0], type);
  1331. return this;
  1332. },
  1333. hasAttr : function(key) {
  1334. if (this.length < 1) {
  1335. return false;
  1336. }
  1337. return !!_getAttr(this[0], key);
  1338. },
  1339. attr : function(key, val) {
  1340. var self = this;
  1341. if (key === undefined) {
  1342. return _getAttrList(self.outer());
  1343. }
  1344. if (typeof key === 'object') {
  1345. _each(key, function(k, v) {
  1346. self.attr(k, v);
  1347. });
  1348. return self;
  1349. }
  1350. if (val === undefined) {
  1351. val = self.length < 1 ? null : _getAttr(self[0], key);
  1352. return val === null ? '' : val;
  1353. }
  1354. self.each(function() {
  1355. _setAttr(this, key, val);
  1356. });
  1357. return self;
  1358. },
  1359. removeAttr : function(key) {
  1360. this.each(function() {
  1361. _removeAttr(this, key);
  1362. });
  1363. return this;
  1364. },
  1365. get : function(i) {
  1366. if (this.length < 1) {
  1367. return null;
  1368. }
  1369. return this[i || 0];
  1370. },
  1371. eq : function(i) {
  1372. if (this.length < 1) {
  1373. return null;
  1374. }
  1375. return this[i] ? new KNode(this[i]) : null;
  1376. },
  1377. hasClass : function(cls) {
  1378. if (this.length < 1) {
  1379. return false;
  1380. }
  1381. return _hasClass(this[0], cls);
  1382. },
  1383. addClass : function(cls) {
  1384. this.each(function() {
  1385. if (!_hasClass(this, cls)) {
  1386. this.className = _trim(this.className + ' ' + cls);
  1387. }
  1388. });
  1389. return this;
  1390. },
  1391. removeClass : function(cls) {
  1392. this.each(function() {
  1393. if (_hasClass(this, cls)) {
  1394. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1395. }
  1396. });
  1397. return this;
  1398. },
  1399. html : function(val) {
  1400. var self = this;
  1401. if (val === undefined) {
  1402. if (self.length < 1 || self.type != 1) {
  1403. return '';
  1404. }
  1405. return _formatHtml(self[0].innerHTML);
  1406. }
  1407. self.each(function() {
  1408. _setHtml(this, val);
  1409. });
  1410. return self;
  1411. },
  1412. text : function() {
  1413. var self = this;
  1414. if (self.length < 1) {
  1415. return '';
  1416. }
  1417. return _IE ? self[0].innerText : self[0].textContent;
  1418. },
  1419. hasVal : function() {
  1420. if (this.length < 1) {
  1421. return false;
  1422. }
  1423. return _hasVal(this[0]);
  1424. },
  1425. val : function(val) {
  1426. var self = this;
  1427. if (val === undefined) {
  1428. if (self.length < 1) {
  1429. return '';
  1430. }
  1431. return self.hasVal() ? self[0].value : self.attr('value');
  1432. } else {
  1433. self.each(function() {
  1434. if (_hasVal(this)) {
  1435. this.value = val;
  1436. } else {
  1437. _setAttr(this, 'value' , val);
  1438. }
  1439. });
  1440. return self;
  1441. }
  1442. },
  1443. css : function(key, val) {
  1444. var self = this;
  1445. if (key === undefined) {
  1446. return _getCssList(self.attr('style'));
  1447. }
  1448. if (typeof key === 'object') {
  1449. _each(key, function(k, v) {
  1450. self.css(k, v);
  1451. });
  1452. return self;
  1453. }
  1454. if (val === undefined) {
  1455. if (self.length < 1) {
  1456. return '';
  1457. }
  1458. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1459. }
  1460. self.each(function() {
  1461. this.style[_toCamel(key)] = val;
  1462. });
  1463. return self;
  1464. },
  1465. width : function(val) {
  1466. var self = this;
  1467. if (val === undefined) {
  1468. if (self.length < 1) {
  1469. return 0;
  1470. }
  1471. return self[0].offsetWidth;
  1472. }
  1473. return self.css('width', _addUnit(val));
  1474. },
  1475. height : function(val) {
  1476. var self = this;
  1477. if (val === undefined) {
  1478. if (self.length < 1) {
  1479. return 0;
  1480. }
  1481. return self[0].offsetHeight;
  1482. }
  1483. return self.css('height', _addUnit(val));
  1484. },
  1485. opacity : function(val) {
  1486. this.each(function() {
  1487. if (this.style.opacity === undefined) {
  1488. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1489. } else {
  1490. this.style.opacity = val == 1 ? '' : val;
  1491. }
  1492. });
  1493. return this;
  1494. },
  1495. data : function(key, val) {
  1496. var self = this;
  1497. key = 'kindeditor_data_' + key;
  1498. if (val === undefined) {
  1499. if (self.length < 1) {
  1500. return null;
  1501. }
  1502. return self[0][key];
  1503. }
  1504. this.each(function() {
  1505. this[key] = val;
  1506. });
  1507. return self;
  1508. },
  1509. pos : function() {
  1510. var self = this, node = self[0], x = 0, y = 0;
  1511. if (node) {
  1512. if (node.getBoundingClientRect) {
  1513. var box = node.getBoundingClientRect(),
  1514. pos = _getScrollPos(self.doc);
  1515. x = box.left + pos.x;
  1516. y = box.top + pos.y;
  1517. } else {
  1518. while (node) {
  1519. x += node.offsetLeft;
  1520. y += node.offsetTop;
  1521. node = node.offsetParent;
  1522. }
  1523. }
  1524. }
  1525. return {x : _round(x), y : _round(y)};
  1526. },
  1527. clone : function(bool) {
  1528. if (this.length < 1) {
  1529. return new KNode([]);
  1530. }
  1531. return new KNode(this[0].cloneNode(bool));
  1532. },
  1533. append : function(expr) {
  1534. this.each(function() {
  1535. if (this.appendChild) {
  1536. this.appendChild(_get(expr));
  1537. }
  1538. });
  1539. return this;
  1540. },
  1541. appendTo : function(expr) {
  1542. this.each(function() {
  1543. _get(expr).appendChild(this);
  1544. });
  1545. return this;
  1546. },
  1547. before : function(expr) {
  1548. this.each(function() {
  1549. this.parentNode.insertBefore(_get(expr), this);
  1550. });
  1551. return this;
  1552. },
  1553. after : function(expr) {
  1554. this.each(function() {
  1555. if (this.nextSibling) {
  1556. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1557. } else {
  1558. this.parentNode.appendChild(_get(expr));
  1559. }
  1560. });
  1561. return this;
  1562. },
  1563. replaceWith : function(expr) {
  1564. var nodes = [];
  1565. this.each(function(i, node) {
  1566. _unbind(node);
  1567. var newNode = _get(expr);
  1568. node.parentNode.replaceChild(newNode, node);
  1569. nodes.push(newNode);
  1570. });
  1571. return K(nodes);
  1572. },
  1573. empty : function() {
  1574. var self = this;
  1575. self.each(function(i, node) {
  1576. var child = node.firstChild;
  1577. while (child) {
  1578. if (!node.parentNode) {
  1579. return;
  1580. }
  1581. var next = child.nextSibling;
  1582. child.parentNode.removeChild(child);
  1583. child = next;
  1584. }
  1585. });
  1586. return self;
  1587. },
  1588. remove : function(keepChilds) {
  1589. var self = this;
  1590. self.each(function(i, node) {
  1591. if (!node.parentNode) {
  1592. return;
  1593. }
  1594. _unbind(node);
  1595. if (keepChilds) {
  1596. var child = node.firstChild;
  1597. while (child) {
  1598. var next = child.nextSibling;
  1599. node.parentNode.insertBefore(child, node);
  1600. child = next;
  1601. }
  1602. }
  1603. node.parentNode.removeChild(node);
  1604. delete self[i];
  1605. });
  1606. self.length = 0;
  1607. return self;
  1608. },
  1609. show : function(val) {
  1610. var self = this;
  1611. if (val === undefined) {
  1612. val = self._originDisplay || '';
  1613. }
  1614. if (self.css('display') != 'none') {
  1615. return self;
  1616. }
  1617. return self.css('display', val);
  1618. },
  1619. hide : function() {
  1620. var self = this;
  1621. if (self.length < 1) {
  1622. return self;
  1623. }
  1624. self._originDisplay = self[0].style.display;
  1625. return self.css('display', 'none');
  1626. },
  1627. outer : function() {
  1628. var self = this;
  1629. if (self.length < 1) {
  1630. return '';
  1631. }
  1632. var div = self.doc.createElement('div'), html;
  1633. div.appendChild(self[0].cloneNode(true));
  1634. html = _formatHtml(div.innerHTML);
  1635. div = null;
  1636. return html;
  1637. },
  1638. isSingle : function() {
  1639. return !!_SINGLE_TAG_MAP[this.name];
  1640. },
  1641. isInline : function() {
  1642. return !!_INLINE_TAG_MAP[this.name];
  1643. },
  1644. isBlock : function() {
  1645. return !!_BLOCK_TAG_MAP[this.name];
  1646. },
  1647. isStyle : function() {
  1648. return !!_STYLE_TAG_MAP[this.name];
  1649. },
  1650. isControl : function() {
  1651. return !!_CONTROL_TAG_MAP[this.name];
  1652. },
  1653. contains : function(otherNode) {
  1654. if (this.length < 1) {
  1655. return false;
  1656. }
  1657. return _contains(this[0], _get(otherNode));
  1658. },
  1659. parent : function() {
  1660. if (this.length < 1) {
  1661. return null;
  1662. }
  1663. var node = this[0].parentNode;
  1664. return node ? new KNode(node) : null;
  1665. },
  1666. children : function() {
  1667. if (this.length < 1) {
  1668. return new KNode([]);
  1669. }
  1670. var list = [], child = this[0].firstChild;
  1671. while (child) {
  1672. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1673. list.push(child);
  1674. }
  1675. child = child.nextSibling;
  1676. }
  1677. return new KNode(list);
  1678. },
  1679. first : function() {
  1680. var list = this.children();
  1681. return list.length > 0 ? list.eq(0) : null;
  1682. },
  1683. last : function() {
  1684. var list = this.children();
  1685. return list.length > 0 ? list.eq(list.length - 1) : null;
  1686. },
  1687. index : function() {
  1688. if (this.length < 1) {
  1689. return -1;
  1690. }
  1691. var i = -1, sibling = this[0];
  1692. while (sibling) {
  1693. i++;
  1694. sibling = sibling.previousSibling;
  1695. }
  1696. return i;
  1697. },
  1698. prev : function() {
  1699. if (this.length < 1) {
  1700. return null;
  1701. }
  1702. var node = this[0].previousSibling;
  1703. return node ? new KNode(node) : null;
  1704. },
  1705. next : function() {
  1706. if (this.length < 1) {
  1707. return null;
  1708. }
  1709. var node = this[0].nextSibling;
  1710. return node ? new KNode(node) : null;
  1711. },
  1712. scan : function(fn, order) {
  1713. if (this.length < 1) {
  1714. return;
  1715. }
  1716. order = (order === undefined) ? true : order;
  1717. function walk(node) {
  1718. var n = order ? node.firstChild : node.lastChild;
  1719. while (n) {
  1720. var next = order ? n.nextSibling : n.previousSibling;
  1721. if (fn(n) === false) {
  1722. return false;
  1723. }
  1724. if (walk(n) === false) {
  1725. return false;
  1726. }
  1727. n = next;
  1728. }
  1729. }
  1730. walk(this[0]);
  1731. return this;
  1732. }
  1733. });
  1734. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1735. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1736. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1737. KNode.prototype[type] = function(fn) {
  1738. return fn ? this.bind(type, fn) : this.fire(type);
  1739. };
  1740. });
  1741. var _K = K;
  1742. K = function(expr, root) {
  1743. if (expr === undefined || expr === null) {
  1744. return;
  1745. }
  1746. function newNode(node) {
  1747. if (!node[0]) {
  1748. node = [];
  1749. }
  1750. return new KNode(node);
  1751. }
  1752. if (typeof expr === 'string') {
  1753. if (root) {
  1754. root = _get(root);
  1755. }
  1756. var length = expr.length;
  1757. if (expr.charAt(0) === '@') {
  1758. expr = expr.substr(1);
  1759. }
  1760. if (expr.length !== length || /<.+>/.test(expr)) {
  1761. var doc = root ? root.ownerDocument || root : document,
  1762. div = doc.createElement('div'), list = [];
  1763. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1764. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1765. var child = div.childNodes[i];
  1766. if (child.id == '__kindeditor_temp_tag__') {
  1767. continue;
  1768. }
  1769. list.push(child);
  1770. }
  1771. return newNode(list);
  1772. }
  1773. return newNode(_queryAll(expr, root));
  1774. }
  1775. if (expr && expr.constructor === KNode) {
  1776. return expr;
  1777. }
  1778. if (expr.toArray) {
  1779. expr = expr.toArray();
  1780. }
  1781. if (_isArray(expr)) {
  1782. return newNode(expr);
  1783. }
  1784. return newNode(_toArray(arguments));
  1785. };
  1786. _each(_K, function(key, val) {
  1787. K[key] = val;
  1788. });
  1789. K.NodeClass = KNode;
  1790. window.KindEditor = K;
  1791. var _START_TO_START = 0,
  1792. _START_TO_END = 1,
  1793. _END_TO_END = 2,
  1794. _END_TO_START = 3,
  1795. _BOOKMARK_ID = 0;
  1796. function _updateCollapsed(range) {
  1797. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1798. return range;
  1799. }
  1800. function _copyAndDelete(range, isCopy, isDelete) {
  1801. var doc = range.doc, nodeList = [];
  1802. function splitTextNode(node, startOffset, endOffset) {
  1803. var length = node.nodeValue.length, centerNode;
  1804. if (isCopy) {
  1805. var cloneNode = node.cloneNode(true);
  1806. if (startOffset > 0) {
  1807. centerNode = cloneNode.splitText(startOffset);
  1808. } else {
  1809. centerNode = cloneNode;
  1810. }
  1811. if (endOffset < length) {
  1812. centerNode.splitText(endOffset - startOffset);
  1813. }
  1814. }
  1815. if (isDelete) {
  1816. var center = node;
  1817. if (startOffset > 0) {
  1818. center = node.splitText(startOffset);
  1819. range.setStart(node, startOffset);
  1820. }
  1821. if (endOffset < length) {
  1822. var right = center.splitText(endOffset - startOffset);
  1823. range.setEnd(right, 0);
  1824. }
  1825. nodeList.push(center);
  1826. }
  1827. return centerNode;
  1828. }
  1829. function removeNodes() {
  1830. if (isDelete) {
  1831. range.up().collapse(true);
  1832. }
  1833. for (var i = 0, len = nodeList.length; i < len; i++) {
  1834. var node = nodeList[i];
  1835. if (node.parentNode) {
  1836. node.parentNode.removeChild(node);
  1837. }
  1838. }
  1839. }
  1840. var copyRange = range.cloneRange().down();
  1841. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1842. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1843. if (ancestor.nodeType == 3) {
  1844. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1845. if (isCopy) {
  1846. frag.appendChild(textNode);
  1847. }
  1848. removeNodes();
  1849. return isCopy ? frag : range;
  1850. }
  1851. function extractNodes(parent, frag) {
  1852. var node = parent.firstChild, nextNode;
  1853. while (node) {
  1854. var testRange = new KRange(doc).selectNode(node);
  1855. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1856. if (start >= 0 && incStart <= 0) {
  1857. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1858. }
  1859. if (incStart >= 0 && incEnd <= 0) {
  1860. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1861. }
  1862. if (incEnd >= 0 && end <= 0) {
  1863. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1864. }
  1865. if (end >= 0) {
  1866. return false;
  1867. }
  1868. nextNode = node.nextSibling;
  1869. if (start > 0) {
  1870. if (node.nodeType == 1) {
  1871. if (incStart >= 0 && incEnd <= 0) {
  1872. if (isCopy) {
  1873. frag.appendChild(node.cloneNode(true));
  1874. }
  1875. if (isDelete) {
  1876. nodeList.push(node);
  1877. }
  1878. } else {
  1879. var childFlag;
  1880. if (isCopy) {
  1881. childFlag = node.cloneNode(false);
  1882. frag.appendChild(childFlag);
  1883. }
  1884. if (extractNodes(node, childFlag) === false) {
  1885. return false;
  1886. }
  1887. }
  1888. } else if (node.nodeType == 3) {
  1889. var textNode;
  1890. if (node == copyRange.startContainer) {
  1891. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1892. } else if (node == copyRange.endContainer) {
  1893. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1894. } else {
  1895. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1896. }
  1897. if (isCopy) {
  1898. try {
  1899. frag.appendChild(textNode);
  1900. } catch(e) {}
  1901. }
  1902. }
  1903. }
  1904. node = nextNode;
  1905. }
  1906. }
  1907. extractNodes(ancestor, frag);
  1908. if (isDelete) {
  1909. range.up().collapse(true);
  1910. }
  1911. for (var i = 0, len = nodeList.length; i < len; i++) {
  1912. var node = nodeList[i];
  1913. if (node.parentNode) {
  1914. node.parentNode.removeChild(node);
  1915. }
  1916. }
  1917. return isCopy ? frag : range;
  1918. }
  1919. function _moveToElementText(range, el) {
  1920. var node = el;
  1921. while (node) {
  1922. var knode = K(node);
  1923. if (knode.name == 'marquee' || knode.name == 'select') {
  1924. return;
  1925. }
  1926. node = node.parentNode;
  1927. }
  1928. try {
  1929. range.moveToElementText(el);
  1930. } catch(e) {}
  1931. }
  1932. function _getStartEnd(rng, isStart) {
  1933. var doc = rng.parentElement().ownerDocument,
  1934. pointRange = rng.duplicate();
  1935. pointRange.collapse(isStart);
  1936. var parent = pointRange.parentElement(),
  1937. nodes = parent.childNodes;
  1938. if (nodes.length === 0) {
  1939. return {node: parent.parentNode, offset: K(parent).index()};
  1940. }
  1941. var startNode = doc, startPos = 0, cmp = -1;
  1942. var testRange = rng.duplicate();
  1943. _moveToElementText(testRange, parent);
  1944. for (var i = 0, len = nodes.length; i < len; i++) {
  1945. var node = nodes[i];
  1946. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1947. if (cmp === 0) {
  1948. return {node: node.parentNode, offset: i};
  1949. }
  1950. if (node.nodeType == 1) {
  1951. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1952. if (knode.isControl()) {
  1953. dummy = doc.createElement('span');
  1954. knode.after(dummy);
  1955. newNode = dummy;
  1956. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1957. }
  1958. _moveToElementText(nodeRange, newNode);
  1959. testRange.setEndPoint('StartToEnd', nodeRange);
  1960. if (cmp > 0) {
  1961. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1962. } else {
  1963. startPos = 0;
  1964. }
  1965. if (dummy) {
  1966. K(dummy).remove();
  1967. }
  1968. } else if (node.nodeType == 3) {
  1969. testRange.moveStart('character', node.nodeValue.length);
  1970. startPos += node.nodeValue.length;
  1971. }
  1972. if (cmp < 0) {
  1973. startNode = node;
  1974. }
  1975. }
  1976. if (cmp < 0 && startNode.nodeType == 1) {
  1977. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1978. }
  1979. if (cmp > 0) {
  1980. while (startNode.nextSibling && startNode.nodeType == 1) {
  1981. startNode = startNode.nextSibling;
  1982. }
  1983. }
  1984. testRange = rng.duplicate();
  1985. _moveToElementText(testRange, parent);
  1986. testRange.setEndPoint('StartToEnd', pointRange);
  1987. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1988. if (cmp > 0 && startNode.nodeType == 3) {
  1989. var prevNode = startNode.previousSibling;
  1990. while (prevNode && prevNode.nodeType == 3) {
  1991. startPos -= prevNode.nodeValue.length;
  1992. prevNode = prevNode.previousSibling;
  1993. }
  1994. }
  1995. return {node: startNode, offset: startPos};
  1996. }
  1997. function _getEndRange(node, offset) {
  1998. var doc = node.ownerDocument || node,
  1999. range = doc.body.createTextRange();
  2000. if (doc == node) {
  2001. range.collapse(true);
  2002. return range;
  2003. }
  2004. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2005. var children = node.childNodes, isStart, child;
  2006. if (offset === 0) {
  2007. child = children[0];
  2008. isStart = true;
  2009. } else {
  2010. child = children[offset - 1];
  2011. isStart = false;
  2012. }
  2013. if (!child) {
  2014. return range;
  2015. }
  2016. if (K(child).name === 'head') {
  2017. if (offset === 1) {
  2018. isStart = true;
  2019. }
  2020. if (offset === 2) {
  2021. isStart = false;
  2022. }
  2023. range.collapse(isStart);
  2024. return range;
  2025. }
  2026. if (child.nodeType == 1) {
  2027. var kchild = K(child), span;
  2028. if (kchild.isControl()) {
  2029. span = doc.createElement('span');
  2030. if (isStart) {
  2031. kchild.before(span);
  2032. } else {
  2033. kchild.after(span);
  2034. }
  2035. child = span;
  2036. }
  2037. _moveToElementText(range, child);
  2038. range.collapse(isStart);
  2039. if (span) {
  2040. K(span).remove();
  2041. }
  2042. return range;
  2043. }
  2044. node = child;
  2045. offset = isStart ? 0 : child.nodeValue.length;
  2046. }
  2047. var dummy = doc.createElement('span');
  2048. K(node).before(dummy);
  2049. _moveToElementText(range, dummy);
  2050. range.moveStart('character', offset);
  2051. K(dummy).remove();
  2052. return range;
  2053. }
  2054. function _toRange(rng) {
  2055. var doc, range;
  2056. function tr2td(start) {
  2057. if (K(start.node).name == 'tr') {
  2058. start.node = start.node.cells[start.offset];
  2059. start.offset = 0;
  2060. }
  2061. }
  2062. if (_IERANGE) {
  2063. if (rng.item) {
  2064. doc = _getDoc(rng.item(0));
  2065. range = new KRange(doc);
  2066. range.selectNode(rng.item(0));
  2067. return range;
  2068. }
  2069. doc = rng.parentElement().ownerDocument;
  2070. var start = _getStartEnd(rng, true),
  2071. end = _getStartEnd(rng, false);
  2072. tr2td(start);
  2073. tr2td(end);
  2074. range = new KRange(doc);
  2075. range.setStart(start.node, start.offset);
  2076. range.setEnd(end.node, end.offset);
  2077. return range;
  2078. }
  2079. var startContainer = rng.startContainer;
  2080. doc = startContainer.ownerDocument || startContainer;
  2081. range = new KRange(doc);
  2082. range.setStart(startContainer, rng.startOffset);
  2083. range.setEnd(rng.endContainer, rng.endOffset);
  2084. return range;
  2085. }
  2086. function KRange(doc) {
  2087. this.init(doc);
  2088. }
  2089. _extend(KRange, {
  2090. init : function(doc) {
  2091. var self = this;
  2092. self.startContainer = doc;
  2093. self.startOffset = 0;
  2094. self.endContainer = doc;
  2095. self.endOffset = 0;
  2096. self.collapsed = true;
  2097. self.doc = doc;
  2098. },
  2099. commonAncestor : function() {
  2100. function getParents(node) {
  2101. var parents = [];
  2102. while (node) {
  2103. parents.push(node);
  2104. node = node.parentNode;
  2105. }
  2106. return parents;
  2107. }
  2108. var parentsA = getParents(this.startContainer),
  2109. parentsB = getParents(this.endContainer),
  2110. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2111. while (++i) {
  2112. parentA = parentsA[lenA - i];
  2113. parentB = parentsB[lenB - i];
  2114. if (!parentA || !parentB || parentA !== parentB) {
  2115. break;
  2116. }
  2117. }
  2118. return parentsA[lenA - i + 1];
  2119. },
  2120. setStart : function(node, offset) {
  2121. var self = this, doc = self.doc;
  2122. self.startContainer = node;
  2123. self.startOffset = offset;
  2124. if (self.endContainer === doc) {
  2125. self.endContainer = node;
  2126. self.endOffset = offset;
  2127. }
  2128. return _updateCollapsed(this);
  2129. },
  2130. setEnd : function(node, offset) {
  2131. var self = this, doc = self.doc;
  2132. self.endContainer = node;
  2133. self.endOffset = offset;
  2134. if (self.startContainer === doc) {
  2135. self.startContainer = node;
  2136. self.startOffset = offset;
  2137. }
  2138. return _updateCollapsed(this);
  2139. },
  2140. setStartBefore : function(node) {
  2141. return this.setStart(node.parentNode || this.doc, K(node).index());
  2142. },
  2143. setStartAfter : function(node) {
  2144. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2145. },
  2146. setEndBefore : function(node) {
  2147. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2148. },
  2149. setEndAfter : function(node) {
  2150. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2151. },
  2152. selectNode : function(node) {
  2153. return this.setStartBefore(node).setEndAfter(node);
  2154. },
  2155. selectNodeContents : function(node) {
  2156. var knode = K(node);
  2157. if (knode.type == 3 || knode.isSingle()) {
  2158. return this.selectNode(node);
  2159. }
  2160. var children = knode.children();
  2161. if (children.length > 0) {
  2162. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2163. }
  2164. return this.setStart(node, 0).setEnd(node, 0);
  2165. },
  2166. collapse : function(toStart) {
  2167. if (toStart) {
  2168. return this.setEnd(this.startContainer, this.startOffset);
  2169. }
  2170. return this.setStart(this.endContainer, this.endOffset);
  2171. },
  2172. compareBoundaryPoints : function(how, range) {
  2173. var rangeA = this.get(), rangeB = range.get();
  2174. if (_IERANGE) {
  2175. var arr = {};
  2176. arr[_START_TO_START] = 'StartToStart';
  2177. arr[_START_TO_END] = 'EndToStart';
  2178. arr[_END_TO_END] = 'EndToEnd';
  2179. arr[_END_TO_START] = 'StartToEnd';
  2180. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2181. if (cmp !== 0) {
  2182. return cmp;
  2183. }
  2184. var nodeA, nodeB, nodeC, posA, posB;
  2185. if (how === _START_TO_START || how === _END_TO_START) {
  2186. nodeA = this.startContainer;
  2187. posA = this.startOffset;
  2188. }
  2189. if (how === _START_TO_END || how === _END_TO_END) {
  2190. nodeA = this.endContainer;
  2191. posA = this.endOffset;
  2192. }
  2193. if (how === _START_TO_START || how === _START_TO_END) {
  2194. nodeB = range.startContainer;
  2195. posB = range.startOffset;
  2196. }
  2197. if (how === _END_TO_END || how === _END_TO_START) {
  2198. nodeB = range.endContainer;
  2199. posB = range.endOffset;
  2200. }
  2201. if (nodeA === nodeB) {
  2202. var diff = posA - posB;
  2203. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2204. }
  2205. nodeC = nodeB;
  2206. while (nodeC && nodeC.parentNode !== nodeA) {
  2207. nodeC = nodeC.parentNode;
  2208. }
  2209. if (nodeC) {
  2210. return K(nodeC).index() >= posA ? -1 : 1;
  2211. }
  2212. nodeC = nodeA;
  2213. while (nodeC && nodeC.parentNode !== nodeB) {
  2214. nodeC = nodeC.parentNode;
  2215. }
  2216. if (nodeC) {
  2217. return K(nodeC).index() >= posB ? 1 : -1;
  2218. }
  2219. nodeC = K(nodeB).next();
  2220. if (nodeC && nodeC.contains(nodeA)) {
  2221. return 1;
  2222. }
  2223. nodeC = K(nodeA).next();
  2224. if (nodeC && nodeC.contains(nodeB)) {
  2225. return -1;
  2226. }
  2227. } else {
  2228. return rangeA.compareBoundaryPoints(how, rangeB);
  2229. }
  2230. },
  2231. cloneRange : function() {
  2232. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2233. },
  2234. toString : function() {
  2235. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2236. return str.replace(/\r\n|\n|\r/g, '');
  2237. },
  2238. cloneContents : function() {
  2239. return _copyAndDelete(this, true, false);
  2240. },
  2241. deleteContents : function() {
  2242. return _copyAndDelete(this, false, true);
  2243. },
  2244. extractContents : function() {
  2245. return _copyAndDelete(this, true, true);
  2246. },
  2247. insertNode : function(node) {
  2248. var self = this,
  2249. sc = self.startContainer, so = self.startOffset,
  2250. ec = self.endContainer, eo = self.endOffset,
  2251. firstChild, lastChild, c, nodeCount = 1;
  2252. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2253. firstChild = node.firstChild;
  2254. lastChild = node.lastChild;
  2255. nodeCount = node.childNodes.length;
  2256. }
  2257. if (sc.nodeType == 1) {
  2258. c = sc.childNodes[so];
  2259. if (c) {
  2260. sc.insertBefore(node, c);
  2261. if (sc === ec) {
  2262. eo += nodeCount;
  2263. }
  2264. } else {
  2265. sc.appendChild(node);
  2266. }
  2267. } else if (sc.nodeType == 3) {
  2268. if (so === 0) {
  2269. sc.parentNode.insertBefore(node, sc);
  2270. if (sc.parentNode === ec) {
  2271. eo += nodeCount;
  2272. }
  2273. } else if (so >= sc.nodeValue.length) {
  2274. if (sc.nextSibling) {
  2275. sc.parentNode.insertBefore(node, sc.nextSibling);
  2276. } else {
  2277. sc.parentNode.appendChild(node);
  2278. }
  2279. } else {
  2280. if (so > 0) {
  2281. c = sc.splitText(so);
  2282. } else {
  2283. c = sc;
  2284. }
  2285. sc.parentNode.insertBefore(node, c);
  2286. if (sc === ec) {
  2287. ec = c;
  2288. eo -= so;
  2289. }
  2290. }
  2291. }
  2292. if (firstChild) {
  2293. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2294. } else {
  2295. self.selectNode(node);
  2296. }
  2297. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2298. return self;
  2299. }
  2300. return self.setEnd(ec, eo);
  2301. },
  2302. surroundContents : function(node) {
  2303. node.appendChild(this.extractContents());
  2304. return this.insertNode(node).selectNode(node);
  2305. },
  2306. isControl : function() {
  2307. var self = this,
  2308. sc = self.startContainer, so = self.startOffset,
  2309. ec = self.endContainer, eo = self.endOffset, rng;
  2310. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2311. },
  2312. get : function(hasControlRange) {
  2313. var self = this, doc = self.doc, node, rng;
  2314. if (!_IERANGE) {
  2315. rng = doc.createRange();
  2316. try {
  2317. rng.setStart(self.startContainer, self.startOffset);
  2318. rng.setEnd(self.endContainer, self.endOffset);
  2319. } catch (e) {}
  2320. return rng;
  2321. }
  2322. if (hasControlRange && self.isControl()) {
  2323. rng = doc.body.createControlRange();
  2324. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2325. return rng;
  2326. }
  2327. var range = self.cloneRange().down();
  2328. rng = doc.body.createTextRange();
  2329. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2330. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2331. return rng;
  2332. },
  2333. html : function() {
  2334. return K(this.cloneContents()).outer();
  2335. },
  2336. down : function() {
  2337. var self = this;
  2338. function downPos(node, pos, isStart) {
  2339. if (node.nodeType != 1) {
  2340. return;
  2341. }
  2342. var children = K(node).children();
  2343. if (children.length === 0) {
  2344. return;
  2345. }
  2346. var left, right, child, offset;
  2347. if (pos > 0) {
  2348. left = children.eq(pos - 1);
  2349. }
  2350. if (pos < children.length) {
  2351. right = children.eq(pos);
  2352. }
  2353. if (left && left.type == 3) {
  2354. child = left[0];
  2355. offset = child.nodeValue.length;
  2356. }
  2357. if (right && right.type == 3) {
  2358. child = right[0];
  2359. offset = 0;
  2360. }
  2361. if (!child) {
  2362. return;
  2363. }
  2364. if (isStart) {
  2365. self.setStart(child, offset);
  2366. } else {
  2367. self.setEnd(child, offset);
  2368. }
  2369. }
  2370. downPos(self.startContainer, self.startOffset, true);
  2371. downPos(self.endContainer, self.endOffset, false);
  2372. return self;
  2373. },
  2374. up : function() {
  2375. var self = this;
  2376. function upPos(node, pos, isStart) {
  2377. if (node.nodeType != 3) {
  2378. return;
  2379. }
  2380. if (pos === 0) {
  2381. if (isStart) {
  2382. self.setStartBefore(node);
  2383. } else {
  2384. self.setEndBefore(node);
  2385. }
  2386. } else if (pos == node.nodeValue.length) {
  2387. if (isStart) {
  2388. self.setStartAfter(node);
  2389. } else {
  2390. self.setEndAfter(node);
  2391. }
  2392. }
  2393. }
  2394. upPos(self.startContainer, self.startOffset, true);
  2395. upPos(self.endContainer, self.endOffset, false);
  2396. return self;
  2397. },
  2398. enlarge : function(toBlock) {
  2399. var self = this;
  2400. self.up();
  2401. function enlargePos(node, pos, isStart) {
  2402. var knode = K(node), parent;
  2403. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2404. return;
  2405. }
  2406. if (pos === 0) {
  2407. while (!knode.prev()) {
  2408. parent = knode.parent();
  2409. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2410. break;
  2411. }
  2412. knode = parent;
  2413. }
  2414. if (isStart) {
  2415. self.setStartBefore(knode[0]);
  2416. } else {
  2417. self.setEndBefore(knode[0]);
  2418. }
  2419. } else if (pos == knode.children().length) {
  2420. while (!knode.next()) {
  2421. parent = knode.parent();
  2422. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2423. break;
  2424. }
  2425. knode = parent;
  2426. }
  2427. if (isStart) {
  2428. self.setStartAfter(knode[0]);
  2429. } else {
  2430. self.setEndAfter(knode[0]);
  2431. }
  2432. }
  2433. }
  2434. enlargePos(self.startContainer, self.startOffset, true);
  2435. enlargePos(self.endContainer, self.endOffset, false);
  2436. return self;
  2437. },
  2438. shrink : function() {
  2439. var self = this, child, collapsed = self.collapsed;
  2440. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2441. self.setStart(child, 0);
  2442. }
  2443. if (collapsed) {
  2444. return self.collapse(collapsed);
  2445. }
  2446. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2447. self.setEnd(child, child.childNodes.length);
  2448. }
  2449. return self;
  2450. },
  2451. createBookmark : function(serialize) {
  2452. var self = this, doc = self.doc, endNode,
  2453. startNode = K('<span style="display:none;"></span>', doc)[0];
  2454. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2455. if (!self.collapsed) {
  2456. endNode = startNode.cloneNode(true);
  2457. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2458. }
  2459. if (endNode) {
  2460. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2461. }
  2462. self.insertNode(startNode).setStartAfter(startNode);
  2463. return {
  2464. start : serialize ? '#' + startNode.id : startNode,
  2465. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2466. };
  2467. },
  2468. moveToBookmark : function(bookmark) {
  2469. var self = this, doc = self.doc,
  2470. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2471. if (!start || start.length < 1) {
  2472. return self;
  2473. }
  2474. self.setStartBefore(start[0]);
  2475. start.remove();
  2476. if (end && end.length > 0) {
  2477. self.setEndBefore(end[0]);
  2478. end.remove();
  2479. } else {
  2480. self.collapse(true);
  2481. }
  2482. return self;
  2483. },
  2484. dump : function() {
  2485. console.log('--------------------');
  2486. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2487. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2488. }
  2489. });
  2490. function _range(mixed) {
  2491. if (!mixed.nodeName) {
  2492. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2493. }
  2494. return new KRange(mixed);
  2495. }
  2496. K.RangeClass = KRange;
  2497. K.range = _range;
  2498. K.START_TO_START = _START_TO_START;
  2499. K.START_TO_END = _START_TO_END;
  2500. K.END_TO_END = _END_TO_END;
  2501. K.END_TO_START = _END_TO_START;
  2502. function _nativeCommand(doc, key, val) {
  2503. try {
  2504. doc.execCommand(key, false, val);
  2505. } catch(e) {}
  2506. }
  2507. function _nativeCommandValue(doc, key) {
  2508. var val = '';
  2509. try {
  2510. val = doc.queryCommandValue(key);
  2511. } catch (e) {}
  2512. if (typeof val !== 'string') {
  2513. val = '';
  2514. }
  2515. return val;
  2516. }
  2517. function _getSel(doc) {
  2518. var win = _getWin(doc);
  2519. return _IERANGE ? doc.selection : win.getSelection();
  2520. }
  2521. function _getRng(doc) {
  2522. var sel = _getSel(doc), rng;
  2523. try {
  2524. if (sel.rangeCount > 0) {
  2525. rng = sel.getRangeAt(0);
  2526. } else {
  2527. rng = sel.createRange();
  2528. }
  2529. } catch(e) {}
  2530. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2531. return null;
  2532. }
  2533. return rng;
  2534. }
  2535. function _singleKeyMap(map) {
  2536. var newMap = {}, arr, v;
  2537. _each(map, function(key, val) {
  2538. arr = key.split(',');
  2539. for (var i = 0, len = arr.length; i < len; i++) {
  2540. v = arr[i];
  2541. newMap[v] = val;
  2542. }
  2543. });
  2544. return newMap;
  2545. }
  2546. function _hasAttrOrCss(knode, map) {
  2547. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2548. }
  2549. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2550. mapKey = mapKey || knode.name;
  2551. if (knode.type !== 1) {
  2552. return false;
  2553. }
  2554. var newMap = _singleKeyMap(map);
  2555. if (!newMap[mapKey]) {
  2556. return false;
  2557. }
  2558. var arr = newMap[mapKey].split(',');
  2559. for (var i = 0, len = arr.length; i < len; i++) {
  2560. var key = arr[i];
  2561. if (key === '*') {
  2562. return true;
  2563. }
  2564. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2565. var method = match[1] ? 'css' : 'attr';
  2566. key = match[2];
  2567. var val = match[3] || '';
  2568. if (val === '' && knode[method](key) !== '') {
  2569. return true;
  2570. }
  2571. if (val !== '' && knode[method](key) === val) {
  2572. return true;
  2573. }
  2574. }
  2575. return false;
  2576. }
  2577. function _removeAttrOrCss(knode, map) {
  2578. if (knode.type != 1) {
  2579. return;
  2580. }
  2581. _removeAttrOrCssByKey(knode, map, '*');
  2582. _removeAttrOrCssByKey(knode, map);
  2583. }
  2584. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2585. mapKey = mapKey || knode.name;
  2586. if (knode.type !== 1) {
  2587. return;
  2588. }
  2589. var newMap = _singleKeyMap(map);
  2590. if (!newMap[mapKey]) {
  2591. return;
  2592. }
  2593. var arr = newMap[mapKey].split(','), allFlag = false;
  2594. for (var i = 0, len = arr.length; i < len; i++) {
  2595. var key = arr[i];
  2596. if (key === '*') {
  2597. allFlag = true;
  2598. break;
  2599. }
  2600. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2601. key = match[2];
  2602. if (match[1]) {
  2603. key = _toCamel(key);
  2604. if (knode[0].style[key]) {
  2605. knode[0].style[key] = '';
  2606. }
  2607. } else {
  2608. knode.removeAttr(key);
  2609. }
  2610. }
  2611. if (allFlag) {
  2612. knode.remove(true);
  2613. }
  2614. }
  2615. function _getInnerNode(knode) {
  2616. var inner = knode;
  2617. while (inner.first()) {
  2618. inner = inner.first();
  2619. }
  2620. return inner;
  2621. }
  2622. function _isEmptyNode(knode) {
  2623. if (knode.type != 1 || knode.isSingle()) {
  2624. return false;
  2625. }
  2626. return knode.html().replace(/<[^>]+>/g, '') === '';
  2627. }
  2628. function _mergeWrapper(a, b) {
  2629. a = a.clone(true);
  2630. var lastA = _getInnerNode(a), childA = a, merged = false;
  2631. while (b) {
  2632. while (childA) {
  2633. if (childA.name === b.name) {
  2634. _mergeAttrs(childA, b.attr(), b.css());
  2635. merged = true;
  2636. }
  2637. childA = childA.first();
  2638. }
  2639. if (!merged) {
  2640. lastA.append(b.clone(false));
  2641. }
  2642. merged = false;
  2643. b = b.first();
  2644. }
  2645. return a;
  2646. }
  2647. function _wrapNode(knode, wrapper) {
  2648. wrapper = wrapper.clone(true);
  2649. if (knode.type == 3) {
  2650. _getInnerNode(wrapper).append(knode.clone(false));
  2651. knode.replaceWith(wrapper);
  2652. return wrapper;
  2653. }
  2654. var nodeWrapper = knode, child;
  2655. while ((child = knode.first()) && child.children().length == 1) {
  2656. knode = child;
  2657. }
  2658. child = knode.first();
  2659. var frag = knode.doc.createDocumentFragment();
  2660. while (child) {
  2661. frag.appendChild(child[0]);
  2662. child = child.next();
  2663. }
  2664. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2665. if (frag.firstChild) {
  2666. _getInnerNode(wrapper).append(frag);
  2667. }
  2668. nodeWrapper.replaceWith(wrapper);
  2669. return wrapper;
  2670. }
  2671. function _mergeAttrs(knode, attrs, styles) {
  2672. _each(attrs, function(key, val) {
  2673. if (key !== 'style') {
  2674. knode.attr(key, val);
  2675. }
  2676. });
  2677. _each(styles, function(key, val) {
  2678. knode.css(key, val);
  2679. });
  2680. }
  2681. function _inPreElement(knode) {
  2682. while (knode && knode.name != 'body') {
  2683. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2684. return true;
  2685. }
  2686. knode = knode.parent();
  2687. }
  2688. return false;
  2689. }
  2690. function KCmd(range) {
  2691. this.init(range);
  2692. }
  2693. _extend(KCmd, {
  2694. init : function(range) {
  2695. var self = this, doc = range.doc;
  2696. self.doc = doc;
  2697. self.win = _getWin(doc);
  2698. self.sel = _getSel(doc);
  2699. self.range = range;
  2700. },
  2701. selection : function(forceReset) {
  2702. var self = this, doc = self.doc, rng = _getRng(doc);
  2703. self.sel = _getSel(doc);
  2704. if (rng) {
  2705. self.range = _range(rng);
  2706. if (K(self.range.startContainer).name == 'html') {
  2707. self.range.selectNodeContents(doc.body).collapse(false);
  2708. }
  2709. return self;
  2710. }
  2711. if (forceReset) {
  2712. self.range.selectNodeContents(doc.body).collapse(false);
  2713. }
  2714. return self;
  2715. },
  2716. select : function(hasDummy) {
  2717. hasDummy = _undef(hasDummy, true);
  2718. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2719. sc = range.startContainer, so = range.startOffset,
  2720. ec = range.endContainer, eo = range.endOffset,
  2721. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2722. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2723. if (_IERANGE) {
  2724. var dummy = K('<span>&nbsp;</span>', doc);
  2725. range.insertNode(dummy[0]);
  2726. rng = doc.body.createTextRange();
  2727. try {
  2728. rng.moveToElementText(dummy[0]);
  2729. } catch(ex) {}
  2730. rng.collapse(false);
  2731. rng.select();
  2732. dummy.remove();
  2733. win.focus();
  2734. return self;
  2735. }
  2736. if (_WEBKIT) {
  2737. var children = sc.childNodes;
  2738. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2739. range.insertNode(doc.createTextNode('\u200B'));
  2740. hasU200b = true;
  2741. }
  2742. }
  2743. }
  2744. if (_IERANGE) {
  2745. try {
  2746. rng = range.get(true);
  2747. rng.select();
  2748. } catch(e) {}
  2749. } else {
  2750. if (hasU200b) {
  2751. range.collapse(false);
  2752. }
  2753. rng = range.get(true);
  2754. sel.removeAllRanges();
  2755. sel.addRange(rng);
  2756. if (doc !== document) {
  2757. var pos = K(rng.endContainer).pos();
  2758. win.scrollTo(pos.x, pos.y);
  2759. }
  2760. }
  2761. win.focus();
  2762. return self;
  2763. },
  2764. wrap : function(val) {
  2765. var self = this, doc = self.doc, range = self.range, wrapper;
  2766. wrapper = K(val, doc);
  2767. if (range.collapsed) {
  2768. range.shrink();
  2769. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2770. return self;
  2771. }
  2772. if (wrapper.isBlock()) {
  2773. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2774. while (child.first()) {
  2775. child = child.first();
  2776. }
  2777. child.append(range.extractContents());
  2778. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2779. return self;
  2780. }
  2781. range.enlarge();
  2782. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2783. K(ancestor).scan(function(node) {
  2784. if (!isStart && node == bookmark.start) {
  2785. isStart = true;
  2786. return;
  2787. }
  2788. if (isStart) {
  2789. if (node == bookmark.end) {
  2790. return false;
  2791. }
  2792. var knode = K(node);
  2793. if (_inPreElement(knode)) {
  2794. return;
  2795. }
  2796. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2797. var parent;
  2798. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2799. knode = parent;
  2800. }
  2801. _wrapNode(knode, wrapper);
  2802. }
  2803. }
  2804. });
  2805. range.moveToBookmark(bookmark);
  2806. return self;
  2807. },
  2808. split : function(isStart, map) {
  2809. var range = this.range, doc = range.doc;
  2810. var tempRange = range.cloneRange().collapse(isStart);
  2811. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2812. parent = node.nodeType == 3 ? node.parentNode : node,
  2813. needSplit = false, knode;
  2814. while (parent && parent.parentNode) {
  2815. knode = K(parent);
  2816. if (map) {
  2817. if (!knode.isStyle()) {
  2818. break;
  2819. }
  2820. if (!_hasAttrOrCss(knode, map)) {
  2821. break;
  2822. }
  2823. } else {
  2824. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2825. break;
  2826. }
  2827. }
  2828. needSplit = true;
  2829. parent = parent.parentNode;
  2830. }
  2831. if (needSplit) {
  2832. var dummy = doc.createElement('span');
  2833. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2834. if (isStart) {
  2835. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2836. } else {
  2837. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2838. }
  2839. var frag = tempRange.extractContents(),
  2840. first = frag.firstChild, last = frag.lastChild;
  2841. if (isStart) {
  2842. tempRange.insertNode(frag);
  2843. range.setStartAfter(last).setEndBefore(dummy);
  2844. } else {
  2845. parent.appendChild(frag);
  2846. range.setStartBefore(dummy).setEndBefore(first);
  2847. }
  2848. var dummyParent = dummy.parentNode;
  2849. if (dummyParent == range.endContainer) {
  2850. var prev = K(dummy).prev(), next = K(dummy).next();
  2851. if (prev && next && prev.type == 3 && next.type == 3) {
  2852. range.setEnd(prev[0], prev[0].nodeValue.length);
  2853. } else if (!isStart) {
  2854. range.setEnd(range.endContainer, range.endOffset - 1);
  2855. }
  2856. }
  2857. dummyParent.removeChild(dummy);
  2858. }
  2859. return this;
  2860. },
  2861. remove : function(map) {
  2862. var self = this, doc = self.doc, range = self.range;
  2863. range.enlarge();
  2864. if (range.startOffset === 0) {
  2865. var ksc = K(range.startContainer), parent;
  2866. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2867. ksc = parent;
  2868. }
  2869. range.setStart(ksc[0], 0);
  2870. ksc = K(range.startContainer);
  2871. if (ksc.isBlock()) {
  2872. _removeAttrOrCss(ksc, map);
  2873. }
  2874. var kscp = ksc.parent();
  2875. if (kscp && kscp.isBlock()) {
  2876. _removeAttrOrCss(kscp, map);
  2877. }
  2878. }
  2879. var sc, so;
  2880. if (range.collapsed) {
  2881. self.split(true, map);
  2882. sc = range.startContainer;
  2883. so = range.startOffset;
  2884. if (so > 0) {
  2885. var sb = K(sc.childNodes[so - 1]);
  2886. if (sb && _isEmptyNode(sb)) {
  2887. sb.remove();
  2888. range.setStart(sc, so - 1);
  2889. }
  2890. }
  2891. var sa = K(sc.childNodes[so]);
  2892. if (sa && _isEmptyNode(sa)) {
  2893. sa.remove();
  2894. }
  2895. if (_isEmptyNode(sc)) {
  2896. range.startBefore(sc);
  2897. sc.remove();
  2898. }
  2899. range.collapse(true);
  2900. return self;
  2901. }
  2902. self.split(true, map);
  2903. self.split(false, map);
  2904. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2905. range.cloneRange().collapse(false).insertNode(endDummy);
  2906. range.cloneRange().collapse(true).insertNode(startDummy);
  2907. var nodeList = [], cmpStart = false;
  2908. K(range.commonAncestor()).scan(function(node) {
  2909. if (!cmpStart && node == startDummy) {
  2910. cmpStart = true;
  2911. return;
  2912. }
  2913. if (node == endDummy) {
  2914. return false;
  2915. }
  2916. if (cmpStart) {
  2917. nodeList.push(node);
  2918. }
  2919. });
  2920. K(startDummy).remove();
  2921. K(endDummy).remove();
  2922. sc = range.startContainer;
  2923. so = range.startOffset;
  2924. var ec = range.endContainer, eo = range.endOffset;
  2925. if (so > 0) {
  2926. var startBefore = K(sc.childNodes[so - 1]);
  2927. if (startBefore && _isEmptyNode(startBefore)) {
  2928. startBefore.remove();
  2929. range.setStart(sc, so - 1);
  2930. if (sc == ec) {
  2931. range.setEnd(ec, eo - 1);
  2932. }
  2933. }
  2934. var startAfter = K(sc.childNodes[so]);
  2935. if (startAfter && _isEmptyNode(startAfter)) {
  2936. startAfter.remove();
  2937. if (sc == ec) {
  2938. range.setEnd(ec, eo - 1);
  2939. }
  2940. }
  2941. }
  2942. var endAfter = K(ec.childNodes[range.endOffset]);
  2943. if (endAfter && _isEmptyNode(endAfter)) {
  2944. endAfter.remove();
  2945. }
  2946. var bookmark = range.createBookmark(true);
  2947. _each(nodeList, function(i, node) {
  2948. _removeAttrOrCss(K(node), map);
  2949. });
  2950. range.moveToBookmark(bookmark);
  2951. return self;
  2952. },
  2953. commonNode : function(map) {
  2954. var range = this.range;
  2955. var ec = range.endContainer, eo = range.endOffset,
  2956. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2957. function find(node) {
  2958. var child = node, parent = node;
  2959. while (parent) {
  2960. if (_hasAttrOrCss(K(parent), map)) {
  2961. return K(parent);
  2962. }
  2963. parent = parent.parentNode;
  2964. }
  2965. while (child && (child = child.lastChild)) {
  2966. if (_hasAttrOrCss(K(child), map)) {
  2967. return K(child);
  2968. }
  2969. }
  2970. return null;
  2971. }
  2972. var cNode = find(node);
  2973. if (cNode) {
  2974. return cNode;
  2975. }
  2976. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2977. var prev = K(node).prev();
  2978. if (prev) {
  2979. return find(prev);
  2980. }
  2981. }
  2982. return null;
  2983. },
  2984. commonAncestor : function(tagName) {
  2985. var range = this.range,
  2986. sc = range.startContainer, so = range.startOffset,
  2987. ec = range.endContainer, eo = range.endOffset,
  2988. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2989. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2990. function find(node) {
  2991. while (node) {
  2992. if (node.nodeType == 1) {
  2993. if (node.tagName.toLowerCase() === tagName) {
  2994. return node;
  2995. }
  2996. }
  2997. node = node.parentNode;
  2998. }
  2999. return null;
  3000. }
  3001. var start = find(startNode), end = find(endNode);
  3002. if (start && end && start === end) {
  3003. return K(start);
  3004. }
  3005. return null;
  3006. },
  3007. state : function(key) {
  3008. var self = this, doc = self.doc, bool = false;
  3009. try {
  3010. bool = doc.queryCommandState(key);
  3011. } catch (e) {}
  3012. return bool;
  3013. },
  3014. val : function(key) {
  3015. var self = this, doc = self.doc, range = self.range;
  3016. function lc(val) {
  3017. return val.toLowerCase();
  3018. }
  3019. key = lc(key);
  3020. var val = '', knode;
  3021. if (key === 'fontfamily' || key === 'fontname') {
  3022. val = _nativeCommandValue(doc, 'fontname');
  3023. val = val.replace(/['"]/g, '');
  3024. return lc(val);
  3025. }
  3026. if (key === 'formatblock') {
  3027. val = _nativeCommandValue(doc, key);
  3028. if (val === '') {
  3029. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3030. if (knode) {
  3031. val = knode.name;
  3032. }
  3033. }
  3034. if (val === 'Normal') {
  3035. val = 'p';
  3036. }
  3037. return lc(val);
  3038. }
  3039. if (key === 'fontsize') {
  3040. knode = self.commonNode({'*' : '.font-size'});
  3041. if (knode) {
  3042. val = knode.css('font-size');
  3043. }
  3044. return lc(val);
  3045. }
  3046. if (key === 'forecolor') {
  3047. knode = self.commonNode({'*' : '.color'});
  3048. if (knode) {
  3049. val = knode.css('color');
  3050. }
  3051. val = _toHex(val);
  3052. if (val === '') {
  3053. val = 'default';
  3054. }
  3055. return lc(val);
  3056. }
  3057. if (key === 'hilitecolor') {
  3058. knode = self.commonNode({'*' : '.background-color'});
  3059. if (knode) {
  3060. val = knode.css('background-color');
  3061. }
  3062. val = _toHex(val);
  3063. if (val === '') {
  3064. val = 'default';
  3065. }
  3066. return lc(val);
  3067. }
  3068. return val;
  3069. },
  3070. toggle : function(wrapper, map) {
  3071. var self = this;
  3072. if (self.commonNode(map)) {
  3073. self.remove(map);
  3074. } else {
  3075. self.wrap(wrapper);
  3076. }
  3077. return self.select();
  3078. },
  3079. bold : function() {
  3080. return this.toggle('<strong></strong>', {
  3081. span : '.font-weight=bold',
  3082. strong : '*',
  3083. b : '*'
  3084. });
  3085. },
  3086. italic : function() {
  3087. return this.toggle('<em></em>', {
  3088. span : '.font-style=italic',
  3089. em : '*',
  3090. i : '*'
  3091. });
  3092. },
  3093. underline : function() {
  3094. return this.toggle('<u></u>', {
  3095. span : '.text-decoration=underline',
  3096. u : '*'
  3097. });
  3098. },
  3099. strikethrough : function() {
  3100. return this.toggle('<s></s>', {
  3101. span : '.text-decoration=line-through',
  3102. s : '*'
  3103. });
  3104. },
  3105. forecolor : function(val) {
  3106. return this.toggle('<span style="color:' + val + ';"></span>', {
  3107. span : '.color=' + val,
  3108. font : 'color'
  3109. });
  3110. },
  3111. hilitecolor : function(val) {
  3112. return this.toggle('<span style="background-color:' + val + ';"></span>', {
  3113. span : '.background-color=' + val
  3114. });
  3115. },
  3116. fontsize : function(val) {
  3117. return this.toggle('<span style="font-size:' + val + ';"></span>', {
  3118. span : '.font-size=' + val,
  3119. font : 'size'
  3120. });
  3121. },
  3122. fontname : function(val) {
  3123. return this.fontfamily(val);
  3124. },
  3125. fontfamily : function(val) {
  3126. return this.toggle('<span style="font-family:' + val + ';"></span>', {
  3127. span : '.font-family=' + val,
  3128. font : 'face'
  3129. });
  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. e.stopPropagation();
  3342. var self = clickEl.get(),
  3343. x = _removeUnit(moveEl.css('left')),
  3344. y = _removeUnit(moveEl.css('top')),
  3345. width = moveEl.width(),
  3346. height = moveEl.height(),
  3347. pageX = e.pageX,
  3348. pageY = e.pageY;
  3349. if (beforeDrag) {
  3350. beforeDrag();
  3351. }
  3352. function moveListener(e) {
  3353. e.preventDefault();
  3354. var kdoc = K(_getDoc(e.target));
  3355. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3356. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3357. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3358. }
  3359. function selectListener(e) {
  3360. e.preventDefault();
  3361. }
  3362. function upListener(e) {
  3363. e.preventDefault();
  3364. K(docs).unbind('mousemove', moveListener)
  3365. .unbind('mouseup', upListener)
  3366. .unbind('selectstart', selectListener);
  3367. if (self.releaseCapture) {
  3368. self.releaseCapture();
  3369. }
  3370. }
  3371. K(docs).mousemove(moveListener)
  3372. .mouseup(upListener)
  3373. .bind('selectstart', selectListener);
  3374. if (self.setCapture) {
  3375. self.setCapture();
  3376. }
  3377. });
  3378. }
  3379. function KWidget(options) {
  3380. this.init(options);
  3381. }
  3382. _extend(KWidget, {
  3383. init : function(options) {
  3384. var self = this;
  3385. self.name = options.name || '';
  3386. self.doc = options.doc || document;
  3387. self.win = _getWin(self.doc);
  3388. self.x = _addUnit(options.x);
  3389. self.y = _addUnit(options.y);
  3390. self.z = options.z;
  3391. self.width = _addUnit(options.width);
  3392. self.height = _addUnit(options.height);
  3393. self.div = K('<div style="display:block;"></div>');
  3394. self.options = options;
  3395. self._alignEl = options.alignEl;
  3396. if (self.width) {
  3397. self.div.css('width', self.width);
  3398. }
  3399. if (self.height) {
  3400. self.div.css('height', self.height);
  3401. }
  3402. if (self.z) {
  3403. self.div.css({
  3404. position : 'absolute',
  3405. left : self.x,
  3406. top : self.y,
  3407. 'z-index' : self.z
  3408. });
  3409. }
  3410. if (self.z && (self.x === undefined || self.y === undefined)) {
  3411. self.autoPos(self.width, self.height);
  3412. }
  3413. if (options.cls) {
  3414. self.div.addClass(options.cls);
  3415. }
  3416. if (options.shadowMode) {
  3417. self.div.addClass('ke-shadow');
  3418. }
  3419. if (options.css) {
  3420. self.div.css(options.css);
  3421. }
  3422. if (options.src) {
  3423. K(options.src).replaceWith(self.div);
  3424. } else {
  3425. K(self.doc.body).append(self.div);
  3426. }
  3427. if (options.html) {
  3428. self.div.html(options.html);
  3429. }
  3430. if (options.autoScroll) {
  3431. if (_IE && _V < 7 || _QUIRKS) {
  3432. var scrollPos = _getScrollPos();
  3433. K(self.win).bind('scroll', function(e) {
  3434. var pos = _getScrollPos(),
  3435. diffX = pos.x - scrollPos.x,
  3436. diffY = pos.y - scrollPos.y;
  3437. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3438. });
  3439. } else {
  3440. self.div.css('position', 'fixed');
  3441. }
  3442. }
  3443. },
  3444. pos : function(x, y, updateProp) {
  3445. var self = this;
  3446. updateProp = _undef(updateProp, true);
  3447. if (x !== null) {
  3448. x = x < 0 ? 0 : _addUnit(x);
  3449. self.div.css('left', x);
  3450. if (updateProp) {
  3451. self.x = x;
  3452. }
  3453. }
  3454. if (y !== null) {
  3455. y = y < 0 ? 0 : _addUnit(y);
  3456. self.div.css('top', y);
  3457. if (updateProp) {
  3458. self.y = y;
  3459. }
  3460. }
  3461. return self;
  3462. },
  3463. autoPos : function(width, height) {
  3464. var self = this,
  3465. w = _removeUnit(width) || 0,
  3466. h = _removeUnit(height) || 0,
  3467. scrollPos = _getScrollPos();
  3468. if (self._alignEl) {
  3469. var knode = K(self._alignEl),
  3470. pos = knode.pos(),
  3471. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3472. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3473. x = diffX < 0 ? pos.x : pos.x + diffX;
  3474. y = diffY < 0 ? pos.y : pos.y + diffY;
  3475. } else {
  3476. var docEl = _docElement(self.doc);
  3477. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3478. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3479. }
  3480. if (!(_IE && _V < 7 || _QUIRKS)) {
  3481. x -= scrollPos.x;
  3482. y -= scrollPos.y;
  3483. }
  3484. return self.pos(x, y);
  3485. },
  3486. remove : function() {
  3487. var self = this;
  3488. if (_IE && _V < 7 || _QUIRKS) {
  3489. K(self.win).unbind('scroll');
  3490. }
  3491. self.div.remove();
  3492. _each(self, function(i) {
  3493. self[i] = null;
  3494. });
  3495. return this;
  3496. },
  3497. show : function() {
  3498. this.div.show();
  3499. return this;
  3500. },
  3501. hide : function() {
  3502. this.div.hide();
  3503. return this;
  3504. },
  3505. draggable : function(options) {
  3506. var self = this;
  3507. options = options || {};
  3508. options.moveEl = self.div;
  3509. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3510. if ((x = x + diffX) < 0) {
  3511. x = 0;
  3512. }
  3513. if ((y = y + diffY) < 0) {
  3514. y = 0;
  3515. }
  3516. self.pos(x, y);
  3517. };
  3518. _drag(options);
  3519. return self;
  3520. }
  3521. });
  3522. function _widget(options) {
  3523. return new KWidget(options);
  3524. }
  3525. K.WidgetClass = KWidget;
  3526. K.widget = _widget;
  3527. function _iframeDoc(iframe) {
  3528. iframe = _get(iframe);
  3529. return iframe.contentDocument || iframe.contentWindow.document;
  3530. }
  3531. var html, _direction = '';
  3532. if ((html = document.getElementsByTagName('html'))) {
  3533. _direction = html[0].dir;
  3534. }
  3535. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3536. var arr = [
  3537. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3538. '<head><meta charset="utf-8" /><title></title>',
  3539. '<style>',
  3540. 'html {margin:0;padding:0;}',
  3541. 'body {margin:0;padding:5px;}',
  3542. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3543. 'body, p, div {word-wrap: break-word;}',
  3544. 'p {margin:5px 0;}',
  3545. 'table {border-collapse:collapse;}',
  3546. 'img {border:0;}',
  3547. 'noscript {display:none;}',
  3548. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3549. 'img.ke-flash {',
  3550. ' border:1px solid #AAA;',
  3551. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3552. ' background-position:center center;',
  3553. ' background-repeat:no-repeat;',
  3554. ' width:100px;',
  3555. ' height:100px;',
  3556. '}',
  3557. 'img.ke-rm {',
  3558. ' border:1px solid #AAA;',
  3559. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3560. ' background-position:center center;',
  3561. ' background-repeat:no-repeat;',
  3562. ' width:100px;',
  3563. ' height:100px;',
  3564. '}',
  3565. 'img.ke-media {',
  3566. ' border:1px solid #AAA;',
  3567. ' background-image:url(' + themesPath + 'common/media.gif);',
  3568. ' background-position:center center;',
  3569. ' background-repeat:no-repeat;',
  3570. ' width:100px;',
  3571. ' height:100px;',
  3572. '}',
  3573. 'img.ke-anchor {',
  3574. ' border:1px dashed #666;',
  3575. ' width:16px;',
  3576. ' height:16px;',
  3577. '}',
  3578. '.ke-script, .ke-noscript, .ke-display-none {',
  3579. ' display:none;',
  3580. ' font-size:0;',
  3581. ' width:0;',
  3582. ' height:0;',
  3583. '}',
  3584. '.ke-pagebreak {',
  3585. ' border:1px dotted #AAA;',
  3586. ' font-size:0;',
  3587. ' height:2px;',
  3588. '}',
  3589. 'a {',
  3590. 'text-decoration: none;',
  3591. '}',
  3592. '</style>'
  3593. ];
  3594. if (!_isArray(cssPath)) {
  3595. cssPath = [cssPath];
  3596. }
  3597. _each(cssPath, function(i, path) {
  3598. if (path) {
  3599. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3600. }
  3601. });
  3602. if (cssData) {
  3603. arr.push('<style>' + cssData + '</style>');
  3604. }
  3605. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3606. return arr.join('\n');
  3607. }
  3608. function _elementVal(knode, val) {
  3609. if (knode.hasVal()) {
  3610. if (val === undefined) {
  3611. var html = knode.val();
  3612. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3613. return html;
  3614. }
  3615. return knode.val(val);
  3616. }
  3617. return knode.html(val);
  3618. }
  3619. function KEdit(options) {
  3620. this.init(options);
  3621. }
  3622. _extend(KEdit, KWidget, {
  3623. init : function(options) {
  3624. var self = this;
  3625. KEdit.parent.init.call(self, options);
  3626. self.srcElement = K(options.srcElement);
  3627. self.div.addClass('ke-edit');
  3628. self.designMode = _undef(options.designMode, true);
  3629. self.beforeGetHtml = options.beforeGetHtml;
  3630. self.beforeSetHtml = options.beforeSetHtml;
  3631. self.afterSetHtml = options.afterSetHtml;
  3632. var themesPath = _undef(options.themesPath, ''),
  3633. bodyClass = options.bodyClass,
  3634. cssPath = options.cssPath,
  3635. cssData = options.cssData,
  3636. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3637. srcScript = ('document.open();' +
  3638. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3639. 'document.close();'),
  3640. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3641. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3642. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3643. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3644. self.iframe.attr('tabindex', self.tabIndex);
  3645. self.textarea.attr('tabindex', self.tabIndex);
  3646. if (self.width) {
  3647. self.setWidth(self.width);
  3648. }
  3649. if (self.height) {
  3650. self.setHeight(self.height);
  3651. }
  3652. if (self.designMode) {
  3653. self.textarea.hide();
  3654. } else {
  3655. self.iframe.hide();
  3656. }
  3657. function ready() {
  3658. var doc = _iframeDoc(self.iframe);
  3659. doc.open();
  3660. if (isDocumentDomain) {
  3661. doc.domain = document.domain;
  3662. }
  3663. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3664. doc.close();
  3665. self.win = self.iframe[0].contentWindow;
  3666. self.doc = doc;
  3667. var cmd = _cmd(doc);
  3668. self.afterChange(function(e) {
  3669. cmd.selection();
  3670. });
  3671. if (_WEBKIT) {
  3672. K(doc).click(function(e) {
  3673. if (K(e.target).name === 'img') {
  3674. cmd.selection(true);
  3675. cmd.range.selectNode(e.target);
  3676. cmd.select();
  3677. }
  3678. });
  3679. }
  3680. if (_IE) {
  3681. self._mousedownHandler = function() {
  3682. var newRange = cmd.range.cloneRange();
  3683. newRange.shrink();
  3684. if (newRange.isControl()) {
  3685. self.blur();
  3686. }
  3687. };
  3688. K(document).mousedown(self._mousedownHandler);
  3689. K(doc).keydown(function(e) {
  3690. if (e.which == 8) {
  3691. cmd.selection();
  3692. var rng = cmd.range;
  3693. if (rng.isControl()) {
  3694. rng.collapse(true);
  3695. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3696. e.preventDefault();
  3697. }
  3698. }
  3699. });
  3700. }
  3701. self.cmd = cmd;
  3702. self.html(_elementVal(self.srcElement));
  3703. if (_IE) {
  3704. doc.body.disabled = true;
  3705. doc.body.contentEditable = true;
  3706. doc.body.removeAttribute('disabled');
  3707. } else {
  3708. doc.designMode = 'on';
  3709. }
  3710. if (options.afterCreate) {
  3711. options.afterCreate.call(self);
  3712. }
  3713. }
  3714. if (isDocumentDomain) {
  3715. self.iframe.bind('load', function(e) {
  3716. self.iframe.unbind('load');
  3717. if (_IE) {
  3718. ready();
  3719. } else {
  3720. setTimeout(ready, 0);
  3721. }
  3722. });
  3723. }
  3724. self.div.append(self.iframe);
  3725. self.div.append(self.textarea);
  3726. self.srcElement.hide();
  3727. !isDocumentDomain && ready();
  3728. },
  3729. setWidth : function(val) {
  3730. this.div.css('width', _addUnit(val));
  3731. return this;
  3732. },
  3733. setHeight : function(val) {
  3734. var self = this;
  3735. val = _addUnit(val);
  3736. self.div.css('height', val);
  3737. self.iframe.css('height', val);
  3738. if ((_IE && _V < 8) || _QUIRKS) {
  3739. val = _addUnit(_removeUnit(val) - 2);
  3740. }
  3741. self.textarea.css('height', val);
  3742. return self;
  3743. },
  3744. remove : function() {
  3745. var self = this, doc = self.doc;
  3746. K(doc.body).unbind();
  3747. K(doc).unbind();
  3748. K(self.win).unbind();
  3749. if (self._mousedownHandler) {
  3750. K(document).unbind('mousedown', self._mousedownHandler);
  3751. }
  3752. _elementVal(self.srcElement, self.html());
  3753. self.srcElement.show();
  3754. doc.write('');
  3755. self.iframe.unbind();
  3756. self.textarea.unbind();
  3757. KEdit.parent.remove.call(self);
  3758. },
  3759. html : function(val, isFull) {
  3760. var self = this, doc = self.doc;
  3761. if (self.designMode) {
  3762. var body = doc.body;
  3763. if (val === undefined) {
  3764. if (isFull) {
  3765. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3766. } else {
  3767. val = body.innerHTML;
  3768. }
  3769. if (self.beforeGetHtml) {
  3770. val = self.beforeGetHtml(val);
  3771. }
  3772. if (_GECKO && val == '<br />') {
  3773. val = '';
  3774. }
  3775. return val;
  3776. }
  3777. if (self.beforeSetHtml) {
  3778. val = self.beforeSetHtml(val);
  3779. }
  3780. if (_IE && _V >= 9) {
  3781. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3782. }
  3783. K(body).html(val);
  3784. if (self.afterSetHtml) {
  3785. self.afterSetHtml();
  3786. }
  3787. return self;
  3788. }
  3789. if (val === undefined) {
  3790. return self.textarea.val();
  3791. }
  3792. self.textarea.val(val);
  3793. return self;
  3794. },
  3795. design : function(bool) {
  3796. var self = this, val;
  3797. if (bool === undefined ? !self.designMode : bool) {
  3798. if (!self.designMode) {
  3799. val = self.html();
  3800. self.designMode = true;
  3801. self.html(val);
  3802. self.textarea.hide();
  3803. self.iframe.show();
  3804. }
  3805. } else {
  3806. if (self.designMode) {
  3807. val = self.html();
  3808. self.designMode = false;
  3809. self.html(val);
  3810. self.iframe.hide();
  3811. self.textarea.show();
  3812. }
  3813. }
  3814. return self.focus();
  3815. },
  3816. focus : function() {
  3817. var self = this;
  3818. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3819. return self;
  3820. },
  3821. blur : function() {
  3822. var self = this;
  3823. if (_IE) {
  3824. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3825. self.div.append(input);
  3826. input[0].focus();
  3827. input.remove();
  3828. } else {
  3829. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3830. }
  3831. return self;
  3832. },
  3833. afterChange : function(fn) {
  3834. var self = this, doc = self.doc, body = doc.body;
  3835. K(doc).keyup(function(e) {
  3836. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3837. fn(e);
  3838. }
  3839. });
  3840. K(doc).mouseup(fn).contextmenu(fn);
  3841. K(self.win).blur(fn);
  3842. function timeoutHandler(e) {
  3843. setTimeout(function() {
  3844. fn(e);
  3845. }, 1);
  3846. }
  3847. K(body).bind('paste', timeoutHandler);
  3848. K(body).bind('cut', timeoutHandler);
  3849. return self;
  3850. }
  3851. });
  3852. function _edit(options) {
  3853. return new KEdit(options);
  3854. }
  3855. K.EditClass = KEdit;
  3856. K.edit = _edit;
  3857. K.iframeDoc = _iframeDoc;
  3858. function _selectToolbar(name, fn) {
  3859. var self = this,
  3860. knode = self.get(name);
  3861. if (knode) {
  3862. if (knode.hasClass('ke-disabled')) {
  3863. return;
  3864. }
  3865. fn(knode);
  3866. }
  3867. }
  3868. function KToolbar(options) {
  3869. this.init(options);
  3870. }
  3871. _extend(KToolbar, KWidget, {
  3872. init : function(options) {
  3873. var self = this;
  3874. KToolbar.parent.init.call(self, options);
  3875. self.disableMode = _undef(options.disableMode, false);
  3876. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3877. self._itemMap = {};
  3878. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3879. e.preventDefault();
  3880. }).attr('unselectable', 'on');
  3881. function find(target) {
  3882. var knode = K(target);
  3883. if (knode.hasClass('ke-outline')) {
  3884. return knode;
  3885. }
  3886. if (knode.hasClass('ke-toolbar-icon')) {
  3887. return knode.parent();
  3888. }
  3889. }
  3890. function hover(e, method) {
  3891. var knode = find(e.target);
  3892. if (knode) {
  3893. if (knode.hasClass('ke-disabled')) {
  3894. return;
  3895. }
  3896. if (knode.hasClass('ke-selected')) {
  3897. return;
  3898. }
  3899. knode[method]('ke-on');
  3900. }
  3901. }
  3902. self.div.mouseover(function(e) {
  3903. hover(e, 'addClass');
  3904. })
  3905. .mouseout(function(e) {
  3906. hover(e, 'removeClass');
  3907. })
  3908. .click(function(e) {
  3909. var knode = find(e.target);
  3910. if (knode) {
  3911. if (knode.hasClass('ke-disabled')) {
  3912. return;
  3913. }
  3914. self.options.click.call(this, e, knode.attr('data-name'));
  3915. }
  3916. });
  3917. },
  3918. get : function(name) {
  3919. if (this._itemMap[name]) {
  3920. return this._itemMap[name];
  3921. }
  3922. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3923. },
  3924. select : function(name) {
  3925. _selectToolbar.call(this, name, function(knode) {
  3926. knode.addClass('ke-selected');
  3927. });
  3928. return self;
  3929. },
  3930. unselect : function(name) {
  3931. _selectToolbar.call(this, name, function(knode) {
  3932. knode.removeClass('ke-selected').removeClass('ke-on');
  3933. });
  3934. return self;
  3935. },
  3936. enable : function(name) {
  3937. var self = this,
  3938. knode = name.get ? name : self.get(name);
  3939. if (knode) {
  3940. knode.removeClass('ke-disabled');
  3941. knode.opacity(1);
  3942. }
  3943. return self;
  3944. },
  3945. disable : function(name) {
  3946. var self = this,
  3947. knode = name.get ? name : self.get(name);
  3948. if (knode) {
  3949. knode.removeClass('ke-selected').addClass('ke-disabled');
  3950. knode.opacity(0.5);
  3951. }
  3952. return self;
  3953. },
  3954. disableAll : function(bool, noDisableItems) {
  3955. var self = this, map = self.noDisableItemMap, item;
  3956. if (noDisableItems) {
  3957. map = _toMap(noDisableItems);
  3958. }
  3959. if (bool === undefined ? !self.disableMode : bool) {
  3960. K('span.ke-outline', self.div).each(function() {
  3961. var knode = K(this),
  3962. name = knode[0].getAttribute('data-name', 2);
  3963. if (!map[name]) {
  3964. self.disable(knode);
  3965. }
  3966. });
  3967. self.disableMode = true;
  3968. } else {
  3969. K('span.ke-outline', self.div).each(function() {
  3970. var knode = K(this),
  3971. name = knode[0].getAttribute('data-name', 2);
  3972. if (!map[name]) {
  3973. self.enable(knode);
  3974. }
  3975. });
  3976. self.disableMode = false;
  3977. }
  3978. return self;
  3979. }
  3980. });
  3981. function _toolbar(options) {
  3982. return new KToolbar(options);
  3983. }
  3984. K.ToolbarClass = KToolbar;
  3985. K.toolbar = _toolbar;
  3986. function KMenu(options) {
  3987. this.init(options);
  3988. }
  3989. _extend(KMenu, KWidget, {
  3990. init : function(options) {
  3991. var self = this;
  3992. options.z = options.z || 811213;
  3993. KMenu.parent.init.call(self, options);
  3994. self.centerLineMode = _undef(options.centerLineMode, true);
  3995. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  3996. e.stopPropagation();
  3997. }).attr('unselectable', 'on');
  3998. },
  3999. addItem : function(item) {
  4000. var self = this;
  4001. if (item.title === '-') {
  4002. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4003. return;
  4004. }
  4005. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4006. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4007. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4008. height = _addUnit(item.height),
  4009. iconClass = _undef(item.iconClass, '');
  4010. self.div.append(itemDiv);
  4011. if (height) {
  4012. itemDiv.css('height', height);
  4013. rightDiv.css('line-height', height);
  4014. }
  4015. var centerDiv;
  4016. if (self.centerLineMode) {
  4017. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4018. if (height) {
  4019. centerDiv.css('height', height);
  4020. }
  4021. }
  4022. itemDiv.mouseover(function(e) {
  4023. K(this).addClass('ke-menu-item-on');
  4024. if (centerDiv) {
  4025. centerDiv.addClass('ke-menu-item-center-on');
  4026. }
  4027. })
  4028. .mouseout(function(e) {
  4029. K(this).removeClass('ke-menu-item-on');
  4030. if (centerDiv) {
  4031. centerDiv.removeClass('ke-menu-item-center-on');
  4032. }
  4033. })
  4034. .click(function(e) {
  4035. item.click.call(K(this));
  4036. e.stopPropagation();
  4037. })
  4038. .append(leftDiv);
  4039. if (centerDiv) {
  4040. itemDiv.append(centerDiv);
  4041. }
  4042. itemDiv.append(rightDiv);
  4043. if (item.checked) {
  4044. iconClass = 'ke-icon-checked';
  4045. }
  4046. if (iconClass !== '') {
  4047. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4048. }
  4049. rightDiv.html(item.title);
  4050. return self;
  4051. },
  4052. remove : function() {
  4053. var self = this;
  4054. if (self.options.beforeRemove) {
  4055. self.options.beforeRemove.call(self);
  4056. }
  4057. K('.ke-menu-item', self.div[0]).unbind();
  4058. KMenu.parent.remove.call(self);
  4059. return self;
  4060. }
  4061. });
  4062. function _menu(options) {
  4063. return new KMenu(options);
  4064. }
  4065. K.MenuClass = KMenu;
  4066. K.menu = _menu;
  4067. function KColorPicker(options) {
  4068. this.init(options);
  4069. }
  4070. _extend(KColorPicker, KWidget, {
  4071. init : function(options) {
  4072. var self = this;
  4073. options.z = options.z || 811213;
  4074. KColorPicker.parent.init.call(self, options);
  4075. var colors = options.colors || [
  4076. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4077. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4078. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4079. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4080. ];
  4081. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4082. self._cells = [];
  4083. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4084. e.stopPropagation();
  4085. }).attr('unselectable', 'on');
  4086. var table = self.doc.createElement('table');
  4087. self.div.append(table);
  4088. table.className = 'ke-colorpicker-table';
  4089. table.cellPadding = 0;
  4090. table.cellSpacing = 0;
  4091. table.border = 0;
  4092. var row = table.insertRow(0), cell = row.insertCell(0);
  4093. cell.colSpan = colors[0].length;
  4094. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4095. for (var i = 0; i < colors.length; i++) {
  4096. row = table.insertRow(i + 1);
  4097. for (var j = 0; j < colors[i].length; j++) {
  4098. cell = row.insertCell(j);
  4099. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4100. }
  4101. }
  4102. },
  4103. _addAttr : function(cell, color, cls) {
  4104. var self = this;
  4105. cell = K(cell).addClass(cls);
  4106. if (self.selectedColor === color.toLowerCase()) {
  4107. cell.addClass('ke-colorpicker-cell-selected');
  4108. }
  4109. cell.attr('title', color || self.options.noColor);
  4110. cell.mouseover(function(e) {
  4111. K(this).addClass('ke-colorpicker-cell-on');
  4112. });
  4113. cell.mouseout(function(e) {
  4114. K(this).removeClass('ke-colorpicker-cell-on');
  4115. });
  4116. cell.click(function(e) {
  4117. e.stop();
  4118. self.options.click.call(K(this), color);
  4119. });
  4120. if (color) {
  4121. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4122. } else {
  4123. cell.html(self.options.noColor);
  4124. }
  4125. K(cell).attr('unselectable', 'on');
  4126. self._cells.push(cell);
  4127. },
  4128. remove : function() {
  4129. var self = this;
  4130. _each(self._cells, function() {
  4131. this.unbind();
  4132. });
  4133. KColorPicker.parent.remove.call(self);
  4134. return self;
  4135. }
  4136. });
  4137. function _colorpicker(options) {
  4138. return new KColorPicker(options);
  4139. }
  4140. K.ColorPickerClass = KColorPicker;
  4141. K.colorpicker = _colorpicker;
  4142. function KUploadButton(options) {
  4143. this.init(options);
  4144. }
  4145. _extend(KUploadButton, {
  4146. init : function(options) {
  4147. var self = this,
  4148. button = K(options.button),
  4149. fieldName = options.fieldName || 'file',
  4150. url = options.url || '',
  4151. title = button.val(),
  4152. extraParams = options.extraParams || {},
  4153. cls = button[0].className || '',
  4154. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4155. options.afterError = options.afterError || function(str) {
  4156. alert(str);
  4157. };
  4158. var hiddenElements = [];
  4159. for(var k in extraParams){
  4160. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4161. }
  4162. var html = [
  4163. '<div class="ke-inline-block ' + cls + '">',
  4164. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4165. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4166. '<span class="ke-button-common">',
  4167. hiddenElements.join(''),
  4168. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4169. '</span>',
  4170. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4171. (options.form ? '</div>' : '</form>'),
  4172. '</div>'].join('');
  4173. var div = K(html, button.doc);
  4174. button.hide();
  4175. button.before(div);
  4176. self.div = div;
  4177. self.button = button;
  4178. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4179. self.form = options.form ? K(options.form) : K('form', div);
  4180. self.fileBox = K('.ke-upload-file', div);
  4181. self.options = options;
  4182. },
  4183. submit : function() {
  4184. var self = this,
  4185. iframe = self.iframe;
  4186. iframe.bind('load', function() {
  4187. iframe.unbind();
  4188. var tempForm = document.createElement('form');
  4189. self.fileBox.before(tempForm);
  4190. K(tempForm).append(self.fileBox);
  4191. tempForm.reset();
  4192. K(tempForm).remove(true);
  4193. var doc = K.iframeDoc(iframe),
  4194. pre = doc.getElementsByTagName('pre')[0],
  4195. str = '', data;
  4196. if (pre) {
  4197. str = pre.innerHTML;
  4198. } else {
  4199. str = doc.body.innerHTML;
  4200. }
  4201. str = _unescape(str);
  4202. iframe[0].src = 'javascript:false';
  4203. try {
  4204. data = K.json(str);
  4205. } catch (e) {
  4206. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4207. }
  4208. if (data) {
  4209. self.options.afterUpload.call(self, data);
  4210. }
  4211. });
  4212. self.form[0].submit();
  4213. return self;
  4214. },
  4215. remove : function() {
  4216. var self = this;
  4217. if (self.fileBox) {
  4218. self.fileBox.unbind();
  4219. }
  4220. self.iframe.remove();
  4221. self.div.remove();
  4222. self.button.show();
  4223. return self;
  4224. }
  4225. });
  4226. function _uploadbutton(options) {
  4227. return new KUploadButton(options);
  4228. }
  4229. K.UploadButtonClass = KUploadButton;
  4230. K.uploadbutton = _uploadbutton;
  4231. function _createButton(arg) {
  4232. arg = arg || {};
  4233. var name = arg.name || '',
  4234. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4235. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4236. if (arg.click) {
  4237. btn.click(arg.click);
  4238. }
  4239. span.append(btn);
  4240. return span;
  4241. }
  4242. function KDialog(options) {
  4243. this.init(options);
  4244. }
  4245. _extend(KDialog, KWidget, {
  4246. init : function(options) {
  4247. var self = this;
  4248. var shadowMode = _undef(options.shadowMode, true);
  4249. options.z = options.z || 811213;
  4250. options.shadowMode = false;
  4251. options.autoScroll = _undef(options.autoScroll, true);
  4252. KDialog.parent.init.call(self, options);
  4253. var title = options.title,
  4254. body = K(options.body, self.doc),
  4255. previewBtn = options.previewBtn,
  4256. yesBtn = options.yesBtn,
  4257. noBtn = options.noBtn,
  4258. closeBtn = options.closeBtn,
  4259. showMask = _undef(options.showMask, true);
  4260. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4261. e.stopPropagation();
  4262. });
  4263. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4264. if (_IE && _V < 7) {
  4265. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4266. } else if (shadowMode) {
  4267. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4268. }
  4269. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4270. contentDiv.append(headerDiv);
  4271. headerDiv.html(title);
  4272. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4273. headerDiv.append(self.closeIcon);
  4274. self.draggable({
  4275. clickEl : headerDiv,
  4276. beforeDrag : options.beforeDrag
  4277. });
  4278. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4279. contentDiv.append(bodyDiv);
  4280. bodyDiv.append(body);
  4281. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4282. if (previewBtn || yesBtn || noBtn) {
  4283. contentDiv.append(footerDiv);
  4284. }
  4285. _each([
  4286. { btn : previewBtn, name : 'preview' },
  4287. { btn : yesBtn, name : 'yes' },
  4288. { btn : noBtn, name : 'no' }
  4289. ], function() {
  4290. if (this.btn) {
  4291. var button = _createButton(this.btn);
  4292. button.addClass('ke-dialog-' + this.name);
  4293. footerDiv.append(button);
  4294. }
  4295. });
  4296. if (self.height) {
  4297. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4298. }
  4299. self.div.width(self.div.width());
  4300. self.div.height(self.div.height());
  4301. self.mask = null;
  4302. if (showMask) {
  4303. var docEl = _docElement(self.doc),
  4304. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4305. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4306. self.mask = _widget({
  4307. x : 0,
  4308. y : 0,
  4309. z : self.z - 1,
  4310. cls : 'ke-dialog-mask',
  4311. width : docWidth,
  4312. height : docHeight
  4313. });
  4314. }
  4315. self.autoPos(self.div.width(), self.div.height());
  4316. self.footerDiv = footerDiv;
  4317. self.bodyDiv = bodyDiv;
  4318. self.headerDiv = headerDiv;
  4319. self.isLoading = false;
  4320. },
  4321. setMaskIndex : function(z) {
  4322. var self = this;
  4323. self.mask.div.css('z-index', z);
  4324. },
  4325. showLoading : function(msg) {
  4326. msg = _undef(msg, '');
  4327. var self = this, body = self.bodyDiv;
  4328. 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>')
  4329. .width(body.width()).height(body.height())
  4330. .css('top', self.headerDiv.height() + 'px');
  4331. body.css('visibility', 'hidden').after(self.loading);
  4332. self.isLoading = true;
  4333. return self;
  4334. },
  4335. hideLoading : function() {
  4336. this.loading && this.loading.remove();
  4337. this.bodyDiv.css('visibility', 'visible');
  4338. this.isLoading = false;
  4339. return this;
  4340. },
  4341. remove : function() {
  4342. var self = this;
  4343. if (self.options.beforeRemove) {
  4344. self.options.beforeRemove.call(self);
  4345. }
  4346. self.mask && self.mask.remove();
  4347. self.iframeMask && self.iframeMask.remove();
  4348. self.closeIcon.unbind();
  4349. K('input', self.div).unbind();
  4350. K('button', self.div).unbind();
  4351. self.footerDiv.unbind();
  4352. self.bodyDiv.unbind();
  4353. self.headerDiv.unbind();
  4354. K('iframe', self.div).each(function() {
  4355. K(this).remove();
  4356. });
  4357. KDialog.parent.remove.call(self);
  4358. return self;
  4359. }
  4360. });
  4361. function _dialog(options) {
  4362. return new KDialog(options);
  4363. }
  4364. K.DialogClass = KDialog;
  4365. K.dialog = _dialog;
  4366. function _tabs(options) {
  4367. var self = _widget(options),
  4368. remove = self.remove,
  4369. afterSelect = options.afterSelect,
  4370. div = self.div,
  4371. liList = [];
  4372. div.addClass('ke-tabs')
  4373. .bind('contextmenu,mousedown,mousemove', function(e) {
  4374. e.preventDefault();
  4375. });
  4376. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4377. div.append(ul);
  4378. self.add = function(tab) {
  4379. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4380. li.data('tab', tab);
  4381. liList.push(li);
  4382. ul.append(li);
  4383. };
  4384. self.selectedIndex = 0;
  4385. self.select = function(index) {
  4386. self.selectedIndex = index;
  4387. _each(liList, function(i, li) {
  4388. li.unbind();
  4389. if (i === index) {
  4390. li.addClass('ke-tabs-li-selected');
  4391. K(li.data('tab').panel).show('');
  4392. } else {
  4393. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4394. .mouseover(function() {
  4395. K(this).addClass('ke-tabs-li-on');
  4396. })
  4397. .mouseout(function() {
  4398. K(this).removeClass('ke-tabs-li-on');
  4399. })
  4400. .click(function() {
  4401. self.select(i);
  4402. });
  4403. K(li.data('tab').panel).hide();
  4404. }
  4405. });
  4406. if (afterSelect) {
  4407. afterSelect.call(self, index);
  4408. }
  4409. };
  4410. self.remove = function() {
  4411. _each(liList, function() {
  4412. this.remove();
  4413. });
  4414. ul.remove();
  4415. remove.call(self);
  4416. };
  4417. return self;
  4418. }
  4419. K.tabs = _tabs;
  4420. function _loadScript(url, fn) {
  4421. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4422. script = document.createElement('script');
  4423. head.appendChild(script);
  4424. script.src = url;
  4425. script.charset = 'utf-8';
  4426. script.onload = script.onreadystatechange = function() {
  4427. if (!this.readyState || this.readyState === 'loaded') {
  4428. if (fn) {
  4429. fn();
  4430. }
  4431. script.onload = script.onreadystatechange = null;
  4432. head.removeChild(script);
  4433. }
  4434. };
  4435. }
  4436. function _chopQuery(url) {
  4437. var index = url.indexOf('?');
  4438. return index > 0 ? url.substr(0, index) : url;
  4439. }
  4440. function _loadStyle(url) {
  4441. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4442. link = document.createElement('link'),
  4443. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4444. var links = K('link[rel="stylesheet"]', head);
  4445. for (var i = 0, len = links.length; i < len; i++) {
  4446. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4447. return;
  4448. }
  4449. }
  4450. head.appendChild(link);
  4451. link.href = url;
  4452. link.rel = 'stylesheet';
  4453. }
  4454. function _ajax(url, fn, method, param, dataType) {
  4455. method = method || 'GET';
  4456. dataType = dataType || 'json';
  4457. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4458. xhr.open(method, url, true);
  4459. xhr.onreadystatechange = function () {
  4460. if (xhr.readyState == 4 && xhr.status == 200) {
  4461. if (fn) {
  4462. var data = _trim(xhr.responseText);
  4463. if (dataType == 'json') {
  4464. data = _json(data);
  4465. }
  4466. fn(data);
  4467. }
  4468. }
  4469. };
  4470. if (method == 'POST') {
  4471. var params = [];
  4472. _each(param, function(key, val) {
  4473. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4474. });
  4475. try {
  4476. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4477. } catch (e) {}
  4478. xhr.send(params.join('&'));
  4479. } else {
  4480. xhr.send(null);
  4481. }
  4482. }
  4483. K.loadScript = _loadScript;
  4484. K.loadStyle = _loadStyle;
  4485. K.ajax = _ajax;
  4486. var _plugins = {};
  4487. function _plugin(name, fn) {
  4488. if (name === undefined) {
  4489. return _plugins;
  4490. }
  4491. if (!fn) {
  4492. return _plugins[name];
  4493. }
  4494. _plugins[name] = fn;
  4495. }
  4496. var _language = {};
  4497. function _parseLangKey(key) {
  4498. var match, ns = 'core';
  4499. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4500. ns = match[1];
  4501. key = match[2];
  4502. }
  4503. return { ns : ns, key : key };
  4504. }
  4505. function _lang(mixed, langType) {
  4506. langType = langType === undefined ? K.options.langType : langType;
  4507. if (typeof mixed === 'string') {
  4508. if (!_language[langType]) {
  4509. return 'no language';
  4510. }
  4511. var pos = mixed.length - 1;
  4512. if (mixed.substr(pos) === '.') {
  4513. return _language[langType][mixed.substr(0, pos)];
  4514. }
  4515. var obj = _parseLangKey(mixed);
  4516. return _language[langType][obj.ns][obj.key];
  4517. }
  4518. _each(mixed, function(key, val) {
  4519. var obj = _parseLangKey(key);
  4520. if (!_language[langType]) {
  4521. _language[langType] = {};
  4522. }
  4523. if (!_language[langType][obj.ns]) {
  4524. _language[langType][obj.ns] = {};
  4525. }
  4526. _language[langType][obj.ns][obj.key] = val;
  4527. });
  4528. }
  4529. function _getImageFromRange(range, fn) {
  4530. if (range.collapsed) {
  4531. return;
  4532. }
  4533. range = range.cloneRange().up();
  4534. var sc = range.startContainer, so = range.startOffset;
  4535. if (!_WEBKIT && !range.isControl()) {
  4536. return;
  4537. }
  4538. var img = K(sc.childNodes[so]);
  4539. if (!img || img.name != 'img') {
  4540. return;
  4541. }
  4542. if (fn(img)) {
  4543. return img;
  4544. }
  4545. }
  4546. function _bindContextmenuEvent() {
  4547. var self = this, doc = self.edit.doc;
  4548. K(doc).contextmenu(function(e) {
  4549. if (self.menu) {
  4550. self.hideMenu();
  4551. }
  4552. if (!self.useContextmenu) {
  4553. e.preventDefault();
  4554. return;
  4555. }
  4556. if (self._contextmenus.length === 0) {
  4557. return;
  4558. }
  4559. var maxWidth = 0, items = [];
  4560. _each(self._contextmenus, function() {
  4561. if (this.title == '-') {
  4562. items.push(this);
  4563. return;
  4564. }
  4565. if (this.cond && this.cond()) {
  4566. items.push(this);
  4567. if (this.width && this.width > maxWidth) {
  4568. maxWidth = this.width;
  4569. }
  4570. }
  4571. });
  4572. while (items.length > 0 && items[0].title == '-') {
  4573. items.shift();
  4574. }
  4575. while (items.length > 0 && items[items.length - 1].title == '-') {
  4576. items.pop();
  4577. }
  4578. var prevItem = null;
  4579. _each(items, function(i) {
  4580. if (this.title == '-' && prevItem.title == '-') {
  4581. delete items[i];
  4582. }
  4583. prevItem = this;
  4584. });
  4585. if (items.length > 0) {
  4586. e.preventDefault();
  4587. var pos = K(self.edit.iframe).pos(),
  4588. menu = _menu({
  4589. x : pos.x + e.clientX,
  4590. y : pos.y + e.clientY,
  4591. width : maxWidth,
  4592. css : { visibility: 'hidden' },
  4593. shadowMode : self.shadowMode
  4594. });
  4595. _each(items, function() {
  4596. if (this.title) {
  4597. menu.addItem(this);
  4598. }
  4599. });
  4600. var docEl = _docElement(menu.doc),
  4601. menuHeight = menu.div.height();
  4602. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4603. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4604. }
  4605. menu.div.css('visibility', 'visible');
  4606. self.menu = menu;
  4607. }
  4608. });
  4609. }
  4610. function _bindNewlineEvent() {
  4611. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4612. if (_IE && newlineTag !== 'br') {
  4613. return;
  4614. }
  4615. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4616. return;
  4617. }
  4618. if (_OPERA && _V < 9) {
  4619. return;
  4620. }
  4621. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4622. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4623. function getAncestorTagName(range) {
  4624. var ancestor = K(range.commonAncestor());
  4625. while (ancestor) {
  4626. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4627. break;
  4628. }
  4629. ancestor = ancestor.parent();
  4630. }
  4631. return ancestor.name;
  4632. }
  4633. K(doc).keydown(function(e) {
  4634. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4635. return;
  4636. }
  4637. self.cmd.selection();
  4638. var tagName = getAncestorTagName(self.cmd.range);
  4639. if (tagName == 'marquee' || tagName == 'select') {
  4640. return;
  4641. }
  4642. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4643. e.preventDefault();
  4644. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4645. return;
  4646. }
  4647. if (!pSkipTagMap[tagName]) {
  4648. _nativeCommand(doc, 'formatblock', '<p>');
  4649. }
  4650. });
  4651. K(doc).keyup(function(e) {
  4652. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4653. return;
  4654. }
  4655. if (newlineTag == 'br') {
  4656. return;
  4657. }
  4658. if (_GECKO) {
  4659. var root = self.cmd.commonAncestor('p');
  4660. var a = self.cmd.commonAncestor('a');
  4661. if (a && a.text() == '') {
  4662. a.remove(true);
  4663. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4664. self.cmd.select();
  4665. }
  4666. return;
  4667. }
  4668. self.cmd.selection();
  4669. var tagName = getAncestorTagName(self.cmd.range);
  4670. if (tagName == 'marquee' || tagName == 'select') {
  4671. return;
  4672. }
  4673. if (!pSkipTagMap[tagName]) {
  4674. _nativeCommand(doc, 'formatblock', '<p>');
  4675. }
  4676. var div = self.cmd.commonAncestor('div');
  4677. if (div) {
  4678. var p = K('<p></p>'),
  4679. child = div[0].firstChild;
  4680. while (child) {
  4681. var next = child.nextSibling;
  4682. p.append(child);
  4683. child = next;
  4684. }
  4685. div.before(p);
  4686. div.remove();
  4687. self.cmd.range.selectNodeContents(p[0]);
  4688. self.cmd.select();
  4689. }
  4690. });
  4691. }
  4692. function _bindTabEvent() {
  4693. var self = this, doc = self.edit.doc;
  4694. K(doc).keydown(function(e) {
  4695. if (e.which == 9) {
  4696. e.preventDefault();
  4697. if (self.afterTab) {
  4698. self.afterTab.call(self, e);
  4699. return;
  4700. }
  4701. var cmd = self.cmd, range = cmd.range;
  4702. range.shrink();
  4703. if (range.collapsed && range.startContainer.nodeType == 1) {
  4704. range.insertNode(K('@&nbsp;', doc)[0]);
  4705. cmd.select();
  4706. }
  4707. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4708. }
  4709. });
  4710. }
  4711. function _bindFocusEvent() {
  4712. var self = this;
  4713. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4714. if (self.afterFocus) {
  4715. self.afterFocus.call(self, e);
  4716. }
  4717. }).blur(function(e) {
  4718. if (self.afterBlur) {
  4719. self.afterBlur.call(self, e);
  4720. }
  4721. });
  4722. }
  4723. function _removeBookmarkTag(html) {
  4724. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4725. }
  4726. function _removeTempTag(html) {
  4727. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4728. }
  4729. function _addBookmarkToStack(stack, bookmark) {
  4730. if (stack.length === 0) {
  4731. stack.push(bookmark);
  4732. return;
  4733. }
  4734. var prev = stack[stack.length - 1];
  4735. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4736. stack.push(bookmark);
  4737. }
  4738. }
  4739. function _undoToRedo(fromStack, toStack) {
  4740. var self = this, edit = self.edit,
  4741. body = edit.doc.body,
  4742. range, bookmark;
  4743. if (fromStack.length === 0) {
  4744. return self;
  4745. }
  4746. if (edit.designMode) {
  4747. range = self.cmd.range;
  4748. bookmark = range.createBookmark(true);
  4749. bookmark.html = body.innerHTML;
  4750. } else {
  4751. bookmark = {
  4752. html : body.innerHTML
  4753. };
  4754. }
  4755. _addBookmarkToStack(toStack, bookmark);
  4756. var prev = fromStack.pop();
  4757. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4758. prev = fromStack.pop();
  4759. }
  4760. if (edit.designMode) {
  4761. edit.html(prev.html);
  4762. if (prev.start) {
  4763. range.moveToBookmark(prev);
  4764. self.select();
  4765. }
  4766. } else {
  4767. K(body).html(_removeBookmarkTag(prev.html));
  4768. }
  4769. return self;
  4770. }
  4771. function KEditor(options) {
  4772. var self = this;
  4773. self.options = {};
  4774. function setOption(key, val) {
  4775. if (KEditor.prototype[key] === undefined) {
  4776. self[key] = val;
  4777. }
  4778. self.options[key] = val;
  4779. }
  4780. _each(options, function(key, val) {
  4781. setOption(key, options[key]);
  4782. });
  4783. _each(K.options, function(key, val) {
  4784. if (self[key] === undefined) {
  4785. setOption(key, val);
  4786. }
  4787. });
  4788. var se = K(self.srcElement || '<textarea/>');
  4789. if (!self.width) {
  4790. self.width = se[0].style.width || se.width();
  4791. }
  4792. if (!self.height) {
  4793. self.height = se[0].style.height || se.height();
  4794. }
  4795. setOption('width', _undef(self.width, self.minWidth));
  4796. setOption('height', _undef(self.height, self.minHeight));
  4797. setOption('width', _addUnit(self.width));
  4798. setOption('height', _addUnit(self.height));
  4799. if (_MOBILE && (!_IOS || _V < 534)) {
  4800. self.designMode = false;
  4801. }
  4802. self.srcElement = se;
  4803. self.initContent = '';
  4804. self.plugin = {};
  4805. self.isCreated = false;
  4806. self._handlers = {};
  4807. self._contextmenus = [];
  4808. self._undoStack = [];
  4809. self._redoStack = [];
  4810. self._firstAddBookmark = true;
  4811. self.menu = self.contextmenu = null;
  4812. self.dialogs = [];
  4813. }
  4814. KEditor.prototype = {
  4815. lang : function(mixed) {
  4816. return _lang(mixed, this.langType);
  4817. },
  4818. loadPlugin : function(name, fn) {
  4819. var self = this;
  4820. if (_plugins[name]) {
  4821. if (!_isFunction(_plugins[name])) {
  4822. setTimeout(function() {
  4823. self.loadPlugin(name, fn);
  4824. }, 100);
  4825. return self;
  4826. }
  4827. _plugins[name].call(self, KindEditor);
  4828. if (fn) {
  4829. fn.call(self);
  4830. }
  4831. return self;
  4832. }
  4833. _plugins[name] = 'loading';
  4834. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4835. setTimeout(function() {
  4836. if (_plugins[name]) {
  4837. self.loadPlugin(name, fn);
  4838. }
  4839. }, 0);
  4840. });
  4841. return self;
  4842. },
  4843. handler : function(key, fn) {
  4844. var self = this;
  4845. if (!self._handlers[key]) {
  4846. self._handlers[key] = [];
  4847. }
  4848. if (_isFunction(fn)) {
  4849. self._handlers[key].push(fn);
  4850. return self;
  4851. }
  4852. _each(self._handlers[key], function() {
  4853. fn = this.call(self, fn);
  4854. });
  4855. return fn;
  4856. },
  4857. clickToolbar : function(name, fn) {
  4858. var self = this, key = 'clickToolbar' + name;
  4859. if (fn === undefined) {
  4860. if (self._handlers[key]) {
  4861. return self.handler(key);
  4862. }
  4863. self.loadPlugin(name, function() {
  4864. self.handler(key);
  4865. });
  4866. return self;
  4867. }
  4868. return self.handler(key, fn);
  4869. },
  4870. updateState : function() {
  4871. var self = this;
  4872. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4873. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4874. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4875. });
  4876. return self;
  4877. },
  4878. addContextmenu : function(item) {
  4879. this._contextmenus.push(item);
  4880. return this;
  4881. },
  4882. afterCreate : function(fn) {
  4883. return this.handler('afterCreate', fn);
  4884. },
  4885. beforeRemove : function(fn) {
  4886. return this.handler('beforeRemove', fn);
  4887. },
  4888. beforeGetHtml : function(fn) {
  4889. return this.handler('beforeGetHtml', fn);
  4890. },
  4891. beforeSetHtml : function(fn) {
  4892. return this.handler('beforeSetHtml', fn);
  4893. },
  4894. afterSetHtml : function(fn) {
  4895. return this.handler('afterSetHtml', fn);
  4896. },
  4897. create : function() {
  4898. var self = this, fullscreenMode = self.fullscreenMode;
  4899. if (self.isCreated) {
  4900. return self;
  4901. }
  4902. if (self.srcElement.data('kindeditor')) {
  4903. return self;
  4904. }
  4905. self.srcElement.data('kindeditor', 'true');
  4906. if (fullscreenMode) {
  4907. _docElement().style.overflow = 'hidden';
  4908. } else {
  4909. _docElement().style.overflow = '';
  4910. }
  4911. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4912. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4913. if ((_IE && _V < 8) || _QUIRKS) {
  4914. height = _addUnit(_removeUnit(height) + 2);
  4915. }
  4916. var container = self.container = K(self.layout);
  4917. if (fullscreenMode) {
  4918. K(document.body).append(container);
  4919. } else {
  4920. self.srcElement.before(container);
  4921. }
  4922. var toolbarDiv = K('.toolbar', container),
  4923. editDiv = K('.edit', container),
  4924. statusbar = self.statusbar = K('.statusbar', container);
  4925. container.removeClass('container')
  4926. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4927. if (fullscreenMode) {
  4928. container.css({
  4929. position : 'absolute',
  4930. left : 0,
  4931. top : 0,
  4932. 'z-index' : 811211
  4933. });
  4934. if (!_GECKO) {
  4935. self._scrollPos = _getScrollPos();
  4936. }
  4937. window.scrollTo(0, 0);
  4938. K(document.body).css({
  4939. 'height' : '1px',
  4940. 'overflow' : 'hidden'
  4941. });
  4942. K(document.body.parentNode).css('overflow', 'hidden');
  4943. self._fullscreenExecuted = true;
  4944. } else {
  4945. if (self._fullscreenExecuted) {
  4946. K(document.body).css({
  4947. 'height' : '',
  4948. 'overflow' : ''
  4949. });
  4950. K(document.body.parentNode).css('overflow', '');
  4951. }
  4952. if (self._scrollPos) {
  4953. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4954. }
  4955. }
  4956. var htmlList = [];
  4957. K.each(self.items, function(i, name) {
  4958. if (name == '|') {
  4959. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4960. } else if (name == '/') {
  4961. htmlList.push('<div class="ke-hr"></div>');
  4962. } else {
  4963. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4964. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4965. }
  4966. });
  4967. var toolbar = self.toolbar = _toolbar({
  4968. src : toolbarDiv,
  4969. html : htmlList.join(''),
  4970. noDisableItems : self.noDisableItems,
  4971. click : function(e, name) {
  4972. e.stop();
  4973. if (self.menu) {
  4974. var menuName = self.menu.name;
  4975. self.hideMenu();
  4976. if (menuName === name) {
  4977. return;
  4978. }
  4979. }
  4980. self.clickToolbar(name);
  4981. }
  4982. });
  4983. var editHeight = _removeUnit(height) - toolbar.div.height();
  4984. var edit = self.edit = _edit({
  4985. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  4986. src : editDiv,
  4987. srcElement : self.srcElement,
  4988. designMode : self.designMode,
  4989. themesPath : self.themesPath,
  4990. bodyClass : self.bodyClass,
  4991. cssPath : self.cssPath,
  4992. cssData : self.cssData,
  4993. beforeGetHtml : function(html) {
  4994. html = self.beforeGetHtml(html);
  4995. html = _removeBookmarkTag(_removeTempTag(html));
  4996. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  4997. },
  4998. beforeSetHtml : function(html) {
  4999. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5000. return self.beforeSetHtml(html);
  5001. },
  5002. afterSetHtml : function() {
  5003. self.edit = edit = this;
  5004. self.afterSetHtml();
  5005. },
  5006. afterCreate : function() {
  5007. self.edit = edit = this;
  5008. self.cmd = edit.cmd;
  5009. self._docMousedownFn = function(e) {
  5010. if (self.menu) {
  5011. self.hideMenu();
  5012. }
  5013. };
  5014. K(edit.doc, document).mousedown(self._docMousedownFn);
  5015. _bindContextmenuEvent.call(self);
  5016. _bindNewlineEvent.call(self);
  5017. _bindTabEvent.call(self);
  5018. _bindFocusEvent.call(self);
  5019. edit.afterChange(function(e) {
  5020. if (!edit.designMode) {
  5021. return;
  5022. }
  5023. self.updateState();
  5024. self.addBookmark();
  5025. if (self.options.afterChange) {
  5026. self.options.afterChange.call(self);
  5027. }
  5028. });
  5029. edit.textarea.keyup(function(e) {
  5030. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5031. if (self.options.afterChange) {
  5032. self.options.afterChange.call(self);
  5033. }
  5034. }
  5035. });
  5036. if (self.readonlyMode) {
  5037. self.readonly();
  5038. }
  5039. self.isCreated = true;
  5040. if (self.initContent === '') {
  5041. self.initContent = self.html();
  5042. }
  5043. if (self._undoStack.length > 0) {
  5044. var prev = self._undoStack.pop();
  5045. if (prev.start) {
  5046. self.html(prev.html);
  5047. edit.cmd.range.moveToBookmark(prev);
  5048. self.select();
  5049. }
  5050. }
  5051. self.afterCreate();
  5052. if (self.options.afterCreate) {
  5053. self.options.afterCreate.call(self);
  5054. }
  5055. }
  5056. });
  5057. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5058. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5059. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5060. if (self._fullscreenResizeHandler) {
  5061. K(window).unbind('resize', self._fullscreenResizeHandler);
  5062. self._fullscreenResizeHandler = null;
  5063. }
  5064. function initResize() {
  5065. if (statusbar.height() === 0) {
  5066. setTimeout(initResize, 100);
  5067. return;
  5068. }
  5069. self.resize(width, height, false);
  5070. }
  5071. initResize();
  5072. if (fullscreenMode) {
  5073. self._fullscreenResizeHandler = function(e) {
  5074. if (self.isCreated) {
  5075. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5076. }
  5077. };
  5078. K(window).bind('resize', self._fullscreenResizeHandler);
  5079. toolbar.select('fullscreen');
  5080. statusbar.first().css('visibility', 'hidden');
  5081. statusbar.last().css('visibility', 'hidden');
  5082. } else {
  5083. if (_GECKO) {
  5084. K(window).bind('scroll', function(e) {
  5085. self._scrollPos = _getScrollPos();
  5086. });
  5087. }
  5088. if (self.resizeType > 0) {
  5089. _drag({
  5090. moveEl : container,
  5091. clickEl : statusbar,
  5092. moveFn : function(x, y, width, height, diffX, diffY) {
  5093. height += diffY;
  5094. self.resize(null, height);
  5095. }
  5096. });
  5097. } else {
  5098. statusbar.first().css('visibility', 'hidden');
  5099. }
  5100. if (self.resizeType === 2) {
  5101. _drag({
  5102. moveEl : container,
  5103. clickEl : statusbar.last(),
  5104. moveFn : function(x, y, width, height, diffX, diffY) {
  5105. width += diffX;
  5106. height += diffY;
  5107. self.resize(width, height);
  5108. }
  5109. });
  5110. } else {
  5111. statusbar.last().css('visibility', 'hidden');
  5112. }
  5113. }
  5114. return self;
  5115. },
  5116. remove : function() {
  5117. var self = this;
  5118. if (!self.isCreated) {
  5119. return self;
  5120. }
  5121. self.beforeRemove();
  5122. self.srcElement.data('kindeditor', '');
  5123. if (self.menu) {
  5124. self.hideMenu();
  5125. }
  5126. _each(self.dialogs, function() {
  5127. self.hideDialog();
  5128. });
  5129. K(document).unbind('mousedown', self._docMousedownFn);
  5130. self.toolbar.remove();
  5131. self.edit.remove();
  5132. self.statusbar.last().unbind();
  5133. self.statusbar.unbind();
  5134. self.container.remove();
  5135. self.container = self.toolbar = self.edit = self.menu = null;
  5136. self.dialogs = [];
  5137. self.isCreated = false;
  5138. return self;
  5139. },
  5140. resize : function(width, height, updateProp) {
  5141. var self = this;
  5142. updateProp = _undef(updateProp, true);
  5143. if (width) {
  5144. if (!/%/.test(width)) {
  5145. width = _removeUnit(width);
  5146. width = width < self.minWidth ? self.minWidth : width;
  5147. }
  5148. self.container.css('width', _addUnit(width));
  5149. if (updateProp) {
  5150. self.width = _addUnit(width);
  5151. }
  5152. }
  5153. if (height) {
  5154. height = _removeUnit(height);
  5155. editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5156. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5157. self.edit.setHeight(editHeight);
  5158. if (updateProp) {
  5159. self.height = _addUnit(height);
  5160. }
  5161. }
  5162. return self;
  5163. },
  5164. select : function() {
  5165. this.isCreated && this.cmd.select();
  5166. return this;
  5167. },
  5168. html : function(val) {
  5169. var self = this;
  5170. if (val === undefined) {
  5171. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5172. }
  5173. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5174. if (self.isCreated) {
  5175. self.cmd.selection();
  5176. }
  5177. return self;
  5178. },
  5179. fullHtml : function() {
  5180. return this.isCreated ? this.edit.html(undefined, true) : '';
  5181. },
  5182. text : function(val) {
  5183. var self = this;
  5184. if (val === undefined) {
  5185. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5186. } else {
  5187. return self.html(_escape(val));
  5188. }
  5189. },
  5190. isEmpty : function() {
  5191. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5192. },
  5193. isDirty : function() {
  5194. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5195. },
  5196. selectedHtml : function() {
  5197. var val = this.isCreated ? this.cmd.range.html() : '';
  5198. val = _removeBookmarkTag(_removeTempTag(val));
  5199. return val;
  5200. },
  5201. count : function(mode) {
  5202. var self = this;
  5203. mode = (mode || 'html').toLowerCase();
  5204. if (mode === 'html') {
  5205. return self.html().length;
  5206. }
  5207. if (mode === 'text') {
  5208. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5209. }
  5210. return 0;
  5211. },
  5212. exec : function(key) {
  5213. key = key.toLowerCase();
  5214. var self = this, cmd = self.cmd,
  5215. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5216. if (changeFlag) {
  5217. self.addBookmark(false);
  5218. }
  5219. cmd[key].apply(cmd, _toArray(arguments, 1));
  5220. if (changeFlag) {
  5221. self.updateState();
  5222. self.addBookmark(false);
  5223. if (self.options.afterChange) {
  5224. self.options.afterChange.call(self);
  5225. }
  5226. }
  5227. return self;
  5228. },
  5229. insertHtml : function(val, quickMode) {
  5230. if (!this.isCreated) {
  5231. return this;
  5232. }
  5233. val = this.beforeSetHtml(val);
  5234. this.exec('inserthtml', val, quickMode);
  5235. return this;
  5236. },
  5237. appendHtml : function(val) {
  5238. this.html(this.html() + val);
  5239. if (this.isCreated) {
  5240. var cmd = this.cmd;
  5241. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5242. cmd.select();
  5243. }
  5244. return this;
  5245. },
  5246. sync : function() {
  5247. _elementVal(this.srcElement, this.html());
  5248. return this;
  5249. },
  5250. focus : function() {
  5251. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5252. return this;
  5253. },
  5254. blur : function() {
  5255. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5256. return this;
  5257. },
  5258. addBookmark : function(checkSize) {
  5259. checkSize = _undef(checkSize, true);
  5260. var self = this, edit = self.edit,
  5261. body = edit.doc.body,
  5262. html = _removeTempTag(body.innerHTML), bookmark;
  5263. if (checkSize && self._undoStack.length > 0) {
  5264. var prev = self._undoStack[self._undoStack.length - 1];
  5265. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5266. return self;
  5267. }
  5268. }
  5269. if (edit.designMode && !self._firstAddBookmark) {
  5270. var range = self.cmd.range;
  5271. bookmark = range.createBookmark(true);
  5272. bookmark.html = _removeTempTag(body.innerHTML);
  5273. range.moveToBookmark(bookmark);
  5274. } else {
  5275. bookmark = {
  5276. html : html
  5277. };
  5278. }
  5279. self._firstAddBookmark = false;
  5280. _addBookmarkToStack(self._undoStack, bookmark);
  5281. return self;
  5282. },
  5283. undo : function() {
  5284. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5285. },
  5286. redo : function() {
  5287. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5288. },
  5289. fullscreen : function(bool) {
  5290. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5291. this.addBookmark(false);
  5292. return this.remove().create();
  5293. },
  5294. readonly : function(isReadonly) {
  5295. isReadonly = _undef(isReadonly, true);
  5296. var self = this, edit = self.edit, doc = edit.doc;
  5297. if (self.designMode) {
  5298. self.toolbar.disableAll(isReadonly, []);
  5299. } else {
  5300. _each(self.noDisableItems, function() {
  5301. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5302. });
  5303. }
  5304. if (_IE) {
  5305. doc.body.contentEditable = !isReadonly;
  5306. } else {
  5307. doc.designMode = isReadonly ? 'off' : 'on';
  5308. }
  5309. edit.textarea[0].disabled = isReadonly;
  5310. },
  5311. createMenu : function(options) {
  5312. var self = this,
  5313. name = options.name,
  5314. knode = self.toolbar.get(name),
  5315. pos = knode.pos();
  5316. options.x = pos.x;
  5317. options.y = pos.y + knode.height();
  5318. options.z = self.options.zIndex;
  5319. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5320. if (options.selectedColor !== undefined) {
  5321. options.cls = 'ke-colorpicker-' + self.themeType;
  5322. options.noColor = self.lang('noColor');
  5323. self.menu = _colorpicker(options);
  5324. } else {
  5325. options.cls = 'ke-menu-' + self.themeType;
  5326. options.centerLineMode = false;
  5327. self.menu = _menu(options);
  5328. }
  5329. return self.menu;
  5330. },
  5331. hideMenu : function() {
  5332. this.menu.remove();
  5333. this.menu = null;
  5334. return this;
  5335. },
  5336. hideContextmenu : function() {
  5337. this.contextmenu.remove();
  5338. this.contextmenu = null;
  5339. return this;
  5340. },
  5341. createDialog : function(options) {
  5342. var self = this, name = options.name;
  5343. options.z = self.options.zIndex;
  5344. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5345. options.closeBtn = _undef(options.closeBtn, {
  5346. name : self.lang('close'),
  5347. click : function(e) {
  5348. self.hideDialog();
  5349. if (_IE && self.cmd) {
  5350. self.cmd.select();
  5351. }
  5352. }
  5353. });
  5354. options.noBtn = _undef(options.noBtn, {
  5355. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5356. click : function(e) {
  5357. self.hideDialog();
  5358. if (_IE && self.cmd) {
  5359. self.cmd.select();
  5360. }
  5361. }
  5362. });
  5363. if (self.dialogAlignType != 'page') {
  5364. options.alignEl = self.container;
  5365. }
  5366. options.cls = 'ke-dialog-' + self.themeType;
  5367. if (self.dialogs.length > 0) {
  5368. var firstDialog = self.dialogs[0],
  5369. parentDialog = self.dialogs[self.dialogs.length - 1];
  5370. firstDialog.setMaskIndex(parentDialog.z + 2);
  5371. options.z = parentDialog.z + 3;
  5372. options.showMask = false;
  5373. }
  5374. var dialog = _dialog(options);
  5375. self.dialogs.push(dialog);
  5376. return dialog;
  5377. },
  5378. hideDialog : function() {
  5379. var self = this;
  5380. if (self.dialogs.length > 0) {
  5381. self.dialogs.pop().remove();
  5382. }
  5383. if (self.dialogs.length > 0) {
  5384. var firstDialog = self.dialogs[0],
  5385. parentDialog = self.dialogs[self.dialogs.length - 1];
  5386. firstDialog.setMaskIndex(parentDialog.z - 1);
  5387. }
  5388. return self;
  5389. },
  5390. errorDialog : function(html) {
  5391. var self = this;
  5392. var dialog = self.createDialog({
  5393. width : 750,
  5394. title : self.lang('uploadError'),
  5395. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5396. });
  5397. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5398. doc.open();
  5399. doc.write(html);
  5400. doc.close();
  5401. K(doc.body).css('background-color', '#FFF');
  5402. iframe[0].contentWindow.focus();
  5403. return self;
  5404. }
  5405. };
  5406. function _editor(options) {
  5407. return new KEditor(options);
  5408. }
  5409. _instances = [];
  5410. function _create(expr, options) {
  5411. options = options || {};
  5412. options.basePath = _undef(options.basePath, K.basePath);
  5413. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5414. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5415. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5416. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5417. var themeType = _undef(options.themeType, K.options.themeType);
  5418. _loadStyle(options.themesPath + 'default/default.css');
  5419. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5420. }
  5421. function create(editor) {
  5422. _each(_plugins, function(name, fn) {
  5423. if (_isFunction(fn)) {
  5424. fn.call(editor, KindEditor);
  5425. }
  5426. });
  5427. return editor.create();
  5428. }
  5429. var knode = K(expr);
  5430. if (!knode || knode.length === 0) {
  5431. return;
  5432. }
  5433. if (knode.length > 1) {
  5434. knode.each(function() {
  5435. _create(this, options);
  5436. });
  5437. return _instances[0];
  5438. }
  5439. options.srcElement = knode[0];
  5440. var editor = new KEditor(options);
  5441. _instances.push(editor);
  5442. if (_language[editor.langType]) {
  5443. return create(editor);
  5444. }
  5445. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5446. create(editor);
  5447. });
  5448. return editor;
  5449. }
  5450. function _eachEditor(expr, fn) {
  5451. K(expr).each(function(i, el) {
  5452. K.each(_instances, function(j, editor) {
  5453. if (editor && editor.srcElement[0] == el) {
  5454. fn.call(editor, j);
  5455. return false;
  5456. }
  5457. });
  5458. });
  5459. }
  5460. K.remove = function(expr) {
  5461. _eachEditor(expr, function(i) {
  5462. this.remove();
  5463. _instances.splice(i, 1);
  5464. });
  5465. };
  5466. K.sync = function(expr) {
  5467. _eachEditor(expr, function() {
  5468. this.sync();
  5469. });
  5470. };
  5471. K.html = function(expr, val) {
  5472. _eachEditor(expr, function() {
  5473. this.html(val);
  5474. });
  5475. };
  5476. K.insertHtml = function(expr, val) {
  5477. _eachEditor(expr, function() {
  5478. this.insertHtml(val);
  5479. });
  5480. };
  5481. K.appendHtml = function(expr, val) {
  5482. _eachEditor(expr, function() {
  5483. this.appendHtml(val);
  5484. });
  5485. };
  5486. if (_IE && _V < 7) {
  5487. _nativeCommand(document, 'BackgroundImageCache', true);
  5488. }
  5489. K.EditorClass = KEditor;
  5490. K.editor = _editor;
  5491. K.create = _create;
  5492. K.instances = _instances;
  5493. K.plugin = _plugin;
  5494. K.lang = _lang;
  5495. _plugin('core', function(K) {
  5496. var self = this,
  5497. shortcutKeys = {
  5498. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5499. };
  5500. self.afterSetHtml(function() {
  5501. if (self.options.afterChange) {
  5502. self.options.afterChange.call(self);
  5503. }
  5504. });
  5505. self.afterCreate(function() {
  5506. if (self.syncType != 'form') {
  5507. return;
  5508. }
  5509. var el = K(self.srcElement), hasForm = false;
  5510. while ((el = el.parent())) {
  5511. if (el.name == 'form') {
  5512. hasForm = true;
  5513. break;
  5514. }
  5515. }
  5516. if (hasForm) {
  5517. el.bind('submit', function(e) {
  5518. self.sync();
  5519. K(window).bind('unload', function() {
  5520. self.edit.textarea.remove();
  5521. });
  5522. });
  5523. var resetBtn = K('[type="reset"]', el);
  5524. resetBtn.click(function() {
  5525. self.html(self.initContent);
  5526. self.cmd.selection();
  5527. });
  5528. self.beforeRemove(function() {
  5529. el.unbind();
  5530. resetBtn.unbind();
  5531. });
  5532. }
  5533. });
  5534. self.clickToolbar('source', function() {
  5535. if (self.edit.designMode) {
  5536. self.toolbar.disableAll(true);
  5537. self.edit.design(false);
  5538. self.toolbar.select('source');
  5539. } else {
  5540. self.toolbar.disableAll(false);
  5541. self.edit.design(true);
  5542. self.toolbar.unselect('source');
  5543. if (_GECKO) {
  5544. setTimeout(function() {
  5545. self.cmd.selection();
  5546. }, 0);
  5547. } else {
  5548. self.cmd.selection();
  5549. }
  5550. }
  5551. self.designMode = self.edit.designMode;
  5552. });
  5553. self.afterCreate(function() {
  5554. if (!self.designMode) {
  5555. self.toolbar.disableAll(true).select('source');
  5556. }
  5557. });
  5558. self.clickToolbar('fullscreen', function() {
  5559. self.fullscreen();
  5560. });
  5561. if (self.fullscreenShortcut) {
  5562. var loaded = false;
  5563. self.afterCreate(function() {
  5564. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5565. if (e.which == 27) {
  5566. setTimeout(function() {
  5567. self.fullscreen();
  5568. }, 0);
  5569. }
  5570. });
  5571. if (loaded) {
  5572. if (_IE && !self.designMode) {
  5573. return;
  5574. }
  5575. self.focus();
  5576. }
  5577. if (!loaded) {
  5578. loaded = true;
  5579. }
  5580. });
  5581. }
  5582. _each('undo,redo'.split(','), function(i, name) {
  5583. if (shortcutKeys[name]) {
  5584. self.afterCreate(function() {
  5585. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5586. self.clickToolbar(name);
  5587. });
  5588. });
  5589. }
  5590. self.clickToolbar(name, function() {
  5591. self[name]();
  5592. });
  5593. });
  5594. self.clickToolbar('formatblock', function() {
  5595. var blocks = self.lang('formatblock.formatBlock'),
  5596. heights = {
  5597. h1 : 28,
  5598. h2 : 24,
  5599. h3 : 18,
  5600. H4 : 14,
  5601. p : 12
  5602. },
  5603. curVal = self.cmd.val('formatblock'),
  5604. menu = self.createMenu({
  5605. name : 'formatblock',
  5606. width : self.langType == 'en' ? 200 : 150
  5607. });
  5608. _each(blocks, function(key, val) {
  5609. var style = 'font-size:' + heights[key] + 'px;';
  5610. if (key.charAt(0) === 'h') {
  5611. style += 'font-weight:bold;';
  5612. }
  5613. menu.addItem({
  5614. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5615. height : heights[key] + 12,
  5616. checked : (curVal === key || curVal === val),
  5617. click : function() {
  5618. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5619. }
  5620. });
  5621. });
  5622. });
  5623. self.clickToolbar('fontname', function() {
  5624. var curVal = self.cmd.val('fontname'),
  5625. menu = self.createMenu({
  5626. name : 'fontname',
  5627. width : 150
  5628. });
  5629. _each(self.lang('fontname.fontName'), function(key, val) {
  5630. menu.addItem({
  5631. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5632. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5633. click : function() {
  5634. self.exec('fontname', key).hideMenu();
  5635. }
  5636. });
  5637. });
  5638. });
  5639. self.clickToolbar('fontsize', function() {
  5640. var curVal = self.cmd.val('fontsize'),
  5641. menu = self.createMenu({
  5642. name : 'fontsize',
  5643. width : 150
  5644. });
  5645. _each(self.fontSizeTable, function(i, val) {
  5646. menu.addItem({
  5647. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5648. height : _removeUnit(val) + 12,
  5649. checked : curVal === val,
  5650. click : function() {
  5651. self.exec('fontsize', val).hideMenu();
  5652. }
  5653. });
  5654. });
  5655. });
  5656. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5657. self.clickToolbar(name, function() {
  5658. self.createMenu({
  5659. name : name,
  5660. selectedColor : self.cmd.val(name) || 'default',
  5661. colors : self.colorTable,
  5662. click : function(color) {
  5663. self.exec(name, color).hideMenu();
  5664. }
  5665. });
  5666. });
  5667. });
  5668. _each(('cut,copy,paste').split(','), function(i, name) {
  5669. self.clickToolbar(name, function() {
  5670. self.focus();
  5671. try {
  5672. self.exec(name, null);
  5673. } catch(e) {
  5674. alert(self.lang(name + 'Error'));
  5675. }
  5676. });
  5677. });
  5678. self.clickToolbar('about', function() {
  5679. var html = '<div style="margin:20px;">' +
  5680. '<div>KindEditor ' + _VERSION + '</div>' +
  5681. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5682. '</div>';
  5683. self.createDialog({
  5684. name : 'about',
  5685. width : 350,
  5686. title : self.lang('about'),
  5687. body : html
  5688. });
  5689. });
  5690. self.plugin.getSelectedLink = function() {
  5691. return self.cmd.commonAncestor('a');
  5692. };
  5693. self.plugin.getSelectedImage = function() {
  5694. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5695. return !/^ke-\w+$/i.test(img[0].className);
  5696. });
  5697. };
  5698. self.plugin.getSelectedFlash = function() {
  5699. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5700. return img[0].className == 'ke-flash';
  5701. });
  5702. };
  5703. self.plugin.getSelectedMedia = function() {
  5704. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5705. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5706. });
  5707. };
  5708. self.plugin.getSelectedAnchor = function() {
  5709. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5710. return img[0].className == 'ke-anchor';
  5711. });
  5712. };
  5713. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5714. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5715. _each('edit,delete'.split(','), function(j, val) {
  5716. self.addContextmenu({
  5717. title : self.lang(val + uName),
  5718. click : function() {
  5719. self.loadPlugin(name, function() {
  5720. self.plugin[name][val]();
  5721. self.hideMenu();
  5722. });
  5723. },
  5724. cond : self.plugin['getSelected' + uName],
  5725. width : 150,
  5726. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5727. });
  5728. });
  5729. self.addContextmenu({ title : '-' });
  5730. });
  5731. self.plugin.getSelectedTable = function() {
  5732. return self.cmd.commonAncestor('table');
  5733. };
  5734. self.plugin.getSelectedRow = function() {
  5735. return self.cmd.commonAncestor('tr');
  5736. };
  5737. self.plugin.getSelectedCell = function() {
  5738. return self.cmd.commonAncestor('td');
  5739. };
  5740. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5741. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5742. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5743. self.addContextmenu({
  5744. title : self.lang('table' + val),
  5745. click : function() {
  5746. self.loadPlugin('table', function() {
  5747. self.plugin.table[val]();
  5748. self.hideMenu();
  5749. });
  5750. },
  5751. cond : cond,
  5752. width : 170,
  5753. iconClass : 'ke-icon-table' + val
  5754. });
  5755. });
  5756. self.addContextmenu({ title : '-' });
  5757. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5758. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5759. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5760. if (shortcutKeys[name]) {
  5761. self.afterCreate(function() {
  5762. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5763. self.cmd.selection();
  5764. self.clickToolbar(name);
  5765. });
  5766. });
  5767. }
  5768. self.clickToolbar(name, function() {
  5769. self.focus().exec(name, null);
  5770. });
  5771. });
  5772. self.afterCreate(function() {
  5773. var doc = self.edit.doc, cmd, bookmark, div,
  5774. cls = '__kindeditor_paste__', pasting = false;
  5775. function movePastedData() {
  5776. cmd.range.moveToBookmark(bookmark);
  5777. cmd.select();
  5778. if (_WEBKIT) {
  5779. K('div.' + cls, div).each(function() {
  5780. K(this).after('<br />').remove(true);
  5781. });
  5782. K('span.Apple-style-span', div).remove(true);
  5783. K('span.Apple-tab-span', div).remove(true);
  5784. K('span[style]', div).each(function() {
  5785. if (K(this).css('white-space') == 'nowrap') {
  5786. K(this).remove(true);
  5787. }
  5788. });
  5789. K('meta', div).remove();
  5790. }
  5791. var html = div[0].innerHTML;
  5792. div.remove();
  5793. if (html === '') {
  5794. return;
  5795. }
  5796. if (_WEBKIT) {
  5797. html = html.replace(/(<br>)\1/ig, '$1');
  5798. }
  5799. if (self.pasteType === 2) {
  5800. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5801. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5802. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5803. } else {
  5804. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5805. html = self.beforeSetHtml(html);
  5806. }
  5807. }
  5808. if (self.pasteType === 1) {
  5809. html = html.replace(/&nbsp;/ig, ' ');
  5810. html = html.replace(/\n\s*\n/g, '\n');
  5811. html = html.replace(/<br[^>]*>/ig, '\n');
  5812. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5813. html = html.replace(/<[^>]+>/g, '');
  5814. html = html.replace(/ {2}/g, ' &nbsp;');
  5815. if (self.newlineTag == 'p') {
  5816. if (/\n/.test(html)) {
  5817. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5818. }
  5819. } else {
  5820. html = html.replace(/\n/g, '<br />$&');
  5821. }
  5822. }
  5823. self.insertHtml(html, true);
  5824. }
  5825. K(doc.body).bind('paste', function(e){
  5826. if (self.pasteType === 0) {
  5827. e.stop();
  5828. return;
  5829. }
  5830. if (pasting) {
  5831. return;
  5832. }
  5833. pasting = true;
  5834. K('div.' + cls, doc).remove();
  5835. cmd = self.cmd.selection();
  5836. bookmark = cmd.range.createBookmark();
  5837. div = K('<div class="' + cls + '"></div>', doc).css({
  5838. position : 'absolute',
  5839. width : '1px',
  5840. height : '1px',
  5841. overflow : 'hidden',
  5842. left : '-1981px',
  5843. top : K(bookmark.start).pos().y + 'px',
  5844. 'white-space' : 'nowrap'
  5845. });
  5846. K(doc.body).append(div);
  5847. if (_IE) {
  5848. var rng = cmd.range.get(true);
  5849. rng.moveToElementText(div[0]);
  5850. rng.select();
  5851. rng.execCommand('paste');
  5852. e.preventDefault();
  5853. } else {
  5854. cmd.range.selectNodeContents(div[0]);
  5855. cmd.select();
  5856. }
  5857. setTimeout(function() {
  5858. movePastedData();
  5859. pasting = false;
  5860. }, 0);
  5861. });
  5862. });
  5863. self.beforeGetHtml(function(html) {
  5864. if (_IE && _V <= 8) {
  5865. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5866. return unescape(tag);
  5867. });
  5868. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5869. if (!/\s+type="[^"]+"/i.test($0)) {
  5870. return $1 + ' type="text"' + $2;
  5871. }
  5872. return $0;
  5873. });
  5874. }
  5875. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5876. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5877. })
  5878. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5879. var imgAttrs = _getAttrList(full);
  5880. var styles = _getCssList(imgAttrs.style || '');
  5881. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5882. var width = _undef(styles.width, '');
  5883. var height = _undef(styles.height, '');
  5884. if (/px/i.test(width)) {
  5885. width = _removeUnit(width);
  5886. }
  5887. if (/px/i.test(height)) {
  5888. height = _removeUnit(height);
  5889. }
  5890. attrs.width = _undef(imgAttrs.width, width);
  5891. attrs.height = _undef(imgAttrs.height, height);
  5892. return _mediaEmbed(attrs);
  5893. })
  5894. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  5895. var imgAttrs = _getAttrList(full);
  5896. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5897. })
  5898. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5899. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5900. })
  5901. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5902. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5903. })
  5904. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  5905. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  5906. return $1 + _unescape(src) + $2;
  5907. });
  5908. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5909. return full;
  5910. })
  5911. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5912. return start + end;
  5913. });
  5914. });
  5915. self.beforeSetHtml(function(html) {
  5916. if (_IE && _V <= 8) {
  5917. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  5918. var attrs = _getAttrList(full);
  5919. var styles = _getCssList(attrs.style || '');
  5920. if (styles.display == 'none') {
  5921. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5922. }
  5923. return full;
  5924. });
  5925. }
  5926. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  5927. var attrs = _getAttrList(full);
  5928. attrs.src = _undef(attrs.src, '');
  5929. attrs.width = _undef(attrs.width, 0);
  5930. attrs.height = _undef(attrs.height, 0);
  5931. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5932. })
  5933. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  5934. var attrs = _getAttrList(full);
  5935. if (attrs.href !== undefined) {
  5936. return full;
  5937. }
  5938. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5939. })
  5940. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  5941. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5942. })
  5943. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  5944. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5945. })
  5946. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  5947. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5948. return full;
  5949. }
  5950. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5951. return full;
  5952. })
  5953. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5954. return start + 'data-ke-' + end;
  5955. })
  5956. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  5957. if (full.indexOf('ke-zeroborder') >= 0) {
  5958. return full;
  5959. }
  5960. return _addClassToTag(full, 'ke-zeroborder');
  5961. });
  5962. });
  5963. });
  5964. })(window);
  5965. /*******************************************************************************
  5966. * KindEditor - WYSIWYG HTML Editor for Internet
  5967. * Copyright (C) 2006-2011 kindsoft.net
  5968. *
  5969. * @author Roddy <luolonghao@gmail.com>
  5970. * @site http://www.kindsoft.net/
  5971. * @licence http://www.kindsoft.net/license.php
  5972. *******************************************************************************/
  5973. KindEditor.lang({
  5974. source : 'HTML代码',
  5975. preview : '预览',
  5976. undo : '后退(Ctrl+Z)',
  5977. redo : '前进(Ctrl+Y)',
  5978. cut : '剪切(Ctrl+X)',
  5979. copy : '复制(Ctrl+C)',
  5980. paste : '粘贴(Ctrl+V)',
  5981. plainpaste : '粘贴为无格式文本',
  5982. wordpaste : '从Word粘贴',
  5983. selectall : '全选(Ctrl+A)',
  5984. justifyleft : '左对齐',
  5985. justifycenter : '居中',
  5986. justifyright : '右对齐',
  5987. justifyfull : '两端对齐',
  5988. insertorderedlist : '编号',
  5989. insertunorderedlist : '项目符号',
  5990. indent : '增加缩进',
  5991. outdent : '减少缩进',
  5992. subscript : '下标',
  5993. superscript : '上标',
  5994. formatblock : '段落',
  5995. fontname : '字体',
  5996. fontsize : '文字大小',
  5997. forecolor : '文字颜色',
  5998. hilitecolor : '文字背景',
  5999. bold : '粗体(Ctrl+B)',
  6000. italic : '斜体(Ctrl+I)',
  6001. underline : '下划线(Ctrl+U)',
  6002. strikethrough : '删除线',
  6003. removeformat : '删除格式',
  6004. image : '图片',
  6005. multiimage : '批量图片上传',
  6006. flash : 'Flash',
  6007. media : '视音频',
  6008. table : '表格',
  6009. tablecell : '单元格',
  6010. hr : '插入横线',
  6011. emoticons : '插入表情',
  6012. link : '超级链接',
  6013. unlink : '取消超级链接',
  6014. fullscreen : '全屏显示',
  6015. about : '关于',
  6016. print : '打印(Ctrl+P)',
  6017. filemanager : '文件空间',
  6018. code : '插入程序代码',
  6019. map : 'Google地图',
  6020. baidumap : '百度地图',
  6021. lineheight : '行距',
  6022. clearhtml : '清理HTML代码',
  6023. pagebreak : '插入分页符',
  6024. quickformat : '一键排版',
  6025. insertfile : '插入文件',
  6026. template : '插入模板',
  6027. anchor : '锚点',
  6028. yes : '确定',
  6029. no : '取消',
  6030. close : '关闭',
  6031. editImage : '图片属性',
  6032. deleteImage : '删除图片',
  6033. editFlash : 'Flash属性',
  6034. deleteFlash : '删除Flash',
  6035. editMedia : '视音频属性',
  6036. deleteMedia : '删除视音频',
  6037. editLink : '超级链接属性',
  6038. deleteLink : '取消超级链接',
  6039. editAnchor : '锚点属性',
  6040. deleteAnchor : '删除锚点',
  6041. tableprop : '表格属性',
  6042. tablecellprop : '单元格属性',
  6043. tableinsert : '插入表格',
  6044. tabledelete : '删除表格',
  6045. tablecolinsertleft : '左侧插入列',
  6046. tablecolinsertright : '右侧插入列',
  6047. tablerowinsertabove : '上方插入行',
  6048. tablerowinsertbelow : '下方插入行',
  6049. tablerowmerge : '向下合并单元格',
  6050. tablecolmerge : '向右合并单元格',
  6051. tablerowsplit : '拆分行',
  6052. tablecolsplit : '拆分列',
  6053. tablecoldelete : '删除列',
  6054. tablerowdelete : '删除行',
  6055. noColor : '无颜色',
  6056. pleaseSelectFile : '请选择文件。',
  6057. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6058. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6059. invalidWidth : "宽度必须为数字。",
  6060. invalidHeight : "高度必须为数字。",
  6061. invalidBorder : "边框必须为数字。",
  6062. invalidUrl : "请输入有效的URL地址。",
  6063. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6064. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6065. invalidPadding : '边距必须为数字。',
  6066. invalidSpacing : '间距必须为数字。',
  6067. invalidJson : '服务器发生故障。',
  6068. uploadSuccess : '上传成功。',
  6069. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6070. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6071. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6072. ajaxLoading : '加载中,请稍候 ...',
  6073. uploadLoading : '上传中,请稍候 ...',
  6074. uploadError : '上传错误',
  6075. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6076. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6077. 'code.pleaseInput' : '请输入程序代码。',
  6078. 'link.url' : 'URL',
  6079. 'link.linkType' : '打开类型',
  6080. 'link.newWindow' : '新窗口',
  6081. 'link.selfWindow' : '当前窗口',
  6082. 'flash.url' : 'URL',
  6083. 'flash.width' : '宽度',
  6084. 'flash.height' : '高度',
  6085. 'flash.upload' : '上传',
  6086. 'flash.viewServer' : '文件空间',
  6087. 'media.url' : 'URL',
  6088. 'media.width' : '宽度',
  6089. 'media.height' : '高度',
  6090. 'media.autostart' : '自动播放',
  6091. 'media.upload' : '上传',
  6092. 'media.viewServer' : '文件空间',
  6093. 'image.remoteImage' : '网络图片',
  6094. 'image.localImage' : '本地上传',
  6095. 'image.remoteUrl' : '图片地址',
  6096. 'image.localUrl' : '上传文件',
  6097. 'image.size' : '图片大小',
  6098. 'image.width' : '宽',
  6099. 'image.height' : '高',
  6100. 'image.resetSize' : '重置大小',
  6101. 'image.align' : '对齐方式',
  6102. 'image.defaultAlign' : '默认方式',
  6103. 'image.leftAlign' : '左对齐',
  6104. 'image.rightAlign' : '右对齐',
  6105. 'image.imgTitle' : '图片说明',
  6106. 'image.upload' : '浏览...',
  6107. 'image.viewServer' : '图片空间',
  6108. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6109. 'multiimage.startUpload' : '开始上传',
  6110. 'multiimage.clearAll' : '全部清空',
  6111. 'multiimage.insertAll' : '全部插入',
  6112. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6113. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6114. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6115. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6116. 'multiimage.unknownError' : '发生异常,无法上传。',
  6117. 'multiimage.pending' : '等待上传',
  6118. 'multiimage.uploadError' : '上传失败',
  6119. 'filemanager.emptyFolder' : '空文件夹',
  6120. 'filemanager.moveup' : '移到上一级文件夹',
  6121. 'filemanager.viewType' : '显示方式:',
  6122. 'filemanager.viewImage' : '缩略图',
  6123. 'filemanager.listImage' : '详细信息',
  6124. 'filemanager.orderType' : '排序方式:',
  6125. 'filemanager.fileName' : '名称',
  6126. 'filemanager.fileSize' : '大小',
  6127. 'filemanager.fileType' : '类型',
  6128. 'insertfile.url' : 'URL',
  6129. 'insertfile.title' : '文件说明',
  6130. 'insertfile.upload' : '上传',
  6131. 'insertfile.viewServer' : '文件空间',
  6132. 'table.cells' : '单元格数',
  6133. 'table.rows' : '行数',
  6134. 'table.cols' : '列数',
  6135. 'table.size' : '大小',
  6136. 'table.width' : '宽度',
  6137. 'table.height' : '高度',
  6138. 'table.percent' : '%',
  6139. 'table.px' : 'px',
  6140. 'table.space' : '边距间距',
  6141. 'table.padding' : '边距',
  6142. 'table.spacing' : '间距',
  6143. 'table.align' : '对齐方式',
  6144. 'table.textAlign' : '水平对齐',
  6145. 'table.verticalAlign' : '垂直对齐',
  6146. 'table.alignDefault' : '默认',
  6147. 'table.alignLeft' : '左对齐',
  6148. 'table.alignCenter' : '居中',
  6149. 'table.alignRight' : '右对齐',
  6150. 'table.alignTop' : '顶部',
  6151. 'table.alignMiddle' : '中部',
  6152. 'table.alignBottom' : '底部',
  6153. 'table.alignBaseline' : '基线',
  6154. 'table.border' : '边框',
  6155. 'table.borderWidth' : '边框',
  6156. 'table.borderColor' : '颜色',
  6157. 'table.backgroundColor' : '背景颜色',
  6158. 'map.address' : '地址: ',
  6159. 'map.search' : '搜索',
  6160. 'baidumap.address' : '地址: ',
  6161. 'baidumap.search' : '搜索',
  6162. 'baidumap.insertDynamicMap' : '插入动态地图',
  6163. 'anchor.name' : '锚点名称',
  6164. 'formatblock.formatBlock' : {
  6165. h1 : '标题 1',
  6166. h2 : '标题 2',
  6167. h3 : '标题 3',
  6168. h4 : '标题 4',
  6169. p : '正 文'
  6170. },
  6171. 'fontname.fontName' : {
  6172. 'SimSun' : '宋体',
  6173. 'NSimSun' : '新宋体',
  6174. 'FangSong_GB2312' : '仿宋_GB2312',
  6175. 'KaiTi_GB2312' : '楷体_GB2312',
  6176. 'SimHei' : '黑体',
  6177. 'Microsoft YaHei' : '微软雅黑',
  6178. 'Arial' : 'Arial',
  6179. 'Arial Black' : 'Arial Black',
  6180. 'Times New Roman' : 'Times New Roman',
  6181. 'Courier New' : 'Courier New',
  6182. 'Tahoma' : 'Tahoma',
  6183. 'Verdana' : 'Verdana'
  6184. },
  6185. 'lineheight.lineHeight' : [
  6186. {'1' : '单倍行距'},
  6187. {'1.5' : '1.5倍行距'},
  6188. {'2' : '2倍行距'},
  6189. {'2.5' : '2.5倍行距'},
  6190. {'3' : '3倍行距'}
  6191. ],
  6192. 'template.selectTemplate' : '可选模板',
  6193. 'template.replaceContent' : '替换当前内容',
  6194. 'template.fileList' : {
  6195. '1.html' : '图片和文字',
  6196. '2.html' : '表格',
  6197. '3.html' : '项目编号'
  6198. }
  6199. }, 'zh_CN');
  6200. /*******************************************************************************
  6201. * KindEditor - WYSIWYG HTML Editor for Internet
  6202. * Copyright (C) 2006-2011 kindsoft.net
  6203. *
  6204. * @author Roddy <luolonghao@gmail.com>
  6205. * @site http://www.kindsoft.net/
  6206. * @licence http://www.kindsoft.net/license.php
  6207. *******************************************************************************/
  6208. KindEditor.plugin('anchor', function(K) {
  6209. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6210. self.plugin.anchor = {
  6211. edit : function() {
  6212. var html = ['<div style="padding:20px;">',
  6213. '<div class="ke-dialog-row">',
  6214. '<label for="keName">' + lang.name + '</label>',
  6215. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6216. '</div>',
  6217. '</div>'].join('');
  6218. var dialog = self.createDialog({
  6219. name : name,
  6220. width : 300,
  6221. title : self.lang(name),
  6222. body : html,
  6223. yesBtn : {
  6224. name : self.lang('yes'),
  6225. click : function(e) {
  6226. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6227. }
  6228. }
  6229. });
  6230. var div = dialog.div,
  6231. nameBox = K('input[name="name"]', div);
  6232. var img = self.plugin.getSelectedAnchor();
  6233. if (img) {
  6234. nameBox.val(unescape(img.attr('data-ke-name')));
  6235. }
  6236. nameBox[0].focus();
  6237. nameBox[0].select();
  6238. },
  6239. 'delete' : function() {
  6240. self.plugin.getSelectedAnchor().remove();
  6241. }
  6242. };
  6243. self.clickToolbar(name, self.plugin.anchor.edit);
  6244. });
  6245. /*******************************************************************************
  6246. * KindEditor - WYSIWYG HTML Editor for Internet
  6247. * Copyright (C) 2006-2011 kindsoft.net
  6248. *
  6249. * @author Roddy <luolonghao@gmail.com>
  6250. * @site http://www.kindsoft.net/
  6251. * @licence http://www.kindsoft.net/license.php
  6252. *******************************************************************************/
  6253. KindEditor.plugin('autoheight', function(K) {
  6254. var self = this;
  6255. if (!self.autoHeightMode) {
  6256. return;
  6257. }
  6258. var edit = self.edit;
  6259. var body = edit.doc.body;
  6260. var minHeight = K.removeUnit(self.height);
  6261. edit.iframe[0].scroll = 'no';
  6262. body.style.overflowY = 'hidden';
  6263. function resetHeight() {
  6264. edit.iframe.height(minHeight);
  6265. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6266. }
  6267. /*
  6268. * 如何实现真正的自动高度?
  6269. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6270. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6271. * 由此就实现了真正的自动高度
  6272. * 测试:chrome、firefox、IE9、IE8
  6273. * */
  6274. edit.afterChange(resetHeight);
  6275. if (self.isCreated) {
  6276. resetHeight();
  6277. } else {
  6278. self.afterCreate(resetHeight);
  6279. }
  6280. });
  6281. /*******************************************************************************
  6282. * KindEditor - WYSIWYG HTML Editor for Internet
  6283. * Copyright (C) 2006-2011 kindsoft.net
  6284. *
  6285. * @author Roddy <luolonghao@gmail.com>
  6286. * @site http://www.kindsoft.net/
  6287. * @licence http://www.kindsoft.net/license.php
  6288. *******************************************************************************/
  6289. // Baidu Maps: http://dev.baidu.com/wiki/map/index.php?title=%E9%A6%96%E9%A1%B5
  6290. KindEditor.plugin('baidumap', function(K) {
  6291. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6292. var mapWidth = K.undef(self.mapWidth, 558);
  6293. var mapHeight = K.undef(self.mapHeight, 360);
  6294. self.clickToolbar(name, function() {
  6295. var html = ['<div style="padding:10px 20px;">',
  6296. '<div class="ke-header">',
  6297. // left start
  6298. '<div class="ke-left">',
  6299. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6300. '<span class="ke-button-common ke-button-outer">',
  6301. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6302. '</span>',
  6303. '</div>',
  6304. // right start
  6305. '<div class="ke-right">',
  6306. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6307. '</div>',
  6308. '<div class="ke-clearfix"></div>',
  6309. '</div>',
  6310. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6311. '</div>'].join('');
  6312. var dialog = self.createDialog({
  6313. name : name,
  6314. width : mapWidth + 42,
  6315. title : self.lang(name),
  6316. body : html,
  6317. yesBtn : {
  6318. name : self.lang('yes'),
  6319. click : function(e) {
  6320. var map = win.map;
  6321. var centerObj = map.getCenter();
  6322. var center = centerObj.lng + ',' + centerObj.lat;
  6323. var zoom = map.getZoom();
  6324. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6325. '?center=' + encodeURIComponent(center),
  6326. '&zoom=' + encodeURIComponent(zoom),
  6327. '&width=' + mapWidth,
  6328. '&height=' + mapHeight,
  6329. '&markers=' + encodeURIComponent(center),
  6330. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6331. if (checkbox[0].checked) {
  6332. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6333. } else {
  6334. self.exec('insertimage', url);
  6335. }
  6336. self.hideDialog().focus();
  6337. }
  6338. },
  6339. beforeRemove : function() {
  6340. searchBtn.remove();
  6341. if (doc) {
  6342. doc.write('');
  6343. }
  6344. iframe.remove();
  6345. }
  6346. });
  6347. var div = dialog.div,
  6348. addressBox = K('[name="address"]', div),
  6349. searchBtn = K('[name="searchBtn"]', div),
  6350. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6351. win, doc;
  6352. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6353. function ready() {
  6354. win = iframe[0].contentWindow;
  6355. doc = K.iframeDoc(iframe);
  6356. }
  6357. iframe.bind('load', function() {
  6358. iframe.unbind('load');
  6359. if (K.IE) {
  6360. ready();
  6361. } else {
  6362. setTimeout(ready, 0);
  6363. }
  6364. });
  6365. K('.ke-map', div).replaceWith(iframe);
  6366. // search map
  6367. searchBtn.click(function() {
  6368. win.search(addressBox.val());
  6369. });
  6370. });
  6371. });
  6372. /*******************************************************************************
  6373. * KindEditor - WYSIWYG HTML Editor for Internet
  6374. * Copyright (C) 2006-2011 kindsoft.net
  6375. *
  6376. * @author Roddy <luolonghao@gmail.com>
  6377. * @site http://www.kindsoft.net/
  6378. * @licence http://www.kindsoft.net/license.php
  6379. *******************************************************************************/
  6380. KindEditor.plugin('clearhtml', function(K) {
  6381. var self = this, name = 'clearhtml';
  6382. self.clickToolbar(name, function() {
  6383. self.focus();
  6384. var html = self.html();
  6385. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6386. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6387. html = K.formatHtml(html, {
  6388. a : ['href', 'target'],
  6389. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6390. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6391. table : ['border'],
  6392. 'td,th' : ['rowspan', 'colspan'],
  6393. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6394. });
  6395. self.html(html);
  6396. self.cmd.selection(true);
  6397. self.addBookmark();
  6398. });
  6399. });
  6400. /*******************************************************************************
  6401. * KindEditor - WYSIWYG HTML Editor for Internet
  6402. * Copyright (C) 2006-2011 kindsoft.net
  6403. *
  6404. * @author Roddy <luolonghao@gmail.com>
  6405. * @site http://www.kindsoft.net/
  6406. * @licence http://www.kindsoft.net/license.php
  6407. *******************************************************************************/
  6408. // google code prettify: http://google-code-prettify.googlecode.com/
  6409. // http://google-code-prettify.googlecode.com/
  6410. KindEditor.plugin('code', function(K) {
  6411. var self = this, name = 'code';
  6412. self.clickToolbar(name, function() {
  6413. var lang = self.lang(name + '.'),
  6414. html = ['<div style="padding:10px 20px;">',
  6415. '<div class="ke-dialog-row">',
  6416. '<select class="ke-code-type">',
  6417. '<option value="js">JavaScript</option>',
  6418. '<option value="html">HTML</option>',
  6419. '<option value="css">CSS</option>',
  6420. '<option value="php">PHP</option>',
  6421. '<option value="pl">Perl</option>',
  6422. '<option value="py">Python</option>',
  6423. '<option value="rb">Ruby</option>',
  6424. '<option value="java">Java</option>',
  6425. '<option value="vb">ASP/VB</option>',
  6426. '<option value="cpp">C/C++</option>',
  6427. '<option value="cs">C#</option>',
  6428. '<option value="xml">XML</option>',
  6429. '<option value="bsh">Shell</option>',
  6430. '<option value="">Other</option>',
  6431. '</select>',
  6432. '</div>',
  6433. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6434. '</div>'].join(''),
  6435. dialog = self.createDialog({
  6436. name : name,
  6437. width : 450,
  6438. title : self.lang(name),
  6439. body : html,
  6440. yesBtn : {
  6441. name : self.lang('yes'),
  6442. click : function(e) {
  6443. var type = K('.ke-code-type', dialog.div).val(),
  6444. code = textarea.val(),
  6445. cls = type === '' ? '' : ' lang-' + type,
  6446. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6447. if (K.trim(code) === '') {
  6448. alert(lang.pleaseInput);
  6449. textarea[0].focus();
  6450. return;
  6451. }
  6452. self.insertHtml(html).hideDialog().focus();
  6453. }
  6454. }
  6455. }),
  6456. textarea = K('textarea', dialog.div);
  6457. textarea[0].focus();
  6458. });
  6459. });
  6460. /*******************************************************************************
  6461. * KindEditor - WYSIWYG HTML Editor for Internet
  6462. * Copyright (C) 2006-2011 kindsoft.net
  6463. *
  6464. * @author Roddy <luolonghao@gmail.com>
  6465. * @site http://www.kindsoft.net/
  6466. * @licence http://www.kindsoft.net/license.php
  6467. *******************************************************************************/
  6468. KindEditor.plugin('emoticons', function(K) {
  6469. var self = this, name = 'emoticons',
  6470. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6471. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6472. currentPageNum = 1;
  6473. self.clickToolbar(name, function() {
  6474. var rows = 5, cols = 9, total = 135, startNum = 0,
  6475. cells = rows * cols, pages = Math.ceil(total / cells),
  6476. colsHalf = Math.floor(cols / 2),
  6477. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6478. elements = [],
  6479. menu = self.createMenu({
  6480. name : name,
  6481. beforeRemove : function() {
  6482. removeEvent();
  6483. }
  6484. });
  6485. menu.div.append(wrapperDiv);
  6486. var previewDiv, previewImg;
  6487. if (allowPreview) {
  6488. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6489. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6490. wrapperDiv.append(previewDiv);
  6491. previewDiv.append(previewImg);
  6492. }
  6493. function bindCellEvent(cell, j, num) {
  6494. if (previewDiv) {
  6495. cell.mouseover(function() {
  6496. if (j > colsHalf) {
  6497. previewDiv.css('left', 0);
  6498. previewDiv.css('right', '');
  6499. } else {
  6500. previewDiv.css('left', '');
  6501. previewDiv.css('right', 0);
  6502. }
  6503. previewImg.attr('src', path + num + '.gif');
  6504. K(this).addClass('ke-on');
  6505. });
  6506. } else {
  6507. cell.mouseover(function() {
  6508. K(this).addClass('ke-on');
  6509. });
  6510. }
  6511. cell.mouseout(function() {
  6512. K(this).removeClass('ke-on');
  6513. });
  6514. cell.click(function(e) {
  6515. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6516. e.stop();
  6517. });
  6518. }
  6519. function createEmoticonsTable(pageNum, parentDiv) {
  6520. var table = document.createElement('table');
  6521. parentDiv.append(table);
  6522. if (previewDiv) {
  6523. K(table).mouseover(function() {
  6524. previewDiv.show('block');
  6525. });
  6526. K(table).mouseout(function() {
  6527. previewDiv.hide();
  6528. });
  6529. elements.push(K(table));
  6530. }
  6531. table.className = 'ke-table';
  6532. table.cellPadding = 0;
  6533. table.cellSpacing = 0;
  6534. table.border = 0;
  6535. var num = (pageNum - 1) * cells + startNum;
  6536. for (var i = 0; i < rows; i++) {
  6537. var row = table.insertRow(i);
  6538. for (var j = 0; j < cols; j++) {
  6539. var cell = K(row.insertCell(j));
  6540. cell.addClass('ke-cell');
  6541. bindCellEvent(cell, j, num);
  6542. var span = K('<span class="ke-img"></span>')
  6543. .css('background-position', '-' + (24 * num) + 'px 0px')
  6544. .css('background-image', 'url(' + path + 'static.gif)');
  6545. cell.append(span);
  6546. elements.push(cell);
  6547. num++;
  6548. }
  6549. }
  6550. return table;
  6551. }
  6552. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6553. function removeEvent() {
  6554. K.each(elements, function() {
  6555. this.unbind();
  6556. });
  6557. }
  6558. var pageDiv;
  6559. function bindPageEvent(el, pageNum) {
  6560. el.click(function(e) {
  6561. removeEvent();
  6562. table.parentNode.removeChild(table);
  6563. pageDiv.remove();
  6564. table = createEmoticonsTable(pageNum, wrapperDiv);
  6565. createPageTable(pageNum);
  6566. currentPageNum = pageNum;
  6567. e.stop();
  6568. });
  6569. }
  6570. function createPageTable(currentPageNum) {
  6571. pageDiv = K('<div class="ke-page"></div>');
  6572. wrapperDiv.append(pageDiv);
  6573. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6574. if (currentPageNum !== pageNum) {
  6575. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6576. bindPageEvent(a, pageNum);
  6577. pageDiv.append(a);
  6578. elements.push(a);
  6579. } else {
  6580. pageDiv.append(K('@[' + pageNum + ']'));
  6581. }
  6582. pageDiv.append(K('@&nbsp;'));
  6583. }
  6584. }
  6585. createPageTable(currentPageNum);
  6586. });
  6587. });
  6588. /*******************************************************************************
  6589. * KindEditor - WYSIWYG HTML Editor for Internet
  6590. * Copyright (C) 2006-2011 kindsoft.net
  6591. *
  6592. * @author Roddy <luolonghao@gmail.com>
  6593. * @site http://www.kindsoft.net/
  6594. * @licence http://www.kindsoft.net/license.php
  6595. *******************************************************************************/
  6596. KindEditor.plugin('filemanager', function(K) {
  6597. var self = this, name = 'filemanager',
  6598. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6599. imgPath = self.pluginsPath + name + '/images/',
  6600. lang = self.lang(name + '.');
  6601. function makeFileTitle(filename, filesize, datetime) {
  6602. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6603. }
  6604. function bindTitle(el, data) {
  6605. if (data.is_dir) {
  6606. el.attr('title', data.filename);
  6607. } else {
  6608. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6609. }
  6610. }
  6611. self.plugin.filemanagerDialog = function(options) {
  6612. var width = K.undef(options.width, 650),
  6613. height = K.undef(options.height, 510),
  6614. dirName = K.undef(options.dirName, ''),
  6615. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(), // "LIST" or "VIEW"
  6616. clickFn = options.clickFn;
  6617. var html = [
  6618. '<div style="padding:10px 20px;">',
  6619. // header start
  6620. '<div class="ke-plugin-filemanager-header">',
  6621. // left start
  6622. '<div class="ke-left">',
  6623. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6624. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6625. '</div>',
  6626. // right start
  6627. '<div class="ke-right">',
  6628. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6629. '<option value="VIEW">' + lang.viewImage + '</option>',
  6630. '<option value="LIST">' + lang.listImage + '</option>',
  6631. '</select> ',
  6632. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6633. '<option value="NAME">' + lang.fileName + '</option>',
  6634. '<option value="SIZE">' + lang.fileSize + '</option>',
  6635. '<option value="TYPE">' + lang.fileType + '</option>',
  6636. '</select>',
  6637. '</div>',
  6638. '<div class="ke-clearfix"></div>',
  6639. '</div>',
  6640. // body start
  6641. '<div class="ke-plugin-filemanager-body"></div>',
  6642. '</div>'
  6643. ].join('');
  6644. var dialog = self.createDialog({
  6645. name : name,
  6646. width : width,
  6647. height : height,
  6648. title : self.lang(name),
  6649. body : html
  6650. }),
  6651. div = dialog.div,
  6652. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6653. moveupImg = K('[name="moveupImg"]', div),
  6654. moveupLink = K('[name="moveupLink"]', div),
  6655. viewServerBtn = K('[name="viewServer"]', div),
  6656. viewTypeBox = K('[name="viewType"]', div),
  6657. orderTypeBox = K('[name="orderType"]', div);
  6658. function reloadPage(path, order, func) {
  6659. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6660. dialog.showLoading(self.lang('ajaxLoading'));
  6661. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6662. dialog.hideLoading();
  6663. func(data);
  6664. });
  6665. }
  6666. var elList = [];
  6667. function bindEvent(el, result, data, createFunc) {
  6668. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6669. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6670. if (data.is_dir) {
  6671. el.click(function(e) {
  6672. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6673. });
  6674. } else if (data.is_photo) {
  6675. el.click(function(e) {
  6676. clickFn.call(this, fileUrl, data.filename);
  6677. });
  6678. } else {
  6679. el.click(function(e) {
  6680. clickFn.call(this, fileUrl, data.filename);
  6681. });
  6682. }
  6683. elList.push(el);
  6684. }
  6685. function createCommon(result, createFunc) {
  6686. // remove events
  6687. K.each(elList, function() {
  6688. this.unbind();
  6689. });
  6690. moveupLink.unbind();
  6691. viewTypeBox.unbind();
  6692. orderTypeBox.unbind();
  6693. // add events
  6694. if (result.current_dir_path) {
  6695. moveupLink.click(function(e) {
  6696. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6697. });
  6698. }
  6699. function changeFunc() {
  6700. if (viewTypeBox.val() == 'VIEW') {
  6701. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6702. } else {
  6703. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6704. }
  6705. }
  6706. viewTypeBox.change(changeFunc);
  6707. orderTypeBox.change(changeFunc);
  6708. bodyDiv.html('');
  6709. }
  6710. function createList(result) {
  6711. createCommon(result, createList);
  6712. var table = document.createElement('table');
  6713. table.className = 'ke-table';
  6714. table.cellPadding = 0;
  6715. table.cellSpacing = 0;
  6716. table.border = 0;
  6717. bodyDiv.append(table);
  6718. var fileList = result.file_list;
  6719. for (var i = 0, len = fileList.length; i < len; i++) {
  6720. var data = fileList[i], row = K(table.insertRow(i));
  6721. row.mouseover(function(e) {
  6722. K(this).addClass('ke-on');
  6723. })
  6724. .mouseout(function(e) {
  6725. K(this).removeClass('ke-on');
  6726. });
  6727. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6728. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6729. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6730. if (!data.is_dir || data.has_file) {
  6731. row.css('cursor', 'pointer');
  6732. cell0.attr('title', data.filename);
  6733. bindEvent(cell0, result, data, createList);
  6734. } else {
  6735. cell0.attr('title', lang.emptyFolder);
  6736. }
  6737. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6738. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6739. }
  6740. }
  6741. function createView(result) {
  6742. createCommon(result, createView);
  6743. var fileList = result.file_list;
  6744. for (var i = 0, len = fileList.length; i < len; i++) {
  6745. var data = fileList[i],
  6746. div = K('<div class="ke-inline-block ke-item"></div>');
  6747. bodyDiv.append(div);
  6748. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6749. .mouseover(function(e) {
  6750. K(this).addClass('ke-on');
  6751. })
  6752. .mouseout(function(e) {
  6753. K(this).removeClass('ke-on');
  6754. });
  6755. div.append(photoDiv);
  6756. var fileUrl = result.current_url + data.filename,
  6757. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6758. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6759. if (!data.is_dir || data.has_file) {
  6760. photoDiv.css('cursor', 'pointer');
  6761. bindTitle(photoDiv, data);
  6762. bindEvent(photoDiv, result, data, createView);
  6763. } else {
  6764. photoDiv.attr('title', lang.emptyFolder);
  6765. }
  6766. photoDiv.append(img);
  6767. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6768. }
  6769. }
  6770. viewTypeBox.val(viewType);
  6771. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6772. return dialog;
  6773. }
  6774. });
  6775. /*******************************************************************************
  6776. * KindEditor - WYSIWYG HTML Editor for Internet
  6777. * Copyright (C) 2006-2011 kindsoft.net
  6778. *
  6779. * @author Roddy <luolonghao@gmail.com>
  6780. * @site http://www.kindsoft.net/
  6781. * @licence http://www.kindsoft.net/license.php
  6782. *******************************************************************************/
  6783. KindEditor.plugin('flash', function(K) {
  6784. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6785. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6786. allowFileManager = K.undef(self.allowFileManager, false),
  6787. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6788. extraParams = K.undef(self.extraFileUploadParams, {}),
  6789. filePostName = K.undef(self.filePostName, 'imgFile'),
  6790. uploadJson = K.undef(self.uploadJson, self.basePath + 'kindeditor/upload_json.php');
  6791. self.plugin.flash = {
  6792. edit : function() {
  6793. var html = [
  6794. '<div style="padding:20px;">',
  6795. //url
  6796. '<div class="ke-dialog-row">',
  6797. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6798. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6799. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6800. '<span class="ke-button-common ke-button-outer">',
  6801. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6802. '</span>',
  6803. '</div>',
  6804. //width
  6805. '<div class="ke-dialog-row">',
  6806. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6807. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6808. '</div>',
  6809. //height
  6810. '<div class="ke-dialog-row">',
  6811. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6812. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6813. '</div>',
  6814. '</div>'
  6815. ].join('');
  6816. var dialog = self.createDialog({
  6817. name : name,
  6818. width : 450,
  6819. title : self.lang(name),
  6820. body : html,
  6821. yesBtn : {
  6822. name : self.lang('yes'),
  6823. click : function(e) {
  6824. var url = K.trim(urlBox.val()),
  6825. width = widthBox.val(),
  6826. height = heightBox.val();
  6827. if (url == 'http://' || K.invalidUrl(url)) {
  6828. alert(self.lang('invalidUrl'));
  6829. urlBox[0].focus();
  6830. return;
  6831. }
  6832. if (!/^\d*$/.test(width)) {
  6833. alert(self.lang('invalidWidth'));
  6834. widthBox[0].focus();
  6835. return;
  6836. }
  6837. if (!/^\d*$/.test(height)) {
  6838. alert(self.lang('invalidHeight'));
  6839. heightBox[0].focus();
  6840. return;
  6841. }
  6842. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6843. src : url,
  6844. type : K.mediaType('.swf'),
  6845. width : width,
  6846. height : height,
  6847. quality : 'high'
  6848. });
  6849. self.insertHtml(html).hideDialog().focus();
  6850. }
  6851. }
  6852. }),
  6853. div = dialog.div,
  6854. urlBox = K('[name="url"]', div),
  6855. viewServerBtn = K('[name="viewServer"]', div),
  6856. widthBox = K('[name="width"]', div),
  6857. heightBox = K('[name="height"]', div);
  6858. urlBox.val('http://');
  6859. if (allowFlashUpload) {
  6860. var uploadbutton = K.uploadbutton({
  6861. button : K('.ke-upload-button', div)[0],
  6862. fieldName : filePostName,
  6863. extraParams : extraParams,
  6864. url : K.addParam(uploadJson, 'dir=flash'),
  6865. afterUpload : function(data) {
  6866. dialog.hideLoading();
  6867. if (data.error === 0) {
  6868. var url = data.url;
  6869. if (formatUploadUrl) {
  6870. url = K.formatUrl(url, 'absolute');
  6871. }
  6872. urlBox.val(url);
  6873. if (self.afterUpload) {
  6874. self.afterUpload.call(self, url, data, name);
  6875. }
  6876. alert(self.lang('uploadSuccess'));
  6877. } else {
  6878. alert(data.message);
  6879. }
  6880. },
  6881. afterError : function(html) {
  6882. dialog.hideLoading();
  6883. self.errorDialog(html);
  6884. }
  6885. });
  6886. uploadbutton.fileBox.change(function(e) {
  6887. dialog.showLoading(self.lang('uploadLoading'));
  6888. uploadbutton.submit();
  6889. });
  6890. } else {
  6891. K('.ke-upload-button', div).hide();
  6892. }
  6893. if (allowFileManager) {
  6894. viewServerBtn.click(function(e) {
  6895. self.loadPlugin('filemanager', function() {
  6896. self.plugin.filemanagerDialog({
  6897. viewType : 'LIST',
  6898. dirName : 'flash',
  6899. clickFn : function(url, title) {
  6900. if (self.dialogs.length > 1) {
  6901. K('[name="url"]', div).val(url);
  6902. if (self.afterSelectFile) {
  6903. self.afterSelectFile.call(self, url);
  6904. }
  6905. self.hideDialog();
  6906. }
  6907. }
  6908. });
  6909. });
  6910. });
  6911. } else {
  6912. viewServerBtn.hide();
  6913. }
  6914. var img = self.plugin.getSelectedFlash();
  6915. if (img) {
  6916. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  6917. urlBox.val(attrs.src);
  6918. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  6919. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  6920. }
  6921. urlBox[0].focus();
  6922. urlBox[0].select();
  6923. },
  6924. 'delete' : function() {
  6925. self.plugin.getSelectedFlash().remove();
  6926. // [IE] 删除图片后立即点击图片按钮出错
  6927. self.addBookmark();
  6928. }
  6929. };
  6930. self.clickToolbar(name, self.plugin.flash.edit);
  6931. });
  6932. /*******************************************************************************
  6933. * KindEditor - WYSIWYG HTML Editor for Internet
  6934. * Copyright (C) 2006-2011 kindsoft.net
  6935. *
  6936. * @author Roddy <luolonghao@gmail.com>
  6937. * @site http://www.kindsoft.net/
  6938. * @licence http://www.kindsoft.net/license.php
  6939. *******************************************************************************/
  6940. KindEditor.plugin('image', function(K) {
  6941. var self = this, name = 'image',
  6942. allowImageUpload = K.undef(self.allowImageUpload, true),
  6943. allowImageRemote = K.undef(self.allowImageRemote, true),
  6944. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6945. allowFileManager = K.undef(self.allowFileManager, false),
  6946. uploadJson = K.undef(self.uploadJson, self.basePath + 'kindeditor/upload_json.php'),
  6947. imageTabIndex = K.undef(self.imageTabIndex, 0),
  6948. imgPath = self.pluginsPath + 'image/images/',
  6949. extraParams = K.undef(self.extraFileUploadParams, {}),
  6950. filePostName = K.undef(self.filePostName, 'imgFile'),
  6951. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  6952. lang = self.lang(name + '.');
  6953. self.plugin.imageDialog = function(options) {
  6954. var imageUrl = options.imageUrl,
  6955. imageWidth = K.undef(options.imageWidth, ''),
  6956. imageHeight = K.undef(options.imageHeight, ''),
  6957. imageTitle = K.undef(options.imageTitle, ''),
  6958. imageAlign = K.undef(options.imageAlign, ''),
  6959. showRemote = K.undef(options.showRemote, true),
  6960. showLocal = K.undef(options.showLocal, true),
  6961. tabIndex = K.undef(options.tabIndex, 0),
  6962. clickFn = options.clickFn;
  6963. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  6964. var hiddenElements = [];
  6965. for(var k in extraParams){
  6966. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  6967. }
  6968. var html = [
  6969. '<div style="padding:20px;">',
  6970. //tabs
  6971. '<div class="tabs"></div>',
  6972. //remote image - start
  6973. '<div class="tab1" style="display:none;">',
  6974. //url
  6975. '<div class="ke-dialog-row">',
  6976. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  6977. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  6978. '<span class="ke-button-common ke-button-outer">',
  6979. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6980. '</span>',
  6981. '</div>',
  6982. //size
  6983. '<div class="ke-dialog-row">',
  6984. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  6985. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  6986. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  6987. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  6988. '</div>',
  6989. //align
  6990. '<div class="ke-dialog-row">',
  6991. '<label style="width:60px;">' + lang.align + '</label>',
  6992. '<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="" />',
  6993. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  6994. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  6995. '</div>',
  6996. //title
  6997. '<div class="ke-dialog-row">',
  6998. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  6999. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7000. '</div>',
  7001. '</div>',
  7002. //remote image - end
  7003. //local upload - start
  7004. '<div class="tab2" style="display:none;">',
  7005. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7006. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7007. //file
  7008. '<div class="ke-dialog-row">',
  7009. hiddenElements.join(''),
  7010. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7011. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7012. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7013. '</div>',
  7014. '</form>',
  7015. '</div>',
  7016. //local upload - end
  7017. '</div>'
  7018. ].join('');
  7019. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7020. dialogHeight = showLocal && showRemote ? 300 : 250;
  7021. var dialog = self.createDialog({
  7022. name : name,
  7023. width : dialogWidth,
  7024. height : dialogHeight,
  7025. title : self.lang(name),
  7026. body : html,
  7027. yesBtn : {
  7028. name : self.lang('yes'),
  7029. click : function(e) {
  7030. // Bugfix: http://code.google.com/p/kindeditor/issues/detail?id=319
  7031. if (dialog.isLoading) {
  7032. return;
  7033. }
  7034. // insert local image
  7035. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7036. if (uploadbutton.fileBox.val() == '') {
  7037. alert(self.lang('pleaseSelectFile'));
  7038. return;
  7039. }
  7040. dialog.showLoading(self.lang('uploadLoading'));
  7041. uploadbutton.submit();
  7042. localUrlBox.val('');
  7043. return;
  7044. }
  7045. // insert remote image
  7046. var url = K.trim(urlBox.val()),
  7047. width = widthBox.val(),
  7048. height = heightBox.val(),
  7049. title = titleBox.val(),
  7050. align = '';
  7051. alignBox.each(function() {
  7052. if (this.checked) {
  7053. align = this.value;
  7054. return false;
  7055. }
  7056. });
  7057. if (url == 'http://' || K.invalidUrl(url)) {
  7058. alert(self.lang('invalidUrl'));
  7059. urlBox[0].focus();
  7060. return;
  7061. }
  7062. if (!/^\d*$/.test(width)) {
  7063. alert(self.lang('invalidWidth'));
  7064. widthBox[0].focus();
  7065. return;
  7066. }
  7067. if (!/^\d*$/.test(height)) {
  7068. alert(self.lang('invalidHeight'));
  7069. heightBox[0].focus();
  7070. return;
  7071. }
  7072. clickFn.call(self, url, title, width, height, 0, align);
  7073. }
  7074. },
  7075. beforeRemove : function() {
  7076. viewServerBtn.unbind();
  7077. widthBox.unbind();
  7078. heightBox.unbind();
  7079. refreshBtn.unbind();
  7080. }
  7081. }),
  7082. div = dialog.div;
  7083. var urlBox = K('[name="url"]', div),
  7084. localUrlBox = K('[name="localUrl"]', div),
  7085. viewServerBtn = K('[name="viewServer"]', div),
  7086. widthBox = K('.tab1 [name="width"]', div),
  7087. heightBox = K('.tab1 [name="height"]', div),
  7088. refreshBtn = K('.ke-refresh-btn', div),
  7089. titleBox = K('.tab1 [name="title"]', div),
  7090. alignBox = K('.tab1 [name="align"]', div);
  7091. var tabs;
  7092. if (showRemote && showLocal) {
  7093. tabs = K.tabs({
  7094. src : K('.tabs', div),
  7095. afterSelect : function(i) {}
  7096. });
  7097. tabs.add({
  7098. title : lang.remoteImage,
  7099. panel : K('.tab1', div)
  7100. });
  7101. tabs.add({
  7102. title : lang.localImage,
  7103. panel : K('.tab2', div)
  7104. });
  7105. tabs.select(tabIndex);
  7106. } else if (showRemote) {
  7107. K('.tab1', div).show();
  7108. } else if (showLocal) {
  7109. K('.tab2', div).show();
  7110. }
  7111. var uploadbutton = K.uploadbutton({
  7112. button : K('.ke-upload-button', div)[0],
  7113. fieldName : filePostName,
  7114. form : K('.ke-form', div),
  7115. target : target,
  7116. width: 60,
  7117. afterUpload : function(data) {
  7118. dialog.hideLoading();
  7119. if (data.error === 0) {
  7120. var url = data.url;
  7121. if (formatUploadUrl) {
  7122. url = K.formatUrl(url, 'absolute');
  7123. }
  7124. if (self.afterUpload) {
  7125. self.afterUpload.call(self, url, data, name);
  7126. }
  7127. if (!fillDescAfterUploadImage) {
  7128. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7129. } else {
  7130. K(".ke-dialog-row #remoteUrl", div).val(url);
  7131. K(".ke-tabs-li", div)[0].click();
  7132. K(".ke-refresh-btn", div).click();
  7133. }
  7134. } else {
  7135. alert(data.message);
  7136. }
  7137. },
  7138. afterError : function(html) {
  7139. dialog.hideLoading();
  7140. self.errorDialog(html);
  7141. }
  7142. });
  7143. uploadbutton.fileBox.change(function(e) {
  7144. localUrlBox.val(uploadbutton.fileBox.val());
  7145. });
  7146. if (allowFileManager) {
  7147. viewServerBtn.click(function(e) {
  7148. self.loadPlugin('filemanager', function() {
  7149. self.plugin.filemanagerDialog({
  7150. viewType : 'VIEW',
  7151. dirName : 'image',
  7152. clickFn : function(url, title) {
  7153. if (self.dialogs.length > 1) {
  7154. K('[name="url"]', div).val(url);
  7155. if (self.afterSelectFile) {
  7156. self.afterSelectFile.call(self, url);
  7157. }
  7158. self.hideDialog();
  7159. }
  7160. }
  7161. });
  7162. });
  7163. });
  7164. } else {
  7165. viewServerBtn.hide();
  7166. }
  7167. var originalWidth = 0, originalHeight = 0;
  7168. function setSize(width, height) {
  7169. widthBox.val(width);
  7170. heightBox.val(height);
  7171. originalWidth = width;
  7172. originalHeight = height;
  7173. }
  7174. refreshBtn.click(function(e) {
  7175. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7176. position : 'absolute',
  7177. visibility : 'hidden',
  7178. top : 0,
  7179. left : '-1000px'
  7180. });
  7181. tempImg.bind('load', function() {
  7182. setSize(tempImg.width(), tempImg.height());
  7183. tempImg.remove();
  7184. });
  7185. K(document.body).append(tempImg);
  7186. });
  7187. widthBox.change(function(e) {
  7188. if (originalWidth > 0) {
  7189. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7190. }
  7191. });
  7192. heightBox.change(function(e) {
  7193. if (originalHeight > 0) {
  7194. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7195. }
  7196. });
  7197. urlBox.val(options.imageUrl);
  7198. setSize(options.imageWidth, options.imageHeight);
  7199. titleBox.val(options.imageTitle);
  7200. alignBox.each(function() {
  7201. if (this.value === options.imageAlign) {
  7202. this.checked = true;
  7203. return false;
  7204. }
  7205. });
  7206. if (showRemote && tabIndex === 0) {
  7207. urlBox[0].focus();
  7208. urlBox[0].select();
  7209. }
  7210. return dialog;
  7211. };
  7212. self.plugin.image = {
  7213. edit : function() {
  7214. var img = self.plugin.getSelectedImage();
  7215. self.plugin.imageDialog({
  7216. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7217. imageWidth : img ? img.width() : '',
  7218. imageHeight : img ? img.height() : '',
  7219. imageTitle : img ? img.attr('title') : '',
  7220. imageAlign : img ? img.attr('align') : '',
  7221. showRemote : allowImageRemote,
  7222. showLocal : allowImageUpload,
  7223. tabIndex: img ? 0 : imageTabIndex,
  7224. clickFn : function(url, title, width, height, border, align) {
  7225. if (img) {
  7226. img.attr('src', url);
  7227. img.attr('data-ke-src', url);
  7228. img.attr('width', width);
  7229. img.attr('height', height);
  7230. img.attr('title', title);
  7231. img.attr('align', align);
  7232. img.attr('alt', title);
  7233. } else {
  7234. self.exec('insertimage', url, title, width, height, border, align);
  7235. }
  7236. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  7237. setTimeout(function() {
  7238. self.hideDialog().focus();
  7239. }, 0);
  7240. }
  7241. });
  7242. },
  7243. 'delete' : function() {
  7244. var target = self.plugin.getSelectedImage();
  7245. if (target.parent().name == 'a') {
  7246. target = target.parent();
  7247. }
  7248. target.remove();
  7249. // [IE] 删除图片后立即点击图片按钮出错
  7250. self.addBookmark();
  7251. }
  7252. };
  7253. self.clickToolbar(name, self.plugin.image.edit);
  7254. });
  7255. /*******************************************************************************
  7256. * KindEditor - WYSIWYG HTML Editor for Internet
  7257. * Copyright (C) 2006-2011 kindsoft.net
  7258. *
  7259. * @author Roddy <luolonghao@gmail.com>
  7260. * @site http://www.kindsoft.net/
  7261. * @licence http://www.kindsoft.net/license.php
  7262. *******************************************************************************/
  7263. KindEditor.plugin('insertfile', function(K) {
  7264. var self = this, name = 'insertfile',
  7265. allowFileUpload = K.undef(self.allowFileUpload, true),
  7266. allowFileManager = K.undef(self.allowFileManager, false),
  7267. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7268. uploadJson = K.undef(self.uploadJson, self.basePath + 'kindeditor/upload_json.php'),
  7269. extraParams = K.undef(self.extraFileUploadParams, {}),
  7270. filePostName = K.undef(self.filePostName, 'imgFile'),
  7271. lang = self.lang(name + '.');
  7272. self.plugin.fileDialog = function(options) {
  7273. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7274. fileTitle = K.undef(options.fileTitle, ''),
  7275. clickFn = options.clickFn;
  7276. var html = [
  7277. '<div style="padding:20px;">',
  7278. '<div class="ke-dialog-row">',
  7279. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7280. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7281. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7282. '<span class="ke-button-common ke-button-outer">',
  7283. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7284. '</span>',
  7285. '</div>',
  7286. //title
  7287. '<div class="ke-dialog-row">',
  7288. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7289. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7290. '</div>',
  7291. //form end
  7292. '</form>',
  7293. '</div>'
  7294. ].join('');
  7295. var dialog = self.createDialog({
  7296. name : name,
  7297. width : 450,
  7298. title : self.lang(name),
  7299. body : html,
  7300. yesBtn : {
  7301. name : self.lang('yes'),
  7302. click : function(e) {
  7303. var url = K.trim(urlBox.val()),
  7304. title = titleBox.val();
  7305. if (url == 'http://' || K.invalidUrl(url)) {
  7306. alert(self.lang('invalidUrl'));
  7307. urlBox[0].focus();
  7308. return;
  7309. }
  7310. if (K.trim(title) === '') {
  7311. title = url;
  7312. }
  7313. clickFn.call(self, url, title);
  7314. }
  7315. }
  7316. }),
  7317. div = dialog.div;
  7318. var urlBox = K('[name="url"]', div),
  7319. viewServerBtn = K('[name="viewServer"]', div),
  7320. titleBox = K('[name="title"]', div);
  7321. if (allowFileUpload) {
  7322. var uploadbutton = K.uploadbutton({
  7323. button : K('.ke-upload-button', div)[0],
  7324. fieldName : filePostName,
  7325. url : K.addParam(uploadJson, 'dir=file'),
  7326. extraParams : extraParams,
  7327. afterUpload : function(data) {
  7328. dialog.hideLoading();
  7329. if (data.error === 0) {
  7330. var url = data.url;
  7331. if (formatUploadUrl) {
  7332. url = K.formatUrl(url, 'absolute');
  7333. }
  7334. urlBox.val(url);
  7335. if (self.afterUpload) {
  7336. self.afterUpload.call(self, url, data, name);
  7337. }
  7338. alert(self.lang('uploadSuccess'));
  7339. } else {
  7340. alert(data.message);
  7341. }
  7342. },
  7343. afterError : function(html) {
  7344. dialog.hideLoading();
  7345. self.errorDialog(html);
  7346. }
  7347. });
  7348. uploadbutton.fileBox.change(function(e) {
  7349. dialog.showLoading(self.lang('uploadLoading'));
  7350. uploadbutton.submit();
  7351. });
  7352. } else {
  7353. K('.ke-upload-button', div).hide();
  7354. }
  7355. if (allowFileManager) {
  7356. viewServerBtn.click(function(e) {
  7357. self.loadPlugin('filemanager', function() {
  7358. self.plugin.filemanagerDialog({
  7359. viewType : 'LIST',
  7360. dirName : 'file',
  7361. clickFn : function(url, title) {
  7362. if (self.dialogs.length > 1) {
  7363. K('[name="url"]', div).val(url);
  7364. if (self.afterSelectFile) {
  7365. self.afterSelectFile.call(self, url);
  7366. }
  7367. self.hideDialog();
  7368. }
  7369. }
  7370. });
  7371. });
  7372. });
  7373. } else {
  7374. viewServerBtn.hide();
  7375. }
  7376. urlBox.val(fileUrl);
  7377. titleBox.val(fileTitle);
  7378. urlBox[0].focus();
  7379. urlBox[0].select();
  7380. };
  7381. self.clickToolbar(name, function() {
  7382. self.plugin.fileDialog({
  7383. clickFn : function(url, title) {
  7384. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7385. self.insertHtml(html).hideDialog().focus();
  7386. }
  7387. });
  7388. });
  7389. });
  7390. /*******************************************************************************
  7391. * KindEditor - WYSIWYG HTML Editor for Internet
  7392. * Copyright (C) 2006-2011 kindsoft.net
  7393. *
  7394. * @author Roddy <luolonghao@gmail.com>
  7395. * @site http://www.kindsoft.net/
  7396. * @licence http://www.kindsoft.net/license.php
  7397. *******************************************************************************/
  7398. KindEditor.plugin('lineheight', function(K) {
  7399. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7400. self.clickToolbar(name, function() {
  7401. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7402. if (commonNode) {
  7403. curVal = commonNode.css('line-height');
  7404. }
  7405. var menu = self.createMenu({
  7406. name : name,
  7407. width : 150
  7408. });
  7409. K.each(lang.lineHeight, function(i, row) {
  7410. K.each(row, function(key, val) {
  7411. menu.addItem({
  7412. title : val,
  7413. checked : curVal === key,
  7414. click : function() {
  7415. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7416. span : '.line-height=' + key
  7417. });
  7418. self.updateState();
  7419. self.addBookmark();
  7420. self.hideMenu();
  7421. }
  7422. });
  7423. });
  7424. });
  7425. });
  7426. });
  7427. /*******************************************************************************
  7428. * KindEditor - WYSIWYG HTML Editor for Internet
  7429. * Copyright (C) 2006-2011 kindsoft.net
  7430. *
  7431. * @author Roddy <luolonghao@gmail.com>
  7432. * @site http://www.kindsoft.net/
  7433. * @licence http://www.kindsoft.net/license.php
  7434. *******************************************************************************/
  7435. KindEditor.plugin('link', function(K) {
  7436. var self = this, name = 'link';
  7437. self.plugin.link = {
  7438. edit : function() {
  7439. var lang = self.lang(name + '.'),
  7440. html = '<div style="padding:20px;">' +
  7441. //url
  7442. '<div class="ke-dialog-row">' +
  7443. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7444. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7445. //type
  7446. '<div class="ke-dialog-row"">' +
  7447. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7448. '<select id="keType" name="type"></select>' +
  7449. '</div>' +
  7450. '</div>',
  7451. dialog = self.createDialog({
  7452. name : name,
  7453. width : 450,
  7454. title : self.lang(name),
  7455. body : html,
  7456. yesBtn : {
  7457. name : self.lang('yes'),
  7458. click : function(e) {
  7459. var url = K.trim(urlBox.val());
  7460. if (url == 'http://' || K.invalidUrl(url)) {
  7461. alert(self.lang('invalidUrl'));
  7462. urlBox[0].focus();
  7463. return;
  7464. }
  7465. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7466. }
  7467. }
  7468. }),
  7469. div = dialog.div,
  7470. urlBox = K('input[name="url"]', div),
  7471. typeBox = K('select[name="type"]', div);
  7472. urlBox.val('http://');
  7473. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7474. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7475. self.cmd.selection();
  7476. var a = self.plugin.getSelectedLink();
  7477. if (a) {
  7478. self.cmd.range.selectNode(a[0]);
  7479. self.cmd.select();
  7480. urlBox.val(a.attr('data-ke-src'));
  7481. typeBox.val(a.attr('target'));
  7482. }
  7483. urlBox[0].focus();
  7484. urlBox[0].select();
  7485. },
  7486. 'delete' : function() {
  7487. self.exec('unlink', null);
  7488. }
  7489. };
  7490. self.clickToolbar(name, self.plugin.link.edit);
  7491. });
  7492. /*******************************************************************************
  7493. * KindEditor - WYSIWYG HTML Editor for Internet
  7494. * Copyright (C) 2006-2011 kindsoft.net
  7495. *
  7496. * @author Roddy <luolonghao@gmail.com>
  7497. * @site http://www.kindsoft.net/
  7498. * @licence http://www.kindsoft.net/license.php
  7499. *******************************************************************************/
  7500. // Google Maps: http://code.google.com/apis/maps/index.html
  7501. KindEditor.plugin('map', function(K) {
  7502. var self = this, name = 'map', lang = self.lang(name + '.');
  7503. self.clickToolbar(name, function() {
  7504. var html = ['<div style="padding:10px 20px;">',
  7505. '<div class="ke-dialog-row">',
  7506. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  7507. '<span class="ke-button-common ke-button-outer">',
  7508. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  7509. '</span>',
  7510. '</div>',
  7511. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  7512. '</div>'].join('');
  7513. var dialog = self.createDialog({
  7514. name : name,
  7515. width : 600,
  7516. title : self.lang(name),
  7517. body : html,
  7518. yesBtn : {
  7519. name : self.lang('yes'),
  7520. click : function(e) {
  7521. var geocoder = win.geocoder,
  7522. map = win.map,
  7523. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  7524. zoom = map.getZoom(),
  7525. maptype = map.getMapTypeId(),
  7526. url = 'http://maps.googleapis.com/maps/api/staticmap';
  7527. url += '?center=' + encodeURIComponent(center);
  7528. url += '&zoom=' + encodeURIComponent(zoom);
  7529. url += '&size=558x360';
  7530. url += '&maptype=' + encodeURIComponent(maptype);
  7531. url += '&markers=' + encodeURIComponent(center);
  7532. url += '&language=' + self.langType;
  7533. url += '&sensor=false';
  7534. self.exec('insertimage', url).hideDialog().focus();
  7535. }
  7536. },
  7537. beforeRemove : function() {
  7538. searchBtn.remove();
  7539. if (doc) {
  7540. doc.write('');
  7541. }
  7542. iframe.remove();
  7543. }
  7544. });
  7545. var div = dialog.div,
  7546. addressBox = K('[name="address"]', div),
  7547. searchBtn = K('[name="searchBtn"]', div),
  7548. win, doc;
  7549. var iframeHtml = ['<!doctype html><html><head>',
  7550. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  7551. '<style>',
  7552. ' html { height: 100% }',
  7553. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  7554. ' #map_canvas { height: 100% }',
  7555. '</style>',
  7556. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  7557. '<script>',
  7558. 'var map, geocoder;',
  7559. 'function initialize() {',
  7560. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  7561. ' var options = {',
  7562. ' zoom: 11,',
  7563. ' center: latlng,',
  7564. ' disableDefaultUI: true,',
  7565. ' panControl: true,',
  7566. ' zoomControl: true,',
  7567. ' mapTypeControl: true,',
  7568. ' scaleControl: true,',
  7569. ' streetViewControl: false,',
  7570. ' overviewMapControl: true,',
  7571. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  7572. ' };',
  7573. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  7574. ' geocoder = new google.maps.Geocoder();',
  7575. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  7576. ' if (status == google.maps.GeocoderStatus.OK) {',
  7577. ' if (results[3]) {',
  7578. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  7579. ' }',
  7580. ' }',
  7581. ' });',
  7582. '}',
  7583. 'function search(address) {',
  7584. ' if (!map) return;',
  7585. ' geocoder.geocode({address : address}, function(results, status) {',
  7586. ' if (status == google.maps.GeocoderStatus.OK) {',
  7587. ' map.setZoom(11);',
  7588. ' map.setCenter(results[0].geometry.location);',
  7589. ' var marker = new google.maps.Marker({',
  7590. ' map: map,',
  7591. ' position: results[0].geometry.location',
  7592. ' });',
  7593. ' } else {',
  7594. ' alert("Invalid address: " + address);',
  7595. ' }',
  7596. ' });',
  7597. '}',
  7598. '</script>',
  7599. '</head>',
  7600. '<body onload="initialize();">',
  7601. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  7602. '</body></html>'].join('\n');
  7603. // TODO:用doc.write(iframeHtml)方式加载时,在IE6上第一次加载报错,暂时使用src方式
  7604. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  7605. function ready() {
  7606. win = iframe[0].contentWindow;
  7607. doc = K.iframeDoc(iframe);
  7608. //doc.open();
  7609. //doc.write(iframeHtml);
  7610. //doc.close();
  7611. }
  7612. iframe.bind('load', function() {
  7613. iframe.unbind('load');
  7614. if (K.IE) {
  7615. ready();
  7616. } else {
  7617. setTimeout(ready, 0);
  7618. }
  7619. });
  7620. K('.ke-map', div).replaceWith(iframe);
  7621. // search map
  7622. searchBtn.click(function() {
  7623. win.search(addressBox.val());
  7624. });
  7625. });
  7626. });
  7627. /*******************************************************************************
  7628. * KindEditor - WYSIWYG HTML Editor for Internet
  7629. * Copyright (C) 2006-2011 kindsoft.net
  7630. *
  7631. * @author Roddy <luolonghao@gmail.com>
  7632. * @site http://www.kindsoft.net/
  7633. * @licence http://www.kindsoft.net/license.php
  7634. *******************************************************************************/
  7635. KindEditor.plugin('media', function(K) {
  7636. var self = this, name = 'media', lang = self.lang(name + '.'),
  7637. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7638. allowFileManager = K.undef(self.allowFileManager, false),
  7639. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7640. extraParams = K.undef(self.extraFileUploadParams, {}),
  7641. filePostName = K.undef(self.filePostName, 'imgFile'),
  7642. uploadJson = K.undef(self.uploadJson, self.basePath + 'kindeditor/upload_json.php');
  7643. self.plugin.media = {
  7644. edit : function(options) {
  7645. var clickFn = options.clickFn;
  7646. var html = [
  7647. '<div style="padding:20px;">',
  7648. //url
  7649. '<div class="ke-dialog-row">',
  7650. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7651. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7652. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7653. '<span class="ke-button-common ke-button-outer">',
  7654. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7655. '</span>',
  7656. '</div>',
  7657. //width
  7658. '<div class="ke-dialog-row">',
  7659. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7660. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7661. '</div>',
  7662. //height
  7663. '<div class="ke-dialog-row">',
  7664. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7665. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7666. '</div>',
  7667. //autostart
  7668. '<div class="ke-dialog-row">',
  7669. '<label for="keAutostart">' + lang.autostart + '</label>',
  7670. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7671. '</div>',
  7672. '</div>'
  7673. ].join('');
  7674. var dialog = self.createDialog({
  7675. name : name,
  7676. width : 450,
  7677. height : 230,
  7678. title : self.lang(name),
  7679. body : html,
  7680. yesBtn : {
  7681. name : self.lang('yes'),
  7682. click : function(e) {
  7683. var url = K.trim(urlBox.val()),
  7684. width = widthBox.val(),
  7685. height = heightBox.val();
  7686. if (url == 'http://' || K.invalidUrl(url)) {
  7687. alert(self.lang('invalidUrl'));
  7688. urlBox[0].focus();
  7689. return;
  7690. }
  7691. if (!/^\d*$/.test(width)) {
  7692. alert(self.lang('invalidWidth'));
  7693. widthBox[0].focus();
  7694. return;
  7695. }
  7696. if (!/^\d*$/.test(height)) {
  7697. alert(self.lang('invalidHeight'));
  7698. heightBox[0].focus();
  7699. return;
  7700. }
  7701. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7702. src : url,
  7703. type : K.mediaType(url),
  7704. width : width,
  7705. height : height,
  7706. autostart : autostartBox[0].checked ? 'true' : 'false',
  7707. loop : 'true'
  7708. });
  7709. self.insertHtml(html).hideDialog().focus();
  7710. clickFn.call(self, url);
  7711. }
  7712. }
  7713. }),
  7714. div = dialog.div,
  7715. urlBox = K('[name="url"]', div),
  7716. viewServerBtn = K('[name="viewServer"]', div),
  7717. widthBox = K('[name="width"]', div),
  7718. heightBox = K('[name="height"]', div),
  7719. autostartBox = K('[name="autostart"]', div);
  7720. urlBox.val('http://');
  7721. if (allowMediaUpload) {
  7722. var uploadbutton = K.uploadbutton({
  7723. button : K('.ke-upload-button', div)[0],
  7724. fieldName : filePostName,
  7725. extraParams : extraParams,
  7726. url : K.addParam(uploadJson, 'dir=media'),
  7727. afterUpload : function(data) {
  7728. dialog.hideLoading();
  7729. if (data.error === 0) {
  7730. var url = data.url;
  7731. if (formatUploadUrl) {
  7732. url = K.formatUrl(url, 'absolute');
  7733. }
  7734. urlBox.val(url);
  7735. if (self.afterUpload) {
  7736. self.afterUpload.call(self, url, data, name);
  7737. }
  7738. alert(self.lang('uploadSuccess'));
  7739. } else {
  7740. alert(data.message);
  7741. }
  7742. },
  7743. afterError : function(html) {
  7744. dialog.hideLoading();
  7745. self.errorDialog(html);
  7746. }
  7747. });
  7748. uploadbutton.fileBox.change(function(e) {
  7749. dialog.showLoading(self.lang('uploadLoading'));
  7750. uploadbutton.submit();
  7751. });
  7752. } else {
  7753. K('.ke-upload-button', div).hide();
  7754. }
  7755. if (allowFileManager) {
  7756. viewServerBtn.click(function(e) {
  7757. self.loadPlugin('filemanager', function() {
  7758. self.plugin.filemanagerDialog({
  7759. viewType : 'LIST',
  7760. dirName : 'media',
  7761. clickFn : function(url, title) {
  7762. if (self.dialogs.length > 1) {
  7763. K('[name="url"]', div).val(url);
  7764. if (self.afterSelectFile) {
  7765. self.afterSelectFile.call(self, url);
  7766. }
  7767. self.hideDialog();
  7768. }
  7769. }
  7770. });
  7771. });
  7772. });
  7773. } else {
  7774. viewServerBtn.hide();
  7775. }
  7776. var img = self.plugin.getSelectedMedia();
  7777. if (img) {
  7778. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7779. urlBox.val(attrs.src);
  7780. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7781. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7782. autostartBox[0].checked = (attrs.autostart === 'true');
  7783. }
  7784. urlBox[0].focus();
  7785. urlBox[0].select();
  7786. },
  7787. 'delete' : function() {
  7788. self.plugin.getSelectedMedia().remove();
  7789. // [IE] 删除图片后立即点击图片按钮出错
  7790. self.addBookmark();
  7791. }
  7792. };
  7793. self.clickToolbar(name, self.plugin.media.edit);
  7794. });
  7795. /*******************************************************************************
  7796. * KindEditor - WYSIWYG HTML Editor for Internet
  7797. * Copyright (C) 2006-2011 kindsoft.net
  7798. *
  7799. * @author Roddy <luolonghao@gmail.com>
  7800. * @site http://www.kindsoft.net/
  7801. * @licence http://www.kindsoft.net/license.php
  7802. *******************************************************************************/
  7803. (function(K) {
  7804. function KSWFUpload(options) {
  7805. this.init(options);
  7806. }
  7807. K.extend(KSWFUpload, {
  7808. init : function(options) {
  7809. var self = this;
  7810. options.afterError = options.afterError || function(str) {
  7811. alert(str);
  7812. };
  7813. self.options = options;
  7814. self.progressbars = {};
  7815. // template
  7816. self.div = K(options.container).html([
  7817. '<div class="ke-swfupload">',
  7818. '<div class="ke-swfupload-top">',
  7819. '<div class="ke-inline-block ke-swfupload-button">',
  7820. '<input type="button" value="Browse" />',
  7821. '</div>',
  7822. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7823. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7824. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7825. '</span>',
  7826. '</div>',
  7827. '<div class="ke-swfupload-body"></div>',
  7828. '</div>'
  7829. ].join(''));
  7830. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7831. function showError(itemDiv, msg) {
  7832. K('.ke-status > div', itemDiv).hide();
  7833. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7834. }
  7835. var settings = {
  7836. debug : false,
  7837. upload_url : options.uploadUrl,
  7838. flash_url : options.flashUrl,
  7839. file_post_name : options.filePostName,
  7840. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7841. button_image_url: options.buttonImageUrl,
  7842. button_width: options.buttonWidth,
  7843. button_height: options.buttonHeight,
  7844. button_cursor : SWFUpload.CURSOR.HAND,
  7845. file_types : options.fileTypes,
  7846. file_types_description : options.fileTypesDesc,
  7847. file_upload_limit : options.fileUploadLimit,
  7848. file_size_limit : options.fileSizeLimit,
  7849. post_params : options.postParams,
  7850. file_queued_handler : function(file) {
  7851. file.url = self.options.fileIconUrl;
  7852. self.appendFile(file);
  7853. },
  7854. file_queue_error_handler : function(file, errorCode, message) {
  7855. var errorName = '';
  7856. switch (errorCode) {
  7857. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7858. errorName = options.queueLimitExceeded;
  7859. break;
  7860. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7861. errorName = options.fileExceedsSizeLimit;
  7862. break;
  7863. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7864. errorName = options.zeroByteFile;
  7865. break;
  7866. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7867. errorName = options.invalidFiletype;
  7868. break;
  7869. default:
  7870. errorName = options.unknownError;
  7871. break;
  7872. }
  7873. K.DEBUG && alert(errorName);
  7874. },
  7875. upload_start_handler : function(file) {
  7876. var self = this;
  7877. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7878. K('.ke-status > div', itemDiv).hide();
  7879. K('.ke-progressbar', itemDiv).show();
  7880. },
  7881. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7882. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7883. var progressbar = self.progressbars[file.id];
  7884. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7885. progressbar.percent.html(percent + '%');
  7886. },
  7887. upload_error_handler : function(file, errorCode, message) {
  7888. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7889. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7890. showError(itemDiv, self.options.errorMessage);
  7891. }
  7892. },
  7893. upload_success_handler : function(file, serverData) {
  7894. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7895. var data = {};
  7896. try {
  7897. data = K.json(serverData);
  7898. } catch (e) {
  7899. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7900. }
  7901. if (data.error !== 0) {
  7902. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7903. return;
  7904. }
  7905. file.url = data.url;
  7906. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7907. K('.ke-status > div', itemDiv).hide();
  7908. }
  7909. };
  7910. self.swfu = new SWFUpload(settings);
  7911. K('.ke-swfupload-startupload input', self.div).click(function() {
  7912. self.swfu.startUpload();
  7913. });
  7914. },
  7915. getUrlList : function() {
  7916. var list = [];
  7917. K('.ke-img', self.bodyDiv).each(function() {
  7918. var img = K(this);
  7919. var status = img.attr('data-status');
  7920. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7921. list.push(img.data('data'));
  7922. }
  7923. });
  7924. return list;
  7925. },
  7926. removeFile : function(fileId) {
  7927. var self = this;
  7928. self.swfu.cancelUpload(fileId);
  7929. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7930. K('.ke-photo', itemDiv).unbind();
  7931. K('.ke-delete', itemDiv).unbind();
  7932. itemDiv.remove();
  7933. },
  7934. removeFiles : function() {
  7935. var self = this;
  7936. K('.ke-item', self.bodyDiv).each(function() {
  7937. self.removeFile(K(this).attr('data-id'));
  7938. });
  7939. },
  7940. appendFile : function(file) {
  7941. var self = this;
  7942. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7943. self.bodyDiv.append(itemDiv);
  7944. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7945. .mouseover(function(e) {
  7946. K(this).addClass('ke-on');
  7947. })
  7948. .mouseout(function(e) {
  7949. K(this).removeClass('ke-on');
  7950. });
  7951. itemDiv.append(photoDiv);
  7952. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7953. photoDiv.append(img);
  7954. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  7955. self.removeFile(file.id);
  7956. });
  7957. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7958. // progressbar
  7959. K(['<div class="ke-progressbar">',
  7960. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7961. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7962. // message
  7963. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7964. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7965. self.progressbars[file.id] = {
  7966. bar : K('.ke-progressbar-bar-inner', photoDiv),
  7967. percent : K('.ke-progressbar-percent', photoDiv)
  7968. };
  7969. },
  7970. remove : function() {
  7971. this.removeFiles();
  7972. this.swfu.destroy();
  7973. this.div.html('');
  7974. }
  7975. });
  7976. K.swfupload = function(element, options) {
  7977. return new KSWFUpload(element, options);
  7978. };
  7979. })(KindEditor);
  7980. KindEditor.plugin('multiimage', function(K) {
  7981. var self = this, name = 'multiimage',
  7982. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7983. uploadJson = K.undef(self.uploadJson, self.basePath + 'kindeditor/upload_json.php'),
  7984. imgPath = self.pluginsPath + 'multiimage/images/',
  7985. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  7986. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  7987. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  7988. filePostName = K.undef(self.filePostName, 'imgFile'),
  7989. lang = self.lang(name + '.');
  7990. self.plugin.multiImageDialog = function(options) {
  7991. var clickFn = options.clickFn,
  7992. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  7993. var html = [
  7994. '<div style="padding:20px;">',
  7995. '<div class="swfupload">',
  7996. '</div>',
  7997. '</div>'
  7998. ].join('');
  7999. var dialog = self.createDialog({
  8000. name : name,
  8001. width : 650,
  8002. height : 510,
  8003. title : self.lang(name),
  8004. body : html,
  8005. previewBtn : {
  8006. name : lang.insertAll,
  8007. click : function(e) {
  8008. clickFn.call(self, swfupload.getUrlList());
  8009. }
  8010. },
  8011. yesBtn : {
  8012. name : lang.clearAll,
  8013. click : function(e) {
  8014. swfupload.removeFiles();
  8015. }
  8016. },
  8017. beforeRemove : function() {
  8018. // IE9 bugfix: https://github.com/kindsoft/kindeditor/issues/72
  8019. if (!K.IE || K.V <= 8) {
  8020. swfupload.remove();
  8021. }
  8022. }
  8023. }),
  8024. div = dialog.div;
  8025. var swfupload = K.swfupload({
  8026. container : K('.swfupload', div),
  8027. buttonImageUrl : imgPath + (self.langType == 'zh_CN' ? 'select-files-zh_CN.png' : 'select-files-en.png'),
  8028. buttonWidth : self.langType == 'zh_CN' ? 72 : 88,
  8029. buttonHeight : 23,
  8030. fileIconUrl : imgPath + 'image.png',
  8031. uploadDesc : uploadDesc,
  8032. startButtonValue : lang.startUpload,
  8033. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8034. flashUrl : imgPath + 'swfupload.swf',
  8035. filePostName : filePostName,
  8036. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8037. fileTypesDesc : 'Image Files',
  8038. fileUploadLimit : imageUploadLimit,
  8039. fileSizeLimit : imageSizeLimit,
  8040. postParams : K.undef(self.extraFileUploadParams, {}),
  8041. queueLimitExceeded : lang.queueLimitExceeded,
  8042. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8043. zeroByteFile : lang.zeroByteFile,
  8044. invalidFiletype : lang.invalidFiletype,
  8045. unknownError : lang.unknownError,
  8046. pendingMessage : lang.pending,
  8047. errorMessage : lang.uploadError,
  8048. afterError : function(html) {
  8049. self.errorDialog(html);
  8050. }
  8051. });
  8052. return dialog;
  8053. };
  8054. self.clickToolbar(name, function() {
  8055. self.plugin.multiImageDialog({
  8056. clickFn : function (urlList) {
  8057. if (urlList.length === 0) {
  8058. return;
  8059. }
  8060. K.each(urlList, function(i, data) {
  8061. if (self.afterUpload) {
  8062. self.afterUpload.call(self, data.url, data, 'multiimage');
  8063. }
  8064. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8065. });
  8066. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  8067. setTimeout(function() {
  8068. self.hideDialog().focus();
  8069. }, 0);
  8070. }
  8071. });
  8072. });
  8073. });
  8074. /**
  8075. * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
  8076. *
  8077. * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
  8078. *
  8079. * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz閚 and Mammon Media and is released under the MIT License:
  8080. * http://www.opensource.org/licenses/mit-license.php
  8081. *
  8082. * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
  8083. * http://www.opensource.org/licenses/mit-license.php
  8084. *
  8085. */
  8086. /* ******************* */
  8087. /* Constructor & Init */
  8088. /* ******************* */
  8089. (function() {
  8090. window.SWFUpload = function (settings) {
  8091. this.initSWFUpload(settings);
  8092. };
  8093. SWFUpload.prototype.initSWFUpload = function (settings) {
  8094. try {
  8095. this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
  8096. this.settings = settings;
  8097. this.eventQueue = [];
  8098. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8099. this.movieElement = null;
  8100. // Setup global control tracking
  8101. SWFUpload.instances[this.movieName] = this;
  8102. // Load the settings. Load the Flash movie.
  8103. this.initSettings();
  8104. this.loadFlash();
  8105. this.displayDebugInfo();
  8106. } catch (ex) {
  8107. delete SWFUpload.instances[this.movieName];
  8108. throw ex;
  8109. }
  8110. };
  8111. /* *************** */
  8112. /* Static Members */
  8113. /* *************** */
  8114. SWFUpload.instances = {};
  8115. SWFUpload.movieCount = 0;
  8116. SWFUpload.version = "2.2.0 2009-03-25";
  8117. SWFUpload.QUEUE_ERROR = {
  8118. QUEUE_LIMIT_EXCEEDED : -100,
  8119. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8120. ZERO_BYTE_FILE : -120,
  8121. INVALID_FILETYPE : -130
  8122. };
  8123. SWFUpload.UPLOAD_ERROR = {
  8124. HTTP_ERROR : -200,
  8125. MISSING_UPLOAD_URL : -210,
  8126. IO_ERROR : -220,
  8127. SECURITY_ERROR : -230,
  8128. UPLOAD_LIMIT_EXCEEDED : -240,
  8129. UPLOAD_FAILED : -250,
  8130. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8131. FILE_VALIDATION_FAILED : -270,
  8132. FILE_CANCELLED : -280,
  8133. UPLOAD_STOPPED : -290
  8134. };
  8135. SWFUpload.FILE_STATUS = {
  8136. QUEUED : -1,
  8137. IN_PROGRESS : -2,
  8138. ERROR : -3,
  8139. COMPLETE : -4,
  8140. CANCELLED : -5
  8141. };
  8142. SWFUpload.BUTTON_ACTION = {
  8143. SELECT_FILE : -100,
  8144. SELECT_FILES : -110,
  8145. START_UPLOAD : -120
  8146. };
  8147. SWFUpload.CURSOR = {
  8148. ARROW : -1,
  8149. HAND : -2
  8150. };
  8151. SWFUpload.WINDOW_MODE = {
  8152. WINDOW : "window",
  8153. TRANSPARENT : "transparent",
  8154. OPAQUE : "opaque"
  8155. };
  8156. // Private: takes a URL, determines if it is relative and converts to an absolute URL
  8157. // using the current site. Only processes the URL if it can, otherwise returns the URL untouched
  8158. SWFUpload.completeURL = function(url) {
  8159. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8160. return url;
  8161. }
  8162. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8163. var indexSlash = window.location.pathname.lastIndexOf("/");
  8164. if (indexSlash <= 0) {
  8165. path = "/";
  8166. } else {
  8167. path = window.location.pathname.substr(0, indexSlash) + "/";
  8168. }
  8169. return /*currentURL +*/ path + url;
  8170. };
  8171. /* ******************** */
  8172. /* Instance Members */
  8173. /* ******************** */
  8174. // Private: initSettings ensures that all the
  8175. // settings are set, getting a default value if one was not assigned.
  8176. SWFUpload.prototype.initSettings = function () {
  8177. this.ensureDefault = function (settingName, defaultValue) {
  8178. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8179. };
  8180. // Upload backend settings
  8181. this.ensureDefault("upload_url", "");
  8182. this.ensureDefault("preserve_relative_urls", false);
  8183. this.ensureDefault("file_post_name", "Filedata");
  8184. this.ensureDefault("post_params", {});
  8185. this.ensureDefault("use_query_string", false);
  8186. this.ensureDefault("requeue_on_error", false);
  8187. this.ensureDefault("http_success", []);
  8188. this.ensureDefault("assume_success_timeout", 0);
  8189. // File Settings
  8190. this.ensureDefault("file_types", "*.*");
  8191. this.ensureDefault("file_types_description", "All Files");
  8192. this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
  8193. this.ensureDefault("file_upload_limit", 0);
  8194. this.ensureDefault("file_queue_limit", 0);
  8195. // Flash Settings
  8196. this.ensureDefault("flash_url", "swfupload.swf");
  8197. this.ensureDefault("prevent_swf_caching", true);
  8198. // Button Settings
  8199. this.ensureDefault("button_image_url", "");
  8200. this.ensureDefault("button_width", 1);
  8201. this.ensureDefault("button_height", 1);
  8202. this.ensureDefault("button_text", "");
  8203. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8204. this.ensureDefault("button_text_top_padding", 0);
  8205. this.ensureDefault("button_text_left_padding", 0);
  8206. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8207. this.ensureDefault("button_disabled", false);
  8208. this.ensureDefault("button_placeholder_id", "");
  8209. this.ensureDefault("button_placeholder", null);
  8210. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8211. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8212. // Debug Settings
  8213. this.ensureDefault("debug", false);
  8214. this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
  8215. // Event Handlers
  8216. this.settings.return_upload_start_handler = this.returnUploadStart;
  8217. this.ensureDefault("swfupload_loaded_handler", null);
  8218. this.ensureDefault("file_dialog_start_handler", null);
  8219. this.ensureDefault("file_queued_handler", null);
  8220. this.ensureDefault("file_queue_error_handler", null);
  8221. this.ensureDefault("file_dialog_complete_handler", null);
  8222. this.ensureDefault("upload_start_handler", null);
  8223. this.ensureDefault("upload_progress_handler", null);
  8224. this.ensureDefault("upload_error_handler", null);
  8225. this.ensureDefault("upload_success_handler", null);
  8226. this.ensureDefault("upload_complete_handler", null);
  8227. this.ensureDefault("debug_handler", this.debugMessage);
  8228. this.ensureDefault("custom_settings", {});
  8229. // Other settings
  8230. this.customSettings = this.settings.custom_settings;
  8231. // Update the flash url if needed
  8232. if (!!this.settings.prevent_swf_caching) {
  8233. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8234. }
  8235. if (!this.settings.preserve_relative_urls) {
  8236. //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it
  8237. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8238. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8239. }
  8240. delete this.ensureDefault;
  8241. };
  8242. // Private: loadFlash replaces the button_placeholder element with the flash movie.
  8243. SWFUpload.prototype.loadFlash = function () {
  8244. var targetElement, tempParent;
  8245. // Make sure an element with the ID we are going to use doesn't already exist
  8246. if (document.getElementById(this.movieName) !== null) {
  8247. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8248. }
  8249. // Get the element where we will be placing the flash movie
  8250. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8251. if (targetElement == undefined) {
  8252. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8253. }
  8254. // Append the container and load the flash
  8255. tempParent = document.createElement("div");
  8256. tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
  8257. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8258. // Fix IE Flash/Form bug
  8259. if (window[this.movieName] == undefined) {
  8260. window[this.movieName] = this.getMovieElement();
  8261. }
  8262. };
  8263. // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
  8264. SWFUpload.prototype.getFlashHTML = function () {
  8265. // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  8266. // Fix bug for IE9
  8267. // http://www.kindsoft.net/view.php?bbsid=7&postid=5825&pagenum=1
  8268. var classid = '';
  8269. if (KindEditor.IE && KindEditor.V > 8) {
  8270. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8271. }
  8272. 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">',
  8273. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8274. '<param name="movie" value="', this.settings.flash_url, '" />',
  8275. '<param name="quality" value="high" />',
  8276. '<param name="menu" value="false" />',
  8277. '<param name="allowScriptAccess" value="always" />',
  8278. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8279. '</object>'].join("");
  8280. };
  8281. // Private: getFlashVars builds the parameter string that will be passed
  8282. // to flash in the flashvars param.
  8283. SWFUpload.prototype.getFlashVars = function () {
  8284. // Build a string from the post param object
  8285. var paramString = this.buildParamString();
  8286. var httpSuccessString = this.settings.http_success.join(",");
  8287. // Build the parameter string
  8288. return ["movieName=", encodeURIComponent(this.movieName),
  8289. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8290. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8291. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8292. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8293. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8294. "&amp;params=", encodeURIComponent(paramString),
  8295. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8296. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8297. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8298. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8299. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8300. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8301. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8302. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8303. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8304. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8305. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8306. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8307. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8308. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8309. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8310. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8311. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8312. ].join("");
  8313. };
  8314. // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
  8315. // The element is cached after the first lookup
  8316. SWFUpload.prototype.getMovieElement = function () {
  8317. if (this.movieElement == undefined) {
  8318. this.movieElement = document.getElementById(this.movieName);
  8319. }
  8320. if (this.movieElement === null) {
  8321. throw "Could not find Flash element";
  8322. }
  8323. return this.movieElement;
  8324. };
  8325. // Private: buildParamString takes the name/value pairs in the post_params setting object
  8326. // and joins them up in to a string formatted "name=value&amp;name=value"
  8327. SWFUpload.prototype.buildParamString = function () {
  8328. var postParams = this.settings.post_params;
  8329. var paramStringPairs = [];
  8330. if (typeof(postParams) === "object") {
  8331. for (var name in postParams) {
  8332. if (postParams.hasOwnProperty(name)) {
  8333. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8334. }
  8335. }
  8336. }
  8337. return paramStringPairs.join("&amp;");
  8338. };
  8339. // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
  8340. // all references to the SWF, and other objects so memory is properly freed.
  8341. // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
  8342. // Credits: Major improvements provided by steffen
  8343. SWFUpload.prototype.destroy = function () {
  8344. try {
  8345. // Make sure Flash is done before we try to remove it
  8346. this.cancelUpload(null, false);
  8347. // Remove the SWFUpload DOM nodes
  8348. var movieElement = null;
  8349. movieElement = this.getMovieElement();
  8350. if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8351. // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
  8352. for (var i in movieElement) {
  8353. try {
  8354. if (typeof(movieElement[i]) === "function") {
  8355. movieElement[i] = null;
  8356. }
  8357. } catch (ex1) {}
  8358. }
  8359. // Remove the Movie Element from the page
  8360. try {
  8361. movieElement.parentNode.removeChild(movieElement);
  8362. } catch (ex) {}
  8363. }
  8364. // Remove IE form fix reference
  8365. window[this.movieName] = null;
  8366. // Destroy other references
  8367. SWFUpload.instances[this.movieName] = null;
  8368. delete SWFUpload.instances[this.movieName];
  8369. this.movieElement = null;
  8370. this.settings = null;
  8371. this.customSettings = null;
  8372. this.eventQueue = null;
  8373. this.movieName = null;
  8374. return true;
  8375. } catch (ex2) {
  8376. return false;
  8377. }
  8378. };
  8379. // Public: displayDebugInfo prints out settings and configuration
  8380. // information about this SWFUpload instance.
  8381. // This function (and any references to it) can be deleted when placing
  8382. // SWFUpload in production.
  8383. SWFUpload.prototype.displayDebugInfo = function () {
  8384. this.debug(
  8385. [
  8386. "---SWFUpload Instance Info---\n",
  8387. "Version: ", SWFUpload.version, "\n",
  8388. "Movie Name: ", this.movieName, "\n",
  8389. "Settings:\n",
  8390. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8391. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8392. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8393. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8394. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8395. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8396. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8397. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8398. "\t", "file_types: ", this.settings.file_types, "\n",
  8399. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8400. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8401. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8402. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8403. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8404. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8405. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8406. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8407. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8408. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8409. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8410. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8411. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8412. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8413. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8414. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8415. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8416. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8417. "Event Handlers:\n",
  8418. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8419. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8420. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8421. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8422. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8423. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8424. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8425. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8426. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8427. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8428. ].join("")
  8429. );
  8430. };
  8431. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8432. the maintain v2 API compatibility
  8433. */
  8434. // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
  8435. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8436. if (value == undefined) {
  8437. return (this.settings[name] = default_value);
  8438. } else {
  8439. return (this.settings[name] = value);
  8440. }
  8441. };
  8442. // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
  8443. SWFUpload.prototype.getSetting = function (name) {
  8444. if (this.settings[name] != undefined) {
  8445. return this.settings[name];
  8446. }
  8447. return "";
  8448. };
  8449. // Private: callFlash handles function calls made to the Flash element.
  8450. // Calls are made with a setTimeout for some functions to work around
  8451. // bugs in the ExternalInterface library.
  8452. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8453. argumentArray = argumentArray || [];
  8454. var movieElement = this.getMovieElement();
  8455. var returnValue, returnString;
  8456. // Flash's method if calling ExternalInterface methods (code adapted from MooTools).
  8457. try {
  8458. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8459. returnValue = eval(returnString);
  8460. } catch (ex) {
  8461. throw "Call to " + functionName + " failed";
  8462. }
  8463. // Unescape file post param values
  8464. if (returnValue != undefined && typeof returnValue.post === "object") {
  8465. returnValue = this.unescapeFilePostParams(returnValue);
  8466. }
  8467. return returnValue;
  8468. };
  8469. /* *****************************
  8470. -- Flash control methods --
  8471. Your UI should use these
  8472. to operate SWFUpload
  8473. ***************************** */
  8474. // WARNING: this function does not work in Flash Player 10
  8475. // Public: selectFile causes a File Selection Dialog window to appear. This
  8476. // dialog only allows 1 file to be selected.
  8477. SWFUpload.prototype.selectFile = function () {
  8478. this.callFlash("SelectFile");
  8479. };
  8480. // WARNING: this function does not work in Flash Player 10
  8481. // Public: selectFiles causes a File Selection Dialog window to appear/ This
  8482. // dialog allows the user to select any number of files
  8483. // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
  8484. // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
  8485. // for this bug.
  8486. SWFUpload.prototype.selectFiles = function () {
  8487. this.callFlash("SelectFiles");
  8488. };
  8489. // Public: startUpload starts uploading the first file in the queue unless
  8490. // the optional parameter 'fileID' specifies the ID
  8491. SWFUpload.prototype.startUpload = function (fileID) {
  8492. this.callFlash("StartUpload", [fileID]);
  8493. };
  8494. // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
  8495. // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
  8496. // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
  8497. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8498. if (triggerErrorEvent !== false) {
  8499. triggerErrorEvent = true;
  8500. }
  8501. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8502. };
  8503. // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
  8504. // If nothing is currently uploading then nothing happens.
  8505. SWFUpload.prototype.stopUpload = function () {
  8506. this.callFlash("StopUpload");
  8507. };
  8508. /* ************************
  8509. * Settings methods
  8510. * These methods change the SWFUpload settings.
  8511. * SWFUpload settings should not be changed directly on the settings object
  8512. * since many of the settings need to be passed to Flash in order to take
  8513. * effect.
  8514. * *********************** */
  8515. // Public: getStats gets the file statistics object.
  8516. SWFUpload.prototype.getStats = function () {
  8517. return this.callFlash("GetStats");
  8518. };
  8519. // Public: setStats changes the SWFUpload statistics. You shouldn't need to
  8520. // change the statistics but you can. Changing the statistics does not
  8521. // affect SWFUpload accept for the successful_uploads count which is used
  8522. // by the upload_limit setting to determine how many files the user may upload.
  8523. SWFUpload.prototype.setStats = function (statsObject) {
  8524. this.callFlash("SetStats", [statsObject]);
  8525. };
  8526. // Public: getFile retrieves a File object by ID or Index. If the file is
  8527. // not found then 'null' is returned.
  8528. SWFUpload.prototype.getFile = function (fileID) {
  8529. if (typeof(fileID) === "number") {
  8530. return this.callFlash("GetFileByIndex", [fileID]);
  8531. } else {
  8532. return this.callFlash("GetFile", [fileID]);
  8533. }
  8534. };
  8535. // Public: addFileParam sets a name/value pair that will be posted with the
  8536. // file specified by the Files ID. If the name already exists then the
  8537. // exiting value will be overwritten.
  8538. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8539. return this.callFlash("AddFileParam", [fileID, name, value]);
  8540. };
  8541. // Public: removeFileParam removes a previously set (by addFileParam) name/value
  8542. // pair from the specified file.
  8543. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8544. this.callFlash("RemoveFileParam", [fileID, name]);
  8545. };
  8546. // Public: setUploadUrl changes the upload_url setting.
  8547. SWFUpload.prototype.setUploadURL = function (url) {
  8548. this.settings.upload_url = url.toString();
  8549. this.callFlash("SetUploadURL", [url]);
  8550. };
  8551. // Public: setPostParams changes the post_params setting
  8552. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8553. this.settings.post_params = paramsObject;
  8554. this.callFlash("SetPostParams", [paramsObject]);
  8555. };
  8556. // Public: addPostParam adds post name/value pair. Each name can have only one value.
  8557. SWFUpload.prototype.addPostParam = function (name, value) {
  8558. this.settings.post_params[name] = value;
  8559. this.callFlash("SetPostParams", [this.settings.post_params]);
  8560. };
  8561. // Public: removePostParam deletes post name/value pair.
  8562. SWFUpload.prototype.removePostParam = function (name) {
  8563. delete this.settings.post_params[name];
  8564. this.callFlash("SetPostParams", [this.settings.post_params]);
  8565. };
  8566. // Public: setFileTypes changes the file_types setting and the file_types_description setting
  8567. SWFUpload.prototype.setFileTypes = function (types, description) {
  8568. this.settings.file_types = types;
  8569. this.settings.file_types_description = description;
  8570. this.callFlash("SetFileTypes", [types, description]);
  8571. };
  8572. // Public: setFileSizeLimit changes the file_size_limit setting
  8573. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8574. this.settings.file_size_limit = fileSizeLimit;
  8575. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8576. };
  8577. // Public: setFileUploadLimit changes the file_upload_limit setting
  8578. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8579. this.settings.file_upload_limit = fileUploadLimit;
  8580. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8581. };
  8582. // Public: setFileQueueLimit changes the file_queue_limit setting
  8583. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8584. this.settings.file_queue_limit = fileQueueLimit;
  8585. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8586. };
  8587. // Public: setFilePostName changes the file_post_name setting
  8588. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8589. this.settings.file_post_name = filePostName;
  8590. this.callFlash("SetFilePostName", [filePostName]);
  8591. };
  8592. // Public: setUseQueryString changes the use_query_string setting
  8593. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8594. this.settings.use_query_string = useQueryString;
  8595. this.callFlash("SetUseQueryString", [useQueryString]);
  8596. };
  8597. // Public: setRequeueOnError changes the requeue_on_error setting
  8598. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8599. this.settings.requeue_on_error = requeueOnError;
  8600. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8601. };
  8602. // Public: setHTTPSuccess changes the http_success setting
  8603. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8604. if (typeof http_status_codes === "string") {
  8605. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8606. }
  8607. this.settings.http_success = http_status_codes;
  8608. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8609. };
  8610. // Public: setHTTPSuccess changes the http_success setting
  8611. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8612. this.settings.assume_success_timeout = timeout_seconds;
  8613. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8614. };
  8615. // Public: setDebugEnabled changes the debug_enabled setting
  8616. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8617. this.settings.debug_enabled = debugEnabled;
  8618. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8619. };
  8620. // Public: setButtonImageURL loads a button image sprite
  8621. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8622. if (buttonImageURL == undefined) {
  8623. buttonImageURL = "";
  8624. }
  8625. this.settings.button_image_url = buttonImageURL;
  8626. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8627. };
  8628. // Public: setButtonDimensions resizes the Flash Movie and button
  8629. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8630. this.settings.button_width = width;
  8631. this.settings.button_height = height;
  8632. var movie = this.getMovieElement();
  8633. if (movie != undefined) {
  8634. movie.style.width = width + "px";
  8635. movie.style.height = height + "px";
  8636. }
  8637. this.callFlash("SetButtonDimensions", [width, height]);
  8638. };
  8639. // Public: setButtonText Changes the text overlaid on the button
  8640. SWFUpload.prototype.setButtonText = function (html) {
  8641. this.settings.button_text = html;
  8642. this.callFlash("SetButtonText", [html]);
  8643. };
  8644. // Public: setButtonTextPadding changes the top and left padding of the text overlay
  8645. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8646. this.settings.button_text_top_padding = top;
  8647. this.settings.button_text_left_padding = left;
  8648. this.callFlash("SetButtonTextPadding", [left, top]);
  8649. };
  8650. // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
  8651. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8652. this.settings.button_text_style = css;
  8653. this.callFlash("SetButtonTextStyle", [css]);
  8654. };
  8655. // Public: setButtonDisabled disables/enables the button
  8656. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8657. this.settings.button_disabled = isDisabled;
  8658. this.callFlash("SetButtonDisabled", [isDisabled]);
  8659. };
  8660. // Public: setButtonAction sets the action that occurs when the button is clicked
  8661. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8662. this.settings.button_action = buttonAction;
  8663. this.callFlash("SetButtonAction", [buttonAction]);
  8664. };
  8665. // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
  8666. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8667. this.settings.button_cursor = cursor;
  8668. this.callFlash("SetButtonCursor", [cursor]);
  8669. };
  8670. /* *******************************
  8671. Flash Event Interfaces
  8672. These functions are used by Flash to trigger the various
  8673. events.
  8674. All these functions a Private.
  8675. Because the ExternalInterface library is buggy the event calls
  8676. are added to a queue and the queue then executed by a setTimeout.
  8677. This ensures that events are executed in a determinate order and that
  8678. the ExternalInterface bugs are avoided.
  8679. ******************************* */
  8680. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8681. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8682. if (argumentArray == undefined) {
  8683. argumentArray = [];
  8684. } else if (!(argumentArray instanceof Array)) {
  8685. argumentArray = [argumentArray];
  8686. }
  8687. var self = this;
  8688. if (typeof this.settings[handlerName] === "function") {
  8689. // Queue the event
  8690. this.eventQueue.push(function () {
  8691. this.settings[handlerName].apply(this, argumentArray);
  8692. });
  8693. // Execute the next queued event
  8694. setTimeout(function () {
  8695. self.executeNextEvent();
  8696. }, 0);
  8697. } else if (this.settings[handlerName] !== null) {
  8698. throw "Event handler " + handlerName + " is unknown or is not a function";
  8699. }
  8700. };
  8701. // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
  8702. // we must queue them in order to garentee that they are executed in order.
  8703. SWFUpload.prototype.executeNextEvent = function () {
  8704. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8705. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8706. if (typeof(f) === "function") {
  8707. f.apply(this);
  8708. }
  8709. };
  8710. // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
  8711. // properties that contain characters that are not valid for JavaScript identifiers. To work around this
  8712. // the Flash Component escapes the parameter names and we must unescape again before passing them along.
  8713. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8714. var reg = /[$]([0-9a-f]{4})/i;
  8715. var unescapedPost = {};
  8716. var uk;
  8717. if (file != undefined) {
  8718. for (var k in file.post) {
  8719. if (file.post.hasOwnProperty(k)) {
  8720. uk = k;
  8721. var match;
  8722. while ((match = reg.exec(uk)) !== null) {
  8723. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8724. }
  8725. unescapedPost[uk] = file.post[k];
  8726. }
  8727. }
  8728. file.post = unescapedPost;
  8729. }
  8730. return file;
  8731. };
  8732. // Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working)
  8733. SWFUpload.prototype.testExternalInterface = function () {
  8734. try {
  8735. return this.callFlash("TestExternalInterface");
  8736. } catch (ex) {
  8737. return false;
  8738. }
  8739. };
  8740. // Private: This event is called by Flash when it has finished loading. Don't modify this.
  8741. // Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded.
  8742. SWFUpload.prototype.flashReady = function () {
  8743. // Check that the movie element is loaded correctly with its ExternalInterface methods defined
  8744. var movieElement = this.getMovieElement();
  8745. if (!movieElement) {
  8746. this.debug("Flash called back ready but the flash movie can't be found.");
  8747. return;
  8748. }
  8749. this.cleanUp(movieElement);
  8750. this.queueEvent("swfupload_loaded_handler");
  8751. };
  8752. // Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
  8753. // This function is called by Flash each time the ExternalInterface functions are created.
  8754. SWFUpload.prototype.cleanUp = function (movieElement) {
  8755. // Pro-actively unhook all the Flash functions
  8756. try {
  8757. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8758. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8759. for (var key in movieElement) {
  8760. try {
  8761. if (typeof(movieElement[key]) === "function") {
  8762. movieElement[key] = null;
  8763. }
  8764. } catch (ex) {
  8765. }
  8766. }
  8767. }
  8768. } catch (ex1) {
  8769. }
  8770. // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
  8771. // it doesn't display errors.
  8772. window["__flash__removeCallback"] = function (instance, name) {
  8773. try {
  8774. if (instance) {
  8775. instance[name] = null;
  8776. }
  8777. } catch (flashEx) {
  8778. }
  8779. };
  8780. };
  8781. /* This is a chance to do something before the browse window opens */
  8782. SWFUpload.prototype.fileDialogStart = function () {
  8783. this.queueEvent("file_dialog_start_handler");
  8784. };
  8785. /* Called when a file is successfully added to the queue. */
  8786. SWFUpload.prototype.fileQueued = function (file) {
  8787. file = this.unescapeFilePostParams(file);
  8788. this.queueEvent("file_queued_handler", file);
  8789. };
  8790. /* Handle errors that occur when an attempt to queue a file fails. */
  8791. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8792. file = this.unescapeFilePostParams(file);
  8793. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8794. };
  8795. /* Called after the file dialog has closed and the selected files have been queued.
  8796. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8797. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8798. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8799. };
  8800. SWFUpload.prototype.uploadStart = function (file) {
  8801. file = this.unescapeFilePostParams(file);
  8802. this.queueEvent("return_upload_start_handler", file);
  8803. };
  8804. SWFUpload.prototype.returnUploadStart = function (file) {
  8805. var returnValue;
  8806. if (typeof this.settings.upload_start_handler === "function") {
  8807. file = this.unescapeFilePostParams(file);
  8808. returnValue = this.settings.upload_start_handler.call(this, file);
  8809. } else if (this.settings.upload_start_handler != undefined) {
  8810. throw "upload_start_handler must be a function";
  8811. }
  8812. // Convert undefined to true so if nothing is returned from the upload_start_handler it is
  8813. // interpretted as 'true'.
  8814. if (returnValue === undefined) {
  8815. returnValue = true;
  8816. }
  8817. returnValue = !!returnValue;
  8818. this.callFlash("ReturnUploadStart", [returnValue]);
  8819. };
  8820. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8821. file = this.unescapeFilePostParams(file);
  8822. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8823. };
  8824. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8825. file = this.unescapeFilePostParams(file);
  8826. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8827. };
  8828. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8829. file = this.unescapeFilePostParams(file);
  8830. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8831. };
  8832. SWFUpload.prototype.uploadComplete = function (file) {
  8833. file = this.unescapeFilePostParams(file);
  8834. this.queueEvent("upload_complete_handler", file);
  8835. };
  8836. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8837. internal debug console. You can override this event and have messages written where you want. */
  8838. SWFUpload.prototype.debug = function (message) {
  8839. this.queueEvent("debug_handler", message);
  8840. };
  8841. /* **********************************
  8842. Debug Console
  8843. The debug console is a self contained, in page location
  8844. for debug message to be sent. The Debug Console adds
  8845. itself to the body if necessary.
  8846. The console is automatically scrolled as messages appear.
  8847. If you are using your own debug handler or when you deploy to production and
  8848. have debug disabled you can remove these functions to reduce the file size
  8849. and complexity.
  8850. ********************************** */
  8851. // Private: debugMessage is the default debug_handler. If you want to print debug messages
  8852. // call the debug() function. When overriding the function your own function should
  8853. // check to see if the debug setting is true before outputting debug information.
  8854. SWFUpload.prototype.debugMessage = function (message) {
  8855. if (this.settings.debug) {
  8856. var exceptionMessage, exceptionValues = [];
  8857. // Check for an exception object and print it nicely
  8858. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8859. for (var key in message) {
  8860. if (message.hasOwnProperty(key)) {
  8861. exceptionValues.push(key + ": " + message[key]);
  8862. }
  8863. }
  8864. exceptionMessage = exceptionValues.join("\n") || "";
  8865. exceptionValues = exceptionMessage.split("\n");
  8866. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8867. SWFUpload.Console.writeLine(exceptionMessage);
  8868. } else {
  8869. SWFUpload.Console.writeLine(message);
  8870. }
  8871. }
  8872. };
  8873. SWFUpload.Console = {};
  8874. SWFUpload.Console.writeLine = function (message) {
  8875. var console, documentForm;
  8876. try {
  8877. console = document.getElementById("SWFUpload_Console");
  8878. if (!console) {
  8879. documentForm = document.createElement("form");
  8880. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8881. console = document.createElement("textarea");
  8882. console.id = "SWFUpload_Console";
  8883. console.style.fontFamily = "monospace";
  8884. console.setAttribute("wrap", "off");
  8885. console.wrap = "off";
  8886. console.style.overflow = "auto";
  8887. console.style.width = "700px";
  8888. console.style.height = "350px";
  8889. console.style.margin = "5px";
  8890. documentForm.appendChild(console);
  8891. }
  8892. console.value += message + "\n";
  8893. console.scrollTop = console.scrollHeight - console.clientHeight;
  8894. } catch (ex) {
  8895. alert("Exception: " + ex.name + " Message: " + ex.message);
  8896. }
  8897. };
  8898. })();
  8899. (function() {
  8900. /*
  8901. Queue Plug-in
  8902. Features:
  8903. *Adds a cancelQueue() method for cancelling the entire queue.
  8904. *All queued files are uploaded when startUpload() is called.
  8905. *If false is returned from uploadComplete then the queue upload is stopped.
  8906. If false is not returned (strict comparison) then the queue upload is continued.
  8907. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8908. Set the event handler with the queue_complete_handler setting.
  8909. */
  8910. if (typeof(SWFUpload) === "function") {
  8911. SWFUpload.queue = {};
  8912. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8913. return function () {
  8914. if (typeof(oldInitSettings) === "function") {
  8915. oldInitSettings.call(this);
  8916. }
  8917. this.queueSettings = {};
  8918. this.queueSettings.queue_cancelled_flag = false;
  8919. this.queueSettings.queue_upload_count = 0;
  8920. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8921. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8922. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8923. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8924. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8925. };
  8926. })(SWFUpload.prototype.initSettings);
  8927. SWFUpload.prototype.startUpload = function (fileID) {
  8928. this.queueSettings.queue_cancelled_flag = false;
  8929. this.callFlash("StartUpload", [fileID]);
  8930. };
  8931. SWFUpload.prototype.cancelQueue = function () {
  8932. this.queueSettings.queue_cancelled_flag = true;
  8933. this.stopUpload();
  8934. var stats = this.getStats();
  8935. while (stats.files_queued > 0) {
  8936. this.cancelUpload();
  8937. stats = this.getStats();
  8938. }
  8939. };
  8940. SWFUpload.queue.uploadStartHandler = function (file) {
  8941. var returnValue;
  8942. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8943. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8944. }
  8945. // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
  8946. returnValue = (returnValue === false) ? false : true;
  8947. this.queueSettings.queue_cancelled_flag = !returnValue;
  8948. return returnValue;
  8949. };
  8950. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8951. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8952. var continueUpload;
  8953. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8954. this.queueSettings.queue_upload_count++;
  8955. }
  8956. if (typeof(user_upload_complete_handler) === "function") {
  8957. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8958. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8959. // If the file was stopped and re-queued don't restart the upload
  8960. continueUpload = false;
  8961. } else {
  8962. continueUpload = true;
  8963. }
  8964. if (continueUpload) {
  8965. var stats = this.getStats();
  8966. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8967. this.startUpload();
  8968. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8969. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8970. this.queueSettings.queue_upload_count = 0;
  8971. } else {
  8972. this.queueSettings.queue_cancelled_flag = false;
  8973. this.queueSettings.queue_upload_count = 0;
  8974. }
  8975. }
  8976. };
  8977. }
  8978. })();
  8979. /*******************************************************************************
  8980. * KindEditor - WYSIWYG HTML Editor for Internet
  8981. * Copyright (C) 2006-2011 kindsoft.net
  8982. *
  8983. * @author Roddy <luolonghao@gmail.com>
  8984. * @site http://www.kindsoft.net/
  8985. * @licence http://www.kindsoft.net/license.php
  8986. *******************************************************************************/
  8987. KindEditor.plugin('pagebreak', function(K) {
  8988. var self = this;
  8989. var name = 'pagebreak';
  8990. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8991. self.clickToolbar(name, function() {
  8992. var cmd = self.cmd, range = cmd.range;
  8993. self.focus();
  8994. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8995. self.insertHtml(pagebreakHtml + tail);
  8996. if (tail !== '') {
  8997. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8998. range.selectNodeContents(p[0]);
  8999. p.removeAttr('id');
  9000. cmd.select();
  9001. }
  9002. });
  9003. });
  9004. /*******************************************************************************
  9005. * KindEditor - WYSIWYG HTML Editor for Internet
  9006. * Copyright (C) 2006-2011 kindsoft.net
  9007. *
  9008. * @author Roddy <luolonghao@gmail.com>
  9009. * @site http://www.kindsoft.net/
  9010. * @licence http://www.kindsoft.net/license.php
  9011. *******************************************************************************/
  9012. KindEditor.plugin('plainpaste', function(K) {
  9013. var self = this, name = 'plainpaste';
  9014. self.clickToolbar(name, function() {
  9015. var lang = self.lang(name + '.'),
  9016. html = '<div style="padding:10px 20px;">' +
  9017. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9018. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9019. '</div>',
  9020. dialog = self.createDialog({
  9021. name : name,
  9022. width : 450,
  9023. title : self.lang(name),
  9024. body : html,
  9025. yesBtn : {
  9026. name : self.lang('yes'),
  9027. click : function(e) {
  9028. var html = textarea.val();
  9029. html = K.escape(html);
  9030. html = html.replace(/ {2}/g, ' &nbsp;');
  9031. if (self.newlineTag == 'p') {
  9032. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9033. } else {
  9034. html = html.replace(/\n/g, '<br />$&');
  9035. }
  9036. self.insertHtml(html).hideDialog().focus();
  9037. }
  9038. }
  9039. }),
  9040. textarea = K('textarea', dialog.div);
  9041. textarea[0].focus();
  9042. });
  9043. });
  9044. /*******************************************************************************
  9045. * KindEditor - WYSIWYG HTML Editor for Internet
  9046. * Copyright (C) 2006-2011 kindsoft.net
  9047. *
  9048. * @author Roddy <luolonghao@gmail.com>
  9049. * @site http://www.kindsoft.net/
  9050. * @licence http://www.kindsoft.net/license.php
  9051. *******************************************************************************/
  9052. KindEditor.plugin('preview', function(K) {
  9053. var self = this, name = 'preview', undefined;
  9054. self.clickToolbar(name, function() {
  9055. var lang = self.lang(name + '.'),
  9056. html = '<div style="padding:10px 20px;">' +
  9057. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9058. '</div>',
  9059. dialog = self.createDialog({
  9060. name : name,
  9061. width : 750,
  9062. title : self.lang(name),
  9063. body : html
  9064. }),
  9065. iframe = K('iframe', dialog.div),
  9066. doc = K.iframeDoc(iframe);
  9067. doc.open();
  9068. doc.write(self.fullHtml());
  9069. doc.close();
  9070. K(doc.body).css('background-color', '#FFF');
  9071. iframe[0].contentWindow.focus();
  9072. });
  9073. });
  9074. /*******************************************************************************
  9075. * KindEditor - WYSIWYG HTML Editor for Internet
  9076. * Copyright (C) 2006-2011 kindsoft.net
  9077. *
  9078. * @author Roddy <luolonghao@gmail.com>
  9079. * @site http://www.kindsoft.net/
  9080. * @licence http://www.kindsoft.net/license.php
  9081. *******************************************************************************/
  9082. KindEditor.plugin('quickformat', function(K) {
  9083. var self = this, name = 'quickformat',
  9084. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9085. function getFirstChild(knode) {
  9086. var child = knode.first();
  9087. while (child && child.first()) {
  9088. child = child.first();
  9089. }
  9090. return child;
  9091. }
  9092. self.clickToolbar(name, function() {
  9093. self.focus();
  9094. var doc = self.edit.doc,
  9095. range = self.cmd.range,
  9096. child = K(doc.body).first(), next,
  9097. nodeList = [], subList = [],
  9098. bookmark = range.createBookmark(true);
  9099. while(child) {
  9100. next = child.next();
  9101. var firstChild = getFirstChild(child);
  9102. if (!firstChild || firstChild.name != 'img') {
  9103. if (blockMap[child.name]) {
  9104. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9105. child.css('text-indent', '2em');
  9106. } else {
  9107. subList.push(child);
  9108. }
  9109. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9110. if (subList.length > 0) {
  9111. nodeList.push(subList);
  9112. }
  9113. subList = [];
  9114. }
  9115. }
  9116. child = next;
  9117. }
  9118. K.each(nodeList, function(i, subList) {
  9119. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9120. subList[0].before(wrapper);
  9121. K.each(subList, function(i, knode) {
  9122. wrapper.append(knode);
  9123. });
  9124. });
  9125. range.moveToBookmark(bookmark);
  9126. self.addBookmark();
  9127. });
  9128. });
  9129. /**
  9130. --------------------------
  9131. abcd<br />
  9132. 1234<br />
  9133. to
  9134. <p style="text-indent:2em;">
  9135. abcd<br />
  9136. 1234<br />
  9137. </p>
  9138. --------------------------
  9139. &nbsp; abcd<img>1233
  9140. <p>1234</p>
  9141. to
  9142. <p style="text-indent:2em;">abcd<img>1233</p>
  9143. <p style="text-indent:2em;">1234</p>
  9144. --------------------------
  9145. *//*******************************************************************************
  9146. * KindEditor - WYSIWYG HTML Editor for Internet
  9147. * Copyright (C) 2006-2011 kindsoft.net
  9148. *
  9149. * @author Roddy <luolonghao@gmail.com>
  9150. * @site http://www.kindsoft.net/
  9151. * @licence http://www.kindsoft.net/license.php
  9152. *******************************************************************************/
  9153. KindEditor.plugin('table', function(K) {
  9154. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9155. // 设置颜色
  9156. function _setColor(box, color) {
  9157. color = color.toUpperCase();
  9158. box.css('background-color', color);
  9159. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9160. box.html(color);
  9161. }
  9162. // 初始化取色器
  9163. var pickerList = [];
  9164. function _initColorPicker(dialogDiv, colorBox) {
  9165. colorBox.bind('click,mousedown', function(e){
  9166. e.stopPropagation();
  9167. });
  9168. function removePicker() {
  9169. K.each(pickerList, function() {
  9170. this.remove();
  9171. });
  9172. pickerList = [];
  9173. K(document).unbind('click,mousedown', removePicker);
  9174. dialogDiv.unbind('click,mousedown', removePicker);
  9175. }
  9176. colorBox.click(function(e) {
  9177. removePicker();
  9178. var box = K(this),
  9179. pos = box.pos();
  9180. var picker = K.colorpicker({
  9181. x : pos.x,
  9182. y : pos.y + box.height(),
  9183. z : 811214,
  9184. selectedColor : K(this).html(),
  9185. colors : self.colorTable,
  9186. noColor : self.lang('noColor'),
  9187. shadowMode : self.shadowMode,
  9188. click : function(color) {
  9189. _setColor(box, color);
  9190. removePicker();
  9191. }
  9192. });
  9193. pickerList.push(picker);
  9194. K(document).bind('click,mousedown', removePicker);
  9195. dialogDiv.bind('click,mousedown', removePicker);
  9196. });
  9197. }
  9198. // 取得下一行cell的index
  9199. function _getCellIndex(table, row, cell) {
  9200. var rowSpanCount = 0;
  9201. for (var i = 0, len = row.cells.length; i < len; i++) {
  9202. if (row.cells[i] == cell) {
  9203. break;
  9204. }
  9205. rowSpanCount += row.cells[i].rowSpan - 1;
  9206. }
  9207. return cell.cellIndex - rowSpanCount;
  9208. }
  9209. self.plugin.table = {
  9210. //insert or modify table
  9211. prop : function(isInsert) {
  9212. var html = [
  9213. '<div style="padding:20px;">',
  9214. //rows, cols
  9215. '<div class="ke-dialog-row">',
  9216. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9217. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9218. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9219. '</div>',
  9220. //width, height
  9221. '<div class="ke-dialog-row">',
  9222. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9223. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9224. '<select name="widthType">',
  9225. '<option value="%">' + lang.percent + '</option>',
  9226. '<option value="px">' + lang.px + '</option>',
  9227. '</select> &nbsp; ',
  9228. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9229. '<select name="heightType">',
  9230. '<option value="%">' + lang.percent + '</option>',
  9231. '<option value="px">' + lang.px + '</option>',
  9232. '</select>',
  9233. '</div>',
  9234. //space, padding
  9235. '<div class="ke-dialog-row">',
  9236. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9237. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9238. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9239. '</div>',
  9240. //align
  9241. '<div class="ke-dialog-row">',
  9242. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9243. '<select id="keAlign" name="align">',
  9244. '<option value="">' + lang.alignDefault + '</option>',
  9245. '<option value="left">' + lang.alignLeft + '</option>',
  9246. '<option value="center">' + lang.alignCenter + '</option>',
  9247. '<option value="right">' + lang.alignRight + '</option>',
  9248. '</select>',
  9249. '</div>',
  9250. //border
  9251. '<div class="ke-dialog-row">',
  9252. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9253. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9254. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9255. '</div>',
  9256. //background color
  9257. '<div class="ke-dialog-row">',
  9258. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9259. '<span class="ke-inline-block ke-input-color"></span>',
  9260. '</div>',
  9261. '</div>'
  9262. ].join('');
  9263. var bookmark = self.cmd.range.createBookmark();
  9264. var dialog = self.createDialog({
  9265. name : name,
  9266. width : 500,
  9267. title : self.lang(name),
  9268. body : html,
  9269. beforeRemove : function() {
  9270. colorBox.unbind();
  9271. },
  9272. yesBtn : {
  9273. name : self.lang('yes'),
  9274. click : function(e) {
  9275. var rows = rowsBox.val(),
  9276. cols = colsBox.val(),
  9277. width = widthBox.val(),
  9278. height = heightBox.val(),
  9279. widthType = widthTypeBox.val(),
  9280. heightType = heightTypeBox.val(),
  9281. padding = paddingBox.val(),
  9282. spacing = spacingBox.val(),
  9283. align = alignBox.val(),
  9284. border = borderBox.val(),
  9285. borderColor = K(colorBox[0]).html() || '',
  9286. bgColor = K(colorBox[1]).html() || '';
  9287. if (rows == 0 || !/^\d+$/.test(rows)) {
  9288. alert(self.lang('invalidRows'));
  9289. rowsBox[0].focus();
  9290. return;
  9291. }
  9292. if (cols == 0 || !/^\d+$/.test(cols)) {
  9293. alert(self.lang('invalidRows'));
  9294. colsBox[0].focus();
  9295. return;
  9296. }
  9297. if (!/^\d*$/.test(width)) {
  9298. alert(self.lang('invalidWidth'));
  9299. widthBox[0].focus();
  9300. return;
  9301. }
  9302. if (!/^\d*$/.test(height)) {
  9303. alert(self.lang('invalidHeight'));
  9304. heightBox[0].focus();
  9305. return;
  9306. }
  9307. if (!/^\d*$/.test(padding)) {
  9308. alert(self.lang('invalidPadding'));
  9309. paddingBox[0].focus();
  9310. return;
  9311. }
  9312. if (!/^\d*$/.test(spacing)) {
  9313. alert(self.lang('invalidSpacing'));
  9314. spacingBox[0].focus();
  9315. return;
  9316. }
  9317. if (!/^\d*$/.test(border)) {
  9318. alert(self.lang('invalidBorder'));
  9319. borderBox[0].focus();
  9320. return;
  9321. }
  9322. //modify table
  9323. if (table) {
  9324. if (width !== '') {
  9325. table.width(width + widthType);
  9326. } else {
  9327. table.css('width', '');
  9328. }
  9329. if (table[0].width !== undefined) {
  9330. table.removeAttr('width');
  9331. }
  9332. if (height !== '') {
  9333. table.height(height + heightType);
  9334. } else {
  9335. table.css('height', '');
  9336. }
  9337. if (table[0].height !== undefined) {
  9338. table.removeAttr('height');
  9339. }
  9340. table.css('background-color', bgColor);
  9341. if (table[0].bgColor !== undefined) {
  9342. table.removeAttr('bgColor');
  9343. }
  9344. if (padding !== '') {
  9345. table[0].cellPadding = padding;
  9346. } else {
  9347. table.removeAttr('cellPadding');
  9348. }
  9349. if (spacing !== '') {
  9350. table[0].cellSpacing = spacing;
  9351. } else {
  9352. table.removeAttr('cellSpacing');
  9353. }
  9354. if (align !== '') {
  9355. table[0].align = align;
  9356. } else {
  9357. table.removeAttr('align');
  9358. }
  9359. if (border !== '') {
  9360. table.attr('border', border);
  9361. } else {
  9362. table.removeAttr('border');
  9363. }
  9364. if (border === '' || border === '0') {
  9365. table.addClass(zeroborder);
  9366. } else {
  9367. table.removeClass(zeroborder);
  9368. }
  9369. if (borderColor !== '') {
  9370. table.attr('borderColor', borderColor);
  9371. } else {
  9372. table.removeAttr('borderColor');
  9373. }
  9374. self.hideDialog().focus();
  9375. self.cmd.range.moveToBookmark(bookmark);
  9376. self.cmd.select();
  9377. self.addBookmark();
  9378. return;
  9379. }
  9380. //insert new table
  9381. var style = '';
  9382. if (width !== '') {
  9383. style += 'width:' + width + widthType + ';';
  9384. }
  9385. if (height !== '') {
  9386. style += 'height:' + height + heightType + ';';
  9387. }
  9388. if (bgColor !== '') {
  9389. style += 'background-color:' + bgColor + ';';
  9390. }
  9391. var html = '<table';
  9392. if (style !== '') {
  9393. html += ' style="' + style + '"';
  9394. }
  9395. if (padding !== '') {
  9396. html += ' cellpadding="' + padding + '"';
  9397. }
  9398. if (spacing !== '') {
  9399. html += ' cellspacing="' + spacing + '"';
  9400. }
  9401. if (align !== '') {
  9402. html += ' align="' + align + '"';
  9403. }
  9404. if (border !== '') {
  9405. html += ' border="' + border + '"';
  9406. }
  9407. if (border === '' || border === '0') {
  9408. html += ' class="' + zeroborder + '"';
  9409. }
  9410. if (borderColor !== '') {
  9411. html += ' bordercolor="' + borderColor + '"';
  9412. }
  9413. html += '>';
  9414. for (var i = 0; i < rows; i++) {
  9415. html += '<tr>';
  9416. for (var j = 0; j < cols; j++) {
  9417. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9418. }
  9419. html += '</tr>';
  9420. }
  9421. html += '</table>';
  9422. if (!K.IE) {
  9423. html += '<br />';
  9424. }
  9425. self.insertHtml(html);
  9426. self.select().hideDialog().focus();
  9427. self.addBookmark();
  9428. }
  9429. }
  9430. }),
  9431. div = dialog.div,
  9432. rowsBox = K('[name="rows"]', div).val(3),
  9433. colsBox = K('[name="cols"]', div).val(2),
  9434. widthBox = K('[name="width"]', div).val(100),
  9435. heightBox = K('[name="height"]', div),
  9436. widthTypeBox = K('[name="widthType"]', div),
  9437. heightTypeBox = K('[name="heightType"]', div),
  9438. paddingBox = K('[name="padding"]', div).val(2),
  9439. spacingBox = K('[name="spacing"]', div).val(0),
  9440. alignBox = K('[name="align"]', div),
  9441. borderBox = K('[name="border"]', div).val(1),
  9442. colorBox = K('.ke-input-color', div);
  9443. _initColorPicker(div, colorBox.eq(0));
  9444. _initColorPicker(div, colorBox.eq(1));
  9445. _setColor(colorBox.eq(0), '#000000');
  9446. _setColor(colorBox.eq(1), '');
  9447. // foucs and select
  9448. rowsBox[0].focus();
  9449. rowsBox[0].select();
  9450. var table;
  9451. if (isInsert) {
  9452. return;
  9453. }
  9454. //get selected table node
  9455. table = self.plugin.getSelectedTable();
  9456. if (table) {
  9457. rowsBox.val(table[0].rows.length);
  9458. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9459. rowsBox.attr('disabled', true);
  9460. colsBox.attr('disabled', true);
  9461. var match,
  9462. tableWidth = table[0].style.width || table[0].width,
  9463. tableHeight = table[0].style.height || table[0].height;
  9464. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9465. widthBox.val(match[1]);
  9466. widthTypeBox.val(match[2]);
  9467. } else {
  9468. widthBox.val('');
  9469. }
  9470. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9471. heightBox.val(match[1]);
  9472. heightTypeBox.val(match[2]);
  9473. }
  9474. paddingBox.val(table[0].cellPadding || '');
  9475. spacingBox.val(table[0].cellSpacing || '');
  9476. alignBox.val(table[0].align || '');
  9477. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9478. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9479. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9480. widthBox[0].focus();
  9481. widthBox[0].select();
  9482. }
  9483. },
  9484. //modify cell
  9485. cellprop : function() {
  9486. var html = [
  9487. '<div style="padding:20px;">',
  9488. //width, height
  9489. '<div class="ke-dialog-row">',
  9490. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9491. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9492. '<select name="widthType">',
  9493. '<option value="%">' + lang.percent + '</option>',
  9494. '<option value="px">' + lang.px + '</option>',
  9495. '</select> &nbsp; ',
  9496. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9497. '<select name="heightType">',
  9498. '<option value="%">' + lang.percent + '</option>',
  9499. '<option value="px">' + lang.px + '</option>',
  9500. '</select>',
  9501. '</div>',
  9502. //align
  9503. '<div class="ke-dialog-row">',
  9504. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9505. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9506. '<option value="">' + lang.alignDefault + '</option>',
  9507. '<option value="left">' + lang.alignLeft + '</option>',
  9508. '<option value="center">' + lang.alignCenter + '</option>',
  9509. '<option value="right">' + lang.alignRight + '</option>',
  9510. '</select> ',
  9511. lang.verticalAlign + ' <select name="verticalAlign">',
  9512. '<option value="">' + lang.alignDefault + '</option>',
  9513. '<option value="top">' + lang.alignTop + '</option>',
  9514. '<option value="middle">' + lang.alignMiddle + '</option>',
  9515. '<option value="bottom">' + lang.alignBottom + '</option>',
  9516. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9517. '</select>',
  9518. '</div>',
  9519. //border
  9520. '<div class="ke-dialog-row">',
  9521. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9522. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9523. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9524. '</div>',
  9525. //background color
  9526. '<div class="ke-dialog-row">',
  9527. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9528. '<span class="ke-inline-block ke-input-color"></span>',
  9529. '</div>',
  9530. '</div>'
  9531. ].join('');
  9532. var bookmark = self.cmd.range.createBookmark();
  9533. var dialog = self.createDialog({
  9534. name : name,
  9535. width : 500,
  9536. title : self.lang('tablecell'),
  9537. body : html,
  9538. beforeRemove : function() {
  9539. colorBox.unbind();
  9540. },
  9541. yesBtn : {
  9542. name : self.lang('yes'),
  9543. click : function(e) {
  9544. var width = widthBox.val(),
  9545. height = heightBox.val(),
  9546. widthType = widthTypeBox.val(),
  9547. heightType = heightTypeBox.val(),
  9548. padding = paddingBox.val(),
  9549. spacing = spacingBox.val(),
  9550. textAlign = textAlignBox.val(),
  9551. verticalAlign = verticalAlignBox.val(),
  9552. border = borderBox.val(),
  9553. borderColor = K(colorBox[0]).html() || '',
  9554. bgColor = K(colorBox[1]).html() || '';
  9555. if (!/^\d*$/.test(width)) {
  9556. alert(self.lang('invalidWidth'));
  9557. widthBox[0].focus();
  9558. return;
  9559. }
  9560. if (!/^\d*$/.test(height)) {
  9561. alert(self.lang('invalidHeight'));
  9562. heightBox[0].focus();
  9563. return;
  9564. }
  9565. if (!/^\d*$/.test(border)) {
  9566. alert(self.lang('invalidBorder'));
  9567. borderBox[0].focus();
  9568. return;
  9569. }
  9570. cell.css({
  9571. width : width !== '' ? (width + widthType) : '',
  9572. height : height !== '' ? (height + heightType) : '',
  9573. 'background-color' : bgColor,
  9574. 'text-align' : textAlign,
  9575. 'vertical-align' : verticalAlign,
  9576. 'border-width' : border,
  9577. 'border-style' : border !== '' ? 'solid' : '',
  9578. 'border-color' : borderColor
  9579. });
  9580. self.hideDialog().focus();
  9581. self.cmd.range.moveToBookmark(bookmark);
  9582. self.cmd.select();
  9583. self.addBookmark();
  9584. }
  9585. }
  9586. }),
  9587. div = dialog.div,
  9588. widthBox = K('[name="width"]', div).val(100),
  9589. heightBox = K('[name="height"]', div),
  9590. widthTypeBox = K('[name="widthType"]', div),
  9591. heightTypeBox = K('[name="heightType"]', div),
  9592. paddingBox = K('[name="padding"]', div).val(2),
  9593. spacingBox = K('[name="spacing"]', div).val(0),
  9594. textAlignBox = K('[name="textAlign"]', div),
  9595. verticalAlignBox = K('[name="verticalAlign"]', div),
  9596. borderBox = K('[name="border"]', div).val(1),
  9597. colorBox = K('.ke-input-color', div);
  9598. _initColorPicker(div, colorBox.eq(0));
  9599. _initColorPicker(div, colorBox.eq(1));
  9600. _setColor(colorBox.eq(0), '#000000');
  9601. _setColor(colorBox.eq(1), '');
  9602. // foucs and select
  9603. widthBox[0].focus();
  9604. widthBox[0].select();
  9605. // get selected cell
  9606. var cell = self.plugin.getSelectedCell();
  9607. var match,
  9608. cellWidth = cell[0].style.width || cell[0].width || '',
  9609. cellHeight = cell[0].style.height || cell[0].height || '';
  9610. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9611. widthBox.val(match[1]);
  9612. widthTypeBox.val(match[2]);
  9613. } else {
  9614. widthBox.val('');
  9615. }
  9616. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9617. heightBox.val(match[1]);
  9618. heightTypeBox.val(match[2]);
  9619. }
  9620. textAlignBox.val(cell[0].style.textAlign || '');
  9621. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9622. var border = cell[0].style.borderWidth || '';
  9623. if (border) {
  9624. border = parseInt(border);
  9625. }
  9626. borderBox.val(border);
  9627. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9628. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9629. widthBox[0].focus();
  9630. widthBox[0].select();
  9631. },
  9632. insert : function() {
  9633. this.prop(true);
  9634. },
  9635. 'delete' : function() {
  9636. var table = self.plugin.getSelectedTable();
  9637. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9638. self.cmd.select();
  9639. table.remove();
  9640. self.addBookmark();
  9641. },
  9642. colinsert : function(offset) {
  9643. var table = self.plugin.getSelectedTable()[0],
  9644. row = self.plugin.getSelectedRow()[0],
  9645. cell = self.plugin.getSelectedCell()[0],
  9646. index = cell.cellIndex + offset;
  9647. // 取得第一行的index
  9648. index += table.rows[0].cells.length - row.cells.length;
  9649. for (var i = 0, len = table.rows.length; i < len; i++) {
  9650. var newRow = table.rows[i],
  9651. newCell = newRow.insertCell(index);
  9652. newCell.innerHTML = K.IE ? '' : '<br />';
  9653. // 调整下一行的单元格index
  9654. index = _getCellIndex(table, newRow, newCell);
  9655. }
  9656. self.cmd.range.selectNodeContents(cell).collapse(true);
  9657. self.cmd.select();
  9658. self.addBookmark();
  9659. },
  9660. colinsertleft : function() {
  9661. this.colinsert(0);
  9662. },
  9663. colinsertright : function() {
  9664. this.colinsert(1);
  9665. },
  9666. rowinsert : function(offset) {
  9667. var table = self.plugin.getSelectedTable()[0],
  9668. row = self.plugin.getSelectedRow()[0],
  9669. cell = self.plugin.getSelectedCell()[0];
  9670. var rowIndex = row.rowIndex;
  9671. if (offset === 1) {
  9672. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9673. }
  9674. var newRow = table.insertRow(rowIndex);
  9675. for (var i = 0, len = row.cells.length; i < len; i++) {
  9676. // 调整cell个数
  9677. if (row.cells[i].rowSpan > 1) {
  9678. len -= row.cells[i].rowSpan - 1;
  9679. }
  9680. var newCell = newRow.insertCell(i);
  9681. // copy colspan
  9682. if (offset === 1 && row.cells[i].colSpan > 1) {
  9683. newCell.colSpan = row.cells[i].colSpan;
  9684. }
  9685. newCell.innerHTML = K.IE ? '' : '<br />';
  9686. }
  9687. // 调整rowspan
  9688. for (var j = rowIndex; j >= 0; j--) {
  9689. var cells = table.rows[j].cells;
  9690. if (cells.length > i) {
  9691. for (var k = cell.cellIndex; k >= 0; k--) {
  9692. if (cells[k].rowSpan > 1) {
  9693. cells[k].rowSpan += 1;
  9694. }
  9695. }
  9696. break;
  9697. }
  9698. }
  9699. self.cmd.range.selectNodeContents(cell).collapse(true);
  9700. self.cmd.select();
  9701. self.addBookmark();
  9702. },
  9703. rowinsertabove : function() {
  9704. this.rowinsert(0);
  9705. },
  9706. rowinsertbelow : function() {
  9707. this.rowinsert(1);
  9708. },
  9709. rowmerge : function() {
  9710. var table = self.plugin.getSelectedTable()[0],
  9711. row = self.plugin.getSelectedRow()[0],
  9712. cell = self.plugin.getSelectedCell()[0],
  9713. rowIndex = row.rowIndex, // 当前行的index
  9714. nextRowIndex = rowIndex + cell.rowSpan, // 下一行的index
  9715. nextRow = table.rows[nextRowIndex]; // 下一行
  9716. // 最后一行不能合并
  9717. if (table.rows.length <= nextRowIndex) {
  9718. return;
  9719. }
  9720. var cellIndex = cell.cellIndex; // 下一行单元格的index
  9721. if (nextRow.cells.length <= cellIndex) {
  9722. return;
  9723. }
  9724. var nextCell = nextRow.cells[cellIndex]; // 下一行单元格
  9725. // 上下行的colspan不一致时不能合并
  9726. if (cell.colSpan !== nextCell.colSpan) {
  9727. return;
  9728. }
  9729. cell.rowSpan += nextCell.rowSpan;
  9730. nextRow.deleteCell(cellIndex);
  9731. self.cmd.range.selectNodeContents(cell).collapse(true);
  9732. self.cmd.select();
  9733. self.addBookmark();
  9734. },
  9735. colmerge : function() {
  9736. var table = self.plugin.getSelectedTable()[0],
  9737. row = self.plugin.getSelectedRow()[0],
  9738. cell = self.plugin.getSelectedCell()[0],
  9739. rowIndex = row.rowIndex, // 当前行的index
  9740. cellIndex = cell.cellIndex,
  9741. nextCellIndex = cellIndex + 1;
  9742. // 最后一列不能合并
  9743. if (row.cells.length <= nextCellIndex) {
  9744. return;
  9745. }
  9746. var nextCell = row.cells[nextCellIndex];
  9747. // 左右列的rowspan不一致时不能合并
  9748. if (cell.rowSpan !== nextCell.rowSpan) {
  9749. return;
  9750. }
  9751. cell.colSpan += nextCell.colSpan;
  9752. row.deleteCell(nextCellIndex);
  9753. self.cmd.range.selectNodeContents(cell).collapse(true);
  9754. self.cmd.select();
  9755. self.addBookmark();
  9756. },
  9757. rowsplit : function() {
  9758. var table = self.plugin.getSelectedTable()[0],
  9759. row = self.plugin.getSelectedRow()[0],
  9760. cell = self.plugin.getSelectedCell()[0],
  9761. rowIndex = row.rowIndex;
  9762. // 不是可分割单元格
  9763. if (cell.rowSpan === 1) {
  9764. return;
  9765. }
  9766. var cellIndex = _getCellIndex(table, row, cell);
  9767. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9768. var newRow = table.rows[rowIndex + i],
  9769. newCell = newRow.insertCell(cellIndex);
  9770. if (cell.colSpan > 1) {
  9771. newCell.colSpan = cell.colSpan;
  9772. }
  9773. newCell.innerHTML = K.IE ? '' : '<br />';
  9774. // 调整下一行的单元格index
  9775. cellIndex = _getCellIndex(table, newRow, newCell);
  9776. }
  9777. K(cell).removeAttr('rowSpan');
  9778. self.cmd.range.selectNodeContents(cell).collapse(true);
  9779. self.cmd.select();
  9780. self.addBookmark();
  9781. },
  9782. colsplit : function() {
  9783. var table = self.plugin.getSelectedTable()[0],
  9784. row = self.plugin.getSelectedRow()[0],
  9785. cell = self.plugin.getSelectedCell()[0],
  9786. cellIndex = cell.cellIndex;
  9787. // 不是可分割单元格
  9788. if (cell.colSpan === 1) {
  9789. return;
  9790. }
  9791. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9792. var newCell = row.insertCell(cellIndex + i);
  9793. if (cell.rowSpan > 1) {
  9794. newCell.rowSpan = cell.rowSpan;
  9795. }
  9796. newCell.innerHTML = K.IE ? '' : '<br />';
  9797. }
  9798. K(cell).removeAttr('colSpan');
  9799. self.cmd.range.selectNodeContents(cell).collapse(true);
  9800. self.cmd.select();
  9801. self.addBookmark();
  9802. },
  9803. coldelete : function() {
  9804. var table = self.plugin.getSelectedTable()[0],
  9805. row = self.plugin.getSelectedRow()[0],
  9806. cell = self.plugin.getSelectedCell()[0],
  9807. index = cell.cellIndex;
  9808. for (var i = 0, len = table.rows.length; i < len; i++) {
  9809. var newRow = table.rows[i],
  9810. newCell = newRow.cells[index];
  9811. if (newCell.colSpan > 1) {
  9812. newCell.colSpan -= 1;
  9813. if (newCell.colSpan === 1) {
  9814. K(newCell).removeAttr('colSpan');
  9815. }
  9816. } else {
  9817. newRow.deleteCell(index);
  9818. }
  9819. // 跳过不需要删除的行
  9820. if (newCell.rowSpan > 1) {
  9821. i += newCell.rowSpan - 1;
  9822. }
  9823. }
  9824. if (row.cells.length === 0) {
  9825. self.cmd.range.setStartBefore(table).collapse(true);
  9826. self.cmd.select();
  9827. K(table).remove();
  9828. } else {
  9829. self.cmd.selection(true);
  9830. }
  9831. self.addBookmark();
  9832. },
  9833. rowdelete : function() {
  9834. var table = self.plugin.getSelectedTable()[0],
  9835. row = self.plugin.getSelectedRow()[0],
  9836. cell = self.plugin.getSelectedCell()[0],
  9837. rowIndex = row.rowIndex;
  9838. // 从下到上删除
  9839. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9840. table.deleteRow(rowIndex + i);
  9841. }
  9842. if (table.rows.length === 0) {
  9843. self.cmd.range.setStartBefore(table).collapse(true);
  9844. self.cmd.select();
  9845. K(table).remove();
  9846. } else {
  9847. self.cmd.selection(true);
  9848. }
  9849. self.addBookmark();
  9850. }
  9851. };
  9852. self.clickToolbar(name, self.plugin.table.prop);
  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('template', function(K) {
  9863. var self = this, name = 'template', lang = self.lang(name + '.'),
  9864. htmlPath = self.pluginsPath + name + '/html/';
  9865. function getFilePath(fileName) {
  9866. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9867. }
  9868. self.clickToolbar(name, function() {
  9869. var lang = self.lang(name + '.'),
  9870. arr = ['<div style="padding:10px 20px;">',
  9871. '<div class="ke-header">',
  9872. // left start
  9873. '<div class="ke-left">',
  9874. lang. selectTemplate + ' <select>'];
  9875. K.each(lang.fileList, function(key, val) {
  9876. arr.push('<option value="' + key + '">' + val + '</option>');
  9877. });
  9878. html = [arr.join(''),
  9879. '</select></div>',
  9880. // right start
  9881. '<div class="ke-right">',
  9882. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9883. '</div>',
  9884. '<div class="ke-clearfix"></div>',
  9885. '</div>',
  9886. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9887. '</div>'].join('');
  9888. var dialog = self.createDialog({
  9889. name : name,
  9890. width : 500,
  9891. title : self.lang(name),
  9892. body : html,
  9893. yesBtn : {
  9894. name : self.lang('yes'),
  9895. click : function(e) {
  9896. var doc = K.iframeDoc(iframe);
  9897. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9898. }
  9899. }
  9900. });
  9901. var selectBox = K('select', dialog.div),
  9902. checkbox = K('[name="replaceFlag"]', dialog.div),
  9903. iframe = K('iframe', dialog.div);
  9904. checkbox[0].checked = true;
  9905. iframe.attr('src', getFilePath(selectBox.val()));
  9906. selectBox.change(function() {
  9907. iframe.attr('src', getFilePath(this.value));
  9908. });
  9909. });
  9910. });
  9911. /*******************************************************************************
  9912. * KindEditor - WYSIWYG HTML Editor for Internet
  9913. * Copyright (C) 2006-2011 kindsoft.net
  9914. *
  9915. * @author Roddy <luolonghao@gmail.com>
  9916. * @site http://www.kindsoft.net/
  9917. * @licence http://www.kindsoft.net/license.php
  9918. *******************************************************************************/
  9919. KindEditor.plugin('wordpaste', function(K) {
  9920. var self = this, name = 'wordpaste';
  9921. self.clickToolbar(name, function() {
  9922. var lang = self.lang(name + '.'),
  9923. html = '<div style="padding:10px 20px;">' +
  9924. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9925. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9926. '</div>',
  9927. dialog = self.createDialog({
  9928. name : name,
  9929. width : 450,
  9930. title : self.lang(name),
  9931. body : html,
  9932. yesBtn : {
  9933. name : self.lang('yes'),
  9934. click : function(e) {
  9935. var str = doc.body.innerHTML;
  9936. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9937. self.insertHtml(str).hideDialog().focus();
  9938. }
  9939. }
  9940. }),
  9941. div = dialog.div,
  9942. iframe = K('iframe', div),
  9943. doc = K.iframeDoc(iframe);
  9944. if (!K.IE) {
  9945. doc.designMode = 'on';
  9946. }
  9947. doc.open();
  9948. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9949. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9950. if (!K.IE) {
  9951. doc.write('<br />');
  9952. }
  9953. doc.write('</body></html>');
  9954. doc.close();
  9955. if (K.IE) {
  9956. doc.body.contentEditable = 'true';
  9957. }
  9958. iframe[0].contentWindow.focus();
  9959. });
  9960. });