kindeditor-all-min.js 304 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348
  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. fontHeightTable : ['0px', '0.25px', '0.5px', '1px', '1.5px', '2px', '2.5px', '3px', '4px', '5px'],
  277. htmlTags : {
  278. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  279. span : [
  280. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  281. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  282. ],
  283. div : [
  284. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  285. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  286. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  287. ],
  288. table: [
  289. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  290. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  291. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  292. '.width', '.height', '.border-collapse'
  293. ],
  294. 'td,th': [
  295. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  296. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  297. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  298. ],
  299. a : ['id', 'class', 'href', 'target', 'name'],
  300. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  301. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  302. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  303. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  304. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  305. ],
  306. pre : ['id', 'class'],
  307. hr : ['id', 'class', '.page-break-after'],
  308. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  309. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  310. },
  311. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  312. };
  313. var _useCapture = false;
  314. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  315. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  316. var _CHANGE_KEY_MAP = {};
  317. _each(_INPUT_KEY_MAP, function(key, val) {
  318. _CHANGE_KEY_MAP[key] = val;
  319. });
  320. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  321. _CHANGE_KEY_MAP[key] = val;
  322. });
  323. function _bindEvent(el, type, fn) {
  324. if (el.addEventListener){
  325. el.addEventListener(type, fn, _useCapture);
  326. } else if (el.attachEvent){
  327. el.attachEvent('on' + type, fn);
  328. }
  329. }
  330. function _unbindEvent(el, type, fn) {
  331. if (el.removeEventListener){
  332. el.removeEventListener(type, fn, _useCapture);
  333. } else if (el.detachEvent){
  334. el.detachEvent('on' + type, fn);
  335. }
  336. }
  337. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  338. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  339. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  340. function KEvent(el, event) {
  341. this.init(el, event);
  342. }
  343. _extend(KEvent, {
  344. init : function(el, event) {
  345. var self = this, doc = el.ownerDocument || el.document || el;
  346. self.event = event;
  347. _each(_EVENT_PROPS, function(key, val) {
  348. self[val] = event[val];
  349. });
  350. if (!self.target) {
  351. self.target = self.srcElement || doc;
  352. }
  353. if (self.target.nodeType === 3) {
  354. self.target = self.target.parentNode;
  355. }
  356. if (!self.relatedTarget && self.fromElement) {
  357. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  358. }
  359. if (self.pageX == null && self.clientX != null) {
  360. var d = doc.documentElement, body = doc.body;
  361. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  362. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  363. }
  364. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  365. self.which = self.charCode || self.keyCode;
  366. }
  367. if (!self.metaKey && self.ctrlKey) {
  368. self.metaKey = self.ctrlKey;
  369. }
  370. if (!self.which && self.button !== undefined) {
  371. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  372. }
  373. switch (self.which) {
  374. case 186 :
  375. self.which = 59;
  376. break;
  377. case 187 :
  378. case 107 :
  379. case 43 :
  380. self.which = 61;
  381. break;
  382. case 189 :
  383. case 45 :
  384. self.which = 109;
  385. break;
  386. case 42 :
  387. self.which = 106;
  388. break;
  389. case 47 :
  390. self.which = 111;
  391. break;
  392. case 78 :
  393. self.which = 110;
  394. break;
  395. }
  396. if (self.which >= 96 && self.which <= 105) {
  397. self.which -= 48;
  398. }
  399. },
  400. preventDefault : function() {
  401. var ev = this.event;
  402. if (ev.preventDefault) {
  403. ev.preventDefault();
  404. } else {
  405. ev.returnValue = false;
  406. }
  407. },
  408. stopPropagation : function() {
  409. var ev = this.event;
  410. if (ev.stopPropagation) {
  411. ev.stopPropagation();
  412. } else {
  413. ev.cancelBubble = true;
  414. }
  415. },
  416. stop : function() {
  417. this.preventDefault();
  418. this.stopPropagation();
  419. }
  420. });
  421. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  422. function _getId(el) {
  423. return el[_eventExpendo] || null;
  424. }
  425. function _setId(el) {
  426. el[_eventExpendo] = ++_eventId;
  427. return _eventId;
  428. }
  429. function _removeId(el) {
  430. try {
  431. delete el[_eventExpendo];
  432. } catch(e) {
  433. if (el.removeAttribute) {
  434. el.removeAttribute(_eventExpendo);
  435. }
  436. }
  437. }
  438. function _bind(el, type, fn) {
  439. if (type.indexOf(',') >= 0) {
  440. _each(type.split(','), function() {
  441. _bind(el, this, fn);
  442. });
  443. return;
  444. }
  445. var id = _getId(el);
  446. if (!id) {
  447. id = _setId(el);
  448. }
  449. if (_eventData[id] === undefined) {
  450. _eventData[id] = {};
  451. }
  452. var events = _eventData[id][type];
  453. if (events && events.length > 0) {
  454. _unbindEvent(el, type, events[0]);
  455. } else {
  456. _eventData[id][type] = [];
  457. _eventData[id].el = el;
  458. }
  459. events = _eventData[id][type];
  460. if (events.length === 0) {
  461. events[0] = function(e) {
  462. var kevent = e ? new KEvent(el, e) : undefined;
  463. _each(events, function(i, event) {
  464. if (i > 0 && event) {
  465. event.call(el, kevent);
  466. }
  467. });
  468. };
  469. }
  470. if (_inArray(fn, events) < 0) {
  471. events.push(fn);
  472. }
  473. _bindEvent(el, type, events[0]);
  474. }
  475. function _unbind(el, type, fn) {
  476. if (type && type.indexOf(',') >= 0) {
  477. _each(type.split(','), function() {
  478. _unbind(el, this, fn);
  479. });
  480. return;
  481. }
  482. var id = _getId(el);
  483. if (!id) {
  484. return;
  485. }
  486. if (type === undefined) {
  487. if (id in _eventData) {
  488. _each(_eventData[id], function(key, events) {
  489. if (key != 'el' && events.length > 0) {
  490. _unbindEvent(el, key, events[0]);
  491. }
  492. });
  493. delete _eventData[id];
  494. _removeId(el);
  495. }
  496. return;
  497. }
  498. if (!_eventData[id]) {
  499. return;
  500. }
  501. var events = _eventData[id][type];
  502. if (events && events.length > 0) {
  503. if (fn === undefined) {
  504. _unbindEvent(el, type, events[0]);
  505. delete _eventData[id][type];
  506. } else {
  507. _each(events, function(i, event) {
  508. if (i > 0 && event === fn) {
  509. events.splice(i, 1);
  510. }
  511. });
  512. if (events.length == 1) {
  513. _unbindEvent(el, type, events[0]);
  514. delete _eventData[id][type];
  515. }
  516. }
  517. var count = 0;
  518. _each(_eventData[id], function() {
  519. count++;
  520. });
  521. if (count < 2) {
  522. delete _eventData[id];
  523. _removeId(el);
  524. }
  525. }
  526. }
  527. function _fire(el, type) {
  528. if (type.indexOf(',') >= 0) {
  529. _each(type.split(','), function() {
  530. _fire(el, this);
  531. });
  532. return;
  533. }
  534. var id = _getId(el);
  535. if (!id) {
  536. return;
  537. }
  538. var events = _eventData[id][type];
  539. if (_eventData[id] && events && events.length > 0) {
  540. events[0]();
  541. }
  542. }
  543. function _ctrl(el, key, fn) {
  544. var self = this;
  545. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  546. _bind(el, 'keydown', function(e) {
  547. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  548. fn.call(el);
  549. e.stop();
  550. }
  551. });
  552. }
  553. var _readyFinished = false;
  554. function _ready(fn) {
  555. if (_readyFinished) {
  556. fn(KindEditor);
  557. return;
  558. }
  559. var loaded = false;
  560. function readyFunc() {
  561. if (!loaded) {
  562. loaded = true;
  563. fn(KindEditor);
  564. _readyFinished = true;
  565. }
  566. }
  567. function ieReadyFunc() {
  568. if (!loaded) {
  569. try {
  570. document.documentElement.doScroll('left');
  571. } catch(e) {
  572. setTimeout(ieReadyFunc, 100);
  573. return;
  574. }
  575. readyFunc();
  576. }
  577. }
  578. function ieReadyStateFunc() {
  579. if (document.readyState === 'complete') {
  580. readyFunc();
  581. }
  582. }
  583. if (document.addEventListener) {
  584. _bind(document, 'DOMContentLoaded', readyFunc);
  585. } else if (document.attachEvent) {
  586. _bind(document, 'readystatechange', ieReadyStateFunc);
  587. var toplevel = false;
  588. try {
  589. toplevel = window.frameElement == null;
  590. } catch(e) {}
  591. if (document.documentElement.doScroll && toplevel) {
  592. ieReadyFunc();
  593. }
  594. }
  595. _bind(window, 'load', readyFunc);
  596. }
  597. if (window.attachEvent) {
  598. window.attachEvent('onunload', function() {
  599. _each(_eventData, function(key, events) {
  600. if (events.el) {
  601. _unbind(events.el);
  602. }
  603. });
  604. });
  605. }
  606. K.ctrl = _ctrl;
  607. K.ready = _ready;
  608. function _getCssList(css) {
  609. css = css.replace(/&quot;/g, '"');
  610. var list = {},
  611. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  612. match;
  613. while ((match = reg.exec(css))) {
  614. var key = _trim(match[1].toLowerCase()),
  615. val = _trim(_toHex(match[2]));
  616. list[key] = val;
  617. }
  618. return list;
  619. }
  620. function _getAttrList(tag) {
  621. var list = {},
  622. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  623. match;
  624. while ((match = reg.exec(tag))) {
  625. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  626. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  627. list[key] = val;
  628. }
  629. return list;
  630. }
  631. function _addClassToTag(tag, className) {
  632. if (/\s+class\s*=/.test(tag)) {
  633. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  634. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  635. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  636. } else {
  637. return $0;
  638. }
  639. });
  640. } else {
  641. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  642. }
  643. return tag;
  644. }
  645. function _formatCss(css) {
  646. var str = '';
  647. _each(_getCssList(css), function(key, val) {
  648. str += key + ':' + val + ';';
  649. });
  650. return str;
  651. }
  652. function _formatUrl(url, mode, host, pathname) {
  653. return url;
  654. mode = _undef(mode, '').toLowerCase();
  655. if (url.substr(0, 5) != 'data:') {
  656. url = url.replace(/([^:])\/\//g, '$1/');
  657. }
  658. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  659. return url;
  660. }
  661. host = host || location.protocol + '//' + location.host;
  662. if (pathname === undefined) {
  663. var m = location.pathname.match(/^(\/.*)\//);
  664. pathname = m ? m[1] : '';
  665. }
  666. var match;
  667. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  668. if (match[1] !== host) {
  669. return url;
  670. }
  671. } else if (/^\w+:/.test(url)) {
  672. return url;
  673. }
  674. function getRealPath(path) {
  675. var parts = path.split('/'), paths = [];
  676. for (var i = 0, len = parts.length; i < len; i++) {
  677. var part = parts[i];
  678. if (part == '..') {
  679. if (paths.length > 0) {
  680. paths.pop();
  681. }
  682. } else if (part !== '' && part != '.') {
  683. paths.push(part);
  684. }
  685. }
  686. return '/' + paths.join('/');
  687. }
  688. if (/^\//.test(url)) {
  689. url = host + getRealPath(url.substr(1));
  690. } else if (!/^\w+:\/\//.test(url)) {
  691. url = host + getRealPath(pathname + '/' + url);
  692. }
  693. function getRelativePath(path, depth) {
  694. if (url.substr(0, path.length) === path) {
  695. var arr = [];
  696. for (var i = 0; i < depth; i++) {
  697. arr.push('..');
  698. }
  699. var prefix = '.';
  700. if (arr.length > 0) {
  701. prefix += '/' + arr.join('/');
  702. }
  703. if (pathname == '/') {
  704. prefix += '/';
  705. }
  706. return prefix + url.substr(path.length);
  707. } else {
  708. if ((match = /^(.*)\//.exec(path))) {
  709. return getRelativePath(match[1], ++depth);
  710. }
  711. }
  712. }
  713. if (mode === 'relative') {
  714. url = getRelativePath(host + pathname, 0).substr(2);
  715. } else if (mode === 'absolute') {
  716. if (url.substr(0, host.length) === host) {
  717. url = url.substr(host.length);
  718. }
  719. }
  720. return url;
  721. }
  722. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  723. if (html == null) {
  724. html = '';
  725. }
  726. urlType = urlType || '';
  727. wellFormatted = _undef(wellFormatted, false);
  728. indentChar = _undef(indentChar, '\t');
  729. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  730. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  731. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  732. });
  733. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  734. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  735. html = html.replace(/\u200B/g, '');
  736. html = html.replace(/\u00A9/g, '&copy;');
  737. html = html.replace(/\u00AE/g, '&reg;');
  738. html = html.replace(/\u2003/g, '&emsp;');
  739. html = html.replace(/\u3000/g, '&emsp;');
  740. html = html.replace(/&quot;/g, '');
  741. html = html.replace(/, " helvetica=""(.*?)"="/g, '');
  742. html = html.replace(/<[^>]+/g, function($0) {
  743. return $0.replace(/\s+/g, ' ');
  744. });
  745. var htmlTagMap = {};
  746. if (htmlTags) {
  747. _each(htmlTags, function(key, val) {
  748. var arr = key.split(',');
  749. for (var i = 0, len = arr.length; i < len; i++) {
  750. htmlTagMap[arr[i]] = _toMap(val);
  751. }
  752. });
  753. if (!htmlTagMap.script) {
  754. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  755. }
  756. if (!htmlTagMap.style) {
  757. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  758. }
  759. }
  760. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  761. var tagStack = [];
  762. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  763. var full = $0,
  764. startNewline = $1 || '',
  765. startSlash = $2 || '',
  766. tagName = $3.toLowerCase(),
  767. attr = $4 || '',
  768. endSlash = $5 ? ' ' + $5 : '',
  769. endNewline = $6 || '';
  770. if (htmlTags && !htmlTagMap[tagName]) {
  771. return '';
  772. }
  773. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  774. endSlash = ' /';
  775. }
  776. if (_INLINE_TAG_MAP[tagName]) {
  777. if (startNewline) {
  778. startNewline = ' ';
  779. }
  780. if (endNewline) {
  781. endNewline = ' ';
  782. }
  783. }
  784. if (_PRE_TAG_MAP[tagName]) {
  785. if (startSlash) {
  786. endNewline = '\n';
  787. } else {
  788. startNewline = '\n';
  789. }
  790. }
  791. if (wellFormatted && tagName == 'br') {
  792. endNewline = '\n';
  793. }
  794. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  795. if (wellFormatted) {
  796. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  797. tagStack.pop();
  798. } else {
  799. tagStack.push(tagName);
  800. }
  801. startNewline = '\n';
  802. endNewline = '\n';
  803. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  804. startNewline += indentChar;
  805. if (!startSlash) {
  806. endNewline += indentChar;
  807. }
  808. }
  809. if (endSlash) {
  810. tagStack.pop();
  811. } else if (!startSlash) {
  812. endNewline += indentChar;
  813. }
  814. } else {
  815. startNewline = endNewline = '';
  816. }
  817. }
  818. if (attr !== '') {
  819. var attrMap = _getAttrList(full);
  820. if (tagName === 'font') {
  821. var fontStyleMap = {}, fontStyle = '';
  822. _each(attrMap, function(key, val) {
  823. if (key === 'color') {
  824. fontStyleMap.color = val;
  825. delete attrMap[key];
  826. }
  827. if (key === 'size') {
  828. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  829. delete attrMap[key];
  830. }
  831. if (key === 'face') {
  832. fontStyleMap['font-family'] = val;
  833. delete attrMap[key];
  834. }
  835. if (key === 'style') {
  836. fontStyle = val;
  837. }
  838. });
  839. if (fontStyle && !/;$/.test(fontStyle)) {
  840. fontStyle += ';';
  841. }
  842. _each(fontStyleMap, function(key, val) {
  843. if (val === '') {
  844. return;
  845. }
  846. if (/\s/.test(val)) {
  847. val = "'" + val + "'";
  848. }
  849. fontStyle += key + ':' + val + ';';
  850. });
  851. attrMap.style = fontStyle;
  852. }
  853. _each(attrMap, function(key, val) {
  854. if (_FILL_ATTR_MAP[key]) {
  855. attrMap[key] = key;
  856. }
  857. if (_inArray(key, ['src', 'href']) >= 0) {
  858. attrMap[key] = _formatUrl(val, urlType);
  859. }
  860. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  861. tagName === 'body' && key === 'contenteditable' ||
  862. /^kindeditor_\d+$/.test(key)) {
  863. delete attrMap[key];
  864. }
  865. if (key === 'style' && val !== '') {
  866. var styleMap = _getCssList(val);
  867. _each(styleMap, function(k, v) {
  868. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  869. delete styleMap[k];
  870. }
  871. });
  872. var style = '';
  873. _each(styleMap, function(k, v) {
  874. style += k + ':' + v + ';';
  875. });
  876. attrMap.style = style;
  877. }
  878. });
  879. attr = '';
  880. _each(attrMap, function(key, val) {
  881. if (key === 'style' && val === '') {
  882. return;
  883. }
  884. val = val.replace(/"/g, '&quot;');
  885. attr += ' ' + key + '="' + val + '"';
  886. });
  887. }
  888. if (tagName === 'font') {
  889. tagName = 'span';
  890. }
  891. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  892. });
  893. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  894. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  895. });
  896. html = html.replace(/\n\s*\n/g, '\n');
  897. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  898. return _trim(html);
  899. }
  900. function _clearMsWord(html, htmlTags) {
  901. html = html.replace(/<meta[\s\S]*?>/ig, '')
  902. .replace(/<![\s\S]*?>/ig, '')
  903. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  904. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  905. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  906. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  907. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  908. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  909. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  910. });
  911. return _formatHtml(html, htmlTags);
  912. }
  913. function _mediaType(src) {
  914. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  915. return 'audio/x-pn-realaudio-plugin';
  916. }
  917. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  918. return 'application/x-shockwave-flash';
  919. }
  920. return 'video/x-ms-asf-plugin';
  921. }
  922. function _mediaClass(type) {
  923. if (/realaudio/i.test(type)) {
  924. return 'ke-rm';
  925. }
  926. if (/flash/i.test(type)) {
  927. return 'ke-flash';
  928. }
  929. return 'ke-media';
  930. }
  931. function _mediaAttrs(srcTag) {
  932. return _getAttrList(unescape(srcTag));
  933. }
  934. function _mediaEmbed(attrs) {
  935. var html = '<embed ';
  936. _each(attrs, function(key, val) {
  937. html += key + '="' + val + '" ';
  938. });
  939. html += '/>';
  940. return html;
  941. }
  942. function _mediaImg(blankPath, attrs) {
  943. var width = attrs.width,
  944. height = attrs.height,
  945. type = attrs.type || _mediaType(attrs.src),
  946. srcTag = _mediaEmbed(attrs),
  947. style = '';
  948. if (/\D/.test(width)) {
  949. style += 'width:' + width + ';';
  950. } else if (width > 0) {
  951. style += 'width:' + width + 'px;';
  952. }
  953. if (/\D/.test(height)) {
  954. style += 'height:' + height + ';';
  955. } else if (height > 0) {
  956. style += 'height:' + height + 'px;';
  957. }
  958. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  959. if (style !== '') {
  960. html += 'style="' + style + '" ';
  961. }
  962. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  963. return html;
  964. }
  965. function _tmpl(str, data) {
  966. var fn = new Function("obj",
  967. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  968. "with(obj){p.push('" +
  969. str.replace(/[\r\t\n]/g, " ")
  970. .split("<%").join("\t")
  971. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  972. .replace(/\t=(.*?)%>/g, "',$1,'")
  973. .split("\t").join("');")
  974. .split("%>").join("p.push('")
  975. .split("\r").join("\\'") + "');}return p.join('');");
  976. return data ? fn(data) : fn;
  977. }
  978. K.formatUrl = _formatUrl;
  979. K.formatHtml = _formatHtml;
  980. K.getCssList = _getCssList;
  981. K.getAttrList = _getAttrList;
  982. K.mediaType = _mediaType;
  983. K.mediaAttrs = _mediaAttrs;
  984. K.mediaEmbed = _mediaEmbed;
  985. K.mediaImg = _mediaImg;
  986. K.clearMsWord = _clearMsWord;
  987. K.tmpl = _tmpl;
  988. function _contains(nodeA, nodeB) {
  989. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  990. return true;
  991. }
  992. while ((nodeB = nodeB.parentNode)) {
  993. if (nodeB == nodeA) {
  994. return true;
  995. }
  996. }
  997. return false;
  998. }
  999. var _getSetAttrDiv = document.createElement('div');
  1000. _getSetAttrDiv.setAttribute('className', 't');
  1001. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1002. function _getAttr(el, key) {
  1003. key = key.toLowerCase();
  1004. var val = null;
  1005. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1006. var div = el.ownerDocument.createElement('div');
  1007. div.appendChild(el.cloneNode(false));
  1008. var list = _getAttrList(_unescape(div.innerHTML));
  1009. if (key in list) {
  1010. val = list[key];
  1011. }
  1012. } else {
  1013. try {
  1014. val = el.getAttribute(key, 2);
  1015. } catch(e) {
  1016. val = el.getAttribute(key, 1);
  1017. }
  1018. }
  1019. if (key === 'style' && val !== null) {
  1020. val = _formatCss(val);
  1021. }
  1022. return val;
  1023. }
  1024. function _queryAll(expr, root) {
  1025. var exprList = expr.split(',');
  1026. if (exprList.length > 1) {
  1027. var mergedResults = [];
  1028. _each(exprList, function() {
  1029. _each(_queryAll(this, root), function() {
  1030. if (_inArray(this, mergedResults) < 0) {
  1031. mergedResults.push(this);
  1032. }
  1033. });
  1034. });
  1035. return mergedResults;
  1036. }
  1037. root = root || document;
  1038. function escape(str) {
  1039. if (typeof str != 'string') {
  1040. return str;
  1041. }
  1042. return str.replace(/([^\w\-])/g, '\\$1');
  1043. }
  1044. function stripslashes(str) {
  1045. return str.replace(/\\/g, '');
  1046. }
  1047. function cmpTag(tagA, tagB) {
  1048. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1049. }
  1050. function byId(id, tag, root) {
  1051. var arr = [],
  1052. doc = root.ownerDocument || root,
  1053. el = doc.getElementById(stripslashes(id));
  1054. if (el) {
  1055. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1056. arr.push(el);
  1057. }
  1058. }
  1059. return arr;
  1060. }
  1061. function byClass(className, tag, root) {
  1062. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1063. if (root.getElementsByClassName) {
  1064. els = root.getElementsByClassName(stripslashes(className));
  1065. for (i = 0, len = els.length; i < len; i++) {
  1066. el = els[i];
  1067. if (cmpTag(tag, el.nodeName)) {
  1068. arr.push(el);
  1069. }
  1070. }
  1071. } else if (doc.querySelectorAll) {
  1072. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1073. for (i = 0, len = els.length; i < len; i++) {
  1074. el = els[i];
  1075. if (_contains(root, el)) {
  1076. arr.push(el);
  1077. }
  1078. }
  1079. } else {
  1080. els = root.getElementsByTagName(tag);
  1081. className = ' ' + className + ' ';
  1082. for (i = 0, len = els.length; i < len; i++) {
  1083. el = els[i];
  1084. if (el.nodeType == 1) {
  1085. var cls = el.className;
  1086. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1087. arr.push(el);
  1088. }
  1089. }
  1090. }
  1091. }
  1092. return arr;
  1093. }
  1094. function byName(name, tag, root) {
  1095. var arr = [], doc = root.ownerDocument || root,
  1096. els = doc.getElementsByName(stripslashes(name)), el;
  1097. for (var i = 0, len = els.length; i < len; i++) {
  1098. el = els[i];
  1099. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1100. if (el.getAttribute('name') !== null) {
  1101. arr.push(el);
  1102. }
  1103. }
  1104. }
  1105. return arr;
  1106. }
  1107. function byAttr(key, val, tag, root) {
  1108. var arr = [], els = root.getElementsByTagName(tag), el;
  1109. for (var i = 0, len = els.length; i < len; i++) {
  1110. el = els[i];
  1111. if (el.nodeType == 1) {
  1112. if (val === null) {
  1113. if (_getAttr(el, key) !== null) {
  1114. arr.push(el);
  1115. }
  1116. } else {
  1117. if (val === escape(_getAttr(el, key))) {
  1118. arr.push(el);
  1119. }
  1120. }
  1121. }
  1122. }
  1123. return arr;
  1124. }
  1125. function select(expr, root) {
  1126. var arr = [], matches;
  1127. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1128. var tag = matches ? matches[1] : '*';
  1129. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1130. arr = byId(matches[1], tag, root);
  1131. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1132. arr = byClass(matches[1], tag, root);
  1133. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1134. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1135. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1136. var key = matches[1].toLowerCase(), val = matches[2];
  1137. if (key === 'id') {
  1138. arr = byId(val, tag, root);
  1139. } else if (key === 'class') {
  1140. arr = byClass(val, tag, root);
  1141. } else if (key === 'name') {
  1142. arr = byName(val, tag, root);
  1143. } else {
  1144. arr = byAttr(key, val, tag, root);
  1145. }
  1146. } else {
  1147. var els = root.getElementsByTagName(tag), el;
  1148. for (var i = 0, len = els.length; i < len; i++) {
  1149. el = els[i];
  1150. if (el.nodeType == 1) {
  1151. arr.push(el);
  1152. }
  1153. }
  1154. }
  1155. return arr;
  1156. }
  1157. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1158. while ((arr = re.exec(expr))) {
  1159. if (arr[1] !== ' ') {
  1160. parts.push(arr[1]);
  1161. }
  1162. }
  1163. var results = [];
  1164. if (parts.length == 1) {
  1165. return select(parts[0], root);
  1166. }
  1167. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1168. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1169. part = parts[i];
  1170. if (part === '>') {
  1171. isChild = true;
  1172. continue;
  1173. }
  1174. if (i > 0) {
  1175. els = [];
  1176. for (j = 0, len = results.length; j < len; j++) {
  1177. val = results[j];
  1178. subResults = select(part, val);
  1179. for (k = 0, l = subResults.length; k < l; k++) {
  1180. v = subResults[k];
  1181. if (isChild) {
  1182. if (val === v.parentNode) {
  1183. els.push(v);
  1184. }
  1185. } else {
  1186. els.push(v);
  1187. }
  1188. }
  1189. }
  1190. results = els;
  1191. } else {
  1192. results = select(part, root);
  1193. }
  1194. if (results.length === 0) {
  1195. return [];
  1196. }
  1197. }
  1198. return results;
  1199. }
  1200. function _query(expr, root) {
  1201. var arr = _queryAll(expr, root);
  1202. return arr.length > 0 ? arr[0] : null;
  1203. }
  1204. K.query = _query;
  1205. K.queryAll = _queryAll;
  1206. function _get(val) {
  1207. return K(val)[0];
  1208. }
  1209. function _getDoc(node) {
  1210. if (!node) {
  1211. return document;
  1212. }
  1213. return node.ownerDocument || node.document || node;
  1214. }
  1215. function _getWin(node) {
  1216. if (!node) {
  1217. return window;
  1218. }
  1219. var doc = _getDoc(node);
  1220. return doc.parentWindow || doc.defaultView;
  1221. }
  1222. function _setHtml(el, html) {
  1223. if (el.nodeType != 1) {
  1224. return;
  1225. }
  1226. var doc = _getDoc(el);
  1227. try {
  1228. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1229. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1230. temp.parentNode.removeChild(temp);
  1231. } catch(e) {
  1232. K(el).empty();
  1233. K('@' + html, doc).each(function() {
  1234. el.appendChild(this);
  1235. });
  1236. }
  1237. }
  1238. function _hasClass(el, cls) {
  1239. return _inString(cls, el.className, ' ');
  1240. }
  1241. function _setAttr(el, key, val) {
  1242. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1243. key = 'className';
  1244. }
  1245. el.setAttribute(key, '' + val);
  1246. }
  1247. function _removeAttr(el, key) {
  1248. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1249. key = 'className';
  1250. }
  1251. _setAttr(el, key, '');
  1252. el.removeAttribute(key);
  1253. }
  1254. function _getNodeName(node) {
  1255. if (!node || !node.nodeName) {
  1256. return '';
  1257. }
  1258. return node.nodeName.toLowerCase();
  1259. }
  1260. function _computedCss(el, key) {
  1261. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1262. if (win.getComputedStyle) {
  1263. var style = win.getComputedStyle(el, null);
  1264. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1265. } else if (el.currentStyle) {
  1266. val = el.currentStyle[camelKey] || el.style[camelKey];
  1267. }
  1268. return val;
  1269. }
  1270. function _hasVal(node) {
  1271. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1272. }
  1273. function _docElement(doc) {
  1274. doc = doc || document;
  1275. return _QUIRKS ? doc.body : doc.documentElement;
  1276. }
  1277. function _docHeight(doc) {
  1278. var el = _docElement(doc);
  1279. return Math.max(el.scrollHeight, el.clientHeight);
  1280. }
  1281. function _docWidth(doc) {
  1282. var el = _docElement(doc);
  1283. return Math.max(el.scrollWidth, el.clientWidth);
  1284. }
  1285. function _getScrollPos(doc) {
  1286. doc = doc || document;
  1287. var x, y;
  1288. if (_IE || _NEWIE || _OPERA) {
  1289. x = _docElement(doc).scrollLeft;
  1290. y = _docElement(doc).scrollTop;
  1291. } else {
  1292. x = _getWin(doc).scrollX;
  1293. y = _getWin(doc).scrollY;
  1294. }
  1295. return {x : x, y : y};
  1296. }
  1297. function KNode(node) {
  1298. this.init(node);
  1299. }
  1300. _extend(KNode, {
  1301. init : function(node) {
  1302. var self = this;
  1303. node = _isArray(node) ? node : [node];
  1304. var length = 0;
  1305. for (var i = 0, len = node.length; i < len; i++) {
  1306. if (node[i]) {
  1307. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1308. length++;
  1309. }
  1310. }
  1311. self.length = length;
  1312. self.doc = _getDoc(self[0]);
  1313. self.name = _getNodeName(self[0]);
  1314. self.type = self.length > 0 ? self[0].nodeType : null;
  1315. self.win = _getWin(self[0]);
  1316. },
  1317. each : function(fn) {
  1318. var self = this;
  1319. for (var i = 0; i < self.length; i++) {
  1320. if (fn.call(self[i], i, self[i]) === false) {
  1321. return self;
  1322. }
  1323. }
  1324. return self;
  1325. },
  1326. bind : function(type, fn) {
  1327. this.each(function() {
  1328. _bind(this, type, fn);
  1329. });
  1330. return this;
  1331. },
  1332. unbind : function(type, fn) {
  1333. this.each(function() {
  1334. _unbind(this, type, fn);
  1335. });
  1336. return this;
  1337. },
  1338. fire : function(type) {
  1339. if (this.length < 1) {
  1340. return this;
  1341. }
  1342. _fire(this[0], type);
  1343. return this;
  1344. },
  1345. hasAttr : function(key) {
  1346. if (this.length < 1) {
  1347. return false;
  1348. }
  1349. return !!_getAttr(this[0], key);
  1350. },
  1351. attr : function(key, val) {
  1352. var self = this;
  1353. if (key === undefined) {
  1354. return _getAttrList(self.outer());
  1355. }
  1356. if (typeof key === 'object') {
  1357. _each(key, function(k, v) {
  1358. self.attr(k, v);
  1359. });
  1360. return self;
  1361. }
  1362. if (val === undefined) {
  1363. val = self.length < 1 ? null : _getAttr(self[0], key);
  1364. return val === null ? '' : val;
  1365. }
  1366. self.each(function() {
  1367. _setAttr(this, key, val);
  1368. });
  1369. return self;
  1370. },
  1371. removeAttr : function(key) {
  1372. this.each(function() {
  1373. _removeAttr(this, key);
  1374. });
  1375. return this;
  1376. },
  1377. get : function(i) {
  1378. if (this.length < 1) {
  1379. return null;
  1380. }
  1381. return this[i || 0];
  1382. },
  1383. eq : function(i) {
  1384. if (this.length < 1) {
  1385. return null;
  1386. }
  1387. return this[i] ? new KNode(this[i]) : null;
  1388. },
  1389. hasClass : function(cls) {
  1390. if (this.length < 1) {
  1391. return false;
  1392. }
  1393. return _hasClass(this[0], cls);
  1394. },
  1395. addClass : function(cls) {
  1396. this.each(function() {
  1397. if (!_hasClass(this, cls)) {
  1398. this.className = _trim(this.className + ' ' + cls);
  1399. }
  1400. });
  1401. return this;
  1402. },
  1403. removeClass : function(cls) {
  1404. this.each(function() {
  1405. if (_hasClass(this, cls)) {
  1406. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1407. }
  1408. });
  1409. return this;
  1410. },
  1411. html : function(val) {
  1412. var self = this;
  1413. if (val === undefined) {
  1414. if (self.length < 1 || self.type != 1) {
  1415. return '';
  1416. }
  1417. return _formatHtml(self[0].innerHTML);
  1418. }
  1419. self.each(function() {
  1420. _setHtml(this, val);
  1421. });
  1422. return self;
  1423. },
  1424. text : function() {
  1425. var self = this;
  1426. if (self.length < 1) {
  1427. return '';
  1428. }
  1429. return _IE ? self[0].innerText : self[0].textContent;
  1430. },
  1431. hasVal : function() {
  1432. if (this.length < 1) {
  1433. return false;
  1434. }
  1435. return _hasVal(this[0]);
  1436. },
  1437. val : function(val) {
  1438. var self = this;
  1439. if (val === undefined) {
  1440. if (self.length < 1) {
  1441. return '';
  1442. }
  1443. return self.hasVal() ? self[0].value : self.attr('value');
  1444. } else {
  1445. self.each(function() {
  1446. if (_hasVal(this)) {
  1447. this.value = val;
  1448. } else {
  1449. _setAttr(this, 'value' , val);
  1450. }
  1451. });
  1452. return self;
  1453. }
  1454. },
  1455. css : function(key, val) {
  1456. var self = this;
  1457. if (key === undefined) {
  1458. return _getCssList(self.attr('style'));
  1459. }
  1460. if (typeof key === 'object') {
  1461. _each(key, function(k, v) {
  1462. self.css(k, v);
  1463. });
  1464. return self;
  1465. }
  1466. if (val === undefined) {
  1467. if (self.length < 1) {
  1468. return '';
  1469. }
  1470. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1471. }
  1472. self.each(function() {
  1473. this.style[_toCamel(key)] = val;
  1474. });
  1475. return self;
  1476. },
  1477. width : function(val) {
  1478. var self = this;
  1479. if (val === undefined) {
  1480. if (self.length < 1) {
  1481. return 0;
  1482. }
  1483. return self[0].offsetWidth;
  1484. }
  1485. return self.css('width', _addUnit(val));
  1486. },
  1487. height : function(val) {
  1488. var self = this;
  1489. if (val === undefined) {
  1490. if (self.length < 1) {
  1491. return 0;
  1492. }
  1493. return self[0].offsetHeight;
  1494. }
  1495. return self.css('height', _addUnit(val));
  1496. },
  1497. opacity : function(val) {
  1498. this.each(function() {
  1499. if (this.style.opacity === undefined) {
  1500. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1501. } else {
  1502. this.style.opacity = val == 1 ? '' : val;
  1503. }
  1504. });
  1505. return this;
  1506. },
  1507. data : function(key, val) {
  1508. var self = this;
  1509. key = 'kindeditor_data_' + key;
  1510. if (val === undefined) {
  1511. if (self.length < 1) {
  1512. return null;
  1513. }
  1514. return self[0][key];
  1515. }
  1516. this.each(function() {
  1517. this[key] = val;
  1518. });
  1519. return self;
  1520. },
  1521. pos : function() {
  1522. var self = this, node = self[0], x = 0, y = 0;
  1523. if (node) {
  1524. if (node.getBoundingClientRect) {
  1525. var box = node.getBoundingClientRect(),
  1526. pos = _getScrollPos(self.doc);
  1527. x = box.left + pos.x;
  1528. y = box.top + pos.y;
  1529. } else {
  1530. while (node) {
  1531. x += node.offsetLeft;
  1532. y += node.offsetTop;
  1533. node = node.offsetParent;
  1534. }
  1535. }
  1536. }
  1537. return {x : _round(x), y : _round(y)};
  1538. },
  1539. clone : function(bool) {
  1540. if (this.length < 1) {
  1541. return new KNode([]);
  1542. }
  1543. return new KNode(this[0].cloneNode(bool));
  1544. },
  1545. append : function(expr) {
  1546. this.each(function() {
  1547. if (this.appendChild) {
  1548. this.appendChild(_get(expr));
  1549. }
  1550. });
  1551. return this;
  1552. },
  1553. appendTo : function(expr) {
  1554. this.each(function() {
  1555. _get(expr).appendChild(this);
  1556. });
  1557. return this;
  1558. },
  1559. before : function(expr) {
  1560. this.each(function() {
  1561. this.parentNode.insertBefore(_get(expr), this);
  1562. });
  1563. return this;
  1564. },
  1565. after : function(expr) {
  1566. this.each(function() {
  1567. if (this.nextSibling) {
  1568. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1569. } else {
  1570. this.parentNode.appendChild(_get(expr));
  1571. }
  1572. });
  1573. return this;
  1574. },
  1575. replaceWith : function(expr) {
  1576. var nodes = [];
  1577. this.each(function(i, node) {
  1578. _unbind(node);
  1579. var newNode = _get(expr);
  1580. node.parentNode.replaceChild(newNode, node);
  1581. nodes.push(newNode);
  1582. });
  1583. return K(nodes);
  1584. },
  1585. empty : function() {
  1586. var self = this;
  1587. self.each(function(i, node) {
  1588. var child = node.firstChild;
  1589. while (child) {
  1590. if (!node.parentNode) {
  1591. return;
  1592. }
  1593. var next = child.nextSibling;
  1594. child.parentNode.removeChild(child);
  1595. child = next;
  1596. }
  1597. });
  1598. return self;
  1599. },
  1600. remove : function(keepChilds) {
  1601. var self = this;
  1602. self.each(function(i, node) {
  1603. if (!node.parentNode) {
  1604. return;
  1605. }
  1606. _unbind(node);
  1607. if (keepChilds) {
  1608. var child = node.firstChild;
  1609. while (child) {
  1610. var next = child.nextSibling;
  1611. node.parentNode.insertBefore(child, node);
  1612. child = next;
  1613. }
  1614. }
  1615. node.parentNode.removeChild(node);
  1616. delete self[i];
  1617. });
  1618. self.length = 0;
  1619. return self;
  1620. },
  1621. show : function(val) {
  1622. var self = this;
  1623. if (val === undefined) {
  1624. val = self._originDisplay || '';
  1625. }
  1626. if (self.css('display') != 'none') {
  1627. return self;
  1628. }
  1629. return self.css('display', val);
  1630. },
  1631. hide : function() {
  1632. var self = this;
  1633. if (self.length < 1) {
  1634. return self;
  1635. }
  1636. self._originDisplay = self[0].style.display;
  1637. return self.css('display', 'none');
  1638. },
  1639. outer : function() {
  1640. var self = this;
  1641. if (self.length < 1) {
  1642. return '';
  1643. }
  1644. var div = self.doc.createElement('div'), html;
  1645. div.appendChild(self[0].cloneNode(true));
  1646. html = _formatHtml(div.innerHTML);
  1647. div = null;
  1648. return html;
  1649. },
  1650. isSingle : function() {
  1651. return !!_SINGLE_TAG_MAP[this.name];
  1652. },
  1653. isInline : function() {
  1654. return !!_INLINE_TAG_MAP[this.name];
  1655. },
  1656. isBlock : function() {
  1657. return !!_BLOCK_TAG_MAP[this.name];
  1658. },
  1659. isStyle : function() {
  1660. return !!_STYLE_TAG_MAP[this.name];
  1661. },
  1662. isControl : function() {
  1663. return !!_CONTROL_TAG_MAP[this.name];
  1664. },
  1665. contains : function(otherNode) {
  1666. if (this.length < 1) {
  1667. return false;
  1668. }
  1669. return _contains(this[0], _get(otherNode));
  1670. },
  1671. parent : function() {
  1672. if (this.length < 1) {
  1673. return null;
  1674. }
  1675. var node = this[0].parentNode;
  1676. return node ? new KNode(node) : null;
  1677. },
  1678. children : function() {
  1679. if (this.length < 1) {
  1680. return new KNode([]);
  1681. }
  1682. var list = [], child = this[0].firstChild;
  1683. while (child) {
  1684. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1685. list.push(child);
  1686. }
  1687. child = child.nextSibling;
  1688. }
  1689. return new KNode(list);
  1690. },
  1691. first : function() {
  1692. var list = this.children();
  1693. return list.length > 0 ? list.eq(0) : null;
  1694. },
  1695. last : function() {
  1696. var list = this.children();
  1697. return list.length > 0 ? list.eq(list.length - 1) : null;
  1698. },
  1699. index : function() {
  1700. if (this.length < 1) {
  1701. return -1;
  1702. }
  1703. var i = -1, sibling = this[0];
  1704. while (sibling) {
  1705. i++;
  1706. sibling = sibling.previousSibling;
  1707. }
  1708. return i;
  1709. },
  1710. prev : function() {
  1711. if (this.length < 1) {
  1712. return null;
  1713. }
  1714. var node = this[0].previousSibling;
  1715. return node ? new KNode(node) : null;
  1716. },
  1717. next : function() {
  1718. if (this.length < 1) {
  1719. return null;
  1720. }
  1721. var node = this[0].nextSibling;
  1722. return node ? new KNode(node) : null;
  1723. },
  1724. scan : function(fn, order) {
  1725. if (this.length < 1) {
  1726. return;
  1727. }
  1728. order = (order === undefined) ? true : order;
  1729. function walk(node) {
  1730. var n = order ? node.firstChild : node.lastChild;
  1731. while (n) {
  1732. var next = order ? n.nextSibling : n.previousSibling;
  1733. if (fn(n) === false) {
  1734. return false;
  1735. }
  1736. if (walk(n) === false) {
  1737. return false;
  1738. }
  1739. n = next;
  1740. }
  1741. }
  1742. walk(this[0]);
  1743. return this;
  1744. }
  1745. });
  1746. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1747. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1748. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1749. KNode.prototype[type] = function(fn) {
  1750. return fn ? this.bind(type, fn) : this.fire(type);
  1751. };
  1752. });
  1753. var _K = K;
  1754. K = function(expr, root) {
  1755. if (expr === undefined || expr === null) {
  1756. return;
  1757. }
  1758. function newNode(node) {
  1759. if (!node[0]) {
  1760. node = [];
  1761. }
  1762. return new KNode(node);
  1763. }
  1764. if (typeof expr === 'string') {
  1765. if (root) {
  1766. root = _get(root);
  1767. }
  1768. var length = expr.length;
  1769. if (expr.charAt(0) === '@') {
  1770. expr = expr.substr(1);
  1771. }
  1772. if (expr.length !== length || /<.+>/.test(expr)) {
  1773. var doc = root ? root.ownerDocument || root : document,
  1774. div = doc.createElement('div'), list = [];
  1775. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1776. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1777. var child = div.childNodes[i];
  1778. if (child.id == '__kindeditor_temp_tag__') {
  1779. continue;
  1780. }
  1781. list.push(child);
  1782. }
  1783. return newNode(list);
  1784. }
  1785. return newNode(_queryAll(expr, root));
  1786. }
  1787. if (expr && expr.constructor === KNode) {
  1788. return expr;
  1789. }
  1790. if (expr.toArray) {
  1791. expr = expr.toArray();
  1792. }
  1793. if (_isArray(expr)) {
  1794. return newNode(expr);
  1795. }
  1796. return newNode(_toArray(arguments));
  1797. };
  1798. _each(_K, function(key, val) {
  1799. K[key] = val;
  1800. });
  1801. K.NodeClass = KNode;
  1802. window.KindEditor = K;
  1803. var _START_TO_START = 0,
  1804. _START_TO_END = 1,
  1805. _END_TO_END = 2,
  1806. _END_TO_START = 3,
  1807. _BOOKMARK_ID = 0;
  1808. function _updateCollapsed(range) {
  1809. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1810. return range;
  1811. }
  1812. function _copyAndDelete(range, isCopy, isDelete) {
  1813. var doc = range.doc, nodeList = [];
  1814. function splitTextNode(node, startOffset, endOffset) {
  1815. var length = node.nodeValue.length, centerNode;
  1816. if (isCopy) {
  1817. var cloneNode = node.cloneNode(true);
  1818. if (startOffset > 0) {
  1819. centerNode = cloneNode.splitText(startOffset);
  1820. } else {
  1821. centerNode = cloneNode;
  1822. }
  1823. if (endOffset < length) {
  1824. centerNode.splitText(endOffset - startOffset);
  1825. }
  1826. }
  1827. if (isDelete) {
  1828. var center = node;
  1829. if (startOffset > 0) {
  1830. center = node.splitText(startOffset);
  1831. range.setStart(node, startOffset);
  1832. }
  1833. if (endOffset < length) {
  1834. var right = center.splitText(endOffset - startOffset);
  1835. range.setEnd(right, 0);
  1836. }
  1837. nodeList.push(center);
  1838. }
  1839. return centerNode;
  1840. }
  1841. function removeNodes() {
  1842. if (isDelete) {
  1843. range.up().collapse(true);
  1844. }
  1845. for (var i = 0, len = nodeList.length; i < len; i++) {
  1846. var node = nodeList[i];
  1847. if (node.parentNode) {
  1848. node.parentNode.removeChild(node);
  1849. }
  1850. }
  1851. }
  1852. var copyRange = range.cloneRange().down();
  1853. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1854. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1855. if (ancestor.nodeType == 3) {
  1856. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1857. if (isCopy) {
  1858. frag.appendChild(textNode);
  1859. }
  1860. removeNodes();
  1861. return isCopy ? frag : range;
  1862. }
  1863. function extractNodes(parent, frag) {
  1864. var node = parent.firstChild, nextNode;
  1865. while (node) {
  1866. var testRange = new KRange(doc).selectNode(node);
  1867. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1868. if (start >= 0 && incStart <= 0) {
  1869. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1870. }
  1871. if (incStart >= 0 && incEnd <= 0) {
  1872. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1873. }
  1874. if (incEnd >= 0 && end <= 0) {
  1875. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1876. }
  1877. if (end >= 0) {
  1878. return false;
  1879. }
  1880. nextNode = node.nextSibling;
  1881. if (start > 0) {
  1882. if (node.nodeType == 1) {
  1883. if (incStart >= 0 && incEnd <= 0) {
  1884. if (isCopy) {
  1885. frag.appendChild(node.cloneNode(true));
  1886. }
  1887. if (isDelete) {
  1888. nodeList.push(node);
  1889. }
  1890. } else {
  1891. var childFlag;
  1892. if (isCopy) {
  1893. childFlag = node.cloneNode(false);
  1894. frag.appendChild(childFlag);
  1895. }
  1896. if (extractNodes(node, childFlag) === false) {
  1897. return false;
  1898. }
  1899. }
  1900. } else if (node.nodeType == 3) {
  1901. var textNode;
  1902. if (node == copyRange.startContainer) {
  1903. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1904. } else if (node == copyRange.endContainer) {
  1905. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1906. } else {
  1907. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1908. }
  1909. if (isCopy) {
  1910. try {
  1911. frag.appendChild(textNode);
  1912. } catch(e) {}
  1913. }
  1914. }
  1915. }
  1916. node = nextNode;
  1917. }
  1918. }
  1919. extractNodes(ancestor, frag);
  1920. if (isDelete) {
  1921. range.up().collapse(true);
  1922. }
  1923. for (var i = 0, len = nodeList.length; i < len; i++) {
  1924. var node = nodeList[i];
  1925. if (node.parentNode) {
  1926. node.parentNode.removeChild(node);
  1927. }
  1928. }
  1929. return isCopy ? frag : range;
  1930. }
  1931. function _moveToElementText(range, el) {
  1932. var node = el;
  1933. while (node) {
  1934. var knode = K(node);
  1935. if (knode.name == 'marquee' || knode.name == 'select') {
  1936. return;
  1937. }
  1938. node = node.parentNode;
  1939. }
  1940. try {
  1941. range.moveToElementText(el);
  1942. } catch(e) {}
  1943. }
  1944. function _getStartEnd(rng, isStart) {
  1945. var doc = rng.parentElement().ownerDocument,
  1946. pointRange = rng.duplicate();
  1947. pointRange.collapse(isStart);
  1948. var parent = pointRange.parentElement(),
  1949. nodes = parent.childNodes;
  1950. if (nodes.length === 0) {
  1951. return {node: parent.parentNode, offset: K(parent).index()};
  1952. }
  1953. var startNode = doc, startPos = 0, cmp = -1;
  1954. var testRange = rng.duplicate();
  1955. _moveToElementText(testRange, parent);
  1956. for (var i = 0, len = nodes.length; i < len; i++) {
  1957. var node = nodes[i];
  1958. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1959. if (cmp === 0) {
  1960. return {node: node.parentNode, offset: i};
  1961. }
  1962. if (node.nodeType == 1) {
  1963. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1964. if (knode.isControl()) {
  1965. dummy = doc.createElement('span');
  1966. knode.after(dummy);
  1967. newNode = dummy;
  1968. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1969. }
  1970. _moveToElementText(nodeRange, newNode);
  1971. testRange.setEndPoint('StartToEnd', nodeRange);
  1972. if (cmp > 0) {
  1973. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1974. } else {
  1975. startPos = 0;
  1976. }
  1977. if (dummy) {
  1978. K(dummy).remove();
  1979. }
  1980. } else if (node.nodeType == 3) {
  1981. testRange.moveStart('character', node.nodeValue.length);
  1982. startPos += node.nodeValue.length;
  1983. }
  1984. if (cmp < 0) {
  1985. startNode = node;
  1986. }
  1987. }
  1988. if (cmp < 0 && startNode.nodeType == 1) {
  1989. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1990. }
  1991. if (cmp > 0) {
  1992. while (startNode.nextSibling && startNode.nodeType == 1) {
  1993. startNode = startNode.nextSibling;
  1994. }
  1995. }
  1996. testRange = rng.duplicate();
  1997. _moveToElementText(testRange, parent);
  1998. testRange.setEndPoint('StartToEnd', pointRange);
  1999. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  2000. if (cmp > 0 && startNode.nodeType == 3) {
  2001. var prevNode = startNode.previousSibling;
  2002. while (prevNode && prevNode.nodeType == 3) {
  2003. startPos -= prevNode.nodeValue.length;
  2004. prevNode = prevNode.previousSibling;
  2005. }
  2006. }
  2007. return {node: startNode, offset: startPos};
  2008. }
  2009. function _getEndRange(node, offset) {
  2010. var doc = node.ownerDocument || node,
  2011. range = doc.body.createTextRange();
  2012. if (doc == node) {
  2013. range.collapse(true);
  2014. return range;
  2015. }
  2016. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2017. var children = node.childNodes, isStart, child;
  2018. if (offset === 0) {
  2019. child = children[0];
  2020. isStart = true;
  2021. } else {
  2022. child = children[offset - 1];
  2023. isStart = false;
  2024. }
  2025. if (!child) {
  2026. return range;
  2027. }
  2028. if (K(child).name === 'head') {
  2029. if (offset === 1) {
  2030. isStart = true;
  2031. }
  2032. if (offset === 2) {
  2033. isStart = false;
  2034. }
  2035. range.collapse(isStart);
  2036. return range;
  2037. }
  2038. if (child.nodeType == 1) {
  2039. var kchild = K(child), span;
  2040. if (kchild.isControl()) {
  2041. span = doc.createElement('span');
  2042. if (isStart) {
  2043. kchild.before(span);
  2044. } else {
  2045. kchild.after(span);
  2046. }
  2047. child = span;
  2048. }
  2049. _moveToElementText(range, child);
  2050. range.collapse(isStart);
  2051. if (span) {
  2052. K(span).remove();
  2053. }
  2054. return range;
  2055. }
  2056. node = child;
  2057. offset = isStart ? 0 : child.nodeValue.length;
  2058. }
  2059. var dummy = doc.createElement('span');
  2060. K(node).before(dummy);
  2061. _moveToElementText(range, dummy);
  2062. range.moveStart('character', offset);
  2063. K(dummy).remove();
  2064. return range;
  2065. }
  2066. function _toRange(rng) {
  2067. var doc, range;
  2068. function tr2td(start) {
  2069. if (K(start.node).name == 'tr') {
  2070. start.node = start.node.cells[start.offset];
  2071. start.offset = 0;
  2072. }
  2073. }
  2074. if (_IERANGE) {
  2075. if (rng.item) {
  2076. doc = _getDoc(rng.item(0));
  2077. range = new KRange(doc);
  2078. range.selectNode(rng.item(0));
  2079. return range;
  2080. }
  2081. doc = rng.parentElement().ownerDocument;
  2082. var start = _getStartEnd(rng, true),
  2083. end = _getStartEnd(rng, false);
  2084. tr2td(start);
  2085. tr2td(end);
  2086. range = new KRange(doc);
  2087. range.setStart(start.node, start.offset);
  2088. range.setEnd(end.node, end.offset);
  2089. return range;
  2090. }
  2091. var startContainer = rng.startContainer;
  2092. doc = startContainer.ownerDocument || startContainer;
  2093. range = new KRange(doc);
  2094. range.setStart(startContainer, rng.startOffset);
  2095. range.setEnd(rng.endContainer, rng.endOffset);
  2096. return range;
  2097. }
  2098. function KRange(doc) {
  2099. this.init(doc);
  2100. }
  2101. _extend(KRange, {
  2102. init : function(doc) {
  2103. var self = this;
  2104. self.startContainer = doc;
  2105. self.startOffset = 0;
  2106. self.endContainer = doc;
  2107. self.endOffset = 0;
  2108. self.collapsed = true;
  2109. self.doc = doc;
  2110. },
  2111. commonAncestor : function() {
  2112. function getParents(node) {
  2113. var parents = [];
  2114. while (node) {
  2115. parents.push(node);
  2116. node = node.parentNode;
  2117. }
  2118. return parents;
  2119. }
  2120. var parentsA = getParents(this.startContainer),
  2121. parentsB = getParents(this.endContainer),
  2122. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2123. while (++i) {
  2124. parentA = parentsA[lenA - i];
  2125. parentB = parentsB[lenB - i];
  2126. if (!parentA || !parentB || parentA !== parentB) {
  2127. break;
  2128. }
  2129. }
  2130. return parentsA[lenA - i + 1];
  2131. },
  2132. setStart : function(node, offset) {
  2133. var self = this, doc = self.doc;
  2134. self.startContainer = node;
  2135. self.startOffset = offset;
  2136. if (self.endContainer === doc) {
  2137. self.endContainer = node;
  2138. self.endOffset = offset;
  2139. }
  2140. return _updateCollapsed(this);
  2141. },
  2142. setEnd : function(node, offset) {
  2143. var self = this, doc = self.doc;
  2144. self.endContainer = node;
  2145. self.endOffset = offset;
  2146. if (self.startContainer === doc) {
  2147. self.startContainer = node;
  2148. self.startOffset = offset;
  2149. }
  2150. return _updateCollapsed(this);
  2151. },
  2152. setStartBefore : function(node) {
  2153. return this.setStart(node.parentNode || this.doc, K(node).index());
  2154. },
  2155. setStartAfter : function(node) {
  2156. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2157. },
  2158. setEndBefore : function(node) {
  2159. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2160. },
  2161. setEndAfter : function(node) {
  2162. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2163. },
  2164. selectNode : function(node) {
  2165. return this.setStartBefore(node).setEndAfter(node);
  2166. },
  2167. selectNodeContents : function(node) {
  2168. var knode = K(node);
  2169. if (knode.type == 3 || knode.isSingle()) {
  2170. return this.selectNode(node);
  2171. }
  2172. var children = knode.children();
  2173. if (children.length > 0) {
  2174. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2175. }
  2176. return this.setStart(node, 0).setEnd(node, 0);
  2177. },
  2178. collapse : function(toStart) {
  2179. if (toStart) {
  2180. return this.setEnd(this.startContainer, this.startOffset);
  2181. }
  2182. return this.setStart(this.endContainer, this.endOffset);
  2183. },
  2184. compareBoundaryPoints : function(how, range) {
  2185. var rangeA = this.get(), rangeB = range.get();
  2186. if (_IERANGE) {
  2187. var arr = {};
  2188. arr[_START_TO_START] = 'StartToStart';
  2189. arr[_START_TO_END] = 'EndToStart';
  2190. arr[_END_TO_END] = 'EndToEnd';
  2191. arr[_END_TO_START] = 'StartToEnd';
  2192. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2193. if (cmp !== 0) {
  2194. return cmp;
  2195. }
  2196. var nodeA, nodeB, nodeC, posA, posB;
  2197. if (how === _START_TO_START || how === _END_TO_START) {
  2198. nodeA = this.startContainer;
  2199. posA = this.startOffset;
  2200. }
  2201. if (how === _START_TO_END || how === _END_TO_END) {
  2202. nodeA = this.endContainer;
  2203. posA = this.endOffset;
  2204. }
  2205. if (how === _START_TO_START || how === _START_TO_END) {
  2206. nodeB = range.startContainer;
  2207. posB = range.startOffset;
  2208. }
  2209. if (how === _END_TO_END || how === _END_TO_START) {
  2210. nodeB = range.endContainer;
  2211. posB = range.endOffset;
  2212. }
  2213. if (nodeA === nodeB) {
  2214. var diff = posA - posB;
  2215. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2216. }
  2217. nodeC = nodeB;
  2218. while (nodeC && nodeC.parentNode !== nodeA) {
  2219. nodeC = nodeC.parentNode;
  2220. }
  2221. if (nodeC) {
  2222. return K(nodeC).index() >= posA ? -1 : 1;
  2223. }
  2224. nodeC = nodeA;
  2225. while (nodeC && nodeC.parentNode !== nodeB) {
  2226. nodeC = nodeC.parentNode;
  2227. }
  2228. if (nodeC) {
  2229. return K(nodeC).index() >= posB ? 1 : -1;
  2230. }
  2231. nodeC = K(nodeB).next();
  2232. if (nodeC && nodeC.contains(nodeA)) {
  2233. return 1;
  2234. }
  2235. nodeC = K(nodeA).next();
  2236. if (nodeC && nodeC.contains(nodeB)) {
  2237. return -1;
  2238. }
  2239. } else {
  2240. return rangeA.compareBoundaryPoints(how, rangeB);
  2241. }
  2242. },
  2243. cloneRange : function() {
  2244. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2245. },
  2246. toString : function() {
  2247. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2248. return str.replace(/\r\n|\n|\r/g, '');
  2249. },
  2250. cloneContents : function() {
  2251. return _copyAndDelete(this, true, false);
  2252. },
  2253. deleteContents : function() {
  2254. return _copyAndDelete(this, false, true);
  2255. },
  2256. extractContents : function() {
  2257. return _copyAndDelete(this, true, true);
  2258. },
  2259. insertNode : function(node) {
  2260. var self = this,
  2261. sc = self.startContainer, so = self.startOffset,
  2262. ec = self.endContainer, eo = self.endOffset,
  2263. firstChild, lastChild, c, nodeCount = 1;
  2264. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2265. firstChild = node.firstChild;
  2266. lastChild = node.lastChild;
  2267. nodeCount = node.childNodes.length;
  2268. }
  2269. if (sc.nodeType == 1) {
  2270. c = sc.childNodes[so];
  2271. if (c) {
  2272. sc.insertBefore(node, c);
  2273. if (sc === ec) {
  2274. eo += nodeCount;
  2275. }
  2276. } else {
  2277. sc.appendChild(node);
  2278. }
  2279. } else if (sc.nodeType == 3) {
  2280. if (so === 0) {
  2281. sc.parentNode.insertBefore(node, sc);
  2282. if (sc.parentNode === ec) {
  2283. eo += nodeCount;
  2284. }
  2285. } else if (so >= sc.nodeValue.length) {
  2286. if (sc.nextSibling) {
  2287. sc.parentNode.insertBefore(node, sc.nextSibling);
  2288. } else {
  2289. sc.parentNode.appendChild(node);
  2290. }
  2291. } else {
  2292. if (so > 0) {
  2293. c = sc.splitText(so);
  2294. } else {
  2295. c = sc;
  2296. }
  2297. sc.parentNode.insertBefore(node, c);
  2298. if (sc === ec) {
  2299. ec = c;
  2300. eo -= so;
  2301. }
  2302. }
  2303. }
  2304. if (firstChild) {
  2305. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2306. } else {
  2307. self.selectNode(node);
  2308. }
  2309. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2310. return self;
  2311. }
  2312. return self.setEnd(ec, eo);
  2313. },
  2314. surroundContents : function(node) {
  2315. node.appendChild(this.extractContents());
  2316. return this.insertNode(node).selectNode(node);
  2317. },
  2318. isControl : function() {
  2319. var self = this,
  2320. sc = self.startContainer, so = self.startOffset,
  2321. ec = self.endContainer, eo = self.endOffset, rng;
  2322. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2323. },
  2324. get : function(hasControlRange) {
  2325. var self = this, doc = self.doc, node, rng;
  2326. if (!_IERANGE) {
  2327. rng = doc.createRange();
  2328. try {
  2329. rng.setStart(self.startContainer, self.startOffset);
  2330. rng.setEnd(self.endContainer, self.endOffset);
  2331. } catch (e) {}
  2332. return rng;
  2333. }
  2334. if (hasControlRange && self.isControl()) {
  2335. rng = doc.body.createControlRange();
  2336. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2337. return rng;
  2338. }
  2339. var range = self.cloneRange().down();
  2340. rng = doc.body.createTextRange();
  2341. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2342. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2343. return rng;
  2344. },
  2345. html : function() {
  2346. return K(this.cloneContents()).outer();
  2347. },
  2348. down : function() {
  2349. var self = this;
  2350. function downPos(node, pos, isStart) {
  2351. if (node.nodeType != 1) {
  2352. return;
  2353. }
  2354. var children = K(node).children();
  2355. if (children.length === 0) {
  2356. return;
  2357. }
  2358. var left, right, child, offset;
  2359. if (pos > 0) {
  2360. left = children.eq(pos - 1);
  2361. }
  2362. if (pos < children.length) {
  2363. right = children.eq(pos);
  2364. }
  2365. if (left && left.type == 3) {
  2366. child = left[0];
  2367. offset = child.nodeValue.length;
  2368. }
  2369. if (right && right.type == 3) {
  2370. child = right[0];
  2371. offset = 0;
  2372. }
  2373. if (!child) {
  2374. return;
  2375. }
  2376. if (isStart) {
  2377. self.setStart(child, offset);
  2378. } else {
  2379. self.setEnd(child, offset);
  2380. }
  2381. }
  2382. downPos(self.startContainer, self.startOffset, true);
  2383. downPos(self.endContainer, self.endOffset, false);
  2384. return self;
  2385. },
  2386. up : function() {
  2387. var self = this;
  2388. function upPos(node, pos, isStart) {
  2389. if (node.nodeType != 3) {
  2390. return;
  2391. }
  2392. if (pos === 0) {
  2393. if (isStart) {
  2394. self.setStartBefore(node);
  2395. } else {
  2396. self.setEndBefore(node);
  2397. }
  2398. } else if (pos == node.nodeValue.length) {
  2399. if (isStart) {
  2400. self.setStartAfter(node);
  2401. } else {
  2402. self.setEndAfter(node);
  2403. }
  2404. }
  2405. }
  2406. upPos(self.startContainer, self.startOffset, true);
  2407. upPos(self.endContainer, self.endOffset, false);
  2408. return self;
  2409. },
  2410. enlarge : function(toBlock) {
  2411. var self = this;
  2412. self.up();
  2413. function enlargePos(node, pos, isStart) {
  2414. var knode = K(node), parent;
  2415. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2416. return;
  2417. }
  2418. if (pos === 0) {
  2419. while (!knode.prev()) {
  2420. parent = knode.parent();
  2421. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2422. break;
  2423. }
  2424. knode = parent;
  2425. }
  2426. if (isStart) {
  2427. self.setStartBefore(knode[0]);
  2428. } else {
  2429. self.setEndBefore(knode[0]);
  2430. }
  2431. } else if (pos == knode.children().length) {
  2432. while (!knode.next()) {
  2433. parent = knode.parent();
  2434. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2435. break;
  2436. }
  2437. knode = parent;
  2438. }
  2439. if (isStart) {
  2440. self.setStartAfter(knode[0]);
  2441. } else {
  2442. self.setEndAfter(knode[0]);
  2443. }
  2444. }
  2445. }
  2446. enlargePos(self.startContainer, self.startOffset, true);
  2447. enlargePos(self.endContainer, self.endOffset, false);
  2448. return self;
  2449. },
  2450. shrink : function() {
  2451. var self = this, child, collapsed = self.collapsed;
  2452. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2453. self.setStart(child, 0);
  2454. }
  2455. if (collapsed) {
  2456. return self.collapse(collapsed);
  2457. }
  2458. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2459. self.setEnd(child, child.childNodes.length);
  2460. }
  2461. return self;
  2462. },
  2463. createBookmark : function(serialize) {
  2464. var self = this, doc = self.doc, endNode,
  2465. startNode = K('<span style="display:none;"></span>', doc)[0];
  2466. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2467. if (!self.collapsed) {
  2468. endNode = startNode.cloneNode(true);
  2469. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2470. }
  2471. if (endNode) {
  2472. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2473. }
  2474. self.insertNode(startNode).setStartAfter(startNode);
  2475. return {
  2476. start : serialize ? '#' + startNode.id : startNode,
  2477. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2478. };
  2479. },
  2480. moveToBookmark : function(bookmark) {
  2481. var self = this, doc = self.doc,
  2482. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2483. if (!start || start.length < 1) {
  2484. return self;
  2485. }
  2486. self.setStartBefore(start[0]);
  2487. start.remove();
  2488. if (end && end.length > 0) {
  2489. self.setEndBefore(end[0]);
  2490. end.remove();
  2491. } else {
  2492. self.collapse(true);
  2493. }
  2494. return self;
  2495. },
  2496. dump : function() {
  2497. console.log('--------------------');
  2498. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2499. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2500. }
  2501. });
  2502. function _range(mixed) {
  2503. if (!mixed.nodeName) {
  2504. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2505. }
  2506. return new KRange(mixed);
  2507. }
  2508. K.RangeClass = KRange;
  2509. K.range = _range;
  2510. K.START_TO_START = _START_TO_START;
  2511. K.START_TO_END = _START_TO_END;
  2512. K.END_TO_END = _END_TO_END;
  2513. K.END_TO_START = _END_TO_START;
  2514. function _nativeCommand(doc, key, val) {
  2515. try {
  2516. doc.execCommand(key, false, val);
  2517. } catch(e) {}
  2518. }
  2519. function _nativeCommandValue(doc, key) {
  2520. var val = '';
  2521. try {
  2522. val = doc.queryCommandValue(key);
  2523. } catch (e) {}
  2524. if (typeof val !== 'string') {
  2525. val = '';
  2526. }
  2527. return val;
  2528. }
  2529. function _getSel(doc) {
  2530. var win = _getWin(doc);
  2531. return _IERANGE ? doc.selection : win.getSelection();
  2532. }
  2533. function _getRng(doc) {
  2534. var sel = _getSel(doc), rng;
  2535. try {
  2536. if (sel.rangeCount > 0) {
  2537. rng = sel.getRangeAt(0);
  2538. } else {
  2539. rng = sel.createRange();
  2540. }
  2541. } catch(e) {}
  2542. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2543. return null;
  2544. }
  2545. return rng;
  2546. }
  2547. function _singleKeyMap(map) {
  2548. var newMap = {}, arr, v;
  2549. _each(map, function(key, val) {
  2550. arr = key.split(',');
  2551. for (var i = 0, len = arr.length; i < len; i++) {
  2552. v = arr[i];
  2553. newMap[v] = val;
  2554. }
  2555. });
  2556. return newMap;
  2557. }
  2558. function _hasAttrOrCss(knode, map) {
  2559. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2560. }
  2561. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2562. mapKey = mapKey || knode.name;
  2563. if (knode.type !== 1) {
  2564. return false;
  2565. }
  2566. var newMap = _singleKeyMap(map);
  2567. if (!newMap[mapKey]) {
  2568. return false;
  2569. }
  2570. var arr = newMap[mapKey].split(',');
  2571. for (var i = 0, len = arr.length; i < len; i++) {
  2572. var key = arr[i];
  2573. if (key === '*') {
  2574. return true;
  2575. }
  2576. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2577. var method = match[1] ? 'css' : 'attr';
  2578. key = match[2];
  2579. var val = match[3] || '';
  2580. if (val === '' && knode[method](key) !== '') {
  2581. return true;
  2582. }
  2583. if (val !== '' && knode[method](key) === val) {
  2584. return true;
  2585. }
  2586. }
  2587. return false;
  2588. }
  2589. function _removeAttrOrCss(knode, map) {
  2590. if (knode.type != 1) {
  2591. return;
  2592. }
  2593. _removeAttrOrCssByKey(knode, map, '*');
  2594. _removeAttrOrCssByKey(knode, map);
  2595. }
  2596. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2597. mapKey = mapKey || knode.name;
  2598. if (knode.type !== 1) {
  2599. return;
  2600. }
  2601. var newMap = _singleKeyMap(map);
  2602. if (!newMap[mapKey]) {
  2603. return;
  2604. }
  2605. var arr = newMap[mapKey].split(','), allFlag = false;
  2606. for (var i = 0, len = arr.length; i < len; i++) {
  2607. var key = arr[i];
  2608. if (key === '*') {
  2609. allFlag = true;
  2610. break;
  2611. }
  2612. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2613. key = match[2];
  2614. if (match[1]) {
  2615. key = _toCamel(key);
  2616. if (knode[0].style[key]) {
  2617. knode[0].style[key] = '';
  2618. }
  2619. } else {
  2620. knode.removeAttr(key);
  2621. }
  2622. }
  2623. if (allFlag) {
  2624. knode.remove(true);
  2625. }
  2626. }
  2627. function _getInnerNode(knode) {
  2628. var inner = knode;
  2629. while (inner.first()) {
  2630. inner = inner.first();
  2631. }
  2632. return inner;
  2633. }
  2634. function _isEmptyNode(knode) {
  2635. if (knode.type != 1 || knode.isSingle()) {
  2636. return false;
  2637. }
  2638. return knode.html().replace(/<[^>]+>/g, '') === '';
  2639. }
  2640. function _mergeWrapper(a, b) {
  2641. a = a.clone(true);
  2642. var lastA = _getInnerNode(a), childA = a, merged = false;
  2643. while (b) {
  2644. while (childA) {
  2645. if (childA.name === b.name) {
  2646. _mergeAttrs(childA, b.attr(), b.css());
  2647. merged = true;
  2648. }
  2649. childA = childA.first();
  2650. }
  2651. if (!merged) {
  2652. lastA.append(b.clone(false));
  2653. }
  2654. merged = false;
  2655. b = b.first();
  2656. }
  2657. return a;
  2658. }
  2659. function _wrapNode(knode, wrapper) {
  2660. wrapper = wrapper.clone(true);
  2661. if (knode.type == 3) {
  2662. _getInnerNode(wrapper).append(knode.clone(false));
  2663. knode.replaceWith(wrapper);
  2664. return wrapper;
  2665. }
  2666. var nodeWrapper = knode, child;
  2667. while ((child = knode.first()) && child.children().length == 1) {
  2668. knode = child;
  2669. }
  2670. child = knode.first();
  2671. var frag = knode.doc.createDocumentFragment();
  2672. while (child) {
  2673. frag.appendChild(child[0]);
  2674. child = child.next();
  2675. }
  2676. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2677. if (frag.firstChild) {
  2678. _getInnerNode(wrapper).append(frag);
  2679. }
  2680. nodeWrapper.replaceWith(wrapper);
  2681. return wrapper;
  2682. }
  2683. function _mergeAttrs(knode, attrs, styles) {
  2684. _each(attrs, function(key, val) {
  2685. if (key !== 'style') {
  2686. knode.attr(key, val);
  2687. }
  2688. });
  2689. _each(styles, function(key, val) {
  2690. knode.css(key, val);
  2691. });
  2692. }
  2693. function _inPreElement(knode) {
  2694. while (knode && knode.name != 'body') {
  2695. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2696. return true;
  2697. }
  2698. knode = knode.parent();
  2699. }
  2700. return false;
  2701. }
  2702. function KCmd(range) {
  2703. this.init(range);
  2704. }
  2705. _extend(KCmd, {
  2706. init : function(range) {
  2707. var self = this, doc = range.doc;
  2708. self.doc = doc;
  2709. self.win = _getWin(doc);
  2710. self.sel = _getSel(doc);
  2711. self.range = range;
  2712. },
  2713. selection : function(forceReset) {
  2714. var self = this, doc = self.doc, rng = _getRng(doc);
  2715. self.sel = _getSel(doc);
  2716. if (rng) {
  2717. self.range = _range(rng);
  2718. if (K(self.range.startContainer).name == 'html') {
  2719. self.range.selectNodeContents(doc.body).collapse(false);
  2720. }
  2721. return self;
  2722. }
  2723. if (forceReset) {
  2724. self.range.selectNodeContents(doc.body).collapse(false);
  2725. }
  2726. return self;
  2727. },
  2728. select : function(hasDummy) {
  2729. hasDummy = _undef(hasDummy, true);
  2730. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2731. sc = range.startContainer, so = range.startOffset,
  2732. ec = range.endContainer, eo = range.endOffset,
  2733. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2734. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2735. if (_IERANGE) {
  2736. var dummy = K('<span>&nbsp;</span>', doc);
  2737. range.insertNode(dummy[0]);
  2738. rng = doc.body.createTextRange();
  2739. try {
  2740. rng.moveToElementText(dummy[0]);
  2741. } catch(ex) {}
  2742. rng.collapse(false);
  2743. rng.select();
  2744. dummy.remove();
  2745. win.focus();
  2746. return self;
  2747. }
  2748. if (_WEBKIT) {
  2749. var children = sc.childNodes;
  2750. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2751. range.insertNode(doc.createTextNode('\u200B'));
  2752. hasU200b = true;
  2753. }
  2754. }
  2755. }
  2756. if (_IERANGE) {
  2757. try {
  2758. rng = range.get(true);
  2759. rng.select();
  2760. } catch(e) {}
  2761. } else {
  2762. if (hasU200b) {
  2763. range.collapse(false);
  2764. }
  2765. rng = range.get(true);
  2766. sel.removeAllRanges();
  2767. sel.addRange(rng);
  2768. if (doc !== document) {
  2769. var pos = K(rng.endContainer).pos();
  2770. //win.scrollTo(pos.x, pos.y);
  2771. }
  2772. }
  2773. win.focus();
  2774. return self;
  2775. },
  2776. wrap : function(val) {
  2777. var self = this, doc = self.doc, range = self.range, wrapper;
  2778. wrapper = K(val, doc);
  2779. if (range.collapsed) {
  2780. range.shrink();
  2781. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2782. return self;
  2783. }
  2784. if (wrapper.isBlock()) {
  2785. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2786. while (child.first()) {
  2787. child = child.first();
  2788. }
  2789. child.append(range.extractContents());
  2790. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2791. return self;
  2792. }
  2793. range.enlarge();
  2794. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2795. K(ancestor).scan(function(node) {
  2796. if (!isStart && node == bookmark.start) {
  2797. isStart = true;
  2798. return;
  2799. }
  2800. if (isStart) {
  2801. if (node == bookmark.end) {
  2802. return false;
  2803. }
  2804. var knode = K(node);
  2805. if (_inPreElement(knode)) {
  2806. return;
  2807. }
  2808. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2809. var parent;
  2810. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2811. knode = parent;
  2812. }
  2813. _wrapNode(knode, wrapper);
  2814. }
  2815. }
  2816. });
  2817. range.moveToBookmark(bookmark);
  2818. return self;
  2819. },
  2820. split : function(isStart, map) {
  2821. var range = this.range, doc = range.doc;
  2822. var tempRange = range.cloneRange().collapse(isStart);
  2823. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2824. parent = node.nodeType == 3 ? node.parentNode : node,
  2825. needSplit = false, knode;
  2826. while (parent && parent.parentNode) {
  2827. knode = K(parent);
  2828. if (map) {
  2829. if (!knode.isStyle()) {
  2830. break;
  2831. }
  2832. if (!_hasAttrOrCss(knode, map)) {
  2833. break;
  2834. }
  2835. } else {
  2836. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2837. break;
  2838. }
  2839. }
  2840. needSplit = true;
  2841. parent = parent.parentNode;
  2842. }
  2843. if (needSplit) {
  2844. var dummy = doc.createElement('span');
  2845. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2846. if (isStart) {
  2847. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2848. } else {
  2849. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2850. }
  2851. var frag = tempRange.extractContents(),
  2852. first = frag.firstChild, last = frag.lastChild;
  2853. if (isStart) {
  2854. tempRange.insertNode(frag);
  2855. range.setStartAfter(last).setEndBefore(dummy);
  2856. } else {
  2857. parent.appendChild(frag);
  2858. range.setStartBefore(dummy).setEndBefore(first);
  2859. }
  2860. var dummyParent = dummy.parentNode;
  2861. if (dummyParent == range.endContainer) {
  2862. var prev = K(dummy).prev(), next = K(dummy).next();
  2863. if (prev && next && prev.type == 3 && next.type == 3) {
  2864. range.setEnd(prev[0], prev[0].nodeValue.length);
  2865. } else if (!isStart) {
  2866. range.setEnd(range.endContainer, range.endOffset - 1);
  2867. }
  2868. }
  2869. dummyParent.removeChild(dummy);
  2870. }
  2871. return this;
  2872. },
  2873. remove : function(map) {
  2874. var self = this, doc = self.doc, range = self.range;
  2875. range.enlarge();
  2876. if (range.startOffset === 0) {
  2877. var ksc = K(range.startContainer), parent;
  2878. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2879. ksc = parent;
  2880. }
  2881. range.setStart(ksc[0], 0);
  2882. ksc = K(range.startContainer);
  2883. if (ksc.isBlock()) {
  2884. _removeAttrOrCss(ksc, map);
  2885. }
  2886. var kscp = ksc.parent();
  2887. if (kscp && kscp.isBlock()) {
  2888. _removeAttrOrCss(kscp, map);
  2889. }
  2890. }
  2891. var sc, so;
  2892. if (range.collapsed) {
  2893. self.split(true, map);
  2894. sc = range.startContainer;
  2895. so = range.startOffset;
  2896. if (so > 0) {
  2897. var sb = K(sc.childNodes[so - 1]);
  2898. if (sb && _isEmptyNode(sb)) {
  2899. sb.remove();
  2900. range.setStart(sc, so - 1);
  2901. }
  2902. }
  2903. var sa = K(sc.childNodes[so]);
  2904. if (sa && _isEmptyNode(sa)) {
  2905. sa.remove();
  2906. }
  2907. if (_isEmptyNode(sc)) {
  2908. range.startBefore(sc);
  2909. sc.remove();
  2910. }
  2911. range.collapse(true);
  2912. return self;
  2913. }
  2914. self.split(true, map);
  2915. self.split(false, map);
  2916. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2917. range.cloneRange().collapse(false).insertNode(endDummy);
  2918. range.cloneRange().collapse(true).insertNode(startDummy);
  2919. var nodeList = [], cmpStart = false;
  2920. K(range.commonAncestor()).scan(function(node) {
  2921. if (!cmpStart && node == startDummy) {
  2922. cmpStart = true;
  2923. return;
  2924. }
  2925. if (node == endDummy) {
  2926. return false;
  2927. }
  2928. if (cmpStart) {
  2929. nodeList.push(node);
  2930. }
  2931. });
  2932. K(startDummy).remove();
  2933. K(endDummy).remove();
  2934. sc = range.startContainer;
  2935. so = range.startOffset;
  2936. var ec = range.endContainer, eo = range.endOffset;
  2937. if (so > 0) {
  2938. var startBefore = K(sc.childNodes[so - 1]);
  2939. if (startBefore && _isEmptyNode(startBefore)) {
  2940. startBefore.remove();
  2941. range.setStart(sc, so - 1);
  2942. if (sc == ec) {
  2943. range.setEnd(ec, eo - 1);
  2944. }
  2945. }
  2946. var startAfter = K(sc.childNodes[so]);
  2947. if (startAfter && _isEmptyNode(startAfter)) {
  2948. startAfter.remove();
  2949. if (sc == ec) {
  2950. range.setEnd(ec, eo - 1);
  2951. }
  2952. }
  2953. }
  2954. var endAfter = K(ec.childNodes[range.endOffset]);
  2955. if (endAfter && _isEmptyNode(endAfter)) {
  2956. endAfter.remove();
  2957. }
  2958. var bookmark = range.createBookmark(true);
  2959. _each(nodeList, function(i, node) {
  2960. _removeAttrOrCss(K(node), map);
  2961. });
  2962. range.moveToBookmark(bookmark);
  2963. return self;
  2964. },
  2965. commonNode : function(map) {
  2966. var range = this.range;
  2967. var ec = range.endContainer, eo = range.endOffset,
  2968. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2969. function find(node) {
  2970. var child = node, parent = node;
  2971. while (parent) {
  2972. if (_hasAttrOrCss(K(parent), map)) {
  2973. return K(parent);
  2974. }
  2975. parent = parent.parentNode;
  2976. }
  2977. while (child && (child = child.lastChild)) {
  2978. if (_hasAttrOrCss(K(child), map)) {
  2979. return K(child);
  2980. }
  2981. }
  2982. return null;
  2983. }
  2984. var cNode = find(node);
  2985. if (cNode) {
  2986. return cNode;
  2987. }
  2988. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2989. var prev = K(node).prev();
  2990. if (prev) {
  2991. return find(prev);
  2992. }
  2993. }
  2994. return null;
  2995. },
  2996. commonAncestor : function(tagName) {
  2997. var range = this.range,
  2998. sc = range.startContainer, so = range.startOffset,
  2999. ec = range.endContainer, eo = range.endOffset,
  3000. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3001. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3002. function find(node) {
  3003. while (node) {
  3004. if (node.nodeType == 1) {
  3005. if (node.tagName.toLowerCase() === tagName) {
  3006. return node;
  3007. }
  3008. }
  3009. node = node.parentNode;
  3010. }
  3011. return null;
  3012. }
  3013. var start = find(startNode), end = find(endNode);
  3014. if (start && end && start === end) {
  3015. return K(start);
  3016. }
  3017. return null;
  3018. },
  3019. state : function(key) {
  3020. var self = this, doc = self.doc, bool = false;
  3021. try {
  3022. bool = doc.queryCommandState(key);
  3023. } catch (e) {}
  3024. return bool;
  3025. },
  3026. val : function(key) {
  3027. var self = this, doc = self.doc, range = self.range;
  3028. function lc(val) {
  3029. return val.toLowerCase();
  3030. }
  3031. key = lc(key);
  3032. var val = '', knode;
  3033. if (key === 'fontfamily' || key === 'fontname') {
  3034. val = _nativeCommandValue(doc, 'fontname');
  3035. val = val.replace(/['"]/g, '');
  3036. return lc(val);
  3037. }
  3038. if (key === 'formatblock') {
  3039. val = _nativeCommandValue(doc, key);
  3040. if (val === '') {
  3041. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3042. if (knode) {
  3043. val = knode.name;
  3044. }
  3045. }
  3046. if (val === 'Normal') {
  3047. val = 'p';
  3048. }
  3049. return lc(val);
  3050. }
  3051. if (key === 'fontsize') {
  3052. knode = self.commonNode({'*' : '.font-size'});
  3053. if (knode) {
  3054. val = knode.css('font-size');
  3055. }
  3056. return lc(val);
  3057. }
  3058. if (key === 'fontheight') {
  3059. knode = self.commonNode({'*' : '.letter-spacing'});
  3060. if (knode) {
  3061. val = knode.css('letter-spacing');
  3062. }
  3063. return lc(val);
  3064. }
  3065. if (key === 'forecolor') {
  3066. knode = self.commonNode({'*' : '.color'});
  3067. if (knode) {
  3068. val = knode.css('color');
  3069. }
  3070. val = _toHex(val);
  3071. if (val === '') {
  3072. val = 'default';
  3073. }
  3074. return lc(val);
  3075. }
  3076. if (key === 'hilitecolor') {
  3077. knode = self.commonNode({'*' : '.background-color'});
  3078. if (knode) {
  3079. val = knode.css('background-color');
  3080. }
  3081. val = _toHex(val);
  3082. if (val === '') {
  3083. val = 'default';
  3084. }
  3085. return lc(val);
  3086. }
  3087. return val;
  3088. },
  3089. toggle : function(wrapper, map) {
  3090. var self = this;
  3091. if (self.commonNode(map)) {
  3092. self.remove(map);
  3093. } else {
  3094. self.wrap(wrapper);
  3095. }
  3096. return self.select();
  3097. },
  3098. bold : function() {
  3099. return this.toggle('<strong></strong>', {
  3100. span : '.font-weight=bold',
  3101. strong : '*',
  3102. b : '*'
  3103. });
  3104. },
  3105. italic : function() {
  3106. return this.toggle('<em></em>', {
  3107. span : '.font-style=italic',
  3108. em : '*',
  3109. i : '*'
  3110. });
  3111. },
  3112. underline : function() {
  3113. return this.toggle('<u></u>', {
  3114. span : '.text-decoration=underline',
  3115. u : '*'
  3116. });
  3117. },
  3118. strikethrough : function() {
  3119. return this.toggle('<s></s>', {
  3120. span : '.text-decoration=line-through',
  3121. s : '*'
  3122. });
  3123. },
  3124. forecolor : function(val) {
  3125. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3126. },
  3127. hilitecolor : function(val) {
  3128. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3129. },
  3130. fontsize : function(val) {
  3131. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3132. },
  3133. fontheight : function(val) {
  3134. return this.wrap('<span style="letter-spacing:' + val + ';"></span>').select();
  3135. },
  3136. fontname : function(val) {
  3137. return this.fontfamily(val);
  3138. },
  3139. fontfamily : function(val) {
  3140. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3141. },
  3142. removeformat : function() {
  3143. var map = {
  3144. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3145. },
  3146. tags = _STYLE_TAG_MAP;
  3147. _each(tags, function(key, val) {
  3148. map[key] = '*';
  3149. });
  3150. this.remove(map);
  3151. return this.select();
  3152. },
  3153. inserthtml : function(val, quickMode) {
  3154. var self = this, range = self.range;
  3155. if (val === '') {
  3156. return self;
  3157. }
  3158. function pasteHtml(range, val) {
  3159. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3160. var rng = range.get();
  3161. if (rng.item) {
  3162. rng.item(0).outerHTML = val;
  3163. } else {
  3164. rng.pasteHTML(val);
  3165. }
  3166. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3167. temp.parentNode.removeChild(temp);
  3168. var newRange = _toRange(rng);
  3169. range.setEnd(newRange.endContainer, newRange.endOffset);
  3170. range.collapse(false);
  3171. self.select(false);
  3172. }
  3173. function insertHtml(range, val) {
  3174. var doc = range.doc,
  3175. frag = doc.createDocumentFragment();
  3176. K('@' + val, doc).each(function() {
  3177. frag.appendChild(this);
  3178. });
  3179. range.deleteContents();
  3180. range.insertNode(frag);
  3181. range.collapse(false);
  3182. self.select(false);
  3183. }
  3184. if (_IERANGE && quickMode) {
  3185. try {
  3186. pasteHtml(range, val);
  3187. } catch(e) {
  3188. insertHtml(range, val);
  3189. }
  3190. return self;
  3191. }
  3192. insertHtml(range, val);
  3193. return self;
  3194. },
  3195. hr : function() {
  3196. return this.inserthtml('<hr />');
  3197. },
  3198. print : function() {
  3199. this.win.print();
  3200. return this;
  3201. },
  3202. insertimage : function(url, title, width, height, border, align) {
  3203. title = _undef(title, '');
  3204. border = _undef(border, 0);
  3205. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3206. if (width) {
  3207. html += 'width="' + _escape(width) + '" ';
  3208. }
  3209. if (height) {
  3210. html += 'height="' + _escape(height) + '" ';
  3211. }
  3212. if (title) {
  3213. html += 'title="' + _escape(title) + '" ';
  3214. }
  3215. if (align) {
  3216. html += 'align="' + _escape(align) + '" ';
  3217. }
  3218. html += 'alt="' + _escape(title) + '" ';
  3219. html += '/>';
  3220. return this.inserthtml(html);
  3221. },
  3222. createlink : function(url, type) {
  3223. var self = this, doc = self.doc, range = self.range;
  3224. self.select();
  3225. var a = self.commonNode({ a : '*' });
  3226. if (a && !range.isControl()) {
  3227. range.selectNode(a.get());
  3228. self.select();
  3229. }
  3230. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3231. if (type) {
  3232. html += ' target="' + _escape(type) + '"';
  3233. }
  3234. if (range.collapsed) {
  3235. html += '>' + _escape(url) + '</a>';
  3236. return self.inserthtml(html);
  3237. }
  3238. if (range.isControl()) {
  3239. var node = K(range.startContainer.childNodes[range.startOffset]);
  3240. html += '></a>';
  3241. node.after(K(html, doc));
  3242. node.next().append(node);
  3243. range.selectNode(node[0]);
  3244. return self.select();
  3245. }
  3246. function setAttr(node, url, type) {
  3247. K(node).attr('href', url).attr('data-ke-src', url);
  3248. if (type) {
  3249. K(node).attr('target', type);
  3250. } else {
  3251. K(node).removeAttr('target');
  3252. }
  3253. }
  3254. var sc = range.startContainer, so = range.startOffset,
  3255. ec = range.endContainer, eo = range.endOffset;
  3256. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3257. var child = sc.childNodes[so];
  3258. if (child.nodeName.toLowerCase() == 'a') {
  3259. setAttr(child, url, type);
  3260. return self;
  3261. }
  3262. }
  3263. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3264. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3265. setAttr(this, url, type);
  3266. });
  3267. return self;
  3268. },
  3269. unlink : function() {
  3270. var self = this, doc = self.doc, range = self.range;
  3271. self.select();
  3272. if (range.collapsed) {
  3273. var a = self.commonNode({ a : '*' });
  3274. if (a) {
  3275. range.selectNode(a.get());
  3276. self.select();
  3277. }
  3278. _nativeCommand(doc, 'unlink', null);
  3279. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3280. var parent = K(range.startContainer).parent();
  3281. if (parent.name === 'a') {
  3282. parent.remove(true);
  3283. }
  3284. }
  3285. } else {
  3286. _nativeCommand(doc, 'unlink', null);
  3287. }
  3288. return self;
  3289. }
  3290. });
  3291. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3292. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3293. KCmd.prototype[name] = function(val) {
  3294. var self = this;
  3295. self.select();
  3296. _nativeCommand(self.doc, name, val);
  3297. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3298. self.selection();
  3299. }
  3300. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3301. self.selection();
  3302. }
  3303. return self;
  3304. };
  3305. });
  3306. _each('cut,copy,paste'.split(','), function(i, name) {
  3307. KCmd.prototype[name] = function() {
  3308. var self = this;
  3309. if (!self.doc.queryCommandSupported(name)) {
  3310. throw 'not supported';
  3311. }
  3312. self.select();
  3313. _nativeCommand(self.doc, name, null);
  3314. return self;
  3315. };
  3316. });
  3317. function _cmd(mixed) {
  3318. if (mixed.nodeName) {
  3319. var doc = _getDoc(mixed);
  3320. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3321. }
  3322. return new KCmd(mixed);
  3323. }
  3324. K.CmdClass = KCmd;
  3325. K.cmd = _cmd;
  3326. function _drag(options) {
  3327. var moveEl = options.moveEl,
  3328. moveFn = options.moveFn,
  3329. clickEl = options.clickEl || moveEl,
  3330. beforeDrag = options.beforeDrag,
  3331. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3332. var docs = [document];
  3333. if (iframeFix) {
  3334. K('iframe').each(function() {
  3335. var src = _formatUrl(this.src || '', 'absolute');
  3336. if (/^https?:\/\//.test(src)) {
  3337. return;
  3338. }
  3339. var doc;
  3340. try {
  3341. doc = _iframeDoc(this);
  3342. } catch(e) {}
  3343. if (doc) {
  3344. var pos = K(this).pos();
  3345. K(doc).data('pos-x', pos.x);
  3346. K(doc).data('pos-y', pos.y);
  3347. docs.push(doc);
  3348. }
  3349. });
  3350. }
  3351. clickEl.mousedown(function(e) {
  3352. if(e.button !== 0 && e.button !== 1) {
  3353. return;
  3354. }
  3355. e.stopPropagation();
  3356. var self = clickEl.get(),
  3357. x = _removeUnit(moveEl.css('left')),
  3358. y = _removeUnit(moveEl.css('top')),
  3359. width = moveEl.width(),
  3360. height = moveEl.height(),
  3361. pageX = e.pageX,
  3362. pageY = e.pageY;
  3363. if (beforeDrag) {
  3364. beforeDrag();
  3365. }
  3366. function moveListener(e) {
  3367. e.preventDefault();
  3368. var kdoc = K(_getDoc(e.target));
  3369. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3370. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3371. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3372. }
  3373. function selectListener(e) {
  3374. e.preventDefault();
  3375. }
  3376. function upListener(e) {
  3377. e.preventDefault();
  3378. K(docs).unbind('mousemove', moveListener)
  3379. .unbind('mouseup', upListener)
  3380. .unbind('selectstart', selectListener);
  3381. if (self.releaseCapture) {
  3382. self.releaseCapture();
  3383. }
  3384. }
  3385. K(docs).mousemove(moveListener)
  3386. .mouseup(upListener)
  3387. .bind('selectstart', selectListener);
  3388. if (self.setCapture) {
  3389. self.setCapture();
  3390. }
  3391. });
  3392. }
  3393. function KWidget(options) {
  3394. this.init(options);
  3395. }
  3396. _extend(KWidget, {
  3397. init : function(options) {
  3398. var self = this;
  3399. self.name = options.name || '';
  3400. self.doc = options.doc || document;
  3401. self.win = _getWin(self.doc);
  3402. self.x = _addUnit(options.x);
  3403. self.y = _addUnit(options.y);
  3404. self.z = options.z;
  3405. self.width = _addUnit(options.width);
  3406. self.height = _addUnit(options.height);
  3407. self.index = _addUnit(options.index);
  3408. self.div = K('<div style="display:block;"></div>');
  3409. self.options = options;
  3410. self._alignEl = options.alignEl;
  3411. if (self.width) {
  3412. self.div.css('width', self.width);
  3413. }
  3414. if (self.height) {
  3415. self.div.css('height', self.height);
  3416. }
  3417. if (self.z) {
  3418. self.div.css({
  3419. position : 'absolute',
  3420. left : self.x,
  3421. top : self.y,
  3422. 'z-index' : self.z
  3423. });
  3424. }
  3425. if (self.z && (self.x === undefined || self.y === undefined)) {
  3426. self.autoPos(self.width, self.height);
  3427. }
  3428. if (options.cls) {
  3429. self.div.addClass(options.cls);
  3430. }
  3431. if (options.shadowMode) {
  3432. self.div.addClass('ke-shadow');
  3433. }
  3434. if (options.css) {
  3435. self.div.css(options.css);
  3436. }
  3437. if (options.src) {
  3438. K(options.src).replaceWith(self.div);
  3439. } else {
  3440. K(self.doc.body).append(self.div);
  3441. }
  3442. if (options.html) {
  3443. self.div.html(options.html);
  3444. }
  3445. if (options.autoScroll) {
  3446. if (_IE && _V < 7 || _QUIRKS) {
  3447. var scrollPos = _getScrollPos();
  3448. K(self.win).bind('scroll', function(e) {
  3449. var pos = _getScrollPos(),
  3450. diffX = pos.x - scrollPos.x,
  3451. diffY = pos.y - scrollPos.y;
  3452. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3453. });
  3454. } else {
  3455. self.div.css('position', 'fixed');
  3456. }
  3457. }
  3458. },
  3459. pos : function(x, y, updateProp) {
  3460. var self = this;
  3461. updateProp = _undef(updateProp, true);
  3462. if (x !== null) {
  3463. x = x < 0 ? 0 : _addUnit(x);
  3464. self.div.css('left', x);
  3465. if (updateProp) {
  3466. self.x = x;
  3467. }
  3468. }
  3469. if (y !== null) {
  3470. y = y < 0 ? 0 : _addUnit(y);
  3471. self.div.css('top', y);
  3472. if (updateProp) {
  3473. self.y = y;
  3474. }
  3475. }
  3476. return self;
  3477. },
  3478. autoPos : function(width, height) {
  3479. var x, y, self = this,
  3480. w = _removeUnit(width) || 0,
  3481. h = _removeUnit(height) || 0,
  3482. scrollPos = _getScrollPos();
  3483. if (self._alignEl) {
  3484. var knode = K(self._alignEl),
  3485. pos = knode.pos(),
  3486. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3487. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3488. x = diffX < 0 ? pos.x : pos.x + diffX;
  3489. y = diffY < 0 ? pos.y : pos.y + diffY;
  3490. } else {
  3491. var docEl = _docElement(self.doc);
  3492. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3493. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3494. }
  3495. if (!(_IE && _V < 7 || _QUIRKS)) {
  3496. x -= scrollPos.x;
  3497. y -= scrollPos.y;
  3498. }
  3499. return self.pos(x, y);
  3500. },
  3501. remove : function() {
  3502. var self = this;
  3503. if (_IE && _V < 7 || _QUIRKS) {
  3504. K(self.win).unbind('scroll');
  3505. }
  3506. self.div.remove();
  3507. _each(self, function(i) {
  3508. self[i] = null;
  3509. });
  3510. return this;
  3511. },
  3512. show : function() {
  3513. this.div.show();
  3514. return this;
  3515. },
  3516. hide : function() {
  3517. this.div.hide();
  3518. return this;
  3519. },
  3520. draggable : function(options) {
  3521. var self = this;
  3522. options = options || {};
  3523. options.moveEl = self.div;
  3524. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3525. if ((x = x + diffX) < 0) {
  3526. x = 0;
  3527. }
  3528. if ((y = y + diffY) < 0) {
  3529. y = 0;
  3530. }
  3531. self.pos(x, y);
  3532. };
  3533. _drag(options);
  3534. return self;
  3535. }
  3536. });
  3537. function _widget(options) {
  3538. return new KWidget(options);
  3539. }
  3540. K.WidgetClass = KWidget;
  3541. K.widget = _widget;
  3542. function _iframeDoc(iframe) {
  3543. iframe = _get(iframe);
  3544. return iframe.contentDocument || iframe.contentWindow.document;
  3545. }
  3546. var html, _direction = '';
  3547. if ((html = document.getElementsByTagName('html'))) {
  3548. _direction = html[0].dir;
  3549. }
  3550. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3551. var arr = [
  3552. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3553. '<head><meta charset="utf-8" /><title></title>',
  3554. '<style>',
  3555. 'html {margin:0;padding:0;}',
  3556. 'body {margin:0;padding:5px;}',
  3557. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3558. 'body, p, div {word-wrap: break-word;}',
  3559. 'p {margin:5px 0;}',
  3560. 'table {border-collapse:collapse;}',
  3561. 'img {border:0;}',
  3562. 'noscript {display:none;}',
  3563. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3564. 'img.ke-flash {',
  3565. ' border:1px solid #AAA;',
  3566. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3567. ' background-position:center center;',
  3568. ' background-repeat:no-repeat;',
  3569. ' width:100px;',
  3570. ' height:100px;',
  3571. '}',
  3572. 'img.ke-rm {',
  3573. ' border:1px solid #AAA;',
  3574. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3575. ' background-position:center center;',
  3576. ' background-repeat:no-repeat;',
  3577. ' width:100px;',
  3578. ' height:100px;',
  3579. '}',
  3580. 'img.ke-media {',
  3581. ' border:1px solid #AAA;',
  3582. ' background-image:url(' + themesPath + 'common/media.gif);',
  3583. ' background-position:center center;',
  3584. ' background-repeat:no-repeat;',
  3585. ' width:100px;',
  3586. ' height:100px;',
  3587. '}',
  3588. 'img.ke-anchor {',
  3589. ' border:1px dashed #666;',
  3590. ' width:16px;',
  3591. ' height:16px;',
  3592. '}',
  3593. '.ke-script, .ke-noscript, .ke-display-none {',
  3594. ' display:none;',
  3595. ' font-size:0;',
  3596. ' width:0;',
  3597. ' height:0;',
  3598. '}',
  3599. '.ke-pagebreak {',
  3600. ' border:1px dotted #AAA;',
  3601. ' font-size:0;',
  3602. ' height:2px;',
  3603. '}',
  3604. '</style>'
  3605. ];
  3606. if (!_isArray(cssPath)) {
  3607. cssPath = [cssPath];
  3608. }
  3609. _each(cssPath, function(i, path) {
  3610. if (path) {
  3611. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3612. }
  3613. });
  3614. if (cssData) {
  3615. arr.push('<style>' + cssData + '</style>');
  3616. }
  3617. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3618. return arr.join('\n');
  3619. }
  3620. function _elementVal(knode, val) {
  3621. if (knode.hasVal()) {
  3622. if (val === undefined) {
  3623. var html = knode.val();
  3624. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3625. return html;
  3626. }
  3627. return knode.val(val);
  3628. }
  3629. return knode.html(val);
  3630. }
  3631. function KEdit(options) {
  3632. this.init(options);
  3633. }
  3634. _extend(KEdit, KWidget, {
  3635. init : function(options) {
  3636. var self = this;
  3637. KEdit.parent.init.call(self, options);
  3638. self.srcElement = K(options.srcElement);
  3639. self.div.addClass('ke-edit');
  3640. self.designMode = _undef(options.designMode, true);
  3641. self.beforeGetHtml = options.beforeGetHtml;
  3642. self.beforeSetHtml = options.beforeSetHtml;
  3643. self.afterSetHtml = options.afterSetHtml;
  3644. var themesPath = _undef(options.themesPath, ''),
  3645. bodyClass = options.bodyClass,
  3646. cssPath = options.cssPath,
  3647. cssData = options.cssData,
  3648. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3649. srcScript = ('document.open();' +
  3650. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3651. 'document.close();'),
  3652. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3653. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3654. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3655. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3656. self.iframe.attr('tabindex', self.tabIndex);
  3657. self.textarea.attr('tabindex', self.tabIndex);
  3658. if (self.width) {
  3659. self.setWidth(self.width);
  3660. }
  3661. if (self.height) {
  3662. self.setHeight(self.height);
  3663. }
  3664. if (self.designMode) {
  3665. self.textarea.hide();
  3666. } else {
  3667. self.iframe.hide();
  3668. }
  3669. function ready() {
  3670. var doc = _iframeDoc(self.iframe);
  3671. doc.open();
  3672. if (isDocumentDomain) {
  3673. doc.domain = document.domain;
  3674. }
  3675. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3676. doc.close();
  3677. self.win = self.iframe[0].contentWindow;
  3678. self.doc = doc;
  3679. var cmd = _cmd(doc);
  3680. self.afterChange(function(e) {
  3681. cmd.selection();
  3682. });
  3683. if (_WEBKIT) {
  3684. K(doc).click(function(e) {
  3685. if (K(e.target).name === 'img') {
  3686. cmd.selection(true);
  3687. cmd.range.selectNode(e.target);
  3688. cmd.select();
  3689. }
  3690. });
  3691. }
  3692. if (_IE) {
  3693. self._mousedownHandler = function() {
  3694. var newRange = cmd.range.cloneRange();
  3695. newRange.shrink();
  3696. if (newRange.isControl()) {
  3697. self.blur();
  3698. }
  3699. };
  3700. K(document).mousedown(self._mousedownHandler);
  3701. K(doc).keydown(function(e) {
  3702. if (e.which == 8) {
  3703. cmd.selection();
  3704. var rng = cmd.range;
  3705. if (rng.isControl()) {
  3706. rng.collapse(true);
  3707. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3708. e.preventDefault();
  3709. }
  3710. }
  3711. });
  3712. }
  3713. self.cmd = cmd;
  3714. self.html(_elementVal(self.srcElement));
  3715. if (_IE) {
  3716. doc.body.disabled = true;
  3717. doc.body.contentEditable = true;
  3718. doc.body.removeAttribute('disabled');
  3719. } else {
  3720. doc.designMode = 'on';
  3721. }
  3722. if (options.afterCreate) {
  3723. options.afterCreate.call(self);
  3724. }
  3725. }
  3726. if (isDocumentDomain) {
  3727. self.iframe.bind('load', function(e) {
  3728. self.iframe.unbind('load');
  3729. if (_IE) {
  3730. ready();
  3731. } else {
  3732. setTimeout(ready, 0);
  3733. }
  3734. });
  3735. }
  3736. self.div.append(self.iframe);
  3737. self.div.append(self.textarea);
  3738. self.srcElement.hide();
  3739. !isDocumentDomain && ready();
  3740. },
  3741. setWidth : function(val) {
  3742. var self = this;
  3743. val = _addUnit(val);
  3744. self.width = val;
  3745. self.div.css('width', val);
  3746. return self;
  3747. },
  3748. setHeight : function(val) {
  3749. var self = this;
  3750. val = _addUnit(val);
  3751. self.height = val;
  3752. self.div.css('height', val);
  3753. self.iframe.css('height', val);
  3754. if ((_IE && _V < 8) || _QUIRKS) {
  3755. val = _addUnit(_removeUnit(val) - 2);
  3756. }
  3757. self.textarea.css('height', val);
  3758. return self;
  3759. },
  3760. remove : function() {
  3761. var self = this, doc = self.doc;
  3762. K(doc.body).unbind();
  3763. K(doc).unbind();
  3764. K(self.win).unbind();
  3765. if (self._mousedownHandler) {
  3766. K(document).unbind('mousedown', self._mousedownHandler);
  3767. }
  3768. _elementVal(self.srcElement, self.html());
  3769. self.srcElement.show();
  3770. self.iframe.unbind();
  3771. self.textarea.unbind();
  3772. KEdit.parent.remove.call(self);
  3773. },
  3774. html : function(val, isFull) {
  3775. var self = this, doc = self.doc;
  3776. if (self.designMode) {
  3777. var body = doc.body;
  3778. if (val === undefined) {
  3779. if (isFull) {
  3780. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3781. } else {
  3782. val = body.innerHTML;
  3783. }
  3784. if (self.beforeGetHtml) {
  3785. val = self.beforeGetHtml(val);
  3786. }
  3787. if (_GECKO && val == '<br />') {
  3788. val = '';
  3789. }
  3790. return val;
  3791. }
  3792. if (self.beforeSetHtml) {
  3793. val = self.beforeSetHtml(val);
  3794. }
  3795. if (_IE && _V >= 9) {
  3796. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3797. }
  3798. K(body).html(val);
  3799. if (self.afterSetHtml) {
  3800. self.afterSetHtml();
  3801. }
  3802. return self;
  3803. }
  3804. if (val === undefined) {
  3805. return self.textarea.val();
  3806. }
  3807. self.textarea.val(val);
  3808. return self;
  3809. },
  3810. design : function(bool) {
  3811. var self = this, val;
  3812. if (bool === undefined ? !self.designMode : bool) {
  3813. if (!self.designMode) {
  3814. val = self.html();
  3815. self.designMode = true;
  3816. self.textarea.hide();
  3817. self.html(val);
  3818. var iframe = self.iframe;
  3819. var height = _removeUnit(self.height);
  3820. iframe.height(height - 2);
  3821. iframe.show();
  3822. setTimeout(function() {
  3823. iframe.height(height);
  3824. }, 0);
  3825. }
  3826. } else {
  3827. if (self.designMode) {
  3828. val = self.html();
  3829. self.designMode = false;
  3830. self.html(val);
  3831. self.iframe.hide();
  3832. self.textarea.show();
  3833. }
  3834. }
  3835. return self.focus();
  3836. },
  3837. focus : function() {
  3838. var self = this;
  3839. //self.designMode ? self.win.focus() : self.textarea[0].focus();
  3840. return self;
  3841. },
  3842. blur : function() {
  3843. var self = this;
  3844. if (_IE) {
  3845. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3846. self.div.append(input);
  3847. input[0].focus();
  3848. input.remove();
  3849. } else {
  3850. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3851. }
  3852. return self;
  3853. },
  3854. afterChange : function(fn) {
  3855. var self = this, doc = self.doc, body = doc.body;
  3856. K(doc).keyup(function(e) {
  3857. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3858. fn(e);
  3859. }
  3860. });
  3861. K(doc).mouseup(fn).contextmenu(fn);
  3862. K(self.win).blur(fn);
  3863. function timeoutHandler(e) {
  3864. setTimeout(function() {
  3865. fn(e);
  3866. }, 1);
  3867. }
  3868. K(body).bind('paste', timeoutHandler);
  3869. K(body).bind('cut', timeoutHandler);
  3870. return self;
  3871. }
  3872. });
  3873. function _edit(options) {
  3874. return new KEdit(options);
  3875. }
  3876. K.EditClass = KEdit;
  3877. K.edit = _edit;
  3878. K.iframeDoc = _iframeDoc;
  3879. function _selectToolbar(name, fn) {
  3880. var self = this,
  3881. knode = self.get(name);
  3882. if (knode) {
  3883. if (knode.hasClass('ke-disabled')) {
  3884. return;
  3885. }
  3886. fn(knode);
  3887. }
  3888. }
  3889. function KToolbar(options) {
  3890. this.init(options);
  3891. }
  3892. _extend(KToolbar, KWidget, {
  3893. init : function(options) {
  3894. var self = this;
  3895. KToolbar.parent.init.call(self, options);
  3896. self.disableMode = _undef(options.disableMode, false);
  3897. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3898. self._itemMap = {};
  3899. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3900. e.preventDefault();
  3901. }).attr('unselectable', 'on');
  3902. function find(target) {
  3903. var knode = K(target);
  3904. if (knode.hasClass('ke-outline')) {
  3905. return knode;
  3906. }
  3907. if (knode.hasClass('ke-toolbar-icon')) {
  3908. return knode.parent();
  3909. }
  3910. }
  3911. function hover(e, method) {
  3912. var knode = find(e.target);
  3913. if (knode) {
  3914. if (knode.hasClass('ke-disabled')) {
  3915. return;
  3916. }
  3917. if (knode.hasClass('ke-selected')) {
  3918. return;
  3919. }
  3920. knode[method]('ke-on');
  3921. }
  3922. }
  3923. self.div.mouseover(function(e) {
  3924. hover(e, 'addClass');
  3925. })
  3926. .mouseout(function(e) {
  3927. hover(e, 'removeClass');
  3928. })
  3929. .click(function(e) {
  3930. var knode = find(e.target);
  3931. if (knode) {
  3932. if (knode.hasClass('ke-disabled')) {
  3933. return;
  3934. }
  3935. self.options.click.call(this, e, knode.attr('data-name'));
  3936. }
  3937. });
  3938. },
  3939. get : function(name) {
  3940. if (this._itemMap[name]) {
  3941. return this._itemMap[name];
  3942. }
  3943. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3944. },
  3945. select : function(name) {
  3946. _selectToolbar.call(this, name, function(knode) {
  3947. knode.addClass('ke-selected');
  3948. });
  3949. return self;
  3950. },
  3951. unselect : function(name) {
  3952. _selectToolbar.call(this, name, function(knode) {
  3953. knode.removeClass('ke-selected').removeClass('ke-on');
  3954. });
  3955. return self;
  3956. },
  3957. enable : function(name) {
  3958. var self = this,
  3959. knode = name.get ? name : self.get(name);
  3960. if (knode) {
  3961. knode.removeClass('ke-disabled');
  3962. knode.opacity(1);
  3963. }
  3964. return self;
  3965. },
  3966. disable : function(name) {
  3967. var self = this,
  3968. knode = name.get ? name : self.get(name);
  3969. if (knode) {
  3970. knode.removeClass('ke-selected').addClass('ke-disabled');
  3971. knode.opacity(0.5);
  3972. }
  3973. return self;
  3974. },
  3975. disableAll : function(bool, noDisableItems) {
  3976. var self = this, map = self.noDisableItemMap, item;
  3977. if (noDisableItems) {
  3978. map = _toMap(noDisableItems);
  3979. }
  3980. if (bool === undefined ? !self.disableMode : bool) {
  3981. K('span.ke-outline', self.div).each(function() {
  3982. var knode = K(this),
  3983. name = knode[0].getAttribute('data-name', 2);
  3984. if (!map[name]) {
  3985. self.disable(knode);
  3986. }
  3987. });
  3988. self.disableMode = true;
  3989. } else {
  3990. K('span.ke-outline', self.div).each(function() {
  3991. var knode = K(this),
  3992. name = knode[0].getAttribute('data-name', 2);
  3993. if (!map[name]) {
  3994. self.enable(knode);
  3995. }
  3996. });
  3997. self.disableMode = false;
  3998. }
  3999. return self;
  4000. }
  4001. });
  4002. function _toolbar(options) {
  4003. return new KToolbar(options);
  4004. }
  4005. K.ToolbarClass = KToolbar;
  4006. K.toolbar = _toolbar;
  4007. function KMenu(options) {
  4008. this.init(options);
  4009. }
  4010. _extend(KMenu, KWidget, {
  4011. init : function(options) {
  4012. var self = this;
  4013. options.z = options.z || 811213;
  4014. KMenu.parent.init.call(self, options);
  4015. self.centerLineMode = _undef(options.centerLineMode, true);
  4016. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4017. e.stopPropagation();
  4018. }).attr('unselectable', 'on');
  4019. },
  4020. addItem : function(item) {
  4021. var self = this;
  4022. if (item.title === '-') {
  4023. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4024. return;
  4025. }
  4026. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4027. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4028. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4029. height = _addUnit(item.height),
  4030. iconClass = _undef(item.iconClass, '');
  4031. self.div.append(itemDiv);
  4032. if (height) {
  4033. itemDiv.css('height', height);
  4034. rightDiv.css('line-height', height);
  4035. }
  4036. var centerDiv;
  4037. if (self.centerLineMode) {
  4038. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4039. if (height) {
  4040. centerDiv.css('height', height);
  4041. }
  4042. }
  4043. itemDiv.mouseover(function(e) {
  4044. K(this).addClass('ke-menu-item-on');
  4045. if (centerDiv) {
  4046. centerDiv.addClass('ke-menu-item-center-on');
  4047. }
  4048. })
  4049. .mouseout(function(e) {
  4050. K(this).removeClass('ke-menu-item-on');
  4051. if (centerDiv) {
  4052. centerDiv.removeClass('ke-menu-item-center-on');
  4053. }
  4054. })
  4055. .click(function(e) {
  4056. item.click.call(K(this));
  4057. e.stopPropagation();
  4058. })
  4059. .append(leftDiv);
  4060. if (centerDiv) {
  4061. itemDiv.append(centerDiv);
  4062. }
  4063. itemDiv.append(rightDiv);
  4064. if (item.checked) {
  4065. iconClass = 'ke-icon-checked';
  4066. }
  4067. if (iconClass !== '') {
  4068. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4069. }
  4070. rightDiv.html(item.title);
  4071. return self;
  4072. },
  4073. remove : function() {
  4074. var self = this;
  4075. if (self.options.beforeRemove) {
  4076. self.options.beforeRemove.call(self);
  4077. }
  4078. K('.ke-menu-item', self.div[0]).unbind();
  4079. KMenu.parent.remove.call(self);
  4080. return self;
  4081. }
  4082. });
  4083. function _menu(options) {
  4084. return new KMenu(options);
  4085. }
  4086. K.MenuClass = KMenu;
  4087. K.menu = _menu;
  4088. function KColorPicker(options) {
  4089. this.init(options);
  4090. }
  4091. _extend(KColorPicker, KWidget, {
  4092. init : function(options) {
  4093. var self = this;
  4094. options.z = options.z || 811213;
  4095. KColorPicker.parent.init.call(self, options);
  4096. var colors = options.colors || [
  4097. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4098. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4099. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4100. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4101. ];
  4102. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4103. self._cells = [];
  4104. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4105. e.stopPropagation();
  4106. }).attr('unselectable', 'on');
  4107. var table = self.doc.createElement('table');
  4108. self.div.append(table);
  4109. table.className = 'ke-colorpicker-table';
  4110. table.cellPadding = 0;
  4111. table.cellSpacing = 0;
  4112. table.border = 0;
  4113. var row = table.insertRow(0), cell = row.insertCell(0);
  4114. cell.colSpan = colors[0].length;
  4115. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4116. for (var i = 0; i < colors.length; i++) {
  4117. row = table.insertRow(i + 1);
  4118. for (var j = 0; j < colors[i].length; j++) {
  4119. cell = row.insertCell(j);
  4120. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4121. }
  4122. }
  4123. },
  4124. _addAttr : function(cell, color, cls) {
  4125. var self = this;
  4126. cell = K(cell).addClass(cls);
  4127. if (self.selectedColor === color.toLowerCase()) {
  4128. cell.addClass('ke-colorpicker-cell-selected');
  4129. }
  4130. cell.attr('title', color || self.options.noColor);
  4131. cell.mouseover(function(e) {
  4132. K(this).addClass('ke-colorpicker-cell-on');
  4133. });
  4134. cell.mouseout(function(e) {
  4135. K(this).removeClass('ke-colorpicker-cell-on');
  4136. });
  4137. cell.click(function(e) {
  4138. e.stop();
  4139. self.options.click.call(K(this), color);
  4140. });
  4141. if (color) {
  4142. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4143. } else {
  4144. cell.html(self.options.noColor);
  4145. }
  4146. K(cell).attr('unselectable', 'on');
  4147. self._cells.push(cell);
  4148. },
  4149. remove : function() {
  4150. var self = this;
  4151. _each(self._cells, function() {
  4152. this.unbind();
  4153. });
  4154. KColorPicker.parent.remove.call(self);
  4155. return self;
  4156. }
  4157. });
  4158. function _colorpicker(options) {
  4159. return new KColorPicker(options);
  4160. }
  4161. K.ColorPickerClass = KColorPicker;
  4162. K.colorpicker = _colorpicker;
  4163. function KUploadButton(options) {
  4164. this.init(options);
  4165. }
  4166. _extend(KUploadButton, {
  4167. init : function(options) {
  4168. var self = this,
  4169. button = K(options.button),
  4170. fieldName = options.fieldName || 'file',
  4171. url = options.url || '',
  4172. title = button.val(),
  4173. extraParams = options.extraParams || {},
  4174. cls = button[0].className || '',
  4175. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4176. options.afterError = options.afterError || function(str) {
  4177. alert(str);
  4178. };
  4179. var hiddenElements = [];
  4180. for(var k in extraParams){
  4181. hiddenElements.push('<input type="hidden" class="ke-upload-file-'+k+'" name="' + k + '" value="' + extraParams[k] + '" />');
  4182. }
  4183. var html = [
  4184. '<div class="ke-inline-block ' + cls + '">',
  4185. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4186. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4187. '<span class="ke-button-common">',
  4188. hiddenElements.join(''),
  4189. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4190. '</span>',
  4191. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4192. (options.form ? '</div>' : '</form>'),
  4193. '</div>'].join('');
  4194. var div = K(html, button.doc);
  4195. button.hide();
  4196. button.before(div);
  4197. self.div = div;
  4198. self.button = button;
  4199. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4200. self.form = options.form ? K(options.form) : K('form', div);
  4201. self.fileBox = K('.ke-upload-file', div);
  4202. var width = options.width || K('.ke-button-common', div).width();
  4203. K('.ke-upload-area', div).width(width);
  4204. self.options = options;
  4205. },
  4206. submit : function(e) {
  4207. var self = this,
  4208. iframe = self.iframe;
  4209. e = false;
  4210. if (e) {
  4211. var file = e.files[0];
  4212. var filename = file.name;
  4213. var temp = filename.split('.');
  4214. //putExtra.params["x:name"] = temp[0];
  4215. var filename = hex_md5(file.name) + '.' + temp[temp.length-1];
  4216. var path = $('.' + 'ke-upload-file-key').val();
  4217. $('.' + 'ke-upload-file-key').val(path + filename);
  4218. //这里要修改 以后再改
  4219. } else {
  4220. iframe.bind('load', function() {
  4221. iframe.unbind();
  4222. var tempForm = document.createElement('form');
  4223. self.fileBox.before(tempForm);
  4224. K(tempForm).append(self.fileBox);
  4225. tempForm.reset();
  4226. K(tempForm).remove(true);
  4227. var doc = K.iframeDoc(iframe),
  4228. pre = doc.getElementsByTagName('pre')[0],
  4229. str = '', data;
  4230. if (pre) {
  4231. str = pre.innerHTML;
  4232. } else {
  4233. str = doc.body.innerHTML;
  4234. }
  4235. str = _unescape(str);
  4236. iframe[0].src = 'javascript:false';
  4237. try {
  4238. data = K.json(str);
  4239. } catch (e) {
  4240. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4241. }
  4242. if (data) {
  4243. self.options.afterUpload.call(self, data);
  4244. }
  4245. });
  4246. self.form[0].submit();
  4247. }
  4248. self.form[0].submit();
  4249. return self;
  4250. },
  4251. remove : function() {
  4252. var self = this;
  4253. if (self.fileBox) {
  4254. self.fileBox.unbind();
  4255. }
  4256. self.iframe.remove();
  4257. self.div.remove();
  4258. self.button.show();
  4259. return self;
  4260. }
  4261. });
  4262. function _uploadbutton(options) {
  4263. return new KUploadButton(options);
  4264. }
  4265. K.UploadButtonClass = KUploadButton;
  4266. K.uploadbutton = _uploadbutton;
  4267. function _createButton(arg) {
  4268. arg = arg || {};
  4269. var name = arg.name || '',
  4270. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4271. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4272. if (arg.click) {
  4273. btn.click(arg.click);
  4274. }
  4275. span.append(btn);
  4276. return span;
  4277. }
  4278. function KDialog(options) {
  4279. this.init(options);
  4280. }
  4281. _extend(KDialog, KWidget, {
  4282. init : function(options) {
  4283. var self = this;
  4284. var shadowMode = _undef(options.shadowMode, true);
  4285. options.z = options.z || 811213;
  4286. options.shadowMode = false;
  4287. options.autoScroll = _undef(options.autoScroll, true);
  4288. KDialog.parent.init.call(self, options);
  4289. var title = options.title,
  4290. body = K(options.body, self.doc),
  4291. previewBtn = options.previewBtn,
  4292. yesBtn = options.yesBtn,
  4293. noBtn = options.noBtn,
  4294. closeBtn = options.closeBtn,
  4295. showMask = _undef(options.showMask, true);
  4296. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4297. e.stopPropagation();
  4298. });
  4299. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4300. if (_IE && _V < 7) {
  4301. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4302. } else if (shadowMode) {
  4303. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4304. }
  4305. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4306. contentDiv.append(headerDiv);
  4307. headerDiv.html(title);
  4308. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4309. headerDiv.append(self.closeIcon);
  4310. self.draggable({
  4311. clickEl : headerDiv,
  4312. beforeDrag : options.beforeDrag
  4313. });
  4314. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4315. contentDiv.append(bodyDiv);
  4316. bodyDiv.append(body);
  4317. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4318. if (previewBtn || yesBtn || noBtn) {
  4319. contentDiv.append(footerDiv);
  4320. }
  4321. _each([
  4322. { btn : previewBtn, name : 'preview' },
  4323. { btn : yesBtn, name : 'yes' },
  4324. { btn : noBtn, name : 'no' }
  4325. ], function() {
  4326. if (this.btn) {
  4327. var button = _createButton(this.btn);
  4328. button.addClass('ke-dialog-' + this.name);
  4329. footerDiv.append(button);
  4330. }
  4331. });
  4332. if (self.height) {
  4333. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4334. }
  4335. self.div.width(self.div.width());
  4336. self.div.height(self.div.height());
  4337. self.mask = null;
  4338. if (showMask) {
  4339. var docEl = _docElement(self.doc),
  4340. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4341. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4342. self.mask = _widget({
  4343. x : 0,
  4344. y : 0,
  4345. z : self.z - 1,
  4346. cls : 'ke-dialog-mask',
  4347. width : docWidth,
  4348. height : docHeight
  4349. });
  4350. }
  4351. self.autoPos(self.div.width(), self.div.height());
  4352. self.footerDiv = footerDiv;
  4353. self.bodyDiv = bodyDiv;
  4354. self.headerDiv = headerDiv;
  4355. self.isLoading = false;
  4356. },
  4357. setMaskIndex : function(z) {
  4358. var self = this;
  4359. self.mask.div.css('z-index', z);
  4360. },
  4361. showLoading : function(msg) {
  4362. msg = _undef(msg, '');
  4363. var self = this, body = self.bodyDiv;
  4364. 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>')
  4365. .width(body.width()).height(body.height())
  4366. .css('top', self.headerDiv.height() + 'px');
  4367. body.css('visibility', 'hidden').after(self.loading);
  4368. self.isLoading = true;
  4369. return self;
  4370. },
  4371. hideLoading : function() {
  4372. this.loading && this.loading.remove();
  4373. this.bodyDiv.css('visibility', 'visible');
  4374. this.isLoading = false;
  4375. return this;
  4376. },
  4377. remove : function() {
  4378. var self = this;
  4379. if (self.options.beforeRemove) {
  4380. self.options.beforeRemove.call(self);
  4381. }
  4382. self.mask && self.mask.remove();
  4383. self.iframeMask && self.iframeMask.remove();
  4384. self.closeIcon.unbind();
  4385. K('input', self.div).unbind();
  4386. K('button', self.div).unbind();
  4387. self.footerDiv.unbind();
  4388. self.bodyDiv.unbind();
  4389. self.headerDiv.unbind();
  4390. K('iframe', self.div).each(function() {
  4391. K(this).remove();
  4392. });
  4393. KDialog.parent.remove.call(self);
  4394. return self;
  4395. }
  4396. });
  4397. function _dialog(options) {
  4398. return new KDialog(options);
  4399. }
  4400. K.DialogClass = KDialog;
  4401. K.dialog = _dialog;
  4402. function _tabs(options) {
  4403. var self = _widget(options),
  4404. remove = self.remove,
  4405. afterSelect = options.afterSelect,
  4406. div = self.div,
  4407. liList = [];
  4408. div.addClass('ke-tabs')
  4409. .bind('contextmenu,mousedown,mousemove', function(e) {
  4410. e.preventDefault();
  4411. });
  4412. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4413. div.append(ul);
  4414. self.add = function(tab) {
  4415. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4416. li.data('tab', tab);
  4417. liList.push(li);
  4418. ul.append(li);
  4419. };
  4420. self.selectedIndex = 0;
  4421. self.select = function(index) {
  4422. self.selectedIndex = index;
  4423. _each(liList, function(i, li) {
  4424. li.unbind();
  4425. if (i === index) {
  4426. li.addClass('ke-tabs-li-selected');
  4427. K(li.data('tab').panel).show('');
  4428. } else {
  4429. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4430. .mouseover(function() {
  4431. K(this).addClass('ke-tabs-li-on');
  4432. })
  4433. .mouseout(function() {
  4434. K(this).removeClass('ke-tabs-li-on');
  4435. })
  4436. .click(function() {
  4437. self.select(i);
  4438. });
  4439. K(li.data('tab').panel).hide();
  4440. }
  4441. });
  4442. if (afterSelect) {
  4443. afterSelect.call(self, index);
  4444. }
  4445. };
  4446. self.remove = function() {
  4447. _each(liList, function() {
  4448. this.remove();
  4449. });
  4450. ul.remove();
  4451. remove.call(self);
  4452. };
  4453. return self;
  4454. }
  4455. K.tabs = _tabs;
  4456. function _loadScript(url, fn) {
  4457. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4458. script = document.createElement('script');
  4459. head.appendChild(script);
  4460. script.src = url;
  4461. script.charset = 'utf-8';
  4462. script.onload = script.onreadystatechange = function() {
  4463. if (!this.readyState || this.readyState === 'loaded') {
  4464. if (fn) {
  4465. fn();
  4466. }
  4467. script.onload = script.onreadystatechange = null;
  4468. head.removeChild(script);
  4469. }
  4470. };
  4471. }
  4472. function _chopQuery(url) {
  4473. var index = url.indexOf('?');
  4474. return index > 0 ? url.substr(0, index) : url;
  4475. }
  4476. function _loadStyle(url) {
  4477. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4478. link = document.createElement('link'),
  4479. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4480. var links = K('link[rel="stylesheet"]', head);
  4481. for (var i = 0, len = links.length; i < len; i++) {
  4482. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4483. return;
  4484. }
  4485. }
  4486. head.appendChild(link);
  4487. link.href = url;
  4488. link.rel = 'stylesheet';
  4489. }
  4490. function _ajax(url, fn, method, param, dataType) {
  4491. method = method || 'GET';
  4492. dataType = dataType || 'json';
  4493. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4494. xhr.open(method, url, true);
  4495. xhr.onreadystatechange = function () {
  4496. if (xhr.readyState == 4 && xhr.status == 200) {
  4497. if (fn) {
  4498. var data = _trim(xhr.responseText);
  4499. if (dataType == 'json') {
  4500. data = _json(data);
  4501. }
  4502. fn(data);
  4503. }
  4504. }
  4505. };
  4506. if (method == 'POST') {
  4507. var params = [];
  4508. _each(param, function(key, val) {
  4509. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4510. });
  4511. try {
  4512. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4513. } catch (e) {}
  4514. xhr.send(params.join('&'));
  4515. } else {
  4516. xhr.send(null);
  4517. }
  4518. }
  4519. K.loadScript = _loadScript;
  4520. K.loadStyle = _loadStyle;
  4521. K.ajax = _ajax;
  4522. var _plugins = {};
  4523. function _plugin(name, fn) {
  4524. if (name === undefined) {
  4525. return _plugins;
  4526. }
  4527. if (!fn) {
  4528. return _plugins[name];
  4529. }
  4530. _plugins[name] = fn;
  4531. }
  4532. var _language = {};
  4533. function _parseLangKey(key) {
  4534. var match, ns = 'core';
  4535. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4536. ns = match[1];
  4537. key = match[2];
  4538. }
  4539. return { ns : ns, key : key };
  4540. }
  4541. function _lang(mixed, langType) {
  4542. langType = langType === undefined ? K.options.langType : langType;
  4543. if (typeof mixed === 'string') {
  4544. if (!_language[langType]) {
  4545. return 'no language';
  4546. }
  4547. var pos = mixed.length - 1;
  4548. if (mixed.substr(pos) === '.') {
  4549. return _language[langType][mixed.substr(0, pos)];
  4550. }
  4551. var obj = _parseLangKey(mixed);
  4552. return _language[langType][obj.ns][obj.key];
  4553. }
  4554. _each(mixed, function(key, val) {
  4555. var obj = _parseLangKey(key);
  4556. if (!_language[langType]) {
  4557. _language[langType] = {};
  4558. }
  4559. if (!_language[langType][obj.ns]) {
  4560. _language[langType][obj.ns] = {};
  4561. }
  4562. _language[langType][obj.ns][obj.key] = val;
  4563. });
  4564. }
  4565. function _getImageFromRange(range, fn) {
  4566. if (range.collapsed) {
  4567. return;
  4568. }
  4569. range = range.cloneRange().up();
  4570. var sc = range.startContainer, so = range.startOffset;
  4571. if (!_WEBKIT && !range.isControl()) {
  4572. return;
  4573. }
  4574. var img = K(sc.childNodes[so]);
  4575. if (!img || img.name != 'img') {
  4576. return;
  4577. }
  4578. if (fn(img)) {
  4579. return img;
  4580. }
  4581. }
  4582. function _bindContextmenuEvent() {
  4583. var self = this, doc = self.edit.doc;
  4584. K(doc).contextmenu(function(e) {
  4585. if (self.menu) {
  4586. self.hideMenu();
  4587. }
  4588. if (!self.useContextmenu) {
  4589. e.preventDefault();
  4590. return;
  4591. }
  4592. if (self._contextmenus.length === 0) {
  4593. return;
  4594. }
  4595. var maxWidth = 0, items = [];
  4596. _each(self._contextmenus, function() {
  4597. if (this.title == '-') {
  4598. items.push(this);
  4599. return;
  4600. }
  4601. if (this.cond && this.cond()) {
  4602. items.push(this);
  4603. if (this.width && this.width > maxWidth) {
  4604. maxWidth = this.width;
  4605. }
  4606. }
  4607. });
  4608. while (items.length > 0 && items[0].title == '-') {
  4609. items.shift();
  4610. }
  4611. while (items.length > 0 && items[items.length - 1].title == '-') {
  4612. items.pop();
  4613. }
  4614. var prevItem = null;
  4615. _each(items, function(i) {
  4616. if (this.title == '-' && prevItem.title == '-') {
  4617. delete items[i];
  4618. }
  4619. prevItem = this;
  4620. });
  4621. if (items.length > 0) {
  4622. e.preventDefault();
  4623. var pos = K(self.edit.iframe).pos(),
  4624. menu = _menu({
  4625. x : pos.x + e.clientX,
  4626. y : pos.y + e.clientY,
  4627. width : maxWidth,
  4628. css : { visibility: 'hidden' },
  4629. shadowMode : self.shadowMode
  4630. });
  4631. _each(items, function() {
  4632. if (this.title) {
  4633. menu.addItem(this);
  4634. }
  4635. });
  4636. var docEl = _docElement(menu.doc),
  4637. menuHeight = menu.div.height();
  4638. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4639. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4640. }
  4641. menu.div.css('visibility', 'visible');
  4642. self.menu = menu;
  4643. }
  4644. });
  4645. }
  4646. function _bindNewlineEvent() {
  4647. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4648. if (_IE && newlineTag !== 'br') {
  4649. return;
  4650. }
  4651. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4652. return;
  4653. }
  4654. if (_OPERA && _V < 9) {
  4655. return;
  4656. }
  4657. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4658. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4659. function getAncestorTagName(range) {
  4660. var ancestor = K(range.commonAncestor());
  4661. while (ancestor) {
  4662. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4663. break;
  4664. }
  4665. ancestor = ancestor.parent();
  4666. }
  4667. return ancestor.name;
  4668. }
  4669. K(doc).keydown(function(e) {
  4670. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4671. autoImg(self);
  4672. return;
  4673. }
  4674. self.cmd.selection();
  4675. var tagName = getAncestorTagName(self.cmd.range);
  4676. if (tagName == 'marquee' || tagName == 'select') {
  4677. return;
  4678. }
  4679. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4680. e.preventDefault();
  4681. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4682. return;
  4683. }
  4684. if (!pSkipTagMap[tagName]) {
  4685. _nativeCommand(doc, 'formatblock', '<p>');
  4686. }
  4687. });
  4688. K(doc).keyup(function(e) {
  4689. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4690. return;
  4691. }
  4692. if (newlineTag == 'br') {
  4693. return;
  4694. }
  4695. if (_GECKO) {
  4696. var root = self.cmd.commonAncestor('p');
  4697. var a = self.cmd.commonAncestor('a');
  4698. if (a && a.text() == '') {
  4699. a.remove(true);
  4700. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4701. self.cmd.select();
  4702. }
  4703. return;
  4704. }
  4705. self.cmd.selection();
  4706. var tagName = getAncestorTagName(self.cmd.range);
  4707. if (tagName == 'marquee' || tagName == 'select') {
  4708. return;
  4709. }
  4710. if (!pSkipTagMap[tagName]) {
  4711. _nativeCommand(doc, 'formatblock', '<p>');
  4712. }
  4713. var div = self.cmd.commonAncestor('div');
  4714. if (div) {
  4715. var p = K('<p></p>'),
  4716. child = div[0].firstChild;
  4717. while (child) {
  4718. var next = child.nextSibling;
  4719. p.append(child);
  4720. child = next;
  4721. }
  4722. div.before(p);
  4723. div.remove();
  4724. self.cmd.range.selectNodeContents(p[0]);
  4725. self.cmd.select();
  4726. }
  4727. });
  4728. }
  4729. function _bindTabEvent() {
  4730. var self = this, doc = self.edit.doc;
  4731. K(doc).keydown(function(e) {
  4732. if (e.which == 9) {
  4733. e.preventDefault();
  4734. if (self.afterTab) {
  4735. self.afterTab.call(self, e);
  4736. return;
  4737. }
  4738. var cmd = self.cmd, range = cmd.range;
  4739. range.shrink();
  4740. if (range.collapsed && range.startContainer.nodeType == 1) {
  4741. range.insertNode(K('@&nbsp;', doc)[0]);
  4742. cmd.select();
  4743. }
  4744. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4745. }
  4746. });
  4747. }
  4748. function _bindFocusEvent() {
  4749. var self = this;
  4750. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4751. if (self.afterFocus) {
  4752. self.afterFocus.call(self, e);
  4753. }
  4754. }).blur(function(e) {
  4755. if (self.afterBlur) {
  4756. self.afterBlur.call(self, e);
  4757. }
  4758. });
  4759. }
  4760. function _removeBookmarkTag(html) {
  4761. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4762. }
  4763. function _removeTempTag(html) {
  4764. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4765. }
  4766. function _addBookmarkToStack(stack, bookmark) {
  4767. if (stack.length === 0) {
  4768. stack.push(bookmark);
  4769. return;
  4770. }
  4771. var prev = stack[stack.length - 1];
  4772. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4773. stack.push(bookmark);
  4774. }
  4775. }
  4776. function _undoToRedo(fromStack, toStack) {
  4777. var self = this, edit = self.edit,
  4778. body = edit.doc.body,
  4779. range, bookmark;
  4780. if (fromStack.length === 0) {
  4781. return self;
  4782. }
  4783. if (edit.designMode) {
  4784. range = self.cmd.range;
  4785. bookmark = range.createBookmark(true);
  4786. bookmark.html = body.innerHTML;
  4787. } else {
  4788. bookmark = {
  4789. html : body.innerHTML
  4790. };
  4791. }
  4792. _addBookmarkToStack(toStack, bookmark);
  4793. var prev = fromStack.pop();
  4794. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4795. prev = fromStack.pop();
  4796. }
  4797. if (edit.designMode) {
  4798. edit.html(prev.html);
  4799. if (prev.start) {
  4800. range.moveToBookmark(prev);
  4801. self.select();
  4802. }
  4803. } else {
  4804. K(body).html(_removeBookmarkTag(prev.html));
  4805. }
  4806. return self;
  4807. }
  4808. function KEditor(options) {
  4809. var self = this;
  4810. self.options = {};
  4811. function setOption(key, val) {
  4812. if (KEditor.prototype[key] === undefined) {
  4813. self[key] = val;
  4814. }
  4815. self.options[key] = val;
  4816. }
  4817. _each(options, function(key, val) {
  4818. setOption(key, options[key]);
  4819. });
  4820. _each(K.options, function(key, val) {
  4821. if (self[key] === undefined) {
  4822. setOption(key, val);
  4823. }
  4824. });
  4825. var se = K(self.srcElement || '<textarea/>');
  4826. if (!self.width) {
  4827. self.width = se[0].style.width || se.width();
  4828. if (!self.width) {
  4829. self.width = '700';
  4830. }
  4831. }
  4832. if (!self.height) {
  4833. self.height = se[0].style.height || se.height();
  4834. }
  4835. setOption('width', _undef(self.width, self.minWidth));
  4836. setOption('height', _undef(self.height, self.minHeight));
  4837. setOption('width', _addUnit(self.width));
  4838. setOption('height', _addUnit(self.height));
  4839. if (_MOBILE && (!_IOS || _V < 534)) {
  4840. //self.designMode = false;
  4841. }
  4842. self.srcElement = se;
  4843. self.initContent = '';
  4844. self.plugin = {};
  4845. self.isCreated = false;
  4846. self._handlers = {};
  4847. self._contextmenus = [];
  4848. self._undoStack = [];
  4849. self._redoStack = [];
  4850. self._firstAddBookmark = true;
  4851. self.menu = self.contextmenu = null;
  4852. self.dialogs = [];
  4853. }
  4854. KEditor.prototype = {
  4855. lang : function(mixed) {
  4856. return _lang(mixed, this.langType);
  4857. },
  4858. loadPlugin : function(name, fn) {
  4859. var self = this;
  4860. var _pluginStatus = this._pluginStatus;
  4861. if (!_pluginStatus) {
  4862. _pluginStatus = this._pluginStatus = {};
  4863. }
  4864. if (_plugins[name]) {
  4865. if (!_isFunction(_plugins[name])) {
  4866. setTimeout(function() {
  4867. self.loadPlugin(name, fn);
  4868. }, 100);
  4869. return self;
  4870. }
  4871. if(!_pluginStatus[name]) {
  4872. _plugins[name].call(self, KindEditor);
  4873. _pluginStatus[name] = 'inited';
  4874. }
  4875. if (fn) {
  4876. fn.call(self);
  4877. }
  4878. return self;
  4879. }
  4880. _plugins[name] = 'loading';
  4881. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4882. setTimeout(function() {
  4883. if (_plugins[name]) {
  4884. self.loadPlugin(name, fn);
  4885. }
  4886. }, 0);
  4887. });
  4888. return self;
  4889. },
  4890. handler : function(key, fn) {
  4891. var self = this;
  4892. if (!self._handlers[key]) {
  4893. self._handlers[key] = [];
  4894. }
  4895. if (_isFunction(fn)) {
  4896. self._handlers[key].push(fn);
  4897. return self;
  4898. }
  4899. _each(self._handlers[key], function() {
  4900. fn = this.call(self, fn);
  4901. });
  4902. return fn;
  4903. },
  4904. clickToolbar : function(name, fn) {
  4905. var self = this, key = 'clickToolbar' + name;
  4906. if (fn === undefined) {
  4907. if (self._handlers[key]) {
  4908. return self.handler(key);
  4909. }
  4910. self.loadPlugin(name, function() {
  4911. self.handler(key);
  4912. });
  4913. return self;
  4914. }
  4915. return self.handler(key, fn);
  4916. },
  4917. updateState : function() {
  4918. var self = this;
  4919. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4920. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4921. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4922. });
  4923. return self;
  4924. },
  4925. addContextmenu : function(item) {
  4926. this._contextmenus.push(item);
  4927. return this;
  4928. },
  4929. afterCreate : function(fn) {
  4930. return this.handler('afterCreate', fn);
  4931. },
  4932. beforeRemove : function(fn) {
  4933. return this.handler('beforeRemove', fn);
  4934. },
  4935. beforeGetHtml : function(fn) {
  4936. return this.handler('beforeGetHtml', fn);
  4937. },
  4938. beforeSetHtml : function(fn) {
  4939. return this.handler('beforeSetHtml', fn);
  4940. },
  4941. afterSetHtml : function(fn) {
  4942. return this.handler('afterSetHtml', fn);
  4943. },
  4944. create : function() {
  4945. var self = this, fullscreenMode = self.fullscreenMode;
  4946. if (self.isCreated) {
  4947. return self;
  4948. }
  4949. if (self.srcElement.data('kindeditor')) {
  4950. return self;
  4951. }
  4952. self.srcElement.data('kindeditor', 'true');
  4953. if (fullscreenMode) {
  4954. _docElement().style.overflow = 'hidden';
  4955. } else {
  4956. _docElement().style.overflow = '';
  4957. }
  4958. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4959. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4960. if ((_IE && _V < 8) || _QUIRKS) {
  4961. height = _addUnit(_removeUnit(height) + 2);
  4962. }
  4963. var container = self.container = K(self.layout);
  4964. if (fullscreenMode) {
  4965. K(document.body).append(container);
  4966. } else {
  4967. self.srcElement.before(container);
  4968. }
  4969. var toolbarDiv = K('.toolbar', container),
  4970. editDiv = K('.edit', container),
  4971. statusbar = self.statusbar = K('.statusbar', container);
  4972. container.removeClass('container')
  4973. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4974. if (fullscreenMode) {
  4975. container.css({
  4976. position : 'absolute',
  4977. left : 0,
  4978. top : 0,
  4979. 'z-index' : 811211
  4980. });
  4981. if (!_GECKO) {
  4982. self._scrollPos = _getScrollPos();
  4983. }
  4984. window.scrollTo(0, 0);
  4985. K(document.body).css({
  4986. 'height' : '1px',
  4987. 'overflow' : 'hidden'
  4988. });
  4989. K(document.body.parentNode).css('overflow', 'hidden');
  4990. self._fullscreenExecuted = true;
  4991. } else {
  4992. if (self._fullscreenExecuted) {
  4993. K(document.body).css({
  4994. 'height' : '',
  4995. 'overflow' : ''
  4996. });
  4997. K(document.body.parentNode).css('overflow', '');
  4998. }
  4999. if (self._scrollPos) {
  5000. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  5001. }
  5002. }
  5003. var htmlList = [];
  5004. K.each(self.items, function(i, name) {
  5005. if (name == '|') {
  5006. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  5007. } else if (name == '/') {
  5008. htmlList.push('<div class="ke-hr"></div>');
  5009. } else {
  5010. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  5011. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  5012. }
  5013. });
  5014. var toolbar = self.toolbar = _toolbar({
  5015. src : toolbarDiv,
  5016. html : htmlList.join(''),
  5017. noDisableItems : self.noDisableItems,
  5018. click : function(e, name) {
  5019. e.stop();
  5020. if (self.menu) {
  5021. var menuName = self.menu.name;
  5022. self.hideMenu();
  5023. if (menuName === name) {
  5024. return;
  5025. }
  5026. }
  5027. self.clickToolbar(name);
  5028. }
  5029. });
  5030. var editHeight = _removeUnit(height) - toolbar.div.height();
  5031. var edit = self.edit = _edit({
  5032. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5033. src : editDiv,
  5034. srcElement : self.srcElement,
  5035. designMode : self.designMode,
  5036. themesPath : self.themesPath,
  5037. bodyClass : self.bodyClass,
  5038. cssPath : self.cssPath,
  5039. cssData : self.cssData,
  5040. beforeGetHtml : function(html) {
  5041. html = self.beforeGetHtml(html);
  5042. html = _removeBookmarkTag(_removeTempTag(html));
  5043. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5044. },
  5045. beforeSetHtml : function(html) {
  5046. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5047. return self.beforeSetHtml(html);
  5048. },
  5049. afterSetHtml : function() {
  5050. self.edit = edit = this;
  5051. self.afterSetHtml();
  5052. },
  5053. afterCreate : function() {
  5054. self.edit = edit = this;
  5055. self.cmd = edit.cmd;
  5056. self._docMousedownFn = function(e) {
  5057. if (self.menu) {
  5058. self.hideMenu();
  5059. }
  5060. };
  5061. K(edit.doc, document).mousedown(self._docMousedownFn);
  5062. _bindContextmenuEvent.call(self);
  5063. _bindNewlineEvent.call(self);
  5064. _bindTabEvent.call(self);
  5065. _bindFocusEvent.call(self);
  5066. edit.afterChange(function(e) {
  5067. if (!edit.designMode) {
  5068. return;
  5069. }
  5070. self.updateState();
  5071. self.addBookmark();
  5072. if (self.options.afterChange) {
  5073. self.options.afterChange.call(self);
  5074. }
  5075. });
  5076. edit.textarea.keyup(function(e) {
  5077. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5078. if (self.options.afterChange) {
  5079. self.options.afterChange.call(self);
  5080. }
  5081. }
  5082. });
  5083. if (self.readonlyMode) {
  5084. self.readonly();
  5085. }
  5086. self.isCreated = true;
  5087. if (self.initContent === '') {
  5088. self.initContent = self.html();
  5089. }
  5090. if (self._undoStack.length > 0) {
  5091. var prev = self._undoStack.pop();
  5092. if (prev.start) {
  5093. self.html(prev.html);
  5094. edit.cmd.range.moveToBookmark(prev);
  5095. self.select();
  5096. }
  5097. }
  5098. self.afterCreate();
  5099. if (self.options.afterCreate) {
  5100. self.options.afterCreate.call(self);
  5101. }
  5102. }
  5103. });
  5104. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5105. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5106. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5107. if (self._fullscreenResizeHandler) {
  5108. K(window).unbind('resize', self._fullscreenResizeHandler);
  5109. self._fullscreenResizeHandler = null;
  5110. }
  5111. function initResize() {
  5112. if (statusbar.height() === 0) {
  5113. setTimeout(initResize, 100);
  5114. return;
  5115. }
  5116. self.resize(width, height, false);
  5117. }
  5118. initResize();
  5119. if (fullscreenMode) {
  5120. self._fullscreenResizeHandler = function(e) {
  5121. if (self.isCreated) {
  5122. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5123. }
  5124. };
  5125. K(window).bind('resize', self._fullscreenResizeHandler);
  5126. toolbar.select('fullscreen');
  5127. statusbar.first().css('visibility', 'hidden');
  5128. statusbar.last().css('visibility', 'hidden');
  5129. } else {
  5130. if (_GECKO) {
  5131. K(window).bind('scroll', function(e) {
  5132. self._scrollPos = _getScrollPos();
  5133. });
  5134. }
  5135. if (self.resizeType > 0) {
  5136. _drag({
  5137. moveEl : container,
  5138. clickEl : statusbar,
  5139. moveFn : function(x, y, width, height, diffX, diffY) {
  5140. height += diffY;
  5141. self.resize(null, height);
  5142. }
  5143. });
  5144. } else {
  5145. statusbar.first().css('visibility', 'hidden');
  5146. }
  5147. if (self.resizeType === 2) {
  5148. _drag({
  5149. moveEl : container,
  5150. clickEl : statusbar.last(),
  5151. moveFn : function(x, y, width, height, diffX, diffY) {
  5152. width += diffX;
  5153. height += diffY;
  5154. self.resize(width, height);
  5155. }
  5156. });
  5157. } else {
  5158. statusbar.last().css('visibility', 'hidden');
  5159. }
  5160. }
  5161. return self;
  5162. },
  5163. remove : function() {
  5164. var self = this;
  5165. if (!self.isCreated) {
  5166. return self;
  5167. }
  5168. self.beforeRemove();
  5169. self.srcElement.data('kindeditor', '');
  5170. if (self.menu) {
  5171. self.hideMenu();
  5172. }
  5173. _each(self.dialogs, function() {
  5174. self.hideDialog();
  5175. });
  5176. K(document).unbind('mousedown', self._docMousedownFn);
  5177. self.toolbar.remove();
  5178. self.edit.remove();
  5179. self.statusbar.last().unbind();
  5180. self.statusbar.unbind();
  5181. self.container.remove();
  5182. self.container = self.toolbar = self.edit = self.menu = null;
  5183. self.dialogs = [];
  5184. self.isCreated = false;
  5185. return self;
  5186. },
  5187. resize : function(width, height, updateProp) {
  5188. var self = this;
  5189. updateProp = _undef(updateProp, true);
  5190. if (width) {
  5191. if (!/%/.test(width)) {
  5192. width = _removeUnit(width);
  5193. width = width < self.minWidth ? self.minWidth : width;
  5194. }
  5195. self.container.css('width', _addUnit(width));
  5196. if (updateProp) {
  5197. self.width = _addUnit(width);
  5198. }
  5199. }
  5200. if (height) {
  5201. height = _removeUnit(height);
  5202. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5203. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5204. self.edit.setHeight(editHeight);
  5205. if (updateProp) {
  5206. self.height = _addUnit(height);
  5207. }
  5208. }
  5209. return self;
  5210. },
  5211. select : function() {
  5212. this.isCreated && this.cmd.select();
  5213. return this;
  5214. },
  5215. html : function(val) {
  5216. var self = this;
  5217. if (val === undefined) {
  5218. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5219. }
  5220. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5221. if (self.isCreated) {
  5222. self.cmd.selection();
  5223. }
  5224. return self;
  5225. },
  5226. fullHtml : function() {
  5227. return this.isCreated ? this.edit.html(undefined, true) : '';
  5228. },
  5229. text : function(val) {
  5230. var self = this;
  5231. if (val === undefined) {
  5232. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5233. } else {
  5234. return self.html(_escape(val));
  5235. }
  5236. },
  5237. isEmpty : function() {
  5238. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5239. },
  5240. isDirty : function() {
  5241. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5242. },
  5243. selectedHtml : function() {
  5244. var val = this.isCreated ? this.cmd.range.html() : '';
  5245. val = _removeBookmarkTag(_removeTempTag(val));
  5246. return val;
  5247. },
  5248. count : function(mode) {
  5249. var self = this;
  5250. mode = (mode || 'html').toLowerCase();
  5251. if (mode === 'html') {
  5252. return self.html().length;
  5253. }
  5254. if (mode === 'text') {
  5255. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5256. }
  5257. return 0;
  5258. },
  5259. exec : function(key) {
  5260. key = key.toLowerCase();
  5261. var self = this, cmd = self.cmd,
  5262. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5263. if (changeFlag) {
  5264. self.addBookmark(false);
  5265. }
  5266. cmd[key].apply(cmd, _toArray(arguments, 1));
  5267. if (changeFlag) {
  5268. self.updateState();
  5269. self.addBookmark(false);
  5270. if (self.options.afterChange) {
  5271. self.options.afterChange.call(self);
  5272. }
  5273. }
  5274. return self;
  5275. },
  5276. insertHtml : function(val, quickMode) {
  5277. if (!this.isCreated) {
  5278. return this;
  5279. }
  5280. val = this.beforeSetHtml(val);
  5281. this.exec('inserthtml', val, quickMode);
  5282. return this;
  5283. },
  5284. appendHtml : function(val) {
  5285. this.html(this.html() + val);
  5286. if (this.isCreated) {
  5287. var cmd = this.cmd;
  5288. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5289. cmd.select();
  5290. }
  5291. return this;
  5292. },
  5293. sync : function() {
  5294. _elementVal(this.srcElement, this.html());
  5295. return this;
  5296. },
  5297. focus : function() {
  5298. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5299. return this;
  5300. },
  5301. blur : function() {
  5302. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5303. return this;
  5304. },
  5305. addBookmark : function(checkSize) {
  5306. checkSize = _undef(checkSize, true);
  5307. var self = this, edit = self.edit,
  5308. body = edit.doc.body,
  5309. html = _removeTempTag(body.innerHTML), bookmark;
  5310. if (checkSize && self._undoStack.length > 0) {
  5311. var prev = self._undoStack[self._undoStack.length - 1];
  5312. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5313. return self;
  5314. }
  5315. }
  5316. if (edit.designMode && !self._firstAddBookmark) {
  5317. var range = self.cmd.range;
  5318. bookmark = range.createBookmark(true);
  5319. bookmark.html = _removeTempTag(body.innerHTML);
  5320. range.moveToBookmark(bookmark);
  5321. } else {
  5322. bookmark = {
  5323. html : html
  5324. };
  5325. }
  5326. self._firstAddBookmark = false;
  5327. _addBookmarkToStack(self._undoStack, bookmark);
  5328. return self;
  5329. },
  5330. undo : function() {
  5331. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5332. },
  5333. redo : function() {
  5334. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5335. },
  5336. fullscreen : function(bool) {
  5337. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5338. this.addBookmark(false);
  5339. return this.remove().create();
  5340. },
  5341. readonly : function(isReadonly) {
  5342. isReadonly = _undef(isReadonly, true);
  5343. var self = this, edit = self.edit, doc = edit.doc;
  5344. if (self.designMode) {
  5345. self.toolbar.disableAll(isReadonly, []);
  5346. } else {
  5347. _each(self.noDisableItems, function() {
  5348. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5349. });
  5350. }
  5351. if (_IE) {
  5352. doc.body.contentEditable = !isReadonly;
  5353. } else {
  5354. doc.designMode = isReadonly ? 'off' : 'on';
  5355. }
  5356. edit.textarea[0].disabled = isReadonly;
  5357. },
  5358. createMenu : function(options) {
  5359. var self = this,
  5360. name = options.name,
  5361. knode = self.toolbar.get(name),
  5362. pos = knode.pos();
  5363. options.x = pos.x;
  5364. options.y = pos.y + knode.height();
  5365. options.z = self.options.zIndex;
  5366. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5367. if (options.selectedColor !== undefined) {
  5368. options.cls = 'ke-colorpicker-' + self.themeType;
  5369. options.noColor = self.lang('noColor');
  5370. self.menu = _colorpicker(options);
  5371. } else {
  5372. options.cls = 'ke-menu-' + self.themeType;
  5373. options.centerLineMode = false;
  5374. self.menu = _menu(options);
  5375. }
  5376. return self.menu;
  5377. },
  5378. hideMenu : function() {
  5379. this.menu.remove();
  5380. this.menu = null;
  5381. return this;
  5382. },
  5383. hideContextmenu : function() {
  5384. this.contextmenu.remove();
  5385. this.contextmenu = null;
  5386. return this;
  5387. },
  5388. createDialog : function(options) {
  5389. var self = this, name = options.name;
  5390. options.z = self.options.zIndex;
  5391. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5392. options.closeBtn = _undef(options.closeBtn, {
  5393. name : self.lang('close'),
  5394. click : function(e) {
  5395. self.hideDialog();
  5396. if (_IE && self.cmd) {
  5397. self.cmd.select();
  5398. }
  5399. }
  5400. });
  5401. options.noBtn = _undef(options.noBtn, {
  5402. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5403. click : function(e) {
  5404. self.hideDialog();
  5405. if (_IE && self.cmd) {
  5406. self.cmd.select();
  5407. }
  5408. }
  5409. });
  5410. if (self.dialogAlignType != 'page') {
  5411. options.alignEl = self.container;
  5412. }
  5413. options.cls = 'ke-dialog-' + self.themeType;
  5414. if (self.dialogs.length > 0) {
  5415. var firstDialog = self.dialogs[0],
  5416. parentDialog = self.dialogs[self.dialogs.length - 1];
  5417. firstDialog.setMaskIndex(parentDialog.z + 2);
  5418. options.z = parentDialog.z + 3;
  5419. options.showMask = false;
  5420. }
  5421. var dialog = _dialog(options);
  5422. self.dialogs.push(dialog);
  5423. return dialog;
  5424. },
  5425. hideDialog : function() {
  5426. var self = this;
  5427. if (self.dialogs.length > 0) {
  5428. self.dialogs.pop().remove();
  5429. }
  5430. if (self.dialogs.length > 0) {
  5431. var firstDialog = self.dialogs[0],
  5432. parentDialog = self.dialogs[self.dialogs.length - 1];
  5433. firstDialog.setMaskIndex(parentDialog.z - 1);
  5434. }
  5435. return self;
  5436. },
  5437. errorDialog : function(html) {
  5438. var self = this;
  5439. var dialog = self.createDialog({
  5440. width : 750,
  5441. title : self.lang('uploadError'),
  5442. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5443. });
  5444. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5445. doc.open();
  5446. doc.write(html);
  5447. doc.close();
  5448. K(doc.body).css('background-color', '#FFF');
  5449. iframe[0].contentWindow.focus();
  5450. return self;
  5451. }
  5452. };
  5453. function _editor(options) {
  5454. return new KEditor(options);
  5455. }
  5456. var _instances = [];
  5457. function _create(expr, options) {
  5458. options = options || {};
  5459. options.basePath = _undef(options.basePath, K.basePath);
  5460. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5461. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5462. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5463. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5464. var themeType = _undef(options.themeType, K.options.themeType);
  5465. _loadStyle(options.themesPath + 'default/default.css');
  5466. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5467. }
  5468. function create(editor) {
  5469. _each(_plugins, function(name, fn) {
  5470. if (_isFunction(fn)) {
  5471. fn.call(editor, KindEditor);
  5472. if (!editor._pluginStatus) {
  5473. editor._pluginStatus = {};
  5474. }
  5475. editor._pluginStatus[name] = 'inited';
  5476. }
  5477. });
  5478. return editor.create();
  5479. }
  5480. var knode = K(expr);
  5481. if (!knode || knode.length === 0) {
  5482. return;
  5483. }
  5484. if (knode.length > 1) {
  5485. knode.each(function() {
  5486. _create(this, options);
  5487. });
  5488. return _instances[0];
  5489. }
  5490. options.srcElement = knode[0];
  5491. var editor = new KEditor(options);
  5492. _instances.push(editor);
  5493. if (_language[editor.langType]) {
  5494. return create(editor);
  5495. }
  5496. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5497. create(editor);
  5498. });
  5499. return editor;
  5500. }
  5501. function _eachEditor(expr, fn) {
  5502. K(expr).each(function(i, el) {
  5503. K.each(_instances, function(j, editor) {
  5504. if (editor && editor.srcElement[0] == el) {
  5505. fn.call(editor, j);
  5506. return false;
  5507. }
  5508. });
  5509. });
  5510. }
  5511. K.remove = function(expr) {
  5512. _eachEditor(expr, function(i) {
  5513. this.remove();
  5514. _instances.splice(i, 1);
  5515. });
  5516. };
  5517. K.sync = function(expr) {
  5518. _eachEditor(expr, function() {
  5519. this.sync();
  5520. });
  5521. };
  5522. K.html = function(expr, val) {
  5523. _eachEditor(expr, function() {
  5524. this.html(val);
  5525. });
  5526. };
  5527. K.insertHtml = function(expr, val) {
  5528. _eachEditor(expr, function() {
  5529. this.insertHtml(val);
  5530. });
  5531. };
  5532. K.appendHtml = function(expr, val) {
  5533. _eachEditor(expr, function() {
  5534. this.appendHtml(val);
  5535. });
  5536. };
  5537. if (_IE && _V < 7) {
  5538. _nativeCommand(document, 'BackgroundImageCache', true);
  5539. }
  5540. K.EditorClass = KEditor;
  5541. K.editor = _editor;
  5542. K.create = _create;
  5543. K.instances = _instances;
  5544. K.plugin = _plugin;
  5545. K.lang = _lang;
  5546. _plugin('core', function(K) {
  5547. var self = this,
  5548. shortcutKeys = {
  5549. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5550. };
  5551. self.afterSetHtml(function() {
  5552. if (self.options.afterChange) {
  5553. self.options.afterChange.call(self);
  5554. }
  5555. });
  5556. self.afterCreate(function() {
  5557. if (self.syncType != 'form') {
  5558. return;
  5559. }
  5560. var el = K(self.srcElement), hasForm = false;
  5561. while ((el = el.parent())) {
  5562. if (el.name == 'form') {
  5563. hasForm = true;
  5564. break;
  5565. }
  5566. }
  5567. if (hasForm) {
  5568. el.bind('submit', function(e) {
  5569. self.sync();
  5570. K(window).bind('unload', function() {
  5571. self.edit.textarea.remove();
  5572. });
  5573. });
  5574. var resetBtn = K('[type="reset"]', el);
  5575. resetBtn.click(function() {
  5576. self.html(self.initContent);
  5577. self.cmd.selection();
  5578. });
  5579. self.beforeRemove(function() {
  5580. el.unbind();
  5581. resetBtn.unbind();
  5582. });
  5583. }
  5584. });
  5585. self.clickToolbar('source', function() {
  5586. if (self.edit.designMode) {
  5587. self.toolbar.disableAll(true);
  5588. self.edit.design(false);
  5589. self.toolbar.select('source');
  5590. } else {
  5591. self.toolbar.disableAll(false);
  5592. self.edit.design(true);
  5593. self.toolbar.unselect('source');
  5594. if (_GECKO) {
  5595. setTimeout(function() {
  5596. self.cmd.selection();
  5597. }, 0);
  5598. } else {
  5599. self.cmd.selection();
  5600. }
  5601. }
  5602. self.designMode = self.edit.designMode;
  5603. });
  5604. self.afterCreate(function() {
  5605. if (!self.designMode) {
  5606. self.toolbar.disableAll(true).select('source');
  5607. }
  5608. });
  5609. self.clickToolbar('fullscreen', function() {
  5610. self.fullscreen();
  5611. });
  5612. if (self.fullscreenShortcut) {
  5613. var loaded = false;
  5614. self.afterCreate(function() {
  5615. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5616. if (e.which == 27) {
  5617. setTimeout(function() {
  5618. self.fullscreen();
  5619. }, 0);
  5620. }
  5621. });
  5622. if (loaded) {
  5623. if (_IE && !self.designMode) {
  5624. return;
  5625. }
  5626. self.focus();
  5627. }
  5628. if (!loaded) {
  5629. loaded = true;
  5630. }
  5631. });
  5632. }
  5633. _each('undo,redo'.split(','), function(i, name) {
  5634. if (shortcutKeys[name]) {
  5635. self.afterCreate(function() {
  5636. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5637. self.clickToolbar(name);
  5638. });
  5639. });
  5640. }
  5641. self.clickToolbar(name, function() {
  5642. self[name]();
  5643. });
  5644. });
  5645. self.clickToolbar('formatblock', function() {
  5646. var blocks = self.lang('formatblock.formatBlock'),
  5647. heights = {
  5648. h1 : 28,
  5649. h2 : 24,
  5650. h3 : 18,
  5651. H4 : 14,
  5652. p : 12
  5653. },
  5654. curVal = self.cmd.val('formatblock'),
  5655. menu = self.createMenu({
  5656. name : 'formatblock',
  5657. width : self.langType == 'en' ? 200 : 150
  5658. });
  5659. _each(blocks, function(key, val) {
  5660. var style = 'font-size:' + heights[key] + 'px;';
  5661. if (key.charAt(0) === 'h') {
  5662. style += 'font-weight:bold;';
  5663. }
  5664. menu.addItem({
  5665. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5666. height : heights[key] + 12,
  5667. checked : (curVal === key || curVal === val),
  5668. click : function() {
  5669. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5670. }
  5671. });
  5672. });
  5673. });
  5674. self.clickToolbar('fontname', function() {
  5675. var curVal = self.cmd.val('fontname'),
  5676. menu = self.createMenu({
  5677. name : 'fontname',
  5678. width : 150
  5679. });
  5680. _each(self.lang('fontname.fontName'), function(key, val) {
  5681. menu.addItem({
  5682. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5683. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5684. click : function() {
  5685. self.exec('fontname', key).hideMenu();
  5686. }
  5687. });
  5688. });
  5689. });
  5690. self.clickToolbar('fontsize', function() {
  5691. var curVal = self.cmd.val('fontsize'),
  5692. menu = self.createMenu({
  5693. name : 'fontsize',
  5694. width : 150
  5695. });
  5696. _each(self.fontSizeTable, function(i, val) {
  5697. menu.addItem({
  5698. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5699. height : _removeUnit(val) + 12,
  5700. checked : curVal === val,
  5701. click : function() {
  5702. self.exec('fontsize', val).hideMenu();
  5703. }
  5704. });
  5705. });
  5706. });
  5707. self.clickToolbar('fontheight', function() {
  5708. var curVal = self.cmd.val('fontheight'),
  5709. menu = self.createMenu({
  5710. name : 'fontsize',
  5711. width : 150
  5712. });
  5713. _each(self.fontHeightTable, function(i, val) {
  5714. menu.addItem({
  5715. title : '<span unselectable="on">' + val + '</span>',
  5716. height : 20,
  5717. checked : curVal === val,
  5718. click : function() {
  5719. self.exec('fontheight', val).hideMenu();
  5720. }
  5721. });
  5722. });
  5723. });
  5724. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5725. self.clickToolbar(name, function() {
  5726. self.createMenu({
  5727. name : name,
  5728. selectedColor : self.cmd.val(name) || 'default',
  5729. colors : self.colorTable,
  5730. click : function(color) {
  5731. self.exec(name, color).hideMenu();
  5732. }
  5733. });
  5734. });
  5735. });
  5736. _each(('cut,copy,paste').split(','), function(i, name) {
  5737. self.clickToolbar(name, function() {
  5738. self.focus();
  5739. try {
  5740. self.exec(name, null);
  5741. } catch(e) {
  5742. alert(self.lang(name + 'Error'));
  5743. }
  5744. });
  5745. });
  5746. self.clickToolbar('about', function() {
  5747. var html = '<div style="margin:20px;">' +
  5748. '<div>KindEditor ' + _VERSION + '</div>' +
  5749. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5750. '</div>';
  5751. self.createDialog({
  5752. name : 'about',
  5753. width : 350,
  5754. title : self.lang('about'),
  5755. body : html
  5756. });
  5757. });
  5758. self.plugin.getSelectedLink = function() {
  5759. return self.cmd.commonAncestor('a');
  5760. };
  5761. self.plugin.getSelectedImage = function() {
  5762. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5763. return !/^ke-\w+$/i.test(img[0].className);
  5764. });
  5765. };
  5766. self.plugin.getSelectedFlash = function() {
  5767. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5768. return img[0].className == 'ke-flash';
  5769. });
  5770. };
  5771. self.plugin.getSelectedMedia = function() {
  5772. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5773. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5774. });
  5775. };
  5776. self.plugin.getSelectedAnchor = function() {
  5777. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5778. return img[0].className == 'ke-anchor';
  5779. });
  5780. };
  5781. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5782. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5783. _each('edit,delete'.split(','), function(j, val) {
  5784. self.addContextmenu({
  5785. title : self.lang(val + uName),
  5786. click : function() {
  5787. self.loadPlugin(name, function() {
  5788. self.plugin[name][val]();
  5789. self.hideMenu();
  5790. });
  5791. },
  5792. cond : self.plugin['getSelected' + uName],
  5793. width : 150,
  5794. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5795. });
  5796. });
  5797. self.addContextmenu({ title : '-' });
  5798. });
  5799. self.plugin.getSelectedTable = function() {
  5800. return self.cmd.commonAncestor('table');
  5801. };
  5802. self.plugin.getSelectedRow = function() {
  5803. return self.cmd.commonAncestor('tr');
  5804. };
  5805. self.plugin.getSelectedCell = function() {
  5806. return self.cmd.commonAncestor('td');
  5807. };
  5808. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5809. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5810. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5811. self.addContextmenu({
  5812. title : self.lang('table' + val),
  5813. click : function() {
  5814. self.loadPlugin('table', function() {
  5815. self.plugin.table[val]();
  5816. self.hideMenu();
  5817. });
  5818. },
  5819. cond : cond,
  5820. width : 170,
  5821. iconClass : 'ke-icon-table' + val
  5822. });
  5823. });
  5824. self.addContextmenu({ title : '-' });
  5825. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5826. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5827. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5828. if (shortcutKeys[name]) {
  5829. self.afterCreate(function() {
  5830. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5831. self.cmd.selection();
  5832. self.clickToolbar(name);
  5833. });
  5834. });
  5835. }
  5836. self.clickToolbar(name, function() {
  5837. self.focus().exec(name, null);
  5838. });
  5839. });
  5840. self.afterCreate(function() {
  5841. var doc = self.edit.doc, cmd, bookmark, div,
  5842. cls = '__kindeditor_paste__', pasting = false;
  5843. function movePastedData() {
  5844. cmd.range.moveToBookmark(bookmark);
  5845. cmd.select();
  5846. if (_WEBKIT) {
  5847. K('div.' + cls, div).each(function() {
  5848. K(this).after('<br />').remove(true);
  5849. });
  5850. K('span.Apple-style-span', div).remove(true);
  5851. K('span.Apple-tab-span', div).remove(true);
  5852. K('span[style]', div).each(function() {
  5853. if (K(this).css('white-space') == 'nowrap') {
  5854. K(this).remove(true);
  5855. }
  5856. });
  5857. K('meta', div).remove();
  5858. }
  5859. var html = div[0].innerHTML;
  5860. div.remove();
  5861. if (html === '') {
  5862. return;
  5863. }
  5864. if (_WEBKIT) {
  5865. html = html.replace(/(<br>)\1/ig, '$1');
  5866. }
  5867. if (self.pasteType === 2) {
  5868. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5869. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5870. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5871. } else {
  5872. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5873. html = self.beforeSetHtml(html);
  5874. }
  5875. }
  5876. if (self.pasteType === 1) {
  5877. html = html.replace(/&nbsp;/ig, ' ');
  5878. html = html.replace(/\n\s*\n/g, '\n');
  5879. html = html.replace(/<br[^>]*>/ig, '\n');
  5880. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5881. html = html.replace(/<[^>]+>/g, '');
  5882. html = html.replace(/ {2}/g, ' &nbsp;');
  5883. if (self.newlineTag == 'p') {
  5884. if (/\n/.test(html)) {
  5885. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5886. }
  5887. } else {
  5888. html = html.replace(/\n/g, '<br />$&');
  5889. }
  5890. }
  5891. self.insertHtml(html, true);
  5892. autoImg(self);
  5893. }
  5894. K(doc.body).bind('paste', function(e){
  5895. //处理IE11,Chrome粘贴图片上传
  5896. function dopasteImg() {
  5897. //debugger;
  5898. var file = null;
  5899. if (window.clipboardData) {//ie
  5900. if (clipboardData.files && clipboardData.files.length)//IE11
  5901. file = clipboardData.files[0];
  5902. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5903. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5904. return true;
  5905. }
  5906. } else {
  5907. if (e.event.clipboardData.items)//chrome
  5908. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5909. if (e.event.clipboardData.items[i].kind === "file") {
  5910. file = e.event.clipboardData.items[i];
  5911. break;
  5912. }
  5913. }
  5914. if (file == null) {
  5915. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5916. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5917. return true;
  5918. }
  5919. }
  5920. }
  5921. if (file) {
  5922. if (!K.undef(self.allowImageUpload, true)) {
  5923. alert("编辑器禁止上传图片,请与有关人员联系!");
  5924. return true;
  5925. }
  5926. //获取File Blob
  5927. //debugger;
  5928. var blb;
  5929. if (file.getAsFile) {//Chrome
  5930. blb = file.getAsFile();
  5931. if (blb.size === 0) {
  5932. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5933. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5934. return true;
  5935. }
  5936. sendfile(blb, file.type);
  5937. } else {
  5938. var fr = new FileReader();
  5939. if (fr.readAsArrayBuffer) {//ie
  5940. fr.onloadend = function (evt) {
  5941. blb = evt.target.result;
  5942. sendfile(blb, file.type);
  5943. }
  5944. fr.readAsArrayBuffer(file);
  5945. }
  5946. }
  5947. function sendfile(b, t) {
  5948. var xhr = new XMLHttpRequest();
  5949. var formData = new FormData();
  5950. var isImg = t.indexOf("image/") === 0;
  5951. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5952. //formData.append('imgFile', b);
  5953. var myBlob = new Blob([b], { "type": t });
  5954. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5955. //formData.append('imgFile', b);
  5956. formData.append('dir', isImg ? 'image' : 'file');
  5957. if (self.uploadYunJson && self.uploadYunJson.domain) {
  5958. formData.append('token', self.uploadYunJson.token);
  5959. xhr.open('POST', self.uploadYunJson.domain);
  5960. } else {
  5961. xhr.open('POST', self.uploadJson);
  5962. }
  5963. xhr.onreadystatechange = function () {
  5964. if (xhr.readyState == 4&&xhr.status == 200) {
  5965. // if (fn) {
  5966. var data = _trim(xhr.responseText);
  5967. //if (dataType == 'json') {
  5968. data = _json(data);
  5969. if (data.error) {
  5970. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5971. $.messager.alert('Error', data.message, 'warning');
  5972. } else {
  5973. alert(data.message);
  5974. }
  5975. } else {
  5976. //self.exec('insertimage', url, title, width, height, border, align);
  5977. if(K.undef(self.formatUploadUrl, true))
  5978. data.url =K.formatUrl(data.url, 'absolute');
  5979. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5980. }
  5981. //}
  5982. // fn(data);
  5983. // }
  5984. }
  5985. }
  5986. xhr.send(formData);
  5987. }
  5988. return true;
  5989. }
  5990. }
  5991. //debugger;
  5992. if (dopasteImg())
  5993. e.stop();
  5994. //处理粘贴结束5825
  5995. if (self.pasteType === 0) {
  5996. e.stop();
  5997. return;
  5998. }
  5999. if (pasting) {
  6000. return;
  6001. }
  6002. pasting = true;
  6003. K('div.' + cls, doc).remove();
  6004. cmd = self.cmd.selection();
  6005. bookmark = cmd.range.createBookmark();
  6006. div = K('<div class="' + cls + '"></div>', doc).css({
  6007. position : 'absolute',
  6008. width : '1px',
  6009. height : '1px',
  6010. overflow : 'hidden',
  6011. left : '-1981px',
  6012. top : K(bookmark.start).pos().y + 'px',
  6013. 'white-space' : 'nowrap'
  6014. });
  6015. K(doc.body).append(div);
  6016. if (_IE) {
  6017. var rng = cmd.range.get(true);
  6018. rng.moveToElementText(div[0]);
  6019. rng.select();
  6020. rng.execCommand('paste');
  6021. e.preventDefault();
  6022. } else {
  6023. cmd.range.selectNodeContents(div[0]);
  6024. cmd.select();
  6025. div[0].tabIndex = -1;
  6026. div[0].focus();
  6027. }
  6028. setTimeout(function() {
  6029. movePastedData();
  6030. pasting = false;
  6031. }, 0);
  6032. });
  6033. });
  6034. self.beforeGetHtml(function(html) {
  6035. if (_IE && _V <= 8) {
  6036. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  6037. return unescape(tag);
  6038. });
  6039. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  6040. if (!/\s+type="[^"]+"/i.test($0)) {
  6041. return $1 + ' type="text"' + $2;
  6042. }
  6043. return $0;
  6044. });
  6045. }
  6046. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  6047. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  6048. })
  6049. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  6050. var imgAttrs = _getAttrList(full);
  6051. var styles = _getCssList(imgAttrs.style || '');
  6052. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6053. var width = _undef(styles.width, '');
  6054. var height = _undef(styles.height, '');
  6055. if (/px/i.test(width)) {
  6056. width = _removeUnit(width);
  6057. }
  6058. if (/px/i.test(height)) {
  6059. height = _removeUnit(height);
  6060. }
  6061. attrs.width = _undef(imgAttrs.width, width);
  6062. attrs.height = _undef(imgAttrs.height, height);
  6063. return _mediaEmbed(attrs);
  6064. })
  6065. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6066. var imgAttrs = _getAttrList(full);
  6067. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6068. })
  6069. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6070. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6071. })
  6072. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6073. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6074. })
  6075. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6076. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6077. return $1 + _unescape(src) + $2;
  6078. });
  6079. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6080. return full;
  6081. })
  6082. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6083. return start + end;
  6084. });
  6085. });
  6086. self.beforeSetHtml(function(html) {
  6087. if (_IE && _V <= 8) {
  6088. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6089. var attrs = _getAttrList(full);
  6090. var styles = _getCssList(attrs.style || '');
  6091. if (styles.display == 'none') {
  6092. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6093. }
  6094. return full;
  6095. });
  6096. }
  6097. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6098. var attrs = _getAttrList(full);
  6099. attrs.src = _undef(attrs.src, '');
  6100. attrs.width = _undef(attrs.width, 0);
  6101. attrs.height = _undef(attrs.height, 0);
  6102. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6103. })
  6104. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6105. var attrs = _getAttrList(full);
  6106. if (attrs.href !== undefined) {
  6107. return full;
  6108. }
  6109. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6110. })
  6111. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6112. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6113. })
  6114. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6115. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6116. })
  6117. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6118. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6119. return full;
  6120. }
  6121. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6122. return full;
  6123. })
  6124. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6125. return start + 'data-ke-' + end;
  6126. })
  6127. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6128. if (full.indexOf('ke-zeroborder') >= 0) {
  6129. return full;
  6130. }
  6131. return _addClassToTag(full, 'ke-zeroborder');
  6132. });
  6133. });
  6134. });
  6135. })(window);
  6136. /*******************************************************************************
  6137. * KindEditor - WYSIWYG HTML Editor for Internet
  6138. * Copyright (C) 2006-2011 kindsoft.net
  6139. *
  6140. * @author Roddy <luolonghao@gmail.com>
  6141. * @site http://www.kindsoft.net/
  6142. * @licence http://www.kindsoft.net/license.php
  6143. *******************************************************************************/
  6144. KindEditor.lang({
  6145. source : 'HTML代码',
  6146. preview : '预览',
  6147. undo : '后退(Ctrl+Z)',
  6148. redo : '前进(Ctrl+Y)',
  6149. cut : '剪切(Ctrl+X)',
  6150. copy : '复制(Ctrl+C)',
  6151. paste : '粘贴(Ctrl+V)',
  6152. plainpaste : '粘贴为无格式文本',
  6153. wordpaste : '从Word粘贴',
  6154. selectall : '全选(Ctrl+A)',
  6155. justifyleft : '左对齐',
  6156. justifycenter : '居中',
  6157. justifyright : '右对齐',
  6158. justifyfull : '两端对齐',
  6159. insertorderedlist : '编号',
  6160. insertunorderedlist : '项目符号',
  6161. indent : '增加缩进',
  6162. outdent : '减少缩进',
  6163. subscript : '下标',
  6164. superscript : '上标',
  6165. formatblock : '段落',
  6166. fontname : '字体',
  6167. fontsize : '文字大小',
  6168. fontheight : '文字间距',
  6169. forecolor : '文字颜色',
  6170. hilitecolor : '文字背景',
  6171. bold : '粗体(Ctrl+B)',
  6172. italic : '斜体(Ctrl+I)',
  6173. underline : '下划线(Ctrl+U)',
  6174. strikethrough : '删除线',
  6175. removeformat : '删除格式',
  6176. image : '图片',
  6177. multiimage : '批量图片上传',
  6178. flash : 'Flash',
  6179. media : '音视频',
  6180. table : '表格',
  6181. tablecell : '单元格',
  6182. hr : '插入横线',
  6183. emoticons : '插入表情',
  6184. link : '超级链接',
  6185. unlink : '取消超级链接',
  6186. fullscreen : '全屏显示',
  6187. about : '关于',
  6188. print : '打印(Ctrl+P)',
  6189. filemanager : '文件库',
  6190. code : '插入程序代码',
  6191. map : 'Google地图',
  6192. baidumap : '百度地图',
  6193. lineheight : '行距',
  6194. clearhtml : '清理HTML代码',
  6195. pagebreak : '插入分页符',
  6196. quickformat : '一键排版',
  6197. insertfile : '插入文件',
  6198. template : '插入模板',
  6199. anchor : '锚点',
  6200. yes : '确定',
  6201. no : '取消',
  6202. close : '关闭',
  6203. editImage : '图片属性',
  6204. deleteImage : '删除图片',
  6205. editFlash : 'Flash属性',
  6206. deleteFlash : '删除Flash',
  6207. editMedia : '音视频属性',
  6208. deleteMedia : '删除音视频',
  6209. editLink : '超级链接属性',
  6210. deleteLink : '取消超级链接',
  6211. editAnchor : '锚点属性',
  6212. deleteAnchor : '删除锚点',
  6213. tableprop : '表格属性',
  6214. tablecellprop : '单元格属性',
  6215. tableinsert : '插入表格',
  6216. tabledelete : '删除表格',
  6217. tablecolinsertleft : '左侧插入列',
  6218. tablecolinsertright : '右侧插入列',
  6219. tablerowinsertabove : '上方插入行',
  6220. tablerowinsertbelow : '下方插入行',
  6221. tablerowmerge : '向下合并单元格',
  6222. tablecolmerge : '向右合并单元格',
  6223. tablerowsplit : '拆分行',
  6224. tablecolsplit : '拆分列',
  6225. tablecoldelete : '删除列',
  6226. tablerowdelete : '删除行',
  6227. noColor : '无颜色',
  6228. pleaseSelectFile : '请选择文件。',
  6229. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6230. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6231. invalidWidth : "宽度必须为数字。",
  6232. invalidHeight : "高度必须为数字。",
  6233. invalidBorder : "边框必须为数字。",
  6234. invalidUrl : "请输入有效的URL地址。",
  6235. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6236. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6237. invalidPadding : '边距必须为数字。',
  6238. invalidSpacing : '间距必须为数字。',
  6239. invalidJson : '服务器发生故障。',
  6240. uploadSuccess : '上传成功。',
  6241. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6242. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6243. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6244. ajaxLoading : '加载中,请稍候 ...',
  6245. uploadLoading : '上传中,请稍候 ...',
  6246. uploadError : '上传错误',
  6247. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6248. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6249. 'code.pleaseInput' : '请输入程序代码。',
  6250. 'link.url' : 'URL',
  6251. 'link.linkType' : '打开类型',
  6252. 'link.newWindow' : '新窗口',
  6253. 'link.selfWindow' : '当前窗口',
  6254. 'flash.url' : 'URL',
  6255. 'flash.width' : '宽度',
  6256. 'flash.height' : '高度',
  6257. 'flash.upload' : '上传',
  6258. 'flash.viewServer' : '文件空间',
  6259. 'media.url' : 'URL',
  6260. 'media.width' : '宽度',
  6261. 'media.height' : '高度',
  6262. 'media.autostart' : '自动播放',
  6263. 'media.upload' : '上传',
  6264. 'media.viewServer' : '文件空间',
  6265. 'image.remoteImage' : '网络图片',
  6266. 'image.localImage' : '本地上传',
  6267. 'image.remoteUrl' : '图片地址',
  6268. 'image.localUrl' : '上传文件',
  6269. 'image.size' : '图片大小',
  6270. 'image.width' : '宽',
  6271. 'image.height' : '高',
  6272. 'image.resetSize' : '重置大小',
  6273. 'image.align' : '对齐方式',
  6274. 'image.defaultAlign' : '默认方式',
  6275. 'image.leftAlign' : '左对齐',
  6276. 'image.rightAlign' : '右对齐',
  6277. 'image.imgTitle' : '图片说明',
  6278. 'image.upload' : '浏览...',
  6279. 'image.viewServer' : '图片空间',
  6280. //'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6281. 'multiimage.uploadDesc' : '',
  6282. 'multiimage.startUpload' : '开始上传',
  6283. 'multiimage.clearAll' : '全部清空',
  6284. 'multiimage.insertAll' : '全部插入',
  6285. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6286. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6287. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6288. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6289. 'multiimage.unknownError' : '发生异常,无法上传。',
  6290. 'multiimage.pending' : '等待上传',
  6291. 'multiimage.uploadError' : '上传失败',
  6292. 'filemanager.emptyFolder' : '空文件夹',
  6293. 'filemanager.moveup' : '移到上一级文件夹',
  6294. 'filemanager.viewType' : '显示方式:',
  6295. 'filemanager.viewImage' : '缩略图',
  6296. 'filemanager.listImage' : '详细信息',
  6297. 'filemanager.orderType' : '排序方式:',
  6298. 'filemanager.fileName' : '名称',
  6299. 'filemanager.fileSize' : '大小',
  6300. 'filemanager.fileType' : '类型',
  6301. 'insertfile.url' : 'URL',
  6302. 'insertfile.title' : '文件说明',
  6303. 'insertfile.upload' : '上传',
  6304. 'insertfile.viewServer' : '文件空间',
  6305. 'table.cells' : '单元格数',
  6306. 'table.rows' : '行数',
  6307. 'table.cols' : '列数',
  6308. 'table.size' : '大小',
  6309. 'table.width' : '宽度',
  6310. 'table.height' : '高度',
  6311. 'table.percent' : '%',
  6312. 'table.px' : 'px',
  6313. 'table.space' : '边距间距',
  6314. 'table.padding' : '边距',
  6315. 'table.spacing' : '间距',
  6316. 'table.align' : '对齐方式',
  6317. 'table.textAlign' : '水平对齐',
  6318. 'table.verticalAlign' : '垂直对齐',
  6319. 'table.alignDefault' : '默认',
  6320. 'table.alignLeft' : '左对齐',
  6321. 'table.alignCenter' : '居中',
  6322. 'table.alignRight' : '右对齐',
  6323. 'table.alignTop' : '顶部',
  6324. 'table.alignMiddle' : '中部',
  6325. 'table.alignBottom' : '底部',
  6326. 'table.alignBaseline' : '基线',
  6327. 'table.border' : '边框',
  6328. 'table.borderWidth' : '边框',
  6329. 'table.borderColor' : '颜色',
  6330. 'table.backgroundColor' : '背景颜色',
  6331. 'map.address' : '地址: ',
  6332. 'map.search' : '搜索',
  6333. 'baidumap.address' : '地址: ',
  6334. 'baidumap.search' : '搜索',
  6335. 'baidumap.insertDynamicMap' : '插入动态地图',
  6336. 'anchor.name' : '锚点名称',
  6337. 'formatblock.formatBlock' : {
  6338. h1 : '标题 1',
  6339. h2 : '标题 2',
  6340. h3 : '标题 3',
  6341. h4 : '标题 4',
  6342. p : '正 文'
  6343. },
  6344. 'fontname.fontName' : {
  6345. 'SimSun' : '宋体',
  6346. 'NSimSun' : '新宋体',
  6347. 'FangSong_GB2312' : '仿宋_GB2312',
  6348. 'KaiTi_GB2312' : '楷体_GB2312',
  6349. 'SimHei' : '黑体',
  6350. 'Microsoft YaHei' : '微软雅黑',
  6351. 'Arial' : 'Arial',
  6352. 'Arial Black' : 'Arial Black',
  6353. 'Times New Roman' : 'Times New Roman',
  6354. 'Courier New' : 'Courier New',
  6355. 'Tahoma' : 'Tahoma',
  6356. 'Verdana' : 'Verdana'
  6357. },
  6358. 'lineheight.lineHeight' : [
  6359. {'1' : '单倍行距'},
  6360. {'1.5' : '1.5倍行距'},
  6361. {'1.75' : '1.75倍行距'},
  6362. {'2' : '2倍行距'},
  6363. {'2.5' : '2.5倍行距'},
  6364. {'3' : '3倍行距'}
  6365. ],
  6366. 'template.selectTemplate' : '可选模板',
  6367. 'template.replaceContent' : '替换当前内容',
  6368. 'template.fileList' : {
  6369. '1.html' : '图片和文字',
  6370. '2.html' : '表格',
  6371. '3.html' : '项目编号'
  6372. }
  6373. }, 'zh-CN');
  6374. KindEditor.options.langType = 'zh-CN';
  6375. /*******************************************************************************
  6376. * KindEditor - WYSIWYG HTML Editor for Internet
  6377. * Copyright (C) 2006-2011 kindsoft.net
  6378. *
  6379. * @author Roddy <luolonghao@gmail.com>
  6380. * @site http://www.kindsoft.net/
  6381. * @licence http://www.kindsoft.net/license.php
  6382. *******************************************************************************/
  6383. KindEditor.plugin('anchor', function(K) {
  6384. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6385. self.plugin.anchor = {
  6386. edit : function() {
  6387. var html = ['<div style="padding:20px;">',
  6388. '<div class="ke-dialog-row">',
  6389. '<label for="keName">' + lang.name + '</label>',
  6390. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6391. '</div>',
  6392. '</div>'].join('');
  6393. var dialog = self.createDialog({
  6394. name : name,
  6395. width : 300,
  6396. title : self.lang(name),
  6397. body : html,
  6398. yesBtn : {
  6399. name : self.lang('yes'),
  6400. click : function(e) {
  6401. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6402. }
  6403. }
  6404. });
  6405. var div = dialog.div,
  6406. nameBox = K('input[name="name"]', div);
  6407. var img = self.plugin.getSelectedAnchor();
  6408. if (img) {
  6409. nameBox.val(unescape(img.attr('data-ke-name')));
  6410. }
  6411. nameBox[0].focus();
  6412. nameBox[0].select();
  6413. },
  6414. 'delete' : function() {
  6415. self.plugin.getSelectedAnchor().remove();
  6416. }
  6417. };
  6418. self.clickToolbar(name, self.plugin.anchor.edit);
  6419. });
  6420. /*******************************************************************************
  6421. * KindEditor - WYSIWYG HTML Editor for Internet
  6422. * Copyright (C) 2006-2011 kindsoft.net
  6423. *
  6424. * @author Roddy <luolonghao@gmail.com>
  6425. * @site http://www.kindsoft.net/
  6426. * @licence http://www.kindsoft.net/license.php
  6427. *******************************************************************************/
  6428. KindEditor.plugin('autoheight', function(K) {
  6429. var self = this;
  6430. if (!self.autoHeightMode) {
  6431. return;
  6432. }
  6433. var minHeight;
  6434. function hideScroll() {
  6435. var edit = self.edit;
  6436. var body = edit.doc.body;
  6437. edit.iframe[0].scroll = 'no';
  6438. body.style.overflowY = 'hidden';
  6439. }
  6440. function resetHeight() {
  6441. if(self.fullscreenMode){
  6442. return;
  6443. }
  6444. var edit = self.edit;
  6445. var body = edit.doc.body;
  6446. edit.iframe.height(minHeight);
  6447. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6448. }
  6449. function init() {
  6450. minHeight = K.removeUnit(self.height);
  6451. self.edit.afterChange(resetHeight);
  6452. if(!self.fullscreenMode){
  6453. hideScroll();
  6454. }
  6455. resetHeight();
  6456. }
  6457. if (self.isCreated) {
  6458. init();
  6459. } else {
  6460. self.afterCreate(init);
  6461. }
  6462. });
  6463. /*
  6464. * 如何实现真正的自动高度?
  6465. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6466. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6467. * 由此就实现了真正的自动高度
  6468. * 测试:chrome、firefox、IE9、IE8
  6469. * */
  6470. /*******************************************************************************
  6471. * KindEditor - WYSIWYG HTML Editor for Internet
  6472. * Copyright (C) 2006-2011 kindsoft.net
  6473. *
  6474. * @author Roddy <luolonghao@gmail.com>
  6475. * @site http://www.kindsoft.net/
  6476. * @licence http://www.kindsoft.net/license.php
  6477. *******************************************************************************/
  6478. KindEditor.plugin('baidumap', function(K) {
  6479. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6480. var mapWidth = K.undef(self.mapWidth, 558);
  6481. var mapHeight = K.undef(self.mapHeight, 360);
  6482. self.clickToolbar(name, function() {
  6483. var html = ['<div style="padding:10px 20px;">',
  6484. '<div class="ke-header">',
  6485. '<div class="ke-left">',
  6486. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6487. '<span class="ke-button-common ke-button-outer">',
  6488. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6489. '</span>',
  6490. '</div>',
  6491. '<div class="ke-right">',
  6492. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6493. '</div>',
  6494. '<div class="ke-clearfix"></div>',
  6495. '</div>',
  6496. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6497. '</div>'].join('');
  6498. var dialog = self.createDialog({
  6499. name : name,
  6500. width : mapWidth + 42,
  6501. title : self.lang(name),
  6502. body : html,
  6503. yesBtn : {
  6504. name : self.lang('yes'),
  6505. click : function(e) {
  6506. var map = win.map;
  6507. var centerObj = map.getCenter();
  6508. var center = centerObj.lng + ',' + centerObj.lat;
  6509. var zoom = map.getZoom();
  6510. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6511. '?center=' + encodeURIComponent(center),
  6512. '&zoom=' + encodeURIComponent(zoom),
  6513. '&width=' + mapWidth,
  6514. '&height=' + mapHeight,
  6515. '&markers=' + encodeURIComponent(center),
  6516. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6517. if (checkbox[0].checked) {
  6518. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6519. } else {
  6520. self.exec('insertimage', url);
  6521. }
  6522. self.hideDialog().focus();
  6523. }
  6524. },
  6525. beforeRemove : function() {
  6526. searchBtn.remove();
  6527. if (doc) {
  6528. doc.write('');
  6529. }
  6530. iframe.remove();
  6531. }
  6532. });
  6533. var div = dialog.div,
  6534. addressBox = K('[name="address"]', div),
  6535. searchBtn = K('[name="searchBtn"]', div),
  6536. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6537. win, doc;
  6538. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6539. function ready() {
  6540. win = iframe[0].contentWindow;
  6541. doc = K.iframeDoc(iframe);
  6542. }
  6543. iframe.bind('load', function() {
  6544. iframe.unbind('load');
  6545. if (K.IE) {
  6546. ready();
  6547. } else {
  6548. setTimeout(ready, 0);
  6549. }
  6550. });
  6551. K('.ke-map', div).replaceWith(iframe);
  6552. searchBtn.click(function() {
  6553. win.search(addressBox.val());
  6554. });
  6555. });
  6556. });
  6557. /*******************************************************************************
  6558. * KindEditor - WYSIWYG HTML Editor for Internet
  6559. * Copyright (C) 2006-2011 kindsoft.net
  6560. *
  6561. * @author Roddy <luolonghao@gmail.com>
  6562. * @site http://www.kindsoft.net/
  6563. * @licence http://www.kindsoft.net/license.php
  6564. *******************************************************************************/
  6565. KindEditor.plugin('map', function(K) {
  6566. var self = this, name = 'map', lang = self.lang(name + '.');
  6567. self.clickToolbar(name, function() {
  6568. var html = ['<div style="padding:10px 20px;">',
  6569. '<div class="ke-dialog-row">',
  6570. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6571. '<span class="ke-button-common ke-button-outer">',
  6572. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6573. '</span>',
  6574. '</div>',
  6575. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6576. '</div>'].join('');
  6577. var dialog = self.createDialog({
  6578. name : name,
  6579. width : 600,
  6580. title : self.lang(name),
  6581. body : html,
  6582. yesBtn : {
  6583. name : self.lang('yes'),
  6584. click : function(e) {
  6585. var geocoder = win.geocoder,
  6586. map = win.map,
  6587. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6588. zoom = map.getZoom(),
  6589. maptype = map.getMapTypeId(),
  6590. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6591. url += '?center=' + encodeURIComponent(center);
  6592. url += '&zoom=' + encodeURIComponent(zoom);
  6593. url += '&size=558x360';
  6594. url += '&maptype=' + encodeURIComponent(maptype);
  6595. url += '&markers=' + encodeURIComponent(center);
  6596. url += '&language=' + self.langType;
  6597. url += '&sensor=false';
  6598. self.exec('insertimage', url).hideDialog().focus();
  6599. }
  6600. },
  6601. beforeRemove : function() {
  6602. searchBtn.remove();
  6603. if (doc) {
  6604. doc.write('');
  6605. }
  6606. iframe.remove();
  6607. }
  6608. });
  6609. var div = dialog.div,
  6610. addressBox = K('[name="address"]', div),
  6611. searchBtn = K('[name="searchBtn"]', div),
  6612. win, doc;
  6613. var iframeHtml = ['<!doctype html><html><head>',
  6614. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6615. '<style>',
  6616. ' html { height: 100% }',
  6617. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6618. ' #map_canvas { height: 100% }',
  6619. '</style>',
  6620. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6621. '<script>',
  6622. 'var map, geocoder;',
  6623. 'function initialize() {',
  6624. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6625. ' var options = {',
  6626. ' zoom: 11,',
  6627. ' center: latlng,',
  6628. ' disableDefaultUI: true,',
  6629. ' panControl: true,',
  6630. ' zoomControl: true,',
  6631. ' mapTypeControl: true,',
  6632. ' scaleControl: true,',
  6633. ' streetViewControl: false,',
  6634. ' overviewMapControl: true,',
  6635. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6636. ' };',
  6637. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6638. ' geocoder = new google.maps.Geocoder();',
  6639. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6640. ' if (status == google.maps.GeocoderStatus.OK) {',
  6641. ' if (results[3]) {',
  6642. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6643. ' }',
  6644. ' }',
  6645. ' });',
  6646. '}',
  6647. 'function search(address) {',
  6648. ' if (!map) return;',
  6649. ' geocoder.geocode({address : address}, function(results, status) {',
  6650. ' if (status == google.maps.GeocoderStatus.OK) {',
  6651. ' map.setZoom(11);',
  6652. ' map.setCenter(results[0].geometry.location);',
  6653. ' var marker = new google.maps.Marker({',
  6654. ' map: map,',
  6655. ' position: results[0].geometry.location',
  6656. ' });',
  6657. ' } else {',
  6658. ' alert("Invalid address: " + address);',
  6659. ' }',
  6660. ' });',
  6661. '}',
  6662. '</script>',
  6663. '</head>',
  6664. '<body onload="initialize();">',
  6665. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6666. '</body></html>'].join('\n');
  6667. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6668. function ready() {
  6669. win = iframe[0].contentWindow;
  6670. doc = K.iframeDoc(iframe);
  6671. }
  6672. iframe.bind('load', function() {
  6673. iframe.unbind('load');
  6674. if (K.IE) {
  6675. ready();
  6676. } else {
  6677. setTimeout(ready, 0);
  6678. }
  6679. });
  6680. K('.ke-map', div).replaceWith(iframe);
  6681. searchBtn.click(function() {
  6682. win.search(addressBox.val());
  6683. });
  6684. });
  6685. });
  6686. /*******************************************************************************
  6687. * KindEditor - WYSIWYG HTML Editor for Internet
  6688. * Copyright (C) 2006-2011 kindsoft.net
  6689. *
  6690. * @author Roddy <luolonghao@gmail.com>
  6691. * @site http://www.kindsoft.net/
  6692. * @licence http://www.kindsoft.net/license.php
  6693. *******************************************************************************/
  6694. KindEditor.plugin('clearhtml', function(K) {
  6695. var self = this, name = 'clearhtml';
  6696. self.clickToolbar(name, function() {
  6697. self.focus();
  6698. var html = self.html();
  6699. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6700. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6701. html = K.formatHtml(html, {
  6702. a : ['href', 'target'],
  6703. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6704. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6705. table : ['border'],
  6706. 'td,th' : ['rowspan', 'colspan'],
  6707. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6708. });
  6709. self.html(html);
  6710. self.cmd.selection(true);
  6711. self.addBookmark();
  6712. });
  6713. });
  6714. /*******************************************************************************
  6715. * KindEditor - WYSIWYG HTML Editor for Internet
  6716. * Copyright (C) 2006-2011 kindsoft.net
  6717. *
  6718. * @author Roddy <luolonghao@gmail.com>
  6719. * @site http://www.kindsoft.net/
  6720. * @licence http://www.kindsoft.net/license.php
  6721. *******************************************************************************/
  6722. KindEditor.plugin('code', function(K) {
  6723. var self = this, name = 'code';
  6724. self.clickToolbar(name, function() {
  6725. var lang = self.lang(name + '.'),
  6726. html = ['<div style="padding:10px 20px;">',
  6727. '<div class="ke-dialog-row">',
  6728. '<select class="ke-code-type">',
  6729. '<option value="js">JavaScript</option>',
  6730. '<option value="html">HTML</option>',
  6731. '<option value="css">CSS</option>',
  6732. '<option value="php">PHP</option>',
  6733. '<option value="pl">Perl</option>',
  6734. '<option value="py">Python</option>',
  6735. '<option value="rb">Ruby</option>',
  6736. '<option value="java">Java</option>',
  6737. '<option value="vb">ASP/VB</option>',
  6738. '<option value="cpp">C/C++</option>',
  6739. '<option value="cs">C#</option>',
  6740. '<option value="xml">XML</option>',
  6741. '<option value="bsh">Shell</option>',
  6742. '<option value="">Other</option>',
  6743. '</select>',
  6744. '</div>',
  6745. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6746. '</div>'].join(''),
  6747. dialog = self.createDialog({
  6748. name : name,
  6749. width : 450,
  6750. title : self.lang(name),
  6751. body : html,
  6752. yesBtn : {
  6753. name : self.lang('yes'),
  6754. click : function(e) {
  6755. var type = K('.ke-code-type', dialog.div).val(),
  6756. code = textarea.val(),
  6757. cls = type === '' ? '' : ' lang-' + type,
  6758. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6759. if (K.trim(code) === '') {
  6760. alert(lang.pleaseInput);
  6761. textarea[0].focus();
  6762. return;
  6763. }
  6764. self.insertHtml(html).hideDialog().focus();
  6765. }
  6766. }
  6767. }),
  6768. textarea = K('textarea', dialog.div);
  6769. textarea[0].focus();
  6770. });
  6771. });
  6772. /*******************************************************************************
  6773. * KindEditor - WYSIWYG HTML Editor for Internet
  6774. * Copyright (C) 2006-2011 kindsoft.net
  6775. *
  6776. * @author Roddy <luolonghao@gmail.com>
  6777. * @site http://www.kindsoft.net/
  6778. * @licence http://www.kindsoft.net/license.php
  6779. *******************************************************************************/
  6780. KindEditor.plugin('emoticons', function(K) {
  6781. var self = this, name = 'emoticons',
  6782. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6783. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6784. currentPageNum = 1;
  6785. self.clickToolbar(name, function() {
  6786. var rows = 5, cols = 9, total = 135, startNum = 0,
  6787. cells = rows * cols, pages = Math.ceil(total / cells),
  6788. colsHalf = Math.floor(cols / 2),
  6789. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6790. elements = [],
  6791. menu = self.createMenu({
  6792. name : name,
  6793. beforeRemove : function() {
  6794. removeEvent();
  6795. }
  6796. });
  6797. menu.div.append(wrapperDiv);
  6798. var previewDiv, previewImg;
  6799. if (allowPreview) {
  6800. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6801. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6802. wrapperDiv.append(previewDiv);
  6803. previewDiv.append(previewImg);
  6804. }
  6805. function bindCellEvent(cell, j, num) {
  6806. if (previewDiv) {
  6807. cell.mouseover(function() {
  6808. if (j > colsHalf) {
  6809. previewDiv.css('left', 0);
  6810. previewDiv.css('right', '');
  6811. } else {
  6812. previewDiv.css('left', '');
  6813. previewDiv.css('right', 0);
  6814. }
  6815. previewImg.attr('src', path + num + '.gif');
  6816. K(this).addClass('ke-on');
  6817. });
  6818. } else {
  6819. cell.mouseover(function() {
  6820. K(this).addClass('ke-on');
  6821. });
  6822. }
  6823. cell.mouseout(function() {
  6824. K(this).removeClass('ke-on');
  6825. });
  6826. cell.click(function(e) {
  6827. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6828. e.stop();
  6829. });
  6830. }
  6831. function createEmoticonsTable(pageNum, parentDiv) {
  6832. var table = document.createElement('table');
  6833. parentDiv.append(table);
  6834. if (previewDiv) {
  6835. K(table).mouseover(function() {
  6836. previewDiv.show('block');
  6837. });
  6838. K(table).mouseout(function() {
  6839. previewDiv.hide();
  6840. });
  6841. elements.push(K(table));
  6842. }
  6843. table.className = 'ke-table';
  6844. table.cellPadding = 0;
  6845. table.cellSpacing = 0;
  6846. table.border = 0;
  6847. var num = (pageNum - 1) * cells + startNum;
  6848. for (var i = 0; i < rows; i++) {
  6849. var row = table.insertRow(i);
  6850. for (var j = 0; j < cols; j++) {
  6851. var cell = K(row.insertCell(j));
  6852. cell.addClass('ke-cell');
  6853. bindCellEvent(cell, j, num);
  6854. var span = K('<span class="ke-img"></span>')
  6855. .css('background-position', '-' + (24 * num) + 'px 0px')
  6856. .css('background-image', 'url(' + path + 'static.gif)');
  6857. cell.append(span);
  6858. elements.push(cell);
  6859. num++;
  6860. }
  6861. }
  6862. return table;
  6863. }
  6864. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6865. function removeEvent() {
  6866. K.each(elements, function() {
  6867. this.unbind();
  6868. });
  6869. }
  6870. var pageDiv;
  6871. function bindPageEvent(el, pageNum) {
  6872. el.click(function(e) {
  6873. removeEvent();
  6874. table.parentNode.removeChild(table);
  6875. pageDiv.remove();
  6876. table = createEmoticonsTable(pageNum, wrapperDiv);
  6877. createPageTable(pageNum);
  6878. currentPageNum = pageNum;
  6879. e.stop();
  6880. });
  6881. }
  6882. function createPageTable(currentPageNum) {
  6883. pageDiv = K('<div class="ke-page"></div>');
  6884. wrapperDiv.append(pageDiv);
  6885. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6886. if (currentPageNum !== pageNum) {
  6887. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6888. bindPageEvent(a, pageNum);
  6889. pageDiv.append(a);
  6890. elements.push(a);
  6891. } else {
  6892. pageDiv.append(K('@[' + pageNum + ']'));
  6893. }
  6894. pageDiv.append(K('@&nbsp;'));
  6895. }
  6896. }
  6897. createPageTable(currentPageNum);
  6898. });
  6899. });
  6900. /*******************************************************************************
  6901. * KindEditor - WYSIWYG HTML Editor for Internet
  6902. * Copyright (C) 2006-2011 kindsoft.net
  6903. *
  6904. * @author Roddy <luolonghao@gmail.com>
  6905. * @site http://www.kindsoft.net/
  6906. * @licence http://www.kindsoft.net/license.php
  6907. *******************************************************************************/
  6908. KindEditor.plugin('filemanager', function(K) {
  6909. var self = this, name = 'filemanager',
  6910. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6911. imgPath = self.pluginsPath + name + '/images/',
  6912. lang = self.lang(name + '.');
  6913. function makeFileTitle(filename, filesize, datetime) {
  6914. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6915. }
  6916. function bindTitle(el, data) {
  6917. if (data.is_dir) {
  6918. el.attr('title', data.filename);
  6919. } else {
  6920. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6921. }
  6922. }
  6923. self.plugin.filemanagerDialog = function(options) {
  6924. var width = K.undef(options.width, 650),
  6925. height = K.undef(options.height, 510),
  6926. dirName = K.undef(options.dirName, ''),
  6927. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6928. clickFn = options.clickFn;
  6929. var html = [
  6930. '<div style="padding:10px 20px;">',
  6931. '<div class="ke-plugin-filemanager-header">',
  6932. '<div class="ke-left">',
  6933. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6934. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6935. '</div>',
  6936. '<div class="ke-right">',
  6937. '标签 <input type="text" style="width:100px;" value="" name="viewTag">',
  6938. '分类 <select class="ke-inline-block" name="viewCate">',
  6939. '',
  6940. '</select> ',
  6941. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6942. '<option value="VIEW">' + lang.viewImage + '</option>',
  6943. '<option value="LIST">' + lang.listImage + '</option>',
  6944. '</select> ',
  6945. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6946. '<option value="NAME">' + lang.fileName + '</option>',
  6947. '<option value="SIZE">' + lang.fileSize + '</option>',
  6948. '<option value="TYPE">' + lang.fileType + '</option>',
  6949. '</select>',
  6950. '</div>',
  6951. '<div class="ke-clearfix"></div>',
  6952. '</div>',
  6953. '<div class="ke-plugin-filemanager-body"></div>',
  6954. '</div>'
  6955. ].join('');
  6956. var dialog = self.createDialog({
  6957. name : name,
  6958. width : width,
  6959. height : height,
  6960. title : self.lang(name),
  6961. body : html
  6962. }),
  6963. div = dialog.div,
  6964. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6965. moveupImg = K('[name="moveupImg"]', div),
  6966. moveupLink = K('[name="moveupLink"]', div),
  6967. viewServerBtn = K('[name="viewServer"]', div),
  6968. viewCateBox = K('[name="viewCate"]', div),
  6969. viewTagBox = K('[name="viewTag"]', div),
  6970. viewTypeBox = K('[name="viewType"]', div),
  6971. orderTypeBox = K('[name="orderType"]', div);
  6972. function reloadPage(path, order, func, cate, tag) {
  6973. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6974. if (cate) {
  6975. param += '&cate=' + cate;
  6976. }
  6977. if (tag) {
  6978. param += '&tag=' + tag;
  6979. }
  6980. dialog.showLoading(self.lang('ajaxLoading'));
  6981. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6982. dialog.hideLoading();
  6983. func(data);
  6984. });
  6985. }
  6986. var elList = [];
  6987. function bindEvent(el, result, data, createFunc) {
  6988. var fileUrl = K.formatUrl(result.current_url + data.file, 'absolute'),
  6989. dirPath = encodeURIComponent(result.current_dir_path + data.path + '/');
  6990. if (data.is_dir) {
  6991. el.click(function(e) {
  6992. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6993. });
  6994. } else if (data.is_photo) {
  6995. el.click(function(e) {
  6996. clickFn.call(this, fileUrl, data.file);
  6997. });
  6998. } else {
  6999. el.click(function(e) {
  7000. clickFn.call(this, fileUrl, data.file);
  7001. });
  7002. }
  7003. elList.push(el);
  7004. }
  7005. function createCommon(result, createFunc) {
  7006. K.each(elList, function() {
  7007. this.unbind();
  7008. });
  7009. moveupLink.unbind();
  7010. viewTypeBox.unbind();
  7011. orderTypeBox.unbind();
  7012. if (result.current_dir_path) {
  7013. moveupLink.click(function(e) {
  7014. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  7015. });
  7016. }
  7017. function changeFunc() {
  7018. if (viewTypeBox.val() == 'VIEW') {
  7019. reloadPage(result.current_dir_path, orderTypeBox.val(), createView, viewCateBox.val(), viewTagBox.val());
  7020. } else {
  7021. reloadPage(result.current_dir_path, orderTypeBox.val(), createList, viewCateBox.val(), viewTagBox.val());
  7022. }
  7023. }
  7024. viewTypeBox.change(changeFunc);
  7025. orderTypeBox.change(changeFunc);
  7026. viewCateBox.change(changeFunc);
  7027. bodyDiv.html('');
  7028. }
  7029. function createList(result) {
  7030. createCommon(result, createList);
  7031. var table = document.createElement('table');
  7032. table.className = 'ke-table';
  7033. table.cellPadding = 0;
  7034. table.cellSpacing = 0;
  7035. table.border = 0;
  7036. bodyDiv.append(table);
  7037. var fileList = result.file_list;
  7038. for (var i = 0, len = fileList.length; i < len; i++) {
  7039. var data = fileList[i], row = K(table.insertRow(i));
  7040. row.mouseover(function(e) {
  7041. K(this).addClass('ke-on');
  7042. })
  7043. .mouseout(function(e) {
  7044. K(this).removeClass('ke-on');
  7045. });
  7046. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  7047. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  7048. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  7049. if (!data.is_dir || data.has_file) {
  7050. row.css('cursor', 'pointer');
  7051. cell0.attr('title', data.filename);
  7052. bindEvent(cell0, result, data, createList);
  7053. } else {
  7054. cell0.attr('title', lang.emptyFolder);
  7055. }
  7056. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  7057. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  7058. }
  7059. }
  7060. function createView(result) {
  7061. createCommon(result, createView);
  7062. var fileList = result.file_list;
  7063. for (var i = 0, len = fileList.length; i < len; i++) {
  7064. var data = fileList[i],
  7065. div = K('<div class="ke-inline-block ke-item"></div>');
  7066. bodyDiv.append(div);
  7067. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7068. .mouseover(function(e) {
  7069. K(this).addClass('ke-on');
  7070. })
  7071. .mouseout(function(e) {
  7072. K(this).removeClass('ke-on');
  7073. });
  7074. div.append(photoDiv);
  7075. var fileUrl = result.current_url + data.file,
  7076. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7077. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7078. if (!data.is_dir || data.has_file) {
  7079. photoDiv.css('cursor', 'pointer');
  7080. bindTitle(photoDiv, data);
  7081. bindEvent(photoDiv, result, data, createView);
  7082. } else {
  7083. photoDiv.attr('title', lang.emptyFolder);
  7084. }
  7085. photoDiv.append(img);
  7086. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7087. }
  7088. }
  7089. viewTypeBox.val(viewType);
  7090. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7091. return dialog;
  7092. }
  7093. });
  7094. /*******************************************************************************
  7095. * KindEditor - WYSIWYG HTML Editor for Internet
  7096. * Copyright (C) 2006-2011 kindsoft.net
  7097. *
  7098. * @author Roddy <luolonghao@gmail.com>
  7099. * @site http://www.kindsoft.net/
  7100. * @licence http://www.kindsoft.net/license.php
  7101. *******************************************************************************/
  7102. KindEditor.plugin('flash', function(K) {
  7103. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7104. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7105. allowFileManager = K.undef(self.allowFileManager, false),
  7106. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7107. extraParams = K.undef(self.extraFileUploadParams, {}),
  7108. filePostName = K.undef(self.filePostName, 'imgFile'),
  7109. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7110. self.plugin.flash = {
  7111. edit : function() {
  7112. var html = [
  7113. '<div style="padding:20px;">',
  7114. '<div class="ke-dialog-row">',
  7115. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7116. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7117. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7118. '<span class="ke-button-common ke-button-outer">',
  7119. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7120. '</span>',
  7121. '</div>',
  7122. '<div class="ke-dialog-row">',
  7123. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7124. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7125. '</div>',
  7126. '<div class="ke-dialog-row">',
  7127. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7128. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7129. '</div>',
  7130. '</div>'
  7131. ].join('');
  7132. var dialog = self.createDialog({
  7133. name : name,
  7134. width : 450,
  7135. title : self.lang(name),
  7136. body : html,
  7137. yesBtn : {
  7138. name : self.lang('yes'),
  7139. click : function(e) {
  7140. var url = K.trim(urlBox.val()),
  7141. width = widthBox.val(),
  7142. height = heightBox.val();
  7143. if (url == 'http://' || K.invalidUrl(url)) {
  7144. alert(self.lang('invalidUrl'));
  7145. urlBox[0].focus();
  7146. return;
  7147. }
  7148. if (!/^\d*$/.test(width)) {
  7149. alert(self.lang('invalidWidth'));
  7150. widthBox[0].focus();
  7151. return;
  7152. }
  7153. if (!/^\d*$/.test(height)) {
  7154. alert(self.lang('invalidHeight'));
  7155. heightBox[0].focus();
  7156. return;
  7157. }
  7158. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7159. src : url,
  7160. type : K.mediaType('.swf'),
  7161. width : width,
  7162. height : height,
  7163. quality : 'high'
  7164. });
  7165. self.insertHtml(html).hideDialog().focus();
  7166. }
  7167. }
  7168. }),
  7169. div = dialog.div,
  7170. urlBox = K('[name="url"]', div),
  7171. viewServerBtn = K('[name="viewServer"]', div),
  7172. widthBox = K('[name="width"]', div),
  7173. heightBox = K('[name="height"]', div);
  7174. urlBox.val('http://');
  7175. if (allowFlashUpload) {
  7176. var uploadbutton = K.uploadbutton({
  7177. button : K('.ke-upload-button', div)[0],
  7178. fieldName : filePostName,
  7179. extraParams : extraParams,
  7180. url : K.addParam(uploadJson, 'dir=flash'),
  7181. afterUpload : function(data) {
  7182. dialog.hideLoading();
  7183. if (data.error === 0) {
  7184. var url = data.url;
  7185. if (formatUploadUrl) {
  7186. url = K.formatUrl(url, 'absolute');
  7187. }
  7188. urlBox.val(url);
  7189. if (self.afterUpload) {
  7190. self.afterUpload.call(self, url, data, name);
  7191. }
  7192. alert(self.lang('uploadSuccess'));
  7193. } else {
  7194. alert(data.message);
  7195. }
  7196. },
  7197. afterError : function(html) {
  7198. dialog.hideLoading();
  7199. self.errorDialog(html);
  7200. }
  7201. });
  7202. uploadbutton.fileBox.change(function(e) {
  7203. dialog.showLoading(self.lang('uploadLoading'));
  7204. uploadbutton.submit();
  7205. });
  7206. } else {
  7207. K('.ke-upload-button', div).hide();
  7208. }
  7209. if (allowFileManager) {
  7210. viewServerBtn.click(function(e) {
  7211. var clickFn = function(url, title, id) {
  7212. K('[name="url"]', div).val(url);
  7213. if (self.afterSelectFile) {
  7214. self.afterSelectFile.call(self, url);
  7215. }
  7216. };
  7217. var cur = K('[name="url"]', div).val();
  7218. editorShowUpload(cur, self.fileManagerJson, 'flash库', clickFn, this);
  7219. /*
  7220. self.loadPlugin('filemanager', function() {
  7221. self.plugin.filemanagerDialog({
  7222. viewType : 'LIST',
  7223. dirName : 'flash',
  7224. clickFn : function(url, title) {
  7225. if (self.dialogs.length > 1) {
  7226. K('[name="url"]', div).val(url);
  7227. if (self.afterSelectFile) {
  7228. self.afterSelectFile.call(self, url);
  7229. }
  7230. self.hideDialog();
  7231. }
  7232. }
  7233. });
  7234. });
  7235. */
  7236. });
  7237. } else {
  7238. viewServerBtn.hide();
  7239. }
  7240. var img = self.plugin.getSelectedFlash();
  7241. if (img) {
  7242. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7243. urlBox.val(attrs.src);
  7244. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7245. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7246. }
  7247. urlBox[0].focus();
  7248. urlBox[0].select();
  7249. },
  7250. 'delete' : function() {
  7251. self.plugin.getSelectedFlash().remove();
  7252. self.addBookmark();
  7253. }
  7254. };
  7255. self.clickToolbar(name, self.plugin.flash.edit);
  7256. });
  7257. /*******************************************************************************
  7258. * KindEditor - WYSIWYG HTML Editor for Internet
  7259. * Copyright (C) 2006-2011 kindsoft.net
  7260. *
  7261. * @author Roddy <luolonghao@gmail.com>
  7262. * @site http://www.kindsoft.net/
  7263. * @licence http://www.kindsoft.net/license.php
  7264. *******************************************************************************/
  7265. KindEditor.plugin('image', function(K) {
  7266. var self = this, name = 'image',
  7267. allowImageUpload = K.undef(self.allowImageUpload, true),
  7268. allowImageRemote = K.undef(self.allowImageRemote, true),
  7269. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7270. allowFileManager = K.undef(self.allowFileManager, false),
  7271. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7272. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7273. imgPath = self.pluginsPath + 'image/images/',
  7274. extraParams = K.undef(self.extraFileUploadParams, {}),
  7275. filePostName = K.undef(self.filePostName, 'imgFile'),
  7276. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7277. lang = self.lang(name + '.');
  7278. self.plugin.imageDialog = function(options) {
  7279. var imageUrl = options.imageUrl,
  7280. imageWidth = K.undef(options.imageWidth, ''),
  7281. imageHeight = K.undef(options.imageHeight, ''),
  7282. imageTitle = K.undef(options.imageTitle, ''),
  7283. imageAlign = K.undef(options.imageAlign, ''),
  7284. showRemote = K.undef(options.showRemote, true),
  7285. showLocal = K.undef(options.showLocal, true),
  7286. tabIndex = K.undef(options.tabIndex, 0),
  7287. clickFn = options.clickFn;
  7288. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7289. var hiddenElements = [];
  7290. for(var k in extraParams){
  7291. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7292. }
  7293. var html = [
  7294. '<div style="padding:20px;">',
  7295. '<div class="tabs"></div>',
  7296. '<div class="tab1" style="display:none;">',
  7297. '<div class="ke-dialog-row">',
  7298. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7299. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7300. '<span class="ke-button-common ke-button-outer">',
  7301. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7302. '</span>',
  7303. '</div>',
  7304. '<div class="ke-dialog-row">',
  7305. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7306. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7307. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7308. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7309. '</div>',
  7310. '<div class="ke-dialog-row">',
  7311. '<label style="width:60px;">' + lang.align + '</label>',
  7312. '<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="" />',
  7313. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7314. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7315. '</div>',
  7316. '<div class="ke-dialog-row">',
  7317. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7318. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7319. '</div>',
  7320. '</div>',
  7321. '<div class="tab2" style="display:none;">',
  7322. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7323. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7324. '<div class="ke-dialog-row">',
  7325. hiddenElements.join(''),
  7326. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7327. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7328. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7329. '</div>',
  7330. '</form>',
  7331. '</div>',
  7332. '</div>'
  7333. ].join('');
  7334. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7335. dialogHeight = showLocal && showRemote ? 300 : 250;
  7336. var dialog = self.createDialog({
  7337. name : name,
  7338. width : dialogWidth,
  7339. height : dialogHeight,
  7340. title : self.lang(name),
  7341. body : html,
  7342. yesBtn : {
  7343. name : self.lang('yes'),
  7344. click : function(e) {
  7345. if (dialog.isLoading) {
  7346. return;
  7347. }
  7348. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7349. if (uploadbutton.fileBox.val() == '') {
  7350. alert(self.lang('pleaseSelectFile'));
  7351. return;
  7352. }
  7353. dialog.showLoading(self.lang('uploadLoading'));
  7354. uploadbutton.submit();
  7355. localUrlBox.val('');
  7356. return;
  7357. }
  7358. var url = K.trim(urlBox.val()),
  7359. width = widthBox.val(),
  7360. height = heightBox.val(),
  7361. title = titleBox.val(),
  7362. align = '';
  7363. alignBox.each(function() {
  7364. if (this.checked) {
  7365. align = this.value;
  7366. return false;
  7367. }
  7368. });
  7369. if (url == 'http://' || K.invalidUrl(url)) {
  7370. alert(self.lang('invalidUrl'));
  7371. urlBox[0].focus();
  7372. return;
  7373. }
  7374. if (!/^\d*$/.test(width)) {
  7375. alert(self.lang('invalidWidth'));
  7376. widthBox[0].focus();
  7377. return;
  7378. }
  7379. if (!/^\d*$/.test(height)) {
  7380. alert(self.lang('invalidHeight'));
  7381. heightBox[0].focus();
  7382. return;
  7383. }
  7384. clickFn.call(self, url, title, width, height, 0, align);
  7385. }
  7386. },
  7387. beforeRemove : function() {
  7388. viewServerBtn.unbind();
  7389. widthBox.unbind();
  7390. heightBox.unbind();
  7391. refreshBtn.unbind();
  7392. }
  7393. }),
  7394. div = dialog.div;
  7395. var urlBox = K('[name="url"]', div),
  7396. localUrlBox = K('[name="localUrl"]', div),
  7397. viewServerBtn = K('[name="viewServer"]', div),
  7398. widthBox = K('.tab1 [name="width"]', div),
  7399. heightBox = K('.tab1 [name="height"]', div),
  7400. refreshBtn = K('.ke-refresh-btn', div),
  7401. titleBox = K('.tab1 [name="title"]', div),
  7402. alignBox = K('.tab1 [name="align"]', div);
  7403. var tabs;
  7404. if (showRemote && showLocal) {
  7405. tabs = K.tabs({
  7406. src : K('.tabs', div),
  7407. afterSelect : function(i) {}
  7408. });
  7409. tabs.add({
  7410. title : lang.remoteImage,
  7411. panel : K('.tab1', div)
  7412. });
  7413. tabs.add({
  7414. title : lang.localImage,
  7415. panel : K('.tab2', div)
  7416. });
  7417. tabs.select(1);
  7418. } else if (showRemote) {
  7419. K('.tab1', div).show();
  7420. } else if (showLocal) {
  7421. K('.tab2', div).show();
  7422. }
  7423. var uploadbutton = K.uploadbutton({
  7424. button : K('.ke-upload-button', div)[0],
  7425. fieldName : filePostName,
  7426. form : K('.ke-form', div),
  7427. target : target,
  7428. width: 60,
  7429. afterUpload : function(data) {
  7430. dialog.hideLoading();
  7431. if (data.error === 0) {
  7432. var url = data.url;
  7433. if (formatUploadUrl) {
  7434. url = K.formatUrl(url, 'absolute');
  7435. }
  7436. if (self.afterUpload) {
  7437. self.afterUpload.call(self, url, data, name);
  7438. }
  7439. if (!fillDescAfterUploadImage) {
  7440. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7441. } else {
  7442. K(".ke-dialog-row #remoteUrl", div).val(url);
  7443. K(".ke-tabs-li", div)[0].click();
  7444. K(".ke-refresh-btn", div).click();
  7445. }
  7446. } else {
  7447. alert(data.message);
  7448. }
  7449. },
  7450. afterError : function(html) {
  7451. dialog.hideLoading();
  7452. self.errorDialog(html);
  7453. }
  7454. });
  7455. uploadbutton.fileBox.change(function(e) {
  7456. localUrlBox.val(uploadbutton.fileBox.val());
  7457. });
  7458. if (allowFileManager) {
  7459. viewServerBtn.click(function(e) {
  7460. //clickFn.call(this, fileUrl, data.file);
  7461. var clickFn = function(url, title, id) {
  7462. K('[name="url"]', div).val(url);
  7463. if (self.afterSelectFile) {
  7464. self.afterSelectFile.call(self, url);
  7465. }
  7466. };
  7467. var cur = K('[name="url"]', div).val();
  7468. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  7469. /*
  7470. self.loadPlugin('filemanager', function() {
  7471. self.plugin.filemanagerDialog({
  7472. viewType : 'VIEW',
  7473. dirName : 'image',
  7474. clickFn : function(url, title) {
  7475. if (self.dialogs.length > 1) {
  7476. K('[name="url"]', div).val(url);
  7477. if (self.afterSelectFile) {
  7478. self.afterSelectFile.call(self, url);
  7479. }
  7480. self.hideDialog();
  7481. }
  7482. }
  7483. });
  7484. });
  7485. */
  7486. });
  7487. } else {
  7488. viewServerBtn.hide();
  7489. }
  7490. var originalWidth = 0, originalHeight = 0;
  7491. function setSize(width, height) {
  7492. widthBox.val(width);
  7493. heightBox.val(height);
  7494. originalWidth = width;
  7495. originalHeight = height;
  7496. }
  7497. refreshBtn.click(function(e) {
  7498. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7499. position : 'absolute',
  7500. visibility : 'hidden',
  7501. top : 0,
  7502. left : '-1000px'
  7503. });
  7504. tempImg.bind('load', function() {
  7505. setSize(tempImg.width(), tempImg.height());
  7506. tempImg.remove();
  7507. });
  7508. K(document.body).append(tempImg);
  7509. });
  7510. widthBox.change(function(e) {
  7511. if (originalWidth > 0) {
  7512. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7513. }
  7514. });
  7515. heightBox.change(function(e) {
  7516. if (originalHeight > 0) {
  7517. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7518. }
  7519. });
  7520. urlBox.val(options.imageUrl);
  7521. setSize(options.imageWidth, options.imageHeight);
  7522. titleBox.val(options.imageTitle);
  7523. alignBox.each(function() {
  7524. if (this.value === options.imageAlign) {
  7525. this.checked = true;
  7526. return false;
  7527. }
  7528. });
  7529. if (showRemote && tabIndex === 0) {
  7530. urlBox[0].focus();
  7531. urlBox[0].select();
  7532. }
  7533. return dialog;
  7534. };
  7535. self.plugin.image = {
  7536. edit : function() {
  7537. var img = self.plugin.getSelectedImage();
  7538. self.plugin.imageDialog({
  7539. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7540. imageWidth : img ? img.width() : '',
  7541. imageHeight : img ? img.height() : '',
  7542. imageTitle : img ? img.attr('title') : '',
  7543. imageAlign : img ? img.attr('align') : '',
  7544. showRemote : allowImageRemote,
  7545. showLocal : allowImageUpload,
  7546. tabIndex: img ? 0 : imageTabIndex,
  7547. clickFn : function(url, title, width, height, border, align) {
  7548. if (img) {
  7549. img.attr('src', url);
  7550. img.attr('data-ke-src', url);
  7551. img.attr('width', width);
  7552. img.attr('height', height);
  7553. img.attr('title', title);
  7554. img.attr('align', align);
  7555. img.attr('alt', title);
  7556. } else {
  7557. self.exec('insertimage', url, title, width, height, border, align);
  7558. }
  7559. setTimeout(function() {
  7560. self.hideDialog().focus();
  7561. }, 0);
  7562. }
  7563. });
  7564. },
  7565. 'delete' : function() {
  7566. var target = self.plugin.getSelectedImage();
  7567. if (target.parent().name == 'a') {
  7568. target = target.parent();
  7569. }
  7570. target.remove();
  7571. self.addBookmark();
  7572. }
  7573. };
  7574. self.clickToolbar(name, self.plugin.image.edit);
  7575. });
  7576. /*******************************************************************************
  7577. * KindEditor - WYSIWYG HTML Editor for Internet
  7578. * Copyright (C) 2006-2011 kindsoft.net
  7579. *
  7580. * @author Roddy <luolonghao@gmail.com>
  7581. * @site http://www.kindsoft.net/
  7582. * @licence http://www.kindsoft.net/license.php
  7583. *******************************************************************************/
  7584. KindEditor.plugin('insertfile', function(K) {
  7585. var self = this, name = 'insertfile',
  7586. allowFileUpload = K.undef(self.allowFileUpload, true),
  7587. allowFileManager = K.undef(self.allowFileManager, false),
  7588. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7589. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7590. extraParams = K.undef(self.extraFileUploadParams, {}),
  7591. filePostName = K.undef(self.filePostName, 'imgFile'),
  7592. lang = self.lang(name + '.');
  7593. self.plugin.fileDialog = function(options) {
  7594. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7595. fileTitle = K.undef(options.fileTitle, ''),
  7596. clickFn = options.clickFn;
  7597. var html = [
  7598. '<div style="padding:20px;">',
  7599. '<div class="ke-dialog-row">',
  7600. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7601. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7602. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7603. '<span class="ke-button-common ke-button-outer">',
  7604. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7605. '</span>',
  7606. '</div>',
  7607. '<div class="ke-dialog-row">',
  7608. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7609. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7610. '</div>',
  7611. '</form>',
  7612. '</div>'
  7613. ].join('');
  7614. var dialog = self.createDialog({
  7615. name : name,
  7616. width : 450,
  7617. title : self.lang(name),
  7618. body : html,
  7619. yesBtn : {
  7620. name : self.lang('yes'),
  7621. click : function(e) {
  7622. var url = K.trim(urlBox.val()),
  7623. title = titleBox.val();
  7624. if (url == 'http://' || K.invalidUrl(url)) {
  7625. alert(self.lang('invalidUrl'));
  7626. urlBox[0].focus();
  7627. return;
  7628. }
  7629. if (K.trim(title) === '') {
  7630. title = url;
  7631. }
  7632. clickFn.call(self, url, title);
  7633. }
  7634. }
  7635. }),
  7636. div = dialog.div;
  7637. var urlBox = K('[name="url"]', div),
  7638. viewServerBtn = K('[name="viewServer"]', div),
  7639. titleBox = K('[name="title"]', div);
  7640. if (allowFileUpload) {
  7641. var uploadbutton = K.uploadbutton({
  7642. button : K('.ke-upload-button', div)[0],
  7643. fieldName : filePostName,
  7644. url : K.addParam(uploadJson, 'dir=file'),
  7645. extraParams : extraParams,
  7646. afterUpload : function(data) {
  7647. dialog.hideLoading();
  7648. if (data.error === 0) {
  7649. var url = data.url;
  7650. if (formatUploadUrl) {
  7651. url = K.formatUrl(url, 'absolute');
  7652. }
  7653. urlBox.val(url);
  7654. if (self.afterUpload) {
  7655. self.afterUpload.call(self, url, data, name);
  7656. }
  7657. alert(self.lang('uploadSuccess'));
  7658. } else {
  7659. alert(data.message);
  7660. }
  7661. },
  7662. afterError : function(html) {
  7663. dialog.hideLoading();
  7664. self.errorDialog(html);
  7665. }
  7666. });
  7667. uploadbutton.fileBox.change(function(e) {
  7668. dialog.showLoading(self.lang('uploadLoading'));
  7669. uploadbutton.submit();
  7670. });
  7671. } else {
  7672. K('.ke-upload-button', div).hide();
  7673. }
  7674. if (allowFileManager) {
  7675. viewServerBtn.click(function(e) {
  7676. var clickFn = function(url, title, id) {
  7677. K('[name="url"]', div).val(url);
  7678. if (self.afterSelectFile) {
  7679. self.afterSelectFile.call(self, url);
  7680. }
  7681. };
  7682. var cur = K('[name="url"]', div).val();
  7683. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '文件库', clickFn, this);
  7684. /*
  7685. self.loadPlugin('filemanager', function() {
  7686. self.plugin.filemanagerDialog({
  7687. viewType : 'LIST',
  7688. dirName : 'file',
  7689. clickFn : function(url, title) {
  7690. if (self.dialogs.length > 1) {
  7691. self.hideDialog();
  7692. }
  7693. }
  7694. });
  7695. });
  7696. */
  7697. });
  7698. } else {
  7699. viewServerBtn.hide();
  7700. }
  7701. urlBox.val(fileUrl);
  7702. titleBox.val(fileTitle);
  7703. urlBox[0].focus();
  7704. urlBox[0].select();
  7705. };
  7706. self.clickToolbar(name, function() {
  7707. self.plugin.fileDialog({
  7708. clickFn : function(url, title) {
  7709. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7710. self.insertHtml(html).hideDialog().focus();
  7711. }
  7712. });
  7713. });
  7714. });
  7715. /*******************************************************************************
  7716. * KindEditor - WYSIWYG HTML Editor for Internet
  7717. * Copyright (C) 2006-2011 kindsoft.net
  7718. *
  7719. * @author Roddy <luolonghao@gmail.com>
  7720. * @site http://www.kindsoft.net/
  7721. * @licence http://www.kindsoft.net/license.php
  7722. *******************************************************************************/
  7723. KindEditor.plugin('lineheight', function(K) {
  7724. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7725. self.clickToolbar(name, function() {
  7726. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7727. if (commonNode) {
  7728. curVal = commonNode.css('line-height');
  7729. }
  7730. var menu = self.createMenu({
  7731. name : name,
  7732. width : 150
  7733. });
  7734. K.each(lang.lineHeight, function(i, row) {
  7735. K.each(row, function(key, val) {
  7736. menu.addItem({
  7737. title : val,
  7738. checked : curVal === key,
  7739. click : function() {
  7740. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7741. span : '.line-height=' + key
  7742. });
  7743. self.updateState();
  7744. self.addBookmark();
  7745. self.hideMenu();
  7746. }
  7747. });
  7748. });
  7749. });
  7750. });
  7751. });
  7752. /*******************************************************************************
  7753. * KindEditor - WYSIWYG HTML Editor for Internet
  7754. * Copyright (C) 2006-2011 kindsoft.net
  7755. *
  7756. * @author Roddy <luolonghao@gmail.com>
  7757. * @site http://www.kindsoft.net/
  7758. * @licence http://www.kindsoft.net/license.php
  7759. *******************************************************************************/
  7760. KindEditor.plugin('link', function(K) {
  7761. var self = this, name = 'link';
  7762. self.plugin.link = {
  7763. edit : function() {
  7764. var lang = self.lang(name + '.'),
  7765. html = '<div style="padding:20px;">' +
  7766. '<div class="ke-dialog-row">' +
  7767. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7768. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7769. '<div class="ke-dialog-row"">' +
  7770. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7771. '<select id="keType" name="type"></select>' +
  7772. '</div>' +
  7773. '</div>',
  7774. dialog = self.createDialog({
  7775. name : name,
  7776. width : 450,
  7777. title : self.lang(name),
  7778. body : html,
  7779. yesBtn : {
  7780. name : self.lang('yes'),
  7781. click : function(e) {
  7782. var url = K.trim(urlBox.val());
  7783. if (url == 'http://' || K.invalidUrl(url)) {
  7784. alert(self.lang('invalidUrl'));
  7785. urlBox[0].focus();
  7786. return;
  7787. }
  7788. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7789. }
  7790. }
  7791. }),
  7792. div = dialog.div,
  7793. urlBox = K('input[name="url"]', div),
  7794. typeBox = K('select[name="type"]', div);
  7795. urlBox.val('http://');
  7796. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7797. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7798. self.cmd.selection();
  7799. var a = self.plugin.getSelectedLink();
  7800. if (a) {
  7801. self.cmd.range.selectNode(a[0]);
  7802. //self.cmd.select();
  7803. urlBox.val(a.attr('data-ke-src'));
  7804. typeBox.val(a.attr('target'));
  7805. }
  7806. urlBox[0].focus();
  7807. urlBox[0].select();
  7808. },
  7809. 'delete' : function() {
  7810. self.exec('unlink', null);
  7811. }
  7812. };
  7813. self.clickToolbar(name, self.plugin.link.edit);
  7814. });
  7815. /*******************************************************************************
  7816. * KindEditor - WYSIWYG HTML Editor for Internet
  7817. * Copyright (C) 2006-2011 kindsoft.net
  7818. *
  7819. * @author Roddy <luolonghao@gmail.com>
  7820. * @site http://www.kindsoft.net/
  7821. * @licence http://www.kindsoft.net/license.php
  7822. *******************************************************************************/
  7823. KindEditor.plugin('media', function(K) {
  7824. var self = this, name = 'media', lang = self.lang(name + '.'),
  7825. allowFileUpload = K.undef(self.allowFileUpload, true),
  7826. allowFileManager = K.undef(self.allowFileManager, false),
  7827. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7828. allowFileManager = K.undef(self.allowFileManager, false),
  7829. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7830. extraParams = K.undef(self.extraFileUploadParams, {}),
  7831. uploadCoverJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7832. filePostName = K.undef(self.filePostName, 'imgFile'),
  7833. uploadJson = K.undef(self.uploadMediaJson, self.basePath + 'php/upload_json.php');
  7834. if (self.uploadYunJson && self.uploadYunJson.domain) {
  7835. uploadJson = self.uploadYunJson.domain;
  7836. extraParams.token = self.uploadYunJson.token;
  7837. extraParams.key = self.uploadYunJson.path;
  7838. }
  7839. self.plugin.media = {
  7840. edit : function() {
  7841. var html = [
  7842. '<div style="padding:20px;">',
  7843. '<div class="ke-dialog-row">',
  7844. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7845. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7846. '<input type="button" class="ke-upload-button ke-upload-button-media" value="' + lang.upload + '" /> &nbsp;',
  7847. '<span class="ke-button-common ke-button-outer">',
  7848. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7849. '</span>',
  7850. '</div>',
  7851. '<div class="ke-dialog-row">',
  7852. '<label for="keUrl" style="width:60px;">封面</label>',
  7853. '<input class="ke-input-text" type="text" id="keUrlCover" name="cover_url" value="" style="width:160px;" /> &nbsp;',
  7854. '<input type="button" class="ke-upload-button ke-upload-button-cover" value="' + lang.upload + '" /> &nbsp;',
  7855. '<span class="ke-button-common ke-button-outer">',
  7856. '<input type="button" class="ke-button-common ke-button" name="viewCoverServer" value="' + lang.viewServer + '" />',
  7857. '</span>',
  7858. '</div>',
  7859. '<div class="ke-dialog-row">',
  7860. '<label for="keWidth" style="width:60px;">标题</label>',
  7861. '<input type="text" id="keName" class="ke-input-text ke-input-number" name="name" value="" maxlength="4" />',
  7862. '</div>',
  7863. '<div class="ke-dialog-row">',
  7864. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7865. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="450" maxlength="4" />',
  7866. '</div>',
  7867. '<div class="ke-dialog-row">',
  7868. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7869. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="100" maxlength="4" />',
  7870. '</div>',
  7871. '<div class="ke-dialog-row">',
  7872. '<label for="keAutostart">' + lang.autostart + '</label>',
  7873. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7874. '</div>',
  7875. '</div>'
  7876. ].join('');
  7877. var dialog = self.createDialog({
  7878. name : name,
  7879. width : 450,
  7880. height : 230,
  7881. title : self.lang(name),
  7882. body : html,
  7883. yesBtn : {
  7884. name : self.lang('yes'),
  7885. click : function(e) {
  7886. var url = K.trim(urlBox.val()),
  7887. coverUrl = K.trim(coverUrlBox.val()),
  7888. name = nameBox.val(),
  7889. width = widthBox.val(),
  7890. height = heightBox.val();
  7891. if (url == 'http://' || K.invalidUrl(url)) {
  7892. alert(self.lang('invalidUrl'));
  7893. urlBox[0].focus();
  7894. return;
  7895. }
  7896. if (!/^\d*$/.test(width)) {
  7897. alert(self.lang('invalidWidth'));
  7898. widthBox[0].focus();
  7899. return;
  7900. }
  7901. if (!/^\d*$/.test(height)) {
  7902. alert(self.lang('invalidHeight'));
  7903. heightBox[0].focus();
  7904. return;
  7905. }
  7906. if (!coverUrl) {
  7907. var cover = self.themesPath + 'common/blank.gif';
  7908. } else {
  7909. var cover = coverUrl;
  7910. }
  7911. /*
  7912. var html = K.mediaImg(cover, {
  7913. src : url,
  7914. type : K.mediaType(url),
  7915. width : width,
  7916. height : height,
  7917. autostart : autostartBox[0].checked ? 'true' : 'false',
  7918. loop : 'true'
  7919. });
  7920. */
  7921. var html = '<img src="'+cover+'" style="width:'+width+'px;height:'+height+'px;" data-file="'+url+'||'+name+'"/>';
  7922. self.insertHtml(html).hideDialog().focus();
  7923. }
  7924. }
  7925. }),
  7926. div = dialog.div,
  7927. nameBox = K('[name="name"]', div),
  7928. coverUrlBox = K('[name="cover_url"]', div),
  7929. viewCoverServerBtn = K('[name="viewCoverServer"]', div),
  7930. urlBox = K('[name="url"]', div),
  7931. viewServerBtn = K('[name="viewServer"]', div),
  7932. widthBox = K('[name="width"]', div),
  7933. heightBox = K('[name="height"]', div),
  7934. autostartBox = K('[name="autostart"]', div);
  7935. urlBox.val('http://');
  7936. coverUrlBox.val('http://');
  7937. if (allowMediaUpload) {
  7938. var uploadbutton = K.uploadbutton({
  7939. button : K('.ke-upload-button-media', div)[0],
  7940. fieldName : filePostName,
  7941. extraParams : extraParams,
  7942. url : K.addParam(uploadJson, 'dir=media'),
  7943. afterUpload : function(data) {
  7944. console.info(data);
  7945. dialog.hideLoading();
  7946. if (data.error === 0) {
  7947. var url = data.url;
  7948. if (formatUploadUrl) {
  7949. url = K.formatUrl(url, 'absolute');
  7950. }
  7951. urlBox.val(url);
  7952. if (self.afterUpload) {
  7953. self.afterUpload.call(self, url, data, name);
  7954. }
  7955. alert(self.lang('uploadSuccess'));
  7956. } else {
  7957. alert(data.message);
  7958. }
  7959. },
  7960. afterError : function(html) {
  7961. dialog.hideLoading();
  7962. self.errorDialog(html);
  7963. }
  7964. });
  7965. uploadbutton.fileBox.change(function(e) {
  7966. dialog.showLoading(self.lang('uploadLoading'));
  7967. uploadbutton.submit(this);
  7968. });
  7969. } else {
  7970. K('.ke-upload-button-media', div).hide();
  7971. }
  7972. if (allowFileUpload) {
  7973. var uploadbuttonCover = K.uploadbutton({
  7974. button : K('.ke-upload-button-cover', div)[0],
  7975. fieldName : filePostName,
  7976. url : K.addParam(uploadCoverJson, 'dir=file'),
  7977. extraParams : extraParams,
  7978. afterUpload : function(data) {
  7979. dialog.hideLoading();
  7980. if (data.error === 0) {
  7981. var url = data.url;
  7982. if (formatUploadUrl) {
  7983. url = K.formatUrl(url, 'absolute');
  7984. }
  7985. coverUrlBox.val(url);
  7986. if (self.afterUpload) {
  7987. self.afterUpload.call(self, url, data, name);
  7988. }
  7989. alert(self.lang('uploadSuccess'));
  7990. } else {
  7991. alert(data.message);
  7992. }
  7993. },
  7994. afterError : function(html) {
  7995. dialog.hideLoading();
  7996. self.errorDialog(html);
  7997. }
  7998. });
  7999. uploadbuttonCover.fileBox.change(function(e) {
  8000. dialog.showLoading(self.lang('uploadLoading'));
  8001. uploadbuttonCover.submit();
  8002. });
  8003. } else {
  8004. K('.ke-upload-button-cover', div).hide();
  8005. }
  8006. if (allowFileManager) {
  8007. viewServerBtn.click(function(e) {
  8008. var clickFn = function(url, title, id) {
  8009. K('[name="url"]', div).val(url);
  8010. if (self.afterSelectFile) {
  8011. self.afterSelectFile.call(self, url);
  8012. }
  8013. };
  8014. var cur = K('[name="url"]', div).val();
  8015. editorShowUpload(cur, self.fileManagerJson, '音视频库', clickFn, this);
  8016. /*
  8017. self.loadPlugin('filemanager', function() {
  8018. self.plugin.filemanagerDialog({
  8019. viewType : 'LIST',
  8020. dirName : 'media',
  8021. clickFn : function(url, title) {
  8022. if (self.dialogs.length > 1) {
  8023. K('[name="url"]', div).val(url);
  8024. if (self.afterSelectFile) {
  8025. self.afterSelectFile.call(self, url);
  8026. }
  8027. self.hideDialog();
  8028. }
  8029. }
  8030. });
  8031. });
  8032. */
  8033. });
  8034. viewCoverServerBtn.click(function(e) {
  8035. var clickFn = function(url, title, id) {
  8036. K('[name="cover_url"]', div).val(url);
  8037. if (self.afterSelectFile) {
  8038. self.afterSelectFile.call(self, url);
  8039. }
  8040. };
  8041. var cur = K('[name="cover_url"]', div).val();
  8042. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  8043. /*
  8044. self.loadPlugin('filemanager', function() {
  8045. self.plugin.filemanagerDialog({
  8046. viewType : 'LIST',
  8047. dirName : 'file',
  8048. clickFn : function(url, title) {
  8049. if (self.dialogs.length > 1) {
  8050. self.hideDialog();
  8051. }
  8052. }
  8053. });
  8054. });
  8055. */
  8056. });
  8057. } else {
  8058. viewServerBtn.hide();
  8059. viewCoverServerBtn.hide();
  8060. }
  8061. var img = self.plugin.getSelectedMedia();
  8062. if (img) {
  8063. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  8064. urlBox.val(attrs.src);
  8065. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  8066. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  8067. autostartBox[0].checked = (attrs.autostart === 'true');
  8068. }
  8069. urlBox[0].focus();
  8070. urlBox[0].select();
  8071. },
  8072. 'delete' : function() {
  8073. self.plugin.getSelectedMedia().remove();
  8074. self.addBookmark();
  8075. }
  8076. };
  8077. self.clickToolbar(name, self.plugin.media.edit);
  8078. });
  8079. /*******************************************************************************
  8080. * KindEditor - WYSIWYG HTML Editor for Internet
  8081. * Copyright (C) 2006-2011 kindsoft.net
  8082. *
  8083. * @author Roddy <luolonghao@gmail.com>
  8084. * @site http://www.kindsoft.net/
  8085. * @licence http://www.kindsoft.net/license.php
  8086. *******************************************************************************/
  8087. (function(K) {
  8088. function KSWFUpload(options) {
  8089. this.init(options);
  8090. }
  8091. K.extend(KSWFUpload, {
  8092. init : function(options) {
  8093. var self = this;
  8094. options.afterError = options.afterError || function(str) {
  8095. alert(str);
  8096. };
  8097. self.options = options;
  8098. self.progressbars = {};
  8099. self.div = K(options.container).html([
  8100. '<div class="ke-swfupload">',
  8101. '<div class="ke-swfupload-top">',
  8102. '<div class="ke-inline-block ke-swfupload-button">',
  8103. '<input type="button" value="Browse" />',
  8104. '</div>',
  8105. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  8106. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  8107. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  8108. '</span>',
  8109. '</div>',
  8110. '<div class="ke-swfupload-body"></div>',
  8111. '</div>'
  8112. ].join(''));
  8113. self.bodyDiv = K('.ke-swfupload-body', self.div);
  8114. function showError(itemDiv, msg) {
  8115. K('.ke-status > div', itemDiv).hide();
  8116. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  8117. }
  8118. var settings = {
  8119. debug : false,
  8120. upload_url : options.uploadUrl,
  8121. flash_url : options.flashUrl,
  8122. file_post_name : options.filePostName,
  8123. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  8124. button_image_url: options.buttonImageUrl,
  8125. button_width: options.buttonWidth,
  8126. button_height: options.buttonHeight,
  8127. button_cursor : SWFUpload.CURSOR.HAND,
  8128. file_types : options.fileTypes,
  8129. file_types_description : options.fileTypesDesc,
  8130. file_upload_limit : options.fileUploadLimit,
  8131. file_size_limit : options.fileSizeLimit,
  8132. post_params : options.postParams,
  8133. file_queued_handler : function(file) {
  8134. file.url = self.options.fileIconUrl;
  8135. self.appendFile(file);
  8136. },
  8137. file_queue_error_handler : function(file, errorCode, message) {
  8138. var errorName = '';
  8139. switch (errorCode) {
  8140. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  8141. errorName = options.queueLimitExceeded;
  8142. break;
  8143. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  8144. errorName = options.fileExceedsSizeLimit;
  8145. break;
  8146. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  8147. errorName = options.zeroByteFile;
  8148. break;
  8149. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  8150. errorName = options.invalidFiletype;
  8151. break;
  8152. default:
  8153. errorName = options.unknownError;
  8154. break;
  8155. }
  8156. K.DEBUG && alert(errorName);
  8157. },
  8158. upload_start_handler : function(file) {
  8159. var self = this;
  8160. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  8161. K('.ke-status > div', itemDiv).hide();
  8162. K('.ke-progressbar', itemDiv).show();
  8163. },
  8164. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  8165. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  8166. var progressbar = self.progressbars[file.id];
  8167. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  8168. progressbar.percent.html(percent + '%');
  8169. },
  8170. upload_error_handler : function(file, errorCode, message) {
  8171. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  8172. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8173. showError(itemDiv, self.options.errorMessage);
  8174. }
  8175. },
  8176. upload_success_handler : function(file, serverData) {
  8177. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8178. var data = {};
  8179. try {
  8180. data = K.json(serverData);
  8181. } catch (e) {
  8182. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  8183. }
  8184. if (data.error !== 0) {
  8185. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  8186. return;
  8187. }
  8188. file.url = data.url;
  8189. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  8190. K('.ke-status > div', itemDiv).hide();
  8191. }
  8192. };
  8193. self.swfu = new SWFUpload(settings);
  8194. K('.ke-swfupload-startupload input', self.div).click(function() {
  8195. self.swfu.startUpload();
  8196. });
  8197. },
  8198. getUrlList : function() {
  8199. var list = [];
  8200. K('.ke-img', self.bodyDiv).each(function() {
  8201. var img = K(this);
  8202. var status = img.attr('data-status');
  8203. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8204. list.push(img.data('data'));
  8205. }
  8206. });
  8207. return list;
  8208. },
  8209. removeFile : function(fileId) {
  8210. var self = this;
  8211. self.swfu.cancelUpload(fileId);
  8212. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8213. K('.ke-photo', itemDiv).unbind();
  8214. K('.ke-delete', itemDiv).unbind();
  8215. itemDiv.remove();
  8216. },
  8217. removeFiles : function() {
  8218. var self = this;
  8219. K('.ke-item', self.bodyDiv).each(function() {
  8220. self.removeFile(K(this).attr('data-id'));
  8221. });
  8222. },
  8223. appendFile : function(file) {
  8224. var self = this;
  8225. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8226. self.bodyDiv.append(itemDiv);
  8227. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8228. .mouseover(function(e) {
  8229. K(this).addClass('ke-on');
  8230. })
  8231. .mouseout(function(e) {
  8232. K(this).removeClass('ke-on');
  8233. });
  8234. itemDiv.append(photoDiv);
  8235. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8236. photoDiv.append(img);
  8237. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8238. self.removeFile(file.id);
  8239. });
  8240. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8241. K(['<div class="ke-progressbar">',
  8242. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8243. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8244. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8245. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8246. self.progressbars[file.id] = {
  8247. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8248. percent : K('.ke-progressbar-percent', photoDiv)
  8249. };
  8250. },
  8251. remove : function() {
  8252. this.removeFiles();
  8253. this.swfu.destroy();
  8254. this.div.html('');
  8255. }
  8256. });
  8257. K.swfupload = function(element, options) {
  8258. return new KSWFUpload(element, options);
  8259. };
  8260. })(KindEditor);
  8261. KindEditor.plugin('multiimage', function(K) {
  8262. var self = this, name = 'multiimage',
  8263. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8264. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8265. imgPath = self.pluginsPath + 'multiimage/images/',
  8266. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8267. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8268. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8269. filePostName = K.undef(self.filePostName, 'imgFile'),
  8270. lang = self.lang(name + '.');
  8271. self.plugin.multiImageDialog = function(options) {
  8272. var clickFn = options.clickFn,
  8273. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8274. uploadDesc = '';
  8275. var html = [
  8276. '<div style="padding:20px;">',
  8277. '<div class="swfupload">',
  8278. '</div>',
  8279. '</div>'
  8280. ].join('');
  8281. var dialog = self.createDialog({
  8282. name : name,
  8283. width : 650,
  8284. height : 510,
  8285. title : self.lang(name),
  8286. body : html,
  8287. previewBtn : {
  8288. name : lang.insertAll,
  8289. click : function(e) {
  8290. clickFn.call(self, swfupload.getUrlList());
  8291. }
  8292. },
  8293. yesBtn : {
  8294. name : lang.clearAll,
  8295. click : function(e) {
  8296. swfupload.removeFiles();
  8297. }
  8298. },
  8299. beforeRemove : function() {
  8300. if (!K.IE || K.V <= 8) {
  8301. swfupload.remove();
  8302. }
  8303. }
  8304. }),
  8305. div = dialog.div;
  8306. var swfupload = K.swfupload({
  8307. container : K('.swfupload', div),
  8308. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8309. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8310. buttonHeight : 23,
  8311. fileIconUrl : imgPath + 'image.png',
  8312. uploadDesc : uploadDesc,
  8313. startButtonValue : lang.startUpload,
  8314. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8315. //uploadMediaUrl : K.addParam(uploadMediaUrl, 'dir=media'),
  8316. flashUrl : imgPath + 'swfupload.swf',
  8317. filePostName : filePostName,
  8318. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8319. fileTypesDesc : 'Image Files',
  8320. fileUploadLimit : imageUploadLimit,
  8321. fileSizeLimit : imageSizeLimit,
  8322. postParams : K.undef(self.extraFileUploadParams, {}),
  8323. queueLimitExceeded : lang.queueLimitExceeded,
  8324. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8325. zeroByteFile : lang.zeroByteFile,
  8326. invalidFiletype : lang.invalidFiletype,
  8327. unknownError : lang.unknownError,
  8328. pendingMessage : lang.pending,
  8329. errorMessage : lang.uploadError,
  8330. afterError : function(html) {
  8331. self.errorDialog(html);
  8332. }
  8333. });
  8334. return dialog;
  8335. };
  8336. self.clickToolbar(name, function() {
  8337. self.plugin.multiImageDialog({
  8338. clickFn : function (urlList) {
  8339. if (urlList.length === 0) {
  8340. return;
  8341. }
  8342. K.each(urlList, function(i, data) {
  8343. if (self.afterUpload) {
  8344. self.afterUpload.call(self, data.url, data, 'multiimage');
  8345. }
  8346. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8347. });
  8348. setTimeout(function() {
  8349. self.hideDialog().focus();
  8350. }, 0);
  8351. }
  8352. });
  8353. });
  8354. });
  8355. /* ******************* */
  8356. /* Constructor & Init */
  8357. /* ******************* */
  8358. (function() {
  8359. window.SWFUpload = function (settings) {
  8360. this.initSWFUpload(settings);
  8361. };
  8362. SWFUpload.prototype.initSWFUpload = function (settings) {
  8363. try {
  8364. this.customSettings = {};
  8365. this.settings = settings;
  8366. this.eventQueue = [];
  8367. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8368. this.movieElement = null;
  8369. SWFUpload.instances[this.movieName] = this;
  8370. this.initSettings();
  8371. this.loadFlash();
  8372. this.displayDebugInfo();
  8373. } catch (ex) {
  8374. delete SWFUpload.instances[this.movieName];
  8375. throw ex;
  8376. }
  8377. };
  8378. /* *************** */
  8379. /* Static Members */
  8380. /* *************** */
  8381. SWFUpload.instances = {};
  8382. SWFUpload.movieCount = 0;
  8383. SWFUpload.version = "2.2.0 2009-03-25";
  8384. SWFUpload.QUEUE_ERROR = {
  8385. QUEUE_LIMIT_EXCEEDED : -100,
  8386. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8387. ZERO_BYTE_FILE : -120,
  8388. INVALID_FILETYPE : -130
  8389. };
  8390. SWFUpload.UPLOAD_ERROR = {
  8391. HTTP_ERROR : -200,
  8392. MISSING_UPLOAD_URL : -210,
  8393. IO_ERROR : -220,
  8394. SECURITY_ERROR : -230,
  8395. UPLOAD_LIMIT_EXCEEDED : -240,
  8396. UPLOAD_FAILED : -250,
  8397. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8398. FILE_VALIDATION_FAILED : -270,
  8399. FILE_CANCELLED : -280,
  8400. UPLOAD_STOPPED : -290
  8401. };
  8402. SWFUpload.FILE_STATUS = {
  8403. QUEUED : -1,
  8404. IN_PROGRESS : -2,
  8405. ERROR : -3,
  8406. COMPLETE : -4,
  8407. CANCELLED : -5
  8408. };
  8409. SWFUpload.BUTTON_ACTION = {
  8410. SELECT_FILE : -100,
  8411. SELECT_FILES : -110,
  8412. START_UPLOAD : -120
  8413. };
  8414. SWFUpload.CURSOR = {
  8415. ARROW : -1,
  8416. HAND : -2
  8417. };
  8418. SWFUpload.WINDOW_MODE = {
  8419. WINDOW : "window",
  8420. TRANSPARENT : "transparent",
  8421. OPAQUE : "opaque"
  8422. };
  8423. SWFUpload.completeURL = function(url) {
  8424. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8425. return url;
  8426. }
  8427. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8428. var indexSlash = window.location.pathname.lastIndexOf("/");
  8429. var path;
  8430. if (indexSlash <= 0) {
  8431. path = "/";
  8432. } else {
  8433. path = window.location.pathname.substr(0, indexSlash) + "/";
  8434. }
  8435. return /*currentURL +*/ path + url;
  8436. };
  8437. /* ******************** */
  8438. /* Instance Members */
  8439. /* ******************** */
  8440. SWFUpload.prototype.initSettings = function () {
  8441. this.ensureDefault = function (settingName, defaultValue) {
  8442. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8443. };
  8444. this.ensureDefault("upload_url", "");
  8445. this.ensureDefault("preserve_relative_urls", false);
  8446. this.ensureDefault("file_post_name", "Filedata");
  8447. this.ensureDefault("post_params", {});
  8448. this.ensureDefault("use_query_string", false);
  8449. this.ensureDefault("requeue_on_error", false);
  8450. this.ensureDefault("http_success", []);
  8451. this.ensureDefault("assume_success_timeout", 0);
  8452. this.ensureDefault("file_types", "*.*");
  8453. this.ensureDefault("file_types_description", "All Files");
  8454. this.ensureDefault("file_size_limit", 0);
  8455. this.ensureDefault("file_upload_limit", 0);
  8456. this.ensureDefault("file_queue_limit", 0);
  8457. this.ensureDefault("flash_url", "swfupload.swf");
  8458. this.ensureDefault("prevent_swf_caching", true);
  8459. this.ensureDefault("button_image_url", "");
  8460. this.ensureDefault("button_width", 1);
  8461. this.ensureDefault("button_height", 1);
  8462. this.ensureDefault("button_text", "");
  8463. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8464. this.ensureDefault("button_text_top_padding", 0);
  8465. this.ensureDefault("button_text_left_padding", 0);
  8466. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8467. this.ensureDefault("button_disabled", false);
  8468. this.ensureDefault("button_placeholder_id", "");
  8469. this.ensureDefault("button_placeholder", null);
  8470. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8471. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8472. this.ensureDefault("debug", false);
  8473. this.settings.debug_enabled = this.settings.debug;
  8474. this.settings.return_upload_start_handler = this.returnUploadStart;
  8475. this.ensureDefault("swfupload_loaded_handler", null);
  8476. this.ensureDefault("file_dialog_start_handler", null);
  8477. this.ensureDefault("file_queued_handler", null);
  8478. this.ensureDefault("file_queue_error_handler", null);
  8479. this.ensureDefault("file_dialog_complete_handler", null);
  8480. this.ensureDefault("upload_start_handler", null);
  8481. this.ensureDefault("upload_progress_handler", null);
  8482. this.ensureDefault("upload_error_handler", null);
  8483. this.ensureDefault("upload_success_handler", null);
  8484. this.ensureDefault("upload_complete_handler", null);
  8485. this.ensureDefault("debug_handler", this.debugMessage);
  8486. this.ensureDefault("custom_settings", {});
  8487. this.customSettings = this.settings.custom_settings;
  8488. if (!!this.settings.prevent_swf_caching) {
  8489. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8490. }
  8491. if (!this.settings.preserve_relative_urls) {
  8492. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8493. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8494. }
  8495. delete this.ensureDefault;
  8496. };
  8497. SWFUpload.prototype.loadFlash = function () {
  8498. var targetElement, tempParent;
  8499. if (document.getElementById(this.movieName) !== null) {
  8500. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8501. }
  8502. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8503. if (targetElement == undefined) {
  8504. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8505. }
  8506. tempParent = document.createElement("div");
  8507. tempParent.innerHTML = this.getFlashHTML();
  8508. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8509. if (window[this.movieName] == undefined) {
  8510. window[this.movieName] = this.getMovieElement();
  8511. }
  8512. };
  8513. SWFUpload.prototype.getFlashHTML = function () {
  8514. var classid = '';
  8515. if (KindEditor.IE && KindEditor.V > 8) {
  8516. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8517. }
  8518. 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">',
  8519. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8520. '<param name="movie" value="', this.settings.flash_url, '" />',
  8521. '<param name="quality" value="high" />',
  8522. '<param name="menu" value="false" />',
  8523. '<param name="allowScriptAccess" value="always" />',
  8524. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8525. '</object>'].join("");
  8526. };
  8527. SWFUpload.prototype.getFlashVars = function () {
  8528. var paramString = this.buildParamString();
  8529. var httpSuccessString = this.settings.http_success.join(",");
  8530. return ["movieName=", encodeURIComponent(this.movieName),
  8531. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8532. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8533. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8534. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8535. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8536. "&amp;params=", encodeURIComponent(paramString),
  8537. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8538. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8539. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8540. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8541. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8542. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8543. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8544. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8545. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8546. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8547. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8548. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8549. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8550. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8551. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8552. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8553. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8554. ].join("");
  8555. };
  8556. SWFUpload.prototype.getMovieElement = function () {
  8557. if (this.movieElement == undefined) {
  8558. this.movieElement = document.getElementById(this.movieName);
  8559. }
  8560. if (this.movieElement === null) {
  8561. throw "Could not find Flash element";
  8562. }
  8563. return this.movieElement;
  8564. };
  8565. SWFUpload.prototype.buildParamString = function () {
  8566. var postParams = this.settings.post_params;
  8567. var paramStringPairs = [];
  8568. if (typeof(postParams) === "object") {
  8569. for (var name in postParams) {
  8570. if (postParams.hasOwnProperty(name)) {
  8571. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8572. }
  8573. }
  8574. }
  8575. return paramStringPairs.join("&amp;");
  8576. };
  8577. SWFUpload.prototype.destroy = function () {
  8578. try {
  8579. this.cancelUpload(null, false);
  8580. var movieElement = null;
  8581. movieElement = this.getMovieElement();
  8582. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8583. for (var i in movieElement) {
  8584. try {
  8585. if (typeof(movieElement[i]) === "function") {
  8586. movieElement[i] = null;
  8587. }
  8588. } catch (ex1) {}
  8589. }
  8590. try {
  8591. movieElement.parentNode.removeChild(movieElement);
  8592. } catch (ex) {}
  8593. }
  8594. window[this.movieName] = null;
  8595. SWFUpload.instances[this.movieName] = null;
  8596. delete SWFUpload.instances[this.movieName];
  8597. this.movieElement = null;
  8598. this.settings = null;
  8599. this.customSettings = null;
  8600. this.eventQueue = null;
  8601. this.movieName = null;
  8602. return true;
  8603. } catch (ex2) {
  8604. return false;
  8605. }
  8606. };
  8607. SWFUpload.prototype.displayDebugInfo = function () {
  8608. this.debug(
  8609. [
  8610. "---SWFUpload Instance Info---\n",
  8611. "Version: ", SWFUpload.version, "\n",
  8612. "Movie Name: ", this.movieName, "\n",
  8613. "Settings:\n",
  8614. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8615. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8616. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8617. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8618. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8619. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8620. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8621. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8622. "\t", "file_types: ", this.settings.file_types, "\n",
  8623. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8624. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8625. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8626. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8627. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8628. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8629. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8630. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8631. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8632. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8633. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8634. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8635. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8636. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8637. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8638. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8639. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8640. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8641. "Event Handlers:\n",
  8642. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8643. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8644. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8645. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8646. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8647. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8648. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8649. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8650. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8651. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8652. ].join("")
  8653. );
  8654. };
  8655. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8656. the maintain v2 API compatibility
  8657. */
  8658. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8659. if (value == undefined) {
  8660. return (this.settings[name] = default_value);
  8661. } else {
  8662. return (this.settings[name] = value);
  8663. }
  8664. };
  8665. SWFUpload.prototype.getSetting = function (name) {
  8666. if (this.settings[name] != undefined) {
  8667. return this.settings[name];
  8668. }
  8669. return "";
  8670. };
  8671. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8672. argumentArray = argumentArray || [];
  8673. var movieElement = this.getMovieElement();
  8674. var returnValue, returnString;
  8675. try {
  8676. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8677. returnValue = eval(returnString);
  8678. } catch (ex) {
  8679. throw "Call to " + functionName + " failed";
  8680. }
  8681. if (returnValue != undefined && typeof returnValue.post === "object") {
  8682. returnValue = this.unescapeFilePostParams(returnValue);
  8683. }
  8684. return returnValue;
  8685. };
  8686. /* *****************************
  8687. -- Flash control methods --
  8688. Your UI should use these
  8689. to operate SWFUpload
  8690. ***************************** */
  8691. SWFUpload.prototype.selectFile = function () {
  8692. this.callFlash("SelectFile");
  8693. };
  8694. SWFUpload.prototype.selectFiles = function () {
  8695. this.callFlash("SelectFiles");
  8696. };
  8697. SWFUpload.prototype.startUpload = function (fileID) {
  8698. this.callFlash("StartUpload", [fileID]);
  8699. };
  8700. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8701. if (triggerErrorEvent !== false) {
  8702. triggerErrorEvent = true;
  8703. }
  8704. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8705. };
  8706. SWFUpload.prototype.stopUpload = function () {
  8707. this.callFlash("StopUpload");
  8708. };
  8709. /* ************************
  8710. * Settings methods
  8711. * These methods change the SWFUpload settings.
  8712. * SWFUpload settings should not be changed directly on the settings object
  8713. * since many of the settings need to be passed to Flash in order to take
  8714. * effect.
  8715. * *********************** */
  8716. SWFUpload.prototype.getStats = function () {
  8717. return this.callFlash("GetStats");
  8718. };
  8719. SWFUpload.prototype.setStats = function (statsObject) {
  8720. this.callFlash("SetStats", [statsObject]);
  8721. };
  8722. SWFUpload.prototype.getFile = function (fileID) {
  8723. if (typeof(fileID) === "number") {
  8724. return this.callFlash("GetFileByIndex", [fileID]);
  8725. } else {
  8726. return this.callFlash("GetFile", [fileID]);
  8727. }
  8728. };
  8729. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8730. return this.callFlash("AddFileParam", [fileID, name, value]);
  8731. };
  8732. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8733. this.callFlash("RemoveFileParam", [fileID, name]);
  8734. };
  8735. SWFUpload.prototype.setUploadURL = function (url) {
  8736. this.settings.upload_url = url.toString();
  8737. this.callFlash("SetUploadURL", [url]);
  8738. };
  8739. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8740. this.settings.post_params = paramsObject;
  8741. this.callFlash("SetPostParams", [paramsObject]);
  8742. };
  8743. SWFUpload.prototype.addPostParam = function (name, value) {
  8744. this.settings.post_params[name] = value;
  8745. this.callFlash("SetPostParams", [this.settings.post_params]);
  8746. };
  8747. SWFUpload.prototype.removePostParam = function (name) {
  8748. delete this.settings.post_params[name];
  8749. this.callFlash("SetPostParams", [this.settings.post_params]);
  8750. };
  8751. SWFUpload.prototype.setFileTypes = function (types, description) {
  8752. this.settings.file_types = types;
  8753. this.settings.file_types_description = description;
  8754. this.callFlash("SetFileTypes", [types, description]);
  8755. };
  8756. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8757. this.settings.file_size_limit = fileSizeLimit;
  8758. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8759. };
  8760. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8761. this.settings.file_upload_limit = fileUploadLimit;
  8762. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8763. };
  8764. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8765. this.settings.file_queue_limit = fileQueueLimit;
  8766. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8767. };
  8768. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8769. this.settings.file_post_name = filePostName;
  8770. this.callFlash("SetFilePostName", [filePostName]);
  8771. };
  8772. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8773. this.settings.use_query_string = useQueryString;
  8774. this.callFlash("SetUseQueryString", [useQueryString]);
  8775. };
  8776. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8777. this.settings.requeue_on_error = requeueOnError;
  8778. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8779. };
  8780. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8781. if (typeof http_status_codes === "string") {
  8782. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8783. }
  8784. this.settings.http_success = http_status_codes;
  8785. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8786. };
  8787. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8788. this.settings.assume_success_timeout = timeout_seconds;
  8789. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8790. };
  8791. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8792. this.settings.debug_enabled = debugEnabled;
  8793. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8794. };
  8795. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8796. if (buttonImageURL == undefined) {
  8797. buttonImageURL = "";
  8798. }
  8799. this.settings.button_image_url = buttonImageURL;
  8800. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8801. };
  8802. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8803. this.settings.button_width = width;
  8804. this.settings.button_height = height;
  8805. var movie = this.getMovieElement();
  8806. if (movie != undefined) {
  8807. movie.style.width = width + "px";
  8808. movie.style.height = height + "px";
  8809. }
  8810. this.callFlash("SetButtonDimensions", [width, height]);
  8811. };
  8812. SWFUpload.prototype.setButtonText = function (html) {
  8813. this.settings.button_text = html;
  8814. this.callFlash("SetButtonText", [html]);
  8815. };
  8816. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8817. this.settings.button_text_top_padding = top;
  8818. this.settings.button_text_left_padding = left;
  8819. this.callFlash("SetButtonTextPadding", [left, top]);
  8820. };
  8821. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8822. this.settings.button_text_style = css;
  8823. this.callFlash("SetButtonTextStyle", [css]);
  8824. };
  8825. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8826. this.settings.button_disabled = isDisabled;
  8827. this.callFlash("SetButtonDisabled", [isDisabled]);
  8828. };
  8829. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8830. this.settings.button_action = buttonAction;
  8831. this.callFlash("SetButtonAction", [buttonAction]);
  8832. };
  8833. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8834. this.settings.button_cursor = cursor;
  8835. this.callFlash("SetButtonCursor", [cursor]);
  8836. };
  8837. /* *******************************
  8838. Flash Event Interfaces
  8839. These functions are used by Flash to trigger the various
  8840. events.
  8841. All these functions a Private.
  8842. Because the ExternalInterface library is buggy the event calls
  8843. are added to a queue and the queue then executed by a setTimeout.
  8844. This ensures that events are executed in a determinate order and that
  8845. the ExternalInterface bugs are avoided.
  8846. ******************************* */
  8847. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8848. if (argumentArray == undefined) {
  8849. argumentArray = [];
  8850. } else if (!(argumentArray instanceof Array)) {
  8851. argumentArray = [argumentArray];
  8852. }
  8853. var self = this;
  8854. if (typeof this.settings[handlerName] === "function") {
  8855. this.eventQueue.push(function () {
  8856. this.settings[handlerName].apply(this, argumentArray);
  8857. });
  8858. setTimeout(function () {
  8859. self.executeNextEvent();
  8860. }, 0);
  8861. } else if (this.settings[handlerName] !== null) {
  8862. throw "Event handler " + handlerName + " is unknown or is not a function";
  8863. }
  8864. };
  8865. SWFUpload.prototype.executeNextEvent = function () {
  8866. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8867. if (typeof(f) === "function") {
  8868. f.apply(this);
  8869. }
  8870. };
  8871. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8872. var reg = /[$]([0-9a-f]{4})/i;
  8873. var unescapedPost = {};
  8874. var uk;
  8875. if (file != undefined) {
  8876. for (var k in file.post) {
  8877. if (file.post.hasOwnProperty(k)) {
  8878. uk = k;
  8879. var match;
  8880. while ((match = reg.exec(uk)) !== null) {
  8881. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8882. }
  8883. unescapedPost[uk] = file.post[k];
  8884. }
  8885. }
  8886. file.post = unescapedPost;
  8887. }
  8888. return file;
  8889. };
  8890. SWFUpload.prototype.testExternalInterface = function () {
  8891. try {
  8892. return this.callFlash("TestExternalInterface");
  8893. } catch (ex) {
  8894. return false;
  8895. }
  8896. };
  8897. SWFUpload.prototype.flashReady = function () {
  8898. var movieElement = this.getMovieElement();
  8899. if (!movieElement) {
  8900. this.debug("Flash called back ready but the flash movie can't be found.");
  8901. return;
  8902. }
  8903. this.cleanUp(movieElement);
  8904. this.queueEvent("swfupload_loaded_handler");
  8905. };
  8906. SWFUpload.prototype.cleanUp = function (movieElement) {
  8907. try {
  8908. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8909. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8910. for (var key in movieElement) {
  8911. try {
  8912. if (typeof(movieElement[key]) === "function") {
  8913. movieElement[key] = null;
  8914. }
  8915. } catch (ex) {
  8916. }
  8917. }
  8918. }
  8919. } catch (ex1) {
  8920. }
  8921. window["__flash__removeCallback"] = function (instance, name) {
  8922. try {
  8923. if (instance) {
  8924. instance[name] = null;
  8925. }
  8926. } catch (flashEx) {
  8927. }
  8928. };
  8929. };
  8930. /* This is a chance to do something before the browse window opens */
  8931. SWFUpload.prototype.fileDialogStart = function () {
  8932. this.queueEvent("file_dialog_start_handler");
  8933. };
  8934. /* Called when a file is successfully added to the queue. */
  8935. SWFUpload.prototype.fileQueued = function (file) {
  8936. file = this.unescapeFilePostParams(file);
  8937. this.queueEvent("file_queued_handler", file);
  8938. };
  8939. /* Handle errors that occur when an attempt to queue a file fails. */
  8940. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8941. file = this.unescapeFilePostParams(file);
  8942. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8943. };
  8944. /* Called after the file dialog has closed and the selected files have been queued.
  8945. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8946. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8947. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8948. };
  8949. SWFUpload.prototype.uploadStart = function (file) {
  8950. file = this.unescapeFilePostParams(file);
  8951. this.queueEvent("return_upload_start_handler", file);
  8952. };
  8953. SWFUpload.prototype.returnUploadStart = function (file) {
  8954. var returnValue;
  8955. if (typeof this.settings.upload_start_handler === "function") {
  8956. file = this.unescapeFilePostParams(file);
  8957. returnValue = this.settings.upload_start_handler.call(this, file);
  8958. } else if (this.settings.upload_start_handler != undefined) {
  8959. throw "upload_start_handler must be a function";
  8960. }
  8961. if (returnValue === undefined) {
  8962. returnValue = true;
  8963. }
  8964. returnValue = !!returnValue;
  8965. this.callFlash("ReturnUploadStart", [returnValue]);
  8966. };
  8967. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8968. file = this.unescapeFilePostParams(file);
  8969. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8970. };
  8971. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8972. file = this.unescapeFilePostParams(file);
  8973. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8974. };
  8975. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8976. file = this.unescapeFilePostParams(file);
  8977. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8978. };
  8979. SWFUpload.prototype.uploadComplete = function (file) {
  8980. file = this.unescapeFilePostParams(file);
  8981. this.queueEvent("upload_complete_handler", file);
  8982. };
  8983. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8984. internal debug console. You can override this event and have messages written where you want. */
  8985. SWFUpload.prototype.debug = function (message) {
  8986. this.queueEvent("debug_handler", message);
  8987. };
  8988. /* **********************************
  8989. Debug Console
  8990. The debug console is a self contained, in page location
  8991. for debug message to be sent. The Debug Console adds
  8992. itself to the body if necessary.
  8993. The console is automatically scrolled as messages appear.
  8994. If you are using your own debug handler or when you deploy to production and
  8995. have debug disabled you can remove these functions to reduce the file size
  8996. and complexity.
  8997. ********************************** */
  8998. SWFUpload.prototype.debugMessage = function (message) {
  8999. if (this.settings.debug) {
  9000. var exceptionMessage, exceptionValues = [];
  9001. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  9002. for (var key in message) {
  9003. if (message.hasOwnProperty(key)) {
  9004. exceptionValues.push(key + ": " + message[key]);
  9005. }
  9006. }
  9007. exceptionMessage = exceptionValues.join("\n") || "";
  9008. exceptionValues = exceptionMessage.split("\n");
  9009. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  9010. SWFUpload.Console.writeLine(exceptionMessage);
  9011. } else {
  9012. SWFUpload.Console.writeLine(message);
  9013. }
  9014. }
  9015. };
  9016. SWFUpload.Console = {};
  9017. SWFUpload.Console.writeLine = function (message) {
  9018. var console, documentForm;
  9019. try {
  9020. console = document.getElementById("SWFUpload_Console");
  9021. if (!console) {
  9022. documentForm = document.createElement("form");
  9023. document.getElementsByTagName("body")[0].appendChild(documentForm);
  9024. console = document.createElement("textarea");
  9025. console.id = "SWFUpload_Console";
  9026. console.style.fontFamily = "monospace";
  9027. console.setAttribute("wrap", "off");
  9028. console.wrap = "off";
  9029. console.style.overflow = "auto";
  9030. console.style.width = "700px";
  9031. console.style.height = "350px";
  9032. console.style.margin = "5px";
  9033. documentForm.appendChild(console);
  9034. }
  9035. console.value += message + "\n";
  9036. console.scrollTop = console.scrollHeight - console.clientHeight;
  9037. } catch (ex) {
  9038. alert("Exception: " + ex.name + " Message: " + ex.message);
  9039. }
  9040. };
  9041. })();
  9042. (function() {
  9043. /*
  9044. Queue Plug-in
  9045. Features:
  9046. *Adds a cancelQueue() method for cancelling the entire queue.
  9047. *All queued files are uploaded when startUpload() is called.
  9048. *If false is returned from uploadComplete then the queue upload is stopped.
  9049. If false is not returned (strict comparison) then the queue upload is continued.
  9050. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  9051. Set the event handler with the queue_complete_handler setting.
  9052. */
  9053. if (typeof(SWFUpload) === "function") {
  9054. SWFUpload.queue = {};
  9055. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  9056. return function () {
  9057. if (typeof(oldInitSettings) === "function") {
  9058. oldInitSettings.call(this);
  9059. }
  9060. this.queueSettings = {};
  9061. this.queueSettings.queue_cancelled_flag = false;
  9062. this.queueSettings.queue_upload_count = 0;
  9063. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  9064. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  9065. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  9066. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  9067. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  9068. };
  9069. })(SWFUpload.prototype.initSettings);
  9070. SWFUpload.prototype.startUpload = function (fileID) {
  9071. this.queueSettings.queue_cancelled_flag = false;
  9072. this.callFlash("StartUpload", [fileID]);
  9073. };
  9074. SWFUpload.prototype.cancelQueue = function () {
  9075. this.queueSettings.queue_cancelled_flag = true;
  9076. this.stopUpload();
  9077. var stats = this.getStats();
  9078. while (stats.files_queued > 0) {
  9079. this.cancelUpload();
  9080. stats = this.getStats();
  9081. }
  9082. };
  9083. SWFUpload.queue.uploadStartHandler = function (file) {
  9084. var returnValue;
  9085. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  9086. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  9087. }
  9088. returnValue = (returnValue === false) ? false : true;
  9089. this.queueSettings.queue_cancelled_flag = !returnValue;
  9090. return returnValue;
  9091. };
  9092. SWFUpload.queue.uploadCompleteHandler = function (file) {
  9093. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  9094. var continueUpload;
  9095. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  9096. this.queueSettings.queue_upload_count++;
  9097. }
  9098. if (typeof(user_upload_complete_handler) === "function") {
  9099. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  9100. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  9101. continueUpload = false;
  9102. } else {
  9103. continueUpload = true;
  9104. }
  9105. if (continueUpload) {
  9106. var stats = this.getStats();
  9107. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  9108. this.startUpload();
  9109. } else if (this.queueSettings.queue_cancelled_flag === false) {
  9110. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  9111. this.queueSettings.queue_upload_count = 0;
  9112. } else {
  9113. this.queueSettings.queue_cancelled_flag = false;
  9114. this.queueSettings.queue_upload_count = 0;
  9115. }
  9116. }
  9117. };
  9118. }
  9119. })();
  9120. /*******************************************************************************
  9121. * KindEditor - WYSIWYG HTML Editor for Internet
  9122. * Copyright (C) 2006-2011 kindsoft.net
  9123. *
  9124. * @author Roddy <luolonghao@gmail.com>
  9125. * @site http://www.kindsoft.net/
  9126. * @licence http://www.kindsoft.net/license.php
  9127. *******************************************************************************/
  9128. KindEditor.plugin('pagebreak', function(K) {
  9129. var self = this;
  9130. var name = 'pagebreak';
  9131. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  9132. self.clickToolbar(name, function() {
  9133. var cmd = self.cmd, range = cmd.range;
  9134. self.focus();
  9135. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  9136. self.insertHtml(pagebreakHtml + tail);
  9137. if (tail !== '') {
  9138. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9139. range.selectNodeContents(p[0]);
  9140. p.removeAttr('id');
  9141. cmd.select();
  9142. }
  9143. });
  9144. });
  9145. /*******************************************************************************
  9146. * KindEditor - WYSIWYG HTML Editor for Internet
  9147. * Copyright (C) 2006-2011 kindsoft.net
  9148. *
  9149. * @author Roddy <luolonghao@gmail.com>
  9150. * @site http://www.kindsoft.net/
  9151. * @licence http://www.kindsoft.net/license.php
  9152. *******************************************************************************/
  9153. KindEditor.plugin('plainpaste', function(K) {
  9154. var self = this, name = 'plainpaste';
  9155. self.clickToolbar(name, function() {
  9156. var lang = self.lang(name + '.'),
  9157. html = '<div style="padding:10px 20px;">' +
  9158. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9159. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9160. '</div>',
  9161. dialog = self.createDialog({
  9162. name : name,
  9163. width : 450,
  9164. title : self.lang(name),
  9165. body : html,
  9166. yesBtn : {
  9167. name : self.lang('yes'),
  9168. click : function(e) {
  9169. var html = textarea.val();
  9170. html = K.escape(html);
  9171. html = html.replace(/ {2}/g, ' &nbsp;');
  9172. if (self.newlineTag == 'p') {
  9173. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9174. } else {
  9175. html = html.replace(/\n/g, '<br />$&');
  9176. }
  9177. self.insertHtml(html).hideDialog().focus();
  9178. }
  9179. }
  9180. }),
  9181. textarea = K('textarea', dialog.div);
  9182. textarea[0].focus();
  9183. });
  9184. });
  9185. /*******************************************************************************
  9186. * KindEditor - WYSIWYG HTML Editor for Internet
  9187. * Copyright (C) 2006-2011 kindsoft.net
  9188. *
  9189. * @author Roddy <luolonghao@gmail.com>
  9190. * @site http://www.kindsoft.net/
  9191. * @licence http://www.kindsoft.net/license.php
  9192. *******************************************************************************/
  9193. KindEditor.plugin('preview', function(K) {
  9194. var self = this, name = 'preview', undefined;
  9195. self.clickToolbar(name, function() {
  9196. var lang = self.lang(name + '.'),
  9197. html = '<div style="padding:10px 20px;">' +
  9198. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9199. '</div>',
  9200. dialog = self.createDialog({
  9201. name : name,
  9202. width : 750,
  9203. title : self.lang(name),
  9204. body : html
  9205. }),
  9206. iframe = K('iframe', dialog.div),
  9207. doc = K.iframeDoc(iframe);
  9208. doc.open();
  9209. doc.write(self.fullHtml());
  9210. doc.close();
  9211. K(doc.body).css('background-color', '#FFF');
  9212. iframe[0].contentWindow.focus();
  9213. });
  9214. });
  9215. /*******************************************************************************
  9216. * KindEditor - WYSIWYG HTML Editor for Internet
  9217. * Copyright (C) 2006-2011 kindsoft.net
  9218. *
  9219. * @author Roddy <luolonghao@gmail.com>
  9220. * @site http://www.kindsoft.net/
  9221. * @licence http://www.kindsoft.net/license.php
  9222. *******************************************************************************/
  9223. KindEditor.plugin('quickformat', function(K) {
  9224. var self = this, name = 'quickformat',
  9225. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9226. function getFirstChild(knode) {
  9227. var child = knode.first();
  9228. while (child && child.first()) {
  9229. child = child.first();
  9230. }
  9231. return child;
  9232. }
  9233. self.clickToolbar(name, function() {
  9234. self.focus();
  9235. var doc = self.edit.doc,
  9236. range = self.cmd.range,
  9237. child = K(doc.body).first(), next,
  9238. nodeList = [], subList = [],
  9239. bookmark = range.createBookmark(true);
  9240. while(child) {
  9241. next = child.next();
  9242. var firstChild = getFirstChild(child);
  9243. if (!firstChild || firstChild.name != 'img') {
  9244. if (blockMap[child.name]) {
  9245. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9246. child.css('text-indent', '2em');
  9247. } else {
  9248. subList.push(child);
  9249. }
  9250. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9251. if (subList.length > 0) {
  9252. nodeList.push(subList);
  9253. }
  9254. subList = [];
  9255. }
  9256. }
  9257. child = next;
  9258. }
  9259. K.each(nodeList, function(i, subList) {
  9260. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9261. subList[0].before(wrapper);
  9262. K.each(subList, function(i, knode) {
  9263. wrapper.append(knode);
  9264. });
  9265. });
  9266. range.moveToBookmark(bookmark);
  9267. self.addBookmark();
  9268. });
  9269. });
  9270. /*******************************************************************************
  9271. * KindEditor - WYSIWYG HTML Editor for Internet
  9272. * Copyright (C) 2006-2011 kindsoft.net
  9273. *
  9274. * @author Roddy <luolonghao@gmail.com>
  9275. * @site http://www.kindsoft.net/
  9276. * @licence http://www.kindsoft.net/license.php
  9277. *******************************************************************************/
  9278. KindEditor.plugin('table', function(K) {
  9279. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9280. function _setColor(box, color) {
  9281. color = color.toUpperCase();
  9282. box.css('background-color', color);
  9283. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9284. box.html(color);
  9285. }
  9286. var pickerList = [];
  9287. function _initColorPicker(dialogDiv, colorBox) {
  9288. colorBox.bind('click,mousedown', function(e){
  9289. e.stopPropagation();
  9290. });
  9291. function removePicker() {
  9292. K.each(pickerList, function() {
  9293. this.remove();
  9294. });
  9295. pickerList = [];
  9296. K(document).unbind('click,mousedown', removePicker);
  9297. dialogDiv.unbind('click,mousedown', removePicker);
  9298. }
  9299. colorBox.click(function(e) {
  9300. removePicker();
  9301. var box = K(this),
  9302. pos = box.pos();
  9303. var picker = K.colorpicker({
  9304. x : pos.x,
  9305. y : pos.y + box.height(),
  9306. z : 811214,
  9307. selectedColor : K(this).html(),
  9308. colors : self.colorTable,
  9309. noColor : self.lang('noColor'),
  9310. shadowMode : self.shadowMode,
  9311. click : function(color) {
  9312. _setColor(box, color);
  9313. removePicker();
  9314. }
  9315. });
  9316. pickerList.push(picker);
  9317. K(document).bind('click,mousedown', removePicker);
  9318. dialogDiv.bind('click,mousedown', removePicker);
  9319. });
  9320. }
  9321. function _getCellIndex(table, row, cell) {
  9322. var rowSpanCount = 0;
  9323. for (var i = 0, len = row.cells.length; i < len; i++) {
  9324. if (row.cells[i] == cell) {
  9325. break;
  9326. }
  9327. rowSpanCount += row.cells[i].rowSpan - 1;
  9328. }
  9329. return cell.cellIndex - rowSpanCount;
  9330. }
  9331. self.plugin.table = {
  9332. prop : function(isInsert) {
  9333. var html = [
  9334. '<div style="padding:20px;">',
  9335. '<div class="ke-dialog-row">',
  9336. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9337. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9338. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9339. '</div>',
  9340. '<div class="ke-dialog-row">',
  9341. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9342. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9343. '<select name="widthType">',
  9344. '<option value="%">' + lang.percent + '</option>',
  9345. '<option value="px">' + lang.px + '</option>',
  9346. '</select> &nbsp; ',
  9347. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9348. '<select name="heightType">',
  9349. '<option value="%">' + lang.percent + '</option>',
  9350. '<option value="px">' + lang.px + '</option>',
  9351. '</select>',
  9352. '</div>',
  9353. '<div class="ke-dialog-row">',
  9354. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9355. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9356. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9357. '</div>',
  9358. '<div class="ke-dialog-row">',
  9359. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9360. '<select id="keAlign" name="align">',
  9361. '<option value="">' + lang.alignDefault + '</option>',
  9362. '<option value="left">' + lang.alignLeft + '</option>',
  9363. '<option value="center">' + lang.alignCenter + '</option>',
  9364. '<option value="right">' + lang.alignRight + '</option>',
  9365. '</select>',
  9366. '</div>',
  9367. '<div class="ke-dialog-row">',
  9368. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9369. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9370. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9371. '</div>',
  9372. '<div class="ke-dialog-row">',
  9373. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9374. '<span class="ke-inline-block ke-input-color"></span>',
  9375. '</div>',
  9376. '</div>'
  9377. ].join('');
  9378. var bookmark = self.cmd.range.createBookmark();
  9379. var dialog = self.createDialog({
  9380. name : name,
  9381. width : 500,
  9382. title : self.lang(name),
  9383. body : html,
  9384. beforeRemove : function() {
  9385. colorBox.unbind();
  9386. },
  9387. yesBtn : {
  9388. name : self.lang('yes'),
  9389. click : function(e) {
  9390. var rows = rowsBox.val(),
  9391. cols = colsBox.val(),
  9392. width = widthBox.val(),
  9393. height = heightBox.val(),
  9394. widthType = widthTypeBox.val(),
  9395. heightType = heightTypeBox.val(),
  9396. padding = paddingBox.val(),
  9397. spacing = spacingBox.val(),
  9398. align = alignBox.val(),
  9399. border = borderBox.val(),
  9400. borderColor = K(colorBox[0]).html() || '',
  9401. bgColor = K(colorBox[1]).html() || '';
  9402. if (rows == 0 || !/^\d+$/.test(rows)) {
  9403. alert(self.lang('invalidRows'));
  9404. rowsBox[0].focus();
  9405. return;
  9406. }
  9407. if (cols == 0 || !/^\d+$/.test(cols)) {
  9408. alert(self.lang('invalidRows'));
  9409. colsBox[0].focus();
  9410. return;
  9411. }
  9412. if (!/^\d*$/.test(width)) {
  9413. alert(self.lang('invalidWidth'));
  9414. widthBox[0].focus();
  9415. return;
  9416. }
  9417. if (!/^\d*$/.test(height)) {
  9418. alert(self.lang('invalidHeight'));
  9419. heightBox[0].focus();
  9420. return;
  9421. }
  9422. if (!/^\d*$/.test(padding)) {
  9423. alert(self.lang('invalidPadding'));
  9424. paddingBox[0].focus();
  9425. return;
  9426. }
  9427. if (!/^\d*$/.test(spacing)) {
  9428. alert(self.lang('invalidSpacing'));
  9429. spacingBox[0].focus();
  9430. return;
  9431. }
  9432. if (!/^\d*$/.test(border)) {
  9433. alert(self.lang('invalidBorder'));
  9434. borderBox[0].focus();
  9435. return;
  9436. }
  9437. if (table) {
  9438. if (width !== '') {
  9439. table.width(width + widthType);
  9440. } else {
  9441. table.css('width', '');
  9442. }
  9443. if (table[0].width !== undefined) {
  9444. table.removeAttr('width');
  9445. }
  9446. if (height !== '') {
  9447. table.height(height + heightType);
  9448. } else {
  9449. table.css('height', '');
  9450. }
  9451. if (table[0].height !== undefined) {
  9452. table.removeAttr('height');
  9453. }
  9454. table.css('background-color', bgColor);
  9455. if (table[0].bgColor !== undefined) {
  9456. table.removeAttr('bgColor');
  9457. }
  9458. if (padding !== '') {
  9459. table[0].cellPadding = padding;
  9460. } else {
  9461. table.removeAttr('cellPadding');
  9462. }
  9463. if (spacing !== '') {
  9464. table[0].cellSpacing = spacing;
  9465. } else {
  9466. table.removeAttr('cellSpacing');
  9467. }
  9468. if (align !== '') {
  9469. table[0].align = align;
  9470. } else {
  9471. table.removeAttr('align');
  9472. }
  9473. if (border !== '') {
  9474. table.attr('border', border);
  9475. } else {
  9476. table.removeAttr('border');
  9477. }
  9478. if (border === '' || border === '0') {
  9479. table.addClass(zeroborder);
  9480. } else {
  9481. table.removeClass(zeroborder);
  9482. }
  9483. if (borderColor !== '') {
  9484. table.attr('borderColor', borderColor);
  9485. } else {
  9486. table.removeAttr('borderColor');
  9487. }
  9488. self.hideDialog().focus();
  9489. self.cmd.range.moveToBookmark(bookmark);
  9490. self.cmd.select();
  9491. self.addBookmark();
  9492. return;
  9493. }
  9494. var style = '';
  9495. if (width !== '') {
  9496. style += 'width:' + width + widthType + ';';
  9497. }
  9498. if (height !== '') {
  9499. style += 'height:' + height + heightType + ';';
  9500. }
  9501. if (bgColor !== '') {
  9502. style += 'background-color:' + bgColor + ';';
  9503. }
  9504. var html = '<table';
  9505. if (style !== '') {
  9506. html += ' style="' + style + '"';
  9507. }
  9508. if (padding !== '') {
  9509. html += ' cellpadding="' + padding + '"';
  9510. }
  9511. if (spacing !== '') {
  9512. html += ' cellspacing="' + spacing + '"';
  9513. }
  9514. if (align !== '') {
  9515. html += ' align="' + align + '"';
  9516. }
  9517. if (border !== '') {
  9518. html += ' border="' + border + '"';
  9519. }
  9520. if (border === '' || border === '0') {
  9521. html += ' class="' + zeroborder + '"';
  9522. }
  9523. if (borderColor !== '') {
  9524. html += ' bordercolor="' + borderColor + '"';
  9525. }
  9526. html += '>';
  9527. for (var i = 0; i < rows; i++) {
  9528. html += '<tr>';
  9529. for (var j = 0; j < cols; j++) {
  9530. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9531. }
  9532. html += '</tr>';
  9533. }
  9534. html += '</table>';
  9535. if (!K.IE) {
  9536. html += '<br />';
  9537. }
  9538. self.insertHtml(html);
  9539. self.select().hideDialog().focus();
  9540. self.addBookmark();
  9541. }
  9542. }
  9543. }),
  9544. div = dialog.div,
  9545. rowsBox = K('[name="rows"]', div).val(3),
  9546. colsBox = K('[name="cols"]', div).val(2),
  9547. widthBox = K('[name="width"]', div).val(100),
  9548. heightBox = K('[name="height"]', div),
  9549. widthTypeBox = K('[name="widthType"]', div),
  9550. heightTypeBox = K('[name="heightType"]', div),
  9551. paddingBox = K('[name="padding"]', div).val(2),
  9552. spacingBox = K('[name="spacing"]', div).val(0),
  9553. alignBox = K('[name="align"]', div),
  9554. borderBox = K('[name="border"]', div).val(1),
  9555. colorBox = K('.ke-input-color', div);
  9556. _initColorPicker(div, colorBox.eq(0));
  9557. _initColorPicker(div, colorBox.eq(1));
  9558. _setColor(colorBox.eq(0), '#000000');
  9559. _setColor(colorBox.eq(1), '');
  9560. rowsBox[0].focus();
  9561. rowsBox[0].select();
  9562. var table;
  9563. if (isInsert) {
  9564. return;
  9565. }
  9566. table = self.plugin.getSelectedTable();
  9567. if (table) {
  9568. rowsBox.val(table[0].rows.length);
  9569. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9570. rowsBox.attr('disabled', true);
  9571. colsBox.attr('disabled', true);
  9572. var match,
  9573. tableWidth = table[0].style.width || table[0].width,
  9574. tableHeight = table[0].style.height || table[0].height;
  9575. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9576. widthBox.val(match[1]);
  9577. widthTypeBox.val(match[2]);
  9578. } else {
  9579. widthBox.val('');
  9580. }
  9581. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9582. heightBox.val(match[1]);
  9583. heightTypeBox.val(match[2]);
  9584. }
  9585. paddingBox.val(table[0].cellPadding || '');
  9586. spacingBox.val(table[0].cellSpacing || '');
  9587. alignBox.val(table[0].align || '');
  9588. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9589. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9590. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9591. widthBox[0].focus();
  9592. widthBox[0].select();
  9593. }
  9594. },
  9595. cellprop : function() {
  9596. var html = [
  9597. '<div style="padding:20px;">',
  9598. '<div class="ke-dialog-row">',
  9599. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9600. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9601. '<select name="widthType">',
  9602. '<option value="%">' + lang.percent + '</option>',
  9603. '<option value="px">' + lang.px + '</option>',
  9604. '</select> &nbsp; ',
  9605. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9606. '<select name="heightType">',
  9607. '<option value="%">' + lang.percent + '</option>',
  9608. '<option value="px">' + lang.px + '</option>',
  9609. '</select>',
  9610. '</div>',
  9611. '<div class="ke-dialog-row">',
  9612. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9613. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9614. '<option value="">' + lang.alignDefault + '</option>',
  9615. '<option value="left">' + lang.alignLeft + '</option>',
  9616. '<option value="center">' + lang.alignCenter + '</option>',
  9617. '<option value="right">' + lang.alignRight + '</option>',
  9618. '</select> ',
  9619. lang.verticalAlign + ' <select name="verticalAlign">',
  9620. '<option value="">' + lang.alignDefault + '</option>',
  9621. '<option value="top">' + lang.alignTop + '</option>',
  9622. '<option value="middle">' + lang.alignMiddle + '</option>',
  9623. '<option value="bottom">' + lang.alignBottom + '</option>',
  9624. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9625. '</select>',
  9626. '</div>',
  9627. '<div class="ke-dialog-row">',
  9628. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9629. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9630. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9631. '</div>',
  9632. '<div class="ke-dialog-row">',
  9633. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9634. '<span class="ke-inline-block ke-input-color"></span>',
  9635. '</div>',
  9636. '</div>'
  9637. ].join('');
  9638. var bookmark = self.cmd.range.createBookmark();
  9639. var dialog = self.createDialog({
  9640. name : name,
  9641. width : 500,
  9642. title : self.lang('tablecell'),
  9643. body : html,
  9644. beforeRemove : function() {
  9645. colorBox.unbind();
  9646. },
  9647. yesBtn : {
  9648. name : self.lang('yes'),
  9649. click : function(e) {
  9650. var width = widthBox.val(),
  9651. height = heightBox.val(),
  9652. widthType = widthTypeBox.val(),
  9653. heightType = heightTypeBox.val(),
  9654. padding = paddingBox.val(),
  9655. spacing = spacingBox.val(),
  9656. textAlign = textAlignBox.val(),
  9657. verticalAlign = verticalAlignBox.val(),
  9658. border = borderBox.val(),
  9659. borderColor = K(colorBox[0]).html() || '',
  9660. bgColor = K(colorBox[1]).html() || '';
  9661. if (!/^\d*$/.test(width)) {
  9662. alert(self.lang('invalidWidth'));
  9663. widthBox[0].focus();
  9664. return;
  9665. }
  9666. if (!/^\d*$/.test(height)) {
  9667. alert(self.lang('invalidHeight'));
  9668. heightBox[0].focus();
  9669. return;
  9670. }
  9671. if (!/^\d*$/.test(border)) {
  9672. alert(self.lang('invalidBorder'));
  9673. borderBox[0].focus();
  9674. return;
  9675. }
  9676. cell.css({
  9677. width : width !== '' ? (width + widthType) : '',
  9678. height : height !== '' ? (height + heightType) : '',
  9679. 'background-color' : bgColor,
  9680. 'text-align' : textAlign,
  9681. 'vertical-align' : verticalAlign,
  9682. 'border-width' : border,
  9683. 'border-style' : border !== '' ? 'solid' : '',
  9684. 'border-color' : borderColor
  9685. });
  9686. self.hideDialog().focus();
  9687. self.cmd.range.moveToBookmark(bookmark);
  9688. self.cmd.select();
  9689. self.addBookmark();
  9690. }
  9691. }
  9692. }),
  9693. div = dialog.div,
  9694. widthBox = K('[name="width"]', div).val(100),
  9695. heightBox = K('[name="height"]', div),
  9696. widthTypeBox = K('[name="widthType"]', div),
  9697. heightTypeBox = K('[name="heightType"]', div),
  9698. paddingBox = K('[name="padding"]', div).val(2),
  9699. spacingBox = K('[name="spacing"]', div).val(0),
  9700. textAlignBox = K('[name="textAlign"]', div),
  9701. verticalAlignBox = K('[name="verticalAlign"]', div),
  9702. borderBox = K('[name="border"]', div).val(1),
  9703. colorBox = K('.ke-input-color', div);
  9704. _initColorPicker(div, colorBox.eq(0));
  9705. _initColorPicker(div, colorBox.eq(1));
  9706. _setColor(colorBox.eq(0), '#000000');
  9707. _setColor(colorBox.eq(1), '');
  9708. widthBox[0].focus();
  9709. widthBox[0].select();
  9710. var cell = self.plugin.getSelectedCell();
  9711. var match,
  9712. cellWidth = cell[0].style.width || cell[0].width || '',
  9713. cellHeight = cell[0].style.height || cell[0].height || '';
  9714. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9715. widthBox.val(match[1]);
  9716. widthTypeBox.val(match[2]);
  9717. } else {
  9718. widthBox.val('');
  9719. }
  9720. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9721. heightBox.val(match[1]);
  9722. heightTypeBox.val(match[2]);
  9723. }
  9724. textAlignBox.val(cell[0].style.textAlign || '');
  9725. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9726. var border = cell[0].style.borderWidth || '';
  9727. if (border) {
  9728. border = parseInt(border);
  9729. }
  9730. borderBox.val(border);
  9731. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9732. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9733. widthBox[0].focus();
  9734. widthBox[0].select();
  9735. },
  9736. insert : function() {
  9737. this.prop(true);
  9738. },
  9739. 'delete' : function() {
  9740. var table = self.plugin.getSelectedTable();
  9741. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9742. self.cmd.select();
  9743. table.remove();
  9744. self.addBookmark();
  9745. },
  9746. colinsert : function(offset) {
  9747. var table = self.plugin.getSelectedTable()[0],
  9748. row = self.plugin.getSelectedRow()[0],
  9749. cell = self.plugin.getSelectedCell()[0],
  9750. index = cell.cellIndex + offset;
  9751. index += table.rows[0].cells.length - row.cells.length;
  9752. for (var i = 0, len = table.rows.length; i < len; i++) {
  9753. var newRow = table.rows[i],
  9754. newCell = newRow.insertCell(index);
  9755. newCell.innerHTML = K.IE ? '' : '<br />';
  9756. index = _getCellIndex(table, newRow, newCell);
  9757. }
  9758. self.cmd.range.selectNodeContents(cell).collapse(true);
  9759. self.cmd.select();
  9760. self.addBookmark();
  9761. },
  9762. colinsertleft : function() {
  9763. this.colinsert(0);
  9764. },
  9765. colinsertright : function() {
  9766. this.colinsert(1);
  9767. },
  9768. rowinsert : function(offset) {
  9769. var table = self.plugin.getSelectedTable()[0],
  9770. row = self.plugin.getSelectedRow()[0],
  9771. cell = self.plugin.getSelectedCell()[0];
  9772. var rowIndex = row.rowIndex;
  9773. if (offset === 1) {
  9774. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9775. }
  9776. var newRow = table.insertRow(rowIndex);
  9777. for (var i = 0, len = row.cells.length; i < len; i++) {
  9778. if (row.cells[i].rowSpan > 1) {
  9779. len -= row.cells[i].rowSpan - 1;
  9780. }
  9781. var newCell = newRow.insertCell(i);
  9782. if (offset === 1 && row.cells[i].colSpan > 1) {
  9783. newCell.colSpan = row.cells[i].colSpan;
  9784. }
  9785. newCell.innerHTML = K.IE ? '' : '<br />';
  9786. }
  9787. for (var j = rowIndex; j >= 0; j--) {
  9788. var cells = table.rows[j].cells;
  9789. if (cells.length > i) {
  9790. for (var k = cell.cellIndex; k >= 0; k--) {
  9791. if (cells[k].rowSpan > 1) {
  9792. cells[k].rowSpan += 1;
  9793. }
  9794. }
  9795. break;
  9796. }
  9797. }
  9798. self.cmd.range.selectNodeContents(cell).collapse(true);
  9799. self.cmd.select();
  9800. self.addBookmark();
  9801. },
  9802. rowinsertabove : function() {
  9803. this.rowinsert(0);
  9804. },
  9805. rowinsertbelow : function() {
  9806. this.rowinsert(1);
  9807. },
  9808. rowmerge : function() {
  9809. var table = self.plugin.getSelectedTable()[0],
  9810. row = self.plugin.getSelectedRow()[0],
  9811. cell = self.plugin.getSelectedCell()[0],
  9812. rowIndex = row.rowIndex,
  9813. nextRowIndex = rowIndex + cell.rowSpan,
  9814. nextRow = table.rows[nextRowIndex];
  9815. if (table.rows.length <= nextRowIndex) {
  9816. return;
  9817. }
  9818. var cellIndex = cell.cellIndex;
  9819. if (nextRow.cells.length <= cellIndex) {
  9820. return;
  9821. }
  9822. var nextCell = nextRow.cells[cellIndex];
  9823. if (cell.colSpan !== nextCell.colSpan) {
  9824. return;
  9825. }
  9826. cell.rowSpan += nextCell.rowSpan;
  9827. nextRow.deleteCell(cellIndex);
  9828. self.cmd.range.selectNodeContents(cell).collapse(true);
  9829. self.cmd.select();
  9830. self.addBookmark();
  9831. },
  9832. colmerge : function() {
  9833. var table = self.plugin.getSelectedTable()[0],
  9834. row = self.plugin.getSelectedRow()[0],
  9835. cell = self.plugin.getSelectedCell()[0],
  9836. rowIndex = row.rowIndex,
  9837. cellIndex = cell.cellIndex,
  9838. nextCellIndex = cellIndex + 1;
  9839. if (row.cells.length <= nextCellIndex) {
  9840. return;
  9841. }
  9842. var nextCell = row.cells[nextCellIndex];
  9843. if (cell.rowSpan !== nextCell.rowSpan) {
  9844. return;
  9845. }
  9846. cell.colSpan += nextCell.colSpan;
  9847. row.deleteCell(nextCellIndex);
  9848. self.cmd.range.selectNodeContents(cell).collapse(true);
  9849. self.cmd.select();
  9850. self.addBookmark();
  9851. },
  9852. rowsplit : function() {
  9853. var table = self.plugin.getSelectedTable()[0],
  9854. row = self.plugin.getSelectedRow()[0],
  9855. cell = self.plugin.getSelectedCell()[0],
  9856. rowIndex = row.rowIndex;
  9857. if (cell.rowSpan === 1) {
  9858. return;
  9859. }
  9860. var cellIndex = _getCellIndex(table, row, cell);
  9861. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9862. var newRow = table.rows[rowIndex + i],
  9863. newCell = newRow.insertCell(cellIndex);
  9864. if (cell.colSpan > 1) {
  9865. newCell.colSpan = cell.colSpan;
  9866. }
  9867. newCell.innerHTML = K.IE ? '' : '<br />';
  9868. cellIndex = _getCellIndex(table, newRow, newCell);
  9869. }
  9870. K(cell).removeAttr('rowSpan');
  9871. self.cmd.range.selectNodeContents(cell).collapse(true);
  9872. self.cmd.select();
  9873. self.addBookmark();
  9874. },
  9875. colsplit : function() {
  9876. var table = self.plugin.getSelectedTable()[0],
  9877. row = self.plugin.getSelectedRow()[0],
  9878. cell = self.plugin.getSelectedCell()[0],
  9879. cellIndex = cell.cellIndex;
  9880. if (cell.colSpan === 1) {
  9881. return;
  9882. }
  9883. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9884. var newCell = row.insertCell(cellIndex + i);
  9885. if (cell.rowSpan > 1) {
  9886. newCell.rowSpan = cell.rowSpan;
  9887. }
  9888. newCell.innerHTML = K.IE ? '' : '<br />';
  9889. }
  9890. K(cell).removeAttr('colSpan');
  9891. self.cmd.range.selectNodeContents(cell).collapse(true);
  9892. self.cmd.select();
  9893. self.addBookmark();
  9894. },
  9895. coldelete : function() {
  9896. var table = self.plugin.getSelectedTable()[0],
  9897. row = self.plugin.getSelectedRow()[0],
  9898. cell = self.plugin.getSelectedCell()[0],
  9899. index = cell.cellIndex;
  9900. for (var i = 0, len = table.rows.length; i < len; i++) {
  9901. var newRow = table.rows[i],
  9902. newCell = newRow.cells[index];
  9903. if (newCell.colSpan > 1) {
  9904. newCell.colSpan -= 1;
  9905. if (newCell.colSpan === 1) {
  9906. K(newCell).removeAttr('colSpan');
  9907. }
  9908. } else {
  9909. newRow.deleteCell(index);
  9910. }
  9911. if (newCell.rowSpan > 1) {
  9912. i += newCell.rowSpan - 1;
  9913. }
  9914. }
  9915. if (row.cells.length === 0) {
  9916. self.cmd.range.setStartBefore(table).collapse(true);
  9917. self.cmd.select();
  9918. K(table).remove();
  9919. } else {
  9920. self.cmd.selection(true);
  9921. }
  9922. self.addBookmark();
  9923. },
  9924. rowdelete : function() {
  9925. var table = self.plugin.getSelectedTable()[0],
  9926. row = self.plugin.getSelectedRow()[0],
  9927. cell = self.plugin.getSelectedCell()[0],
  9928. rowIndex = row.rowIndex;
  9929. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9930. table.deleteRow(rowIndex + i);
  9931. }
  9932. if (table.rows.length === 0) {
  9933. self.cmd.range.setStartBefore(table).collapse(true);
  9934. self.cmd.select();
  9935. K(table).remove();
  9936. } else {
  9937. self.cmd.selection(true);
  9938. }
  9939. self.addBookmark();
  9940. }
  9941. };
  9942. self.clickToolbar(name, self.plugin.table.prop);
  9943. });
  9944. /*******************************************************************************
  9945. * KindEditor - WYSIWYG HTML Editor for Internet
  9946. * Copyright (C) 2006-2011 kindsoft.net
  9947. *
  9948. * @author Roddy <luolonghao@gmail.com>
  9949. * @site http://www.kindsoft.net/
  9950. * @licence http://www.kindsoft.net/license.php
  9951. *******************************************************************************/
  9952. KindEditor.plugin('template', function(K) {
  9953. var self = this, name = 'template', lang = self.lang(name + '.'),
  9954. htmlPath = self.pluginsPath + name + '/html/';
  9955. function getFilePath(fileName) {
  9956. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9957. }
  9958. self.clickToolbar(name, function() {
  9959. var lang = self.lang(name + '.'),
  9960. arr = ['<div style="padding:10px 20px;">',
  9961. '<div class="ke-header">',
  9962. '<div class="ke-left">',
  9963. lang. selectTemplate + ' <select>'];
  9964. K.each(lang.fileList, function(key, val) {
  9965. arr.push('<option value="' + key + '">' + val + '</option>');
  9966. });
  9967. html = [arr.join(''),
  9968. '</select></div>',
  9969. '<div class="ke-right">',
  9970. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9971. '</div>',
  9972. '<div class="ke-clearfix"></div>',
  9973. '</div>',
  9974. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9975. '</div>'].join('');
  9976. var dialog = self.createDialog({
  9977. name : name,
  9978. width : 500,
  9979. title : self.lang(name),
  9980. body : html,
  9981. yesBtn : {
  9982. name : self.lang('yes'),
  9983. click : function(e) {
  9984. var doc = K.iframeDoc(iframe);
  9985. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9986. }
  9987. }
  9988. });
  9989. var selectBox = K('select', dialog.div),
  9990. checkbox = K('[name="replaceFlag"]', dialog.div),
  9991. iframe = K('iframe', dialog.div);
  9992. checkbox[0].checked = true;
  9993. iframe.attr('src', getFilePath(selectBox.val()));
  9994. selectBox.change(function() {
  9995. iframe.attr('src', getFilePath(this.value));
  9996. });
  9997. });
  9998. });
  9999. /*******************************************************************************
  10000. * KindEditor - WYSIWYG HTML Editor for Internet
  10001. * Copyright (C) 2006-2011 kindsoft.net
  10002. *
  10003. * @author Roddy <luolonghao@gmail.com>
  10004. * @site http://www.kindsoft.net/
  10005. * @licence http://www.kindsoft.net/license.php
  10006. *******************************************************************************/
  10007. KindEditor.plugin('wordpaste', function(K) {
  10008. var self = this, name = 'wordpaste';
  10009. self.clickToolbar(name, function() {
  10010. var lang = self.lang(name + '.'),
  10011. html = '<div style="padding:10px 20px;">' +
  10012. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  10013. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  10014. '</div>',
  10015. dialog = self.createDialog({
  10016. name : name,
  10017. width : 450,
  10018. title : self.lang(name),
  10019. body : html,
  10020. yesBtn : {
  10021. name : self.lang('yes'),
  10022. click : function(e) {
  10023. var str = doc.body.innerHTML;
  10024. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  10025. self.insertHtml(str).hideDialog().focus();
  10026. }
  10027. }
  10028. }),
  10029. div = dialog.div,
  10030. iframe = K('iframe', div),
  10031. doc = K.iframeDoc(iframe);
  10032. if (!K.IE) {
  10033. doc.designMode = 'on';
  10034. }
  10035. doc.open();
  10036. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  10037. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  10038. if (!K.IE) {
  10039. doc.write('<br />');
  10040. }
  10041. doc.write('</body></html>');
  10042. doc.close();
  10043. if (K.IE) {
  10044. doc.body.contentEditable = 'true';
  10045. }
  10046. iframe[0].contentWindow.focus();
  10047. });
  10048. });
  10049. KindEditor.plugin('fixtoolbar', function (K) {
  10050. var self = this;
  10051. if (!self.fixToolBar) {
  10052. return;
  10053. }
  10054. function init() {
  10055. var toolbar = K('.ke-toolbar');
  10056. var originY = toolbar.pos().y;
  10057. K(window).bind('scroll', function () {
  10058. if (toolbar.css('position') == 'fixed') {
  10059. if(document.body.scrollTop - originY < 0){
  10060. toolbar.css('position', 'static');
  10061. toolbar.css('top', 'auto');
  10062. }
  10063. } else {
  10064. if (toolbar.pos().y - document.body.scrollTop < 0) {
  10065. toolbar.css('position', 'fixed');
  10066. toolbar.css('top', 0);
  10067. }
  10068. }
  10069. });
  10070. }
  10071. if (self.isCreated) {
  10072. init();
  10073. } else {
  10074. self.afterCreate(init);
  10075. }
  10076. });
  10077. //自定义资源库
  10078. KindEditor.plugin('res', function(K) {
  10079. var self = this;
  10080. // 点击图标时执行
  10081. self.clickToolbar('res', function() {
  10082. var clickFn = function(url, title, id) {
  10083. var html = '<embed src="{url}" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" id="{id}"/>';
  10084. html = html.replace('{url}', url);
  10085. html = html.replace('{id}', id);
  10086. self.insertHtml(html);
  10087. };
  10088. editorShowUpload('', self.fileManagerJson, '视频库', clickFn, this);
  10089. });
  10090. });
  10091. function autoImg(self) {
  10092. var index = self.index;
  10093. var haspicContainer = document.getElementById("has_pic_" + index);
  10094. if (haspicContainer == null) {
  10095. haspicContainer = document.createElement("div");
  10096. haspicContainer.id = "has_pic_" + index;
  10097. haspicContainer.innerHTML = "<input type='text' id='piclist_"+index+"' value='' style='display:none;'/><div id='upload_"+index+"' style='color:red'><b>您有图片需要上传到服务器</b>&nbsp;&nbsp;<a href='javascript:uploadpic(\""+self.uploadJson+"\", \""+self.filePostName+"\", \""+index+"\");' style='color:red'>[上传]</a></div><div id='confirm_"+index+"'></div>";
  10098. $(".ke-toolbar").eq(index).after(haspicContainer);
  10099. }
  10100. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10101. var piccount = 0;
  10102. var sstr = '';
  10103. $(img).each(function (i) {
  10104. var that = $(this);
  10105. var host = gethost(self.uploadJson);
  10106. var yhost = '';
  10107. if (self.uploadYunJson && self.uploadYunJson.host) {
  10108. yhost = gethost(self.uploadYunJson.host);
  10109. }
  10110. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10111. var n = gethost(that.attr("src"));
  10112. if (yhost) {
  10113. if (host != n && yhost != n) {
  10114. piccount++;
  10115. if (i == $(img).length - 1)
  10116. sstr += that.attr("src");
  10117. else
  10118. sstr += that.attr("src") + ",";
  10119. }
  10120. } else {
  10121. if (host != n) {
  10122. piccount++;
  10123. if (i == $(img).length - 1)
  10124. sstr += that.attr("src");
  10125. else
  10126. sstr += that.attr("src") + ",";
  10127. }
  10128. }
  10129. }
  10130. });
  10131. $("#piclist_" + index).val(encodeURIComponent(sstr));
  10132. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  10133. }
  10134. function closeupload(index) {
  10135. $("#has_pic_" + index).hide();
  10136. $("#upload_" + index).show();
  10137. }
  10138. function uploadpic(url, name, index) {
  10139. var piclist = encodeURI($("#piclist_" + index).val());
  10140. if (piclist.length == 0) return false;
  10141. $.ajax({
  10142. url: url.replace('kindeditor', 'copys') + '&json=1',
  10143. data: name + "=" + piclist,
  10144. type: "POST",
  10145. dataType: "json",
  10146. beforeSend: function () {
  10147. $("#upload_" + index).hide();
  10148. $("#confirm_" + index).text("正在上传中...");
  10149. },
  10150. success: function (msg) {
  10151. var url = msg.data;
  10152. if (url !== "") {
  10153. var str = new Array();
  10154. str = url.split(',');
  10155. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10156. $(img).each(function (i) {
  10157. var that = $(this);
  10158. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10159. that.attr("src", str[i]);
  10160. that.attr("data-ke-src", str[i]);
  10161. }
  10162. });
  10163. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  10164. }
  10165. else $("#confirm_" + index).text("上传失败!");
  10166. }
  10167. });
  10168. }
  10169. function gethost(url){
  10170. var reg = /^http(s)?:\/\/(.*?)\//;
  10171. return reg.exec(url)[2];
  10172. }