kindeditor-all-min.js 328 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759
  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. if (typeof(val) == 'string') {
  88. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  89. } else {
  90. return val;
  91. }
  92. }
  93. function _unescape(val) {
  94. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  95. }
  96. function _toCamel(str) {
  97. var arr = str.split('-');
  98. str = '';
  99. _each(arr, function(key, val) {
  100. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  101. });
  102. return str;
  103. }
  104. function _toHex(val) {
  105. function hex(d) {
  106. var s = parseInt(d, 10).toString(16).toUpperCase();
  107. return s.length > 1 ? s : '0' + s;
  108. }
  109. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  110. function($0, $1, $2, $3) {
  111. return '#' + hex($1) + hex($2) + hex($3);
  112. }
  113. );
  114. }
  115. function _toMap(val, delimiter) {
  116. delimiter = delimiter === undefined ? ',' : delimiter;
  117. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  118. _each(arr, function(key, val) {
  119. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  120. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  121. map[i.toString()] = true;
  122. }
  123. } else {
  124. map[val] = true;
  125. }
  126. });
  127. return map;
  128. }
  129. function _toArray(obj, offset) {
  130. return Array.prototype.slice.call(obj, offset || 0);
  131. }
  132. function _undef(val, defaultVal) {
  133. return val === undefined ? defaultVal : val;
  134. }
  135. function _invalidUrl(url) {
  136. return !url || /[<>"]/.test(url);
  137. }
  138. function _addParam(url, param) {
  139. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  140. }
  141. function _extend(child, parent, proto) {
  142. if (!proto) {
  143. proto = parent;
  144. parent = null;
  145. }
  146. var childProto;
  147. if (parent) {
  148. var fn = function () {};
  149. fn.prototype = parent.prototype;
  150. childProto = new fn();
  151. _each(proto, function(key, val) {
  152. childProto[key] = val;
  153. });
  154. } else {
  155. childProto = proto;
  156. }
  157. childProto.constructor = child;
  158. child.prototype = childProto;
  159. child.parent = parent ? parent.prototype : null;
  160. }
  161. function _json(text) {
  162. var match;
  163. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  164. text = match[0];
  165. }
  166. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  167. cx.lastIndex = 0;
  168. if (cx.test(text)) {
  169. text = text.replace(cx, function (a) {
  170. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  171. });
  172. }
  173. if (/^[\],:{}\s]*$/.
  174. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  175. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  176. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  177. return eval('(' + text + ')');
  178. }
  179. throw 'JSON parse error';
  180. }
  181. var _round = Math.round;
  182. var K = {
  183. DEBUG : false,
  184. VERSION : _VERSION,
  185. IE : _IE,
  186. GECKO : _GECKO,
  187. WEBKIT : _WEBKIT,
  188. OPERA : _OPERA,
  189. V : _V,
  190. TIME : _TIME,
  191. each : _each,
  192. isArray : _isArray,
  193. isFunction : _isFunction,
  194. inArray : _inArray,
  195. inString : _inString,
  196. trim : _trim,
  197. addUnit : _addUnit,
  198. removeUnit : _removeUnit,
  199. escape : _escape,
  200. unescape : _unescape,
  201. toCamel : _toCamel,
  202. toHex : _toHex,
  203. toMap : _toMap,
  204. toArray : _toArray,
  205. undef : _undef,
  206. invalidUrl : _invalidUrl,
  207. addParam : _addParam,
  208. extend : _extend,
  209. json : _json
  210. };
  211. 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'),
  212. _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'),
  213. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  214. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  215. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  216. _PRE_TAG_MAP = _toMap('pre,style,script'),
  217. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  218. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  219. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  220. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  221. function _getBasePath() {
  222. var els = document.getElementsByTagName('script'), src;
  223. for (var i = 0, len = els.length; i < len; i++) {
  224. src = els[i].src || '';
  225. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  226. return src.substring(0, src.lastIndexOf('/') + 1);
  227. }
  228. }
  229. return '';
  230. }
  231. K.basePath = _getBasePath();
  232. K.options = {
  233. index : 0,
  234. designMode : true,
  235. fullscreenMode : false,
  236. filterMode : true,
  237. wellFormatMode : true,
  238. shadowMode : true,
  239. loadStyleMode : true,
  240. basePath : K.basePath,
  241. themesPath : K.basePath + 'themes/',
  242. langPath : K.basePath + 'lang/',
  243. pluginsPath : K.basePath + 'plugins/',
  244. themeType : 'default',
  245. langType : 'zh-CN',
  246. urlType : '',
  247. newlineTag : 'p',
  248. resizeType : 2,
  249. syncType : 'form',
  250. pasteType : 2,
  251. dialogAlignType : 'page',
  252. useContextmenu : true,
  253. fullscreenShortcut : false,
  254. bodyClass : 'ke-content',
  255. indentChar : '\t',
  256. cssPath : '',
  257. cssData : '',
  258. minWidth : 650,
  259. minHeight : 100,
  260. minChangeSize : 50,
  261. zIndex : 19850426,
  262. items : [
  263. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  264. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  265. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  266. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  267. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  268. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  269. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  270. 'anchor', 'link', 'unlink', '|', 'about'
  271. ],
  272. noDisableItems : ['source', 'fullscreen'],
  273. colorTable : [
  274. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  275. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  276. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  277. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  278. ],
  279. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  280. fontHeightTable : ['0px', '0.25px', '0.5px', '1px', '1.5px', '2px', '2.5px', '3px', '4px', '5px'],
  281. htmlTags : {
  282. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  283. span : [
  284. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  285. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  286. ],
  287. div : [
  288. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  289. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  290. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  291. ],
  292. table: [
  293. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  294. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  295. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  296. '.width', '.height', '.border-collapse'
  297. ],
  298. 'td,th': [
  299. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  300. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  301. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  302. ],
  303. a : ['id', 'class', 'href', 'target', 'name'],
  304. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  305. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  306. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  307. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  308. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  309. ],
  310. pre : ['id', 'class'],
  311. hr : ['id', 'class', '.page-break-after'],
  312. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  313. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  314. },
  315. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  316. };
  317. var _useCapture = false;
  318. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  319. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  320. var _CHANGE_KEY_MAP = {};
  321. _each(_INPUT_KEY_MAP, function(key, val) {
  322. _CHANGE_KEY_MAP[key] = val;
  323. });
  324. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  325. _CHANGE_KEY_MAP[key] = val;
  326. });
  327. function _bindEvent(el, type, fn) {
  328. if (el.addEventListener){
  329. el.addEventListener(type, fn, _useCapture);
  330. } else if (el.attachEvent){
  331. el.attachEvent('on' + type, fn);
  332. }
  333. }
  334. function _unbindEvent(el, type, fn) {
  335. if (el.removeEventListener){
  336. el.removeEventListener(type, fn, _useCapture);
  337. } else if (el.detachEvent){
  338. el.detachEvent('on' + type, fn);
  339. }
  340. }
  341. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  342. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  343. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  344. function KEvent(el, event) {
  345. this.init(el, event);
  346. }
  347. _extend(KEvent, {
  348. init : function(el, event) {
  349. var self = this, doc = el.ownerDocument || el.document || el;
  350. self.event = event;
  351. _each(_EVENT_PROPS, function(key, val) {
  352. self[val] = event[val];
  353. });
  354. if (!self.target) {
  355. self.target = self.srcElement || doc;
  356. }
  357. if (self.target.nodeType === 3) {
  358. self.target = self.target.parentNode;
  359. }
  360. if (!self.relatedTarget && self.fromElement) {
  361. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  362. }
  363. if (self.pageX == null && self.clientX != null) {
  364. var d = doc.documentElement, body = doc.body;
  365. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  366. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  367. }
  368. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  369. self.which = self.charCode || self.keyCode;
  370. }
  371. if (!self.metaKey && self.ctrlKey) {
  372. self.metaKey = self.ctrlKey;
  373. }
  374. if (!self.which && self.button !== undefined) {
  375. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  376. }
  377. switch (self.which) {
  378. case 186 :
  379. self.which = 59;
  380. break;
  381. case 187 :
  382. case 107 :
  383. case 43 :
  384. self.which = 61;
  385. break;
  386. case 189 :
  387. case 45 :
  388. self.which = 109;
  389. break;
  390. case 42 :
  391. self.which = 106;
  392. break;
  393. case 47 :
  394. self.which = 111;
  395. break;
  396. case 78 :
  397. self.which = 110;
  398. break;
  399. }
  400. if (self.which >= 96 && self.which <= 105) {
  401. self.which -= 48;
  402. }
  403. },
  404. preventDefault : function() {
  405. var ev = this.event;
  406. if (ev.preventDefault) {
  407. ev.preventDefault();
  408. } else {
  409. ev.returnValue = false;
  410. }
  411. },
  412. stopPropagation : function() {
  413. var ev = this.event;
  414. if (ev.stopPropagation) {
  415. ev.stopPropagation();
  416. } else {
  417. ev.cancelBubble = true;
  418. }
  419. },
  420. stop : function() {
  421. this.preventDefault();
  422. this.stopPropagation();
  423. }
  424. });
  425. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  426. function _getId(el) {
  427. return el[_eventExpendo] || null;
  428. }
  429. function _setId(el) {
  430. el[_eventExpendo] = ++_eventId;
  431. return _eventId;
  432. }
  433. function _removeId(el) {
  434. try {
  435. delete el[_eventExpendo];
  436. } catch(e) {
  437. if (el.removeAttribute) {
  438. el.removeAttribute(_eventExpendo);
  439. }
  440. }
  441. }
  442. function _bind(el, type, fn) {
  443. if (type.indexOf(',') >= 0) {
  444. _each(type.split(','), function() {
  445. _bind(el, this, fn);
  446. });
  447. return;
  448. }
  449. var id = _getId(el);
  450. if (!id) {
  451. id = _setId(el);
  452. }
  453. if (_eventData[id] === undefined) {
  454. _eventData[id] = {};
  455. }
  456. var events = _eventData[id][type];
  457. if (events && events.length > 0) {
  458. _unbindEvent(el, type, events[0]);
  459. } else {
  460. _eventData[id][type] = [];
  461. _eventData[id].el = el;
  462. }
  463. events = _eventData[id][type];
  464. if (events.length === 0) {
  465. events[0] = function(e) {
  466. var kevent = e ? new KEvent(el, e) : undefined;
  467. _each(events, function(i, event) {
  468. if (i > 0 && event) {
  469. event.call(el, kevent);
  470. }
  471. });
  472. };
  473. }
  474. if (_inArray(fn, events) < 0) {
  475. events.push(fn);
  476. }
  477. _bindEvent(el, type, events[0]);
  478. }
  479. function _unbind(el, type, fn) {
  480. if (type && type.indexOf(',') >= 0) {
  481. _each(type.split(','), function() {
  482. _unbind(el, this, fn);
  483. });
  484. return;
  485. }
  486. var id = _getId(el);
  487. if (!id) {
  488. return;
  489. }
  490. if (type === undefined) {
  491. if (id in _eventData) {
  492. _each(_eventData[id], function(key, events) {
  493. if (key != 'el' && events.length > 0) {
  494. _unbindEvent(el, key, events[0]);
  495. }
  496. });
  497. delete _eventData[id];
  498. _removeId(el);
  499. }
  500. return;
  501. }
  502. if (!_eventData[id]) {
  503. return;
  504. }
  505. var events = _eventData[id][type];
  506. if (events && events.length > 0) {
  507. if (fn === undefined) {
  508. _unbindEvent(el, type, events[0]);
  509. delete _eventData[id][type];
  510. } else {
  511. _each(events, function(i, event) {
  512. if (i > 0 && event === fn) {
  513. events.splice(i, 1);
  514. }
  515. });
  516. if (events.length == 1) {
  517. _unbindEvent(el, type, events[0]);
  518. delete _eventData[id][type];
  519. }
  520. }
  521. var count = 0;
  522. _each(_eventData[id], function() {
  523. count++;
  524. });
  525. if (count < 2) {
  526. delete _eventData[id];
  527. _removeId(el);
  528. }
  529. }
  530. }
  531. function _fire(el, type) {
  532. if (type.indexOf(',') >= 0) {
  533. _each(type.split(','), function() {
  534. _fire(el, this);
  535. });
  536. return;
  537. }
  538. var id = _getId(el);
  539. if (!id) {
  540. return;
  541. }
  542. var events = _eventData[id][type];
  543. if (_eventData[id] && events && events.length > 0) {
  544. events[0]();
  545. }
  546. }
  547. function _ctrl(el, key, fn) {
  548. var self = this;
  549. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  550. _bind(el, 'keydown', function(e) {
  551. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  552. fn.call(el);
  553. e.stop();
  554. }
  555. });
  556. }
  557. var _readyFinished = false;
  558. function _ready(fn) {
  559. if (_readyFinished) {
  560. fn(KindEditor);
  561. return;
  562. }
  563. var loaded = false;
  564. function readyFunc() {
  565. if (!loaded) {
  566. loaded = true;
  567. fn(KindEditor);
  568. _readyFinished = true;
  569. }
  570. }
  571. function ieReadyFunc() {
  572. if (!loaded) {
  573. try {
  574. document.documentElement.doScroll('left');
  575. } catch(e) {
  576. setTimeout(ieReadyFunc, 100);
  577. return;
  578. }
  579. readyFunc();
  580. }
  581. }
  582. function ieReadyStateFunc() {
  583. if (document.readyState === 'complete') {
  584. readyFunc();
  585. }
  586. }
  587. if (document.addEventListener) {
  588. _bind(document, 'DOMContentLoaded', readyFunc);
  589. } else if (document.attachEvent) {
  590. _bind(document, 'readystatechange', ieReadyStateFunc);
  591. var toplevel = false;
  592. try {
  593. toplevel = window.frameElement == null;
  594. } catch(e) {}
  595. if (document.documentElement.doScroll && toplevel) {
  596. ieReadyFunc();
  597. }
  598. }
  599. _bind(window, 'load', readyFunc);
  600. }
  601. if (window.attachEvent) {
  602. window.attachEvent('onunload', function() {
  603. _each(_eventData, function(key, events) {
  604. if (events.el) {
  605. _unbind(events.el);
  606. }
  607. });
  608. });
  609. }
  610. K.ctrl = _ctrl;
  611. K.ready = _ready;
  612. function _getCssList(css) {
  613. css = css.replace(/&quot;/g, '"');
  614. var list = {},
  615. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  616. match;
  617. while ((match = reg.exec(css))) {
  618. var key = _trim(match[1].toLowerCase()),
  619. val = _trim(_toHex(match[2]));
  620. list[key] = val;
  621. }
  622. return list;
  623. }
  624. function _getAttrList(tag) {
  625. var list = {},
  626. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  627. match;
  628. while ((match = reg.exec(tag))) {
  629. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  630. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  631. list[key] = val;
  632. }
  633. return list;
  634. }
  635. function _addClassToTag(tag, className) {
  636. if (/\s+class\s*=/.test(tag)) {
  637. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  638. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  639. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  640. } else {
  641. return $0;
  642. }
  643. });
  644. } else {
  645. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  646. }
  647. return tag;
  648. }
  649. function _formatCss(css) {
  650. var str = '';
  651. _each(_getCssList(css), function(key, val) {
  652. str += key + ':' + val + ';';
  653. });
  654. return str;
  655. }
  656. function _formatUrl(url, mode, host, pathname) {
  657. return url;
  658. mode = _undef(mode, '').toLowerCase();
  659. if (url.substr(0, 5) != 'data:') {
  660. url = url.replace(/([^:])\/\//g, '$1/');
  661. }
  662. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  663. return url;
  664. }
  665. host = host || location.protocol + '//' + location.host;
  666. if (pathname === undefined) {
  667. var m = location.pathname.match(/^(\/.*)\//);
  668. pathname = m ? m[1] : '';
  669. }
  670. var match;
  671. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  672. if (match[1] !== host) {
  673. return url;
  674. }
  675. } else if (/^\w+:/.test(url)) {
  676. return url;
  677. }
  678. function getRealPath(path) {
  679. var parts = path.split('/'), paths = [];
  680. for (var i = 0, len = parts.length; i < len; i++) {
  681. var part = parts[i];
  682. if (part == '..') {
  683. if (paths.length > 0) {
  684. paths.pop();
  685. }
  686. } else if (part !== '' && part != '.') {
  687. paths.push(part);
  688. }
  689. }
  690. return '/' + paths.join('/');
  691. }
  692. if (/^\//.test(url)) {
  693. url = host + getRealPath(url.substr(1));
  694. } else if (!/^\w+:\/\//.test(url)) {
  695. url = host + getRealPath(pathname + '/' + url);
  696. }
  697. function getRelativePath(path, depth) {
  698. if (url.substr(0, path.length) === path) {
  699. var arr = [];
  700. for (var i = 0; i < depth; i++) {
  701. arr.push('..');
  702. }
  703. var prefix = '.';
  704. if (arr.length > 0) {
  705. prefix += '/' + arr.join('/');
  706. }
  707. if (pathname == '/') {
  708. prefix += '/';
  709. }
  710. return prefix + url.substr(path.length);
  711. } else {
  712. if ((match = /^(.*)\//.exec(path))) {
  713. return getRelativePath(match[1], ++depth);
  714. }
  715. }
  716. }
  717. if (mode === 'relative') {
  718. url = getRelativePath(host + pathname, 0).substr(2);
  719. } else if (mode === 'absolute') {
  720. if (url.substr(0, host.length) === host) {
  721. url = url.substr(host.length);
  722. }
  723. }
  724. return url;
  725. }
  726. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  727. if (html == null) {
  728. html = '';
  729. }
  730. urlType = urlType || '';
  731. wellFormatted = _undef(wellFormatted, false);
  732. indentChar = _undef(indentChar, '\t');
  733. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  734. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  735. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  736. });
  737. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  738. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  739. html = html.replace(/\u200B/g, '');
  740. html = html.replace(/\u00A9/g, '&copy;');
  741. html = html.replace(/\u00AE/g, '&reg;');
  742. html = html.replace(/\u2003/g, '&emsp;');
  743. html = html.replace(/\u3000/g, '&emsp;');
  744. html = html.replace(/&quot;/g, '');
  745. html = html.replace(/, " helvetica=""(.*?)"="/g, '');
  746. html = html.replace(/<[^>]+/g, function($0) {
  747. return $0.replace(/\s+/g, ' ');
  748. });
  749. var htmlTagMap = {};
  750. if (htmlTags) {
  751. _each(htmlTags, function(key, val) {
  752. var arr = key.split(',');
  753. for (var i = 0, len = arr.length; i < len; i++) {
  754. htmlTagMap[arr[i]] = _toMap(val);
  755. }
  756. });
  757. if (!htmlTagMap.script) {
  758. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  759. }
  760. if (!htmlTagMap.style) {
  761. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  762. }
  763. }
  764. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  765. var tagStack = [];
  766. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  767. var full = $0,
  768. startNewline = $1 || '',
  769. startSlash = $2 || '',
  770. tagName = $3.toLowerCase(),
  771. attr = $4 || '',
  772. endSlash = $5 ? ' ' + $5 : '',
  773. endNewline = $6 || '';
  774. if (htmlTags && !htmlTagMap[tagName]) {
  775. return '';
  776. }
  777. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  778. endSlash = ' /';
  779. }
  780. if (_INLINE_TAG_MAP[tagName]) {
  781. if (startNewline) {
  782. startNewline = ' ';
  783. }
  784. if (endNewline) {
  785. endNewline = ' ';
  786. }
  787. }
  788. if (_PRE_TAG_MAP[tagName]) {
  789. if (startSlash) {
  790. endNewline = '\n';
  791. } else {
  792. startNewline = '\n';
  793. }
  794. }
  795. if (wellFormatted && tagName == 'br') {
  796. endNewline = '\n';
  797. }
  798. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  799. if (wellFormatted) {
  800. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  801. tagStack.pop();
  802. } else {
  803. tagStack.push(tagName);
  804. }
  805. startNewline = '\n';
  806. endNewline = '\n';
  807. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  808. startNewline += indentChar;
  809. if (!startSlash) {
  810. endNewline += indentChar;
  811. }
  812. }
  813. if (endSlash) {
  814. tagStack.pop();
  815. } else if (!startSlash) {
  816. endNewline += indentChar;
  817. }
  818. } else {
  819. startNewline = endNewline = '';
  820. }
  821. }
  822. if (attr !== '') {
  823. var attrMap = _getAttrList(full);
  824. if (tagName === 'font') {
  825. var fontStyleMap = {}, fontStyle = '';
  826. _each(attrMap, function(key, val) {
  827. if (key === 'color') {
  828. fontStyleMap.color = val;
  829. delete attrMap[key];
  830. }
  831. if (key === 'size') {
  832. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  833. delete attrMap[key];
  834. }
  835. if (key === 'face') {
  836. fontStyleMap['font-family'] = val;
  837. delete attrMap[key];
  838. }
  839. if (key === 'style') {
  840. fontStyle = val;
  841. }
  842. });
  843. if (fontStyle && !/;$/.test(fontStyle)) {
  844. fontStyle += ';';
  845. }
  846. _each(fontStyleMap, function(key, val) {
  847. if (val === '') {
  848. return;
  849. }
  850. if (/\s/.test(val)) {
  851. val = "'" + val + "'";
  852. }
  853. fontStyle += key + ':' + val + ';';
  854. });
  855. attrMap.style = fontStyle;
  856. }
  857. _each(attrMap, function(key, val) {
  858. if (_FILL_ATTR_MAP[key]) {
  859. attrMap[key] = key;
  860. }
  861. if (_inArray(key, ['src', 'href']) >= 0) {
  862. attrMap[key] = _formatUrl(val, urlType);
  863. }
  864. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  865. tagName === 'body' && key === 'contenteditable' ||
  866. /^kindeditor_\d+$/.test(key)) {
  867. delete attrMap[key];
  868. }
  869. if (key === 'style' && val !== '') {
  870. var styleMap = _getCssList(val);
  871. _each(styleMap, function(k, v) {
  872. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  873. delete styleMap[k];
  874. }
  875. });
  876. var style = '';
  877. _each(styleMap, function(k, v) {
  878. style += k + ':' + v + ';';
  879. });
  880. attrMap.style = style;
  881. }
  882. });
  883. attr = '';
  884. _each(attrMap, function(key, val) {
  885. if (key === 'style' && val === '') {
  886. return;
  887. }
  888. val = val.replace(/"/g, '&quot;');
  889. attr += ' ' + key + '="' + val + '"';
  890. });
  891. }
  892. if (tagName === 'font') {
  893. tagName = 'span';
  894. }
  895. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  896. });
  897. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  898. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  899. });
  900. html = html.replace(/\n\s*\n/g, '\n');
  901. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  902. return _trim(html);
  903. }
  904. function _clearMsWord(html, htmlTags) {
  905. html = html.replace(/<meta[\s\S]*?>/ig, '')
  906. .replace(/<![\s\S]*?>/ig, '')
  907. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  908. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  909. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  910. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  911. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  912. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  913. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  914. });
  915. return _formatHtml(html, htmlTags);
  916. }
  917. function _mediaType(src) {
  918. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  919. return 'audio/x-pn-realaudio-plugin';
  920. }
  921. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  922. return 'application/x-shockwave-flash';
  923. }
  924. return 'video/x-ms-asf-plugin';
  925. }
  926. function _mediaClass(type) {
  927. if (/realaudio/i.test(type)) {
  928. return 'ke-rm';
  929. }
  930. if (/flash/i.test(type)) {
  931. return 'ke-flash';
  932. }
  933. return 'ke-media';
  934. }
  935. function _mediaAttrs(srcTag) {
  936. return _getAttrList(unescape(srcTag));
  937. }
  938. function _mediaEmbed(attrs) {
  939. var html = '<embed ';
  940. _each(attrs, function(key, val) {
  941. html += key + '="' + val + '" ';
  942. });
  943. html += '/>';
  944. return html;
  945. }
  946. function _mediaImg(blankPath, attrs) {
  947. var width = attrs.width,
  948. height = attrs.height,
  949. type = attrs.type || _mediaType(attrs.src),
  950. srcTag = _mediaEmbed(attrs),
  951. style = '';
  952. if (/\D/.test(width)) {
  953. style += 'width:' + width + ';';
  954. } else if (width > 0) {
  955. style += 'width:' + width + 'px;';
  956. }
  957. if (/\D/.test(height)) {
  958. style += 'height:' + height + ';';
  959. } else if (height > 0) {
  960. style += 'height:' + height + 'px;';
  961. }
  962. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  963. if (style !== '') {
  964. html += 'style="' + style + '" ';
  965. }
  966. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  967. return html;
  968. }
  969. function _tmpl(str, data) {
  970. var fn = new Function("obj",
  971. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  972. "with(obj){p.push('" +
  973. str.replace(/[\r\t\n]/g, " ")
  974. .split("<%").join("\t")
  975. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  976. .replace(/\t=(.*?)%>/g, "',$1,'")
  977. .split("\t").join("');")
  978. .split("%>").join("p.push('")
  979. .split("\r").join("\\'") + "');}return p.join('');");
  980. return data ? fn(data) : fn;
  981. }
  982. K.formatUrl = _formatUrl;
  983. K.formatHtml = _formatHtml;
  984. K.getCssList = _getCssList;
  985. K.getAttrList = _getAttrList;
  986. K.mediaType = _mediaType;
  987. K.mediaAttrs = _mediaAttrs;
  988. K.mediaEmbed = _mediaEmbed;
  989. K.mediaImg = _mediaImg;
  990. K.clearMsWord = _clearMsWord;
  991. K.tmpl = _tmpl;
  992. function _contains(nodeA, nodeB) {
  993. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  994. return true;
  995. }
  996. while ((nodeB = nodeB.parentNode)) {
  997. if (nodeB == nodeA) {
  998. return true;
  999. }
  1000. }
  1001. return false;
  1002. }
  1003. var _getSetAttrDiv = document.createElement('div');
  1004. _getSetAttrDiv.setAttribute('className', 't');
  1005. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1006. function _getAttr(el, key) {
  1007. key = key.toLowerCase();
  1008. var val = null;
  1009. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1010. var div = el.ownerDocument.createElement('div');
  1011. div.appendChild(el.cloneNode(false));
  1012. var list = _getAttrList(_unescape(div.innerHTML));
  1013. if (key in list) {
  1014. val = list[key];
  1015. }
  1016. } else {
  1017. try {
  1018. val = el.getAttribute(key, 2);
  1019. } catch(e) {
  1020. val = el.getAttribute(key, 1);
  1021. }
  1022. }
  1023. if (key === 'style' && val !== null) {
  1024. val = _formatCss(val);
  1025. }
  1026. return val;
  1027. }
  1028. function _queryAll(expr, root) {
  1029. var exprList = expr.split(',');
  1030. if (exprList.length > 1) {
  1031. var mergedResults = [];
  1032. _each(exprList, function() {
  1033. _each(_queryAll(this, root), function() {
  1034. if (_inArray(this, mergedResults) < 0) {
  1035. mergedResults.push(this);
  1036. }
  1037. });
  1038. });
  1039. return mergedResults;
  1040. }
  1041. root = root || document;
  1042. function escape(str) {
  1043. if (typeof str != 'string') {
  1044. return str;
  1045. }
  1046. return str.replace(/([^\w\-])/g, '\\$1');
  1047. }
  1048. function stripslashes(str) {
  1049. return str.replace(/\\/g, '');
  1050. }
  1051. function cmpTag(tagA, tagB) {
  1052. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1053. }
  1054. function byId(id, tag, root) {
  1055. var arr = [],
  1056. doc = root.ownerDocument || root,
  1057. el = doc.getElementById(stripslashes(id));
  1058. if (el) {
  1059. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1060. arr.push(el);
  1061. }
  1062. }
  1063. return arr;
  1064. }
  1065. function byClass(className, tag, root) {
  1066. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1067. if (root.getElementsByClassName) {
  1068. els = root.getElementsByClassName(stripslashes(className));
  1069. for (i = 0, len = els.length; i < len; i++) {
  1070. el = els[i];
  1071. if (cmpTag(tag, el.nodeName)) {
  1072. arr.push(el);
  1073. }
  1074. }
  1075. } else if (doc.querySelectorAll) {
  1076. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1077. for (i = 0, len = els.length; i < len; i++) {
  1078. el = els[i];
  1079. if (_contains(root, el)) {
  1080. arr.push(el);
  1081. }
  1082. }
  1083. } else {
  1084. els = root.getElementsByTagName(tag);
  1085. className = ' ' + className + ' ';
  1086. for (i = 0, len = els.length; i < len; i++) {
  1087. el = els[i];
  1088. if (el.nodeType == 1) {
  1089. var cls = el.className;
  1090. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1091. arr.push(el);
  1092. }
  1093. }
  1094. }
  1095. }
  1096. return arr;
  1097. }
  1098. function byName(name, tag, root) {
  1099. var arr = [], doc = root.ownerDocument || root,
  1100. els = doc.getElementsByName(stripslashes(name)), el;
  1101. for (var i = 0, len = els.length; i < len; i++) {
  1102. el = els[i];
  1103. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1104. if (el.getAttribute('name') !== null) {
  1105. arr.push(el);
  1106. }
  1107. }
  1108. }
  1109. return arr;
  1110. }
  1111. function byAttr(key, val, tag, root) {
  1112. var arr = [], els = root.getElementsByTagName(tag), el;
  1113. for (var i = 0, len = els.length; i < len; i++) {
  1114. el = els[i];
  1115. if (el.nodeType == 1) {
  1116. if (val === null) {
  1117. if (_getAttr(el, key) !== null) {
  1118. arr.push(el);
  1119. }
  1120. } else {
  1121. if (val === escape(_getAttr(el, key))) {
  1122. arr.push(el);
  1123. }
  1124. }
  1125. }
  1126. }
  1127. return arr;
  1128. }
  1129. function select(expr, root) {
  1130. var arr = [], matches;
  1131. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1132. var tag = matches ? matches[1] : '*';
  1133. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1134. arr = byId(matches[1], tag, root);
  1135. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1136. arr = byClass(matches[1], tag, root);
  1137. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1138. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1139. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1140. var key = matches[1].toLowerCase(), val = matches[2];
  1141. if (key === 'id') {
  1142. arr = byId(val, tag, root);
  1143. } else if (key === 'class') {
  1144. arr = byClass(val, tag, root);
  1145. } else if (key === 'name') {
  1146. arr = byName(val, tag, root);
  1147. } else {
  1148. arr = byAttr(key, val, tag, root);
  1149. }
  1150. } else {
  1151. var els = root.getElementsByTagName(tag), el;
  1152. for (var i = 0, len = els.length; i < len; i++) {
  1153. el = els[i];
  1154. if (el.nodeType == 1) {
  1155. arr.push(el);
  1156. }
  1157. }
  1158. }
  1159. return arr;
  1160. }
  1161. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1162. while ((arr = re.exec(expr))) {
  1163. if (arr[1] !== ' ') {
  1164. parts.push(arr[1]);
  1165. }
  1166. }
  1167. var results = [];
  1168. if (parts.length == 1) {
  1169. return select(parts[0], root);
  1170. }
  1171. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1172. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1173. part = parts[i];
  1174. if (part === '>') {
  1175. isChild = true;
  1176. continue;
  1177. }
  1178. if (i > 0) {
  1179. els = [];
  1180. for (j = 0, len = results.length; j < len; j++) {
  1181. val = results[j];
  1182. subResults = select(part, val);
  1183. for (k = 0, l = subResults.length; k < l; k++) {
  1184. v = subResults[k];
  1185. if (isChild) {
  1186. if (val === v.parentNode) {
  1187. els.push(v);
  1188. }
  1189. } else {
  1190. els.push(v);
  1191. }
  1192. }
  1193. }
  1194. results = els;
  1195. } else {
  1196. results = select(part, root);
  1197. }
  1198. if (results.length === 0) {
  1199. return [];
  1200. }
  1201. }
  1202. return results;
  1203. }
  1204. function _query(expr, root) {
  1205. var arr = _queryAll(expr, root);
  1206. return arr.length > 0 ? arr[0] : null;
  1207. }
  1208. K.query = _query;
  1209. K.queryAll = _queryAll;
  1210. function _get(val) {
  1211. return K(val)[0];
  1212. }
  1213. function _getDoc(node) {
  1214. if (!node) {
  1215. return document;
  1216. }
  1217. return node.ownerDocument || node.document || node;
  1218. }
  1219. function _getWin(node) {
  1220. if (!node) {
  1221. return window;
  1222. }
  1223. var doc = _getDoc(node);
  1224. return doc.parentWindow || doc.defaultView;
  1225. }
  1226. function _setHtml(el, html) {
  1227. if (el.nodeType != 1) {
  1228. return;
  1229. }
  1230. var doc = _getDoc(el);
  1231. try {
  1232. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1233. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1234. temp.parentNode.removeChild(temp);
  1235. } catch(e) {
  1236. K(el).empty();
  1237. K('@' + html, doc).each(function() {
  1238. el.appendChild(this);
  1239. });
  1240. }
  1241. }
  1242. function _hasClass(el, cls) {
  1243. return _inString(cls, el.className, ' ');
  1244. }
  1245. function _setAttr(el, key, val) {
  1246. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1247. key = 'className';
  1248. }
  1249. el.setAttribute(key, '' + val);
  1250. }
  1251. function _removeAttr(el, key) {
  1252. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1253. key = 'className';
  1254. }
  1255. _setAttr(el, key, '');
  1256. el.removeAttribute(key);
  1257. }
  1258. function _getNodeName(node) {
  1259. if (!node || !node.nodeName) {
  1260. return '';
  1261. }
  1262. return node.nodeName.toLowerCase();
  1263. }
  1264. function _computedCss(el, key) {
  1265. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1266. if (win.getComputedStyle) {
  1267. var style = win.getComputedStyle(el, null);
  1268. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1269. } else if (el.currentStyle) {
  1270. val = el.currentStyle[camelKey] || el.style[camelKey];
  1271. }
  1272. return val;
  1273. }
  1274. function _hasVal(node) {
  1275. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1276. }
  1277. function _docElement(doc) {
  1278. doc = doc || document;
  1279. return _QUIRKS ? doc.body : doc.documentElement;
  1280. }
  1281. function _docHeight(doc) {
  1282. var el = _docElement(doc);
  1283. return Math.max(el.scrollHeight, el.clientHeight);
  1284. }
  1285. function _docWidth(doc) {
  1286. var el = _docElement(doc);
  1287. return Math.max(el.scrollWidth, el.clientWidth);
  1288. }
  1289. function _getScrollPos(doc) {
  1290. doc = doc || document;
  1291. var x, y;
  1292. if (_IE || _NEWIE || _OPERA) {
  1293. x = _docElement(doc).scrollLeft;
  1294. y = _docElement(doc).scrollTop;
  1295. } else {
  1296. x = _getWin(doc).scrollX;
  1297. y = _getWin(doc).scrollY;
  1298. }
  1299. return {x : x, y : y};
  1300. }
  1301. function KNode(node) {
  1302. this.init(node);
  1303. }
  1304. _extend(KNode, {
  1305. init : function(node) {
  1306. var self = this;
  1307. node = _isArray(node) ? node : [node];
  1308. var length = 0;
  1309. for (var i = 0, len = node.length; i < len; i++) {
  1310. if (node[i]) {
  1311. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1312. length++;
  1313. }
  1314. }
  1315. self.length = length;
  1316. self.doc = _getDoc(self[0]);
  1317. self.name = _getNodeName(self[0]);
  1318. self.type = self.length > 0 ? self[0].nodeType : null;
  1319. self.win = _getWin(self[0]);
  1320. },
  1321. each : function(fn) {
  1322. var self = this;
  1323. for (var i = 0; i < self.length; i++) {
  1324. if (fn.call(self[i], i, self[i]) === false) {
  1325. return self;
  1326. }
  1327. }
  1328. return self;
  1329. },
  1330. bind : function(type, fn) {
  1331. this.each(function() {
  1332. _bind(this, type, fn);
  1333. });
  1334. return this;
  1335. },
  1336. unbind : function(type, fn) {
  1337. this.each(function() {
  1338. _unbind(this, type, fn);
  1339. });
  1340. return this;
  1341. },
  1342. fire : function(type) {
  1343. if (this.length < 1) {
  1344. return this;
  1345. }
  1346. _fire(this[0], type);
  1347. return this;
  1348. },
  1349. hasAttr : function(key) {
  1350. if (this.length < 1) {
  1351. return false;
  1352. }
  1353. return !!_getAttr(this[0], key);
  1354. },
  1355. attr : function(key, val) {
  1356. var self = this;
  1357. if (key === undefined) {
  1358. return _getAttrList(self.outer());
  1359. }
  1360. if (typeof key === 'object') {
  1361. _each(key, function(k, v) {
  1362. self.attr(k, v);
  1363. });
  1364. return self;
  1365. }
  1366. if (val === undefined) {
  1367. val = self.length < 1 ? null : _getAttr(self[0], key);
  1368. return val === null ? '' : val;
  1369. }
  1370. self.each(function() {
  1371. _setAttr(this, key, val);
  1372. });
  1373. return self;
  1374. },
  1375. removeAttr : function(key) {
  1376. this.each(function() {
  1377. _removeAttr(this, key);
  1378. });
  1379. return this;
  1380. },
  1381. get : function(i) {
  1382. if (this.length < 1) {
  1383. return null;
  1384. }
  1385. return this[i || 0];
  1386. },
  1387. eq : function(i) {
  1388. if (this.length < 1) {
  1389. return null;
  1390. }
  1391. return this[i] ? new KNode(this[i]) : null;
  1392. },
  1393. hasClass : function(cls) {
  1394. if (this.length < 1) {
  1395. return false;
  1396. }
  1397. return _hasClass(this[0], cls);
  1398. },
  1399. addClass : function(cls) {
  1400. this.each(function() {
  1401. if (!_hasClass(this, cls)) {
  1402. this.className = _trim(this.className + ' ' + cls);
  1403. }
  1404. });
  1405. return this;
  1406. },
  1407. removeClass : function(cls) {
  1408. this.each(function() {
  1409. if (_hasClass(this, cls)) {
  1410. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1411. }
  1412. });
  1413. return this;
  1414. },
  1415. html : function(val) {
  1416. var self = this;
  1417. if (val === undefined) {
  1418. if (self.length < 1 || self.type != 1) {
  1419. return '';
  1420. }
  1421. return _formatHtml(self[0].innerHTML);
  1422. }
  1423. self.each(function() {
  1424. _setHtml(this, val);
  1425. });
  1426. return self;
  1427. },
  1428. text : function() {
  1429. var self = this;
  1430. if (self.length < 1) {
  1431. return '';
  1432. }
  1433. return _IE ? self[0].innerText : self[0].textContent;
  1434. },
  1435. hasVal : function() {
  1436. if (this.length < 1) {
  1437. return false;
  1438. }
  1439. return _hasVal(this[0]);
  1440. },
  1441. val : function(val) {
  1442. var self = this;
  1443. if (val === undefined) {
  1444. if (self.length < 1) {
  1445. return '';
  1446. }
  1447. return self.hasVal() ? self[0].value : self.attr('value');
  1448. } else {
  1449. self.each(function() {
  1450. if (_hasVal(this)) {
  1451. this.value = val;
  1452. } else {
  1453. _setAttr(this, 'value' , val);
  1454. }
  1455. });
  1456. return self;
  1457. }
  1458. },
  1459. css : function(key, val) {
  1460. var self = this;
  1461. if (key === undefined) {
  1462. return _getCssList(self.attr('style'));
  1463. }
  1464. if (typeof key === 'object') {
  1465. _each(key, function(k, v) {
  1466. self.css(k, v);
  1467. });
  1468. return self;
  1469. }
  1470. if (val === undefined) {
  1471. if (self.length < 1) {
  1472. return '';
  1473. }
  1474. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1475. }
  1476. self.each(function() {
  1477. this.style[_toCamel(key)] = val;
  1478. });
  1479. return self;
  1480. },
  1481. width : function(val) {
  1482. var self = this;
  1483. if (val === undefined) {
  1484. if (self.length < 1) {
  1485. return 0;
  1486. }
  1487. return self[0].offsetWidth;
  1488. }
  1489. return self.css('width', _addUnit(val));
  1490. },
  1491. height : function(val) {
  1492. var self = this;
  1493. if (val === undefined) {
  1494. if (self.length < 1) {
  1495. return 0;
  1496. }
  1497. return self[0].offsetHeight;
  1498. }
  1499. return self.css('height', _addUnit(val));
  1500. },
  1501. opacity : function(val) {
  1502. this.each(function() {
  1503. if (this.style.opacity === undefined) {
  1504. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1505. } else {
  1506. this.style.opacity = val == 1 ? '' : val;
  1507. }
  1508. });
  1509. return this;
  1510. },
  1511. data : function(key, val) {
  1512. var self = this;
  1513. key = 'kindeditor_data_' + key;
  1514. if (val === undefined) {
  1515. if (self.length < 1) {
  1516. return null;
  1517. }
  1518. return self[0][key];
  1519. }
  1520. this.each(function() {
  1521. this[key] = val;
  1522. });
  1523. return self;
  1524. },
  1525. pos : function() {
  1526. var self = this, node = self[0], x = 0, y = 0;
  1527. if (node) {
  1528. if (node.getBoundingClientRect) {
  1529. var box = node.getBoundingClientRect(),
  1530. pos = _getScrollPos(self.doc);
  1531. x = box.left + pos.x;
  1532. y = box.top + pos.y;
  1533. } else {
  1534. while (node) {
  1535. x += node.offsetLeft;
  1536. y += node.offsetTop;
  1537. node = node.offsetParent;
  1538. }
  1539. }
  1540. }
  1541. return {x : _round(x), y : _round(y)};
  1542. },
  1543. clone : function(bool) {
  1544. if (this.length < 1) {
  1545. return new KNode([]);
  1546. }
  1547. return new KNode(this[0].cloneNode(bool));
  1548. },
  1549. append : function(expr) {
  1550. this.each(function() {
  1551. if (this.appendChild) {
  1552. this.appendChild(_get(expr));
  1553. }
  1554. });
  1555. return this;
  1556. },
  1557. appendTo : function(expr) {
  1558. this.each(function() {
  1559. _get(expr).appendChild(this);
  1560. });
  1561. return this;
  1562. },
  1563. before : function(expr) {
  1564. this.each(function() {
  1565. this.parentNode.insertBefore(_get(expr), this);
  1566. });
  1567. return this;
  1568. },
  1569. after : function(expr) {
  1570. this.each(function() {
  1571. if (this.nextSibling) {
  1572. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1573. } else {
  1574. this.parentNode.appendChild(_get(expr));
  1575. }
  1576. });
  1577. return this;
  1578. },
  1579. replaceWith : function(expr) {
  1580. var nodes = [];
  1581. this.each(function(i, node) {
  1582. _unbind(node);
  1583. var newNode = _get(expr);
  1584. node.parentNode.replaceChild(newNode, node);
  1585. nodes.push(newNode);
  1586. });
  1587. return K(nodes);
  1588. },
  1589. empty : function() {
  1590. var self = this;
  1591. self.each(function(i, node) {
  1592. var child = node.firstChild;
  1593. while (child) {
  1594. if (!node.parentNode) {
  1595. return;
  1596. }
  1597. var next = child.nextSibling;
  1598. child.parentNode.removeChild(child);
  1599. child = next;
  1600. }
  1601. });
  1602. return self;
  1603. },
  1604. remove : function(keepChilds) {
  1605. var self = this;
  1606. self.each(function(i, node) {
  1607. if (!node.parentNode) {
  1608. return;
  1609. }
  1610. _unbind(node);
  1611. if (keepChilds) {
  1612. var child = node.firstChild;
  1613. while (child) {
  1614. var next = child.nextSibling;
  1615. node.parentNode.insertBefore(child, node);
  1616. child = next;
  1617. }
  1618. }
  1619. node.parentNode.removeChild(node);
  1620. delete self[i];
  1621. });
  1622. self.length = 0;
  1623. return self;
  1624. },
  1625. show : function(val) {
  1626. var self = this;
  1627. if (val === undefined) {
  1628. val = self._originDisplay || '';
  1629. }
  1630. if (self.css('display') != 'none') {
  1631. return self;
  1632. }
  1633. return self.css('display', val);
  1634. },
  1635. hide : function() {
  1636. var self = this;
  1637. if (self.length < 1) {
  1638. return self;
  1639. }
  1640. self._originDisplay = self[0].style.display;
  1641. return self.css('display', 'none');
  1642. },
  1643. outer : function() {
  1644. var self = this;
  1645. if (self.length < 1) {
  1646. return '';
  1647. }
  1648. var div = self.doc.createElement('div'), html;
  1649. div.appendChild(self[0].cloneNode(true));
  1650. html = _formatHtml(div.innerHTML);
  1651. div = null;
  1652. return html;
  1653. },
  1654. isSingle : function() {
  1655. return !!_SINGLE_TAG_MAP[this.name];
  1656. },
  1657. isInline : function() {
  1658. return !!_INLINE_TAG_MAP[this.name];
  1659. },
  1660. isBlock : function() {
  1661. return !!_BLOCK_TAG_MAP[this.name];
  1662. },
  1663. isStyle : function() {
  1664. return !!_STYLE_TAG_MAP[this.name];
  1665. },
  1666. isControl : function() {
  1667. return !!_CONTROL_TAG_MAP[this.name];
  1668. },
  1669. contains : function(otherNode) {
  1670. if (this.length < 1) {
  1671. return false;
  1672. }
  1673. return _contains(this[0], _get(otherNode));
  1674. },
  1675. parent : function() {
  1676. if (this.length < 1) {
  1677. return null;
  1678. }
  1679. var node = this[0].parentNode;
  1680. return node ? new KNode(node) : null;
  1681. },
  1682. children : function() {
  1683. if (this.length < 1) {
  1684. return new KNode([]);
  1685. }
  1686. var list = [], child = this[0].firstChild;
  1687. while (child) {
  1688. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1689. list.push(child);
  1690. }
  1691. child = child.nextSibling;
  1692. }
  1693. return new KNode(list);
  1694. },
  1695. first : function() {
  1696. var list = this.children();
  1697. return list.length > 0 ? list.eq(0) : null;
  1698. },
  1699. last : function() {
  1700. var list = this.children();
  1701. return list.length > 0 ? list.eq(list.length - 1) : null;
  1702. },
  1703. index : function() {
  1704. if (this.length < 1) {
  1705. return -1;
  1706. }
  1707. var i = -1, sibling = this[0];
  1708. while (sibling) {
  1709. i++;
  1710. sibling = sibling.previousSibling;
  1711. }
  1712. return i;
  1713. },
  1714. prev : function() {
  1715. if (this.length < 1) {
  1716. return null;
  1717. }
  1718. var node = this[0].previousSibling;
  1719. return node ? new KNode(node) : null;
  1720. },
  1721. next : function() {
  1722. if (this.length < 1) {
  1723. return null;
  1724. }
  1725. var node = this[0].nextSibling;
  1726. return node ? new KNode(node) : null;
  1727. },
  1728. scan : function(fn, order) {
  1729. if (this.length < 1) {
  1730. return;
  1731. }
  1732. order = (order === undefined) ? true : order;
  1733. function walk(node) {
  1734. var n = order ? node.firstChild : node.lastChild;
  1735. while (n) {
  1736. var next = order ? n.nextSibling : n.previousSibling;
  1737. if (fn(n) === false) {
  1738. return false;
  1739. }
  1740. if (walk(n) === false) {
  1741. return false;
  1742. }
  1743. n = next;
  1744. }
  1745. }
  1746. walk(this[0]);
  1747. return this;
  1748. }
  1749. });
  1750. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1751. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1752. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1753. KNode.prototype[type] = function(fn) {
  1754. return fn ? this.bind(type, fn) : this.fire(type);
  1755. };
  1756. });
  1757. var _K = K;
  1758. K = function(expr, root) {
  1759. if (expr === undefined || expr === null) {
  1760. return;
  1761. }
  1762. function newNode(node) {
  1763. if (!node[0]) {
  1764. node = [];
  1765. }
  1766. return new KNode(node);
  1767. }
  1768. if (typeof expr === 'string') {
  1769. if (root) {
  1770. root = _get(root);
  1771. }
  1772. var length = expr.length;
  1773. if (expr.charAt(0) === '@') {
  1774. expr = expr.substr(1);
  1775. }
  1776. if (expr.length !== length || /<.+>/.test(expr)) {
  1777. var doc = root ? root.ownerDocument || root : document,
  1778. div = doc.createElement('div'), list = [];
  1779. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1780. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1781. var child = div.childNodes[i];
  1782. if (child.id == '__kindeditor_temp_tag__') {
  1783. continue;
  1784. }
  1785. list.push(child);
  1786. }
  1787. return newNode(list);
  1788. }
  1789. return newNode(_queryAll(expr, root));
  1790. }
  1791. if (expr && expr.constructor === KNode) {
  1792. return expr;
  1793. }
  1794. if (expr.toArray) {
  1795. expr = expr.toArray();
  1796. }
  1797. if (_isArray(expr)) {
  1798. return newNode(expr);
  1799. }
  1800. return newNode(_toArray(arguments));
  1801. };
  1802. _each(_K, function(key, val) {
  1803. K[key] = val;
  1804. });
  1805. K.NodeClass = KNode;
  1806. window.KindEditor = K;
  1807. var _START_TO_START = 0,
  1808. _START_TO_END = 1,
  1809. _END_TO_END = 2,
  1810. _END_TO_START = 3,
  1811. _BOOKMARK_ID = 0;
  1812. function _updateCollapsed(range) {
  1813. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1814. return range;
  1815. }
  1816. function _copyAndDelete(range, isCopy, isDelete) {
  1817. var doc = range.doc, nodeList = [];
  1818. function splitTextNode(node, startOffset, endOffset) {
  1819. var length = node.nodeValue.length, centerNode;
  1820. if (isCopy) {
  1821. var cloneNode = node.cloneNode(true);
  1822. if (startOffset > 0) {
  1823. centerNode = cloneNode.splitText(startOffset);
  1824. } else {
  1825. centerNode = cloneNode;
  1826. }
  1827. if (endOffset < length) {
  1828. centerNode.splitText(endOffset - startOffset);
  1829. }
  1830. }
  1831. if (isDelete) {
  1832. var center = node;
  1833. if (startOffset > 0) {
  1834. center = node.splitText(startOffset);
  1835. range.setStart(node, startOffset);
  1836. }
  1837. if (endOffset < length) {
  1838. var right = center.splitText(endOffset - startOffset);
  1839. range.setEnd(right, 0);
  1840. }
  1841. nodeList.push(center);
  1842. }
  1843. return centerNode;
  1844. }
  1845. function removeNodes() {
  1846. if (isDelete) {
  1847. range.up().collapse(true);
  1848. }
  1849. for (var i = 0, len = nodeList.length; i < len; i++) {
  1850. var node = nodeList[i];
  1851. if (node.parentNode) {
  1852. node.parentNode.removeChild(node);
  1853. }
  1854. }
  1855. }
  1856. var copyRange = range.cloneRange().down();
  1857. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1858. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1859. if (ancestor.nodeType == 3) {
  1860. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1861. if (isCopy) {
  1862. frag.appendChild(textNode);
  1863. }
  1864. removeNodes();
  1865. return isCopy ? frag : range;
  1866. }
  1867. function extractNodes(parent, frag) {
  1868. var node = parent.firstChild, nextNode;
  1869. while (node) {
  1870. var testRange = new KRange(doc).selectNode(node);
  1871. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1872. if (start >= 0 && incStart <= 0) {
  1873. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1874. }
  1875. if (incStart >= 0 && incEnd <= 0) {
  1876. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1877. }
  1878. if (incEnd >= 0 && end <= 0) {
  1879. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1880. }
  1881. if (end >= 0) {
  1882. return false;
  1883. }
  1884. nextNode = node.nextSibling;
  1885. if (start > 0) {
  1886. if (node.nodeType == 1) {
  1887. if (incStart >= 0 && incEnd <= 0) {
  1888. if (isCopy) {
  1889. frag.appendChild(node.cloneNode(true));
  1890. }
  1891. if (isDelete) {
  1892. nodeList.push(node);
  1893. }
  1894. } else {
  1895. var childFlag;
  1896. if (isCopy) {
  1897. childFlag = node.cloneNode(false);
  1898. frag.appendChild(childFlag);
  1899. }
  1900. if (extractNodes(node, childFlag) === false) {
  1901. return false;
  1902. }
  1903. }
  1904. } else if (node.nodeType == 3) {
  1905. var textNode;
  1906. if (node == copyRange.startContainer) {
  1907. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1908. } else if (node == copyRange.endContainer) {
  1909. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1910. } else {
  1911. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1912. }
  1913. if (isCopy) {
  1914. try {
  1915. frag.appendChild(textNode);
  1916. } catch(e) {}
  1917. }
  1918. }
  1919. }
  1920. node = nextNode;
  1921. }
  1922. }
  1923. extractNodes(ancestor, frag);
  1924. if (isDelete) {
  1925. range.up().collapse(true);
  1926. }
  1927. for (var i = 0, len = nodeList.length; i < len; i++) {
  1928. var node = nodeList[i];
  1929. if (node.parentNode) {
  1930. node.parentNode.removeChild(node);
  1931. }
  1932. }
  1933. return isCopy ? frag : range;
  1934. }
  1935. function _moveToElementText(range, el) {
  1936. var node = el;
  1937. while (node) {
  1938. var knode = K(node);
  1939. if (knode.name == 'marquee' || knode.name == 'select') {
  1940. return;
  1941. }
  1942. node = node.parentNode;
  1943. }
  1944. try {
  1945. range.moveToElementText(el);
  1946. } catch(e) {}
  1947. }
  1948. function _getStartEnd(rng, isStart) {
  1949. var doc = rng.parentElement().ownerDocument,
  1950. pointRange = rng.duplicate();
  1951. pointRange.collapse(isStart);
  1952. var parent = pointRange.parentElement(),
  1953. nodes = parent.childNodes;
  1954. if (nodes.length === 0) {
  1955. return {node: parent.parentNode, offset: K(parent).index()};
  1956. }
  1957. var startNode = doc, startPos = 0, cmp = -1;
  1958. var testRange = rng.duplicate();
  1959. _moveToElementText(testRange, parent);
  1960. for (var i = 0, len = nodes.length; i < len; i++) {
  1961. var node = nodes[i];
  1962. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1963. if (cmp === 0) {
  1964. return {node: node.parentNode, offset: i};
  1965. }
  1966. if (node.nodeType == 1) {
  1967. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1968. if (knode.isControl()) {
  1969. dummy = doc.createElement('span');
  1970. knode.after(dummy);
  1971. newNode = dummy;
  1972. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1973. }
  1974. _moveToElementText(nodeRange, newNode);
  1975. testRange.setEndPoint('StartToEnd', nodeRange);
  1976. if (cmp > 0) {
  1977. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1978. } else {
  1979. startPos = 0;
  1980. }
  1981. if (dummy) {
  1982. K(dummy).remove();
  1983. }
  1984. } else if (node.nodeType == 3) {
  1985. testRange.moveStart('character', node.nodeValue.length);
  1986. startPos += node.nodeValue.length;
  1987. }
  1988. if (cmp < 0) {
  1989. startNode = node;
  1990. }
  1991. }
  1992. if (cmp < 0 && startNode.nodeType == 1) {
  1993. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1994. }
  1995. if (cmp > 0) {
  1996. while (startNode.nextSibling && startNode.nodeType == 1) {
  1997. startNode = startNode.nextSibling;
  1998. }
  1999. }
  2000. testRange = rng.duplicate();
  2001. _moveToElementText(testRange, parent);
  2002. testRange.setEndPoint('StartToEnd', pointRange);
  2003. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  2004. if (cmp > 0 && startNode.nodeType == 3) {
  2005. var prevNode = startNode.previousSibling;
  2006. while (prevNode && prevNode.nodeType == 3) {
  2007. startPos -= prevNode.nodeValue.length;
  2008. prevNode = prevNode.previousSibling;
  2009. }
  2010. }
  2011. return {node: startNode, offset: startPos};
  2012. }
  2013. function _getEndRange(node, offset) {
  2014. var doc = node.ownerDocument || node,
  2015. range = doc.body.createTextRange();
  2016. if (doc == node) {
  2017. range.collapse(true);
  2018. return range;
  2019. }
  2020. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2021. var children = node.childNodes, isStart, child;
  2022. if (offset === 0) {
  2023. child = children[0];
  2024. isStart = true;
  2025. } else {
  2026. child = children[offset - 1];
  2027. isStart = false;
  2028. }
  2029. if (!child) {
  2030. return range;
  2031. }
  2032. if (K(child).name === 'head') {
  2033. if (offset === 1) {
  2034. isStart = true;
  2035. }
  2036. if (offset === 2) {
  2037. isStart = false;
  2038. }
  2039. range.collapse(isStart);
  2040. return range;
  2041. }
  2042. if (child.nodeType == 1) {
  2043. var kchild = K(child), span;
  2044. if (kchild.isControl()) {
  2045. span = doc.createElement('span');
  2046. if (isStart) {
  2047. kchild.before(span);
  2048. } else {
  2049. kchild.after(span);
  2050. }
  2051. child = span;
  2052. }
  2053. _moveToElementText(range, child);
  2054. range.collapse(isStart);
  2055. if (span) {
  2056. K(span).remove();
  2057. }
  2058. return range;
  2059. }
  2060. node = child;
  2061. offset = isStart ? 0 : child.nodeValue.length;
  2062. }
  2063. var dummy = doc.createElement('span');
  2064. K(node).before(dummy);
  2065. _moveToElementText(range, dummy);
  2066. range.moveStart('character', offset);
  2067. K(dummy).remove();
  2068. return range;
  2069. }
  2070. function _toRange(rng) {
  2071. var doc, range;
  2072. function tr2td(start) {
  2073. if (K(start.node).name == 'tr') {
  2074. start.node = start.node.cells[start.offset];
  2075. start.offset = 0;
  2076. }
  2077. }
  2078. if (_IERANGE) {
  2079. if (rng.item) {
  2080. doc = _getDoc(rng.item(0));
  2081. range = new KRange(doc);
  2082. range.selectNode(rng.item(0));
  2083. return range;
  2084. }
  2085. doc = rng.parentElement().ownerDocument;
  2086. var start = _getStartEnd(rng, true),
  2087. end = _getStartEnd(rng, false);
  2088. tr2td(start);
  2089. tr2td(end);
  2090. range = new KRange(doc);
  2091. range.setStart(start.node, start.offset);
  2092. range.setEnd(end.node, end.offset);
  2093. return range;
  2094. }
  2095. var startContainer = rng.startContainer;
  2096. doc = startContainer.ownerDocument || startContainer;
  2097. range = new KRange(doc);
  2098. range.setStart(startContainer, rng.startOffset);
  2099. range.setEnd(rng.endContainer, rng.endOffset);
  2100. return range;
  2101. }
  2102. function KRange(doc) {
  2103. this.init(doc);
  2104. }
  2105. _extend(KRange, {
  2106. init : function(doc) {
  2107. var self = this;
  2108. self.startContainer = doc;
  2109. self.startOffset = 0;
  2110. self.endContainer = doc;
  2111. self.endOffset = 0;
  2112. self.collapsed = true;
  2113. self.doc = doc;
  2114. },
  2115. commonAncestor : function() {
  2116. function getParents(node) {
  2117. var parents = [];
  2118. while (node) {
  2119. parents.push(node);
  2120. node = node.parentNode;
  2121. }
  2122. return parents;
  2123. }
  2124. var parentsA = getParents(this.startContainer),
  2125. parentsB = getParents(this.endContainer),
  2126. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2127. while (++i) {
  2128. parentA = parentsA[lenA - i];
  2129. parentB = parentsB[lenB - i];
  2130. if (!parentA || !parentB || parentA !== parentB) {
  2131. break;
  2132. }
  2133. }
  2134. return parentsA[lenA - i + 1];
  2135. },
  2136. setStart : function(node, offset) {
  2137. var self = this, doc = self.doc;
  2138. self.startContainer = node;
  2139. self.startOffset = offset;
  2140. if (self.endContainer === doc) {
  2141. self.endContainer = node;
  2142. self.endOffset = offset;
  2143. }
  2144. return _updateCollapsed(this);
  2145. },
  2146. setEnd : function(node, offset) {
  2147. var self = this, doc = self.doc;
  2148. self.endContainer = node;
  2149. self.endOffset = offset;
  2150. if (self.startContainer === doc) {
  2151. self.startContainer = node;
  2152. self.startOffset = offset;
  2153. }
  2154. return _updateCollapsed(this);
  2155. },
  2156. setStartBefore : function(node) {
  2157. return this.setStart(node.parentNode || this.doc, K(node).index());
  2158. },
  2159. setStartAfter : function(node) {
  2160. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2161. },
  2162. setEndBefore : function(node) {
  2163. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2164. },
  2165. setEndAfter : function(node) {
  2166. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2167. },
  2168. selectNode : function(node) {
  2169. return this.setStartBefore(node).setEndAfter(node);
  2170. },
  2171. selectNodeContents : function(node) {
  2172. var knode = K(node);
  2173. if (knode.type == 3 || knode.isSingle()) {
  2174. return this.selectNode(node);
  2175. }
  2176. var children = knode.children();
  2177. if (children.length > 0) {
  2178. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2179. }
  2180. return this.setStart(node, 0).setEnd(node, 0);
  2181. },
  2182. collapse : function(toStart) {
  2183. if (toStart) {
  2184. return this.setEnd(this.startContainer, this.startOffset);
  2185. }
  2186. return this.setStart(this.endContainer, this.endOffset);
  2187. },
  2188. compareBoundaryPoints : function(how, range) {
  2189. var rangeA = this.get(), rangeB = range.get();
  2190. if (_IERANGE) {
  2191. var arr = {};
  2192. arr[_START_TO_START] = 'StartToStart';
  2193. arr[_START_TO_END] = 'EndToStart';
  2194. arr[_END_TO_END] = 'EndToEnd';
  2195. arr[_END_TO_START] = 'StartToEnd';
  2196. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2197. if (cmp !== 0) {
  2198. return cmp;
  2199. }
  2200. var nodeA, nodeB, nodeC, posA, posB;
  2201. if (how === _START_TO_START || how === _END_TO_START) {
  2202. nodeA = this.startContainer;
  2203. posA = this.startOffset;
  2204. }
  2205. if (how === _START_TO_END || how === _END_TO_END) {
  2206. nodeA = this.endContainer;
  2207. posA = this.endOffset;
  2208. }
  2209. if (how === _START_TO_START || how === _START_TO_END) {
  2210. nodeB = range.startContainer;
  2211. posB = range.startOffset;
  2212. }
  2213. if (how === _END_TO_END || how === _END_TO_START) {
  2214. nodeB = range.endContainer;
  2215. posB = range.endOffset;
  2216. }
  2217. if (nodeA === nodeB) {
  2218. var diff = posA - posB;
  2219. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2220. }
  2221. nodeC = nodeB;
  2222. while (nodeC && nodeC.parentNode !== nodeA) {
  2223. nodeC = nodeC.parentNode;
  2224. }
  2225. if (nodeC) {
  2226. return K(nodeC).index() >= posA ? -1 : 1;
  2227. }
  2228. nodeC = nodeA;
  2229. while (nodeC && nodeC.parentNode !== nodeB) {
  2230. nodeC = nodeC.parentNode;
  2231. }
  2232. if (nodeC) {
  2233. return K(nodeC).index() >= posB ? 1 : -1;
  2234. }
  2235. nodeC = K(nodeB).next();
  2236. if (nodeC && nodeC.contains(nodeA)) {
  2237. return 1;
  2238. }
  2239. nodeC = K(nodeA).next();
  2240. if (nodeC && nodeC.contains(nodeB)) {
  2241. return -1;
  2242. }
  2243. } else {
  2244. return rangeA.compareBoundaryPoints(how, rangeB);
  2245. }
  2246. },
  2247. cloneRange : function() {
  2248. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2249. },
  2250. toString : function() {
  2251. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2252. return str.replace(/\r\n|\n|\r/g, '');
  2253. },
  2254. cloneContents : function() {
  2255. return _copyAndDelete(this, true, false);
  2256. },
  2257. deleteContents : function() {
  2258. return _copyAndDelete(this, false, true);
  2259. },
  2260. extractContents : function() {
  2261. return _copyAndDelete(this, true, true);
  2262. },
  2263. insertNode : function(node) {
  2264. var self = this,
  2265. sc = self.startContainer, so = self.startOffset,
  2266. ec = self.endContainer, eo = self.endOffset,
  2267. firstChild, lastChild, c, nodeCount = 1;
  2268. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2269. firstChild = node.firstChild;
  2270. lastChild = node.lastChild;
  2271. nodeCount = node.childNodes.length;
  2272. }
  2273. if (sc.nodeType == 1) {
  2274. c = sc.childNodes[so];
  2275. if (c) {
  2276. sc.insertBefore(node, c);
  2277. if (sc === ec) {
  2278. eo += nodeCount;
  2279. }
  2280. } else {
  2281. sc.appendChild(node);
  2282. }
  2283. } else if (sc.nodeType == 3) {
  2284. if (so === 0) {
  2285. sc.parentNode.insertBefore(node, sc);
  2286. if (sc.parentNode === ec) {
  2287. eo += nodeCount;
  2288. }
  2289. } else if (so >= sc.nodeValue.length) {
  2290. if (sc.nextSibling) {
  2291. sc.parentNode.insertBefore(node, sc.nextSibling);
  2292. } else {
  2293. sc.parentNode.appendChild(node);
  2294. }
  2295. } else {
  2296. if (so > 0) {
  2297. c = sc.splitText(so);
  2298. } else {
  2299. c = sc;
  2300. }
  2301. sc.parentNode.insertBefore(node, c);
  2302. if (sc === ec) {
  2303. ec = c;
  2304. eo -= so;
  2305. }
  2306. }
  2307. }
  2308. if (firstChild) {
  2309. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2310. } else {
  2311. self.selectNode(node);
  2312. }
  2313. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2314. return self;
  2315. }
  2316. return self.setEnd(ec, eo);
  2317. },
  2318. surroundContents : function(node) {
  2319. node.appendChild(this.extractContents());
  2320. return this.insertNode(node).selectNode(node);
  2321. },
  2322. isControl : function() {
  2323. var self = this,
  2324. sc = self.startContainer, so = self.startOffset,
  2325. ec = self.endContainer, eo = self.endOffset, rng;
  2326. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2327. },
  2328. get : function(hasControlRange) {
  2329. var self = this, doc = self.doc, node, rng;
  2330. if (!_IERANGE) {
  2331. rng = doc.createRange();
  2332. try {
  2333. rng.setStart(self.startContainer, self.startOffset);
  2334. rng.setEnd(self.endContainer, self.endOffset);
  2335. } catch (e) {}
  2336. return rng;
  2337. }
  2338. if (hasControlRange && self.isControl()) {
  2339. rng = doc.body.createControlRange();
  2340. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2341. return rng;
  2342. }
  2343. var range = self.cloneRange().down();
  2344. rng = doc.body.createTextRange();
  2345. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2346. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2347. return rng;
  2348. },
  2349. html : function() {
  2350. return K(this.cloneContents()).outer();
  2351. },
  2352. down : function() {
  2353. var self = this;
  2354. function downPos(node, pos, isStart) {
  2355. if (node.nodeType != 1) {
  2356. return;
  2357. }
  2358. var children = K(node).children();
  2359. if (children.length === 0) {
  2360. return;
  2361. }
  2362. var left, right, child, offset;
  2363. if (pos > 0) {
  2364. left = children.eq(pos - 1);
  2365. }
  2366. if (pos < children.length) {
  2367. right = children.eq(pos);
  2368. }
  2369. if (left && left.type == 3) {
  2370. child = left[0];
  2371. offset = child.nodeValue.length;
  2372. }
  2373. if (right && right.type == 3) {
  2374. child = right[0];
  2375. offset = 0;
  2376. }
  2377. if (!child) {
  2378. return;
  2379. }
  2380. if (isStart) {
  2381. self.setStart(child, offset);
  2382. } else {
  2383. self.setEnd(child, offset);
  2384. }
  2385. }
  2386. downPos(self.startContainer, self.startOffset, true);
  2387. downPos(self.endContainer, self.endOffset, false);
  2388. return self;
  2389. },
  2390. up : function() {
  2391. var self = this;
  2392. function upPos(node, pos, isStart) {
  2393. if (node.nodeType != 3) {
  2394. return;
  2395. }
  2396. if (pos === 0) {
  2397. if (isStart) {
  2398. self.setStartBefore(node);
  2399. } else {
  2400. self.setEndBefore(node);
  2401. }
  2402. } else if (pos == node.nodeValue.length) {
  2403. if (isStart) {
  2404. self.setStartAfter(node);
  2405. } else {
  2406. self.setEndAfter(node);
  2407. }
  2408. }
  2409. }
  2410. upPos(self.startContainer, self.startOffset, true);
  2411. upPos(self.endContainer, self.endOffset, false);
  2412. return self;
  2413. },
  2414. enlarge : function(toBlock) {
  2415. var self = this;
  2416. self.up();
  2417. function enlargePos(node, pos, isStart) {
  2418. var knode = K(node), parent;
  2419. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2420. return;
  2421. }
  2422. if (pos === 0) {
  2423. while (!knode.prev()) {
  2424. parent = knode.parent();
  2425. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2426. break;
  2427. }
  2428. knode = parent;
  2429. }
  2430. if (isStart) {
  2431. self.setStartBefore(knode[0]);
  2432. } else {
  2433. self.setEndBefore(knode[0]);
  2434. }
  2435. } else if (pos == knode.children().length) {
  2436. while (!knode.next()) {
  2437. parent = knode.parent();
  2438. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2439. break;
  2440. }
  2441. knode = parent;
  2442. }
  2443. if (isStart) {
  2444. self.setStartAfter(knode[0]);
  2445. } else {
  2446. self.setEndAfter(knode[0]);
  2447. }
  2448. }
  2449. }
  2450. enlargePos(self.startContainer, self.startOffset, true);
  2451. enlargePos(self.endContainer, self.endOffset, false);
  2452. return self;
  2453. },
  2454. shrink : function() {
  2455. var self = this, child, collapsed = self.collapsed;
  2456. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2457. self.setStart(child, 0);
  2458. }
  2459. if (collapsed) {
  2460. return self.collapse(collapsed);
  2461. }
  2462. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2463. self.setEnd(child, child.childNodes.length);
  2464. }
  2465. return self;
  2466. },
  2467. createBookmark : function(serialize) {
  2468. var self = this, doc = self.doc, endNode,
  2469. startNode = K('<span style="display:none;"></span>', doc)[0];
  2470. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2471. if (!self.collapsed) {
  2472. endNode = startNode.cloneNode(true);
  2473. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2474. }
  2475. if (endNode) {
  2476. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2477. }
  2478. self.insertNode(startNode).setStartAfter(startNode);
  2479. return {
  2480. start : serialize ? '#' + startNode.id : startNode,
  2481. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2482. };
  2483. },
  2484. moveToBookmark : function(bookmark) {
  2485. var self = this, doc = self.doc,
  2486. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2487. if (!start || start.length < 1) {
  2488. return self;
  2489. }
  2490. self.setStartBefore(start[0]);
  2491. start.remove();
  2492. if (end && end.length > 0) {
  2493. self.setEndBefore(end[0]);
  2494. end.remove();
  2495. } else {
  2496. self.collapse(true);
  2497. }
  2498. return self;
  2499. },
  2500. dump : function() {
  2501. console.log('--------------------');
  2502. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2503. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2504. }
  2505. });
  2506. function _range(mixed) {
  2507. if (!mixed.nodeName) {
  2508. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2509. }
  2510. return new KRange(mixed);
  2511. }
  2512. K.RangeClass = KRange;
  2513. K.range = _range;
  2514. K.START_TO_START = _START_TO_START;
  2515. K.START_TO_END = _START_TO_END;
  2516. K.END_TO_END = _END_TO_END;
  2517. K.END_TO_START = _END_TO_START;
  2518. function _nativeCommand(doc, key, val) {
  2519. try {
  2520. doc.execCommand(key, false, val);
  2521. } catch(e) {}
  2522. }
  2523. function _nativeCommandValue(doc, key) {
  2524. var val = '';
  2525. try {
  2526. val = doc.queryCommandValue(key);
  2527. } catch (e) {}
  2528. if (typeof val !== 'string') {
  2529. val = '';
  2530. }
  2531. return val;
  2532. }
  2533. function _getSel(doc) {
  2534. var win = _getWin(doc);
  2535. return _IERANGE ? doc.selection : win.getSelection();
  2536. }
  2537. function _getRng(doc) {
  2538. var sel = _getSel(doc), rng;
  2539. try {
  2540. if (sel.rangeCount > 0) {
  2541. rng = sel.getRangeAt(0);
  2542. } else {
  2543. rng = sel.createRange();
  2544. }
  2545. } catch(e) {}
  2546. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2547. return null;
  2548. }
  2549. return rng;
  2550. }
  2551. function _singleKeyMap(map) {
  2552. var newMap = {}, arr, v;
  2553. _each(map, function(key, val) {
  2554. arr = key.split(',');
  2555. for (var i = 0, len = arr.length; i < len; i++) {
  2556. v = arr[i];
  2557. newMap[v] = val;
  2558. }
  2559. });
  2560. return newMap;
  2561. }
  2562. function _hasAttrOrCss(knode, map) {
  2563. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2564. }
  2565. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2566. mapKey = mapKey || knode.name;
  2567. if (knode.type !== 1) {
  2568. return false;
  2569. }
  2570. var newMap = _singleKeyMap(map);
  2571. if (!newMap[mapKey]) {
  2572. return false;
  2573. }
  2574. var arr = newMap[mapKey].split(',');
  2575. for (var i = 0, len = arr.length; i < len; i++) {
  2576. var key = arr[i];
  2577. if (key === '*') {
  2578. return true;
  2579. }
  2580. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2581. var method = match[1] ? 'css' : 'attr';
  2582. key = match[2];
  2583. var val = match[3] || '';
  2584. if (val === '' && knode[method](key) !== '') {
  2585. return true;
  2586. }
  2587. if (val !== '' && knode[method](key) === val) {
  2588. return true;
  2589. }
  2590. }
  2591. return false;
  2592. }
  2593. function _removeAttrOrCss(knode, map) {
  2594. if (knode.type != 1) {
  2595. return;
  2596. }
  2597. _removeAttrOrCssByKey(knode, map, '*');
  2598. _removeAttrOrCssByKey(knode, map);
  2599. }
  2600. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2601. mapKey = mapKey || knode.name;
  2602. if (knode.type !== 1) {
  2603. return;
  2604. }
  2605. var newMap = _singleKeyMap(map);
  2606. if (!newMap[mapKey]) {
  2607. return;
  2608. }
  2609. var arr = newMap[mapKey].split(','), allFlag = false;
  2610. for (var i = 0, len = arr.length; i < len; i++) {
  2611. var key = arr[i];
  2612. if (key === '*') {
  2613. allFlag = true;
  2614. break;
  2615. }
  2616. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2617. key = match[2];
  2618. if (match[1]) {
  2619. key = _toCamel(key);
  2620. if (knode[0].style[key]) {
  2621. knode[0].style[key] = '';
  2622. }
  2623. } else {
  2624. knode.removeAttr(key);
  2625. }
  2626. }
  2627. if (allFlag) {
  2628. knode.remove(true);
  2629. }
  2630. }
  2631. function _getInnerNode(knode) {
  2632. var inner = knode;
  2633. while (inner.first()) {
  2634. inner = inner.first();
  2635. }
  2636. return inner;
  2637. }
  2638. function _isEmptyNode(knode) {
  2639. if (knode.type != 1 || knode.isSingle()) {
  2640. return false;
  2641. }
  2642. return knode.html().replace(/<[^>]+>/g, '') === '';
  2643. }
  2644. function _mergeWrapper(a, b) {
  2645. a = a.clone(true);
  2646. var lastA = _getInnerNode(a), childA = a, merged = false;
  2647. while (b) {
  2648. while (childA) {
  2649. if (childA.name === b.name) {
  2650. _mergeAttrs(childA, b.attr(), b.css());
  2651. merged = true;
  2652. }
  2653. childA = childA.first();
  2654. }
  2655. if (!merged) {
  2656. lastA.append(b.clone(false));
  2657. }
  2658. merged = false;
  2659. b = b.first();
  2660. }
  2661. return a;
  2662. }
  2663. function _wrapNode(knode, wrapper) {
  2664. wrapper = wrapper.clone(true);
  2665. if (knode.type == 3) {
  2666. _getInnerNode(wrapper).append(knode.clone(false));
  2667. knode.replaceWith(wrapper);
  2668. return wrapper;
  2669. }
  2670. var nodeWrapper = knode, child;
  2671. while ((child = knode.first()) && child.children().length == 1) {
  2672. knode = child;
  2673. }
  2674. child = knode.first();
  2675. var frag = knode.doc.createDocumentFragment();
  2676. while (child) {
  2677. frag.appendChild(child[0]);
  2678. child = child.next();
  2679. }
  2680. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2681. if (frag.firstChild) {
  2682. _getInnerNode(wrapper).append(frag);
  2683. }
  2684. nodeWrapper.replaceWith(wrapper);
  2685. return wrapper;
  2686. }
  2687. function _mergeAttrs(knode, attrs, styles) {
  2688. _each(attrs, function(key, val) {
  2689. if (key !== 'style') {
  2690. knode.attr(key, val);
  2691. }
  2692. });
  2693. _each(styles, function(key, val) {
  2694. knode.css(key, val);
  2695. });
  2696. }
  2697. function _inPreElement(knode) {
  2698. while (knode && knode.name != 'body') {
  2699. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2700. return true;
  2701. }
  2702. knode = knode.parent();
  2703. }
  2704. return false;
  2705. }
  2706. function KCmd(range) {
  2707. this.init(range);
  2708. }
  2709. _extend(KCmd, {
  2710. init : function(range) {
  2711. var self = this, doc = range.doc;
  2712. self.doc = doc;
  2713. self.win = _getWin(doc);
  2714. self.sel = _getSel(doc);
  2715. self.range = range;
  2716. },
  2717. selection : function(forceReset) {
  2718. var self = this, doc = self.doc, rng = _getRng(doc);
  2719. self.sel = _getSel(doc);
  2720. if (rng) {
  2721. self.range = _range(rng);
  2722. if (K(self.range.startContainer).name == 'html') {
  2723. self.range.selectNodeContents(doc.body).collapse(false);
  2724. }
  2725. return self;
  2726. }
  2727. if (forceReset) {
  2728. self.range.selectNodeContents(doc.body).collapse(false);
  2729. }
  2730. return self;
  2731. },
  2732. select : function(hasDummy) {
  2733. hasDummy = _undef(hasDummy, true);
  2734. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2735. sc = range.startContainer, so = range.startOffset,
  2736. ec = range.endContainer, eo = range.endOffset,
  2737. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2738. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2739. if (_IERANGE) {
  2740. var dummy = K('<span>&nbsp;</span>', doc);
  2741. range.insertNode(dummy[0]);
  2742. rng = doc.body.createTextRange();
  2743. try {
  2744. rng.moveToElementText(dummy[0]);
  2745. } catch(ex) {}
  2746. rng.collapse(false);
  2747. rng.select();
  2748. dummy.remove();
  2749. win.focus();
  2750. return self;
  2751. }
  2752. if (_WEBKIT) {
  2753. var children = sc.childNodes;
  2754. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2755. range.insertNode(doc.createTextNode('\u200B'));
  2756. hasU200b = true;
  2757. }
  2758. }
  2759. }
  2760. if (_IERANGE) {
  2761. try {
  2762. rng = range.get(true);
  2763. rng.select();
  2764. } catch(e) {}
  2765. } else {
  2766. if (hasU200b) {
  2767. range.collapse(false);
  2768. }
  2769. rng = range.get(true);
  2770. sel.removeAllRanges();
  2771. sel.addRange(rng);
  2772. if (doc !== document) {
  2773. var pos = K(rng.endContainer).pos();
  2774. //win.scrollTo(pos.x, pos.y);
  2775. }
  2776. }
  2777. win.focus();
  2778. return self;
  2779. },
  2780. wrap : function(val) {
  2781. var self = this, doc = self.doc, range = self.range, wrapper;
  2782. wrapper = K(val, doc);
  2783. if (range.collapsed) {
  2784. range.shrink();
  2785. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2786. return self;
  2787. }
  2788. if (wrapper.isBlock()) {
  2789. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2790. while (child.first()) {
  2791. child = child.first();
  2792. }
  2793. child.append(range.extractContents());
  2794. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2795. return self;
  2796. }
  2797. range.enlarge();
  2798. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2799. K(ancestor).scan(function(node) {
  2800. if (!isStart && node == bookmark.start) {
  2801. isStart = true;
  2802. return;
  2803. }
  2804. if (isStart) {
  2805. if (node == bookmark.end) {
  2806. return false;
  2807. }
  2808. var knode = K(node);
  2809. if (_inPreElement(knode)) {
  2810. return;
  2811. }
  2812. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2813. var parent;
  2814. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2815. knode = parent;
  2816. }
  2817. _wrapNode(knode, wrapper);
  2818. }
  2819. }
  2820. });
  2821. range.moveToBookmark(bookmark);
  2822. return self;
  2823. },
  2824. split : function(isStart, map) {
  2825. var range = this.range, doc = range.doc;
  2826. var tempRange = range.cloneRange().collapse(isStart);
  2827. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2828. parent = node.nodeType == 3 ? node.parentNode : node,
  2829. needSplit = false, knode;
  2830. while (parent && parent.parentNode) {
  2831. knode = K(parent);
  2832. if (map) {
  2833. if (!knode.isStyle()) {
  2834. break;
  2835. }
  2836. if (!_hasAttrOrCss(knode, map)) {
  2837. break;
  2838. }
  2839. } else {
  2840. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2841. break;
  2842. }
  2843. }
  2844. needSplit = true;
  2845. parent = parent.parentNode;
  2846. }
  2847. if (needSplit) {
  2848. var dummy = doc.createElement('span');
  2849. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2850. if (isStart) {
  2851. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2852. } else {
  2853. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2854. }
  2855. var frag = tempRange.extractContents(),
  2856. first = frag.firstChild, last = frag.lastChild;
  2857. if (isStart) {
  2858. tempRange.insertNode(frag);
  2859. range.setStartAfter(last).setEndBefore(dummy);
  2860. } else {
  2861. parent.appendChild(frag);
  2862. range.setStartBefore(dummy).setEndBefore(first);
  2863. }
  2864. var dummyParent = dummy.parentNode;
  2865. if (dummyParent == range.endContainer) {
  2866. var prev = K(dummy).prev(), next = K(dummy).next();
  2867. if (prev && next && prev.type == 3 && next.type == 3) {
  2868. range.setEnd(prev[0], prev[0].nodeValue.length);
  2869. } else if (!isStart) {
  2870. range.setEnd(range.endContainer, range.endOffset - 1);
  2871. }
  2872. }
  2873. dummyParent.removeChild(dummy);
  2874. }
  2875. return this;
  2876. },
  2877. remove : function(map) {
  2878. var self = this, doc = self.doc, range = self.range;
  2879. range.enlarge();
  2880. if (range.startOffset === 0) {
  2881. var ksc = K(range.startContainer), parent;
  2882. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2883. ksc = parent;
  2884. }
  2885. range.setStart(ksc[0], 0);
  2886. ksc = K(range.startContainer);
  2887. if (ksc.isBlock()) {
  2888. _removeAttrOrCss(ksc, map);
  2889. }
  2890. var kscp = ksc.parent();
  2891. if (kscp && kscp.isBlock()) {
  2892. _removeAttrOrCss(kscp, map);
  2893. }
  2894. }
  2895. var sc, so;
  2896. if (range.collapsed) {
  2897. self.split(true, map);
  2898. sc = range.startContainer;
  2899. so = range.startOffset;
  2900. if (so > 0) {
  2901. var sb = K(sc.childNodes[so - 1]);
  2902. if (sb && _isEmptyNode(sb)) {
  2903. sb.remove();
  2904. range.setStart(sc, so - 1);
  2905. }
  2906. }
  2907. var sa = K(sc.childNodes[so]);
  2908. if (sa && _isEmptyNode(sa)) {
  2909. sa.remove();
  2910. }
  2911. if (_isEmptyNode(sc)) {
  2912. range.startBefore(sc);
  2913. sc.remove();
  2914. }
  2915. range.collapse(true);
  2916. return self;
  2917. }
  2918. self.split(true, map);
  2919. self.split(false, map);
  2920. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2921. range.cloneRange().collapse(false).insertNode(endDummy);
  2922. range.cloneRange().collapse(true).insertNode(startDummy);
  2923. var nodeList = [], cmpStart = false;
  2924. K(range.commonAncestor()).scan(function(node) {
  2925. if (!cmpStart && node == startDummy) {
  2926. cmpStart = true;
  2927. return;
  2928. }
  2929. if (node == endDummy) {
  2930. return false;
  2931. }
  2932. if (cmpStart) {
  2933. nodeList.push(node);
  2934. }
  2935. });
  2936. K(startDummy).remove();
  2937. K(endDummy).remove();
  2938. sc = range.startContainer;
  2939. so = range.startOffset;
  2940. var ec = range.endContainer, eo = range.endOffset;
  2941. if (so > 0) {
  2942. var startBefore = K(sc.childNodes[so - 1]);
  2943. if (startBefore && _isEmptyNode(startBefore)) {
  2944. startBefore.remove();
  2945. range.setStart(sc, so - 1);
  2946. if (sc == ec) {
  2947. range.setEnd(ec, eo - 1);
  2948. }
  2949. }
  2950. var startAfter = K(sc.childNodes[so]);
  2951. if (startAfter && _isEmptyNode(startAfter)) {
  2952. startAfter.remove();
  2953. if (sc == ec) {
  2954. range.setEnd(ec, eo - 1);
  2955. }
  2956. }
  2957. }
  2958. var endAfter = K(ec.childNodes[range.endOffset]);
  2959. if (endAfter && _isEmptyNode(endAfter)) {
  2960. endAfter.remove();
  2961. }
  2962. var bookmark = range.createBookmark(true);
  2963. _each(nodeList, function(i, node) {
  2964. _removeAttrOrCss(K(node), map);
  2965. });
  2966. range.moveToBookmark(bookmark);
  2967. return self;
  2968. },
  2969. commonNode : function(map) {
  2970. var range = this.range;
  2971. var ec = range.endContainer, eo = range.endOffset,
  2972. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2973. function find(node) {
  2974. var child = node, parent = node;
  2975. while (parent) {
  2976. if (_hasAttrOrCss(K(parent), map)) {
  2977. return K(parent);
  2978. }
  2979. parent = parent.parentNode;
  2980. }
  2981. while (child && (child = child.lastChild)) {
  2982. if (_hasAttrOrCss(K(child), map)) {
  2983. return K(child);
  2984. }
  2985. }
  2986. return null;
  2987. }
  2988. var cNode = find(node);
  2989. if (cNode) {
  2990. return cNode;
  2991. }
  2992. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2993. var prev = K(node).prev();
  2994. if (prev) {
  2995. return find(prev);
  2996. }
  2997. }
  2998. return null;
  2999. },
  3000. commonAncestor : function(tagName) {
  3001. var range = this.range,
  3002. sc = range.startContainer, so = range.startOffset,
  3003. ec = range.endContainer, eo = range.endOffset,
  3004. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3005. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3006. function find(node) {
  3007. while (node) {
  3008. if (node.nodeType == 1) {
  3009. if (node.tagName.toLowerCase() === tagName) {
  3010. return node;
  3011. }
  3012. }
  3013. node = node.parentNode;
  3014. }
  3015. return null;
  3016. }
  3017. var start = find(startNode), end = find(endNode);
  3018. if (start && end && start === end) {
  3019. return K(start);
  3020. }
  3021. return null;
  3022. },
  3023. state : function(key) {
  3024. var self = this, doc = self.doc, bool = false;
  3025. try {
  3026. bool = doc.queryCommandState(key);
  3027. } catch (e) {}
  3028. return bool;
  3029. },
  3030. val : function(key) {
  3031. var self = this, doc = self.doc, range = self.range;
  3032. function lc(val) {
  3033. return val.toLowerCase();
  3034. }
  3035. key = lc(key);
  3036. var val = '', knode;
  3037. if (key === 'fontfamily' || key === 'fontname') {
  3038. val = _nativeCommandValue(doc, 'fontname');
  3039. val = val.replace(/['"]/g, '');
  3040. return lc(val);
  3041. }
  3042. if (key === 'formatblock') {
  3043. val = _nativeCommandValue(doc, key);
  3044. if (val === '') {
  3045. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3046. if (knode) {
  3047. val = knode.name;
  3048. }
  3049. }
  3050. if (val === 'Normal') {
  3051. val = 'p';
  3052. }
  3053. return lc(val);
  3054. }
  3055. if (key === 'fontsize') {
  3056. knode = self.commonNode({'*' : '.font-size'});
  3057. if (knode) {
  3058. val = knode.css('font-size');
  3059. }
  3060. return lc(val);
  3061. }
  3062. if (key === 'fontheight') {
  3063. knode = self.commonNode({'*' : '.letter-spacing'});
  3064. if (knode) {
  3065. val = knode.css('letter-spacing');
  3066. }
  3067. return lc(val);
  3068. }
  3069. if (key === 'forecolor') {
  3070. knode = self.commonNode({'*' : '.color'});
  3071. if (knode) {
  3072. val = knode.css('color');
  3073. }
  3074. val = _toHex(val);
  3075. if (val === '') {
  3076. val = 'default';
  3077. }
  3078. return lc(val);
  3079. }
  3080. if (key === 'hilitecolor') {
  3081. knode = self.commonNode({'*' : '.background-color'});
  3082. if (knode) {
  3083. val = knode.css('background-color');
  3084. }
  3085. val = _toHex(val);
  3086. if (val === '') {
  3087. val = 'default';
  3088. }
  3089. return lc(val);
  3090. }
  3091. return val;
  3092. },
  3093. toggle : function(wrapper, map) {
  3094. var self = this;
  3095. if (self.commonNode(map)) {
  3096. self.remove(map);
  3097. } else {
  3098. self.wrap(wrapper);
  3099. }
  3100. return self.select();
  3101. },
  3102. bold : function() {
  3103. return this.toggle('<strong></strong>', {
  3104. span : '.font-weight=bold',
  3105. strong : '*',
  3106. b : '*'
  3107. });
  3108. },
  3109. italic : function() {
  3110. return this.toggle('<em></em>', {
  3111. span : '.font-style=italic',
  3112. em : '*',
  3113. i : '*'
  3114. });
  3115. },
  3116. underline : function() {
  3117. return this.toggle('<u></u>', {
  3118. span : '.text-decoration=underline',
  3119. u : '*'
  3120. });
  3121. },
  3122. strikethrough : function() {
  3123. return this.toggle('<s></s>', {
  3124. span : '.text-decoration=line-through',
  3125. s : '*'
  3126. });
  3127. },
  3128. forecolor : function(val) {
  3129. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3130. },
  3131. hilitecolor : function(val) {
  3132. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3133. },
  3134. fontsize : function(val) {
  3135. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3136. },
  3137. fontheight : function(val) {
  3138. return this.wrap('<span style="letter-spacing:' + val + ';"></span>').select();
  3139. },
  3140. fontname : function(val) {
  3141. return this.fontfamily(val);
  3142. },
  3143. fontfamily : function(val) {
  3144. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3145. },
  3146. removeformat : function() {
  3147. var map = {
  3148. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3149. },
  3150. tags = _STYLE_TAG_MAP;
  3151. _each(tags, function(key, val) {
  3152. map[key] = '*';
  3153. });
  3154. this.remove(map);
  3155. return this.select();
  3156. },
  3157. inserthtml : function(val, quickMode) {
  3158. var self = this, range = self.range;
  3159. if (val === '') {
  3160. return self;
  3161. }
  3162. function pasteHtml(range, val) {
  3163. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3164. var rng = range.get();
  3165. if (rng.item) {
  3166. rng.item(0).outerHTML = val;
  3167. } else {
  3168. rng.pasteHTML(val);
  3169. }
  3170. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3171. temp.parentNode.removeChild(temp);
  3172. var newRange = _toRange(rng);
  3173. range.setEnd(newRange.endContainer, newRange.endOffset);
  3174. range.collapse(false);
  3175. self.select(false);
  3176. }
  3177. function insertHtml(range, val) {
  3178. var doc = range.doc,
  3179. frag = doc.createDocumentFragment();
  3180. K('@' + val, doc).each(function() {
  3181. frag.appendChild(this);
  3182. });
  3183. range.deleteContents();
  3184. range.insertNode(frag);
  3185. range.collapse(false);
  3186. self.select(false);
  3187. }
  3188. if (_IERANGE && quickMode) {
  3189. try {
  3190. pasteHtml(range, val);
  3191. } catch(e) {
  3192. insertHtml(range, val);
  3193. }
  3194. return self;
  3195. }
  3196. insertHtml(range, val);
  3197. return self;
  3198. },
  3199. hr : function() {
  3200. return this.inserthtml('<hr />');
  3201. },
  3202. print : function() {
  3203. this.win.print();
  3204. return this;
  3205. },
  3206. insertimage : function(url, title, width, height, border, align) {
  3207. title = _undef(title, '');
  3208. border = _undef(border, 0);
  3209. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3210. if (width) {
  3211. html += 'width="' + _escape(width) + '" ';
  3212. }
  3213. if (height) {
  3214. html += 'height="' + _escape(height) + '" ';
  3215. }
  3216. if (title) {
  3217. html += 'title="' + _escape(title) + '" ';
  3218. }
  3219. if (align) {
  3220. html += 'align="' + _escape(align) + '" ';
  3221. }
  3222. html += 'alt="' + _escape(title) + '" ';
  3223. html += '/>';
  3224. return this.inserthtml(html);
  3225. },
  3226. createlink : function(url, type) {
  3227. var self = this, doc = self.doc, range = self.range;
  3228. self.select();
  3229. var a = self.commonNode({ a : '*' });
  3230. if (a && !range.isControl()) {
  3231. range.selectNode(a.get());
  3232. self.select();
  3233. }
  3234. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3235. if (type) {
  3236. html += ' target="' + _escape(type) + '"';
  3237. }
  3238. if (range.collapsed) {
  3239. html += '>' + _escape(url) + '</a>';
  3240. return self.inserthtml(html);
  3241. }
  3242. if (range.isControl()) {
  3243. var node = K(range.startContainer.childNodes[range.startOffset]);
  3244. html += '></a>';
  3245. node.after(K(html, doc));
  3246. node.next().append(node);
  3247. range.selectNode(node[0]);
  3248. return self.select();
  3249. }
  3250. function setAttr(node, url, type) {
  3251. K(node).attr('href', url).attr('data-ke-src', url);
  3252. if (type) {
  3253. K(node).attr('target', type);
  3254. } else {
  3255. K(node).removeAttr('target');
  3256. }
  3257. }
  3258. var sc = range.startContainer, so = range.startOffset,
  3259. ec = range.endContainer, eo = range.endOffset;
  3260. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3261. var child = sc.childNodes[so];
  3262. if (child.nodeName.toLowerCase() == 'a') {
  3263. setAttr(child, url, type);
  3264. return self;
  3265. }
  3266. }
  3267. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3268. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3269. setAttr(this, url, type);
  3270. });
  3271. return self;
  3272. },
  3273. unlink : function() {
  3274. var self = this, doc = self.doc, range = self.range;
  3275. self.select();
  3276. if (range.collapsed) {
  3277. var a = self.commonNode({ a : '*' });
  3278. if (a) {
  3279. range.selectNode(a.get());
  3280. self.select();
  3281. }
  3282. _nativeCommand(doc, 'unlink', null);
  3283. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3284. var parent = K(range.startContainer).parent();
  3285. if (parent.name === 'a') {
  3286. parent.remove(true);
  3287. }
  3288. }
  3289. } else {
  3290. _nativeCommand(doc, 'unlink', null);
  3291. }
  3292. return self;
  3293. }
  3294. });
  3295. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3296. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3297. KCmd.prototype[name] = function(val) {
  3298. var self = this;
  3299. self.select();
  3300. _nativeCommand(self.doc, name, val);
  3301. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3302. self.selection();
  3303. }
  3304. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3305. self.selection();
  3306. }
  3307. return self;
  3308. };
  3309. });
  3310. _each('cut,copy,paste'.split(','), function(i, name) {
  3311. KCmd.prototype[name] = function() {
  3312. var self = this;
  3313. if (!self.doc.queryCommandSupported(name)) {
  3314. throw 'not supported';
  3315. }
  3316. self.select();
  3317. _nativeCommand(self.doc, name, null);
  3318. return self;
  3319. };
  3320. });
  3321. function _cmd(mixed) {
  3322. if (mixed.nodeName) {
  3323. var doc = _getDoc(mixed);
  3324. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3325. }
  3326. return new KCmd(mixed);
  3327. }
  3328. K.CmdClass = KCmd;
  3329. K.cmd = _cmd;
  3330. function _drag(options) {
  3331. var moveEl = options.moveEl,
  3332. moveFn = options.moveFn,
  3333. clickEl = options.clickEl || moveEl,
  3334. beforeDrag = options.beforeDrag,
  3335. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3336. var docs = [document];
  3337. if (iframeFix) {
  3338. K('iframe').each(function() {
  3339. var src = _formatUrl(this.src || '', 'absolute');
  3340. if (/^https?:\/\//.test(src)) {
  3341. return;
  3342. }
  3343. var doc;
  3344. try {
  3345. doc = _iframeDoc(this);
  3346. } catch(e) {}
  3347. if (doc) {
  3348. var pos = K(this).pos();
  3349. K(doc).data('pos-x', pos.x);
  3350. K(doc).data('pos-y', pos.y);
  3351. docs.push(doc);
  3352. }
  3353. });
  3354. }
  3355. clickEl.mousedown(function(e) {
  3356. if(e.button !== 0 && e.button !== 1) {
  3357. return;
  3358. }
  3359. e.stopPropagation();
  3360. var self = clickEl.get(),
  3361. x = _removeUnit(moveEl.css('left')),
  3362. y = _removeUnit(moveEl.css('top')),
  3363. width = moveEl.width(),
  3364. height = moveEl.height(),
  3365. pageX = e.pageX,
  3366. pageY = e.pageY;
  3367. if (beforeDrag) {
  3368. beforeDrag();
  3369. }
  3370. function moveListener(e) {
  3371. e.preventDefault();
  3372. var kdoc = K(_getDoc(e.target));
  3373. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3374. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3375. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3376. }
  3377. function selectListener(e) {
  3378. e.preventDefault();
  3379. }
  3380. function upListener(e) {
  3381. e.preventDefault();
  3382. K(docs).unbind('mousemove', moveListener)
  3383. .unbind('mouseup', upListener)
  3384. .unbind('selectstart', selectListener);
  3385. if (self.releaseCapture) {
  3386. self.releaseCapture();
  3387. }
  3388. }
  3389. K(docs).mousemove(moveListener)
  3390. .mouseup(upListener)
  3391. .bind('selectstart', selectListener);
  3392. if (self.setCapture) {
  3393. self.setCapture();
  3394. }
  3395. });
  3396. }
  3397. function KWidget(options) {
  3398. this.init(options);
  3399. }
  3400. _extend(KWidget, {
  3401. init : function(options) {
  3402. var self = this;
  3403. self.name = options.name || '';
  3404. self.doc = options.doc || document;
  3405. self.win = _getWin(self.doc);
  3406. self.x = _addUnit(options.x);
  3407. self.y = _addUnit(options.y);
  3408. self.z = options.z;
  3409. self.width = _addUnit(options.width);
  3410. self.height = _addUnit(options.height);
  3411. self.index = _addUnit(options.index);
  3412. self.div = K('<div style="display:block;"></div>');
  3413. self.options = options;
  3414. self._alignEl = options.alignEl;
  3415. if (self.width) {
  3416. self.div.css('width', self.width);
  3417. }
  3418. if (self.height) {
  3419. self.div.css('height', self.height);
  3420. }
  3421. if (self.z) {
  3422. self.div.css({
  3423. position : 'absolute',
  3424. left : self.x,
  3425. top : self.y,
  3426. 'z-index' : self.z
  3427. });
  3428. }
  3429. if (self.z && (self.x === undefined || self.y === undefined)) {
  3430. self.autoPos(self.width, self.height);
  3431. }
  3432. if (options.cls) {
  3433. self.div.addClass(options.cls);
  3434. }
  3435. if (options.shadowMode) {
  3436. self.div.addClass('ke-shadow');
  3437. }
  3438. if (options.css) {
  3439. self.div.css(options.css);
  3440. }
  3441. if (options.src) {
  3442. K(options.src).replaceWith(self.div);
  3443. } else {
  3444. K(self.doc.body).append(self.div);
  3445. }
  3446. if (options.html) {
  3447. self.div.html(options.html);
  3448. }
  3449. if (options.autoScroll) {
  3450. if (_IE && _V < 7 || _QUIRKS) {
  3451. var scrollPos = _getScrollPos();
  3452. K(self.win).bind('scroll', function(e) {
  3453. var pos = _getScrollPos(),
  3454. diffX = pos.x - scrollPos.x,
  3455. diffY = pos.y - scrollPos.y;
  3456. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3457. });
  3458. } else {
  3459. self.div.css('position', 'fixed');
  3460. }
  3461. }
  3462. },
  3463. pos : function(x, y, updateProp) {
  3464. var self = this;
  3465. updateProp = _undef(updateProp, true);
  3466. if (x !== null) {
  3467. x = x < 0 ? 0 : _addUnit(x);
  3468. self.div.css('left', x);
  3469. if (updateProp) {
  3470. self.x = x;
  3471. }
  3472. }
  3473. if (y !== null) {
  3474. y = y < 0 ? 0 : _addUnit(y);
  3475. self.div.css('top', y);
  3476. if (updateProp) {
  3477. self.y = y;
  3478. }
  3479. }
  3480. return self;
  3481. },
  3482. autoPos : function(width, height) {
  3483. var x, y, self = this,
  3484. w = _removeUnit(width) || 0,
  3485. h = _removeUnit(height) || 0,
  3486. scrollPos = _getScrollPos();
  3487. if (self._alignEl) {
  3488. var knode = K(self._alignEl),
  3489. pos = knode.pos(),
  3490. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3491. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3492. x = diffX < 0 ? pos.x : pos.x + diffX;
  3493. y = diffY < 0 ? pos.y : pos.y + diffY;
  3494. } else {
  3495. var docEl = _docElement(self.doc);
  3496. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3497. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3498. }
  3499. if (!(_IE && _V < 7 || _QUIRKS)) {
  3500. x -= scrollPos.x;
  3501. y -= scrollPos.y;
  3502. }
  3503. return self.pos(x, y);
  3504. },
  3505. remove : function() {
  3506. var self = this;
  3507. if (_IE && _V < 7 || _QUIRKS) {
  3508. K(self.win).unbind('scroll');
  3509. }
  3510. self.div.remove();
  3511. _each(self, function(i) {
  3512. self[i] = null;
  3513. });
  3514. return this;
  3515. },
  3516. show : function() {
  3517. this.div.show();
  3518. return this;
  3519. },
  3520. hide : function() {
  3521. this.div.hide();
  3522. return this;
  3523. },
  3524. draggable : function(options) {
  3525. var self = this;
  3526. options = options || {};
  3527. options.moveEl = self.div;
  3528. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3529. if ((x = x + diffX) < 0) {
  3530. x = 0;
  3531. }
  3532. if ((y = y + diffY) < 0) {
  3533. y = 0;
  3534. }
  3535. self.pos(x, y);
  3536. };
  3537. _drag(options);
  3538. return self;
  3539. }
  3540. });
  3541. function _widget(options) {
  3542. return new KWidget(options);
  3543. }
  3544. K.WidgetClass = KWidget;
  3545. K.widget = _widget;
  3546. function _iframeDoc(iframe) {
  3547. iframe = _get(iframe);
  3548. return iframe.contentDocument || iframe.contentWindow.document;
  3549. }
  3550. var html, _direction = '';
  3551. if ((html = document.getElementsByTagName('html'))) {
  3552. _direction = html[0].dir;
  3553. }
  3554. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3555. var arr = [
  3556. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3557. '<head><meta charset="utf-8" /><title></title>',
  3558. '<style>',
  3559. 'html {margin:0;padding:0;}',
  3560. 'body {margin:0;padding:5px;}',
  3561. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3562. 'body, p, div {word-wrap: break-word;}',
  3563. 'p {margin:5px 0;}',
  3564. 'table {border-collapse:collapse;}',
  3565. 'img {border:0;}',
  3566. 'noscript {display:none;}',
  3567. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3568. 'img.ke-flash {',
  3569. ' border:1px solid #AAA;',
  3570. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3571. ' background-position:center center;',
  3572. ' background-repeat:no-repeat;',
  3573. ' width:100px;',
  3574. ' height:100px;',
  3575. '}',
  3576. 'img.ke-rm {',
  3577. ' border:1px solid #AAA;',
  3578. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3579. ' background-position:center center;',
  3580. ' background-repeat:no-repeat;',
  3581. ' width:100px;',
  3582. ' height:100px;',
  3583. '}',
  3584. 'img.ke-media {',
  3585. ' border:1px solid #AAA;',
  3586. ' background-image:url(' + themesPath + 'common/media.gif);',
  3587. ' background-position:center center;',
  3588. ' background-repeat:no-repeat;',
  3589. ' width:100px;',
  3590. ' height:100px;',
  3591. '}',
  3592. 'img.ke-anchor {',
  3593. ' border:1px dashed #666;',
  3594. ' width:16px;',
  3595. ' height:16px;',
  3596. '}',
  3597. '.ke-script, .ke-noscript, .ke-display-none {',
  3598. ' display:none;',
  3599. ' font-size:0;',
  3600. ' width:0;',
  3601. ' height:0;',
  3602. '}',
  3603. '.ke-pagebreak {',
  3604. ' border:1px dotted #AAA;',
  3605. ' font-size:0;',
  3606. ' height:2px;',
  3607. '}',
  3608. '</style>'
  3609. ];
  3610. if (!_isArray(cssPath)) {
  3611. cssPath = [cssPath];
  3612. }
  3613. _each(cssPath, function(i, path) {
  3614. if (path) {
  3615. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3616. }
  3617. });
  3618. if (cssData) {
  3619. arr.push('<style>' + cssData + '</style>');
  3620. }
  3621. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3622. return arr.join('\n');
  3623. }
  3624. function _elementVal(knode, val) {
  3625. if (knode.hasVal()) {
  3626. if (val === undefined) {
  3627. var html = knode.val();
  3628. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3629. return html;
  3630. }
  3631. return knode.val(val);
  3632. }
  3633. return knode.html(val);
  3634. }
  3635. function KEdit(options) {
  3636. this.init(options);
  3637. }
  3638. _extend(KEdit, KWidget, {
  3639. init : function(options) {
  3640. var self = this;
  3641. KEdit.parent.init.call(self, options);
  3642. self.srcElement = K(options.srcElement);
  3643. self.div.addClass('ke-edit');
  3644. self.designMode = _undef(options.designMode, true);
  3645. self.beforeGetHtml = options.beforeGetHtml;
  3646. self.beforeSetHtml = options.beforeSetHtml;
  3647. self.afterSetHtml = options.afterSetHtml;
  3648. var themesPath = _undef(options.themesPath, ''),
  3649. bodyClass = options.bodyClass,
  3650. cssPath = options.cssPath,
  3651. cssData = options.cssData,
  3652. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3653. srcScript = ('document.open();' +
  3654. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3655. 'document.close();'),
  3656. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3657. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3658. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3659. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3660. self.iframe.attr('tabindex', self.tabIndex);
  3661. self.textarea.attr('tabindex', self.tabIndex);
  3662. if (self.width) {
  3663. self.setWidth(self.width);
  3664. }
  3665. if (self.height) {
  3666. self.setHeight(self.height);
  3667. }
  3668. if (self.designMode) {
  3669. self.textarea.hide();
  3670. } else {
  3671. self.iframe.hide();
  3672. }
  3673. function ready() {
  3674. var doc = _iframeDoc(self.iframe);
  3675. doc.open();
  3676. if (isDocumentDomain) {
  3677. doc.domain = document.domain;
  3678. }
  3679. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3680. doc.close();
  3681. self.win = self.iframe[0].contentWindow;
  3682. self.doc = doc;
  3683. var cmd = _cmd(doc);
  3684. self.afterChange(function(e) {
  3685. cmd.selection();
  3686. });
  3687. if (_WEBKIT) {
  3688. K(doc).click(function(e) {
  3689. if (K(e.target).name === 'img') {
  3690. cmd.selection(true);
  3691. cmd.range.selectNode(e.target);
  3692. cmd.select();
  3693. }
  3694. });
  3695. }
  3696. if (_IE) {
  3697. self._mousedownHandler = function() {
  3698. var newRange = cmd.range.cloneRange();
  3699. newRange.shrink();
  3700. if (newRange.isControl()) {
  3701. self.blur();
  3702. }
  3703. };
  3704. K(document).mousedown(self._mousedownHandler);
  3705. K(doc).keydown(function(e) {
  3706. if (e.which == 8) {
  3707. cmd.selection();
  3708. var rng = cmd.range;
  3709. if (rng.isControl()) {
  3710. rng.collapse(true);
  3711. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3712. e.preventDefault();
  3713. }
  3714. }
  3715. });
  3716. }
  3717. self.cmd = cmd;
  3718. self.html(_elementVal(self.srcElement));
  3719. if (_IE) {
  3720. doc.body.disabled = true;
  3721. doc.body.contentEditable = true;
  3722. doc.body.removeAttribute('disabled');
  3723. } else {
  3724. doc.designMode = 'on';
  3725. }
  3726. if (options.afterCreate) {
  3727. options.afterCreate.call(self);
  3728. }
  3729. }
  3730. if (isDocumentDomain) {
  3731. self.iframe.bind('load', function(e) {
  3732. self.iframe.unbind('load');
  3733. if (_IE) {
  3734. ready();
  3735. } else {
  3736. setTimeout(ready, 0);
  3737. }
  3738. });
  3739. }
  3740. self.div.append(self.iframe);
  3741. self.div.append(self.textarea);
  3742. self.srcElement.hide();
  3743. !isDocumentDomain && ready();
  3744. },
  3745. setWidth : function(val) {
  3746. var self = this;
  3747. val = _addUnit(val);
  3748. self.width = val;
  3749. self.div.css('width', val);
  3750. return self;
  3751. },
  3752. setHeight : function(val) {
  3753. var self = this;
  3754. val = _addUnit(val);
  3755. self.height = val;
  3756. self.div.css('height', val);
  3757. self.iframe.css('height', val);
  3758. if ((_IE && _V < 8) || _QUIRKS) {
  3759. val = _addUnit(_removeUnit(val) - 2);
  3760. }
  3761. self.textarea.css('height', val);
  3762. return self;
  3763. },
  3764. remove : function() {
  3765. var self = this, doc = self.doc;
  3766. K(doc.body).unbind();
  3767. K(doc).unbind();
  3768. K(self.win).unbind();
  3769. if (self._mousedownHandler) {
  3770. K(document).unbind('mousedown', self._mousedownHandler);
  3771. }
  3772. _elementVal(self.srcElement, self.html());
  3773. self.srcElement.show();
  3774. self.iframe.unbind();
  3775. self.textarea.unbind();
  3776. KEdit.parent.remove.call(self);
  3777. },
  3778. html : function(val, isFull) {
  3779. var self = this, doc = self.doc;
  3780. if (self.designMode) {
  3781. var body = doc.body;
  3782. if (val === undefined) {
  3783. if (isFull) {
  3784. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3785. } else {
  3786. val = body.innerHTML;
  3787. }
  3788. if (self.beforeGetHtml) {
  3789. val = self.beforeGetHtml(val);
  3790. }
  3791. if (_GECKO && val == '<br />') {
  3792. val = '';
  3793. }
  3794. return val;
  3795. }
  3796. if (self.beforeSetHtml) {
  3797. val = self.beforeSetHtml(val);
  3798. }
  3799. if (_IE && _V >= 9) {
  3800. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3801. }
  3802. K(body).html(val);
  3803. if (self.afterSetHtml) {
  3804. self.afterSetHtml();
  3805. }
  3806. return self;
  3807. }
  3808. if (val === undefined) {
  3809. return self.textarea.val();
  3810. }
  3811. self.textarea.val(val);
  3812. return self;
  3813. },
  3814. design : function(bool) {
  3815. var self = this, val;
  3816. if (bool === undefined ? !self.designMode : bool) {
  3817. if (!self.designMode) {
  3818. val = self.html();
  3819. self.designMode = true;
  3820. self.textarea.hide();
  3821. self.html(val);
  3822. var iframe = self.iframe;
  3823. var height = _removeUnit(self.height);
  3824. iframe.height(height - 2);
  3825. iframe.show();
  3826. setTimeout(function() {
  3827. iframe.height(height);
  3828. }, 0);
  3829. }
  3830. } else {
  3831. if (self.designMode) {
  3832. val = self.html();
  3833. self.designMode = false;
  3834. self.html(val);
  3835. self.iframe.hide();
  3836. self.textarea.show();
  3837. }
  3838. }
  3839. return self.focus();
  3840. },
  3841. focus : function() {
  3842. var self = this;
  3843. //self.designMode ? self.win.focus() : self.textarea[0].focus();
  3844. return self;
  3845. },
  3846. blur : function() {
  3847. var self = this;
  3848. if (_IE) {
  3849. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3850. self.div.append(input);
  3851. input[0].focus();
  3852. input.remove();
  3853. } else {
  3854. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3855. }
  3856. return self;
  3857. },
  3858. afterChange : function(fn) {
  3859. var self = this, doc = self.doc, body = doc.body;
  3860. K(doc).keyup(function(e) {
  3861. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3862. fn(e);
  3863. }
  3864. });
  3865. K(doc).mouseup(fn).contextmenu(fn);
  3866. K(self.win).blur(fn);
  3867. function timeoutHandler(e) {
  3868. setTimeout(function() {
  3869. fn(e);
  3870. }, 1);
  3871. }
  3872. K(body).bind('paste', timeoutHandler);
  3873. K(body).bind('cut', timeoutHandler);
  3874. return self;
  3875. }
  3876. });
  3877. function _edit(options) {
  3878. return new KEdit(options);
  3879. }
  3880. K.EditClass = KEdit;
  3881. K.edit = _edit;
  3882. K.iframeDoc = _iframeDoc;
  3883. function _selectToolbar(name, fn) {
  3884. var self = this,
  3885. knode = self.get(name);
  3886. if (knode) {
  3887. if (knode.hasClass('ke-disabled')) {
  3888. return;
  3889. }
  3890. fn(knode);
  3891. }
  3892. }
  3893. function KToolbar(options) {
  3894. this.init(options);
  3895. }
  3896. _extend(KToolbar, KWidget, {
  3897. init : function(options) {
  3898. var self = this;
  3899. KToolbar.parent.init.call(self, options);
  3900. self.disableMode = _undef(options.disableMode, false);
  3901. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3902. self._itemMap = {};
  3903. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3904. e.preventDefault();
  3905. }).attr('unselectable', 'on');
  3906. function find(target) {
  3907. var knode = K(target);
  3908. if (knode.hasClass('ke-outline')) {
  3909. return knode;
  3910. }
  3911. if (knode.hasClass('ke-toolbar-icon')) {
  3912. return knode.parent();
  3913. }
  3914. }
  3915. function hover(e, method) {
  3916. var knode = find(e.target);
  3917. if (knode) {
  3918. if (knode.hasClass('ke-disabled')) {
  3919. return;
  3920. }
  3921. if (knode.hasClass('ke-selected')) {
  3922. return;
  3923. }
  3924. knode[method]('ke-on');
  3925. }
  3926. }
  3927. self.div.mouseover(function(e) {
  3928. hover(e, 'addClass');
  3929. })
  3930. .mouseout(function(e) {
  3931. hover(e, 'removeClass');
  3932. })
  3933. .click(function(e) {
  3934. var knode = find(e.target);
  3935. if (knode) {
  3936. if (knode.hasClass('ke-disabled')) {
  3937. return;
  3938. }
  3939. self.options.click.call(this, e, knode.attr('data-name'));
  3940. }
  3941. });
  3942. },
  3943. get : function(name) {
  3944. if (this._itemMap[name]) {
  3945. return this._itemMap[name];
  3946. }
  3947. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3948. },
  3949. select : function(name) {
  3950. _selectToolbar.call(this, name, function(knode) {
  3951. knode.addClass('ke-selected');
  3952. });
  3953. return self;
  3954. },
  3955. unselect : function(name) {
  3956. _selectToolbar.call(this, name, function(knode) {
  3957. knode.removeClass('ke-selected').removeClass('ke-on');
  3958. });
  3959. return self;
  3960. },
  3961. enable : function(name) {
  3962. var self = this,
  3963. knode = name.get ? name : self.get(name);
  3964. if (knode) {
  3965. knode.removeClass('ke-disabled');
  3966. knode.opacity(1);
  3967. }
  3968. return self;
  3969. },
  3970. disable : function(name) {
  3971. var self = this,
  3972. knode = name.get ? name : self.get(name);
  3973. if (knode) {
  3974. knode.removeClass('ke-selected').addClass('ke-disabled');
  3975. knode.opacity(0.5);
  3976. }
  3977. return self;
  3978. },
  3979. disableAll : function(bool, noDisableItems) {
  3980. var self = this, map = self.noDisableItemMap, item;
  3981. if (noDisableItems) {
  3982. map = _toMap(noDisableItems);
  3983. }
  3984. if (bool === undefined ? !self.disableMode : bool) {
  3985. K('span.ke-outline', self.div).each(function() {
  3986. var knode = K(this),
  3987. name = knode[0].getAttribute('data-name', 2);
  3988. if (!map[name]) {
  3989. self.disable(knode);
  3990. }
  3991. });
  3992. self.disableMode = true;
  3993. } else {
  3994. K('span.ke-outline', self.div).each(function() {
  3995. var knode = K(this),
  3996. name = knode[0].getAttribute('data-name', 2);
  3997. if (!map[name]) {
  3998. self.enable(knode);
  3999. }
  4000. });
  4001. self.disableMode = false;
  4002. }
  4003. return self;
  4004. }
  4005. });
  4006. function _toolbar(options) {
  4007. return new KToolbar(options);
  4008. }
  4009. K.ToolbarClass = KToolbar;
  4010. K.toolbar = _toolbar;
  4011. function KMenu(options) {
  4012. this.init(options);
  4013. }
  4014. _extend(KMenu, KWidget, {
  4015. init : function(options) {
  4016. var self = this;
  4017. options.z = options.z || 811213;
  4018. KMenu.parent.init.call(self, options);
  4019. self.centerLineMode = _undef(options.centerLineMode, true);
  4020. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4021. e.stopPropagation();
  4022. }).attr('unselectable', 'on');
  4023. },
  4024. addItem : function(item) {
  4025. var self = this;
  4026. if (item.title === '-') {
  4027. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4028. return;
  4029. }
  4030. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4031. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4032. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4033. height = _addUnit(item.height),
  4034. iconClass = _undef(item.iconClass, '');
  4035. self.div.append(itemDiv);
  4036. if (height) {
  4037. itemDiv.css('height', height);
  4038. rightDiv.css('line-height', height);
  4039. }
  4040. var centerDiv;
  4041. if (self.centerLineMode) {
  4042. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4043. if (height) {
  4044. centerDiv.css('height', height);
  4045. }
  4046. }
  4047. itemDiv.mouseover(function(e) {
  4048. K(this).addClass('ke-menu-item-on');
  4049. if (centerDiv) {
  4050. centerDiv.addClass('ke-menu-item-center-on');
  4051. }
  4052. })
  4053. .mouseout(function(e) {
  4054. K(this).removeClass('ke-menu-item-on');
  4055. if (centerDiv) {
  4056. centerDiv.removeClass('ke-menu-item-center-on');
  4057. }
  4058. })
  4059. .click(function(e) {
  4060. item.click.call(K(this));
  4061. e.stopPropagation();
  4062. })
  4063. .append(leftDiv);
  4064. if (centerDiv) {
  4065. itemDiv.append(centerDiv);
  4066. }
  4067. itemDiv.append(rightDiv);
  4068. if (item.checked) {
  4069. iconClass = 'ke-icon-checked';
  4070. }
  4071. if (iconClass !== '') {
  4072. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4073. }
  4074. rightDiv.html(item.title);
  4075. return self;
  4076. },
  4077. remove : function() {
  4078. var self = this;
  4079. if (self.options.beforeRemove) {
  4080. self.options.beforeRemove.call(self);
  4081. }
  4082. K('.ke-menu-item', self.div[0]).unbind();
  4083. KMenu.parent.remove.call(self);
  4084. return self;
  4085. }
  4086. });
  4087. function _menu(options) {
  4088. return new KMenu(options);
  4089. }
  4090. K.MenuClass = KMenu;
  4091. K.menu = _menu;
  4092. function KColorPicker(options) {
  4093. this.init(options);
  4094. }
  4095. _extend(KColorPicker, KWidget, {
  4096. init : function(options) {
  4097. var self = this;
  4098. options.z = options.z || 811213;
  4099. KColorPicker.parent.init.call(self, options);
  4100. var colors = options.colors || [
  4101. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4102. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4103. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4104. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4105. ];
  4106. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4107. self._cells = [];
  4108. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4109. e.stopPropagation();
  4110. }).attr('unselectable', 'on');
  4111. var table = self.doc.createElement('table');
  4112. self.div.append(table);
  4113. table.className = 'ke-colorpicker-table';
  4114. table.cellPadding = 0;
  4115. table.cellSpacing = 0;
  4116. table.border = 0;
  4117. var row = table.insertRow(0), cell = row.insertCell(0);
  4118. cell.colSpan = colors[0].length;
  4119. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4120. for (var i = 0; i < colors.length; i++) {
  4121. row = table.insertRow(i + 1);
  4122. for (var j = 0; j < colors[i].length; j++) {
  4123. cell = row.insertCell(j);
  4124. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4125. }
  4126. }
  4127. },
  4128. _addAttr : function(cell, color, cls) {
  4129. var self = this;
  4130. cell = K(cell).addClass(cls);
  4131. if (self.selectedColor === color.toLowerCase()) {
  4132. cell.addClass('ke-colorpicker-cell-selected');
  4133. }
  4134. cell.attr('title', color || self.options.noColor);
  4135. cell.mouseover(function(e) {
  4136. K(this).addClass('ke-colorpicker-cell-on');
  4137. });
  4138. cell.mouseout(function(e) {
  4139. K(this).removeClass('ke-colorpicker-cell-on');
  4140. });
  4141. cell.click(function(e) {
  4142. e.stop();
  4143. self.options.click.call(K(this), color);
  4144. });
  4145. if (color) {
  4146. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4147. } else {
  4148. cell.html(self.options.noColor);
  4149. }
  4150. K(cell).attr('unselectable', 'on');
  4151. self._cells.push(cell);
  4152. },
  4153. remove : function() {
  4154. var self = this;
  4155. _each(self._cells, function() {
  4156. this.unbind();
  4157. });
  4158. KColorPicker.parent.remove.call(self);
  4159. return self;
  4160. }
  4161. });
  4162. function _colorpicker(options) {
  4163. return new KColorPicker(options);
  4164. }
  4165. K.ColorPickerClass = KColorPicker;
  4166. K.colorpicker = _colorpicker;
  4167. function KUploadButton(options) {
  4168. this.init(options);
  4169. }
  4170. _extend(KUploadButton, {
  4171. init : function(options) {
  4172. var self = this,
  4173. button = K(options.button),
  4174. fieldName = options.fieldName || 'file',
  4175. url = options.url || '',
  4176. title = button.val(),
  4177. extraParams = options.extraParams || {},
  4178. cls = button[0].className || '',
  4179. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4180. options.afterError = options.afterError || function(str) {
  4181. alert(str);
  4182. };
  4183. var hiddenElements = [];
  4184. for(var k in extraParams){
  4185. hiddenElements.push('<input type="hidden" class="ke-upload-file-'+k+'" name="' + k + '" value="' + extraParams[k] + '" />');
  4186. }
  4187. var html = [
  4188. '<div class="ke-inline-block ' + cls + '">',
  4189. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4190. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4191. '<span class="ke-button-common">',
  4192. hiddenElements.join(''),
  4193. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4194. '</span>',
  4195. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4196. (options.form ? '</div>' : '</form>'),
  4197. '</div>'].join('');
  4198. var div = K(html, button.doc);
  4199. button.hide();
  4200. button.before(div);
  4201. self.div = div;
  4202. self.button = button;
  4203. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4204. self.form = options.form ? K(options.form) : K('form', div);
  4205. self.fileBox = K('.ke-upload-file', div);
  4206. var width = options.width || K('.ke-button-common', div).width();
  4207. K('.ke-upload-area', div).width(width);
  4208. self.options = options;
  4209. },
  4210. submit : function(e) {
  4211. var self = this,
  4212. iframe = self.iframe;
  4213. e = false;
  4214. if (e) {
  4215. var file = e.files[0];
  4216. var filename = file.name;
  4217. var temp = filename.split('.');
  4218. //putExtra.params["x:name"] = temp[0];
  4219. var filename = hex_md5(file.name) + '.' + temp[temp.length-1];
  4220. var path = $('.' + 'ke-upload-file-key').val();
  4221. $('.' + 'ke-upload-file-key').val(path + filename);
  4222. //这里要修改 以后再改
  4223. } else {
  4224. iframe.bind('load', function() {
  4225. iframe.unbind();
  4226. var tempForm = document.createElement('form');
  4227. self.fileBox.before(tempForm);
  4228. K(tempForm).append(self.fileBox);
  4229. tempForm.reset();
  4230. K(tempForm).remove(true);
  4231. var doc = K.iframeDoc(iframe),
  4232. pre = doc.getElementsByTagName('pre')[0],
  4233. str = '', data;
  4234. if (pre) {
  4235. str = pre.innerHTML;
  4236. } else {
  4237. str = doc.body.innerHTML;
  4238. }
  4239. str = _unescape(str);
  4240. iframe[0].src = 'javascript:false';
  4241. try {
  4242. data = K.json(str);
  4243. } catch (e) {
  4244. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4245. }
  4246. if (data) {
  4247. self.options.afterUpload.call(self, data);
  4248. }
  4249. });
  4250. self.form[0].submit();
  4251. }
  4252. self.form[0].submit();
  4253. return self;
  4254. },
  4255. remove : function() {
  4256. var self = this;
  4257. if (self.fileBox) {
  4258. self.fileBox.unbind();
  4259. }
  4260. self.iframe.remove();
  4261. self.div.remove();
  4262. self.button.show();
  4263. return self;
  4264. }
  4265. });
  4266. function _uploadbutton(options) {
  4267. return new KUploadButton(options);
  4268. }
  4269. K.UploadButtonClass = KUploadButton;
  4270. K.uploadbutton = _uploadbutton;
  4271. function _createButton(arg) {
  4272. arg = arg || {};
  4273. var name = arg.name || '',
  4274. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4275. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4276. if (arg.click) {
  4277. btn.click(arg.click);
  4278. }
  4279. span.append(btn);
  4280. return span;
  4281. }
  4282. function KDialog(options) {
  4283. this.init(options);
  4284. }
  4285. _extend(KDialog, KWidget, {
  4286. init : function(options) {
  4287. var self = this;
  4288. var shadowMode = _undef(options.shadowMode, true);
  4289. options.z = options.z || 811213;
  4290. options.shadowMode = false;
  4291. options.autoScroll = _undef(options.autoScroll, true);
  4292. KDialog.parent.init.call(self, options);
  4293. var title = options.title,
  4294. body = K(options.body, self.doc),
  4295. previewBtn = options.previewBtn,
  4296. yesBtn = options.yesBtn,
  4297. noBtn = options.noBtn,
  4298. closeBtn = options.closeBtn,
  4299. showMask = _undef(options.showMask, true);
  4300. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4301. e.stopPropagation();
  4302. });
  4303. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4304. if (_IE && _V < 7) {
  4305. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4306. } else if (shadowMode) {
  4307. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4308. }
  4309. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4310. contentDiv.append(headerDiv);
  4311. headerDiv.html(title);
  4312. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4313. headerDiv.append(self.closeIcon);
  4314. self.draggable({
  4315. clickEl : headerDiv,
  4316. beforeDrag : options.beforeDrag
  4317. });
  4318. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4319. contentDiv.append(bodyDiv);
  4320. bodyDiv.append(body);
  4321. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4322. if (previewBtn || yesBtn || noBtn) {
  4323. contentDiv.append(footerDiv);
  4324. }
  4325. _each([
  4326. { btn : previewBtn, name : 'preview' },
  4327. { btn : yesBtn, name : 'yes' },
  4328. { btn : noBtn, name : 'no' }
  4329. ], function() {
  4330. if (this.btn) {
  4331. var button = _createButton(this.btn);
  4332. button.addClass('ke-dialog-' + this.name);
  4333. footerDiv.append(button);
  4334. }
  4335. });
  4336. if (self.height) {
  4337. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4338. }
  4339. self.div.width(self.div.width());
  4340. self.div.height(self.div.height());
  4341. self.mask = null;
  4342. if (showMask) {
  4343. var docEl = _docElement(self.doc),
  4344. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4345. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4346. self.mask = _widget({
  4347. x : 0,
  4348. y : 0,
  4349. z : self.z - 1,
  4350. cls : 'ke-dialog-mask',
  4351. width : docWidth,
  4352. height : docHeight
  4353. });
  4354. }
  4355. self.autoPos(self.div.width(), self.div.height());
  4356. self.footerDiv = footerDiv;
  4357. self.bodyDiv = bodyDiv;
  4358. self.headerDiv = headerDiv;
  4359. self.isLoading = false;
  4360. },
  4361. setMaskIndex : function(z) {
  4362. var self = this;
  4363. self.mask.div.css('z-index', z);
  4364. },
  4365. showLoading : function(msg) {
  4366. msg = _undef(msg, '');
  4367. var self = this, body = self.bodyDiv;
  4368. 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>')
  4369. .width(body.width()).height(body.height())
  4370. .css('top', self.headerDiv.height() + 'px');
  4371. body.css('visibility', 'hidden').after(self.loading);
  4372. self.isLoading = true;
  4373. return self;
  4374. },
  4375. hideLoading : function() {
  4376. this.loading && this.loading.remove();
  4377. this.bodyDiv.css('visibility', 'visible');
  4378. this.isLoading = false;
  4379. return this;
  4380. },
  4381. remove : function() {
  4382. var self = this;
  4383. if (self.options.beforeRemove) {
  4384. self.options.beforeRemove.call(self);
  4385. }
  4386. self.mask && self.mask.remove();
  4387. self.iframeMask && self.iframeMask.remove();
  4388. self.closeIcon.unbind();
  4389. K('input', self.div).unbind();
  4390. K('button', self.div).unbind();
  4391. self.footerDiv.unbind();
  4392. self.bodyDiv.unbind();
  4393. self.headerDiv.unbind();
  4394. K('iframe', self.div).each(function() {
  4395. K(this).remove();
  4396. });
  4397. KDialog.parent.remove.call(self);
  4398. return self;
  4399. }
  4400. });
  4401. function _dialog(options) {
  4402. return new KDialog(options);
  4403. }
  4404. K.DialogClass = KDialog;
  4405. K.dialog = _dialog;
  4406. function _tabs(options) {
  4407. var self = _widget(options),
  4408. remove = self.remove,
  4409. afterSelect = options.afterSelect,
  4410. div = self.div,
  4411. liList = [];
  4412. div.addClass('ke-tabs')
  4413. .bind('contextmenu,mousedown,mousemove', function(e) {
  4414. e.preventDefault();
  4415. });
  4416. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4417. div.append(ul);
  4418. self.add = function(tab) {
  4419. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4420. li.data('tab', tab);
  4421. liList.push(li);
  4422. ul.append(li);
  4423. };
  4424. self.selectedIndex = 0;
  4425. self.select = function(index) {
  4426. self.selectedIndex = index;
  4427. _each(liList, function(i, li) {
  4428. li.unbind();
  4429. if (i === index) {
  4430. li.addClass('ke-tabs-li-selected');
  4431. K(li.data('tab').panel).show('');
  4432. } else {
  4433. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4434. .mouseover(function() {
  4435. K(this).addClass('ke-tabs-li-on');
  4436. })
  4437. .mouseout(function() {
  4438. K(this).removeClass('ke-tabs-li-on');
  4439. })
  4440. .click(function() {
  4441. self.select(i);
  4442. });
  4443. K(li.data('tab').panel).hide();
  4444. }
  4445. });
  4446. if (afterSelect) {
  4447. afterSelect.call(self, index);
  4448. }
  4449. };
  4450. self.remove = function() {
  4451. _each(liList, function() {
  4452. this.remove();
  4453. });
  4454. ul.remove();
  4455. remove.call(self);
  4456. };
  4457. return self;
  4458. }
  4459. K.tabs = _tabs;
  4460. function _loadScript(url, fn) {
  4461. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4462. script = document.createElement('script');
  4463. head.appendChild(script);
  4464. script.src = url;
  4465. script.charset = 'utf-8';
  4466. script.onload = script.onreadystatechange = function() {
  4467. if (!this.readyState || this.readyState === 'loaded') {
  4468. if (fn) {
  4469. fn();
  4470. }
  4471. script.onload = script.onreadystatechange = null;
  4472. head.removeChild(script);
  4473. }
  4474. };
  4475. }
  4476. function _chopQuery(url) {
  4477. var index = url.indexOf('?');
  4478. return index > 0 ? url.substr(0, index) : url;
  4479. }
  4480. function _loadStyle(url) {
  4481. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4482. link = document.createElement('link'),
  4483. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4484. var links = K('link[rel="stylesheet"]', head);
  4485. for (var i = 0, len = links.length; i < len; i++) {
  4486. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4487. return;
  4488. }
  4489. }
  4490. head.appendChild(link);
  4491. link.href = url;
  4492. link.rel = 'stylesheet';
  4493. }
  4494. function _ajax(url, fn, method, param, dataType) {
  4495. method = method || 'GET';
  4496. dataType = dataType || 'json';
  4497. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4498. xhr.open(method, url, true);
  4499. xhr.onreadystatechange = function () {
  4500. if (xhr.readyState == 4 && xhr.status == 200) {
  4501. if (fn) {
  4502. var data = _trim(xhr.responseText);
  4503. if (dataType == 'json') {
  4504. data = _json(data);
  4505. }
  4506. fn(data);
  4507. }
  4508. }
  4509. };
  4510. if (method == 'POST') {
  4511. var params = [];
  4512. _each(param, function(key, val) {
  4513. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4514. });
  4515. try {
  4516. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4517. } catch (e) {}
  4518. xhr.send(params.join('&'));
  4519. } else {
  4520. xhr.send(null);
  4521. }
  4522. }
  4523. K.loadScript = _loadScript;
  4524. K.loadStyle = _loadStyle;
  4525. K.ajax = _ajax;
  4526. var _plugins = {};
  4527. function _plugin(name, fn) {
  4528. if (name === undefined) {
  4529. return _plugins;
  4530. }
  4531. if (!fn) {
  4532. return _plugins[name];
  4533. }
  4534. _plugins[name] = fn;
  4535. }
  4536. var _language = {};
  4537. function _parseLangKey(key) {
  4538. var match, ns = 'core';
  4539. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4540. ns = match[1];
  4541. key = match[2];
  4542. }
  4543. return { ns : ns, key : key };
  4544. }
  4545. function _lang(mixed, langType) {
  4546. langType = langType === undefined ? K.options.langType : langType;
  4547. if (typeof mixed === 'string') {
  4548. if (!_language[langType]) {
  4549. return 'no language';
  4550. }
  4551. var pos = mixed.length - 1;
  4552. if (mixed.substr(pos) === '.') {
  4553. return _language[langType][mixed.substr(0, pos)];
  4554. }
  4555. var obj = _parseLangKey(mixed);
  4556. return _language[langType][obj.ns][obj.key];
  4557. }
  4558. _each(mixed, function(key, val) {
  4559. var obj = _parseLangKey(key);
  4560. if (!_language[langType]) {
  4561. _language[langType] = {};
  4562. }
  4563. if (!_language[langType][obj.ns]) {
  4564. _language[langType][obj.ns] = {};
  4565. }
  4566. _language[langType][obj.ns][obj.key] = val;
  4567. });
  4568. }
  4569. function _getImageFromRange(range, fn) {
  4570. if (range.collapsed) {
  4571. return;
  4572. }
  4573. range = range.cloneRange().up();
  4574. var sc = range.startContainer, so = range.startOffset;
  4575. if (!_WEBKIT && !range.isControl()) {
  4576. return;
  4577. }
  4578. var img = K(sc.childNodes[so]);
  4579. if (!img || img.name != 'img') {
  4580. return;
  4581. }
  4582. if (fn(img)) {
  4583. return img;
  4584. }
  4585. }
  4586. function _bindContextmenuEvent() {
  4587. var self = this, doc = self.edit.doc;
  4588. K(doc).contextmenu(function(e) {
  4589. if (self.menu) {
  4590. self.hideMenu();
  4591. }
  4592. if (!self.useContextmenu) {
  4593. e.preventDefault();
  4594. return;
  4595. }
  4596. if (self._contextmenus.length === 0) {
  4597. return;
  4598. }
  4599. var maxWidth = 0, items = [];
  4600. _each(self._contextmenus, function() {
  4601. if (this.title == '-') {
  4602. items.push(this);
  4603. return;
  4604. }
  4605. if (this.cond && this.cond()) {
  4606. items.push(this);
  4607. if (this.width && this.width > maxWidth) {
  4608. maxWidth = this.width;
  4609. }
  4610. }
  4611. });
  4612. while (items.length > 0 && items[0].title == '-') {
  4613. items.shift();
  4614. }
  4615. while (items.length > 0 && items[items.length - 1].title == '-') {
  4616. items.pop();
  4617. }
  4618. var prevItem = null;
  4619. _each(items, function(i) {
  4620. if (this.title == '-' && prevItem.title == '-') {
  4621. delete items[i];
  4622. }
  4623. prevItem = this;
  4624. });
  4625. if (items.length > 0) {
  4626. e.preventDefault();
  4627. var pos = K(self.edit.iframe).pos(),
  4628. menu = _menu({
  4629. x : pos.x + e.clientX,
  4630. y : pos.y + e.clientY,
  4631. width : maxWidth,
  4632. css : { visibility: 'hidden' },
  4633. shadowMode : self.shadowMode
  4634. });
  4635. _each(items, function() {
  4636. if (this.title) {
  4637. menu.addItem(this);
  4638. }
  4639. });
  4640. var docEl = _docElement(menu.doc),
  4641. menuHeight = menu.div.height();
  4642. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4643. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4644. }
  4645. menu.div.css('visibility', 'visible');
  4646. self.menu = menu;
  4647. }
  4648. });
  4649. }
  4650. function _bindNewlineEvent() {
  4651. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4652. if (_IE && newlineTag !== 'br') {
  4653. return;
  4654. }
  4655. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4656. return;
  4657. }
  4658. if (_OPERA && _V < 9) {
  4659. return;
  4660. }
  4661. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4662. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4663. function getAncestorTagName(range) {
  4664. var ancestor = K(range.commonAncestor());
  4665. while (ancestor) {
  4666. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4667. break;
  4668. }
  4669. ancestor = ancestor.parent();
  4670. }
  4671. return ancestor.name;
  4672. }
  4673. K(doc).keydown(function(e) {
  4674. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4675. autoImg(self);
  4676. return;
  4677. }
  4678. self.cmd.selection();
  4679. var tagName = getAncestorTagName(self.cmd.range);
  4680. if (tagName == 'marquee' || tagName == 'select') {
  4681. return;
  4682. }
  4683. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4684. e.preventDefault();
  4685. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4686. return;
  4687. }
  4688. if (!pSkipTagMap[tagName]) {
  4689. _nativeCommand(doc, 'formatblock', '<p>');
  4690. }
  4691. });
  4692. K(doc).keyup(function(e) {
  4693. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4694. return;
  4695. }
  4696. if (newlineTag == 'br') {
  4697. return;
  4698. }
  4699. if (_GECKO) {
  4700. var root = self.cmd.commonAncestor('p');
  4701. var a = self.cmd.commonAncestor('a');
  4702. if (a && a.text() == '') {
  4703. a.remove(true);
  4704. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4705. self.cmd.select();
  4706. }
  4707. return;
  4708. }
  4709. self.cmd.selection();
  4710. var tagName = getAncestorTagName(self.cmd.range);
  4711. if (tagName == 'marquee' || tagName == 'select') {
  4712. return;
  4713. }
  4714. if (!pSkipTagMap[tagName]) {
  4715. _nativeCommand(doc, 'formatblock', '<p>');
  4716. }
  4717. var div = self.cmd.commonAncestor('div');
  4718. if (div) {
  4719. var p = K('<p></p>'),
  4720. child = div[0].firstChild;
  4721. while (child) {
  4722. var next = child.nextSibling;
  4723. p.append(child);
  4724. child = next;
  4725. }
  4726. div.before(p);
  4727. div.remove();
  4728. self.cmd.range.selectNodeContents(p[0]);
  4729. self.cmd.select();
  4730. }
  4731. });
  4732. }
  4733. function _bindTabEvent() {
  4734. var self = this, doc = self.edit.doc;
  4735. K(doc).keydown(function(e) {
  4736. if (e.which == 9) {
  4737. e.preventDefault();
  4738. if (self.afterTab) {
  4739. self.afterTab.call(self, e);
  4740. return;
  4741. }
  4742. var cmd = self.cmd, range = cmd.range;
  4743. range.shrink();
  4744. if (range.collapsed && range.startContainer.nodeType == 1) {
  4745. range.insertNode(K('@&nbsp;', doc)[0]);
  4746. cmd.select();
  4747. }
  4748. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4749. }
  4750. });
  4751. }
  4752. function _bindFocusEvent() {
  4753. var self = this;
  4754. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4755. if (self.afterFocus) {
  4756. self.afterFocus.call(self, e);
  4757. }
  4758. }).blur(function(e) {
  4759. if (self.afterBlur) {
  4760. self.afterBlur.call(self, e);
  4761. }
  4762. });
  4763. }
  4764. function _removeBookmarkTag(html) {
  4765. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4766. }
  4767. function _removeTempTag(html) {
  4768. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4769. }
  4770. function _addBookmarkToStack(stack, bookmark) {
  4771. if (stack.length === 0) {
  4772. stack.push(bookmark);
  4773. return;
  4774. }
  4775. var prev = stack[stack.length - 1];
  4776. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4777. stack.push(bookmark);
  4778. }
  4779. }
  4780. function _undoToRedo(fromStack, toStack) {
  4781. var self = this, edit = self.edit,
  4782. body = edit.doc.body,
  4783. range, bookmark;
  4784. if (fromStack.length === 0) {
  4785. return self;
  4786. }
  4787. if (edit.designMode) {
  4788. range = self.cmd.range;
  4789. bookmark = range.createBookmark(true);
  4790. bookmark.html = body.innerHTML;
  4791. } else {
  4792. bookmark = {
  4793. html : body.innerHTML
  4794. };
  4795. }
  4796. _addBookmarkToStack(toStack, bookmark);
  4797. var prev = fromStack.pop();
  4798. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4799. prev = fromStack.pop();
  4800. }
  4801. if (edit.designMode) {
  4802. edit.html(prev.html);
  4803. if (prev.start) {
  4804. range.moveToBookmark(prev);
  4805. self.select();
  4806. }
  4807. } else {
  4808. K(body).html(_removeBookmarkTag(prev.html));
  4809. }
  4810. return self;
  4811. }
  4812. function KEditor(options) {
  4813. var self = this;
  4814. self.options = {};
  4815. function setOption(key, val) {
  4816. if (KEditor.prototype[key] === undefined) {
  4817. self[key] = val;
  4818. }
  4819. self.options[key] = val;
  4820. }
  4821. _each(options, function(key, val) {
  4822. setOption(key, options[key]);
  4823. });
  4824. _each(K.options, function(key, val) {
  4825. if (self[key] === undefined) {
  4826. setOption(key, val);
  4827. }
  4828. });
  4829. var se = K(self.srcElement || '<textarea/>');
  4830. if (!self.width) {
  4831. self.width = se[0].style.width || se.width();
  4832. if (!self.width) {
  4833. self.width = '700';
  4834. }
  4835. }
  4836. if (!self.height) {
  4837. self.height = se[0].style.height || se.height();
  4838. }
  4839. setOption('width', _undef(self.width, self.minWidth));
  4840. setOption('height', _undef(self.height, self.minHeight));
  4841. setOption('width', _addUnit(self.width));
  4842. setOption('height', _addUnit(self.height));
  4843. if (_MOBILE && (!_IOS || _V < 534)) {
  4844. //self.designMode = false;
  4845. }
  4846. self.srcElement = se;
  4847. self.initContent = '';
  4848. self.plugin = {};
  4849. self.isCreated = false;
  4850. self._handlers = {};
  4851. self._contextmenus = [];
  4852. self._undoStack = [];
  4853. self._redoStack = [];
  4854. self._firstAddBookmark = true;
  4855. self.menu = self.contextmenu = null;
  4856. self.dialogs = [];
  4857. }
  4858. KEditor.prototype = {
  4859. lang : function(mixed) {
  4860. return _lang(mixed, this.langType);
  4861. },
  4862. loadPlugin : function(name, fn) {
  4863. var self = this;
  4864. var _pluginStatus = this._pluginStatus;
  4865. if (!_pluginStatus) {
  4866. _pluginStatus = this._pluginStatus = {};
  4867. }
  4868. if (_plugins[name]) {
  4869. if (!_isFunction(_plugins[name])) {
  4870. setTimeout(function() {
  4871. self.loadPlugin(name, fn);
  4872. }, 100);
  4873. return self;
  4874. }
  4875. if(!_pluginStatus[name]) {
  4876. _plugins[name].call(self, KindEditor);
  4877. _pluginStatus[name] = 'inited';
  4878. }
  4879. if (fn) {
  4880. fn.call(self);
  4881. }
  4882. return self;
  4883. }
  4884. _plugins[name] = 'loading';
  4885. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4886. setTimeout(function() {
  4887. if (_plugins[name]) {
  4888. self.loadPlugin(name, fn);
  4889. }
  4890. }, 0);
  4891. });
  4892. return self;
  4893. },
  4894. handler : function(key, fn) {
  4895. var self = this;
  4896. if (!self._handlers[key]) {
  4897. self._handlers[key] = [];
  4898. }
  4899. if (_isFunction(fn)) {
  4900. self._handlers[key].push(fn);
  4901. return self;
  4902. }
  4903. _each(self._handlers[key], function() {
  4904. fn = this.call(self, fn);
  4905. });
  4906. return fn;
  4907. },
  4908. clickToolbar : function(name, fn) {
  4909. var self = this, key = 'clickToolbar' + name;
  4910. if (fn === undefined) {
  4911. if (self._handlers[key]) {
  4912. return self.handler(key);
  4913. }
  4914. self.loadPlugin(name, function() {
  4915. self.handler(key);
  4916. });
  4917. return self;
  4918. }
  4919. return self.handler(key, fn);
  4920. },
  4921. updateState : function() {
  4922. var self = this;
  4923. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4924. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4925. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4926. });
  4927. return self;
  4928. },
  4929. addContextmenu : function(item) {
  4930. this._contextmenus.push(item);
  4931. return this;
  4932. },
  4933. afterCreate : function(fn) {
  4934. return this.handler('afterCreate', fn);
  4935. },
  4936. beforeRemove : function(fn) {
  4937. return this.handler('beforeRemove', fn);
  4938. },
  4939. beforeGetHtml : function(fn) {
  4940. return this.handler('beforeGetHtml', fn);
  4941. },
  4942. beforeSetHtml : function(fn) {
  4943. return this.handler('beforeSetHtml', fn);
  4944. },
  4945. afterSetHtml : function(fn) {
  4946. return this.handler('afterSetHtml', fn);
  4947. },
  4948. create : function() {
  4949. var self = this, fullscreenMode = self.fullscreenMode;
  4950. if (self.isCreated) {
  4951. return self;
  4952. }
  4953. if (self.srcElement.data('kindeditor')) {
  4954. return self;
  4955. }
  4956. self.srcElement.data('kindeditor', 'true');
  4957. if (fullscreenMode) {
  4958. _docElement().style.overflow = 'hidden';
  4959. } else {
  4960. _docElement().style.overflow = '';
  4961. }
  4962. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4963. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4964. if ((_IE && _V < 8) || _QUIRKS) {
  4965. height = _addUnit(_removeUnit(height) + 2);
  4966. }
  4967. var container = self.container = K(self.layout);
  4968. if (fullscreenMode) {
  4969. K(document.body).append(container);
  4970. } else {
  4971. self.srcElement.before(container);
  4972. }
  4973. var toolbarDiv = K('.toolbar', container),
  4974. editDiv = K('.edit', container),
  4975. statusbar = self.statusbar = K('.statusbar', container);
  4976. container.removeClass('container')
  4977. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4978. if (fullscreenMode) {
  4979. container.css({
  4980. position : 'absolute',
  4981. left : 0,
  4982. top : 0,
  4983. 'z-index' : 811211
  4984. });
  4985. if (!_GECKO) {
  4986. self._scrollPos = _getScrollPos();
  4987. }
  4988. window.scrollTo(0, 0);
  4989. K(document.body).css({
  4990. 'height' : '1px',
  4991. 'overflow' : 'hidden'
  4992. });
  4993. K(document.body.parentNode).css('overflow', 'hidden');
  4994. self._fullscreenExecuted = true;
  4995. } else {
  4996. if (self._fullscreenExecuted) {
  4997. K(document.body).css({
  4998. 'height' : '',
  4999. 'overflow' : ''
  5000. });
  5001. K(document.body.parentNode).css('overflow', '');
  5002. }
  5003. if (self._scrollPos) {
  5004. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  5005. }
  5006. }
  5007. var htmlList = [];
  5008. K.each(self.items, function(i, name) {
  5009. if (name == '|') {
  5010. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  5011. } else if (name == '/') {
  5012. htmlList.push('<div class="ke-hr"></div>');
  5013. } else {
  5014. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  5015. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  5016. }
  5017. });
  5018. var toolbar = self.toolbar = _toolbar({
  5019. src : toolbarDiv,
  5020. html : htmlList.join(''),
  5021. noDisableItems : self.noDisableItems,
  5022. click : function(e, name) {
  5023. e.stop();
  5024. if (self.menu) {
  5025. var menuName = self.menu.name;
  5026. self.hideMenu();
  5027. if (menuName === name) {
  5028. return;
  5029. }
  5030. }
  5031. self.clickToolbar(name);
  5032. }
  5033. });
  5034. var editHeight = _removeUnit(height) - toolbar.div.height();
  5035. var edit = self.edit = _edit({
  5036. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5037. src : editDiv,
  5038. srcElement : self.srcElement,
  5039. designMode : self.designMode,
  5040. themesPath : self.themesPath,
  5041. bodyClass : self.bodyClass,
  5042. cssPath : self.cssPath,
  5043. cssData : self.cssData,
  5044. beforeGetHtml : function(html) {
  5045. html = self.beforeGetHtml(html);
  5046. html = _removeBookmarkTag(_removeTempTag(html));
  5047. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5048. },
  5049. beforeSetHtml : function(html) {
  5050. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5051. return self.beforeSetHtml(html);
  5052. },
  5053. afterSetHtml : function() {
  5054. self.edit = edit = this;
  5055. self.afterSetHtml();
  5056. },
  5057. afterCreate : function() {
  5058. self.edit = edit = this;
  5059. self.cmd = edit.cmd;
  5060. self._docMousedownFn = function(e) {
  5061. if (self.menu) {
  5062. self.hideMenu();
  5063. }
  5064. };
  5065. K(edit.doc, document).mousedown(self._docMousedownFn);
  5066. _bindContextmenuEvent.call(self);
  5067. _bindNewlineEvent.call(self);
  5068. _bindTabEvent.call(self);
  5069. _bindFocusEvent.call(self);
  5070. edit.afterChange(function(e) {
  5071. if (!edit.designMode) {
  5072. return;
  5073. }
  5074. self.updateState();
  5075. self.addBookmark();
  5076. if (self.options.afterChange) {
  5077. self.options.afterChange.call(self);
  5078. }
  5079. });
  5080. edit.textarea.keyup(function(e) {
  5081. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5082. if (self.options.afterChange) {
  5083. self.options.afterChange.call(self);
  5084. }
  5085. }
  5086. });
  5087. if (self.readonlyMode) {
  5088. self.readonly();
  5089. }
  5090. self.isCreated = true;
  5091. if (self.initContent === '') {
  5092. self.initContent = self.html();
  5093. }
  5094. if (self._undoStack.length > 0) {
  5095. var prev = self._undoStack.pop();
  5096. if (prev.start) {
  5097. self.html(prev.html);
  5098. edit.cmd.range.moveToBookmark(prev);
  5099. self.select();
  5100. }
  5101. }
  5102. self.afterCreate();
  5103. if (self.options.afterCreate) {
  5104. self.options.afterCreate.call(self);
  5105. }
  5106. }
  5107. });
  5108. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5109. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5110. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5111. if (self._fullscreenResizeHandler) {
  5112. K(window).unbind('resize', self._fullscreenResizeHandler);
  5113. self._fullscreenResizeHandler = null;
  5114. }
  5115. function initResize() {
  5116. if (statusbar.height() === 0) {
  5117. setTimeout(initResize, 100);
  5118. return;
  5119. }
  5120. self.resize(width, height, false);
  5121. }
  5122. initResize();
  5123. if (fullscreenMode) {
  5124. self._fullscreenResizeHandler = function(e) {
  5125. if (self.isCreated) {
  5126. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5127. }
  5128. };
  5129. K(window).bind('resize', self._fullscreenResizeHandler);
  5130. toolbar.select('fullscreen');
  5131. statusbar.first().css('visibility', 'hidden');
  5132. statusbar.last().css('visibility', 'hidden');
  5133. } else {
  5134. if (_GECKO) {
  5135. K(window).bind('scroll', function(e) {
  5136. self._scrollPos = _getScrollPos();
  5137. });
  5138. }
  5139. if (self.resizeType > 0) {
  5140. _drag({
  5141. moveEl : container,
  5142. clickEl : statusbar,
  5143. moveFn : function(x, y, width, height, diffX, diffY) {
  5144. height += diffY;
  5145. self.resize(null, height);
  5146. }
  5147. });
  5148. } else {
  5149. statusbar.first().css('visibility', 'hidden');
  5150. }
  5151. if (self.resizeType === 2) {
  5152. _drag({
  5153. moveEl : container,
  5154. clickEl : statusbar.last(),
  5155. moveFn : function(x, y, width, height, diffX, diffY) {
  5156. width += diffX;
  5157. height += diffY;
  5158. self.resize(width, height);
  5159. }
  5160. });
  5161. } else {
  5162. statusbar.last().css('visibility', 'hidden');
  5163. }
  5164. }
  5165. return self;
  5166. },
  5167. remove : function() {
  5168. var self = this;
  5169. if (!self.isCreated) {
  5170. return self;
  5171. }
  5172. self.beforeRemove();
  5173. self.srcElement.data('kindeditor', '');
  5174. if (self.menu) {
  5175. self.hideMenu();
  5176. }
  5177. _each(self.dialogs, function() {
  5178. self.hideDialog();
  5179. });
  5180. K(document).unbind('mousedown', self._docMousedownFn);
  5181. self.toolbar.remove();
  5182. self.edit.remove();
  5183. self.statusbar.last().unbind();
  5184. self.statusbar.unbind();
  5185. self.container.remove();
  5186. self.container = self.toolbar = self.edit = self.menu = null;
  5187. self.dialogs = [];
  5188. self.isCreated = false;
  5189. return self;
  5190. },
  5191. resize : function(width, height, updateProp) {
  5192. var self = this;
  5193. updateProp = _undef(updateProp, true);
  5194. if (width) {
  5195. if (!/%/.test(width)) {
  5196. width = _removeUnit(width);
  5197. width = width < self.minWidth ? self.minWidth : width;
  5198. }
  5199. self.container.css('width', _addUnit(width));
  5200. if (updateProp) {
  5201. self.width = _addUnit(width);
  5202. }
  5203. }
  5204. if (height) {
  5205. height = _removeUnit(height);
  5206. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5207. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5208. self.edit.setHeight(editHeight);
  5209. if (updateProp) {
  5210. self.height = _addUnit(height);
  5211. }
  5212. }
  5213. return self;
  5214. },
  5215. select : function() {
  5216. this.isCreated && this.cmd.select();
  5217. return this;
  5218. },
  5219. html : function(val) {
  5220. var self = this;
  5221. if (val === undefined) {
  5222. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5223. }
  5224. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5225. if (self.isCreated) {
  5226. self.cmd.selection();
  5227. }
  5228. return self;
  5229. },
  5230. fullHtml : function() {
  5231. return this.isCreated ? this.edit.html(undefined, true) : '';
  5232. },
  5233. text : function(val) {
  5234. var self = this;
  5235. if (val === undefined) {
  5236. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5237. } else {
  5238. return self.html(_escape(val));
  5239. }
  5240. },
  5241. isEmpty : function() {
  5242. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5243. },
  5244. isDirty : function() {
  5245. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5246. },
  5247. selectedHtml : function() {
  5248. var val = this.isCreated ? this.cmd.range.html() : '';
  5249. val = _removeBookmarkTag(_removeTempTag(val));
  5250. return val;
  5251. },
  5252. count : function(mode) {
  5253. var self = this;
  5254. mode = (mode || 'html').toLowerCase();
  5255. if (mode === 'html') {
  5256. return self.html().length;
  5257. }
  5258. if (mode === 'text') {
  5259. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5260. }
  5261. return 0;
  5262. },
  5263. exec : function(key) {
  5264. key = key.toLowerCase();
  5265. var self = this, cmd = self.cmd,
  5266. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5267. if (changeFlag) {
  5268. self.addBookmark(false);
  5269. }
  5270. cmd[key].apply(cmd, _toArray(arguments, 1));
  5271. if (changeFlag) {
  5272. self.updateState();
  5273. self.addBookmark(false);
  5274. if (self.options.afterChange) {
  5275. self.options.afterChange.call(self);
  5276. }
  5277. }
  5278. return self;
  5279. },
  5280. insertHtml : function(val, quickMode) {
  5281. if (!this.isCreated) {
  5282. return this;
  5283. }
  5284. val = this.beforeSetHtml(val);
  5285. this.exec('inserthtml', val, quickMode);
  5286. return this;
  5287. },
  5288. appendHtml : function(val) {
  5289. this.html(this.html() + val);
  5290. if (this.isCreated) {
  5291. var cmd = this.cmd;
  5292. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5293. cmd.select();
  5294. }
  5295. return this;
  5296. },
  5297. sync : function() {
  5298. _elementVal(this.srcElement, this.html());
  5299. return this;
  5300. },
  5301. focus : function() {
  5302. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5303. return this;
  5304. },
  5305. blur : function() {
  5306. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5307. return this;
  5308. },
  5309. addBookmark : function(checkSize) {
  5310. checkSize = _undef(checkSize, true);
  5311. var self = this, edit = self.edit,
  5312. body = edit.doc.body,
  5313. html = _removeTempTag(body.innerHTML), bookmark;
  5314. if (checkSize && self._undoStack.length > 0) {
  5315. var prev = self._undoStack[self._undoStack.length - 1];
  5316. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5317. return self;
  5318. }
  5319. }
  5320. if (edit.designMode && !self._firstAddBookmark) {
  5321. var range = self.cmd.range;
  5322. bookmark = range.createBookmark(true);
  5323. bookmark.html = _removeTempTag(body.innerHTML);
  5324. range.moveToBookmark(bookmark);
  5325. } else {
  5326. bookmark = {
  5327. html : html
  5328. };
  5329. }
  5330. self._firstAddBookmark = false;
  5331. _addBookmarkToStack(self._undoStack, bookmark);
  5332. return self;
  5333. },
  5334. undo : function() {
  5335. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5336. },
  5337. redo : function() {
  5338. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5339. },
  5340. fullscreen : function(bool) {
  5341. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5342. this.addBookmark(false);
  5343. return this.remove().create();
  5344. },
  5345. readonly : function(isReadonly) {
  5346. isReadonly = _undef(isReadonly, true);
  5347. var self = this, edit = self.edit, doc = edit.doc;
  5348. if (self.designMode) {
  5349. self.toolbar.disableAll(isReadonly, []);
  5350. } else {
  5351. _each(self.noDisableItems, function() {
  5352. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5353. });
  5354. }
  5355. if (_IE) {
  5356. doc.body.contentEditable = !isReadonly;
  5357. } else {
  5358. doc.designMode = isReadonly ? 'off' : 'on';
  5359. }
  5360. edit.textarea[0].disabled = isReadonly;
  5361. },
  5362. createMenu : function(options) {
  5363. var self = this,
  5364. name = options.name,
  5365. knode = self.toolbar.get(name),
  5366. pos = knode.pos();
  5367. options.x = pos.x;
  5368. options.y = pos.y + knode.height();
  5369. options.z = self.options.zIndex;
  5370. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5371. if (options.selectedColor !== undefined) {
  5372. options.cls = 'ke-colorpicker-' + self.themeType;
  5373. options.noColor = self.lang('noColor');
  5374. self.menu = _colorpicker(options);
  5375. } else {
  5376. options.cls = 'ke-menu-' + self.themeType;
  5377. options.centerLineMode = false;
  5378. self.menu = _menu(options);
  5379. }
  5380. return self.menu;
  5381. },
  5382. hideMenu : function() {
  5383. this.menu.remove();
  5384. this.menu = null;
  5385. return this;
  5386. },
  5387. hideContextmenu : function() {
  5388. this.contextmenu.remove();
  5389. this.contextmenu = null;
  5390. return this;
  5391. },
  5392. createDialog : function(options) {
  5393. var self = this, name = options.name;
  5394. options.z = self.options.zIndex;
  5395. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5396. options.closeBtn = _undef(options.closeBtn, {
  5397. name : self.lang('close'),
  5398. click : function(e) {
  5399. self.hideDialog();
  5400. if (_IE && self.cmd) {
  5401. self.cmd.select();
  5402. }
  5403. }
  5404. });
  5405. options.noBtn = _undef(options.noBtn, {
  5406. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5407. click : function(e) {
  5408. self.hideDialog();
  5409. if (_IE && self.cmd) {
  5410. self.cmd.select();
  5411. }
  5412. }
  5413. });
  5414. if (self.dialogAlignType != 'page') {
  5415. options.alignEl = self.container;
  5416. }
  5417. options.cls = 'ke-dialog-' + self.themeType;
  5418. if (self.dialogs.length > 0) {
  5419. var firstDialog = self.dialogs[0],
  5420. parentDialog = self.dialogs[self.dialogs.length - 1];
  5421. firstDialog.setMaskIndex(parentDialog.z + 2);
  5422. options.z = parentDialog.z + 3;
  5423. options.showMask = false;
  5424. }
  5425. var dialog = _dialog(options);
  5426. self.dialogs.push(dialog);
  5427. return dialog;
  5428. },
  5429. hideDialog : function() {
  5430. var self = this;
  5431. if (self.dialogs.length > 0) {
  5432. self.dialogs.pop().remove();
  5433. }
  5434. if (self.dialogs.length > 0) {
  5435. var firstDialog = self.dialogs[0],
  5436. parentDialog = self.dialogs[self.dialogs.length - 1];
  5437. firstDialog.setMaskIndex(parentDialog.z - 1);
  5438. }
  5439. return self;
  5440. },
  5441. errorDialog : function(html) {
  5442. var self = this;
  5443. var dialog = self.createDialog({
  5444. width : 750,
  5445. title : self.lang('uploadError'),
  5446. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5447. });
  5448. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5449. doc.open();
  5450. doc.write(html);
  5451. doc.close();
  5452. K(doc.body).css('background-color', '#FFF');
  5453. iframe[0].contentWindow.focus();
  5454. return self;
  5455. }
  5456. };
  5457. function _editor(options) {
  5458. return new KEditor(options);
  5459. }
  5460. var _instances = [];
  5461. function _create(expr, options) {
  5462. options = options || {};
  5463. options.basePath = _undef(options.basePath, K.basePath);
  5464. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5465. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5466. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5467. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5468. var themeType = _undef(options.themeType, K.options.themeType);
  5469. _loadStyle(options.themesPath + 'default/default.css');
  5470. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5471. }
  5472. function create(editor) {
  5473. _each(_plugins, function(name, fn) {
  5474. if (_isFunction(fn)) {
  5475. fn.call(editor, KindEditor);
  5476. if (!editor._pluginStatus) {
  5477. editor._pluginStatus = {};
  5478. }
  5479. editor._pluginStatus[name] = 'inited';
  5480. }
  5481. });
  5482. return editor.create();
  5483. }
  5484. var knode = K(expr);
  5485. if (!knode || knode.length === 0) {
  5486. return;
  5487. }
  5488. if (knode.length > 1) {
  5489. knode.each(function() {
  5490. _create(this, options);
  5491. });
  5492. return _instances[0];
  5493. }
  5494. options.srcElement = knode[0];
  5495. var editor = new KEditor(options);
  5496. _instances.push(editor);
  5497. if (_language[editor.langType]) {
  5498. return create(editor);
  5499. }
  5500. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5501. create(editor);
  5502. });
  5503. return editor;
  5504. }
  5505. function _eachEditor(expr, fn) {
  5506. K(expr).each(function(i, el) {
  5507. K.each(_instances, function(j, editor) {
  5508. if (editor && editor.srcElement[0] == el) {
  5509. fn.call(editor, j);
  5510. return false;
  5511. }
  5512. });
  5513. });
  5514. }
  5515. K.remove = function(expr) {
  5516. _eachEditor(expr, function(i) {
  5517. this.remove();
  5518. _instances.splice(i, 1);
  5519. });
  5520. };
  5521. K.sync = function(expr) {
  5522. _eachEditor(expr, function() {
  5523. this.sync();
  5524. });
  5525. };
  5526. K.html = function(expr, val) {
  5527. _eachEditor(expr, function() {
  5528. this.html(val);
  5529. });
  5530. };
  5531. K.insertHtml = function(expr, val) {
  5532. _eachEditor(expr, function() {
  5533. this.insertHtml(val);
  5534. });
  5535. };
  5536. K.appendHtml = function(expr, val) {
  5537. _eachEditor(expr, function() {
  5538. this.appendHtml(val);
  5539. });
  5540. };
  5541. if (_IE && _V < 7) {
  5542. _nativeCommand(document, 'BackgroundImageCache', true);
  5543. }
  5544. K.EditorClass = KEditor;
  5545. K.editor = _editor;
  5546. K.create = _create;
  5547. K.instances = _instances;
  5548. K.plugin = _plugin;
  5549. K.lang = _lang;
  5550. _plugin('core', function(K) {
  5551. var self = this,
  5552. shortcutKeys = {
  5553. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5554. };
  5555. self.afterSetHtml(function() {
  5556. if (self.options.afterChange) {
  5557. self.options.afterChange.call(self);
  5558. }
  5559. });
  5560. self.afterCreate(function() {
  5561. if (self.syncType != 'form') {
  5562. return;
  5563. }
  5564. var el = K(self.srcElement), hasForm = false;
  5565. while ((el = el.parent())) {
  5566. if (el.name == 'form') {
  5567. hasForm = true;
  5568. break;
  5569. }
  5570. }
  5571. if (hasForm) {
  5572. el.bind('submit', function(e) {
  5573. self.sync();
  5574. K(window).bind('unload', function() {
  5575. self.edit.textarea.remove();
  5576. });
  5577. });
  5578. var resetBtn = K('[type="reset"]', el);
  5579. resetBtn.click(function() {
  5580. self.html(self.initContent);
  5581. self.cmd.selection();
  5582. });
  5583. self.beforeRemove(function() {
  5584. el.unbind();
  5585. resetBtn.unbind();
  5586. });
  5587. }
  5588. });
  5589. self.clickToolbar('source', function() {
  5590. if (self.edit.designMode) {
  5591. self.toolbar.disableAll(true);
  5592. self.edit.design(false);
  5593. self.toolbar.select('source');
  5594. } else {
  5595. self.toolbar.disableAll(false);
  5596. self.edit.design(true);
  5597. self.toolbar.unselect('source');
  5598. if (_GECKO) {
  5599. setTimeout(function() {
  5600. self.cmd.selection();
  5601. }, 0);
  5602. } else {
  5603. self.cmd.selection();
  5604. }
  5605. }
  5606. self.designMode = self.edit.designMode;
  5607. });
  5608. self.afterCreate(function() {
  5609. if (!self.designMode) {
  5610. self.toolbar.disableAll(true).select('source');
  5611. }
  5612. });
  5613. self.clickToolbar('fullscreen', function() {
  5614. self.fullscreen();
  5615. });
  5616. if (self.fullscreenShortcut) {
  5617. var loaded = false;
  5618. self.afterCreate(function() {
  5619. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5620. if (e.which == 27) {
  5621. setTimeout(function() {
  5622. self.fullscreen();
  5623. }, 0);
  5624. }
  5625. });
  5626. if (loaded) {
  5627. if (_IE && !self.designMode) {
  5628. return;
  5629. }
  5630. self.focus();
  5631. }
  5632. if (!loaded) {
  5633. loaded = true;
  5634. }
  5635. });
  5636. }
  5637. _each('undo,redo'.split(','), function(i, name) {
  5638. if (shortcutKeys[name]) {
  5639. self.afterCreate(function() {
  5640. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5641. self.clickToolbar(name);
  5642. });
  5643. });
  5644. }
  5645. self.clickToolbar(name, function() {
  5646. self[name]();
  5647. });
  5648. });
  5649. self.clickToolbar('formatblock', function() {
  5650. var blocks = self.lang('formatblock.formatBlock'),
  5651. heights = {
  5652. h1 : 28,
  5653. h2 : 24,
  5654. h3 : 18,
  5655. H4 : 14,
  5656. p : 12
  5657. },
  5658. curVal = self.cmd.val('formatblock'),
  5659. menu = self.createMenu({
  5660. name : 'formatblock',
  5661. width : self.langType == 'en' ? 200 : 150
  5662. });
  5663. _each(blocks, function(key, val) {
  5664. var style = 'font-size:' + heights[key] + 'px;';
  5665. if (key.charAt(0) === 'h') {
  5666. style += 'font-weight:bold;';
  5667. }
  5668. menu.addItem({
  5669. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5670. height : heights[key] + 12,
  5671. checked : (curVal === key || curVal === val),
  5672. click : function() {
  5673. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5674. }
  5675. });
  5676. });
  5677. });
  5678. self.clickToolbar('fontname', function() {
  5679. var curVal = self.cmd.val('fontname'),
  5680. menu = self.createMenu({
  5681. name : 'fontname',
  5682. width : 150
  5683. });
  5684. _each(self.lang('fontname.fontName'), function(key, val) {
  5685. menu.addItem({
  5686. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5687. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5688. click : function() {
  5689. self.exec('fontname', key).hideMenu();
  5690. }
  5691. });
  5692. });
  5693. });
  5694. self.clickToolbar('fontsize', function() {
  5695. var curVal = self.cmd.val('fontsize'),
  5696. menu = self.createMenu({
  5697. name : 'fontsize',
  5698. width : 150
  5699. });
  5700. _each(self.fontSizeTable, function(i, val) {
  5701. menu.addItem({
  5702. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5703. height : _removeUnit(val) + 12,
  5704. checked : curVal === val,
  5705. click : function() {
  5706. self.exec('fontsize', val).hideMenu();
  5707. }
  5708. });
  5709. });
  5710. });
  5711. self.clickToolbar('fontheight', function() {
  5712. var curVal = self.cmd.val('fontheight'),
  5713. menu = self.createMenu({
  5714. name : 'fontsize',
  5715. width : 150
  5716. });
  5717. _each(self.fontHeightTable, function(i, val) {
  5718. menu.addItem({
  5719. title : '<span unselectable="on">' + val + '</span>',
  5720. height : 20,
  5721. checked : curVal === val,
  5722. click : function() {
  5723. self.exec('fontheight', val).hideMenu();
  5724. }
  5725. });
  5726. });
  5727. });
  5728. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5729. self.clickToolbar(name, function() {
  5730. self.createMenu({
  5731. name : name,
  5732. selectedColor : self.cmd.val(name) || 'default',
  5733. colors : self.colorTable,
  5734. click : function(color) {
  5735. self.exec(name, color).hideMenu();
  5736. }
  5737. });
  5738. });
  5739. });
  5740. _each(('cut,copy,paste').split(','), function(i, name) {
  5741. self.clickToolbar(name, function() {
  5742. self.focus();
  5743. try {
  5744. self.exec(name, null);
  5745. } catch(e) {
  5746. alert(self.lang(name + 'Error'));
  5747. }
  5748. });
  5749. });
  5750. self.clickToolbar('about', function() {
  5751. var html = '<div style="margin:20px;">' +
  5752. '<div>KindEditor ' + _VERSION + '</div>' +
  5753. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5754. '</div>';
  5755. self.createDialog({
  5756. name : 'about',
  5757. width : 350,
  5758. title : self.lang('about'),
  5759. body : html
  5760. });
  5761. });
  5762. self.plugin.getSelectedLink = function() {
  5763. return self.cmd.commonAncestor('a');
  5764. };
  5765. self.plugin.getSelectedImage = function() {
  5766. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5767. return !/^ke-\w+$/i.test(img[0].className) && !img[0].getAttribute('data-key') && !img[0].getAttribute('data-applet') && !img[0].getAttribute('data-file');
  5768. });
  5769. };
  5770. self.plugin.getSelectedFlash = function() {
  5771. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5772. return img[0].className == 'ke-flash';
  5773. });
  5774. };
  5775. self.plugin.getSelectedMedia = function() {
  5776. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5777. return img[0].className == 'ke-media' || img[0].className == 'ke-rm' || img[0].getAttribute('data-file');
  5778. });
  5779. };
  5780. self.plugin.getSelectedDiy = function() {
  5781. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5782. return img[0].getAttribute('data-applet') || img[0].getAttribute('data-key');
  5783. });
  5784. };
  5785. self.plugin.getSelectedAnchor = function() {
  5786. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5787. return img[0].className == 'ke-anchor';
  5788. });
  5789. };
  5790. _each('diy,link,image,flash,media,anchor'.split(','), function(i, name) {
  5791. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5792. _each('edit,delete'.split(','), function(j, val) {
  5793. self.addContextmenu({
  5794. title : self.lang(val + uName),
  5795. click : function() {
  5796. self.loadPlugin(name, function() {
  5797. self.plugin[name][val]();
  5798. self.hideMenu();
  5799. });
  5800. },
  5801. cond : self.plugin['getSelected' + uName],
  5802. width : 150,
  5803. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5804. });
  5805. });
  5806. self.addContextmenu({ title : '-' });
  5807. });
  5808. self.plugin.getSelectedTable = function() {
  5809. return self.cmd.commonAncestor('table');
  5810. };
  5811. self.plugin.getSelectedRow = function() {
  5812. return self.cmd.commonAncestor('tr');
  5813. };
  5814. self.plugin.getSelectedCell = function() {
  5815. return self.cmd.commonAncestor('td');
  5816. };
  5817. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5818. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5819. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5820. self.addContextmenu({
  5821. title : self.lang('table' + val),
  5822. click : function() {
  5823. self.loadPlugin('table', function() {
  5824. self.plugin.table[val]();
  5825. self.hideMenu();
  5826. });
  5827. },
  5828. cond : cond,
  5829. width : 170,
  5830. iconClass : 'ke-icon-table' + val
  5831. });
  5832. });
  5833. self.addContextmenu({ title : '-' });
  5834. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5835. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5836. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5837. if (shortcutKeys[name]) {
  5838. self.afterCreate(function() {
  5839. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5840. self.cmd.selection();
  5841. self.clickToolbar(name);
  5842. });
  5843. });
  5844. }
  5845. self.clickToolbar(name, function() {
  5846. self.focus().exec(name, null);
  5847. });
  5848. });
  5849. self.afterCreate(function() {
  5850. var doc = self.edit.doc, cmd, bookmark, div,
  5851. cls = '__kindeditor_paste__', pasting = false;
  5852. function movePastedData() {
  5853. cmd.range.moveToBookmark(bookmark);
  5854. cmd.select();
  5855. if (_WEBKIT) {
  5856. K('div.' + cls, div).each(function() {
  5857. K(this).after('<br />').remove(true);
  5858. });
  5859. K('span.Apple-style-span', div).remove(true);
  5860. K('span.Apple-tab-span', div).remove(true);
  5861. K('span[style]', div).each(function() {
  5862. if (K(this).css('white-space') == 'nowrap') {
  5863. K(this).remove(true);
  5864. }
  5865. });
  5866. K('meta', div).remove();
  5867. }
  5868. var html = div[0].innerHTML;
  5869. div.remove();
  5870. if (html === '') {
  5871. return;
  5872. }
  5873. if (_WEBKIT) {
  5874. html = html.replace(/(<br>)\1/ig, '$1');
  5875. }
  5876. if (self.pasteType === 2) {
  5877. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5878. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5879. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5880. } else {
  5881. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5882. html = self.beforeSetHtml(html);
  5883. }
  5884. }
  5885. if (self.pasteType === 1) {
  5886. html = html.replace(/&nbsp;/ig, ' ');
  5887. html = html.replace(/\n\s*\n/g, '\n');
  5888. html = html.replace(/<br[^>]*>/ig, '\n');
  5889. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5890. html = html.replace(/<[^>]+>/g, '');
  5891. html = html.replace(/ {2}/g, ' &nbsp;');
  5892. if (self.newlineTag == 'p') {
  5893. if (/\n/.test(html)) {
  5894. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5895. }
  5896. } else {
  5897. html = html.replace(/\n/g, '<br />$&');
  5898. }
  5899. }
  5900. self.insertHtml(html, true);
  5901. autoImg(self);
  5902. }
  5903. K(doc.body).bind('paste', function(e){
  5904. //处理IE11,Chrome粘贴图片上传
  5905. function dopasteImg() {
  5906. //debugger;
  5907. var file = null;
  5908. if (window.clipboardData) {//ie
  5909. if (clipboardData.files && clipboardData.files.length)//IE11
  5910. file = clipboardData.files[0];
  5911. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5912. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5913. return true;
  5914. }
  5915. } else {
  5916. if (e.event.clipboardData.items)//chrome
  5917. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5918. if (e.event.clipboardData.items[i].kind === "file") {
  5919. file = e.event.clipboardData.items[i];
  5920. break;
  5921. }
  5922. }
  5923. if (file == null) {
  5924. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5925. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5926. return true;
  5927. }
  5928. }
  5929. }
  5930. if (file) {
  5931. if (!K.undef(self.allowImageUpload, true)) {
  5932. alert("编辑器禁止上传图片,请与有关人员联系!");
  5933. return true;
  5934. }
  5935. //获取File Blob
  5936. //debugger;
  5937. var blb;
  5938. if (file.getAsFile) {//Chrome
  5939. blb = file.getAsFile();
  5940. if (blb.size === 0) {
  5941. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5942. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5943. return true;
  5944. }
  5945. sendfile(blb, file.type);
  5946. } else {
  5947. var fr = new FileReader();
  5948. if (fr.readAsArrayBuffer) {//ie
  5949. fr.onloadend = function (evt) {
  5950. blb = evt.target.result;
  5951. sendfile(blb, file.type);
  5952. }
  5953. fr.readAsArrayBuffer(file);
  5954. }
  5955. }
  5956. function sendfile(b, t) {
  5957. var xhr = new XMLHttpRequest();
  5958. var formData = new FormData();
  5959. var isImg = t.indexOf("image/") === 0;
  5960. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5961. //formData.append('imgFile', b);
  5962. var myBlob = new Blob([b], { "type": t });
  5963. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5964. //formData.append('imgFile', b);
  5965. formData.append('dir', isImg ? 'image' : 'file');
  5966. if (self.uploadYunJson && self.uploadYunJson.domain) {
  5967. formData.append('token', self.uploadYunJson.token);
  5968. xhr.open('POST', self.uploadYunJson.domain);
  5969. } else {
  5970. xhr.open('POST', self.uploadJson);
  5971. }
  5972. xhr.onreadystatechange = function () {
  5973. if (xhr.readyState == 4&&xhr.status == 200) {
  5974. // if (fn) {
  5975. var data = _trim(xhr.responseText);
  5976. //if (dataType == 'json') {
  5977. data = _json(data);
  5978. if (data.error) {
  5979. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5980. $.messager.alert('Error', data.message, 'warning');
  5981. } else {
  5982. alert(data.message);
  5983. }
  5984. } else {
  5985. //self.exec('insertimage', url, title, width, height, border, align);
  5986. if(K.undef(self.formatUploadUrl, true))
  5987. data.url =K.formatUrl(data.url, 'absolute');
  5988. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5989. }
  5990. //}
  5991. // fn(data);
  5992. // }
  5993. }
  5994. }
  5995. xhr.send(formData);
  5996. }
  5997. return true;
  5998. }
  5999. }
  6000. //debugger;
  6001. if (dopasteImg())
  6002. e.stop();
  6003. //处理粘贴结束5825
  6004. if (self.pasteType === 0) {
  6005. e.stop();
  6006. return;
  6007. }
  6008. if (pasting) {
  6009. return;
  6010. }
  6011. pasting = true;
  6012. K('div.' + cls, doc).remove();
  6013. cmd = self.cmd.selection();
  6014. bookmark = cmd.range.createBookmark();
  6015. div = K('<div class="' + cls + '"></div>', doc).css({
  6016. position : 'absolute',
  6017. width : '1px',
  6018. height : '1px',
  6019. overflow : 'hidden',
  6020. left : '-1981px',
  6021. top : K(bookmark.start).pos().y + 'px',
  6022. 'white-space' : 'nowrap'
  6023. });
  6024. K(doc.body).append(div);
  6025. if (_IE) {
  6026. var rng = cmd.range.get(true);
  6027. rng.moveToElementText(div[0]);
  6028. rng.select();
  6029. rng.execCommand('paste');
  6030. e.preventDefault();
  6031. } else {
  6032. cmd.range.selectNodeContents(div[0]);
  6033. cmd.select();
  6034. div[0].tabIndex = -1;
  6035. div[0].focus();
  6036. }
  6037. setTimeout(function() {
  6038. movePastedData();
  6039. pasting = false;
  6040. }, 0);
  6041. });
  6042. });
  6043. self.beforeGetHtml(function(html) {
  6044. if (_IE && _V <= 8) {
  6045. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  6046. return unescape(tag);
  6047. });
  6048. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  6049. if (!/\s+type="[^"]+"/i.test($0)) {
  6050. return $1 + ' type="text"' + $2;
  6051. }
  6052. return $0;
  6053. });
  6054. }
  6055. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  6056. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  6057. })
  6058. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  6059. var imgAttrs = _getAttrList(full);
  6060. var styles = _getCssList(imgAttrs.style || '');
  6061. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6062. var width = _undef(styles.width, '');
  6063. var height = _undef(styles.height, '');
  6064. if (/px/i.test(width)) {
  6065. width = _removeUnit(width);
  6066. }
  6067. if (/px/i.test(height)) {
  6068. height = _removeUnit(height);
  6069. }
  6070. attrs.width = _undef(imgAttrs.width, width);
  6071. attrs.height = _undef(imgAttrs.height, height);
  6072. return _mediaEmbed(attrs);
  6073. })
  6074. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6075. var imgAttrs = _getAttrList(full);
  6076. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6077. })
  6078. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6079. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6080. })
  6081. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6082. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6083. })
  6084. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6085. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6086. return $1 + _unescape(src) + $2;
  6087. });
  6088. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6089. return full;
  6090. })
  6091. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6092. return start + end;
  6093. });
  6094. });
  6095. self.beforeSetHtml(function(html) {
  6096. if (_IE && _V <= 8) {
  6097. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6098. var attrs = _getAttrList(full);
  6099. var styles = _getCssList(attrs.style || '');
  6100. if (styles.display == 'none') {
  6101. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6102. }
  6103. return full;
  6104. });
  6105. }
  6106. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6107. var attrs = _getAttrList(full);
  6108. attrs.src = _undef(attrs.src, '');
  6109. attrs.width = _undef(attrs.width, 0);
  6110. attrs.height = _undef(attrs.height, 0);
  6111. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6112. })
  6113. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6114. var attrs = _getAttrList(full);
  6115. if (attrs.href !== undefined) {
  6116. return full;
  6117. }
  6118. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6119. })
  6120. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6121. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6122. })
  6123. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6124. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6125. })
  6126. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6127. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6128. return full;
  6129. }
  6130. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6131. return full;
  6132. })
  6133. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6134. return start + 'data-ke-' + end;
  6135. })
  6136. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6137. if (full.indexOf('ke-zeroborder') >= 0) {
  6138. return full;
  6139. }
  6140. return _addClassToTag(full, 'ke-zeroborder');
  6141. });
  6142. });
  6143. });
  6144. })(window);
  6145. /*******************************************************************************
  6146. * KindEditor - WYSIWYG HTML Editor for Internet
  6147. * Copyright (C) 2006-2011 kindsoft.net
  6148. *
  6149. * @author Roddy <luolonghao@gmail.com>
  6150. * @site http://www.kindsoft.net/
  6151. * @licence http://www.kindsoft.net/license.php
  6152. *******************************************************************************/
  6153. KindEditor.lang({
  6154. source : 'HTML代码',
  6155. preview : '预览',
  6156. undo : '后退(Ctrl+Z)',
  6157. redo : '前进(Ctrl+Y)',
  6158. cut : '剪切(Ctrl+X)',
  6159. copy : '复制(Ctrl+C)',
  6160. paste : '粘贴(Ctrl+V)',
  6161. plainpaste : '粘贴为无格式文本',
  6162. wordpaste : '从Word粘贴',
  6163. selectall : '全选(Ctrl+A)',
  6164. justifyleft : '左对齐',
  6165. justifycenter : '居中',
  6166. justifyright : '右对齐',
  6167. justifyfull : '两端对齐',
  6168. insertorderedlist : '编号',
  6169. insertunorderedlist : '项目符号',
  6170. indent : '增加缩进',
  6171. outdent : '减少缩进',
  6172. subscript : '下标',
  6173. superscript : '上标',
  6174. formatblock : '段落',
  6175. fontname : '字体',
  6176. fontsize : '文字大小',
  6177. fontheight : '文字间距',
  6178. forecolor : '文字颜色',
  6179. hilitecolor : '文字背景',
  6180. bold : '粗体(Ctrl+B)',
  6181. italic : '斜体(Ctrl+I)',
  6182. underline : '下划线(Ctrl+U)',
  6183. strikethrough : '删除线',
  6184. removeformat : '删除格式',
  6185. image : '图片',
  6186. multiimage : '批量图片上传',
  6187. flash : 'Flash',
  6188. media : '音频',
  6189. table : '表格',
  6190. tablecell : '单元格',
  6191. hr : '插入横线',
  6192. emoticons : '插入表情',
  6193. link : '超级链接',
  6194. unlink : '取消超级链接',
  6195. fullscreen : '全屏显示',
  6196. about : '关于',
  6197. print : '打印(Ctrl+P)',
  6198. filemanager : '文件库',
  6199. code : '插入程序代码',
  6200. map : 'Google地图',
  6201. baidumap : '百度地图',
  6202. lineheight : '行距',
  6203. clearhtml : '清理HTML代码',
  6204. pagebreak : '插入分页符',
  6205. quickformat : '一键排版',
  6206. insertfile : '插入文件',
  6207. template : '插入模板',
  6208. anchor : '锚点',
  6209. yes : '确定',
  6210. no : '取消',
  6211. close : '关闭',
  6212. editImage : '图片属性',
  6213. deleteImage : '删除图片',
  6214. editFlash : 'Flash属性',
  6215. deleteFlash : '删除Flash',
  6216. editMedia : '音频属性',
  6217. deleteMedia : '删除音频',
  6218. editLink : '超级链接属性',
  6219. deleteLink : '取消超级链接',
  6220. editAnchor : '锚点属性',
  6221. deleteAnchor : '删除锚点',
  6222. tableprop : '表格属性',
  6223. tablecellprop : '单元格属性',
  6224. tableinsert : '插入表格',
  6225. tabledelete : '删除表格',
  6226. tablecolinsertleft : '左侧插入列',
  6227. tablecolinsertright : '右侧插入列',
  6228. tablerowinsertabove : '上方插入行',
  6229. tablerowinsertbelow : '下方插入行',
  6230. tablerowmerge : '向下合并单元格',
  6231. tablecolmerge : '向右合并单元格',
  6232. tablerowsplit : '拆分行',
  6233. tablecolsplit : '拆分列',
  6234. tablecoldelete : '删除列',
  6235. tablerowdelete : '删除行',
  6236. noColor : '无颜色',
  6237. pleaseSelectFile : '请选择文件。',
  6238. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6239. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6240. invalidWidth : "宽度必须为数字。",
  6241. invalidHeight : "高度必须为数字。",
  6242. invalidBorder : "边框必须为数字。",
  6243. invalidUrl : "请输入有效的URL地址。",
  6244. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6245. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6246. invalidPadding : '边距必须为数字。',
  6247. invalidSpacing : '间距必须为数字。',
  6248. invalidJson : '服务器发生故障。',
  6249. uploadSuccess : '上传成功。',
  6250. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6251. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6252. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6253. ajaxLoading : '加载中,请稍候 ...',
  6254. uploadLoading : '上传中,请稍候 ...',
  6255. uploadError : '上传错误',
  6256. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6257. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6258. 'code.pleaseInput' : '请输入程序代码。',
  6259. 'link.url' : 'URL',
  6260. 'link.linkType' : '打开类型',
  6261. 'link.newWindow' : '新窗口',
  6262. 'link.selfWindow' : '当前窗口',
  6263. 'flash.url' : 'URL',
  6264. 'flash.width' : '宽度',
  6265. 'flash.height' : '高度',
  6266. 'flash.upload' : '上传',
  6267. 'flash.viewServer' : '文件空间',
  6268. 'media.url' : 'URL',
  6269. 'media.width' : '宽度',
  6270. 'media.height' : '高度',
  6271. 'media.autostart' : '自动播放',
  6272. 'media.upload' : '上传',
  6273. 'media.viewServer' : '文件空间',
  6274. 'image.remoteImage' : '网络图片',
  6275. 'image.localImage' : '本地上传',
  6276. 'image.remoteUrl' : '图片地址',
  6277. 'image.localUrl' : '上传文件',
  6278. 'image.size' : '图片大小',
  6279. 'image.width' : '宽',
  6280. 'image.height' : '高',
  6281. 'image.resetSize' : '重置大小',
  6282. 'image.align' : '对齐方式',
  6283. 'image.defaultAlign' : '默认方式',
  6284. 'image.leftAlign' : '左对齐',
  6285. 'image.rightAlign' : '右对齐',
  6286. 'image.imgTitle' : '图片说明',
  6287. 'image.upload' : '浏览...',
  6288. 'image.viewServer' : '图片空间',
  6289. //'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6290. 'multiimage.uploadDesc' : '',
  6291. 'multiimage.startUpload' : '开始上传',
  6292. 'multiimage.clearAll' : '全部清空',
  6293. 'multiimage.insertAll' : '全部插入',
  6294. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6295. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6296. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6297. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6298. 'multiimage.unknownError' : '发生异常,无法上传。',
  6299. 'multiimage.pending' : '等待上传',
  6300. 'multiimage.uploadError' : '上传失败',
  6301. 'filemanager.emptyFolder' : '空文件夹',
  6302. 'filemanager.moveup' : '移到上一级文件夹',
  6303. 'filemanager.viewType' : '显示方式:',
  6304. 'filemanager.viewImage' : '缩略图',
  6305. 'filemanager.listImage' : '详细信息',
  6306. 'filemanager.orderType' : '排序方式:',
  6307. 'filemanager.fileName' : '名称',
  6308. 'filemanager.fileSize' : '大小',
  6309. 'filemanager.fileType' : '类型',
  6310. 'insertfile.url' : 'URL',
  6311. 'insertfile.title' : '文件说明',
  6312. 'insertfile.upload' : '上传',
  6313. 'insertfile.viewServer' : '文件空间',
  6314. 'table.cells' : '单元格数',
  6315. 'table.rows' : '行数',
  6316. 'table.cols' : '列数',
  6317. 'table.size' : '大小',
  6318. 'table.width' : '宽度',
  6319. 'table.height' : '高度',
  6320. 'table.percent' : '%',
  6321. 'table.px' : 'px',
  6322. 'table.space' : '边距间距',
  6323. 'table.padding' : '边距',
  6324. 'table.spacing' : '间距',
  6325. 'table.align' : '对齐方式',
  6326. 'table.textAlign' : '水平对齐',
  6327. 'table.verticalAlign' : '垂直对齐',
  6328. 'table.alignDefault' : '默认',
  6329. 'table.alignLeft' : '左对齐',
  6330. 'table.alignCenter' : '居中',
  6331. 'table.alignRight' : '右对齐',
  6332. 'table.alignTop' : '顶部',
  6333. 'table.alignMiddle' : '中部',
  6334. 'table.alignBottom' : '底部',
  6335. 'table.alignBaseline' : '基线',
  6336. 'table.border' : '边框',
  6337. 'table.borderWidth' : '边框',
  6338. 'table.borderColor' : '颜色',
  6339. 'table.backgroundColor' : '背景颜色',
  6340. 'map.address' : '地址: ',
  6341. 'map.search' : '搜索',
  6342. 'baidumap.address' : '地址: ',
  6343. 'baidumap.search' : '搜索',
  6344. 'baidumap.insertDynamicMap' : '插入动态地图',
  6345. 'anchor.name' : '锚点名称',
  6346. 'formatblock.formatBlock' : {
  6347. h1 : '标题 1',
  6348. h2 : '标题 2',
  6349. h3 : '标题 3',
  6350. h4 : '标题 4',
  6351. p : '正 文'
  6352. },
  6353. 'fontname.fontName' : {
  6354. 'SimSun' : '宋体',
  6355. 'NSimSun' : '新宋体',
  6356. 'FangSong_GB2312' : '仿宋_GB2312',
  6357. 'KaiTi_GB2312' : '楷体_GB2312',
  6358. 'SimHei' : '黑体',
  6359. 'Microsoft YaHei' : '微软雅黑',
  6360. 'Arial' : 'Arial',
  6361. 'Arial Black' : 'Arial Black',
  6362. 'Times New Roman' : 'Times New Roman',
  6363. 'Courier New' : 'Courier New',
  6364. 'Tahoma' : 'Tahoma',
  6365. 'Verdana' : 'Verdana'
  6366. },
  6367. 'lineheight.lineHeight' : [
  6368. {'1' : '单倍行距'},
  6369. {'1.5' : '1.5倍行距'},
  6370. {'1.75' : '1.75倍行距'},
  6371. {'2' : '2倍行距'},
  6372. {'2.5' : '2.5倍行距'},
  6373. {'3' : '3倍行距'}
  6374. ],
  6375. 'template.selectTemplate' : '可选模板',
  6376. 'template.replaceContent' : '替换当前内容',
  6377. 'template.fileList' : {
  6378. '1.html' : '图片和文字',
  6379. '2.html' : '表格',
  6380. '3.html' : '项目编号'
  6381. }
  6382. }, 'zh-CN');
  6383. KindEditor.options.langType = 'zh-CN';
  6384. /*******************************************************************************
  6385. * KindEditor - WYSIWYG HTML Editor for Internet
  6386. * Copyright (C) 2006-2011 kindsoft.net
  6387. *
  6388. * @author Roddy <luolonghao@gmail.com>
  6389. * @site http://www.kindsoft.net/
  6390. * @licence http://www.kindsoft.net/license.php
  6391. *******************************************************************************/
  6392. KindEditor.plugin('anchor', function(K) {
  6393. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6394. self.plugin.anchor = {
  6395. edit : function() {
  6396. var html = ['<div style="padding:20px;">',
  6397. '<div class="ke-dialog-row">',
  6398. '<label for="keName">' + lang.name + '</label>',
  6399. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6400. '</div>',
  6401. '</div>'].join('');
  6402. var dialog = self.createDialog({
  6403. name : name,
  6404. width : 300,
  6405. title : self.lang(name),
  6406. body : html,
  6407. yesBtn : {
  6408. name : self.lang('yes'),
  6409. click : function(e) {
  6410. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6411. }
  6412. }
  6413. });
  6414. var div = dialog.div,
  6415. nameBox = K('input[name="name"]', div);
  6416. var img = self.plugin.getSelectedAnchor();
  6417. if (img) {
  6418. nameBox.val(unescape(img.attr('data-ke-name')));
  6419. }
  6420. nameBox[0].focus();
  6421. nameBox[0].select();
  6422. },
  6423. 'delete' : function() {
  6424. self.plugin.getSelectedAnchor().remove();
  6425. }
  6426. };
  6427. self.clickToolbar(name, self.plugin.anchor.edit);
  6428. });
  6429. /*******************************************************************************
  6430. * KindEditor - WYSIWYG HTML Editor for Internet
  6431. * Copyright (C) 2006-2011 kindsoft.net
  6432. *
  6433. * @author Roddy <luolonghao@gmail.com>
  6434. * @site http://www.kindsoft.net/
  6435. * @licence http://www.kindsoft.net/license.php
  6436. *******************************************************************************/
  6437. KindEditor.plugin('autoheight', function(K) {
  6438. var self = this;
  6439. if (!self.autoHeightMode) {
  6440. return;
  6441. }
  6442. var minHeight;
  6443. function hideScroll() {
  6444. var edit = self.edit;
  6445. var body = edit.doc.body;
  6446. edit.iframe[0].scroll = 'no';
  6447. body.style.overflowY = 'hidden';
  6448. }
  6449. function resetHeight() {
  6450. if(self.fullscreenMode){
  6451. return;
  6452. }
  6453. var edit = self.edit;
  6454. var body = edit.doc.body;
  6455. edit.iframe.height(minHeight);
  6456. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6457. }
  6458. function init() {
  6459. minHeight = K.removeUnit(self.height);
  6460. self.edit.afterChange(resetHeight);
  6461. if(!self.fullscreenMode){
  6462. hideScroll();
  6463. }
  6464. resetHeight();
  6465. }
  6466. if (self.isCreated) {
  6467. init();
  6468. } else {
  6469. self.afterCreate(init);
  6470. }
  6471. });
  6472. /*
  6473. * 如何实现真正的自动高度?
  6474. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6475. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6476. * 由此就实现了真正的自动高度
  6477. * 测试:chrome、firefox、IE9、IE8
  6478. * */
  6479. /*******************************************************************************
  6480. * KindEditor - WYSIWYG HTML Editor for Internet
  6481. * Copyright (C) 2006-2011 kindsoft.net
  6482. *
  6483. * @author Roddy <luolonghao@gmail.com>
  6484. * @site http://www.kindsoft.net/
  6485. * @licence http://www.kindsoft.net/license.php
  6486. *******************************************************************************/
  6487. KindEditor.plugin('baidumap', function(K) {
  6488. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6489. var mapWidth = K.undef(self.mapWidth, 558);
  6490. var mapHeight = K.undef(self.mapHeight, 360);
  6491. self.clickToolbar(name, function() {
  6492. var html = ['<div style="padding:10px 20px;">',
  6493. '<div class="ke-header">',
  6494. '<div class="ke-left">',
  6495. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6496. '<span class="ke-button-common ke-button-outer">',
  6497. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6498. '</span>',
  6499. '</div>',
  6500. '<div class="ke-right">',
  6501. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6502. '</div>',
  6503. '<div class="ke-clearfix"></div>',
  6504. '</div>',
  6505. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6506. '</div>'].join('');
  6507. var dialog = self.createDialog({
  6508. name : name,
  6509. width : mapWidth + 42,
  6510. title : self.lang(name),
  6511. body : html,
  6512. yesBtn : {
  6513. name : self.lang('yes'),
  6514. click : function(e) {
  6515. var map = win.map;
  6516. var centerObj = map.getCenter();
  6517. var center = centerObj.lng + ',' + centerObj.lat;
  6518. var zoom = map.getZoom();
  6519. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6520. '?center=' + encodeURIComponent(center),
  6521. '&zoom=' + encodeURIComponent(zoom),
  6522. '&width=' + mapWidth,
  6523. '&height=' + mapHeight,
  6524. '&markers=' + encodeURIComponent(center),
  6525. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6526. if (checkbox[0].checked) {
  6527. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6528. } else {
  6529. self.exec('insertimage', url);
  6530. }
  6531. self.hideDialog().focus();
  6532. }
  6533. },
  6534. beforeRemove : function() {
  6535. searchBtn.remove();
  6536. if (doc) {
  6537. doc.write('');
  6538. }
  6539. iframe.remove();
  6540. }
  6541. });
  6542. var div = dialog.div,
  6543. addressBox = K('[name="address"]', div),
  6544. searchBtn = K('[name="searchBtn"]', div),
  6545. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6546. win, doc;
  6547. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6548. function ready() {
  6549. win = iframe[0].contentWindow;
  6550. doc = K.iframeDoc(iframe);
  6551. }
  6552. iframe.bind('load', function() {
  6553. iframe.unbind('load');
  6554. if (K.IE) {
  6555. ready();
  6556. } else {
  6557. setTimeout(ready, 0);
  6558. }
  6559. });
  6560. K('.ke-map', div).replaceWith(iframe);
  6561. searchBtn.click(function() {
  6562. win.search(addressBox.val());
  6563. });
  6564. });
  6565. });
  6566. /*******************************************************************************
  6567. * KindEditor - WYSIWYG HTML Editor for Internet
  6568. * Copyright (C) 2006-2011 kindsoft.net
  6569. *
  6570. * @author Roddy <luolonghao@gmail.com>
  6571. * @site http://www.kindsoft.net/
  6572. * @licence http://www.kindsoft.net/license.php
  6573. *******************************************************************************/
  6574. KindEditor.plugin('map', function(K) {
  6575. var self = this, name = 'map', lang = self.lang(name + '.');
  6576. self.clickToolbar(name, function() {
  6577. var html = ['<div style="padding:10px 20px;">',
  6578. '<div class="ke-dialog-row">',
  6579. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6580. '<span class="ke-button-common ke-button-outer">',
  6581. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6582. '</span>',
  6583. '</div>',
  6584. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6585. '</div>'].join('');
  6586. var dialog = self.createDialog({
  6587. name : name,
  6588. width : 600,
  6589. title : self.lang(name),
  6590. body : html,
  6591. yesBtn : {
  6592. name : self.lang('yes'),
  6593. click : function(e) {
  6594. var geocoder = win.geocoder,
  6595. map = win.map,
  6596. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6597. zoom = map.getZoom(),
  6598. maptype = map.getMapTypeId(),
  6599. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6600. url += '?center=' + encodeURIComponent(center);
  6601. url += '&zoom=' + encodeURIComponent(zoom);
  6602. url += '&size=558x360';
  6603. url += '&maptype=' + encodeURIComponent(maptype);
  6604. url += '&markers=' + encodeURIComponent(center);
  6605. url += '&language=' + self.langType;
  6606. url += '&sensor=false';
  6607. self.exec('insertimage', url).hideDialog().focus();
  6608. }
  6609. },
  6610. beforeRemove : function() {
  6611. searchBtn.remove();
  6612. if (doc) {
  6613. doc.write('');
  6614. }
  6615. iframe.remove();
  6616. }
  6617. });
  6618. var div = dialog.div,
  6619. addressBox = K('[name="address"]', div),
  6620. searchBtn = K('[name="searchBtn"]', div),
  6621. win, doc;
  6622. var iframeHtml = ['<!doctype html><html><head>',
  6623. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6624. '<style>',
  6625. ' html { height: 100% }',
  6626. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6627. ' #map_canvas { height: 100% }',
  6628. '</style>',
  6629. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6630. '<script>',
  6631. 'var map, geocoder;',
  6632. 'function initialize() {',
  6633. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6634. ' var options = {',
  6635. ' zoom: 11,',
  6636. ' center: latlng,',
  6637. ' disableDefaultUI: true,',
  6638. ' panControl: true,',
  6639. ' zoomControl: true,',
  6640. ' mapTypeControl: true,',
  6641. ' scaleControl: true,',
  6642. ' streetViewControl: false,',
  6643. ' overviewMapControl: true,',
  6644. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6645. ' };',
  6646. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6647. ' geocoder = new google.maps.Geocoder();',
  6648. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6649. ' if (status == google.maps.GeocoderStatus.OK) {',
  6650. ' if (results[3]) {',
  6651. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6652. ' }',
  6653. ' }',
  6654. ' });',
  6655. '}',
  6656. 'function search(address) {',
  6657. ' if (!map) return;',
  6658. ' geocoder.geocode({address : address}, function(results, status) {',
  6659. ' if (status == google.maps.GeocoderStatus.OK) {',
  6660. ' map.setZoom(11);',
  6661. ' map.setCenter(results[0].geometry.location);',
  6662. ' var marker = new google.maps.Marker({',
  6663. ' map: map,',
  6664. ' position: results[0].geometry.location',
  6665. ' });',
  6666. ' } else {',
  6667. ' alert("Invalid address: " + address);',
  6668. ' }',
  6669. ' });',
  6670. '}',
  6671. '</script>',
  6672. '</head>',
  6673. '<body onload="initialize();">',
  6674. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6675. '</body></html>'].join('\n');
  6676. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6677. function ready() {
  6678. win = iframe[0].contentWindow;
  6679. doc = K.iframeDoc(iframe);
  6680. }
  6681. iframe.bind('load', function() {
  6682. iframe.unbind('load');
  6683. if (K.IE) {
  6684. ready();
  6685. } else {
  6686. setTimeout(ready, 0);
  6687. }
  6688. });
  6689. K('.ke-map', div).replaceWith(iframe);
  6690. searchBtn.click(function() {
  6691. win.search(addressBox.val());
  6692. });
  6693. });
  6694. });
  6695. /*******************************************************************************
  6696. * KindEditor - WYSIWYG HTML Editor for Internet
  6697. * Copyright (C) 2006-2011 kindsoft.net
  6698. *
  6699. * @author Roddy <luolonghao@gmail.com>
  6700. * @site http://www.kindsoft.net/
  6701. * @licence http://www.kindsoft.net/license.php
  6702. *******************************************************************************/
  6703. KindEditor.plugin('clearhtml', function(K) {
  6704. var self = this, name = 'clearhtml';
  6705. self.clickToolbar(name, function() {
  6706. self.focus();
  6707. var html = self.html();
  6708. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6709. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6710. html = K.formatHtml(html, {
  6711. a : ['href', 'target'],
  6712. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6713. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6714. table : ['border'],
  6715. 'td,th' : ['rowspan', 'colspan'],
  6716. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6717. });
  6718. self.html(html);
  6719. self.cmd.selection(true);
  6720. self.addBookmark();
  6721. });
  6722. });
  6723. /*******************************************************************************
  6724. * KindEditor - WYSIWYG HTML Editor for Internet
  6725. * Copyright (C) 2006-2011 kindsoft.net
  6726. *
  6727. * @author Roddy <luolonghao@gmail.com>
  6728. * @site http://www.kindsoft.net/
  6729. * @licence http://www.kindsoft.net/license.php
  6730. *******************************************************************************/
  6731. KindEditor.plugin('code', function(K) {
  6732. var self = this, name = 'code';
  6733. self.clickToolbar(name, function() {
  6734. var lang = self.lang(name + '.'),
  6735. html = ['<div style="padding:10px 20px;">',
  6736. '<div class="ke-dialog-row">',
  6737. '<select class="ke-code-type">',
  6738. '<option value="js">JavaScript</option>',
  6739. '<option value="html">HTML</option>',
  6740. '<option value="css">CSS</option>',
  6741. '<option value="php">PHP</option>',
  6742. '<option value="pl">Perl</option>',
  6743. '<option value="py">Python</option>',
  6744. '<option value="rb">Ruby</option>',
  6745. '<option value="java">Java</option>',
  6746. '<option value="vb">ASP/VB</option>',
  6747. '<option value="cpp">C/C++</option>',
  6748. '<option value="cs">C#</option>',
  6749. '<option value="xml">XML</option>',
  6750. '<option value="bsh">Shell</option>',
  6751. '<option value="">Other</option>',
  6752. '</select>',
  6753. '</div>',
  6754. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6755. '</div>'].join(''),
  6756. dialog = self.createDialog({
  6757. name : name,
  6758. width : 450,
  6759. title : self.lang(name),
  6760. body : html,
  6761. yesBtn : {
  6762. name : self.lang('yes'),
  6763. click : function(e) {
  6764. var type = K('.ke-code-type', dialog.div).val(),
  6765. code = textarea.val(),
  6766. cls = type === '' ? '' : ' lang-' + type,
  6767. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6768. if (K.trim(code) === '') {
  6769. alert(lang.pleaseInput);
  6770. textarea[0].focus();
  6771. return;
  6772. }
  6773. self.insertHtml(html).hideDialog().focus();
  6774. }
  6775. }
  6776. }),
  6777. textarea = K('textarea', dialog.div);
  6778. textarea[0].focus();
  6779. });
  6780. });
  6781. /*******************************************************************************
  6782. * KindEditor - WYSIWYG HTML Editor for Internet
  6783. * Copyright (C) 2006-2011 kindsoft.net
  6784. *
  6785. * @author Roddy <luolonghao@gmail.com>
  6786. * @site http://www.kindsoft.net/
  6787. * @licence http://www.kindsoft.net/license.php
  6788. *******************************************************************************/
  6789. KindEditor.plugin('emoticons', function(K) {
  6790. var self = this, name = 'emoticons',
  6791. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6792. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6793. currentPageNum = 1;
  6794. self.clickToolbar(name, function() {
  6795. var rows = 5, cols = 9, total = 135, startNum = 0,
  6796. cells = rows * cols, pages = Math.ceil(total / cells),
  6797. colsHalf = Math.floor(cols / 2),
  6798. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6799. elements = [],
  6800. menu = self.createMenu({
  6801. name : name,
  6802. beforeRemove : function() {
  6803. removeEvent();
  6804. }
  6805. });
  6806. menu.div.append(wrapperDiv);
  6807. var previewDiv, previewImg;
  6808. if (allowPreview) {
  6809. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6810. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6811. wrapperDiv.append(previewDiv);
  6812. previewDiv.append(previewImg);
  6813. }
  6814. function bindCellEvent(cell, j, num) {
  6815. if (previewDiv) {
  6816. cell.mouseover(function() {
  6817. if (j > colsHalf) {
  6818. previewDiv.css('left', 0);
  6819. previewDiv.css('right', '');
  6820. } else {
  6821. previewDiv.css('left', '');
  6822. previewDiv.css('right', 0);
  6823. }
  6824. previewImg.attr('src', path + num + '.gif');
  6825. K(this).addClass('ke-on');
  6826. });
  6827. } else {
  6828. cell.mouseover(function() {
  6829. K(this).addClass('ke-on');
  6830. });
  6831. }
  6832. cell.mouseout(function() {
  6833. K(this).removeClass('ke-on');
  6834. });
  6835. cell.click(function(e) {
  6836. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6837. e.stop();
  6838. });
  6839. }
  6840. function createEmoticonsTable(pageNum, parentDiv) {
  6841. var table = document.createElement('table');
  6842. parentDiv.append(table);
  6843. if (previewDiv) {
  6844. K(table).mouseover(function() {
  6845. previewDiv.show('block');
  6846. });
  6847. K(table).mouseout(function() {
  6848. previewDiv.hide();
  6849. });
  6850. elements.push(K(table));
  6851. }
  6852. table.className = 'ke-table';
  6853. table.cellPadding = 0;
  6854. table.cellSpacing = 0;
  6855. table.border = 0;
  6856. var num = (pageNum - 1) * cells + startNum;
  6857. for (var i = 0; i < rows; i++) {
  6858. var row = table.insertRow(i);
  6859. for (var j = 0; j < cols; j++) {
  6860. var cell = K(row.insertCell(j));
  6861. cell.addClass('ke-cell');
  6862. bindCellEvent(cell, j, num);
  6863. var span = K('<span class="ke-img"></span>')
  6864. .css('background-position', '-' + (24 * num) + 'px 0px')
  6865. .css('background-image', 'url(' + path + 'static.gif)');
  6866. cell.append(span);
  6867. elements.push(cell);
  6868. num++;
  6869. }
  6870. }
  6871. return table;
  6872. }
  6873. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6874. function removeEvent() {
  6875. K.each(elements, function() {
  6876. this.unbind();
  6877. });
  6878. }
  6879. var pageDiv;
  6880. function bindPageEvent(el, pageNum) {
  6881. el.click(function(e) {
  6882. removeEvent();
  6883. table.parentNode.removeChild(table);
  6884. pageDiv.remove();
  6885. table = createEmoticonsTable(pageNum, wrapperDiv);
  6886. createPageTable(pageNum);
  6887. currentPageNum = pageNum;
  6888. e.stop();
  6889. });
  6890. }
  6891. function createPageTable(currentPageNum) {
  6892. pageDiv = K('<div class="ke-page"></div>');
  6893. wrapperDiv.append(pageDiv);
  6894. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6895. if (currentPageNum !== pageNum) {
  6896. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6897. bindPageEvent(a, pageNum);
  6898. pageDiv.append(a);
  6899. elements.push(a);
  6900. } else {
  6901. pageDiv.append(K('@[' + pageNum + ']'));
  6902. }
  6903. pageDiv.append(K('@&nbsp;'));
  6904. }
  6905. }
  6906. createPageTable(currentPageNum);
  6907. });
  6908. });
  6909. /*******************************************************************************
  6910. * KindEditor - WYSIWYG HTML Editor for Internet
  6911. * Copyright (C) 2006-2011 kindsoft.net
  6912. *
  6913. * @author Roddy <luolonghao@gmail.com>
  6914. * @site http://www.kindsoft.net/
  6915. * @licence http://www.kindsoft.net/license.php
  6916. *******************************************************************************/
  6917. KindEditor.plugin('filemanager', function(K) {
  6918. var self = this, name = 'filemanager',
  6919. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6920. imgPath = self.pluginsPath + name + '/images/',
  6921. lang = self.lang(name + '.');
  6922. function makeFileTitle(filename, filesize, datetime) {
  6923. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6924. }
  6925. function bindTitle(el, data) {
  6926. if (data.is_dir) {
  6927. el.attr('title', data.filename);
  6928. } else {
  6929. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6930. }
  6931. }
  6932. self.plugin.filemanagerDialog = function(options) {
  6933. var width = K.undef(options.width, 650),
  6934. height = K.undef(options.height, 510),
  6935. dirName = K.undef(options.dirName, ''),
  6936. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6937. clickFn = options.clickFn;
  6938. var html = [
  6939. '<div style="padding:10px 20px;">',
  6940. '<div class="ke-plugin-filemanager-header">',
  6941. '<div class="ke-left">',
  6942. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6943. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6944. '</div>',
  6945. '<div class="ke-right">',
  6946. '标签 <input type="text" style="width:100px;" value="" name="viewTag">',
  6947. '分类 <select class="ke-inline-block" name="viewCate">',
  6948. '',
  6949. '</select> ',
  6950. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6951. '<option value="VIEW">' + lang.viewImage + '</option>',
  6952. '<option value="LIST">' + lang.listImage + '</option>',
  6953. '</select> ',
  6954. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6955. '<option value="NAME">' + lang.fileName + '</option>',
  6956. '<option value="SIZE">' + lang.fileSize + '</option>',
  6957. '<option value="TYPE">' + lang.fileType + '</option>',
  6958. '</select>',
  6959. '</div>',
  6960. '<div class="ke-clearfix"></div>',
  6961. '</div>',
  6962. '<div class="ke-plugin-filemanager-body"></div>',
  6963. '</div>'
  6964. ].join('');
  6965. var dialog = self.createDialog({
  6966. name : name,
  6967. width : width,
  6968. height : height,
  6969. title : self.lang(name),
  6970. body : html
  6971. }),
  6972. div = dialog.div,
  6973. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6974. moveupImg = K('[name="moveupImg"]', div),
  6975. moveupLink = K('[name="moveupLink"]', div),
  6976. viewServerBtn = K('[name="viewServer"]', div),
  6977. viewCateBox = K('[name="viewCate"]', div),
  6978. viewTagBox = K('[name="viewTag"]', div),
  6979. viewTypeBox = K('[name="viewType"]', div),
  6980. orderTypeBox = K('[name="orderType"]', div);
  6981. function reloadPage(path, order, func, cate, tag) {
  6982. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6983. if (cate) {
  6984. param += '&cate=' + cate;
  6985. }
  6986. if (tag) {
  6987. param += '&tag=' + tag;
  6988. }
  6989. dialog.showLoading(self.lang('ajaxLoading'));
  6990. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6991. dialog.hideLoading();
  6992. func(data);
  6993. });
  6994. }
  6995. var elList = [];
  6996. function bindEvent(el, result, data, createFunc) {
  6997. var fileUrl = K.formatUrl(result.current_url + data.file, 'absolute'),
  6998. dirPath = encodeURIComponent(result.current_dir_path + data.path + '/');
  6999. if (data.is_dir) {
  7000. el.click(function(e) {
  7001. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  7002. });
  7003. } else if (data.is_photo) {
  7004. el.click(function(e) {
  7005. clickFn.call(this, fileUrl, data.file);
  7006. });
  7007. } else {
  7008. el.click(function(e) {
  7009. clickFn.call(this, fileUrl, data.file);
  7010. });
  7011. }
  7012. elList.push(el);
  7013. }
  7014. function createCommon(result, createFunc) {
  7015. K.each(elList, function() {
  7016. this.unbind();
  7017. });
  7018. moveupLink.unbind();
  7019. viewTypeBox.unbind();
  7020. orderTypeBox.unbind();
  7021. if (result.current_dir_path) {
  7022. moveupLink.click(function(e) {
  7023. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  7024. });
  7025. }
  7026. function changeFunc() {
  7027. if (viewTypeBox.val() == 'VIEW') {
  7028. reloadPage(result.current_dir_path, orderTypeBox.val(), createView, viewCateBox.val(), viewTagBox.val());
  7029. } else {
  7030. reloadPage(result.current_dir_path, orderTypeBox.val(), createList, viewCateBox.val(), viewTagBox.val());
  7031. }
  7032. }
  7033. viewTypeBox.change(changeFunc);
  7034. orderTypeBox.change(changeFunc);
  7035. viewCateBox.change(changeFunc);
  7036. bodyDiv.html('');
  7037. }
  7038. function createList(result) {
  7039. createCommon(result, createList);
  7040. var table = document.createElement('table');
  7041. table.className = 'ke-table';
  7042. table.cellPadding = 0;
  7043. table.cellSpacing = 0;
  7044. table.border = 0;
  7045. bodyDiv.append(table);
  7046. var fileList = result.file_list;
  7047. for (var i = 0, len = fileList.length; i < len; i++) {
  7048. var data = fileList[i], row = K(table.insertRow(i));
  7049. row.mouseover(function(e) {
  7050. K(this).addClass('ke-on');
  7051. })
  7052. .mouseout(function(e) {
  7053. K(this).removeClass('ke-on');
  7054. });
  7055. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  7056. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  7057. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  7058. if (!data.is_dir || data.has_file) {
  7059. row.css('cursor', 'pointer');
  7060. cell0.attr('title', data.filename);
  7061. bindEvent(cell0, result, data, createList);
  7062. } else {
  7063. cell0.attr('title', lang.emptyFolder);
  7064. }
  7065. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  7066. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  7067. }
  7068. }
  7069. function createView(result) {
  7070. createCommon(result, createView);
  7071. var fileList = result.file_list;
  7072. for (var i = 0, len = fileList.length; i < len; i++) {
  7073. var data = fileList[i],
  7074. div = K('<div class="ke-inline-block ke-item"></div>');
  7075. bodyDiv.append(div);
  7076. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7077. .mouseover(function(e) {
  7078. K(this).addClass('ke-on');
  7079. })
  7080. .mouseout(function(e) {
  7081. K(this).removeClass('ke-on');
  7082. });
  7083. div.append(photoDiv);
  7084. var fileUrl = result.current_url + data.file,
  7085. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7086. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7087. if (!data.is_dir || data.has_file) {
  7088. photoDiv.css('cursor', 'pointer');
  7089. bindTitle(photoDiv, data);
  7090. bindEvent(photoDiv, result, data, createView);
  7091. } else {
  7092. photoDiv.attr('title', lang.emptyFolder);
  7093. }
  7094. photoDiv.append(img);
  7095. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7096. }
  7097. }
  7098. viewTypeBox.val(viewType);
  7099. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7100. return dialog;
  7101. }
  7102. });
  7103. /*******************************************************************************
  7104. * KindEditor - WYSIWYG HTML Editor for Internet
  7105. * Copyright (C) 2006-2011 kindsoft.net
  7106. *
  7107. * @author Roddy <luolonghao@gmail.com>
  7108. * @site http://www.kindsoft.net/
  7109. * @licence http://www.kindsoft.net/license.php
  7110. *******************************************************************************/
  7111. KindEditor.plugin('flash', function(K) {
  7112. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7113. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7114. allowFileManager = K.undef(self.allowFileManager, false),
  7115. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7116. extraParams = K.undef(self.extraFileUploadParams, {}),
  7117. filePostName = K.undef(self.filePostName, 'imgFile'),
  7118. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7119. self.plugin.flash = {
  7120. edit : function() {
  7121. var html = [
  7122. '<div style="padding:20px;">',
  7123. '<div class="ke-dialog-row">',
  7124. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7125. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7126. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7127. '<span class="ke-button-common ke-button-outer">',
  7128. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7129. '</span>',
  7130. '</div>',
  7131. '<div class="ke-dialog-row">',
  7132. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7133. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7134. '</div>',
  7135. '<div class="ke-dialog-row">',
  7136. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7137. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7138. '</div>',
  7139. '</div>'
  7140. ].join('');
  7141. var dialog = self.createDialog({
  7142. name : name,
  7143. width : 450,
  7144. title : self.lang(name),
  7145. body : html,
  7146. yesBtn : {
  7147. name : self.lang('yes'),
  7148. click : function(e) {
  7149. var url = K.trim(urlBox.val()),
  7150. width = widthBox.val(),
  7151. height = heightBox.val();
  7152. if (url == 'http://' || K.invalidUrl(url)) {
  7153. alert(self.lang('invalidUrl'));
  7154. urlBox[0].focus();
  7155. return;
  7156. }
  7157. if (!/^\d*$/.test(width)) {
  7158. alert(self.lang('invalidWidth'));
  7159. widthBox[0].focus();
  7160. return;
  7161. }
  7162. if (!/^\d*$/.test(height)) {
  7163. alert(self.lang('invalidHeight'));
  7164. heightBox[0].focus();
  7165. return;
  7166. }
  7167. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7168. src : url,
  7169. type : K.mediaType('.swf'),
  7170. width : width,
  7171. height : height,
  7172. quality : 'high'
  7173. });
  7174. self.insertHtml(html).hideDialog().focus();
  7175. }
  7176. }
  7177. }),
  7178. div = dialog.div,
  7179. urlBox = K('[name="url"]', div),
  7180. viewServerBtn = K('[name="viewServer"]', div),
  7181. widthBox = K('[name="width"]', div),
  7182. heightBox = K('[name="height"]', div);
  7183. urlBox.val('http://');
  7184. if (allowFlashUpload) {
  7185. var uploadbutton = K.uploadbutton({
  7186. button : K('.ke-upload-button', div)[0],
  7187. fieldName : filePostName,
  7188. extraParams : extraParams,
  7189. url : K.addParam(uploadJson, 'dir=flash'),
  7190. afterUpload : function(data) {
  7191. dialog.hideLoading();
  7192. if (data.error === 0) {
  7193. var url = data.url;
  7194. if (formatUploadUrl) {
  7195. url = K.formatUrl(url, 'absolute');
  7196. }
  7197. urlBox.val(url);
  7198. if (self.afterUpload) {
  7199. self.afterUpload.call(self, url, data, name);
  7200. }
  7201. alert(self.lang('uploadSuccess'));
  7202. } else {
  7203. alert(data.message);
  7204. }
  7205. },
  7206. afterError : function(html) {
  7207. dialog.hideLoading();
  7208. self.errorDialog(html);
  7209. }
  7210. });
  7211. uploadbutton.fileBox.change(function(e) {
  7212. dialog.showLoading(self.lang('uploadLoading'));
  7213. uploadbutton.submit();
  7214. });
  7215. } else {
  7216. K('.ke-upload-button', div).hide();
  7217. }
  7218. if (allowFileManager) {
  7219. viewServerBtn.click(function(e) {
  7220. var clickFn = function(url, title, id) {
  7221. K('[name="url"]', div).val(url);
  7222. if (self.afterSelectFile) {
  7223. self.afterSelectFile.call(self, url);
  7224. }
  7225. };
  7226. var cur = K('[name="url"]', div).val();
  7227. editorShowUpload(cur, self.mediaManagerJson, 'flash库', clickFn, this);
  7228. /*
  7229. self.loadPlugin('filemanager', function() {
  7230. self.plugin.filemanagerDialog({
  7231. viewType : 'LIST',
  7232. dirName : 'flash',
  7233. clickFn : function(url, title) {
  7234. if (self.dialogs.length > 1) {
  7235. K('[name="url"]', div).val(url);
  7236. if (self.afterSelectFile) {
  7237. self.afterSelectFile.call(self, url);
  7238. }
  7239. self.hideDialog();
  7240. }
  7241. }
  7242. });
  7243. });
  7244. */
  7245. });
  7246. } else {
  7247. viewServerBtn.hide();
  7248. }
  7249. var img = self.plugin.getSelectedFlash();
  7250. if (img) {
  7251. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7252. urlBox.val(attrs.src);
  7253. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7254. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7255. }
  7256. urlBox[0].focus();
  7257. urlBox[0].select();
  7258. },
  7259. 'delete' : function() {
  7260. self.plugin.getSelectedFlash().remove();
  7261. self.addBookmark();
  7262. }
  7263. };
  7264. self.clickToolbar(name, self.plugin.flash.edit);
  7265. });
  7266. /*******************************************************************************
  7267. * KindEditor - WYSIWYG HTML Editor for Internet
  7268. * Copyright (C) 2006-2011 kindsoft.net
  7269. *
  7270. * @author Roddy <luolonghao@gmail.com>
  7271. * @site http://www.kindsoft.net/
  7272. * @licence http://www.kindsoft.net/license.php
  7273. *******************************************************************************/
  7274. KindEditor.plugin('image', function(K) {
  7275. var self = this, name = 'image',
  7276. allowImageUpload = K.undef(self.allowImageUpload, true),
  7277. allowImageRemote = K.undef(self.allowImageRemote, true),
  7278. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7279. allowFileManager = K.undef(self.allowFileManager, false),
  7280. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7281. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7282. imgPath = self.pluginsPath + 'image/images/',
  7283. extraParams = K.undef(self.extraFileUploadParams, {}),
  7284. filePostName = K.undef(self.filePostName, 'imgFile'),
  7285. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7286. lang = self.lang(name + '.');
  7287. self.plugin.imageDialog = function(options) {
  7288. var imageUrl = options.imageUrl,
  7289. imageWidth = K.undef(options.imageWidth, ''),
  7290. imageHeight = K.undef(options.imageHeight, ''),
  7291. imageTitle = K.undef(options.imageTitle, ''),
  7292. imageAlign = K.undef(options.imageAlign, ''),
  7293. showRemote = K.undef(options.showRemote, true),
  7294. showLocal = K.undef(options.showLocal, true),
  7295. tabIndex = K.undef(options.tabIndex, 0),
  7296. clickFn = options.clickFn;
  7297. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7298. var hiddenElements = [];
  7299. for(var k in extraParams){
  7300. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7301. }
  7302. var html = [
  7303. '<div style="padding:20px;">',
  7304. '<div class="tabs"></div>',
  7305. '<div class="tab1" style="display:none;">',
  7306. '<div class="ke-dialog-row">',
  7307. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7308. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7309. '<span class="ke-button-common ke-button-outer">',
  7310. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7311. '</span>',
  7312. '</div>',
  7313. '<div class="ke-dialog-row">',
  7314. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7315. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7316. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7317. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7318. '</div>',
  7319. '<div class="ke-dialog-row">',
  7320. '<label style="width:60px;">' + lang.align + '</label>',
  7321. '<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="" />',
  7322. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7323. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7324. '</div>',
  7325. '<div class="ke-dialog-row">',
  7326. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7327. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7328. '</div>',
  7329. '</div>',
  7330. '<div class="tab2" style="display:none;">',
  7331. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7332. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7333. '<div class="ke-dialog-row">',
  7334. hiddenElements.join(''),
  7335. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7336. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7337. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7338. '</div>',
  7339. '</form>',
  7340. '</div>',
  7341. '</div>'
  7342. ].join('');
  7343. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7344. dialogHeight = showLocal && showRemote ? 300 : 250;
  7345. var dialog = self.createDialog({
  7346. name : name,
  7347. width : dialogWidth,
  7348. height : dialogHeight,
  7349. title : self.lang(name),
  7350. body : html,
  7351. yesBtn : {
  7352. name : self.lang('yes'),
  7353. click : function(e) {
  7354. if (dialog.isLoading) {
  7355. return;
  7356. }
  7357. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7358. if (uploadbutton.fileBox.val() == '') {
  7359. alert(self.lang('pleaseSelectFile'));
  7360. return;
  7361. }
  7362. dialog.showLoading(self.lang('uploadLoading'));
  7363. uploadbutton.submit();
  7364. localUrlBox.val('');
  7365. return;
  7366. }
  7367. var url = K.trim(urlBox.val()),
  7368. width = widthBox.val(),
  7369. height = heightBox.val(),
  7370. title = titleBox.val(),
  7371. align = '';
  7372. alignBox.each(function() {
  7373. if (this.checked) {
  7374. align = this.value;
  7375. return false;
  7376. }
  7377. });
  7378. if (url == 'http://' || K.invalidUrl(url)) {
  7379. alert(self.lang('invalidUrl'));
  7380. urlBox[0].focus();
  7381. return;
  7382. }
  7383. if (!/^\d*$/.test(width)) {
  7384. alert(self.lang('invalidWidth'));
  7385. widthBox[0].focus();
  7386. return;
  7387. }
  7388. if (!/^\d*$/.test(height)) {
  7389. alert(self.lang('invalidHeight'));
  7390. heightBox[0].focus();
  7391. return;
  7392. }
  7393. clickFn.call(self, url, title, width, height, 0, align);
  7394. }
  7395. },
  7396. beforeRemove : function() {
  7397. viewServerBtn.unbind();
  7398. widthBox.unbind();
  7399. heightBox.unbind();
  7400. refreshBtn.unbind();
  7401. }
  7402. }),
  7403. div = dialog.div;
  7404. var urlBox = K('[name="url"]', div),
  7405. localUrlBox = K('[name="localUrl"]', div),
  7406. viewServerBtn = K('[name="viewServer"]', div),
  7407. widthBox = K('.tab1 [name="width"]', div),
  7408. heightBox = K('.tab1 [name="height"]', div),
  7409. refreshBtn = K('.ke-refresh-btn', div),
  7410. titleBox = K('.tab1 [name="title"]', div),
  7411. alignBox = K('.tab1 [name="align"]', div);
  7412. var tabs;
  7413. if (showRemote && showLocal) {
  7414. tabs = K.tabs({
  7415. src : K('.tabs', div),
  7416. afterSelect : function(i) {}
  7417. });
  7418. tabs.add({
  7419. title : lang.remoteImage,
  7420. panel : K('.tab1', div)
  7421. });
  7422. tabs.add({
  7423. title : lang.localImage,
  7424. panel : K('.tab2', div)
  7425. });
  7426. tabs.select(1);
  7427. } else if (showRemote) {
  7428. K('.tab1', div).show();
  7429. } else if (showLocal) {
  7430. K('.tab2', div).show();
  7431. }
  7432. var uploadbutton = K.uploadbutton({
  7433. button : K('.ke-upload-button', div)[0],
  7434. fieldName : filePostName,
  7435. form : K('.ke-form', div),
  7436. target : target,
  7437. width: 60,
  7438. afterUpload : function(data) {
  7439. dialog.hideLoading();
  7440. if (data.error === 0) {
  7441. var url = data.url;
  7442. if (formatUploadUrl) {
  7443. url = K.formatUrl(url, 'absolute');
  7444. }
  7445. if (self.afterUpload) {
  7446. self.afterUpload.call(self, url, data, name);
  7447. }
  7448. if (!fillDescAfterUploadImage) {
  7449. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7450. } else {
  7451. K(".ke-dialog-row #remoteUrl", div).val(url);
  7452. K(".ke-tabs-li", div)[0].click();
  7453. K(".ke-refresh-btn", div).click();
  7454. }
  7455. } else {
  7456. alert(data.message);
  7457. }
  7458. },
  7459. afterError : function(html) {
  7460. dialog.hideLoading();
  7461. self.errorDialog(html);
  7462. }
  7463. });
  7464. uploadbutton.fileBox.change(function(e) {
  7465. localUrlBox.val(uploadbutton.fileBox.val());
  7466. });
  7467. if (allowFileManager) {
  7468. viewServerBtn.click(function(e) {
  7469. //clickFn.call(this, fileUrl, data.file);
  7470. var clickFn = function(url, title, id) {
  7471. K('[name="url"]', div).val(url);
  7472. if (self.afterSelectFile) {
  7473. self.afterSelectFile.call(self, url);
  7474. }
  7475. };
  7476. var cur = K('[name="url"]', div).val();
  7477. editorShowUpload(cur, self.fileManagerJson, '图库', clickFn, this);
  7478. /*
  7479. self.loadPlugin('filemanager', function() {
  7480. self.plugin.filemanagerDialog({
  7481. viewType : 'VIEW',
  7482. dirName : 'image',
  7483. clickFn : function(url, title) {
  7484. if (self.dialogs.length > 1) {
  7485. K('[name="url"]', div).val(url);
  7486. if (self.afterSelectFile) {
  7487. self.afterSelectFile.call(self, url);
  7488. }
  7489. self.hideDialog();
  7490. }
  7491. }
  7492. });
  7493. });
  7494. */
  7495. });
  7496. } else {
  7497. viewServerBtn.hide();
  7498. }
  7499. var originalWidth = 0, originalHeight = 0;
  7500. function setSize(width, height) {
  7501. widthBox.val(width);
  7502. heightBox.val(height);
  7503. originalWidth = width;
  7504. originalHeight = height;
  7505. }
  7506. refreshBtn.click(function(e) {
  7507. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7508. position : 'absolute',
  7509. visibility : 'hidden',
  7510. top : 0,
  7511. left : '-1000px'
  7512. });
  7513. tempImg.bind('load', function() {
  7514. setSize(tempImg.width(), tempImg.height());
  7515. tempImg.remove();
  7516. });
  7517. K(document.body).append(tempImg);
  7518. });
  7519. widthBox.change(function(e) {
  7520. if (originalWidth > 0) {
  7521. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7522. }
  7523. });
  7524. heightBox.change(function(e) {
  7525. if (originalHeight > 0) {
  7526. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7527. }
  7528. });
  7529. urlBox.val(options.imageUrl);
  7530. setSize(options.imageWidth, options.imageHeight);
  7531. titleBox.val(options.imageTitle);
  7532. alignBox.each(function() {
  7533. if (this.value === options.imageAlign) {
  7534. this.checked = true;
  7535. return false;
  7536. }
  7537. });
  7538. if (showRemote && tabIndex === 0) {
  7539. urlBox[0].focus();
  7540. urlBox[0].select();
  7541. }
  7542. return dialog;
  7543. };
  7544. self.plugin.image = {
  7545. edit : function() {
  7546. var img = self.plugin.getSelectedImage();
  7547. self.plugin.imageDialog({
  7548. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7549. imageWidth : img ? img.width() : '',
  7550. imageHeight : img ? img.height() : '',
  7551. imageTitle : img ? img.attr('title') : '',
  7552. imageAlign : img ? img.attr('align') : '',
  7553. showRemote : allowImageRemote,
  7554. showLocal : allowImageUpload,
  7555. tabIndex: img ? 0 : imageTabIndex,
  7556. clickFn : function(url, title, width, height, border, align) {
  7557. if (img) {
  7558. img.attr('src', url);
  7559. img.attr('data-ke-src', url);
  7560. img.attr('width', width);
  7561. img.attr('height', height);
  7562. img.attr('title', title);
  7563. img.attr('align', align);
  7564. img.attr('alt', title);
  7565. } else {
  7566. self.exec('insertimage', url, title, width, height, border, align);
  7567. }
  7568. setTimeout(function() {
  7569. self.hideDialog().focus();
  7570. }, 0);
  7571. }
  7572. });
  7573. },
  7574. 'delete' : function() {
  7575. var target = self.plugin.getSelectedImage();
  7576. if (target.parent().name == 'a') {
  7577. target = target.parent();
  7578. }
  7579. target.remove();
  7580. self.addBookmark();
  7581. }
  7582. };
  7583. self.clickToolbar(name, self.plugin.image.edit);
  7584. });
  7585. KindEditor.plugin('diy', function(K) {
  7586. var self = this, name = 'diy';
  7587. self.plugin.diy = {
  7588. edit : function() {
  7589. var value = self.plugin.getSelectedDiy();
  7590. if (value.attr('data-applet')) {
  7591. $('.update_show_editor').each(function(i)
  7592. {
  7593. var key = $(this).attr('key');
  7594. if (key.indexOf('http://') > -1) {
  7595. $(this).attr('data-value', value.attr('data-applet'));
  7596. $(this).click();
  7597. $(this).attr('data-value', '');
  7598. }
  7599. })
  7600. } else if (value.attr('data-key')) {
  7601. var data_key = value.attr('data-key');
  7602. $('.upload_show_editor').each(function(i)
  7603. {
  7604. var key = $(this).attr('key');
  7605. if (key == data_key) {
  7606. $(this).attr('data-value', value.attr('data-id'));
  7607. $(this).click();
  7608. $(this).attr('data-value', '');
  7609. }
  7610. })
  7611. }
  7612. },
  7613. 'delete' : function() {
  7614. var target = self.plugin.getSelectedDiy();
  7615. if (target.parent().name == 'a') {
  7616. target = target.parent();
  7617. }
  7618. target.remove();
  7619. self.addBookmark();
  7620. }
  7621. };
  7622. });
  7623. /*******************************************************************************
  7624. * KindEditor - WYSIWYG HTML Editor for Internet
  7625. * Copyright (C) 2006-2011 kindsoft.net
  7626. *
  7627. * @author Roddy <luolonghao@gmail.com>
  7628. * @site http://www.kindsoft.net/
  7629. * @licence http://www.kindsoft.net/license.php
  7630. *******************************************************************************/
  7631. KindEditor.plugin('insertfile', function(K) {
  7632. var self = this, name = 'insertfile',
  7633. allowFileUpload = K.undef(self.allowFileUpload, true),
  7634. allowFileManager = K.undef(self.allowFileManager, false),
  7635. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7636. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7637. extraParams = K.undef(self.extraFileUploadParams, {}),
  7638. filePostName = K.undef(self.filePostName, 'imgFile'),
  7639. lang = self.lang(name + '.');
  7640. self.plugin.fileDialog = function(options) {
  7641. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7642. fileTitle = K.undef(options.fileTitle, ''),
  7643. clickFn = options.clickFn;
  7644. var html = [
  7645. '<div style="padding:20px;">',
  7646. '<div class="ke-dialog-row">',
  7647. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7648. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7649. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7650. '<span class="ke-button-common ke-button-outer">',
  7651. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7652. '</span>',
  7653. '</div>',
  7654. '<div class="ke-dialog-row">',
  7655. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7656. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7657. '</div>',
  7658. '</form>',
  7659. '</div>'
  7660. ].join('');
  7661. var dialog = self.createDialog({
  7662. name : name,
  7663. width : 450,
  7664. title : self.lang(name),
  7665. body : html,
  7666. yesBtn : {
  7667. name : self.lang('yes'),
  7668. click : function(e) {
  7669. var url = K.trim(urlBox.val()),
  7670. title = titleBox.val();
  7671. if (url == 'http://' || K.invalidUrl(url)) {
  7672. alert(self.lang('invalidUrl'));
  7673. urlBox[0].focus();
  7674. return;
  7675. }
  7676. if (K.trim(title) === '') {
  7677. title = url;
  7678. }
  7679. clickFn.call(self, url, title);
  7680. }
  7681. }
  7682. }),
  7683. div = dialog.div;
  7684. var urlBox = K('[name="url"]', div),
  7685. viewServerBtn = K('[name="viewServer"]', div),
  7686. titleBox = K('[name="title"]', div);
  7687. if (allowFileUpload) {
  7688. var uploadbutton = K.uploadbutton({
  7689. button : K('.ke-upload-button', div)[0],
  7690. fieldName : filePostName,
  7691. url : K.addParam(uploadJson, 'dir=file'),
  7692. extraParams : extraParams,
  7693. afterUpload : function(data) {
  7694. dialog.hideLoading();
  7695. if (data.error === 0) {
  7696. var url = data.url;
  7697. if (formatUploadUrl) {
  7698. url = K.formatUrl(url, 'absolute');
  7699. }
  7700. urlBox.val(url);
  7701. if (self.afterUpload) {
  7702. self.afterUpload.call(self, url, data, name);
  7703. }
  7704. alert(self.lang('uploadSuccess'));
  7705. } else {
  7706. alert(data.message);
  7707. }
  7708. },
  7709. afterError : function(html) {
  7710. dialog.hideLoading();
  7711. self.errorDialog(html);
  7712. }
  7713. });
  7714. uploadbutton.fileBox.change(function(e) {
  7715. dialog.showLoading(self.lang('uploadLoading'));
  7716. uploadbutton.submit();
  7717. });
  7718. } else {
  7719. K('.ke-upload-button', div).hide();
  7720. }
  7721. if (allowFileManager) {
  7722. viewServerBtn.click(function(e) {
  7723. var clickFn = function(url, title, id) {
  7724. K('[name="url"]', div).val(url);
  7725. if (self.afterSelectFile) {
  7726. self.afterSelectFile.call(self, url);
  7727. }
  7728. };
  7729. var cur = K('[name="url"]', div).val();
  7730. editorShowUpload(cur, self.fileManagerJson, '文件库', clickFn, this);
  7731. /*
  7732. self.loadPlugin('filemanager', function() {
  7733. self.plugin.filemanagerDialog({
  7734. viewType : 'LIST',
  7735. dirName : 'file',
  7736. clickFn : function(url, title) {
  7737. if (self.dialogs.length > 1) {
  7738. self.hideDialog();
  7739. }
  7740. }
  7741. });
  7742. });
  7743. */
  7744. });
  7745. } else {
  7746. viewServerBtn.hide();
  7747. }
  7748. urlBox.val(fileUrl);
  7749. titleBox.val(fileTitle);
  7750. urlBox[0].focus();
  7751. urlBox[0].select();
  7752. };
  7753. self.clickToolbar(name, function() {
  7754. self.plugin.fileDialog({
  7755. clickFn : function(url, title) {
  7756. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7757. self.insertHtml(html).hideDialog().focus();
  7758. }
  7759. });
  7760. });
  7761. });
  7762. /*******************************************************************************
  7763. * KindEditor - WYSIWYG HTML Editor for Internet
  7764. * Copyright (C) 2006-2011 kindsoft.net
  7765. *
  7766. * @author Roddy <luolonghao@gmail.com>
  7767. * @site http://www.kindsoft.net/
  7768. * @licence http://www.kindsoft.net/license.php
  7769. *******************************************************************************/
  7770. KindEditor.plugin('lineheight', function(K) {
  7771. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7772. self.clickToolbar(name, function() {
  7773. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7774. if (commonNode) {
  7775. curVal = commonNode.css('line-height');
  7776. }
  7777. var menu = self.createMenu({
  7778. name : name,
  7779. width : 150
  7780. });
  7781. K.each(lang.lineHeight, function(i, row) {
  7782. K.each(row, function(key, val) {
  7783. menu.addItem({
  7784. title : val,
  7785. checked : curVal === key,
  7786. click : function() {
  7787. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7788. span : '.line-height=' + key
  7789. });
  7790. self.updateState();
  7791. self.addBookmark();
  7792. self.hideMenu();
  7793. }
  7794. });
  7795. });
  7796. });
  7797. });
  7798. });
  7799. /*******************************************************************************
  7800. * KindEditor - WYSIWYG HTML Editor for Internet
  7801. * Copyright (C) 2006-2011 kindsoft.net
  7802. *
  7803. * @author Roddy <luolonghao@gmail.com>
  7804. * @site http://www.kindsoft.net/
  7805. * @licence http://www.kindsoft.net/license.php
  7806. *******************************************************************************/
  7807. KindEditor.plugin('link', function(K) {
  7808. var self = this, name = 'link';
  7809. self.plugin.link = {
  7810. edit : function() {
  7811. var lang = self.lang(name + '.'),
  7812. html = '<div style="padding:20px;">' +
  7813. '<div class="ke-dialog-row">' +
  7814. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7815. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7816. '<div class="ke-dialog-row"">' +
  7817. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7818. '<select id="keType" name="type"></select>' +
  7819. '</div>' +
  7820. '</div>',
  7821. dialog = self.createDialog({
  7822. name : name,
  7823. width : 450,
  7824. title : self.lang(name),
  7825. body : html,
  7826. yesBtn : {
  7827. name : self.lang('yes'),
  7828. click : function(e) {
  7829. var url = K.trim(urlBox.val());
  7830. if (url == 'http://' || K.invalidUrl(url)) {
  7831. alert(self.lang('invalidUrl'));
  7832. urlBox[0].focus();
  7833. return;
  7834. }
  7835. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7836. }
  7837. }
  7838. }),
  7839. div = dialog.div,
  7840. urlBox = K('input[name="url"]', div),
  7841. typeBox = K('select[name="type"]', div);
  7842. urlBox.val('http://');
  7843. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7844. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7845. self.cmd.selection();
  7846. var a = self.plugin.getSelectedLink();
  7847. if (a) {
  7848. self.cmd.range.selectNode(a[0]);
  7849. //self.cmd.select();
  7850. urlBox.val(a.attr('data-ke-src'));
  7851. typeBox.val(a.attr('target'));
  7852. }
  7853. urlBox[0].focus();
  7854. urlBox[0].select();
  7855. },
  7856. 'delete' : function() {
  7857. self.exec('unlink', null);
  7858. }
  7859. };
  7860. self.clickToolbar(name, self.plugin.link.edit);
  7861. });
  7862. /*******************************************************************************
  7863. * KindEditor - WYSIWYG HTML Editor for Internet
  7864. * Copyright (C) 2006-2011 kindsoft.net
  7865. *
  7866. * @author Roddy <luolonghao@gmail.com>
  7867. * @site http://www.kindsoft.net/
  7868. * @licence http://www.kindsoft.net/license.php
  7869. *******************************************************************************/
  7870. KindEditor.plugin('media', function(K) {
  7871. var self = this, name = 'media', lang = self.lang(name + '.'),
  7872. allowFileUpload = K.undef(self.allowFileUpload, true),
  7873. allowFileManager = K.undef(self.allowFileManager, false),
  7874. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7875. allowFileManager = K.undef(self.allowFileManager, false),
  7876. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7877. extraParams = K.undef(self.extraFileUploadParams, {}),
  7878. uploadCoverJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7879. filePostName = K.undef(self.filePostName, 'imgFile'),
  7880. uploadJson = K.undef(self.uploadMediaJson, self.basePath + 'php/upload_json.php');
  7881. if (self.uploadYunJson && self.uploadYunJson.domain) {
  7882. uploadJson = self.uploadYunJson.domain;
  7883. extraParams.token = self.uploadYunJson.token;
  7884. extraParams.key = self.uploadYunJson.path;
  7885. }
  7886. self.plugin.media = {
  7887. edit : function() {
  7888. var html = [
  7889. '<div style="padding:20px;">',
  7890. '<div class="ke-dialog-row">',
  7891. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7892. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7893. '<input type="button" class="ke-upload-button ke-upload-button-media" value="' + lang.upload + '" /> &nbsp;',
  7894. '<span class="ke-button-common ke-button-outer">',
  7895. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7896. '</span>',
  7897. '</div>',
  7898. '<div class="ke-dialog-row">',
  7899. '<label for="keWidth" style="width:60px;">标题</label>',
  7900. '<input type="text" id="keName" class="ke-input-text" style="width:160px;" name="name" value="" maxlength="30" />&nbsp;&nbsp;&nbsp;宽高:<input type="text" id="keWh" class="ke-input-text" style="width:100px;" name="wh" value="200px*200px" maxlength="100" />',
  7901. '</div>',
  7902. '<div class="ke-dialog-row">',
  7903. '<label for="keUrl" style="width:60px;">封面</label>',
  7904. '<input class="ke-input-text" type="text" id="keUrlCover" name="cover_url" value="" style="width:160px;" /> &nbsp;',
  7905. '<input type="button" class="ke-upload-button ke-upload-button-cover" value="' + lang.upload + '" /> &nbsp;',
  7906. '<span class="ke-button-common ke-button-outer">',
  7907. '<input type="button" class="ke-button-common ke-button" name="viewCoverServer" value="' + lang.viewServer + '" />',
  7908. '</span>',
  7909. '<br /><br />(封面要求:音频封面图片尺寸200*200px或等比尺寸,视频封面图片尺寸为视频实际尺寸或者等比尺寸,上传大小不能超过2M,建议上传JPG格式)',
  7910. '</div>',
  7911. '<div class="ke-dialog-row" style="display:none;">',
  7912. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7913. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="200" maxlength="4" />',
  7914. '<div style="display: inline;margin-left: 20px;">',
  7915. '<label for="keHeight" >' + lang.height + '</label>',
  7916. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="200" maxlength="4" />',
  7917. '</div>',
  7918. '</div>',
  7919. '<div class="ke-dialog-row" style="display:none;">',
  7920. '<label for="keAutostart">' + lang.autostart + '</label>',
  7921. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7922. '</div>',
  7923. '</div>'
  7924. ].join('');
  7925. var dialog = self.createDialog({
  7926. name : name,
  7927. width : 450,
  7928. height : 230,
  7929. title : self.lang(name),
  7930. body : html,
  7931. yesBtn : {
  7932. name : self.lang('yes'),
  7933. click : function(e) {
  7934. var url = K.trim(urlBox.val()),
  7935. coverUrl = K.trim(coverUrlBox.val()),
  7936. name = nameBox.val(),
  7937. wh = whBox.val(),
  7938. width = widthBox.val(),
  7939. height = heightBox.val();
  7940. var temp = wh.split('*');
  7941. width = temp[0];
  7942. height = temp[1];
  7943. if (url == 'http://' || K.invalidUrl(url)) {
  7944. alert(self.lang('invalidUrl'));
  7945. urlBox[0].focus();
  7946. return;
  7947. }
  7948. if (!name) {
  7949. alert('请填写标题');
  7950. urlBox[0].focus();
  7951. return;
  7952. }
  7953. if (!wh) {
  7954. alert('请填写宽高');
  7955. urlBox[0].focus();
  7956. return;
  7957. }
  7958. if (coverUrl == 'http://' || K.invalidUrl(coverUrl)) {
  7959. alert('请上传封面');
  7960. urlBox[0].focus();
  7961. return;
  7962. }
  7963. /*
  7964. if (!/^\d*$/.test(width)) {
  7965. alert(self.lang('invalidWidth'));
  7966. widthBox[0].focus();
  7967. return;
  7968. }
  7969. if (!/^\d*$/.test(height)) {
  7970. alert(self.lang('invalidHeight'));
  7971. heightBox[0].focus();
  7972. return;
  7973. }
  7974. */
  7975. if (!coverUrl) {
  7976. var cover = self.themesPath + 'common/blank.gif';
  7977. } else {
  7978. var cover = coverUrl;
  7979. }
  7980. /*
  7981. var html = K.mediaImg(cover, {
  7982. src : url,
  7983. type : K.mediaType(url),
  7984. width : width,
  7985. height : height,
  7986. autostart : autostartBox[0].checked ? 'true' : 'false',
  7987. loop : 'true'
  7988. });
  7989. */
  7990. var html = '<img src="'+cover+'" style="width:'+width+';height:'+height+';" data-file="'+url+'||'+name+'||'+wh+'"/>';
  7991. self.insertHtml(html).hideDialog().focus();
  7992. }
  7993. }
  7994. }),
  7995. div = dialog.div,
  7996. nameBox = K('[name="name"]', div),
  7997. whBox = K('[name="wh"]', div),
  7998. coverUrlBox = K('[name="cover_url"]', div),
  7999. viewCoverServerBtn = K('[name="viewCoverServer"]', div),
  8000. urlBox = K('[name="url"]', div),
  8001. viewServerBtn = K('[name="viewServer"]', div),
  8002. widthBox = K('[name="width"]', div),
  8003. heightBox = K('[name="height"]', div),
  8004. autostartBox = K('[name="autostart"]', div);
  8005. urlBox.val('http://');
  8006. coverUrlBox.val('http://');
  8007. if (allowMediaUpload) {
  8008. var uploadbutton = K.uploadbutton({
  8009. button : K('.ke-upload-button-media', div)[0],
  8010. fieldName : filePostName,
  8011. extraParams : extraParams,
  8012. url : K.addParam(uploadJson, 'dir=media'),
  8013. afterUpload : function(data) {
  8014. console.info(data);
  8015. dialog.hideLoading();
  8016. if (data.error === 0) {
  8017. var url = data.url;
  8018. if (formatUploadUrl) {
  8019. url = K.formatUrl(url, 'absolute');
  8020. }
  8021. urlBox.val(url);
  8022. if (self.afterUpload) {
  8023. self.afterUpload.call(self, url, data, name);
  8024. }
  8025. alert(self.lang('uploadSuccess'));
  8026. } else {
  8027. alert(data.message);
  8028. }
  8029. },
  8030. afterError : function(html) {
  8031. dialog.hideLoading();
  8032. self.errorDialog(html);
  8033. }
  8034. });
  8035. uploadbutton.fileBox.change(function(e) {
  8036. dialog.showLoading(self.lang('uploadLoading'));
  8037. uploadbutton.submit(this);
  8038. });
  8039. } else {
  8040. K('.ke-upload-button-media', div).hide();
  8041. }
  8042. if (allowFileUpload) {
  8043. var uploadbuttonCover = K.uploadbutton({
  8044. button : K('.ke-upload-button-cover', div)[0],
  8045. fieldName : filePostName,
  8046. url : K.addParam(uploadCoverJson, 'dir=file'),
  8047. extraParams : extraParams,
  8048. afterUpload : function(data) {
  8049. dialog.hideLoading();
  8050. if (data.error === 0) {
  8051. var url = data.url;
  8052. if (formatUploadUrl) {
  8053. url = K.formatUrl(url, 'absolute');
  8054. }
  8055. coverUrlBox.val(url);
  8056. if (self.afterUpload) {
  8057. self.afterUpload.call(self, url, data, name);
  8058. }
  8059. alert(self.lang('uploadSuccess'));
  8060. } else {
  8061. alert(data.message);
  8062. }
  8063. },
  8064. afterError : function(html) {
  8065. dialog.hideLoading();
  8066. self.errorDialog(html);
  8067. }
  8068. });
  8069. uploadbuttonCover.fileBox.change(function(e) {
  8070. dialog.showLoading(self.lang('uploadLoading'));
  8071. uploadbuttonCover.submit();
  8072. });
  8073. } else {
  8074. K('.ke-upload-button-cover', div).hide();
  8075. }
  8076. if (allowFileManager) {
  8077. viewServerBtn.click(function(e) {
  8078. var clickFn = function(url, title, id) {
  8079. K('[name="url"]', div).val(url);
  8080. if (self.afterSelectFile) {
  8081. self.afterSelectFile.call(self, url);
  8082. }
  8083. };
  8084. var cur = K('[name="url"]', div).val();
  8085. editorShowUpload(cur, self.mediaManagerJson, '音频库', clickFn, this);
  8086. /*
  8087. self.loadPlugin('filemanager', function() {
  8088. self.plugin.filemanagerDialog({
  8089. viewType : 'LIST',
  8090. dirName : 'media',
  8091. clickFn : function(url, title) {
  8092. if (self.dialogs.length > 1) {
  8093. K('[name="url"]', div).val(url);
  8094. if (self.afterSelectFile) {
  8095. self.afterSelectFile.call(self, url);
  8096. }
  8097. self.hideDialog();
  8098. }
  8099. }
  8100. });
  8101. });
  8102. */
  8103. });
  8104. viewCoverServerBtn.click(function(e) {
  8105. var clickFn = function(url, title, id) {
  8106. coverUrlBox.val(url);
  8107. if (self.afterSelectFile) {
  8108. self.afterSelectFile.call(self, url);
  8109. }
  8110. };
  8111. var cur = coverUrlBox.val();
  8112. editorShowUpload(cur, self.fileManagerJson, '图库', clickFn, this);
  8113. /*
  8114. self.loadPlugin('filemanager', function() {
  8115. self.plugin.filemanagerDialog({
  8116. viewType : 'LIST',
  8117. dirName : 'file',
  8118. clickFn : function(url, title) {
  8119. if (self.dialogs.length > 1) {
  8120. self.hideDialog();
  8121. }
  8122. }
  8123. });
  8124. });
  8125. */
  8126. });
  8127. } else {
  8128. viewServerBtn.hide();
  8129. viewCoverServerBtn.hide();
  8130. }
  8131. var img = self.plugin.getSelectedMedia();
  8132. if (img) {
  8133. if (img.attr('data-file')) {
  8134. var temp = img.attr('data-file').split('||');
  8135. nameBox.val(temp[1]);
  8136. whBox.val(temp[2]);
  8137. urlBox.val(temp[0]);
  8138. coverUrlBox.val(img.attr('src'));
  8139. } else {
  8140. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  8141. urlBox.val(attrs.src);
  8142. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  8143. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  8144. autostartBox[0].checked = (attrs.autostart === 'true');
  8145. }
  8146. }
  8147. urlBox[0].focus();
  8148. urlBox[0].select();
  8149. },
  8150. 'delete' : function() {
  8151. self.plugin.getSelectedMedia().remove();
  8152. self.addBookmark();
  8153. }
  8154. };
  8155. self.clickToolbar(name, self.plugin.media.edit);
  8156. });
  8157. /*******************************************************************************
  8158. * KindEditor - WYSIWYG HTML Editor for Internet
  8159. * Copyright (C) 2006-2011 kindsoft.net
  8160. *
  8161. * @author Roddy <luolonghao@gmail.com>
  8162. * @site http://www.kindsoft.net/
  8163. * @licence http://www.kindsoft.net/license.php
  8164. *******************************************************************************/
  8165. (function (K) {
  8166. var ZYFILE = {
  8167. fileInput: null, // 选择文件按钮dom对象
  8168. uploadInput: null, // 上传文件按钮dom对象
  8169. dragDrop: null, //拖拽敏感区域
  8170. url: "", // 上传action路径
  8171. filePostName: "imgFile", // 上传action路径
  8172. uploadFile: [], // 需要上传的文件数组
  8173. lastUploadFile: [], // 上一次选择的文件数组,方便继续上传使用
  8174. perUploadFile: [], // 存放永久的文件数组,方便删除使用
  8175. fileNum: 0, // 代表文件总个数,因为涉及到继续添加,所以下一次添加需要在它的基础上添加索引
  8176. /* 提供给外部的接口 */
  8177. filterFile: function (files) { // 提供给外部的过滤文件格式等的接口,外部需要把过滤后的文件返回
  8178. return files;
  8179. },
  8180. onSelect: function (selectFile, files) { // 提供给外部获取选中的文件,供外部实现预览等功能 selectFile:当前选中的文件 allFiles:还没上传的全部文件
  8181. },
  8182. onDelete: function (file, files) { // 提供给外部获取删除的单个文件,供外部实现删除效果 file:当前删除的文件 files:删除之后的文件
  8183. },
  8184. onProgress: function (file, loaded, total) { // 提供给外部获取单个文件的上传进度,供外部实现上传进度效果
  8185. },
  8186. onSuccess: function (file, responseInfo) { // 提供给外部获取单个文件上传成功,供外部实现成功效果
  8187. },
  8188. onFailure: function (file, responseInfo) { // 提供给外部获取单个文件上传失败,供外部实现失败效果
  8189. },
  8190. onComplete: function (responseInfo) { // 提供给外部获取全部文件上传完成,供外部实现完成效果
  8191. },
  8192. /* 内部实现功能方法 */
  8193. // 获得选中的文件
  8194. //文件拖放
  8195. funDragHover: function (e) {
  8196. e.stopPropagation();
  8197. e.preventDefault();
  8198. this[e.type === "dragover" ? "onDragOver" : "onDragLeave"].call(e.target);
  8199. return this;
  8200. },
  8201. // 获取文件
  8202. funGetFiles: function (e) {
  8203. var self = this;
  8204. // 取消鼠标经过样式
  8205. this.funDragHover(e);
  8206. // 从事件中获取选中的所有文件
  8207. var files = e.target.files || e.dataTransfer.files;
  8208. self.lastUploadFile = this.uploadFile;
  8209. this.uploadFile = this.uploadFile.concat(this.filterFile(files));
  8210. var tmpFiles = [];
  8211. // 因为jquery的inArray方法无法对object数组进行判断是否存在于,所以只能提取名称进行判断
  8212. var lArr = []; // 之前文件的名称数组
  8213. var uArr = []; // 现在文件的名称数组
  8214. $.each(self.lastUploadFile, function (k, v) {
  8215. lArr.push(v.name);
  8216. });
  8217. $.each(self.uploadFile, function (k, v) {
  8218. uArr.push(v.name);
  8219. });
  8220. $.each(uArr, function (k, v) {
  8221. // 获得当前选择的每一个文件 判断当前这一个文件是否存在于之前的文件当中
  8222. if ($.inArray(v, lArr) < 0) { // 不存在
  8223. tmpFiles.push(self.uploadFile[k]);
  8224. }
  8225. });
  8226. // 如果tmpFiles进行过过滤上一次选择的文件的操作,需要把过滤后的文件赋值
  8227. //if(tmpFiles.length!=0){
  8228. this.uploadFile = tmpFiles;
  8229. //}
  8230. // 调用对文件处理的方法
  8231. this.funDealtFiles();
  8232. return true;
  8233. },
  8234. // 处理过滤后的文件,给每个文件设置下标
  8235. funDealtFiles: function () {
  8236. var self = this;
  8237. // 目前是遍历所有的文件,给每个文件增加唯一索引值
  8238. $.each(this.uploadFile, function (k, v) {
  8239. // 因为涉及到继续添加,所以下一次添加需要在总个数的基础上添加
  8240. v.index = self.fileNum;
  8241. // 添加一个之后自增
  8242. self.fileNum++;
  8243. });
  8244. // 先把当前选中的文件保存备份
  8245. var selectFile = this.uploadFile;
  8246. // 要把全部的文件都保存下来,因为删除所使用的下标是全局的变量
  8247. this.perUploadFile = this.perUploadFile.concat(this.uploadFile);
  8248. // 合并下上传的文件
  8249. this.uploadFile = this.lastUploadFile.concat(this.uploadFile);
  8250. // 执行选择回调
  8251. this.onSelect(selectFile, this.uploadFile);
  8252. return this;
  8253. },
  8254. // 处理需要删除的文件 isCb代表是否回调onDelete方法
  8255. // 因为上传完成并不希望在页面上删除div,但是单独点击删除的时候需要删除div 所以用isCb做判断
  8256. funDeleteFile: function (delFileIndex, isCb) {
  8257. var self = this; // 在each中this指向没个v 所以先将this保留
  8258. var tmpFile = []; // 用来替换的文件数组
  8259. // 合并下上传的文件
  8260. var delFile = this.perUploadFile[delFileIndex];
  8261. // 目前是遍历所有的文件,对比每个文件 删除
  8262. $.each(this.uploadFile, function (k, v) {
  8263. if (delFile != v) {
  8264. // 如果不是删除的那个文件 就放到临时数组中
  8265. tmpFile.push(v);
  8266. }
  8267. });
  8268. this.uploadFile = tmpFile;
  8269. if (isCb) { // 执行回调
  8270. // 回调删除方法,供外部进行删除效果的实现
  8271. self.onDelete(delFile, this.uploadFile);
  8272. }
  8273. return true;
  8274. },
  8275. // 上传多个文件
  8276. funUploadFiles: function () {
  8277. var self = this; // 在each中this指向没个v 所以先将this保留
  8278. // 遍历所有文件 ,在调用单个文件上传的方法
  8279. $.each(this.uploadFile, function (k, v) {
  8280. self.funUploadFile(v);
  8281. });
  8282. },
  8283. // 上传单个个文件
  8284. funUploadFile: function (file) {
  8285. var self = this; // 在each中this指向没个v 所以先将this保留
  8286. var formdata = new FormData();
  8287. formdata.append(self.filePostName, file);
  8288. var xhr = new XMLHttpRequest();
  8289. // 绑定上传事件
  8290. // 进度
  8291. xhr.upload.addEventListener("progress", function (e) {
  8292. // 回调到外部
  8293. self.onProgress(file, e.loaded, e.total);
  8294. }, false);
  8295. // 完成
  8296. xhr.addEventListener("load", function (e) {
  8297. // 从文件中删除上传成功的文件 false是不执行onDelete回调方法
  8298. self.funDeleteFile(file.index, false);
  8299. // 回调到外部
  8300. self.onSuccess(file, xhr.responseText);
  8301. if (self.uploadFile.length == 0) {
  8302. // 回调全部完成方法
  8303. self.onComplete("全部完成");
  8304. }
  8305. }, false);
  8306. // 错误
  8307. xhr.addEventListener("error", function (e) {
  8308. // 回调到外部
  8309. self.onFailure(file, xhr.responseText);
  8310. }, false);
  8311. xhr.open("POST", self.url, true);
  8312. //xhr.setRequestHeader("X_FILENAME", file.name);
  8313. xhr.send(formdata);
  8314. },
  8315. // 返回需要上传的文件
  8316. funReturnNeedFiles: function () {
  8317. return this.uploadFile;
  8318. },
  8319. // 初始化
  8320. init: function () { // 初始化方法,在此给选择、上传按钮绑定事件
  8321. var self = this; // 克隆一个自身
  8322. self.uploadFile = []; // 需要上传的文件数组
  8323. self.lastUploadFile = []; // 上一次选择的文件数组,方便继续上传使用
  8324. self.perUploadFile = []; // 存放永久的文件数组,方便删除使用
  8325. self.fileNum = 0; // 代表文件总个数,因为涉及到继续添加,所以下一次添加需要在它的基础上添加索引
  8326. if (this.dragDrop) {
  8327. this.dragDrop.addEventListener("dragover", function (e) { self.funDragHover(e); }, false);
  8328. this.dragDrop.addEventListener("dragleave", function (e) { self.funDragHover(e); }, false);
  8329. this.dragDrop.addEventListener("drop", function (e) { self.funGetFiles(e); }, false);
  8330. }
  8331. // 如果选择按钮存在
  8332. if (self.fileInput) {
  8333. // 绑定change事件
  8334. this.fileInput.addEventListener("change", function (e) {
  8335. self.funGetFiles(e);
  8336. self.funUploadFiles(e);
  8337. this.value = '';
  8338. }, false);
  8339. }
  8340. // 如果上传按钮存在
  8341. if (self.uploadInput) {
  8342. // 绑定click事件
  8343. /*
  8344. this.uploadInput.addEventListener("click", function (e) {
  8345. self.funUploadFiles(e);
  8346. }, false);
  8347. */
  8348. }
  8349. }
  8350. };
  8351. $.fn.zyUpload = function (options, param) {
  8352. var otherArgs = Array.prototype.slice.call(arguments, 1);
  8353. if (typeof options == 'string') {
  8354. var fn = this[0][options];
  8355. if ($.isFunction(fn)) {
  8356. return fn.apply(this, otherArgs);
  8357. } else {
  8358. throw ("zyUpload - No such method: " + options);
  8359. }
  8360. }
  8361. return this.each(function () {
  8362. var para = {}; // 保留参数
  8363. var self = this; // 保存组件对象
  8364. var defaults = {
  8365. itemWidth: "140px", // 文件项的宽度
  8366. itemHeight: "120px", // 文件项的高度
  8367. url: "/upload/UploadAction", // 上传文件的路径
  8368. filePostName: "imgFile", // name值
  8369. multiple: true, // 是否可以多个文件上传
  8370. dragDrop: true, // 是否可以拖动上传文件
  8371. del: true, // 是否可以删除文件
  8372. finishDel: false, // 是否在上传文件完成后删除预览
  8373. /* 提供给外部的接口方法 */
  8374. onSelect: function (selectFiles, files) { },// 选择文件的回调方法 selectFile:当前选中的文件 allFiles:还没上传的全部文件
  8375. onDelete: function (file, files) { }, // 删除一个文件的回调方法 file:当前删除的文件 files:删除之后的文件
  8376. onSuccess: function (file) { }, // 文件上传成功的回调方法
  8377. onFailure: function (file) { }, // 文件上传失败的回调方法
  8378. onComplete: function (responseInfo) { }, // 上传完成的回调方法
  8379. };
  8380. para = $.extend(defaults, options);
  8381. this.init = function () {
  8382. this.createHtml(); // 创建组件html
  8383. this.createCorePlug(); // 调用核心js
  8384. };
  8385. /**
  8386. * 功能:创建上传所使用的html
  8387. * 参数: 无
  8388. * 返回: 无
  8389. */
  8390. this.createHtml = function () {
  8391. var multiple = ""; // 设置多选的参数
  8392. para.multiple ? multiple = "multiple" : multiple = "";
  8393. var html = '';
  8394. html += [
  8395. '<div class="ke-swfupload">',
  8396. '<div class="ke-swfupload-top">',
  8397. '<div class="ke-inline-block ke-swfupload-button">',
  8398. '<span class="ke-button-common ke-button-outer">',
  8399. '<input type="button" class="ke-button-common ke-button webuploader_pick" value="选择文件" />',
  8400. '</span>',
  8401. '</div>',
  8402. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '<span class="status_info"></span></div>',
  8403. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  8404. '<input type="button" class="ke-button-common ke-button upload_btn" style="display:none;" value="' + options.startButtonValue + '" />',
  8405. '</span>',
  8406. '</div>',
  8407. '<div class="ke-swfupload-body upload_preview preview"></div>',
  8408. '</div>',
  8409. '<form class="uploadForm" action="' + para.url + '" method="post" enctype="multipart/form-data">',
  8410. '<input class="fileImage" style="display:none;" type="file" size="30" name="fileImage" ' + multiple + '>',
  8411. '<button type="button" class="upload_submit_btn fileSubmit" style="display:none">确认上传文件</button>',
  8412. '</form>',
  8413. ].join('');
  8414. $(self).append(html);
  8415. $(self).data('uploadList', []);
  8416. // 初始化html之后绑定按钮的点击事件
  8417. this.addEvent();
  8418. };
  8419. /**
  8420. * 功能:显示统计信息和绑定继续上传和上传按钮的点击事件
  8421. * 参数: 无
  8422. * 返回: 无
  8423. */
  8424. this.funSetStatusInfo = function (files) {
  8425. return ;
  8426. };
  8427. /**
  8428. * 功能:过滤上传的文件格式等
  8429. * 参数: files 本次选择的文件
  8430. * 返回: 通过的文件
  8431. */
  8432. this.funFilterEligibleFile = function (files) {
  8433. var arrFiles = []; // 替换的文件数组
  8434. for (var i = 0, file; file = files[i]; i++) {
  8435. if (file.size >= 51200000) {
  8436. alert('您这个"' + file.name + '"文件大小过大');
  8437. } else {
  8438. // 在这里需要判断当前所有文件中
  8439. arrFiles.push(file);
  8440. }
  8441. }
  8442. return arrFiles;
  8443. };
  8444. /**
  8445. * 功能: 处理参数和格式上的预览html
  8446. * 参数: files 本次选择的文件
  8447. * 返回: 预览的html
  8448. */
  8449. this.funDisposePreviewHtml = function (file, e) {
  8450. var html = "";
  8451. var imgWidth = parseInt(para.itemWidth.replace("px", "")) - 5;
  8452. // 处理配置参数删除按钮
  8453. var delHtml = "";
  8454. if (para.del) { // 显示删除按钮
  8455. delHtml = '<span class="file_del" data-index="' + file.index + '" title="删除"></span>';
  8456. }
  8457. // 处理不同类型文件代表的图标
  8458. var fileImgSrc = "control/images/fileType/";
  8459. if (file.type.indexOf("rar") > 0) {
  8460. fileImgSrc = fileImgSrc + "rar.png";
  8461. } else if (file.type.indexOf("zip") > 0) {
  8462. fileImgSrc = fileImgSrc + "zip.png";
  8463. } else if (file.type.indexOf("text") > 0) {
  8464. fileImgSrc = fileImgSrc + "txt.png";
  8465. } else {
  8466. fileImgSrc = fileImgSrc + "file.png";
  8467. }
  8468. // 图片上传的是图片还是其他类型文件
  8469. if (file.type.indexOf("image") == 0) {
  8470. html += '<div class="upload_append_list uploadList_' + file.index + '">';
  8471. html += ' <div class="file_bar">';
  8472. html += ' <div style="padding:5px;">';
  8473. html += ' <p class="file_name">' + file.name + '</p>';
  8474. html += delHtml; // 删除按钮的html
  8475. html += ' </div>';
  8476. html += ' </div>';
  8477. html += ' <a style="width:' + para.itemWidth + ';height:' + para.itemHeight + ';line-height:' + para.itemHeight + ';" href="#" >';
  8478. html += ' <img class="upload_image uploadImage_' + file.index + '" style="width:100px;" src="' + e.target.result + '"/>';
  8479. /* html += ' <div class="uploadImg" style="width:'+para.itemWidth+'px;)">';
  8480. html += ' </div>'; */
  8481. html += ' </a>';
  8482. html += ' <p class="file_progress uploadProgress_' + file.index + '" ></p>';
  8483. //html += ' <p class="file_failure uploadFailure_' + file.index + '" >上传失败,请重试</p>';
  8484. html += ' <p class="file_success uploadSuccess_' + file.index + '" ></p>';
  8485. html += '</div>';
  8486. } else {
  8487. html += '<div class="upload_append_list uploadList_' + file.index + '">';
  8488. html += ' <div class="file_bar">';
  8489. html += ' <div style="padding:5px;">';
  8490. html += ' <p class="file_name">' + file.name + '</p>';
  8491. html += delHtml; // 删除按钮的html
  8492. html += ' </div>';
  8493. html += ' </div>';
  8494. html += ' <a style="width:' + para.itemWidth + ';height:' + para.itemHeight + ';line-height:' + para.itemHeight + ';" href="#" >';
  8495. html += ' <img class="upload_image uploadImage_' + file.index + '" src="' + fileImgSrc + '"/>';
  8496. html += ' </a>';
  8497. html += ' <p class="file_progress uploadProgress_' + file.index + '" ></p>';
  8498. html += ' <p class="file_failure uploadFailure_' + file.index + '" >上传失败,请重试</p>';
  8499. html += ' <p class="file_success uploadSuccess_' + file.index + '" ></p>';
  8500. html += '</div>';
  8501. }
  8502. return html;
  8503. };
  8504. /**
  8505. * 功能:调用核心插件
  8506. * 参数: 无
  8507. * 返回: 无
  8508. */
  8509. this.createCorePlug = function () {
  8510. var params = {
  8511. fileInput: $(self).find(".fileImage").get(0),
  8512. uploadInput: $(self).find(".fileSubmit").get(0),
  8513. dragDrop: $(self).find(".fileDragArea").get(0),
  8514. url: $(self).find(".uploadForm").attr("action"),
  8515. filePostName: para.filePostName,
  8516. filterFile: function (files) {
  8517. // 过滤合格的文件
  8518. return self.funFilterEligibleFile(files);
  8519. },
  8520. onSelect: function (selectFiles, allFiles) {
  8521. para.onSelect(selectFiles, allFiles); // 回调方法
  8522. self.funSetStatusInfo(ZYFILE.funReturnNeedFiles()); // 显示统计信息
  8523. var html = '', i = 0;
  8524. // 组织预览html
  8525. var funDealtPreviewHtml = function () {
  8526. file = selectFiles[i];
  8527. if (file) {
  8528. var reader = new FileReader()
  8529. reader.onload = function (e) {
  8530. // 处理下配置参数和格式的html
  8531. html += self.funDisposePreviewHtml(file, e);
  8532. i++;
  8533. // 再接着调用此方法递归组成可以预览的html
  8534. funDealtPreviewHtml();
  8535. }
  8536. reader.readAsDataURL(file);
  8537. } else {
  8538. // 走到这里说明文件html已经组织完毕,要把html添加到预览区
  8539. funAppendPreviewHtml(html);
  8540. }
  8541. };
  8542. // 添加预览html
  8543. var funAppendPreviewHtml = function (html) {
  8544. // 添加到添加按钮前
  8545. $(self).find(".preview").append(html);
  8546. // 绑定删除按钮
  8547. funBindDelEvent();
  8548. funBindHoverEvent();
  8549. };
  8550. // 绑定删除按钮事件
  8551. var funBindDelEvent = function () {
  8552. if ($(self).find(".file_del").length > 0) {
  8553. // 删除方法
  8554. $(self).find(".file_del").click(function () {
  8555. ZYFILE.funDeleteFile(parseInt($(this).attr("data-index")), true);
  8556. return false;
  8557. });
  8558. }
  8559. if ($(self).find(".file_edit").length > 0) {
  8560. // 编辑方法
  8561. $(self).find(".file_edit").click(function () {
  8562. // 调用编辑操作
  8563. //ZYFILE.funEditFile(parseInt($(this).attr("data-index")), true);
  8564. return false;
  8565. });
  8566. }
  8567. };
  8568. // 绑定显示操作栏事件
  8569. var funBindHoverEvent = function () {
  8570. $(self).find(".upload_append_list").hover(
  8571. function (e) {
  8572. $(this).find(".file_bar").addClass("file_hover");
  8573. }, function (e) {
  8574. $(this).find(".file_bar").removeClass("file_hover");
  8575. }
  8576. );
  8577. };
  8578. funDealtPreviewHtml();
  8579. },
  8580. onDelete: function (file, files) {
  8581. // 移除效果
  8582. $(self).find(".uploadList_" + file.index).fadeOut();
  8583. // 重新设置统计栏信息
  8584. self.funSetStatusInfo(files);
  8585. var list = $(self).data('uploadList');
  8586. $.each(list, function (k, v) {
  8587. if (file.index == v.index) {
  8588. list.splice(k, 1);
  8589. }
  8590. })
  8591. },
  8592. onProgress: function (file, loaded, total) {
  8593. var eleProgress = $(self).find(".uploadProgress_" + file.index), percent = (loaded / total * 100).toFixed(2) + '%';
  8594. if (eleProgress.is(":hidden")) {
  8595. eleProgress.show();
  8596. }
  8597. eleProgress.css("width", percent);
  8598. },
  8599. onSuccess: function (file, response) {
  8600. file.res = JSON.parse(response);
  8601. $(self).data('uploadList').push(file);
  8602. $(self).find(".uploadProgress_" + file.index).hide();
  8603. $(self).find(".uploadSuccess_" + file.index).show();
  8604. //$(self).find(".uploadInf").append("<p>上传成功,文件地址是:" + response + "</p>");
  8605. // 根据配置参数确定隐不隐藏上传成功的文件
  8606. if (para.finishDel) {
  8607. // 移除效果
  8608. $(self).find(".uploadList_" + file.index).fadeOut();
  8609. // 重新设置统计栏信息
  8610. self.funSetStatusInfo(ZYFILE.funReturnNeedFiles());
  8611. }
  8612. },
  8613. onFailure: function (file) {
  8614. $(self).find(".uploadProgress_" + file.index).hide();
  8615. $(self).find(".uploadSuccess_" + file.index).show();
  8616. $(self).find(".uploadInf").append("<p>文件" + file.name + "上传失败!</p>");
  8617. //$(self).find(".uploadImage_" + file.index).css("opacity", 0.2);
  8618. },
  8619. onComplete: function (response) {
  8620. },
  8621. onDragOver: function () {
  8622. $(this).addClass("upload_drag_hover");
  8623. },
  8624. onDragLeave: function () {
  8625. $(this).removeClass("upload_drag_hover");
  8626. }
  8627. };
  8628. ZYFILE = $.extend(ZYFILE, params);
  8629. ZYFILE.init();
  8630. };
  8631. /**
  8632. * 功能:绑定事件
  8633. * 参数: 无
  8634. * 返回: 无
  8635. */
  8636. this.addEvent = function () {
  8637. // 如果快捷添加文件按钮存在
  8638. if ($(self).find(".filePicker").length > 0) {
  8639. // 绑定选择事件
  8640. $(self).find(".filePicker").bind("click", function (e) {
  8641. $(self).find(".fileImage").click();
  8642. });
  8643. }
  8644. // 绑定继续添加点击事件
  8645. $(self).find(".webuploader_pick").bind("click", function (e) {
  8646. $(self).find(".fileImage").click();
  8647. });
  8648. // 绑定上传点击事件
  8649. $(self).find(".upload_btn").bind("click", function (e) {
  8650. // 判断当前是否有文件需要上传
  8651. if (ZYFILE.funReturnNeedFiles().length > 0) {
  8652. $(self).find(".fileSubmit").click();
  8653. } else {
  8654. alert("请先选中文件再点击上传");
  8655. }
  8656. });
  8657. // 如果快捷添加文件按钮存在
  8658. if ($(self).find(".rapidAddImg").length > 0) {
  8659. // 绑定添加点击事件
  8660. $(self).find(".rapidAddImg").bind("click", function (e) {
  8661. $(self).find(".fileImage").click();
  8662. });
  8663. }
  8664. };
  8665. // 初始化上传控制层插件
  8666. this.init();
  8667. });
  8668. };
  8669. })(KindEditor);
  8670. KindEditor.plugin('multiimage', function (K) {
  8671. var self = this, name = 'multiimage',
  8672. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8673. uploadJson = K.undef(self.uploadJson, self.basePath + '/Home/Notify/mulUploadImg'),
  8674. imgPath = self.pluginsPath + 'multiimage/images/',
  8675. imageSizeLimit = K.undef(self.imageSizeLimit, '2MB'),
  8676. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8677. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8678. filePostName = K.undef(self.filePostName, 'imgFile'),
  8679. lang = self.lang(name + '.');
  8680. self.plugin.multiImageDialog = function (options) {
  8681. var clickFn = options.clickFn,
  8682. uploadDesc = K.tmpl(lang.uploadDesc, { uploadLimit: imageUploadLimit, sizeLimit: imageSizeLimit });
  8683. var html = [
  8684. '<div style="padding:20px;">',
  8685. '<div class="swfupload">',
  8686. '</div>',
  8687. '</div>'
  8688. ].join('');
  8689. var dialog = self.createDialog({
  8690. name: name,
  8691. width: 650,
  8692. height: 510,
  8693. title: self.lang(name),
  8694. body: html,
  8695. previewBtn: {
  8696. name: lang.insertAll,
  8697. click: function (e) {
  8698. var urlList = [];
  8699. $.each(uploadEle.data('uploadList'), function (k, v) {
  8700. urlList.push({
  8701. url: v.res.url,
  8702. title: v.name,
  8703. });
  8704. })
  8705. clickFn.call(self, urlList);
  8706. }
  8707. },
  8708. yesBtn: {
  8709. name: lang.clearAll,
  8710. click: function (e) {
  8711. uploadEle.find('.file_del').click();
  8712. }
  8713. },
  8714. beforeRemove: function () {
  8715. }
  8716. }),
  8717. div = dialog.div,
  8718. uploadEle = $(div[0]).find('.swfupload').zyUpload({
  8719. itemWidth: "120px", // 文件项的宽度
  8720. itemHeight: "100px", // 文件项的高度
  8721. url: uploadJson, // 上传文件的路径
  8722. multiple: true, // 是否可以多个文件上传
  8723. dragDrop: false, // 是否可以拖动上传文件
  8724. del: true, // 是否可以删除文件
  8725. finishDel: false, // 是否在上传文件完成后删除预览
  8726. uploadDesc: uploadDesc,
  8727. startButtonValue: lang.startUpload,
  8728. filePostName: filePostName,
  8729. /* 外部获得的回调接口 */
  8730. onSelect: function (files, allFiles) { // 选择文件的回调方法
  8731. },
  8732. onDelete: function (file, surplusFiles) { // 删除一个文件的回调方法
  8733. },
  8734. onSuccess: function (file, res) { // 文件上传成功的回调方法
  8735. //zyUpload
  8736. },
  8737. onFailure: function (file) { // 文件上传失败的回调方法
  8738. },
  8739. onComplete: function (responseInfo) { // 上传完成的回调方法
  8740. }
  8741. });
  8742. return dialog;
  8743. };
  8744. self.clickToolbar(name, function () {
  8745. self.plugin.multiImageDialog({
  8746. clickFn: function (urlList) {
  8747. if (urlList.length === 0) {
  8748. return;
  8749. }
  8750. K.each(urlList, function (i, data) {
  8751. if (self.afterUpload) {
  8752. self.afterUpload.call(self, data.url, data, 'multiimage');
  8753. }
  8754. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8755. });
  8756. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  8757. setTimeout(function () {
  8758. self.hideDialog().focus();
  8759. }, 0);
  8760. }
  8761. });
  8762. });
  8763. });
  8764. /* ******************* */
  8765. /* Constructor & Init */
  8766. /* ******************* */
  8767. (function() {
  8768. window.SWFUpload = function (settings) {
  8769. this.initSWFUpload(settings);
  8770. };
  8771. SWFUpload.prototype.initSWFUpload = function (settings) {
  8772. try {
  8773. this.customSettings = {};
  8774. this.settings = settings;
  8775. this.eventQueue = [];
  8776. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8777. this.movieElement = null;
  8778. SWFUpload.instances[this.movieName] = this;
  8779. this.initSettings();
  8780. this.loadFlash();
  8781. this.displayDebugInfo();
  8782. } catch (ex) {
  8783. delete SWFUpload.instances[this.movieName];
  8784. throw ex;
  8785. }
  8786. };
  8787. /* *************** */
  8788. /* Static Members */
  8789. /* *************** */
  8790. SWFUpload.instances = {};
  8791. SWFUpload.movieCount = 0;
  8792. SWFUpload.version = "2.2.0 2009-03-25";
  8793. SWFUpload.QUEUE_ERROR = {
  8794. QUEUE_LIMIT_EXCEEDED : -100,
  8795. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8796. ZERO_BYTE_FILE : -120,
  8797. INVALID_FILETYPE : -130
  8798. };
  8799. SWFUpload.UPLOAD_ERROR = {
  8800. HTTP_ERROR : -200,
  8801. MISSING_UPLOAD_URL : -210,
  8802. IO_ERROR : -220,
  8803. SECURITY_ERROR : -230,
  8804. UPLOAD_LIMIT_EXCEEDED : -240,
  8805. UPLOAD_FAILED : -250,
  8806. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8807. FILE_VALIDATION_FAILED : -270,
  8808. FILE_CANCELLED : -280,
  8809. UPLOAD_STOPPED : -290
  8810. };
  8811. SWFUpload.FILE_STATUS = {
  8812. QUEUED : -1,
  8813. IN_PROGRESS : -2,
  8814. ERROR : -3,
  8815. COMPLETE : -4,
  8816. CANCELLED : -5
  8817. };
  8818. SWFUpload.BUTTON_ACTION = {
  8819. SELECT_FILE : -100,
  8820. SELECT_FILES : -110,
  8821. START_UPLOAD : -120
  8822. };
  8823. SWFUpload.CURSOR = {
  8824. ARROW : -1,
  8825. HAND : -2
  8826. };
  8827. SWFUpload.WINDOW_MODE = {
  8828. WINDOW : "window",
  8829. TRANSPARENT : "transparent",
  8830. OPAQUE : "opaque"
  8831. };
  8832. SWFUpload.completeURL = function(url) {
  8833. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8834. return url;
  8835. }
  8836. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8837. var indexSlash = window.location.pathname.lastIndexOf("/");
  8838. var path;
  8839. if (indexSlash <= 0) {
  8840. path = "/";
  8841. } else {
  8842. path = window.location.pathname.substr(0, indexSlash) + "/";
  8843. }
  8844. return /*currentURL +*/ path + url;
  8845. };
  8846. /* ******************** */
  8847. /* Instance Members */
  8848. /* ******************** */
  8849. SWFUpload.prototype.initSettings = function () {
  8850. this.ensureDefault = function (settingName, defaultValue) {
  8851. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8852. };
  8853. this.ensureDefault("upload_url", "");
  8854. this.ensureDefault("preserve_relative_urls", false);
  8855. this.ensureDefault("file_post_name", "Filedata");
  8856. this.ensureDefault("post_params", {});
  8857. this.ensureDefault("use_query_string", false);
  8858. this.ensureDefault("requeue_on_error", false);
  8859. this.ensureDefault("http_success", []);
  8860. this.ensureDefault("assume_success_timeout", 0);
  8861. this.ensureDefault("file_types", "*.*");
  8862. this.ensureDefault("file_types_description", "All Files");
  8863. this.ensureDefault("file_size_limit", 0);
  8864. this.ensureDefault("file_upload_limit", 0);
  8865. this.ensureDefault("file_queue_limit", 0);
  8866. this.ensureDefault("flash_url", "swfupload.swf");
  8867. this.ensureDefault("prevent_swf_caching", true);
  8868. this.ensureDefault("button_image_url", "");
  8869. this.ensureDefault("button_width", 1);
  8870. this.ensureDefault("button_height", 1);
  8871. this.ensureDefault("button_text", "");
  8872. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8873. this.ensureDefault("button_text_top_padding", 0);
  8874. this.ensureDefault("button_text_left_padding", 0);
  8875. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8876. this.ensureDefault("button_disabled", false);
  8877. this.ensureDefault("button_placeholder_id", "");
  8878. this.ensureDefault("button_placeholder", null);
  8879. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8880. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8881. this.ensureDefault("debug", false);
  8882. this.settings.debug_enabled = this.settings.debug;
  8883. this.settings.return_upload_start_handler = this.returnUploadStart;
  8884. this.ensureDefault("swfupload_loaded_handler", null);
  8885. this.ensureDefault("file_dialog_start_handler", null);
  8886. this.ensureDefault("file_queued_handler", null);
  8887. this.ensureDefault("file_queue_error_handler", null);
  8888. this.ensureDefault("file_dialog_complete_handler", null);
  8889. this.ensureDefault("upload_start_handler", null);
  8890. this.ensureDefault("upload_progress_handler", null);
  8891. this.ensureDefault("upload_error_handler", null);
  8892. this.ensureDefault("upload_success_handler", null);
  8893. this.ensureDefault("upload_complete_handler", null);
  8894. this.ensureDefault("debug_handler", this.debugMessage);
  8895. this.ensureDefault("custom_settings", {});
  8896. this.customSettings = this.settings.custom_settings;
  8897. if (!!this.settings.prevent_swf_caching) {
  8898. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8899. }
  8900. if (!this.settings.preserve_relative_urls) {
  8901. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8902. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8903. }
  8904. delete this.ensureDefault;
  8905. };
  8906. SWFUpload.prototype.loadFlash = function () {
  8907. var targetElement, tempParent;
  8908. if (document.getElementById(this.movieName) !== null) {
  8909. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8910. }
  8911. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8912. if (targetElement == undefined) {
  8913. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8914. }
  8915. tempParent = document.createElement("div");
  8916. tempParent.innerHTML = this.getFlashHTML();
  8917. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8918. if (window[this.movieName] == undefined) {
  8919. window[this.movieName] = this.getMovieElement();
  8920. }
  8921. };
  8922. SWFUpload.prototype.getFlashHTML = function () {
  8923. var classid = '';
  8924. if (KindEditor.IE && KindEditor.V > 8) {
  8925. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8926. }
  8927. 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">',
  8928. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8929. '<param name="movie" value="', this.settings.flash_url, '" />',
  8930. '<param name="quality" value="high" />',
  8931. '<param name="menu" value="false" />',
  8932. '<param name="allowScriptAccess" value="always" />',
  8933. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8934. '</object>'].join("");
  8935. };
  8936. SWFUpload.prototype.getFlashVars = function () {
  8937. var paramString = this.buildParamString();
  8938. var httpSuccessString = this.settings.http_success.join(",");
  8939. return ["movieName=", encodeURIComponent(this.movieName),
  8940. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8941. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8942. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8943. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8944. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8945. "&amp;params=", encodeURIComponent(paramString),
  8946. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8947. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8948. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8949. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8950. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8951. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8952. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8953. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8954. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8955. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8956. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8957. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8958. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8959. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8960. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8961. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8962. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8963. ].join("");
  8964. };
  8965. SWFUpload.prototype.getMovieElement = function () {
  8966. if (this.movieElement == undefined) {
  8967. this.movieElement = document.getElementById(this.movieName);
  8968. }
  8969. if (this.movieElement === null) {
  8970. throw "Could not find Flash element";
  8971. }
  8972. return this.movieElement;
  8973. };
  8974. SWFUpload.prototype.buildParamString = function () {
  8975. var postParams = this.settings.post_params;
  8976. var paramStringPairs = [];
  8977. if (typeof(postParams) === "object") {
  8978. for (var name in postParams) {
  8979. if (postParams.hasOwnProperty(name)) {
  8980. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8981. }
  8982. }
  8983. }
  8984. return paramStringPairs.join("&amp;");
  8985. };
  8986. SWFUpload.prototype.destroy = function () {
  8987. try {
  8988. this.cancelUpload(null, false);
  8989. var movieElement = null;
  8990. movieElement = this.getMovieElement();
  8991. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8992. for (var i in movieElement) {
  8993. try {
  8994. if (typeof(movieElement[i]) === "function") {
  8995. movieElement[i] = null;
  8996. }
  8997. } catch (ex1) {}
  8998. }
  8999. try {
  9000. movieElement.parentNode.removeChild(movieElement);
  9001. } catch (ex) {}
  9002. }
  9003. window[this.movieName] = null;
  9004. SWFUpload.instances[this.movieName] = null;
  9005. delete SWFUpload.instances[this.movieName];
  9006. this.movieElement = null;
  9007. this.settings = null;
  9008. this.customSettings = null;
  9009. this.eventQueue = null;
  9010. this.movieName = null;
  9011. return true;
  9012. } catch (ex2) {
  9013. return false;
  9014. }
  9015. };
  9016. SWFUpload.prototype.displayDebugInfo = function () {
  9017. this.debug(
  9018. [
  9019. "---SWFUpload Instance Info---\n",
  9020. "Version: ", SWFUpload.version, "\n",
  9021. "Movie Name: ", this.movieName, "\n",
  9022. "Settings:\n",
  9023. "\t", "upload_url: ", this.settings.upload_url, "\n",
  9024. "\t", "flash_url: ", this.settings.flash_url, "\n",
  9025. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  9026. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  9027. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  9028. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  9029. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  9030. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  9031. "\t", "file_types: ", this.settings.file_types, "\n",
  9032. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  9033. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  9034. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  9035. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  9036. "\t", "debug: ", this.settings.debug.toString(), "\n",
  9037. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  9038. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  9039. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  9040. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  9041. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  9042. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  9043. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  9044. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  9045. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  9046. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  9047. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  9048. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  9049. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  9050. "Event Handlers:\n",
  9051. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  9052. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  9053. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  9054. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  9055. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  9056. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  9057. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  9058. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  9059. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  9060. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  9061. ].join("")
  9062. );
  9063. };
  9064. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  9065. the maintain v2 API compatibility
  9066. */
  9067. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  9068. if (value == undefined) {
  9069. return (this.settings[name] = default_value);
  9070. } else {
  9071. return (this.settings[name] = value);
  9072. }
  9073. };
  9074. SWFUpload.prototype.getSetting = function (name) {
  9075. if (this.settings[name] != undefined) {
  9076. return this.settings[name];
  9077. }
  9078. return "";
  9079. };
  9080. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  9081. argumentArray = argumentArray || [];
  9082. var movieElement = this.getMovieElement();
  9083. var returnValue, returnString;
  9084. try {
  9085. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  9086. returnValue = eval(returnString);
  9087. } catch (ex) {
  9088. throw "Call to " + functionName + " failed";
  9089. }
  9090. if (returnValue != undefined && typeof returnValue.post === "object") {
  9091. returnValue = this.unescapeFilePostParams(returnValue);
  9092. }
  9093. return returnValue;
  9094. };
  9095. /* *****************************
  9096. -- Flash control methods --
  9097. Your UI should use these
  9098. to operate SWFUpload
  9099. ***************************** */
  9100. SWFUpload.prototype.selectFile = function () {
  9101. this.callFlash("SelectFile");
  9102. };
  9103. SWFUpload.prototype.selectFiles = function () {
  9104. this.callFlash("SelectFiles");
  9105. };
  9106. SWFUpload.prototype.startUpload = function (fileID) {
  9107. this.callFlash("StartUpload", [fileID]);
  9108. };
  9109. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  9110. if (triggerErrorEvent !== false) {
  9111. triggerErrorEvent = true;
  9112. }
  9113. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  9114. };
  9115. SWFUpload.prototype.stopUpload = function () {
  9116. this.callFlash("StopUpload");
  9117. };
  9118. /* ************************
  9119. * Settings methods
  9120. * These methods change the SWFUpload settings.
  9121. * SWFUpload settings should not be changed directly on the settings object
  9122. * since many of the settings need to be passed to Flash in order to take
  9123. * effect.
  9124. * *********************** */
  9125. SWFUpload.prototype.getStats = function () {
  9126. return this.callFlash("GetStats");
  9127. };
  9128. SWFUpload.prototype.setStats = function (statsObject) {
  9129. this.callFlash("SetStats", [statsObject]);
  9130. };
  9131. SWFUpload.prototype.getFile = function (fileID) {
  9132. if (typeof(fileID) === "number") {
  9133. return this.callFlash("GetFileByIndex", [fileID]);
  9134. } else {
  9135. return this.callFlash("GetFile", [fileID]);
  9136. }
  9137. };
  9138. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  9139. return this.callFlash("AddFileParam", [fileID, name, value]);
  9140. };
  9141. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  9142. this.callFlash("RemoveFileParam", [fileID, name]);
  9143. };
  9144. SWFUpload.prototype.setUploadURL = function (url) {
  9145. this.settings.upload_url = url.toString();
  9146. this.callFlash("SetUploadURL", [url]);
  9147. };
  9148. SWFUpload.prototype.setPostParams = function (paramsObject) {
  9149. this.settings.post_params = paramsObject;
  9150. this.callFlash("SetPostParams", [paramsObject]);
  9151. };
  9152. SWFUpload.prototype.addPostParam = function (name, value) {
  9153. this.settings.post_params[name] = value;
  9154. this.callFlash("SetPostParams", [this.settings.post_params]);
  9155. };
  9156. SWFUpload.prototype.removePostParam = function (name) {
  9157. delete this.settings.post_params[name];
  9158. this.callFlash("SetPostParams", [this.settings.post_params]);
  9159. };
  9160. SWFUpload.prototype.setFileTypes = function (types, description) {
  9161. this.settings.file_types = types;
  9162. this.settings.file_types_description = description;
  9163. this.callFlash("SetFileTypes", [types, description]);
  9164. };
  9165. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  9166. this.settings.file_size_limit = fileSizeLimit;
  9167. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  9168. };
  9169. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  9170. this.settings.file_upload_limit = fileUploadLimit;
  9171. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  9172. };
  9173. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  9174. this.settings.file_queue_limit = fileQueueLimit;
  9175. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  9176. };
  9177. SWFUpload.prototype.setFilePostName = function (filePostName) {
  9178. this.settings.file_post_name = filePostName;
  9179. this.callFlash("SetFilePostName", [filePostName]);
  9180. };
  9181. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  9182. this.settings.use_query_string = useQueryString;
  9183. this.callFlash("SetUseQueryString", [useQueryString]);
  9184. };
  9185. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  9186. this.settings.requeue_on_error = requeueOnError;
  9187. this.callFlash("SetRequeueOnError", [requeueOnError]);
  9188. };
  9189. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  9190. if (typeof http_status_codes === "string") {
  9191. http_status_codes = http_status_codes.replace(" ", "").split(",");
  9192. }
  9193. this.settings.http_success = http_status_codes;
  9194. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  9195. };
  9196. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  9197. this.settings.assume_success_timeout = timeout_seconds;
  9198. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  9199. };
  9200. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  9201. this.settings.debug_enabled = debugEnabled;
  9202. this.callFlash("SetDebugEnabled", [debugEnabled]);
  9203. };
  9204. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  9205. if (buttonImageURL == undefined) {
  9206. buttonImageURL = "";
  9207. }
  9208. this.settings.button_image_url = buttonImageURL;
  9209. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  9210. };
  9211. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  9212. this.settings.button_width = width;
  9213. this.settings.button_height = height;
  9214. var movie = this.getMovieElement();
  9215. if (movie != undefined) {
  9216. movie.style.width = width + "px";
  9217. movie.style.height = height + "px";
  9218. }
  9219. this.callFlash("SetButtonDimensions", [width, height]);
  9220. };
  9221. SWFUpload.prototype.setButtonText = function (html) {
  9222. this.settings.button_text = html;
  9223. this.callFlash("SetButtonText", [html]);
  9224. };
  9225. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  9226. this.settings.button_text_top_padding = top;
  9227. this.settings.button_text_left_padding = left;
  9228. this.callFlash("SetButtonTextPadding", [left, top]);
  9229. };
  9230. SWFUpload.prototype.setButtonTextStyle = function (css) {
  9231. this.settings.button_text_style = css;
  9232. this.callFlash("SetButtonTextStyle", [css]);
  9233. };
  9234. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  9235. this.settings.button_disabled = isDisabled;
  9236. this.callFlash("SetButtonDisabled", [isDisabled]);
  9237. };
  9238. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  9239. this.settings.button_action = buttonAction;
  9240. this.callFlash("SetButtonAction", [buttonAction]);
  9241. };
  9242. SWFUpload.prototype.setButtonCursor = function (cursor) {
  9243. this.settings.button_cursor = cursor;
  9244. this.callFlash("SetButtonCursor", [cursor]);
  9245. };
  9246. /* *******************************
  9247. Flash Event Interfaces
  9248. These functions are used by Flash to trigger the various
  9249. events.
  9250. All these functions a Private.
  9251. Because the ExternalInterface library is buggy the event calls
  9252. are added to a queue and the queue then executed by a setTimeout.
  9253. This ensures that events are executed in a determinate order and that
  9254. the ExternalInterface bugs are avoided.
  9255. ******************************* */
  9256. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  9257. if (argumentArray == undefined) {
  9258. argumentArray = [];
  9259. } else if (!(argumentArray instanceof Array)) {
  9260. argumentArray = [argumentArray];
  9261. }
  9262. var self = this;
  9263. if (typeof this.settings[handlerName] === "function") {
  9264. this.eventQueue.push(function () {
  9265. this.settings[handlerName].apply(this, argumentArray);
  9266. });
  9267. setTimeout(function () {
  9268. self.executeNextEvent();
  9269. }, 0);
  9270. } else if (this.settings[handlerName] !== null) {
  9271. throw "Event handler " + handlerName + " is unknown or is not a function";
  9272. }
  9273. };
  9274. SWFUpload.prototype.executeNextEvent = function () {
  9275. var f = this.eventQueue ? this.eventQueue.shift() : null;
  9276. if (typeof(f) === "function") {
  9277. f.apply(this);
  9278. }
  9279. };
  9280. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  9281. var reg = /[$]([0-9a-f]{4})/i;
  9282. var unescapedPost = {};
  9283. var uk;
  9284. if (file != undefined) {
  9285. for (var k in file.post) {
  9286. if (file.post.hasOwnProperty(k)) {
  9287. uk = k;
  9288. var match;
  9289. while ((match = reg.exec(uk)) !== null) {
  9290. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  9291. }
  9292. unescapedPost[uk] = file.post[k];
  9293. }
  9294. }
  9295. file.post = unescapedPost;
  9296. }
  9297. return file;
  9298. };
  9299. SWFUpload.prototype.testExternalInterface = function () {
  9300. try {
  9301. return this.callFlash("TestExternalInterface");
  9302. } catch (ex) {
  9303. return false;
  9304. }
  9305. };
  9306. SWFUpload.prototype.flashReady = function () {
  9307. var movieElement = this.getMovieElement();
  9308. if (!movieElement) {
  9309. this.debug("Flash called back ready but the flash movie can't be found.");
  9310. return;
  9311. }
  9312. this.cleanUp(movieElement);
  9313. this.queueEvent("swfupload_loaded_handler");
  9314. };
  9315. SWFUpload.prototype.cleanUp = function (movieElement) {
  9316. try {
  9317. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  9318. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  9319. for (var key in movieElement) {
  9320. try {
  9321. if (typeof(movieElement[key]) === "function") {
  9322. movieElement[key] = null;
  9323. }
  9324. } catch (ex) {
  9325. }
  9326. }
  9327. }
  9328. } catch (ex1) {
  9329. }
  9330. window["__flash__removeCallback"] = function (instance, name) {
  9331. try {
  9332. if (instance) {
  9333. instance[name] = null;
  9334. }
  9335. } catch (flashEx) {
  9336. }
  9337. };
  9338. };
  9339. /* This is a chance to do something before the browse window opens */
  9340. SWFUpload.prototype.fileDialogStart = function () {
  9341. this.queueEvent("file_dialog_start_handler");
  9342. };
  9343. /* Called when a file is successfully added to the queue. */
  9344. SWFUpload.prototype.fileQueued = function (file) {
  9345. file = this.unescapeFilePostParams(file);
  9346. this.queueEvent("file_queued_handler", file);
  9347. };
  9348. /* Handle errors that occur when an attempt to queue a file fails. */
  9349. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  9350. file = this.unescapeFilePostParams(file);
  9351. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  9352. };
  9353. /* Called after the file dialog has closed and the selected files have been queued.
  9354. You could call startUpload here if you want the queued files to begin uploading immediately. */
  9355. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  9356. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  9357. };
  9358. SWFUpload.prototype.uploadStart = function (file) {
  9359. file = this.unescapeFilePostParams(file);
  9360. this.queueEvent("return_upload_start_handler", file);
  9361. };
  9362. SWFUpload.prototype.returnUploadStart = function (file) {
  9363. var returnValue;
  9364. if (typeof this.settings.upload_start_handler === "function") {
  9365. file = this.unescapeFilePostParams(file);
  9366. returnValue = this.settings.upload_start_handler.call(this, file);
  9367. } else if (this.settings.upload_start_handler != undefined) {
  9368. throw "upload_start_handler must be a function";
  9369. }
  9370. if (returnValue === undefined) {
  9371. returnValue = true;
  9372. }
  9373. returnValue = !!returnValue;
  9374. this.callFlash("ReturnUploadStart", [returnValue]);
  9375. };
  9376. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  9377. file = this.unescapeFilePostParams(file);
  9378. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  9379. };
  9380. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  9381. file = this.unescapeFilePostParams(file);
  9382. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  9383. };
  9384. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  9385. file = this.unescapeFilePostParams(file);
  9386. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  9387. };
  9388. SWFUpload.prototype.uploadComplete = function (file) {
  9389. file = this.unescapeFilePostParams(file);
  9390. this.queueEvent("upload_complete_handler", file);
  9391. };
  9392. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  9393. internal debug console. You can override this event and have messages written where you want. */
  9394. SWFUpload.prototype.debug = function (message) {
  9395. this.queueEvent("debug_handler", message);
  9396. };
  9397. /* **********************************
  9398. Debug Console
  9399. The debug console is a self contained, in page location
  9400. for debug message to be sent. The Debug Console adds
  9401. itself to the body if necessary.
  9402. The console is automatically scrolled as messages appear.
  9403. If you are using your own debug handler or when you deploy to production and
  9404. have debug disabled you can remove these functions to reduce the file size
  9405. and complexity.
  9406. ********************************** */
  9407. SWFUpload.prototype.debugMessage = function (message) {
  9408. if (this.settings.debug) {
  9409. var exceptionMessage, exceptionValues = [];
  9410. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  9411. for (var key in message) {
  9412. if (message.hasOwnProperty(key)) {
  9413. exceptionValues.push(key + ": " + message[key]);
  9414. }
  9415. }
  9416. exceptionMessage = exceptionValues.join("\n") || "";
  9417. exceptionValues = exceptionMessage.split("\n");
  9418. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  9419. SWFUpload.Console.writeLine(exceptionMessage);
  9420. } else {
  9421. SWFUpload.Console.writeLine(message);
  9422. }
  9423. }
  9424. };
  9425. SWFUpload.Console = {};
  9426. SWFUpload.Console.writeLine = function (message) {
  9427. var console, documentForm;
  9428. try {
  9429. console = document.getElementById("SWFUpload_Console");
  9430. if (!console) {
  9431. documentForm = document.createElement("form");
  9432. document.getElementsByTagName("body")[0].appendChild(documentForm);
  9433. console = document.createElement("textarea");
  9434. console.id = "SWFUpload_Console";
  9435. console.style.fontFamily = "monospace";
  9436. console.setAttribute("wrap", "off");
  9437. console.wrap = "off";
  9438. console.style.overflow = "auto";
  9439. console.style.width = "700px";
  9440. console.style.height = "350px";
  9441. console.style.margin = "5px";
  9442. documentForm.appendChild(console);
  9443. }
  9444. console.value += message + "\n";
  9445. console.scrollTop = console.scrollHeight - console.clientHeight;
  9446. } catch (ex) {
  9447. alert("Exception: " + ex.name + " Message: " + ex.message);
  9448. }
  9449. };
  9450. })();
  9451. (function() {
  9452. /*
  9453. Queue Plug-in
  9454. Features:
  9455. *Adds a cancelQueue() method for cancelling the entire queue.
  9456. *All queued files are uploaded when startUpload() is called.
  9457. *If false is returned from uploadComplete then the queue upload is stopped.
  9458. If false is not returned (strict comparison) then the queue upload is continued.
  9459. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  9460. Set the event handler with the queue_complete_handler setting.
  9461. */
  9462. if (typeof(SWFUpload) === "function") {
  9463. SWFUpload.queue = {};
  9464. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  9465. return function () {
  9466. if (typeof(oldInitSettings) === "function") {
  9467. oldInitSettings.call(this);
  9468. }
  9469. this.queueSettings = {};
  9470. this.queueSettings.queue_cancelled_flag = false;
  9471. this.queueSettings.queue_upload_count = 0;
  9472. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  9473. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  9474. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  9475. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  9476. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  9477. };
  9478. })(SWFUpload.prototype.initSettings);
  9479. SWFUpload.prototype.startUpload = function (fileID) {
  9480. this.queueSettings.queue_cancelled_flag = false;
  9481. this.callFlash("StartUpload", [fileID]);
  9482. };
  9483. SWFUpload.prototype.cancelQueue = function () {
  9484. this.queueSettings.queue_cancelled_flag = true;
  9485. this.stopUpload();
  9486. var stats = this.getStats();
  9487. while (stats.files_queued > 0) {
  9488. this.cancelUpload();
  9489. stats = this.getStats();
  9490. }
  9491. };
  9492. SWFUpload.queue.uploadStartHandler = function (file) {
  9493. var returnValue;
  9494. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  9495. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  9496. }
  9497. returnValue = (returnValue === false) ? false : true;
  9498. this.queueSettings.queue_cancelled_flag = !returnValue;
  9499. return returnValue;
  9500. };
  9501. SWFUpload.queue.uploadCompleteHandler = function (file) {
  9502. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  9503. var continueUpload;
  9504. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  9505. this.queueSettings.queue_upload_count++;
  9506. }
  9507. if (typeof(user_upload_complete_handler) === "function") {
  9508. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  9509. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  9510. continueUpload = false;
  9511. } else {
  9512. continueUpload = true;
  9513. }
  9514. if (continueUpload) {
  9515. var stats = this.getStats();
  9516. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  9517. this.startUpload();
  9518. } else if (this.queueSettings.queue_cancelled_flag === false) {
  9519. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  9520. this.queueSettings.queue_upload_count = 0;
  9521. } else {
  9522. this.queueSettings.queue_cancelled_flag = false;
  9523. this.queueSettings.queue_upload_count = 0;
  9524. }
  9525. }
  9526. };
  9527. }
  9528. })();
  9529. /*******************************************************************************
  9530. * KindEditor - WYSIWYG HTML Editor for Internet
  9531. * Copyright (C) 2006-2011 kindsoft.net
  9532. *
  9533. * @author Roddy <luolonghao@gmail.com>
  9534. * @site http://www.kindsoft.net/
  9535. * @licence http://www.kindsoft.net/license.php
  9536. *******************************************************************************/
  9537. KindEditor.plugin('pagebreak', function(K) {
  9538. var self = this;
  9539. var name = 'pagebreak';
  9540. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  9541. self.clickToolbar(name, function() {
  9542. var cmd = self.cmd, range = cmd.range;
  9543. self.focus();
  9544. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  9545. self.insertHtml(pagebreakHtml + tail);
  9546. if (tail !== '') {
  9547. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9548. range.selectNodeContents(p[0]);
  9549. p.removeAttr('id');
  9550. cmd.select();
  9551. }
  9552. });
  9553. });
  9554. /*******************************************************************************
  9555. * KindEditor - WYSIWYG HTML Editor for Internet
  9556. * Copyright (C) 2006-2011 kindsoft.net
  9557. *
  9558. * @author Roddy <luolonghao@gmail.com>
  9559. * @site http://www.kindsoft.net/
  9560. * @licence http://www.kindsoft.net/license.php
  9561. *******************************************************************************/
  9562. KindEditor.plugin('plainpaste', function(K) {
  9563. var self = this, name = 'plainpaste';
  9564. self.clickToolbar(name, function() {
  9565. var lang = self.lang(name + '.'),
  9566. html = '<div style="padding:10px 20px;">' +
  9567. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9568. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9569. '</div>',
  9570. dialog = self.createDialog({
  9571. name : name,
  9572. width : 450,
  9573. title : self.lang(name),
  9574. body : html,
  9575. yesBtn : {
  9576. name : self.lang('yes'),
  9577. click : function(e) {
  9578. var html = textarea.val();
  9579. html = K.escape(html);
  9580. html = html.replace(/ {2}/g, ' &nbsp;');
  9581. if (self.newlineTag == 'p') {
  9582. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9583. } else {
  9584. html = html.replace(/\n/g, '<br />$&');
  9585. }
  9586. self.insertHtml(html).hideDialog().focus();
  9587. }
  9588. }
  9589. }),
  9590. textarea = K('textarea', dialog.div);
  9591. textarea[0].focus();
  9592. });
  9593. });
  9594. /*******************************************************************************
  9595. * KindEditor - WYSIWYG HTML Editor for Internet
  9596. * Copyright (C) 2006-2011 kindsoft.net
  9597. *
  9598. * @author Roddy <luolonghao@gmail.com>
  9599. * @site http://www.kindsoft.net/
  9600. * @licence http://www.kindsoft.net/license.php
  9601. *******************************************************************************/
  9602. KindEditor.plugin('preview', function(K) {
  9603. var self = this, name = 'preview', undefined;
  9604. self.clickToolbar(name, function() {
  9605. var lang = self.lang(name + '.'),
  9606. html = '<div style="padding:10px 20px;">' +
  9607. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9608. '</div>',
  9609. dialog = self.createDialog({
  9610. name : name,
  9611. width : 750,
  9612. title : self.lang(name),
  9613. body : html
  9614. }),
  9615. iframe = K('iframe', dialog.div),
  9616. doc = K.iframeDoc(iframe);
  9617. doc.open();
  9618. doc.write(self.fullHtml());
  9619. doc.close();
  9620. K(doc.body).css('background-color', '#FFF');
  9621. iframe[0].contentWindow.focus();
  9622. });
  9623. });
  9624. /*******************************************************************************
  9625. * KindEditor - WYSIWYG HTML Editor for Internet
  9626. * Copyright (C) 2006-2011 kindsoft.net
  9627. *
  9628. * @author Roddy <luolonghao@gmail.com>
  9629. * @site http://www.kindsoft.net/
  9630. * @licence http://www.kindsoft.net/license.php
  9631. *******************************************************************************/
  9632. KindEditor.plugin('quickformat', function(K) {
  9633. var self = this, name = 'quickformat',
  9634. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9635. function getFirstChild(knode) {
  9636. var child = knode.first();
  9637. while (child && child.first()) {
  9638. child = child.first();
  9639. }
  9640. return child;
  9641. }
  9642. self.clickToolbar(name, function() {
  9643. self.focus();
  9644. var doc = self.edit.doc,
  9645. range = self.cmd.range,
  9646. child = K(doc.body).first(), next,
  9647. nodeList = [], subList = [],
  9648. bookmark = range.createBookmark(true);
  9649. while(child) {
  9650. next = child.next();
  9651. var firstChild = getFirstChild(child);
  9652. if (!firstChild || firstChild.name != 'img') {
  9653. if (blockMap[child.name]) {
  9654. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9655. child.css('text-indent', '2em');
  9656. } else {
  9657. subList.push(child);
  9658. }
  9659. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9660. if (subList.length > 0) {
  9661. nodeList.push(subList);
  9662. }
  9663. subList = [];
  9664. }
  9665. }
  9666. child = next;
  9667. }
  9668. K.each(nodeList, function(i, subList) {
  9669. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9670. subList[0].before(wrapper);
  9671. K.each(subList, function(i, knode) {
  9672. wrapper.append(knode);
  9673. });
  9674. });
  9675. range.moveToBookmark(bookmark);
  9676. self.addBookmark();
  9677. });
  9678. });
  9679. /*******************************************************************************
  9680. * KindEditor - WYSIWYG HTML Editor for Internet
  9681. * Copyright (C) 2006-2011 kindsoft.net
  9682. *
  9683. * @author Roddy <luolonghao@gmail.com>
  9684. * @site http://www.kindsoft.net/
  9685. * @licence http://www.kindsoft.net/license.php
  9686. *******************************************************************************/
  9687. KindEditor.plugin('table', function(K) {
  9688. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9689. function _setColor(box, color) {
  9690. color = color.toUpperCase();
  9691. box.css('background-color', color);
  9692. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9693. box.html(color);
  9694. }
  9695. var pickerList = [];
  9696. function _initColorPicker(dialogDiv, colorBox) {
  9697. colorBox.bind('click,mousedown', function(e){
  9698. e.stopPropagation();
  9699. });
  9700. function removePicker() {
  9701. K.each(pickerList, function() {
  9702. this.remove();
  9703. });
  9704. pickerList = [];
  9705. K(document).unbind('click,mousedown', removePicker);
  9706. dialogDiv.unbind('click,mousedown', removePicker);
  9707. }
  9708. colorBox.click(function(e) {
  9709. removePicker();
  9710. var box = K(this),
  9711. pos = box.pos();
  9712. var picker = K.colorpicker({
  9713. x : pos.x,
  9714. y : pos.y + box.height(),
  9715. z : 811214,
  9716. selectedColor : K(this).html(),
  9717. colors : self.colorTable,
  9718. noColor : self.lang('noColor'),
  9719. shadowMode : self.shadowMode,
  9720. click : function(color) {
  9721. _setColor(box, color);
  9722. removePicker();
  9723. }
  9724. });
  9725. pickerList.push(picker);
  9726. K(document).bind('click,mousedown', removePicker);
  9727. dialogDiv.bind('click,mousedown', removePicker);
  9728. });
  9729. }
  9730. function _getCellIndex(table, row, cell) {
  9731. var rowSpanCount = 0;
  9732. for (var i = 0, len = row.cells.length; i < len; i++) {
  9733. if (row.cells[i] == cell) {
  9734. break;
  9735. }
  9736. rowSpanCount += row.cells[i].rowSpan - 1;
  9737. }
  9738. return cell.cellIndex - rowSpanCount;
  9739. }
  9740. self.plugin.table = {
  9741. prop : function(isInsert) {
  9742. var html = [
  9743. '<div style="padding:20px;">',
  9744. '<div class="ke-dialog-row">',
  9745. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9746. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9747. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9748. '</div>',
  9749. '<div class="ke-dialog-row">',
  9750. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9751. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9752. '<select name="widthType">',
  9753. '<option value="%">' + lang.percent + '</option>',
  9754. '<option value="px">' + lang.px + '</option>',
  9755. '</select> &nbsp; ',
  9756. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9757. '<select name="heightType">',
  9758. '<option value="%">' + lang.percent + '</option>',
  9759. '<option value="px">' + lang.px + '</option>',
  9760. '</select>',
  9761. '</div>',
  9762. '<div class="ke-dialog-row">',
  9763. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9764. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9765. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9766. '</div>',
  9767. '<div class="ke-dialog-row">',
  9768. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9769. '<select id="keAlign" name="align">',
  9770. '<option value="">' + lang.alignDefault + '</option>',
  9771. '<option value="left">' + lang.alignLeft + '</option>',
  9772. '<option value="center">' + lang.alignCenter + '</option>',
  9773. '<option value="right">' + lang.alignRight + '</option>',
  9774. '</select>',
  9775. '</div>',
  9776. '<div class="ke-dialog-row">',
  9777. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9778. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9779. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9780. '</div>',
  9781. '<div class="ke-dialog-row">',
  9782. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9783. '<span class="ke-inline-block ke-input-color"></span>',
  9784. '</div>',
  9785. '</div>'
  9786. ].join('');
  9787. var bookmark = self.cmd.range.createBookmark();
  9788. var dialog = self.createDialog({
  9789. name : name,
  9790. width : 500,
  9791. title : self.lang(name),
  9792. body : html,
  9793. beforeRemove : function() {
  9794. colorBox.unbind();
  9795. },
  9796. yesBtn : {
  9797. name : self.lang('yes'),
  9798. click : function(e) {
  9799. var rows = rowsBox.val(),
  9800. cols = colsBox.val(),
  9801. width = widthBox.val(),
  9802. height = heightBox.val(),
  9803. widthType = widthTypeBox.val(),
  9804. heightType = heightTypeBox.val(),
  9805. padding = paddingBox.val(),
  9806. spacing = spacingBox.val(),
  9807. align = alignBox.val(),
  9808. border = borderBox.val(),
  9809. borderColor = K(colorBox[0]).html() || '',
  9810. bgColor = K(colorBox[1]).html() || '';
  9811. if (rows == 0 || !/^\d+$/.test(rows)) {
  9812. alert(self.lang('invalidRows'));
  9813. rowsBox[0].focus();
  9814. return;
  9815. }
  9816. if (cols == 0 || !/^\d+$/.test(cols)) {
  9817. alert(self.lang('invalidRows'));
  9818. colsBox[0].focus();
  9819. return;
  9820. }
  9821. if (!/^\d*$/.test(width)) {
  9822. alert(self.lang('invalidWidth'));
  9823. widthBox[0].focus();
  9824. return;
  9825. }
  9826. if (!/^\d*$/.test(height)) {
  9827. alert(self.lang('invalidHeight'));
  9828. heightBox[0].focus();
  9829. return;
  9830. }
  9831. if (!/^\d*$/.test(padding)) {
  9832. alert(self.lang('invalidPadding'));
  9833. paddingBox[0].focus();
  9834. return;
  9835. }
  9836. if (!/^\d*$/.test(spacing)) {
  9837. alert(self.lang('invalidSpacing'));
  9838. spacingBox[0].focus();
  9839. return;
  9840. }
  9841. if (!/^\d*$/.test(border)) {
  9842. alert(self.lang('invalidBorder'));
  9843. borderBox[0].focus();
  9844. return;
  9845. }
  9846. if (table) {
  9847. if (width !== '') {
  9848. table.width(width + widthType);
  9849. } else {
  9850. table.css('width', '');
  9851. }
  9852. if (table[0].width !== undefined) {
  9853. table.removeAttr('width');
  9854. }
  9855. if (height !== '') {
  9856. table.height(height + heightType);
  9857. } else {
  9858. table.css('height', '');
  9859. }
  9860. if (table[0].height !== undefined) {
  9861. table.removeAttr('height');
  9862. }
  9863. table.css('background-color', bgColor);
  9864. if (table[0].bgColor !== undefined) {
  9865. table.removeAttr('bgColor');
  9866. }
  9867. if (padding !== '') {
  9868. table[0].cellPadding = padding;
  9869. } else {
  9870. table.removeAttr('cellPadding');
  9871. }
  9872. if (spacing !== '') {
  9873. table[0].cellSpacing = spacing;
  9874. } else {
  9875. table.removeAttr('cellSpacing');
  9876. }
  9877. if (align !== '') {
  9878. table[0].align = align;
  9879. } else {
  9880. table.removeAttr('align');
  9881. }
  9882. if (border !== '') {
  9883. table.attr('border', border);
  9884. } else {
  9885. table.removeAttr('border');
  9886. }
  9887. if (border === '' || border === '0') {
  9888. table.addClass(zeroborder);
  9889. } else {
  9890. table.removeClass(zeroborder);
  9891. }
  9892. if (borderColor !== '') {
  9893. table.attr('borderColor', borderColor);
  9894. } else {
  9895. table.removeAttr('borderColor');
  9896. }
  9897. self.hideDialog().focus();
  9898. self.cmd.range.moveToBookmark(bookmark);
  9899. self.cmd.select();
  9900. self.addBookmark();
  9901. return;
  9902. }
  9903. var style = '';
  9904. if (width !== '') {
  9905. style += 'width:' + width + widthType + ';';
  9906. }
  9907. if (height !== '') {
  9908. style += 'height:' + height + heightType + ';';
  9909. }
  9910. if (bgColor !== '') {
  9911. style += 'background-color:' + bgColor + ';';
  9912. }
  9913. var html = '<table';
  9914. if (style !== '') {
  9915. html += ' style="' + style + '"';
  9916. }
  9917. if (padding !== '') {
  9918. html += ' cellpadding="' + padding + '"';
  9919. }
  9920. if (spacing !== '') {
  9921. html += ' cellspacing="' + spacing + '"';
  9922. }
  9923. if (align !== '') {
  9924. html += ' align="' + align + '"';
  9925. }
  9926. if (border !== '') {
  9927. html += ' border="' + border + '"';
  9928. }
  9929. if (border === '' || border === '0') {
  9930. html += ' class="' + zeroborder + '"';
  9931. }
  9932. if (borderColor !== '') {
  9933. html += ' bordercolor="' + borderColor + '"';
  9934. }
  9935. html += '>';
  9936. for (var i = 0; i < rows; i++) {
  9937. html += '<tr>';
  9938. for (var j = 0; j < cols; j++) {
  9939. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9940. }
  9941. html += '</tr>';
  9942. }
  9943. html += '</table>';
  9944. if (!K.IE) {
  9945. html += '<br />';
  9946. }
  9947. self.insertHtml(html);
  9948. self.select().hideDialog().focus();
  9949. self.addBookmark();
  9950. }
  9951. }
  9952. }),
  9953. div = dialog.div,
  9954. rowsBox = K('[name="rows"]', div).val(3),
  9955. colsBox = K('[name="cols"]', div).val(2),
  9956. widthBox = K('[name="width"]', div).val(100),
  9957. heightBox = K('[name="height"]', div),
  9958. widthTypeBox = K('[name="widthType"]', div),
  9959. heightTypeBox = K('[name="heightType"]', div),
  9960. paddingBox = K('[name="padding"]', div).val(2),
  9961. spacingBox = K('[name="spacing"]', div).val(0),
  9962. alignBox = K('[name="align"]', div),
  9963. borderBox = K('[name="border"]', div).val(1),
  9964. colorBox = K('.ke-input-color', div);
  9965. _initColorPicker(div, colorBox.eq(0));
  9966. _initColorPicker(div, colorBox.eq(1));
  9967. _setColor(colorBox.eq(0), '#000000');
  9968. _setColor(colorBox.eq(1), '');
  9969. rowsBox[0].focus();
  9970. rowsBox[0].select();
  9971. var table;
  9972. if (isInsert) {
  9973. return;
  9974. }
  9975. table = self.plugin.getSelectedTable();
  9976. if (table) {
  9977. rowsBox.val(table[0].rows.length);
  9978. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9979. rowsBox.attr('disabled', true);
  9980. colsBox.attr('disabled', true);
  9981. var match,
  9982. tableWidth = table[0].style.width || table[0].width,
  9983. tableHeight = table[0].style.height || table[0].height;
  9984. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9985. widthBox.val(match[1]);
  9986. widthTypeBox.val(match[2]);
  9987. } else {
  9988. widthBox.val('');
  9989. }
  9990. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9991. heightBox.val(match[1]);
  9992. heightTypeBox.val(match[2]);
  9993. }
  9994. paddingBox.val(table[0].cellPadding || '');
  9995. spacingBox.val(table[0].cellSpacing || '');
  9996. alignBox.val(table[0].align || '');
  9997. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9998. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9999. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  10000. widthBox[0].focus();
  10001. widthBox[0].select();
  10002. }
  10003. },
  10004. cellprop : function() {
  10005. var html = [
  10006. '<div style="padding:20px;">',
  10007. '<div class="ke-dialog-row">',
  10008. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  10009. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  10010. '<select name="widthType">',
  10011. '<option value="%">' + lang.percent + '</option>',
  10012. '<option value="px">' + lang.px + '</option>',
  10013. '</select> &nbsp; ',
  10014. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  10015. '<select name="heightType">',
  10016. '<option value="%">' + lang.percent + '</option>',
  10017. '<option value="px">' + lang.px + '</option>',
  10018. '</select>',
  10019. '</div>',
  10020. '<div class="ke-dialog-row">',
  10021. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  10022. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  10023. '<option value="">' + lang.alignDefault + '</option>',
  10024. '<option value="left">' + lang.alignLeft + '</option>',
  10025. '<option value="center">' + lang.alignCenter + '</option>',
  10026. '<option value="right">' + lang.alignRight + '</option>',
  10027. '</select> ',
  10028. lang.verticalAlign + ' <select name="verticalAlign">',
  10029. '<option value="">' + lang.alignDefault + '</option>',
  10030. '<option value="top">' + lang.alignTop + '</option>',
  10031. '<option value="middle">' + lang.alignMiddle + '</option>',
  10032. '<option value="bottom">' + lang.alignBottom + '</option>',
  10033. '<option value="baseline">' + lang.alignBaseline + '</option>',
  10034. '</select>',
  10035. '</div>',
  10036. '<div class="ke-dialog-row">',
  10037. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  10038. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  10039. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  10040. '</div>',
  10041. '<div class="ke-dialog-row">',
  10042. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  10043. '<span class="ke-inline-block ke-input-color"></span>',
  10044. '</div>',
  10045. '</div>'
  10046. ].join('');
  10047. var bookmark = self.cmd.range.createBookmark();
  10048. var dialog = self.createDialog({
  10049. name : name,
  10050. width : 500,
  10051. title : self.lang('tablecell'),
  10052. body : html,
  10053. beforeRemove : function() {
  10054. colorBox.unbind();
  10055. },
  10056. yesBtn : {
  10057. name : self.lang('yes'),
  10058. click : function(e) {
  10059. var width = widthBox.val(),
  10060. height = heightBox.val(),
  10061. widthType = widthTypeBox.val(),
  10062. heightType = heightTypeBox.val(),
  10063. padding = paddingBox.val(),
  10064. spacing = spacingBox.val(),
  10065. textAlign = textAlignBox.val(),
  10066. verticalAlign = verticalAlignBox.val(),
  10067. border = borderBox.val(),
  10068. borderColor = K(colorBox[0]).html() || '',
  10069. bgColor = K(colorBox[1]).html() || '';
  10070. if (!/^\d*$/.test(width)) {
  10071. alert(self.lang('invalidWidth'));
  10072. widthBox[0].focus();
  10073. return;
  10074. }
  10075. if (!/^\d*$/.test(height)) {
  10076. alert(self.lang('invalidHeight'));
  10077. heightBox[0].focus();
  10078. return;
  10079. }
  10080. if (!/^\d*$/.test(border)) {
  10081. alert(self.lang('invalidBorder'));
  10082. borderBox[0].focus();
  10083. return;
  10084. }
  10085. cell.css({
  10086. width : width !== '' ? (width + widthType) : '',
  10087. height : height !== '' ? (height + heightType) : '',
  10088. 'background-color' : bgColor,
  10089. 'text-align' : textAlign,
  10090. 'vertical-align' : verticalAlign,
  10091. 'border-width' : border,
  10092. 'border-style' : border !== '' ? 'solid' : '',
  10093. 'border-color' : borderColor
  10094. });
  10095. self.hideDialog().focus();
  10096. self.cmd.range.moveToBookmark(bookmark);
  10097. self.cmd.select();
  10098. self.addBookmark();
  10099. }
  10100. }
  10101. }),
  10102. div = dialog.div,
  10103. widthBox = K('[name="width"]', div).val(100),
  10104. heightBox = K('[name="height"]', div),
  10105. widthTypeBox = K('[name="widthType"]', div),
  10106. heightTypeBox = K('[name="heightType"]', div),
  10107. paddingBox = K('[name="padding"]', div).val(2),
  10108. spacingBox = K('[name="spacing"]', div).val(0),
  10109. textAlignBox = K('[name="textAlign"]', div),
  10110. verticalAlignBox = K('[name="verticalAlign"]', div),
  10111. borderBox = K('[name="border"]', div).val(1),
  10112. colorBox = K('.ke-input-color', div);
  10113. _initColorPicker(div, colorBox.eq(0));
  10114. _initColorPicker(div, colorBox.eq(1));
  10115. _setColor(colorBox.eq(0), '#000000');
  10116. _setColor(colorBox.eq(1), '');
  10117. widthBox[0].focus();
  10118. widthBox[0].select();
  10119. var cell = self.plugin.getSelectedCell();
  10120. var match,
  10121. cellWidth = cell[0].style.width || cell[0].width || '',
  10122. cellHeight = cell[0].style.height || cell[0].height || '';
  10123. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  10124. widthBox.val(match[1]);
  10125. widthTypeBox.val(match[2]);
  10126. } else {
  10127. widthBox.val('');
  10128. }
  10129. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  10130. heightBox.val(match[1]);
  10131. heightTypeBox.val(match[2]);
  10132. }
  10133. textAlignBox.val(cell[0].style.textAlign || '');
  10134. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  10135. var border = cell[0].style.borderWidth || '';
  10136. if (border) {
  10137. border = parseInt(border);
  10138. }
  10139. borderBox.val(border);
  10140. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  10141. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  10142. widthBox[0].focus();
  10143. widthBox[0].select();
  10144. },
  10145. insert : function() {
  10146. this.prop(true);
  10147. },
  10148. 'delete' : function() {
  10149. var table = self.plugin.getSelectedTable();
  10150. self.cmd.range.setStartBefore(table[0]).collapse(true);
  10151. self.cmd.select();
  10152. table.remove();
  10153. self.addBookmark();
  10154. },
  10155. colinsert : function(offset) {
  10156. var table = self.plugin.getSelectedTable()[0],
  10157. row = self.plugin.getSelectedRow()[0],
  10158. cell = self.plugin.getSelectedCell()[0],
  10159. index = cell.cellIndex + offset;
  10160. index += table.rows[0].cells.length - row.cells.length;
  10161. for (var i = 0, len = table.rows.length; i < len; i++) {
  10162. var newRow = table.rows[i],
  10163. newCell = newRow.insertCell(index);
  10164. newCell.innerHTML = K.IE ? '' : '<br />';
  10165. index = _getCellIndex(table, newRow, newCell);
  10166. }
  10167. self.cmd.range.selectNodeContents(cell).collapse(true);
  10168. self.cmd.select();
  10169. self.addBookmark();
  10170. },
  10171. colinsertleft : function() {
  10172. this.colinsert(0);
  10173. },
  10174. colinsertright : function() {
  10175. this.colinsert(1);
  10176. },
  10177. rowinsert : function(offset) {
  10178. var table = self.plugin.getSelectedTable()[0],
  10179. row = self.plugin.getSelectedRow()[0],
  10180. cell = self.plugin.getSelectedCell()[0];
  10181. var rowIndex = row.rowIndex;
  10182. if (offset === 1) {
  10183. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  10184. }
  10185. var newRow = table.insertRow(rowIndex);
  10186. for (var i = 0, len = row.cells.length; i < len; i++) {
  10187. if (row.cells[i].rowSpan > 1) {
  10188. len -= row.cells[i].rowSpan - 1;
  10189. }
  10190. var newCell = newRow.insertCell(i);
  10191. if (offset === 1 && row.cells[i].colSpan > 1) {
  10192. newCell.colSpan = row.cells[i].colSpan;
  10193. }
  10194. newCell.innerHTML = K.IE ? '' : '<br />';
  10195. }
  10196. for (var j = rowIndex; j >= 0; j--) {
  10197. var cells = table.rows[j].cells;
  10198. if (cells.length > i) {
  10199. for (var k = cell.cellIndex; k >= 0; k--) {
  10200. if (cells[k].rowSpan > 1) {
  10201. cells[k].rowSpan += 1;
  10202. }
  10203. }
  10204. break;
  10205. }
  10206. }
  10207. self.cmd.range.selectNodeContents(cell).collapse(true);
  10208. self.cmd.select();
  10209. self.addBookmark();
  10210. },
  10211. rowinsertabove : function() {
  10212. this.rowinsert(0);
  10213. },
  10214. rowinsertbelow : function() {
  10215. this.rowinsert(1);
  10216. },
  10217. rowmerge : function() {
  10218. var table = self.plugin.getSelectedTable()[0],
  10219. row = self.plugin.getSelectedRow()[0],
  10220. cell = self.plugin.getSelectedCell()[0],
  10221. rowIndex = row.rowIndex,
  10222. nextRowIndex = rowIndex + cell.rowSpan,
  10223. nextRow = table.rows[nextRowIndex];
  10224. if (table.rows.length <= nextRowIndex) {
  10225. return;
  10226. }
  10227. var cellIndex = cell.cellIndex;
  10228. if (nextRow.cells.length <= cellIndex) {
  10229. return;
  10230. }
  10231. var nextCell = nextRow.cells[cellIndex];
  10232. if (cell.colSpan !== nextCell.colSpan) {
  10233. return;
  10234. }
  10235. cell.rowSpan += nextCell.rowSpan;
  10236. nextRow.deleteCell(cellIndex);
  10237. self.cmd.range.selectNodeContents(cell).collapse(true);
  10238. self.cmd.select();
  10239. self.addBookmark();
  10240. },
  10241. colmerge : function() {
  10242. var table = self.plugin.getSelectedTable()[0],
  10243. row = self.plugin.getSelectedRow()[0],
  10244. cell = self.plugin.getSelectedCell()[0],
  10245. rowIndex = row.rowIndex,
  10246. cellIndex = cell.cellIndex,
  10247. nextCellIndex = cellIndex + 1;
  10248. if (row.cells.length <= nextCellIndex) {
  10249. return;
  10250. }
  10251. var nextCell = row.cells[nextCellIndex];
  10252. if (cell.rowSpan !== nextCell.rowSpan) {
  10253. return;
  10254. }
  10255. cell.colSpan += nextCell.colSpan;
  10256. row.deleteCell(nextCellIndex);
  10257. self.cmd.range.selectNodeContents(cell).collapse(true);
  10258. self.cmd.select();
  10259. self.addBookmark();
  10260. },
  10261. rowsplit : function() {
  10262. var table = self.plugin.getSelectedTable()[0],
  10263. row = self.plugin.getSelectedRow()[0],
  10264. cell = self.plugin.getSelectedCell()[0],
  10265. rowIndex = row.rowIndex;
  10266. if (cell.rowSpan === 1) {
  10267. return;
  10268. }
  10269. var cellIndex = _getCellIndex(table, row, cell);
  10270. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  10271. var newRow = table.rows[rowIndex + i],
  10272. newCell = newRow.insertCell(cellIndex);
  10273. if (cell.colSpan > 1) {
  10274. newCell.colSpan = cell.colSpan;
  10275. }
  10276. newCell.innerHTML = K.IE ? '' : '<br />';
  10277. cellIndex = _getCellIndex(table, newRow, newCell);
  10278. }
  10279. K(cell).removeAttr('rowSpan');
  10280. self.cmd.range.selectNodeContents(cell).collapse(true);
  10281. self.cmd.select();
  10282. self.addBookmark();
  10283. },
  10284. colsplit : function() {
  10285. var table = self.plugin.getSelectedTable()[0],
  10286. row = self.plugin.getSelectedRow()[0],
  10287. cell = self.plugin.getSelectedCell()[0],
  10288. cellIndex = cell.cellIndex;
  10289. if (cell.colSpan === 1) {
  10290. return;
  10291. }
  10292. for (var i = 1, len = cell.colSpan; i < len; i++) {
  10293. var newCell = row.insertCell(cellIndex + i);
  10294. if (cell.rowSpan > 1) {
  10295. newCell.rowSpan = cell.rowSpan;
  10296. }
  10297. newCell.innerHTML = K.IE ? '' : '<br />';
  10298. }
  10299. K(cell).removeAttr('colSpan');
  10300. self.cmd.range.selectNodeContents(cell).collapse(true);
  10301. self.cmd.select();
  10302. self.addBookmark();
  10303. },
  10304. coldelete : function() {
  10305. var table = self.plugin.getSelectedTable()[0],
  10306. row = self.plugin.getSelectedRow()[0],
  10307. cell = self.plugin.getSelectedCell()[0],
  10308. index = cell.cellIndex;
  10309. for (var i = 0, len = table.rows.length; i < len; i++) {
  10310. var newRow = table.rows[i],
  10311. newCell = newRow.cells[index];
  10312. if (newCell.colSpan > 1) {
  10313. newCell.colSpan -= 1;
  10314. if (newCell.colSpan === 1) {
  10315. K(newCell).removeAttr('colSpan');
  10316. }
  10317. } else {
  10318. newRow.deleteCell(index);
  10319. }
  10320. if (newCell.rowSpan > 1) {
  10321. i += newCell.rowSpan - 1;
  10322. }
  10323. }
  10324. if (row.cells.length === 0) {
  10325. self.cmd.range.setStartBefore(table).collapse(true);
  10326. self.cmd.select();
  10327. K(table).remove();
  10328. } else {
  10329. self.cmd.selection(true);
  10330. }
  10331. self.addBookmark();
  10332. },
  10333. rowdelete : function() {
  10334. var table = self.plugin.getSelectedTable()[0],
  10335. row = self.plugin.getSelectedRow()[0],
  10336. cell = self.plugin.getSelectedCell()[0],
  10337. rowIndex = row.rowIndex;
  10338. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  10339. table.deleteRow(rowIndex + i);
  10340. }
  10341. if (table.rows.length === 0) {
  10342. self.cmd.range.setStartBefore(table).collapse(true);
  10343. self.cmd.select();
  10344. K(table).remove();
  10345. } else {
  10346. self.cmd.selection(true);
  10347. }
  10348. self.addBookmark();
  10349. }
  10350. };
  10351. self.clickToolbar(name, self.plugin.table.prop);
  10352. });
  10353. /*******************************************************************************
  10354. * KindEditor - WYSIWYG HTML Editor for Internet
  10355. * Copyright (C) 2006-2011 kindsoft.net
  10356. *
  10357. * @author Roddy <luolonghao@gmail.com>
  10358. * @site http://www.kindsoft.net/
  10359. * @licence http://www.kindsoft.net/license.php
  10360. *******************************************************************************/
  10361. KindEditor.plugin('template', function(K) {
  10362. var self = this, name = 'template', lang = self.lang(name + '.'),
  10363. htmlPath = self.pluginsPath + name + '/html/';
  10364. function getFilePath(fileName) {
  10365. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  10366. }
  10367. self.clickToolbar(name, function() {
  10368. var lang = self.lang(name + '.'),
  10369. arr = ['<div style="padding:10px 20px;">',
  10370. '<div class="ke-header">',
  10371. '<div class="ke-left">',
  10372. lang. selectTemplate + ' <select>'];
  10373. K.each(lang.fileList, function(key, val) {
  10374. arr.push('<option value="' + key + '">' + val + '</option>');
  10375. });
  10376. html = [arr.join(''),
  10377. '</select></div>',
  10378. '<div class="ke-right">',
  10379. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  10380. '</div>',
  10381. '<div class="ke-clearfix"></div>',
  10382. '</div>',
  10383. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  10384. '</div>'].join('');
  10385. var dialog = self.createDialog({
  10386. name : name,
  10387. width : 500,
  10388. title : self.lang(name),
  10389. body : html,
  10390. yesBtn : {
  10391. name : self.lang('yes'),
  10392. click : function(e) {
  10393. var doc = K.iframeDoc(iframe);
  10394. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  10395. }
  10396. }
  10397. });
  10398. var selectBox = K('select', dialog.div),
  10399. checkbox = K('[name="replaceFlag"]', dialog.div),
  10400. iframe = K('iframe', dialog.div);
  10401. checkbox[0].checked = true;
  10402. iframe.attr('src', getFilePath(selectBox.val()));
  10403. selectBox.change(function() {
  10404. iframe.attr('src', getFilePath(this.value));
  10405. });
  10406. });
  10407. });
  10408. /*******************************************************************************
  10409. * KindEditor - WYSIWYG HTML Editor for Internet
  10410. * Copyright (C) 2006-2011 kindsoft.net
  10411. *
  10412. * @author Roddy <luolonghao@gmail.com>
  10413. * @site http://www.kindsoft.net/
  10414. * @licence http://www.kindsoft.net/license.php
  10415. *******************************************************************************/
  10416. KindEditor.plugin('wordpaste', function(K) {
  10417. var self = this, name = 'wordpaste';
  10418. self.clickToolbar(name, function() {
  10419. var lang = self.lang(name + '.'),
  10420. html = '<div style="padding:10px 20px;">' +
  10421. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  10422. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  10423. '</div>',
  10424. dialog = self.createDialog({
  10425. name : name,
  10426. width : 450,
  10427. title : self.lang(name),
  10428. body : html,
  10429. yesBtn : {
  10430. name : self.lang('yes'),
  10431. click : function(e) {
  10432. var str = doc.body.innerHTML;
  10433. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  10434. self.insertHtml(str).hideDialog().focus();
  10435. }
  10436. }
  10437. }),
  10438. div = dialog.div,
  10439. iframe = K('iframe', div),
  10440. doc = K.iframeDoc(iframe);
  10441. if (!K.IE) {
  10442. doc.designMode = 'on';
  10443. }
  10444. doc.open();
  10445. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  10446. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  10447. if (!K.IE) {
  10448. doc.write('<br />');
  10449. }
  10450. doc.write('</body></html>');
  10451. doc.close();
  10452. if (K.IE) {
  10453. doc.body.contentEditable = 'true';
  10454. }
  10455. iframe[0].contentWindow.focus();
  10456. });
  10457. });
  10458. KindEditor.plugin('fixtoolbar', function (K) {
  10459. var self = this;
  10460. if (!self.fixToolBar) {
  10461. return;
  10462. }
  10463. function init() {
  10464. var toolbar = K('.ke-toolbar');
  10465. var originY = toolbar.pos().y;
  10466. K(window).bind('scroll', function () {
  10467. if (toolbar.css('position') == 'fixed') {
  10468. if(document.body.scrollTop - originY < 0){
  10469. toolbar.css('position', 'static');
  10470. toolbar.css('top', 'auto');
  10471. }
  10472. } else {
  10473. if (toolbar.pos().y - document.body.scrollTop < 0) {
  10474. toolbar.css('position', 'fixed');
  10475. toolbar.css('top', 0);
  10476. }
  10477. }
  10478. });
  10479. }
  10480. if (self.isCreated) {
  10481. init();
  10482. } else {
  10483. self.afterCreate(init);
  10484. }
  10485. });
  10486. //自定义资源库
  10487. KindEditor.plugin('res', function(K) {
  10488. var self = this;
  10489. // 点击图标时执行
  10490. self.clickToolbar('res', function() {
  10491. var clickFn = function(url, title, id) {
  10492. var html = '<embed src="{url}" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" id="{id}"/>';
  10493. html = html.replace('{url}', url);
  10494. html = html.replace('{id}', id);
  10495. self.insertHtml(html);
  10496. };
  10497. editorShowUpload('', self.mediaManagerJson, '视频库', clickFn, this);
  10498. });
  10499. });
  10500. function autoImg(self) {
  10501. var index = self.index;
  10502. var haspicContainer = document.getElementById("has_pic_" + index);
  10503. if (haspicContainer == null) {
  10504. haspicContainer = document.createElement("div");
  10505. haspicContainer.id = "has_pic_" + index;
  10506. 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>";
  10507. $(".ke-toolbar").eq(index).after(haspicContainer);
  10508. }
  10509. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10510. var piccount = 0;
  10511. var sstr = '';
  10512. $(img).each(function (i) {
  10513. var that = $(this);
  10514. var host = gethost(self.uploadResJson);
  10515. var yhost = '';
  10516. if (self.uploadYunJson && self.uploadYunJson.host) {
  10517. yhost = gethost(self.uploadYunJson.host);
  10518. }
  10519. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10520. var n = gethost(that.attr("src"));
  10521. if (yhost) {
  10522. if (host != n && yhost != n) {
  10523. piccount++;
  10524. if (i == $(img).length - 1)
  10525. sstr += that.attr("src");
  10526. else
  10527. sstr += that.attr("src") + ",";
  10528. }
  10529. } else {
  10530. if (host != n) {
  10531. piccount++;
  10532. if (i == $(img).length - 1)
  10533. sstr += that.attr("src");
  10534. else
  10535. sstr += that.attr("src") + ",";
  10536. }
  10537. }
  10538. }
  10539. });
  10540. $("#piclist_" + index).val(encodeURIComponent(sstr));
  10541. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  10542. }
  10543. function closeupload(index) {
  10544. $("#has_pic_" + index).hide();
  10545. $("#upload_" + index).show();
  10546. }
  10547. function uploadpic(url, name, index) {
  10548. var piclist = encodeURI($("#piclist_" + index).val());
  10549. if (piclist.length == 0) return false;
  10550. $.ajax({
  10551. url: url.replace('kindeditor', 'copys') + '&json=1',
  10552. data: name + "=" + piclist,
  10553. type: "POST",
  10554. dataType: "json",
  10555. beforeSend: function () {
  10556. $("#upload_" + index).hide();
  10557. $("#confirm_" + index).text("正在上传中...");
  10558. },
  10559. success: function (msg) {
  10560. var url = msg.data;
  10561. if (url !== "") {
  10562. var str = new Array();
  10563. str = url.split(',');
  10564. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10565. $(img).each(function (i) {
  10566. var that = $(this);
  10567. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10568. that.attr("src", str[i]);
  10569. that.attr("data-ke-src", str[i]);
  10570. }
  10571. });
  10572. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  10573. }
  10574. else $("#confirm_" + index).text("上传失败!");
  10575. }
  10576. });
  10577. }
  10578. function gethost(url){
  10579. var reg = /^http(s)?:\/\/(.*?)\//;
  10580. return reg.exec(url)[2];
  10581. }