kindeditor-all.js 310 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514
  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,video,audio'),
  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 : 'simple',
  240. langType : 'zh_CN',
  241. urlType : '',
  242. newlineTag : 'p',
  243. resizeType : 1,
  244. syncType : 'form',
  245. pasteType : 2,
  246. dialogAlignType : 'page',
  247. useContextmenu : true,
  248. fullscreenShortcut : false,
  249. bodyClass : 'ke-content typo',
  250. indentChar : '\t',
  251. cssPath : K.basePath + '../../../styles/typo.css',
  252. cssData : '',
  253. width:'90%',
  254. minWidth : 520,
  255. minHeight : 500,
  256. minChangeSize : 50,
  257. zIndex : 9000000,
  258. allowImageUpload : true,
  259. allowFlashUpload : true,
  260. allowMediaUpload : true,
  261. allowFileUpload : true,
  262. prefixStaticUrl:'',
  263. items : [
  264. 'source', '|',
  265. 'undo', 'redo', '|',
  266. 'code', 'cut', 'copy', 'paste','plainpaste', 'wordpaste', '|',
  267. 'justifyleft', 'justifycenter', 'justifyright','insertorderedlist', 'insertunorderedlist',
  268. 'indent', 'outdent', 'subscript','superscript',
  269. 'formatblock', 'fontname', 'fontsize', '|',
  270. 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough','removeformat', '|',
  271. 'image','media','table', 'hr', 'pagebreak', 'anchor', 'link', 'unlink', '|',
  272. 'clearhtml', 'quickformat',
  273. ],
  274. // items : [
  275. // 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  276. // 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  277. // 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  278. // 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  279. // 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  280. // 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  281. // 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  282. // 'anchor', 'link', 'unlink', '|', 'about'
  283. // ],
  284. noDisableItems : ['source', 'fullscreen'],
  285. colorTable : [
  286. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  287. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  288. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  289. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  290. ],
  291. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  292. htmlTags : {
  293. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  294. span : [
  295. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  296. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  297. ],
  298. div : [
  299. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  300. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  301. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  302. ],
  303. table: [
  304. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  305. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  306. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  307. '.width', '.height', '.border-collapse'
  308. ],
  309. 'td,th': [
  310. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  311. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  312. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  313. ],
  314. a : ['id', 'class', 'href', 'target', 'name'],
  315. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  316. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border', 'eventdata', 'onclick'],
  317. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  318. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  319. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  320. ],
  321. video:['id','class','src','width','height','controls','autobuffer','autoplay','loop','muted','poster','preload','onplaying','eventdata','onclick'],
  322. audio:['id','class','src','width','height','controls','autobuffer','autoplay','loop','muted','poster','preload','onplaying','eventdata','onclick'],
  323. pre : ['id', 'class'],
  324. hr : ['id', 'class', '.page-break-after'],
  325. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  326. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height'],
  327. input: ['type', 'value', 'onclick', 'class'],
  328. button: ['class', 'onclick']
  329. },
  330. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  331. };
  332. var _useCapture = false;
  333. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  334. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  335. var _CHANGE_KEY_MAP = {};
  336. _each(_INPUT_KEY_MAP, function(key, val) {
  337. _CHANGE_KEY_MAP[key] = val;
  338. });
  339. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  340. _CHANGE_KEY_MAP[key] = val;
  341. });
  342. function _bindEvent(el, type, fn) {
  343. if (el.addEventListener){
  344. el.addEventListener(type, fn, _useCapture);
  345. } else if (el.attachEvent){
  346. el.attachEvent('on' + type, fn);
  347. }
  348. }
  349. function _unbindEvent(el, type, fn) {
  350. if (el.removeEventListener){
  351. el.removeEventListener(type, fn, _useCapture);
  352. } else if (el.detachEvent){
  353. el.detachEvent('on' + type, fn);
  354. }
  355. }
  356. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  357. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  358. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  359. function KEvent(el, event) {
  360. this.init(el, event);
  361. }
  362. _extend(KEvent, {
  363. init : function(el, event) {
  364. var self = this, doc = el.ownerDocument || el.document || el;
  365. self.event = event;
  366. _each(_EVENT_PROPS, function(key, val) {
  367. self[val] = event[val];
  368. });
  369. if (!self.target) {
  370. self.target = self.srcElement || doc;
  371. }
  372. if (self.target.nodeType === 3) {
  373. self.target = self.target.parentNode;
  374. }
  375. if (!self.relatedTarget && self.fromElement) {
  376. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  377. }
  378. if (self.pageX == null && self.clientX != null) {
  379. var d = doc.documentElement, body = doc.body;
  380. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  381. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  382. }
  383. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  384. self.which = self.charCode || self.keyCode;
  385. }
  386. if (!self.metaKey && self.ctrlKey) {
  387. self.metaKey = self.ctrlKey;
  388. }
  389. if (!self.which && self.button !== undefined) {
  390. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  391. }
  392. switch (self.which) {
  393. case 186 :
  394. self.which = 59;
  395. break;
  396. case 187 :
  397. case 107 :
  398. case 43 :
  399. self.which = 61;
  400. break;
  401. case 189 :
  402. case 45 :
  403. self.which = 109;
  404. break;
  405. case 42 :
  406. self.which = 106;
  407. break;
  408. case 47 :
  409. self.which = 111;
  410. break;
  411. case 78 :
  412. self.which = 110;
  413. break;
  414. }
  415. if (self.which >= 96 && self.which <= 105) {
  416. self.which -= 48;
  417. }
  418. },
  419. preventDefault : function() {
  420. var ev = this.event;
  421. if (ev.preventDefault) {
  422. ev.preventDefault();
  423. } else {
  424. ev.returnValue = false;
  425. }
  426. },
  427. stopPropagation : function() {
  428. var ev = this.event;
  429. if (ev.stopPropagation) {
  430. ev.stopPropagation();
  431. } else {
  432. ev.cancelBubble = true;
  433. }
  434. },
  435. stop : function() {
  436. this.preventDefault();
  437. this.stopPropagation();
  438. }
  439. });
  440. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  441. function _getId(el) {
  442. return el[_eventExpendo] || null;
  443. }
  444. function _setId(el) {
  445. el[_eventExpendo] = ++_eventId;
  446. return _eventId;
  447. }
  448. function _removeId(el) {
  449. try {
  450. delete el[_eventExpendo];
  451. } catch(e) {
  452. if (el.removeAttribute) {
  453. el.removeAttribute(_eventExpendo);
  454. }
  455. }
  456. }
  457. function _bind(el, type, fn) {
  458. if (type.indexOf(',') >= 0) {
  459. _each(type.split(','), function() {
  460. _bind(el, this, fn);
  461. });
  462. return;
  463. }
  464. var id = _getId(el);
  465. if (!id) {
  466. id = _setId(el);
  467. }
  468. if (_eventData[id] === undefined) {
  469. _eventData[id] = {};
  470. }
  471. var events = _eventData[id][type];
  472. if (events && events.length > 0) {
  473. _unbindEvent(el, type, events[0]);
  474. } else {
  475. _eventData[id][type] = [];
  476. _eventData[id].el = el;
  477. }
  478. events = _eventData[id][type];
  479. if (events.length === 0) {
  480. events[0] = function(e) {
  481. var kevent = e ? new KEvent(el, e) : undefined;
  482. _each(events, function(i, event) {
  483. if (i > 0 && event) {
  484. event.call(el, kevent);
  485. }
  486. });
  487. };
  488. }
  489. if (_inArray(fn, events) < 0) {
  490. events.push(fn);
  491. }
  492. _bindEvent(el, type, events[0]);
  493. }
  494. function _unbind(el, type, fn) {
  495. if (type && type.indexOf(',') >= 0) {
  496. _each(type.split(','), function() {
  497. _unbind(el, this, fn);
  498. });
  499. return;
  500. }
  501. var id = _getId(el);
  502. if (!id) {
  503. return;
  504. }
  505. if (type === undefined) {
  506. if (id in _eventData) {
  507. _each(_eventData[id], function(key, events) {
  508. if (key != 'el' && events.length > 0) {
  509. _unbindEvent(el, key, events[0]);
  510. }
  511. });
  512. delete _eventData[id];
  513. _removeId(el);
  514. }
  515. return;
  516. }
  517. if (!_eventData[id]) {
  518. return;
  519. }
  520. var events = _eventData[id][type];
  521. if (events && events.length > 0) {
  522. if (fn === undefined) {
  523. _unbindEvent(el, type, events[0]);
  524. delete _eventData[id][type];
  525. } else {
  526. _each(events, function(i, event) {
  527. if (i > 0 && event === fn) {
  528. events.splice(i, 1);
  529. }
  530. });
  531. if (events.length == 1) {
  532. _unbindEvent(el, type, events[0]);
  533. delete _eventData[id][type];
  534. }
  535. }
  536. var count = 0;
  537. _each(_eventData[id], function() {
  538. count++;
  539. });
  540. if (count < 2) {
  541. delete _eventData[id];
  542. _removeId(el);
  543. }
  544. }
  545. }
  546. function _fire(el, type) {
  547. if (type.indexOf(',') >= 0) {
  548. _each(type.split(','), function() {
  549. _fire(el, this);
  550. });
  551. return;
  552. }
  553. var id = _getId(el);
  554. if (!id) {
  555. return;
  556. }
  557. var events = _eventData[id][type];
  558. if (_eventData[id] && events && events.length > 0) {
  559. events[0]();
  560. }
  561. }
  562. function _ctrl(el, key, fn) {
  563. var self = this;
  564. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  565. _bind(el, 'keydown', function(e) {
  566. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  567. fn.call(el);
  568. e.stop();
  569. }
  570. });
  571. }
  572. var _readyFinished = false;
  573. function _ready(fn) {
  574. if (_readyFinished) {
  575. fn(KindEditor);
  576. return;
  577. }
  578. var loaded = false;
  579. function readyFunc() {
  580. if (!loaded) {
  581. loaded = true;
  582. fn(KindEditor);
  583. _readyFinished = true;
  584. }
  585. }
  586. function ieReadyFunc() {
  587. if (!loaded) {
  588. try {
  589. document.documentElement.doScroll('left');
  590. } catch(e) {
  591. setTimeout(ieReadyFunc, 100);
  592. return;
  593. }
  594. readyFunc();
  595. }
  596. }
  597. function ieReadyStateFunc() {
  598. if (document.readyState === 'complete') {
  599. readyFunc();
  600. }
  601. }
  602. if (document.addEventListener) {
  603. _bind(document, 'DOMContentLoaded', readyFunc);
  604. } else if (document.attachEvent) {
  605. _bind(document, 'readystatechange', ieReadyStateFunc);
  606. var toplevel = false;
  607. try {
  608. toplevel = window.frameElement == null;
  609. } catch(e) {}
  610. if (document.documentElement.doScroll && toplevel) {
  611. ieReadyFunc();
  612. }
  613. }
  614. _bind(window, 'load', readyFunc);
  615. }
  616. if (_IE) {
  617. window.attachEvent('onunload', function() {
  618. _each(_eventData, function(key, events) {
  619. if (events.el) {
  620. _unbind(events.el);
  621. }
  622. });
  623. });
  624. }
  625. K.ctrl = _ctrl;
  626. K.ready = _ready;
  627. function _getCssList(css) {
  628. var list = {},
  629. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  630. match;
  631. while ((match = reg.exec(css))) {
  632. var key = _trim(match[1].toLowerCase()),
  633. val = _trim(_toHex(match[2]));
  634. list[key] = val;
  635. }
  636. return list;
  637. }
  638. function _getAttrList(tag) {
  639. var list = {},
  640. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  641. match;
  642. while ((match = reg.exec(tag))) {
  643. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  644. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  645. list[key] = val;
  646. }
  647. return list;
  648. }
  649. function _addClassToTag(tag, className) {
  650. if (/\s+class\s*=/.test(tag)) {
  651. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  652. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  653. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  654. } else {
  655. return $0;
  656. }
  657. });
  658. } else {
  659. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  660. }
  661. return tag;
  662. }
  663. function _formatCss(css) {
  664. var str = '';
  665. _each(_getCssList(css), function(key, val) {
  666. str += key + ':' + val + ';';
  667. });
  668. return str;
  669. }
  670. function _formatUrl(url, mode, host, pathname) {
  671. mode = _undef(mode, '').toLowerCase();
  672. if (url.substr(0, 5) != 'data:') {
  673. url = url.replace(/([^:])\/\//g, '$1/');
  674. }
  675. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  676. return url;
  677. }
  678. host = host || location.protocol + '//' + location.host;
  679. if (pathname === undefined) {
  680. var m = location.pathname.match(/^(\/.*)\//);
  681. pathname = m ? m[1] : '';
  682. }
  683. var match;
  684. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  685. if (match[1] !== host) {
  686. return url;
  687. }
  688. } else if (/^\w+:/.test(url)) {
  689. return url;
  690. }
  691. function getRealPath(path) {
  692. var parts = path.split('/'), paths = [];
  693. for (var i = 0, len = parts.length; i < len; i++) {
  694. var part = parts[i];
  695. if (part == '..') {
  696. if (paths.length > 0) {
  697. paths.pop();
  698. }
  699. } else if (part !== '' && part != '.') {
  700. paths.push(part);
  701. }
  702. }
  703. return '/' + paths.join('/');
  704. }
  705. if (/^\//.test(url)) {
  706. url = host + getRealPath(url.substr(1));
  707. } else if (!/^\w+:\/\//.test(url)) {
  708. url = host + getRealPath(pathname + '/' + url);
  709. }
  710. function getRelativePath(path, depth) {
  711. if (url.substr(0, path.length) === path) {
  712. var arr = [];
  713. for (var i = 0; i < depth; i++) {
  714. arr.push('..');
  715. }
  716. var prefix = '.';
  717. if (arr.length > 0) {
  718. prefix += '/' + arr.join('/');
  719. }
  720. if (pathname == '/') {
  721. prefix += '/';
  722. }
  723. return prefix + url.substr(path.length);
  724. } else {
  725. if ((match = /^(.*)\//.exec(path))) {
  726. return getRelativePath(match[1], ++depth);
  727. }
  728. }
  729. }
  730. if (mode === 'relative') {
  731. url = getRelativePath(host + pathname, 0).substr(2);
  732. } else if (mode === 'absolute') {
  733. if (url.substr(0, host.length) === host) {
  734. url = url.substr(host.length);
  735. }
  736. }
  737. return url;
  738. }
  739. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  740. if (html == null) {
  741. html = '';
  742. }
  743. urlType = urlType || '';
  744. wellFormatted = _undef(wellFormatted, false);
  745. indentChar = _undef(indentChar, '\t');
  746. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  747. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  748. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  749. });
  750. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  751. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  752. html = html.replace(/\u200B/g, '');
  753. html = html.replace(/\u00A9/g, '&copy;');
  754. html = html.replace(/\u00AE/g, '&reg;');
  755. html = html.replace(/<[^>]+/g, function($0) {
  756. return $0.replace(/\s+/g, ' ');
  757. });
  758. var htmlTagMap = {};
  759. if (htmlTags) {
  760. _each(htmlTags, function(key, val) {
  761. var arr = key.split(',');
  762. for (var i = 0, len = arr.length; i < len; i++) {
  763. htmlTagMap[arr[i]] = _toMap(val);
  764. }
  765. });
  766. if (!htmlTagMap.script) {
  767. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  768. }
  769. if (!htmlTagMap.style) {
  770. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  771. }
  772. }
  773. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  774. var tagStack = [];
  775. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  776. var full = $0,
  777. startNewline = $1 || '',
  778. startSlash = $2 || '',
  779. tagName = $3.toLowerCase(),
  780. attr = $4 || '',
  781. endSlash = $5 ? ' ' + $5 : '',
  782. endNewline = $6 || '';
  783. if (htmlTags && !htmlTagMap[tagName]) {
  784. return '';
  785. }
  786. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  787. endSlash = ' /';
  788. }
  789. if (_INLINE_TAG_MAP[tagName]) {
  790. if (startNewline) {
  791. startNewline = ' ';
  792. }
  793. if (endNewline) {
  794. endNewline = ' ';
  795. }
  796. }
  797. if (_PRE_TAG_MAP[tagName]) {
  798. if (startSlash) {
  799. endNewline = '\n';
  800. } else {
  801. startNewline = '\n';
  802. }
  803. }
  804. if (wellFormatted && tagName == 'br') {
  805. endNewline = '\n';
  806. }
  807. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  808. if (wellFormatted) {
  809. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  810. tagStack.pop();
  811. } else {
  812. tagStack.push(tagName);
  813. }
  814. startNewline = '\n';
  815. endNewline = '\n';
  816. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  817. startNewline += indentChar;
  818. if (!startSlash) {
  819. endNewline += indentChar;
  820. }
  821. }
  822. if (endSlash) {
  823. tagStack.pop();
  824. } else if (!startSlash) {
  825. endNewline += indentChar;
  826. }
  827. } else {
  828. startNewline = endNewline = '';
  829. }
  830. }
  831. if (attr !== '') {
  832. var attrMap = _getAttrList(full);
  833. if (tagName === 'font') {
  834. var fontStyleMap = {}, fontStyle = '';
  835. _each(attrMap, function(key, val) {
  836. if (key === 'color') {
  837. fontStyleMap.color = val;
  838. delete attrMap[key];
  839. }
  840. if (key === 'size') {
  841. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  842. delete attrMap[key];
  843. }
  844. if (key === 'face') {
  845. fontStyleMap['font-family'] = val;
  846. delete attrMap[key];
  847. }
  848. if (key === 'style') {
  849. fontStyle = val;
  850. }
  851. });
  852. if (fontStyle && !/;$/.test(fontStyle)) {
  853. fontStyle += ';';
  854. }
  855. _each(fontStyleMap, function(key, val) {
  856. if (val === '') {
  857. return;
  858. }
  859. if (/\s/.test(val)) {
  860. val = "'" + val + "'";
  861. }
  862. fontStyle += key + ':' + val + ';';
  863. });
  864. attrMap.style = fontStyle;
  865. }
  866. _each(attrMap, function(key, val) {
  867. if (_FILL_ATTR_MAP[key]) {
  868. attrMap[key] = key;
  869. }
  870. if (_inArray(key, ['src', 'href']) >= 0) {
  871. attrMap[key] = _formatUrl(val, urlType);
  872. }
  873. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  874. tagName === 'body' && key === 'contenteditable' ||
  875. /^kindeditor_\d+$/.test(key)) {
  876. delete attrMap[key];
  877. }
  878. if (key === 'style' && val !== '') {
  879. var styleMap = _getCssList(val);
  880. _each(styleMap, function(k, v) {
  881. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  882. delete styleMap[k];
  883. }
  884. });
  885. var style = '';
  886. _each(styleMap, function(k, v) {
  887. style += k + ':' + v + ';';
  888. });
  889. attrMap.style = style;
  890. }
  891. });
  892. attr = '';
  893. _each(attrMap, function(key, val) {
  894. if (key === 'style' && val === '') {
  895. return;
  896. }
  897. val = val.replace(/"/g, '&quot;');
  898. attr += ' ' + key + '="' + val + '"';
  899. });
  900. }
  901. if (tagName === 'font') {
  902. tagName = 'span';
  903. }
  904. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  905. });
  906. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  907. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  908. });
  909. html = html.replace(/\n\s*\n/g, '\n');
  910. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  911. return _trim(html);
  912. }
  913. function _clearMsWord(html, htmlTags) {
  914. html = html.replace(/<meta[\s\S]*?>/ig, '')
  915. .replace(/<![\s\S]*?>/ig, '')
  916. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  917. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  918. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  919. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  920. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  921. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  922. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  923. });
  924. return _formatHtml(html, htmlTags);
  925. }
  926. function _mediaType(src) {
  927. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  928. return 'audio/x-pn-realaudio-plugin';
  929. }
  930. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  931. return 'application/x-shockwave-flash';
  932. }
  933. return 'video/x-ms-asf-plugin';
  934. }
  935. function _mediaClass(type) {
  936. if (/realaudio/i.test(type)) {
  937. return 'ke-rm';
  938. }
  939. if (/flash/i.test(type)) {
  940. return 'ke-flash';
  941. }
  942. return 'ke-media';
  943. }
  944. function _mediaAttrs(srcTag) {
  945. return _getAttrList(unescape(srcTag));
  946. }
  947. function _mediaEmbed(attrs) {
  948. var html = '<embed ';
  949. _each(attrs, function(key, val) {
  950. html += key + '="' + val + '" ';
  951. });
  952. html += '/>';
  953. return html;
  954. }
  955. function _mediaVideo(attrs){
  956. var html = '<video ';
  957. _each(attrs, function(key, val) {
  958. html += key + '="' + val + '" ';
  959. });
  960. html += ' controls autobuffer></video>';
  961. return html;
  962. }
  963. function _mediaImg(blankPath, attrs) {
  964. var width = attrs.width,
  965. height = attrs.height,
  966. type = attrs.type || _mediaType(attrs.src),
  967. srcTag = _mediaEmbed(attrs),
  968. style = '';
  969. if (/\D/.test(width)) {
  970. style += 'width:' + width + ';';
  971. } else if (width > 0) {
  972. style += 'width:' + width + 'px;';
  973. }
  974. if (/\D/.test(height)) {
  975. style += 'height:' + height + ';';
  976. } else if (height > 0) {
  977. style += 'height:' + height + 'px;';
  978. }
  979. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  980. if (style !== '') {
  981. html += 'style="' + style + '" ';
  982. }
  983. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  984. return html;
  985. }
  986. function _tmpl(str, data) {
  987. var fn = new Function("obj",
  988. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  989. "with(obj){p.push('" +
  990. str.replace(/[\r\t\n]/g, " ")
  991. .split("<%").join("\t")
  992. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  993. .replace(/\t=(.*?)%>/g, "',$1,'")
  994. .split("\t").join("');")
  995. .split("%>").join("p.push('")
  996. .split("\r").join("\\'") + "');}return p.join('');");
  997. return data ? fn(data) : fn;
  998. }
  999. K.formatUrl = _formatUrl;
  1000. K.formatHtml = _formatHtml;
  1001. K.getCssList = _getCssList;
  1002. K.getAttrList = _getAttrList;
  1003. K.mediaType = _mediaType;
  1004. K.mediaAttrs = _mediaAttrs;
  1005. K.mediaEmbed = _mediaEmbed;
  1006. K.mediaImg = _mediaImg;
  1007. K.clearMsWord = _clearMsWord;
  1008. K.tmpl = _tmpl;
  1009. function _contains(nodeA, nodeB) {
  1010. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  1011. return true;
  1012. }
  1013. while ((nodeB = nodeB.parentNode)) {
  1014. if (nodeB == nodeA) {
  1015. return true;
  1016. }
  1017. }
  1018. return false;
  1019. }
  1020. var _getSetAttrDiv = document.createElement('div');
  1021. _getSetAttrDiv.setAttribute('className', 't');
  1022. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1023. function _getAttr(el, key) {
  1024. key = key.toLowerCase();
  1025. var val = null;
  1026. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1027. var div = el.ownerDocument.createElement('div');
  1028. div.appendChild(el.cloneNode(false));
  1029. var list = _getAttrList(_unescape(div.innerHTML));
  1030. if (key in list) {
  1031. val = list[key];
  1032. }
  1033. } else {
  1034. try {
  1035. val = el.getAttribute(key, 2);
  1036. } catch(e) {
  1037. val = el.getAttribute(key, 1);
  1038. }
  1039. }
  1040. if (key === 'style' && val !== null) {
  1041. val = _formatCss(val);
  1042. }
  1043. return val;
  1044. }
  1045. function _queryAll(expr, root) {
  1046. var exprList = expr.split(',');
  1047. if (exprList.length > 1) {
  1048. var mergedResults = [];
  1049. _each(exprList, function() {
  1050. _each(_queryAll(this, root), function() {
  1051. if (_inArray(this, mergedResults) < 0) {
  1052. mergedResults.push(this);
  1053. }
  1054. });
  1055. });
  1056. return mergedResults;
  1057. }
  1058. root = root || document;
  1059. function escape(str) {
  1060. if (typeof str != 'string') {
  1061. return str;
  1062. }
  1063. return str.replace(/([^\w\-])/g, '\\$1');
  1064. }
  1065. function stripslashes(str) {
  1066. return str.replace(/\\/g, '');
  1067. }
  1068. function cmpTag(tagA, tagB) {
  1069. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1070. }
  1071. function byId(id, tag, root) {
  1072. var arr = [],
  1073. doc = root.ownerDocument || root,
  1074. el = doc.getElementById(stripslashes(id));
  1075. if (el) {
  1076. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1077. arr.push(el);
  1078. }
  1079. }
  1080. return arr;
  1081. }
  1082. function byClass(className, tag, root) {
  1083. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1084. if (root.getElementsByClassName) {
  1085. els = root.getElementsByClassName(stripslashes(className));
  1086. for (i = 0, len = els.length; i < len; i++) {
  1087. el = els[i];
  1088. if (cmpTag(tag, el.nodeName)) {
  1089. arr.push(el);
  1090. }
  1091. }
  1092. } else if (doc.querySelectorAll) {
  1093. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1094. for (i = 0, len = els.length; i < len; i++) {
  1095. el = els[i];
  1096. if (_contains(root, el)) {
  1097. arr.push(el);
  1098. }
  1099. }
  1100. } else {
  1101. els = root.getElementsByTagName(tag);
  1102. className = ' ' + className + ' ';
  1103. for (i = 0, len = els.length; i < len; i++) {
  1104. el = els[i];
  1105. if (el.nodeType == 1) {
  1106. var cls = el.className;
  1107. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1108. arr.push(el);
  1109. }
  1110. }
  1111. }
  1112. }
  1113. return arr;
  1114. }
  1115. function byName(name, tag, root) {
  1116. var arr = [], doc = root.ownerDocument || root,
  1117. els = doc.getElementsByName(stripslashes(name)), el;
  1118. for (var i = 0, len = els.length; i < len; i++) {
  1119. el = els[i];
  1120. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1121. if (el.getAttribute('name') !== null) {
  1122. arr.push(el);
  1123. }
  1124. }
  1125. }
  1126. return arr;
  1127. }
  1128. function byAttr(key, val, tag, root) {
  1129. var arr = [], els = root.getElementsByTagName(tag), el;
  1130. for (var i = 0, len = els.length; i < len; i++) {
  1131. el = els[i];
  1132. if (el.nodeType == 1) {
  1133. if (val === null) {
  1134. if (_getAttr(el, key) !== null) {
  1135. arr.push(el);
  1136. }
  1137. } else {
  1138. if (val === escape(_getAttr(el, key))) {
  1139. arr.push(el);
  1140. }
  1141. }
  1142. }
  1143. }
  1144. return arr;
  1145. }
  1146. function select(expr, root) {
  1147. var arr = [], matches;
  1148. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1149. var tag = matches ? matches[1] : '*';
  1150. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1151. arr = byId(matches[1], tag, root);
  1152. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1153. arr = byClass(matches[1], tag, root);
  1154. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1155. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1156. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1157. var key = matches[1].toLowerCase(), val = matches[2];
  1158. if (key === 'id') {
  1159. arr = byId(val, tag, root);
  1160. } else if (key === 'class') {
  1161. arr = byClass(val, tag, root);
  1162. } else if (key === 'name') {
  1163. arr = byName(val, tag, root);
  1164. } else {
  1165. arr = byAttr(key, val, tag, root);
  1166. }
  1167. } else {
  1168. var els = root.getElementsByTagName(tag), el;
  1169. for (var i = 0, len = els.length; i < len; i++) {
  1170. el = els[i];
  1171. if (el.nodeType == 1) {
  1172. arr.push(el);
  1173. }
  1174. }
  1175. }
  1176. return arr;
  1177. }
  1178. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1179. while ((arr = re.exec(expr))) {
  1180. if (arr[1] !== ' ') {
  1181. parts.push(arr[1]);
  1182. }
  1183. }
  1184. var results = [];
  1185. if (parts.length == 1) {
  1186. return select(parts[0], root);
  1187. }
  1188. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1189. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1190. part = parts[i];
  1191. if (part === '>') {
  1192. isChild = true;
  1193. continue;
  1194. }
  1195. if (i > 0) {
  1196. els = [];
  1197. for (j = 0, len = results.length; j < len; j++) {
  1198. val = results[j];
  1199. subResults = select(part, val);
  1200. for (k = 0, l = subResults.length; k < l; k++) {
  1201. v = subResults[k];
  1202. if (isChild) {
  1203. if (val === v.parentNode) {
  1204. els.push(v);
  1205. }
  1206. } else {
  1207. els.push(v);
  1208. }
  1209. }
  1210. }
  1211. results = els;
  1212. } else {
  1213. results = select(part, root);
  1214. }
  1215. if (results.length === 0) {
  1216. return [];
  1217. }
  1218. }
  1219. return results;
  1220. }
  1221. function _query(expr, root) {
  1222. var arr = _queryAll(expr, root);
  1223. return arr.length > 0 ? arr[0] : null;
  1224. }
  1225. K.query = _query;
  1226. K.queryAll = _queryAll;
  1227. function _get(val) {
  1228. return K(val)[0];
  1229. }
  1230. function _getDoc(node) {
  1231. if (!node) {
  1232. return document;
  1233. }
  1234. return node.ownerDocument || node.document || node;
  1235. }
  1236. function _getWin(node) {
  1237. if (!node) {
  1238. return window;
  1239. }
  1240. var doc = _getDoc(node);
  1241. return doc.parentWindow || doc.defaultView;
  1242. }
  1243. function _setHtml(el, html) {
  1244. if (el.nodeType != 1) {
  1245. return;
  1246. }
  1247. var doc = _getDoc(el);
  1248. try {
  1249. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1250. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1251. temp.parentNode.removeChild(temp);
  1252. } catch(e) {
  1253. K(el).empty();
  1254. K('@' + html, doc).each(function() {
  1255. el.appendChild(this);
  1256. });
  1257. }
  1258. }
  1259. function _hasClass(el, cls) {
  1260. return _inString(cls, el.className, ' ');
  1261. }
  1262. function _setAttr(el, key, val) {
  1263. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1264. key = 'className';
  1265. }
  1266. el.setAttribute(key, '' + val);
  1267. }
  1268. function _removeAttr(el, key) {
  1269. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1270. key = 'className';
  1271. }
  1272. _setAttr(el, key, '');
  1273. el.removeAttribute(key);
  1274. }
  1275. function _getNodeName(node) {
  1276. if (!node || !node.nodeName) {
  1277. return '';
  1278. }
  1279. return node.nodeName.toLowerCase();
  1280. }
  1281. function _computedCss(el, key) {
  1282. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1283. if (win.getComputedStyle) {
  1284. var style = win.getComputedStyle(el, null);
  1285. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1286. } else if (el.currentStyle) {
  1287. val = el.currentStyle[camelKey] || el.style[camelKey];
  1288. }
  1289. return val;
  1290. }
  1291. function _hasVal(node) {
  1292. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1293. }
  1294. function _docElement(doc) {
  1295. doc = doc || document;
  1296. return _QUIRKS ? doc.body : doc.documentElement;
  1297. }
  1298. function _docHeight(doc) {
  1299. var el = _docElement(doc);
  1300. return Math.max(el.scrollHeight, el.clientHeight);
  1301. }
  1302. function _docWidth(doc) {
  1303. var el = _docElement(doc);
  1304. return Math.max(el.scrollWidth, el.clientWidth);
  1305. }
  1306. function _getScrollPos(doc) {
  1307. doc = doc || document;
  1308. var x, y;
  1309. if (_IE || _NEWIE || _OPERA) {
  1310. x = _docElement(doc).scrollLeft;
  1311. y = _docElement(doc).scrollTop;
  1312. } else {
  1313. x = _getWin(doc).scrollX;
  1314. y = _getWin(doc).scrollY;
  1315. }
  1316. return {x : x, y : y};
  1317. }
  1318. function KNode(node) {
  1319. this.init(node);
  1320. }
  1321. _extend(KNode, {
  1322. init : function(node) {
  1323. var self = this;
  1324. node = _isArray(node) ? node : [node];
  1325. var length = 0;
  1326. for (var i = 0, len = node.length; i < len; i++) {
  1327. if (node[i]) {
  1328. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1329. length++;
  1330. }
  1331. }
  1332. self.length = length;
  1333. self.doc = _getDoc(self[0]);
  1334. self.name = _getNodeName(self[0]);
  1335. self.type = self.length > 0 ? self[0].nodeType : null;
  1336. self.win = _getWin(self[0]);
  1337. },
  1338. each : function(fn) {
  1339. var self = this;
  1340. for (var i = 0; i < self.length; i++) {
  1341. if (fn.call(self[i], i, self[i]) === false) {
  1342. return self;
  1343. }
  1344. }
  1345. return self;
  1346. },
  1347. bind : function(type, fn) {
  1348. this.each(function() {
  1349. _bind(this, type, fn);
  1350. });
  1351. return this;
  1352. },
  1353. unbind : function(type, fn) {
  1354. this.each(function() {
  1355. _unbind(this, type, fn);
  1356. });
  1357. return this;
  1358. },
  1359. fire : function(type) {
  1360. if (this.length < 1) {
  1361. return this;
  1362. }
  1363. _fire(this[0], type);
  1364. return this;
  1365. },
  1366. hasAttr : function(key) {
  1367. if (this.length < 1) {
  1368. return false;
  1369. }
  1370. return !!_getAttr(this[0], key);
  1371. },
  1372. attr : function(key, val) {
  1373. var self = this;
  1374. if (key === undefined) {
  1375. return _getAttrList(self.outer());
  1376. }
  1377. if (typeof key === 'object') {
  1378. _each(key, function(k, v) {
  1379. self.attr(k, v);
  1380. });
  1381. return self;
  1382. }
  1383. if (val === undefined) {
  1384. val = self.length < 1 ? null : _getAttr(self[0], key);
  1385. return val === null ? '' : val;
  1386. }
  1387. self.each(function() {
  1388. _setAttr(this, key, val);
  1389. });
  1390. return self;
  1391. },
  1392. removeAttr : function(key) {
  1393. this.each(function() {
  1394. _removeAttr(this, key);
  1395. });
  1396. return this;
  1397. },
  1398. get : function(i) {
  1399. if (this.length < 1) {
  1400. return null;
  1401. }
  1402. return this[i || 0];
  1403. },
  1404. eq : function(i) {
  1405. if (this.length < 1) {
  1406. return null;
  1407. }
  1408. return this[i] ? new KNode(this[i]) : null;
  1409. },
  1410. hasClass : function(cls) {
  1411. if (this.length < 1) {
  1412. return false;
  1413. }
  1414. return _hasClass(this[0], cls);
  1415. },
  1416. addClass : function(cls) {
  1417. this.each(function() {
  1418. if (!_hasClass(this, cls)) {
  1419. this.className = _trim(this.className + ' ' + cls);
  1420. }
  1421. });
  1422. return this;
  1423. },
  1424. removeClass : function(cls) {
  1425. this.each(function() {
  1426. if (_hasClass(this, cls)) {
  1427. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1428. }
  1429. });
  1430. return this;
  1431. },
  1432. html : function(val) {
  1433. var self = this;
  1434. if (val === undefined) {
  1435. if (self.length < 1 || self.type != 1) {
  1436. return '';
  1437. }
  1438. return _formatHtml(self[0].innerHTML);
  1439. }
  1440. self.each(function() {
  1441. _setHtml(this, val);
  1442. });
  1443. return self;
  1444. },
  1445. text : function() {
  1446. var self = this;
  1447. if (self.length < 1) {
  1448. return '';
  1449. }
  1450. return _IE ? self[0].innerText : self[0].textContent;
  1451. },
  1452. hasVal : function() {
  1453. if (this.length < 1) {
  1454. return false;
  1455. }
  1456. return _hasVal(this[0]);
  1457. },
  1458. val : function(val) {
  1459. var self = this;
  1460. if (val === undefined) {
  1461. if (self.length < 1) {
  1462. return '';
  1463. }
  1464. return self.hasVal() ? self[0].value : self.attr('value');
  1465. } else {
  1466. self.each(function() {
  1467. if (_hasVal(this)) {
  1468. this.value = val;
  1469. } else {
  1470. _setAttr(this, 'value' , val);
  1471. }
  1472. });
  1473. return self;
  1474. }
  1475. },
  1476. css : function(key, val) {
  1477. var self = this;
  1478. if (key === undefined) {
  1479. return _getCssList(self.attr('style'));
  1480. }
  1481. if (typeof key === 'object') {
  1482. _each(key, function(k, v) {
  1483. self.css(k, v);
  1484. });
  1485. return self;
  1486. }
  1487. if (val === undefined) {
  1488. if (self.length < 1) {
  1489. return '';
  1490. }
  1491. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1492. }
  1493. self.each(function() {
  1494. this.style[_toCamel(key)] = val;
  1495. });
  1496. return self;
  1497. },
  1498. width : function(val) {
  1499. var self = this;
  1500. if (val === undefined) {
  1501. if (self.length < 1) {
  1502. return 0;
  1503. }
  1504. return self[0].offsetWidth;
  1505. }
  1506. return self.css('width', _addUnit(val));
  1507. },
  1508. height : function(val) {
  1509. var self = this;
  1510. if (val === undefined) {
  1511. if (self.length < 1) {
  1512. return 0;
  1513. }
  1514. return self[0].offsetHeight;
  1515. }
  1516. return self.css('height', _addUnit(val));
  1517. },
  1518. opacity : function(val) {
  1519. this.each(function() {
  1520. if (this.style.opacity === undefined) {
  1521. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1522. } else {
  1523. this.style.opacity = val == 1 ? '' : val;
  1524. }
  1525. });
  1526. return this;
  1527. },
  1528. data : function(key, val) {
  1529. var self = this;
  1530. key = 'kindeditor_data_' + key;
  1531. if (val === undefined) {
  1532. if (self.length < 1) {
  1533. return null;
  1534. }
  1535. return self[0][key];
  1536. }
  1537. this.each(function() {
  1538. this[key] = val;
  1539. });
  1540. return self;
  1541. },
  1542. pos : function() {
  1543. var self = this, node = self[0], x = 0, y = 0;
  1544. if (node) {
  1545. if (node.getBoundingClientRect) {
  1546. var box = node.getBoundingClientRect(),
  1547. pos = _getScrollPos(self.doc);
  1548. x = box.left + pos.x;
  1549. y = box.top + pos.y;
  1550. } else {
  1551. while (node) {
  1552. x += node.offsetLeft;
  1553. y += node.offsetTop;
  1554. node = node.offsetParent;
  1555. }
  1556. }
  1557. }
  1558. return {x : _round(x), y : _round(y)};
  1559. },
  1560. clone : function(bool) {
  1561. if (this.length < 1) {
  1562. return new KNode([]);
  1563. }
  1564. return new KNode(this[0].cloneNode(bool));
  1565. },
  1566. append : function(expr) {
  1567. this.each(function() {
  1568. if (this.appendChild) {
  1569. this.appendChild(_get(expr));
  1570. }
  1571. });
  1572. return this;
  1573. },
  1574. appendTo : function(expr) {
  1575. this.each(function() {
  1576. _get(expr).appendChild(this);
  1577. });
  1578. return this;
  1579. },
  1580. before : function(expr) {
  1581. this.each(function() {
  1582. this.parentNode.insertBefore(_get(expr), this);
  1583. });
  1584. return this;
  1585. },
  1586. after : function(expr) {
  1587. this.each(function() {
  1588. if (this.nextSibling) {
  1589. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1590. } else {
  1591. this.parentNode.appendChild(_get(expr));
  1592. }
  1593. });
  1594. return this;
  1595. },
  1596. replaceWith : function(expr) {
  1597. var nodes = [];
  1598. this.each(function(i, node) {
  1599. _unbind(node);
  1600. var newNode = _get(expr);
  1601. node.parentNode.replaceChild(newNode, node);
  1602. nodes.push(newNode);
  1603. });
  1604. return K(nodes);
  1605. },
  1606. empty : function() {
  1607. var self = this;
  1608. self.each(function(i, node) {
  1609. var child = node.firstChild;
  1610. while (child) {
  1611. if (!node.parentNode) {
  1612. return;
  1613. }
  1614. var next = child.nextSibling;
  1615. child.parentNode.removeChild(child);
  1616. child = next;
  1617. }
  1618. });
  1619. return self;
  1620. },
  1621. remove : function(keepChilds) {
  1622. var self = this;
  1623. self.each(function(i, node) {
  1624. if (!node.parentNode) {
  1625. return;
  1626. }
  1627. _unbind(node);
  1628. if (keepChilds) {
  1629. var child = node.firstChild;
  1630. while (child) {
  1631. var next = child.nextSibling;
  1632. node.parentNode.insertBefore(child, node);
  1633. child = next;
  1634. }
  1635. }
  1636. node.parentNode.removeChild(node);
  1637. delete self[i];
  1638. });
  1639. self.length = 0;
  1640. return self;
  1641. },
  1642. show : function(val) {
  1643. var self = this;
  1644. if (val === undefined) {
  1645. val = self._originDisplay || '';
  1646. }
  1647. if (self.css('display') != 'none') {
  1648. return self;
  1649. }
  1650. return self.css('display', val);
  1651. },
  1652. hide : function() {
  1653. var self = this;
  1654. if (self.length < 1) {
  1655. return self;
  1656. }
  1657. self._originDisplay = self[0].style.display;
  1658. return self.css('display', 'none');
  1659. },
  1660. outer : function() {
  1661. var self = this;
  1662. if (self.length < 1) {
  1663. return '';
  1664. }
  1665. var div = self.doc.createElement('div'), html;
  1666. div.appendChild(self[0].cloneNode(true));
  1667. html = _formatHtml(div.innerHTML);
  1668. div = null;
  1669. return html;
  1670. },
  1671. isSingle : function() {
  1672. return !!_SINGLE_TAG_MAP[this.name];
  1673. },
  1674. isInline : function() {
  1675. return !!_INLINE_TAG_MAP[this.name];
  1676. },
  1677. isBlock : function() {
  1678. return !!_BLOCK_TAG_MAP[this.name];
  1679. },
  1680. isStyle : function() {
  1681. return !!_STYLE_TAG_MAP[this.name];
  1682. },
  1683. isControl : function() {
  1684. return !!_CONTROL_TAG_MAP[this.name];
  1685. },
  1686. contains : function(otherNode) {
  1687. if (this.length < 1) {
  1688. return false;
  1689. }
  1690. return _contains(this[0], _get(otherNode));
  1691. },
  1692. parent : function() {
  1693. if (this.length < 1) {
  1694. return null;
  1695. }
  1696. var node = this[0].parentNode;
  1697. return node ? new KNode(node) : null;
  1698. },
  1699. children : function() {
  1700. if (this.length < 1) {
  1701. return new KNode([]);
  1702. }
  1703. var list = [], child = this[0].firstChild;
  1704. while (child) {
  1705. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1706. list.push(child);
  1707. }
  1708. child = child.nextSibling;
  1709. }
  1710. return new KNode(list);
  1711. },
  1712. first : function() {
  1713. var list = this.children();
  1714. return list.length > 0 ? list.eq(0) : null;
  1715. },
  1716. last : function() {
  1717. var list = this.children();
  1718. return list.length > 0 ? list.eq(list.length - 1) : null;
  1719. },
  1720. index : function() {
  1721. if (this.length < 1) {
  1722. return -1;
  1723. }
  1724. var i = -1, sibling = this[0];
  1725. while (sibling) {
  1726. i++;
  1727. sibling = sibling.previousSibling;
  1728. }
  1729. return i;
  1730. },
  1731. prev : function() {
  1732. if (this.length < 1) {
  1733. return null;
  1734. }
  1735. var node = this[0].previousSibling;
  1736. return node ? new KNode(node) : null;
  1737. },
  1738. next : function() {
  1739. if (this.length < 1) {
  1740. return null;
  1741. }
  1742. var node = this[0].nextSibling;
  1743. return node ? new KNode(node) : null;
  1744. },
  1745. scan : function(fn, order) {
  1746. if (this.length < 1) {
  1747. return;
  1748. }
  1749. order = (order === undefined) ? true : order;
  1750. function walk(node) {
  1751. var n = order ? node.firstChild : node.lastChild;
  1752. while (n) {
  1753. var next = order ? n.nextSibling : n.previousSibling;
  1754. if (fn(n) === false) {
  1755. return false;
  1756. }
  1757. if (walk(n) === false) {
  1758. return false;
  1759. }
  1760. n = next;
  1761. }
  1762. }
  1763. walk(this[0]);
  1764. return this;
  1765. }
  1766. });
  1767. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1768. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1769. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1770. KNode.prototype[type] = function(fn) {
  1771. return fn ? this.bind(type, fn) : this.fire(type);
  1772. };
  1773. });
  1774. var _K = K;
  1775. K = function(expr, root) {
  1776. if (expr === undefined || expr === null) {
  1777. return;
  1778. }
  1779. function newNode(node) {
  1780. if (!node[0]) {
  1781. node = [];
  1782. }
  1783. return new KNode(node);
  1784. }
  1785. if (typeof expr === 'string') {
  1786. if (root) {
  1787. root = _get(root);
  1788. }
  1789. var length = expr.length;
  1790. if (expr.charAt(0) === '@') {
  1791. expr = expr.substr(1);
  1792. }
  1793. if (expr.length !== length || /<.+>/.test(expr)) {
  1794. var doc = root ? root.ownerDocument || root : document,
  1795. div = doc.createElement('div'), list = [];
  1796. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1797. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1798. var child = div.childNodes[i];
  1799. if (child.id == '__kindeditor_temp_tag__') {
  1800. continue;
  1801. }
  1802. list.push(child);
  1803. }
  1804. return newNode(list);
  1805. }
  1806. return newNode(_queryAll(expr, root));
  1807. }
  1808. if (expr && expr.constructor === KNode) {
  1809. return expr;
  1810. }
  1811. if (expr.toArray) {
  1812. expr = expr.toArray();
  1813. }
  1814. if (_isArray(expr)) {
  1815. return newNode(expr);
  1816. }
  1817. return newNode(_toArray(arguments));
  1818. };
  1819. _each(_K, function(key, val) {
  1820. K[key] = val;
  1821. });
  1822. K.NodeClass = KNode;
  1823. window.KindEditor = K;
  1824. var _START_TO_START = 0,
  1825. _START_TO_END = 1,
  1826. _END_TO_END = 2,
  1827. _END_TO_START = 3,
  1828. _BOOKMARK_ID = 0;
  1829. function _updateCollapsed(range) {
  1830. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1831. return range;
  1832. }
  1833. function _copyAndDelete(range, isCopy, isDelete) {
  1834. var doc = range.doc, nodeList = [];
  1835. function splitTextNode(node, startOffset, endOffset) {
  1836. var length = node.nodeValue.length, centerNode;
  1837. if (isCopy) {
  1838. var cloneNode = node.cloneNode(true);
  1839. if (startOffset > 0) {
  1840. centerNode = cloneNode.splitText(startOffset);
  1841. } else {
  1842. centerNode = cloneNode;
  1843. }
  1844. if (endOffset < length) {
  1845. centerNode.splitText(endOffset - startOffset);
  1846. }
  1847. }
  1848. if (isDelete) {
  1849. var center = node;
  1850. if (startOffset > 0) {
  1851. center = node.splitText(startOffset);
  1852. range.setStart(node, startOffset);
  1853. }
  1854. if (endOffset < length) {
  1855. var right = center.splitText(endOffset - startOffset);
  1856. range.setEnd(right, 0);
  1857. }
  1858. nodeList.push(center);
  1859. }
  1860. return centerNode;
  1861. }
  1862. function removeNodes() {
  1863. if (isDelete) {
  1864. range.up().collapse(true);
  1865. }
  1866. for (var i = 0, len = nodeList.length; i < len; i++) {
  1867. var node = nodeList[i];
  1868. if (node.parentNode) {
  1869. node.parentNode.removeChild(node);
  1870. }
  1871. }
  1872. }
  1873. var copyRange = range.cloneRange().down();
  1874. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1875. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1876. if (ancestor.nodeType == 3) {
  1877. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1878. if (isCopy) {
  1879. frag.appendChild(textNode);
  1880. }
  1881. removeNodes();
  1882. return isCopy ? frag : range;
  1883. }
  1884. function extractNodes(parent, frag) {
  1885. var node = parent.firstChild, nextNode;
  1886. while (node) {
  1887. var testRange = new KRange(doc).selectNode(node);
  1888. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1889. if (start >= 0 && incStart <= 0) {
  1890. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1891. }
  1892. if (incStart >= 0 && incEnd <= 0) {
  1893. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1894. }
  1895. if (incEnd >= 0 && end <= 0) {
  1896. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1897. }
  1898. if (end >= 0) {
  1899. return false;
  1900. }
  1901. nextNode = node.nextSibling;
  1902. if (start > 0) {
  1903. if (node.nodeType == 1) {
  1904. if (incStart >= 0 && incEnd <= 0) {
  1905. if (isCopy) {
  1906. frag.appendChild(node.cloneNode(true));
  1907. }
  1908. if (isDelete) {
  1909. nodeList.push(node);
  1910. }
  1911. } else {
  1912. var childFlag;
  1913. if (isCopy) {
  1914. childFlag = node.cloneNode(false);
  1915. frag.appendChild(childFlag);
  1916. }
  1917. if (extractNodes(node, childFlag) === false) {
  1918. return false;
  1919. }
  1920. }
  1921. } else if (node.nodeType == 3) {
  1922. var textNode;
  1923. if (node == copyRange.startContainer) {
  1924. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1925. } else if (node == copyRange.endContainer) {
  1926. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1927. } else {
  1928. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1929. }
  1930. if (isCopy) {
  1931. try {
  1932. frag.appendChild(textNode);
  1933. } catch(e) {}
  1934. }
  1935. }
  1936. }
  1937. node = nextNode;
  1938. }
  1939. }
  1940. extractNodes(ancestor, frag);
  1941. if (isDelete) {
  1942. range.up().collapse(true);
  1943. }
  1944. for (var i = 0, len = nodeList.length; i < len; i++) {
  1945. var node = nodeList[i];
  1946. if (node.parentNode) {
  1947. node.parentNode.removeChild(node);
  1948. }
  1949. }
  1950. return isCopy ? frag : range;
  1951. }
  1952. function _moveToElementText(range, el) {
  1953. var node = el;
  1954. while (node) {
  1955. var knode = K(node);
  1956. if (knode.name == 'marquee' || knode.name == 'select') {
  1957. return;
  1958. }
  1959. node = node.parentNode;
  1960. }
  1961. try {
  1962. range.moveToElementText(el);
  1963. } catch(e) {}
  1964. }
  1965. function _getStartEnd(rng, isStart) {
  1966. var doc = rng.parentElement().ownerDocument,
  1967. pointRange = rng.duplicate();
  1968. pointRange.collapse(isStart);
  1969. var parent = pointRange.parentElement(),
  1970. nodes = parent.childNodes;
  1971. if (nodes.length === 0) {
  1972. return {node: parent.parentNode, offset: K(parent).index()};
  1973. }
  1974. var startNode = doc, startPos = 0, cmp = -1;
  1975. var testRange = rng.duplicate();
  1976. _moveToElementText(testRange, parent);
  1977. for (var i = 0, len = nodes.length; i < len; i++) {
  1978. var node = nodes[i];
  1979. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1980. if (cmp === 0) {
  1981. return {node: node.parentNode, offset: i};
  1982. }
  1983. if (node.nodeType == 1) {
  1984. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1985. if (knode.isControl()) {
  1986. dummy = doc.createElement('span');
  1987. knode.after(dummy);
  1988. newNode = dummy;
  1989. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1990. }
  1991. _moveToElementText(nodeRange, newNode);
  1992. testRange.setEndPoint('StartToEnd', nodeRange);
  1993. if (cmp > 0) {
  1994. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1995. } else {
  1996. startPos = 0;
  1997. }
  1998. if (dummy) {
  1999. K(dummy).remove();
  2000. }
  2001. } else if (node.nodeType == 3) {
  2002. testRange.moveStart('character', node.nodeValue.length);
  2003. startPos += node.nodeValue.length;
  2004. }
  2005. if (cmp < 0) {
  2006. startNode = node;
  2007. }
  2008. }
  2009. if (cmp < 0 && startNode.nodeType == 1) {
  2010. return {node: parent, offset: K(parent.lastChild).index() + 1};
  2011. }
  2012. if (cmp > 0) {
  2013. while (startNode.nextSibling && startNode.nodeType == 1) {
  2014. startNode = startNode.nextSibling;
  2015. }
  2016. }
  2017. testRange = rng.duplicate();
  2018. _moveToElementText(testRange, parent);
  2019. testRange.setEndPoint('StartToEnd', pointRange);
  2020. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  2021. if (cmp > 0 && startNode.nodeType == 3) {
  2022. var prevNode = startNode.previousSibling;
  2023. while (prevNode && prevNode.nodeType == 3) {
  2024. startPos -= prevNode.nodeValue.length;
  2025. prevNode = prevNode.previousSibling;
  2026. }
  2027. }
  2028. return {node: startNode, offset: startPos};
  2029. }
  2030. function _getEndRange(node, offset) {
  2031. var doc = node.ownerDocument || node,
  2032. range = doc.body.createTextRange();
  2033. if (doc == node) {
  2034. range.collapse(true);
  2035. return range;
  2036. }
  2037. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2038. var children = node.childNodes, isStart, child;
  2039. if (offset === 0) {
  2040. child = children[0];
  2041. isStart = true;
  2042. } else {
  2043. child = children[offset - 1];
  2044. isStart = false;
  2045. }
  2046. if (!child) {
  2047. return range;
  2048. }
  2049. if (K(child).name === 'head') {
  2050. if (offset === 1) {
  2051. isStart = true;
  2052. }
  2053. if (offset === 2) {
  2054. isStart = false;
  2055. }
  2056. range.collapse(isStart);
  2057. return range;
  2058. }
  2059. if (child.nodeType == 1) {
  2060. var kchild = K(child), span;
  2061. if (kchild.isControl()) {
  2062. span = doc.createElement('span');
  2063. if (isStart) {
  2064. kchild.before(span);
  2065. } else {
  2066. kchild.after(span);
  2067. }
  2068. child = span;
  2069. }
  2070. _moveToElementText(range, child);
  2071. range.collapse(isStart);
  2072. if (span) {
  2073. K(span).remove();
  2074. }
  2075. return range;
  2076. }
  2077. node = child;
  2078. offset = isStart ? 0 : child.nodeValue.length;
  2079. }
  2080. var dummy = doc.createElement('span');
  2081. K(node).before(dummy);
  2082. _moveToElementText(range, dummy);
  2083. range.moveStart('character', offset);
  2084. K(dummy).remove();
  2085. return range;
  2086. }
  2087. function _toRange(rng) {
  2088. var doc, range;
  2089. function tr2td(start) {
  2090. if (K(start.node).name == 'tr') {
  2091. start.node = start.node.cells[start.offset];
  2092. start.offset = 0;
  2093. }
  2094. }
  2095. if (_IERANGE) {
  2096. if (rng.item) {
  2097. doc = _getDoc(rng.item(0));
  2098. range = new KRange(doc);
  2099. range.selectNode(rng.item(0));
  2100. return range;
  2101. }
  2102. doc = rng.parentElement().ownerDocument;
  2103. var start = _getStartEnd(rng, true),
  2104. end = _getStartEnd(rng, false);
  2105. tr2td(start);
  2106. tr2td(end);
  2107. range = new KRange(doc);
  2108. range.setStart(start.node, start.offset);
  2109. range.setEnd(end.node, end.offset);
  2110. return range;
  2111. }
  2112. var startContainer = rng.startContainer;
  2113. doc = startContainer.ownerDocument || startContainer;
  2114. range = new KRange(doc);
  2115. range.setStart(startContainer, rng.startOffset);
  2116. range.setEnd(rng.endContainer, rng.endOffset);
  2117. return range;
  2118. }
  2119. function KRange(doc) {
  2120. this.init(doc);
  2121. }
  2122. _extend(KRange, {
  2123. init : function(doc) {
  2124. var self = this;
  2125. self.startContainer = doc;
  2126. self.startOffset = 0;
  2127. self.endContainer = doc;
  2128. self.endOffset = 0;
  2129. self.collapsed = true;
  2130. self.doc = doc;
  2131. },
  2132. commonAncestor : function() {
  2133. function getParents(node) {
  2134. var parents = [];
  2135. while (node) {
  2136. parents.push(node);
  2137. node = node.parentNode;
  2138. }
  2139. return parents;
  2140. }
  2141. var parentsA = getParents(this.startContainer),
  2142. parentsB = getParents(this.endContainer),
  2143. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2144. while (++i) {
  2145. parentA = parentsA[lenA - i];
  2146. parentB = parentsB[lenB - i];
  2147. if (!parentA || !parentB || parentA !== parentB) {
  2148. break;
  2149. }
  2150. }
  2151. return parentsA[lenA - i + 1];
  2152. },
  2153. setStart : function(node, offset) {
  2154. var self = this, doc = self.doc;
  2155. self.startContainer = node;
  2156. self.startOffset = offset;
  2157. if (self.endContainer === doc) {
  2158. self.endContainer = node;
  2159. self.endOffset = offset;
  2160. }
  2161. return _updateCollapsed(this);
  2162. },
  2163. setEnd : function(node, offset) {
  2164. var self = this, doc = self.doc;
  2165. self.endContainer = node;
  2166. self.endOffset = offset;
  2167. if (self.startContainer === doc) {
  2168. self.startContainer = node;
  2169. self.startOffset = offset;
  2170. }
  2171. return _updateCollapsed(this);
  2172. },
  2173. setStartBefore : function(node) {
  2174. return this.setStart(node.parentNode || this.doc, K(node).index());
  2175. },
  2176. setStartAfter : function(node) {
  2177. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2178. },
  2179. setEndBefore : function(node) {
  2180. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2181. },
  2182. setEndAfter : function(node) {
  2183. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2184. },
  2185. selectNode : function(node) {
  2186. return this.setStartBefore(node).setEndAfter(node);
  2187. },
  2188. selectNodeContents : function(node) {
  2189. var knode = K(node);
  2190. if (knode.type == 3 || knode.isSingle()) {
  2191. return this.selectNode(node);
  2192. }
  2193. var children = knode.children();
  2194. if (children.length > 0) {
  2195. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2196. }
  2197. return this.setStart(node, 0).setEnd(node, 0);
  2198. },
  2199. collapse : function(toStart) {
  2200. if (toStart) {
  2201. return this.setEnd(this.startContainer, this.startOffset);
  2202. }
  2203. return this.setStart(this.endContainer, this.endOffset);
  2204. },
  2205. compareBoundaryPoints : function(how, range) {
  2206. var rangeA = this.get(), rangeB = range.get();
  2207. if (_IERANGE) {
  2208. var arr = {};
  2209. arr[_START_TO_START] = 'StartToStart';
  2210. arr[_START_TO_END] = 'EndToStart';
  2211. arr[_END_TO_END] = 'EndToEnd';
  2212. arr[_END_TO_START] = 'StartToEnd';
  2213. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2214. if (cmp !== 0) {
  2215. return cmp;
  2216. }
  2217. var nodeA, nodeB, nodeC, posA, posB;
  2218. if (how === _START_TO_START || how === _END_TO_START) {
  2219. nodeA = this.startContainer;
  2220. posA = this.startOffset;
  2221. }
  2222. if (how === _START_TO_END || how === _END_TO_END) {
  2223. nodeA = this.endContainer;
  2224. posA = this.endOffset;
  2225. }
  2226. if (how === _START_TO_START || how === _START_TO_END) {
  2227. nodeB = range.startContainer;
  2228. posB = range.startOffset;
  2229. }
  2230. if (how === _END_TO_END || how === _END_TO_START) {
  2231. nodeB = range.endContainer;
  2232. posB = range.endOffset;
  2233. }
  2234. if (nodeA === nodeB) {
  2235. var diff = posA - posB;
  2236. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2237. }
  2238. nodeC = nodeB;
  2239. while (nodeC && nodeC.parentNode !== nodeA) {
  2240. nodeC = nodeC.parentNode;
  2241. }
  2242. if (nodeC) {
  2243. return K(nodeC).index() >= posA ? -1 : 1;
  2244. }
  2245. nodeC = nodeA;
  2246. while (nodeC && nodeC.parentNode !== nodeB) {
  2247. nodeC = nodeC.parentNode;
  2248. }
  2249. if (nodeC) {
  2250. return K(nodeC).index() >= posB ? 1 : -1;
  2251. }
  2252. nodeC = K(nodeB).next();
  2253. if (nodeC && nodeC.contains(nodeA)) {
  2254. return 1;
  2255. }
  2256. nodeC = K(nodeA).next();
  2257. if (nodeC && nodeC.contains(nodeB)) {
  2258. return -1;
  2259. }
  2260. } else {
  2261. return rangeA.compareBoundaryPoints(how, rangeB);
  2262. }
  2263. },
  2264. cloneRange : function() {
  2265. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2266. },
  2267. toString : function() {
  2268. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2269. return str.replace(/\r\n|\n|\r/g, '');
  2270. },
  2271. cloneContents : function() {
  2272. return _copyAndDelete(this, true, false);
  2273. },
  2274. deleteContents : function() {
  2275. return _copyAndDelete(this, false, true);
  2276. },
  2277. extractContents : function() {
  2278. return _copyAndDelete(this, true, true);
  2279. },
  2280. insertNode : function(node) {
  2281. var self = this,
  2282. sc = self.startContainer, so = self.startOffset,
  2283. ec = self.endContainer, eo = self.endOffset,
  2284. firstChild, lastChild, c, nodeCount = 1;
  2285. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2286. firstChild = node.firstChild;
  2287. lastChild = node.lastChild;
  2288. nodeCount = node.childNodes.length;
  2289. }
  2290. if (sc.nodeType == 1) {
  2291. c = sc.childNodes[so];
  2292. if (c) {
  2293. sc.insertBefore(node, c);
  2294. if (sc === ec) {
  2295. eo += nodeCount;
  2296. }
  2297. } else {
  2298. sc.appendChild(node);
  2299. }
  2300. } else if (sc.nodeType == 3) {
  2301. if (so === 0) {
  2302. sc.parentNode.insertBefore(node, sc);
  2303. if (sc.parentNode === ec) {
  2304. eo += nodeCount;
  2305. }
  2306. } else if (so >= sc.nodeValue.length) {
  2307. if (sc.nextSibling) {
  2308. sc.parentNode.insertBefore(node, sc.nextSibling);
  2309. } else {
  2310. sc.parentNode.appendChild(node);
  2311. }
  2312. } else {
  2313. if (so > 0) {
  2314. c = sc.splitText(so);
  2315. } else {
  2316. c = sc;
  2317. }
  2318. sc.parentNode.insertBefore(node, c);
  2319. if (sc === ec) {
  2320. ec = c;
  2321. eo -= so;
  2322. }
  2323. }
  2324. }
  2325. if (firstChild) {
  2326. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2327. } else {
  2328. self.selectNode(node);
  2329. }
  2330. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2331. return self;
  2332. }
  2333. return self.setEnd(ec, eo);
  2334. },
  2335. surroundContents : function(node) {
  2336. node.appendChild(this.extractContents());
  2337. return this.insertNode(node).selectNode(node);
  2338. },
  2339. isControl : function() {
  2340. var self = this,
  2341. sc = self.startContainer, so = self.startOffset,
  2342. ec = self.endContainer, eo = self.endOffset, rng;
  2343. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2344. },
  2345. get : function(hasControlRange) {
  2346. var self = this, doc = self.doc, node, rng;
  2347. if (!_IERANGE) {
  2348. rng = doc.createRange();
  2349. try {
  2350. rng.setStart(self.startContainer, self.startOffset);
  2351. rng.setEnd(self.endContainer, self.endOffset);
  2352. } catch (e) {}
  2353. return rng;
  2354. }
  2355. if (hasControlRange && self.isControl()) {
  2356. rng = doc.body.createControlRange();
  2357. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2358. return rng;
  2359. }
  2360. var range = self.cloneRange().down();
  2361. rng = doc.body.createTextRange();
  2362. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2363. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2364. return rng;
  2365. },
  2366. html : function() {
  2367. return K(this.cloneContents()).outer();
  2368. },
  2369. down : function() {
  2370. var self = this;
  2371. function downPos(node, pos, isStart) {
  2372. if (node.nodeType != 1) {
  2373. return;
  2374. }
  2375. var children = K(node).children();
  2376. if (children.length === 0) {
  2377. return;
  2378. }
  2379. var left, right, child, offset;
  2380. if (pos > 0) {
  2381. left = children.eq(pos - 1);
  2382. }
  2383. if (pos < children.length) {
  2384. right = children.eq(pos);
  2385. }
  2386. if (left && left.type == 3) {
  2387. child = left[0];
  2388. offset = child.nodeValue.length;
  2389. }
  2390. if (right && right.type == 3) {
  2391. child = right[0];
  2392. offset = 0;
  2393. }
  2394. if (!child) {
  2395. return;
  2396. }
  2397. if (isStart) {
  2398. self.setStart(child, offset);
  2399. } else {
  2400. self.setEnd(child, offset);
  2401. }
  2402. }
  2403. downPos(self.startContainer, self.startOffset, true);
  2404. downPos(self.endContainer, self.endOffset, false);
  2405. return self;
  2406. },
  2407. up : function() {
  2408. var self = this;
  2409. function upPos(node, pos, isStart) {
  2410. if (node.nodeType != 3) {
  2411. return;
  2412. }
  2413. if (pos === 0) {
  2414. if (isStart) {
  2415. self.setStartBefore(node);
  2416. } else {
  2417. self.setEndBefore(node);
  2418. }
  2419. } else if (pos == node.nodeValue.length) {
  2420. if (isStart) {
  2421. self.setStartAfter(node);
  2422. } else {
  2423. self.setEndAfter(node);
  2424. }
  2425. }
  2426. }
  2427. upPos(self.startContainer, self.startOffset, true);
  2428. upPos(self.endContainer, self.endOffset, false);
  2429. return self;
  2430. },
  2431. enlarge : function(toBlock) {
  2432. var self = this;
  2433. self.up();
  2434. function enlargePos(node, pos, isStart) {
  2435. var knode = K(node), parent;
  2436. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2437. return;
  2438. }
  2439. if (pos === 0) {
  2440. while (!knode.prev()) {
  2441. parent = knode.parent();
  2442. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2443. break;
  2444. }
  2445. knode = parent;
  2446. }
  2447. if (isStart) {
  2448. self.setStartBefore(knode[0]);
  2449. } else {
  2450. self.setEndBefore(knode[0]);
  2451. }
  2452. } else if (pos == knode.children().length) {
  2453. while (!knode.next()) {
  2454. parent = knode.parent();
  2455. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2456. break;
  2457. }
  2458. knode = parent;
  2459. }
  2460. if (isStart) {
  2461. self.setStartAfter(knode[0]);
  2462. } else {
  2463. self.setEndAfter(knode[0]);
  2464. }
  2465. }
  2466. }
  2467. enlargePos(self.startContainer, self.startOffset, true);
  2468. enlargePos(self.endContainer, self.endOffset, false);
  2469. return self;
  2470. },
  2471. shrink : function() {
  2472. var self = this, child, collapsed = self.collapsed;
  2473. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2474. self.setStart(child, 0);
  2475. }
  2476. if (collapsed) {
  2477. return self.collapse(collapsed);
  2478. }
  2479. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2480. self.setEnd(child, child.childNodes.length);
  2481. }
  2482. return self;
  2483. },
  2484. createBookmark : function(serialize) {
  2485. var self = this, doc = self.doc, endNode,
  2486. startNode = K('<span style="display:none;"></span>', doc)[0];
  2487. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2488. if (!self.collapsed) {
  2489. endNode = startNode.cloneNode(true);
  2490. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2491. }
  2492. if (endNode) {
  2493. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2494. }
  2495. self.insertNode(startNode).setStartAfter(startNode);
  2496. return {
  2497. start : serialize ? '#' + startNode.id : startNode,
  2498. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2499. };
  2500. },
  2501. moveToBookmark : function(bookmark) {
  2502. var self = this, doc = self.doc,
  2503. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2504. if (!start || start.length < 1) {
  2505. return self;
  2506. }
  2507. self.setStartBefore(start[0]);
  2508. start.remove();
  2509. if (end && end.length > 0) {
  2510. self.setEndBefore(end[0]);
  2511. end.remove();
  2512. } else {
  2513. self.collapse(true);
  2514. }
  2515. return self;
  2516. },
  2517. dump : function() {
  2518. console.log('--------------------');
  2519. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2520. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2521. }
  2522. });
  2523. function _range(mixed) {
  2524. if (!mixed.nodeName) {
  2525. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2526. }
  2527. return new KRange(mixed);
  2528. }
  2529. K.RangeClass = KRange;
  2530. K.range = _range;
  2531. K.START_TO_START = _START_TO_START;
  2532. K.START_TO_END = _START_TO_END;
  2533. K.END_TO_END = _END_TO_END;
  2534. K.END_TO_START = _END_TO_START;
  2535. function _nativeCommand(doc, key, val) {
  2536. try {
  2537. doc.execCommand(key, false, val);
  2538. } catch(e) {}
  2539. }
  2540. function _nativeCommandValue(doc, key) {
  2541. var val = '';
  2542. try {
  2543. val = doc.queryCommandValue(key);
  2544. } catch (e) {}
  2545. if (typeof val !== 'string') {
  2546. val = '';
  2547. }
  2548. return val;
  2549. }
  2550. function _getSel(doc) {
  2551. var win = _getWin(doc);
  2552. return _IERANGE ? doc.selection : win.getSelection();
  2553. }
  2554. function _getRng(doc) {
  2555. var sel = _getSel(doc), rng;
  2556. try {
  2557. if (sel.rangeCount > 0) {
  2558. rng = sel.getRangeAt(0);
  2559. } else {
  2560. rng = sel.createRange();
  2561. }
  2562. } catch(e) {}
  2563. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2564. return null;
  2565. }
  2566. return rng;
  2567. }
  2568. function _singleKeyMap(map) {
  2569. var newMap = {}, arr, v;
  2570. _each(map, function(key, val) {
  2571. arr = key.split(',');
  2572. for (var i = 0, len = arr.length; i < len; i++) {
  2573. v = arr[i];
  2574. newMap[v] = val;
  2575. }
  2576. });
  2577. return newMap;
  2578. }
  2579. function _hasAttrOrCss(knode, map) {
  2580. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2581. }
  2582. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2583. mapKey = mapKey || knode.name;
  2584. if (knode.type !== 1) {
  2585. return false;
  2586. }
  2587. var newMap = _singleKeyMap(map);
  2588. if (!newMap[mapKey]) {
  2589. return false;
  2590. }
  2591. var arr = newMap[mapKey].split(',');
  2592. for (var i = 0, len = arr.length; i < len; i++) {
  2593. var key = arr[i];
  2594. if (key === '*') {
  2595. return true;
  2596. }
  2597. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2598. var method = match[1] ? 'css' : 'attr';
  2599. key = match[2];
  2600. var val = match[3] || '';
  2601. if (val === '' && knode[method](key) !== '') {
  2602. return true;
  2603. }
  2604. if (val !== '' && knode[method](key) === val) {
  2605. return true;
  2606. }
  2607. }
  2608. return false;
  2609. }
  2610. function _removeAttrOrCss(knode, map) {
  2611. if (knode.type != 1) {
  2612. return;
  2613. }
  2614. _removeAttrOrCssByKey(knode, map, '*');
  2615. _removeAttrOrCssByKey(knode, map);
  2616. }
  2617. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2618. mapKey = mapKey || knode.name;
  2619. if (knode.type !== 1) {
  2620. return;
  2621. }
  2622. var newMap = _singleKeyMap(map);
  2623. if (!newMap[mapKey]) {
  2624. return;
  2625. }
  2626. var arr = newMap[mapKey].split(','), allFlag = false;
  2627. for (var i = 0, len = arr.length; i < len; i++) {
  2628. var key = arr[i];
  2629. if (key === '*') {
  2630. allFlag = true;
  2631. break;
  2632. }
  2633. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2634. key = match[2];
  2635. if (match[1]) {
  2636. key = _toCamel(key);
  2637. if (knode[0].style[key]) {
  2638. knode[0].style[key] = '';
  2639. }
  2640. } else {
  2641. knode.removeAttr(key);
  2642. }
  2643. }
  2644. if (allFlag) {
  2645. knode.remove(true);
  2646. }
  2647. }
  2648. function _getInnerNode(knode) {
  2649. var inner = knode;
  2650. while (inner.first()) {
  2651. inner = inner.first();
  2652. }
  2653. return inner;
  2654. }
  2655. function _isEmptyNode(knode) {
  2656. if (knode.type != 1 || knode.isSingle()) {
  2657. return false;
  2658. }
  2659. return knode.html().replace(/<[^>]+>/g, '') === '';
  2660. }
  2661. function _mergeWrapper(a, b) {
  2662. a = a.clone(true);
  2663. var lastA = _getInnerNode(a), childA = a, merged = false;
  2664. while (b) {
  2665. while (childA) {
  2666. if (childA.name === b.name) {
  2667. _mergeAttrs(childA, b.attr(), b.css());
  2668. merged = true;
  2669. }
  2670. childA = childA.first();
  2671. }
  2672. if (!merged) {
  2673. lastA.append(b.clone(false));
  2674. }
  2675. merged = false;
  2676. b = b.first();
  2677. }
  2678. return a;
  2679. }
  2680. function _wrapNode(knode, wrapper) {
  2681. wrapper = wrapper.clone(true);
  2682. if (knode.type == 3) {
  2683. _getInnerNode(wrapper).append(knode.clone(false));
  2684. knode.replaceWith(wrapper);
  2685. return wrapper;
  2686. }
  2687. var nodeWrapper = knode, child;
  2688. while ((child = knode.first()) && child.children().length == 1) {
  2689. knode = child;
  2690. }
  2691. child = knode.first();
  2692. var frag = knode.doc.createDocumentFragment();
  2693. while (child) {
  2694. frag.appendChild(child[0]);
  2695. child = child.next();
  2696. }
  2697. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2698. if (frag.firstChild) {
  2699. _getInnerNode(wrapper).append(frag);
  2700. }
  2701. nodeWrapper.replaceWith(wrapper);
  2702. return wrapper;
  2703. }
  2704. function _mergeAttrs(knode, attrs, styles) {
  2705. _each(attrs, function(key, val) {
  2706. if (key !== 'style') {
  2707. knode.attr(key, val);
  2708. }
  2709. });
  2710. _each(styles, function(key, val) {
  2711. knode.css(key, val);
  2712. });
  2713. }
  2714. function _inPreElement(knode) {
  2715. while (knode && knode.name != 'body') {
  2716. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2717. return true;
  2718. }
  2719. knode = knode.parent();
  2720. }
  2721. return false;
  2722. }
  2723. function KCmd(range) {
  2724. this.init(range);
  2725. }
  2726. _extend(KCmd, {
  2727. init : function(range) {
  2728. var self = this, doc = range.doc;
  2729. self.doc = doc;
  2730. self.win = _getWin(doc);
  2731. self.sel = _getSel(doc);
  2732. self.range = range;
  2733. },
  2734. selection : function(forceReset) {
  2735. var self = this, doc = self.doc, rng = _getRng(doc);
  2736. self.sel = _getSel(doc);
  2737. if (rng) {
  2738. self.range = _range(rng);
  2739. if (K(self.range.startContainer).name == 'html') {
  2740. self.range.selectNodeContents(doc.body).collapse(false);
  2741. }
  2742. return self;
  2743. }
  2744. if (forceReset) {
  2745. self.range.selectNodeContents(doc.body).collapse(false);
  2746. }
  2747. return self;
  2748. },
  2749. select : function(hasDummy) {
  2750. hasDummy = _undef(hasDummy, true);
  2751. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2752. sc = range.startContainer, so = range.startOffset,
  2753. ec = range.endContainer, eo = range.endOffset,
  2754. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2755. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2756. if (_IERANGE) {
  2757. var dummy = K('<span>&nbsp;</span>', doc);
  2758. range.insertNode(dummy[0]);
  2759. rng = doc.body.createTextRange();
  2760. try {
  2761. rng.moveToElementText(dummy[0]);
  2762. } catch(ex) {}
  2763. rng.collapse(false);
  2764. rng.select();
  2765. dummy.remove();
  2766. win.focus();
  2767. return self;
  2768. }
  2769. if (_WEBKIT) {
  2770. var children = sc.childNodes;
  2771. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2772. range.insertNode(doc.createTextNode('\u200B'));
  2773. hasU200b = true;
  2774. }
  2775. }
  2776. }
  2777. if (_IERANGE) {
  2778. try {
  2779. rng = range.get(true);
  2780. rng.select();
  2781. } catch(e) {}
  2782. } else {
  2783. if (hasU200b) {
  2784. range.collapse(false);
  2785. }
  2786. rng = range.get(true);
  2787. sel.removeAllRanges();
  2788. sel.addRange(rng);
  2789. if (doc !== document) {
  2790. var pos = K(rng.endContainer).pos();
  2791. win.scrollTo(pos.x, pos.y);
  2792. }
  2793. }
  2794. win.focus();
  2795. return self;
  2796. },
  2797. wrap : function(val) {
  2798. var self = this, doc = self.doc, range = self.range, wrapper;
  2799. wrapper = K(val, doc);
  2800. if (range.collapsed) {
  2801. range.shrink();
  2802. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2803. return self;
  2804. }
  2805. if (wrapper.isBlock()) {
  2806. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2807. while (child.first()) {
  2808. child = child.first();
  2809. }
  2810. child.append(range.extractContents());
  2811. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2812. return self;
  2813. }
  2814. range.enlarge();
  2815. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2816. K(ancestor).scan(function(node) {
  2817. if (!isStart && node == bookmark.start) {
  2818. isStart = true;
  2819. return;
  2820. }
  2821. if (isStart) {
  2822. if (node == bookmark.end) {
  2823. return false;
  2824. }
  2825. var knode = K(node);
  2826. if (_inPreElement(knode)) {
  2827. return;
  2828. }
  2829. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2830. var parent;
  2831. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2832. knode = parent;
  2833. }
  2834. _wrapNode(knode, wrapper);
  2835. }
  2836. }
  2837. });
  2838. range.moveToBookmark(bookmark);
  2839. return self;
  2840. },
  2841. split : function(isStart, map) {
  2842. var range = this.range, doc = range.doc;
  2843. var tempRange = range.cloneRange().collapse(isStart);
  2844. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2845. parent = node.nodeType == 3 ? node.parentNode : node,
  2846. needSplit = false, knode;
  2847. while (parent && parent.parentNode) {
  2848. knode = K(parent);
  2849. if (map) {
  2850. if (!knode.isStyle()) {
  2851. break;
  2852. }
  2853. if (!_hasAttrOrCss(knode, map)) {
  2854. break;
  2855. }
  2856. } else {
  2857. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2858. break;
  2859. }
  2860. }
  2861. needSplit = true;
  2862. parent = parent.parentNode;
  2863. }
  2864. if (needSplit) {
  2865. var dummy = doc.createElement('span');
  2866. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2867. if (isStart) {
  2868. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2869. } else {
  2870. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2871. }
  2872. var frag = tempRange.extractContents(),
  2873. first = frag.firstChild, last = frag.lastChild;
  2874. if (isStart) {
  2875. tempRange.insertNode(frag);
  2876. range.setStartAfter(last).setEndBefore(dummy);
  2877. } else {
  2878. parent.appendChild(frag);
  2879. range.setStartBefore(dummy).setEndBefore(first);
  2880. }
  2881. var dummyParent = dummy.parentNode;
  2882. if (dummyParent == range.endContainer) {
  2883. var prev = K(dummy).prev(), next = K(dummy).next();
  2884. if (prev && next && prev.type == 3 && next.type == 3) {
  2885. range.setEnd(prev[0], prev[0].nodeValue.length);
  2886. } else if (!isStart) {
  2887. range.setEnd(range.endContainer, range.endOffset - 1);
  2888. }
  2889. }
  2890. dummyParent.removeChild(dummy);
  2891. }
  2892. return this;
  2893. },
  2894. remove : function(map) {
  2895. var self = this, doc = self.doc, range = self.range;
  2896. range.enlarge();
  2897. if (range.startOffset === 0) {
  2898. var ksc = K(range.startContainer), parent;
  2899. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2900. ksc = parent;
  2901. }
  2902. range.setStart(ksc[0], 0);
  2903. ksc = K(range.startContainer);
  2904. if (ksc.isBlock()) {
  2905. _removeAttrOrCss(ksc, map);
  2906. }
  2907. var kscp = ksc.parent();
  2908. if (kscp && kscp.isBlock()) {
  2909. _removeAttrOrCss(kscp, map);
  2910. }
  2911. }
  2912. var sc, so;
  2913. if (range.collapsed) {
  2914. self.split(true, map);
  2915. sc = range.startContainer;
  2916. so = range.startOffset;
  2917. if (so > 0) {
  2918. var sb = K(sc.childNodes[so - 1]);
  2919. if (sb && _isEmptyNode(sb)) {
  2920. sb.remove();
  2921. range.setStart(sc, so - 1);
  2922. }
  2923. }
  2924. var sa = K(sc.childNodes[so]);
  2925. if (sa && _isEmptyNode(sa)) {
  2926. sa.remove();
  2927. }
  2928. if (_isEmptyNode(sc)) {
  2929. range.startBefore(sc);
  2930. sc.remove();
  2931. }
  2932. range.collapse(true);
  2933. return self;
  2934. }
  2935. self.split(true, map);
  2936. self.split(false, map);
  2937. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2938. range.cloneRange().collapse(false).insertNode(endDummy);
  2939. range.cloneRange().collapse(true).insertNode(startDummy);
  2940. var nodeList = [], cmpStart = false;
  2941. K(range.commonAncestor()).scan(function(node) {
  2942. if (!cmpStart && node == startDummy) {
  2943. cmpStart = true;
  2944. return;
  2945. }
  2946. if (node == endDummy) {
  2947. return false;
  2948. }
  2949. if (cmpStart) {
  2950. nodeList.push(node);
  2951. }
  2952. });
  2953. K(startDummy).remove();
  2954. K(endDummy).remove();
  2955. sc = range.startContainer;
  2956. so = range.startOffset;
  2957. var ec = range.endContainer, eo = range.endOffset;
  2958. if (so > 0) {
  2959. var startBefore = K(sc.childNodes[so - 1]);
  2960. if (startBefore && _isEmptyNode(startBefore)) {
  2961. startBefore.remove();
  2962. range.setStart(sc, so - 1);
  2963. if (sc == ec) {
  2964. range.setEnd(ec, eo - 1);
  2965. }
  2966. }
  2967. var startAfter = K(sc.childNodes[so]);
  2968. if (startAfter && _isEmptyNode(startAfter)) {
  2969. startAfter.remove();
  2970. if (sc == ec) {
  2971. range.setEnd(ec, eo - 1);
  2972. }
  2973. }
  2974. }
  2975. var endAfter = K(ec.childNodes[range.endOffset]);
  2976. if (endAfter && _isEmptyNode(endAfter)) {
  2977. endAfter.remove();
  2978. }
  2979. var bookmark = range.createBookmark(true);
  2980. _each(nodeList, function(i, node) {
  2981. _removeAttrOrCss(K(node), map);
  2982. });
  2983. range.moveToBookmark(bookmark);
  2984. return self;
  2985. },
  2986. commonNode : function(map) {
  2987. var range = this.range;
  2988. var ec = range.endContainer, eo = range.endOffset,
  2989. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2990. function find(node) {
  2991. var child = node, parent = node;
  2992. while (parent) {
  2993. if (_hasAttrOrCss(K(parent), map)) {
  2994. return K(parent);
  2995. }
  2996. parent = parent.parentNode;
  2997. }
  2998. while (child && (child = child.lastChild)) {
  2999. if (_hasAttrOrCss(K(child), map)) {
  3000. return K(child);
  3001. }
  3002. }
  3003. return null;
  3004. }
  3005. var cNode = find(node);
  3006. if (cNode) {
  3007. return cNode;
  3008. }
  3009. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  3010. var prev = K(node).prev();
  3011. if (prev) {
  3012. return find(prev);
  3013. }
  3014. }
  3015. return null;
  3016. },
  3017. commonAncestor : function(tagName) {
  3018. var range = this.range,
  3019. sc = range.startContainer, so = range.startOffset,
  3020. ec = range.endContainer, eo = range.endOffset,
  3021. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3022. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3023. function find(node) {
  3024. while (node) {
  3025. if (node.nodeType == 1) {
  3026. if (node.tagName.toLowerCase() === tagName) {
  3027. return node;
  3028. }
  3029. }
  3030. node = node.parentNode;
  3031. }
  3032. return null;
  3033. }
  3034. var start = find(startNode), end = find(endNode);
  3035. if (start && end && start === end) {
  3036. return K(start);
  3037. }
  3038. return null;
  3039. },
  3040. state : function(key) {
  3041. var self = this, doc = self.doc, bool = false;
  3042. try {
  3043. bool = doc.queryCommandState(key);
  3044. } catch (e) {}
  3045. return bool;
  3046. },
  3047. val : function(key) {
  3048. var self = this, doc = self.doc, range = self.range;
  3049. function lc(val) {
  3050. return val.toLowerCase();
  3051. }
  3052. key = lc(key);
  3053. var val = '', knode;
  3054. if (key === 'fontfamily' || key === 'fontname') {
  3055. val = _nativeCommandValue(doc, 'fontname');
  3056. val = val.replace(/['"]/g, '');
  3057. return lc(val);
  3058. }
  3059. if (key === 'formatblock') {
  3060. val = _nativeCommandValue(doc, key);
  3061. if (val === '') {
  3062. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3063. if (knode) {
  3064. val = knode.name;
  3065. }
  3066. }
  3067. if (val === 'Normal') {
  3068. val = 'p';
  3069. }
  3070. return lc(val);
  3071. }
  3072. if (key === 'fontsize') {
  3073. knode = self.commonNode({'*' : '.font-size'});
  3074. if (knode) {
  3075. val = knode.css('font-size');
  3076. }
  3077. return lc(val);
  3078. }
  3079. if (key === 'forecolor') {
  3080. knode = self.commonNode({'*' : '.color'});
  3081. if (knode) {
  3082. val = knode.css('color');
  3083. }
  3084. val = _toHex(val);
  3085. if (val === '') {
  3086. val = 'default';
  3087. }
  3088. return lc(val);
  3089. }
  3090. if (key === 'hilitecolor') {
  3091. knode = self.commonNode({'*' : '.background-color'});
  3092. if (knode) {
  3093. val = knode.css('background-color');
  3094. }
  3095. val = _toHex(val);
  3096. if (val === '') {
  3097. val = 'default';
  3098. }
  3099. return lc(val);
  3100. }
  3101. return val;
  3102. },
  3103. toggle : function(wrapper, map) {
  3104. var self = this;
  3105. if (self.commonNode(map)) {
  3106. self.remove(map);
  3107. } else {
  3108. self.wrap(wrapper);
  3109. }
  3110. return self.select();
  3111. },
  3112. bold : function() {
  3113. return this.toggle('<strong></strong>', {
  3114. span : '.font-weight=bold',
  3115. strong : '*',
  3116. b : '*'
  3117. });
  3118. },
  3119. italic : function() {
  3120. return this.toggle('<em></em>', {
  3121. span : '.font-style=italic',
  3122. em : '*',
  3123. i : '*'
  3124. });
  3125. },
  3126. underline : function() {
  3127. return this.toggle('<u></u>', {
  3128. span : '.text-decoration=underline',
  3129. u : '*'
  3130. });
  3131. },
  3132. strikethrough : function() {
  3133. return this.toggle('<s></s>', {
  3134. span : '.text-decoration=line-through',
  3135. s : '*'
  3136. });
  3137. },
  3138. forecolor : function(val) {
  3139. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3140. },
  3141. hilitecolor : function(val) {
  3142. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3143. },
  3144. fontsize : function(val) {
  3145. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3146. },
  3147. fontname : function(val) {
  3148. return this.fontfamily(val);
  3149. },
  3150. fontfamily : function(val) {
  3151. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3152. },
  3153. removeformat : function() {
  3154. var map = {
  3155. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3156. },
  3157. tags = _STYLE_TAG_MAP;
  3158. _each(tags, function(key, val) {
  3159. map[key] = '*';
  3160. });
  3161. this.remove(map);
  3162. return this.select();
  3163. },
  3164. inserthtml : function(val, quickMode) {
  3165. var self = this, range = self.range;
  3166. if (val === '') {
  3167. return self;
  3168. }
  3169. function pasteHtml(range, val) {
  3170. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3171. var rng = range.get();
  3172. if (rng.item) {
  3173. rng.item(0).outerHTML = val;
  3174. } else {
  3175. rng.pasteHTML(val);
  3176. }
  3177. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3178. temp.parentNode.removeChild(temp);
  3179. var newRange = _toRange(rng);
  3180. range.setEnd(newRange.endContainer, newRange.endOffset);
  3181. range.collapse(false);
  3182. self.select(false);
  3183. }
  3184. function insertHtml(range, val) {
  3185. var doc = range.doc,
  3186. frag = doc.createDocumentFragment();
  3187. K('@' + val, doc).each(function() {
  3188. frag.appendChild(this);
  3189. });
  3190. range.deleteContents();
  3191. range.insertNode(frag);
  3192. range.collapse(false);
  3193. self.select(false);
  3194. }
  3195. if (_IERANGE && quickMode) {
  3196. try {
  3197. pasteHtml(range, val);
  3198. } catch(e) {
  3199. insertHtml(range, val);
  3200. }
  3201. return self;
  3202. }
  3203. insertHtml(range, val);
  3204. return self;
  3205. },
  3206. hr : function() {
  3207. return this.inserthtml('<hr />');
  3208. },
  3209. print : function() {
  3210. this.win.print();
  3211. return this;
  3212. },
  3213. insertimage : function(url, title, width, height, border, align) {
  3214. title = _undef(title, '');
  3215. border = _undef(border, 0);
  3216. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3217. if (width) {
  3218. html += 'width="' + _escape(width) + '" ';
  3219. }
  3220. if (height) {
  3221. html += 'height="' + _escape(height) + '" ';
  3222. }
  3223. if (title) {
  3224. html += 'title="' + _escape(title) + '" ';
  3225. }
  3226. if (align) {
  3227. html += 'align="' + _escape(align) + '" ';
  3228. }
  3229. html += 'alt="' + _escape(title) + '" ';
  3230. html += '/>';
  3231. return this.inserthtml(html);
  3232. },
  3233. createlink : function(url, type) {
  3234. var self = this, doc = self.doc, range = self.range;
  3235. self.select();
  3236. var a = self.commonNode({ a : '*' });
  3237. if (a && !range.isControl()) {
  3238. range.selectNode(a.get());
  3239. self.select();
  3240. }
  3241. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3242. if (type) {
  3243. html += ' target="' + _escape(type) + '"';
  3244. }
  3245. if (range.collapsed) {
  3246. html += '>' + _escape(url) + '</a>';
  3247. return self.inserthtml(html);
  3248. }
  3249. if (range.isControl()) {
  3250. var node = K(range.startContainer.childNodes[range.startOffset]);
  3251. html += '></a>';
  3252. node.after(K(html, doc));
  3253. node.next().append(node);
  3254. range.selectNode(node[0]);
  3255. return self.select();
  3256. }
  3257. function setAttr(node, url, type) {
  3258. K(node).attr('href', url).attr('data-ke-src', url);
  3259. if (type) {
  3260. K(node).attr('target', type);
  3261. } else {
  3262. K(node).removeAttr('target');
  3263. }
  3264. }
  3265. var sc = range.startContainer, so = range.startOffset,
  3266. ec = range.endContainer, eo = range.endOffset;
  3267. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3268. var child = sc.childNodes[so];
  3269. if (child.nodeName.toLowerCase() == 'a') {
  3270. setAttr(child, url, type);
  3271. return self;
  3272. }
  3273. }
  3274. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3275. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3276. setAttr(this, url, type);
  3277. });
  3278. return self;
  3279. },
  3280. unlink : function() {
  3281. var self = this, doc = self.doc, range = self.range;
  3282. self.select();
  3283. if (range.collapsed) {
  3284. var a = self.commonNode({ a : '*' });
  3285. if (a) {
  3286. range.selectNode(a.get());
  3287. self.select();
  3288. }
  3289. _nativeCommand(doc, 'unlink', null);
  3290. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3291. var parent = K(range.startContainer).parent();
  3292. if (parent.name === 'a') {
  3293. parent.remove(true);
  3294. }
  3295. }
  3296. } else {
  3297. _nativeCommand(doc, 'unlink', null);
  3298. }
  3299. return self;
  3300. }
  3301. });
  3302. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3303. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3304. KCmd.prototype[name] = function(val) {
  3305. var self = this;
  3306. self.select();
  3307. _nativeCommand(self.doc, name, val);
  3308. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3309. self.selection();
  3310. }
  3311. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3312. self.selection();
  3313. }
  3314. return self;
  3315. };
  3316. });
  3317. _each('cut,copy,paste'.split(','), function(i, name) {
  3318. KCmd.prototype[name] = function() {
  3319. var self = this;
  3320. if (!self.doc.queryCommandSupported(name)) {
  3321. throw 'not supported';
  3322. }
  3323. self.select();
  3324. _nativeCommand(self.doc, name, null);
  3325. return self;
  3326. };
  3327. });
  3328. function _cmd(mixed) {
  3329. if (mixed.nodeName) {
  3330. var doc = _getDoc(mixed);
  3331. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3332. }
  3333. return new KCmd(mixed);
  3334. }
  3335. K.CmdClass = KCmd;
  3336. K.cmd = _cmd;
  3337. function _drag(options) {
  3338. var moveEl = options.moveEl,
  3339. moveFn = options.moveFn,
  3340. clickEl = options.clickEl || moveEl,
  3341. beforeDrag = options.beforeDrag,
  3342. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3343. var docs = [document];
  3344. if (iframeFix) {
  3345. K('iframe').each(function() {
  3346. var src = _formatUrl(this.src || '', 'absolute');
  3347. if (/^https?:\/\//.test(src)) {
  3348. return;
  3349. }
  3350. var doc;
  3351. try {
  3352. doc = _iframeDoc(this);
  3353. } catch(e) {}
  3354. if (doc) {
  3355. var pos = K(this).pos();
  3356. K(doc).data('pos-x', pos.x);
  3357. K(doc).data('pos-y', pos.y);
  3358. docs.push(doc);
  3359. }
  3360. });
  3361. }
  3362. clickEl.mousedown(function(e) {
  3363. e.stopPropagation();
  3364. var self = clickEl.get(),
  3365. x = _removeUnit(moveEl.css('left')),
  3366. y = _removeUnit(moveEl.css('top')),
  3367. width = moveEl.width(),
  3368. height = moveEl.height(),
  3369. pageX = e.pageX,
  3370. pageY = e.pageY;
  3371. if (beforeDrag) {
  3372. beforeDrag();
  3373. }
  3374. function moveListener(e) {
  3375. e.preventDefault();
  3376. var kdoc = K(_getDoc(e.target));
  3377. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3378. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3379. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3380. }
  3381. function selectListener(e) {
  3382. e.preventDefault();
  3383. }
  3384. function upListener(e) {
  3385. e.preventDefault();
  3386. K(docs).unbind('mousemove', moveListener)
  3387. .unbind('mouseup', upListener)
  3388. .unbind('selectstart', selectListener);
  3389. if (self.releaseCapture) {
  3390. self.releaseCapture();
  3391. }
  3392. }
  3393. K(docs).mousemove(moveListener)
  3394. .mouseup(upListener)
  3395. .bind('selectstart', selectListener);
  3396. if (self.setCapture) {
  3397. self.setCapture();
  3398. }
  3399. });
  3400. }
  3401. function KWidget(options) {
  3402. this.init(options);
  3403. }
  3404. _extend(KWidget, {
  3405. init : function(options) {
  3406. var self = this;
  3407. self.name = options.name || '';
  3408. self.doc = options.doc || document;
  3409. self.win = _getWin(self.doc);
  3410. self.x = _addUnit(options.x);
  3411. self.y = _addUnit(options.y);
  3412. self.z = options.z;
  3413. self.width = _addUnit(options.width);
  3414. self.height = _addUnit(options.height);
  3415. self.div = K('<div style="display:block;"></div>');
  3416. self.options = options;
  3417. self._alignEl = options.alignEl;
  3418. if (self.width) {
  3419. self.div.css('width', self.width);
  3420. }
  3421. if (self.height) {
  3422. self.div.css('height', self.height);
  3423. }
  3424. if (self.z) {
  3425. self.div.css({
  3426. position : 'absolute',
  3427. left : self.x,
  3428. top : self.y,
  3429. 'z-index' : self.z
  3430. });
  3431. }
  3432. if (self.z && (self.x === undefined || self.y === undefined)) {
  3433. self.autoPos(self.width, self.height);
  3434. }
  3435. if (options.cls) {
  3436. self.div.addClass(options.cls);
  3437. }
  3438. if (options.shadowMode) {
  3439. self.div.addClass('ke-shadow');
  3440. }
  3441. if (options.css) {
  3442. self.div.css(options.css);
  3443. }
  3444. if (options.src) {
  3445. K(options.src).replaceWith(self.div);
  3446. } else {
  3447. K(self.doc.body).append(self.div);
  3448. }
  3449. if (options.html) {
  3450. self.div.html(options.html);
  3451. }
  3452. if (options.autoScroll) {
  3453. if (_IE && _V < 7 || _QUIRKS) {
  3454. var scrollPos = _getScrollPos();
  3455. K(self.win).bind('scroll', function(e) {
  3456. var pos = _getScrollPos(),
  3457. diffX = pos.x - scrollPos.x,
  3458. diffY = pos.y - scrollPos.y;
  3459. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3460. });
  3461. } else {
  3462. self.div.css('position', 'fixed');
  3463. }
  3464. }
  3465. },
  3466. pos : function(x, y, updateProp) {
  3467. var self = this;
  3468. updateProp = _undef(updateProp, true);
  3469. if (x !== null) {
  3470. x = x < 0 ? 0 : _addUnit(x);
  3471. self.div.css('left', x);
  3472. if (updateProp) {
  3473. self.x = x;
  3474. }
  3475. }
  3476. if (y !== null) {
  3477. y = y < 0 ? 0 : _addUnit(y);
  3478. self.div.css('top', y);
  3479. if (updateProp) {
  3480. self.y = y;
  3481. }
  3482. }
  3483. return self;
  3484. },
  3485. autoPos : function(width, height) {
  3486. var self = this,
  3487. w = _removeUnit(width) || 0,
  3488. h = _removeUnit(height) || 0,
  3489. scrollPos = _getScrollPos();
  3490. if (self._alignEl) {
  3491. var knode = K(self._alignEl),
  3492. pos = knode.pos(),
  3493. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3494. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3495. x = diffX < 0 ? pos.x : pos.x + diffX;
  3496. y = diffY < 0 ? pos.y : pos.y + diffY;
  3497. } else {
  3498. var docEl = _docElement(self.doc);
  3499. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3500. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3501. }
  3502. if (!(_IE && _V < 7 || _QUIRKS)) {
  3503. x -= scrollPos.x;
  3504. y -= scrollPos.y;
  3505. }
  3506. return self.pos(x, y);
  3507. },
  3508. remove : function() {
  3509. var self = this;
  3510. if (_IE && _V < 7 || _QUIRKS) {
  3511. K(self.win).unbind('scroll');
  3512. }
  3513. self.div.remove();
  3514. _each(self, function(i) {
  3515. self[i] = null;
  3516. });
  3517. return this;
  3518. },
  3519. show : function() {
  3520. this.div.show();
  3521. return this;
  3522. },
  3523. hide : function() {
  3524. this.div.hide();
  3525. return this;
  3526. },
  3527. draggable : function(options) {
  3528. var self = this;
  3529. options = options || {};
  3530. options.moveEl = self.div;
  3531. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3532. if ((x = x + diffX) < 0) {
  3533. x = 0;
  3534. }
  3535. if ((y = y + diffY) < 0) {
  3536. y = 0;
  3537. }
  3538. self.pos(x, y);
  3539. };
  3540. _drag(options);
  3541. return self;
  3542. }
  3543. });
  3544. function _widget(options) {
  3545. return new KWidget(options);
  3546. }
  3547. K.WidgetClass = KWidget;
  3548. K.widget = _widget;
  3549. function _iframeDoc(iframe) {
  3550. iframe = _get(iframe);
  3551. //return iframe.contentWindow.document || iframe.contentDocument;
  3552. return iframe.contentDocument || iframe.contentWindow.document;
  3553. }
  3554. var html, _direction = '';
  3555. if ((html = document.getElementsByTagName('html'))) {
  3556. _direction = html[0].dir;
  3557. }
  3558. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3559. var arr = [
  3560. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3561. '<head><meta charset="utf-8" />',
  3562. '<title></title>',
  3563. '<style>',
  3564. 'html {margin:0;padding:0;}',
  3565. 'body {margin:0;padding:5px;}',
  3566. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3567. 'body, p, div {word-wrap: break-word;}',
  3568. 'p {margin:5px 0;}',
  3569. 'table {border-collapse:collapse;}',
  3570. 'img {border:0;}',
  3571. 'noscript {display:none;}',
  3572. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3573. 'img.ke-flash {',
  3574. ' border:1px solid #AAA;',
  3575. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3576. ' background-position:center center;',
  3577. ' background-repeat:no-repeat;',
  3578. ' width:100px;',
  3579. ' height:100px;',
  3580. '}',
  3581. 'img.ke-rm {',
  3582. ' border:1px solid #AAA;',
  3583. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3584. ' background-position:center center;',
  3585. ' background-repeat:no-repeat;',
  3586. ' width:100px;',
  3587. ' height:100px;',
  3588. '}',
  3589. 'img.ke-media {',
  3590. ' border:1px solid #AAA;',
  3591. ' background-image:url(' + themesPath + 'common/media.gif);',
  3592. ' background-position:center center;',
  3593. ' background-repeat:no-repeat;',
  3594. ' width:100px;',
  3595. ' height:100px;',
  3596. '}',
  3597. 'img.ke-anchor {',
  3598. ' border:1px dashed #666;',
  3599. ' width:16px;',
  3600. ' height:16px;',
  3601. '}',
  3602. '.ke-script, .ke-noscript, .ke-display-none {',
  3603. ' display:none;',
  3604. ' font-size:0;',
  3605. ' width:0;',
  3606. ' height:0;',
  3607. '}',
  3608. '.ke-pagebreak {',
  3609. ' border:1px dotted #AAA !important;',
  3610. ' font-size:0;',
  3611. ' height:2px; !important',
  3612. '}',
  3613. '</style>'
  3614. ];
  3615. if (!_isArray(cssPath)) {
  3616. cssPath = [cssPath];
  3617. }
  3618. _each(cssPath, function(i, path) {
  3619. if (path) {
  3620. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3621. }
  3622. });
  3623. if (cssData) {
  3624. arr.push('<style>' + cssData + '</style>');
  3625. }
  3626. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3627. return arr.join('\n');
  3628. }
  3629. function _elementVal(knode, val) {
  3630. if (knode.hasVal()) {
  3631. if (val === undefined) {
  3632. var html = knode.val();
  3633. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3634. return html;
  3635. }
  3636. return knode.val(val);
  3637. }
  3638. return knode.html(val);
  3639. }
  3640. function KEdit(options) {
  3641. this.init(options);
  3642. }
  3643. _extend(KEdit, KWidget, {
  3644. init : function(options) {
  3645. var self = this;
  3646. KEdit.parent.init.call(self, options);
  3647. self.srcElement = K(options.srcElement);
  3648. self.div.addClass('ke-edit');
  3649. self.designMode = _undef(options.designMode, true);
  3650. self.beforeGetHtml = options.beforeGetHtml;
  3651. self.beforeSetHtml = options.beforeSetHtml;
  3652. self.afterSetHtml = options.afterSetHtml;
  3653. var themesPath = _undef(options.themesPath, ''),
  3654. bodyClass = options.bodyClass,
  3655. cssPath = options.cssPath,
  3656. cssData = options.cssData,
  3657. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3658. srcScript = ('document.open();' +
  3659. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3660. 'document.close();'),
  3661. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3662. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3663. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3664. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3665. self.iframe.attr('tabindex', self.tabIndex);
  3666. self.textarea.attr('tabindex', self.tabIndex);
  3667. if (self.width) {
  3668. self.setWidth(self.width);
  3669. }
  3670. if (self.height) {
  3671. self.setHeight(self.height);
  3672. }
  3673. if (self.designMode) {
  3674. self.textarea.hide();
  3675. } else {
  3676. self.iframe.hide();
  3677. }
  3678. function ready() {
  3679. var doc = _iframeDoc(self.iframe);
  3680. doc.open();
  3681. if (isDocumentDomain) {
  3682. doc.domain = document.domain;
  3683. }
  3684. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3685. doc.close();
  3686. self.win = self.iframe[0].contentWindow;
  3687. self.doc = doc;
  3688. var cmd = _cmd(doc);
  3689. self.afterChange(function(e) {
  3690. cmd.selection();
  3691. });
  3692. if (_WEBKIT) {
  3693. K(doc).click(function(e) {
  3694. if (K(e.target).name === 'img') {
  3695. cmd.selection(true);
  3696. cmd.range.selectNode(e.target);
  3697. cmd.select();
  3698. }
  3699. });
  3700. }
  3701. if (_IE) {
  3702. self._mousedownHandler = function() {
  3703. var newRange = cmd.range.cloneRange();
  3704. newRange.shrink();
  3705. if (newRange.isControl()) {
  3706. self.blur();
  3707. }
  3708. };
  3709. K(document).mousedown(self._mousedownHandler);
  3710. K(doc).keydown(function(e) {
  3711. if (e.which == 8) {
  3712. cmd.selection();
  3713. var rng = cmd.range;
  3714. if (rng.isControl()) {
  3715. rng.collapse(true);
  3716. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3717. e.preventDefault();
  3718. }
  3719. }
  3720. });
  3721. }
  3722. self.cmd = cmd;
  3723. self.html(_elementVal(self.srcElement));
  3724. if (_IE) {
  3725. doc.body.disabled = true;
  3726. doc.body.contentEditable = true;
  3727. doc.body.removeAttribute('disabled');
  3728. } else {
  3729. doc.designMode = 'on';
  3730. }
  3731. if (options.afterCreate) {
  3732. options.afterCreate.call(self);
  3733. }
  3734. }
  3735. if (isDocumentDomain) {
  3736. self.iframe.bind('load', function(e) {
  3737. self.iframe.unbind('load');
  3738. if (_IE) {
  3739. ready();
  3740. } else {
  3741. setTimeout(ready, 0);
  3742. }
  3743. });
  3744. }
  3745. self.div.append(self.iframe);
  3746. self.div.append(self.textarea);
  3747. self.srcElement.hide();
  3748. !isDocumentDomain && ready();
  3749. },
  3750. setWidth : function(val) {
  3751. var self = this;
  3752. val = _addUnit(val);
  3753. self.width = val;
  3754. self.div.css('width', val);
  3755. return self;
  3756. },
  3757. setHeight : function(val) {
  3758. var self = this;
  3759. val = _addUnit(val);
  3760. self.height = val;
  3761. self.div.css('height', val);
  3762. self.iframe.css('height', val);
  3763. if ((_IE && _V < 8) || _QUIRKS) {
  3764. val = _addUnit(_removeUnit(val) - 2);
  3765. }
  3766. self.textarea.css('height', val);
  3767. return self;
  3768. },
  3769. remove : function() {
  3770. var self = this, doc = self.doc;
  3771. K(doc.body).unbind();
  3772. K(doc).unbind();
  3773. K(self.win).unbind();
  3774. if (self._mousedownHandler) {
  3775. K(document).unbind('mousedown', self._mousedownHandler);
  3776. }
  3777. _elementVal(self.srcElement, self.html());
  3778. self.srcElement.show();
  3779. doc.write('');
  3780. self.iframe.unbind();
  3781. self.textarea.unbind();
  3782. KEdit.parent.remove.call(self);
  3783. },
  3784. html : function(val, isFull) {
  3785. var self = this, doc = self.doc;
  3786. if (self.designMode) {
  3787. var body = doc.body;
  3788. if (val === undefined) {
  3789. if (isFull) {
  3790. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3791. } else {
  3792. val = body.innerHTML;
  3793. }
  3794. if (self.beforeGetHtml) {
  3795. val = self.beforeGetHtml(val);
  3796. }
  3797. if (_GECKO && val == '<br />') {
  3798. val = '';
  3799. }
  3800. return val;
  3801. }
  3802. if (self.beforeSetHtml) {
  3803. val = self.beforeSetHtml(val);
  3804. }
  3805. if (_IE && _V >= 9) {
  3806. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3807. }
  3808. K(body).html(val);
  3809. if (self.afterSetHtml) {
  3810. self.afterSetHtml();
  3811. }
  3812. return self;
  3813. }
  3814. if (val === undefined) {
  3815. return self.textarea.val();
  3816. }
  3817. self.textarea.val(val);
  3818. return self;
  3819. },
  3820. design : function(bool) {
  3821. var self = this, val;
  3822. if (bool === undefined ? !self.designMode : bool) {
  3823. if (!self.designMode) {
  3824. val = self.html();
  3825. self.designMode = true;
  3826. self.html(val);
  3827. self.textarea.hide();
  3828. self.iframe.show();
  3829. }
  3830. } else {
  3831. if (self.designMode) {
  3832. val = self.html();
  3833. self.designMode = false;
  3834. self.html(val);
  3835. self.iframe.hide();
  3836. self.textarea.show();
  3837. }
  3838. }
  3839. return self.focus();
  3840. },
  3841. focus : function() {
  3842. var self = this;
  3843. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3844. return self;
  3845. },
  3846. blur : function() {
  3847. var self = this;
  3848. if (_IE) {
  3849. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3850. self.div.append(input);
  3851. input[0].focus();
  3852. input.remove();
  3853. } else {
  3854. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3855. }
  3856. return self;
  3857. },
  3858. afterChange : function(fn) {
  3859. var self = this, doc = self.doc, body = doc.body;
  3860. K(doc).keyup(function(e) {
  3861. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3862. fn(e);
  3863. }
  3864. });
  3865. K(doc).mouseup(fn).contextmenu(fn);
  3866. K(self.win).blur(fn);
  3867. function timeoutHandler(e) {
  3868. setTimeout(function() {
  3869. fn(e);
  3870. }, 1);
  3871. }
  3872. K(body).bind('paste', timeoutHandler);
  3873. K(body).bind('cut', timeoutHandler);
  3874. return self;
  3875. }
  3876. });
  3877. function _edit(options) {
  3878. return new KEdit(options);
  3879. }
  3880. K.EditClass = KEdit;
  3881. K.edit = _edit;
  3882. K.iframeDoc = _iframeDoc;
  3883. function _selectToolbar(name, fn) {
  3884. var self = this,
  3885. knode = self.get(name);
  3886. if (knode) {
  3887. if (knode.hasClass('ke-disabled')) {
  3888. return;
  3889. }
  3890. fn(knode);
  3891. }
  3892. }
  3893. function KToolbar(options) {
  3894. this.init(options);
  3895. }
  3896. _extend(KToolbar, KWidget, {
  3897. init : function(options) {
  3898. var self = this;
  3899. KToolbar.parent.init.call(self, options);
  3900. self.disableMode = _undef(options.disableMode, false);
  3901. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3902. self._itemMap = {};
  3903. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3904. e.preventDefault();
  3905. }).attr('unselectable', 'on');
  3906. function find(target) {
  3907. var knode = K(target);
  3908. if (knode.hasClass('ke-outline')) {
  3909. return knode;
  3910. }
  3911. if (knode.hasClass('ke-toolbar-icon')) {
  3912. return knode.parent();
  3913. }
  3914. }
  3915. function hover(e, method) {
  3916. var knode = find(e.target);
  3917. if (knode) {
  3918. if (knode.hasClass('ke-disabled')) {
  3919. return;
  3920. }
  3921. if (knode.hasClass('ke-selected')) {
  3922. return;
  3923. }
  3924. knode[method]('ke-on');
  3925. }
  3926. }
  3927. self.div.mouseover(function(e) {
  3928. hover(e, 'addClass');
  3929. })
  3930. .mouseout(function(e) {
  3931. hover(e, 'removeClass');
  3932. })
  3933. .click(function(e) {
  3934. var knode = find(e.target);
  3935. if (knode) {
  3936. if (knode.hasClass('ke-disabled')) {
  3937. return;
  3938. }
  3939. self.options.click.call(this, e, knode.attr('data-name'));
  3940. }
  3941. });
  3942. },
  3943. get : function(name) {
  3944. if (this._itemMap[name]) {
  3945. return this._itemMap[name];
  3946. }
  3947. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3948. },
  3949. select : function(name) {
  3950. _selectToolbar.call(this, name, function(knode) {
  3951. knode.addClass('ke-selected');
  3952. });
  3953. return self;
  3954. },
  3955. unselect : function(name) {
  3956. _selectToolbar.call(this, name, function(knode) {
  3957. knode.removeClass('ke-selected').removeClass('ke-on');
  3958. });
  3959. return self;
  3960. },
  3961. enable : function(name) {
  3962. var self = this,
  3963. knode = name.get ? name : self.get(name);
  3964. if (knode) {
  3965. knode.removeClass('ke-disabled');
  3966. knode.opacity(1);
  3967. }
  3968. return self;
  3969. },
  3970. disable : function(name) {
  3971. var self = this,
  3972. knode = name.get ? name : self.get(name);
  3973. if (knode) {
  3974. knode.removeClass('ke-selected').addClass('ke-disabled');
  3975. knode.opacity(0.5);
  3976. }
  3977. return self;
  3978. },
  3979. disableAll : function(bool, noDisableItems) {
  3980. var self = this, map = self.noDisableItemMap, item;
  3981. if (noDisableItems) {
  3982. map = _toMap(noDisableItems);
  3983. }
  3984. if (bool === undefined ? !self.disableMode : bool) {
  3985. K('span.ke-outline', self.div).each(function() {
  3986. var knode = K(this),
  3987. name = knode[0].getAttribute('data-name', 2);
  3988. if (!map[name]) {
  3989. self.disable(knode);
  3990. }
  3991. });
  3992. self.disableMode = true;
  3993. } else {
  3994. K('span.ke-outline', self.div).each(function() {
  3995. var knode = K(this),
  3996. name = knode[0].getAttribute('data-name', 2);
  3997. if (!map[name]) {
  3998. self.enable(knode);
  3999. }
  4000. });
  4001. self.disableMode = false;
  4002. }
  4003. return self;
  4004. }
  4005. });
  4006. function _toolbar(options) {
  4007. return new KToolbar(options);
  4008. }
  4009. K.ToolbarClass = KToolbar;
  4010. K.toolbar = _toolbar;
  4011. function KMenu(options) {
  4012. this.init(options);
  4013. }
  4014. _extend(KMenu, KWidget, {
  4015. init : function(options) {
  4016. var self = this;
  4017. options.z = options.z || 811213;
  4018. KMenu.parent.init.call(self, options);
  4019. self.centerLineMode = _undef(options.centerLineMode, true);
  4020. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4021. e.stopPropagation();
  4022. }).attr('unselectable', 'on');
  4023. },
  4024. addItem : function(item) {
  4025. var self = this;
  4026. if (item.title === '-') {
  4027. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4028. return;
  4029. }
  4030. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4031. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4032. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4033. height = _addUnit(item.height),
  4034. iconClass = _undef(item.iconClass, '');
  4035. self.div.append(itemDiv);
  4036. if (height) {
  4037. itemDiv.css('height', height);
  4038. rightDiv.css('line-height', height);
  4039. }
  4040. var centerDiv;
  4041. if (self.centerLineMode) {
  4042. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4043. if (height) {
  4044. centerDiv.css('height', height);
  4045. }
  4046. }
  4047. itemDiv.mouseover(function(e) {
  4048. K(this).addClass('ke-menu-item-on');
  4049. if (centerDiv) {
  4050. centerDiv.addClass('ke-menu-item-center-on');
  4051. }
  4052. })
  4053. .mouseout(function(e) {
  4054. K(this).removeClass('ke-menu-item-on');
  4055. if (centerDiv) {
  4056. centerDiv.removeClass('ke-menu-item-center-on');
  4057. }
  4058. })
  4059. .click(function(e) {
  4060. item.click.call(K(this));
  4061. e.stopPropagation();
  4062. })
  4063. .append(leftDiv);
  4064. if (centerDiv) {
  4065. itemDiv.append(centerDiv);
  4066. }
  4067. itemDiv.append(rightDiv);
  4068. if (item.checked) {
  4069. iconClass = 'ke-icon-checked';
  4070. }
  4071. if (iconClass !== '') {
  4072. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4073. }
  4074. rightDiv.html(item.title);
  4075. return self;
  4076. },
  4077. remove : function() {
  4078. var self = this;
  4079. if (self.options.beforeRemove) {
  4080. self.options.beforeRemove.call(self);
  4081. }
  4082. K('.ke-menu-item', self.div[0]).unbind();
  4083. KMenu.parent.remove.call(self);
  4084. return self;
  4085. }
  4086. });
  4087. function _menu(options) {
  4088. return new KMenu(options);
  4089. }
  4090. K.MenuClass = KMenu;
  4091. K.menu = _menu;
  4092. function KColorPicker(options) {
  4093. this.init(options);
  4094. }
  4095. _extend(KColorPicker, KWidget, {
  4096. init : function(options) {
  4097. var self = this;
  4098. options.z = options.z || 811213;
  4099. KColorPicker.parent.init.call(self, options);
  4100. var colors = options.colors || [
  4101. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4102. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4103. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4104. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4105. ];
  4106. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4107. self._cells = [];
  4108. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4109. e.stopPropagation();
  4110. }).attr('unselectable', 'on');
  4111. var table = self.doc.createElement('table');
  4112. self.div.append(table);
  4113. table.className = 'ke-colorpicker-table';
  4114. table.cellPadding = 0;
  4115. table.cellSpacing = 0;
  4116. table.border = 0;
  4117. var row = table.insertRow(0), cell = row.insertCell(0);
  4118. cell.colSpan = colors[0].length;
  4119. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4120. for (var i = 0; i < colors.length; i++) {
  4121. row = table.insertRow(i + 1);
  4122. for (var j = 0; j < colors[i].length; j++) {
  4123. cell = row.insertCell(j);
  4124. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4125. }
  4126. }
  4127. },
  4128. _addAttr : function(cell, color, cls) {
  4129. var self = this;
  4130. cell = K(cell).addClass(cls);
  4131. if (self.selectedColor === color.toLowerCase()) {
  4132. cell.addClass('ke-colorpicker-cell-selected');
  4133. }
  4134. cell.attr('title', color || self.options.noColor);
  4135. cell.mouseover(function(e) {
  4136. K(this).addClass('ke-colorpicker-cell-on');
  4137. });
  4138. cell.mouseout(function(e) {
  4139. K(this).removeClass('ke-colorpicker-cell-on');
  4140. });
  4141. cell.click(function(e) {
  4142. e.stop();
  4143. self.options.click.call(K(this), color);
  4144. });
  4145. if (color) {
  4146. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4147. } else {
  4148. cell.html(self.options.noColor);
  4149. }
  4150. K(cell).attr('unselectable', 'on');
  4151. self._cells.push(cell);
  4152. },
  4153. remove : function() {
  4154. var self = this;
  4155. _each(self._cells, function() {
  4156. this.unbind();
  4157. });
  4158. KColorPicker.parent.remove.call(self);
  4159. return self;
  4160. }
  4161. });
  4162. function _colorpicker(options) {
  4163. return new KColorPicker(options);
  4164. }
  4165. K.ColorPickerClass = KColorPicker;
  4166. K.colorpicker = _colorpicker;
  4167. function KUploadButton(options) {
  4168. this.init(options);
  4169. }
  4170. _extend(KUploadButton, {
  4171. init : function(options) {
  4172. var self = this,
  4173. button = K(options.button),
  4174. fieldName = options.fieldName || 'file',
  4175. url = options.url || '',
  4176. title = button.val(),
  4177. extraParams = options.extraParams || {},
  4178. cls = button[0].className || '',
  4179. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4180. options.afterError = options.afterError || function(str) {
  4181. alert(str);
  4182. };
  4183. var hiddenElements = [];
  4184. for(var k in extraParams){
  4185. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4186. }
  4187. var html = [
  4188. '<div class="ke-inline-block ' + cls + '">',
  4189. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4190. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4191. '<span class="ke-button-common">',
  4192. hiddenElements.join(''),
  4193. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4194. '</span>',
  4195. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4196. (options.form ? '</div>' : '</form>'),
  4197. '</div>'].join('');
  4198. var div = K(html, button.doc);
  4199. button.hide();
  4200. button.before(div);
  4201. self.div = div;
  4202. self.button = button;
  4203. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4204. self.form = options.form ? K(options.form) : K('form', div);
  4205. self.fileBox = K('.ke-upload-file', div);
  4206. var width = options.width || K('.ke-button-common', div).width();
  4207. K('.ke-upload-area', div).width(width);
  4208. self.options = options;
  4209. },
  4210. submit : function() {
  4211. var self = this,
  4212. iframe = self.iframe;
  4213. iframe.bind('load', function() {
  4214. iframe.unbind();
  4215. var tempForm = document.createElement('form');
  4216. self.fileBox.before(tempForm);
  4217. K(tempForm).append(self.fileBox);
  4218. tempForm.reset();
  4219. K(tempForm).remove(true);
  4220. var doc = K.iframeDoc(iframe),
  4221. pre = doc.getElementsByTagName('pre')[0],
  4222. str = '', data;
  4223. if (pre) {
  4224. str = pre.innerHTML;
  4225. } else {
  4226. str = doc.body.innerHTML;
  4227. }
  4228. str = _unescape(str);
  4229. iframe[0].src = 'javascript:false';
  4230. try {
  4231. data = K.json(str);
  4232. } catch (e) {
  4233. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4234. }
  4235. if (data) {
  4236. self.options.afterUpload.call(self, data);
  4237. }
  4238. });
  4239. self.form[0].submit();
  4240. return self;
  4241. },
  4242. remove : function() {
  4243. var self = this;
  4244. if (self.fileBox) {
  4245. self.fileBox.unbind();
  4246. }
  4247. self.iframe.remove();
  4248. self.div.remove();
  4249. self.button.show();
  4250. return self;
  4251. }
  4252. });
  4253. function _uploadbutton(options) {
  4254. return new KUploadButton(options);
  4255. }
  4256. K.UploadButtonClass = KUploadButton;
  4257. K.uploadbutton = _uploadbutton;
  4258. function _createButton(arg) {
  4259. arg = arg || {};
  4260. var name = arg.name || '',
  4261. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4262. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4263. if (arg.click) {
  4264. btn.click(arg.click);
  4265. }
  4266. span.append(btn);
  4267. return span;
  4268. }
  4269. function KDialog(options) {
  4270. this.init(options);
  4271. }
  4272. _extend(KDialog, KWidget, {
  4273. init : function(options) {
  4274. var self = this;
  4275. var shadowMode = _undef(options.shadowMode, true);
  4276. options.z = options.z || 811213;
  4277. options.shadowMode = false;
  4278. options.autoScroll = _undef(options.autoScroll, true);
  4279. KDialog.parent.init.call(self, options);
  4280. var title = options.title,
  4281. body = K(options.body, self.doc),
  4282. previewBtn = options.previewBtn,
  4283. yesBtn = options.yesBtn,
  4284. noBtn = options.noBtn,
  4285. closeBtn = options.closeBtn,
  4286. showMask = _undef(options.showMask, true);
  4287. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4288. e.stopPropagation();
  4289. });
  4290. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4291. if (_IE && _V < 7) {
  4292. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4293. } else if (shadowMode) {
  4294. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4295. }
  4296. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4297. contentDiv.append(headerDiv);
  4298. headerDiv.html(title);
  4299. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4300. headerDiv.append(self.closeIcon);
  4301. self.draggable({
  4302. clickEl : headerDiv,
  4303. beforeDrag : options.beforeDrag
  4304. });
  4305. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4306. contentDiv.append(bodyDiv);
  4307. bodyDiv.append(body);
  4308. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4309. if (previewBtn || yesBtn || noBtn) {
  4310. contentDiv.append(footerDiv);
  4311. }
  4312. _each([
  4313. { btn : previewBtn, name : 'preview' },
  4314. { btn : yesBtn, name : 'yes' },
  4315. { btn : noBtn, name : 'no' }
  4316. ], function() {
  4317. if (this.btn) {
  4318. var button = _createButton(this.btn);
  4319. button.addClass('ke-dialog-' + this.name);
  4320. footerDiv.append(button);
  4321. }
  4322. });
  4323. if (self.height) {
  4324. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4325. }
  4326. self.div.width(self.div.width());
  4327. self.div.height(self.div.height());
  4328. self.mask = null;
  4329. if (showMask) {
  4330. var docEl = _docElement(self.doc),
  4331. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4332. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4333. self.mask = _widget({
  4334. x : 0,
  4335. y : 0,
  4336. z : self.z - 1,
  4337. cls : 'ke-dialog-mask',
  4338. width : docWidth,
  4339. height : docHeight
  4340. });
  4341. }
  4342. self.autoPos(self.div.width(), self.div.height());
  4343. self.footerDiv = footerDiv;
  4344. self.bodyDiv = bodyDiv;
  4345. self.headerDiv = headerDiv;
  4346. self.isLoading = false;
  4347. },
  4348. setMaskIndex : function(z) {
  4349. var self = this;
  4350. self.mask.div.css('z-index', z);
  4351. },
  4352. showLoading : function(msg) {
  4353. msg = _undef(msg, '');
  4354. var self = this, body = self.bodyDiv;
  4355. 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>')
  4356. .width(body.width()).height(body.height())
  4357. .css('top', self.headerDiv.height() + 'px');
  4358. body.css('visibility', 'hidden').after(self.loading);
  4359. self.isLoading = true;
  4360. return self;
  4361. },
  4362. hideLoading : function() {
  4363. this.loading && this.loading.remove();
  4364. this.bodyDiv.css('visibility', 'visible');
  4365. this.isLoading = false;
  4366. return this;
  4367. },
  4368. remove : function() {
  4369. var self = this;
  4370. if (self.options.beforeRemove) {
  4371. self.options.beforeRemove.call(self);
  4372. }
  4373. self.mask && self.mask.remove();
  4374. self.iframeMask && self.iframeMask.remove();
  4375. self.closeIcon.unbind();
  4376. K('input', self.div).unbind();
  4377. K('button', self.div).unbind();
  4378. self.footerDiv.unbind();
  4379. self.bodyDiv.unbind();
  4380. self.headerDiv.unbind();
  4381. K('iframe', self.div).each(function() {
  4382. K(this).remove();
  4383. });
  4384. KDialog.parent.remove.call(self);
  4385. return self;
  4386. }
  4387. });
  4388. function _dialog(options) {
  4389. return new KDialog(options);
  4390. }
  4391. K.DialogClass = KDialog;
  4392. K.dialog = _dialog;
  4393. function _tabs(options) {
  4394. var self = _widget(options),
  4395. remove = self.remove,
  4396. afterSelect = options.afterSelect,
  4397. div = self.div,
  4398. liList = [];
  4399. div.addClass('ke-tabs')
  4400. .bind('contextmenu,mousedown,mousemove', function(e) {
  4401. e.preventDefault();
  4402. });
  4403. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4404. div.append(ul);
  4405. self.add = function(tab) {
  4406. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4407. li.data('tab', tab);
  4408. liList.push(li);
  4409. ul.append(li);
  4410. };
  4411. self.selectedIndex = 0;
  4412. self.select = function(index) {
  4413. self.selectedIndex = index;
  4414. _each(liList, function(i, li) {
  4415. li.unbind();
  4416. if (i === index) {
  4417. li.addClass('ke-tabs-li-selected');
  4418. K(li.data('tab').panel).show('');
  4419. } else {
  4420. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4421. .mouseover(function() {
  4422. K(this).addClass('ke-tabs-li-on');
  4423. })
  4424. .mouseout(function() {
  4425. K(this).removeClass('ke-tabs-li-on');
  4426. })
  4427. .click(function() {
  4428. self.select(i);
  4429. });
  4430. K(li.data('tab').panel).hide();
  4431. }
  4432. });
  4433. if (afterSelect) {
  4434. afterSelect.call(self, index);
  4435. }
  4436. };
  4437. self.remove = function() {
  4438. _each(liList, function() {
  4439. this.remove();
  4440. });
  4441. ul.remove();
  4442. remove.call(self);
  4443. };
  4444. return self;
  4445. }
  4446. K.tabs = _tabs;
  4447. function _loadScript(url, fn) {
  4448. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4449. script = document.createElement('script');
  4450. head.appendChild(script);
  4451. script.src = url;
  4452. script.charset = 'utf-8';
  4453. script.onload = script.onreadystatechange = function() {
  4454. if (!this.readyState || this.readyState === 'loaded') {
  4455. if (fn) {
  4456. fn();
  4457. }
  4458. script.onload = script.onreadystatechange = null;
  4459. head.removeChild(script);
  4460. }
  4461. };
  4462. }
  4463. function _chopQuery(url) {
  4464. var index = url.indexOf('?');
  4465. return index > 0 ? url.substr(0, index) : url;
  4466. }
  4467. function _loadStyle(url) {
  4468. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4469. link = document.createElement('link'),
  4470. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4471. var links = K('link[rel="stylesheet"]', head);
  4472. for (var i = 0, len = links.length; i < len; i++) {
  4473. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4474. return;
  4475. }
  4476. }
  4477. head.appendChild(link);
  4478. link.href = url;
  4479. link.rel = 'stylesheet';
  4480. }
  4481. function _ajax(url, fn, method, param, dataType) {
  4482. method = method || 'GET';
  4483. dataType = dataType || 'json';
  4484. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4485. xhr.open(method, url, true);
  4486. xhr.onreadystatechange = function () {
  4487. if (xhr.readyState == 4 && xhr.status == 200) {
  4488. if (fn) {
  4489. var data = _trim(xhr.responseText);
  4490. if (dataType == 'json') {
  4491. data = _json(data);
  4492. }
  4493. fn(data);
  4494. }
  4495. }
  4496. };
  4497. if (method == 'POST') {
  4498. var params = [];
  4499. _each(param, function(key, val) {
  4500. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4501. });
  4502. try {
  4503. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4504. } catch (e) {}
  4505. xhr.send(params.join('&'));
  4506. } else {
  4507. xhr.send(null);
  4508. }
  4509. }
  4510. K.loadScript = _loadScript;
  4511. K.loadStyle = _loadStyle;
  4512. K.ajax = _ajax;
  4513. var _plugins = {};
  4514. function _plugin(name, fn) {
  4515. if (name === undefined) {
  4516. return _plugins;
  4517. }
  4518. if (!fn) {
  4519. return _plugins[name];
  4520. }
  4521. _plugins[name] = fn;
  4522. }
  4523. var _language = {};
  4524. function _parseLangKey(key) {
  4525. var match, ns = 'core';
  4526. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4527. ns = match[1];
  4528. key = match[2];
  4529. }
  4530. return { ns : ns, key : key };
  4531. }
  4532. function _lang(mixed, langType) {
  4533. langType = langType === undefined ? K.options.langType : langType;
  4534. if (typeof mixed === 'string') {
  4535. if (!_language[langType]) {
  4536. return 'no language';
  4537. }
  4538. var pos = mixed.length - 1;
  4539. if (mixed.substr(pos) === '.') {
  4540. return _language[langType][mixed.substr(0, pos)];
  4541. }
  4542. var obj = _parseLangKey(mixed);
  4543. return _language[langType][obj.ns][obj.key];
  4544. }
  4545. _each(mixed, function(key, val) {
  4546. var obj = _parseLangKey(key);
  4547. if (!_language[langType]) {
  4548. _language[langType] = {};
  4549. }
  4550. if (!_language[langType][obj.ns]) {
  4551. _language[langType][obj.ns] = {};
  4552. }
  4553. _language[langType][obj.ns][obj.key] = val;
  4554. });
  4555. }
  4556. function _getImageFromRange(range, fn) {
  4557. if (range.collapsed) {
  4558. return;
  4559. }
  4560. range = range.cloneRange().up();
  4561. var sc = range.startContainer, so = range.startOffset;
  4562. if (!_WEBKIT && !range.isControl()) {
  4563. return;
  4564. }
  4565. var img = K(sc.childNodes[so]);
  4566. if (!img || img.name != 'img') {
  4567. return;
  4568. }
  4569. if (fn(img)) {
  4570. return img;
  4571. }
  4572. }
  4573. function _bindContextmenuEvent() {
  4574. var self = this, doc = self.edit.doc;
  4575. K(doc).contextmenu(function(e) {
  4576. if (self.menu) {
  4577. self.hideMenu();
  4578. }
  4579. if (!self.useContextmenu) {
  4580. e.preventDefault();
  4581. return;
  4582. }
  4583. if (self._contextmenus.length === 0) {
  4584. return;
  4585. }
  4586. var maxWidth = 0, items = [];
  4587. _each(self._contextmenus, function() {
  4588. if (this.title == '-') {
  4589. items.push(this);
  4590. return;
  4591. }
  4592. if (this.cond && this.cond()) {
  4593. items.push(this);
  4594. if (this.width && this.width > maxWidth) {
  4595. maxWidth = this.width;
  4596. }
  4597. }
  4598. });
  4599. while (items.length > 0 && items[0].title == '-') {
  4600. items.shift();
  4601. }
  4602. while (items.length > 0 && items[items.length - 1].title == '-') {
  4603. items.pop();
  4604. }
  4605. var prevItem = null;
  4606. _each(items, function(i) {
  4607. if (this.title == '-' && prevItem.title == '-') {
  4608. delete items[i];
  4609. }
  4610. prevItem = this;
  4611. });
  4612. if (items.length > 0) {
  4613. e.preventDefault();
  4614. var pos = K(self.edit.iframe).pos(),
  4615. menu = _menu({
  4616. x : pos.x + e.clientX,
  4617. y : pos.y + e.clientY,
  4618. width : maxWidth,
  4619. css : { visibility: 'hidden' },
  4620. shadowMode : self.shadowMode
  4621. });
  4622. _each(items, function() {
  4623. if (this.title) {
  4624. menu.addItem(this);
  4625. }
  4626. });
  4627. var docEl = _docElement(menu.doc),
  4628. menuHeight = menu.div.height();
  4629. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4630. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4631. }
  4632. menu.div.css('visibility', 'visible');
  4633. self.menu = menu;
  4634. }
  4635. });
  4636. }
  4637. function _bindNewlineEvent() {
  4638. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4639. if (_IE && newlineTag !== 'br') {
  4640. return;
  4641. }
  4642. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4643. return;
  4644. }
  4645. if (_OPERA && _V < 9) {
  4646. return;
  4647. }
  4648. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4649. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4650. function getAncestorTagName(range) {
  4651. var ancestor = K(range.commonAncestor());
  4652. while (ancestor) {
  4653. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4654. break;
  4655. }
  4656. ancestor = ancestor.parent();
  4657. }
  4658. return ancestor.name;
  4659. }
  4660. K(doc).keydown(function(e) {
  4661. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4662. return;
  4663. }
  4664. self.cmd.selection();
  4665. var tagName = getAncestorTagName(self.cmd.range);
  4666. if (tagName == 'marquee' || tagName == 'select') {
  4667. return;
  4668. }
  4669. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4670. e.preventDefault();
  4671. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4672. return;
  4673. }
  4674. if (!pSkipTagMap[tagName]) {
  4675. _nativeCommand(doc, 'formatblock', '<p>');
  4676. }
  4677. });
  4678. K(doc).keyup(function(e) {
  4679. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4680. return;
  4681. }
  4682. if (newlineTag == 'br') {
  4683. return;
  4684. }
  4685. if (_GECKO) {
  4686. var root = self.cmd.commonAncestor('p');
  4687. var a = self.cmd.commonAncestor('a');
  4688. if (a && a.text() == '') {
  4689. a.remove(true);
  4690. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4691. self.cmd.select();
  4692. }
  4693. return;
  4694. }
  4695. self.cmd.selection();
  4696. var tagName = getAncestorTagName(self.cmd.range);
  4697. if (tagName == 'marquee' || tagName == 'select') {
  4698. return;
  4699. }
  4700. if (!pSkipTagMap[tagName]) {
  4701. _nativeCommand(doc, 'formatblock', '<p>');
  4702. }
  4703. var div = self.cmd.commonAncestor('div');
  4704. if (div) {
  4705. var p = K('<p></p>'),
  4706. child = div[0].firstChild;
  4707. while (child) {
  4708. var next = child.nextSibling;
  4709. p.append(child);
  4710. child = next;
  4711. }
  4712. div.before(p);
  4713. div.remove();
  4714. self.cmd.range.selectNodeContents(p[0]);
  4715. self.cmd.select();
  4716. }
  4717. });
  4718. }
  4719. function _bindTabEvent() {
  4720. var self = this, doc = self.edit.doc;
  4721. K(doc).keydown(function(e) {
  4722. if (e.which == 9) {
  4723. e.preventDefault();
  4724. if (self.afterTab) {
  4725. self.afterTab.call(self, e);
  4726. return;
  4727. }
  4728. var cmd = self.cmd, range = cmd.range;
  4729. range.shrink();
  4730. if (range.collapsed && range.startContainer.nodeType == 1) {
  4731. range.insertNode(K('@&nbsp;', doc)[0]);
  4732. cmd.select();
  4733. }
  4734. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4735. }
  4736. });
  4737. }
  4738. function _bindFocusEvent() {
  4739. var self = this;
  4740. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4741. if (self.afterFocus) {
  4742. self.afterFocus.call(self, e);
  4743. }
  4744. }).blur(function(e) {
  4745. if (self.afterBlur) {
  4746. self.afterBlur.call(self, e);
  4747. }
  4748. });
  4749. }
  4750. function _removeBookmarkTag(html) {
  4751. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4752. }
  4753. function _removeTempTag(html) {
  4754. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4755. }
  4756. function _addBookmarkToStack(stack, bookmark) {
  4757. if (stack.length === 0) {
  4758. stack.push(bookmark);
  4759. return;
  4760. }
  4761. var prev = stack[stack.length - 1];
  4762. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4763. stack.push(bookmark);
  4764. }
  4765. }
  4766. function _undoToRedo(fromStack, toStack) {
  4767. var self = this, edit = self.edit,
  4768. body = edit.doc.body,
  4769. range, bookmark;
  4770. if (fromStack.length === 0) {
  4771. return self;
  4772. }
  4773. if (edit.designMode) {
  4774. range = self.cmd.range;
  4775. bookmark = range.createBookmark(true);
  4776. bookmark.html = body.innerHTML;
  4777. } else {
  4778. bookmark = {
  4779. html : body.innerHTML
  4780. };
  4781. }
  4782. _addBookmarkToStack(toStack, bookmark);
  4783. var prev = fromStack.pop();
  4784. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4785. prev = fromStack.pop();
  4786. }
  4787. if (edit.designMode) {
  4788. edit.html(prev.html);
  4789. if (prev.start) {
  4790. range.moveToBookmark(prev);
  4791. self.select();
  4792. }
  4793. } else {
  4794. K(body).html(_removeBookmarkTag(prev.html));
  4795. }
  4796. return self;
  4797. }
  4798. function KEditor(options) {
  4799. var self = this;
  4800. self.options = {};
  4801. function setOption(key, val) {
  4802. if (KEditor.prototype[key] === undefined) {
  4803. self[key] = val;
  4804. }
  4805. self.options[key] = val;
  4806. }
  4807. _each(options, function(key, val) {
  4808. setOption(key, options[key]);
  4809. });
  4810. _each(K.options, function(key, val) {
  4811. if (self[key] === undefined) {
  4812. setOption(key, val);
  4813. }
  4814. });
  4815. var se = K(self.srcElement || '<textarea/>');
  4816. if (!self.width) {
  4817. self.width = se[0].style.width || se.width();
  4818. }
  4819. if (!self.height) {
  4820. self.height = se[0].style.height || se.height();
  4821. }
  4822. setOption('width', _undef(self.width, self.minWidth));
  4823. setOption('height', _undef(self.height, self.minHeight));
  4824. setOption('width', _addUnit(self.width));
  4825. setOption('height', _addUnit(self.height));
  4826. if (_MOBILE && (!_IOS || _V < 534)) {
  4827. self.designMode = false;
  4828. }
  4829. self.srcElement = se;
  4830. self.initContent = '';
  4831. self.plugin = {};
  4832. self.isCreated = false;
  4833. self._handlers = {};
  4834. self._contextmenus = [];
  4835. self._undoStack = [];
  4836. self._redoStack = [];
  4837. self._firstAddBookmark = true;
  4838. self.menu = self.contextmenu = null;
  4839. self.dialogs = [];
  4840. }
  4841. KEditor.prototype = {
  4842. lang : function(mixed) {
  4843. return _lang(mixed, this.langType);
  4844. },
  4845. loadPlugin : function(name, fn) {
  4846. var self = this;
  4847. if (_plugins[name]) {
  4848. if (!_isFunction(_plugins[name])) {
  4849. setTimeout(function() {
  4850. self.loadPlugin(name, fn);
  4851. }, 100);
  4852. return self;
  4853. }
  4854. _plugins[name].call(self, KindEditor);
  4855. if (fn) {
  4856. fn.call(self);
  4857. }
  4858. return self;
  4859. }
  4860. _plugins[name] = 'loading';
  4861. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4862. setTimeout(function() {
  4863. if (_plugins[name]) {
  4864. self.loadPlugin(name, fn);
  4865. }
  4866. }, 0);
  4867. });
  4868. return self;
  4869. },
  4870. handler : function(key, fn) {
  4871. var self = this;
  4872. if (!self._handlers[key]) {
  4873. self._handlers[key] = [];
  4874. }
  4875. if (_isFunction(fn)) {
  4876. self._handlers[key].push(fn);
  4877. return self;
  4878. }
  4879. _each(self._handlers[key], function() {
  4880. fn = this.call(self, fn);
  4881. });
  4882. return fn;
  4883. },
  4884. clickToolbar : function(name, fn) {
  4885. var self = this, key = 'clickToolbar' + name;
  4886. if (fn === undefined) {
  4887. if (self._handlers[key]) {
  4888. return self.handler(key);
  4889. }
  4890. self.loadPlugin(name, function() {
  4891. self.handler(key);
  4892. });
  4893. return self;
  4894. }
  4895. return self.handler(key, fn);
  4896. },
  4897. updateState : function() {
  4898. var self = this;
  4899. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4900. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4901. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4902. });
  4903. return self;
  4904. },
  4905. addContextmenu : function(item) {
  4906. this._contextmenus.push(item);
  4907. return this;
  4908. },
  4909. afterCreate : function(fn) {
  4910. return this.handler('afterCreate', fn);
  4911. },
  4912. beforeRemove : function(fn) {
  4913. return this.handler('beforeRemove', fn);
  4914. },
  4915. beforeGetHtml : function(fn) {
  4916. return this.handler('beforeGetHtml', fn);
  4917. },
  4918. beforeSetHtml : function(fn) {
  4919. return this.handler('beforeSetHtml', fn);
  4920. },
  4921. afterSetHtml : function(fn) {
  4922. return this.handler('afterSetHtml', fn);
  4923. },
  4924. create : function() {
  4925. var self = this, fullscreenMode = self.fullscreenMode;
  4926. if (self.isCreated) {
  4927. return self;
  4928. }
  4929. if (self.srcElement.data('kindeditor')) {
  4930. return self;
  4931. }
  4932. self.srcElement.data('kindeditor', 'true');
  4933. if (fullscreenMode) {
  4934. _docElement().style.overflow = 'hidden';
  4935. } else {
  4936. _docElement().style.overflow = '';
  4937. }
  4938. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4939. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4940. if ((_IE && _V < 8) || _QUIRKS) {
  4941. height = _addUnit(_removeUnit(height) + 2);
  4942. }
  4943. var container = self.container = K(self.layout);
  4944. if (fullscreenMode) {
  4945. K(document.body).append(container);
  4946. } else {
  4947. self.srcElement.before(container);
  4948. }
  4949. var toolbarDiv = K('.toolbar', container),
  4950. editDiv = K('.edit', container),
  4951. statusbar = self.statusbar = K('.statusbar', container);
  4952. container.removeClass('container')
  4953. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4954. if (fullscreenMode) {
  4955. container.css({
  4956. position : 'absolute',
  4957. left : 0,
  4958. top : 0,
  4959. 'z-index' : 811211
  4960. });
  4961. if (!_GECKO) {
  4962. self._scrollPos = _getScrollPos();
  4963. }
  4964. window.scrollTo(0, 0);
  4965. K(document.body).css({
  4966. 'height' : '1px',
  4967. 'overflow' : 'hidden'
  4968. });
  4969. K(document.body.parentNode).css('overflow', 'hidden');
  4970. self._fullscreenExecuted = true;
  4971. } else {
  4972. if (self._fullscreenExecuted) {
  4973. K(document.body).css({
  4974. 'height' : '',
  4975. 'overflow' : ''
  4976. });
  4977. K(document.body.parentNode).css('overflow', '');
  4978. }
  4979. if (self._scrollPos) {
  4980. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4981. }
  4982. }
  4983. var htmlList = [];
  4984. K.each(self.items, function(i, name) {
  4985. if (name == '|') {
  4986. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4987. } else if (name == '/') {
  4988. htmlList.push('<div class="ke-hr"></div>');
  4989. } else {
  4990. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4991. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4992. }
  4993. });
  4994. var toolbar = self.toolbar = _toolbar({
  4995. src : toolbarDiv,
  4996. html : htmlList.join(''),
  4997. noDisableItems : self.noDisableItems,
  4998. click : function(e, name) {
  4999. e.stop();
  5000. if (self.menu) {
  5001. var menuName = self.menu.name;
  5002. self.hideMenu();
  5003. if (menuName === name) {
  5004. return;
  5005. }
  5006. }
  5007. self.clickToolbar(name);
  5008. }
  5009. });
  5010. var editHeight = _removeUnit(height) - toolbar.div.height();
  5011. var edit = self.edit = _edit({
  5012. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5013. src : editDiv,
  5014. srcElement : self.srcElement,
  5015. designMode : self.designMode,
  5016. themesPath : self.themesPath,
  5017. bodyClass : self.bodyClass,
  5018. cssPath : self.cssPath,
  5019. cssData : self.cssData,
  5020. beforeGetHtml : function(html) {
  5021. html = self.beforeGetHtml(html);
  5022. html = _removeBookmarkTag(_removeTempTag(html));
  5023. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5024. },
  5025. beforeSetHtml : function(html) {
  5026. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5027. return self.beforeSetHtml(html);
  5028. },
  5029. afterSetHtml : function() {
  5030. self.edit = edit = this;
  5031. self.afterSetHtml();
  5032. },
  5033. afterCreate : function() {
  5034. self.edit = edit = this;
  5035. self.cmd = edit.cmd;
  5036. self._docMousedownFn = function(e) {
  5037. if (self.menu) {
  5038. self.hideMenu();
  5039. }
  5040. };
  5041. K(edit.doc, document).mousedown(self._docMousedownFn);
  5042. _bindContextmenuEvent.call(self);
  5043. _bindNewlineEvent.call(self);
  5044. _bindTabEvent.call(self);
  5045. _bindFocusEvent.call(self);
  5046. edit.afterChange(function(e) {
  5047. if (!edit.designMode) {
  5048. return;
  5049. }
  5050. self.updateState();
  5051. self.addBookmark();
  5052. if (self.options.afterChange) {
  5053. self.options.afterChange.call(self);
  5054. }
  5055. });
  5056. edit.textarea.keyup(function(e) {
  5057. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5058. if (self.options.afterChange) {
  5059. self.options.afterChange.call(self);
  5060. }
  5061. }
  5062. });
  5063. if (self.readonlyMode) {
  5064. self.readonly();
  5065. }
  5066. self.isCreated = true;
  5067. if (self.initContent === '') {
  5068. self.initContent = self.html();
  5069. }
  5070. if (self._undoStack.length > 0) {
  5071. var prev = self._undoStack.pop();
  5072. if (prev.start) {
  5073. self.html(prev.html);
  5074. edit.cmd.range.moveToBookmark(prev);
  5075. self.select();
  5076. }
  5077. }
  5078. self.afterCreate();
  5079. if (self.options.afterCreate) {
  5080. self.options.afterCreate.call(self);
  5081. }
  5082. }
  5083. });
  5084. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5085. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5086. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5087. if (self._fullscreenResizeHandler) {
  5088. K(window).unbind('resize', self._fullscreenResizeHandler);
  5089. self._fullscreenResizeHandler = null;
  5090. }
  5091. function initResize() {
  5092. if (statusbar.height() === 0) {
  5093. setTimeout(initResize, 100);
  5094. return;
  5095. }
  5096. self.resize(width, height, false);
  5097. }
  5098. initResize();
  5099. if (fullscreenMode) {
  5100. self._fullscreenResizeHandler = function(e) {
  5101. if (self.isCreated) {
  5102. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5103. }
  5104. };
  5105. K(window).bind('resize', self._fullscreenResizeHandler);
  5106. toolbar.select('fullscreen');
  5107. statusbar.first().css('visibility', 'hidden');
  5108. statusbar.last().css('visibility', 'hidden');
  5109. } else {
  5110. if (_GECKO) {
  5111. K(window).bind('scroll', function(e) {
  5112. self._scrollPos = _getScrollPos();
  5113. });
  5114. }
  5115. if (self.resizeType > 0) {
  5116. _drag({
  5117. moveEl : container,
  5118. clickEl : statusbar,
  5119. moveFn : function(x, y, width, height, diffX, diffY) {
  5120. height += diffY;
  5121. self.resize(null, height);
  5122. }
  5123. });
  5124. } else {
  5125. statusbar.first().css('visibility', 'hidden');
  5126. }
  5127. if (self.resizeType === 2) {
  5128. _drag({
  5129. moveEl : container,
  5130. clickEl : statusbar.last(),
  5131. moveFn : function(x, y, width, height, diffX, diffY) {
  5132. width += diffX;
  5133. height += diffY;
  5134. self.resize(width, height);
  5135. }
  5136. });
  5137. } else {
  5138. statusbar.last().css('visibility', 'hidden');
  5139. }
  5140. }
  5141. return self;
  5142. },
  5143. remove : function() {
  5144. var self = this;
  5145. if (!self.isCreated) {
  5146. return self;
  5147. }
  5148. self.beforeRemove();
  5149. self.srcElement.data('kindeditor', '');
  5150. if (self.menu) {
  5151. self.hideMenu();
  5152. }
  5153. _each(self.dialogs, function() {
  5154. self.hideDialog();
  5155. });
  5156. K(document).unbind('mousedown', self._docMousedownFn);
  5157. self.toolbar.remove();
  5158. self.edit.remove();
  5159. self.statusbar.last().unbind();
  5160. self.statusbar.unbind();
  5161. self.container.remove();
  5162. self.container = self.toolbar = self.edit = self.menu = null;
  5163. self.dialogs = [];
  5164. self.isCreated = false;
  5165. return self;
  5166. },
  5167. resize : function(width, height, updateProp) {
  5168. var self = this;
  5169. updateProp = _undef(updateProp, true);
  5170. if (width) {
  5171. if (!/%/.test(width)) {
  5172. width = _removeUnit(width);
  5173. width = width < self.minWidth ? self.minWidth : width;
  5174. }
  5175. self.container.css('width', _addUnit(width));
  5176. if (updateProp) {
  5177. self.width = _addUnit(width);
  5178. }
  5179. }
  5180. if (height) {
  5181. height = _removeUnit(height);
  5182. editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5183. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5184. self.edit.setHeight(editHeight);
  5185. if (updateProp) {
  5186. self.height = _addUnit(height);
  5187. }
  5188. }
  5189. return self;
  5190. },
  5191. select : function() {
  5192. this.isCreated && this.cmd.select();
  5193. return this;
  5194. },
  5195. html : function(val) {
  5196. var self = this;
  5197. if (val === undefined) {
  5198. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5199. }
  5200. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5201. if (self.isCreated) {
  5202. self.cmd.selection();
  5203. }
  5204. return self;
  5205. },
  5206. fullHtml : function() {
  5207. return this.isCreated ? this.edit.html(undefined, true) : '';
  5208. },
  5209. text : function(val) {
  5210. var self = this;
  5211. if (val === undefined) {
  5212. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5213. } else {
  5214. return self.html(_escape(val));
  5215. }
  5216. },
  5217. isEmpty : function() {
  5218. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5219. },
  5220. isDirty : function() {
  5221. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5222. },
  5223. selectedHtml : function() {
  5224. var val = this.isCreated ? this.cmd.range.html() : '';
  5225. val = _removeBookmarkTag(_removeTempTag(val));
  5226. return val;
  5227. },
  5228. count : function(mode) {
  5229. var self = this;
  5230. mode = (mode || 'html').toLowerCase();
  5231. if (mode === 'html') {
  5232. return self.html().length;
  5233. }
  5234. if (mode === 'text') {
  5235. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5236. }
  5237. return 0;
  5238. },
  5239. exec : function(key) {
  5240. key = key.toLowerCase();
  5241. var self = this, cmd = self.cmd,
  5242. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5243. if (changeFlag) {
  5244. self.addBookmark(false);
  5245. }
  5246. cmd[key].apply(cmd, _toArray(arguments, 1));
  5247. if (changeFlag) {
  5248. self.updateState();
  5249. self.addBookmark(false);
  5250. if (self.options.afterChange) {
  5251. self.options.afterChange.call(self);
  5252. }
  5253. }
  5254. return self;
  5255. },
  5256. insertHtml : function(val, quickMode) {
  5257. if (!this.isCreated) {
  5258. return this;
  5259. }
  5260. val = this.beforeSetHtml(val);
  5261. this.exec('inserthtml', val, quickMode);
  5262. return this;
  5263. },
  5264. appendHtml : function(val) {
  5265. this.html(this.html() + val);
  5266. if (this.isCreated) {
  5267. var cmd = this.cmd;
  5268. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5269. cmd.select();
  5270. }
  5271. return this;
  5272. },
  5273. sync : function() {
  5274. _elementVal(this.srcElement, this.html());
  5275. return this;
  5276. },
  5277. focus : function() {
  5278. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5279. return this;
  5280. },
  5281. blur : function() {
  5282. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5283. return this;
  5284. },
  5285. addBookmark : function(checkSize) {
  5286. checkSize = _undef(checkSize, true);
  5287. var self = this, edit = self.edit,
  5288. body = edit.doc.body,
  5289. html = _removeTempTag(body.innerHTML), bookmark;
  5290. if (checkSize && self._undoStack.length > 0) {
  5291. var prev = self._undoStack[self._undoStack.length - 1];
  5292. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5293. return self;
  5294. }
  5295. }
  5296. if (edit.designMode && !self._firstAddBookmark) {
  5297. var range = self.cmd.range;
  5298. bookmark = range.createBookmark(true);
  5299. bookmark.html = _removeTempTag(body.innerHTML);
  5300. range.moveToBookmark(bookmark);
  5301. } else {
  5302. bookmark = {
  5303. html : html
  5304. };
  5305. }
  5306. self._firstAddBookmark = false;
  5307. _addBookmarkToStack(self._undoStack, bookmark);
  5308. return self;
  5309. },
  5310. undo : function() {
  5311. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5312. },
  5313. redo : function() {
  5314. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5315. },
  5316. fullscreen : function(bool) {
  5317. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5318. this.addBookmark(false);
  5319. return this.remove().create();
  5320. },
  5321. readonly : function(isReadonly) {
  5322. isReadonly = _undef(isReadonly, true);
  5323. var self = this, edit = self.edit, doc = edit.doc;
  5324. if (self.designMode) {
  5325. self.toolbar.disableAll(isReadonly, []);
  5326. } else {
  5327. _each(self.noDisableItems, function() {
  5328. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5329. });
  5330. }
  5331. if (_IE) {
  5332. doc.body.contentEditable = !isReadonly;
  5333. } else {
  5334. doc.designMode = isReadonly ? 'off' : 'on';
  5335. }
  5336. edit.textarea[0].disabled = isReadonly;
  5337. },
  5338. createMenu : function(options) {
  5339. var self = this,
  5340. name = options.name,
  5341. knode = self.toolbar.get(name),
  5342. pos = knode.pos();
  5343. options.x = pos.x;
  5344. options.y = pos.y + knode.height();
  5345. options.z = self.options.zIndex;
  5346. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5347. if (options.selectedColor !== undefined) {
  5348. options.cls = 'ke-colorpicker-' + self.themeType;
  5349. options.noColor = self.lang('noColor');
  5350. self.menu = _colorpicker(options);
  5351. } else {
  5352. options.cls = 'ke-menu-' + self.themeType;
  5353. options.centerLineMode = false;
  5354. self.menu = _menu(options);
  5355. }
  5356. return self.menu;
  5357. },
  5358. hideMenu : function() {
  5359. this.menu.remove();
  5360. this.menu = null;
  5361. return this;
  5362. },
  5363. hideContextmenu : function() {
  5364. this.contextmenu.remove();
  5365. this.contextmenu = null;
  5366. return this;
  5367. },
  5368. createDialog : function(options) {
  5369. var self = this, name = options.name;
  5370. options.z = self.options.zIndex;
  5371. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5372. options.closeBtn = _undef(options.closeBtn, {
  5373. name : self.lang('close'),
  5374. click : function(e) {
  5375. self.hideDialog();
  5376. if (_IE && self.cmd) {
  5377. self.cmd.select();
  5378. }
  5379. }
  5380. });
  5381. options.noBtn = _undef(options.noBtn, {
  5382. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5383. click : function(e) {
  5384. self.hideDialog();
  5385. if (_IE && self.cmd) {
  5386. self.cmd.select();
  5387. }
  5388. }
  5389. });
  5390. if (self.dialogAlignType != 'page') {
  5391. options.alignEl = self.container;
  5392. }
  5393. options.cls = 'ke-dialog-' + self.themeType;
  5394. if (self.dialogs.length > 0) {
  5395. var firstDialog = self.dialogs[0],
  5396. parentDialog = self.dialogs[self.dialogs.length - 1];
  5397. firstDialog.setMaskIndex(parentDialog.z + 2);
  5398. options.z = parentDialog.z + 3;
  5399. options.showMask = false;
  5400. }
  5401. var dialog = _dialog(options);
  5402. self.dialogs.push(dialog);
  5403. return dialog;
  5404. },
  5405. hideDialog : function() {
  5406. var self = this;
  5407. if (self.dialogs.length > 0) {
  5408. self.dialogs.pop().remove();
  5409. }
  5410. if (self.dialogs.length > 0) {
  5411. var firstDialog = self.dialogs[0],
  5412. parentDialog = self.dialogs[self.dialogs.length - 1];
  5413. firstDialog.setMaskIndex(parentDialog.z - 1);
  5414. }
  5415. return self;
  5416. },
  5417. errorDialog : function(html) {
  5418. var self = this;
  5419. var dialog = self.createDialog({
  5420. width : 750,
  5421. title : self.lang('uploadError'),
  5422. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5423. });
  5424. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5425. doc.open();
  5426. doc.write(html);
  5427. doc.close();
  5428. K(doc.body).css('background-color', '#FFF');
  5429. iframe[0].contentWindow.focus();
  5430. return self;
  5431. }
  5432. };
  5433. function _editor(options) {
  5434. return new KEditor(options);
  5435. }
  5436. _instances = [];
  5437. function _create(expr, options) {
  5438. options = options || {};
  5439. options.basePath = _undef(options.basePath, K.basePath);
  5440. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5441. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5442. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5443. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5444. var themeType = _undef(options.themeType, K.options.themeType);
  5445. _loadStyle(options.themesPath + 'default/default.css');
  5446. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5447. }
  5448. function create(editor) {
  5449. _each(_plugins, function(name, fn) {
  5450. if (_isFunction(fn)) {
  5451. fn.call(editor, KindEditor);
  5452. }
  5453. });
  5454. return editor.create();
  5455. }
  5456. var knode = K(expr);
  5457. if (!knode || knode.length === 0) {
  5458. return;
  5459. }
  5460. if (knode.length > 1) {
  5461. knode.each(function() {
  5462. _create(this, options);
  5463. });
  5464. return _instances[0];
  5465. }
  5466. options.srcElement = knode[0];
  5467. var editor = new KEditor(options);
  5468. _instances.push(editor);
  5469. if (_language[editor.langType]) {
  5470. return create(editor);
  5471. }
  5472. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5473. create(editor);
  5474. });
  5475. return editor;
  5476. }
  5477. function _eachEditor(expr, fn) {
  5478. K(expr).each(function(i, el) {
  5479. K.each(_instances, function(j, editor) {
  5480. if (editor && editor.srcElement[0] == el) {
  5481. fn.call(editor, j);
  5482. return false;
  5483. }
  5484. });
  5485. });
  5486. }
  5487. K.remove = function(expr) {
  5488. _eachEditor(expr, function(i) {
  5489. this.remove();
  5490. _instances.splice(i, 1);
  5491. });
  5492. };
  5493. K.sync = function(expr) {
  5494. _eachEditor(expr, function() {
  5495. this.sync();
  5496. });
  5497. };
  5498. K.html = function(expr, val) {
  5499. _eachEditor(expr, function() {
  5500. this.html(val);
  5501. });
  5502. };
  5503. K.insertHtml = function(expr, val) {
  5504. _eachEditor(expr, function() {
  5505. this.insertHtml(val);
  5506. });
  5507. };
  5508. K.appendHtml = function(expr, val) {
  5509. _eachEditor(expr, function() {
  5510. this.appendHtml(val);
  5511. });
  5512. };
  5513. if (_IE && _V < 7) {
  5514. _nativeCommand(document, 'BackgroundImageCache', true);
  5515. }
  5516. K.EditorClass = KEditor;
  5517. K.editor = _editor;
  5518. K.create = _create;
  5519. K.instances = _instances;
  5520. K.plugin = _plugin;
  5521. K.lang = _lang;
  5522. _plugin('core', function(K) {
  5523. var self = this,
  5524. shortcutKeys = {
  5525. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5526. };
  5527. self.afterSetHtml(function() {
  5528. if (self.options.afterChange) {
  5529. self.options.afterChange.call(self);
  5530. }
  5531. });
  5532. self.afterCreate(function() {
  5533. if (self.syncType != 'form') {
  5534. return;
  5535. }
  5536. var el = K(self.srcElement), hasForm = false;
  5537. while ((el = el.parent())) {
  5538. if (el.name == 'form') {
  5539. hasForm = true;
  5540. break;
  5541. }
  5542. }
  5543. if (hasForm) {
  5544. el.bind('submit', function(e) {
  5545. self.sync();
  5546. K(window).bind('unload', function() {
  5547. self.edit.textarea.remove();
  5548. });
  5549. });
  5550. var resetBtn = K('[type="reset"]', el);
  5551. resetBtn.click(function() {
  5552. self.html(self.initContent);
  5553. self.cmd.selection();
  5554. });
  5555. self.beforeRemove(function() {
  5556. el.unbind();
  5557. resetBtn.unbind();
  5558. });
  5559. }
  5560. });
  5561. self.clickToolbar('source', function() {
  5562. if (self.edit.designMode) {
  5563. self.toolbar.disableAll(true);
  5564. self.edit.design(false);
  5565. self.toolbar.select('source');
  5566. } else {
  5567. self.toolbar.disableAll(false);
  5568. self.edit.design(true);
  5569. self.toolbar.unselect('source');
  5570. if (_GECKO) {
  5571. setTimeout(function() {
  5572. self.cmd.selection();
  5573. }, 0);
  5574. } else {
  5575. self.cmd.selection();
  5576. }
  5577. }
  5578. self.designMode = self.edit.designMode;
  5579. });
  5580. self.afterCreate(function() {
  5581. if (!self.designMode) {
  5582. self.toolbar.disableAll(true).select('source');
  5583. }
  5584. });
  5585. self.clickToolbar('fullscreen', function() {
  5586. self.fullscreen();
  5587. });
  5588. if (self.fullscreenShortcut) {
  5589. var loaded = false;
  5590. self.afterCreate(function() {
  5591. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5592. if (e.which == 27) {
  5593. setTimeout(function() {
  5594. self.fullscreen();
  5595. }, 0);
  5596. }
  5597. });
  5598. if (loaded) {
  5599. if (_IE && !self.designMode) {
  5600. return;
  5601. }
  5602. self.focus();
  5603. }
  5604. if (!loaded) {
  5605. loaded = true;
  5606. }
  5607. });
  5608. }
  5609. _each('undo,redo'.split(','), function(i, name) {
  5610. if (shortcutKeys[name]) {
  5611. self.afterCreate(function() {
  5612. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5613. self.clickToolbar(name);
  5614. });
  5615. });
  5616. }
  5617. self.clickToolbar(name, function() {
  5618. self[name]();
  5619. });
  5620. });
  5621. self.clickToolbar('formatblock', function() {
  5622. var blocks = self.lang('formatblock.formatBlock'),
  5623. heights = {
  5624. h1 : 28,
  5625. h2 : 24,
  5626. h3 : 18,
  5627. H4 : 14,
  5628. p : 12
  5629. },
  5630. curVal = self.cmd.val('formatblock'),
  5631. menu = self.createMenu({
  5632. name : 'formatblock',
  5633. width : self.langType == 'en' ? 200 : 150
  5634. });
  5635. _each(blocks, function(key, val) {
  5636. var style = 'font-size:' + heights[key] + 'px;';
  5637. if (key.charAt(0) === 'h') {
  5638. style += 'font-weight:bold;';
  5639. }
  5640. menu.addItem({
  5641. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5642. height : heights[key] + 12,
  5643. checked : (curVal === key || curVal === val),
  5644. click : function() {
  5645. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5646. }
  5647. });
  5648. });
  5649. });
  5650. self.clickToolbar('fontname', function() {
  5651. var curVal = self.cmd.val('fontname'),
  5652. menu = self.createMenu({
  5653. name : 'fontname',
  5654. width : 150
  5655. });
  5656. _each(self.lang('fontname.fontName'), function(key, val) {
  5657. menu.addItem({
  5658. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5659. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5660. click : function() {
  5661. self.exec('fontname', key).hideMenu();
  5662. }
  5663. });
  5664. });
  5665. });
  5666. self.clickToolbar('fontsize', function() {
  5667. var curVal = self.cmd.val('fontsize'),
  5668. menu = self.createMenu({
  5669. name : 'fontsize',
  5670. width : 150
  5671. });
  5672. _each(self.fontSizeTable, function(i, val) {
  5673. menu.addItem({
  5674. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5675. height : _removeUnit(val) + 12,
  5676. checked : curVal === val,
  5677. click : function() {
  5678. self.exec('fontsize', val).hideMenu();
  5679. }
  5680. });
  5681. });
  5682. });
  5683. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5684. self.clickToolbar(name, function() {
  5685. self.createMenu({
  5686. name : name,
  5687. selectedColor : self.cmd.val(name) || 'default',
  5688. colors : self.colorTable,
  5689. click : function(color) {
  5690. self.exec(name, color).hideMenu();
  5691. }
  5692. });
  5693. });
  5694. });
  5695. _each(('cut,copy,paste').split(','), function(i, name) {
  5696. self.clickToolbar(name, function() {
  5697. self.focus();
  5698. try {
  5699. self.exec(name, null);
  5700. } catch(e) {
  5701. alert(self.lang(name + 'Error'));
  5702. }
  5703. });
  5704. });
  5705. self.clickToolbar('about', function() {
  5706. var html = '<div style="margin:20px;">' +
  5707. '<div>KindEditor ' + _VERSION + '</div>' +
  5708. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5709. '</div>';
  5710. self.createDialog({
  5711. name : 'about',
  5712. width : 350,
  5713. title : self.lang('about'),
  5714. body : html
  5715. });
  5716. });
  5717. self.plugin.getSelectedLink = function() {
  5718. return self.cmd.commonAncestor('a');
  5719. };
  5720. self.plugin.getSelectedImage = function() {
  5721. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5722. return !/^ke-\w+$/i.test(img[0].className);
  5723. });
  5724. };
  5725. self.plugin.getSelectedFlash = function() {
  5726. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5727. return img[0].className == 'ke-flash';
  5728. });
  5729. };
  5730. self.plugin.getSelectedMedia = function() {
  5731. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5732. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5733. });
  5734. };
  5735. self.plugin.getSelectedAnchor = function() {
  5736. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5737. return img[0].className == 'ke-anchor';
  5738. });
  5739. };
  5740. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5741. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5742. _each('edit,delete'.split(','), function(j, val) {
  5743. self.addContextmenu({
  5744. title : self.lang(val + uName),
  5745. click : function() {
  5746. self.loadPlugin(name, function() {
  5747. self.plugin[name][val]();
  5748. self.hideMenu();
  5749. });
  5750. },
  5751. cond : self.plugin['getSelected' + uName],
  5752. width : 150,
  5753. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5754. });
  5755. });
  5756. self.addContextmenu({ title : '-' });
  5757. });
  5758. self.plugin.getSelectedTable = function() {
  5759. return self.cmd.commonAncestor('table');
  5760. };
  5761. self.plugin.getSelectedRow = function() {
  5762. return self.cmd.commonAncestor('tr');
  5763. };
  5764. self.plugin.getSelectedCell = function() {
  5765. return self.cmd.commonAncestor('td');
  5766. };
  5767. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5768. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5769. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5770. self.addContextmenu({
  5771. title : self.lang('table' + val),
  5772. click : function() {
  5773. self.loadPlugin('table', function() {
  5774. self.plugin.table[val]();
  5775. self.hideMenu();
  5776. });
  5777. },
  5778. cond : cond,
  5779. width : 170,
  5780. iconClass : 'ke-icon-table' + val
  5781. });
  5782. });
  5783. self.addContextmenu({ title : '-' });
  5784. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5785. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5786. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5787. if (shortcutKeys[name]) {
  5788. self.afterCreate(function() {
  5789. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5790. self.cmd.selection();
  5791. self.clickToolbar(name);
  5792. });
  5793. });
  5794. }
  5795. self.clickToolbar(name, function() {
  5796. self.focus().exec(name, null);
  5797. });
  5798. });
  5799. self.afterCreate(function() {
  5800. var doc = self.edit.doc, cmd, bookmark, div,
  5801. cls = '__kindeditor_paste__', pasting = false;
  5802. function movePastedData() {
  5803. cmd.range.moveToBookmark(bookmark);
  5804. cmd.select();
  5805. if (_WEBKIT) {
  5806. K('div.' + cls, div).each(function() {
  5807. K(this).after('<br />').remove(true);
  5808. });
  5809. K('span.Apple-style-span', div).remove(true);
  5810. K('span.Apple-tab-span', div).remove(true);
  5811. K('span[style]', div).each(function() {
  5812. if (K(this).css('white-space') == 'nowrap') {
  5813. K(this).remove(true);
  5814. }
  5815. });
  5816. K('meta', div).remove();
  5817. }
  5818. var html = div[0].innerHTML;
  5819. div.remove();
  5820. if (html === '') {
  5821. return;
  5822. }
  5823. if (_WEBKIT) {
  5824. html = html.replace(/(<br>)\1/ig, '$1');
  5825. }
  5826. if (self.pasteType === 2) {
  5827. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5828. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5829. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5830. } else {
  5831. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5832. html = self.beforeSetHtml(html);
  5833. }
  5834. }
  5835. if (self.pasteType === 1) {
  5836. html = html.replace(/&nbsp;/ig, ' ');
  5837. html = html.replace(/\n\s*\n/g, '\n');
  5838. html = html.replace(/<br[^>]*>/ig, '\n');
  5839. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5840. html = html.replace(/<[^>]+>/g, '');
  5841. html = html.replace(/ {2}/g, ' &nbsp;');
  5842. if (self.newlineTag == 'p') {
  5843. if (/\n/.test(html)) {
  5844. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5845. }
  5846. } else {
  5847. html = html.replace(/\n/g, '<br />$&');
  5848. }
  5849. }
  5850. self.insertHtml(html, true);
  5851. }
  5852. K(doc.body).bind('paste', function(e){
  5853. if (self.pasteType === 0) {
  5854. e.stop();
  5855. return;
  5856. }
  5857. if (pasting) {
  5858. return;
  5859. }
  5860. pasting = true;
  5861. K('div.' + cls, doc).remove();
  5862. cmd = self.cmd.selection();
  5863. bookmark = cmd.range.createBookmark();
  5864. div = K('<div class="' + cls + '"></div>', doc).css({
  5865. position : 'absolute',
  5866. width : '1px',
  5867. height : '1px',
  5868. overflow : 'hidden',
  5869. left : '-1981px',
  5870. top : K(bookmark.start).pos().y + 'px',
  5871. 'white-space' : 'nowrap'
  5872. });
  5873. K(doc.body).append(div);
  5874. if (_IE) {
  5875. var rng = cmd.range.get(true);
  5876. rng.moveToElementText(div[0]);
  5877. rng.select();
  5878. rng.execCommand('paste');
  5879. e.preventDefault();
  5880. } else {
  5881. cmd.range.selectNodeContents(div[0]);
  5882. cmd.select();
  5883. }
  5884. setTimeout(function() {
  5885. movePastedData();
  5886. pasting = false;
  5887. }, 0);
  5888. });
  5889. });
  5890. self.beforeGetHtml(function(html) {
  5891. if (_IE && _V <= 8) {
  5892. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5893. return unescape(tag);
  5894. });
  5895. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5896. if (!/\s+type="[^"]+"/i.test($0)) {
  5897. return $1 + ' type="text"' + $2;
  5898. }
  5899. return $0;
  5900. });
  5901. }
  5902. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5903. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5904. })
  5905. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5906. var imgAttrs = _getAttrList(full);
  5907. var styles = _getCssList(imgAttrs.style || '');
  5908. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5909. var width = _undef(styles.width, '');
  5910. var height = _undef(styles.height, '');
  5911. if (/px/i.test(width)) {
  5912. width = _removeUnit(width);
  5913. }
  5914. if (/px/i.test(height)) {
  5915. height = _removeUnit(height);
  5916. }
  5917. attrs.width = _undef(imgAttrs.width, width);
  5918. attrs.height = _undef(imgAttrs.height, height);
  5919. return _mediaVideo(attrs);
  5920. //return _mediaEmbed(attrs);
  5921. })
  5922. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  5923. var imgAttrs = _getAttrList(full);
  5924. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5925. })
  5926. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5927. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5928. })
  5929. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5930. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5931. })
  5932. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  5933. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  5934. return $1 + _unescape(src) + $2;
  5935. });
  5936. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5937. return full;
  5938. })
  5939. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5940. return start + end;
  5941. });
  5942. });
  5943. self.beforeSetHtml(function(html) {
  5944. if (_IE && _V <= 8) {
  5945. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  5946. var attrs = _getAttrList(full);
  5947. var styles = _getCssList(attrs.style || '');
  5948. if (styles.display == 'none') {
  5949. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5950. }
  5951. return full;
  5952. });
  5953. }
  5954. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  5955. var attrs = _getAttrList(full);
  5956. attrs.src = _undef(attrs.src, '');
  5957. attrs.width = _undef(attrs.width, 0);
  5958. attrs.height = _undef(attrs.height, 0);
  5959. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5960. })
  5961. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  5962. var attrs = _getAttrList(full);
  5963. if (attrs.href !== undefined) {
  5964. return full;
  5965. }
  5966. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5967. })
  5968. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  5969. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5970. })
  5971. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  5972. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5973. })
  5974. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  5975. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5976. return full;
  5977. }
  5978. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5979. return full;
  5980. })
  5981. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5982. return start + 'data-ke-' + end;
  5983. })
  5984. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  5985. if (full.indexOf('ke-zeroborder') >= 0) {
  5986. return full;
  5987. }
  5988. return _addClassToTag(full, 'ke-zeroborder');
  5989. });
  5990. });
  5991. });
  5992. })(window);
  5993. /*******************************************************************************
  5994. * KindEditor - WYSIWYG HTML Editor for Internet
  5995. * Copyright (C) 2006-2011 kindsoft.net
  5996. *
  5997. * @author Roddy <luolonghao@gmail.com>
  5998. * @site http://www.kindsoft.net/
  5999. * @licence http://www.kindsoft.net/license.php
  6000. *******************************************************************************/
  6001. KindEditor.lang({
  6002. source : 'HTML代码',
  6003. preview : '预览',
  6004. undo : '后退(Ctrl+Z)',
  6005. redo : '前进(Ctrl+Y)',
  6006. cut : '剪切(Ctrl+X)',
  6007. copy : '复制(Ctrl+C)',
  6008. paste : '粘贴(Ctrl+V)',
  6009. plainpaste : '粘贴为无格式文本',
  6010. wordpaste : '从Word粘贴',
  6011. selectall : '全选(Ctrl+A)',
  6012. justifyleft : '左对齐',
  6013. justifycenter : '居中',
  6014. justifyright : '右对齐',
  6015. justifyfull : '两端对齐',
  6016. insertorderedlist : '编号',
  6017. insertunorderedlist : '项目符号',
  6018. indent : '增加缩进',
  6019. outdent : '减少缩进',
  6020. subscript : '下标',
  6021. superscript : '上标',
  6022. formatblock : '段落',
  6023. fontname : '字体',
  6024. fontsize : '文字大小',
  6025. forecolor : '文字颜色',
  6026. hilitecolor : '文字背景',
  6027. bold : '粗体(Ctrl+B)',
  6028. italic : '斜体(Ctrl+I)',
  6029. underline : '下划线(Ctrl+U)',
  6030. strikethrough : '删除线',
  6031. removeformat : '删除格式',
  6032. image : '图片',
  6033. multiimage : '批量图片上传',
  6034. flash : 'Flash',
  6035. media : '视音频',
  6036. table : '表格',
  6037. tablecell : '单元格',
  6038. hr : '插入横线',
  6039. emoticons : '插入表情',
  6040. link : '超级链接',
  6041. unlink : '取消超级链接',
  6042. fullscreen : '全屏显示',
  6043. about : '关于',
  6044. print : '打印(Ctrl+P)',
  6045. filemanager : '文件空间',
  6046. code : '插入程序代码',
  6047. map : 'Google地图',
  6048. baidumap : '百度地图',
  6049. lineheight : '行距',
  6050. clearhtml : '清理HTML代码',
  6051. pagebreak : '插入分页符',
  6052. quickformat : '一键排版',
  6053. insertfile : '插入文件',
  6054. template : '插入模板',
  6055. anchor : '锚点',
  6056. yes : '确定',
  6057. no : '取消',
  6058. close : '关闭',
  6059. editImage : '图片属性',
  6060. deleteImage : '删除图片',
  6061. editFlash : 'Flash属性',
  6062. deleteFlash : '删除Flash',
  6063. editMedia : '视音频属性',
  6064. deleteMedia : '删除视音频',
  6065. editLink : '超级链接属性',
  6066. deleteLink : '取消超级链接',
  6067. editAnchor : '锚点属性',
  6068. deleteAnchor : '删除锚点',
  6069. tableprop : '表格属性',
  6070. tablecellprop : '单元格属性',
  6071. tableinsert : '插入表格',
  6072. tabledelete : '删除表格',
  6073. tablecolinsertleft : '左侧插入列',
  6074. tablecolinsertright : '右侧插入列',
  6075. tablerowinsertabove : '上方插入行',
  6076. tablerowinsertbelow : '下方插入行',
  6077. tablerowmerge : '向下合并单元格',
  6078. tablecolmerge : '向右合并单元格',
  6079. tablerowsplit : '拆分行',
  6080. tablecolsplit : '拆分列',
  6081. tablecoldelete : '删除列',
  6082. tablerowdelete : '删除行',
  6083. noColor : '无颜色',
  6084. pleaseSelectFile : '请选择文件。',
  6085. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6086. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6087. invalidWidth : "宽度必须为数字。",
  6088. invalidHeight : "高度必须为数字。",
  6089. invalidBorder : "边框必须为数字。",
  6090. invalidUrl : "请输入有效的URL地址。",
  6091. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6092. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6093. invalidPadding : '边距必须为数字。',
  6094. invalidSpacing : '间距必须为数字。',
  6095. invalidJson : '服务器发生故障。',
  6096. uploadSuccess : '上传成功。',
  6097. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6098. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6099. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6100. ajaxLoading : '加载中,请稍候 ...',
  6101. uploadLoading : '上传中,请稍候 ...',
  6102. uploadError : '上传错误',
  6103. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6104. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6105. 'code.pleaseInput' : '请输入程序代码。',
  6106. 'link.url' : 'URL',
  6107. 'link.linkType' : '打开类型',
  6108. 'link.newWindow' : '新窗口',
  6109. 'link.selfWindow' : '当前窗口',
  6110. 'flash.url' : 'URL',
  6111. 'flash.width' : '宽度',
  6112. 'flash.height' : '高度',
  6113. 'flash.upload' : '上传',
  6114. 'flash.viewServer' : '文件空间',
  6115. 'media.url' : 'URL',
  6116. 'media.width' : '宽度',
  6117. 'media.height' : '高度',
  6118. 'media.autostart' : '自动播放',
  6119. 'media.upload' : '上传',
  6120. 'media.viewServer' : '文件空间',
  6121. 'image.remoteImage' : '网络图片',
  6122. 'image.localImage' : '本地上传',
  6123. 'image.remoteUrl' : '图片地址',
  6124. 'image.localUrl' : '上传文件',
  6125. 'image.size' : '图片大小',
  6126. 'image.width' : '宽',
  6127. 'image.height' : '高',
  6128. 'image.resetSize' : '重置大小',
  6129. 'image.align' : '对齐方式',
  6130. 'image.defaultAlign' : '默认方式',
  6131. 'image.leftAlign' : '左对齐',
  6132. 'image.rightAlign' : '右对齐',
  6133. 'image.imgTitle' : '图片说明',
  6134. 'image.upload' : '浏览...',
  6135. 'image.viewServer' : '图片空间',
  6136. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6137. 'multiimage.startUpload' : '开始上传',
  6138. 'multiimage.clearAll' : '全部清空',
  6139. 'multiimage.insertAll' : '确定',
  6140. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6141. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6142. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6143. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6144. 'multiimage.unknownError' : '发生异常,无法上传。',
  6145. 'multiimage.pending' : '等待上传',
  6146. 'multiimage.uploadError' : '上传失败',
  6147. 'filemanager.emptyFolder' : '空文件夹',
  6148. 'filemanager.moveup' : '移到上一级文件夹',
  6149. 'filemanager.viewType' : '显示方式:',
  6150. 'filemanager.viewImage' : '缩略图',
  6151. 'filemanager.listImage' : '详细信息',
  6152. 'filemanager.orderType' : '排序方式:',
  6153. 'filemanager.fileName' : '名称',
  6154. 'filemanager.fileSize' : '大小',
  6155. 'filemanager.fileType' : '类型',
  6156. 'insertfile.url' : 'URL',
  6157. 'insertfile.title' : '文件说明',
  6158. 'insertfile.upload' : '上传',
  6159. 'insertfile.viewServer' : '文件空间',
  6160. 'table.cells' : '单元格数',
  6161. 'table.rows' : '行数',
  6162. 'table.cols' : '列数',
  6163. 'table.size' : '大小',
  6164. 'table.width' : '宽度',
  6165. 'table.height' : '高度',
  6166. 'table.percent' : '%',
  6167. 'table.px' : 'px',
  6168. 'table.space' : '边距间距',
  6169. 'table.padding' : '边距',
  6170. 'table.spacing' : '间距',
  6171. 'table.align' : '对齐方式',
  6172. 'table.textAlign' : '水平对齐',
  6173. 'table.verticalAlign' : '垂直对齐',
  6174. 'table.alignDefault' : '默认',
  6175. 'table.alignLeft' : '左对齐',
  6176. 'table.alignCenter' : '居中',
  6177. 'table.alignRight' : '右对齐',
  6178. 'table.alignTop' : '顶部',
  6179. 'table.alignMiddle' : '中部',
  6180. 'table.alignBottom' : '底部',
  6181. 'table.alignBaseline' : '基线',
  6182. 'table.border' : '边框',
  6183. 'table.borderWidth' : '边框',
  6184. 'table.borderColor' : '颜色',
  6185. 'table.backgroundColor' : '背景颜色',
  6186. 'map.address' : '地址: ',
  6187. 'map.search' : '搜索',
  6188. 'baidumap.address' : '地址: ',
  6189. 'baidumap.search' : '搜索',
  6190. 'baidumap.insertDynamicMap' : '插入动态地图',
  6191. 'anchor.name' : '锚点名称',
  6192. 'formatblock.formatBlock' : {
  6193. h1 : '标题 1',
  6194. h2 : '标题 2',
  6195. h3 : '标题 3',
  6196. h4 : '标题 4',
  6197. p : '正 文'
  6198. },
  6199. 'fontname.fontName' : {
  6200. 'SimSun' : '宋体',
  6201. 'NSimSun' : '新宋体',
  6202. 'FangSong_GB2312' : '仿宋_GB2312',
  6203. 'KaiTi_GB2312' : '楷体_GB2312',
  6204. 'SimHei' : '黑体',
  6205. 'Microsoft YaHei' : '微软雅黑',
  6206. 'Arial' : 'Arial',
  6207. 'Arial Black' : 'Arial Black',
  6208. 'Times New Roman' : 'Times New Roman',
  6209. 'Courier New' : 'Courier New',
  6210. 'Tahoma' : 'Tahoma',
  6211. 'Verdana' : 'Verdana'
  6212. },
  6213. 'lineheight.lineHeight' : [
  6214. {'1' : '单倍行距'},
  6215. {'1.5' : '1.5倍行距'},
  6216. {'2' : '2倍行距'},
  6217. {'2.5' : '2.5倍行距'},
  6218. {'3' : '3倍行距'}
  6219. ],
  6220. 'template.selectTemplate' : '可选模板',
  6221. 'template.replaceContent' : '替换当前内容',
  6222. 'template.fileList' : {
  6223. '1.html' : '图片和文字',
  6224. '2.html' : '表格',
  6225. '3.html' : '项目编号'
  6226. }
  6227. }, 'zh_CN');
  6228. /*******************************************************************************
  6229. * KindEditor - WYSIWYG HTML Editor for Internet
  6230. * Copyright (C) 2006-2011 kindsoft.net
  6231. *
  6232. * @author Roddy <luolonghao@gmail.com>
  6233. * @site http://www.kindsoft.net/
  6234. * @licence http://www.kindsoft.net/license.php
  6235. *******************************************************************************/
  6236. KindEditor.plugin('anchor', function(K) {
  6237. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6238. self.plugin.anchor = {
  6239. edit : function() {
  6240. var html = ['<div style="padding:20px;">',
  6241. '<div class="ke-dialog-row">',
  6242. '<label for="keName">' + lang.name + '</label>',
  6243. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6244. '</div>',
  6245. '</div>'].join('');
  6246. var dialog = self.createDialog({
  6247. name : name,
  6248. width : 300,
  6249. title : self.lang(name),
  6250. body : html,
  6251. yesBtn : {
  6252. name : self.lang('yes'),
  6253. click : function(e) {
  6254. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6255. }
  6256. }
  6257. });
  6258. var div = dialog.div,
  6259. nameBox = K('input[name="name"]', div);
  6260. var img = self.plugin.getSelectedAnchor();
  6261. if (img) {
  6262. nameBox.val(unescape(img.attr('data-ke-name')));
  6263. }
  6264. nameBox[0].focus();
  6265. nameBox[0].select();
  6266. },
  6267. 'delete' : function() {
  6268. self.plugin.getSelectedAnchor().remove();
  6269. }
  6270. };
  6271. self.clickToolbar(name, self.plugin.anchor.edit);
  6272. });
  6273. /*******************************************************************************
  6274. * KindEditor - WYSIWYG HTML Editor for Internet
  6275. * Copyright (C) 2006-2011 kindsoft.net
  6276. *
  6277. * @author Roddy <luolonghao@gmail.com>
  6278. * @site http://www.kindsoft.net/
  6279. * @licence http://www.kindsoft.net/license.php
  6280. *******************************************************************************/
  6281. KindEditor.plugin('autoheight', function(K) {
  6282. var self = this;
  6283. if (!self.autoHeightMode) {
  6284. return;
  6285. }
  6286. var minHeight;
  6287. function hideScroll() {
  6288. var edit = self.edit;
  6289. var body = edit.doc.body;
  6290. edit.iframe[0].scroll = 'no';
  6291. body.style.overflowY = 'hidden';
  6292. }
  6293. function resetHeight() {
  6294. var edit = self.edit;
  6295. var body = edit.doc.body;
  6296. edit.iframe.height(minHeight);
  6297. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6298. }
  6299. function init() {
  6300. minHeight = K.removeUnit(self.height);
  6301. self.edit.afterChange(resetHeight);
  6302. hideScroll();
  6303. resetHeight();
  6304. }
  6305. if (self.isCreated) {
  6306. init();
  6307. } else {
  6308. self.afterCreate(init);
  6309. }
  6310. });
  6311. /*
  6312. * 如何实现真正的自动高度?
  6313. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6314. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6315. * 由此就实现了真正的自动高度
  6316. * 测试:chrome、firefox、IE9、IE8
  6317. * */
  6318. /*******************************************************************************
  6319. * KindEditor - WYSIWYG HTML Editor for Internet
  6320. * Copyright (C) 2006-2011 kindsoft.net
  6321. *
  6322. * @author Roddy <luolonghao@gmail.com>
  6323. * @site http://www.kindsoft.net/
  6324. * @licence http://www.kindsoft.net/license.php
  6325. *******************************************************************************/
  6326. // Baidu Maps: http://dev.baidu.com/wiki/map/index.php?title=%E9%A6%96%E9%A1%B5
  6327. KindEditor.plugin('baidumap', function(K) {
  6328. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6329. var mapWidth = K.undef(self.mapWidth, 558);
  6330. var mapHeight = K.undef(self.mapHeight, 360);
  6331. self.clickToolbar(name, function() {
  6332. var html = ['<div style="padding:10px 20px;">',
  6333. '<div class="ke-header">',
  6334. // left start
  6335. '<div class="ke-left">',
  6336. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6337. '<span class="ke-button-common ke-button-outer">',
  6338. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6339. '</span>',
  6340. '</div>',
  6341. // right start
  6342. '<div class="ke-right">',
  6343. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6344. '</div>',
  6345. '<div class="ke-clearfix"></div>',
  6346. '</div>',
  6347. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6348. '</div>'].join('');
  6349. var dialog = self.createDialog({
  6350. name : name,
  6351. width : mapWidth + 42,
  6352. title : self.lang(name),
  6353. body : html,
  6354. yesBtn : {
  6355. name : self.lang('yes'),
  6356. click : function(e) {
  6357. var map = win.map;
  6358. var centerObj = map.getCenter();
  6359. var center = centerObj.lng + ',' + centerObj.lat;
  6360. var zoom = map.getZoom();
  6361. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6362. '?center=' + encodeURIComponent(center),
  6363. '&zoom=' + encodeURIComponent(zoom),
  6364. '&width=' + mapWidth,
  6365. '&height=' + mapHeight,
  6366. '&markers=' + encodeURIComponent(center),
  6367. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6368. if (checkbox[0].checked) {
  6369. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6370. } else {
  6371. self.exec('insertimage', url);
  6372. }
  6373. self.hideDialog().focus();
  6374. }
  6375. },
  6376. beforeRemove : function() {
  6377. searchBtn.remove();
  6378. if (doc) {
  6379. doc.write('');
  6380. }
  6381. iframe.remove();
  6382. }
  6383. });
  6384. var div = dialog.div,
  6385. addressBox = K('[name="address"]', div),
  6386. searchBtn = K('[name="searchBtn"]', div),
  6387. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6388. win, doc;
  6389. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6390. function ready() {
  6391. win = iframe[0].contentWindow;
  6392. doc = K.iframeDoc(iframe);
  6393. }
  6394. iframe.bind('load', function() {
  6395. iframe.unbind('load');
  6396. if (K.IE) {
  6397. ready();
  6398. } else {
  6399. setTimeout(ready, 0);
  6400. }
  6401. });
  6402. K('.ke-map', div).replaceWith(iframe);
  6403. // search map
  6404. searchBtn.click(function() {
  6405. win.search(addressBox.val());
  6406. });
  6407. });
  6408. });
  6409. /*******************************************************************************
  6410. * KindEditor - WYSIWYG HTML Editor for Internet
  6411. * Copyright (C) 2006-2011 kindsoft.net
  6412. *
  6413. * @author Roddy <luolonghao@gmail.com>
  6414. * @site http://www.kindsoft.net/
  6415. * @licence http://www.kindsoft.net/license.php
  6416. *******************************************************************************/
  6417. KindEditor.plugin('clearhtml', function(K) {
  6418. var self = this, name = 'clearhtml';
  6419. self.clickToolbar(name, function() {
  6420. self.focus();
  6421. var html = self.html();
  6422. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6423. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6424. html = K.formatHtml(html, {
  6425. a : ['href', 'target'],
  6426. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6427. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height','eventData','onclick'],
  6428. table : ['border'],
  6429. video:['class','src','width','height','controls','autobuffer','autoplay','loop','muted','poster','preload','eventData','onclick','aaa'],
  6430. audio:['id','src','width','height','controls','autobuffer','autoplay','loop','muted','poster','preload','eventData','onclick','onplaying'],
  6431. 'td,th' : ['rowspan', 'colspan'],
  6432. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6433. });
  6434. self.html(html);
  6435. self.cmd.selection(true);
  6436. self.addBookmark();
  6437. });
  6438. });
  6439. /*******************************************************************************
  6440. * KindEditor - WYSIWYG HTML Editor for Internet
  6441. * Copyright (C) 2006-2011 kindsoft.net
  6442. *
  6443. * @author Roddy <luolonghao@gmail.com>
  6444. * @site http://www.kindsoft.net/
  6445. * @licence http://www.kindsoft.net/license.php
  6446. *******************************************************************************/
  6447. // google code prettify: http://google-code-prettify.googlecode.com/
  6448. // http://google-code-prettify.googlecode.com/
  6449. KindEditor.plugin('code', function(K) {
  6450. var self = this, name = 'code';
  6451. self.clickToolbar(name, function() {
  6452. var lang = self.lang(name + '.'),
  6453. html = ['<div style="padding:10px 20px;">',
  6454. '<div class="ke-dialog-row">',
  6455. '<select class="ke-code-type">',
  6456. '<option value="js">JavaScript</option>',
  6457. '<option value="html">HTML</option>',
  6458. '<option value="css">CSS</option>',
  6459. '<option value="php">PHP</option>',
  6460. '<option value="pl">Perl</option>',
  6461. '<option value="py">Python</option>',
  6462. '<option value="rb">Ruby</option>',
  6463. '<option value="java">Java</option>',
  6464. '<option value="vb">ASP/VB</option>',
  6465. '<option value="cpp">C/C++</option>',
  6466. '<option value="cs">C#</option>',
  6467. '<option value="xml">XML</option>',
  6468. '<option value="bsh">Shell</option>',
  6469. '<option value="">Other</option>',
  6470. '</select>',
  6471. '</div>',
  6472. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6473. '</div>'].join(''),
  6474. dialog = self.createDialog({
  6475. name : name,
  6476. width : 450,
  6477. title : self.lang(name),
  6478. body : html,
  6479. yesBtn : {
  6480. name : self.lang('yes'),
  6481. click : function(e) {
  6482. var type = K('.ke-code-type', dialog.div).val(),
  6483. code = textarea.val(),
  6484. cls = type === '' ? '' : ' lang-' + type,
  6485. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6486. if (K.trim(code) === '') {
  6487. alert(lang.pleaseInput);
  6488. textarea[0].focus();
  6489. return;
  6490. }
  6491. self.insertHtml(html).hideDialog().focus();
  6492. }
  6493. }
  6494. }),
  6495. textarea = K('textarea', dialog.div);
  6496. textarea[0].focus();
  6497. });
  6498. });
  6499. /*******************************************************************************
  6500. * KindEditor - WYSIWYG HTML Editor for Internet
  6501. * Copyright (C) 2006-2011 kindsoft.net
  6502. *
  6503. * @author Roddy <luolonghao@gmail.com>
  6504. * @site http://www.kindsoft.net/
  6505. * @licence http://www.kindsoft.net/license.php
  6506. *******************************************************************************/
  6507. KindEditor.plugin('emoticons', function(K) {
  6508. var self = this, name = 'emoticons',
  6509. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6510. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6511. currentPageNum = 1;
  6512. self.clickToolbar(name, function() {
  6513. var rows = 5, cols = 9, total = 135, startNum = 0,
  6514. cells = rows * cols, pages = Math.ceil(total / cells),
  6515. colsHalf = Math.floor(cols / 2),
  6516. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6517. elements = [],
  6518. menu = self.createMenu({
  6519. name : name,
  6520. beforeRemove : function() {
  6521. removeEvent();
  6522. }
  6523. });
  6524. menu.div.append(wrapperDiv);
  6525. var previewDiv, previewImg;
  6526. if (allowPreview) {
  6527. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6528. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6529. wrapperDiv.append(previewDiv);
  6530. previewDiv.append(previewImg);
  6531. }
  6532. function bindCellEvent(cell, j, num) {
  6533. if (previewDiv) {
  6534. cell.mouseover(function() {
  6535. if (j > colsHalf) {
  6536. previewDiv.css('left', 0);
  6537. previewDiv.css('right', '');
  6538. } else {
  6539. previewDiv.css('left', '');
  6540. previewDiv.css('right', 0);
  6541. }
  6542. previewImg.attr('src', path + num + '.gif');
  6543. K(this).addClass('ke-on');
  6544. });
  6545. } else {
  6546. cell.mouseover(function() {
  6547. K(this).addClass('ke-on');
  6548. });
  6549. }
  6550. cell.mouseout(function() {
  6551. K(this).removeClass('ke-on');
  6552. });
  6553. cell.click(function(e) {
  6554. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6555. e.stop();
  6556. });
  6557. }
  6558. function createEmoticonsTable(pageNum, parentDiv) {
  6559. var table = document.createElement('table');
  6560. parentDiv.append(table);
  6561. if (previewDiv) {
  6562. K(table).mouseover(function() {
  6563. previewDiv.show('block');
  6564. });
  6565. K(table).mouseout(function() {
  6566. previewDiv.hide();
  6567. });
  6568. elements.push(K(table));
  6569. }
  6570. table.className = 'ke-table';
  6571. table.cellPadding = 0;
  6572. table.cellSpacing = 0;
  6573. table.border = 0;
  6574. var num = (pageNum - 1) * cells + startNum;
  6575. for (var i = 0; i < rows; i++) {
  6576. var row = table.insertRow(i);
  6577. for (var j = 0; j < cols; j++) {
  6578. var cell = K(row.insertCell(j));
  6579. cell.addClass('ke-cell');
  6580. bindCellEvent(cell, j, num);
  6581. var span = K('<span class="ke-img"></span>')
  6582. .css('background-position', '-' + (24 * num) + 'px 0px')
  6583. .css('background-image', 'url(' + path + 'static.gif)');
  6584. cell.append(span);
  6585. elements.push(cell);
  6586. num++;
  6587. }
  6588. }
  6589. return table;
  6590. }
  6591. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6592. function removeEvent() {
  6593. K.each(elements, function() {
  6594. this.unbind();
  6595. });
  6596. }
  6597. var pageDiv;
  6598. function bindPageEvent(el, pageNum) {
  6599. el.click(function(e) {
  6600. removeEvent();
  6601. table.parentNode.removeChild(table);
  6602. pageDiv.remove();
  6603. table = createEmoticonsTable(pageNum, wrapperDiv);
  6604. createPageTable(pageNum);
  6605. currentPageNum = pageNum;
  6606. e.stop();
  6607. });
  6608. }
  6609. function createPageTable(currentPageNum) {
  6610. pageDiv = K('<div class="ke-page"></div>');
  6611. wrapperDiv.append(pageDiv);
  6612. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6613. if (currentPageNum !== pageNum) {
  6614. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6615. bindPageEvent(a, pageNum);
  6616. pageDiv.append(a);
  6617. elements.push(a);
  6618. } else {
  6619. pageDiv.append(K('@[' + pageNum + ']'));
  6620. }
  6621. pageDiv.append(K('@&nbsp;'));
  6622. }
  6623. }
  6624. createPageTable(currentPageNum);
  6625. });
  6626. });
  6627. /*******************************************************************************
  6628. * KindEditor - WYSIWYG HTML Editor for Internet
  6629. * Copyright (C) 2006-2011 kindsoft.net
  6630. *
  6631. * @author Roddy <luolonghao@gmail.com>
  6632. * @site http://www.kindsoft.net/
  6633. * @licence http://www.kindsoft.net/license.php
  6634. *******************************************************************************/
  6635. KindEditor.plugin('filemanager', function(K) {
  6636. var self = this, name = 'filemanager',
  6637. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6638. imgPath = self.pluginsPath + name + '/images/',
  6639. lang = self.lang(name + '.');
  6640. function makeFileTitle(filename, filesize, datetime) {
  6641. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6642. }
  6643. function bindTitle(el, data) {
  6644. if (data.is_dir) {
  6645. el.attr('title', data.filename);
  6646. } else {
  6647. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6648. }
  6649. }
  6650. self.plugin.filemanagerDialog = function(options) {
  6651. var width = K.undef(options.width, 650),
  6652. height = K.undef(options.height, 510),
  6653. dirName = K.undef(options.dirName, ''),
  6654. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(), // "LIST" or "VIEW"
  6655. clickFn = options.clickFn;
  6656. var html = [
  6657. '<div style="padding:10px 20px;">',
  6658. // header start
  6659. '<div class="ke-plugin-filemanager-header">',
  6660. // left start
  6661. '<div class="ke-left">',
  6662. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6663. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6664. '</div>',
  6665. // right start
  6666. '<div class="ke-right">',
  6667. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6668. '<option value="VIEW">' + lang.viewImage + '</option>',
  6669. '<option value="LIST">' + lang.listImage + '</option>',
  6670. '</select> ',
  6671. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6672. '<option value="NAME">' + lang.fileName + '</option>',
  6673. '<option value="SIZE">' + lang.fileSize + '</option>',
  6674. '<option value="TYPE">' + lang.fileType + '</option>',
  6675. '</select>',
  6676. '</div>',
  6677. '<div class="ke-clearfix"></div>',
  6678. '</div>',
  6679. // body start
  6680. '<div class="ke-plugin-filemanager-body"></div>',
  6681. '</div>'
  6682. ].join('');
  6683. var dialog = self.createDialog({
  6684. name : name,
  6685. width : width,
  6686. height : height,
  6687. title : self.lang(name),
  6688. body : html
  6689. }),
  6690. div = dialog.div,
  6691. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6692. moveupImg = K('[name="moveupImg"]', div),
  6693. moveupLink = K('[name="moveupLink"]', div),
  6694. viewServerBtn = K('[name="viewServer"]', div),
  6695. viewTypeBox = K('[name="viewType"]', div),
  6696. orderTypeBox = K('[name="orderType"]', div);
  6697. function reloadPage(path, order, func) {
  6698. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6699. dialog.showLoading(self.lang('ajaxLoading'));
  6700. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6701. dialog.hideLoading();
  6702. func(data);
  6703. });
  6704. }
  6705. var elList = [];
  6706. function bindEvent(el, result, data, createFunc) {
  6707. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6708. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6709. if (data.is_dir) {
  6710. el.click(function(e) {
  6711. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6712. });
  6713. } else if (data.is_photo) {
  6714. el.click(function(e) {
  6715. clickFn.call(this, fileUrl, data.filename);
  6716. });
  6717. } else {
  6718. el.click(function(e) {
  6719. clickFn.call(this, fileUrl, data.filename);
  6720. });
  6721. }
  6722. elList.push(el);
  6723. }
  6724. function createCommon(result, createFunc) {
  6725. // remove events
  6726. K.each(elList, function() {
  6727. this.unbind();
  6728. });
  6729. moveupLink.unbind();
  6730. viewTypeBox.unbind();
  6731. orderTypeBox.unbind();
  6732. // add events
  6733. if (result.current_dir_path) {
  6734. moveupLink.click(function(e) {
  6735. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6736. });
  6737. }
  6738. function changeFunc() {
  6739. if (viewTypeBox.val() == 'VIEW') {
  6740. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6741. } else {
  6742. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6743. }
  6744. }
  6745. viewTypeBox.change(changeFunc);
  6746. orderTypeBox.change(changeFunc);
  6747. bodyDiv.html('');
  6748. }
  6749. function createList(result) {
  6750. createCommon(result, createList);
  6751. var table = document.createElement('table');
  6752. table.className = 'ke-table';
  6753. table.cellPadding = 0;
  6754. table.cellSpacing = 0;
  6755. table.border = 0;
  6756. bodyDiv.append(table);
  6757. var fileList = result.file_list;
  6758. for (var i = 0, len = fileList.length; i < len; i++) {
  6759. var data = fileList[i], row = K(table.insertRow(i));
  6760. row.mouseover(function(e) {
  6761. K(this).addClass('ke-on');
  6762. })
  6763. .mouseout(function(e) {
  6764. K(this).removeClass('ke-on');
  6765. });
  6766. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6767. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6768. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6769. if (!data.is_dir || data.has_file) {
  6770. row.css('cursor', 'pointer');
  6771. cell0.attr('title', data.filename);
  6772. bindEvent(cell0, result, data, createList);
  6773. } else {
  6774. cell0.attr('title', lang.emptyFolder);
  6775. }
  6776. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6777. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6778. }
  6779. }
  6780. function createView(result) {
  6781. createCommon(result, createView);
  6782. var fileList = result.file_list;
  6783. for (var i = 0, len = fileList.length; i < len; i++) {
  6784. var data = fileList[i],
  6785. div = K('<div class="ke-inline-block ke-item"></div>');
  6786. bodyDiv.append(div);
  6787. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6788. .mouseover(function(e) {
  6789. K(this).addClass('ke-on');
  6790. })
  6791. .mouseout(function(e) {
  6792. K(this).removeClass('ke-on');
  6793. });
  6794. div.append(photoDiv);
  6795. var fileUrl = result.current_url + data.filename,
  6796. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6797. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6798. if (!data.is_dir || data.has_file) {
  6799. photoDiv.css('cursor', 'pointer');
  6800. bindTitle(photoDiv, data);
  6801. bindEvent(photoDiv, result, data, createView);
  6802. } else {
  6803. photoDiv.attr('title', lang.emptyFolder);
  6804. }
  6805. photoDiv.append(img);
  6806. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6807. }
  6808. }
  6809. viewTypeBox.val(viewType);
  6810. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6811. return dialog;
  6812. }
  6813. });
  6814. /*******************************************************************************
  6815. * KindEditor - WYSIWYG HTML Editor for Internet
  6816. * Copyright (C) 2006-2011 kindsoft.net
  6817. *
  6818. * @author Roddy <luolonghao@gmail.com>
  6819. * @site http://www.kindsoft.net/
  6820. * @licence http://www.kindsoft.net/license.php
  6821. *******************************************************************************/
  6822. KindEditor.plugin('flash', function(K) {
  6823. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6824. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6825. allowFileManager = K.undef(self.allowFileManager, false),
  6826. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6827. extraParams = K.undef(self.extraFileUploadParams, {}),
  6828. filePostName = K.undef(self.filePostName, 'imgFile'),
  6829. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  6830. self.plugin.flash = {
  6831. edit : function() {
  6832. var html = [
  6833. '<div style="padding:20px;">',
  6834. //url
  6835. '<div class="ke-dialog-row">',
  6836. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6837. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6838. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6839. '<span class="ke-button-common ke-button-outer">',
  6840. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6841. '</span>',
  6842. '</div>',
  6843. //width
  6844. '<div class="ke-dialog-row">',
  6845. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6846. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6847. '</div>',
  6848. //height
  6849. '<div class="ke-dialog-row">',
  6850. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6851. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6852. '</div>',
  6853. '</div>'
  6854. ].join('');
  6855. var dialog = self.createDialog({
  6856. name : name,
  6857. width : 450,
  6858. title : self.lang(name),
  6859. body : html,
  6860. yesBtn : {
  6861. name : self.lang('yes'),
  6862. click : function(e) {
  6863. var url = K.trim(urlBox.val()),
  6864. width = widthBox.val(),
  6865. height = heightBox.val();
  6866. if (url == 'http://' || K.invalidUrl(url)) {
  6867. alert(self.lang('invalidUrl'));
  6868. urlBox[0].focus();
  6869. return;
  6870. }
  6871. if (!/^\d*$/.test(width)) {
  6872. alert(self.lang('invalidWidth'));
  6873. widthBox[0].focus();
  6874. return;
  6875. }
  6876. if (!/^\d*$/.test(height)) {
  6877. alert(self.lang('invalidHeight'));
  6878. heightBox[0].focus();
  6879. return;
  6880. }
  6881. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6882. src : url,
  6883. type : K.mediaType('.swf'),
  6884. width : width,
  6885. height : height,
  6886. quality : 'high'
  6887. });
  6888. self.insertHtml(html).hideDialog().focus();
  6889. }
  6890. }
  6891. }),
  6892. div = dialog.div,
  6893. urlBox = K('[name="url"]', div),
  6894. viewServerBtn = K('[name="viewServer"]', div),
  6895. widthBox = K('[name="width"]', div),
  6896. heightBox = K('[name="height"]', div);
  6897. urlBox.val('http://');
  6898. if (allowFlashUpload) {
  6899. var uploadbutton = K.uploadbutton({
  6900. button : K('.ke-upload-button', div)[0],
  6901. fieldName : filePostName,
  6902. extraParams : extraParams,
  6903. url : K.addParam(uploadJson, 'dir=flash'),
  6904. afterUpload : function(data) {
  6905. dialog.hideLoading();
  6906. if (data.error === 0) {
  6907. var url = data.url;
  6908. if (formatUploadUrl) {
  6909. url = K.formatUrl(url, 'absolute');
  6910. }
  6911. urlBox.val(url);
  6912. if (self.afterUpload) {
  6913. self.afterUpload.call(self, url, data, name);
  6914. }
  6915. alert(self.lang('uploadSuccess'));
  6916. } else {
  6917. alert(data.message);
  6918. }
  6919. },
  6920. afterError : function(html) {
  6921. dialog.hideLoading();
  6922. self.errorDialog(html);
  6923. }
  6924. });
  6925. uploadbutton.fileBox.change(function(e) {
  6926. dialog.showLoading(self.lang('uploadLoading'));
  6927. uploadbutton.submit();
  6928. });
  6929. } else {
  6930. K('.ke-upload-button', div).hide();
  6931. }
  6932. if (allowFileManager) {
  6933. viewServerBtn.click(function(e) {
  6934. self.loadPlugin('filemanager', function() {
  6935. self.plugin.filemanagerDialog({
  6936. viewType : 'LIST',
  6937. dirName : 'flash',
  6938. clickFn : function(url, title) {
  6939. if (self.dialogs.length > 1) {
  6940. K('[name="url"]', div).val(url);
  6941. if (self.afterSelectFile) {
  6942. self.afterSelectFile.call(self, url);
  6943. }
  6944. self.hideDialog();
  6945. }
  6946. }
  6947. });
  6948. });
  6949. });
  6950. } else {
  6951. viewServerBtn.hide();
  6952. }
  6953. var img = self.plugin.getSelectedFlash();
  6954. if (img) {
  6955. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  6956. urlBox.val(attrs.src);
  6957. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  6958. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  6959. }
  6960. urlBox[0].focus();
  6961. urlBox[0].select();
  6962. },
  6963. 'delete' : function() {
  6964. self.plugin.getSelectedFlash().remove();
  6965. // [IE] 删除图片后立即点击图片按钮出错
  6966. self.addBookmark();
  6967. }
  6968. };
  6969. self.clickToolbar(name, self.plugin.flash.edit);
  6970. });
  6971. /*******************************************************************************
  6972. * KindEditor - WYSIWYG HTML Editor for Internet
  6973. * Copyright (C) 2006-2011 kindsoft.net
  6974. *
  6975. * @author Roddy <luolonghao@gmail.com>
  6976. * @site http://www.kindsoft.net/
  6977. * @licence http://www.kindsoft.net/license.php
  6978. *******************************************************************************/
  6979. KindEditor.plugin('image', function(K) {
  6980. var self = this, name = 'image',
  6981. allowImageUpload = K.undef(self.allowImageUpload, true),
  6982. allowImageRemote = K.undef(self.allowImageRemote, true),
  6983. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6984. allowFileManager = K.undef(self.allowFileManager, false),
  6985. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  6986. imageTabIndex = K.undef(self.imageTabIndex, 0),
  6987. imgPath = self.pluginsPath + 'image/images/',
  6988. extraParams = K.undef(self.extraFileUploadParams, {}),
  6989. filePostName = K.undef(self.filePostName, 'file'),
  6990. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  6991. lang = self.lang(name + '.');
  6992. self.plugin.imageDialog = function(options) {
  6993. var imageUrl = options.imageUrl,
  6994. imageWidth = K.undef(options.imageWidth, ''),
  6995. imageHeight = K.undef(options.imageHeight, ''),
  6996. imageTitle = K.undef(options.imageTitle, ''),
  6997. imageAlign = K.undef(options.imageAlign, ''),
  6998. showRemote = K.undef(options.showRemote, true),
  6999. showLocal = K.undef(options.showLocal, true),
  7000. tabIndex = K.undef(options.tabIndex, 0),
  7001. clickFn = options.clickFn;
  7002. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7003. var hiddenElements = [];
  7004. for(var k in extraParams){
  7005. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7006. }
  7007. var html = [
  7008. '<div style="padding:20px;">',
  7009. //tabs
  7010. '<div class="tabs"></div>',
  7011. //remote image - start
  7012. '<div class="tab1" style="display:none;">',
  7013. //url
  7014. '<div class="ke-dialog-row">',
  7015. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7016. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7017. '<span class="ke-button-common ke-button-outer">',
  7018. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7019. '</span>',
  7020. '</div>',
  7021. //size
  7022. '<div class="ke-dialog-row">',
  7023. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7024. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7025. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7026. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7027. '</div>',
  7028. //align
  7029. '<div class="ke-dialog-row">',
  7030. '<label style="width:60px;">' + lang.align + '</label>',
  7031. '<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="" />',
  7032. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7033. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7034. '</div>',
  7035. //title
  7036. '<div class="ke-dialog-row">',
  7037. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7038. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7039. '</div>',
  7040. '</div>',
  7041. //remote image - end
  7042. //local upload - start
  7043. '<div class="tab2" style="display:none;">',
  7044. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7045. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + uploadJson + '">',
  7046. //file
  7047. '<div class="ke-dialog-row">',
  7048. hiddenElements.join(''),
  7049. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7050. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7051. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7052. '</div>',
  7053. '</form>',
  7054. '</div>',
  7055. //local upload - end
  7056. '</div>'
  7057. ].join('');
  7058. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7059. dialogHeight = showLocal && showRemote ? 300 : 250;
  7060. var dialog = self.createDialog({
  7061. name : name,
  7062. width : dialogWidth,
  7063. height : dialogHeight,
  7064. title : self.lang(name),
  7065. body : html,
  7066. yesBtn : {
  7067. name : self.lang('yes'),
  7068. click : function(e) {
  7069. // Bugfix: http://code.google.com/p/kindeditor/issues/detail?id=319
  7070. if (dialog.isLoading) {
  7071. return;
  7072. }
  7073. // insert local image
  7074. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7075. if (uploadbutton.fileBox.val() == '') {
  7076. alert(self.lang('pleaseSelectFile'));
  7077. return;
  7078. }
  7079. dialog.showLoading(self.lang('uploadLoading'));
  7080. uploadbutton.submit();
  7081. localUrlBox.val('');
  7082. return;
  7083. }
  7084. // insert remote image
  7085. var url = K.trim(urlBox.val()),
  7086. width = widthBox.val(),
  7087. height = heightBox.val(),
  7088. title = titleBox.val(),
  7089. align = '';
  7090. alignBox.each(function() {
  7091. if (this.checked) {
  7092. align = this.value;
  7093. return false;
  7094. }
  7095. });
  7096. if (url == 'http://' || K.invalidUrl(url)) {
  7097. alert(self.lang('invalidUrl'));
  7098. urlBox[0].focus();
  7099. return;
  7100. }
  7101. if (!/^\d*$/.test(width)) {
  7102. alert(self.lang('invalidWidth'));
  7103. widthBox[0].focus();
  7104. return;
  7105. }
  7106. if (!/^\d*$/.test(height)) {
  7107. alert(self.lang('invalidHeight'));
  7108. heightBox[0].focus();
  7109. return;
  7110. }
  7111. clickFn.call(self, url, title, width, height, 0, align);
  7112. }
  7113. },
  7114. beforeRemove : function() {
  7115. viewServerBtn.unbind();
  7116. widthBox.unbind();
  7117. heightBox.unbind();
  7118. refreshBtn.unbind();
  7119. }
  7120. }),
  7121. div = dialog.div;
  7122. var urlBox = K('[name="url"]', div),
  7123. localUrlBox = K('[name="localUrl"]', div),
  7124. viewServerBtn = K('[name="viewServer"]', div),
  7125. widthBox = K('.tab1 [name="width"]', div),
  7126. heightBox = K('.tab1 [name="height"]', div),
  7127. refreshBtn = K('.ke-refresh-btn', div),
  7128. titleBox = K('.tab1 [name="title"]', div),
  7129. alignBox = K('.tab1 [name="align"]', div);
  7130. var tabs;
  7131. if (showRemote && showLocal) {
  7132. tabs = K.tabs({
  7133. src : K('.tabs', div),
  7134. afterSelect : function(i) {}
  7135. });
  7136. tabs.add({
  7137. title : lang.remoteImage,
  7138. panel : K('.tab1', div)
  7139. });
  7140. tabs.add({
  7141. title : lang.localImage,
  7142. panel : K('.tab2', div)
  7143. });
  7144. tabs.select(tabIndex);
  7145. } else if (showRemote) {
  7146. K('.tab1', div).show();
  7147. } else if (showLocal) {
  7148. K('.tab2', div).show();
  7149. }
  7150. var uploadbutton = K.uploadbutton({
  7151. button : K('.ke-upload-button', div)[0],
  7152. fieldName : filePostName,
  7153. form : K('.ke-form', div),
  7154. target : target,
  7155. width: 60,
  7156. afterUpload : function(data) {
  7157. dialog.hideLoading();
  7158. if (data.code === 0) {
  7159. var url = data.files[0];
  7160. if (formatUploadUrl) {
  7161. url = K.formatUrl(url, 'absolute');
  7162. }
  7163. if (self.afterUpload) {
  7164. self.afterUpload.call(self, url, data, name);
  7165. }
  7166. if (!fillDescAfterUploadImage) {
  7167. //clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7168. clickFn.call(self,data);
  7169. } else {
  7170. K(".ke-dialog-row #remoteUrl", div).val(url);
  7171. K(".ke-tabs-li", div)[0].click();
  7172. K(".ke-refresh-btn", div).click();
  7173. }
  7174. } else {
  7175. alert(data.message);
  7176. }
  7177. },
  7178. afterError : function(html) {
  7179. dialog.hideLoading();
  7180. self.errorDialog(html);
  7181. }
  7182. });
  7183. uploadbutton.fileBox.change(function(e) {
  7184. localUrlBox.val(uploadbutton.fileBox.val());
  7185. });
  7186. if (allowFileManager) {
  7187. viewServerBtn.click(function(e) {
  7188. self.loadPlugin('filemanager', function() {
  7189. self.plugin.filemanagerDialog({
  7190. viewType : 'VIEW',
  7191. dirName : 'image',
  7192. clickFn : function(url, title) {
  7193. if (self.dialogs.length > 1) {
  7194. K('[name="url"]', div).val(url);
  7195. if (self.afterSelectFile) {
  7196. self.afterSelectFile.call(self, url);
  7197. }
  7198. self.hideDialog();
  7199. }
  7200. }
  7201. });
  7202. });
  7203. });
  7204. } else {
  7205. viewServerBtn.hide();
  7206. }
  7207. var originalWidth = 0, originalHeight = 0;
  7208. function setSize(width, height) {
  7209. widthBox.val(width);
  7210. heightBox.val(height);
  7211. originalWidth = width;
  7212. originalHeight = height;
  7213. }
  7214. refreshBtn.click(function(e) {
  7215. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7216. position : 'absolute',
  7217. visibility : 'hidden',
  7218. top : 0,
  7219. left : '-1000px'
  7220. });
  7221. tempImg.bind('load', function() {
  7222. setSize(tempImg.width(), tempImg.height());
  7223. tempImg.remove();
  7224. });
  7225. K(document.body).append(tempImg);
  7226. });
  7227. widthBox.change(function(e) {
  7228. if (originalWidth > 0) {
  7229. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7230. }
  7231. });
  7232. heightBox.change(function(e) {
  7233. if (originalHeight > 0) {
  7234. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7235. }
  7236. });
  7237. urlBox.val(options.imageUrl);
  7238. setSize(options.imageWidth, options.imageHeight);
  7239. titleBox.val(options.imageTitle);
  7240. alignBox.each(function() {
  7241. if (this.value === options.imageAlign) {
  7242. this.checked = true;
  7243. return false;
  7244. }
  7245. });
  7246. if (showRemote && tabIndex === 0) {
  7247. urlBox[0].focus();
  7248. urlBox[0].select();
  7249. }
  7250. return dialog;
  7251. };
  7252. self.plugin.image = {
  7253. edit : function() {
  7254. var img = self.plugin.getSelectedImage();
  7255. self.plugin.imageDialog({
  7256. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7257. imageWidth : img ? img.width() : '',
  7258. imageHeight : img ? img.height() : '',
  7259. imageTitle : img ? img.attr('title') : '',
  7260. imageAlign : img ? img.attr('align') : '',
  7261. showRemote : allowImageRemote,
  7262. showLocal : allowImageUpload,
  7263. tabIndex: img ? 0 : imageTabIndex,
  7264. clickFn : function(url, title, width, height, border, align) {
  7265. if (img) {
  7266. img.attr('src', url);
  7267. img.attr('data-ke-src', url);
  7268. img.attr('width', width);
  7269. img.attr('height', height);
  7270. img.attr('title', title);
  7271. img.attr('align', align);
  7272. img.attr('alt', title);
  7273. } else {
  7274. self.exec('insertimage', self.options.prefixStaticUrl+url['files'][0], title, width, height, border, align);
  7275. }
  7276. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  7277. setTimeout(function() {
  7278. self.hideDialog().focus();
  7279. }, 0);
  7280. }
  7281. });
  7282. },
  7283. 'delete' : function() {
  7284. var target = self.plugin.getSelectedImage();
  7285. if (target.parent().name == 'a') {
  7286. target = target.parent();
  7287. }
  7288. target.remove();
  7289. // [IE] 删除图片后立即点击图片按钮出错
  7290. self.addBookmark();
  7291. }
  7292. };
  7293. self.clickToolbar(name, self.plugin.image.edit);
  7294. });
  7295. /*******************************************************************************
  7296. * KindEditor - WYSIWYG HTML Editor for Internet
  7297. * Copyright (C) 2006-2011 kindsoft.net
  7298. *
  7299. * @author Roddy <luolonghao@gmail.com>
  7300. * @site http://www.kindsoft.net/
  7301. * @licence http://www.kindsoft.net/license.php
  7302. *******************************************************************************/
  7303. KindEditor.plugin('insertfile', function(K) {
  7304. var self = this, name = 'insertfile',
  7305. allowFileUpload = K.undef(self.allowFileUpload, true),
  7306. allowFileManager = K.undef(self.allowFileManager, false),
  7307. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7308. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7309. extraParams = K.undef(self.extraFileUploadParams, {}),
  7310. filePostName = K.undef(self.filePostName, 'imgFile'),
  7311. lang = self.lang(name + '.');
  7312. self.plugin.fileDialog = function(options) {
  7313. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7314. fileTitle = K.undef(options.fileTitle, ''),
  7315. clickFn = options.clickFn;
  7316. var html = [
  7317. '<div style="padding:20px;">',
  7318. '<div class="ke-dialog-row">',
  7319. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7320. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7321. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7322. '<span class="ke-button-common ke-button-outer">',
  7323. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7324. '</span>',
  7325. '</div>',
  7326. //title
  7327. '<div class="ke-dialog-row">',
  7328. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7329. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7330. '</div>',
  7331. //form end
  7332. '</form>',
  7333. '</div>'
  7334. ].join('');
  7335. var dialog = self.createDialog({
  7336. name : name,
  7337. width : 450,
  7338. title : self.lang(name),
  7339. body : html,
  7340. yesBtn : {
  7341. name : self.lang('yes'),
  7342. click : function(e) {
  7343. var url = K.trim(urlBox.val()),
  7344. title = titleBox.val();
  7345. if (url == 'http://' || K.invalidUrl(url)) {
  7346. alert(self.lang('invalidUrl'));
  7347. urlBox[0].focus();
  7348. return;
  7349. }
  7350. if (K.trim(title) === '') {
  7351. title = url;
  7352. }
  7353. clickFn.call(self, url, title);
  7354. }
  7355. }
  7356. }),
  7357. div = dialog.div;
  7358. var urlBox = K('[name="url"]', div),
  7359. viewServerBtn = K('[name="viewServer"]', div),
  7360. titleBox = K('[name="title"]', div);
  7361. if (allowFileUpload) {
  7362. var uploadbutton = K.uploadbutton({
  7363. button : K('.ke-upload-button', div)[0],
  7364. fieldName : filePostName,
  7365. url : K.addParam(uploadJson, 'dir=file'),
  7366. extraParams : extraParams,
  7367. afterUpload : function(data) {
  7368. dialog.hideLoading();
  7369. if (data.error === 0) {
  7370. var url = data.url;
  7371. if (formatUploadUrl) {
  7372. url = K.formatUrl(url, 'absolute');
  7373. }
  7374. urlBox.val(url);
  7375. if (self.afterUpload) {
  7376. self.afterUpload.call(self, url, data, name);
  7377. }
  7378. alert(self.lang('uploadSuccess'));
  7379. } else {
  7380. alert(data.message);
  7381. }
  7382. },
  7383. afterError : function(html) {
  7384. dialog.hideLoading();
  7385. self.errorDialog(html);
  7386. }
  7387. });
  7388. uploadbutton.fileBox.change(function(e) {
  7389. dialog.showLoading(self.lang('uploadLoading'));
  7390. uploadbutton.submit();
  7391. });
  7392. } else {
  7393. K('.ke-upload-button', div).hide();
  7394. }
  7395. if (allowFileManager) {
  7396. viewServerBtn.click(function(e) {
  7397. self.loadPlugin('filemanager', function() {
  7398. self.plugin.filemanagerDialog({
  7399. viewType : 'LIST',
  7400. dirName : 'file',
  7401. clickFn : function(url, title) {
  7402. if (self.dialogs.length > 1) {
  7403. K('[name="url"]', div).val(url);
  7404. if (self.afterSelectFile) {
  7405. self.afterSelectFile.call(self, url);
  7406. }
  7407. self.hideDialog();
  7408. }
  7409. }
  7410. });
  7411. });
  7412. });
  7413. } else {
  7414. viewServerBtn.hide();
  7415. }
  7416. urlBox.val(fileUrl);
  7417. titleBox.val(fileTitle);
  7418. urlBox[0].focus();
  7419. urlBox[0].select();
  7420. };
  7421. self.clickToolbar(name, function() {
  7422. self.plugin.fileDialog({
  7423. clickFn : function(url, title) {
  7424. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7425. self.insertHtml(html).hideDialog().focus();
  7426. }
  7427. });
  7428. });
  7429. });
  7430. /*******************************************************************************
  7431. * KindEditor - WYSIWYG HTML Editor for Internet
  7432. * Copyright (C) 2006-2011 kindsoft.net
  7433. *
  7434. * @author Roddy <luolonghao@gmail.com>
  7435. * @site http://www.kindsoft.net/
  7436. * @licence http://www.kindsoft.net/license.php
  7437. *******************************************************************************/
  7438. KindEditor.plugin('lineheight', function(K) {
  7439. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7440. self.clickToolbar(name, function() {
  7441. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7442. if (commonNode) {
  7443. curVal = commonNode.css('line-height');
  7444. }
  7445. var menu = self.createMenu({
  7446. name : name,
  7447. width : 150
  7448. });
  7449. K.each(lang.lineHeight, function(i, row) {
  7450. K.each(row, function(key, val) {
  7451. menu.addItem({
  7452. title : val,
  7453. checked : curVal === key,
  7454. click : function() {
  7455. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7456. span : '.line-height=' + key
  7457. });
  7458. self.updateState();
  7459. self.addBookmark();
  7460. self.hideMenu();
  7461. }
  7462. });
  7463. });
  7464. });
  7465. });
  7466. });
  7467. /*******************************************************************************
  7468. * KindEditor - WYSIWYG HTML Editor for Internet
  7469. * Copyright (C) 2006-2011 kindsoft.net
  7470. *
  7471. * @author Roddy <luolonghao@gmail.com>
  7472. * @site http://www.kindsoft.net/
  7473. * @licence http://www.kindsoft.net/license.php
  7474. *******************************************************************************/
  7475. KindEditor.plugin('link', function(K) {
  7476. var self = this, name = 'link';
  7477. self.plugin.link = {
  7478. edit : function() {
  7479. var lang = self.lang(name + '.'),
  7480. html = '<div style="padding:20px;">' +
  7481. //url
  7482. '<div class="ke-dialog-row">' +
  7483. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7484. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7485. //type
  7486. '<div class="ke-dialog-row"">' +
  7487. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7488. '<select id="keType" name="type"></select>' +
  7489. '</div>' +
  7490. '</div>',
  7491. dialog = self.createDialog({
  7492. name : name,
  7493. width : 450,
  7494. title : self.lang(name),
  7495. body : html,
  7496. yesBtn : {
  7497. name : self.lang('yes'),
  7498. click : function(e) {
  7499. var url = K.trim(urlBox.val());
  7500. if (url == 'http://' || K.invalidUrl(url)) {
  7501. alert(self.lang('invalidUrl'));
  7502. urlBox[0].focus();
  7503. return;
  7504. }
  7505. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7506. }
  7507. }
  7508. }),
  7509. div = dialog.div,
  7510. urlBox = K('input[name="url"]', div),
  7511. typeBox = K('select[name="type"]', div);
  7512. urlBox.val('http://');
  7513. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7514. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7515. self.cmd.selection();
  7516. var a = self.plugin.getSelectedLink();
  7517. if (a) {
  7518. self.cmd.range.selectNode(a[0]);
  7519. self.cmd.select();
  7520. urlBox.val(a.attr('data-ke-src'));
  7521. typeBox.val(a.attr('target'));
  7522. }
  7523. urlBox[0].focus();
  7524. urlBox[0].select();
  7525. },
  7526. 'delete' : function() {
  7527. self.exec('unlink', null);
  7528. }
  7529. };
  7530. self.clickToolbar(name, self.plugin.link.edit);
  7531. });
  7532. /*******************************************************************************
  7533. * KindEditor - WYSIWYG HTML Editor for Internet
  7534. * Copyright (C) 2006-2011 kindsoft.net
  7535. *
  7536. * @author Roddy <luolonghao@gmail.com>
  7537. * @site http://www.kindsoft.net/
  7538. * @licence http://www.kindsoft.net/license.php
  7539. *******************************************************************************/
  7540. // Google Maps: http://code.google.com/apis/maps/index.html
  7541. KindEditor.plugin('map', function(K) {
  7542. var self = this, name = 'map', lang = self.lang(name + '.');
  7543. self.clickToolbar(name, function() {
  7544. var html = ['<div style="padding:10px 20px;">',
  7545. '<div class="ke-dialog-row">',
  7546. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  7547. '<span class="ke-button-common ke-button-outer">',
  7548. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  7549. '</span>',
  7550. '</div>',
  7551. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  7552. '</div>'].join('');
  7553. var dialog = self.createDialog({
  7554. name : name,
  7555. width : 600,
  7556. title : self.lang(name),
  7557. body : html,
  7558. yesBtn : {
  7559. name : self.lang('yes'),
  7560. click : function(e) {
  7561. var geocoder = win.geocoder,
  7562. map = win.map,
  7563. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  7564. zoom = map.getZoom(),
  7565. maptype = map.getMapTypeId(),
  7566. url = 'http://maps.googleapis.com/maps/api/staticmap';
  7567. url += '?center=' + encodeURIComponent(center);
  7568. url += '&zoom=' + encodeURIComponent(zoom);
  7569. url += '&size=558x360';
  7570. url += '&maptype=' + encodeURIComponent(maptype);
  7571. url += '&markers=' + encodeURIComponent(center);
  7572. url += '&language=' + self.langType;
  7573. url += '&sensor=false';
  7574. self.exec('insertimage', url).hideDialog().focus();
  7575. }
  7576. },
  7577. beforeRemove : function() {
  7578. searchBtn.remove();
  7579. if (doc) {
  7580. doc.write('');
  7581. }
  7582. iframe.remove();
  7583. }
  7584. });
  7585. var div = dialog.div,
  7586. addressBox = K('[name="address"]', div),
  7587. searchBtn = K('[name="searchBtn"]', div),
  7588. win, doc;
  7589. var iframeHtml = ['<!doctype html><html><head>',
  7590. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  7591. '<style>',
  7592. ' html { height: 100% }',
  7593. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  7594. ' #map_canvas { height: 100% }',
  7595. '</style>',
  7596. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  7597. '<script>',
  7598. 'var map, geocoder;',
  7599. 'function initialize() {',
  7600. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  7601. ' var options = {',
  7602. ' zoom: 11,',
  7603. ' center: latlng,',
  7604. ' disableDefaultUI: true,',
  7605. ' panControl: true,',
  7606. ' zoomControl: true,',
  7607. ' mapTypeControl: true,',
  7608. ' scaleControl: true,',
  7609. ' streetViewControl: false,',
  7610. ' overviewMapControl: true,',
  7611. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  7612. ' };',
  7613. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  7614. ' geocoder = new google.maps.Geocoder();',
  7615. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  7616. ' if (status == google.maps.GeocoderStatus.OK) {',
  7617. ' if (results[3]) {',
  7618. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  7619. ' }',
  7620. ' }',
  7621. ' });',
  7622. '}',
  7623. 'function search(address) {',
  7624. ' if (!map) return;',
  7625. ' geocoder.geocode({address : address}, function(results, status) {',
  7626. ' if (status == google.maps.GeocoderStatus.OK) {',
  7627. ' map.setZoom(11);',
  7628. ' map.setCenter(results[0].geometry.location);',
  7629. ' var marker = new google.maps.Marker({',
  7630. ' map: map,',
  7631. ' position: results[0].geometry.location',
  7632. ' });',
  7633. ' } else {',
  7634. ' alert("Invalid address: " + address);',
  7635. ' }',
  7636. ' });',
  7637. '}',
  7638. '</script>',
  7639. '</head>',
  7640. '<body onload="initialize();">',
  7641. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  7642. '</body></html>'].join('\n');
  7643. // TODO:用doc.write(iframeHtml)方式加载时,在IE6上第一次加载报错,暂时使用src方式
  7644. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  7645. function ready() {
  7646. win = iframe[0].contentWindow;
  7647. doc = K.iframeDoc(iframe);
  7648. //doc.open();
  7649. //doc.write(iframeHtml);
  7650. //doc.close();
  7651. }
  7652. iframe.bind('load', function() {
  7653. iframe.unbind('load');
  7654. if (K.IE) {
  7655. ready();
  7656. } else {
  7657. setTimeout(ready, 0);
  7658. }
  7659. });
  7660. K('.ke-map', div).replaceWith(iframe);
  7661. // search map
  7662. searchBtn.click(function() {
  7663. win.search(addressBox.val());
  7664. });
  7665. });
  7666. });
  7667. /*******************************************************************************
  7668. * KindEditor - WYSIWYG HTML Editor for Internet
  7669. * Copyright (C) 2006-2011 kindsoft.net
  7670. *
  7671. * @author Roddy <luolonghao@gmail.com>
  7672. * @site http://www.kindsoft.net/
  7673. * @licence http://www.kindsoft.net/license.php
  7674. *******************************************************************************/
  7675. KindEditor.plugin('media', function(K) {
  7676. var self = this, name = 'media', lang = self.lang(name + '.'),
  7677. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7678. allowFileManager = K.undef(self.allowFileManager, false),
  7679. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7680. extraParams = K.undef(self.extraFileUploadParams, {}),
  7681. filePostName = K.undef(self.filePostName, 'file'),
  7682. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7683. self.plugin.media = {
  7684. edit : function() {
  7685. var html = [
  7686. '<div style="padding:20px;">',
  7687. //url
  7688. '<div class="ke-dialog-row">',
  7689. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7690. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7691. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7692. '<span class="ke-button-common ke-button-outer">',
  7693. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7694. '</span>',
  7695. '</div>',
  7696. //width
  7697. '<div class="ke-dialog-row">',
  7698. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7699. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7700. '</div>',
  7701. //height
  7702. '<div class="ke-dialog-row">',
  7703. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7704. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7705. '</div>',
  7706. //autostart
  7707. '<div class="ke-dialog-row">',
  7708. '<label for="keAutostart">' + lang.autostart + '</label>',
  7709. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7710. '</div>',
  7711. '</div>'
  7712. ].join('');
  7713. var dialog = self.createDialog({
  7714. name : name,
  7715. width : 450,
  7716. height : 230,
  7717. title : self.lang(name),
  7718. body : html,
  7719. yesBtn : {
  7720. name : self.lang('yes'),
  7721. click : function(e) {
  7722. var url = K.trim(urlBox.val()),
  7723. width = widthBox.val(),
  7724. height = heightBox.val();
  7725. if (url == 'http://' || K.invalidUrl(url)) {
  7726. alert(self.lang('invalidUrl'));
  7727. urlBox[0].focus();
  7728. return;
  7729. }
  7730. if (!/^\d*$/.test(width)) {
  7731. alert(self.lang('invalidWidth'));
  7732. widthBox[0].focus();
  7733. return;
  7734. }
  7735. if (!/^\d*$/.test(height)) {
  7736. alert(self.lang('invalidHeight'));
  7737. heightBox[0].focus();
  7738. return;
  7739. }
  7740. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7741. src : url,
  7742. type : K.mediaType(url),
  7743. width : width,
  7744. height : height,
  7745. autostart : autostartBox[0].checked ? 'true' : 'false',
  7746. loop : 'true'
  7747. });
  7748. self.insertHtml(html).hideDialog().focus();
  7749. }
  7750. }
  7751. }),
  7752. div = dialog.div,
  7753. urlBox = K('[name="url"]', div),
  7754. viewServerBtn = K('[name="viewServer"]', div),
  7755. widthBox = K('[name="width"]', div),
  7756. heightBox = K('[name="height"]', div),
  7757. autostartBox = K('[name="autostart"]', div);
  7758. urlBox.val('http://');
  7759. if (allowMediaUpload) {
  7760. var uploadbutton = K.uploadbutton({
  7761. button : K('.ke-upload-button', div)[0],
  7762. fieldName : filePostName,
  7763. extraParams : extraParams,
  7764. url : uploadJson,
  7765. afterUpload : function(data) {
  7766. dialog.hideLoading();
  7767. if (data.code === 0) {
  7768. var url = data.files[0];
  7769. if (formatUploadUrl) {
  7770. url = K.formatUrl(url, 'absolute');
  7771. }
  7772. url = self.options.prefixStaticUrl+url;
  7773. urlBox.val(url);
  7774. if (self.afterUpload) {
  7775. self.afterUpload.call(self, url, data, name);
  7776. }
  7777. alert(self.lang('uploadSuccess'));
  7778. } else {
  7779. alert(data.message);
  7780. }
  7781. },
  7782. afterError : function(html) {
  7783. dialog.hideLoading();
  7784. self.errorDialog(html);
  7785. }
  7786. });
  7787. uploadbutton.fileBox.change(function(e) {
  7788. dialog.showLoading(self.lang('uploadLoading'));
  7789. uploadbutton.submit();
  7790. });
  7791. } else {
  7792. K('.ke-upload-button', div).hide();
  7793. }
  7794. if (allowFileManager) {
  7795. viewServerBtn.click(function(e) {
  7796. self.loadPlugin('filemanager', function() {
  7797. self.plugin.filemanagerDialog({
  7798. viewType : 'LIST',
  7799. dirName : 'media',
  7800. clickFn : function(url, title) {
  7801. if (self.dialogs.length > 1) {
  7802. K('[name="url"]', div).val(url);
  7803. if (self.afterSelectFile) {
  7804. self.afterSelectFile.call(self, url);
  7805. }
  7806. self.hideDialog();
  7807. }
  7808. }
  7809. });
  7810. });
  7811. });
  7812. } else {
  7813. viewServerBtn.hide();
  7814. }
  7815. var img = self.plugin.getSelectedMedia();
  7816. if (img) {
  7817. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7818. urlBox.val(attrs.src);
  7819. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7820. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7821. autostartBox[0].checked = (attrs.autostart === 'true');
  7822. }
  7823. urlBox[0].focus();
  7824. urlBox[0].select();
  7825. },
  7826. 'delete' : function() {
  7827. self.plugin.getSelectedMedia().remove();
  7828. // [IE] 删除图片后立即点击图片按钮出错
  7829. self.addBookmark();
  7830. }
  7831. };
  7832. self.clickToolbar(name, self.plugin.media.edit);
  7833. });
  7834. /*******************************************************************************
  7835. * KindEditor - WYSIWYG HTML Editor for Internet
  7836. * Copyright (C) 2006-2011 kindsoft.net
  7837. *
  7838. * @author Roddy <luolonghao@gmail.com>
  7839. * @site http://www.kindsoft.net/
  7840. * @licence http://www.kindsoft.net/license.php
  7841. *******************************************************************************/
  7842. (function(K) {
  7843. function KSWFUpload(options) {
  7844. this.init(options);
  7845. }
  7846. K.extend(KSWFUpload, {
  7847. init : function(options) {
  7848. var self = this;
  7849. options.afterError = options.afterError || function(str) {
  7850. alert(str);
  7851. };
  7852. self.options = options;
  7853. self.progressbars = {};
  7854. // template
  7855. self.div = K(options.container).html([
  7856. '<div class="ke-swfupload">',
  7857. '<div class="ke-swfupload-top">',
  7858. '<div class="ke-inline-block ke-swfupload-button">',
  7859. '<input type="button" value="Browse" />',
  7860. '</div>',
  7861. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7862. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7863. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7864. '</span>',
  7865. '</div>',
  7866. '<div class="ke-swfupload-body"></div>',
  7867. '</div>'
  7868. ].join(''));
  7869. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7870. function showError(itemDiv, msg) {
  7871. K('.ke-status > div', itemDiv).hide();
  7872. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7873. }
  7874. var settings = {
  7875. debug : false,
  7876. upload_url : options.uploadUrl,
  7877. flash_url : options.flashUrl,
  7878. file_post_name : options.filePostName,
  7879. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7880. button_image_url: options.buttonImageUrl,
  7881. button_width: options.buttonWidth,
  7882. button_height: options.buttonHeight,
  7883. button_cursor : SWFUpload.CURSOR.HAND,
  7884. file_types : options.fileTypes,
  7885. file_types_description : options.fileTypesDesc,
  7886. file_upload_limit : options.fileUploadLimit,
  7887. file_size_limit : options.fileSizeLimit,
  7888. post_params : options.postParams,
  7889. prefixStaticUrl:options.prefixStaticUrl,
  7890. file_queued_handler : function(file) {
  7891. file.url = self.options.fileIconUrl;
  7892. self.appendFile(file);
  7893. },
  7894. file_queue_error_handler : function(file, errorCode, message) {
  7895. var errorName = '';
  7896. switch (errorCode) {
  7897. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7898. errorName = options.queueLimitExceeded;
  7899. break;
  7900. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7901. errorName = options.fileExceedsSizeLimit;
  7902. break;
  7903. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7904. errorName = options.zeroByteFile;
  7905. break;
  7906. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7907. errorName = options.invalidFiletype;
  7908. break;
  7909. default:
  7910. errorName = options.unknownError;
  7911. break;
  7912. }
  7913. K.DEBUG && alert(errorName);
  7914. },
  7915. upload_start_handler : function(file) {
  7916. var self = this;
  7917. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7918. K('.ke-status > div', itemDiv).hide();
  7919. K('.ke-progressbar', itemDiv).show();
  7920. },
  7921. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7922. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7923. var progressbar = self.progressbars[file.id];
  7924. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7925. progressbar.percent.html(percent + '%');
  7926. },
  7927. upload_error_handler : function(file, errorCode, message) {
  7928. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7929. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7930. showError(itemDiv, self.options.errorMessage);
  7931. }
  7932. },
  7933. upload_success_handler : function(file, serverData) {
  7934. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7935. var data = {};
  7936. try {
  7937. data = K.json(serverData);
  7938. } catch (e) {
  7939. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7940. }
  7941. if (data.code !== 0) {
  7942. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7943. return;
  7944. }
  7945. file.url = data.files[0];
  7946. K('.ke-img', itemDiv).attr('src', self.options.prefixStaticUrl+file.url+'?w=80&h=80').attr('data-status', file.filestatus).data('data', data);
  7947. K('.ke-status > div', itemDiv).hide();
  7948. }
  7949. };
  7950. self.swfu = new SWFUpload(settings);
  7951. K('.ke-swfupload-startupload input', self.div).click(function() {
  7952. self.swfu.startUpload();
  7953. });
  7954. },
  7955. getUrlList : function() {
  7956. var list = [];
  7957. K('.ke-img', self.bodyDiv).each(function() {
  7958. var img = K(this);
  7959. var status = img.attr('data-status');
  7960. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7961. list.push(img.data('data'));
  7962. }
  7963. });
  7964. return list;
  7965. },
  7966. removeFile : function(fileId) {
  7967. var self = this;
  7968. self.swfu.cancelUpload(fileId);
  7969. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7970. K('.ke-photo', itemDiv).unbind();
  7971. K('.ke-delete', itemDiv).unbind();
  7972. itemDiv.remove();
  7973. },
  7974. removeFiles : function() {
  7975. var self = this;
  7976. K('.ke-item', self.bodyDiv).each(function() {
  7977. self.removeFile(K(this).attr('data-id'));
  7978. });
  7979. },
  7980. appendFile : function(file) {
  7981. var self = this;
  7982. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7983. self.bodyDiv.append(itemDiv);
  7984. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7985. .mouseover(function(e) {
  7986. K(this).addClass('ke-on');
  7987. })
  7988. .mouseout(function(e) {
  7989. K(this).removeClass('ke-on');
  7990. });
  7991. itemDiv.append(photoDiv);
  7992. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7993. photoDiv.append(img);
  7994. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  7995. self.removeFile(file.id);
  7996. });
  7997. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7998. // progressbar
  7999. K(['<div class="ke-progressbar">',
  8000. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8001. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8002. // message
  8003. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8004. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8005. self.progressbars[file.id] = {
  8006. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8007. percent : K('.ke-progressbar-percent', photoDiv)
  8008. };
  8009. },
  8010. remove : function() {
  8011. this.removeFiles();
  8012. this.swfu.destroy();
  8013. this.div.html('');
  8014. }
  8015. });
  8016. K.swfupload = function(element, options) {
  8017. return new KSWFUpload(element, options);
  8018. };
  8019. })(KindEditor);
  8020. KindEditor.plugin('multiimage', function(K) {
  8021. var self = this, name = 'multiimage',
  8022. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8023. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8024. imgPath = self.pluginsPath + 'multiimage/images/',
  8025. imageSizeLimit = K.undef(self.imageSizeLimit, '10MB'),
  8026. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8027. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8028. filePostName = K.undef(self.filePostName, 'file'),
  8029. lang = self.lang(name + '.');
  8030. self.plugin.multiImageDialog = function(options) {
  8031. var clickFn = options.clickFn,
  8032. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8033. var html = [
  8034. '<div style="padding:20px;">',
  8035. '<div class="swfupload">',
  8036. '</div>',
  8037. '</div>'
  8038. ].join('');
  8039. var dialog = self.createDialog({
  8040. name : name,
  8041. width : 650,
  8042. height : 510,
  8043. title : self.lang(name),
  8044. body : html,
  8045. previewBtn : {
  8046. name : lang.insertAll,
  8047. click : function(e) {
  8048. clickFn.call(self, swfupload.getUrlList());
  8049. }
  8050. },
  8051. yesBtn : {
  8052. name : lang.clearAll,
  8053. click : function(e) {
  8054. swfupload.removeFiles();
  8055. }
  8056. },
  8057. beforeRemove : function() {
  8058. // IE9 bugfix: https://github.com/kindsoft/kindeditor/issues/72
  8059. if (!K.IE || K.V <= 8) {
  8060. swfupload.remove();
  8061. }
  8062. }
  8063. }),
  8064. div = dialog.div;
  8065. var swfupload = K.swfupload({
  8066. container : K('.swfupload', div),
  8067. buttonImageUrl : imgPath + (self.langType == 'zh_CN' ? 'select-files-zh_CN.png' : 'select-files-en.png'),
  8068. buttonWidth : self.langType == 'zh_CN' ? 72 : 88,
  8069. buttonHeight : 23,
  8070. fileIconUrl : imgPath + 'image.png',
  8071. uploadDesc : uploadDesc,
  8072. startButtonValue : lang.startUpload,
  8073. uploadUrl : uploadJson,//K.addParam(uploadJson, 'dir=image'),
  8074. flashUrl : imgPath + 'swfupload.swf',
  8075. filePostName : filePostName,
  8076. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8077. fileTypesDesc : 'Image Files',
  8078. fileUploadLimit : imageUploadLimit,
  8079. fileSizeLimit : imageSizeLimit,
  8080. postParams : K.undef(self.extraFileUploadParams, {}),
  8081. queueLimitExceeded : lang.queueLimitExceeded,
  8082. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8083. zeroByteFile : lang.zeroByteFile,
  8084. invalidFiletype : lang.invalidFiletype,
  8085. unknownError : lang.unknownError,
  8086. pendingMessage : lang.pending,
  8087. errorMessage : lang.uploadError,
  8088. prefixStaticUrl:self.options.prefixStaticUrl,
  8089. afterError : function(html) {
  8090. self.errorDialog(html);
  8091. }
  8092. });
  8093. return dialog;
  8094. };
  8095. self.clickToolbar(name, function() {
  8096. self.plugin.multiImageDialog({
  8097. clickFn : function (urlList) {
  8098. if (urlList.length === 0) {
  8099. return;
  8100. }
  8101. K.each(urlList, function(i, data) {
  8102. if (self.afterUpload) {
  8103. self.afterUpload.call(self, data.url, data, 'multiimage');
  8104. }
  8105. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8106. });
  8107. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  8108. setTimeout(function() {
  8109. self.hideDialog().focus();
  8110. }, 0);
  8111. }
  8112. });
  8113. });
  8114. });
  8115. /**
  8116. * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
  8117. *
  8118. * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
  8119. *
  8120. * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz閚 and Mammon Media and is released under the MIT License:
  8121. * http://www.opensource.org/licenses/mit-license.php
  8122. *
  8123. * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
  8124. * http://www.opensource.org/licenses/mit-license.php
  8125. *
  8126. */
  8127. /* ******************* */
  8128. /* Constructor & Init */
  8129. /* ******************* */
  8130. (function() {
  8131. window.SWFUpload = function (settings) {
  8132. this.initSWFUpload(settings);
  8133. };
  8134. SWFUpload.prototype.initSWFUpload = function (settings) {
  8135. try {
  8136. this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
  8137. this.settings = settings;
  8138. this.eventQueue = [];
  8139. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8140. this.movieElement = null;
  8141. // Setup global control tracking
  8142. SWFUpload.instances[this.movieName] = this;
  8143. // Load the settings. Load the Flash movie.
  8144. this.initSettings();
  8145. this.loadFlash();
  8146. this.displayDebugInfo();
  8147. } catch (ex) {
  8148. delete SWFUpload.instances[this.movieName];
  8149. throw ex;
  8150. }
  8151. };
  8152. /* *************** */
  8153. /* Static Members */
  8154. /* *************** */
  8155. SWFUpload.instances = {};
  8156. SWFUpload.movieCount = 0;
  8157. SWFUpload.version = "2.2.0 2009-03-25";
  8158. SWFUpload.QUEUE_ERROR = {
  8159. QUEUE_LIMIT_EXCEEDED : -100,
  8160. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8161. ZERO_BYTE_FILE : -120,
  8162. INVALID_FILETYPE : -130
  8163. };
  8164. SWFUpload.UPLOAD_ERROR = {
  8165. HTTP_ERROR : -200,
  8166. MISSING_UPLOAD_URL : -210,
  8167. IO_ERROR : -220,
  8168. SECURITY_ERROR : -230,
  8169. UPLOAD_LIMIT_EXCEEDED : -240,
  8170. UPLOAD_FAILED : -250,
  8171. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8172. FILE_VALIDATION_FAILED : -270,
  8173. FILE_CANCELLED : -280,
  8174. UPLOAD_STOPPED : -290
  8175. };
  8176. SWFUpload.FILE_STATUS = {
  8177. QUEUED : -1,
  8178. IN_PROGRESS : -2,
  8179. ERROR : -3,
  8180. COMPLETE : -4,
  8181. CANCELLED : -5
  8182. };
  8183. SWFUpload.BUTTON_ACTION = {
  8184. SELECT_FILE : -100,
  8185. SELECT_FILES : -110,
  8186. START_UPLOAD : -120
  8187. };
  8188. SWFUpload.CURSOR = {
  8189. ARROW : -1,
  8190. HAND : -2
  8191. };
  8192. SWFUpload.WINDOW_MODE = {
  8193. WINDOW : "window",
  8194. TRANSPARENT : "transparent",
  8195. OPAQUE : "opaque"
  8196. };
  8197. // Private: takes a URL, determines if it is relative and converts to an absolute URL
  8198. // using the current site. Only processes the URL if it can, otherwise returns the URL untouched
  8199. SWFUpload.completeURL = function(url) {
  8200. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8201. return url;
  8202. }
  8203. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8204. var indexSlash = window.location.pathname.lastIndexOf("/");
  8205. if (indexSlash <= 0) {
  8206. path = "/";
  8207. } else {
  8208. path = window.location.pathname.substr(0, indexSlash) + "/";
  8209. }
  8210. return /*currentURL +*/ path + url;
  8211. };
  8212. /* ******************** */
  8213. /* Instance Members */
  8214. /* ******************** */
  8215. // Private: initSettings ensures that all the
  8216. // settings are set, getting a default value if one was not assigned.
  8217. SWFUpload.prototype.initSettings = function () {
  8218. this.ensureDefault = function (settingName, defaultValue) {
  8219. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8220. };
  8221. // Upload backend settings
  8222. this.ensureDefault("upload_url", "");
  8223. this.ensureDefault("preserve_relative_urls", false);
  8224. this.ensureDefault("file_post_name", "Filedata");
  8225. this.ensureDefault("post_params", {});
  8226. this.ensureDefault("use_query_string", false);
  8227. this.ensureDefault("requeue_on_error", false);
  8228. this.ensureDefault("http_success", []);
  8229. this.ensureDefault("assume_success_timeout", 0);
  8230. // File Settings
  8231. this.ensureDefault("file_types", "*.*");
  8232. this.ensureDefault("file_types_description", "All Files");
  8233. this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
  8234. this.ensureDefault("file_upload_limit", 0);
  8235. this.ensureDefault("file_queue_limit", 0);
  8236. // Flash Settings
  8237. this.ensureDefault("flash_url", "swfupload.swf");
  8238. this.ensureDefault("prevent_swf_caching", true);
  8239. // Button Settings
  8240. this.ensureDefault("button_image_url", "");
  8241. this.ensureDefault("button_width", 1);
  8242. this.ensureDefault("button_height", 1);
  8243. this.ensureDefault("button_text", "");
  8244. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8245. this.ensureDefault("button_text_top_padding", 0);
  8246. this.ensureDefault("button_text_left_padding", 0);
  8247. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8248. this.ensureDefault("button_disabled", false);
  8249. this.ensureDefault("button_placeholder_id", "");
  8250. this.ensureDefault("button_placeholder", null);
  8251. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8252. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8253. // Debug Settings
  8254. this.ensureDefault("debug", false);
  8255. this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
  8256. // Event Handlers
  8257. this.settings.return_upload_start_handler = this.returnUploadStart;
  8258. this.ensureDefault("swfupload_loaded_handler", null);
  8259. this.ensureDefault("file_dialog_start_handler", null);
  8260. this.ensureDefault("file_queued_handler", null);
  8261. this.ensureDefault("file_queue_error_handler", null);
  8262. this.ensureDefault("file_dialog_complete_handler", null);
  8263. this.ensureDefault("upload_start_handler", null);
  8264. this.ensureDefault("upload_progress_handler", null);
  8265. this.ensureDefault("upload_error_handler", null);
  8266. this.ensureDefault("upload_success_handler", null);
  8267. this.ensureDefault("upload_complete_handler", null);
  8268. this.ensureDefault("debug_handler", this.debugMessage);
  8269. this.ensureDefault("custom_settings", {});
  8270. // Other settings
  8271. this.customSettings = this.settings.custom_settings;
  8272. // Update the flash url if needed
  8273. if (!!this.settings.prevent_swf_caching) {
  8274. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8275. }
  8276. if (!this.settings.preserve_relative_urls) {
  8277. //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it
  8278. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8279. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8280. }
  8281. delete this.ensureDefault;
  8282. };
  8283. // Private: loadFlash replaces the button_placeholder element with the flash movie.
  8284. SWFUpload.prototype.loadFlash = function () {
  8285. var targetElement, tempParent;
  8286. // Make sure an element with the ID we are going to use doesn't already exist
  8287. if (document.getElementById(this.movieName) !== null) {
  8288. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8289. }
  8290. // Get the element where we will be placing the flash movie
  8291. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8292. if (targetElement == undefined) {
  8293. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8294. }
  8295. // Append the container and load the flash
  8296. tempParent = document.createElement("div");
  8297. tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
  8298. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8299. // Fix IE Flash/Form bug
  8300. if (window[this.movieName] == undefined) {
  8301. window[this.movieName] = this.getMovieElement();
  8302. }
  8303. };
  8304. // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
  8305. SWFUpload.prototype.getFlashHTML = function () {
  8306. // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  8307. // Fix bug for IE9
  8308. // http://www.kindsoft.net/view.php?bbsid=7&postid=5825&pagenum=1
  8309. var classid = '';
  8310. if (KindEditor.IE && KindEditor.V > 8) {
  8311. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8312. }
  8313. 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">',
  8314. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8315. '<param name="movie" value="', this.settings.flash_url, '" />',
  8316. '<param name="quality" value="high" />',
  8317. '<param name="menu" value="false" />',
  8318. '<param name="allowScriptAccess" value="always" />',
  8319. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8320. '</object>'].join("");
  8321. };
  8322. // Private: getFlashVars builds the parameter string that will be passed
  8323. // to flash in the flashvars param.
  8324. SWFUpload.prototype.getFlashVars = function () {
  8325. // Build a string from the post param object
  8326. var paramString = this.buildParamString();
  8327. var httpSuccessString = this.settings.http_success.join(",");
  8328. // Build the parameter string
  8329. return ["movieName=", encodeURIComponent(this.movieName),
  8330. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8331. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8332. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8333. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8334. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8335. "&amp;params=", encodeURIComponent(paramString),
  8336. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8337. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8338. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8339. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8340. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8341. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8342. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8343. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8344. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8345. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8346. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8347. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8348. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8349. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8350. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8351. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8352. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8353. ].join("");
  8354. };
  8355. // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
  8356. // The element is cached after the first lookup
  8357. SWFUpload.prototype.getMovieElement = function () {
  8358. if (this.movieElement == undefined) {
  8359. this.movieElement = document.getElementById(this.movieName);
  8360. }
  8361. if (this.movieElement === null) {
  8362. throw "Could not find Flash element";
  8363. }
  8364. return this.movieElement;
  8365. };
  8366. // Private: buildParamString takes the name/value pairs in the post_params setting object
  8367. // and joins them up in to a string formatted "name=value&amp;name=value"
  8368. SWFUpload.prototype.buildParamString = function () {
  8369. var postParams = this.settings.post_params;
  8370. var paramStringPairs = [];
  8371. if (typeof(postParams) === "object") {
  8372. for (var name in postParams) {
  8373. if (postParams.hasOwnProperty(name)) {
  8374. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8375. }
  8376. }
  8377. }
  8378. return paramStringPairs.join("&amp;");
  8379. };
  8380. // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
  8381. // all references to the SWF, and other objects so memory is properly freed.
  8382. // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
  8383. // Credits: Major improvements provided by steffen
  8384. SWFUpload.prototype.destroy = function () {
  8385. try {
  8386. // Make sure Flash is done before we try to remove it
  8387. this.cancelUpload(null, false);
  8388. // Remove the SWFUpload DOM nodes
  8389. var movieElement = null;
  8390. movieElement = this.getMovieElement();
  8391. if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8392. // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
  8393. for (var i in movieElement) {
  8394. try {
  8395. if (typeof(movieElement[i]) === "function") {
  8396. movieElement[i] = null;
  8397. }
  8398. } catch (ex1) {}
  8399. }
  8400. // Remove the Movie Element from the page
  8401. try {
  8402. movieElement.parentNode.removeChild(movieElement);
  8403. } catch (ex) {}
  8404. }
  8405. // Remove IE form fix reference
  8406. window[this.movieName] = null;
  8407. // Destroy other references
  8408. SWFUpload.instances[this.movieName] = null;
  8409. delete SWFUpload.instances[this.movieName];
  8410. this.movieElement = null;
  8411. this.settings = null;
  8412. this.customSettings = null;
  8413. this.eventQueue = null;
  8414. this.movieName = null;
  8415. return true;
  8416. } catch (ex2) {
  8417. return false;
  8418. }
  8419. };
  8420. // Public: displayDebugInfo prints out settings and configuration
  8421. // information about this SWFUpload instance.
  8422. // This function (and any references to it) can be deleted when placing
  8423. // SWFUpload in production.
  8424. SWFUpload.prototype.displayDebugInfo = function () {
  8425. this.debug(
  8426. [
  8427. "---SWFUpload Instance Info---\n",
  8428. "Version: ", SWFUpload.version, "\n",
  8429. "Movie Name: ", this.movieName, "\n",
  8430. "Settings:\n",
  8431. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8432. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8433. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8434. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8435. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8436. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8437. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8438. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8439. "\t", "file_types: ", this.settings.file_types, "\n",
  8440. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8441. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8442. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8443. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8444. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8445. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8446. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8447. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8448. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8449. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8450. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8451. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8452. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8453. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8454. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8455. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8456. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8457. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8458. "Event Handlers:\n",
  8459. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8460. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8461. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8462. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8463. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8464. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8465. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8466. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8467. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8468. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8469. ].join("")
  8470. );
  8471. };
  8472. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8473. the maintain v2 API compatibility
  8474. */
  8475. // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
  8476. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8477. if (value == undefined) {
  8478. return (this.settings[name] = default_value);
  8479. } else {
  8480. return (this.settings[name] = value);
  8481. }
  8482. };
  8483. // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
  8484. SWFUpload.prototype.getSetting = function (name) {
  8485. if (this.settings[name] != undefined) {
  8486. return this.settings[name];
  8487. }
  8488. return "";
  8489. };
  8490. // Private: callFlash handles function calls made to the Flash element.
  8491. // Calls are made with a setTimeout for some functions to work around
  8492. // bugs in the ExternalInterface library.
  8493. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8494. argumentArray = argumentArray || [];
  8495. var movieElement = this.getMovieElement();
  8496. var returnValue, returnString;
  8497. // Flash's method if calling ExternalInterface methods (code adapted from MooTools).
  8498. try {
  8499. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8500. returnValue = eval(returnString);
  8501. } catch (ex) {
  8502. throw "Call to " + functionName + " failed";
  8503. }
  8504. // Unescape file post param values
  8505. if (returnValue != undefined && typeof returnValue.post === "object") {
  8506. returnValue = this.unescapeFilePostParams(returnValue);
  8507. }
  8508. return returnValue;
  8509. };
  8510. /* *****************************
  8511. -- Flash control methods --
  8512. Your UI should use these
  8513. to operate SWFUpload
  8514. ***************************** */
  8515. // WARNING: this function does not work in Flash Player 10
  8516. // Public: selectFile causes a File Selection Dialog window to appear. This
  8517. // dialog only allows 1 file to be selected.
  8518. SWFUpload.prototype.selectFile = function () {
  8519. this.callFlash("SelectFile");
  8520. };
  8521. // WARNING: this function does not work in Flash Player 10
  8522. // Public: selectFiles causes a File Selection Dialog window to appear/ This
  8523. // dialog allows the user to select any number of files
  8524. // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
  8525. // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
  8526. // for this bug.
  8527. SWFUpload.prototype.selectFiles = function () {
  8528. this.callFlash("SelectFiles");
  8529. };
  8530. // Public: startUpload starts uploading the first file in the queue unless
  8531. // the optional parameter 'fileID' specifies the ID
  8532. SWFUpload.prototype.startUpload = function (fileID) {
  8533. this.callFlash("StartUpload", [fileID]);
  8534. };
  8535. // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
  8536. // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
  8537. // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
  8538. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8539. if (triggerErrorEvent !== false) {
  8540. triggerErrorEvent = true;
  8541. }
  8542. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8543. };
  8544. // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
  8545. // If nothing is currently uploading then nothing happens.
  8546. SWFUpload.prototype.stopUpload = function () {
  8547. this.callFlash("StopUpload");
  8548. };
  8549. /* ************************
  8550. * Settings methods
  8551. * These methods change the SWFUpload settings.
  8552. * SWFUpload settings should not be changed directly on the settings object
  8553. * since many of the settings need to be passed to Flash in order to take
  8554. * effect.
  8555. * *********************** */
  8556. // Public: getStats gets the file statistics object.
  8557. SWFUpload.prototype.getStats = function () {
  8558. return this.callFlash("GetStats");
  8559. };
  8560. // Public: setStats changes the SWFUpload statistics. You shouldn't need to
  8561. // change the statistics but you can. Changing the statistics does not
  8562. // affect SWFUpload accept for the successful_uploads count which is used
  8563. // by the upload_limit setting to determine how many files the user may upload.
  8564. SWFUpload.prototype.setStats = function (statsObject) {
  8565. this.callFlash("SetStats", [statsObject]);
  8566. };
  8567. // Public: getFile retrieves a File object by ID or Index. If the file is
  8568. // not found then 'null' is returned.
  8569. SWFUpload.prototype.getFile = function (fileID) {
  8570. if (typeof(fileID) === "number") {
  8571. return this.callFlash("GetFileByIndex", [fileID]);
  8572. } else {
  8573. return this.callFlash("GetFile", [fileID]);
  8574. }
  8575. };
  8576. // Public: addFileParam sets a name/value pair that will be posted with the
  8577. // file specified by the Files ID. If the name already exists then the
  8578. // exiting value will be overwritten.
  8579. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8580. return this.callFlash("AddFileParam", [fileID, name, value]);
  8581. };
  8582. // Public: removeFileParam removes a previously set (by addFileParam) name/value
  8583. // pair from the specified file.
  8584. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8585. this.callFlash("RemoveFileParam", [fileID, name]);
  8586. };
  8587. // Public: setUploadUrl changes the upload_url setting.
  8588. SWFUpload.prototype.setUploadURL = function (url) {
  8589. this.settings.upload_url = url.toString();
  8590. this.callFlash("SetUploadURL", [url]);
  8591. };
  8592. // Public: setPostParams changes the post_params setting
  8593. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8594. this.settings.post_params = paramsObject;
  8595. this.callFlash("SetPostParams", [paramsObject]);
  8596. };
  8597. // Public: addPostParam adds post name/value pair. Each name can have only one value.
  8598. SWFUpload.prototype.addPostParam = function (name, value) {
  8599. this.settings.post_params[name] = value;
  8600. this.callFlash("SetPostParams", [this.settings.post_params]);
  8601. };
  8602. // Public: removePostParam deletes post name/value pair.
  8603. SWFUpload.prototype.removePostParam = function (name) {
  8604. delete this.settings.post_params[name];
  8605. this.callFlash("SetPostParams", [this.settings.post_params]);
  8606. };
  8607. // Public: setFileTypes changes the file_types setting and the file_types_description setting
  8608. SWFUpload.prototype.setFileTypes = function (types, description) {
  8609. this.settings.file_types = types;
  8610. this.settings.file_types_description = description;
  8611. this.callFlash("SetFileTypes", [types, description]);
  8612. };
  8613. // Public: setFileSizeLimit changes the file_size_limit setting
  8614. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8615. this.settings.file_size_limit = fileSizeLimit;
  8616. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8617. };
  8618. // Public: setFileUploadLimit changes the file_upload_limit setting
  8619. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8620. this.settings.file_upload_limit = fileUploadLimit;
  8621. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8622. };
  8623. // Public: setFileQueueLimit changes the file_queue_limit setting
  8624. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8625. this.settings.file_queue_limit = fileQueueLimit;
  8626. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8627. };
  8628. // Public: setFilePostName changes the file_post_name setting
  8629. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8630. this.settings.file_post_name = filePostName;
  8631. this.callFlash("SetFilePostName", [filePostName]);
  8632. };
  8633. // Public: setUseQueryString changes the use_query_string setting
  8634. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8635. this.settings.use_query_string = useQueryString;
  8636. this.callFlash("SetUseQueryString", [useQueryString]);
  8637. };
  8638. // Public: setRequeueOnError changes the requeue_on_error setting
  8639. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8640. this.settings.requeue_on_error = requeueOnError;
  8641. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8642. };
  8643. // Public: setHTTPSuccess changes the http_success setting
  8644. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8645. if (typeof http_status_codes === "string") {
  8646. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8647. }
  8648. this.settings.http_success = http_status_codes;
  8649. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8650. };
  8651. // Public: setHTTPSuccess changes the http_success setting
  8652. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8653. this.settings.assume_success_timeout = timeout_seconds;
  8654. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8655. };
  8656. // Public: setDebugEnabled changes the debug_enabled setting
  8657. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8658. this.settings.debug_enabled = debugEnabled;
  8659. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8660. };
  8661. // Public: setButtonImageURL loads a button image sprite
  8662. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8663. if (buttonImageURL == undefined) {
  8664. buttonImageURL = "";
  8665. }
  8666. this.settings.button_image_url = buttonImageURL;
  8667. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8668. };
  8669. // Public: setButtonDimensions resizes the Flash Movie and button
  8670. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8671. this.settings.button_width = width;
  8672. this.settings.button_height = height;
  8673. var movie = this.getMovieElement();
  8674. if (movie != undefined) {
  8675. movie.style.width = width + "px";
  8676. movie.style.height = height + "px";
  8677. }
  8678. this.callFlash("SetButtonDimensions", [width, height]);
  8679. };
  8680. // Public: setButtonText Changes the text overlaid on the button
  8681. SWFUpload.prototype.setButtonText = function (html) {
  8682. this.settings.button_text = html;
  8683. this.callFlash("SetButtonText", [html]);
  8684. };
  8685. // Public: setButtonTextPadding changes the top and left padding of the text overlay
  8686. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8687. this.settings.button_text_top_padding = top;
  8688. this.settings.button_text_left_padding = left;
  8689. this.callFlash("SetButtonTextPadding", [left, top]);
  8690. };
  8691. // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
  8692. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8693. this.settings.button_text_style = css;
  8694. this.callFlash("SetButtonTextStyle", [css]);
  8695. };
  8696. // Public: setButtonDisabled disables/enables the button
  8697. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8698. this.settings.button_disabled = isDisabled;
  8699. this.callFlash("SetButtonDisabled", [isDisabled]);
  8700. };
  8701. // Public: setButtonAction sets the action that occurs when the button is clicked
  8702. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8703. this.settings.button_action = buttonAction;
  8704. this.callFlash("SetButtonAction", [buttonAction]);
  8705. };
  8706. // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
  8707. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8708. this.settings.button_cursor = cursor;
  8709. this.callFlash("SetButtonCursor", [cursor]);
  8710. };
  8711. /* *******************************
  8712. Flash Event Interfaces
  8713. These functions are used by Flash to trigger the various
  8714. events.
  8715. All these functions a Private.
  8716. Because the ExternalInterface library is buggy the event calls
  8717. are added to a queue and the queue then executed by a setTimeout.
  8718. This ensures that events are executed in a determinate order and that
  8719. the ExternalInterface bugs are avoided.
  8720. ******************************* */
  8721. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8722. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8723. if (argumentArray == undefined) {
  8724. argumentArray = [];
  8725. } else if (!(argumentArray instanceof Array)) {
  8726. argumentArray = [argumentArray];
  8727. }
  8728. var self = this;
  8729. if (typeof this.settings[handlerName] === "function") {
  8730. // Queue the event
  8731. this.eventQueue.push(function () {
  8732. this.settings[handlerName].apply(this, argumentArray);
  8733. });
  8734. // Execute the next queued event
  8735. setTimeout(function () {
  8736. self.executeNextEvent();
  8737. }, 0);
  8738. } else if (this.settings[handlerName] !== null) {
  8739. throw "Event handler " + handlerName + " is unknown or is not a function";
  8740. }
  8741. };
  8742. // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
  8743. // we must queue them in order to garentee that they are executed in order.
  8744. SWFUpload.prototype.executeNextEvent = function () {
  8745. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8746. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8747. if (typeof(f) === "function") {
  8748. f.apply(this);
  8749. }
  8750. };
  8751. // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
  8752. // properties that contain characters that are not valid for JavaScript identifiers. To work around this
  8753. // the Flash Component escapes the parameter names and we must unescape again before passing them along.
  8754. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8755. var reg = /[$]([0-9a-f]{4})/i;
  8756. var unescapedPost = {};
  8757. var uk;
  8758. if (file != undefined) {
  8759. for (var k in file.post) {
  8760. if (file.post.hasOwnProperty(k)) {
  8761. uk = k;
  8762. var match;
  8763. while ((match = reg.exec(uk)) !== null) {
  8764. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8765. }
  8766. unescapedPost[uk] = file.post[k];
  8767. }
  8768. }
  8769. file.post = unescapedPost;
  8770. }
  8771. return file;
  8772. };
  8773. // Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working)
  8774. SWFUpload.prototype.testExternalInterface = function () {
  8775. try {
  8776. return this.callFlash("TestExternalInterface");
  8777. } catch (ex) {
  8778. return false;
  8779. }
  8780. };
  8781. // Private: This event is called by Flash when it has finished loading. Don't modify this.
  8782. // Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded.
  8783. SWFUpload.prototype.flashReady = function () {
  8784. // Check that the movie element is loaded correctly with its ExternalInterface methods defined
  8785. var movieElement = this.getMovieElement();
  8786. if (!movieElement) {
  8787. this.debug("Flash called back ready but the flash movie can't be found.");
  8788. return;
  8789. }
  8790. this.cleanUp(movieElement);
  8791. this.queueEvent("swfupload_loaded_handler");
  8792. };
  8793. // Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
  8794. // This function is called by Flash each time the ExternalInterface functions are created.
  8795. SWFUpload.prototype.cleanUp = function (movieElement) {
  8796. // Pro-actively unhook all the Flash functions
  8797. try {
  8798. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8799. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8800. for (var key in movieElement) {
  8801. try {
  8802. if (typeof(movieElement[key]) === "function") {
  8803. movieElement[key] = null;
  8804. }
  8805. } catch (ex) {
  8806. }
  8807. }
  8808. }
  8809. } catch (ex1) {
  8810. }
  8811. // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
  8812. // it doesn't display errors.
  8813. window["__flash__removeCallback"] = function (instance, name) {
  8814. try {
  8815. if (instance) {
  8816. instance[name] = null;
  8817. }
  8818. } catch (flashEx) {
  8819. }
  8820. };
  8821. };
  8822. /* This is a chance to do something before the browse window opens */
  8823. SWFUpload.prototype.fileDialogStart = function () {
  8824. this.queueEvent("file_dialog_start_handler");
  8825. };
  8826. /* Called when a file is successfully added to the queue. */
  8827. SWFUpload.prototype.fileQueued = function (file) {
  8828. file = this.unescapeFilePostParams(file);
  8829. this.queueEvent("file_queued_handler", file);
  8830. };
  8831. /* Handle errors that occur when an attempt to queue a file fails. */
  8832. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8833. file = this.unescapeFilePostParams(file);
  8834. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8835. };
  8836. /* Called after the file dialog has closed and the selected files have been queued.
  8837. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8838. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8839. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8840. };
  8841. SWFUpload.prototype.uploadStart = function (file) {
  8842. file = this.unescapeFilePostParams(file);
  8843. this.queueEvent("return_upload_start_handler", file);
  8844. };
  8845. SWFUpload.prototype.returnUploadStart = function (file) {
  8846. var returnValue;
  8847. if (typeof this.settings.upload_start_handler === "function") {
  8848. file = this.unescapeFilePostParams(file);
  8849. returnValue = this.settings.upload_start_handler.call(this, file);
  8850. } else if (this.settings.upload_start_handler != undefined) {
  8851. throw "upload_start_handler must be a function";
  8852. }
  8853. // Convert undefined to true so if nothing is returned from the upload_start_handler it is
  8854. // interpretted as 'true'.
  8855. if (returnValue === undefined) {
  8856. returnValue = true;
  8857. }
  8858. returnValue = !!returnValue;
  8859. this.callFlash("ReturnUploadStart", [returnValue]);
  8860. };
  8861. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8862. file = this.unescapeFilePostParams(file);
  8863. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8864. };
  8865. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8866. file = this.unescapeFilePostParams(file);
  8867. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8868. };
  8869. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8870. file = this.unescapeFilePostParams(file);
  8871. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8872. };
  8873. SWFUpload.prototype.uploadComplete = function (file) {
  8874. file = this.unescapeFilePostParams(file);
  8875. this.queueEvent("upload_complete_handler", file);
  8876. };
  8877. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8878. internal debug console. You can override this event and have messages written where you want. */
  8879. SWFUpload.prototype.debug = function (message) {
  8880. this.queueEvent("debug_handler", message);
  8881. };
  8882. /* **********************************
  8883. Debug Console
  8884. The debug console is a self contained, in page location
  8885. for debug message to be sent. The Debug Console adds
  8886. itself to the body if necessary.
  8887. The console is automatically scrolled as messages appear.
  8888. If you are using your own debug handler or when you deploy to production and
  8889. have debug disabled you can remove these functions to reduce the file size
  8890. and complexity.
  8891. ********************************** */
  8892. // Private: debugMessage is the default debug_handler. If you want to print debug messages
  8893. // call the debug() function. When overriding the function your own function should
  8894. // check to see if the debug setting is true before outputting debug information.
  8895. SWFUpload.prototype.debugMessage = function (message) {
  8896. if (this.settings.debug) {
  8897. var exceptionMessage, exceptionValues = [];
  8898. // Check for an exception object and print it nicely
  8899. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8900. for (var key in message) {
  8901. if (message.hasOwnProperty(key)) {
  8902. exceptionValues.push(key + ": " + message[key]);
  8903. }
  8904. }
  8905. exceptionMessage = exceptionValues.join("\n") || "";
  8906. exceptionValues = exceptionMessage.split("\n");
  8907. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8908. SWFUpload.Console.writeLine(exceptionMessage);
  8909. } else {
  8910. SWFUpload.Console.writeLine(message);
  8911. }
  8912. }
  8913. };
  8914. SWFUpload.Console = {};
  8915. SWFUpload.Console.writeLine = function (message) {
  8916. var console, documentForm;
  8917. try {
  8918. console = document.getElementById("SWFUpload_Console");
  8919. if (!console) {
  8920. documentForm = document.createElement("form");
  8921. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8922. console = document.createElement("textarea");
  8923. console.id = "SWFUpload_Console";
  8924. console.style.fontFamily = "monospace";
  8925. console.setAttribute("wrap", "off");
  8926. console.wrap = "off";
  8927. console.style.overflow = "auto";
  8928. console.style.width = "700px";
  8929. console.style.height = "350px";
  8930. console.style.margin = "5px";
  8931. documentForm.appendChild(console);
  8932. }
  8933. console.value += message + "\n";
  8934. console.scrollTop = console.scrollHeight - console.clientHeight;
  8935. } catch (ex) {
  8936. alert("Exception: " + ex.name + " Message: " + ex.message);
  8937. }
  8938. };
  8939. })();
  8940. (function() {
  8941. /*
  8942. Queue Plug-in
  8943. Features:
  8944. *Adds a cancelQueue() method for cancelling the entire queue.
  8945. *All queued files are uploaded when startUpload() is called.
  8946. *If false is returned from uploadComplete then the queue upload is stopped.
  8947. If false is not returned (strict comparison) then the queue upload is continued.
  8948. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8949. Set the event handler with the queue_complete_handler setting.
  8950. */
  8951. if (typeof(SWFUpload) === "function") {
  8952. SWFUpload.queue = {};
  8953. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8954. return function () {
  8955. if (typeof(oldInitSettings) === "function") {
  8956. oldInitSettings.call(this);
  8957. }
  8958. this.queueSettings = {};
  8959. this.queueSettings.queue_cancelled_flag = false;
  8960. this.queueSettings.queue_upload_count = 0;
  8961. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8962. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8963. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8964. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8965. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8966. };
  8967. })(SWFUpload.prototype.initSettings);
  8968. SWFUpload.prototype.startUpload = function (fileID) {
  8969. this.queueSettings.queue_cancelled_flag = false;
  8970. this.callFlash("StartUpload", [fileID]);
  8971. };
  8972. SWFUpload.prototype.cancelQueue = function () {
  8973. this.queueSettings.queue_cancelled_flag = true;
  8974. this.stopUpload();
  8975. var stats = this.getStats();
  8976. while (stats.files_queued > 0) {
  8977. this.cancelUpload();
  8978. stats = this.getStats();
  8979. }
  8980. };
  8981. SWFUpload.queue.uploadStartHandler = function (file) {
  8982. var returnValue;
  8983. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8984. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8985. }
  8986. // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
  8987. returnValue = (returnValue === false) ? false : true;
  8988. this.queueSettings.queue_cancelled_flag = !returnValue;
  8989. return returnValue;
  8990. };
  8991. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8992. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8993. var continueUpload;
  8994. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8995. this.queueSettings.queue_upload_count++;
  8996. }
  8997. if (typeof(user_upload_complete_handler) === "function") {
  8998. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8999. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  9000. // If the file was stopped and re-queued don't restart the upload
  9001. continueUpload = false;
  9002. } else {
  9003. continueUpload = true;
  9004. }
  9005. if (continueUpload) {
  9006. var stats = this.getStats();
  9007. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  9008. this.startUpload();
  9009. } else if (this.queueSettings.queue_cancelled_flag === false) {
  9010. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  9011. this.queueSettings.queue_upload_count = 0;
  9012. } else {
  9013. this.queueSettings.queue_cancelled_flag = false;
  9014. this.queueSettings.queue_upload_count = 0;
  9015. }
  9016. }
  9017. };
  9018. }
  9019. })();
  9020. /*******************************************************************************
  9021. * KindEditor - WYSIWYG HTML Editor for Internet
  9022. * Copyright (C) 2006-2011 kindsoft.net
  9023. *
  9024. * @author Roddy <luolonghao@gmail.com>
  9025. * @site http://www.kindsoft.net/
  9026. * @licence http://www.kindsoft.net/license.php
  9027. *******************************************************************************/
  9028. KindEditor.plugin('pagebreak', function(K) {
  9029. var self = this;
  9030. var name = 'pagebreak';
  9031. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  9032. self.clickToolbar(name, function() {
  9033. var cmd = self.cmd, range = cmd.range;
  9034. self.focus();
  9035. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  9036. self.insertHtml(pagebreakHtml + tail);
  9037. if (tail !== '') {
  9038. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9039. range.selectNodeContents(p[0]);
  9040. p.removeAttr('id');
  9041. cmd.select();
  9042. }
  9043. });
  9044. });
  9045. /*******************************************************************************
  9046. * KindEditor - WYSIWYG HTML Editor for Internet
  9047. * Copyright (C) 2006-2011 kindsoft.net
  9048. *
  9049. * @author Roddy <luolonghao@gmail.com>
  9050. * @site http://www.kindsoft.net/
  9051. * @licence http://www.kindsoft.net/license.php
  9052. *******************************************************************************/
  9053. KindEditor.plugin('plainpaste', function(K) {
  9054. var self = this, name = 'plainpaste';
  9055. self.clickToolbar(name, function() {
  9056. var lang = self.lang(name + '.'),
  9057. html = '<div style="padding:10px 20px;">' +
  9058. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9059. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9060. '</div>',
  9061. dialog = self.createDialog({
  9062. name : name,
  9063. width : 450,
  9064. title : self.lang(name),
  9065. body : html,
  9066. yesBtn : {
  9067. name : self.lang('yes'),
  9068. click : function(e) {
  9069. var html = textarea.val();
  9070. html = K.escape(html);
  9071. html = html.replace(/ {2}/g, ' &nbsp;');
  9072. if (self.newlineTag == 'p') {
  9073. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9074. } else {
  9075. html = html.replace(/\n/g, '<br />$&');
  9076. }
  9077. self.insertHtml(html).hideDialog().focus();
  9078. }
  9079. }
  9080. }),
  9081. textarea = K('textarea', dialog.div);
  9082. textarea[0].focus();
  9083. });
  9084. });
  9085. /*******************************************************************************
  9086. * KindEditor - WYSIWYG HTML Editor for Internet
  9087. * Copyright (C) 2006-2011 kindsoft.net
  9088. *
  9089. * @author Roddy <luolonghao@gmail.com>
  9090. * @site http://www.kindsoft.net/
  9091. * @licence http://www.kindsoft.net/license.php
  9092. *******************************************************************************/
  9093. KindEditor.plugin('preview', function(K) {
  9094. var self = this, name = 'preview', undefined;
  9095. self.clickToolbar(name, function() {
  9096. var lang = self.lang(name + '.'),
  9097. html = '<div style="padding:10px 20px;">' +
  9098. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9099. '</div>',
  9100. dialog = self.createDialog({
  9101. name : name,
  9102. width : 750,
  9103. title : self.lang(name),
  9104. body : html
  9105. }),
  9106. iframe = K('iframe', dialog.div),
  9107. doc = K.iframeDoc(iframe);
  9108. doc.open();
  9109. doc.write(self.fullHtml());
  9110. doc.close();
  9111. K(doc.body).css('background-color', '#FFF');
  9112. iframe[0].contentWindow.focus();
  9113. });
  9114. });
  9115. /*******************************************************************************
  9116. * KindEditor - WYSIWYG HTML Editor for Internet
  9117. * Copyright (C) 2006-2011 kindsoft.net
  9118. *
  9119. * @author Roddy <luolonghao@gmail.com>
  9120. * @site http://www.kindsoft.net/
  9121. * @licence http://www.kindsoft.net/license.php
  9122. *******************************************************************************/
  9123. KindEditor.plugin('quickformat', function(K) {
  9124. var self = this, name = 'quickformat',
  9125. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9126. function getFirstChild(knode) {
  9127. var child = knode.first();
  9128. while (child && child.first()) {
  9129. child = child.first();
  9130. }
  9131. return child;
  9132. }
  9133. self.clickToolbar(name, function() {
  9134. self.focus();
  9135. var doc = self.edit.doc,
  9136. range = self.cmd.range,
  9137. child = K(doc.body).first(), next,
  9138. nodeList = [], subList = [],
  9139. bookmark = range.createBookmark(true);
  9140. while(child) {
  9141. next = child.next();
  9142. var firstChild = getFirstChild(child);
  9143. if (!firstChild || firstChild.name != 'img') {
  9144. if (blockMap[child.name]) {
  9145. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9146. child.css('text-indent', '2em');
  9147. } else {
  9148. subList.push(child);
  9149. }
  9150. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9151. if (subList.length > 0) {
  9152. nodeList.push(subList);
  9153. }
  9154. subList = [];
  9155. }
  9156. }
  9157. child = next;
  9158. }
  9159. K.each(nodeList, function(i, subList) {
  9160. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9161. subList[0].before(wrapper);
  9162. K.each(subList, function(i, knode) {
  9163. wrapper.append(knode);
  9164. });
  9165. });
  9166. range.moveToBookmark(bookmark);
  9167. self.addBookmark();
  9168. });
  9169. });
  9170. /**
  9171. --------------------------
  9172. abcd<br />
  9173. 1234<br />
  9174. to
  9175. <p style="text-indent:2em;">
  9176. abcd<br />
  9177. 1234<br />
  9178. </p>
  9179. --------------------------
  9180. &nbsp; abcd<img>1233
  9181. <p>1234</p>
  9182. to
  9183. <p style="text-indent:2em;">abcd<img>1233</p>
  9184. <p style="text-indent:2em;">1234</p>
  9185. --------------------------
  9186. *//*******************************************************************************
  9187. * KindEditor - WYSIWYG HTML Editor for Internet
  9188. * Copyright (C) 2006-2011 kindsoft.net
  9189. *
  9190. * @author Roddy <luolonghao@gmail.com>
  9191. * @site http://www.kindsoft.net/
  9192. * @licence http://www.kindsoft.net/license.php
  9193. *******************************************************************************/
  9194. KindEditor.plugin('table', function(K) {
  9195. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9196. // 设置颜色
  9197. function _setColor(box, color) {
  9198. color = color.toUpperCase();
  9199. box.css('background-color', color);
  9200. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9201. box.html(color);
  9202. }
  9203. // 初始化取色器
  9204. var pickerList = [];
  9205. function _initColorPicker(dialogDiv, colorBox) {
  9206. colorBox.bind('click,mousedown', function(e){
  9207. e.stopPropagation();
  9208. });
  9209. function removePicker() {
  9210. K.each(pickerList, function() {
  9211. this.remove();
  9212. });
  9213. pickerList = [];
  9214. K(document).unbind('click,mousedown', removePicker);
  9215. dialogDiv.unbind('click,mousedown', removePicker);
  9216. }
  9217. colorBox.click(function(e) {
  9218. removePicker();
  9219. var box = K(this),
  9220. pos = box.pos();
  9221. var picker = K.colorpicker({
  9222. x : pos.x,
  9223. y : pos.y + box.height(),
  9224. z : 811214,
  9225. selectedColor : K(this).html(),
  9226. colors : self.colorTable,
  9227. noColor : self.lang('noColor'),
  9228. shadowMode : self.shadowMode,
  9229. click : function(color) {
  9230. _setColor(box, color);
  9231. removePicker();
  9232. }
  9233. });
  9234. pickerList.push(picker);
  9235. K(document).bind('click,mousedown', removePicker);
  9236. dialogDiv.bind('click,mousedown', removePicker);
  9237. });
  9238. }
  9239. // 取得下一行cell的index
  9240. function _getCellIndex(table, row, cell) {
  9241. var rowSpanCount = 0;
  9242. for (var i = 0, len = row.cells.length; i < len; i++) {
  9243. if (row.cells[i] == cell) {
  9244. break;
  9245. }
  9246. rowSpanCount += row.cells[i].rowSpan - 1;
  9247. }
  9248. return cell.cellIndex - rowSpanCount;
  9249. }
  9250. self.plugin.table = {
  9251. //insert or modify table
  9252. prop : function(isInsert) {
  9253. var html = [
  9254. '<div style="padding:20px;">',
  9255. //rows, cols
  9256. '<div class="ke-dialog-row">',
  9257. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9258. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9259. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9260. '</div>',
  9261. //width, height
  9262. '<div class="ke-dialog-row">',
  9263. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9264. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9265. '<select name="widthType">',
  9266. '<option value="%">' + lang.percent + '</option>',
  9267. '<option value="px">' + lang.px + '</option>',
  9268. '</select> &nbsp; ',
  9269. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9270. '<select name="heightType">',
  9271. '<option value="%">' + lang.percent + '</option>',
  9272. '<option value="px">' + lang.px + '</option>',
  9273. '</select>',
  9274. '</div>',
  9275. //space, padding
  9276. '<div class="ke-dialog-row">',
  9277. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9278. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9279. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9280. '</div>',
  9281. //align
  9282. '<div class="ke-dialog-row">',
  9283. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9284. '<select id="keAlign" name="align">',
  9285. '<option value="">' + lang.alignDefault + '</option>',
  9286. '<option value="left">' + lang.alignLeft + '</option>',
  9287. '<option value="center">' + lang.alignCenter + '</option>',
  9288. '<option value="right">' + lang.alignRight + '</option>',
  9289. '</select>',
  9290. '</div>',
  9291. //border
  9292. '<div class="ke-dialog-row">',
  9293. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9294. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9295. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9296. '</div>',
  9297. //background color
  9298. '<div class="ke-dialog-row">',
  9299. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9300. '<span class="ke-inline-block ke-input-color"></span>',
  9301. '</div>',
  9302. '</div>'
  9303. ].join('');
  9304. var bookmark = self.cmd.range.createBookmark();
  9305. var dialog = self.createDialog({
  9306. name : name,
  9307. width : 500,
  9308. title : self.lang(name),
  9309. body : html,
  9310. beforeRemove : function() {
  9311. colorBox.unbind();
  9312. },
  9313. yesBtn : {
  9314. name : self.lang('yes'),
  9315. click : function(e) {
  9316. var rows = rowsBox.val(),
  9317. cols = colsBox.val(),
  9318. width = widthBox.val(),
  9319. height = heightBox.val(),
  9320. widthType = widthTypeBox.val(),
  9321. heightType = heightTypeBox.val(),
  9322. padding = paddingBox.val(),
  9323. spacing = spacingBox.val(),
  9324. align = alignBox.val(),
  9325. border = borderBox.val(),
  9326. borderColor = K(colorBox[0]).html() || '',
  9327. bgColor = K(colorBox[1]).html() || '';
  9328. if (rows == 0 || !/^\d+$/.test(rows)) {
  9329. alert(self.lang('invalidRows'));
  9330. rowsBox[0].focus();
  9331. return;
  9332. }
  9333. if (cols == 0 || !/^\d+$/.test(cols)) {
  9334. alert(self.lang('invalidRows'));
  9335. colsBox[0].focus();
  9336. return;
  9337. }
  9338. if (!/^\d*$/.test(width)) {
  9339. alert(self.lang('invalidWidth'));
  9340. widthBox[0].focus();
  9341. return;
  9342. }
  9343. if (!/^\d*$/.test(height)) {
  9344. alert(self.lang('invalidHeight'));
  9345. heightBox[0].focus();
  9346. return;
  9347. }
  9348. if (!/^\d*$/.test(padding)) {
  9349. alert(self.lang('invalidPadding'));
  9350. paddingBox[0].focus();
  9351. return;
  9352. }
  9353. if (!/^\d*$/.test(spacing)) {
  9354. alert(self.lang('invalidSpacing'));
  9355. spacingBox[0].focus();
  9356. return;
  9357. }
  9358. if (!/^\d*$/.test(border)) {
  9359. alert(self.lang('invalidBorder'));
  9360. borderBox[0].focus();
  9361. return;
  9362. }
  9363. //modify table
  9364. if (table) {
  9365. if (width !== '') {
  9366. table.width(width + widthType);
  9367. } else {
  9368. table.css('width', '');
  9369. }
  9370. if (table[0].width !== undefined) {
  9371. table.removeAttr('width');
  9372. }
  9373. if (height !== '') {
  9374. table.height(height + heightType);
  9375. } else {
  9376. table.css('height', '');
  9377. }
  9378. if (table[0].height !== undefined) {
  9379. table.removeAttr('height');
  9380. }
  9381. table.css('background-color', bgColor);
  9382. if (table[0].bgColor !== undefined) {
  9383. table.removeAttr('bgColor');
  9384. }
  9385. if (padding !== '') {
  9386. table[0].cellPadding = padding;
  9387. } else {
  9388. table.removeAttr('cellPadding');
  9389. }
  9390. if (spacing !== '') {
  9391. table[0].cellSpacing = spacing;
  9392. } else {
  9393. table.removeAttr('cellSpacing');
  9394. }
  9395. if (align !== '') {
  9396. table[0].align = align;
  9397. } else {
  9398. table.removeAttr('align');
  9399. }
  9400. if (border !== '') {
  9401. table.attr('border', border);
  9402. } else {
  9403. table.removeAttr('border');
  9404. }
  9405. if (border === '' || border === '0') {
  9406. table.addClass(zeroborder);
  9407. } else {
  9408. table.removeClass(zeroborder);
  9409. }
  9410. if (borderColor !== '') {
  9411. table.attr('borderColor', borderColor);
  9412. } else {
  9413. table.removeAttr('borderColor');
  9414. }
  9415. self.hideDialog().focus();
  9416. self.cmd.range.moveToBookmark(bookmark);
  9417. self.cmd.select();
  9418. self.addBookmark();
  9419. return;
  9420. }
  9421. //insert new table
  9422. var style = '';
  9423. if (width !== '') {
  9424. style += 'width:' + width + widthType + ';';
  9425. }
  9426. if (height !== '') {
  9427. style += 'height:' + height + heightType + ';';
  9428. }
  9429. if (bgColor !== '') {
  9430. style += 'background-color:' + bgColor + ';';
  9431. }
  9432. var html = '<table';
  9433. if (style !== '') {
  9434. html += ' style="' + style + '"';
  9435. }
  9436. if (padding !== '') {
  9437. html += ' cellpadding="' + padding + '"';
  9438. }
  9439. if (spacing !== '') {
  9440. html += ' cellspacing="' + spacing + '"';
  9441. }
  9442. if (align !== '') {
  9443. html += ' align="' + align + '"';
  9444. }
  9445. if (border !== '') {
  9446. html += ' border="' + border + '"';
  9447. }
  9448. if (border === '' || border === '0') {
  9449. html += ' class="' + zeroborder + '"';
  9450. }
  9451. if (borderColor !== '') {
  9452. html += ' bordercolor="' + borderColor + '"';
  9453. }
  9454. html += '>';
  9455. for (var i = 0; i < rows; i++) {
  9456. html += '<tr>';
  9457. for (var j = 0; j < cols; j++) {
  9458. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9459. }
  9460. html += '</tr>';
  9461. }
  9462. html += '</table>';
  9463. if (!K.IE) {
  9464. html += '<br />';
  9465. }
  9466. self.insertHtml(html);
  9467. self.select().hideDialog().focus();
  9468. self.addBookmark();
  9469. }
  9470. }
  9471. }),
  9472. div = dialog.div,
  9473. rowsBox = K('[name="rows"]', div).val(3),
  9474. colsBox = K('[name="cols"]', div).val(2),
  9475. widthBox = K('[name="width"]', div).val(100),
  9476. heightBox = K('[name="height"]', div),
  9477. widthTypeBox = K('[name="widthType"]', div),
  9478. heightTypeBox = K('[name="heightType"]', div),
  9479. paddingBox = K('[name="padding"]', div).val(2),
  9480. spacingBox = K('[name="spacing"]', div).val(0),
  9481. alignBox = K('[name="align"]', div),
  9482. borderBox = K('[name="border"]', div).val(1),
  9483. colorBox = K('.ke-input-color', div);
  9484. _initColorPicker(div, colorBox.eq(0));
  9485. _initColorPicker(div, colorBox.eq(1));
  9486. _setColor(colorBox.eq(0), '#000000');
  9487. _setColor(colorBox.eq(1), '');
  9488. // foucs and select
  9489. rowsBox[0].focus();
  9490. rowsBox[0].select();
  9491. var table;
  9492. if (isInsert) {
  9493. return;
  9494. }
  9495. //get selected table node
  9496. table = self.plugin.getSelectedTable();
  9497. if (table) {
  9498. rowsBox.val(table[0].rows.length);
  9499. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9500. rowsBox.attr('disabled', true);
  9501. colsBox.attr('disabled', true);
  9502. var match,
  9503. tableWidth = table[0].style.width || table[0].width,
  9504. tableHeight = table[0].style.height || table[0].height;
  9505. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9506. widthBox.val(match[1]);
  9507. widthTypeBox.val(match[2]);
  9508. } else {
  9509. widthBox.val('');
  9510. }
  9511. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9512. heightBox.val(match[1]);
  9513. heightTypeBox.val(match[2]);
  9514. }
  9515. paddingBox.val(table[0].cellPadding || '');
  9516. spacingBox.val(table[0].cellSpacing || '');
  9517. alignBox.val(table[0].align || '');
  9518. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9519. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9520. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9521. widthBox[0].focus();
  9522. widthBox[0].select();
  9523. }
  9524. },
  9525. //modify cell
  9526. cellprop : function() {
  9527. var html = [
  9528. '<div style="padding:20px;">',
  9529. //width, height
  9530. '<div class="ke-dialog-row">',
  9531. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9532. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9533. '<select name="widthType">',
  9534. '<option value="%">' + lang.percent + '</option>',
  9535. '<option value="px">' + lang.px + '</option>',
  9536. '</select> &nbsp; ',
  9537. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9538. '<select name="heightType">',
  9539. '<option value="%">' + lang.percent + '</option>',
  9540. '<option value="px">' + lang.px + '</option>',
  9541. '</select>',
  9542. '</div>',
  9543. //align
  9544. '<div class="ke-dialog-row">',
  9545. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9546. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9547. '<option value="">' + lang.alignDefault + '</option>',
  9548. '<option value="left">' + lang.alignLeft + '</option>',
  9549. '<option value="center">' + lang.alignCenter + '</option>',
  9550. '<option value="right">' + lang.alignRight + '</option>',
  9551. '</select> ',
  9552. lang.verticalAlign + ' <select name="verticalAlign">',
  9553. '<option value="">' + lang.alignDefault + '</option>',
  9554. '<option value="top">' + lang.alignTop + '</option>',
  9555. '<option value="middle">' + lang.alignMiddle + '</option>',
  9556. '<option value="bottom">' + lang.alignBottom + '</option>',
  9557. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9558. '</select>',
  9559. '</div>',
  9560. //border
  9561. '<div class="ke-dialog-row">',
  9562. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9563. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9564. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9565. '</div>',
  9566. //background color
  9567. '<div class="ke-dialog-row">',
  9568. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9569. '<span class="ke-inline-block ke-input-color"></span>',
  9570. '</div>',
  9571. '</div>'
  9572. ].join('');
  9573. var bookmark = self.cmd.range.createBookmark();
  9574. var dialog = self.createDialog({
  9575. name : name,
  9576. width : 500,
  9577. title : self.lang('tablecell'),
  9578. body : html,
  9579. beforeRemove : function() {
  9580. colorBox.unbind();
  9581. },
  9582. yesBtn : {
  9583. name : self.lang('yes'),
  9584. click : function(e) {
  9585. var width = widthBox.val(),
  9586. height = heightBox.val(),
  9587. widthType = widthTypeBox.val(),
  9588. heightType = heightTypeBox.val(),
  9589. padding = paddingBox.val(),
  9590. spacing = spacingBox.val(),
  9591. textAlign = textAlignBox.val(),
  9592. verticalAlign = verticalAlignBox.val(),
  9593. border = borderBox.val(),
  9594. borderColor = K(colorBox[0]).html() || '',
  9595. bgColor = K(colorBox[1]).html() || '';
  9596. if (!/^\d*$/.test(width)) {
  9597. alert(self.lang('invalidWidth'));
  9598. widthBox[0].focus();
  9599. return;
  9600. }
  9601. if (!/^\d*$/.test(height)) {
  9602. alert(self.lang('invalidHeight'));
  9603. heightBox[0].focus();
  9604. return;
  9605. }
  9606. if (!/^\d*$/.test(border)) {
  9607. alert(self.lang('invalidBorder'));
  9608. borderBox[0].focus();
  9609. return;
  9610. }
  9611. cell.css({
  9612. width : width !== '' ? (width + widthType) : '',
  9613. height : height !== '' ? (height + heightType) : '',
  9614. 'background-color' : bgColor,
  9615. 'text-align' : textAlign,
  9616. 'vertical-align' : verticalAlign,
  9617. 'border-width' : border,
  9618. 'border-style' : border !== '' ? 'solid' : '',
  9619. 'border-color' : borderColor
  9620. });
  9621. self.hideDialog().focus();
  9622. self.cmd.range.moveToBookmark(bookmark);
  9623. self.cmd.select();
  9624. self.addBookmark();
  9625. }
  9626. }
  9627. }),
  9628. div = dialog.div,
  9629. widthBox = K('[name="width"]', div).val(100),
  9630. heightBox = K('[name="height"]', div),
  9631. widthTypeBox = K('[name="widthType"]', div),
  9632. heightTypeBox = K('[name="heightType"]', div),
  9633. paddingBox = K('[name="padding"]', div).val(2),
  9634. spacingBox = K('[name="spacing"]', div).val(0),
  9635. textAlignBox = K('[name="textAlign"]', div),
  9636. verticalAlignBox = K('[name="verticalAlign"]', div),
  9637. borderBox = K('[name="border"]', div).val(1),
  9638. colorBox = K('.ke-input-color', div);
  9639. _initColorPicker(div, colorBox.eq(0));
  9640. _initColorPicker(div, colorBox.eq(1));
  9641. _setColor(colorBox.eq(0), '#000000');
  9642. _setColor(colorBox.eq(1), '');
  9643. // foucs and select
  9644. widthBox[0].focus();
  9645. widthBox[0].select();
  9646. // get selected cell
  9647. var cell = self.plugin.getSelectedCell();
  9648. var match,
  9649. cellWidth = cell[0].style.width || cell[0].width || '',
  9650. cellHeight = cell[0].style.height || cell[0].height || '';
  9651. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9652. widthBox.val(match[1]);
  9653. widthTypeBox.val(match[2]);
  9654. } else {
  9655. widthBox.val('');
  9656. }
  9657. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9658. heightBox.val(match[1]);
  9659. heightTypeBox.val(match[2]);
  9660. }
  9661. textAlignBox.val(cell[0].style.textAlign || '');
  9662. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9663. var border = cell[0].style.borderWidth || '';
  9664. if (border) {
  9665. border = parseInt(border);
  9666. }
  9667. borderBox.val(border);
  9668. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9669. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9670. widthBox[0].focus();
  9671. widthBox[0].select();
  9672. },
  9673. insert : function() {
  9674. this.prop(true);
  9675. },
  9676. 'delete' : function() {
  9677. var table = self.plugin.getSelectedTable();
  9678. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9679. self.cmd.select();
  9680. table.remove();
  9681. self.addBookmark();
  9682. },
  9683. colinsert : function(offset) {
  9684. var table = self.plugin.getSelectedTable()[0],
  9685. row = self.plugin.getSelectedRow()[0],
  9686. cell = self.plugin.getSelectedCell()[0],
  9687. index = cell.cellIndex + offset;
  9688. // 取得第一行的index
  9689. index += table.rows[0].cells.length - row.cells.length;
  9690. for (var i = 0, len = table.rows.length; i < len; i++) {
  9691. var newRow = table.rows[i],
  9692. newCell = newRow.insertCell(index);
  9693. newCell.innerHTML = K.IE ? '' : '<br />';
  9694. // 调整下一行的单元格index
  9695. index = _getCellIndex(table, newRow, newCell);
  9696. }
  9697. self.cmd.range.selectNodeContents(cell).collapse(true);
  9698. self.cmd.select();
  9699. self.addBookmark();
  9700. },
  9701. colinsertleft : function() {
  9702. this.colinsert(0);
  9703. },
  9704. colinsertright : function() {
  9705. this.colinsert(1);
  9706. },
  9707. rowinsert : function(offset) {
  9708. var table = self.plugin.getSelectedTable()[0],
  9709. row = self.plugin.getSelectedRow()[0],
  9710. cell = self.plugin.getSelectedCell()[0];
  9711. var rowIndex = row.rowIndex;
  9712. if (offset === 1) {
  9713. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9714. }
  9715. var newRow = table.insertRow(rowIndex);
  9716. for (var i = 0, len = row.cells.length; i < len; i++) {
  9717. // 调整cell个数
  9718. if (row.cells[i].rowSpan > 1) {
  9719. len -= row.cells[i].rowSpan - 1;
  9720. }
  9721. var newCell = newRow.insertCell(i);
  9722. // copy colspan
  9723. if (offset === 1 && row.cells[i].colSpan > 1) {
  9724. newCell.colSpan = row.cells[i].colSpan;
  9725. }
  9726. newCell.innerHTML = K.IE ? '' : '<br />';
  9727. }
  9728. // 调整rowspan
  9729. for (var j = rowIndex; j >= 0; j--) {
  9730. var cells = table.rows[j].cells;
  9731. if (cells.length > i) {
  9732. for (var k = cell.cellIndex; k >= 0; k--) {
  9733. if (cells[k].rowSpan > 1) {
  9734. cells[k].rowSpan += 1;
  9735. }
  9736. }
  9737. break;
  9738. }
  9739. }
  9740. self.cmd.range.selectNodeContents(cell).collapse(true);
  9741. self.cmd.select();
  9742. self.addBookmark();
  9743. },
  9744. rowinsertabove : function() {
  9745. this.rowinsert(0);
  9746. },
  9747. rowinsertbelow : function() {
  9748. this.rowinsert(1);
  9749. },
  9750. rowmerge : function() {
  9751. var table = self.plugin.getSelectedTable()[0],
  9752. row = self.plugin.getSelectedRow()[0],
  9753. cell = self.plugin.getSelectedCell()[0],
  9754. rowIndex = row.rowIndex, // 当前行的index
  9755. nextRowIndex = rowIndex + cell.rowSpan, // 下一行的index
  9756. nextRow = table.rows[nextRowIndex]; // 下一行
  9757. // 最后一行不能合并
  9758. if (table.rows.length <= nextRowIndex) {
  9759. return;
  9760. }
  9761. var cellIndex = cell.cellIndex; // 下一行单元格的index
  9762. if (nextRow.cells.length <= cellIndex) {
  9763. return;
  9764. }
  9765. var nextCell = nextRow.cells[cellIndex]; // 下一行单元格
  9766. // 上下行的colspan不一致时不能合并
  9767. if (cell.colSpan !== nextCell.colSpan) {
  9768. return;
  9769. }
  9770. cell.rowSpan += nextCell.rowSpan;
  9771. nextRow.deleteCell(cellIndex);
  9772. self.cmd.range.selectNodeContents(cell).collapse(true);
  9773. self.cmd.select();
  9774. self.addBookmark();
  9775. },
  9776. colmerge : function() {
  9777. var table = self.plugin.getSelectedTable()[0],
  9778. row = self.plugin.getSelectedRow()[0],
  9779. cell = self.plugin.getSelectedCell()[0],
  9780. rowIndex = row.rowIndex, // 当前行的index
  9781. cellIndex = cell.cellIndex,
  9782. nextCellIndex = cellIndex + 1;
  9783. // 最后一列不能合并
  9784. if (row.cells.length <= nextCellIndex) {
  9785. return;
  9786. }
  9787. var nextCell = row.cells[nextCellIndex];
  9788. // 左右列的rowspan不一致时不能合并
  9789. if (cell.rowSpan !== nextCell.rowSpan) {
  9790. return;
  9791. }
  9792. cell.colSpan += nextCell.colSpan;
  9793. row.deleteCell(nextCellIndex);
  9794. self.cmd.range.selectNodeContents(cell).collapse(true);
  9795. self.cmd.select();
  9796. self.addBookmark();
  9797. },
  9798. rowsplit : function() {
  9799. var table = self.plugin.getSelectedTable()[0],
  9800. row = self.plugin.getSelectedRow()[0],
  9801. cell = self.plugin.getSelectedCell()[0],
  9802. rowIndex = row.rowIndex;
  9803. // 不是可分割单元格
  9804. if (cell.rowSpan === 1) {
  9805. return;
  9806. }
  9807. var cellIndex = _getCellIndex(table, row, cell);
  9808. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9809. var newRow = table.rows[rowIndex + i],
  9810. newCell = newRow.insertCell(cellIndex);
  9811. if (cell.colSpan > 1) {
  9812. newCell.colSpan = cell.colSpan;
  9813. }
  9814. newCell.innerHTML = K.IE ? '' : '<br />';
  9815. // 调整下一行的单元格index
  9816. cellIndex = _getCellIndex(table, newRow, newCell);
  9817. }
  9818. K(cell).removeAttr('rowSpan');
  9819. self.cmd.range.selectNodeContents(cell).collapse(true);
  9820. self.cmd.select();
  9821. self.addBookmark();
  9822. },
  9823. colsplit : function() {
  9824. var table = self.plugin.getSelectedTable()[0],
  9825. row = self.plugin.getSelectedRow()[0],
  9826. cell = self.plugin.getSelectedCell()[0],
  9827. cellIndex = cell.cellIndex;
  9828. // 不是可分割单元格
  9829. if (cell.colSpan === 1) {
  9830. return;
  9831. }
  9832. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9833. var newCell = row.insertCell(cellIndex + i);
  9834. if (cell.rowSpan > 1) {
  9835. newCell.rowSpan = cell.rowSpan;
  9836. }
  9837. newCell.innerHTML = K.IE ? '' : '<br />';
  9838. }
  9839. K(cell).removeAttr('colSpan');
  9840. self.cmd.range.selectNodeContents(cell).collapse(true);
  9841. self.cmd.select();
  9842. self.addBookmark();
  9843. },
  9844. coldelete : function() {
  9845. var table = self.plugin.getSelectedTable()[0],
  9846. row = self.plugin.getSelectedRow()[0],
  9847. cell = self.plugin.getSelectedCell()[0],
  9848. index = cell.cellIndex;
  9849. for (var i = 0, len = table.rows.length; i < len; i++) {
  9850. var newRow = table.rows[i],
  9851. newCell = newRow.cells[index];
  9852. if (newCell.colSpan > 1) {
  9853. newCell.colSpan -= 1;
  9854. if (newCell.colSpan === 1) {
  9855. K(newCell).removeAttr('colSpan');
  9856. }
  9857. } else {
  9858. newRow.deleteCell(index);
  9859. }
  9860. // 跳过不需要删除的行
  9861. if (newCell.rowSpan > 1) {
  9862. i += newCell.rowSpan - 1;
  9863. }
  9864. }
  9865. if (row.cells.length === 0) {
  9866. self.cmd.range.setStartBefore(table).collapse(true);
  9867. self.cmd.select();
  9868. K(table).remove();
  9869. } else {
  9870. self.cmd.selection(true);
  9871. }
  9872. self.addBookmark();
  9873. },
  9874. rowdelete : function() {
  9875. var table = self.plugin.getSelectedTable()[0],
  9876. row = self.plugin.getSelectedRow()[0],
  9877. cell = self.plugin.getSelectedCell()[0],
  9878. rowIndex = row.rowIndex;
  9879. // 从下到上删除
  9880. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9881. table.deleteRow(rowIndex + i);
  9882. }
  9883. if (table.rows.length === 0) {
  9884. self.cmd.range.setStartBefore(table).collapse(true);
  9885. self.cmd.select();
  9886. K(table).remove();
  9887. } else {
  9888. self.cmd.selection(true);
  9889. }
  9890. self.addBookmark();
  9891. }
  9892. };
  9893. self.clickToolbar(name, self.plugin.table.prop);
  9894. });
  9895. /*******************************************************************************
  9896. * KindEditor - WYSIWYG HTML Editor for Internet
  9897. * Copyright (C) 2006-2011 kindsoft.net
  9898. *
  9899. * @author Roddy <luolonghao@gmail.com>
  9900. * @site http://www.kindsoft.net/
  9901. * @licence http://www.kindsoft.net/license.php
  9902. *******************************************************************************/
  9903. KindEditor.plugin('template', function(K) {
  9904. var self = this, name = 'template', lang = self.lang(name + '.'),
  9905. htmlPath = self.pluginsPath + name + '/html/';
  9906. function getFilePath(fileName) {
  9907. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9908. }
  9909. self.clickToolbar(name, function() {
  9910. var lang = self.lang(name + '.'),
  9911. arr = ['<div style="padding:10px 20px;">',
  9912. '<div class="ke-header">',
  9913. // left start
  9914. '<div class="ke-left">',
  9915. lang. selectTemplate + ' <select>'];
  9916. K.each(lang.fileList, function(key, val) {
  9917. arr.push('<option value="' + key + '">' + val + '</option>');
  9918. });
  9919. html = [arr.join(''),
  9920. '</select></div>',
  9921. // right start
  9922. '<div class="ke-right">',
  9923. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9924. '</div>',
  9925. '<div class="ke-clearfix"></div>',
  9926. '</div>',
  9927. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9928. '</div>'].join('');
  9929. var dialog = self.createDialog({
  9930. name : name,
  9931. width : 500,
  9932. title : self.lang(name),
  9933. body : html,
  9934. yesBtn : {
  9935. name : self.lang('yes'),
  9936. click : function(e) {
  9937. var doc = K.iframeDoc(iframe);
  9938. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9939. }
  9940. }
  9941. });
  9942. var selectBox = K('select', dialog.div),
  9943. checkbox = K('[name="replaceFlag"]', dialog.div),
  9944. iframe = K('iframe', dialog.div);
  9945. checkbox[0].checked = true;
  9946. iframe.attr('src', getFilePath(selectBox.val()));
  9947. selectBox.change(function() {
  9948. iframe.attr('src', getFilePath(this.value));
  9949. });
  9950. });
  9951. });
  9952. /*******************************************************************************
  9953. * KindEditor - WYSIWYG HTML Editor for Internet
  9954. * Copyright (C) 2006-2011 kindsoft.net
  9955. *
  9956. * @author Roddy <luolonghao@gmail.com>
  9957. * @site http://www.kindsoft.net/
  9958. * @licence http://www.kindsoft.net/license.php
  9959. *******************************************************************************/
  9960. KindEditor.plugin('wordpaste', function(K) {
  9961. var self = this, name = 'wordpaste';
  9962. self.clickToolbar(name, function() {
  9963. var lang = self.lang(name + '.'),
  9964. html = '<div style="padding:10px 20px;">' +
  9965. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9966. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9967. '</div>',
  9968. dialog = self.createDialog({
  9969. name : name,
  9970. width : 450,
  9971. title : self.lang(name),
  9972. body : html,
  9973. yesBtn : {
  9974. name : self.lang('yes'),
  9975. click : function(e) {
  9976. var str = doc.body.innerHTML;
  9977. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9978. self.insertHtml(str).hideDialog().focus();
  9979. }
  9980. }
  9981. }),
  9982. div = dialog.div,
  9983. iframe = K('iframe', div),
  9984. doc = K.iframeDoc(iframe);
  9985. if (!K.IE) {
  9986. doc.designMode = 'on';
  9987. }
  9988. doc.open();
  9989. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9990. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9991. if (!K.IE) {
  9992. doc.write('<br />');
  9993. }
  9994. doc.write('</body></html>');
  9995. doc.close();
  9996. if (K.IE) {
  9997. doc.body.contentEditable = 'true';
  9998. }
  9999. iframe[0].contentWindow.focus();
  10000. });
  10001. });
  10002. /*******************************************************************************
  10003. uploadfile
  10004. *******************************************************************************/
  10005. KindEditor.plugin('uploadfile', function(K) {
  10006. var self = this, name = 'uploadfile',
  10007. allowFileUpload = K.undef(self.allowFileUpload, true),
  10008. allowFileManager = K.undef(self.allowFileManager, false),
  10009. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  10010. uploadJson = self.uploadJson,
  10011. extraParams = K.undef(self.extraFileUploadParams, {}),
  10012. filePostName = K.undef(self.filePostName, 'file');
  10013. self.plugin.fileDialog = function(options) {
  10014. var fileUrl = '';
  10015. var html = [
  10016. '<div style="padding:20px;">',
  10017. '<div class="ke-dialog-row">',
  10018. '<label for="keUrl" style="width:60px;">文件地址</label>',
  10019. '<input readonly="readonly" type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  10020. '<input type="button" class="ke-upload-button" value="选择文件" /> &nbsp;',
  10021. '</div>',
  10022. '</form>',
  10023. '</div>'
  10024. ].join('');
  10025. var dialog = self.createDialog({
  10026. name : name,
  10027. width : 450,
  10028. title : '上传新的文件',
  10029. body : html
  10030. }),
  10031. div = dialog.div;
  10032. var urlBox = K('[name="url"]', div);
  10033. var uploadbutton = K.uploadbutton({
  10034. button : K('.ke-upload-button', div)[0],
  10035. fieldName : filePostName,
  10036. url : uploadJson,
  10037. extraParams : extraParams,
  10038. afterUpload : function(data) {
  10039. //if(data.code == 0){
  10040. if (self.afterUpload) {
  10041. self.afterUpload(data);
  10042. }
  10043. // }else {
  10044. // GCMSAPP.C.publisher.publish({type:'error',message:data['message']},'noteBar::add');
  10045. // dialog.hideLoading();
  10046. // }
  10047. },
  10048. afterError : function(html) {
  10049. dialog.hideLoading();
  10050. self.errorDialog(html);
  10051. }
  10052. });
  10053. uploadbutton.fileBox.change(function(e) {
  10054. dialog.showLoading('正在上传');
  10055. uploadbutton.submit();
  10056. });
  10057. urlBox.val(fileUrl);
  10058. urlBox[0].focus();
  10059. urlBox[0].select();
  10060. };
  10061. });
  10062. /*******************************************************************************
  10063. uploadvideo
  10064. *******************************************************************************/
  10065. KindEditor.plugin('uploadvideo', function(K) {
  10066. var self = this, name = 'uploadvideo',
  10067. allowFileUpload = K.undef(self.allowFileUpload, true),
  10068. allowFileManager = K.undef(self.allowFileManager, false),
  10069. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  10070. uploadJson = self.uploadJson,
  10071. extraParams = K.undef(self.extraFileUploadParams, {}),
  10072. filePostName = K.undef(self.filePostName, 'file');
  10073. self.plugin.videoDialog = function(options) {
  10074. var fileUrl = '';
  10075. var html = [
  10076. '<div style="padding:20px;">',
  10077. '<div class="ke-dialog-row">',
  10078. '<label for="keUrl" style="width:60px;">视频地址</label>',
  10079. '<input readonly="readonly" type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  10080. '<input type="button" class="ke-upload-button" value="选择视频" /> &nbsp;',
  10081. '</div>',
  10082. '</form>',
  10083. '</div>'
  10084. ].join('');
  10085. var dialog = self.createDialog({
  10086. name : name,
  10087. width : 450,
  10088. title : '上传新的视频',
  10089. body : html
  10090. }),
  10091. div = dialog.div;
  10092. var urlBox = K('[name="url"]', div);
  10093. var uploadbutton = K.uploadbutton({
  10094. button : K('.ke-upload-button', div)[0],
  10095. fieldName : filePostName,
  10096. url : uploadJson,
  10097. extraParams : extraParams,
  10098. afterUpload : function(data) {
  10099. //if(data.code == 0){
  10100. if (self.afterUpload) {
  10101. self.afterUpload(data);
  10102. }
  10103. // }else {
  10104. // GCMSAPP.C.publisher.publish({type:'error',message:data['message']},'noteBar::add');
  10105. // dialog.hideLoading();
  10106. // }
  10107. },
  10108. afterError : function(html) {
  10109. dialog.hideLoading();
  10110. self.errorDialog(html);
  10111. }
  10112. });
  10113. uploadbutton.fileBox.change(function(e) {
  10114. dialog.showLoading('正在上传');
  10115. uploadbutton.submit();
  10116. });
  10117. urlBox.val(fileUrl);
  10118. urlBox[0].focus();
  10119. urlBox[0].select();
  10120. };
  10121. });
  10122. /*******************************************************************************
  10123. uploadpicture
  10124. *******************************************************************************/
  10125. KindEditor.plugin('uploadpicture', function(K) {
  10126. var self = this, name = 'uploadpicture',
  10127. allowFileUpload = K.undef(self.allowFileUpload, true),
  10128. allowFileManager = K.undef(self.allowFileManager, false),
  10129. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  10130. uploadJson = self.uploadJson,
  10131. extraParams = K.undef(self.extraFileUploadParams, {}),
  10132. filePostName = K.undef(self.filePostName, 'file');
  10133. self.plugin.pictureDialog = function(options) {
  10134. var fileUrl = '';
  10135. var html = [
  10136. '<div style="padding:20px;">',
  10137. '<div class="ke-dialog-row">',
  10138. '<label for="keUrl" style="width:60px;">图片地址</label>',
  10139. '<input readonly="readonly" type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  10140. '<input type="button" class="ke-upload-button" value="选择图片" /> &nbsp;',
  10141. '</div>',
  10142. '</form>',
  10143. '</div>'
  10144. ].join('');
  10145. var dialog = self.createDialog({
  10146. name : name,
  10147. width : 450,
  10148. title : '上传新的图片',
  10149. body : html
  10150. }),
  10151. div = dialog.div;
  10152. var urlBox = K('[name="url"]', div);
  10153. var uploadbutton = K.uploadbutton({
  10154. button : K('.ke-upload-button', div)[0],
  10155. fieldName : filePostName,
  10156. url : uploadJson,
  10157. extraParams : extraParams,
  10158. afterUpload : function(data) {
  10159. if (self.afterUpload) {
  10160. self.afterUpload(data);
  10161. }
  10162. },
  10163. afterError : function(html) {
  10164. dialog.hideLoading();
  10165. self.errorDialog(html);
  10166. }
  10167. });
  10168. uploadbutton.fileBox.change(function(e) {
  10169. dialog.showLoading('正在上传');
  10170. uploadbutton.submit();
  10171. });
  10172. urlBox.val(fileUrl);
  10173. urlBox[0].focus();
  10174. urlBox[0].select();
  10175. };
  10176. });
  10177. /*******************************************************************************
  10178. uploadaudio
  10179. *******************************************************************************/
  10180. KindEditor.plugin('uploadaudio', function(K) {
  10181. var self = this, name = 'uploadaudio',
  10182. allowFileUpload = K.undef(self.allowFileUpload, true),
  10183. allowFileManager = K.undef(self.allowFileManager, false),
  10184. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  10185. uploadJson = self.uploadJson,
  10186. extraParams = K.undef(self.extraFileUploadParams, {}),
  10187. filePostName = K.undef(self.filePostName, 'file');
  10188. self.plugin.audioDialog = function(options) {
  10189. var fileUrl = '';
  10190. var html = [
  10191. '<div style="padding:20px;">',
  10192. '<div class="ke-dialog-row">',
  10193. '<label for="keUrl" style="width:60px;">音频地址</label>',
  10194. '<input readonly="readonly" type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  10195. '<input type="button" class="ke-upload-button" value="选择音频" /> &nbsp;',
  10196. '</div>',
  10197. '</form>',
  10198. '</div>'
  10199. ].join('');
  10200. var dialog = self.createDialog({
  10201. name : name,
  10202. width : 450,
  10203. title : '上传新的音频',
  10204. body : html
  10205. }),
  10206. div = dialog.div;
  10207. var urlBox = K('[name="url"]', div);
  10208. var uploadbutton = K.uploadbutton({
  10209. button : K('.ke-upload-button', div)[0],
  10210. fieldName : filePostName,
  10211. url : uploadJson,
  10212. extraParams : extraParams,
  10213. afterUpload : function(data) {
  10214. if (self.afterUpload) {
  10215. self.afterUpload(data);
  10216. }
  10217. },
  10218. afterError : function(html) {
  10219. dialog.hideLoading();
  10220. self.errorDialog(html);
  10221. }
  10222. });
  10223. uploadbutton.fileBox.change(function(e) {
  10224. dialog.showLoading('正在上传');
  10225. uploadbutton.submit();
  10226. });
  10227. urlBox.val(fileUrl);
  10228. urlBox[0].focus();
  10229. urlBox[0].select();
  10230. };
  10231. });