kindeditor-all-min.js 300 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2017 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.12 (2017-04-12)
  9. *******************************************************************************/
  10. (function (window, undefined) {
  11. if (window.KindEditor) {
  12. return;
  13. }
  14. if (!window.console) {
  15. window.console = {};
  16. }
  17. if (!console.log) {
  18. console.log = function () {};
  19. }
  20. var _VERSION = '4.1.12 (2017-04-12)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  24. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  25. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  26. _OPERA = _ua.indexOf('opera') > -1,
  27. _MOBILE = _ua.indexOf('mobile') > -1,
  28. _IOS = /ipad|iphone|ipod/.test(_ua),
  29. _QUIRKS = document.compatMode != 'CSS1Compat',
  30. _IERANGE = !window.getSelection,
  31. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  32. _V = _matches ? _matches[1] : '0',
  33. _TIME = new Date().getTime();
  34. function _isArray(val) {
  35. if (!val) {
  36. return false;
  37. }
  38. return Object.prototype.toString.call(val) === '[object Array]';
  39. }
  40. function _isFunction(val) {
  41. if (!val) {
  42. return false;
  43. }
  44. return Object.prototype.toString.call(val) === '[object Function]';
  45. }
  46. function _inArray(val, arr) {
  47. for (var i = 0, len = arr.length; i < len; i++) {
  48. if (val === arr[i]) {
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. function _each(obj, fn) {
  55. if (_isArray(obj)) {
  56. for (var i = 0, len = obj.length; i < len; i++) {
  57. if (fn.call(obj[i], i, obj[i]) === false) {
  58. break;
  59. }
  60. }
  61. } else {
  62. for (var key in obj) {
  63. if (obj.hasOwnProperty(key)) {
  64. if (fn.call(obj[key], key, obj[key]) === false) {
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. function _trim(str) {
  72. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  73. }
  74. function _inString(val, str, delimiter) {
  75. delimiter = delimiter === undefined ? ',' : delimiter;
  76. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  77. }
  78. function _addUnit(val, unit) {
  79. unit = unit || 'px';
  80. return val && /^-?\d+(?:\.\d+)?$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function(key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function(key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () {};
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function(key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG : false,
  180. VERSION : _VERSION,
  181. IE : _IE,
  182. GECKO : _GECKO,
  183. WEBKIT : _WEBKIT,
  184. OPERA : _OPERA,
  185. V : _V,
  186. TIME : _TIME,
  187. each : _each,
  188. isArray : _isArray,
  189. isFunction : _isFunction,
  190. inArray : _inArray,
  191. inString : _inString,
  192. trim : _trim,
  193. addUnit : _addUnit,
  194. removeUnit : _removeUnit,
  195. escape : _escape,
  196. unescape : _unescape,
  197. toCamel : _toCamel,
  198. toHex : _toHex,
  199. toMap : _toMap,
  200. toArray : _toArray,
  201. undef : _undef,
  202. invalidUrl : _invalidUrl,
  203. addParam : _addParam,
  204. extend : _extend,
  205. json : _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. index : 0,
  230. designMode : true,
  231. fullscreenMode : false,
  232. filterMode : true,
  233. wellFormatMode : true,
  234. shadowMode : true,
  235. loadStyleMode : true,
  236. basePath : K.basePath,
  237. themesPath : K.basePath + 'themes/',
  238. langPath : K.basePath + 'lang/',
  239. pluginsPath : K.basePath + 'plugins/',
  240. themeType : 'default',
  241. langType : 'zh-CN',
  242. urlType : '',
  243. newlineTag : 'p',
  244. resizeType : 2,
  245. syncType : 'form',
  246. pasteType : 2,
  247. dialogAlignType : 'page',
  248. useContextmenu : true,
  249. fullscreenShortcut : false,
  250. bodyClass : 'ke-content',
  251. indentChar : '\t',
  252. cssPath : '',
  253. cssData : '',
  254. minWidth : 650,
  255. minHeight : 100,
  256. minChangeSize : 50,
  257. zIndex : 19850426,
  258. items : [
  259. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  260. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  261. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  262. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  263. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  264. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  265. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  266. 'anchor', 'link', 'unlink', '|', 'about'
  267. ],
  268. noDisableItems : ['source', 'fullscreen'],
  269. colorTable : [
  270. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  271. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  272. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  273. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  274. ],
  275. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  276. htmlTags : {
  277. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  278. span : [
  279. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  280. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  281. ],
  282. div : [
  283. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  284. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  285. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  286. ],
  287. table: [
  288. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  289. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  290. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  291. '.width', '.height', '.border-collapse'
  292. ],
  293. 'td,th': [
  294. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  295. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  296. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  297. ],
  298. a : ['id', 'class', 'href', 'target', 'name'],
  299. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  300. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  301. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  302. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  303. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  304. ],
  305. pre : ['id', 'class'],
  306. hr : ['id', 'class', '.page-break-after'],
  307. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  308. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  309. },
  310. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  311. };
  312. var _useCapture = false;
  313. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  314. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  315. var _CHANGE_KEY_MAP = {};
  316. _each(_INPUT_KEY_MAP, function(key, val) {
  317. _CHANGE_KEY_MAP[key] = val;
  318. });
  319. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  320. _CHANGE_KEY_MAP[key] = val;
  321. });
  322. function _bindEvent(el, type, fn) {
  323. if (el.addEventListener){
  324. el.addEventListener(type, fn, _useCapture);
  325. } else if (el.attachEvent){
  326. el.attachEvent('on' + type, fn);
  327. }
  328. }
  329. function _unbindEvent(el, type, fn) {
  330. if (el.removeEventListener){
  331. el.removeEventListener(type, fn, _useCapture);
  332. } else if (el.detachEvent){
  333. el.detachEvent('on' + type, fn);
  334. }
  335. }
  336. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  337. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  338. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  339. function KEvent(el, event) {
  340. this.init(el, event);
  341. }
  342. _extend(KEvent, {
  343. init : function(el, event) {
  344. var self = this, doc = el.ownerDocument || el.document || el;
  345. self.event = event;
  346. _each(_EVENT_PROPS, function(key, val) {
  347. self[val] = event[val];
  348. });
  349. if (!self.target) {
  350. self.target = self.srcElement || doc;
  351. }
  352. if (self.target.nodeType === 3) {
  353. self.target = self.target.parentNode;
  354. }
  355. if (!self.relatedTarget && self.fromElement) {
  356. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  357. }
  358. if (self.pageX == null && self.clientX != null) {
  359. var d = doc.documentElement, body = doc.body;
  360. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  361. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  362. }
  363. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  364. self.which = self.charCode || self.keyCode;
  365. }
  366. if (!self.metaKey && self.ctrlKey) {
  367. self.metaKey = self.ctrlKey;
  368. }
  369. if (!self.which && self.button !== undefined) {
  370. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  371. }
  372. switch (self.which) {
  373. case 186 :
  374. self.which = 59;
  375. break;
  376. case 187 :
  377. case 107 :
  378. case 43 :
  379. self.which = 61;
  380. break;
  381. case 189 :
  382. case 45 :
  383. self.which = 109;
  384. break;
  385. case 42 :
  386. self.which = 106;
  387. break;
  388. case 47 :
  389. self.which = 111;
  390. break;
  391. case 78 :
  392. self.which = 110;
  393. break;
  394. }
  395. if (self.which >= 96 && self.which <= 105) {
  396. self.which -= 48;
  397. }
  398. },
  399. preventDefault : function() {
  400. var ev = this.event;
  401. if (ev.preventDefault) {
  402. ev.preventDefault();
  403. } else {
  404. ev.returnValue = false;
  405. }
  406. },
  407. stopPropagation : function() {
  408. var ev = this.event;
  409. if (ev.stopPropagation) {
  410. ev.stopPropagation();
  411. } else {
  412. ev.cancelBubble = true;
  413. }
  414. },
  415. stop : function() {
  416. this.preventDefault();
  417. this.stopPropagation();
  418. }
  419. });
  420. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  421. function _getId(el) {
  422. return el[_eventExpendo] || null;
  423. }
  424. function _setId(el) {
  425. el[_eventExpendo] = ++_eventId;
  426. return _eventId;
  427. }
  428. function _removeId(el) {
  429. try {
  430. delete el[_eventExpendo];
  431. } catch(e) {
  432. if (el.removeAttribute) {
  433. el.removeAttribute(_eventExpendo);
  434. }
  435. }
  436. }
  437. function _bind(el, type, fn) {
  438. if (type.indexOf(',') >= 0) {
  439. _each(type.split(','), function() {
  440. _bind(el, this, fn);
  441. });
  442. return;
  443. }
  444. var id = _getId(el);
  445. if (!id) {
  446. id = _setId(el);
  447. }
  448. if (_eventData[id] === undefined) {
  449. _eventData[id] = {};
  450. }
  451. var events = _eventData[id][type];
  452. if (events && events.length > 0) {
  453. _unbindEvent(el, type, events[0]);
  454. } else {
  455. _eventData[id][type] = [];
  456. _eventData[id].el = el;
  457. }
  458. events = _eventData[id][type];
  459. if (events.length === 0) {
  460. events[0] = function(e) {
  461. var kevent = e ? new KEvent(el, e) : undefined;
  462. _each(events, function(i, event) {
  463. if (i > 0 && event) {
  464. event.call(el, kevent);
  465. }
  466. });
  467. };
  468. }
  469. if (_inArray(fn, events) < 0) {
  470. events.push(fn);
  471. }
  472. _bindEvent(el, type, events[0]);
  473. }
  474. function _unbind(el, type, fn) {
  475. if (type && type.indexOf(',') >= 0) {
  476. _each(type.split(','), function() {
  477. _unbind(el, this, fn);
  478. });
  479. return;
  480. }
  481. var id = _getId(el);
  482. if (!id) {
  483. return;
  484. }
  485. if (type === undefined) {
  486. if (id in _eventData) {
  487. _each(_eventData[id], function(key, events) {
  488. if (key != 'el' && events.length > 0) {
  489. _unbindEvent(el, key, events[0]);
  490. }
  491. });
  492. delete _eventData[id];
  493. _removeId(el);
  494. }
  495. return;
  496. }
  497. if (!_eventData[id]) {
  498. return;
  499. }
  500. var events = _eventData[id][type];
  501. if (events && events.length > 0) {
  502. if (fn === undefined) {
  503. _unbindEvent(el, type, events[0]);
  504. delete _eventData[id][type];
  505. } else {
  506. _each(events, function(i, event) {
  507. if (i > 0 && event === fn) {
  508. events.splice(i, 1);
  509. }
  510. });
  511. if (events.length == 1) {
  512. _unbindEvent(el, type, events[0]);
  513. delete _eventData[id][type];
  514. }
  515. }
  516. var count = 0;
  517. _each(_eventData[id], function() {
  518. count++;
  519. });
  520. if (count < 2) {
  521. delete _eventData[id];
  522. _removeId(el);
  523. }
  524. }
  525. }
  526. function _fire(el, type) {
  527. if (type.indexOf(',') >= 0) {
  528. _each(type.split(','), function() {
  529. _fire(el, this);
  530. });
  531. return;
  532. }
  533. var id = _getId(el);
  534. if (!id) {
  535. return;
  536. }
  537. var events = _eventData[id][type];
  538. if (_eventData[id] && events && events.length > 0) {
  539. events[0]();
  540. }
  541. }
  542. function _ctrl(el, key, fn) {
  543. var self = this;
  544. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  545. _bind(el, 'keydown', function(e) {
  546. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  547. fn.call(el);
  548. e.stop();
  549. }
  550. });
  551. }
  552. var _readyFinished = false;
  553. function _ready(fn) {
  554. if (_readyFinished) {
  555. fn(KindEditor);
  556. return;
  557. }
  558. var loaded = false;
  559. function readyFunc() {
  560. if (!loaded) {
  561. loaded = true;
  562. fn(KindEditor);
  563. _readyFinished = true;
  564. }
  565. }
  566. function ieReadyFunc() {
  567. if (!loaded) {
  568. try {
  569. document.documentElement.doScroll('left');
  570. } catch(e) {
  571. setTimeout(ieReadyFunc, 100);
  572. return;
  573. }
  574. readyFunc();
  575. }
  576. }
  577. function ieReadyStateFunc() {
  578. if (document.readyState === 'complete') {
  579. readyFunc();
  580. }
  581. }
  582. if (document.addEventListener) {
  583. _bind(document, 'DOMContentLoaded', readyFunc);
  584. } else if (document.attachEvent) {
  585. _bind(document, 'readystatechange', ieReadyStateFunc);
  586. var toplevel = false;
  587. try {
  588. toplevel = window.frameElement == null;
  589. } catch(e) {}
  590. if (document.documentElement.doScroll && toplevel) {
  591. ieReadyFunc();
  592. }
  593. }
  594. _bind(window, 'load', readyFunc);
  595. }
  596. if (window.attachEvent) {
  597. window.attachEvent('onunload', function() {
  598. _each(_eventData, function(key, events) {
  599. if (events.el) {
  600. _unbind(events.el);
  601. }
  602. });
  603. });
  604. }
  605. K.ctrl = _ctrl;
  606. K.ready = _ready;
  607. function _getCssList(css) {
  608. css = css.replace(/&quot;/g, '"');
  609. var list = {},
  610. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  611. match;
  612. while ((match = reg.exec(css))) {
  613. var key = _trim(match[1].toLowerCase()),
  614. val = _trim(_toHex(match[2]));
  615. list[key] = val;
  616. }
  617. return list;
  618. }
  619. function _getAttrList(tag) {
  620. var list = {},
  621. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  622. match;
  623. while ((match = reg.exec(tag))) {
  624. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  625. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  626. list[key] = val;
  627. }
  628. return list;
  629. }
  630. function _addClassToTag(tag, className) {
  631. if (/\s+class\s*=/.test(tag)) {
  632. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  633. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  634. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  635. } else {
  636. return $0;
  637. }
  638. });
  639. } else {
  640. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  641. }
  642. return tag;
  643. }
  644. function _formatCss(css) {
  645. var str = '';
  646. _each(_getCssList(css), function(key, val) {
  647. str += key + ':' + val + ';';
  648. });
  649. return str;
  650. }
  651. function _formatUrl(url, mode, host, pathname) {
  652. return url;
  653. mode = _undef(mode, '').toLowerCase();
  654. if (url.substr(0, 5) != 'data:') {
  655. url = url.replace(/([^:])\/\//g, '$1/');
  656. }
  657. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  658. return url;
  659. }
  660. host = host || location.protocol + '//' + location.host;
  661. if (pathname === undefined) {
  662. var m = location.pathname.match(/^(\/.*)\//);
  663. pathname = m ? m[1] : '';
  664. }
  665. var match;
  666. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  667. if (match[1] !== host) {
  668. return url;
  669. }
  670. } else if (/^\w+:/.test(url)) {
  671. return url;
  672. }
  673. function getRealPath(path) {
  674. var parts = path.split('/'), paths = [];
  675. for (var i = 0, len = parts.length; i < len; i++) {
  676. var part = parts[i];
  677. if (part == '..') {
  678. if (paths.length > 0) {
  679. paths.pop();
  680. }
  681. } else if (part !== '' && part != '.') {
  682. paths.push(part);
  683. }
  684. }
  685. return '/' + paths.join('/');
  686. }
  687. if (/^\//.test(url)) {
  688. url = host + getRealPath(url.substr(1));
  689. } else if (!/^\w+:\/\//.test(url)) {
  690. url = host + getRealPath(pathname + '/' + url);
  691. }
  692. function getRelativePath(path, depth) {
  693. if (url.substr(0, path.length) === path) {
  694. var arr = [];
  695. for (var i = 0; i < depth; i++) {
  696. arr.push('..');
  697. }
  698. var prefix = '.';
  699. if (arr.length > 0) {
  700. prefix += '/' + arr.join('/');
  701. }
  702. if (pathname == '/') {
  703. prefix += '/';
  704. }
  705. return prefix + url.substr(path.length);
  706. } else {
  707. if ((match = /^(.*)\//.exec(path))) {
  708. return getRelativePath(match[1], ++depth);
  709. }
  710. }
  711. }
  712. if (mode === 'relative') {
  713. url = getRelativePath(host + pathname, 0).substr(2);
  714. } else if (mode === 'absolute') {
  715. if (url.substr(0, host.length) === host) {
  716. url = url.substr(host.length);
  717. }
  718. }
  719. return url;
  720. }
  721. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  722. if (html == null) {
  723. html = '';
  724. }
  725. urlType = urlType || '';
  726. wellFormatted = _undef(wellFormatted, false);
  727. indentChar = _undef(indentChar, '\t');
  728. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  729. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  730. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  731. });
  732. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  733. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  734. html = html.replace(/\u200B/g, '');
  735. html = html.replace(/\u00A9/g, '&copy;');
  736. html = html.replace(/\u00AE/g, '&reg;');
  737. html = html.replace(/\u2003/g, '&emsp;');
  738. html = html.replace(/\u3000/g, '&emsp;');
  739. html = html.replace(/&quot;/g, '');
  740. html = html.replace(/, " helvetica=""(.*?)"="/g, '');
  741. html = html.replace(/<[^>]+/g, function($0) {
  742. return $0.replace(/\s+/g, ' ');
  743. });
  744. var htmlTagMap = {};
  745. if (htmlTags) {
  746. _each(htmlTags, function(key, val) {
  747. var arr = key.split(',');
  748. for (var i = 0, len = arr.length; i < len; i++) {
  749. htmlTagMap[arr[i]] = _toMap(val);
  750. }
  751. });
  752. if (!htmlTagMap.script) {
  753. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  754. }
  755. if (!htmlTagMap.style) {
  756. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  757. }
  758. }
  759. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  760. var tagStack = [];
  761. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  762. var full = $0,
  763. startNewline = $1 || '',
  764. startSlash = $2 || '',
  765. tagName = $3.toLowerCase(),
  766. attr = $4 || '',
  767. endSlash = $5 ? ' ' + $5 : '',
  768. endNewline = $6 || '';
  769. if (htmlTags && !htmlTagMap[tagName]) {
  770. return '';
  771. }
  772. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  773. endSlash = ' /';
  774. }
  775. if (_INLINE_TAG_MAP[tagName]) {
  776. if (startNewline) {
  777. startNewline = ' ';
  778. }
  779. if (endNewline) {
  780. endNewline = ' ';
  781. }
  782. }
  783. if (_PRE_TAG_MAP[tagName]) {
  784. if (startSlash) {
  785. endNewline = '\n';
  786. } else {
  787. startNewline = '\n';
  788. }
  789. }
  790. if (wellFormatted && tagName == 'br') {
  791. endNewline = '\n';
  792. }
  793. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  794. if (wellFormatted) {
  795. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  796. tagStack.pop();
  797. } else {
  798. tagStack.push(tagName);
  799. }
  800. startNewline = '\n';
  801. endNewline = '\n';
  802. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  803. startNewline += indentChar;
  804. if (!startSlash) {
  805. endNewline += indentChar;
  806. }
  807. }
  808. if (endSlash) {
  809. tagStack.pop();
  810. } else if (!startSlash) {
  811. endNewline += indentChar;
  812. }
  813. } else {
  814. startNewline = endNewline = '';
  815. }
  816. }
  817. if (attr !== '') {
  818. var attrMap = _getAttrList(full);
  819. if (tagName === 'font') {
  820. var fontStyleMap = {}, fontStyle = '';
  821. _each(attrMap, function(key, val) {
  822. if (key === 'color') {
  823. fontStyleMap.color = val;
  824. delete attrMap[key];
  825. }
  826. if (key === 'size') {
  827. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  828. delete attrMap[key];
  829. }
  830. if (key === 'face') {
  831. fontStyleMap['font-family'] = val;
  832. delete attrMap[key];
  833. }
  834. if (key === 'style') {
  835. fontStyle = val;
  836. }
  837. });
  838. if (fontStyle && !/;$/.test(fontStyle)) {
  839. fontStyle += ';';
  840. }
  841. _each(fontStyleMap, function(key, val) {
  842. if (val === '') {
  843. return;
  844. }
  845. if (/\s/.test(val)) {
  846. val = "'" + val + "'";
  847. }
  848. fontStyle += key + ':' + val + ';';
  849. });
  850. attrMap.style = fontStyle;
  851. }
  852. _each(attrMap, function(key, val) {
  853. if (_FILL_ATTR_MAP[key]) {
  854. attrMap[key] = key;
  855. }
  856. if (_inArray(key, ['src', 'href']) >= 0) {
  857. attrMap[key] = _formatUrl(val, urlType);
  858. }
  859. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  860. tagName === 'body' && key === 'contenteditable' ||
  861. /^kindeditor_\d+$/.test(key)) {
  862. delete attrMap[key];
  863. }
  864. if (key === 'style' && val !== '') {
  865. var styleMap = _getCssList(val);
  866. _each(styleMap, function(k, v) {
  867. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  868. delete styleMap[k];
  869. }
  870. });
  871. var style = '';
  872. _each(styleMap, function(k, v) {
  873. style += k + ':' + v + ';';
  874. });
  875. attrMap.style = style;
  876. }
  877. });
  878. attr = '';
  879. _each(attrMap, function(key, val) {
  880. if (key === 'style' && val === '') {
  881. return;
  882. }
  883. val = val.replace(/"/g, '&quot;');
  884. attr += ' ' + key + '="' + val + '"';
  885. });
  886. }
  887. if (tagName === 'font') {
  888. tagName = 'span';
  889. }
  890. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  891. });
  892. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  893. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  894. });
  895. html = html.replace(/\n\s*\n/g, '\n');
  896. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  897. return _trim(html);
  898. }
  899. function _clearMsWord(html, htmlTags) {
  900. html = html.replace(/<meta[\s\S]*?>/ig, '')
  901. .replace(/<![\s\S]*?>/ig, '')
  902. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  903. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  904. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  905. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  906. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  907. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  908. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  909. });
  910. return _formatHtml(html, htmlTags);
  911. }
  912. function _mediaType(src) {
  913. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  914. return 'audio/x-pn-realaudio-plugin';
  915. }
  916. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  917. return 'application/x-shockwave-flash';
  918. }
  919. return 'video/x-ms-asf-plugin';
  920. }
  921. function _mediaClass(type) {
  922. if (/realaudio/i.test(type)) {
  923. return 'ke-rm';
  924. }
  925. if (/flash/i.test(type)) {
  926. return 'ke-flash';
  927. }
  928. return 'ke-media';
  929. }
  930. function _mediaAttrs(srcTag) {
  931. return _getAttrList(unescape(srcTag));
  932. }
  933. function _mediaEmbed(attrs) {
  934. var html = '<embed ';
  935. _each(attrs, function(key, val) {
  936. html += key + '="' + val + '" ';
  937. });
  938. html += '/>';
  939. return html;
  940. }
  941. function _mediaImg(blankPath, attrs) {
  942. var width = attrs.width,
  943. height = attrs.height,
  944. type = attrs.type || _mediaType(attrs.src),
  945. srcTag = _mediaEmbed(attrs),
  946. style = '';
  947. if (/\D/.test(width)) {
  948. style += 'width:' + width + ';';
  949. } else if (width > 0) {
  950. style += 'width:' + width + 'px;';
  951. }
  952. if (/\D/.test(height)) {
  953. style += 'height:' + height + ';';
  954. } else if (height > 0) {
  955. style += 'height:' + height + 'px;';
  956. }
  957. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  958. if (style !== '') {
  959. html += 'style="' + style + '" ';
  960. }
  961. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  962. return html;
  963. }
  964. function _tmpl(str, data) {
  965. var fn = new Function("obj",
  966. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  967. "with(obj){p.push('" +
  968. str.replace(/[\r\t\n]/g, " ")
  969. .split("<%").join("\t")
  970. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  971. .replace(/\t=(.*?)%>/g, "',$1,'")
  972. .split("\t").join("');")
  973. .split("%>").join("p.push('")
  974. .split("\r").join("\\'") + "');}return p.join('');");
  975. return data ? fn(data) : fn;
  976. }
  977. K.formatUrl = _formatUrl;
  978. K.formatHtml = _formatHtml;
  979. K.getCssList = _getCssList;
  980. K.getAttrList = _getAttrList;
  981. K.mediaType = _mediaType;
  982. K.mediaAttrs = _mediaAttrs;
  983. K.mediaEmbed = _mediaEmbed;
  984. K.mediaImg = _mediaImg;
  985. K.clearMsWord = _clearMsWord;
  986. K.tmpl = _tmpl;
  987. function _contains(nodeA, nodeB) {
  988. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  989. return true;
  990. }
  991. while ((nodeB = nodeB.parentNode)) {
  992. if (nodeB == nodeA) {
  993. return true;
  994. }
  995. }
  996. return false;
  997. }
  998. var _getSetAttrDiv = document.createElement('div');
  999. _getSetAttrDiv.setAttribute('className', 't');
  1000. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1001. function _getAttr(el, key) {
  1002. key = key.toLowerCase();
  1003. var val = null;
  1004. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1005. var div = el.ownerDocument.createElement('div');
  1006. div.appendChild(el.cloneNode(false));
  1007. var list = _getAttrList(_unescape(div.innerHTML));
  1008. if (key in list) {
  1009. val = list[key];
  1010. }
  1011. } else {
  1012. try {
  1013. val = el.getAttribute(key, 2);
  1014. } catch(e) {
  1015. val = el.getAttribute(key, 1);
  1016. }
  1017. }
  1018. if (key === 'style' && val !== null) {
  1019. val = _formatCss(val);
  1020. }
  1021. return val;
  1022. }
  1023. function _queryAll(expr, root) {
  1024. var exprList = expr.split(',');
  1025. if (exprList.length > 1) {
  1026. var mergedResults = [];
  1027. _each(exprList, function() {
  1028. _each(_queryAll(this, root), function() {
  1029. if (_inArray(this, mergedResults) < 0) {
  1030. mergedResults.push(this);
  1031. }
  1032. });
  1033. });
  1034. return mergedResults;
  1035. }
  1036. root = root || document;
  1037. function escape(str) {
  1038. if (typeof str != 'string') {
  1039. return str;
  1040. }
  1041. return str.replace(/([^\w\-])/g, '\\$1');
  1042. }
  1043. function stripslashes(str) {
  1044. return str.replace(/\\/g, '');
  1045. }
  1046. function cmpTag(tagA, tagB) {
  1047. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1048. }
  1049. function byId(id, tag, root) {
  1050. var arr = [],
  1051. doc = root.ownerDocument || root,
  1052. el = doc.getElementById(stripslashes(id));
  1053. if (el) {
  1054. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1055. arr.push(el);
  1056. }
  1057. }
  1058. return arr;
  1059. }
  1060. function byClass(className, tag, root) {
  1061. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1062. if (root.getElementsByClassName) {
  1063. els = root.getElementsByClassName(stripslashes(className));
  1064. for (i = 0, len = els.length; i < len; i++) {
  1065. el = els[i];
  1066. if (cmpTag(tag, el.nodeName)) {
  1067. arr.push(el);
  1068. }
  1069. }
  1070. } else if (doc.querySelectorAll) {
  1071. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1072. for (i = 0, len = els.length; i < len; i++) {
  1073. el = els[i];
  1074. if (_contains(root, el)) {
  1075. arr.push(el);
  1076. }
  1077. }
  1078. } else {
  1079. els = root.getElementsByTagName(tag);
  1080. className = ' ' + className + ' ';
  1081. for (i = 0, len = els.length; i < len; i++) {
  1082. el = els[i];
  1083. if (el.nodeType == 1) {
  1084. var cls = el.className;
  1085. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1086. arr.push(el);
  1087. }
  1088. }
  1089. }
  1090. }
  1091. return arr;
  1092. }
  1093. function byName(name, tag, root) {
  1094. var arr = [], doc = root.ownerDocument || root,
  1095. els = doc.getElementsByName(stripslashes(name)), el;
  1096. for (var i = 0, len = els.length; i < len; i++) {
  1097. el = els[i];
  1098. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1099. if (el.getAttribute('name') !== null) {
  1100. arr.push(el);
  1101. }
  1102. }
  1103. }
  1104. return arr;
  1105. }
  1106. function byAttr(key, val, tag, root) {
  1107. var arr = [], els = root.getElementsByTagName(tag), el;
  1108. for (var i = 0, len = els.length; i < len; i++) {
  1109. el = els[i];
  1110. if (el.nodeType == 1) {
  1111. if (val === null) {
  1112. if (_getAttr(el, key) !== null) {
  1113. arr.push(el);
  1114. }
  1115. } else {
  1116. if (val === escape(_getAttr(el, key))) {
  1117. arr.push(el);
  1118. }
  1119. }
  1120. }
  1121. }
  1122. return arr;
  1123. }
  1124. function select(expr, root) {
  1125. var arr = [], matches;
  1126. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1127. var tag = matches ? matches[1] : '*';
  1128. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1129. arr = byId(matches[1], tag, root);
  1130. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1131. arr = byClass(matches[1], tag, root);
  1132. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1133. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1134. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1135. var key = matches[1].toLowerCase(), val = matches[2];
  1136. if (key === 'id') {
  1137. arr = byId(val, tag, root);
  1138. } else if (key === 'class') {
  1139. arr = byClass(val, tag, root);
  1140. } else if (key === 'name') {
  1141. arr = byName(val, tag, root);
  1142. } else {
  1143. arr = byAttr(key, val, tag, root);
  1144. }
  1145. } else {
  1146. var els = root.getElementsByTagName(tag), el;
  1147. for (var i = 0, len = els.length; i < len; i++) {
  1148. el = els[i];
  1149. if (el.nodeType == 1) {
  1150. arr.push(el);
  1151. }
  1152. }
  1153. }
  1154. return arr;
  1155. }
  1156. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1157. while ((arr = re.exec(expr))) {
  1158. if (arr[1] !== ' ') {
  1159. parts.push(arr[1]);
  1160. }
  1161. }
  1162. var results = [];
  1163. if (parts.length == 1) {
  1164. return select(parts[0], root);
  1165. }
  1166. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1167. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1168. part = parts[i];
  1169. if (part === '>') {
  1170. isChild = true;
  1171. continue;
  1172. }
  1173. if (i > 0) {
  1174. els = [];
  1175. for (j = 0, len = results.length; j < len; j++) {
  1176. val = results[j];
  1177. subResults = select(part, val);
  1178. for (k = 0, l = subResults.length; k < l; k++) {
  1179. v = subResults[k];
  1180. if (isChild) {
  1181. if (val === v.parentNode) {
  1182. els.push(v);
  1183. }
  1184. } else {
  1185. els.push(v);
  1186. }
  1187. }
  1188. }
  1189. results = els;
  1190. } else {
  1191. results = select(part, root);
  1192. }
  1193. if (results.length === 0) {
  1194. return [];
  1195. }
  1196. }
  1197. return results;
  1198. }
  1199. function _query(expr, root) {
  1200. var arr = _queryAll(expr, root);
  1201. return arr.length > 0 ? arr[0] : null;
  1202. }
  1203. K.query = _query;
  1204. K.queryAll = _queryAll;
  1205. function _get(val) {
  1206. return K(val)[0];
  1207. }
  1208. function _getDoc(node) {
  1209. if (!node) {
  1210. return document;
  1211. }
  1212. return node.ownerDocument || node.document || node;
  1213. }
  1214. function _getWin(node) {
  1215. if (!node) {
  1216. return window;
  1217. }
  1218. var doc = _getDoc(node);
  1219. return doc.parentWindow || doc.defaultView;
  1220. }
  1221. function _setHtml(el, html) {
  1222. if (el.nodeType != 1) {
  1223. return;
  1224. }
  1225. var doc = _getDoc(el);
  1226. try {
  1227. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1228. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1229. temp.parentNode.removeChild(temp);
  1230. } catch(e) {
  1231. K(el).empty();
  1232. K('@' + html, doc).each(function() {
  1233. el.appendChild(this);
  1234. });
  1235. }
  1236. }
  1237. function _hasClass(el, cls) {
  1238. return _inString(cls, el.className, ' ');
  1239. }
  1240. function _setAttr(el, key, val) {
  1241. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1242. key = 'className';
  1243. }
  1244. el.setAttribute(key, '' + val);
  1245. }
  1246. function _removeAttr(el, key) {
  1247. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1248. key = 'className';
  1249. }
  1250. _setAttr(el, key, '');
  1251. el.removeAttribute(key);
  1252. }
  1253. function _getNodeName(node) {
  1254. if (!node || !node.nodeName) {
  1255. return '';
  1256. }
  1257. return node.nodeName.toLowerCase();
  1258. }
  1259. function _computedCss(el, key) {
  1260. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1261. if (win.getComputedStyle) {
  1262. var style = win.getComputedStyle(el, null);
  1263. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1264. } else if (el.currentStyle) {
  1265. val = el.currentStyle[camelKey] || el.style[camelKey];
  1266. }
  1267. return val;
  1268. }
  1269. function _hasVal(node) {
  1270. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1271. }
  1272. function _docElement(doc) {
  1273. doc = doc || document;
  1274. return _QUIRKS ? doc.body : doc.documentElement;
  1275. }
  1276. function _docHeight(doc) {
  1277. var el = _docElement(doc);
  1278. return Math.max(el.scrollHeight, el.clientHeight);
  1279. }
  1280. function _docWidth(doc) {
  1281. var el = _docElement(doc);
  1282. return Math.max(el.scrollWidth, el.clientWidth);
  1283. }
  1284. function _getScrollPos(doc) {
  1285. doc = doc || document;
  1286. var x, y;
  1287. if (_IE || _NEWIE || _OPERA) {
  1288. x = _docElement(doc).scrollLeft;
  1289. y = _docElement(doc).scrollTop;
  1290. } else {
  1291. x = _getWin(doc).scrollX;
  1292. y = _getWin(doc).scrollY;
  1293. }
  1294. return {x : x, y : y};
  1295. }
  1296. function KNode(node) {
  1297. this.init(node);
  1298. }
  1299. _extend(KNode, {
  1300. init : function(node) {
  1301. var self = this;
  1302. node = _isArray(node) ? node : [node];
  1303. var length = 0;
  1304. for (var i = 0, len = node.length; i < len; i++) {
  1305. if (node[i]) {
  1306. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1307. length++;
  1308. }
  1309. }
  1310. self.length = length;
  1311. self.doc = _getDoc(self[0]);
  1312. self.name = _getNodeName(self[0]);
  1313. self.type = self.length > 0 ? self[0].nodeType : null;
  1314. self.win = _getWin(self[0]);
  1315. },
  1316. each : function(fn) {
  1317. var self = this;
  1318. for (var i = 0; i < self.length; i++) {
  1319. if (fn.call(self[i], i, self[i]) === false) {
  1320. return self;
  1321. }
  1322. }
  1323. return self;
  1324. },
  1325. bind : function(type, fn) {
  1326. this.each(function() {
  1327. _bind(this, type, fn);
  1328. });
  1329. return this;
  1330. },
  1331. unbind : function(type, fn) {
  1332. this.each(function() {
  1333. _unbind(this, type, fn);
  1334. });
  1335. return this;
  1336. },
  1337. fire : function(type) {
  1338. if (this.length < 1) {
  1339. return this;
  1340. }
  1341. _fire(this[0], type);
  1342. return this;
  1343. },
  1344. hasAttr : function(key) {
  1345. if (this.length < 1) {
  1346. return false;
  1347. }
  1348. return !!_getAttr(this[0], key);
  1349. },
  1350. attr : function(key, val) {
  1351. var self = this;
  1352. if (key === undefined) {
  1353. return _getAttrList(self.outer());
  1354. }
  1355. if (typeof key === 'object') {
  1356. _each(key, function(k, v) {
  1357. self.attr(k, v);
  1358. });
  1359. return self;
  1360. }
  1361. if (val === undefined) {
  1362. val = self.length < 1 ? null : _getAttr(self[0], key);
  1363. return val === null ? '' : val;
  1364. }
  1365. self.each(function() {
  1366. _setAttr(this, key, val);
  1367. });
  1368. return self;
  1369. },
  1370. removeAttr : function(key) {
  1371. this.each(function() {
  1372. _removeAttr(this, key);
  1373. });
  1374. return this;
  1375. },
  1376. get : function(i) {
  1377. if (this.length < 1) {
  1378. return null;
  1379. }
  1380. return this[i || 0];
  1381. },
  1382. eq : function(i) {
  1383. if (this.length < 1) {
  1384. return null;
  1385. }
  1386. return this[i] ? new KNode(this[i]) : null;
  1387. },
  1388. hasClass : function(cls) {
  1389. if (this.length < 1) {
  1390. return false;
  1391. }
  1392. return _hasClass(this[0], cls);
  1393. },
  1394. addClass : function(cls) {
  1395. this.each(function() {
  1396. if (!_hasClass(this, cls)) {
  1397. this.className = _trim(this.className + ' ' + cls);
  1398. }
  1399. });
  1400. return this;
  1401. },
  1402. removeClass : function(cls) {
  1403. this.each(function() {
  1404. if (_hasClass(this, cls)) {
  1405. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1406. }
  1407. });
  1408. return this;
  1409. },
  1410. html : function(val) {
  1411. var self = this;
  1412. if (val === undefined) {
  1413. if (self.length < 1 || self.type != 1) {
  1414. return '';
  1415. }
  1416. return _formatHtml(self[0].innerHTML);
  1417. }
  1418. self.each(function() {
  1419. _setHtml(this, val);
  1420. });
  1421. return self;
  1422. },
  1423. text : function() {
  1424. var self = this;
  1425. if (self.length < 1) {
  1426. return '';
  1427. }
  1428. return _IE ? self[0].innerText : self[0].textContent;
  1429. },
  1430. hasVal : function() {
  1431. if (this.length < 1) {
  1432. return false;
  1433. }
  1434. return _hasVal(this[0]);
  1435. },
  1436. val : function(val) {
  1437. var self = this;
  1438. if (val === undefined) {
  1439. if (self.length < 1) {
  1440. return '';
  1441. }
  1442. return self.hasVal() ? self[0].value : self.attr('value');
  1443. } else {
  1444. self.each(function() {
  1445. if (_hasVal(this)) {
  1446. this.value = val;
  1447. } else {
  1448. _setAttr(this, 'value' , val);
  1449. }
  1450. });
  1451. return self;
  1452. }
  1453. },
  1454. css : function(key, val) {
  1455. var self = this;
  1456. if (key === undefined) {
  1457. return _getCssList(self.attr('style'));
  1458. }
  1459. if (typeof key === 'object') {
  1460. _each(key, function(k, v) {
  1461. self.css(k, v);
  1462. });
  1463. return self;
  1464. }
  1465. if (val === undefined) {
  1466. if (self.length < 1) {
  1467. return '';
  1468. }
  1469. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1470. }
  1471. self.each(function() {
  1472. this.style[_toCamel(key)] = val;
  1473. });
  1474. return self;
  1475. },
  1476. width : function(val) {
  1477. var self = this;
  1478. if (val === undefined) {
  1479. if (self.length < 1) {
  1480. return 0;
  1481. }
  1482. return self[0].offsetWidth;
  1483. }
  1484. return self.css('width', _addUnit(val));
  1485. },
  1486. height : function(val) {
  1487. var self = this;
  1488. if (val === undefined) {
  1489. if (self.length < 1) {
  1490. return 0;
  1491. }
  1492. return self[0].offsetHeight;
  1493. }
  1494. return self.css('height', _addUnit(val));
  1495. },
  1496. opacity : function(val) {
  1497. this.each(function() {
  1498. if (this.style.opacity === undefined) {
  1499. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1500. } else {
  1501. this.style.opacity = val == 1 ? '' : val;
  1502. }
  1503. });
  1504. return this;
  1505. },
  1506. data : function(key, val) {
  1507. var self = this;
  1508. key = 'kindeditor_data_' + key;
  1509. if (val === undefined) {
  1510. if (self.length < 1) {
  1511. return null;
  1512. }
  1513. return self[0][key];
  1514. }
  1515. this.each(function() {
  1516. this[key] = val;
  1517. });
  1518. return self;
  1519. },
  1520. pos : function() {
  1521. var self = this, node = self[0], x = 0, y = 0;
  1522. if (node) {
  1523. if (node.getBoundingClientRect) {
  1524. var box = node.getBoundingClientRect(),
  1525. pos = _getScrollPos(self.doc);
  1526. x = box.left + pos.x;
  1527. y = box.top + pos.y;
  1528. } else {
  1529. while (node) {
  1530. x += node.offsetLeft;
  1531. y += node.offsetTop;
  1532. node = node.offsetParent;
  1533. }
  1534. }
  1535. }
  1536. return {x : _round(x), y : _round(y)};
  1537. },
  1538. clone : function(bool) {
  1539. if (this.length < 1) {
  1540. return new KNode([]);
  1541. }
  1542. return new KNode(this[0].cloneNode(bool));
  1543. },
  1544. append : function(expr) {
  1545. this.each(function() {
  1546. if (this.appendChild) {
  1547. this.appendChild(_get(expr));
  1548. }
  1549. });
  1550. return this;
  1551. },
  1552. appendTo : function(expr) {
  1553. this.each(function() {
  1554. _get(expr).appendChild(this);
  1555. });
  1556. return this;
  1557. },
  1558. before : function(expr) {
  1559. this.each(function() {
  1560. this.parentNode.insertBefore(_get(expr), this);
  1561. });
  1562. return this;
  1563. },
  1564. after : function(expr) {
  1565. this.each(function() {
  1566. if (this.nextSibling) {
  1567. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1568. } else {
  1569. this.parentNode.appendChild(_get(expr));
  1570. }
  1571. });
  1572. return this;
  1573. },
  1574. replaceWith : function(expr) {
  1575. var nodes = [];
  1576. this.each(function(i, node) {
  1577. _unbind(node);
  1578. var newNode = _get(expr);
  1579. node.parentNode.replaceChild(newNode, node);
  1580. nodes.push(newNode);
  1581. });
  1582. return K(nodes);
  1583. },
  1584. empty : function() {
  1585. var self = this;
  1586. self.each(function(i, node) {
  1587. var child = node.firstChild;
  1588. while (child) {
  1589. if (!node.parentNode) {
  1590. return;
  1591. }
  1592. var next = child.nextSibling;
  1593. child.parentNode.removeChild(child);
  1594. child = next;
  1595. }
  1596. });
  1597. return self;
  1598. },
  1599. remove : function(keepChilds) {
  1600. var self = this;
  1601. self.each(function(i, node) {
  1602. if (!node.parentNode) {
  1603. return;
  1604. }
  1605. _unbind(node);
  1606. if (keepChilds) {
  1607. var child = node.firstChild;
  1608. while (child) {
  1609. var next = child.nextSibling;
  1610. node.parentNode.insertBefore(child, node);
  1611. child = next;
  1612. }
  1613. }
  1614. node.parentNode.removeChild(node);
  1615. delete self[i];
  1616. });
  1617. self.length = 0;
  1618. return self;
  1619. },
  1620. show : function(val) {
  1621. var self = this;
  1622. if (val === undefined) {
  1623. val = self._originDisplay || '';
  1624. }
  1625. if (self.css('display') != 'none') {
  1626. return self;
  1627. }
  1628. return self.css('display', val);
  1629. },
  1630. hide : function() {
  1631. var self = this;
  1632. if (self.length < 1) {
  1633. return self;
  1634. }
  1635. self._originDisplay = self[0].style.display;
  1636. return self.css('display', 'none');
  1637. },
  1638. outer : function() {
  1639. var self = this;
  1640. if (self.length < 1) {
  1641. return '';
  1642. }
  1643. var div = self.doc.createElement('div'), html;
  1644. div.appendChild(self[0].cloneNode(true));
  1645. html = _formatHtml(div.innerHTML);
  1646. div = null;
  1647. return html;
  1648. },
  1649. isSingle : function() {
  1650. return !!_SINGLE_TAG_MAP[this.name];
  1651. },
  1652. isInline : function() {
  1653. return !!_INLINE_TAG_MAP[this.name];
  1654. },
  1655. isBlock : function() {
  1656. return !!_BLOCK_TAG_MAP[this.name];
  1657. },
  1658. isStyle : function() {
  1659. return !!_STYLE_TAG_MAP[this.name];
  1660. },
  1661. isControl : function() {
  1662. return !!_CONTROL_TAG_MAP[this.name];
  1663. },
  1664. contains : function(otherNode) {
  1665. if (this.length < 1) {
  1666. return false;
  1667. }
  1668. return _contains(this[0], _get(otherNode));
  1669. },
  1670. parent : function() {
  1671. if (this.length < 1) {
  1672. return null;
  1673. }
  1674. var node = this[0].parentNode;
  1675. return node ? new KNode(node) : null;
  1676. },
  1677. children : function() {
  1678. if (this.length < 1) {
  1679. return new KNode([]);
  1680. }
  1681. var list = [], child = this[0].firstChild;
  1682. while (child) {
  1683. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1684. list.push(child);
  1685. }
  1686. child = child.nextSibling;
  1687. }
  1688. return new KNode(list);
  1689. },
  1690. first : function() {
  1691. var list = this.children();
  1692. return list.length > 0 ? list.eq(0) : null;
  1693. },
  1694. last : function() {
  1695. var list = this.children();
  1696. return list.length > 0 ? list.eq(list.length - 1) : null;
  1697. },
  1698. index : function() {
  1699. if (this.length < 1) {
  1700. return -1;
  1701. }
  1702. var i = -1, sibling = this[0];
  1703. while (sibling) {
  1704. i++;
  1705. sibling = sibling.previousSibling;
  1706. }
  1707. return i;
  1708. },
  1709. prev : function() {
  1710. if (this.length < 1) {
  1711. return null;
  1712. }
  1713. var node = this[0].previousSibling;
  1714. return node ? new KNode(node) : null;
  1715. },
  1716. next : function() {
  1717. if (this.length < 1) {
  1718. return null;
  1719. }
  1720. var node = this[0].nextSibling;
  1721. return node ? new KNode(node) : null;
  1722. },
  1723. scan : function(fn, order) {
  1724. if (this.length < 1) {
  1725. return;
  1726. }
  1727. order = (order === undefined) ? true : order;
  1728. function walk(node) {
  1729. var n = order ? node.firstChild : node.lastChild;
  1730. while (n) {
  1731. var next = order ? n.nextSibling : n.previousSibling;
  1732. if (fn(n) === false) {
  1733. return false;
  1734. }
  1735. if (walk(n) === false) {
  1736. return false;
  1737. }
  1738. n = next;
  1739. }
  1740. }
  1741. walk(this[0]);
  1742. return this;
  1743. }
  1744. });
  1745. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1746. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1747. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1748. KNode.prototype[type] = function(fn) {
  1749. return fn ? this.bind(type, fn) : this.fire(type);
  1750. };
  1751. });
  1752. var _K = K;
  1753. K = function(expr, root) {
  1754. if (expr === undefined || expr === null) {
  1755. return;
  1756. }
  1757. function newNode(node) {
  1758. if (!node[0]) {
  1759. node = [];
  1760. }
  1761. return new KNode(node);
  1762. }
  1763. if (typeof expr === 'string') {
  1764. if (root) {
  1765. root = _get(root);
  1766. }
  1767. var length = expr.length;
  1768. if (expr.charAt(0) === '@') {
  1769. expr = expr.substr(1);
  1770. }
  1771. if (expr.length !== length || /<.+>/.test(expr)) {
  1772. var doc = root ? root.ownerDocument || root : document,
  1773. div = doc.createElement('div'), list = [];
  1774. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1775. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1776. var child = div.childNodes[i];
  1777. if (child.id == '__kindeditor_temp_tag__') {
  1778. continue;
  1779. }
  1780. list.push(child);
  1781. }
  1782. return newNode(list);
  1783. }
  1784. return newNode(_queryAll(expr, root));
  1785. }
  1786. if (expr && expr.constructor === KNode) {
  1787. return expr;
  1788. }
  1789. if (expr.toArray) {
  1790. expr = expr.toArray();
  1791. }
  1792. if (_isArray(expr)) {
  1793. return newNode(expr);
  1794. }
  1795. return newNode(_toArray(arguments));
  1796. };
  1797. _each(_K, function(key, val) {
  1798. K[key] = val;
  1799. });
  1800. K.NodeClass = KNode;
  1801. window.KindEditor = K;
  1802. var _START_TO_START = 0,
  1803. _START_TO_END = 1,
  1804. _END_TO_END = 2,
  1805. _END_TO_START = 3,
  1806. _BOOKMARK_ID = 0;
  1807. function _updateCollapsed(range) {
  1808. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1809. return range;
  1810. }
  1811. function _copyAndDelete(range, isCopy, isDelete) {
  1812. var doc = range.doc, nodeList = [];
  1813. function splitTextNode(node, startOffset, endOffset) {
  1814. var length = node.nodeValue.length, centerNode;
  1815. if (isCopy) {
  1816. var cloneNode = node.cloneNode(true);
  1817. if (startOffset > 0) {
  1818. centerNode = cloneNode.splitText(startOffset);
  1819. } else {
  1820. centerNode = cloneNode;
  1821. }
  1822. if (endOffset < length) {
  1823. centerNode.splitText(endOffset - startOffset);
  1824. }
  1825. }
  1826. if (isDelete) {
  1827. var center = node;
  1828. if (startOffset > 0) {
  1829. center = node.splitText(startOffset);
  1830. range.setStart(node, startOffset);
  1831. }
  1832. if (endOffset < length) {
  1833. var right = center.splitText(endOffset - startOffset);
  1834. range.setEnd(right, 0);
  1835. }
  1836. nodeList.push(center);
  1837. }
  1838. return centerNode;
  1839. }
  1840. function removeNodes() {
  1841. if (isDelete) {
  1842. range.up().collapse(true);
  1843. }
  1844. for (var i = 0, len = nodeList.length; i < len; i++) {
  1845. var node = nodeList[i];
  1846. if (node.parentNode) {
  1847. node.parentNode.removeChild(node);
  1848. }
  1849. }
  1850. }
  1851. var copyRange = range.cloneRange().down();
  1852. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1853. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1854. if (ancestor.nodeType == 3) {
  1855. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1856. if (isCopy) {
  1857. frag.appendChild(textNode);
  1858. }
  1859. removeNodes();
  1860. return isCopy ? frag : range;
  1861. }
  1862. function extractNodes(parent, frag) {
  1863. var node = parent.firstChild, nextNode;
  1864. while (node) {
  1865. var testRange = new KRange(doc).selectNode(node);
  1866. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1867. if (start >= 0 && incStart <= 0) {
  1868. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1869. }
  1870. if (incStart >= 0 && incEnd <= 0) {
  1871. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1872. }
  1873. if (incEnd >= 0 && end <= 0) {
  1874. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1875. }
  1876. if (end >= 0) {
  1877. return false;
  1878. }
  1879. nextNode = node.nextSibling;
  1880. if (start > 0) {
  1881. if (node.nodeType == 1) {
  1882. if (incStart >= 0 && incEnd <= 0) {
  1883. if (isCopy) {
  1884. frag.appendChild(node.cloneNode(true));
  1885. }
  1886. if (isDelete) {
  1887. nodeList.push(node);
  1888. }
  1889. } else {
  1890. var childFlag;
  1891. if (isCopy) {
  1892. childFlag = node.cloneNode(false);
  1893. frag.appendChild(childFlag);
  1894. }
  1895. if (extractNodes(node, childFlag) === false) {
  1896. return false;
  1897. }
  1898. }
  1899. } else if (node.nodeType == 3) {
  1900. var textNode;
  1901. if (node == copyRange.startContainer) {
  1902. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1903. } else if (node == copyRange.endContainer) {
  1904. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1905. } else {
  1906. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1907. }
  1908. if (isCopy) {
  1909. try {
  1910. frag.appendChild(textNode);
  1911. } catch(e) {}
  1912. }
  1913. }
  1914. }
  1915. node = nextNode;
  1916. }
  1917. }
  1918. extractNodes(ancestor, frag);
  1919. if (isDelete) {
  1920. range.up().collapse(true);
  1921. }
  1922. for (var i = 0, len = nodeList.length; i < len; i++) {
  1923. var node = nodeList[i];
  1924. if (node.parentNode) {
  1925. node.parentNode.removeChild(node);
  1926. }
  1927. }
  1928. return isCopy ? frag : range;
  1929. }
  1930. function _moveToElementText(range, el) {
  1931. var node = el;
  1932. while (node) {
  1933. var knode = K(node);
  1934. if (knode.name == 'marquee' || knode.name == 'select') {
  1935. return;
  1936. }
  1937. node = node.parentNode;
  1938. }
  1939. try {
  1940. range.moveToElementText(el);
  1941. } catch(e) {}
  1942. }
  1943. function _getStartEnd(rng, isStart) {
  1944. var doc = rng.parentElement().ownerDocument,
  1945. pointRange = rng.duplicate();
  1946. pointRange.collapse(isStart);
  1947. var parent = pointRange.parentElement(),
  1948. nodes = parent.childNodes;
  1949. if (nodes.length === 0) {
  1950. return {node: parent.parentNode, offset: K(parent).index()};
  1951. }
  1952. var startNode = doc, startPos = 0, cmp = -1;
  1953. var testRange = rng.duplicate();
  1954. _moveToElementText(testRange, parent);
  1955. for (var i = 0, len = nodes.length; i < len; i++) {
  1956. var node = nodes[i];
  1957. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1958. if (cmp === 0) {
  1959. return {node: node.parentNode, offset: i};
  1960. }
  1961. if (node.nodeType == 1) {
  1962. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1963. if (knode.isControl()) {
  1964. dummy = doc.createElement('span');
  1965. knode.after(dummy);
  1966. newNode = dummy;
  1967. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1968. }
  1969. _moveToElementText(nodeRange, newNode);
  1970. testRange.setEndPoint('StartToEnd', nodeRange);
  1971. if (cmp > 0) {
  1972. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1973. } else {
  1974. startPos = 0;
  1975. }
  1976. if (dummy) {
  1977. K(dummy).remove();
  1978. }
  1979. } else if (node.nodeType == 3) {
  1980. testRange.moveStart('character', node.nodeValue.length);
  1981. startPos += node.nodeValue.length;
  1982. }
  1983. if (cmp < 0) {
  1984. startNode = node;
  1985. }
  1986. }
  1987. if (cmp < 0 && startNode.nodeType == 1) {
  1988. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1989. }
  1990. if (cmp > 0) {
  1991. while (startNode.nextSibling && startNode.nodeType == 1) {
  1992. startNode = startNode.nextSibling;
  1993. }
  1994. }
  1995. testRange = rng.duplicate();
  1996. _moveToElementText(testRange, parent);
  1997. testRange.setEndPoint('StartToEnd', pointRange);
  1998. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1999. if (cmp > 0 && startNode.nodeType == 3) {
  2000. var prevNode = startNode.previousSibling;
  2001. while (prevNode && prevNode.nodeType == 3) {
  2002. startPos -= prevNode.nodeValue.length;
  2003. prevNode = prevNode.previousSibling;
  2004. }
  2005. }
  2006. return {node: startNode, offset: startPos};
  2007. }
  2008. function _getEndRange(node, offset) {
  2009. var doc = node.ownerDocument || node,
  2010. range = doc.body.createTextRange();
  2011. if (doc == node) {
  2012. range.collapse(true);
  2013. return range;
  2014. }
  2015. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2016. var children = node.childNodes, isStart, child;
  2017. if (offset === 0) {
  2018. child = children[0];
  2019. isStart = true;
  2020. } else {
  2021. child = children[offset - 1];
  2022. isStart = false;
  2023. }
  2024. if (!child) {
  2025. return range;
  2026. }
  2027. if (K(child).name === 'head') {
  2028. if (offset === 1) {
  2029. isStart = true;
  2030. }
  2031. if (offset === 2) {
  2032. isStart = false;
  2033. }
  2034. range.collapse(isStart);
  2035. return range;
  2036. }
  2037. if (child.nodeType == 1) {
  2038. var kchild = K(child), span;
  2039. if (kchild.isControl()) {
  2040. span = doc.createElement('span');
  2041. if (isStart) {
  2042. kchild.before(span);
  2043. } else {
  2044. kchild.after(span);
  2045. }
  2046. child = span;
  2047. }
  2048. _moveToElementText(range, child);
  2049. range.collapse(isStart);
  2050. if (span) {
  2051. K(span).remove();
  2052. }
  2053. return range;
  2054. }
  2055. node = child;
  2056. offset = isStart ? 0 : child.nodeValue.length;
  2057. }
  2058. var dummy = doc.createElement('span');
  2059. K(node).before(dummy);
  2060. _moveToElementText(range, dummy);
  2061. range.moveStart('character', offset);
  2062. K(dummy).remove();
  2063. return range;
  2064. }
  2065. function _toRange(rng) {
  2066. var doc, range;
  2067. function tr2td(start) {
  2068. if (K(start.node).name == 'tr') {
  2069. start.node = start.node.cells[start.offset];
  2070. start.offset = 0;
  2071. }
  2072. }
  2073. if (_IERANGE) {
  2074. if (rng.item) {
  2075. doc = _getDoc(rng.item(0));
  2076. range = new KRange(doc);
  2077. range.selectNode(rng.item(0));
  2078. return range;
  2079. }
  2080. doc = rng.parentElement().ownerDocument;
  2081. var start = _getStartEnd(rng, true),
  2082. end = _getStartEnd(rng, false);
  2083. tr2td(start);
  2084. tr2td(end);
  2085. range = new KRange(doc);
  2086. range.setStart(start.node, start.offset);
  2087. range.setEnd(end.node, end.offset);
  2088. return range;
  2089. }
  2090. var startContainer = rng.startContainer;
  2091. doc = startContainer.ownerDocument || startContainer;
  2092. range = new KRange(doc);
  2093. range.setStart(startContainer, rng.startOffset);
  2094. range.setEnd(rng.endContainer, rng.endOffset);
  2095. return range;
  2096. }
  2097. function KRange(doc) {
  2098. this.init(doc);
  2099. }
  2100. _extend(KRange, {
  2101. init : function(doc) {
  2102. var self = this;
  2103. self.startContainer = doc;
  2104. self.startOffset = 0;
  2105. self.endContainer = doc;
  2106. self.endOffset = 0;
  2107. self.collapsed = true;
  2108. self.doc = doc;
  2109. },
  2110. commonAncestor : function() {
  2111. function getParents(node) {
  2112. var parents = [];
  2113. while (node) {
  2114. parents.push(node);
  2115. node = node.parentNode;
  2116. }
  2117. return parents;
  2118. }
  2119. var parentsA = getParents(this.startContainer),
  2120. parentsB = getParents(this.endContainer),
  2121. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2122. while (++i) {
  2123. parentA = parentsA[lenA - i];
  2124. parentB = parentsB[lenB - i];
  2125. if (!parentA || !parentB || parentA !== parentB) {
  2126. break;
  2127. }
  2128. }
  2129. return parentsA[lenA - i + 1];
  2130. },
  2131. setStart : function(node, offset) {
  2132. var self = this, doc = self.doc;
  2133. self.startContainer = node;
  2134. self.startOffset = offset;
  2135. if (self.endContainer === doc) {
  2136. self.endContainer = node;
  2137. self.endOffset = offset;
  2138. }
  2139. return _updateCollapsed(this);
  2140. },
  2141. setEnd : function(node, offset) {
  2142. var self = this, doc = self.doc;
  2143. self.endContainer = node;
  2144. self.endOffset = offset;
  2145. if (self.startContainer === doc) {
  2146. self.startContainer = node;
  2147. self.startOffset = offset;
  2148. }
  2149. return _updateCollapsed(this);
  2150. },
  2151. setStartBefore : function(node) {
  2152. return this.setStart(node.parentNode || this.doc, K(node).index());
  2153. },
  2154. setStartAfter : function(node) {
  2155. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2156. },
  2157. setEndBefore : function(node) {
  2158. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2159. },
  2160. setEndAfter : function(node) {
  2161. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2162. },
  2163. selectNode : function(node) {
  2164. return this.setStartBefore(node).setEndAfter(node);
  2165. },
  2166. selectNodeContents : function(node) {
  2167. var knode = K(node);
  2168. if (knode.type == 3 || knode.isSingle()) {
  2169. return this.selectNode(node);
  2170. }
  2171. var children = knode.children();
  2172. if (children.length > 0) {
  2173. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2174. }
  2175. return this.setStart(node, 0).setEnd(node, 0);
  2176. },
  2177. collapse : function(toStart) {
  2178. if (toStart) {
  2179. return this.setEnd(this.startContainer, this.startOffset);
  2180. }
  2181. return this.setStart(this.endContainer, this.endOffset);
  2182. },
  2183. compareBoundaryPoints : function(how, range) {
  2184. var rangeA = this.get(), rangeB = range.get();
  2185. if (_IERANGE) {
  2186. var arr = {};
  2187. arr[_START_TO_START] = 'StartToStart';
  2188. arr[_START_TO_END] = 'EndToStart';
  2189. arr[_END_TO_END] = 'EndToEnd';
  2190. arr[_END_TO_START] = 'StartToEnd';
  2191. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2192. if (cmp !== 0) {
  2193. return cmp;
  2194. }
  2195. var nodeA, nodeB, nodeC, posA, posB;
  2196. if (how === _START_TO_START || how === _END_TO_START) {
  2197. nodeA = this.startContainer;
  2198. posA = this.startOffset;
  2199. }
  2200. if (how === _START_TO_END || how === _END_TO_END) {
  2201. nodeA = this.endContainer;
  2202. posA = this.endOffset;
  2203. }
  2204. if (how === _START_TO_START || how === _START_TO_END) {
  2205. nodeB = range.startContainer;
  2206. posB = range.startOffset;
  2207. }
  2208. if (how === _END_TO_END || how === _END_TO_START) {
  2209. nodeB = range.endContainer;
  2210. posB = range.endOffset;
  2211. }
  2212. if (nodeA === nodeB) {
  2213. var diff = posA - posB;
  2214. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2215. }
  2216. nodeC = nodeB;
  2217. while (nodeC && nodeC.parentNode !== nodeA) {
  2218. nodeC = nodeC.parentNode;
  2219. }
  2220. if (nodeC) {
  2221. return K(nodeC).index() >= posA ? -1 : 1;
  2222. }
  2223. nodeC = nodeA;
  2224. while (nodeC && nodeC.parentNode !== nodeB) {
  2225. nodeC = nodeC.parentNode;
  2226. }
  2227. if (nodeC) {
  2228. return K(nodeC).index() >= posB ? 1 : -1;
  2229. }
  2230. nodeC = K(nodeB).next();
  2231. if (nodeC && nodeC.contains(nodeA)) {
  2232. return 1;
  2233. }
  2234. nodeC = K(nodeA).next();
  2235. if (nodeC && nodeC.contains(nodeB)) {
  2236. return -1;
  2237. }
  2238. } else {
  2239. return rangeA.compareBoundaryPoints(how, rangeB);
  2240. }
  2241. },
  2242. cloneRange : function() {
  2243. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2244. },
  2245. toString : function() {
  2246. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2247. return str.replace(/\r\n|\n|\r/g, '');
  2248. },
  2249. cloneContents : function() {
  2250. return _copyAndDelete(this, true, false);
  2251. },
  2252. deleteContents : function() {
  2253. return _copyAndDelete(this, false, true);
  2254. },
  2255. extractContents : function() {
  2256. return _copyAndDelete(this, true, true);
  2257. },
  2258. insertNode : function(node) {
  2259. var self = this,
  2260. sc = self.startContainer, so = self.startOffset,
  2261. ec = self.endContainer, eo = self.endOffset,
  2262. firstChild, lastChild, c, nodeCount = 1;
  2263. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2264. firstChild = node.firstChild;
  2265. lastChild = node.lastChild;
  2266. nodeCount = node.childNodes.length;
  2267. }
  2268. if (sc.nodeType == 1) {
  2269. c = sc.childNodes[so];
  2270. if (c) {
  2271. sc.insertBefore(node, c);
  2272. if (sc === ec) {
  2273. eo += nodeCount;
  2274. }
  2275. } else {
  2276. sc.appendChild(node);
  2277. }
  2278. } else if (sc.nodeType == 3) {
  2279. if (so === 0) {
  2280. sc.parentNode.insertBefore(node, sc);
  2281. if (sc.parentNode === ec) {
  2282. eo += nodeCount;
  2283. }
  2284. } else if (so >= sc.nodeValue.length) {
  2285. if (sc.nextSibling) {
  2286. sc.parentNode.insertBefore(node, sc.nextSibling);
  2287. } else {
  2288. sc.parentNode.appendChild(node);
  2289. }
  2290. } else {
  2291. if (so > 0) {
  2292. c = sc.splitText(so);
  2293. } else {
  2294. c = sc;
  2295. }
  2296. sc.parentNode.insertBefore(node, c);
  2297. if (sc === ec) {
  2298. ec = c;
  2299. eo -= so;
  2300. }
  2301. }
  2302. }
  2303. if (firstChild) {
  2304. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2305. } else {
  2306. self.selectNode(node);
  2307. }
  2308. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2309. return self;
  2310. }
  2311. return self.setEnd(ec, eo);
  2312. },
  2313. surroundContents : function(node) {
  2314. node.appendChild(this.extractContents());
  2315. return this.insertNode(node).selectNode(node);
  2316. },
  2317. isControl : function() {
  2318. var self = this,
  2319. sc = self.startContainer, so = self.startOffset,
  2320. ec = self.endContainer, eo = self.endOffset, rng;
  2321. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2322. },
  2323. get : function(hasControlRange) {
  2324. var self = this, doc = self.doc, node, rng;
  2325. if (!_IERANGE) {
  2326. rng = doc.createRange();
  2327. try {
  2328. rng.setStart(self.startContainer, self.startOffset);
  2329. rng.setEnd(self.endContainer, self.endOffset);
  2330. } catch (e) {}
  2331. return rng;
  2332. }
  2333. if (hasControlRange && self.isControl()) {
  2334. rng = doc.body.createControlRange();
  2335. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2336. return rng;
  2337. }
  2338. var range = self.cloneRange().down();
  2339. rng = doc.body.createTextRange();
  2340. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2341. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2342. return rng;
  2343. },
  2344. html : function() {
  2345. return K(this.cloneContents()).outer();
  2346. },
  2347. down : function() {
  2348. var self = this;
  2349. function downPos(node, pos, isStart) {
  2350. if (node.nodeType != 1) {
  2351. return;
  2352. }
  2353. var children = K(node).children();
  2354. if (children.length === 0) {
  2355. return;
  2356. }
  2357. var left, right, child, offset;
  2358. if (pos > 0) {
  2359. left = children.eq(pos - 1);
  2360. }
  2361. if (pos < children.length) {
  2362. right = children.eq(pos);
  2363. }
  2364. if (left && left.type == 3) {
  2365. child = left[0];
  2366. offset = child.nodeValue.length;
  2367. }
  2368. if (right && right.type == 3) {
  2369. child = right[0];
  2370. offset = 0;
  2371. }
  2372. if (!child) {
  2373. return;
  2374. }
  2375. if (isStart) {
  2376. self.setStart(child, offset);
  2377. } else {
  2378. self.setEnd(child, offset);
  2379. }
  2380. }
  2381. downPos(self.startContainer, self.startOffset, true);
  2382. downPos(self.endContainer, self.endOffset, false);
  2383. return self;
  2384. },
  2385. up : function() {
  2386. var self = this;
  2387. function upPos(node, pos, isStart) {
  2388. if (node.nodeType != 3) {
  2389. return;
  2390. }
  2391. if (pos === 0) {
  2392. if (isStart) {
  2393. self.setStartBefore(node);
  2394. } else {
  2395. self.setEndBefore(node);
  2396. }
  2397. } else if (pos == node.nodeValue.length) {
  2398. if (isStart) {
  2399. self.setStartAfter(node);
  2400. } else {
  2401. self.setEndAfter(node);
  2402. }
  2403. }
  2404. }
  2405. upPos(self.startContainer, self.startOffset, true);
  2406. upPos(self.endContainer, self.endOffset, false);
  2407. return self;
  2408. },
  2409. enlarge : function(toBlock) {
  2410. var self = this;
  2411. self.up();
  2412. function enlargePos(node, pos, isStart) {
  2413. var knode = K(node), parent;
  2414. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2415. return;
  2416. }
  2417. if (pos === 0) {
  2418. while (!knode.prev()) {
  2419. parent = knode.parent();
  2420. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2421. break;
  2422. }
  2423. knode = parent;
  2424. }
  2425. if (isStart) {
  2426. self.setStartBefore(knode[0]);
  2427. } else {
  2428. self.setEndBefore(knode[0]);
  2429. }
  2430. } else if (pos == knode.children().length) {
  2431. while (!knode.next()) {
  2432. parent = knode.parent();
  2433. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2434. break;
  2435. }
  2436. knode = parent;
  2437. }
  2438. if (isStart) {
  2439. self.setStartAfter(knode[0]);
  2440. } else {
  2441. self.setEndAfter(knode[0]);
  2442. }
  2443. }
  2444. }
  2445. enlargePos(self.startContainer, self.startOffset, true);
  2446. enlargePos(self.endContainer, self.endOffset, false);
  2447. return self;
  2448. },
  2449. shrink : function() {
  2450. var self = this, child, collapsed = self.collapsed;
  2451. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2452. self.setStart(child, 0);
  2453. }
  2454. if (collapsed) {
  2455. return self.collapse(collapsed);
  2456. }
  2457. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2458. self.setEnd(child, child.childNodes.length);
  2459. }
  2460. return self;
  2461. },
  2462. createBookmark : function(serialize) {
  2463. var self = this, doc = self.doc, endNode,
  2464. startNode = K('<span style="display:none;"></span>', doc)[0];
  2465. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2466. if (!self.collapsed) {
  2467. endNode = startNode.cloneNode(true);
  2468. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2469. }
  2470. if (endNode) {
  2471. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2472. }
  2473. self.insertNode(startNode).setStartAfter(startNode);
  2474. return {
  2475. start : serialize ? '#' + startNode.id : startNode,
  2476. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2477. };
  2478. },
  2479. moveToBookmark : function(bookmark) {
  2480. var self = this, doc = self.doc,
  2481. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2482. if (!start || start.length < 1) {
  2483. return self;
  2484. }
  2485. self.setStartBefore(start[0]);
  2486. start.remove();
  2487. if (end && end.length > 0) {
  2488. self.setEndBefore(end[0]);
  2489. end.remove();
  2490. } else {
  2491. self.collapse(true);
  2492. }
  2493. return self;
  2494. },
  2495. dump : function() {
  2496. console.log('--------------------');
  2497. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2498. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2499. }
  2500. });
  2501. function _range(mixed) {
  2502. if (!mixed.nodeName) {
  2503. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2504. }
  2505. return new KRange(mixed);
  2506. }
  2507. K.RangeClass = KRange;
  2508. K.range = _range;
  2509. K.START_TO_START = _START_TO_START;
  2510. K.START_TO_END = _START_TO_END;
  2511. K.END_TO_END = _END_TO_END;
  2512. K.END_TO_START = _END_TO_START;
  2513. function _nativeCommand(doc, key, val) {
  2514. try {
  2515. doc.execCommand(key, false, val);
  2516. } catch(e) {}
  2517. }
  2518. function _nativeCommandValue(doc, key) {
  2519. var val = '';
  2520. try {
  2521. val = doc.queryCommandValue(key);
  2522. } catch (e) {}
  2523. if (typeof val !== 'string') {
  2524. val = '';
  2525. }
  2526. return val;
  2527. }
  2528. function _getSel(doc) {
  2529. var win = _getWin(doc);
  2530. return _IERANGE ? doc.selection : win.getSelection();
  2531. }
  2532. function _getRng(doc) {
  2533. var sel = _getSel(doc), rng;
  2534. try {
  2535. if (sel.rangeCount > 0) {
  2536. rng = sel.getRangeAt(0);
  2537. } else {
  2538. rng = sel.createRange();
  2539. }
  2540. } catch(e) {}
  2541. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2542. return null;
  2543. }
  2544. return rng;
  2545. }
  2546. function _singleKeyMap(map) {
  2547. var newMap = {}, arr, v;
  2548. _each(map, function(key, val) {
  2549. arr = key.split(',');
  2550. for (var i = 0, len = arr.length; i < len; i++) {
  2551. v = arr[i];
  2552. newMap[v] = val;
  2553. }
  2554. });
  2555. return newMap;
  2556. }
  2557. function _hasAttrOrCss(knode, map) {
  2558. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2559. }
  2560. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2561. mapKey = mapKey || knode.name;
  2562. if (knode.type !== 1) {
  2563. return false;
  2564. }
  2565. var newMap = _singleKeyMap(map);
  2566. if (!newMap[mapKey]) {
  2567. return false;
  2568. }
  2569. var arr = newMap[mapKey].split(',');
  2570. for (var i = 0, len = arr.length; i < len; i++) {
  2571. var key = arr[i];
  2572. if (key === '*') {
  2573. return true;
  2574. }
  2575. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2576. var method = match[1] ? 'css' : 'attr';
  2577. key = match[2];
  2578. var val = match[3] || '';
  2579. if (val === '' && knode[method](key) !== '') {
  2580. return true;
  2581. }
  2582. if (val !== '' && knode[method](key) === val) {
  2583. return true;
  2584. }
  2585. }
  2586. return false;
  2587. }
  2588. function _removeAttrOrCss(knode, map) {
  2589. if (knode.type != 1) {
  2590. return;
  2591. }
  2592. _removeAttrOrCssByKey(knode, map, '*');
  2593. _removeAttrOrCssByKey(knode, map);
  2594. }
  2595. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2596. mapKey = mapKey || knode.name;
  2597. if (knode.type !== 1) {
  2598. return;
  2599. }
  2600. var newMap = _singleKeyMap(map);
  2601. if (!newMap[mapKey]) {
  2602. return;
  2603. }
  2604. var arr = newMap[mapKey].split(','), allFlag = false;
  2605. for (var i = 0, len = arr.length; i < len; i++) {
  2606. var key = arr[i];
  2607. if (key === '*') {
  2608. allFlag = true;
  2609. break;
  2610. }
  2611. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2612. key = match[2];
  2613. if (match[1]) {
  2614. key = _toCamel(key);
  2615. if (knode[0].style[key]) {
  2616. knode[0].style[key] = '';
  2617. }
  2618. } else {
  2619. knode.removeAttr(key);
  2620. }
  2621. }
  2622. if (allFlag) {
  2623. knode.remove(true);
  2624. }
  2625. }
  2626. function _getInnerNode(knode) {
  2627. var inner = knode;
  2628. while (inner.first()) {
  2629. inner = inner.first();
  2630. }
  2631. return inner;
  2632. }
  2633. function _isEmptyNode(knode) {
  2634. if (knode.type != 1 || knode.isSingle()) {
  2635. return false;
  2636. }
  2637. return knode.html().replace(/<[^>]+>/g, '') === '';
  2638. }
  2639. function _mergeWrapper(a, b) {
  2640. a = a.clone(true);
  2641. var lastA = _getInnerNode(a), childA = a, merged = false;
  2642. while (b) {
  2643. while (childA) {
  2644. if (childA.name === b.name) {
  2645. _mergeAttrs(childA, b.attr(), b.css());
  2646. merged = true;
  2647. }
  2648. childA = childA.first();
  2649. }
  2650. if (!merged) {
  2651. lastA.append(b.clone(false));
  2652. }
  2653. merged = false;
  2654. b = b.first();
  2655. }
  2656. return a;
  2657. }
  2658. function _wrapNode(knode, wrapper) {
  2659. wrapper = wrapper.clone(true);
  2660. if (knode.type == 3) {
  2661. _getInnerNode(wrapper).append(knode.clone(false));
  2662. knode.replaceWith(wrapper);
  2663. return wrapper;
  2664. }
  2665. var nodeWrapper = knode, child;
  2666. while ((child = knode.first()) && child.children().length == 1) {
  2667. knode = child;
  2668. }
  2669. child = knode.first();
  2670. var frag = knode.doc.createDocumentFragment();
  2671. while (child) {
  2672. frag.appendChild(child[0]);
  2673. child = child.next();
  2674. }
  2675. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2676. if (frag.firstChild) {
  2677. _getInnerNode(wrapper).append(frag);
  2678. }
  2679. nodeWrapper.replaceWith(wrapper);
  2680. return wrapper;
  2681. }
  2682. function _mergeAttrs(knode, attrs, styles) {
  2683. _each(attrs, function(key, val) {
  2684. if (key !== 'style') {
  2685. knode.attr(key, val);
  2686. }
  2687. });
  2688. _each(styles, function(key, val) {
  2689. knode.css(key, val);
  2690. });
  2691. }
  2692. function _inPreElement(knode) {
  2693. while (knode && knode.name != 'body') {
  2694. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2695. return true;
  2696. }
  2697. knode = knode.parent();
  2698. }
  2699. return false;
  2700. }
  2701. function KCmd(range) {
  2702. this.init(range);
  2703. }
  2704. _extend(KCmd, {
  2705. init : function(range) {
  2706. var self = this, doc = range.doc;
  2707. self.doc = doc;
  2708. self.win = _getWin(doc);
  2709. self.sel = _getSel(doc);
  2710. self.range = range;
  2711. },
  2712. selection : function(forceReset) {
  2713. var self = this, doc = self.doc, rng = _getRng(doc);
  2714. self.sel = _getSel(doc);
  2715. if (rng) {
  2716. self.range = _range(rng);
  2717. if (K(self.range.startContainer).name == 'html') {
  2718. self.range.selectNodeContents(doc.body).collapse(false);
  2719. }
  2720. return self;
  2721. }
  2722. if (forceReset) {
  2723. self.range.selectNodeContents(doc.body).collapse(false);
  2724. }
  2725. return self;
  2726. },
  2727. select : function(hasDummy) {
  2728. hasDummy = _undef(hasDummy, true);
  2729. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2730. sc = range.startContainer, so = range.startOffset,
  2731. ec = range.endContainer, eo = range.endOffset,
  2732. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2733. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2734. if (_IERANGE) {
  2735. var dummy = K('<span>&nbsp;</span>', doc);
  2736. range.insertNode(dummy[0]);
  2737. rng = doc.body.createTextRange();
  2738. try {
  2739. rng.moveToElementText(dummy[0]);
  2740. } catch(ex) {}
  2741. rng.collapse(false);
  2742. rng.select();
  2743. dummy.remove();
  2744. win.focus();
  2745. return self;
  2746. }
  2747. if (_WEBKIT) {
  2748. var children = sc.childNodes;
  2749. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2750. range.insertNode(doc.createTextNode('\u200B'));
  2751. hasU200b = true;
  2752. }
  2753. }
  2754. }
  2755. if (_IERANGE) {
  2756. try {
  2757. rng = range.get(true);
  2758. rng.select();
  2759. } catch(e) {}
  2760. } else {
  2761. if (hasU200b) {
  2762. range.collapse(false);
  2763. }
  2764. rng = range.get(true);
  2765. sel.removeAllRanges();
  2766. sel.addRange(rng);
  2767. if (doc !== document) {
  2768. var pos = K(rng.endContainer).pos();
  2769. win.scrollTo(pos.x, pos.y);
  2770. }
  2771. }
  2772. win.focus();
  2773. return self;
  2774. },
  2775. wrap : function(val) {
  2776. var self = this, doc = self.doc, range = self.range, wrapper;
  2777. wrapper = K(val, doc);
  2778. if (range.collapsed) {
  2779. range.shrink();
  2780. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2781. return self;
  2782. }
  2783. if (wrapper.isBlock()) {
  2784. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2785. while (child.first()) {
  2786. child = child.first();
  2787. }
  2788. child.append(range.extractContents());
  2789. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2790. return self;
  2791. }
  2792. range.enlarge();
  2793. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2794. K(ancestor).scan(function(node) {
  2795. if (!isStart && node == bookmark.start) {
  2796. isStart = true;
  2797. return;
  2798. }
  2799. if (isStart) {
  2800. if (node == bookmark.end) {
  2801. return false;
  2802. }
  2803. var knode = K(node);
  2804. if (_inPreElement(knode)) {
  2805. return;
  2806. }
  2807. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2808. var parent;
  2809. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2810. knode = parent;
  2811. }
  2812. _wrapNode(knode, wrapper);
  2813. }
  2814. }
  2815. });
  2816. range.moveToBookmark(bookmark);
  2817. return self;
  2818. },
  2819. split : function(isStart, map) {
  2820. var range = this.range, doc = range.doc;
  2821. var tempRange = range.cloneRange().collapse(isStart);
  2822. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2823. parent = node.nodeType == 3 ? node.parentNode : node,
  2824. needSplit = false, knode;
  2825. while (parent && parent.parentNode) {
  2826. knode = K(parent);
  2827. if (map) {
  2828. if (!knode.isStyle()) {
  2829. break;
  2830. }
  2831. if (!_hasAttrOrCss(knode, map)) {
  2832. break;
  2833. }
  2834. } else {
  2835. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2836. break;
  2837. }
  2838. }
  2839. needSplit = true;
  2840. parent = parent.parentNode;
  2841. }
  2842. if (needSplit) {
  2843. var dummy = doc.createElement('span');
  2844. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2845. if (isStart) {
  2846. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2847. } else {
  2848. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2849. }
  2850. var frag = tempRange.extractContents(),
  2851. first = frag.firstChild, last = frag.lastChild;
  2852. if (isStart) {
  2853. tempRange.insertNode(frag);
  2854. range.setStartAfter(last).setEndBefore(dummy);
  2855. } else {
  2856. parent.appendChild(frag);
  2857. range.setStartBefore(dummy).setEndBefore(first);
  2858. }
  2859. var dummyParent = dummy.parentNode;
  2860. if (dummyParent == range.endContainer) {
  2861. var prev = K(dummy).prev(), next = K(dummy).next();
  2862. if (prev && next && prev.type == 3 && next.type == 3) {
  2863. range.setEnd(prev[0], prev[0].nodeValue.length);
  2864. } else if (!isStart) {
  2865. range.setEnd(range.endContainer, range.endOffset - 1);
  2866. }
  2867. }
  2868. dummyParent.removeChild(dummy);
  2869. }
  2870. return this;
  2871. },
  2872. remove : function(map) {
  2873. var self = this, doc = self.doc, range = self.range;
  2874. range.enlarge();
  2875. if (range.startOffset === 0) {
  2876. var ksc = K(range.startContainer), parent;
  2877. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2878. ksc = parent;
  2879. }
  2880. range.setStart(ksc[0], 0);
  2881. ksc = K(range.startContainer);
  2882. if (ksc.isBlock()) {
  2883. _removeAttrOrCss(ksc, map);
  2884. }
  2885. var kscp = ksc.parent();
  2886. if (kscp && kscp.isBlock()) {
  2887. _removeAttrOrCss(kscp, map);
  2888. }
  2889. }
  2890. var sc, so;
  2891. if (range.collapsed) {
  2892. self.split(true, map);
  2893. sc = range.startContainer;
  2894. so = range.startOffset;
  2895. if (so > 0) {
  2896. var sb = K(sc.childNodes[so - 1]);
  2897. if (sb && _isEmptyNode(sb)) {
  2898. sb.remove();
  2899. range.setStart(sc, so - 1);
  2900. }
  2901. }
  2902. var sa = K(sc.childNodes[so]);
  2903. if (sa && _isEmptyNode(sa)) {
  2904. sa.remove();
  2905. }
  2906. if (_isEmptyNode(sc)) {
  2907. range.startBefore(sc);
  2908. sc.remove();
  2909. }
  2910. range.collapse(true);
  2911. return self;
  2912. }
  2913. self.split(true, map);
  2914. self.split(false, map);
  2915. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2916. range.cloneRange().collapse(false).insertNode(endDummy);
  2917. range.cloneRange().collapse(true).insertNode(startDummy);
  2918. var nodeList = [], cmpStart = false;
  2919. K(range.commonAncestor()).scan(function(node) {
  2920. if (!cmpStart && node == startDummy) {
  2921. cmpStart = true;
  2922. return;
  2923. }
  2924. if (node == endDummy) {
  2925. return false;
  2926. }
  2927. if (cmpStart) {
  2928. nodeList.push(node);
  2929. }
  2930. });
  2931. K(startDummy).remove();
  2932. K(endDummy).remove();
  2933. sc = range.startContainer;
  2934. so = range.startOffset;
  2935. var ec = range.endContainer, eo = range.endOffset;
  2936. if (so > 0) {
  2937. var startBefore = K(sc.childNodes[so - 1]);
  2938. if (startBefore && _isEmptyNode(startBefore)) {
  2939. startBefore.remove();
  2940. range.setStart(sc, so - 1);
  2941. if (sc == ec) {
  2942. range.setEnd(ec, eo - 1);
  2943. }
  2944. }
  2945. var startAfter = K(sc.childNodes[so]);
  2946. if (startAfter && _isEmptyNode(startAfter)) {
  2947. startAfter.remove();
  2948. if (sc == ec) {
  2949. range.setEnd(ec, eo - 1);
  2950. }
  2951. }
  2952. }
  2953. var endAfter = K(ec.childNodes[range.endOffset]);
  2954. if (endAfter && _isEmptyNode(endAfter)) {
  2955. endAfter.remove();
  2956. }
  2957. var bookmark = range.createBookmark(true);
  2958. _each(nodeList, function(i, node) {
  2959. _removeAttrOrCss(K(node), map);
  2960. });
  2961. range.moveToBookmark(bookmark);
  2962. return self;
  2963. },
  2964. commonNode : function(map) {
  2965. var range = this.range;
  2966. var ec = range.endContainer, eo = range.endOffset,
  2967. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2968. function find(node) {
  2969. var child = node, parent = node;
  2970. while (parent) {
  2971. if (_hasAttrOrCss(K(parent), map)) {
  2972. return K(parent);
  2973. }
  2974. parent = parent.parentNode;
  2975. }
  2976. while (child && (child = child.lastChild)) {
  2977. if (_hasAttrOrCss(K(child), map)) {
  2978. return K(child);
  2979. }
  2980. }
  2981. return null;
  2982. }
  2983. var cNode = find(node);
  2984. if (cNode) {
  2985. return cNode;
  2986. }
  2987. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2988. var prev = K(node).prev();
  2989. if (prev) {
  2990. return find(prev);
  2991. }
  2992. }
  2993. return null;
  2994. },
  2995. commonAncestor : function(tagName) {
  2996. var range = this.range,
  2997. sc = range.startContainer, so = range.startOffset,
  2998. ec = range.endContainer, eo = range.endOffset,
  2999. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3000. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3001. function find(node) {
  3002. while (node) {
  3003. if (node.nodeType == 1) {
  3004. if (node.tagName.toLowerCase() === tagName) {
  3005. return node;
  3006. }
  3007. }
  3008. node = node.parentNode;
  3009. }
  3010. return null;
  3011. }
  3012. var start = find(startNode), end = find(endNode);
  3013. if (start && end && start === end) {
  3014. return K(start);
  3015. }
  3016. return null;
  3017. },
  3018. state : function(key) {
  3019. var self = this, doc = self.doc, bool = false;
  3020. try {
  3021. bool = doc.queryCommandState(key);
  3022. } catch (e) {}
  3023. return bool;
  3024. },
  3025. val : function(key) {
  3026. var self = this, doc = self.doc, range = self.range;
  3027. function lc(val) {
  3028. return val.toLowerCase();
  3029. }
  3030. key = lc(key);
  3031. var val = '', knode;
  3032. if (key === 'fontfamily' || key === 'fontname') {
  3033. val = _nativeCommandValue(doc, 'fontname');
  3034. val = val.replace(/['"]/g, '');
  3035. return lc(val);
  3036. }
  3037. if (key === 'formatblock') {
  3038. val = _nativeCommandValue(doc, key);
  3039. if (val === '') {
  3040. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3041. if (knode) {
  3042. val = knode.name;
  3043. }
  3044. }
  3045. if (val === 'Normal') {
  3046. val = 'p';
  3047. }
  3048. return lc(val);
  3049. }
  3050. if (key === 'fontsize') {
  3051. knode = self.commonNode({'*' : '.font-size'});
  3052. if (knode) {
  3053. val = knode.css('font-size');
  3054. }
  3055. return lc(val);
  3056. }
  3057. if (key === 'forecolor') {
  3058. knode = self.commonNode({'*' : '.color'});
  3059. if (knode) {
  3060. val = knode.css('color');
  3061. }
  3062. val = _toHex(val);
  3063. if (val === '') {
  3064. val = 'default';
  3065. }
  3066. return lc(val);
  3067. }
  3068. if (key === 'hilitecolor') {
  3069. knode = self.commonNode({'*' : '.background-color'});
  3070. if (knode) {
  3071. val = knode.css('background-color');
  3072. }
  3073. val = _toHex(val);
  3074. if (val === '') {
  3075. val = 'default';
  3076. }
  3077. return lc(val);
  3078. }
  3079. return val;
  3080. },
  3081. toggle : function(wrapper, map) {
  3082. var self = this;
  3083. if (self.commonNode(map)) {
  3084. self.remove(map);
  3085. } else {
  3086. self.wrap(wrapper);
  3087. }
  3088. return self.select();
  3089. },
  3090. bold : function() {
  3091. return this.toggle('<strong></strong>', {
  3092. span : '.font-weight=bold',
  3093. strong : '*',
  3094. b : '*'
  3095. });
  3096. },
  3097. italic : function() {
  3098. return this.toggle('<em></em>', {
  3099. span : '.font-style=italic',
  3100. em : '*',
  3101. i : '*'
  3102. });
  3103. },
  3104. underline : function() {
  3105. return this.toggle('<u></u>', {
  3106. span : '.text-decoration=underline',
  3107. u : '*'
  3108. });
  3109. },
  3110. strikethrough : function() {
  3111. return this.toggle('<s></s>', {
  3112. span : '.text-decoration=line-through',
  3113. s : '*'
  3114. });
  3115. },
  3116. forecolor : function(val) {
  3117. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3118. },
  3119. hilitecolor : function(val) {
  3120. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3121. },
  3122. fontsize : function(val) {
  3123. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3124. },
  3125. fontname : function(val) {
  3126. return this.fontfamily(val);
  3127. },
  3128. fontfamily : function(val) {
  3129. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3130. },
  3131. removeformat : function() {
  3132. var map = {
  3133. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3134. },
  3135. tags = _STYLE_TAG_MAP;
  3136. _each(tags, function(key, val) {
  3137. map[key] = '*';
  3138. });
  3139. this.remove(map);
  3140. return this.select();
  3141. },
  3142. inserthtml : function(val, quickMode) {
  3143. var self = this, range = self.range;
  3144. if (val === '') {
  3145. return self;
  3146. }
  3147. function pasteHtml(range, val) {
  3148. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3149. var rng = range.get();
  3150. if (rng.item) {
  3151. rng.item(0).outerHTML = val;
  3152. } else {
  3153. rng.pasteHTML(val);
  3154. }
  3155. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3156. temp.parentNode.removeChild(temp);
  3157. var newRange = _toRange(rng);
  3158. range.setEnd(newRange.endContainer, newRange.endOffset);
  3159. range.collapse(false);
  3160. self.select(false);
  3161. }
  3162. function insertHtml(range, val) {
  3163. var doc = range.doc,
  3164. frag = doc.createDocumentFragment();
  3165. K('@' + val, doc).each(function() {
  3166. frag.appendChild(this);
  3167. });
  3168. range.deleteContents();
  3169. range.insertNode(frag);
  3170. range.collapse(false);
  3171. self.select(false);
  3172. }
  3173. if (_IERANGE && quickMode) {
  3174. try {
  3175. pasteHtml(range, val);
  3176. } catch(e) {
  3177. insertHtml(range, val);
  3178. }
  3179. return self;
  3180. }
  3181. insertHtml(range, val);
  3182. return self;
  3183. },
  3184. hr : function() {
  3185. return this.inserthtml('<hr />');
  3186. },
  3187. print : function() {
  3188. this.win.print();
  3189. return this;
  3190. },
  3191. insertimage : function(url, title, width, height, border, align) {
  3192. title = _undef(title, '');
  3193. border = _undef(border, 0);
  3194. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3195. if (width) {
  3196. html += 'width="' + _escape(width) + '" ';
  3197. }
  3198. if (height) {
  3199. html += 'height="' + _escape(height) + '" ';
  3200. }
  3201. if (title) {
  3202. html += 'title="' + _escape(title) + '" ';
  3203. }
  3204. if (align) {
  3205. html += 'align="' + _escape(align) + '" ';
  3206. }
  3207. html += 'alt="' + _escape(title) + '" ';
  3208. html += '/>';
  3209. return this.inserthtml(html);
  3210. },
  3211. createlink : function(url, type) {
  3212. var self = this, doc = self.doc, range = self.range;
  3213. self.select();
  3214. var a = self.commonNode({ a : '*' });
  3215. if (a && !range.isControl()) {
  3216. range.selectNode(a.get());
  3217. self.select();
  3218. }
  3219. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3220. if (type) {
  3221. html += ' target="' + _escape(type) + '"';
  3222. }
  3223. if (range.collapsed) {
  3224. html += '>' + _escape(url) + '</a>';
  3225. return self.inserthtml(html);
  3226. }
  3227. if (range.isControl()) {
  3228. var node = K(range.startContainer.childNodes[range.startOffset]);
  3229. html += '></a>';
  3230. node.after(K(html, doc));
  3231. node.next().append(node);
  3232. range.selectNode(node[0]);
  3233. return self.select();
  3234. }
  3235. function setAttr(node, url, type) {
  3236. K(node).attr('href', url).attr('data-ke-src', url);
  3237. if (type) {
  3238. K(node).attr('target', type);
  3239. } else {
  3240. K(node).removeAttr('target');
  3241. }
  3242. }
  3243. var sc = range.startContainer, so = range.startOffset,
  3244. ec = range.endContainer, eo = range.endOffset;
  3245. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3246. var child = sc.childNodes[so];
  3247. if (child.nodeName.toLowerCase() == 'a') {
  3248. setAttr(child, url, type);
  3249. return self;
  3250. }
  3251. }
  3252. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3253. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3254. setAttr(this, url, type);
  3255. });
  3256. return self;
  3257. },
  3258. unlink : function() {
  3259. var self = this, doc = self.doc, range = self.range;
  3260. self.select();
  3261. if (range.collapsed) {
  3262. var a = self.commonNode({ a : '*' });
  3263. if (a) {
  3264. range.selectNode(a.get());
  3265. self.select();
  3266. }
  3267. _nativeCommand(doc, 'unlink', null);
  3268. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3269. var parent = K(range.startContainer).parent();
  3270. if (parent.name === 'a') {
  3271. parent.remove(true);
  3272. }
  3273. }
  3274. } else {
  3275. _nativeCommand(doc, 'unlink', null);
  3276. }
  3277. return self;
  3278. }
  3279. });
  3280. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3281. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3282. KCmd.prototype[name] = function(val) {
  3283. var self = this;
  3284. self.select();
  3285. _nativeCommand(self.doc, name, val);
  3286. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3287. self.selection();
  3288. }
  3289. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3290. self.selection();
  3291. }
  3292. return self;
  3293. };
  3294. });
  3295. _each('cut,copy,paste'.split(','), function(i, name) {
  3296. KCmd.prototype[name] = function() {
  3297. var self = this;
  3298. if (!self.doc.queryCommandSupported(name)) {
  3299. throw 'not supported';
  3300. }
  3301. self.select();
  3302. _nativeCommand(self.doc, name, null);
  3303. return self;
  3304. };
  3305. });
  3306. function _cmd(mixed) {
  3307. if (mixed.nodeName) {
  3308. var doc = _getDoc(mixed);
  3309. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3310. }
  3311. return new KCmd(mixed);
  3312. }
  3313. K.CmdClass = KCmd;
  3314. K.cmd = _cmd;
  3315. function _drag(options) {
  3316. var moveEl = options.moveEl,
  3317. moveFn = options.moveFn,
  3318. clickEl = options.clickEl || moveEl,
  3319. beforeDrag = options.beforeDrag,
  3320. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3321. var docs = [document];
  3322. if (iframeFix) {
  3323. K('iframe').each(function() {
  3324. var src = _formatUrl(this.src || '', 'absolute');
  3325. if (/^https?:\/\//.test(src)) {
  3326. return;
  3327. }
  3328. var doc;
  3329. try {
  3330. doc = _iframeDoc(this);
  3331. } catch(e) {}
  3332. if (doc) {
  3333. var pos = K(this).pos();
  3334. K(doc).data('pos-x', pos.x);
  3335. K(doc).data('pos-y', pos.y);
  3336. docs.push(doc);
  3337. }
  3338. });
  3339. }
  3340. clickEl.mousedown(function(e) {
  3341. if(e.button !== 0 && e.button !== 1) {
  3342. return;
  3343. }
  3344. e.stopPropagation();
  3345. var self = clickEl.get(),
  3346. x = _removeUnit(moveEl.css('left')),
  3347. y = _removeUnit(moveEl.css('top')),
  3348. width = moveEl.width(),
  3349. height = moveEl.height(),
  3350. pageX = e.pageX,
  3351. pageY = e.pageY;
  3352. if (beforeDrag) {
  3353. beforeDrag();
  3354. }
  3355. function moveListener(e) {
  3356. e.preventDefault();
  3357. var kdoc = K(_getDoc(e.target));
  3358. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3359. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3360. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3361. }
  3362. function selectListener(e) {
  3363. e.preventDefault();
  3364. }
  3365. function upListener(e) {
  3366. e.preventDefault();
  3367. K(docs).unbind('mousemove', moveListener)
  3368. .unbind('mouseup', upListener)
  3369. .unbind('selectstart', selectListener);
  3370. if (self.releaseCapture) {
  3371. self.releaseCapture();
  3372. }
  3373. }
  3374. K(docs).mousemove(moveListener)
  3375. .mouseup(upListener)
  3376. .bind('selectstart', selectListener);
  3377. if (self.setCapture) {
  3378. self.setCapture();
  3379. }
  3380. });
  3381. }
  3382. function KWidget(options) {
  3383. this.init(options);
  3384. }
  3385. _extend(KWidget, {
  3386. init : function(options) {
  3387. var self = this;
  3388. self.name = options.name || '';
  3389. self.doc = options.doc || document;
  3390. self.win = _getWin(self.doc);
  3391. self.x = _addUnit(options.x);
  3392. self.y = _addUnit(options.y);
  3393. self.z = options.z;
  3394. self.width = _addUnit(options.width);
  3395. self.height = _addUnit(options.height);
  3396. self.index = _addUnit(options.index);
  3397. self.div = K('<div style="display:block;"></div>');
  3398. self.options = options;
  3399. self._alignEl = options.alignEl;
  3400. if (self.width) {
  3401. self.div.css('width', self.width);
  3402. }
  3403. if (self.height) {
  3404. self.div.css('height', self.height);
  3405. }
  3406. if (self.z) {
  3407. self.div.css({
  3408. position : 'absolute',
  3409. left : self.x,
  3410. top : self.y,
  3411. 'z-index' : self.z
  3412. });
  3413. }
  3414. if (self.z && (self.x === undefined || self.y === undefined)) {
  3415. self.autoPos(self.width, self.height);
  3416. }
  3417. if (options.cls) {
  3418. self.div.addClass(options.cls);
  3419. }
  3420. if (options.shadowMode) {
  3421. self.div.addClass('ke-shadow');
  3422. }
  3423. if (options.css) {
  3424. self.div.css(options.css);
  3425. }
  3426. if (options.src) {
  3427. K(options.src).replaceWith(self.div);
  3428. } else {
  3429. K(self.doc.body).append(self.div);
  3430. }
  3431. if (options.html) {
  3432. self.div.html(options.html);
  3433. }
  3434. if (options.autoScroll) {
  3435. if (_IE && _V < 7 || _QUIRKS) {
  3436. var scrollPos = _getScrollPos();
  3437. K(self.win).bind('scroll', function(e) {
  3438. var pos = _getScrollPos(),
  3439. diffX = pos.x - scrollPos.x,
  3440. diffY = pos.y - scrollPos.y;
  3441. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3442. });
  3443. } else {
  3444. self.div.css('position', 'fixed');
  3445. }
  3446. }
  3447. },
  3448. pos : function(x, y, updateProp) {
  3449. var self = this;
  3450. updateProp = _undef(updateProp, true);
  3451. if (x !== null) {
  3452. x = x < 0 ? 0 : _addUnit(x);
  3453. self.div.css('left', x);
  3454. if (updateProp) {
  3455. self.x = x;
  3456. }
  3457. }
  3458. if (y !== null) {
  3459. y = y < 0 ? 0 : _addUnit(y);
  3460. self.div.css('top', y);
  3461. if (updateProp) {
  3462. self.y = y;
  3463. }
  3464. }
  3465. return self;
  3466. },
  3467. autoPos : function(width, height) {
  3468. var x, y, self = this,
  3469. w = _removeUnit(width) || 0,
  3470. h = _removeUnit(height) || 0,
  3471. scrollPos = _getScrollPos();
  3472. if (self._alignEl) {
  3473. var knode = K(self._alignEl),
  3474. pos = knode.pos(),
  3475. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3476. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3477. x = diffX < 0 ? pos.x : pos.x + diffX;
  3478. y = diffY < 0 ? pos.y : pos.y + diffY;
  3479. } else {
  3480. var docEl = _docElement(self.doc);
  3481. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3482. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3483. }
  3484. if (!(_IE && _V < 7 || _QUIRKS)) {
  3485. x -= scrollPos.x;
  3486. y -= scrollPos.y;
  3487. }
  3488. return self.pos(x, y);
  3489. },
  3490. remove : function() {
  3491. var self = this;
  3492. if (_IE && _V < 7 || _QUIRKS) {
  3493. K(self.win).unbind('scroll');
  3494. }
  3495. self.div.remove();
  3496. _each(self, function(i) {
  3497. self[i] = null;
  3498. });
  3499. return this;
  3500. },
  3501. show : function() {
  3502. this.div.show();
  3503. return this;
  3504. },
  3505. hide : function() {
  3506. this.div.hide();
  3507. return this;
  3508. },
  3509. draggable : function(options) {
  3510. var self = this;
  3511. options = options || {};
  3512. options.moveEl = self.div;
  3513. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3514. if ((x = x + diffX) < 0) {
  3515. x = 0;
  3516. }
  3517. if ((y = y + diffY) < 0) {
  3518. y = 0;
  3519. }
  3520. self.pos(x, y);
  3521. };
  3522. _drag(options);
  3523. return self;
  3524. }
  3525. });
  3526. function _widget(options) {
  3527. return new KWidget(options);
  3528. }
  3529. K.WidgetClass = KWidget;
  3530. K.widget = _widget;
  3531. function _iframeDoc(iframe) {
  3532. iframe = _get(iframe);
  3533. return iframe.contentDocument || iframe.contentWindow.document;
  3534. }
  3535. var html, _direction = '';
  3536. if ((html = document.getElementsByTagName('html'))) {
  3537. _direction = html[0].dir;
  3538. }
  3539. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3540. var arr = [
  3541. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3542. '<head><meta charset="utf-8" /><title></title>',
  3543. '<style>',
  3544. 'html {margin:0;padding:0;}',
  3545. 'body {margin:0;padding:5px;}',
  3546. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3547. 'body, p, div {word-wrap: break-word;}',
  3548. 'p {margin:5px 0;}',
  3549. 'table {border-collapse:collapse;}',
  3550. 'img {border:0;}',
  3551. 'noscript {display:none;}',
  3552. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3553. 'img.ke-flash {',
  3554. ' border:1px solid #AAA;',
  3555. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3556. ' background-position:center center;',
  3557. ' background-repeat:no-repeat;',
  3558. ' width:100px;',
  3559. ' height:100px;',
  3560. '}',
  3561. 'img.ke-rm {',
  3562. ' border:1px solid #AAA;',
  3563. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3564. ' background-position:center center;',
  3565. ' background-repeat:no-repeat;',
  3566. ' width:100px;',
  3567. ' height:100px;',
  3568. '}',
  3569. 'img.ke-media {',
  3570. ' border:1px solid #AAA;',
  3571. ' background-image:url(' + themesPath + 'common/media.gif);',
  3572. ' background-position:center center;',
  3573. ' background-repeat:no-repeat;',
  3574. ' width:100px;',
  3575. ' height:100px;',
  3576. '}',
  3577. 'img.ke-anchor {',
  3578. ' border:1px dashed #666;',
  3579. ' width:16px;',
  3580. ' height:16px;',
  3581. '}',
  3582. '.ke-script, .ke-noscript, .ke-display-none {',
  3583. ' display:none;',
  3584. ' font-size:0;',
  3585. ' width:0;',
  3586. ' height:0;',
  3587. '}',
  3588. '.ke-pagebreak {',
  3589. ' border:1px dotted #AAA;',
  3590. ' font-size:0;',
  3591. ' height:2px;',
  3592. '}',
  3593. '</style>'
  3594. ];
  3595. if (!_isArray(cssPath)) {
  3596. cssPath = [cssPath];
  3597. }
  3598. _each(cssPath, function(i, path) {
  3599. if (path) {
  3600. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3601. }
  3602. });
  3603. if (cssData) {
  3604. arr.push('<style>' + cssData + '</style>');
  3605. }
  3606. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3607. return arr.join('\n');
  3608. }
  3609. function _elementVal(knode, val) {
  3610. if (knode.hasVal()) {
  3611. if (val === undefined) {
  3612. var html = knode.val();
  3613. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3614. return html;
  3615. }
  3616. return knode.val(val);
  3617. }
  3618. return knode.html(val);
  3619. }
  3620. function KEdit(options) {
  3621. this.init(options);
  3622. }
  3623. _extend(KEdit, KWidget, {
  3624. init : function(options) {
  3625. var self = this;
  3626. KEdit.parent.init.call(self, options);
  3627. self.srcElement = K(options.srcElement);
  3628. self.div.addClass('ke-edit');
  3629. self.designMode = _undef(options.designMode, true);
  3630. self.beforeGetHtml = options.beforeGetHtml;
  3631. self.beforeSetHtml = options.beforeSetHtml;
  3632. self.afterSetHtml = options.afterSetHtml;
  3633. var themesPath = _undef(options.themesPath, ''),
  3634. bodyClass = options.bodyClass,
  3635. cssPath = options.cssPath,
  3636. cssData = options.cssData,
  3637. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3638. srcScript = ('document.open();' +
  3639. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3640. 'document.close();'),
  3641. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3642. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3643. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3644. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3645. self.iframe.attr('tabindex', self.tabIndex);
  3646. self.textarea.attr('tabindex', self.tabIndex);
  3647. if (self.width) {
  3648. self.setWidth(self.width);
  3649. }
  3650. if (self.height) {
  3651. self.setHeight(self.height);
  3652. }
  3653. if (self.designMode) {
  3654. self.textarea.hide();
  3655. } else {
  3656. self.iframe.hide();
  3657. }
  3658. function ready() {
  3659. var doc = _iframeDoc(self.iframe);
  3660. doc.open();
  3661. if (isDocumentDomain) {
  3662. doc.domain = document.domain;
  3663. }
  3664. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3665. doc.close();
  3666. self.win = self.iframe[0].contentWindow;
  3667. self.doc = doc;
  3668. var cmd = _cmd(doc);
  3669. self.afterChange(function(e) {
  3670. cmd.selection();
  3671. });
  3672. if (_WEBKIT) {
  3673. K(doc).click(function(e) {
  3674. if (K(e.target).name === 'img') {
  3675. cmd.selection(true);
  3676. cmd.range.selectNode(e.target);
  3677. cmd.select();
  3678. }
  3679. });
  3680. }
  3681. if (_IE) {
  3682. self._mousedownHandler = function() {
  3683. var newRange = cmd.range.cloneRange();
  3684. newRange.shrink();
  3685. if (newRange.isControl()) {
  3686. self.blur();
  3687. }
  3688. };
  3689. K(document).mousedown(self._mousedownHandler);
  3690. K(doc).keydown(function(e) {
  3691. if (e.which == 8) {
  3692. cmd.selection();
  3693. var rng = cmd.range;
  3694. if (rng.isControl()) {
  3695. rng.collapse(true);
  3696. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3697. e.preventDefault();
  3698. }
  3699. }
  3700. });
  3701. }
  3702. self.cmd = cmd;
  3703. self.html(_elementVal(self.srcElement));
  3704. if (_IE) {
  3705. doc.body.disabled = true;
  3706. doc.body.contentEditable = true;
  3707. doc.body.removeAttribute('disabled');
  3708. } else {
  3709. doc.designMode = 'on';
  3710. }
  3711. if (options.afterCreate) {
  3712. options.afterCreate.call(self);
  3713. }
  3714. }
  3715. if (isDocumentDomain) {
  3716. self.iframe.bind('load', function(e) {
  3717. self.iframe.unbind('load');
  3718. if (_IE) {
  3719. ready();
  3720. } else {
  3721. setTimeout(ready, 0);
  3722. }
  3723. });
  3724. }
  3725. self.div.append(self.iframe);
  3726. self.div.append(self.textarea);
  3727. self.srcElement.hide();
  3728. !isDocumentDomain && ready();
  3729. },
  3730. setWidth : function(val) {
  3731. var self = this;
  3732. val = _addUnit(val);
  3733. self.width = val;
  3734. self.div.css('width', val);
  3735. return self;
  3736. },
  3737. setHeight : function(val) {
  3738. var self = this;
  3739. val = _addUnit(val);
  3740. self.height = val;
  3741. self.div.css('height', val);
  3742. self.iframe.css('height', val);
  3743. if ((_IE && _V < 8) || _QUIRKS) {
  3744. val = _addUnit(_removeUnit(val) - 2);
  3745. }
  3746. self.textarea.css('height', val);
  3747. return self;
  3748. },
  3749. remove : function() {
  3750. var self = this, doc = self.doc;
  3751. K(doc.body).unbind();
  3752. K(doc).unbind();
  3753. K(self.win).unbind();
  3754. if (self._mousedownHandler) {
  3755. K(document).unbind('mousedown', self._mousedownHandler);
  3756. }
  3757. _elementVal(self.srcElement, self.html());
  3758. self.srcElement.show();
  3759. self.iframe.unbind();
  3760. self.textarea.unbind();
  3761. KEdit.parent.remove.call(self);
  3762. },
  3763. html : function(val, isFull) {
  3764. var self = this, doc = self.doc;
  3765. if (self.designMode) {
  3766. var body = doc.body;
  3767. if (val === undefined) {
  3768. if (isFull) {
  3769. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3770. } else {
  3771. val = body.innerHTML;
  3772. }
  3773. if (self.beforeGetHtml) {
  3774. val = self.beforeGetHtml(val);
  3775. }
  3776. if (_GECKO && val == '<br />') {
  3777. val = '';
  3778. }
  3779. return val;
  3780. }
  3781. if (self.beforeSetHtml) {
  3782. val = self.beforeSetHtml(val);
  3783. }
  3784. if (_IE && _V >= 9) {
  3785. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3786. }
  3787. K(body).html(val);
  3788. if (self.afterSetHtml) {
  3789. self.afterSetHtml();
  3790. }
  3791. return self;
  3792. }
  3793. if (val === undefined) {
  3794. return self.textarea.val();
  3795. }
  3796. self.textarea.val(val);
  3797. return self;
  3798. },
  3799. design : function(bool) {
  3800. var self = this, val;
  3801. if (bool === undefined ? !self.designMode : bool) {
  3802. if (!self.designMode) {
  3803. val = self.html();
  3804. self.designMode = true;
  3805. self.textarea.hide();
  3806. self.html(val);
  3807. var iframe = self.iframe;
  3808. var height = _removeUnit(self.height);
  3809. iframe.height(height - 2);
  3810. iframe.show();
  3811. setTimeout(function() {
  3812. iframe.height(height);
  3813. }, 0);
  3814. }
  3815. } else {
  3816. if (self.designMode) {
  3817. val = self.html();
  3818. self.designMode = false;
  3819. self.html(val);
  3820. self.iframe.hide();
  3821. self.textarea.show();
  3822. }
  3823. }
  3824. return self.focus();
  3825. },
  3826. focus : function() {
  3827. var self = this;
  3828. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3829. return self;
  3830. },
  3831. blur : function() {
  3832. var self = this;
  3833. if (_IE) {
  3834. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3835. self.div.append(input);
  3836. input[0].focus();
  3837. input.remove();
  3838. } else {
  3839. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3840. }
  3841. return self;
  3842. },
  3843. afterChange : function(fn) {
  3844. var self = this, doc = self.doc, body = doc.body;
  3845. K(doc).keyup(function(e) {
  3846. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3847. fn(e);
  3848. }
  3849. });
  3850. K(doc).mouseup(fn).contextmenu(fn);
  3851. K(self.win).blur(fn);
  3852. function timeoutHandler(e) {
  3853. setTimeout(function() {
  3854. fn(e);
  3855. }, 1);
  3856. }
  3857. K(body).bind('paste', timeoutHandler);
  3858. K(body).bind('cut', timeoutHandler);
  3859. return self;
  3860. }
  3861. });
  3862. function _edit(options) {
  3863. return new KEdit(options);
  3864. }
  3865. K.EditClass = KEdit;
  3866. K.edit = _edit;
  3867. K.iframeDoc = _iframeDoc;
  3868. function _selectToolbar(name, fn) {
  3869. var self = this,
  3870. knode = self.get(name);
  3871. if (knode) {
  3872. if (knode.hasClass('ke-disabled')) {
  3873. return;
  3874. }
  3875. fn(knode);
  3876. }
  3877. }
  3878. function KToolbar(options) {
  3879. this.init(options);
  3880. }
  3881. _extend(KToolbar, KWidget, {
  3882. init : function(options) {
  3883. var self = this;
  3884. KToolbar.parent.init.call(self, options);
  3885. self.disableMode = _undef(options.disableMode, false);
  3886. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3887. self._itemMap = {};
  3888. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3889. e.preventDefault();
  3890. }).attr('unselectable', 'on');
  3891. function find(target) {
  3892. var knode = K(target);
  3893. if (knode.hasClass('ke-outline')) {
  3894. return knode;
  3895. }
  3896. if (knode.hasClass('ke-toolbar-icon')) {
  3897. return knode.parent();
  3898. }
  3899. }
  3900. function hover(e, method) {
  3901. var knode = find(e.target);
  3902. if (knode) {
  3903. if (knode.hasClass('ke-disabled')) {
  3904. return;
  3905. }
  3906. if (knode.hasClass('ke-selected')) {
  3907. return;
  3908. }
  3909. knode[method]('ke-on');
  3910. }
  3911. }
  3912. self.div.mouseover(function(e) {
  3913. hover(e, 'addClass');
  3914. })
  3915. .mouseout(function(e) {
  3916. hover(e, 'removeClass');
  3917. })
  3918. .click(function(e) {
  3919. var knode = find(e.target);
  3920. if (knode) {
  3921. if (knode.hasClass('ke-disabled')) {
  3922. return;
  3923. }
  3924. self.options.click.call(this, e, knode.attr('data-name'));
  3925. }
  3926. });
  3927. },
  3928. get : function(name) {
  3929. if (this._itemMap[name]) {
  3930. return this._itemMap[name];
  3931. }
  3932. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3933. },
  3934. select : function(name) {
  3935. _selectToolbar.call(this, name, function(knode) {
  3936. knode.addClass('ke-selected');
  3937. });
  3938. return self;
  3939. },
  3940. unselect : function(name) {
  3941. _selectToolbar.call(this, name, function(knode) {
  3942. knode.removeClass('ke-selected').removeClass('ke-on');
  3943. });
  3944. return self;
  3945. },
  3946. enable : function(name) {
  3947. var self = this,
  3948. knode = name.get ? name : self.get(name);
  3949. if (knode) {
  3950. knode.removeClass('ke-disabled');
  3951. knode.opacity(1);
  3952. }
  3953. return self;
  3954. },
  3955. disable : function(name) {
  3956. var self = this,
  3957. knode = name.get ? name : self.get(name);
  3958. if (knode) {
  3959. knode.removeClass('ke-selected').addClass('ke-disabled');
  3960. knode.opacity(0.5);
  3961. }
  3962. return self;
  3963. },
  3964. disableAll : function(bool, noDisableItems) {
  3965. var self = this, map = self.noDisableItemMap, item;
  3966. if (noDisableItems) {
  3967. map = _toMap(noDisableItems);
  3968. }
  3969. if (bool === undefined ? !self.disableMode : bool) {
  3970. K('span.ke-outline', self.div).each(function() {
  3971. var knode = K(this),
  3972. name = knode[0].getAttribute('data-name', 2);
  3973. if (!map[name]) {
  3974. self.disable(knode);
  3975. }
  3976. });
  3977. self.disableMode = true;
  3978. } else {
  3979. K('span.ke-outline', self.div).each(function() {
  3980. var knode = K(this),
  3981. name = knode[0].getAttribute('data-name', 2);
  3982. if (!map[name]) {
  3983. self.enable(knode);
  3984. }
  3985. });
  3986. self.disableMode = false;
  3987. }
  3988. return self;
  3989. }
  3990. });
  3991. function _toolbar(options) {
  3992. return new KToolbar(options);
  3993. }
  3994. K.ToolbarClass = KToolbar;
  3995. K.toolbar = _toolbar;
  3996. function KMenu(options) {
  3997. this.init(options);
  3998. }
  3999. _extend(KMenu, KWidget, {
  4000. init : function(options) {
  4001. var self = this;
  4002. options.z = options.z || 811213;
  4003. KMenu.parent.init.call(self, options);
  4004. self.centerLineMode = _undef(options.centerLineMode, true);
  4005. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4006. e.stopPropagation();
  4007. }).attr('unselectable', 'on');
  4008. },
  4009. addItem : function(item) {
  4010. var self = this;
  4011. if (item.title === '-') {
  4012. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4013. return;
  4014. }
  4015. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4016. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4017. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4018. height = _addUnit(item.height),
  4019. iconClass = _undef(item.iconClass, '');
  4020. self.div.append(itemDiv);
  4021. if (height) {
  4022. itemDiv.css('height', height);
  4023. rightDiv.css('line-height', height);
  4024. }
  4025. var centerDiv;
  4026. if (self.centerLineMode) {
  4027. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4028. if (height) {
  4029. centerDiv.css('height', height);
  4030. }
  4031. }
  4032. itemDiv.mouseover(function(e) {
  4033. K(this).addClass('ke-menu-item-on');
  4034. if (centerDiv) {
  4035. centerDiv.addClass('ke-menu-item-center-on');
  4036. }
  4037. })
  4038. .mouseout(function(e) {
  4039. K(this).removeClass('ke-menu-item-on');
  4040. if (centerDiv) {
  4041. centerDiv.removeClass('ke-menu-item-center-on');
  4042. }
  4043. })
  4044. .click(function(e) {
  4045. item.click.call(K(this));
  4046. e.stopPropagation();
  4047. })
  4048. .append(leftDiv);
  4049. if (centerDiv) {
  4050. itemDiv.append(centerDiv);
  4051. }
  4052. itemDiv.append(rightDiv);
  4053. if (item.checked) {
  4054. iconClass = 'ke-icon-checked';
  4055. }
  4056. if (iconClass !== '') {
  4057. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4058. }
  4059. rightDiv.html(item.title);
  4060. return self;
  4061. },
  4062. remove : function() {
  4063. var self = this;
  4064. if (self.options.beforeRemove) {
  4065. self.options.beforeRemove.call(self);
  4066. }
  4067. K('.ke-menu-item', self.div[0]).unbind();
  4068. KMenu.parent.remove.call(self);
  4069. return self;
  4070. }
  4071. });
  4072. function _menu(options) {
  4073. return new KMenu(options);
  4074. }
  4075. K.MenuClass = KMenu;
  4076. K.menu = _menu;
  4077. function KColorPicker(options) {
  4078. this.init(options);
  4079. }
  4080. _extend(KColorPicker, KWidget, {
  4081. init : function(options) {
  4082. var self = this;
  4083. options.z = options.z || 811213;
  4084. KColorPicker.parent.init.call(self, options);
  4085. var colors = options.colors || [
  4086. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4087. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4088. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4089. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4090. ];
  4091. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4092. self._cells = [];
  4093. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4094. e.stopPropagation();
  4095. }).attr('unselectable', 'on');
  4096. var table = self.doc.createElement('table');
  4097. self.div.append(table);
  4098. table.className = 'ke-colorpicker-table';
  4099. table.cellPadding = 0;
  4100. table.cellSpacing = 0;
  4101. table.border = 0;
  4102. var row = table.insertRow(0), cell = row.insertCell(0);
  4103. cell.colSpan = colors[0].length;
  4104. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4105. for (var i = 0; i < colors.length; i++) {
  4106. row = table.insertRow(i + 1);
  4107. for (var j = 0; j < colors[i].length; j++) {
  4108. cell = row.insertCell(j);
  4109. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4110. }
  4111. }
  4112. },
  4113. _addAttr : function(cell, color, cls) {
  4114. var self = this;
  4115. cell = K(cell).addClass(cls);
  4116. if (self.selectedColor === color.toLowerCase()) {
  4117. cell.addClass('ke-colorpicker-cell-selected');
  4118. }
  4119. cell.attr('title', color || self.options.noColor);
  4120. cell.mouseover(function(e) {
  4121. K(this).addClass('ke-colorpicker-cell-on');
  4122. });
  4123. cell.mouseout(function(e) {
  4124. K(this).removeClass('ke-colorpicker-cell-on');
  4125. });
  4126. cell.click(function(e) {
  4127. e.stop();
  4128. self.options.click.call(K(this), color);
  4129. });
  4130. if (color) {
  4131. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4132. } else {
  4133. cell.html(self.options.noColor);
  4134. }
  4135. K(cell).attr('unselectable', 'on');
  4136. self._cells.push(cell);
  4137. },
  4138. remove : function() {
  4139. var self = this;
  4140. _each(self._cells, function() {
  4141. this.unbind();
  4142. });
  4143. KColorPicker.parent.remove.call(self);
  4144. return self;
  4145. }
  4146. });
  4147. function _colorpicker(options) {
  4148. return new KColorPicker(options);
  4149. }
  4150. K.ColorPickerClass = KColorPicker;
  4151. K.colorpicker = _colorpicker;
  4152. function KUploadButton(options) {
  4153. this.init(options);
  4154. }
  4155. _extend(KUploadButton, {
  4156. init : function(options) {
  4157. var self = this,
  4158. button = K(options.button),
  4159. fieldName = options.fieldName || 'file',
  4160. url = options.url || '',
  4161. title = button.val(),
  4162. extraParams = options.extraParams || {},
  4163. cls = button[0].className || '',
  4164. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4165. options.afterError = options.afterError || function(str) {
  4166. alert(str);
  4167. };
  4168. var hiddenElements = [];
  4169. for(var k in extraParams){
  4170. hiddenElements.push('<input type="hidden" class="ke-upload-file-'+k+'" name="' + k + '" value="' + extraParams[k] + '" />');
  4171. }
  4172. var html = [
  4173. '<div class="ke-inline-block ' + cls + '">',
  4174. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4175. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4176. '<span class="ke-button-common">',
  4177. hiddenElements.join(''),
  4178. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4179. '</span>',
  4180. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4181. (options.form ? '</div>' : '</form>'),
  4182. '</div>'].join('');
  4183. var div = K(html, button.doc);
  4184. button.hide();
  4185. button.before(div);
  4186. self.div = div;
  4187. self.button = button;
  4188. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4189. self.form = options.form ? K(options.form) : K('form', div);
  4190. self.fileBox = K('.ke-upload-file', div);
  4191. var width = options.width || K('.ke-button-common', div).width();
  4192. K('.ke-upload-area', div).width(width);
  4193. self.options = options;
  4194. },
  4195. submit : function(e) {
  4196. var self = this,
  4197. iframe = self.iframe;
  4198. e = false;
  4199. if (e) {
  4200. var file = e.files[0];
  4201. var filename = file.name;
  4202. var temp = filename.split('.');
  4203. //putExtra.params["x:name"] = temp[0];
  4204. var filename = hex_md5(file.name) + '.' + temp[temp.length-1];
  4205. var path = $('.' + 'ke-upload-file-key').val();
  4206. $('.' + 'ke-upload-file-key').val(path + filename);
  4207. //这里要修改 以后再改
  4208. } else {
  4209. iframe.bind('load', function() {
  4210. iframe.unbind();
  4211. var tempForm = document.createElement('form');
  4212. self.fileBox.before(tempForm);
  4213. K(tempForm).append(self.fileBox);
  4214. tempForm.reset();
  4215. K(tempForm).remove(true);
  4216. var doc = K.iframeDoc(iframe),
  4217. pre = doc.getElementsByTagName('pre')[0],
  4218. str = '', data;
  4219. if (pre) {
  4220. str = pre.innerHTML;
  4221. } else {
  4222. str = doc.body.innerHTML;
  4223. }
  4224. str = _unescape(str);
  4225. iframe[0].src = 'javascript:false';
  4226. try {
  4227. data = K.json(str);
  4228. } catch (e) {
  4229. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4230. }
  4231. if (data) {
  4232. self.options.afterUpload.call(self, data);
  4233. }
  4234. });
  4235. self.form[0].submit();
  4236. }
  4237. self.form[0].submit();
  4238. return self;
  4239. },
  4240. remove : function() {
  4241. var self = this;
  4242. if (self.fileBox) {
  4243. self.fileBox.unbind();
  4244. }
  4245. self.iframe.remove();
  4246. self.div.remove();
  4247. self.button.show();
  4248. return self;
  4249. }
  4250. });
  4251. function _uploadbutton(options) {
  4252. return new KUploadButton(options);
  4253. }
  4254. K.UploadButtonClass = KUploadButton;
  4255. K.uploadbutton = _uploadbutton;
  4256. function _createButton(arg) {
  4257. arg = arg || {};
  4258. var name = arg.name || '',
  4259. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4260. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4261. if (arg.click) {
  4262. btn.click(arg.click);
  4263. }
  4264. span.append(btn);
  4265. return span;
  4266. }
  4267. function KDialog(options) {
  4268. this.init(options);
  4269. }
  4270. _extend(KDialog, KWidget, {
  4271. init : function(options) {
  4272. var self = this;
  4273. var shadowMode = _undef(options.shadowMode, true);
  4274. options.z = options.z || 811213;
  4275. options.shadowMode = false;
  4276. options.autoScroll = _undef(options.autoScroll, true);
  4277. KDialog.parent.init.call(self, options);
  4278. var title = options.title,
  4279. body = K(options.body, self.doc),
  4280. previewBtn = options.previewBtn,
  4281. yesBtn = options.yesBtn,
  4282. noBtn = options.noBtn,
  4283. closeBtn = options.closeBtn,
  4284. showMask = _undef(options.showMask, true);
  4285. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4286. e.stopPropagation();
  4287. });
  4288. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4289. if (_IE && _V < 7) {
  4290. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4291. } else if (shadowMode) {
  4292. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4293. }
  4294. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4295. contentDiv.append(headerDiv);
  4296. headerDiv.html(title);
  4297. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4298. headerDiv.append(self.closeIcon);
  4299. self.draggable({
  4300. clickEl : headerDiv,
  4301. beforeDrag : options.beforeDrag
  4302. });
  4303. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4304. contentDiv.append(bodyDiv);
  4305. bodyDiv.append(body);
  4306. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4307. if (previewBtn || yesBtn || noBtn) {
  4308. contentDiv.append(footerDiv);
  4309. }
  4310. _each([
  4311. { btn : previewBtn, name : 'preview' },
  4312. { btn : yesBtn, name : 'yes' },
  4313. { btn : noBtn, name : 'no' }
  4314. ], function() {
  4315. if (this.btn) {
  4316. var button = _createButton(this.btn);
  4317. button.addClass('ke-dialog-' + this.name);
  4318. footerDiv.append(button);
  4319. }
  4320. });
  4321. if (self.height) {
  4322. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4323. }
  4324. self.div.width(self.div.width());
  4325. self.div.height(self.div.height());
  4326. self.mask = null;
  4327. if (showMask) {
  4328. var docEl = _docElement(self.doc),
  4329. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4330. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4331. self.mask = _widget({
  4332. x : 0,
  4333. y : 0,
  4334. z : self.z - 1,
  4335. cls : 'ke-dialog-mask',
  4336. width : docWidth,
  4337. height : docHeight
  4338. });
  4339. }
  4340. self.autoPos(self.div.width(), self.div.height());
  4341. self.footerDiv = footerDiv;
  4342. self.bodyDiv = bodyDiv;
  4343. self.headerDiv = headerDiv;
  4344. self.isLoading = false;
  4345. },
  4346. setMaskIndex : function(z) {
  4347. var self = this;
  4348. self.mask.div.css('z-index', z);
  4349. },
  4350. showLoading : function(msg) {
  4351. msg = _undef(msg, '');
  4352. var self = this, body = self.bodyDiv;
  4353. 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>')
  4354. .width(body.width()).height(body.height())
  4355. .css('top', self.headerDiv.height() + 'px');
  4356. body.css('visibility', 'hidden').after(self.loading);
  4357. self.isLoading = true;
  4358. return self;
  4359. },
  4360. hideLoading : function() {
  4361. this.loading && this.loading.remove();
  4362. this.bodyDiv.css('visibility', 'visible');
  4363. this.isLoading = false;
  4364. return this;
  4365. },
  4366. remove : function() {
  4367. var self = this;
  4368. if (self.options.beforeRemove) {
  4369. self.options.beforeRemove.call(self);
  4370. }
  4371. self.mask && self.mask.remove();
  4372. self.iframeMask && self.iframeMask.remove();
  4373. self.closeIcon.unbind();
  4374. K('input', self.div).unbind();
  4375. K('button', self.div).unbind();
  4376. self.footerDiv.unbind();
  4377. self.bodyDiv.unbind();
  4378. self.headerDiv.unbind();
  4379. K('iframe', self.div).each(function() {
  4380. K(this).remove();
  4381. });
  4382. KDialog.parent.remove.call(self);
  4383. return self;
  4384. }
  4385. });
  4386. function _dialog(options) {
  4387. return new KDialog(options);
  4388. }
  4389. K.DialogClass = KDialog;
  4390. K.dialog = _dialog;
  4391. function _tabs(options) {
  4392. var self = _widget(options),
  4393. remove = self.remove,
  4394. afterSelect = options.afterSelect,
  4395. div = self.div,
  4396. liList = [];
  4397. div.addClass('ke-tabs')
  4398. .bind('contextmenu,mousedown,mousemove', function(e) {
  4399. e.preventDefault();
  4400. });
  4401. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4402. div.append(ul);
  4403. self.add = function(tab) {
  4404. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4405. li.data('tab', tab);
  4406. liList.push(li);
  4407. ul.append(li);
  4408. };
  4409. self.selectedIndex = 0;
  4410. self.select = function(index) {
  4411. self.selectedIndex = index;
  4412. _each(liList, function(i, li) {
  4413. li.unbind();
  4414. if (i === index) {
  4415. li.addClass('ke-tabs-li-selected');
  4416. K(li.data('tab').panel).show('');
  4417. } else {
  4418. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4419. .mouseover(function() {
  4420. K(this).addClass('ke-tabs-li-on');
  4421. })
  4422. .mouseout(function() {
  4423. K(this).removeClass('ke-tabs-li-on');
  4424. })
  4425. .click(function() {
  4426. self.select(i);
  4427. });
  4428. K(li.data('tab').panel).hide();
  4429. }
  4430. });
  4431. if (afterSelect) {
  4432. afterSelect.call(self, index);
  4433. }
  4434. };
  4435. self.remove = function() {
  4436. _each(liList, function() {
  4437. this.remove();
  4438. });
  4439. ul.remove();
  4440. remove.call(self);
  4441. };
  4442. return self;
  4443. }
  4444. K.tabs = _tabs;
  4445. function _loadScript(url, fn) {
  4446. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4447. script = document.createElement('script');
  4448. head.appendChild(script);
  4449. script.src = url;
  4450. script.charset = 'utf-8';
  4451. script.onload = script.onreadystatechange = function() {
  4452. if (!this.readyState || this.readyState === 'loaded') {
  4453. if (fn) {
  4454. fn();
  4455. }
  4456. script.onload = script.onreadystatechange = null;
  4457. head.removeChild(script);
  4458. }
  4459. };
  4460. }
  4461. function _chopQuery(url) {
  4462. var index = url.indexOf('?');
  4463. return index > 0 ? url.substr(0, index) : url;
  4464. }
  4465. function _loadStyle(url) {
  4466. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4467. link = document.createElement('link'),
  4468. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4469. var links = K('link[rel="stylesheet"]', head);
  4470. for (var i = 0, len = links.length; i < len; i++) {
  4471. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4472. return;
  4473. }
  4474. }
  4475. head.appendChild(link);
  4476. link.href = url;
  4477. link.rel = 'stylesheet';
  4478. }
  4479. function _ajax(url, fn, method, param, dataType) {
  4480. method = method || 'GET';
  4481. dataType = dataType || 'json';
  4482. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4483. xhr.open(method, url, true);
  4484. xhr.onreadystatechange = function () {
  4485. if (xhr.readyState == 4 && xhr.status == 200) {
  4486. if (fn) {
  4487. var data = _trim(xhr.responseText);
  4488. if (dataType == 'json') {
  4489. data = _json(data);
  4490. }
  4491. fn(data);
  4492. }
  4493. }
  4494. };
  4495. if (method == 'POST') {
  4496. var params = [];
  4497. _each(param, function(key, val) {
  4498. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4499. });
  4500. try {
  4501. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4502. } catch (e) {}
  4503. xhr.send(params.join('&'));
  4504. } else {
  4505. xhr.send(null);
  4506. }
  4507. }
  4508. K.loadScript = _loadScript;
  4509. K.loadStyle = _loadStyle;
  4510. K.ajax = _ajax;
  4511. var _plugins = {};
  4512. function _plugin(name, fn) {
  4513. if (name === undefined) {
  4514. return _plugins;
  4515. }
  4516. if (!fn) {
  4517. return _plugins[name];
  4518. }
  4519. _plugins[name] = fn;
  4520. }
  4521. var _language = {};
  4522. function _parseLangKey(key) {
  4523. var match, ns = 'core';
  4524. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4525. ns = match[1];
  4526. key = match[2];
  4527. }
  4528. return { ns : ns, key : key };
  4529. }
  4530. function _lang(mixed, langType) {
  4531. langType = langType === undefined ? K.options.langType : langType;
  4532. if (typeof mixed === 'string') {
  4533. if (!_language[langType]) {
  4534. return 'no language';
  4535. }
  4536. var pos = mixed.length - 1;
  4537. if (mixed.substr(pos) === '.') {
  4538. return _language[langType][mixed.substr(0, pos)];
  4539. }
  4540. var obj = _parseLangKey(mixed);
  4541. return _language[langType][obj.ns][obj.key];
  4542. }
  4543. _each(mixed, function(key, val) {
  4544. var obj = _parseLangKey(key);
  4545. if (!_language[langType]) {
  4546. _language[langType] = {};
  4547. }
  4548. if (!_language[langType][obj.ns]) {
  4549. _language[langType][obj.ns] = {};
  4550. }
  4551. _language[langType][obj.ns][obj.key] = val;
  4552. });
  4553. }
  4554. function _getImageFromRange(range, fn) {
  4555. if (range.collapsed) {
  4556. return;
  4557. }
  4558. range = range.cloneRange().up();
  4559. var sc = range.startContainer, so = range.startOffset;
  4560. if (!_WEBKIT && !range.isControl()) {
  4561. return;
  4562. }
  4563. var img = K(sc.childNodes[so]);
  4564. if (!img || img.name != 'img') {
  4565. return;
  4566. }
  4567. if (fn(img)) {
  4568. return img;
  4569. }
  4570. }
  4571. function _bindContextmenuEvent() {
  4572. var self = this, doc = self.edit.doc;
  4573. K(doc).contextmenu(function(e) {
  4574. if (self.menu) {
  4575. self.hideMenu();
  4576. }
  4577. if (!self.useContextmenu) {
  4578. e.preventDefault();
  4579. return;
  4580. }
  4581. if (self._contextmenus.length === 0) {
  4582. return;
  4583. }
  4584. var maxWidth = 0, items = [];
  4585. _each(self._contextmenus, function() {
  4586. if (this.title == '-') {
  4587. items.push(this);
  4588. return;
  4589. }
  4590. if (this.cond && this.cond()) {
  4591. items.push(this);
  4592. if (this.width && this.width > maxWidth) {
  4593. maxWidth = this.width;
  4594. }
  4595. }
  4596. });
  4597. while (items.length > 0 && items[0].title == '-') {
  4598. items.shift();
  4599. }
  4600. while (items.length > 0 && items[items.length - 1].title == '-') {
  4601. items.pop();
  4602. }
  4603. var prevItem = null;
  4604. _each(items, function(i) {
  4605. if (this.title == '-' && prevItem.title == '-') {
  4606. delete items[i];
  4607. }
  4608. prevItem = this;
  4609. });
  4610. if (items.length > 0) {
  4611. e.preventDefault();
  4612. var pos = K(self.edit.iframe).pos(),
  4613. menu = _menu({
  4614. x : pos.x + e.clientX,
  4615. y : pos.y + e.clientY,
  4616. width : maxWidth,
  4617. css : { visibility: 'hidden' },
  4618. shadowMode : self.shadowMode
  4619. });
  4620. _each(items, function() {
  4621. if (this.title) {
  4622. menu.addItem(this);
  4623. }
  4624. });
  4625. var docEl = _docElement(menu.doc),
  4626. menuHeight = menu.div.height();
  4627. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4628. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4629. }
  4630. menu.div.css('visibility', 'visible');
  4631. self.menu = menu;
  4632. }
  4633. });
  4634. }
  4635. function _bindNewlineEvent() {
  4636. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4637. if (_IE && newlineTag !== 'br') {
  4638. return;
  4639. }
  4640. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4641. return;
  4642. }
  4643. if (_OPERA && _V < 9) {
  4644. return;
  4645. }
  4646. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4647. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4648. function getAncestorTagName(range) {
  4649. var ancestor = K(range.commonAncestor());
  4650. while (ancestor) {
  4651. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4652. break;
  4653. }
  4654. ancestor = ancestor.parent();
  4655. }
  4656. return ancestor.name;
  4657. }
  4658. K(doc).keydown(function(e) {
  4659. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4660. autoImg(self);
  4661. return;
  4662. }
  4663. self.cmd.selection();
  4664. var tagName = getAncestorTagName(self.cmd.range);
  4665. if (tagName == 'marquee' || tagName == 'select') {
  4666. return;
  4667. }
  4668. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4669. e.preventDefault();
  4670. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4671. return;
  4672. }
  4673. if (!pSkipTagMap[tagName]) {
  4674. _nativeCommand(doc, 'formatblock', '<p>');
  4675. }
  4676. });
  4677. K(doc).keyup(function(e) {
  4678. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4679. return;
  4680. }
  4681. if (newlineTag == 'br') {
  4682. return;
  4683. }
  4684. if (_GECKO) {
  4685. var root = self.cmd.commonAncestor('p');
  4686. var a = self.cmd.commonAncestor('a');
  4687. if (a && a.text() == '') {
  4688. a.remove(true);
  4689. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4690. self.cmd.select();
  4691. }
  4692. return;
  4693. }
  4694. self.cmd.selection();
  4695. var tagName = getAncestorTagName(self.cmd.range);
  4696. if (tagName == 'marquee' || tagName == 'select') {
  4697. return;
  4698. }
  4699. if (!pSkipTagMap[tagName]) {
  4700. _nativeCommand(doc, 'formatblock', '<p>');
  4701. }
  4702. var div = self.cmd.commonAncestor('div');
  4703. if (div) {
  4704. var p = K('<p></p>'),
  4705. child = div[0].firstChild;
  4706. while (child) {
  4707. var next = child.nextSibling;
  4708. p.append(child);
  4709. child = next;
  4710. }
  4711. div.before(p);
  4712. div.remove();
  4713. self.cmd.range.selectNodeContents(p[0]);
  4714. self.cmd.select();
  4715. }
  4716. });
  4717. }
  4718. function _bindTabEvent() {
  4719. var self = this, doc = self.edit.doc;
  4720. K(doc).keydown(function(e) {
  4721. if (e.which == 9) {
  4722. e.preventDefault();
  4723. if (self.afterTab) {
  4724. self.afterTab.call(self, e);
  4725. return;
  4726. }
  4727. var cmd = self.cmd, range = cmd.range;
  4728. range.shrink();
  4729. if (range.collapsed && range.startContainer.nodeType == 1) {
  4730. range.insertNode(K('@&nbsp;', doc)[0]);
  4731. cmd.select();
  4732. }
  4733. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4734. }
  4735. });
  4736. }
  4737. function _bindFocusEvent() {
  4738. var self = this;
  4739. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4740. if (self.afterFocus) {
  4741. self.afterFocus.call(self, e);
  4742. }
  4743. }).blur(function(e) {
  4744. if (self.afterBlur) {
  4745. self.afterBlur.call(self, e);
  4746. }
  4747. });
  4748. }
  4749. function _removeBookmarkTag(html) {
  4750. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4751. }
  4752. function _removeTempTag(html) {
  4753. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4754. }
  4755. function _addBookmarkToStack(stack, bookmark) {
  4756. if (stack.length === 0) {
  4757. stack.push(bookmark);
  4758. return;
  4759. }
  4760. var prev = stack[stack.length - 1];
  4761. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4762. stack.push(bookmark);
  4763. }
  4764. }
  4765. function _undoToRedo(fromStack, toStack) {
  4766. var self = this, edit = self.edit,
  4767. body = edit.doc.body,
  4768. range, bookmark;
  4769. if (fromStack.length === 0) {
  4770. return self;
  4771. }
  4772. if (edit.designMode) {
  4773. range = self.cmd.range;
  4774. bookmark = range.createBookmark(true);
  4775. bookmark.html = body.innerHTML;
  4776. } else {
  4777. bookmark = {
  4778. html : body.innerHTML
  4779. };
  4780. }
  4781. _addBookmarkToStack(toStack, bookmark);
  4782. var prev = fromStack.pop();
  4783. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4784. prev = fromStack.pop();
  4785. }
  4786. if (edit.designMode) {
  4787. edit.html(prev.html);
  4788. if (prev.start) {
  4789. range.moveToBookmark(prev);
  4790. self.select();
  4791. }
  4792. } else {
  4793. K(body).html(_removeBookmarkTag(prev.html));
  4794. }
  4795. return self;
  4796. }
  4797. function KEditor(options) {
  4798. var self = this;
  4799. self.options = {};
  4800. function setOption(key, val) {
  4801. if (KEditor.prototype[key] === undefined) {
  4802. self[key] = val;
  4803. }
  4804. self.options[key] = val;
  4805. }
  4806. _each(options, function(key, val) {
  4807. setOption(key, options[key]);
  4808. });
  4809. _each(K.options, function(key, val) {
  4810. if (self[key] === undefined) {
  4811. setOption(key, val);
  4812. }
  4813. });
  4814. var se = K(self.srcElement || '<textarea/>');
  4815. if (!self.width) {
  4816. self.width = se[0].style.width || se.width();
  4817. if (!self.width) {
  4818. self.width = '700';
  4819. }
  4820. }
  4821. if (!self.height) {
  4822. self.height = se[0].style.height || se.height();
  4823. }
  4824. setOption('width', _undef(self.width, self.minWidth));
  4825. setOption('height', _undef(self.height, self.minHeight));
  4826. setOption('width', _addUnit(self.width));
  4827. setOption('height', _addUnit(self.height));
  4828. if (_MOBILE && (!_IOS || _V < 534)) {
  4829. //self.designMode = false;
  4830. }
  4831. self.srcElement = se;
  4832. self.initContent = '';
  4833. self.plugin = {};
  4834. self.isCreated = false;
  4835. self._handlers = {};
  4836. self._contextmenus = [];
  4837. self._undoStack = [];
  4838. self._redoStack = [];
  4839. self._firstAddBookmark = true;
  4840. self.menu = self.contextmenu = null;
  4841. self.dialogs = [];
  4842. }
  4843. KEditor.prototype = {
  4844. lang : function(mixed) {
  4845. return _lang(mixed, this.langType);
  4846. },
  4847. loadPlugin : function(name, fn) {
  4848. var self = this;
  4849. var _pluginStatus = this._pluginStatus;
  4850. if (!_pluginStatus) {
  4851. _pluginStatus = this._pluginStatus = {};
  4852. }
  4853. if (_plugins[name]) {
  4854. if (!_isFunction(_plugins[name])) {
  4855. setTimeout(function() {
  4856. self.loadPlugin(name, fn);
  4857. }, 100);
  4858. return self;
  4859. }
  4860. if(!_pluginStatus[name]) {
  4861. _plugins[name].call(self, KindEditor);
  4862. _pluginStatus[name] = 'inited';
  4863. }
  4864. if (fn) {
  4865. fn.call(self);
  4866. }
  4867. return self;
  4868. }
  4869. _plugins[name] = 'loading';
  4870. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4871. setTimeout(function() {
  4872. if (_plugins[name]) {
  4873. self.loadPlugin(name, fn);
  4874. }
  4875. }, 0);
  4876. });
  4877. return self;
  4878. },
  4879. handler : function(key, fn) {
  4880. var self = this;
  4881. if (!self._handlers[key]) {
  4882. self._handlers[key] = [];
  4883. }
  4884. if (_isFunction(fn)) {
  4885. self._handlers[key].push(fn);
  4886. return self;
  4887. }
  4888. _each(self._handlers[key], function() {
  4889. fn = this.call(self, fn);
  4890. });
  4891. return fn;
  4892. },
  4893. clickToolbar : function(name, fn) {
  4894. var self = this, key = 'clickToolbar' + name;
  4895. if (fn === undefined) {
  4896. if (self._handlers[key]) {
  4897. return self.handler(key);
  4898. }
  4899. self.loadPlugin(name, function() {
  4900. self.handler(key);
  4901. });
  4902. return self;
  4903. }
  4904. return self.handler(key, fn);
  4905. },
  4906. updateState : function() {
  4907. var self = this;
  4908. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4909. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4910. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4911. });
  4912. return self;
  4913. },
  4914. addContextmenu : function(item) {
  4915. this._contextmenus.push(item);
  4916. return this;
  4917. },
  4918. afterCreate : function(fn) {
  4919. return this.handler('afterCreate', fn);
  4920. },
  4921. beforeRemove : function(fn) {
  4922. return this.handler('beforeRemove', fn);
  4923. },
  4924. beforeGetHtml : function(fn) {
  4925. return this.handler('beforeGetHtml', fn);
  4926. },
  4927. beforeSetHtml : function(fn) {
  4928. return this.handler('beforeSetHtml', fn);
  4929. },
  4930. afterSetHtml : function(fn) {
  4931. return this.handler('afterSetHtml', fn);
  4932. },
  4933. create : function() {
  4934. var self = this, fullscreenMode = self.fullscreenMode;
  4935. if (self.isCreated) {
  4936. return self;
  4937. }
  4938. if (self.srcElement.data('kindeditor')) {
  4939. return self;
  4940. }
  4941. self.srcElement.data('kindeditor', 'true');
  4942. if (fullscreenMode) {
  4943. _docElement().style.overflow = 'hidden';
  4944. } else {
  4945. _docElement().style.overflow = '';
  4946. }
  4947. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4948. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4949. if ((_IE && _V < 8) || _QUIRKS) {
  4950. height = _addUnit(_removeUnit(height) + 2);
  4951. }
  4952. var container = self.container = K(self.layout);
  4953. if (fullscreenMode) {
  4954. K(document.body).append(container);
  4955. } else {
  4956. self.srcElement.before(container);
  4957. }
  4958. var toolbarDiv = K('.toolbar', container),
  4959. editDiv = K('.edit', container),
  4960. statusbar = self.statusbar = K('.statusbar', container);
  4961. container.removeClass('container')
  4962. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4963. if (fullscreenMode) {
  4964. container.css({
  4965. position : 'absolute',
  4966. left : 0,
  4967. top : 0,
  4968. 'z-index' : 811211
  4969. });
  4970. if (!_GECKO) {
  4971. self._scrollPos = _getScrollPos();
  4972. }
  4973. window.scrollTo(0, 0);
  4974. K(document.body).css({
  4975. 'height' : '1px',
  4976. 'overflow' : 'hidden'
  4977. });
  4978. K(document.body.parentNode).css('overflow', 'hidden');
  4979. self._fullscreenExecuted = true;
  4980. } else {
  4981. if (self._fullscreenExecuted) {
  4982. K(document.body).css({
  4983. 'height' : '',
  4984. 'overflow' : ''
  4985. });
  4986. K(document.body.parentNode).css('overflow', '');
  4987. }
  4988. if (self._scrollPos) {
  4989. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4990. }
  4991. }
  4992. var htmlList = [];
  4993. K.each(self.items, function(i, name) {
  4994. if (name == '|') {
  4995. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4996. } else if (name == '/') {
  4997. htmlList.push('<div class="ke-hr"></div>');
  4998. } else {
  4999. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  5000. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  5001. }
  5002. });
  5003. var toolbar = self.toolbar = _toolbar({
  5004. src : toolbarDiv,
  5005. html : htmlList.join(''),
  5006. noDisableItems : self.noDisableItems,
  5007. click : function(e, name) {
  5008. e.stop();
  5009. if (self.menu) {
  5010. var menuName = self.menu.name;
  5011. self.hideMenu();
  5012. if (menuName === name) {
  5013. return;
  5014. }
  5015. }
  5016. self.clickToolbar(name);
  5017. }
  5018. });
  5019. var editHeight = _removeUnit(height) - toolbar.div.height();
  5020. var edit = self.edit = _edit({
  5021. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5022. src : editDiv,
  5023. srcElement : self.srcElement,
  5024. designMode : self.designMode,
  5025. themesPath : self.themesPath,
  5026. bodyClass : self.bodyClass,
  5027. cssPath : self.cssPath,
  5028. cssData : self.cssData,
  5029. beforeGetHtml : function(html) {
  5030. html = self.beforeGetHtml(html);
  5031. html = _removeBookmarkTag(_removeTempTag(html));
  5032. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5033. },
  5034. beforeSetHtml : function(html) {
  5035. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5036. return self.beforeSetHtml(html);
  5037. },
  5038. afterSetHtml : function() {
  5039. self.edit = edit = this;
  5040. self.afterSetHtml();
  5041. },
  5042. afterCreate : function() {
  5043. self.edit = edit = this;
  5044. self.cmd = edit.cmd;
  5045. self._docMousedownFn = function(e) {
  5046. if (self.menu) {
  5047. self.hideMenu();
  5048. }
  5049. };
  5050. K(edit.doc, document).mousedown(self._docMousedownFn);
  5051. _bindContextmenuEvent.call(self);
  5052. _bindNewlineEvent.call(self);
  5053. _bindTabEvent.call(self);
  5054. _bindFocusEvent.call(self);
  5055. edit.afterChange(function(e) {
  5056. if (!edit.designMode) {
  5057. return;
  5058. }
  5059. self.updateState();
  5060. self.addBookmark();
  5061. if (self.options.afterChange) {
  5062. self.options.afterChange.call(self);
  5063. }
  5064. });
  5065. edit.textarea.keyup(function(e) {
  5066. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5067. if (self.options.afterChange) {
  5068. self.options.afterChange.call(self);
  5069. }
  5070. }
  5071. });
  5072. if (self.readonlyMode) {
  5073. self.readonly();
  5074. }
  5075. self.isCreated = true;
  5076. if (self.initContent === '') {
  5077. self.initContent = self.html();
  5078. }
  5079. if (self._undoStack.length > 0) {
  5080. var prev = self._undoStack.pop();
  5081. if (prev.start) {
  5082. self.html(prev.html);
  5083. edit.cmd.range.moveToBookmark(prev);
  5084. self.select();
  5085. }
  5086. }
  5087. self.afterCreate();
  5088. if (self.options.afterCreate) {
  5089. self.options.afterCreate.call(self);
  5090. }
  5091. }
  5092. });
  5093. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5094. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5095. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5096. if (self._fullscreenResizeHandler) {
  5097. K(window).unbind('resize', self._fullscreenResizeHandler);
  5098. self._fullscreenResizeHandler = null;
  5099. }
  5100. function initResize() {
  5101. if (statusbar.height() === 0) {
  5102. setTimeout(initResize, 100);
  5103. return;
  5104. }
  5105. self.resize(width, height, false);
  5106. }
  5107. initResize();
  5108. if (fullscreenMode) {
  5109. self._fullscreenResizeHandler = function(e) {
  5110. if (self.isCreated) {
  5111. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5112. }
  5113. };
  5114. K(window).bind('resize', self._fullscreenResizeHandler);
  5115. toolbar.select('fullscreen');
  5116. statusbar.first().css('visibility', 'hidden');
  5117. statusbar.last().css('visibility', 'hidden');
  5118. } else {
  5119. if (_GECKO) {
  5120. K(window).bind('scroll', function(e) {
  5121. self._scrollPos = _getScrollPos();
  5122. });
  5123. }
  5124. if (self.resizeType > 0) {
  5125. _drag({
  5126. moveEl : container,
  5127. clickEl : statusbar,
  5128. moveFn : function(x, y, width, height, diffX, diffY) {
  5129. height += diffY;
  5130. self.resize(null, height);
  5131. }
  5132. });
  5133. } else {
  5134. statusbar.first().css('visibility', 'hidden');
  5135. }
  5136. if (self.resizeType === 2) {
  5137. _drag({
  5138. moveEl : container,
  5139. clickEl : statusbar.last(),
  5140. moveFn : function(x, y, width, height, diffX, diffY) {
  5141. width += diffX;
  5142. height += diffY;
  5143. self.resize(width, height);
  5144. }
  5145. });
  5146. } else {
  5147. statusbar.last().css('visibility', 'hidden');
  5148. }
  5149. }
  5150. return self;
  5151. },
  5152. remove : function() {
  5153. var self = this;
  5154. if (!self.isCreated) {
  5155. return self;
  5156. }
  5157. self.beforeRemove();
  5158. self.srcElement.data('kindeditor', '');
  5159. if (self.menu) {
  5160. self.hideMenu();
  5161. }
  5162. _each(self.dialogs, function() {
  5163. self.hideDialog();
  5164. });
  5165. K(document).unbind('mousedown', self._docMousedownFn);
  5166. self.toolbar.remove();
  5167. self.edit.remove();
  5168. self.statusbar.last().unbind();
  5169. self.statusbar.unbind();
  5170. self.container.remove();
  5171. self.container = self.toolbar = self.edit = self.menu = null;
  5172. self.dialogs = [];
  5173. self.isCreated = false;
  5174. return self;
  5175. },
  5176. resize : function(width, height, updateProp) {
  5177. var self = this;
  5178. updateProp = _undef(updateProp, true);
  5179. if (width) {
  5180. if (!/%/.test(width)) {
  5181. width = _removeUnit(width);
  5182. width = width < self.minWidth ? self.minWidth : width;
  5183. }
  5184. self.container.css('width', _addUnit(width));
  5185. if (updateProp) {
  5186. self.width = _addUnit(width);
  5187. }
  5188. }
  5189. if (height) {
  5190. height = _removeUnit(height);
  5191. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5192. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5193. self.edit.setHeight(editHeight);
  5194. if (updateProp) {
  5195. self.height = _addUnit(height);
  5196. }
  5197. }
  5198. return self;
  5199. },
  5200. select : function() {
  5201. this.isCreated && this.cmd.select();
  5202. return this;
  5203. },
  5204. html : function(val) {
  5205. var self = this;
  5206. if (val === undefined) {
  5207. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5208. }
  5209. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5210. if (self.isCreated) {
  5211. self.cmd.selection();
  5212. }
  5213. return self;
  5214. },
  5215. fullHtml : function() {
  5216. return this.isCreated ? this.edit.html(undefined, true) : '';
  5217. },
  5218. text : function(val) {
  5219. var self = this;
  5220. if (val === undefined) {
  5221. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5222. } else {
  5223. return self.html(_escape(val));
  5224. }
  5225. },
  5226. isEmpty : function() {
  5227. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5228. },
  5229. isDirty : function() {
  5230. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5231. },
  5232. selectedHtml : function() {
  5233. var val = this.isCreated ? this.cmd.range.html() : '';
  5234. val = _removeBookmarkTag(_removeTempTag(val));
  5235. return val;
  5236. },
  5237. count : function(mode) {
  5238. var self = this;
  5239. mode = (mode || 'html').toLowerCase();
  5240. if (mode === 'html') {
  5241. return self.html().length;
  5242. }
  5243. if (mode === 'text') {
  5244. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5245. }
  5246. return 0;
  5247. },
  5248. exec : function(key) {
  5249. key = key.toLowerCase();
  5250. var self = this, cmd = self.cmd,
  5251. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5252. if (changeFlag) {
  5253. self.addBookmark(false);
  5254. }
  5255. cmd[key].apply(cmd, _toArray(arguments, 1));
  5256. if (changeFlag) {
  5257. self.updateState();
  5258. self.addBookmark(false);
  5259. if (self.options.afterChange) {
  5260. self.options.afterChange.call(self);
  5261. }
  5262. }
  5263. return self;
  5264. },
  5265. insertHtml : function(val, quickMode) {
  5266. if (!this.isCreated) {
  5267. return this;
  5268. }
  5269. val = this.beforeSetHtml(val);
  5270. this.exec('inserthtml', val, quickMode);
  5271. return this;
  5272. },
  5273. appendHtml : function(val) {
  5274. this.html(this.html() + val);
  5275. if (this.isCreated) {
  5276. var cmd = this.cmd;
  5277. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5278. cmd.select();
  5279. }
  5280. return this;
  5281. },
  5282. sync : function() {
  5283. _elementVal(this.srcElement, this.html());
  5284. return this;
  5285. },
  5286. focus : function() {
  5287. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5288. return this;
  5289. },
  5290. blur : function() {
  5291. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5292. return this;
  5293. },
  5294. addBookmark : function(checkSize) {
  5295. checkSize = _undef(checkSize, true);
  5296. var self = this, edit = self.edit,
  5297. body = edit.doc.body,
  5298. html = _removeTempTag(body.innerHTML), bookmark;
  5299. if (checkSize && self._undoStack.length > 0) {
  5300. var prev = self._undoStack[self._undoStack.length - 1];
  5301. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5302. return self;
  5303. }
  5304. }
  5305. if (edit.designMode && !self._firstAddBookmark) {
  5306. var range = self.cmd.range;
  5307. bookmark = range.createBookmark(true);
  5308. bookmark.html = _removeTempTag(body.innerHTML);
  5309. range.moveToBookmark(bookmark);
  5310. } else {
  5311. bookmark = {
  5312. html : html
  5313. };
  5314. }
  5315. self._firstAddBookmark = false;
  5316. _addBookmarkToStack(self._undoStack, bookmark);
  5317. return self;
  5318. },
  5319. undo : function() {
  5320. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5321. },
  5322. redo : function() {
  5323. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5324. },
  5325. fullscreen : function(bool) {
  5326. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5327. this.addBookmark(false);
  5328. return this.remove().create();
  5329. },
  5330. readonly : function(isReadonly) {
  5331. isReadonly = _undef(isReadonly, true);
  5332. var self = this, edit = self.edit, doc = edit.doc;
  5333. if (self.designMode) {
  5334. self.toolbar.disableAll(isReadonly, []);
  5335. } else {
  5336. _each(self.noDisableItems, function() {
  5337. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5338. });
  5339. }
  5340. if (_IE) {
  5341. doc.body.contentEditable = !isReadonly;
  5342. } else {
  5343. doc.designMode = isReadonly ? 'off' : 'on';
  5344. }
  5345. edit.textarea[0].disabled = isReadonly;
  5346. },
  5347. createMenu : function(options) {
  5348. var self = this,
  5349. name = options.name,
  5350. knode = self.toolbar.get(name),
  5351. pos = knode.pos();
  5352. options.x = pos.x;
  5353. options.y = pos.y + knode.height();
  5354. options.z = self.options.zIndex;
  5355. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5356. if (options.selectedColor !== undefined) {
  5357. options.cls = 'ke-colorpicker-' + self.themeType;
  5358. options.noColor = self.lang('noColor');
  5359. self.menu = _colorpicker(options);
  5360. } else {
  5361. options.cls = 'ke-menu-' + self.themeType;
  5362. options.centerLineMode = false;
  5363. self.menu = _menu(options);
  5364. }
  5365. return self.menu;
  5366. },
  5367. hideMenu : function() {
  5368. this.menu.remove();
  5369. this.menu = null;
  5370. return this;
  5371. },
  5372. hideContextmenu : function() {
  5373. this.contextmenu.remove();
  5374. this.contextmenu = null;
  5375. return this;
  5376. },
  5377. createDialog : function(options) {
  5378. var self = this, name = options.name;
  5379. options.z = self.options.zIndex;
  5380. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5381. options.closeBtn = _undef(options.closeBtn, {
  5382. name : self.lang('close'),
  5383. click : function(e) {
  5384. self.hideDialog();
  5385. if (_IE && self.cmd) {
  5386. self.cmd.select();
  5387. }
  5388. }
  5389. });
  5390. options.noBtn = _undef(options.noBtn, {
  5391. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5392. click : function(e) {
  5393. self.hideDialog();
  5394. if (_IE && self.cmd) {
  5395. self.cmd.select();
  5396. }
  5397. }
  5398. });
  5399. if (self.dialogAlignType != 'page') {
  5400. options.alignEl = self.container;
  5401. }
  5402. options.cls = 'ke-dialog-' + self.themeType;
  5403. if (self.dialogs.length > 0) {
  5404. var firstDialog = self.dialogs[0],
  5405. parentDialog = self.dialogs[self.dialogs.length - 1];
  5406. firstDialog.setMaskIndex(parentDialog.z + 2);
  5407. options.z = parentDialog.z + 3;
  5408. options.showMask = false;
  5409. }
  5410. var dialog = _dialog(options);
  5411. self.dialogs.push(dialog);
  5412. return dialog;
  5413. },
  5414. hideDialog : function() {
  5415. var self = this;
  5416. if (self.dialogs.length > 0) {
  5417. self.dialogs.pop().remove();
  5418. }
  5419. if (self.dialogs.length > 0) {
  5420. var firstDialog = self.dialogs[0],
  5421. parentDialog = self.dialogs[self.dialogs.length - 1];
  5422. firstDialog.setMaskIndex(parentDialog.z - 1);
  5423. }
  5424. return self;
  5425. },
  5426. errorDialog : function(html) {
  5427. var self = this;
  5428. var dialog = self.createDialog({
  5429. width : 750,
  5430. title : self.lang('uploadError'),
  5431. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5432. });
  5433. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5434. doc.open();
  5435. doc.write(html);
  5436. doc.close();
  5437. K(doc.body).css('background-color', '#FFF');
  5438. iframe[0].contentWindow.focus();
  5439. return self;
  5440. }
  5441. };
  5442. function _editor(options) {
  5443. return new KEditor(options);
  5444. }
  5445. var _instances = [];
  5446. function _create(expr, options) {
  5447. options = options || {};
  5448. options.basePath = _undef(options.basePath, K.basePath);
  5449. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5450. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5451. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5452. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5453. var themeType = _undef(options.themeType, K.options.themeType);
  5454. _loadStyle(options.themesPath + 'default/default.css');
  5455. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5456. }
  5457. function create(editor) {
  5458. _each(_plugins, function(name, fn) {
  5459. if (_isFunction(fn)) {
  5460. fn.call(editor, KindEditor);
  5461. if (!editor._pluginStatus) {
  5462. editor._pluginStatus = {};
  5463. }
  5464. editor._pluginStatus[name] = 'inited';
  5465. }
  5466. });
  5467. return editor.create();
  5468. }
  5469. var knode = K(expr);
  5470. if (!knode || knode.length === 0) {
  5471. return;
  5472. }
  5473. if (knode.length > 1) {
  5474. knode.each(function() {
  5475. _create(this, options);
  5476. });
  5477. return _instances[0];
  5478. }
  5479. options.srcElement = knode[0];
  5480. var editor = new KEditor(options);
  5481. _instances.push(editor);
  5482. if (_language[editor.langType]) {
  5483. return create(editor);
  5484. }
  5485. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5486. create(editor);
  5487. });
  5488. return editor;
  5489. }
  5490. function _eachEditor(expr, fn) {
  5491. K(expr).each(function(i, el) {
  5492. K.each(_instances, function(j, editor) {
  5493. if (editor && editor.srcElement[0] == el) {
  5494. fn.call(editor, j);
  5495. return false;
  5496. }
  5497. });
  5498. });
  5499. }
  5500. K.remove = function(expr) {
  5501. _eachEditor(expr, function(i) {
  5502. this.remove();
  5503. _instances.splice(i, 1);
  5504. });
  5505. };
  5506. K.sync = function(expr) {
  5507. _eachEditor(expr, function() {
  5508. this.sync();
  5509. });
  5510. };
  5511. K.html = function(expr, val) {
  5512. _eachEditor(expr, function() {
  5513. this.html(val);
  5514. });
  5515. };
  5516. K.insertHtml = function(expr, val) {
  5517. _eachEditor(expr, function() {
  5518. this.insertHtml(val);
  5519. });
  5520. };
  5521. K.appendHtml = function(expr, val) {
  5522. _eachEditor(expr, function() {
  5523. this.appendHtml(val);
  5524. });
  5525. };
  5526. if (_IE && _V < 7) {
  5527. _nativeCommand(document, 'BackgroundImageCache', true);
  5528. }
  5529. K.EditorClass = KEditor;
  5530. K.editor = _editor;
  5531. K.create = _create;
  5532. K.instances = _instances;
  5533. K.plugin = _plugin;
  5534. K.lang = _lang;
  5535. _plugin('core', function(K) {
  5536. var self = this,
  5537. shortcutKeys = {
  5538. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5539. };
  5540. self.afterSetHtml(function() {
  5541. if (self.options.afterChange) {
  5542. self.options.afterChange.call(self);
  5543. }
  5544. });
  5545. self.afterCreate(function() {
  5546. if (self.syncType != 'form') {
  5547. return;
  5548. }
  5549. var el = K(self.srcElement), hasForm = false;
  5550. while ((el = el.parent())) {
  5551. if (el.name == 'form') {
  5552. hasForm = true;
  5553. break;
  5554. }
  5555. }
  5556. if (hasForm) {
  5557. el.bind('submit', function(e) {
  5558. self.sync();
  5559. K(window).bind('unload', function() {
  5560. self.edit.textarea.remove();
  5561. });
  5562. });
  5563. var resetBtn = K('[type="reset"]', el);
  5564. resetBtn.click(function() {
  5565. self.html(self.initContent);
  5566. self.cmd.selection();
  5567. });
  5568. self.beforeRemove(function() {
  5569. el.unbind();
  5570. resetBtn.unbind();
  5571. });
  5572. }
  5573. });
  5574. self.clickToolbar('source', function() {
  5575. if (self.edit.designMode) {
  5576. self.toolbar.disableAll(true);
  5577. self.edit.design(false);
  5578. self.toolbar.select('source');
  5579. } else {
  5580. self.toolbar.disableAll(false);
  5581. self.edit.design(true);
  5582. self.toolbar.unselect('source');
  5583. if (_GECKO) {
  5584. setTimeout(function() {
  5585. self.cmd.selection();
  5586. }, 0);
  5587. } else {
  5588. self.cmd.selection();
  5589. }
  5590. }
  5591. self.designMode = self.edit.designMode;
  5592. });
  5593. self.afterCreate(function() {
  5594. if (!self.designMode) {
  5595. self.toolbar.disableAll(true).select('source');
  5596. }
  5597. });
  5598. self.clickToolbar('fullscreen', function() {
  5599. self.fullscreen();
  5600. });
  5601. if (self.fullscreenShortcut) {
  5602. var loaded = false;
  5603. self.afterCreate(function() {
  5604. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5605. if (e.which == 27) {
  5606. setTimeout(function() {
  5607. self.fullscreen();
  5608. }, 0);
  5609. }
  5610. });
  5611. if (loaded) {
  5612. if (_IE && !self.designMode) {
  5613. return;
  5614. }
  5615. self.focus();
  5616. }
  5617. if (!loaded) {
  5618. loaded = true;
  5619. }
  5620. });
  5621. }
  5622. _each('undo,redo'.split(','), function(i, name) {
  5623. if (shortcutKeys[name]) {
  5624. self.afterCreate(function() {
  5625. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5626. self.clickToolbar(name);
  5627. });
  5628. });
  5629. }
  5630. self.clickToolbar(name, function() {
  5631. self[name]();
  5632. });
  5633. });
  5634. self.clickToolbar('formatblock', function() {
  5635. var blocks = self.lang('formatblock.formatBlock'),
  5636. heights = {
  5637. h1 : 28,
  5638. h2 : 24,
  5639. h3 : 18,
  5640. H4 : 14,
  5641. p : 12
  5642. },
  5643. curVal = self.cmd.val('formatblock'),
  5644. menu = self.createMenu({
  5645. name : 'formatblock',
  5646. width : self.langType == 'en' ? 200 : 150
  5647. });
  5648. _each(blocks, function(key, val) {
  5649. var style = 'font-size:' + heights[key] + 'px;';
  5650. if (key.charAt(0) === 'h') {
  5651. style += 'font-weight:bold;';
  5652. }
  5653. menu.addItem({
  5654. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5655. height : heights[key] + 12,
  5656. checked : (curVal === key || curVal === val),
  5657. click : function() {
  5658. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5659. }
  5660. });
  5661. });
  5662. });
  5663. self.clickToolbar('fontname', function() {
  5664. var curVal = self.cmd.val('fontname'),
  5665. menu = self.createMenu({
  5666. name : 'fontname',
  5667. width : 150
  5668. });
  5669. _each(self.lang('fontname.fontName'), function(key, val) {
  5670. menu.addItem({
  5671. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5672. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5673. click : function() {
  5674. self.exec('fontname', key).hideMenu();
  5675. }
  5676. });
  5677. });
  5678. });
  5679. self.clickToolbar('fontsize', function() {
  5680. var curVal = self.cmd.val('fontsize'),
  5681. menu = self.createMenu({
  5682. name : 'fontsize',
  5683. width : 150
  5684. });
  5685. _each(self.fontSizeTable, function(i, val) {
  5686. menu.addItem({
  5687. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5688. height : _removeUnit(val) + 12,
  5689. checked : curVal === val,
  5690. click : function() {
  5691. self.exec('fontsize', val).hideMenu();
  5692. }
  5693. });
  5694. });
  5695. });
  5696. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5697. self.clickToolbar(name, function() {
  5698. self.createMenu({
  5699. name : name,
  5700. selectedColor : self.cmd.val(name) || 'default',
  5701. colors : self.colorTable,
  5702. click : function(color) {
  5703. self.exec(name, color).hideMenu();
  5704. }
  5705. });
  5706. });
  5707. });
  5708. _each(('cut,copy,paste').split(','), function(i, name) {
  5709. self.clickToolbar(name, function() {
  5710. self.focus();
  5711. try {
  5712. self.exec(name, null);
  5713. } catch(e) {
  5714. alert(self.lang(name + 'Error'));
  5715. }
  5716. });
  5717. });
  5718. self.clickToolbar('about', function() {
  5719. var html = '<div style="margin:20px;">' +
  5720. '<div>KindEditor ' + _VERSION + '</div>' +
  5721. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5722. '</div>';
  5723. self.createDialog({
  5724. name : 'about',
  5725. width : 350,
  5726. title : self.lang('about'),
  5727. body : html
  5728. });
  5729. });
  5730. self.plugin.getSelectedLink = function() {
  5731. return self.cmd.commonAncestor('a');
  5732. };
  5733. self.plugin.getSelectedImage = function() {
  5734. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5735. return !/^ke-\w+$/i.test(img[0].className);
  5736. });
  5737. };
  5738. self.plugin.getSelectedFlash = function() {
  5739. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5740. return img[0].className == 'ke-flash';
  5741. });
  5742. };
  5743. self.plugin.getSelectedMedia = function() {
  5744. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5745. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5746. });
  5747. };
  5748. self.plugin.getSelectedAnchor = function() {
  5749. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5750. return img[0].className == 'ke-anchor';
  5751. });
  5752. };
  5753. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5754. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5755. _each('edit,delete'.split(','), function(j, val) {
  5756. self.addContextmenu({
  5757. title : self.lang(val + uName),
  5758. click : function() {
  5759. self.loadPlugin(name, function() {
  5760. self.plugin[name][val]();
  5761. self.hideMenu();
  5762. });
  5763. },
  5764. cond : self.plugin['getSelected' + uName],
  5765. width : 150,
  5766. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5767. });
  5768. });
  5769. self.addContextmenu({ title : '-' });
  5770. });
  5771. self.plugin.getSelectedTable = function() {
  5772. return self.cmd.commonAncestor('table');
  5773. };
  5774. self.plugin.getSelectedRow = function() {
  5775. return self.cmd.commonAncestor('tr');
  5776. };
  5777. self.plugin.getSelectedCell = function() {
  5778. return self.cmd.commonAncestor('td');
  5779. };
  5780. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5781. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5782. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5783. self.addContextmenu({
  5784. title : self.lang('table' + val),
  5785. click : function() {
  5786. self.loadPlugin('table', function() {
  5787. self.plugin.table[val]();
  5788. self.hideMenu();
  5789. });
  5790. },
  5791. cond : cond,
  5792. width : 170,
  5793. iconClass : 'ke-icon-table' + val
  5794. });
  5795. });
  5796. self.addContextmenu({ title : '-' });
  5797. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5798. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5799. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5800. if (shortcutKeys[name]) {
  5801. self.afterCreate(function() {
  5802. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5803. self.cmd.selection();
  5804. self.clickToolbar(name);
  5805. });
  5806. });
  5807. }
  5808. self.clickToolbar(name, function() {
  5809. self.focus().exec(name, null);
  5810. });
  5811. });
  5812. self.afterCreate(function() {
  5813. var doc = self.edit.doc, cmd, bookmark, div,
  5814. cls = '__kindeditor_paste__', pasting = false;
  5815. function movePastedData() {
  5816. cmd.range.moveToBookmark(bookmark);
  5817. cmd.select();
  5818. if (_WEBKIT) {
  5819. K('div.' + cls, div).each(function() {
  5820. K(this).after('<br />').remove(true);
  5821. });
  5822. K('span.Apple-style-span', div).remove(true);
  5823. K('span.Apple-tab-span', div).remove(true);
  5824. K('span[style]', div).each(function() {
  5825. if (K(this).css('white-space') == 'nowrap') {
  5826. K(this).remove(true);
  5827. }
  5828. });
  5829. K('meta', div).remove();
  5830. }
  5831. var html = div[0].innerHTML;
  5832. div.remove();
  5833. if (html === '') {
  5834. return;
  5835. }
  5836. if (_WEBKIT) {
  5837. html = html.replace(/(<br>)\1/ig, '$1');
  5838. }
  5839. if (self.pasteType === 2) {
  5840. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5841. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5842. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5843. } else {
  5844. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5845. html = self.beforeSetHtml(html);
  5846. }
  5847. }
  5848. if (self.pasteType === 1) {
  5849. html = html.replace(/&nbsp;/ig, ' ');
  5850. html = html.replace(/\n\s*\n/g, '\n');
  5851. html = html.replace(/<br[^>]*>/ig, '\n');
  5852. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5853. html = html.replace(/<[^>]+>/g, '');
  5854. html = html.replace(/ {2}/g, ' &nbsp;');
  5855. if (self.newlineTag == 'p') {
  5856. if (/\n/.test(html)) {
  5857. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5858. }
  5859. } else {
  5860. html = html.replace(/\n/g, '<br />$&');
  5861. }
  5862. }
  5863. self.insertHtml(html, true);
  5864. }
  5865. K(doc.body).bind('paste', function(e){
  5866. //处理IE11,Chrome粘贴图片上传
  5867. function dopasteImg() {
  5868. //debugger;
  5869. var file = null;
  5870. if (window.clipboardData) {//ie
  5871. if (clipboardData.files && clipboardData.files.length)//IE11
  5872. file = clipboardData.files[0];
  5873. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5874. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5875. return true;
  5876. }
  5877. } else {
  5878. if (e.event.clipboardData.items)//chrome
  5879. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5880. if (e.event.clipboardData.items[i].kind === "file") {
  5881. file = e.event.clipboardData.items[i];
  5882. break;
  5883. }
  5884. }
  5885. if (file == null) {
  5886. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5887. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5888. return true;
  5889. }
  5890. }
  5891. }
  5892. if (file) {
  5893. if (!K.undef(self.allowImageUpload, true)) {
  5894. alert("编辑器禁止上传图片,请与有关人员联系!");
  5895. return true;
  5896. }
  5897. //获取File Blob
  5898. //debugger;
  5899. var blb;
  5900. if (file.getAsFile) {//Chrome
  5901. blb = file.getAsFile();
  5902. if (blb.size === 0) {
  5903. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5904. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5905. return true;
  5906. }
  5907. sendfile(blb, file.type);
  5908. } else {
  5909. var fr = new FileReader();
  5910. if (fr.readAsArrayBuffer) {//ie
  5911. fr.onloadend = function (evt) {
  5912. blb = evt.target.result;
  5913. sendfile(blb, file.type);
  5914. }
  5915. fr.readAsArrayBuffer(file);
  5916. }
  5917. }
  5918. function sendfile(b, t) {
  5919. var xhr = new XMLHttpRequest();
  5920. var formData = new FormData();
  5921. var isImg = t.indexOf("image/") === 0;
  5922. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5923. //formData.append('imgFile', b);
  5924. var myBlob = new Blob([b], { "type": t });
  5925. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5926. //formData.append('imgFile', b);
  5927. formData.append('dir', isImg ? 'image' : 'file');
  5928. if (self.uploadYunJson && self.uploadYunJson.domain) {
  5929. formData.append('token', self.uploadYunJson.token);
  5930. xhr.open('POST', self.uploadYunJson.domain);
  5931. } else {
  5932. xhr.open('POST', self.uploadJson);
  5933. }
  5934. xhr.onreadystatechange = function () {
  5935. if (xhr.readyState == 4&&xhr.status == 200) {
  5936. // if (fn) {
  5937. var data = _trim(xhr.responseText);
  5938. //if (dataType == 'json') {
  5939. data = _json(data);
  5940. if (data.error) {
  5941. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5942. $.messager.alert('Error', data.message, 'warning');
  5943. } else {
  5944. alert(data.message);
  5945. }
  5946. } else {
  5947. //self.exec('insertimage', url, title, width, height, border, align);
  5948. if(K.undef(self.formatUploadUrl, true))
  5949. data.url =K.formatUrl(data.url, 'absolute');
  5950. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5951. }
  5952. //}
  5953. // fn(data);
  5954. // }
  5955. }
  5956. }
  5957. xhr.send(formData);
  5958. }
  5959. return true;
  5960. }
  5961. }
  5962. //debugger;
  5963. if (dopasteImg())
  5964. e.stop();
  5965. //处理粘贴结束5825
  5966. if (self.pasteType === 0) {
  5967. e.stop();
  5968. return;
  5969. }
  5970. if (pasting) {
  5971. return;
  5972. }
  5973. pasting = true;
  5974. K('div.' + cls, doc).remove();
  5975. cmd = self.cmd.selection();
  5976. bookmark = cmd.range.createBookmark();
  5977. div = K('<div class="' + cls + '"></div>', doc).css({
  5978. position : 'absolute',
  5979. width : '1px',
  5980. height : '1px',
  5981. overflow : 'hidden',
  5982. left : '-1981px',
  5983. top : K(bookmark.start).pos().y + 'px',
  5984. 'white-space' : 'nowrap'
  5985. });
  5986. K(doc.body).append(div);
  5987. if (_IE) {
  5988. var rng = cmd.range.get(true);
  5989. rng.moveToElementText(div[0]);
  5990. rng.select();
  5991. rng.execCommand('paste');
  5992. e.preventDefault();
  5993. } else {
  5994. cmd.range.selectNodeContents(div[0]);
  5995. cmd.select();
  5996. div[0].tabIndex = -1;
  5997. div[0].focus();
  5998. }
  5999. setTimeout(function() {
  6000. movePastedData();
  6001. pasting = false;
  6002. }, 0);
  6003. });
  6004. });
  6005. self.beforeGetHtml(function(html) {
  6006. if (_IE && _V <= 8) {
  6007. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  6008. return unescape(tag);
  6009. });
  6010. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  6011. if (!/\s+type="[^"]+"/i.test($0)) {
  6012. return $1 + ' type="text"' + $2;
  6013. }
  6014. return $0;
  6015. });
  6016. }
  6017. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  6018. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  6019. })
  6020. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  6021. var imgAttrs = _getAttrList(full);
  6022. var styles = _getCssList(imgAttrs.style || '');
  6023. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6024. var width = _undef(styles.width, '');
  6025. var height = _undef(styles.height, '');
  6026. if (/px/i.test(width)) {
  6027. width = _removeUnit(width);
  6028. }
  6029. if (/px/i.test(height)) {
  6030. height = _removeUnit(height);
  6031. }
  6032. attrs.width = _undef(imgAttrs.width, width);
  6033. attrs.height = _undef(imgAttrs.height, height);
  6034. return _mediaEmbed(attrs);
  6035. })
  6036. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6037. var imgAttrs = _getAttrList(full);
  6038. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6039. })
  6040. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6041. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6042. })
  6043. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6044. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6045. })
  6046. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6047. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6048. return $1 + _unescape(src) + $2;
  6049. });
  6050. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6051. return full;
  6052. })
  6053. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6054. return start + end;
  6055. });
  6056. });
  6057. self.beforeSetHtml(function(html) {
  6058. if (_IE && _V <= 8) {
  6059. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6060. var attrs = _getAttrList(full);
  6061. var styles = _getCssList(attrs.style || '');
  6062. if (styles.display == 'none') {
  6063. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6064. }
  6065. return full;
  6066. });
  6067. }
  6068. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6069. var attrs = _getAttrList(full);
  6070. attrs.src = _undef(attrs.src, '');
  6071. attrs.width = _undef(attrs.width, 0);
  6072. attrs.height = _undef(attrs.height, 0);
  6073. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6074. })
  6075. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6076. var attrs = _getAttrList(full);
  6077. if (attrs.href !== undefined) {
  6078. return full;
  6079. }
  6080. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6081. })
  6082. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6083. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6084. })
  6085. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6086. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6087. })
  6088. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6089. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6090. return full;
  6091. }
  6092. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6093. return full;
  6094. })
  6095. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6096. return start + 'data-ke-' + end;
  6097. })
  6098. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6099. if (full.indexOf('ke-zeroborder') >= 0) {
  6100. return full;
  6101. }
  6102. return _addClassToTag(full, 'ke-zeroborder');
  6103. });
  6104. });
  6105. });
  6106. })(window);
  6107. /*******************************************************************************
  6108. * KindEditor - WYSIWYG HTML Editor for Internet
  6109. * Copyright (C) 2006-2011 kindsoft.net
  6110. *
  6111. * @author Roddy <luolonghao@gmail.com>
  6112. * @site http://www.kindsoft.net/
  6113. * @licence http://www.kindsoft.net/license.php
  6114. *******************************************************************************/
  6115. KindEditor.lang({
  6116. source : 'HTML代码',
  6117. preview : '预览',
  6118. undo : '后退(Ctrl+Z)',
  6119. redo : '前进(Ctrl+Y)',
  6120. cut : '剪切(Ctrl+X)',
  6121. copy : '复制(Ctrl+C)',
  6122. paste : '粘贴(Ctrl+V)',
  6123. plainpaste : '粘贴为无格式文本',
  6124. wordpaste : '从Word粘贴',
  6125. selectall : '全选(Ctrl+A)',
  6126. justifyleft : '左对齐',
  6127. justifycenter : '居中',
  6128. justifyright : '右对齐',
  6129. justifyfull : '两端对齐',
  6130. insertorderedlist : '编号',
  6131. insertunorderedlist : '项目符号',
  6132. indent : '增加缩进',
  6133. outdent : '减少缩进',
  6134. subscript : '下标',
  6135. superscript : '上标',
  6136. formatblock : '段落',
  6137. fontname : '字体',
  6138. fontsize : '文字大小',
  6139. forecolor : '文字颜色',
  6140. hilitecolor : '文字背景',
  6141. bold : '粗体(Ctrl+B)',
  6142. italic : '斜体(Ctrl+I)',
  6143. underline : '下划线(Ctrl+U)',
  6144. strikethrough : '删除线',
  6145. removeformat : '删除格式',
  6146. image : '图片',
  6147. multiimage : '批量图片上传',
  6148. flash : 'Flash',
  6149. media : '音视频',
  6150. table : '表格',
  6151. tablecell : '单元格',
  6152. hr : '插入横线',
  6153. emoticons : '插入表情',
  6154. link : '超级链接',
  6155. unlink : '取消超级链接',
  6156. fullscreen : '全屏显示',
  6157. about : '关于',
  6158. print : '打印(Ctrl+P)',
  6159. filemanager : '文件库',
  6160. code : '插入程序代码',
  6161. map : 'Google地图',
  6162. baidumap : '百度地图',
  6163. lineheight : '行距',
  6164. clearhtml : '清理HTML代码',
  6165. pagebreak : '插入分页符',
  6166. quickformat : '一键排版',
  6167. insertfile : '插入文件',
  6168. template : '插入模板',
  6169. anchor : '锚点',
  6170. yes : '确定',
  6171. no : '取消',
  6172. close : '关闭',
  6173. editImage : '图片属性',
  6174. deleteImage : '删除图片',
  6175. editFlash : 'Flash属性',
  6176. deleteFlash : '删除Flash',
  6177. editMedia : '音视频属性',
  6178. deleteMedia : '删除音视频',
  6179. editLink : '超级链接属性',
  6180. deleteLink : '取消超级链接',
  6181. editAnchor : '锚点属性',
  6182. deleteAnchor : '删除锚点',
  6183. tableprop : '表格属性',
  6184. tablecellprop : '单元格属性',
  6185. tableinsert : '插入表格',
  6186. tabledelete : '删除表格',
  6187. tablecolinsertleft : '左侧插入列',
  6188. tablecolinsertright : '右侧插入列',
  6189. tablerowinsertabove : '上方插入行',
  6190. tablerowinsertbelow : '下方插入行',
  6191. tablerowmerge : '向下合并单元格',
  6192. tablecolmerge : '向右合并单元格',
  6193. tablerowsplit : '拆分行',
  6194. tablecolsplit : '拆分列',
  6195. tablecoldelete : '删除列',
  6196. tablerowdelete : '删除行',
  6197. noColor : '无颜色',
  6198. pleaseSelectFile : '请选择文件。',
  6199. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6200. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6201. invalidWidth : "宽度必须为数字。",
  6202. invalidHeight : "高度必须为数字。",
  6203. invalidBorder : "边框必须为数字。",
  6204. invalidUrl : "请输入有效的URL地址。",
  6205. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6206. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6207. invalidPadding : '边距必须为数字。',
  6208. invalidSpacing : '间距必须为数字。',
  6209. invalidJson : '服务器发生故障。',
  6210. uploadSuccess : '上传成功。',
  6211. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6212. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6213. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6214. ajaxLoading : '加载中,请稍候 ...',
  6215. uploadLoading : '上传中,请稍候 ...',
  6216. uploadError : '上传错误',
  6217. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6218. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6219. 'code.pleaseInput' : '请输入程序代码。',
  6220. 'link.url' : 'URL',
  6221. 'link.linkType' : '打开类型',
  6222. 'link.newWindow' : '新窗口',
  6223. 'link.selfWindow' : '当前窗口',
  6224. 'flash.url' : 'URL',
  6225. 'flash.width' : '宽度',
  6226. 'flash.height' : '高度',
  6227. 'flash.upload' : '上传',
  6228. 'flash.viewServer' : '文件空间',
  6229. 'media.url' : 'URL',
  6230. 'media.width' : '宽度',
  6231. 'media.height' : '高度',
  6232. 'media.autostart' : '自动播放',
  6233. 'media.upload' : '上传',
  6234. 'media.viewServer' : '文件空间',
  6235. 'image.remoteImage' : '网络图片',
  6236. 'image.localImage' : '本地上传',
  6237. 'image.remoteUrl' : '图片地址',
  6238. 'image.localUrl' : '上传文件',
  6239. 'image.size' : '图片大小',
  6240. 'image.width' : '宽',
  6241. 'image.height' : '高',
  6242. 'image.resetSize' : '重置大小',
  6243. 'image.align' : '对齐方式',
  6244. 'image.defaultAlign' : '默认方式',
  6245. 'image.leftAlign' : '左对齐',
  6246. 'image.rightAlign' : '右对齐',
  6247. 'image.imgTitle' : '图片说明',
  6248. 'image.upload' : '浏览...',
  6249. 'image.viewServer' : '图片空间',
  6250. //'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6251. 'multiimage.uploadDesc' : '',
  6252. 'multiimage.startUpload' : '开始上传',
  6253. 'multiimage.clearAll' : '全部清空',
  6254. 'multiimage.insertAll' : '全部插入',
  6255. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6256. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6257. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6258. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6259. 'multiimage.unknownError' : '发生异常,无法上传。',
  6260. 'multiimage.pending' : '等待上传',
  6261. 'multiimage.uploadError' : '上传失败',
  6262. 'filemanager.emptyFolder' : '空文件夹',
  6263. 'filemanager.moveup' : '移到上一级文件夹',
  6264. 'filemanager.viewType' : '显示方式:',
  6265. 'filemanager.viewImage' : '缩略图',
  6266. 'filemanager.listImage' : '详细信息',
  6267. 'filemanager.orderType' : '排序方式:',
  6268. 'filemanager.fileName' : '名称',
  6269. 'filemanager.fileSize' : '大小',
  6270. 'filemanager.fileType' : '类型',
  6271. 'insertfile.url' : 'URL',
  6272. 'insertfile.title' : '文件说明',
  6273. 'insertfile.upload' : '上传',
  6274. 'insertfile.viewServer' : '文件空间',
  6275. 'table.cells' : '单元格数',
  6276. 'table.rows' : '行数',
  6277. 'table.cols' : '列数',
  6278. 'table.size' : '大小',
  6279. 'table.width' : '宽度',
  6280. 'table.height' : '高度',
  6281. 'table.percent' : '%',
  6282. 'table.px' : 'px',
  6283. 'table.space' : '边距间距',
  6284. 'table.padding' : '边距',
  6285. 'table.spacing' : '间距',
  6286. 'table.align' : '对齐方式',
  6287. 'table.textAlign' : '水平对齐',
  6288. 'table.verticalAlign' : '垂直对齐',
  6289. 'table.alignDefault' : '默认',
  6290. 'table.alignLeft' : '左对齐',
  6291. 'table.alignCenter' : '居中',
  6292. 'table.alignRight' : '右对齐',
  6293. 'table.alignTop' : '顶部',
  6294. 'table.alignMiddle' : '中部',
  6295. 'table.alignBottom' : '底部',
  6296. 'table.alignBaseline' : '基线',
  6297. 'table.border' : '边框',
  6298. 'table.borderWidth' : '边框',
  6299. 'table.borderColor' : '颜色',
  6300. 'table.backgroundColor' : '背景颜色',
  6301. 'map.address' : '地址: ',
  6302. 'map.search' : '搜索',
  6303. 'baidumap.address' : '地址: ',
  6304. 'baidumap.search' : '搜索',
  6305. 'baidumap.insertDynamicMap' : '插入动态地图',
  6306. 'anchor.name' : '锚点名称',
  6307. 'formatblock.formatBlock' : {
  6308. h1 : '标题 1',
  6309. h2 : '标题 2',
  6310. h3 : '标题 3',
  6311. h4 : '标题 4',
  6312. p : '正 文'
  6313. },
  6314. 'fontname.fontName' : {
  6315. 'SimSun' : '宋体',
  6316. 'NSimSun' : '新宋体',
  6317. 'FangSong_GB2312' : '仿宋_GB2312',
  6318. 'KaiTi_GB2312' : '楷体_GB2312',
  6319. 'SimHei' : '黑体',
  6320. 'Microsoft YaHei' : '微软雅黑',
  6321. 'Arial' : 'Arial',
  6322. 'Arial Black' : 'Arial Black',
  6323. 'Times New Roman' : 'Times New Roman',
  6324. 'Courier New' : 'Courier New',
  6325. 'Tahoma' : 'Tahoma',
  6326. 'Verdana' : 'Verdana'
  6327. },
  6328. 'lineheight.lineHeight' : [
  6329. {'1' : '单倍行距'},
  6330. {'1.5' : '1.5倍行距'},
  6331. {'2' : '2倍行距'},
  6332. {'2.5' : '2.5倍行距'},
  6333. {'3' : '3倍行距'}
  6334. ],
  6335. 'template.selectTemplate' : '可选模板',
  6336. 'template.replaceContent' : '替换当前内容',
  6337. 'template.fileList' : {
  6338. '1.html' : '图片和文字',
  6339. '2.html' : '表格',
  6340. '3.html' : '项目编号'
  6341. }
  6342. }, 'zh-CN');
  6343. KindEditor.options.langType = 'zh-CN';
  6344. /*******************************************************************************
  6345. * KindEditor - WYSIWYG HTML Editor for Internet
  6346. * Copyright (C) 2006-2011 kindsoft.net
  6347. *
  6348. * @author Roddy <luolonghao@gmail.com>
  6349. * @site http://www.kindsoft.net/
  6350. * @licence http://www.kindsoft.net/license.php
  6351. *******************************************************************************/
  6352. KindEditor.plugin('anchor', function(K) {
  6353. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6354. self.plugin.anchor = {
  6355. edit : function() {
  6356. var html = ['<div style="padding:20px;">',
  6357. '<div class="ke-dialog-row">',
  6358. '<label for="keName">' + lang.name + '</label>',
  6359. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6360. '</div>',
  6361. '</div>'].join('');
  6362. var dialog = self.createDialog({
  6363. name : name,
  6364. width : 300,
  6365. title : self.lang(name),
  6366. body : html,
  6367. yesBtn : {
  6368. name : self.lang('yes'),
  6369. click : function(e) {
  6370. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6371. }
  6372. }
  6373. });
  6374. var div = dialog.div,
  6375. nameBox = K('input[name="name"]', div);
  6376. var img = self.plugin.getSelectedAnchor();
  6377. if (img) {
  6378. nameBox.val(unescape(img.attr('data-ke-name')));
  6379. }
  6380. nameBox[0].focus();
  6381. nameBox[0].select();
  6382. },
  6383. 'delete' : function() {
  6384. self.plugin.getSelectedAnchor().remove();
  6385. }
  6386. };
  6387. self.clickToolbar(name, self.plugin.anchor.edit);
  6388. });
  6389. /*******************************************************************************
  6390. * KindEditor - WYSIWYG HTML Editor for Internet
  6391. * Copyright (C) 2006-2011 kindsoft.net
  6392. *
  6393. * @author Roddy <luolonghao@gmail.com>
  6394. * @site http://www.kindsoft.net/
  6395. * @licence http://www.kindsoft.net/license.php
  6396. *******************************************************************************/
  6397. KindEditor.plugin('autoheight', function(K) {
  6398. var self = this;
  6399. if (!self.autoHeightMode) {
  6400. return;
  6401. }
  6402. var minHeight;
  6403. function hideScroll() {
  6404. var edit = self.edit;
  6405. var body = edit.doc.body;
  6406. edit.iframe[0].scroll = 'no';
  6407. body.style.overflowY = 'hidden';
  6408. }
  6409. function resetHeight() {
  6410. if(self.fullscreenMode){
  6411. return;
  6412. }
  6413. var edit = self.edit;
  6414. var body = edit.doc.body;
  6415. edit.iframe.height(minHeight);
  6416. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6417. }
  6418. function init() {
  6419. minHeight = K.removeUnit(self.height);
  6420. self.edit.afterChange(resetHeight);
  6421. if(!self.fullscreenMode){
  6422. hideScroll();
  6423. }
  6424. resetHeight();
  6425. }
  6426. if (self.isCreated) {
  6427. init();
  6428. } else {
  6429. self.afterCreate(init);
  6430. }
  6431. });
  6432. /*
  6433. * 如何实现真正的自动高度?
  6434. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6435. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6436. * 由此就实现了真正的自动高度
  6437. * 测试:chrome、firefox、IE9、IE8
  6438. * */
  6439. /*******************************************************************************
  6440. * KindEditor - WYSIWYG HTML Editor for Internet
  6441. * Copyright (C) 2006-2011 kindsoft.net
  6442. *
  6443. * @author Roddy <luolonghao@gmail.com>
  6444. * @site http://www.kindsoft.net/
  6445. * @licence http://www.kindsoft.net/license.php
  6446. *******************************************************************************/
  6447. KindEditor.plugin('baidumap', function(K) {
  6448. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6449. var mapWidth = K.undef(self.mapWidth, 558);
  6450. var mapHeight = K.undef(self.mapHeight, 360);
  6451. self.clickToolbar(name, function() {
  6452. var html = ['<div style="padding:10px 20px;">',
  6453. '<div class="ke-header">',
  6454. '<div class="ke-left">',
  6455. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6456. '<span class="ke-button-common ke-button-outer">',
  6457. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6458. '</span>',
  6459. '</div>',
  6460. '<div class="ke-right">',
  6461. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6462. '</div>',
  6463. '<div class="ke-clearfix"></div>',
  6464. '</div>',
  6465. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6466. '</div>'].join('');
  6467. var dialog = self.createDialog({
  6468. name : name,
  6469. width : mapWidth + 42,
  6470. title : self.lang(name),
  6471. body : html,
  6472. yesBtn : {
  6473. name : self.lang('yes'),
  6474. click : function(e) {
  6475. var map = win.map;
  6476. var centerObj = map.getCenter();
  6477. var center = centerObj.lng + ',' + centerObj.lat;
  6478. var zoom = map.getZoom();
  6479. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6480. '?center=' + encodeURIComponent(center),
  6481. '&zoom=' + encodeURIComponent(zoom),
  6482. '&width=' + mapWidth,
  6483. '&height=' + mapHeight,
  6484. '&markers=' + encodeURIComponent(center),
  6485. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6486. if (checkbox[0].checked) {
  6487. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6488. } else {
  6489. self.exec('insertimage', url);
  6490. }
  6491. self.hideDialog().focus();
  6492. }
  6493. },
  6494. beforeRemove : function() {
  6495. searchBtn.remove();
  6496. if (doc) {
  6497. doc.write('');
  6498. }
  6499. iframe.remove();
  6500. }
  6501. });
  6502. var div = dialog.div,
  6503. addressBox = K('[name="address"]', div),
  6504. searchBtn = K('[name="searchBtn"]', div),
  6505. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6506. win, doc;
  6507. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6508. function ready() {
  6509. win = iframe[0].contentWindow;
  6510. doc = K.iframeDoc(iframe);
  6511. }
  6512. iframe.bind('load', function() {
  6513. iframe.unbind('load');
  6514. if (K.IE) {
  6515. ready();
  6516. } else {
  6517. setTimeout(ready, 0);
  6518. }
  6519. });
  6520. K('.ke-map', div).replaceWith(iframe);
  6521. searchBtn.click(function() {
  6522. win.search(addressBox.val());
  6523. });
  6524. });
  6525. });
  6526. /*******************************************************************************
  6527. * KindEditor - WYSIWYG HTML Editor for Internet
  6528. * Copyright (C) 2006-2011 kindsoft.net
  6529. *
  6530. * @author Roddy <luolonghao@gmail.com>
  6531. * @site http://www.kindsoft.net/
  6532. * @licence http://www.kindsoft.net/license.php
  6533. *******************************************************************************/
  6534. KindEditor.plugin('map', function(K) {
  6535. var self = this, name = 'map', lang = self.lang(name + '.');
  6536. self.clickToolbar(name, function() {
  6537. var html = ['<div style="padding:10px 20px;">',
  6538. '<div class="ke-dialog-row">',
  6539. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6540. '<span class="ke-button-common ke-button-outer">',
  6541. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6542. '</span>',
  6543. '</div>',
  6544. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6545. '</div>'].join('');
  6546. var dialog = self.createDialog({
  6547. name : name,
  6548. width : 600,
  6549. title : self.lang(name),
  6550. body : html,
  6551. yesBtn : {
  6552. name : self.lang('yes'),
  6553. click : function(e) {
  6554. var geocoder = win.geocoder,
  6555. map = win.map,
  6556. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6557. zoom = map.getZoom(),
  6558. maptype = map.getMapTypeId(),
  6559. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6560. url += '?center=' + encodeURIComponent(center);
  6561. url += '&zoom=' + encodeURIComponent(zoom);
  6562. url += '&size=558x360';
  6563. url += '&maptype=' + encodeURIComponent(maptype);
  6564. url += '&markers=' + encodeURIComponent(center);
  6565. url += '&language=' + self.langType;
  6566. url += '&sensor=false';
  6567. self.exec('insertimage', url).hideDialog().focus();
  6568. }
  6569. },
  6570. beforeRemove : function() {
  6571. searchBtn.remove();
  6572. if (doc) {
  6573. doc.write('');
  6574. }
  6575. iframe.remove();
  6576. }
  6577. });
  6578. var div = dialog.div,
  6579. addressBox = K('[name="address"]', div),
  6580. searchBtn = K('[name="searchBtn"]', div),
  6581. win, doc;
  6582. var iframeHtml = ['<!doctype html><html><head>',
  6583. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6584. '<style>',
  6585. ' html { height: 100% }',
  6586. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6587. ' #map_canvas { height: 100% }',
  6588. '</style>',
  6589. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6590. '<script>',
  6591. 'var map, geocoder;',
  6592. 'function initialize() {',
  6593. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6594. ' var options = {',
  6595. ' zoom: 11,',
  6596. ' center: latlng,',
  6597. ' disableDefaultUI: true,',
  6598. ' panControl: true,',
  6599. ' zoomControl: true,',
  6600. ' mapTypeControl: true,',
  6601. ' scaleControl: true,',
  6602. ' streetViewControl: false,',
  6603. ' overviewMapControl: true,',
  6604. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6605. ' };',
  6606. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6607. ' geocoder = new google.maps.Geocoder();',
  6608. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6609. ' if (status == google.maps.GeocoderStatus.OK) {',
  6610. ' if (results[3]) {',
  6611. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6612. ' }',
  6613. ' }',
  6614. ' });',
  6615. '}',
  6616. 'function search(address) {',
  6617. ' if (!map) return;',
  6618. ' geocoder.geocode({address : address}, function(results, status) {',
  6619. ' if (status == google.maps.GeocoderStatus.OK) {',
  6620. ' map.setZoom(11);',
  6621. ' map.setCenter(results[0].geometry.location);',
  6622. ' var marker = new google.maps.Marker({',
  6623. ' map: map,',
  6624. ' position: results[0].geometry.location',
  6625. ' });',
  6626. ' } else {',
  6627. ' alert("Invalid address: " + address);',
  6628. ' }',
  6629. ' });',
  6630. '}',
  6631. '</script>',
  6632. '</head>',
  6633. '<body onload="initialize();">',
  6634. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6635. '</body></html>'].join('\n');
  6636. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6637. function ready() {
  6638. win = iframe[0].contentWindow;
  6639. doc = K.iframeDoc(iframe);
  6640. }
  6641. iframe.bind('load', function() {
  6642. iframe.unbind('load');
  6643. if (K.IE) {
  6644. ready();
  6645. } else {
  6646. setTimeout(ready, 0);
  6647. }
  6648. });
  6649. K('.ke-map', div).replaceWith(iframe);
  6650. searchBtn.click(function() {
  6651. win.search(addressBox.val());
  6652. });
  6653. });
  6654. });
  6655. /*******************************************************************************
  6656. * KindEditor - WYSIWYG HTML Editor for Internet
  6657. * Copyright (C) 2006-2011 kindsoft.net
  6658. *
  6659. * @author Roddy <luolonghao@gmail.com>
  6660. * @site http://www.kindsoft.net/
  6661. * @licence http://www.kindsoft.net/license.php
  6662. *******************************************************************************/
  6663. KindEditor.plugin('clearhtml', function(K) {
  6664. var self = this, name = 'clearhtml';
  6665. self.clickToolbar(name, function() {
  6666. self.focus();
  6667. var html = self.html();
  6668. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6669. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6670. html = K.formatHtml(html, {
  6671. a : ['href', 'target'],
  6672. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6673. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6674. table : ['border'],
  6675. 'td,th' : ['rowspan', 'colspan'],
  6676. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6677. });
  6678. self.html(html);
  6679. self.cmd.selection(true);
  6680. self.addBookmark();
  6681. });
  6682. });
  6683. /*******************************************************************************
  6684. * KindEditor - WYSIWYG HTML Editor for Internet
  6685. * Copyright (C) 2006-2011 kindsoft.net
  6686. *
  6687. * @author Roddy <luolonghao@gmail.com>
  6688. * @site http://www.kindsoft.net/
  6689. * @licence http://www.kindsoft.net/license.php
  6690. *******************************************************************************/
  6691. KindEditor.plugin('code', function(K) {
  6692. var self = this, name = 'code';
  6693. self.clickToolbar(name, function() {
  6694. var lang = self.lang(name + '.'),
  6695. html = ['<div style="padding:10px 20px;">',
  6696. '<div class="ke-dialog-row">',
  6697. '<select class="ke-code-type">',
  6698. '<option value="js">JavaScript</option>',
  6699. '<option value="html">HTML</option>',
  6700. '<option value="css">CSS</option>',
  6701. '<option value="php">PHP</option>',
  6702. '<option value="pl">Perl</option>',
  6703. '<option value="py">Python</option>',
  6704. '<option value="rb">Ruby</option>',
  6705. '<option value="java">Java</option>',
  6706. '<option value="vb">ASP/VB</option>',
  6707. '<option value="cpp">C/C++</option>',
  6708. '<option value="cs">C#</option>',
  6709. '<option value="xml">XML</option>',
  6710. '<option value="bsh">Shell</option>',
  6711. '<option value="">Other</option>',
  6712. '</select>',
  6713. '</div>',
  6714. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6715. '</div>'].join(''),
  6716. dialog = self.createDialog({
  6717. name : name,
  6718. width : 450,
  6719. title : self.lang(name),
  6720. body : html,
  6721. yesBtn : {
  6722. name : self.lang('yes'),
  6723. click : function(e) {
  6724. var type = K('.ke-code-type', dialog.div).val(),
  6725. code = textarea.val(),
  6726. cls = type === '' ? '' : ' lang-' + type,
  6727. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6728. if (K.trim(code) === '') {
  6729. alert(lang.pleaseInput);
  6730. textarea[0].focus();
  6731. return;
  6732. }
  6733. self.insertHtml(html).hideDialog().focus();
  6734. }
  6735. }
  6736. }),
  6737. textarea = K('textarea', dialog.div);
  6738. textarea[0].focus();
  6739. });
  6740. });
  6741. /*******************************************************************************
  6742. * KindEditor - WYSIWYG HTML Editor for Internet
  6743. * Copyright (C) 2006-2011 kindsoft.net
  6744. *
  6745. * @author Roddy <luolonghao@gmail.com>
  6746. * @site http://www.kindsoft.net/
  6747. * @licence http://www.kindsoft.net/license.php
  6748. *******************************************************************************/
  6749. KindEditor.plugin('emoticons', function(K) {
  6750. var self = this, name = 'emoticons',
  6751. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6752. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6753. currentPageNum = 1;
  6754. self.clickToolbar(name, function() {
  6755. var rows = 5, cols = 9, total = 135, startNum = 0,
  6756. cells = rows * cols, pages = Math.ceil(total / cells),
  6757. colsHalf = Math.floor(cols / 2),
  6758. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6759. elements = [],
  6760. menu = self.createMenu({
  6761. name : name,
  6762. beforeRemove : function() {
  6763. removeEvent();
  6764. }
  6765. });
  6766. menu.div.append(wrapperDiv);
  6767. var previewDiv, previewImg;
  6768. if (allowPreview) {
  6769. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6770. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6771. wrapperDiv.append(previewDiv);
  6772. previewDiv.append(previewImg);
  6773. }
  6774. function bindCellEvent(cell, j, num) {
  6775. if (previewDiv) {
  6776. cell.mouseover(function() {
  6777. if (j > colsHalf) {
  6778. previewDiv.css('left', 0);
  6779. previewDiv.css('right', '');
  6780. } else {
  6781. previewDiv.css('left', '');
  6782. previewDiv.css('right', 0);
  6783. }
  6784. previewImg.attr('src', path + num + '.gif');
  6785. K(this).addClass('ke-on');
  6786. });
  6787. } else {
  6788. cell.mouseover(function() {
  6789. K(this).addClass('ke-on');
  6790. });
  6791. }
  6792. cell.mouseout(function() {
  6793. K(this).removeClass('ke-on');
  6794. });
  6795. cell.click(function(e) {
  6796. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6797. e.stop();
  6798. });
  6799. }
  6800. function createEmoticonsTable(pageNum, parentDiv) {
  6801. var table = document.createElement('table');
  6802. parentDiv.append(table);
  6803. if (previewDiv) {
  6804. K(table).mouseover(function() {
  6805. previewDiv.show('block');
  6806. });
  6807. K(table).mouseout(function() {
  6808. previewDiv.hide();
  6809. });
  6810. elements.push(K(table));
  6811. }
  6812. table.className = 'ke-table';
  6813. table.cellPadding = 0;
  6814. table.cellSpacing = 0;
  6815. table.border = 0;
  6816. var num = (pageNum - 1) * cells + startNum;
  6817. for (var i = 0; i < rows; i++) {
  6818. var row = table.insertRow(i);
  6819. for (var j = 0; j < cols; j++) {
  6820. var cell = K(row.insertCell(j));
  6821. cell.addClass('ke-cell');
  6822. bindCellEvent(cell, j, num);
  6823. var span = K('<span class="ke-img"></span>')
  6824. .css('background-position', '-' + (24 * num) + 'px 0px')
  6825. .css('background-image', 'url(' + path + 'static.gif)');
  6826. cell.append(span);
  6827. elements.push(cell);
  6828. num++;
  6829. }
  6830. }
  6831. return table;
  6832. }
  6833. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6834. function removeEvent() {
  6835. K.each(elements, function() {
  6836. this.unbind();
  6837. });
  6838. }
  6839. var pageDiv;
  6840. function bindPageEvent(el, pageNum) {
  6841. el.click(function(e) {
  6842. removeEvent();
  6843. table.parentNode.removeChild(table);
  6844. pageDiv.remove();
  6845. table = createEmoticonsTable(pageNum, wrapperDiv);
  6846. createPageTable(pageNum);
  6847. currentPageNum = pageNum;
  6848. e.stop();
  6849. });
  6850. }
  6851. function createPageTable(currentPageNum) {
  6852. pageDiv = K('<div class="ke-page"></div>');
  6853. wrapperDiv.append(pageDiv);
  6854. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6855. if (currentPageNum !== pageNum) {
  6856. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6857. bindPageEvent(a, pageNum);
  6858. pageDiv.append(a);
  6859. elements.push(a);
  6860. } else {
  6861. pageDiv.append(K('@[' + pageNum + ']'));
  6862. }
  6863. pageDiv.append(K('@&nbsp;'));
  6864. }
  6865. }
  6866. createPageTable(currentPageNum);
  6867. });
  6868. });
  6869. /*******************************************************************************
  6870. * KindEditor - WYSIWYG HTML Editor for Internet
  6871. * Copyright (C) 2006-2011 kindsoft.net
  6872. *
  6873. * @author Roddy <luolonghao@gmail.com>
  6874. * @site http://www.kindsoft.net/
  6875. * @licence http://www.kindsoft.net/license.php
  6876. *******************************************************************************/
  6877. KindEditor.plugin('filemanager', function(K) {
  6878. var self = this, name = 'filemanager',
  6879. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6880. imgPath = self.pluginsPath + name + '/images/',
  6881. lang = self.lang(name + '.');
  6882. function makeFileTitle(filename, filesize, datetime) {
  6883. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6884. }
  6885. function bindTitle(el, data) {
  6886. if (data.is_dir) {
  6887. el.attr('title', data.filename);
  6888. } else {
  6889. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6890. }
  6891. }
  6892. self.plugin.filemanagerDialog = function(options) {
  6893. var width = K.undef(options.width, 650),
  6894. height = K.undef(options.height, 510),
  6895. dirName = K.undef(options.dirName, ''),
  6896. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6897. clickFn = options.clickFn;
  6898. var html = [
  6899. '<div style="padding:10px 20px;">',
  6900. '<div class="ke-plugin-filemanager-header">',
  6901. '<div class="ke-left">',
  6902. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6903. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6904. '</div>',
  6905. '<div class="ke-right">',
  6906. '标签 <input type="text" style="width:100px;" value="" name="viewTag">',
  6907. '分类 <select class="ke-inline-block" name="viewCate">',
  6908. '',
  6909. '</select> ',
  6910. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6911. '<option value="VIEW">' + lang.viewImage + '</option>',
  6912. '<option value="LIST">' + lang.listImage + '</option>',
  6913. '</select> ',
  6914. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6915. '<option value="NAME">' + lang.fileName + '</option>',
  6916. '<option value="SIZE">' + lang.fileSize + '</option>',
  6917. '<option value="TYPE">' + lang.fileType + '</option>',
  6918. '</select>',
  6919. '</div>',
  6920. '<div class="ke-clearfix"></div>',
  6921. '</div>',
  6922. '<div class="ke-plugin-filemanager-body"></div>',
  6923. '</div>'
  6924. ].join('');
  6925. var dialog = self.createDialog({
  6926. name : name,
  6927. width : width,
  6928. height : height,
  6929. title : self.lang(name),
  6930. body : html
  6931. }),
  6932. div = dialog.div,
  6933. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6934. moveupImg = K('[name="moveupImg"]', div),
  6935. moveupLink = K('[name="moveupLink"]', div),
  6936. viewServerBtn = K('[name="viewServer"]', div),
  6937. viewCateBox = K('[name="viewCate"]', div),
  6938. viewTagBox = K('[name="viewTag"]', div),
  6939. viewTypeBox = K('[name="viewType"]', div),
  6940. orderTypeBox = K('[name="orderType"]', div);
  6941. function reloadPage(path, order, func, cate, tag) {
  6942. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6943. if (cate) {
  6944. param += '&cate=' + cate;
  6945. }
  6946. if (tag) {
  6947. param += '&tag=' + tag;
  6948. }
  6949. dialog.showLoading(self.lang('ajaxLoading'));
  6950. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6951. dialog.hideLoading();
  6952. func(data);
  6953. });
  6954. }
  6955. var elList = [];
  6956. function bindEvent(el, result, data, createFunc) {
  6957. var fileUrl = K.formatUrl(result.current_url + data.file, 'absolute'),
  6958. dirPath = encodeURIComponent(result.current_dir_path + data.path + '/');
  6959. if (data.is_dir) {
  6960. el.click(function(e) {
  6961. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6962. });
  6963. } else if (data.is_photo) {
  6964. el.click(function(e) {
  6965. clickFn.call(this, fileUrl, data.file);
  6966. });
  6967. } else {
  6968. el.click(function(e) {
  6969. clickFn.call(this, fileUrl, data.file);
  6970. });
  6971. }
  6972. elList.push(el);
  6973. }
  6974. function createCommon(result, createFunc) {
  6975. K.each(elList, function() {
  6976. this.unbind();
  6977. });
  6978. moveupLink.unbind();
  6979. viewTypeBox.unbind();
  6980. orderTypeBox.unbind();
  6981. if (result.current_dir_path) {
  6982. moveupLink.click(function(e) {
  6983. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6984. });
  6985. }
  6986. function changeFunc() {
  6987. if (viewTypeBox.val() == 'VIEW') {
  6988. reloadPage(result.current_dir_path, orderTypeBox.val(), createView, viewCateBox.val(), viewTagBox.val());
  6989. } else {
  6990. reloadPage(result.current_dir_path, orderTypeBox.val(), createList, viewCateBox.val(), viewTagBox.val());
  6991. }
  6992. }
  6993. viewTypeBox.change(changeFunc);
  6994. orderTypeBox.change(changeFunc);
  6995. viewCateBox.change(changeFunc);
  6996. bodyDiv.html('');
  6997. }
  6998. function createList(result) {
  6999. createCommon(result, createList);
  7000. var table = document.createElement('table');
  7001. table.className = 'ke-table';
  7002. table.cellPadding = 0;
  7003. table.cellSpacing = 0;
  7004. table.border = 0;
  7005. bodyDiv.append(table);
  7006. var fileList = result.file_list;
  7007. for (var i = 0, len = fileList.length; i < len; i++) {
  7008. var data = fileList[i], row = K(table.insertRow(i));
  7009. row.mouseover(function(e) {
  7010. K(this).addClass('ke-on');
  7011. })
  7012. .mouseout(function(e) {
  7013. K(this).removeClass('ke-on');
  7014. });
  7015. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  7016. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  7017. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  7018. if (!data.is_dir || data.has_file) {
  7019. row.css('cursor', 'pointer');
  7020. cell0.attr('title', data.filename);
  7021. bindEvent(cell0, result, data, createList);
  7022. } else {
  7023. cell0.attr('title', lang.emptyFolder);
  7024. }
  7025. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  7026. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  7027. }
  7028. }
  7029. function createView(result) {
  7030. createCommon(result, createView);
  7031. var fileList = result.file_list;
  7032. for (var i = 0, len = fileList.length; i < len; i++) {
  7033. var data = fileList[i],
  7034. div = K('<div class="ke-inline-block ke-item"></div>');
  7035. bodyDiv.append(div);
  7036. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7037. .mouseover(function(e) {
  7038. K(this).addClass('ke-on');
  7039. })
  7040. .mouseout(function(e) {
  7041. K(this).removeClass('ke-on');
  7042. });
  7043. div.append(photoDiv);
  7044. var fileUrl = result.current_url + data.file,
  7045. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7046. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7047. if (!data.is_dir || data.has_file) {
  7048. photoDiv.css('cursor', 'pointer');
  7049. bindTitle(photoDiv, data);
  7050. bindEvent(photoDiv, result, data, createView);
  7051. } else {
  7052. photoDiv.attr('title', lang.emptyFolder);
  7053. }
  7054. photoDiv.append(img);
  7055. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7056. }
  7057. }
  7058. viewTypeBox.val(viewType);
  7059. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7060. return dialog;
  7061. }
  7062. });
  7063. /*******************************************************************************
  7064. * KindEditor - WYSIWYG HTML Editor for Internet
  7065. * Copyright (C) 2006-2011 kindsoft.net
  7066. *
  7067. * @author Roddy <luolonghao@gmail.com>
  7068. * @site http://www.kindsoft.net/
  7069. * @licence http://www.kindsoft.net/license.php
  7070. *******************************************************************************/
  7071. KindEditor.plugin('flash', function(K) {
  7072. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7073. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7074. allowFileManager = K.undef(self.allowFileManager, false),
  7075. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7076. extraParams = K.undef(self.extraFileUploadParams, {}),
  7077. filePostName = K.undef(self.filePostName, 'imgFile'),
  7078. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7079. self.plugin.flash = {
  7080. edit : function() {
  7081. var html = [
  7082. '<div style="padding:20px;">',
  7083. '<div class="ke-dialog-row">',
  7084. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7085. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7086. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7087. '<span class="ke-button-common ke-button-outer">',
  7088. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7089. '</span>',
  7090. '</div>',
  7091. '<div class="ke-dialog-row">',
  7092. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7093. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7094. '</div>',
  7095. '<div class="ke-dialog-row">',
  7096. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7097. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7098. '</div>',
  7099. '</div>'
  7100. ].join('');
  7101. var dialog = self.createDialog({
  7102. name : name,
  7103. width : 450,
  7104. title : self.lang(name),
  7105. body : html,
  7106. yesBtn : {
  7107. name : self.lang('yes'),
  7108. click : function(e) {
  7109. var url = K.trim(urlBox.val()),
  7110. width = widthBox.val(),
  7111. height = heightBox.val();
  7112. if (url == 'http://' || K.invalidUrl(url)) {
  7113. alert(self.lang('invalidUrl'));
  7114. urlBox[0].focus();
  7115. return;
  7116. }
  7117. if (!/^\d*$/.test(width)) {
  7118. alert(self.lang('invalidWidth'));
  7119. widthBox[0].focus();
  7120. return;
  7121. }
  7122. if (!/^\d*$/.test(height)) {
  7123. alert(self.lang('invalidHeight'));
  7124. heightBox[0].focus();
  7125. return;
  7126. }
  7127. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7128. src : url,
  7129. type : K.mediaType('.swf'),
  7130. width : width,
  7131. height : height,
  7132. quality : 'high'
  7133. });
  7134. self.insertHtml(html).hideDialog().focus();
  7135. }
  7136. }
  7137. }),
  7138. div = dialog.div,
  7139. urlBox = K('[name="url"]', div),
  7140. viewServerBtn = K('[name="viewServer"]', div),
  7141. widthBox = K('[name="width"]', div),
  7142. heightBox = K('[name="height"]', div);
  7143. urlBox.val('http://');
  7144. if (allowFlashUpload) {
  7145. var uploadbutton = K.uploadbutton({
  7146. button : K('.ke-upload-button', div)[0],
  7147. fieldName : filePostName,
  7148. extraParams : extraParams,
  7149. url : K.addParam(uploadJson, 'dir=flash'),
  7150. afterUpload : function(data) {
  7151. dialog.hideLoading();
  7152. if (data.error === 0) {
  7153. var url = data.url;
  7154. if (formatUploadUrl) {
  7155. url = K.formatUrl(url, 'absolute');
  7156. }
  7157. urlBox.val(url);
  7158. if (self.afterUpload) {
  7159. self.afterUpload.call(self, url, data, name);
  7160. }
  7161. alert(self.lang('uploadSuccess'));
  7162. } else {
  7163. alert(data.message);
  7164. }
  7165. },
  7166. afterError : function(html) {
  7167. dialog.hideLoading();
  7168. self.errorDialog(html);
  7169. }
  7170. });
  7171. uploadbutton.fileBox.change(function(e) {
  7172. dialog.showLoading(self.lang('uploadLoading'));
  7173. uploadbutton.submit();
  7174. });
  7175. } else {
  7176. K('.ke-upload-button', div).hide();
  7177. }
  7178. if (allowFileManager) {
  7179. viewServerBtn.click(function(e) {
  7180. var clickFn = function(url, title, id) {
  7181. K('[name="url"]', div).val(url);
  7182. if (self.afterSelectFile) {
  7183. self.afterSelectFile.call(self, url);
  7184. }
  7185. };
  7186. var cur = K('[name="url"]', div).val();
  7187. editorShowUpload(cur, self.fileManagerJson, 'flash库', clickFn, this);
  7188. /*
  7189. self.loadPlugin('filemanager', function() {
  7190. self.plugin.filemanagerDialog({
  7191. viewType : 'LIST',
  7192. dirName : 'flash',
  7193. clickFn : function(url, title) {
  7194. if (self.dialogs.length > 1) {
  7195. K('[name="url"]', div).val(url);
  7196. if (self.afterSelectFile) {
  7197. self.afterSelectFile.call(self, url);
  7198. }
  7199. self.hideDialog();
  7200. }
  7201. }
  7202. });
  7203. });
  7204. */
  7205. });
  7206. } else {
  7207. viewServerBtn.hide();
  7208. }
  7209. var img = self.plugin.getSelectedFlash();
  7210. if (img) {
  7211. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7212. urlBox.val(attrs.src);
  7213. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7214. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7215. }
  7216. urlBox[0].focus();
  7217. urlBox[0].select();
  7218. },
  7219. 'delete' : function() {
  7220. self.plugin.getSelectedFlash().remove();
  7221. self.addBookmark();
  7222. }
  7223. };
  7224. self.clickToolbar(name, self.plugin.flash.edit);
  7225. });
  7226. /*******************************************************************************
  7227. * KindEditor - WYSIWYG HTML Editor for Internet
  7228. * Copyright (C) 2006-2011 kindsoft.net
  7229. *
  7230. * @author Roddy <luolonghao@gmail.com>
  7231. * @site http://www.kindsoft.net/
  7232. * @licence http://www.kindsoft.net/license.php
  7233. *******************************************************************************/
  7234. KindEditor.plugin('image', function(K) {
  7235. var self = this, name = 'image',
  7236. allowImageUpload = K.undef(self.allowImageUpload, true),
  7237. allowImageRemote = K.undef(self.allowImageRemote, true),
  7238. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7239. allowFileManager = K.undef(self.allowFileManager, false),
  7240. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7241. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7242. imgPath = self.pluginsPath + 'image/images/',
  7243. extraParams = K.undef(self.extraFileUploadParams, {}),
  7244. filePostName = K.undef(self.filePostName, 'imgFile'),
  7245. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7246. lang = self.lang(name + '.');
  7247. self.plugin.imageDialog = function(options) {
  7248. var imageUrl = options.imageUrl,
  7249. imageWidth = K.undef(options.imageWidth, ''),
  7250. imageHeight = K.undef(options.imageHeight, ''),
  7251. imageTitle = K.undef(options.imageTitle, ''),
  7252. imageAlign = K.undef(options.imageAlign, ''),
  7253. showRemote = K.undef(options.showRemote, true),
  7254. showLocal = K.undef(options.showLocal, true),
  7255. tabIndex = K.undef(options.tabIndex, 0),
  7256. clickFn = options.clickFn;
  7257. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7258. var hiddenElements = [];
  7259. for(var k in extraParams){
  7260. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7261. }
  7262. var html = [
  7263. '<div style="padding:20px;">',
  7264. '<div class="tabs"></div>',
  7265. '<div class="tab1" style="display:none;">',
  7266. '<div class="ke-dialog-row">',
  7267. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7268. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7269. '<span class="ke-button-common ke-button-outer">',
  7270. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7271. '</span>',
  7272. '</div>',
  7273. '<div class="ke-dialog-row">',
  7274. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7275. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7276. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7277. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7278. '</div>',
  7279. '<div class="ke-dialog-row">',
  7280. '<label style="width:60px;">' + lang.align + '</label>',
  7281. '<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="" />',
  7282. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7283. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7284. '</div>',
  7285. '<div class="ke-dialog-row">',
  7286. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7287. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7288. '</div>',
  7289. '</div>',
  7290. '<div class="tab2" style="display:none;">',
  7291. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7292. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7293. '<div class="ke-dialog-row">',
  7294. hiddenElements.join(''),
  7295. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7296. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7297. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7298. '</div>',
  7299. '</form>',
  7300. '</div>',
  7301. '</div>'
  7302. ].join('');
  7303. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7304. dialogHeight = showLocal && showRemote ? 300 : 250;
  7305. var dialog = self.createDialog({
  7306. name : name,
  7307. width : dialogWidth,
  7308. height : dialogHeight,
  7309. title : self.lang(name),
  7310. body : html,
  7311. yesBtn : {
  7312. name : self.lang('yes'),
  7313. click : function(e) {
  7314. if (dialog.isLoading) {
  7315. return;
  7316. }
  7317. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7318. if (uploadbutton.fileBox.val() == '') {
  7319. alert(self.lang('pleaseSelectFile'));
  7320. return;
  7321. }
  7322. dialog.showLoading(self.lang('uploadLoading'));
  7323. uploadbutton.submit();
  7324. localUrlBox.val('');
  7325. return;
  7326. }
  7327. var url = K.trim(urlBox.val()),
  7328. width = widthBox.val(),
  7329. height = heightBox.val(),
  7330. title = titleBox.val(),
  7331. align = '';
  7332. alignBox.each(function() {
  7333. if (this.checked) {
  7334. align = this.value;
  7335. return false;
  7336. }
  7337. });
  7338. if (url == 'http://' || K.invalidUrl(url)) {
  7339. alert(self.lang('invalidUrl'));
  7340. urlBox[0].focus();
  7341. return;
  7342. }
  7343. if (!/^\d*$/.test(width)) {
  7344. alert(self.lang('invalidWidth'));
  7345. widthBox[0].focus();
  7346. return;
  7347. }
  7348. if (!/^\d*$/.test(height)) {
  7349. alert(self.lang('invalidHeight'));
  7350. heightBox[0].focus();
  7351. return;
  7352. }
  7353. clickFn.call(self, url, title, width, height, 0, align);
  7354. }
  7355. },
  7356. beforeRemove : function() {
  7357. viewServerBtn.unbind();
  7358. widthBox.unbind();
  7359. heightBox.unbind();
  7360. refreshBtn.unbind();
  7361. }
  7362. }),
  7363. div = dialog.div;
  7364. var urlBox = K('[name="url"]', div),
  7365. localUrlBox = K('[name="localUrl"]', div),
  7366. viewServerBtn = K('[name="viewServer"]', div),
  7367. widthBox = K('.tab1 [name="width"]', div),
  7368. heightBox = K('.tab1 [name="height"]', div),
  7369. refreshBtn = K('.ke-refresh-btn', div),
  7370. titleBox = K('.tab1 [name="title"]', div),
  7371. alignBox = K('.tab1 [name="align"]', div);
  7372. var tabs;
  7373. if (showRemote && showLocal) {
  7374. tabs = K.tabs({
  7375. src : K('.tabs', div),
  7376. afterSelect : function(i) {}
  7377. });
  7378. tabs.add({
  7379. title : lang.remoteImage,
  7380. panel : K('.tab1', div)
  7381. });
  7382. tabs.add({
  7383. title : lang.localImage,
  7384. panel : K('.tab2', div)
  7385. });
  7386. tabs.select(1);
  7387. } else if (showRemote) {
  7388. K('.tab1', div).show();
  7389. } else if (showLocal) {
  7390. K('.tab2', div).show();
  7391. }
  7392. var uploadbutton = K.uploadbutton({
  7393. button : K('.ke-upload-button', div)[0],
  7394. fieldName : filePostName,
  7395. form : K('.ke-form', div),
  7396. target : target,
  7397. width: 60,
  7398. afterUpload : function(data) {
  7399. dialog.hideLoading();
  7400. if (data.error === 0) {
  7401. var url = data.url;
  7402. if (formatUploadUrl) {
  7403. url = K.formatUrl(url, 'absolute');
  7404. }
  7405. if (self.afterUpload) {
  7406. self.afterUpload.call(self, url, data, name);
  7407. }
  7408. if (!fillDescAfterUploadImage) {
  7409. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7410. } else {
  7411. K(".ke-dialog-row #remoteUrl", div).val(url);
  7412. K(".ke-tabs-li", div)[0].click();
  7413. K(".ke-refresh-btn", div).click();
  7414. }
  7415. } else {
  7416. alert(data.message);
  7417. }
  7418. },
  7419. afterError : function(html) {
  7420. dialog.hideLoading();
  7421. self.errorDialog(html);
  7422. }
  7423. });
  7424. uploadbutton.fileBox.change(function(e) {
  7425. localUrlBox.val(uploadbutton.fileBox.val());
  7426. });
  7427. if (allowFileManager) {
  7428. viewServerBtn.click(function(e) {
  7429. //clickFn.call(this, fileUrl, data.file);
  7430. var clickFn = function(url, title, id) {
  7431. K('[name="url"]', div).val(url);
  7432. if (self.afterSelectFile) {
  7433. self.afterSelectFile.call(self, url);
  7434. }
  7435. };
  7436. var cur = K('[name="url"]', div).val();
  7437. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  7438. /*
  7439. self.loadPlugin('filemanager', function() {
  7440. self.plugin.filemanagerDialog({
  7441. viewType : 'VIEW',
  7442. dirName : 'image',
  7443. clickFn : function(url, title) {
  7444. if (self.dialogs.length > 1) {
  7445. K('[name="url"]', div).val(url);
  7446. if (self.afterSelectFile) {
  7447. self.afterSelectFile.call(self, url);
  7448. }
  7449. self.hideDialog();
  7450. }
  7451. }
  7452. });
  7453. });
  7454. */
  7455. });
  7456. } else {
  7457. viewServerBtn.hide();
  7458. }
  7459. var originalWidth = 0, originalHeight = 0;
  7460. function setSize(width, height) {
  7461. widthBox.val(width);
  7462. heightBox.val(height);
  7463. originalWidth = width;
  7464. originalHeight = height;
  7465. }
  7466. refreshBtn.click(function(e) {
  7467. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7468. position : 'absolute',
  7469. visibility : 'hidden',
  7470. top : 0,
  7471. left : '-1000px'
  7472. });
  7473. tempImg.bind('load', function() {
  7474. setSize(tempImg.width(), tempImg.height());
  7475. tempImg.remove();
  7476. });
  7477. K(document.body).append(tempImg);
  7478. });
  7479. widthBox.change(function(e) {
  7480. if (originalWidth > 0) {
  7481. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7482. }
  7483. });
  7484. heightBox.change(function(e) {
  7485. if (originalHeight > 0) {
  7486. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7487. }
  7488. });
  7489. urlBox.val(options.imageUrl);
  7490. setSize(options.imageWidth, options.imageHeight);
  7491. titleBox.val(options.imageTitle);
  7492. alignBox.each(function() {
  7493. if (this.value === options.imageAlign) {
  7494. this.checked = true;
  7495. return false;
  7496. }
  7497. });
  7498. if (showRemote && tabIndex === 0) {
  7499. urlBox[0].focus();
  7500. urlBox[0].select();
  7501. }
  7502. return dialog;
  7503. };
  7504. self.plugin.image = {
  7505. edit : function() {
  7506. var img = self.plugin.getSelectedImage();
  7507. self.plugin.imageDialog({
  7508. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7509. imageWidth : img ? img.width() : '',
  7510. imageHeight : img ? img.height() : '',
  7511. imageTitle : img ? img.attr('title') : '',
  7512. imageAlign : img ? img.attr('align') : '',
  7513. showRemote : allowImageRemote,
  7514. showLocal : allowImageUpload,
  7515. tabIndex: img ? 0 : imageTabIndex,
  7516. clickFn : function(url, title, width, height, border, align) {
  7517. if (img) {
  7518. img.attr('src', url);
  7519. img.attr('data-ke-src', url);
  7520. img.attr('width', width);
  7521. img.attr('height', height);
  7522. img.attr('title', title);
  7523. img.attr('align', align);
  7524. img.attr('alt', title);
  7525. } else {
  7526. self.exec('insertimage', url, title, width, height, border, align);
  7527. }
  7528. setTimeout(function() {
  7529. self.hideDialog().focus();
  7530. }, 0);
  7531. }
  7532. });
  7533. },
  7534. 'delete' : function() {
  7535. var target = self.plugin.getSelectedImage();
  7536. if (target.parent().name == 'a') {
  7537. target = target.parent();
  7538. }
  7539. target.remove();
  7540. self.addBookmark();
  7541. }
  7542. };
  7543. self.clickToolbar(name, self.plugin.image.edit);
  7544. });
  7545. /*******************************************************************************
  7546. * KindEditor - WYSIWYG HTML Editor for Internet
  7547. * Copyright (C) 2006-2011 kindsoft.net
  7548. *
  7549. * @author Roddy <luolonghao@gmail.com>
  7550. * @site http://www.kindsoft.net/
  7551. * @licence http://www.kindsoft.net/license.php
  7552. *******************************************************************************/
  7553. KindEditor.plugin('insertfile', function(K) {
  7554. var self = this, name = 'insertfile',
  7555. allowFileUpload = K.undef(self.allowFileUpload, true),
  7556. allowFileManager = K.undef(self.allowFileManager, false),
  7557. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7558. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7559. extraParams = K.undef(self.extraFileUploadParams, {}),
  7560. filePostName = K.undef(self.filePostName, 'imgFile'),
  7561. lang = self.lang(name + '.');
  7562. self.plugin.fileDialog = function(options) {
  7563. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7564. fileTitle = K.undef(options.fileTitle, ''),
  7565. clickFn = options.clickFn;
  7566. var html = [
  7567. '<div style="padding:20px;">',
  7568. '<div class="ke-dialog-row">',
  7569. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7570. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7571. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7572. '<span class="ke-button-common ke-button-outer">',
  7573. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7574. '</span>',
  7575. '</div>',
  7576. '<div class="ke-dialog-row">',
  7577. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7578. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7579. '</div>',
  7580. '</form>',
  7581. '</div>'
  7582. ].join('');
  7583. var dialog = self.createDialog({
  7584. name : name,
  7585. width : 450,
  7586. title : self.lang(name),
  7587. body : html,
  7588. yesBtn : {
  7589. name : self.lang('yes'),
  7590. click : function(e) {
  7591. var url = K.trim(urlBox.val()),
  7592. title = titleBox.val();
  7593. if (url == 'http://' || K.invalidUrl(url)) {
  7594. alert(self.lang('invalidUrl'));
  7595. urlBox[0].focus();
  7596. return;
  7597. }
  7598. if (K.trim(title) === '') {
  7599. title = url;
  7600. }
  7601. clickFn.call(self, url, title);
  7602. }
  7603. }
  7604. }),
  7605. div = dialog.div;
  7606. var urlBox = K('[name="url"]', div),
  7607. viewServerBtn = K('[name="viewServer"]', div),
  7608. titleBox = K('[name="title"]', div);
  7609. if (allowFileUpload) {
  7610. var uploadbutton = K.uploadbutton({
  7611. button : K('.ke-upload-button', div)[0],
  7612. fieldName : filePostName,
  7613. url : K.addParam(uploadJson, 'dir=file'),
  7614. extraParams : extraParams,
  7615. afterUpload : function(data) {
  7616. dialog.hideLoading();
  7617. if (data.error === 0) {
  7618. var url = data.url;
  7619. if (formatUploadUrl) {
  7620. url = K.formatUrl(url, 'absolute');
  7621. }
  7622. urlBox.val(url);
  7623. if (self.afterUpload) {
  7624. self.afterUpload.call(self, url, data, name);
  7625. }
  7626. alert(self.lang('uploadSuccess'));
  7627. } else {
  7628. alert(data.message);
  7629. }
  7630. },
  7631. afterError : function(html) {
  7632. dialog.hideLoading();
  7633. self.errorDialog(html);
  7634. }
  7635. });
  7636. uploadbutton.fileBox.change(function(e) {
  7637. dialog.showLoading(self.lang('uploadLoading'));
  7638. uploadbutton.submit();
  7639. });
  7640. } else {
  7641. K('.ke-upload-button', div).hide();
  7642. }
  7643. if (allowFileManager) {
  7644. viewServerBtn.click(function(e) {
  7645. var clickFn = function(url, title, id) {
  7646. K('[name="url"]', div).val(url);
  7647. if (self.afterSelectFile) {
  7648. self.afterSelectFile.call(self, url);
  7649. }
  7650. };
  7651. var cur = K('[name="url"]', div).val();
  7652. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '文件库', clickFn, this);
  7653. /*
  7654. self.loadPlugin('filemanager', function() {
  7655. self.plugin.filemanagerDialog({
  7656. viewType : 'LIST',
  7657. dirName : 'file',
  7658. clickFn : function(url, title) {
  7659. if (self.dialogs.length > 1) {
  7660. self.hideDialog();
  7661. }
  7662. }
  7663. });
  7664. });
  7665. */
  7666. });
  7667. } else {
  7668. viewServerBtn.hide();
  7669. }
  7670. urlBox.val(fileUrl);
  7671. titleBox.val(fileTitle);
  7672. urlBox[0].focus();
  7673. urlBox[0].select();
  7674. };
  7675. self.clickToolbar(name, function() {
  7676. self.plugin.fileDialog({
  7677. clickFn : function(url, title) {
  7678. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7679. self.insertHtml(html).hideDialog().focus();
  7680. }
  7681. });
  7682. });
  7683. });
  7684. /*******************************************************************************
  7685. * KindEditor - WYSIWYG HTML Editor for Internet
  7686. * Copyright (C) 2006-2011 kindsoft.net
  7687. *
  7688. * @author Roddy <luolonghao@gmail.com>
  7689. * @site http://www.kindsoft.net/
  7690. * @licence http://www.kindsoft.net/license.php
  7691. *******************************************************************************/
  7692. KindEditor.plugin('lineheight', function(K) {
  7693. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7694. self.clickToolbar(name, function() {
  7695. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7696. if (commonNode) {
  7697. curVal = commonNode.css('line-height');
  7698. }
  7699. var menu = self.createMenu({
  7700. name : name,
  7701. width : 150
  7702. });
  7703. K.each(lang.lineHeight, function(i, row) {
  7704. K.each(row, function(key, val) {
  7705. menu.addItem({
  7706. title : val,
  7707. checked : curVal === key,
  7708. click : function() {
  7709. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7710. span : '.line-height=' + key
  7711. });
  7712. self.updateState();
  7713. self.addBookmark();
  7714. self.hideMenu();
  7715. }
  7716. });
  7717. });
  7718. });
  7719. });
  7720. });
  7721. /*******************************************************************************
  7722. * KindEditor - WYSIWYG HTML Editor for Internet
  7723. * Copyright (C) 2006-2011 kindsoft.net
  7724. *
  7725. * @author Roddy <luolonghao@gmail.com>
  7726. * @site http://www.kindsoft.net/
  7727. * @licence http://www.kindsoft.net/license.php
  7728. *******************************************************************************/
  7729. KindEditor.plugin('link', function(K) {
  7730. var self = this, name = 'link';
  7731. self.plugin.link = {
  7732. edit : function() {
  7733. var lang = self.lang(name + '.'),
  7734. html = '<div style="padding:20px;">' +
  7735. '<div class="ke-dialog-row">' +
  7736. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7737. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7738. '<div class="ke-dialog-row"">' +
  7739. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7740. '<select id="keType" name="type"></select>' +
  7741. '</div>' +
  7742. '</div>',
  7743. dialog = self.createDialog({
  7744. name : name,
  7745. width : 450,
  7746. title : self.lang(name),
  7747. body : html,
  7748. yesBtn : {
  7749. name : self.lang('yes'),
  7750. click : function(e) {
  7751. var url = K.trim(urlBox.val());
  7752. if (url == 'http://' || K.invalidUrl(url)) {
  7753. alert(self.lang('invalidUrl'));
  7754. urlBox[0].focus();
  7755. return;
  7756. }
  7757. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7758. }
  7759. }
  7760. }),
  7761. div = dialog.div,
  7762. urlBox = K('input[name="url"]', div),
  7763. typeBox = K('select[name="type"]', div);
  7764. urlBox.val('http://');
  7765. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7766. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7767. self.cmd.selection();
  7768. var a = self.plugin.getSelectedLink();
  7769. if (a) {
  7770. self.cmd.range.selectNode(a[0]);
  7771. self.cmd.select();
  7772. urlBox.val(a.attr('data-ke-src'));
  7773. typeBox.val(a.attr('target'));
  7774. }
  7775. urlBox[0].focus();
  7776. urlBox[0].select();
  7777. },
  7778. 'delete' : function() {
  7779. self.exec('unlink', null);
  7780. }
  7781. };
  7782. self.clickToolbar(name, self.plugin.link.edit);
  7783. });
  7784. /*******************************************************************************
  7785. * KindEditor - WYSIWYG HTML Editor for Internet
  7786. * Copyright (C) 2006-2011 kindsoft.net
  7787. *
  7788. * @author Roddy <luolonghao@gmail.com>
  7789. * @site http://www.kindsoft.net/
  7790. * @licence http://www.kindsoft.net/license.php
  7791. *******************************************************************************/
  7792. KindEditor.plugin('media', function(K) {
  7793. var self = this, name = 'media', lang = self.lang(name + '.'),
  7794. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7795. allowFileManager = K.undef(self.allowFileManager, false),
  7796. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7797. extraParams = K.undef(self.extraFileUploadParams, {}),
  7798. filePostName = K.undef(self.filePostName, 'imgFile'),
  7799. uploadJson = K.undef(self.uploadMediaJson, self.basePath + 'php/upload_json.php');
  7800. if (self.uploadYunJson && self.uploadYunJson.domain) {
  7801. uploadJson = self.uploadYunJson.domain;
  7802. extraParams.token = self.uploadYunJson.token;
  7803. extraParams.key = self.uploadYunJson.path;
  7804. }
  7805. self.plugin.media = {
  7806. edit : function() {
  7807. var html = [
  7808. '<div style="padding:20px;">',
  7809. '<div class="ke-dialog-row">',
  7810. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7811. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7812. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7813. '<span class="ke-button-common ke-button-outer">',
  7814. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7815. '</span>',
  7816. '</div>',
  7817. '<div class="ke-dialog-row">',
  7818. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7819. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="450" maxlength="4" />',
  7820. '</div>',
  7821. '<div class="ke-dialog-row">',
  7822. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7823. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="100" maxlength="4" />',
  7824. '</div>',
  7825. '<div class="ke-dialog-row">',
  7826. '<label for="keAutostart">' + lang.autostart + '</label>',
  7827. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7828. '</div>',
  7829. '</div>'
  7830. ].join('');
  7831. var dialog = self.createDialog({
  7832. name : name,
  7833. width : 450,
  7834. height : 230,
  7835. title : self.lang(name),
  7836. body : html,
  7837. yesBtn : {
  7838. name : self.lang('yes'),
  7839. click : function(e) {
  7840. var url = K.trim(urlBox.val()),
  7841. width = widthBox.val(),
  7842. height = heightBox.val();
  7843. if (url == 'http://' || K.invalidUrl(url)) {
  7844. alert(self.lang('invalidUrl'));
  7845. urlBox[0].focus();
  7846. return;
  7847. }
  7848. if (!/^\d*$/.test(width)) {
  7849. alert(self.lang('invalidWidth'));
  7850. widthBox[0].focus();
  7851. return;
  7852. }
  7853. if (!/^\d*$/.test(height)) {
  7854. alert(self.lang('invalidHeight'));
  7855. heightBox[0].focus();
  7856. return;
  7857. }
  7858. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7859. src : url,
  7860. type : K.mediaType(url),
  7861. width : width,
  7862. height : height,
  7863. autostart : autostartBox[0].checked ? 'true' : 'false',
  7864. loop : 'true'
  7865. });
  7866. self.insertHtml(html).hideDialog().focus();
  7867. }
  7868. }
  7869. }),
  7870. div = dialog.div,
  7871. urlBox = K('[name="url"]', div),
  7872. viewServerBtn = K('[name="viewServer"]', div),
  7873. widthBox = K('[name="width"]', div),
  7874. heightBox = K('[name="height"]', div),
  7875. autostartBox = K('[name="autostart"]', div);
  7876. urlBox.val('http://');
  7877. if (allowMediaUpload) {
  7878. var uploadbutton = K.uploadbutton({
  7879. button : K('.ke-upload-button', div)[0],
  7880. fieldName : filePostName,
  7881. extraParams : extraParams,
  7882. url : K.addParam(uploadJson, 'dir=media'),
  7883. afterUpload : function(data) {
  7884. console.info(data);
  7885. dialog.hideLoading();
  7886. if (data.error === 0) {
  7887. var url = data.url;
  7888. if (formatUploadUrl) {
  7889. url = K.formatUrl(url, 'absolute');
  7890. }
  7891. urlBox.val(url);
  7892. if (self.afterUpload) {
  7893. self.afterUpload.call(self, url, data, name);
  7894. }
  7895. alert(self.lang('uploadSuccess'));
  7896. } else {
  7897. alert(data.message);
  7898. }
  7899. },
  7900. afterError : function(html) {
  7901. dialog.hideLoading();
  7902. self.errorDialog(html);
  7903. }
  7904. });
  7905. uploadbutton.fileBox.change(function(e) {
  7906. dialog.showLoading(self.lang('uploadLoading'));
  7907. uploadbutton.submit(this);
  7908. });
  7909. } else {
  7910. K('.ke-upload-button', div).hide();
  7911. }
  7912. if (allowFileManager) {
  7913. viewServerBtn.click(function(e) {
  7914. var clickFn = function(url, title, id) {
  7915. K('[name="url"]', div).val(url);
  7916. if (self.afterSelectFile) {
  7917. self.afterSelectFile.call(self, url);
  7918. }
  7919. };
  7920. var cur = K('[name="url"]', div).val();
  7921. editorShowUpload(cur, self.fileManagerJson, '音视频库', clickFn, this);
  7922. /*
  7923. self.loadPlugin('filemanager', function() {
  7924. self.plugin.filemanagerDialog({
  7925. viewType : 'LIST',
  7926. dirName : 'media',
  7927. clickFn : function(url, title) {
  7928. if (self.dialogs.length > 1) {
  7929. K('[name="url"]', div).val(url);
  7930. if (self.afterSelectFile) {
  7931. self.afterSelectFile.call(self, url);
  7932. }
  7933. self.hideDialog();
  7934. }
  7935. }
  7936. });
  7937. });
  7938. */
  7939. });
  7940. } else {
  7941. viewServerBtn.hide();
  7942. }
  7943. var img = self.plugin.getSelectedMedia();
  7944. if (img) {
  7945. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7946. urlBox.val(attrs.src);
  7947. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7948. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7949. autostartBox[0].checked = (attrs.autostart === 'true');
  7950. }
  7951. urlBox[0].focus();
  7952. urlBox[0].select();
  7953. },
  7954. 'delete' : function() {
  7955. self.plugin.getSelectedMedia().remove();
  7956. self.addBookmark();
  7957. }
  7958. };
  7959. self.clickToolbar(name, self.plugin.media.edit);
  7960. });
  7961. /*******************************************************************************
  7962. * KindEditor - WYSIWYG HTML Editor for Internet
  7963. * Copyright (C) 2006-2011 kindsoft.net
  7964. *
  7965. * @author Roddy <luolonghao@gmail.com>
  7966. * @site http://www.kindsoft.net/
  7967. * @licence http://www.kindsoft.net/license.php
  7968. *******************************************************************************/
  7969. (function(K) {
  7970. function KSWFUpload(options) {
  7971. this.init(options);
  7972. }
  7973. K.extend(KSWFUpload, {
  7974. init : function(options) {
  7975. var self = this;
  7976. options.afterError = options.afterError || function(str) {
  7977. alert(str);
  7978. };
  7979. self.options = options;
  7980. self.progressbars = {};
  7981. self.div = K(options.container).html([
  7982. '<div class="ke-swfupload">',
  7983. '<div class="ke-swfupload-top">',
  7984. '<div class="ke-inline-block ke-swfupload-button">',
  7985. '<input type="button" value="Browse" />',
  7986. '</div>',
  7987. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7988. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7989. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7990. '</span>',
  7991. '</div>',
  7992. '<div class="ke-swfupload-body"></div>',
  7993. '</div>'
  7994. ].join(''));
  7995. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7996. function showError(itemDiv, msg) {
  7997. K('.ke-status > div', itemDiv).hide();
  7998. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7999. }
  8000. var settings = {
  8001. debug : false,
  8002. upload_url : options.uploadUrl,
  8003. flash_url : options.flashUrl,
  8004. file_post_name : options.filePostName,
  8005. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  8006. button_image_url: options.buttonImageUrl,
  8007. button_width: options.buttonWidth,
  8008. button_height: options.buttonHeight,
  8009. button_cursor : SWFUpload.CURSOR.HAND,
  8010. file_types : options.fileTypes,
  8011. file_types_description : options.fileTypesDesc,
  8012. file_upload_limit : options.fileUploadLimit,
  8013. file_size_limit : options.fileSizeLimit,
  8014. post_params : options.postParams,
  8015. file_queued_handler : function(file) {
  8016. file.url = self.options.fileIconUrl;
  8017. self.appendFile(file);
  8018. },
  8019. file_queue_error_handler : function(file, errorCode, message) {
  8020. var errorName = '';
  8021. switch (errorCode) {
  8022. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  8023. errorName = options.queueLimitExceeded;
  8024. break;
  8025. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  8026. errorName = options.fileExceedsSizeLimit;
  8027. break;
  8028. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  8029. errorName = options.zeroByteFile;
  8030. break;
  8031. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  8032. errorName = options.invalidFiletype;
  8033. break;
  8034. default:
  8035. errorName = options.unknownError;
  8036. break;
  8037. }
  8038. K.DEBUG && alert(errorName);
  8039. },
  8040. upload_start_handler : function(file) {
  8041. var self = this;
  8042. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  8043. K('.ke-status > div', itemDiv).hide();
  8044. K('.ke-progressbar', itemDiv).show();
  8045. },
  8046. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  8047. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  8048. var progressbar = self.progressbars[file.id];
  8049. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  8050. progressbar.percent.html(percent + '%');
  8051. },
  8052. upload_error_handler : function(file, errorCode, message) {
  8053. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  8054. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8055. showError(itemDiv, self.options.errorMessage);
  8056. }
  8057. },
  8058. upload_success_handler : function(file, serverData) {
  8059. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8060. var data = {};
  8061. try {
  8062. data = K.json(serverData);
  8063. } catch (e) {
  8064. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  8065. }
  8066. if (data.error !== 0) {
  8067. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  8068. return;
  8069. }
  8070. file.url = data.url;
  8071. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  8072. K('.ke-status > div', itemDiv).hide();
  8073. }
  8074. };
  8075. self.swfu = new SWFUpload(settings);
  8076. K('.ke-swfupload-startupload input', self.div).click(function() {
  8077. self.swfu.startUpload();
  8078. });
  8079. },
  8080. getUrlList : function() {
  8081. var list = [];
  8082. K('.ke-img', self.bodyDiv).each(function() {
  8083. var img = K(this);
  8084. var status = img.attr('data-status');
  8085. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8086. list.push(img.data('data'));
  8087. }
  8088. });
  8089. return list;
  8090. },
  8091. removeFile : function(fileId) {
  8092. var self = this;
  8093. self.swfu.cancelUpload(fileId);
  8094. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8095. K('.ke-photo', itemDiv).unbind();
  8096. K('.ke-delete', itemDiv).unbind();
  8097. itemDiv.remove();
  8098. },
  8099. removeFiles : function() {
  8100. var self = this;
  8101. K('.ke-item', self.bodyDiv).each(function() {
  8102. self.removeFile(K(this).attr('data-id'));
  8103. });
  8104. },
  8105. appendFile : function(file) {
  8106. var self = this;
  8107. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8108. self.bodyDiv.append(itemDiv);
  8109. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8110. .mouseover(function(e) {
  8111. K(this).addClass('ke-on');
  8112. })
  8113. .mouseout(function(e) {
  8114. K(this).removeClass('ke-on');
  8115. });
  8116. itemDiv.append(photoDiv);
  8117. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8118. photoDiv.append(img);
  8119. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8120. self.removeFile(file.id);
  8121. });
  8122. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8123. K(['<div class="ke-progressbar">',
  8124. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8125. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8126. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8127. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8128. self.progressbars[file.id] = {
  8129. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8130. percent : K('.ke-progressbar-percent', photoDiv)
  8131. };
  8132. },
  8133. remove : function() {
  8134. this.removeFiles();
  8135. this.swfu.destroy();
  8136. this.div.html('');
  8137. }
  8138. });
  8139. K.swfupload = function(element, options) {
  8140. return new KSWFUpload(element, options);
  8141. };
  8142. })(KindEditor);
  8143. KindEditor.plugin('multiimage', function(K) {
  8144. var self = this, name = 'multiimage',
  8145. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8146. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8147. imgPath = self.pluginsPath + 'multiimage/images/',
  8148. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8149. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8150. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8151. filePostName = K.undef(self.filePostName, 'imgFile'),
  8152. lang = self.lang(name + '.');
  8153. self.plugin.multiImageDialog = function(options) {
  8154. var clickFn = options.clickFn,
  8155. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8156. uploadDesc = '';
  8157. var html = [
  8158. '<div style="padding:20px;">',
  8159. '<div class="swfupload">',
  8160. '</div>',
  8161. '</div>'
  8162. ].join('');
  8163. var dialog = self.createDialog({
  8164. name : name,
  8165. width : 650,
  8166. height : 510,
  8167. title : self.lang(name),
  8168. body : html,
  8169. previewBtn : {
  8170. name : lang.insertAll,
  8171. click : function(e) {
  8172. clickFn.call(self, swfupload.getUrlList());
  8173. }
  8174. },
  8175. yesBtn : {
  8176. name : lang.clearAll,
  8177. click : function(e) {
  8178. swfupload.removeFiles();
  8179. }
  8180. },
  8181. beforeRemove : function() {
  8182. if (!K.IE || K.V <= 8) {
  8183. swfupload.remove();
  8184. }
  8185. }
  8186. }),
  8187. div = dialog.div;
  8188. var swfupload = K.swfupload({
  8189. container : K('.swfupload', div),
  8190. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8191. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8192. buttonHeight : 23,
  8193. fileIconUrl : imgPath + 'image.png',
  8194. uploadDesc : uploadDesc,
  8195. startButtonValue : lang.startUpload,
  8196. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8197. //uploadMediaUrl : K.addParam(uploadMediaUrl, 'dir=media'),
  8198. flashUrl : imgPath + 'swfupload.swf',
  8199. filePostName : filePostName,
  8200. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8201. fileTypesDesc : 'Image Files',
  8202. fileUploadLimit : imageUploadLimit,
  8203. fileSizeLimit : imageSizeLimit,
  8204. postParams : K.undef(self.extraFileUploadParams, {}),
  8205. queueLimitExceeded : lang.queueLimitExceeded,
  8206. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8207. zeroByteFile : lang.zeroByteFile,
  8208. invalidFiletype : lang.invalidFiletype,
  8209. unknownError : lang.unknownError,
  8210. pendingMessage : lang.pending,
  8211. errorMessage : lang.uploadError,
  8212. afterError : function(html) {
  8213. self.errorDialog(html);
  8214. }
  8215. });
  8216. return dialog;
  8217. };
  8218. self.clickToolbar(name, function() {
  8219. self.plugin.multiImageDialog({
  8220. clickFn : function (urlList) {
  8221. if (urlList.length === 0) {
  8222. return;
  8223. }
  8224. K.each(urlList, function(i, data) {
  8225. if (self.afterUpload) {
  8226. self.afterUpload.call(self, data.url, data, 'multiimage');
  8227. }
  8228. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8229. });
  8230. setTimeout(function() {
  8231. self.hideDialog().focus();
  8232. }, 0);
  8233. }
  8234. });
  8235. });
  8236. });
  8237. /* ******************* */
  8238. /* Constructor & Init */
  8239. /* ******************* */
  8240. (function() {
  8241. window.SWFUpload = function (settings) {
  8242. this.initSWFUpload(settings);
  8243. };
  8244. SWFUpload.prototype.initSWFUpload = function (settings) {
  8245. try {
  8246. this.customSettings = {};
  8247. this.settings = settings;
  8248. this.eventQueue = [];
  8249. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8250. this.movieElement = null;
  8251. SWFUpload.instances[this.movieName] = this;
  8252. this.initSettings();
  8253. this.loadFlash();
  8254. this.displayDebugInfo();
  8255. } catch (ex) {
  8256. delete SWFUpload.instances[this.movieName];
  8257. throw ex;
  8258. }
  8259. };
  8260. /* *************** */
  8261. /* Static Members */
  8262. /* *************** */
  8263. SWFUpload.instances = {};
  8264. SWFUpload.movieCount = 0;
  8265. SWFUpload.version = "2.2.0 2009-03-25";
  8266. SWFUpload.QUEUE_ERROR = {
  8267. QUEUE_LIMIT_EXCEEDED : -100,
  8268. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8269. ZERO_BYTE_FILE : -120,
  8270. INVALID_FILETYPE : -130
  8271. };
  8272. SWFUpload.UPLOAD_ERROR = {
  8273. HTTP_ERROR : -200,
  8274. MISSING_UPLOAD_URL : -210,
  8275. IO_ERROR : -220,
  8276. SECURITY_ERROR : -230,
  8277. UPLOAD_LIMIT_EXCEEDED : -240,
  8278. UPLOAD_FAILED : -250,
  8279. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8280. FILE_VALIDATION_FAILED : -270,
  8281. FILE_CANCELLED : -280,
  8282. UPLOAD_STOPPED : -290
  8283. };
  8284. SWFUpload.FILE_STATUS = {
  8285. QUEUED : -1,
  8286. IN_PROGRESS : -2,
  8287. ERROR : -3,
  8288. COMPLETE : -4,
  8289. CANCELLED : -5
  8290. };
  8291. SWFUpload.BUTTON_ACTION = {
  8292. SELECT_FILE : -100,
  8293. SELECT_FILES : -110,
  8294. START_UPLOAD : -120
  8295. };
  8296. SWFUpload.CURSOR = {
  8297. ARROW : -1,
  8298. HAND : -2
  8299. };
  8300. SWFUpload.WINDOW_MODE = {
  8301. WINDOW : "window",
  8302. TRANSPARENT : "transparent",
  8303. OPAQUE : "opaque"
  8304. };
  8305. SWFUpload.completeURL = function(url) {
  8306. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8307. return url;
  8308. }
  8309. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8310. var indexSlash = window.location.pathname.lastIndexOf("/");
  8311. var path;
  8312. if (indexSlash <= 0) {
  8313. path = "/";
  8314. } else {
  8315. path = window.location.pathname.substr(0, indexSlash) + "/";
  8316. }
  8317. return /*currentURL +*/ path + url;
  8318. };
  8319. /* ******************** */
  8320. /* Instance Members */
  8321. /* ******************** */
  8322. SWFUpload.prototype.initSettings = function () {
  8323. this.ensureDefault = function (settingName, defaultValue) {
  8324. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8325. };
  8326. this.ensureDefault("upload_url", "");
  8327. this.ensureDefault("preserve_relative_urls", false);
  8328. this.ensureDefault("file_post_name", "Filedata");
  8329. this.ensureDefault("post_params", {});
  8330. this.ensureDefault("use_query_string", false);
  8331. this.ensureDefault("requeue_on_error", false);
  8332. this.ensureDefault("http_success", []);
  8333. this.ensureDefault("assume_success_timeout", 0);
  8334. this.ensureDefault("file_types", "*.*");
  8335. this.ensureDefault("file_types_description", "All Files");
  8336. this.ensureDefault("file_size_limit", 0);
  8337. this.ensureDefault("file_upload_limit", 0);
  8338. this.ensureDefault("file_queue_limit", 0);
  8339. this.ensureDefault("flash_url", "swfupload.swf");
  8340. this.ensureDefault("prevent_swf_caching", true);
  8341. this.ensureDefault("button_image_url", "");
  8342. this.ensureDefault("button_width", 1);
  8343. this.ensureDefault("button_height", 1);
  8344. this.ensureDefault("button_text", "");
  8345. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8346. this.ensureDefault("button_text_top_padding", 0);
  8347. this.ensureDefault("button_text_left_padding", 0);
  8348. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8349. this.ensureDefault("button_disabled", false);
  8350. this.ensureDefault("button_placeholder_id", "");
  8351. this.ensureDefault("button_placeholder", null);
  8352. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8353. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8354. this.ensureDefault("debug", false);
  8355. this.settings.debug_enabled = this.settings.debug;
  8356. this.settings.return_upload_start_handler = this.returnUploadStart;
  8357. this.ensureDefault("swfupload_loaded_handler", null);
  8358. this.ensureDefault("file_dialog_start_handler", null);
  8359. this.ensureDefault("file_queued_handler", null);
  8360. this.ensureDefault("file_queue_error_handler", null);
  8361. this.ensureDefault("file_dialog_complete_handler", null);
  8362. this.ensureDefault("upload_start_handler", null);
  8363. this.ensureDefault("upload_progress_handler", null);
  8364. this.ensureDefault("upload_error_handler", null);
  8365. this.ensureDefault("upload_success_handler", null);
  8366. this.ensureDefault("upload_complete_handler", null);
  8367. this.ensureDefault("debug_handler", this.debugMessage);
  8368. this.ensureDefault("custom_settings", {});
  8369. this.customSettings = this.settings.custom_settings;
  8370. if (!!this.settings.prevent_swf_caching) {
  8371. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8372. }
  8373. if (!this.settings.preserve_relative_urls) {
  8374. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8375. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8376. }
  8377. delete this.ensureDefault;
  8378. };
  8379. SWFUpload.prototype.loadFlash = function () {
  8380. var targetElement, tempParent;
  8381. if (document.getElementById(this.movieName) !== null) {
  8382. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8383. }
  8384. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8385. if (targetElement == undefined) {
  8386. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8387. }
  8388. tempParent = document.createElement("div");
  8389. tempParent.innerHTML = this.getFlashHTML();
  8390. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8391. if (window[this.movieName] == undefined) {
  8392. window[this.movieName] = this.getMovieElement();
  8393. }
  8394. };
  8395. SWFUpload.prototype.getFlashHTML = function () {
  8396. var classid = '';
  8397. if (KindEditor.IE && KindEditor.V > 8) {
  8398. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8399. }
  8400. 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">',
  8401. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8402. '<param name="movie" value="', this.settings.flash_url, '" />',
  8403. '<param name="quality" value="high" />',
  8404. '<param name="menu" value="false" />',
  8405. '<param name="allowScriptAccess" value="always" />',
  8406. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8407. '</object>'].join("");
  8408. };
  8409. SWFUpload.prototype.getFlashVars = function () {
  8410. var paramString = this.buildParamString();
  8411. var httpSuccessString = this.settings.http_success.join(",");
  8412. return ["movieName=", encodeURIComponent(this.movieName),
  8413. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8414. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8415. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8416. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8417. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8418. "&amp;params=", encodeURIComponent(paramString),
  8419. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8420. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8421. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8422. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8423. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8424. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8425. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8426. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8427. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8428. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8429. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8430. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8431. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8432. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8433. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8434. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8435. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8436. ].join("");
  8437. };
  8438. SWFUpload.prototype.getMovieElement = function () {
  8439. if (this.movieElement == undefined) {
  8440. this.movieElement = document.getElementById(this.movieName);
  8441. }
  8442. if (this.movieElement === null) {
  8443. throw "Could not find Flash element";
  8444. }
  8445. return this.movieElement;
  8446. };
  8447. SWFUpload.prototype.buildParamString = function () {
  8448. var postParams = this.settings.post_params;
  8449. var paramStringPairs = [];
  8450. if (typeof(postParams) === "object") {
  8451. for (var name in postParams) {
  8452. if (postParams.hasOwnProperty(name)) {
  8453. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8454. }
  8455. }
  8456. }
  8457. return paramStringPairs.join("&amp;");
  8458. };
  8459. SWFUpload.prototype.destroy = function () {
  8460. try {
  8461. this.cancelUpload(null, false);
  8462. var movieElement = null;
  8463. movieElement = this.getMovieElement();
  8464. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8465. for (var i in movieElement) {
  8466. try {
  8467. if (typeof(movieElement[i]) === "function") {
  8468. movieElement[i] = null;
  8469. }
  8470. } catch (ex1) {}
  8471. }
  8472. try {
  8473. movieElement.parentNode.removeChild(movieElement);
  8474. } catch (ex) {}
  8475. }
  8476. window[this.movieName] = null;
  8477. SWFUpload.instances[this.movieName] = null;
  8478. delete SWFUpload.instances[this.movieName];
  8479. this.movieElement = null;
  8480. this.settings = null;
  8481. this.customSettings = null;
  8482. this.eventQueue = null;
  8483. this.movieName = null;
  8484. return true;
  8485. } catch (ex2) {
  8486. return false;
  8487. }
  8488. };
  8489. SWFUpload.prototype.displayDebugInfo = function () {
  8490. this.debug(
  8491. [
  8492. "---SWFUpload Instance Info---\n",
  8493. "Version: ", SWFUpload.version, "\n",
  8494. "Movie Name: ", this.movieName, "\n",
  8495. "Settings:\n",
  8496. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8497. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8498. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8499. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8500. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8501. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8502. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8503. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8504. "\t", "file_types: ", this.settings.file_types, "\n",
  8505. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8506. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8507. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8508. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8509. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8510. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8511. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8512. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8513. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8514. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8515. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8516. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8517. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8518. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8519. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8520. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8521. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8522. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8523. "Event Handlers:\n",
  8524. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8525. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8526. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8527. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8528. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8529. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8530. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8531. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8532. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8533. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8534. ].join("")
  8535. );
  8536. };
  8537. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8538. the maintain v2 API compatibility
  8539. */
  8540. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8541. if (value == undefined) {
  8542. return (this.settings[name] = default_value);
  8543. } else {
  8544. return (this.settings[name] = value);
  8545. }
  8546. };
  8547. SWFUpload.prototype.getSetting = function (name) {
  8548. if (this.settings[name] != undefined) {
  8549. return this.settings[name];
  8550. }
  8551. return "";
  8552. };
  8553. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8554. argumentArray = argumentArray || [];
  8555. var movieElement = this.getMovieElement();
  8556. var returnValue, returnString;
  8557. try {
  8558. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8559. returnValue = eval(returnString);
  8560. } catch (ex) {
  8561. throw "Call to " + functionName + " failed";
  8562. }
  8563. if (returnValue != undefined && typeof returnValue.post === "object") {
  8564. returnValue = this.unescapeFilePostParams(returnValue);
  8565. }
  8566. return returnValue;
  8567. };
  8568. /* *****************************
  8569. -- Flash control methods --
  8570. Your UI should use these
  8571. to operate SWFUpload
  8572. ***************************** */
  8573. SWFUpload.prototype.selectFile = function () {
  8574. this.callFlash("SelectFile");
  8575. };
  8576. SWFUpload.prototype.selectFiles = function () {
  8577. this.callFlash("SelectFiles");
  8578. };
  8579. SWFUpload.prototype.startUpload = function (fileID) {
  8580. this.callFlash("StartUpload", [fileID]);
  8581. };
  8582. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8583. if (triggerErrorEvent !== false) {
  8584. triggerErrorEvent = true;
  8585. }
  8586. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8587. };
  8588. SWFUpload.prototype.stopUpload = function () {
  8589. this.callFlash("StopUpload");
  8590. };
  8591. /* ************************
  8592. * Settings methods
  8593. * These methods change the SWFUpload settings.
  8594. * SWFUpload settings should not be changed directly on the settings object
  8595. * since many of the settings need to be passed to Flash in order to take
  8596. * effect.
  8597. * *********************** */
  8598. SWFUpload.prototype.getStats = function () {
  8599. return this.callFlash("GetStats");
  8600. };
  8601. SWFUpload.prototype.setStats = function (statsObject) {
  8602. this.callFlash("SetStats", [statsObject]);
  8603. };
  8604. SWFUpload.prototype.getFile = function (fileID) {
  8605. if (typeof(fileID) === "number") {
  8606. return this.callFlash("GetFileByIndex", [fileID]);
  8607. } else {
  8608. return this.callFlash("GetFile", [fileID]);
  8609. }
  8610. };
  8611. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8612. return this.callFlash("AddFileParam", [fileID, name, value]);
  8613. };
  8614. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8615. this.callFlash("RemoveFileParam", [fileID, name]);
  8616. };
  8617. SWFUpload.prototype.setUploadURL = function (url) {
  8618. this.settings.upload_url = url.toString();
  8619. this.callFlash("SetUploadURL", [url]);
  8620. };
  8621. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8622. this.settings.post_params = paramsObject;
  8623. this.callFlash("SetPostParams", [paramsObject]);
  8624. };
  8625. SWFUpload.prototype.addPostParam = function (name, value) {
  8626. this.settings.post_params[name] = value;
  8627. this.callFlash("SetPostParams", [this.settings.post_params]);
  8628. };
  8629. SWFUpload.prototype.removePostParam = function (name) {
  8630. delete this.settings.post_params[name];
  8631. this.callFlash("SetPostParams", [this.settings.post_params]);
  8632. };
  8633. SWFUpload.prototype.setFileTypes = function (types, description) {
  8634. this.settings.file_types = types;
  8635. this.settings.file_types_description = description;
  8636. this.callFlash("SetFileTypes", [types, description]);
  8637. };
  8638. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8639. this.settings.file_size_limit = fileSizeLimit;
  8640. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8641. };
  8642. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8643. this.settings.file_upload_limit = fileUploadLimit;
  8644. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8645. };
  8646. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8647. this.settings.file_queue_limit = fileQueueLimit;
  8648. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8649. };
  8650. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8651. this.settings.file_post_name = filePostName;
  8652. this.callFlash("SetFilePostName", [filePostName]);
  8653. };
  8654. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8655. this.settings.use_query_string = useQueryString;
  8656. this.callFlash("SetUseQueryString", [useQueryString]);
  8657. };
  8658. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8659. this.settings.requeue_on_error = requeueOnError;
  8660. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8661. };
  8662. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8663. if (typeof http_status_codes === "string") {
  8664. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8665. }
  8666. this.settings.http_success = http_status_codes;
  8667. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8668. };
  8669. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8670. this.settings.assume_success_timeout = timeout_seconds;
  8671. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8672. };
  8673. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8674. this.settings.debug_enabled = debugEnabled;
  8675. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8676. };
  8677. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8678. if (buttonImageURL == undefined) {
  8679. buttonImageURL = "";
  8680. }
  8681. this.settings.button_image_url = buttonImageURL;
  8682. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8683. };
  8684. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8685. this.settings.button_width = width;
  8686. this.settings.button_height = height;
  8687. var movie = this.getMovieElement();
  8688. if (movie != undefined) {
  8689. movie.style.width = width + "px";
  8690. movie.style.height = height + "px";
  8691. }
  8692. this.callFlash("SetButtonDimensions", [width, height]);
  8693. };
  8694. SWFUpload.prototype.setButtonText = function (html) {
  8695. this.settings.button_text = html;
  8696. this.callFlash("SetButtonText", [html]);
  8697. };
  8698. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8699. this.settings.button_text_top_padding = top;
  8700. this.settings.button_text_left_padding = left;
  8701. this.callFlash("SetButtonTextPadding", [left, top]);
  8702. };
  8703. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8704. this.settings.button_text_style = css;
  8705. this.callFlash("SetButtonTextStyle", [css]);
  8706. };
  8707. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8708. this.settings.button_disabled = isDisabled;
  8709. this.callFlash("SetButtonDisabled", [isDisabled]);
  8710. };
  8711. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8712. this.settings.button_action = buttonAction;
  8713. this.callFlash("SetButtonAction", [buttonAction]);
  8714. };
  8715. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8716. this.settings.button_cursor = cursor;
  8717. this.callFlash("SetButtonCursor", [cursor]);
  8718. };
  8719. /* *******************************
  8720. Flash Event Interfaces
  8721. These functions are used by Flash to trigger the various
  8722. events.
  8723. All these functions a Private.
  8724. Because the ExternalInterface library is buggy the event calls
  8725. are added to a queue and the queue then executed by a setTimeout.
  8726. This ensures that events are executed in a determinate order and that
  8727. the ExternalInterface bugs are avoided.
  8728. ******************************* */
  8729. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8730. if (argumentArray == undefined) {
  8731. argumentArray = [];
  8732. } else if (!(argumentArray instanceof Array)) {
  8733. argumentArray = [argumentArray];
  8734. }
  8735. var self = this;
  8736. if (typeof this.settings[handlerName] === "function") {
  8737. this.eventQueue.push(function () {
  8738. this.settings[handlerName].apply(this, argumentArray);
  8739. });
  8740. setTimeout(function () {
  8741. self.executeNextEvent();
  8742. }, 0);
  8743. } else if (this.settings[handlerName] !== null) {
  8744. throw "Event handler " + handlerName + " is unknown or is not a function";
  8745. }
  8746. };
  8747. SWFUpload.prototype.executeNextEvent = function () {
  8748. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8749. if (typeof(f) === "function") {
  8750. f.apply(this);
  8751. }
  8752. };
  8753. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8754. var reg = /[$]([0-9a-f]{4})/i;
  8755. var unescapedPost = {};
  8756. var uk;
  8757. if (file != undefined) {
  8758. for (var k in file.post) {
  8759. if (file.post.hasOwnProperty(k)) {
  8760. uk = k;
  8761. var match;
  8762. while ((match = reg.exec(uk)) !== null) {
  8763. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8764. }
  8765. unescapedPost[uk] = file.post[k];
  8766. }
  8767. }
  8768. file.post = unescapedPost;
  8769. }
  8770. return file;
  8771. };
  8772. SWFUpload.prototype.testExternalInterface = function () {
  8773. try {
  8774. return this.callFlash("TestExternalInterface");
  8775. } catch (ex) {
  8776. return false;
  8777. }
  8778. };
  8779. SWFUpload.prototype.flashReady = function () {
  8780. var movieElement = this.getMovieElement();
  8781. if (!movieElement) {
  8782. this.debug("Flash called back ready but the flash movie can't be found.");
  8783. return;
  8784. }
  8785. this.cleanUp(movieElement);
  8786. this.queueEvent("swfupload_loaded_handler");
  8787. };
  8788. SWFUpload.prototype.cleanUp = function (movieElement) {
  8789. try {
  8790. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8791. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8792. for (var key in movieElement) {
  8793. try {
  8794. if (typeof(movieElement[key]) === "function") {
  8795. movieElement[key] = null;
  8796. }
  8797. } catch (ex) {
  8798. }
  8799. }
  8800. }
  8801. } catch (ex1) {
  8802. }
  8803. window["__flash__removeCallback"] = function (instance, name) {
  8804. try {
  8805. if (instance) {
  8806. instance[name] = null;
  8807. }
  8808. } catch (flashEx) {
  8809. }
  8810. };
  8811. };
  8812. /* This is a chance to do something before the browse window opens */
  8813. SWFUpload.prototype.fileDialogStart = function () {
  8814. this.queueEvent("file_dialog_start_handler");
  8815. };
  8816. /* Called when a file is successfully added to the queue. */
  8817. SWFUpload.prototype.fileQueued = function (file) {
  8818. file = this.unescapeFilePostParams(file);
  8819. this.queueEvent("file_queued_handler", file);
  8820. };
  8821. /* Handle errors that occur when an attempt to queue a file fails. */
  8822. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8823. file = this.unescapeFilePostParams(file);
  8824. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8825. };
  8826. /* Called after the file dialog has closed and the selected files have been queued.
  8827. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8828. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8829. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8830. };
  8831. SWFUpload.prototype.uploadStart = function (file) {
  8832. file = this.unescapeFilePostParams(file);
  8833. this.queueEvent("return_upload_start_handler", file);
  8834. };
  8835. SWFUpload.prototype.returnUploadStart = function (file) {
  8836. var returnValue;
  8837. if (typeof this.settings.upload_start_handler === "function") {
  8838. file = this.unescapeFilePostParams(file);
  8839. returnValue = this.settings.upload_start_handler.call(this, file);
  8840. } else if (this.settings.upload_start_handler != undefined) {
  8841. throw "upload_start_handler must be a function";
  8842. }
  8843. if (returnValue === undefined) {
  8844. returnValue = true;
  8845. }
  8846. returnValue = !!returnValue;
  8847. this.callFlash("ReturnUploadStart", [returnValue]);
  8848. };
  8849. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8850. file = this.unescapeFilePostParams(file);
  8851. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8852. };
  8853. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8854. file = this.unescapeFilePostParams(file);
  8855. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8856. };
  8857. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8858. file = this.unescapeFilePostParams(file);
  8859. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8860. };
  8861. SWFUpload.prototype.uploadComplete = function (file) {
  8862. file = this.unescapeFilePostParams(file);
  8863. this.queueEvent("upload_complete_handler", file);
  8864. };
  8865. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8866. internal debug console. You can override this event and have messages written where you want. */
  8867. SWFUpload.prototype.debug = function (message) {
  8868. this.queueEvent("debug_handler", message);
  8869. };
  8870. /* **********************************
  8871. Debug Console
  8872. The debug console is a self contained, in page location
  8873. for debug message to be sent. The Debug Console adds
  8874. itself to the body if necessary.
  8875. The console is automatically scrolled as messages appear.
  8876. If you are using your own debug handler or when you deploy to production and
  8877. have debug disabled you can remove these functions to reduce the file size
  8878. and complexity.
  8879. ********************************** */
  8880. SWFUpload.prototype.debugMessage = function (message) {
  8881. if (this.settings.debug) {
  8882. var exceptionMessage, exceptionValues = [];
  8883. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8884. for (var key in message) {
  8885. if (message.hasOwnProperty(key)) {
  8886. exceptionValues.push(key + ": " + message[key]);
  8887. }
  8888. }
  8889. exceptionMessage = exceptionValues.join("\n") || "";
  8890. exceptionValues = exceptionMessage.split("\n");
  8891. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8892. SWFUpload.Console.writeLine(exceptionMessage);
  8893. } else {
  8894. SWFUpload.Console.writeLine(message);
  8895. }
  8896. }
  8897. };
  8898. SWFUpload.Console = {};
  8899. SWFUpload.Console.writeLine = function (message) {
  8900. var console, documentForm;
  8901. try {
  8902. console = document.getElementById("SWFUpload_Console");
  8903. if (!console) {
  8904. documentForm = document.createElement("form");
  8905. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8906. console = document.createElement("textarea");
  8907. console.id = "SWFUpload_Console";
  8908. console.style.fontFamily = "monospace";
  8909. console.setAttribute("wrap", "off");
  8910. console.wrap = "off";
  8911. console.style.overflow = "auto";
  8912. console.style.width = "700px";
  8913. console.style.height = "350px";
  8914. console.style.margin = "5px";
  8915. documentForm.appendChild(console);
  8916. }
  8917. console.value += message + "\n";
  8918. console.scrollTop = console.scrollHeight - console.clientHeight;
  8919. } catch (ex) {
  8920. alert("Exception: " + ex.name + " Message: " + ex.message);
  8921. }
  8922. };
  8923. })();
  8924. (function() {
  8925. /*
  8926. Queue Plug-in
  8927. Features:
  8928. *Adds a cancelQueue() method for cancelling the entire queue.
  8929. *All queued files are uploaded when startUpload() is called.
  8930. *If false is returned from uploadComplete then the queue upload is stopped.
  8931. If false is not returned (strict comparison) then the queue upload is continued.
  8932. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8933. Set the event handler with the queue_complete_handler setting.
  8934. */
  8935. if (typeof(SWFUpload) === "function") {
  8936. SWFUpload.queue = {};
  8937. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8938. return function () {
  8939. if (typeof(oldInitSettings) === "function") {
  8940. oldInitSettings.call(this);
  8941. }
  8942. this.queueSettings = {};
  8943. this.queueSettings.queue_cancelled_flag = false;
  8944. this.queueSettings.queue_upload_count = 0;
  8945. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8946. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8947. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8948. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8949. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8950. };
  8951. })(SWFUpload.prototype.initSettings);
  8952. SWFUpload.prototype.startUpload = function (fileID) {
  8953. this.queueSettings.queue_cancelled_flag = false;
  8954. this.callFlash("StartUpload", [fileID]);
  8955. };
  8956. SWFUpload.prototype.cancelQueue = function () {
  8957. this.queueSettings.queue_cancelled_flag = true;
  8958. this.stopUpload();
  8959. var stats = this.getStats();
  8960. while (stats.files_queued > 0) {
  8961. this.cancelUpload();
  8962. stats = this.getStats();
  8963. }
  8964. };
  8965. SWFUpload.queue.uploadStartHandler = function (file) {
  8966. var returnValue;
  8967. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8968. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8969. }
  8970. returnValue = (returnValue === false) ? false : true;
  8971. this.queueSettings.queue_cancelled_flag = !returnValue;
  8972. return returnValue;
  8973. };
  8974. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8975. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8976. var continueUpload;
  8977. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8978. this.queueSettings.queue_upload_count++;
  8979. }
  8980. if (typeof(user_upload_complete_handler) === "function") {
  8981. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8982. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8983. continueUpload = false;
  8984. } else {
  8985. continueUpload = true;
  8986. }
  8987. if (continueUpload) {
  8988. var stats = this.getStats();
  8989. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8990. this.startUpload();
  8991. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8992. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8993. this.queueSettings.queue_upload_count = 0;
  8994. } else {
  8995. this.queueSettings.queue_cancelled_flag = false;
  8996. this.queueSettings.queue_upload_count = 0;
  8997. }
  8998. }
  8999. };
  9000. }
  9001. })();
  9002. /*******************************************************************************
  9003. * KindEditor - WYSIWYG HTML Editor for Internet
  9004. * Copyright (C) 2006-2011 kindsoft.net
  9005. *
  9006. * @author Roddy <luolonghao@gmail.com>
  9007. * @site http://www.kindsoft.net/
  9008. * @licence http://www.kindsoft.net/license.php
  9009. *******************************************************************************/
  9010. KindEditor.plugin('pagebreak', function(K) {
  9011. var self = this;
  9012. var name = 'pagebreak';
  9013. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  9014. self.clickToolbar(name, function() {
  9015. var cmd = self.cmd, range = cmd.range;
  9016. self.focus();
  9017. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  9018. self.insertHtml(pagebreakHtml + tail);
  9019. if (tail !== '') {
  9020. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9021. range.selectNodeContents(p[0]);
  9022. p.removeAttr('id');
  9023. cmd.select();
  9024. }
  9025. });
  9026. });
  9027. /*******************************************************************************
  9028. * KindEditor - WYSIWYG HTML Editor for Internet
  9029. * Copyright (C) 2006-2011 kindsoft.net
  9030. *
  9031. * @author Roddy <luolonghao@gmail.com>
  9032. * @site http://www.kindsoft.net/
  9033. * @licence http://www.kindsoft.net/license.php
  9034. *******************************************************************************/
  9035. KindEditor.plugin('plainpaste', function(K) {
  9036. var self = this, name = 'plainpaste';
  9037. self.clickToolbar(name, function() {
  9038. var lang = self.lang(name + '.'),
  9039. html = '<div style="padding:10px 20px;">' +
  9040. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9041. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9042. '</div>',
  9043. dialog = self.createDialog({
  9044. name : name,
  9045. width : 450,
  9046. title : self.lang(name),
  9047. body : html,
  9048. yesBtn : {
  9049. name : self.lang('yes'),
  9050. click : function(e) {
  9051. var html = textarea.val();
  9052. html = K.escape(html);
  9053. html = html.replace(/ {2}/g, ' &nbsp;');
  9054. if (self.newlineTag == 'p') {
  9055. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9056. } else {
  9057. html = html.replace(/\n/g, '<br />$&');
  9058. }
  9059. self.insertHtml(html).hideDialog().focus();
  9060. }
  9061. }
  9062. }),
  9063. textarea = K('textarea', dialog.div);
  9064. textarea[0].focus();
  9065. });
  9066. });
  9067. /*******************************************************************************
  9068. * KindEditor - WYSIWYG HTML Editor for Internet
  9069. * Copyright (C) 2006-2011 kindsoft.net
  9070. *
  9071. * @author Roddy <luolonghao@gmail.com>
  9072. * @site http://www.kindsoft.net/
  9073. * @licence http://www.kindsoft.net/license.php
  9074. *******************************************************************************/
  9075. KindEditor.plugin('preview', function(K) {
  9076. var self = this, name = 'preview', undefined;
  9077. self.clickToolbar(name, function() {
  9078. var lang = self.lang(name + '.'),
  9079. html = '<div style="padding:10px 20px;">' +
  9080. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9081. '</div>',
  9082. dialog = self.createDialog({
  9083. name : name,
  9084. width : 750,
  9085. title : self.lang(name),
  9086. body : html
  9087. }),
  9088. iframe = K('iframe', dialog.div),
  9089. doc = K.iframeDoc(iframe);
  9090. doc.open();
  9091. doc.write(self.fullHtml());
  9092. doc.close();
  9093. K(doc.body).css('background-color', '#FFF');
  9094. iframe[0].contentWindow.focus();
  9095. });
  9096. });
  9097. /*******************************************************************************
  9098. * KindEditor - WYSIWYG HTML Editor for Internet
  9099. * Copyright (C) 2006-2011 kindsoft.net
  9100. *
  9101. * @author Roddy <luolonghao@gmail.com>
  9102. * @site http://www.kindsoft.net/
  9103. * @licence http://www.kindsoft.net/license.php
  9104. *******************************************************************************/
  9105. KindEditor.plugin('quickformat', function(K) {
  9106. var self = this, name = 'quickformat',
  9107. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9108. function getFirstChild(knode) {
  9109. var child = knode.first();
  9110. while (child && child.first()) {
  9111. child = child.first();
  9112. }
  9113. return child;
  9114. }
  9115. self.clickToolbar(name, function() {
  9116. self.focus();
  9117. var doc = self.edit.doc,
  9118. range = self.cmd.range,
  9119. child = K(doc.body).first(), next,
  9120. nodeList = [], subList = [],
  9121. bookmark = range.createBookmark(true);
  9122. while(child) {
  9123. next = child.next();
  9124. var firstChild = getFirstChild(child);
  9125. if (!firstChild || firstChild.name != 'img') {
  9126. if (blockMap[child.name]) {
  9127. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9128. child.css('text-indent', '2em');
  9129. } else {
  9130. subList.push(child);
  9131. }
  9132. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9133. if (subList.length > 0) {
  9134. nodeList.push(subList);
  9135. }
  9136. subList = [];
  9137. }
  9138. }
  9139. child = next;
  9140. }
  9141. K.each(nodeList, function(i, subList) {
  9142. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9143. subList[0].before(wrapper);
  9144. K.each(subList, function(i, knode) {
  9145. wrapper.append(knode);
  9146. });
  9147. });
  9148. range.moveToBookmark(bookmark);
  9149. self.addBookmark();
  9150. });
  9151. });
  9152. /*******************************************************************************
  9153. * KindEditor - WYSIWYG HTML Editor for Internet
  9154. * Copyright (C) 2006-2011 kindsoft.net
  9155. *
  9156. * @author Roddy <luolonghao@gmail.com>
  9157. * @site http://www.kindsoft.net/
  9158. * @licence http://www.kindsoft.net/license.php
  9159. *******************************************************************************/
  9160. KindEditor.plugin('table', function(K) {
  9161. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9162. function _setColor(box, color) {
  9163. color = color.toUpperCase();
  9164. box.css('background-color', color);
  9165. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9166. box.html(color);
  9167. }
  9168. var pickerList = [];
  9169. function _initColorPicker(dialogDiv, colorBox) {
  9170. colorBox.bind('click,mousedown', function(e){
  9171. e.stopPropagation();
  9172. });
  9173. function removePicker() {
  9174. K.each(pickerList, function() {
  9175. this.remove();
  9176. });
  9177. pickerList = [];
  9178. K(document).unbind('click,mousedown', removePicker);
  9179. dialogDiv.unbind('click,mousedown', removePicker);
  9180. }
  9181. colorBox.click(function(e) {
  9182. removePicker();
  9183. var box = K(this),
  9184. pos = box.pos();
  9185. var picker = K.colorpicker({
  9186. x : pos.x,
  9187. y : pos.y + box.height(),
  9188. z : 811214,
  9189. selectedColor : K(this).html(),
  9190. colors : self.colorTable,
  9191. noColor : self.lang('noColor'),
  9192. shadowMode : self.shadowMode,
  9193. click : function(color) {
  9194. _setColor(box, color);
  9195. removePicker();
  9196. }
  9197. });
  9198. pickerList.push(picker);
  9199. K(document).bind('click,mousedown', removePicker);
  9200. dialogDiv.bind('click,mousedown', removePicker);
  9201. });
  9202. }
  9203. function _getCellIndex(table, row, cell) {
  9204. var rowSpanCount = 0;
  9205. for (var i = 0, len = row.cells.length; i < len; i++) {
  9206. if (row.cells[i] == cell) {
  9207. break;
  9208. }
  9209. rowSpanCount += row.cells[i].rowSpan - 1;
  9210. }
  9211. return cell.cellIndex - rowSpanCount;
  9212. }
  9213. self.plugin.table = {
  9214. prop : function(isInsert) {
  9215. var html = [
  9216. '<div style="padding:20px;">',
  9217. '<div class="ke-dialog-row">',
  9218. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9219. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9220. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9221. '</div>',
  9222. '<div class="ke-dialog-row">',
  9223. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9224. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9225. '<select name="widthType">',
  9226. '<option value="%">' + lang.percent + '</option>',
  9227. '<option value="px">' + lang.px + '</option>',
  9228. '</select> &nbsp; ',
  9229. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9230. '<select name="heightType">',
  9231. '<option value="%">' + lang.percent + '</option>',
  9232. '<option value="px">' + lang.px + '</option>',
  9233. '</select>',
  9234. '</div>',
  9235. '<div class="ke-dialog-row">',
  9236. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9237. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9238. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9239. '</div>',
  9240. '<div class="ke-dialog-row">',
  9241. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9242. '<select id="keAlign" name="align">',
  9243. '<option value="">' + lang.alignDefault + '</option>',
  9244. '<option value="left">' + lang.alignLeft + '</option>',
  9245. '<option value="center">' + lang.alignCenter + '</option>',
  9246. '<option value="right">' + lang.alignRight + '</option>',
  9247. '</select>',
  9248. '</div>',
  9249. '<div class="ke-dialog-row">',
  9250. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9251. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9252. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9253. '</div>',
  9254. '<div class="ke-dialog-row">',
  9255. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9256. '<span class="ke-inline-block ke-input-color"></span>',
  9257. '</div>',
  9258. '</div>'
  9259. ].join('');
  9260. var bookmark = self.cmd.range.createBookmark();
  9261. var dialog = self.createDialog({
  9262. name : name,
  9263. width : 500,
  9264. title : self.lang(name),
  9265. body : html,
  9266. beforeRemove : function() {
  9267. colorBox.unbind();
  9268. },
  9269. yesBtn : {
  9270. name : self.lang('yes'),
  9271. click : function(e) {
  9272. var rows = rowsBox.val(),
  9273. cols = colsBox.val(),
  9274. width = widthBox.val(),
  9275. height = heightBox.val(),
  9276. widthType = widthTypeBox.val(),
  9277. heightType = heightTypeBox.val(),
  9278. padding = paddingBox.val(),
  9279. spacing = spacingBox.val(),
  9280. align = alignBox.val(),
  9281. border = borderBox.val(),
  9282. borderColor = K(colorBox[0]).html() || '',
  9283. bgColor = K(colorBox[1]).html() || '';
  9284. if (rows == 0 || !/^\d+$/.test(rows)) {
  9285. alert(self.lang('invalidRows'));
  9286. rowsBox[0].focus();
  9287. return;
  9288. }
  9289. if (cols == 0 || !/^\d+$/.test(cols)) {
  9290. alert(self.lang('invalidRows'));
  9291. colsBox[0].focus();
  9292. return;
  9293. }
  9294. if (!/^\d*$/.test(width)) {
  9295. alert(self.lang('invalidWidth'));
  9296. widthBox[0].focus();
  9297. return;
  9298. }
  9299. if (!/^\d*$/.test(height)) {
  9300. alert(self.lang('invalidHeight'));
  9301. heightBox[0].focus();
  9302. return;
  9303. }
  9304. if (!/^\d*$/.test(padding)) {
  9305. alert(self.lang('invalidPadding'));
  9306. paddingBox[0].focus();
  9307. return;
  9308. }
  9309. if (!/^\d*$/.test(spacing)) {
  9310. alert(self.lang('invalidSpacing'));
  9311. spacingBox[0].focus();
  9312. return;
  9313. }
  9314. if (!/^\d*$/.test(border)) {
  9315. alert(self.lang('invalidBorder'));
  9316. borderBox[0].focus();
  9317. return;
  9318. }
  9319. if (table) {
  9320. if (width !== '') {
  9321. table.width(width + widthType);
  9322. } else {
  9323. table.css('width', '');
  9324. }
  9325. if (table[0].width !== undefined) {
  9326. table.removeAttr('width');
  9327. }
  9328. if (height !== '') {
  9329. table.height(height + heightType);
  9330. } else {
  9331. table.css('height', '');
  9332. }
  9333. if (table[0].height !== undefined) {
  9334. table.removeAttr('height');
  9335. }
  9336. table.css('background-color', bgColor);
  9337. if (table[0].bgColor !== undefined) {
  9338. table.removeAttr('bgColor');
  9339. }
  9340. if (padding !== '') {
  9341. table[0].cellPadding = padding;
  9342. } else {
  9343. table.removeAttr('cellPadding');
  9344. }
  9345. if (spacing !== '') {
  9346. table[0].cellSpacing = spacing;
  9347. } else {
  9348. table.removeAttr('cellSpacing');
  9349. }
  9350. if (align !== '') {
  9351. table[0].align = align;
  9352. } else {
  9353. table.removeAttr('align');
  9354. }
  9355. if (border !== '') {
  9356. table.attr('border', border);
  9357. } else {
  9358. table.removeAttr('border');
  9359. }
  9360. if (border === '' || border === '0') {
  9361. table.addClass(zeroborder);
  9362. } else {
  9363. table.removeClass(zeroborder);
  9364. }
  9365. if (borderColor !== '') {
  9366. table.attr('borderColor', borderColor);
  9367. } else {
  9368. table.removeAttr('borderColor');
  9369. }
  9370. self.hideDialog().focus();
  9371. self.cmd.range.moveToBookmark(bookmark);
  9372. self.cmd.select();
  9373. self.addBookmark();
  9374. return;
  9375. }
  9376. var style = '';
  9377. if (width !== '') {
  9378. style += 'width:' + width + widthType + ';';
  9379. }
  9380. if (height !== '') {
  9381. style += 'height:' + height + heightType + ';';
  9382. }
  9383. if (bgColor !== '') {
  9384. style += 'background-color:' + bgColor + ';';
  9385. }
  9386. var html = '<table';
  9387. if (style !== '') {
  9388. html += ' style="' + style + '"';
  9389. }
  9390. if (padding !== '') {
  9391. html += ' cellpadding="' + padding + '"';
  9392. }
  9393. if (spacing !== '') {
  9394. html += ' cellspacing="' + spacing + '"';
  9395. }
  9396. if (align !== '') {
  9397. html += ' align="' + align + '"';
  9398. }
  9399. if (border !== '') {
  9400. html += ' border="' + border + '"';
  9401. }
  9402. if (border === '' || border === '0') {
  9403. html += ' class="' + zeroborder + '"';
  9404. }
  9405. if (borderColor !== '') {
  9406. html += ' bordercolor="' + borderColor + '"';
  9407. }
  9408. html += '>';
  9409. for (var i = 0; i < rows; i++) {
  9410. html += '<tr>';
  9411. for (var j = 0; j < cols; j++) {
  9412. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9413. }
  9414. html += '</tr>';
  9415. }
  9416. html += '</table>';
  9417. if (!K.IE) {
  9418. html += '<br />';
  9419. }
  9420. self.insertHtml(html);
  9421. self.select().hideDialog().focus();
  9422. self.addBookmark();
  9423. }
  9424. }
  9425. }),
  9426. div = dialog.div,
  9427. rowsBox = K('[name="rows"]', div).val(3),
  9428. colsBox = K('[name="cols"]', div).val(2),
  9429. widthBox = K('[name="width"]', div).val(100),
  9430. heightBox = K('[name="height"]', div),
  9431. widthTypeBox = K('[name="widthType"]', div),
  9432. heightTypeBox = K('[name="heightType"]', div),
  9433. paddingBox = K('[name="padding"]', div).val(2),
  9434. spacingBox = K('[name="spacing"]', div).val(0),
  9435. alignBox = K('[name="align"]', div),
  9436. borderBox = K('[name="border"]', div).val(1),
  9437. colorBox = K('.ke-input-color', div);
  9438. _initColorPicker(div, colorBox.eq(0));
  9439. _initColorPicker(div, colorBox.eq(1));
  9440. _setColor(colorBox.eq(0), '#000000');
  9441. _setColor(colorBox.eq(1), '');
  9442. rowsBox[0].focus();
  9443. rowsBox[0].select();
  9444. var table;
  9445. if (isInsert) {
  9446. return;
  9447. }
  9448. table = self.plugin.getSelectedTable();
  9449. if (table) {
  9450. rowsBox.val(table[0].rows.length);
  9451. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9452. rowsBox.attr('disabled', true);
  9453. colsBox.attr('disabled', true);
  9454. var match,
  9455. tableWidth = table[0].style.width || table[0].width,
  9456. tableHeight = table[0].style.height || table[0].height;
  9457. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9458. widthBox.val(match[1]);
  9459. widthTypeBox.val(match[2]);
  9460. } else {
  9461. widthBox.val('');
  9462. }
  9463. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9464. heightBox.val(match[1]);
  9465. heightTypeBox.val(match[2]);
  9466. }
  9467. paddingBox.val(table[0].cellPadding || '');
  9468. spacingBox.val(table[0].cellSpacing || '');
  9469. alignBox.val(table[0].align || '');
  9470. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9471. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9472. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9473. widthBox[0].focus();
  9474. widthBox[0].select();
  9475. }
  9476. },
  9477. cellprop : function() {
  9478. var html = [
  9479. '<div style="padding:20px;">',
  9480. '<div class="ke-dialog-row">',
  9481. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9482. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9483. '<select name="widthType">',
  9484. '<option value="%">' + lang.percent + '</option>',
  9485. '<option value="px">' + lang.px + '</option>',
  9486. '</select> &nbsp; ',
  9487. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9488. '<select name="heightType">',
  9489. '<option value="%">' + lang.percent + '</option>',
  9490. '<option value="px">' + lang.px + '</option>',
  9491. '</select>',
  9492. '</div>',
  9493. '<div class="ke-dialog-row">',
  9494. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9495. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9496. '<option value="">' + lang.alignDefault + '</option>',
  9497. '<option value="left">' + lang.alignLeft + '</option>',
  9498. '<option value="center">' + lang.alignCenter + '</option>',
  9499. '<option value="right">' + lang.alignRight + '</option>',
  9500. '</select> ',
  9501. lang.verticalAlign + ' <select name="verticalAlign">',
  9502. '<option value="">' + lang.alignDefault + '</option>',
  9503. '<option value="top">' + lang.alignTop + '</option>',
  9504. '<option value="middle">' + lang.alignMiddle + '</option>',
  9505. '<option value="bottom">' + lang.alignBottom + '</option>',
  9506. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9507. '</select>',
  9508. '</div>',
  9509. '<div class="ke-dialog-row">',
  9510. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9511. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9512. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9513. '</div>',
  9514. '<div class="ke-dialog-row">',
  9515. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9516. '<span class="ke-inline-block ke-input-color"></span>',
  9517. '</div>',
  9518. '</div>'
  9519. ].join('');
  9520. var bookmark = self.cmd.range.createBookmark();
  9521. var dialog = self.createDialog({
  9522. name : name,
  9523. width : 500,
  9524. title : self.lang('tablecell'),
  9525. body : html,
  9526. beforeRemove : function() {
  9527. colorBox.unbind();
  9528. },
  9529. yesBtn : {
  9530. name : self.lang('yes'),
  9531. click : function(e) {
  9532. var width = widthBox.val(),
  9533. height = heightBox.val(),
  9534. widthType = widthTypeBox.val(),
  9535. heightType = heightTypeBox.val(),
  9536. padding = paddingBox.val(),
  9537. spacing = spacingBox.val(),
  9538. textAlign = textAlignBox.val(),
  9539. verticalAlign = verticalAlignBox.val(),
  9540. border = borderBox.val(),
  9541. borderColor = K(colorBox[0]).html() || '',
  9542. bgColor = K(colorBox[1]).html() || '';
  9543. if (!/^\d*$/.test(width)) {
  9544. alert(self.lang('invalidWidth'));
  9545. widthBox[0].focus();
  9546. return;
  9547. }
  9548. if (!/^\d*$/.test(height)) {
  9549. alert(self.lang('invalidHeight'));
  9550. heightBox[0].focus();
  9551. return;
  9552. }
  9553. if (!/^\d*$/.test(border)) {
  9554. alert(self.lang('invalidBorder'));
  9555. borderBox[0].focus();
  9556. return;
  9557. }
  9558. cell.css({
  9559. width : width !== '' ? (width + widthType) : '',
  9560. height : height !== '' ? (height + heightType) : '',
  9561. 'background-color' : bgColor,
  9562. 'text-align' : textAlign,
  9563. 'vertical-align' : verticalAlign,
  9564. 'border-width' : border,
  9565. 'border-style' : border !== '' ? 'solid' : '',
  9566. 'border-color' : borderColor
  9567. });
  9568. self.hideDialog().focus();
  9569. self.cmd.range.moveToBookmark(bookmark);
  9570. self.cmd.select();
  9571. self.addBookmark();
  9572. }
  9573. }
  9574. }),
  9575. div = dialog.div,
  9576. widthBox = K('[name="width"]', div).val(100),
  9577. heightBox = K('[name="height"]', div),
  9578. widthTypeBox = K('[name="widthType"]', div),
  9579. heightTypeBox = K('[name="heightType"]', div),
  9580. paddingBox = K('[name="padding"]', div).val(2),
  9581. spacingBox = K('[name="spacing"]', div).val(0),
  9582. textAlignBox = K('[name="textAlign"]', div),
  9583. verticalAlignBox = K('[name="verticalAlign"]', div),
  9584. borderBox = K('[name="border"]', div).val(1),
  9585. colorBox = K('.ke-input-color', div);
  9586. _initColorPicker(div, colorBox.eq(0));
  9587. _initColorPicker(div, colorBox.eq(1));
  9588. _setColor(colorBox.eq(0), '#000000');
  9589. _setColor(colorBox.eq(1), '');
  9590. widthBox[0].focus();
  9591. widthBox[0].select();
  9592. var cell = self.plugin.getSelectedCell();
  9593. var match,
  9594. cellWidth = cell[0].style.width || cell[0].width || '',
  9595. cellHeight = cell[0].style.height || cell[0].height || '';
  9596. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9597. widthBox.val(match[1]);
  9598. widthTypeBox.val(match[2]);
  9599. } else {
  9600. widthBox.val('');
  9601. }
  9602. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9603. heightBox.val(match[1]);
  9604. heightTypeBox.val(match[2]);
  9605. }
  9606. textAlignBox.val(cell[0].style.textAlign || '');
  9607. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9608. var border = cell[0].style.borderWidth || '';
  9609. if (border) {
  9610. border = parseInt(border);
  9611. }
  9612. borderBox.val(border);
  9613. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9614. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9615. widthBox[0].focus();
  9616. widthBox[0].select();
  9617. },
  9618. insert : function() {
  9619. this.prop(true);
  9620. },
  9621. 'delete' : function() {
  9622. var table = self.plugin.getSelectedTable();
  9623. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9624. self.cmd.select();
  9625. table.remove();
  9626. self.addBookmark();
  9627. },
  9628. colinsert : function(offset) {
  9629. var table = self.plugin.getSelectedTable()[0],
  9630. row = self.plugin.getSelectedRow()[0],
  9631. cell = self.plugin.getSelectedCell()[0],
  9632. index = cell.cellIndex + offset;
  9633. index += table.rows[0].cells.length - row.cells.length;
  9634. for (var i = 0, len = table.rows.length; i < len; i++) {
  9635. var newRow = table.rows[i],
  9636. newCell = newRow.insertCell(index);
  9637. newCell.innerHTML = K.IE ? '' : '<br />';
  9638. index = _getCellIndex(table, newRow, newCell);
  9639. }
  9640. self.cmd.range.selectNodeContents(cell).collapse(true);
  9641. self.cmd.select();
  9642. self.addBookmark();
  9643. },
  9644. colinsertleft : function() {
  9645. this.colinsert(0);
  9646. },
  9647. colinsertright : function() {
  9648. this.colinsert(1);
  9649. },
  9650. rowinsert : function(offset) {
  9651. var table = self.plugin.getSelectedTable()[0],
  9652. row = self.plugin.getSelectedRow()[0],
  9653. cell = self.plugin.getSelectedCell()[0];
  9654. var rowIndex = row.rowIndex;
  9655. if (offset === 1) {
  9656. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9657. }
  9658. var newRow = table.insertRow(rowIndex);
  9659. for (var i = 0, len = row.cells.length; i < len; i++) {
  9660. if (row.cells[i].rowSpan > 1) {
  9661. len -= row.cells[i].rowSpan - 1;
  9662. }
  9663. var newCell = newRow.insertCell(i);
  9664. if (offset === 1 && row.cells[i].colSpan > 1) {
  9665. newCell.colSpan = row.cells[i].colSpan;
  9666. }
  9667. newCell.innerHTML = K.IE ? '' : '<br />';
  9668. }
  9669. for (var j = rowIndex; j >= 0; j--) {
  9670. var cells = table.rows[j].cells;
  9671. if (cells.length > i) {
  9672. for (var k = cell.cellIndex; k >= 0; k--) {
  9673. if (cells[k].rowSpan > 1) {
  9674. cells[k].rowSpan += 1;
  9675. }
  9676. }
  9677. break;
  9678. }
  9679. }
  9680. self.cmd.range.selectNodeContents(cell).collapse(true);
  9681. self.cmd.select();
  9682. self.addBookmark();
  9683. },
  9684. rowinsertabove : function() {
  9685. this.rowinsert(0);
  9686. },
  9687. rowinsertbelow : function() {
  9688. this.rowinsert(1);
  9689. },
  9690. rowmerge : function() {
  9691. var table = self.plugin.getSelectedTable()[0],
  9692. row = self.plugin.getSelectedRow()[0],
  9693. cell = self.plugin.getSelectedCell()[0],
  9694. rowIndex = row.rowIndex,
  9695. nextRowIndex = rowIndex + cell.rowSpan,
  9696. nextRow = table.rows[nextRowIndex];
  9697. if (table.rows.length <= nextRowIndex) {
  9698. return;
  9699. }
  9700. var cellIndex = cell.cellIndex;
  9701. if (nextRow.cells.length <= cellIndex) {
  9702. return;
  9703. }
  9704. var nextCell = nextRow.cells[cellIndex];
  9705. if (cell.colSpan !== nextCell.colSpan) {
  9706. return;
  9707. }
  9708. cell.rowSpan += nextCell.rowSpan;
  9709. nextRow.deleteCell(cellIndex);
  9710. self.cmd.range.selectNodeContents(cell).collapse(true);
  9711. self.cmd.select();
  9712. self.addBookmark();
  9713. },
  9714. colmerge : function() {
  9715. var table = self.plugin.getSelectedTable()[0],
  9716. row = self.plugin.getSelectedRow()[0],
  9717. cell = self.plugin.getSelectedCell()[0],
  9718. rowIndex = row.rowIndex,
  9719. cellIndex = cell.cellIndex,
  9720. nextCellIndex = cellIndex + 1;
  9721. if (row.cells.length <= nextCellIndex) {
  9722. return;
  9723. }
  9724. var nextCell = row.cells[nextCellIndex];
  9725. if (cell.rowSpan !== nextCell.rowSpan) {
  9726. return;
  9727. }
  9728. cell.colSpan += nextCell.colSpan;
  9729. row.deleteCell(nextCellIndex);
  9730. self.cmd.range.selectNodeContents(cell).collapse(true);
  9731. self.cmd.select();
  9732. self.addBookmark();
  9733. },
  9734. rowsplit : function() {
  9735. var table = self.plugin.getSelectedTable()[0],
  9736. row = self.plugin.getSelectedRow()[0],
  9737. cell = self.plugin.getSelectedCell()[0],
  9738. rowIndex = row.rowIndex;
  9739. if (cell.rowSpan === 1) {
  9740. return;
  9741. }
  9742. var cellIndex = _getCellIndex(table, row, cell);
  9743. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9744. var newRow = table.rows[rowIndex + i],
  9745. newCell = newRow.insertCell(cellIndex);
  9746. if (cell.colSpan > 1) {
  9747. newCell.colSpan = cell.colSpan;
  9748. }
  9749. newCell.innerHTML = K.IE ? '' : '<br />';
  9750. cellIndex = _getCellIndex(table, newRow, newCell);
  9751. }
  9752. K(cell).removeAttr('rowSpan');
  9753. self.cmd.range.selectNodeContents(cell).collapse(true);
  9754. self.cmd.select();
  9755. self.addBookmark();
  9756. },
  9757. colsplit : function() {
  9758. var table = self.plugin.getSelectedTable()[0],
  9759. row = self.plugin.getSelectedRow()[0],
  9760. cell = self.plugin.getSelectedCell()[0],
  9761. cellIndex = cell.cellIndex;
  9762. if (cell.colSpan === 1) {
  9763. return;
  9764. }
  9765. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9766. var newCell = row.insertCell(cellIndex + i);
  9767. if (cell.rowSpan > 1) {
  9768. newCell.rowSpan = cell.rowSpan;
  9769. }
  9770. newCell.innerHTML = K.IE ? '' : '<br />';
  9771. }
  9772. K(cell).removeAttr('colSpan');
  9773. self.cmd.range.selectNodeContents(cell).collapse(true);
  9774. self.cmd.select();
  9775. self.addBookmark();
  9776. },
  9777. coldelete : function() {
  9778. var table = self.plugin.getSelectedTable()[0],
  9779. row = self.plugin.getSelectedRow()[0],
  9780. cell = self.plugin.getSelectedCell()[0],
  9781. index = cell.cellIndex;
  9782. for (var i = 0, len = table.rows.length; i < len; i++) {
  9783. var newRow = table.rows[i],
  9784. newCell = newRow.cells[index];
  9785. if (newCell.colSpan > 1) {
  9786. newCell.colSpan -= 1;
  9787. if (newCell.colSpan === 1) {
  9788. K(newCell).removeAttr('colSpan');
  9789. }
  9790. } else {
  9791. newRow.deleteCell(index);
  9792. }
  9793. if (newCell.rowSpan > 1) {
  9794. i += newCell.rowSpan - 1;
  9795. }
  9796. }
  9797. if (row.cells.length === 0) {
  9798. self.cmd.range.setStartBefore(table).collapse(true);
  9799. self.cmd.select();
  9800. K(table).remove();
  9801. } else {
  9802. self.cmd.selection(true);
  9803. }
  9804. self.addBookmark();
  9805. },
  9806. rowdelete : function() {
  9807. var table = self.plugin.getSelectedTable()[0],
  9808. row = self.plugin.getSelectedRow()[0],
  9809. cell = self.plugin.getSelectedCell()[0],
  9810. rowIndex = row.rowIndex;
  9811. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9812. table.deleteRow(rowIndex + i);
  9813. }
  9814. if (table.rows.length === 0) {
  9815. self.cmd.range.setStartBefore(table).collapse(true);
  9816. self.cmd.select();
  9817. K(table).remove();
  9818. } else {
  9819. self.cmd.selection(true);
  9820. }
  9821. self.addBookmark();
  9822. }
  9823. };
  9824. self.clickToolbar(name, self.plugin.table.prop);
  9825. });
  9826. /*******************************************************************************
  9827. * KindEditor - WYSIWYG HTML Editor for Internet
  9828. * Copyright (C) 2006-2011 kindsoft.net
  9829. *
  9830. * @author Roddy <luolonghao@gmail.com>
  9831. * @site http://www.kindsoft.net/
  9832. * @licence http://www.kindsoft.net/license.php
  9833. *******************************************************************************/
  9834. KindEditor.plugin('template', function(K) {
  9835. var self = this, name = 'template', lang = self.lang(name + '.'),
  9836. htmlPath = self.pluginsPath + name + '/html/';
  9837. function getFilePath(fileName) {
  9838. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9839. }
  9840. self.clickToolbar(name, function() {
  9841. var lang = self.lang(name + '.'),
  9842. arr = ['<div style="padding:10px 20px;">',
  9843. '<div class="ke-header">',
  9844. '<div class="ke-left">',
  9845. lang. selectTemplate + ' <select>'];
  9846. K.each(lang.fileList, function(key, val) {
  9847. arr.push('<option value="' + key + '">' + val + '</option>');
  9848. });
  9849. html = [arr.join(''),
  9850. '</select></div>',
  9851. '<div class="ke-right">',
  9852. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9853. '</div>',
  9854. '<div class="ke-clearfix"></div>',
  9855. '</div>',
  9856. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9857. '</div>'].join('');
  9858. var dialog = self.createDialog({
  9859. name : name,
  9860. width : 500,
  9861. title : self.lang(name),
  9862. body : html,
  9863. yesBtn : {
  9864. name : self.lang('yes'),
  9865. click : function(e) {
  9866. var doc = K.iframeDoc(iframe);
  9867. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9868. }
  9869. }
  9870. });
  9871. var selectBox = K('select', dialog.div),
  9872. checkbox = K('[name="replaceFlag"]', dialog.div),
  9873. iframe = K('iframe', dialog.div);
  9874. checkbox[0].checked = true;
  9875. iframe.attr('src', getFilePath(selectBox.val()));
  9876. selectBox.change(function() {
  9877. iframe.attr('src', getFilePath(this.value));
  9878. });
  9879. });
  9880. });
  9881. /*******************************************************************************
  9882. * KindEditor - WYSIWYG HTML Editor for Internet
  9883. * Copyright (C) 2006-2011 kindsoft.net
  9884. *
  9885. * @author Roddy <luolonghao@gmail.com>
  9886. * @site http://www.kindsoft.net/
  9887. * @licence http://www.kindsoft.net/license.php
  9888. *******************************************************************************/
  9889. KindEditor.plugin('wordpaste', function(K) {
  9890. var self = this, name = 'wordpaste';
  9891. self.clickToolbar(name, function() {
  9892. var lang = self.lang(name + '.'),
  9893. html = '<div style="padding:10px 20px;">' +
  9894. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9895. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9896. '</div>',
  9897. dialog = self.createDialog({
  9898. name : name,
  9899. width : 450,
  9900. title : self.lang(name),
  9901. body : html,
  9902. yesBtn : {
  9903. name : self.lang('yes'),
  9904. click : function(e) {
  9905. var str = doc.body.innerHTML;
  9906. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9907. self.insertHtml(str).hideDialog().focus();
  9908. }
  9909. }
  9910. }),
  9911. div = dialog.div,
  9912. iframe = K('iframe', div),
  9913. doc = K.iframeDoc(iframe);
  9914. if (!K.IE) {
  9915. doc.designMode = 'on';
  9916. }
  9917. doc.open();
  9918. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9919. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9920. if (!K.IE) {
  9921. doc.write('<br />');
  9922. }
  9923. doc.write('</body></html>');
  9924. doc.close();
  9925. if (K.IE) {
  9926. doc.body.contentEditable = 'true';
  9927. }
  9928. iframe[0].contentWindow.focus();
  9929. });
  9930. });
  9931. KindEditor.plugin('fixtoolbar', function (K) {
  9932. var self = this;
  9933. if (!self.fixToolBar) {
  9934. return;
  9935. }
  9936. function init() {
  9937. var toolbar = K('.ke-toolbar');
  9938. var originY = toolbar.pos().y;
  9939. K(window).bind('scroll', function () {
  9940. if (toolbar.css('position') == 'fixed') {
  9941. if(document.body.scrollTop - originY < 0){
  9942. toolbar.css('position', 'static');
  9943. toolbar.css('top', 'auto');
  9944. }
  9945. } else {
  9946. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9947. toolbar.css('position', 'fixed');
  9948. toolbar.css('top', 0);
  9949. }
  9950. }
  9951. });
  9952. }
  9953. if (self.isCreated) {
  9954. init();
  9955. } else {
  9956. self.afterCreate(init);
  9957. }
  9958. });
  9959. //自定义资源库
  9960. KindEditor.plugin('res', function(K) {
  9961. var self = this;
  9962. // 点击图标时执行
  9963. self.clickToolbar('res', function() {
  9964. var clickFn = function(url, title, id) {
  9965. var html = '<embed src="{url}" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" id="{id}"/>';
  9966. html = html.replace('{url}', url);
  9967. html = html.replace('{id}', id);
  9968. self.insertHtml(html);
  9969. };
  9970. editorShowUpload('', self.fileManagerJson, '视频库', clickFn, this);
  9971. });
  9972. });
  9973. function autoImg(self) {
  9974. var index = self.index;
  9975. var haspicContainer = document.getElementById("has_pic_" + index);
  9976. if (haspicContainer == null) {
  9977. haspicContainer = document.createElement("div");
  9978. haspicContainer.id = "has_pic_" + index;
  9979. haspicContainer.innerHTML = "<input type='text' id='piclist_"+index+"' value='' style='display:none;'/><div id='upload_"+index+"'><b>您有图片需要上传到服务器</b>&nbsp;&nbsp;<a href='javascript:uploadpic(\""+self.uploadJson+"\", \""+self.filePostName+"\", \""+index+"\");' >上传</a></div><div id='confirm_"+index+"'></div>";
  9980. $(".ke-toolbar").eq(index).after(haspicContainer);
  9981. }
  9982. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  9983. var piccount = 0;
  9984. var sstr = '';
  9985. $(img).each(function (i) {
  9986. var that = $(this);
  9987. var host = gethost(self.uploadJson);
  9988. if (self.uploadYunJson && self.uploadYunJson.host) {
  9989. var host = gethost(self.uploadYunJson.host);
  9990. }
  9991. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  9992. var n = gethost(that.attr("src"));
  9993. if (yhost) {
  9994. if (host != n && yhost != n) {
  9995. piccount++;
  9996. if (i == $(img).length - 1)
  9997. sstr += that.attr("src");
  9998. else
  9999. sstr += that.attr("src") + ",";
  10000. }
  10001. } else {
  10002. if (host != n) {
  10003. piccount++;
  10004. if (i == $(img).length - 1)
  10005. sstr += that.attr("src");
  10006. else
  10007. sstr += that.attr("src") + ",";
  10008. }
  10009. }
  10010. }
  10011. });
  10012. $("#piclist_" + index).val(encodeURIComponent(sstr));
  10013. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  10014. }
  10015. function closeupload(index) {
  10016. $("#has_pic_" + index).hide();
  10017. $("#upload_" + index).show();
  10018. }
  10019. function uploadpic(url, name, index) {
  10020. var piclist = encodeURI($("#piclist_" + index).val());
  10021. if (piclist.length == 0) return false;
  10022. $.ajax({
  10023. url: url.replace('kindeditor', 'copys') + '&json=1',
  10024. data: name + "=" + piclist,
  10025. type: "POST",
  10026. dataType: "json",
  10027. beforeSend: function () {
  10028. $("#upload_" + index).hide();
  10029. $("#confirm_" + index).text("正在上传中...");
  10030. },
  10031. success: function (msg) {
  10032. var url = msg.data;
  10033. if (url !== "") {
  10034. var str = new Array();
  10035. str = url.split(',');
  10036. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10037. $(img).each(function (i) {
  10038. var that = $(this);
  10039. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10040. that.attr("src", str[i]);
  10041. that.attr("data-ke-src", str[i]);
  10042. }
  10043. });
  10044. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  10045. }
  10046. else $("#confirm_" + index).text("上传失败!");
  10047. }
  10048. });
  10049. }
  10050. function gethost(url){
  10051. var reg = /^http(s)?:\/\/(.*?)\//;
  10052. return reg.exec(url)[2];
  10053. }