kindeditor-all-min.js 307 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2017 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.12 (2017-04-12)
  9. *******************************************************************************/
  10. (function (window, undefined) {
  11. if (window.KindEditor) {
  12. return;
  13. }
  14. if (!window.console) {
  15. window.console = {};
  16. }
  17. if (!console.log) {
  18. console.log = function () {};
  19. }
  20. var _VERSION = '4.1.12 (2017-04-12)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  24. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  25. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  26. _OPERA = _ua.indexOf('opera') > -1,
  27. _MOBILE = _ua.indexOf('mobile') > -1,
  28. _IOS = /ipad|iphone|ipod/.test(_ua),
  29. _QUIRKS = document.compatMode != 'CSS1Compat',
  30. _IERANGE = !window.getSelection,
  31. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  32. _V = _matches ? _matches[1] : '0',
  33. _TIME = new Date().getTime();
  34. function _isArray(val) {
  35. if (!val) {
  36. return false;
  37. }
  38. return Object.prototype.toString.call(val) === '[object Array]';
  39. }
  40. function _isFunction(val) {
  41. if (!val) {
  42. return false;
  43. }
  44. return Object.prototype.toString.call(val) === '[object Function]';
  45. }
  46. function _inArray(val, arr) {
  47. for (var i = 0, len = arr.length; i < len; i++) {
  48. if (val === arr[i]) {
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. function _each(obj, fn) {
  55. if (_isArray(obj)) {
  56. for (var i = 0, len = obj.length; i < len; i++) {
  57. if (fn.call(obj[i], i, obj[i]) === false) {
  58. break;
  59. }
  60. }
  61. } else {
  62. for (var key in obj) {
  63. if (obj.hasOwnProperty(key)) {
  64. if (fn.call(obj[key], key, obj[key]) === false) {
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. function _trim(str) {
  72. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  73. }
  74. function _inString(val, str, delimiter) {
  75. delimiter = delimiter === undefined ? ',' : delimiter;
  76. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  77. }
  78. function _addUnit(val, unit) {
  79. unit = unit || 'px';
  80. return val && /^-?\d+(?:\.\d+)?$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function(key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function(key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () {};
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function(key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG : false,
  180. VERSION : _VERSION,
  181. IE : _IE,
  182. GECKO : _GECKO,
  183. WEBKIT : _WEBKIT,
  184. OPERA : _OPERA,
  185. V : _V,
  186. TIME : _TIME,
  187. each : _each,
  188. isArray : _isArray,
  189. isFunction : _isFunction,
  190. inArray : _inArray,
  191. inString : _inString,
  192. trim : _trim,
  193. addUnit : _addUnit,
  194. removeUnit : _removeUnit,
  195. escape : _escape,
  196. unescape : _unescape,
  197. toCamel : _toCamel,
  198. toHex : _toHex,
  199. toMap : _toMap,
  200. toArray : _toArray,
  201. undef : _undef,
  202. invalidUrl : _invalidUrl,
  203. addParam : _addParam,
  204. extend : _extend,
  205. json : _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. index : 0,
  230. designMode : true,
  231. fullscreenMode : false,
  232. filterMode : true,
  233. wellFormatMode : true,
  234. shadowMode : true,
  235. loadStyleMode : true,
  236. basePath : K.basePath,
  237. themesPath : K.basePath + 'themes/',
  238. langPath : K.basePath + 'lang/',
  239. pluginsPath : K.basePath + 'plugins/',
  240. themeType : 'default',
  241. langType : 'zh-CN',
  242. urlType : '',
  243. newlineTag : 'p',
  244. resizeType : 2,
  245. syncType : 'form',
  246. pasteType : 2,
  247. dialogAlignType : 'page',
  248. useContextmenu : true,
  249. fullscreenShortcut : false,
  250. bodyClass : 'ke-content',
  251. indentChar : '\t',
  252. cssPath : '',
  253. cssData : '',
  254. minWidth : 650,
  255. minHeight : 100,
  256. minChangeSize : 50,
  257. zIndex : 19850426,
  258. items : [
  259. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  260. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  261. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  262. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  263. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  264. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  265. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  266. 'anchor', 'link', 'unlink', '|', 'about'
  267. ],
  268. noDisableItems : ['source', 'fullscreen'],
  269. colorTable : [
  270. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  271. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  272. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  273. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  274. ],
  275. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  276. fontHeightTable : ['0px', '0.25px', '0.5px', '1px', '1.5px', '2px', '2.5px', '3px', '4px', '5px'],
  277. htmlTags : {
  278. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  279. span : [
  280. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  281. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  282. ],
  283. div : [
  284. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  285. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  286. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  287. ],
  288. table: [
  289. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  290. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  291. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  292. '.width', '.height', '.border-collapse'
  293. ],
  294. 'td,th': [
  295. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  296. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  297. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  298. ],
  299. a : ['id', 'class', 'href', 'target', 'name'],
  300. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  301. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  302. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  303. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  304. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  305. ],
  306. pre : ['id', 'class'],
  307. hr : ['id', 'class', '.page-break-after'],
  308. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  309. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  310. },
  311. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  312. };
  313. var _useCapture = false;
  314. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  315. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  316. var _CHANGE_KEY_MAP = {};
  317. _each(_INPUT_KEY_MAP, function(key, val) {
  318. _CHANGE_KEY_MAP[key] = val;
  319. });
  320. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  321. _CHANGE_KEY_MAP[key] = val;
  322. });
  323. function _bindEvent(el, type, fn) {
  324. if (el.addEventListener){
  325. el.addEventListener(type, fn, _useCapture);
  326. } else if (el.attachEvent){
  327. el.attachEvent('on' + type, fn);
  328. }
  329. }
  330. function _unbindEvent(el, type, fn) {
  331. if (el.removeEventListener){
  332. el.removeEventListener(type, fn, _useCapture);
  333. } else if (el.detachEvent){
  334. el.detachEvent('on' + type, fn);
  335. }
  336. }
  337. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  338. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  339. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  340. function KEvent(el, event) {
  341. this.init(el, event);
  342. }
  343. _extend(KEvent, {
  344. init : function(el, event) {
  345. var self = this, doc = el.ownerDocument || el.document || el;
  346. self.event = event;
  347. _each(_EVENT_PROPS, function(key, val) {
  348. self[val] = event[val];
  349. });
  350. if (!self.target) {
  351. self.target = self.srcElement || doc;
  352. }
  353. if (self.target.nodeType === 3) {
  354. self.target = self.target.parentNode;
  355. }
  356. if (!self.relatedTarget && self.fromElement) {
  357. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  358. }
  359. if (self.pageX == null && self.clientX != null) {
  360. var d = doc.documentElement, body = doc.body;
  361. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  362. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  363. }
  364. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  365. self.which = self.charCode || self.keyCode;
  366. }
  367. if (!self.metaKey && self.ctrlKey) {
  368. self.metaKey = self.ctrlKey;
  369. }
  370. if (!self.which && self.button !== undefined) {
  371. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  372. }
  373. switch (self.which) {
  374. case 186 :
  375. self.which = 59;
  376. break;
  377. case 187 :
  378. case 107 :
  379. case 43 :
  380. self.which = 61;
  381. break;
  382. case 189 :
  383. case 45 :
  384. self.which = 109;
  385. break;
  386. case 42 :
  387. self.which = 106;
  388. break;
  389. case 47 :
  390. self.which = 111;
  391. break;
  392. case 78 :
  393. self.which = 110;
  394. break;
  395. }
  396. if (self.which >= 96 && self.which <= 105) {
  397. self.which -= 48;
  398. }
  399. },
  400. preventDefault : function() {
  401. var ev = this.event;
  402. if (ev.preventDefault) {
  403. ev.preventDefault();
  404. } else {
  405. ev.returnValue = false;
  406. }
  407. },
  408. stopPropagation : function() {
  409. var ev = this.event;
  410. if (ev.stopPropagation) {
  411. ev.stopPropagation();
  412. } else {
  413. ev.cancelBubble = true;
  414. }
  415. },
  416. stop : function() {
  417. this.preventDefault();
  418. this.stopPropagation();
  419. }
  420. });
  421. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  422. function _getId(el) {
  423. return el[_eventExpendo] || null;
  424. }
  425. function _setId(el) {
  426. el[_eventExpendo] = ++_eventId;
  427. return _eventId;
  428. }
  429. function _removeId(el) {
  430. try {
  431. delete el[_eventExpendo];
  432. } catch(e) {
  433. if (el.removeAttribute) {
  434. el.removeAttribute(_eventExpendo);
  435. }
  436. }
  437. }
  438. function _bind(el, type, fn) {
  439. if (type.indexOf(',') >= 0) {
  440. _each(type.split(','), function() {
  441. _bind(el, this, fn);
  442. });
  443. return;
  444. }
  445. var id = _getId(el);
  446. if (!id) {
  447. id = _setId(el);
  448. }
  449. if (_eventData[id] === undefined) {
  450. _eventData[id] = {};
  451. }
  452. var events = _eventData[id][type];
  453. if (events && events.length > 0) {
  454. _unbindEvent(el, type, events[0]);
  455. } else {
  456. _eventData[id][type] = [];
  457. _eventData[id].el = el;
  458. }
  459. events = _eventData[id][type];
  460. if (events.length === 0) {
  461. events[0] = function(e) {
  462. var kevent = e ? new KEvent(el, e) : undefined;
  463. _each(events, function(i, event) {
  464. if (i > 0 && event) {
  465. event.call(el, kevent);
  466. }
  467. });
  468. };
  469. }
  470. if (_inArray(fn, events) < 0) {
  471. events.push(fn);
  472. }
  473. _bindEvent(el, type, events[0]);
  474. }
  475. function _unbind(el, type, fn) {
  476. if (type && type.indexOf(',') >= 0) {
  477. _each(type.split(','), function() {
  478. _unbind(el, this, fn);
  479. });
  480. return;
  481. }
  482. var id = _getId(el);
  483. if (!id) {
  484. return;
  485. }
  486. if (type === undefined) {
  487. if (id in _eventData) {
  488. _each(_eventData[id], function(key, events) {
  489. if (key != 'el' && events.length > 0) {
  490. _unbindEvent(el, key, events[0]);
  491. }
  492. });
  493. delete _eventData[id];
  494. _removeId(el);
  495. }
  496. return;
  497. }
  498. if (!_eventData[id]) {
  499. return;
  500. }
  501. var events = _eventData[id][type];
  502. if (events && events.length > 0) {
  503. if (fn === undefined) {
  504. _unbindEvent(el, type, events[0]);
  505. delete _eventData[id][type];
  506. } else {
  507. _each(events, function(i, event) {
  508. if (i > 0 && event === fn) {
  509. events.splice(i, 1);
  510. }
  511. });
  512. if (events.length == 1) {
  513. _unbindEvent(el, type, events[0]);
  514. delete _eventData[id][type];
  515. }
  516. }
  517. var count = 0;
  518. _each(_eventData[id], function() {
  519. count++;
  520. });
  521. if (count < 2) {
  522. delete _eventData[id];
  523. _removeId(el);
  524. }
  525. }
  526. }
  527. function _fire(el, type) {
  528. if (type.indexOf(',') >= 0) {
  529. _each(type.split(','), function() {
  530. _fire(el, this);
  531. });
  532. return;
  533. }
  534. var id = _getId(el);
  535. if (!id) {
  536. return;
  537. }
  538. var events = _eventData[id][type];
  539. if (_eventData[id] && events && events.length > 0) {
  540. events[0]();
  541. }
  542. }
  543. function _ctrl(el, key, fn) {
  544. var self = this;
  545. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  546. _bind(el, 'keydown', function(e) {
  547. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  548. fn.call(el);
  549. e.stop();
  550. }
  551. });
  552. }
  553. var _readyFinished = false;
  554. function _ready(fn) {
  555. if (_readyFinished) {
  556. fn(KindEditor);
  557. return;
  558. }
  559. var loaded = false;
  560. function readyFunc() {
  561. if (!loaded) {
  562. loaded = true;
  563. fn(KindEditor);
  564. _readyFinished = true;
  565. }
  566. }
  567. function ieReadyFunc() {
  568. if (!loaded) {
  569. try {
  570. document.documentElement.doScroll('left');
  571. } catch(e) {
  572. setTimeout(ieReadyFunc, 100);
  573. return;
  574. }
  575. readyFunc();
  576. }
  577. }
  578. function ieReadyStateFunc() {
  579. if (document.readyState === 'complete') {
  580. readyFunc();
  581. }
  582. }
  583. if (document.addEventListener) {
  584. _bind(document, 'DOMContentLoaded', readyFunc);
  585. } else if (document.attachEvent) {
  586. _bind(document, 'readystatechange', ieReadyStateFunc);
  587. var toplevel = false;
  588. try {
  589. toplevel = window.frameElement == null;
  590. } catch(e) {}
  591. if (document.documentElement.doScroll && toplevel) {
  592. ieReadyFunc();
  593. }
  594. }
  595. _bind(window, 'load', readyFunc);
  596. }
  597. if (window.attachEvent) {
  598. window.attachEvent('onunload', function() {
  599. _each(_eventData, function(key, events) {
  600. if (events.el) {
  601. _unbind(events.el);
  602. }
  603. });
  604. });
  605. }
  606. K.ctrl = _ctrl;
  607. K.ready = _ready;
  608. function _getCssList(css) {
  609. css = css.replace(/&quot;/g, '"');
  610. var list = {},
  611. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  612. match;
  613. while ((match = reg.exec(css))) {
  614. var key = _trim(match[1].toLowerCase()),
  615. val = _trim(_toHex(match[2]));
  616. list[key] = val;
  617. }
  618. return list;
  619. }
  620. function _getAttrList(tag) {
  621. var list = {},
  622. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  623. match;
  624. while ((match = reg.exec(tag))) {
  625. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  626. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  627. list[key] = val;
  628. }
  629. return list;
  630. }
  631. function _addClassToTag(tag, className) {
  632. if (/\s+class\s*=/.test(tag)) {
  633. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  634. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  635. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  636. } else {
  637. return $0;
  638. }
  639. });
  640. } else {
  641. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  642. }
  643. return tag;
  644. }
  645. function _formatCss(css) {
  646. var str = '';
  647. _each(_getCssList(css), function(key, val) {
  648. str += key + ':' + val + ';';
  649. });
  650. return str;
  651. }
  652. function _formatUrl(url, mode, host, pathname) {
  653. return url;
  654. mode = _undef(mode, '').toLowerCase();
  655. if (url.substr(0, 5) != 'data:') {
  656. url = url.replace(/([^:])\/\//g, '$1/');
  657. }
  658. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  659. return url;
  660. }
  661. host = host || location.protocol + '//' + location.host;
  662. if (pathname === undefined) {
  663. var m = location.pathname.match(/^(\/.*)\//);
  664. pathname = m ? m[1] : '';
  665. }
  666. var match;
  667. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  668. if (match[1] !== host) {
  669. return url;
  670. }
  671. } else if (/^\w+:/.test(url)) {
  672. return url;
  673. }
  674. function getRealPath(path) {
  675. var parts = path.split('/'), paths = [];
  676. for (var i = 0, len = parts.length; i < len; i++) {
  677. var part = parts[i];
  678. if (part == '..') {
  679. if (paths.length > 0) {
  680. paths.pop();
  681. }
  682. } else if (part !== '' && part != '.') {
  683. paths.push(part);
  684. }
  685. }
  686. return '/' + paths.join('/');
  687. }
  688. if (/^\//.test(url)) {
  689. url = host + getRealPath(url.substr(1));
  690. } else if (!/^\w+:\/\//.test(url)) {
  691. url = host + getRealPath(pathname + '/' + url);
  692. }
  693. function getRelativePath(path, depth) {
  694. if (url.substr(0, path.length) === path) {
  695. var arr = [];
  696. for (var i = 0; i < depth; i++) {
  697. arr.push('..');
  698. }
  699. var prefix = '.';
  700. if (arr.length > 0) {
  701. prefix += '/' + arr.join('/');
  702. }
  703. if (pathname == '/') {
  704. prefix += '/';
  705. }
  706. return prefix + url.substr(path.length);
  707. } else {
  708. if ((match = /^(.*)\//.exec(path))) {
  709. return getRelativePath(match[1], ++depth);
  710. }
  711. }
  712. }
  713. if (mode === 'relative') {
  714. url = getRelativePath(host + pathname, 0).substr(2);
  715. } else if (mode === 'absolute') {
  716. if (url.substr(0, host.length) === host) {
  717. url = url.substr(host.length);
  718. }
  719. }
  720. return url;
  721. }
  722. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  723. if (html == null) {
  724. html = '';
  725. }
  726. urlType = urlType || '';
  727. wellFormatted = _undef(wellFormatted, false);
  728. indentChar = _undef(indentChar, '\t');
  729. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  730. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  731. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  732. });
  733. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  734. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  735. html = html.replace(/\u200B/g, '');
  736. html = html.replace(/\u00A9/g, '&copy;');
  737. html = html.replace(/\u00AE/g, '&reg;');
  738. html = html.replace(/\u2003/g, '&emsp;');
  739. html = html.replace(/\u3000/g, '&emsp;');
  740. html = html.replace(/&quot;/g, '');
  741. html = html.replace(/, " helvetica=""(.*?)"="/g, '');
  742. html = html.replace(/<[^>]+/g, function($0) {
  743. return $0.replace(/\s+/g, ' ');
  744. });
  745. var htmlTagMap = {};
  746. if (htmlTags) {
  747. _each(htmlTags, function(key, val) {
  748. var arr = key.split(',');
  749. for (var i = 0, len = arr.length; i < len; i++) {
  750. htmlTagMap[arr[i]] = _toMap(val);
  751. }
  752. });
  753. if (!htmlTagMap.script) {
  754. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  755. }
  756. if (!htmlTagMap.style) {
  757. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  758. }
  759. }
  760. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  761. var tagStack = [];
  762. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  763. var full = $0,
  764. startNewline = $1 || '',
  765. startSlash = $2 || '',
  766. tagName = $3.toLowerCase(),
  767. attr = $4 || '',
  768. endSlash = $5 ? ' ' + $5 : '',
  769. endNewline = $6 || '';
  770. if (htmlTags && !htmlTagMap[tagName]) {
  771. return '';
  772. }
  773. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  774. endSlash = ' /';
  775. }
  776. if (_INLINE_TAG_MAP[tagName]) {
  777. if (startNewline) {
  778. startNewline = ' ';
  779. }
  780. if (endNewline) {
  781. endNewline = ' ';
  782. }
  783. }
  784. if (_PRE_TAG_MAP[tagName]) {
  785. if (startSlash) {
  786. endNewline = '\n';
  787. } else {
  788. startNewline = '\n';
  789. }
  790. }
  791. if (wellFormatted && tagName == 'br') {
  792. endNewline = '\n';
  793. }
  794. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  795. if (wellFormatted) {
  796. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  797. tagStack.pop();
  798. } else {
  799. tagStack.push(tagName);
  800. }
  801. startNewline = '\n';
  802. endNewline = '\n';
  803. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  804. startNewline += indentChar;
  805. if (!startSlash) {
  806. endNewline += indentChar;
  807. }
  808. }
  809. if (endSlash) {
  810. tagStack.pop();
  811. } else if (!startSlash) {
  812. endNewline += indentChar;
  813. }
  814. } else {
  815. startNewline = endNewline = '';
  816. }
  817. }
  818. if (attr !== '') {
  819. var attrMap = _getAttrList(full);
  820. if (tagName === 'font') {
  821. var fontStyleMap = {}, fontStyle = '';
  822. _each(attrMap, function(key, val) {
  823. if (key === 'color') {
  824. fontStyleMap.color = val;
  825. delete attrMap[key];
  826. }
  827. if (key === 'size') {
  828. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  829. delete attrMap[key];
  830. }
  831. if (key === 'face') {
  832. fontStyleMap['font-family'] = val;
  833. delete attrMap[key];
  834. }
  835. if (key === 'style') {
  836. fontStyle = val;
  837. }
  838. });
  839. if (fontStyle && !/;$/.test(fontStyle)) {
  840. fontStyle += ';';
  841. }
  842. _each(fontStyleMap, function(key, val) {
  843. if (val === '') {
  844. return;
  845. }
  846. if (/\s/.test(val)) {
  847. val = "'" + val + "'";
  848. }
  849. fontStyle += key + ':' + val + ';';
  850. });
  851. attrMap.style = fontStyle;
  852. }
  853. _each(attrMap, function(key, val) {
  854. if (_FILL_ATTR_MAP[key]) {
  855. attrMap[key] = key;
  856. }
  857. if (_inArray(key, ['src', 'href']) >= 0) {
  858. attrMap[key] = _formatUrl(val, urlType);
  859. }
  860. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  861. tagName === 'body' && key === 'contenteditable' ||
  862. /^kindeditor_\d+$/.test(key)) {
  863. delete attrMap[key];
  864. }
  865. if (key === 'style' && val !== '') {
  866. var styleMap = _getCssList(val);
  867. _each(styleMap, function(k, v) {
  868. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  869. delete styleMap[k];
  870. }
  871. });
  872. var style = '';
  873. _each(styleMap, function(k, v) {
  874. style += k + ':' + v + ';';
  875. });
  876. attrMap.style = style;
  877. }
  878. });
  879. attr = '';
  880. _each(attrMap, function(key, val) {
  881. if (key === 'style' && val === '') {
  882. return;
  883. }
  884. val = val.replace(/"/g, '&quot;');
  885. attr += ' ' + key + '="' + val + '"';
  886. });
  887. }
  888. if (tagName === 'font') {
  889. tagName = 'span';
  890. }
  891. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  892. });
  893. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  894. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  895. });
  896. html = html.replace(/\n\s*\n/g, '\n');
  897. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  898. return _trim(html);
  899. }
  900. function _clearMsWord(html, htmlTags) {
  901. html = html.replace(/<meta[\s\S]*?>/ig, '')
  902. .replace(/<![\s\S]*?>/ig, '')
  903. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  904. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  905. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  906. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  907. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  908. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  909. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  910. });
  911. return _formatHtml(html, htmlTags);
  912. }
  913. function _mediaType(src) {
  914. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  915. return 'audio/x-pn-realaudio-plugin';
  916. }
  917. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  918. return 'application/x-shockwave-flash';
  919. }
  920. return 'video/x-ms-asf-plugin';
  921. }
  922. function _mediaClass(type) {
  923. if (/realaudio/i.test(type)) {
  924. return 'ke-rm';
  925. }
  926. if (/flash/i.test(type)) {
  927. return 'ke-flash';
  928. }
  929. return 'ke-media';
  930. }
  931. function _mediaAttrs(srcTag) {
  932. return _getAttrList(unescape(srcTag));
  933. }
  934. function _mediaEmbed(attrs) {
  935. var html = '<embed ';
  936. _each(attrs, function(key, val) {
  937. html += key + '="' + val + '" ';
  938. });
  939. html += '/>';
  940. return html;
  941. }
  942. function _mediaImg(blankPath, attrs) {
  943. var width = attrs.width,
  944. height = attrs.height,
  945. type = attrs.type || _mediaType(attrs.src),
  946. srcTag = _mediaEmbed(attrs),
  947. style = '';
  948. if (/\D/.test(width)) {
  949. style += 'width:' + width + ';';
  950. } else if (width > 0) {
  951. style += 'width:' + width + 'px;';
  952. }
  953. if (/\D/.test(height)) {
  954. style += 'height:' + height + ';';
  955. } else if (height > 0) {
  956. style += 'height:' + height + 'px;';
  957. }
  958. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  959. if (style !== '') {
  960. html += 'style="' + style + '" ';
  961. }
  962. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  963. return html;
  964. }
  965. function _tmpl(str, data) {
  966. var fn = new Function("obj",
  967. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  968. "with(obj){p.push('" +
  969. str.replace(/[\r\t\n]/g, " ")
  970. .split("<%").join("\t")
  971. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  972. .replace(/\t=(.*?)%>/g, "',$1,'")
  973. .split("\t").join("');")
  974. .split("%>").join("p.push('")
  975. .split("\r").join("\\'") + "');}return p.join('');");
  976. return data ? fn(data) : fn;
  977. }
  978. K.formatUrl = _formatUrl;
  979. K.formatHtml = _formatHtml;
  980. K.getCssList = _getCssList;
  981. K.getAttrList = _getAttrList;
  982. K.mediaType = _mediaType;
  983. K.mediaAttrs = _mediaAttrs;
  984. K.mediaEmbed = _mediaEmbed;
  985. K.mediaImg = _mediaImg;
  986. K.clearMsWord = _clearMsWord;
  987. K.tmpl = _tmpl;
  988. function _contains(nodeA, nodeB) {
  989. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  990. return true;
  991. }
  992. while ((nodeB = nodeB.parentNode)) {
  993. if (nodeB == nodeA) {
  994. return true;
  995. }
  996. }
  997. return false;
  998. }
  999. var _getSetAttrDiv = document.createElement('div');
  1000. _getSetAttrDiv.setAttribute('className', 't');
  1001. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1002. function _getAttr(el, key) {
  1003. key = key.toLowerCase();
  1004. var val = null;
  1005. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1006. var div = el.ownerDocument.createElement('div');
  1007. div.appendChild(el.cloneNode(false));
  1008. var list = _getAttrList(_unescape(div.innerHTML));
  1009. if (key in list) {
  1010. val = list[key];
  1011. }
  1012. } else {
  1013. try {
  1014. val = el.getAttribute(key, 2);
  1015. } catch(e) {
  1016. val = el.getAttribute(key, 1);
  1017. }
  1018. }
  1019. if (key === 'style' && val !== null) {
  1020. val = _formatCss(val);
  1021. }
  1022. return val;
  1023. }
  1024. function _queryAll(expr, root) {
  1025. var exprList = expr.split(',');
  1026. if (exprList.length > 1) {
  1027. var mergedResults = [];
  1028. _each(exprList, function() {
  1029. _each(_queryAll(this, root), function() {
  1030. if (_inArray(this, mergedResults) < 0) {
  1031. mergedResults.push(this);
  1032. }
  1033. });
  1034. });
  1035. return mergedResults;
  1036. }
  1037. root = root || document;
  1038. function escape(str) {
  1039. if (typeof str != 'string') {
  1040. return str;
  1041. }
  1042. return str.replace(/([^\w\-])/g, '\\$1');
  1043. }
  1044. function stripslashes(str) {
  1045. return str.replace(/\\/g, '');
  1046. }
  1047. function cmpTag(tagA, tagB) {
  1048. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1049. }
  1050. function byId(id, tag, root) {
  1051. var arr = [],
  1052. doc = root.ownerDocument || root,
  1053. el = doc.getElementById(stripslashes(id));
  1054. if (el) {
  1055. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1056. arr.push(el);
  1057. }
  1058. }
  1059. return arr;
  1060. }
  1061. function byClass(className, tag, root) {
  1062. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1063. if (root.getElementsByClassName) {
  1064. els = root.getElementsByClassName(stripslashes(className));
  1065. for (i = 0, len = els.length; i < len; i++) {
  1066. el = els[i];
  1067. if (cmpTag(tag, el.nodeName)) {
  1068. arr.push(el);
  1069. }
  1070. }
  1071. } else if (doc.querySelectorAll) {
  1072. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1073. for (i = 0, len = els.length; i < len; i++) {
  1074. el = els[i];
  1075. if (_contains(root, el)) {
  1076. arr.push(el);
  1077. }
  1078. }
  1079. } else {
  1080. els = root.getElementsByTagName(tag);
  1081. className = ' ' + className + ' ';
  1082. for (i = 0, len = els.length; i < len; i++) {
  1083. el = els[i];
  1084. if (el.nodeType == 1) {
  1085. var cls = el.className;
  1086. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1087. arr.push(el);
  1088. }
  1089. }
  1090. }
  1091. }
  1092. return arr;
  1093. }
  1094. function byName(name, tag, root) {
  1095. var arr = [], doc = root.ownerDocument || root,
  1096. els = doc.getElementsByName(stripslashes(name)), el;
  1097. for (var i = 0, len = els.length; i < len; i++) {
  1098. el = els[i];
  1099. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1100. if (el.getAttribute('name') !== null) {
  1101. arr.push(el);
  1102. }
  1103. }
  1104. }
  1105. return arr;
  1106. }
  1107. function byAttr(key, val, tag, root) {
  1108. var arr = [], els = root.getElementsByTagName(tag), el;
  1109. for (var i = 0, len = els.length; i < len; i++) {
  1110. el = els[i];
  1111. if (el.nodeType == 1) {
  1112. if (val === null) {
  1113. if (_getAttr(el, key) !== null) {
  1114. arr.push(el);
  1115. }
  1116. } else {
  1117. if (val === escape(_getAttr(el, key))) {
  1118. arr.push(el);
  1119. }
  1120. }
  1121. }
  1122. }
  1123. return arr;
  1124. }
  1125. function select(expr, root) {
  1126. var arr = [], matches;
  1127. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1128. var tag = matches ? matches[1] : '*';
  1129. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1130. arr = byId(matches[1], tag, root);
  1131. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1132. arr = byClass(matches[1], tag, root);
  1133. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1134. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1135. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1136. var key = matches[1].toLowerCase(), val = matches[2];
  1137. if (key === 'id') {
  1138. arr = byId(val, tag, root);
  1139. } else if (key === 'class') {
  1140. arr = byClass(val, tag, root);
  1141. } else if (key === 'name') {
  1142. arr = byName(val, tag, root);
  1143. } else {
  1144. arr = byAttr(key, val, tag, root);
  1145. }
  1146. } else {
  1147. var els = root.getElementsByTagName(tag), el;
  1148. for (var i = 0, len = els.length; i < len; i++) {
  1149. el = els[i];
  1150. if (el.nodeType == 1) {
  1151. arr.push(el);
  1152. }
  1153. }
  1154. }
  1155. return arr;
  1156. }
  1157. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1158. while ((arr = re.exec(expr))) {
  1159. if (arr[1] !== ' ') {
  1160. parts.push(arr[1]);
  1161. }
  1162. }
  1163. var results = [];
  1164. if (parts.length == 1) {
  1165. return select(parts[0], root);
  1166. }
  1167. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1168. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1169. part = parts[i];
  1170. if (part === '>') {
  1171. isChild = true;
  1172. continue;
  1173. }
  1174. if (i > 0) {
  1175. els = [];
  1176. for (j = 0, len = results.length; j < len; j++) {
  1177. val = results[j];
  1178. subResults = select(part, val);
  1179. for (k = 0, l = subResults.length; k < l; k++) {
  1180. v = subResults[k];
  1181. if (isChild) {
  1182. if (val === v.parentNode) {
  1183. els.push(v);
  1184. }
  1185. } else {
  1186. els.push(v);
  1187. }
  1188. }
  1189. }
  1190. results = els;
  1191. } else {
  1192. results = select(part, root);
  1193. }
  1194. if (results.length === 0) {
  1195. return [];
  1196. }
  1197. }
  1198. return results;
  1199. }
  1200. function _query(expr, root) {
  1201. var arr = _queryAll(expr, root);
  1202. return arr.length > 0 ? arr[0] : null;
  1203. }
  1204. K.query = _query;
  1205. K.queryAll = _queryAll;
  1206. function _get(val) {
  1207. return K(val)[0];
  1208. }
  1209. function _getDoc(node) {
  1210. if (!node) {
  1211. return document;
  1212. }
  1213. return node.ownerDocument || node.document || node;
  1214. }
  1215. function _getWin(node) {
  1216. if (!node) {
  1217. return window;
  1218. }
  1219. var doc = _getDoc(node);
  1220. return doc.parentWindow || doc.defaultView;
  1221. }
  1222. function _setHtml(el, html) {
  1223. if (el.nodeType != 1) {
  1224. return;
  1225. }
  1226. var doc = _getDoc(el);
  1227. try {
  1228. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1229. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1230. temp.parentNode.removeChild(temp);
  1231. } catch(e) {
  1232. K(el).empty();
  1233. K('@' + html, doc).each(function() {
  1234. el.appendChild(this);
  1235. });
  1236. }
  1237. }
  1238. function _hasClass(el, cls) {
  1239. return _inString(cls, el.className, ' ');
  1240. }
  1241. function _setAttr(el, key, val) {
  1242. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1243. key = 'className';
  1244. }
  1245. el.setAttribute(key, '' + val);
  1246. }
  1247. function _removeAttr(el, key) {
  1248. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1249. key = 'className';
  1250. }
  1251. _setAttr(el, key, '');
  1252. el.removeAttribute(key);
  1253. }
  1254. function _getNodeName(node) {
  1255. if (!node || !node.nodeName) {
  1256. return '';
  1257. }
  1258. return node.nodeName.toLowerCase();
  1259. }
  1260. function _computedCss(el, key) {
  1261. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1262. if (win.getComputedStyle) {
  1263. var style = win.getComputedStyle(el, null);
  1264. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1265. } else if (el.currentStyle) {
  1266. val = el.currentStyle[camelKey] || el.style[camelKey];
  1267. }
  1268. return val;
  1269. }
  1270. function _hasVal(node) {
  1271. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1272. }
  1273. function _docElement(doc) {
  1274. doc = doc || document;
  1275. return _QUIRKS ? doc.body : doc.documentElement;
  1276. }
  1277. function _docHeight(doc) {
  1278. var el = _docElement(doc);
  1279. return Math.max(el.scrollHeight, el.clientHeight);
  1280. }
  1281. function _docWidth(doc) {
  1282. var el = _docElement(doc);
  1283. return Math.max(el.scrollWidth, el.clientWidth);
  1284. }
  1285. function _getScrollPos(doc) {
  1286. doc = doc || document;
  1287. var x, y;
  1288. if (_IE || _NEWIE || _OPERA) {
  1289. x = _docElement(doc).scrollLeft;
  1290. y = _docElement(doc).scrollTop;
  1291. } else {
  1292. x = _getWin(doc).scrollX;
  1293. y = _getWin(doc).scrollY;
  1294. }
  1295. return {x : x, y : y};
  1296. }
  1297. function KNode(node) {
  1298. this.init(node);
  1299. }
  1300. _extend(KNode, {
  1301. init : function(node) {
  1302. var self = this;
  1303. node = _isArray(node) ? node : [node];
  1304. var length = 0;
  1305. for (var i = 0, len = node.length; i < len; i++) {
  1306. if (node[i]) {
  1307. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1308. length++;
  1309. }
  1310. }
  1311. self.length = length;
  1312. self.doc = _getDoc(self[0]);
  1313. self.name = _getNodeName(self[0]);
  1314. self.type = self.length > 0 ? self[0].nodeType : null;
  1315. self.win = _getWin(self[0]);
  1316. },
  1317. each : function(fn) {
  1318. var self = this;
  1319. for (var i = 0; i < self.length; i++) {
  1320. if (fn.call(self[i], i, self[i]) === false) {
  1321. return self;
  1322. }
  1323. }
  1324. return self;
  1325. },
  1326. bind : function(type, fn) {
  1327. this.each(function() {
  1328. _bind(this, type, fn);
  1329. });
  1330. return this;
  1331. },
  1332. unbind : function(type, fn) {
  1333. this.each(function() {
  1334. _unbind(this, type, fn);
  1335. });
  1336. return this;
  1337. },
  1338. fire : function(type) {
  1339. if (this.length < 1) {
  1340. return this;
  1341. }
  1342. _fire(this[0], type);
  1343. return this;
  1344. },
  1345. hasAttr : function(key) {
  1346. if (this.length < 1) {
  1347. return false;
  1348. }
  1349. return !!_getAttr(this[0], key);
  1350. },
  1351. attr : function(key, val) {
  1352. var self = this;
  1353. if (key === undefined) {
  1354. return _getAttrList(self.outer());
  1355. }
  1356. if (typeof key === 'object') {
  1357. _each(key, function(k, v) {
  1358. self.attr(k, v);
  1359. });
  1360. return self;
  1361. }
  1362. if (val === undefined) {
  1363. val = self.length < 1 ? null : _getAttr(self[0], key);
  1364. return val === null ? '' : val;
  1365. }
  1366. self.each(function() {
  1367. _setAttr(this, key, val);
  1368. });
  1369. return self;
  1370. },
  1371. removeAttr : function(key) {
  1372. this.each(function() {
  1373. _removeAttr(this, key);
  1374. });
  1375. return this;
  1376. },
  1377. get : function(i) {
  1378. if (this.length < 1) {
  1379. return null;
  1380. }
  1381. return this[i || 0];
  1382. },
  1383. eq : function(i) {
  1384. if (this.length < 1) {
  1385. return null;
  1386. }
  1387. return this[i] ? new KNode(this[i]) : null;
  1388. },
  1389. hasClass : function(cls) {
  1390. if (this.length < 1) {
  1391. return false;
  1392. }
  1393. return _hasClass(this[0], cls);
  1394. },
  1395. addClass : function(cls) {
  1396. this.each(function() {
  1397. if (!_hasClass(this, cls)) {
  1398. this.className = _trim(this.className + ' ' + cls);
  1399. }
  1400. });
  1401. return this;
  1402. },
  1403. removeClass : function(cls) {
  1404. this.each(function() {
  1405. if (_hasClass(this, cls)) {
  1406. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1407. }
  1408. });
  1409. return this;
  1410. },
  1411. html : function(val) {
  1412. var self = this;
  1413. if (val === undefined) {
  1414. if (self.length < 1 || self.type != 1) {
  1415. return '';
  1416. }
  1417. return _formatHtml(self[0].innerHTML);
  1418. }
  1419. self.each(function() {
  1420. _setHtml(this, val);
  1421. });
  1422. return self;
  1423. },
  1424. text : function() {
  1425. var self = this;
  1426. if (self.length < 1) {
  1427. return '';
  1428. }
  1429. return _IE ? self[0].innerText : self[0].textContent;
  1430. },
  1431. hasVal : function() {
  1432. if (this.length < 1) {
  1433. return false;
  1434. }
  1435. return _hasVal(this[0]);
  1436. },
  1437. val : function(val) {
  1438. var self = this;
  1439. if (val === undefined) {
  1440. if (self.length < 1) {
  1441. return '';
  1442. }
  1443. return self.hasVal() ? self[0].value : self.attr('value');
  1444. } else {
  1445. self.each(function() {
  1446. if (_hasVal(this)) {
  1447. this.value = val;
  1448. } else {
  1449. _setAttr(this, 'value' , val);
  1450. }
  1451. });
  1452. return self;
  1453. }
  1454. },
  1455. css : function(key, val) {
  1456. var self = this;
  1457. if (key === undefined) {
  1458. return _getCssList(self.attr('style'));
  1459. }
  1460. if (typeof key === 'object') {
  1461. _each(key, function(k, v) {
  1462. self.css(k, v);
  1463. });
  1464. return self;
  1465. }
  1466. if (val === undefined) {
  1467. if (self.length < 1) {
  1468. return '';
  1469. }
  1470. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1471. }
  1472. self.each(function() {
  1473. this.style[_toCamel(key)] = val;
  1474. });
  1475. return self;
  1476. },
  1477. width : function(val) {
  1478. var self = this;
  1479. if (val === undefined) {
  1480. if (self.length < 1) {
  1481. return 0;
  1482. }
  1483. return self[0].offsetWidth;
  1484. }
  1485. return self.css('width', _addUnit(val));
  1486. },
  1487. height : function(val) {
  1488. var self = this;
  1489. if (val === undefined) {
  1490. if (self.length < 1) {
  1491. return 0;
  1492. }
  1493. return self[0].offsetHeight;
  1494. }
  1495. return self.css('height', _addUnit(val));
  1496. },
  1497. opacity : function(val) {
  1498. this.each(function() {
  1499. if (this.style.opacity === undefined) {
  1500. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1501. } else {
  1502. this.style.opacity = val == 1 ? '' : val;
  1503. }
  1504. });
  1505. return this;
  1506. },
  1507. data : function(key, val) {
  1508. var self = this;
  1509. key = 'kindeditor_data_' + key;
  1510. if (val === undefined) {
  1511. if (self.length < 1) {
  1512. return null;
  1513. }
  1514. return self[0][key];
  1515. }
  1516. this.each(function() {
  1517. this[key] = val;
  1518. });
  1519. return self;
  1520. },
  1521. pos : function() {
  1522. var self = this, node = self[0], x = 0, y = 0;
  1523. if (node) {
  1524. if (node.getBoundingClientRect) {
  1525. var box = node.getBoundingClientRect(),
  1526. pos = _getScrollPos(self.doc);
  1527. x = box.left + pos.x;
  1528. y = box.top + pos.y;
  1529. } else {
  1530. while (node) {
  1531. x += node.offsetLeft;
  1532. y += node.offsetTop;
  1533. node = node.offsetParent;
  1534. }
  1535. }
  1536. }
  1537. return {x : _round(x), y : _round(y)};
  1538. },
  1539. clone : function(bool) {
  1540. if (this.length < 1) {
  1541. return new KNode([]);
  1542. }
  1543. return new KNode(this[0].cloneNode(bool));
  1544. },
  1545. append : function(expr) {
  1546. this.each(function() {
  1547. if (this.appendChild) {
  1548. this.appendChild(_get(expr));
  1549. }
  1550. });
  1551. return this;
  1552. },
  1553. appendTo : function(expr) {
  1554. this.each(function() {
  1555. _get(expr).appendChild(this);
  1556. });
  1557. return this;
  1558. },
  1559. before : function(expr) {
  1560. this.each(function() {
  1561. this.parentNode.insertBefore(_get(expr), this);
  1562. });
  1563. return this;
  1564. },
  1565. after : function(expr) {
  1566. this.each(function() {
  1567. if (this.nextSibling) {
  1568. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1569. } else {
  1570. this.parentNode.appendChild(_get(expr));
  1571. }
  1572. });
  1573. return this;
  1574. },
  1575. replaceWith : function(expr) {
  1576. var nodes = [];
  1577. this.each(function(i, node) {
  1578. _unbind(node);
  1579. var newNode = _get(expr);
  1580. node.parentNode.replaceChild(newNode, node);
  1581. nodes.push(newNode);
  1582. });
  1583. return K(nodes);
  1584. },
  1585. empty : function() {
  1586. var self = this;
  1587. self.each(function(i, node) {
  1588. var child = node.firstChild;
  1589. while (child) {
  1590. if (!node.parentNode) {
  1591. return;
  1592. }
  1593. var next = child.nextSibling;
  1594. child.parentNode.removeChild(child);
  1595. child = next;
  1596. }
  1597. });
  1598. return self;
  1599. },
  1600. remove : function(keepChilds) {
  1601. var self = this;
  1602. self.each(function(i, node) {
  1603. if (!node.parentNode) {
  1604. return;
  1605. }
  1606. _unbind(node);
  1607. if (keepChilds) {
  1608. var child = node.firstChild;
  1609. while (child) {
  1610. var next = child.nextSibling;
  1611. node.parentNode.insertBefore(child, node);
  1612. child = next;
  1613. }
  1614. }
  1615. node.parentNode.removeChild(node);
  1616. delete self[i];
  1617. });
  1618. self.length = 0;
  1619. return self;
  1620. },
  1621. show : function(val) {
  1622. var self = this;
  1623. if (val === undefined) {
  1624. val = self._originDisplay || '';
  1625. }
  1626. if (self.css('display') != 'none') {
  1627. return self;
  1628. }
  1629. return self.css('display', val);
  1630. },
  1631. hide : function() {
  1632. var self = this;
  1633. if (self.length < 1) {
  1634. return self;
  1635. }
  1636. self._originDisplay = self[0].style.display;
  1637. return self.css('display', 'none');
  1638. },
  1639. outer : function() {
  1640. var self = this;
  1641. if (self.length < 1) {
  1642. return '';
  1643. }
  1644. var div = self.doc.createElement('div'), html;
  1645. div.appendChild(self[0].cloneNode(true));
  1646. html = _formatHtml(div.innerHTML);
  1647. div = null;
  1648. return html;
  1649. },
  1650. isSingle : function() {
  1651. return !!_SINGLE_TAG_MAP[this.name];
  1652. },
  1653. isInline : function() {
  1654. return !!_INLINE_TAG_MAP[this.name];
  1655. },
  1656. isBlock : function() {
  1657. return !!_BLOCK_TAG_MAP[this.name];
  1658. },
  1659. isStyle : function() {
  1660. return !!_STYLE_TAG_MAP[this.name];
  1661. },
  1662. isControl : function() {
  1663. return !!_CONTROL_TAG_MAP[this.name];
  1664. },
  1665. contains : function(otherNode) {
  1666. if (this.length < 1) {
  1667. return false;
  1668. }
  1669. return _contains(this[0], _get(otherNode));
  1670. },
  1671. parent : function() {
  1672. if (this.length < 1) {
  1673. return null;
  1674. }
  1675. var node = this[0].parentNode;
  1676. return node ? new KNode(node) : null;
  1677. },
  1678. children : function() {
  1679. if (this.length < 1) {
  1680. return new KNode([]);
  1681. }
  1682. var list = [], child = this[0].firstChild;
  1683. while (child) {
  1684. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1685. list.push(child);
  1686. }
  1687. child = child.nextSibling;
  1688. }
  1689. return new KNode(list);
  1690. },
  1691. first : function() {
  1692. var list = this.children();
  1693. return list.length > 0 ? list.eq(0) : null;
  1694. },
  1695. last : function() {
  1696. var list = this.children();
  1697. return list.length > 0 ? list.eq(list.length - 1) : null;
  1698. },
  1699. index : function() {
  1700. if (this.length < 1) {
  1701. return -1;
  1702. }
  1703. var i = -1, sibling = this[0];
  1704. while (sibling) {
  1705. i++;
  1706. sibling = sibling.previousSibling;
  1707. }
  1708. return i;
  1709. },
  1710. prev : function() {
  1711. if (this.length < 1) {
  1712. return null;
  1713. }
  1714. var node = this[0].previousSibling;
  1715. return node ? new KNode(node) : null;
  1716. },
  1717. next : function() {
  1718. if (this.length < 1) {
  1719. return null;
  1720. }
  1721. var node = this[0].nextSibling;
  1722. return node ? new KNode(node) : null;
  1723. },
  1724. scan : function(fn, order) {
  1725. if (this.length < 1) {
  1726. return;
  1727. }
  1728. order = (order === undefined) ? true : order;
  1729. function walk(node) {
  1730. var n = order ? node.firstChild : node.lastChild;
  1731. while (n) {
  1732. var next = order ? n.nextSibling : n.previousSibling;
  1733. if (fn(n) === false) {
  1734. return false;
  1735. }
  1736. if (walk(n) === false) {
  1737. return false;
  1738. }
  1739. n = next;
  1740. }
  1741. }
  1742. walk(this[0]);
  1743. return this;
  1744. }
  1745. });
  1746. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1747. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1748. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1749. KNode.prototype[type] = function(fn) {
  1750. return fn ? this.bind(type, fn) : this.fire(type);
  1751. };
  1752. });
  1753. var _K = K;
  1754. K = function(expr, root) {
  1755. if (expr === undefined || expr === null) {
  1756. return;
  1757. }
  1758. function newNode(node) {
  1759. if (!node[0]) {
  1760. node = [];
  1761. }
  1762. return new KNode(node);
  1763. }
  1764. if (typeof expr === 'string') {
  1765. if (root) {
  1766. root = _get(root);
  1767. }
  1768. var length = expr.length;
  1769. if (expr.charAt(0) === '@') {
  1770. expr = expr.substr(1);
  1771. }
  1772. if (expr.length !== length || /<.+>/.test(expr)) {
  1773. var doc = root ? root.ownerDocument || root : document,
  1774. div = doc.createElement('div'), list = [];
  1775. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1776. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1777. var child = div.childNodes[i];
  1778. if (child.id == '__kindeditor_temp_tag__') {
  1779. continue;
  1780. }
  1781. list.push(child);
  1782. }
  1783. return newNode(list);
  1784. }
  1785. return newNode(_queryAll(expr, root));
  1786. }
  1787. if (expr && expr.constructor === KNode) {
  1788. return expr;
  1789. }
  1790. if (expr.toArray) {
  1791. expr = expr.toArray();
  1792. }
  1793. if (_isArray(expr)) {
  1794. return newNode(expr);
  1795. }
  1796. return newNode(_toArray(arguments));
  1797. };
  1798. _each(_K, function(key, val) {
  1799. K[key] = val;
  1800. });
  1801. K.NodeClass = KNode;
  1802. window.KindEditor = K;
  1803. var _START_TO_START = 0,
  1804. _START_TO_END = 1,
  1805. _END_TO_END = 2,
  1806. _END_TO_START = 3,
  1807. _BOOKMARK_ID = 0;
  1808. function _updateCollapsed(range) {
  1809. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1810. return range;
  1811. }
  1812. function _copyAndDelete(range, isCopy, isDelete) {
  1813. var doc = range.doc, nodeList = [];
  1814. function splitTextNode(node, startOffset, endOffset) {
  1815. var length = node.nodeValue.length, centerNode;
  1816. if (isCopy) {
  1817. var cloneNode = node.cloneNode(true);
  1818. if (startOffset > 0) {
  1819. centerNode = cloneNode.splitText(startOffset);
  1820. } else {
  1821. centerNode = cloneNode;
  1822. }
  1823. if (endOffset < length) {
  1824. centerNode.splitText(endOffset - startOffset);
  1825. }
  1826. }
  1827. if (isDelete) {
  1828. var center = node;
  1829. if (startOffset > 0) {
  1830. center = node.splitText(startOffset);
  1831. range.setStart(node, startOffset);
  1832. }
  1833. if (endOffset < length) {
  1834. var right = center.splitText(endOffset - startOffset);
  1835. range.setEnd(right, 0);
  1836. }
  1837. nodeList.push(center);
  1838. }
  1839. return centerNode;
  1840. }
  1841. function removeNodes() {
  1842. if (isDelete) {
  1843. range.up().collapse(true);
  1844. }
  1845. for (var i = 0, len = nodeList.length; i < len; i++) {
  1846. var node = nodeList[i];
  1847. if (node.parentNode) {
  1848. node.parentNode.removeChild(node);
  1849. }
  1850. }
  1851. }
  1852. var copyRange = range.cloneRange().down();
  1853. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1854. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1855. if (ancestor.nodeType == 3) {
  1856. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1857. if (isCopy) {
  1858. frag.appendChild(textNode);
  1859. }
  1860. removeNodes();
  1861. return isCopy ? frag : range;
  1862. }
  1863. function extractNodes(parent, frag) {
  1864. var node = parent.firstChild, nextNode;
  1865. while (node) {
  1866. var testRange = new KRange(doc).selectNode(node);
  1867. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1868. if (start >= 0 && incStart <= 0) {
  1869. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1870. }
  1871. if (incStart >= 0 && incEnd <= 0) {
  1872. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1873. }
  1874. if (incEnd >= 0 && end <= 0) {
  1875. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1876. }
  1877. if (end >= 0) {
  1878. return false;
  1879. }
  1880. nextNode = node.nextSibling;
  1881. if (start > 0) {
  1882. if (node.nodeType == 1) {
  1883. if (incStart >= 0 && incEnd <= 0) {
  1884. if (isCopy) {
  1885. frag.appendChild(node.cloneNode(true));
  1886. }
  1887. if (isDelete) {
  1888. nodeList.push(node);
  1889. }
  1890. } else {
  1891. var childFlag;
  1892. if (isCopy) {
  1893. childFlag = node.cloneNode(false);
  1894. frag.appendChild(childFlag);
  1895. }
  1896. if (extractNodes(node, childFlag) === false) {
  1897. return false;
  1898. }
  1899. }
  1900. } else if (node.nodeType == 3) {
  1901. var textNode;
  1902. if (node == copyRange.startContainer) {
  1903. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1904. } else if (node == copyRange.endContainer) {
  1905. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1906. } else {
  1907. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1908. }
  1909. if (isCopy) {
  1910. try {
  1911. frag.appendChild(textNode);
  1912. } catch(e) {}
  1913. }
  1914. }
  1915. }
  1916. node = nextNode;
  1917. }
  1918. }
  1919. extractNodes(ancestor, frag);
  1920. if (isDelete) {
  1921. range.up().collapse(true);
  1922. }
  1923. for (var i = 0, len = nodeList.length; i < len; i++) {
  1924. var node = nodeList[i];
  1925. if (node.parentNode) {
  1926. node.parentNode.removeChild(node);
  1927. }
  1928. }
  1929. return isCopy ? frag : range;
  1930. }
  1931. function _moveToElementText(range, el) {
  1932. var node = el;
  1933. while (node) {
  1934. var knode = K(node);
  1935. if (knode.name == 'marquee' || knode.name == 'select') {
  1936. return;
  1937. }
  1938. node = node.parentNode;
  1939. }
  1940. try {
  1941. range.moveToElementText(el);
  1942. } catch(e) {}
  1943. }
  1944. function _getStartEnd(rng, isStart) {
  1945. var doc = rng.parentElement().ownerDocument,
  1946. pointRange = rng.duplicate();
  1947. pointRange.collapse(isStart);
  1948. var parent = pointRange.parentElement(),
  1949. nodes = parent.childNodes;
  1950. if (nodes.length === 0) {
  1951. return {node: parent.parentNode, offset: K(parent).index()};
  1952. }
  1953. var startNode = doc, startPos = 0, cmp = -1;
  1954. var testRange = rng.duplicate();
  1955. _moveToElementText(testRange, parent);
  1956. for (var i = 0, len = nodes.length; i < len; i++) {
  1957. var node = nodes[i];
  1958. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1959. if (cmp === 0) {
  1960. return {node: node.parentNode, offset: i};
  1961. }
  1962. if (node.nodeType == 1) {
  1963. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1964. if (knode.isControl()) {
  1965. dummy = doc.createElement('span');
  1966. knode.after(dummy);
  1967. newNode = dummy;
  1968. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1969. }
  1970. _moveToElementText(nodeRange, newNode);
  1971. testRange.setEndPoint('StartToEnd', nodeRange);
  1972. if (cmp > 0) {
  1973. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1974. } else {
  1975. startPos = 0;
  1976. }
  1977. if (dummy) {
  1978. K(dummy).remove();
  1979. }
  1980. } else if (node.nodeType == 3) {
  1981. testRange.moveStart('character', node.nodeValue.length);
  1982. startPos += node.nodeValue.length;
  1983. }
  1984. if (cmp < 0) {
  1985. startNode = node;
  1986. }
  1987. }
  1988. if (cmp < 0 && startNode.nodeType == 1) {
  1989. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1990. }
  1991. if (cmp > 0) {
  1992. while (startNode.nextSibling && startNode.nodeType == 1) {
  1993. startNode = startNode.nextSibling;
  1994. }
  1995. }
  1996. testRange = rng.duplicate();
  1997. _moveToElementText(testRange, parent);
  1998. testRange.setEndPoint('StartToEnd', pointRange);
  1999. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  2000. if (cmp > 0 && startNode.nodeType == 3) {
  2001. var prevNode = startNode.previousSibling;
  2002. while (prevNode && prevNode.nodeType == 3) {
  2003. startPos -= prevNode.nodeValue.length;
  2004. prevNode = prevNode.previousSibling;
  2005. }
  2006. }
  2007. return {node: startNode, offset: startPos};
  2008. }
  2009. function _getEndRange(node, offset) {
  2010. var doc = node.ownerDocument || node,
  2011. range = doc.body.createTextRange();
  2012. if (doc == node) {
  2013. range.collapse(true);
  2014. return range;
  2015. }
  2016. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2017. var children = node.childNodes, isStart, child;
  2018. if (offset === 0) {
  2019. child = children[0];
  2020. isStart = true;
  2021. } else {
  2022. child = children[offset - 1];
  2023. isStart = false;
  2024. }
  2025. if (!child) {
  2026. return range;
  2027. }
  2028. if (K(child).name === 'head') {
  2029. if (offset === 1) {
  2030. isStart = true;
  2031. }
  2032. if (offset === 2) {
  2033. isStart = false;
  2034. }
  2035. range.collapse(isStart);
  2036. return range;
  2037. }
  2038. if (child.nodeType == 1) {
  2039. var kchild = K(child), span;
  2040. if (kchild.isControl()) {
  2041. span = doc.createElement('span');
  2042. if (isStart) {
  2043. kchild.before(span);
  2044. } else {
  2045. kchild.after(span);
  2046. }
  2047. child = span;
  2048. }
  2049. _moveToElementText(range, child);
  2050. range.collapse(isStart);
  2051. if (span) {
  2052. K(span).remove();
  2053. }
  2054. return range;
  2055. }
  2056. node = child;
  2057. offset = isStart ? 0 : child.nodeValue.length;
  2058. }
  2059. var dummy = doc.createElement('span');
  2060. K(node).before(dummy);
  2061. _moveToElementText(range, dummy);
  2062. range.moveStart('character', offset);
  2063. K(dummy).remove();
  2064. return range;
  2065. }
  2066. function _toRange(rng) {
  2067. var doc, range;
  2068. function tr2td(start) {
  2069. if (K(start.node).name == 'tr') {
  2070. start.node = start.node.cells[start.offset];
  2071. start.offset = 0;
  2072. }
  2073. }
  2074. if (_IERANGE) {
  2075. if (rng.item) {
  2076. doc = _getDoc(rng.item(0));
  2077. range = new KRange(doc);
  2078. range.selectNode(rng.item(0));
  2079. return range;
  2080. }
  2081. doc = rng.parentElement().ownerDocument;
  2082. var start = _getStartEnd(rng, true),
  2083. end = _getStartEnd(rng, false);
  2084. tr2td(start);
  2085. tr2td(end);
  2086. range = new KRange(doc);
  2087. range.setStart(start.node, start.offset);
  2088. range.setEnd(end.node, end.offset);
  2089. return range;
  2090. }
  2091. var startContainer = rng.startContainer;
  2092. doc = startContainer.ownerDocument || startContainer;
  2093. range = new KRange(doc);
  2094. range.setStart(startContainer, rng.startOffset);
  2095. range.setEnd(rng.endContainer, rng.endOffset);
  2096. return range;
  2097. }
  2098. function KRange(doc) {
  2099. this.init(doc);
  2100. }
  2101. _extend(KRange, {
  2102. init : function(doc) {
  2103. var self = this;
  2104. self.startContainer = doc;
  2105. self.startOffset = 0;
  2106. self.endContainer = doc;
  2107. self.endOffset = 0;
  2108. self.collapsed = true;
  2109. self.doc = doc;
  2110. },
  2111. commonAncestor : function() {
  2112. function getParents(node) {
  2113. var parents = [];
  2114. while (node) {
  2115. parents.push(node);
  2116. node = node.parentNode;
  2117. }
  2118. return parents;
  2119. }
  2120. var parentsA = getParents(this.startContainer),
  2121. parentsB = getParents(this.endContainer),
  2122. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2123. while (++i) {
  2124. parentA = parentsA[lenA - i];
  2125. parentB = parentsB[lenB - i];
  2126. if (!parentA || !parentB || parentA !== parentB) {
  2127. break;
  2128. }
  2129. }
  2130. return parentsA[lenA - i + 1];
  2131. },
  2132. setStart : function(node, offset) {
  2133. var self = this, doc = self.doc;
  2134. self.startContainer = node;
  2135. self.startOffset = offset;
  2136. if (self.endContainer === doc) {
  2137. self.endContainer = node;
  2138. self.endOffset = offset;
  2139. }
  2140. return _updateCollapsed(this);
  2141. },
  2142. setEnd : function(node, offset) {
  2143. var self = this, doc = self.doc;
  2144. self.endContainer = node;
  2145. self.endOffset = offset;
  2146. if (self.startContainer === doc) {
  2147. self.startContainer = node;
  2148. self.startOffset = offset;
  2149. }
  2150. return _updateCollapsed(this);
  2151. },
  2152. setStartBefore : function(node) {
  2153. return this.setStart(node.parentNode || this.doc, K(node).index());
  2154. },
  2155. setStartAfter : function(node) {
  2156. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2157. },
  2158. setEndBefore : function(node) {
  2159. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2160. },
  2161. setEndAfter : function(node) {
  2162. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2163. },
  2164. selectNode : function(node) {
  2165. return this.setStartBefore(node).setEndAfter(node);
  2166. },
  2167. selectNodeContents : function(node) {
  2168. var knode = K(node);
  2169. if (knode.type == 3 || knode.isSingle()) {
  2170. return this.selectNode(node);
  2171. }
  2172. var children = knode.children();
  2173. if (children.length > 0) {
  2174. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2175. }
  2176. return this.setStart(node, 0).setEnd(node, 0);
  2177. },
  2178. collapse : function(toStart) {
  2179. if (toStart) {
  2180. return this.setEnd(this.startContainer, this.startOffset);
  2181. }
  2182. return this.setStart(this.endContainer, this.endOffset);
  2183. },
  2184. compareBoundaryPoints : function(how, range) {
  2185. var rangeA = this.get(), rangeB = range.get();
  2186. if (_IERANGE) {
  2187. var arr = {};
  2188. arr[_START_TO_START] = 'StartToStart';
  2189. arr[_START_TO_END] = 'EndToStart';
  2190. arr[_END_TO_END] = 'EndToEnd';
  2191. arr[_END_TO_START] = 'StartToEnd';
  2192. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2193. if (cmp !== 0) {
  2194. return cmp;
  2195. }
  2196. var nodeA, nodeB, nodeC, posA, posB;
  2197. if (how === _START_TO_START || how === _END_TO_START) {
  2198. nodeA = this.startContainer;
  2199. posA = this.startOffset;
  2200. }
  2201. if (how === _START_TO_END || how === _END_TO_END) {
  2202. nodeA = this.endContainer;
  2203. posA = this.endOffset;
  2204. }
  2205. if (how === _START_TO_START || how === _START_TO_END) {
  2206. nodeB = range.startContainer;
  2207. posB = range.startOffset;
  2208. }
  2209. if (how === _END_TO_END || how === _END_TO_START) {
  2210. nodeB = range.endContainer;
  2211. posB = range.endOffset;
  2212. }
  2213. if (nodeA === nodeB) {
  2214. var diff = posA - posB;
  2215. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2216. }
  2217. nodeC = nodeB;
  2218. while (nodeC && nodeC.parentNode !== nodeA) {
  2219. nodeC = nodeC.parentNode;
  2220. }
  2221. if (nodeC) {
  2222. return K(nodeC).index() >= posA ? -1 : 1;
  2223. }
  2224. nodeC = nodeA;
  2225. while (nodeC && nodeC.parentNode !== nodeB) {
  2226. nodeC = nodeC.parentNode;
  2227. }
  2228. if (nodeC) {
  2229. return K(nodeC).index() >= posB ? 1 : -1;
  2230. }
  2231. nodeC = K(nodeB).next();
  2232. if (nodeC && nodeC.contains(nodeA)) {
  2233. return 1;
  2234. }
  2235. nodeC = K(nodeA).next();
  2236. if (nodeC && nodeC.contains(nodeB)) {
  2237. return -1;
  2238. }
  2239. } else {
  2240. return rangeA.compareBoundaryPoints(how, rangeB);
  2241. }
  2242. },
  2243. cloneRange : function() {
  2244. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2245. },
  2246. toString : function() {
  2247. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2248. return str.replace(/\r\n|\n|\r/g, '');
  2249. },
  2250. cloneContents : function() {
  2251. return _copyAndDelete(this, true, false);
  2252. },
  2253. deleteContents : function() {
  2254. return _copyAndDelete(this, false, true);
  2255. },
  2256. extractContents : function() {
  2257. return _copyAndDelete(this, true, true);
  2258. },
  2259. insertNode : function(node) {
  2260. var self = this,
  2261. sc = self.startContainer, so = self.startOffset,
  2262. ec = self.endContainer, eo = self.endOffset,
  2263. firstChild, lastChild, c, nodeCount = 1;
  2264. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2265. firstChild = node.firstChild;
  2266. lastChild = node.lastChild;
  2267. nodeCount = node.childNodes.length;
  2268. }
  2269. if (sc.nodeType == 1) {
  2270. c = sc.childNodes[so];
  2271. if (c) {
  2272. sc.insertBefore(node, c);
  2273. if (sc === ec) {
  2274. eo += nodeCount;
  2275. }
  2276. } else {
  2277. sc.appendChild(node);
  2278. }
  2279. } else if (sc.nodeType == 3) {
  2280. if (so === 0) {
  2281. sc.parentNode.insertBefore(node, sc);
  2282. if (sc.parentNode === ec) {
  2283. eo += nodeCount;
  2284. }
  2285. } else if (so >= sc.nodeValue.length) {
  2286. if (sc.nextSibling) {
  2287. sc.parentNode.insertBefore(node, sc.nextSibling);
  2288. } else {
  2289. sc.parentNode.appendChild(node);
  2290. }
  2291. } else {
  2292. if (so > 0) {
  2293. c = sc.splitText(so);
  2294. } else {
  2295. c = sc;
  2296. }
  2297. sc.parentNode.insertBefore(node, c);
  2298. if (sc === ec) {
  2299. ec = c;
  2300. eo -= so;
  2301. }
  2302. }
  2303. }
  2304. if (firstChild) {
  2305. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2306. } else {
  2307. self.selectNode(node);
  2308. }
  2309. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2310. return self;
  2311. }
  2312. return self.setEnd(ec, eo);
  2313. },
  2314. surroundContents : function(node) {
  2315. node.appendChild(this.extractContents());
  2316. return this.insertNode(node).selectNode(node);
  2317. },
  2318. isControl : function() {
  2319. var self = this,
  2320. sc = self.startContainer, so = self.startOffset,
  2321. ec = self.endContainer, eo = self.endOffset, rng;
  2322. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2323. },
  2324. get : function(hasControlRange) {
  2325. var self = this, doc = self.doc, node, rng;
  2326. if (!_IERANGE) {
  2327. rng = doc.createRange();
  2328. try {
  2329. rng.setStart(self.startContainer, self.startOffset);
  2330. rng.setEnd(self.endContainer, self.endOffset);
  2331. } catch (e) {}
  2332. return rng;
  2333. }
  2334. if (hasControlRange && self.isControl()) {
  2335. rng = doc.body.createControlRange();
  2336. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2337. return rng;
  2338. }
  2339. var range = self.cloneRange().down();
  2340. rng = doc.body.createTextRange();
  2341. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2342. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2343. return rng;
  2344. },
  2345. html : function() {
  2346. return K(this.cloneContents()).outer();
  2347. },
  2348. down : function() {
  2349. var self = this;
  2350. function downPos(node, pos, isStart) {
  2351. if (node.nodeType != 1) {
  2352. return;
  2353. }
  2354. var children = K(node).children();
  2355. if (children.length === 0) {
  2356. return;
  2357. }
  2358. var left, right, child, offset;
  2359. if (pos > 0) {
  2360. left = children.eq(pos - 1);
  2361. }
  2362. if (pos < children.length) {
  2363. right = children.eq(pos);
  2364. }
  2365. if (left && left.type == 3) {
  2366. child = left[0];
  2367. offset = child.nodeValue.length;
  2368. }
  2369. if (right && right.type == 3) {
  2370. child = right[0];
  2371. offset = 0;
  2372. }
  2373. if (!child) {
  2374. return;
  2375. }
  2376. if (isStart) {
  2377. self.setStart(child, offset);
  2378. } else {
  2379. self.setEnd(child, offset);
  2380. }
  2381. }
  2382. downPos(self.startContainer, self.startOffset, true);
  2383. downPos(self.endContainer, self.endOffset, false);
  2384. return self;
  2385. },
  2386. up : function() {
  2387. var self = this;
  2388. function upPos(node, pos, isStart) {
  2389. if (node.nodeType != 3) {
  2390. return;
  2391. }
  2392. if (pos === 0) {
  2393. if (isStart) {
  2394. self.setStartBefore(node);
  2395. } else {
  2396. self.setEndBefore(node);
  2397. }
  2398. } else if (pos == node.nodeValue.length) {
  2399. if (isStart) {
  2400. self.setStartAfter(node);
  2401. } else {
  2402. self.setEndAfter(node);
  2403. }
  2404. }
  2405. }
  2406. upPos(self.startContainer, self.startOffset, true);
  2407. upPos(self.endContainer, self.endOffset, false);
  2408. return self;
  2409. },
  2410. enlarge : function(toBlock) {
  2411. var self = this;
  2412. self.up();
  2413. function enlargePos(node, pos, isStart) {
  2414. var knode = K(node), parent;
  2415. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2416. return;
  2417. }
  2418. if (pos === 0) {
  2419. while (!knode.prev()) {
  2420. parent = knode.parent();
  2421. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2422. break;
  2423. }
  2424. knode = parent;
  2425. }
  2426. if (isStart) {
  2427. self.setStartBefore(knode[0]);
  2428. } else {
  2429. self.setEndBefore(knode[0]);
  2430. }
  2431. } else if (pos == knode.children().length) {
  2432. while (!knode.next()) {
  2433. parent = knode.parent();
  2434. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2435. break;
  2436. }
  2437. knode = parent;
  2438. }
  2439. if (isStart) {
  2440. self.setStartAfter(knode[0]);
  2441. } else {
  2442. self.setEndAfter(knode[0]);
  2443. }
  2444. }
  2445. }
  2446. enlargePos(self.startContainer, self.startOffset, true);
  2447. enlargePos(self.endContainer, self.endOffset, false);
  2448. return self;
  2449. },
  2450. shrink : function() {
  2451. var self = this, child, collapsed = self.collapsed;
  2452. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2453. self.setStart(child, 0);
  2454. }
  2455. if (collapsed) {
  2456. return self.collapse(collapsed);
  2457. }
  2458. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2459. self.setEnd(child, child.childNodes.length);
  2460. }
  2461. return self;
  2462. },
  2463. createBookmark : function(serialize) {
  2464. var self = this, doc = self.doc, endNode,
  2465. startNode = K('<span style="display:none;"></span>', doc)[0];
  2466. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2467. if (!self.collapsed) {
  2468. endNode = startNode.cloneNode(true);
  2469. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2470. }
  2471. if (endNode) {
  2472. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2473. }
  2474. self.insertNode(startNode).setStartAfter(startNode);
  2475. return {
  2476. start : serialize ? '#' + startNode.id : startNode,
  2477. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2478. };
  2479. },
  2480. moveToBookmark : function(bookmark) {
  2481. var self = this, doc = self.doc,
  2482. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2483. if (!start || start.length < 1) {
  2484. return self;
  2485. }
  2486. self.setStartBefore(start[0]);
  2487. start.remove();
  2488. if (end && end.length > 0) {
  2489. self.setEndBefore(end[0]);
  2490. end.remove();
  2491. } else {
  2492. self.collapse(true);
  2493. }
  2494. return self;
  2495. },
  2496. dump : function() {
  2497. console.log('--------------------');
  2498. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2499. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2500. }
  2501. });
  2502. function _range(mixed) {
  2503. if (!mixed.nodeName) {
  2504. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2505. }
  2506. return new KRange(mixed);
  2507. }
  2508. K.RangeClass = KRange;
  2509. K.range = _range;
  2510. K.START_TO_START = _START_TO_START;
  2511. K.START_TO_END = _START_TO_END;
  2512. K.END_TO_END = _END_TO_END;
  2513. K.END_TO_START = _END_TO_START;
  2514. function _nativeCommand(doc, key, val) {
  2515. try {
  2516. doc.execCommand(key, false, val);
  2517. } catch(e) {}
  2518. }
  2519. function _nativeCommandValue(doc, key) {
  2520. var val = '';
  2521. try {
  2522. val = doc.queryCommandValue(key);
  2523. } catch (e) {}
  2524. if (typeof val !== 'string') {
  2525. val = '';
  2526. }
  2527. return val;
  2528. }
  2529. function _getSel(doc) {
  2530. var win = _getWin(doc);
  2531. return _IERANGE ? doc.selection : win.getSelection();
  2532. }
  2533. function _getRng(doc) {
  2534. var sel = _getSel(doc), rng;
  2535. try {
  2536. if (sel.rangeCount > 0) {
  2537. rng = sel.getRangeAt(0);
  2538. } else {
  2539. rng = sel.createRange();
  2540. }
  2541. } catch(e) {}
  2542. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2543. return null;
  2544. }
  2545. return rng;
  2546. }
  2547. function _singleKeyMap(map) {
  2548. var newMap = {}, arr, v;
  2549. _each(map, function(key, val) {
  2550. arr = key.split(',');
  2551. for (var i = 0, len = arr.length; i < len; i++) {
  2552. v = arr[i];
  2553. newMap[v] = val;
  2554. }
  2555. });
  2556. return newMap;
  2557. }
  2558. function _hasAttrOrCss(knode, map) {
  2559. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2560. }
  2561. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2562. mapKey = mapKey || knode.name;
  2563. if (knode.type !== 1) {
  2564. return false;
  2565. }
  2566. var newMap = _singleKeyMap(map);
  2567. if (!newMap[mapKey]) {
  2568. return false;
  2569. }
  2570. var arr = newMap[mapKey].split(',');
  2571. for (var i = 0, len = arr.length; i < len; i++) {
  2572. var key = arr[i];
  2573. if (key === '*') {
  2574. return true;
  2575. }
  2576. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2577. var method = match[1] ? 'css' : 'attr';
  2578. key = match[2];
  2579. var val = match[3] || '';
  2580. if (val === '' && knode[method](key) !== '') {
  2581. return true;
  2582. }
  2583. if (val !== '' && knode[method](key) === val) {
  2584. return true;
  2585. }
  2586. }
  2587. return false;
  2588. }
  2589. function _removeAttrOrCss(knode, map) {
  2590. if (knode.type != 1) {
  2591. return;
  2592. }
  2593. _removeAttrOrCssByKey(knode, map, '*');
  2594. _removeAttrOrCssByKey(knode, map);
  2595. }
  2596. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2597. mapKey = mapKey || knode.name;
  2598. if (knode.type !== 1) {
  2599. return;
  2600. }
  2601. var newMap = _singleKeyMap(map);
  2602. if (!newMap[mapKey]) {
  2603. return;
  2604. }
  2605. var arr = newMap[mapKey].split(','), allFlag = false;
  2606. for (var i = 0, len = arr.length; i < len; i++) {
  2607. var key = arr[i];
  2608. if (key === '*') {
  2609. allFlag = true;
  2610. break;
  2611. }
  2612. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2613. key = match[2];
  2614. if (match[1]) {
  2615. key = _toCamel(key);
  2616. if (knode[0].style[key]) {
  2617. knode[0].style[key] = '';
  2618. }
  2619. } else {
  2620. knode.removeAttr(key);
  2621. }
  2622. }
  2623. if (allFlag) {
  2624. knode.remove(true);
  2625. }
  2626. }
  2627. function _getInnerNode(knode) {
  2628. var inner = knode;
  2629. while (inner.first()) {
  2630. inner = inner.first();
  2631. }
  2632. return inner;
  2633. }
  2634. function _isEmptyNode(knode) {
  2635. if (knode.type != 1 || knode.isSingle()) {
  2636. return false;
  2637. }
  2638. return knode.html().replace(/<[^>]+>/g, '') === '';
  2639. }
  2640. function _mergeWrapper(a, b) {
  2641. a = a.clone(true);
  2642. var lastA = _getInnerNode(a), childA = a, merged = false;
  2643. while (b) {
  2644. while (childA) {
  2645. if (childA.name === b.name) {
  2646. _mergeAttrs(childA, b.attr(), b.css());
  2647. merged = true;
  2648. }
  2649. childA = childA.first();
  2650. }
  2651. if (!merged) {
  2652. lastA.append(b.clone(false));
  2653. }
  2654. merged = false;
  2655. b = b.first();
  2656. }
  2657. return a;
  2658. }
  2659. function _wrapNode(knode, wrapper) {
  2660. wrapper = wrapper.clone(true);
  2661. if (knode.type == 3) {
  2662. _getInnerNode(wrapper).append(knode.clone(false));
  2663. knode.replaceWith(wrapper);
  2664. return wrapper;
  2665. }
  2666. var nodeWrapper = knode, child;
  2667. while ((child = knode.first()) && child.children().length == 1) {
  2668. knode = child;
  2669. }
  2670. child = knode.first();
  2671. var frag = knode.doc.createDocumentFragment();
  2672. while (child) {
  2673. frag.appendChild(child[0]);
  2674. child = child.next();
  2675. }
  2676. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2677. if (frag.firstChild) {
  2678. _getInnerNode(wrapper).append(frag);
  2679. }
  2680. nodeWrapper.replaceWith(wrapper);
  2681. return wrapper;
  2682. }
  2683. function _mergeAttrs(knode, attrs, styles) {
  2684. _each(attrs, function(key, val) {
  2685. if (key !== 'style') {
  2686. knode.attr(key, val);
  2687. }
  2688. });
  2689. _each(styles, function(key, val) {
  2690. knode.css(key, val);
  2691. });
  2692. }
  2693. function _inPreElement(knode) {
  2694. while (knode && knode.name != 'body') {
  2695. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2696. return true;
  2697. }
  2698. knode = knode.parent();
  2699. }
  2700. return false;
  2701. }
  2702. function KCmd(range) {
  2703. this.init(range);
  2704. }
  2705. _extend(KCmd, {
  2706. init : function(range) {
  2707. var self = this, doc = range.doc;
  2708. self.doc = doc;
  2709. self.win = _getWin(doc);
  2710. self.sel = _getSel(doc);
  2711. self.range = range;
  2712. },
  2713. selection : function(forceReset) {
  2714. var self = this, doc = self.doc, rng = _getRng(doc);
  2715. self.sel = _getSel(doc);
  2716. if (rng) {
  2717. self.range = _range(rng);
  2718. if (K(self.range.startContainer).name == 'html') {
  2719. self.range.selectNodeContents(doc.body).collapse(false);
  2720. }
  2721. return self;
  2722. }
  2723. if (forceReset) {
  2724. self.range.selectNodeContents(doc.body).collapse(false);
  2725. }
  2726. return self;
  2727. },
  2728. select : function(hasDummy) {
  2729. hasDummy = _undef(hasDummy, true);
  2730. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2731. sc = range.startContainer, so = range.startOffset,
  2732. ec = range.endContainer, eo = range.endOffset,
  2733. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2734. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2735. if (_IERANGE) {
  2736. var dummy = K('<span>&nbsp;</span>', doc);
  2737. range.insertNode(dummy[0]);
  2738. rng = doc.body.createTextRange();
  2739. try {
  2740. rng.moveToElementText(dummy[0]);
  2741. } catch(ex) {}
  2742. rng.collapse(false);
  2743. rng.select();
  2744. dummy.remove();
  2745. win.focus();
  2746. return self;
  2747. }
  2748. if (_WEBKIT) {
  2749. var children = sc.childNodes;
  2750. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2751. range.insertNode(doc.createTextNode('\u200B'));
  2752. hasU200b = true;
  2753. }
  2754. }
  2755. }
  2756. if (_IERANGE) {
  2757. try {
  2758. rng = range.get(true);
  2759. rng.select();
  2760. } catch(e) {}
  2761. } else {
  2762. if (hasU200b) {
  2763. range.collapse(false);
  2764. }
  2765. rng = range.get(true);
  2766. sel.removeAllRanges();
  2767. sel.addRange(rng);
  2768. if (doc !== document) {
  2769. var pos = K(rng.endContainer).pos();
  2770. //win.scrollTo(pos.x, pos.y);
  2771. }
  2772. }
  2773. win.focus();
  2774. return self;
  2775. },
  2776. wrap : function(val) {
  2777. var self = this, doc = self.doc, range = self.range, wrapper;
  2778. wrapper = K(val, doc);
  2779. if (range.collapsed) {
  2780. range.shrink();
  2781. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2782. return self;
  2783. }
  2784. if (wrapper.isBlock()) {
  2785. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2786. while (child.first()) {
  2787. child = child.first();
  2788. }
  2789. child.append(range.extractContents());
  2790. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2791. return self;
  2792. }
  2793. range.enlarge();
  2794. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2795. K(ancestor).scan(function(node) {
  2796. if (!isStart && node == bookmark.start) {
  2797. isStart = true;
  2798. return;
  2799. }
  2800. if (isStart) {
  2801. if (node == bookmark.end) {
  2802. return false;
  2803. }
  2804. var knode = K(node);
  2805. if (_inPreElement(knode)) {
  2806. return;
  2807. }
  2808. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2809. var parent;
  2810. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2811. knode = parent;
  2812. }
  2813. _wrapNode(knode, wrapper);
  2814. }
  2815. }
  2816. });
  2817. range.moveToBookmark(bookmark);
  2818. return self;
  2819. },
  2820. split : function(isStart, map) {
  2821. var range = this.range, doc = range.doc;
  2822. var tempRange = range.cloneRange().collapse(isStart);
  2823. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2824. parent = node.nodeType == 3 ? node.parentNode : node,
  2825. needSplit = false, knode;
  2826. while (parent && parent.parentNode) {
  2827. knode = K(parent);
  2828. if (map) {
  2829. if (!knode.isStyle()) {
  2830. break;
  2831. }
  2832. if (!_hasAttrOrCss(knode, map)) {
  2833. break;
  2834. }
  2835. } else {
  2836. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2837. break;
  2838. }
  2839. }
  2840. needSplit = true;
  2841. parent = parent.parentNode;
  2842. }
  2843. if (needSplit) {
  2844. var dummy = doc.createElement('span');
  2845. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2846. if (isStart) {
  2847. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2848. } else {
  2849. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2850. }
  2851. var frag = tempRange.extractContents(),
  2852. first = frag.firstChild, last = frag.lastChild;
  2853. if (isStart) {
  2854. tempRange.insertNode(frag);
  2855. range.setStartAfter(last).setEndBefore(dummy);
  2856. } else {
  2857. parent.appendChild(frag);
  2858. range.setStartBefore(dummy).setEndBefore(first);
  2859. }
  2860. var dummyParent = dummy.parentNode;
  2861. if (dummyParent == range.endContainer) {
  2862. var prev = K(dummy).prev(), next = K(dummy).next();
  2863. if (prev && next && prev.type == 3 && next.type == 3) {
  2864. range.setEnd(prev[0], prev[0].nodeValue.length);
  2865. } else if (!isStart) {
  2866. range.setEnd(range.endContainer, range.endOffset - 1);
  2867. }
  2868. }
  2869. dummyParent.removeChild(dummy);
  2870. }
  2871. return this;
  2872. },
  2873. remove : function(map) {
  2874. var self = this, doc = self.doc, range = self.range;
  2875. range.enlarge();
  2876. if (range.startOffset === 0) {
  2877. var ksc = K(range.startContainer), parent;
  2878. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2879. ksc = parent;
  2880. }
  2881. range.setStart(ksc[0], 0);
  2882. ksc = K(range.startContainer);
  2883. if (ksc.isBlock()) {
  2884. _removeAttrOrCss(ksc, map);
  2885. }
  2886. var kscp = ksc.parent();
  2887. if (kscp && kscp.isBlock()) {
  2888. _removeAttrOrCss(kscp, map);
  2889. }
  2890. }
  2891. var sc, so;
  2892. if (range.collapsed) {
  2893. self.split(true, map);
  2894. sc = range.startContainer;
  2895. so = range.startOffset;
  2896. if (so > 0) {
  2897. var sb = K(sc.childNodes[so - 1]);
  2898. if (sb && _isEmptyNode(sb)) {
  2899. sb.remove();
  2900. range.setStart(sc, so - 1);
  2901. }
  2902. }
  2903. var sa = K(sc.childNodes[so]);
  2904. if (sa && _isEmptyNode(sa)) {
  2905. sa.remove();
  2906. }
  2907. if (_isEmptyNode(sc)) {
  2908. range.startBefore(sc);
  2909. sc.remove();
  2910. }
  2911. range.collapse(true);
  2912. return self;
  2913. }
  2914. self.split(true, map);
  2915. self.split(false, map);
  2916. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2917. range.cloneRange().collapse(false).insertNode(endDummy);
  2918. range.cloneRange().collapse(true).insertNode(startDummy);
  2919. var nodeList = [], cmpStart = false;
  2920. K(range.commonAncestor()).scan(function(node) {
  2921. if (!cmpStart && node == startDummy) {
  2922. cmpStart = true;
  2923. return;
  2924. }
  2925. if (node == endDummy) {
  2926. return false;
  2927. }
  2928. if (cmpStart) {
  2929. nodeList.push(node);
  2930. }
  2931. });
  2932. K(startDummy).remove();
  2933. K(endDummy).remove();
  2934. sc = range.startContainer;
  2935. so = range.startOffset;
  2936. var ec = range.endContainer, eo = range.endOffset;
  2937. if (so > 0) {
  2938. var startBefore = K(sc.childNodes[so - 1]);
  2939. if (startBefore && _isEmptyNode(startBefore)) {
  2940. startBefore.remove();
  2941. range.setStart(sc, so - 1);
  2942. if (sc == ec) {
  2943. range.setEnd(ec, eo - 1);
  2944. }
  2945. }
  2946. var startAfter = K(sc.childNodes[so]);
  2947. if (startAfter && _isEmptyNode(startAfter)) {
  2948. startAfter.remove();
  2949. if (sc == ec) {
  2950. range.setEnd(ec, eo - 1);
  2951. }
  2952. }
  2953. }
  2954. var endAfter = K(ec.childNodes[range.endOffset]);
  2955. if (endAfter && _isEmptyNode(endAfter)) {
  2956. endAfter.remove();
  2957. }
  2958. var bookmark = range.createBookmark(true);
  2959. _each(nodeList, function(i, node) {
  2960. _removeAttrOrCss(K(node), map);
  2961. });
  2962. range.moveToBookmark(bookmark);
  2963. return self;
  2964. },
  2965. commonNode : function(map) {
  2966. var range = this.range;
  2967. var ec = range.endContainer, eo = range.endOffset,
  2968. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2969. function find(node) {
  2970. var child = node, parent = node;
  2971. while (parent) {
  2972. if (_hasAttrOrCss(K(parent), map)) {
  2973. return K(parent);
  2974. }
  2975. parent = parent.parentNode;
  2976. }
  2977. while (child && (child = child.lastChild)) {
  2978. if (_hasAttrOrCss(K(child), map)) {
  2979. return K(child);
  2980. }
  2981. }
  2982. return null;
  2983. }
  2984. var cNode = find(node);
  2985. if (cNode) {
  2986. return cNode;
  2987. }
  2988. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2989. var prev = K(node).prev();
  2990. if (prev) {
  2991. return find(prev);
  2992. }
  2993. }
  2994. return null;
  2995. },
  2996. commonAncestor : function(tagName) {
  2997. var range = this.range,
  2998. sc = range.startContainer, so = range.startOffset,
  2999. ec = range.endContainer, eo = range.endOffset,
  3000. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3001. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3002. function find(node) {
  3003. while (node) {
  3004. if (node.nodeType == 1) {
  3005. if (node.tagName.toLowerCase() === tagName) {
  3006. return node;
  3007. }
  3008. }
  3009. node = node.parentNode;
  3010. }
  3011. return null;
  3012. }
  3013. var start = find(startNode), end = find(endNode);
  3014. if (start && end && start === end) {
  3015. return K(start);
  3016. }
  3017. return null;
  3018. },
  3019. state : function(key) {
  3020. var self = this, doc = self.doc, bool = false;
  3021. try {
  3022. bool = doc.queryCommandState(key);
  3023. } catch (e) {}
  3024. return bool;
  3025. },
  3026. val : function(key) {
  3027. var self = this, doc = self.doc, range = self.range;
  3028. function lc(val) {
  3029. return val.toLowerCase();
  3030. }
  3031. key = lc(key);
  3032. var val = '', knode;
  3033. if (key === 'fontfamily' || key === 'fontname') {
  3034. val = _nativeCommandValue(doc, 'fontname');
  3035. val = val.replace(/['"]/g, '');
  3036. return lc(val);
  3037. }
  3038. if (key === 'formatblock') {
  3039. val = _nativeCommandValue(doc, key);
  3040. if (val === '') {
  3041. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3042. if (knode) {
  3043. val = knode.name;
  3044. }
  3045. }
  3046. if (val === 'Normal') {
  3047. val = 'p';
  3048. }
  3049. return lc(val);
  3050. }
  3051. if (key === 'fontsize') {
  3052. knode = self.commonNode({'*' : '.font-size'});
  3053. if (knode) {
  3054. val = knode.css('font-size');
  3055. }
  3056. return lc(val);
  3057. }
  3058. if (key === 'fontheight') {
  3059. knode = self.commonNode({'*' : '.letter-spacing'});
  3060. if (knode) {
  3061. val = knode.css('letter-spacing');
  3062. }
  3063. return lc(val);
  3064. }
  3065. if (key === 'forecolor') {
  3066. knode = self.commonNode({'*' : '.color'});
  3067. if (knode) {
  3068. val = knode.css('color');
  3069. }
  3070. val = _toHex(val);
  3071. if (val === '') {
  3072. val = 'default';
  3073. }
  3074. return lc(val);
  3075. }
  3076. if (key === 'hilitecolor') {
  3077. knode = self.commonNode({'*' : '.background-color'});
  3078. if (knode) {
  3079. val = knode.css('background-color');
  3080. }
  3081. val = _toHex(val);
  3082. if (val === '') {
  3083. val = 'default';
  3084. }
  3085. return lc(val);
  3086. }
  3087. return val;
  3088. },
  3089. toggle : function(wrapper, map) {
  3090. var self = this;
  3091. if (self.commonNode(map)) {
  3092. self.remove(map);
  3093. } else {
  3094. self.wrap(wrapper);
  3095. }
  3096. return self.select();
  3097. },
  3098. bold : function() {
  3099. return this.toggle('<strong></strong>', {
  3100. span : '.font-weight=bold',
  3101. strong : '*',
  3102. b : '*'
  3103. });
  3104. },
  3105. italic : function() {
  3106. return this.toggle('<em></em>', {
  3107. span : '.font-style=italic',
  3108. em : '*',
  3109. i : '*'
  3110. });
  3111. },
  3112. underline : function() {
  3113. return this.toggle('<u></u>', {
  3114. span : '.text-decoration=underline',
  3115. u : '*'
  3116. });
  3117. },
  3118. strikethrough : function() {
  3119. return this.toggle('<s></s>', {
  3120. span : '.text-decoration=line-through',
  3121. s : '*'
  3122. });
  3123. },
  3124. forecolor : function(val) {
  3125. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3126. },
  3127. hilitecolor : function(val) {
  3128. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3129. },
  3130. fontsize : function(val) {
  3131. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3132. },
  3133. fontheight : function(val) {
  3134. return this.wrap('<span style="letter-spacing:' + val + ';"></span>').select();
  3135. },
  3136. fontname : function(val) {
  3137. return this.fontfamily(val);
  3138. },
  3139. fontfamily : function(val) {
  3140. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3141. },
  3142. removeformat : function() {
  3143. var map = {
  3144. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3145. },
  3146. tags = _STYLE_TAG_MAP;
  3147. _each(tags, function(key, val) {
  3148. map[key] = '*';
  3149. });
  3150. this.remove(map);
  3151. return this.select();
  3152. },
  3153. inserthtml : function(val, quickMode) {
  3154. var self = this, range = self.range;
  3155. if (val === '') {
  3156. return self;
  3157. }
  3158. function pasteHtml(range, val) {
  3159. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3160. var rng = range.get();
  3161. if (rng.item) {
  3162. rng.item(0).outerHTML = val;
  3163. } else {
  3164. rng.pasteHTML(val);
  3165. }
  3166. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3167. temp.parentNode.removeChild(temp);
  3168. var newRange = _toRange(rng);
  3169. range.setEnd(newRange.endContainer, newRange.endOffset);
  3170. range.collapse(false);
  3171. self.select(false);
  3172. }
  3173. function insertHtml(range, val) {
  3174. var doc = range.doc,
  3175. frag = doc.createDocumentFragment();
  3176. K('@' + val, doc).each(function() {
  3177. frag.appendChild(this);
  3178. });
  3179. range.deleteContents();
  3180. range.insertNode(frag);
  3181. range.collapse(false);
  3182. self.select(false);
  3183. }
  3184. if (_IERANGE && quickMode) {
  3185. try {
  3186. pasteHtml(range, val);
  3187. } catch(e) {
  3188. insertHtml(range, val);
  3189. }
  3190. return self;
  3191. }
  3192. insertHtml(range, val);
  3193. return self;
  3194. },
  3195. hr : function() {
  3196. return this.inserthtml('<hr />');
  3197. },
  3198. print : function() {
  3199. this.win.print();
  3200. return this;
  3201. },
  3202. insertimage : function(url, title, width, height, border, align) {
  3203. title = _undef(title, '');
  3204. border = _undef(border, 0);
  3205. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3206. if (width) {
  3207. html += 'width="' + _escape(width) + '" ';
  3208. }
  3209. if (height) {
  3210. html += 'height="' + _escape(height) + '" ';
  3211. }
  3212. if (title) {
  3213. html += 'title="' + _escape(title) + '" ';
  3214. }
  3215. if (align) {
  3216. html += 'align="' + _escape(align) + '" ';
  3217. }
  3218. html += 'alt="' + _escape(title) + '" ';
  3219. html += '/>';
  3220. return this.inserthtml(html);
  3221. },
  3222. createlink : function(url, type) {
  3223. var self = this, doc = self.doc, range = self.range;
  3224. self.select();
  3225. var a = self.commonNode({ a : '*' });
  3226. if (a && !range.isControl()) {
  3227. range.selectNode(a.get());
  3228. self.select();
  3229. }
  3230. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3231. if (type) {
  3232. html += ' target="' + _escape(type) + '"';
  3233. }
  3234. if (range.collapsed) {
  3235. html += '>' + _escape(url) + '</a>';
  3236. return self.inserthtml(html);
  3237. }
  3238. if (range.isControl()) {
  3239. var node = K(range.startContainer.childNodes[range.startOffset]);
  3240. html += '></a>';
  3241. node.after(K(html, doc));
  3242. node.next().append(node);
  3243. range.selectNode(node[0]);
  3244. return self.select();
  3245. }
  3246. function setAttr(node, url, type) {
  3247. K(node).attr('href', url).attr('data-ke-src', url);
  3248. if (type) {
  3249. K(node).attr('target', type);
  3250. } else {
  3251. K(node).removeAttr('target');
  3252. }
  3253. }
  3254. var sc = range.startContainer, so = range.startOffset,
  3255. ec = range.endContainer, eo = range.endOffset;
  3256. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3257. var child = sc.childNodes[so];
  3258. if (child.nodeName.toLowerCase() == 'a') {
  3259. setAttr(child, url, type);
  3260. return self;
  3261. }
  3262. }
  3263. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3264. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3265. setAttr(this, url, type);
  3266. });
  3267. return self;
  3268. },
  3269. unlink : function() {
  3270. var self = this, doc = self.doc, range = self.range;
  3271. self.select();
  3272. if (range.collapsed) {
  3273. var a = self.commonNode({ a : '*' });
  3274. if (a) {
  3275. range.selectNode(a.get());
  3276. self.select();
  3277. }
  3278. _nativeCommand(doc, 'unlink', null);
  3279. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3280. var parent = K(range.startContainer).parent();
  3281. if (parent.name === 'a') {
  3282. parent.remove(true);
  3283. }
  3284. }
  3285. } else {
  3286. _nativeCommand(doc, 'unlink', null);
  3287. }
  3288. return self;
  3289. }
  3290. });
  3291. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3292. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3293. KCmd.prototype[name] = function(val) {
  3294. var self = this;
  3295. self.select();
  3296. _nativeCommand(self.doc, name, val);
  3297. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3298. self.selection();
  3299. }
  3300. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3301. self.selection();
  3302. }
  3303. return self;
  3304. };
  3305. });
  3306. _each('cut,copy,paste'.split(','), function(i, name) {
  3307. KCmd.prototype[name] = function() {
  3308. var self = this;
  3309. if (!self.doc.queryCommandSupported(name)) {
  3310. throw 'not supported';
  3311. }
  3312. self.select();
  3313. _nativeCommand(self.doc, name, null);
  3314. return self;
  3315. };
  3316. });
  3317. function _cmd(mixed) {
  3318. if (mixed.nodeName) {
  3319. var doc = _getDoc(mixed);
  3320. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3321. }
  3322. return new KCmd(mixed);
  3323. }
  3324. K.CmdClass = KCmd;
  3325. K.cmd = _cmd;
  3326. function _drag(options) {
  3327. var moveEl = options.moveEl,
  3328. moveFn = options.moveFn,
  3329. clickEl = options.clickEl || moveEl,
  3330. beforeDrag = options.beforeDrag,
  3331. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3332. var docs = [document];
  3333. if (iframeFix) {
  3334. K('iframe').each(function() {
  3335. var src = _formatUrl(this.src || '', 'absolute');
  3336. if (/^https?:\/\//.test(src)) {
  3337. return;
  3338. }
  3339. var doc;
  3340. try {
  3341. doc = _iframeDoc(this);
  3342. } catch(e) {}
  3343. if (doc) {
  3344. var pos = K(this).pos();
  3345. K(doc).data('pos-x', pos.x);
  3346. K(doc).data('pos-y', pos.y);
  3347. docs.push(doc);
  3348. }
  3349. });
  3350. }
  3351. clickEl.mousedown(function(e) {
  3352. if(e.button !== 0 && e.button !== 1) {
  3353. return;
  3354. }
  3355. e.stopPropagation();
  3356. var self = clickEl.get(),
  3357. x = _removeUnit(moveEl.css('left')),
  3358. y = _removeUnit(moveEl.css('top')),
  3359. width = moveEl.width(),
  3360. height = moveEl.height(),
  3361. pageX = e.pageX,
  3362. pageY = e.pageY;
  3363. if (beforeDrag) {
  3364. beforeDrag();
  3365. }
  3366. function moveListener(e) {
  3367. e.preventDefault();
  3368. var kdoc = K(_getDoc(e.target));
  3369. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3370. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3371. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3372. }
  3373. function selectListener(e) {
  3374. e.preventDefault();
  3375. }
  3376. function upListener(e) {
  3377. e.preventDefault();
  3378. K(docs).unbind('mousemove', moveListener)
  3379. .unbind('mouseup', upListener)
  3380. .unbind('selectstart', selectListener);
  3381. if (self.releaseCapture) {
  3382. self.releaseCapture();
  3383. }
  3384. }
  3385. K(docs).mousemove(moveListener)
  3386. .mouseup(upListener)
  3387. .bind('selectstart', selectListener);
  3388. if (self.setCapture) {
  3389. self.setCapture();
  3390. }
  3391. });
  3392. }
  3393. function KWidget(options) {
  3394. this.init(options);
  3395. }
  3396. _extend(KWidget, {
  3397. init : function(options) {
  3398. var self = this;
  3399. self.name = options.name || '';
  3400. self.doc = options.doc || document;
  3401. self.win = _getWin(self.doc);
  3402. self.x = _addUnit(options.x);
  3403. self.y = _addUnit(options.y);
  3404. self.z = options.z;
  3405. self.width = _addUnit(options.width);
  3406. self.height = _addUnit(options.height);
  3407. self.index = _addUnit(options.index);
  3408. self.div = K('<div style="display:block;"></div>');
  3409. self.options = options;
  3410. self._alignEl = options.alignEl;
  3411. if (self.width) {
  3412. self.div.css('width', self.width);
  3413. }
  3414. if (self.height) {
  3415. self.div.css('height', self.height);
  3416. }
  3417. if (self.z) {
  3418. self.div.css({
  3419. position : 'absolute',
  3420. left : self.x,
  3421. top : self.y,
  3422. 'z-index' : self.z
  3423. });
  3424. }
  3425. if (self.z && (self.x === undefined || self.y === undefined)) {
  3426. self.autoPos(self.width, self.height);
  3427. }
  3428. if (options.cls) {
  3429. self.div.addClass(options.cls);
  3430. }
  3431. if (options.shadowMode) {
  3432. self.div.addClass('ke-shadow');
  3433. }
  3434. if (options.css) {
  3435. self.div.css(options.css);
  3436. }
  3437. if (options.src) {
  3438. K(options.src).replaceWith(self.div);
  3439. } else {
  3440. K(self.doc.body).append(self.div);
  3441. }
  3442. if (options.html) {
  3443. self.div.html(options.html);
  3444. }
  3445. if (options.autoScroll) {
  3446. if (_IE && _V < 7 || _QUIRKS) {
  3447. var scrollPos = _getScrollPos();
  3448. K(self.win).bind('scroll', function(e) {
  3449. var pos = _getScrollPos(),
  3450. diffX = pos.x - scrollPos.x,
  3451. diffY = pos.y - scrollPos.y;
  3452. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3453. });
  3454. } else {
  3455. self.div.css('position', 'fixed');
  3456. }
  3457. }
  3458. },
  3459. pos : function(x, y, updateProp) {
  3460. var self = this;
  3461. updateProp = _undef(updateProp, true);
  3462. if (x !== null) {
  3463. x = x < 0 ? 0 : _addUnit(x);
  3464. self.div.css('left', x);
  3465. if (updateProp) {
  3466. self.x = x;
  3467. }
  3468. }
  3469. if (y !== null) {
  3470. y = y < 0 ? 0 : _addUnit(y);
  3471. self.div.css('top', y);
  3472. if (updateProp) {
  3473. self.y = y;
  3474. }
  3475. }
  3476. return self;
  3477. },
  3478. autoPos : function(width, height) {
  3479. var x, y, self = this,
  3480. w = _removeUnit(width) || 0,
  3481. h = _removeUnit(height) || 0,
  3482. scrollPos = _getScrollPos();
  3483. if (self._alignEl) {
  3484. var knode = K(self._alignEl),
  3485. pos = knode.pos(),
  3486. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3487. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3488. x = diffX < 0 ? pos.x : pos.x + diffX;
  3489. y = diffY < 0 ? pos.y : pos.y + diffY;
  3490. } else {
  3491. var docEl = _docElement(self.doc);
  3492. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3493. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3494. }
  3495. if (!(_IE && _V < 7 || _QUIRKS)) {
  3496. x -= scrollPos.x;
  3497. y -= scrollPos.y;
  3498. }
  3499. return self.pos(x, y);
  3500. },
  3501. remove : function() {
  3502. var self = this;
  3503. if (_IE && _V < 7 || _QUIRKS) {
  3504. K(self.win).unbind('scroll');
  3505. }
  3506. self.div.remove();
  3507. _each(self, function(i) {
  3508. self[i] = null;
  3509. });
  3510. return this;
  3511. },
  3512. show : function() {
  3513. this.div.show();
  3514. return this;
  3515. },
  3516. hide : function() {
  3517. this.div.hide();
  3518. return this;
  3519. },
  3520. draggable : function(options) {
  3521. var self = this;
  3522. options = options || {};
  3523. options.moveEl = self.div;
  3524. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3525. if ((x = x + diffX) < 0) {
  3526. x = 0;
  3527. }
  3528. if ((y = y + diffY) < 0) {
  3529. y = 0;
  3530. }
  3531. self.pos(x, y);
  3532. };
  3533. _drag(options);
  3534. return self;
  3535. }
  3536. });
  3537. function _widget(options) {
  3538. return new KWidget(options);
  3539. }
  3540. K.WidgetClass = KWidget;
  3541. K.widget = _widget;
  3542. function _iframeDoc(iframe) {
  3543. iframe = _get(iframe);
  3544. return iframe.contentDocument || iframe.contentWindow.document;
  3545. }
  3546. var html, _direction = '';
  3547. if ((html = document.getElementsByTagName('html'))) {
  3548. _direction = html[0].dir;
  3549. }
  3550. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3551. var arr = [
  3552. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3553. '<head><meta charset="utf-8" /><title></title>',
  3554. '<style>',
  3555. 'html {margin:0;padding:0;}',
  3556. 'body {margin:0;padding:5px;}',
  3557. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3558. 'body, p, div {word-wrap: break-word;}',
  3559. 'p {margin:5px 0;}',
  3560. 'table {border-collapse:collapse;}',
  3561. 'img {border:0;}',
  3562. 'noscript {display:none;}',
  3563. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3564. 'img.ke-flash {',
  3565. ' border:1px solid #AAA;',
  3566. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3567. ' background-position:center center;',
  3568. ' background-repeat:no-repeat;',
  3569. ' width:100px;',
  3570. ' height:100px;',
  3571. '}',
  3572. 'img.ke-rm {',
  3573. ' border:1px solid #AAA;',
  3574. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3575. ' background-position:center center;',
  3576. ' background-repeat:no-repeat;',
  3577. ' width:100px;',
  3578. ' height:100px;',
  3579. '}',
  3580. 'img.ke-media {',
  3581. ' border:1px solid #AAA;',
  3582. ' background-image:url(' + themesPath + 'common/media.gif);',
  3583. ' background-position:center center;',
  3584. ' background-repeat:no-repeat;',
  3585. ' width:100px;',
  3586. ' height:100px;',
  3587. '}',
  3588. 'img.ke-anchor {',
  3589. ' border:1px dashed #666;',
  3590. ' width:16px;',
  3591. ' height:16px;',
  3592. '}',
  3593. '.ke-script, .ke-noscript, .ke-display-none {',
  3594. ' display:none;',
  3595. ' font-size:0;',
  3596. ' width:0;',
  3597. ' height:0;',
  3598. '}',
  3599. '.ke-pagebreak {',
  3600. ' border:1px dotted #AAA;',
  3601. ' font-size:0;',
  3602. ' height:2px;',
  3603. '}',
  3604. '</style>'
  3605. ];
  3606. if (!_isArray(cssPath)) {
  3607. cssPath = [cssPath];
  3608. }
  3609. _each(cssPath, function(i, path) {
  3610. if (path) {
  3611. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3612. }
  3613. });
  3614. if (cssData) {
  3615. arr.push('<style>' + cssData + '</style>');
  3616. }
  3617. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3618. return arr.join('\n');
  3619. }
  3620. function _elementVal(knode, val) {
  3621. if (knode.hasVal()) {
  3622. if (val === undefined) {
  3623. var html = knode.val();
  3624. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3625. return html;
  3626. }
  3627. return knode.val(val);
  3628. }
  3629. return knode.html(val);
  3630. }
  3631. function KEdit(options) {
  3632. this.init(options);
  3633. }
  3634. _extend(KEdit, KWidget, {
  3635. init : function(options) {
  3636. var self = this;
  3637. KEdit.parent.init.call(self, options);
  3638. self.srcElement = K(options.srcElement);
  3639. self.div.addClass('ke-edit');
  3640. self.designMode = _undef(options.designMode, true);
  3641. self.beforeGetHtml = options.beforeGetHtml;
  3642. self.beforeSetHtml = options.beforeSetHtml;
  3643. self.afterSetHtml = options.afterSetHtml;
  3644. var themesPath = _undef(options.themesPath, ''),
  3645. bodyClass = options.bodyClass,
  3646. cssPath = options.cssPath,
  3647. cssData = options.cssData,
  3648. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3649. srcScript = ('document.open();' +
  3650. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3651. 'document.close();'),
  3652. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3653. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3654. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3655. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3656. self.iframe.attr('tabindex', self.tabIndex);
  3657. self.textarea.attr('tabindex', self.tabIndex);
  3658. if (self.width) {
  3659. self.setWidth(self.width);
  3660. }
  3661. if (self.height) {
  3662. self.setHeight(self.height);
  3663. }
  3664. if (self.designMode) {
  3665. self.textarea.hide();
  3666. } else {
  3667. self.iframe.hide();
  3668. }
  3669. function ready() {
  3670. var doc = _iframeDoc(self.iframe);
  3671. doc.open();
  3672. if (isDocumentDomain) {
  3673. doc.domain = document.domain;
  3674. }
  3675. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3676. doc.close();
  3677. self.win = self.iframe[0].contentWindow;
  3678. self.doc = doc;
  3679. var cmd = _cmd(doc);
  3680. self.afterChange(function(e) {
  3681. cmd.selection();
  3682. });
  3683. if (_WEBKIT) {
  3684. K(doc).click(function(e) {
  3685. if (K(e.target).name === 'img') {
  3686. cmd.selection(true);
  3687. cmd.range.selectNode(e.target);
  3688. cmd.select();
  3689. }
  3690. });
  3691. }
  3692. if (_IE) {
  3693. self._mousedownHandler = function() {
  3694. var newRange = cmd.range.cloneRange();
  3695. newRange.shrink();
  3696. if (newRange.isControl()) {
  3697. self.blur();
  3698. }
  3699. };
  3700. K(document).mousedown(self._mousedownHandler);
  3701. K(doc).keydown(function(e) {
  3702. if (e.which == 8) {
  3703. cmd.selection();
  3704. var rng = cmd.range;
  3705. if (rng.isControl()) {
  3706. rng.collapse(true);
  3707. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3708. e.preventDefault();
  3709. }
  3710. }
  3711. });
  3712. }
  3713. self.cmd = cmd;
  3714. self.html(_elementVal(self.srcElement));
  3715. if (_IE) {
  3716. doc.body.disabled = true;
  3717. doc.body.contentEditable = true;
  3718. doc.body.removeAttribute('disabled');
  3719. } else {
  3720. doc.designMode = 'on';
  3721. }
  3722. if (options.afterCreate) {
  3723. options.afterCreate.call(self);
  3724. }
  3725. }
  3726. if (isDocumentDomain) {
  3727. self.iframe.bind('load', function(e) {
  3728. self.iframe.unbind('load');
  3729. if (_IE) {
  3730. ready();
  3731. } else {
  3732. setTimeout(ready, 0);
  3733. }
  3734. });
  3735. }
  3736. self.div.append(self.iframe);
  3737. self.div.append(self.textarea);
  3738. self.srcElement.hide();
  3739. !isDocumentDomain && ready();
  3740. },
  3741. setWidth : function(val) {
  3742. var self = this;
  3743. val = _addUnit(val);
  3744. self.width = val;
  3745. self.div.css('width', val);
  3746. return self;
  3747. },
  3748. setHeight : function(val) {
  3749. var self = this;
  3750. val = _addUnit(val);
  3751. self.height = val;
  3752. self.div.css('height', val);
  3753. self.iframe.css('height', val);
  3754. if ((_IE && _V < 8) || _QUIRKS) {
  3755. val = _addUnit(_removeUnit(val) - 2);
  3756. }
  3757. self.textarea.css('height', val);
  3758. return self;
  3759. },
  3760. remove : function() {
  3761. var self = this, doc = self.doc;
  3762. K(doc.body).unbind();
  3763. K(doc).unbind();
  3764. K(self.win).unbind();
  3765. if (self._mousedownHandler) {
  3766. K(document).unbind('mousedown', self._mousedownHandler);
  3767. }
  3768. _elementVal(self.srcElement, self.html());
  3769. self.srcElement.show();
  3770. self.iframe.unbind();
  3771. self.textarea.unbind();
  3772. KEdit.parent.remove.call(self);
  3773. },
  3774. html : function(val, isFull) {
  3775. var self = this, doc = self.doc;
  3776. if (self.designMode) {
  3777. var body = doc.body;
  3778. if (val === undefined) {
  3779. if (isFull) {
  3780. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3781. } else {
  3782. val = body.innerHTML;
  3783. }
  3784. if (self.beforeGetHtml) {
  3785. val = self.beforeGetHtml(val);
  3786. }
  3787. if (_GECKO && val == '<br />') {
  3788. val = '';
  3789. }
  3790. return val;
  3791. }
  3792. if (self.beforeSetHtml) {
  3793. val = self.beforeSetHtml(val);
  3794. }
  3795. if (_IE && _V >= 9) {
  3796. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3797. }
  3798. K(body).html(val);
  3799. if (self.afterSetHtml) {
  3800. self.afterSetHtml();
  3801. }
  3802. return self;
  3803. }
  3804. if (val === undefined) {
  3805. return self.textarea.val();
  3806. }
  3807. self.textarea.val(val);
  3808. return self;
  3809. },
  3810. design : function(bool) {
  3811. var self = this, val;
  3812. if (bool === undefined ? !self.designMode : bool) {
  3813. if (!self.designMode) {
  3814. val = self.html();
  3815. self.designMode = true;
  3816. self.textarea.hide();
  3817. self.html(val);
  3818. var iframe = self.iframe;
  3819. var height = _removeUnit(self.height);
  3820. iframe.height(height - 2);
  3821. iframe.show();
  3822. setTimeout(function() {
  3823. iframe.height(height);
  3824. }, 0);
  3825. }
  3826. } else {
  3827. if (self.designMode) {
  3828. val = self.html();
  3829. self.designMode = false;
  3830. self.html(val);
  3831. self.iframe.hide();
  3832. self.textarea.show();
  3833. }
  3834. }
  3835. return self.focus();
  3836. },
  3837. focus : function() {
  3838. var self = this;
  3839. //self.designMode ? self.win.focus() : self.textarea[0].focus();
  3840. return self;
  3841. },
  3842. blur : function() {
  3843. var self = this;
  3844. if (_IE) {
  3845. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3846. self.div.append(input);
  3847. input[0].focus();
  3848. input.remove();
  3849. } else {
  3850. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3851. }
  3852. return self;
  3853. },
  3854. afterChange : function(fn) {
  3855. var self = this, doc = self.doc, body = doc.body;
  3856. K(doc).keyup(function(e) {
  3857. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3858. fn(e);
  3859. }
  3860. });
  3861. K(doc).mouseup(fn).contextmenu(fn);
  3862. K(self.win).blur(fn);
  3863. function timeoutHandler(e) {
  3864. setTimeout(function() {
  3865. fn(e);
  3866. }, 1);
  3867. }
  3868. K(body).bind('paste', timeoutHandler);
  3869. K(body).bind('cut', timeoutHandler);
  3870. return self;
  3871. }
  3872. });
  3873. function _edit(options) {
  3874. return new KEdit(options);
  3875. }
  3876. K.EditClass = KEdit;
  3877. K.edit = _edit;
  3878. K.iframeDoc = _iframeDoc;
  3879. function _selectToolbar(name, fn) {
  3880. var self = this,
  3881. knode = self.get(name);
  3882. if (knode) {
  3883. if (knode.hasClass('ke-disabled')) {
  3884. return;
  3885. }
  3886. fn(knode);
  3887. }
  3888. }
  3889. function KToolbar(options) {
  3890. this.init(options);
  3891. }
  3892. _extend(KToolbar, KWidget, {
  3893. init : function(options) {
  3894. var self = this;
  3895. KToolbar.parent.init.call(self, options);
  3896. self.disableMode = _undef(options.disableMode, false);
  3897. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3898. self._itemMap = {};
  3899. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3900. e.preventDefault();
  3901. }).attr('unselectable', 'on');
  3902. function find(target) {
  3903. var knode = K(target);
  3904. if (knode.hasClass('ke-outline')) {
  3905. return knode;
  3906. }
  3907. if (knode.hasClass('ke-toolbar-icon')) {
  3908. return knode.parent();
  3909. }
  3910. }
  3911. function hover(e, method) {
  3912. var knode = find(e.target);
  3913. if (knode) {
  3914. if (knode.hasClass('ke-disabled')) {
  3915. return;
  3916. }
  3917. if (knode.hasClass('ke-selected')) {
  3918. return;
  3919. }
  3920. knode[method]('ke-on');
  3921. }
  3922. }
  3923. self.div.mouseover(function(e) {
  3924. hover(e, 'addClass');
  3925. })
  3926. .mouseout(function(e) {
  3927. hover(e, 'removeClass');
  3928. })
  3929. .click(function(e) {
  3930. var knode = find(e.target);
  3931. if (knode) {
  3932. if (knode.hasClass('ke-disabled')) {
  3933. return;
  3934. }
  3935. self.options.click.call(this, e, knode.attr('data-name'));
  3936. }
  3937. });
  3938. },
  3939. get : function(name) {
  3940. if (this._itemMap[name]) {
  3941. return this._itemMap[name];
  3942. }
  3943. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3944. },
  3945. select : function(name) {
  3946. _selectToolbar.call(this, name, function(knode) {
  3947. knode.addClass('ke-selected');
  3948. });
  3949. return self;
  3950. },
  3951. unselect : function(name) {
  3952. _selectToolbar.call(this, name, function(knode) {
  3953. knode.removeClass('ke-selected').removeClass('ke-on');
  3954. });
  3955. return self;
  3956. },
  3957. enable : function(name) {
  3958. var self = this,
  3959. knode = name.get ? name : self.get(name);
  3960. if (knode) {
  3961. knode.removeClass('ke-disabled');
  3962. knode.opacity(1);
  3963. }
  3964. return self;
  3965. },
  3966. disable : function(name) {
  3967. var self = this,
  3968. knode = name.get ? name : self.get(name);
  3969. if (knode) {
  3970. knode.removeClass('ke-selected').addClass('ke-disabled');
  3971. knode.opacity(0.5);
  3972. }
  3973. return self;
  3974. },
  3975. disableAll : function(bool, noDisableItems) {
  3976. var self = this, map = self.noDisableItemMap, item;
  3977. if (noDisableItems) {
  3978. map = _toMap(noDisableItems);
  3979. }
  3980. if (bool === undefined ? !self.disableMode : bool) {
  3981. K('span.ke-outline', self.div).each(function() {
  3982. var knode = K(this),
  3983. name = knode[0].getAttribute('data-name', 2);
  3984. if (!map[name]) {
  3985. self.disable(knode);
  3986. }
  3987. });
  3988. self.disableMode = true;
  3989. } else {
  3990. K('span.ke-outline', self.div).each(function() {
  3991. var knode = K(this),
  3992. name = knode[0].getAttribute('data-name', 2);
  3993. if (!map[name]) {
  3994. self.enable(knode);
  3995. }
  3996. });
  3997. self.disableMode = false;
  3998. }
  3999. return self;
  4000. }
  4001. });
  4002. function _toolbar(options) {
  4003. return new KToolbar(options);
  4004. }
  4005. K.ToolbarClass = KToolbar;
  4006. K.toolbar = _toolbar;
  4007. function KMenu(options) {
  4008. this.init(options);
  4009. }
  4010. _extend(KMenu, KWidget, {
  4011. init : function(options) {
  4012. var self = this;
  4013. options.z = options.z || 811213;
  4014. KMenu.parent.init.call(self, options);
  4015. self.centerLineMode = _undef(options.centerLineMode, true);
  4016. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4017. e.stopPropagation();
  4018. }).attr('unselectable', 'on');
  4019. },
  4020. addItem : function(item) {
  4021. var self = this;
  4022. if (item.title === '-') {
  4023. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4024. return;
  4025. }
  4026. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4027. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4028. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4029. height = _addUnit(item.height),
  4030. iconClass = _undef(item.iconClass, '');
  4031. self.div.append(itemDiv);
  4032. if (height) {
  4033. itemDiv.css('height', height);
  4034. rightDiv.css('line-height', height);
  4035. }
  4036. var centerDiv;
  4037. if (self.centerLineMode) {
  4038. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4039. if (height) {
  4040. centerDiv.css('height', height);
  4041. }
  4042. }
  4043. itemDiv.mouseover(function(e) {
  4044. K(this).addClass('ke-menu-item-on');
  4045. if (centerDiv) {
  4046. centerDiv.addClass('ke-menu-item-center-on');
  4047. }
  4048. })
  4049. .mouseout(function(e) {
  4050. K(this).removeClass('ke-menu-item-on');
  4051. if (centerDiv) {
  4052. centerDiv.removeClass('ke-menu-item-center-on');
  4053. }
  4054. })
  4055. .click(function(e) {
  4056. item.click.call(K(this));
  4057. e.stopPropagation();
  4058. })
  4059. .append(leftDiv);
  4060. if (centerDiv) {
  4061. itemDiv.append(centerDiv);
  4062. }
  4063. itemDiv.append(rightDiv);
  4064. if (item.checked) {
  4065. iconClass = 'ke-icon-checked';
  4066. }
  4067. if (iconClass !== '') {
  4068. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4069. }
  4070. rightDiv.html(item.title);
  4071. return self;
  4072. },
  4073. remove : function() {
  4074. var self = this;
  4075. if (self.options.beforeRemove) {
  4076. self.options.beforeRemove.call(self);
  4077. }
  4078. K('.ke-menu-item', self.div[0]).unbind();
  4079. KMenu.parent.remove.call(self);
  4080. return self;
  4081. }
  4082. });
  4083. function _menu(options) {
  4084. return new KMenu(options);
  4085. }
  4086. K.MenuClass = KMenu;
  4087. K.menu = _menu;
  4088. function KColorPicker(options) {
  4089. this.init(options);
  4090. }
  4091. _extend(KColorPicker, KWidget, {
  4092. init : function(options) {
  4093. var self = this;
  4094. options.z = options.z || 811213;
  4095. KColorPicker.parent.init.call(self, options);
  4096. var colors = options.colors || [
  4097. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4098. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4099. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4100. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4101. ];
  4102. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4103. self._cells = [];
  4104. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4105. e.stopPropagation();
  4106. }).attr('unselectable', 'on');
  4107. var table = self.doc.createElement('table');
  4108. self.div.append(table);
  4109. table.className = 'ke-colorpicker-table';
  4110. table.cellPadding = 0;
  4111. table.cellSpacing = 0;
  4112. table.border = 0;
  4113. var row = table.insertRow(0), cell = row.insertCell(0);
  4114. cell.colSpan = colors[0].length;
  4115. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4116. for (var i = 0; i < colors.length; i++) {
  4117. row = table.insertRow(i + 1);
  4118. for (var j = 0; j < colors[i].length; j++) {
  4119. cell = row.insertCell(j);
  4120. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4121. }
  4122. }
  4123. },
  4124. _addAttr : function(cell, color, cls) {
  4125. var self = this;
  4126. cell = K(cell).addClass(cls);
  4127. if (self.selectedColor === color.toLowerCase()) {
  4128. cell.addClass('ke-colorpicker-cell-selected');
  4129. }
  4130. cell.attr('title', color || self.options.noColor);
  4131. cell.mouseover(function(e) {
  4132. K(this).addClass('ke-colorpicker-cell-on');
  4133. });
  4134. cell.mouseout(function(e) {
  4135. K(this).removeClass('ke-colorpicker-cell-on');
  4136. });
  4137. cell.click(function(e) {
  4138. e.stop();
  4139. self.options.click.call(K(this), color);
  4140. });
  4141. if (color) {
  4142. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4143. } else {
  4144. cell.html(self.options.noColor);
  4145. }
  4146. K(cell).attr('unselectable', 'on');
  4147. self._cells.push(cell);
  4148. },
  4149. remove : function() {
  4150. var self = this;
  4151. _each(self._cells, function() {
  4152. this.unbind();
  4153. });
  4154. KColorPicker.parent.remove.call(self);
  4155. return self;
  4156. }
  4157. });
  4158. function _colorpicker(options) {
  4159. return new KColorPicker(options);
  4160. }
  4161. K.ColorPickerClass = KColorPicker;
  4162. K.colorpicker = _colorpicker;
  4163. function KUploadButton(options) {
  4164. this.init(options);
  4165. }
  4166. _extend(KUploadButton, {
  4167. init : function(options) {
  4168. var self = this,
  4169. button = K(options.button),
  4170. fieldName = options.fieldName || 'file',
  4171. url = options.url || '',
  4172. title = button.val(),
  4173. extraParams = options.extraParams || {},
  4174. cls = button[0].className || '',
  4175. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4176. options.afterError = options.afterError || function(str) {
  4177. alert(str);
  4178. };
  4179. var hiddenElements = [];
  4180. for(var k in extraParams){
  4181. hiddenElements.push('<input type="hidden" class="ke-upload-file-'+k+'" name="' + k + '" value="' + extraParams[k] + '" />');
  4182. }
  4183. var html = [
  4184. '<div class="ke-inline-block ' + cls + '">',
  4185. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4186. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4187. '<span class="ke-button-common">',
  4188. hiddenElements.join(''),
  4189. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4190. '</span>',
  4191. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4192. (options.form ? '</div>' : '</form>'),
  4193. '</div>'].join('');
  4194. var div = K(html, button.doc);
  4195. button.hide();
  4196. button.before(div);
  4197. self.div = div;
  4198. self.button = button;
  4199. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4200. self.form = options.form ? K(options.form) : K('form', div);
  4201. self.fileBox = K('.ke-upload-file', div);
  4202. var width = options.width || K('.ke-button-common', div).width();
  4203. K('.ke-upload-area', div).width(width);
  4204. self.options = options;
  4205. },
  4206. submit : function(e) {
  4207. var self = this,
  4208. iframe = self.iframe;
  4209. e = false;
  4210. if (e) {
  4211. var file = e.files[0];
  4212. var filename = file.name;
  4213. var temp = filename.split('.');
  4214. //putExtra.params["x:name"] = temp[0];
  4215. var filename = hex_md5(file.name) + '.' + temp[temp.length-1];
  4216. var path = $('.' + 'ke-upload-file-key').val();
  4217. $('.' + 'ke-upload-file-key').val(path + filename);
  4218. //这里要修改 以后再改
  4219. } else {
  4220. iframe.bind('load', function() {
  4221. iframe.unbind();
  4222. var tempForm = document.createElement('form');
  4223. self.fileBox.before(tempForm);
  4224. K(tempForm).append(self.fileBox);
  4225. tempForm.reset();
  4226. K(tempForm).remove(true);
  4227. var doc = K.iframeDoc(iframe),
  4228. pre = doc.getElementsByTagName('pre')[0],
  4229. str = '', data;
  4230. if (pre) {
  4231. str = pre.innerHTML;
  4232. } else {
  4233. str = doc.body.innerHTML;
  4234. }
  4235. str = _unescape(str);
  4236. iframe[0].src = 'javascript:false';
  4237. try {
  4238. data = K.json(str);
  4239. } catch (e) {
  4240. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4241. }
  4242. if (data) {
  4243. self.options.afterUpload.call(self, data);
  4244. }
  4245. });
  4246. self.form[0].submit();
  4247. }
  4248. self.form[0].submit();
  4249. return self;
  4250. },
  4251. remove : function() {
  4252. var self = this;
  4253. if (self.fileBox) {
  4254. self.fileBox.unbind();
  4255. }
  4256. self.iframe.remove();
  4257. self.div.remove();
  4258. self.button.show();
  4259. return self;
  4260. }
  4261. });
  4262. function _uploadbutton(options) {
  4263. return new KUploadButton(options);
  4264. }
  4265. K.UploadButtonClass = KUploadButton;
  4266. K.uploadbutton = _uploadbutton;
  4267. function _createButton(arg) {
  4268. arg = arg || {};
  4269. var name = arg.name || '',
  4270. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4271. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4272. if (arg.click) {
  4273. btn.click(arg.click);
  4274. }
  4275. span.append(btn);
  4276. return span;
  4277. }
  4278. function KDialog(options) {
  4279. this.init(options);
  4280. }
  4281. _extend(KDialog, KWidget, {
  4282. init : function(options) {
  4283. var self = this;
  4284. var shadowMode = _undef(options.shadowMode, true);
  4285. options.z = options.z || 811213;
  4286. options.shadowMode = false;
  4287. options.autoScroll = _undef(options.autoScroll, true);
  4288. KDialog.parent.init.call(self, options);
  4289. var title = options.title,
  4290. body = K(options.body, self.doc),
  4291. previewBtn = options.previewBtn,
  4292. yesBtn = options.yesBtn,
  4293. noBtn = options.noBtn,
  4294. closeBtn = options.closeBtn,
  4295. showMask = _undef(options.showMask, true);
  4296. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4297. e.stopPropagation();
  4298. });
  4299. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4300. if (_IE && _V < 7) {
  4301. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4302. } else if (shadowMode) {
  4303. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4304. }
  4305. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4306. contentDiv.append(headerDiv);
  4307. headerDiv.html(title);
  4308. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4309. headerDiv.append(self.closeIcon);
  4310. self.draggable({
  4311. clickEl : headerDiv,
  4312. beforeDrag : options.beforeDrag
  4313. });
  4314. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4315. contentDiv.append(bodyDiv);
  4316. bodyDiv.append(body);
  4317. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4318. if (previewBtn || yesBtn || noBtn) {
  4319. contentDiv.append(footerDiv);
  4320. }
  4321. _each([
  4322. { btn : previewBtn, name : 'preview' },
  4323. { btn : yesBtn, name : 'yes' },
  4324. { btn : noBtn, name : 'no' }
  4325. ], function() {
  4326. if (this.btn) {
  4327. var button = _createButton(this.btn);
  4328. button.addClass('ke-dialog-' + this.name);
  4329. footerDiv.append(button);
  4330. }
  4331. });
  4332. if (self.height) {
  4333. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4334. }
  4335. self.div.width(self.div.width());
  4336. self.div.height(self.div.height());
  4337. self.mask = null;
  4338. if (showMask) {
  4339. var docEl = _docElement(self.doc),
  4340. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4341. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4342. self.mask = _widget({
  4343. x : 0,
  4344. y : 0,
  4345. z : self.z - 1,
  4346. cls : 'ke-dialog-mask',
  4347. width : docWidth,
  4348. height : docHeight
  4349. });
  4350. }
  4351. self.autoPos(self.div.width(), self.div.height());
  4352. self.footerDiv = footerDiv;
  4353. self.bodyDiv = bodyDiv;
  4354. self.headerDiv = headerDiv;
  4355. self.isLoading = false;
  4356. },
  4357. setMaskIndex : function(z) {
  4358. var self = this;
  4359. self.mask.div.css('z-index', z);
  4360. },
  4361. showLoading : function(msg) {
  4362. msg = _undef(msg, '');
  4363. var self = this, body = self.bodyDiv;
  4364. self.loading = K('<div class="ke-dialog-loading"><div class="ke-inline-block ke-dialog-loading-content" style="margin-top:' + Math.round(body.height() / 3) + 'px;">' + msg + '</div></div>')
  4365. .width(body.width()).height(body.height())
  4366. .css('top', self.headerDiv.height() + 'px');
  4367. body.css('visibility', 'hidden').after(self.loading);
  4368. self.isLoading = true;
  4369. return self;
  4370. },
  4371. hideLoading : function() {
  4372. this.loading && this.loading.remove();
  4373. this.bodyDiv.css('visibility', 'visible');
  4374. this.isLoading = false;
  4375. return this;
  4376. },
  4377. remove : function() {
  4378. var self = this;
  4379. if (self.options.beforeRemove) {
  4380. self.options.beforeRemove.call(self);
  4381. }
  4382. self.mask && self.mask.remove();
  4383. self.iframeMask && self.iframeMask.remove();
  4384. self.closeIcon.unbind();
  4385. K('input', self.div).unbind();
  4386. K('button', self.div).unbind();
  4387. self.footerDiv.unbind();
  4388. self.bodyDiv.unbind();
  4389. self.headerDiv.unbind();
  4390. K('iframe', self.div).each(function() {
  4391. K(this).remove();
  4392. });
  4393. KDialog.parent.remove.call(self);
  4394. return self;
  4395. }
  4396. });
  4397. function _dialog(options) {
  4398. return new KDialog(options);
  4399. }
  4400. K.DialogClass = KDialog;
  4401. K.dialog = _dialog;
  4402. function _tabs(options) {
  4403. var self = _widget(options),
  4404. remove = self.remove,
  4405. afterSelect = options.afterSelect,
  4406. div = self.div,
  4407. liList = [];
  4408. div.addClass('ke-tabs')
  4409. .bind('contextmenu,mousedown,mousemove', function(e) {
  4410. e.preventDefault();
  4411. });
  4412. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4413. div.append(ul);
  4414. self.add = function(tab) {
  4415. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4416. li.data('tab', tab);
  4417. liList.push(li);
  4418. ul.append(li);
  4419. };
  4420. self.selectedIndex = 0;
  4421. self.select = function(index) {
  4422. self.selectedIndex = index;
  4423. _each(liList, function(i, li) {
  4424. li.unbind();
  4425. if (i === index) {
  4426. li.addClass('ke-tabs-li-selected');
  4427. K(li.data('tab').panel).show('');
  4428. } else {
  4429. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4430. .mouseover(function() {
  4431. K(this).addClass('ke-tabs-li-on');
  4432. })
  4433. .mouseout(function() {
  4434. K(this).removeClass('ke-tabs-li-on');
  4435. })
  4436. .click(function() {
  4437. self.select(i);
  4438. });
  4439. K(li.data('tab').panel).hide();
  4440. }
  4441. });
  4442. if (afterSelect) {
  4443. afterSelect.call(self, index);
  4444. }
  4445. };
  4446. self.remove = function() {
  4447. _each(liList, function() {
  4448. this.remove();
  4449. });
  4450. ul.remove();
  4451. remove.call(self);
  4452. };
  4453. return self;
  4454. }
  4455. K.tabs = _tabs;
  4456. function _loadScript(url, fn) {
  4457. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4458. script = document.createElement('script');
  4459. head.appendChild(script);
  4460. script.src = url;
  4461. script.charset = 'utf-8';
  4462. script.onload = script.onreadystatechange = function() {
  4463. if (!this.readyState || this.readyState === 'loaded') {
  4464. if (fn) {
  4465. fn();
  4466. }
  4467. script.onload = script.onreadystatechange = null;
  4468. head.removeChild(script);
  4469. }
  4470. };
  4471. }
  4472. function _chopQuery(url) {
  4473. var index = url.indexOf('?');
  4474. return index > 0 ? url.substr(0, index) : url;
  4475. }
  4476. function _loadStyle(url) {
  4477. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4478. link = document.createElement('link'),
  4479. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4480. var links = K('link[rel="stylesheet"]', head);
  4481. for (var i = 0, len = links.length; i < len; i++) {
  4482. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4483. return;
  4484. }
  4485. }
  4486. head.appendChild(link);
  4487. link.href = url;
  4488. link.rel = 'stylesheet';
  4489. }
  4490. function _ajax(url, fn, method, param, dataType) {
  4491. method = method || 'GET';
  4492. dataType = dataType || 'json';
  4493. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4494. xhr.open(method, url, true);
  4495. xhr.onreadystatechange = function () {
  4496. if (xhr.readyState == 4 && xhr.status == 200) {
  4497. if (fn) {
  4498. var data = _trim(xhr.responseText);
  4499. if (dataType == 'json') {
  4500. data = _json(data);
  4501. }
  4502. fn(data);
  4503. }
  4504. }
  4505. };
  4506. if (method == 'POST') {
  4507. var params = [];
  4508. _each(param, function(key, val) {
  4509. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4510. });
  4511. try {
  4512. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4513. } catch (e) {}
  4514. xhr.send(params.join('&'));
  4515. } else {
  4516. xhr.send(null);
  4517. }
  4518. }
  4519. K.loadScript = _loadScript;
  4520. K.loadStyle = _loadStyle;
  4521. K.ajax = _ajax;
  4522. var _plugins = {};
  4523. function _plugin(name, fn) {
  4524. if (name === undefined) {
  4525. return _plugins;
  4526. }
  4527. if (!fn) {
  4528. return _plugins[name];
  4529. }
  4530. _plugins[name] = fn;
  4531. }
  4532. var _language = {};
  4533. function _parseLangKey(key) {
  4534. var match, ns = 'core';
  4535. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4536. ns = match[1];
  4537. key = match[2];
  4538. }
  4539. return { ns : ns, key : key };
  4540. }
  4541. function _lang(mixed, langType) {
  4542. langType = langType === undefined ? K.options.langType : langType;
  4543. if (typeof mixed === 'string') {
  4544. if (!_language[langType]) {
  4545. return 'no language';
  4546. }
  4547. var pos = mixed.length - 1;
  4548. if (mixed.substr(pos) === '.') {
  4549. return _language[langType][mixed.substr(0, pos)];
  4550. }
  4551. var obj = _parseLangKey(mixed);
  4552. return _language[langType][obj.ns][obj.key];
  4553. }
  4554. _each(mixed, function(key, val) {
  4555. var obj = _parseLangKey(key);
  4556. if (!_language[langType]) {
  4557. _language[langType] = {};
  4558. }
  4559. if (!_language[langType][obj.ns]) {
  4560. _language[langType][obj.ns] = {};
  4561. }
  4562. _language[langType][obj.ns][obj.key] = val;
  4563. });
  4564. }
  4565. function _getImageFromRange(range, fn) {
  4566. if (range.collapsed) {
  4567. return;
  4568. }
  4569. range = range.cloneRange().up();
  4570. var sc = range.startContainer, so = range.startOffset;
  4571. if (!_WEBKIT && !range.isControl()) {
  4572. return;
  4573. }
  4574. var img = K(sc.childNodes[so]);
  4575. if (!img || img.name != 'img') {
  4576. return;
  4577. }
  4578. if (fn(img)) {
  4579. return img;
  4580. }
  4581. }
  4582. function _bindContextmenuEvent() {
  4583. var self = this, doc = self.edit.doc;
  4584. K(doc).contextmenu(function(e) {
  4585. if (self.menu) {
  4586. self.hideMenu();
  4587. }
  4588. if (!self.useContextmenu) {
  4589. e.preventDefault();
  4590. return;
  4591. }
  4592. if (self._contextmenus.length === 0) {
  4593. return;
  4594. }
  4595. var maxWidth = 0, items = [];
  4596. _each(self._contextmenus, function() {
  4597. if (this.title == '-') {
  4598. items.push(this);
  4599. return;
  4600. }
  4601. if (this.cond && this.cond()) {
  4602. items.push(this);
  4603. if (this.width && this.width > maxWidth) {
  4604. maxWidth = this.width;
  4605. }
  4606. }
  4607. });
  4608. while (items.length > 0 && items[0].title == '-') {
  4609. items.shift();
  4610. }
  4611. while (items.length > 0 && items[items.length - 1].title == '-') {
  4612. items.pop();
  4613. }
  4614. var prevItem = null;
  4615. _each(items, function(i) {
  4616. if (this.title == '-' && prevItem.title == '-') {
  4617. delete items[i];
  4618. }
  4619. prevItem = this;
  4620. });
  4621. if (items.length > 0) {
  4622. e.preventDefault();
  4623. var pos = K(self.edit.iframe).pos(),
  4624. menu = _menu({
  4625. x : pos.x + e.clientX,
  4626. y : pos.y + e.clientY,
  4627. width : maxWidth,
  4628. css : { visibility: 'hidden' },
  4629. shadowMode : self.shadowMode
  4630. });
  4631. _each(items, function() {
  4632. if (this.title) {
  4633. menu.addItem(this);
  4634. }
  4635. });
  4636. var docEl = _docElement(menu.doc),
  4637. menuHeight = menu.div.height();
  4638. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4639. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4640. }
  4641. menu.div.css('visibility', 'visible');
  4642. self.menu = menu;
  4643. }
  4644. });
  4645. }
  4646. function _bindNewlineEvent() {
  4647. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4648. if (_IE && newlineTag !== 'br') {
  4649. return;
  4650. }
  4651. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4652. return;
  4653. }
  4654. if (_OPERA && _V < 9) {
  4655. return;
  4656. }
  4657. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4658. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4659. function getAncestorTagName(range) {
  4660. var ancestor = K(range.commonAncestor());
  4661. while (ancestor) {
  4662. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4663. break;
  4664. }
  4665. ancestor = ancestor.parent();
  4666. }
  4667. return ancestor.name;
  4668. }
  4669. K(doc).keydown(function(e) {
  4670. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4671. autoImg(self);
  4672. return;
  4673. }
  4674. self.cmd.selection();
  4675. var tagName = getAncestorTagName(self.cmd.range);
  4676. if (tagName == 'marquee' || tagName == 'select') {
  4677. return;
  4678. }
  4679. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4680. e.preventDefault();
  4681. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4682. return;
  4683. }
  4684. if (!pSkipTagMap[tagName]) {
  4685. _nativeCommand(doc, 'formatblock', '<p>');
  4686. }
  4687. });
  4688. K(doc).keyup(function(e) {
  4689. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4690. return;
  4691. }
  4692. if (newlineTag == 'br') {
  4693. return;
  4694. }
  4695. if (_GECKO) {
  4696. var root = self.cmd.commonAncestor('p');
  4697. var a = self.cmd.commonAncestor('a');
  4698. if (a && a.text() == '') {
  4699. a.remove(true);
  4700. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4701. self.cmd.select();
  4702. }
  4703. return;
  4704. }
  4705. self.cmd.selection();
  4706. var tagName = getAncestorTagName(self.cmd.range);
  4707. if (tagName == 'marquee' || tagName == 'select') {
  4708. return;
  4709. }
  4710. if (!pSkipTagMap[tagName]) {
  4711. _nativeCommand(doc, 'formatblock', '<p>');
  4712. }
  4713. var div = self.cmd.commonAncestor('div');
  4714. if (div) {
  4715. var p = K('<p></p>'),
  4716. child = div[0].firstChild;
  4717. while (child) {
  4718. var next = child.nextSibling;
  4719. p.append(child);
  4720. child = next;
  4721. }
  4722. div.before(p);
  4723. div.remove();
  4724. self.cmd.range.selectNodeContents(p[0]);
  4725. self.cmd.select();
  4726. }
  4727. });
  4728. }
  4729. function _bindTabEvent() {
  4730. var self = this, doc = self.edit.doc;
  4731. K(doc).keydown(function(e) {
  4732. if (e.which == 9) {
  4733. e.preventDefault();
  4734. if (self.afterTab) {
  4735. self.afterTab.call(self, e);
  4736. return;
  4737. }
  4738. var cmd = self.cmd, range = cmd.range;
  4739. range.shrink();
  4740. if (range.collapsed && range.startContainer.nodeType == 1) {
  4741. range.insertNode(K('@&nbsp;', doc)[0]);
  4742. cmd.select();
  4743. }
  4744. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4745. }
  4746. });
  4747. }
  4748. function _bindFocusEvent() {
  4749. var self = this;
  4750. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4751. if (self.afterFocus) {
  4752. self.afterFocus.call(self, e);
  4753. }
  4754. }).blur(function(e) {
  4755. if (self.afterBlur) {
  4756. self.afterBlur.call(self, e);
  4757. }
  4758. });
  4759. }
  4760. function _removeBookmarkTag(html) {
  4761. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4762. }
  4763. function _removeTempTag(html) {
  4764. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4765. }
  4766. function _addBookmarkToStack(stack, bookmark) {
  4767. if (stack.length === 0) {
  4768. stack.push(bookmark);
  4769. return;
  4770. }
  4771. var prev = stack[stack.length - 1];
  4772. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4773. stack.push(bookmark);
  4774. }
  4775. }
  4776. function _undoToRedo(fromStack, toStack) {
  4777. var self = this, edit = self.edit,
  4778. body = edit.doc.body,
  4779. range, bookmark;
  4780. if (fromStack.length === 0) {
  4781. return self;
  4782. }
  4783. if (edit.designMode) {
  4784. range = self.cmd.range;
  4785. bookmark = range.createBookmark(true);
  4786. bookmark.html = body.innerHTML;
  4787. } else {
  4788. bookmark = {
  4789. html : body.innerHTML
  4790. };
  4791. }
  4792. _addBookmarkToStack(toStack, bookmark);
  4793. var prev = fromStack.pop();
  4794. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4795. prev = fromStack.pop();
  4796. }
  4797. if (edit.designMode) {
  4798. edit.html(prev.html);
  4799. if (prev.start) {
  4800. range.moveToBookmark(prev);
  4801. self.select();
  4802. }
  4803. } else {
  4804. K(body).html(_removeBookmarkTag(prev.html));
  4805. }
  4806. return self;
  4807. }
  4808. function KEditor(options) {
  4809. var self = this;
  4810. self.options = {};
  4811. function setOption(key, val) {
  4812. if (KEditor.prototype[key] === undefined) {
  4813. self[key] = val;
  4814. }
  4815. self.options[key] = val;
  4816. }
  4817. _each(options, function(key, val) {
  4818. setOption(key, options[key]);
  4819. });
  4820. _each(K.options, function(key, val) {
  4821. if (self[key] === undefined) {
  4822. setOption(key, val);
  4823. }
  4824. });
  4825. var se = K(self.srcElement || '<textarea/>');
  4826. if (!self.width) {
  4827. self.width = se[0].style.width || se.width();
  4828. if (!self.width) {
  4829. self.width = '700';
  4830. }
  4831. }
  4832. if (!self.height) {
  4833. self.height = se[0].style.height || se.height();
  4834. }
  4835. setOption('width', _undef(self.width, self.minWidth));
  4836. setOption('height', _undef(self.height, self.minHeight));
  4837. setOption('width', _addUnit(self.width));
  4838. setOption('height', _addUnit(self.height));
  4839. if (_MOBILE && (!_IOS || _V < 534)) {
  4840. //self.designMode = false;
  4841. }
  4842. self.srcElement = se;
  4843. self.initContent = '';
  4844. self.plugin = {};
  4845. self.isCreated = false;
  4846. self._handlers = {};
  4847. self._contextmenus = [];
  4848. self._undoStack = [];
  4849. self._redoStack = [];
  4850. self._firstAddBookmark = true;
  4851. self.menu = self.contextmenu = null;
  4852. self.dialogs = [];
  4853. }
  4854. KEditor.prototype = {
  4855. lang : function(mixed) {
  4856. return _lang(mixed, this.langType);
  4857. },
  4858. loadPlugin : function(name, fn) {
  4859. var self = this;
  4860. var _pluginStatus = this._pluginStatus;
  4861. if (!_pluginStatus) {
  4862. _pluginStatus = this._pluginStatus = {};
  4863. }
  4864. if (_plugins[name]) {
  4865. if (!_isFunction(_plugins[name])) {
  4866. setTimeout(function() {
  4867. self.loadPlugin(name, fn);
  4868. }, 100);
  4869. return self;
  4870. }
  4871. if(!_pluginStatus[name]) {
  4872. _plugins[name].call(self, KindEditor);
  4873. _pluginStatus[name] = 'inited';
  4874. }
  4875. if (fn) {
  4876. fn.call(self);
  4877. }
  4878. return self;
  4879. }
  4880. _plugins[name] = 'loading';
  4881. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4882. setTimeout(function() {
  4883. if (_plugins[name]) {
  4884. self.loadPlugin(name, fn);
  4885. }
  4886. }, 0);
  4887. });
  4888. return self;
  4889. },
  4890. handler : function(key, fn) {
  4891. var self = this;
  4892. if (!self._handlers[key]) {
  4893. self._handlers[key] = [];
  4894. }
  4895. if (_isFunction(fn)) {
  4896. self._handlers[key].push(fn);
  4897. return self;
  4898. }
  4899. _each(self._handlers[key], function() {
  4900. fn = this.call(self, fn);
  4901. });
  4902. return fn;
  4903. },
  4904. clickToolbar : function(name, fn) {
  4905. var self = this, key = 'clickToolbar' + name;
  4906. if (fn === undefined) {
  4907. if (self._handlers[key]) {
  4908. return self.handler(key);
  4909. }
  4910. self.loadPlugin(name, function() {
  4911. self.handler(key);
  4912. });
  4913. return self;
  4914. }
  4915. return self.handler(key, fn);
  4916. },
  4917. updateState : function() {
  4918. var self = this;
  4919. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4920. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4921. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4922. });
  4923. return self;
  4924. },
  4925. addContextmenu : function(item) {
  4926. this._contextmenus.push(item);
  4927. return this;
  4928. },
  4929. afterCreate : function(fn) {
  4930. return this.handler('afterCreate', fn);
  4931. },
  4932. beforeRemove : function(fn) {
  4933. return this.handler('beforeRemove', fn);
  4934. },
  4935. beforeGetHtml : function(fn) {
  4936. return this.handler('beforeGetHtml', fn);
  4937. },
  4938. beforeSetHtml : function(fn) {
  4939. return this.handler('beforeSetHtml', fn);
  4940. },
  4941. afterSetHtml : function(fn) {
  4942. return this.handler('afterSetHtml', fn);
  4943. },
  4944. create : function() {
  4945. var self = this, fullscreenMode = self.fullscreenMode;
  4946. if (self.isCreated) {
  4947. return self;
  4948. }
  4949. if (self.srcElement.data('kindeditor')) {
  4950. return self;
  4951. }
  4952. self.srcElement.data('kindeditor', 'true');
  4953. if (fullscreenMode) {
  4954. _docElement().style.overflow = 'hidden';
  4955. } else {
  4956. _docElement().style.overflow = '';
  4957. }
  4958. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4959. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4960. if ((_IE && _V < 8) || _QUIRKS) {
  4961. height = _addUnit(_removeUnit(height) + 2);
  4962. }
  4963. var container = self.container = K(self.layout);
  4964. if (fullscreenMode) {
  4965. K(document.body).append(container);
  4966. } else {
  4967. self.srcElement.before(container);
  4968. }
  4969. var toolbarDiv = K('.toolbar', container),
  4970. editDiv = K('.edit', container),
  4971. statusbar = self.statusbar = K('.statusbar', container);
  4972. container.removeClass('container')
  4973. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4974. if (fullscreenMode) {
  4975. container.css({
  4976. position : 'absolute',
  4977. left : 0,
  4978. top : 0,
  4979. 'z-index' : 811211
  4980. });
  4981. if (!_GECKO) {
  4982. self._scrollPos = _getScrollPos();
  4983. }
  4984. window.scrollTo(0, 0);
  4985. K(document.body).css({
  4986. 'height' : '1px',
  4987. 'overflow' : 'hidden'
  4988. });
  4989. K(document.body.parentNode).css('overflow', 'hidden');
  4990. self._fullscreenExecuted = true;
  4991. } else {
  4992. if (self._fullscreenExecuted) {
  4993. K(document.body).css({
  4994. 'height' : '',
  4995. 'overflow' : ''
  4996. });
  4997. K(document.body.parentNode).css('overflow', '');
  4998. }
  4999. if (self._scrollPos) {
  5000. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  5001. }
  5002. }
  5003. var htmlList = [];
  5004. K.each(self.items, function(i, name) {
  5005. if (name == '|') {
  5006. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  5007. } else if (name == '/') {
  5008. htmlList.push('<div class="ke-hr"></div>');
  5009. } else {
  5010. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  5011. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  5012. }
  5013. });
  5014. var toolbar = self.toolbar = _toolbar({
  5015. src : toolbarDiv,
  5016. html : htmlList.join(''),
  5017. noDisableItems : self.noDisableItems,
  5018. click : function(e, name) {
  5019. e.stop();
  5020. if (self.menu) {
  5021. var menuName = self.menu.name;
  5022. self.hideMenu();
  5023. if (menuName === name) {
  5024. return;
  5025. }
  5026. }
  5027. self.clickToolbar(name);
  5028. }
  5029. });
  5030. var editHeight = _removeUnit(height) - toolbar.div.height();
  5031. var edit = self.edit = _edit({
  5032. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5033. src : editDiv,
  5034. srcElement : self.srcElement,
  5035. designMode : self.designMode,
  5036. themesPath : self.themesPath,
  5037. bodyClass : self.bodyClass,
  5038. cssPath : self.cssPath,
  5039. cssData : self.cssData,
  5040. beforeGetHtml : function(html) {
  5041. html = self.beforeGetHtml(html);
  5042. html = _removeBookmarkTag(_removeTempTag(html));
  5043. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5044. },
  5045. beforeSetHtml : function(html) {
  5046. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5047. return self.beforeSetHtml(html);
  5048. },
  5049. afterSetHtml : function() {
  5050. self.edit = edit = this;
  5051. self.afterSetHtml();
  5052. },
  5053. afterCreate : function() {
  5054. self.edit = edit = this;
  5055. self.cmd = edit.cmd;
  5056. self._docMousedownFn = function(e) {
  5057. if (self.menu) {
  5058. self.hideMenu();
  5059. }
  5060. };
  5061. K(edit.doc, document).mousedown(self._docMousedownFn);
  5062. _bindContextmenuEvent.call(self);
  5063. _bindNewlineEvent.call(self);
  5064. _bindTabEvent.call(self);
  5065. _bindFocusEvent.call(self);
  5066. edit.afterChange(function(e) {
  5067. if (!edit.designMode) {
  5068. return;
  5069. }
  5070. self.updateState();
  5071. self.addBookmark();
  5072. if (self.options.afterChange) {
  5073. self.options.afterChange.call(self);
  5074. }
  5075. });
  5076. edit.textarea.keyup(function(e) {
  5077. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5078. if (self.options.afterChange) {
  5079. self.options.afterChange.call(self);
  5080. }
  5081. }
  5082. });
  5083. if (self.readonlyMode) {
  5084. self.readonly();
  5085. }
  5086. self.isCreated = true;
  5087. if (self.initContent === '') {
  5088. self.initContent = self.html();
  5089. }
  5090. if (self._undoStack.length > 0) {
  5091. var prev = self._undoStack.pop();
  5092. if (prev.start) {
  5093. self.html(prev.html);
  5094. edit.cmd.range.moveToBookmark(prev);
  5095. self.select();
  5096. }
  5097. }
  5098. self.afterCreate();
  5099. if (self.options.afterCreate) {
  5100. self.options.afterCreate.call(self);
  5101. }
  5102. }
  5103. });
  5104. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5105. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5106. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5107. if (self._fullscreenResizeHandler) {
  5108. K(window).unbind('resize', self._fullscreenResizeHandler);
  5109. self._fullscreenResizeHandler = null;
  5110. }
  5111. function initResize() {
  5112. if (statusbar.height() === 0) {
  5113. setTimeout(initResize, 100);
  5114. return;
  5115. }
  5116. self.resize(width, height, false);
  5117. }
  5118. initResize();
  5119. if (fullscreenMode) {
  5120. self._fullscreenResizeHandler = function(e) {
  5121. if (self.isCreated) {
  5122. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5123. }
  5124. };
  5125. K(window).bind('resize', self._fullscreenResizeHandler);
  5126. toolbar.select('fullscreen');
  5127. statusbar.first().css('visibility', 'hidden');
  5128. statusbar.last().css('visibility', 'hidden');
  5129. } else {
  5130. if (_GECKO) {
  5131. K(window).bind('scroll', function(e) {
  5132. self._scrollPos = _getScrollPos();
  5133. });
  5134. }
  5135. if (self.resizeType > 0) {
  5136. _drag({
  5137. moveEl : container,
  5138. clickEl : statusbar,
  5139. moveFn : function(x, y, width, height, diffX, diffY) {
  5140. height += diffY;
  5141. self.resize(null, height);
  5142. }
  5143. });
  5144. } else {
  5145. statusbar.first().css('visibility', 'hidden');
  5146. }
  5147. if (self.resizeType === 2) {
  5148. _drag({
  5149. moveEl : container,
  5150. clickEl : statusbar.last(),
  5151. moveFn : function(x, y, width, height, diffX, diffY) {
  5152. width += diffX;
  5153. height += diffY;
  5154. self.resize(width, height);
  5155. }
  5156. });
  5157. } else {
  5158. statusbar.last().css('visibility', 'hidden');
  5159. }
  5160. }
  5161. return self;
  5162. },
  5163. remove : function() {
  5164. var self = this;
  5165. if (!self.isCreated) {
  5166. return self;
  5167. }
  5168. self.beforeRemove();
  5169. self.srcElement.data('kindeditor', '');
  5170. if (self.menu) {
  5171. self.hideMenu();
  5172. }
  5173. _each(self.dialogs, function() {
  5174. self.hideDialog();
  5175. });
  5176. K(document).unbind('mousedown', self._docMousedownFn);
  5177. self.toolbar.remove();
  5178. self.edit.remove();
  5179. self.statusbar.last().unbind();
  5180. self.statusbar.unbind();
  5181. self.container.remove();
  5182. self.container = self.toolbar = self.edit = self.menu = null;
  5183. self.dialogs = [];
  5184. self.isCreated = false;
  5185. return self;
  5186. },
  5187. resize : function(width, height, updateProp) {
  5188. var self = this;
  5189. updateProp = _undef(updateProp, true);
  5190. if (width) {
  5191. if (!/%/.test(width)) {
  5192. width = _removeUnit(width);
  5193. width = width < self.minWidth ? self.minWidth : width;
  5194. }
  5195. self.container.css('width', _addUnit(width));
  5196. if (updateProp) {
  5197. self.width = _addUnit(width);
  5198. }
  5199. }
  5200. if (height) {
  5201. height = _removeUnit(height);
  5202. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5203. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5204. self.edit.setHeight(editHeight);
  5205. if (updateProp) {
  5206. self.height = _addUnit(height);
  5207. }
  5208. }
  5209. return self;
  5210. },
  5211. select : function() {
  5212. this.isCreated && this.cmd.select();
  5213. return this;
  5214. },
  5215. html : function(val) {
  5216. var self = this;
  5217. if (val === undefined) {
  5218. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5219. }
  5220. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5221. if (self.isCreated) {
  5222. self.cmd.selection();
  5223. }
  5224. return self;
  5225. },
  5226. fullHtml : function() {
  5227. return this.isCreated ? this.edit.html(undefined, true) : '';
  5228. },
  5229. text : function(val) {
  5230. var self = this;
  5231. if (val === undefined) {
  5232. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5233. } else {
  5234. return self.html(_escape(val));
  5235. }
  5236. },
  5237. isEmpty : function() {
  5238. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5239. },
  5240. isDirty : function() {
  5241. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5242. },
  5243. selectedHtml : function() {
  5244. var val = this.isCreated ? this.cmd.range.html() : '';
  5245. val = _removeBookmarkTag(_removeTempTag(val));
  5246. return val;
  5247. },
  5248. count : function(mode) {
  5249. var self = this;
  5250. mode = (mode || 'html').toLowerCase();
  5251. if (mode === 'html') {
  5252. return self.html().length;
  5253. }
  5254. if (mode === 'text') {
  5255. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5256. }
  5257. return 0;
  5258. },
  5259. exec : function(key) {
  5260. key = key.toLowerCase();
  5261. var self = this, cmd = self.cmd,
  5262. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5263. if (changeFlag) {
  5264. self.addBookmark(false);
  5265. }
  5266. cmd[key].apply(cmd, _toArray(arguments, 1));
  5267. if (changeFlag) {
  5268. self.updateState();
  5269. self.addBookmark(false);
  5270. if (self.options.afterChange) {
  5271. self.options.afterChange.call(self);
  5272. }
  5273. }
  5274. return self;
  5275. },
  5276. insertHtml : function(val, quickMode) {
  5277. if (!this.isCreated) {
  5278. return this;
  5279. }
  5280. val = this.beforeSetHtml(val);
  5281. this.exec('inserthtml', val, quickMode);
  5282. return this;
  5283. },
  5284. appendHtml : function(val) {
  5285. this.html(this.html() + val);
  5286. if (this.isCreated) {
  5287. var cmd = this.cmd;
  5288. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5289. cmd.select();
  5290. }
  5291. return this;
  5292. },
  5293. sync : function() {
  5294. _elementVal(this.srcElement, this.html());
  5295. return this;
  5296. },
  5297. focus : function() {
  5298. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5299. return this;
  5300. },
  5301. blur : function() {
  5302. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5303. return this;
  5304. },
  5305. addBookmark : function(checkSize) {
  5306. checkSize = _undef(checkSize, true);
  5307. var self = this, edit = self.edit,
  5308. body = edit.doc.body,
  5309. html = _removeTempTag(body.innerHTML), bookmark;
  5310. if (checkSize && self._undoStack.length > 0) {
  5311. var prev = self._undoStack[self._undoStack.length - 1];
  5312. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5313. return self;
  5314. }
  5315. }
  5316. if (edit.designMode && !self._firstAddBookmark) {
  5317. var range = self.cmd.range;
  5318. bookmark = range.createBookmark(true);
  5319. bookmark.html = _removeTempTag(body.innerHTML);
  5320. range.moveToBookmark(bookmark);
  5321. } else {
  5322. bookmark = {
  5323. html : html
  5324. };
  5325. }
  5326. self._firstAddBookmark = false;
  5327. _addBookmarkToStack(self._undoStack, bookmark);
  5328. return self;
  5329. },
  5330. undo : function() {
  5331. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5332. },
  5333. redo : function() {
  5334. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5335. },
  5336. fullscreen : function(bool) {
  5337. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5338. this.addBookmark(false);
  5339. return this.remove().create();
  5340. },
  5341. readonly : function(isReadonly) {
  5342. isReadonly = _undef(isReadonly, true);
  5343. var self = this, edit = self.edit, doc = edit.doc;
  5344. if (self.designMode) {
  5345. self.toolbar.disableAll(isReadonly, []);
  5346. } else {
  5347. _each(self.noDisableItems, function() {
  5348. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5349. });
  5350. }
  5351. if (_IE) {
  5352. doc.body.contentEditable = !isReadonly;
  5353. } else {
  5354. doc.designMode = isReadonly ? 'off' : 'on';
  5355. }
  5356. edit.textarea[0].disabled = isReadonly;
  5357. },
  5358. createMenu : function(options) {
  5359. var self = this,
  5360. name = options.name,
  5361. knode = self.toolbar.get(name),
  5362. pos = knode.pos();
  5363. options.x = pos.x;
  5364. options.y = pos.y + knode.height();
  5365. options.z = self.options.zIndex;
  5366. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5367. if (options.selectedColor !== undefined) {
  5368. options.cls = 'ke-colorpicker-' + self.themeType;
  5369. options.noColor = self.lang('noColor');
  5370. self.menu = _colorpicker(options);
  5371. } else {
  5372. options.cls = 'ke-menu-' + self.themeType;
  5373. options.centerLineMode = false;
  5374. self.menu = _menu(options);
  5375. }
  5376. return self.menu;
  5377. },
  5378. hideMenu : function() {
  5379. this.menu.remove();
  5380. this.menu = null;
  5381. return this;
  5382. },
  5383. hideContextmenu : function() {
  5384. this.contextmenu.remove();
  5385. this.contextmenu = null;
  5386. return this;
  5387. },
  5388. createDialog : function(options) {
  5389. var self = this, name = options.name;
  5390. options.z = self.options.zIndex;
  5391. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5392. options.closeBtn = _undef(options.closeBtn, {
  5393. name : self.lang('close'),
  5394. click : function(e) {
  5395. self.hideDialog();
  5396. if (_IE && self.cmd) {
  5397. self.cmd.select();
  5398. }
  5399. }
  5400. });
  5401. options.noBtn = _undef(options.noBtn, {
  5402. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5403. click : function(e) {
  5404. self.hideDialog();
  5405. if (_IE && self.cmd) {
  5406. self.cmd.select();
  5407. }
  5408. }
  5409. });
  5410. if (self.dialogAlignType != 'page') {
  5411. options.alignEl = self.container;
  5412. }
  5413. options.cls = 'ke-dialog-' + self.themeType;
  5414. if (self.dialogs.length > 0) {
  5415. var firstDialog = self.dialogs[0],
  5416. parentDialog = self.dialogs[self.dialogs.length - 1];
  5417. firstDialog.setMaskIndex(parentDialog.z + 2);
  5418. options.z = parentDialog.z + 3;
  5419. options.showMask = false;
  5420. }
  5421. var dialog = _dialog(options);
  5422. self.dialogs.push(dialog);
  5423. return dialog;
  5424. },
  5425. hideDialog : function() {
  5426. var self = this;
  5427. if (self.dialogs.length > 0) {
  5428. self.dialogs.pop().remove();
  5429. }
  5430. if (self.dialogs.length > 0) {
  5431. var firstDialog = self.dialogs[0],
  5432. parentDialog = self.dialogs[self.dialogs.length - 1];
  5433. firstDialog.setMaskIndex(parentDialog.z - 1);
  5434. }
  5435. return self;
  5436. },
  5437. errorDialog : function(html) {
  5438. var self = this;
  5439. var dialog = self.createDialog({
  5440. width : 750,
  5441. title : self.lang('uploadError'),
  5442. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5443. });
  5444. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5445. doc.open();
  5446. doc.write(html);
  5447. doc.close();
  5448. K(doc.body).css('background-color', '#FFF');
  5449. iframe[0].contentWindow.focus();
  5450. return self;
  5451. }
  5452. };
  5453. function _editor(options) {
  5454. return new KEditor(options);
  5455. }
  5456. var _instances = [];
  5457. function _create(expr, options) {
  5458. options = options || {};
  5459. options.basePath = _undef(options.basePath, K.basePath);
  5460. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5461. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5462. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5463. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5464. var themeType = _undef(options.themeType, K.options.themeType);
  5465. _loadStyle(options.themesPath + 'default/default.css');
  5466. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5467. }
  5468. function create(editor) {
  5469. _each(_plugins, function(name, fn) {
  5470. if (_isFunction(fn)) {
  5471. fn.call(editor, KindEditor);
  5472. if (!editor._pluginStatus) {
  5473. editor._pluginStatus = {};
  5474. }
  5475. editor._pluginStatus[name] = 'inited';
  5476. }
  5477. });
  5478. return editor.create();
  5479. }
  5480. var knode = K(expr);
  5481. if (!knode || knode.length === 0) {
  5482. return;
  5483. }
  5484. if (knode.length > 1) {
  5485. knode.each(function() {
  5486. _create(this, options);
  5487. });
  5488. return _instances[0];
  5489. }
  5490. options.srcElement = knode[0];
  5491. var editor = new KEditor(options);
  5492. _instances.push(editor);
  5493. if (_language[editor.langType]) {
  5494. return create(editor);
  5495. }
  5496. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5497. create(editor);
  5498. });
  5499. return editor;
  5500. }
  5501. function _eachEditor(expr, fn) {
  5502. K(expr).each(function(i, el) {
  5503. K.each(_instances, function(j, editor) {
  5504. if (editor && editor.srcElement[0] == el) {
  5505. fn.call(editor, j);
  5506. return false;
  5507. }
  5508. });
  5509. });
  5510. }
  5511. K.remove = function(expr) {
  5512. _eachEditor(expr, function(i) {
  5513. this.remove();
  5514. _instances.splice(i, 1);
  5515. });
  5516. };
  5517. K.sync = function(expr) {
  5518. _eachEditor(expr, function() {
  5519. this.sync();
  5520. });
  5521. };
  5522. K.html = function(expr, val) {
  5523. _eachEditor(expr, function() {
  5524. this.html(val);
  5525. });
  5526. };
  5527. K.insertHtml = function(expr, val) {
  5528. _eachEditor(expr, function() {
  5529. this.insertHtml(val);
  5530. });
  5531. };
  5532. K.appendHtml = function(expr, val) {
  5533. _eachEditor(expr, function() {
  5534. this.appendHtml(val);
  5535. });
  5536. };
  5537. if (_IE && _V < 7) {
  5538. _nativeCommand(document, 'BackgroundImageCache', true);
  5539. }
  5540. K.EditorClass = KEditor;
  5541. K.editor = _editor;
  5542. K.create = _create;
  5543. K.instances = _instances;
  5544. K.plugin = _plugin;
  5545. K.lang = _lang;
  5546. _plugin('core', function(K) {
  5547. var self = this,
  5548. shortcutKeys = {
  5549. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5550. };
  5551. self.afterSetHtml(function() {
  5552. if (self.options.afterChange) {
  5553. self.options.afterChange.call(self);
  5554. }
  5555. });
  5556. self.afterCreate(function() {
  5557. if (self.syncType != 'form') {
  5558. return;
  5559. }
  5560. var el = K(self.srcElement), hasForm = false;
  5561. while ((el = el.parent())) {
  5562. if (el.name == 'form') {
  5563. hasForm = true;
  5564. break;
  5565. }
  5566. }
  5567. if (hasForm) {
  5568. el.bind('submit', function(e) {
  5569. self.sync();
  5570. K(window).bind('unload', function() {
  5571. self.edit.textarea.remove();
  5572. });
  5573. });
  5574. var resetBtn = K('[type="reset"]', el);
  5575. resetBtn.click(function() {
  5576. self.html(self.initContent);
  5577. self.cmd.selection();
  5578. });
  5579. self.beforeRemove(function() {
  5580. el.unbind();
  5581. resetBtn.unbind();
  5582. });
  5583. }
  5584. });
  5585. self.clickToolbar('source', function() {
  5586. if (self.edit.designMode) {
  5587. self.toolbar.disableAll(true);
  5588. self.edit.design(false);
  5589. self.toolbar.select('source');
  5590. } else {
  5591. self.toolbar.disableAll(false);
  5592. self.edit.design(true);
  5593. self.toolbar.unselect('source');
  5594. if (_GECKO) {
  5595. setTimeout(function() {
  5596. self.cmd.selection();
  5597. }, 0);
  5598. } else {
  5599. self.cmd.selection();
  5600. }
  5601. }
  5602. self.designMode = self.edit.designMode;
  5603. });
  5604. self.afterCreate(function() {
  5605. if (!self.designMode) {
  5606. self.toolbar.disableAll(true).select('source');
  5607. }
  5608. });
  5609. self.clickToolbar('fullscreen', function() {
  5610. self.fullscreen();
  5611. });
  5612. if (self.fullscreenShortcut) {
  5613. var loaded = false;
  5614. self.afterCreate(function() {
  5615. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5616. if (e.which == 27) {
  5617. setTimeout(function() {
  5618. self.fullscreen();
  5619. }, 0);
  5620. }
  5621. });
  5622. if (loaded) {
  5623. if (_IE && !self.designMode) {
  5624. return;
  5625. }
  5626. self.focus();
  5627. }
  5628. if (!loaded) {
  5629. loaded = true;
  5630. }
  5631. });
  5632. }
  5633. _each('undo,redo'.split(','), function(i, name) {
  5634. if (shortcutKeys[name]) {
  5635. self.afterCreate(function() {
  5636. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5637. self.clickToolbar(name);
  5638. });
  5639. });
  5640. }
  5641. self.clickToolbar(name, function() {
  5642. self[name]();
  5643. });
  5644. });
  5645. self.clickToolbar('formatblock', function() {
  5646. var blocks = self.lang('formatblock.formatBlock'),
  5647. heights = {
  5648. h1 : 28,
  5649. h2 : 24,
  5650. h3 : 18,
  5651. H4 : 14,
  5652. p : 12
  5653. },
  5654. curVal = self.cmd.val('formatblock'),
  5655. menu = self.createMenu({
  5656. name : 'formatblock',
  5657. width : self.langType == 'en' ? 200 : 150
  5658. });
  5659. _each(blocks, function(key, val) {
  5660. var style = 'font-size:' + heights[key] + 'px;';
  5661. if (key.charAt(0) === 'h') {
  5662. style += 'font-weight:bold;';
  5663. }
  5664. menu.addItem({
  5665. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5666. height : heights[key] + 12,
  5667. checked : (curVal === key || curVal === val),
  5668. click : function() {
  5669. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5670. }
  5671. });
  5672. });
  5673. });
  5674. self.clickToolbar('fontname', function() {
  5675. var curVal = self.cmd.val('fontname'),
  5676. menu = self.createMenu({
  5677. name : 'fontname',
  5678. width : 150
  5679. });
  5680. _each(self.lang('fontname.fontName'), function(key, val) {
  5681. menu.addItem({
  5682. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5683. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5684. click : function() {
  5685. self.exec('fontname', key).hideMenu();
  5686. }
  5687. });
  5688. });
  5689. });
  5690. self.clickToolbar('fontsize', function() {
  5691. var curVal = self.cmd.val('fontsize'),
  5692. menu = self.createMenu({
  5693. name : 'fontsize',
  5694. width : 150
  5695. });
  5696. _each(self.fontSizeTable, function(i, val) {
  5697. menu.addItem({
  5698. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5699. height : _removeUnit(val) + 12,
  5700. checked : curVal === val,
  5701. click : function() {
  5702. self.exec('fontsize', val).hideMenu();
  5703. }
  5704. });
  5705. });
  5706. });
  5707. self.clickToolbar('fontheight', function() {
  5708. var curVal = self.cmd.val('fontheight'),
  5709. menu = self.createMenu({
  5710. name : 'fontsize',
  5711. width : 150
  5712. });
  5713. _each(self.fontHeightTable, function(i, val) {
  5714. menu.addItem({
  5715. title : '<span unselectable="on">' + val + '</span>',
  5716. height : 20,
  5717. checked : curVal === val,
  5718. click : function() {
  5719. self.exec('fontheight', val).hideMenu();
  5720. }
  5721. });
  5722. });
  5723. });
  5724. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5725. self.clickToolbar(name, function() {
  5726. self.createMenu({
  5727. name : name,
  5728. selectedColor : self.cmd.val(name) || 'default',
  5729. colors : self.colorTable,
  5730. click : function(color) {
  5731. self.exec(name, color).hideMenu();
  5732. }
  5733. });
  5734. });
  5735. });
  5736. _each(('cut,copy,paste').split(','), function(i, name) {
  5737. self.clickToolbar(name, function() {
  5738. self.focus();
  5739. try {
  5740. self.exec(name, null);
  5741. } catch(e) {
  5742. alert(self.lang(name + 'Error'));
  5743. }
  5744. });
  5745. });
  5746. self.clickToolbar('about', function() {
  5747. var html = '<div style="margin:20px;">' +
  5748. '<div>KindEditor ' + _VERSION + '</div>' +
  5749. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5750. '</div>';
  5751. self.createDialog({
  5752. name : 'about',
  5753. width : 350,
  5754. title : self.lang('about'),
  5755. body : html
  5756. });
  5757. });
  5758. self.plugin.getSelectedLink = function() {
  5759. return self.cmd.commonAncestor('a');
  5760. };
  5761. self.plugin.getSelectedImage = function() {
  5762. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5763. return !/^ke-\w+$/i.test(img[0].className) && !img[0].getAttribute('data-key') && !img[0].getAttribute('data-applet') && !img[0].getAttribute('data-file');
  5764. });
  5765. };
  5766. self.plugin.getSelectedFlash = function() {
  5767. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5768. return img[0].className == 'ke-flash';
  5769. });
  5770. };
  5771. self.plugin.getSelectedMedia = function() {
  5772. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5773. return img[0].className == 'ke-media' || img[0].className == 'ke-rm' || img[0].getAttribute('data-file');
  5774. });
  5775. };
  5776. self.plugin.getSelectedDiy = function() {
  5777. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5778. return img[0].getAttribute('data-applet') || img[0].getAttribute('data-key');
  5779. });
  5780. };
  5781. self.plugin.getSelectedAnchor = function() {
  5782. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5783. return img[0].className == 'ke-anchor';
  5784. });
  5785. };
  5786. _each('diy,link,image,flash,media,anchor'.split(','), function(i, name) {
  5787. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5788. _each('edit,delete'.split(','), function(j, val) {
  5789. self.addContextmenu({
  5790. title : self.lang(val + uName),
  5791. click : function() {
  5792. self.loadPlugin(name, function() {
  5793. self.plugin[name][val]();
  5794. self.hideMenu();
  5795. });
  5796. },
  5797. cond : self.plugin['getSelected' + uName],
  5798. width : 150,
  5799. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5800. });
  5801. });
  5802. self.addContextmenu({ title : '-' });
  5803. });
  5804. self.plugin.getSelectedTable = function() {
  5805. return self.cmd.commonAncestor('table');
  5806. };
  5807. self.plugin.getSelectedRow = function() {
  5808. return self.cmd.commonAncestor('tr');
  5809. };
  5810. self.plugin.getSelectedCell = function() {
  5811. return self.cmd.commonAncestor('td');
  5812. };
  5813. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5814. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5815. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5816. self.addContextmenu({
  5817. title : self.lang('table' + val),
  5818. click : function() {
  5819. self.loadPlugin('table', function() {
  5820. self.plugin.table[val]();
  5821. self.hideMenu();
  5822. });
  5823. },
  5824. cond : cond,
  5825. width : 170,
  5826. iconClass : 'ke-icon-table' + val
  5827. });
  5828. });
  5829. self.addContextmenu({ title : '-' });
  5830. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5831. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5832. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5833. if (shortcutKeys[name]) {
  5834. self.afterCreate(function() {
  5835. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5836. self.cmd.selection();
  5837. self.clickToolbar(name);
  5838. });
  5839. });
  5840. }
  5841. self.clickToolbar(name, function() {
  5842. self.focus().exec(name, null);
  5843. });
  5844. });
  5845. self.afterCreate(function() {
  5846. var doc = self.edit.doc, cmd, bookmark, div,
  5847. cls = '__kindeditor_paste__', pasting = false;
  5848. function movePastedData() {
  5849. cmd.range.moveToBookmark(bookmark);
  5850. cmd.select();
  5851. if (_WEBKIT) {
  5852. K('div.' + cls, div).each(function() {
  5853. K(this).after('<br />').remove(true);
  5854. });
  5855. K('span.Apple-style-span', div).remove(true);
  5856. K('span.Apple-tab-span', div).remove(true);
  5857. K('span[style]', div).each(function() {
  5858. if (K(this).css('white-space') == 'nowrap') {
  5859. K(this).remove(true);
  5860. }
  5861. });
  5862. K('meta', div).remove();
  5863. }
  5864. var html = div[0].innerHTML;
  5865. div.remove();
  5866. if (html === '') {
  5867. return;
  5868. }
  5869. if (_WEBKIT) {
  5870. html = html.replace(/(<br>)\1/ig, '$1');
  5871. }
  5872. if (self.pasteType === 2) {
  5873. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5874. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5875. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5876. } else {
  5877. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5878. html = self.beforeSetHtml(html);
  5879. }
  5880. }
  5881. if (self.pasteType === 1) {
  5882. html = html.replace(/&nbsp;/ig, ' ');
  5883. html = html.replace(/\n\s*\n/g, '\n');
  5884. html = html.replace(/<br[^>]*>/ig, '\n');
  5885. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5886. html = html.replace(/<[^>]+>/g, '');
  5887. html = html.replace(/ {2}/g, ' &nbsp;');
  5888. if (self.newlineTag == 'p') {
  5889. if (/\n/.test(html)) {
  5890. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5891. }
  5892. } else {
  5893. html = html.replace(/\n/g, '<br />$&');
  5894. }
  5895. }
  5896. self.insertHtml(html, true);
  5897. autoImg(self);
  5898. }
  5899. K(doc.body).bind('paste', function(e){
  5900. //处理IE11,Chrome粘贴图片上传
  5901. function dopasteImg() {
  5902. //debugger;
  5903. var file = null;
  5904. if (window.clipboardData) {//ie
  5905. if (clipboardData.files && clipboardData.files.length)//IE11
  5906. file = clipboardData.files[0];
  5907. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5908. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5909. return true;
  5910. }
  5911. } else {
  5912. if (e.event.clipboardData.items)//chrome
  5913. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5914. if (e.event.clipboardData.items[i].kind === "file") {
  5915. file = e.event.clipboardData.items[i];
  5916. break;
  5917. }
  5918. }
  5919. if (file == null) {
  5920. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5921. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5922. return true;
  5923. }
  5924. }
  5925. }
  5926. if (file) {
  5927. if (!K.undef(self.allowImageUpload, true)) {
  5928. alert("编辑器禁止上传图片,请与有关人员联系!");
  5929. return true;
  5930. }
  5931. //获取File Blob
  5932. //debugger;
  5933. var blb;
  5934. if (file.getAsFile) {//Chrome
  5935. blb = file.getAsFile();
  5936. if (blb.size === 0) {
  5937. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5938. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5939. return true;
  5940. }
  5941. sendfile(blb, file.type);
  5942. } else {
  5943. var fr = new FileReader();
  5944. if (fr.readAsArrayBuffer) {//ie
  5945. fr.onloadend = function (evt) {
  5946. blb = evt.target.result;
  5947. sendfile(blb, file.type);
  5948. }
  5949. fr.readAsArrayBuffer(file);
  5950. }
  5951. }
  5952. function sendfile(b, t) {
  5953. var xhr = new XMLHttpRequest();
  5954. var formData = new FormData();
  5955. var isImg = t.indexOf("image/") === 0;
  5956. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5957. //formData.append('imgFile', b);
  5958. var myBlob = new Blob([b], { "type": t });
  5959. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5960. //formData.append('imgFile', b);
  5961. formData.append('dir', isImg ? 'image' : 'file');
  5962. if (self.uploadYunJson && self.uploadYunJson.domain) {
  5963. formData.append('token', self.uploadYunJson.token);
  5964. xhr.open('POST', self.uploadYunJson.domain);
  5965. } else {
  5966. xhr.open('POST', self.uploadJson);
  5967. }
  5968. xhr.onreadystatechange = function () {
  5969. if (xhr.readyState == 4&&xhr.status == 200) {
  5970. // if (fn) {
  5971. var data = _trim(xhr.responseText);
  5972. //if (dataType == 'json') {
  5973. data = _json(data);
  5974. if (data.error) {
  5975. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5976. $.messager.alert('Error', data.message, 'warning');
  5977. } else {
  5978. alert(data.message);
  5979. }
  5980. } else {
  5981. //self.exec('insertimage', url, title, width, height, border, align);
  5982. if(K.undef(self.formatUploadUrl, true))
  5983. data.url =K.formatUrl(data.url, 'absolute');
  5984. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5985. }
  5986. //}
  5987. // fn(data);
  5988. // }
  5989. }
  5990. }
  5991. xhr.send(formData);
  5992. }
  5993. return true;
  5994. }
  5995. }
  5996. //debugger;
  5997. if (dopasteImg())
  5998. e.stop();
  5999. //处理粘贴结束5825
  6000. if (self.pasteType === 0) {
  6001. e.stop();
  6002. return;
  6003. }
  6004. if (pasting) {
  6005. return;
  6006. }
  6007. pasting = true;
  6008. K('div.' + cls, doc).remove();
  6009. cmd = self.cmd.selection();
  6010. bookmark = cmd.range.createBookmark();
  6011. div = K('<div class="' + cls + '"></div>', doc).css({
  6012. position : 'absolute',
  6013. width : '1px',
  6014. height : '1px',
  6015. overflow : 'hidden',
  6016. left : '-1981px',
  6017. top : K(bookmark.start).pos().y + 'px',
  6018. 'white-space' : 'nowrap'
  6019. });
  6020. K(doc.body).append(div);
  6021. if (_IE) {
  6022. var rng = cmd.range.get(true);
  6023. rng.moveToElementText(div[0]);
  6024. rng.select();
  6025. rng.execCommand('paste');
  6026. e.preventDefault();
  6027. } else {
  6028. cmd.range.selectNodeContents(div[0]);
  6029. cmd.select();
  6030. div[0].tabIndex = -1;
  6031. div[0].focus();
  6032. }
  6033. setTimeout(function() {
  6034. movePastedData();
  6035. pasting = false;
  6036. }, 0);
  6037. });
  6038. });
  6039. self.beforeGetHtml(function(html) {
  6040. if (_IE && _V <= 8) {
  6041. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  6042. return unescape(tag);
  6043. });
  6044. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  6045. if (!/\s+type="[^"]+"/i.test($0)) {
  6046. return $1 + ' type="text"' + $2;
  6047. }
  6048. return $0;
  6049. });
  6050. }
  6051. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  6052. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  6053. })
  6054. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  6055. var imgAttrs = _getAttrList(full);
  6056. var styles = _getCssList(imgAttrs.style || '');
  6057. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6058. var width = _undef(styles.width, '');
  6059. var height = _undef(styles.height, '');
  6060. if (/px/i.test(width)) {
  6061. width = _removeUnit(width);
  6062. }
  6063. if (/px/i.test(height)) {
  6064. height = _removeUnit(height);
  6065. }
  6066. attrs.width = _undef(imgAttrs.width, width);
  6067. attrs.height = _undef(imgAttrs.height, height);
  6068. return _mediaEmbed(attrs);
  6069. })
  6070. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6071. var imgAttrs = _getAttrList(full);
  6072. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6073. })
  6074. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6075. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6076. })
  6077. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6078. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6079. })
  6080. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6081. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6082. return $1 + _unescape(src) + $2;
  6083. });
  6084. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6085. return full;
  6086. })
  6087. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6088. return start + end;
  6089. });
  6090. });
  6091. self.beforeSetHtml(function(html) {
  6092. if (_IE && _V <= 8) {
  6093. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6094. var attrs = _getAttrList(full);
  6095. var styles = _getCssList(attrs.style || '');
  6096. if (styles.display == 'none') {
  6097. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6098. }
  6099. return full;
  6100. });
  6101. }
  6102. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6103. var attrs = _getAttrList(full);
  6104. attrs.src = _undef(attrs.src, '');
  6105. attrs.width = _undef(attrs.width, 0);
  6106. attrs.height = _undef(attrs.height, 0);
  6107. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6108. })
  6109. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6110. var attrs = _getAttrList(full);
  6111. if (attrs.href !== undefined) {
  6112. return full;
  6113. }
  6114. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6115. })
  6116. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6117. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6118. })
  6119. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6120. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6121. })
  6122. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6123. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6124. return full;
  6125. }
  6126. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6127. return full;
  6128. })
  6129. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6130. return start + 'data-ke-' + end;
  6131. })
  6132. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6133. if (full.indexOf('ke-zeroborder') >= 0) {
  6134. return full;
  6135. }
  6136. return _addClassToTag(full, 'ke-zeroborder');
  6137. });
  6138. });
  6139. });
  6140. })(window);
  6141. /*******************************************************************************
  6142. * KindEditor - WYSIWYG HTML Editor for Internet
  6143. * Copyright (C) 2006-2011 kindsoft.net
  6144. *
  6145. * @author Roddy <luolonghao@gmail.com>
  6146. * @site http://www.kindsoft.net/
  6147. * @licence http://www.kindsoft.net/license.php
  6148. *******************************************************************************/
  6149. KindEditor.lang({
  6150. source : 'HTML代码',
  6151. preview : '预览',
  6152. undo : '后退(Ctrl+Z)',
  6153. redo : '前进(Ctrl+Y)',
  6154. cut : '剪切(Ctrl+X)',
  6155. copy : '复制(Ctrl+C)',
  6156. paste : '粘贴(Ctrl+V)',
  6157. plainpaste : '粘贴为无格式文本',
  6158. wordpaste : '从Word粘贴',
  6159. selectall : '全选(Ctrl+A)',
  6160. justifyleft : '左对齐',
  6161. justifycenter : '居中',
  6162. justifyright : '右对齐',
  6163. justifyfull : '两端对齐',
  6164. insertorderedlist : '编号',
  6165. insertunorderedlist : '项目符号',
  6166. indent : '增加缩进',
  6167. outdent : '减少缩进',
  6168. subscript : '下标',
  6169. superscript : '上标',
  6170. formatblock : '段落',
  6171. fontname : '字体',
  6172. fontsize : '文字大小',
  6173. fontheight : '文字间距',
  6174. forecolor : '文字颜色',
  6175. hilitecolor : '文字背景',
  6176. bold : '粗体(Ctrl+B)',
  6177. italic : '斜体(Ctrl+I)',
  6178. underline : '下划线(Ctrl+U)',
  6179. strikethrough : '删除线',
  6180. removeformat : '删除格式',
  6181. image : '图片',
  6182. multiimage : '批量图片上传',
  6183. flash : 'Flash',
  6184. media : '音频',
  6185. table : '表格',
  6186. tablecell : '单元格',
  6187. hr : '插入横线',
  6188. emoticons : '插入表情',
  6189. link : '超级链接',
  6190. unlink : '取消超级链接',
  6191. fullscreen : '全屏显示',
  6192. about : '关于',
  6193. print : '打印(Ctrl+P)',
  6194. filemanager : '文件库',
  6195. code : '插入程序代码',
  6196. map : 'Google地图',
  6197. baidumap : '百度地图',
  6198. lineheight : '行距',
  6199. clearhtml : '清理HTML代码',
  6200. pagebreak : '插入分页符',
  6201. quickformat : '一键排版',
  6202. insertfile : '插入文件',
  6203. template : '插入模板',
  6204. anchor : '锚点',
  6205. yes : '确定',
  6206. no : '取消',
  6207. close : '关闭',
  6208. editImage : '图片属性',
  6209. deleteImage : '删除图片',
  6210. editFlash : 'Flash属性',
  6211. deleteFlash : '删除Flash',
  6212. editMedia : '音频属性',
  6213. deleteMedia : '删除音频',
  6214. editLink : '超级链接属性',
  6215. deleteLink : '取消超级链接',
  6216. editAnchor : '锚点属性',
  6217. deleteAnchor : '删除锚点',
  6218. tableprop : '表格属性',
  6219. tablecellprop : '单元格属性',
  6220. tableinsert : '插入表格',
  6221. tabledelete : '删除表格',
  6222. tablecolinsertleft : '左侧插入列',
  6223. tablecolinsertright : '右侧插入列',
  6224. tablerowinsertabove : '上方插入行',
  6225. tablerowinsertbelow : '下方插入行',
  6226. tablerowmerge : '向下合并单元格',
  6227. tablecolmerge : '向右合并单元格',
  6228. tablerowsplit : '拆分行',
  6229. tablecolsplit : '拆分列',
  6230. tablecoldelete : '删除列',
  6231. tablerowdelete : '删除行',
  6232. noColor : '无颜色',
  6233. pleaseSelectFile : '请选择文件。',
  6234. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6235. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6236. invalidWidth : "宽度必须为数字。",
  6237. invalidHeight : "高度必须为数字。",
  6238. invalidBorder : "边框必须为数字。",
  6239. invalidUrl : "请输入有效的URL地址。",
  6240. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6241. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6242. invalidPadding : '边距必须为数字。',
  6243. invalidSpacing : '间距必须为数字。',
  6244. invalidJson : '服务器发生故障。',
  6245. uploadSuccess : '上传成功。',
  6246. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6247. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6248. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6249. ajaxLoading : '加载中,请稍候 ...',
  6250. uploadLoading : '上传中,请稍候 ...',
  6251. uploadError : '上传错误',
  6252. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6253. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6254. 'code.pleaseInput' : '请输入程序代码。',
  6255. 'link.url' : 'URL',
  6256. 'link.linkType' : '打开类型',
  6257. 'link.newWindow' : '新窗口',
  6258. 'link.selfWindow' : '当前窗口',
  6259. 'flash.url' : 'URL',
  6260. 'flash.width' : '宽度',
  6261. 'flash.height' : '高度',
  6262. 'flash.upload' : '上传',
  6263. 'flash.viewServer' : '文件空间',
  6264. 'media.url' : 'URL',
  6265. 'media.width' : '宽度',
  6266. 'media.height' : '高度',
  6267. 'media.autostart' : '自动播放',
  6268. 'media.upload' : '上传',
  6269. 'media.viewServer' : '文件空间',
  6270. 'image.remoteImage' : '网络图片',
  6271. 'image.localImage' : '本地上传',
  6272. 'image.remoteUrl' : '图片地址',
  6273. 'image.localUrl' : '上传文件',
  6274. 'image.size' : '图片大小',
  6275. 'image.width' : '宽',
  6276. 'image.height' : '高',
  6277. 'image.resetSize' : '重置大小',
  6278. 'image.align' : '对齐方式',
  6279. 'image.defaultAlign' : '默认方式',
  6280. 'image.leftAlign' : '左对齐',
  6281. 'image.rightAlign' : '右对齐',
  6282. 'image.imgTitle' : '图片说明',
  6283. 'image.upload' : '浏览...',
  6284. 'image.viewServer' : '图片空间',
  6285. //'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6286. 'multiimage.uploadDesc' : '',
  6287. 'multiimage.startUpload' : '开始上传',
  6288. 'multiimage.clearAll' : '全部清空',
  6289. 'multiimage.insertAll' : '全部插入',
  6290. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6291. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6292. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6293. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6294. 'multiimage.unknownError' : '发生异常,无法上传。',
  6295. 'multiimage.pending' : '等待上传',
  6296. 'multiimage.uploadError' : '上传失败',
  6297. 'filemanager.emptyFolder' : '空文件夹',
  6298. 'filemanager.moveup' : '移到上一级文件夹',
  6299. 'filemanager.viewType' : '显示方式:',
  6300. 'filemanager.viewImage' : '缩略图',
  6301. 'filemanager.listImage' : '详细信息',
  6302. 'filemanager.orderType' : '排序方式:',
  6303. 'filemanager.fileName' : '名称',
  6304. 'filemanager.fileSize' : '大小',
  6305. 'filemanager.fileType' : '类型',
  6306. 'insertfile.url' : 'URL',
  6307. 'insertfile.title' : '文件说明',
  6308. 'insertfile.upload' : '上传',
  6309. 'insertfile.viewServer' : '文件空间',
  6310. 'table.cells' : '单元格数',
  6311. 'table.rows' : '行数',
  6312. 'table.cols' : '列数',
  6313. 'table.size' : '大小',
  6314. 'table.width' : '宽度',
  6315. 'table.height' : '高度',
  6316. 'table.percent' : '%',
  6317. 'table.px' : 'px',
  6318. 'table.space' : '边距间距',
  6319. 'table.padding' : '边距',
  6320. 'table.spacing' : '间距',
  6321. 'table.align' : '对齐方式',
  6322. 'table.textAlign' : '水平对齐',
  6323. 'table.verticalAlign' : '垂直对齐',
  6324. 'table.alignDefault' : '默认',
  6325. 'table.alignLeft' : '左对齐',
  6326. 'table.alignCenter' : '居中',
  6327. 'table.alignRight' : '右对齐',
  6328. 'table.alignTop' : '顶部',
  6329. 'table.alignMiddle' : '中部',
  6330. 'table.alignBottom' : '底部',
  6331. 'table.alignBaseline' : '基线',
  6332. 'table.border' : '边框',
  6333. 'table.borderWidth' : '边框',
  6334. 'table.borderColor' : '颜色',
  6335. 'table.backgroundColor' : '背景颜色',
  6336. 'map.address' : '地址: ',
  6337. 'map.search' : '搜索',
  6338. 'baidumap.address' : '地址: ',
  6339. 'baidumap.search' : '搜索',
  6340. 'baidumap.insertDynamicMap' : '插入动态地图',
  6341. 'anchor.name' : '锚点名称',
  6342. 'formatblock.formatBlock' : {
  6343. h1 : '标题 1',
  6344. h2 : '标题 2',
  6345. h3 : '标题 3',
  6346. h4 : '标题 4',
  6347. p : '正 文'
  6348. },
  6349. 'fontname.fontName' : {
  6350. 'SimSun' : '宋体',
  6351. 'NSimSun' : '新宋体',
  6352. 'FangSong_GB2312' : '仿宋_GB2312',
  6353. 'KaiTi_GB2312' : '楷体_GB2312',
  6354. 'SimHei' : '黑体',
  6355. 'Microsoft YaHei' : '微软雅黑',
  6356. 'Arial' : 'Arial',
  6357. 'Arial Black' : 'Arial Black',
  6358. 'Times New Roman' : 'Times New Roman',
  6359. 'Courier New' : 'Courier New',
  6360. 'Tahoma' : 'Tahoma',
  6361. 'Verdana' : 'Verdana'
  6362. },
  6363. 'lineheight.lineHeight' : [
  6364. {'1' : '单倍行距'},
  6365. {'1.5' : '1.5倍行距'},
  6366. {'1.75' : '1.75倍行距'},
  6367. {'2' : '2倍行距'},
  6368. {'2.5' : '2.5倍行距'},
  6369. {'3' : '3倍行距'}
  6370. ],
  6371. 'template.selectTemplate' : '可选模板',
  6372. 'template.replaceContent' : '替换当前内容',
  6373. 'template.fileList' : {
  6374. '1.html' : '图片和文字',
  6375. '2.html' : '表格',
  6376. '3.html' : '项目编号'
  6377. }
  6378. }, 'zh-CN');
  6379. KindEditor.options.langType = 'zh-CN';
  6380. /*******************************************************************************
  6381. * KindEditor - WYSIWYG HTML Editor for Internet
  6382. * Copyright (C) 2006-2011 kindsoft.net
  6383. *
  6384. * @author Roddy <luolonghao@gmail.com>
  6385. * @site http://www.kindsoft.net/
  6386. * @licence http://www.kindsoft.net/license.php
  6387. *******************************************************************************/
  6388. KindEditor.plugin('anchor', function(K) {
  6389. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6390. self.plugin.anchor = {
  6391. edit : function() {
  6392. var html = ['<div style="padding:20px;">',
  6393. '<div class="ke-dialog-row">',
  6394. '<label for="keName">' + lang.name + '</label>',
  6395. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6396. '</div>',
  6397. '</div>'].join('');
  6398. var dialog = self.createDialog({
  6399. name : name,
  6400. width : 300,
  6401. title : self.lang(name),
  6402. body : html,
  6403. yesBtn : {
  6404. name : self.lang('yes'),
  6405. click : function(e) {
  6406. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6407. }
  6408. }
  6409. });
  6410. var div = dialog.div,
  6411. nameBox = K('input[name="name"]', div);
  6412. var img = self.plugin.getSelectedAnchor();
  6413. if (img) {
  6414. nameBox.val(unescape(img.attr('data-ke-name')));
  6415. }
  6416. nameBox[0].focus();
  6417. nameBox[0].select();
  6418. },
  6419. 'delete' : function() {
  6420. self.plugin.getSelectedAnchor().remove();
  6421. }
  6422. };
  6423. self.clickToolbar(name, self.plugin.anchor.edit);
  6424. });
  6425. /*******************************************************************************
  6426. * KindEditor - WYSIWYG HTML Editor for Internet
  6427. * Copyright (C) 2006-2011 kindsoft.net
  6428. *
  6429. * @author Roddy <luolonghao@gmail.com>
  6430. * @site http://www.kindsoft.net/
  6431. * @licence http://www.kindsoft.net/license.php
  6432. *******************************************************************************/
  6433. KindEditor.plugin('autoheight', function(K) {
  6434. var self = this;
  6435. if (!self.autoHeightMode) {
  6436. return;
  6437. }
  6438. var minHeight;
  6439. function hideScroll() {
  6440. var edit = self.edit;
  6441. var body = edit.doc.body;
  6442. edit.iframe[0].scroll = 'no';
  6443. body.style.overflowY = 'hidden';
  6444. }
  6445. function resetHeight() {
  6446. if(self.fullscreenMode){
  6447. return;
  6448. }
  6449. var edit = self.edit;
  6450. var body = edit.doc.body;
  6451. edit.iframe.height(minHeight);
  6452. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6453. }
  6454. function init() {
  6455. minHeight = K.removeUnit(self.height);
  6456. self.edit.afterChange(resetHeight);
  6457. if(!self.fullscreenMode){
  6458. hideScroll();
  6459. }
  6460. resetHeight();
  6461. }
  6462. if (self.isCreated) {
  6463. init();
  6464. } else {
  6465. self.afterCreate(init);
  6466. }
  6467. });
  6468. /*
  6469. * 如何实现真正的自动高度?
  6470. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6471. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6472. * 由此就实现了真正的自动高度
  6473. * 测试:chrome、firefox、IE9、IE8
  6474. * */
  6475. /*******************************************************************************
  6476. * KindEditor - WYSIWYG HTML Editor for Internet
  6477. * Copyright (C) 2006-2011 kindsoft.net
  6478. *
  6479. * @author Roddy <luolonghao@gmail.com>
  6480. * @site http://www.kindsoft.net/
  6481. * @licence http://www.kindsoft.net/license.php
  6482. *******************************************************************************/
  6483. KindEditor.plugin('baidumap', function(K) {
  6484. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6485. var mapWidth = K.undef(self.mapWidth, 558);
  6486. var mapHeight = K.undef(self.mapHeight, 360);
  6487. self.clickToolbar(name, function() {
  6488. var html = ['<div style="padding:10px 20px;">',
  6489. '<div class="ke-header">',
  6490. '<div class="ke-left">',
  6491. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6492. '<span class="ke-button-common ke-button-outer">',
  6493. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6494. '</span>',
  6495. '</div>',
  6496. '<div class="ke-right">',
  6497. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6498. '</div>',
  6499. '<div class="ke-clearfix"></div>',
  6500. '</div>',
  6501. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6502. '</div>'].join('');
  6503. var dialog = self.createDialog({
  6504. name : name,
  6505. width : mapWidth + 42,
  6506. title : self.lang(name),
  6507. body : html,
  6508. yesBtn : {
  6509. name : self.lang('yes'),
  6510. click : function(e) {
  6511. var map = win.map;
  6512. var centerObj = map.getCenter();
  6513. var center = centerObj.lng + ',' + centerObj.lat;
  6514. var zoom = map.getZoom();
  6515. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6516. '?center=' + encodeURIComponent(center),
  6517. '&zoom=' + encodeURIComponent(zoom),
  6518. '&width=' + mapWidth,
  6519. '&height=' + mapHeight,
  6520. '&markers=' + encodeURIComponent(center),
  6521. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6522. if (checkbox[0].checked) {
  6523. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6524. } else {
  6525. self.exec('insertimage', url);
  6526. }
  6527. self.hideDialog().focus();
  6528. }
  6529. },
  6530. beforeRemove : function() {
  6531. searchBtn.remove();
  6532. if (doc) {
  6533. doc.write('');
  6534. }
  6535. iframe.remove();
  6536. }
  6537. });
  6538. var div = dialog.div,
  6539. addressBox = K('[name="address"]', div),
  6540. searchBtn = K('[name="searchBtn"]', div),
  6541. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6542. win, doc;
  6543. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6544. function ready() {
  6545. win = iframe[0].contentWindow;
  6546. doc = K.iframeDoc(iframe);
  6547. }
  6548. iframe.bind('load', function() {
  6549. iframe.unbind('load');
  6550. if (K.IE) {
  6551. ready();
  6552. } else {
  6553. setTimeout(ready, 0);
  6554. }
  6555. });
  6556. K('.ke-map', div).replaceWith(iframe);
  6557. searchBtn.click(function() {
  6558. win.search(addressBox.val());
  6559. });
  6560. });
  6561. });
  6562. /*******************************************************************************
  6563. * KindEditor - WYSIWYG HTML Editor for Internet
  6564. * Copyright (C) 2006-2011 kindsoft.net
  6565. *
  6566. * @author Roddy <luolonghao@gmail.com>
  6567. * @site http://www.kindsoft.net/
  6568. * @licence http://www.kindsoft.net/license.php
  6569. *******************************************************************************/
  6570. KindEditor.plugin('map', function(K) {
  6571. var self = this, name = 'map', lang = self.lang(name + '.');
  6572. self.clickToolbar(name, function() {
  6573. var html = ['<div style="padding:10px 20px;">',
  6574. '<div class="ke-dialog-row">',
  6575. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6576. '<span class="ke-button-common ke-button-outer">',
  6577. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6578. '</span>',
  6579. '</div>',
  6580. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6581. '</div>'].join('');
  6582. var dialog = self.createDialog({
  6583. name : name,
  6584. width : 600,
  6585. title : self.lang(name),
  6586. body : html,
  6587. yesBtn : {
  6588. name : self.lang('yes'),
  6589. click : function(e) {
  6590. var geocoder = win.geocoder,
  6591. map = win.map,
  6592. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6593. zoom = map.getZoom(),
  6594. maptype = map.getMapTypeId(),
  6595. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6596. url += '?center=' + encodeURIComponent(center);
  6597. url += '&zoom=' + encodeURIComponent(zoom);
  6598. url += '&size=558x360';
  6599. url += '&maptype=' + encodeURIComponent(maptype);
  6600. url += '&markers=' + encodeURIComponent(center);
  6601. url += '&language=' + self.langType;
  6602. url += '&sensor=false';
  6603. self.exec('insertimage', url).hideDialog().focus();
  6604. }
  6605. },
  6606. beforeRemove : function() {
  6607. searchBtn.remove();
  6608. if (doc) {
  6609. doc.write('');
  6610. }
  6611. iframe.remove();
  6612. }
  6613. });
  6614. var div = dialog.div,
  6615. addressBox = K('[name="address"]', div),
  6616. searchBtn = K('[name="searchBtn"]', div),
  6617. win, doc;
  6618. var iframeHtml = ['<!doctype html><html><head>',
  6619. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6620. '<style>',
  6621. ' html { height: 100% }',
  6622. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6623. ' #map_canvas { height: 100% }',
  6624. '</style>',
  6625. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6626. '<script>',
  6627. 'var map, geocoder;',
  6628. 'function initialize() {',
  6629. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6630. ' var options = {',
  6631. ' zoom: 11,',
  6632. ' center: latlng,',
  6633. ' disableDefaultUI: true,',
  6634. ' panControl: true,',
  6635. ' zoomControl: true,',
  6636. ' mapTypeControl: true,',
  6637. ' scaleControl: true,',
  6638. ' streetViewControl: false,',
  6639. ' overviewMapControl: true,',
  6640. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6641. ' };',
  6642. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6643. ' geocoder = new google.maps.Geocoder();',
  6644. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6645. ' if (status == google.maps.GeocoderStatus.OK) {',
  6646. ' if (results[3]) {',
  6647. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6648. ' }',
  6649. ' }',
  6650. ' });',
  6651. '}',
  6652. 'function search(address) {',
  6653. ' if (!map) return;',
  6654. ' geocoder.geocode({address : address}, function(results, status) {',
  6655. ' if (status == google.maps.GeocoderStatus.OK) {',
  6656. ' map.setZoom(11);',
  6657. ' map.setCenter(results[0].geometry.location);',
  6658. ' var marker = new google.maps.Marker({',
  6659. ' map: map,',
  6660. ' position: results[0].geometry.location',
  6661. ' });',
  6662. ' } else {',
  6663. ' alert("Invalid address: " + address);',
  6664. ' }',
  6665. ' });',
  6666. '}',
  6667. '</script>',
  6668. '</head>',
  6669. '<body onload="initialize();">',
  6670. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6671. '</body></html>'].join('\n');
  6672. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6673. function ready() {
  6674. win = iframe[0].contentWindow;
  6675. doc = K.iframeDoc(iframe);
  6676. }
  6677. iframe.bind('load', function() {
  6678. iframe.unbind('load');
  6679. if (K.IE) {
  6680. ready();
  6681. } else {
  6682. setTimeout(ready, 0);
  6683. }
  6684. });
  6685. K('.ke-map', div).replaceWith(iframe);
  6686. searchBtn.click(function() {
  6687. win.search(addressBox.val());
  6688. });
  6689. });
  6690. });
  6691. /*******************************************************************************
  6692. * KindEditor - WYSIWYG HTML Editor for Internet
  6693. * Copyright (C) 2006-2011 kindsoft.net
  6694. *
  6695. * @author Roddy <luolonghao@gmail.com>
  6696. * @site http://www.kindsoft.net/
  6697. * @licence http://www.kindsoft.net/license.php
  6698. *******************************************************************************/
  6699. KindEditor.plugin('clearhtml', function(K) {
  6700. var self = this, name = 'clearhtml';
  6701. self.clickToolbar(name, function() {
  6702. self.focus();
  6703. var html = self.html();
  6704. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6705. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6706. html = K.formatHtml(html, {
  6707. a : ['href', 'target'],
  6708. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6709. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6710. table : ['border'],
  6711. 'td,th' : ['rowspan', 'colspan'],
  6712. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6713. });
  6714. self.html(html);
  6715. self.cmd.selection(true);
  6716. self.addBookmark();
  6717. });
  6718. });
  6719. /*******************************************************************************
  6720. * KindEditor - WYSIWYG HTML Editor for Internet
  6721. * Copyright (C) 2006-2011 kindsoft.net
  6722. *
  6723. * @author Roddy <luolonghao@gmail.com>
  6724. * @site http://www.kindsoft.net/
  6725. * @licence http://www.kindsoft.net/license.php
  6726. *******************************************************************************/
  6727. KindEditor.plugin('code', function(K) {
  6728. var self = this, name = 'code';
  6729. self.clickToolbar(name, function() {
  6730. var lang = self.lang(name + '.'),
  6731. html = ['<div style="padding:10px 20px;">',
  6732. '<div class="ke-dialog-row">',
  6733. '<select class="ke-code-type">',
  6734. '<option value="js">JavaScript</option>',
  6735. '<option value="html">HTML</option>',
  6736. '<option value="css">CSS</option>',
  6737. '<option value="php">PHP</option>',
  6738. '<option value="pl">Perl</option>',
  6739. '<option value="py">Python</option>',
  6740. '<option value="rb">Ruby</option>',
  6741. '<option value="java">Java</option>',
  6742. '<option value="vb">ASP/VB</option>',
  6743. '<option value="cpp">C/C++</option>',
  6744. '<option value="cs">C#</option>',
  6745. '<option value="xml">XML</option>',
  6746. '<option value="bsh">Shell</option>',
  6747. '<option value="">Other</option>',
  6748. '</select>',
  6749. '</div>',
  6750. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6751. '</div>'].join(''),
  6752. dialog = self.createDialog({
  6753. name : name,
  6754. width : 450,
  6755. title : self.lang(name),
  6756. body : html,
  6757. yesBtn : {
  6758. name : self.lang('yes'),
  6759. click : function(e) {
  6760. var type = K('.ke-code-type', dialog.div).val(),
  6761. code = textarea.val(),
  6762. cls = type === '' ? '' : ' lang-' + type,
  6763. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6764. if (K.trim(code) === '') {
  6765. alert(lang.pleaseInput);
  6766. textarea[0].focus();
  6767. return;
  6768. }
  6769. self.insertHtml(html).hideDialog().focus();
  6770. }
  6771. }
  6772. }),
  6773. textarea = K('textarea', dialog.div);
  6774. textarea[0].focus();
  6775. });
  6776. });
  6777. /*******************************************************************************
  6778. * KindEditor - WYSIWYG HTML Editor for Internet
  6779. * Copyright (C) 2006-2011 kindsoft.net
  6780. *
  6781. * @author Roddy <luolonghao@gmail.com>
  6782. * @site http://www.kindsoft.net/
  6783. * @licence http://www.kindsoft.net/license.php
  6784. *******************************************************************************/
  6785. KindEditor.plugin('emoticons', function(K) {
  6786. var self = this, name = 'emoticons',
  6787. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6788. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6789. currentPageNum = 1;
  6790. self.clickToolbar(name, function() {
  6791. var rows = 5, cols = 9, total = 135, startNum = 0,
  6792. cells = rows * cols, pages = Math.ceil(total / cells),
  6793. colsHalf = Math.floor(cols / 2),
  6794. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6795. elements = [],
  6796. menu = self.createMenu({
  6797. name : name,
  6798. beforeRemove : function() {
  6799. removeEvent();
  6800. }
  6801. });
  6802. menu.div.append(wrapperDiv);
  6803. var previewDiv, previewImg;
  6804. if (allowPreview) {
  6805. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6806. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6807. wrapperDiv.append(previewDiv);
  6808. previewDiv.append(previewImg);
  6809. }
  6810. function bindCellEvent(cell, j, num) {
  6811. if (previewDiv) {
  6812. cell.mouseover(function() {
  6813. if (j > colsHalf) {
  6814. previewDiv.css('left', 0);
  6815. previewDiv.css('right', '');
  6816. } else {
  6817. previewDiv.css('left', '');
  6818. previewDiv.css('right', 0);
  6819. }
  6820. previewImg.attr('src', path + num + '.gif');
  6821. K(this).addClass('ke-on');
  6822. });
  6823. } else {
  6824. cell.mouseover(function() {
  6825. K(this).addClass('ke-on');
  6826. });
  6827. }
  6828. cell.mouseout(function() {
  6829. K(this).removeClass('ke-on');
  6830. });
  6831. cell.click(function(e) {
  6832. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6833. e.stop();
  6834. });
  6835. }
  6836. function createEmoticonsTable(pageNum, parentDiv) {
  6837. var table = document.createElement('table');
  6838. parentDiv.append(table);
  6839. if (previewDiv) {
  6840. K(table).mouseover(function() {
  6841. previewDiv.show('block');
  6842. });
  6843. K(table).mouseout(function() {
  6844. previewDiv.hide();
  6845. });
  6846. elements.push(K(table));
  6847. }
  6848. table.className = 'ke-table';
  6849. table.cellPadding = 0;
  6850. table.cellSpacing = 0;
  6851. table.border = 0;
  6852. var num = (pageNum - 1) * cells + startNum;
  6853. for (var i = 0; i < rows; i++) {
  6854. var row = table.insertRow(i);
  6855. for (var j = 0; j < cols; j++) {
  6856. var cell = K(row.insertCell(j));
  6857. cell.addClass('ke-cell');
  6858. bindCellEvent(cell, j, num);
  6859. var span = K('<span class="ke-img"></span>')
  6860. .css('background-position', '-' + (24 * num) + 'px 0px')
  6861. .css('background-image', 'url(' + path + 'static.gif)');
  6862. cell.append(span);
  6863. elements.push(cell);
  6864. num++;
  6865. }
  6866. }
  6867. return table;
  6868. }
  6869. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6870. function removeEvent() {
  6871. K.each(elements, function() {
  6872. this.unbind();
  6873. });
  6874. }
  6875. var pageDiv;
  6876. function bindPageEvent(el, pageNum) {
  6877. el.click(function(e) {
  6878. removeEvent();
  6879. table.parentNode.removeChild(table);
  6880. pageDiv.remove();
  6881. table = createEmoticonsTable(pageNum, wrapperDiv);
  6882. createPageTable(pageNum);
  6883. currentPageNum = pageNum;
  6884. e.stop();
  6885. });
  6886. }
  6887. function createPageTable(currentPageNum) {
  6888. pageDiv = K('<div class="ke-page"></div>');
  6889. wrapperDiv.append(pageDiv);
  6890. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6891. if (currentPageNum !== pageNum) {
  6892. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6893. bindPageEvent(a, pageNum);
  6894. pageDiv.append(a);
  6895. elements.push(a);
  6896. } else {
  6897. pageDiv.append(K('@[' + pageNum + ']'));
  6898. }
  6899. pageDiv.append(K('@&nbsp;'));
  6900. }
  6901. }
  6902. createPageTable(currentPageNum);
  6903. });
  6904. });
  6905. /*******************************************************************************
  6906. * KindEditor - WYSIWYG HTML Editor for Internet
  6907. * Copyright (C) 2006-2011 kindsoft.net
  6908. *
  6909. * @author Roddy <luolonghao@gmail.com>
  6910. * @site http://www.kindsoft.net/
  6911. * @licence http://www.kindsoft.net/license.php
  6912. *******************************************************************************/
  6913. KindEditor.plugin('filemanager', function(K) {
  6914. var self = this, name = 'filemanager',
  6915. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6916. imgPath = self.pluginsPath + name + '/images/',
  6917. lang = self.lang(name + '.');
  6918. function makeFileTitle(filename, filesize, datetime) {
  6919. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6920. }
  6921. function bindTitle(el, data) {
  6922. if (data.is_dir) {
  6923. el.attr('title', data.filename);
  6924. } else {
  6925. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6926. }
  6927. }
  6928. self.plugin.filemanagerDialog = function(options) {
  6929. var width = K.undef(options.width, 650),
  6930. height = K.undef(options.height, 510),
  6931. dirName = K.undef(options.dirName, ''),
  6932. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6933. clickFn = options.clickFn;
  6934. var html = [
  6935. '<div style="padding:10px 20px;">',
  6936. '<div class="ke-plugin-filemanager-header">',
  6937. '<div class="ke-left">',
  6938. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6939. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6940. '</div>',
  6941. '<div class="ke-right">',
  6942. '标签 <input type="text" style="width:100px;" value="" name="viewTag">',
  6943. '分类 <select class="ke-inline-block" name="viewCate">',
  6944. '',
  6945. '</select> ',
  6946. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6947. '<option value="VIEW">' + lang.viewImage + '</option>',
  6948. '<option value="LIST">' + lang.listImage + '</option>',
  6949. '</select> ',
  6950. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6951. '<option value="NAME">' + lang.fileName + '</option>',
  6952. '<option value="SIZE">' + lang.fileSize + '</option>',
  6953. '<option value="TYPE">' + lang.fileType + '</option>',
  6954. '</select>',
  6955. '</div>',
  6956. '<div class="ke-clearfix"></div>',
  6957. '</div>',
  6958. '<div class="ke-plugin-filemanager-body"></div>',
  6959. '</div>'
  6960. ].join('');
  6961. var dialog = self.createDialog({
  6962. name : name,
  6963. width : width,
  6964. height : height,
  6965. title : self.lang(name),
  6966. body : html
  6967. }),
  6968. div = dialog.div,
  6969. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6970. moveupImg = K('[name="moveupImg"]', div),
  6971. moveupLink = K('[name="moveupLink"]', div),
  6972. viewServerBtn = K('[name="viewServer"]', div),
  6973. viewCateBox = K('[name="viewCate"]', div),
  6974. viewTagBox = K('[name="viewTag"]', div),
  6975. viewTypeBox = K('[name="viewType"]', div),
  6976. orderTypeBox = K('[name="orderType"]', div);
  6977. function reloadPage(path, order, func, cate, tag) {
  6978. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6979. if (cate) {
  6980. param += '&cate=' + cate;
  6981. }
  6982. if (tag) {
  6983. param += '&tag=' + tag;
  6984. }
  6985. dialog.showLoading(self.lang('ajaxLoading'));
  6986. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6987. dialog.hideLoading();
  6988. func(data);
  6989. });
  6990. }
  6991. var elList = [];
  6992. function bindEvent(el, result, data, createFunc) {
  6993. var fileUrl = K.formatUrl(result.current_url + data.file, 'absolute'),
  6994. dirPath = encodeURIComponent(result.current_dir_path + data.path + '/');
  6995. if (data.is_dir) {
  6996. el.click(function(e) {
  6997. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6998. });
  6999. } else if (data.is_photo) {
  7000. el.click(function(e) {
  7001. clickFn.call(this, fileUrl, data.file);
  7002. });
  7003. } else {
  7004. el.click(function(e) {
  7005. clickFn.call(this, fileUrl, data.file);
  7006. });
  7007. }
  7008. elList.push(el);
  7009. }
  7010. function createCommon(result, createFunc) {
  7011. K.each(elList, function() {
  7012. this.unbind();
  7013. });
  7014. moveupLink.unbind();
  7015. viewTypeBox.unbind();
  7016. orderTypeBox.unbind();
  7017. if (result.current_dir_path) {
  7018. moveupLink.click(function(e) {
  7019. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  7020. });
  7021. }
  7022. function changeFunc() {
  7023. if (viewTypeBox.val() == 'VIEW') {
  7024. reloadPage(result.current_dir_path, orderTypeBox.val(), createView, viewCateBox.val(), viewTagBox.val());
  7025. } else {
  7026. reloadPage(result.current_dir_path, orderTypeBox.val(), createList, viewCateBox.val(), viewTagBox.val());
  7027. }
  7028. }
  7029. viewTypeBox.change(changeFunc);
  7030. orderTypeBox.change(changeFunc);
  7031. viewCateBox.change(changeFunc);
  7032. bodyDiv.html('');
  7033. }
  7034. function createList(result) {
  7035. createCommon(result, createList);
  7036. var table = document.createElement('table');
  7037. table.className = 'ke-table';
  7038. table.cellPadding = 0;
  7039. table.cellSpacing = 0;
  7040. table.border = 0;
  7041. bodyDiv.append(table);
  7042. var fileList = result.file_list;
  7043. for (var i = 0, len = fileList.length; i < len; i++) {
  7044. var data = fileList[i], row = K(table.insertRow(i));
  7045. row.mouseover(function(e) {
  7046. K(this).addClass('ke-on');
  7047. })
  7048. .mouseout(function(e) {
  7049. K(this).removeClass('ke-on');
  7050. });
  7051. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  7052. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  7053. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  7054. if (!data.is_dir || data.has_file) {
  7055. row.css('cursor', 'pointer');
  7056. cell0.attr('title', data.filename);
  7057. bindEvent(cell0, result, data, createList);
  7058. } else {
  7059. cell0.attr('title', lang.emptyFolder);
  7060. }
  7061. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  7062. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  7063. }
  7064. }
  7065. function createView(result) {
  7066. createCommon(result, createView);
  7067. var fileList = result.file_list;
  7068. for (var i = 0, len = fileList.length; i < len; i++) {
  7069. var data = fileList[i],
  7070. div = K('<div class="ke-inline-block ke-item"></div>');
  7071. bodyDiv.append(div);
  7072. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7073. .mouseover(function(e) {
  7074. K(this).addClass('ke-on');
  7075. })
  7076. .mouseout(function(e) {
  7077. K(this).removeClass('ke-on');
  7078. });
  7079. div.append(photoDiv);
  7080. var fileUrl = result.current_url + data.file,
  7081. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7082. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7083. if (!data.is_dir || data.has_file) {
  7084. photoDiv.css('cursor', 'pointer');
  7085. bindTitle(photoDiv, data);
  7086. bindEvent(photoDiv, result, data, createView);
  7087. } else {
  7088. photoDiv.attr('title', lang.emptyFolder);
  7089. }
  7090. photoDiv.append(img);
  7091. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7092. }
  7093. }
  7094. viewTypeBox.val(viewType);
  7095. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7096. return dialog;
  7097. }
  7098. });
  7099. /*******************************************************************************
  7100. * KindEditor - WYSIWYG HTML Editor for Internet
  7101. * Copyright (C) 2006-2011 kindsoft.net
  7102. *
  7103. * @author Roddy <luolonghao@gmail.com>
  7104. * @site http://www.kindsoft.net/
  7105. * @licence http://www.kindsoft.net/license.php
  7106. *******************************************************************************/
  7107. KindEditor.plugin('flash', function(K) {
  7108. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7109. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7110. allowFileManager = K.undef(self.allowFileManager, false),
  7111. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7112. extraParams = K.undef(self.extraFileUploadParams, {}),
  7113. filePostName = K.undef(self.filePostName, 'imgFile'),
  7114. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7115. self.plugin.flash = {
  7116. edit : function() {
  7117. var html = [
  7118. '<div style="padding:20px;">',
  7119. '<div class="ke-dialog-row">',
  7120. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7121. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7122. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7123. '<span class="ke-button-common ke-button-outer">',
  7124. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7125. '</span>',
  7126. '</div>',
  7127. '<div class="ke-dialog-row">',
  7128. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7129. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7130. '</div>',
  7131. '<div class="ke-dialog-row">',
  7132. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7133. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7134. '</div>',
  7135. '</div>'
  7136. ].join('');
  7137. var dialog = self.createDialog({
  7138. name : name,
  7139. width : 450,
  7140. title : self.lang(name),
  7141. body : html,
  7142. yesBtn : {
  7143. name : self.lang('yes'),
  7144. click : function(e) {
  7145. var url = K.trim(urlBox.val()),
  7146. width = widthBox.val(),
  7147. height = heightBox.val();
  7148. if (url == 'http://' || K.invalidUrl(url)) {
  7149. alert(self.lang('invalidUrl'));
  7150. urlBox[0].focus();
  7151. return;
  7152. }
  7153. if (!/^\d*$/.test(width)) {
  7154. alert(self.lang('invalidWidth'));
  7155. widthBox[0].focus();
  7156. return;
  7157. }
  7158. if (!/^\d*$/.test(height)) {
  7159. alert(self.lang('invalidHeight'));
  7160. heightBox[0].focus();
  7161. return;
  7162. }
  7163. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7164. src : url,
  7165. type : K.mediaType('.swf'),
  7166. width : width,
  7167. height : height,
  7168. quality : 'high'
  7169. });
  7170. self.insertHtml(html).hideDialog().focus();
  7171. }
  7172. }
  7173. }),
  7174. div = dialog.div,
  7175. urlBox = K('[name="url"]', div),
  7176. viewServerBtn = K('[name="viewServer"]', div),
  7177. widthBox = K('[name="width"]', div),
  7178. heightBox = K('[name="height"]', div);
  7179. urlBox.val('http://');
  7180. if (allowFlashUpload) {
  7181. var uploadbutton = K.uploadbutton({
  7182. button : K('.ke-upload-button', div)[0],
  7183. fieldName : filePostName,
  7184. extraParams : extraParams,
  7185. url : K.addParam(uploadJson, 'dir=flash'),
  7186. afterUpload : function(data) {
  7187. dialog.hideLoading();
  7188. if (data.error === 0) {
  7189. var url = data.url;
  7190. if (formatUploadUrl) {
  7191. url = K.formatUrl(url, 'absolute');
  7192. }
  7193. urlBox.val(url);
  7194. if (self.afterUpload) {
  7195. self.afterUpload.call(self, url, data, name);
  7196. }
  7197. alert(self.lang('uploadSuccess'));
  7198. } else {
  7199. alert(data.message);
  7200. }
  7201. },
  7202. afterError : function(html) {
  7203. dialog.hideLoading();
  7204. self.errorDialog(html);
  7205. }
  7206. });
  7207. uploadbutton.fileBox.change(function(e) {
  7208. dialog.showLoading(self.lang('uploadLoading'));
  7209. uploadbutton.submit();
  7210. });
  7211. } else {
  7212. K('.ke-upload-button', div).hide();
  7213. }
  7214. if (allowFileManager) {
  7215. viewServerBtn.click(function(e) {
  7216. var clickFn = function(url, title, id) {
  7217. K('[name="url"]', div).val(url);
  7218. if (self.afterSelectFile) {
  7219. self.afterSelectFile.call(self, url);
  7220. }
  7221. };
  7222. var cur = K('[name="url"]', div).val();
  7223. editorShowUpload(cur, self.fileManagerJson, 'flash库', clickFn, this);
  7224. /*
  7225. self.loadPlugin('filemanager', function() {
  7226. self.plugin.filemanagerDialog({
  7227. viewType : 'LIST',
  7228. dirName : 'flash',
  7229. clickFn : function(url, title) {
  7230. if (self.dialogs.length > 1) {
  7231. K('[name="url"]', div).val(url);
  7232. if (self.afterSelectFile) {
  7233. self.afterSelectFile.call(self, url);
  7234. }
  7235. self.hideDialog();
  7236. }
  7237. }
  7238. });
  7239. });
  7240. */
  7241. });
  7242. } else {
  7243. viewServerBtn.hide();
  7244. }
  7245. var img = self.plugin.getSelectedFlash();
  7246. if (img) {
  7247. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7248. urlBox.val(attrs.src);
  7249. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7250. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7251. }
  7252. urlBox[0].focus();
  7253. urlBox[0].select();
  7254. },
  7255. 'delete' : function() {
  7256. self.plugin.getSelectedFlash().remove();
  7257. self.addBookmark();
  7258. }
  7259. };
  7260. self.clickToolbar(name, self.plugin.flash.edit);
  7261. });
  7262. /*******************************************************************************
  7263. * KindEditor - WYSIWYG HTML Editor for Internet
  7264. * Copyright (C) 2006-2011 kindsoft.net
  7265. *
  7266. * @author Roddy <luolonghao@gmail.com>
  7267. * @site http://www.kindsoft.net/
  7268. * @licence http://www.kindsoft.net/license.php
  7269. *******************************************************************************/
  7270. KindEditor.plugin('image', function(K) {
  7271. var self = this, name = 'image',
  7272. allowImageUpload = K.undef(self.allowImageUpload, true),
  7273. allowImageRemote = K.undef(self.allowImageRemote, true),
  7274. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7275. allowFileManager = K.undef(self.allowFileManager, false),
  7276. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7277. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7278. imgPath = self.pluginsPath + 'image/images/',
  7279. extraParams = K.undef(self.extraFileUploadParams, {}),
  7280. filePostName = K.undef(self.filePostName, 'imgFile'),
  7281. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7282. lang = self.lang(name + '.');
  7283. self.plugin.imageDialog = function(options) {
  7284. var imageUrl = options.imageUrl,
  7285. imageWidth = K.undef(options.imageWidth, ''),
  7286. imageHeight = K.undef(options.imageHeight, ''),
  7287. imageTitle = K.undef(options.imageTitle, ''),
  7288. imageAlign = K.undef(options.imageAlign, ''),
  7289. showRemote = K.undef(options.showRemote, true),
  7290. showLocal = K.undef(options.showLocal, true),
  7291. tabIndex = K.undef(options.tabIndex, 0),
  7292. clickFn = options.clickFn;
  7293. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7294. var hiddenElements = [];
  7295. for(var k in extraParams){
  7296. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7297. }
  7298. var html = [
  7299. '<div style="padding:20px;">',
  7300. '<div class="tabs"></div>',
  7301. '<div class="tab1" style="display:none;">',
  7302. '<div class="ke-dialog-row">',
  7303. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7304. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7305. '<span class="ke-button-common ke-button-outer">',
  7306. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7307. '</span>',
  7308. '</div>',
  7309. '<div class="ke-dialog-row">',
  7310. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7311. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7312. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7313. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7314. '</div>',
  7315. '<div class="ke-dialog-row">',
  7316. '<label style="width:60px;">' + lang.align + '</label>',
  7317. '<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="" />',
  7318. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7319. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7320. '</div>',
  7321. '<div class="ke-dialog-row">',
  7322. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7323. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7324. '</div>',
  7325. '</div>',
  7326. '<div class="tab2" style="display:none;">',
  7327. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7328. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7329. '<div class="ke-dialog-row">',
  7330. hiddenElements.join(''),
  7331. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7332. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7333. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7334. '</div>',
  7335. '</form>',
  7336. '</div>',
  7337. '</div>'
  7338. ].join('');
  7339. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7340. dialogHeight = showLocal && showRemote ? 300 : 250;
  7341. var dialog = self.createDialog({
  7342. name : name,
  7343. width : dialogWidth,
  7344. height : dialogHeight,
  7345. title : self.lang(name),
  7346. body : html,
  7347. yesBtn : {
  7348. name : self.lang('yes'),
  7349. click : function(e) {
  7350. if (dialog.isLoading) {
  7351. return;
  7352. }
  7353. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7354. if (uploadbutton.fileBox.val() == '') {
  7355. alert(self.lang('pleaseSelectFile'));
  7356. return;
  7357. }
  7358. dialog.showLoading(self.lang('uploadLoading'));
  7359. uploadbutton.submit();
  7360. localUrlBox.val('');
  7361. return;
  7362. }
  7363. var url = K.trim(urlBox.val()),
  7364. width = widthBox.val(),
  7365. height = heightBox.val(),
  7366. title = titleBox.val(),
  7367. align = '';
  7368. alignBox.each(function() {
  7369. if (this.checked) {
  7370. align = this.value;
  7371. return false;
  7372. }
  7373. });
  7374. if (url == 'http://' || K.invalidUrl(url)) {
  7375. alert(self.lang('invalidUrl'));
  7376. urlBox[0].focus();
  7377. return;
  7378. }
  7379. if (!/^\d*$/.test(width)) {
  7380. alert(self.lang('invalidWidth'));
  7381. widthBox[0].focus();
  7382. return;
  7383. }
  7384. if (!/^\d*$/.test(height)) {
  7385. alert(self.lang('invalidHeight'));
  7386. heightBox[0].focus();
  7387. return;
  7388. }
  7389. clickFn.call(self, url, title, width, height, 0, align);
  7390. }
  7391. },
  7392. beforeRemove : function() {
  7393. viewServerBtn.unbind();
  7394. widthBox.unbind();
  7395. heightBox.unbind();
  7396. refreshBtn.unbind();
  7397. }
  7398. }),
  7399. div = dialog.div;
  7400. var urlBox = K('[name="url"]', div),
  7401. localUrlBox = K('[name="localUrl"]', div),
  7402. viewServerBtn = K('[name="viewServer"]', div),
  7403. widthBox = K('.tab1 [name="width"]', div),
  7404. heightBox = K('.tab1 [name="height"]', div),
  7405. refreshBtn = K('.ke-refresh-btn', div),
  7406. titleBox = K('.tab1 [name="title"]', div),
  7407. alignBox = K('.tab1 [name="align"]', div);
  7408. var tabs;
  7409. if (showRemote && showLocal) {
  7410. tabs = K.tabs({
  7411. src : K('.tabs', div),
  7412. afterSelect : function(i) {}
  7413. });
  7414. tabs.add({
  7415. title : lang.remoteImage,
  7416. panel : K('.tab1', div)
  7417. });
  7418. tabs.add({
  7419. title : lang.localImage,
  7420. panel : K('.tab2', div)
  7421. });
  7422. tabs.select(1);
  7423. } else if (showRemote) {
  7424. K('.tab1', div).show();
  7425. } else if (showLocal) {
  7426. K('.tab2', div).show();
  7427. }
  7428. var uploadbutton = K.uploadbutton({
  7429. button : K('.ke-upload-button', div)[0],
  7430. fieldName : filePostName,
  7431. form : K('.ke-form', div),
  7432. target : target,
  7433. width: 60,
  7434. afterUpload : function(data) {
  7435. dialog.hideLoading();
  7436. if (data.error === 0) {
  7437. var url = data.url;
  7438. if (formatUploadUrl) {
  7439. url = K.formatUrl(url, 'absolute');
  7440. }
  7441. if (self.afterUpload) {
  7442. self.afterUpload.call(self, url, data, name);
  7443. }
  7444. if (!fillDescAfterUploadImage) {
  7445. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7446. } else {
  7447. K(".ke-dialog-row #remoteUrl", div).val(url);
  7448. K(".ke-tabs-li", div)[0].click();
  7449. K(".ke-refresh-btn", div).click();
  7450. }
  7451. } else {
  7452. alert(data.message);
  7453. }
  7454. },
  7455. afterError : function(html) {
  7456. dialog.hideLoading();
  7457. self.errorDialog(html);
  7458. }
  7459. });
  7460. uploadbutton.fileBox.change(function(e) {
  7461. localUrlBox.val(uploadbutton.fileBox.val());
  7462. });
  7463. if (allowFileManager) {
  7464. viewServerBtn.click(function(e) {
  7465. //clickFn.call(this, fileUrl, data.file);
  7466. var clickFn = function(url, title, id) {
  7467. K('[name="url"]', div).val(url);
  7468. if (self.afterSelectFile) {
  7469. self.afterSelectFile.call(self, url);
  7470. }
  7471. };
  7472. var cur = K('[name="url"]', div).val();
  7473. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  7474. /*
  7475. self.loadPlugin('filemanager', function() {
  7476. self.plugin.filemanagerDialog({
  7477. viewType : 'VIEW',
  7478. dirName : 'image',
  7479. clickFn : function(url, title) {
  7480. if (self.dialogs.length > 1) {
  7481. K('[name="url"]', div).val(url);
  7482. if (self.afterSelectFile) {
  7483. self.afterSelectFile.call(self, url);
  7484. }
  7485. self.hideDialog();
  7486. }
  7487. }
  7488. });
  7489. });
  7490. */
  7491. });
  7492. } else {
  7493. viewServerBtn.hide();
  7494. }
  7495. var originalWidth = 0, originalHeight = 0;
  7496. function setSize(width, height) {
  7497. widthBox.val(width);
  7498. heightBox.val(height);
  7499. originalWidth = width;
  7500. originalHeight = height;
  7501. }
  7502. refreshBtn.click(function(e) {
  7503. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7504. position : 'absolute',
  7505. visibility : 'hidden',
  7506. top : 0,
  7507. left : '-1000px'
  7508. });
  7509. tempImg.bind('load', function() {
  7510. setSize(tempImg.width(), tempImg.height());
  7511. tempImg.remove();
  7512. });
  7513. K(document.body).append(tempImg);
  7514. });
  7515. widthBox.change(function(e) {
  7516. if (originalWidth > 0) {
  7517. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7518. }
  7519. });
  7520. heightBox.change(function(e) {
  7521. if (originalHeight > 0) {
  7522. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7523. }
  7524. });
  7525. urlBox.val(options.imageUrl);
  7526. setSize(options.imageWidth, options.imageHeight);
  7527. titleBox.val(options.imageTitle);
  7528. alignBox.each(function() {
  7529. if (this.value === options.imageAlign) {
  7530. this.checked = true;
  7531. return false;
  7532. }
  7533. });
  7534. if (showRemote && tabIndex === 0) {
  7535. urlBox[0].focus();
  7536. urlBox[0].select();
  7537. }
  7538. return dialog;
  7539. };
  7540. self.plugin.image = {
  7541. edit : function() {
  7542. var img = self.plugin.getSelectedImage();
  7543. self.plugin.imageDialog({
  7544. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7545. imageWidth : img ? img.width() : '',
  7546. imageHeight : img ? img.height() : '',
  7547. imageTitle : img ? img.attr('title') : '',
  7548. imageAlign : img ? img.attr('align') : '',
  7549. showRemote : allowImageRemote,
  7550. showLocal : allowImageUpload,
  7551. tabIndex: img ? 0 : imageTabIndex,
  7552. clickFn : function(url, title, width, height, border, align) {
  7553. if (img) {
  7554. img.attr('src', url);
  7555. img.attr('data-ke-src', url);
  7556. img.attr('width', width);
  7557. img.attr('height', height);
  7558. img.attr('title', title);
  7559. img.attr('align', align);
  7560. img.attr('alt', title);
  7561. } else {
  7562. self.exec('insertimage', url, title, width, height, border, align);
  7563. }
  7564. setTimeout(function() {
  7565. self.hideDialog().focus();
  7566. }, 0);
  7567. }
  7568. });
  7569. },
  7570. 'delete' : function() {
  7571. var target = self.plugin.getSelectedImage();
  7572. if (target.parent().name == 'a') {
  7573. target = target.parent();
  7574. }
  7575. target.remove();
  7576. self.addBookmark();
  7577. }
  7578. };
  7579. self.clickToolbar(name, self.plugin.image.edit);
  7580. });
  7581. KindEditor.plugin('diy', function(K) {
  7582. var self = this, name = 'diy';
  7583. self.plugin.diy = {
  7584. edit : function() {
  7585. var value = self.plugin.getSelectedDiy();
  7586. if (value.attr('data-applet')) {
  7587. $('.update_show_editor').each(function(i)
  7588. {
  7589. var key = $(this).attr('key');
  7590. if (key.indexOf('http://') > -1) {
  7591. $(this).attr('data-value', value.attr('data-applet'));
  7592. $(this).click();
  7593. $(this).attr('data-value', '');
  7594. }
  7595. })
  7596. } else if (value.attr('data-key')) {
  7597. var data_key = value.attr('data-key');
  7598. $('.upload_show_editor').each(function(i)
  7599. {
  7600. var key = $(this).attr('key');
  7601. if (key == data_key) {
  7602. $(this).attr('data-value', value.attr('data-id'));
  7603. $(this).click();
  7604. $(this).attr('data-value', '');
  7605. }
  7606. })
  7607. }
  7608. },
  7609. 'delete' : function() {
  7610. var target = self.plugin.getSelectedDiy();
  7611. if (target.parent().name == 'a') {
  7612. target = target.parent();
  7613. }
  7614. target.remove();
  7615. self.addBookmark();
  7616. }
  7617. };
  7618. });
  7619. /*******************************************************************************
  7620. * KindEditor - WYSIWYG HTML Editor for Internet
  7621. * Copyright (C) 2006-2011 kindsoft.net
  7622. *
  7623. * @author Roddy <luolonghao@gmail.com>
  7624. * @site http://www.kindsoft.net/
  7625. * @licence http://www.kindsoft.net/license.php
  7626. *******************************************************************************/
  7627. KindEditor.plugin('insertfile', function(K) {
  7628. var self = this, name = 'insertfile',
  7629. allowFileUpload = K.undef(self.allowFileUpload, true),
  7630. allowFileManager = K.undef(self.allowFileManager, false),
  7631. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7632. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7633. extraParams = K.undef(self.extraFileUploadParams, {}),
  7634. filePostName = K.undef(self.filePostName, 'imgFile'),
  7635. lang = self.lang(name + '.');
  7636. self.plugin.fileDialog = function(options) {
  7637. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7638. fileTitle = K.undef(options.fileTitle, ''),
  7639. clickFn = options.clickFn;
  7640. var html = [
  7641. '<div style="padding:20px;">',
  7642. '<div class="ke-dialog-row">',
  7643. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7644. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7645. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7646. '<span class="ke-button-common ke-button-outer">',
  7647. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7648. '</span>',
  7649. '</div>',
  7650. '<div class="ke-dialog-row">',
  7651. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7652. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7653. '</div>',
  7654. '</form>',
  7655. '</div>'
  7656. ].join('');
  7657. var dialog = self.createDialog({
  7658. name : name,
  7659. width : 450,
  7660. title : self.lang(name),
  7661. body : html,
  7662. yesBtn : {
  7663. name : self.lang('yes'),
  7664. click : function(e) {
  7665. var url = K.trim(urlBox.val()),
  7666. title = titleBox.val();
  7667. if (url == 'http://' || K.invalidUrl(url)) {
  7668. alert(self.lang('invalidUrl'));
  7669. urlBox[0].focus();
  7670. return;
  7671. }
  7672. if (K.trim(title) === '') {
  7673. title = url;
  7674. }
  7675. clickFn.call(self, url, title);
  7676. }
  7677. }
  7678. }),
  7679. div = dialog.div;
  7680. var urlBox = K('[name="url"]', div),
  7681. viewServerBtn = K('[name="viewServer"]', div),
  7682. titleBox = K('[name="title"]', div);
  7683. if (allowFileUpload) {
  7684. var uploadbutton = K.uploadbutton({
  7685. button : K('.ke-upload-button', div)[0],
  7686. fieldName : filePostName,
  7687. url : K.addParam(uploadJson, 'dir=file'),
  7688. extraParams : extraParams,
  7689. afterUpload : function(data) {
  7690. dialog.hideLoading();
  7691. if (data.error === 0) {
  7692. var url = data.url;
  7693. if (formatUploadUrl) {
  7694. url = K.formatUrl(url, 'absolute');
  7695. }
  7696. urlBox.val(url);
  7697. if (self.afterUpload) {
  7698. self.afterUpload.call(self, url, data, name);
  7699. }
  7700. alert(self.lang('uploadSuccess'));
  7701. } else {
  7702. alert(data.message);
  7703. }
  7704. },
  7705. afterError : function(html) {
  7706. dialog.hideLoading();
  7707. self.errorDialog(html);
  7708. }
  7709. });
  7710. uploadbutton.fileBox.change(function(e) {
  7711. dialog.showLoading(self.lang('uploadLoading'));
  7712. uploadbutton.submit();
  7713. });
  7714. } else {
  7715. K('.ke-upload-button', div).hide();
  7716. }
  7717. if (allowFileManager) {
  7718. viewServerBtn.click(function(e) {
  7719. var clickFn = function(url, title, id) {
  7720. K('[name="url"]', div).val(url);
  7721. if (self.afterSelectFile) {
  7722. self.afterSelectFile.call(self, url);
  7723. }
  7724. };
  7725. var cur = K('[name="url"]', div).val();
  7726. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '文件库', clickFn, this);
  7727. /*
  7728. self.loadPlugin('filemanager', function() {
  7729. self.plugin.filemanagerDialog({
  7730. viewType : 'LIST',
  7731. dirName : 'file',
  7732. clickFn : function(url, title) {
  7733. if (self.dialogs.length > 1) {
  7734. self.hideDialog();
  7735. }
  7736. }
  7737. });
  7738. });
  7739. */
  7740. });
  7741. } else {
  7742. viewServerBtn.hide();
  7743. }
  7744. urlBox.val(fileUrl);
  7745. titleBox.val(fileTitle);
  7746. urlBox[0].focus();
  7747. urlBox[0].select();
  7748. };
  7749. self.clickToolbar(name, function() {
  7750. self.plugin.fileDialog({
  7751. clickFn : function(url, title) {
  7752. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7753. self.insertHtml(html).hideDialog().focus();
  7754. }
  7755. });
  7756. });
  7757. });
  7758. /*******************************************************************************
  7759. * KindEditor - WYSIWYG HTML Editor for Internet
  7760. * Copyright (C) 2006-2011 kindsoft.net
  7761. *
  7762. * @author Roddy <luolonghao@gmail.com>
  7763. * @site http://www.kindsoft.net/
  7764. * @licence http://www.kindsoft.net/license.php
  7765. *******************************************************************************/
  7766. KindEditor.plugin('lineheight', function(K) {
  7767. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7768. self.clickToolbar(name, function() {
  7769. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7770. if (commonNode) {
  7771. curVal = commonNode.css('line-height');
  7772. }
  7773. var menu = self.createMenu({
  7774. name : name,
  7775. width : 150
  7776. });
  7777. K.each(lang.lineHeight, function(i, row) {
  7778. K.each(row, function(key, val) {
  7779. menu.addItem({
  7780. title : val,
  7781. checked : curVal === key,
  7782. click : function() {
  7783. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7784. span : '.line-height=' + key
  7785. });
  7786. self.updateState();
  7787. self.addBookmark();
  7788. self.hideMenu();
  7789. }
  7790. });
  7791. });
  7792. });
  7793. });
  7794. });
  7795. /*******************************************************************************
  7796. * KindEditor - WYSIWYG HTML Editor for Internet
  7797. * Copyright (C) 2006-2011 kindsoft.net
  7798. *
  7799. * @author Roddy <luolonghao@gmail.com>
  7800. * @site http://www.kindsoft.net/
  7801. * @licence http://www.kindsoft.net/license.php
  7802. *******************************************************************************/
  7803. KindEditor.plugin('link', function(K) {
  7804. var self = this, name = 'link';
  7805. self.plugin.link = {
  7806. edit : function() {
  7807. var lang = self.lang(name + '.'),
  7808. html = '<div style="padding:20px;">' +
  7809. '<div class="ke-dialog-row">' +
  7810. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7811. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7812. '<div class="ke-dialog-row"">' +
  7813. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7814. '<select id="keType" name="type"></select>' +
  7815. '</div>' +
  7816. '</div>',
  7817. dialog = self.createDialog({
  7818. name : name,
  7819. width : 450,
  7820. title : self.lang(name),
  7821. body : html,
  7822. yesBtn : {
  7823. name : self.lang('yes'),
  7824. click : function(e) {
  7825. var url = K.trim(urlBox.val());
  7826. if (url == 'http://' || K.invalidUrl(url)) {
  7827. alert(self.lang('invalidUrl'));
  7828. urlBox[0].focus();
  7829. return;
  7830. }
  7831. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7832. }
  7833. }
  7834. }),
  7835. div = dialog.div,
  7836. urlBox = K('input[name="url"]', div),
  7837. typeBox = K('select[name="type"]', div);
  7838. urlBox.val('http://');
  7839. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7840. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7841. self.cmd.selection();
  7842. var a = self.plugin.getSelectedLink();
  7843. if (a) {
  7844. self.cmd.range.selectNode(a[0]);
  7845. //self.cmd.select();
  7846. urlBox.val(a.attr('data-ke-src'));
  7847. typeBox.val(a.attr('target'));
  7848. }
  7849. urlBox[0].focus();
  7850. urlBox[0].select();
  7851. },
  7852. 'delete' : function() {
  7853. self.exec('unlink', null);
  7854. }
  7855. };
  7856. self.clickToolbar(name, self.plugin.link.edit);
  7857. });
  7858. /*******************************************************************************
  7859. * KindEditor - WYSIWYG HTML Editor for Internet
  7860. * Copyright (C) 2006-2011 kindsoft.net
  7861. *
  7862. * @author Roddy <luolonghao@gmail.com>
  7863. * @site http://www.kindsoft.net/
  7864. * @licence http://www.kindsoft.net/license.php
  7865. *******************************************************************************/
  7866. KindEditor.plugin('media', function(K) {
  7867. var self = this, name = 'media', lang = self.lang(name + '.'),
  7868. allowFileUpload = K.undef(self.allowFileUpload, true),
  7869. allowFileManager = K.undef(self.allowFileManager, false),
  7870. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7871. allowFileManager = K.undef(self.allowFileManager, false),
  7872. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7873. extraParams = K.undef(self.extraFileUploadParams, {}),
  7874. uploadCoverJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7875. filePostName = K.undef(self.filePostName, 'imgFile'),
  7876. uploadJson = K.undef(self.uploadMediaJson, self.basePath + 'php/upload_json.php');
  7877. if (self.uploadYunJson && self.uploadYunJson.domain) {
  7878. uploadJson = self.uploadYunJson.domain;
  7879. extraParams.token = self.uploadYunJson.token;
  7880. extraParams.key = self.uploadYunJson.path;
  7881. }
  7882. self.plugin.media = {
  7883. edit : function() {
  7884. var html = [
  7885. '<div style="padding:20px;">',
  7886. '<div class="ke-dialog-row">',
  7887. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7888. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7889. '<input type="button" class="ke-upload-button ke-upload-button-media" value="' + lang.upload + '" /> &nbsp;',
  7890. '<span class="ke-button-common ke-button-outer">',
  7891. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7892. '</span>',
  7893. '</div>',
  7894. '<div class="ke-dialog-row">',
  7895. '<label for="keWidth" style="width:60px;">标题</label>',
  7896. '<input type="text" id="keName" class="ke-input-text" style="width:160px;" name="name" value="" maxlength="30" />&nbsp;&nbsp;&nbsp;宽高:<input type="text" id="keWh" class="ke-input-text" style="width:100px;" name="wh" value="200px*200px" maxlength="100" />',
  7897. '</div>',
  7898. '<div class="ke-dialog-row">',
  7899. '<label for="keUrl" style="width:60px;">封面</label>',
  7900. '<input class="ke-input-text" type="text" id="keUrlCover" name="cover_url" value="" style="width:160px;" /> &nbsp;',
  7901. '<input type="button" class="ke-upload-button ke-upload-button-cover" value="' + lang.upload + '" /> &nbsp;',
  7902. '<span class="ke-button-common ke-button-outer">',
  7903. '<input type="button" class="ke-button-common ke-button" name="viewCoverServer" value="' + lang.viewServer + '" />',
  7904. '</span>',
  7905. '<br /><br />(封面要求:音频封面图片尺寸200*200px或等比尺寸,视频封面图片尺寸为视频实际尺寸或者等比尺寸,上传大小不能超过2M,建议上传JPG格式)',
  7906. '</div>',
  7907. '<div class="ke-dialog-row" style="display:none;">',
  7908. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7909. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="200" maxlength="4" />',
  7910. '<div style="display: inline;margin-left: 20px;">',
  7911. '<label for="keHeight" >' + lang.height + '</label>',
  7912. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="200" maxlength="4" />',
  7913. '</div>',
  7914. '</div>',
  7915. '<div class="ke-dialog-row" style="display:none;">',
  7916. '<label for="keAutostart">' + lang.autostart + '</label>',
  7917. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7918. '</div>',
  7919. '</div>'
  7920. ].join('');
  7921. var dialog = self.createDialog({
  7922. name : name,
  7923. width : 450,
  7924. height : 230,
  7925. title : self.lang(name),
  7926. body : html,
  7927. yesBtn : {
  7928. name : self.lang('yes'),
  7929. click : function(e) {
  7930. var url = K.trim(urlBox.val()),
  7931. coverUrl = K.trim(coverUrlBox.val()),
  7932. name = nameBox.val(),
  7933. wh = whBox.val(),
  7934. width = widthBox.val(),
  7935. height = heightBox.val();
  7936. var temp = wh.split('*');
  7937. width = temp[0];
  7938. height = temp[1];
  7939. if (url == 'http://' || K.invalidUrl(url)) {
  7940. alert(self.lang('invalidUrl'));
  7941. urlBox[0].focus();
  7942. return;
  7943. }
  7944. if (!name) {
  7945. alert('请填写标题');
  7946. urlBox[0].focus();
  7947. return;
  7948. }
  7949. if (!wh) {
  7950. alert('请填写宽高');
  7951. urlBox[0].focus();
  7952. return;
  7953. }
  7954. if (coverUrl == 'http://' || K.invalidUrl(coverUrl)) {
  7955. alert('请上传封面');
  7956. urlBox[0].focus();
  7957. return;
  7958. }
  7959. /*
  7960. if (!/^\d*$/.test(width)) {
  7961. alert(self.lang('invalidWidth'));
  7962. widthBox[0].focus();
  7963. return;
  7964. }
  7965. if (!/^\d*$/.test(height)) {
  7966. alert(self.lang('invalidHeight'));
  7967. heightBox[0].focus();
  7968. return;
  7969. }
  7970. */
  7971. if (!coverUrl) {
  7972. var cover = self.themesPath + 'common/blank.gif';
  7973. } else {
  7974. var cover = coverUrl;
  7975. }
  7976. /*
  7977. var html = K.mediaImg(cover, {
  7978. src : url,
  7979. type : K.mediaType(url),
  7980. width : width,
  7981. height : height,
  7982. autostart : autostartBox[0].checked ? 'true' : 'false',
  7983. loop : 'true'
  7984. });
  7985. */
  7986. var html = '<img src="'+cover+'" style="width:'+width+';height:'+height+';" data-file="'+url+'||'+name+'||'+wh+'"/>';
  7987. self.insertHtml(html).hideDialog().focus();
  7988. }
  7989. }
  7990. }),
  7991. div = dialog.div,
  7992. nameBox = K('[name="name"]', div),
  7993. whBox = K('[name="wh"]', div),
  7994. coverUrlBox = K('[name="cover_url"]', div),
  7995. viewCoverServerBtn = K('[name="viewCoverServer"]', div),
  7996. urlBox = K('[name="url"]', div),
  7997. viewServerBtn = K('[name="viewServer"]', div),
  7998. widthBox = K('[name="width"]', div),
  7999. heightBox = K('[name="height"]', div),
  8000. autostartBox = K('[name="autostart"]', div);
  8001. urlBox.val('http://');
  8002. coverUrlBox.val('http://');
  8003. if (allowMediaUpload) {
  8004. var uploadbutton = K.uploadbutton({
  8005. button : K('.ke-upload-button-media', div)[0],
  8006. fieldName : filePostName,
  8007. extraParams : extraParams,
  8008. url : K.addParam(uploadJson, 'dir=media'),
  8009. afterUpload : function(data) {
  8010. console.info(data);
  8011. dialog.hideLoading();
  8012. if (data.error === 0) {
  8013. var url = data.url;
  8014. if (formatUploadUrl) {
  8015. url = K.formatUrl(url, 'absolute');
  8016. }
  8017. urlBox.val(url);
  8018. if (self.afterUpload) {
  8019. self.afterUpload.call(self, url, data, name);
  8020. }
  8021. alert(self.lang('uploadSuccess'));
  8022. } else {
  8023. alert(data.message);
  8024. }
  8025. },
  8026. afterError : function(html) {
  8027. dialog.hideLoading();
  8028. self.errorDialog(html);
  8029. }
  8030. });
  8031. uploadbutton.fileBox.change(function(e) {
  8032. dialog.showLoading(self.lang('uploadLoading'));
  8033. uploadbutton.submit(this);
  8034. });
  8035. } else {
  8036. K('.ke-upload-button-media', div).hide();
  8037. }
  8038. if (allowFileUpload) {
  8039. var uploadbuttonCover = K.uploadbutton({
  8040. button : K('.ke-upload-button-cover', div)[0],
  8041. fieldName : filePostName,
  8042. url : K.addParam(uploadCoverJson, 'dir=file'),
  8043. extraParams : extraParams,
  8044. afterUpload : function(data) {
  8045. dialog.hideLoading();
  8046. if (data.error === 0) {
  8047. var url = data.url;
  8048. if (formatUploadUrl) {
  8049. url = K.formatUrl(url, 'absolute');
  8050. }
  8051. coverUrlBox.val(url);
  8052. if (self.afterUpload) {
  8053. self.afterUpload.call(self, url, data, name);
  8054. }
  8055. alert(self.lang('uploadSuccess'));
  8056. } else {
  8057. alert(data.message);
  8058. }
  8059. },
  8060. afterError : function(html) {
  8061. dialog.hideLoading();
  8062. self.errorDialog(html);
  8063. }
  8064. });
  8065. uploadbuttonCover.fileBox.change(function(e) {
  8066. dialog.showLoading(self.lang('uploadLoading'));
  8067. uploadbuttonCover.submit();
  8068. });
  8069. } else {
  8070. K('.ke-upload-button-cover', div).hide();
  8071. }
  8072. if (allowFileManager) {
  8073. viewServerBtn.click(function(e) {
  8074. var clickFn = function(url, title, id) {
  8075. K('[name="url"]', div).val(url);
  8076. if (self.afterSelectFile) {
  8077. self.afterSelectFile.call(self, url);
  8078. }
  8079. };
  8080. var cur = K('[name="url"]', div).val();
  8081. editorShowUpload(cur, self.fileManagerJson, '音频库', clickFn, this);
  8082. /*
  8083. self.loadPlugin('filemanager', function() {
  8084. self.plugin.filemanagerDialog({
  8085. viewType : 'LIST',
  8086. dirName : 'media',
  8087. clickFn : function(url, title) {
  8088. if (self.dialogs.length > 1) {
  8089. K('[name="url"]', div).val(url);
  8090. if (self.afterSelectFile) {
  8091. self.afterSelectFile.call(self, url);
  8092. }
  8093. self.hideDialog();
  8094. }
  8095. }
  8096. });
  8097. });
  8098. */
  8099. });
  8100. viewCoverServerBtn.click(function(e) {
  8101. var clickFn = function(url, title, id) {
  8102. coverUrlBox.val(url);
  8103. if (self.afterSelectFile) {
  8104. self.afterSelectFile.call(self, url);
  8105. }
  8106. };
  8107. var cur = coverUrlBox.val();
  8108. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  8109. /*
  8110. self.loadPlugin('filemanager', function() {
  8111. self.plugin.filemanagerDialog({
  8112. viewType : 'LIST',
  8113. dirName : 'file',
  8114. clickFn : function(url, title) {
  8115. if (self.dialogs.length > 1) {
  8116. self.hideDialog();
  8117. }
  8118. }
  8119. });
  8120. });
  8121. */
  8122. });
  8123. } else {
  8124. viewServerBtn.hide();
  8125. viewCoverServerBtn.hide();
  8126. }
  8127. var img = self.plugin.getSelectedMedia();
  8128. if (img) {
  8129. if (img.attr('data-file')) {
  8130. var temp = img.attr('data-file').split('||');
  8131. nameBox.val(temp[1]);
  8132. whBox.val(temp[2]);
  8133. urlBox.val(temp[0]);
  8134. coverUrlBox.val(img.attr('src'));
  8135. } else {
  8136. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  8137. urlBox.val(attrs.src);
  8138. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  8139. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  8140. autostartBox[0].checked = (attrs.autostart === 'true');
  8141. }
  8142. }
  8143. urlBox[0].focus();
  8144. urlBox[0].select();
  8145. },
  8146. 'delete' : function() {
  8147. self.plugin.getSelectedMedia().remove();
  8148. self.addBookmark();
  8149. }
  8150. };
  8151. self.clickToolbar(name, self.plugin.media.edit);
  8152. });
  8153. /*******************************************************************************
  8154. * KindEditor - WYSIWYG HTML Editor for Internet
  8155. * Copyright (C) 2006-2011 kindsoft.net
  8156. *
  8157. * @author Roddy <luolonghao@gmail.com>
  8158. * @site http://www.kindsoft.net/
  8159. * @licence http://www.kindsoft.net/license.php
  8160. *******************************************************************************/
  8161. (function(K) {
  8162. function KSWFUpload(options) {
  8163. this.init(options);
  8164. }
  8165. K.extend(KSWFUpload, {
  8166. init : function(options) {
  8167. var self = this;
  8168. options.afterError = options.afterError || function(str) {
  8169. alert(str);
  8170. };
  8171. self.options = options;
  8172. self.progressbars = {};
  8173. self.div = K(options.container).html([
  8174. '<div class="ke-swfupload">',
  8175. '<div class="ke-swfupload-top">',
  8176. '<div class="ke-inline-block ke-swfupload-button">',
  8177. '<input type="button" value="Browse" />',
  8178. '</div>',
  8179. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  8180. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  8181. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  8182. '</span>',
  8183. '</div>',
  8184. '<div class="ke-swfupload-body"></div>',
  8185. '</div>'
  8186. ].join(''));
  8187. self.bodyDiv = K('.ke-swfupload-body', self.div);
  8188. function showError(itemDiv, msg) {
  8189. K('.ke-status > div', itemDiv).hide();
  8190. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  8191. }
  8192. var settings = {
  8193. debug : false,
  8194. upload_url : options.uploadUrl,
  8195. flash_url : options.flashUrl,
  8196. file_post_name : options.filePostName,
  8197. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  8198. button_image_url: options.buttonImageUrl,
  8199. button_width: options.buttonWidth,
  8200. button_height: options.buttonHeight,
  8201. button_cursor : SWFUpload.CURSOR.HAND,
  8202. file_types : options.fileTypes,
  8203. file_types_description : options.fileTypesDesc,
  8204. file_upload_limit : options.fileUploadLimit,
  8205. file_size_limit : options.fileSizeLimit,
  8206. post_params : options.postParams,
  8207. file_queued_handler : function(file) {
  8208. file.url = self.options.fileIconUrl;
  8209. self.appendFile(file);
  8210. },
  8211. file_queue_error_handler : function(file, errorCode, message) {
  8212. var errorName = '';
  8213. switch (errorCode) {
  8214. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  8215. errorName = options.queueLimitExceeded;
  8216. break;
  8217. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  8218. errorName = options.fileExceedsSizeLimit;
  8219. break;
  8220. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  8221. errorName = options.zeroByteFile;
  8222. break;
  8223. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  8224. errorName = options.invalidFiletype;
  8225. break;
  8226. default:
  8227. errorName = options.unknownError;
  8228. break;
  8229. }
  8230. K.DEBUG && alert(errorName);
  8231. },
  8232. upload_start_handler : function(file) {
  8233. var self = this;
  8234. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  8235. K('.ke-status > div', itemDiv).hide();
  8236. K('.ke-progressbar', itemDiv).show();
  8237. },
  8238. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  8239. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  8240. var progressbar = self.progressbars[file.id];
  8241. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  8242. progressbar.percent.html(percent + '%');
  8243. },
  8244. upload_error_handler : function(file, errorCode, message) {
  8245. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  8246. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8247. showError(itemDiv, self.options.errorMessage);
  8248. }
  8249. },
  8250. upload_success_handler : function(file, serverData) {
  8251. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8252. var data = {};
  8253. try {
  8254. data = K.json(serverData);
  8255. } catch (e) {
  8256. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  8257. }
  8258. if (data.error !== 0) {
  8259. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  8260. return;
  8261. }
  8262. file.url = data.url;
  8263. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  8264. K('.ke-status > div', itemDiv).hide();
  8265. }
  8266. };
  8267. self.swfu = new SWFUpload(settings);
  8268. K('.ke-swfupload-startupload input', self.div).click(function() {
  8269. self.swfu.startUpload();
  8270. });
  8271. },
  8272. getUrlList : function() {
  8273. var list = [];
  8274. K('.ke-img', self.bodyDiv).each(function() {
  8275. var img = K(this);
  8276. var status = img.attr('data-status');
  8277. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8278. list.push(img.data('data'));
  8279. }
  8280. });
  8281. return list;
  8282. },
  8283. removeFile : function(fileId) {
  8284. var self = this;
  8285. self.swfu.cancelUpload(fileId);
  8286. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8287. K('.ke-photo', itemDiv).unbind();
  8288. K('.ke-delete', itemDiv).unbind();
  8289. itemDiv.remove();
  8290. },
  8291. removeFiles : function() {
  8292. var self = this;
  8293. K('.ke-item', self.bodyDiv).each(function() {
  8294. self.removeFile(K(this).attr('data-id'));
  8295. });
  8296. },
  8297. appendFile : function(file) {
  8298. var self = this;
  8299. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8300. self.bodyDiv.append(itemDiv);
  8301. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8302. .mouseover(function(e) {
  8303. K(this).addClass('ke-on');
  8304. })
  8305. .mouseout(function(e) {
  8306. K(this).removeClass('ke-on');
  8307. });
  8308. itemDiv.append(photoDiv);
  8309. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8310. photoDiv.append(img);
  8311. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8312. self.removeFile(file.id);
  8313. });
  8314. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8315. K(['<div class="ke-progressbar">',
  8316. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8317. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8318. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8319. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8320. self.progressbars[file.id] = {
  8321. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8322. percent : K('.ke-progressbar-percent', photoDiv)
  8323. };
  8324. },
  8325. remove : function() {
  8326. this.removeFiles();
  8327. this.swfu.destroy();
  8328. this.div.html('');
  8329. }
  8330. });
  8331. K.swfupload = function(element, options) {
  8332. return new KSWFUpload(element, options);
  8333. };
  8334. })(KindEditor);
  8335. KindEditor.plugin('multiimage', function(K) {
  8336. var self = this, name = 'multiimage',
  8337. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8338. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8339. imgPath = self.pluginsPath + 'multiimage/images/',
  8340. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8341. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8342. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8343. filePostName = K.undef(self.filePostName, 'imgFile'),
  8344. lang = self.lang(name + '.');
  8345. self.plugin.multiImageDialog = function(options) {
  8346. var clickFn = options.clickFn,
  8347. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8348. uploadDesc = '';
  8349. var html = [
  8350. '<div style="padding:20px;">',
  8351. '<div class="swfupload">',
  8352. '</div>',
  8353. '</div>'
  8354. ].join('');
  8355. var dialog = self.createDialog({
  8356. name : name,
  8357. width : 650,
  8358. height : 510,
  8359. title : self.lang(name),
  8360. body : html,
  8361. previewBtn : {
  8362. name : lang.insertAll,
  8363. click : function(e) {
  8364. clickFn.call(self, swfupload.getUrlList());
  8365. }
  8366. },
  8367. yesBtn : {
  8368. name : lang.clearAll,
  8369. click : function(e) {
  8370. swfupload.removeFiles();
  8371. }
  8372. },
  8373. beforeRemove : function() {
  8374. if (!K.IE || K.V <= 8) {
  8375. swfupload.remove();
  8376. }
  8377. }
  8378. }),
  8379. div = dialog.div;
  8380. var swfupload = K.swfupload({
  8381. container : K('.swfupload', div),
  8382. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8383. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8384. buttonHeight : 23,
  8385. fileIconUrl : imgPath + 'image.png',
  8386. uploadDesc : uploadDesc,
  8387. startButtonValue : lang.startUpload,
  8388. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8389. //uploadMediaUrl : K.addParam(uploadMediaUrl, 'dir=media'),
  8390. flashUrl : imgPath + 'swfupload.swf',
  8391. filePostName : filePostName,
  8392. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8393. fileTypesDesc : 'Image Files',
  8394. fileUploadLimit : imageUploadLimit,
  8395. fileSizeLimit : imageSizeLimit,
  8396. postParams : K.undef(self.extraFileUploadParams, {}),
  8397. queueLimitExceeded : lang.queueLimitExceeded,
  8398. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8399. zeroByteFile : lang.zeroByteFile,
  8400. invalidFiletype : lang.invalidFiletype,
  8401. unknownError : lang.unknownError,
  8402. pendingMessage : lang.pending,
  8403. errorMessage : lang.uploadError,
  8404. afterError : function(html) {
  8405. self.errorDialog(html);
  8406. }
  8407. });
  8408. return dialog;
  8409. };
  8410. self.clickToolbar(name, function() {
  8411. self.plugin.multiImageDialog({
  8412. clickFn : function (urlList) {
  8413. if (urlList.length === 0) {
  8414. return;
  8415. }
  8416. K.each(urlList, function(i, data) {
  8417. if (self.afterUpload) {
  8418. self.afterUpload.call(self, data.url, data, 'multiimage');
  8419. }
  8420. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8421. });
  8422. setTimeout(function() {
  8423. self.hideDialog().focus();
  8424. }, 0);
  8425. }
  8426. });
  8427. });
  8428. });
  8429. /* ******************* */
  8430. /* Constructor & Init */
  8431. /* ******************* */
  8432. (function() {
  8433. window.SWFUpload = function (settings) {
  8434. this.initSWFUpload(settings);
  8435. };
  8436. SWFUpload.prototype.initSWFUpload = function (settings) {
  8437. try {
  8438. this.customSettings = {};
  8439. this.settings = settings;
  8440. this.eventQueue = [];
  8441. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8442. this.movieElement = null;
  8443. SWFUpload.instances[this.movieName] = this;
  8444. this.initSettings();
  8445. this.loadFlash();
  8446. this.displayDebugInfo();
  8447. } catch (ex) {
  8448. delete SWFUpload.instances[this.movieName];
  8449. throw ex;
  8450. }
  8451. };
  8452. /* *************** */
  8453. /* Static Members */
  8454. /* *************** */
  8455. SWFUpload.instances = {};
  8456. SWFUpload.movieCount = 0;
  8457. SWFUpload.version = "2.2.0 2009-03-25";
  8458. SWFUpload.QUEUE_ERROR = {
  8459. QUEUE_LIMIT_EXCEEDED : -100,
  8460. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8461. ZERO_BYTE_FILE : -120,
  8462. INVALID_FILETYPE : -130
  8463. };
  8464. SWFUpload.UPLOAD_ERROR = {
  8465. HTTP_ERROR : -200,
  8466. MISSING_UPLOAD_URL : -210,
  8467. IO_ERROR : -220,
  8468. SECURITY_ERROR : -230,
  8469. UPLOAD_LIMIT_EXCEEDED : -240,
  8470. UPLOAD_FAILED : -250,
  8471. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8472. FILE_VALIDATION_FAILED : -270,
  8473. FILE_CANCELLED : -280,
  8474. UPLOAD_STOPPED : -290
  8475. };
  8476. SWFUpload.FILE_STATUS = {
  8477. QUEUED : -1,
  8478. IN_PROGRESS : -2,
  8479. ERROR : -3,
  8480. COMPLETE : -4,
  8481. CANCELLED : -5
  8482. };
  8483. SWFUpload.BUTTON_ACTION = {
  8484. SELECT_FILE : -100,
  8485. SELECT_FILES : -110,
  8486. START_UPLOAD : -120
  8487. };
  8488. SWFUpload.CURSOR = {
  8489. ARROW : -1,
  8490. HAND : -2
  8491. };
  8492. SWFUpload.WINDOW_MODE = {
  8493. WINDOW : "window",
  8494. TRANSPARENT : "transparent",
  8495. OPAQUE : "opaque"
  8496. };
  8497. SWFUpload.completeURL = function(url) {
  8498. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8499. return url;
  8500. }
  8501. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8502. var indexSlash = window.location.pathname.lastIndexOf("/");
  8503. var path;
  8504. if (indexSlash <= 0) {
  8505. path = "/";
  8506. } else {
  8507. path = window.location.pathname.substr(0, indexSlash) + "/";
  8508. }
  8509. return /*currentURL +*/ path + url;
  8510. };
  8511. /* ******************** */
  8512. /* Instance Members */
  8513. /* ******************** */
  8514. SWFUpload.prototype.initSettings = function () {
  8515. this.ensureDefault = function (settingName, defaultValue) {
  8516. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8517. };
  8518. this.ensureDefault("upload_url", "");
  8519. this.ensureDefault("preserve_relative_urls", false);
  8520. this.ensureDefault("file_post_name", "Filedata");
  8521. this.ensureDefault("post_params", {});
  8522. this.ensureDefault("use_query_string", false);
  8523. this.ensureDefault("requeue_on_error", false);
  8524. this.ensureDefault("http_success", []);
  8525. this.ensureDefault("assume_success_timeout", 0);
  8526. this.ensureDefault("file_types", "*.*");
  8527. this.ensureDefault("file_types_description", "All Files");
  8528. this.ensureDefault("file_size_limit", 0);
  8529. this.ensureDefault("file_upload_limit", 0);
  8530. this.ensureDefault("file_queue_limit", 0);
  8531. this.ensureDefault("flash_url", "swfupload.swf");
  8532. this.ensureDefault("prevent_swf_caching", true);
  8533. this.ensureDefault("button_image_url", "");
  8534. this.ensureDefault("button_width", 1);
  8535. this.ensureDefault("button_height", 1);
  8536. this.ensureDefault("button_text", "");
  8537. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8538. this.ensureDefault("button_text_top_padding", 0);
  8539. this.ensureDefault("button_text_left_padding", 0);
  8540. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8541. this.ensureDefault("button_disabled", false);
  8542. this.ensureDefault("button_placeholder_id", "");
  8543. this.ensureDefault("button_placeholder", null);
  8544. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8545. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8546. this.ensureDefault("debug", false);
  8547. this.settings.debug_enabled = this.settings.debug;
  8548. this.settings.return_upload_start_handler = this.returnUploadStart;
  8549. this.ensureDefault("swfupload_loaded_handler", null);
  8550. this.ensureDefault("file_dialog_start_handler", null);
  8551. this.ensureDefault("file_queued_handler", null);
  8552. this.ensureDefault("file_queue_error_handler", null);
  8553. this.ensureDefault("file_dialog_complete_handler", null);
  8554. this.ensureDefault("upload_start_handler", null);
  8555. this.ensureDefault("upload_progress_handler", null);
  8556. this.ensureDefault("upload_error_handler", null);
  8557. this.ensureDefault("upload_success_handler", null);
  8558. this.ensureDefault("upload_complete_handler", null);
  8559. this.ensureDefault("debug_handler", this.debugMessage);
  8560. this.ensureDefault("custom_settings", {});
  8561. this.customSettings = this.settings.custom_settings;
  8562. if (!!this.settings.prevent_swf_caching) {
  8563. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8564. }
  8565. if (!this.settings.preserve_relative_urls) {
  8566. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8567. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8568. }
  8569. delete this.ensureDefault;
  8570. };
  8571. SWFUpload.prototype.loadFlash = function () {
  8572. var targetElement, tempParent;
  8573. if (document.getElementById(this.movieName) !== null) {
  8574. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8575. }
  8576. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8577. if (targetElement == undefined) {
  8578. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8579. }
  8580. tempParent = document.createElement("div");
  8581. tempParent.innerHTML = this.getFlashHTML();
  8582. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8583. if (window[this.movieName] == undefined) {
  8584. window[this.movieName] = this.getMovieElement();
  8585. }
  8586. };
  8587. SWFUpload.prototype.getFlashHTML = function () {
  8588. var classid = '';
  8589. if (KindEditor.IE && KindEditor.V > 8) {
  8590. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8591. }
  8592. 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">',
  8593. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8594. '<param name="movie" value="', this.settings.flash_url, '" />',
  8595. '<param name="quality" value="high" />',
  8596. '<param name="menu" value="false" />',
  8597. '<param name="allowScriptAccess" value="always" />',
  8598. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8599. '</object>'].join("");
  8600. };
  8601. SWFUpload.prototype.getFlashVars = function () {
  8602. var paramString = this.buildParamString();
  8603. var httpSuccessString = this.settings.http_success.join(",");
  8604. return ["movieName=", encodeURIComponent(this.movieName),
  8605. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8606. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8607. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8608. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8609. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8610. "&amp;params=", encodeURIComponent(paramString),
  8611. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8612. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8613. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8614. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8615. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8616. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8617. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8618. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8619. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8620. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8621. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8622. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8623. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8624. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8625. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8626. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8627. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8628. ].join("");
  8629. };
  8630. SWFUpload.prototype.getMovieElement = function () {
  8631. if (this.movieElement == undefined) {
  8632. this.movieElement = document.getElementById(this.movieName);
  8633. }
  8634. if (this.movieElement === null) {
  8635. throw "Could not find Flash element";
  8636. }
  8637. return this.movieElement;
  8638. };
  8639. SWFUpload.prototype.buildParamString = function () {
  8640. var postParams = this.settings.post_params;
  8641. var paramStringPairs = [];
  8642. if (typeof(postParams) === "object") {
  8643. for (var name in postParams) {
  8644. if (postParams.hasOwnProperty(name)) {
  8645. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8646. }
  8647. }
  8648. }
  8649. return paramStringPairs.join("&amp;");
  8650. };
  8651. SWFUpload.prototype.destroy = function () {
  8652. try {
  8653. this.cancelUpload(null, false);
  8654. var movieElement = null;
  8655. movieElement = this.getMovieElement();
  8656. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8657. for (var i in movieElement) {
  8658. try {
  8659. if (typeof(movieElement[i]) === "function") {
  8660. movieElement[i] = null;
  8661. }
  8662. } catch (ex1) {}
  8663. }
  8664. try {
  8665. movieElement.parentNode.removeChild(movieElement);
  8666. } catch (ex) {}
  8667. }
  8668. window[this.movieName] = null;
  8669. SWFUpload.instances[this.movieName] = null;
  8670. delete SWFUpload.instances[this.movieName];
  8671. this.movieElement = null;
  8672. this.settings = null;
  8673. this.customSettings = null;
  8674. this.eventQueue = null;
  8675. this.movieName = null;
  8676. return true;
  8677. } catch (ex2) {
  8678. return false;
  8679. }
  8680. };
  8681. SWFUpload.prototype.displayDebugInfo = function () {
  8682. this.debug(
  8683. [
  8684. "---SWFUpload Instance Info---\n",
  8685. "Version: ", SWFUpload.version, "\n",
  8686. "Movie Name: ", this.movieName, "\n",
  8687. "Settings:\n",
  8688. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8689. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8690. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8691. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8692. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8693. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8694. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8695. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8696. "\t", "file_types: ", this.settings.file_types, "\n",
  8697. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8698. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8699. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8700. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8701. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8702. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8703. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8704. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8705. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8706. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8707. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8708. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8709. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8710. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8711. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8712. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8713. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8714. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8715. "Event Handlers:\n",
  8716. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8717. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8718. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8719. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8720. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8721. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8722. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8723. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8724. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8725. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8726. ].join("")
  8727. );
  8728. };
  8729. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8730. the maintain v2 API compatibility
  8731. */
  8732. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8733. if (value == undefined) {
  8734. return (this.settings[name] = default_value);
  8735. } else {
  8736. return (this.settings[name] = value);
  8737. }
  8738. };
  8739. SWFUpload.prototype.getSetting = function (name) {
  8740. if (this.settings[name] != undefined) {
  8741. return this.settings[name];
  8742. }
  8743. return "";
  8744. };
  8745. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8746. argumentArray = argumentArray || [];
  8747. var movieElement = this.getMovieElement();
  8748. var returnValue, returnString;
  8749. try {
  8750. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8751. returnValue = eval(returnString);
  8752. } catch (ex) {
  8753. throw "Call to " + functionName + " failed";
  8754. }
  8755. if (returnValue != undefined && typeof returnValue.post === "object") {
  8756. returnValue = this.unescapeFilePostParams(returnValue);
  8757. }
  8758. return returnValue;
  8759. };
  8760. /* *****************************
  8761. -- Flash control methods --
  8762. Your UI should use these
  8763. to operate SWFUpload
  8764. ***************************** */
  8765. SWFUpload.prototype.selectFile = function () {
  8766. this.callFlash("SelectFile");
  8767. };
  8768. SWFUpload.prototype.selectFiles = function () {
  8769. this.callFlash("SelectFiles");
  8770. };
  8771. SWFUpload.prototype.startUpload = function (fileID) {
  8772. this.callFlash("StartUpload", [fileID]);
  8773. };
  8774. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8775. if (triggerErrorEvent !== false) {
  8776. triggerErrorEvent = true;
  8777. }
  8778. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8779. };
  8780. SWFUpload.prototype.stopUpload = function () {
  8781. this.callFlash("StopUpload");
  8782. };
  8783. /* ************************
  8784. * Settings methods
  8785. * These methods change the SWFUpload settings.
  8786. * SWFUpload settings should not be changed directly on the settings object
  8787. * since many of the settings need to be passed to Flash in order to take
  8788. * effect.
  8789. * *********************** */
  8790. SWFUpload.prototype.getStats = function () {
  8791. return this.callFlash("GetStats");
  8792. };
  8793. SWFUpload.prototype.setStats = function (statsObject) {
  8794. this.callFlash("SetStats", [statsObject]);
  8795. };
  8796. SWFUpload.prototype.getFile = function (fileID) {
  8797. if (typeof(fileID) === "number") {
  8798. return this.callFlash("GetFileByIndex", [fileID]);
  8799. } else {
  8800. return this.callFlash("GetFile", [fileID]);
  8801. }
  8802. };
  8803. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8804. return this.callFlash("AddFileParam", [fileID, name, value]);
  8805. };
  8806. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8807. this.callFlash("RemoveFileParam", [fileID, name]);
  8808. };
  8809. SWFUpload.prototype.setUploadURL = function (url) {
  8810. this.settings.upload_url = url.toString();
  8811. this.callFlash("SetUploadURL", [url]);
  8812. };
  8813. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8814. this.settings.post_params = paramsObject;
  8815. this.callFlash("SetPostParams", [paramsObject]);
  8816. };
  8817. SWFUpload.prototype.addPostParam = function (name, value) {
  8818. this.settings.post_params[name] = value;
  8819. this.callFlash("SetPostParams", [this.settings.post_params]);
  8820. };
  8821. SWFUpload.prototype.removePostParam = function (name) {
  8822. delete this.settings.post_params[name];
  8823. this.callFlash("SetPostParams", [this.settings.post_params]);
  8824. };
  8825. SWFUpload.prototype.setFileTypes = function (types, description) {
  8826. this.settings.file_types = types;
  8827. this.settings.file_types_description = description;
  8828. this.callFlash("SetFileTypes", [types, description]);
  8829. };
  8830. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8831. this.settings.file_size_limit = fileSizeLimit;
  8832. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8833. };
  8834. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8835. this.settings.file_upload_limit = fileUploadLimit;
  8836. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8837. };
  8838. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8839. this.settings.file_queue_limit = fileQueueLimit;
  8840. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8841. };
  8842. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8843. this.settings.file_post_name = filePostName;
  8844. this.callFlash("SetFilePostName", [filePostName]);
  8845. };
  8846. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8847. this.settings.use_query_string = useQueryString;
  8848. this.callFlash("SetUseQueryString", [useQueryString]);
  8849. };
  8850. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8851. this.settings.requeue_on_error = requeueOnError;
  8852. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8853. };
  8854. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8855. if (typeof http_status_codes === "string") {
  8856. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8857. }
  8858. this.settings.http_success = http_status_codes;
  8859. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8860. };
  8861. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8862. this.settings.assume_success_timeout = timeout_seconds;
  8863. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8864. };
  8865. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8866. this.settings.debug_enabled = debugEnabled;
  8867. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8868. };
  8869. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8870. if (buttonImageURL == undefined) {
  8871. buttonImageURL = "";
  8872. }
  8873. this.settings.button_image_url = buttonImageURL;
  8874. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8875. };
  8876. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8877. this.settings.button_width = width;
  8878. this.settings.button_height = height;
  8879. var movie = this.getMovieElement();
  8880. if (movie != undefined) {
  8881. movie.style.width = width + "px";
  8882. movie.style.height = height + "px";
  8883. }
  8884. this.callFlash("SetButtonDimensions", [width, height]);
  8885. };
  8886. SWFUpload.prototype.setButtonText = function (html) {
  8887. this.settings.button_text = html;
  8888. this.callFlash("SetButtonText", [html]);
  8889. };
  8890. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8891. this.settings.button_text_top_padding = top;
  8892. this.settings.button_text_left_padding = left;
  8893. this.callFlash("SetButtonTextPadding", [left, top]);
  8894. };
  8895. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8896. this.settings.button_text_style = css;
  8897. this.callFlash("SetButtonTextStyle", [css]);
  8898. };
  8899. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8900. this.settings.button_disabled = isDisabled;
  8901. this.callFlash("SetButtonDisabled", [isDisabled]);
  8902. };
  8903. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8904. this.settings.button_action = buttonAction;
  8905. this.callFlash("SetButtonAction", [buttonAction]);
  8906. };
  8907. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8908. this.settings.button_cursor = cursor;
  8909. this.callFlash("SetButtonCursor", [cursor]);
  8910. };
  8911. /* *******************************
  8912. Flash Event Interfaces
  8913. These functions are used by Flash to trigger the various
  8914. events.
  8915. All these functions a Private.
  8916. Because the ExternalInterface library is buggy the event calls
  8917. are added to a queue and the queue then executed by a setTimeout.
  8918. This ensures that events are executed in a determinate order and that
  8919. the ExternalInterface bugs are avoided.
  8920. ******************************* */
  8921. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8922. if (argumentArray == undefined) {
  8923. argumentArray = [];
  8924. } else if (!(argumentArray instanceof Array)) {
  8925. argumentArray = [argumentArray];
  8926. }
  8927. var self = this;
  8928. if (typeof this.settings[handlerName] === "function") {
  8929. this.eventQueue.push(function () {
  8930. this.settings[handlerName].apply(this, argumentArray);
  8931. });
  8932. setTimeout(function () {
  8933. self.executeNextEvent();
  8934. }, 0);
  8935. } else if (this.settings[handlerName] !== null) {
  8936. throw "Event handler " + handlerName + " is unknown or is not a function";
  8937. }
  8938. };
  8939. SWFUpload.prototype.executeNextEvent = function () {
  8940. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8941. if (typeof(f) === "function") {
  8942. f.apply(this);
  8943. }
  8944. };
  8945. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8946. var reg = /[$]([0-9a-f]{4})/i;
  8947. var unescapedPost = {};
  8948. var uk;
  8949. if (file != undefined) {
  8950. for (var k in file.post) {
  8951. if (file.post.hasOwnProperty(k)) {
  8952. uk = k;
  8953. var match;
  8954. while ((match = reg.exec(uk)) !== null) {
  8955. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8956. }
  8957. unescapedPost[uk] = file.post[k];
  8958. }
  8959. }
  8960. file.post = unescapedPost;
  8961. }
  8962. return file;
  8963. };
  8964. SWFUpload.prototype.testExternalInterface = function () {
  8965. try {
  8966. return this.callFlash("TestExternalInterface");
  8967. } catch (ex) {
  8968. return false;
  8969. }
  8970. };
  8971. SWFUpload.prototype.flashReady = function () {
  8972. var movieElement = this.getMovieElement();
  8973. if (!movieElement) {
  8974. this.debug("Flash called back ready but the flash movie can't be found.");
  8975. return;
  8976. }
  8977. this.cleanUp(movieElement);
  8978. this.queueEvent("swfupload_loaded_handler");
  8979. };
  8980. SWFUpload.prototype.cleanUp = function (movieElement) {
  8981. try {
  8982. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8983. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8984. for (var key in movieElement) {
  8985. try {
  8986. if (typeof(movieElement[key]) === "function") {
  8987. movieElement[key] = null;
  8988. }
  8989. } catch (ex) {
  8990. }
  8991. }
  8992. }
  8993. } catch (ex1) {
  8994. }
  8995. window["__flash__removeCallback"] = function (instance, name) {
  8996. try {
  8997. if (instance) {
  8998. instance[name] = null;
  8999. }
  9000. } catch (flashEx) {
  9001. }
  9002. };
  9003. };
  9004. /* This is a chance to do something before the browse window opens */
  9005. SWFUpload.prototype.fileDialogStart = function () {
  9006. this.queueEvent("file_dialog_start_handler");
  9007. };
  9008. /* Called when a file is successfully added to the queue. */
  9009. SWFUpload.prototype.fileQueued = function (file) {
  9010. file = this.unescapeFilePostParams(file);
  9011. this.queueEvent("file_queued_handler", file);
  9012. };
  9013. /* Handle errors that occur when an attempt to queue a file fails. */
  9014. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  9015. file = this.unescapeFilePostParams(file);
  9016. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  9017. };
  9018. /* Called after the file dialog has closed and the selected files have been queued.
  9019. You could call startUpload here if you want the queued files to begin uploading immediately. */
  9020. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  9021. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  9022. };
  9023. SWFUpload.prototype.uploadStart = function (file) {
  9024. file = this.unescapeFilePostParams(file);
  9025. this.queueEvent("return_upload_start_handler", file);
  9026. };
  9027. SWFUpload.prototype.returnUploadStart = function (file) {
  9028. var returnValue;
  9029. if (typeof this.settings.upload_start_handler === "function") {
  9030. file = this.unescapeFilePostParams(file);
  9031. returnValue = this.settings.upload_start_handler.call(this, file);
  9032. } else if (this.settings.upload_start_handler != undefined) {
  9033. throw "upload_start_handler must be a function";
  9034. }
  9035. if (returnValue === undefined) {
  9036. returnValue = true;
  9037. }
  9038. returnValue = !!returnValue;
  9039. this.callFlash("ReturnUploadStart", [returnValue]);
  9040. };
  9041. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  9042. file = this.unescapeFilePostParams(file);
  9043. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  9044. };
  9045. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  9046. file = this.unescapeFilePostParams(file);
  9047. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  9048. };
  9049. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  9050. file = this.unescapeFilePostParams(file);
  9051. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  9052. };
  9053. SWFUpload.prototype.uploadComplete = function (file) {
  9054. file = this.unescapeFilePostParams(file);
  9055. this.queueEvent("upload_complete_handler", file);
  9056. };
  9057. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  9058. internal debug console. You can override this event and have messages written where you want. */
  9059. SWFUpload.prototype.debug = function (message) {
  9060. this.queueEvent("debug_handler", message);
  9061. };
  9062. /* **********************************
  9063. Debug Console
  9064. The debug console is a self contained, in page location
  9065. for debug message to be sent. The Debug Console adds
  9066. itself to the body if necessary.
  9067. The console is automatically scrolled as messages appear.
  9068. If you are using your own debug handler or when you deploy to production and
  9069. have debug disabled you can remove these functions to reduce the file size
  9070. and complexity.
  9071. ********************************** */
  9072. SWFUpload.prototype.debugMessage = function (message) {
  9073. if (this.settings.debug) {
  9074. var exceptionMessage, exceptionValues = [];
  9075. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  9076. for (var key in message) {
  9077. if (message.hasOwnProperty(key)) {
  9078. exceptionValues.push(key + ": " + message[key]);
  9079. }
  9080. }
  9081. exceptionMessage = exceptionValues.join("\n") || "";
  9082. exceptionValues = exceptionMessage.split("\n");
  9083. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  9084. SWFUpload.Console.writeLine(exceptionMessage);
  9085. } else {
  9086. SWFUpload.Console.writeLine(message);
  9087. }
  9088. }
  9089. };
  9090. SWFUpload.Console = {};
  9091. SWFUpload.Console.writeLine = function (message) {
  9092. var console, documentForm;
  9093. try {
  9094. console = document.getElementById("SWFUpload_Console");
  9095. if (!console) {
  9096. documentForm = document.createElement("form");
  9097. document.getElementsByTagName("body")[0].appendChild(documentForm);
  9098. console = document.createElement("textarea");
  9099. console.id = "SWFUpload_Console";
  9100. console.style.fontFamily = "monospace";
  9101. console.setAttribute("wrap", "off");
  9102. console.wrap = "off";
  9103. console.style.overflow = "auto";
  9104. console.style.width = "700px";
  9105. console.style.height = "350px";
  9106. console.style.margin = "5px";
  9107. documentForm.appendChild(console);
  9108. }
  9109. console.value += message + "\n";
  9110. console.scrollTop = console.scrollHeight - console.clientHeight;
  9111. } catch (ex) {
  9112. alert("Exception: " + ex.name + " Message: " + ex.message);
  9113. }
  9114. };
  9115. })();
  9116. (function() {
  9117. /*
  9118. Queue Plug-in
  9119. Features:
  9120. *Adds a cancelQueue() method for cancelling the entire queue.
  9121. *All queued files are uploaded when startUpload() is called.
  9122. *If false is returned from uploadComplete then the queue upload is stopped.
  9123. If false is not returned (strict comparison) then the queue upload is continued.
  9124. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  9125. Set the event handler with the queue_complete_handler setting.
  9126. */
  9127. if (typeof(SWFUpload) === "function") {
  9128. SWFUpload.queue = {};
  9129. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  9130. return function () {
  9131. if (typeof(oldInitSettings) === "function") {
  9132. oldInitSettings.call(this);
  9133. }
  9134. this.queueSettings = {};
  9135. this.queueSettings.queue_cancelled_flag = false;
  9136. this.queueSettings.queue_upload_count = 0;
  9137. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  9138. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  9139. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  9140. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  9141. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  9142. };
  9143. })(SWFUpload.prototype.initSettings);
  9144. SWFUpload.prototype.startUpload = function (fileID) {
  9145. this.queueSettings.queue_cancelled_flag = false;
  9146. this.callFlash("StartUpload", [fileID]);
  9147. };
  9148. SWFUpload.prototype.cancelQueue = function () {
  9149. this.queueSettings.queue_cancelled_flag = true;
  9150. this.stopUpload();
  9151. var stats = this.getStats();
  9152. while (stats.files_queued > 0) {
  9153. this.cancelUpload();
  9154. stats = this.getStats();
  9155. }
  9156. };
  9157. SWFUpload.queue.uploadStartHandler = function (file) {
  9158. var returnValue;
  9159. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  9160. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  9161. }
  9162. returnValue = (returnValue === false) ? false : true;
  9163. this.queueSettings.queue_cancelled_flag = !returnValue;
  9164. return returnValue;
  9165. };
  9166. SWFUpload.queue.uploadCompleteHandler = function (file) {
  9167. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  9168. var continueUpload;
  9169. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  9170. this.queueSettings.queue_upload_count++;
  9171. }
  9172. if (typeof(user_upload_complete_handler) === "function") {
  9173. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  9174. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  9175. continueUpload = false;
  9176. } else {
  9177. continueUpload = true;
  9178. }
  9179. if (continueUpload) {
  9180. var stats = this.getStats();
  9181. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  9182. this.startUpload();
  9183. } else if (this.queueSettings.queue_cancelled_flag === false) {
  9184. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  9185. this.queueSettings.queue_upload_count = 0;
  9186. } else {
  9187. this.queueSettings.queue_cancelled_flag = false;
  9188. this.queueSettings.queue_upload_count = 0;
  9189. }
  9190. }
  9191. };
  9192. }
  9193. })();
  9194. /*******************************************************************************
  9195. * KindEditor - WYSIWYG HTML Editor for Internet
  9196. * Copyright (C) 2006-2011 kindsoft.net
  9197. *
  9198. * @author Roddy <luolonghao@gmail.com>
  9199. * @site http://www.kindsoft.net/
  9200. * @licence http://www.kindsoft.net/license.php
  9201. *******************************************************************************/
  9202. KindEditor.plugin('pagebreak', function(K) {
  9203. var self = this;
  9204. var name = 'pagebreak';
  9205. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  9206. self.clickToolbar(name, function() {
  9207. var cmd = self.cmd, range = cmd.range;
  9208. self.focus();
  9209. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  9210. self.insertHtml(pagebreakHtml + tail);
  9211. if (tail !== '') {
  9212. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9213. range.selectNodeContents(p[0]);
  9214. p.removeAttr('id');
  9215. cmd.select();
  9216. }
  9217. });
  9218. });
  9219. /*******************************************************************************
  9220. * KindEditor - WYSIWYG HTML Editor for Internet
  9221. * Copyright (C) 2006-2011 kindsoft.net
  9222. *
  9223. * @author Roddy <luolonghao@gmail.com>
  9224. * @site http://www.kindsoft.net/
  9225. * @licence http://www.kindsoft.net/license.php
  9226. *******************************************************************************/
  9227. KindEditor.plugin('plainpaste', function(K) {
  9228. var self = this, name = 'plainpaste';
  9229. self.clickToolbar(name, function() {
  9230. var lang = self.lang(name + '.'),
  9231. html = '<div style="padding:10px 20px;">' +
  9232. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9233. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9234. '</div>',
  9235. dialog = self.createDialog({
  9236. name : name,
  9237. width : 450,
  9238. title : self.lang(name),
  9239. body : html,
  9240. yesBtn : {
  9241. name : self.lang('yes'),
  9242. click : function(e) {
  9243. var html = textarea.val();
  9244. html = K.escape(html);
  9245. html = html.replace(/ {2}/g, ' &nbsp;');
  9246. if (self.newlineTag == 'p') {
  9247. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9248. } else {
  9249. html = html.replace(/\n/g, '<br />$&');
  9250. }
  9251. self.insertHtml(html).hideDialog().focus();
  9252. }
  9253. }
  9254. }),
  9255. textarea = K('textarea', dialog.div);
  9256. textarea[0].focus();
  9257. });
  9258. });
  9259. /*******************************************************************************
  9260. * KindEditor - WYSIWYG HTML Editor for Internet
  9261. * Copyright (C) 2006-2011 kindsoft.net
  9262. *
  9263. * @author Roddy <luolonghao@gmail.com>
  9264. * @site http://www.kindsoft.net/
  9265. * @licence http://www.kindsoft.net/license.php
  9266. *******************************************************************************/
  9267. KindEditor.plugin('preview', function(K) {
  9268. var self = this, name = 'preview', undefined;
  9269. self.clickToolbar(name, function() {
  9270. var lang = self.lang(name + '.'),
  9271. html = '<div style="padding:10px 20px;">' +
  9272. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9273. '</div>',
  9274. dialog = self.createDialog({
  9275. name : name,
  9276. width : 750,
  9277. title : self.lang(name),
  9278. body : html
  9279. }),
  9280. iframe = K('iframe', dialog.div),
  9281. doc = K.iframeDoc(iframe);
  9282. doc.open();
  9283. doc.write(self.fullHtml());
  9284. doc.close();
  9285. K(doc.body).css('background-color', '#FFF');
  9286. iframe[0].contentWindow.focus();
  9287. });
  9288. });
  9289. /*******************************************************************************
  9290. * KindEditor - WYSIWYG HTML Editor for Internet
  9291. * Copyright (C) 2006-2011 kindsoft.net
  9292. *
  9293. * @author Roddy <luolonghao@gmail.com>
  9294. * @site http://www.kindsoft.net/
  9295. * @licence http://www.kindsoft.net/license.php
  9296. *******************************************************************************/
  9297. KindEditor.plugin('quickformat', function(K) {
  9298. var self = this, name = 'quickformat',
  9299. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9300. function getFirstChild(knode) {
  9301. var child = knode.first();
  9302. while (child && child.first()) {
  9303. child = child.first();
  9304. }
  9305. return child;
  9306. }
  9307. self.clickToolbar(name, function() {
  9308. self.focus();
  9309. var doc = self.edit.doc,
  9310. range = self.cmd.range,
  9311. child = K(doc.body).first(), next,
  9312. nodeList = [], subList = [],
  9313. bookmark = range.createBookmark(true);
  9314. while(child) {
  9315. next = child.next();
  9316. var firstChild = getFirstChild(child);
  9317. if (!firstChild || firstChild.name != 'img') {
  9318. if (blockMap[child.name]) {
  9319. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9320. child.css('text-indent', '2em');
  9321. } else {
  9322. subList.push(child);
  9323. }
  9324. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9325. if (subList.length > 0) {
  9326. nodeList.push(subList);
  9327. }
  9328. subList = [];
  9329. }
  9330. }
  9331. child = next;
  9332. }
  9333. K.each(nodeList, function(i, subList) {
  9334. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9335. subList[0].before(wrapper);
  9336. K.each(subList, function(i, knode) {
  9337. wrapper.append(knode);
  9338. });
  9339. });
  9340. range.moveToBookmark(bookmark);
  9341. self.addBookmark();
  9342. });
  9343. });
  9344. /*******************************************************************************
  9345. * KindEditor - WYSIWYG HTML Editor for Internet
  9346. * Copyright (C) 2006-2011 kindsoft.net
  9347. *
  9348. * @author Roddy <luolonghao@gmail.com>
  9349. * @site http://www.kindsoft.net/
  9350. * @licence http://www.kindsoft.net/license.php
  9351. *******************************************************************************/
  9352. KindEditor.plugin('table', function(K) {
  9353. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9354. function _setColor(box, color) {
  9355. color = color.toUpperCase();
  9356. box.css('background-color', color);
  9357. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9358. box.html(color);
  9359. }
  9360. var pickerList = [];
  9361. function _initColorPicker(dialogDiv, colorBox) {
  9362. colorBox.bind('click,mousedown', function(e){
  9363. e.stopPropagation();
  9364. });
  9365. function removePicker() {
  9366. K.each(pickerList, function() {
  9367. this.remove();
  9368. });
  9369. pickerList = [];
  9370. K(document).unbind('click,mousedown', removePicker);
  9371. dialogDiv.unbind('click,mousedown', removePicker);
  9372. }
  9373. colorBox.click(function(e) {
  9374. removePicker();
  9375. var box = K(this),
  9376. pos = box.pos();
  9377. var picker = K.colorpicker({
  9378. x : pos.x,
  9379. y : pos.y + box.height(),
  9380. z : 811214,
  9381. selectedColor : K(this).html(),
  9382. colors : self.colorTable,
  9383. noColor : self.lang('noColor'),
  9384. shadowMode : self.shadowMode,
  9385. click : function(color) {
  9386. _setColor(box, color);
  9387. removePicker();
  9388. }
  9389. });
  9390. pickerList.push(picker);
  9391. K(document).bind('click,mousedown', removePicker);
  9392. dialogDiv.bind('click,mousedown', removePicker);
  9393. });
  9394. }
  9395. function _getCellIndex(table, row, cell) {
  9396. var rowSpanCount = 0;
  9397. for (var i = 0, len = row.cells.length; i < len; i++) {
  9398. if (row.cells[i] == cell) {
  9399. break;
  9400. }
  9401. rowSpanCount += row.cells[i].rowSpan - 1;
  9402. }
  9403. return cell.cellIndex - rowSpanCount;
  9404. }
  9405. self.plugin.table = {
  9406. prop : function(isInsert) {
  9407. var html = [
  9408. '<div style="padding:20px;">',
  9409. '<div class="ke-dialog-row">',
  9410. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9411. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9412. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9413. '</div>',
  9414. '<div class="ke-dialog-row">',
  9415. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9416. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9417. '<select name="widthType">',
  9418. '<option value="%">' + lang.percent + '</option>',
  9419. '<option value="px">' + lang.px + '</option>',
  9420. '</select> &nbsp; ',
  9421. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9422. '<select name="heightType">',
  9423. '<option value="%">' + lang.percent + '</option>',
  9424. '<option value="px">' + lang.px + '</option>',
  9425. '</select>',
  9426. '</div>',
  9427. '<div class="ke-dialog-row">',
  9428. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9429. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9430. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9431. '</div>',
  9432. '<div class="ke-dialog-row">',
  9433. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9434. '<select id="keAlign" name="align">',
  9435. '<option value="">' + lang.alignDefault + '</option>',
  9436. '<option value="left">' + lang.alignLeft + '</option>',
  9437. '<option value="center">' + lang.alignCenter + '</option>',
  9438. '<option value="right">' + lang.alignRight + '</option>',
  9439. '</select>',
  9440. '</div>',
  9441. '<div class="ke-dialog-row">',
  9442. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9443. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9444. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9445. '</div>',
  9446. '<div class="ke-dialog-row">',
  9447. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9448. '<span class="ke-inline-block ke-input-color"></span>',
  9449. '</div>',
  9450. '</div>'
  9451. ].join('');
  9452. var bookmark = self.cmd.range.createBookmark();
  9453. var dialog = self.createDialog({
  9454. name : name,
  9455. width : 500,
  9456. title : self.lang(name),
  9457. body : html,
  9458. beforeRemove : function() {
  9459. colorBox.unbind();
  9460. },
  9461. yesBtn : {
  9462. name : self.lang('yes'),
  9463. click : function(e) {
  9464. var rows = rowsBox.val(),
  9465. cols = colsBox.val(),
  9466. width = widthBox.val(),
  9467. height = heightBox.val(),
  9468. widthType = widthTypeBox.val(),
  9469. heightType = heightTypeBox.val(),
  9470. padding = paddingBox.val(),
  9471. spacing = spacingBox.val(),
  9472. align = alignBox.val(),
  9473. border = borderBox.val(),
  9474. borderColor = K(colorBox[0]).html() || '',
  9475. bgColor = K(colorBox[1]).html() || '';
  9476. if (rows == 0 || !/^\d+$/.test(rows)) {
  9477. alert(self.lang('invalidRows'));
  9478. rowsBox[0].focus();
  9479. return;
  9480. }
  9481. if (cols == 0 || !/^\d+$/.test(cols)) {
  9482. alert(self.lang('invalidRows'));
  9483. colsBox[0].focus();
  9484. return;
  9485. }
  9486. if (!/^\d*$/.test(width)) {
  9487. alert(self.lang('invalidWidth'));
  9488. widthBox[0].focus();
  9489. return;
  9490. }
  9491. if (!/^\d*$/.test(height)) {
  9492. alert(self.lang('invalidHeight'));
  9493. heightBox[0].focus();
  9494. return;
  9495. }
  9496. if (!/^\d*$/.test(padding)) {
  9497. alert(self.lang('invalidPadding'));
  9498. paddingBox[0].focus();
  9499. return;
  9500. }
  9501. if (!/^\d*$/.test(spacing)) {
  9502. alert(self.lang('invalidSpacing'));
  9503. spacingBox[0].focus();
  9504. return;
  9505. }
  9506. if (!/^\d*$/.test(border)) {
  9507. alert(self.lang('invalidBorder'));
  9508. borderBox[0].focus();
  9509. return;
  9510. }
  9511. if (table) {
  9512. if (width !== '') {
  9513. table.width(width + widthType);
  9514. } else {
  9515. table.css('width', '');
  9516. }
  9517. if (table[0].width !== undefined) {
  9518. table.removeAttr('width');
  9519. }
  9520. if (height !== '') {
  9521. table.height(height + heightType);
  9522. } else {
  9523. table.css('height', '');
  9524. }
  9525. if (table[0].height !== undefined) {
  9526. table.removeAttr('height');
  9527. }
  9528. table.css('background-color', bgColor);
  9529. if (table[0].bgColor !== undefined) {
  9530. table.removeAttr('bgColor');
  9531. }
  9532. if (padding !== '') {
  9533. table[0].cellPadding = padding;
  9534. } else {
  9535. table.removeAttr('cellPadding');
  9536. }
  9537. if (spacing !== '') {
  9538. table[0].cellSpacing = spacing;
  9539. } else {
  9540. table.removeAttr('cellSpacing');
  9541. }
  9542. if (align !== '') {
  9543. table[0].align = align;
  9544. } else {
  9545. table.removeAttr('align');
  9546. }
  9547. if (border !== '') {
  9548. table.attr('border', border);
  9549. } else {
  9550. table.removeAttr('border');
  9551. }
  9552. if (border === '' || border === '0') {
  9553. table.addClass(zeroborder);
  9554. } else {
  9555. table.removeClass(zeroborder);
  9556. }
  9557. if (borderColor !== '') {
  9558. table.attr('borderColor', borderColor);
  9559. } else {
  9560. table.removeAttr('borderColor');
  9561. }
  9562. self.hideDialog().focus();
  9563. self.cmd.range.moveToBookmark(bookmark);
  9564. self.cmd.select();
  9565. self.addBookmark();
  9566. return;
  9567. }
  9568. var style = '';
  9569. if (width !== '') {
  9570. style += 'width:' + width + widthType + ';';
  9571. }
  9572. if (height !== '') {
  9573. style += 'height:' + height + heightType + ';';
  9574. }
  9575. if (bgColor !== '') {
  9576. style += 'background-color:' + bgColor + ';';
  9577. }
  9578. var html = '<table';
  9579. if (style !== '') {
  9580. html += ' style="' + style + '"';
  9581. }
  9582. if (padding !== '') {
  9583. html += ' cellpadding="' + padding + '"';
  9584. }
  9585. if (spacing !== '') {
  9586. html += ' cellspacing="' + spacing + '"';
  9587. }
  9588. if (align !== '') {
  9589. html += ' align="' + align + '"';
  9590. }
  9591. if (border !== '') {
  9592. html += ' border="' + border + '"';
  9593. }
  9594. if (border === '' || border === '0') {
  9595. html += ' class="' + zeroborder + '"';
  9596. }
  9597. if (borderColor !== '') {
  9598. html += ' bordercolor="' + borderColor + '"';
  9599. }
  9600. html += '>';
  9601. for (var i = 0; i < rows; i++) {
  9602. html += '<tr>';
  9603. for (var j = 0; j < cols; j++) {
  9604. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9605. }
  9606. html += '</tr>';
  9607. }
  9608. html += '</table>';
  9609. if (!K.IE) {
  9610. html += '<br />';
  9611. }
  9612. self.insertHtml(html);
  9613. self.select().hideDialog().focus();
  9614. self.addBookmark();
  9615. }
  9616. }
  9617. }),
  9618. div = dialog.div,
  9619. rowsBox = K('[name="rows"]', div).val(3),
  9620. colsBox = K('[name="cols"]', div).val(2),
  9621. widthBox = K('[name="width"]', div).val(100),
  9622. heightBox = K('[name="height"]', div),
  9623. widthTypeBox = K('[name="widthType"]', div),
  9624. heightTypeBox = K('[name="heightType"]', div),
  9625. paddingBox = K('[name="padding"]', div).val(2),
  9626. spacingBox = K('[name="spacing"]', div).val(0),
  9627. alignBox = K('[name="align"]', div),
  9628. borderBox = K('[name="border"]', div).val(1),
  9629. colorBox = K('.ke-input-color', div);
  9630. _initColorPicker(div, colorBox.eq(0));
  9631. _initColorPicker(div, colorBox.eq(1));
  9632. _setColor(colorBox.eq(0), '#000000');
  9633. _setColor(colorBox.eq(1), '');
  9634. rowsBox[0].focus();
  9635. rowsBox[0].select();
  9636. var table;
  9637. if (isInsert) {
  9638. return;
  9639. }
  9640. table = self.plugin.getSelectedTable();
  9641. if (table) {
  9642. rowsBox.val(table[0].rows.length);
  9643. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9644. rowsBox.attr('disabled', true);
  9645. colsBox.attr('disabled', true);
  9646. var match,
  9647. tableWidth = table[0].style.width || table[0].width,
  9648. tableHeight = table[0].style.height || table[0].height;
  9649. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9650. widthBox.val(match[1]);
  9651. widthTypeBox.val(match[2]);
  9652. } else {
  9653. widthBox.val('');
  9654. }
  9655. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9656. heightBox.val(match[1]);
  9657. heightTypeBox.val(match[2]);
  9658. }
  9659. paddingBox.val(table[0].cellPadding || '');
  9660. spacingBox.val(table[0].cellSpacing || '');
  9661. alignBox.val(table[0].align || '');
  9662. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9663. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9664. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9665. widthBox[0].focus();
  9666. widthBox[0].select();
  9667. }
  9668. },
  9669. cellprop : function() {
  9670. var html = [
  9671. '<div style="padding:20px;">',
  9672. '<div class="ke-dialog-row">',
  9673. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9674. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9675. '<select name="widthType">',
  9676. '<option value="%">' + lang.percent + '</option>',
  9677. '<option value="px">' + lang.px + '</option>',
  9678. '</select> &nbsp; ',
  9679. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9680. '<select name="heightType">',
  9681. '<option value="%">' + lang.percent + '</option>',
  9682. '<option value="px">' + lang.px + '</option>',
  9683. '</select>',
  9684. '</div>',
  9685. '<div class="ke-dialog-row">',
  9686. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9687. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9688. '<option value="">' + lang.alignDefault + '</option>',
  9689. '<option value="left">' + lang.alignLeft + '</option>',
  9690. '<option value="center">' + lang.alignCenter + '</option>',
  9691. '<option value="right">' + lang.alignRight + '</option>',
  9692. '</select> ',
  9693. lang.verticalAlign + ' <select name="verticalAlign">',
  9694. '<option value="">' + lang.alignDefault + '</option>',
  9695. '<option value="top">' + lang.alignTop + '</option>',
  9696. '<option value="middle">' + lang.alignMiddle + '</option>',
  9697. '<option value="bottom">' + lang.alignBottom + '</option>',
  9698. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9699. '</select>',
  9700. '</div>',
  9701. '<div class="ke-dialog-row">',
  9702. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9703. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9704. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9705. '</div>',
  9706. '<div class="ke-dialog-row">',
  9707. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9708. '<span class="ke-inline-block ke-input-color"></span>',
  9709. '</div>',
  9710. '</div>'
  9711. ].join('');
  9712. var bookmark = self.cmd.range.createBookmark();
  9713. var dialog = self.createDialog({
  9714. name : name,
  9715. width : 500,
  9716. title : self.lang('tablecell'),
  9717. body : html,
  9718. beforeRemove : function() {
  9719. colorBox.unbind();
  9720. },
  9721. yesBtn : {
  9722. name : self.lang('yes'),
  9723. click : function(e) {
  9724. var width = widthBox.val(),
  9725. height = heightBox.val(),
  9726. widthType = widthTypeBox.val(),
  9727. heightType = heightTypeBox.val(),
  9728. padding = paddingBox.val(),
  9729. spacing = spacingBox.val(),
  9730. textAlign = textAlignBox.val(),
  9731. verticalAlign = verticalAlignBox.val(),
  9732. border = borderBox.val(),
  9733. borderColor = K(colorBox[0]).html() || '',
  9734. bgColor = K(colorBox[1]).html() || '';
  9735. if (!/^\d*$/.test(width)) {
  9736. alert(self.lang('invalidWidth'));
  9737. widthBox[0].focus();
  9738. return;
  9739. }
  9740. if (!/^\d*$/.test(height)) {
  9741. alert(self.lang('invalidHeight'));
  9742. heightBox[0].focus();
  9743. return;
  9744. }
  9745. if (!/^\d*$/.test(border)) {
  9746. alert(self.lang('invalidBorder'));
  9747. borderBox[0].focus();
  9748. return;
  9749. }
  9750. cell.css({
  9751. width : width !== '' ? (width + widthType) : '',
  9752. height : height !== '' ? (height + heightType) : '',
  9753. 'background-color' : bgColor,
  9754. 'text-align' : textAlign,
  9755. 'vertical-align' : verticalAlign,
  9756. 'border-width' : border,
  9757. 'border-style' : border !== '' ? 'solid' : '',
  9758. 'border-color' : borderColor
  9759. });
  9760. self.hideDialog().focus();
  9761. self.cmd.range.moveToBookmark(bookmark);
  9762. self.cmd.select();
  9763. self.addBookmark();
  9764. }
  9765. }
  9766. }),
  9767. div = dialog.div,
  9768. widthBox = K('[name="width"]', div).val(100),
  9769. heightBox = K('[name="height"]', div),
  9770. widthTypeBox = K('[name="widthType"]', div),
  9771. heightTypeBox = K('[name="heightType"]', div),
  9772. paddingBox = K('[name="padding"]', div).val(2),
  9773. spacingBox = K('[name="spacing"]', div).val(0),
  9774. textAlignBox = K('[name="textAlign"]', div),
  9775. verticalAlignBox = K('[name="verticalAlign"]', div),
  9776. borderBox = K('[name="border"]', div).val(1),
  9777. colorBox = K('.ke-input-color', div);
  9778. _initColorPicker(div, colorBox.eq(0));
  9779. _initColorPicker(div, colorBox.eq(1));
  9780. _setColor(colorBox.eq(0), '#000000');
  9781. _setColor(colorBox.eq(1), '');
  9782. widthBox[0].focus();
  9783. widthBox[0].select();
  9784. var cell = self.plugin.getSelectedCell();
  9785. var match,
  9786. cellWidth = cell[0].style.width || cell[0].width || '',
  9787. cellHeight = cell[0].style.height || cell[0].height || '';
  9788. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9789. widthBox.val(match[1]);
  9790. widthTypeBox.val(match[2]);
  9791. } else {
  9792. widthBox.val('');
  9793. }
  9794. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9795. heightBox.val(match[1]);
  9796. heightTypeBox.val(match[2]);
  9797. }
  9798. textAlignBox.val(cell[0].style.textAlign || '');
  9799. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9800. var border = cell[0].style.borderWidth || '';
  9801. if (border) {
  9802. border = parseInt(border);
  9803. }
  9804. borderBox.val(border);
  9805. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9806. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9807. widthBox[0].focus();
  9808. widthBox[0].select();
  9809. },
  9810. insert : function() {
  9811. this.prop(true);
  9812. },
  9813. 'delete' : function() {
  9814. var table = self.plugin.getSelectedTable();
  9815. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9816. self.cmd.select();
  9817. table.remove();
  9818. self.addBookmark();
  9819. },
  9820. colinsert : function(offset) {
  9821. var table = self.plugin.getSelectedTable()[0],
  9822. row = self.plugin.getSelectedRow()[0],
  9823. cell = self.plugin.getSelectedCell()[0],
  9824. index = cell.cellIndex + offset;
  9825. index += table.rows[0].cells.length - row.cells.length;
  9826. for (var i = 0, len = table.rows.length; i < len; i++) {
  9827. var newRow = table.rows[i],
  9828. newCell = newRow.insertCell(index);
  9829. newCell.innerHTML = K.IE ? '' : '<br />';
  9830. index = _getCellIndex(table, newRow, newCell);
  9831. }
  9832. self.cmd.range.selectNodeContents(cell).collapse(true);
  9833. self.cmd.select();
  9834. self.addBookmark();
  9835. },
  9836. colinsertleft : function() {
  9837. this.colinsert(0);
  9838. },
  9839. colinsertright : function() {
  9840. this.colinsert(1);
  9841. },
  9842. rowinsert : function(offset) {
  9843. var table = self.plugin.getSelectedTable()[0],
  9844. row = self.plugin.getSelectedRow()[0],
  9845. cell = self.plugin.getSelectedCell()[0];
  9846. var rowIndex = row.rowIndex;
  9847. if (offset === 1) {
  9848. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9849. }
  9850. var newRow = table.insertRow(rowIndex);
  9851. for (var i = 0, len = row.cells.length; i < len; i++) {
  9852. if (row.cells[i].rowSpan > 1) {
  9853. len -= row.cells[i].rowSpan - 1;
  9854. }
  9855. var newCell = newRow.insertCell(i);
  9856. if (offset === 1 && row.cells[i].colSpan > 1) {
  9857. newCell.colSpan = row.cells[i].colSpan;
  9858. }
  9859. newCell.innerHTML = K.IE ? '' : '<br />';
  9860. }
  9861. for (var j = rowIndex; j >= 0; j--) {
  9862. var cells = table.rows[j].cells;
  9863. if (cells.length > i) {
  9864. for (var k = cell.cellIndex; k >= 0; k--) {
  9865. if (cells[k].rowSpan > 1) {
  9866. cells[k].rowSpan += 1;
  9867. }
  9868. }
  9869. break;
  9870. }
  9871. }
  9872. self.cmd.range.selectNodeContents(cell).collapse(true);
  9873. self.cmd.select();
  9874. self.addBookmark();
  9875. },
  9876. rowinsertabove : function() {
  9877. this.rowinsert(0);
  9878. },
  9879. rowinsertbelow : function() {
  9880. this.rowinsert(1);
  9881. },
  9882. rowmerge : function() {
  9883. var table = self.plugin.getSelectedTable()[0],
  9884. row = self.plugin.getSelectedRow()[0],
  9885. cell = self.plugin.getSelectedCell()[0],
  9886. rowIndex = row.rowIndex,
  9887. nextRowIndex = rowIndex + cell.rowSpan,
  9888. nextRow = table.rows[nextRowIndex];
  9889. if (table.rows.length <= nextRowIndex) {
  9890. return;
  9891. }
  9892. var cellIndex = cell.cellIndex;
  9893. if (nextRow.cells.length <= cellIndex) {
  9894. return;
  9895. }
  9896. var nextCell = nextRow.cells[cellIndex];
  9897. if (cell.colSpan !== nextCell.colSpan) {
  9898. return;
  9899. }
  9900. cell.rowSpan += nextCell.rowSpan;
  9901. nextRow.deleteCell(cellIndex);
  9902. self.cmd.range.selectNodeContents(cell).collapse(true);
  9903. self.cmd.select();
  9904. self.addBookmark();
  9905. },
  9906. colmerge : function() {
  9907. var table = self.plugin.getSelectedTable()[0],
  9908. row = self.plugin.getSelectedRow()[0],
  9909. cell = self.plugin.getSelectedCell()[0],
  9910. rowIndex = row.rowIndex,
  9911. cellIndex = cell.cellIndex,
  9912. nextCellIndex = cellIndex + 1;
  9913. if (row.cells.length <= nextCellIndex) {
  9914. return;
  9915. }
  9916. var nextCell = row.cells[nextCellIndex];
  9917. if (cell.rowSpan !== nextCell.rowSpan) {
  9918. return;
  9919. }
  9920. cell.colSpan += nextCell.colSpan;
  9921. row.deleteCell(nextCellIndex);
  9922. self.cmd.range.selectNodeContents(cell).collapse(true);
  9923. self.cmd.select();
  9924. self.addBookmark();
  9925. },
  9926. rowsplit : function() {
  9927. var table = self.plugin.getSelectedTable()[0],
  9928. row = self.plugin.getSelectedRow()[0],
  9929. cell = self.plugin.getSelectedCell()[0],
  9930. rowIndex = row.rowIndex;
  9931. if (cell.rowSpan === 1) {
  9932. return;
  9933. }
  9934. var cellIndex = _getCellIndex(table, row, cell);
  9935. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9936. var newRow = table.rows[rowIndex + i],
  9937. newCell = newRow.insertCell(cellIndex);
  9938. if (cell.colSpan > 1) {
  9939. newCell.colSpan = cell.colSpan;
  9940. }
  9941. newCell.innerHTML = K.IE ? '' : '<br />';
  9942. cellIndex = _getCellIndex(table, newRow, newCell);
  9943. }
  9944. K(cell).removeAttr('rowSpan');
  9945. self.cmd.range.selectNodeContents(cell).collapse(true);
  9946. self.cmd.select();
  9947. self.addBookmark();
  9948. },
  9949. colsplit : function() {
  9950. var table = self.plugin.getSelectedTable()[0],
  9951. row = self.plugin.getSelectedRow()[0],
  9952. cell = self.plugin.getSelectedCell()[0],
  9953. cellIndex = cell.cellIndex;
  9954. if (cell.colSpan === 1) {
  9955. return;
  9956. }
  9957. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9958. var newCell = row.insertCell(cellIndex + i);
  9959. if (cell.rowSpan > 1) {
  9960. newCell.rowSpan = cell.rowSpan;
  9961. }
  9962. newCell.innerHTML = K.IE ? '' : '<br />';
  9963. }
  9964. K(cell).removeAttr('colSpan');
  9965. self.cmd.range.selectNodeContents(cell).collapse(true);
  9966. self.cmd.select();
  9967. self.addBookmark();
  9968. },
  9969. coldelete : function() {
  9970. var table = self.plugin.getSelectedTable()[0],
  9971. row = self.plugin.getSelectedRow()[0],
  9972. cell = self.plugin.getSelectedCell()[0],
  9973. index = cell.cellIndex;
  9974. for (var i = 0, len = table.rows.length; i < len; i++) {
  9975. var newRow = table.rows[i],
  9976. newCell = newRow.cells[index];
  9977. if (newCell.colSpan > 1) {
  9978. newCell.colSpan -= 1;
  9979. if (newCell.colSpan === 1) {
  9980. K(newCell).removeAttr('colSpan');
  9981. }
  9982. } else {
  9983. newRow.deleteCell(index);
  9984. }
  9985. if (newCell.rowSpan > 1) {
  9986. i += newCell.rowSpan - 1;
  9987. }
  9988. }
  9989. if (row.cells.length === 0) {
  9990. self.cmd.range.setStartBefore(table).collapse(true);
  9991. self.cmd.select();
  9992. K(table).remove();
  9993. } else {
  9994. self.cmd.selection(true);
  9995. }
  9996. self.addBookmark();
  9997. },
  9998. rowdelete : function() {
  9999. var table = self.plugin.getSelectedTable()[0],
  10000. row = self.plugin.getSelectedRow()[0],
  10001. cell = self.plugin.getSelectedCell()[0],
  10002. rowIndex = row.rowIndex;
  10003. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  10004. table.deleteRow(rowIndex + i);
  10005. }
  10006. if (table.rows.length === 0) {
  10007. self.cmd.range.setStartBefore(table).collapse(true);
  10008. self.cmd.select();
  10009. K(table).remove();
  10010. } else {
  10011. self.cmd.selection(true);
  10012. }
  10013. self.addBookmark();
  10014. }
  10015. };
  10016. self.clickToolbar(name, self.plugin.table.prop);
  10017. });
  10018. /*******************************************************************************
  10019. * KindEditor - WYSIWYG HTML Editor for Internet
  10020. * Copyright (C) 2006-2011 kindsoft.net
  10021. *
  10022. * @author Roddy <luolonghao@gmail.com>
  10023. * @site http://www.kindsoft.net/
  10024. * @licence http://www.kindsoft.net/license.php
  10025. *******************************************************************************/
  10026. KindEditor.plugin('template', function(K) {
  10027. var self = this, name = 'template', lang = self.lang(name + '.'),
  10028. htmlPath = self.pluginsPath + name + '/html/';
  10029. function getFilePath(fileName) {
  10030. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  10031. }
  10032. self.clickToolbar(name, function() {
  10033. var lang = self.lang(name + '.'),
  10034. arr = ['<div style="padding:10px 20px;">',
  10035. '<div class="ke-header">',
  10036. '<div class="ke-left">',
  10037. lang. selectTemplate + ' <select>'];
  10038. K.each(lang.fileList, function(key, val) {
  10039. arr.push('<option value="' + key + '">' + val + '</option>');
  10040. });
  10041. html = [arr.join(''),
  10042. '</select></div>',
  10043. '<div class="ke-right">',
  10044. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  10045. '</div>',
  10046. '<div class="ke-clearfix"></div>',
  10047. '</div>',
  10048. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  10049. '</div>'].join('');
  10050. var dialog = self.createDialog({
  10051. name : name,
  10052. width : 500,
  10053. title : self.lang(name),
  10054. body : html,
  10055. yesBtn : {
  10056. name : self.lang('yes'),
  10057. click : function(e) {
  10058. var doc = K.iframeDoc(iframe);
  10059. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  10060. }
  10061. }
  10062. });
  10063. var selectBox = K('select', dialog.div),
  10064. checkbox = K('[name="replaceFlag"]', dialog.div),
  10065. iframe = K('iframe', dialog.div);
  10066. checkbox[0].checked = true;
  10067. iframe.attr('src', getFilePath(selectBox.val()));
  10068. selectBox.change(function() {
  10069. iframe.attr('src', getFilePath(this.value));
  10070. });
  10071. });
  10072. });
  10073. /*******************************************************************************
  10074. * KindEditor - WYSIWYG HTML Editor for Internet
  10075. * Copyright (C) 2006-2011 kindsoft.net
  10076. *
  10077. * @author Roddy <luolonghao@gmail.com>
  10078. * @site http://www.kindsoft.net/
  10079. * @licence http://www.kindsoft.net/license.php
  10080. *******************************************************************************/
  10081. KindEditor.plugin('wordpaste', function(K) {
  10082. var self = this, name = 'wordpaste';
  10083. self.clickToolbar(name, function() {
  10084. var lang = self.lang(name + '.'),
  10085. html = '<div style="padding:10px 20px;">' +
  10086. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  10087. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  10088. '</div>',
  10089. dialog = self.createDialog({
  10090. name : name,
  10091. width : 450,
  10092. title : self.lang(name),
  10093. body : html,
  10094. yesBtn : {
  10095. name : self.lang('yes'),
  10096. click : function(e) {
  10097. var str = doc.body.innerHTML;
  10098. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  10099. self.insertHtml(str).hideDialog().focus();
  10100. }
  10101. }
  10102. }),
  10103. div = dialog.div,
  10104. iframe = K('iframe', div),
  10105. doc = K.iframeDoc(iframe);
  10106. if (!K.IE) {
  10107. doc.designMode = 'on';
  10108. }
  10109. doc.open();
  10110. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  10111. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  10112. if (!K.IE) {
  10113. doc.write('<br />');
  10114. }
  10115. doc.write('</body></html>');
  10116. doc.close();
  10117. if (K.IE) {
  10118. doc.body.contentEditable = 'true';
  10119. }
  10120. iframe[0].contentWindow.focus();
  10121. });
  10122. });
  10123. KindEditor.plugin('fixtoolbar', function (K) {
  10124. var self = this;
  10125. if (!self.fixToolBar) {
  10126. return;
  10127. }
  10128. function init() {
  10129. var toolbar = K('.ke-toolbar');
  10130. var originY = toolbar.pos().y;
  10131. K(window).bind('scroll', function () {
  10132. if (toolbar.css('position') == 'fixed') {
  10133. if(document.body.scrollTop - originY < 0){
  10134. toolbar.css('position', 'static');
  10135. toolbar.css('top', 'auto');
  10136. }
  10137. } else {
  10138. if (toolbar.pos().y - document.body.scrollTop < 0) {
  10139. toolbar.css('position', 'fixed');
  10140. toolbar.css('top', 0);
  10141. }
  10142. }
  10143. });
  10144. }
  10145. if (self.isCreated) {
  10146. init();
  10147. } else {
  10148. self.afterCreate(init);
  10149. }
  10150. });
  10151. //自定义资源库
  10152. KindEditor.plugin('res', function(K) {
  10153. var self = this;
  10154. // 点击图标时执行
  10155. self.clickToolbar('res', function() {
  10156. var clickFn = function(url, title, id) {
  10157. var html = '<embed src="{url}" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" id="{id}"/>';
  10158. html = html.replace('{url}', url);
  10159. html = html.replace('{id}', id);
  10160. self.insertHtml(html);
  10161. };
  10162. editorShowUpload('', self.fileManagerJson, '视频库', clickFn, this);
  10163. });
  10164. });
  10165. function autoImg(self) {
  10166. var index = self.index;
  10167. var haspicContainer = document.getElementById("has_pic_" + index);
  10168. if (haspicContainer == null) {
  10169. haspicContainer = document.createElement("div");
  10170. haspicContainer.id = "has_pic_" + index;
  10171. haspicContainer.innerHTML = "<input type='text' id='piclist_"+index+"' value='' style='display:none;'/><div id='upload_"+index+"' style='color:red'><b>您有图片需要上传到服务器</b>&nbsp;&nbsp;<a href='javascript:uploadpic(\""+self.uploadJson+"\", \""+self.filePostName+"\", \""+index+"\");' style='color:red'>[上传]</a></div><div id='confirm_"+index+"'></div>";
  10172. $(".ke-toolbar").eq(index).after(haspicContainer);
  10173. }
  10174. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10175. var piccount = 0;
  10176. var sstr = '';
  10177. $(img).each(function (i) {
  10178. var that = $(this);
  10179. var host = gethost(self.uploadResJson);
  10180. var yhost = '';
  10181. if (self.uploadYunJson && self.uploadYunJson.host) {
  10182. yhost = gethost(self.uploadYunJson.host);
  10183. }
  10184. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10185. var n = gethost(that.attr("src"));
  10186. if (yhost) {
  10187. if (host != n && yhost != n) {
  10188. piccount++;
  10189. if (i == $(img).length - 1)
  10190. sstr += that.attr("src");
  10191. else
  10192. sstr += that.attr("src") + ",";
  10193. }
  10194. } else {
  10195. if (host != n) {
  10196. piccount++;
  10197. if (i == $(img).length - 1)
  10198. sstr += that.attr("src");
  10199. else
  10200. sstr += that.attr("src") + ",";
  10201. }
  10202. }
  10203. }
  10204. });
  10205. $("#piclist_" + index).val(encodeURIComponent(sstr));
  10206. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  10207. }
  10208. function closeupload(index) {
  10209. $("#has_pic_" + index).hide();
  10210. $("#upload_" + index).show();
  10211. }
  10212. function uploadpic(url, name, index) {
  10213. var piclist = encodeURI($("#piclist_" + index).val());
  10214. if (piclist.length == 0) return false;
  10215. $.ajax({
  10216. url: url.replace('kindeditor', 'copys') + '&json=1',
  10217. data: name + "=" + piclist,
  10218. type: "POST",
  10219. dataType: "json",
  10220. beforeSend: function () {
  10221. $("#upload_" + index).hide();
  10222. $("#confirm_" + index).text("正在上传中...");
  10223. },
  10224. success: function (msg) {
  10225. var url = msg.data;
  10226. if (url !== "") {
  10227. var str = new Array();
  10228. str = url.split(',');
  10229. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10230. $(img).each(function (i) {
  10231. var that = $(this);
  10232. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10233. that.attr("src", str[i]);
  10234. that.attr("data-ke-src", str[i]);
  10235. }
  10236. });
  10237. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  10238. }
  10239. else $("#confirm_" + index).text("上传失败!");
  10240. }
  10241. });
  10242. }
  10243. function gethost(url){
  10244. var reg = /^http(s)?:\/\/(.*?)\//;
  10245. return reg.exec(url)[2];
  10246. }