kindeditor-all-min.js 304 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2017 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.12 (2017-04-12)
  9. *******************************************************************************/
  10. (function (window, undefined) {
  11. if (window.KindEditor) {
  12. return;
  13. }
  14. if (!window.console) {
  15. window.console = {};
  16. }
  17. if (!console.log) {
  18. console.log = function () {};
  19. }
  20. var _VERSION = '4.1.12 (2017-04-12)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  24. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  25. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  26. _OPERA = _ua.indexOf('opera') > -1,
  27. _MOBILE = _ua.indexOf('mobile') > -1,
  28. _IOS = /ipad|iphone|ipod/.test(_ua),
  29. _QUIRKS = document.compatMode != 'CSS1Compat',
  30. _IERANGE = !window.getSelection,
  31. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  32. _V = _matches ? _matches[1] : '0',
  33. _TIME = new Date().getTime();
  34. function _isArray(val) {
  35. if (!val) {
  36. return false;
  37. }
  38. return Object.prototype.toString.call(val) === '[object Array]';
  39. }
  40. function _isFunction(val) {
  41. if (!val) {
  42. return false;
  43. }
  44. return Object.prototype.toString.call(val) === '[object Function]';
  45. }
  46. function _inArray(val, arr) {
  47. for (var i = 0, len = arr.length; i < len; i++) {
  48. if (val === arr[i]) {
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. function _each(obj, fn) {
  55. if (_isArray(obj)) {
  56. for (var i = 0, len = obj.length; i < len; i++) {
  57. if (fn.call(obj[i], i, obj[i]) === false) {
  58. break;
  59. }
  60. }
  61. } else {
  62. for (var key in obj) {
  63. if (obj.hasOwnProperty(key)) {
  64. if (fn.call(obj[key], key, obj[key]) === false) {
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. function _trim(str) {
  72. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  73. }
  74. function _inString(val, str, delimiter) {
  75. delimiter = delimiter === undefined ? ',' : delimiter;
  76. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  77. }
  78. function _addUnit(val, unit) {
  79. unit = unit || 'px';
  80. return val && /^-?\d+(?:\.\d+)?$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function(key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function(key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () {};
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function(key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG : false,
  180. VERSION : _VERSION,
  181. IE : _IE,
  182. GECKO : _GECKO,
  183. WEBKIT : _WEBKIT,
  184. OPERA : _OPERA,
  185. V : _V,
  186. TIME : _TIME,
  187. each : _each,
  188. isArray : _isArray,
  189. isFunction : _isFunction,
  190. inArray : _inArray,
  191. inString : _inString,
  192. trim : _trim,
  193. addUnit : _addUnit,
  194. removeUnit : _removeUnit,
  195. escape : _escape,
  196. unescape : _unescape,
  197. toCamel : _toCamel,
  198. toHex : _toHex,
  199. toMap : _toMap,
  200. toArray : _toArray,
  201. undef : _undef,
  202. invalidUrl : _invalidUrl,
  203. addParam : _addParam,
  204. extend : _extend,
  205. json : _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. index : 0,
  230. designMode : true,
  231. fullscreenMode : false,
  232. filterMode : true,
  233. wellFormatMode : true,
  234. shadowMode : true,
  235. loadStyleMode : true,
  236. basePath : K.basePath,
  237. themesPath : K.basePath + 'themes/',
  238. langPath : K.basePath + 'lang/',
  239. pluginsPath : K.basePath + 'plugins/',
  240. themeType : 'default',
  241. langType : 'zh-CN',
  242. urlType : '',
  243. newlineTag : 'p',
  244. resizeType : 2,
  245. syncType : 'form',
  246. pasteType : 2,
  247. dialogAlignType : 'page',
  248. useContextmenu : true,
  249. fullscreenShortcut : false,
  250. bodyClass : 'ke-content',
  251. indentChar : '\t',
  252. cssPath : '',
  253. cssData : '',
  254. minWidth : 650,
  255. minHeight : 100,
  256. minChangeSize : 50,
  257. zIndex : 19850426,
  258. items : [
  259. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  260. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  261. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  262. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  263. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  264. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  265. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  266. 'anchor', 'link', 'unlink', '|', 'about'
  267. ],
  268. noDisableItems : ['source', 'fullscreen'],
  269. colorTable : [
  270. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  271. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  272. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  273. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  274. ],
  275. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  276. fontHeightTable : ['0px', '0.25px', '0.5px', '1px', '1.5px', '2px', '2.5px', '3px', '4px', '5px'],
  277. htmlTags : {
  278. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  279. span : [
  280. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  281. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  282. ],
  283. div : [
  284. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  285. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  286. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  287. ],
  288. table: [
  289. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  290. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  291. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  292. '.width', '.height', '.border-collapse'
  293. ],
  294. 'td,th': [
  295. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  296. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  297. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  298. ],
  299. a : ['id', 'class', 'href', 'target', 'name'],
  300. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  301. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  302. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  303. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  304. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  305. ],
  306. pre : ['id', 'class'],
  307. hr : ['id', 'class', '.page-break-after'],
  308. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  309. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  310. },
  311. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  312. };
  313. var _useCapture = false;
  314. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  315. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  316. var _CHANGE_KEY_MAP = {};
  317. _each(_INPUT_KEY_MAP, function(key, val) {
  318. _CHANGE_KEY_MAP[key] = val;
  319. });
  320. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  321. _CHANGE_KEY_MAP[key] = val;
  322. });
  323. function _bindEvent(el, type, fn) {
  324. if (el.addEventListener){
  325. el.addEventListener(type, fn, _useCapture);
  326. } else if (el.attachEvent){
  327. el.attachEvent('on' + type, fn);
  328. }
  329. }
  330. function _unbindEvent(el, type, fn) {
  331. if (el.removeEventListener){
  332. el.removeEventListener(type, fn, _useCapture);
  333. } else if (el.detachEvent){
  334. el.detachEvent('on' + type, fn);
  335. }
  336. }
  337. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  338. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  339. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  340. function KEvent(el, event) {
  341. this.init(el, event);
  342. }
  343. _extend(KEvent, {
  344. init : function(el, event) {
  345. var self = this, doc = el.ownerDocument || el.document || el;
  346. self.event = event;
  347. _each(_EVENT_PROPS, function(key, val) {
  348. self[val] = event[val];
  349. });
  350. if (!self.target) {
  351. self.target = self.srcElement || doc;
  352. }
  353. if (self.target.nodeType === 3) {
  354. self.target = self.target.parentNode;
  355. }
  356. if (!self.relatedTarget && self.fromElement) {
  357. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  358. }
  359. if (self.pageX == null && self.clientX != null) {
  360. var d = doc.documentElement, body = doc.body;
  361. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  362. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  363. }
  364. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  365. self.which = self.charCode || self.keyCode;
  366. }
  367. if (!self.metaKey && self.ctrlKey) {
  368. self.metaKey = self.ctrlKey;
  369. }
  370. if (!self.which && self.button !== undefined) {
  371. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  372. }
  373. switch (self.which) {
  374. case 186 :
  375. self.which = 59;
  376. break;
  377. case 187 :
  378. case 107 :
  379. case 43 :
  380. self.which = 61;
  381. break;
  382. case 189 :
  383. case 45 :
  384. self.which = 109;
  385. break;
  386. case 42 :
  387. self.which = 106;
  388. break;
  389. case 47 :
  390. self.which = 111;
  391. break;
  392. case 78 :
  393. self.which = 110;
  394. break;
  395. }
  396. if (self.which >= 96 && self.which <= 105) {
  397. self.which -= 48;
  398. }
  399. },
  400. preventDefault : function() {
  401. var ev = this.event;
  402. if (ev.preventDefault) {
  403. ev.preventDefault();
  404. } else {
  405. ev.returnValue = false;
  406. }
  407. },
  408. stopPropagation : function() {
  409. var ev = this.event;
  410. if (ev.stopPropagation) {
  411. ev.stopPropagation();
  412. } else {
  413. ev.cancelBubble = true;
  414. }
  415. },
  416. stop : function() {
  417. this.preventDefault();
  418. this.stopPropagation();
  419. }
  420. });
  421. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  422. function _getId(el) {
  423. return el[_eventExpendo] || null;
  424. }
  425. function _setId(el) {
  426. el[_eventExpendo] = ++_eventId;
  427. return _eventId;
  428. }
  429. function _removeId(el) {
  430. try {
  431. delete el[_eventExpendo];
  432. } catch(e) {
  433. if (el.removeAttribute) {
  434. el.removeAttribute(_eventExpendo);
  435. }
  436. }
  437. }
  438. function _bind(el, type, fn) {
  439. if (type.indexOf(',') >= 0) {
  440. _each(type.split(','), function() {
  441. _bind(el, this, fn);
  442. });
  443. return;
  444. }
  445. var id = _getId(el);
  446. if (!id) {
  447. id = _setId(el);
  448. }
  449. if (_eventData[id] === undefined) {
  450. _eventData[id] = {};
  451. }
  452. var events = _eventData[id][type];
  453. if (events && events.length > 0) {
  454. _unbindEvent(el, type, events[0]);
  455. } else {
  456. _eventData[id][type] = [];
  457. _eventData[id].el = el;
  458. }
  459. events = _eventData[id][type];
  460. if (events.length === 0) {
  461. events[0] = function(e) {
  462. var kevent = e ? new KEvent(el, e) : undefined;
  463. _each(events, function(i, event) {
  464. if (i > 0 && event) {
  465. event.call(el, kevent);
  466. }
  467. });
  468. };
  469. }
  470. if (_inArray(fn, events) < 0) {
  471. events.push(fn);
  472. }
  473. _bindEvent(el, type, events[0]);
  474. }
  475. function _unbind(el, type, fn) {
  476. if (type && type.indexOf(',') >= 0) {
  477. _each(type.split(','), function() {
  478. _unbind(el, this, fn);
  479. });
  480. return;
  481. }
  482. var id = _getId(el);
  483. if (!id) {
  484. return;
  485. }
  486. if (type === undefined) {
  487. if (id in _eventData) {
  488. _each(_eventData[id], function(key, events) {
  489. if (key != 'el' && events.length > 0) {
  490. _unbindEvent(el, key, events[0]);
  491. }
  492. });
  493. delete _eventData[id];
  494. _removeId(el);
  495. }
  496. return;
  497. }
  498. if (!_eventData[id]) {
  499. return;
  500. }
  501. var events = _eventData[id][type];
  502. if (events && events.length > 0) {
  503. if (fn === undefined) {
  504. _unbindEvent(el, type, events[0]);
  505. delete _eventData[id][type];
  506. } else {
  507. _each(events, function(i, event) {
  508. if (i > 0 && event === fn) {
  509. events.splice(i, 1);
  510. }
  511. });
  512. if (events.length == 1) {
  513. _unbindEvent(el, type, events[0]);
  514. delete _eventData[id][type];
  515. }
  516. }
  517. var count = 0;
  518. _each(_eventData[id], function() {
  519. count++;
  520. });
  521. if (count < 2) {
  522. delete _eventData[id];
  523. _removeId(el);
  524. }
  525. }
  526. }
  527. function _fire(el, type) {
  528. if (type.indexOf(',') >= 0) {
  529. _each(type.split(','), function() {
  530. _fire(el, this);
  531. });
  532. return;
  533. }
  534. var id = _getId(el);
  535. if (!id) {
  536. return;
  537. }
  538. var events = _eventData[id][type];
  539. if (_eventData[id] && events && events.length > 0) {
  540. events[0]();
  541. }
  542. }
  543. function _ctrl(el, key, fn) {
  544. var self = this;
  545. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  546. _bind(el, 'keydown', function(e) {
  547. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  548. fn.call(el);
  549. e.stop();
  550. }
  551. });
  552. }
  553. var _readyFinished = false;
  554. function _ready(fn) {
  555. if (_readyFinished) {
  556. fn(KindEditor);
  557. return;
  558. }
  559. var loaded = false;
  560. function readyFunc() {
  561. if (!loaded) {
  562. loaded = true;
  563. fn(KindEditor);
  564. _readyFinished = true;
  565. }
  566. }
  567. function ieReadyFunc() {
  568. if (!loaded) {
  569. try {
  570. document.documentElement.doScroll('left');
  571. } catch(e) {
  572. setTimeout(ieReadyFunc, 100);
  573. return;
  574. }
  575. readyFunc();
  576. }
  577. }
  578. function ieReadyStateFunc() {
  579. if (document.readyState === 'complete') {
  580. readyFunc();
  581. }
  582. }
  583. if (document.addEventListener) {
  584. _bind(document, 'DOMContentLoaded', readyFunc);
  585. } else if (document.attachEvent) {
  586. _bind(document, 'readystatechange', ieReadyStateFunc);
  587. var toplevel = false;
  588. try {
  589. toplevel = window.frameElement == null;
  590. } catch(e) {}
  591. if (document.documentElement.doScroll && toplevel) {
  592. ieReadyFunc();
  593. }
  594. }
  595. _bind(window, 'load', readyFunc);
  596. }
  597. if (window.attachEvent) {
  598. window.attachEvent('onunload', function() {
  599. _each(_eventData, function(key, events) {
  600. if (events.el) {
  601. _unbind(events.el);
  602. }
  603. });
  604. });
  605. }
  606. K.ctrl = _ctrl;
  607. K.ready = _ready;
  608. function _getCssList(css) {
  609. css = css.replace(/&quot;/g, '"');
  610. var list = {},
  611. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  612. match;
  613. while ((match = reg.exec(css))) {
  614. var key = _trim(match[1].toLowerCase()),
  615. val = _trim(_toHex(match[2]));
  616. list[key] = val;
  617. }
  618. return list;
  619. }
  620. function _getAttrList(tag) {
  621. var list = {},
  622. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  623. match;
  624. while ((match = reg.exec(tag))) {
  625. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  626. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  627. list[key] = val;
  628. }
  629. return list;
  630. }
  631. function _addClassToTag(tag, className) {
  632. if (/\s+class\s*=/.test(tag)) {
  633. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  634. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  635. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  636. } else {
  637. return $0;
  638. }
  639. });
  640. } else {
  641. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  642. }
  643. return tag;
  644. }
  645. function _formatCss(css) {
  646. var str = '';
  647. _each(_getCssList(css), function(key, val) {
  648. str += key + ':' + val + ';';
  649. });
  650. return str;
  651. }
  652. function _formatUrl(url, mode, host, pathname) {
  653. return url;
  654. mode = _undef(mode, '').toLowerCase();
  655. if (url.substr(0, 5) != 'data:') {
  656. url = url.replace(/([^:])\/\//g, '$1/');
  657. }
  658. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  659. return url;
  660. }
  661. host = host || location.protocol + '//' + location.host;
  662. if (pathname === undefined) {
  663. var m = location.pathname.match(/^(\/.*)\//);
  664. pathname = m ? m[1] : '';
  665. }
  666. var match;
  667. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  668. if (match[1] !== host) {
  669. return url;
  670. }
  671. } else if (/^\w+:/.test(url)) {
  672. return url;
  673. }
  674. function getRealPath(path) {
  675. var parts = path.split('/'), paths = [];
  676. for (var i = 0, len = parts.length; i < len; i++) {
  677. var part = parts[i];
  678. if (part == '..') {
  679. if (paths.length > 0) {
  680. paths.pop();
  681. }
  682. } else if (part !== '' && part != '.') {
  683. paths.push(part);
  684. }
  685. }
  686. return '/' + paths.join('/');
  687. }
  688. if (/^\//.test(url)) {
  689. url = host + getRealPath(url.substr(1));
  690. } else if (!/^\w+:\/\//.test(url)) {
  691. url = host + getRealPath(pathname + '/' + url);
  692. }
  693. function getRelativePath(path, depth) {
  694. if (url.substr(0, path.length) === path) {
  695. var arr = [];
  696. for (var i = 0; i < depth; i++) {
  697. arr.push('..');
  698. }
  699. var prefix = '.';
  700. if (arr.length > 0) {
  701. prefix += '/' + arr.join('/');
  702. }
  703. if (pathname == '/') {
  704. prefix += '/';
  705. }
  706. return prefix + url.substr(path.length);
  707. } else {
  708. if ((match = /^(.*)\//.exec(path))) {
  709. return getRelativePath(match[1], ++depth);
  710. }
  711. }
  712. }
  713. if (mode === 'relative') {
  714. url = getRelativePath(host + pathname, 0).substr(2);
  715. } else if (mode === 'absolute') {
  716. if (url.substr(0, host.length) === host) {
  717. url = url.substr(host.length);
  718. }
  719. }
  720. return url;
  721. }
  722. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  723. if (html == null) {
  724. html = '';
  725. }
  726. urlType = urlType || '';
  727. wellFormatted = _undef(wellFormatted, false);
  728. indentChar = _undef(indentChar, '\t');
  729. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  730. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  731. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  732. });
  733. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  734. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  735. html = html.replace(/\u200B/g, '');
  736. html = html.replace(/\u00A9/g, '&copy;');
  737. html = html.replace(/\u00AE/g, '&reg;');
  738. html = html.replace(/\u2003/g, '&emsp;');
  739. html = html.replace(/\u3000/g, '&emsp;');
  740. html = html.replace(/&quot;/g, '');
  741. html = html.replace(/, " helvetica=""(.*?)"="/g, '');
  742. html = html.replace(/<[^>]+/g, function($0) {
  743. return $0.replace(/\s+/g, ' ');
  744. });
  745. var htmlTagMap = {};
  746. if (htmlTags) {
  747. _each(htmlTags, function(key, val) {
  748. var arr = key.split(',');
  749. for (var i = 0, len = arr.length; i < len; i++) {
  750. htmlTagMap[arr[i]] = _toMap(val);
  751. }
  752. });
  753. if (!htmlTagMap.script) {
  754. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  755. }
  756. if (!htmlTagMap.style) {
  757. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  758. }
  759. }
  760. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  761. var tagStack = [];
  762. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  763. var full = $0,
  764. startNewline = $1 || '',
  765. startSlash = $2 || '',
  766. tagName = $3.toLowerCase(),
  767. attr = $4 || '',
  768. endSlash = $5 ? ' ' + $5 : '',
  769. endNewline = $6 || '';
  770. if (htmlTags && !htmlTagMap[tagName]) {
  771. return '';
  772. }
  773. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  774. endSlash = ' /';
  775. }
  776. if (_INLINE_TAG_MAP[tagName]) {
  777. if (startNewline) {
  778. startNewline = ' ';
  779. }
  780. if (endNewline) {
  781. endNewline = ' ';
  782. }
  783. }
  784. if (_PRE_TAG_MAP[tagName]) {
  785. if (startSlash) {
  786. endNewline = '\n';
  787. } else {
  788. startNewline = '\n';
  789. }
  790. }
  791. if (wellFormatted && tagName == 'br') {
  792. endNewline = '\n';
  793. }
  794. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  795. if (wellFormatted) {
  796. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  797. tagStack.pop();
  798. } else {
  799. tagStack.push(tagName);
  800. }
  801. startNewline = '\n';
  802. endNewline = '\n';
  803. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  804. startNewline += indentChar;
  805. if (!startSlash) {
  806. endNewline += indentChar;
  807. }
  808. }
  809. if (endSlash) {
  810. tagStack.pop();
  811. } else if (!startSlash) {
  812. endNewline += indentChar;
  813. }
  814. } else {
  815. startNewline = endNewline = '';
  816. }
  817. }
  818. if (attr !== '') {
  819. var attrMap = _getAttrList(full);
  820. if (tagName === 'font') {
  821. var fontStyleMap = {}, fontStyle = '';
  822. _each(attrMap, function(key, val) {
  823. if (key === 'color') {
  824. fontStyleMap.color = val;
  825. delete attrMap[key];
  826. }
  827. if (key === 'size') {
  828. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  829. delete attrMap[key];
  830. }
  831. if (key === 'face') {
  832. fontStyleMap['font-family'] = val;
  833. delete attrMap[key];
  834. }
  835. if (key === 'style') {
  836. fontStyle = val;
  837. }
  838. });
  839. if (fontStyle && !/;$/.test(fontStyle)) {
  840. fontStyle += ';';
  841. }
  842. _each(fontStyleMap, function(key, val) {
  843. if (val === '') {
  844. return;
  845. }
  846. if (/\s/.test(val)) {
  847. val = "'" + val + "'";
  848. }
  849. fontStyle += key + ':' + val + ';';
  850. });
  851. attrMap.style = fontStyle;
  852. }
  853. _each(attrMap, function(key, val) {
  854. if (_FILL_ATTR_MAP[key]) {
  855. attrMap[key] = key;
  856. }
  857. if (_inArray(key, ['src', 'href']) >= 0) {
  858. attrMap[key] = _formatUrl(val, urlType);
  859. }
  860. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  861. tagName === 'body' && key === 'contenteditable' ||
  862. /^kindeditor_\d+$/.test(key)) {
  863. delete attrMap[key];
  864. }
  865. if (key === 'style' && val !== '') {
  866. var styleMap = _getCssList(val);
  867. _each(styleMap, function(k, v) {
  868. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  869. delete styleMap[k];
  870. }
  871. });
  872. var style = '';
  873. _each(styleMap, function(k, v) {
  874. style += k + ':' + v + ';';
  875. });
  876. attrMap.style = style;
  877. }
  878. });
  879. attr = '';
  880. _each(attrMap, function(key, val) {
  881. if (key === 'style' && val === '') {
  882. return;
  883. }
  884. val = val.replace(/"/g, '&quot;');
  885. attr += ' ' + key + '="' + val + '"';
  886. });
  887. }
  888. if (tagName === 'font') {
  889. tagName = 'span';
  890. }
  891. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  892. });
  893. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  894. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  895. });
  896. html = html.replace(/\n\s*\n/g, '\n');
  897. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  898. return _trim(html);
  899. }
  900. function _clearMsWord(html, htmlTags) {
  901. html = html.replace(/<meta[\s\S]*?>/ig, '')
  902. .replace(/<![\s\S]*?>/ig, '')
  903. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  904. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  905. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  906. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  907. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  908. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  909. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  910. });
  911. return _formatHtml(html, htmlTags);
  912. }
  913. function _mediaType(src) {
  914. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  915. return 'audio/x-pn-realaudio-plugin';
  916. }
  917. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  918. return 'application/x-shockwave-flash';
  919. }
  920. return 'video/x-ms-asf-plugin';
  921. }
  922. function _mediaClass(type) {
  923. if (/realaudio/i.test(type)) {
  924. return 'ke-rm';
  925. }
  926. if (/flash/i.test(type)) {
  927. return 'ke-flash';
  928. }
  929. return 'ke-media';
  930. }
  931. function _mediaAttrs(srcTag) {
  932. return _getAttrList(unescape(srcTag));
  933. }
  934. function _mediaEmbed(attrs) {
  935. var html = '<embed ';
  936. _each(attrs, function(key, val) {
  937. html += key + '="' + val + '" ';
  938. });
  939. html += '/>';
  940. return html;
  941. }
  942. function _mediaImg(blankPath, attrs) {
  943. var width = attrs.width,
  944. height = attrs.height,
  945. type = attrs.type || _mediaType(attrs.src),
  946. srcTag = _mediaEmbed(attrs),
  947. style = '';
  948. if (/\D/.test(width)) {
  949. style += 'width:' + width + ';';
  950. } else if (width > 0) {
  951. style += 'width:' + width + 'px;';
  952. }
  953. if (/\D/.test(height)) {
  954. style += 'height:' + height + ';';
  955. } else if (height > 0) {
  956. style += 'height:' + height + 'px;';
  957. }
  958. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  959. if (style !== '') {
  960. html += 'style="' + style + '" ';
  961. }
  962. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  963. return html;
  964. }
  965. function _tmpl(str, data) {
  966. var fn = new Function("obj",
  967. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  968. "with(obj){p.push('" +
  969. str.replace(/[\r\t\n]/g, " ")
  970. .split("<%").join("\t")
  971. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  972. .replace(/\t=(.*?)%>/g, "',$1,'")
  973. .split("\t").join("');")
  974. .split("%>").join("p.push('")
  975. .split("\r").join("\\'") + "');}return p.join('');");
  976. return data ? fn(data) : fn;
  977. }
  978. K.formatUrl = _formatUrl;
  979. K.formatHtml = _formatHtml;
  980. K.getCssList = _getCssList;
  981. K.getAttrList = _getAttrList;
  982. K.mediaType = _mediaType;
  983. K.mediaAttrs = _mediaAttrs;
  984. K.mediaEmbed = _mediaEmbed;
  985. K.mediaImg = _mediaImg;
  986. K.clearMsWord = _clearMsWord;
  987. K.tmpl = _tmpl;
  988. function _contains(nodeA, nodeB) {
  989. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  990. return true;
  991. }
  992. while ((nodeB = nodeB.parentNode)) {
  993. if (nodeB == nodeA) {
  994. return true;
  995. }
  996. }
  997. return false;
  998. }
  999. var _getSetAttrDiv = document.createElement('div');
  1000. _getSetAttrDiv.setAttribute('className', 't');
  1001. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1002. function _getAttr(el, key) {
  1003. key = key.toLowerCase();
  1004. var val = null;
  1005. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1006. var div = el.ownerDocument.createElement('div');
  1007. div.appendChild(el.cloneNode(false));
  1008. var list = _getAttrList(_unescape(div.innerHTML));
  1009. if (key in list) {
  1010. val = list[key];
  1011. }
  1012. } else {
  1013. try {
  1014. val = el.getAttribute(key, 2);
  1015. } catch(e) {
  1016. val = el.getAttribute(key, 1);
  1017. }
  1018. }
  1019. if (key === 'style' && val !== null) {
  1020. val = _formatCss(val);
  1021. }
  1022. return val;
  1023. }
  1024. function _queryAll(expr, root) {
  1025. var exprList = expr.split(',');
  1026. if (exprList.length > 1) {
  1027. var mergedResults = [];
  1028. _each(exprList, function() {
  1029. _each(_queryAll(this, root), function() {
  1030. if (_inArray(this, mergedResults) < 0) {
  1031. mergedResults.push(this);
  1032. }
  1033. });
  1034. });
  1035. return mergedResults;
  1036. }
  1037. root = root || document;
  1038. function escape(str) {
  1039. if (typeof str != 'string') {
  1040. return str;
  1041. }
  1042. return str.replace(/([^\w\-])/g, '\\$1');
  1043. }
  1044. function stripslashes(str) {
  1045. return str.replace(/\\/g, '');
  1046. }
  1047. function cmpTag(tagA, tagB) {
  1048. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1049. }
  1050. function byId(id, tag, root) {
  1051. var arr = [],
  1052. doc = root.ownerDocument || root,
  1053. el = doc.getElementById(stripslashes(id));
  1054. if (el) {
  1055. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1056. arr.push(el);
  1057. }
  1058. }
  1059. return arr;
  1060. }
  1061. function byClass(className, tag, root) {
  1062. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1063. if (root.getElementsByClassName) {
  1064. els = root.getElementsByClassName(stripslashes(className));
  1065. for (i = 0, len = els.length; i < len; i++) {
  1066. el = els[i];
  1067. if (cmpTag(tag, el.nodeName)) {
  1068. arr.push(el);
  1069. }
  1070. }
  1071. } else if (doc.querySelectorAll) {
  1072. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1073. for (i = 0, len = els.length; i < len; i++) {
  1074. el = els[i];
  1075. if (_contains(root, el)) {
  1076. arr.push(el);
  1077. }
  1078. }
  1079. } else {
  1080. els = root.getElementsByTagName(tag);
  1081. className = ' ' + className + ' ';
  1082. for (i = 0, len = els.length; i < len; i++) {
  1083. el = els[i];
  1084. if (el.nodeType == 1) {
  1085. var cls = el.className;
  1086. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1087. arr.push(el);
  1088. }
  1089. }
  1090. }
  1091. }
  1092. return arr;
  1093. }
  1094. function byName(name, tag, root) {
  1095. var arr = [], doc = root.ownerDocument || root,
  1096. els = doc.getElementsByName(stripslashes(name)), el;
  1097. for (var i = 0, len = els.length; i < len; i++) {
  1098. el = els[i];
  1099. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1100. if (el.getAttribute('name') !== null) {
  1101. arr.push(el);
  1102. }
  1103. }
  1104. }
  1105. return arr;
  1106. }
  1107. function byAttr(key, val, tag, root) {
  1108. var arr = [], els = root.getElementsByTagName(tag), el;
  1109. for (var i = 0, len = els.length; i < len; i++) {
  1110. el = els[i];
  1111. if (el.nodeType == 1) {
  1112. if (val === null) {
  1113. if (_getAttr(el, key) !== null) {
  1114. arr.push(el);
  1115. }
  1116. } else {
  1117. if (val === escape(_getAttr(el, key))) {
  1118. arr.push(el);
  1119. }
  1120. }
  1121. }
  1122. }
  1123. return arr;
  1124. }
  1125. function select(expr, root) {
  1126. var arr = [], matches;
  1127. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1128. var tag = matches ? matches[1] : '*';
  1129. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1130. arr = byId(matches[1], tag, root);
  1131. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1132. arr = byClass(matches[1], tag, root);
  1133. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1134. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1135. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1136. var key = matches[1].toLowerCase(), val = matches[2];
  1137. if (key === 'id') {
  1138. arr = byId(val, tag, root);
  1139. } else if (key === 'class') {
  1140. arr = byClass(val, tag, root);
  1141. } else if (key === 'name') {
  1142. arr = byName(val, tag, root);
  1143. } else {
  1144. arr = byAttr(key, val, tag, root);
  1145. }
  1146. } else {
  1147. var els = root.getElementsByTagName(tag), el;
  1148. for (var i = 0, len = els.length; i < len; i++) {
  1149. el = els[i];
  1150. if (el.nodeType == 1) {
  1151. arr.push(el);
  1152. }
  1153. }
  1154. }
  1155. return arr;
  1156. }
  1157. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1158. while ((arr = re.exec(expr))) {
  1159. if (arr[1] !== ' ') {
  1160. parts.push(arr[1]);
  1161. }
  1162. }
  1163. var results = [];
  1164. if (parts.length == 1) {
  1165. return select(parts[0], root);
  1166. }
  1167. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1168. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1169. part = parts[i];
  1170. if (part === '>') {
  1171. isChild = true;
  1172. continue;
  1173. }
  1174. if (i > 0) {
  1175. els = [];
  1176. for (j = 0, len = results.length; j < len; j++) {
  1177. val = results[j];
  1178. subResults = select(part, val);
  1179. for (k = 0, l = subResults.length; k < l; k++) {
  1180. v = subResults[k];
  1181. if (isChild) {
  1182. if (val === v.parentNode) {
  1183. els.push(v);
  1184. }
  1185. } else {
  1186. els.push(v);
  1187. }
  1188. }
  1189. }
  1190. results = els;
  1191. } else {
  1192. results = select(part, root);
  1193. }
  1194. if (results.length === 0) {
  1195. return [];
  1196. }
  1197. }
  1198. return results;
  1199. }
  1200. function _query(expr, root) {
  1201. var arr = _queryAll(expr, root);
  1202. return arr.length > 0 ? arr[0] : null;
  1203. }
  1204. K.query = _query;
  1205. K.queryAll = _queryAll;
  1206. function _get(val) {
  1207. return K(val)[0];
  1208. }
  1209. function _getDoc(node) {
  1210. if (!node) {
  1211. return document;
  1212. }
  1213. return node.ownerDocument || node.document || node;
  1214. }
  1215. function _getWin(node) {
  1216. if (!node) {
  1217. return window;
  1218. }
  1219. var doc = _getDoc(node);
  1220. return doc.parentWindow || doc.defaultView;
  1221. }
  1222. function _setHtml(el, html) {
  1223. if (el.nodeType != 1) {
  1224. return;
  1225. }
  1226. var doc = _getDoc(el);
  1227. try {
  1228. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1229. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1230. temp.parentNode.removeChild(temp);
  1231. } catch(e) {
  1232. K(el).empty();
  1233. K('@' + html, doc).each(function() {
  1234. el.appendChild(this);
  1235. });
  1236. }
  1237. }
  1238. function _hasClass(el, cls) {
  1239. return _inString(cls, el.className, ' ');
  1240. }
  1241. function _setAttr(el, key, val) {
  1242. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1243. key = 'className';
  1244. }
  1245. el.setAttribute(key, '' + val);
  1246. }
  1247. function _removeAttr(el, key) {
  1248. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1249. key = 'className';
  1250. }
  1251. _setAttr(el, key, '');
  1252. el.removeAttribute(key);
  1253. }
  1254. function _getNodeName(node) {
  1255. if (!node || !node.nodeName) {
  1256. return '';
  1257. }
  1258. return node.nodeName.toLowerCase();
  1259. }
  1260. function _computedCss(el, key) {
  1261. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1262. if (win.getComputedStyle) {
  1263. var style = win.getComputedStyle(el, null);
  1264. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1265. } else if (el.currentStyle) {
  1266. val = el.currentStyle[camelKey] || el.style[camelKey];
  1267. }
  1268. return val;
  1269. }
  1270. function _hasVal(node) {
  1271. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1272. }
  1273. function _docElement(doc) {
  1274. doc = doc || document;
  1275. return _QUIRKS ? doc.body : doc.documentElement;
  1276. }
  1277. function _docHeight(doc) {
  1278. var el = _docElement(doc);
  1279. return Math.max(el.scrollHeight, el.clientHeight);
  1280. }
  1281. function _docWidth(doc) {
  1282. var el = _docElement(doc);
  1283. return Math.max(el.scrollWidth, el.clientWidth);
  1284. }
  1285. function _getScrollPos(doc) {
  1286. doc = doc || document;
  1287. var x, y;
  1288. if (_IE || _NEWIE || _OPERA) {
  1289. x = _docElement(doc).scrollLeft;
  1290. y = _docElement(doc).scrollTop;
  1291. } else {
  1292. x = _getWin(doc).scrollX;
  1293. y = _getWin(doc).scrollY;
  1294. }
  1295. return {x : x, y : y};
  1296. }
  1297. function KNode(node) {
  1298. this.init(node);
  1299. }
  1300. _extend(KNode, {
  1301. init : function(node) {
  1302. var self = this;
  1303. node = _isArray(node) ? node : [node];
  1304. var length = 0;
  1305. for (var i = 0, len = node.length; i < len; i++) {
  1306. if (node[i]) {
  1307. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1308. length++;
  1309. }
  1310. }
  1311. self.length = length;
  1312. self.doc = _getDoc(self[0]);
  1313. self.name = _getNodeName(self[0]);
  1314. self.type = self.length > 0 ? self[0].nodeType : null;
  1315. self.win = _getWin(self[0]);
  1316. },
  1317. each : function(fn) {
  1318. var self = this;
  1319. for (var i = 0; i < self.length; i++) {
  1320. if (fn.call(self[i], i, self[i]) === false) {
  1321. return self;
  1322. }
  1323. }
  1324. return self;
  1325. },
  1326. bind : function(type, fn) {
  1327. this.each(function() {
  1328. _bind(this, type, fn);
  1329. });
  1330. return this;
  1331. },
  1332. unbind : function(type, fn) {
  1333. this.each(function() {
  1334. _unbind(this, type, fn);
  1335. });
  1336. return this;
  1337. },
  1338. fire : function(type) {
  1339. if (this.length < 1) {
  1340. return this;
  1341. }
  1342. _fire(this[0], type);
  1343. return this;
  1344. },
  1345. hasAttr : function(key) {
  1346. if (this.length < 1) {
  1347. return false;
  1348. }
  1349. return !!_getAttr(this[0], key);
  1350. },
  1351. attr : function(key, val) {
  1352. var self = this;
  1353. if (key === undefined) {
  1354. return _getAttrList(self.outer());
  1355. }
  1356. if (typeof key === 'object') {
  1357. _each(key, function(k, v) {
  1358. self.attr(k, v);
  1359. });
  1360. return self;
  1361. }
  1362. if (val === undefined) {
  1363. val = self.length < 1 ? null : _getAttr(self[0], key);
  1364. return val === null ? '' : val;
  1365. }
  1366. self.each(function() {
  1367. _setAttr(this, key, val);
  1368. });
  1369. return self;
  1370. },
  1371. removeAttr : function(key) {
  1372. this.each(function() {
  1373. _removeAttr(this, key);
  1374. });
  1375. return this;
  1376. },
  1377. get : function(i) {
  1378. if (this.length < 1) {
  1379. return null;
  1380. }
  1381. return this[i || 0];
  1382. },
  1383. eq : function(i) {
  1384. if (this.length < 1) {
  1385. return null;
  1386. }
  1387. return this[i] ? new KNode(this[i]) : null;
  1388. },
  1389. hasClass : function(cls) {
  1390. if (this.length < 1) {
  1391. return false;
  1392. }
  1393. return _hasClass(this[0], cls);
  1394. },
  1395. addClass : function(cls) {
  1396. this.each(function() {
  1397. if (!_hasClass(this, cls)) {
  1398. this.className = _trim(this.className + ' ' + cls);
  1399. }
  1400. });
  1401. return this;
  1402. },
  1403. removeClass : function(cls) {
  1404. this.each(function() {
  1405. if (_hasClass(this, cls)) {
  1406. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1407. }
  1408. });
  1409. return this;
  1410. },
  1411. html : function(val) {
  1412. var self = this;
  1413. if (val === undefined) {
  1414. if (self.length < 1 || self.type != 1) {
  1415. return '';
  1416. }
  1417. return _formatHtml(self[0].innerHTML);
  1418. }
  1419. self.each(function() {
  1420. _setHtml(this, val);
  1421. });
  1422. return self;
  1423. },
  1424. text : function() {
  1425. var self = this;
  1426. if (self.length < 1) {
  1427. return '';
  1428. }
  1429. return _IE ? self[0].innerText : self[0].textContent;
  1430. },
  1431. hasVal : function() {
  1432. if (this.length < 1) {
  1433. return false;
  1434. }
  1435. return _hasVal(this[0]);
  1436. },
  1437. val : function(val) {
  1438. var self = this;
  1439. if (val === undefined) {
  1440. if (self.length < 1) {
  1441. return '';
  1442. }
  1443. return self.hasVal() ? self[0].value : self.attr('value');
  1444. } else {
  1445. self.each(function() {
  1446. if (_hasVal(this)) {
  1447. this.value = val;
  1448. } else {
  1449. _setAttr(this, 'value' , val);
  1450. }
  1451. });
  1452. return self;
  1453. }
  1454. },
  1455. css : function(key, val) {
  1456. var self = this;
  1457. if (key === undefined) {
  1458. return _getCssList(self.attr('style'));
  1459. }
  1460. if (typeof key === 'object') {
  1461. _each(key, function(k, v) {
  1462. self.css(k, v);
  1463. });
  1464. return self;
  1465. }
  1466. if (val === undefined) {
  1467. if (self.length < 1) {
  1468. return '';
  1469. }
  1470. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1471. }
  1472. self.each(function() {
  1473. this.style[_toCamel(key)] = val;
  1474. });
  1475. return self;
  1476. },
  1477. width : function(val) {
  1478. var self = this;
  1479. if (val === undefined) {
  1480. if (self.length < 1) {
  1481. return 0;
  1482. }
  1483. return self[0].offsetWidth;
  1484. }
  1485. return self.css('width', _addUnit(val));
  1486. },
  1487. height : function(val) {
  1488. var self = this;
  1489. if (val === undefined) {
  1490. if (self.length < 1) {
  1491. return 0;
  1492. }
  1493. return self[0].offsetHeight;
  1494. }
  1495. return self.css('height', _addUnit(val));
  1496. },
  1497. opacity : function(val) {
  1498. this.each(function() {
  1499. if (this.style.opacity === undefined) {
  1500. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1501. } else {
  1502. this.style.opacity = val == 1 ? '' : val;
  1503. }
  1504. });
  1505. return this;
  1506. },
  1507. data : function(key, val) {
  1508. var self = this;
  1509. key = 'kindeditor_data_' + key;
  1510. if (val === undefined) {
  1511. if (self.length < 1) {
  1512. return null;
  1513. }
  1514. return self[0][key];
  1515. }
  1516. this.each(function() {
  1517. this[key] = val;
  1518. });
  1519. return self;
  1520. },
  1521. pos : function() {
  1522. var self = this, node = self[0], x = 0, y = 0;
  1523. if (node) {
  1524. if (node.getBoundingClientRect) {
  1525. var box = node.getBoundingClientRect(),
  1526. pos = _getScrollPos(self.doc);
  1527. x = box.left + pos.x;
  1528. y = box.top + pos.y;
  1529. } else {
  1530. while (node) {
  1531. x += node.offsetLeft;
  1532. y += node.offsetTop;
  1533. node = node.offsetParent;
  1534. }
  1535. }
  1536. }
  1537. return {x : _round(x), y : _round(y)};
  1538. },
  1539. clone : function(bool) {
  1540. if (this.length < 1) {
  1541. return new KNode([]);
  1542. }
  1543. return new KNode(this[0].cloneNode(bool));
  1544. },
  1545. append : function(expr) {
  1546. this.each(function() {
  1547. if (this.appendChild) {
  1548. this.appendChild(_get(expr));
  1549. }
  1550. });
  1551. return this;
  1552. },
  1553. appendTo : function(expr) {
  1554. this.each(function() {
  1555. _get(expr).appendChild(this);
  1556. });
  1557. return this;
  1558. },
  1559. before : function(expr) {
  1560. this.each(function() {
  1561. this.parentNode.insertBefore(_get(expr), this);
  1562. });
  1563. return this;
  1564. },
  1565. after : function(expr) {
  1566. this.each(function() {
  1567. if (this.nextSibling) {
  1568. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1569. } else {
  1570. this.parentNode.appendChild(_get(expr));
  1571. }
  1572. });
  1573. return this;
  1574. },
  1575. replaceWith : function(expr) {
  1576. var nodes = [];
  1577. this.each(function(i, node) {
  1578. _unbind(node);
  1579. var newNode = _get(expr);
  1580. node.parentNode.replaceChild(newNode, node);
  1581. nodes.push(newNode);
  1582. });
  1583. return K(nodes);
  1584. },
  1585. empty : function() {
  1586. var self = this;
  1587. self.each(function(i, node) {
  1588. var child = node.firstChild;
  1589. while (child) {
  1590. if (!node.parentNode) {
  1591. return;
  1592. }
  1593. var next = child.nextSibling;
  1594. child.parentNode.removeChild(child);
  1595. child = next;
  1596. }
  1597. });
  1598. return self;
  1599. },
  1600. remove : function(keepChilds) {
  1601. var self = this;
  1602. self.each(function(i, node) {
  1603. if (!node.parentNode) {
  1604. return;
  1605. }
  1606. _unbind(node);
  1607. if (keepChilds) {
  1608. var child = node.firstChild;
  1609. while (child) {
  1610. var next = child.nextSibling;
  1611. node.parentNode.insertBefore(child, node);
  1612. child = next;
  1613. }
  1614. }
  1615. node.parentNode.removeChild(node);
  1616. delete self[i];
  1617. });
  1618. self.length = 0;
  1619. return self;
  1620. },
  1621. show : function(val) {
  1622. var self = this;
  1623. if (val === undefined) {
  1624. val = self._originDisplay || '';
  1625. }
  1626. if (self.css('display') != 'none') {
  1627. return self;
  1628. }
  1629. return self.css('display', val);
  1630. },
  1631. hide : function() {
  1632. var self = this;
  1633. if (self.length < 1) {
  1634. return self;
  1635. }
  1636. self._originDisplay = self[0].style.display;
  1637. return self.css('display', 'none');
  1638. },
  1639. outer : function() {
  1640. var self = this;
  1641. if (self.length < 1) {
  1642. return '';
  1643. }
  1644. var div = self.doc.createElement('div'), html;
  1645. div.appendChild(self[0].cloneNode(true));
  1646. html = _formatHtml(div.innerHTML);
  1647. div = null;
  1648. return html;
  1649. },
  1650. isSingle : function() {
  1651. return !!_SINGLE_TAG_MAP[this.name];
  1652. },
  1653. isInline : function() {
  1654. return !!_INLINE_TAG_MAP[this.name];
  1655. },
  1656. isBlock : function() {
  1657. return !!_BLOCK_TAG_MAP[this.name];
  1658. },
  1659. isStyle : function() {
  1660. return !!_STYLE_TAG_MAP[this.name];
  1661. },
  1662. isControl : function() {
  1663. return !!_CONTROL_TAG_MAP[this.name];
  1664. },
  1665. contains : function(otherNode) {
  1666. if (this.length < 1) {
  1667. return false;
  1668. }
  1669. return _contains(this[0], _get(otherNode));
  1670. },
  1671. parent : function() {
  1672. if (this.length < 1) {
  1673. return null;
  1674. }
  1675. var node = this[0].parentNode;
  1676. return node ? new KNode(node) : null;
  1677. },
  1678. children : function() {
  1679. if (this.length < 1) {
  1680. return new KNode([]);
  1681. }
  1682. var list = [], child = this[0].firstChild;
  1683. while (child) {
  1684. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1685. list.push(child);
  1686. }
  1687. child = child.nextSibling;
  1688. }
  1689. return new KNode(list);
  1690. },
  1691. first : function() {
  1692. var list = this.children();
  1693. return list.length > 0 ? list.eq(0) : null;
  1694. },
  1695. last : function() {
  1696. var list = this.children();
  1697. return list.length > 0 ? list.eq(list.length - 1) : null;
  1698. },
  1699. index : function() {
  1700. if (this.length < 1) {
  1701. return -1;
  1702. }
  1703. var i = -1, sibling = this[0];
  1704. while (sibling) {
  1705. i++;
  1706. sibling = sibling.previousSibling;
  1707. }
  1708. return i;
  1709. },
  1710. prev : function() {
  1711. if (this.length < 1) {
  1712. return null;
  1713. }
  1714. var node = this[0].previousSibling;
  1715. return node ? new KNode(node) : null;
  1716. },
  1717. next : function() {
  1718. if (this.length < 1) {
  1719. return null;
  1720. }
  1721. var node = this[0].nextSibling;
  1722. return node ? new KNode(node) : null;
  1723. },
  1724. scan : function(fn, order) {
  1725. if (this.length < 1) {
  1726. return;
  1727. }
  1728. order = (order === undefined) ? true : order;
  1729. function walk(node) {
  1730. var n = order ? node.firstChild : node.lastChild;
  1731. while (n) {
  1732. var next = order ? n.nextSibling : n.previousSibling;
  1733. if (fn(n) === false) {
  1734. return false;
  1735. }
  1736. if (walk(n) === false) {
  1737. return false;
  1738. }
  1739. n = next;
  1740. }
  1741. }
  1742. walk(this[0]);
  1743. return this;
  1744. }
  1745. });
  1746. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1747. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1748. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1749. KNode.prototype[type] = function(fn) {
  1750. return fn ? this.bind(type, fn) : this.fire(type);
  1751. };
  1752. });
  1753. var _K = K;
  1754. K = function(expr, root) {
  1755. if (expr === undefined || expr === null) {
  1756. return;
  1757. }
  1758. function newNode(node) {
  1759. if (!node[0]) {
  1760. node = [];
  1761. }
  1762. return new KNode(node);
  1763. }
  1764. if (typeof expr === 'string') {
  1765. if (root) {
  1766. root = _get(root);
  1767. }
  1768. var length = expr.length;
  1769. if (expr.charAt(0) === '@') {
  1770. expr = expr.substr(1);
  1771. }
  1772. if (expr.length !== length || /<.+>/.test(expr)) {
  1773. var doc = root ? root.ownerDocument || root : document,
  1774. div = doc.createElement('div'), list = [];
  1775. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1776. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1777. var child = div.childNodes[i];
  1778. if (child.id == '__kindeditor_temp_tag__') {
  1779. continue;
  1780. }
  1781. list.push(child);
  1782. }
  1783. return newNode(list);
  1784. }
  1785. return newNode(_queryAll(expr, root));
  1786. }
  1787. if (expr && expr.constructor === KNode) {
  1788. return expr;
  1789. }
  1790. if (expr.toArray) {
  1791. expr = expr.toArray();
  1792. }
  1793. if (_isArray(expr)) {
  1794. return newNode(expr);
  1795. }
  1796. return newNode(_toArray(arguments));
  1797. };
  1798. _each(_K, function(key, val) {
  1799. K[key] = val;
  1800. });
  1801. K.NodeClass = KNode;
  1802. window.KindEditor = K;
  1803. var _START_TO_START = 0,
  1804. _START_TO_END = 1,
  1805. _END_TO_END = 2,
  1806. _END_TO_START = 3,
  1807. _BOOKMARK_ID = 0;
  1808. function _updateCollapsed(range) {
  1809. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1810. return range;
  1811. }
  1812. function _copyAndDelete(range, isCopy, isDelete) {
  1813. var doc = range.doc, nodeList = [];
  1814. function splitTextNode(node, startOffset, endOffset) {
  1815. var length = node.nodeValue.length, centerNode;
  1816. if (isCopy) {
  1817. var cloneNode = node.cloneNode(true);
  1818. if (startOffset > 0) {
  1819. centerNode = cloneNode.splitText(startOffset);
  1820. } else {
  1821. centerNode = cloneNode;
  1822. }
  1823. if (endOffset < length) {
  1824. centerNode.splitText(endOffset - startOffset);
  1825. }
  1826. }
  1827. if (isDelete) {
  1828. var center = node;
  1829. if (startOffset > 0) {
  1830. center = node.splitText(startOffset);
  1831. range.setStart(node, startOffset);
  1832. }
  1833. if (endOffset < length) {
  1834. var right = center.splitText(endOffset - startOffset);
  1835. range.setEnd(right, 0);
  1836. }
  1837. nodeList.push(center);
  1838. }
  1839. return centerNode;
  1840. }
  1841. function removeNodes() {
  1842. if (isDelete) {
  1843. range.up().collapse(true);
  1844. }
  1845. for (var i = 0, len = nodeList.length; i < len; i++) {
  1846. var node = nodeList[i];
  1847. if (node.parentNode) {
  1848. node.parentNode.removeChild(node);
  1849. }
  1850. }
  1851. }
  1852. var copyRange = range.cloneRange().down();
  1853. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1854. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1855. if (ancestor.nodeType == 3) {
  1856. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1857. if (isCopy) {
  1858. frag.appendChild(textNode);
  1859. }
  1860. removeNodes();
  1861. return isCopy ? frag : range;
  1862. }
  1863. function extractNodes(parent, frag) {
  1864. var node = parent.firstChild, nextNode;
  1865. while (node) {
  1866. var testRange = new KRange(doc).selectNode(node);
  1867. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1868. if (start >= 0 && incStart <= 0) {
  1869. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1870. }
  1871. if (incStart >= 0 && incEnd <= 0) {
  1872. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1873. }
  1874. if (incEnd >= 0 && end <= 0) {
  1875. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1876. }
  1877. if (end >= 0) {
  1878. return false;
  1879. }
  1880. nextNode = node.nextSibling;
  1881. if (start > 0) {
  1882. if (node.nodeType == 1) {
  1883. if (incStart >= 0 && incEnd <= 0) {
  1884. if (isCopy) {
  1885. frag.appendChild(node.cloneNode(true));
  1886. }
  1887. if (isDelete) {
  1888. nodeList.push(node);
  1889. }
  1890. } else {
  1891. var childFlag;
  1892. if (isCopy) {
  1893. childFlag = node.cloneNode(false);
  1894. frag.appendChild(childFlag);
  1895. }
  1896. if (extractNodes(node, childFlag) === false) {
  1897. return false;
  1898. }
  1899. }
  1900. } else if (node.nodeType == 3) {
  1901. var textNode;
  1902. if (node == copyRange.startContainer) {
  1903. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1904. } else if (node == copyRange.endContainer) {
  1905. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1906. } else {
  1907. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1908. }
  1909. if (isCopy) {
  1910. try {
  1911. frag.appendChild(textNode);
  1912. } catch(e) {}
  1913. }
  1914. }
  1915. }
  1916. node = nextNode;
  1917. }
  1918. }
  1919. extractNodes(ancestor, frag);
  1920. if (isDelete) {
  1921. range.up().collapse(true);
  1922. }
  1923. for (var i = 0, len = nodeList.length; i < len; i++) {
  1924. var node = nodeList[i];
  1925. if (node.parentNode) {
  1926. node.parentNode.removeChild(node);
  1927. }
  1928. }
  1929. return isCopy ? frag : range;
  1930. }
  1931. function _moveToElementText(range, el) {
  1932. var node = el;
  1933. while (node) {
  1934. var knode = K(node);
  1935. if (knode.name == 'marquee' || knode.name == 'select') {
  1936. return;
  1937. }
  1938. node = node.parentNode;
  1939. }
  1940. try {
  1941. range.moveToElementText(el);
  1942. } catch(e) {}
  1943. }
  1944. function _getStartEnd(rng, isStart) {
  1945. var doc = rng.parentElement().ownerDocument,
  1946. pointRange = rng.duplicate();
  1947. pointRange.collapse(isStart);
  1948. var parent = pointRange.parentElement(),
  1949. nodes = parent.childNodes;
  1950. if (nodes.length === 0) {
  1951. return {node: parent.parentNode, offset: K(parent).index()};
  1952. }
  1953. var startNode = doc, startPos = 0, cmp = -1;
  1954. var testRange = rng.duplicate();
  1955. _moveToElementText(testRange, parent);
  1956. for (var i = 0, len = nodes.length; i < len; i++) {
  1957. var node = nodes[i];
  1958. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1959. if (cmp === 0) {
  1960. return {node: node.parentNode, offset: i};
  1961. }
  1962. if (node.nodeType == 1) {
  1963. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1964. if (knode.isControl()) {
  1965. dummy = doc.createElement('span');
  1966. knode.after(dummy);
  1967. newNode = dummy;
  1968. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1969. }
  1970. _moveToElementText(nodeRange, newNode);
  1971. testRange.setEndPoint('StartToEnd', nodeRange);
  1972. if (cmp > 0) {
  1973. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1974. } else {
  1975. startPos = 0;
  1976. }
  1977. if (dummy) {
  1978. K(dummy).remove();
  1979. }
  1980. } else if (node.nodeType == 3) {
  1981. testRange.moveStart('character', node.nodeValue.length);
  1982. startPos += node.nodeValue.length;
  1983. }
  1984. if (cmp < 0) {
  1985. startNode = node;
  1986. }
  1987. }
  1988. if (cmp < 0 && startNode.nodeType == 1) {
  1989. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1990. }
  1991. if (cmp > 0) {
  1992. while (startNode.nextSibling && startNode.nodeType == 1) {
  1993. startNode = startNode.nextSibling;
  1994. }
  1995. }
  1996. testRange = rng.duplicate();
  1997. _moveToElementText(testRange, parent);
  1998. testRange.setEndPoint('StartToEnd', pointRange);
  1999. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  2000. if (cmp > 0 && startNode.nodeType == 3) {
  2001. var prevNode = startNode.previousSibling;
  2002. while (prevNode && prevNode.nodeType == 3) {
  2003. startPos -= prevNode.nodeValue.length;
  2004. prevNode = prevNode.previousSibling;
  2005. }
  2006. }
  2007. return {node: startNode, offset: startPos};
  2008. }
  2009. function _getEndRange(node, offset) {
  2010. var doc = node.ownerDocument || node,
  2011. range = doc.body.createTextRange();
  2012. if (doc == node) {
  2013. range.collapse(true);
  2014. return range;
  2015. }
  2016. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2017. var children = node.childNodes, isStart, child;
  2018. if (offset === 0) {
  2019. child = children[0];
  2020. isStart = true;
  2021. } else {
  2022. child = children[offset - 1];
  2023. isStart = false;
  2024. }
  2025. if (!child) {
  2026. return range;
  2027. }
  2028. if (K(child).name === 'head') {
  2029. if (offset === 1) {
  2030. isStart = true;
  2031. }
  2032. if (offset === 2) {
  2033. isStart = false;
  2034. }
  2035. range.collapse(isStart);
  2036. return range;
  2037. }
  2038. if (child.nodeType == 1) {
  2039. var kchild = K(child), span;
  2040. if (kchild.isControl()) {
  2041. span = doc.createElement('span');
  2042. if (isStart) {
  2043. kchild.before(span);
  2044. } else {
  2045. kchild.after(span);
  2046. }
  2047. child = span;
  2048. }
  2049. _moveToElementText(range, child);
  2050. range.collapse(isStart);
  2051. if (span) {
  2052. K(span).remove();
  2053. }
  2054. return range;
  2055. }
  2056. node = child;
  2057. offset = isStart ? 0 : child.nodeValue.length;
  2058. }
  2059. var dummy = doc.createElement('span');
  2060. K(node).before(dummy);
  2061. _moveToElementText(range, dummy);
  2062. range.moveStart('character', offset);
  2063. K(dummy).remove();
  2064. return range;
  2065. }
  2066. function _toRange(rng) {
  2067. var doc, range;
  2068. function tr2td(start) {
  2069. if (K(start.node).name == 'tr') {
  2070. start.node = start.node.cells[start.offset];
  2071. start.offset = 0;
  2072. }
  2073. }
  2074. if (_IERANGE) {
  2075. if (rng.item) {
  2076. doc = _getDoc(rng.item(0));
  2077. range = new KRange(doc);
  2078. range.selectNode(rng.item(0));
  2079. return range;
  2080. }
  2081. doc = rng.parentElement().ownerDocument;
  2082. var start = _getStartEnd(rng, true),
  2083. end = _getStartEnd(rng, false);
  2084. tr2td(start);
  2085. tr2td(end);
  2086. range = new KRange(doc);
  2087. range.setStart(start.node, start.offset);
  2088. range.setEnd(end.node, end.offset);
  2089. return range;
  2090. }
  2091. var startContainer = rng.startContainer;
  2092. doc = startContainer.ownerDocument || startContainer;
  2093. range = new KRange(doc);
  2094. range.setStart(startContainer, rng.startOffset);
  2095. range.setEnd(rng.endContainer, rng.endOffset);
  2096. return range;
  2097. }
  2098. function KRange(doc) {
  2099. this.init(doc);
  2100. }
  2101. _extend(KRange, {
  2102. init : function(doc) {
  2103. var self = this;
  2104. self.startContainer = doc;
  2105. self.startOffset = 0;
  2106. self.endContainer = doc;
  2107. self.endOffset = 0;
  2108. self.collapsed = true;
  2109. self.doc = doc;
  2110. },
  2111. commonAncestor : function() {
  2112. function getParents(node) {
  2113. var parents = [];
  2114. while (node) {
  2115. parents.push(node);
  2116. node = node.parentNode;
  2117. }
  2118. return parents;
  2119. }
  2120. var parentsA = getParents(this.startContainer),
  2121. parentsB = getParents(this.endContainer),
  2122. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2123. while (++i) {
  2124. parentA = parentsA[lenA - i];
  2125. parentB = parentsB[lenB - i];
  2126. if (!parentA || !parentB || parentA !== parentB) {
  2127. break;
  2128. }
  2129. }
  2130. return parentsA[lenA - i + 1];
  2131. },
  2132. setStart : function(node, offset) {
  2133. var self = this, doc = self.doc;
  2134. self.startContainer = node;
  2135. self.startOffset = offset;
  2136. if (self.endContainer === doc) {
  2137. self.endContainer = node;
  2138. self.endOffset = offset;
  2139. }
  2140. return _updateCollapsed(this);
  2141. },
  2142. setEnd : function(node, offset) {
  2143. var self = this, doc = self.doc;
  2144. self.endContainer = node;
  2145. self.endOffset = offset;
  2146. if (self.startContainer === doc) {
  2147. self.startContainer = node;
  2148. self.startOffset = offset;
  2149. }
  2150. return _updateCollapsed(this);
  2151. },
  2152. setStartBefore : function(node) {
  2153. return this.setStart(node.parentNode || this.doc, K(node).index());
  2154. },
  2155. setStartAfter : function(node) {
  2156. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2157. },
  2158. setEndBefore : function(node) {
  2159. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2160. },
  2161. setEndAfter : function(node) {
  2162. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2163. },
  2164. selectNode : function(node) {
  2165. return this.setStartBefore(node).setEndAfter(node);
  2166. },
  2167. selectNodeContents : function(node) {
  2168. var knode = K(node);
  2169. if (knode.type == 3 || knode.isSingle()) {
  2170. return this.selectNode(node);
  2171. }
  2172. var children = knode.children();
  2173. if (children.length > 0) {
  2174. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2175. }
  2176. return this.setStart(node, 0).setEnd(node, 0);
  2177. },
  2178. collapse : function(toStart) {
  2179. if (toStart) {
  2180. return this.setEnd(this.startContainer, this.startOffset);
  2181. }
  2182. return this.setStart(this.endContainer, this.endOffset);
  2183. },
  2184. compareBoundaryPoints : function(how, range) {
  2185. var rangeA = this.get(), rangeB = range.get();
  2186. if (_IERANGE) {
  2187. var arr = {};
  2188. arr[_START_TO_START] = 'StartToStart';
  2189. arr[_START_TO_END] = 'EndToStart';
  2190. arr[_END_TO_END] = 'EndToEnd';
  2191. arr[_END_TO_START] = 'StartToEnd';
  2192. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2193. if (cmp !== 0) {
  2194. return cmp;
  2195. }
  2196. var nodeA, nodeB, nodeC, posA, posB;
  2197. if (how === _START_TO_START || how === _END_TO_START) {
  2198. nodeA = this.startContainer;
  2199. posA = this.startOffset;
  2200. }
  2201. if (how === _START_TO_END || how === _END_TO_END) {
  2202. nodeA = this.endContainer;
  2203. posA = this.endOffset;
  2204. }
  2205. if (how === _START_TO_START || how === _START_TO_END) {
  2206. nodeB = range.startContainer;
  2207. posB = range.startOffset;
  2208. }
  2209. if (how === _END_TO_END || how === _END_TO_START) {
  2210. nodeB = range.endContainer;
  2211. posB = range.endOffset;
  2212. }
  2213. if (nodeA === nodeB) {
  2214. var diff = posA - posB;
  2215. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2216. }
  2217. nodeC = nodeB;
  2218. while (nodeC && nodeC.parentNode !== nodeA) {
  2219. nodeC = nodeC.parentNode;
  2220. }
  2221. if (nodeC) {
  2222. return K(nodeC).index() >= posA ? -1 : 1;
  2223. }
  2224. nodeC = nodeA;
  2225. while (nodeC && nodeC.parentNode !== nodeB) {
  2226. nodeC = nodeC.parentNode;
  2227. }
  2228. if (nodeC) {
  2229. return K(nodeC).index() >= posB ? 1 : -1;
  2230. }
  2231. nodeC = K(nodeB).next();
  2232. if (nodeC && nodeC.contains(nodeA)) {
  2233. return 1;
  2234. }
  2235. nodeC = K(nodeA).next();
  2236. if (nodeC && nodeC.contains(nodeB)) {
  2237. return -1;
  2238. }
  2239. } else {
  2240. return rangeA.compareBoundaryPoints(how, rangeB);
  2241. }
  2242. },
  2243. cloneRange : function() {
  2244. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2245. },
  2246. toString : function() {
  2247. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2248. return str.replace(/\r\n|\n|\r/g, '');
  2249. },
  2250. cloneContents : function() {
  2251. return _copyAndDelete(this, true, false);
  2252. },
  2253. deleteContents : function() {
  2254. return _copyAndDelete(this, false, true);
  2255. },
  2256. extractContents : function() {
  2257. return _copyAndDelete(this, true, true);
  2258. },
  2259. insertNode : function(node) {
  2260. var self = this,
  2261. sc = self.startContainer, so = self.startOffset,
  2262. ec = self.endContainer, eo = self.endOffset,
  2263. firstChild, lastChild, c, nodeCount = 1;
  2264. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2265. firstChild = node.firstChild;
  2266. lastChild = node.lastChild;
  2267. nodeCount = node.childNodes.length;
  2268. }
  2269. if (sc.nodeType == 1) {
  2270. c = sc.childNodes[so];
  2271. if (c) {
  2272. sc.insertBefore(node, c);
  2273. if (sc === ec) {
  2274. eo += nodeCount;
  2275. }
  2276. } else {
  2277. sc.appendChild(node);
  2278. }
  2279. } else if (sc.nodeType == 3) {
  2280. if (so === 0) {
  2281. sc.parentNode.insertBefore(node, sc);
  2282. if (sc.parentNode === ec) {
  2283. eo += nodeCount;
  2284. }
  2285. } else if (so >= sc.nodeValue.length) {
  2286. if (sc.nextSibling) {
  2287. sc.parentNode.insertBefore(node, sc.nextSibling);
  2288. } else {
  2289. sc.parentNode.appendChild(node);
  2290. }
  2291. } else {
  2292. if (so > 0) {
  2293. c = sc.splitText(so);
  2294. } else {
  2295. c = sc;
  2296. }
  2297. sc.parentNode.insertBefore(node, c);
  2298. if (sc === ec) {
  2299. ec = c;
  2300. eo -= so;
  2301. }
  2302. }
  2303. }
  2304. if (firstChild) {
  2305. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2306. } else {
  2307. self.selectNode(node);
  2308. }
  2309. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2310. return self;
  2311. }
  2312. return self.setEnd(ec, eo);
  2313. },
  2314. surroundContents : function(node) {
  2315. node.appendChild(this.extractContents());
  2316. return this.insertNode(node).selectNode(node);
  2317. },
  2318. isControl : function() {
  2319. var self = this,
  2320. sc = self.startContainer, so = self.startOffset,
  2321. ec = self.endContainer, eo = self.endOffset, rng;
  2322. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2323. },
  2324. get : function(hasControlRange) {
  2325. var self = this, doc = self.doc, node, rng;
  2326. if (!_IERANGE) {
  2327. rng = doc.createRange();
  2328. try {
  2329. rng.setStart(self.startContainer, self.startOffset);
  2330. rng.setEnd(self.endContainer, self.endOffset);
  2331. } catch (e) {}
  2332. return rng;
  2333. }
  2334. if (hasControlRange && self.isControl()) {
  2335. rng = doc.body.createControlRange();
  2336. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2337. return rng;
  2338. }
  2339. var range = self.cloneRange().down();
  2340. rng = doc.body.createTextRange();
  2341. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2342. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2343. return rng;
  2344. },
  2345. html : function() {
  2346. return K(this.cloneContents()).outer();
  2347. },
  2348. down : function() {
  2349. var self = this;
  2350. function downPos(node, pos, isStart) {
  2351. if (node.nodeType != 1) {
  2352. return;
  2353. }
  2354. var children = K(node).children();
  2355. if (children.length === 0) {
  2356. return;
  2357. }
  2358. var left, right, child, offset;
  2359. if (pos > 0) {
  2360. left = children.eq(pos - 1);
  2361. }
  2362. if (pos < children.length) {
  2363. right = children.eq(pos);
  2364. }
  2365. if (left && left.type == 3) {
  2366. child = left[0];
  2367. offset = child.nodeValue.length;
  2368. }
  2369. if (right && right.type == 3) {
  2370. child = right[0];
  2371. offset = 0;
  2372. }
  2373. if (!child) {
  2374. return;
  2375. }
  2376. if (isStart) {
  2377. self.setStart(child, offset);
  2378. } else {
  2379. self.setEnd(child, offset);
  2380. }
  2381. }
  2382. downPos(self.startContainer, self.startOffset, true);
  2383. downPos(self.endContainer, self.endOffset, false);
  2384. return self;
  2385. },
  2386. up : function() {
  2387. var self = this;
  2388. function upPos(node, pos, isStart) {
  2389. if (node.nodeType != 3) {
  2390. return;
  2391. }
  2392. if (pos === 0) {
  2393. if (isStart) {
  2394. self.setStartBefore(node);
  2395. } else {
  2396. self.setEndBefore(node);
  2397. }
  2398. } else if (pos == node.nodeValue.length) {
  2399. if (isStart) {
  2400. self.setStartAfter(node);
  2401. } else {
  2402. self.setEndAfter(node);
  2403. }
  2404. }
  2405. }
  2406. upPos(self.startContainer, self.startOffset, true);
  2407. upPos(self.endContainer, self.endOffset, false);
  2408. return self;
  2409. },
  2410. enlarge : function(toBlock) {
  2411. var self = this;
  2412. self.up();
  2413. function enlargePos(node, pos, isStart) {
  2414. var knode = K(node), parent;
  2415. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2416. return;
  2417. }
  2418. if (pos === 0) {
  2419. while (!knode.prev()) {
  2420. parent = knode.parent();
  2421. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2422. break;
  2423. }
  2424. knode = parent;
  2425. }
  2426. if (isStart) {
  2427. self.setStartBefore(knode[0]);
  2428. } else {
  2429. self.setEndBefore(knode[0]);
  2430. }
  2431. } else if (pos == knode.children().length) {
  2432. while (!knode.next()) {
  2433. parent = knode.parent();
  2434. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2435. break;
  2436. }
  2437. knode = parent;
  2438. }
  2439. if (isStart) {
  2440. self.setStartAfter(knode[0]);
  2441. } else {
  2442. self.setEndAfter(knode[0]);
  2443. }
  2444. }
  2445. }
  2446. enlargePos(self.startContainer, self.startOffset, true);
  2447. enlargePos(self.endContainer, self.endOffset, false);
  2448. return self;
  2449. },
  2450. shrink : function() {
  2451. var self = this, child, collapsed = self.collapsed;
  2452. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2453. self.setStart(child, 0);
  2454. }
  2455. if (collapsed) {
  2456. return self.collapse(collapsed);
  2457. }
  2458. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2459. self.setEnd(child, child.childNodes.length);
  2460. }
  2461. return self;
  2462. },
  2463. createBookmark : function(serialize) {
  2464. var self = this, doc = self.doc, endNode,
  2465. startNode = K('<span style="display:none;"></span>', doc)[0];
  2466. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2467. if (!self.collapsed) {
  2468. endNode = startNode.cloneNode(true);
  2469. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2470. }
  2471. if (endNode) {
  2472. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2473. }
  2474. self.insertNode(startNode).setStartAfter(startNode);
  2475. return {
  2476. start : serialize ? '#' + startNode.id : startNode,
  2477. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2478. };
  2479. },
  2480. moveToBookmark : function(bookmark) {
  2481. var self = this, doc = self.doc,
  2482. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2483. if (!start || start.length < 1) {
  2484. return self;
  2485. }
  2486. self.setStartBefore(start[0]);
  2487. start.remove();
  2488. if (end && end.length > 0) {
  2489. self.setEndBefore(end[0]);
  2490. end.remove();
  2491. } else {
  2492. self.collapse(true);
  2493. }
  2494. return self;
  2495. },
  2496. dump : function() {
  2497. console.log('--------------------');
  2498. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2499. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2500. }
  2501. });
  2502. function _range(mixed) {
  2503. if (!mixed.nodeName) {
  2504. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2505. }
  2506. return new KRange(mixed);
  2507. }
  2508. K.RangeClass = KRange;
  2509. K.range = _range;
  2510. K.START_TO_START = _START_TO_START;
  2511. K.START_TO_END = _START_TO_END;
  2512. K.END_TO_END = _END_TO_END;
  2513. K.END_TO_START = _END_TO_START;
  2514. function _nativeCommand(doc, key, val) {
  2515. try {
  2516. doc.execCommand(key, false, val);
  2517. } catch(e) {}
  2518. }
  2519. function _nativeCommandValue(doc, key) {
  2520. var val = '';
  2521. try {
  2522. val = doc.queryCommandValue(key);
  2523. } catch (e) {}
  2524. if (typeof val !== 'string') {
  2525. val = '';
  2526. }
  2527. return val;
  2528. }
  2529. function _getSel(doc) {
  2530. var win = _getWin(doc);
  2531. return _IERANGE ? doc.selection : win.getSelection();
  2532. }
  2533. function _getRng(doc) {
  2534. var sel = _getSel(doc), rng;
  2535. try {
  2536. if (sel.rangeCount > 0) {
  2537. rng = sel.getRangeAt(0);
  2538. } else {
  2539. rng = sel.createRange();
  2540. }
  2541. } catch(e) {}
  2542. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2543. return null;
  2544. }
  2545. return rng;
  2546. }
  2547. function _singleKeyMap(map) {
  2548. var newMap = {}, arr, v;
  2549. _each(map, function(key, val) {
  2550. arr = key.split(',');
  2551. for (var i = 0, len = arr.length; i < len; i++) {
  2552. v = arr[i];
  2553. newMap[v] = val;
  2554. }
  2555. });
  2556. return newMap;
  2557. }
  2558. function _hasAttrOrCss(knode, map) {
  2559. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2560. }
  2561. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2562. mapKey = mapKey || knode.name;
  2563. if (knode.type !== 1) {
  2564. return false;
  2565. }
  2566. var newMap = _singleKeyMap(map);
  2567. if (!newMap[mapKey]) {
  2568. return false;
  2569. }
  2570. var arr = newMap[mapKey].split(',');
  2571. for (var i = 0, len = arr.length; i < len; i++) {
  2572. var key = arr[i];
  2573. if (key === '*') {
  2574. return true;
  2575. }
  2576. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2577. var method = match[1] ? 'css' : 'attr';
  2578. key = match[2];
  2579. var val = match[3] || '';
  2580. if (val === '' && knode[method](key) !== '') {
  2581. return true;
  2582. }
  2583. if (val !== '' && knode[method](key) === val) {
  2584. return true;
  2585. }
  2586. }
  2587. return false;
  2588. }
  2589. function _removeAttrOrCss(knode, map) {
  2590. if (knode.type != 1) {
  2591. return;
  2592. }
  2593. _removeAttrOrCssByKey(knode, map, '*');
  2594. _removeAttrOrCssByKey(knode, map);
  2595. }
  2596. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2597. mapKey = mapKey || knode.name;
  2598. if (knode.type !== 1) {
  2599. return;
  2600. }
  2601. var newMap = _singleKeyMap(map);
  2602. if (!newMap[mapKey]) {
  2603. return;
  2604. }
  2605. var arr = newMap[mapKey].split(','), allFlag = false;
  2606. for (var i = 0, len = arr.length; i < len; i++) {
  2607. var key = arr[i];
  2608. if (key === '*') {
  2609. allFlag = true;
  2610. break;
  2611. }
  2612. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2613. key = match[2];
  2614. if (match[1]) {
  2615. key = _toCamel(key);
  2616. if (knode[0].style[key]) {
  2617. knode[0].style[key] = '';
  2618. }
  2619. } else {
  2620. knode.removeAttr(key);
  2621. }
  2622. }
  2623. if (allFlag) {
  2624. knode.remove(true);
  2625. }
  2626. }
  2627. function _getInnerNode(knode) {
  2628. var inner = knode;
  2629. while (inner.first()) {
  2630. inner = inner.first();
  2631. }
  2632. return inner;
  2633. }
  2634. function _isEmptyNode(knode) {
  2635. if (knode.type != 1 || knode.isSingle()) {
  2636. return false;
  2637. }
  2638. return knode.html().replace(/<[^>]+>/g, '') === '';
  2639. }
  2640. function _mergeWrapper(a, b) {
  2641. a = a.clone(true);
  2642. var lastA = _getInnerNode(a), childA = a, merged = false;
  2643. while (b) {
  2644. while (childA) {
  2645. if (childA.name === b.name) {
  2646. _mergeAttrs(childA, b.attr(), b.css());
  2647. merged = true;
  2648. }
  2649. childA = childA.first();
  2650. }
  2651. if (!merged) {
  2652. lastA.append(b.clone(false));
  2653. }
  2654. merged = false;
  2655. b = b.first();
  2656. }
  2657. return a;
  2658. }
  2659. function _wrapNode(knode, wrapper) {
  2660. wrapper = wrapper.clone(true);
  2661. if (knode.type == 3) {
  2662. _getInnerNode(wrapper).append(knode.clone(false));
  2663. knode.replaceWith(wrapper);
  2664. return wrapper;
  2665. }
  2666. var nodeWrapper = knode, child;
  2667. while ((child = knode.first()) && child.children().length == 1) {
  2668. knode = child;
  2669. }
  2670. child = knode.first();
  2671. var frag = knode.doc.createDocumentFragment();
  2672. while (child) {
  2673. frag.appendChild(child[0]);
  2674. child = child.next();
  2675. }
  2676. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2677. if (frag.firstChild) {
  2678. _getInnerNode(wrapper).append(frag);
  2679. }
  2680. nodeWrapper.replaceWith(wrapper);
  2681. return wrapper;
  2682. }
  2683. function _mergeAttrs(knode, attrs, styles) {
  2684. _each(attrs, function(key, val) {
  2685. if (key !== 'style') {
  2686. knode.attr(key, val);
  2687. }
  2688. });
  2689. _each(styles, function(key, val) {
  2690. knode.css(key, val);
  2691. });
  2692. }
  2693. function _inPreElement(knode) {
  2694. while (knode && knode.name != 'body') {
  2695. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2696. return true;
  2697. }
  2698. knode = knode.parent();
  2699. }
  2700. return false;
  2701. }
  2702. function KCmd(range) {
  2703. this.init(range);
  2704. }
  2705. _extend(KCmd, {
  2706. init : function(range) {
  2707. var self = this, doc = range.doc;
  2708. self.doc = doc;
  2709. self.win = _getWin(doc);
  2710. self.sel = _getSel(doc);
  2711. self.range = range;
  2712. },
  2713. selection : function(forceReset) {
  2714. var self = this, doc = self.doc, rng = _getRng(doc);
  2715. self.sel = _getSel(doc);
  2716. if (rng) {
  2717. self.range = _range(rng);
  2718. if (K(self.range.startContainer).name == 'html') {
  2719. self.range.selectNodeContents(doc.body).collapse(false);
  2720. }
  2721. return self;
  2722. }
  2723. if (forceReset) {
  2724. self.range.selectNodeContents(doc.body).collapse(false);
  2725. }
  2726. return self;
  2727. },
  2728. select : function(hasDummy) {
  2729. hasDummy = _undef(hasDummy, true);
  2730. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2731. sc = range.startContainer, so = range.startOffset,
  2732. ec = range.endContainer, eo = range.endOffset,
  2733. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2734. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2735. if (_IERANGE) {
  2736. var dummy = K('<span>&nbsp;</span>', doc);
  2737. range.insertNode(dummy[0]);
  2738. rng = doc.body.createTextRange();
  2739. try {
  2740. rng.moveToElementText(dummy[0]);
  2741. } catch(ex) {}
  2742. rng.collapse(false);
  2743. rng.select();
  2744. dummy.remove();
  2745. win.focus();
  2746. return self;
  2747. }
  2748. if (_WEBKIT) {
  2749. var children = sc.childNodes;
  2750. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2751. range.insertNode(doc.createTextNode('\u200B'));
  2752. hasU200b = true;
  2753. }
  2754. }
  2755. }
  2756. if (_IERANGE) {
  2757. try {
  2758. rng = range.get(true);
  2759. rng.select();
  2760. } catch(e) {}
  2761. } else {
  2762. if (hasU200b) {
  2763. range.collapse(false);
  2764. }
  2765. rng = range.get(true);
  2766. sel.removeAllRanges();
  2767. sel.addRange(rng);
  2768. if (doc !== document) {
  2769. var pos = K(rng.endContainer).pos();
  2770. //win.scrollTo(pos.x, pos.y);
  2771. }
  2772. }
  2773. win.focus();
  2774. return self;
  2775. },
  2776. wrap : function(val) {
  2777. var self = this, doc = self.doc, range = self.range, wrapper;
  2778. wrapper = K(val, doc);
  2779. if (range.collapsed) {
  2780. range.shrink();
  2781. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2782. return self;
  2783. }
  2784. if (wrapper.isBlock()) {
  2785. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2786. while (child.first()) {
  2787. child = child.first();
  2788. }
  2789. child.append(range.extractContents());
  2790. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2791. return self;
  2792. }
  2793. range.enlarge();
  2794. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2795. K(ancestor).scan(function(node) {
  2796. if (!isStart && node == bookmark.start) {
  2797. isStart = true;
  2798. return;
  2799. }
  2800. if (isStart) {
  2801. if (node == bookmark.end) {
  2802. return false;
  2803. }
  2804. var knode = K(node);
  2805. if (_inPreElement(knode)) {
  2806. return;
  2807. }
  2808. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2809. var parent;
  2810. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2811. knode = parent;
  2812. }
  2813. _wrapNode(knode, wrapper);
  2814. }
  2815. }
  2816. });
  2817. range.moveToBookmark(bookmark);
  2818. return self;
  2819. },
  2820. split : function(isStart, map) {
  2821. var range = this.range, doc = range.doc;
  2822. var tempRange = range.cloneRange().collapse(isStart);
  2823. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2824. parent = node.nodeType == 3 ? node.parentNode : node,
  2825. needSplit = false, knode;
  2826. while (parent && parent.parentNode) {
  2827. knode = K(parent);
  2828. if (map) {
  2829. if (!knode.isStyle()) {
  2830. break;
  2831. }
  2832. if (!_hasAttrOrCss(knode, map)) {
  2833. break;
  2834. }
  2835. } else {
  2836. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2837. break;
  2838. }
  2839. }
  2840. needSplit = true;
  2841. parent = parent.parentNode;
  2842. }
  2843. if (needSplit) {
  2844. var dummy = doc.createElement('span');
  2845. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2846. if (isStart) {
  2847. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2848. } else {
  2849. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2850. }
  2851. var frag = tempRange.extractContents(),
  2852. first = frag.firstChild, last = frag.lastChild;
  2853. if (isStart) {
  2854. tempRange.insertNode(frag);
  2855. range.setStartAfter(last).setEndBefore(dummy);
  2856. } else {
  2857. parent.appendChild(frag);
  2858. range.setStartBefore(dummy).setEndBefore(first);
  2859. }
  2860. var dummyParent = dummy.parentNode;
  2861. if (dummyParent == range.endContainer) {
  2862. var prev = K(dummy).prev(), next = K(dummy).next();
  2863. if (prev && next && prev.type == 3 && next.type == 3) {
  2864. range.setEnd(prev[0], prev[0].nodeValue.length);
  2865. } else if (!isStart) {
  2866. range.setEnd(range.endContainer, range.endOffset - 1);
  2867. }
  2868. }
  2869. dummyParent.removeChild(dummy);
  2870. }
  2871. return this;
  2872. },
  2873. remove : function(map) {
  2874. var self = this, doc = self.doc, range = self.range;
  2875. range.enlarge();
  2876. if (range.startOffset === 0) {
  2877. var ksc = K(range.startContainer), parent;
  2878. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2879. ksc = parent;
  2880. }
  2881. range.setStart(ksc[0], 0);
  2882. ksc = K(range.startContainer);
  2883. if (ksc.isBlock()) {
  2884. _removeAttrOrCss(ksc, map);
  2885. }
  2886. var kscp = ksc.parent();
  2887. if (kscp && kscp.isBlock()) {
  2888. _removeAttrOrCss(kscp, map);
  2889. }
  2890. }
  2891. var sc, so;
  2892. if (range.collapsed) {
  2893. self.split(true, map);
  2894. sc = range.startContainer;
  2895. so = range.startOffset;
  2896. if (so > 0) {
  2897. var sb = K(sc.childNodes[so - 1]);
  2898. if (sb && _isEmptyNode(sb)) {
  2899. sb.remove();
  2900. range.setStart(sc, so - 1);
  2901. }
  2902. }
  2903. var sa = K(sc.childNodes[so]);
  2904. if (sa && _isEmptyNode(sa)) {
  2905. sa.remove();
  2906. }
  2907. if (_isEmptyNode(sc)) {
  2908. range.startBefore(sc);
  2909. sc.remove();
  2910. }
  2911. range.collapse(true);
  2912. return self;
  2913. }
  2914. self.split(true, map);
  2915. self.split(false, map);
  2916. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2917. range.cloneRange().collapse(false).insertNode(endDummy);
  2918. range.cloneRange().collapse(true).insertNode(startDummy);
  2919. var nodeList = [], cmpStart = false;
  2920. K(range.commonAncestor()).scan(function(node) {
  2921. if (!cmpStart && node == startDummy) {
  2922. cmpStart = true;
  2923. return;
  2924. }
  2925. if (node == endDummy) {
  2926. return false;
  2927. }
  2928. if (cmpStart) {
  2929. nodeList.push(node);
  2930. }
  2931. });
  2932. K(startDummy).remove();
  2933. K(endDummy).remove();
  2934. sc = range.startContainer;
  2935. so = range.startOffset;
  2936. var ec = range.endContainer, eo = range.endOffset;
  2937. if (so > 0) {
  2938. var startBefore = K(sc.childNodes[so - 1]);
  2939. if (startBefore && _isEmptyNode(startBefore)) {
  2940. startBefore.remove();
  2941. range.setStart(sc, so - 1);
  2942. if (sc == ec) {
  2943. range.setEnd(ec, eo - 1);
  2944. }
  2945. }
  2946. var startAfter = K(sc.childNodes[so]);
  2947. if (startAfter && _isEmptyNode(startAfter)) {
  2948. startAfter.remove();
  2949. if (sc == ec) {
  2950. range.setEnd(ec, eo - 1);
  2951. }
  2952. }
  2953. }
  2954. var endAfter = K(ec.childNodes[range.endOffset]);
  2955. if (endAfter && _isEmptyNode(endAfter)) {
  2956. endAfter.remove();
  2957. }
  2958. var bookmark = range.createBookmark(true);
  2959. _each(nodeList, function(i, node) {
  2960. _removeAttrOrCss(K(node), map);
  2961. });
  2962. range.moveToBookmark(bookmark);
  2963. return self;
  2964. },
  2965. commonNode : function(map) {
  2966. var range = this.range;
  2967. var ec = range.endContainer, eo = range.endOffset,
  2968. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2969. function find(node) {
  2970. var child = node, parent = node;
  2971. while (parent) {
  2972. if (_hasAttrOrCss(K(parent), map)) {
  2973. return K(parent);
  2974. }
  2975. parent = parent.parentNode;
  2976. }
  2977. while (child && (child = child.lastChild)) {
  2978. if (_hasAttrOrCss(K(child), map)) {
  2979. return K(child);
  2980. }
  2981. }
  2982. return null;
  2983. }
  2984. var cNode = find(node);
  2985. if (cNode) {
  2986. return cNode;
  2987. }
  2988. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2989. var prev = K(node).prev();
  2990. if (prev) {
  2991. return find(prev);
  2992. }
  2993. }
  2994. return null;
  2995. },
  2996. commonAncestor : function(tagName) {
  2997. var range = this.range,
  2998. sc = range.startContainer, so = range.startOffset,
  2999. ec = range.endContainer, eo = range.endOffset,
  3000. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3001. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3002. function find(node) {
  3003. while (node) {
  3004. if (node.nodeType == 1) {
  3005. if (node.tagName.toLowerCase() === tagName) {
  3006. return node;
  3007. }
  3008. }
  3009. node = node.parentNode;
  3010. }
  3011. return null;
  3012. }
  3013. var start = find(startNode), end = find(endNode);
  3014. if (start && end && start === end) {
  3015. return K(start);
  3016. }
  3017. return null;
  3018. },
  3019. state : function(key) {
  3020. var self = this, doc = self.doc, bool = false;
  3021. try {
  3022. bool = doc.queryCommandState(key);
  3023. } catch (e) {}
  3024. return bool;
  3025. },
  3026. val : function(key) {
  3027. var self = this, doc = self.doc, range = self.range;
  3028. function lc(val) {
  3029. return val.toLowerCase();
  3030. }
  3031. key = lc(key);
  3032. var val = '', knode;
  3033. if (key === 'fontfamily' || key === 'fontname') {
  3034. val = _nativeCommandValue(doc, 'fontname');
  3035. val = val.replace(/['"]/g, '');
  3036. return lc(val);
  3037. }
  3038. if (key === 'formatblock') {
  3039. val = _nativeCommandValue(doc, key);
  3040. if (val === '') {
  3041. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3042. if (knode) {
  3043. val = knode.name;
  3044. }
  3045. }
  3046. if (val === 'Normal') {
  3047. val = 'p';
  3048. }
  3049. return lc(val);
  3050. }
  3051. if (key === 'fontsize') {
  3052. knode = self.commonNode({'*' : '.font-size'});
  3053. if (knode) {
  3054. val = knode.css('font-size');
  3055. }
  3056. return lc(val);
  3057. }
  3058. if (key === 'fontheight') {
  3059. knode = self.commonNode({'*' : '.letter-spacing'});
  3060. if (knode) {
  3061. val = knode.css('letter-spacing');
  3062. }
  3063. return lc(val);
  3064. }
  3065. if (key === 'forecolor') {
  3066. knode = self.commonNode({'*' : '.color'});
  3067. if (knode) {
  3068. val = knode.css('color');
  3069. }
  3070. val = _toHex(val);
  3071. if (val === '') {
  3072. val = 'default';
  3073. }
  3074. return lc(val);
  3075. }
  3076. if (key === 'hilitecolor') {
  3077. knode = self.commonNode({'*' : '.background-color'});
  3078. if (knode) {
  3079. val = knode.css('background-color');
  3080. }
  3081. val = _toHex(val);
  3082. if (val === '') {
  3083. val = 'default';
  3084. }
  3085. return lc(val);
  3086. }
  3087. return val;
  3088. },
  3089. toggle : function(wrapper, map) {
  3090. var self = this;
  3091. if (self.commonNode(map)) {
  3092. self.remove(map);
  3093. } else {
  3094. self.wrap(wrapper);
  3095. }
  3096. return self.select();
  3097. },
  3098. bold : function() {
  3099. return this.toggle('<strong></strong>', {
  3100. span : '.font-weight=bold',
  3101. strong : '*',
  3102. b : '*'
  3103. });
  3104. },
  3105. italic : function() {
  3106. return this.toggle('<em></em>', {
  3107. span : '.font-style=italic',
  3108. em : '*',
  3109. i : '*'
  3110. });
  3111. },
  3112. underline : function() {
  3113. return this.toggle('<u></u>', {
  3114. span : '.text-decoration=underline',
  3115. u : '*'
  3116. });
  3117. },
  3118. strikethrough : function() {
  3119. return this.toggle('<s></s>', {
  3120. span : '.text-decoration=line-through',
  3121. s : '*'
  3122. });
  3123. },
  3124. forecolor : function(val) {
  3125. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3126. },
  3127. hilitecolor : function(val) {
  3128. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3129. },
  3130. fontsize : function(val) {
  3131. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3132. },
  3133. fontheight : function(val) {
  3134. return this.wrap('<span style="letter-spacing:' + val + ';"></span>').select();
  3135. },
  3136. fontname : function(val) {
  3137. return this.fontfamily(val);
  3138. },
  3139. fontfamily : function(val) {
  3140. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3141. },
  3142. removeformat : function() {
  3143. var map = {
  3144. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3145. },
  3146. tags = _STYLE_TAG_MAP;
  3147. _each(tags, function(key, val) {
  3148. map[key] = '*';
  3149. });
  3150. this.remove(map);
  3151. return this.select();
  3152. },
  3153. inserthtml : function(val, quickMode) {
  3154. var self = this, range = self.range;
  3155. if (val === '') {
  3156. return self;
  3157. }
  3158. function pasteHtml(range, val) {
  3159. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3160. var rng = range.get();
  3161. if (rng.item) {
  3162. rng.item(0).outerHTML = val;
  3163. } else {
  3164. rng.pasteHTML(val);
  3165. }
  3166. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3167. temp.parentNode.removeChild(temp);
  3168. var newRange = _toRange(rng);
  3169. range.setEnd(newRange.endContainer, newRange.endOffset);
  3170. range.collapse(false);
  3171. self.select(false);
  3172. }
  3173. function insertHtml(range, val) {
  3174. var doc = range.doc,
  3175. frag = doc.createDocumentFragment();
  3176. K('@' + val, doc).each(function() {
  3177. frag.appendChild(this);
  3178. });
  3179. range.deleteContents();
  3180. range.insertNode(frag);
  3181. range.collapse(false);
  3182. self.select(false);
  3183. }
  3184. if (_IERANGE && quickMode) {
  3185. try {
  3186. pasteHtml(range, val);
  3187. } catch(e) {
  3188. insertHtml(range, val);
  3189. }
  3190. return self;
  3191. }
  3192. insertHtml(range, val);
  3193. return self;
  3194. },
  3195. hr : function() {
  3196. return this.inserthtml('<hr />');
  3197. },
  3198. print : function() {
  3199. this.win.print();
  3200. return this;
  3201. },
  3202. insertimage : function(url, title, width, height, border, align) {
  3203. title = _undef(title, '');
  3204. border = _undef(border, 0);
  3205. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3206. if (width) {
  3207. html += 'width="' + _escape(width) + '" ';
  3208. }
  3209. if (height) {
  3210. html += 'height="' + _escape(height) + '" ';
  3211. }
  3212. if (title) {
  3213. html += 'title="' + _escape(title) + '" ';
  3214. }
  3215. if (align) {
  3216. html += 'align="' + _escape(align) + '" ';
  3217. }
  3218. html += 'alt="' + _escape(title) + '" ';
  3219. html += '/>';
  3220. return this.inserthtml(html);
  3221. },
  3222. createlink : function(url, type) {
  3223. var self = this, doc = self.doc, range = self.range;
  3224. self.select();
  3225. var a = self.commonNode({ a : '*' });
  3226. if (a && !range.isControl()) {
  3227. range.selectNode(a.get());
  3228. self.select();
  3229. }
  3230. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3231. if (type) {
  3232. html += ' target="' + _escape(type) + '"';
  3233. }
  3234. if (range.collapsed) {
  3235. html += '>' + _escape(url) + '</a>';
  3236. return self.inserthtml(html);
  3237. }
  3238. if (range.isControl()) {
  3239. var node = K(range.startContainer.childNodes[range.startOffset]);
  3240. html += '></a>';
  3241. node.after(K(html, doc));
  3242. node.next().append(node);
  3243. range.selectNode(node[0]);
  3244. return self.select();
  3245. }
  3246. function setAttr(node, url, type) {
  3247. K(node).attr('href', url).attr('data-ke-src', url);
  3248. if (type) {
  3249. K(node).attr('target', type);
  3250. } else {
  3251. K(node).removeAttr('target');
  3252. }
  3253. }
  3254. var sc = range.startContainer, so = range.startOffset,
  3255. ec = range.endContainer, eo = range.endOffset;
  3256. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3257. var child = sc.childNodes[so];
  3258. if (child.nodeName.toLowerCase() == 'a') {
  3259. setAttr(child, url, type);
  3260. return self;
  3261. }
  3262. }
  3263. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3264. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3265. setAttr(this, url, type);
  3266. });
  3267. return self;
  3268. },
  3269. unlink : function() {
  3270. var self = this, doc = self.doc, range = self.range;
  3271. self.select();
  3272. if (range.collapsed) {
  3273. var a = self.commonNode({ a : '*' });
  3274. if (a) {
  3275. range.selectNode(a.get());
  3276. self.select();
  3277. }
  3278. _nativeCommand(doc, 'unlink', null);
  3279. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3280. var parent = K(range.startContainer).parent();
  3281. if (parent.name === 'a') {
  3282. parent.remove(true);
  3283. }
  3284. }
  3285. } else {
  3286. _nativeCommand(doc, 'unlink', null);
  3287. }
  3288. return self;
  3289. }
  3290. });
  3291. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3292. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3293. KCmd.prototype[name] = function(val) {
  3294. var self = this;
  3295. self.select();
  3296. _nativeCommand(self.doc, name, val);
  3297. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3298. self.selection();
  3299. }
  3300. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3301. self.selection();
  3302. }
  3303. return self;
  3304. };
  3305. });
  3306. _each('cut,copy,paste'.split(','), function(i, name) {
  3307. KCmd.prototype[name] = function() {
  3308. var self = this;
  3309. if (!self.doc.queryCommandSupported(name)) {
  3310. throw 'not supported';
  3311. }
  3312. self.select();
  3313. _nativeCommand(self.doc, name, null);
  3314. return self;
  3315. };
  3316. });
  3317. function _cmd(mixed) {
  3318. if (mixed.nodeName) {
  3319. var doc = _getDoc(mixed);
  3320. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3321. }
  3322. return new KCmd(mixed);
  3323. }
  3324. K.CmdClass = KCmd;
  3325. K.cmd = _cmd;
  3326. function _drag(options) {
  3327. var moveEl = options.moveEl,
  3328. moveFn = options.moveFn,
  3329. clickEl = options.clickEl || moveEl,
  3330. beforeDrag = options.beforeDrag,
  3331. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3332. var docs = [document];
  3333. if (iframeFix) {
  3334. K('iframe').each(function() {
  3335. var src = _formatUrl(this.src || '', 'absolute');
  3336. if (/^https?:\/\//.test(src)) {
  3337. return;
  3338. }
  3339. var doc;
  3340. try {
  3341. doc = _iframeDoc(this);
  3342. } catch(e) {}
  3343. if (doc) {
  3344. var pos = K(this).pos();
  3345. K(doc).data('pos-x', pos.x);
  3346. K(doc).data('pos-y', pos.y);
  3347. docs.push(doc);
  3348. }
  3349. });
  3350. }
  3351. clickEl.mousedown(function(e) {
  3352. if(e.button !== 0 && e.button !== 1) {
  3353. return;
  3354. }
  3355. e.stopPropagation();
  3356. var self = clickEl.get(),
  3357. x = _removeUnit(moveEl.css('left')),
  3358. y = _removeUnit(moveEl.css('top')),
  3359. width = moveEl.width(),
  3360. height = moveEl.height(),
  3361. pageX = e.pageX,
  3362. pageY = e.pageY;
  3363. if (beforeDrag) {
  3364. beforeDrag();
  3365. }
  3366. function moveListener(e) {
  3367. e.preventDefault();
  3368. var kdoc = K(_getDoc(e.target));
  3369. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3370. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3371. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3372. }
  3373. function selectListener(e) {
  3374. e.preventDefault();
  3375. }
  3376. function upListener(e) {
  3377. e.preventDefault();
  3378. K(docs).unbind('mousemove', moveListener)
  3379. .unbind('mouseup', upListener)
  3380. .unbind('selectstart', selectListener);
  3381. if (self.releaseCapture) {
  3382. self.releaseCapture();
  3383. }
  3384. }
  3385. K(docs).mousemove(moveListener)
  3386. .mouseup(upListener)
  3387. .bind('selectstart', selectListener);
  3388. if (self.setCapture) {
  3389. self.setCapture();
  3390. }
  3391. });
  3392. }
  3393. function KWidget(options) {
  3394. this.init(options);
  3395. }
  3396. _extend(KWidget, {
  3397. init : function(options) {
  3398. var self = this;
  3399. self.name = options.name || '';
  3400. self.doc = options.doc || document;
  3401. self.win = _getWin(self.doc);
  3402. self.x = _addUnit(options.x);
  3403. self.y = _addUnit(options.y);
  3404. self.z = options.z;
  3405. self.width = _addUnit(options.width);
  3406. self.height = _addUnit(options.height);
  3407. self.index = _addUnit(options.index);
  3408. self.div = K('<div style="display:block;"></div>');
  3409. self.options = options;
  3410. self._alignEl = options.alignEl;
  3411. if (self.width) {
  3412. self.div.css('width', self.width);
  3413. }
  3414. if (self.height) {
  3415. self.div.css('height', self.height);
  3416. }
  3417. if (self.z) {
  3418. self.div.css({
  3419. position : 'absolute',
  3420. left : self.x,
  3421. top : self.y,
  3422. 'z-index' : self.z
  3423. });
  3424. }
  3425. if (self.z && (self.x === undefined || self.y === undefined)) {
  3426. self.autoPos(self.width, self.height);
  3427. }
  3428. if (options.cls) {
  3429. self.div.addClass(options.cls);
  3430. }
  3431. if (options.shadowMode) {
  3432. self.div.addClass('ke-shadow');
  3433. }
  3434. if (options.css) {
  3435. self.div.css(options.css);
  3436. }
  3437. if (options.src) {
  3438. K(options.src).replaceWith(self.div);
  3439. } else {
  3440. K(self.doc.body).append(self.div);
  3441. }
  3442. if (options.html) {
  3443. self.div.html(options.html);
  3444. }
  3445. if (options.autoScroll) {
  3446. if (_IE && _V < 7 || _QUIRKS) {
  3447. var scrollPos = _getScrollPos();
  3448. K(self.win).bind('scroll', function(e) {
  3449. var pos = _getScrollPos(),
  3450. diffX = pos.x - scrollPos.x,
  3451. diffY = pos.y - scrollPos.y;
  3452. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3453. });
  3454. } else {
  3455. self.div.css('position', 'fixed');
  3456. }
  3457. }
  3458. },
  3459. pos : function(x, y, updateProp) {
  3460. var self = this;
  3461. updateProp = _undef(updateProp, true);
  3462. if (x !== null) {
  3463. x = x < 0 ? 0 : _addUnit(x);
  3464. self.div.css('left', x);
  3465. if (updateProp) {
  3466. self.x = x;
  3467. }
  3468. }
  3469. if (y !== null) {
  3470. y = y < 0 ? 0 : _addUnit(y);
  3471. self.div.css('top', y);
  3472. if (updateProp) {
  3473. self.y = y;
  3474. }
  3475. }
  3476. return self;
  3477. },
  3478. autoPos : function(width, height) {
  3479. var x, y, self = this,
  3480. w = _removeUnit(width) || 0,
  3481. h = _removeUnit(height) || 0,
  3482. scrollPos = _getScrollPos();
  3483. if (self._alignEl) {
  3484. var knode = K(self._alignEl),
  3485. pos = knode.pos(),
  3486. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3487. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3488. x = diffX < 0 ? pos.x : pos.x + diffX;
  3489. y = diffY < 0 ? pos.y : pos.y + diffY;
  3490. } else {
  3491. var docEl = _docElement(self.doc);
  3492. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3493. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3494. }
  3495. if (!(_IE && _V < 7 || _QUIRKS)) {
  3496. x -= scrollPos.x;
  3497. y -= scrollPos.y;
  3498. }
  3499. return self.pos(x, y);
  3500. },
  3501. remove : function() {
  3502. var self = this;
  3503. if (_IE && _V < 7 || _QUIRKS) {
  3504. K(self.win).unbind('scroll');
  3505. }
  3506. self.div.remove();
  3507. _each(self, function(i) {
  3508. self[i] = null;
  3509. });
  3510. return this;
  3511. },
  3512. show : function() {
  3513. this.div.show();
  3514. return this;
  3515. },
  3516. hide : function() {
  3517. this.div.hide();
  3518. return this;
  3519. },
  3520. draggable : function(options) {
  3521. var self = this;
  3522. options = options || {};
  3523. options.moveEl = self.div;
  3524. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3525. if ((x = x + diffX) < 0) {
  3526. x = 0;
  3527. }
  3528. if ((y = y + diffY) < 0) {
  3529. y = 0;
  3530. }
  3531. self.pos(x, y);
  3532. };
  3533. _drag(options);
  3534. return self;
  3535. }
  3536. });
  3537. function _widget(options) {
  3538. return new KWidget(options);
  3539. }
  3540. K.WidgetClass = KWidget;
  3541. K.widget = _widget;
  3542. function _iframeDoc(iframe) {
  3543. iframe = _get(iframe);
  3544. return iframe.contentDocument || iframe.contentWindow.document;
  3545. }
  3546. var html, _direction = '';
  3547. if ((html = document.getElementsByTagName('html'))) {
  3548. _direction = html[0].dir;
  3549. }
  3550. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3551. var arr = [
  3552. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3553. '<head><meta charset="utf-8" /><title></title>',
  3554. '<style>',
  3555. 'html {margin:0;padding:0;}',
  3556. 'body {margin:0;padding:5px;}',
  3557. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3558. 'body, p, div {word-wrap: break-word;}',
  3559. 'p {margin:5px 0;}',
  3560. 'table {border-collapse:collapse;}',
  3561. 'img {border:0;}',
  3562. 'noscript {display:none;}',
  3563. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3564. 'img.ke-flash {',
  3565. ' border:1px solid #AAA;',
  3566. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3567. ' background-position:center center;',
  3568. ' background-repeat:no-repeat;',
  3569. ' width:100px;',
  3570. ' height:100px;',
  3571. '}',
  3572. 'img.ke-rm {',
  3573. ' border:1px solid #AAA;',
  3574. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3575. ' background-position:center center;',
  3576. ' background-repeat:no-repeat;',
  3577. ' width:100px;',
  3578. ' height:100px;',
  3579. '}',
  3580. 'img.ke-media {',
  3581. ' border:1px solid #AAA;',
  3582. ' background-image:url(' + themesPath + 'common/media.gif);',
  3583. ' background-position:center center;',
  3584. ' background-repeat:no-repeat;',
  3585. ' width:100px;',
  3586. ' height:100px;',
  3587. '}',
  3588. 'img.ke-anchor {',
  3589. ' border:1px dashed #666;',
  3590. ' width:16px;',
  3591. ' height:16px;',
  3592. '}',
  3593. '.ke-script, .ke-noscript, .ke-display-none {',
  3594. ' display:none;',
  3595. ' font-size:0;',
  3596. ' width:0;',
  3597. ' height:0;',
  3598. '}',
  3599. '.ke-pagebreak {',
  3600. ' border:1px dotted #AAA;',
  3601. ' font-size:0;',
  3602. ' height:2px;',
  3603. '}',
  3604. '</style>'
  3605. ];
  3606. if (!_isArray(cssPath)) {
  3607. cssPath = [cssPath];
  3608. }
  3609. _each(cssPath, function(i, path) {
  3610. if (path) {
  3611. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3612. }
  3613. });
  3614. if (cssData) {
  3615. arr.push('<style>' + cssData + '</style>');
  3616. }
  3617. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3618. return arr.join('\n');
  3619. }
  3620. function _elementVal(knode, val) {
  3621. if (knode.hasVal()) {
  3622. if (val === undefined) {
  3623. var html = knode.val();
  3624. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3625. return html;
  3626. }
  3627. return knode.val(val);
  3628. }
  3629. return knode.html(val);
  3630. }
  3631. function KEdit(options) {
  3632. this.init(options);
  3633. }
  3634. _extend(KEdit, KWidget, {
  3635. init : function(options) {
  3636. var self = this;
  3637. KEdit.parent.init.call(self, options);
  3638. self.srcElement = K(options.srcElement);
  3639. self.div.addClass('ke-edit');
  3640. self.designMode = _undef(options.designMode, true);
  3641. self.beforeGetHtml = options.beforeGetHtml;
  3642. self.beforeSetHtml = options.beforeSetHtml;
  3643. self.afterSetHtml = options.afterSetHtml;
  3644. var themesPath = _undef(options.themesPath, ''),
  3645. bodyClass = options.bodyClass,
  3646. cssPath = options.cssPath,
  3647. cssData = options.cssData,
  3648. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3649. srcScript = ('document.open();' +
  3650. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3651. 'document.close();'),
  3652. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3653. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3654. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3655. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3656. self.iframe.attr('tabindex', self.tabIndex);
  3657. self.textarea.attr('tabindex', self.tabIndex);
  3658. if (self.width) {
  3659. self.setWidth(self.width);
  3660. }
  3661. if (self.height) {
  3662. self.setHeight(self.height);
  3663. }
  3664. if (self.designMode) {
  3665. self.textarea.hide();
  3666. } else {
  3667. self.iframe.hide();
  3668. }
  3669. function ready() {
  3670. var doc = _iframeDoc(self.iframe);
  3671. doc.open();
  3672. if (isDocumentDomain) {
  3673. doc.domain = document.domain;
  3674. }
  3675. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3676. doc.close();
  3677. self.win = self.iframe[0].contentWindow;
  3678. self.doc = doc;
  3679. var cmd = _cmd(doc);
  3680. self.afterChange(function(e) {
  3681. cmd.selection();
  3682. });
  3683. if (_WEBKIT) {
  3684. K(doc).click(function(e) {
  3685. if (K(e.target).name === 'img') {
  3686. cmd.selection(true);
  3687. cmd.range.selectNode(e.target);
  3688. cmd.select();
  3689. }
  3690. });
  3691. }
  3692. if (_IE) {
  3693. self._mousedownHandler = function() {
  3694. var newRange = cmd.range.cloneRange();
  3695. newRange.shrink();
  3696. if (newRange.isControl()) {
  3697. self.blur();
  3698. }
  3699. };
  3700. K(document).mousedown(self._mousedownHandler);
  3701. K(doc).keydown(function(e) {
  3702. if (e.which == 8) {
  3703. cmd.selection();
  3704. var rng = cmd.range;
  3705. if (rng.isControl()) {
  3706. rng.collapse(true);
  3707. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3708. e.preventDefault();
  3709. }
  3710. }
  3711. });
  3712. }
  3713. self.cmd = cmd;
  3714. self.html(_elementVal(self.srcElement));
  3715. if (_IE) {
  3716. doc.body.disabled = true;
  3717. doc.body.contentEditable = true;
  3718. doc.body.removeAttribute('disabled');
  3719. } else {
  3720. doc.designMode = 'on';
  3721. }
  3722. if (options.afterCreate) {
  3723. options.afterCreate.call(self);
  3724. }
  3725. }
  3726. if (isDocumentDomain) {
  3727. self.iframe.bind('load', function(e) {
  3728. self.iframe.unbind('load');
  3729. if (_IE) {
  3730. ready();
  3731. } else {
  3732. setTimeout(ready, 0);
  3733. }
  3734. });
  3735. }
  3736. self.div.append(self.iframe);
  3737. self.div.append(self.textarea);
  3738. self.srcElement.hide();
  3739. !isDocumentDomain && ready();
  3740. },
  3741. setWidth : function(val) {
  3742. var self = this;
  3743. val = _addUnit(val);
  3744. self.width = val;
  3745. self.div.css('width', val);
  3746. return self;
  3747. },
  3748. setHeight : function(val) {
  3749. var self = this;
  3750. val = _addUnit(val);
  3751. self.height = val;
  3752. self.div.css('height', val);
  3753. self.iframe.css('height', val);
  3754. if ((_IE && _V < 8) || _QUIRKS) {
  3755. val = _addUnit(_removeUnit(val) - 2);
  3756. }
  3757. self.textarea.css('height', val);
  3758. return self;
  3759. },
  3760. remove : function() {
  3761. var self = this, doc = self.doc;
  3762. K(doc.body).unbind();
  3763. K(doc).unbind();
  3764. K(self.win).unbind();
  3765. if (self._mousedownHandler) {
  3766. K(document).unbind('mousedown', self._mousedownHandler);
  3767. }
  3768. _elementVal(self.srcElement, self.html());
  3769. self.srcElement.show();
  3770. self.iframe.unbind();
  3771. self.textarea.unbind();
  3772. KEdit.parent.remove.call(self);
  3773. },
  3774. html : function(val, isFull) {
  3775. var self = this, doc = self.doc;
  3776. if (self.designMode) {
  3777. var body = doc.body;
  3778. if (val === undefined) {
  3779. if (isFull) {
  3780. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3781. } else {
  3782. val = body.innerHTML;
  3783. }
  3784. if (self.beforeGetHtml) {
  3785. val = self.beforeGetHtml(val);
  3786. }
  3787. if (_GECKO && val == '<br />') {
  3788. val = '';
  3789. }
  3790. return val;
  3791. }
  3792. if (self.beforeSetHtml) {
  3793. val = self.beforeSetHtml(val);
  3794. }
  3795. if (_IE && _V >= 9) {
  3796. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3797. }
  3798. K(body).html(val);
  3799. if (self.afterSetHtml) {
  3800. self.afterSetHtml();
  3801. }
  3802. return self;
  3803. }
  3804. if (val === undefined) {
  3805. return self.textarea.val();
  3806. }
  3807. self.textarea.val(val);
  3808. return self;
  3809. },
  3810. design : function(bool) {
  3811. var self = this, val;
  3812. if (bool === undefined ? !self.designMode : bool) {
  3813. if (!self.designMode) {
  3814. val = self.html();
  3815. self.designMode = true;
  3816. self.textarea.hide();
  3817. self.html(val);
  3818. var iframe = self.iframe;
  3819. var height = _removeUnit(self.height);
  3820. iframe.height(height - 2);
  3821. iframe.show();
  3822. setTimeout(function() {
  3823. iframe.height(height);
  3824. }, 0);
  3825. }
  3826. } else {
  3827. if (self.designMode) {
  3828. val = self.html();
  3829. self.designMode = false;
  3830. self.html(val);
  3831. self.iframe.hide();
  3832. self.textarea.show();
  3833. }
  3834. }
  3835. return self.focus();
  3836. },
  3837. focus : function() {
  3838. var self = this;
  3839. //self.designMode ? self.win.focus() : self.textarea[0].focus();
  3840. return self;
  3841. },
  3842. blur : function() {
  3843. var self = this;
  3844. if (_IE) {
  3845. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3846. self.div.append(input);
  3847. input[0].focus();
  3848. input.remove();
  3849. } else {
  3850. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3851. }
  3852. return self;
  3853. },
  3854. afterChange : function(fn) {
  3855. var self = this, doc = self.doc, body = doc.body;
  3856. K(doc).keyup(function(e) {
  3857. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3858. fn(e);
  3859. }
  3860. });
  3861. K(doc).mouseup(fn).contextmenu(fn);
  3862. K(self.win).blur(fn);
  3863. function timeoutHandler(e) {
  3864. setTimeout(function() {
  3865. fn(e);
  3866. }, 1);
  3867. }
  3868. K(body).bind('paste', timeoutHandler);
  3869. K(body).bind('cut', timeoutHandler);
  3870. return self;
  3871. }
  3872. });
  3873. function _edit(options) {
  3874. return new KEdit(options);
  3875. }
  3876. K.EditClass = KEdit;
  3877. K.edit = _edit;
  3878. K.iframeDoc = _iframeDoc;
  3879. function _selectToolbar(name, fn) {
  3880. var self = this,
  3881. knode = self.get(name);
  3882. if (knode) {
  3883. if (knode.hasClass('ke-disabled')) {
  3884. return;
  3885. }
  3886. fn(knode);
  3887. }
  3888. }
  3889. function KToolbar(options) {
  3890. this.init(options);
  3891. }
  3892. _extend(KToolbar, KWidget, {
  3893. init : function(options) {
  3894. var self = this;
  3895. KToolbar.parent.init.call(self, options);
  3896. self.disableMode = _undef(options.disableMode, false);
  3897. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3898. self._itemMap = {};
  3899. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3900. e.preventDefault();
  3901. }).attr('unselectable', 'on');
  3902. function find(target) {
  3903. var knode = K(target);
  3904. if (knode.hasClass('ke-outline')) {
  3905. return knode;
  3906. }
  3907. if (knode.hasClass('ke-toolbar-icon')) {
  3908. return knode.parent();
  3909. }
  3910. }
  3911. function hover(e, method) {
  3912. var knode = find(e.target);
  3913. if (knode) {
  3914. if (knode.hasClass('ke-disabled')) {
  3915. return;
  3916. }
  3917. if (knode.hasClass('ke-selected')) {
  3918. return;
  3919. }
  3920. knode[method]('ke-on');
  3921. }
  3922. }
  3923. self.div.mouseover(function(e) {
  3924. hover(e, 'addClass');
  3925. })
  3926. .mouseout(function(e) {
  3927. hover(e, 'removeClass');
  3928. })
  3929. .click(function(e) {
  3930. var knode = find(e.target);
  3931. if (knode) {
  3932. if (knode.hasClass('ke-disabled')) {
  3933. return;
  3934. }
  3935. self.options.click.call(this, e, knode.attr('data-name'));
  3936. }
  3937. });
  3938. },
  3939. get : function(name) {
  3940. if (this._itemMap[name]) {
  3941. return this._itemMap[name];
  3942. }
  3943. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3944. },
  3945. select : function(name) {
  3946. _selectToolbar.call(this, name, function(knode) {
  3947. knode.addClass('ke-selected');
  3948. });
  3949. return self;
  3950. },
  3951. unselect : function(name) {
  3952. _selectToolbar.call(this, name, function(knode) {
  3953. knode.removeClass('ke-selected').removeClass('ke-on');
  3954. });
  3955. return self;
  3956. },
  3957. enable : function(name) {
  3958. var self = this,
  3959. knode = name.get ? name : self.get(name);
  3960. if (knode) {
  3961. knode.removeClass('ke-disabled');
  3962. knode.opacity(1);
  3963. }
  3964. return self;
  3965. },
  3966. disable : function(name) {
  3967. var self = this,
  3968. knode = name.get ? name : self.get(name);
  3969. if (knode) {
  3970. knode.removeClass('ke-selected').addClass('ke-disabled');
  3971. knode.opacity(0.5);
  3972. }
  3973. return self;
  3974. },
  3975. disableAll : function(bool, noDisableItems) {
  3976. var self = this, map = self.noDisableItemMap, item;
  3977. if (noDisableItems) {
  3978. map = _toMap(noDisableItems);
  3979. }
  3980. if (bool === undefined ? !self.disableMode : bool) {
  3981. K('span.ke-outline', self.div).each(function() {
  3982. var knode = K(this),
  3983. name = knode[0].getAttribute('data-name', 2);
  3984. if (!map[name]) {
  3985. self.disable(knode);
  3986. }
  3987. });
  3988. self.disableMode = true;
  3989. } else {
  3990. K('span.ke-outline', self.div).each(function() {
  3991. var knode = K(this),
  3992. name = knode[0].getAttribute('data-name', 2);
  3993. if (!map[name]) {
  3994. self.enable(knode);
  3995. }
  3996. });
  3997. self.disableMode = false;
  3998. }
  3999. return self;
  4000. }
  4001. });
  4002. function _toolbar(options) {
  4003. return new KToolbar(options);
  4004. }
  4005. K.ToolbarClass = KToolbar;
  4006. K.toolbar = _toolbar;
  4007. function KMenu(options) {
  4008. this.init(options);
  4009. }
  4010. _extend(KMenu, KWidget, {
  4011. init : function(options) {
  4012. var self = this;
  4013. options.z = options.z || 811213;
  4014. KMenu.parent.init.call(self, options);
  4015. self.centerLineMode = _undef(options.centerLineMode, true);
  4016. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4017. e.stopPropagation();
  4018. }).attr('unselectable', 'on');
  4019. },
  4020. addItem : function(item) {
  4021. var self = this;
  4022. if (item.title === '-') {
  4023. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4024. return;
  4025. }
  4026. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4027. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4028. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4029. height = _addUnit(item.height),
  4030. iconClass = _undef(item.iconClass, '');
  4031. self.div.append(itemDiv);
  4032. if (height) {
  4033. itemDiv.css('height', height);
  4034. rightDiv.css('line-height', height);
  4035. }
  4036. var centerDiv;
  4037. if (self.centerLineMode) {
  4038. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4039. if (height) {
  4040. centerDiv.css('height', height);
  4041. }
  4042. }
  4043. itemDiv.mouseover(function(e) {
  4044. K(this).addClass('ke-menu-item-on');
  4045. if (centerDiv) {
  4046. centerDiv.addClass('ke-menu-item-center-on');
  4047. }
  4048. })
  4049. .mouseout(function(e) {
  4050. K(this).removeClass('ke-menu-item-on');
  4051. if (centerDiv) {
  4052. centerDiv.removeClass('ke-menu-item-center-on');
  4053. }
  4054. })
  4055. .click(function(e) {
  4056. item.click.call(K(this));
  4057. e.stopPropagation();
  4058. })
  4059. .append(leftDiv);
  4060. if (centerDiv) {
  4061. itemDiv.append(centerDiv);
  4062. }
  4063. itemDiv.append(rightDiv);
  4064. if (item.checked) {
  4065. iconClass = 'ke-icon-checked';
  4066. }
  4067. if (iconClass !== '') {
  4068. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4069. }
  4070. rightDiv.html(item.title);
  4071. return self;
  4072. },
  4073. remove : function() {
  4074. var self = this;
  4075. if (self.options.beforeRemove) {
  4076. self.options.beforeRemove.call(self);
  4077. }
  4078. K('.ke-menu-item', self.div[0]).unbind();
  4079. KMenu.parent.remove.call(self);
  4080. return self;
  4081. }
  4082. });
  4083. function _menu(options) {
  4084. return new KMenu(options);
  4085. }
  4086. K.MenuClass = KMenu;
  4087. K.menu = _menu;
  4088. function KColorPicker(options) {
  4089. this.init(options);
  4090. }
  4091. _extend(KColorPicker, KWidget, {
  4092. init : function(options) {
  4093. var self = this;
  4094. options.z = options.z || 811213;
  4095. KColorPicker.parent.init.call(self, options);
  4096. var colors = options.colors || [
  4097. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4098. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4099. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4100. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4101. ];
  4102. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4103. self._cells = [];
  4104. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4105. e.stopPropagation();
  4106. }).attr('unselectable', 'on');
  4107. var table = self.doc.createElement('table');
  4108. self.div.append(table);
  4109. table.className = 'ke-colorpicker-table';
  4110. table.cellPadding = 0;
  4111. table.cellSpacing = 0;
  4112. table.border = 0;
  4113. var row = table.insertRow(0), cell = row.insertCell(0);
  4114. cell.colSpan = colors[0].length;
  4115. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4116. for (var i = 0; i < colors.length; i++) {
  4117. row = table.insertRow(i + 1);
  4118. for (var j = 0; j < colors[i].length; j++) {
  4119. cell = row.insertCell(j);
  4120. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4121. }
  4122. }
  4123. },
  4124. _addAttr : function(cell, color, cls) {
  4125. var self = this;
  4126. cell = K(cell).addClass(cls);
  4127. if (self.selectedColor === color.toLowerCase()) {
  4128. cell.addClass('ke-colorpicker-cell-selected');
  4129. }
  4130. cell.attr('title', color || self.options.noColor);
  4131. cell.mouseover(function(e) {
  4132. K(this).addClass('ke-colorpicker-cell-on');
  4133. });
  4134. cell.mouseout(function(e) {
  4135. K(this).removeClass('ke-colorpicker-cell-on');
  4136. });
  4137. cell.click(function(e) {
  4138. e.stop();
  4139. self.options.click.call(K(this), color);
  4140. });
  4141. if (color) {
  4142. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4143. } else {
  4144. cell.html(self.options.noColor);
  4145. }
  4146. K(cell).attr('unselectable', 'on');
  4147. self._cells.push(cell);
  4148. },
  4149. remove : function() {
  4150. var self = this;
  4151. _each(self._cells, function() {
  4152. this.unbind();
  4153. });
  4154. KColorPicker.parent.remove.call(self);
  4155. return self;
  4156. }
  4157. });
  4158. function _colorpicker(options) {
  4159. return new KColorPicker(options);
  4160. }
  4161. K.ColorPickerClass = KColorPicker;
  4162. K.colorpicker = _colorpicker;
  4163. function KUploadButton(options) {
  4164. this.init(options);
  4165. }
  4166. _extend(KUploadButton, {
  4167. init : function(options) {
  4168. var self = this,
  4169. button = K(options.button),
  4170. fieldName = options.fieldName || 'file',
  4171. url = options.url || '',
  4172. title = button.val(),
  4173. extraParams = options.extraParams || {},
  4174. cls = button[0].className || '',
  4175. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4176. options.afterError = options.afterError || function(str) {
  4177. alert(str);
  4178. };
  4179. var hiddenElements = [];
  4180. for(var k in extraParams){
  4181. hiddenElements.push('<input type="hidden" class="ke-upload-file-'+k+'" name="' + k + '" value="' + extraParams[k] + '" />');
  4182. }
  4183. var html = [
  4184. '<div class="ke-inline-block ' + cls + '">',
  4185. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4186. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4187. '<span class="ke-button-common">',
  4188. hiddenElements.join(''),
  4189. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4190. '</span>',
  4191. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4192. (options.form ? '</div>' : '</form>'),
  4193. '</div>'].join('');
  4194. var div = K(html, button.doc);
  4195. button.hide();
  4196. button.before(div);
  4197. self.div = div;
  4198. self.button = button;
  4199. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4200. self.form = options.form ? K(options.form) : K('form', div);
  4201. self.fileBox = K('.ke-upload-file', div);
  4202. var width = options.width || K('.ke-button-common', div).width();
  4203. K('.ke-upload-area', div).width(width);
  4204. self.options = options;
  4205. },
  4206. submit : function(e) {
  4207. var self = this,
  4208. iframe = self.iframe;
  4209. e = false;
  4210. if (e) {
  4211. var file = e.files[0];
  4212. var filename = file.name;
  4213. var temp = filename.split('.');
  4214. //putExtra.params["x:name"] = temp[0];
  4215. var filename = hex_md5(file.name) + '.' + temp[temp.length-1];
  4216. var path = $('.' + 'ke-upload-file-key').val();
  4217. $('.' + 'ke-upload-file-key').val(path + filename);
  4218. //这里要修改 以后再改
  4219. } else {
  4220. iframe.bind('load', function() {
  4221. iframe.unbind();
  4222. var tempForm = document.createElement('form');
  4223. self.fileBox.before(tempForm);
  4224. K(tempForm).append(self.fileBox);
  4225. tempForm.reset();
  4226. K(tempForm).remove(true);
  4227. var doc = K.iframeDoc(iframe),
  4228. pre = doc.getElementsByTagName('pre')[0],
  4229. str = '', data;
  4230. if (pre) {
  4231. str = pre.innerHTML;
  4232. } else {
  4233. str = doc.body.innerHTML;
  4234. }
  4235. str = _unescape(str);
  4236. iframe[0].src = 'javascript:false';
  4237. try {
  4238. data = K.json(str);
  4239. } catch (e) {
  4240. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4241. }
  4242. if (data) {
  4243. self.options.afterUpload.call(self, data);
  4244. }
  4245. });
  4246. self.form[0].submit();
  4247. }
  4248. self.form[0].submit();
  4249. return self;
  4250. },
  4251. remove : function() {
  4252. var self = this;
  4253. if (self.fileBox) {
  4254. self.fileBox.unbind();
  4255. }
  4256. self.iframe.remove();
  4257. self.div.remove();
  4258. self.button.show();
  4259. return self;
  4260. }
  4261. });
  4262. function _uploadbutton(options) {
  4263. return new KUploadButton(options);
  4264. }
  4265. K.UploadButtonClass = KUploadButton;
  4266. K.uploadbutton = _uploadbutton;
  4267. function _createButton(arg) {
  4268. arg = arg || {};
  4269. var name = arg.name || '',
  4270. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4271. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4272. if (arg.click) {
  4273. btn.click(arg.click);
  4274. }
  4275. span.append(btn);
  4276. return span;
  4277. }
  4278. function KDialog(options) {
  4279. this.init(options);
  4280. }
  4281. _extend(KDialog, KWidget, {
  4282. init : function(options) {
  4283. var self = this;
  4284. var shadowMode = _undef(options.shadowMode, true);
  4285. options.z = options.z || 811213;
  4286. options.shadowMode = false;
  4287. options.autoScroll = _undef(options.autoScroll, true);
  4288. KDialog.parent.init.call(self, options);
  4289. var title = options.title,
  4290. body = K(options.body, self.doc),
  4291. previewBtn = options.previewBtn,
  4292. yesBtn = options.yesBtn,
  4293. noBtn = options.noBtn,
  4294. closeBtn = options.closeBtn,
  4295. showMask = _undef(options.showMask, true);
  4296. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4297. e.stopPropagation();
  4298. });
  4299. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4300. if (_IE && _V < 7) {
  4301. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4302. } else if (shadowMode) {
  4303. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4304. }
  4305. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4306. contentDiv.append(headerDiv);
  4307. headerDiv.html(title);
  4308. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4309. headerDiv.append(self.closeIcon);
  4310. self.draggable({
  4311. clickEl : headerDiv,
  4312. beforeDrag : options.beforeDrag
  4313. });
  4314. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4315. contentDiv.append(bodyDiv);
  4316. bodyDiv.append(body);
  4317. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4318. if (previewBtn || yesBtn || noBtn) {
  4319. contentDiv.append(footerDiv);
  4320. }
  4321. _each([
  4322. { btn : previewBtn, name : 'preview' },
  4323. { btn : yesBtn, name : 'yes' },
  4324. { btn : noBtn, name : 'no' }
  4325. ], function() {
  4326. if (this.btn) {
  4327. var button = _createButton(this.btn);
  4328. button.addClass('ke-dialog-' + this.name);
  4329. footerDiv.append(button);
  4330. }
  4331. });
  4332. if (self.height) {
  4333. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4334. }
  4335. self.div.width(self.div.width());
  4336. self.div.height(self.div.height());
  4337. self.mask = null;
  4338. if (showMask) {
  4339. var docEl = _docElement(self.doc),
  4340. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4341. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4342. self.mask = _widget({
  4343. x : 0,
  4344. y : 0,
  4345. z : self.z - 1,
  4346. cls : 'ke-dialog-mask',
  4347. width : docWidth,
  4348. height : docHeight
  4349. });
  4350. }
  4351. self.autoPos(self.div.width(), self.div.height());
  4352. self.footerDiv = footerDiv;
  4353. self.bodyDiv = bodyDiv;
  4354. self.headerDiv = headerDiv;
  4355. self.isLoading = false;
  4356. },
  4357. setMaskIndex : function(z) {
  4358. var self = this;
  4359. self.mask.div.css('z-index', z);
  4360. },
  4361. showLoading : function(msg) {
  4362. msg = _undef(msg, '');
  4363. var self = this, body = self.bodyDiv;
  4364. self.loading = K('<div class="ke-dialog-loading"><div class="ke-inline-block ke-dialog-loading-content" style="margin-top:' + Math.round(body.height() / 3) + 'px;">' + msg + '</div></div>')
  4365. .width(body.width()).height(body.height())
  4366. .css('top', self.headerDiv.height() + 'px');
  4367. body.css('visibility', 'hidden').after(self.loading);
  4368. self.isLoading = true;
  4369. return self;
  4370. },
  4371. hideLoading : function() {
  4372. this.loading && this.loading.remove();
  4373. this.bodyDiv.css('visibility', 'visible');
  4374. this.isLoading = false;
  4375. return this;
  4376. },
  4377. remove : function() {
  4378. var self = this;
  4379. if (self.options.beforeRemove) {
  4380. self.options.beforeRemove.call(self);
  4381. }
  4382. self.mask && self.mask.remove();
  4383. self.iframeMask && self.iframeMask.remove();
  4384. self.closeIcon.unbind();
  4385. K('input', self.div).unbind();
  4386. K('button', self.div).unbind();
  4387. self.footerDiv.unbind();
  4388. self.bodyDiv.unbind();
  4389. self.headerDiv.unbind();
  4390. K('iframe', self.div).each(function() {
  4391. K(this).remove();
  4392. });
  4393. KDialog.parent.remove.call(self);
  4394. return self;
  4395. }
  4396. });
  4397. function _dialog(options) {
  4398. return new KDialog(options);
  4399. }
  4400. K.DialogClass = KDialog;
  4401. K.dialog = _dialog;
  4402. function _tabs(options) {
  4403. var self = _widget(options),
  4404. remove = self.remove,
  4405. afterSelect = options.afterSelect,
  4406. div = self.div,
  4407. liList = [];
  4408. div.addClass('ke-tabs')
  4409. .bind('contextmenu,mousedown,mousemove', function(e) {
  4410. e.preventDefault();
  4411. });
  4412. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4413. div.append(ul);
  4414. self.add = function(tab) {
  4415. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4416. li.data('tab', tab);
  4417. liList.push(li);
  4418. ul.append(li);
  4419. };
  4420. self.selectedIndex = 0;
  4421. self.select = function(index) {
  4422. self.selectedIndex = index;
  4423. _each(liList, function(i, li) {
  4424. li.unbind();
  4425. if (i === index) {
  4426. li.addClass('ke-tabs-li-selected');
  4427. K(li.data('tab').panel).show('');
  4428. } else {
  4429. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4430. .mouseover(function() {
  4431. K(this).addClass('ke-tabs-li-on');
  4432. })
  4433. .mouseout(function() {
  4434. K(this).removeClass('ke-tabs-li-on');
  4435. })
  4436. .click(function() {
  4437. self.select(i);
  4438. });
  4439. K(li.data('tab').panel).hide();
  4440. }
  4441. });
  4442. if (afterSelect) {
  4443. afterSelect.call(self, index);
  4444. }
  4445. };
  4446. self.remove = function() {
  4447. _each(liList, function() {
  4448. this.remove();
  4449. });
  4450. ul.remove();
  4451. remove.call(self);
  4452. };
  4453. return self;
  4454. }
  4455. K.tabs = _tabs;
  4456. function _loadScript(url, fn) {
  4457. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4458. script = document.createElement('script');
  4459. head.appendChild(script);
  4460. script.src = url;
  4461. script.charset = 'utf-8';
  4462. script.onload = script.onreadystatechange = function() {
  4463. if (!this.readyState || this.readyState === 'loaded') {
  4464. if (fn) {
  4465. fn();
  4466. }
  4467. script.onload = script.onreadystatechange = null;
  4468. head.removeChild(script);
  4469. }
  4470. };
  4471. }
  4472. function _chopQuery(url) {
  4473. var index = url.indexOf('?');
  4474. return index > 0 ? url.substr(0, index) : url;
  4475. }
  4476. function _loadStyle(url) {
  4477. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4478. link = document.createElement('link'),
  4479. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4480. var links = K('link[rel="stylesheet"]', head);
  4481. for (var i = 0, len = links.length; i < len; i++) {
  4482. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4483. return;
  4484. }
  4485. }
  4486. head.appendChild(link);
  4487. link.href = url;
  4488. link.rel = 'stylesheet';
  4489. }
  4490. function _ajax(url, fn, method, param, dataType) {
  4491. method = method || 'GET';
  4492. dataType = dataType || 'json';
  4493. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4494. xhr.open(method, url, true);
  4495. xhr.onreadystatechange = function () {
  4496. if (xhr.readyState == 4 && xhr.status == 200) {
  4497. if (fn) {
  4498. var data = _trim(xhr.responseText);
  4499. if (dataType == 'json') {
  4500. data = _json(data);
  4501. }
  4502. fn(data);
  4503. }
  4504. }
  4505. };
  4506. if (method == 'POST') {
  4507. var params = [];
  4508. _each(param, function(key, val) {
  4509. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4510. });
  4511. try {
  4512. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4513. } catch (e) {}
  4514. xhr.send(params.join('&'));
  4515. } else {
  4516. xhr.send(null);
  4517. }
  4518. }
  4519. K.loadScript = _loadScript;
  4520. K.loadStyle = _loadStyle;
  4521. K.ajax = _ajax;
  4522. var _plugins = {};
  4523. function _plugin(name, fn) {
  4524. if (name === undefined) {
  4525. return _plugins;
  4526. }
  4527. if (!fn) {
  4528. return _plugins[name];
  4529. }
  4530. _plugins[name] = fn;
  4531. }
  4532. var _language = {};
  4533. function _parseLangKey(key) {
  4534. var match, ns = 'core';
  4535. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4536. ns = match[1];
  4537. key = match[2];
  4538. }
  4539. return { ns : ns, key : key };
  4540. }
  4541. function _lang(mixed, langType) {
  4542. langType = langType === undefined ? K.options.langType : langType;
  4543. if (typeof mixed === 'string') {
  4544. if (!_language[langType]) {
  4545. return 'no language';
  4546. }
  4547. var pos = mixed.length - 1;
  4548. if (mixed.substr(pos) === '.') {
  4549. return _language[langType][mixed.substr(0, pos)];
  4550. }
  4551. var obj = _parseLangKey(mixed);
  4552. return _language[langType][obj.ns][obj.key];
  4553. }
  4554. _each(mixed, function(key, val) {
  4555. var obj = _parseLangKey(key);
  4556. if (!_language[langType]) {
  4557. _language[langType] = {};
  4558. }
  4559. if (!_language[langType][obj.ns]) {
  4560. _language[langType][obj.ns] = {};
  4561. }
  4562. _language[langType][obj.ns][obj.key] = val;
  4563. });
  4564. }
  4565. function _getImageFromRange(range, fn) {
  4566. if (range.collapsed) {
  4567. return;
  4568. }
  4569. range = range.cloneRange().up();
  4570. var sc = range.startContainer, so = range.startOffset;
  4571. if (!_WEBKIT && !range.isControl()) {
  4572. return;
  4573. }
  4574. var img = K(sc.childNodes[so]);
  4575. if (!img || img.name != 'img') {
  4576. return;
  4577. }
  4578. if (fn(img)) {
  4579. return img;
  4580. }
  4581. }
  4582. function _bindContextmenuEvent() {
  4583. var self = this, doc = self.edit.doc;
  4584. K(doc).contextmenu(function(e) {
  4585. if (self.menu) {
  4586. self.hideMenu();
  4587. }
  4588. if (!self.useContextmenu) {
  4589. e.preventDefault();
  4590. return;
  4591. }
  4592. if (self._contextmenus.length === 0) {
  4593. return;
  4594. }
  4595. var maxWidth = 0, items = [];
  4596. _each(self._contextmenus, function() {
  4597. if (this.title == '-') {
  4598. items.push(this);
  4599. return;
  4600. }
  4601. if (this.cond && this.cond()) {
  4602. items.push(this);
  4603. if (this.width && this.width > maxWidth) {
  4604. maxWidth = this.width;
  4605. }
  4606. }
  4607. });
  4608. while (items.length > 0 && items[0].title == '-') {
  4609. items.shift();
  4610. }
  4611. while (items.length > 0 && items[items.length - 1].title == '-') {
  4612. items.pop();
  4613. }
  4614. var prevItem = null;
  4615. _each(items, function(i) {
  4616. if (this.title == '-' && prevItem.title == '-') {
  4617. delete items[i];
  4618. }
  4619. prevItem = this;
  4620. });
  4621. if (items.length > 0) {
  4622. e.preventDefault();
  4623. var pos = K(self.edit.iframe).pos(),
  4624. menu = _menu({
  4625. x : pos.x + e.clientX,
  4626. y : pos.y + e.clientY,
  4627. width : maxWidth,
  4628. css : { visibility: 'hidden' },
  4629. shadowMode : self.shadowMode
  4630. });
  4631. _each(items, function() {
  4632. if (this.title) {
  4633. menu.addItem(this);
  4634. }
  4635. });
  4636. var docEl = _docElement(menu.doc),
  4637. menuHeight = menu.div.height();
  4638. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4639. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4640. }
  4641. menu.div.css('visibility', 'visible');
  4642. self.menu = menu;
  4643. }
  4644. });
  4645. }
  4646. function _bindNewlineEvent() {
  4647. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4648. if (_IE && newlineTag !== 'br') {
  4649. return;
  4650. }
  4651. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4652. return;
  4653. }
  4654. if (_OPERA && _V < 9) {
  4655. return;
  4656. }
  4657. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4658. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4659. function getAncestorTagName(range) {
  4660. var ancestor = K(range.commonAncestor());
  4661. while (ancestor) {
  4662. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4663. break;
  4664. }
  4665. ancestor = ancestor.parent();
  4666. }
  4667. return ancestor.name;
  4668. }
  4669. K(doc).keydown(function(e) {
  4670. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4671. autoImg(self);
  4672. return;
  4673. }
  4674. self.cmd.selection();
  4675. var tagName = getAncestorTagName(self.cmd.range);
  4676. if (tagName == 'marquee' || tagName == 'select') {
  4677. return;
  4678. }
  4679. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4680. e.preventDefault();
  4681. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4682. return;
  4683. }
  4684. if (!pSkipTagMap[tagName]) {
  4685. _nativeCommand(doc, 'formatblock', '<p>');
  4686. }
  4687. });
  4688. K(doc).keyup(function(e) {
  4689. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4690. return;
  4691. }
  4692. if (newlineTag == 'br') {
  4693. return;
  4694. }
  4695. if (_GECKO) {
  4696. var root = self.cmd.commonAncestor('p');
  4697. var a = self.cmd.commonAncestor('a');
  4698. if (a && a.text() == '') {
  4699. a.remove(true);
  4700. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4701. self.cmd.select();
  4702. }
  4703. return;
  4704. }
  4705. self.cmd.selection();
  4706. var tagName = getAncestorTagName(self.cmd.range);
  4707. if (tagName == 'marquee' || tagName == 'select') {
  4708. return;
  4709. }
  4710. if (!pSkipTagMap[tagName]) {
  4711. _nativeCommand(doc, 'formatblock', '<p>');
  4712. }
  4713. var div = self.cmd.commonAncestor('div');
  4714. if (div) {
  4715. var p = K('<p></p>'),
  4716. child = div[0].firstChild;
  4717. while (child) {
  4718. var next = child.nextSibling;
  4719. p.append(child);
  4720. child = next;
  4721. }
  4722. div.before(p);
  4723. div.remove();
  4724. self.cmd.range.selectNodeContents(p[0]);
  4725. self.cmd.select();
  4726. }
  4727. });
  4728. }
  4729. function _bindTabEvent() {
  4730. var self = this, doc = self.edit.doc;
  4731. K(doc).keydown(function(e) {
  4732. if (e.which == 9) {
  4733. e.preventDefault();
  4734. if (self.afterTab) {
  4735. self.afterTab.call(self, e);
  4736. return;
  4737. }
  4738. var cmd = self.cmd, range = cmd.range;
  4739. range.shrink();
  4740. if (range.collapsed && range.startContainer.nodeType == 1) {
  4741. range.insertNode(K('@&nbsp;', doc)[0]);
  4742. cmd.select();
  4743. }
  4744. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4745. }
  4746. });
  4747. }
  4748. function _bindFocusEvent() {
  4749. var self = this;
  4750. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4751. if (self.afterFocus) {
  4752. self.afterFocus.call(self, e);
  4753. }
  4754. }).blur(function(e) {
  4755. if (self.afterBlur) {
  4756. self.afterBlur.call(self, e);
  4757. }
  4758. });
  4759. }
  4760. function _removeBookmarkTag(html) {
  4761. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4762. }
  4763. function _removeTempTag(html) {
  4764. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4765. }
  4766. function _addBookmarkToStack(stack, bookmark) {
  4767. if (stack.length === 0) {
  4768. stack.push(bookmark);
  4769. return;
  4770. }
  4771. var prev = stack[stack.length - 1];
  4772. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4773. stack.push(bookmark);
  4774. }
  4775. }
  4776. function _undoToRedo(fromStack, toStack) {
  4777. var self = this, edit = self.edit,
  4778. body = edit.doc.body,
  4779. range, bookmark;
  4780. if (fromStack.length === 0) {
  4781. return self;
  4782. }
  4783. if (edit.designMode) {
  4784. range = self.cmd.range;
  4785. bookmark = range.createBookmark(true);
  4786. bookmark.html = body.innerHTML;
  4787. } else {
  4788. bookmark = {
  4789. html : body.innerHTML
  4790. };
  4791. }
  4792. _addBookmarkToStack(toStack, bookmark);
  4793. var prev = fromStack.pop();
  4794. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4795. prev = fromStack.pop();
  4796. }
  4797. if (edit.designMode) {
  4798. edit.html(prev.html);
  4799. if (prev.start) {
  4800. range.moveToBookmark(prev);
  4801. self.select();
  4802. }
  4803. } else {
  4804. K(body).html(_removeBookmarkTag(prev.html));
  4805. }
  4806. return self;
  4807. }
  4808. function KEditor(options) {
  4809. var self = this;
  4810. self.options = {};
  4811. function setOption(key, val) {
  4812. if (KEditor.prototype[key] === undefined) {
  4813. self[key] = val;
  4814. }
  4815. self.options[key] = val;
  4816. }
  4817. _each(options, function(key, val) {
  4818. setOption(key, options[key]);
  4819. });
  4820. _each(K.options, function(key, val) {
  4821. if (self[key] === undefined) {
  4822. setOption(key, val);
  4823. }
  4824. });
  4825. var se = K(self.srcElement || '<textarea/>');
  4826. if (!self.width) {
  4827. self.width = se[0].style.width || se.width();
  4828. if (!self.width) {
  4829. self.width = '700';
  4830. }
  4831. }
  4832. if (!self.height) {
  4833. self.height = se[0].style.height || se.height();
  4834. }
  4835. setOption('width', _undef(self.width, self.minWidth));
  4836. setOption('height', _undef(self.height, self.minHeight));
  4837. setOption('width', _addUnit(self.width));
  4838. setOption('height', _addUnit(self.height));
  4839. if (_MOBILE && (!_IOS || _V < 534)) {
  4840. //self.designMode = false;
  4841. }
  4842. self.srcElement = se;
  4843. self.initContent = '';
  4844. self.plugin = {};
  4845. self.isCreated = false;
  4846. self._handlers = {};
  4847. self._contextmenus = [];
  4848. self._undoStack = [];
  4849. self._redoStack = [];
  4850. self._firstAddBookmark = true;
  4851. self.menu = self.contextmenu = null;
  4852. self.dialogs = [];
  4853. }
  4854. KEditor.prototype = {
  4855. lang : function(mixed) {
  4856. return _lang(mixed, this.langType);
  4857. },
  4858. loadPlugin : function(name, fn) {
  4859. var self = this;
  4860. var _pluginStatus = this._pluginStatus;
  4861. if (!_pluginStatus) {
  4862. _pluginStatus = this._pluginStatus = {};
  4863. }
  4864. if (_plugins[name]) {
  4865. if (!_isFunction(_plugins[name])) {
  4866. setTimeout(function() {
  4867. self.loadPlugin(name, fn);
  4868. }, 100);
  4869. return self;
  4870. }
  4871. if(!_pluginStatus[name]) {
  4872. _plugins[name].call(self, KindEditor);
  4873. _pluginStatus[name] = 'inited';
  4874. }
  4875. if (fn) {
  4876. fn.call(self);
  4877. }
  4878. return self;
  4879. }
  4880. _plugins[name] = 'loading';
  4881. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4882. setTimeout(function() {
  4883. if (_plugins[name]) {
  4884. self.loadPlugin(name, fn);
  4885. }
  4886. }, 0);
  4887. });
  4888. return self;
  4889. },
  4890. handler : function(key, fn) {
  4891. var self = this;
  4892. if (!self._handlers[key]) {
  4893. self._handlers[key] = [];
  4894. }
  4895. if (_isFunction(fn)) {
  4896. self._handlers[key].push(fn);
  4897. return self;
  4898. }
  4899. _each(self._handlers[key], function() {
  4900. fn = this.call(self, fn);
  4901. });
  4902. return fn;
  4903. },
  4904. clickToolbar : function(name, fn) {
  4905. var self = this, key = 'clickToolbar' + name;
  4906. if (fn === undefined) {
  4907. if (self._handlers[key]) {
  4908. return self.handler(key);
  4909. }
  4910. self.loadPlugin(name, function() {
  4911. self.handler(key);
  4912. });
  4913. return self;
  4914. }
  4915. return self.handler(key, fn);
  4916. },
  4917. updateState : function() {
  4918. var self = this;
  4919. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4920. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4921. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4922. });
  4923. return self;
  4924. },
  4925. addContextmenu : function(item) {
  4926. this._contextmenus.push(item);
  4927. return this;
  4928. },
  4929. afterCreate : function(fn) {
  4930. return this.handler('afterCreate', fn);
  4931. },
  4932. beforeRemove : function(fn) {
  4933. return this.handler('beforeRemove', fn);
  4934. },
  4935. beforeGetHtml : function(fn) {
  4936. return this.handler('beforeGetHtml', fn);
  4937. },
  4938. beforeSetHtml : function(fn) {
  4939. return this.handler('beforeSetHtml', fn);
  4940. },
  4941. afterSetHtml : function(fn) {
  4942. return this.handler('afterSetHtml', fn);
  4943. },
  4944. create : function() {
  4945. var self = this, fullscreenMode = self.fullscreenMode;
  4946. if (self.isCreated) {
  4947. return self;
  4948. }
  4949. if (self.srcElement.data('kindeditor')) {
  4950. return self;
  4951. }
  4952. self.srcElement.data('kindeditor', 'true');
  4953. if (fullscreenMode) {
  4954. _docElement().style.overflow = 'hidden';
  4955. } else {
  4956. _docElement().style.overflow = '';
  4957. }
  4958. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4959. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4960. if ((_IE && _V < 8) || _QUIRKS) {
  4961. height = _addUnit(_removeUnit(height) + 2);
  4962. }
  4963. var container = self.container = K(self.layout);
  4964. if (fullscreenMode) {
  4965. K(document.body).append(container);
  4966. } else {
  4967. self.srcElement.before(container);
  4968. }
  4969. var toolbarDiv = K('.toolbar', container),
  4970. editDiv = K('.edit', container),
  4971. statusbar = self.statusbar = K('.statusbar', container);
  4972. container.removeClass('container')
  4973. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4974. if (fullscreenMode) {
  4975. container.css({
  4976. position : 'absolute',
  4977. left : 0,
  4978. top : 0,
  4979. 'z-index' : 811211
  4980. });
  4981. if (!_GECKO) {
  4982. self._scrollPos = _getScrollPos();
  4983. }
  4984. window.scrollTo(0, 0);
  4985. K(document.body).css({
  4986. 'height' : '1px',
  4987. 'overflow' : 'hidden'
  4988. });
  4989. K(document.body.parentNode).css('overflow', 'hidden');
  4990. self._fullscreenExecuted = true;
  4991. } else {
  4992. if (self._fullscreenExecuted) {
  4993. K(document.body).css({
  4994. 'height' : '',
  4995. 'overflow' : ''
  4996. });
  4997. K(document.body.parentNode).css('overflow', '');
  4998. }
  4999. if (self._scrollPos) {
  5000. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  5001. }
  5002. }
  5003. var htmlList = [];
  5004. K.each(self.items, function(i, name) {
  5005. if (name == '|') {
  5006. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  5007. } else if (name == '/') {
  5008. htmlList.push('<div class="ke-hr"></div>');
  5009. } else {
  5010. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  5011. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  5012. }
  5013. });
  5014. var toolbar = self.toolbar = _toolbar({
  5015. src : toolbarDiv,
  5016. html : htmlList.join(''),
  5017. noDisableItems : self.noDisableItems,
  5018. click : function(e, name) {
  5019. e.stop();
  5020. if (self.menu) {
  5021. var menuName = self.menu.name;
  5022. self.hideMenu();
  5023. if (menuName === name) {
  5024. return;
  5025. }
  5026. }
  5027. self.clickToolbar(name);
  5028. }
  5029. });
  5030. var editHeight = _removeUnit(height) - toolbar.div.height();
  5031. var edit = self.edit = _edit({
  5032. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5033. src : editDiv,
  5034. srcElement : self.srcElement,
  5035. designMode : self.designMode,
  5036. themesPath : self.themesPath,
  5037. bodyClass : self.bodyClass,
  5038. cssPath : self.cssPath,
  5039. cssData : self.cssData,
  5040. beforeGetHtml : function(html) {
  5041. html = self.beforeGetHtml(html);
  5042. html = _removeBookmarkTag(_removeTempTag(html));
  5043. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5044. },
  5045. beforeSetHtml : function(html) {
  5046. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5047. return self.beforeSetHtml(html);
  5048. },
  5049. afterSetHtml : function() {
  5050. self.edit = edit = this;
  5051. self.afterSetHtml();
  5052. },
  5053. afterCreate : function() {
  5054. self.edit = edit = this;
  5055. self.cmd = edit.cmd;
  5056. self._docMousedownFn = function(e) {
  5057. if (self.menu) {
  5058. self.hideMenu();
  5059. }
  5060. };
  5061. K(edit.doc, document).mousedown(self._docMousedownFn);
  5062. _bindContextmenuEvent.call(self);
  5063. _bindNewlineEvent.call(self);
  5064. _bindTabEvent.call(self);
  5065. _bindFocusEvent.call(self);
  5066. edit.afterChange(function(e) {
  5067. if (!edit.designMode) {
  5068. return;
  5069. }
  5070. self.updateState();
  5071. self.addBookmark();
  5072. if (self.options.afterChange) {
  5073. self.options.afterChange.call(self);
  5074. }
  5075. });
  5076. edit.textarea.keyup(function(e) {
  5077. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5078. if (self.options.afterChange) {
  5079. self.options.afterChange.call(self);
  5080. }
  5081. }
  5082. });
  5083. if (self.readonlyMode) {
  5084. self.readonly();
  5085. }
  5086. self.isCreated = true;
  5087. if (self.initContent === '') {
  5088. self.initContent = self.html();
  5089. }
  5090. if (self._undoStack.length > 0) {
  5091. var prev = self._undoStack.pop();
  5092. if (prev.start) {
  5093. self.html(prev.html);
  5094. edit.cmd.range.moveToBookmark(prev);
  5095. self.select();
  5096. }
  5097. }
  5098. self.afterCreate();
  5099. if (self.options.afterCreate) {
  5100. self.options.afterCreate.call(self);
  5101. }
  5102. }
  5103. });
  5104. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5105. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5106. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5107. if (self._fullscreenResizeHandler) {
  5108. K(window).unbind('resize', self._fullscreenResizeHandler);
  5109. self._fullscreenResizeHandler = null;
  5110. }
  5111. function initResize() {
  5112. if (statusbar.height() === 0) {
  5113. setTimeout(initResize, 100);
  5114. return;
  5115. }
  5116. self.resize(width, height, false);
  5117. }
  5118. initResize();
  5119. if (fullscreenMode) {
  5120. self._fullscreenResizeHandler = function(e) {
  5121. if (self.isCreated) {
  5122. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5123. }
  5124. };
  5125. K(window).bind('resize', self._fullscreenResizeHandler);
  5126. toolbar.select('fullscreen');
  5127. statusbar.first().css('visibility', 'hidden');
  5128. statusbar.last().css('visibility', 'hidden');
  5129. } else {
  5130. if (_GECKO) {
  5131. K(window).bind('scroll', function(e) {
  5132. self._scrollPos = _getScrollPos();
  5133. });
  5134. }
  5135. if (self.resizeType > 0) {
  5136. _drag({
  5137. moveEl : container,
  5138. clickEl : statusbar,
  5139. moveFn : function(x, y, width, height, diffX, diffY) {
  5140. height += diffY;
  5141. self.resize(null, height);
  5142. }
  5143. });
  5144. } else {
  5145. statusbar.first().css('visibility', 'hidden');
  5146. }
  5147. if (self.resizeType === 2) {
  5148. _drag({
  5149. moveEl : container,
  5150. clickEl : statusbar.last(),
  5151. moveFn : function(x, y, width, height, diffX, diffY) {
  5152. width += diffX;
  5153. height += diffY;
  5154. self.resize(width, height);
  5155. }
  5156. });
  5157. } else {
  5158. statusbar.last().css('visibility', 'hidden');
  5159. }
  5160. }
  5161. return self;
  5162. },
  5163. remove : function() {
  5164. var self = this;
  5165. if (!self.isCreated) {
  5166. return self;
  5167. }
  5168. self.beforeRemove();
  5169. self.srcElement.data('kindeditor', '');
  5170. if (self.menu) {
  5171. self.hideMenu();
  5172. }
  5173. _each(self.dialogs, function() {
  5174. self.hideDialog();
  5175. });
  5176. K(document).unbind('mousedown', self._docMousedownFn);
  5177. self.toolbar.remove();
  5178. self.edit.remove();
  5179. self.statusbar.last().unbind();
  5180. self.statusbar.unbind();
  5181. self.container.remove();
  5182. self.container = self.toolbar = self.edit = self.menu = null;
  5183. self.dialogs = [];
  5184. self.isCreated = false;
  5185. return self;
  5186. },
  5187. resize : function(width, height, updateProp) {
  5188. var self = this;
  5189. updateProp = _undef(updateProp, true);
  5190. if (width) {
  5191. if (!/%/.test(width)) {
  5192. width = _removeUnit(width);
  5193. width = width < self.minWidth ? self.minWidth : width;
  5194. }
  5195. self.container.css('width', _addUnit(width));
  5196. if (updateProp) {
  5197. self.width = _addUnit(width);
  5198. }
  5199. }
  5200. if (height) {
  5201. height = _removeUnit(height);
  5202. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5203. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5204. self.edit.setHeight(editHeight);
  5205. if (updateProp) {
  5206. self.height = _addUnit(height);
  5207. }
  5208. }
  5209. return self;
  5210. },
  5211. select : function() {
  5212. this.isCreated && this.cmd.select();
  5213. return this;
  5214. },
  5215. html : function(val) {
  5216. var self = this;
  5217. if (val === undefined) {
  5218. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5219. }
  5220. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5221. if (self.isCreated) {
  5222. self.cmd.selection();
  5223. }
  5224. return self;
  5225. },
  5226. fullHtml : function() {
  5227. return this.isCreated ? this.edit.html(undefined, true) : '';
  5228. },
  5229. text : function(val) {
  5230. var self = this;
  5231. if (val === undefined) {
  5232. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5233. } else {
  5234. return self.html(_escape(val));
  5235. }
  5236. },
  5237. isEmpty : function() {
  5238. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5239. },
  5240. isDirty : function() {
  5241. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5242. },
  5243. selectedHtml : function() {
  5244. var val = this.isCreated ? this.cmd.range.html() : '';
  5245. val = _removeBookmarkTag(_removeTempTag(val));
  5246. return val;
  5247. },
  5248. count : function(mode) {
  5249. var self = this;
  5250. mode = (mode || 'html').toLowerCase();
  5251. if (mode === 'html') {
  5252. return self.html().length;
  5253. }
  5254. if (mode === 'text') {
  5255. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5256. }
  5257. return 0;
  5258. },
  5259. exec : function(key) {
  5260. key = key.toLowerCase();
  5261. var self = this, cmd = self.cmd,
  5262. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5263. if (changeFlag) {
  5264. self.addBookmark(false);
  5265. }
  5266. cmd[key].apply(cmd, _toArray(arguments, 1));
  5267. if (changeFlag) {
  5268. self.updateState();
  5269. self.addBookmark(false);
  5270. if (self.options.afterChange) {
  5271. self.options.afterChange.call(self);
  5272. }
  5273. }
  5274. return self;
  5275. },
  5276. insertHtml : function(val, quickMode) {
  5277. if (!this.isCreated) {
  5278. return this;
  5279. }
  5280. val = this.beforeSetHtml(val);
  5281. this.exec('inserthtml', val, quickMode);
  5282. return this;
  5283. },
  5284. appendHtml : function(val) {
  5285. this.html(this.html() + val);
  5286. if (this.isCreated) {
  5287. var cmd = this.cmd;
  5288. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5289. cmd.select();
  5290. }
  5291. return this;
  5292. },
  5293. sync : function() {
  5294. _elementVal(this.srcElement, this.html());
  5295. return this;
  5296. },
  5297. focus : function() {
  5298. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5299. return this;
  5300. },
  5301. blur : function() {
  5302. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5303. return this;
  5304. },
  5305. addBookmark : function(checkSize) {
  5306. checkSize = _undef(checkSize, true);
  5307. var self = this, edit = self.edit,
  5308. body = edit.doc.body,
  5309. html = _removeTempTag(body.innerHTML), bookmark;
  5310. if (checkSize && self._undoStack.length > 0) {
  5311. var prev = self._undoStack[self._undoStack.length - 1];
  5312. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5313. return self;
  5314. }
  5315. }
  5316. if (edit.designMode && !self._firstAddBookmark) {
  5317. var range = self.cmd.range;
  5318. bookmark = range.createBookmark(true);
  5319. bookmark.html = _removeTempTag(body.innerHTML);
  5320. range.moveToBookmark(bookmark);
  5321. } else {
  5322. bookmark = {
  5323. html : html
  5324. };
  5325. }
  5326. self._firstAddBookmark = false;
  5327. _addBookmarkToStack(self._undoStack, bookmark);
  5328. return self;
  5329. },
  5330. undo : function() {
  5331. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5332. },
  5333. redo : function() {
  5334. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5335. },
  5336. fullscreen : function(bool) {
  5337. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5338. this.addBookmark(false);
  5339. return this.remove().create();
  5340. },
  5341. readonly : function(isReadonly) {
  5342. isReadonly = _undef(isReadonly, true);
  5343. var self = this, edit = self.edit, doc = edit.doc;
  5344. if (self.designMode) {
  5345. self.toolbar.disableAll(isReadonly, []);
  5346. } else {
  5347. _each(self.noDisableItems, function() {
  5348. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5349. });
  5350. }
  5351. if (_IE) {
  5352. doc.body.contentEditable = !isReadonly;
  5353. } else {
  5354. doc.designMode = isReadonly ? 'off' : 'on';
  5355. }
  5356. edit.textarea[0].disabled = isReadonly;
  5357. },
  5358. createMenu : function(options) {
  5359. var self = this,
  5360. name = options.name,
  5361. knode = self.toolbar.get(name),
  5362. pos = knode.pos();
  5363. options.x = pos.x;
  5364. options.y = pos.y + knode.height();
  5365. options.z = self.options.zIndex;
  5366. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5367. if (options.selectedColor !== undefined) {
  5368. options.cls = 'ke-colorpicker-' + self.themeType;
  5369. options.noColor = self.lang('noColor');
  5370. self.menu = _colorpicker(options);
  5371. } else {
  5372. options.cls = 'ke-menu-' + self.themeType;
  5373. options.centerLineMode = false;
  5374. self.menu = _menu(options);
  5375. }
  5376. return self.menu;
  5377. },
  5378. hideMenu : function() {
  5379. this.menu.remove();
  5380. this.menu = null;
  5381. return this;
  5382. },
  5383. hideContextmenu : function() {
  5384. this.contextmenu.remove();
  5385. this.contextmenu = null;
  5386. return this;
  5387. },
  5388. createDialog : function(options) {
  5389. var self = this, name = options.name;
  5390. options.z = self.options.zIndex;
  5391. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5392. options.closeBtn = _undef(options.closeBtn, {
  5393. name : self.lang('close'),
  5394. click : function(e) {
  5395. self.hideDialog();
  5396. if (_IE && self.cmd) {
  5397. self.cmd.select();
  5398. }
  5399. }
  5400. });
  5401. options.noBtn = _undef(options.noBtn, {
  5402. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5403. click : function(e) {
  5404. self.hideDialog();
  5405. if (_IE && self.cmd) {
  5406. self.cmd.select();
  5407. }
  5408. }
  5409. });
  5410. if (self.dialogAlignType != 'page') {
  5411. options.alignEl = self.container;
  5412. }
  5413. options.cls = 'ke-dialog-' + self.themeType;
  5414. if (self.dialogs.length > 0) {
  5415. var firstDialog = self.dialogs[0],
  5416. parentDialog = self.dialogs[self.dialogs.length - 1];
  5417. firstDialog.setMaskIndex(parentDialog.z + 2);
  5418. options.z = parentDialog.z + 3;
  5419. options.showMask = false;
  5420. }
  5421. var dialog = _dialog(options);
  5422. self.dialogs.push(dialog);
  5423. return dialog;
  5424. },
  5425. hideDialog : function() {
  5426. var self = this;
  5427. if (self.dialogs.length > 0) {
  5428. self.dialogs.pop().remove();
  5429. }
  5430. if (self.dialogs.length > 0) {
  5431. var firstDialog = self.dialogs[0],
  5432. parentDialog = self.dialogs[self.dialogs.length - 1];
  5433. firstDialog.setMaskIndex(parentDialog.z - 1);
  5434. }
  5435. return self;
  5436. },
  5437. errorDialog : function(html) {
  5438. var self = this;
  5439. var dialog = self.createDialog({
  5440. width : 750,
  5441. title : self.lang('uploadError'),
  5442. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5443. });
  5444. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5445. doc.open();
  5446. doc.write(html);
  5447. doc.close();
  5448. K(doc.body).css('background-color', '#FFF');
  5449. iframe[0].contentWindow.focus();
  5450. return self;
  5451. }
  5452. };
  5453. function _editor(options) {
  5454. return new KEditor(options);
  5455. }
  5456. var _instances = [];
  5457. function _create(expr, options) {
  5458. options = options || {};
  5459. options.basePath = _undef(options.basePath, K.basePath);
  5460. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5461. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5462. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5463. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5464. var themeType = _undef(options.themeType, K.options.themeType);
  5465. _loadStyle(options.themesPath + 'default/default.css');
  5466. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5467. }
  5468. function create(editor) {
  5469. _each(_plugins, function(name, fn) {
  5470. if (_isFunction(fn)) {
  5471. fn.call(editor, KindEditor);
  5472. if (!editor._pluginStatus) {
  5473. editor._pluginStatus = {};
  5474. }
  5475. editor._pluginStatus[name] = 'inited';
  5476. }
  5477. });
  5478. return editor.create();
  5479. }
  5480. var knode = K(expr);
  5481. if (!knode || knode.length === 0) {
  5482. return;
  5483. }
  5484. if (knode.length > 1) {
  5485. knode.each(function() {
  5486. _create(this, options);
  5487. });
  5488. return _instances[0];
  5489. }
  5490. options.srcElement = knode[0];
  5491. var editor = new KEditor(options);
  5492. _instances.push(editor);
  5493. if (_language[editor.langType]) {
  5494. return create(editor);
  5495. }
  5496. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5497. create(editor);
  5498. });
  5499. return editor;
  5500. }
  5501. function _eachEditor(expr, fn) {
  5502. K(expr).each(function(i, el) {
  5503. K.each(_instances, function(j, editor) {
  5504. if (editor && editor.srcElement[0] == el) {
  5505. fn.call(editor, j);
  5506. return false;
  5507. }
  5508. });
  5509. });
  5510. }
  5511. K.remove = function(expr) {
  5512. _eachEditor(expr, function(i) {
  5513. this.remove();
  5514. _instances.splice(i, 1);
  5515. });
  5516. };
  5517. K.sync = function(expr) {
  5518. _eachEditor(expr, function() {
  5519. this.sync();
  5520. });
  5521. };
  5522. K.html = function(expr, val) {
  5523. _eachEditor(expr, function() {
  5524. this.html(val);
  5525. });
  5526. };
  5527. K.insertHtml = function(expr, val) {
  5528. _eachEditor(expr, function() {
  5529. this.insertHtml(val);
  5530. });
  5531. };
  5532. K.appendHtml = function(expr, val) {
  5533. _eachEditor(expr, function() {
  5534. this.appendHtml(val);
  5535. });
  5536. };
  5537. if (_IE && _V < 7) {
  5538. _nativeCommand(document, 'BackgroundImageCache', true);
  5539. }
  5540. K.EditorClass = KEditor;
  5541. K.editor = _editor;
  5542. K.create = _create;
  5543. K.instances = _instances;
  5544. K.plugin = _plugin;
  5545. K.lang = _lang;
  5546. _plugin('core', function(K) {
  5547. var self = this,
  5548. shortcutKeys = {
  5549. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5550. };
  5551. self.afterSetHtml(function() {
  5552. if (self.options.afterChange) {
  5553. self.options.afterChange.call(self);
  5554. }
  5555. });
  5556. self.afterCreate(function() {
  5557. if (self.syncType != 'form') {
  5558. return;
  5559. }
  5560. var el = K(self.srcElement), hasForm = false;
  5561. while ((el = el.parent())) {
  5562. if (el.name == 'form') {
  5563. hasForm = true;
  5564. break;
  5565. }
  5566. }
  5567. if (hasForm) {
  5568. el.bind('submit', function(e) {
  5569. self.sync();
  5570. K(window).bind('unload', function() {
  5571. self.edit.textarea.remove();
  5572. });
  5573. });
  5574. var resetBtn = K('[type="reset"]', el);
  5575. resetBtn.click(function() {
  5576. self.html(self.initContent);
  5577. self.cmd.selection();
  5578. });
  5579. self.beforeRemove(function() {
  5580. el.unbind();
  5581. resetBtn.unbind();
  5582. });
  5583. }
  5584. });
  5585. self.clickToolbar('source', function() {
  5586. if (self.edit.designMode) {
  5587. self.toolbar.disableAll(true);
  5588. self.edit.design(false);
  5589. self.toolbar.select('source');
  5590. } else {
  5591. self.toolbar.disableAll(false);
  5592. self.edit.design(true);
  5593. self.toolbar.unselect('source');
  5594. if (_GECKO) {
  5595. setTimeout(function() {
  5596. self.cmd.selection();
  5597. }, 0);
  5598. } else {
  5599. self.cmd.selection();
  5600. }
  5601. }
  5602. self.designMode = self.edit.designMode;
  5603. });
  5604. self.afterCreate(function() {
  5605. if (!self.designMode) {
  5606. self.toolbar.disableAll(true).select('source');
  5607. }
  5608. });
  5609. self.clickToolbar('fullscreen', function() {
  5610. self.fullscreen();
  5611. });
  5612. if (self.fullscreenShortcut) {
  5613. var loaded = false;
  5614. self.afterCreate(function() {
  5615. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5616. if (e.which == 27) {
  5617. setTimeout(function() {
  5618. self.fullscreen();
  5619. }, 0);
  5620. }
  5621. });
  5622. if (loaded) {
  5623. if (_IE && !self.designMode) {
  5624. return;
  5625. }
  5626. self.focus();
  5627. }
  5628. if (!loaded) {
  5629. loaded = true;
  5630. }
  5631. });
  5632. }
  5633. _each('undo,redo'.split(','), function(i, name) {
  5634. if (shortcutKeys[name]) {
  5635. self.afterCreate(function() {
  5636. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5637. self.clickToolbar(name);
  5638. });
  5639. });
  5640. }
  5641. self.clickToolbar(name, function() {
  5642. self[name]();
  5643. });
  5644. });
  5645. self.clickToolbar('formatblock', function() {
  5646. var blocks = self.lang('formatblock.formatBlock'),
  5647. heights = {
  5648. h1 : 28,
  5649. h2 : 24,
  5650. h3 : 18,
  5651. H4 : 14,
  5652. p : 12
  5653. },
  5654. curVal = self.cmd.val('formatblock'),
  5655. menu = self.createMenu({
  5656. name : 'formatblock',
  5657. width : self.langType == 'en' ? 200 : 150
  5658. });
  5659. _each(blocks, function(key, val) {
  5660. var style = 'font-size:' + heights[key] + 'px;';
  5661. if (key.charAt(0) === 'h') {
  5662. style += 'font-weight:bold;';
  5663. }
  5664. menu.addItem({
  5665. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5666. height : heights[key] + 12,
  5667. checked : (curVal === key || curVal === val),
  5668. click : function() {
  5669. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5670. }
  5671. });
  5672. });
  5673. });
  5674. self.clickToolbar('fontname', function() {
  5675. var curVal = self.cmd.val('fontname'),
  5676. menu = self.createMenu({
  5677. name : 'fontname',
  5678. width : 150
  5679. });
  5680. _each(self.lang('fontname.fontName'), function(key, val) {
  5681. menu.addItem({
  5682. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5683. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5684. click : function() {
  5685. self.exec('fontname', key).hideMenu();
  5686. }
  5687. });
  5688. });
  5689. });
  5690. self.clickToolbar('fontsize', function() {
  5691. var curVal = self.cmd.val('fontsize'),
  5692. menu = self.createMenu({
  5693. name : 'fontsize',
  5694. width : 150
  5695. });
  5696. _each(self.fontSizeTable, function(i, val) {
  5697. menu.addItem({
  5698. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5699. height : _removeUnit(val) + 12,
  5700. checked : curVal === val,
  5701. click : function() {
  5702. self.exec('fontsize', val).hideMenu();
  5703. }
  5704. });
  5705. });
  5706. });
  5707. self.clickToolbar('fontheight', function() {
  5708. var curVal = self.cmd.val('fontheight'),
  5709. menu = self.createMenu({
  5710. name : 'fontsize',
  5711. width : 150
  5712. });
  5713. _each(self.fontHeightTable, function(i, val) {
  5714. menu.addItem({
  5715. title : '<span unselectable="on">' + val + '</span>',
  5716. height : 20,
  5717. checked : curVal === val,
  5718. click : function() {
  5719. self.exec('fontheight', val).hideMenu();
  5720. }
  5721. });
  5722. });
  5723. });
  5724. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5725. self.clickToolbar(name, function() {
  5726. self.createMenu({
  5727. name : name,
  5728. selectedColor : self.cmd.val(name) || 'default',
  5729. colors : self.colorTable,
  5730. click : function(color) {
  5731. self.exec(name, color).hideMenu();
  5732. }
  5733. });
  5734. });
  5735. });
  5736. _each(('cut,copy,paste').split(','), function(i, name) {
  5737. self.clickToolbar(name, function() {
  5738. self.focus();
  5739. try {
  5740. self.exec(name, null);
  5741. } catch(e) {
  5742. alert(self.lang(name + 'Error'));
  5743. }
  5744. });
  5745. });
  5746. self.clickToolbar('about', function() {
  5747. var html = '<div style="margin:20px;">' +
  5748. '<div>KindEditor ' + _VERSION + '</div>' +
  5749. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5750. '</div>';
  5751. self.createDialog({
  5752. name : 'about',
  5753. width : 350,
  5754. title : self.lang('about'),
  5755. body : html
  5756. });
  5757. });
  5758. self.plugin.getSelectedLink = function() {
  5759. return self.cmd.commonAncestor('a');
  5760. };
  5761. self.plugin.getSelectedImage = function() {
  5762. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5763. return !/^ke-\w+$/i.test(img[0].className);
  5764. });
  5765. };
  5766. self.plugin.getSelectedFlash = function() {
  5767. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5768. return img[0].className == 'ke-flash';
  5769. });
  5770. };
  5771. self.plugin.getSelectedMedia = function() {
  5772. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5773. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5774. });
  5775. };
  5776. self.plugin.getSelectedAnchor = function() {
  5777. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5778. return img[0].className == 'ke-anchor';
  5779. });
  5780. };
  5781. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5782. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5783. _each('edit,delete'.split(','), function(j, val) {
  5784. self.addContextmenu({
  5785. title : self.lang(val + uName),
  5786. click : function() {
  5787. self.loadPlugin(name, function() {
  5788. self.plugin[name][val]();
  5789. self.hideMenu();
  5790. });
  5791. },
  5792. cond : self.plugin['getSelected' + uName],
  5793. width : 150,
  5794. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5795. });
  5796. });
  5797. self.addContextmenu({ title : '-' });
  5798. });
  5799. self.plugin.getSelectedTable = function() {
  5800. return self.cmd.commonAncestor('table');
  5801. };
  5802. self.plugin.getSelectedRow = function() {
  5803. return self.cmd.commonAncestor('tr');
  5804. };
  5805. self.plugin.getSelectedCell = function() {
  5806. return self.cmd.commonAncestor('td');
  5807. };
  5808. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5809. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5810. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5811. self.addContextmenu({
  5812. title : self.lang('table' + val),
  5813. click : function() {
  5814. self.loadPlugin('table', function() {
  5815. self.plugin.table[val]();
  5816. self.hideMenu();
  5817. });
  5818. },
  5819. cond : cond,
  5820. width : 170,
  5821. iconClass : 'ke-icon-table' + val
  5822. });
  5823. });
  5824. self.addContextmenu({ title : '-' });
  5825. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5826. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5827. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5828. if (shortcutKeys[name]) {
  5829. self.afterCreate(function() {
  5830. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5831. self.cmd.selection();
  5832. self.clickToolbar(name);
  5833. });
  5834. });
  5835. }
  5836. self.clickToolbar(name, function() {
  5837. self.focus().exec(name, null);
  5838. });
  5839. });
  5840. self.afterCreate(function() {
  5841. var doc = self.edit.doc, cmd, bookmark, div,
  5842. cls = '__kindeditor_paste__', pasting = false;
  5843. function movePastedData() {
  5844. cmd.range.moveToBookmark(bookmark);
  5845. cmd.select();
  5846. if (_WEBKIT) {
  5847. K('div.' + cls, div).each(function() {
  5848. K(this).after('<br />').remove(true);
  5849. });
  5850. K('span.Apple-style-span', div).remove(true);
  5851. K('span.Apple-tab-span', div).remove(true);
  5852. K('span[style]', div).each(function() {
  5853. if (K(this).css('white-space') == 'nowrap') {
  5854. K(this).remove(true);
  5855. }
  5856. });
  5857. K('meta', div).remove();
  5858. }
  5859. var html = div[0].innerHTML;
  5860. div.remove();
  5861. if (html === '') {
  5862. return;
  5863. }
  5864. if (_WEBKIT) {
  5865. html = html.replace(/(<br>)\1/ig, '$1');
  5866. }
  5867. if (self.pasteType === 2) {
  5868. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5869. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5870. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5871. } else {
  5872. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5873. html = self.beforeSetHtml(html);
  5874. }
  5875. }
  5876. if (self.pasteType === 1) {
  5877. html = html.replace(/&nbsp;/ig, ' ');
  5878. html = html.replace(/\n\s*\n/g, '\n');
  5879. html = html.replace(/<br[^>]*>/ig, '\n');
  5880. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5881. html = html.replace(/<[^>]+>/g, '');
  5882. html = html.replace(/ {2}/g, ' &nbsp;');
  5883. if (self.newlineTag == 'p') {
  5884. if (/\n/.test(html)) {
  5885. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5886. }
  5887. } else {
  5888. html = html.replace(/\n/g, '<br />$&');
  5889. }
  5890. }
  5891. self.insertHtml(html, true);
  5892. autoImg(self);
  5893. }
  5894. K(doc.body).bind('paste', function(e){
  5895. //处理IE11,Chrome粘贴图片上传
  5896. function dopasteImg() {
  5897. //debugger;
  5898. var file = null;
  5899. if (window.clipboardData) {//ie
  5900. if (clipboardData.files && clipboardData.files.length)//IE11
  5901. file = clipboardData.files[0];
  5902. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5903. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5904. return true;
  5905. }
  5906. } else {
  5907. if (e.event.clipboardData.items)//chrome
  5908. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5909. if (e.event.clipboardData.items[i].kind === "file") {
  5910. file = e.event.clipboardData.items[i];
  5911. break;
  5912. }
  5913. }
  5914. if (file == null) {
  5915. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5916. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5917. return true;
  5918. }
  5919. }
  5920. }
  5921. if (file) {
  5922. if (!K.undef(self.allowImageUpload, true)) {
  5923. alert("编辑器禁止上传图片,请与有关人员联系!");
  5924. return true;
  5925. }
  5926. //获取File Blob
  5927. //debugger;
  5928. var blb;
  5929. if (file.getAsFile) {//Chrome
  5930. blb = file.getAsFile();
  5931. if (blb.size === 0) {
  5932. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5933. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5934. return true;
  5935. }
  5936. sendfile(blb, file.type);
  5937. } else {
  5938. var fr = new FileReader();
  5939. if (fr.readAsArrayBuffer) {//ie
  5940. fr.onloadend = function (evt) {
  5941. blb = evt.target.result;
  5942. sendfile(blb, file.type);
  5943. }
  5944. fr.readAsArrayBuffer(file);
  5945. }
  5946. }
  5947. function sendfile(b, t) {
  5948. var xhr = new XMLHttpRequest();
  5949. var formData = new FormData();
  5950. var isImg = t.indexOf("image/") === 0;
  5951. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5952. //formData.append('imgFile', b);
  5953. var myBlob = new Blob([b], { "type": t });
  5954. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5955. //formData.append('imgFile', b);
  5956. formData.append('dir', isImg ? 'image' : 'file');
  5957. if (self.uploadYunJson && self.uploadYunJson.domain) {
  5958. formData.append('token', self.uploadYunJson.token);
  5959. xhr.open('POST', self.uploadYunJson.domain);
  5960. } else {
  5961. xhr.open('POST', self.uploadJson);
  5962. }
  5963. xhr.onreadystatechange = function () {
  5964. if (xhr.readyState == 4&&xhr.status == 200) {
  5965. // if (fn) {
  5966. var data = _trim(xhr.responseText);
  5967. //if (dataType == 'json') {
  5968. data = _json(data);
  5969. if (data.error) {
  5970. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5971. $.messager.alert('Error', data.message, 'warning');
  5972. } else {
  5973. alert(data.message);
  5974. }
  5975. } else {
  5976. //self.exec('insertimage', url, title, width, height, border, align);
  5977. if(K.undef(self.formatUploadUrl, true))
  5978. data.url =K.formatUrl(data.url, 'absolute');
  5979. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5980. }
  5981. //}
  5982. // fn(data);
  5983. // }
  5984. }
  5985. }
  5986. xhr.send(formData);
  5987. }
  5988. return true;
  5989. }
  5990. }
  5991. //debugger;
  5992. if (dopasteImg())
  5993. e.stop();
  5994. //处理粘贴结束5825
  5995. if (self.pasteType === 0) {
  5996. e.stop();
  5997. return;
  5998. }
  5999. if (pasting) {
  6000. return;
  6001. }
  6002. pasting = true;
  6003. K('div.' + cls, doc).remove();
  6004. cmd = self.cmd.selection();
  6005. bookmark = cmd.range.createBookmark();
  6006. div = K('<div class="' + cls + '"></div>', doc).css({
  6007. position : 'absolute',
  6008. width : '1px',
  6009. height : '1px',
  6010. overflow : 'hidden',
  6011. left : '-1981px',
  6012. top : K(bookmark.start).pos().y + 'px',
  6013. 'white-space' : 'nowrap'
  6014. });
  6015. K(doc.body).append(div);
  6016. if (_IE) {
  6017. var rng = cmd.range.get(true);
  6018. rng.moveToElementText(div[0]);
  6019. rng.select();
  6020. rng.execCommand('paste');
  6021. e.preventDefault();
  6022. } else {
  6023. cmd.range.selectNodeContents(div[0]);
  6024. cmd.select();
  6025. div[0].tabIndex = -1;
  6026. div[0].focus();
  6027. }
  6028. setTimeout(function() {
  6029. movePastedData();
  6030. pasting = false;
  6031. }, 0);
  6032. });
  6033. });
  6034. self.beforeGetHtml(function(html) {
  6035. if (_IE && _V <= 8) {
  6036. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  6037. return unescape(tag);
  6038. });
  6039. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  6040. if (!/\s+type="[^"]+"/i.test($0)) {
  6041. return $1 + ' type="text"' + $2;
  6042. }
  6043. return $0;
  6044. });
  6045. }
  6046. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  6047. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  6048. })
  6049. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  6050. var imgAttrs = _getAttrList(full);
  6051. var styles = _getCssList(imgAttrs.style || '');
  6052. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6053. var width = _undef(styles.width, '');
  6054. var height = _undef(styles.height, '');
  6055. if (/px/i.test(width)) {
  6056. width = _removeUnit(width);
  6057. }
  6058. if (/px/i.test(height)) {
  6059. height = _removeUnit(height);
  6060. }
  6061. attrs.width = _undef(imgAttrs.width, width);
  6062. attrs.height = _undef(imgAttrs.height, height);
  6063. return _mediaEmbed(attrs);
  6064. })
  6065. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6066. var imgAttrs = _getAttrList(full);
  6067. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6068. })
  6069. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6070. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6071. })
  6072. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6073. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6074. })
  6075. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6076. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6077. return $1 + _unescape(src) + $2;
  6078. });
  6079. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6080. return full;
  6081. })
  6082. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6083. return start + end;
  6084. });
  6085. });
  6086. self.beforeSetHtml(function(html) {
  6087. if (_IE && _V <= 8) {
  6088. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6089. var attrs = _getAttrList(full);
  6090. var styles = _getCssList(attrs.style || '');
  6091. if (styles.display == 'none') {
  6092. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6093. }
  6094. return full;
  6095. });
  6096. }
  6097. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6098. var attrs = _getAttrList(full);
  6099. attrs.src = _undef(attrs.src, '');
  6100. attrs.width = _undef(attrs.width, 0);
  6101. attrs.height = _undef(attrs.height, 0);
  6102. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6103. })
  6104. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6105. var attrs = _getAttrList(full);
  6106. if (attrs.href !== undefined) {
  6107. return full;
  6108. }
  6109. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6110. })
  6111. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6112. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6113. })
  6114. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6115. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6116. })
  6117. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6118. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6119. return full;
  6120. }
  6121. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6122. return full;
  6123. })
  6124. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6125. return start + 'data-ke-' + end;
  6126. })
  6127. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6128. if (full.indexOf('ke-zeroborder') >= 0) {
  6129. return full;
  6130. }
  6131. return _addClassToTag(full, 'ke-zeroborder');
  6132. });
  6133. });
  6134. });
  6135. })(window);
  6136. /*******************************************************************************
  6137. * KindEditor - WYSIWYG HTML Editor for Internet
  6138. * Copyright (C) 2006-2011 kindsoft.net
  6139. *
  6140. * @author Roddy <luolonghao@gmail.com>
  6141. * @site http://www.kindsoft.net/
  6142. * @licence http://www.kindsoft.net/license.php
  6143. *******************************************************************************/
  6144. KindEditor.lang({
  6145. source : 'HTML代码',
  6146. preview : '预览',
  6147. undo : '后退(Ctrl+Z)',
  6148. redo : '前进(Ctrl+Y)',
  6149. cut : '剪切(Ctrl+X)',
  6150. copy : '复制(Ctrl+C)',
  6151. paste : '粘贴(Ctrl+V)',
  6152. plainpaste : '粘贴为无格式文本',
  6153. wordpaste : '从Word粘贴',
  6154. selectall : '全选(Ctrl+A)',
  6155. justifyleft : '左对齐',
  6156. justifycenter : '居中',
  6157. justifyright : '右对齐',
  6158. justifyfull : '两端对齐',
  6159. insertorderedlist : '编号',
  6160. insertunorderedlist : '项目符号',
  6161. indent : '增加缩进',
  6162. outdent : '减少缩进',
  6163. subscript : '下标',
  6164. superscript : '上标',
  6165. formatblock : '段落',
  6166. fontname : '字体',
  6167. fontsize : '文字大小',
  6168. fontheight : '文字间距',
  6169. forecolor : '文字颜色',
  6170. hilitecolor : '文字背景',
  6171. bold : '粗体(Ctrl+B)',
  6172. italic : '斜体(Ctrl+I)',
  6173. underline : '下划线(Ctrl+U)',
  6174. strikethrough : '删除线',
  6175. removeformat : '删除格式',
  6176. image : '图片',
  6177. multiimage : '批量图片上传',
  6178. flash : 'Flash',
  6179. media : '音视频',
  6180. table : '表格',
  6181. tablecell : '单元格',
  6182. hr : '插入横线',
  6183. emoticons : '插入表情',
  6184. link : '超级链接',
  6185. unlink : '取消超级链接',
  6186. fullscreen : '全屏显示',
  6187. about : '关于',
  6188. print : '打印(Ctrl+P)',
  6189. filemanager : '文件库',
  6190. code : '插入程序代码',
  6191. map : 'Google地图',
  6192. baidumap : '百度地图',
  6193. lineheight : '行距',
  6194. clearhtml : '清理HTML代码',
  6195. pagebreak : '插入分页符',
  6196. quickformat : '一键排版',
  6197. insertfile : '插入文件',
  6198. template : '插入模板',
  6199. anchor : '锚点',
  6200. yes : '确定',
  6201. no : '取消',
  6202. close : '关闭',
  6203. editImage : '图片属性',
  6204. deleteImage : '删除图片',
  6205. editFlash : 'Flash属性',
  6206. deleteFlash : '删除Flash',
  6207. editMedia : '音视频属性',
  6208. deleteMedia : '删除音视频',
  6209. editLink : '超级链接属性',
  6210. deleteLink : '取消超级链接',
  6211. editAnchor : '锚点属性',
  6212. deleteAnchor : '删除锚点',
  6213. tableprop : '表格属性',
  6214. tablecellprop : '单元格属性',
  6215. tableinsert : '插入表格',
  6216. tabledelete : '删除表格',
  6217. tablecolinsertleft : '左侧插入列',
  6218. tablecolinsertright : '右侧插入列',
  6219. tablerowinsertabove : '上方插入行',
  6220. tablerowinsertbelow : '下方插入行',
  6221. tablerowmerge : '向下合并单元格',
  6222. tablecolmerge : '向右合并单元格',
  6223. tablerowsplit : '拆分行',
  6224. tablecolsplit : '拆分列',
  6225. tablecoldelete : '删除列',
  6226. tablerowdelete : '删除行',
  6227. noColor : '无颜色',
  6228. pleaseSelectFile : '请选择文件。',
  6229. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6230. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6231. invalidWidth : "宽度必须为数字。",
  6232. invalidHeight : "高度必须为数字。",
  6233. invalidBorder : "边框必须为数字。",
  6234. invalidUrl : "请输入有效的URL地址。",
  6235. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6236. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6237. invalidPadding : '边距必须为数字。',
  6238. invalidSpacing : '间距必须为数字。',
  6239. invalidJson : '服务器发生故障。',
  6240. uploadSuccess : '上传成功。',
  6241. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6242. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6243. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6244. ajaxLoading : '加载中,请稍候 ...',
  6245. uploadLoading : '上传中,请稍候 ...',
  6246. uploadError : '上传错误',
  6247. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6248. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6249. 'code.pleaseInput' : '请输入程序代码。',
  6250. 'link.url' : 'URL',
  6251. 'link.linkType' : '打开类型',
  6252. 'link.newWindow' : '新窗口',
  6253. 'link.selfWindow' : '当前窗口',
  6254. 'flash.url' : 'URL',
  6255. 'flash.width' : '宽度',
  6256. 'flash.height' : '高度',
  6257. 'flash.upload' : '上传',
  6258. 'flash.viewServer' : '文件空间',
  6259. 'media.url' : 'URL',
  6260. 'media.width' : '宽度',
  6261. 'media.height' : '高度',
  6262. 'media.autostart' : '自动播放',
  6263. 'media.upload' : '上传',
  6264. 'media.viewServer' : '文件空间',
  6265. 'image.remoteImage' : '网络图片',
  6266. 'image.localImage' : '本地上传',
  6267. 'image.remoteUrl' : '图片地址',
  6268. 'image.localUrl' : '上传文件',
  6269. 'image.size' : '图片大小',
  6270. 'image.width' : '宽',
  6271. 'image.height' : '高',
  6272. 'image.resetSize' : '重置大小',
  6273. 'image.align' : '对齐方式',
  6274. 'image.defaultAlign' : '默认方式',
  6275. 'image.leftAlign' : '左对齐',
  6276. 'image.rightAlign' : '右对齐',
  6277. 'image.imgTitle' : '图片说明',
  6278. 'image.upload' : '浏览...',
  6279. 'image.viewServer' : '图片空间',
  6280. //'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6281. 'multiimage.uploadDesc' : '',
  6282. 'multiimage.startUpload' : '开始上传',
  6283. 'multiimage.clearAll' : '全部清空',
  6284. 'multiimage.insertAll' : '全部插入',
  6285. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6286. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6287. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6288. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6289. 'multiimage.unknownError' : '发生异常,无法上传。',
  6290. 'multiimage.pending' : '等待上传',
  6291. 'multiimage.uploadError' : '上传失败',
  6292. 'filemanager.emptyFolder' : '空文件夹',
  6293. 'filemanager.moveup' : '移到上一级文件夹',
  6294. 'filemanager.viewType' : '显示方式:',
  6295. 'filemanager.viewImage' : '缩略图',
  6296. 'filemanager.listImage' : '详细信息',
  6297. 'filemanager.orderType' : '排序方式:',
  6298. 'filemanager.fileName' : '名称',
  6299. 'filemanager.fileSize' : '大小',
  6300. 'filemanager.fileType' : '类型',
  6301. 'insertfile.url' : 'URL',
  6302. 'insertfile.title' : '文件说明',
  6303. 'insertfile.upload' : '上传',
  6304. 'insertfile.viewServer' : '文件空间',
  6305. 'table.cells' : '单元格数',
  6306. 'table.rows' : '行数',
  6307. 'table.cols' : '列数',
  6308. 'table.size' : '大小',
  6309. 'table.width' : '宽度',
  6310. 'table.height' : '高度',
  6311. 'table.percent' : '%',
  6312. 'table.px' : 'px',
  6313. 'table.space' : '边距间距',
  6314. 'table.padding' : '边距',
  6315. 'table.spacing' : '间距',
  6316. 'table.align' : '对齐方式',
  6317. 'table.textAlign' : '水平对齐',
  6318. 'table.verticalAlign' : '垂直对齐',
  6319. 'table.alignDefault' : '默认',
  6320. 'table.alignLeft' : '左对齐',
  6321. 'table.alignCenter' : '居中',
  6322. 'table.alignRight' : '右对齐',
  6323. 'table.alignTop' : '顶部',
  6324. 'table.alignMiddle' : '中部',
  6325. 'table.alignBottom' : '底部',
  6326. 'table.alignBaseline' : '基线',
  6327. 'table.border' : '边框',
  6328. 'table.borderWidth' : '边框',
  6329. 'table.borderColor' : '颜色',
  6330. 'table.backgroundColor' : '背景颜色',
  6331. 'map.address' : '地址: ',
  6332. 'map.search' : '搜索',
  6333. 'baidumap.address' : '地址: ',
  6334. 'baidumap.search' : '搜索',
  6335. 'baidumap.insertDynamicMap' : '插入动态地图',
  6336. 'anchor.name' : '锚点名称',
  6337. 'formatblock.formatBlock' : {
  6338. h1 : '标题 1',
  6339. h2 : '标题 2',
  6340. h3 : '标题 3',
  6341. h4 : '标题 4',
  6342. p : '正 文'
  6343. },
  6344. 'fontname.fontName' : {
  6345. 'SimSun' : '宋体',
  6346. 'NSimSun' : '新宋体',
  6347. 'FangSong_GB2312' : '仿宋_GB2312',
  6348. 'KaiTi_GB2312' : '楷体_GB2312',
  6349. 'SimHei' : '黑体',
  6350. 'Microsoft YaHei' : '微软雅黑',
  6351. 'Arial' : 'Arial',
  6352. 'Arial Black' : 'Arial Black',
  6353. 'Times New Roman' : 'Times New Roman',
  6354. 'Courier New' : 'Courier New',
  6355. 'Tahoma' : 'Tahoma',
  6356. 'Verdana' : 'Verdana'
  6357. },
  6358. 'lineheight.lineHeight' : [
  6359. {'1' : '单倍行距'},
  6360. {'1.5' : '1.5倍行距'},
  6361. {'1.75' : '1.75倍行距'},
  6362. {'2' : '2倍行距'},
  6363. {'2.5' : '2.5倍行距'},
  6364. {'3' : '3倍行距'}
  6365. ],
  6366. 'template.selectTemplate' : '可选模板',
  6367. 'template.replaceContent' : '替换当前内容',
  6368. 'template.fileList' : {
  6369. '1.html' : '图片和文字',
  6370. '2.html' : '表格',
  6371. '3.html' : '项目编号'
  6372. }
  6373. }, 'zh-CN');
  6374. KindEditor.options.langType = 'zh-CN';
  6375. /*******************************************************************************
  6376. * KindEditor - WYSIWYG HTML Editor for Internet
  6377. * Copyright (C) 2006-2011 kindsoft.net
  6378. *
  6379. * @author Roddy <luolonghao@gmail.com>
  6380. * @site http://www.kindsoft.net/
  6381. * @licence http://www.kindsoft.net/license.php
  6382. *******************************************************************************/
  6383. KindEditor.plugin('anchor', function(K) {
  6384. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6385. self.plugin.anchor = {
  6386. edit : function() {
  6387. var html = ['<div style="padding:20px;">',
  6388. '<div class="ke-dialog-row">',
  6389. '<label for="keName">' + lang.name + '</label>',
  6390. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6391. '</div>',
  6392. '</div>'].join('');
  6393. var dialog = self.createDialog({
  6394. name : name,
  6395. width : 300,
  6396. title : self.lang(name),
  6397. body : html,
  6398. yesBtn : {
  6399. name : self.lang('yes'),
  6400. click : function(e) {
  6401. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6402. }
  6403. }
  6404. });
  6405. var div = dialog.div,
  6406. nameBox = K('input[name="name"]', div);
  6407. var img = self.plugin.getSelectedAnchor();
  6408. if (img) {
  6409. nameBox.val(unescape(img.attr('data-ke-name')));
  6410. }
  6411. nameBox[0].focus();
  6412. nameBox[0].select();
  6413. },
  6414. 'delete' : function() {
  6415. self.plugin.getSelectedAnchor().remove();
  6416. }
  6417. };
  6418. self.clickToolbar(name, self.plugin.anchor.edit);
  6419. });
  6420. /*******************************************************************************
  6421. * KindEditor - WYSIWYG HTML Editor for Internet
  6422. * Copyright (C) 2006-2011 kindsoft.net
  6423. *
  6424. * @author Roddy <luolonghao@gmail.com>
  6425. * @site http://www.kindsoft.net/
  6426. * @licence http://www.kindsoft.net/license.php
  6427. *******************************************************************************/
  6428. KindEditor.plugin('autoheight', function(K) {
  6429. var self = this;
  6430. if (!self.autoHeightMode) {
  6431. return;
  6432. }
  6433. var minHeight;
  6434. function hideScroll() {
  6435. var edit = self.edit;
  6436. var body = edit.doc.body;
  6437. edit.iframe[0].scroll = 'no';
  6438. body.style.overflowY = 'hidden';
  6439. }
  6440. function resetHeight() {
  6441. if(self.fullscreenMode){
  6442. return;
  6443. }
  6444. var edit = self.edit;
  6445. var body = edit.doc.body;
  6446. edit.iframe.height(minHeight);
  6447. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6448. }
  6449. function init() {
  6450. minHeight = K.removeUnit(self.height);
  6451. self.edit.afterChange(resetHeight);
  6452. if(!self.fullscreenMode){
  6453. hideScroll();
  6454. }
  6455. resetHeight();
  6456. }
  6457. if (self.isCreated) {
  6458. init();
  6459. } else {
  6460. self.afterCreate(init);
  6461. }
  6462. });
  6463. /*
  6464. * 如何实现真正的自动高度?
  6465. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6466. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6467. * 由此就实现了真正的自动高度
  6468. * 测试:chrome、firefox、IE9、IE8
  6469. * */
  6470. /*******************************************************************************
  6471. * KindEditor - WYSIWYG HTML Editor for Internet
  6472. * Copyright (C) 2006-2011 kindsoft.net
  6473. *
  6474. * @author Roddy <luolonghao@gmail.com>
  6475. * @site http://www.kindsoft.net/
  6476. * @licence http://www.kindsoft.net/license.php
  6477. *******************************************************************************/
  6478. KindEditor.plugin('baidumap', function(K) {
  6479. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6480. var mapWidth = K.undef(self.mapWidth, 558);
  6481. var mapHeight = K.undef(self.mapHeight, 360);
  6482. self.clickToolbar(name, function() {
  6483. var html = ['<div style="padding:10px 20px;">',
  6484. '<div class="ke-header">',
  6485. '<div class="ke-left">',
  6486. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6487. '<span class="ke-button-common ke-button-outer">',
  6488. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6489. '</span>',
  6490. '</div>',
  6491. '<div class="ke-right">',
  6492. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6493. '</div>',
  6494. '<div class="ke-clearfix"></div>',
  6495. '</div>',
  6496. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6497. '</div>'].join('');
  6498. var dialog = self.createDialog({
  6499. name : name,
  6500. width : mapWidth + 42,
  6501. title : self.lang(name),
  6502. body : html,
  6503. yesBtn : {
  6504. name : self.lang('yes'),
  6505. click : function(e) {
  6506. var map = win.map;
  6507. var centerObj = map.getCenter();
  6508. var center = centerObj.lng + ',' + centerObj.lat;
  6509. var zoom = map.getZoom();
  6510. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6511. '?center=' + encodeURIComponent(center),
  6512. '&zoom=' + encodeURIComponent(zoom),
  6513. '&width=' + mapWidth,
  6514. '&height=' + mapHeight,
  6515. '&markers=' + encodeURIComponent(center),
  6516. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6517. if (checkbox[0].checked) {
  6518. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6519. } else {
  6520. self.exec('insertimage', url);
  6521. }
  6522. self.hideDialog().focus();
  6523. }
  6524. },
  6525. beforeRemove : function() {
  6526. searchBtn.remove();
  6527. if (doc) {
  6528. doc.write('');
  6529. }
  6530. iframe.remove();
  6531. }
  6532. });
  6533. var div = dialog.div,
  6534. addressBox = K('[name="address"]', div),
  6535. searchBtn = K('[name="searchBtn"]', div),
  6536. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6537. win, doc;
  6538. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6539. function ready() {
  6540. win = iframe[0].contentWindow;
  6541. doc = K.iframeDoc(iframe);
  6542. }
  6543. iframe.bind('load', function() {
  6544. iframe.unbind('load');
  6545. if (K.IE) {
  6546. ready();
  6547. } else {
  6548. setTimeout(ready, 0);
  6549. }
  6550. });
  6551. K('.ke-map', div).replaceWith(iframe);
  6552. searchBtn.click(function() {
  6553. win.search(addressBox.val());
  6554. });
  6555. });
  6556. });
  6557. /*******************************************************************************
  6558. * KindEditor - WYSIWYG HTML Editor for Internet
  6559. * Copyright (C) 2006-2011 kindsoft.net
  6560. *
  6561. * @author Roddy <luolonghao@gmail.com>
  6562. * @site http://www.kindsoft.net/
  6563. * @licence http://www.kindsoft.net/license.php
  6564. *******************************************************************************/
  6565. KindEditor.plugin('map', function(K) {
  6566. var self = this, name = 'map', lang = self.lang(name + '.');
  6567. self.clickToolbar(name, function() {
  6568. var html = ['<div style="padding:10px 20px;">',
  6569. '<div class="ke-dialog-row">',
  6570. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6571. '<span class="ke-button-common ke-button-outer">',
  6572. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6573. '</span>',
  6574. '</div>',
  6575. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6576. '</div>'].join('');
  6577. var dialog = self.createDialog({
  6578. name : name,
  6579. width : 600,
  6580. title : self.lang(name),
  6581. body : html,
  6582. yesBtn : {
  6583. name : self.lang('yes'),
  6584. click : function(e) {
  6585. var geocoder = win.geocoder,
  6586. map = win.map,
  6587. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6588. zoom = map.getZoom(),
  6589. maptype = map.getMapTypeId(),
  6590. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6591. url += '?center=' + encodeURIComponent(center);
  6592. url += '&zoom=' + encodeURIComponent(zoom);
  6593. url += '&size=558x360';
  6594. url += '&maptype=' + encodeURIComponent(maptype);
  6595. url += '&markers=' + encodeURIComponent(center);
  6596. url += '&language=' + self.langType;
  6597. url += '&sensor=false';
  6598. self.exec('insertimage', url).hideDialog().focus();
  6599. }
  6600. },
  6601. beforeRemove : function() {
  6602. searchBtn.remove();
  6603. if (doc) {
  6604. doc.write('');
  6605. }
  6606. iframe.remove();
  6607. }
  6608. });
  6609. var div = dialog.div,
  6610. addressBox = K('[name="address"]', div),
  6611. searchBtn = K('[name="searchBtn"]', div),
  6612. win, doc;
  6613. var iframeHtml = ['<!doctype html><html><head>',
  6614. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6615. '<style>',
  6616. ' html { height: 100% }',
  6617. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6618. ' #map_canvas { height: 100% }',
  6619. '</style>',
  6620. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6621. '<script>',
  6622. 'var map, geocoder;',
  6623. 'function initialize() {',
  6624. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6625. ' var options = {',
  6626. ' zoom: 11,',
  6627. ' center: latlng,',
  6628. ' disableDefaultUI: true,',
  6629. ' panControl: true,',
  6630. ' zoomControl: true,',
  6631. ' mapTypeControl: true,',
  6632. ' scaleControl: true,',
  6633. ' streetViewControl: false,',
  6634. ' overviewMapControl: true,',
  6635. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6636. ' };',
  6637. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6638. ' geocoder = new google.maps.Geocoder();',
  6639. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6640. ' if (status == google.maps.GeocoderStatus.OK) {',
  6641. ' if (results[3]) {',
  6642. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6643. ' }',
  6644. ' }',
  6645. ' });',
  6646. '}',
  6647. 'function search(address) {',
  6648. ' if (!map) return;',
  6649. ' geocoder.geocode({address : address}, function(results, status) {',
  6650. ' if (status == google.maps.GeocoderStatus.OK) {',
  6651. ' map.setZoom(11);',
  6652. ' map.setCenter(results[0].geometry.location);',
  6653. ' var marker = new google.maps.Marker({',
  6654. ' map: map,',
  6655. ' position: results[0].geometry.location',
  6656. ' });',
  6657. ' } else {',
  6658. ' alert("Invalid address: " + address);',
  6659. ' }',
  6660. ' });',
  6661. '}',
  6662. '</script>',
  6663. '</head>',
  6664. '<body onload="initialize();">',
  6665. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6666. '</body></html>'].join('\n');
  6667. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6668. function ready() {
  6669. win = iframe[0].contentWindow;
  6670. doc = K.iframeDoc(iframe);
  6671. }
  6672. iframe.bind('load', function() {
  6673. iframe.unbind('load');
  6674. if (K.IE) {
  6675. ready();
  6676. } else {
  6677. setTimeout(ready, 0);
  6678. }
  6679. });
  6680. K('.ke-map', div).replaceWith(iframe);
  6681. searchBtn.click(function() {
  6682. win.search(addressBox.val());
  6683. });
  6684. });
  6685. });
  6686. /*******************************************************************************
  6687. * KindEditor - WYSIWYG HTML Editor for Internet
  6688. * Copyright (C) 2006-2011 kindsoft.net
  6689. *
  6690. * @author Roddy <luolonghao@gmail.com>
  6691. * @site http://www.kindsoft.net/
  6692. * @licence http://www.kindsoft.net/license.php
  6693. *******************************************************************************/
  6694. KindEditor.plugin('clearhtml', function(K) {
  6695. var self = this, name = 'clearhtml';
  6696. self.clickToolbar(name, function() {
  6697. self.focus();
  6698. var html = self.html();
  6699. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6700. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6701. html = K.formatHtml(html, {
  6702. a : ['href', 'target'],
  6703. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6704. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6705. table : ['border'],
  6706. 'td,th' : ['rowspan', 'colspan'],
  6707. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6708. });
  6709. self.html(html);
  6710. self.cmd.selection(true);
  6711. self.addBookmark();
  6712. });
  6713. });
  6714. /*******************************************************************************
  6715. * KindEditor - WYSIWYG HTML Editor for Internet
  6716. * Copyright (C) 2006-2011 kindsoft.net
  6717. *
  6718. * @author Roddy <luolonghao@gmail.com>
  6719. * @site http://www.kindsoft.net/
  6720. * @licence http://www.kindsoft.net/license.php
  6721. *******************************************************************************/
  6722. KindEditor.plugin('code', function(K) {
  6723. var self = this, name = 'code';
  6724. self.clickToolbar(name, function() {
  6725. var lang = self.lang(name + '.'),
  6726. html = ['<div style="padding:10px 20px;">',
  6727. '<div class="ke-dialog-row">',
  6728. '<select class="ke-code-type">',
  6729. '<option value="js">JavaScript</option>',
  6730. '<option value="html">HTML</option>',
  6731. '<option value="css">CSS</option>',
  6732. '<option value="php">PHP</option>',
  6733. '<option value="pl">Perl</option>',
  6734. '<option value="py">Python</option>',
  6735. '<option value="rb">Ruby</option>',
  6736. '<option value="java">Java</option>',
  6737. '<option value="vb">ASP/VB</option>',
  6738. '<option value="cpp">C/C++</option>',
  6739. '<option value="cs">C#</option>',
  6740. '<option value="xml">XML</option>',
  6741. '<option value="bsh">Shell</option>',
  6742. '<option value="">Other</option>',
  6743. '</select>',
  6744. '</div>',
  6745. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6746. '</div>'].join(''),
  6747. dialog = self.createDialog({
  6748. name : name,
  6749. width : 450,
  6750. title : self.lang(name),
  6751. body : html,
  6752. yesBtn : {
  6753. name : self.lang('yes'),
  6754. click : function(e) {
  6755. var type = K('.ke-code-type', dialog.div).val(),
  6756. code = textarea.val(),
  6757. cls = type === '' ? '' : ' lang-' + type,
  6758. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6759. if (K.trim(code) === '') {
  6760. alert(lang.pleaseInput);
  6761. textarea[0].focus();
  6762. return;
  6763. }
  6764. self.insertHtml(html).hideDialog().focus();
  6765. }
  6766. }
  6767. }),
  6768. textarea = K('textarea', dialog.div);
  6769. textarea[0].focus();
  6770. });
  6771. });
  6772. /*******************************************************************************
  6773. * KindEditor - WYSIWYG HTML Editor for Internet
  6774. * Copyright (C) 2006-2011 kindsoft.net
  6775. *
  6776. * @author Roddy <luolonghao@gmail.com>
  6777. * @site http://www.kindsoft.net/
  6778. * @licence http://www.kindsoft.net/license.php
  6779. *******************************************************************************/
  6780. KindEditor.plugin('emoticons', function(K) {
  6781. var self = this, name = 'emoticons',
  6782. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6783. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6784. currentPageNum = 1;
  6785. self.clickToolbar(name, function() {
  6786. var rows = 5, cols = 9, total = 135, startNum = 0,
  6787. cells = rows * cols, pages = Math.ceil(total / cells),
  6788. colsHalf = Math.floor(cols / 2),
  6789. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6790. elements = [],
  6791. menu = self.createMenu({
  6792. name : name,
  6793. beforeRemove : function() {
  6794. removeEvent();
  6795. }
  6796. });
  6797. menu.div.append(wrapperDiv);
  6798. var previewDiv, previewImg;
  6799. if (allowPreview) {
  6800. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6801. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6802. wrapperDiv.append(previewDiv);
  6803. previewDiv.append(previewImg);
  6804. }
  6805. function bindCellEvent(cell, j, num) {
  6806. if (previewDiv) {
  6807. cell.mouseover(function() {
  6808. if (j > colsHalf) {
  6809. previewDiv.css('left', 0);
  6810. previewDiv.css('right', '');
  6811. } else {
  6812. previewDiv.css('left', '');
  6813. previewDiv.css('right', 0);
  6814. }
  6815. previewImg.attr('src', path + num + '.gif');
  6816. K(this).addClass('ke-on');
  6817. });
  6818. } else {
  6819. cell.mouseover(function() {
  6820. K(this).addClass('ke-on');
  6821. });
  6822. }
  6823. cell.mouseout(function() {
  6824. K(this).removeClass('ke-on');
  6825. });
  6826. cell.click(function(e) {
  6827. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6828. e.stop();
  6829. });
  6830. }
  6831. function createEmoticonsTable(pageNum, parentDiv) {
  6832. var table = document.createElement('table');
  6833. parentDiv.append(table);
  6834. if (previewDiv) {
  6835. K(table).mouseover(function() {
  6836. previewDiv.show('block');
  6837. });
  6838. K(table).mouseout(function() {
  6839. previewDiv.hide();
  6840. });
  6841. elements.push(K(table));
  6842. }
  6843. table.className = 'ke-table';
  6844. table.cellPadding = 0;
  6845. table.cellSpacing = 0;
  6846. table.border = 0;
  6847. var num = (pageNum - 1) * cells + startNum;
  6848. for (var i = 0; i < rows; i++) {
  6849. var row = table.insertRow(i);
  6850. for (var j = 0; j < cols; j++) {
  6851. var cell = K(row.insertCell(j));
  6852. cell.addClass('ke-cell');
  6853. bindCellEvent(cell, j, num);
  6854. var span = K('<span class="ke-img"></span>')
  6855. .css('background-position', '-' + (24 * num) + 'px 0px')
  6856. .css('background-image', 'url(' + path + 'static.gif)');
  6857. cell.append(span);
  6858. elements.push(cell);
  6859. num++;
  6860. }
  6861. }
  6862. return table;
  6863. }
  6864. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6865. function removeEvent() {
  6866. K.each(elements, function() {
  6867. this.unbind();
  6868. });
  6869. }
  6870. var pageDiv;
  6871. function bindPageEvent(el, pageNum) {
  6872. el.click(function(e) {
  6873. removeEvent();
  6874. table.parentNode.removeChild(table);
  6875. pageDiv.remove();
  6876. table = createEmoticonsTable(pageNum, wrapperDiv);
  6877. createPageTable(pageNum);
  6878. currentPageNum = pageNum;
  6879. e.stop();
  6880. });
  6881. }
  6882. function createPageTable(currentPageNum) {
  6883. pageDiv = K('<div class="ke-page"></div>');
  6884. wrapperDiv.append(pageDiv);
  6885. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6886. if (currentPageNum !== pageNum) {
  6887. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6888. bindPageEvent(a, pageNum);
  6889. pageDiv.append(a);
  6890. elements.push(a);
  6891. } else {
  6892. pageDiv.append(K('@[' + pageNum + ']'));
  6893. }
  6894. pageDiv.append(K('@&nbsp;'));
  6895. }
  6896. }
  6897. createPageTable(currentPageNum);
  6898. });
  6899. });
  6900. /*******************************************************************************
  6901. * KindEditor - WYSIWYG HTML Editor for Internet
  6902. * Copyright (C) 2006-2011 kindsoft.net
  6903. *
  6904. * @author Roddy <luolonghao@gmail.com>
  6905. * @site http://www.kindsoft.net/
  6906. * @licence http://www.kindsoft.net/license.php
  6907. *******************************************************************************/
  6908. KindEditor.plugin('filemanager', function(K) {
  6909. var self = this, name = 'filemanager',
  6910. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6911. imgPath = self.pluginsPath + name + '/images/',
  6912. lang = self.lang(name + '.');
  6913. function makeFileTitle(filename, filesize, datetime) {
  6914. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6915. }
  6916. function bindTitle(el, data) {
  6917. if (data.is_dir) {
  6918. el.attr('title', data.filename);
  6919. } else {
  6920. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6921. }
  6922. }
  6923. self.plugin.filemanagerDialog = function(options) {
  6924. var width = K.undef(options.width, 650),
  6925. height = K.undef(options.height, 510),
  6926. dirName = K.undef(options.dirName, ''),
  6927. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6928. clickFn = options.clickFn;
  6929. var html = [
  6930. '<div style="padding:10px 20px;">',
  6931. '<div class="ke-plugin-filemanager-header">',
  6932. '<div class="ke-left">',
  6933. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6934. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6935. '</div>',
  6936. '<div class="ke-right">',
  6937. '标签 <input type="text" style="width:100px;" value="" name="viewTag">',
  6938. '分类 <select class="ke-inline-block" name="viewCate">',
  6939. '',
  6940. '</select> ',
  6941. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6942. '<option value="VIEW">' + lang.viewImage + '</option>',
  6943. '<option value="LIST">' + lang.listImage + '</option>',
  6944. '</select> ',
  6945. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6946. '<option value="NAME">' + lang.fileName + '</option>',
  6947. '<option value="SIZE">' + lang.fileSize + '</option>',
  6948. '<option value="TYPE">' + lang.fileType + '</option>',
  6949. '</select>',
  6950. '</div>',
  6951. '<div class="ke-clearfix"></div>',
  6952. '</div>',
  6953. '<div class="ke-plugin-filemanager-body"></div>',
  6954. '</div>'
  6955. ].join('');
  6956. var dialog = self.createDialog({
  6957. name : name,
  6958. width : width,
  6959. height : height,
  6960. title : self.lang(name),
  6961. body : html
  6962. }),
  6963. div = dialog.div,
  6964. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6965. moveupImg = K('[name="moveupImg"]', div),
  6966. moveupLink = K('[name="moveupLink"]', div),
  6967. viewServerBtn = K('[name="viewServer"]', div),
  6968. viewCateBox = K('[name="viewCate"]', div),
  6969. viewTagBox = K('[name="viewTag"]', div),
  6970. viewTypeBox = K('[name="viewType"]', div),
  6971. orderTypeBox = K('[name="orderType"]', div);
  6972. function reloadPage(path, order, func, cate, tag) {
  6973. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6974. if (cate) {
  6975. param += '&cate=' + cate;
  6976. }
  6977. if (tag) {
  6978. param += '&tag=' + tag;
  6979. }
  6980. dialog.showLoading(self.lang('ajaxLoading'));
  6981. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6982. dialog.hideLoading();
  6983. func(data);
  6984. });
  6985. }
  6986. var elList = [];
  6987. function bindEvent(el, result, data, createFunc) {
  6988. var fileUrl = K.formatUrl(result.current_url + data.file, 'absolute'),
  6989. dirPath = encodeURIComponent(result.current_dir_path + data.path + '/');
  6990. if (data.is_dir) {
  6991. el.click(function(e) {
  6992. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6993. });
  6994. } else if (data.is_photo) {
  6995. el.click(function(e) {
  6996. clickFn.call(this, fileUrl, data.file);
  6997. });
  6998. } else {
  6999. el.click(function(e) {
  7000. clickFn.call(this, fileUrl, data.file);
  7001. });
  7002. }
  7003. elList.push(el);
  7004. }
  7005. function createCommon(result, createFunc) {
  7006. K.each(elList, function() {
  7007. this.unbind();
  7008. });
  7009. moveupLink.unbind();
  7010. viewTypeBox.unbind();
  7011. orderTypeBox.unbind();
  7012. if (result.current_dir_path) {
  7013. moveupLink.click(function(e) {
  7014. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  7015. });
  7016. }
  7017. function changeFunc() {
  7018. if (viewTypeBox.val() == 'VIEW') {
  7019. reloadPage(result.current_dir_path, orderTypeBox.val(), createView, viewCateBox.val(), viewTagBox.val());
  7020. } else {
  7021. reloadPage(result.current_dir_path, orderTypeBox.val(), createList, viewCateBox.val(), viewTagBox.val());
  7022. }
  7023. }
  7024. viewTypeBox.change(changeFunc);
  7025. orderTypeBox.change(changeFunc);
  7026. viewCateBox.change(changeFunc);
  7027. bodyDiv.html('');
  7028. }
  7029. function createList(result) {
  7030. createCommon(result, createList);
  7031. var table = document.createElement('table');
  7032. table.className = 'ke-table';
  7033. table.cellPadding = 0;
  7034. table.cellSpacing = 0;
  7035. table.border = 0;
  7036. bodyDiv.append(table);
  7037. var fileList = result.file_list;
  7038. for (var i = 0, len = fileList.length; i < len; i++) {
  7039. var data = fileList[i], row = K(table.insertRow(i));
  7040. row.mouseover(function(e) {
  7041. K(this).addClass('ke-on');
  7042. })
  7043. .mouseout(function(e) {
  7044. K(this).removeClass('ke-on');
  7045. });
  7046. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  7047. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  7048. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  7049. if (!data.is_dir || data.has_file) {
  7050. row.css('cursor', 'pointer');
  7051. cell0.attr('title', data.filename);
  7052. bindEvent(cell0, result, data, createList);
  7053. } else {
  7054. cell0.attr('title', lang.emptyFolder);
  7055. }
  7056. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  7057. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  7058. }
  7059. }
  7060. function createView(result) {
  7061. createCommon(result, createView);
  7062. var fileList = result.file_list;
  7063. for (var i = 0, len = fileList.length; i < len; i++) {
  7064. var data = fileList[i],
  7065. div = K('<div class="ke-inline-block ke-item"></div>');
  7066. bodyDiv.append(div);
  7067. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7068. .mouseover(function(e) {
  7069. K(this).addClass('ke-on');
  7070. })
  7071. .mouseout(function(e) {
  7072. K(this).removeClass('ke-on');
  7073. });
  7074. div.append(photoDiv);
  7075. var fileUrl = result.current_url + data.file,
  7076. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7077. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7078. if (!data.is_dir || data.has_file) {
  7079. photoDiv.css('cursor', 'pointer');
  7080. bindTitle(photoDiv, data);
  7081. bindEvent(photoDiv, result, data, createView);
  7082. } else {
  7083. photoDiv.attr('title', lang.emptyFolder);
  7084. }
  7085. photoDiv.append(img);
  7086. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7087. }
  7088. }
  7089. viewTypeBox.val(viewType);
  7090. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7091. return dialog;
  7092. }
  7093. });
  7094. /*******************************************************************************
  7095. * KindEditor - WYSIWYG HTML Editor for Internet
  7096. * Copyright (C) 2006-2011 kindsoft.net
  7097. *
  7098. * @author Roddy <luolonghao@gmail.com>
  7099. * @site http://www.kindsoft.net/
  7100. * @licence http://www.kindsoft.net/license.php
  7101. *******************************************************************************/
  7102. KindEditor.plugin('flash', function(K) {
  7103. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7104. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7105. allowFileManager = K.undef(self.allowFileManager, false),
  7106. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7107. extraParams = K.undef(self.extraFileUploadParams, {}),
  7108. filePostName = K.undef(self.filePostName, 'imgFile'),
  7109. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7110. self.plugin.flash = {
  7111. edit : function() {
  7112. var html = [
  7113. '<div style="padding:20px;">',
  7114. '<div class="ke-dialog-row">',
  7115. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7116. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7117. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7118. '<span class="ke-button-common ke-button-outer">',
  7119. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7120. '</span>',
  7121. '</div>',
  7122. '<div class="ke-dialog-row">',
  7123. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7124. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7125. '</div>',
  7126. '<div class="ke-dialog-row">',
  7127. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7128. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7129. '</div>',
  7130. '</div>'
  7131. ].join('');
  7132. var dialog = self.createDialog({
  7133. name : name,
  7134. width : 450,
  7135. title : self.lang(name),
  7136. body : html,
  7137. yesBtn : {
  7138. name : self.lang('yes'),
  7139. click : function(e) {
  7140. var url = K.trim(urlBox.val()),
  7141. width = widthBox.val(),
  7142. height = heightBox.val();
  7143. if (url == 'http://' || K.invalidUrl(url)) {
  7144. alert(self.lang('invalidUrl'));
  7145. urlBox[0].focus();
  7146. return;
  7147. }
  7148. if (!/^\d*$/.test(width)) {
  7149. alert(self.lang('invalidWidth'));
  7150. widthBox[0].focus();
  7151. return;
  7152. }
  7153. if (!/^\d*$/.test(height)) {
  7154. alert(self.lang('invalidHeight'));
  7155. heightBox[0].focus();
  7156. return;
  7157. }
  7158. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7159. src : url,
  7160. type : K.mediaType('.swf'),
  7161. width : width,
  7162. height : height,
  7163. quality : 'high'
  7164. });
  7165. self.insertHtml(html).hideDialog().focus();
  7166. }
  7167. }
  7168. }),
  7169. div = dialog.div,
  7170. urlBox = K('[name="url"]', div),
  7171. viewServerBtn = K('[name="viewServer"]', div),
  7172. widthBox = K('[name="width"]', div),
  7173. heightBox = K('[name="height"]', div);
  7174. urlBox.val('http://');
  7175. if (allowFlashUpload) {
  7176. var uploadbutton = K.uploadbutton({
  7177. button : K('.ke-upload-button', div)[0],
  7178. fieldName : filePostName,
  7179. extraParams : extraParams,
  7180. url : K.addParam(uploadJson, 'dir=flash'),
  7181. afterUpload : function(data) {
  7182. dialog.hideLoading();
  7183. if (data.error === 0) {
  7184. var url = data.url;
  7185. if (formatUploadUrl) {
  7186. url = K.formatUrl(url, 'absolute');
  7187. }
  7188. urlBox.val(url);
  7189. if (self.afterUpload) {
  7190. self.afterUpload.call(self, url, data, name);
  7191. }
  7192. alert(self.lang('uploadSuccess'));
  7193. } else {
  7194. alert(data.message);
  7195. }
  7196. },
  7197. afterError : function(html) {
  7198. dialog.hideLoading();
  7199. self.errorDialog(html);
  7200. }
  7201. });
  7202. uploadbutton.fileBox.change(function(e) {
  7203. dialog.showLoading(self.lang('uploadLoading'));
  7204. uploadbutton.submit();
  7205. });
  7206. } else {
  7207. K('.ke-upload-button', div).hide();
  7208. }
  7209. if (allowFileManager) {
  7210. viewServerBtn.click(function(e) {
  7211. var clickFn = function(url, title, id) {
  7212. K('[name="url"]', div).val(url);
  7213. if (self.afterSelectFile) {
  7214. self.afterSelectFile.call(self, url);
  7215. }
  7216. };
  7217. var cur = K('[name="url"]', div).val();
  7218. editorShowUpload(cur, self.fileManagerJson, 'flash库', clickFn, this);
  7219. /*
  7220. self.loadPlugin('filemanager', function() {
  7221. self.plugin.filemanagerDialog({
  7222. viewType : 'LIST',
  7223. dirName : 'flash',
  7224. clickFn : function(url, title) {
  7225. if (self.dialogs.length > 1) {
  7226. K('[name="url"]', div).val(url);
  7227. if (self.afterSelectFile) {
  7228. self.afterSelectFile.call(self, url);
  7229. }
  7230. self.hideDialog();
  7231. }
  7232. }
  7233. });
  7234. });
  7235. */
  7236. });
  7237. } else {
  7238. viewServerBtn.hide();
  7239. }
  7240. var img = self.plugin.getSelectedFlash();
  7241. if (img) {
  7242. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7243. urlBox.val(attrs.src);
  7244. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7245. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7246. }
  7247. urlBox[0].focus();
  7248. urlBox[0].select();
  7249. },
  7250. 'delete' : function() {
  7251. self.plugin.getSelectedFlash().remove();
  7252. self.addBookmark();
  7253. }
  7254. };
  7255. self.clickToolbar(name, self.plugin.flash.edit);
  7256. });
  7257. /*******************************************************************************
  7258. * KindEditor - WYSIWYG HTML Editor for Internet
  7259. * Copyright (C) 2006-2011 kindsoft.net
  7260. *
  7261. * @author Roddy <luolonghao@gmail.com>
  7262. * @site http://www.kindsoft.net/
  7263. * @licence http://www.kindsoft.net/license.php
  7264. *******************************************************************************/
  7265. KindEditor.plugin('image', function(K) {
  7266. var self = this, name = 'image',
  7267. allowImageUpload = K.undef(self.allowImageUpload, true),
  7268. allowImageRemote = K.undef(self.allowImageRemote, true),
  7269. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7270. allowFileManager = K.undef(self.allowFileManager, false),
  7271. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7272. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7273. imgPath = self.pluginsPath + 'image/images/',
  7274. extraParams = K.undef(self.extraFileUploadParams, {}),
  7275. filePostName = K.undef(self.filePostName, 'imgFile'),
  7276. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7277. lang = self.lang(name + '.');
  7278. self.plugin.imageDialog = function(options) {
  7279. var imageUrl = options.imageUrl,
  7280. imageWidth = K.undef(options.imageWidth, ''),
  7281. imageHeight = K.undef(options.imageHeight, ''),
  7282. imageTitle = K.undef(options.imageTitle, ''),
  7283. imageAlign = K.undef(options.imageAlign, ''),
  7284. showRemote = K.undef(options.showRemote, true),
  7285. showLocal = K.undef(options.showLocal, true),
  7286. tabIndex = K.undef(options.tabIndex, 0),
  7287. clickFn = options.clickFn;
  7288. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7289. var hiddenElements = [];
  7290. for(var k in extraParams){
  7291. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7292. }
  7293. var html = [
  7294. '<div style="padding:20px;">',
  7295. '<div class="tabs"></div>',
  7296. '<div class="tab1" style="display:none;">',
  7297. '<div class="ke-dialog-row">',
  7298. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7299. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7300. '<span class="ke-button-common ke-button-outer">',
  7301. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7302. '</span>',
  7303. '</div>',
  7304. '<div class="ke-dialog-row">',
  7305. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7306. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7307. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7308. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7309. '</div>',
  7310. '<div class="ke-dialog-row">',
  7311. '<label style="width:60px;">' + lang.align + '</label>',
  7312. '<input type="radio" name="align" class="ke-inline-block" value="" checked="checked" /> <img name="defaultImg" src="' + imgPath + 'align_top.gif" width="23" height="25" alt="" />',
  7313. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7314. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7315. '</div>',
  7316. '<div class="ke-dialog-row">',
  7317. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7318. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7319. '</div>',
  7320. '</div>',
  7321. '<div class="tab2" style="display:none;">',
  7322. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7323. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7324. '<div class="ke-dialog-row">',
  7325. hiddenElements.join(''),
  7326. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7327. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7328. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7329. '</div>',
  7330. '</form>',
  7331. '</div>',
  7332. '</div>'
  7333. ].join('');
  7334. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7335. dialogHeight = showLocal && showRemote ? 300 : 250;
  7336. var dialog = self.createDialog({
  7337. name : name,
  7338. width : dialogWidth,
  7339. height : dialogHeight,
  7340. title : self.lang(name),
  7341. body : html,
  7342. yesBtn : {
  7343. name : self.lang('yes'),
  7344. click : function(e) {
  7345. if (dialog.isLoading) {
  7346. return;
  7347. }
  7348. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7349. if (uploadbutton.fileBox.val() == '') {
  7350. alert(self.lang('pleaseSelectFile'));
  7351. return;
  7352. }
  7353. dialog.showLoading(self.lang('uploadLoading'));
  7354. uploadbutton.submit();
  7355. localUrlBox.val('');
  7356. return;
  7357. }
  7358. var url = K.trim(urlBox.val()),
  7359. width = widthBox.val(),
  7360. height = heightBox.val(),
  7361. title = titleBox.val(),
  7362. align = '';
  7363. alignBox.each(function() {
  7364. if (this.checked) {
  7365. align = this.value;
  7366. return false;
  7367. }
  7368. });
  7369. if (url == 'http://' || K.invalidUrl(url)) {
  7370. alert(self.lang('invalidUrl'));
  7371. urlBox[0].focus();
  7372. return;
  7373. }
  7374. if (!/^\d*$/.test(width)) {
  7375. alert(self.lang('invalidWidth'));
  7376. widthBox[0].focus();
  7377. return;
  7378. }
  7379. if (!/^\d*$/.test(height)) {
  7380. alert(self.lang('invalidHeight'));
  7381. heightBox[0].focus();
  7382. return;
  7383. }
  7384. clickFn.call(self, url, title, width, height, 0, align);
  7385. }
  7386. },
  7387. beforeRemove : function() {
  7388. viewServerBtn.unbind();
  7389. widthBox.unbind();
  7390. heightBox.unbind();
  7391. refreshBtn.unbind();
  7392. }
  7393. }),
  7394. div = dialog.div;
  7395. var urlBox = K('[name="url"]', div),
  7396. localUrlBox = K('[name="localUrl"]', div),
  7397. viewServerBtn = K('[name="viewServer"]', div),
  7398. widthBox = K('.tab1 [name="width"]', div),
  7399. heightBox = K('.tab1 [name="height"]', div),
  7400. refreshBtn = K('.ke-refresh-btn', div),
  7401. titleBox = K('.tab1 [name="title"]', div),
  7402. alignBox = K('.tab1 [name="align"]', div);
  7403. var tabs;
  7404. if (showRemote && showLocal) {
  7405. tabs = K.tabs({
  7406. src : K('.tabs', div),
  7407. afterSelect : function(i) {}
  7408. });
  7409. tabs.add({
  7410. title : lang.remoteImage,
  7411. panel : K('.tab1', div)
  7412. });
  7413. tabs.add({
  7414. title : lang.localImage,
  7415. panel : K('.tab2', div)
  7416. });
  7417. tabs.select(1);
  7418. } else if (showRemote) {
  7419. K('.tab1', div).show();
  7420. } else if (showLocal) {
  7421. K('.tab2', div).show();
  7422. }
  7423. var uploadbutton = K.uploadbutton({
  7424. button : K('.ke-upload-button', div)[0],
  7425. fieldName : filePostName,
  7426. form : K('.ke-form', div),
  7427. target : target,
  7428. width: 60,
  7429. afterUpload : function(data) {
  7430. dialog.hideLoading();
  7431. if (data.error === 0) {
  7432. var url = data.url;
  7433. if (formatUploadUrl) {
  7434. url = K.formatUrl(url, 'absolute');
  7435. }
  7436. if (self.afterUpload) {
  7437. self.afterUpload.call(self, url, data, name);
  7438. }
  7439. if (!fillDescAfterUploadImage) {
  7440. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7441. } else {
  7442. K(".ke-dialog-row #remoteUrl", div).val(url);
  7443. K(".ke-tabs-li", div)[0].click();
  7444. K(".ke-refresh-btn", div).click();
  7445. }
  7446. } else {
  7447. alert(data.message);
  7448. }
  7449. },
  7450. afterError : function(html) {
  7451. dialog.hideLoading();
  7452. self.errorDialog(html);
  7453. }
  7454. });
  7455. uploadbutton.fileBox.change(function(e) {
  7456. localUrlBox.val(uploadbutton.fileBox.val());
  7457. });
  7458. if (allowFileManager) {
  7459. viewServerBtn.click(function(e) {
  7460. //clickFn.call(this, fileUrl, data.file);
  7461. var clickFn = function(url, title, id) {
  7462. K('[name="url"]', div).val(url);
  7463. if (self.afterSelectFile) {
  7464. self.afterSelectFile.call(self, url);
  7465. }
  7466. };
  7467. var cur = K('[name="url"]', div).val();
  7468. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  7469. /*
  7470. self.loadPlugin('filemanager', function() {
  7471. self.plugin.filemanagerDialog({
  7472. viewType : 'VIEW',
  7473. dirName : 'image',
  7474. clickFn : function(url, title) {
  7475. if (self.dialogs.length > 1) {
  7476. K('[name="url"]', div).val(url);
  7477. if (self.afterSelectFile) {
  7478. self.afterSelectFile.call(self, url);
  7479. }
  7480. self.hideDialog();
  7481. }
  7482. }
  7483. });
  7484. });
  7485. */
  7486. });
  7487. } else {
  7488. viewServerBtn.hide();
  7489. }
  7490. var originalWidth = 0, originalHeight = 0;
  7491. function setSize(width, height) {
  7492. widthBox.val(width);
  7493. heightBox.val(height);
  7494. originalWidth = width;
  7495. originalHeight = height;
  7496. }
  7497. refreshBtn.click(function(e) {
  7498. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7499. position : 'absolute',
  7500. visibility : 'hidden',
  7501. top : 0,
  7502. left : '-1000px'
  7503. });
  7504. tempImg.bind('load', function() {
  7505. setSize(tempImg.width(), tempImg.height());
  7506. tempImg.remove();
  7507. });
  7508. K(document.body).append(tempImg);
  7509. });
  7510. widthBox.change(function(e) {
  7511. if (originalWidth > 0) {
  7512. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7513. }
  7514. });
  7515. heightBox.change(function(e) {
  7516. if (originalHeight > 0) {
  7517. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7518. }
  7519. });
  7520. urlBox.val(options.imageUrl);
  7521. setSize(options.imageWidth, options.imageHeight);
  7522. titleBox.val(options.imageTitle);
  7523. alignBox.each(function() {
  7524. if (this.value === options.imageAlign) {
  7525. this.checked = true;
  7526. return false;
  7527. }
  7528. });
  7529. if (showRemote && tabIndex === 0) {
  7530. urlBox[0].focus();
  7531. urlBox[0].select();
  7532. }
  7533. return dialog;
  7534. };
  7535. self.plugin.image = {
  7536. edit : function() {
  7537. var img = self.plugin.getSelectedImage();
  7538. self.plugin.imageDialog({
  7539. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7540. imageWidth : img ? img.width() : '',
  7541. imageHeight : img ? img.height() : '',
  7542. imageTitle : img ? img.attr('title') : '',
  7543. imageAlign : img ? img.attr('align') : '',
  7544. showRemote : allowImageRemote,
  7545. showLocal : allowImageUpload,
  7546. tabIndex: img ? 0 : imageTabIndex,
  7547. clickFn : function(url, title, width, height, border, align) {
  7548. if (img) {
  7549. img.attr('src', url);
  7550. img.attr('data-ke-src', url);
  7551. img.attr('width', width);
  7552. img.attr('height', height);
  7553. img.attr('title', title);
  7554. img.attr('align', align);
  7555. img.attr('alt', title);
  7556. } else {
  7557. self.exec('insertimage', url, title, width, height, border, align);
  7558. }
  7559. setTimeout(function() {
  7560. self.hideDialog().focus();
  7561. }, 0);
  7562. }
  7563. });
  7564. },
  7565. 'delete' : function() {
  7566. var target = self.plugin.getSelectedImage();
  7567. if (target.parent().name == 'a') {
  7568. target = target.parent();
  7569. }
  7570. target.remove();
  7571. self.addBookmark();
  7572. }
  7573. };
  7574. self.clickToolbar(name, self.plugin.image.edit);
  7575. });
  7576. /*******************************************************************************
  7577. * KindEditor - WYSIWYG HTML Editor for Internet
  7578. * Copyright (C) 2006-2011 kindsoft.net
  7579. *
  7580. * @author Roddy <luolonghao@gmail.com>
  7581. * @site http://www.kindsoft.net/
  7582. * @licence http://www.kindsoft.net/license.php
  7583. *******************************************************************************/
  7584. KindEditor.plugin('insertfile', function(K) {
  7585. var self = this, name = 'insertfile',
  7586. allowFileUpload = K.undef(self.allowFileUpload, true),
  7587. allowFileManager = K.undef(self.allowFileManager, false),
  7588. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7589. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7590. extraParams = K.undef(self.extraFileUploadParams, {}),
  7591. filePostName = K.undef(self.filePostName, 'imgFile'),
  7592. lang = self.lang(name + '.');
  7593. self.plugin.fileDialog = function(options) {
  7594. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7595. fileTitle = K.undef(options.fileTitle, ''),
  7596. clickFn = options.clickFn;
  7597. var html = [
  7598. '<div style="padding:20px;">',
  7599. '<div class="ke-dialog-row">',
  7600. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7601. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7602. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7603. '<span class="ke-button-common ke-button-outer">',
  7604. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7605. '</span>',
  7606. '</div>',
  7607. '<div class="ke-dialog-row">',
  7608. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7609. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7610. '</div>',
  7611. '</form>',
  7612. '</div>'
  7613. ].join('');
  7614. var dialog = self.createDialog({
  7615. name : name,
  7616. width : 450,
  7617. title : self.lang(name),
  7618. body : html,
  7619. yesBtn : {
  7620. name : self.lang('yes'),
  7621. click : function(e) {
  7622. var url = K.trim(urlBox.val()),
  7623. title = titleBox.val();
  7624. if (url == 'http://' || K.invalidUrl(url)) {
  7625. alert(self.lang('invalidUrl'));
  7626. urlBox[0].focus();
  7627. return;
  7628. }
  7629. if (K.trim(title) === '') {
  7630. title = url;
  7631. }
  7632. clickFn.call(self, url, title);
  7633. }
  7634. }
  7635. }),
  7636. div = dialog.div;
  7637. var urlBox = K('[name="url"]', div),
  7638. viewServerBtn = K('[name="viewServer"]', div),
  7639. titleBox = K('[name="title"]', div);
  7640. if (allowFileUpload) {
  7641. var uploadbutton = K.uploadbutton({
  7642. button : K('.ke-upload-button', div)[0],
  7643. fieldName : filePostName,
  7644. url : K.addParam(uploadJson, 'dir=file'),
  7645. extraParams : extraParams,
  7646. afterUpload : function(data) {
  7647. dialog.hideLoading();
  7648. if (data.error === 0) {
  7649. var url = data.url;
  7650. if (formatUploadUrl) {
  7651. url = K.formatUrl(url, 'absolute');
  7652. }
  7653. urlBox.val(url);
  7654. if (self.afterUpload) {
  7655. self.afterUpload.call(self, url, data, name);
  7656. }
  7657. alert(self.lang('uploadSuccess'));
  7658. } else {
  7659. alert(data.message);
  7660. }
  7661. },
  7662. afterError : function(html) {
  7663. dialog.hideLoading();
  7664. self.errorDialog(html);
  7665. }
  7666. });
  7667. uploadbutton.fileBox.change(function(e) {
  7668. dialog.showLoading(self.lang('uploadLoading'));
  7669. uploadbutton.submit();
  7670. });
  7671. } else {
  7672. K('.ke-upload-button', div).hide();
  7673. }
  7674. if (allowFileManager) {
  7675. viewServerBtn.click(function(e) {
  7676. var clickFn = function(url, title, id) {
  7677. K('[name="url"]', div).val(url);
  7678. if (self.afterSelectFile) {
  7679. self.afterSelectFile.call(self, url);
  7680. }
  7681. };
  7682. var cur = K('[name="url"]', div).val();
  7683. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '文件库', clickFn, this);
  7684. /*
  7685. self.loadPlugin('filemanager', function() {
  7686. self.plugin.filemanagerDialog({
  7687. viewType : 'LIST',
  7688. dirName : 'file',
  7689. clickFn : function(url, title) {
  7690. if (self.dialogs.length > 1) {
  7691. self.hideDialog();
  7692. }
  7693. }
  7694. });
  7695. });
  7696. */
  7697. });
  7698. } else {
  7699. viewServerBtn.hide();
  7700. }
  7701. urlBox.val(fileUrl);
  7702. titleBox.val(fileTitle);
  7703. urlBox[0].focus();
  7704. urlBox[0].select();
  7705. };
  7706. self.clickToolbar(name, function() {
  7707. self.plugin.fileDialog({
  7708. clickFn : function(url, title) {
  7709. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7710. self.insertHtml(html).hideDialog().focus();
  7711. }
  7712. });
  7713. });
  7714. });
  7715. /*******************************************************************************
  7716. * KindEditor - WYSIWYG HTML Editor for Internet
  7717. * Copyright (C) 2006-2011 kindsoft.net
  7718. *
  7719. * @author Roddy <luolonghao@gmail.com>
  7720. * @site http://www.kindsoft.net/
  7721. * @licence http://www.kindsoft.net/license.php
  7722. *******************************************************************************/
  7723. KindEditor.plugin('lineheight', function(K) {
  7724. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7725. self.clickToolbar(name, function() {
  7726. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7727. if (commonNode) {
  7728. curVal = commonNode.css('line-height');
  7729. }
  7730. var menu = self.createMenu({
  7731. name : name,
  7732. width : 150
  7733. });
  7734. K.each(lang.lineHeight, function(i, row) {
  7735. K.each(row, function(key, val) {
  7736. menu.addItem({
  7737. title : val,
  7738. checked : curVal === key,
  7739. click : function() {
  7740. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7741. span : '.line-height=' + key
  7742. });
  7743. self.updateState();
  7744. self.addBookmark();
  7745. self.hideMenu();
  7746. }
  7747. });
  7748. });
  7749. });
  7750. });
  7751. });
  7752. /*******************************************************************************
  7753. * KindEditor - WYSIWYG HTML Editor for Internet
  7754. * Copyright (C) 2006-2011 kindsoft.net
  7755. *
  7756. * @author Roddy <luolonghao@gmail.com>
  7757. * @site http://www.kindsoft.net/
  7758. * @licence http://www.kindsoft.net/license.php
  7759. *******************************************************************************/
  7760. KindEditor.plugin('link', function(K) {
  7761. var self = this, name = 'link';
  7762. self.plugin.link = {
  7763. edit : function() {
  7764. var lang = self.lang(name + '.'),
  7765. html = '<div style="padding:20px;">' +
  7766. '<div class="ke-dialog-row">' +
  7767. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7768. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7769. '<div class="ke-dialog-row"">' +
  7770. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7771. '<select id="keType" name="type"></select>' +
  7772. '</div>' +
  7773. '</div>',
  7774. dialog = self.createDialog({
  7775. name : name,
  7776. width : 450,
  7777. title : self.lang(name),
  7778. body : html,
  7779. yesBtn : {
  7780. name : self.lang('yes'),
  7781. click : function(e) {
  7782. var url = K.trim(urlBox.val());
  7783. if (url == 'http://' || K.invalidUrl(url)) {
  7784. alert(self.lang('invalidUrl'));
  7785. urlBox[0].focus();
  7786. return;
  7787. }
  7788. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7789. }
  7790. }
  7791. }),
  7792. div = dialog.div,
  7793. urlBox = K('input[name="url"]', div),
  7794. typeBox = K('select[name="type"]', div);
  7795. urlBox.val('http://');
  7796. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7797. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7798. self.cmd.selection();
  7799. var a = self.plugin.getSelectedLink();
  7800. if (a) {
  7801. self.cmd.range.selectNode(a[0]);
  7802. //self.cmd.select();
  7803. urlBox.val(a.attr('data-ke-src'));
  7804. typeBox.val(a.attr('target'));
  7805. }
  7806. urlBox[0].focus();
  7807. urlBox[0].select();
  7808. },
  7809. 'delete' : function() {
  7810. self.exec('unlink', null);
  7811. }
  7812. };
  7813. self.clickToolbar(name, self.plugin.link.edit);
  7814. });
  7815. /*******************************************************************************
  7816. * KindEditor - WYSIWYG HTML Editor for Internet
  7817. * Copyright (C) 2006-2011 kindsoft.net
  7818. *
  7819. * @author Roddy <luolonghao@gmail.com>
  7820. * @site http://www.kindsoft.net/
  7821. * @licence http://www.kindsoft.net/license.php
  7822. *******************************************************************************/
  7823. KindEditor.plugin('media', function(K) {
  7824. var self = this, name = 'media', lang = self.lang(name + '.'),
  7825. allowFileUpload = K.undef(self.allowFileUpload, true),
  7826. allowFileManager = K.undef(self.allowFileManager, false),
  7827. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7828. allowFileManager = K.undef(self.allowFileManager, false),
  7829. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7830. extraParams = K.undef(self.extraFileUploadParams, {}),
  7831. uploadCoverJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7832. filePostName = K.undef(self.filePostName, 'imgFile'),
  7833. uploadJson = K.undef(self.uploadMediaJson, self.basePath + 'php/upload_json.php');
  7834. if (self.uploadYunJson && self.uploadYunJson.domain) {
  7835. uploadJson = self.uploadYunJson.domain;
  7836. extraParams.token = self.uploadYunJson.token;
  7837. extraParams.key = self.uploadYunJson.path;
  7838. }
  7839. self.plugin.media = {
  7840. edit : function() {
  7841. var html = [
  7842. '<div style="padding:20px;">',
  7843. '<div class="ke-dialog-row">',
  7844. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7845. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7846. '<input type="button" class="ke-upload-button ke-upload-button-media" value="' + lang.upload + '" /> &nbsp;',
  7847. '<span class="ke-button-common ke-button-outer">',
  7848. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7849. '</span>',
  7850. '</div>',
  7851. '<div class="ke-dialog-row">',
  7852. '<label for="keUrl" style="width:60px;">封面</label>',
  7853. '<input class="ke-input-text" type="text" id="keUrlCover" name="cover_url" value="" style="width:160px;" /> &nbsp;',
  7854. '<input type="button" class="ke-upload-button ke-upload-button-cover" value="' + lang.upload + '" /> &nbsp;',
  7855. '<span class="ke-button-common ke-button-outer">',
  7856. '<input type="button" class="ke-button-common ke-button" name="viewCoverServer" value="' + lang.viewServer + '" />',
  7857. '</span>',
  7858. '</div>',
  7859. '<div class="ke-dialog-row">',
  7860. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7861. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="450" maxlength="4" />',
  7862. '</div>',
  7863. '<div class="ke-dialog-row">',
  7864. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7865. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="100" maxlength="4" />',
  7866. '</div>',
  7867. '<div class="ke-dialog-row">',
  7868. '<label for="keAutostart">' + lang.autostart + '</label>',
  7869. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7870. '</div>',
  7871. '</div>'
  7872. ].join('');
  7873. var dialog = self.createDialog({
  7874. name : name,
  7875. width : 450,
  7876. height : 230,
  7877. title : self.lang(name),
  7878. body : html,
  7879. yesBtn : {
  7880. name : self.lang('yes'),
  7881. click : function(e) {
  7882. var url = K.trim(urlBox.val()),
  7883. width = widthBox.val(),
  7884. height = heightBox.val();
  7885. if (url == 'http://' || K.invalidUrl(url)) {
  7886. alert(self.lang('invalidUrl'));
  7887. urlBox[0].focus();
  7888. return;
  7889. }
  7890. if (!/^\d*$/.test(width)) {
  7891. alert(self.lang('invalidWidth'));
  7892. widthBox[0].focus();
  7893. return;
  7894. }
  7895. if (!/^\d*$/.test(height)) {
  7896. alert(self.lang('invalidHeight'));
  7897. heightBox[0].focus();
  7898. return;
  7899. }
  7900. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7901. src : url,
  7902. type : K.mediaType(url),
  7903. width : width,
  7904. height : height,
  7905. autostart : autostartBox[0].checked ? 'true' : 'false',
  7906. loop : 'true'
  7907. });
  7908. self.insertHtml(html).hideDialog().focus();
  7909. }
  7910. }
  7911. }),
  7912. div = dialog.div,
  7913. coverUrlBox = K('[name="cover_url"]', div),
  7914. viewCoverServerBtn = K('[name="viewCoverServer"]', div),
  7915. urlBox = K('[name="url"]', div),
  7916. viewServerBtn = K('[name="viewServer"]', div),
  7917. widthBox = K('[name="width"]', div),
  7918. heightBox = K('[name="height"]', div),
  7919. autostartBox = K('[name="autostart"]', div);
  7920. urlBox.val('http://');
  7921. coverUrlBox.val('http://');
  7922. if (allowMediaUpload) {
  7923. var uploadbutton = K.uploadbutton({
  7924. button : K('.ke-upload-button-media', div)[0],
  7925. fieldName : filePostName,
  7926. extraParams : extraParams,
  7927. url : K.addParam(uploadJson, 'dir=media'),
  7928. afterUpload : function(data) {
  7929. console.info(data);
  7930. dialog.hideLoading();
  7931. if (data.error === 0) {
  7932. var url = data.url;
  7933. if (formatUploadUrl) {
  7934. url = K.formatUrl(url, 'absolute');
  7935. }
  7936. urlBox.val(url);
  7937. if (self.afterUpload) {
  7938. self.afterUpload.call(self, url, data, name);
  7939. }
  7940. alert(self.lang('uploadSuccess'));
  7941. } else {
  7942. alert(data.message);
  7943. }
  7944. },
  7945. afterError : function(html) {
  7946. dialog.hideLoading();
  7947. self.errorDialog(html);
  7948. }
  7949. });
  7950. uploadbutton.fileBox.change(function(e) {
  7951. dialog.showLoading(self.lang('uploadLoading'));
  7952. uploadbutton.submit(this);
  7953. });
  7954. } else {
  7955. K('.ke-upload-button-media', div).hide();
  7956. }
  7957. if (allowFileUpload) {
  7958. var uploadbuttonCover = K.uploadbutton({
  7959. button : K('.ke-upload-button-cover', div)[0],
  7960. fieldName : filePostName,
  7961. url : K.addParam(uploadCoverJson, 'dir=file'),
  7962. extraParams : extraParams,
  7963. afterUpload : function(data) {
  7964. dialog.hideLoading();
  7965. if (data.error === 0) {
  7966. var url = data.url;
  7967. if (formatUploadUrl) {
  7968. url = K.formatUrl(url, 'absolute');
  7969. }
  7970. coverUrlBox.val(url);
  7971. if (self.afterUpload) {
  7972. self.afterUpload.call(self, url, data, name);
  7973. }
  7974. alert(self.lang('uploadSuccess'));
  7975. } else {
  7976. alert(data.message);
  7977. }
  7978. },
  7979. afterError : function(html) {
  7980. dialog.hideLoading();
  7981. self.errorDialog(html);
  7982. }
  7983. });
  7984. uploadbuttonCover.fileBox.change(function(e) {
  7985. dialog.showLoading(self.lang('uploadLoading'));
  7986. uploadbutton.submit();
  7987. });
  7988. } else {
  7989. K('.ke-upload-button-cover', div).hide();
  7990. }
  7991. if (allowFileManager) {
  7992. viewServerBtn.click(function(e) {
  7993. var clickFn = function(url, title, id) {
  7994. K('[name="url"]', div).val(url);
  7995. if (self.afterSelectFile) {
  7996. self.afterSelectFile.call(self, url);
  7997. }
  7998. };
  7999. var cur = K('[name="url"]', div).val();
  8000. editorShowUpload(cur, self.fileManagerJson, '音视频库', clickFn, this);
  8001. /*
  8002. self.loadPlugin('filemanager', function() {
  8003. self.plugin.filemanagerDialog({
  8004. viewType : 'LIST',
  8005. dirName : 'media',
  8006. clickFn : function(url, title) {
  8007. if (self.dialogs.length > 1) {
  8008. K('[name="url"]', div).val(url);
  8009. if (self.afterSelectFile) {
  8010. self.afterSelectFile.call(self, url);
  8011. }
  8012. self.hideDialog();
  8013. }
  8014. }
  8015. });
  8016. });
  8017. */
  8018. });
  8019. viewCoverServerBtn.click(function(e) {
  8020. var clickFn = function(url, title, id) {
  8021. K('[name="cover_url"]', div).val(url);
  8022. if (self.afterSelectFile) {
  8023. self.afterSelectFile.call(self, url);
  8024. }
  8025. };
  8026. var cur = K('[name="cover_url"]', div).val();
  8027. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  8028. /*
  8029. self.loadPlugin('filemanager', function() {
  8030. self.plugin.filemanagerDialog({
  8031. viewType : 'LIST',
  8032. dirName : 'file',
  8033. clickFn : function(url, title) {
  8034. if (self.dialogs.length > 1) {
  8035. self.hideDialog();
  8036. }
  8037. }
  8038. });
  8039. });
  8040. */
  8041. });
  8042. } else {
  8043. viewServerBtn.hide();
  8044. viewCoverServerBtn.hide();
  8045. }
  8046. var img = self.plugin.getSelectedMedia();
  8047. if (img) {
  8048. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  8049. urlBox.val(attrs.src);
  8050. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  8051. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  8052. autostartBox[0].checked = (attrs.autostart === 'true');
  8053. }
  8054. urlBox[0].focus();
  8055. urlBox[0].select();
  8056. },
  8057. 'delete' : function() {
  8058. self.plugin.getSelectedMedia().remove();
  8059. self.addBookmark();
  8060. }
  8061. };
  8062. self.clickToolbar(name, self.plugin.media.edit);
  8063. });
  8064. /*******************************************************************************
  8065. * KindEditor - WYSIWYG HTML Editor for Internet
  8066. * Copyright (C) 2006-2011 kindsoft.net
  8067. *
  8068. * @author Roddy <luolonghao@gmail.com>
  8069. * @site http://www.kindsoft.net/
  8070. * @licence http://www.kindsoft.net/license.php
  8071. *******************************************************************************/
  8072. (function(K) {
  8073. function KSWFUpload(options) {
  8074. this.init(options);
  8075. }
  8076. K.extend(KSWFUpload, {
  8077. init : function(options) {
  8078. var self = this;
  8079. options.afterError = options.afterError || function(str) {
  8080. alert(str);
  8081. };
  8082. self.options = options;
  8083. self.progressbars = {};
  8084. self.div = K(options.container).html([
  8085. '<div class="ke-swfupload">',
  8086. '<div class="ke-swfupload-top">',
  8087. '<div class="ke-inline-block ke-swfupload-button">',
  8088. '<input type="button" value="Browse" />',
  8089. '</div>',
  8090. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  8091. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  8092. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  8093. '</span>',
  8094. '</div>',
  8095. '<div class="ke-swfupload-body"></div>',
  8096. '</div>'
  8097. ].join(''));
  8098. self.bodyDiv = K('.ke-swfupload-body', self.div);
  8099. function showError(itemDiv, msg) {
  8100. K('.ke-status > div', itemDiv).hide();
  8101. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  8102. }
  8103. var settings = {
  8104. debug : false,
  8105. upload_url : options.uploadUrl,
  8106. flash_url : options.flashUrl,
  8107. file_post_name : options.filePostName,
  8108. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  8109. button_image_url: options.buttonImageUrl,
  8110. button_width: options.buttonWidth,
  8111. button_height: options.buttonHeight,
  8112. button_cursor : SWFUpload.CURSOR.HAND,
  8113. file_types : options.fileTypes,
  8114. file_types_description : options.fileTypesDesc,
  8115. file_upload_limit : options.fileUploadLimit,
  8116. file_size_limit : options.fileSizeLimit,
  8117. post_params : options.postParams,
  8118. file_queued_handler : function(file) {
  8119. file.url = self.options.fileIconUrl;
  8120. self.appendFile(file);
  8121. },
  8122. file_queue_error_handler : function(file, errorCode, message) {
  8123. var errorName = '';
  8124. switch (errorCode) {
  8125. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  8126. errorName = options.queueLimitExceeded;
  8127. break;
  8128. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  8129. errorName = options.fileExceedsSizeLimit;
  8130. break;
  8131. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  8132. errorName = options.zeroByteFile;
  8133. break;
  8134. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  8135. errorName = options.invalidFiletype;
  8136. break;
  8137. default:
  8138. errorName = options.unknownError;
  8139. break;
  8140. }
  8141. K.DEBUG && alert(errorName);
  8142. },
  8143. upload_start_handler : function(file) {
  8144. var self = this;
  8145. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  8146. K('.ke-status > div', itemDiv).hide();
  8147. K('.ke-progressbar', itemDiv).show();
  8148. },
  8149. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  8150. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  8151. var progressbar = self.progressbars[file.id];
  8152. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  8153. progressbar.percent.html(percent + '%');
  8154. },
  8155. upload_error_handler : function(file, errorCode, message) {
  8156. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  8157. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8158. showError(itemDiv, self.options.errorMessage);
  8159. }
  8160. },
  8161. upload_success_handler : function(file, serverData) {
  8162. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8163. var data = {};
  8164. try {
  8165. data = K.json(serverData);
  8166. } catch (e) {
  8167. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  8168. }
  8169. if (data.error !== 0) {
  8170. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  8171. return;
  8172. }
  8173. file.url = data.url;
  8174. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  8175. K('.ke-status > div', itemDiv).hide();
  8176. }
  8177. };
  8178. self.swfu = new SWFUpload(settings);
  8179. K('.ke-swfupload-startupload input', self.div).click(function() {
  8180. self.swfu.startUpload();
  8181. });
  8182. },
  8183. getUrlList : function() {
  8184. var list = [];
  8185. K('.ke-img', self.bodyDiv).each(function() {
  8186. var img = K(this);
  8187. var status = img.attr('data-status');
  8188. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8189. list.push(img.data('data'));
  8190. }
  8191. });
  8192. return list;
  8193. },
  8194. removeFile : function(fileId) {
  8195. var self = this;
  8196. self.swfu.cancelUpload(fileId);
  8197. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8198. K('.ke-photo', itemDiv).unbind();
  8199. K('.ke-delete', itemDiv).unbind();
  8200. itemDiv.remove();
  8201. },
  8202. removeFiles : function() {
  8203. var self = this;
  8204. K('.ke-item', self.bodyDiv).each(function() {
  8205. self.removeFile(K(this).attr('data-id'));
  8206. });
  8207. },
  8208. appendFile : function(file) {
  8209. var self = this;
  8210. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8211. self.bodyDiv.append(itemDiv);
  8212. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8213. .mouseover(function(e) {
  8214. K(this).addClass('ke-on');
  8215. })
  8216. .mouseout(function(e) {
  8217. K(this).removeClass('ke-on');
  8218. });
  8219. itemDiv.append(photoDiv);
  8220. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8221. photoDiv.append(img);
  8222. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8223. self.removeFile(file.id);
  8224. });
  8225. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8226. K(['<div class="ke-progressbar">',
  8227. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8228. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8229. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8230. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8231. self.progressbars[file.id] = {
  8232. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8233. percent : K('.ke-progressbar-percent', photoDiv)
  8234. };
  8235. },
  8236. remove : function() {
  8237. this.removeFiles();
  8238. this.swfu.destroy();
  8239. this.div.html('');
  8240. }
  8241. });
  8242. K.swfupload = function(element, options) {
  8243. return new KSWFUpload(element, options);
  8244. };
  8245. })(KindEditor);
  8246. KindEditor.plugin('multiimage', function(K) {
  8247. var self = this, name = 'multiimage',
  8248. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8249. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8250. imgPath = self.pluginsPath + 'multiimage/images/',
  8251. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8252. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8253. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8254. filePostName = K.undef(self.filePostName, 'imgFile'),
  8255. lang = self.lang(name + '.');
  8256. self.plugin.multiImageDialog = function(options) {
  8257. var clickFn = options.clickFn,
  8258. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8259. uploadDesc = '';
  8260. var html = [
  8261. '<div style="padding:20px;">',
  8262. '<div class="swfupload">',
  8263. '</div>',
  8264. '</div>'
  8265. ].join('');
  8266. var dialog = self.createDialog({
  8267. name : name,
  8268. width : 650,
  8269. height : 510,
  8270. title : self.lang(name),
  8271. body : html,
  8272. previewBtn : {
  8273. name : lang.insertAll,
  8274. click : function(e) {
  8275. clickFn.call(self, swfupload.getUrlList());
  8276. }
  8277. },
  8278. yesBtn : {
  8279. name : lang.clearAll,
  8280. click : function(e) {
  8281. swfupload.removeFiles();
  8282. }
  8283. },
  8284. beforeRemove : function() {
  8285. if (!K.IE || K.V <= 8) {
  8286. swfupload.remove();
  8287. }
  8288. }
  8289. }),
  8290. div = dialog.div;
  8291. var swfupload = K.swfupload({
  8292. container : K('.swfupload', div),
  8293. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8294. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8295. buttonHeight : 23,
  8296. fileIconUrl : imgPath + 'image.png',
  8297. uploadDesc : uploadDesc,
  8298. startButtonValue : lang.startUpload,
  8299. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8300. //uploadMediaUrl : K.addParam(uploadMediaUrl, 'dir=media'),
  8301. flashUrl : imgPath + 'swfupload.swf',
  8302. filePostName : filePostName,
  8303. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8304. fileTypesDesc : 'Image Files',
  8305. fileUploadLimit : imageUploadLimit,
  8306. fileSizeLimit : imageSizeLimit,
  8307. postParams : K.undef(self.extraFileUploadParams, {}),
  8308. queueLimitExceeded : lang.queueLimitExceeded,
  8309. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8310. zeroByteFile : lang.zeroByteFile,
  8311. invalidFiletype : lang.invalidFiletype,
  8312. unknownError : lang.unknownError,
  8313. pendingMessage : lang.pending,
  8314. errorMessage : lang.uploadError,
  8315. afterError : function(html) {
  8316. self.errorDialog(html);
  8317. }
  8318. });
  8319. return dialog;
  8320. };
  8321. self.clickToolbar(name, function() {
  8322. self.plugin.multiImageDialog({
  8323. clickFn : function (urlList) {
  8324. if (urlList.length === 0) {
  8325. return;
  8326. }
  8327. K.each(urlList, function(i, data) {
  8328. if (self.afterUpload) {
  8329. self.afterUpload.call(self, data.url, data, 'multiimage');
  8330. }
  8331. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8332. });
  8333. setTimeout(function() {
  8334. self.hideDialog().focus();
  8335. }, 0);
  8336. }
  8337. });
  8338. });
  8339. });
  8340. /* ******************* */
  8341. /* Constructor & Init */
  8342. /* ******************* */
  8343. (function() {
  8344. window.SWFUpload = function (settings) {
  8345. this.initSWFUpload(settings);
  8346. };
  8347. SWFUpload.prototype.initSWFUpload = function (settings) {
  8348. try {
  8349. this.customSettings = {};
  8350. this.settings = settings;
  8351. this.eventQueue = [];
  8352. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8353. this.movieElement = null;
  8354. SWFUpload.instances[this.movieName] = this;
  8355. this.initSettings();
  8356. this.loadFlash();
  8357. this.displayDebugInfo();
  8358. } catch (ex) {
  8359. delete SWFUpload.instances[this.movieName];
  8360. throw ex;
  8361. }
  8362. };
  8363. /* *************** */
  8364. /* Static Members */
  8365. /* *************** */
  8366. SWFUpload.instances = {};
  8367. SWFUpload.movieCount = 0;
  8368. SWFUpload.version = "2.2.0 2009-03-25";
  8369. SWFUpload.QUEUE_ERROR = {
  8370. QUEUE_LIMIT_EXCEEDED : -100,
  8371. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8372. ZERO_BYTE_FILE : -120,
  8373. INVALID_FILETYPE : -130
  8374. };
  8375. SWFUpload.UPLOAD_ERROR = {
  8376. HTTP_ERROR : -200,
  8377. MISSING_UPLOAD_URL : -210,
  8378. IO_ERROR : -220,
  8379. SECURITY_ERROR : -230,
  8380. UPLOAD_LIMIT_EXCEEDED : -240,
  8381. UPLOAD_FAILED : -250,
  8382. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8383. FILE_VALIDATION_FAILED : -270,
  8384. FILE_CANCELLED : -280,
  8385. UPLOAD_STOPPED : -290
  8386. };
  8387. SWFUpload.FILE_STATUS = {
  8388. QUEUED : -1,
  8389. IN_PROGRESS : -2,
  8390. ERROR : -3,
  8391. COMPLETE : -4,
  8392. CANCELLED : -5
  8393. };
  8394. SWFUpload.BUTTON_ACTION = {
  8395. SELECT_FILE : -100,
  8396. SELECT_FILES : -110,
  8397. START_UPLOAD : -120
  8398. };
  8399. SWFUpload.CURSOR = {
  8400. ARROW : -1,
  8401. HAND : -2
  8402. };
  8403. SWFUpload.WINDOW_MODE = {
  8404. WINDOW : "window",
  8405. TRANSPARENT : "transparent",
  8406. OPAQUE : "opaque"
  8407. };
  8408. SWFUpload.completeURL = function(url) {
  8409. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8410. return url;
  8411. }
  8412. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8413. var indexSlash = window.location.pathname.lastIndexOf("/");
  8414. var path;
  8415. if (indexSlash <= 0) {
  8416. path = "/";
  8417. } else {
  8418. path = window.location.pathname.substr(0, indexSlash) + "/";
  8419. }
  8420. return /*currentURL +*/ path + url;
  8421. };
  8422. /* ******************** */
  8423. /* Instance Members */
  8424. /* ******************** */
  8425. SWFUpload.prototype.initSettings = function () {
  8426. this.ensureDefault = function (settingName, defaultValue) {
  8427. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8428. };
  8429. this.ensureDefault("upload_url", "");
  8430. this.ensureDefault("preserve_relative_urls", false);
  8431. this.ensureDefault("file_post_name", "Filedata");
  8432. this.ensureDefault("post_params", {});
  8433. this.ensureDefault("use_query_string", false);
  8434. this.ensureDefault("requeue_on_error", false);
  8435. this.ensureDefault("http_success", []);
  8436. this.ensureDefault("assume_success_timeout", 0);
  8437. this.ensureDefault("file_types", "*.*");
  8438. this.ensureDefault("file_types_description", "All Files");
  8439. this.ensureDefault("file_size_limit", 0);
  8440. this.ensureDefault("file_upload_limit", 0);
  8441. this.ensureDefault("file_queue_limit", 0);
  8442. this.ensureDefault("flash_url", "swfupload.swf");
  8443. this.ensureDefault("prevent_swf_caching", true);
  8444. this.ensureDefault("button_image_url", "");
  8445. this.ensureDefault("button_width", 1);
  8446. this.ensureDefault("button_height", 1);
  8447. this.ensureDefault("button_text", "");
  8448. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8449. this.ensureDefault("button_text_top_padding", 0);
  8450. this.ensureDefault("button_text_left_padding", 0);
  8451. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8452. this.ensureDefault("button_disabled", false);
  8453. this.ensureDefault("button_placeholder_id", "");
  8454. this.ensureDefault("button_placeholder", null);
  8455. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8456. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8457. this.ensureDefault("debug", false);
  8458. this.settings.debug_enabled = this.settings.debug;
  8459. this.settings.return_upload_start_handler = this.returnUploadStart;
  8460. this.ensureDefault("swfupload_loaded_handler", null);
  8461. this.ensureDefault("file_dialog_start_handler", null);
  8462. this.ensureDefault("file_queued_handler", null);
  8463. this.ensureDefault("file_queue_error_handler", null);
  8464. this.ensureDefault("file_dialog_complete_handler", null);
  8465. this.ensureDefault("upload_start_handler", null);
  8466. this.ensureDefault("upload_progress_handler", null);
  8467. this.ensureDefault("upload_error_handler", null);
  8468. this.ensureDefault("upload_success_handler", null);
  8469. this.ensureDefault("upload_complete_handler", null);
  8470. this.ensureDefault("debug_handler", this.debugMessage);
  8471. this.ensureDefault("custom_settings", {});
  8472. this.customSettings = this.settings.custom_settings;
  8473. if (!!this.settings.prevent_swf_caching) {
  8474. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8475. }
  8476. if (!this.settings.preserve_relative_urls) {
  8477. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8478. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8479. }
  8480. delete this.ensureDefault;
  8481. };
  8482. SWFUpload.prototype.loadFlash = function () {
  8483. var targetElement, tempParent;
  8484. if (document.getElementById(this.movieName) !== null) {
  8485. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8486. }
  8487. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8488. if (targetElement == undefined) {
  8489. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8490. }
  8491. tempParent = document.createElement("div");
  8492. tempParent.innerHTML = this.getFlashHTML();
  8493. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8494. if (window[this.movieName] == undefined) {
  8495. window[this.movieName] = this.getMovieElement();
  8496. }
  8497. };
  8498. SWFUpload.prototype.getFlashHTML = function () {
  8499. var classid = '';
  8500. if (KindEditor.IE && KindEditor.V > 8) {
  8501. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8502. }
  8503. 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">',
  8504. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8505. '<param name="movie" value="', this.settings.flash_url, '" />',
  8506. '<param name="quality" value="high" />',
  8507. '<param name="menu" value="false" />',
  8508. '<param name="allowScriptAccess" value="always" />',
  8509. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8510. '</object>'].join("");
  8511. };
  8512. SWFUpload.prototype.getFlashVars = function () {
  8513. var paramString = this.buildParamString();
  8514. var httpSuccessString = this.settings.http_success.join(",");
  8515. return ["movieName=", encodeURIComponent(this.movieName),
  8516. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8517. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8518. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8519. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8520. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8521. "&amp;params=", encodeURIComponent(paramString),
  8522. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8523. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8524. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8525. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8526. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8527. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8528. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8529. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8530. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8531. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8532. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8533. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8534. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8535. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8536. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8537. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8538. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8539. ].join("");
  8540. };
  8541. SWFUpload.prototype.getMovieElement = function () {
  8542. if (this.movieElement == undefined) {
  8543. this.movieElement = document.getElementById(this.movieName);
  8544. }
  8545. if (this.movieElement === null) {
  8546. throw "Could not find Flash element";
  8547. }
  8548. return this.movieElement;
  8549. };
  8550. SWFUpload.prototype.buildParamString = function () {
  8551. var postParams = this.settings.post_params;
  8552. var paramStringPairs = [];
  8553. if (typeof(postParams) === "object") {
  8554. for (var name in postParams) {
  8555. if (postParams.hasOwnProperty(name)) {
  8556. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8557. }
  8558. }
  8559. }
  8560. return paramStringPairs.join("&amp;");
  8561. };
  8562. SWFUpload.prototype.destroy = function () {
  8563. try {
  8564. this.cancelUpload(null, false);
  8565. var movieElement = null;
  8566. movieElement = this.getMovieElement();
  8567. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8568. for (var i in movieElement) {
  8569. try {
  8570. if (typeof(movieElement[i]) === "function") {
  8571. movieElement[i] = null;
  8572. }
  8573. } catch (ex1) {}
  8574. }
  8575. try {
  8576. movieElement.parentNode.removeChild(movieElement);
  8577. } catch (ex) {}
  8578. }
  8579. window[this.movieName] = null;
  8580. SWFUpload.instances[this.movieName] = null;
  8581. delete SWFUpload.instances[this.movieName];
  8582. this.movieElement = null;
  8583. this.settings = null;
  8584. this.customSettings = null;
  8585. this.eventQueue = null;
  8586. this.movieName = null;
  8587. return true;
  8588. } catch (ex2) {
  8589. return false;
  8590. }
  8591. };
  8592. SWFUpload.prototype.displayDebugInfo = function () {
  8593. this.debug(
  8594. [
  8595. "---SWFUpload Instance Info---\n",
  8596. "Version: ", SWFUpload.version, "\n",
  8597. "Movie Name: ", this.movieName, "\n",
  8598. "Settings:\n",
  8599. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8600. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8601. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8602. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8603. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8604. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8605. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8606. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8607. "\t", "file_types: ", this.settings.file_types, "\n",
  8608. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8609. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8610. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8611. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8612. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8613. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8614. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8615. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8616. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8617. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8618. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8619. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8620. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8621. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8622. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8623. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8624. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8625. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8626. "Event Handlers:\n",
  8627. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8628. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8629. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8630. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8631. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8632. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8633. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8634. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8635. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8636. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8637. ].join("")
  8638. );
  8639. };
  8640. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8641. the maintain v2 API compatibility
  8642. */
  8643. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8644. if (value == undefined) {
  8645. return (this.settings[name] = default_value);
  8646. } else {
  8647. return (this.settings[name] = value);
  8648. }
  8649. };
  8650. SWFUpload.prototype.getSetting = function (name) {
  8651. if (this.settings[name] != undefined) {
  8652. return this.settings[name];
  8653. }
  8654. return "";
  8655. };
  8656. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8657. argumentArray = argumentArray || [];
  8658. var movieElement = this.getMovieElement();
  8659. var returnValue, returnString;
  8660. try {
  8661. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8662. returnValue = eval(returnString);
  8663. } catch (ex) {
  8664. throw "Call to " + functionName + " failed";
  8665. }
  8666. if (returnValue != undefined && typeof returnValue.post === "object") {
  8667. returnValue = this.unescapeFilePostParams(returnValue);
  8668. }
  8669. return returnValue;
  8670. };
  8671. /* *****************************
  8672. -- Flash control methods --
  8673. Your UI should use these
  8674. to operate SWFUpload
  8675. ***************************** */
  8676. SWFUpload.prototype.selectFile = function () {
  8677. this.callFlash("SelectFile");
  8678. };
  8679. SWFUpload.prototype.selectFiles = function () {
  8680. this.callFlash("SelectFiles");
  8681. };
  8682. SWFUpload.prototype.startUpload = function (fileID) {
  8683. this.callFlash("StartUpload", [fileID]);
  8684. };
  8685. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8686. if (triggerErrorEvent !== false) {
  8687. triggerErrorEvent = true;
  8688. }
  8689. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8690. };
  8691. SWFUpload.prototype.stopUpload = function () {
  8692. this.callFlash("StopUpload");
  8693. };
  8694. /* ************************
  8695. * Settings methods
  8696. * These methods change the SWFUpload settings.
  8697. * SWFUpload settings should not be changed directly on the settings object
  8698. * since many of the settings need to be passed to Flash in order to take
  8699. * effect.
  8700. * *********************** */
  8701. SWFUpload.prototype.getStats = function () {
  8702. return this.callFlash("GetStats");
  8703. };
  8704. SWFUpload.prototype.setStats = function (statsObject) {
  8705. this.callFlash("SetStats", [statsObject]);
  8706. };
  8707. SWFUpload.prototype.getFile = function (fileID) {
  8708. if (typeof(fileID) === "number") {
  8709. return this.callFlash("GetFileByIndex", [fileID]);
  8710. } else {
  8711. return this.callFlash("GetFile", [fileID]);
  8712. }
  8713. };
  8714. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8715. return this.callFlash("AddFileParam", [fileID, name, value]);
  8716. };
  8717. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8718. this.callFlash("RemoveFileParam", [fileID, name]);
  8719. };
  8720. SWFUpload.prototype.setUploadURL = function (url) {
  8721. this.settings.upload_url = url.toString();
  8722. this.callFlash("SetUploadURL", [url]);
  8723. };
  8724. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8725. this.settings.post_params = paramsObject;
  8726. this.callFlash("SetPostParams", [paramsObject]);
  8727. };
  8728. SWFUpload.prototype.addPostParam = function (name, value) {
  8729. this.settings.post_params[name] = value;
  8730. this.callFlash("SetPostParams", [this.settings.post_params]);
  8731. };
  8732. SWFUpload.prototype.removePostParam = function (name) {
  8733. delete this.settings.post_params[name];
  8734. this.callFlash("SetPostParams", [this.settings.post_params]);
  8735. };
  8736. SWFUpload.prototype.setFileTypes = function (types, description) {
  8737. this.settings.file_types = types;
  8738. this.settings.file_types_description = description;
  8739. this.callFlash("SetFileTypes", [types, description]);
  8740. };
  8741. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8742. this.settings.file_size_limit = fileSizeLimit;
  8743. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8744. };
  8745. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8746. this.settings.file_upload_limit = fileUploadLimit;
  8747. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8748. };
  8749. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8750. this.settings.file_queue_limit = fileQueueLimit;
  8751. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8752. };
  8753. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8754. this.settings.file_post_name = filePostName;
  8755. this.callFlash("SetFilePostName", [filePostName]);
  8756. };
  8757. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8758. this.settings.use_query_string = useQueryString;
  8759. this.callFlash("SetUseQueryString", [useQueryString]);
  8760. };
  8761. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8762. this.settings.requeue_on_error = requeueOnError;
  8763. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8764. };
  8765. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8766. if (typeof http_status_codes === "string") {
  8767. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8768. }
  8769. this.settings.http_success = http_status_codes;
  8770. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8771. };
  8772. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8773. this.settings.assume_success_timeout = timeout_seconds;
  8774. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8775. };
  8776. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8777. this.settings.debug_enabled = debugEnabled;
  8778. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8779. };
  8780. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8781. if (buttonImageURL == undefined) {
  8782. buttonImageURL = "";
  8783. }
  8784. this.settings.button_image_url = buttonImageURL;
  8785. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8786. };
  8787. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8788. this.settings.button_width = width;
  8789. this.settings.button_height = height;
  8790. var movie = this.getMovieElement();
  8791. if (movie != undefined) {
  8792. movie.style.width = width + "px";
  8793. movie.style.height = height + "px";
  8794. }
  8795. this.callFlash("SetButtonDimensions", [width, height]);
  8796. };
  8797. SWFUpload.prototype.setButtonText = function (html) {
  8798. this.settings.button_text = html;
  8799. this.callFlash("SetButtonText", [html]);
  8800. };
  8801. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8802. this.settings.button_text_top_padding = top;
  8803. this.settings.button_text_left_padding = left;
  8804. this.callFlash("SetButtonTextPadding", [left, top]);
  8805. };
  8806. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8807. this.settings.button_text_style = css;
  8808. this.callFlash("SetButtonTextStyle", [css]);
  8809. };
  8810. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8811. this.settings.button_disabled = isDisabled;
  8812. this.callFlash("SetButtonDisabled", [isDisabled]);
  8813. };
  8814. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8815. this.settings.button_action = buttonAction;
  8816. this.callFlash("SetButtonAction", [buttonAction]);
  8817. };
  8818. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8819. this.settings.button_cursor = cursor;
  8820. this.callFlash("SetButtonCursor", [cursor]);
  8821. };
  8822. /* *******************************
  8823. Flash Event Interfaces
  8824. These functions are used by Flash to trigger the various
  8825. events.
  8826. All these functions a Private.
  8827. Because the ExternalInterface library is buggy the event calls
  8828. are added to a queue and the queue then executed by a setTimeout.
  8829. This ensures that events are executed in a determinate order and that
  8830. the ExternalInterface bugs are avoided.
  8831. ******************************* */
  8832. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8833. if (argumentArray == undefined) {
  8834. argumentArray = [];
  8835. } else if (!(argumentArray instanceof Array)) {
  8836. argumentArray = [argumentArray];
  8837. }
  8838. var self = this;
  8839. if (typeof this.settings[handlerName] === "function") {
  8840. this.eventQueue.push(function () {
  8841. this.settings[handlerName].apply(this, argumentArray);
  8842. });
  8843. setTimeout(function () {
  8844. self.executeNextEvent();
  8845. }, 0);
  8846. } else if (this.settings[handlerName] !== null) {
  8847. throw "Event handler " + handlerName + " is unknown or is not a function";
  8848. }
  8849. };
  8850. SWFUpload.prototype.executeNextEvent = function () {
  8851. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8852. if (typeof(f) === "function") {
  8853. f.apply(this);
  8854. }
  8855. };
  8856. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8857. var reg = /[$]([0-9a-f]{4})/i;
  8858. var unescapedPost = {};
  8859. var uk;
  8860. if (file != undefined) {
  8861. for (var k in file.post) {
  8862. if (file.post.hasOwnProperty(k)) {
  8863. uk = k;
  8864. var match;
  8865. while ((match = reg.exec(uk)) !== null) {
  8866. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8867. }
  8868. unescapedPost[uk] = file.post[k];
  8869. }
  8870. }
  8871. file.post = unescapedPost;
  8872. }
  8873. return file;
  8874. };
  8875. SWFUpload.prototype.testExternalInterface = function () {
  8876. try {
  8877. return this.callFlash("TestExternalInterface");
  8878. } catch (ex) {
  8879. return false;
  8880. }
  8881. };
  8882. SWFUpload.prototype.flashReady = function () {
  8883. var movieElement = this.getMovieElement();
  8884. if (!movieElement) {
  8885. this.debug("Flash called back ready but the flash movie can't be found.");
  8886. return;
  8887. }
  8888. this.cleanUp(movieElement);
  8889. this.queueEvent("swfupload_loaded_handler");
  8890. };
  8891. SWFUpload.prototype.cleanUp = function (movieElement) {
  8892. try {
  8893. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8894. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8895. for (var key in movieElement) {
  8896. try {
  8897. if (typeof(movieElement[key]) === "function") {
  8898. movieElement[key] = null;
  8899. }
  8900. } catch (ex) {
  8901. }
  8902. }
  8903. }
  8904. } catch (ex1) {
  8905. }
  8906. window["__flash__removeCallback"] = function (instance, name) {
  8907. try {
  8908. if (instance) {
  8909. instance[name] = null;
  8910. }
  8911. } catch (flashEx) {
  8912. }
  8913. };
  8914. };
  8915. /* This is a chance to do something before the browse window opens */
  8916. SWFUpload.prototype.fileDialogStart = function () {
  8917. this.queueEvent("file_dialog_start_handler");
  8918. };
  8919. /* Called when a file is successfully added to the queue. */
  8920. SWFUpload.prototype.fileQueued = function (file) {
  8921. file = this.unescapeFilePostParams(file);
  8922. this.queueEvent("file_queued_handler", file);
  8923. };
  8924. /* Handle errors that occur when an attempt to queue a file fails. */
  8925. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8926. file = this.unescapeFilePostParams(file);
  8927. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8928. };
  8929. /* Called after the file dialog has closed and the selected files have been queued.
  8930. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8931. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8932. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8933. };
  8934. SWFUpload.prototype.uploadStart = function (file) {
  8935. file = this.unescapeFilePostParams(file);
  8936. this.queueEvent("return_upload_start_handler", file);
  8937. };
  8938. SWFUpload.prototype.returnUploadStart = function (file) {
  8939. var returnValue;
  8940. if (typeof this.settings.upload_start_handler === "function") {
  8941. file = this.unescapeFilePostParams(file);
  8942. returnValue = this.settings.upload_start_handler.call(this, file);
  8943. } else if (this.settings.upload_start_handler != undefined) {
  8944. throw "upload_start_handler must be a function";
  8945. }
  8946. if (returnValue === undefined) {
  8947. returnValue = true;
  8948. }
  8949. returnValue = !!returnValue;
  8950. this.callFlash("ReturnUploadStart", [returnValue]);
  8951. };
  8952. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8953. file = this.unescapeFilePostParams(file);
  8954. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8955. };
  8956. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8957. file = this.unescapeFilePostParams(file);
  8958. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8959. };
  8960. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8961. file = this.unescapeFilePostParams(file);
  8962. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8963. };
  8964. SWFUpload.prototype.uploadComplete = function (file) {
  8965. file = this.unescapeFilePostParams(file);
  8966. this.queueEvent("upload_complete_handler", file);
  8967. };
  8968. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8969. internal debug console. You can override this event and have messages written where you want. */
  8970. SWFUpload.prototype.debug = function (message) {
  8971. this.queueEvent("debug_handler", message);
  8972. };
  8973. /* **********************************
  8974. Debug Console
  8975. The debug console is a self contained, in page location
  8976. for debug message to be sent. The Debug Console adds
  8977. itself to the body if necessary.
  8978. The console is automatically scrolled as messages appear.
  8979. If you are using your own debug handler or when you deploy to production and
  8980. have debug disabled you can remove these functions to reduce the file size
  8981. and complexity.
  8982. ********************************** */
  8983. SWFUpload.prototype.debugMessage = function (message) {
  8984. if (this.settings.debug) {
  8985. var exceptionMessage, exceptionValues = [];
  8986. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8987. for (var key in message) {
  8988. if (message.hasOwnProperty(key)) {
  8989. exceptionValues.push(key + ": " + message[key]);
  8990. }
  8991. }
  8992. exceptionMessage = exceptionValues.join("\n") || "";
  8993. exceptionValues = exceptionMessage.split("\n");
  8994. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8995. SWFUpload.Console.writeLine(exceptionMessage);
  8996. } else {
  8997. SWFUpload.Console.writeLine(message);
  8998. }
  8999. }
  9000. };
  9001. SWFUpload.Console = {};
  9002. SWFUpload.Console.writeLine = function (message) {
  9003. var console, documentForm;
  9004. try {
  9005. console = document.getElementById("SWFUpload_Console");
  9006. if (!console) {
  9007. documentForm = document.createElement("form");
  9008. document.getElementsByTagName("body")[0].appendChild(documentForm);
  9009. console = document.createElement("textarea");
  9010. console.id = "SWFUpload_Console";
  9011. console.style.fontFamily = "monospace";
  9012. console.setAttribute("wrap", "off");
  9013. console.wrap = "off";
  9014. console.style.overflow = "auto";
  9015. console.style.width = "700px";
  9016. console.style.height = "350px";
  9017. console.style.margin = "5px";
  9018. documentForm.appendChild(console);
  9019. }
  9020. console.value += message + "\n";
  9021. console.scrollTop = console.scrollHeight - console.clientHeight;
  9022. } catch (ex) {
  9023. alert("Exception: " + ex.name + " Message: " + ex.message);
  9024. }
  9025. };
  9026. })();
  9027. (function() {
  9028. /*
  9029. Queue Plug-in
  9030. Features:
  9031. *Adds a cancelQueue() method for cancelling the entire queue.
  9032. *All queued files are uploaded when startUpload() is called.
  9033. *If false is returned from uploadComplete then the queue upload is stopped.
  9034. If false is not returned (strict comparison) then the queue upload is continued.
  9035. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  9036. Set the event handler with the queue_complete_handler setting.
  9037. */
  9038. if (typeof(SWFUpload) === "function") {
  9039. SWFUpload.queue = {};
  9040. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  9041. return function () {
  9042. if (typeof(oldInitSettings) === "function") {
  9043. oldInitSettings.call(this);
  9044. }
  9045. this.queueSettings = {};
  9046. this.queueSettings.queue_cancelled_flag = false;
  9047. this.queueSettings.queue_upload_count = 0;
  9048. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  9049. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  9050. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  9051. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  9052. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  9053. };
  9054. })(SWFUpload.prototype.initSettings);
  9055. SWFUpload.prototype.startUpload = function (fileID) {
  9056. this.queueSettings.queue_cancelled_flag = false;
  9057. this.callFlash("StartUpload", [fileID]);
  9058. };
  9059. SWFUpload.prototype.cancelQueue = function () {
  9060. this.queueSettings.queue_cancelled_flag = true;
  9061. this.stopUpload();
  9062. var stats = this.getStats();
  9063. while (stats.files_queued > 0) {
  9064. this.cancelUpload();
  9065. stats = this.getStats();
  9066. }
  9067. };
  9068. SWFUpload.queue.uploadStartHandler = function (file) {
  9069. var returnValue;
  9070. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  9071. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  9072. }
  9073. returnValue = (returnValue === false) ? false : true;
  9074. this.queueSettings.queue_cancelled_flag = !returnValue;
  9075. return returnValue;
  9076. };
  9077. SWFUpload.queue.uploadCompleteHandler = function (file) {
  9078. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  9079. var continueUpload;
  9080. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  9081. this.queueSettings.queue_upload_count++;
  9082. }
  9083. if (typeof(user_upload_complete_handler) === "function") {
  9084. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  9085. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  9086. continueUpload = false;
  9087. } else {
  9088. continueUpload = true;
  9089. }
  9090. if (continueUpload) {
  9091. var stats = this.getStats();
  9092. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  9093. this.startUpload();
  9094. } else if (this.queueSettings.queue_cancelled_flag === false) {
  9095. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  9096. this.queueSettings.queue_upload_count = 0;
  9097. } else {
  9098. this.queueSettings.queue_cancelled_flag = false;
  9099. this.queueSettings.queue_upload_count = 0;
  9100. }
  9101. }
  9102. };
  9103. }
  9104. })();
  9105. /*******************************************************************************
  9106. * KindEditor - WYSIWYG HTML Editor for Internet
  9107. * Copyright (C) 2006-2011 kindsoft.net
  9108. *
  9109. * @author Roddy <luolonghao@gmail.com>
  9110. * @site http://www.kindsoft.net/
  9111. * @licence http://www.kindsoft.net/license.php
  9112. *******************************************************************************/
  9113. KindEditor.plugin('pagebreak', function(K) {
  9114. var self = this;
  9115. var name = 'pagebreak';
  9116. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  9117. self.clickToolbar(name, function() {
  9118. var cmd = self.cmd, range = cmd.range;
  9119. self.focus();
  9120. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  9121. self.insertHtml(pagebreakHtml + tail);
  9122. if (tail !== '') {
  9123. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9124. range.selectNodeContents(p[0]);
  9125. p.removeAttr('id');
  9126. cmd.select();
  9127. }
  9128. });
  9129. });
  9130. /*******************************************************************************
  9131. * KindEditor - WYSIWYG HTML Editor for Internet
  9132. * Copyright (C) 2006-2011 kindsoft.net
  9133. *
  9134. * @author Roddy <luolonghao@gmail.com>
  9135. * @site http://www.kindsoft.net/
  9136. * @licence http://www.kindsoft.net/license.php
  9137. *******************************************************************************/
  9138. KindEditor.plugin('plainpaste', function(K) {
  9139. var self = this, name = 'plainpaste';
  9140. self.clickToolbar(name, function() {
  9141. var lang = self.lang(name + '.'),
  9142. html = '<div style="padding:10px 20px;">' +
  9143. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9144. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9145. '</div>',
  9146. dialog = self.createDialog({
  9147. name : name,
  9148. width : 450,
  9149. title : self.lang(name),
  9150. body : html,
  9151. yesBtn : {
  9152. name : self.lang('yes'),
  9153. click : function(e) {
  9154. var html = textarea.val();
  9155. html = K.escape(html);
  9156. html = html.replace(/ {2}/g, ' &nbsp;');
  9157. if (self.newlineTag == 'p') {
  9158. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9159. } else {
  9160. html = html.replace(/\n/g, '<br />$&');
  9161. }
  9162. self.insertHtml(html).hideDialog().focus();
  9163. }
  9164. }
  9165. }),
  9166. textarea = K('textarea', dialog.div);
  9167. textarea[0].focus();
  9168. });
  9169. });
  9170. /*******************************************************************************
  9171. * KindEditor - WYSIWYG HTML Editor for Internet
  9172. * Copyright (C) 2006-2011 kindsoft.net
  9173. *
  9174. * @author Roddy <luolonghao@gmail.com>
  9175. * @site http://www.kindsoft.net/
  9176. * @licence http://www.kindsoft.net/license.php
  9177. *******************************************************************************/
  9178. KindEditor.plugin('preview', function(K) {
  9179. var self = this, name = 'preview', undefined;
  9180. self.clickToolbar(name, function() {
  9181. var lang = self.lang(name + '.'),
  9182. html = '<div style="padding:10px 20px;">' +
  9183. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9184. '</div>',
  9185. dialog = self.createDialog({
  9186. name : name,
  9187. width : 750,
  9188. title : self.lang(name),
  9189. body : html
  9190. }),
  9191. iframe = K('iframe', dialog.div),
  9192. doc = K.iframeDoc(iframe);
  9193. doc.open();
  9194. doc.write(self.fullHtml());
  9195. doc.close();
  9196. K(doc.body).css('background-color', '#FFF');
  9197. iframe[0].contentWindow.focus();
  9198. });
  9199. });
  9200. /*******************************************************************************
  9201. * KindEditor - WYSIWYG HTML Editor for Internet
  9202. * Copyright (C) 2006-2011 kindsoft.net
  9203. *
  9204. * @author Roddy <luolonghao@gmail.com>
  9205. * @site http://www.kindsoft.net/
  9206. * @licence http://www.kindsoft.net/license.php
  9207. *******************************************************************************/
  9208. KindEditor.plugin('quickformat', function(K) {
  9209. var self = this, name = 'quickformat',
  9210. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9211. function getFirstChild(knode) {
  9212. var child = knode.first();
  9213. while (child && child.first()) {
  9214. child = child.first();
  9215. }
  9216. return child;
  9217. }
  9218. self.clickToolbar(name, function() {
  9219. self.focus();
  9220. var doc = self.edit.doc,
  9221. range = self.cmd.range,
  9222. child = K(doc.body).first(), next,
  9223. nodeList = [], subList = [],
  9224. bookmark = range.createBookmark(true);
  9225. while(child) {
  9226. next = child.next();
  9227. var firstChild = getFirstChild(child);
  9228. if (!firstChild || firstChild.name != 'img') {
  9229. if (blockMap[child.name]) {
  9230. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9231. child.css('text-indent', '2em');
  9232. } else {
  9233. subList.push(child);
  9234. }
  9235. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9236. if (subList.length > 0) {
  9237. nodeList.push(subList);
  9238. }
  9239. subList = [];
  9240. }
  9241. }
  9242. child = next;
  9243. }
  9244. K.each(nodeList, function(i, subList) {
  9245. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9246. subList[0].before(wrapper);
  9247. K.each(subList, function(i, knode) {
  9248. wrapper.append(knode);
  9249. });
  9250. });
  9251. range.moveToBookmark(bookmark);
  9252. self.addBookmark();
  9253. });
  9254. });
  9255. /*******************************************************************************
  9256. * KindEditor - WYSIWYG HTML Editor for Internet
  9257. * Copyright (C) 2006-2011 kindsoft.net
  9258. *
  9259. * @author Roddy <luolonghao@gmail.com>
  9260. * @site http://www.kindsoft.net/
  9261. * @licence http://www.kindsoft.net/license.php
  9262. *******************************************************************************/
  9263. KindEditor.plugin('table', function(K) {
  9264. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9265. function _setColor(box, color) {
  9266. color = color.toUpperCase();
  9267. box.css('background-color', color);
  9268. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9269. box.html(color);
  9270. }
  9271. var pickerList = [];
  9272. function _initColorPicker(dialogDiv, colorBox) {
  9273. colorBox.bind('click,mousedown', function(e){
  9274. e.stopPropagation();
  9275. });
  9276. function removePicker() {
  9277. K.each(pickerList, function() {
  9278. this.remove();
  9279. });
  9280. pickerList = [];
  9281. K(document).unbind('click,mousedown', removePicker);
  9282. dialogDiv.unbind('click,mousedown', removePicker);
  9283. }
  9284. colorBox.click(function(e) {
  9285. removePicker();
  9286. var box = K(this),
  9287. pos = box.pos();
  9288. var picker = K.colorpicker({
  9289. x : pos.x,
  9290. y : pos.y + box.height(),
  9291. z : 811214,
  9292. selectedColor : K(this).html(),
  9293. colors : self.colorTable,
  9294. noColor : self.lang('noColor'),
  9295. shadowMode : self.shadowMode,
  9296. click : function(color) {
  9297. _setColor(box, color);
  9298. removePicker();
  9299. }
  9300. });
  9301. pickerList.push(picker);
  9302. K(document).bind('click,mousedown', removePicker);
  9303. dialogDiv.bind('click,mousedown', removePicker);
  9304. });
  9305. }
  9306. function _getCellIndex(table, row, cell) {
  9307. var rowSpanCount = 0;
  9308. for (var i = 0, len = row.cells.length; i < len; i++) {
  9309. if (row.cells[i] == cell) {
  9310. break;
  9311. }
  9312. rowSpanCount += row.cells[i].rowSpan - 1;
  9313. }
  9314. return cell.cellIndex - rowSpanCount;
  9315. }
  9316. self.plugin.table = {
  9317. prop : function(isInsert) {
  9318. var html = [
  9319. '<div style="padding:20px;">',
  9320. '<div class="ke-dialog-row">',
  9321. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9322. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9323. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9324. '</div>',
  9325. '<div class="ke-dialog-row">',
  9326. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9327. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9328. '<select name="widthType">',
  9329. '<option value="%">' + lang.percent + '</option>',
  9330. '<option value="px">' + lang.px + '</option>',
  9331. '</select> &nbsp; ',
  9332. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9333. '<select name="heightType">',
  9334. '<option value="%">' + lang.percent + '</option>',
  9335. '<option value="px">' + lang.px + '</option>',
  9336. '</select>',
  9337. '</div>',
  9338. '<div class="ke-dialog-row">',
  9339. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9340. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9341. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9342. '</div>',
  9343. '<div class="ke-dialog-row">',
  9344. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9345. '<select id="keAlign" name="align">',
  9346. '<option value="">' + lang.alignDefault + '</option>',
  9347. '<option value="left">' + lang.alignLeft + '</option>',
  9348. '<option value="center">' + lang.alignCenter + '</option>',
  9349. '<option value="right">' + lang.alignRight + '</option>',
  9350. '</select>',
  9351. '</div>',
  9352. '<div class="ke-dialog-row">',
  9353. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9354. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9355. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9356. '</div>',
  9357. '<div class="ke-dialog-row">',
  9358. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9359. '<span class="ke-inline-block ke-input-color"></span>',
  9360. '</div>',
  9361. '</div>'
  9362. ].join('');
  9363. var bookmark = self.cmd.range.createBookmark();
  9364. var dialog = self.createDialog({
  9365. name : name,
  9366. width : 500,
  9367. title : self.lang(name),
  9368. body : html,
  9369. beforeRemove : function() {
  9370. colorBox.unbind();
  9371. },
  9372. yesBtn : {
  9373. name : self.lang('yes'),
  9374. click : function(e) {
  9375. var rows = rowsBox.val(),
  9376. cols = colsBox.val(),
  9377. width = widthBox.val(),
  9378. height = heightBox.val(),
  9379. widthType = widthTypeBox.val(),
  9380. heightType = heightTypeBox.val(),
  9381. padding = paddingBox.val(),
  9382. spacing = spacingBox.val(),
  9383. align = alignBox.val(),
  9384. border = borderBox.val(),
  9385. borderColor = K(colorBox[0]).html() || '',
  9386. bgColor = K(colorBox[1]).html() || '';
  9387. if (rows == 0 || !/^\d+$/.test(rows)) {
  9388. alert(self.lang('invalidRows'));
  9389. rowsBox[0].focus();
  9390. return;
  9391. }
  9392. if (cols == 0 || !/^\d+$/.test(cols)) {
  9393. alert(self.lang('invalidRows'));
  9394. colsBox[0].focus();
  9395. return;
  9396. }
  9397. if (!/^\d*$/.test(width)) {
  9398. alert(self.lang('invalidWidth'));
  9399. widthBox[0].focus();
  9400. return;
  9401. }
  9402. if (!/^\d*$/.test(height)) {
  9403. alert(self.lang('invalidHeight'));
  9404. heightBox[0].focus();
  9405. return;
  9406. }
  9407. if (!/^\d*$/.test(padding)) {
  9408. alert(self.lang('invalidPadding'));
  9409. paddingBox[0].focus();
  9410. return;
  9411. }
  9412. if (!/^\d*$/.test(spacing)) {
  9413. alert(self.lang('invalidSpacing'));
  9414. spacingBox[0].focus();
  9415. return;
  9416. }
  9417. if (!/^\d*$/.test(border)) {
  9418. alert(self.lang('invalidBorder'));
  9419. borderBox[0].focus();
  9420. return;
  9421. }
  9422. if (table) {
  9423. if (width !== '') {
  9424. table.width(width + widthType);
  9425. } else {
  9426. table.css('width', '');
  9427. }
  9428. if (table[0].width !== undefined) {
  9429. table.removeAttr('width');
  9430. }
  9431. if (height !== '') {
  9432. table.height(height + heightType);
  9433. } else {
  9434. table.css('height', '');
  9435. }
  9436. if (table[0].height !== undefined) {
  9437. table.removeAttr('height');
  9438. }
  9439. table.css('background-color', bgColor);
  9440. if (table[0].bgColor !== undefined) {
  9441. table.removeAttr('bgColor');
  9442. }
  9443. if (padding !== '') {
  9444. table[0].cellPadding = padding;
  9445. } else {
  9446. table.removeAttr('cellPadding');
  9447. }
  9448. if (spacing !== '') {
  9449. table[0].cellSpacing = spacing;
  9450. } else {
  9451. table.removeAttr('cellSpacing');
  9452. }
  9453. if (align !== '') {
  9454. table[0].align = align;
  9455. } else {
  9456. table.removeAttr('align');
  9457. }
  9458. if (border !== '') {
  9459. table.attr('border', border);
  9460. } else {
  9461. table.removeAttr('border');
  9462. }
  9463. if (border === '' || border === '0') {
  9464. table.addClass(zeroborder);
  9465. } else {
  9466. table.removeClass(zeroborder);
  9467. }
  9468. if (borderColor !== '') {
  9469. table.attr('borderColor', borderColor);
  9470. } else {
  9471. table.removeAttr('borderColor');
  9472. }
  9473. self.hideDialog().focus();
  9474. self.cmd.range.moveToBookmark(bookmark);
  9475. self.cmd.select();
  9476. self.addBookmark();
  9477. return;
  9478. }
  9479. var style = '';
  9480. if (width !== '') {
  9481. style += 'width:' + width + widthType + ';';
  9482. }
  9483. if (height !== '') {
  9484. style += 'height:' + height + heightType + ';';
  9485. }
  9486. if (bgColor !== '') {
  9487. style += 'background-color:' + bgColor + ';';
  9488. }
  9489. var html = '<table';
  9490. if (style !== '') {
  9491. html += ' style="' + style + '"';
  9492. }
  9493. if (padding !== '') {
  9494. html += ' cellpadding="' + padding + '"';
  9495. }
  9496. if (spacing !== '') {
  9497. html += ' cellspacing="' + spacing + '"';
  9498. }
  9499. if (align !== '') {
  9500. html += ' align="' + align + '"';
  9501. }
  9502. if (border !== '') {
  9503. html += ' border="' + border + '"';
  9504. }
  9505. if (border === '' || border === '0') {
  9506. html += ' class="' + zeroborder + '"';
  9507. }
  9508. if (borderColor !== '') {
  9509. html += ' bordercolor="' + borderColor + '"';
  9510. }
  9511. html += '>';
  9512. for (var i = 0; i < rows; i++) {
  9513. html += '<tr>';
  9514. for (var j = 0; j < cols; j++) {
  9515. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9516. }
  9517. html += '</tr>';
  9518. }
  9519. html += '</table>';
  9520. if (!K.IE) {
  9521. html += '<br />';
  9522. }
  9523. self.insertHtml(html);
  9524. self.select().hideDialog().focus();
  9525. self.addBookmark();
  9526. }
  9527. }
  9528. }),
  9529. div = dialog.div,
  9530. rowsBox = K('[name="rows"]', div).val(3),
  9531. colsBox = K('[name="cols"]', div).val(2),
  9532. widthBox = K('[name="width"]', div).val(100),
  9533. heightBox = K('[name="height"]', div),
  9534. widthTypeBox = K('[name="widthType"]', div),
  9535. heightTypeBox = K('[name="heightType"]', div),
  9536. paddingBox = K('[name="padding"]', div).val(2),
  9537. spacingBox = K('[name="spacing"]', div).val(0),
  9538. alignBox = K('[name="align"]', div),
  9539. borderBox = K('[name="border"]', div).val(1),
  9540. colorBox = K('.ke-input-color', div);
  9541. _initColorPicker(div, colorBox.eq(0));
  9542. _initColorPicker(div, colorBox.eq(1));
  9543. _setColor(colorBox.eq(0), '#000000');
  9544. _setColor(colorBox.eq(1), '');
  9545. rowsBox[0].focus();
  9546. rowsBox[0].select();
  9547. var table;
  9548. if (isInsert) {
  9549. return;
  9550. }
  9551. table = self.plugin.getSelectedTable();
  9552. if (table) {
  9553. rowsBox.val(table[0].rows.length);
  9554. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9555. rowsBox.attr('disabled', true);
  9556. colsBox.attr('disabled', true);
  9557. var match,
  9558. tableWidth = table[0].style.width || table[0].width,
  9559. tableHeight = table[0].style.height || table[0].height;
  9560. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9561. widthBox.val(match[1]);
  9562. widthTypeBox.val(match[2]);
  9563. } else {
  9564. widthBox.val('');
  9565. }
  9566. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9567. heightBox.val(match[1]);
  9568. heightTypeBox.val(match[2]);
  9569. }
  9570. paddingBox.val(table[0].cellPadding || '');
  9571. spacingBox.val(table[0].cellSpacing || '');
  9572. alignBox.val(table[0].align || '');
  9573. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9574. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9575. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9576. widthBox[0].focus();
  9577. widthBox[0].select();
  9578. }
  9579. },
  9580. cellprop : function() {
  9581. var html = [
  9582. '<div style="padding:20px;">',
  9583. '<div class="ke-dialog-row">',
  9584. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9585. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9586. '<select name="widthType">',
  9587. '<option value="%">' + lang.percent + '</option>',
  9588. '<option value="px">' + lang.px + '</option>',
  9589. '</select> &nbsp; ',
  9590. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9591. '<select name="heightType">',
  9592. '<option value="%">' + lang.percent + '</option>',
  9593. '<option value="px">' + lang.px + '</option>',
  9594. '</select>',
  9595. '</div>',
  9596. '<div class="ke-dialog-row">',
  9597. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9598. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9599. '<option value="">' + lang.alignDefault + '</option>',
  9600. '<option value="left">' + lang.alignLeft + '</option>',
  9601. '<option value="center">' + lang.alignCenter + '</option>',
  9602. '<option value="right">' + lang.alignRight + '</option>',
  9603. '</select> ',
  9604. lang.verticalAlign + ' <select name="verticalAlign">',
  9605. '<option value="">' + lang.alignDefault + '</option>',
  9606. '<option value="top">' + lang.alignTop + '</option>',
  9607. '<option value="middle">' + lang.alignMiddle + '</option>',
  9608. '<option value="bottom">' + lang.alignBottom + '</option>',
  9609. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9610. '</select>',
  9611. '</div>',
  9612. '<div class="ke-dialog-row">',
  9613. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9614. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9615. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9616. '</div>',
  9617. '<div class="ke-dialog-row">',
  9618. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9619. '<span class="ke-inline-block ke-input-color"></span>',
  9620. '</div>',
  9621. '</div>'
  9622. ].join('');
  9623. var bookmark = self.cmd.range.createBookmark();
  9624. var dialog = self.createDialog({
  9625. name : name,
  9626. width : 500,
  9627. title : self.lang('tablecell'),
  9628. body : html,
  9629. beforeRemove : function() {
  9630. colorBox.unbind();
  9631. },
  9632. yesBtn : {
  9633. name : self.lang('yes'),
  9634. click : function(e) {
  9635. var width = widthBox.val(),
  9636. height = heightBox.val(),
  9637. widthType = widthTypeBox.val(),
  9638. heightType = heightTypeBox.val(),
  9639. padding = paddingBox.val(),
  9640. spacing = spacingBox.val(),
  9641. textAlign = textAlignBox.val(),
  9642. verticalAlign = verticalAlignBox.val(),
  9643. border = borderBox.val(),
  9644. borderColor = K(colorBox[0]).html() || '',
  9645. bgColor = K(colorBox[1]).html() || '';
  9646. if (!/^\d*$/.test(width)) {
  9647. alert(self.lang('invalidWidth'));
  9648. widthBox[0].focus();
  9649. return;
  9650. }
  9651. if (!/^\d*$/.test(height)) {
  9652. alert(self.lang('invalidHeight'));
  9653. heightBox[0].focus();
  9654. return;
  9655. }
  9656. if (!/^\d*$/.test(border)) {
  9657. alert(self.lang('invalidBorder'));
  9658. borderBox[0].focus();
  9659. return;
  9660. }
  9661. cell.css({
  9662. width : width !== '' ? (width + widthType) : '',
  9663. height : height !== '' ? (height + heightType) : '',
  9664. 'background-color' : bgColor,
  9665. 'text-align' : textAlign,
  9666. 'vertical-align' : verticalAlign,
  9667. 'border-width' : border,
  9668. 'border-style' : border !== '' ? 'solid' : '',
  9669. 'border-color' : borderColor
  9670. });
  9671. self.hideDialog().focus();
  9672. self.cmd.range.moveToBookmark(bookmark);
  9673. self.cmd.select();
  9674. self.addBookmark();
  9675. }
  9676. }
  9677. }),
  9678. div = dialog.div,
  9679. widthBox = K('[name="width"]', div).val(100),
  9680. heightBox = K('[name="height"]', div),
  9681. widthTypeBox = K('[name="widthType"]', div),
  9682. heightTypeBox = K('[name="heightType"]', div),
  9683. paddingBox = K('[name="padding"]', div).val(2),
  9684. spacingBox = K('[name="spacing"]', div).val(0),
  9685. textAlignBox = K('[name="textAlign"]', div),
  9686. verticalAlignBox = K('[name="verticalAlign"]', div),
  9687. borderBox = K('[name="border"]', div).val(1),
  9688. colorBox = K('.ke-input-color', div);
  9689. _initColorPicker(div, colorBox.eq(0));
  9690. _initColorPicker(div, colorBox.eq(1));
  9691. _setColor(colorBox.eq(0), '#000000');
  9692. _setColor(colorBox.eq(1), '');
  9693. widthBox[0].focus();
  9694. widthBox[0].select();
  9695. var cell = self.plugin.getSelectedCell();
  9696. var match,
  9697. cellWidth = cell[0].style.width || cell[0].width || '',
  9698. cellHeight = cell[0].style.height || cell[0].height || '';
  9699. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9700. widthBox.val(match[1]);
  9701. widthTypeBox.val(match[2]);
  9702. } else {
  9703. widthBox.val('');
  9704. }
  9705. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9706. heightBox.val(match[1]);
  9707. heightTypeBox.val(match[2]);
  9708. }
  9709. textAlignBox.val(cell[0].style.textAlign || '');
  9710. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9711. var border = cell[0].style.borderWidth || '';
  9712. if (border) {
  9713. border = parseInt(border);
  9714. }
  9715. borderBox.val(border);
  9716. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9717. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9718. widthBox[0].focus();
  9719. widthBox[0].select();
  9720. },
  9721. insert : function() {
  9722. this.prop(true);
  9723. },
  9724. 'delete' : function() {
  9725. var table = self.plugin.getSelectedTable();
  9726. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9727. self.cmd.select();
  9728. table.remove();
  9729. self.addBookmark();
  9730. },
  9731. colinsert : function(offset) {
  9732. var table = self.plugin.getSelectedTable()[0],
  9733. row = self.plugin.getSelectedRow()[0],
  9734. cell = self.plugin.getSelectedCell()[0],
  9735. index = cell.cellIndex + offset;
  9736. index += table.rows[0].cells.length - row.cells.length;
  9737. for (var i = 0, len = table.rows.length; i < len; i++) {
  9738. var newRow = table.rows[i],
  9739. newCell = newRow.insertCell(index);
  9740. newCell.innerHTML = K.IE ? '' : '<br />';
  9741. index = _getCellIndex(table, newRow, newCell);
  9742. }
  9743. self.cmd.range.selectNodeContents(cell).collapse(true);
  9744. self.cmd.select();
  9745. self.addBookmark();
  9746. },
  9747. colinsertleft : function() {
  9748. this.colinsert(0);
  9749. },
  9750. colinsertright : function() {
  9751. this.colinsert(1);
  9752. },
  9753. rowinsert : function(offset) {
  9754. var table = self.plugin.getSelectedTable()[0],
  9755. row = self.plugin.getSelectedRow()[0],
  9756. cell = self.plugin.getSelectedCell()[0];
  9757. var rowIndex = row.rowIndex;
  9758. if (offset === 1) {
  9759. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9760. }
  9761. var newRow = table.insertRow(rowIndex);
  9762. for (var i = 0, len = row.cells.length; i < len; i++) {
  9763. if (row.cells[i].rowSpan > 1) {
  9764. len -= row.cells[i].rowSpan - 1;
  9765. }
  9766. var newCell = newRow.insertCell(i);
  9767. if (offset === 1 && row.cells[i].colSpan > 1) {
  9768. newCell.colSpan = row.cells[i].colSpan;
  9769. }
  9770. newCell.innerHTML = K.IE ? '' : '<br />';
  9771. }
  9772. for (var j = rowIndex; j >= 0; j--) {
  9773. var cells = table.rows[j].cells;
  9774. if (cells.length > i) {
  9775. for (var k = cell.cellIndex; k >= 0; k--) {
  9776. if (cells[k].rowSpan > 1) {
  9777. cells[k].rowSpan += 1;
  9778. }
  9779. }
  9780. break;
  9781. }
  9782. }
  9783. self.cmd.range.selectNodeContents(cell).collapse(true);
  9784. self.cmd.select();
  9785. self.addBookmark();
  9786. },
  9787. rowinsertabove : function() {
  9788. this.rowinsert(0);
  9789. },
  9790. rowinsertbelow : function() {
  9791. this.rowinsert(1);
  9792. },
  9793. rowmerge : function() {
  9794. var table = self.plugin.getSelectedTable()[0],
  9795. row = self.plugin.getSelectedRow()[0],
  9796. cell = self.plugin.getSelectedCell()[0],
  9797. rowIndex = row.rowIndex,
  9798. nextRowIndex = rowIndex + cell.rowSpan,
  9799. nextRow = table.rows[nextRowIndex];
  9800. if (table.rows.length <= nextRowIndex) {
  9801. return;
  9802. }
  9803. var cellIndex = cell.cellIndex;
  9804. if (nextRow.cells.length <= cellIndex) {
  9805. return;
  9806. }
  9807. var nextCell = nextRow.cells[cellIndex];
  9808. if (cell.colSpan !== nextCell.colSpan) {
  9809. return;
  9810. }
  9811. cell.rowSpan += nextCell.rowSpan;
  9812. nextRow.deleteCell(cellIndex);
  9813. self.cmd.range.selectNodeContents(cell).collapse(true);
  9814. self.cmd.select();
  9815. self.addBookmark();
  9816. },
  9817. colmerge : function() {
  9818. var table = self.plugin.getSelectedTable()[0],
  9819. row = self.plugin.getSelectedRow()[0],
  9820. cell = self.plugin.getSelectedCell()[0],
  9821. rowIndex = row.rowIndex,
  9822. cellIndex = cell.cellIndex,
  9823. nextCellIndex = cellIndex + 1;
  9824. if (row.cells.length <= nextCellIndex) {
  9825. return;
  9826. }
  9827. var nextCell = row.cells[nextCellIndex];
  9828. if (cell.rowSpan !== nextCell.rowSpan) {
  9829. return;
  9830. }
  9831. cell.colSpan += nextCell.colSpan;
  9832. row.deleteCell(nextCellIndex);
  9833. self.cmd.range.selectNodeContents(cell).collapse(true);
  9834. self.cmd.select();
  9835. self.addBookmark();
  9836. },
  9837. rowsplit : function() {
  9838. var table = self.plugin.getSelectedTable()[0],
  9839. row = self.plugin.getSelectedRow()[0],
  9840. cell = self.plugin.getSelectedCell()[0],
  9841. rowIndex = row.rowIndex;
  9842. if (cell.rowSpan === 1) {
  9843. return;
  9844. }
  9845. var cellIndex = _getCellIndex(table, row, cell);
  9846. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9847. var newRow = table.rows[rowIndex + i],
  9848. newCell = newRow.insertCell(cellIndex);
  9849. if (cell.colSpan > 1) {
  9850. newCell.colSpan = cell.colSpan;
  9851. }
  9852. newCell.innerHTML = K.IE ? '' : '<br />';
  9853. cellIndex = _getCellIndex(table, newRow, newCell);
  9854. }
  9855. K(cell).removeAttr('rowSpan');
  9856. self.cmd.range.selectNodeContents(cell).collapse(true);
  9857. self.cmd.select();
  9858. self.addBookmark();
  9859. },
  9860. colsplit : function() {
  9861. var table = self.plugin.getSelectedTable()[0],
  9862. row = self.plugin.getSelectedRow()[0],
  9863. cell = self.plugin.getSelectedCell()[0],
  9864. cellIndex = cell.cellIndex;
  9865. if (cell.colSpan === 1) {
  9866. return;
  9867. }
  9868. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9869. var newCell = row.insertCell(cellIndex + i);
  9870. if (cell.rowSpan > 1) {
  9871. newCell.rowSpan = cell.rowSpan;
  9872. }
  9873. newCell.innerHTML = K.IE ? '' : '<br />';
  9874. }
  9875. K(cell).removeAttr('colSpan');
  9876. self.cmd.range.selectNodeContents(cell).collapse(true);
  9877. self.cmd.select();
  9878. self.addBookmark();
  9879. },
  9880. coldelete : function() {
  9881. var table = self.plugin.getSelectedTable()[0],
  9882. row = self.plugin.getSelectedRow()[0],
  9883. cell = self.plugin.getSelectedCell()[0],
  9884. index = cell.cellIndex;
  9885. for (var i = 0, len = table.rows.length; i < len; i++) {
  9886. var newRow = table.rows[i],
  9887. newCell = newRow.cells[index];
  9888. if (newCell.colSpan > 1) {
  9889. newCell.colSpan -= 1;
  9890. if (newCell.colSpan === 1) {
  9891. K(newCell).removeAttr('colSpan');
  9892. }
  9893. } else {
  9894. newRow.deleteCell(index);
  9895. }
  9896. if (newCell.rowSpan > 1) {
  9897. i += newCell.rowSpan - 1;
  9898. }
  9899. }
  9900. if (row.cells.length === 0) {
  9901. self.cmd.range.setStartBefore(table).collapse(true);
  9902. self.cmd.select();
  9903. K(table).remove();
  9904. } else {
  9905. self.cmd.selection(true);
  9906. }
  9907. self.addBookmark();
  9908. },
  9909. rowdelete : function() {
  9910. var table = self.plugin.getSelectedTable()[0],
  9911. row = self.plugin.getSelectedRow()[0],
  9912. cell = self.plugin.getSelectedCell()[0],
  9913. rowIndex = row.rowIndex;
  9914. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9915. table.deleteRow(rowIndex + i);
  9916. }
  9917. if (table.rows.length === 0) {
  9918. self.cmd.range.setStartBefore(table).collapse(true);
  9919. self.cmd.select();
  9920. K(table).remove();
  9921. } else {
  9922. self.cmd.selection(true);
  9923. }
  9924. self.addBookmark();
  9925. }
  9926. };
  9927. self.clickToolbar(name, self.plugin.table.prop);
  9928. });
  9929. /*******************************************************************************
  9930. * KindEditor - WYSIWYG HTML Editor for Internet
  9931. * Copyright (C) 2006-2011 kindsoft.net
  9932. *
  9933. * @author Roddy <luolonghao@gmail.com>
  9934. * @site http://www.kindsoft.net/
  9935. * @licence http://www.kindsoft.net/license.php
  9936. *******************************************************************************/
  9937. KindEditor.plugin('template', function(K) {
  9938. var self = this, name = 'template', lang = self.lang(name + '.'),
  9939. htmlPath = self.pluginsPath + name + '/html/';
  9940. function getFilePath(fileName) {
  9941. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9942. }
  9943. self.clickToolbar(name, function() {
  9944. var lang = self.lang(name + '.'),
  9945. arr = ['<div style="padding:10px 20px;">',
  9946. '<div class="ke-header">',
  9947. '<div class="ke-left">',
  9948. lang. selectTemplate + ' <select>'];
  9949. K.each(lang.fileList, function(key, val) {
  9950. arr.push('<option value="' + key + '">' + val + '</option>');
  9951. });
  9952. html = [arr.join(''),
  9953. '</select></div>',
  9954. '<div class="ke-right">',
  9955. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9956. '</div>',
  9957. '<div class="ke-clearfix"></div>',
  9958. '</div>',
  9959. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9960. '</div>'].join('');
  9961. var dialog = self.createDialog({
  9962. name : name,
  9963. width : 500,
  9964. title : self.lang(name),
  9965. body : html,
  9966. yesBtn : {
  9967. name : self.lang('yes'),
  9968. click : function(e) {
  9969. var doc = K.iframeDoc(iframe);
  9970. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9971. }
  9972. }
  9973. });
  9974. var selectBox = K('select', dialog.div),
  9975. checkbox = K('[name="replaceFlag"]', dialog.div),
  9976. iframe = K('iframe', dialog.div);
  9977. checkbox[0].checked = true;
  9978. iframe.attr('src', getFilePath(selectBox.val()));
  9979. selectBox.change(function() {
  9980. iframe.attr('src', getFilePath(this.value));
  9981. });
  9982. });
  9983. });
  9984. /*******************************************************************************
  9985. * KindEditor - WYSIWYG HTML Editor for Internet
  9986. * Copyright (C) 2006-2011 kindsoft.net
  9987. *
  9988. * @author Roddy <luolonghao@gmail.com>
  9989. * @site http://www.kindsoft.net/
  9990. * @licence http://www.kindsoft.net/license.php
  9991. *******************************************************************************/
  9992. KindEditor.plugin('wordpaste', function(K) {
  9993. var self = this, name = 'wordpaste';
  9994. self.clickToolbar(name, function() {
  9995. var lang = self.lang(name + '.'),
  9996. html = '<div style="padding:10px 20px;">' +
  9997. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9998. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9999. '</div>',
  10000. dialog = self.createDialog({
  10001. name : name,
  10002. width : 450,
  10003. title : self.lang(name),
  10004. body : html,
  10005. yesBtn : {
  10006. name : self.lang('yes'),
  10007. click : function(e) {
  10008. var str = doc.body.innerHTML;
  10009. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  10010. self.insertHtml(str).hideDialog().focus();
  10011. }
  10012. }
  10013. }),
  10014. div = dialog.div,
  10015. iframe = K('iframe', div),
  10016. doc = K.iframeDoc(iframe);
  10017. if (!K.IE) {
  10018. doc.designMode = 'on';
  10019. }
  10020. doc.open();
  10021. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  10022. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  10023. if (!K.IE) {
  10024. doc.write('<br />');
  10025. }
  10026. doc.write('</body></html>');
  10027. doc.close();
  10028. if (K.IE) {
  10029. doc.body.contentEditable = 'true';
  10030. }
  10031. iframe[0].contentWindow.focus();
  10032. });
  10033. });
  10034. KindEditor.plugin('fixtoolbar', function (K) {
  10035. var self = this;
  10036. if (!self.fixToolBar) {
  10037. return;
  10038. }
  10039. function init() {
  10040. var toolbar = K('.ke-toolbar');
  10041. var originY = toolbar.pos().y;
  10042. K(window).bind('scroll', function () {
  10043. if (toolbar.css('position') == 'fixed') {
  10044. if(document.body.scrollTop - originY < 0){
  10045. toolbar.css('position', 'static');
  10046. toolbar.css('top', 'auto');
  10047. }
  10048. } else {
  10049. if (toolbar.pos().y - document.body.scrollTop < 0) {
  10050. toolbar.css('position', 'fixed');
  10051. toolbar.css('top', 0);
  10052. }
  10053. }
  10054. });
  10055. }
  10056. if (self.isCreated) {
  10057. init();
  10058. } else {
  10059. self.afterCreate(init);
  10060. }
  10061. });
  10062. //自定义资源库
  10063. KindEditor.plugin('res', function(K) {
  10064. var self = this;
  10065. // 点击图标时执行
  10066. self.clickToolbar('res', function() {
  10067. var clickFn = function(url, title, id) {
  10068. var html = '<embed src="{url}" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" id="{id}"/>';
  10069. html = html.replace('{url}', url);
  10070. html = html.replace('{id}', id);
  10071. self.insertHtml(html);
  10072. };
  10073. editorShowUpload('', self.fileManagerJson, '视频库', clickFn, this);
  10074. });
  10075. });
  10076. function autoImg(self) {
  10077. var index = self.index;
  10078. var haspicContainer = document.getElementById("has_pic_" + index);
  10079. if (haspicContainer == null) {
  10080. haspicContainer = document.createElement("div");
  10081. haspicContainer.id = "has_pic_" + index;
  10082. 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>";
  10083. $(".ke-toolbar").eq(index).after(haspicContainer);
  10084. }
  10085. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10086. var piccount = 0;
  10087. var sstr = '';
  10088. $(img).each(function (i) {
  10089. var that = $(this);
  10090. var host = gethost(self.uploadJson);
  10091. var yhost = '';
  10092. if (self.uploadYunJson && self.uploadYunJson.host) {
  10093. yhost = gethost(self.uploadYunJson.host);
  10094. }
  10095. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10096. var n = gethost(that.attr("src"));
  10097. if (yhost) {
  10098. if (host != n && yhost != n) {
  10099. piccount++;
  10100. if (i == $(img).length - 1)
  10101. sstr += that.attr("src");
  10102. else
  10103. sstr += that.attr("src") + ",";
  10104. }
  10105. } else {
  10106. if (host != n) {
  10107. piccount++;
  10108. if (i == $(img).length - 1)
  10109. sstr += that.attr("src");
  10110. else
  10111. sstr += that.attr("src") + ",";
  10112. }
  10113. }
  10114. }
  10115. });
  10116. $("#piclist_" + index).val(encodeURIComponent(sstr));
  10117. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  10118. }
  10119. function closeupload(index) {
  10120. $("#has_pic_" + index).hide();
  10121. $("#upload_" + index).show();
  10122. }
  10123. function uploadpic(url, name, index) {
  10124. var piclist = encodeURI($("#piclist_" + index).val());
  10125. if (piclist.length == 0) return false;
  10126. $.ajax({
  10127. url: url.replace('kindeditor', 'copys') + '&json=1',
  10128. data: name + "=" + piclist,
  10129. type: "POST",
  10130. dataType: "json",
  10131. beforeSend: function () {
  10132. $("#upload_" + index).hide();
  10133. $("#confirm_" + index).text("正在上传中...");
  10134. },
  10135. success: function (msg) {
  10136. var url = msg.data;
  10137. if (url !== "") {
  10138. var str = new Array();
  10139. str = url.split(',');
  10140. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10141. $(img).each(function (i) {
  10142. var that = $(this);
  10143. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10144. that.attr("src", str[i]);
  10145. that.attr("data-ke-src", str[i]);
  10146. }
  10147. });
  10148. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  10149. }
  10150. else $("#confirm_" + index).text("上传失败!");
  10151. }
  10152. });
  10153. }
  10154. function gethost(url){
  10155. var reg = /^http(s)?:\/\/(.*?)\//;
  10156. return reg.exec(url)[2];
  10157. }