1c6d31ce30341f8116e6124a77c89c930204b96d.svn-base 300 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2013 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.10 (2013-11-23)
  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.10 (2013-11-23)',
  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+$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function(key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function(key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () {};
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function(key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG : false,
  180. VERSION : _VERSION,
  181. IE : _IE,
  182. GECKO : _GECKO,
  183. WEBKIT : _WEBKIT,
  184. OPERA : _OPERA,
  185. V : _V,
  186. TIME : _TIME,
  187. each : _each,
  188. isArray : _isArray,
  189. isFunction : _isFunction,
  190. inArray : _inArray,
  191. inString : _inString,
  192. trim : _trim,
  193. addUnit : _addUnit,
  194. removeUnit : _removeUnit,
  195. escape : _escape,
  196. unescape : _unescape,
  197. toCamel : _toCamel,
  198. toHex : _toHex,
  199. toMap : _toMap,
  200. toArray : _toArray,
  201. undef : _undef,
  202. invalidUrl : _invalidUrl,
  203. addParam : _addParam,
  204. extend : _extend,
  205. json : _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. designMode : true,
  230. fullscreenMode : false,
  231. filterMode : true,
  232. wellFormatMode : true,
  233. shadowMode : true,
  234. loadStyleMode : true,
  235. basePath : K.basePath,
  236. themesPath : K.basePath + 'themes/',
  237. langPath : K.basePath + 'lang/',
  238. pluginsPath : K.basePath + 'plugins/',
  239. themeType : 'default',
  240. langType : 'zh_CN',
  241. urlType : '',
  242. newlineTag : 'p',
  243. resizeType : 2,
  244. syncType : 'form',
  245. pasteType : 2,
  246. dialogAlignType : 'page',
  247. useContextmenu : true,
  248. fullscreenShortcut : false,
  249. bodyClass : 'ke-content',
  250. indentChar : '\t',
  251. cssPath : '',
  252. cssData : '',
  253. minWidth : 650,
  254. minHeight : 100,
  255. minChangeSize : 50,
  256. zIndex : 811213,
  257. items : [
  258. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  259. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  260. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  261. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  262. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  263. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  264. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  265. 'anchor', 'link', 'unlink', '|', 'about'
  266. ],
  267. noDisableItems : ['source', 'fullscreen'],
  268. colorTable : [
  269. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  270. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  271. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  272. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  273. ],
  274. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  275. htmlTags : {
  276. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  277. span : [
  278. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  279. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  280. ],
  281. div : [
  282. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  283. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  284. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  285. ],
  286. table: [
  287. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  288. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  289. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  290. '.width', '.height', '.border-collapse'
  291. ],
  292. 'td,th': [
  293. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  294. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  295. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  296. ],
  297. a : ['id', 'class', 'href', 'target', 'name'],
  298. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  299. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  300. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  301. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  302. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  303. ],
  304. pre : ['id', 'class'],
  305. hr : ['id', 'class', '.page-break-after'],
  306. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  307. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  308. },
  309. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  310. };
  311. var _useCapture = false;
  312. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  313. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  314. var _CHANGE_KEY_MAP = {};
  315. _each(_INPUT_KEY_MAP, function(key, val) {
  316. _CHANGE_KEY_MAP[key] = val;
  317. });
  318. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  319. _CHANGE_KEY_MAP[key] = val;
  320. });
  321. function _bindEvent(el, type, fn) {
  322. if (el.addEventListener){
  323. el.addEventListener(type, fn, _useCapture);
  324. } else if (el.attachEvent){
  325. el.attachEvent('on' + type, fn);
  326. }
  327. }
  328. function _unbindEvent(el, type, fn) {
  329. if (el.removeEventListener){
  330. el.removeEventListener(type, fn, _useCapture);
  331. } else if (el.detachEvent){
  332. el.detachEvent('on' + type, fn);
  333. }
  334. }
  335. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  336. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  337. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  338. function KEvent(el, event) {
  339. this.init(el, event);
  340. }
  341. _extend(KEvent, {
  342. init : function(el, event) {
  343. var self = this, doc = el.ownerDocument || el.document || el;
  344. self.event = event;
  345. _each(_EVENT_PROPS, function(key, val) {
  346. self[val] = event[val];
  347. });
  348. if (!self.target) {
  349. self.target = self.srcElement || doc;
  350. }
  351. if (self.target.nodeType === 3) {
  352. self.target = self.target.parentNode;
  353. }
  354. if (!self.relatedTarget && self.fromElement) {
  355. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  356. }
  357. if (self.pageX == null && self.clientX != null) {
  358. var d = doc.documentElement, body = doc.body;
  359. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  360. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  361. }
  362. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  363. self.which = self.charCode || self.keyCode;
  364. }
  365. if (!self.metaKey && self.ctrlKey) {
  366. self.metaKey = self.ctrlKey;
  367. }
  368. if (!self.which && self.button !== undefined) {
  369. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  370. }
  371. switch (self.which) {
  372. case 186 :
  373. self.which = 59;
  374. break;
  375. case 187 :
  376. case 107 :
  377. case 43 :
  378. self.which = 61;
  379. break;
  380. case 189 :
  381. case 45 :
  382. self.which = 109;
  383. break;
  384. case 42 :
  385. self.which = 106;
  386. break;
  387. case 47 :
  388. self.which = 111;
  389. break;
  390. case 78 :
  391. self.which = 110;
  392. break;
  393. }
  394. if (self.which >= 96 && self.which <= 105) {
  395. self.which -= 48;
  396. }
  397. },
  398. preventDefault : function() {
  399. var ev = this.event;
  400. if (ev.preventDefault) {
  401. ev.preventDefault();
  402. } else {
  403. ev.returnValue = false;
  404. }
  405. },
  406. stopPropagation : function() {
  407. var ev = this.event;
  408. if (ev.stopPropagation) {
  409. ev.stopPropagation();
  410. } else {
  411. ev.cancelBubble = true;
  412. }
  413. },
  414. stop : function() {
  415. this.preventDefault();
  416. this.stopPropagation();
  417. }
  418. });
  419. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  420. function _getId(el) {
  421. return el[_eventExpendo] || null;
  422. }
  423. function _setId(el) {
  424. el[_eventExpendo] = ++_eventId;
  425. return _eventId;
  426. }
  427. function _removeId(el) {
  428. try {
  429. delete el[_eventExpendo];
  430. } catch(e) {
  431. if (el.removeAttribute) {
  432. el.removeAttribute(_eventExpendo);
  433. }
  434. }
  435. }
  436. function _bind(el, type, fn) {
  437. if (type.indexOf(',') >= 0) {
  438. _each(type.split(','), function() {
  439. _bind(el, this, fn);
  440. });
  441. return;
  442. }
  443. var id = _getId(el);
  444. if (!id) {
  445. id = _setId(el);
  446. }
  447. if (_eventData[id] === undefined) {
  448. _eventData[id] = {};
  449. }
  450. var events = _eventData[id][type];
  451. if (events && events.length > 0) {
  452. _unbindEvent(el, type, events[0]);
  453. } else {
  454. _eventData[id][type] = [];
  455. _eventData[id].el = el;
  456. }
  457. events = _eventData[id][type];
  458. if (events.length === 0) {
  459. events[0] = function(e) {
  460. var kevent = e ? new KEvent(el, e) : undefined;
  461. _each(events, function(i, event) {
  462. if (i > 0 && event) {
  463. event.call(el, kevent);
  464. }
  465. });
  466. };
  467. }
  468. if (_inArray(fn, events) < 0) {
  469. events.push(fn);
  470. }
  471. _bindEvent(el, type, events[0]);
  472. }
  473. function _unbind(el, type, fn) {
  474. if (type && type.indexOf(',') >= 0) {
  475. _each(type.split(','), function() {
  476. _unbind(el, this, fn);
  477. });
  478. return;
  479. }
  480. var id = _getId(el);
  481. if (!id) {
  482. return;
  483. }
  484. if (type === undefined) {
  485. if (id in _eventData) {
  486. _each(_eventData[id], function(key, events) {
  487. if (key != 'el' && events.length > 0) {
  488. _unbindEvent(el, key, events[0]);
  489. }
  490. });
  491. delete _eventData[id];
  492. _removeId(el);
  493. }
  494. return;
  495. }
  496. if (!_eventData[id]) {
  497. return;
  498. }
  499. var events = _eventData[id][type];
  500. if (events && events.length > 0) {
  501. if (fn === undefined) {
  502. _unbindEvent(el, type, events[0]);
  503. delete _eventData[id][type];
  504. } else {
  505. _each(events, function(i, event) {
  506. if (i > 0 && event === fn) {
  507. events.splice(i, 1);
  508. }
  509. });
  510. if (events.length == 1) {
  511. _unbindEvent(el, type, events[0]);
  512. delete _eventData[id][type];
  513. }
  514. }
  515. var count = 0;
  516. _each(_eventData[id], function() {
  517. count++;
  518. });
  519. if (count < 2) {
  520. delete _eventData[id];
  521. _removeId(el);
  522. }
  523. }
  524. }
  525. function _fire(el, type) {
  526. if (type.indexOf(',') >= 0) {
  527. _each(type.split(','), function() {
  528. _fire(el, this);
  529. });
  530. return;
  531. }
  532. var id = _getId(el);
  533. if (!id) {
  534. return;
  535. }
  536. var events = _eventData[id][type];
  537. if (_eventData[id] && events && events.length > 0) {
  538. events[0]();
  539. }
  540. }
  541. function _ctrl(el, key, fn) {
  542. var self = this;
  543. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  544. _bind(el, 'keydown', function(e) {
  545. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  546. fn.call(el);
  547. e.stop();
  548. }
  549. });
  550. }
  551. var _readyFinished = false;
  552. function _ready(fn) {
  553. if (_readyFinished) {
  554. fn(KindEditor);
  555. return;
  556. }
  557. var loaded = false;
  558. function readyFunc() {
  559. if (!loaded) {
  560. loaded = true;
  561. fn(KindEditor);
  562. _readyFinished = true;
  563. }
  564. }
  565. function ieReadyFunc() {
  566. if (!loaded) {
  567. try {
  568. document.documentElement.doScroll('left');
  569. } catch(e) {
  570. setTimeout(ieReadyFunc, 100);
  571. return;
  572. }
  573. readyFunc();
  574. }
  575. }
  576. function ieReadyStateFunc() {
  577. if (document.readyState === 'complete') {
  578. readyFunc();
  579. }
  580. }
  581. if (document.addEventListener) {
  582. _bind(document, 'DOMContentLoaded', readyFunc);
  583. } else if (document.attachEvent) {
  584. _bind(document, 'readystatechange', ieReadyStateFunc);
  585. var toplevel = false;
  586. try {
  587. toplevel = window.frameElement == null;
  588. } catch(e) {}
  589. if (document.documentElement.doScroll && toplevel) {
  590. ieReadyFunc();
  591. }
  592. }
  593. _bind(window, 'load', readyFunc);
  594. }
  595. if (_IE) {
  596. window.attachEvent('onunload', function() {
  597. _each(_eventData, function(key, events) {
  598. if (events.el) {
  599. _unbind(events.el);
  600. }
  601. });
  602. });
  603. }
  604. K.ctrl = _ctrl;
  605. K.ready = _ready;
  606. function _getCssList(css) {
  607. var list = {},
  608. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  609. match;
  610. while ((match = reg.exec(css))) {
  611. var key = _trim(match[1].toLowerCase()),
  612. val = _trim(_toHex(match[2]));
  613. list[key] = val;
  614. }
  615. return list;
  616. }
  617. function _getAttrList(tag) {
  618. var list = {},
  619. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  620. match;
  621. while ((match = reg.exec(tag))) {
  622. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  623. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  624. list[key] = val;
  625. }
  626. return list;
  627. }
  628. function _addClassToTag(tag, className) {
  629. if (/\s+class\s*=/.test(tag)) {
  630. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  631. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  632. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  633. } else {
  634. return $0;
  635. }
  636. });
  637. } else {
  638. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  639. }
  640. return tag;
  641. }
  642. function _formatCss(css) {
  643. var str = '';
  644. _each(_getCssList(css), function(key, val) {
  645. str += key + ':' + val + ';';
  646. });
  647. return str;
  648. }
  649. function _formatUrl(url, mode, host, pathname) {
  650. mode = _undef(mode, '').toLowerCase();
  651. if (url.substr(0, 5) != 'data:') {
  652. url = url.replace(/([^:])\/\//g, '$1/');
  653. }
  654. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  655. return url;
  656. }
  657. host = host || location.protocol + '//' + location.host;
  658. if (pathname === undefined) {
  659. var m = location.pathname.match(/^(\/.*)\//);
  660. pathname = m ? m[1] : '';
  661. }
  662. var match;
  663. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  664. if (match[1] !== host) {
  665. return url;
  666. }
  667. } else if (/^\w+:/.test(url)) {
  668. return url;
  669. }
  670. function getRealPath(path) {
  671. var parts = path.split('/'), paths = [];
  672. for (var i = 0, len = parts.length; i < len; i++) {
  673. var part = parts[i];
  674. if (part == '..') {
  675. if (paths.length > 0) {
  676. paths.pop();
  677. }
  678. } else if (part !== '' && part != '.') {
  679. paths.push(part);
  680. }
  681. }
  682. return '/' + paths.join('/');
  683. }
  684. if (/^\//.test(url)) {
  685. url = host + getRealPath(url.substr(1));
  686. } else if (!/^\w+:\/\//.test(url)) {
  687. url = host + getRealPath(pathname + '/' + url);
  688. }
  689. function getRelativePath(path, depth) {
  690. if (url.substr(0, path.length) === path) {
  691. var arr = [];
  692. for (var i = 0; i < depth; i++) {
  693. arr.push('..');
  694. }
  695. var prefix = '.';
  696. if (arr.length > 0) {
  697. prefix += '/' + arr.join('/');
  698. }
  699. if (pathname == '/') {
  700. prefix += '/';
  701. }
  702. return prefix + url.substr(path.length);
  703. } else {
  704. if ((match = /^(.*)\//.exec(path))) {
  705. return getRelativePath(match[1], ++depth);
  706. }
  707. }
  708. }
  709. if (mode === 'relative') {
  710. url = getRelativePath(host + pathname, 0).substr(2);
  711. } else if (mode === 'absolute') {
  712. if (url.substr(0, host.length) === host) {
  713. url = url.substr(host.length);
  714. }
  715. }
  716. return url;
  717. }
  718. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  719. if (html == null) {
  720. html = '';
  721. }
  722. urlType = urlType || '';
  723. wellFormatted = _undef(wellFormatted, false);
  724. indentChar = _undef(indentChar, '\t');
  725. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  726. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  727. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  728. });
  729. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  730. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  731. html = html.replace(/\u200B/g, '');
  732. html = html.replace(/\u00A9/g, '&copy;');
  733. html = html.replace(/\u00AE/g, '&reg;');
  734. html = html.replace(/<[^>]+/g, function($0) {
  735. return $0.replace(/\s+/g, ' ');
  736. });
  737. var htmlTagMap = {};
  738. if (htmlTags) {
  739. _each(htmlTags, function(key, val) {
  740. var arr = key.split(',');
  741. for (var i = 0, len = arr.length; i < len; i++) {
  742. htmlTagMap[arr[i]] = _toMap(val);
  743. }
  744. });
  745. if (!htmlTagMap.script) {
  746. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  747. }
  748. if (!htmlTagMap.style) {
  749. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  750. }
  751. }
  752. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  753. var tagStack = [];
  754. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  755. var full = $0,
  756. startNewline = $1 || '',
  757. startSlash = $2 || '',
  758. tagName = $3.toLowerCase(),
  759. attr = $4 || '',
  760. endSlash = $5 ? ' ' + $5 : '',
  761. endNewline = $6 || '';
  762. if (htmlTags && !htmlTagMap[tagName]) {
  763. return '';
  764. }
  765. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  766. endSlash = ' /';
  767. }
  768. if (_INLINE_TAG_MAP[tagName]) {
  769. if (startNewline) {
  770. startNewline = ' ';
  771. }
  772. if (endNewline) {
  773. endNewline = ' ';
  774. }
  775. }
  776. if (_PRE_TAG_MAP[tagName]) {
  777. if (startSlash) {
  778. endNewline = '\n';
  779. } else {
  780. startNewline = '\n';
  781. }
  782. }
  783. if (wellFormatted && tagName == 'br') {
  784. endNewline = '\n';
  785. }
  786. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  787. if (wellFormatted) {
  788. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  789. tagStack.pop();
  790. } else {
  791. tagStack.push(tagName);
  792. }
  793. startNewline = '\n';
  794. endNewline = '\n';
  795. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  796. startNewline += indentChar;
  797. if (!startSlash) {
  798. endNewline += indentChar;
  799. }
  800. }
  801. if (endSlash) {
  802. tagStack.pop();
  803. } else if (!startSlash) {
  804. endNewline += indentChar;
  805. }
  806. } else {
  807. startNewline = endNewline = '';
  808. }
  809. }
  810. if (attr !== '') {
  811. var attrMap = _getAttrList(full);
  812. if (tagName === 'font') {
  813. var fontStyleMap = {}, fontStyle = '';
  814. _each(attrMap, function(key, val) {
  815. if (key === 'color') {
  816. fontStyleMap.color = val;
  817. delete attrMap[key];
  818. }
  819. if (key === 'size') {
  820. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  821. delete attrMap[key];
  822. }
  823. if (key === 'face') {
  824. fontStyleMap['font-family'] = val;
  825. delete attrMap[key];
  826. }
  827. if (key === 'style') {
  828. fontStyle = val;
  829. }
  830. });
  831. if (fontStyle && !/;$/.test(fontStyle)) {
  832. fontStyle += ';';
  833. }
  834. _each(fontStyleMap, function(key, val) {
  835. if (val === '') {
  836. return;
  837. }
  838. if (/\s/.test(val)) {
  839. val = "'" + val + "'";
  840. }
  841. fontStyle += key + ':' + val + ';';
  842. });
  843. attrMap.style = fontStyle;
  844. }
  845. _each(attrMap, function(key, val) {
  846. if (_FILL_ATTR_MAP[key]) {
  847. attrMap[key] = key;
  848. }
  849. if (_inArray(key, ['src', 'href']) >= 0) {
  850. attrMap[key] = _formatUrl(val, urlType);
  851. }
  852. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  853. tagName === 'body' && key === 'contenteditable' ||
  854. /^kindeditor_\d+$/.test(key)) {
  855. delete attrMap[key];
  856. }
  857. if (key === 'style' && val !== '') {
  858. var styleMap = _getCssList(val);
  859. _each(styleMap, function(k, v) {
  860. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  861. delete styleMap[k];
  862. }
  863. });
  864. var style = '';
  865. _each(styleMap, function(k, v) {
  866. style += k + ':' + v + ';';
  867. });
  868. attrMap.style = style;
  869. }
  870. });
  871. attr = '';
  872. _each(attrMap, function(key, val) {
  873. if (key === 'style' && val === '') {
  874. return;
  875. }
  876. val = val.replace(/"/g, '&quot;');
  877. attr += ' ' + key + '="' + val + '"';
  878. });
  879. }
  880. if (tagName === 'font') {
  881. tagName = 'span';
  882. }
  883. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  884. });
  885. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  886. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  887. });
  888. html = html.replace(/\n\s*\n/g, '\n');
  889. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  890. return _trim(html);
  891. }
  892. function _clearMsWord(html, htmlTags) {
  893. html = html.replace(/<meta[\s\S]*?>/ig, '')
  894. .replace(/<![\s\S]*?>/ig, '')
  895. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  896. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  897. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  898. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  899. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  900. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  901. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  902. });
  903. return _formatHtml(html, htmlTags);
  904. }
  905. function _mediaType(src) {
  906. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  907. return 'audio/x-pn-realaudio-plugin';
  908. }
  909. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  910. return 'application/x-shockwave-flash';
  911. }
  912. return 'video/x-ms-asf-plugin';
  913. }
  914. function _mediaClass(type) {
  915. if (/realaudio/i.test(type)) {
  916. return 'ke-rm';
  917. }
  918. if (/flash/i.test(type)) {
  919. return 'ke-flash';
  920. }
  921. return 'ke-media';
  922. }
  923. function _mediaAttrs(srcTag) {
  924. return _getAttrList(unescape(srcTag));
  925. }
  926. function _mediaEmbed(attrs) {
  927. var html = '<embed ';
  928. _each(attrs, function(key, val) {
  929. html += key + '="' + val + '" ';
  930. });
  931. html += '/>';
  932. return html;
  933. }
  934. function _mediaImg(blankPath, attrs) {
  935. var width = attrs.width,
  936. height = attrs.height,
  937. type = attrs.type || _mediaType(attrs.src),
  938. srcTag = _mediaEmbed(attrs),
  939. style = '';
  940. if (/\D/.test(width)) {
  941. style += 'width:' + width + ';';
  942. } else if (width > 0) {
  943. style += 'width:' + width + 'px;';
  944. }
  945. if (/\D/.test(height)) {
  946. style += 'height:' + height + ';';
  947. } else if (height > 0) {
  948. style += 'height:' + height + 'px;';
  949. }
  950. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  951. if (style !== '') {
  952. html += 'style="' + style + '" ';
  953. }
  954. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  955. return html;
  956. }
  957. function _tmpl(str, data) {
  958. var fn = new Function("obj",
  959. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  960. "with(obj){p.push('" +
  961. str.replace(/[\r\t\n]/g, " ")
  962. .split("<%").join("\t")
  963. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  964. .replace(/\t=(.*?)%>/g, "',$1,'")
  965. .split("\t").join("');")
  966. .split("%>").join("p.push('")
  967. .split("\r").join("\\'") + "');}return p.join('');");
  968. return data ? fn(data) : fn;
  969. }
  970. K.formatUrl = _formatUrl;
  971. K.formatHtml = _formatHtml;
  972. K.getCssList = _getCssList;
  973. K.getAttrList = _getAttrList;
  974. K.mediaType = _mediaType;
  975. K.mediaAttrs = _mediaAttrs;
  976. K.mediaEmbed = _mediaEmbed;
  977. K.mediaImg = _mediaImg;
  978. K.clearMsWord = _clearMsWord;
  979. K.tmpl = _tmpl;
  980. function _contains(nodeA, nodeB) {
  981. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  982. return true;
  983. }
  984. while ((nodeB = nodeB.parentNode)) {
  985. if (nodeB == nodeA) {
  986. return true;
  987. }
  988. }
  989. return false;
  990. }
  991. var _getSetAttrDiv = document.createElement('div');
  992. _getSetAttrDiv.setAttribute('className', 't');
  993. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  994. function _getAttr(el, key) {
  995. key = key.toLowerCase();
  996. var val = null;
  997. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  998. var div = el.ownerDocument.createElement('div');
  999. div.appendChild(el.cloneNode(false));
  1000. var list = _getAttrList(_unescape(div.innerHTML));
  1001. if (key in list) {
  1002. val = list[key];
  1003. }
  1004. } else {
  1005. try {
  1006. val = el.getAttribute(key, 2);
  1007. } catch(e) {
  1008. val = el.getAttribute(key, 1);
  1009. }
  1010. }
  1011. if (key === 'style' && val !== null) {
  1012. val = _formatCss(val);
  1013. }
  1014. return val;
  1015. }
  1016. function _queryAll(expr, root) {
  1017. var exprList = expr.split(',');
  1018. if (exprList.length > 1) {
  1019. var mergedResults = [];
  1020. _each(exprList, function() {
  1021. _each(_queryAll(this, root), function() {
  1022. if (_inArray(this, mergedResults) < 0) {
  1023. mergedResults.push(this);
  1024. }
  1025. });
  1026. });
  1027. return mergedResults;
  1028. }
  1029. root = root || document;
  1030. function escape(str) {
  1031. if (typeof str != 'string') {
  1032. return str;
  1033. }
  1034. return str.replace(/([^\w\-])/g, '\\$1');
  1035. }
  1036. function stripslashes(str) {
  1037. return str.replace(/\\/g, '');
  1038. }
  1039. function cmpTag(tagA, tagB) {
  1040. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1041. }
  1042. function byId(id, tag, root) {
  1043. var arr = [],
  1044. doc = root.ownerDocument || root,
  1045. el = doc.getElementById(stripslashes(id));
  1046. if (el) {
  1047. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1048. arr.push(el);
  1049. }
  1050. }
  1051. return arr;
  1052. }
  1053. function byClass(className, tag, root) {
  1054. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1055. if (root.getElementsByClassName) {
  1056. els = root.getElementsByClassName(stripslashes(className));
  1057. for (i = 0, len = els.length; i < len; i++) {
  1058. el = els[i];
  1059. if (cmpTag(tag, el.nodeName)) {
  1060. arr.push(el);
  1061. }
  1062. }
  1063. } else if (doc.querySelectorAll) {
  1064. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1065. for (i = 0, len = els.length; i < len; i++) {
  1066. el = els[i];
  1067. if (_contains(root, el)) {
  1068. arr.push(el);
  1069. }
  1070. }
  1071. } else {
  1072. els = root.getElementsByTagName(tag);
  1073. className = ' ' + className + ' ';
  1074. for (i = 0, len = els.length; i < len; i++) {
  1075. el = els[i];
  1076. if (el.nodeType == 1) {
  1077. var cls = el.className;
  1078. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1079. arr.push(el);
  1080. }
  1081. }
  1082. }
  1083. }
  1084. return arr;
  1085. }
  1086. function byName(name, tag, root) {
  1087. var arr = [], doc = root.ownerDocument || root,
  1088. els = doc.getElementsByName(stripslashes(name)), el;
  1089. for (var i = 0, len = els.length; i < len; i++) {
  1090. el = els[i];
  1091. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1092. if (el.getAttribute('name') !== null) {
  1093. arr.push(el);
  1094. }
  1095. }
  1096. }
  1097. return arr;
  1098. }
  1099. function byAttr(key, val, tag, root) {
  1100. var arr = [], els = root.getElementsByTagName(tag), el;
  1101. for (var i = 0, len = els.length; i < len; i++) {
  1102. el = els[i];
  1103. if (el.nodeType == 1) {
  1104. if (val === null) {
  1105. if (_getAttr(el, key) !== null) {
  1106. arr.push(el);
  1107. }
  1108. } else {
  1109. if (val === escape(_getAttr(el, key))) {
  1110. arr.push(el);
  1111. }
  1112. }
  1113. }
  1114. }
  1115. return arr;
  1116. }
  1117. function select(expr, root) {
  1118. var arr = [], matches;
  1119. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1120. var tag = matches ? matches[1] : '*';
  1121. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1122. arr = byId(matches[1], tag, root);
  1123. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1124. arr = byClass(matches[1], tag, root);
  1125. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1126. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1127. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1128. var key = matches[1].toLowerCase(), val = matches[2];
  1129. if (key === 'id') {
  1130. arr = byId(val, tag, root);
  1131. } else if (key === 'class') {
  1132. arr = byClass(val, tag, root);
  1133. } else if (key === 'name') {
  1134. arr = byName(val, tag, root);
  1135. } else {
  1136. arr = byAttr(key, val, tag, root);
  1137. }
  1138. } else {
  1139. var els = root.getElementsByTagName(tag), el;
  1140. for (var i = 0, len = els.length; i < len; i++) {
  1141. el = els[i];
  1142. if (el.nodeType == 1) {
  1143. arr.push(el);
  1144. }
  1145. }
  1146. }
  1147. return arr;
  1148. }
  1149. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1150. while ((arr = re.exec(expr))) {
  1151. if (arr[1] !== ' ') {
  1152. parts.push(arr[1]);
  1153. }
  1154. }
  1155. var results = [];
  1156. if (parts.length == 1) {
  1157. return select(parts[0], root);
  1158. }
  1159. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1160. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1161. part = parts[i];
  1162. if (part === '>') {
  1163. isChild = true;
  1164. continue;
  1165. }
  1166. if (i > 0) {
  1167. els = [];
  1168. for (j = 0, len = results.length; j < len; j++) {
  1169. val = results[j];
  1170. subResults = select(part, val);
  1171. for (k = 0, l = subResults.length; k < l; k++) {
  1172. v = subResults[k];
  1173. if (isChild) {
  1174. if (val === v.parentNode) {
  1175. els.push(v);
  1176. }
  1177. } else {
  1178. els.push(v);
  1179. }
  1180. }
  1181. }
  1182. results = els;
  1183. } else {
  1184. results = select(part, root);
  1185. }
  1186. if (results.length === 0) {
  1187. return [];
  1188. }
  1189. }
  1190. return results;
  1191. }
  1192. function _query(expr, root) {
  1193. var arr = _queryAll(expr, root);
  1194. return arr.length > 0 ? arr[0] : null;
  1195. }
  1196. K.query = _query;
  1197. K.queryAll = _queryAll;
  1198. function _get(val) {
  1199. return K(val)[0];
  1200. }
  1201. function _getDoc(node) {
  1202. if (!node) {
  1203. return document;
  1204. }
  1205. return node.ownerDocument || node.document || node;
  1206. }
  1207. function _getWin(node) {
  1208. if (!node) {
  1209. return window;
  1210. }
  1211. var doc = _getDoc(node);
  1212. return doc.parentWindow || doc.defaultView;
  1213. }
  1214. function _setHtml(el, html) {
  1215. if (el.nodeType != 1) {
  1216. return;
  1217. }
  1218. var doc = _getDoc(el);
  1219. try {
  1220. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1221. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1222. temp.parentNode.removeChild(temp);
  1223. } catch(e) {
  1224. K(el).empty();
  1225. K('@' + html, doc).each(function() {
  1226. el.appendChild(this);
  1227. });
  1228. }
  1229. }
  1230. function _hasClass(el, cls) {
  1231. return _inString(cls, el.className, ' ');
  1232. }
  1233. function _setAttr(el, key, val) {
  1234. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1235. key = 'className';
  1236. }
  1237. el.setAttribute(key, '' + val);
  1238. }
  1239. function _removeAttr(el, key) {
  1240. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1241. key = 'className';
  1242. }
  1243. _setAttr(el, key, '');
  1244. el.removeAttribute(key);
  1245. }
  1246. function _getNodeName(node) {
  1247. if (!node || !node.nodeName) {
  1248. return '';
  1249. }
  1250. return node.nodeName.toLowerCase();
  1251. }
  1252. function _computedCss(el, key) {
  1253. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1254. if (win.getComputedStyle) {
  1255. var style = win.getComputedStyle(el, null);
  1256. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1257. } else if (el.currentStyle) {
  1258. val = el.currentStyle[camelKey] || el.style[camelKey];
  1259. }
  1260. return val;
  1261. }
  1262. function _hasVal(node) {
  1263. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1264. }
  1265. function _docElement(doc) {
  1266. doc = doc || document;
  1267. return _QUIRKS ? doc.body : doc.documentElement;
  1268. }
  1269. function _docHeight(doc) {
  1270. var el = _docElement(doc);
  1271. return Math.max(el.scrollHeight, el.clientHeight);
  1272. }
  1273. function _docWidth(doc) {
  1274. var el = _docElement(doc);
  1275. return Math.max(el.scrollWidth, el.clientWidth);
  1276. }
  1277. function _getScrollPos(doc) {
  1278. doc = doc || document;
  1279. var x, y;
  1280. if (_IE || _NEWIE || _OPERA) {
  1281. x = _docElement(doc).scrollLeft;
  1282. y = _docElement(doc).scrollTop;
  1283. } else {
  1284. x = _getWin(doc).scrollX;
  1285. y = _getWin(doc).scrollY;
  1286. }
  1287. return {x : x, y : y};
  1288. }
  1289. function KNode(node) {
  1290. this.init(node);
  1291. }
  1292. _extend(KNode, {
  1293. init : function(node) {
  1294. var self = this;
  1295. node = _isArray(node) ? node : [node];
  1296. var length = 0;
  1297. for (var i = 0, len = node.length; i < len; i++) {
  1298. if (node[i]) {
  1299. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1300. length++;
  1301. }
  1302. }
  1303. self.length = length;
  1304. self.doc = _getDoc(self[0]);
  1305. self.name = _getNodeName(self[0]);
  1306. self.type = self.length > 0 ? self[0].nodeType : null;
  1307. self.win = _getWin(self[0]);
  1308. },
  1309. each : function(fn) {
  1310. var self = this;
  1311. for (var i = 0; i < self.length; i++) {
  1312. if (fn.call(self[i], i, self[i]) === false) {
  1313. return self;
  1314. }
  1315. }
  1316. return self;
  1317. },
  1318. bind : function(type, fn) {
  1319. this.each(function() {
  1320. _bind(this, type, fn);
  1321. });
  1322. return this;
  1323. },
  1324. unbind : function(type, fn) {
  1325. this.each(function() {
  1326. _unbind(this, type, fn);
  1327. });
  1328. return this;
  1329. },
  1330. fire : function(type) {
  1331. if (this.length < 1) {
  1332. return this;
  1333. }
  1334. _fire(this[0], type);
  1335. return this;
  1336. },
  1337. hasAttr : function(key) {
  1338. if (this.length < 1) {
  1339. return false;
  1340. }
  1341. return !!_getAttr(this[0], key);
  1342. },
  1343. attr : function(key, val) {
  1344. var self = this;
  1345. if (key === undefined) {
  1346. return _getAttrList(self.outer());
  1347. }
  1348. if (typeof key === 'object') {
  1349. _each(key, function(k, v) {
  1350. self.attr(k, v);
  1351. });
  1352. return self;
  1353. }
  1354. if (val === undefined) {
  1355. val = self.length < 1 ? null : _getAttr(self[0], key);
  1356. return val === null ? '' : val;
  1357. }
  1358. self.each(function() {
  1359. _setAttr(this, key, val);
  1360. });
  1361. return self;
  1362. },
  1363. removeAttr : function(key) {
  1364. this.each(function() {
  1365. _removeAttr(this, key);
  1366. });
  1367. return this;
  1368. },
  1369. get : function(i) {
  1370. if (this.length < 1) {
  1371. return null;
  1372. }
  1373. return this[i || 0];
  1374. },
  1375. eq : function(i) {
  1376. if (this.length < 1) {
  1377. return null;
  1378. }
  1379. return this[i] ? new KNode(this[i]) : null;
  1380. },
  1381. hasClass : function(cls) {
  1382. if (this.length < 1) {
  1383. return false;
  1384. }
  1385. return _hasClass(this[0], cls);
  1386. },
  1387. addClass : function(cls) {
  1388. this.each(function() {
  1389. if (!_hasClass(this, cls)) {
  1390. this.className = _trim(this.className + ' ' + cls);
  1391. }
  1392. });
  1393. return this;
  1394. },
  1395. removeClass : function(cls) {
  1396. this.each(function() {
  1397. if (_hasClass(this, cls)) {
  1398. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1399. }
  1400. });
  1401. return this;
  1402. },
  1403. html : function(val) {
  1404. var self = this;
  1405. if (val === undefined) {
  1406. if (self.length < 1 || self.type != 1) {
  1407. return '';
  1408. }
  1409. return _formatHtml(self[0].innerHTML);
  1410. }
  1411. self.each(function() {
  1412. _setHtml(this, val);
  1413. });
  1414. return self;
  1415. },
  1416. text : function() {
  1417. var self = this;
  1418. if (self.length < 1) {
  1419. return '';
  1420. }
  1421. return _IE ? self[0].innerText : self[0].textContent;
  1422. },
  1423. hasVal : function() {
  1424. if (this.length < 1) {
  1425. return false;
  1426. }
  1427. return _hasVal(this[0]);
  1428. },
  1429. val : function(val) {
  1430. var self = this;
  1431. if (val === undefined) {
  1432. if (self.length < 1) {
  1433. return '';
  1434. }
  1435. return self.hasVal() ? self[0].value : self.attr('value');
  1436. } else {
  1437. self.each(function() {
  1438. if (_hasVal(this)) {
  1439. this.value = val;
  1440. } else {
  1441. _setAttr(this, 'value' , val);
  1442. }
  1443. });
  1444. return self;
  1445. }
  1446. },
  1447. css : function(key, val) {
  1448. var self = this;
  1449. if (key === undefined) {
  1450. return _getCssList(self.attr('style'));
  1451. }
  1452. if (typeof key === 'object') {
  1453. _each(key, function(k, v) {
  1454. self.css(k, v);
  1455. });
  1456. return self;
  1457. }
  1458. if (val === undefined) {
  1459. if (self.length < 1) {
  1460. return '';
  1461. }
  1462. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1463. }
  1464. self.each(function() {
  1465. this.style[_toCamel(key)] = val;
  1466. });
  1467. return self;
  1468. },
  1469. width : function(val) {
  1470. var self = this;
  1471. if (val === undefined) {
  1472. if (self.length < 1) {
  1473. return 0;
  1474. }
  1475. return self[0].offsetWidth;
  1476. }
  1477. return self.css('width', _addUnit(val));
  1478. },
  1479. height : function(val) {
  1480. var self = this;
  1481. if (val === undefined) {
  1482. if (self.length < 1) {
  1483. return 0;
  1484. }
  1485. return self[0].offsetHeight;
  1486. }
  1487. return self.css('height', _addUnit(val));
  1488. },
  1489. opacity : function(val) {
  1490. this.each(function() {
  1491. if (this.style.opacity === undefined) {
  1492. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1493. } else {
  1494. this.style.opacity = val == 1 ? '' : val;
  1495. }
  1496. });
  1497. return this;
  1498. },
  1499. data : function(key, val) {
  1500. var self = this;
  1501. key = 'kindeditor_data_' + key;
  1502. if (val === undefined) {
  1503. if (self.length < 1) {
  1504. return null;
  1505. }
  1506. return self[0][key];
  1507. }
  1508. this.each(function() {
  1509. this[key] = val;
  1510. });
  1511. return self;
  1512. },
  1513. pos : function() {
  1514. var self = this, node = self[0], x = 0, y = 0;
  1515. if (node) {
  1516. if (node.getBoundingClientRect) {
  1517. var box = node.getBoundingClientRect(),
  1518. pos = _getScrollPos(self.doc);
  1519. x = box.left + pos.x;
  1520. y = box.top + pos.y;
  1521. } else {
  1522. while (node) {
  1523. x += node.offsetLeft;
  1524. y += node.offsetTop;
  1525. node = node.offsetParent;
  1526. }
  1527. }
  1528. }
  1529. return {x : _round(x), y : _round(y)};
  1530. },
  1531. clone : function(bool) {
  1532. if (this.length < 1) {
  1533. return new KNode([]);
  1534. }
  1535. return new KNode(this[0].cloneNode(bool));
  1536. },
  1537. append : function(expr) {
  1538. this.each(function() {
  1539. if (this.appendChild) {
  1540. this.appendChild(_get(expr));
  1541. }
  1542. });
  1543. return this;
  1544. },
  1545. appendTo : function(expr) {
  1546. this.each(function() {
  1547. _get(expr).appendChild(this);
  1548. });
  1549. return this;
  1550. },
  1551. before : function(expr) {
  1552. this.each(function() {
  1553. this.parentNode.insertBefore(_get(expr), this);
  1554. });
  1555. return this;
  1556. },
  1557. after : function(expr) {
  1558. this.each(function() {
  1559. if (this.nextSibling) {
  1560. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1561. } else {
  1562. this.parentNode.appendChild(_get(expr));
  1563. }
  1564. });
  1565. return this;
  1566. },
  1567. replaceWith : function(expr) {
  1568. var nodes = [];
  1569. this.each(function(i, node) {
  1570. _unbind(node);
  1571. var newNode = _get(expr);
  1572. node.parentNode.replaceChild(newNode, node);
  1573. nodes.push(newNode);
  1574. });
  1575. return K(nodes);
  1576. },
  1577. empty : function() {
  1578. var self = this;
  1579. self.each(function(i, node) {
  1580. var child = node.firstChild;
  1581. while (child) {
  1582. if (!node.parentNode) {
  1583. return;
  1584. }
  1585. var next = child.nextSibling;
  1586. child.parentNode.removeChild(child);
  1587. child = next;
  1588. }
  1589. });
  1590. return self;
  1591. },
  1592. remove : function(keepChilds) {
  1593. var self = this;
  1594. self.each(function(i, node) {
  1595. if (!node.parentNode) {
  1596. return;
  1597. }
  1598. _unbind(node);
  1599. if (keepChilds) {
  1600. var child = node.firstChild;
  1601. while (child) {
  1602. var next = child.nextSibling;
  1603. node.parentNode.insertBefore(child, node);
  1604. child = next;
  1605. }
  1606. }
  1607. node.parentNode.removeChild(node);
  1608. delete self[i];
  1609. });
  1610. self.length = 0;
  1611. return self;
  1612. },
  1613. show : function(val) {
  1614. var self = this;
  1615. if (val === undefined) {
  1616. val = self._originDisplay || '';
  1617. }
  1618. if (self.css('display') != 'none') {
  1619. return self;
  1620. }
  1621. return self.css('display', val);
  1622. },
  1623. hide : function() {
  1624. var self = this;
  1625. if (self.length < 1) {
  1626. return self;
  1627. }
  1628. self._originDisplay = self[0].style.display;
  1629. return self.css('display', 'none');
  1630. },
  1631. outer : function() {
  1632. var self = this;
  1633. if (self.length < 1) {
  1634. return '';
  1635. }
  1636. var div = self.doc.createElement('div'), html;
  1637. div.appendChild(self[0].cloneNode(true));
  1638. html = _formatHtml(div.innerHTML);
  1639. div = null;
  1640. return html;
  1641. },
  1642. isSingle : function() {
  1643. return !!_SINGLE_TAG_MAP[this.name];
  1644. },
  1645. isInline : function() {
  1646. return !!_INLINE_TAG_MAP[this.name];
  1647. },
  1648. isBlock : function() {
  1649. return !!_BLOCK_TAG_MAP[this.name];
  1650. },
  1651. isStyle : function() {
  1652. return !!_STYLE_TAG_MAP[this.name];
  1653. },
  1654. isControl : function() {
  1655. return !!_CONTROL_TAG_MAP[this.name];
  1656. },
  1657. contains : function(otherNode) {
  1658. if (this.length < 1) {
  1659. return false;
  1660. }
  1661. return _contains(this[0], _get(otherNode));
  1662. },
  1663. parent : function() {
  1664. if (this.length < 1) {
  1665. return null;
  1666. }
  1667. var node = this[0].parentNode;
  1668. return node ? new KNode(node) : null;
  1669. },
  1670. children : function() {
  1671. if (this.length < 1) {
  1672. return new KNode([]);
  1673. }
  1674. var list = [], child = this[0].firstChild;
  1675. while (child) {
  1676. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1677. list.push(child);
  1678. }
  1679. child = child.nextSibling;
  1680. }
  1681. return new KNode(list);
  1682. },
  1683. first : function() {
  1684. var list = this.children();
  1685. return list.length > 0 ? list.eq(0) : null;
  1686. },
  1687. last : function() {
  1688. var list = this.children();
  1689. return list.length > 0 ? list.eq(list.length - 1) : null;
  1690. },
  1691. index : function() {
  1692. if (this.length < 1) {
  1693. return -1;
  1694. }
  1695. var i = -1, sibling = this[0];
  1696. while (sibling) {
  1697. i++;
  1698. sibling = sibling.previousSibling;
  1699. }
  1700. return i;
  1701. },
  1702. prev : function() {
  1703. if (this.length < 1) {
  1704. return null;
  1705. }
  1706. var node = this[0].previousSibling;
  1707. return node ? new KNode(node) : null;
  1708. },
  1709. next : function() {
  1710. if (this.length < 1) {
  1711. return null;
  1712. }
  1713. var node = this[0].nextSibling;
  1714. return node ? new KNode(node) : null;
  1715. },
  1716. scan : function(fn, order) {
  1717. if (this.length < 1) {
  1718. return;
  1719. }
  1720. order = (order === undefined) ? true : order;
  1721. function walk(node) {
  1722. var n = order ? node.firstChild : node.lastChild;
  1723. while (n) {
  1724. var next = order ? n.nextSibling : n.previousSibling;
  1725. if (fn(n) === false) {
  1726. return false;
  1727. }
  1728. if (walk(n) === false) {
  1729. return false;
  1730. }
  1731. n = next;
  1732. }
  1733. }
  1734. walk(this[0]);
  1735. return this;
  1736. }
  1737. });
  1738. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1739. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1740. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1741. KNode.prototype[type] = function(fn) {
  1742. return fn ? this.bind(type, fn) : this.fire(type);
  1743. };
  1744. });
  1745. var _K = K;
  1746. K = function(expr, root) {
  1747. if (expr === undefined || expr === null) {
  1748. return;
  1749. }
  1750. function newNode(node) {
  1751. if (!node[0]) {
  1752. node = [];
  1753. }
  1754. return new KNode(node);
  1755. }
  1756. if (typeof expr === 'string') {
  1757. if (root) {
  1758. root = _get(root);
  1759. }
  1760. var length = expr.length;
  1761. if (expr.charAt(0) === '@') {
  1762. expr = expr.substr(1);
  1763. }
  1764. if (expr.length !== length || /<.+>/.test(expr)) {
  1765. var doc = root ? root.ownerDocument || root : document,
  1766. div = doc.createElement('div'), list = [];
  1767. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1768. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1769. var child = div.childNodes[i];
  1770. if (child.id == '__kindeditor_temp_tag__') {
  1771. continue;
  1772. }
  1773. list.push(child);
  1774. }
  1775. return newNode(list);
  1776. }
  1777. return newNode(_queryAll(expr, root));
  1778. }
  1779. if (expr && expr.constructor === KNode) {
  1780. return expr;
  1781. }
  1782. if (expr.toArray) {
  1783. expr = expr.toArray();
  1784. }
  1785. if (_isArray(expr)) {
  1786. return newNode(expr);
  1787. }
  1788. return newNode(_toArray(arguments));
  1789. };
  1790. _each(_K, function(key, val) {
  1791. K[key] = val;
  1792. });
  1793. K.NodeClass = KNode;
  1794. window.KindEditor = K;
  1795. var _START_TO_START = 0,
  1796. _START_TO_END = 1,
  1797. _END_TO_END = 2,
  1798. _END_TO_START = 3,
  1799. _BOOKMARK_ID = 0;
  1800. function _updateCollapsed(range) {
  1801. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1802. return range;
  1803. }
  1804. function _copyAndDelete(range, isCopy, isDelete) {
  1805. var doc = range.doc, nodeList = [];
  1806. function splitTextNode(node, startOffset, endOffset) {
  1807. var length = node.nodeValue.length, centerNode;
  1808. if (isCopy) {
  1809. var cloneNode = node.cloneNode(true);
  1810. if (startOffset > 0) {
  1811. centerNode = cloneNode.splitText(startOffset);
  1812. } else {
  1813. centerNode = cloneNode;
  1814. }
  1815. if (endOffset < length) {
  1816. centerNode.splitText(endOffset - startOffset);
  1817. }
  1818. }
  1819. if (isDelete) {
  1820. var center = node;
  1821. if (startOffset > 0) {
  1822. center = node.splitText(startOffset);
  1823. range.setStart(node, startOffset);
  1824. }
  1825. if (endOffset < length) {
  1826. var right = center.splitText(endOffset - startOffset);
  1827. range.setEnd(right, 0);
  1828. }
  1829. nodeList.push(center);
  1830. }
  1831. return centerNode;
  1832. }
  1833. function removeNodes() {
  1834. if (isDelete) {
  1835. range.up().collapse(true);
  1836. }
  1837. for (var i = 0, len = nodeList.length; i < len; i++) {
  1838. var node = nodeList[i];
  1839. if (node.parentNode) {
  1840. node.parentNode.removeChild(node);
  1841. }
  1842. }
  1843. }
  1844. var copyRange = range.cloneRange().down();
  1845. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1846. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1847. if (ancestor.nodeType == 3) {
  1848. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1849. if (isCopy) {
  1850. frag.appendChild(textNode);
  1851. }
  1852. removeNodes();
  1853. return isCopy ? frag : range;
  1854. }
  1855. function extractNodes(parent, frag) {
  1856. var node = parent.firstChild, nextNode;
  1857. while (node) {
  1858. var testRange = new KRange(doc).selectNode(node);
  1859. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1860. if (start >= 0 && incStart <= 0) {
  1861. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1862. }
  1863. if (incStart >= 0 && incEnd <= 0) {
  1864. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1865. }
  1866. if (incEnd >= 0 && end <= 0) {
  1867. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1868. }
  1869. if (end >= 0) {
  1870. return false;
  1871. }
  1872. nextNode = node.nextSibling;
  1873. if (start > 0) {
  1874. if (node.nodeType == 1) {
  1875. if (incStart >= 0 && incEnd <= 0) {
  1876. if (isCopy) {
  1877. frag.appendChild(node.cloneNode(true));
  1878. }
  1879. if (isDelete) {
  1880. nodeList.push(node);
  1881. }
  1882. } else {
  1883. var childFlag;
  1884. if (isCopy) {
  1885. childFlag = node.cloneNode(false);
  1886. frag.appendChild(childFlag);
  1887. }
  1888. if (extractNodes(node, childFlag) === false) {
  1889. return false;
  1890. }
  1891. }
  1892. } else if (node.nodeType == 3) {
  1893. var textNode;
  1894. if (node == copyRange.startContainer) {
  1895. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1896. } else if (node == copyRange.endContainer) {
  1897. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1898. } else {
  1899. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1900. }
  1901. if (isCopy) {
  1902. try {
  1903. frag.appendChild(textNode);
  1904. } catch(e) {}
  1905. }
  1906. }
  1907. }
  1908. node = nextNode;
  1909. }
  1910. }
  1911. extractNodes(ancestor, frag);
  1912. if (isDelete) {
  1913. range.up().collapse(true);
  1914. }
  1915. for (var i = 0, len = nodeList.length; i < len; i++) {
  1916. var node = nodeList[i];
  1917. if (node.parentNode) {
  1918. node.parentNode.removeChild(node);
  1919. }
  1920. }
  1921. return isCopy ? frag : range;
  1922. }
  1923. function _moveToElementText(range, el) {
  1924. var node = el;
  1925. while (node) {
  1926. var knode = K(node);
  1927. if (knode.name == 'marquee' || knode.name == 'select') {
  1928. return;
  1929. }
  1930. node = node.parentNode;
  1931. }
  1932. try {
  1933. range.moveToElementText(el);
  1934. } catch(e) {}
  1935. }
  1936. function _getStartEnd(rng, isStart) {
  1937. var doc = rng.parentElement().ownerDocument,
  1938. pointRange = rng.duplicate();
  1939. pointRange.collapse(isStart);
  1940. var parent = pointRange.parentElement(),
  1941. nodes = parent.childNodes;
  1942. if (nodes.length === 0) {
  1943. return {node: parent.parentNode, offset: K(parent).index()};
  1944. }
  1945. var startNode = doc, startPos = 0, cmp = -1;
  1946. var testRange = rng.duplicate();
  1947. _moveToElementText(testRange, parent);
  1948. for (var i = 0, len = nodes.length; i < len; i++) {
  1949. var node = nodes[i];
  1950. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1951. if (cmp === 0) {
  1952. return {node: node.parentNode, offset: i};
  1953. }
  1954. if (node.nodeType == 1) {
  1955. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1956. if (knode.isControl()) {
  1957. dummy = doc.createElement('span');
  1958. knode.after(dummy);
  1959. newNode = dummy;
  1960. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1961. }
  1962. _moveToElementText(nodeRange, newNode);
  1963. testRange.setEndPoint('StartToEnd', nodeRange);
  1964. if (cmp > 0) {
  1965. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1966. } else {
  1967. startPos = 0;
  1968. }
  1969. if (dummy) {
  1970. K(dummy).remove();
  1971. }
  1972. } else if (node.nodeType == 3) {
  1973. testRange.moveStart('character', node.nodeValue.length);
  1974. startPos += node.nodeValue.length;
  1975. }
  1976. if (cmp < 0) {
  1977. startNode = node;
  1978. }
  1979. }
  1980. if (cmp < 0 && startNode.nodeType == 1) {
  1981. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1982. }
  1983. if (cmp > 0) {
  1984. while (startNode.nextSibling && startNode.nodeType == 1) {
  1985. startNode = startNode.nextSibling;
  1986. }
  1987. }
  1988. testRange = rng.duplicate();
  1989. _moveToElementText(testRange, parent);
  1990. testRange.setEndPoint('StartToEnd', pointRange);
  1991. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1992. if (cmp > 0 && startNode.nodeType == 3) {
  1993. var prevNode = startNode.previousSibling;
  1994. while (prevNode && prevNode.nodeType == 3) {
  1995. startPos -= prevNode.nodeValue.length;
  1996. prevNode = prevNode.previousSibling;
  1997. }
  1998. }
  1999. return {node: startNode, offset: startPos};
  2000. }
  2001. function _getEndRange(node, offset) {
  2002. var doc = node.ownerDocument || node,
  2003. range = doc.body.createTextRange();
  2004. if (doc == node) {
  2005. range.collapse(true);
  2006. return range;
  2007. }
  2008. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2009. var children = node.childNodes, isStart, child;
  2010. if (offset === 0) {
  2011. child = children[0];
  2012. isStart = true;
  2013. } else {
  2014. child = children[offset - 1];
  2015. isStart = false;
  2016. }
  2017. if (!child) {
  2018. return range;
  2019. }
  2020. if (K(child).name === 'head') {
  2021. if (offset === 1) {
  2022. isStart = true;
  2023. }
  2024. if (offset === 2) {
  2025. isStart = false;
  2026. }
  2027. range.collapse(isStart);
  2028. return range;
  2029. }
  2030. if (child.nodeType == 1) {
  2031. var kchild = K(child), span;
  2032. if (kchild.isControl()) {
  2033. span = doc.createElement('span');
  2034. if (isStart) {
  2035. kchild.before(span);
  2036. } else {
  2037. kchild.after(span);
  2038. }
  2039. child = span;
  2040. }
  2041. _moveToElementText(range, child);
  2042. range.collapse(isStart);
  2043. if (span) {
  2044. K(span).remove();
  2045. }
  2046. return range;
  2047. }
  2048. node = child;
  2049. offset = isStart ? 0 : child.nodeValue.length;
  2050. }
  2051. var dummy = doc.createElement('span');
  2052. K(node).before(dummy);
  2053. _moveToElementText(range, dummy);
  2054. range.moveStart('character', offset);
  2055. K(dummy).remove();
  2056. return range;
  2057. }
  2058. function _toRange(rng) {
  2059. var doc, range;
  2060. function tr2td(start) {
  2061. if (K(start.node).name == 'tr') {
  2062. start.node = start.node.cells[start.offset];
  2063. start.offset = 0;
  2064. }
  2065. }
  2066. if (_IERANGE) {
  2067. if (rng.item) {
  2068. doc = _getDoc(rng.item(0));
  2069. range = new KRange(doc);
  2070. range.selectNode(rng.item(0));
  2071. return range;
  2072. }
  2073. doc = rng.parentElement().ownerDocument;
  2074. var start = _getStartEnd(rng, true),
  2075. end = _getStartEnd(rng, false);
  2076. tr2td(start);
  2077. tr2td(end);
  2078. range = new KRange(doc);
  2079. range.setStart(start.node, start.offset);
  2080. range.setEnd(end.node, end.offset);
  2081. return range;
  2082. }
  2083. var startContainer = rng.startContainer;
  2084. doc = startContainer.ownerDocument || startContainer;
  2085. range = new KRange(doc);
  2086. range.setStart(startContainer, rng.startOffset);
  2087. range.setEnd(rng.endContainer, rng.endOffset);
  2088. return range;
  2089. }
  2090. function KRange(doc) {
  2091. this.init(doc);
  2092. }
  2093. _extend(KRange, {
  2094. init : function(doc) {
  2095. var self = this;
  2096. self.startContainer = doc;
  2097. self.startOffset = 0;
  2098. self.endContainer = doc;
  2099. self.endOffset = 0;
  2100. self.collapsed = true;
  2101. self.doc = doc;
  2102. },
  2103. commonAncestor : function() {
  2104. function getParents(node) {
  2105. var parents = [];
  2106. while (node) {
  2107. parents.push(node);
  2108. node = node.parentNode;
  2109. }
  2110. return parents;
  2111. }
  2112. var parentsA = getParents(this.startContainer),
  2113. parentsB = getParents(this.endContainer),
  2114. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2115. while (++i) {
  2116. parentA = parentsA[lenA - i];
  2117. parentB = parentsB[lenB - i];
  2118. if (!parentA || !parentB || parentA !== parentB) {
  2119. break;
  2120. }
  2121. }
  2122. return parentsA[lenA - i + 1];
  2123. },
  2124. setStart : function(node, offset) {
  2125. var self = this, doc = self.doc;
  2126. self.startContainer = node;
  2127. self.startOffset = offset;
  2128. if (self.endContainer === doc) {
  2129. self.endContainer = node;
  2130. self.endOffset = offset;
  2131. }
  2132. return _updateCollapsed(this);
  2133. },
  2134. setEnd : function(node, offset) {
  2135. var self = this, doc = self.doc;
  2136. self.endContainer = node;
  2137. self.endOffset = offset;
  2138. if (self.startContainer === doc) {
  2139. self.startContainer = node;
  2140. self.startOffset = offset;
  2141. }
  2142. return _updateCollapsed(this);
  2143. },
  2144. setStartBefore : function(node) {
  2145. return this.setStart(node.parentNode || this.doc, K(node).index());
  2146. },
  2147. setStartAfter : function(node) {
  2148. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2149. },
  2150. setEndBefore : function(node) {
  2151. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2152. },
  2153. setEndAfter : function(node) {
  2154. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2155. },
  2156. selectNode : function(node) {
  2157. return this.setStartBefore(node).setEndAfter(node);
  2158. },
  2159. selectNodeContents : function(node) {
  2160. var knode = K(node);
  2161. if (knode.type == 3 || knode.isSingle()) {
  2162. return this.selectNode(node);
  2163. }
  2164. var children = knode.children();
  2165. if (children.length > 0) {
  2166. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2167. }
  2168. return this.setStart(node, 0).setEnd(node, 0);
  2169. },
  2170. collapse : function(toStart) {
  2171. if (toStart) {
  2172. return this.setEnd(this.startContainer, this.startOffset);
  2173. }
  2174. return this.setStart(this.endContainer, this.endOffset);
  2175. },
  2176. compareBoundaryPoints : function(how, range) {
  2177. var rangeA = this.get(), rangeB = range.get();
  2178. if (_IERANGE) {
  2179. var arr = {};
  2180. arr[_START_TO_START] = 'StartToStart';
  2181. arr[_START_TO_END] = 'EndToStart';
  2182. arr[_END_TO_END] = 'EndToEnd';
  2183. arr[_END_TO_START] = 'StartToEnd';
  2184. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2185. if (cmp !== 0) {
  2186. return cmp;
  2187. }
  2188. var nodeA, nodeB, nodeC, posA, posB;
  2189. if (how === _START_TO_START || how === _END_TO_START) {
  2190. nodeA = this.startContainer;
  2191. posA = this.startOffset;
  2192. }
  2193. if (how === _START_TO_END || how === _END_TO_END) {
  2194. nodeA = this.endContainer;
  2195. posA = this.endOffset;
  2196. }
  2197. if (how === _START_TO_START || how === _START_TO_END) {
  2198. nodeB = range.startContainer;
  2199. posB = range.startOffset;
  2200. }
  2201. if (how === _END_TO_END || how === _END_TO_START) {
  2202. nodeB = range.endContainer;
  2203. posB = range.endOffset;
  2204. }
  2205. if (nodeA === nodeB) {
  2206. var diff = posA - posB;
  2207. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2208. }
  2209. nodeC = nodeB;
  2210. while (nodeC && nodeC.parentNode !== nodeA) {
  2211. nodeC = nodeC.parentNode;
  2212. }
  2213. if (nodeC) {
  2214. return K(nodeC).index() >= posA ? -1 : 1;
  2215. }
  2216. nodeC = nodeA;
  2217. while (nodeC && nodeC.parentNode !== nodeB) {
  2218. nodeC = nodeC.parentNode;
  2219. }
  2220. if (nodeC) {
  2221. return K(nodeC).index() >= posB ? 1 : -1;
  2222. }
  2223. nodeC = K(nodeB).next();
  2224. if (nodeC && nodeC.contains(nodeA)) {
  2225. return 1;
  2226. }
  2227. nodeC = K(nodeA).next();
  2228. if (nodeC && nodeC.contains(nodeB)) {
  2229. return -1;
  2230. }
  2231. } else {
  2232. return rangeA.compareBoundaryPoints(how, rangeB);
  2233. }
  2234. },
  2235. cloneRange : function() {
  2236. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2237. },
  2238. toString : function() {
  2239. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2240. return str.replace(/\r\n|\n|\r/g, '');
  2241. },
  2242. cloneContents : function() {
  2243. return _copyAndDelete(this, true, false);
  2244. },
  2245. deleteContents : function() {
  2246. return _copyAndDelete(this, false, true);
  2247. },
  2248. extractContents : function() {
  2249. return _copyAndDelete(this, true, true);
  2250. },
  2251. insertNode : function(node) {
  2252. var self = this,
  2253. sc = self.startContainer, so = self.startOffset,
  2254. ec = self.endContainer, eo = self.endOffset,
  2255. firstChild, lastChild, c, nodeCount = 1;
  2256. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2257. firstChild = node.firstChild;
  2258. lastChild = node.lastChild;
  2259. nodeCount = node.childNodes.length;
  2260. }
  2261. if (sc.nodeType == 1) {
  2262. c = sc.childNodes[so];
  2263. if (c) {
  2264. sc.insertBefore(node, c);
  2265. if (sc === ec) {
  2266. eo += nodeCount;
  2267. }
  2268. } else {
  2269. sc.appendChild(node);
  2270. }
  2271. } else if (sc.nodeType == 3) {
  2272. if (so === 0) {
  2273. sc.parentNode.insertBefore(node, sc);
  2274. if (sc.parentNode === ec) {
  2275. eo += nodeCount;
  2276. }
  2277. } else if (so >= sc.nodeValue.length) {
  2278. if (sc.nextSibling) {
  2279. sc.parentNode.insertBefore(node, sc.nextSibling);
  2280. } else {
  2281. sc.parentNode.appendChild(node);
  2282. }
  2283. } else {
  2284. if (so > 0) {
  2285. c = sc.splitText(so);
  2286. } else {
  2287. c = sc;
  2288. }
  2289. sc.parentNode.insertBefore(node, c);
  2290. if (sc === ec) {
  2291. ec = c;
  2292. eo -= so;
  2293. }
  2294. }
  2295. }
  2296. if (firstChild) {
  2297. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2298. } else {
  2299. self.selectNode(node);
  2300. }
  2301. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2302. return self;
  2303. }
  2304. return self.setEnd(ec, eo);
  2305. },
  2306. surroundContents : function(node) {
  2307. node.appendChild(this.extractContents());
  2308. return this.insertNode(node).selectNode(node);
  2309. },
  2310. isControl : function() {
  2311. var self = this,
  2312. sc = self.startContainer, so = self.startOffset,
  2313. ec = self.endContainer, eo = self.endOffset, rng;
  2314. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2315. },
  2316. get : function(hasControlRange) {
  2317. var self = this, doc = self.doc, node, rng;
  2318. if (!_IERANGE) {
  2319. rng = doc.createRange();
  2320. try {
  2321. rng.setStart(self.startContainer, self.startOffset);
  2322. rng.setEnd(self.endContainer, self.endOffset);
  2323. } catch (e) {}
  2324. return rng;
  2325. }
  2326. if (hasControlRange && self.isControl()) {
  2327. rng = doc.body.createControlRange();
  2328. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2329. return rng;
  2330. }
  2331. var range = self.cloneRange().down();
  2332. rng = doc.body.createTextRange();
  2333. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2334. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2335. return rng;
  2336. },
  2337. html : function() {
  2338. return K(this.cloneContents()).outer();
  2339. },
  2340. down : function() {
  2341. var self = this;
  2342. function downPos(node, pos, isStart) {
  2343. if (node.nodeType != 1) {
  2344. return;
  2345. }
  2346. var children = K(node).children();
  2347. if (children.length === 0) {
  2348. return;
  2349. }
  2350. var left, right, child, offset;
  2351. if (pos > 0) {
  2352. left = children.eq(pos - 1);
  2353. }
  2354. if (pos < children.length) {
  2355. right = children.eq(pos);
  2356. }
  2357. if (left && left.type == 3) {
  2358. child = left[0];
  2359. offset = child.nodeValue.length;
  2360. }
  2361. if (right && right.type == 3) {
  2362. child = right[0];
  2363. offset = 0;
  2364. }
  2365. if (!child) {
  2366. return;
  2367. }
  2368. if (isStart) {
  2369. self.setStart(child, offset);
  2370. } else {
  2371. self.setEnd(child, offset);
  2372. }
  2373. }
  2374. downPos(self.startContainer, self.startOffset, true);
  2375. downPos(self.endContainer, self.endOffset, false);
  2376. return self;
  2377. },
  2378. up : function() {
  2379. var self = this;
  2380. function upPos(node, pos, isStart) {
  2381. if (node.nodeType != 3) {
  2382. return;
  2383. }
  2384. if (pos === 0) {
  2385. if (isStart) {
  2386. self.setStartBefore(node);
  2387. } else {
  2388. self.setEndBefore(node);
  2389. }
  2390. } else if (pos == node.nodeValue.length) {
  2391. if (isStart) {
  2392. self.setStartAfter(node);
  2393. } else {
  2394. self.setEndAfter(node);
  2395. }
  2396. }
  2397. }
  2398. upPos(self.startContainer, self.startOffset, true);
  2399. upPos(self.endContainer, self.endOffset, false);
  2400. return self;
  2401. },
  2402. enlarge : function(toBlock) {
  2403. var self = this;
  2404. self.up();
  2405. function enlargePos(node, pos, isStart) {
  2406. var knode = K(node), parent;
  2407. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2408. return;
  2409. }
  2410. if (pos === 0) {
  2411. while (!knode.prev()) {
  2412. parent = knode.parent();
  2413. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2414. break;
  2415. }
  2416. knode = parent;
  2417. }
  2418. if (isStart) {
  2419. self.setStartBefore(knode[0]);
  2420. } else {
  2421. self.setEndBefore(knode[0]);
  2422. }
  2423. } else if (pos == knode.children().length) {
  2424. while (!knode.next()) {
  2425. parent = knode.parent();
  2426. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2427. break;
  2428. }
  2429. knode = parent;
  2430. }
  2431. if (isStart) {
  2432. self.setStartAfter(knode[0]);
  2433. } else {
  2434. self.setEndAfter(knode[0]);
  2435. }
  2436. }
  2437. }
  2438. enlargePos(self.startContainer, self.startOffset, true);
  2439. enlargePos(self.endContainer, self.endOffset, false);
  2440. return self;
  2441. },
  2442. shrink : function() {
  2443. var self = this, child, collapsed = self.collapsed;
  2444. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2445. self.setStart(child, 0);
  2446. }
  2447. if (collapsed) {
  2448. return self.collapse(collapsed);
  2449. }
  2450. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2451. self.setEnd(child, child.childNodes.length);
  2452. }
  2453. return self;
  2454. },
  2455. createBookmark : function(serialize) {
  2456. var self = this, doc = self.doc, endNode,
  2457. startNode = K('<span style="display:none;"></span>', doc)[0];
  2458. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2459. if (!self.collapsed) {
  2460. endNode = startNode.cloneNode(true);
  2461. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2462. }
  2463. if (endNode) {
  2464. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2465. }
  2466. self.insertNode(startNode).setStartAfter(startNode);
  2467. return {
  2468. start : serialize ? '#' + startNode.id : startNode,
  2469. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2470. };
  2471. },
  2472. moveToBookmark : function(bookmark) {
  2473. var self = this, doc = self.doc,
  2474. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2475. if (!start || start.length < 1) {
  2476. return self;
  2477. }
  2478. self.setStartBefore(start[0]);
  2479. start.remove();
  2480. if (end && end.length > 0) {
  2481. self.setEndBefore(end[0]);
  2482. end.remove();
  2483. } else {
  2484. self.collapse(true);
  2485. }
  2486. return self;
  2487. },
  2488. dump : function() {
  2489. console.log('--------------------');
  2490. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2491. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2492. }
  2493. });
  2494. function _range(mixed) {
  2495. if (!mixed.nodeName) {
  2496. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2497. }
  2498. return new KRange(mixed);
  2499. }
  2500. K.RangeClass = KRange;
  2501. K.range = _range;
  2502. K.START_TO_START = _START_TO_START;
  2503. K.START_TO_END = _START_TO_END;
  2504. K.END_TO_END = _END_TO_END;
  2505. K.END_TO_START = _END_TO_START;
  2506. function _nativeCommand(doc, key, val) {
  2507. try {
  2508. doc.execCommand(key, false, val);
  2509. } catch(e) {}
  2510. }
  2511. function _nativeCommandValue(doc, key) {
  2512. var val = '';
  2513. try {
  2514. val = doc.queryCommandValue(key);
  2515. } catch (e) {}
  2516. if (typeof val !== 'string') {
  2517. val = '';
  2518. }
  2519. return val;
  2520. }
  2521. function _getSel(doc) {
  2522. var win = _getWin(doc);
  2523. return _IERANGE ? doc.selection : win.getSelection();
  2524. }
  2525. function _getRng(doc) {
  2526. var sel = _getSel(doc), rng;
  2527. try {
  2528. if (sel.rangeCount > 0) {
  2529. rng = sel.getRangeAt(0);
  2530. } else {
  2531. rng = sel.createRange();
  2532. }
  2533. } catch(e) {}
  2534. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2535. return null;
  2536. }
  2537. return rng;
  2538. }
  2539. function _singleKeyMap(map) {
  2540. var newMap = {}, arr, v;
  2541. _each(map, function(key, val) {
  2542. arr = key.split(',');
  2543. for (var i = 0, len = arr.length; i < len; i++) {
  2544. v = arr[i];
  2545. newMap[v] = val;
  2546. }
  2547. });
  2548. return newMap;
  2549. }
  2550. function _hasAttrOrCss(knode, map) {
  2551. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2552. }
  2553. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2554. mapKey = mapKey || knode.name;
  2555. if (knode.type !== 1) {
  2556. return false;
  2557. }
  2558. var newMap = _singleKeyMap(map);
  2559. if (!newMap[mapKey]) {
  2560. return false;
  2561. }
  2562. var arr = newMap[mapKey].split(',');
  2563. for (var i = 0, len = arr.length; i < len; i++) {
  2564. var key = arr[i];
  2565. if (key === '*') {
  2566. return true;
  2567. }
  2568. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2569. var method = match[1] ? 'css' : 'attr';
  2570. key = match[2];
  2571. var val = match[3] || '';
  2572. if (val === '' && knode[method](key) !== '') {
  2573. return true;
  2574. }
  2575. if (val !== '' && knode[method](key) === val) {
  2576. return true;
  2577. }
  2578. }
  2579. return false;
  2580. }
  2581. function _removeAttrOrCss(knode, map) {
  2582. if (knode.type != 1) {
  2583. return;
  2584. }
  2585. _removeAttrOrCssByKey(knode, map, '*');
  2586. _removeAttrOrCssByKey(knode, map);
  2587. }
  2588. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2589. mapKey = mapKey || knode.name;
  2590. if (knode.type !== 1) {
  2591. return;
  2592. }
  2593. var newMap = _singleKeyMap(map);
  2594. if (!newMap[mapKey]) {
  2595. return;
  2596. }
  2597. var arr = newMap[mapKey].split(','), allFlag = false;
  2598. for (var i = 0, len = arr.length; i < len; i++) {
  2599. var key = arr[i];
  2600. if (key === '*') {
  2601. allFlag = true;
  2602. break;
  2603. }
  2604. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2605. key = match[2];
  2606. if (match[1]) {
  2607. key = _toCamel(key);
  2608. if (knode[0].style[key]) {
  2609. knode[0].style[key] = '';
  2610. }
  2611. } else {
  2612. knode.removeAttr(key);
  2613. }
  2614. }
  2615. if (allFlag) {
  2616. knode.remove(true);
  2617. }
  2618. }
  2619. function _getInnerNode(knode) {
  2620. var inner = knode;
  2621. while (inner.first()) {
  2622. inner = inner.first();
  2623. }
  2624. return inner;
  2625. }
  2626. function _isEmptyNode(knode) {
  2627. if (knode.type != 1 || knode.isSingle()) {
  2628. return false;
  2629. }
  2630. return knode.html().replace(/<[^>]+>/g, '') === '';
  2631. }
  2632. function _mergeWrapper(a, b) {
  2633. a = a.clone(true);
  2634. var lastA = _getInnerNode(a), childA = a, merged = false;
  2635. while (b) {
  2636. while (childA) {
  2637. if (childA.name === b.name) {
  2638. _mergeAttrs(childA, b.attr(), b.css());
  2639. merged = true;
  2640. }
  2641. childA = childA.first();
  2642. }
  2643. if (!merged) {
  2644. lastA.append(b.clone(false));
  2645. }
  2646. merged = false;
  2647. b = b.first();
  2648. }
  2649. return a;
  2650. }
  2651. function _wrapNode(knode, wrapper) {
  2652. wrapper = wrapper.clone(true);
  2653. if (knode.type == 3) {
  2654. _getInnerNode(wrapper).append(knode.clone(false));
  2655. knode.replaceWith(wrapper);
  2656. return wrapper;
  2657. }
  2658. var nodeWrapper = knode, child;
  2659. while ((child = knode.first()) && child.children().length == 1) {
  2660. knode = child;
  2661. }
  2662. child = knode.first();
  2663. var frag = knode.doc.createDocumentFragment();
  2664. while (child) {
  2665. frag.appendChild(child[0]);
  2666. child = child.next();
  2667. }
  2668. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2669. if (frag.firstChild) {
  2670. _getInnerNode(wrapper).append(frag);
  2671. }
  2672. nodeWrapper.replaceWith(wrapper);
  2673. return wrapper;
  2674. }
  2675. function _mergeAttrs(knode, attrs, styles) {
  2676. _each(attrs, function(key, val) {
  2677. if (key !== 'style') {
  2678. knode.attr(key, val);
  2679. }
  2680. });
  2681. _each(styles, function(key, val) {
  2682. knode.css(key, val);
  2683. });
  2684. }
  2685. function _inPreElement(knode) {
  2686. while (knode && knode.name != 'body') {
  2687. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2688. return true;
  2689. }
  2690. knode = knode.parent();
  2691. }
  2692. return false;
  2693. }
  2694. function KCmd(range) {
  2695. this.init(range);
  2696. }
  2697. _extend(KCmd, {
  2698. init : function(range) {
  2699. var self = this, doc = range.doc;
  2700. self.doc = doc;
  2701. self.win = _getWin(doc);
  2702. self.sel = _getSel(doc);
  2703. self.range = range;
  2704. },
  2705. selection : function(forceReset) {
  2706. var self = this, doc = self.doc, rng = _getRng(doc);
  2707. self.sel = _getSel(doc);
  2708. if (rng) {
  2709. self.range = _range(rng);
  2710. if (K(self.range.startContainer).name == 'html') {
  2711. self.range.selectNodeContents(doc.body).collapse(false);
  2712. }
  2713. return self;
  2714. }
  2715. if (forceReset) {
  2716. self.range.selectNodeContents(doc.body).collapse(false);
  2717. }
  2718. return self;
  2719. },
  2720. select : function(hasDummy) {
  2721. hasDummy = _undef(hasDummy, true);
  2722. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2723. sc = range.startContainer, so = range.startOffset,
  2724. ec = range.endContainer, eo = range.endOffset,
  2725. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2726. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2727. if (_IERANGE) {
  2728. var dummy = K('<span>&nbsp;</span>', doc);
  2729. range.insertNode(dummy[0]);
  2730. rng = doc.body.createTextRange();
  2731. try {
  2732. rng.moveToElementText(dummy[0]);
  2733. } catch(ex) {}
  2734. rng.collapse(false);
  2735. rng.select();
  2736. dummy.remove();
  2737. win.focus();
  2738. return self;
  2739. }
  2740. if (_WEBKIT) {
  2741. var children = sc.childNodes;
  2742. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2743. range.insertNode(doc.createTextNode('\u200B'));
  2744. hasU200b = true;
  2745. }
  2746. }
  2747. }
  2748. if (_IERANGE) {
  2749. try {
  2750. rng = range.get(true);
  2751. rng.select();
  2752. } catch(e) {}
  2753. } else {
  2754. if (hasU200b) {
  2755. range.collapse(false);
  2756. }
  2757. rng = range.get(true);
  2758. sel.removeAllRanges();
  2759. sel.addRange(rng);
  2760. if (doc !== document) {
  2761. var pos = K(rng.endContainer).pos();
  2762. win.scrollTo(pos.x, pos.y);
  2763. }
  2764. }
  2765. win.focus();
  2766. return self;
  2767. },
  2768. wrap : function(val) {
  2769. var self = this, doc = self.doc, range = self.range, wrapper;
  2770. wrapper = K(val, doc);
  2771. if (range.collapsed) {
  2772. range.shrink();
  2773. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2774. return self;
  2775. }
  2776. if (wrapper.isBlock()) {
  2777. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2778. while (child.first()) {
  2779. child = child.first();
  2780. }
  2781. child.append(range.extractContents());
  2782. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2783. return self;
  2784. }
  2785. range.enlarge();
  2786. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2787. K(ancestor).scan(function(node) {
  2788. if (!isStart && node == bookmark.start) {
  2789. isStart = true;
  2790. return;
  2791. }
  2792. if (isStart) {
  2793. if (node == bookmark.end) {
  2794. return false;
  2795. }
  2796. var knode = K(node);
  2797. if (_inPreElement(knode)) {
  2798. return;
  2799. }
  2800. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2801. var parent;
  2802. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2803. knode = parent;
  2804. }
  2805. _wrapNode(knode, wrapper);
  2806. }
  2807. }
  2808. });
  2809. range.moveToBookmark(bookmark);
  2810. return self;
  2811. },
  2812. split : function(isStart, map) {
  2813. var range = this.range, doc = range.doc;
  2814. var tempRange = range.cloneRange().collapse(isStart);
  2815. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2816. parent = node.nodeType == 3 ? node.parentNode : node,
  2817. needSplit = false, knode;
  2818. while (parent && parent.parentNode) {
  2819. knode = K(parent);
  2820. if (map) {
  2821. if (!knode.isStyle()) {
  2822. break;
  2823. }
  2824. if (!_hasAttrOrCss(knode, map)) {
  2825. break;
  2826. }
  2827. } else {
  2828. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2829. break;
  2830. }
  2831. }
  2832. needSplit = true;
  2833. parent = parent.parentNode;
  2834. }
  2835. if (needSplit) {
  2836. var dummy = doc.createElement('span');
  2837. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2838. if (isStart) {
  2839. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2840. } else {
  2841. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2842. }
  2843. var frag = tempRange.extractContents(),
  2844. first = frag.firstChild, last = frag.lastChild;
  2845. if (isStart) {
  2846. tempRange.insertNode(frag);
  2847. range.setStartAfter(last).setEndBefore(dummy);
  2848. } else {
  2849. parent.appendChild(frag);
  2850. range.setStartBefore(dummy).setEndBefore(first);
  2851. }
  2852. var dummyParent = dummy.parentNode;
  2853. if (dummyParent == range.endContainer) {
  2854. var prev = K(dummy).prev(), next = K(dummy).next();
  2855. if (prev && next && prev.type == 3 && next.type == 3) {
  2856. range.setEnd(prev[0], prev[0].nodeValue.length);
  2857. } else if (!isStart) {
  2858. range.setEnd(range.endContainer, range.endOffset - 1);
  2859. }
  2860. }
  2861. dummyParent.removeChild(dummy);
  2862. }
  2863. return this;
  2864. },
  2865. remove : function(map) {
  2866. var self = this, doc = self.doc, range = self.range;
  2867. range.enlarge();
  2868. if (range.startOffset === 0) {
  2869. var ksc = K(range.startContainer), parent;
  2870. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2871. ksc = parent;
  2872. }
  2873. range.setStart(ksc[0], 0);
  2874. ksc = K(range.startContainer);
  2875. if (ksc.isBlock()) {
  2876. _removeAttrOrCss(ksc, map);
  2877. }
  2878. var kscp = ksc.parent();
  2879. if (kscp && kscp.isBlock()) {
  2880. _removeAttrOrCss(kscp, map);
  2881. }
  2882. }
  2883. var sc, so;
  2884. if (range.collapsed) {
  2885. self.split(true, map);
  2886. sc = range.startContainer;
  2887. so = range.startOffset;
  2888. if (so > 0) {
  2889. var sb = K(sc.childNodes[so - 1]);
  2890. if (sb && _isEmptyNode(sb)) {
  2891. sb.remove();
  2892. range.setStart(sc, so - 1);
  2893. }
  2894. }
  2895. var sa = K(sc.childNodes[so]);
  2896. if (sa && _isEmptyNode(sa)) {
  2897. sa.remove();
  2898. }
  2899. if (_isEmptyNode(sc)) {
  2900. range.startBefore(sc);
  2901. sc.remove();
  2902. }
  2903. range.collapse(true);
  2904. return self;
  2905. }
  2906. self.split(true, map);
  2907. self.split(false, map);
  2908. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2909. range.cloneRange().collapse(false).insertNode(endDummy);
  2910. range.cloneRange().collapse(true).insertNode(startDummy);
  2911. var nodeList = [], cmpStart = false;
  2912. K(range.commonAncestor()).scan(function(node) {
  2913. if (!cmpStart && node == startDummy) {
  2914. cmpStart = true;
  2915. return;
  2916. }
  2917. if (node == endDummy) {
  2918. return false;
  2919. }
  2920. if (cmpStart) {
  2921. nodeList.push(node);
  2922. }
  2923. });
  2924. K(startDummy).remove();
  2925. K(endDummy).remove();
  2926. sc = range.startContainer;
  2927. so = range.startOffset;
  2928. var ec = range.endContainer, eo = range.endOffset;
  2929. if (so > 0) {
  2930. var startBefore = K(sc.childNodes[so - 1]);
  2931. if (startBefore && _isEmptyNode(startBefore)) {
  2932. startBefore.remove();
  2933. range.setStart(sc, so - 1);
  2934. if (sc == ec) {
  2935. range.setEnd(ec, eo - 1);
  2936. }
  2937. }
  2938. var startAfter = K(sc.childNodes[so]);
  2939. if (startAfter && _isEmptyNode(startAfter)) {
  2940. startAfter.remove();
  2941. if (sc == ec) {
  2942. range.setEnd(ec, eo - 1);
  2943. }
  2944. }
  2945. }
  2946. var endAfter = K(ec.childNodes[range.endOffset]);
  2947. if (endAfter && _isEmptyNode(endAfter)) {
  2948. endAfter.remove();
  2949. }
  2950. var bookmark = range.createBookmark(true);
  2951. _each(nodeList, function(i, node) {
  2952. _removeAttrOrCss(K(node), map);
  2953. });
  2954. range.moveToBookmark(bookmark);
  2955. return self;
  2956. },
  2957. commonNode : function(map) {
  2958. var range = this.range;
  2959. var ec = range.endContainer, eo = range.endOffset,
  2960. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2961. function find(node) {
  2962. var child = node, parent = node;
  2963. while (parent) {
  2964. if (_hasAttrOrCss(K(parent), map)) {
  2965. return K(parent);
  2966. }
  2967. parent = parent.parentNode;
  2968. }
  2969. while (child && (child = child.lastChild)) {
  2970. if (_hasAttrOrCss(K(child), map)) {
  2971. return K(child);
  2972. }
  2973. }
  2974. return null;
  2975. }
  2976. var cNode = find(node);
  2977. if (cNode) {
  2978. return cNode;
  2979. }
  2980. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2981. var prev = K(node).prev();
  2982. if (prev) {
  2983. return find(prev);
  2984. }
  2985. }
  2986. return null;
  2987. },
  2988. commonAncestor : function(tagName) {
  2989. var range = this.range,
  2990. sc = range.startContainer, so = range.startOffset,
  2991. ec = range.endContainer, eo = range.endOffset,
  2992. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2993. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2994. function find(node) {
  2995. while (node) {
  2996. if (node.nodeType == 1) {
  2997. if (node.tagName.toLowerCase() === tagName) {
  2998. return node;
  2999. }
  3000. }
  3001. node = node.parentNode;
  3002. }
  3003. return null;
  3004. }
  3005. var start = find(startNode), end = find(endNode);
  3006. if (start && end && start === end) {
  3007. return K(start);
  3008. }
  3009. return null;
  3010. },
  3011. state : function(key) {
  3012. var self = this, doc = self.doc, bool = false;
  3013. try {
  3014. bool = doc.queryCommandState(key);
  3015. } catch (e) {}
  3016. return bool;
  3017. },
  3018. val : function(key) {
  3019. var self = this, doc = self.doc, range = self.range;
  3020. function lc(val) {
  3021. return val.toLowerCase();
  3022. }
  3023. key = lc(key);
  3024. var val = '', knode;
  3025. if (key === 'fontfamily' || key === 'fontname') {
  3026. val = _nativeCommandValue(doc, 'fontname');
  3027. val = val.replace(/['"]/g, '');
  3028. return lc(val);
  3029. }
  3030. if (key === 'formatblock') {
  3031. val = _nativeCommandValue(doc, key);
  3032. if (val === '') {
  3033. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3034. if (knode) {
  3035. val = knode.name;
  3036. }
  3037. }
  3038. if (val === 'Normal') {
  3039. val = 'p';
  3040. }
  3041. return lc(val);
  3042. }
  3043. if (key === 'fontsize') {
  3044. knode = self.commonNode({'*' : '.font-size'});
  3045. if (knode) {
  3046. val = knode.css('font-size');
  3047. }
  3048. return lc(val);
  3049. }
  3050. if (key === 'forecolor') {
  3051. knode = self.commonNode({'*' : '.color'});
  3052. if (knode) {
  3053. val = knode.css('color');
  3054. }
  3055. val = _toHex(val);
  3056. if (val === '') {
  3057. val = 'default';
  3058. }
  3059. return lc(val);
  3060. }
  3061. if (key === 'hilitecolor') {
  3062. knode = self.commonNode({'*' : '.background-color'});
  3063. if (knode) {
  3064. val = knode.css('background-color');
  3065. }
  3066. val = _toHex(val);
  3067. if (val === '') {
  3068. val = 'default';
  3069. }
  3070. return lc(val);
  3071. }
  3072. return val;
  3073. },
  3074. toggle : function(wrapper, map) {
  3075. var self = this;
  3076. if (self.commonNode(map)) {
  3077. self.remove(map);
  3078. } else {
  3079. self.wrap(wrapper);
  3080. }
  3081. return self.select();
  3082. },
  3083. bold : function() {
  3084. return this.toggle('<strong></strong>', {
  3085. span : '.font-weight=bold',
  3086. strong : '*',
  3087. b : '*'
  3088. });
  3089. },
  3090. italic : function() {
  3091. return this.toggle('<em></em>', {
  3092. span : '.font-style=italic',
  3093. em : '*',
  3094. i : '*'
  3095. });
  3096. },
  3097. underline : function() {
  3098. return this.toggle('<u></u>', {
  3099. span : '.text-decoration=underline',
  3100. u : '*'
  3101. });
  3102. },
  3103. strikethrough : function() {
  3104. return this.toggle('<s></s>', {
  3105. span : '.text-decoration=line-through',
  3106. s : '*'
  3107. });
  3108. },
  3109. forecolor : function(val) {
  3110. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3111. },
  3112. hilitecolor : function(val) {
  3113. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3114. },
  3115. fontsize : function(val) {
  3116. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3117. },
  3118. fontname : function(val) {
  3119. return this.fontfamily(val);
  3120. },
  3121. fontfamily : function(val) {
  3122. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3123. },
  3124. removeformat : function() {
  3125. var map = {
  3126. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3127. },
  3128. tags = _STYLE_TAG_MAP;
  3129. _each(tags, function(key, val) {
  3130. map[key] = '*';
  3131. });
  3132. this.remove(map);
  3133. return this.select();
  3134. },
  3135. inserthtml : function(val, quickMode) {
  3136. var self = this, range = self.range;
  3137. if (val === '') {
  3138. return self;
  3139. }
  3140. function pasteHtml(range, val) {
  3141. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3142. var rng = range.get();
  3143. if (rng.item) {
  3144. rng.item(0).outerHTML = val;
  3145. } else {
  3146. rng.pasteHTML(val);
  3147. }
  3148. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3149. temp.parentNode.removeChild(temp);
  3150. var newRange = _toRange(rng);
  3151. range.setEnd(newRange.endContainer, newRange.endOffset);
  3152. range.collapse(false);
  3153. self.select(false);
  3154. }
  3155. function insertHtml(range, val) {
  3156. var doc = range.doc,
  3157. frag = doc.createDocumentFragment();
  3158. K('@' + val, doc).each(function() {
  3159. frag.appendChild(this);
  3160. });
  3161. range.deleteContents();
  3162. range.insertNode(frag);
  3163. range.collapse(false);
  3164. self.select(false);
  3165. }
  3166. if (_IERANGE && quickMode) {
  3167. try {
  3168. pasteHtml(range, val);
  3169. } catch(e) {
  3170. insertHtml(range, val);
  3171. }
  3172. return self;
  3173. }
  3174. insertHtml(range, val);
  3175. return self;
  3176. },
  3177. hr : function() {
  3178. return this.inserthtml('<hr />');
  3179. },
  3180. print : function() {
  3181. this.win.print();
  3182. return this;
  3183. },
  3184. insertimage : function(url, title, width, height, border, align) {
  3185. title = _undef(title, '');
  3186. border = _undef(border, 0);
  3187. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3188. if (width) {
  3189. html += 'width="' + _escape(width) + '" ';
  3190. }
  3191. if (height) {
  3192. html += 'height="' + _escape(height) + '" ';
  3193. }
  3194. if (title) {
  3195. html += 'title="' + _escape(title) + '" ';
  3196. }
  3197. if (align) {
  3198. html += 'align="' + _escape(align) + '" ';
  3199. }
  3200. html += 'alt="' + _escape(title) + '" ';
  3201. html += '/>';
  3202. return this.inserthtml(html);
  3203. },
  3204. createlink : function(url, type) {
  3205. var self = this, doc = self.doc, range = self.range;
  3206. self.select();
  3207. var a = self.commonNode({ a : '*' });
  3208. if (a && !range.isControl()) {
  3209. range.selectNode(a.get());
  3210. self.select();
  3211. }
  3212. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3213. if (type) {
  3214. html += ' target="' + _escape(type) + '"';
  3215. }
  3216. if (range.collapsed) {
  3217. html += '>' + _escape(url) + '</a>';
  3218. return self.inserthtml(html);
  3219. }
  3220. if (range.isControl()) {
  3221. var node = K(range.startContainer.childNodes[range.startOffset]);
  3222. html += '></a>';
  3223. node.after(K(html, doc));
  3224. node.next().append(node);
  3225. range.selectNode(node[0]);
  3226. return self.select();
  3227. }
  3228. function setAttr(node, url, type) {
  3229. K(node).attr('href', url).attr('data-ke-src', url);
  3230. if (type) {
  3231. K(node).attr('target', type);
  3232. } else {
  3233. K(node).removeAttr('target');
  3234. }
  3235. }
  3236. var sc = range.startContainer, so = range.startOffset,
  3237. ec = range.endContainer, eo = range.endOffset;
  3238. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3239. var child = sc.childNodes[so];
  3240. if (child.nodeName.toLowerCase() == 'a') {
  3241. setAttr(child, url, type);
  3242. return self;
  3243. }
  3244. }
  3245. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3246. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3247. setAttr(this, url, type);
  3248. });
  3249. return self;
  3250. },
  3251. unlink : function() {
  3252. var self = this, doc = self.doc, range = self.range;
  3253. self.select();
  3254. if (range.collapsed) {
  3255. var a = self.commonNode({ a : '*' });
  3256. if (a) {
  3257. range.selectNode(a.get());
  3258. self.select();
  3259. }
  3260. _nativeCommand(doc, 'unlink', null);
  3261. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3262. var parent = K(range.startContainer).parent();
  3263. if (parent.name === 'a') {
  3264. parent.remove(true);
  3265. }
  3266. }
  3267. } else {
  3268. _nativeCommand(doc, 'unlink', null);
  3269. }
  3270. return self;
  3271. }
  3272. });
  3273. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3274. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3275. KCmd.prototype[name] = function(val) {
  3276. var self = this;
  3277. self.select();
  3278. _nativeCommand(self.doc, name, val);
  3279. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3280. self.selection();
  3281. }
  3282. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3283. self.selection();
  3284. }
  3285. return self;
  3286. };
  3287. });
  3288. _each('cut,copy,paste'.split(','), function(i, name) {
  3289. KCmd.prototype[name] = function() {
  3290. var self = this;
  3291. if (!self.doc.queryCommandSupported(name)) {
  3292. throw 'not supported';
  3293. }
  3294. self.select();
  3295. _nativeCommand(self.doc, name, null);
  3296. return self;
  3297. };
  3298. });
  3299. function _cmd(mixed) {
  3300. if (mixed.nodeName) {
  3301. var doc = _getDoc(mixed);
  3302. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3303. }
  3304. return new KCmd(mixed);
  3305. }
  3306. K.CmdClass = KCmd;
  3307. K.cmd = _cmd;
  3308. function _drag(options) {
  3309. var moveEl = options.moveEl,
  3310. moveFn = options.moveFn,
  3311. clickEl = options.clickEl || moveEl,
  3312. beforeDrag = options.beforeDrag,
  3313. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3314. var docs = [document];
  3315. if (iframeFix) {
  3316. K('iframe').each(function() {
  3317. var src = _formatUrl(this.src || '', 'absolute');
  3318. if (/^https?:\/\//.test(src)) {
  3319. return;
  3320. }
  3321. var doc;
  3322. try {
  3323. doc = _iframeDoc(this);
  3324. } catch(e) {}
  3325. if (doc) {
  3326. var pos = K(this).pos();
  3327. K(doc).data('pos-x', pos.x);
  3328. K(doc).data('pos-y', pos.y);
  3329. docs.push(doc);
  3330. }
  3331. });
  3332. }
  3333. clickEl.mousedown(function(e) {
  3334. e.stopPropagation();
  3335. var self = clickEl.get(),
  3336. x = _removeUnit(moveEl.css('left')),
  3337. y = _removeUnit(moveEl.css('top')),
  3338. width = moveEl.width(),
  3339. height = moveEl.height(),
  3340. pageX = e.pageX,
  3341. pageY = e.pageY;
  3342. if (beforeDrag) {
  3343. beforeDrag();
  3344. }
  3345. function moveListener(e) {
  3346. e.preventDefault();
  3347. var kdoc = K(_getDoc(e.target));
  3348. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3349. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3350. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3351. }
  3352. function selectListener(e) {
  3353. e.preventDefault();
  3354. }
  3355. function upListener(e) {
  3356. e.preventDefault();
  3357. K(docs).unbind('mousemove', moveListener)
  3358. .unbind('mouseup', upListener)
  3359. .unbind('selectstart', selectListener);
  3360. if (self.releaseCapture) {
  3361. self.releaseCapture();
  3362. }
  3363. }
  3364. K(docs).mousemove(moveListener)
  3365. .mouseup(upListener)
  3366. .bind('selectstart', selectListener);
  3367. if (self.setCapture) {
  3368. self.setCapture();
  3369. }
  3370. });
  3371. }
  3372. function KWidget(options) {
  3373. this.init(options);
  3374. }
  3375. _extend(KWidget, {
  3376. init : function(options) {
  3377. var self = this;
  3378. self.name = options.name || '';
  3379. self.doc = options.doc || document;
  3380. self.win = _getWin(self.doc);
  3381. self.x = _addUnit(options.x);
  3382. self.y = _addUnit(options.y);
  3383. self.z = options.z;
  3384. self.width = _addUnit(options.width);
  3385. self.height = _addUnit(options.height);
  3386. self.div = K('<div style="display:block;"></div>');
  3387. self.options = options;
  3388. self._alignEl = options.alignEl;
  3389. if (self.width) {
  3390. self.div.css('width', self.width);
  3391. }
  3392. if (self.height) {
  3393. self.div.css('height', self.height);
  3394. }
  3395. if (self.z) {
  3396. self.div.css({
  3397. position : 'absolute',
  3398. left : self.x,
  3399. top : self.y,
  3400. 'z-index' : self.z
  3401. });
  3402. }
  3403. if (self.z && (self.x === undefined || self.y === undefined)) {
  3404. self.autoPos(self.width, self.height);
  3405. }
  3406. if (options.cls) {
  3407. self.div.addClass(options.cls);
  3408. }
  3409. if (options.shadowMode) {
  3410. self.div.addClass('ke-shadow');
  3411. }
  3412. if (options.css) {
  3413. self.div.css(options.css);
  3414. }
  3415. if (options.src) {
  3416. K(options.src).replaceWith(self.div);
  3417. } else {
  3418. K(self.doc.body).append(self.div);
  3419. }
  3420. if (options.html) {
  3421. self.div.html(options.html);
  3422. }
  3423. if (options.autoScroll) {
  3424. if (_IE && _V < 7 || _QUIRKS) {
  3425. var scrollPos = _getScrollPos();
  3426. K(self.win).bind('scroll', function(e) {
  3427. var pos = _getScrollPos(),
  3428. diffX = pos.x - scrollPos.x,
  3429. diffY = pos.y - scrollPos.y;
  3430. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3431. });
  3432. } else {
  3433. self.div.css('position', 'fixed');
  3434. }
  3435. }
  3436. },
  3437. pos : function(x, y, updateProp) {
  3438. var self = this;
  3439. updateProp = _undef(updateProp, true);
  3440. if (x !== null) {
  3441. x = x < 0 ? 0 : _addUnit(x);
  3442. self.div.css('left', x);
  3443. if (updateProp) {
  3444. self.x = x;
  3445. }
  3446. }
  3447. if (y !== null) {
  3448. y = y < 0 ? 0 : _addUnit(y);
  3449. self.div.css('top', y);
  3450. if (updateProp) {
  3451. self.y = y;
  3452. }
  3453. }
  3454. return self;
  3455. },
  3456. autoPos : function(width, height) {
  3457. var self = this,
  3458. w = _removeUnit(width) || 0,
  3459. h = _removeUnit(height) || 0,
  3460. scrollPos = _getScrollPos();
  3461. if (self._alignEl) {
  3462. var knode = K(self._alignEl),
  3463. pos = knode.pos(),
  3464. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3465. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3466. x = diffX < 0 ? pos.x : pos.x + diffX;
  3467. y = diffY < 0 ? pos.y : pos.y + diffY;
  3468. } else {
  3469. var docEl = _docElement(self.doc);
  3470. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3471. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3472. }
  3473. if (!(_IE && _V < 7 || _QUIRKS)) {
  3474. x -= scrollPos.x;
  3475. y -= scrollPos.y;
  3476. }
  3477. return self.pos(x, y);
  3478. },
  3479. remove : function() {
  3480. var self = this;
  3481. if (_IE && _V < 7 || _QUIRKS) {
  3482. K(self.win).unbind('scroll');
  3483. }
  3484. self.div.remove();
  3485. _each(self, function(i) {
  3486. self[i] = null;
  3487. });
  3488. return this;
  3489. },
  3490. show : function() {
  3491. this.div.show();
  3492. return this;
  3493. },
  3494. hide : function() {
  3495. this.div.hide();
  3496. return this;
  3497. },
  3498. draggable : function(options) {
  3499. var self = this;
  3500. options = options || {};
  3501. options.moveEl = self.div;
  3502. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3503. if ((x = x + diffX) < 0) {
  3504. x = 0;
  3505. }
  3506. if ((y = y + diffY) < 0) {
  3507. y = 0;
  3508. }
  3509. self.pos(x, y);
  3510. };
  3511. _drag(options);
  3512. return self;
  3513. }
  3514. });
  3515. function _widget(options) {
  3516. return new KWidget(options);
  3517. }
  3518. K.WidgetClass = KWidget;
  3519. K.widget = _widget;
  3520. function _iframeDoc(iframe) {
  3521. iframe = _get(iframe);
  3522. return iframe.contentDocument || iframe.contentWindow.document;
  3523. }
  3524. var html, _direction = '';
  3525. if ((html = document.getElementsByTagName('html'))) {
  3526. _direction = html[0].dir;
  3527. }
  3528. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3529. var arr = [
  3530. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3531. '<head><meta charset="utf-8" /><title></title>',
  3532. '<style>',
  3533. 'html {margin:0;padding:0;}',
  3534. 'body {margin:0;padding:5px;}',
  3535. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3536. 'body, p, div {word-wrap: break-word;}',
  3537. 'p {margin:5px 0;}',
  3538. 'table {border-collapse:collapse;}',
  3539. 'img {border:0;}',
  3540. 'noscript {display:none;}',
  3541. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3542. 'img.ke-flash {',
  3543. ' border:1px solid #AAA;',
  3544. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3545. ' background-position:center center;',
  3546. ' background-repeat:no-repeat;',
  3547. ' width:100px;',
  3548. ' height:100px;',
  3549. '}',
  3550. 'img.ke-rm {',
  3551. ' border:1px solid #AAA;',
  3552. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3553. ' background-position:center center;',
  3554. ' background-repeat:no-repeat;',
  3555. ' width:100px;',
  3556. ' height:100px;',
  3557. '}',
  3558. 'img.ke-media {',
  3559. ' border:1px solid #AAA;',
  3560. ' background-image:url(' + themesPath + 'common/media.gif);',
  3561. ' background-position:center center;',
  3562. ' background-repeat:no-repeat;',
  3563. ' width:100px;',
  3564. ' height:100px;',
  3565. '}',
  3566. 'img.ke-anchor {',
  3567. ' border:1px dashed #666;',
  3568. ' width:16px;',
  3569. ' height:16px;',
  3570. '}',
  3571. '.ke-script, .ke-noscript, .ke-display-none {',
  3572. ' display:none;',
  3573. ' font-size:0;',
  3574. ' width:0;',
  3575. ' height:0;',
  3576. '}',
  3577. '.ke-pagebreak {',
  3578. ' border:1px dotted #AAA;',
  3579. ' font-size:0;',
  3580. ' height:2px;',
  3581. '}',
  3582. '</style>'
  3583. ];
  3584. if (!_isArray(cssPath)) {
  3585. cssPath = [cssPath];
  3586. }
  3587. _each(cssPath, function(i, path) {
  3588. if (path) {
  3589. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3590. }
  3591. });
  3592. if (cssData) {
  3593. arr.push('<style>' + cssData + '</style>');
  3594. }
  3595. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3596. return arr.join('\n');
  3597. }
  3598. function _elementVal(knode, val) {
  3599. if (knode.hasVal()) {
  3600. if (val === undefined) {
  3601. var html = knode.val();
  3602. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3603. return html;
  3604. }
  3605. return knode.val(val);
  3606. }
  3607. return knode.html(val);
  3608. }
  3609. function KEdit(options) {
  3610. this.init(options);
  3611. }
  3612. _extend(KEdit, KWidget, {
  3613. init : function(options) {
  3614. var self = this;
  3615. KEdit.parent.init.call(self, options);
  3616. self.srcElement = K(options.srcElement);
  3617. self.div.addClass('ke-edit');
  3618. self.designMode = _undef(options.designMode, true);
  3619. self.beforeGetHtml = options.beforeGetHtml;
  3620. self.beforeSetHtml = options.beforeSetHtml;
  3621. self.afterSetHtml = options.afterSetHtml;
  3622. var themesPath = _undef(options.themesPath, ''),
  3623. bodyClass = options.bodyClass,
  3624. cssPath = options.cssPath,
  3625. cssData = options.cssData,
  3626. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3627. srcScript = ('document.open();' +
  3628. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3629. 'document.close();'),
  3630. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3631. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3632. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3633. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3634. self.iframe.attr('tabindex', self.tabIndex);
  3635. self.textarea.attr('tabindex', self.tabIndex);
  3636. if (self.width) {
  3637. self.setWidth(self.width);
  3638. }
  3639. if (self.height) {
  3640. self.setHeight(self.height);
  3641. }
  3642. if (self.designMode) {
  3643. self.textarea.hide();
  3644. } else {
  3645. self.iframe.hide();
  3646. }
  3647. function ready() {
  3648. var doc = _iframeDoc(self.iframe);
  3649. doc.open();
  3650. if (isDocumentDomain) {
  3651. doc.domain = document.domain;
  3652. }
  3653. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3654. doc.close();
  3655. self.win = self.iframe[0].contentWindow;
  3656. self.doc = doc;
  3657. var cmd = _cmd(doc);
  3658. self.afterChange(function(e) {
  3659. cmd.selection();
  3660. });
  3661. if (_WEBKIT) {
  3662. K(doc).click(function(e) {
  3663. if (K(e.target).name === 'img') {
  3664. cmd.selection(true);
  3665. cmd.range.selectNode(e.target);
  3666. cmd.select();
  3667. }
  3668. });
  3669. }
  3670. if (_IE) {
  3671. self._mousedownHandler = function() {
  3672. var newRange = cmd.range.cloneRange();
  3673. newRange.shrink();
  3674. if (newRange.isControl()) {
  3675. self.blur();
  3676. }
  3677. };
  3678. K(document).mousedown(self._mousedownHandler);
  3679. K(doc).keydown(function(e) {
  3680. if (e.which == 8) {
  3681. cmd.selection();
  3682. var rng = cmd.range;
  3683. if (rng.isControl()) {
  3684. rng.collapse(true);
  3685. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3686. e.preventDefault();
  3687. }
  3688. }
  3689. });
  3690. }
  3691. self.cmd = cmd;
  3692. self.html(_elementVal(self.srcElement));
  3693. if (_IE) {
  3694. doc.body.disabled = true;
  3695. doc.body.contentEditable = true;
  3696. doc.body.removeAttribute('disabled');
  3697. } else {
  3698. doc.designMode = 'on';
  3699. }
  3700. if (options.afterCreate) {
  3701. options.afterCreate.call(self);
  3702. }
  3703. }
  3704. if (isDocumentDomain) {
  3705. self.iframe.bind('load', function(e) {
  3706. self.iframe.unbind('load');
  3707. if (_IE) {
  3708. ready();
  3709. } else {
  3710. setTimeout(ready, 0);
  3711. }
  3712. });
  3713. }
  3714. self.div.append(self.iframe);
  3715. self.div.append(self.textarea);
  3716. self.srcElement.hide();
  3717. !isDocumentDomain && ready();
  3718. },
  3719. setWidth : function(val) {
  3720. var self = this;
  3721. val = _addUnit(val);
  3722. self.width = val;
  3723. self.div.css('width', val);
  3724. return self;
  3725. },
  3726. setHeight : function(val) {
  3727. var self = this;
  3728. val = _addUnit(val);
  3729. self.height = val;
  3730. self.div.css('height', val);
  3731. self.iframe.css('height', val);
  3732. if ((_IE && _V < 8) || _QUIRKS) {
  3733. val = _addUnit(_removeUnit(val) - 2);
  3734. }
  3735. self.textarea.css('height', val);
  3736. return self;
  3737. },
  3738. remove : function() {
  3739. var self = this, doc = self.doc;
  3740. K(doc.body).unbind();
  3741. K(doc).unbind();
  3742. K(self.win).unbind();
  3743. if (self._mousedownHandler) {
  3744. K(document).unbind('mousedown', self._mousedownHandler);
  3745. }
  3746. _elementVal(self.srcElement, self.html());
  3747. self.srcElement.show();
  3748. doc.write('');
  3749. self.iframe.unbind();
  3750. self.textarea.unbind();
  3751. KEdit.parent.remove.call(self);
  3752. },
  3753. html : function(val, isFull) {
  3754. var self = this, doc = self.doc;
  3755. if (self.designMode) {
  3756. var body = doc.body;
  3757. if (val === undefined) {
  3758. if (isFull) {
  3759. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3760. } else {
  3761. val = body.innerHTML;
  3762. }
  3763. if (self.beforeGetHtml) {
  3764. val = self.beforeGetHtml(val);
  3765. }
  3766. if (_GECKO && val == '<br />') {
  3767. val = '';
  3768. }
  3769. return val;
  3770. }
  3771. if (self.beforeSetHtml) {
  3772. val = self.beforeSetHtml(val);
  3773. }
  3774. if (_IE && _V >= 9) {
  3775. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3776. }
  3777. K(body).html(val);
  3778. if (self.afterSetHtml) {
  3779. self.afterSetHtml();
  3780. }
  3781. return self;
  3782. }
  3783. if (val === undefined) {
  3784. return self.textarea.val();
  3785. }
  3786. self.textarea.val(val);
  3787. return self;
  3788. },
  3789. design : function(bool) {
  3790. var self = this, val;
  3791. if (bool === undefined ? !self.designMode : bool) {
  3792. if (!self.designMode) {
  3793. val = self.html();
  3794. self.designMode = true;
  3795. self.html(val);
  3796. self.textarea.hide();
  3797. self.iframe.show();
  3798. }
  3799. } else {
  3800. if (self.designMode) {
  3801. val = self.html();
  3802. self.designMode = false;
  3803. self.html(val);
  3804. self.iframe.hide();
  3805. self.textarea.show();
  3806. }
  3807. }
  3808. return self.focus();
  3809. },
  3810. focus : function() {
  3811. var self = this;
  3812. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3813. return self;
  3814. },
  3815. blur : function() {
  3816. var self = this;
  3817. if (_IE) {
  3818. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3819. self.div.append(input);
  3820. input[0].focus();
  3821. input.remove();
  3822. } else {
  3823. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3824. }
  3825. return self;
  3826. },
  3827. afterChange : function(fn) {
  3828. var self = this, doc = self.doc, body = doc.body;
  3829. K(doc).keyup(function(e) {
  3830. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3831. fn(e);
  3832. }
  3833. });
  3834. K(doc).mouseup(fn).contextmenu(fn);
  3835. K(self.win).blur(fn);
  3836. function timeoutHandler(e) {
  3837. setTimeout(function() {
  3838. fn(e);
  3839. }, 1);
  3840. }
  3841. K(body).bind('paste', timeoutHandler);
  3842. K(body).bind('cut', timeoutHandler);
  3843. return self;
  3844. }
  3845. });
  3846. function _edit(options) {
  3847. return new KEdit(options);
  3848. }
  3849. K.EditClass = KEdit;
  3850. K.edit = _edit;
  3851. K.iframeDoc = _iframeDoc;
  3852. function _selectToolbar(name, fn) {
  3853. var self = this,
  3854. knode = self.get(name);
  3855. if (knode) {
  3856. if (knode.hasClass('ke-disabled')) {
  3857. return;
  3858. }
  3859. fn(knode);
  3860. }
  3861. }
  3862. function KToolbar(options) {
  3863. this.init(options);
  3864. }
  3865. _extend(KToolbar, KWidget, {
  3866. init : function(options) {
  3867. var self = this;
  3868. KToolbar.parent.init.call(self, options);
  3869. self.disableMode = _undef(options.disableMode, false);
  3870. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3871. self._itemMap = {};
  3872. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3873. e.preventDefault();
  3874. }).attr('unselectable', 'on');
  3875. function find(target) {
  3876. var knode = K(target);
  3877. if (knode.hasClass('ke-outline')) {
  3878. return knode;
  3879. }
  3880. if (knode.hasClass('ke-toolbar-icon')) {
  3881. return knode.parent();
  3882. }
  3883. }
  3884. function hover(e, method) {
  3885. var knode = find(e.target);
  3886. if (knode) {
  3887. if (knode.hasClass('ke-disabled')) {
  3888. return;
  3889. }
  3890. if (knode.hasClass('ke-selected')) {
  3891. return;
  3892. }
  3893. knode[method]('ke-on');
  3894. }
  3895. }
  3896. self.div.mouseover(function(e) {
  3897. hover(e, 'addClass');
  3898. })
  3899. .mouseout(function(e) {
  3900. hover(e, 'removeClass');
  3901. })
  3902. .click(function(e) {
  3903. var knode = find(e.target);
  3904. if (knode) {
  3905. if (knode.hasClass('ke-disabled')) {
  3906. return;
  3907. }
  3908. self.options.click.call(this, e, knode.attr('data-name'));
  3909. }
  3910. });
  3911. },
  3912. get : function(name) {
  3913. if (this._itemMap[name]) {
  3914. return this._itemMap[name];
  3915. }
  3916. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3917. },
  3918. select : function(name) {
  3919. _selectToolbar.call(this, name, function(knode) {
  3920. knode.addClass('ke-selected');
  3921. });
  3922. return self;
  3923. },
  3924. unselect : function(name) {
  3925. _selectToolbar.call(this, name, function(knode) {
  3926. knode.removeClass('ke-selected').removeClass('ke-on');
  3927. });
  3928. return self;
  3929. },
  3930. enable : function(name) {
  3931. var self = this,
  3932. knode = name.get ? name : self.get(name);
  3933. if (knode) {
  3934. knode.removeClass('ke-disabled');
  3935. knode.opacity(1);
  3936. }
  3937. return self;
  3938. },
  3939. disable : function(name) {
  3940. var self = this,
  3941. knode = name.get ? name : self.get(name);
  3942. if (knode) {
  3943. knode.removeClass('ke-selected').addClass('ke-disabled');
  3944. knode.opacity(0.5);
  3945. }
  3946. return self;
  3947. },
  3948. disableAll : function(bool, noDisableItems) {
  3949. var self = this, map = self.noDisableItemMap, item;
  3950. if (noDisableItems) {
  3951. map = _toMap(noDisableItems);
  3952. }
  3953. if (bool === undefined ? !self.disableMode : bool) {
  3954. K('span.ke-outline', self.div).each(function() {
  3955. var knode = K(this),
  3956. name = knode[0].getAttribute('data-name', 2);
  3957. if (!map[name]) {
  3958. self.disable(knode);
  3959. }
  3960. });
  3961. self.disableMode = true;
  3962. } else {
  3963. K('span.ke-outline', self.div).each(function() {
  3964. var knode = K(this),
  3965. name = knode[0].getAttribute('data-name', 2);
  3966. if (!map[name]) {
  3967. self.enable(knode);
  3968. }
  3969. });
  3970. self.disableMode = false;
  3971. }
  3972. return self;
  3973. }
  3974. });
  3975. function _toolbar(options) {
  3976. return new KToolbar(options);
  3977. }
  3978. K.ToolbarClass = KToolbar;
  3979. K.toolbar = _toolbar;
  3980. function KMenu(options) {
  3981. this.init(options);
  3982. }
  3983. _extend(KMenu, KWidget, {
  3984. init : function(options) {
  3985. var self = this;
  3986. options.z = options.z || 811213;
  3987. KMenu.parent.init.call(self, options);
  3988. self.centerLineMode = _undef(options.centerLineMode, true);
  3989. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  3990. e.stopPropagation();
  3991. }).attr('unselectable', 'on');
  3992. },
  3993. addItem : function(item) {
  3994. var self = this;
  3995. if (item.title === '-') {
  3996. self.div.append(K('<div class="ke-menu-separator"></div>'));
  3997. return;
  3998. }
  3999. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4000. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4001. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4002. height = _addUnit(item.height),
  4003. iconClass = _undef(item.iconClass, '');
  4004. self.div.append(itemDiv);
  4005. if (height) {
  4006. itemDiv.css('height', height);
  4007. rightDiv.css('line-height', height);
  4008. }
  4009. var centerDiv;
  4010. if (self.centerLineMode) {
  4011. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4012. if (height) {
  4013. centerDiv.css('height', height);
  4014. }
  4015. }
  4016. itemDiv.mouseover(function(e) {
  4017. K(this).addClass('ke-menu-item-on');
  4018. if (centerDiv) {
  4019. centerDiv.addClass('ke-menu-item-center-on');
  4020. }
  4021. })
  4022. .mouseout(function(e) {
  4023. K(this).removeClass('ke-menu-item-on');
  4024. if (centerDiv) {
  4025. centerDiv.removeClass('ke-menu-item-center-on');
  4026. }
  4027. })
  4028. .click(function(e) {
  4029. item.click.call(K(this));
  4030. e.stopPropagation();
  4031. })
  4032. .append(leftDiv);
  4033. if (centerDiv) {
  4034. itemDiv.append(centerDiv);
  4035. }
  4036. itemDiv.append(rightDiv);
  4037. if (item.checked) {
  4038. iconClass = 'ke-icon-checked';
  4039. }
  4040. if (iconClass !== '') {
  4041. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4042. }
  4043. rightDiv.html(item.title);
  4044. return self;
  4045. },
  4046. remove : function() {
  4047. var self = this;
  4048. if (self.options.beforeRemove) {
  4049. self.options.beforeRemove.call(self);
  4050. }
  4051. K('.ke-menu-item', self.div[0]).unbind();
  4052. KMenu.parent.remove.call(self);
  4053. return self;
  4054. }
  4055. });
  4056. function _menu(options) {
  4057. return new KMenu(options);
  4058. }
  4059. K.MenuClass = KMenu;
  4060. K.menu = _menu;
  4061. function KColorPicker(options) {
  4062. this.init(options);
  4063. }
  4064. _extend(KColorPicker, KWidget, {
  4065. init : function(options) {
  4066. var self = this;
  4067. options.z = options.z || 811213;
  4068. KColorPicker.parent.init.call(self, options);
  4069. var colors = options.colors || [
  4070. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4071. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4072. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4073. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4074. ];
  4075. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4076. self._cells = [];
  4077. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4078. e.stopPropagation();
  4079. }).attr('unselectable', 'on');
  4080. var table = self.doc.createElement('table');
  4081. self.div.append(table);
  4082. table.className = 'ke-colorpicker-table';
  4083. table.cellPadding = 0;
  4084. table.cellSpacing = 0;
  4085. table.border = 0;
  4086. var row = table.insertRow(0), cell = row.insertCell(0);
  4087. cell.colSpan = colors[0].length;
  4088. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4089. for (var i = 0; i < colors.length; i++) {
  4090. row = table.insertRow(i + 1);
  4091. for (var j = 0; j < colors[i].length; j++) {
  4092. cell = row.insertCell(j);
  4093. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4094. }
  4095. }
  4096. },
  4097. _addAttr : function(cell, color, cls) {
  4098. var self = this;
  4099. cell = K(cell).addClass(cls);
  4100. if (self.selectedColor === color.toLowerCase()) {
  4101. cell.addClass('ke-colorpicker-cell-selected');
  4102. }
  4103. cell.attr('title', color || self.options.noColor);
  4104. cell.mouseover(function(e) {
  4105. K(this).addClass('ke-colorpicker-cell-on');
  4106. });
  4107. cell.mouseout(function(e) {
  4108. K(this).removeClass('ke-colorpicker-cell-on');
  4109. });
  4110. cell.click(function(e) {
  4111. e.stop();
  4112. self.options.click.call(K(this), color);
  4113. });
  4114. if (color) {
  4115. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4116. } else {
  4117. cell.html(self.options.noColor);
  4118. }
  4119. K(cell).attr('unselectable', 'on');
  4120. self._cells.push(cell);
  4121. },
  4122. remove : function() {
  4123. var self = this;
  4124. _each(self._cells, function() {
  4125. this.unbind();
  4126. });
  4127. KColorPicker.parent.remove.call(self);
  4128. return self;
  4129. }
  4130. });
  4131. function _colorpicker(options) {
  4132. return new KColorPicker(options);
  4133. }
  4134. K.ColorPickerClass = KColorPicker;
  4135. K.colorpicker = _colorpicker;
  4136. function KUploadButton(options) {
  4137. this.init(options);
  4138. }
  4139. _extend(KUploadButton, {
  4140. init : function(options) {
  4141. var self = this,
  4142. button = K(options.button),
  4143. fieldName = options.fieldName || 'file',
  4144. url = options.url || '',
  4145. title = button.val(),
  4146. extraParams = options.extraParams || {},
  4147. cls = button[0].className || '',
  4148. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4149. options.afterError = options.afterError || function(str) {
  4150. };
  4151. var hiddenElements = [];
  4152. for(var k in extraParams){
  4153. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4154. }
  4155. var html = [
  4156. '<div class="ke-inline-block ' + cls + '">',
  4157. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4158. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4159. '<span class="ke-button-common">',
  4160. hiddenElements.join(''),
  4161. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4162. '</span>',
  4163. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4164. (options.form ? '</div>' : '</form>'),
  4165. '</div>'].join('');
  4166. var div = K(html, button.doc);
  4167. button.hide();
  4168. button.before(div);
  4169. self.div = div;
  4170. self.button = button;
  4171. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4172. self.form = options.form ? K(options.form) : K('form', div);
  4173. self.fileBox = K('.ke-upload-file', div);
  4174. var width = options.width || K('.ke-button-common', div).width();
  4175. K('.ke-upload-area', div).width(width);
  4176. self.options = options;
  4177. },
  4178. submit : function() {
  4179. var self = this,
  4180. iframe = self.iframe;
  4181. iframe.bind('load', function() {
  4182. iframe.unbind();
  4183. var tempForm = document.createElement('form');
  4184. self.fileBox.before(tempForm);
  4185. K(tempForm).append(self.fileBox);
  4186. tempForm.reset();
  4187. K(tempForm).remove(true);
  4188. var doc = K.iframeDoc(iframe),
  4189. pre = doc.getElementsByTagName('pre')[0],
  4190. str = '', data;
  4191. if (pre) {
  4192. str = pre.innerHTML;
  4193. } else {
  4194. str = doc.body.innerHTML;
  4195. }
  4196. str = _unescape(str);
  4197. iframe[0].src = 'javascript:false';
  4198. try {
  4199. data = K.json(str);
  4200. } catch (e) {
  4201. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4202. }
  4203. if (data) {
  4204. self.options.afterUpload.call(self, data);
  4205. }
  4206. });
  4207. self.form[0].submit();
  4208. return self;
  4209. },
  4210. remove : function() {
  4211. var self = this;
  4212. if (self.fileBox) {
  4213. self.fileBox.unbind();
  4214. }
  4215. self.iframe.remove();
  4216. self.div.remove();
  4217. self.button.show();
  4218. return self;
  4219. }
  4220. });
  4221. function _uploadbutton(options) {
  4222. return new KUploadButton(options);
  4223. }
  4224. K.UploadButtonClass = KUploadButton;
  4225. K.uploadbutton = _uploadbutton;
  4226. function _createButton(arg) {
  4227. arg = arg || {};
  4228. var name = arg.name || '',
  4229. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4230. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4231. if (arg.click) {
  4232. btn.click(arg.click);
  4233. }
  4234. span.append(btn);
  4235. return span;
  4236. }
  4237. function KDialog(options) {
  4238. this.init(options);
  4239. }
  4240. _extend(KDialog, KWidget, {
  4241. init : function(options) {
  4242. var self = this;
  4243. var shadowMode = _undef(options.shadowMode, true);
  4244. options.z = options.z || 811213;
  4245. options.shadowMode = false;
  4246. options.autoScroll = _undef(options.autoScroll, true);
  4247. KDialog.parent.init.call(self, options);
  4248. var title = options.title,
  4249. body = K(options.body, self.doc),
  4250. previewBtn = options.previewBtn,
  4251. yesBtn = options.yesBtn,
  4252. noBtn = options.noBtn,
  4253. closeBtn = options.closeBtn,
  4254. showMask = _undef(options.showMask, true);
  4255. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4256. e.stopPropagation();
  4257. });
  4258. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4259. if (_IE && _V < 7) {
  4260. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4261. } else if (shadowMode) {
  4262. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4263. }
  4264. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4265. contentDiv.append(headerDiv);
  4266. headerDiv.html(title);
  4267. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4268. headerDiv.append(self.closeIcon);
  4269. self.draggable({
  4270. clickEl : headerDiv,
  4271. beforeDrag : options.beforeDrag
  4272. });
  4273. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4274. contentDiv.append(bodyDiv);
  4275. bodyDiv.append(body);
  4276. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4277. if (previewBtn || yesBtn || noBtn) {
  4278. contentDiv.append(footerDiv);
  4279. }
  4280. _each([
  4281. { btn : previewBtn, name : 'preview' },
  4282. { btn : yesBtn, name : 'yes' },
  4283. { btn : noBtn, name : 'no' }
  4284. ], function() {
  4285. if (this.btn) {
  4286. var button = _createButton(this.btn);
  4287. button.addClass('ke-dialog-' + this.name);
  4288. footerDiv.append(button);
  4289. }
  4290. });
  4291. if (self.height) {
  4292. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4293. }
  4294. self.div.width(self.div.width());
  4295. self.div.height(self.div.height());
  4296. self.mask = null;
  4297. if (showMask) {
  4298. var docEl = _docElement(self.doc),
  4299. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4300. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4301. self.mask = _widget({
  4302. x : 0,
  4303. y : 0,
  4304. z : self.z - 1,
  4305. cls : 'ke-dialog-mask',
  4306. width : docWidth,
  4307. height : docHeight
  4308. });
  4309. }
  4310. self.autoPos(self.div.width(), self.div.height());
  4311. self.footerDiv = footerDiv;
  4312. self.bodyDiv = bodyDiv;
  4313. self.headerDiv = headerDiv;
  4314. self.isLoading = false;
  4315. },
  4316. setMaskIndex : function(z) {
  4317. var self = this;
  4318. self.mask.div.css('z-index', z);
  4319. },
  4320. showLoading : function(msg) {
  4321. msg = _undef(msg, '');
  4322. var self = this, body = self.bodyDiv;
  4323. 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>')
  4324. .width(body.width()).height(body.height())
  4325. .css('top', self.headerDiv.height() + 'px');
  4326. body.css('visibility', 'hidden').after(self.loading);
  4327. self.isLoading = true;
  4328. return self;
  4329. },
  4330. hideLoading : function() {
  4331. this.loading && this.loading.remove();
  4332. this.bodyDiv.css('visibility', 'visible');
  4333. this.isLoading = false;
  4334. return this;
  4335. },
  4336. remove : function() {
  4337. var self = this;
  4338. if (self.options.beforeRemove) {
  4339. self.options.beforeRemove.call(self);
  4340. }
  4341. self.mask && self.mask.remove();
  4342. self.iframeMask && self.iframeMask.remove();
  4343. self.closeIcon.unbind();
  4344. K('input', self.div).unbind();
  4345. K('button', self.div).unbind();
  4346. self.footerDiv.unbind();
  4347. self.bodyDiv.unbind();
  4348. self.headerDiv.unbind();
  4349. K('iframe', self.div).each(function() {
  4350. K(this).remove();
  4351. });
  4352. KDialog.parent.remove.call(self);
  4353. return self;
  4354. }
  4355. });
  4356. function _dialog(options) {
  4357. return new KDialog(options);
  4358. }
  4359. K.DialogClass = KDialog;
  4360. K.dialog = _dialog;
  4361. function _tabs(options) {
  4362. var self = _widget(options),
  4363. remove = self.remove,
  4364. afterSelect = options.afterSelect,
  4365. div = self.div,
  4366. liList = [];
  4367. div.addClass('ke-tabs')
  4368. .bind('contextmenu,mousedown,mousemove', function(e) {
  4369. e.preventDefault();
  4370. });
  4371. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4372. div.append(ul);
  4373. self.add = function(tab) {
  4374. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4375. li.data('tab', tab);
  4376. liList.push(li);
  4377. ul.append(li);
  4378. };
  4379. self.selectedIndex = 0;
  4380. self.select = function(index) {
  4381. self.selectedIndex = index;
  4382. _each(liList, function(i, li) {
  4383. li.unbind();
  4384. if (i === index) {
  4385. li.addClass('ke-tabs-li-selected');
  4386. K(li.data('tab').panel).show('');
  4387. } else {
  4388. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4389. .mouseover(function() {
  4390. K(this).addClass('ke-tabs-li-on');
  4391. })
  4392. .mouseout(function() {
  4393. K(this).removeClass('ke-tabs-li-on');
  4394. })
  4395. .click(function() {
  4396. self.select(i);
  4397. });
  4398. K(li.data('tab').panel).hide();
  4399. }
  4400. });
  4401. if (afterSelect) {
  4402. afterSelect.call(self, index);
  4403. }
  4404. };
  4405. self.remove = function() {
  4406. _each(liList, function() {
  4407. this.remove();
  4408. });
  4409. ul.remove();
  4410. remove.call(self);
  4411. };
  4412. return self;
  4413. }
  4414. K.tabs = _tabs;
  4415. function _loadScript(url, fn) {
  4416. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4417. script = document.createElement('script');
  4418. head.appendChild(script);
  4419. script.src = url;
  4420. script.charset = 'utf-8';
  4421. script.onload = script.onreadystatechange = function() {
  4422. if (!this.readyState || this.readyState === 'loaded') {
  4423. if (fn) {
  4424. fn();
  4425. }
  4426. script.onload = script.onreadystatechange = null;
  4427. head.removeChild(script);
  4428. }
  4429. };
  4430. }
  4431. function _chopQuery(url) {
  4432. var index = url.indexOf('?');
  4433. return index > 0 ? url.substr(0, index) : url;
  4434. }
  4435. function _loadStyle(url) {
  4436. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4437. link = document.createElement('link'),
  4438. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4439. var links = K('link[rel="stylesheet"]', head);
  4440. for (var i = 0, len = links.length; i < len; i++) {
  4441. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4442. return;
  4443. }
  4444. }
  4445. head.appendChild(link);
  4446. link.href = url;
  4447. link.rel = 'stylesheet';
  4448. }
  4449. function _ajax(url, fn, method, param, dataType) {
  4450. method = method || 'GET';
  4451. dataType = dataType || 'json';
  4452. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4453. xhr.open(method, url, true);
  4454. xhr.onreadystatechange = function () {
  4455. if (xhr.readyState == 4 && xhr.status == 200) {
  4456. if (fn) {
  4457. var data = _trim(xhr.responseText);
  4458. if (dataType == 'json') {
  4459. data = _json(data);
  4460. }
  4461. fn(data);
  4462. }
  4463. }
  4464. };
  4465. if (method == 'POST') {
  4466. var params = [];
  4467. _each(param, function(key, val) {
  4468. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4469. });
  4470. try {
  4471. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4472. } catch (e) {}
  4473. xhr.send(params.join('&'));
  4474. } else {
  4475. xhr.send(null);
  4476. }
  4477. }
  4478. K.loadScript = _loadScript;
  4479. K.loadStyle = _loadStyle;
  4480. K.ajax = _ajax;
  4481. var _plugins = {};
  4482. function _plugin(name, fn) {
  4483. if (name === undefined) {
  4484. return _plugins;
  4485. }
  4486. if (!fn) {
  4487. return _plugins[name];
  4488. }
  4489. _plugins[name] = fn;
  4490. }
  4491. var _language = {};
  4492. function _parseLangKey(key) {
  4493. var match, ns = 'core';
  4494. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4495. ns = match[1];
  4496. key = match[2];
  4497. }
  4498. return { ns : ns, key : key };
  4499. }
  4500. function _lang(mixed, langType) {
  4501. langType = langType === undefined ? K.options.langType : langType;
  4502. if (typeof mixed === 'string') {
  4503. if (!_language[langType]) {
  4504. return 'no language';
  4505. }
  4506. var pos = mixed.length - 1;
  4507. if (mixed.substr(pos) === '.') {
  4508. return _language[langType][mixed.substr(0, pos)];
  4509. }
  4510. var obj = _parseLangKey(mixed);
  4511. return _language[langType][obj.ns][obj.key];
  4512. }
  4513. _each(mixed, function(key, val) {
  4514. var obj = _parseLangKey(key);
  4515. if (!_language[langType]) {
  4516. _language[langType] = {};
  4517. }
  4518. if (!_language[langType][obj.ns]) {
  4519. _language[langType][obj.ns] = {};
  4520. }
  4521. _language[langType][obj.ns][obj.key] = val;
  4522. });
  4523. }
  4524. function _getImageFromRange(range, fn) {
  4525. if (range.collapsed) {
  4526. return;
  4527. }
  4528. range = range.cloneRange().up();
  4529. var sc = range.startContainer, so = range.startOffset;
  4530. if (!_WEBKIT && !range.isControl()) {
  4531. return;
  4532. }
  4533. var img = K(sc.childNodes[so]);
  4534. if (!img || img.name != 'img') {
  4535. return;
  4536. }
  4537. if (fn(img)) {
  4538. return img;
  4539. }
  4540. }
  4541. function _bindContextmenuEvent() {
  4542. var self = this, doc = self.edit.doc;
  4543. K(doc).contextmenu(function(e) {
  4544. if (self.menu) {
  4545. self.hideMenu();
  4546. }
  4547. if (!self.useContextmenu) {
  4548. e.preventDefault();
  4549. return;
  4550. }
  4551. if (self._contextmenus.length === 0) {
  4552. return;
  4553. }
  4554. var maxWidth = 0, items = [];
  4555. _each(self._contextmenus, function() {
  4556. if (this.title == '-') {
  4557. items.push(this);
  4558. return;
  4559. }
  4560. if (this.cond && this.cond()) {
  4561. items.push(this);
  4562. if (this.width && this.width > maxWidth) {
  4563. maxWidth = this.width;
  4564. }
  4565. }
  4566. });
  4567. while (items.length > 0 && items[0].title == '-') {
  4568. items.shift();
  4569. }
  4570. while (items.length > 0 && items[items.length - 1].title == '-') {
  4571. items.pop();
  4572. }
  4573. var prevItem = null;
  4574. _each(items, function(i) {
  4575. if (this.title == '-' && prevItem.title == '-') {
  4576. delete items[i];
  4577. }
  4578. prevItem = this;
  4579. });
  4580. if (items.length > 0) {
  4581. e.preventDefault();
  4582. var pos = K(self.edit.iframe).pos(),
  4583. menu = _menu({
  4584. x : pos.x + e.clientX,
  4585. y : pos.y + e.clientY,
  4586. width : maxWidth,
  4587. css : { visibility: 'hidden' },
  4588. shadowMode : self.shadowMode
  4589. });
  4590. _each(items, function() {
  4591. if (this.title) {
  4592. menu.addItem(this);
  4593. }
  4594. });
  4595. var docEl = _docElement(menu.doc),
  4596. menuHeight = menu.div.height();
  4597. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4598. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4599. }
  4600. menu.div.css('visibility', 'visible');
  4601. self.menu = menu;
  4602. }
  4603. });
  4604. }
  4605. function _bindNewlineEvent() {
  4606. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4607. if (_IE && newlineTag !== 'br') {
  4608. return;
  4609. }
  4610. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4611. return;
  4612. }
  4613. if (_OPERA && _V < 9) {
  4614. return;
  4615. }
  4616. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4617. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4618. function getAncestorTagName(range) {
  4619. var ancestor = K(range.commonAncestor());
  4620. while (ancestor) {
  4621. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4622. break;
  4623. }
  4624. ancestor = ancestor.parent();
  4625. }
  4626. return ancestor.name;
  4627. }
  4628. K(doc).keydown(function(e) {
  4629. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4630. return;
  4631. }
  4632. self.cmd.selection();
  4633. var tagName = getAncestorTagName(self.cmd.range);
  4634. if (tagName == 'marquee' || tagName == 'select') {
  4635. return;
  4636. }
  4637. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4638. e.preventDefault();
  4639. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4640. return;
  4641. }
  4642. if (!pSkipTagMap[tagName]) {
  4643. _nativeCommand(doc, 'formatblock', '<p>');
  4644. }
  4645. });
  4646. K(doc).keyup(function(e) {
  4647. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4648. return;
  4649. }
  4650. if (newlineTag == 'br') {
  4651. return;
  4652. }
  4653. if (_GECKO) {
  4654. var root = self.cmd.commonAncestor('p');
  4655. var a = self.cmd.commonAncestor('a');
  4656. if (a && a.text() == '') {
  4657. a.remove(true);
  4658. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4659. self.cmd.select();
  4660. }
  4661. return;
  4662. }
  4663. self.cmd.selection();
  4664. var tagName = getAncestorTagName(self.cmd.range);
  4665. if (tagName == 'marquee' || tagName == 'select') {
  4666. return;
  4667. }
  4668. if (!pSkipTagMap[tagName]) {
  4669. _nativeCommand(doc, 'formatblock', '<p>');
  4670. }
  4671. var div = self.cmd.commonAncestor('div');
  4672. if (div) {
  4673. var p = K('<p></p>'),
  4674. child = div[0].firstChild;
  4675. while (child) {
  4676. var next = child.nextSibling;
  4677. p.append(child);
  4678. child = next;
  4679. }
  4680. div.before(p);
  4681. div.remove();
  4682. self.cmd.range.selectNodeContents(p[0]);
  4683. self.cmd.select();
  4684. }
  4685. });
  4686. }
  4687. function _bindTabEvent() {
  4688. var self = this, doc = self.edit.doc;
  4689. K(doc).keydown(function(e) {
  4690. if (e.which == 9) {
  4691. e.preventDefault();
  4692. if (self.afterTab) {
  4693. self.afterTab.call(self, e);
  4694. return;
  4695. }
  4696. var cmd = self.cmd, range = cmd.range;
  4697. range.shrink();
  4698. if (range.collapsed && range.startContainer.nodeType == 1) {
  4699. range.insertNode(K('@&nbsp;', doc)[0]);
  4700. cmd.select();
  4701. }
  4702. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4703. }
  4704. });
  4705. }
  4706. function _bindFocusEvent() {
  4707. var self = this;
  4708. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4709. if (self.afterFocus) {
  4710. self.afterFocus.call(self, e);
  4711. }
  4712. }).blur(function(e) {
  4713. if (self.afterBlur) {
  4714. self.afterBlur.call(self, e);
  4715. }
  4716. });
  4717. }
  4718. function _removeBookmarkTag(html) {
  4719. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4720. }
  4721. function _removeTempTag(html) {
  4722. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4723. }
  4724. function _addBookmarkToStack(stack, bookmark) {
  4725. if (stack.length === 0) {
  4726. stack.push(bookmark);
  4727. return;
  4728. }
  4729. var prev = stack[stack.length - 1];
  4730. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4731. stack.push(bookmark);
  4732. }
  4733. }
  4734. function _undoToRedo(fromStack, toStack) {
  4735. var self = this, edit = self.edit,
  4736. body = edit.doc.body,
  4737. range, bookmark;
  4738. if (fromStack.length === 0) {
  4739. return self;
  4740. }
  4741. if (edit.designMode) {
  4742. range = self.cmd.range;
  4743. bookmark = range.createBookmark(true);
  4744. bookmark.html = body.innerHTML;
  4745. } else {
  4746. bookmark = {
  4747. html : body.innerHTML
  4748. };
  4749. }
  4750. _addBookmarkToStack(toStack, bookmark);
  4751. var prev = fromStack.pop();
  4752. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4753. prev = fromStack.pop();
  4754. }
  4755. if (edit.designMode) {
  4756. edit.html(prev.html);
  4757. if (prev.start) {
  4758. range.moveToBookmark(prev);
  4759. self.select();
  4760. }
  4761. } else {
  4762. K(body).html(_removeBookmarkTag(prev.html));
  4763. }
  4764. return self;
  4765. }
  4766. function KEditor(options) {
  4767. var self = this;
  4768. self.options = {};
  4769. function setOption(key, val) {
  4770. if (KEditor.prototype[key] === undefined) {
  4771. self[key] = val;
  4772. }
  4773. self.options[key] = val;
  4774. }
  4775. _each(options, function(key, val) {
  4776. setOption(key, options[key]);
  4777. });
  4778. _each(K.options, function(key, val) {
  4779. if (self[key] === undefined) {
  4780. setOption(key, val);
  4781. }
  4782. });
  4783. var se = K(self.srcElement || '<textarea/>');
  4784. if (!self.width) {
  4785. self.width = se[0].style.width || se.width();
  4786. }
  4787. if (!self.height) {
  4788. self.height = se[0].style.height || se.height();
  4789. }
  4790. setOption('width', _undef(self.width, self.minWidth));
  4791. setOption('height', _undef(self.height, self.minHeight));
  4792. setOption('width', _addUnit(self.width));
  4793. setOption('height', _addUnit(self.height));
  4794. if (_MOBILE && (!_IOS || _V < 534)) {
  4795. self.designMode = false;
  4796. }
  4797. self.srcElement = se;
  4798. self.initContent = '';
  4799. self.plugin = {};
  4800. self.isCreated = false;
  4801. self._handlers = {};
  4802. self._contextmenus = [];
  4803. self._undoStack = [];
  4804. self._redoStack = [];
  4805. self._firstAddBookmark = true;
  4806. self.menu = self.contextmenu = null;
  4807. self.dialogs = [];
  4808. }
  4809. KEditor.prototype = {
  4810. lang : function(mixed) {
  4811. return _lang(mixed, this.langType);
  4812. },
  4813. loadPlugin : function(name, fn) {
  4814. var self = this;
  4815. if (_plugins[name]) {
  4816. if (!_isFunction(_plugins[name])) {
  4817. setTimeout(function() {
  4818. self.loadPlugin(name, fn);
  4819. }, 100);
  4820. return self;
  4821. }
  4822. _plugins[name].call(self, KindEditor);
  4823. if (fn) {
  4824. fn.call(self);
  4825. }
  4826. return self;
  4827. }
  4828. _plugins[name] = 'loading';
  4829. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4830. setTimeout(function() {
  4831. if (_plugins[name]) {
  4832. self.loadPlugin(name, fn);
  4833. }
  4834. }, 0);
  4835. });
  4836. return self;
  4837. },
  4838. handler : function(key, fn) {
  4839. var self = this;
  4840. if (!self._handlers[key]) {
  4841. self._handlers[key] = [];
  4842. }
  4843. if (_isFunction(fn)) {
  4844. self._handlers[key].push(fn);
  4845. return self;
  4846. }
  4847. _each(self._handlers[key], function() {
  4848. fn = this.call(self, fn);
  4849. });
  4850. return fn;
  4851. },
  4852. clickToolbar : function(name, fn) {
  4853. var self = this, key = 'clickToolbar' + name;
  4854. if (fn === undefined) {
  4855. if (self._handlers[key]) {
  4856. return self.handler(key);
  4857. }
  4858. self.loadPlugin(name, function() {
  4859. self.handler(key);
  4860. });
  4861. return self;
  4862. }
  4863. return self.handler(key, fn);
  4864. },
  4865. updateState : function() {
  4866. var self = this;
  4867. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4868. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4869. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4870. });
  4871. return self;
  4872. },
  4873. addContextmenu : function(item) {
  4874. this._contextmenus.push(item);
  4875. return this;
  4876. },
  4877. afterCreate : function(fn) {
  4878. return this.handler('afterCreate', fn);
  4879. },
  4880. beforeRemove : function(fn) {
  4881. return this.handler('beforeRemove', fn);
  4882. },
  4883. beforeGetHtml : function(fn) {
  4884. return this.handler('beforeGetHtml', fn);
  4885. },
  4886. beforeSetHtml : function(fn) {
  4887. return this.handler('beforeSetHtml', fn);
  4888. },
  4889. afterSetHtml : function(fn) {
  4890. return this.handler('afterSetHtml', fn);
  4891. },
  4892. create : function() {
  4893. var self = this, fullscreenMode = self.fullscreenMode;
  4894. if (self.isCreated) {
  4895. return self;
  4896. }
  4897. if (self.srcElement.data('kindeditor')) {
  4898. return self;
  4899. }
  4900. self.srcElement.data('kindeditor', 'true');
  4901. if (fullscreenMode) {
  4902. _docElement().style.overflow = 'hidden';
  4903. } else {
  4904. _docElement().style.overflow = '';
  4905. }
  4906. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4907. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4908. if ((_IE && _V < 8) || _QUIRKS) {
  4909. height = _addUnit(_removeUnit(height) + 2);
  4910. }
  4911. var container = self.container = K(self.layout);
  4912. if (fullscreenMode) {
  4913. K(document.body).append(container);
  4914. } else {
  4915. self.srcElement.before(container);
  4916. }
  4917. var toolbarDiv = K('.toolbar', container),
  4918. editDiv = K('.edit', container),
  4919. statusbar = self.statusbar = K('.statusbar', container);
  4920. container.removeClass('container')
  4921. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4922. if (fullscreenMode) {
  4923. container.css({
  4924. position : 'absolute',
  4925. left : 0,
  4926. top : 0,
  4927. 'z-index' : 811211
  4928. });
  4929. if (!_GECKO) {
  4930. self._scrollPos = _getScrollPos();
  4931. }
  4932. window.scrollTo(0, 0);
  4933. K(document.body).css({
  4934. 'height' : '1px',
  4935. 'overflow' : 'hidden'
  4936. });
  4937. K(document.body.parentNode).css('overflow', 'hidden');
  4938. self._fullscreenExecuted = true;
  4939. } else {
  4940. if (self._fullscreenExecuted) {
  4941. K(document.body).css({
  4942. 'height' : '',
  4943. 'overflow' : ''
  4944. });
  4945. K(document.body.parentNode).css('overflow', '');
  4946. }
  4947. if (self._scrollPos) {
  4948. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4949. }
  4950. }
  4951. var htmlList = [];
  4952. K.each(self.items, function(i, name) {
  4953. if (name == '|') {
  4954. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4955. } else if (name == '/') {
  4956. htmlList.push('<div class="ke-hr"></div>');
  4957. } else {
  4958. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4959. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4960. }
  4961. });
  4962. var toolbar = self.toolbar = _toolbar({
  4963. src : toolbarDiv,
  4964. html : htmlList.join(''),
  4965. noDisableItems : self.noDisableItems,
  4966. click : function(e, name) {
  4967. e.stop();
  4968. if (self.menu) {
  4969. var menuName = self.menu.name;
  4970. self.hideMenu();
  4971. if (menuName === name) {
  4972. return;
  4973. }
  4974. }
  4975. self.clickToolbar(name);
  4976. }
  4977. });
  4978. var editHeight = _removeUnit(height) - toolbar.div.height();
  4979. var edit = self.edit = _edit({
  4980. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  4981. src : editDiv,
  4982. srcElement : self.srcElement,
  4983. designMode : self.designMode,
  4984. themesPath : self.themesPath,
  4985. bodyClass : self.bodyClass,
  4986. cssPath : self.cssPath,
  4987. cssData : self.cssData,
  4988. beforeGetHtml : function(html) {
  4989. html = self.beforeGetHtml(html);
  4990. html = _removeBookmarkTag(_removeTempTag(html));
  4991. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  4992. },
  4993. beforeSetHtml : function(html) {
  4994. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  4995. return self.beforeSetHtml(html);
  4996. },
  4997. afterSetHtml : function() {
  4998. self.edit = edit = this;
  4999. self.afterSetHtml();
  5000. },
  5001. afterCreate : function() {
  5002. self.edit = edit = this;
  5003. self.cmd = edit.cmd;
  5004. self._docMousedownFn = function(e) {
  5005. if (self.menu) {
  5006. self.hideMenu();
  5007. }
  5008. };
  5009. K(edit.doc, document).mousedown(self._docMousedownFn);
  5010. _bindContextmenuEvent.call(self);
  5011. _bindNewlineEvent.call(self);
  5012. _bindTabEvent.call(self);
  5013. _bindFocusEvent.call(self);
  5014. edit.afterChange(function(e) {
  5015. if (!edit.designMode) {
  5016. return;
  5017. }
  5018. self.updateState();
  5019. self.addBookmark();
  5020. if (self.options.afterChange) {
  5021. self.options.afterChange.call(self);
  5022. }
  5023. });
  5024. edit.textarea.keyup(function(e) {
  5025. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5026. if (self.options.afterChange) {
  5027. self.options.afterChange.call(self);
  5028. }
  5029. }
  5030. });
  5031. if (self.readonlyMode) {
  5032. self.readonly();
  5033. }
  5034. self.isCreated = true;
  5035. if (self.initContent === '') {
  5036. self.initContent = self.html();
  5037. }
  5038. if (self._undoStack.length > 0) {
  5039. var prev = self._undoStack.pop();
  5040. if (prev.start) {
  5041. self.html(prev.html);
  5042. edit.cmd.range.moveToBookmark(prev);
  5043. self.select();
  5044. }
  5045. }
  5046. self.afterCreate();
  5047. if (self.options.afterCreate) {
  5048. self.options.afterCreate.call(self);
  5049. }
  5050. }
  5051. });
  5052. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5053. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5054. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5055. if (self._fullscreenResizeHandler) {
  5056. K(window).unbind('resize', self._fullscreenResizeHandler);
  5057. self._fullscreenResizeHandler = null;
  5058. }
  5059. function initResize() {
  5060. if (statusbar.height() === 0) {
  5061. setTimeout(initResize, 100);
  5062. return;
  5063. }
  5064. self.resize(width, height, false);
  5065. }
  5066. initResize();
  5067. if (fullscreenMode) {
  5068. self._fullscreenResizeHandler = function(e) {
  5069. if (self.isCreated) {
  5070. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5071. }
  5072. };
  5073. K(window).bind('resize', self._fullscreenResizeHandler);
  5074. toolbar.select('fullscreen');
  5075. statusbar.first().css('visibility', 'hidden');
  5076. statusbar.last().css('visibility', 'hidden');
  5077. } else {
  5078. if (_GECKO) {
  5079. K(window).bind('scroll', function(e) {
  5080. self._scrollPos = _getScrollPos();
  5081. });
  5082. }
  5083. if (self.resizeType > 0) {
  5084. _drag({
  5085. moveEl : container,
  5086. clickEl : statusbar,
  5087. moveFn : function(x, y, width, height, diffX, diffY) {
  5088. height += diffY;
  5089. self.resize(null, height);
  5090. }
  5091. });
  5092. } else {
  5093. statusbar.first().css('visibility', 'hidden');
  5094. }
  5095. if (self.resizeType === 2) {
  5096. _drag({
  5097. moveEl : container,
  5098. clickEl : statusbar.last(),
  5099. moveFn : function(x, y, width, height, diffX, diffY) {
  5100. width += diffX;
  5101. height += diffY;
  5102. self.resize(width, height);
  5103. }
  5104. });
  5105. } else {
  5106. statusbar.last().css('visibility', 'hidden');
  5107. }
  5108. }
  5109. return self;
  5110. },
  5111. remove : function() {
  5112. var self = this;
  5113. if (!self.isCreated) {
  5114. return self;
  5115. }
  5116. self.beforeRemove();
  5117. self.srcElement.data('kindeditor', '');
  5118. if (self.menu) {
  5119. self.hideMenu();
  5120. }
  5121. _each(self.dialogs, function() {
  5122. self.hideDialog();
  5123. });
  5124. K(document).unbind('mousedown', self._docMousedownFn);
  5125. self.toolbar.remove();
  5126. self.edit.remove();
  5127. self.statusbar.last().unbind();
  5128. self.statusbar.unbind();
  5129. self.container.remove();
  5130. self.container = self.toolbar = self.edit = self.menu = null;
  5131. self.dialogs = [];
  5132. self.isCreated = false;
  5133. return self;
  5134. },
  5135. resize : function(width, height, updateProp) {
  5136. var self = this;
  5137. updateProp = _undef(updateProp, true);
  5138. if (width) {
  5139. if (!/%/.test(width)) {
  5140. width = _removeUnit(width);
  5141. width = width < self.minWidth ? self.minWidth : width;
  5142. }
  5143. self.container.css('width', _addUnit(width));
  5144. if (updateProp) {
  5145. self.width = _addUnit(width);
  5146. }
  5147. }
  5148. if (height) {
  5149. height = _removeUnit(height);
  5150. editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5151. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5152. self.edit.setHeight(editHeight);
  5153. if (updateProp) {
  5154. self.height = _addUnit(height);
  5155. }
  5156. }
  5157. return self;
  5158. },
  5159. select : function() {
  5160. this.isCreated && this.cmd.select();
  5161. return this;
  5162. },
  5163. html : function(val) {
  5164. var self = this;
  5165. if (val === undefined) {
  5166. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5167. }
  5168. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5169. if (self.isCreated) {
  5170. self.cmd.selection();
  5171. }
  5172. return self;
  5173. },
  5174. fullHtml : function() {
  5175. return this.isCreated ? this.edit.html(undefined, true) : '';
  5176. },
  5177. text : function(val) {
  5178. var self = this;
  5179. if (val === undefined) {
  5180. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5181. } else {
  5182. return self.html(_escape(val));
  5183. }
  5184. },
  5185. isEmpty : function() {
  5186. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5187. },
  5188. isDirty : function() {
  5189. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5190. },
  5191. selectedHtml : function() {
  5192. var val = this.isCreated ? this.cmd.range.html() : '';
  5193. val = _removeBookmarkTag(_removeTempTag(val));
  5194. return val;
  5195. },
  5196. count : function(mode) {
  5197. var self = this;
  5198. mode = (mode || 'html').toLowerCase();
  5199. if (mode === 'html') {
  5200. return self.html().length;
  5201. }
  5202. if (mode === 'text') {
  5203. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5204. }
  5205. return 0;
  5206. },
  5207. exec : function(key) {
  5208. key = key.toLowerCase();
  5209. var self = this, cmd = self.cmd,
  5210. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5211. if (changeFlag) {
  5212. self.addBookmark(false);
  5213. }
  5214. cmd[key].apply(cmd, _toArray(arguments, 1));
  5215. if (changeFlag) {
  5216. self.updateState();
  5217. self.addBookmark(false);
  5218. if (self.options.afterChange) {
  5219. self.options.afterChange.call(self);
  5220. }
  5221. }
  5222. return self;
  5223. },
  5224. insertHtml : function(val, quickMode) {
  5225. if (!this.isCreated) {
  5226. return this;
  5227. }
  5228. val = this.beforeSetHtml(val);
  5229. this.exec('inserthtml', val, quickMode);
  5230. return this;
  5231. },
  5232. appendHtml : function(val) {
  5233. this.html(this.html() + val);
  5234. if (this.isCreated) {
  5235. var cmd = this.cmd;
  5236. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5237. cmd.select();
  5238. }
  5239. return this;
  5240. },
  5241. sync : function() {
  5242. _elementVal(this.srcElement, this.html());
  5243. return this;
  5244. },
  5245. focus : function() {
  5246. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5247. return this;
  5248. },
  5249. blur : function() {
  5250. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5251. return this;
  5252. },
  5253. addBookmark : function(checkSize) {
  5254. checkSize = _undef(checkSize, true);
  5255. var self = this, edit = self.edit,
  5256. body = edit.doc.body,
  5257. html = _removeTempTag(body.innerHTML), bookmark;
  5258. if (checkSize && self._undoStack.length > 0) {
  5259. var prev = self._undoStack[self._undoStack.length - 1];
  5260. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5261. return self;
  5262. }
  5263. }
  5264. if (edit.designMode && !self._firstAddBookmark) {
  5265. var range = self.cmd.range;
  5266. bookmark = range.createBookmark(true);
  5267. bookmark.html = _removeTempTag(body.innerHTML);
  5268. range.moveToBookmark(bookmark);
  5269. } else {
  5270. bookmark = {
  5271. html : html
  5272. };
  5273. }
  5274. self._firstAddBookmark = false;
  5275. _addBookmarkToStack(self._undoStack, bookmark);
  5276. return self;
  5277. },
  5278. undo : function() {
  5279. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5280. },
  5281. redo : function() {
  5282. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5283. },
  5284. fullscreen : function(bool) {
  5285. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5286. this.addBookmark(false);
  5287. return this.remove().create();
  5288. },
  5289. readonly : function(isReadonly) {
  5290. isReadonly = _undef(isReadonly, true);
  5291. var self = this, edit = self.edit, doc = edit.doc;
  5292. if (self.designMode) {
  5293. self.toolbar.disableAll(isReadonly, []);
  5294. } else {
  5295. _each(self.noDisableItems, function() {
  5296. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5297. });
  5298. }
  5299. if (_IE) {
  5300. doc.body.contentEditable = !isReadonly;
  5301. } else {
  5302. doc.designMode = isReadonly ? 'off' : 'on';
  5303. }
  5304. edit.textarea[0].disabled = isReadonly;
  5305. },
  5306. createMenu : function(options) {
  5307. var self = this,
  5308. name = options.name,
  5309. knode = self.toolbar.get(name),
  5310. pos = knode.pos();
  5311. options.x = pos.x;
  5312. options.y = pos.y + knode.height();
  5313. options.z = self.options.zIndex;
  5314. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5315. if (options.selectedColor !== undefined) {
  5316. options.cls = 'ke-colorpicker-' + self.themeType;
  5317. options.noColor = self.lang('noColor');
  5318. self.menu = _colorpicker(options);
  5319. } else {
  5320. options.cls = 'ke-menu-' + self.themeType;
  5321. options.centerLineMode = false;
  5322. self.menu = _menu(options);
  5323. }
  5324. return self.menu;
  5325. },
  5326. hideMenu : function() {
  5327. this.menu.remove();
  5328. this.menu = null;
  5329. return this;
  5330. },
  5331. hideContextmenu : function() {
  5332. this.contextmenu.remove();
  5333. this.contextmenu = null;
  5334. return this;
  5335. },
  5336. createDialog : function(options) {
  5337. var self = this, name = options.name;
  5338. options.z = self.options.zIndex;
  5339. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5340. options.closeBtn = _undef(options.closeBtn, {
  5341. name : self.lang('close'),
  5342. click : function(e) {
  5343. self.hideDialog();
  5344. if (_IE && self.cmd) {
  5345. self.cmd.select();
  5346. }
  5347. }
  5348. });
  5349. options.noBtn = _undef(options.noBtn, {
  5350. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5351. click : function(e) {
  5352. self.hideDialog();
  5353. if (_IE && self.cmd) {
  5354. self.cmd.select();
  5355. }
  5356. }
  5357. });
  5358. if (self.dialogAlignType != 'page') {
  5359. options.alignEl = self.container;
  5360. }
  5361. options.cls = 'ke-dialog-' + self.themeType;
  5362. if (self.dialogs.length > 0) {
  5363. var firstDialog = self.dialogs[0],
  5364. parentDialog = self.dialogs[self.dialogs.length - 1];
  5365. firstDialog.setMaskIndex(parentDialog.z + 2);
  5366. options.z = parentDialog.z + 3;
  5367. options.showMask = false;
  5368. }
  5369. var dialog = _dialog(options);
  5370. self.dialogs.push(dialog);
  5371. return dialog;
  5372. },
  5373. hideDialog : function() {
  5374. var self = this;
  5375. if (self.dialogs.length > 0) {
  5376. self.dialogs.pop().remove();
  5377. }
  5378. if (self.dialogs.length > 0) {
  5379. var firstDialog = self.dialogs[0],
  5380. parentDialog = self.dialogs[self.dialogs.length - 1];
  5381. firstDialog.setMaskIndex(parentDialog.z - 1);
  5382. }
  5383. return self;
  5384. },
  5385. errorDialog : function(html) {
  5386. var self = this;
  5387. var dialog = self.createDialog({
  5388. width : 750,
  5389. title : self.lang('uploadError'),
  5390. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5391. });
  5392. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5393. doc.open();
  5394. doc.write(html);
  5395. doc.close();
  5396. K(doc.body).css('background-color', '#FFF');
  5397. iframe[0].contentWindow.focus();
  5398. return self;
  5399. }
  5400. };
  5401. function _editor(options) {
  5402. return new KEditor(options);
  5403. }
  5404. _instances = [];
  5405. function _create(expr, options) {
  5406. options = options || {};
  5407. options.basePath = _undef(options.basePath, K.basePath);
  5408. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5409. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5410. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5411. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5412. var themeType = _undef(options.themeType, K.options.themeType);
  5413. _loadStyle(options.themesPath + 'default/default.css');
  5414. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5415. }
  5416. function create(editor) {
  5417. _each(_plugins, function(name, fn) {
  5418. if (_isFunction(fn)) {
  5419. fn.call(editor, KindEditor);
  5420. }
  5421. });
  5422. return editor.create();
  5423. }
  5424. var knode = K(expr);
  5425. if (!knode || knode.length === 0) {
  5426. return;
  5427. }
  5428. if (knode.length > 1) {
  5429. knode.each(function() {
  5430. _create(this, options);
  5431. });
  5432. return _instances[0];
  5433. }
  5434. options.srcElement = knode[0];
  5435. var editor = new KEditor(options);
  5436. _instances.push(editor);
  5437. if (_language[editor.langType]) {
  5438. return create(editor);
  5439. }
  5440. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5441. create(editor);
  5442. });
  5443. return editor;
  5444. }
  5445. function _eachEditor(expr, fn) {
  5446. K(expr).each(function(i, el) {
  5447. K.each(_instances, function(j, editor) {
  5448. if (editor && editor.srcElement[0] == el) {
  5449. fn.call(editor, j);
  5450. return false;
  5451. }
  5452. });
  5453. });
  5454. }
  5455. K.remove = function(expr) {
  5456. _eachEditor(expr, function(i) {
  5457. this.remove();
  5458. _instances.splice(i, 1);
  5459. });
  5460. };
  5461. K.sync = function(expr) {
  5462. _eachEditor(expr, function() {
  5463. this.sync();
  5464. });
  5465. };
  5466. K.html = function(expr, val) {
  5467. _eachEditor(expr, function() {
  5468. this.html(val);
  5469. });
  5470. };
  5471. K.insertHtml = function(expr, val) {
  5472. _eachEditor(expr, function() {
  5473. this.insertHtml(val);
  5474. });
  5475. };
  5476. K.appendHtml = function(expr, val) {
  5477. _eachEditor(expr, function() {
  5478. this.appendHtml(val);
  5479. });
  5480. };
  5481. if (_IE && _V < 7) {
  5482. _nativeCommand(document, 'BackgroundImageCache', true);
  5483. }
  5484. K.EditorClass = KEditor;
  5485. K.editor = _editor;
  5486. K.create = _create;
  5487. K.instances = _instances;
  5488. K.plugin = _plugin;
  5489. K.lang = _lang;
  5490. _plugin('core', function(K) {
  5491. var self = this,
  5492. shortcutKeys = {
  5493. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5494. };
  5495. self.afterSetHtml(function() {
  5496. if (self.options.afterChange) {
  5497. self.options.afterChange.call(self);
  5498. }
  5499. });
  5500. self.afterCreate(function() {
  5501. if (self.syncType != 'form') {
  5502. return;
  5503. }
  5504. var el = K(self.srcElement), hasForm = false;
  5505. while ((el = el.parent())) {
  5506. if (el.name == 'form') {
  5507. hasForm = true;
  5508. break;
  5509. }
  5510. }
  5511. if (hasForm) {
  5512. el.bind('submit', function(e) {
  5513. self.sync();
  5514. K(window).bind('unload', function() {
  5515. self.edit.textarea.remove();
  5516. });
  5517. });
  5518. var resetBtn = K('[type="reset"]', el);
  5519. resetBtn.click(function() {
  5520. self.html(self.initContent);
  5521. self.cmd.selection();
  5522. });
  5523. self.beforeRemove(function() {
  5524. el.unbind();
  5525. resetBtn.unbind();
  5526. });
  5527. }
  5528. });
  5529. self.clickToolbar('source', function() {
  5530. if (self.edit.designMode) {
  5531. self.toolbar.disableAll(true);
  5532. self.edit.design(false);
  5533. self.toolbar.select('source');
  5534. } else {
  5535. self.toolbar.disableAll(false);
  5536. self.edit.design(true);
  5537. self.toolbar.unselect('source');
  5538. if (_GECKO) {
  5539. setTimeout(function() {
  5540. self.cmd.selection();
  5541. }, 0);
  5542. } else {
  5543. self.cmd.selection();
  5544. }
  5545. }
  5546. self.designMode = self.edit.designMode;
  5547. });
  5548. self.afterCreate(function() {
  5549. if (!self.designMode) {
  5550. self.toolbar.disableAll(true).select('source');
  5551. }
  5552. });
  5553. self.clickToolbar('fullscreen', function() {
  5554. self.fullscreen();
  5555. });
  5556. if (self.fullscreenShortcut) {
  5557. var loaded = false;
  5558. self.afterCreate(function() {
  5559. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5560. if (e.which == 27) {
  5561. setTimeout(function() {
  5562. self.fullscreen();
  5563. }, 0);
  5564. }
  5565. });
  5566. if (loaded) {
  5567. if (_IE && !self.designMode) {
  5568. return;
  5569. }
  5570. self.focus();
  5571. }
  5572. if (!loaded) {
  5573. loaded = true;
  5574. }
  5575. });
  5576. }
  5577. _each('undo,redo'.split(','), function(i, name) {
  5578. if (shortcutKeys[name]) {
  5579. self.afterCreate(function() {
  5580. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5581. self.clickToolbar(name);
  5582. });
  5583. });
  5584. }
  5585. self.clickToolbar(name, function() {
  5586. self[name]();
  5587. });
  5588. });
  5589. self.clickToolbar('formatblock', function() {
  5590. var blocks = self.lang('formatblock.formatBlock'),
  5591. heights = {
  5592. h1 : 28,
  5593. h2 : 24,
  5594. h3 : 18,
  5595. H4 : 14,
  5596. p : 12
  5597. },
  5598. curVal = self.cmd.val('formatblock'),
  5599. menu = self.createMenu({
  5600. name : 'formatblock',
  5601. width : self.langType == 'en' ? 200 : 150
  5602. });
  5603. _each(blocks, function(key, val) {
  5604. var style = 'font-size:' + heights[key] + 'px;';
  5605. if (key.charAt(0) === 'h') {
  5606. style += 'font-weight:bold;';
  5607. }
  5608. menu.addItem({
  5609. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5610. height : heights[key] + 12,
  5611. checked : (curVal === key || curVal === val),
  5612. click : function() {
  5613. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5614. }
  5615. });
  5616. });
  5617. });
  5618. self.clickToolbar('fontname', function() {
  5619. var curVal = self.cmd.val('fontname'),
  5620. menu = self.createMenu({
  5621. name : 'fontname',
  5622. width : 150
  5623. });
  5624. _each(self.lang('fontname.fontName'), function(key, val) {
  5625. menu.addItem({
  5626. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5627. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5628. click : function() {
  5629. self.exec('fontname', key).hideMenu();
  5630. }
  5631. });
  5632. });
  5633. });
  5634. self.clickToolbar('fontsize', function() {
  5635. var curVal = self.cmd.val('fontsize'),
  5636. menu = self.createMenu({
  5637. name : 'fontsize',
  5638. width : 150
  5639. });
  5640. _each(self.fontSizeTable, function(i, val) {
  5641. menu.addItem({
  5642. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5643. height : _removeUnit(val) + 12,
  5644. checked : curVal === val,
  5645. click : function() {
  5646. self.exec('fontsize', val).hideMenu();
  5647. }
  5648. });
  5649. });
  5650. });
  5651. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5652. self.clickToolbar(name, function() {
  5653. self.createMenu({
  5654. name : name,
  5655. selectedColor : self.cmd.val(name) || 'default',
  5656. colors : self.colorTable,
  5657. click : function(color) {
  5658. self.exec(name, color).hideMenu();
  5659. }
  5660. });
  5661. });
  5662. });
  5663. _each(('cut,copy,paste').split(','), function(i, name) {
  5664. self.clickToolbar(name, function() {
  5665. self.focus();
  5666. try {
  5667. self.exec(name, null);
  5668. } catch(e) {
  5669. }
  5670. });
  5671. });
  5672. self.clickToolbar('about', function() {
  5673. var html = '<div style="margin:20px;">' +
  5674. '<div>KindEditor ' + _VERSION + '</div>' +
  5675. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5676. '</div>';
  5677. self.createDialog({
  5678. name : 'about',
  5679. width : 350,
  5680. title : self.lang('about'),
  5681. body : html
  5682. });
  5683. });
  5684. self.plugin.getSelectedLink = function() {
  5685. return self.cmd.commonAncestor('a');
  5686. };
  5687. self.plugin.getSelectedImage = function() {
  5688. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5689. return !/^ke-\w+$/i.test(img[0].className);
  5690. });
  5691. };
  5692. self.plugin.getSelectedFlash = function() {
  5693. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5694. return img[0].className == 'ke-flash';
  5695. });
  5696. };
  5697. self.plugin.getSelectedMedia = function() {
  5698. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5699. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5700. });
  5701. };
  5702. self.plugin.getSelectedAnchor = function() {
  5703. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5704. return img[0].className == 'ke-anchor';
  5705. });
  5706. };
  5707. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5708. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5709. _each('edit,delete'.split(','), function(j, val) {
  5710. self.addContextmenu({
  5711. title : self.lang(val + uName),
  5712. click : function() {
  5713. self.loadPlugin(name, function() {
  5714. self.plugin[name][val]();
  5715. self.hideMenu();
  5716. });
  5717. },
  5718. cond : self.plugin['getSelected' + uName],
  5719. width : 150,
  5720. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5721. });
  5722. });
  5723. self.addContextmenu({ title : '-' });
  5724. });
  5725. self.plugin.getSelectedTable = function() {
  5726. return self.cmd.commonAncestor('table');
  5727. };
  5728. self.plugin.getSelectedRow = function() {
  5729. return self.cmd.commonAncestor('tr');
  5730. };
  5731. self.plugin.getSelectedCell = function() {
  5732. return self.cmd.commonAncestor('td');
  5733. };
  5734. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5735. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5736. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5737. self.addContextmenu({
  5738. title : self.lang('table' + val),
  5739. click : function() {
  5740. self.loadPlugin('table', function() {
  5741. self.plugin.table[val]();
  5742. self.hideMenu();
  5743. });
  5744. },
  5745. cond : cond,
  5746. width : 170,
  5747. iconClass : 'ke-icon-table' + val
  5748. });
  5749. });
  5750. self.addContextmenu({ title : '-' });
  5751. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5752. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5753. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5754. if (shortcutKeys[name]) {
  5755. self.afterCreate(function() {
  5756. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5757. self.cmd.selection();
  5758. self.clickToolbar(name);
  5759. });
  5760. });
  5761. }
  5762. self.clickToolbar(name, function() {
  5763. self.focus().exec(name, null);
  5764. });
  5765. });
  5766. self.afterCreate(function() {
  5767. var doc = self.edit.doc, cmd, bookmark, div,
  5768. cls = '__kindeditor_paste__', pasting = false;
  5769. function movePastedData() {
  5770. cmd.range.moveToBookmark(bookmark);
  5771. cmd.select();
  5772. if (_WEBKIT) {
  5773. K('div.' + cls, div).each(function() {
  5774. K(this).after('<br />').remove(true);
  5775. });
  5776. K('span.Apple-style-span', div).remove(true);
  5777. K('span.Apple-tab-span', div).remove(true);
  5778. K('span[style]', div).each(function() {
  5779. if (K(this).css('white-space') == 'nowrap') {
  5780. K(this).remove(true);
  5781. }
  5782. });
  5783. K('meta', div).remove();
  5784. }
  5785. var html = div[0].innerHTML;
  5786. div.remove();
  5787. if (html === '') {
  5788. return;
  5789. }
  5790. if (_WEBKIT) {
  5791. html = html.replace(/(<br>)\1/ig, '$1');
  5792. }
  5793. if (self.pasteType === 2) {
  5794. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5795. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5796. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5797. } else {
  5798. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5799. html = self.beforeSetHtml(html);
  5800. }
  5801. }
  5802. if (self.pasteType === 1) {
  5803. html = html.replace(/&nbsp;/ig, ' ');
  5804. html = html.replace(/\n\s*\n/g, '\n');
  5805. html = html.replace(/<br[^>]*>/ig, '\n');
  5806. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5807. html = html.replace(/<[^>]+>/g, '');
  5808. html = html.replace(/ {2}/g, ' &nbsp;');
  5809. if (self.newlineTag == 'p') {
  5810. if (/\n/.test(html)) {
  5811. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5812. }
  5813. } else {
  5814. html = html.replace(/\n/g, '<br />$&');
  5815. }
  5816. }
  5817. self.insertHtml(html, true);
  5818. }
  5819. K(doc.body).bind('paste', function(e){
  5820. if (self.pasteType === 0) {
  5821. e.stop();
  5822. return;
  5823. }
  5824. if (pasting) {
  5825. return;
  5826. }
  5827. pasting = true;
  5828. K('div.' + cls, doc).remove();
  5829. cmd = self.cmd.selection();
  5830. bookmark = cmd.range.createBookmark();
  5831. div = K('<div class="' + cls + '"></div>', doc).css({
  5832. position : 'absolute',
  5833. width : '1px',
  5834. height : '1px',
  5835. overflow : 'hidden',
  5836. left : '-1981px',
  5837. top : K(bookmark.start).pos().y + 'px',
  5838. 'white-space' : 'nowrap'
  5839. });
  5840. K(doc.body).append(div);
  5841. if (_IE) {
  5842. var rng = cmd.range.get(true);
  5843. rng.moveToElementText(div[0]);
  5844. rng.select();
  5845. rng.execCommand('paste');
  5846. e.preventDefault();
  5847. } else {
  5848. cmd.range.selectNodeContents(div[0]);
  5849. cmd.select();
  5850. }
  5851. setTimeout(function() {
  5852. movePastedData();
  5853. pasting = false;
  5854. }, 0);
  5855. });
  5856. });
  5857. self.beforeGetHtml(function(html) {
  5858. if (_IE && _V <= 8) {
  5859. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5860. return unescape(tag);
  5861. });
  5862. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5863. if (!/\s+type="[^"]+"/i.test($0)) {
  5864. return $1 + ' type="text"' + $2;
  5865. }
  5866. return $0;
  5867. });
  5868. }
  5869. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5870. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5871. })
  5872. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5873. var imgAttrs = _getAttrList(full);
  5874. var styles = _getCssList(imgAttrs.style || '');
  5875. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5876. var width = _undef(styles.width, '');
  5877. var height = _undef(styles.height, '');
  5878. if (/px/i.test(width)) {
  5879. width = _removeUnit(width);
  5880. }
  5881. if (/px/i.test(height)) {
  5882. height = _removeUnit(height);
  5883. }
  5884. attrs.width = _undef(imgAttrs.width, width);
  5885. attrs.height = _undef(imgAttrs.height, height);
  5886. return _mediaEmbed(attrs);
  5887. })
  5888. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  5889. var imgAttrs = _getAttrList(full);
  5890. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5891. })
  5892. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5893. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5894. })
  5895. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5896. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5897. })
  5898. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  5899. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  5900. return $1 + _unescape(src) + $2;
  5901. });
  5902. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5903. return full;
  5904. })
  5905. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5906. return start + end;
  5907. });
  5908. });
  5909. self.beforeSetHtml(function(html) {
  5910. if (_IE && _V <= 8) {
  5911. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  5912. var attrs = _getAttrList(full);
  5913. var styles = _getCssList(attrs.style || '');
  5914. if (styles.display == 'none') {
  5915. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5916. }
  5917. return full;
  5918. });
  5919. }
  5920. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  5921. var attrs = _getAttrList(full);
  5922. attrs.src = _undef(attrs.src, '');
  5923. attrs.width = _undef(attrs.width, 0);
  5924. attrs.height = _undef(attrs.height, 0);
  5925. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5926. })
  5927. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  5928. var attrs = _getAttrList(full);
  5929. if (attrs.href !== undefined) {
  5930. return full;
  5931. }
  5932. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5933. })
  5934. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  5935. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5936. })
  5937. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  5938. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5939. })
  5940. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  5941. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5942. return full;
  5943. }
  5944. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5945. return full;
  5946. })
  5947. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5948. return start + 'data-ke-' + end;
  5949. })
  5950. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  5951. if (full.indexOf('ke-zeroborder') >= 0) {
  5952. return full;
  5953. }
  5954. return _addClassToTag(full, 'ke-zeroborder');
  5955. });
  5956. });
  5957. });
  5958. })(window);
  5959. /*******************************************************************************
  5960. * KindEditor - WYSIWYG HTML Editor for Internet
  5961. * Copyright (C) 2006-2011 kindsoft.net
  5962. *
  5963. * @author Roddy <luolonghao@gmail.com>
  5964. * @site http://www.kindsoft.net/
  5965. * @licence http://www.kindsoft.net/license.php
  5966. *******************************************************************************/
  5967. KindEditor.lang({
  5968. source : 'HTML代码',
  5969. preview : '预览',
  5970. undo : '后退(Ctrl+Z)',
  5971. redo : '前进(Ctrl+Y)',
  5972. cut : '剪切(Ctrl+X)',
  5973. copy : '复制(Ctrl+C)',
  5974. paste : '粘贴(Ctrl+V)',
  5975. plainpaste : '粘贴为无格式文本',
  5976. wordpaste : '从Word粘贴',
  5977. selectall : '全选(Ctrl+A)',
  5978. justifyleft : '左对齐',
  5979. justifycenter : '居中',
  5980. justifyright : '右对齐',
  5981. justifyfull : '两端对齐',
  5982. insertorderedlist : '编号',
  5983. insertunorderedlist : '项目符号',
  5984. indent : '增加缩进',
  5985. outdent : '减少缩进',
  5986. subscript : '下标',
  5987. superscript : '上标',
  5988. formatblock : '段落',
  5989. fontname : '字体',
  5990. fontsize : '文字大小',
  5991. forecolor : '文字颜色',
  5992. hilitecolor : '文字背景',
  5993. bold : '粗体(Ctrl+B)',
  5994. italic : '斜体(Ctrl+I)',
  5995. underline : '下划线(Ctrl+U)',
  5996. strikethrough : '删除线',
  5997. removeformat : '删除格式',
  5998. image : '图片',
  5999. multiimage : '批量图片上传',
  6000. flash : 'Flash',
  6001. media : '视音频',
  6002. table : '表格',
  6003. tablecell : '单元格',
  6004. hr : '插入横线',
  6005. emoticons : '插入表情',
  6006. link : '超级链接',
  6007. unlink : '取消超级链接',
  6008. fullscreen : '全屏显示',
  6009. about : '关于',
  6010. print : '打印(Ctrl+P)',
  6011. filemanager : '文件空间',
  6012. code : '插入程序代码',
  6013. map : 'Google地图',
  6014. baidumap : '百度地图',
  6015. lineheight : '行距',
  6016. clearhtml : '清理HTML代码',
  6017. pagebreak : '插入分页符',
  6018. quickformat : '一键排版',
  6019. insertfile : '插入文件',
  6020. template : '插入模板',
  6021. anchor : '锚点',
  6022. yes : '确定',
  6023. no : '取消',
  6024. close : '关闭',
  6025. editImage : '图片属性',
  6026. deleteImage : '删除图片',
  6027. editFlash : 'Flash属性',
  6028. deleteFlash : '删除Flash',
  6029. editMedia : '视音频属性',
  6030. deleteMedia : '删除视音频',
  6031. editLink : '超级链接属性',
  6032. deleteLink : '取消超级链接',
  6033. editAnchor : '锚点属性',
  6034. deleteAnchor : '删除锚点',
  6035. tableprop : '表格属性',
  6036. tablecellprop : '单元格属性',
  6037. tableinsert : '插入表格',
  6038. tabledelete : '删除表格',
  6039. tablecolinsertleft : '左侧插入列',
  6040. tablecolinsertright : '右侧插入列',
  6041. tablerowinsertabove : '上方插入行',
  6042. tablerowinsertbelow : '下方插入行',
  6043. tablerowmerge : '向下合并单元格',
  6044. tablecolmerge : '向右合并单元格',
  6045. tablerowsplit : '拆分行',
  6046. tablecolsplit : '拆分列',
  6047. tablecoldelete : '删除列',
  6048. tablerowdelete : '删除行',
  6049. noColor : '无颜色',
  6050. pleaseSelectFile : '请选择文件。',
  6051. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6052. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6053. invalidWidth : "宽度必须为数字。",
  6054. invalidHeight : "高度必须为数字。",
  6055. invalidBorder : "边框必须为数字。",
  6056. invalidUrl : "请输入有效的URL地址。",
  6057. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6058. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6059. invalidPadding : '边距必须为数字。',
  6060. invalidSpacing : '间距必须为数字。',
  6061. invalidJson : '服务器发生故障。',
  6062. uploadSuccess : '上传成功。',
  6063. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6064. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6065. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6066. ajaxLoading : '加载中,请稍候 ...',
  6067. uploadLoading : '上传中,请稍候 ...',
  6068. uploadError : '上传错误',
  6069. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6070. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6071. 'code.pleaseInput' : '请输入程序代码。',
  6072. 'link.url' : 'URL',
  6073. 'link.linkType' : '打开类型',
  6074. 'link.newWindow' : '新窗口',
  6075. 'link.selfWindow' : '当前窗口',
  6076. 'flash.url' : 'URL',
  6077. 'flash.width' : '宽度',
  6078. 'flash.height' : '高度',
  6079. 'flash.upload' : '上传',
  6080. 'flash.viewServer' : '文件空间',
  6081. 'media.url' : 'URL',
  6082. 'media.width' : '宽度',
  6083. 'media.height' : '高度',
  6084. 'media.autostart' : '自动播放',
  6085. 'media.upload' : '上传',
  6086. 'media.viewServer' : '文件空间',
  6087. 'image.remoteImage' : '网络图片',
  6088. 'image.localImage' : '本地上传',
  6089. 'image.remoteUrl' : '图片地址',
  6090. 'image.localUrl' : '上传文件',
  6091. 'image.size' : '图片大小',
  6092. 'image.width' : '宽',
  6093. 'image.height' : '高',
  6094. 'image.resetSize' : '重置大小',
  6095. 'image.align' : '对齐方式',
  6096. 'image.defaultAlign' : '默认方式',
  6097. 'image.leftAlign' : '左对齐',
  6098. 'image.rightAlign' : '右对齐',
  6099. 'image.imgTitle' : '图片说明',
  6100. 'image.upload' : '浏览...',
  6101. 'image.viewServer' : '图片空间',
  6102. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6103. 'multiimage.startUpload' : '开始上传',
  6104. 'multiimage.clearAll' : '全部清空',
  6105. 'multiimage.insertAll' : '全部插入',
  6106. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6107. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6108. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6109. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6110. 'multiimage.unknownError' : '发生异常,无法上传。',
  6111. 'multiimage.pending' : '等待上传',
  6112. 'multiimage.uploadError' : '上传失败',
  6113. 'filemanager.emptyFolder' : '空文件夹',
  6114. 'filemanager.moveup' : '移到上一级文件夹',
  6115. 'filemanager.viewType' : '显示方式:',
  6116. 'filemanager.viewImage' : '缩略图',
  6117. 'filemanager.listImage' : '详细信息',
  6118. 'filemanager.orderType' : '排序方式:',
  6119. 'filemanager.fileName' : '名称',
  6120. 'filemanager.fileSize' : '大小',
  6121. 'filemanager.fileType' : '类型',
  6122. 'insertfile.url' : 'URL',
  6123. 'insertfile.title' : '文件说明',
  6124. 'insertfile.upload' : '上传',
  6125. 'insertfile.viewServer' : '文件空间',
  6126. 'table.cells' : '单元格数',
  6127. 'table.rows' : '行数',
  6128. 'table.cols' : '列数',
  6129. 'table.size' : '大小',
  6130. 'table.width' : '宽度',
  6131. 'table.height' : '高度',
  6132. 'table.percent' : '%',
  6133. 'table.px' : 'px',
  6134. 'table.space' : '边距间距',
  6135. 'table.padding' : '边距',
  6136. 'table.spacing' : '间距',
  6137. 'table.align' : '对齐方式',
  6138. 'table.textAlign' : '水平对齐',
  6139. 'table.verticalAlign' : '垂直对齐',
  6140. 'table.alignDefault' : '默认',
  6141. 'table.alignLeft' : '左对齐',
  6142. 'table.alignCenter' : '居中',
  6143. 'table.alignRight' : '右对齐',
  6144. 'table.alignTop' : '顶部',
  6145. 'table.alignMiddle' : '中部',
  6146. 'table.alignBottom' : '底部',
  6147. 'table.alignBaseline' : '基线',
  6148. 'table.border' : '边框',
  6149. 'table.borderWidth' : '边框',
  6150. 'table.borderColor' : '颜色',
  6151. 'table.backgroundColor' : '背景颜色',
  6152. 'map.address' : '地址: ',
  6153. 'map.search' : '搜索',
  6154. 'baidumap.address' : '地址: ',
  6155. 'baidumap.search' : '搜索',
  6156. 'baidumap.insertDynamicMap' : '插入动态地图',
  6157. 'anchor.name' : '锚点名称',
  6158. 'formatblock.formatBlock' : {
  6159. h1 : '标题 1',
  6160. h2 : '标题 2',
  6161. h3 : '标题 3',
  6162. h4 : '标题 4',
  6163. p : '正 文'
  6164. },
  6165. 'fontname.fontName' : {
  6166. 'SimSun' : '宋体',
  6167. 'NSimSun' : '新宋体',
  6168. 'FangSong_GB2312' : '仿宋_GB2312',
  6169. 'KaiTi_GB2312' : '楷体_GB2312',
  6170. 'SimHei' : '黑体',
  6171. 'Microsoft YaHei' : '微软雅黑',
  6172. 'Arial' : 'Arial',
  6173. 'Arial Black' : 'Arial Black',
  6174. 'Times New Roman' : 'Times New Roman',
  6175. 'Courier New' : 'Courier New',
  6176. 'Tahoma' : 'Tahoma',
  6177. 'Verdana' : 'Verdana'
  6178. },
  6179. 'lineheight.lineHeight' : [
  6180. {'1' : '单倍行距'},
  6181. {'1.5' : '1.5倍行距'},
  6182. {'2' : '2倍行距'},
  6183. {'2.5' : '2.5倍行距'},
  6184. {'3' : '3倍行距'}
  6185. ],
  6186. 'template.selectTemplate' : '可选模板',
  6187. 'template.replaceContent' : '替换当前内容',
  6188. 'template.fileList' : {
  6189. '1.html' : '图片和文字',
  6190. '2.html' : '表格',
  6191. '3.html' : '项目编号'
  6192. }
  6193. }, 'zh_CN');
  6194. /*******************************************************************************
  6195. * KindEditor - WYSIWYG HTML Editor for Internet
  6196. * Copyright (C) 2006-2011 kindsoft.net
  6197. *
  6198. * @author Roddy <luolonghao@gmail.com>
  6199. * @site http://www.kindsoft.net/
  6200. * @licence http://www.kindsoft.net/license.php
  6201. *******************************************************************************/
  6202. KindEditor.plugin('anchor', function(K) {
  6203. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6204. self.plugin.anchor = {
  6205. edit : function() {
  6206. var html = ['<div style="padding:20px;">',
  6207. '<div class="ke-dialog-row">',
  6208. '<label for="keName">' + lang.name + '</label>',
  6209. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6210. '</div>',
  6211. '</div>'].join('');
  6212. var dialog = self.createDialog({
  6213. name : name,
  6214. width : 300,
  6215. title : self.lang(name),
  6216. body : html,
  6217. yesBtn : {
  6218. name : self.lang('yes'),
  6219. click : function(e) {
  6220. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6221. }
  6222. }
  6223. });
  6224. var div = dialog.div,
  6225. nameBox = K('input[name="name"]', div);
  6226. var img = self.plugin.getSelectedAnchor();
  6227. if (img) {
  6228. nameBox.val(unescape(img.attr('data-ke-name')));
  6229. }
  6230. nameBox[0].focus();
  6231. nameBox[0].select();
  6232. },
  6233. 'delete' : function() {
  6234. self.plugin.getSelectedAnchor().remove();
  6235. }
  6236. };
  6237. self.clickToolbar(name, self.plugin.anchor.edit);
  6238. });
  6239. /*******************************************************************************
  6240. * KindEditor - WYSIWYG HTML Editor for Internet
  6241. * Copyright (C) 2006-2011 kindsoft.net
  6242. *
  6243. * @author Roddy <luolonghao@gmail.com>
  6244. * @site http://www.kindsoft.net/
  6245. * @licence http://www.kindsoft.net/license.php
  6246. *******************************************************************************/
  6247. KindEditor.plugin('autoheight', function(K) {
  6248. var self = this;
  6249. if (!self.autoHeightMode) {
  6250. return;
  6251. }
  6252. var minHeight;
  6253. function hideScroll() {
  6254. var edit = self.edit;
  6255. var body = edit.doc.body;
  6256. edit.iframe[0].scroll = 'no';
  6257. body.style.overflowY = 'hidden';
  6258. }
  6259. function resetHeight() {
  6260. var edit = self.edit;
  6261. var body = edit.doc.body;
  6262. edit.iframe.height(minHeight);
  6263. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6264. }
  6265. function init() {
  6266. minHeight = K.removeUnit(self.height);
  6267. self.edit.afterChange(resetHeight);
  6268. hideScroll();
  6269. resetHeight();
  6270. }
  6271. if (self.isCreated) {
  6272. init();
  6273. } else {
  6274. self.afterCreate(init);
  6275. }
  6276. });
  6277. /*
  6278. * 如何实现真正的自动高度?
  6279. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6280. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6281. * 由此就实现了真正的自动高度
  6282. * 测试:chrome、firefox、IE9、IE8
  6283. * */
  6284. /*******************************************************************************
  6285. * KindEditor - WYSIWYG HTML Editor for Internet
  6286. * Copyright (C) 2006-2011 kindsoft.net
  6287. *
  6288. * @author Roddy <luolonghao@gmail.com>
  6289. * @site http://www.kindsoft.net/
  6290. * @licence http://www.kindsoft.net/license.php
  6291. *******************************************************************************/
  6292. // Baidu Maps: http://dev.baidu.com/wiki/map/index.php?title=%E9%A6%96%E9%A1%B5
  6293. KindEditor.plugin('baidumap', function(K) {
  6294. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6295. var mapWidth = K.undef(self.mapWidth, 558);
  6296. var mapHeight = K.undef(self.mapHeight, 360);
  6297. self.clickToolbar(name, function() {
  6298. var html = ['<div style="padding:10px 20px;">',
  6299. '<div class="ke-header">',
  6300. // left start
  6301. '<div class="ke-left">',
  6302. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6303. '<span class="ke-button-common ke-button-outer">',
  6304. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6305. '</span>',
  6306. '</div>',
  6307. // right start
  6308. '<div class="ke-right">',
  6309. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6310. '</div>',
  6311. '<div class="ke-clearfix"></div>',
  6312. '</div>',
  6313. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6314. '</div>'].join('');
  6315. var dialog = self.createDialog({
  6316. name : name,
  6317. width : mapWidth + 42,
  6318. title : self.lang(name),
  6319. body : html,
  6320. yesBtn : {
  6321. name : self.lang('yes'),
  6322. click : function(e) {
  6323. var map = win.map;
  6324. var centerObj = map.getCenter();
  6325. var center = centerObj.lng + ',' + centerObj.lat;
  6326. var zoom = map.getZoom();
  6327. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6328. '?center=' + encodeURIComponent(center),
  6329. '&zoom=' + encodeURIComponent(zoom),
  6330. '&width=' + mapWidth,
  6331. '&height=' + mapHeight,
  6332. '&markers=' + encodeURIComponent(center),
  6333. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6334. if (checkbox[0].checked) {
  6335. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6336. } else {
  6337. self.exec('insertimage', url);
  6338. }
  6339. self.hideDialog().focus();
  6340. }
  6341. },
  6342. beforeRemove : function() {
  6343. searchBtn.remove();
  6344. if (doc) {
  6345. doc.write('');
  6346. }
  6347. iframe.remove();
  6348. }
  6349. });
  6350. var div = dialog.div,
  6351. addressBox = K('[name="address"]', div),
  6352. searchBtn = K('[name="searchBtn"]', div),
  6353. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6354. win, doc;
  6355. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6356. function ready() {
  6357. win = iframe[0].contentWindow;
  6358. doc = K.iframeDoc(iframe);
  6359. }
  6360. iframe.bind('load', function() {
  6361. iframe.unbind('load');
  6362. if (K.IE) {
  6363. ready();
  6364. } else {
  6365. setTimeout(ready, 0);
  6366. }
  6367. });
  6368. K('.ke-map', div).replaceWith(iframe);
  6369. // search map
  6370. searchBtn.click(function() {
  6371. win.search(addressBox.val());
  6372. });
  6373. });
  6374. });
  6375. /*******************************************************************************
  6376. * KindEditor - WYSIWYG HTML Editor for Internet
  6377. * Copyright (C) 2006-2011 kindsoft.net
  6378. *
  6379. * @author Roddy <luolonghao@gmail.com>
  6380. * @site http://www.kindsoft.net/
  6381. * @licence http://www.kindsoft.net/license.php
  6382. *******************************************************************************/
  6383. KindEditor.plugin('clearhtml', function(K) {
  6384. var self = this, name = 'clearhtml';
  6385. self.clickToolbar(name, function() {
  6386. self.focus();
  6387. var html = self.html();
  6388. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6389. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6390. html = K.formatHtml(html, {
  6391. a : ['href', 'target'],
  6392. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6393. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6394. table : ['border'],
  6395. 'td,th' : ['rowspan', 'colspan'],
  6396. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6397. });
  6398. self.html(html);
  6399. self.cmd.selection(true);
  6400. self.addBookmark();
  6401. });
  6402. });
  6403. /*******************************************************************************
  6404. * KindEditor - WYSIWYG HTML Editor for Internet
  6405. * Copyright (C) 2006-2011 kindsoft.net
  6406. *
  6407. * @author Roddy <luolonghao@gmail.com>
  6408. * @site http://www.kindsoft.net/
  6409. * @licence http://www.kindsoft.net/license.php
  6410. *******************************************************************************/
  6411. // google code prettify: http://google-code-prettify.googlecode.com/
  6412. // http://google-code-prettify.googlecode.com/
  6413. KindEditor.plugin('code', function(K) {
  6414. var self = this, name = 'code';
  6415. self.clickToolbar(name, function() {
  6416. var lang = self.lang(name + '.'),
  6417. html = ['<div style="padding:10px 20px;">',
  6418. '<div class="ke-dialog-row">',
  6419. '<select class="ke-code-type">',
  6420. '<option value="js">JavaScript</option>',
  6421. '<option value="html">HTML</option>',
  6422. '<option value="css">CSS</option>',
  6423. '<option value="php">PHP</option>',
  6424. '<option value="pl">Perl</option>',
  6425. '<option value="py">Python</option>',
  6426. '<option value="rb">Ruby</option>',
  6427. '<option value="java">Java</option>',
  6428. '<option value="vb">ASP/VB</option>',
  6429. '<option value="cpp">C/C++</option>',
  6430. '<option value="cs">C#</option>',
  6431. '<option value="xml">XML</option>',
  6432. '<option value="bsh">Shell</option>',
  6433. '<option value="">Other</option>',
  6434. '</select>',
  6435. '</div>',
  6436. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6437. '</div>'].join(''),
  6438. dialog = self.createDialog({
  6439. name : name,
  6440. width : 450,
  6441. title : self.lang(name),
  6442. body : html,
  6443. yesBtn : {
  6444. name : self.lang('yes'),
  6445. click : function(e) {
  6446. var type = K('.ke-code-type', dialog.div).val(),
  6447. code = textarea.val(),
  6448. cls = type === '' ? '' : ' lang-' + type,
  6449. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6450. if (K.trim(code) === '') {
  6451. textarea[0].focus();
  6452. return;
  6453. }
  6454. self.insertHtml(html).hideDialog().focus();
  6455. }
  6456. }
  6457. }),
  6458. textarea = K('textarea', dialog.div);
  6459. textarea[0].focus();
  6460. });
  6461. });
  6462. /*******************************************************************************
  6463. * KindEditor - WYSIWYG HTML Editor for Internet
  6464. * Copyright (C) 2006-2011 kindsoft.net
  6465. *
  6466. * @author Roddy <luolonghao@gmail.com>
  6467. * @site http://www.kindsoft.net/
  6468. * @licence http://www.kindsoft.net/license.php
  6469. *******************************************************************************/
  6470. KindEditor.plugin('emoticons', function(K) {
  6471. var self = this, name = 'emoticons',
  6472. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6473. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6474. currentPageNum = 1;
  6475. self.clickToolbar(name, function() {
  6476. var rows = 5, cols = 9, total = 135, startNum = 0,
  6477. cells = rows * cols, pages = Math.ceil(total / cells),
  6478. colsHalf = Math.floor(cols / 2),
  6479. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6480. elements = [],
  6481. menu = self.createMenu({
  6482. name : name,
  6483. beforeRemove : function() {
  6484. removeEvent();
  6485. }
  6486. });
  6487. menu.div.append(wrapperDiv);
  6488. var previewDiv, previewImg;
  6489. if (allowPreview) {
  6490. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6491. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6492. wrapperDiv.append(previewDiv);
  6493. previewDiv.append(previewImg);
  6494. }
  6495. function bindCellEvent(cell, j, num) {
  6496. if (previewDiv) {
  6497. cell.mouseover(function() {
  6498. if (j > colsHalf) {
  6499. previewDiv.css('left', 0);
  6500. previewDiv.css('right', '');
  6501. } else {
  6502. previewDiv.css('left', '');
  6503. previewDiv.css('right', 0);
  6504. }
  6505. previewImg.attr('src', path + num + '.gif');
  6506. K(this).addClass('ke-on');
  6507. });
  6508. } else {
  6509. cell.mouseover(function() {
  6510. K(this).addClass('ke-on');
  6511. });
  6512. }
  6513. cell.mouseout(function() {
  6514. K(this).removeClass('ke-on');
  6515. });
  6516. cell.click(function(e) {
  6517. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6518. e.stop();
  6519. });
  6520. }
  6521. function createEmoticonsTable(pageNum, parentDiv) {
  6522. var table = document.createElement('table');
  6523. parentDiv.append(table);
  6524. if (previewDiv) {
  6525. K(table).mouseover(function() {
  6526. previewDiv.show('block');
  6527. });
  6528. K(table).mouseout(function() {
  6529. previewDiv.hide();
  6530. });
  6531. elements.push(K(table));
  6532. }
  6533. table.className = 'ke-table';
  6534. table.cellPadding = 0;
  6535. table.cellSpacing = 0;
  6536. table.border = 0;
  6537. var num = (pageNum - 1) * cells + startNum;
  6538. for (var i = 0; i < rows; i++) {
  6539. var row = table.insertRow(i);
  6540. for (var j = 0; j < cols; j++) {
  6541. var cell = K(row.insertCell(j));
  6542. cell.addClass('ke-cell');
  6543. bindCellEvent(cell, j, num);
  6544. var span = K('<span class="ke-img"></span>')
  6545. .css('background-position', '-' + (24 * num) + 'px 0px')
  6546. .css('background-image', 'url(' + path + 'static.gif)');
  6547. cell.append(span);
  6548. elements.push(cell);
  6549. num++;
  6550. }
  6551. }
  6552. return table;
  6553. }
  6554. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6555. function removeEvent() {
  6556. K.each(elements, function() {
  6557. this.unbind();
  6558. });
  6559. }
  6560. var pageDiv;
  6561. function bindPageEvent(el, pageNum) {
  6562. el.click(function(e) {
  6563. removeEvent();
  6564. table.parentNode.removeChild(table);
  6565. pageDiv.remove();
  6566. table = createEmoticonsTable(pageNum, wrapperDiv);
  6567. createPageTable(pageNum);
  6568. currentPageNum = pageNum;
  6569. e.stop();
  6570. });
  6571. }
  6572. function createPageTable(currentPageNum) {
  6573. pageDiv = K('<div class="ke-page"></div>');
  6574. wrapperDiv.append(pageDiv);
  6575. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6576. if (currentPageNum !== pageNum) {
  6577. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6578. bindPageEvent(a, pageNum);
  6579. pageDiv.append(a);
  6580. elements.push(a);
  6581. } else {
  6582. pageDiv.append(K('@[' + pageNum + ']'));
  6583. }
  6584. pageDiv.append(K('@&nbsp;'));
  6585. }
  6586. }
  6587. createPageTable(currentPageNum);
  6588. });
  6589. });
  6590. /*******************************************************************************
  6591. * KindEditor - WYSIWYG HTML Editor for Internet
  6592. * Copyright (C) 2006-2011 kindsoft.net
  6593. *
  6594. * @author Roddy <luolonghao@gmail.com>
  6595. * @site http://www.kindsoft.net/
  6596. * @licence http://www.kindsoft.net/license.php
  6597. *******************************************************************************/
  6598. KindEditor.plugin('filemanager', function(K) {
  6599. var self = this, name = 'filemanager',
  6600. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'jsp/file_manager_json.jsp'),
  6601. imgPath = self.pluginsPath + name + '/images/',
  6602. lang = self.lang(name + '.');
  6603. function makeFileTitle(filename, filesize, datetime) {
  6604. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6605. }
  6606. function bindTitle(el, data) {
  6607. if (data.is_dir) {
  6608. el.attr('title', data.filename);
  6609. } else {
  6610. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6611. }
  6612. }
  6613. self.plugin.filemanagerDialog = function(options) {
  6614. var width = K.undef(options.width, 650),
  6615. height = K.undef(options.height, 510),
  6616. dirName = K.undef(options.dirName, ''),
  6617. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(), // "LIST" or "VIEW"
  6618. clickFn = options.clickFn;
  6619. var html = [
  6620. '<div style="padding:10px 20px;">',
  6621. // header start
  6622. '<div class="ke-plugin-filemanager-header">',
  6623. // left start
  6624. '<div class="ke-left">',
  6625. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6626. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6627. '</div>',
  6628. // right start
  6629. '<div class="ke-right">',
  6630. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6631. '<option value="VIEW">' + lang.viewImage + '</option>',
  6632. '<option value="LIST">' + lang.listImage + '</option>',
  6633. '</select> ',
  6634. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6635. '<option value="NAME">' + lang.fileName + '</option>',
  6636. '<option value="SIZE">' + lang.fileSize + '</option>',
  6637. '<option value="TYPE">' + lang.fileType + '</option>',
  6638. '</select>',
  6639. '</div>',
  6640. '<div class="ke-clearfix"></div>',
  6641. '</div>',
  6642. // body start
  6643. '<div class="ke-plugin-filemanager-body"></div>',
  6644. '</div>'
  6645. ].join('');
  6646. var dialog = self.createDialog({
  6647. name : name,
  6648. width : width,
  6649. height : height,
  6650. title : self.lang(name),
  6651. body : html
  6652. }),
  6653. div = dialog.div,
  6654. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6655. moveupImg = K('[name="moveupImg"]', div),
  6656. moveupLink = K('[name="moveupLink"]', div),
  6657. viewServerBtn = K('[name="viewServer"]', div),
  6658. viewTypeBox = K('[name="viewType"]', div),
  6659. orderTypeBox = K('[name="orderType"]', div);
  6660. function reloadPage(path, order, func) {
  6661. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6662. dialog.showLoading(self.lang('ajaxLoading'));
  6663. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6664. dialog.hideLoading();
  6665. func(data);
  6666. });
  6667. }
  6668. var elList = [];
  6669. function bindEvent(el, result, data, createFunc) {
  6670. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6671. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6672. if (data.is_dir) {
  6673. el.click(function(e) {
  6674. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6675. });
  6676. } else if (data.is_photo) {
  6677. el.click(function(e) {
  6678. clickFn.call(this, fileUrl, data.filename);
  6679. });
  6680. } else {
  6681. el.click(function(e) {
  6682. clickFn.call(this, fileUrl, data.filename);
  6683. });
  6684. }
  6685. elList.push(el);
  6686. }
  6687. function createCommon(result, createFunc) {
  6688. // remove events
  6689. K.each(elList, function() {
  6690. this.unbind();
  6691. });
  6692. moveupLink.unbind();
  6693. viewTypeBox.unbind();
  6694. orderTypeBox.unbind();
  6695. // add events
  6696. if (result.current_dir_path) {
  6697. moveupLink.click(function(e) {
  6698. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6699. });
  6700. }
  6701. function changeFunc() {
  6702. if (viewTypeBox.val() == 'VIEW') {
  6703. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6704. } else {
  6705. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6706. }
  6707. }
  6708. viewTypeBox.change(changeFunc);
  6709. orderTypeBox.change(changeFunc);
  6710. bodyDiv.html('');
  6711. }
  6712. function createList(result) {
  6713. createCommon(result, createList);
  6714. var table = document.createElement('table');
  6715. table.className = 'ke-table';
  6716. table.cellPadding = 0;
  6717. table.cellSpacing = 0;
  6718. table.border = 0;
  6719. bodyDiv.append(table);
  6720. var fileList = result.file_list;
  6721. for (var i = 0, len = fileList.length; i < len; i++) {
  6722. var data = fileList[i], row = K(table.insertRow(i));
  6723. row.mouseover(function(e) {
  6724. K(this).addClass('ke-on');
  6725. })
  6726. .mouseout(function(e) {
  6727. K(this).removeClass('ke-on');
  6728. });
  6729. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6730. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6731. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6732. if (!data.is_dir || data.has_file) {
  6733. row.css('cursor', 'pointer');
  6734. cell0.attr('title', data.filename);
  6735. bindEvent(cell0, result, data, createList);
  6736. } else {
  6737. cell0.attr('title', lang.emptyFolder);
  6738. }
  6739. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6740. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6741. }
  6742. }
  6743. function createView(result) {
  6744. createCommon(result, createView);
  6745. var fileList = result.file_list;
  6746. for (var i = 0, len = fileList.length; i < len; i++) {
  6747. var data = fileList[i],
  6748. div = K('<div class="ke-inline-block ke-item"></div>');
  6749. bodyDiv.append(div);
  6750. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6751. .mouseover(function(e) {
  6752. K(this).addClass('ke-on');
  6753. })
  6754. .mouseout(function(e) {
  6755. K(this).removeClass('ke-on');
  6756. });
  6757. div.append(photoDiv);
  6758. var fileUrl = result.current_url + data.filename,
  6759. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6760. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6761. if (!data.is_dir || data.has_file) {
  6762. photoDiv.css('cursor', 'pointer');
  6763. bindTitle(photoDiv, data);
  6764. bindEvent(photoDiv, result, data, createView);
  6765. } else {
  6766. photoDiv.attr('title', lang.emptyFolder);
  6767. }
  6768. photoDiv.append(img);
  6769. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6770. }
  6771. }
  6772. viewTypeBox.val(viewType);
  6773. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6774. return dialog;
  6775. }
  6776. });
  6777. /*******************************************************************************
  6778. * KindEditor - WYSIWYG HTML Editor for Internet
  6779. * Copyright (C) 2006-2011 kindsoft.net
  6780. *
  6781. * @author Roddy <luolonghao@gmail.com>
  6782. * @site http://www.kindsoft.net/
  6783. * @licence http://www.kindsoft.net/license.php
  6784. *******************************************************************************/
  6785. KindEditor.plugin('flash', function(K) {
  6786. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6787. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6788. allowFileManager = K.undef(self.allowFileManager, false),
  6789. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6790. extraParams = K.undef(self.extraFileUploadParams, {}),
  6791. filePostName = K.undef(self.filePostName, 'imgFile'),
  6792. uploadJson = K.undef(self.uploadJson, self.basePath + 'jsp/upload_json.jsp');
  6793. self.plugin.flash = {
  6794. edit : function() {
  6795. var html = [
  6796. '<div style="padding:20px;">',
  6797. //url
  6798. '<div class="ke-dialog-row">',
  6799. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6800. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6801. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6802. '<span class="ke-button-common ke-button-outer">',
  6803. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6804. '</span>',
  6805. '</div>',
  6806. //width
  6807. '<div class="ke-dialog-row">',
  6808. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6809. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6810. '</div>',
  6811. //height
  6812. '<div class="ke-dialog-row">',
  6813. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6814. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6815. '</div>',
  6816. '</div>'
  6817. ].join('');
  6818. var dialog = self.createDialog({
  6819. name : name,
  6820. width : 450,
  6821. title : self.lang(name),
  6822. body : html,
  6823. yesBtn : {
  6824. name : self.lang('yes'),
  6825. click : function(e) {
  6826. var url = K.trim(urlBox.val()),
  6827. width = widthBox.val(),
  6828. height = heightBox.val();
  6829. if (url == 'http://' || K.invalidUrl(url)) {
  6830. alert(self.lang('invalidUrl'));
  6831. urlBox[0].focus();
  6832. return;
  6833. }
  6834. if (!/^\d*$/.test(width)) {
  6835. alert(self.lang('invalidWidth'));
  6836. widthBox[0].focus();
  6837. return;
  6838. }
  6839. if (!/^\d*$/.test(height)) {
  6840. alert(self.lang('invalidHeight'));
  6841. heightBox[0].focus();
  6842. return;
  6843. }
  6844. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6845. src : url,
  6846. type : K.mediaType('.swf'),
  6847. width : width,
  6848. height : height,
  6849. quality : 'high'
  6850. });
  6851. self.insertHtml(html).hideDialog().focus();
  6852. }
  6853. }
  6854. }),
  6855. div = dialog.div,
  6856. urlBox = K('[name="url"]', div),
  6857. viewServerBtn = K('[name="viewServer"]', div),
  6858. widthBox = K('[name="width"]', div),
  6859. heightBox = K('[name="height"]', div);
  6860. urlBox.val('http://');
  6861. if (allowFlashUpload) {
  6862. var uploadbutton = K.uploadbutton({
  6863. button : K('.ke-upload-button', div)[0],
  6864. fieldName : filePostName,
  6865. extraParams : extraParams,
  6866. url : K.addParam(uploadJson, 'dir=flash'),
  6867. afterUpload : function(data) {
  6868. dialog.hideLoading();
  6869. if (data.error === 0) {
  6870. var url = data.url;
  6871. if (formatUploadUrl) {
  6872. url = K.formatUrl(url, 'absolute');
  6873. }
  6874. urlBox.val(url);
  6875. if (self.afterUpload) {
  6876. self.afterUpload.call(self, url, data, name);
  6877. }
  6878. alert(self.lang('uploadSuccess'));
  6879. } else {
  6880. alert(data.message);
  6881. }
  6882. },
  6883. afterError : function(html) {
  6884. dialog.hideLoading();
  6885. self.errorDialog(html);
  6886. }
  6887. });
  6888. uploadbutton.fileBox.change(function(e) {
  6889. dialog.showLoading(self.lang('uploadLoading'));
  6890. uploadbutton.submit();
  6891. });
  6892. } else {
  6893. K('.ke-upload-button', div).hide();
  6894. }
  6895. if (allowFileManager) {
  6896. viewServerBtn.click(function(e) {
  6897. self.loadPlugin('filemanager', function() {
  6898. self.plugin.filemanagerDialog({
  6899. viewType : 'LIST',
  6900. dirName : 'flash',
  6901. clickFn : function(url, title) {
  6902. if (self.dialogs.length > 1) {
  6903. K('[name="url"]', div).val(url);
  6904. if (self.afterSelectFile) {
  6905. self.afterSelectFile.call(self, url);
  6906. }
  6907. self.hideDialog();
  6908. }
  6909. }
  6910. });
  6911. });
  6912. });
  6913. } else {
  6914. viewServerBtn.hide();
  6915. }
  6916. var img = self.plugin.getSelectedFlash();
  6917. if (img) {
  6918. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  6919. urlBox.val(attrs.src);
  6920. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  6921. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  6922. }
  6923. urlBox[0].focus();
  6924. urlBox[0].select();
  6925. },
  6926. 'delete' : function() {
  6927. self.plugin.getSelectedFlash().remove();
  6928. // [IE] 删除图片后立即点击图片按钮出错
  6929. self.addBookmark();
  6930. }
  6931. };
  6932. self.clickToolbar(name, self.plugin.flash.edit);
  6933. });
  6934. /*******************************************************************************
  6935. * KindEditor - WYSIWYG HTML Editor for Internet
  6936. * Copyright (C) 2006-2011 kindsoft.net
  6937. *
  6938. * @author Roddy <luolonghao@gmail.com>
  6939. * @site http://www.kindsoft.net/
  6940. * @licence http://www.kindsoft.net/license.php
  6941. *******************************************************************************/
  6942. KindEditor.plugin('image', function(K) {
  6943. var self = this, name = 'image',
  6944. allowImageUpload = K.undef(self.allowImageUpload, true),
  6945. allowImageRemote = K.undef(self.allowImageRemote, true),
  6946. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6947. allowFileManager = K.undef(self.allowFileManager, false),
  6948. uploadJson = K.undef(self.uploadJson, self.basePath + 'jsp/upload_json.jsp'),
  6949. imageTabIndex = K.undef(self.imageTabIndex, 0),
  6950. imgPath = self.pluginsPath + 'image/images/',
  6951. extraParams = K.undef(self.extraFileUploadParams, {}),
  6952. filePostName = K.undef(self.filePostName, 'imgFile'),
  6953. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  6954. lang = self.lang(name + '.');
  6955. self.plugin.imageDialog = function(options) {
  6956. var imageUrl = options.imageUrl,
  6957. imageWidth = K.undef(options.imageWidth, ''),
  6958. imageHeight = K.undef(options.imageHeight, ''),
  6959. imageTitle = K.undef(options.imageTitle, ''),
  6960. imageAlign = K.undef(options.imageAlign, ''),
  6961. showRemote = K.undef(options.showRemote, true),
  6962. showLocal = K.undef(options.showLocal, true),
  6963. tabIndex = K.undef(options.tabIndex, 0),
  6964. clickFn = options.clickFn;
  6965. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  6966. var hiddenElements = [];
  6967. for(var k in extraParams){
  6968. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  6969. }
  6970. var html = [
  6971. '<div style="padding:20px;">',
  6972. //tabs
  6973. '<div class="tabs"></div>',
  6974. //remote image - start
  6975. '<div class="tab1" style="display:none;">',
  6976. //url
  6977. '<div class="ke-dialog-row">',
  6978. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  6979. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  6980. '<span class="ke-button-common ke-button-outer">',
  6981. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6982. '</span>',
  6983. '</div>',
  6984. //size
  6985. '<div class="ke-dialog-row">',
  6986. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  6987. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  6988. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  6989. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  6990. '</div>',
  6991. //align
  6992. '<div class="ke-dialog-row">',
  6993. '<label style="width:60px;">' + lang.align + '</label>',
  6994. '<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="" />',
  6995. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  6996. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  6997. '</div>',
  6998. //title
  6999. '<div class="ke-dialog-row">',
  7000. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7001. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7002. '</div>',
  7003. '</div>',
  7004. //remote image - end
  7005. //local upload - start
  7006. '<div class="tab2" style="display:none;">',
  7007. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7008. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7009. //file
  7010. '<div class="ke-dialog-row">',
  7011. hiddenElements.join(''),
  7012. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7013. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7014. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7015. '</div>',
  7016. '</form>',
  7017. '</div>',
  7018. //local upload - end
  7019. '</div>'
  7020. ].join('');
  7021. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7022. dialogHeight = showLocal && showRemote ? 300 : 250;
  7023. var dialog = self.createDialog({
  7024. name : name,
  7025. width : dialogWidth,
  7026. height : dialogHeight,
  7027. title : self.lang(name),
  7028. body : html,
  7029. yesBtn : {
  7030. name : self.lang('yes'),
  7031. click : function(e) {
  7032. // Bugfix: http://code.google.com/p/kindeditor/issues/detail?id=319
  7033. if (dialog.isLoading) {
  7034. return;
  7035. }
  7036. // insert local image
  7037. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7038. if (uploadbutton.fileBox.val() == '') {
  7039. alert(self.lang('pleaseSelectFile'));
  7040. return;
  7041. }
  7042. dialog.showLoading(self.lang('uploadLoading'));
  7043. uploadbutton.submit();
  7044. localUrlBox.val('');
  7045. return;
  7046. }
  7047. // insert remote image
  7048. var url = K.trim(urlBox.val()),
  7049. width = widthBox.val(),
  7050. height = heightBox.val(),
  7051. title = titleBox.val(),
  7052. align = '';
  7053. alignBox.each(function() {
  7054. if (this.checked) {
  7055. align = this.value;
  7056. return false;
  7057. }
  7058. });
  7059. if (url == 'http://' || K.invalidUrl(url)) {
  7060. alert(self.lang('invalidUrl'));
  7061. urlBox[0].focus();
  7062. return;
  7063. }
  7064. if (!/^\d*$/.test(width)) {
  7065. alert(self.lang('invalidWidth'));
  7066. widthBox[0].focus();
  7067. return;
  7068. }
  7069. if (!/^\d*$/.test(height)) {
  7070. alert(self.lang('invalidHeight'));
  7071. heightBox[0].focus();
  7072. return;
  7073. }
  7074. clickFn.call(self, url, title, width, height, 0, align);
  7075. }
  7076. },
  7077. beforeRemove : function() {
  7078. viewServerBtn.unbind();
  7079. widthBox.unbind();
  7080. heightBox.unbind();
  7081. refreshBtn.unbind();
  7082. }
  7083. }),
  7084. div = dialog.div;
  7085. var urlBox = K('[name="url"]', div),
  7086. localUrlBox = K('[name="localUrl"]', div),
  7087. viewServerBtn = K('[name="viewServer"]', div),
  7088. widthBox = K('.tab1 [name="width"]', div),
  7089. heightBox = K('.tab1 [name="height"]', div),
  7090. refreshBtn = K('.ke-refresh-btn', div),
  7091. titleBox = K('.tab1 [name="title"]', div),
  7092. alignBox = K('.tab1 [name="align"]', div);
  7093. var tabs;
  7094. if (showRemote && showLocal) {
  7095. tabs = K.tabs({
  7096. src : K('.tabs', div),
  7097. afterSelect : function(i) {}
  7098. });
  7099. tabs.add({
  7100. title : lang.remoteImage,
  7101. panel : K('.tab1', div)
  7102. });
  7103. tabs.add({
  7104. title : lang.localImage,
  7105. panel : K('.tab2', div)
  7106. });
  7107. tabs.select(tabIndex);
  7108. } else if (showRemote) {
  7109. K('.tab1', div).show();
  7110. } else if (showLocal) {
  7111. K('.tab2', div).show();
  7112. }
  7113. var uploadbutton = K.uploadbutton({
  7114. button : K('.ke-upload-button', div)[0],
  7115. fieldName : filePostName,
  7116. form : K('.ke-form', div),
  7117. target : target,
  7118. width: 60,
  7119. afterUpload : function(data) {
  7120. dialog.hideLoading();
  7121. if (data.error === 0) {
  7122. var url = data.url;
  7123. if (formatUploadUrl) {
  7124. url = K.formatUrl(url, 'absolute');
  7125. }
  7126. if (self.afterUpload) {
  7127. self.afterUpload.call(self, url, data, name);
  7128. }
  7129. if (!fillDescAfterUploadImage) {
  7130. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7131. } else {
  7132. K(".ke-dialog-row #remoteUrl", div).val(url);
  7133. K(".ke-tabs-li", div)[0].click();
  7134. K(".ke-refresh-btn", div).click();
  7135. }
  7136. } else {
  7137. }
  7138. },
  7139. afterError : function(html) {
  7140. dialog.hideLoading();
  7141. self.errorDialog(html);
  7142. }
  7143. });
  7144. uploadbutton.fileBox.change(function(e) {
  7145. localUrlBox.val(uploadbutton.fileBox.val());
  7146. });
  7147. if (allowFileManager) {
  7148. viewServerBtn.click(function(e) {
  7149. self.loadPlugin('filemanager', function() {
  7150. self.plugin.filemanagerDialog({
  7151. viewType : 'VIEW',
  7152. dirName : 'image',
  7153. clickFn : function(url, title) {
  7154. if (self.dialogs.length > 1) {
  7155. K('[name="url"]', div).val(url);
  7156. if (self.afterSelectFile) {
  7157. self.afterSelectFile.call(self, url);
  7158. }
  7159. self.hideDialog();
  7160. }
  7161. }
  7162. });
  7163. });
  7164. });
  7165. } else {
  7166. viewServerBtn.hide();
  7167. }
  7168. var originalWidth = 0, originalHeight = 0;
  7169. function setSize(width, height) {
  7170. widthBox.val(width);
  7171. heightBox.val(height);
  7172. originalWidth = width;
  7173. originalHeight = height;
  7174. }
  7175. refreshBtn.click(function(e) {
  7176. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7177. position : 'absolute',
  7178. visibility : 'hidden',
  7179. top : 0,
  7180. left : '-1000px'
  7181. });
  7182. tempImg.bind('load', function() {
  7183. setSize(tempImg.width(), tempImg.height());
  7184. tempImg.remove();
  7185. });
  7186. K(document.body).append(tempImg);
  7187. });
  7188. widthBox.change(function(e) {
  7189. if (originalWidth > 0) {
  7190. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7191. }
  7192. });
  7193. heightBox.change(function(e) {
  7194. if (originalHeight > 0) {
  7195. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7196. }
  7197. });
  7198. urlBox.val(options.imageUrl);
  7199. setSize(options.imageWidth, options.imageHeight);
  7200. titleBox.val(options.imageTitle);
  7201. alignBox.each(function() {
  7202. if (this.value === options.imageAlign) {
  7203. this.checked = true;
  7204. return false;
  7205. }
  7206. });
  7207. if (showRemote && tabIndex === 0) {
  7208. urlBox[0].focus();
  7209. urlBox[0].select();
  7210. }
  7211. return dialog;
  7212. };
  7213. self.plugin.image = {
  7214. edit : function() {
  7215. var img = self.plugin.getSelectedImage();
  7216. self.plugin.imageDialog({
  7217. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7218. imageWidth : img ? img.width() : '',
  7219. imageHeight : img ? img.height() : '',
  7220. imageTitle : img ? img.attr('title') : '',
  7221. imageAlign : img ? img.attr('align') : '',
  7222. showRemote : allowImageRemote,
  7223. showLocal : allowImageUpload,
  7224. tabIndex: img ? 0 : imageTabIndex,
  7225. clickFn : function(url, title, width, height, border, align) {
  7226. if (img) {
  7227. img.attr('src', url);
  7228. img.attr('data-ke-src', url);
  7229. img.attr('width', width);
  7230. img.attr('height', height);
  7231. img.attr('title', title);
  7232. img.attr('align', align);
  7233. img.attr('alt', title);
  7234. } else {
  7235. self.exec('insertimage', url, title, width, height, border, align);
  7236. }
  7237. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  7238. setTimeout(function() {
  7239. self.hideDialog().focus();
  7240. }, 0);
  7241. }
  7242. });
  7243. },
  7244. 'delete' : function() {
  7245. var target = self.plugin.getSelectedImage();
  7246. if (target.parent().name == 'a') {
  7247. target = target.parent();
  7248. }
  7249. target.remove();
  7250. // [IE] 删除图片后立即点击图片按钮出错
  7251. self.addBookmark();
  7252. }
  7253. };
  7254. self.clickToolbar(name, self.plugin.image.edit);
  7255. });
  7256. /*******************************************************************************
  7257. * KindEditor - WYSIWYG HTML Editor for Internet
  7258. * Copyright (C) 2006-2011 kindsoft.net
  7259. *
  7260. * @author Roddy <luolonghao@gmail.com>
  7261. * @site http://www.kindsoft.net/
  7262. * @licence http://www.kindsoft.net/license.php
  7263. *******************************************************************************/
  7264. KindEditor.plugin('insertfile', function(K) {
  7265. var self = this, name = 'insertfile',
  7266. allowFileUpload = K.undef(self.allowFileUpload, true),
  7267. allowFileManager = K.undef(self.allowFileManager, false),
  7268. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7269. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7270. extraParams = K.undef(self.extraFileUploadParams, {}),
  7271. filePostName = K.undef(self.filePostName, 'imgFile'),
  7272. lang = self.lang(name + '.');
  7273. self.plugin.fileDialog = function(options) {
  7274. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7275. fileTitle = K.undef(options.fileTitle, ''),
  7276. clickFn = options.clickFn;
  7277. var html = [
  7278. '<div style="padding:20px;">',
  7279. '<div class="ke-dialog-row">',
  7280. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7281. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7282. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7283. '<span class="ke-button-common ke-button-outer">',
  7284. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7285. '</span>',
  7286. '</div>',
  7287. //title
  7288. '<div class="ke-dialog-row">',
  7289. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7290. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7291. '</div>',
  7292. //form end
  7293. '</form>',
  7294. '</div>'
  7295. ].join('');
  7296. var dialog = self.createDialog({
  7297. name : name,
  7298. width : 450,
  7299. title : self.lang(name),
  7300. body : html,
  7301. yesBtn : {
  7302. name : self.lang('yes'),
  7303. click : function(e) {
  7304. var url = K.trim(urlBox.val()),
  7305. title = titleBox.val();
  7306. if (url == 'http://' || K.invalidUrl(url)) {
  7307. alert(self.lang('invalidUrl'));
  7308. urlBox[0].focus();
  7309. return;
  7310. }
  7311. if (K.trim(title) === '') {
  7312. title = url;
  7313. }
  7314. clickFn.call(self, url, title);
  7315. }
  7316. }
  7317. }),
  7318. div = dialog.div;
  7319. var urlBox = K('[name="url"]', div),
  7320. viewServerBtn = K('[name="viewServer"]', div),
  7321. titleBox = K('[name="title"]', div);
  7322. if (allowFileUpload) {
  7323. var uploadbutton = K.uploadbutton({
  7324. button : K('.ke-upload-button', div)[0],
  7325. fieldName : filePostName,
  7326. url : K.addParam(uploadJson, 'dir=file'),
  7327. extraParams : extraParams,
  7328. afterUpload : function(data) {
  7329. dialog.hideLoading();
  7330. if (data.error === 0) {
  7331. var url = data.url;
  7332. if (formatUploadUrl) {
  7333. url = K.formatUrl(url, 'absolute');
  7334. }
  7335. urlBox.val(url);
  7336. if (self.afterUpload) {
  7337. self.afterUpload.call(self, url, data, name);
  7338. }
  7339. alert(self.lang('uploadSuccess'));
  7340. } else {
  7341. alert(data.message);
  7342. }
  7343. },
  7344. afterError : function(html) {
  7345. dialog.hideLoading();
  7346. self.errorDialog(html);
  7347. }
  7348. });
  7349. uploadbutton.fileBox.change(function(e) {
  7350. dialog.showLoading(self.lang('uploadLoading'));
  7351. uploadbutton.submit();
  7352. });
  7353. } else {
  7354. K('.ke-upload-button', div).hide();
  7355. }
  7356. if (allowFileManager) {
  7357. viewServerBtn.click(function(e) {
  7358. self.loadPlugin('filemanager', function() {
  7359. self.plugin.filemanagerDialog({
  7360. viewType : 'LIST',
  7361. dirName : 'file',
  7362. clickFn : function(url, title) {
  7363. if (self.dialogs.length > 1) {
  7364. K('[name="url"]', div).val(url);
  7365. if (self.afterSelectFile) {
  7366. self.afterSelectFile.call(self, url);
  7367. }
  7368. self.hideDialog();
  7369. }
  7370. }
  7371. });
  7372. });
  7373. });
  7374. } else {
  7375. viewServerBtn.hide();
  7376. }
  7377. urlBox.val(fileUrl);
  7378. titleBox.val(fileTitle);
  7379. urlBox[0].focus();
  7380. urlBox[0].select();
  7381. };
  7382. self.clickToolbar(name, function() {
  7383. self.plugin.fileDialog({
  7384. clickFn : function(url, title) {
  7385. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7386. self.insertHtml(html).hideDialog().focus();
  7387. }
  7388. });
  7389. });
  7390. });
  7391. /*******************************************************************************
  7392. * KindEditor - WYSIWYG HTML Editor for Internet
  7393. * Copyright (C) 2006-2011 kindsoft.net
  7394. *
  7395. * @author Roddy <luolonghao@gmail.com>
  7396. * @site http://www.kindsoft.net/
  7397. * @licence http://www.kindsoft.net/license.php
  7398. *******************************************************************************/
  7399. KindEditor.plugin('lineheight', function(K) {
  7400. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7401. self.clickToolbar(name, function() {
  7402. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7403. if (commonNode) {
  7404. curVal = commonNode.css('line-height');
  7405. }
  7406. var menu = self.createMenu({
  7407. name : name,
  7408. width : 150
  7409. });
  7410. K.each(lang.lineHeight, function(i, row) {
  7411. K.each(row, function(key, val) {
  7412. menu.addItem({
  7413. title : val,
  7414. checked : curVal === key,
  7415. click : function() {
  7416. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7417. span : '.line-height=' + key
  7418. });
  7419. self.updateState();
  7420. self.addBookmark();
  7421. self.hideMenu();
  7422. }
  7423. });
  7424. });
  7425. });
  7426. });
  7427. });
  7428. /*******************************************************************************
  7429. * KindEditor - WYSIWYG HTML Editor for Internet
  7430. * Copyright (C) 2006-2011 kindsoft.net
  7431. *
  7432. * @author Roddy <luolonghao@gmail.com>
  7433. * @site http://www.kindsoft.net/
  7434. * @licence http://www.kindsoft.net/license.php
  7435. *******************************************************************************/
  7436. KindEditor.plugin('link', function(K) {
  7437. var self = this, name = 'link';
  7438. self.plugin.link = {
  7439. edit : function() {
  7440. var lang = self.lang(name + '.'),
  7441. html = '<div style="padding:20px;">' +
  7442. //url
  7443. '<div class="ke-dialog-row">' +
  7444. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7445. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7446. //type
  7447. '<div class="ke-dialog-row"">' +
  7448. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7449. '<select id="keType" name="type"></select>' +
  7450. '</div>' +
  7451. '</div>',
  7452. dialog = self.createDialog({
  7453. name : name,
  7454. width : 450,
  7455. title : self.lang(name),
  7456. body : html,
  7457. yesBtn : {
  7458. name : self.lang('yes'),
  7459. click : function(e) {
  7460. var url = K.trim(urlBox.val());
  7461. if (url == 'http://' || K.invalidUrl(url)) {
  7462. alert(self.lang('invalidUrl'));
  7463. urlBox[0].focus();
  7464. return;
  7465. }
  7466. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7467. }
  7468. }
  7469. }),
  7470. div = dialog.div,
  7471. urlBox = K('input[name="url"]', div),
  7472. typeBox = K('select[name="type"]', div);
  7473. urlBox.val('http://');
  7474. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7475. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7476. self.cmd.selection();
  7477. var a = self.plugin.getSelectedLink();
  7478. if (a) {
  7479. self.cmd.range.selectNode(a[0]);
  7480. self.cmd.select();
  7481. urlBox.val(a.attr('data-ke-src'));
  7482. typeBox.val(a.attr('target'));
  7483. }
  7484. urlBox[0].focus();
  7485. urlBox[0].select();
  7486. },
  7487. 'delete' : function() {
  7488. self.exec('unlink', null);
  7489. }
  7490. };
  7491. self.clickToolbar(name, self.plugin.link.edit);
  7492. });
  7493. /*******************************************************************************
  7494. * KindEditor - WYSIWYG HTML Editor for Internet
  7495. * Copyright (C) 2006-2011 kindsoft.net
  7496. *
  7497. * @author Roddy <luolonghao@gmail.com>
  7498. * @site http://www.kindsoft.net/
  7499. * @licence http://www.kindsoft.net/license.php
  7500. *******************************************************************************/
  7501. // Google Maps: http://code.google.com/apis/maps/index.html
  7502. KindEditor.plugin('map', function(K) {
  7503. var self = this, name = 'map', lang = self.lang(name + '.');
  7504. self.clickToolbar(name, function() {
  7505. var html = ['<div style="padding:10px 20px;">',
  7506. '<div class="ke-dialog-row">',
  7507. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  7508. '<span class="ke-button-common ke-button-outer">',
  7509. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  7510. '</span>',
  7511. '</div>',
  7512. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  7513. '</div>'].join('');
  7514. var dialog = self.createDialog({
  7515. name : name,
  7516. width : 600,
  7517. title : self.lang(name),
  7518. body : html,
  7519. yesBtn : {
  7520. name : self.lang('yes'),
  7521. click : function(e) {
  7522. var geocoder = win.geocoder,
  7523. map = win.map,
  7524. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  7525. zoom = map.getZoom(),
  7526. maptype = map.getMapTypeId(),
  7527. url = 'http://maps.googleapis.com/maps/api/staticmap';
  7528. url += '?center=' + encodeURIComponent(center);
  7529. url += '&zoom=' + encodeURIComponent(zoom);
  7530. url += '&size=558x360';
  7531. url += '&maptype=' + encodeURIComponent(maptype);
  7532. url += '&markers=' + encodeURIComponent(center);
  7533. url += '&language=' + self.langType;
  7534. url += '&sensor=false';
  7535. self.exec('insertimage', url).hideDialog().focus();
  7536. }
  7537. },
  7538. beforeRemove : function() {
  7539. searchBtn.remove();
  7540. if (doc) {
  7541. doc.write('');
  7542. }
  7543. iframe.remove();
  7544. }
  7545. });
  7546. var div = dialog.div,
  7547. addressBox = K('[name="address"]', div),
  7548. searchBtn = K('[name="searchBtn"]', div),
  7549. win, doc;
  7550. var iframeHtml = ['<!doctype html><html><head>',
  7551. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  7552. '<style>',
  7553. ' html { height: 100% }',
  7554. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  7555. ' #map_canvas { height: 100% }',
  7556. '</style>',
  7557. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  7558. '<script>',
  7559. 'var map, geocoder;',
  7560. 'function initialize() {',
  7561. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  7562. ' var options = {',
  7563. ' zoom: 11,',
  7564. ' center: latlng,',
  7565. ' disableDefaultUI: true,',
  7566. ' panControl: true,',
  7567. ' zoomControl: true,',
  7568. ' mapTypeControl: true,',
  7569. ' scaleControl: true,',
  7570. ' streetViewControl: false,',
  7571. ' overviewMapControl: true,',
  7572. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  7573. ' };',
  7574. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  7575. ' geocoder = new google.maps.Geocoder();',
  7576. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  7577. ' if (status == google.maps.GeocoderStatus.OK) {',
  7578. ' if (results[3]) {',
  7579. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  7580. ' }',
  7581. ' }',
  7582. ' });',
  7583. '}',
  7584. 'function search(address) {',
  7585. ' if (!map) return;',
  7586. ' geocoder.geocode({address : address}, function(results, status) {',
  7587. ' if (status == google.maps.GeocoderStatus.OK) {',
  7588. ' map.setZoom(11);',
  7589. ' map.setCenter(results[0].geometry.location);',
  7590. ' var marker = new google.maps.Marker({',
  7591. ' map: map,',
  7592. ' position: results[0].geometry.location',
  7593. ' });',
  7594. ' } else {',
  7595. ' alert("Invalid address: " + address);',
  7596. ' }',
  7597. ' });',
  7598. '}',
  7599. '</script>',
  7600. '</head>',
  7601. '<body onload="initialize();">',
  7602. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  7603. '</body></html>'].join('\n');
  7604. // TODO:用doc.write(iframeHtml)方式加载时,在IE6上第一次加载报错,暂时使用src方式
  7605. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  7606. function ready() {
  7607. win = iframe[0].contentWindow;
  7608. doc = K.iframeDoc(iframe);
  7609. //doc.open();
  7610. //doc.write(iframeHtml);
  7611. //doc.close();
  7612. }
  7613. iframe.bind('load', function() {
  7614. iframe.unbind('load');
  7615. if (K.IE) {
  7616. ready();
  7617. } else {
  7618. setTimeout(ready, 0);
  7619. }
  7620. });
  7621. K('.ke-map', div).replaceWith(iframe);
  7622. // search map
  7623. searchBtn.click(function() {
  7624. win.search(addressBox.val());
  7625. });
  7626. });
  7627. });
  7628. /*******************************************************************************
  7629. * KindEditor - WYSIWYG HTML Editor for Internet
  7630. * Copyright (C) 2006-2011 kindsoft.net
  7631. *
  7632. * @author Roddy <luolonghao@gmail.com>
  7633. * @site http://www.kindsoft.net/
  7634. * @licence http://www.kindsoft.net/license.php
  7635. *******************************************************************************/
  7636. KindEditor.plugin('media', function(K) {
  7637. var self = this, name = 'media', lang = self.lang(name + '.'),
  7638. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7639. allowFileManager = K.undef(self.allowFileManager, false),
  7640. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7641. extraParams = K.undef(self.extraFileUploadParams, {}),
  7642. filePostName = K.undef(self.filePostName, 'imgFile'),
  7643. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7644. self.plugin.media = {
  7645. edit : function() {
  7646. var html = [
  7647. '<div style="padding:20px;">',
  7648. //url
  7649. '<div class="ke-dialog-row">',
  7650. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7651. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7652. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7653. '<span class="ke-button-common ke-button-outer">',
  7654. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7655. '</span>',
  7656. '</div>',
  7657. //width
  7658. '<div class="ke-dialog-row">',
  7659. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7660. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7661. '</div>',
  7662. //height
  7663. '<div class="ke-dialog-row">',
  7664. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7665. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7666. '</div>',
  7667. //autostart
  7668. '<div class="ke-dialog-row">',
  7669. '<label for="keAutostart">' + lang.autostart + '</label>',
  7670. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7671. '</div>',
  7672. '</div>'
  7673. ].join('');
  7674. var dialog = self.createDialog({
  7675. name : name,
  7676. width : 450,
  7677. height : 230,
  7678. title : self.lang(name),
  7679. body : html,
  7680. yesBtn : {
  7681. name : self.lang('yes'),
  7682. click : function(e) {
  7683. var url = K.trim(urlBox.val()),
  7684. width = widthBox.val(),
  7685. height = heightBox.val();
  7686. if (url == 'http://' || K.invalidUrl(url)) {
  7687. alert(self.lang('invalidUrl'));
  7688. urlBox[0].focus();
  7689. return;
  7690. }
  7691. if (!/^\d*$/.test(width)) {
  7692. alert(self.lang('invalidWidth'));
  7693. widthBox[0].focus();
  7694. return;
  7695. }
  7696. if (!/^\d*$/.test(height)) {
  7697. alert(self.lang('invalidHeight'));
  7698. heightBox[0].focus();
  7699. return;
  7700. }
  7701. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7702. src : url,
  7703. type : K.mediaType(url),
  7704. width : width,
  7705. height : height,
  7706. autostart : autostartBox[0].checked ? 'true' : 'false',
  7707. loop : 'true'
  7708. });
  7709. self.insertHtml(html).hideDialog().focus();
  7710. }
  7711. }
  7712. }),
  7713. div = dialog.div,
  7714. urlBox = K('[name="url"]', div),
  7715. viewServerBtn = K('[name="viewServer"]', div),
  7716. widthBox = K('[name="width"]', div),
  7717. heightBox = K('[name="height"]', div),
  7718. autostartBox = K('[name="autostart"]', div);
  7719. urlBox.val('http://');
  7720. if (allowMediaUpload) {
  7721. var uploadbutton = K.uploadbutton({
  7722. button : K('.ke-upload-button', div)[0],
  7723. fieldName : filePostName,
  7724. extraParams : extraParams,
  7725. url : K.addParam(uploadJson, 'dir=media'),
  7726. afterUpload : function(data) {
  7727. dialog.hideLoading();
  7728. if (data.error === 0) {
  7729. var url = data.url;
  7730. if (formatUploadUrl) {
  7731. url = K.formatUrl(url, 'absolute');
  7732. }
  7733. urlBox.val(url);
  7734. if (self.afterUpload) {
  7735. self.afterUpload.call(self, url, data, name);
  7736. }
  7737. alert(self.lang('uploadSuccess'));
  7738. } else {
  7739. alert(data.message);
  7740. }
  7741. },
  7742. afterError : function(html) {
  7743. dialog.hideLoading();
  7744. self.errorDialog(html);
  7745. }
  7746. });
  7747. uploadbutton.fileBox.change(function(e) {
  7748. dialog.showLoading(self.lang('uploadLoading'));
  7749. uploadbutton.submit();
  7750. });
  7751. } else {
  7752. K('.ke-upload-button', div).hide();
  7753. }
  7754. if (allowFileManager) {
  7755. viewServerBtn.click(function(e) {
  7756. self.loadPlugin('filemanager', function() {
  7757. self.plugin.filemanagerDialog({
  7758. viewType : 'LIST',
  7759. dirName : 'media',
  7760. clickFn : function(url, title) {
  7761. if (self.dialogs.length > 1) {
  7762. K('[name="url"]', div).val(url);
  7763. if (self.afterSelectFile) {
  7764. self.afterSelectFile.call(self, url);
  7765. }
  7766. self.hideDialog();
  7767. }
  7768. }
  7769. });
  7770. });
  7771. });
  7772. } else {
  7773. viewServerBtn.hide();
  7774. }
  7775. var img = self.plugin.getSelectedMedia();
  7776. if (img) {
  7777. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7778. urlBox.val(attrs.src);
  7779. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7780. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7781. autostartBox[0].checked = (attrs.autostart === 'true');
  7782. }
  7783. urlBox[0].focus();
  7784. urlBox[0].select();
  7785. },
  7786. 'delete' : function() {
  7787. self.plugin.getSelectedMedia().remove();
  7788. // [IE] 删除图片后立即点击图片按钮出错
  7789. self.addBookmark();
  7790. }
  7791. };
  7792. self.clickToolbar(name, self.plugin.media.edit);
  7793. });
  7794. /*******************************************************************************
  7795. * KindEditor - WYSIWYG HTML Editor for Internet
  7796. * Copyright (C) 2006-2011 kindsoft.net
  7797. *
  7798. * @author Roddy <luolonghao@gmail.com>
  7799. * @site http://www.kindsoft.net/
  7800. * @licence http://www.kindsoft.net/license.php
  7801. *******************************************************************************/
  7802. (function(K) {
  7803. function KSWFUpload(options) {
  7804. this.init(options);
  7805. }
  7806. K.extend(KSWFUpload, {
  7807. init : function(options) {
  7808. var self = this;
  7809. options.afterError = options.afterError || function(str) {
  7810. alert(str);
  7811. };
  7812. self.options = options;
  7813. self.progressbars = {};
  7814. // template
  7815. self.div = K(options.container).html([
  7816. '<div class="ke-swfupload">',
  7817. '<div class="ke-swfupload-top">',
  7818. '<div class="ke-inline-block ke-swfupload-button">',
  7819. '<input type="button" value="Browse" />',
  7820. '</div>',
  7821. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7822. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7823. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7824. '</span>',
  7825. '</div>',
  7826. '<div class="ke-swfupload-body"></div>',
  7827. '</div>'
  7828. ].join(''));
  7829. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7830. function showError(itemDiv, msg) {
  7831. K('.ke-status > div', itemDiv).hide();
  7832. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7833. }
  7834. var settings = {
  7835. debug : false,
  7836. upload_url : options.uploadUrl,
  7837. flash_url : options.flashUrl,
  7838. file_post_name : options.filePostName,
  7839. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7840. button_image_url: options.buttonImageUrl,
  7841. button_width: options.buttonWidth,
  7842. button_height: options.buttonHeight,
  7843. button_cursor : SWFUpload.CURSOR.HAND,
  7844. file_types : options.fileTypes,
  7845. file_types_description : options.fileTypesDesc,
  7846. file_upload_limit : options.fileUploadLimit,
  7847. file_size_limit : options.fileSizeLimit,
  7848. post_params : options.postParams,
  7849. file_queued_handler : function(file) {
  7850. file.url = self.options.fileIconUrl;
  7851. self.appendFile(file);
  7852. },
  7853. file_queue_error_handler : function(file, errorCode, message) {
  7854. var errorName = '';
  7855. switch (errorCode) {
  7856. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7857. errorName = options.queueLimitExceeded;
  7858. break;
  7859. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7860. errorName = options.fileExceedsSizeLimit;
  7861. break;
  7862. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7863. errorName = options.zeroByteFile;
  7864. break;
  7865. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7866. errorName = options.invalidFiletype;
  7867. break;
  7868. default:
  7869. errorName = options.unknownError;
  7870. break;
  7871. }
  7872. K.DEBUG && alert(errorName);
  7873. },
  7874. upload_start_handler : function(file) {
  7875. var self = this;
  7876. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7877. K('.ke-status > div', itemDiv).hide();
  7878. K('.ke-progressbar', itemDiv).show();
  7879. },
  7880. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7881. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7882. var progressbar = self.progressbars[file.id];
  7883. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7884. progressbar.percent.html(percent + '%');
  7885. },
  7886. upload_error_handler : function(file, errorCode, message) {
  7887. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7888. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7889. showError(itemDiv, self.options.errorMessage);
  7890. }
  7891. },
  7892. upload_success_handler : function(file, serverData) {
  7893. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7894. var data = {};
  7895. try {
  7896. data = K.json(serverData);
  7897. } catch (e) {
  7898. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7899. }
  7900. if (data.error !== 0) {
  7901. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7902. return;
  7903. }
  7904. file.url = data.url;
  7905. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7906. K('.ke-status > div', itemDiv).hide();
  7907. }
  7908. };
  7909. self.swfu = new SWFUpload(settings);
  7910. K('.ke-swfupload-startupload input', self.div).click(function() {
  7911. self.swfu.startUpload();
  7912. });
  7913. },
  7914. getUrlList : function() {
  7915. var list = [];
  7916. K('.ke-img', self.bodyDiv).each(function() {
  7917. var img = K(this);
  7918. var status = img.attr('data-status');
  7919. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7920. list.push(img.data('data'));
  7921. }
  7922. });
  7923. return list;
  7924. },
  7925. removeFile : function(fileId) {
  7926. var self = this;
  7927. self.swfu.cancelUpload(fileId);
  7928. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7929. K('.ke-photo', itemDiv).unbind();
  7930. K('.ke-delete', itemDiv).unbind();
  7931. itemDiv.remove();
  7932. },
  7933. removeFiles : function() {
  7934. var self = this;
  7935. K('.ke-item', self.bodyDiv).each(function() {
  7936. self.removeFile(K(this).attr('data-id'));
  7937. });
  7938. },
  7939. appendFile : function(file) {
  7940. var self = this;
  7941. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7942. self.bodyDiv.append(itemDiv);
  7943. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7944. .mouseover(function(e) {
  7945. K(this).addClass('ke-on');
  7946. })
  7947. .mouseout(function(e) {
  7948. K(this).removeClass('ke-on');
  7949. });
  7950. itemDiv.append(photoDiv);
  7951. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7952. photoDiv.append(img);
  7953. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  7954. self.removeFile(file.id);
  7955. });
  7956. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7957. // progressbar
  7958. K(['<div class="ke-progressbar">',
  7959. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7960. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7961. // message
  7962. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7963. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7964. self.progressbars[file.id] = {
  7965. bar : K('.ke-progressbar-bar-inner', photoDiv),
  7966. percent : K('.ke-progressbar-percent', photoDiv)
  7967. };
  7968. },
  7969. remove : function() {
  7970. this.removeFiles();
  7971. this.swfu.destroy();
  7972. this.div.html('');
  7973. }
  7974. });
  7975. K.swfupload = function(element, options) {
  7976. return new KSWFUpload(element, options);
  7977. };
  7978. })(KindEditor);
  7979. KindEditor.plugin('multiimage', function(K) {
  7980. var self = this, name = 'multiimage',
  7981. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7982. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7983. imgPath = self.pluginsPath + 'multiimage/images/',
  7984. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  7985. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  7986. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  7987. filePostName = K.undef(self.filePostName, 'imgFile'),
  7988. lang = self.lang(name + '.');
  7989. self.plugin.multiImageDialog = function(options) {
  7990. var clickFn = options.clickFn,
  7991. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  7992. var html = [
  7993. '<div style="padding:20px;">',
  7994. '<div class="swfupload">',
  7995. '</div>',
  7996. '</div>'
  7997. ].join('');
  7998. var dialog = self.createDialog({
  7999. name : name,
  8000. width : 650,
  8001. height : 510,
  8002. title : self.lang(name),
  8003. body : html,
  8004. previewBtn : {
  8005. name : lang.insertAll,
  8006. click : function(e) {
  8007. clickFn.call(self, swfupload.getUrlList());
  8008. }
  8009. },
  8010. yesBtn : {
  8011. name : lang.clearAll,
  8012. click : function(e) {
  8013. swfupload.removeFiles();
  8014. }
  8015. },
  8016. beforeRemove : function() {
  8017. // IE9 bugfix: https://github.com/kindsoft/kindeditor/issues/72
  8018. if (!K.IE || K.V <= 8) {
  8019. swfupload.remove();
  8020. }
  8021. }
  8022. }),
  8023. div = dialog.div;
  8024. var swfupload = K.swfupload({
  8025. container : K('.swfupload', div),
  8026. buttonImageUrl : imgPath + (self.langType == 'zh_CN' ? 'select-files-zh_CN.png' : 'select-files-en.png'),
  8027. buttonWidth : self.langType == 'zh_CN' ? 72 : 88,
  8028. buttonHeight : 23,
  8029. fileIconUrl : imgPath + 'image.png',
  8030. uploadDesc : uploadDesc,
  8031. startButtonValue : lang.startUpload,
  8032. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8033. flashUrl : imgPath + 'swfupload.swf',
  8034. filePostName : filePostName,
  8035. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8036. fileTypesDesc : 'Image Files',
  8037. fileUploadLimit : imageUploadLimit,
  8038. fileSizeLimit : imageSizeLimit,
  8039. postParams : K.undef(self.extraFileUploadParams, {}),
  8040. queueLimitExceeded : lang.queueLimitExceeded,
  8041. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8042. zeroByteFile : lang.zeroByteFile,
  8043. invalidFiletype : lang.invalidFiletype,
  8044. unknownError : lang.unknownError,
  8045. pendingMessage : lang.pending,
  8046. errorMessage : lang.uploadError,
  8047. afterError : function(html) {
  8048. self.errorDialog(html);
  8049. }
  8050. });
  8051. return dialog;
  8052. };
  8053. self.clickToolbar(name, function() {
  8054. self.plugin.multiImageDialog({
  8055. clickFn : function (urlList) {
  8056. if (urlList.length === 0) {
  8057. return;
  8058. }
  8059. K.each(urlList, function(i, data) {
  8060. if (self.afterUpload) {
  8061. self.afterUpload.call(self, data.url, data, 'multiimage');
  8062. }
  8063. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8064. });
  8065. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  8066. setTimeout(function() {
  8067. self.hideDialog().focus();
  8068. }, 0);
  8069. }
  8070. });
  8071. });
  8072. });
  8073. /**
  8074. * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
  8075. *
  8076. * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
  8077. *
  8078. * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz閚 and Mammon Media and is released under the MIT License:
  8079. * http://www.opensource.org/licenses/mit-license.php
  8080. *
  8081. * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
  8082. * http://www.opensource.org/licenses/mit-license.php
  8083. *
  8084. */
  8085. /* ******************* */
  8086. /* Constructor & Init */
  8087. /* ******************* */
  8088. (function() {
  8089. window.SWFUpload = function (settings) {
  8090. this.initSWFUpload(settings);
  8091. };
  8092. SWFUpload.prototype.initSWFUpload = function (settings) {
  8093. try {
  8094. this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
  8095. this.settings = settings;
  8096. this.eventQueue = [];
  8097. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8098. this.movieElement = null;
  8099. // Setup global control tracking
  8100. SWFUpload.instances[this.movieName] = this;
  8101. // Load the settings. Load the Flash movie.
  8102. this.initSettings();
  8103. this.loadFlash();
  8104. this.displayDebugInfo();
  8105. } catch (ex) {
  8106. delete SWFUpload.instances[this.movieName];
  8107. throw ex;
  8108. }
  8109. };
  8110. /* *************** */
  8111. /* Static Members */
  8112. /* *************** */
  8113. SWFUpload.instances = {};
  8114. SWFUpload.movieCount = 0;
  8115. SWFUpload.version = "2.2.0 2009-03-25";
  8116. SWFUpload.QUEUE_ERROR = {
  8117. QUEUE_LIMIT_EXCEEDED : -100,
  8118. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8119. ZERO_BYTE_FILE : -120,
  8120. INVALID_FILETYPE : -130
  8121. };
  8122. SWFUpload.UPLOAD_ERROR = {
  8123. HTTP_ERROR : -200,
  8124. MISSING_UPLOAD_URL : -210,
  8125. IO_ERROR : -220,
  8126. SECURITY_ERROR : -230,
  8127. UPLOAD_LIMIT_EXCEEDED : -240,
  8128. UPLOAD_FAILED : -250,
  8129. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8130. FILE_VALIDATION_FAILED : -270,
  8131. FILE_CANCELLED : -280,
  8132. UPLOAD_STOPPED : -290
  8133. };
  8134. SWFUpload.FILE_STATUS = {
  8135. QUEUED : -1,
  8136. IN_PROGRESS : -2,
  8137. ERROR : -3,
  8138. COMPLETE : -4,
  8139. CANCELLED : -5
  8140. };
  8141. SWFUpload.BUTTON_ACTION = {
  8142. SELECT_FILE : -100,
  8143. SELECT_FILES : -110,
  8144. START_UPLOAD : -120
  8145. };
  8146. SWFUpload.CURSOR = {
  8147. ARROW : -1,
  8148. HAND : -2
  8149. };
  8150. SWFUpload.WINDOW_MODE = {
  8151. WINDOW : "window",
  8152. TRANSPARENT : "transparent",
  8153. OPAQUE : "opaque"
  8154. };
  8155. // Private: takes a URL, determines if it is relative and converts to an absolute URL
  8156. // using the current site. Only processes the URL if it can, otherwise returns the URL untouched
  8157. SWFUpload.completeURL = function(url) {
  8158. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8159. return url;
  8160. }
  8161. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8162. var indexSlash = window.location.pathname.lastIndexOf("/");
  8163. if (indexSlash <= 0) {
  8164. path = "/";
  8165. } else {
  8166. path = window.location.pathname.substr(0, indexSlash) + "/";
  8167. }
  8168. return /*currentURL +*/ path + url;
  8169. };
  8170. /* ******************** */
  8171. /* Instance Members */
  8172. /* ******************** */
  8173. // Private: initSettings ensures that all the
  8174. // settings are set, getting a default value if one was not assigned.
  8175. SWFUpload.prototype.initSettings = function () {
  8176. this.ensureDefault = function (settingName, defaultValue) {
  8177. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8178. };
  8179. // Upload backend settings
  8180. this.ensureDefault("upload_url", "");
  8181. this.ensureDefault("preserve_relative_urls", false);
  8182. this.ensureDefault("file_post_name", "Filedata");
  8183. this.ensureDefault("post_params", {});
  8184. this.ensureDefault("use_query_string", false);
  8185. this.ensureDefault("requeue_on_error", false);
  8186. this.ensureDefault("http_success", []);
  8187. this.ensureDefault("assume_success_timeout", 0);
  8188. // File Settings
  8189. this.ensureDefault("file_types", "*.*");
  8190. this.ensureDefault("file_types_description", "All Files");
  8191. this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
  8192. this.ensureDefault("file_upload_limit", 0);
  8193. this.ensureDefault("file_queue_limit", 0);
  8194. // Flash Settings
  8195. this.ensureDefault("flash_url", "swfupload.swf");
  8196. this.ensureDefault("prevent_swf_caching", true);
  8197. // Button Settings
  8198. this.ensureDefault("button_image_url", "");
  8199. this.ensureDefault("button_width", 1);
  8200. this.ensureDefault("button_height", 1);
  8201. this.ensureDefault("button_text", "");
  8202. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8203. this.ensureDefault("button_text_top_padding", 0);
  8204. this.ensureDefault("button_text_left_padding", 0);
  8205. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8206. this.ensureDefault("button_disabled", false);
  8207. this.ensureDefault("button_placeholder_id", "");
  8208. this.ensureDefault("button_placeholder", null);
  8209. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8210. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8211. // Debug Settings
  8212. this.ensureDefault("debug", false);
  8213. this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
  8214. // Event Handlers
  8215. this.settings.return_upload_start_handler = this.returnUploadStart;
  8216. this.ensureDefault("swfupload_loaded_handler", null);
  8217. this.ensureDefault("file_dialog_start_handler", null);
  8218. this.ensureDefault("file_queued_handler", null);
  8219. this.ensureDefault("file_queue_error_handler", null);
  8220. this.ensureDefault("file_dialog_complete_handler", null);
  8221. this.ensureDefault("upload_start_handler", null);
  8222. this.ensureDefault("upload_progress_handler", null);
  8223. this.ensureDefault("upload_error_handler", null);
  8224. this.ensureDefault("upload_success_handler", null);
  8225. this.ensureDefault("upload_complete_handler", null);
  8226. this.ensureDefault("debug_handler", this.debugMessage);
  8227. this.ensureDefault("custom_settings", {});
  8228. // Other settings
  8229. this.customSettings = this.settings.custom_settings;
  8230. // Update the flash url if needed
  8231. if (!!this.settings.prevent_swf_caching) {
  8232. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8233. }
  8234. if (!this.settings.preserve_relative_urls) {
  8235. //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it
  8236. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8237. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8238. }
  8239. delete this.ensureDefault;
  8240. };
  8241. // Private: loadFlash replaces the button_placeholder element with the flash movie.
  8242. SWFUpload.prototype.loadFlash = function () {
  8243. var targetElement, tempParent;
  8244. // Make sure an element with the ID we are going to use doesn't already exist
  8245. if (document.getElementById(this.movieName) !== null) {
  8246. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8247. }
  8248. // Get the element where we will be placing the flash movie
  8249. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8250. if (targetElement == undefined) {
  8251. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8252. }
  8253. // Append the container and load the flash
  8254. tempParent = document.createElement("div");
  8255. tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
  8256. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8257. // Fix IE Flash/Form bug
  8258. if (window[this.movieName] == undefined) {
  8259. window[this.movieName] = this.getMovieElement();
  8260. }
  8261. };
  8262. // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
  8263. SWFUpload.prototype.getFlashHTML = function () {
  8264. // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  8265. // Fix bug for IE9
  8266. // http://www.kindsoft.net/view.php?bbsid=7&postid=5825&pagenum=1
  8267. var classid = '';
  8268. if (KindEditor.IE && KindEditor.V > 8) {
  8269. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8270. }
  8271. 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">',
  8272. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8273. '<param name="movie" value="', this.settings.flash_url, '" />',
  8274. '<param name="quality" value="high" />',
  8275. '<param name="menu" value="false" />',
  8276. '<param name="allowScriptAccess" value="always" />',
  8277. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8278. '</object>'].join("");
  8279. };
  8280. // Private: getFlashVars builds the parameter string that will be passed
  8281. // to flash in the flashvars param.
  8282. SWFUpload.prototype.getFlashVars = function () {
  8283. // Build a string from the post param object
  8284. var paramString = this.buildParamString();
  8285. var httpSuccessString = this.settings.http_success.join(",");
  8286. // Build the parameter string
  8287. return ["movieName=", encodeURIComponent(this.movieName),
  8288. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8289. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8290. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8291. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8292. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8293. "&amp;params=", encodeURIComponent(paramString),
  8294. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8295. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8296. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8297. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8298. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8299. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8300. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8301. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8302. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8303. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8304. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8305. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8306. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8307. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8308. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8309. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8310. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8311. ].join("");
  8312. };
  8313. // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
  8314. // The element is cached after the first lookup
  8315. SWFUpload.prototype.getMovieElement = function () {
  8316. if (this.movieElement == undefined) {
  8317. this.movieElement = document.getElementById(this.movieName);
  8318. }
  8319. if (this.movieElement === null) {
  8320. throw "Could not find Flash element";
  8321. }
  8322. return this.movieElement;
  8323. };
  8324. // Private: buildParamString takes the name/value pairs in the post_params setting object
  8325. // and joins them up in to a string formatted "name=value&amp;name=value"
  8326. SWFUpload.prototype.buildParamString = function () {
  8327. var postParams = this.settings.post_params;
  8328. var paramStringPairs = [];
  8329. if (typeof(postParams) === "object") {
  8330. for (var name in postParams) {
  8331. if (postParams.hasOwnProperty(name)) {
  8332. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8333. }
  8334. }
  8335. }
  8336. return paramStringPairs.join("&amp;");
  8337. };
  8338. // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
  8339. // all references to the SWF, and other objects so memory is properly freed.
  8340. // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
  8341. // Credits: Major improvements provided by steffen
  8342. SWFUpload.prototype.destroy = function () {
  8343. try {
  8344. // Make sure Flash is done before we try to remove it
  8345. this.cancelUpload(null, false);
  8346. // Remove the SWFUpload DOM nodes
  8347. var movieElement = null;
  8348. movieElement = this.getMovieElement();
  8349. if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8350. // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
  8351. for (var i in movieElement) {
  8352. try {
  8353. if (typeof(movieElement[i]) === "function") {
  8354. movieElement[i] = null;
  8355. }
  8356. } catch (ex1) {}
  8357. }
  8358. // Remove the Movie Element from the page
  8359. try {
  8360. movieElement.parentNode.removeChild(movieElement);
  8361. } catch (ex) {}
  8362. }
  8363. // Remove IE form fix reference
  8364. window[this.movieName] = null;
  8365. // Destroy other references
  8366. SWFUpload.instances[this.movieName] = null;
  8367. delete SWFUpload.instances[this.movieName];
  8368. this.movieElement = null;
  8369. this.settings = null;
  8370. this.customSettings = null;
  8371. this.eventQueue = null;
  8372. this.movieName = null;
  8373. return true;
  8374. } catch (ex2) {
  8375. return false;
  8376. }
  8377. };
  8378. // Public: displayDebugInfo prints out settings and configuration
  8379. // information about this SWFUpload instance.
  8380. // This function (and any references to it) can be deleted when placing
  8381. // SWFUpload in production.
  8382. SWFUpload.prototype.displayDebugInfo = function () {
  8383. this.debug(
  8384. [
  8385. "---SWFUpload Instance Info---\n",
  8386. "Version: ", SWFUpload.version, "\n",
  8387. "Movie Name: ", this.movieName, "\n",
  8388. "Settings:\n",
  8389. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8390. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8391. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8392. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8393. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8394. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8395. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8396. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8397. "\t", "file_types: ", this.settings.file_types, "\n",
  8398. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8399. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8400. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8401. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8402. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8403. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8404. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8405. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8406. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8407. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8408. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8409. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8410. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8411. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8412. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8413. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8414. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8415. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8416. "Event Handlers:\n",
  8417. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8418. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8419. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8420. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8421. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8422. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8423. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8424. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8425. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8426. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8427. ].join("")
  8428. );
  8429. };
  8430. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8431. the maintain v2 API compatibility
  8432. */
  8433. // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
  8434. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8435. if (value == undefined) {
  8436. return (this.settings[name] = default_value);
  8437. } else {
  8438. return (this.settings[name] = value);
  8439. }
  8440. };
  8441. // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
  8442. SWFUpload.prototype.getSetting = function (name) {
  8443. if (this.settings[name] != undefined) {
  8444. return this.settings[name];
  8445. }
  8446. return "";
  8447. };
  8448. // Private: callFlash handles function calls made to the Flash element.
  8449. // Calls are made with a setTimeout for some functions to work around
  8450. // bugs in the ExternalInterface library.
  8451. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8452. argumentArray = argumentArray || [];
  8453. var movieElement = this.getMovieElement();
  8454. var returnValue, returnString;
  8455. // Flash's method if calling ExternalInterface methods (code adapted from MooTools).
  8456. try {
  8457. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8458. returnValue = eval(returnString);
  8459. } catch (ex) {
  8460. throw "Call to " + functionName + " failed";
  8461. }
  8462. // Unescape file post param values
  8463. if (returnValue != undefined && typeof returnValue.post === "object") {
  8464. returnValue = this.unescapeFilePostParams(returnValue);
  8465. }
  8466. return returnValue;
  8467. };
  8468. /* *****************************
  8469. -- Flash control methods --
  8470. Your UI should use these
  8471. to operate SWFUpload
  8472. ***************************** */
  8473. // WARNING: this function does not work in Flash Player 10
  8474. // Public: selectFile causes a File Selection Dialog window to appear. This
  8475. // dialog only allows 1 file to be selected.
  8476. SWFUpload.prototype.selectFile = function () {
  8477. this.callFlash("SelectFile");
  8478. };
  8479. // WARNING: this function does not work in Flash Player 10
  8480. // Public: selectFiles causes a File Selection Dialog window to appear/ This
  8481. // dialog allows the user to select any number of files
  8482. // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
  8483. // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
  8484. // for this bug.
  8485. SWFUpload.prototype.selectFiles = function () {
  8486. this.callFlash("SelectFiles");
  8487. };
  8488. // Public: startUpload starts uploading the first file in the queue unless
  8489. // the optional parameter 'fileID' specifies the ID
  8490. SWFUpload.prototype.startUpload = function (fileID) {
  8491. this.callFlash("StartUpload", [fileID]);
  8492. };
  8493. // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
  8494. // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
  8495. // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
  8496. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8497. if (triggerErrorEvent !== false) {
  8498. triggerErrorEvent = true;
  8499. }
  8500. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8501. };
  8502. // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
  8503. // If nothing is currently uploading then nothing happens.
  8504. SWFUpload.prototype.stopUpload = function () {
  8505. this.callFlash("StopUpload");
  8506. };
  8507. /* ************************
  8508. * Settings methods
  8509. * These methods change the SWFUpload settings.
  8510. * SWFUpload settings should not be changed directly on the settings object
  8511. * since many of the settings need to be passed to Flash in order to take
  8512. * effect.
  8513. * *********************** */
  8514. // Public: getStats gets the file statistics object.
  8515. SWFUpload.prototype.getStats = function () {
  8516. return this.callFlash("GetStats");
  8517. };
  8518. // Public: setStats changes the SWFUpload statistics. You shouldn't need to
  8519. // change the statistics but you can. Changing the statistics does not
  8520. // affect SWFUpload accept for the successful_uploads count which is used
  8521. // by the upload_limit setting to determine how many files the user may upload.
  8522. SWFUpload.prototype.setStats = function (statsObject) {
  8523. this.callFlash("SetStats", [statsObject]);
  8524. };
  8525. // Public: getFile retrieves a File object by ID or Index. If the file is
  8526. // not found then 'null' is returned.
  8527. SWFUpload.prototype.getFile = function (fileID) {
  8528. if (typeof(fileID) === "number") {
  8529. return this.callFlash("GetFileByIndex", [fileID]);
  8530. } else {
  8531. return this.callFlash("GetFile", [fileID]);
  8532. }
  8533. };
  8534. // Public: addFileParam sets a name/value pair that will be posted with the
  8535. // file specified by the Files ID. If the name already exists then the
  8536. // exiting value will be overwritten.
  8537. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8538. return this.callFlash("AddFileParam", [fileID, name, value]);
  8539. };
  8540. // Public: removeFileParam removes a previously set (by addFileParam) name/value
  8541. // pair from the specified file.
  8542. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8543. this.callFlash("RemoveFileParam", [fileID, name]);
  8544. };
  8545. // Public: setUploadUrl changes the upload_url setting.
  8546. SWFUpload.prototype.setUploadURL = function (url) {
  8547. this.settings.upload_url = url.toString();
  8548. this.callFlash("SetUploadURL", [url]);
  8549. };
  8550. // Public: setPostParams changes the post_params setting
  8551. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8552. this.settings.post_params = paramsObject;
  8553. this.callFlash("SetPostParams", [paramsObject]);
  8554. };
  8555. // Public: addPostParam adds post name/value pair. Each name can have only one value.
  8556. SWFUpload.prototype.addPostParam = function (name, value) {
  8557. this.settings.post_params[name] = value;
  8558. this.callFlash("SetPostParams", [this.settings.post_params]);
  8559. };
  8560. // Public: removePostParam deletes post name/value pair.
  8561. SWFUpload.prototype.removePostParam = function (name) {
  8562. delete this.settings.post_params[name];
  8563. this.callFlash("SetPostParams", [this.settings.post_params]);
  8564. };
  8565. // Public: setFileTypes changes the file_types setting and the file_types_description setting
  8566. SWFUpload.prototype.setFileTypes = function (types, description) {
  8567. this.settings.file_types = types;
  8568. this.settings.file_types_description = description;
  8569. this.callFlash("SetFileTypes", [types, description]);
  8570. };
  8571. // Public: setFileSizeLimit changes the file_size_limit setting
  8572. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8573. this.settings.file_size_limit = fileSizeLimit;
  8574. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8575. };
  8576. // Public: setFileUploadLimit changes the file_upload_limit setting
  8577. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8578. this.settings.file_upload_limit = fileUploadLimit;
  8579. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8580. };
  8581. // Public: setFileQueueLimit changes the file_queue_limit setting
  8582. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8583. this.settings.file_queue_limit = fileQueueLimit;
  8584. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8585. };
  8586. // Public: setFilePostName changes the file_post_name setting
  8587. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8588. this.settings.file_post_name = filePostName;
  8589. this.callFlash("SetFilePostName", [filePostName]);
  8590. };
  8591. // Public: setUseQueryString changes the use_query_string setting
  8592. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8593. this.settings.use_query_string = useQueryString;
  8594. this.callFlash("SetUseQueryString", [useQueryString]);
  8595. };
  8596. // Public: setRequeueOnError changes the requeue_on_error setting
  8597. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8598. this.settings.requeue_on_error = requeueOnError;
  8599. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8600. };
  8601. // Public: setHTTPSuccess changes the http_success setting
  8602. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8603. if (typeof http_status_codes === "string") {
  8604. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8605. }
  8606. this.settings.http_success = http_status_codes;
  8607. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8608. };
  8609. // Public: setHTTPSuccess changes the http_success setting
  8610. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8611. this.settings.assume_success_timeout = timeout_seconds;
  8612. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8613. };
  8614. // Public: setDebugEnabled changes the debug_enabled setting
  8615. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8616. this.settings.debug_enabled = debugEnabled;
  8617. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8618. };
  8619. // Public: setButtonImageURL loads a button image sprite
  8620. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8621. if (buttonImageURL == undefined) {
  8622. buttonImageURL = "";
  8623. }
  8624. this.settings.button_image_url = buttonImageURL;
  8625. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8626. };
  8627. // Public: setButtonDimensions resizes the Flash Movie and button
  8628. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8629. this.settings.button_width = width;
  8630. this.settings.button_height = height;
  8631. var movie = this.getMovieElement();
  8632. if (movie != undefined) {
  8633. movie.style.width = width + "px";
  8634. movie.style.height = height + "px";
  8635. }
  8636. this.callFlash("SetButtonDimensions", [width, height]);
  8637. };
  8638. // Public: setButtonText Changes the text overlaid on the button
  8639. SWFUpload.prototype.setButtonText = function (html) {
  8640. this.settings.button_text = html;
  8641. this.callFlash("SetButtonText", [html]);
  8642. };
  8643. // Public: setButtonTextPadding changes the top and left padding of the text overlay
  8644. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8645. this.settings.button_text_top_padding = top;
  8646. this.settings.button_text_left_padding = left;
  8647. this.callFlash("SetButtonTextPadding", [left, top]);
  8648. };
  8649. // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
  8650. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8651. this.settings.button_text_style = css;
  8652. this.callFlash("SetButtonTextStyle", [css]);
  8653. };
  8654. // Public: setButtonDisabled disables/enables the button
  8655. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8656. this.settings.button_disabled = isDisabled;
  8657. this.callFlash("SetButtonDisabled", [isDisabled]);
  8658. };
  8659. // Public: setButtonAction sets the action that occurs when the button is clicked
  8660. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8661. this.settings.button_action = buttonAction;
  8662. this.callFlash("SetButtonAction", [buttonAction]);
  8663. };
  8664. // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
  8665. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8666. this.settings.button_cursor = cursor;
  8667. this.callFlash("SetButtonCursor", [cursor]);
  8668. };
  8669. /* *******************************
  8670. Flash Event Interfaces
  8671. These functions are used by Flash to trigger the various
  8672. events.
  8673. All these functions a Private.
  8674. Because the ExternalInterface library is buggy the event calls
  8675. are added to a queue and the queue then executed by a setTimeout.
  8676. This ensures that events are executed in a determinate order and that
  8677. the ExternalInterface bugs are avoided.
  8678. ******************************* */
  8679. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8680. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8681. if (argumentArray == undefined) {
  8682. argumentArray = [];
  8683. } else if (!(argumentArray instanceof Array)) {
  8684. argumentArray = [argumentArray];
  8685. }
  8686. var self = this;
  8687. if (typeof this.settings[handlerName] === "function") {
  8688. // Queue the event
  8689. this.eventQueue.push(function () {
  8690. this.settings[handlerName].apply(this, argumentArray);
  8691. });
  8692. // Execute the next queued event
  8693. setTimeout(function () {
  8694. self.executeNextEvent();
  8695. }, 0);
  8696. } else if (this.settings[handlerName] !== null) {
  8697. throw "Event handler " + handlerName + " is unknown or is not a function";
  8698. }
  8699. };
  8700. // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
  8701. // we must queue them in order to garentee that they are executed in order.
  8702. SWFUpload.prototype.executeNextEvent = function () {
  8703. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8704. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8705. if (typeof(f) === "function") {
  8706. f.apply(this);
  8707. }
  8708. };
  8709. // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
  8710. // properties that contain characters that are not valid for JavaScript identifiers. To work around this
  8711. // the Flash Component escapes the parameter names and we must unescape again before passing them along.
  8712. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8713. var reg = /[$]([0-9a-f]{4})/i;
  8714. var unescapedPost = {};
  8715. var uk;
  8716. if (file != undefined) {
  8717. for (var k in file.post) {
  8718. if (file.post.hasOwnProperty(k)) {
  8719. uk = k;
  8720. var match;
  8721. while ((match = reg.exec(uk)) !== null) {
  8722. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8723. }
  8724. unescapedPost[uk] = file.post[k];
  8725. }
  8726. }
  8727. file.post = unescapedPost;
  8728. }
  8729. return file;
  8730. };
  8731. // Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working)
  8732. SWFUpload.prototype.testExternalInterface = function () {
  8733. try {
  8734. return this.callFlash("TestExternalInterface");
  8735. } catch (ex) {
  8736. return false;
  8737. }
  8738. };
  8739. // Private: This event is called by Flash when it has finished loading. Don't modify this.
  8740. // Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded.
  8741. SWFUpload.prototype.flashReady = function () {
  8742. // Check that the movie element is loaded correctly with its ExternalInterface methods defined
  8743. var movieElement = this.getMovieElement();
  8744. if (!movieElement) {
  8745. this.debug("Flash called back ready but the flash movie can't be found.");
  8746. return;
  8747. }
  8748. this.cleanUp(movieElement);
  8749. this.queueEvent("swfupload_loaded_handler");
  8750. };
  8751. // Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
  8752. // This function is called by Flash each time the ExternalInterface functions are created.
  8753. SWFUpload.prototype.cleanUp = function (movieElement) {
  8754. // Pro-actively unhook all the Flash functions
  8755. try {
  8756. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8757. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8758. for (var key in movieElement) {
  8759. try {
  8760. if (typeof(movieElement[key]) === "function") {
  8761. movieElement[key] = null;
  8762. }
  8763. } catch (ex) {
  8764. }
  8765. }
  8766. }
  8767. } catch (ex1) {
  8768. }
  8769. // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
  8770. // it doesn't display errors.
  8771. window["__flash__removeCallback"] = function (instance, name) {
  8772. try {
  8773. if (instance) {
  8774. instance[name] = null;
  8775. }
  8776. } catch (flashEx) {
  8777. }
  8778. };
  8779. };
  8780. /* This is a chance to do something before the browse window opens */
  8781. SWFUpload.prototype.fileDialogStart = function () {
  8782. this.queueEvent("file_dialog_start_handler");
  8783. };
  8784. /* Called when a file is successfully added to the queue. */
  8785. SWFUpload.prototype.fileQueued = function (file) {
  8786. file = this.unescapeFilePostParams(file);
  8787. this.queueEvent("file_queued_handler", file);
  8788. };
  8789. /* Handle errors that occur when an attempt to queue a file fails. */
  8790. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8791. file = this.unescapeFilePostParams(file);
  8792. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8793. };
  8794. /* Called after the file dialog has closed and the selected files have been queued.
  8795. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8796. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8797. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8798. };
  8799. SWFUpload.prototype.uploadStart = function (file) {
  8800. file = this.unescapeFilePostParams(file);
  8801. this.queueEvent("return_upload_start_handler", file);
  8802. };
  8803. SWFUpload.prototype.returnUploadStart = function (file) {
  8804. var returnValue;
  8805. if (typeof this.settings.upload_start_handler === "function") {
  8806. file = this.unescapeFilePostParams(file);
  8807. returnValue = this.settings.upload_start_handler.call(this, file);
  8808. } else if (this.settings.upload_start_handler != undefined) {
  8809. throw "upload_start_handler must be a function";
  8810. }
  8811. // Convert undefined to true so if nothing is returned from the upload_start_handler it is
  8812. // interpretted as 'true'.
  8813. if (returnValue === undefined) {
  8814. returnValue = true;
  8815. }
  8816. returnValue = !!returnValue;
  8817. this.callFlash("ReturnUploadStart", [returnValue]);
  8818. };
  8819. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8820. file = this.unescapeFilePostParams(file);
  8821. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8822. };
  8823. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8824. file = this.unescapeFilePostParams(file);
  8825. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8826. };
  8827. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8828. file = this.unescapeFilePostParams(file);
  8829. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8830. };
  8831. SWFUpload.prototype.uploadComplete = function (file) {
  8832. file = this.unescapeFilePostParams(file);
  8833. this.queueEvent("upload_complete_handler", file);
  8834. };
  8835. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8836. internal debug console. You can override this event and have messages written where you want. */
  8837. SWFUpload.prototype.debug = function (message) {
  8838. this.queueEvent("debug_handler", message);
  8839. };
  8840. /* **********************************
  8841. Debug Console
  8842. The debug console is a self contained, in page location
  8843. for debug message to be sent. The Debug Console adds
  8844. itself to the body if necessary.
  8845. The console is automatically scrolled as messages appear.
  8846. If you are using your own debug handler or when you deploy to production and
  8847. have debug disabled you can remove these functions to reduce the file size
  8848. and complexity.
  8849. ********************************** */
  8850. // Private: debugMessage is the default debug_handler. If you want to print debug messages
  8851. // call the debug() function. When overriding the function your own function should
  8852. // check to see if the debug setting is true before outputting debug information.
  8853. SWFUpload.prototype.debugMessage = function (message) {
  8854. if (this.settings.debug) {
  8855. var exceptionMessage, exceptionValues = [];
  8856. // Check for an exception object and print it nicely
  8857. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8858. for (var key in message) {
  8859. if (message.hasOwnProperty(key)) {
  8860. exceptionValues.push(key + ": " + message[key]);
  8861. }
  8862. }
  8863. exceptionMessage = exceptionValues.join("\n") || "";
  8864. exceptionValues = exceptionMessage.split("\n");
  8865. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8866. SWFUpload.Console.writeLine(exceptionMessage);
  8867. } else {
  8868. SWFUpload.Console.writeLine(message);
  8869. }
  8870. }
  8871. };
  8872. SWFUpload.Console = {};
  8873. SWFUpload.Console.writeLine = function (message) {
  8874. var console, documentForm;
  8875. try {
  8876. console = document.getElementById("SWFUpload_Console");
  8877. if (!console) {
  8878. documentForm = document.createElement("form");
  8879. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8880. console = document.createElement("textarea");
  8881. console.id = "SWFUpload_Console";
  8882. console.style.fontFamily = "monospace";
  8883. console.setAttribute("wrap", "off");
  8884. console.wrap = "off";
  8885. console.style.overflow = "auto";
  8886. console.style.width = "700px";
  8887. console.style.height = "350px";
  8888. console.style.margin = "5px";
  8889. documentForm.appendChild(console);
  8890. }
  8891. console.value += message + "\n";
  8892. console.scrollTop = console.scrollHeight - console.clientHeight;
  8893. } catch (ex) {
  8894. alert("Exception: " + ex.name + " Message: " + ex.message);
  8895. }
  8896. };
  8897. })();
  8898. (function() {
  8899. /*
  8900. Queue Plug-in
  8901. Features:
  8902. *Adds a cancelQueue() method for cancelling the entire queue.
  8903. *All queued files are uploaded when startUpload() is called.
  8904. *If false is returned from uploadComplete then the queue upload is stopped.
  8905. If false is not returned (strict comparison) then the queue upload is continued.
  8906. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8907. Set the event handler with the queue_complete_handler setting.
  8908. */
  8909. if (typeof(SWFUpload) === "function") {
  8910. SWFUpload.queue = {};
  8911. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8912. return function () {
  8913. if (typeof(oldInitSettings) === "function") {
  8914. oldInitSettings.call(this);
  8915. }
  8916. this.queueSettings = {};
  8917. this.queueSettings.queue_cancelled_flag = false;
  8918. this.queueSettings.queue_upload_count = 0;
  8919. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8920. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8921. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8922. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8923. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8924. };
  8925. })(SWFUpload.prototype.initSettings);
  8926. SWFUpload.prototype.startUpload = function (fileID) {
  8927. this.queueSettings.queue_cancelled_flag = false;
  8928. this.callFlash("StartUpload", [fileID]);
  8929. };
  8930. SWFUpload.prototype.cancelQueue = function () {
  8931. this.queueSettings.queue_cancelled_flag = true;
  8932. this.stopUpload();
  8933. var stats = this.getStats();
  8934. while (stats.files_queued > 0) {
  8935. this.cancelUpload();
  8936. stats = this.getStats();
  8937. }
  8938. };
  8939. SWFUpload.queue.uploadStartHandler = function (file) {
  8940. var returnValue;
  8941. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8942. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8943. }
  8944. // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
  8945. returnValue = (returnValue === false) ? false : true;
  8946. this.queueSettings.queue_cancelled_flag = !returnValue;
  8947. return returnValue;
  8948. };
  8949. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8950. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8951. var continueUpload;
  8952. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8953. this.queueSettings.queue_upload_count++;
  8954. }
  8955. if (typeof(user_upload_complete_handler) === "function") {
  8956. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8957. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8958. // If the file was stopped and re-queued don't restart the upload
  8959. continueUpload = false;
  8960. } else {
  8961. continueUpload = true;
  8962. }
  8963. if (continueUpload) {
  8964. var stats = this.getStats();
  8965. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8966. this.startUpload();
  8967. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8968. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8969. this.queueSettings.queue_upload_count = 0;
  8970. } else {
  8971. this.queueSettings.queue_cancelled_flag = false;
  8972. this.queueSettings.queue_upload_count = 0;
  8973. }
  8974. }
  8975. };
  8976. }
  8977. })();
  8978. /*******************************************************************************
  8979. * KindEditor - WYSIWYG HTML Editor for Internet
  8980. * Copyright (C) 2006-2011 kindsoft.net
  8981. *
  8982. * @author Roddy <luolonghao@gmail.com>
  8983. * @site http://www.kindsoft.net/
  8984. * @licence http://www.kindsoft.net/license.php
  8985. *******************************************************************************/
  8986. KindEditor.plugin('pagebreak', function(K) {
  8987. var self = this;
  8988. var name = 'pagebreak';
  8989. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8990. self.clickToolbar(name, function() {
  8991. var cmd = self.cmd, range = cmd.range;
  8992. self.focus();
  8993. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8994. self.insertHtml(pagebreakHtml + tail);
  8995. if (tail !== '') {
  8996. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8997. range.selectNodeContents(p[0]);
  8998. p.removeAttr('id');
  8999. cmd.select();
  9000. }
  9001. });
  9002. });
  9003. /*******************************************************************************
  9004. * KindEditor - WYSIWYG HTML Editor for Internet
  9005. * Copyright (C) 2006-2011 kindsoft.net
  9006. *
  9007. * @author Roddy <luolonghao@gmail.com>
  9008. * @site http://www.kindsoft.net/
  9009. * @licence http://www.kindsoft.net/license.php
  9010. *******************************************************************************/
  9011. KindEditor.plugin('plainpaste', function(K) {
  9012. var self = this, name = 'plainpaste';
  9013. self.clickToolbar(name, function() {
  9014. var lang = self.lang(name + '.'),
  9015. html = '<div style="padding:10px 20px;">' +
  9016. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9017. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9018. '</div>',
  9019. dialog = self.createDialog({
  9020. name : name,
  9021. width : 450,
  9022. title : self.lang(name),
  9023. body : html,
  9024. yesBtn : {
  9025. name : self.lang('yes'),
  9026. click : function(e) {
  9027. var html = textarea.val();
  9028. html = K.escape(html);
  9029. html = html.replace(/ {2}/g, ' &nbsp;');
  9030. if (self.newlineTag == 'p') {
  9031. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9032. } else {
  9033. html = html.replace(/\n/g, '<br />$&');
  9034. }
  9035. self.insertHtml(html).hideDialog().focus();
  9036. }
  9037. }
  9038. }),
  9039. textarea = K('textarea', dialog.div);
  9040. textarea[0].focus();
  9041. });
  9042. });
  9043. /*******************************************************************************
  9044. * KindEditor - WYSIWYG HTML Editor for Internet
  9045. * Copyright (C) 2006-2011 kindsoft.net
  9046. *
  9047. * @author Roddy <luolonghao@gmail.com>
  9048. * @site http://www.kindsoft.net/
  9049. * @licence http://www.kindsoft.net/license.php
  9050. *******************************************************************************/
  9051. KindEditor.plugin('preview', function(K) {
  9052. var self = this, name = 'preview', undefined;
  9053. self.clickToolbar(name, function() {
  9054. var lang = self.lang(name + '.'),
  9055. html = '<div style="padding:10px 20px;">' +
  9056. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9057. '</div>',
  9058. dialog = self.createDialog({
  9059. name : name,
  9060. width : 750,
  9061. title : self.lang(name),
  9062. body : html
  9063. }),
  9064. iframe = K('iframe', dialog.div),
  9065. doc = K.iframeDoc(iframe);
  9066. doc.open();
  9067. doc.write(self.fullHtml());
  9068. doc.close();
  9069. K(doc.body).css('background-color', '#FFF');
  9070. iframe[0].contentWindow.focus();
  9071. });
  9072. });
  9073. /*******************************************************************************
  9074. * KindEditor - WYSIWYG HTML Editor for Internet
  9075. * Copyright (C) 2006-2011 kindsoft.net
  9076. *
  9077. * @author Roddy <luolonghao@gmail.com>
  9078. * @site http://www.kindsoft.net/
  9079. * @licence http://www.kindsoft.net/license.php
  9080. *******************************************************************************/
  9081. KindEditor.plugin('quickformat', function(K) {
  9082. var self = this, name = 'quickformat',
  9083. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9084. function getFirstChild(knode) {
  9085. var child = knode.first();
  9086. while (child && child.first()) {
  9087. child = child.first();
  9088. }
  9089. return child;
  9090. }
  9091. self.clickToolbar(name, function() {
  9092. self.focus();
  9093. var doc = self.edit.doc,
  9094. range = self.cmd.range,
  9095. child = K(doc.body).first(), next,
  9096. nodeList = [], subList = [],
  9097. bookmark = range.createBookmark(true);
  9098. while(child) {
  9099. next = child.next();
  9100. var firstChild = getFirstChild(child);
  9101. if (!firstChild || firstChild.name != 'img') {
  9102. if (blockMap[child.name]) {
  9103. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9104. child.css('text-indent', '2em');
  9105. } else {
  9106. subList.push(child);
  9107. }
  9108. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9109. if (subList.length > 0) {
  9110. nodeList.push(subList);
  9111. }
  9112. subList = [];
  9113. }
  9114. }
  9115. child = next;
  9116. }
  9117. K.each(nodeList, function(i, subList) {
  9118. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9119. subList[0].before(wrapper);
  9120. K.each(subList, function(i, knode) {
  9121. wrapper.append(knode);
  9122. });
  9123. });
  9124. range.moveToBookmark(bookmark);
  9125. self.addBookmark();
  9126. });
  9127. });
  9128. /**
  9129. --------------------------
  9130. abcd<br />
  9131. 1234<br />
  9132. to
  9133. <p style="text-indent:2em;">
  9134. abcd<br />
  9135. 1234<br />
  9136. </p>
  9137. --------------------------
  9138. &nbsp; abcd<img>1233
  9139. <p>1234</p>
  9140. to
  9141. <p style="text-indent:2em;">abcd<img>1233</p>
  9142. <p style="text-indent:2em;">1234</p>
  9143. --------------------------
  9144. *//*******************************************************************************
  9145. * KindEditor - WYSIWYG HTML Editor for Internet
  9146. * Copyright (C) 2006-2011 kindsoft.net
  9147. *
  9148. * @author Roddy <luolonghao@gmail.com>
  9149. * @site http://www.kindsoft.net/
  9150. * @licence http://www.kindsoft.net/license.php
  9151. *******************************************************************************/
  9152. KindEditor.plugin('table', function(K) {
  9153. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9154. // 设置颜色
  9155. function _setColor(box, color) {
  9156. color = color.toUpperCase();
  9157. box.css('background-color', color);
  9158. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9159. box.html(color);
  9160. }
  9161. // 初始化取色器
  9162. var pickerList = [];
  9163. function _initColorPicker(dialogDiv, colorBox) {
  9164. colorBox.bind('click,mousedown', function(e){
  9165. e.stopPropagation();
  9166. });
  9167. function removePicker() {
  9168. K.each(pickerList, function() {
  9169. this.remove();
  9170. });
  9171. pickerList = [];
  9172. K(document).unbind('click,mousedown', removePicker);
  9173. dialogDiv.unbind('click,mousedown', removePicker);
  9174. }
  9175. colorBox.click(function(e) {
  9176. removePicker();
  9177. var box = K(this),
  9178. pos = box.pos();
  9179. var picker = K.colorpicker({
  9180. x : pos.x,
  9181. y : pos.y + box.height(),
  9182. z : 811214,
  9183. selectedColor : K(this).html(),
  9184. colors : self.colorTable,
  9185. noColor : self.lang('noColor'),
  9186. shadowMode : self.shadowMode,
  9187. click : function(color) {
  9188. _setColor(box, color);
  9189. removePicker();
  9190. }
  9191. });
  9192. pickerList.push(picker);
  9193. K(document).bind('click,mousedown', removePicker);
  9194. dialogDiv.bind('click,mousedown', removePicker);
  9195. });
  9196. }
  9197. // 取得下一行cell的index
  9198. function _getCellIndex(table, row, cell) {
  9199. var rowSpanCount = 0;
  9200. for (var i = 0, len = row.cells.length; i < len; i++) {
  9201. if (row.cells[i] == cell) {
  9202. break;
  9203. }
  9204. rowSpanCount += row.cells[i].rowSpan - 1;
  9205. }
  9206. return cell.cellIndex - rowSpanCount;
  9207. }
  9208. self.plugin.table = {
  9209. //insert or modify table
  9210. prop : function(isInsert) {
  9211. var html = [
  9212. '<div style="padding:20px;">',
  9213. //rows, cols
  9214. '<div class="ke-dialog-row">',
  9215. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9216. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9217. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9218. '</div>',
  9219. //width, height
  9220. '<div class="ke-dialog-row">',
  9221. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9222. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9223. '<select name="widthType">',
  9224. '<option value="%">' + lang.percent + '</option>',
  9225. '<option value="px">' + lang.px + '</option>',
  9226. '</select> &nbsp; ',
  9227. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9228. '<select name="heightType">',
  9229. '<option value="%">' + lang.percent + '</option>',
  9230. '<option value="px">' + lang.px + '</option>',
  9231. '</select>',
  9232. '</div>',
  9233. //space, padding
  9234. '<div class="ke-dialog-row">',
  9235. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9236. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9237. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9238. '</div>',
  9239. //align
  9240. '<div class="ke-dialog-row">',
  9241. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9242. '<select id="keAlign" name="align">',
  9243. '<option value="">' + lang.alignDefault + '</option>',
  9244. '<option value="left">' + lang.alignLeft + '</option>',
  9245. '<option value="center">' + lang.alignCenter + '</option>',
  9246. '<option value="right">' + lang.alignRight + '</option>',
  9247. '</select>',
  9248. '</div>',
  9249. //border
  9250. '<div class="ke-dialog-row">',
  9251. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9252. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9253. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9254. '</div>',
  9255. //background color
  9256. '<div class="ke-dialog-row">',
  9257. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9258. '<span class="ke-inline-block ke-input-color"></span>',
  9259. '</div>',
  9260. '</div>'
  9261. ].join('');
  9262. var bookmark = self.cmd.range.createBookmark();
  9263. var dialog = self.createDialog({
  9264. name : name,
  9265. width : 500,
  9266. title : self.lang(name),
  9267. body : html,
  9268. beforeRemove : function() {
  9269. colorBox.unbind();
  9270. },
  9271. yesBtn : {
  9272. name : self.lang('yes'),
  9273. click : function(e) {
  9274. var rows = rowsBox.val(),
  9275. cols = colsBox.val(),
  9276. width = widthBox.val(),
  9277. height = heightBox.val(),
  9278. widthType = widthTypeBox.val(),
  9279. heightType = heightTypeBox.val(),
  9280. padding = paddingBox.val(),
  9281. spacing = spacingBox.val(),
  9282. align = alignBox.val(),
  9283. border = borderBox.val(),
  9284. borderColor = K(colorBox[0]).html() || '',
  9285. bgColor = K(colorBox[1]).html() || '';
  9286. if (rows == 0 || !/^\d+$/.test(rows)) {
  9287. alert(self.lang('invalidRows'));
  9288. rowsBox[0].focus();
  9289. return;
  9290. }
  9291. if (cols == 0 || !/^\d+$/.test(cols)) {
  9292. alert(self.lang('invalidRows'));
  9293. colsBox[0].focus();
  9294. return;
  9295. }
  9296. if (!/^\d*$/.test(width)) {
  9297. alert(self.lang('invalidWidth'));
  9298. widthBox[0].focus();
  9299. return;
  9300. }
  9301. if (!/^\d*$/.test(height)) {
  9302. alert(self.lang('invalidHeight'));
  9303. heightBox[0].focus();
  9304. return;
  9305. }
  9306. if (!/^\d*$/.test(padding)) {
  9307. alert(self.lang('invalidPadding'));
  9308. paddingBox[0].focus();
  9309. return;
  9310. }
  9311. if (!/^\d*$/.test(spacing)) {
  9312. alert(self.lang('invalidSpacing'));
  9313. spacingBox[0].focus();
  9314. return;
  9315. }
  9316. if (!/^\d*$/.test(border)) {
  9317. alert(self.lang('invalidBorder'));
  9318. borderBox[0].focus();
  9319. return;
  9320. }
  9321. //modify table
  9322. if (table) {
  9323. if (width !== '') {
  9324. table.width(width + widthType);
  9325. } else {
  9326. table.css('width', '');
  9327. }
  9328. if (table[0].width !== undefined) {
  9329. table.removeAttr('width');
  9330. }
  9331. if (height !== '') {
  9332. table.height(height + heightType);
  9333. } else {
  9334. table.css('height', '');
  9335. }
  9336. if (table[0].height !== undefined) {
  9337. table.removeAttr('height');
  9338. }
  9339. table.css('background-color', bgColor);
  9340. if (table[0].bgColor !== undefined) {
  9341. table.removeAttr('bgColor');
  9342. }
  9343. if (padding !== '') {
  9344. table[0].cellPadding = padding;
  9345. } else {
  9346. table.removeAttr('cellPadding');
  9347. }
  9348. if (spacing !== '') {
  9349. table[0].cellSpacing = spacing;
  9350. } else {
  9351. table.removeAttr('cellSpacing');
  9352. }
  9353. if (align !== '') {
  9354. table[0].align = align;
  9355. } else {
  9356. table.removeAttr('align');
  9357. }
  9358. if (border !== '') {
  9359. table.attr('border', border);
  9360. } else {
  9361. table.removeAttr('border');
  9362. }
  9363. if (border === '' || border === '0') {
  9364. table.addClass(zeroborder);
  9365. } else {
  9366. table.removeClass(zeroborder);
  9367. }
  9368. if (borderColor !== '') {
  9369. table.attr('borderColor', borderColor);
  9370. } else {
  9371. table.removeAttr('borderColor');
  9372. }
  9373. self.hideDialog().focus();
  9374. self.cmd.range.moveToBookmark(bookmark);
  9375. self.cmd.select();
  9376. self.addBookmark();
  9377. return;
  9378. }
  9379. //insert new table
  9380. var style = '';
  9381. if (width !== '') {
  9382. style += 'width:' + width + widthType + ';';
  9383. }
  9384. if (height !== '') {
  9385. style += 'height:' + height + heightType + ';';
  9386. }
  9387. if (bgColor !== '') {
  9388. style += 'background-color:' + bgColor + ';';
  9389. }
  9390. var html = '<table';
  9391. if (style !== '') {
  9392. html += ' style="' + style + '"';
  9393. }
  9394. if (padding !== '') {
  9395. html += ' cellpadding="' + padding + '"';
  9396. }
  9397. if (spacing !== '') {
  9398. html += ' cellspacing="' + spacing + '"';
  9399. }
  9400. if (align !== '') {
  9401. html += ' align="' + align + '"';
  9402. }
  9403. if (border !== '') {
  9404. html += ' border="' + border + '"';
  9405. }
  9406. if (border === '' || border === '0') {
  9407. html += ' class="' + zeroborder + '"';
  9408. }
  9409. if (borderColor !== '') {
  9410. html += ' bordercolor="' + borderColor + '"';
  9411. }
  9412. html += '>';
  9413. for (var i = 0; i < rows; i++) {
  9414. html += '<tr>';
  9415. for (var j = 0; j < cols; j++) {
  9416. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9417. }
  9418. html += '</tr>';
  9419. }
  9420. html += '</table>';
  9421. if (!K.IE) {
  9422. html += '<br />';
  9423. }
  9424. self.insertHtml(html);
  9425. self.select().hideDialog().focus();
  9426. self.addBookmark();
  9427. }
  9428. }
  9429. }),
  9430. div = dialog.div,
  9431. rowsBox = K('[name="rows"]', div).val(3),
  9432. colsBox = K('[name="cols"]', div).val(2),
  9433. widthBox = K('[name="width"]', div).val(100),
  9434. heightBox = K('[name="height"]', div),
  9435. widthTypeBox = K('[name="widthType"]', div),
  9436. heightTypeBox = K('[name="heightType"]', div),
  9437. paddingBox = K('[name="padding"]', div).val(2),
  9438. spacingBox = K('[name="spacing"]', div).val(0),
  9439. alignBox = K('[name="align"]', div),
  9440. borderBox = K('[name="border"]', div).val(1),
  9441. colorBox = K('.ke-input-color', div);
  9442. _initColorPicker(div, colorBox.eq(0));
  9443. _initColorPicker(div, colorBox.eq(1));
  9444. _setColor(colorBox.eq(0), '#000000');
  9445. _setColor(colorBox.eq(1), '');
  9446. // foucs and select
  9447. rowsBox[0].focus();
  9448. rowsBox[0].select();
  9449. var table;
  9450. if (isInsert) {
  9451. return;
  9452. }
  9453. //get selected table node
  9454. table = self.plugin.getSelectedTable();
  9455. if (table) {
  9456. rowsBox.val(table[0].rows.length);
  9457. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9458. rowsBox.attr('disabled', true);
  9459. colsBox.attr('disabled', true);
  9460. var match,
  9461. tableWidth = table[0].style.width || table[0].width,
  9462. tableHeight = table[0].style.height || table[0].height;
  9463. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9464. widthBox.val(match[1]);
  9465. widthTypeBox.val(match[2]);
  9466. } else {
  9467. widthBox.val('');
  9468. }
  9469. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9470. heightBox.val(match[1]);
  9471. heightTypeBox.val(match[2]);
  9472. }
  9473. paddingBox.val(table[0].cellPadding || '');
  9474. spacingBox.val(table[0].cellSpacing || '');
  9475. alignBox.val(table[0].align || '');
  9476. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9477. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9478. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9479. widthBox[0].focus();
  9480. widthBox[0].select();
  9481. }
  9482. },
  9483. //modify cell
  9484. cellprop : function() {
  9485. var html = [
  9486. '<div style="padding:20px;">',
  9487. //width, height
  9488. '<div class="ke-dialog-row">',
  9489. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9490. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9491. '<select name="widthType">',
  9492. '<option value="%">' + lang.percent + '</option>',
  9493. '<option value="px">' + lang.px + '</option>',
  9494. '</select> &nbsp; ',
  9495. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9496. '<select name="heightType">',
  9497. '<option value="%">' + lang.percent + '</option>',
  9498. '<option value="px">' + lang.px + '</option>',
  9499. '</select>',
  9500. '</div>',
  9501. //align
  9502. '<div class="ke-dialog-row">',
  9503. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9504. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9505. '<option value="">' + lang.alignDefault + '</option>',
  9506. '<option value="left">' + lang.alignLeft + '</option>',
  9507. '<option value="center">' + lang.alignCenter + '</option>',
  9508. '<option value="right">' + lang.alignRight + '</option>',
  9509. '</select> ',
  9510. lang.verticalAlign + ' <select name="verticalAlign">',
  9511. '<option value="">' + lang.alignDefault + '</option>',
  9512. '<option value="top">' + lang.alignTop + '</option>',
  9513. '<option value="middle">' + lang.alignMiddle + '</option>',
  9514. '<option value="bottom">' + lang.alignBottom + '</option>',
  9515. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9516. '</select>',
  9517. '</div>',
  9518. //border
  9519. '<div class="ke-dialog-row">',
  9520. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9521. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9522. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9523. '</div>',
  9524. //background color
  9525. '<div class="ke-dialog-row">',
  9526. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9527. '<span class="ke-inline-block ke-input-color"></span>',
  9528. '</div>',
  9529. '</div>'
  9530. ].join('');
  9531. var bookmark = self.cmd.range.createBookmark();
  9532. var dialog = self.createDialog({
  9533. name : name,
  9534. width : 500,
  9535. title : self.lang('tablecell'),
  9536. body : html,
  9537. beforeRemove : function() {
  9538. colorBox.unbind();
  9539. },
  9540. yesBtn : {
  9541. name : self.lang('yes'),
  9542. click : function(e) {
  9543. var width = widthBox.val(),
  9544. height = heightBox.val(),
  9545. widthType = widthTypeBox.val(),
  9546. heightType = heightTypeBox.val(),
  9547. padding = paddingBox.val(),
  9548. spacing = spacingBox.val(),
  9549. textAlign = textAlignBox.val(),
  9550. verticalAlign = verticalAlignBox.val(),
  9551. border = borderBox.val(),
  9552. borderColor = K(colorBox[0]).html() || '',
  9553. bgColor = K(colorBox[1]).html() || '';
  9554. if (!/^\d*$/.test(width)) {
  9555. alert(self.lang('invalidWidth'));
  9556. widthBox[0].focus();
  9557. return;
  9558. }
  9559. if (!/^\d*$/.test(height)) {
  9560. alert(self.lang('invalidHeight'));
  9561. heightBox[0].focus();
  9562. return;
  9563. }
  9564. if (!/^\d*$/.test(border)) {
  9565. alert(self.lang('invalidBorder'));
  9566. borderBox[0].focus();
  9567. return;
  9568. }
  9569. cell.css({
  9570. width : width !== '' ? (width + widthType) : '',
  9571. height : height !== '' ? (height + heightType) : '',
  9572. 'background-color' : bgColor,
  9573. 'text-align' : textAlign,
  9574. 'vertical-align' : verticalAlign,
  9575. 'border-width' : border,
  9576. 'border-style' : border !== '' ? 'solid' : '',
  9577. 'border-color' : borderColor
  9578. });
  9579. self.hideDialog().focus();
  9580. self.cmd.range.moveToBookmark(bookmark);
  9581. self.cmd.select();
  9582. self.addBookmark();
  9583. }
  9584. }
  9585. }),
  9586. div = dialog.div,
  9587. widthBox = K('[name="width"]', div).val(100),
  9588. heightBox = K('[name="height"]', div),
  9589. widthTypeBox = K('[name="widthType"]', div),
  9590. heightTypeBox = K('[name="heightType"]', div),
  9591. paddingBox = K('[name="padding"]', div).val(2),
  9592. spacingBox = K('[name="spacing"]', div).val(0),
  9593. textAlignBox = K('[name="textAlign"]', div),
  9594. verticalAlignBox = K('[name="verticalAlign"]', div),
  9595. borderBox = K('[name="border"]', div).val(1),
  9596. colorBox = K('.ke-input-color', div);
  9597. _initColorPicker(div, colorBox.eq(0));
  9598. _initColorPicker(div, colorBox.eq(1));
  9599. _setColor(colorBox.eq(0), '#000000');
  9600. _setColor(colorBox.eq(1), '');
  9601. // foucs and select
  9602. widthBox[0].focus();
  9603. widthBox[0].select();
  9604. // get selected cell
  9605. var cell = self.plugin.getSelectedCell();
  9606. var match,
  9607. cellWidth = cell[0].style.width || cell[0].width || '',
  9608. cellHeight = cell[0].style.height || cell[0].height || '';
  9609. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9610. widthBox.val(match[1]);
  9611. widthTypeBox.val(match[2]);
  9612. } else {
  9613. widthBox.val('');
  9614. }
  9615. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9616. heightBox.val(match[1]);
  9617. heightTypeBox.val(match[2]);
  9618. }
  9619. textAlignBox.val(cell[0].style.textAlign || '');
  9620. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9621. var border = cell[0].style.borderWidth || '';
  9622. if (border) {
  9623. border = parseInt(border);
  9624. }
  9625. borderBox.val(border);
  9626. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9627. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9628. widthBox[0].focus();
  9629. widthBox[0].select();
  9630. },
  9631. insert : function() {
  9632. this.prop(true);
  9633. },
  9634. 'delete' : function() {
  9635. var table = self.plugin.getSelectedTable();
  9636. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9637. self.cmd.select();
  9638. table.remove();
  9639. self.addBookmark();
  9640. },
  9641. colinsert : function(offset) {
  9642. var table = self.plugin.getSelectedTable()[0],
  9643. row = self.plugin.getSelectedRow()[0],
  9644. cell = self.plugin.getSelectedCell()[0],
  9645. index = cell.cellIndex + offset;
  9646. // 取得第一行的index
  9647. index += table.rows[0].cells.length - row.cells.length;
  9648. for (var i = 0, len = table.rows.length; i < len; i++) {
  9649. var newRow = table.rows[i],
  9650. newCell = newRow.insertCell(index);
  9651. newCell.innerHTML = K.IE ? '' : '<br />';
  9652. // 调整下一行的单元格index
  9653. index = _getCellIndex(table, newRow, newCell);
  9654. }
  9655. self.cmd.range.selectNodeContents(cell).collapse(true);
  9656. self.cmd.select();
  9657. self.addBookmark();
  9658. },
  9659. colinsertleft : function() {
  9660. this.colinsert(0);
  9661. },
  9662. colinsertright : function() {
  9663. this.colinsert(1);
  9664. },
  9665. rowinsert : function(offset) {
  9666. var table = self.plugin.getSelectedTable()[0],
  9667. row = self.plugin.getSelectedRow()[0],
  9668. cell = self.plugin.getSelectedCell()[0];
  9669. var rowIndex = row.rowIndex;
  9670. if (offset === 1) {
  9671. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9672. }
  9673. var newRow = table.insertRow(rowIndex);
  9674. for (var i = 0, len = row.cells.length; i < len; i++) {
  9675. // 调整cell个数
  9676. if (row.cells[i].rowSpan > 1) {
  9677. len -= row.cells[i].rowSpan - 1;
  9678. }
  9679. var newCell = newRow.insertCell(i);
  9680. // copy colspan
  9681. if (offset === 1 && row.cells[i].colSpan > 1) {
  9682. newCell.colSpan = row.cells[i].colSpan;
  9683. }
  9684. newCell.innerHTML = K.IE ? '' : '<br />';
  9685. }
  9686. // 调整rowspan
  9687. for (var j = rowIndex; j >= 0; j--) {
  9688. var cells = table.rows[j].cells;
  9689. if (cells.length > i) {
  9690. for (var k = cell.cellIndex; k >= 0; k--) {
  9691. if (cells[k].rowSpan > 1) {
  9692. cells[k].rowSpan += 1;
  9693. }
  9694. }
  9695. break;
  9696. }
  9697. }
  9698. self.cmd.range.selectNodeContents(cell).collapse(true);
  9699. self.cmd.select();
  9700. self.addBookmark();
  9701. },
  9702. rowinsertabove : function() {
  9703. this.rowinsert(0);
  9704. },
  9705. rowinsertbelow : function() {
  9706. this.rowinsert(1);
  9707. },
  9708. rowmerge : function() {
  9709. var table = self.plugin.getSelectedTable()[0],
  9710. row = self.plugin.getSelectedRow()[0],
  9711. cell = self.plugin.getSelectedCell()[0],
  9712. rowIndex = row.rowIndex, // 当前行的index
  9713. nextRowIndex = rowIndex + cell.rowSpan, // 下一行的index
  9714. nextRow = table.rows[nextRowIndex]; // 下一行
  9715. // 最后一行不能合并
  9716. if (table.rows.length <= nextRowIndex) {
  9717. return;
  9718. }
  9719. var cellIndex = cell.cellIndex; // 下一行单元格的index
  9720. if (nextRow.cells.length <= cellIndex) {
  9721. return;
  9722. }
  9723. var nextCell = nextRow.cells[cellIndex]; // 下一行单元格
  9724. // 上下行的colspan不一致时不能合并
  9725. if (cell.colSpan !== nextCell.colSpan) {
  9726. return;
  9727. }
  9728. cell.rowSpan += nextCell.rowSpan;
  9729. nextRow.deleteCell(cellIndex);
  9730. self.cmd.range.selectNodeContents(cell).collapse(true);
  9731. self.cmd.select();
  9732. self.addBookmark();
  9733. },
  9734. colmerge : function() {
  9735. var table = self.plugin.getSelectedTable()[0],
  9736. row = self.plugin.getSelectedRow()[0],
  9737. cell = self.plugin.getSelectedCell()[0],
  9738. rowIndex = row.rowIndex, // 当前行的index
  9739. cellIndex = cell.cellIndex,
  9740. nextCellIndex = cellIndex + 1;
  9741. // 最后一列不能合并
  9742. if (row.cells.length <= nextCellIndex) {
  9743. return;
  9744. }
  9745. var nextCell = row.cells[nextCellIndex];
  9746. // 左右列的rowspan不一致时不能合并
  9747. if (cell.rowSpan !== nextCell.rowSpan) {
  9748. return;
  9749. }
  9750. cell.colSpan += nextCell.colSpan;
  9751. row.deleteCell(nextCellIndex);
  9752. self.cmd.range.selectNodeContents(cell).collapse(true);
  9753. self.cmd.select();
  9754. self.addBookmark();
  9755. },
  9756. rowsplit : function() {
  9757. var table = self.plugin.getSelectedTable()[0],
  9758. row = self.plugin.getSelectedRow()[0],
  9759. cell = self.plugin.getSelectedCell()[0],
  9760. rowIndex = row.rowIndex;
  9761. // 不是可分割单元格
  9762. if (cell.rowSpan === 1) {
  9763. return;
  9764. }
  9765. var cellIndex = _getCellIndex(table, row, cell);
  9766. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9767. var newRow = table.rows[rowIndex + i],
  9768. newCell = newRow.insertCell(cellIndex);
  9769. if (cell.colSpan > 1) {
  9770. newCell.colSpan = cell.colSpan;
  9771. }
  9772. newCell.innerHTML = K.IE ? '' : '<br />';
  9773. // 调整下一行的单元格index
  9774. cellIndex = _getCellIndex(table, newRow, newCell);
  9775. }
  9776. K(cell).removeAttr('rowSpan');
  9777. self.cmd.range.selectNodeContents(cell).collapse(true);
  9778. self.cmd.select();
  9779. self.addBookmark();
  9780. },
  9781. colsplit : function() {
  9782. var table = self.plugin.getSelectedTable()[0],
  9783. row = self.plugin.getSelectedRow()[0],
  9784. cell = self.plugin.getSelectedCell()[0],
  9785. cellIndex = cell.cellIndex;
  9786. // 不是可分割单元格
  9787. if (cell.colSpan === 1) {
  9788. return;
  9789. }
  9790. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9791. var newCell = row.insertCell(cellIndex + i);
  9792. if (cell.rowSpan > 1) {
  9793. newCell.rowSpan = cell.rowSpan;
  9794. }
  9795. newCell.innerHTML = K.IE ? '' : '<br />';
  9796. }
  9797. K(cell).removeAttr('colSpan');
  9798. self.cmd.range.selectNodeContents(cell).collapse(true);
  9799. self.cmd.select();
  9800. self.addBookmark();
  9801. },
  9802. coldelete : function() {
  9803. var table = self.plugin.getSelectedTable()[0],
  9804. row = self.plugin.getSelectedRow()[0],
  9805. cell = self.plugin.getSelectedCell()[0],
  9806. index = cell.cellIndex;
  9807. for (var i = 0, len = table.rows.length; i < len; i++) {
  9808. var newRow = table.rows[i],
  9809. newCell = newRow.cells[index];
  9810. if (newCell.colSpan > 1) {
  9811. newCell.colSpan -= 1;
  9812. if (newCell.colSpan === 1) {
  9813. K(newCell).removeAttr('colSpan');
  9814. }
  9815. } else {
  9816. newRow.deleteCell(index);
  9817. }
  9818. // 跳过不需要删除的行
  9819. if (newCell.rowSpan > 1) {
  9820. i += newCell.rowSpan - 1;
  9821. }
  9822. }
  9823. if (row.cells.length === 0) {
  9824. self.cmd.range.setStartBefore(table).collapse(true);
  9825. self.cmd.select();
  9826. K(table).remove();
  9827. } else {
  9828. self.cmd.selection(true);
  9829. }
  9830. self.addBookmark();
  9831. },
  9832. rowdelete : function() {
  9833. var table = self.plugin.getSelectedTable()[0],
  9834. row = self.plugin.getSelectedRow()[0],
  9835. cell = self.plugin.getSelectedCell()[0],
  9836. rowIndex = row.rowIndex;
  9837. // 从下到上删除
  9838. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9839. table.deleteRow(rowIndex + i);
  9840. }
  9841. if (table.rows.length === 0) {
  9842. self.cmd.range.setStartBefore(table).collapse(true);
  9843. self.cmd.select();
  9844. K(table).remove();
  9845. } else {
  9846. self.cmd.selection(true);
  9847. }
  9848. self.addBookmark();
  9849. }
  9850. };
  9851. self.clickToolbar(name, self.plugin.table.prop);
  9852. });
  9853. /*******************************************************************************
  9854. * KindEditor - WYSIWYG HTML Editor for Internet
  9855. * Copyright (C) 2006-2011 kindsoft.net
  9856. *
  9857. * @author Roddy <luolonghao@gmail.com>
  9858. * @site http://www.kindsoft.net/
  9859. * @licence http://www.kindsoft.net/license.php
  9860. *******************************************************************************/
  9861. KindEditor.plugin('template', function(K) {
  9862. var self = this, name = 'template', lang = self.lang(name + '.'),
  9863. htmlPath = self.pluginsPath + name + '/html/';
  9864. function getFilePath(fileName) {
  9865. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9866. }
  9867. self.clickToolbar(name, function() {
  9868. var lang = self.lang(name + '.'),
  9869. arr = ['<div style="padding:10px 20px;">',
  9870. '<div class="ke-header">',
  9871. // left start
  9872. '<div class="ke-left">',
  9873. lang. selectTemplate + ' <select>'];
  9874. K.each(lang.fileList, function(key, val) {
  9875. arr.push('<option value="' + key + '">' + val + '</option>');
  9876. });
  9877. html = [arr.join(''),
  9878. '</select></div>',
  9879. // right start
  9880. '<div class="ke-right">',
  9881. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9882. '</div>',
  9883. '<div class="ke-clearfix"></div>',
  9884. '</div>',
  9885. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9886. '</div>'].join('');
  9887. var dialog = self.createDialog({
  9888. name : name,
  9889. width : 500,
  9890. title : self.lang(name),
  9891. body : html,
  9892. yesBtn : {
  9893. name : self.lang('yes'),
  9894. click : function(e) {
  9895. var doc = K.iframeDoc(iframe);
  9896. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9897. }
  9898. }
  9899. });
  9900. var selectBox = K('select', dialog.div),
  9901. checkbox = K('[name="replaceFlag"]', dialog.div),
  9902. iframe = K('iframe', dialog.div);
  9903. checkbox[0].checked = true;
  9904. iframe.attr('src', getFilePath(selectBox.val()));
  9905. selectBox.change(function() {
  9906. iframe.attr('src', getFilePath(this.value));
  9907. });
  9908. });
  9909. });
  9910. /*******************************************************************************
  9911. * KindEditor - WYSIWYG HTML Editor for Internet
  9912. * Copyright (C) 2006-2011 kindsoft.net
  9913. *
  9914. * @author Roddy <luolonghao@gmail.com>
  9915. * @site http://www.kindsoft.net/
  9916. * @licence http://www.kindsoft.net/license.php
  9917. *******************************************************************************/
  9918. KindEditor.plugin('wordpaste', function(K) {
  9919. var self = this, name = 'wordpaste';
  9920. self.clickToolbar(name, function() {
  9921. var lang = self.lang(name + '.'),
  9922. html = '<div style="padding:10px 20px;">' +
  9923. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9924. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9925. '</div>',
  9926. dialog = self.createDialog({
  9927. name : name,
  9928. width : 450,
  9929. title : self.lang(name),
  9930. body : html,
  9931. yesBtn : {
  9932. name : self.lang('yes'),
  9933. click : function(e) {
  9934. var str = doc.body.innerHTML;
  9935. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9936. self.insertHtml(str).hideDialog().focus();
  9937. }
  9938. }
  9939. }),
  9940. div = dialog.div,
  9941. iframe = K('iframe', div),
  9942. doc = K.iframeDoc(iframe);
  9943. if (!K.IE) {
  9944. doc.designMode = 'on';
  9945. }
  9946. doc.open();
  9947. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9948. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9949. if (!K.IE) {
  9950. doc.write('<br />');
  9951. }
  9952. doc.write('</body></html>');
  9953. doc.close();
  9954. if (K.IE) {
  9955. doc.body.contentEditable = 'true';
  9956. }
  9957. iframe[0].contentWindow.focus();
  9958. });
  9959. });