kindeditor.js 290 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2017 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.12 (2017-04-12)
  9. *******************************************************************************/
  10. // 判断ie有没有安装flash播放器
  11. function IEVersion() {
  12. var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
  13. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE浏览器
  14. if(isIE) {
  15. var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
  16. reIE.test(userAgent);
  17. var fIEVersion = parseFloat(RegExp["$1"]);
  18. if(fIEVersion == 7 || fIEVersion == 8 || fIEVersion == 9){
  19. var hasFlash = false;
  20. try {
  21. hasFlash = Boolean(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'));
  22. } catch(exception) {
  23. hasFlash = ('undefined' != typeof navigator.mimeTypes['application/x-shockwave-flash']);
  24. var r=confirm("您的浏览器不支持上传文件,请安装flash播放器");
  25. if (r==true){
  26. window.open("https://get.adobe.com/tw/flashplayer/");
  27. }
  28. else{
  29. }
  30. }
  31. }
  32. }
  33. };
  34. (function (window, undefined) {
  35. if (window.KindEditor) {
  36. return;
  37. }
  38. if (!window.console) {
  39. window.console = {};
  40. }
  41. if (!console.log) {
  42. console.log = function () {};
  43. }
  44. var _VERSION = '4.1.12 (2017-04-12)',
  45. _ua = navigator.userAgent.toLowerCase(),
  46. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  47. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  48. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  49. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  50. _OPERA = _ua.indexOf('opera') > -1,
  51. _MOBILE = _ua.indexOf('mobile') > -1,
  52. _IOS = /ipad|iphone|ipod/.test(_ua),
  53. _QUIRKS = document.compatMode != 'CSS1Compat',
  54. _IERANGE = !window.getSelection,
  55. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  56. _V = _matches ? _matches[1] : '0',
  57. _TIME = new Date().getTime();
  58. function _isArray(val) {
  59. if (!val) {
  60. return false;
  61. }
  62. return Object.prototype.toString.call(val) === '[object Array]';
  63. }
  64. function _isFunction(val) {
  65. if (!val) {
  66. return false;
  67. }
  68. return Object.prototype.toString.call(val) === '[object Function]';
  69. }
  70. function _inArray(val, arr) {
  71. for (var i = 0, len = arr.length; i < len; i++) {
  72. if (val === arr[i]) {
  73. return i;
  74. }
  75. }
  76. return -1;
  77. }
  78. function _each(obj, fn) {
  79. if (_isArray(obj)) {
  80. for (var i = 0, len = obj.length; i < len; i++) {
  81. if (fn.call(obj[i], i, obj[i]) === false) {
  82. break;
  83. }
  84. }
  85. } else {
  86. for (var key in obj) {
  87. if (obj.hasOwnProperty(key)) {
  88. if (fn.call(obj[key], key, obj[key]) === false) {
  89. break;
  90. }
  91. }
  92. }
  93. }
  94. }
  95. function _trim(str) {
  96. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  97. }
  98. function _inString(val, str, delimiter) {
  99. delimiter = delimiter === undefined ? ',' : delimiter;
  100. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  101. }
  102. function _addUnit(val, unit) {
  103. unit = unit || 'px';
  104. return val && /^-?\d+(?:\.\d+)?$/.test(val) ? val + unit : val;
  105. }
  106. function _removeUnit(val) {
  107. var match;
  108. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  109. }
  110. function _escape(val) {
  111. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  112. }
  113. function _unescape(val) {
  114. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  115. }
  116. function _toCamel(str) {
  117. var arr = str.split('-');
  118. str = '';
  119. _each(arr, function(key, val) {
  120. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  121. });
  122. return str;
  123. }
  124. function _toHex(val) {
  125. function hex(d) {
  126. var s = parseInt(d, 10).toString(16).toUpperCase();
  127. return s.length > 1 ? s : '0' + s;
  128. }
  129. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  130. function($0, $1, $2, $3) {
  131. return '#' + hex($1) + hex($2) + hex($3);
  132. }
  133. );
  134. }
  135. function _toMap(val, delimiter) {
  136. delimiter = delimiter === undefined ? ',' : delimiter;
  137. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  138. _each(arr, function(key, val) {
  139. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  140. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  141. map[i.toString()] = true;
  142. }
  143. } else {
  144. map[val] = true;
  145. }
  146. });
  147. return map;
  148. }
  149. function _toArray(obj, offset) {
  150. return Array.prototype.slice.call(obj, offset || 0);
  151. }
  152. function _undef(val, defaultVal) {
  153. return val === undefined ? defaultVal : val;
  154. }
  155. function _invalidUrl(url) {
  156. return !url || /[<>"]/.test(url);
  157. }
  158. function _addParam(url, param) {
  159. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  160. }
  161. function _extend(child, parent, proto) {
  162. if (!proto) {
  163. proto = parent;
  164. parent = null;
  165. }
  166. var childProto;
  167. if (parent) {
  168. var fn = function () {};
  169. fn.prototype = parent.prototype;
  170. childProto = new fn();
  171. _each(proto, function(key, val) {
  172. childProto[key] = val;
  173. });
  174. } else {
  175. childProto = proto;
  176. }
  177. childProto.constructor = child;
  178. child.prototype = childProto;
  179. child.parent = parent ? parent.prototype : null;
  180. }
  181. function _json(text) {
  182. var match;
  183. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  184. text = match[0];
  185. }
  186. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  187. cx.lastIndex = 0;
  188. if (cx.test(text)) {
  189. text = text.replace(cx, function (a) {
  190. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  191. });
  192. }
  193. if (/^[\],:{}\s]*$/.
  194. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  195. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  196. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  197. return eval('(' + text + ')');
  198. }
  199. throw 'JSON parse error';
  200. }
  201. var _round = Math.round;
  202. var K = {
  203. DEBUG : false,
  204. VERSION : _VERSION,
  205. IE : _IE,
  206. GECKO : _GECKO,
  207. WEBKIT : _WEBKIT,
  208. OPERA : _OPERA,
  209. V : _V,
  210. TIME : _TIME,
  211. each : _each,
  212. isArray : _isArray,
  213. isFunction : _isFunction,
  214. inArray : _inArray,
  215. inString : _inString,
  216. trim : _trim,
  217. addUnit : _addUnit,
  218. removeUnit : _removeUnit,
  219. escape : _escape,
  220. unescape : _unescape,
  221. toCamel : _toCamel,
  222. toHex : _toHex,
  223. toMap : _toMap,
  224. toArray : _toArray,
  225. undef : _undef,
  226. invalidUrl : _invalidUrl,
  227. addParam : _addParam,
  228. extend : _extend,
  229. json : _json
  230. };
  231. 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'),
  232. _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'),
  233. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  234. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  235. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  236. _PRE_TAG_MAP = _toMap('pre,style,script'),
  237. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  238. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  239. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  240. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  241. function _getBasePath() {
  242. var els = document.getElementsByTagName('script'), src;
  243. for (var i = 0, len = els.length; i < len; i++) {
  244. src = els[i].src || '';
  245. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  246. return src.substring(0, src.lastIndexOf('/') + 1);
  247. }
  248. }
  249. return '';
  250. }
  251. K.basePath = _getBasePath();
  252. K.options = {
  253. designMode : true,
  254. fullscreenMode : false,
  255. filterMode : true,
  256. wellFormatMode : true,
  257. shadowMode : true,
  258. loadStyleMode : true,
  259. basePath : K.basePath,
  260. themesPath : K.basePath + 'themes/',
  261. langPath : K.basePath + 'lang/',
  262. pluginsPath : K.basePath + 'plugins/',
  263. themeType : 'default',
  264. langType : 'zh-CN',
  265. urlType : '',
  266. newlineTag : 'p',
  267. resizeType : 2,
  268. syncType : 'form',
  269. pasteType : 2,
  270. dialogAlignType : 'page',
  271. useContextmenu : true,
  272. fullscreenShortcut : false,
  273. bodyClass : 'ke-content',
  274. indentChar : '\t',
  275. cssPath : '',
  276. cssData : '',
  277. minWidth : 650,
  278. minHeight : 100,
  279. minChangeSize : 50,
  280. zIndex : 811213,
  281. items : [
  282. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  283. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  284. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  285. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  286. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  287. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  288. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  289. 'anchor', 'link', 'unlink', '|', 'about'
  290. ],
  291. noDisableItems : ['source', 'fullscreen'],
  292. colorTable : [
  293. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  294. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  295. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  296. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  297. ],
  298. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  299. htmlTags : {
  300. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  301. span : [
  302. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  303. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  304. ],
  305. div : [
  306. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  307. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  308. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  309. ],
  310. table: [
  311. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  312. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  313. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  314. '.width', '.height', '.border-collapse'
  315. ],
  316. 'td,th': [
  317. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  318. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  319. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  320. ],
  321. a : ['id', 'class', 'href', 'target', 'name'],
  322. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  323. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  324. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  325. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  326. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  327. ],
  328. pre : ['id', 'class'],
  329. hr : ['id', 'class', '.page-break-after'],
  330. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  331. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  332. },
  333. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  334. };
  335. var _useCapture = false;
  336. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  337. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  338. var _CHANGE_KEY_MAP = {};
  339. _each(_INPUT_KEY_MAP, function(key, val) {
  340. _CHANGE_KEY_MAP[key] = val;
  341. });
  342. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  343. _CHANGE_KEY_MAP[key] = val;
  344. });
  345. function _bindEvent(el, type, fn) {
  346. if (el.addEventListener){
  347. el.addEventListener(type, fn, _useCapture);
  348. } else if (el.attachEvent){
  349. el.attachEvent('on' + type, fn);
  350. }
  351. }
  352. function _unbindEvent(el, type, fn) {
  353. if (el.removeEventListener){
  354. el.removeEventListener(type, fn, _useCapture);
  355. } else if (el.detachEvent){
  356. el.detachEvent('on' + type, fn);
  357. }
  358. }
  359. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  360. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  361. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  362. function KEvent(el, event) {
  363. this.init(el, event);
  364. }
  365. _extend(KEvent, {
  366. init : function(el, event) {
  367. var self = this, doc = el.ownerDocument || el.document || el;
  368. self.event = event;
  369. _each(_EVENT_PROPS, function(key, val) {
  370. self[val] = event[val];
  371. });
  372. if (!self.target) {
  373. self.target = self.srcElement || doc;
  374. }
  375. if (self.target.nodeType === 3) {
  376. self.target = self.target.parentNode;
  377. }
  378. if (!self.relatedTarget && self.fromElement) {
  379. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  380. }
  381. if (self.pageX == null && self.clientX != null) {
  382. var d = doc.documentElement, body = doc.body;
  383. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  384. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  385. }
  386. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  387. self.which = self.charCode || self.keyCode;
  388. }
  389. if (!self.metaKey && self.ctrlKey) {
  390. self.metaKey = self.ctrlKey;
  391. }
  392. if (!self.which && self.button !== undefined) {
  393. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  394. }
  395. switch (self.which) {
  396. case 186 :
  397. self.which = 59;
  398. break;
  399. case 187 :
  400. case 107 :
  401. case 43 :
  402. self.which = 61;
  403. break;
  404. case 189 :
  405. case 45 :
  406. self.which = 109;
  407. break;
  408. case 42 :
  409. self.which = 106;
  410. break;
  411. case 47 :
  412. self.which = 111;
  413. break;
  414. case 78 :
  415. self.which = 110;
  416. break;
  417. }
  418. if (self.which >= 96 && self.which <= 105) {
  419. self.which -= 48;
  420. }
  421. },
  422. preventDefault : function() {
  423. var ev = this.event;
  424. if (ev.preventDefault) {
  425. ev.preventDefault();
  426. } else {
  427. ev.returnValue = false;
  428. }
  429. },
  430. stopPropagation : function() {
  431. var ev = this.event;
  432. if (ev.stopPropagation) {
  433. ev.stopPropagation();
  434. } else {
  435. ev.cancelBubble = true;
  436. }
  437. },
  438. stop : function() {
  439. this.preventDefault();
  440. this.stopPropagation();
  441. }
  442. });
  443. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  444. function _getId(el) {
  445. return el[_eventExpendo] || null;
  446. }
  447. function _setId(el) {
  448. el[_eventExpendo] = ++_eventId;
  449. return _eventId;
  450. }
  451. function _removeId(el) {
  452. try {
  453. delete el[_eventExpendo];
  454. } catch(e) {
  455. if (el.removeAttribute) {
  456. el.removeAttribute(_eventExpendo);
  457. }
  458. }
  459. }
  460. function _bind(el, type, fn) {
  461. if (type.indexOf(',') >= 0) {
  462. _each(type.split(','), function() {
  463. _bind(el, this, fn);
  464. });
  465. return;
  466. }
  467. var id = _getId(el);
  468. if (!id) {
  469. id = _setId(el);
  470. }
  471. if (_eventData[id] === undefined) {
  472. _eventData[id] = {};
  473. }
  474. var events = _eventData[id][type];
  475. if (events && events.length > 0) {
  476. _unbindEvent(el, type, events[0]);
  477. } else {
  478. _eventData[id][type] = [];
  479. _eventData[id].el = el;
  480. }
  481. events = _eventData[id][type];
  482. if (events.length === 0) {
  483. events[0] = function(e) {
  484. var kevent = e ? new KEvent(el, e) : undefined;
  485. _each(events, function(i, event) {
  486. if (i > 0 && event) {
  487. event.call(el, kevent);
  488. }
  489. });
  490. };
  491. }
  492. if (_inArray(fn, events) < 0) {
  493. events.push(fn);
  494. }
  495. _bindEvent(el, type, events[0]);
  496. }
  497. function _unbind(el, type, fn) {
  498. if (type && type.indexOf(',') >= 0) {
  499. _each(type.split(','), function() {
  500. _unbind(el, this, fn);
  501. });
  502. return;
  503. }
  504. var id = _getId(el);
  505. if (!id) {
  506. return;
  507. }
  508. if (type === undefined) {
  509. if (id in _eventData) {
  510. _each(_eventData[id], function(key, events) {
  511. if (key != 'el' && events.length > 0) {
  512. _unbindEvent(el, key, events[0]);
  513. }
  514. });
  515. delete _eventData[id];
  516. _removeId(el);
  517. }
  518. return;
  519. }
  520. if (!_eventData[id]) {
  521. return;
  522. }
  523. var events = _eventData[id][type];
  524. if (events && events.length > 0) {
  525. if (fn === undefined) {
  526. _unbindEvent(el, type, events[0]);
  527. delete _eventData[id][type];
  528. } else {
  529. _each(events, function(i, event) {
  530. if (i > 0 && event === fn) {
  531. events.splice(i, 1);
  532. }
  533. });
  534. if (events.length == 1) {
  535. _unbindEvent(el, type, events[0]);
  536. delete _eventData[id][type];
  537. }
  538. }
  539. var count = 0;
  540. _each(_eventData[id], function() {
  541. count++;
  542. });
  543. if (count < 2) {
  544. delete _eventData[id];
  545. _removeId(el);
  546. }
  547. }
  548. }
  549. function _fire(el, type) {
  550. if (type.indexOf(',') >= 0) {
  551. _each(type.split(','), function() {
  552. _fire(el, this);
  553. });
  554. return;
  555. }
  556. var id = _getId(el);
  557. if (!id) {
  558. return;
  559. }
  560. var events = _eventData[id][type];
  561. if (_eventData[id] && events && events.length > 0) {
  562. events[0]();
  563. }
  564. }
  565. function _ctrl(el, key, fn) {
  566. var self = this;
  567. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  568. _bind(el, 'keydown', function(e) {
  569. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  570. fn.call(el);
  571. e.stop();
  572. }
  573. });
  574. }
  575. var _readyFinished = false;
  576. function _ready(fn) {
  577. if (_readyFinished) {
  578. fn(KindEditor);
  579. return;
  580. }
  581. var loaded = false;
  582. function readyFunc() {
  583. if (!loaded) {
  584. loaded = true;
  585. fn(KindEditor);
  586. _readyFinished = true;
  587. }
  588. }
  589. function ieReadyFunc() {
  590. if (!loaded) {
  591. try {
  592. document.documentElement.doScroll('left');
  593. } catch(e) {
  594. setTimeout(ieReadyFunc, 100);
  595. return;
  596. }
  597. readyFunc();
  598. }
  599. }
  600. function ieReadyStateFunc() {
  601. if (document.readyState === 'complete') {
  602. readyFunc();
  603. }
  604. }
  605. if (document.addEventListener) {
  606. _bind(document, 'DOMContentLoaded', readyFunc);
  607. } else if (document.attachEvent) {
  608. _bind(document, 'readystatechange', ieReadyStateFunc);
  609. var toplevel = false;
  610. try {
  611. toplevel = window.frameElement == null;
  612. } catch(e) {}
  613. if (document.documentElement.doScroll && toplevel) {
  614. ieReadyFunc();
  615. }
  616. }
  617. _bind(window, 'load', readyFunc);
  618. }
  619. if (window.attachEvent) {
  620. window.attachEvent('onunload', function() {
  621. _each(_eventData, function(key, events) {
  622. if (events.el) {
  623. _unbind(events.el);
  624. }
  625. });
  626. });
  627. }
  628. K.ctrl = _ctrl;
  629. K.ready = _ready;
  630. function _getCssList(css) {
  631. css = css.replace(/&quot;/g, '"');
  632. var list = {},
  633. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  634. match;
  635. while ((match = reg.exec(css))) {
  636. var key = _trim(match[1].toLowerCase()),
  637. val = _trim(_toHex(match[2]));
  638. list[key] = val;
  639. }
  640. return list;
  641. }
  642. function _getAttrList(tag) {
  643. var list = {},
  644. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  645. match;
  646. while ((match = reg.exec(tag))) {
  647. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  648. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  649. list[key] = val;
  650. }
  651. return list;
  652. }
  653. function _addClassToTag(tag, className) {
  654. if (/\s+class\s*=/.test(tag)) {
  655. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  656. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  657. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  658. } else {
  659. return $0;
  660. }
  661. });
  662. } else {
  663. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  664. }
  665. return tag;
  666. }
  667. function _formatCss(css) {
  668. var str = '';
  669. _each(_getCssList(css), function(key, val) {
  670. str += key + ':' + val + ';';
  671. });
  672. return str;
  673. }
  674. function _formatUrl(url, mode, host, pathname) {
  675. mode = _undef(mode, '').toLowerCase();
  676. if (url.substr(0, 5) != 'data:') {
  677. url = url.replace(/([^:])\/\//g, '$1/');
  678. }
  679. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  680. return url;
  681. }
  682. host = host || location.protocol + '//' + location.host;
  683. if (pathname === undefined) {
  684. var m = location.pathname.match(/^(\/.*)\//);
  685. pathname = m ? m[1] : '';
  686. }
  687. var match;
  688. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  689. if (match[1] !== host) {
  690. return url;
  691. }
  692. } else if (/^\w+:/.test(url)) {
  693. return url;
  694. }
  695. function getRealPath(path) {
  696. var parts = path.split('/'), paths = [];
  697. for (var i = 0, len = parts.length; i < len; i++) {
  698. var part = parts[i];
  699. if (part == '..') {
  700. if (paths.length > 0) {
  701. paths.pop();
  702. }
  703. } else if (part !== '' && part != '.') {
  704. paths.push(part);
  705. }
  706. }
  707. return '/' + paths.join('/');
  708. }
  709. if (/^\//.test(url)) {
  710. url = host + getRealPath(url.substr(1));
  711. } else if (!/^\w+:\/\//.test(url)) {
  712. url = host + getRealPath(pathname + '/' + url);
  713. }
  714. function getRelativePath(path, depth) {
  715. if (url.substr(0, path.length) === path) {
  716. var arr = [];
  717. for (var i = 0; i < depth; i++) {
  718. arr.push('..');
  719. }
  720. var prefix = '.';
  721. if (arr.length > 0) {
  722. prefix += '/' + arr.join('/');
  723. }
  724. if (pathname == '/') {
  725. prefix += '/';
  726. }
  727. return prefix + url.substr(path.length);
  728. } else {
  729. if ((match = /^(.*)\//.exec(path))) {
  730. return getRelativePath(match[1], ++depth);
  731. }
  732. }
  733. }
  734. if (mode === 'relative') {
  735. url = getRelativePath(host + pathname, 0).substr(2);
  736. } else if (mode === 'absolute') {
  737. if (url.substr(0, host.length) === host) {
  738. url = url.substr(host.length);
  739. }
  740. }
  741. return url;
  742. }
  743. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  744. if (html == null) {
  745. html = '';
  746. }
  747. urlType = urlType || '';
  748. wellFormatted = _undef(wellFormatted, false);
  749. indentChar = _undef(indentChar, '\t');
  750. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  751. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  752. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  753. });
  754. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  755. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  756. html = html.replace(/\u200B/g, '');
  757. html = html.replace(/\u00A9/g, '&copy;');
  758. html = html.replace(/\u00AE/g, '&reg;');
  759. html = html.replace(/\u2003/g, '&emsp;');
  760. html = html.replace(/\u3000/g, '&emsp;');
  761. html = html.replace(/<[^>]+/g, function($0) {
  762. return $0.replace(/\s+/g, ' ');
  763. });
  764. var htmlTagMap = {};
  765. if (htmlTags) {
  766. _each(htmlTags, function(key, val) {
  767. var arr = key.split(',');
  768. for (var i = 0, len = arr.length; i < len; i++) {
  769. htmlTagMap[arr[i]] = _toMap(val);
  770. }
  771. });
  772. if (!htmlTagMap.script) {
  773. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  774. }
  775. if (!htmlTagMap.style) {
  776. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  777. }
  778. }
  779. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  780. var tagStack = [];
  781. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  782. var full = $0,
  783. startNewline = $1 || '',
  784. startSlash = $2 || '',
  785. tagName = $3.toLowerCase(),
  786. attr = $4 || '',
  787. endSlash = $5 ? ' ' + $5 : '',
  788. endNewline = $6 || '';
  789. if (htmlTags && !htmlTagMap[tagName]) {
  790. return '';
  791. }
  792. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  793. endSlash = ' /';
  794. }
  795. if (_INLINE_TAG_MAP[tagName]) {
  796. if (startNewline) {
  797. startNewline = ' ';
  798. }
  799. if (endNewline) {
  800. endNewline = ' ';
  801. }
  802. }
  803. if (_PRE_TAG_MAP[tagName]) {
  804. if (startSlash) {
  805. endNewline = '\n';
  806. } else {
  807. startNewline = '\n';
  808. }
  809. }
  810. if (wellFormatted && tagName == 'br') {
  811. endNewline = '\n';
  812. }
  813. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  814. if (wellFormatted) {
  815. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  816. tagStack.pop();
  817. } else {
  818. tagStack.push(tagName);
  819. }
  820. startNewline = '\n';
  821. endNewline = '\n';
  822. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  823. startNewline += indentChar;
  824. if (!startSlash) {
  825. endNewline += indentChar;
  826. }
  827. }
  828. if (endSlash) {
  829. tagStack.pop();
  830. } else if (!startSlash) {
  831. endNewline += indentChar;
  832. }
  833. } else {
  834. startNewline = endNewline = '';
  835. }
  836. }
  837. if (attr !== '') {
  838. var attrMap = _getAttrList(full);
  839. if (tagName === 'font') {
  840. var fontStyleMap = {}, fontStyle = '';
  841. _each(attrMap, function(key, val) {
  842. if (key === 'color') {
  843. fontStyleMap.color = val;
  844. delete attrMap[key];
  845. }
  846. if (key === 'size') {
  847. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  848. delete attrMap[key];
  849. }
  850. if (key === 'face') {
  851. fontStyleMap['font-family'] = val;
  852. delete attrMap[key];
  853. }
  854. if (key === 'style') {
  855. fontStyle = val;
  856. }
  857. });
  858. if (fontStyle && !/;$/.test(fontStyle)) {
  859. fontStyle += ';';
  860. }
  861. _each(fontStyleMap, function(key, val) {
  862. if (val === '') {
  863. return;
  864. }
  865. if (/\s/.test(val)) {
  866. val = "'" + val + "'";
  867. }
  868. fontStyle += key + ':' + val + ';';
  869. });
  870. attrMap.style = fontStyle;
  871. }
  872. _each(attrMap, function(key, val) {
  873. if (_FILL_ATTR_MAP[key]) {
  874. attrMap[key] = key;
  875. }
  876. if (_inArray(key, ['src', 'href']) >= 0) {
  877. attrMap[key] = _formatUrl(val, urlType);
  878. }
  879. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  880. tagName === 'body' && key === 'contenteditable' ||
  881. /^kindeditor_\d+$/.test(key)) {
  882. delete attrMap[key];
  883. }
  884. if (key === 'style' && val !== '') {
  885. var styleMap = _getCssList(val);
  886. _each(styleMap, function(k, v) {
  887. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  888. delete styleMap[k];
  889. }
  890. });
  891. var style = '';
  892. _each(styleMap, function(k, v) {
  893. style += k + ':' + v + ';';
  894. });
  895. attrMap.style = style;
  896. }
  897. });
  898. attr = '';
  899. _each(attrMap, function(key, val) {
  900. if (key === 'style' && val === '') {
  901. return;
  902. }
  903. val = val.replace(/"/g, '&quot;');
  904. attr += ' ' + key + '="' + val + '"';
  905. });
  906. }
  907. if (tagName === 'font') {
  908. tagName = 'span';
  909. }
  910. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  911. });
  912. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  913. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  914. });
  915. html = html.replace(/\n\s*\n/g, '\n');
  916. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  917. return _trim(html);
  918. }
  919. function _clearMsWord(html, htmlTags) {
  920. html = html.replace(/<meta[\s\S]*?>/ig, '')
  921. .replace(/<![\s\S]*?>/ig, '')
  922. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  923. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  924. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  925. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  926. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  927. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  928. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  929. });
  930. return _formatHtml(html, htmlTags);
  931. }
  932. function _mediaType(src) {
  933. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  934. return 'audio/x-pn-realaudio-plugin';
  935. }
  936. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  937. return 'application/x-shockwave-flash';
  938. }
  939. return 'video/x-ms-asf-plugin';
  940. }
  941. function _mediaClass(type) {
  942. if (/realaudio/i.test(type)) {
  943. return 'ke-rm';
  944. }
  945. if (/flash/i.test(type)) {
  946. return 'ke-flash';
  947. }
  948. return 'ke-media';
  949. }
  950. function _mediaAttrs(srcTag) {
  951. return _getAttrList(unescape(srcTag));
  952. }
  953. function _mediaEmbed(attrs) {
  954. var html = '<embed ';
  955. _each(attrs, function(key, val) {
  956. html += key + '="' + val + '" ';
  957. });
  958. html += '/>';
  959. return html;
  960. }
  961. function _mediaImg(blankPath, attrs) {
  962. var width = attrs.width,
  963. height = attrs.height,
  964. type = attrs.type || _mediaType(attrs.src),
  965. srcTag = _mediaEmbed(attrs),
  966. style = '';
  967. if (/\D/.test(width)) {
  968. style += 'width:' + width + ';';
  969. } else if (width > 0) {
  970. style += 'width:' + width + 'px;';
  971. }
  972. if (/\D/.test(height)) {
  973. style += 'height:' + height + ';';
  974. } else if (height > 0) {
  975. style += 'height:' + height + 'px;';
  976. }
  977. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  978. if (style !== '') {
  979. html += 'style="' + style + '" ';
  980. }
  981. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  982. return html;
  983. }
  984. function _tmpl(str, data) {
  985. var fn = new Function("obj",
  986. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  987. "with(obj){p.push('" +
  988. str.replace(/[\r\t\n]/g, " ")
  989. .split("<%").join("\t")
  990. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  991. .replace(/\t=(.*?)%>/g, "',$1,'")
  992. .split("\t").join("');")
  993. .split("%>").join("p.push('")
  994. .split("\r").join("\\'") + "');}return p.join('');");
  995. return data ? fn(data) : fn;
  996. }
  997. K.formatUrl = _formatUrl;
  998. K.formatHtml = _formatHtml;
  999. K.getCssList = _getCssList;
  1000. K.getAttrList = _getAttrList;
  1001. K.mediaType = _mediaType;
  1002. K.mediaAttrs = _mediaAttrs;
  1003. K.mediaEmbed = _mediaEmbed;
  1004. K.mediaImg = _mediaImg;
  1005. K.clearMsWord = _clearMsWord;
  1006. K.tmpl = _tmpl;
  1007. function _contains(nodeA, nodeB) {
  1008. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  1009. return true;
  1010. }
  1011. while ((nodeB = nodeB.parentNode)) {
  1012. if (nodeB == nodeA) {
  1013. return true;
  1014. }
  1015. }
  1016. return false;
  1017. }
  1018. var _getSetAttrDiv = document.createElement('div');
  1019. _getSetAttrDiv.setAttribute('className', 't');
  1020. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1021. function _getAttr(el, key) {
  1022. key = key.toLowerCase();
  1023. var val = null;
  1024. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1025. var div = el.ownerDocument.createElement('div');
  1026. div.appendChild(el.cloneNode(false));
  1027. var list = _getAttrList(_unescape(div.innerHTML));
  1028. if (key in list) {
  1029. val = list[key];
  1030. }
  1031. } else {
  1032. try {
  1033. val = el.getAttribute(key, 2);
  1034. } catch(e) {
  1035. val = el.getAttribute(key, 1);
  1036. }
  1037. }
  1038. if (key === 'style' && val !== null) {
  1039. val = _formatCss(val);
  1040. }
  1041. return val;
  1042. }
  1043. function _queryAll(expr, root) {
  1044. var exprList = expr.split(',');
  1045. if (exprList.length > 1) {
  1046. var mergedResults = [];
  1047. _each(exprList, function() {
  1048. _each(_queryAll(this, root), function() {
  1049. if (_inArray(this, mergedResults) < 0) {
  1050. mergedResults.push(this);
  1051. }
  1052. });
  1053. });
  1054. return mergedResults;
  1055. }
  1056. root = root || document;
  1057. function escape(str) {
  1058. if (typeof str != 'string') {
  1059. return str;
  1060. }
  1061. return str.replace(/([^\w\-])/g, '\\$1');
  1062. }
  1063. function stripslashes(str) {
  1064. return str.replace(/\\/g, '');
  1065. }
  1066. function cmpTag(tagA, tagB) {
  1067. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1068. }
  1069. function byId(id, tag, root) {
  1070. var arr = [],
  1071. doc = root.ownerDocument || root,
  1072. el = doc.getElementById(stripslashes(id));
  1073. if (el) {
  1074. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1075. arr.push(el);
  1076. }
  1077. }
  1078. return arr;
  1079. }
  1080. function byClass(className, tag, root) {
  1081. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1082. if (root.getElementsByClassName) {
  1083. els = root.getElementsByClassName(stripslashes(className));
  1084. for (i = 0, len = els.length; i < len; i++) {
  1085. el = els[i];
  1086. if (cmpTag(tag, el.nodeName)) {
  1087. arr.push(el);
  1088. }
  1089. }
  1090. } else if (doc.querySelectorAll) {
  1091. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1092. for (i = 0, len = els.length; i < len; i++) {
  1093. el = els[i];
  1094. if (_contains(root, el)) {
  1095. arr.push(el);
  1096. }
  1097. }
  1098. } else {
  1099. els = root.getElementsByTagName(tag);
  1100. className = ' ' + className + ' ';
  1101. for (i = 0, len = els.length; i < len; i++) {
  1102. el = els[i];
  1103. if (el.nodeType == 1) {
  1104. var cls = el.className;
  1105. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1106. arr.push(el);
  1107. }
  1108. }
  1109. }
  1110. }
  1111. return arr;
  1112. }
  1113. function byName(name, tag, root) {
  1114. var arr = [], doc = root.ownerDocument || root,
  1115. els = doc.getElementsByName(stripslashes(name)), el;
  1116. for (var i = 0, len = els.length; i < len; i++) {
  1117. el = els[i];
  1118. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1119. if (el.getAttribute('name') !== null) {
  1120. arr.push(el);
  1121. }
  1122. }
  1123. }
  1124. return arr;
  1125. }
  1126. function byAttr(key, val, tag, root) {
  1127. var arr = [], els = root.getElementsByTagName(tag), el;
  1128. for (var i = 0, len = els.length; i < len; i++) {
  1129. el = els[i];
  1130. if (el.nodeType == 1) {
  1131. if (val === null) {
  1132. if (_getAttr(el, key) !== null) {
  1133. arr.push(el);
  1134. }
  1135. } else {
  1136. if (val === escape(_getAttr(el, key))) {
  1137. arr.push(el);
  1138. }
  1139. }
  1140. }
  1141. }
  1142. return arr;
  1143. }
  1144. function select(expr, root) {
  1145. var arr = [], matches;
  1146. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1147. var tag = matches ? matches[1] : '*';
  1148. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1149. arr = byId(matches[1], tag, root);
  1150. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1151. arr = byClass(matches[1], tag, root);
  1152. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1153. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1154. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1155. var key = matches[1].toLowerCase(), val = matches[2];
  1156. if (key === 'id') {
  1157. arr = byId(val, tag, root);
  1158. } else if (key === 'class') {
  1159. arr = byClass(val, tag, root);
  1160. } else if (key === 'name') {
  1161. arr = byName(val, tag, root);
  1162. } else {
  1163. arr = byAttr(key, val, tag, root);
  1164. }
  1165. } else {
  1166. var els = root.getElementsByTagName(tag), el;
  1167. for (var i = 0, len = els.length; i < len; i++) {
  1168. el = els[i];
  1169. if (el.nodeType == 1) {
  1170. arr.push(el);
  1171. }
  1172. }
  1173. }
  1174. return arr;
  1175. }
  1176. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1177. while ((arr = re.exec(expr))) {
  1178. if (arr[1] !== ' ') {
  1179. parts.push(arr[1]);
  1180. }
  1181. }
  1182. var results = [];
  1183. if (parts.length == 1) {
  1184. return select(parts[0], root);
  1185. }
  1186. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1187. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1188. part = parts[i];
  1189. if (part === '>') {
  1190. isChild = true;
  1191. continue;
  1192. }
  1193. if (i > 0) {
  1194. els = [];
  1195. for (j = 0, len = results.length; j < len; j++) {
  1196. val = results[j];
  1197. subResults = select(part, val);
  1198. for (k = 0, l = subResults.length; k < l; k++) {
  1199. v = subResults[k];
  1200. if (isChild) {
  1201. if (val === v.parentNode) {
  1202. els.push(v);
  1203. }
  1204. } else {
  1205. els.push(v);
  1206. }
  1207. }
  1208. }
  1209. results = els;
  1210. } else {
  1211. results = select(part, root);
  1212. }
  1213. if (results.length === 0) {
  1214. return [];
  1215. }
  1216. }
  1217. return results;
  1218. }
  1219. function _query(expr, root) {
  1220. var arr = _queryAll(expr, root);
  1221. return arr.length > 0 ? arr[0] : null;
  1222. }
  1223. K.query = _query;
  1224. K.queryAll = _queryAll;
  1225. function _get(val) {
  1226. return K(val)[0];
  1227. }
  1228. function _getDoc(node) {
  1229. if (!node) {
  1230. return document;
  1231. }
  1232. return node.ownerDocument || node.document || node;
  1233. }
  1234. function _getWin(node) {
  1235. if (!node) {
  1236. return window;
  1237. }
  1238. var doc = _getDoc(node);
  1239. return doc.parentWindow || doc.defaultView;
  1240. }
  1241. function _setHtml(el, html) {
  1242. if (el.nodeType != 1) {
  1243. return;
  1244. }
  1245. var doc = _getDoc(el);
  1246. try {
  1247. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1248. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1249. temp.parentNode.removeChild(temp);
  1250. } catch(e) {
  1251. K(el).empty();
  1252. K('@' + html, doc).each(function() {
  1253. el.appendChild(this);
  1254. });
  1255. }
  1256. }
  1257. function _hasClass(el, cls) {
  1258. return _inString(cls, el.className, ' ');
  1259. }
  1260. function _setAttr(el, key, val) {
  1261. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1262. key = 'className';
  1263. }
  1264. el.setAttribute(key, '' + val);
  1265. }
  1266. function _removeAttr(el, key) {
  1267. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1268. key = 'className';
  1269. }
  1270. _setAttr(el, key, '');
  1271. el.removeAttribute(key);
  1272. }
  1273. function _getNodeName(node) {
  1274. if (!node || !node.nodeName) {
  1275. return '';
  1276. }
  1277. return node.nodeName.toLowerCase();
  1278. }
  1279. function _computedCss(el, key) {
  1280. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1281. if (win.getComputedStyle) {
  1282. var style = win.getComputedStyle(el, null);
  1283. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1284. } else if (el.currentStyle) {
  1285. val = el.currentStyle[camelKey] || el.style[camelKey];
  1286. }
  1287. return val;
  1288. }
  1289. function _hasVal(node) {
  1290. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1291. }
  1292. function _docElement(doc) {
  1293. doc = doc || document;
  1294. return _QUIRKS ? doc.body : doc.documentElement;
  1295. }
  1296. function _docHeight(doc) {
  1297. var el = _docElement(doc);
  1298. return Math.max(el.scrollHeight, el.clientHeight);
  1299. }
  1300. function _docWidth(doc) {
  1301. var el = _docElement(doc);
  1302. return Math.max(el.scrollWidth, el.clientWidth);
  1303. }
  1304. function _getScrollPos(doc) {
  1305. doc = doc || document;
  1306. var x, y;
  1307. if (_IE || _NEWIE || _OPERA) {
  1308. x = _docElement(doc).scrollLeft;
  1309. y = _docElement(doc).scrollTop;
  1310. } else {
  1311. x = _getWin(doc).scrollX;
  1312. y = _getWin(doc).scrollY;
  1313. }
  1314. return {x : x, y : y};
  1315. }
  1316. function KNode(node) {
  1317. this.init(node);
  1318. }
  1319. _extend(KNode, {
  1320. init : function(node) {
  1321. var self = this;
  1322. node = _isArray(node) ? node : [node];
  1323. var length = 0;
  1324. for (var i = 0, len = node.length; i < len; i++) {
  1325. if (node[i]) {
  1326. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1327. length++;
  1328. }
  1329. }
  1330. self.length = length;
  1331. self.doc = _getDoc(self[0]);
  1332. self.name = _getNodeName(self[0]);
  1333. self.type = self.length > 0 ? self[0].nodeType : null;
  1334. self.win = _getWin(self[0]);
  1335. },
  1336. each : function(fn) {
  1337. var self = this;
  1338. for (var i = 0; i < self.length; i++) {
  1339. if (fn.call(self[i], i, self[i]) === false) {
  1340. return self;
  1341. }
  1342. }
  1343. return self;
  1344. },
  1345. bind : function(type, fn) {
  1346. this.each(function() {
  1347. _bind(this, type, fn);
  1348. });
  1349. return this;
  1350. },
  1351. unbind : function(type, fn) {
  1352. this.each(function() {
  1353. _unbind(this, type, fn);
  1354. });
  1355. return this;
  1356. },
  1357. fire : function(type) {
  1358. if (this.length < 1) {
  1359. return this;
  1360. }
  1361. _fire(this[0], type);
  1362. return this;
  1363. },
  1364. hasAttr : function(key) {
  1365. if (this.length < 1) {
  1366. return false;
  1367. }
  1368. return !!_getAttr(this[0], key);
  1369. },
  1370. attr : function(key, val) {
  1371. var self = this;
  1372. if (key === undefined) {
  1373. return _getAttrList(self.outer());
  1374. }
  1375. if (typeof key === 'object') {
  1376. _each(key, function(k, v) {
  1377. self.attr(k, v);
  1378. });
  1379. return self;
  1380. }
  1381. if (val === undefined) {
  1382. val = self.length < 1 ? null : _getAttr(self[0], key);
  1383. return val === null ? '' : val;
  1384. }
  1385. self.each(function() {
  1386. _setAttr(this, key, val);
  1387. });
  1388. return self;
  1389. },
  1390. removeAttr : function(key) {
  1391. this.each(function() {
  1392. _removeAttr(this, key);
  1393. });
  1394. return this;
  1395. },
  1396. get : function(i) {
  1397. if (this.length < 1) {
  1398. return null;
  1399. }
  1400. return this[i || 0];
  1401. },
  1402. eq : function(i) {
  1403. if (this.length < 1) {
  1404. return null;
  1405. }
  1406. return this[i] ? new KNode(this[i]) : null;
  1407. },
  1408. hasClass : function(cls) {
  1409. if (this.length < 1) {
  1410. return false;
  1411. }
  1412. return _hasClass(this[0], cls);
  1413. },
  1414. addClass : function(cls) {
  1415. this.each(function() {
  1416. if (!_hasClass(this, cls)) {
  1417. this.className = _trim(this.className + ' ' + cls);
  1418. }
  1419. });
  1420. return this;
  1421. },
  1422. removeClass : function(cls) {
  1423. this.each(function() {
  1424. if (_hasClass(this, cls)) {
  1425. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1426. }
  1427. });
  1428. return this;
  1429. },
  1430. html : function(val) {
  1431. var self = this;
  1432. if (val === undefined) {
  1433. if (self.length < 1 || self.type != 1) {
  1434. return '';
  1435. }
  1436. return _formatHtml(self[0].innerHTML);
  1437. }
  1438. self.each(function() {
  1439. _setHtml(this, val);
  1440. });
  1441. return self;
  1442. },
  1443. text : function() {
  1444. var self = this;
  1445. if (self.length < 1) {
  1446. return '';
  1447. }
  1448. return _IE ? self[0].innerText : self[0].textContent;
  1449. },
  1450. hasVal : function() {
  1451. if (this.length < 1) {
  1452. return false;
  1453. }
  1454. return _hasVal(this[0]);
  1455. },
  1456. val : function(val) {
  1457. var self = this;
  1458. if (val === undefined) {
  1459. if (self.length < 1) {
  1460. return '';
  1461. }
  1462. return self.hasVal() ? self[0].value : self.attr('value');
  1463. } else {
  1464. self.each(function() {
  1465. if (_hasVal(this)) {
  1466. this.value = val;
  1467. } else {
  1468. _setAttr(this, 'value' , val);
  1469. }
  1470. });
  1471. return self;
  1472. }
  1473. },
  1474. css : function(key, val) {
  1475. var self = this;
  1476. if (key === undefined) {
  1477. return _getCssList(self.attr('style'));
  1478. }
  1479. if (typeof key === 'object') {
  1480. _each(key, function(k, v) {
  1481. self.css(k, v);
  1482. });
  1483. return self;
  1484. }
  1485. if (val === undefined) {
  1486. if (self.length < 1) {
  1487. return '';
  1488. }
  1489. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1490. }
  1491. self.each(function() {
  1492. this.style[_toCamel(key)] = val;
  1493. });
  1494. return self;
  1495. },
  1496. width : function(val) {
  1497. var self = this;
  1498. if (val === undefined) {
  1499. if (self.length < 1) {
  1500. return 0;
  1501. }
  1502. return self[0].offsetWidth;
  1503. }
  1504. return self.css('width', _addUnit(val));
  1505. },
  1506. height : function(val) {
  1507. var self = this;
  1508. if (val === undefined) {
  1509. if (self.length < 1) {
  1510. return 0;
  1511. }
  1512. return self[0].offsetHeight;
  1513. }
  1514. return self.css('height', _addUnit(val));
  1515. },
  1516. opacity : function(val) {
  1517. this.each(function() {
  1518. if (this.style.opacity === undefined) {
  1519. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1520. } else {
  1521. this.style.opacity = val == 1 ? '' : val;
  1522. }
  1523. });
  1524. return this;
  1525. },
  1526. data : function(key, val) {
  1527. var self = this;
  1528. key = 'kindeditor_data_' + key;
  1529. if (val === undefined) {
  1530. if (self.length < 1) {
  1531. return null;
  1532. }
  1533. return self[0][key];
  1534. }
  1535. this.each(function() {
  1536. this[key] = val;
  1537. });
  1538. return self;
  1539. },
  1540. pos : function() {
  1541. var self = this, node = self[0], x = 0, y = 0;
  1542. if (node) {
  1543. if (node.getBoundingClientRect) {
  1544. var box = node.getBoundingClientRect(),
  1545. pos = _getScrollPos(self.doc);
  1546. x = box.left + pos.x;
  1547. y = box.top + pos.y;
  1548. } else {
  1549. while (node) {
  1550. x += node.offsetLeft;
  1551. y += node.offsetTop;
  1552. node = node.offsetParent;
  1553. }
  1554. }
  1555. }
  1556. return {x : _round(x), y : _round(y)};
  1557. },
  1558. clone : function(bool) {
  1559. if (this.length < 1) {
  1560. return new KNode([]);
  1561. }
  1562. return new KNode(this[0].cloneNode(bool));
  1563. },
  1564. append : function(expr) {
  1565. this.each(function() {
  1566. if (this.appendChild) {
  1567. this.appendChild(_get(expr));
  1568. }
  1569. });
  1570. return this;
  1571. },
  1572. appendTo : function(expr) {
  1573. this.each(function() {
  1574. _get(expr).appendChild(this);
  1575. });
  1576. return this;
  1577. },
  1578. before : function(expr) {
  1579. this.each(function() {
  1580. this.parentNode.insertBefore(_get(expr), this);
  1581. });
  1582. return this;
  1583. },
  1584. after : function(expr) {
  1585. this.each(function() {
  1586. if (this.nextSibling) {
  1587. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1588. } else {
  1589. this.parentNode.appendChild(_get(expr));
  1590. }
  1591. });
  1592. return this;
  1593. },
  1594. replaceWith : function(expr) {
  1595. var nodes = [];
  1596. this.each(function(i, node) {
  1597. _unbind(node);
  1598. var newNode = _get(expr);
  1599. node.parentNode.replaceChild(newNode, node);
  1600. nodes.push(newNode);
  1601. });
  1602. return K(nodes);
  1603. },
  1604. empty : function() {
  1605. var self = this;
  1606. self.each(function(i, node) {
  1607. var child = node.firstChild;
  1608. while (child) {
  1609. if (!node.parentNode) {
  1610. return;
  1611. }
  1612. var next = child.nextSibling;
  1613. child.parentNode.removeChild(child);
  1614. child = next;
  1615. }
  1616. });
  1617. return self;
  1618. },
  1619. remove : function(keepChilds) {
  1620. var self = this;
  1621. self.each(function(i, node) {
  1622. if (!node.parentNode) {
  1623. return;
  1624. }
  1625. _unbind(node);
  1626. if (keepChilds) {
  1627. var child = node.firstChild;
  1628. while (child) {
  1629. var next = child.nextSibling;
  1630. node.parentNode.insertBefore(child, node);
  1631. child = next;
  1632. }
  1633. }
  1634. node.parentNode.removeChild(node);
  1635. delete self[i];
  1636. });
  1637. self.length = 0;
  1638. return self;
  1639. },
  1640. show : function(val) {
  1641. var self = this;
  1642. if (val === undefined) {
  1643. val = self._originDisplay || '';
  1644. }
  1645. if (self.css('display') != 'none') {
  1646. return self;
  1647. }
  1648. return self.css('display', val);
  1649. },
  1650. hide : function() {
  1651. var self = this;
  1652. if (self.length < 1) {
  1653. return self;
  1654. }
  1655. self._originDisplay = self[0].style.display;
  1656. return self.css('display', 'none');
  1657. },
  1658. outer : function() {
  1659. var self = this;
  1660. if (self.length < 1) {
  1661. return '';
  1662. }
  1663. var div = self.doc.createElement('div'), html;
  1664. div.appendChild(self[0].cloneNode(true));
  1665. html = _formatHtml(div.innerHTML);
  1666. div = null;
  1667. return html;
  1668. },
  1669. isSingle : function() {
  1670. return !!_SINGLE_TAG_MAP[this.name];
  1671. },
  1672. isInline : function() {
  1673. return !!_INLINE_TAG_MAP[this.name];
  1674. },
  1675. isBlock : function() {
  1676. return !!_BLOCK_TAG_MAP[this.name];
  1677. },
  1678. isStyle : function() {
  1679. return !!_STYLE_TAG_MAP[this.name];
  1680. },
  1681. isControl : function() {
  1682. return !!_CONTROL_TAG_MAP[this.name];
  1683. },
  1684. contains : function(otherNode) {
  1685. if (this.length < 1) {
  1686. return false;
  1687. }
  1688. return _contains(this[0], _get(otherNode));
  1689. },
  1690. parent : function() {
  1691. if (this.length < 1) {
  1692. return null;
  1693. }
  1694. var node = this[0].parentNode;
  1695. return node ? new KNode(node) : null;
  1696. },
  1697. children : function() {
  1698. if (this.length < 1) {
  1699. return new KNode([]);
  1700. }
  1701. var list = [], child = this[0].firstChild;
  1702. while (child) {
  1703. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1704. list.push(child);
  1705. }
  1706. child = child.nextSibling;
  1707. }
  1708. return new KNode(list);
  1709. },
  1710. first : function() {
  1711. var list = this.children();
  1712. return list.length > 0 ? list.eq(0) : null;
  1713. },
  1714. last : function() {
  1715. var list = this.children();
  1716. return list.length > 0 ? list.eq(list.length - 1) : null;
  1717. },
  1718. index : function() {
  1719. if (this.length < 1) {
  1720. return -1;
  1721. }
  1722. var i = -1, sibling = this[0];
  1723. while (sibling) {
  1724. i++;
  1725. sibling = sibling.previousSibling;
  1726. }
  1727. return i;
  1728. },
  1729. prev : function() {
  1730. if (this.length < 1) {
  1731. return null;
  1732. }
  1733. var node = this[0].previousSibling;
  1734. return node ? new KNode(node) : null;
  1735. },
  1736. next : function() {
  1737. if (this.length < 1) {
  1738. return null;
  1739. }
  1740. var node = this[0].nextSibling;
  1741. return node ? new KNode(node) : null;
  1742. },
  1743. scan : function(fn, order) {
  1744. if (this.length < 1) {
  1745. return;
  1746. }
  1747. order = (order === undefined) ? true : order;
  1748. function walk(node) {
  1749. var n = order ? node.firstChild : node.lastChild;
  1750. while (n) {
  1751. var next = order ? n.nextSibling : n.previousSibling;
  1752. if (fn(n) === false) {
  1753. return false;
  1754. }
  1755. if (walk(n) === false) {
  1756. return false;
  1757. }
  1758. n = next;
  1759. }
  1760. }
  1761. walk(this[0]);
  1762. return this;
  1763. }
  1764. });
  1765. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1766. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1767. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1768. KNode.prototype[type] = function(fn) {
  1769. return fn ? this.bind(type, fn) : this.fire(type);
  1770. };
  1771. });
  1772. var _K = K;
  1773. K = function(expr, root) {
  1774. if (expr === undefined || expr === null) {
  1775. return;
  1776. }
  1777. function newNode(node) {
  1778. if (!node[0]) {
  1779. node = [];
  1780. }
  1781. return new KNode(node);
  1782. }
  1783. if (typeof expr === 'string') {
  1784. if (root) {
  1785. root = _get(root);
  1786. }
  1787. var length = expr.length;
  1788. if (expr.charAt(0) === '@') {
  1789. expr = expr.substr(1);
  1790. }
  1791. if (expr.length !== length || /<.+>/.test(expr)) {
  1792. var doc = root ? root.ownerDocument || root : document,
  1793. div = doc.createElement('div'), list = [];
  1794. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1795. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1796. var child = div.childNodes[i];
  1797. if (child.id == '__kindeditor_temp_tag__') {
  1798. continue;
  1799. }
  1800. list.push(child);
  1801. }
  1802. return newNode(list);
  1803. }
  1804. return newNode(_queryAll(expr, root));
  1805. }
  1806. if (expr && expr.constructor === KNode) {
  1807. return expr;
  1808. }
  1809. if (expr.toArray) {
  1810. expr = expr.toArray();
  1811. }
  1812. if (_isArray(expr)) {
  1813. return newNode(expr);
  1814. }
  1815. return newNode(_toArray(arguments));
  1816. };
  1817. _each(_K, function(key, val) {
  1818. K[key] = val;
  1819. });
  1820. K.NodeClass = KNode;
  1821. window.KindEditor = K;
  1822. var _START_TO_START = 0,
  1823. _START_TO_END = 1,
  1824. _END_TO_END = 2,
  1825. _END_TO_START = 3,
  1826. _BOOKMARK_ID = 0;
  1827. function _updateCollapsed(range) {
  1828. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1829. return range;
  1830. }
  1831. function _copyAndDelete(range, isCopy, isDelete) {
  1832. var doc = range.doc, nodeList = [];
  1833. function splitTextNode(node, startOffset, endOffset) {
  1834. var length = node.nodeValue.length, centerNode;
  1835. if (isCopy) {
  1836. var cloneNode = node.cloneNode(true);
  1837. if (startOffset > 0) {
  1838. centerNode = cloneNode.splitText(startOffset);
  1839. } else {
  1840. centerNode = cloneNode;
  1841. }
  1842. if (endOffset < length) {
  1843. centerNode.splitText(endOffset - startOffset);
  1844. }
  1845. }
  1846. if (isDelete) {
  1847. var center = node;
  1848. if (startOffset > 0) {
  1849. center = node.splitText(startOffset);
  1850. range.setStart(node, startOffset);
  1851. }
  1852. if (endOffset < length) {
  1853. var right = center.splitText(endOffset - startOffset);
  1854. range.setEnd(right, 0);
  1855. }
  1856. nodeList.push(center);
  1857. }
  1858. return centerNode;
  1859. }
  1860. function removeNodes() {
  1861. if (isDelete) {
  1862. range.up().collapse(true);
  1863. }
  1864. for (var i = 0, len = nodeList.length; i < len; i++) {
  1865. var node = nodeList[i];
  1866. if (node.parentNode) {
  1867. node.parentNode.removeChild(node);
  1868. }
  1869. }
  1870. }
  1871. var copyRange = range.cloneRange().down();
  1872. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1873. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1874. if (ancestor.nodeType == 3) {
  1875. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1876. if (isCopy) {
  1877. frag.appendChild(textNode);
  1878. }
  1879. removeNodes();
  1880. return isCopy ? frag : range;
  1881. }
  1882. function extractNodes(parent, frag) {
  1883. var node = parent.firstChild, nextNode;
  1884. while (node) {
  1885. var testRange = new KRange(doc).selectNode(node);
  1886. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1887. if (start >= 0 && incStart <= 0) {
  1888. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1889. }
  1890. if (incStart >= 0 && incEnd <= 0) {
  1891. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1892. }
  1893. if (incEnd >= 0 && end <= 0) {
  1894. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1895. }
  1896. if (end >= 0) {
  1897. return false;
  1898. }
  1899. nextNode = node.nextSibling;
  1900. if (start > 0) {
  1901. if (node.nodeType == 1) {
  1902. if (incStart >= 0 && incEnd <= 0) {
  1903. if (isCopy) {
  1904. frag.appendChild(node.cloneNode(true));
  1905. }
  1906. if (isDelete) {
  1907. nodeList.push(node);
  1908. }
  1909. } else {
  1910. var childFlag;
  1911. if (isCopy) {
  1912. childFlag = node.cloneNode(false);
  1913. frag.appendChild(childFlag);
  1914. }
  1915. if (extractNodes(node, childFlag) === false) {
  1916. return false;
  1917. }
  1918. }
  1919. } else if (node.nodeType == 3) {
  1920. var textNode;
  1921. if (node == copyRange.startContainer) {
  1922. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1923. } else if (node == copyRange.endContainer) {
  1924. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1925. } else {
  1926. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1927. }
  1928. if (isCopy) {
  1929. try {
  1930. frag.appendChild(textNode);
  1931. } catch(e) {}
  1932. }
  1933. }
  1934. }
  1935. node = nextNode;
  1936. }
  1937. }
  1938. extractNodes(ancestor, frag);
  1939. if (isDelete) {
  1940. range.up().collapse(true);
  1941. }
  1942. for (var i = 0, len = nodeList.length; i < len; i++) {
  1943. var node = nodeList[i];
  1944. if (node.parentNode) {
  1945. node.parentNode.removeChild(node);
  1946. }
  1947. }
  1948. return isCopy ? frag : range;
  1949. }
  1950. function _moveToElementText(range, el) {
  1951. var node = el;
  1952. while (node) {
  1953. var knode = K(node);
  1954. if (knode.name == 'marquee' || knode.name == 'select') {
  1955. return;
  1956. }
  1957. node = node.parentNode;
  1958. }
  1959. try {
  1960. range.moveToElementText(el);
  1961. } catch(e) {}
  1962. }
  1963. function _getStartEnd(rng, isStart) {
  1964. var doc = rng.parentElement().ownerDocument,
  1965. pointRange = rng.duplicate();
  1966. pointRange.collapse(isStart);
  1967. var parent = pointRange.parentElement(),
  1968. nodes = parent.childNodes;
  1969. if (nodes.length === 0) {
  1970. return {node: parent.parentNode, offset: K(parent).index()};
  1971. }
  1972. var startNode = doc, startPos = 0, cmp = -1;
  1973. var testRange = rng.duplicate();
  1974. _moveToElementText(testRange, parent);
  1975. for (var i = 0, len = nodes.length; i < len; i++) {
  1976. var node = nodes[i];
  1977. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1978. if (cmp === 0) {
  1979. return {node: node.parentNode, offset: i};
  1980. }
  1981. if (node.nodeType == 1) {
  1982. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1983. if (knode.isControl()) {
  1984. dummy = doc.createElement('span');
  1985. knode.after(dummy);
  1986. newNode = dummy;
  1987. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1988. }
  1989. _moveToElementText(nodeRange, newNode);
  1990. testRange.setEndPoint('StartToEnd', nodeRange);
  1991. if (cmp > 0) {
  1992. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1993. } else {
  1994. startPos = 0;
  1995. }
  1996. if (dummy) {
  1997. K(dummy).remove();
  1998. }
  1999. } else if (node.nodeType == 3) {
  2000. testRange.moveStart('character', node.nodeValue.length);
  2001. startPos += node.nodeValue.length;
  2002. }
  2003. if (cmp < 0) {
  2004. startNode = node;
  2005. }
  2006. }
  2007. if (cmp < 0 && startNode.nodeType == 1) {
  2008. return {node: parent, offset: K(parent.lastChild).index() + 1};
  2009. }
  2010. if (cmp > 0) {
  2011. while (startNode.nextSibling && startNode.nodeType == 1) {
  2012. startNode = startNode.nextSibling;
  2013. }
  2014. }
  2015. testRange = rng.duplicate();
  2016. _moveToElementText(testRange, parent);
  2017. testRange.setEndPoint('StartToEnd', pointRange);
  2018. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  2019. if (cmp > 0 && startNode.nodeType == 3) {
  2020. var prevNode = startNode.previousSibling;
  2021. while (prevNode && prevNode.nodeType == 3) {
  2022. startPos -= prevNode.nodeValue.length;
  2023. prevNode = prevNode.previousSibling;
  2024. }
  2025. }
  2026. return {node: startNode, offset: startPos};
  2027. }
  2028. function _getEndRange(node, offset) {
  2029. var doc = node.ownerDocument || node,
  2030. range = doc.body.createTextRange();
  2031. if (doc == node) {
  2032. range.collapse(true);
  2033. return range;
  2034. }
  2035. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2036. var children = node.childNodes, isStart, child;
  2037. if (offset === 0) {
  2038. child = children[0];
  2039. isStart = true;
  2040. } else {
  2041. child = children[offset - 1];
  2042. isStart = false;
  2043. }
  2044. if (!child) {
  2045. return range;
  2046. }
  2047. if (K(child).name === 'head') {
  2048. if (offset === 1) {
  2049. isStart = true;
  2050. }
  2051. if (offset === 2) {
  2052. isStart = false;
  2053. }
  2054. range.collapse(isStart);
  2055. return range;
  2056. }
  2057. if (child.nodeType == 1) {
  2058. var kchild = K(child), span;
  2059. if (kchild.isControl()) {
  2060. span = doc.createElement('span');
  2061. if (isStart) {
  2062. kchild.before(span);
  2063. } else {
  2064. kchild.after(span);
  2065. }
  2066. child = span;
  2067. }
  2068. _moveToElementText(range, child);
  2069. range.collapse(isStart);
  2070. if (span) {
  2071. K(span).remove();
  2072. }
  2073. return range;
  2074. }
  2075. node = child;
  2076. offset = isStart ? 0 : child.nodeValue.length;
  2077. }
  2078. var dummy = doc.createElement('span');
  2079. K(node).before(dummy);
  2080. _moveToElementText(range, dummy);
  2081. range.moveStart('character', offset);
  2082. K(dummy).remove();
  2083. return range;
  2084. }
  2085. function _toRange(rng) {
  2086. var doc, range;
  2087. function tr2td(start) {
  2088. if (K(start.node).name == 'tr') {
  2089. start.node = start.node.cells[start.offset];
  2090. start.offset = 0;
  2091. }
  2092. }
  2093. if (_IERANGE) {
  2094. if (rng.item) {
  2095. doc = _getDoc(rng.item(0));
  2096. range = new KRange(doc);
  2097. range.selectNode(rng.item(0));
  2098. return range;
  2099. }
  2100. doc = rng.parentElement().ownerDocument;
  2101. var start = _getStartEnd(rng, true),
  2102. end = _getStartEnd(rng, false);
  2103. tr2td(start);
  2104. tr2td(end);
  2105. range = new KRange(doc);
  2106. range.setStart(start.node, start.offset);
  2107. range.setEnd(end.node, end.offset);
  2108. return range;
  2109. }
  2110. var startContainer = rng.startContainer;
  2111. doc = startContainer.ownerDocument || startContainer;
  2112. range = new KRange(doc);
  2113. range.setStart(startContainer, rng.startOffset);
  2114. range.setEnd(rng.endContainer, rng.endOffset);
  2115. return range;
  2116. }
  2117. function KRange(doc) {
  2118. this.init(doc);
  2119. }
  2120. _extend(KRange, {
  2121. init : function(doc) {
  2122. var self = this;
  2123. self.startContainer = doc;
  2124. self.startOffset = 0;
  2125. self.endContainer = doc;
  2126. self.endOffset = 0;
  2127. self.collapsed = true;
  2128. self.doc = doc;
  2129. },
  2130. commonAncestor : function() {
  2131. function getParents(node) {
  2132. var parents = [];
  2133. while (node) {
  2134. parents.push(node);
  2135. node = node.parentNode;
  2136. }
  2137. return parents;
  2138. }
  2139. var parentsA = getParents(this.startContainer),
  2140. parentsB = getParents(this.endContainer),
  2141. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2142. while (++i) {
  2143. parentA = parentsA[lenA - i];
  2144. parentB = parentsB[lenB - i];
  2145. if (!parentA || !parentB || parentA !== parentB) {
  2146. break;
  2147. }
  2148. }
  2149. return parentsA[lenA - i + 1];
  2150. },
  2151. setStart : function(node, offset) {
  2152. var self = this, doc = self.doc;
  2153. self.startContainer = node;
  2154. self.startOffset = offset;
  2155. if (self.endContainer === doc) {
  2156. self.endContainer = node;
  2157. self.endOffset = offset;
  2158. }
  2159. return _updateCollapsed(this);
  2160. },
  2161. setEnd : function(node, offset) {
  2162. var self = this, doc = self.doc;
  2163. self.endContainer = node;
  2164. self.endOffset = offset;
  2165. if (self.startContainer === doc) {
  2166. self.startContainer = node;
  2167. self.startOffset = offset;
  2168. }
  2169. return _updateCollapsed(this);
  2170. },
  2171. setStartBefore : function(node) {
  2172. return this.setStart(node.parentNode || this.doc, K(node).index());
  2173. },
  2174. setStartAfter : function(node) {
  2175. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2176. },
  2177. setEndBefore : function(node) {
  2178. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2179. },
  2180. setEndAfter : function(node) {
  2181. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2182. },
  2183. selectNode : function(node) {
  2184. return this.setStartBefore(node).setEndAfter(node);
  2185. },
  2186. selectNodeContents : function(node) {
  2187. var knode = K(node);
  2188. if (knode.type == 3 || knode.isSingle()) {
  2189. return this.selectNode(node);
  2190. }
  2191. var children = knode.children();
  2192. if (children.length > 0) {
  2193. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2194. }
  2195. return this.setStart(node, 0).setEnd(node, 0);
  2196. },
  2197. collapse : function(toStart) {
  2198. if (toStart) {
  2199. return this.setEnd(this.startContainer, this.startOffset);
  2200. }
  2201. return this.setStart(this.endContainer, this.endOffset);
  2202. },
  2203. compareBoundaryPoints : function(how, range) {
  2204. var rangeA = this.get(), rangeB = range.get();
  2205. if (_IERANGE) {
  2206. var arr = {};
  2207. arr[_START_TO_START] = 'StartToStart';
  2208. arr[_START_TO_END] = 'EndToStart';
  2209. arr[_END_TO_END] = 'EndToEnd';
  2210. arr[_END_TO_START] = 'StartToEnd';
  2211. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2212. if (cmp !== 0) {
  2213. return cmp;
  2214. }
  2215. var nodeA, nodeB, nodeC, posA, posB;
  2216. if (how === _START_TO_START || how === _END_TO_START) {
  2217. nodeA = this.startContainer;
  2218. posA = this.startOffset;
  2219. }
  2220. if (how === _START_TO_END || how === _END_TO_END) {
  2221. nodeA = this.endContainer;
  2222. posA = this.endOffset;
  2223. }
  2224. if (how === _START_TO_START || how === _START_TO_END) {
  2225. nodeB = range.startContainer;
  2226. posB = range.startOffset;
  2227. }
  2228. if (how === _END_TO_END || how === _END_TO_START) {
  2229. nodeB = range.endContainer;
  2230. posB = range.endOffset;
  2231. }
  2232. if (nodeA === nodeB) {
  2233. var diff = posA - posB;
  2234. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2235. }
  2236. nodeC = nodeB;
  2237. while (nodeC && nodeC.parentNode !== nodeA) {
  2238. nodeC = nodeC.parentNode;
  2239. }
  2240. if (nodeC) {
  2241. return K(nodeC).index() >= posA ? -1 : 1;
  2242. }
  2243. nodeC = nodeA;
  2244. while (nodeC && nodeC.parentNode !== nodeB) {
  2245. nodeC = nodeC.parentNode;
  2246. }
  2247. if (nodeC) {
  2248. return K(nodeC).index() >= posB ? 1 : -1;
  2249. }
  2250. nodeC = K(nodeB).next();
  2251. if (nodeC && nodeC.contains(nodeA)) {
  2252. return 1;
  2253. }
  2254. nodeC = K(nodeA).next();
  2255. if (nodeC && nodeC.contains(nodeB)) {
  2256. return -1;
  2257. }
  2258. } else {
  2259. return rangeA.compareBoundaryPoints(how, rangeB);
  2260. }
  2261. },
  2262. cloneRange : function() {
  2263. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2264. },
  2265. toString : function() {
  2266. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2267. return str.replace(/\r\n|\n|\r/g, '');
  2268. },
  2269. cloneContents : function() {
  2270. return _copyAndDelete(this, true, false);
  2271. },
  2272. deleteContents : function() {
  2273. return _copyAndDelete(this, false, true);
  2274. },
  2275. extractContents : function() {
  2276. return _copyAndDelete(this, true, true);
  2277. },
  2278. insertNode : function(node) {
  2279. var self = this,
  2280. sc = self.startContainer, so = self.startOffset,
  2281. ec = self.endContainer, eo = self.endOffset,
  2282. firstChild, lastChild, c, nodeCount = 1;
  2283. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2284. firstChild = node.firstChild;
  2285. lastChild = node.lastChild;
  2286. nodeCount = node.childNodes.length;
  2287. }
  2288. if (sc.nodeType == 1) {
  2289. c = sc.childNodes[so];
  2290. if (c) {
  2291. sc.insertBefore(node, c);
  2292. if (sc === ec) {
  2293. eo += nodeCount;
  2294. }
  2295. } else {
  2296. sc.appendChild(node);
  2297. }
  2298. } else if (sc.nodeType == 3) {
  2299. if (so === 0) {
  2300. sc.parentNode.insertBefore(node, sc);
  2301. if (sc.parentNode === ec) {
  2302. eo += nodeCount;
  2303. }
  2304. } else if (so >= sc.nodeValue.length) {
  2305. if (sc.nextSibling) {
  2306. sc.parentNode.insertBefore(node, sc.nextSibling);
  2307. } else {
  2308. sc.parentNode.appendChild(node);
  2309. }
  2310. } else {
  2311. if (so > 0) {
  2312. c = sc.splitText(so);
  2313. } else {
  2314. c = sc;
  2315. }
  2316. sc.parentNode.insertBefore(node, c);
  2317. if (sc === ec) {
  2318. ec = c;
  2319. eo -= so;
  2320. }
  2321. }
  2322. }
  2323. if (firstChild) {
  2324. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2325. } else {
  2326. self.selectNode(node);
  2327. }
  2328. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2329. return self;
  2330. }
  2331. return self.setEnd(ec, eo);
  2332. },
  2333. surroundContents : function(node) {
  2334. node.appendChild(this.extractContents());
  2335. return this.insertNode(node).selectNode(node);
  2336. },
  2337. isControl : function() {
  2338. var self = this,
  2339. sc = self.startContainer, so = self.startOffset,
  2340. ec = self.endContainer, eo = self.endOffset, rng;
  2341. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2342. },
  2343. get : function(hasControlRange) {
  2344. var self = this, doc = self.doc, node, rng;
  2345. if (!_IERANGE) {
  2346. rng = doc.createRange();
  2347. try {
  2348. rng.setStart(self.startContainer, self.startOffset);
  2349. rng.setEnd(self.endContainer, self.endOffset);
  2350. } catch (e) {}
  2351. return rng;
  2352. }
  2353. if (hasControlRange && self.isControl()) {
  2354. rng = doc.body.createControlRange();
  2355. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2356. return rng;
  2357. }
  2358. var range = self.cloneRange().down();
  2359. rng = doc.body.createTextRange();
  2360. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2361. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2362. return rng;
  2363. },
  2364. html : function() {
  2365. return K(this.cloneContents()).outer();
  2366. },
  2367. down : function() {
  2368. var self = this;
  2369. function downPos(node, pos, isStart) {
  2370. if (node.nodeType != 1) {
  2371. return;
  2372. }
  2373. var children = K(node).children();
  2374. if (children.length === 0) {
  2375. return;
  2376. }
  2377. var left, right, child, offset;
  2378. if (pos > 0) {
  2379. left = children.eq(pos - 1);
  2380. }
  2381. if (pos < children.length) {
  2382. right = children.eq(pos);
  2383. }
  2384. if (left && left.type == 3) {
  2385. child = left[0];
  2386. offset = child.nodeValue.length;
  2387. }
  2388. if (right && right.type == 3) {
  2389. child = right[0];
  2390. offset = 0;
  2391. }
  2392. if (!child) {
  2393. return;
  2394. }
  2395. if (isStart) {
  2396. self.setStart(child, offset);
  2397. } else {
  2398. self.setEnd(child, offset);
  2399. }
  2400. }
  2401. downPos(self.startContainer, self.startOffset, true);
  2402. downPos(self.endContainer, self.endOffset, false);
  2403. return self;
  2404. },
  2405. up : function() {
  2406. var self = this;
  2407. function upPos(node, pos, isStart) {
  2408. if (node.nodeType != 3) {
  2409. return;
  2410. }
  2411. if (pos === 0) {
  2412. if (isStart) {
  2413. self.setStartBefore(node);
  2414. } else {
  2415. self.setEndBefore(node);
  2416. }
  2417. } else if (pos == node.nodeValue.length) {
  2418. if (isStart) {
  2419. self.setStartAfter(node);
  2420. } else {
  2421. self.setEndAfter(node);
  2422. }
  2423. }
  2424. }
  2425. upPos(self.startContainer, self.startOffset, true);
  2426. upPos(self.endContainer, self.endOffset, false);
  2427. return self;
  2428. },
  2429. enlarge : function(toBlock) {
  2430. var self = this;
  2431. self.up();
  2432. function enlargePos(node, pos, isStart) {
  2433. var knode = K(node), parent;
  2434. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2435. return;
  2436. }
  2437. if (pos === 0) {
  2438. while (!knode.prev()) {
  2439. parent = knode.parent();
  2440. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2441. break;
  2442. }
  2443. knode = parent;
  2444. }
  2445. if (isStart) {
  2446. self.setStartBefore(knode[0]);
  2447. } else {
  2448. self.setEndBefore(knode[0]);
  2449. }
  2450. } else if (pos == knode.children().length) {
  2451. while (!knode.next()) {
  2452. parent = knode.parent();
  2453. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2454. break;
  2455. }
  2456. knode = parent;
  2457. }
  2458. if (isStart) {
  2459. self.setStartAfter(knode[0]);
  2460. } else {
  2461. self.setEndAfter(knode[0]);
  2462. }
  2463. }
  2464. }
  2465. enlargePos(self.startContainer, self.startOffset, true);
  2466. enlargePos(self.endContainer, self.endOffset, false);
  2467. return self;
  2468. },
  2469. shrink : function() {
  2470. var self = this, child, collapsed = self.collapsed;
  2471. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2472. self.setStart(child, 0);
  2473. }
  2474. if (collapsed) {
  2475. return self.collapse(collapsed);
  2476. }
  2477. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2478. self.setEnd(child, child.childNodes.length);
  2479. }
  2480. return self;
  2481. },
  2482. createBookmark : function(serialize) {
  2483. var self = this, doc = self.doc, endNode,
  2484. startNode = K('<span style="display:none;"></span>', doc)[0];
  2485. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2486. if (!self.collapsed) {
  2487. endNode = startNode.cloneNode(true);
  2488. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2489. }
  2490. if (endNode) {
  2491. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2492. }
  2493. self.insertNode(startNode).setStartAfter(startNode);
  2494. return {
  2495. start : serialize ? '#' + startNode.id : startNode,
  2496. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2497. };
  2498. },
  2499. moveToBookmark : function(bookmark) {
  2500. var self = this, doc = self.doc,
  2501. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2502. if (!start || start.length < 1) {
  2503. return self;
  2504. }
  2505. self.setStartBefore(start[0]);
  2506. start.remove();
  2507. if (end && end.length > 0) {
  2508. self.setEndBefore(end[0]);
  2509. end.remove();
  2510. } else {
  2511. self.collapse(true);
  2512. }
  2513. return self;
  2514. },
  2515. dump : function() {
  2516. console.log('--------------------');
  2517. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2518. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2519. }
  2520. });
  2521. function _range(mixed) {
  2522. if (!mixed.nodeName) {
  2523. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2524. }
  2525. return new KRange(mixed);
  2526. }
  2527. K.RangeClass = KRange;
  2528. K.range = _range;
  2529. K.START_TO_START = _START_TO_START;
  2530. K.START_TO_END = _START_TO_END;
  2531. K.END_TO_END = _END_TO_END;
  2532. K.END_TO_START = _END_TO_START;
  2533. function _nativeCommand(doc, key, val) {
  2534. try {
  2535. doc.execCommand(key, false, val);
  2536. } catch(e) {}
  2537. }
  2538. function _nativeCommandValue(doc, key) {
  2539. var val = '';
  2540. try {
  2541. val = doc.queryCommandValue(key);
  2542. } catch (e) {}
  2543. if (typeof val !== 'string') {
  2544. val = '';
  2545. }
  2546. return val;
  2547. }
  2548. function _getSel(doc) {
  2549. var win = _getWin(doc);
  2550. return _IERANGE ? doc.selection : win.getSelection();
  2551. }
  2552. function _getRng(doc) {
  2553. var sel = _getSel(doc), rng;
  2554. try {
  2555. if (sel.rangeCount > 0) {
  2556. rng = sel.getRangeAt(0);
  2557. } else {
  2558. rng = sel.createRange();
  2559. }
  2560. } catch(e) {}
  2561. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2562. return null;
  2563. }
  2564. return rng;
  2565. }
  2566. function _singleKeyMap(map) {
  2567. var newMap = {}, arr, v;
  2568. _each(map, function(key, val) {
  2569. arr = key.split(',');
  2570. for (var i = 0, len = arr.length; i < len; i++) {
  2571. v = arr[i];
  2572. newMap[v] = val;
  2573. }
  2574. });
  2575. return newMap;
  2576. }
  2577. function _hasAttrOrCss(knode, map) {
  2578. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2579. }
  2580. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2581. mapKey = mapKey || knode.name;
  2582. if (knode.type !== 1) {
  2583. return false;
  2584. }
  2585. var newMap = _singleKeyMap(map);
  2586. if (!newMap[mapKey]) {
  2587. return false;
  2588. }
  2589. var arr = newMap[mapKey].split(',');
  2590. for (var i = 0, len = arr.length; i < len; i++) {
  2591. var key = arr[i];
  2592. if (key === '*') {
  2593. return true;
  2594. }
  2595. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2596. var method = match[1] ? 'css' : 'attr';
  2597. key = match[2];
  2598. var val = match[3] || '';
  2599. if (val === '' && knode[method](key) !== '') {
  2600. return true;
  2601. }
  2602. if (val !== '' && knode[method](key) === val) {
  2603. return true;
  2604. }
  2605. }
  2606. return false;
  2607. }
  2608. function _removeAttrOrCss(knode, map) {
  2609. if (knode.type != 1) {
  2610. return;
  2611. }
  2612. _removeAttrOrCssByKey(knode, map, '*');
  2613. _removeAttrOrCssByKey(knode, map);
  2614. }
  2615. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2616. mapKey = mapKey || knode.name;
  2617. if (knode.type !== 1) {
  2618. return;
  2619. }
  2620. var newMap = _singleKeyMap(map);
  2621. if (!newMap[mapKey]) {
  2622. return;
  2623. }
  2624. var arr = newMap[mapKey].split(','), allFlag = false;
  2625. for (var i = 0, len = arr.length; i < len; i++) {
  2626. var key = arr[i];
  2627. if (key === '*') {
  2628. allFlag = true;
  2629. break;
  2630. }
  2631. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2632. key = match[2];
  2633. if (match[1]) {
  2634. key = _toCamel(key);
  2635. if (knode[0].style[key]) {
  2636. knode[0].style[key] = '';
  2637. }
  2638. } else {
  2639. knode.removeAttr(key);
  2640. }
  2641. }
  2642. if (allFlag) {
  2643. knode.remove(true);
  2644. }
  2645. }
  2646. function _getInnerNode(knode) {
  2647. var inner = knode;
  2648. while (inner.first()) {
  2649. inner = inner.first();
  2650. }
  2651. return inner;
  2652. }
  2653. function _isEmptyNode(knode) {
  2654. if (knode.type != 1 || knode.isSingle()) {
  2655. return false;
  2656. }
  2657. return knode.html().replace(/<[^>]+>/g, '') === '';
  2658. }
  2659. function _mergeWrapper(a, b) {
  2660. a = a.clone(true);
  2661. var lastA = _getInnerNode(a), childA = a, merged = false;
  2662. while (b) {
  2663. while (childA) {
  2664. if (childA.name === b.name) {
  2665. _mergeAttrs(childA, b.attr(), b.css());
  2666. merged = true;
  2667. }
  2668. childA = childA.first();
  2669. }
  2670. if (!merged) {
  2671. lastA.append(b.clone(false));
  2672. }
  2673. merged = false;
  2674. b = b.first();
  2675. }
  2676. return a;
  2677. }
  2678. function _wrapNode(knode, wrapper) {
  2679. wrapper = wrapper.clone(true);
  2680. if (knode.type == 3) {
  2681. _getInnerNode(wrapper).append(knode.clone(false));
  2682. knode.replaceWith(wrapper);
  2683. return wrapper;
  2684. }
  2685. var nodeWrapper = knode, child;
  2686. while ((child = knode.first()) && child.children().length == 1) {
  2687. knode = child;
  2688. }
  2689. child = knode.first();
  2690. var frag = knode.doc.createDocumentFragment();
  2691. while (child) {
  2692. frag.appendChild(child[0]);
  2693. child = child.next();
  2694. }
  2695. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2696. if (frag.firstChild) {
  2697. _getInnerNode(wrapper).append(frag);
  2698. }
  2699. nodeWrapper.replaceWith(wrapper);
  2700. return wrapper;
  2701. }
  2702. function _mergeAttrs(knode, attrs, styles) {
  2703. _each(attrs, function(key, val) {
  2704. if (key !== 'style') {
  2705. knode.attr(key, val);
  2706. }
  2707. });
  2708. _each(styles, function(key, val) {
  2709. knode.css(key, val);
  2710. });
  2711. }
  2712. function _inPreElement(knode) {
  2713. while (knode && knode.name != 'body') {
  2714. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2715. return true;
  2716. }
  2717. knode = knode.parent();
  2718. }
  2719. return false;
  2720. }
  2721. function KCmd(range) {
  2722. this.init(range);
  2723. }
  2724. _extend(KCmd, {
  2725. init : function(range) {
  2726. var self = this, doc = range.doc;
  2727. self.doc = doc;
  2728. self.win = _getWin(doc);
  2729. self.sel = _getSel(doc);
  2730. self.range = range;
  2731. },
  2732. selection : function(forceReset) {
  2733. var self = this, doc = self.doc, rng = _getRng(doc);
  2734. self.sel = _getSel(doc);
  2735. if (rng) {
  2736. self.range = _range(rng);
  2737. if (K(self.range.startContainer).name == 'html') {
  2738. self.range.selectNodeContents(doc.body).collapse(false);
  2739. }
  2740. return self;
  2741. }
  2742. if (forceReset) {
  2743. self.range.selectNodeContents(doc.body).collapse(false);
  2744. }
  2745. return self;
  2746. },
  2747. select : function(hasDummy) {
  2748. hasDummy = _undef(hasDummy, true);
  2749. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2750. sc = range.startContainer, so = range.startOffset,
  2751. ec = range.endContainer, eo = range.endOffset,
  2752. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2753. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2754. if (_IERANGE) {
  2755. var dummy = K('<span>&nbsp;</span>', doc);
  2756. range.insertNode(dummy[0]);
  2757. rng = doc.body.createTextRange();
  2758. try {
  2759. rng.moveToElementText(dummy[0]);
  2760. } catch(ex) {}
  2761. rng.collapse(false);
  2762. rng.select();
  2763. dummy.remove();
  2764. win.focus();
  2765. return self;
  2766. }
  2767. if (_WEBKIT) {
  2768. var children = sc.childNodes;
  2769. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2770. range.insertNode(doc.createTextNode('\u200B'));
  2771. hasU200b = true;
  2772. }
  2773. }
  2774. }
  2775. if (_IERANGE) {
  2776. try {
  2777. rng = range.get(true);
  2778. rng.select();
  2779. } catch(e) {}
  2780. } else {
  2781. if (hasU200b) {
  2782. range.collapse(false);
  2783. }
  2784. rng = range.get(true);
  2785. sel.removeAllRanges();
  2786. sel.addRange(rng);
  2787. if (doc !== document) {
  2788. var pos = K(rng.endContainer).pos();
  2789. win.scrollTo(pos.x, pos.y);
  2790. }
  2791. }
  2792. win.focus();
  2793. return self;
  2794. },
  2795. wrap : function(val) {
  2796. var self = this, doc = self.doc, range = self.range, wrapper;
  2797. wrapper = K(val, doc);
  2798. if (range.collapsed) {
  2799. range.shrink();
  2800. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2801. return self;
  2802. }
  2803. if (wrapper.isBlock()) {
  2804. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2805. while (child.first()) {
  2806. child = child.first();
  2807. }
  2808. child.append(range.extractContents());
  2809. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2810. return self;
  2811. }
  2812. range.enlarge();
  2813. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2814. K(ancestor).scan(function(node) {
  2815. if (!isStart && node == bookmark.start) {
  2816. isStart = true;
  2817. return;
  2818. }
  2819. if (isStart) {
  2820. if (node == bookmark.end) {
  2821. return false;
  2822. }
  2823. var knode = K(node);
  2824. if (_inPreElement(knode)) {
  2825. return;
  2826. }
  2827. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2828. var parent;
  2829. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2830. knode = parent;
  2831. }
  2832. _wrapNode(knode, wrapper);
  2833. }
  2834. }
  2835. });
  2836. range.moveToBookmark(bookmark);
  2837. return self;
  2838. },
  2839. split : function(isStart, map) {
  2840. var range = this.range, doc = range.doc;
  2841. var tempRange = range.cloneRange().collapse(isStart);
  2842. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2843. parent = node.nodeType == 3 ? node.parentNode : node,
  2844. needSplit = false, knode;
  2845. while (parent && parent.parentNode) {
  2846. knode = K(parent);
  2847. if (map) {
  2848. if (!knode.isStyle()) {
  2849. break;
  2850. }
  2851. if (!_hasAttrOrCss(knode, map)) {
  2852. break;
  2853. }
  2854. } else {
  2855. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2856. break;
  2857. }
  2858. }
  2859. needSplit = true;
  2860. parent = parent.parentNode;
  2861. }
  2862. if (needSplit) {
  2863. var dummy = doc.createElement('span');
  2864. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2865. if (isStart) {
  2866. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2867. } else {
  2868. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2869. }
  2870. var frag = tempRange.extractContents(),
  2871. first = frag.firstChild, last = frag.lastChild;
  2872. if (isStart) {
  2873. tempRange.insertNode(frag);
  2874. range.setStartAfter(last).setEndBefore(dummy);
  2875. } else {
  2876. parent.appendChild(frag);
  2877. range.setStartBefore(dummy).setEndBefore(first);
  2878. }
  2879. var dummyParent = dummy.parentNode;
  2880. if (dummyParent == range.endContainer) {
  2881. var prev = K(dummy).prev(), next = K(dummy).next();
  2882. if (prev && next && prev.type == 3 && next.type == 3) {
  2883. range.setEnd(prev[0], prev[0].nodeValue.length);
  2884. } else if (!isStart) {
  2885. range.setEnd(range.endContainer, range.endOffset - 1);
  2886. }
  2887. }
  2888. dummyParent.removeChild(dummy);
  2889. }
  2890. return this;
  2891. },
  2892. remove : function(map) {
  2893. var self = this, doc = self.doc, range = self.range;
  2894. range.enlarge();
  2895. if (range.startOffset === 0) {
  2896. var ksc = K(range.startContainer), parent;
  2897. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2898. ksc = parent;
  2899. }
  2900. range.setStart(ksc[0], 0);
  2901. ksc = K(range.startContainer);
  2902. if (ksc.isBlock()) {
  2903. _removeAttrOrCss(ksc, map);
  2904. }
  2905. var kscp = ksc.parent();
  2906. if (kscp && kscp.isBlock()) {
  2907. _removeAttrOrCss(kscp, map);
  2908. }
  2909. }
  2910. var sc, so;
  2911. if (range.collapsed) {
  2912. self.split(true, map);
  2913. sc = range.startContainer;
  2914. so = range.startOffset;
  2915. if (so > 0) {
  2916. var sb = K(sc.childNodes[so - 1]);
  2917. if (sb && _isEmptyNode(sb)) {
  2918. sb.remove();
  2919. range.setStart(sc, so - 1);
  2920. }
  2921. }
  2922. var sa = K(sc.childNodes[so]);
  2923. if (sa && _isEmptyNode(sa)) {
  2924. sa.remove();
  2925. }
  2926. if (_isEmptyNode(sc)) {
  2927. range.startBefore(sc);
  2928. sc.remove();
  2929. }
  2930. range.collapse(true);
  2931. return self;
  2932. }
  2933. self.split(true, map);
  2934. self.split(false, map);
  2935. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2936. range.cloneRange().collapse(false).insertNode(endDummy);
  2937. range.cloneRange().collapse(true).insertNode(startDummy);
  2938. var nodeList = [], cmpStart = false;
  2939. K(range.commonAncestor()).scan(function(node) {
  2940. if (!cmpStart && node == startDummy) {
  2941. cmpStart = true;
  2942. return;
  2943. }
  2944. if (node == endDummy) {
  2945. return false;
  2946. }
  2947. if (cmpStart) {
  2948. nodeList.push(node);
  2949. }
  2950. });
  2951. K(startDummy).remove();
  2952. K(endDummy).remove();
  2953. sc = range.startContainer;
  2954. so = range.startOffset;
  2955. var ec = range.endContainer, eo = range.endOffset;
  2956. if (so > 0) {
  2957. var startBefore = K(sc.childNodes[so - 1]);
  2958. if (startBefore && _isEmptyNode(startBefore)) {
  2959. startBefore.remove();
  2960. range.setStart(sc, so - 1);
  2961. if (sc == ec) {
  2962. range.setEnd(ec, eo - 1);
  2963. }
  2964. }
  2965. var startAfter = K(sc.childNodes[so]);
  2966. if (startAfter && _isEmptyNode(startAfter)) {
  2967. startAfter.remove();
  2968. if (sc == ec) {
  2969. range.setEnd(ec, eo - 1);
  2970. }
  2971. }
  2972. }
  2973. var endAfter = K(ec.childNodes[range.endOffset]);
  2974. if (endAfter && _isEmptyNode(endAfter)) {
  2975. endAfter.remove();
  2976. }
  2977. var bookmark = range.createBookmark(true);
  2978. _each(nodeList, function(i, node) {
  2979. _removeAttrOrCss(K(node), map);
  2980. });
  2981. range.moveToBookmark(bookmark);
  2982. return self;
  2983. },
  2984. commonNode : function(map) {
  2985. var range = this.range;
  2986. var ec = range.endContainer, eo = range.endOffset,
  2987. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2988. function find(node) {
  2989. var child = node, parent = node;
  2990. while (parent) {
  2991. if (_hasAttrOrCss(K(parent), map)) {
  2992. return K(parent);
  2993. }
  2994. parent = parent.parentNode;
  2995. }
  2996. while (child && (child = child.lastChild)) {
  2997. if (_hasAttrOrCss(K(child), map)) {
  2998. return K(child);
  2999. }
  3000. }
  3001. return null;
  3002. }
  3003. var cNode = find(node);
  3004. if (cNode) {
  3005. return cNode;
  3006. }
  3007. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  3008. var prev = K(node).prev();
  3009. if (prev) {
  3010. return find(prev);
  3011. }
  3012. }
  3013. return null;
  3014. },
  3015. commonAncestor : function(tagName) {
  3016. var range = this.range,
  3017. sc = range.startContainer, so = range.startOffset,
  3018. ec = range.endContainer, eo = range.endOffset,
  3019. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3020. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3021. function find(node) {
  3022. while (node) {
  3023. if (node.nodeType == 1) {
  3024. if (node.tagName.toLowerCase() === tagName) {
  3025. return node;
  3026. }
  3027. }
  3028. node = node.parentNode;
  3029. }
  3030. return null;
  3031. }
  3032. var start = find(startNode), end = find(endNode);
  3033. if (start && end && start === end) {
  3034. return K(start);
  3035. }
  3036. return null;
  3037. },
  3038. state : function(key) {
  3039. var self = this, doc = self.doc, bool = false;
  3040. try {
  3041. bool = doc.queryCommandState(key);
  3042. } catch (e) {}
  3043. return bool;
  3044. },
  3045. val : function(key) {
  3046. var self = this, doc = self.doc, range = self.range;
  3047. function lc(val) {
  3048. return val.toLowerCase();
  3049. }
  3050. key = lc(key);
  3051. var val = '', knode;
  3052. if (key === 'fontfamily' || key === 'fontname') {
  3053. val = _nativeCommandValue(doc, 'fontname');
  3054. val = val.replace(/['"]/g, '');
  3055. return lc(val);
  3056. }
  3057. if (key === 'formatblock') {
  3058. val = _nativeCommandValue(doc, key);
  3059. if (val === '') {
  3060. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3061. if (knode) {
  3062. val = knode.name;
  3063. }
  3064. }
  3065. if (val === 'Normal') {
  3066. val = 'p';
  3067. }
  3068. return lc(val);
  3069. }
  3070. if (key === 'fontsize') {
  3071. knode = self.commonNode({'*' : '.font-size'});
  3072. if (knode) {
  3073. val = knode.css('font-size');
  3074. }
  3075. return lc(val);
  3076. }
  3077. if (key === 'forecolor') {
  3078. knode = self.commonNode({'*' : '.color'});
  3079. if (knode) {
  3080. val = knode.css('color');
  3081. }
  3082. val = _toHex(val);
  3083. if (val === '') {
  3084. val = 'default';
  3085. }
  3086. return lc(val);
  3087. }
  3088. if (key === 'hilitecolor') {
  3089. knode = self.commonNode({'*' : '.background-color'});
  3090. if (knode) {
  3091. val = knode.css('background-color');
  3092. }
  3093. val = _toHex(val);
  3094. if (val === '') {
  3095. val = 'default';
  3096. }
  3097. return lc(val);
  3098. }
  3099. return val;
  3100. },
  3101. toggle : function(wrapper, map) {
  3102. var self = this;
  3103. if (self.commonNode(map)) {
  3104. self.remove(map);
  3105. } else {
  3106. self.wrap(wrapper);
  3107. }
  3108. return self.select();
  3109. },
  3110. bold : function() {
  3111. return this.toggle('<strong></strong>', {
  3112. span : '.font-weight=bold',
  3113. strong : '*',
  3114. b : '*'
  3115. });
  3116. },
  3117. italic : function() {
  3118. return this.toggle('<em></em>', {
  3119. span : '.font-style=italic',
  3120. em : '*',
  3121. i : '*'
  3122. });
  3123. },
  3124. underline : function() {
  3125. return this.toggle('<u></u>', {
  3126. span : '.text-decoration=underline',
  3127. u : '*'
  3128. });
  3129. },
  3130. strikethrough : function() {
  3131. return this.toggle('<s></s>', {
  3132. span : '.text-decoration=line-through',
  3133. s : '*'
  3134. });
  3135. },
  3136. forecolor : function(val) {
  3137. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3138. },
  3139. hilitecolor : function(val) {
  3140. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3141. },
  3142. fontsize : function(val) {
  3143. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3144. },
  3145. fontname : function(val) {
  3146. return this.fontfamily(val);
  3147. },
  3148. fontfamily : function(val) {
  3149. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3150. },
  3151. removeformat : function() {
  3152. var map = {
  3153. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3154. },
  3155. tags = _STYLE_TAG_MAP;
  3156. _each(tags, function(key, val) {
  3157. map[key] = '*';
  3158. });
  3159. this.remove(map);
  3160. return this.select();
  3161. },
  3162. inserthtml : function(val, quickMode) {
  3163. var self = this, range = self.range;
  3164. if (val === '') {
  3165. return self;
  3166. }
  3167. function pasteHtml(range, val) {
  3168. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3169. var rng = range.get();
  3170. if (rng.item) {
  3171. rng.item(0).outerHTML = val;
  3172. } else {
  3173. rng.pasteHTML(val);
  3174. }
  3175. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3176. temp.parentNode.removeChild(temp);
  3177. var newRange = _toRange(rng);
  3178. range.setEnd(newRange.endContainer, newRange.endOffset);
  3179. range.collapse(false);
  3180. self.select(false);
  3181. }
  3182. function insertHtml(range, val) {
  3183. var doc = range.doc,
  3184. frag = doc.createDocumentFragment();
  3185. K('@' + val, doc).each(function() {
  3186. frag.appendChild(this);
  3187. });
  3188. range.deleteContents();
  3189. range.insertNode(frag);
  3190. range.collapse(false);
  3191. self.select(false);
  3192. }
  3193. if (_IERANGE && quickMode) {
  3194. try {
  3195. pasteHtml(range, val);
  3196. } catch(e) {
  3197. insertHtml(range, val);
  3198. }
  3199. return self;
  3200. }
  3201. insertHtml(range, val);
  3202. return self;
  3203. },
  3204. hr : function() {
  3205. return this.inserthtml('<hr />');
  3206. },
  3207. print : function() {
  3208. this.win.print();
  3209. return this;
  3210. },
  3211. insertimage : function(url, title, width, height, border, align) {
  3212. title = _undef(title, '');
  3213. border = _undef(border, 0);
  3214. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3215. if (width) {
  3216. html += 'width="' + _escape(width) + '" ';
  3217. }
  3218. if (height) {
  3219. html += 'height="' + _escape(height) + '" ';
  3220. }
  3221. if (title) {
  3222. html += 'title="' + _escape(title) + '" ';
  3223. }
  3224. if (align) {
  3225. html += 'align="' + _escape(align) + '" ';
  3226. }
  3227. html += 'alt="' + _escape(title) + '" ';
  3228. html += '/>';
  3229. return this.inserthtml(html);
  3230. },
  3231. createlink : function(url, type) {
  3232. var self = this, doc = self.doc, range = self.range;
  3233. self.select();
  3234. var a = self.commonNode({ a : '*' });
  3235. if (a && !range.isControl()) {
  3236. range.selectNode(a.get());
  3237. self.select();
  3238. }
  3239. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3240. if (type) {
  3241. html += ' target="' + _escape(type) + '"';
  3242. }
  3243. if (range.collapsed) {
  3244. html += '>' + _escape(url) + '</a>';
  3245. return self.inserthtml(html);
  3246. }
  3247. if (range.isControl()) {
  3248. var node = K(range.startContainer.childNodes[range.startOffset]);
  3249. html += '></a>';
  3250. node.after(K(html, doc));
  3251. node.next().append(node);
  3252. range.selectNode(node[0]);
  3253. return self.select();
  3254. }
  3255. function setAttr(node, url, type) {
  3256. K(node).attr('href', url).attr('data-ke-src', url);
  3257. if (type) {
  3258. K(node).attr('target', type);
  3259. } else {
  3260. K(node).removeAttr('target');
  3261. }
  3262. }
  3263. var sc = range.startContainer, so = range.startOffset,
  3264. ec = range.endContainer, eo = range.endOffset;
  3265. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3266. var child = sc.childNodes[so];
  3267. if (child.nodeName.toLowerCase() == 'a') {
  3268. setAttr(child, url, type);
  3269. return self;
  3270. }
  3271. }
  3272. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3273. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3274. setAttr(this, url, type);
  3275. });
  3276. return self;
  3277. },
  3278. unlink : function() {
  3279. var self = this, doc = self.doc, range = self.range;
  3280. self.select();
  3281. if (range.collapsed) {
  3282. var a = self.commonNode({ a : '*' });
  3283. if (a) {
  3284. range.selectNode(a.get());
  3285. self.select();
  3286. }
  3287. _nativeCommand(doc, 'unlink', null);
  3288. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3289. var parent = K(range.startContainer).parent();
  3290. if (parent.name === 'a') {
  3291. parent.remove(true);
  3292. }
  3293. }
  3294. } else {
  3295. _nativeCommand(doc, 'unlink', null);
  3296. }
  3297. return self;
  3298. }
  3299. });
  3300. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3301. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3302. KCmd.prototype[name] = function(val) {
  3303. var self = this;
  3304. self.select();
  3305. _nativeCommand(self.doc, name, val);
  3306. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3307. self.selection();
  3308. }
  3309. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3310. self.selection();
  3311. }
  3312. return self;
  3313. };
  3314. });
  3315. _each('cut,copy,paste'.split(','), function(i, name) {
  3316. KCmd.prototype[name] = function() {
  3317. var self = this;
  3318. if (!self.doc.queryCommandSupported(name)) {
  3319. throw 'not supported';
  3320. }
  3321. self.select();
  3322. _nativeCommand(self.doc, name, null);
  3323. return self;
  3324. };
  3325. });
  3326. function _cmd(mixed) {
  3327. if (mixed.nodeName) {
  3328. var doc = _getDoc(mixed);
  3329. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3330. }
  3331. return new KCmd(mixed);
  3332. }
  3333. K.CmdClass = KCmd;
  3334. K.cmd = _cmd;
  3335. function _drag(options) {
  3336. var moveEl = options.moveEl,
  3337. moveFn = options.moveFn,
  3338. clickEl = options.clickEl || moveEl,
  3339. beforeDrag = options.beforeDrag,
  3340. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3341. var docs = [document];
  3342. if (iframeFix) {
  3343. K('iframe').each(function() {
  3344. var src = _formatUrl(this.src || '', 'absolute');
  3345. if (/^https?:\/\//.test(src)) {
  3346. return;
  3347. }
  3348. var doc;
  3349. try {
  3350. doc = _iframeDoc(this);
  3351. } catch(e) {}
  3352. if (doc) {
  3353. var pos = K(this).pos();
  3354. K(doc).data('pos-x', pos.x);
  3355. K(doc).data('pos-y', pos.y);
  3356. docs.push(doc);
  3357. }
  3358. });
  3359. }
  3360. clickEl.mousedown(function(e) {
  3361. if(e.button !== 0 && e.button !== 1) {
  3362. return;
  3363. }
  3364. e.stopPropagation();
  3365. var self = clickEl.get(),
  3366. x = _removeUnit(moveEl.css('left')),
  3367. y = _removeUnit(moveEl.css('top')),
  3368. width = moveEl.width(),
  3369. height = moveEl.height(),
  3370. pageX = e.pageX,
  3371. pageY = e.pageY;
  3372. if (beforeDrag) {
  3373. beforeDrag();
  3374. }
  3375. function moveListener(e) {
  3376. e.preventDefault();
  3377. var kdoc = K(_getDoc(e.target));
  3378. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3379. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3380. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3381. }
  3382. function selectListener(e) {
  3383. e.preventDefault();
  3384. }
  3385. function upListener(e) {
  3386. e.preventDefault();
  3387. K(docs).unbind('mousemove', moveListener)
  3388. .unbind('mouseup', upListener)
  3389. .unbind('selectstart', selectListener);
  3390. if (self.releaseCapture) {
  3391. self.releaseCapture();
  3392. }
  3393. }
  3394. K(docs).mousemove(moveListener)
  3395. .mouseup(upListener)
  3396. .bind('selectstart', selectListener);
  3397. if (self.setCapture) {
  3398. self.setCapture();
  3399. }
  3400. });
  3401. }
  3402. function KWidget(options) {
  3403. this.init(options);
  3404. }
  3405. _extend(KWidget, {
  3406. init : function(options) {
  3407. var self = this;
  3408. self.name = options.name || '';
  3409. self.doc = options.doc || document;
  3410. self.win = _getWin(self.doc);
  3411. self.x = _addUnit(options.x);
  3412. self.y = _addUnit(options.y);
  3413. self.z = options.z;
  3414. self.width = _addUnit(options.width);
  3415. self.height = _addUnit(options.height);
  3416. self.div = K('<div style="display:block;"></div>');
  3417. self.options = options;
  3418. self._alignEl = options.alignEl;
  3419. if (self.width) {
  3420. self.div.css('width', self.width);
  3421. }
  3422. if (self.height) {
  3423. self.div.css('height', self.height);
  3424. }
  3425. if (self.z) {
  3426. self.div.css({
  3427. position : 'absolute',
  3428. left : self.x,
  3429. top : self.y,
  3430. 'z-index' : self.z
  3431. });
  3432. }
  3433. if (self.z && (self.x === undefined || self.y === undefined)) {
  3434. self.autoPos(self.width, self.height);
  3435. }
  3436. if (options.cls) {
  3437. self.div.addClass(options.cls);
  3438. }
  3439. if (options.shadowMode) {
  3440. self.div.addClass('ke-shadow');
  3441. }
  3442. if (options.css) {
  3443. self.div.css(options.css);
  3444. }
  3445. if (options.src) {
  3446. K(options.src).replaceWith(self.div);
  3447. } else {
  3448. K(self.doc.body).append(self.div);
  3449. }
  3450. if (options.html) {
  3451. self.div.html(options.html);
  3452. }
  3453. if (options.autoScroll) {
  3454. if (_IE && _V < 7 || _QUIRKS) {
  3455. var scrollPos = _getScrollPos();
  3456. K(self.win).bind('scroll', function(e) {
  3457. var pos = _getScrollPos(),
  3458. diffX = pos.x - scrollPos.x,
  3459. diffY = pos.y - scrollPos.y;
  3460. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3461. });
  3462. } else {
  3463. self.div.css('position', 'fixed');
  3464. }
  3465. }
  3466. },
  3467. pos : function(x, y, updateProp) {
  3468. var self = this;
  3469. updateProp = _undef(updateProp, true);
  3470. if (x !== null) {
  3471. x = x < 0 ? 0 : _addUnit(x);
  3472. self.div.css('left', x);
  3473. if (updateProp) {
  3474. self.x = x;
  3475. }
  3476. }
  3477. if (y !== null) {
  3478. y = y < 0 ? 0 : _addUnit(y);
  3479. self.div.css('top', y);
  3480. if (updateProp) {
  3481. self.y = y;
  3482. }
  3483. }
  3484. return self;
  3485. },
  3486. autoPos : function(width, height) {
  3487. var x, y, self = this,
  3488. w = _removeUnit(width) || 0,
  3489. h = _removeUnit(height) || 0,
  3490. scrollPos = _getScrollPos();
  3491. if (self._alignEl) {
  3492. var knode = K(self._alignEl),
  3493. pos = knode.pos(),
  3494. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3495. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3496. x = diffX < 0 ? pos.x : pos.x + diffX;
  3497. y = diffY < 0 ? pos.y : pos.y + diffY;
  3498. } else {
  3499. var docEl = _docElement(self.doc);
  3500. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3501. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3502. }
  3503. if (!(_IE && _V < 7 || _QUIRKS)) {
  3504. x -= scrollPos.x;
  3505. y -= scrollPos.y;
  3506. }
  3507. return self.pos(x, y);
  3508. },
  3509. remove : function() {
  3510. var self = this;
  3511. if (_IE && _V < 7 || _QUIRKS) {
  3512. K(self.win).unbind('scroll');
  3513. }
  3514. self.div.remove();
  3515. _each(self, function(i) {
  3516. self[i] = null;
  3517. });
  3518. return this;
  3519. },
  3520. show : function() {
  3521. this.div.show();
  3522. return this;
  3523. },
  3524. hide : function() {
  3525. this.div.hide();
  3526. return this;
  3527. },
  3528. draggable : function(options) {
  3529. var self = this;
  3530. options = options || {};
  3531. options.moveEl = self.div;
  3532. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3533. if ((x = x + diffX) < 0) {
  3534. x = 0;
  3535. }
  3536. if ((y = y + diffY) < 0) {
  3537. y = 0;
  3538. }
  3539. self.pos(x, y);
  3540. };
  3541. _drag(options);
  3542. return self;
  3543. }
  3544. });
  3545. function _widget(options) {
  3546. return new KWidget(options);
  3547. }
  3548. K.WidgetClass = KWidget;
  3549. K.widget = _widget;
  3550. function _iframeDoc(iframe) {
  3551. iframe = _get(iframe);
  3552. return iframe.contentDocument || iframe.contentWindow.document;
  3553. }
  3554. var html, _direction = '';
  3555. if ((html = document.getElementsByTagName('html'))) {
  3556. _direction = html[0].dir;
  3557. }
  3558. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3559. var arr = [
  3560. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3561. '<head><meta charset="utf-8" /><title></title>',
  3562. '<style>',
  3563. 'html {margin:0;padding:0;}',
  3564. 'body {margin:0;padding:5px;}',
  3565. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3566. 'body, p, div {word-wrap: break-word;}',
  3567. 'p {margin:5px 0;}',
  3568. 'table {border-collapse:collapse;}',
  3569. 'img {border:0;}',
  3570. 'noscript {display:none;}',
  3571. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3572. 'img.ke-flash {',
  3573. ' border:1px solid #AAA;',
  3574. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3575. ' background-position:center center;',
  3576. ' background-repeat:no-repeat;',
  3577. ' width:100px;',
  3578. ' height:100px;',
  3579. '}',
  3580. 'img.ke-rm {',
  3581. ' border:1px solid #AAA;',
  3582. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3583. ' background-position:center center;',
  3584. ' background-repeat:no-repeat;',
  3585. ' width:100px;',
  3586. ' height:100px;',
  3587. '}',
  3588. 'img.ke-media {',
  3589. ' border:1px solid #AAA;',
  3590. ' background-image:url(' + themesPath + 'common/media.gif);',
  3591. ' background-position:center center;',
  3592. ' background-repeat:no-repeat;',
  3593. ' width:100px;',
  3594. ' height:100px;',
  3595. '}',
  3596. 'img.ke-anchor {',
  3597. ' border:1px dashed #666;',
  3598. ' width:16px;',
  3599. ' height:16px;',
  3600. '}',
  3601. '.ke-script, .ke-noscript, .ke-display-none {',
  3602. ' display:none;',
  3603. ' font-size:0;',
  3604. ' width:0;',
  3605. ' height:0;',
  3606. '}',
  3607. '.ke-pagebreak {',
  3608. ' border:1px dotted #AAA;',
  3609. ' font-size:0;',
  3610. ' height:2px;',
  3611. '}',
  3612. '</style>'
  3613. ];
  3614. if (!_isArray(cssPath)) {
  3615. cssPath = [cssPath];
  3616. }
  3617. _each(cssPath, function(i, path) {
  3618. if (path) {
  3619. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3620. }
  3621. });
  3622. if (cssData) {
  3623. arr.push('<style>' + cssData + '</style>');
  3624. }
  3625. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3626. return arr.join('\n');
  3627. }
  3628. function _elementVal(knode, val) {
  3629. if (knode.hasVal()) {
  3630. if (val === undefined) {
  3631. var html = knode.val();
  3632. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3633. return html;
  3634. }
  3635. return knode.val(val);
  3636. }
  3637. return knode.html(val);
  3638. }
  3639. function KEdit(options) {
  3640. this.init(options);
  3641. IEVersion();
  3642. }
  3643. _extend(KEdit, KWidget, {
  3644. init : function(options) {
  3645. var self = this;
  3646. KEdit.parent.init.call(self, options);
  3647. self.srcElement = K(options.srcElement);
  3648. self.div.addClass('ke-edit');
  3649. self.designMode = _undef(options.designMode, true);
  3650. self.beforeGetHtml = options.beforeGetHtml;
  3651. self.beforeSetHtml = options.beforeSetHtml;
  3652. self.afterSetHtml = options.afterSetHtml;
  3653. var themesPath = _undef(options.themesPath, ''),
  3654. bodyClass = options.bodyClass,
  3655. cssPath = options.cssPath,
  3656. cssData = options.cssData,
  3657. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3658. srcScript = ('document.open();' +
  3659. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3660. 'document.close();'),
  3661. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3662. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3663. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3664. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3665. self.iframe.attr('tabindex', self.tabIndex);
  3666. self.textarea.attr('tabindex', self.tabIndex);
  3667. if (self.width) {
  3668. self.setWidth(self.width);
  3669. }
  3670. if (self.height) {
  3671. self.setHeight(self.height);
  3672. }
  3673. if (self.designMode) {
  3674. self.textarea.hide();
  3675. } else {
  3676. self.iframe.hide();
  3677. }
  3678. function ready() {
  3679. var doc = _iframeDoc(self.iframe);
  3680. doc.open();
  3681. if (isDocumentDomain) {
  3682. doc.domain = document.domain;
  3683. }
  3684. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3685. doc.close();
  3686. self.win = self.iframe[0].contentWindow;
  3687. self.doc = doc;
  3688. var cmd = _cmd(doc);
  3689. self.afterChange(function(e) {
  3690. cmd.selection();
  3691. });
  3692. if (_WEBKIT) {
  3693. K(doc).click(function(e) {
  3694. if (K(e.target).name === 'img') {
  3695. cmd.selection(true);
  3696. cmd.range.selectNode(e.target);
  3697. cmd.select();
  3698. }
  3699. });
  3700. }
  3701. if (_IE) {
  3702. self._mousedownHandler = function() {
  3703. var newRange = cmd.range.cloneRange();
  3704. newRange.shrink();
  3705. if (newRange.isControl()) {
  3706. self.blur();
  3707. }
  3708. };
  3709. K(document).mousedown(self._mousedownHandler);
  3710. K(doc).keydown(function(e) {
  3711. if (e.which == 8) {
  3712. cmd.selection();
  3713. var rng = cmd.range;
  3714. if (rng.isControl()) {
  3715. rng.collapse(true);
  3716. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3717. e.preventDefault();
  3718. }
  3719. }
  3720. });
  3721. }
  3722. self.cmd = cmd;
  3723. self.html(_elementVal(self.srcElement));
  3724. if (_IE) {
  3725. doc.body.disabled = true;
  3726. doc.body.contentEditable = true;
  3727. doc.body.removeAttribute('disabled');
  3728. } else {
  3729. doc.designMode = 'on';
  3730. }
  3731. if (options.afterCreate) {
  3732. options.afterCreate.call(self);
  3733. }
  3734. }
  3735. if (isDocumentDomain) {
  3736. self.iframe.bind('load', function(e) {
  3737. self.iframe.unbind('load');
  3738. if (_IE) {
  3739. ready();
  3740. } else {
  3741. setTimeout(ready, 0);
  3742. }
  3743. });
  3744. }
  3745. self.div.append(self.iframe);
  3746. self.div.append(self.textarea);
  3747. self.srcElement.hide();
  3748. !isDocumentDomain && ready();
  3749. },
  3750. setWidth : function(val) {
  3751. var self = this;
  3752. val = _addUnit(val);
  3753. self.width = val;
  3754. self.div.css('width', val);
  3755. return self;
  3756. },
  3757. setHeight : function(val) {
  3758. var self = this;
  3759. val = _addUnit(val);
  3760. self.height = val;
  3761. self.div.css('height', val);
  3762. self.iframe.css('height', val);
  3763. if ((_IE && _V < 8) || _QUIRKS) {
  3764. val = _addUnit(_removeUnit(val) - 2);
  3765. }
  3766. self.textarea.css('height', val);
  3767. return self;
  3768. },
  3769. remove : function() {
  3770. var self = this, doc = self.doc;
  3771. K(doc.body).unbind();
  3772. K(doc).unbind();
  3773. K(self.win).unbind();
  3774. if (self._mousedownHandler) {
  3775. K(document).unbind('mousedown', self._mousedownHandler);
  3776. }
  3777. _elementVal(self.srcElement, self.html());
  3778. self.srcElement.show();
  3779. self.iframe.unbind();
  3780. self.textarea.unbind();
  3781. KEdit.parent.remove.call(self);
  3782. },
  3783. html : function(val, isFull) {
  3784. var self = this, doc = self.doc;
  3785. if (self.designMode) {
  3786. var body = doc.body;
  3787. if (val === undefined) {
  3788. if (isFull) {
  3789. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3790. } else {
  3791. val = body.innerHTML;
  3792. }
  3793. if (self.beforeGetHtml) {
  3794. val = self.beforeGetHtml(val);
  3795. }
  3796. if (_GECKO && val == '<br />') {
  3797. val = '';
  3798. }
  3799. return val;
  3800. }
  3801. if (self.beforeSetHtml) {
  3802. val = self.beforeSetHtml(val);
  3803. }
  3804. if (_IE && _V >= 9) {
  3805. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3806. }
  3807. K(body).html(val);
  3808. if (self.afterSetHtml) {
  3809. self.afterSetHtml();
  3810. }
  3811. return self;
  3812. }
  3813. if (val === undefined) {
  3814. return self.textarea.val();
  3815. }
  3816. self.textarea.val(val);
  3817. return self;
  3818. },
  3819. design : function(bool) {
  3820. var self = this, val;
  3821. if (bool === undefined ? !self.designMode : bool) {
  3822. if (!self.designMode) {
  3823. val = self.html();
  3824. self.designMode = true;
  3825. self.textarea.hide();
  3826. self.html(val);
  3827. var iframe = self.iframe;
  3828. var height = _removeUnit(self.height);
  3829. iframe.height(height - 2);
  3830. iframe.show();
  3831. setTimeout(function() {
  3832. iframe.height(height);
  3833. }, 0);
  3834. }
  3835. } else {
  3836. if (self.designMode) {
  3837. val = self.html();
  3838. self.designMode = false;
  3839. self.html(val);
  3840. self.iframe.hide();
  3841. self.textarea.show();
  3842. }
  3843. }
  3844. return self.focus();
  3845. },
  3846. focus : function() {
  3847. var self = this;
  3848. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3849. return self;
  3850. },
  3851. blur : function() {
  3852. var self = this;
  3853. if (_IE) {
  3854. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3855. self.div.append(input);
  3856. input[0].focus();
  3857. input.remove();
  3858. } else {
  3859. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3860. }
  3861. return self;
  3862. },
  3863. afterChange : function(fn) {
  3864. var self = this, doc = self.doc, body = doc.body;
  3865. K(doc).keyup(function(e) {
  3866. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3867. fn(e);
  3868. }
  3869. });
  3870. K(doc).mouseup(fn).contextmenu(fn);
  3871. K(self.win).blur(fn);
  3872. function timeoutHandler(e) {
  3873. setTimeout(function() {
  3874. fn(e);
  3875. }, 1);
  3876. }
  3877. K(body).bind('paste', timeoutHandler);
  3878. K(body).bind('cut', timeoutHandler);
  3879. return self;
  3880. }
  3881. });
  3882. function _edit(options) {
  3883. return new KEdit(options);
  3884. }
  3885. K.EditClass = KEdit;
  3886. K.edit = _edit;
  3887. K.iframeDoc = _iframeDoc;
  3888. function _selectToolbar(name, fn) {
  3889. var self = this,
  3890. knode = self.get(name);
  3891. if (knode) {
  3892. if (knode.hasClass('ke-disabled')) {
  3893. return;
  3894. }
  3895. fn(knode);
  3896. }
  3897. }
  3898. function KToolbar(options) {
  3899. this.init(options);
  3900. }
  3901. _extend(KToolbar, KWidget, {
  3902. init : function(options) {
  3903. var self = this;
  3904. KToolbar.parent.init.call(self, options);
  3905. self.disableMode = _undef(options.disableMode, false);
  3906. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3907. self._itemMap = {};
  3908. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3909. e.preventDefault();
  3910. }).attr('unselectable', 'on');
  3911. function find(target) {
  3912. var knode = K(target);
  3913. if (knode.hasClass('ke-outline')) {
  3914. return knode;
  3915. }
  3916. if (knode.hasClass('ke-toolbar-icon')) {
  3917. return knode.parent();
  3918. }
  3919. }
  3920. function hover(e, method) {
  3921. var knode = find(e.target);
  3922. if (knode) {
  3923. if (knode.hasClass('ke-disabled')) {
  3924. return;
  3925. }
  3926. if (knode.hasClass('ke-selected')) {
  3927. return;
  3928. }
  3929. knode[method]('ke-on');
  3930. }
  3931. }
  3932. self.div.mouseover(function(e) {
  3933. hover(e, 'addClass');
  3934. })
  3935. .mouseout(function(e) {
  3936. hover(e, 'removeClass');
  3937. })
  3938. .click(function(e) {
  3939. var knode = find(e.target);
  3940. if (knode) {
  3941. if (knode.hasClass('ke-disabled')) {
  3942. return;
  3943. }
  3944. self.options.click.call(this, e, knode.attr('data-name'));
  3945. }
  3946. });
  3947. },
  3948. get : function(name) {
  3949. if (this._itemMap[name]) {
  3950. return this._itemMap[name];
  3951. }
  3952. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3953. },
  3954. select : function(name) {
  3955. _selectToolbar.call(this, name, function(knode) {
  3956. knode.addClass('ke-selected');
  3957. });
  3958. return self;
  3959. },
  3960. unselect : function(name) {
  3961. _selectToolbar.call(this, name, function(knode) {
  3962. knode.removeClass('ke-selected').removeClass('ke-on');
  3963. });
  3964. return self;
  3965. },
  3966. enable : function(name) {
  3967. var self = this,
  3968. knode = name.get ? name : self.get(name);
  3969. if (knode) {
  3970. knode.removeClass('ke-disabled');
  3971. knode.opacity(1);
  3972. }
  3973. return self;
  3974. },
  3975. disable : function(name) {
  3976. var self = this,
  3977. knode = name.get ? name : self.get(name);
  3978. if (knode) {
  3979. knode.removeClass('ke-selected').addClass('ke-disabled');
  3980. knode.opacity(0.5);
  3981. }
  3982. return self;
  3983. },
  3984. disableAll : function(bool, noDisableItems) {
  3985. var self = this, map = self.noDisableItemMap, item;
  3986. if (noDisableItems) {
  3987. map = _toMap(noDisableItems);
  3988. }
  3989. if (bool === undefined ? !self.disableMode : bool) {
  3990. K('span.ke-outline', self.div).each(function() {
  3991. var knode = K(this),
  3992. name = knode[0].getAttribute('data-name', 2);
  3993. if (!map[name]) {
  3994. self.disable(knode);
  3995. }
  3996. });
  3997. self.disableMode = true;
  3998. } else {
  3999. K('span.ke-outline', self.div).each(function() {
  4000. var knode = K(this),
  4001. name = knode[0].getAttribute('data-name', 2);
  4002. if (!map[name]) {
  4003. self.enable(knode);
  4004. }
  4005. });
  4006. self.disableMode = false;
  4007. }
  4008. return self;
  4009. }
  4010. });
  4011. function _toolbar(options) {
  4012. return new KToolbar(options);
  4013. }
  4014. K.ToolbarClass = KToolbar;
  4015. K.toolbar = _toolbar;
  4016. function KMenu(options) {
  4017. this.init(options);
  4018. }
  4019. _extend(KMenu, KWidget, {
  4020. init : function(options) {
  4021. var self = this;
  4022. options.z = options.z || 811213;
  4023. KMenu.parent.init.call(self, options);
  4024. self.centerLineMode = _undef(options.centerLineMode, true);
  4025. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4026. e.stopPropagation();
  4027. }).attr('unselectable', 'on');
  4028. },
  4029. addItem : function(item) {
  4030. var self = this;
  4031. if (item.title === '-') {
  4032. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4033. return;
  4034. }
  4035. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4036. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4037. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4038. height = _addUnit(item.height),
  4039. iconClass = _undef(item.iconClass, '');
  4040. self.div.append(itemDiv);
  4041. if (height) {
  4042. itemDiv.css('height', height);
  4043. rightDiv.css('line-height', height);
  4044. }
  4045. var centerDiv;
  4046. if (self.centerLineMode) {
  4047. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4048. if (height) {
  4049. centerDiv.css('height', height);
  4050. }
  4051. }
  4052. itemDiv.mouseover(function(e) {
  4053. K(this).addClass('ke-menu-item-on');
  4054. if (centerDiv) {
  4055. centerDiv.addClass('ke-menu-item-center-on');
  4056. }
  4057. })
  4058. .mouseout(function(e) {
  4059. K(this).removeClass('ke-menu-item-on');
  4060. if (centerDiv) {
  4061. centerDiv.removeClass('ke-menu-item-center-on');
  4062. }
  4063. })
  4064. .click(function(e) {
  4065. item.click.call(K(this));
  4066. e.stopPropagation();
  4067. })
  4068. .append(leftDiv);
  4069. if (centerDiv) {
  4070. itemDiv.append(centerDiv);
  4071. }
  4072. itemDiv.append(rightDiv);
  4073. if (item.checked) {
  4074. iconClass = 'ke-icon-checked';
  4075. }
  4076. if (iconClass !== '') {
  4077. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4078. }
  4079. rightDiv.html(item.title);
  4080. return self;
  4081. },
  4082. remove : function() {
  4083. var self = this;
  4084. if (self.options.beforeRemove) {
  4085. self.options.beforeRemove.call(self);
  4086. }
  4087. K('.ke-menu-item', self.div[0]).unbind();
  4088. KMenu.parent.remove.call(self);
  4089. return self;
  4090. }
  4091. });
  4092. function _menu(options) {
  4093. return new KMenu(options);
  4094. }
  4095. K.MenuClass = KMenu;
  4096. K.menu = _menu;
  4097. function KColorPicker(options) {
  4098. this.init(options);
  4099. }
  4100. _extend(KColorPicker, KWidget, {
  4101. init : function(options) {
  4102. var self = this;
  4103. options.z = options.z || 811213;
  4104. KColorPicker.parent.init.call(self, options);
  4105. var colors = options.colors || [
  4106. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4107. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4108. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4109. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4110. ];
  4111. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4112. self._cells = [];
  4113. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4114. e.stopPropagation();
  4115. }).attr('unselectable', 'on');
  4116. var table = self.doc.createElement('table');
  4117. self.div.append(table);
  4118. table.className = 'ke-colorpicker-table';
  4119. table.cellPadding = 0;
  4120. table.cellSpacing = 0;
  4121. table.border = 0;
  4122. var row = table.insertRow(0), cell = row.insertCell(0);
  4123. cell.colSpan = colors[0].length;
  4124. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4125. for (var i = 0; i < colors.length; i++) {
  4126. row = table.insertRow(i + 1);
  4127. for (var j = 0; j < colors[i].length; j++) {
  4128. cell = row.insertCell(j);
  4129. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4130. }
  4131. }
  4132. },
  4133. _addAttr : function(cell, color, cls) {
  4134. var self = this;
  4135. cell = K(cell).addClass(cls);
  4136. if (self.selectedColor === color.toLowerCase()) {
  4137. cell.addClass('ke-colorpicker-cell-selected');
  4138. }
  4139. cell.attr('title', color || self.options.noColor);
  4140. cell.mouseover(function(e) {
  4141. K(this).addClass('ke-colorpicker-cell-on');
  4142. });
  4143. cell.mouseout(function(e) {
  4144. K(this).removeClass('ke-colorpicker-cell-on');
  4145. });
  4146. cell.click(function(e) {
  4147. e.stop();
  4148. self.options.click.call(K(this), color);
  4149. });
  4150. if (color) {
  4151. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4152. } else {
  4153. cell.html(self.options.noColor);
  4154. }
  4155. K(cell).attr('unselectable', 'on');
  4156. self._cells.push(cell);
  4157. },
  4158. remove : function() {
  4159. var self = this;
  4160. _each(self._cells, function() {
  4161. this.unbind();
  4162. });
  4163. KColorPicker.parent.remove.call(self);
  4164. return self;
  4165. }
  4166. });
  4167. function _colorpicker(options) {
  4168. return new KColorPicker(options);
  4169. }
  4170. K.ColorPickerClass = KColorPicker;
  4171. K.colorpicker = _colorpicker;
  4172. function KUploadButton(options) {
  4173. this.init(options);
  4174. }
  4175. _extend(KUploadButton, {
  4176. init : function(options) {
  4177. var self = this,
  4178. button = K(options.button),
  4179. fieldName = options.fieldName || 'file',
  4180. url = options.url || '',
  4181. title = button.val(),
  4182. extraParams = options.extraParams || {},
  4183. cls = button[0].className || '',
  4184. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4185. options.afterError = options.afterError || function(str) {
  4186. alert(str);
  4187. };
  4188. var hiddenElements = [];
  4189. for(var k in extraParams){
  4190. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4191. }
  4192. var html = [
  4193. '<div class="ke-inline-block ' + cls + '">',
  4194. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4195. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4196. '<span class="ke-button-common">',
  4197. hiddenElements.join(''),
  4198. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4199. '</span>',
  4200. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4201. (options.form ? '</div>' : '</form>'),
  4202. '</div>'].join('');
  4203. var div = K(html, button.doc);
  4204. button.hide();
  4205. button.before(div);
  4206. self.div = div;
  4207. self.button = button;
  4208. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4209. self.form = options.form ? K(options.form) : K('form', div);
  4210. self.fileBox = K('.ke-upload-file', div);
  4211. var width = options.width || K('.ke-button-common', div).width();
  4212. K('.ke-upload-area', div).width(width);
  4213. self.options = options;
  4214. },
  4215. submit : function() {
  4216. var self = this,
  4217. iframe = self.iframe;
  4218. iframe.bind('load', function() {
  4219. iframe.unbind();
  4220. var tempForm = document.createElement('form');
  4221. self.fileBox.before(tempForm);
  4222. K(tempForm).append(self.fileBox);
  4223. tempForm.reset();
  4224. K(tempForm).remove(true);
  4225. var doc = K.iframeDoc(iframe),
  4226. pre = doc.getElementsByTagName('pre')[0],
  4227. str = '', data;
  4228. if (pre) {
  4229. str = pre.innerHTML;
  4230. } else {
  4231. str = doc.body.innerHTML;
  4232. }
  4233. str = _unescape(str);
  4234. iframe[0].src = 'javascript:false';
  4235. try {
  4236. data = K.json(str);
  4237. } catch (e) {
  4238. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4239. }
  4240. if (data) {
  4241. self.options.afterUpload.call(self, data);
  4242. }
  4243. });
  4244. self.form[0].submit();
  4245. return self;
  4246. },
  4247. remove : function() {
  4248. var self = this;
  4249. if (self.fileBox) {
  4250. self.fileBox.unbind();
  4251. }
  4252. self.iframe.remove();
  4253. self.div.remove();
  4254. self.button.show();
  4255. return self;
  4256. }
  4257. });
  4258. function _uploadbutton(options) {
  4259. return new KUploadButton(options);
  4260. }
  4261. K.UploadButtonClass = KUploadButton;
  4262. K.uploadbutton = _uploadbutton;
  4263. function _createButton(arg) {
  4264. arg = arg || {};
  4265. var name = arg.name || '',
  4266. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4267. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4268. if (arg.click) {
  4269. btn.click(arg.click);
  4270. }
  4271. span.append(btn);
  4272. return span;
  4273. }
  4274. function KDialog(options) {
  4275. this.init(options);
  4276. }
  4277. _extend(KDialog, KWidget, {
  4278. init : function(options) {
  4279. var self = this;
  4280. var shadowMode = _undef(options.shadowMode, true);
  4281. options.z = options.z || 811213;
  4282. options.shadowMode = false;
  4283. options.autoScroll = _undef(options.autoScroll, true);
  4284. KDialog.parent.init.call(self, options);
  4285. var title = options.title,
  4286. body = K(options.body, self.doc),
  4287. previewBtn = options.previewBtn,
  4288. yesBtn = options.yesBtn,
  4289. noBtn = options.noBtn,
  4290. closeBtn = options.closeBtn,
  4291. showMask = _undef(options.showMask, true);
  4292. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4293. e.stopPropagation();
  4294. });
  4295. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4296. if (_IE && _V < 7) {
  4297. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4298. } else if (shadowMode) {
  4299. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4300. }
  4301. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4302. contentDiv.append(headerDiv);
  4303. headerDiv.html(title);
  4304. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4305. headerDiv.append(self.closeIcon);
  4306. self.draggable({
  4307. clickEl : headerDiv,
  4308. beforeDrag : options.beforeDrag
  4309. });
  4310. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4311. contentDiv.append(bodyDiv);
  4312. bodyDiv.append(body);
  4313. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4314. if (previewBtn || yesBtn || noBtn) {
  4315. contentDiv.append(footerDiv);
  4316. }
  4317. _each([
  4318. { btn : previewBtn, name : 'preview' },
  4319. { btn : yesBtn, name : 'yes' },
  4320. { btn : noBtn, name : 'no' }
  4321. ], function() {
  4322. if (this.btn) {
  4323. var button = _createButton(this.btn);
  4324. button.addClass('ke-dialog-' + this.name);
  4325. footerDiv.append(button);
  4326. }
  4327. });
  4328. if (self.height) {
  4329. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4330. }
  4331. self.div.width(self.div.width());
  4332. self.div.height(self.div.height());
  4333. self.mask = null;
  4334. if (showMask) {
  4335. var docEl = _docElement(self.doc),
  4336. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4337. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4338. self.mask = _widget({
  4339. x : 0,
  4340. y : 0,
  4341. z : self.z - 1,
  4342. cls : 'ke-dialog-mask',
  4343. width : docWidth,
  4344. height : docHeight
  4345. });
  4346. }
  4347. self.autoPos(self.div.width(), self.div.height());
  4348. self.footerDiv = footerDiv;
  4349. self.bodyDiv = bodyDiv;
  4350. self.headerDiv = headerDiv;
  4351. self.isLoading = false;
  4352. },
  4353. setMaskIndex : function(z) {
  4354. var self = this;
  4355. self.mask.div.css('z-index', z);
  4356. },
  4357. showLoading : function(msg) {
  4358. msg = _undef(msg, '');
  4359. var self = this, body = self.bodyDiv;
  4360. 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>')
  4361. .width(body.width()).height(body.height())
  4362. .css('top', self.headerDiv.height() + 'px');
  4363. body.css('visibility', 'hidden').after(self.loading);
  4364. self.isLoading = true;
  4365. return self;
  4366. },
  4367. hideLoading : function() {
  4368. this.loading && this.loading.remove();
  4369. this.bodyDiv.css('visibility', 'visible');
  4370. this.isLoading = false;
  4371. return this;
  4372. },
  4373. remove : function() {
  4374. var self = this;
  4375. if (self.options.beforeRemove) {
  4376. self.options.beforeRemove.call(self);
  4377. }
  4378. self.mask && self.mask.remove();
  4379. self.iframeMask && self.iframeMask.remove();
  4380. self.closeIcon.unbind();
  4381. K('input', self.div).unbind();
  4382. K('button', self.div).unbind();
  4383. self.footerDiv.unbind();
  4384. self.bodyDiv.unbind();
  4385. self.headerDiv.unbind();
  4386. K('iframe', self.div).each(function() {
  4387. K(this).remove();
  4388. });
  4389. KDialog.parent.remove.call(self);
  4390. return self;
  4391. }
  4392. });
  4393. function _dialog(options) {
  4394. return new KDialog(options);
  4395. }
  4396. K.DialogClass = KDialog;
  4397. K.dialog = _dialog;
  4398. function _tabs(options) {
  4399. var self = _widget(options),
  4400. remove = self.remove,
  4401. afterSelect = options.afterSelect,
  4402. div = self.div,
  4403. liList = [];
  4404. div.addClass('ke-tabs')
  4405. .bind('contextmenu,mousedown,mousemove', function(e) {
  4406. e.preventDefault();
  4407. });
  4408. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4409. div.append(ul);
  4410. self.add = function(tab) {
  4411. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4412. li.data('tab', tab);
  4413. liList.push(li);
  4414. ul.append(li);
  4415. };
  4416. self.selectedIndex = 0;
  4417. self.select = function(index) {
  4418. self.selectedIndex = index;
  4419. _each(liList, function(i, li) {
  4420. li.unbind();
  4421. if (i === index) {
  4422. li.addClass('ke-tabs-li-selected');
  4423. K(li.data('tab').panel).show('');
  4424. } else {
  4425. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4426. .mouseover(function() {
  4427. K(this).addClass('ke-tabs-li-on');
  4428. })
  4429. .mouseout(function() {
  4430. K(this).removeClass('ke-tabs-li-on');
  4431. })
  4432. .click(function() {
  4433. self.select(i);
  4434. });
  4435. K(li.data('tab').panel).hide();
  4436. }
  4437. });
  4438. if (afterSelect) {
  4439. afterSelect.call(self, index);
  4440. }
  4441. };
  4442. self.remove = function() {
  4443. _each(liList, function() {
  4444. this.remove();
  4445. });
  4446. ul.remove();
  4447. remove.call(self);
  4448. };
  4449. return self;
  4450. }
  4451. K.tabs = _tabs;
  4452. function _loadScript(url, fn) {
  4453. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4454. script = document.createElement('script');
  4455. head.appendChild(script);
  4456. script.src = url;
  4457. script.charset = 'utf-8';
  4458. script.onload = script.onreadystatechange = function() {
  4459. if (!this.readyState || this.readyState === 'loaded') {
  4460. if (fn) {
  4461. fn();
  4462. }
  4463. script.onload = script.onreadystatechange = null;
  4464. head.removeChild(script);
  4465. }
  4466. };
  4467. }
  4468. function _chopQuery(url) {
  4469. var index = url.indexOf('?');
  4470. return index > 0 ? url.substr(0, index) : url;
  4471. }
  4472. function _loadStyle(url) {
  4473. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4474. link = document.createElement('link'),
  4475. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4476. var links = K('link[rel="stylesheet"]', head);
  4477. for (var i = 0, len = links.length; i < len; i++) {
  4478. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4479. return;
  4480. }
  4481. }
  4482. head.appendChild(link);
  4483. link.href = url;
  4484. link.rel = 'stylesheet';
  4485. }
  4486. function _ajax(url, fn, method, param, dataType) {
  4487. method = method || 'GET';
  4488. dataType = dataType || 'json';
  4489. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4490. xhr.open(method, url, true);
  4491. xhr.onreadystatechange = function () {
  4492. if (xhr.readyState == 4 && xhr.status == 200) {
  4493. if (fn) {
  4494. var data = _trim(xhr.responseText);
  4495. if (dataType == 'json') {
  4496. data = _json(data);
  4497. }
  4498. fn(data);
  4499. }
  4500. }
  4501. };
  4502. if (method == 'POST') {
  4503. var params = [];
  4504. _each(param, function(key, val) {
  4505. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4506. });
  4507. try {
  4508. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4509. } catch (e) {}
  4510. xhr.send(params.join('&'));
  4511. } else {
  4512. xhr.send(null);
  4513. }
  4514. }
  4515. K.loadScript = _loadScript;
  4516. K.loadStyle = _loadStyle;
  4517. K.ajax = _ajax;
  4518. var _plugins = {};
  4519. function _plugin(name, fn) {
  4520. if (name === undefined) {
  4521. return _plugins;
  4522. }
  4523. if (!fn) {
  4524. return _plugins[name];
  4525. }
  4526. _plugins[name] = fn;
  4527. }
  4528. var _language = {};
  4529. function _parseLangKey(key) {
  4530. var match, ns = 'core';
  4531. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4532. ns = match[1];
  4533. key = match[2];
  4534. }
  4535. return { ns : ns, key : key };
  4536. }
  4537. function _lang(mixed, langType) {
  4538. langType = langType === undefined ? K.options.langType : langType;
  4539. if (typeof mixed === 'string') {
  4540. if (!_language[langType]) {
  4541. return 'no language';
  4542. }
  4543. var pos = mixed.length - 1;
  4544. if (mixed.substr(pos) === '.') {
  4545. return _language[langType][mixed.substr(0, pos)];
  4546. }
  4547. var obj = _parseLangKey(mixed);
  4548. return _language[langType][obj.ns][obj.key];
  4549. }
  4550. _each(mixed, function(key, val) {
  4551. var obj = _parseLangKey(key);
  4552. if (!_language[langType]) {
  4553. _language[langType] = {};
  4554. }
  4555. if (!_language[langType][obj.ns]) {
  4556. _language[langType][obj.ns] = {};
  4557. }
  4558. _language[langType][obj.ns][obj.key] = val;
  4559. });
  4560. }
  4561. function _getImageFromRange(range, fn) {
  4562. if (range.collapsed) {
  4563. return;
  4564. }
  4565. range = range.cloneRange().up();
  4566. var sc = range.startContainer, so = range.startOffset;
  4567. if (!_WEBKIT && !range.isControl()) {
  4568. return;
  4569. }
  4570. var img = K(sc.childNodes[so]);
  4571. if (!img || img.name != 'img') {
  4572. return;
  4573. }
  4574. if (fn(img)) {
  4575. return img;
  4576. }
  4577. }
  4578. function _bindContextmenuEvent() {
  4579. var self = this, doc = self.edit.doc;
  4580. K(doc).contextmenu(function(e) {
  4581. if (self.menu) {
  4582. self.hideMenu();
  4583. }
  4584. if (!self.useContextmenu) {
  4585. e.preventDefault();
  4586. return;
  4587. }
  4588. if (self._contextmenus.length === 0) {
  4589. return;
  4590. }
  4591. var maxWidth = 0, items = [];
  4592. _each(self._contextmenus, function() {
  4593. if (this.title == '-') {
  4594. items.push(this);
  4595. return;
  4596. }
  4597. if (this.cond && this.cond()) {
  4598. items.push(this);
  4599. if (this.width && this.width > maxWidth) {
  4600. maxWidth = this.width;
  4601. }
  4602. }
  4603. });
  4604. while (items.length > 0 && items[0].title == '-') {
  4605. items.shift();
  4606. }
  4607. while (items.length > 0 && items[items.length - 1].title == '-') {
  4608. items.pop();
  4609. }
  4610. var prevItem = null;
  4611. _each(items, function(i) {
  4612. if (this.title == '-' && prevItem.title == '-') {
  4613. delete items[i];
  4614. }
  4615. prevItem = this;
  4616. });
  4617. if (items.length > 0) {
  4618. e.preventDefault();
  4619. var pos = K(self.edit.iframe).pos(),
  4620. menu = _menu({
  4621. x : pos.x + e.clientX,
  4622. y : pos.y + e.clientY,
  4623. width : maxWidth,
  4624. css : { visibility: 'hidden' },
  4625. shadowMode : self.shadowMode
  4626. });
  4627. _each(items, function() {
  4628. if (this.title) {
  4629. menu.addItem(this);
  4630. }
  4631. });
  4632. var docEl = _docElement(menu.doc),
  4633. menuHeight = menu.div.height();
  4634. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4635. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4636. }
  4637. menu.div.css('visibility', 'visible');
  4638. self.menu = menu;
  4639. }
  4640. });
  4641. }
  4642. function _bindNewlineEvent() {
  4643. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4644. if (_IE && newlineTag !== 'br') {
  4645. return;
  4646. }
  4647. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4648. return;
  4649. }
  4650. if (_OPERA && _V < 9) {
  4651. return;
  4652. }
  4653. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4654. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4655. function getAncestorTagName(range) {
  4656. var ancestor = K(range.commonAncestor());
  4657. while (ancestor) {
  4658. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4659. break;
  4660. }
  4661. ancestor = ancestor.parent();
  4662. }
  4663. return ancestor.name;
  4664. }
  4665. K(doc).keydown(function(e) {
  4666. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4667. return;
  4668. }
  4669. self.cmd.selection();
  4670. var tagName = getAncestorTagName(self.cmd.range);
  4671. if (tagName == 'marquee' || tagName == 'select') {
  4672. return;
  4673. }
  4674. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4675. e.preventDefault();
  4676. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4677. return;
  4678. }
  4679. if (!pSkipTagMap[tagName]) {
  4680. _nativeCommand(doc, 'formatblock', '<p>');
  4681. }
  4682. });
  4683. K(doc).keyup(function(e) {
  4684. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4685. return;
  4686. }
  4687. if (newlineTag == 'br') {
  4688. return;
  4689. }
  4690. if (_GECKO) {
  4691. var root = self.cmd.commonAncestor('p');
  4692. var a = self.cmd.commonAncestor('a');
  4693. if (a && a.text() == '') {
  4694. a.remove(true);
  4695. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4696. self.cmd.select();
  4697. }
  4698. return;
  4699. }
  4700. self.cmd.selection();
  4701. var tagName = getAncestorTagName(self.cmd.range);
  4702. if (tagName == 'marquee' || tagName == 'select') {
  4703. return;
  4704. }
  4705. if (!pSkipTagMap[tagName]) {
  4706. _nativeCommand(doc, 'formatblock', '<p>');
  4707. }
  4708. var div = self.cmd.commonAncestor('div');
  4709. if (div) {
  4710. var p = K('<p></p>'),
  4711. child = div[0].firstChild;
  4712. while (child) {
  4713. var next = child.nextSibling;
  4714. p.append(child);
  4715. child = next;
  4716. }
  4717. div.before(p);
  4718. div.remove();
  4719. self.cmd.range.selectNodeContents(p[0]);
  4720. self.cmd.select();
  4721. }
  4722. });
  4723. }
  4724. function _bindTabEvent() {
  4725. var self = this, doc = self.edit.doc;
  4726. K(doc).keydown(function(e) {
  4727. if (e.which == 9) {
  4728. e.preventDefault();
  4729. if (self.afterTab) {
  4730. self.afterTab.call(self, e);
  4731. return;
  4732. }
  4733. var cmd = self.cmd, range = cmd.range;
  4734. range.shrink();
  4735. if (range.collapsed && range.startContainer.nodeType == 1) {
  4736. range.insertNode(K('@&nbsp;', doc)[0]);
  4737. cmd.select();
  4738. }
  4739. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4740. }
  4741. });
  4742. }
  4743. function _bindFocusEvent() {
  4744. var self = this;
  4745. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4746. if (self.afterFocus) {
  4747. self.afterFocus.call(self, e);
  4748. }
  4749. }).blur(function(e) {
  4750. if (self.afterBlur) {
  4751. self.afterBlur.call(self, e);
  4752. }
  4753. });
  4754. }
  4755. function _removeBookmarkTag(html) {
  4756. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4757. }
  4758. function _removeTempTag(html) {
  4759. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4760. }
  4761. function _addBookmarkToStack(stack, bookmark) {
  4762. if (stack.length === 0) {
  4763. stack.push(bookmark);
  4764. return;
  4765. }
  4766. var prev = stack[stack.length - 1];
  4767. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4768. stack.push(bookmark);
  4769. }
  4770. }
  4771. function _undoToRedo(fromStack, toStack) {
  4772. var self = this, edit = self.edit,
  4773. body = edit.doc.body,
  4774. range, bookmark;
  4775. if (fromStack.length === 0) {
  4776. return self;
  4777. }
  4778. if (edit.designMode) {
  4779. range = self.cmd.range;
  4780. bookmark = range.createBookmark(true);
  4781. bookmark.html = body.innerHTML;
  4782. } else {
  4783. bookmark = {
  4784. html : body.innerHTML
  4785. };
  4786. }
  4787. _addBookmarkToStack(toStack, bookmark);
  4788. var prev = fromStack.pop();
  4789. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4790. prev = fromStack.pop();
  4791. }
  4792. if (edit.designMode) {
  4793. edit.html(prev.html);
  4794. if (prev.start) {
  4795. range.moveToBookmark(prev);
  4796. self.select();
  4797. }
  4798. } else {
  4799. K(body).html(_removeBookmarkTag(prev.html));
  4800. }
  4801. return self;
  4802. }
  4803. function KEditor(options) {
  4804. var self = this;
  4805. self.options = {};
  4806. function setOption(key, val) {
  4807. if (KEditor.prototype[key] === undefined) {
  4808. self[key] = val;
  4809. }
  4810. self.options[key] = val;
  4811. }
  4812. _each(options, function(key, val) {
  4813. setOption(key, options[key]);
  4814. });
  4815. _each(K.options, function(key, val) {
  4816. if (self[key] === undefined) {
  4817. setOption(key, val);
  4818. }
  4819. });
  4820. var se = K(self.srcElement || '<textarea/>');
  4821. if (!self.width) {
  4822. self.width = se[0].style.width || se.width();
  4823. }
  4824. if (!self.height) {
  4825. self.height = se[0].style.height || se.height();
  4826. }
  4827. setOption('width', _undef(self.width, self.minWidth));
  4828. setOption('height', _undef(self.height, self.minHeight));
  4829. setOption('width', _addUnit(self.width));
  4830. setOption('height', _addUnit(self.height));
  4831. if (_MOBILE && (!_IOS || _V < 534)) {
  4832. self.designMode = false;
  4833. }
  4834. self.srcElement = se;
  4835. self.initContent = '';
  4836. self.plugin = {};
  4837. self.isCreated = false;
  4838. self._handlers = {};
  4839. self._contextmenus = [];
  4840. self._undoStack = [];
  4841. self._redoStack = [];
  4842. self._firstAddBookmark = true;
  4843. self.menu = self.contextmenu = null;
  4844. self.dialogs = [];
  4845. }
  4846. KEditor.prototype = {
  4847. lang : function(mixed) {
  4848. return _lang(mixed, this.langType);
  4849. },
  4850. loadPlugin : function(name, fn) {
  4851. var self = this;
  4852. var _pluginStatus = this._pluginStatus;
  4853. if (!_pluginStatus) {
  4854. _pluginStatus = this._pluginStatus = {};
  4855. }
  4856. if (_plugins[name]) {
  4857. if (!_isFunction(_plugins[name])) {
  4858. setTimeout(function() {
  4859. self.loadPlugin(name, fn);
  4860. }, 100);
  4861. return self;
  4862. }
  4863. if(!_pluginStatus[name]) {
  4864. _plugins[name].call(self, KindEditor);
  4865. _pluginStatus[name] = 'inited';
  4866. }
  4867. if (fn) {
  4868. fn.call(self);
  4869. }
  4870. return self;
  4871. }
  4872. _plugins[name] = 'loading';
  4873. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4874. setTimeout(function() {
  4875. if (_plugins[name]) {
  4876. self.loadPlugin(name, fn);
  4877. }
  4878. }, 0);
  4879. });
  4880. return self;
  4881. },
  4882. handler : function(key, fn) {
  4883. var self = this;
  4884. if (!self._handlers[key]) {
  4885. self._handlers[key] = [];
  4886. }
  4887. if (_isFunction(fn)) {
  4888. self._handlers[key].push(fn);
  4889. return self;
  4890. }
  4891. _each(self._handlers[key], function() {
  4892. fn = this.call(self, fn);
  4893. });
  4894. return fn;
  4895. },
  4896. clickToolbar : function(name, fn) {
  4897. var self = this, key = 'clickToolbar' + name;
  4898. if (fn === undefined) {
  4899. if (self._handlers[key]) {
  4900. return self.handler(key);
  4901. }
  4902. self.loadPlugin(name, function() {
  4903. self.handler(key);
  4904. });
  4905. return self;
  4906. }
  4907. return self.handler(key, fn);
  4908. },
  4909. updateState : function() {
  4910. var self = this;
  4911. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4912. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4913. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4914. });
  4915. return self;
  4916. },
  4917. addContextmenu : function(item) {
  4918. this._contextmenus.push(item);
  4919. return this;
  4920. },
  4921. afterCreate : function(fn) {
  4922. return this.handler('afterCreate', fn);
  4923. },
  4924. beforeRemove : function(fn) {
  4925. return this.handler('beforeRemove', fn);
  4926. },
  4927. beforeGetHtml : function(fn) {
  4928. return this.handler('beforeGetHtml', fn);
  4929. },
  4930. beforeSetHtml : function(fn) {
  4931. return this.handler('beforeSetHtml', fn);
  4932. },
  4933. afterSetHtml : function(fn) {
  4934. return this.handler('afterSetHtml', fn);
  4935. },
  4936. create : function() {
  4937. var self = this, fullscreenMode = self.fullscreenMode;
  4938. if (self.isCreated) {
  4939. return self;
  4940. }
  4941. if (self.srcElement.data('kindeditor')) {
  4942. return self;
  4943. }
  4944. self.srcElement.data('kindeditor', 'true');
  4945. if (fullscreenMode) {
  4946. _docElement().style.overflow = 'hidden';
  4947. } else {
  4948. _docElement().style.overflow = '';
  4949. }
  4950. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4951. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4952. if ((_IE && _V < 8) || _QUIRKS) {
  4953. height = _addUnit(_removeUnit(height) + 2);
  4954. }
  4955. var container = self.container = K(self.layout);
  4956. if (fullscreenMode) {
  4957. K(document.body).append(container);
  4958. } else {
  4959. self.srcElement.before(container);
  4960. }
  4961. var toolbarDiv = K('.toolbar', container),
  4962. editDiv = K('.edit', container),
  4963. statusbar = self.statusbar = K('.statusbar', container);
  4964. container.removeClass('container')
  4965. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4966. if (fullscreenMode) {
  4967. container.css({
  4968. position : 'absolute',
  4969. left : 0,
  4970. top : 0,
  4971. 'z-index' : 811211
  4972. });
  4973. if (!_GECKO) {
  4974. self._scrollPos = _getScrollPos();
  4975. }
  4976. window.scrollTo(0, 0);
  4977. K(document.body).css({
  4978. 'height' : '1px',
  4979. 'overflow' : 'hidden'
  4980. });
  4981. K(document.body.parentNode).css('overflow', 'hidden');
  4982. self._fullscreenExecuted = true;
  4983. } else {
  4984. if (self._fullscreenExecuted) {
  4985. K(document.body).css({
  4986. 'height' : '',
  4987. 'overflow' : ''
  4988. });
  4989. K(document.body.parentNode).css('overflow', '');
  4990. }
  4991. if (self._scrollPos) {
  4992. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4993. }
  4994. }
  4995. var htmlList = [];
  4996. K.each(self.items, function(i, name) {
  4997. if (name == '|') {
  4998. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4999. } else if (name == '/') {
  5000. htmlList.push('<div class="ke-hr"></div>');
  5001. } else {
  5002. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  5003. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  5004. }
  5005. });
  5006. var toolbar = self.toolbar = _toolbar({
  5007. src : toolbarDiv,
  5008. html : htmlList.join(''),
  5009. noDisableItems : self.noDisableItems,
  5010. click : function(e, name) {
  5011. e.stop();
  5012. if (self.menu) {
  5013. var menuName = self.menu.name;
  5014. self.hideMenu();
  5015. if (menuName === name) {
  5016. return;
  5017. }
  5018. }
  5019. self.clickToolbar(name);
  5020. }
  5021. });
  5022. var editHeight = _removeUnit(height) - toolbar.div.height();
  5023. var edit = self.edit = _edit({
  5024. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5025. src : editDiv,
  5026. srcElement : self.srcElement,
  5027. designMode : self.designMode,
  5028. themesPath : self.themesPath,
  5029. bodyClass : self.bodyClass,
  5030. cssPath : self.cssPath,
  5031. cssData : self.cssData,
  5032. beforeGetHtml : function(html) {
  5033. html = self.beforeGetHtml(html);
  5034. html = _removeBookmarkTag(_removeTempTag(html));
  5035. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5036. },
  5037. beforeSetHtml : function(html) {
  5038. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5039. return self.beforeSetHtml(html);
  5040. },
  5041. afterSetHtml : function() {
  5042. self.edit = edit = this;
  5043. self.afterSetHtml();
  5044. },
  5045. afterCreate : function() {
  5046. self.edit = edit = this;
  5047. self.cmd = edit.cmd;
  5048. self._docMousedownFn = function(e) {
  5049. if (self.menu) {
  5050. self.hideMenu();
  5051. }
  5052. };
  5053. K(edit.doc, document).mousedown(self._docMousedownFn);
  5054. _bindContextmenuEvent.call(self);
  5055. _bindNewlineEvent.call(self);
  5056. _bindTabEvent.call(self);
  5057. _bindFocusEvent.call(self);
  5058. edit.afterChange(function(e) {
  5059. if (!edit.designMode) {
  5060. return;
  5061. }
  5062. self.updateState();
  5063. self.addBookmark();
  5064. if (self.options.afterChange) {
  5065. self.options.afterChange.call(self);
  5066. }
  5067. });
  5068. edit.textarea.keyup(function(e) {
  5069. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5070. if (self.options.afterChange) {
  5071. self.options.afterChange.call(self);
  5072. }
  5073. }
  5074. });
  5075. if (self.readonlyMode) {
  5076. self.readonly();
  5077. }
  5078. self.isCreated = true;
  5079. if (self.initContent === '') {
  5080. self.initContent = self.html();
  5081. }
  5082. if (self._undoStack.length > 0) {
  5083. var prev = self._undoStack.pop();
  5084. if (prev.start) {
  5085. self.html(prev.html);
  5086. edit.cmd.range.moveToBookmark(prev);
  5087. self.select();
  5088. }
  5089. }
  5090. self.afterCreate();
  5091. if (self.options.afterCreate) {
  5092. self.options.afterCreate.call(self);
  5093. }
  5094. }
  5095. });
  5096. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5097. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5098. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5099. if (self._fullscreenResizeHandler) {
  5100. K(window).unbind('resize', self._fullscreenResizeHandler);
  5101. self._fullscreenResizeHandler = null;
  5102. }
  5103. function initResize() {
  5104. if (statusbar.height() === 0) {
  5105. setTimeout(initResize, 100);
  5106. return;
  5107. }
  5108. self.resize(width, height, false);
  5109. }
  5110. initResize();
  5111. if (fullscreenMode) {
  5112. self._fullscreenResizeHandler = function(e) {
  5113. if (self.isCreated) {
  5114. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5115. }
  5116. };
  5117. K(window).bind('resize', self._fullscreenResizeHandler);
  5118. toolbar.select('fullscreen');
  5119. statusbar.first().css('visibility', 'hidden');
  5120. statusbar.last().css('visibility', 'hidden');
  5121. } else {
  5122. if (_GECKO) {
  5123. K(window).bind('scroll', function(e) {
  5124. self._scrollPos = _getScrollPos();
  5125. });
  5126. }
  5127. if (self.resizeType > 0) {
  5128. _drag({
  5129. moveEl : container,
  5130. clickEl : statusbar,
  5131. moveFn : function(x, y, width, height, diffX, diffY) {
  5132. height += diffY;
  5133. self.resize(null, height);
  5134. }
  5135. });
  5136. } else {
  5137. statusbar.first().css('visibility', 'hidden');
  5138. }
  5139. if (self.resizeType === 2) {
  5140. _drag({
  5141. moveEl : container,
  5142. clickEl : statusbar.last(),
  5143. moveFn : function(x, y, width, height, diffX, diffY) {
  5144. width += diffX;
  5145. height += diffY;
  5146. self.resize(width, height);
  5147. }
  5148. });
  5149. } else {
  5150. statusbar.last().css('visibility', 'hidden');
  5151. }
  5152. }
  5153. return self;
  5154. },
  5155. remove : function() {
  5156. var self = this;
  5157. if (!self.isCreated) {
  5158. return self;
  5159. }
  5160. self.beforeRemove();
  5161. self.srcElement.data('kindeditor', '');
  5162. if (self.menu) {
  5163. self.hideMenu();
  5164. }
  5165. _each(self.dialogs, function() {
  5166. self.hideDialog();
  5167. });
  5168. K(document).unbind('mousedown', self._docMousedownFn);
  5169. self.toolbar.remove();
  5170. self.edit.remove();
  5171. self.statusbar.last().unbind();
  5172. self.statusbar.unbind();
  5173. self.container.remove();
  5174. self.container = self.toolbar = self.edit = self.menu = null;
  5175. self.dialogs = [];
  5176. self.isCreated = false;
  5177. return self;
  5178. },
  5179. resize : function(width, height, updateProp) {
  5180. var self = this;
  5181. updateProp = _undef(updateProp, true);
  5182. if (width) {
  5183. if (!/%/.test(width)) {
  5184. width = _removeUnit(width);
  5185. width = width < self.minWidth ? self.minWidth : width;
  5186. }
  5187. self.container.css('width', _addUnit(width));
  5188. if (updateProp) {
  5189. self.width = _addUnit(width);
  5190. }
  5191. }
  5192. if (height) {
  5193. height = _removeUnit(height);
  5194. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5195. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5196. self.edit.setHeight(editHeight);
  5197. if (updateProp) {
  5198. self.height = _addUnit(height);
  5199. }
  5200. }
  5201. return self;
  5202. },
  5203. select : function() {
  5204. this.isCreated && this.cmd.select();
  5205. return this;
  5206. },
  5207. html : function(val) {
  5208. var self = this;
  5209. if (val === undefined) {
  5210. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5211. }
  5212. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5213. if (self.isCreated) {
  5214. self.cmd.selection();
  5215. }
  5216. return self;
  5217. },
  5218. fullHtml : function() {
  5219. return this.isCreated ? this.edit.html(undefined, true) : '';
  5220. },
  5221. text : function(val) {
  5222. var self = this;
  5223. if (val === undefined) {
  5224. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5225. } else {
  5226. return self.html(_escape(val));
  5227. }
  5228. },
  5229. isEmpty : function() {
  5230. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5231. },
  5232. isDirty : function() {
  5233. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5234. },
  5235. selectedHtml : function() {
  5236. var val = this.isCreated ? this.cmd.range.html() : '';
  5237. val = _removeBookmarkTag(_removeTempTag(val));
  5238. return val;
  5239. },
  5240. count : function(mode) {
  5241. var self = this;
  5242. mode = (mode || 'html').toLowerCase();
  5243. if (mode === 'html') {
  5244. return self.html().length;
  5245. }
  5246. if (mode === 'text') {
  5247. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5248. }
  5249. return 0;
  5250. },
  5251. exec : function(key) {
  5252. key = key.toLowerCase();
  5253. var self = this, cmd = self.cmd,
  5254. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5255. if (changeFlag) {
  5256. self.addBookmark(false);
  5257. }
  5258. cmd[key].apply(cmd, _toArray(arguments, 1));
  5259. if (changeFlag) {
  5260. self.updateState();
  5261. self.addBookmark(false);
  5262. if (self.options.afterChange) {
  5263. self.options.afterChange.call(self);
  5264. }
  5265. }
  5266. return self;
  5267. },
  5268. insertHtml : function(val, quickMode) {
  5269. if (!this.isCreated) {
  5270. return this;
  5271. }
  5272. val = this.beforeSetHtml(val);
  5273. this.exec('inserthtml', val, quickMode);
  5274. return this;
  5275. },
  5276. appendHtml : function(val) {
  5277. this.html(this.html() + val);
  5278. if (this.isCreated) {
  5279. var cmd = this.cmd;
  5280. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5281. cmd.select();
  5282. }
  5283. return this;
  5284. },
  5285. sync : function() {
  5286. _elementVal(this.srcElement, this.html());
  5287. return this;
  5288. },
  5289. focus : function() {
  5290. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5291. return this;
  5292. },
  5293. blur : function() {
  5294. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5295. return this;
  5296. },
  5297. addBookmark : function(checkSize) {
  5298. checkSize = _undef(checkSize, true);
  5299. var self = this, edit = self.edit,
  5300. body = edit.doc.body,
  5301. html = _removeTempTag(body.innerHTML), bookmark;
  5302. if (checkSize && self._undoStack.length > 0) {
  5303. var prev = self._undoStack[self._undoStack.length - 1];
  5304. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5305. return self;
  5306. }
  5307. }
  5308. if (edit.designMode && !self._firstAddBookmark) {
  5309. var range = self.cmd.range;
  5310. bookmark = range.createBookmark(true);
  5311. bookmark.html = _removeTempTag(body.innerHTML);
  5312. range.moveToBookmark(bookmark);
  5313. } else {
  5314. bookmark = {
  5315. html : html
  5316. };
  5317. }
  5318. self._firstAddBookmark = false;
  5319. _addBookmarkToStack(self._undoStack, bookmark);
  5320. return self;
  5321. },
  5322. undo : function() {
  5323. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5324. },
  5325. redo : function() {
  5326. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5327. },
  5328. fullscreen : function(bool) {
  5329. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5330. this.addBookmark(false);
  5331. return this.remove().create();
  5332. },
  5333. readonly : function(isReadonly) {
  5334. isReadonly = _undef(isReadonly, true);
  5335. var self = this, edit = self.edit, doc = edit.doc;
  5336. if (self.designMode) {
  5337. self.toolbar.disableAll(isReadonly, []);
  5338. } else {
  5339. _each(self.noDisableItems, function() {
  5340. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5341. });
  5342. }
  5343. if (_IE) {
  5344. doc.body.contentEditable = !isReadonly;
  5345. } else {
  5346. doc.designMode = isReadonly ? 'off' : 'on';
  5347. }
  5348. edit.textarea[0].disabled = isReadonly;
  5349. },
  5350. createMenu : function(options) {
  5351. var self = this,
  5352. name = options.name,
  5353. knode = self.toolbar.get(name),
  5354. pos = knode.pos();
  5355. options.x = pos.x;
  5356. options.y = pos.y + knode.height();
  5357. options.z = self.options.zIndex;
  5358. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5359. if (options.selectedColor !== undefined) {
  5360. options.cls = 'ke-colorpicker-' + self.themeType;
  5361. options.noColor = self.lang('noColor');
  5362. self.menu = _colorpicker(options);
  5363. } else {
  5364. options.cls = 'ke-menu-' + self.themeType;
  5365. options.centerLineMode = false;
  5366. self.menu = _menu(options);
  5367. }
  5368. return self.menu;
  5369. },
  5370. hideMenu : function() {
  5371. this.menu.remove();
  5372. this.menu = null;
  5373. return this;
  5374. },
  5375. hideContextmenu : function() {
  5376. this.contextmenu.remove();
  5377. this.contextmenu = null;
  5378. return this;
  5379. },
  5380. createDialog : function(options) {
  5381. var self = this, name = options.name;
  5382. options.z = self.options.zIndex;
  5383. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5384. options.closeBtn = _undef(options.closeBtn, {
  5385. name : self.lang('close'),
  5386. click : function(e) {
  5387. self.hideDialog();
  5388. if (_IE && self.cmd) {
  5389. self.cmd.select();
  5390. }
  5391. }
  5392. });
  5393. options.noBtn = _undef(options.noBtn, {
  5394. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5395. click : function(e) {
  5396. self.hideDialog();
  5397. if (_IE && self.cmd) {
  5398. self.cmd.select();
  5399. }
  5400. }
  5401. });
  5402. if (self.dialogAlignType != 'page') {
  5403. options.alignEl = self.container;
  5404. }
  5405. options.cls = 'ke-dialog-' + self.themeType;
  5406. if (self.dialogs.length > 0) {
  5407. var firstDialog = self.dialogs[0],
  5408. parentDialog = self.dialogs[self.dialogs.length - 1];
  5409. firstDialog.setMaskIndex(parentDialog.z + 2);
  5410. options.z = parentDialog.z + 3;
  5411. options.showMask = false;
  5412. }
  5413. var dialog = _dialog(options);
  5414. self.dialogs.push(dialog);
  5415. return dialog;
  5416. },
  5417. hideDialog : function() {
  5418. var self = this;
  5419. if (self.dialogs.length > 0) {
  5420. self.dialogs.pop().remove();
  5421. }
  5422. if (self.dialogs.length > 0) {
  5423. var firstDialog = self.dialogs[0],
  5424. parentDialog = self.dialogs[self.dialogs.length - 1];
  5425. firstDialog.setMaskIndex(parentDialog.z - 1);
  5426. }
  5427. return self;
  5428. },
  5429. errorDialog : function(html) {
  5430. var self = this;
  5431. var dialog = self.createDialog({
  5432. width : 750,
  5433. title : self.lang('uploadError'),
  5434. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5435. });
  5436. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5437. doc.open();
  5438. doc.write(html);
  5439. doc.close();
  5440. K(doc.body).css('background-color', '#FFF');
  5441. iframe[0].contentWindow.focus();
  5442. return self;
  5443. }
  5444. };
  5445. function _editor(options) {
  5446. return new KEditor(options);
  5447. }
  5448. var _instances = [];
  5449. function _create(expr, options) {
  5450. options = options || {};
  5451. options.basePath = _undef(options.basePath, K.basePath);
  5452. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5453. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5454. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5455. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5456. var themeType = _undef(options.themeType, K.options.themeType);
  5457. _loadStyle(options.themesPath + 'default/default.css');
  5458. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5459. }
  5460. function create(editor) {
  5461. _each(_plugins, function(name, fn) {
  5462. if (_isFunction(fn)) {
  5463. fn.call(editor, KindEditor);
  5464. if (!editor._pluginStatus) {
  5465. editor._pluginStatus = {};
  5466. }
  5467. editor._pluginStatus[name] = 'inited';
  5468. }
  5469. });
  5470. return editor.create();
  5471. }
  5472. var knode = K(expr);
  5473. if (!knode || knode.length === 0) {
  5474. return;
  5475. }
  5476. if (knode.length > 1) {
  5477. knode.each(function() {
  5478. _create(this, options);
  5479. });
  5480. return _instances[0];
  5481. }
  5482. options.srcElement = knode[0];
  5483. var editor = new KEditor(options);
  5484. _instances.push(editor);
  5485. if (_language[editor.langType]) {
  5486. return create(editor);
  5487. }
  5488. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5489. create(editor);
  5490. });
  5491. return editor;
  5492. }
  5493. function _eachEditor(expr, fn) {
  5494. K(expr).each(function(i, el) {
  5495. K.each(_instances, function(j, editor) {
  5496. if (editor && editor.srcElement[0] == el) {
  5497. fn.call(editor, j);
  5498. return false;
  5499. }
  5500. });
  5501. });
  5502. }
  5503. K.remove = function(expr) {
  5504. _eachEditor(expr, function(i) {
  5505. this.remove();
  5506. _instances.splice(i, 1);
  5507. });
  5508. };
  5509. K.sync = function(expr) {
  5510. _eachEditor(expr, function() {
  5511. this.sync();
  5512. });
  5513. };
  5514. K.html = function(expr, val) {
  5515. _eachEditor(expr, function() {
  5516. this.html(val);
  5517. });
  5518. };
  5519. K.insertHtml = function(expr, val) {
  5520. _eachEditor(expr, function() {
  5521. this.insertHtml(val);
  5522. });
  5523. };
  5524. K.appendHtml = function(expr, val) {
  5525. _eachEditor(expr, function() {
  5526. this.appendHtml(val);
  5527. });
  5528. };
  5529. if (_IE && _V < 7) {
  5530. _nativeCommand(document, 'BackgroundImageCache', true);
  5531. }
  5532. K.EditorClass = KEditor;
  5533. K.editor = _editor;
  5534. K.create = _create;
  5535. K.instances = _instances;
  5536. K.plugin = _plugin;
  5537. K.lang = _lang;
  5538. _plugin('core', function(K) {
  5539. var self = this,
  5540. shortcutKeys = {
  5541. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5542. };
  5543. self.afterSetHtml(function() {
  5544. if (self.options.afterChange) {
  5545. self.options.afterChange.call(self);
  5546. }
  5547. });
  5548. self.afterCreate(function() {
  5549. if (self.syncType != 'form') {
  5550. return;
  5551. }
  5552. var el = K(self.srcElement), hasForm = false;
  5553. while ((el = el.parent())) {
  5554. if (el.name == 'form') {
  5555. hasForm = true;
  5556. break;
  5557. }
  5558. }
  5559. if (hasForm) {
  5560. el.bind('submit', function(e) {
  5561. self.sync();
  5562. K(window).bind('unload', function() {
  5563. self.edit.textarea.remove();
  5564. });
  5565. });
  5566. var resetBtn = K('[type="reset"]', el);
  5567. resetBtn.click(function() {
  5568. self.html(self.initContent);
  5569. self.cmd.selection();
  5570. });
  5571. self.beforeRemove(function() {
  5572. el.unbind();
  5573. resetBtn.unbind();
  5574. });
  5575. }
  5576. });
  5577. self.clickToolbar('source', function() {
  5578. if (self.edit.designMode) {
  5579. self.toolbar.disableAll(true);
  5580. self.edit.design(false);
  5581. self.toolbar.select('source');
  5582. } else {
  5583. self.toolbar.disableAll(false);
  5584. self.edit.design(true);
  5585. self.toolbar.unselect('source');
  5586. if (_GECKO) {
  5587. setTimeout(function() {
  5588. self.cmd.selection();
  5589. }, 0);
  5590. } else {
  5591. self.cmd.selection();
  5592. }
  5593. }
  5594. self.designMode = self.edit.designMode;
  5595. });
  5596. self.afterCreate(function() {
  5597. if (!self.designMode) {
  5598. self.toolbar.disableAll(true).select('source');
  5599. }
  5600. });
  5601. self.clickToolbar('fullscreen', function() {
  5602. self.fullscreen();
  5603. });
  5604. if (self.fullscreenShortcut) {
  5605. var loaded = false;
  5606. self.afterCreate(function() {
  5607. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5608. if (e.which == 27) {
  5609. setTimeout(function() {
  5610. self.fullscreen();
  5611. }, 0);
  5612. }
  5613. });
  5614. if (loaded) {
  5615. if (_IE && !self.designMode) {
  5616. return;
  5617. }
  5618. self.focus();
  5619. }
  5620. if (!loaded) {
  5621. loaded = true;
  5622. }
  5623. });
  5624. }
  5625. _each('undo,redo'.split(','), function(i, name) {
  5626. if (shortcutKeys[name]) {
  5627. self.afterCreate(function() {
  5628. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5629. self.clickToolbar(name);
  5630. });
  5631. });
  5632. }
  5633. self.clickToolbar(name, function() {
  5634. self[name]();
  5635. });
  5636. });
  5637. self.clickToolbar('formatblock', function() {
  5638. var blocks = self.lang('formatblock.formatBlock'),
  5639. heights = {
  5640. h1 : 28,
  5641. h2 : 24,
  5642. h3 : 18,
  5643. H4 : 14,
  5644. p : 12
  5645. },
  5646. curVal = self.cmd.val('formatblock'),
  5647. menu = self.createMenu({
  5648. name : 'formatblock',
  5649. width : self.langType == 'en' ? 200 : 150
  5650. });
  5651. _each(blocks, function(key, val) {
  5652. var style = 'font-size:' + heights[key] + 'px;';
  5653. if (key.charAt(0) === 'h') {
  5654. style += 'font-weight:bold;';
  5655. }
  5656. menu.addItem({
  5657. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5658. height : heights[key] + 12,
  5659. checked : (curVal === key || curVal === val),
  5660. click : function() {
  5661. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5662. }
  5663. });
  5664. });
  5665. });
  5666. self.clickToolbar('fontname', function() {
  5667. var curVal = self.cmd.val('fontname'),
  5668. menu = self.createMenu({
  5669. name : 'fontname',
  5670. width : 150
  5671. });
  5672. _each(self.lang('fontname.fontName'), function(key, val) {
  5673. menu.addItem({
  5674. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5675. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5676. click : function() {
  5677. self.exec('fontname', key).hideMenu();
  5678. }
  5679. });
  5680. });
  5681. });
  5682. self.clickToolbar('fontsize', function() {
  5683. var curVal = self.cmd.val('fontsize'),
  5684. menu = self.createMenu({
  5685. name : 'fontsize',
  5686. width : 150
  5687. });
  5688. _each(self.fontSizeTable, function(i, val) {
  5689. menu.addItem({
  5690. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5691. height : _removeUnit(val) + 12,
  5692. checked : curVal === val,
  5693. click : function() {
  5694. self.exec('fontsize', val).hideMenu();
  5695. }
  5696. });
  5697. });
  5698. });
  5699. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5700. self.clickToolbar(name, function() {
  5701. self.createMenu({
  5702. name : name,
  5703. selectedColor : self.cmd.val(name) || 'default',
  5704. colors : self.colorTable,
  5705. click : function(color) {
  5706. self.exec(name, color).hideMenu();
  5707. }
  5708. });
  5709. });
  5710. });
  5711. _each(('cut,copy,paste').split(','), function(i, name) {
  5712. self.clickToolbar(name, function() {
  5713. self.focus();
  5714. try {
  5715. self.exec(name, null);
  5716. } catch(e) {
  5717. alert(self.lang(name + 'Error'));
  5718. }
  5719. });
  5720. });
  5721. self.clickToolbar('about', function() {
  5722. var html = '<div style="margin:20px;">' +
  5723. '<div>KindEditor ' + _VERSION + '</div>' +
  5724. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5725. '</div>';
  5726. self.createDialog({
  5727. name : 'about',
  5728. width : 350,
  5729. title : self.lang('about'),
  5730. body : html
  5731. });
  5732. });
  5733. self.plugin.getSelectedLink = function() {
  5734. return self.cmd.commonAncestor('a');
  5735. };
  5736. self.plugin.getSelectedImage = function() {
  5737. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5738. return !/^ke-\w+$/i.test(img[0].className);
  5739. });
  5740. };
  5741. self.plugin.getSelectedFlash = function() {
  5742. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5743. return img[0].className == 'ke-flash';
  5744. });
  5745. };
  5746. self.plugin.getSelectedMedia = function() {
  5747. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5748. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5749. });
  5750. };
  5751. self.plugin.getSelectedAnchor = function() {
  5752. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5753. return img[0].className == 'ke-anchor';
  5754. });
  5755. };
  5756. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5757. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5758. _each('edit,delete'.split(','), function(j, val) {
  5759. self.addContextmenu({
  5760. title : self.lang(val + uName),
  5761. click : function() {
  5762. self.loadPlugin(name, function() {
  5763. self.plugin[name][val]();
  5764. self.hideMenu();
  5765. });
  5766. },
  5767. cond : self.plugin['getSelected' + uName],
  5768. width : 150,
  5769. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5770. });
  5771. });
  5772. self.addContextmenu({ title : '-' });
  5773. });
  5774. self.plugin.getSelectedTable = function() {
  5775. return self.cmd.commonAncestor('table');
  5776. };
  5777. self.plugin.getSelectedRow = function() {
  5778. return self.cmd.commonAncestor('tr');
  5779. };
  5780. self.plugin.getSelectedCell = function() {
  5781. return self.cmd.commonAncestor('td');
  5782. };
  5783. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5784. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5785. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5786. self.addContextmenu({
  5787. title : self.lang('table' + val),
  5788. click : function() {
  5789. self.loadPlugin('table', function() {
  5790. self.plugin.table[val]();
  5791. self.hideMenu();
  5792. });
  5793. },
  5794. cond : cond,
  5795. width : 170,
  5796. iconClass : 'ke-icon-table' + val
  5797. });
  5798. });
  5799. self.addContextmenu({ title : '-' });
  5800. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5801. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5802. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5803. if (shortcutKeys[name]) {
  5804. self.afterCreate(function() {
  5805. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5806. self.cmd.selection();
  5807. self.clickToolbar(name);
  5808. });
  5809. });
  5810. }
  5811. self.clickToolbar(name, function() {
  5812. self.focus().exec(name, null);
  5813. });
  5814. });
  5815. self.afterCreate(function() {
  5816. var doc = self.edit.doc, cmd, bookmark, div,
  5817. cls = '__kindeditor_paste__', pasting = false;
  5818. function movePastedData() {
  5819. cmd.range.moveToBookmark(bookmark);
  5820. cmd.select();
  5821. if (_WEBKIT) {
  5822. K('div.' + cls, div).each(function() {
  5823. K(this).after('<br />').remove(true);
  5824. });
  5825. K('span.Apple-style-span', div).remove(true);
  5826. K('span.Apple-tab-span', div).remove(true);
  5827. K('span[style]', div).each(function() {
  5828. if (K(this).css('white-space') == 'nowrap') {
  5829. K(this).remove(true);
  5830. }
  5831. });
  5832. K('meta', div).remove();
  5833. }
  5834. var html = div[0].innerHTML;
  5835. div.remove();
  5836. if (html === '') {
  5837. return;
  5838. }
  5839. if (_WEBKIT) {
  5840. html = html.replace(/(<br>)\1/ig, '$1');
  5841. }
  5842. if (self.pasteType === 2) {
  5843. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5844. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5845. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5846. } else {
  5847. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5848. html = self.beforeSetHtml(html);
  5849. }
  5850. }
  5851. if (self.pasteType === 1) {
  5852. html = html.replace(/&nbsp;/ig, ' ');
  5853. html = html.replace(/\n\s*\n/g, '\n');
  5854. html = html.replace(/<br[^>]*>/ig, '\n');
  5855. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5856. html = html.replace(/<[^>]+>/g, '');
  5857. html = html.replace(/ {2}/g, ' &nbsp;');
  5858. if (self.newlineTag == 'p') {
  5859. if (/\n/.test(html)) {
  5860. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5861. // console.log(html);
  5862. }
  5863. } else {
  5864. html = html.replace(/\n/g, '<br />$&');
  5865. }
  5866. }
  5867. self.insertHtml(html, true);
  5868. }
  5869. K(doc.body).bind('paste', function(e){
  5870. if (self.pasteType === 0) {
  5871. e.stop();
  5872. return;
  5873. }
  5874. if (pasting) {
  5875. return;
  5876. }
  5877. pasting = true;
  5878. K('div.' + cls, doc).remove();
  5879. cmd = self.cmd.selection();
  5880. bookmark = cmd.range.createBookmark();
  5881. div = K('<div class="' + cls + '"></div>', doc).css({
  5882. position : 'absolute',
  5883. width : '1px',
  5884. height : '1px',
  5885. overflow : 'hidden',
  5886. left : '-1981px',
  5887. top : K(bookmark.start).pos().y + 'px',
  5888. 'white-space' : 'nowrap'
  5889. });
  5890. K(doc.body).append(div);
  5891. if (_IE) {
  5892. var rng = cmd.range.get(true);
  5893. rng.moveToElementText(div[0]);
  5894. rng.select();
  5895. rng.execCommand('paste');
  5896. e.preventDefault();
  5897. } else {
  5898. cmd.range.selectNodeContents(div[0]);
  5899. cmd.select();
  5900. div[0].tabIndex = -1;
  5901. div[0].focus();
  5902. }
  5903. setTimeout(function() {
  5904. movePastedData();
  5905. pasting = false;
  5906. }, 0);
  5907. });
  5908. });
  5909. self.beforeGetHtml(function(html) {
  5910. if (_IE && _V <= 8) {
  5911. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5912. return unescape(tag);
  5913. });
  5914. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5915. if (!/\s+type="[^"]+"/i.test($0)) {
  5916. return $1 + ' type="text"' + $2;
  5917. }
  5918. return $0;
  5919. });
  5920. }
  5921. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5922. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5923. })
  5924. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5925. var imgAttrs = _getAttrList(full);
  5926. var styles = _getCssList(imgAttrs.style || '');
  5927. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5928. var width = _undef(styles.width, '');
  5929. var height = _undef(styles.height, '');
  5930. if (/px/i.test(width)) {
  5931. width = _removeUnit(width);
  5932. }
  5933. if (/px/i.test(height)) {
  5934. height = _removeUnit(height);
  5935. }
  5936. attrs.width = _undef(imgAttrs.width, width);
  5937. attrs.height = _undef(imgAttrs.height, height);
  5938. return _mediaEmbed(attrs);
  5939. })
  5940. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  5941. var imgAttrs = _getAttrList(full);
  5942. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5943. })
  5944. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5945. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5946. })
  5947. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5948. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5949. })
  5950. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  5951. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  5952. return $1 + _unescape(src) + $2;
  5953. });
  5954. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5955. return full;
  5956. })
  5957. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5958. return start + end;
  5959. });
  5960. });
  5961. self.beforeSetHtml(function(html) {
  5962. if (_IE && _V <= 8) {
  5963. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  5964. var attrs = _getAttrList(full);
  5965. var styles = _getCssList(attrs.style || '');
  5966. if (styles.display == 'none') {
  5967. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5968. }
  5969. return full;
  5970. });
  5971. }
  5972. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  5973. var attrs = _getAttrList(full);
  5974. attrs.src = _undef(attrs.src, '');
  5975. attrs.width = _undef(attrs.width, 0);
  5976. attrs.height = _undef(attrs.height, 0);
  5977. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5978. })
  5979. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  5980. var attrs = _getAttrList(full);
  5981. if (attrs.href !== undefined) {
  5982. return full;
  5983. }
  5984. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5985. })
  5986. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  5987. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5988. })
  5989. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  5990. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5991. })
  5992. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  5993. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5994. return full;
  5995. }
  5996. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5997. return full;
  5998. })
  5999. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6000. return start + 'data-ke-' + end;
  6001. })
  6002. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6003. if (full.indexOf('ke-zeroborder') >= 0) {
  6004. return full;
  6005. }
  6006. return _addClassToTag(full, 'ke-zeroborder');
  6007. });
  6008. });
  6009. });
  6010. })(window);
  6011. /*******************************************************************************
  6012. * KindEditor - WYSIWYG HTML Editor for Internet
  6013. * Copyright (C) 2006-2011 kindsoft.net
  6014. *
  6015. * @author Roddy <luolonghao@gmail.com>
  6016. * @site http://www.kindsoft.net/
  6017. * @licence http://www.kindsoft.net/license.php
  6018. *******************************************************************************/
  6019. KindEditor.lang({
  6020. source : 'HTML代码',
  6021. preview : '预览',
  6022. undo : '后退(Ctrl+Z)',
  6023. redo : '前进(Ctrl+Y)',
  6024. cut : '剪切(Ctrl+X)',
  6025. copy : '复制(Ctrl+C)',
  6026. paste : '粘贴(Ctrl+V)',
  6027. plainpaste : '粘贴为无格式文本',
  6028. wordpaste : '从Word粘贴',
  6029. selectall : '全选(Ctrl+A)',
  6030. justifyleft : '左对齐',
  6031. justifycenter : '居中',
  6032. justifyright : '右对齐',
  6033. justifyfull : '两端对齐',
  6034. insertorderedlist : '编号',
  6035. insertunorderedlist : '项目符号',
  6036. indent : '增加缩进',
  6037. outdent : '减少缩进',
  6038. subscript : '下标',
  6039. superscript : '上标',
  6040. formatblock : '段落',
  6041. fontname : '字体',
  6042. fontsize : '文字大小',
  6043. forecolor : '文字颜色',
  6044. hilitecolor : '文字背景',
  6045. bold : '粗体(Ctrl+B)',
  6046. italic : '斜体(Ctrl+I)',
  6047. underline : '下划线(Ctrl+U)',
  6048. strikethrough : '删除线',
  6049. removeformat : '删除格式',
  6050. image : '图片',
  6051. multiimage : '批量图片上传',
  6052. flash : 'Flash',
  6053. media : '视音频',
  6054. table : '表格',
  6055. tablecell : '单元格',
  6056. hr : '插入横线',
  6057. emoticons : '插入表情',
  6058. link : '超级链接',
  6059. unlink : '取消超级链接',
  6060. fullscreen : '全屏显示',
  6061. about : '关于',
  6062. print : '打印(Ctrl+P)',
  6063. filemanager : '文件空间',
  6064. code : '插入程序代码',
  6065. map : 'Google地图',
  6066. baidumap : '百度地图',
  6067. lineheight : '行距',
  6068. clearhtml : '清理HTML代码',
  6069. pagebreak : '插入分页符',
  6070. quickformat : '一键排版',
  6071. insertfile : '插入文件',
  6072. template : '插入模板',
  6073. anchor : '锚点',
  6074. yes : '确定',
  6075. no : '取消',
  6076. close : '关闭',
  6077. editImage : '图片属性',
  6078. deleteImage : '删除图片',
  6079. editFlash : 'Flash属性',
  6080. deleteFlash : '删除Flash',
  6081. editMedia : '视音频属性',
  6082. deleteMedia : '删除视音频',
  6083. editLink : '超级链接属性',
  6084. deleteLink : '取消超级链接',
  6085. editAnchor : '锚点属性',
  6086. deleteAnchor : '删除锚点',
  6087. tableprop : '表格属性',
  6088. tablecellprop : '单元格属性',
  6089. tableinsert : '插入表格',
  6090. tabledelete : '删除表格',
  6091. tablecolinsertleft : '左侧插入列',
  6092. tablecolinsertright : '右侧插入列',
  6093. tablerowinsertabove : '上方插入行',
  6094. tablerowinsertbelow : '下方插入行',
  6095. tablerowmerge : '向下合并单元格',
  6096. tablecolmerge : '向右合并单元格',
  6097. tablerowsplit : '拆分行',
  6098. tablecolsplit : '拆分列',
  6099. tablecoldelete : '删除列',
  6100. tablerowdelete : '删除行',
  6101. noColor : '无颜色',
  6102. pleaseSelectFile : '请选择文件。',
  6103. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6104. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6105. invalidWidth : "宽度必须为数字。",
  6106. invalidHeight : "高度必须为数字。",
  6107. invalidBorder : "边框必须为数字。",
  6108. invalidUrl : "请输入有效的URL地址。",
  6109. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6110. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6111. invalidPadding : '边距必须为数字。',
  6112. invalidSpacing : '间距必须为数字。',
  6113. invalidJson : '服务器发生故障。',
  6114. uploadSuccess : '上传成功。',
  6115. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6116. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6117. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6118. ajaxLoading : '加载中,请稍候 ...',
  6119. uploadLoading : '上传中,请稍候 ...',
  6120. uploadError : '上传错误',
  6121. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6122. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6123. 'code.pleaseInput' : '请输入程序代码。',
  6124. 'link.url' : 'URL',
  6125. 'link.linkType' : '打开类型',
  6126. 'link.newWindow' : '新窗口',
  6127. 'link.selfWindow' : '当前窗口',
  6128. 'flash.url' : 'URL',
  6129. 'flash.width' : '宽度',
  6130. 'flash.height' : '高度',
  6131. 'flash.upload' : '上传',
  6132. 'flash.viewServer' : '文件空间',
  6133. 'media.url' : 'URL',
  6134. 'media.width' : '宽度',
  6135. 'media.height' : '高度',
  6136. 'media.autostart' : '自动播放',
  6137. 'media.upload' : '上传',
  6138. 'media.viewServer' : '文件空间',
  6139. 'image.remoteImage' : '网络图片',
  6140. 'image.localImage' : '本地上传',
  6141. 'image.remoteUrl' : '图片地址',
  6142. 'image.localUrl' : '上传文件',
  6143. 'image.size' : '图片大小',
  6144. 'image.width' : '宽',
  6145. 'image.height' : '高',
  6146. 'image.resetSize' : '重置大小',
  6147. 'image.align' : '对齐方式',
  6148. 'image.defaultAlign' : '默认方式',
  6149. 'image.leftAlign' : '左对齐',
  6150. 'image.rightAlign' : '右对齐',
  6151. 'image.imgTitle' : '图片说明',
  6152. 'image.upload' : '浏览...',
  6153. 'image.viewServer' : '图片空间',
  6154. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6155. 'multiimage.startUpload' : '开始上传',
  6156. 'multiimage.clearAll' : '全部清空',
  6157. 'multiimage.insertAll' : '全部插入',
  6158. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6159. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6160. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6161. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6162. 'multiimage.unknownError' : '发生异常,无法上传。',
  6163. 'multiimage.pending' : '等待上传',
  6164. 'multiimage.uploadError' : '上传失败',
  6165. 'filemanager.emptyFolder' : '空文件夹',
  6166. 'filemanager.moveup' : '移到上一级文件夹',
  6167. 'filemanager.viewType' : '显示方式:',
  6168. 'filemanager.viewImage' : '缩略图',
  6169. 'filemanager.listImage' : '详细信息',
  6170. 'filemanager.orderType' : '排序方式:',
  6171. 'filemanager.fileName' : '名称',
  6172. 'filemanager.fileSize' : '大小',
  6173. 'filemanager.fileType' : '类型',
  6174. 'insertfile.url' : 'URL',
  6175. 'insertfile.title' : '文件说明',
  6176. 'insertfile.upload' : '上传',
  6177. 'insertfile.viewServer' : '文件空间',
  6178. 'table.cells' : '单元格数',
  6179. 'table.rows' : '行数',
  6180. 'table.cols' : '列数',
  6181. 'table.size' : '大小',
  6182. 'table.width' : '宽度',
  6183. 'table.height' : '高度',
  6184. 'table.percent' : '%',
  6185. 'table.px' : 'px',
  6186. 'table.space' : '边距间距',
  6187. 'table.padding' : '边距',
  6188. 'table.spacing' : '间距',
  6189. 'table.align' : '对齐方式',
  6190. 'table.textAlign' : '水平对齐',
  6191. 'table.verticalAlign' : '垂直对齐',
  6192. 'table.alignDefault' : '默认',
  6193. 'table.alignLeft' : '左对齐',
  6194. 'table.alignCenter' : '居中',
  6195. 'table.alignRight' : '右对齐',
  6196. 'table.alignTop' : '顶部',
  6197. 'table.alignMiddle' : '中部',
  6198. 'table.alignBottom' : '底部',
  6199. 'table.alignBaseline' : '基线',
  6200. 'table.border' : '边框',
  6201. 'table.borderWidth' : '边框',
  6202. 'table.borderColor' : '颜色',
  6203. 'table.backgroundColor' : '背景颜色',
  6204. 'map.address' : '地址: ',
  6205. 'map.search' : '搜索',
  6206. 'baidumap.address' : '地址: ',
  6207. 'baidumap.search' : '搜索',
  6208. 'baidumap.insertDynamicMap' : '插入动态地图',
  6209. 'anchor.name' : '锚点名称',
  6210. 'formatblock.formatBlock' : {
  6211. h1 : '标题 1',
  6212. h2 : '标题 2',
  6213. h3 : '标题 3',
  6214. h4 : '标题 4',
  6215. p : '正 文'
  6216. },
  6217. 'fontname.fontName' : {
  6218. 'SimSun' : '宋体',
  6219. 'NSimSun' : '新宋体',
  6220. 'KaiTi' : '楷体',
  6221. 'SimHei' : '黑体',
  6222. 'Microsoft YaHei' : '微软雅黑'
  6223. },
  6224. 'lineheight.lineHeight' : [
  6225. {'1' : '单倍行距'},
  6226. {'1.5' : '1.5倍行距'},
  6227. {'2' : '2倍行距'},
  6228. {'2.5' : '2.5倍行距'},
  6229. {'3' : '3倍行距'}
  6230. ],
  6231. 'template.selectTemplate' : '可选模板',
  6232. 'template.replaceContent' : '替换当前内容',
  6233. 'template.fileList' : {
  6234. '1.html' : '图片和文字',
  6235. '2.html' : '表格',
  6236. '3.html' : '项目编号'
  6237. }
  6238. }, 'zh-CN');
  6239. KindEditor.options.langType = 'zh-CN';
  6240. /*******************************************************************************
  6241. * KindEditor - WYSIWYG HTML Editor for Internet
  6242. * Copyright (C) 2006-2011 kindsoft.net
  6243. *
  6244. * @author Roddy <luolonghao@gmail.com>
  6245. * @site http://www.kindsoft.net/
  6246. * @licence http://www.kindsoft.net/license.php
  6247. *******************************************************************************/
  6248. KindEditor.plugin('anchor', function(K) {
  6249. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6250. self.plugin.anchor = {
  6251. edit : function() {
  6252. var html = ['<div style="padding:20px;">',
  6253. '<div class="ke-dialog-row">',
  6254. '<label for="keName">' + lang.name + '</label>',
  6255. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6256. '</div>',
  6257. '</div>'].join('');
  6258. var dialog = self.createDialog({
  6259. name : name,
  6260. width : 300,
  6261. title : self.lang(name),
  6262. body : html,
  6263. yesBtn : {
  6264. name : self.lang('yes'),
  6265. click : function(e) {
  6266. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6267. }
  6268. }
  6269. });
  6270. var div = dialog.div,
  6271. nameBox = K('input[name="name"]', div);
  6272. var img = self.plugin.getSelectedAnchor();
  6273. if (img) {
  6274. nameBox.val(unescape(img.attr('data-ke-name')));
  6275. }
  6276. nameBox[0].focus();
  6277. nameBox[0].select();
  6278. },
  6279. 'delete' : function() {
  6280. self.plugin.getSelectedAnchor().remove();
  6281. }
  6282. };
  6283. self.clickToolbar(name, self.plugin.anchor.edit);
  6284. });
  6285. /*******************************************************************************
  6286. * KindEditor - WYSIWYG HTML Editor for Internet
  6287. * Copyright (C) 2006-2011 kindsoft.net
  6288. *
  6289. * @author Roddy <luolonghao@gmail.com>
  6290. * @site http://www.kindsoft.net/
  6291. * @licence http://www.kindsoft.net/license.php
  6292. *******************************************************************************/
  6293. KindEditor.plugin('autoheight', function(K) {
  6294. var self = this;
  6295. if (!self.autoHeightMode) {
  6296. return;
  6297. }
  6298. var minHeight;
  6299. function hideScroll() {
  6300. var edit = self.edit;
  6301. var body = edit.doc.body;
  6302. edit.iframe[0].scroll = 'no';
  6303. body.style.overflowY = 'hidden';
  6304. }
  6305. function resetHeight() {
  6306. if(self.fullscreenMode){
  6307. return;
  6308. }
  6309. var edit = self.edit;
  6310. var body = edit.doc.body;
  6311. edit.iframe.height(minHeight);
  6312. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6313. }
  6314. function init() {
  6315. minHeight = K.removeUnit(self.height);
  6316. self.edit.afterChange(resetHeight);
  6317. if(!self.fullscreenMode){
  6318. hideScroll();
  6319. }
  6320. resetHeight();
  6321. }
  6322. if (self.isCreated) {
  6323. init();
  6324. } else {
  6325. self.afterCreate(init);
  6326. }
  6327. });
  6328. /*
  6329. * 如何实现真正的自动高度?
  6330. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6331. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6332. * 由此就实现了真正的自动高度
  6333. * 测试:chrome、firefox、IE9、IE8
  6334. * */
  6335. /*******************************************************************************
  6336. * KindEditor - WYSIWYG HTML Editor for Internet
  6337. * Copyright (C) 2006-2011 kindsoft.net
  6338. *
  6339. * @author Roddy <luolonghao@gmail.com>
  6340. * @site http://www.kindsoft.net/
  6341. * @licence http://www.kindsoft.net/license.php
  6342. *******************************************************************************/
  6343. KindEditor.plugin('baidumap', function(K) {
  6344. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6345. var mapWidth = K.undef(self.mapWidth, 558);
  6346. var mapHeight = K.undef(self.mapHeight, 360);
  6347. self.clickToolbar(name, function() {
  6348. var html = ['<div style="padding:10px 20px;">',
  6349. '<div class="ke-header">',
  6350. '<div class="ke-left">',
  6351. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6352. '<span class="ke-button-common ke-button-outer">',
  6353. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6354. '</span>',
  6355. '</div>',
  6356. '<div class="ke-right">',
  6357. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6358. '</div>',
  6359. '<div class="ke-clearfix"></div>',
  6360. '</div>',
  6361. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6362. '</div>'].join('');
  6363. var dialog = self.createDialog({
  6364. name : name,
  6365. width : mapWidth + 42,
  6366. title : self.lang(name),
  6367. body : html,
  6368. yesBtn : {
  6369. name : self.lang('yes'),
  6370. click : function(e) {
  6371. var map = win.map;
  6372. var centerObj = map.getCenter();
  6373. var center = centerObj.lng + ',' + centerObj.lat;
  6374. var zoom = map.getZoom();
  6375. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6376. '?center=' + encodeURIComponent(center),
  6377. '&zoom=' + encodeURIComponent(zoom),
  6378. '&width=' + mapWidth,
  6379. '&height=' + mapHeight,
  6380. '&markers=' + encodeURIComponent(center),
  6381. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6382. if (checkbox[0].checked) {
  6383. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6384. } else {
  6385. self.exec('insertimage', url);
  6386. }
  6387. self.hideDialog().focus();
  6388. }
  6389. },
  6390. beforeRemove : function() {
  6391. searchBtn.remove();
  6392. if (doc) {
  6393. doc.write('');
  6394. }
  6395. iframe.remove();
  6396. }
  6397. });
  6398. var div = dialog.div,
  6399. addressBox = K('[name="address"]', div),
  6400. searchBtn = K('[name="searchBtn"]', div),
  6401. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6402. win, doc;
  6403. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6404. function ready() {
  6405. win = iframe[0].contentWindow;
  6406. doc = K.iframeDoc(iframe);
  6407. }
  6408. iframe.bind('load', function() {
  6409. iframe.unbind('load');
  6410. if (K.IE) {
  6411. ready();
  6412. } else {
  6413. setTimeout(ready, 0);
  6414. }
  6415. });
  6416. K('.ke-map', div).replaceWith(iframe);
  6417. searchBtn.click(function() {
  6418. win.search(addressBox.val());
  6419. });
  6420. });
  6421. });
  6422. /*******************************************************************************
  6423. * KindEditor - WYSIWYG HTML Editor for Internet
  6424. * Copyright (C) 2006-2011 kindsoft.net
  6425. *
  6426. * @author Roddy <luolonghao@gmail.com>
  6427. * @site http://www.kindsoft.net/
  6428. * @licence http://www.kindsoft.net/license.php
  6429. *******************************************************************************/
  6430. KindEditor.plugin('map', function(K) {
  6431. var self = this, name = 'map', lang = self.lang(name + '.');
  6432. self.clickToolbar(name, function() {
  6433. var html = ['<div style="padding:10px 20px;">',
  6434. '<div class="ke-dialog-row">',
  6435. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6436. '<span class="ke-button-common ke-button-outer">',
  6437. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6438. '</span>',
  6439. '</div>',
  6440. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6441. '</div>'].join('');
  6442. var dialog = self.createDialog({
  6443. name : name,
  6444. width : 600,
  6445. title : self.lang(name),
  6446. body : html,
  6447. yesBtn : {
  6448. name : self.lang('yes'),
  6449. click : function(e) {
  6450. var geocoder = win.geocoder,
  6451. map = win.map,
  6452. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6453. zoom = map.getZoom(),
  6454. maptype = map.getMapTypeId(),
  6455. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6456. url += '?center=' + encodeURIComponent(center);
  6457. url += '&zoom=' + encodeURIComponent(zoom);
  6458. url += '&size=558x360';
  6459. url += '&maptype=' + encodeURIComponent(maptype);
  6460. url += '&markers=' + encodeURIComponent(center);
  6461. url += '&language=' + self.langType;
  6462. url += '&sensor=false';
  6463. self.exec('insertimage', url).hideDialog().focus();
  6464. }
  6465. },
  6466. beforeRemove : function() {
  6467. searchBtn.remove();
  6468. if (doc) {
  6469. doc.write('');
  6470. }
  6471. iframe.remove();
  6472. }
  6473. });
  6474. var div = dialog.div,
  6475. addressBox = K('[name="address"]', div),
  6476. searchBtn = K('[name="searchBtn"]', div),
  6477. win, doc;
  6478. var iframeHtml = ['<!doctype html><html><head>',
  6479. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6480. '<style>',
  6481. ' html { height: 100% }',
  6482. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6483. ' #map_canvas { height: 100% }',
  6484. '</style>',
  6485. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6486. '<script>',
  6487. 'var map, geocoder;',
  6488. 'function initialize() {',
  6489. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6490. ' var options = {',
  6491. ' zoom: 11,',
  6492. ' center: latlng,',
  6493. ' disableDefaultUI: true,',
  6494. ' panControl: true,',
  6495. ' zoomControl: true,',
  6496. ' mapTypeControl: true,',
  6497. ' scaleControl: true,',
  6498. ' streetViewControl: false,',
  6499. ' overviewMapControl: true,',
  6500. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6501. ' };',
  6502. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6503. ' geocoder = new google.maps.Geocoder();',
  6504. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6505. ' if (status == google.maps.GeocoderStatus.OK) {',
  6506. ' if (results[3]) {',
  6507. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6508. ' }',
  6509. ' }',
  6510. ' });',
  6511. '}',
  6512. 'function search(address) {',
  6513. ' if (!map) return;',
  6514. ' geocoder.geocode({address : address}, function(results, status) {',
  6515. ' if (status == google.maps.GeocoderStatus.OK) {',
  6516. ' map.setZoom(11);',
  6517. ' map.setCenter(results[0].geometry.location);',
  6518. ' var marker = new google.maps.Marker({',
  6519. ' map: map,',
  6520. ' position: results[0].geometry.location',
  6521. ' });',
  6522. ' } else {',
  6523. ' alert("Invalid address: " + address);',
  6524. ' }',
  6525. ' });',
  6526. '}',
  6527. '</script>',
  6528. '</head>',
  6529. '<body onload="initialize();">',
  6530. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6531. '</body></html>'].join('\n');
  6532. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6533. function ready() {
  6534. win = iframe[0].contentWindow;
  6535. doc = K.iframeDoc(iframe);
  6536. }
  6537. iframe.bind('load', function() {
  6538. iframe.unbind('load');
  6539. if (K.IE) {
  6540. ready();
  6541. } else {
  6542. setTimeout(ready, 0);
  6543. }
  6544. });
  6545. K('.ke-map', div).replaceWith(iframe);
  6546. searchBtn.click(function() {
  6547. win.search(addressBox.val());
  6548. });
  6549. });
  6550. });
  6551. /*******************************************************************************
  6552. * KindEditor - WYSIWYG HTML Editor for Internet
  6553. * Copyright (C) 2006-2011 kindsoft.net
  6554. *
  6555. * @author Roddy <luolonghao@gmail.com>
  6556. * @site http://www.kindsoft.net/
  6557. * @licence http://www.kindsoft.net/license.php
  6558. *******************************************************************************/
  6559. KindEditor.plugin('clearhtml', function(K) {
  6560. var self = this, name = 'clearhtml';
  6561. self.clickToolbar(name, function() {
  6562. self.focus();
  6563. var html = self.html();
  6564. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6565. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6566. html = K.formatHtml(html, {
  6567. a : ['href', 'target'],
  6568. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6569. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6570. table : ['border'],
  6571. 'td,th' : ['rowspan', 'colspan'],
  6572. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6573. });
  6574. self.html(html);
  6575. self.cmd.selection(true);
  6576. self.addBookmark();
  6577. });
  6578. });
  6579. /*******************************************************************************
  6580. * KindEditor - WYSIWYG HTML Editor for Internet
  6581. * Copyright (C) 2006-2011 kindsoft.net
  6582. *
  6583. * @author Roddy <luolonghao@gmail.com>
  6584. * @site http://www.kindsoft.net/
  6585. * @licence http://www.kindsoft.net/license.php
  6586. *******************************************************************************/
  6587. KindEditor.plugin('code', function(K) {
  6588. var self = this, name = 'code';
  6589. self.clickToolbar(name, function() {
  6590. var lang = self.lang(name + '.'),
  6591. html = ['<div style="padding:10px 20px;">',
  6592. '<div class="ke-dialog-row">',
  6593. '<select class="ke-code-type">',
  6594. '<option value="js">JavaScript</option>',
  6595. '<option value="html">HTML</option>',
  6596. '<option value="css">CSS</option>',
  6597. '<option value="php">PHP</option>',
  6598. '<option value="pl">Perl</option>',
  6599. '<option value="py">Python</option>',
  6600. '<option value="rb">Ruby</option>',
  6601. '<option value="java">Java</option>',
  6602. '<option value="vb">ASP/VB</option>',
  6603. '<option value="cpp">C/C++</option>',
  6604. '<option value="cs">C#</option>',
  6605. '<option value="xml">XML</option>',
  6606. '<option value="bsh">Shell</option>',
  6607. '<option value="">Other</option>',
  6608. '</select>',
  6609. '</div>',
  6610. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6611. '</div>'].join(''),
  6612. dialog = self.createDialog({
  6613. name : name,
  6614. width : 450,
  6615. title : self.lang(name),
  6616. body : html,
  6617. yesBtn : {
  6618. name : self.lang('yes'),
  6619. click : function(e) {
  6620. var type = K('.ke-code-type', dialog.div).val(),
  6621. code = textarea.val(),
  6622. cls = type === '' ? '' : ' lang-' + type,
  6623. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6624. if (K.trim(code) === '') {
  6625. alert(lang.pleaseInput);
  6626. textarea[0].focus();
  6627. return;
  6628. }
  6629. self.insertHtml(html).hideDialog().focus();
  6630. }
  6631. }
  6632. }),
  6633. textarea = K('textarea', dialog.div);
  6634. textarea[0].focus();
  6635. });
  6636. });
  6637. /*******************************************************************************
  6638. * KindEditor - WYSIWYG HTML Editor for Internet
  6639. * Copyright (C) 2006-2011 kindsoft.net
  6640. *
  6641. * @author Roddy <luolonghao@gmail.com>
  6642. * @site http://www.kindsoft.net/
  6643. * @licence http://www.kindsoft.net/license.php
  6644. *******************************************************************************/
  6645. KindEditor.plugin('emoticons', function(K) {
  6646. var self = this, name = 'emoticons',
  6647. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6648. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6649. currentPageNum = 1;
  6650. self.clickToolbar(name, function() {
  6651. var rows = 5, cols = 9, total = 135, startNum = 0,
  6652. cells = rows * cols, pages = Math.ceil(total / cells),
  6653. colsHalf = Math.floor(cols / 2),
  6654. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6655. elements = [],
  6656. menu = self.createMenu({
  6657. name : name,
  6658. beforeRemove : function() {
  6659. removeEvent();
  6660. }
  6661. });
  6662. menu.div.append(wrapperDiv);
  6663. var previewDiv, previewImg;
  6664. if (allowPreview) {
  6665. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6666. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6667. wrapperDiv.append(previewDiv);
  6668. previewDiv.append(previewImg);
  6669. }
  6670. function bindCellEvent(cell, j, num) {
  6671. if (previewDiv) {
  6672. cell.mouseover(function() {
  6673. if (j > colsHalf) {
  6674. previewDiv.css('left', 0);
  6675. previewDiv.css('right', '');
  6676. } else {
  6677. previewDiv.css('left', '');
  6678. previewDiv.css('right', 0);
  6679. }
  6680. previewImg.attr('src', path + num + '.gif');
  6681. K(this).addClass('ke-on');
  6682. });
  6683. } else {
  6684. cell.mouseover(function() {
  6685. K(this).addClass('ke-on');
  6686. });
  6687. }
  6688. cell.mouseout(function() {
  6689. K(this).removeClass('ke-on');
  6690. });
  6691. cell.click(function(e) {
  6692. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6693. e.stop();
  6694. });
  6695. }
  6696. function createEmoticonsTable(pageNum, parentDiv) {
  6697. var table = document.createElement('table');
  6698. parentDiv.append(table);
  6699. if (previewDiv) {
  6700. K(table).mouseover(function() {
  6701. previewDiv.show('block');
  6702. });
  6703. K(table).mouseout(function() {
  6704. previewDiv.hide();
  6705. });
  6706. elements.push(K(table));
  6707. }
  6708. table.className = 'ke-table';
  6709. table.cellPadding = 0;
  6710. table.cellSpacing = 0;
  6711. table.border = 0;
  6712. var num = (pageNum - 1) * cells + startNum;
  6713. for (var i = 0; i < rows; i++) {
  6714. var row = table.insertRow(i);
  6715. for (var j = 0; j < cols; j++) {
  6716. var cell = K(row.insertCell(j));
  6717. cell.addClass('ke-cell');
  6718. bindCellEvent(cell, j, num);
  6719. var span = K('<span class="ke-img"></span>')
  6720. .css('background-position', '-' + (24 * num) + 'px 0px')
  6721. .css('background-image', 'url(' + path + 'static.gif)');
  6722. cell.append(span);
  6723. elements.push(cell);
  6724. num++;
  6725. }
  6726. }
  6727. return table;
  6728. }
  6729. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6730. function removeEvent() {
  6731. K.each(elements, function() {
  6732. this.unbind();
  6733. });
  6734. }
  6735. var pageDiv;
  6736. function bindPageEvent(el, pageNum) {
  6737. el.click(function(e) {
  6738. removeEvent();
  6739. table.parentNode.removeChild(table);
  6740. pageDiv.remove();
  6741. table = createEmoticonsTable(pageNum, wrapperDiv);
  6742. createPageTable(pageNum);
  6743. currentPageNum = pageNum;
  6744. e.stop();
  6745. });
  6746. }
  6747. function createPageTable(currentPageNum) {
  6748. pageDiv = K('<div class="ke-page"></div>');
  6749. wrapperDiv.append(pageDiv);
  6750. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6751. if (currentPageNum !== pageNum) {
  6752. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6753. bindPageEvent(a, pageNum);
  6754. pageDiv.append(a);
  6755. elements.push(a);
  6756. } else {
  6757. pageDiv.append(K('@[' + pageNum + ']'));
  6758. }
  6759. pageDiv.append(K('@&nbsp;'));
  6760. }
  6761. }
  6762. createPageTable(currentPageNum);
  6763. });
  6764. });
  6765. /*******************************************************************************
  6766. * KindEditor - WYSIWYG HTML Editor for Internet
  6767. * Copyright (C) 2006-2011 kindsoft.net
  6768. *
  6769. * @author Roddy <luolonghao@gmail.com>
  6770. * @site http://www.kindsoft.net/
  6771. * @licence http://www.kindsoft.net/license.php
  6772. *******************************************************************************/
  6773. KindEditor.plugin('filemanager', function(K) {
  6774. var self = this, name = 'filemanager',
  6775. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6776. imgPath = self.pluginsPath + name + '/images/',
  6777. lang = self.lang(name + '.');
  6778. function makeFileTitle(filename, filesize, datetime) {
  6779. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6780. }
  6781. function bindTitle(el, data) {
  6782. if (data.is_dir) {
  6783. el.attr('title', data.filename);
  6784. } else {
  6785. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6786. }
  6787. }
  6788. self.plugin.filemanagerDialog = function(options) {
  6789. var width = K.undef(options.width, 650),
  6790. height = K.undef(options.height, 510),
  6791. dirName = K.undef(options.dirName, ''),
  6792. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6793. clickFn = options.clickFn;
  6794. var html = [
  6795. '<div style="padding:10px 20px;">',
  6796. '<div class="ke-plugin-filemanager-header">',
  6797. '<div class="ke-left">',
  6798. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6799. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6800. '</div>',
  6801. '<div class="ke-right">',
  6802. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6803. '<option value="VIEW">' + lang.viewImage + '</option>',
  6804. '<option value="LIST">' + lang.listImage + '</option>',
  6805. '</select> ',
  6806. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6807. '<option value="NAME">' + lang.fileName + '</option>',
  6808. '<option value="SIZE">' + lang.fileSize + '</option>',
  6809. '<option value="TYPE">' + lang.fileType + '</option>',
  6810. '</select>',
  6811. '</div>',
  6812. '<div class="ke-clearfix"></div>',
  6813. '</div>',
  6814. '<div class="ke-plugin-filemanager-body"></div>',
  6815. '</div>'
  6816. ].join('');
  6817. var dialog = self.createDialog({
  6818. name : name,
  6819. width : width,
  6820. height : height,
  6821. title : self.lang(name),
  6822. body : html
  6823. }),
  6824. div = dialog.div,
  6825. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6826. moveupImg = K('[name="moveupImg"]', div),
  6827. moveupLink = K('[name="moveupLink"]', div),
  6828. viewServerBtn = K('[name="viewServer"]', div),
  6829. viewTypeBox = K('[name="viewType"]', div),
  6830. orderTypeBox = K('[name="orderType"]', div);
  6831. function reloadPage(path, order, func) {
  6832. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6833. dialog.showLoading(self.lang('ajaxLoading'));
  6834. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6835. dialog.hideLoading();
  6836. func(data);
  6837. });
  6838. }
  6839. var elList = [];
  6840. function bindEvent(el, result, data, createFunc) {
  6841. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6842. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6843. if (data.is_dir) {
  6844. el.click(function(e) {
  6845. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6846. });
  6847. } else if (data.is_photo) {
  6848. el.click(function(e) {
  6849. clickFn.call(this, fileUrl, data.filename);
  6850. });
  6851. } else {
  6852. el.click(function(e) {
  6853. clickFn.call(this, fileUrl, data.filename);
  6854. });
  6855. }
  6856. elList.push(el);
  6857. }
  6858. function createCommon(result, createFunc) {
  6859. K.each(elList, function() {
  6860. this.unbind();
  6861. });
  6862. moveupLink.unbind();
  6863. viewTypeBox.unbind();
  6864. orderTypeBox.unbind();
  6865. if (result.current_dir_path) {
  6866. moveupLink.click(function(e) {
  6867. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6868. });
  6869. }
  6870. function changeFunc() {
  6871. if (viewTypeBox.val() == 'VIEW') {
  6872. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6873. } else {
  6874. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6875. }
  6876. }
  6877. viewTypeBox.change(changeFunc);
  6878. orderTypeBox.change(changeFunc);
  6879. bodyDiv.html('');
  6880. }
  6881. function createList(result) {
  6882. createCommon(result, createList);
  6883. var table = document.createElement('table');
  6884. table.className = 'ke-table';
  6885. table.cellPadding = 0;
  6886. table.cellSpacing = 0;
  6887. table.border = 0;
  6888. bodyDiv.append(table);
  6889. var fileList = result.file_list;
  6890. for (var i = 0, len = fileList.length; i < len; i++) {
  6891. var data = fileList[i], row = K(table.insertRow(i));
  6892. row.mouseover(function(e) {
  6893. K(this).addClass('ke-on');
  6894. })
  6895. .mouseout(function(e) {
  6896. K(this).removeClass('ke-on');
  6897. });
  6898. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6899. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6900. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6901. if (!data.is_dir || data.has_file) {
  6902. row.css('cursor', 'pointer');
  6903. cell0.attr('title', data.filename);
  6904. bindEvent(cell0, result, data, createList);
  6905. } else {
  6906. cell0.attr('title', lang.emptyFolder);
  6907. }
  6908. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6909. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6910. }
  6911. }
  6912. function createView(result) {
  6913. createCommon(result, createView);
  6914. var fileList = result.file_list;
  6915. for (var i = 0, len = fileList.length; i < len; i++) {
  6916. var data = fileList[i],
  6917. div = K('<div class="ke-inline-block ke-item"></div>');
  6918. bodyDiv.append(div);
  6919. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6920. .mouseover(function(e) {
  6921. K(this).addClass('ke-on');
  6922. })
  6923. .mouseout(function(e) {
  6924. K(this).removeClass('ke-on');
  6925. });
  6926. div.append(photoDiv);
  6927. var fileUrl = result.current_url + data.filename,
  6928. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6929. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6930. if (!data.is_dir || data.has_file) {
  6931. photoDiv.css('cursor', 'pointer');
  6932. bindTitle(photoDiv, data);
  6933. bindEvent(photoDiv, result, data, createView);
  6934. } else {
  6935. photoDiv.attr('title', lang.emptyFolder);
  6936. }
  6937. photoDiv.append(img);
  6938. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6939. }
  6940. }
  6941. viewTypeBox.val(viewType);
  6942. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6943. return dialog;
  6944. }
  6945. });
  6946. /*******************************************************************************
  6947. * KindEditor - WYSIWYG HTML Editor for Internet
  6948. * Copyright (C) 2006-2011 kindsoft.net
  6949. *
  6950. * @author Roddy <luolonghao@gmail.com>
  6951. * @site http://www.kindsoft.net/
  6952. * @licence http://www.kindsoft.net/license.php
  6953. *******************************************************************************/
  6954. KindEditor.plugin('flash', function(K) {
  6955. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6956. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6957. allowFileManager = K.undef(self.allowFileManager, false),
  6958. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6959. extraParams = K.undef(self.extraFileUploadParams, {}),
  6960. filePostName = K.undef(self.filePostName, 'imgFile'),
  6961. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  6962. self.plugin.flash = {
  6963. edit : function() {
  6964. var html = [
  6965. '<div style="padding:20px;">',
  6966. '<div class="ke-dialog-row">',
  6967. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6968. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6969. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6970. '<span class="ke-button-common ke-button-outer">',
  6971. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6972. '</span>',
  6973. '</div>',
  6974. '<div class="ke-dialog-row">',
  6975. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6976. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6977. '</div>',
  6978. '<div class="ke-dialog-row">',
  6979. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6980. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6981. '</div>',
  6982. '</div>'
  6983. ].join('');
  6984. var dialog = self.createDialog({
  6985. name : name,
  6986. width : 450,
  6987. title : self.lang(name),
  6988. body : html,
  6989. yesBtn : {
  6990. name : self.lang('yes'),
  6991. click : function(e) {
  6992. var url = K.trim(urlBox.val()),
  6993. width = widthBox.val(),
  6994. height = heightBox.val();
  6995. if (url == 'http://' || K.invalidUrl(url)) {
  6996. alert(self.lang('invalidUrl'));
  6997. urlBox[0].focus();
  6998. return;
  6999. }
  7000. if (!/^\d*$/.test(width)) {
  7001. alert(self.lang('invalidWidth'));
  7002. widthBox[0].focus();
  7003. return;
  7004. }
  7005. if (!/^\d*$/.test(height)) {
  7006. alert(self.lang('invalidHeight'));
  7007. heightBox[0].focus();
  7008. return;
  7009. }
  7010. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7011. src : url,
  7012. type : K.mediaType('.swf'),
  7013. width : width,
  7014. height : height,
  7015. quality : 'high'
  7016. });
  7017. self.insertHtml(html).hideDialog().focus();
  7018. }
  7019. }
  7020. }),
  7021. div = dialog.div,
  7022. urlBox = K('[name="url"]', div),
  7023. viewServerBtn = K('[name="viewServer"]', div),
  7024. widthBox = K('[name="width"]', div),
  7025. heightBox = K('[name="height"]', div);
  7026. urlBox.val('http://');
  7027. if (allowFlashUpload) {
  7028. var uploadbutton = K.uploadbutton({
  7029. button : K('.ke-upload-button', div)[0],
  7030. fieldName : filePostName,
  7031. extraParams : extraParams,
  7032. url : K.addParam(uploadJson, 'dir=flash'),
  7033. afterUpload : function(data) {
  7034. dialog.hideLoading();
  7035. if (data.error === 0) {
  7036. var url = data.url;
  7037. if (formatUploadUrl) {
  7038. url = K.formatUrl(url, 'absolute');
  7039. }
  7040. urlBox.val(url);
  7041. if (self.afterUpload) {
  7042. self.afterUpload.call(self, url, data, name);
  7043. }
  7044. alert(self.lang('uploadSuccess'));
  7045. } else {
  7046. alert(data.message);
  7047. }
  7048. },
  7049. afterError : function(html) {
  7050. dialog.hideLoading();
  7051. self.errorDialog(html);
  7052. }
  7053. });
  7054. uploadbutton.fileBox.change(function(e) {
  7055. dialog.showLoading(self.lang('uploadLoading'));
  7056. uploadbutton.submit();
  7057. });
  7058. } else {
  7059. K('.ke-upload-button', div).hide();
  7060. }
  7061. if (allowFileManager) {
  7062. viewServerBtn.click(function(e) {
  7063. self.loadPlugin('filemanager', function() {
  7064. self.plugin.filemanagerDialog({
  7065. viewType : 'LIST',
  7066. dirName : 'flash',
  7067. clickFn : function(url, title) {
  7068. if (self.dialogs.length > 1) {
  7069. K('[name="url"]', div).val(url);
  7070. if (self.afterSelectFile) {
  7071. self.afterSelectFile.call(self, url);
  7072. }
  7073. self.hideDialog();
  7074. }
  7075. }
  7076. });
  7077. });
  7078. });
  7079. } else {
  7080. viewServerBtn.hide();
  7081. }
  7082. var img = self.plugin.getSelectedFlash();
  7083. if (img) {
  7084. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7085. urlBox.val(attrs.src);
  7086. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7087. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7088. }
  7089. urlBox[0].focus();
  7090. urlBox[0].select();
  7091. },
  7092. 'delete' : function() {
  7093. self.plugin.getSelectedFlash().remove();
  7094. self.addBookmark();
  7095. }
  7096. };
  7097. self.clickToolbar(name, self.plugin.flash.edit);
  7098. });
  7099. /*******************************************************************************
  7100. * KindEditor - WYSIWYG HTML Editor for Internet
  7101. * Copyright (C) 2006-2011 kindsoft.net
  7102. *
  7103. * @author Roddy <luolonghao@gmail.com>
  7104. * @site http://www.kindsoft.net/
  7105. * @licence http://www.kindsoft.net/license.php
  7106. *******************************************************************************/
  7107. KindEditor.plugin('image', function(K) {
  7108. var self = this, name = 'image',
  7109. allowImageUpload = K.undef(self.allowImageUpload, true),
  7110. allowImageRemote = K.undef(self.allowImageRemote, true),
  7111. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7112. allowFileManager = K.undef(self.allowFileManager, false),
  7113. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7114. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7115. imgPath = self.pluginsPath + 'image/images/',
  7116. extraParams = K.undef(self.extraFileUploadParams, {}),
  7117. filePostName = K.undef(self.filePostName, 'imgFile'),
  7118. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7119. lang = self.lang(name + '.');
  7120. self.plugin.imageDialog = function(options) {
  7121. var imageUrl = options.imageUrl,
  7122. imageWidth = K.undef(options.imageWidth, ''),
  7123. imageHeight = K.undef(options.imageHeight, ''),
  7124. imageTitle = K.undef(options.imageTitle, ''),
  7125. imageAlign = K.undef(options.imageAlign, ''),
  7126. showRemote = K.undef(options.showRemote, true),
  7127. showLocal = K.undef(options.showLocal, true),
  7128. tabIndex = K.undef(options.tabIndex, 0),
  7129. clickFn = options.clickFn;
  7130. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7131. var hiddenElements = [];
  7132. for(var k in extraParams){
  7133. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7134. }
  7135. var html = [
  7136. '<div style="padding:20px;">',
  7137. '<div class="tabs"></div>',
  7138. '<div class="tab1" style="display:none;">',
  7139. '<div class="ke-dialog-row">',
  7140. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7141. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7142. '<span class="ke-button-common ke-button-outer">',
  7143. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7144. '</span>',
  7145. '</div>',
  7146. '<div class="ke-dialog-row">',
  7147. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7148. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7149. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7150. // '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7151. '</div>',
  7152. '<div class="ke-dialog-row">',
  7153. '<label style="width:60px;">' + lang.align + '</label>',
  7154. '<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="" />',
  7155. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7156. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7157. '</div>',
  7158. '<div class="ke-dialog-row">',
  7159. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7160. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7161. '</div>',
  7162. '</div>',
  7163. '<div class="tab2" style="display:none;">',
  7164. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7165. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7166. '<div class="ke-dialog-row">',
  7167. hiddenElements.join(''),
  7168. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7169. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7170. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7171. '</div>',
  7172. '</form>',
  7173. '</div>',
  7174. '</div>'
  7175. ].join('');
  7176. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7177. dialogHeight = showLocal && showRemote ? 300 : 250;
  7178. var dialog = self.createDialog({
  7179. name : name,
  7180. width : dialogWidth,
  7181. height : dialogHeight,
  7182. title : self.lang(name),
  7183. body : html,
  7184. yesBtn : {
  7185. name : self.lang('yes'),
  7186. click : function(e) {
  7187. if (dialog.isLoading) {
  7188. return;
  7189. }
  7190. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7191. if (uploadbutton.fileBox.val() == '') {
  7192. alert(self.lang('pleaseSelectFile'));
  7193. return;
  7194. }
  7195. dialog.showLoading(self.lang('uploadLoading'));
  7196. uploadbutton.submit();
  7197. localUrlBox.val('');
  7198. return;
  7199. }
  7200. var url = K.trim(urlBox.val()),
  7201. width = widthBox.val(),
  7202. height = heightBox.val(),
  7203. title = titleBox.val(),
  7204. align = '';
  7205. alignBox.each(function() {
  7206. if (this.checked) {
  7207. align = this.value;
  7208. return false;
  7209. }
  7210. });
  7211. if (url == 'http://' || K.invalidUrl(url)) {
  7212. alert(self.lang('invalidUrl'));
  7213. urlBox[0].focus();
  7214. return;
  7215. }
  7216. if (!/^\d*$/.test(width)) {
  7217. alert(self.lang('invalidWidth'));
  7218. widthBox[0].focus();
  7219. return;
  7220. }
  7221. if (!/^\d*$/.test(height)) {
  7222. alert(self.lang('invalidHeight'));
  7223. heightBox[0].focus();
  7224. return;
  7225. }
  7226. clickFn.call(self, url, title, width, height, 0, align);
  7227. }
  7228. },
  7229. beforeRemove : function() {
  7230. viewServerBtn.unbind();
  7231. widthBox.unbind();
  7232. heightBox.unbind();
  7233. refreshBtn.unbind();
  7234. }
  7235. }),
  7236. div = dialog.div;
  7237. var urlBox = K('[name="url"]', div),
  7238. localUrlBox = K('[name="localUrl"]', div),
  7239. viewServerBtn = K('[name="viewServer"]', div),
  7240. widthBox = K('.tab1 [name="width"]', div),
  7241. heightBox = K('.tab1 [name="height"]', div),
  7242. refreshBtn = K('.ke-refresh-btn', div),
  7243. titleBox = K('.tab1 [name="title"]', div),
  7244. alignBox = K('.tab1 [name="align"]', div);
  7245. var tabs;
  7246. if (showRemote && showLocal) {
  7247. tabs = K.tabs({
  7248. src : K('.tabs', div),
  7249. afterSelect : function(i) {}
  7250. });
  7251. tabs.add({
  7252. title : lang.remoteImage,
  7253. panel : K('.tab1', div)
  7254. });
  7255. tabs.add({
  7256. title : lang.localImage,
  7257. panel : K('.tab2', div)
  7258. });
  7259. tabs.select(tabIndex);
  7260. } else if (showRemote) {
  7261. K('.tab1', div).show();
  7262. } else if (showLocal) {
  7263. K('.tab2', div).show();
  7264. }
  7265. var uploadbutton = K.uploadbutton({
  7266. button : K('.ke-upload-button', div)[0],
  7267. fieldName : filePostName,
  7268. form : K('.ke-form', div),
  7269. target : target,
  7270. width: 60,
  7271. afterUpload : function(data) {
  7272. dialog.hideLoading();
  7273. if (data.error === 0) {
  7274. var url = data.url;
  7275. if (formatUploadUrl) {
  7276. url = K.formatUrl(url, 'absolute');
  7277. }
  7278. if (self.afterUpload) {
  7279. self.afterUpload.call(self, url, data, name);
  7280. }
  7281. if (!fillDescAfterUploadImage) {
  7282. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7283. } else {
  7284. K(".ke-dialog-row #remoteUrl", div).val(url);
  7285. K(".ke-tabs-li", div)[0].click();
  7286. K(".ke-refresh-btn", div).click();
  7287. }
  7288. } else {
  7289. alert(data.message);
  7290. }
  7291. },
  7292. afterError : function(html) {
  7293. dialog.hideLoading();
  7294. self.errorDialog(html);
  7295. }
  7296. });
  7297. uploadbutton.fileBox.change(function(e) {
  7298. localUrlBox.val(uploadbutton.fileBox.val());
  7299. });
  7300. if (allowFileManager) {
  7301. viewServerBtn.click(function(e) {
  7302. self.loadPlugin('filemanager', function() {
  7303. self.plugin.filemanagerDialog({
  7304. viewType : 'VIEW',
  7305. dirName : 'image',
  7306. clickFn : function(url, title) {
  7307. if (self.dialogs.length > 1) {
  7308. K('[name="url"]', div).val(url);
  7309. if (self.afterSelectFile) {
  7310. self.afterSelectFile.call(self, url);
  7311. }
  7312. self.hideDialog();
  7313. }
  7314. }
  7315. });
  7316. });
  7317. });
  7318. } else {
  7319. viewServerBtn.hide();
  7320. }
  7321. var originalWidth = 0, originalHeight = 0;
  7322. function setSize(width, height) {
  7323. widthBox.val(width);
  7324. heightBox.val(height);
  7325. originalWidth = width;
  7326. originalHeight = height;
  7327. }
  7328. refreshBtn.click(function(e) {
  7329. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7330. position : 'absolute',
  7331. visibility : 'hidden',
  7332. top : 0,
  7333. left : '-1000px'
  7334. });
  7335. tempImg.bind('load', function() {
  7336. setSize(tempImg.width(), tempImg.height());
  7337. tempImg.remove();
  7338. });
  7339. K(document.body).append(tempImg);
  7340. });
  7341. widthBox.change(function(e) {
  7342. if (originalWidth > 0) {
  7343. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7344. }
  7345. });
  7346. heightBox.change(function(e) {
  7347. if (originalHeight > 0) {
  7348. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7349. }
  7350. });
  7351. urlBox.val(options.imageUrl);
  7352. setSize(options.imageWidth, options.imageHeight);
  7353. titleBox.val(options.imageTitle);
  7354. alignBox.each(function() {
  7355. if (this.value === options.imageAlign) {
  7356. this.checked = true;
  7357. return false;
  7358. }
  7359. });
  7360. if (showRemote && tabIndex === 0) {
  7361. urlBox[0].focus();
  7362. urlBox[0].select();
  7363. }
  7364. return dialog;
  7365. };
  7366. self.plugin.image = {
  7367. edit : function() {
  7368. var img = self.plugin.getSelectedImage();
  7369. self.plugin.imageDialog({
  7370. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7371. imageWidth : img ? img.width() : '',
  7372. imageHeight : img ? img.height() : '',
  7373. imageTitle : img ? img.attr('title') : '',
  7374. imageAlign : img ? img.attr('align') : '',
  7375. showRemote : allowImageRemote,
  7376. showLocal : allowImageUpload,
  7377. tabIndex: img ? 0 : imageTabIndex,
  7378. clickFn : function(url, title, width, height, border, align) {
  7379. if (img) {
  7380. img.attr('src', url);
  7381. img.attr('data-ke-src', url);
  7382. img.attr('width', width);
  7383. img.attr('height', height);
  7384. img.attr('title', title);
  7385. img.attr('align', align);
  7386. img.attr('alt', title);
  7387. } else {
  7388. self.exec('insertimage', url, title, width, height, border, align);
  7389. }
  7390. setTimeout(function() {
  7391. self.hideDialog().focus();
  7392. }, 0);
  7393. }
  7394. });
  7395. },
  7396. 'delete' : function() {
  7397. var target = self.plugin.getSelectedImage();
  7398. if (target.parent().name == 'a') {
  7399. target = target.parent();
  7400. }
  7401. target.remove();
  7402. self.addBookmark();
  7403. }
  7404. };
  7405. self.clickToolbar(name, self.plugin.image.edit);
  7406. });
  7407. /*******************************************************************************
  7408. * KindEditor - WYSIWYG HTML Editor for Internet
  7409. * Copyright (C) 2006-2011 kindsoft.net
  7410. *
  7411. * @author Roddy <luolonghao@gmail.com>
  7412. * @site http://www.kindsoft.net/
  7413. * @licence http://www.kindsoft.net/license.php
  7414. *******************************************************************************/
  7415. KindEditor.plugin('insertfile', function(K) {
  7416. var self = this, name = 'insertfile',
  7417. allowFileUpload = K.undef(self.allowFileUpload, true),
  7418. allowFileManager = K.undef(self.allowFileManager, false),
  7419. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7420. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7421. extraParams = K.undef(self.extraFileUploadParams, {}),
  7422. filePostName = K.undef(self.filePostName, 'imgFile'),
  7423. lang = self.lang(name + '.');
  7424. self.plugin.fileDialog = function(options) {
  7425. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7426. fileTitle = K.undef(options.fileTitle, ''),
  7427. clickFn = options.clickFn;
  7428. var html = [
  7429. '<div style="padding:20px;">',
  7430. '<div class="ke-dialog-row">',
  7431. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7432. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7433. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7434. '<span class="ke-button-common ke-button-outer">',
  7435. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7436. '</span>',
  7437. '</div>',
  7438. '<div class="ke-dialog-row">',
  7439. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7440. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7441. '</div>',
  7442. '</form>',
  7443. '</div>'
  7444. ].join('');
  7445. var dialog = self.createDialog({
  7446. name : name,
  7447. width : 450,
  7448. title : self.lang(name),
  7449. body : html,
  7450. yesBtn : {
  7451. name : self.lang('yes'),
  7452. click : function(e) {
  7453. var url = K.trim(urlBox.val()),
  7454. title = titleBox.val();
  7455. if (url == 'http://' || K.invalidUrl(url)) {
  7456. alert(self.lang('invalidUrl'));
  7457. urlBox[0].focus();
  7458. return;
  7459. }
  7460. if (K.trim(title) === '') {
  7461. title = url;
  7462. }
  7463. clickFn.call(self, url, title);
  7464. }
  7465. }
  7466. }),
  7467. div = dialog.div;
  7468. var urlBox = K('[name="url"]', div),
  7469. viewServerBtn = K('[name="viewServer"]', div),
  7470. titleBox = K('[name="title"]', div);
  7471. if (allowFileUpload) {
  7472. var uploadbutton = K.uploadbutton({
  7473. button : K('.ke-upload-button', div)[0],
  7474. fieldName : filePostName,
  7475. url : K.addParam(uploadJson, 'dir=file'),
  7476. extraParams : extraParams,
  7477. afterUpload : function(data) {
  7478. dialog.hideLoading();
  7479. if (data.error === 0) {
  7480. var url = data.url;
  7481. if (formatUploadUrl) {
  7482. url = K.formatUrl(url, 'absolute');
  7483. }
  7484. urlBox.val(url);
  7485. if (self.afterUpload) {
  7486. self.afterUpload.call(self, url, data, name);
  7487. }
  7488. alert(self.lang('uploadSuccess'));
  7489. } else {
  7490. alert(data.message);
  7491. }
  7492. },
  7493. afterError : function(html) {
  7494. dialog.hideLoading();
  7495. self.errorDialog(html);
  7496. }
  7497. });
  7498. uploadbutton.fileBox.change(function(e) {
  7499. dialog.showLoading(self.lang('uploadLoading'));
  7500. uploadbutton.submit();
  7501. });
  7502. } else {
  7503. K('.ke-upload-button', div).hide();
  7504. }
  7505. if (allowFileManager) {
  7506. viewServerBtn.click(function(e) {
  7507. self.loadPlugin('filemanager', function() {
  7508. self.plugin.filemanagerDialog({
  7509. viewType : 'LIST',
  7510. dirName : 'file',
  7511. clickFn : function(url, title) {
  7512. if (self.dialogs.length > 1) {
  7513. K('[name="url"]', div).val(url);
  7514. if (self.afterSelectFile) {
  7515. self.afterSelectFile.call(self, url);
  7516. }
  7517. self.hideDialog();
  7518. }
  7519. }
  7520. });
  7521. });
  7522. });
  7523. } else {
  7524. viewServerBtn.hide();
  7525. }
  7526. urlBox.val(fileUrl);
  7527. titleBox.val(fileTitle);
  7528. urlBox[0].focus();
  7529. urlBox[0].select();
  7530. };
  7531. self.clickToolbar(name, function() {
  7532. self.plugin.fileDialog({
  7533. clickFn : function(url, title) {
  7534. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7535. self.insertHtml(html).hideDialog().focus();
  7536. }
  7537. });
  7538. });
  7539. });
  7540. /*******************************************************************************
  7541. * KindEditor - WYSIWYG HTML Editor for Internet
  7542. * Copyright (C) 2006-2011 kindsoft.net
  7543. *
  7544. * @author Roddy <luolonghao@gmail.com>
  7545. * @site http://www.kindsoft.net/
  7546. * @licence http://www.kindsoft.net/license.php
  7547. *******************************************************************************/
  7548. KindEditor.plugin('lineheight', function(K) {
  7549. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7550. self.clickToolbar(name, function() {
  7551. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7552. if (commonNode) {
  7553. curVal = commonNode.css('line-height');
  7554. }
  7555. var menu = self.createMenu({
  7556. name : name,
  7557. width : 150
  7558. });
  7559. K.each(lang.lineHeight, function(i, row) {
  7560. K.each(row, function(key, val) {
  7561. menu.addItem({
  7562. title : val,
  7563. checked : curVal === key,
  7564. click : function() {
  7565. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7566. span : '.line-height=' + key
  7567. });
  7568. self.updateState();
  7569. self.addBookmark();
  7570. self.hideMenu();
  7571. }
  7572. });
  7573. });
  7574. });
  7575. });
  7576. });
  7577. /*******************************************************************************
  7578. * KindEditor - WYSIWYG HTML Editor for Internet
  7579. * Copyright (C) 2006-2011 kindsoft.net
  7580. *
  7581. * @author Roddy <luolonghao@gmail.com>
  7582. * @site http://www.kindsoft.net/
  7583. * @licence http://www.kindsoft.net/license.php
  7584. *******************************************************************************/
  7585. KindEditor.plugin('link', function(K) {
  7586. var self = this, name = 'link';
  7587. self.plugin.link = {
  7588. edit : function() {
  7589. var lang = self.lang(name + '.'),
  7590. html = '<div style="padding:20px;">' +
  7591. '<div class="ke-dialog-row">' +
  7592. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7593. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7594. '<div class="ke-dialog-row"">' +
  7595. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7596. '<select id="keType" name="type"></select>' +
  7597. '</div>' +
  7598. '</div>',
  7599. dialog = self.createDialog({
  7600. name : name,
  7601. width : 450,
  7602. title : self.lang(name),
  7603. body : html,
  7604. yesBtn : {
  7605. name : self.lang('yes'),
  7606. click : function(e) {
  7607. var url = K.trim(urlBox.val());
  7608. if (url == 'http://' || K.invalidUrl(url)) {
  7609. alert(self.lang('invalidUrl'));
  7610. urlBox[0].focus();
  7611. return;
  7612. }
  7613. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7614. }
  7615. }
  7616. }),
  7617. div = dialog.div,
  7618. urlBox = K('input[name="url"]', div),
  7619. typeBox = K('select[name="type"]', div);
  7620. urlBox.val('http://');
  7621. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7622. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7623. self.cmd.selection();
  7624. var a = self.plugin.getSelectedLink();
  7625. if (a) {
  7626. self.cmd.range.selectNode(a[0]);
  7627. self.cmd.select();
  7628. urlBox.val(a.attr('data-ke-src'));
  7629. typeBox.val(a.attr('target'));
  7630. }
  7631. urlBox[0].focus();
  7632. urlBox[0].select();
  7633. },
  7634. 'delete' : function() {
  7635. self.exec('unlink', null);
  7636. }
  7637. };
  7638. self.clickToolbar(name, self.plugin.link.edit);
  7639. });
  7640. /*******************************************************************************
  7641. * KindEditor - WYSIWYG HTML Editor for Internet
  7642. * Copyright (C) 2006-2011 kindsoft.net
  7643. *
  7644. * @author Roddy <luolonghao@gmail.com>
  7645. * @site http://www.kindsoft.net/
  7646. * @licence http://www.kindsoft.net/license.php
  7647. *******************************************************************************/
  7648. KindEditor.plugin('media', function(K) {
  7649. var self = this, name = 'media', lang = self.lang(name + '.'),
  7650. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7651. allowFileManager = K.undef(self.allowFileManager, false),
  7652. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7653. extraParams = K.undef(self.extraFileUploadParams, {}),
  7654. filePostName = K.undef(self.filePostName, 'imgFile'),
  7655. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7656. self.plugin.media = {
  7657. edit : function() {
  7658. var html = [
  7659. '<div style="padding:20px;">',
  7660. '<div class="ke-dialog-row">',
  7661. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7662. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7663. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7664. '<span class="ke-button-common ke-button-outer">',
  7665. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7666. '</span>',
  7667. '</div>',
  7668. '<div class="ke-dialog-row">',
  7669. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7670. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7671. '</div>',
  7672. '<div class="ke-dialog-row">',
  7673. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7674. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7675. '</div>',
  7676. '<div class="ke-dialog-row">',
  7677. '<label for="keAutostart">' + lang.autostart + '</label>',
  7678. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7679. '</div>',
  7680. '</div>'
  7681. ].join('');
  7682. var dialog = self.createDialog({
  7683. name : name,
  7684. width : 450,
  7685. height : 230,
  7686. title : self.lang(name),
  7687. body : html,
  7688. yesBtn : {
  7689. name : self.lang('yes'),
  7690. click : function(e) {
  7691. var url = K.trim(urlBox.val()),
  7692. width = widthBox.val(),
  7693. height = heightBox.val();
  7694. if (url == 'http://' || K.invalidUrl(url)) {
  7695. alert(self.lang('invalidUrl'));
  7696. urlBox[0].focus();
  7697. return;
  7698. }
  7699. if (!/^\d*$/.test(width)) {
  7700. alert(self.lang('invalidWidth'));
  7701. widthBox[0].focus();
  7702. return;
  7703. }
  7704. if (!/^\d*$/.test(height)) {
  7705. alert(self.lang('invalidHeight'));
  7706. heightBox[0].focus();
  7707. return;
  7708. }
  7709. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7710. src : url,
  7711. type : K.mediaType(url),
  7712. width : width,
  7713. height : height,
  7714. autostart : autostartBox[0].checked ? 'true' : 'false',
  7715. loop : 'true'
  7716. });
  7717. self.insertHtml(html).hideDialog().focus();
  7718. }
  7719. }
  7720. }),
  7721. div = dialog.div,
  7722. urlBox = K('[name="url"]', div),
  7723. viewServerBtn = K('[name="viewServer"]', div),
  7724. widthBox = K('[name="width"]', div),
  7725. heightBox = K('[name="height"]', div),
  7726. autostartBox = K('[name="autostart"]', div);
  7727. urlBox.val('http://');
  7728. if (allowMediaUpload) {
  7729. var uploadbutton = K.uploadbutton({
  7730. button : K('.ke-upload-button', div)[0],
  7731. fieldName : filePostName,
  7732. extraParams : extraParams,
  7733. url : K.addParam(uploadJson, 'dir=media'),
  7734. afterUpload : function(data) {
  7735. dialog.hideLoading();
  7736. if (data.error === 0) {
  7737. var url = data.url;
  7738. if (formatUploadUrl) {
  7739. url = K.formatUrl(url, 'absolute');
  7740. }
  7741. urlBox.val(url);
  7742. if (self.afterUpload) {
  7743. self.afterUpload.call(self, url, data, name);
  7744. }
  7745. alert(self.lang('uploadSuccess'));
  7746. } else {
  7747. alert(data.message);
  7748. }
  7749. },
  7750. afterError : function(html) {
  7751. dialog.hideLoading();
  7752. self.errorDialog(html);
  7753. }
  7754. });
  7755. uploadbutton.fileBox.change(function(e) {
  7756. dialog.showLoading(self.lang('uploadLoading'));
  7757. uploadbutton.submit();
  7758. });
  7759. } else {
  7760. K('.ke-upload-button', div).hide();
  7761. }
  7762. if (allowFileManager) {
  7763. viewServerBtn.click(function(e) {
  7764. self.loadPlugin('filemanager', function() {
  7765. self.plugin.filemanagerDialog({
  7766. viewType : 'LIST',
  7767. dirName : 'media',
  7768. clickFn : function(url, title) {
  7769. if (self.dialogs.length > 1) {
  7770. K('[name="url"]', div).val(url);
  7771. if (self.afterSelectFile) {
  7772. self.afterSelectFile.call(self, url);
  7773. }
  7774. self.hideDialog();
  7775. }
  7776. }
  7777. });
  7778. });
  7779. });
  7780. } else {
  7781. viewServerBtn.hide();
  7782. }
  7783. var img = self.plugin.getSelectedMedia();
  7784. if (img) {
  7785. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7786. urlBox.val(attrs.src);
  7787. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7788. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7789. autostartBox[0].checked = (attrs.autostart === 'true');
  7790. }
  7791. urlBox[0].focus();
  7792. urlBox[0].select();
  7793. },
  7794. 'delete' : function() {
  7795. self.plugin.getSelectedMedia().remove();
  7796. self.addBookmark();
  7797. }
  7798. };
  7799. self.clickToolbar(name, self.plugin.media.edit);
  7800. });
  7801. /*******************************************************************************
  7802. * KindEditor - WYSIWYG HTML Editor for Internet
  7803. * Copyright (C) 2006-2011 kindsoft.net
  7804. *
  7805. * @author Roddy <luolonghao@gmail.com>
  7806. * @site http://www.kindsoft.net/
  7807. * @licence http://www.kindsoft.net/license.php
  7808. *******************************************************************************/
  7809. (function(K) {
  7810. function KSWFUpload(options) {
  7811. this.init(options);
  7812. }
  7813. K.extend(KSWFUpload, {
  7814. init : function(options) {
  7815. var self = this;
  7816. options.afterError = options.afterError || function(str) {
  7817. alert(str);
  7818. };
  7819. self.options = options;
  7820. self.progressbars = {};
  7821. self.div = K(options.container).html([
  7822. '<div class="ke-swfupload">',
  7823. '<div class="ke-swfupload-top">',
  7824. '<div class="ke-inline-block ke-swfupload-button">',
  7825. '<input type="button" value="Browse" />',
  7826. '</div>',
  7827. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7828. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7829. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7830. '</span>',
  7831. '</div>',
  7832. '<div class="ke-swfupload-body"></div>',
  7833. '</div>'
  7834. ].join(''));
  7835. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7836. function showError(itemDiv, msg) {
  7837. K('.ke-status > div', itemDiv).hide();
  7838. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7839. }
  7840. var settings = {
  7841. debug : false,
  7842. upload_url : options.uploadUrl,
  7843. flash_url : options.flashUrl,
  7844. file_post_name : options.filePostName,
  7845. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7846. button_image_url: options.buttonImageUrl,
  7847. button_width: options.buttonWidth,
  7848. button_height: options.buttonHeight,
  7849. button_cursor : SWFUpload.CURSOR.HAND,
  7850. file_types : options.fileTypes,
  7851. file_types_description : options.fileTypesDesc,
  7852. file_upload_limit : options.fileUploadLimit,
  7853. file_size_limit : options.fileSizeLimit,
  7854. post_params : options.postParams,
  7855. file_queued_handler : function(file) {
  7856. file.url = self.options.fileIconUrl;
  7857. self.appendFile(file);
  7858. },
  7859. file_queue_error_handler : function(file, errorCode, message) {
  7860. var errorName = '';
  7861. switch (errorCode) {
  7862. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7863. errorName = options.queueLimitExceeded;
  7864. break;
  7865. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7866. errorName = options.fileExceedsSizeLimit;
  7867. break;
  7868. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7869. errorName = options.zeroByteFile;
  7870. break;
  7871. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7872. errorName = options.invalidFiletype;
  7873. break;
  7874. default:
  7875. errorName = options.unknownError;
  7876. break;
  7877. }
  7878. K.DEBUG && alert(errorName);
  7879. },
  7880. upload_start_handler : function(file) {
  7881. var self = this;
  7882. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7883. K('.ke-status > div', itemDiv).hide();
  7884. K('.ke-progressbar', itemDiv).show();
  7885. },
  7886. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7887. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7888. var progressbar = self.progressbars[file.id];
  7889. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7890. progressbar.percent.html(percent + '%');
  7891. },
  7892. upload_error_handler : function(file, errorCode, message) {
  7893. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7894. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7895. showError(itemDiv, self.options.errorMessage);
  7896. }
  7897. },
  7898. upload_success_handler : function(file, serverData) {
  7899. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7900. var data = {};
  7901. try {
  7902. data = K.json(serverData);
  7903. } catch (e) {
  7904. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7905. }
  7906. if (data.error !== 0) {
  7907. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7908. return;
  7909. }
  7910. file.url = data.url;
  7911. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7912. K('.ke-status > div', itemDiv).hide();
  7913. }
  7914. };
  7915. self.swfu = new SWFUpload(settings);
  7916. K('.ke-swfupload-startupload input', self.div).click(function() {
  7917. self.swfu.startUpload();
  7918. });
  7919. },
  7920. getUrlList : function() {
  7921. var list = [];
  7922. K('.ke-img', self.bodyDiv).each(function() {
  7923. var img = K(this);
  7924. var status = img.attr('data-status');
  7925. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7926. list.push(img.data('data'));
  7927. }
  7928. });
  7929. return list;
  7930. },
  7931. removeFile : function(fileId) {
  7932. var self = this;
  7933. self.swfu.cancelUpload(fileId);
  7934. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7935. K('.ke-photo', itemDiv).unbind();
  7936. K('.ke-delete', itemDiv).unbind();
  7937. itemDiv.remove();
  7938. },
  7939. removeFiles : function() {
  7940. var self = this;
  7941. K('.ke-item', self.bodyDiv).each(function() {
  7942. self.removeFile(K(this).attr('data-id'));
  7943. });
  7944. },
  7945. appendFile : function(file) {
  7946. var self = this;
  7947. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7948. self.bodyDiv.append(itemDiv);
  7949. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7950. .mouseover(function(e) {
  7951. K(this).addClass('ke-on');
  7952. })
  7953. .mouseout(function(e) {
  7954. K(this).removeClass('ke-on');
  7955. });
  7956. itemDiv.append(photoDiv);
  7957. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7958. photoDiv.append(img);
  7959. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  7960. self.removeFile(file.id);
  7961. });
  7962. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7963. K(['<div class="ke-progressbar">',
  7964. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7965. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7966. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7967. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7968. self.progressbars[file.id] = {
  7969. bar : K('.ke-progressbar-bar-inner', photoDiv),
  7970. percent : K('.ke-progressbar-percent', photoDiv)
  7971. };
  7972. },
  7973. remove : function() {
  7974. this.removeFiles();
  7975. this.swfu.destroy();
  7976. this.div.html('');
  7977. }
  7978. });
  7979. K.swfupload = function(element, options) {
  7980. return new KSWFUpload(element, options);
  7981. };
  7982. })(KindEditor);
  7983. KindEditor.plugin('multiimage', function(K) {
  7984. var self = this, name = 'multiimage',
  7985. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7986. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7987. imgPath = self.pluginsPath + 'multiimage/images/',
  7988. imageSizeLimit = K.undef(self.imageSizeLimit, '5MB'),
  7989. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  7990. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  7991. filePostName = K.undef(self.filePostName, 'imgFile'),
  7992. lang = self.lang(name + '.');
  7993. self.plugin.multiImageDialog = function(options) {
  7994. var clickFn = options.clickFn,
  7995. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  7996. var html = [
  7997. '<div style="padding:20px;">',
  7998. '<div class="swfupload">',
  7999. '</div>',
  8000. '</div>'
  8001. ].join('');
  8002. var dialog = self.createDialog({
  8003. name : name,
  8004. width : 650,
  8005. height : 510,
  8006. title : self.lang(name),
  8007. body : html,
  8008. previewBtn : {
  8009. name : lang.insertAll,
  8010. click : function(e) {
  8011. clickFn.call(self, swfupload.getUrlList());
  8012. }
  8013. },
  8014. yesBtn : {
  8015. name : lang.clearAll,
  8016. click : function(e) {
  8017. swfupload.removeFiles();
  8018. }
  8019. },
  8020. beforeRemove : function() {
  8021. if (!K.IE || K.V <= 8) {
  8022. swfupload.remove();
  8023. }
  8024. }
  8025. }),
  8026. div = dialog.div;
  8027. var swfupload = K.swfupload({
  8028. container : K('.swfupload', div),
  8029. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8030. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8031. buttonHeight : 23,
  8032. fileIconUrl : imgPath + 'image.png',
  8033. uploadDesc : uploadDesc,
  8034. startButtonValue : lang.startUpload,
  8035. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8036. flashUrl : imgPath + 'swfupload.swf',
  8037. filePostName : filePostName,
  8038. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8039. fileTypesDesc : 'Image Files',
  8040. fileUploadLimit : imageUploadLimit,
  8041. fileSizeLimit : imageSizeLimit,
  8042. postParams : K.undef(self.extraFileUploadParams, {}),
  8043. queueLimitExceeded : lang.queueLimitExceeded,
  8044. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8045. zeroByteFile : lang.zeroByteFile,
  8046. invalidFiletype : lang.invalidFiletype,
  8047. unknownError : lang.unknownError,
  8048. pendingMessage : lang.pending,
  8049. errorMessage : lang.uploadError,
  8050. afterError : function(html) {
  8051. self.errorDialog(html);
  8052. }
  8053. });
  8054. return dialog;
  8055. };
  8056. self.clickToolbar(name, function() {
  8057. self.plugin.multiImageDialog({
  8058. clickFn : function (urlList) {
  8059. if (urlList.length === 0) {
  8060. return;
  8061. }
  8062. K.each(urlList, function(i, data) {
  8063. if (self.afterUpload) {
  8064. self.afterUpload.call(self, data.url, data, 'multiimage');
  8065. }
  8066. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8067. });
  8068. setTimeout(function() {
  8069. self.hideDialog().focus();
  8070. }, 0);
  8071. }
  8072. });
  8073. });
  8074. });
  8075. /* ******************* */
  8076. /* Constructor & Init */
  8077. /* ******************* */
  8078. (function() {
  8079. window.SWFUpload = function (settings) {
  8080. this.initSWFUpload(settings);
  8081. };
  8082. SWFUpload.prototype.initSWFUpload = function (settings) {
  8083. try {
  8084. this.customSettings = {};
  8085. this.settings = settings;
  8086. this.eventQueue = [];
  8087. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8088. this.movieElement = null;
  8089. SWFUpload.instances[this.movieName] = this;
  8090. this.initSettings();
  8091. this.loadFlash();
  8092. this.displayDebugInfo();
  8093. } catch (ex) {
  8094. delete SWFUpload.instances[this.movieName];
  8095. throw ex;
  8096. }
  8097. };
  8098. /* *************** */
  8099. /* Static Members */
  8100. /* *************** */
  8101. SWFUpload.instances = {};
  8102. SWFUpload.movieCount = 0;
  8103. SWFUpload.version = "2.2.0 2009-03-25";
  8104. SWFUpload.QUEUE_ERROR = {
  8105. QUEUE_LIMIT_EXCEEDED : -100,
  8106. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8107. ZERO_BYTE_FILE : -120,
  8108. INVALID_FILETYPE : -130
  8109. };
  8110. SWFUpload.UPLOAD_ERROR = {
  8111. HTTP_ERROR : -200,
  8112. MISSING_UPLOAD_URL : -210,
  8113. IO_ERROR : -220,
  8114. SECURITY_ERROR : -230,
  8115. UPLOAD_LIMIT_EXCEEDED : -240,
  8116. UPLOAD_FAILED : -250,
  8117. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8118. FILE_VALIDATION_FAILED : -270,
  8119. FILE_CANCELLED : -280,
  8120. UPLOAD_STOPPED : -290
  8121. };
  8122. SWFUpload.FILE_STATUS = {
  8123. QUEUED : -1,
  8124. IN_PROGRESS : -2,
  8125. ERROR : -3,
  8126. COMPLETE : -4,
  8127. CANCELLED : -5
  8128. };
  8129. SWFUpload.BUTTON_ACTION = {
  8130. SELECT_FILE : -100,
  8131. SELECT_FILES : -110,
  8132. START_UPLOAD : -120
  8133. };
  8134. SWFUpload.CURSOR = {
  8135. ARROW : -1,
  8136. HAND : -2
  8137. };
  8138. SWFUpload.WINDOW_MODE = {
  8139. WINDOW : "window",
  8140. TRANSPARENT : "transparent",
  8141. OPAQUE : "opaque"
  8142. };
  8143. SWFUpload.completeURL = function(url) {
  8144. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8145. return url;
  8146. }
  8147. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8148. var indexSlash = window.location.pathname.lastIndexOf("/");
  8149. var path;
  8150. if (indexSlash <= 0) {
  8151. path = "/";
  8152. } else {
  8153. path = window.location.pathname.substr(0, indexSlash) + "/";
  8154. }
  8155. return /*currentURL +*/ path + url;
  8156. };
  8157. /* ******************** */
  8158. /* Instance Members */
  8159. /* ******************** */
  8160. SWFUpload.prototype.initSettings = function () {
  8161. this.ensureDefault = function (settingName, defaultValue) {
  8162. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8163. };
  8164. this.ensureDefault("upload_url", "");
  8165. this.ensureDefault("preserve_relative_urls", false);
  8166. this.ensureDefault("file_post_name", "Filedata");
  8167. this.ensureDefault("post_params", {});
  8168. this.ensureDefault("use_query_string", false);
  8169. this.ensureDefault("requeue_on_error", false);
  8170. this.ensureDefault("http_success", []);
  8171. this.ensureDefault("assume_success_timeout", 0);
  8172. this.ensureDefault("file_types", "*.*");
  8173. this.ensureDefault("file_types_description", "All Files");
  8174. this.ensureDefault("file_size_limit", 0);
  8175. this.ensureDefault("file_upload_limit", 0);
  8176. this.ensureDefault("file_queue_limit", 0);
  8177. this.ensureDefault("flash_url", "swfupload.swf");
  8178. this.ensureDefault("prevent_swf_caching", true);
  8179. this.ensureDefault("button_image_url", "");
  8180. this.ensureDefault("button_width", 1);
  8181. this.ensureDefault("button_height", 1);
  8182. this.ensureDefault("button_text", "");
  8183. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8184. this.ensureDefault("button_text_top_padding", 0);
  8185. this.ensureDefault("button_text_left_padding", 0);
  8186. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8187. this.ensureDefault("button_disabled", false);
  8188. this.ensureDefault("button_placeholder_id", "");
  8189. this.ensureDefault("button_placeholder", null);
  8190. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8191. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8192. this.ensureDefault("debug", false);
  8193. this.settings.debug_enabled = this.settings.debug;
  8194. this.settings.return_upload_start_handler = this.returnUploadStart;
  8195. this.ensureDefault("swfupload_loaded_handler", null);
  8196. this.ensureDefault("file_dialog_start_handler", null);
  8197. this.ensureDefault("file_queued_handler", null);
  8198. this.ensureDefault("file_queue_error_handler", null);
  8199. this.ensureDefault("file_dialog_complete_handler", null);
  8200. this.ensureDefault("upload_start_handler", null);
  8201. this.ensureDefault("upload_progress_handler", null);
  8202. this.ensureDefault("upload_error_handler", null);
  8203. this.ensureDefault("upload_success_handler", null);
  8204. this.ensureDefault("upload_complete_handler", null);
  8205. this.ensureDefault("debug_handler", this.debugMessage);
  8206. this.ensureDefault("custom_settings", {});
  8207. this.customSettings = this.settings.custom_settings;
  8208. if (!!this.settings.prevent_swf_caching) {
  8209. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8210. }
  8211. if (!this.settings.preserve_relative_urls) {
  8212. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8213. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8214. }
  8215. delete this.ensureDefault;
  8216. };
  8217. SWFUpload.prototype.loadFlash = function () {
  8218. var targetElement, tempParent;
  8219. if (document.getElementById(this.movieName) !== null) {
  8220. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8221. }
  8222. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8223. if (targetElement == undefined) {
  8224. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8225. }
  8226. tempParent = document.createElement("div");
  8227. tempParent.innerHTML = this.getFlashHTML();
  8228. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8229. if (window[this.movieName] == undefined) {
  8230. window[this.movieName] = this.getMovieElement();
  8231. }
  8232. };
  8233. SWFUpload.prototype.getFlashHTML = function () {
  8234. var classid = '';
  8235. if (KindEditor.IE && KindEditor.V > 8) {
  8236. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8237. }
  8238. 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">',
  8239. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8240. '<param name="movie" value="', this.settings.flash_url, '" />',
  8241. '<param name="quality" value="high" />',
  8242. '<param name="menu" value="false" />',
  8243. '<param name="allowScriptAccess" value="always" />',
  8244. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8245. '</object>'].join("");
  8246. };
  8247. SWFUpload.prototype.getFlashVars = function () {
  8248. var paramString = this.buildParamString();
  8249. var httpSuccessString = this.settings.http_success.join(",");
  8250. return ["movieName=", encodeURIComponent(this.movieName),
  8251. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8252. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8253. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8254. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8255. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8256. "&amp;params=", encodeURIComponent(paramString),
  8257. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8258. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8259. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8260. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8261. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8262. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8263. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8264. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8265. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8266. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8267. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8268. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8269. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8270. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8271. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8272. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8273. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8274. ].join("");
  8275. };
  8276. SWFUpload.prototype.getMovieElement = function () {
  8277. if (this.movieElement == undefined) {
  8278. this.movieElement = document.getElementById(this.movieName);
  8279. }
  8280. if (this.movieElement === null) {
  8281. throw "Could not find Flash element";
  8282. }
  8283. return this.movieElement;
  8284. };
  8285. SWFUpload.prototype.buildParamString = function () {
  8286. var postParams = this.settings.post_params;
  8287. var paramStringPairs = [];
  8288. if (typeof(postParams) === "object") {
  8289. for (var name in postParams) {
  8290. if (postParams.hasOwnProperty(name)) {
  8291. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8292. }
  8293. }
  8294. }
  8295. return paramStringPairs.join("&amp;");
  8296. };
  8297. SWFUpload.prototype.destroy = function () {
  8298. try {
  8299. this.cancelUpload(null, false);
  8300. var movieElement = null;
  8301. movieElement = this.getMovieElement();
  8302. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8303. for (var i in movieElement) {
  8304. try {
  8305. if (typeof(movieElement[i]) === "function") {
  8306. movieElement[i] = null;
  8307. }
  8308. } catch (ex1) {}
  8309. }
  8310. try {
  8311. movieElement.parentNode.removeChild(movieElement);
  8312. } catch (ex) {}
  8313. }
  8314. window[this.movieName] = null;
  8315. SWFUpload.instances[this.movieName] = null;
  8316. delete SWFUpload.instances[this.movieName];
  8317. this.movieElement = null;
  8318. this.settings = null;
  8319. this.customSettings = null;
  8320. this.eventQueue = null;
  8321. this.movieName = null;
  8322. return true;
  8323. } catch (ex2) {
  8324. return false;
  8325. }
  8326. };
  8327. SWFUpload.prototype.displayDebugInfo = function () {
  8328. this.debug(
  8329. [
  8330. "---SWFUpload Instance Info---\n",
  8331. "Version: ", SWFUpload.version, "\n",
  8332. "Movie Name: ", this.movieName, "\n",
  8333. "Settings:\n",
  8334. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8335. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8336. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8337. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8338. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8339. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8340. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8341. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8342. "\t", "file_types: ", this.settings.file_types, "\n",
  8343. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8344. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8345. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8346. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8347. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8348. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8349. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8350. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8351. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8352. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8353. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8354. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8355. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8356. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8357. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8358. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8359. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8360. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8361. "Event Handlers:\n",
  8362. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8363. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8364. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8365. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8366. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8367. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8368. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8369. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8370. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8371. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8372. ].join("")
  8373. );
  8374. };
  8375. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8376. the maintain v2 API compatibility
  8377. */
  8378. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8379. if (value == undefined) {
  8380. return (this.settings[name] = default_value);
  8381. } else {
  8382. return (this.settings[name] = value);
  8383. }
  8384. };
  8385. SWFUpload.prototype.getSetting = function (name) {
  8386. if (this.settings[name] != undefined) {
  8387. return this.settings[name];
  8388. }
  8389. return "";
  8390. };
  8391. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8392. argumentArray = argumentArray || [];
  8393. var movieElement = this.getMovieElement();
  8394. var returnValue, returnString;
  8395. try {
  8396. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8397. returnValue = eval(returnString);
  8398. } catch (ex) {
  8399. throw "Call to " + functionName + " failed";
  8400. }
  8401. if (returnValue != undefined && typeof returnValue.post === "object") {
  8402. returnValue = this.unescapeFilePostParams(returnValue);
  8403. }
  8404. return returnValue;
  8405. };
  8406. /* *****************************
  8407. -- Flash control methods --
  8408. Your UI should use these
  8409. to operate SWFUpload
  8410. ***************************** */
  8411. SWFUpload.prototype.selectFile = function () {
  8412. this.callFlash("SelectFile");
  8413. };
  8414. SWFUpload.prototype.selectFiles = function () {
  8415. this.callFlash("SelectFiles");
  8416. };
  8417. SWFUpload.prototype.startUpload = function (fileID) {
  8418. this.callFlash("StartUpload", [fileID]);
  8419. };
  8420. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8421. if (triggerErrorEvent !== false) {
  8422. triggerErrorEvent = true;
  8423. }
  8424. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8425. };
  8426. SWFUpload.prototype.stopUpload = function () {
  8427. this.callFlash("StopUpload");
  8428. };
  8429. /* ************************
  8430. * Settings methods
  8431. * These methods change the SWFUpload settings.
  8432. * SWFUpload settings should not be changed directly on the settings object
  8433. * since many of the settings need to be passed to Flash in order to take
  8434. * effect.
  8435. * *********************** */
  8436. SWFUpload.prototype.getStats = function () {
  8437. return this.callFlash("GetStats");
  8438. };
  8439. SWFUpload.prototype.setStats = function (statsObject) {
  8440. this.callFlash("SetStats", [statsObject]);
  8441. };
  8442. SWFUpload.prototype.getFile = function (fileID) {
  8443. if (typeof(fileID) === "number") {
  8444. return this.callFlash("GetFileByIndex", [fileID]);
  8445. } else {
  8446. return this.callFlash("GetFile", [fileID]);
  8447. }
  8448. };
  8449. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8450. return this.callFlash("AddFileParam", [fileID, name, value]);
  8451. };
  8452. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8453. this.callFlash("RemoveFileParam", [fileID, name]);
  8454. };
  8455. SWFUpload.prototype.setUploadURL = function (url) {
  8456. this.settings.upload_url = url.toString();
  8457. this.callFlash("SetUploadURL", [url]);
  8458. };
  8459. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8460. this.settings.post_params = paramsObject;
  8461. this.callFlash("SetPostParams", [paramsObject]);
  8462. };
  8463. SWFUpload.prototype.addPostParam = function (name, value) {
  8464. this.settings.post_params[name] = value;
  8465. this.callFlash("SetPostParams", [this.settings.post_params]);
  8466. };
  8467. SWFUpload.prototype.removePostParam = function (name) {
  8468. delete this.settings.post_params[name];
  8469. this.callFlash("SetPostParams", [this.settings.post_params]);
  8470. };
  8471. SWFUpload.prototype.setFileTypes = function (types, description) {
  8472. this.settings.file_types = types;
  8473. this.settings.file_types_description = description;
  8474. this.callFlash("SetFileTypes", [types, description]);
  8475. };
  8476. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8477. this.settings.file_size_limit = fileSizeLimit;
  8478. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8479. };
  8480. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8481. this.settings.file_upload_limit = fileUploadLimit;
  8482. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8483. };
  8484. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8485. this.settings.file_queue_limit = fileQueueLimit;
  8486. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8487. };
  8488. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8489. this.settings.file_post_name = filePostName;
  8490. this.callFlash("SetFilePostName", [filePostName]);
  8491. };
  8492. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8493. this.settings.use_query_string = useQueryString;
  8494. this.callFlash("SetUseQueryString", [useQueryString]);
  8495. };
  8496. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8497. this.settings.requeue_on_error = requeueOnError;
  8498. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8499. };
  8500. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8501. if (typeof http_status_codes === "string") {
  8502. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8503. }
  8504. this.settings.http_success = http_status_codes;
  8505. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8506. };
  8507. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8508. this.settings.assume_success_timeout = timeout_seconds;
  8509. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8510. };
  8511. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8512. this.settings.debug_enabled = debugEnabled;
  8513. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8514. };
  8515. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8516. if (buttonImageURL == undefined) {
  8517. buttonImageURL = "";
  8518. }
  8519. this.settings.button_image_url = buttonImageURL;
  8520. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8521. };
  8522. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8523. this.settings.button_width = width;
  8524. this.settings.button_height = height;
  8525. var movie = this.getMovieElement();
  8526. if (movie != undefined) {
  8527. movie.style.width = width + "px";
  8528. movie.style.height = height + "px";
  8529. }
  8530. this.callFlash("SetButtonDimensions", [width, height]);
  8531. };
  8532. SWFUpload.prototype.setButtonText = function (html) {
  8533. this.settings.button_text = html;
  8534. this.callFlash("SetButtonText", [html]);
  8535. };
  8536. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8537. this.settings.button_text_top_padding = top;
  8538. this.settings.button_text_left_padding = left;
  8539. this.callFlash("SetButtonTextPadding", [left, top]);
  8540. };
  8541. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8542. this.settings.button_text_style = css;
  8543. this.callFlash("SetButtonTextStyle", [css]);
  8544. };
  8545. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8546. this.settings.button_disabled = isDisabled;
  8547. this.callFlash("SetButtonDisabled", [isDisabled]);
  8548. };
  8549. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8550. this.settings.button_action = buttonAction;
  8551. this.callFlash("SetButtonAction", [buttonAction]);
  8552. };
  8553. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8554. this.settings.button_cursor = cursor;
  8555. this.callFlash("SetButtonCursor", [cursor]);
  8556. };
  8557. /* *******************************
  8558. Flash Event Interfaces
  8559. These functions are used by Flash to trigger the various
  8560. events.
  8561. All these functions a Private.
  8562. Because the ExternalInterface library is buggy the event calls
  8563. are added to a queue and the queue then executed by a setTimeout.
  8564. This ensures that events are executed in a determinate order and that
  8565. the ExternalInterface bugs are avoided.
  8566. ******************************* */
  8567. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8568. if (argumentArray == undefined) {
  8569. argumentArray = [];
  8570. } else if (!(argumentArray instanceof Array)) {
  8571. argumentArray = [argumentArray];
  8572. }
  8573. var self = this;
  8574. if (typeof this.settings[handlerName] === "function") {
  8575. this.eventQueue.push(function () {
  8576. this.settings[handlerName].apply(this, argumentArray);
  8577. });
  8578. setTimeout(function () {
  8579. self.executeNextEvent();
  8580. }, 0);
  8581. } else if (this.settings[handlerName] !== null) {
  8582. throw "Event handler " + handlerName + " is unknown or is not a function";
  8583. }
  8584. };
  8585. SWFUpload.prototype.executeNextEvent = function () {
  8586. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8587. if (typeof(f) === "function") {
  8588. f.apply(this);
  8589. }
  8590. };
  8591. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8592. var reg = /[$]([0-9a-f]{4})/i;
  8593. var unescapedPost = {};
  8594. var uk;
  8595. if (file != undefined) {
  8596. for (var k in file.post) {
  8597. if (file.post.hasOwnProperty(k)) {
  8598. uk = k;
  8599. var match;
  8600. while ((match = reg.exec(uk)) !== null) {
  8601. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8602. }
  8603. unescapedPost[uk] = file.post[k];
  8604. }
  8605. }
  8606. file.post = unescapedPost;
  8607. }
  8608. return file;
  8609. };
  8610. SWFUpload.prototype.testExternalInterface = function () {
  8611. try {
  8612. return this.callFlash("TestExternalInterface");
  8613. } catch (ex) {
  8614. return false;
  8615. }
  8616. };
  8617. SWFUpload.prototype.flashReady = function () {
  8618. var movieElement = this.getMovieElement();
  8619. if (!movieElement) {
  8620. this.debug("Flash called back ready but the flash movie can't be found.");
  8621. return;
  8622. }
  8623. this.cleanUp(movieElement);
  8624. this.queueEvent("swfupload_loaded_handler");
  8625. };
  8626. SWFUpload.prototype.cleanUp = function (movieElement) {
  8627. try {
  8628. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8629. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8630. for (var key in movieElement) {
  8631. try {
  8632. if (typeof(movieElement[key]) === "function") {
  8633. movieElement[key] = null;
  8634. }
  8635. } catch (ex) {
  8636. }
  8637. }
  8638. }
  8639. } catch (ex1) {
  8640. }
  8641. window["__flash__removeCallback"] = function (instance, name) {
  8642. try {
  8643. if (instance) {
  8644. instance[name] = null;
  8645. }
  8646. } catch (flashEx) {
  8647. }
  8648. };
  8649. };
  8650. /* This is a chance to do something before the browse window opens */
  8651. SWFUpload.prototype.fileDialogStart = function () {
  8652. this.queueEvent("file_dialog_start_handler");
  8653. };
  8654. /* Called when a file is successfully added to the queue. */
  8655. SWFUpload.prototype.fileQueued = function (file) {
  8656. file = this.unescapeFilePostParams(file);
  8657. this.queueEvent("file_queued_handler", file);
  8658. };
  8659. /* Handle errors that occur when an attempt to queue a file fails. */
  8660. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8661. file = this.unescapeFilePostParams(file);
  8662. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8663. };
  8664. /* Called after the file dialog has closed and the selected files have been queued.
  8665. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8666. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8667. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8668. };
  8669. SWFUpload.prototype.uploadStart = function (file) {
  8670. file = this.unescapeFilePostParams(file);
  8671. this.queueEvent("return_upload_start_handler", file);
  8672. };
  8673. SWFUpload.prototype.returnUploadStart = function (file) {
  8674. var returnValue;
  8675. if (typeof this.settings.upload_start_handler === "function") {
  8676. file = this.unescapeFilePostParams(file);
  8677. returnValue = this.settings.upload_start_handler.call(this, file);
  8678. } else if (this.settings.upload_start_handler != undefined) {
  8679. throw "upload_start_handler must be a function";
  8680. }
  8681. if (returnValue === undefined) {
  8682. returnValue = true;
  8683. }
  8684. returnValue = !!returnValue;
  8685. this.callFlash("ReturnUploadStart", [returnValue]);
  8686. };
  8687. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8688. file = this.unescapeFilePostParams(file);
  8689. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8690. };
  8691. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8692. file = this.unescapeFilePostParams(file);
  8693. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8694. };
  8695. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8696. file = this.unescapeFilePostParams(file);
  8697. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8698. };
  8699. SWFUpload.prototype.uploadComplete = function (file) {
  8700. file = this.unescapeFilePostParams(file);
  8701. this.queueEvent("upload_complete_handler", file);
  8702. };
  8703. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8704. internal debug console. You can override this event and have messages written where you want. */
  8705. SWFUpload.prototype.debug = function (message) {
  8706. this.queueEvent("debug_handler", message);
  8707. };
  8708. /* **********************************
  8709. Debug Console
  8710. The debug console is a self contained, in page location
  8711. for debug message to be sent. The Debug Console adds
  8712. itself to the body if necessary.
  8713. The console is automatically scrolled as messages appear.
  8714. If you are using your own debug handler or when you deploy to production and
  8715. have debug disabled you can remove these functions to reduce the file size
  8716. and complexity.
  8717. ********************************** */
  8718. SWFUpload.prototype.debugMessage = function (message) {
  8719. if (this.settings.debug) {
  8720. var exceptionMessage, exceptionValues = [];
  8721. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8722. for (var key in message) {
  8723. if (message.hasOwnProperty(key)) {
  8724. exceptionValues.push(key + ": " + message[key]);
  8725. }
  8726. }
  8727. exceptionMessage = exceptionValues.join("\n") || "";
  8728. exceptionValues = exceptionMessage.split("\n");
  8729. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8730. SWFUpload.Console.writeLine(exceptionMessage);
  8731. } else {
  8732. SWFUpload.Console.writeLine(message);
  8733. }
  8734. }
  8735. };
  8736. SWFUpload.Console = {};
  8737. SWFUpload.Console.writeLine = function (message) {
  8738. var console, documentForm;
  8739. try {
  8740. console = document.getElementById("SWFUpload_Console");
  8741. if (!console) {
  8742. documentForm = document.createElement("form");
  8743. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8744. console = document.createElement("textarea");
  8745. console.id = "SWFUpload_Console";
  8746. console.style.fontFamily = "monospace";
  8747. console.setAttribute("wrap", "off");
  8748. console.wrap = "off";
  8749. console.style.overflow = "auto";
  8750. console.style.width = "700px";
  8751. console.style.height = "350px";
  8752. console.style.margin = "5px";
  8753. documentForm.appendChild(console);
  8754. }
  8755. console.value += message + "\n";
  8756. console.scrollTop = console.scrollHeight - console.clientHeight;
  8757. } catch (ex) {
  8758. alert("Exception: " + ex.name + " Message: " + ex.message);
  8759. }
  8760. };
  8761. })();
  8762. (function() {
  8763. /*
  8764. Queue Plug-in
  8765. Features:
  8766. *Adds a cancelQueue() method for cancelling the entire queue.
  8767. *All queued files are uploaded when startUpload() is called.
  8768. *If false is returned from uploadComplete then the queue upload is stopped.
  8769. If false is not returned (strict comparison) then the queue upload is continued.
  8770. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8771. Set the event handler with the queue_complete_handler setting.
  8772. */
  8773. if (typeof(SWFUpload) === "function") {
  8774. SWFUpload.queue = {};
  8775. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8776. return function () {
  8777. if (typeof(oldInitSettings) === "function") {
  8778. oldInitSettings.call(this);
  8779. }
  8780. this.queueSettings = {};
  8781. this.queueSettings.queue_cancelled_flag = false;
  8782. this.queueSettings.queue_upload_count = 0;
  8783. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8784. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8785. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8786. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8787. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8788. };
  8789. })(SWFUpload.prototype.initSettings);
  8790. SWFUpload.prototype.startUpload = function (fileID) {
  8791. this.queueSettings.queue_cancelled_flag = false;
  8792. this.callFlash("StartUpload", [fileID]);
  8793. };
  8794. SWFUpload.prototype.cancelQueue = function () {
  8795. this.queueSettings.queue_cancelled_flag = true;
  8796. this.stopUpload();
  8797. var stats = this.getStats();
  8798. while (stats.files_queued > 0) {
  8799. this.cancelUpload();
  8800. stats = this.getStats();
  8801. }
  8802. };
  8803. SWFUpload.queue.uploadStartHandler = function (file) {
  8804. var returnValue;
  8805. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8806. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8807. }
  8808. returnValue = (returnValue === false) ? false : true;
  8809. this.queueSettings.queue_cancelled_flag = !returnValue;
  8810. return returnValue;
  8811. };
  8812. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8813. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8814. var continueUpload;
  8815. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8816. this.queueSettings.queue_upload_count++;
  8817. }
  8818. if (typeof(user_upload_complete_handler) === "function") {
  8819. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8820. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8821. continueUpload = false;
  8822. } else {
  8823. continueUpload = true;
  8824. }
  8825. if (continueUpload) {
  8826. var stats = this.getStats();
  8827. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8828. this.startUpload();
  8829. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8830. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8831. this.queueSettings.queue_upload_count = 0;
  8832. } else {
  8833. this.queueSettings.queue_cancelled_flag = false;
  8834. this.queueSettings.queue_upload_count = 0;
  8835. }
  8836. }
  8837. };
  8838. }
  8839. })();
  8840. /*******************************************************************************
  8841. * KindEditor - WYSIWYG HTML Editor for Internet
  8842. * Copyright (C) 2006-2011 kindsoft.net
  8843. *
  8844. * @author Roddy <luolonghao@gmail.com>
  8845. * @site http://www.kindsoft.net/
  8846. * @licence http://www.kindsoft.net/license.php
  8847. *******************************************************************************/
  8848. KindEditor.plugin('pagebreak', function(K) {
  8849. var self = this;
  8850. var name = 'pagebreak';
  8851. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8852. self.clickToolbar(name, function() {
  8853. var cmd = self.cmd, range = cmd.range;
  8854. self.focus();
  8855. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8856. self.insertHtml(pagebreakHtml + tail);
  8857. if (tail !== '') {
  8858. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8859. range.selectNodeContents(p[0]);
  8860. p.removeAttr('id');
  8861. cmd.select();
  8862. }
  8863. });
  8864. });
  8865. /*******************************************************************************
  8866. * KindEditor - WYSIWYG HTML Editor for Internet
  8867. * Copyright (C) 2006-2011 kindsoft.net
  8868. *
  8869. * @author Roddy <luolonghao@gmail.com>
  8870. * @site http://www.kindsoft.net/
  8871. * @licence http://www.kindsoft.net/license.php
  8872. *******************************************************************************/
  8873. KindEditor.plugin('plainpaste', function(K) {
  8874. var self = this, name = 'plainpaste';
  8875. self.clickToolbar(name, function() {
  8876. var lang = self.lang(name + '.'),
  8877. html = '<div style="padding:10px 20px;">' +
  8878. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  8879. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  8880. '</div>',
  8881. dialog = self.createDialog({
  8882. name : name,
  8883. width : 450,
  8884. title : self.lang(name),
  8885. body : html,
  8886. yesBtn : {
  8887. name : self.lang('yes'),
  8888. click : function(e) {
  8889. var html = textarea.val();
  8890. html = K.escape(html);
  8891. html = html.replace(/ {2}/g, ' &nbsp;');
  8892. if (self.newlineTag == 'p') {
  8893. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  8894. } else {
  8895. html = html.replace(/\n/g, '<br />$&');
  8896. }
  8897. self.insertHtml(html).hideDialog().focus();
  8898. }
  8899. }
  8900. }),
  8901. textarea = K('textarea', dialog.div);
  8902. textarea[0].focus();
  8903. });
  8904. });
  8905. /*******************************************************************************
  8906. * KindEditor - WYSIWYG HTML Editor for Internet
  8907. * Copyright (C) 2006-2011 kindsoft.net
  8908. *
  8909. * @author Roddy <luolonghao@gmail.com>
  8910. * @site http://www.kindsoft.net/
  8911. * @licence http://www.kindsoft.net/license.php
  8912. *******************************************************************************/
  8913. KindEditor.plugin('preview', function(K) {
  8914. var self = this, name = 'preview', undefined;
  8915. self.clickToolbar(name, function() {
  8916. var lang = self.lang(name + '.'),
  8917. html = '<div style="padding:10px 20px;">' +
  8918. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  8919. '</div>',
  8920. dialog = self.createDialog({
  8921. name : name,
  8922. width : 750,
  8923. title : self.lang(name),
  8924. body : html
  8925. }),
  8926. iframe = K('iframe', dialog.div),
  8927. doc = K.iframeDoc(iframe);
  8928. doc.open();
  8929. doc.write(self.fullHtml());
  8930. doc.close();
  8931. K(doc.body).css('background-color', '#FFF');
  8932. iframe[0].contentWindow.focus();
  8933. });
  8934. });
  8935. /*******************************************************************************
  8936. * KindEditor - WYSIWYG HTML Editor for Internet
  8937. * Copyright (C) 2006-2011 kindsoft.net
  8938. *
  8939. * @author Roddy <luolonghao@gmail.com>
  8940. * @site http://www.kindsoft.net/
  8941. * @licence http://www.kindsoft.net/license.php
  8942. *******************************************************************************/
  8943. KindEditor.plugin('quickformat', function(K) {
  8944. var self = this, name = 'quickformat',
  8945. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  8946. function getFirstChild(knode) {
  8947. var child = knode.first();
  8948. while (child && child.first()) {
  8949. child = child.first();
  8950. }
  8951. return child;
  8952. }
  8953. self.clickToolbar(name, function() {
  8954. self.focus();
  8955. var doc = self.edit.doc,
  8956. range = self.cmd.range,
  8957. child = K(doc.body).first(), next,
  8958. nodeList = [], subList = [],
  8959. bookmark = range.createBookmark(true);
  8960. while(child) {
  8961. next = child.next();
  8962. var firstChild = getFirstChild(child);
  8963. if (!firstChild || firstChild.name != 'img') {
  8964. if (blockMap[child.name]) {
  8965. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  8966. child.css('text-indent', '2em');
  8967. } else {
  8968. subList.push(child);
  8969. }
  8970. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  8971. if (subList.length > 0) {
  8972. nodeList.push(subList);
  8973. }
  8974. subList = [];
  8975. }
  8976. }
  8977. child = next;
  8978. }
  8979. K.each(nodeList, function(i, subList) {
  8980. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  8981. subList[0].before(wrapper);
  8982. K.each(subList, function(i, knode) {
  8983. wrapper.append(knode);
  8984. });
  8985. });
  8986. range.moveToBookmark(bookmark);
  8987. self.addBookmark();
  8988. });
  8989. });
  8990. /*******************************************************************************
  8991. * KindEditor - WYSIWYG HTML Editor for Internet
  8992. * Copyright (C) 2006-2011 kindsoft.net
  8993. *
  8994. * @author Roddy <luolonghao@gmail.com>
  8995. * @site http://www.kindsoft.net/
  8996. * @licence http://www.kindsoft.net/license.php
  8997. *******************************************************************************/
  8998. KindEditor.plugin('table', function(K) {
  8999. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9000. function _setColor(box, color) {
  9001. color = color.toUpperCase();
  9002. box.css('background-color', color);
  9003. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9004. box.html(color);
  9005. }
  9006. var pickerList = [];
  9007. function _initColorPicker(dialogDiv, colorBox) {
  9008. colorBox.bind('click,mousedown', function(e){
  9009. e.stopPropagation();
  9010. });
  9011. function removePicker() {
  9012. K.each(pickerList, function() {
  9013. this.remove();
  9014. });
  9015. pickerList = [];
  9016. K(document).unbind('click,mousedown', removePicker);
  9017. dialogDiv.unbind('click,mousedown', removePicker);
  9018. }
  9019. colorBox.click(function(e) {
  9020. removePicker();
  9021. var box = K(this),
  9022. pos = box.pos();
  9023. var picker = K.colorpicker({
  9024. x : pos.x,
  9025. y : pos.y + box.height(),
  9026. z : 811214,
  9027. selectedColor : K(this).html(),
  9028. colors : self.colorTable,
  9029. noColor : self.lang('noColor'),
  9030. shadowMode : self.shadowMode,
  9031. click : function(color) {
  9032. _setColor(box, color);
  9033. removePicker();
  9034. }
  9035. });
  9036. pickerList.push(picker);
  9037. K(document).bind('click,mousedown', removePicker);
  9038. dialogDiv.bind('click,mousedown', removePicker);
  9039. });
  9040. }
  9041. function _getCellIndex(table, row, cell) {
  9042. var rowSpanCount = 0;
  9043. for (var i = 0, len = row.cells.length; i < len; i++) {
  9044. if (row.cells[i] == cell) {
  9045. break;
  9046. }
  9047. rowSpanCount += row.cells[i].rowSpan - 1;
  9048. }
  9049. return cell.cellIndex - rowSpanCount;
  9050. }
  9051. self.plugin.table = {
  9052. prop : function(isInsert) {
  9053. var html = [
  9054. '<div style="padding:20px;">',
  9055. '<div class="ke-dialog-row">',
  9056. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9057. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9058. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9059. '</div>',
  9060. '<div class="ke-dialog-row">',
  9061. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9062. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9063. '<select name="widthType">',
  9064. '<option value="%">' + lang.percent + '</option>',
  9065. '<option value="px">' + lang.px + '</option>',
  9066. '</select> &nbsp; ',
  9067. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9068. '<select name="heightType">',
  9069. '<option value="%">' + lang.percent + '</option>',
  9070. '<option value="px">' + lang.px + '</option>',
  9071. '</select>',
  9072. '</div>',
  9073. '<div class="ke-dialog-row">',
  9074. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9075. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9076. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9077. '</div>',
  9078. '<div class="ke-dialog-row">',
  9079. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9080. '<select id="keAlign" name="align">',
  9081. '<option value="">' + lang.alignDefault + '</option>',
  9082. '<option value="left">' + lang.alignLeft + '</option>',
  9083. '<option value="center">' + lang.alignCenter + '</option>',
  9084. '<option value="right">' + lang.alignRight + '</option>',
  9085. '</select>',
  9086. '</div>',
  9087. '<div class="ke-dialog-row">',
  9088. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9089. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9090. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9091. '</div>',
  9092. '<div class="ke-dialog-row">',
  9093. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9094. '<span class="ke-inline-block ke-input-color"></span>',
  9095. '</div>',
  9096. '</div>'
  9097. ].join('');
  9098. var bookmark = self.cmd.range.createBookmark();
  9099. var dialog = self.createDialog({
  9100. name : name,
  9101. width : 500,
  9102. title : self.lang(name),
  9103. body : html,
  9104. beforeRemove : function() {
  9105. colorBox.unbind();
  9106. },
  9107. yesBtn : {
  9108. name : self.lang('yes'),
  9109. click : function(e) {
  9110. var rows = rowsBox.val(),
  9111. cols = colsBox.val(),
  9112. width = widthBox.val(),
  9113. height = heightBox.val(),
  9114. widthType = widthTypeBox.val(),
  9115. heightType = heightTypeBox.val(),
  9116. padding = paddingBox.val(),
  9117. spacing = spacingBox.val(),
  9118. align = alignBox.val(),
  9119. border = borderBox.val(),
  9120. borderColor = K(colorBox[0]).html() || '',
  9121. bgColor = K(colorBox[1]).html() || '';
  9122. if (rows == 0 || !/^\d+$/.test(rows)) {
  9123. alert(self.lang('invalidRows'));
  9124. rowsBox[0].focus();
  9125. return;
  9126. }
  9127. if (cols == 0 || !/^\d+$/.test(cols)) {
  9128. alert(self.lang('invalidRows'));
  9129. colsBox[0].focus();
  9130. return;
  9131. }
  9132. if (!/^\d*$/.test(width)) {
  9133. alert(self.lang('invalidWidth'));
  9134. widthBox[0].focus();
  9135. return;
  9136. }
  9137. if (!/^\d*$/.test(height)) {
  9138. alert(self.lang('invalidHeight'));
  9139. heightBox[0].focus();
  9140. return;
  9141. }
  9142. if (!/^\d*$/.test(padding)) {
  9143. alert(self.lang('invalidPadding'));
  9144. paddingBox[0].focus();
  9145. return;
  9146. }
  9147. if (!/^\d*$/.test(spacing)) {
  9148. alert(self.lang('invalidSpacing'));
  9149. spacingBox[0].focus();
  9150. return;
  9151. }
  9152. if (!/^\d*$/.test(border)) {
  9153. alert(self.lang('invalidBorder'));
  9154. borderBox[0].focus();
  9155. return;
  9156. }
  9157. if (table) {
  9158. if (width !== '') {
  9159. table.width(width + widthType);
  9160. } else {
  9161. table.css('width', '');
  9162. }
  9163. if (table[0].width !== undefined) {
  9164. table.removeAttr('width');
  9165. }
  9166. if (height !== '') {
  9167. table.height(height + heightType);
  9168. } else {
  9169. table.css('height', '');
  9170. }
  9171. if (table[0].height !== undefined) {
  9172. table.removeAttr('height');
  9173. }
  9174. table.css('background-color', bgColor);
  9175. if (table[0].bgColor !== undefined) {
  9176. table.removeAttr('bgColor');
  9177. }
  9178. if (padding !== '') {
  9179. table[0].cellPadding = padding;
  9180. } else {
  9181. table.removeAttr('cellPadding');
  9182. }
  9183. if (spacing !== '') {
  9184. table[0].cellSpacing = spacing;
  9185. } else {
  9186. table.removeAttr('cellSpacing');
  9187. }
  9188. if (align !== '') {
  9189. table[0].align = align;
  9190. } else {
  9191. table.removeAttr('align');
  9192. }
  9193. if (border !== '') {
  9194. table.attr('border', border);
  9195. } else {
  9196. table.removeAttr('border');
  9197. }
  9198. if (border === '' || border === '0') {
  9199. table.addClass(zeroborder);
  9200. } else {
  9201. table.removeClass(zeroborder);
  9202. }
  9203. if (borderColor !== '') {
  9204. table.attr('borderColor', borderColor);
  9205. } else {
  9206. table.removeAttr('borderColor');
  9207. }
  9208. self.hideDialog().focus();
  9209. self.cmd.range.moveToBookmark(bookmark);
  9210. self.cmd.select();
  9211. self.addBookmark();
  9212. return;
  9213. }
  9214. var style = '';
  9215. if (width !== '') {
  9216. style += 'width:' + width + widthType + ';';
  9217. }
  9218. if (height !== '') {
  9219. style += 'height:' + height + heightType + ';';
  9220. }
  9221. if (bgColor !== '') {
  9222. style += 'background-color:' + bgColor + ';';
  9223. }
  9224. var html = '<table';
  9225. if (style !== '') {
  9226. html += ' style="' + style + '"';
  9227. }
  9228. if (padding !== '') {
  9229. html += ' cellpadding="' + padding + '"';
  9230. }
  9231. if (spacing !== '') {
  9232. html += ' cellspacing="' + spacing + '"';
  9233. }
  9234. if (align !== '') {
  9235. html += ' align="' + align + '"';
  9236. }
  9237. if (border !== '') {
  9238. html += ' border="' + border + '"';
  9239. }
  9240. if (border === '' || border === '0') {
  9241. html += ' class="' + zeroborder + '"';
  9242. }
  9243. if (borderColor !== '') {
  9244. html += ' bordercolor="' + borderColor + '"';
  9245. }
  9246. html += '>';
  9247. for (var i = 0; i < rows; i++) {
  9248. html += '<tr>';
  9249. for (var j = 0; j < cols; j++) {
  9250. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9251. }
  9252. html += '</tr>';
  9253. }
  9254. html += '</table>';
  9255. if (!K.IE) {
  9256. html += '<br />';
  9257. }
  9258. self.insertHtml(html);
  9259. self.select().hideDialog().focus();
  9260. self.addBookmark();
  9261. }
  9262. }
  9263. }),
  9264. div = dialog.div,
  9265. rowsBox = K('[name="rows"]', div).val(3),
  9266. colsBox = K('[name="cols"]', div).val(2),
  9267. widthBox = K('[name="width"]', div).val(100),
  9268. heightBox = K('[name="height"]', div),
  9269. widthTypeBox = K('[name="widthType"]', div),
  9270. heightTypeBox = K('[name="heightType"]', div),
  9271. paddingBox = K('[name="padding"]', div).val(2),
  9272. spacingBox = K('[name="spacing"]', div).val(0),
  9273. alignBox = K('[name="align"]', div),
  9274. borderBox = K('[name="border"]', div).val(1),
  9275. colorBox = K('.ke-input-color', div);
  9276. _initColorPicker(div, colorBox.eq(0));
  9277. _initColorPicker(div, colorBox.eq(1));
  9278. _setColor(colorBox.eq(0), '#000000');
  9279. _setColor(colorBox.eq(1), '');
  9280. rowsBox[0].focus();
  9281. rowsBox[0].select();
  9282. var table;
  9283. if (isInsert) {
  9284. return;
  9285. }
  9286. table = self.plugin.getSelectedTable();
  9287. if (table) {
  9288. rowsBox.val(table[0].rows.length);
  9289. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9290. rowsBox.attr('disabled', true);
  9291. colsBox.attr('disabled', true);
  9292. var match,
  9293. tableWidth = table[0].style.width || table[0].width,
  9294. tableHeight = table[0].style.height || table[0].height;
  9295. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9296. widthBox.val(match[1]);
  9297. widthTypeBox.val(match[2]);
  9298. } else {
  9299. widthBox.val('');
  9300. }
  9301. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9302. heightBox.val(match[1]);
  9303. heightTypeBox.val(match[2]);
  9304. }
  9305. paddingBox.val(table[0].cellPadding || '');
  9306. spacingBox.val(table[0].cellSpacing || '');
  9307. alignBox.val(table[0].align || '');
  9308. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9309. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9310. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9311. widthBox[0].focus();
  9312. widthBox[0].select();
  9313. }
  9314. },
  9315. cellprop : function() {
  9316. var html = [
  9317. '<div style="padding:20px;">',
  9318. '<div class="ke-dialog-row">',
  9319. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9320. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9321. '<select name="widthType">',
  9322. '<option value="%">' + lang.percent + '</option>',
  9323. '<option value="px">' + lang.px + '</option>',
  9324. '</select> &nbsp; ',
  9325. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9326. '<select name="heightType">',
  9327. '<option value="%">' + lang.percent + '</option>',
  9328. '<option value="px">' + lang.px + '</option>',
  9329. '</select>',
  9330. '</div>',
  9331. '<div class="ke-dialog-row">',
  9332. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9333. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9334. '<option value="">' + lang.alignDefault + '</option>',
  9335. '<option value="left">' + lang.alignLeft + '</option>',
  9336. '<option value="center">' + lang.alignCenter + '</option>',
  9337. '<option value="right">' + lang.alignRight + '</option>',
  9338. '</select> ',
  9339. lang.verticalAlign + ' <select name="verticalAlign">',
  9340. '<option value="">' + lang.alignDefault + '</option>',
  9341. '<option value="top">' + lang.alignTop + '</option>',
  9342. '<option value="middle">' + lang.alignMiddle + '</option>',
  9343. '<option value="bottom">' + lang.alignBottom + '</option>',
  9344. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9345. '</select>',
  9346. '</div>',
  9347. '<div class="ke-dialog-row">',
  9348. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9349. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9350. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9351. '</div>',
  9352. '<div class="ke-dialog-row">',
  9353. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9354. '<span class="ke-inline-block ke-input-color"></span>',
  9355. '</div>',
  9356. '</div>'
  9357. ].join('');
  9358. var bookmark = self.cmd.range.createBookmark();
  9359. var dialog = self.createDialog({
  9360. name : name,
  9361. width : 500,
  9362. title : self.lang('tablecell'),
  9363. body : html,
  9364. beforeRemove : function() {
  9365. colorBox.unbind();
  9366. },
  9367. yesBtn : {
  9368. name : self.lang('yes'),
  9369. click : function(e) {
  9370. var width = widthBox.val(),
  9371. height = heightBox.val(),
  9372. widthType = widthTypeBox.val(),
  9373. heightType = heightTypeBox.val(),
  9374. padding = paddingBox.val(),
  9375. spacing = spacingBox.val(),
  9376. textAlign = textAlignBox.val(),
  9377. verticalAlign = verticalAlignBox.val(),
  9378. border = borderBox.val(),
  9379. borderColor = K(colorBox[0]).html() || '',
  9380. bgColor = K(colorBox[1]).html() || '';
  9381. if (!/^\d*$/.test(width)) {
  9382. alert(self.lang('invalidWidth'));
  9383. widthBox[0].focus();
  9384. return;
  9385. }
  9386. if (!/^\d*$/.test(height)) {
  9387. alert(self.lang('invalidHeight'));
  9388. heightBox[0].focus();
  9389. return;
  9390. }
  9391. if (!/^\d*$/.test(border)) {
  9392. alert(self.lang('invalidBorder'));
  9393. borderBox[0].focus();
  9394. return;
  9395. }
  9396. cell.css({
  9397. width : width !== '' ? (width + widthType) : '',
  9398. height : height !== '' ? (height + heightType) : '',
  9399. 'background-color' : bgColor,
  9400. 'text-align' : textAlign,
  9401. 'vertical-align' : verticalAlign,
  9402. 'border-width' : border,
  9403. 'border-style' : border !== '' ? 'solid' : '',
  9404. 'border-color' : borderColor
  9405. });
  9406. self.hideDialog().focus();
  9407. self.cmd.range.moveToBookmark(bookmark);
  9408. self.cmd.select();
  9409. self.addBookmark();
  9410. }
  9411. }
  9412. }),
  9413. div = dialog.div,
  9414. widthBox = K('[name="width"]', div).val(100),
  9415. heightBox = K('[name="height"]', div),
  9416. widthTypeBox = K('[name="widthType"]', div),
  9417. heightTypeBox = K('[name="heightType"]', div),
  9418. paddingBox = K('[name="padding"]', div).val(2),
  9419. spacingBox = K('[name="spacing"]', div).val(0),
  9420. textAlignBox = K('[name="textAlign"]', div),
  9421. verticalAlignBox = K('[name="verticalAlign"]', div),
  9422. borderBox = K('[name="border"]', div).val(1),
  9423. colorBox = K('.ke-input-color', div);
  9424. _initColorPicker(div, colorBox.eq(0));
  9425. _initColorPicker(div, colorBox.eq(1));
  9426. _setColor(colorBox.eq(0), '#000000');
  9427. _setColor(colorBox.eq(1), '');
  9428. widthBox[0].focus();
  9429. widthBox[0].select();
  9430. var cell = self.plugin.getSelectedCell();
  9431. var match,
  9432. cellWidth = cell[0].style.width || cell[0].width || '',
  9433. cellHeight = cell[0].style.height || cell[0].height || '';
  9434. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9435. widthBox.val(match[1]);
  9436. widthTypeBox.val(match[2]);
  9437. } else {
  9438. widthBox.val('');
  9439. }
  9440. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9441. heightBox.val(match[1]);
  9442. heightTypeBox.val(match[2]);
  9443. }
  9444. textAlignBox.val(cell[0].style.textAlign || '');
  9445. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9446. var border = cell[0].style.borderWidth || '';
  9447. if (border) {
  9448. border = parseInt(border);
  9449. }
  9450. borderBox.val(border);
  9451. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9452. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9453. widthBox[0].focus();
  9454. widthBox[0].select();
  9455. },
  9456. insert : function() {
  9457. this.prop(true);
  9458. },
  9459. 'delete' : function() {
  9460. var table = self.plugin.getSelectedTable();
  9461. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9462. self.cmd.select();
  9463. table.remove();
  9464. self.addBookmark();
  9465. },
  9466. colinsert : function(offset) {
  9467. var table = self.plugin.getSelectedTable()[0],
  9468. row = self.plugin.getSelectedRow()[0],
  9469. cell = self.plugin.getSelectedCell()[0],
  9470. index = cell.cellIndex + offset;
  9471. index += table.rows[0].cells.length - row.cells.length;
  9472. for (var i = 0, len = table.rows.length; i < len; i++) {
  9473. var newRow = table.rows[i],
  9474. newCell = newRow.insertCell(index);
  9475. newCell.innerHTML = K.IE ? '' : '<br />';
  9476. index = _getCellIndex(table, newRow, newCell);
  9477. }
  9478. self.cmd.range.selectNodeContents(cell).collapse(true);
  9479. self.cmd.select();
  9480. self.addBookmark();
  9481. },
  9482. colinsertleft : function() {
  9483. this.colinsert(0);
  9484. },
  9485. colinsertright : function() {
  9486. this.colinsert(1);
  9487. },
  9488. rowinsert : function(offset) {
  9489. var table = self.plugin.getSelectedTable()[0],
  9490. row = self.plugin.getSelectedRow()[0],
  9491. cell = self.plugin.getSelectedCell()[0];
  9492. var rowIndex = row.rowIndex;
  9493. if (offset === 1) {
  9494. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9495. }
  9496. var newRow = table.insertRow(rowIndex);
  9497. for (var i = 0, len = row.cells.length; i < len; i++) {
  9498. if (row.cells[i].rowSpan > 1) {
  9499. len -= row.cells[i].rowSpan - 1;
  9500. }
  9501. var newCell = newRow.insertCell(i);
  9502. if (offset === 1 && row.cells[i].colSpan > 1) {
  9503. newCell.colSpan = row.cells[i].colSpan;
  9504. }
  9505. newCell.innerHTML = K.IE ? '' : '<br />';
  9506. }
  9507. for (var j = rowIndex; j >= 0; j--) {
  9508. var cells = table.rows[j].cells;
  9509. if (cells.length > i) {
  9510. for (var k = cell.cellIndex; k >= 0; k--) {
  9511. if (cells[k].rowSpan > 1) {
  9512. cells[k].rowSpan += 1;
  9513. }
  9514. }
  9515. break;
  9516. }
  9517. }
  9518. self.cmd.range.selectNodeContents(cell).collapse(true);
  9519. self.cmd.select();
  9520. self.addBookmark();
  9521. },
  9522. rowinsertabove : function() {
  9523. this.rowinsert(0);
  9524. },
  9525. rowinsertbelow : function() {
  9526. this.rowinsert(1);
  9527. },
  9528. rowmerge : function() {
  9529. var table = self.plugin.getSelectedTable()[0],
  9530. row = self.plugin.getSelectedRow()[0],
  9531. cell = self.plugin.getSelectedCell()[0],
  9532. rowIndex = row.rowIndex,
  9533. nextRowIndex = rowIndex + cell.rowSpan,
  9534. nextRow = table.rows[nextRowIndex];
  9535. if (table.rows.length <= nextRowIndex) {
  9536. return;
  9537. }
  9538. var cellIndex = cell.cellIndex;
  9539. if (nextRow.cells.length <= cellIndex) {
  9540. return;
  9541. }
  9542. var nextCell = nextRow.cells[cellIndex];
  9543. if (cell.colSpan !== nextCell.colSpan) {
  9544. return;
  9545. }
  9546. cell.rowSpan += nextCell.rowSpan;
  9547. nextRow.deleteCell(cellIndex);
  9548. self.cmd.range.selectNodeContents(cell).collapse(true);
  9549. self.cmd.select();
  9550. self.addBookmark();
  9551. },
  9552. colmerge : function() {
  9553. var table = self.plugin.getSelectedTable()[0],
  9554. row = self.plugin.getSelectedRow()[0],
  9555. cell = self.plugin.getSelectedCell()[0],
  9556. rowIndex = row.rowIndex,
  9557. cellIndex = cell.cellIndex,
  9558. nextCellIndex = cellIndex + 1;
  9559. if (row.cells.length <= nextCellIndex) {
  9560. return;
  9561. }
  9562. var nextCell = row.cells[nextCellIndex];
  9563. if (cell.rowSpan !== nextCell.rowSpan) {
  9564. return;
  9565. }
  9566. cell.colSpan += nextCell.colSpan;
  9567. row.deleteCell(nextCellIndex);
  9568. self.cmd.range.selectNodeContents(cell).collapse(true);
  9569. self.cmd.select();
  9570. self.addBookmark();
  9571. },
  9572. rowsplit : function() {
  9573. var table = self.plugin.getSelectedTable()[0],
  9574. row = self.plugin.getSelectedRow()[0],
  9575. cell = self.plugin.getSelectedCell()[0],
  9576. rowIndex = row.rowIndex;
  9577. if (cell.rowSpan === 1) {
  9578. return;
  9579. }
  9580. var cellIndex = _getCellIndex(table, row, cell);
  9581. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9582. var newRow = table.rows[rowIndex + i],
  9583. newCell = newRow.insertCell(cellIndex);
  9584. if (cell.colSpan > 1) {
  9585. newCell.colSpan = cell.colSpan;
  9586. }
  9587. newCell.innerHTML = K.IE ? '' : '<br />';
  9588. cellIndex = _getCellIndex(table, newRow, newCell);
  9589. }
  9590. K(cell).removeAttr('rowSpan');
  9591. self.cmd.range.selectNodeContents(cell).collapse(true);
  9592. self.cmd.select();
  9593. self.addBookmark();
  9594. },
  9595. colsplit : function() {
  9596. var table = self.plugin.getSelectedTable()[0],
  9597. row = self.plugin.getSelectedRow()[0],
  9598. cell = self.plugin.getSelectedCell()[0],
  9599. cellIndex = cell.cellIndex;
  9600. if (cell.colSpan === 1) {
  9601. return;
  9602. }
  9603. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9604. var newCell = row.insertCell(cellIndex + i);
  9605. if (cell.rowSpan > 1) {
  9606. newCell.rowSpan = cell.rowSpan;
  9607. }
  9608. newCell.innerHTML = K.IE ? '' : '<br />';
  9609. }
  9610. K(cell).removeAttr('colSpan');
  9611. self.cmd.range.selectNodeContents(cell).collapse(true);
  9612. self.cmd.select();
  9613. self.addBookmark();
  9614. },
  9615. coldelete : function() {
  9616. var table = self.plugin.getSelectedTable()[0],
  9617. row = self.plugin.getSelectedRow()[0],
  9618. cell = self.plugin.getSelectedCell()[0],
  9619. index = cell.cellIndex;
  9620. for (var i = 0, len = table.rows.length; i < len; i++) {
  9621. var newRow = table.rows[i],
  9622. newCell = newRow.cells[index];
  9623. if (newCell.colSpan > 1) {
  9624. newCell.colSpan -= 1;
  9625. if (newCell.colSpan === 1) {
  9626. K(newCell).removeAttr('colSpan');
  9627. }
  9628. } else {
  9629. newRow.deleteCell(index);
  9630. }
  9631. if (newCell.rowSpan > 1) {
  9632. i += newCell.rowSpan - 1;
  9633. }
  9634. }
  9635. if (row.cells.length === 0) {
  9636. self.cmd.range.setStartBefore(table).collapse(true);
  9637. self.cmd.select();
  9638. K(table).remove();
  9639. } else {
  9640. self.cmd.selection(true);
  9641. }
  9642. self.addBookmark();
  9643. },
  9644. rowdelete : function() {
  9645. var table = self.plugin.getSelectedTable()[0],
  9646. row = self.plugin.getSelectedRow()[0],
  9647. cell = self.plugin.getSelectedCell()[0],
  9648. rowIndex = row.rowIndex;
  9649. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9650. table.deleteRow(rowIndex + i);
  9651. }
  9652. if (table.rows.length === 0) {
  9653. self.cmd.range.setStartBefore(table).collapse(true);
  9654. self.cmd.select();
  9655. K(table).remove();
  9656. } else {
  9657. self.cmd.selection(true);
  9658. }
  9659. self.addBookmark();
  9660. }
  9661. };
  9662. self.clickToolbar(name, self.plugin.table.prop);
  9663. });
  9664. /*******************************************************************************
  9665. * KindEditor - WYSIWYG HTML Editor for Internet
  9666. * Copyright (C) 2006-2011 kindsoft.net
  9667. *
  9668. * @author Roddy <luolonghao@gmail.com>
  9669. * @site http://www.kindsoft.net/
  9670. * @licence http://www.kindsoft.net/license.php
  9671. *******************************************************************************/
  9672. KindEditor.plugin('template', function(K) {
  9673. var self = this, name = 'template', lang = self.lang(name + '.'),
  9674. htmlPath = self.pluginsPath + name + '/html/';
  9675. function getFilePath(fileName) {
  9676. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9677. }
  9678. self.clickToolbar(name, function() {
  9679. var lang = self.lang(name + '.'),
  9680. arr = ['<div style="padding:10px 20px;">',
  9681. '<div class="ke-header">',
  9682. '<div class="ke-left">',
  9683. lang. selectTemplate + ' <select>'];
  9684. K.each(lang.fileList, function(key, val) {
  9685. arr.push('<option value="' + key + '">' + val + '</option>');
  9686. });
  9687. html = [arr.join(''),
  9688. '</select></div>',
  9689. '<div class="ke-right">',
  9690. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9691. '</div>',
  9692. '<div class="ke-clearfix"></div>',
  9693. '</div>',
  9694. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9695. '</div>'].join('');
  9696. var dialog = self.createDialog({
  9697. name : name,
  9698. width : 500,
  9699. title : self.lang(name),
  9700. body : html,
  9701. yesBtn : {
  9702. name : self.lang('yes'),
  9703. click : function(e) {
  9704. var doc = K.iframeDoc(iframe);
  9705. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9706. }
  9707. }
  9708. });
  9709. var selectBox = K('select', dialog.div),
  9710. checkbox = K('[name="replaceFlag"]', dialog.div),
  9711. iframe = K('iframe', dialog.div);
  9712. checkbox[0].checked = true;
  9713. iframe.attr('src', getFilePath(selectBox.val()));
  9714. selectBox.change(function() {
  9715. iframe.attr('src', getFilePath(this.value));
  9716. });
  9717. });
  9718. });
  9719. /*******************************************************************************
  9720. * KindEditor - WYSIWYG HTML Editor for Internet
  9721. * Copyright (C) 2006-2011 kindsoft.net
  9722. *
  9723. * @author Roddy <luolonghao@gmail.com>
  9724. * @site http://www.kindsoft.net/
  9725. * @licence http://www.kindsoft.net/license.php
  9726. *******************************************************************************/
  9727. KindEditor.plugin('wordpaste', function(K) {
  9728. var self = this, name = 'wordpaste';
  9729. self.clickToolbar(name, function() {
  9730. var lang = self.lang(name + '.'),
  9731. html = '<div style="padding:10px 20px;">' +
  9732. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9733. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9734. '</div>',
  9735. dialog = self.createDialog({
  9736. name : name,
  9737. width : 450,
  9738. title : self.lang(name),
  9739. body : html,
  9740. yesBtn : {
  9741. name : self.lang('yes'),
  9742. click : function(e) {
  9743. var str = doc.body.innerHTML;
  9744. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9745. self.insertHtml(str).hideDialog().focus();
  9746. }
  9747. }
  9748. }),
  9749. div = dialog.div,
  9750. iframe = K('iframe', div),
  9751. doc = K.iframeDoc(iframe);
  9752. if (!K.IE) {
  9753. doc.designMode = 'on';
  9754. }
  9755. doc.open();
  9756. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9757. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9758. if (!K.IE) {
  9759. doc.write('<br />');
  9760. }
  9761. doc.write('</body></html>');
  9762. doc.close();
  9763. if (K.IE) {
  9764. doc.body.contentEditable = 'true';
  9765. }
  9766. iframe[0].contentWindow.focus();
  9767. });
  9768. });
  9769. KindEditor.plugin('fixtoolbar', function (K) {
  9770. var self = this;
  9771. if (!self.fixToolBar) {
  9772. return;
  9773. }
  9774. function init() {
  9775. var toolbar = K('.ke-toolbar');
  9776. var originY = toolbar.pos().y;
  9777. K(window).bind('scroll', function () {
  9778. if (toolbar.css('position') == 'fixed') {
  9779. if(document.body.scrollTop - originY < 0){
  9780. toolbar.css('position', 'static');
  9781. toolbar.css('top', 'auto');
  9782. }
  9783. } else {
  9784. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9785. toolbar.css('position', 'fixed');
  9786. toolbar.css('top', 0);
  9787. }
  9788. }
  9789. });
  9790. }
  9791. if (self.isCreated) {
  9792. init();
  9793. } else {
  9794. self.afterCreate(init);
  9795. }
  9796. });