kindeditor-all-min.js 296 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091
  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 : 811213,
  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. htmlTags : {
  277. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  278. span : [
  279. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  280. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  281. ],
  282. div : [
  283. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  284. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  285. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  286. ],
  287. table: [
  288. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  289. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  290. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  291. '.width', '.height', '.border-collapse'
  292. ],
  293. 'td,th': [
  294. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  295. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  296. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  297. ],
  298. a : ['id', 'class', 'href', 'target', 'name'],
  299. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  300. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  301. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  302. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  303. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  304. ],
  305. pre : ['id', 'class'],
  306. hr : ['id', 'class', '.page-break-after'],
  307. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  308. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  309. },
  310. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  311. };
  312. var _useCapture = false;
  313. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  314. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  315. var _CHANGE_KEY_MAP = {};
  316. _each(_INPUT_KEY_MAP, function(key, val) {
  317. _CHANGE_KEY_MAP[key] = val;
  318. });
  319. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  320. _CHANGE_KEY_MAP[key] = val;
  321. });
  322. function _bindEvent(el, type, fn) {
  323. if (el.addEventListener){
  324. el.addEventListener(type, fn, _useCapture);
  325. } else if (el.attachEvent){
  326. el.attachEvent('on' + type, fn);
  327. }
  328. }
  329. function _unbindEvent(el, type, fn) {
  330. if (el.removeEventListener){
  331. el.removeEventListener(type, fn, _useCapture);
  332. } else if (el.detachEvent){
  333. el.detachEvent('on' + type, fn);
  334. }
  335. }
  336. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  337. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  338. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  339. function KEvent(el, event) {
  340. this.init(el, event);
  341. }
  342. _extend(KEvent, {
  343. init : function(el, event) {
  344. var self = this, doc = el.ownerDocument || el.document || el;
  345. self.event = event;
  346. _each(_EVENT_PROPS, function(key, val) {
  347. self[val] = event[val];
  348. });
  349. if (!self.target) {
  350. self.target = self.srcElement || doc;
  351. }
  352. if (self.target.nodeType === 3) {
  353. self.target = self.target.parentNode;
  354. }
  355. if (!self.relatedTarget && self.fromElement) {
  356. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  357. }
  358. if (self.pageX == null && self.clientX != null) {
  359. var d = doc.documentElement, body = doc.body;
  360. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  361. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  362. }
  363. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  364. self.which = self.charCode || self.keyCode;
  365. }
  366. if (!self.metaKey && self.ctrlKey) {
  367. self.metaKey = self.ctrlKey;
  368. }
  369. if (!self.which && self.button !== undefined) {
  370. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  371. }
  372. switch (self.which) {
  373. case 186 :
  374. self.which = 59;
  375. break;
  376. case 187 :
  377. case 107 :
  378. case 43 :
  379. self.which = 61;
  380. break;
  381. case 189 :
  382. case 45 :
  383. self.which = 109;
  384. break;
  385. case 42 :
  386. self.which = 106;
  387. break;
  388. case 47 :
  389. self.which = 111;
  390. break;
  391. case 78 :
  392. self.which = 110;
  393. break;
  394. }
  395. if (self.which >= 96 && self.which <= 105) {
  396. self.which -= 48;
  397. }
  398. },
  399. preventDefault : function() {
  400. var ev = this.event;
  401. if (ev.preventDefault) {
  402. ev.preventDefault();
  403. } else {
  404. ev.returnValue = false;
  405. }
  406. },
  407. stopPropagation : function() {
  408. var ev = this.event;
  409. if (ev.stopPropagation) {
  410. ev.stopPropagation();
  411. } else {
  412. ev.cancelBubble = true;
  413. }
  414. },
  415. stop : function() {
  416. this.preventDefault();
  417. this.stopPropagation();
  418. }
  419. });
  420. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  421. function _getId(el) {
  422. return el[_eventExpendo] || null;
  423. }
  424. function _setId(el) {
  425. el[_eventExpendo] = ++_eventId;
  426. return _eventId;
  427. }
  428. function _removeId(el) {
  429. try {
  430. delete el[_eventExpendo];
  431. } catch(e) {
  432. if (el.removeAttribute) {
  433. el.removeAttribute(_eventExpendo);
  434. }
  435. }
  436. }
  437. function _bind(el, type, fn) {
  438. if (type.indexOf(',') >= 0) {
  439. _each(type.split(','), function() {
  440. _bind(el, this, fn);
  441. });
  442. return;
  443. }
  444. var id = _getId(el);
  445. if (!id) {
  446. id = _setId(el);
  447. }
  448. if (_eventData[id] === undefined) {
  449. _eventData[id] = {};
  450. }
  451. var events = _eventData[id][type];
  452. if (events && events.length > 0) {
  453. _unbindEvent(el, type, events[0]);
  454. } else {
  455. _eventData[id][type] = [];
  456. _eventData[id].el = el;
  457. }
  458. events = _eventData[id][type];
  459. if (events.length === 0) {
  460. events[0] = function(e) {
  461. var kevent = e ? new KEvent(el, e) : undefined;
  462. _each(events, function(i, event) {
  463. if (i > 0 && event) {
  464. event.call(el, kevent);
  465. }
  466. });
  467. };
  468. }
  469. if (_inArray(fn, events) < 0) {
  470. events.push(fn);
  471. }
  472. _bindEvent(el, type, events[0]);
  473. }
  474. function _unbind(el, type, fn) {
  475. if (type && type.indexOf(',') >= 0) {
  476. _each(type.split(','), function() {
  477. _unbind(el, this, fn);
  478. });
  479. return;
  480. }
  481. var id = _getId(el);
  482. if (!id) {
  483. return;
  484. }
  485. if (type === undefined) {
  486. if (id in _eventData) {
  487. _each(_eventData[id], function(key, events) {
  488. if (key != 'el' && events.length > 0) {
  489. _unbindEvent(el, key, events[0]);
  490. }
  491. });
  492. delete _eventData[id];
  493. _removeId(el);
  494. }
  495. return;
  496. }
  497. if (!_eventData[id]) {
  498. return;
  499. }
  500. var events = _eventData[id][type];
  501. if (events && events.length > 0) {
  502. if (fn === undefined) {
  503. _unbindEvent(el, type, events[0]);
  504. delete _eventData[id][type];
  505. } else {
  506. _each(events, function(i, event) {
  507. if (i > 0 && event === fn) {
  508. events.splice(i, 1);
  509. }
  510. });
  511. if (events.length == 1) {
  512. _unbindEvent(el, type, events[0]);
  513. delete _eventData[id][type];
  514. }
  515. }
  516. var count = 0;
  517. _each(_eventData[id], function() {
  518. count++;
  519. });
  520. if (count < 2) {
  521. delete _eventData[id];
  522. _removeId(el);
  523. }
  524. }
  525. }
  526. function _fire(el, type) {
  527. if (type.indexOf(',') >= 0) {
  528. _each(type.split(','), function() {
  529. _fire(el, this);
  530. });
  531. return;
  532. }
  533. var id = _getId(el);
  534. if (!id) {
  535. return;
  536. }
  537. var events = _eventData[id][type];
  538. if (_eventData[id] && events && events.length > 0) {
  539. events[0]();
  540. }
  541. }
  542. function _ctrl(el, key, fn) {
  543. var self = this;
  544. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  545. _bind(el, 'keydown', function(e) {
  546. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  547. fn.call(el);
  548. e.stop();
  549. }
  550. });
  551. }
  552. var _readyFinished = false;
  553. function _ready(fn) {
  554. if (_readyFinished) {
  555. fn(KindEditor);
  556. return;
  557. }
  558. var loaded = false;
  559. function readyFunc() {
  560. if (!loaded) {
  561. loaded = true;
  562. fn(KindEditor);
  563. _readyFinished = true;
  564. }
  565. }
  566. function ieReadyFunc() {
  567. if (!loaded) {
  568. try {
  569. document.documentElement.doScroll('left');
  570. } catch(e) {
  571. setTimeout(ieReadyFunc, 100);
  572. return;
  573. }
  574. readyFunc();
  575. }
  576. }
  577. function ieReadyStateFunc() {
  578. if (document.readyState === 'complete') {
  579. readyFunc();
  580. }
  581. }
  582. if (document.addEventListener) {
  583. _bind(document, 'DOMContentLoaded', readyFunc);
  584. } else if (document.attachEvent) {
  585. _bind(document, 'readystatechange', ieReadyStateFunc);
  586. var toplevel = false;
  587. try {
  588. toplevel = window.frameElement == null;
  589. } catch(e) {}
  590. if (document.documentElement.doScroll && toplevel) {
  591. ieReadyFunc();
  592. }
  593. }
  594. _bind(window, 'load', readyFunc);
  595. }
  596. if (window.attachEvent) {
  597. window.attachEvent('onunload', function() {
  598. _each(_eventData, function(key, events) {
  599. if (events.el) {
  600. _unbind(events.el);
  601. }
  602. });
  603. });
  604. }
  605. K.ctrl = _ctrl;
  606. K.ready = _ready;
  607. function _getCssList(css) {
  608. css = css.replace(/&quot;/g, '"');
  609. var list = {},
  610. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  611. match;
  612. while ((match = reg.exec(css))) {
  613. var key = _trim(match[1].toLowerCase()),
  614. val = _trim(_toHex(match[2]));
  615. list[key] = val;
  616. }
  617. return list;
  618. }
  619. function _getAttrList(tag) {
  620. var list = {},
  621. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  622. match;
  623. while ((match = reg.exec(tag))) {
  624. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  625. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  626. list[key] = val;
  627. }
  628. return list;
  629. }
  630. function _addClassToTag(tag, className) {
  631. if (/\s+class\s*=/.test(tag)) {
  632. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  633. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  634. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  635. } else {
  636. return $0;
  637. }
  638. });
  639. } else {
  640. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  641. }
  642. return tag;
  643. }
  644. function _formatCss(css) {
  645. var str = '';
  646. _each(_getCssList(css), function(key, val) {
  647. str += key + ':' + val + ';';
  648. });
  649. return str;
  650. }
  651. function _formatUrl(url, mode, host, pathname) {
  652. return url;
  653. mode = _undef(mode, '').toLowerCase();
  654. if (url.substr(0, 5) != 'data:') {
  655. url = url.replace(/([^:])\/\//g, '$1/');
  656. }
  657. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  658. return url;
  659. }
  660. host = host || location.protocol + '//' + location.host;
  661. if (pathname === undefined) {
  662. var m = location.pathname.match(/^(\/.*)\//);
  663. pathname = m ? m[1] : '';
  664. }
  665. var match;
  666. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  667. if (match[1] !== host) {
  668. return url;
  669. }
  670. } else if (/^\w+:/.test(url)) {
  671. return url;
  672. }
  673. function getRealPath(path) {
  674. var parts = path.split('/'), paths = [];
  675. for (var i = 0, len = parts.length; i < len; i++) {
  676. var part = parts[i];
  677. if (part == '..') {
  678. if (paths.length > 0) {
  679. paths.pop();
  680. }
  681. } else if (part !== '' && part != '.') {
  682. paths.push(part);
  683. }
  684. }
  685. return '/' + paths.join('/');
  686. }
  687. if (/^\//.test(url)) {
  688. url = host + getRealPath(url.substr(1));
  689. } else if (!/^\w+:\/\//.test(url)) {
  690. url = host + getRealPath(pathname + '/' + url);
  691. }
  692. function getRelativePath(path, depth) {
  693. if (url.substr(0, path.length) === path) {
  694. var arr = [];
  695. for (var i = 0; i < depth; i++) {
  696. arr.push('..');
  697. }
  698. var prefix = '.';
  699. if (arr.length > 0) {
  700. prefix += '/' + arr.join('/');
  701. }
  702. if (pathname == '/') {
  703. prefix += '/';
  704. }
  705. return prefix + url.substr(path.length);
  706. } else {
  707. if ((match = /^(.*)\//.exec(path))) {
  708. return getRelativePath(match[1], ++depth);
  709. }
  710. }
  711. }
  712. if (mode === 'relative') {
  713. url = getRelativePath(host + pathname, 0).substr(2);
  714. } else if (mode === 'absolute') {
  715. if (url.substr(0, host.length) === host) {
  716. url = url.substr(host.length);
  717. }
  718. }
  719. return url;
  720. }
  721. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  722. if (html == null) {
  723. html = '';
  724. }
  725. urlType = urlType || '';
  726. wellFormatted = _undef(wellFormatted, false);
  727. indentChar = _undef(indentChar, '\t');
  728. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  729. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  730. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  731. });
  732. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  733. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  734. html = html.replace(/\u200B/g, '');
  735. html = html.replace(/\u00A9/g, '&copy;');
  736. html = html.replace(/\u00AE/g, '&reg;');
  737. html = html.replace(/\u2003/g, '&emsp;');
  738. html = html.replace(/\u3000/g, '&emsp;');
  739. html = html.replace(/&quot;/g, '');
  740. html = html.replace(/, " helvetica=""(.*?)"="/g, '');
  741. html = html.replace(/<[^>]+/g, function($0) {
  742. return $0.replace(/\s+/g, ' ');
  743. });
  744. var htmlTagMap = {};
  745. if (htmlTags) {
  746. _each(htmlTags, function(key, val) {
  747. var arr = key.split(',');
  748. for (var i = 0, len = arr.length; i < len; i++) {
  749. htmlTagMap[arr[i]] = _toMap(val);
  750. }
  751. });
  752. if (!htmlTagMap.script) {
  753. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  754. }
  755. if (!htmlTagMap.style) {
  756. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  757. }
  758. }
  759. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  760. var tagStack = [];
  761. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  762. var full = $0,
  763. startNewline = $1 || '',
  764. startSlash = $2 || '',
  765. tagName = $3.toLowerCase(),
  766. attr = $4 || '',
  767. endSlash = $5 ? ' ' + $5 : '',
  768. endNewline = $6 || '';
  769. if (htmlTags && !htmlTagMap[tagName]) {
  770. return '';
  771. }
  772. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  773. endSlash = ' /';
  774. }
  775. if (_INLINE_TAG_MAP[tagName]) {
  776. if (startNewline) {
  777. startNewline = ' ';
  778. }
  779. if (endNewline) {
  780. endNewline = ' ';
  781. }
  782. }
  783. if (_PRE_TAG_MAP[tagName]) {
  784. if (startSlash) {
  785. endNewline = '\n';
  786. } else {
  787. startNewline = '\n';
  788. }
  789. }
  790. if (wellFormatted && tagName == 'br') {
  791. endNewline = '\n';
  792. }
  793. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  794. if (wellFormatted) {
  795. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  796. tagStack.pop();
  797. } else {
  798. tagStack.push(tagName);
  799. }
  800. startNewline = '\n';
  801. endNewline = '\n';
  802. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  803. startNewline += indentChar;
  804. if (!startSlash) {
  805. endNewline += indentChar;
  806. }
  807. }
  808. if (endSlash) {
  809. tagStack.pop();
  810. } else if (!startSlash) {
  811. endNewline += indentChar;
  812. }
  813. } else {
  814. startNewline = endNewline = '';
  815. }
  816. }
  817. if (attr !== '') {
  818. var attrMap = _getAttrList(full);
  819. if (tagName === 'font') {
  820. var fontStyleMap = {}, fontStyle = '';
  821. _each(attrMap, function(key, val) {
  822. if (key === 'color') {
  823. fontStyleMap.color = val;
  824. delete attrMap[key];
  825. }
  826. if (key === 'size') {
  827. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  828. delete attrMap[key];
  829. }
  830. if (key === 'face') {
  831. fontStyleMap['font-family'] = val;
  832. delete attrMap[key];
  833. }
  834. if (key === 'style') {
  835. fontStyle = val;
  836. }
  837. });
  838. if (fontStyle && !/;$/.test(fontStyle)) {
  839. fontStyle += ';';
  840. }
  841. _each(fontStyleMap, function(key, val) {
  842. if (val === '') {
  843. return;
  844. }
  845. if (/\s/.test(val)) {
  846. val = "'" + val + "'";
  847. }
  848. fontStyle += key + ':' + val + ';';
  849. });
  850. attrMap.style = fontStyle;
  851. }
  852. _each(attrMap, function(key, val) {
  853. if (_FILL_ATTR_MAP[key]) {
  854. attrMap[key] = key;
  855. }
  856. if (_inArray(key, ['src', 'href']) >= 0) {
  857. attrMap[key] = _formatUrl(val, urlType);
  858. }
  859. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  860. tagName === 'body' && key === 'contenteditable' ||
  861. /^kindeditor_\d+$/.test(key)) {
  862. delete attrMap[key];
  863. }
  864. if (key === 'style' && val !== '') {
  865. var styleMap = _getCssList(val);
  866. _each(styleMap, function(k, v) {
  867. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  868. delete styleMap[k];
  869. }
  870. });
  871. var style = '';
  872. _each(styleMap, function(k, v) {
  873. style += k + ':' + v + ';';
  874. });
  875. attrMap.style = style;
  876. }
  877. });
  878. attr = '';
  879. _each(attrMap, function(key, val) {
  880. if (key === 'style' && val === '') {
  881. return;
  882. }
  883. val = val.replace(/"/g, '&quot;');
  884. attr += ' ' + key + '="' + val + '"';
  885. });
  886. }
  887. if (tagName === 'font') {
  888. tagName = 'span';
  889. }
  890. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  891. });
  892. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  893. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  894. });
  895. html = html.replace(/\n\s*\n/g, '\n');
  896. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  897. return _trim(html);
  898. }
  899. function _clearMsWord(html, htmlTags) {
  900. html = html.replace(/<meta[\s\S]*?>/ig, '')
  901. .replace(/<![\s\S]*?>/ig, '')
  902. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  903. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  904. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  905. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  906. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  907. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  908. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  909. });
  910. return _formatHtml(html, htmlTags);
  911. }
  912. function _mediaType(src) {
  913. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  914. return 'audio/x-pn-realaudio-plugin';
  915. }
  916. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  917. return 'application/x-shockwave-flash';
  918. }
  919. return 'video/x-ms-asf-plugin';
  920. }
  921. function _mediaClass(type) {
  922. if (/realaudio/i.test(type)) {
  923. return 'ke-rm';
  924. }
  925. if (/flash/i.test(type)) {
  926. return 'ke-flash';
  927. }
  928. return 'ke-media';
  929. }
  930. function _mediaAttrs(srcTag) {
  931. return _getAttrList(unescape(srcTag));
  932. }
  933. function _mediaEmbed(attrs) {
  934. var html = '<embed ';
  935. _each(attrs, function(key, val) {
  936. html += key + '="' + val + '" ';
  937. });
  938. html += '/>';
  939. return html;
  940. }
  941. function _mediaImg(blankPath, attrs) {
  942. var width = attrs.width,
  943. height = attrs.height,
  944. type = attrs.type || _mediaType(attrs.src),
  945. srcTag = _mediaEmbed(attrs),
  946. style = '';
  947. if (/\D/.test(width)) {
  948. style += 'width:' + width + ';';
  949. } else if (width > 0) {
  950. style += 'width:' + width + 'px;';
  951. }
  952. if (/\D/.test(height)) {
  953. style += 'height:' + height + ';';
  954. } else if (height > 0) {
  955. style += 'height:' + height + 'px;';
  956. }
  957. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  958. if (style !== '') {
  959. html += 'style="' + style + '" ';
  960. }
  961. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  962. return html;
  963. }
  964. function _tmpl(str, data) {
  965. var fn = new Function("obj",
  966. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  967. "with(obj){p.push('" +
  968. str.replace(/[\r\t\n]/g, " ")
  969. .split("<%").join("\t")
  970. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  971. .replace(/\t=(.*?)%>/g, "',$1,'")
  972. .split("\t").join("');")
  973. .split("%>").join("p.push('")
  974. .split("\r").join("\\'") + "');}return p.join('');");
  975. return data ? fn(data) : fn;
  976. }
  977. K.formatUrl = _formatUrl;
  978. K.formatHtml = _formatHtml;
  979. K.getCssList = _getCssList;
  980. K.getAttrList = _getAttrList;
  981. K.mediaType = _mediaType;
  982. K.mediaAttrs = _mediaAttrs;
  983. K.mediaEmbed = _mediaEmbed;
  984. K.mediaImg = _mediaImg;
  985. K.clearMsWord = _clearMsWord;
  986. K.tmpl = _tmpl;
  987. function _contains(nodeA, nodeB) {
  988. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  989. return true;
  990. }
  991. while ((nodeB = nodeB.parentNode)) {
  992. if (nodeB == nodeA) {
  993. return true;
  994. }
  995. }
  996. return false;
  997. }
  998. var _getSetAttrDiv = document.createElement('div');
  999. _getSetAttrDiv.setAttribute('className', 't');
  1000. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1001. function _getAttr(el, key) {
  1002. key = key.toLowerCase();
  1003. var val = null;
  1004. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1005. var div = el.ownerDocument.createElement('div');
  1006. div.appendChild(el.cloneNode(false));
  1007. var list = _getAttrList(_unescape(div.innerHTML));
  1008. if (key in list) {
  1009. val = list[key];
  1010. }
  1011. } else {
  1012. try {
  1013. val = el.getAttribute(key, 2);
  1014. } catch(e) {
  1015. val = el.getAttribute(key, 1);
  1016. }
  1017. }
  1018. if (key === 'style' && val !== null) {
  1019. val = _formatCss(val);
  1020. }
  1021. return val;
  1022. }
  1023. function _queryAll(expr, root) {
  1024. var exprList = expr.split(',');
  1025. if (exprList.length > 1) {
  1026. var mergedResults = [];
  1027. _each(exprList, function() {
  1028. _each(_queryAll(this, root), function() {
  1029. if (_inArray(this, mergedResults) < 0) {
  1030. mergedResults.push(this);
  1031. }
  1032. });
  1033. });
  1034. return mergedResults;
  1035. }
  1036. root = root || document;
  1037. function escape(str) {
  1038. if (typeof str != 'string') {
  1039. return str;
  1040. }
  1041. return str.replace(/([^\w\-])/g, '\\$1');
  1042. }
  1043. function stripslashes(str) {
  1044. return str.replace(/\\/g, '');
  1045. }
  1046. function cmpTag(tagA, tagB) {
  1047. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1048. }
  1049. function byId(id, tag, root) {
  1050. var arr = [],
  1051. doc = root.ownerDocument || root,
  1052. el = doc.getElementById(stripslashes(id));
  1053. if (el) {
  1054. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1055. arr.push(el);
  1056. }
  1057. }
  1058. return arr;
  1059. }
  1060. function byClass(className, tag, root) {
  1061. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1062. if (root.getElementsByClassName) {
  1063. els = root.getElementsByClassName(stripslashes(className));
  1064. for (i = 0, len = els.length; i < len; i++) {
  1065. el = els[i];
  1066. if (cmpTag(tag, el.nodeName)) {
  1067. arr.push(el);
  1068. }
  1069. }
  1070. } else if (doc.querySelectorAll) {
  1071. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1072. for (i = 0, len = els.length; i < len; i++) {
  1073. el = els[i];
  1074. if (_contains(root, el)) {
  1075. arr.push(el);
  1076. }
  1077. }
  1078. } else {
  1079. els = root.getElementsByTagName(tag);
  1080. className = ' ' + className + ' ';
  1081. for (i = 0, len = els.length; i < len; i++) {
  1082. el = els[i];
  1083. if (el.nodeType == 1) {
  1084. var cls = el.className;
  1085. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1086. arr.push(el);
  1087. }
  1088. }
  1089. }
  1090. }
  1091. return arr;
  1092. }
  1093. function byName(name, tag, root) {
  1094. var arr = [], doc = root.ownerDocument || root,
  1095. els = doc.getElementsByName(stripslashes(name)), el;
  1096. for (var i = 0, len = els.length; i < len; i++) {
  1097. el = els[i];
  1098. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1099. if (el.getAttribute('name') !== null) {
  1100. arr.push(el);
  1101. }
  1102. }
  1103. }
  1104. return arr;
  1105. }
  1106. function byAttr(key, val, tag, root) {
  1107. var arr = [], els = root.getElementsByTagName(tag), el;
  1108. for (var i = 0, len = els.length; i < len; i++) {
  1109. el = els[i];
  1110. if (el.nodeType == 1) {
  1111. if (val === null) {
  1112. if (_getAttr(el, key) !== null) {
  1113. arr.push(el);
  1114. }
  1115. } else {
  1116. if (val === escape(_getAttr(el, key))) {
  1117. arr.push(el);
  1118. }
  1119. }
  1120. }
  1121. }
  1122. return arr;
  1123. }
  1124. function select(expr, root) {
  1125. var arr = [], matches;
  1126. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1127. var tag = matches ? matches[1] : '*';
  1128. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1129. arr = byId(matches[1], tag, root);
  1130. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1131. arr = byClass(matches[1], tag, root);
  1132. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1133. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1134. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1135. var key = matches[1].toLowerCase(), val = matches[2];
  1136. if (key === 'id') {
  1137. arr = byId(val, tag, root);
  1138. } else if (key === 'class') {
  1139. arr = byClass(val, tag, root);
  1140. } else if (key === 'name') {
  1141. arr = byName(val, tag, root);
  1142. } else {
  1143. arr = byAttr(key, val, tag, root);
  1144. }
  1145. } else {
  1146. var els = root.getElementsByTagName(tag), el;
  1147. for (var i = 0, len = els.length; i < len; i++) {
  1148. el = els[i];
  1149. if (el.nodeType == 1) {
  1150. arr.push(el);
  1151. }
  1152. }
  1153. }
  1154. return arr;
  1155. }
  1156. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1157. while ((arr = re.exec(expr))) {
  1158. if (arr[1] !== ' ') {
  1159. parts.push(arr[1]);
  1160. }
  1161. }
  1162. var results = [];
  1163. if (parts.length == 1) {
  1164. return select(parts[0], root);
  1165. }
  1166. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1167. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1168. part = parts[i];
  1169. if (part === '>') {
  1170. isChild = true;
  1171. continue;
  1172. }
  1173. if (i > 0) {
  1174. els = [];
  1175. for (j = 0, len = results.length; j < len; j++) {
  1176. val = results[j];
  1177. subResults = select(part, val);
  1178. for (k = 0, l = subResults.length; k < l; k++) {
  1179. v = subResults[k];
  1180. if (isChild) {
  1181. if (val === v.parentNode) {
  1182. els.push(v);
  1183. }
  1184. } else {
  1185. els.push(v);
  1186. }
  1187. }
  1188. }
  1189. results = els;
  1190. } else {
  1191. results = select(part, root);
  1192. }
  1193. if (results.length === 0) {
  1194. return [];
  1195. }
  1196. }
  1197. return results;
  1198. }
  1199. function _query(expr, root) {
  1200. var arr = _queryAll(expr, root);
  1201. return arr.length > 0 ? arr[0] : null;
  1202. }
  1203. K.query = _query;
  1204. K.queryAll = _queryAll;
  1205. function _get(val) {
  1206. return K(val)[0];
  1207. }
  1208. function _getDoc(node) {
  1209. if (!node) {
  1210. return document;
  1211. }
  1212. return node.ownerDocument || node.document || node;
  1213. }
  1214. function _getWin(node) {
  1215. if (!node) {
  1216. return window;
  1217. }
  1218. var doc = _getDoc(node);
  1219. return doc.parentWindow || doc.defaultView;
  1220. }
  1221. function _setHtml(el, html) {
  1222. if (el.nodeType != 1) {
  1223. return;
  1224. }
  1225. var doc = _getDoc(el);
  1226. try {
  1227. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1228. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1229. temp.parentNode.removeChild(temp);
  1230. } catch(e) {
  1231. K(el).empty();
  1232. K('@' + html, doc).each(function() {
  1233. el.appendChild(this);
  1234. });
  1235. }
  1236. }
  1237. function _hasClass(el, cls) {
  1238. return _inString(cls, el.className, ' ');
  1239. }
  1240. function _setAttr(el, key, val) {
  1241. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1242. key = 'className';
  1243. }
  1244. el.setAttribute(key, '' + val);
  1245. }
  1246. function _removeAttr(el, key) {
  1247. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1248. key = 'className';
  1249. }
  1250. _setAttr(el, key, '');
  1251. el.removeAttribute(key);
  1252. }
  1253. function _getNodeName(node) {
  1254. if (!node || !node.nodeName) {
  1255. return '';
  1256. }
  1257. return node.nodeName.toLowerCase();
  1258. }
  1259. function _computedCss(el, key) {
  1260. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1261. if (win.getComputedStyle) {
  1262. var style = win.getComputedStyle(el, null);
  1263. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1264. } else if (el.currentStyle) {
  1265. val = el.currentStyle[camelKey] || el.style[camelKey];
  1266. }
  1267. return val;
  1268. }
  1269. function _hasVal(node) {
  1270. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1271. }
  1272. function _docElement(doc) {
  1273. doc = doc || document;
  1274. return _QUIRKS ? doc.body : doc.documentElement;
  1275. }
  1276. function _docHeight(doc) {
  1277. var el = _docElement(doc);
  1278. return Math.max(el.scrollHeight, el.clientHeight);
  1279. }
  1280. function _docWidth(doc) {
  1281. var el = _docElement(doc);
  1282. return Math.max(el.scrollWidth, el.clientWidth);
  1283. }
  1284. function _getScrollPos(doc) {
  1285. doc = doc || document;
  1286. var x, y;
  1287. if (_IE || _NEWIE || _OPERA) {
  1288. x = _docElement(doc).scrollLeft;
  1289. y = _docElement(doc).scrollTop;
  1290. } else {
  1291. x = _getWin(doc).scrollX;
  1292. y = _getWin(doc).scrollY;
  1293. }
  1294. return {x : x, y : y};
  1295. }
  1296. function KNode(node) {
  1297. this.init(node);
  1298. }
  1299. _extend(KNode, {
  1300. init : function(node) {
  1301. var self = this;
  1302. node = _isArray(node) ? node : [node];
  1303. var length = 0;
  1304. for (var i = 0, len = node.length; i < len; i++) {
  1305. if (node[i]) {
  1306. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1307. length++;
  1308. }
  1309. }
  1310. self.length = length;
  1311. self.doc = _getDoc(self[0]);
  1312. self.name = _getNodeName(self[0]);
  1313. self.type = self.length > 0 ? self[0].nodeType : null;
  1314. self.win = _getWin(self[0]);
  1315. },
  1316. each : function(fn) {
  1317. var self = this;
  1318. for (var i = 0; i < self.length; i++) {
  1319. if (fn.call(self[i], i, self[i]) === false) {
  1320. return self;
  1321. }
  1322. }
  1323. return self;
  1324. },
  1325. bind : function(type, fn) {
  1326. this.each(function() {
  1327. _bind(this, type, fn);
  1328. });
  1329. return this;
  1330. },
  1331. unbind : function(type, fn) {
  1332. this.each(function() {
  1333. _unbind(this, type, fn);
  1334. });
  1335. return this;
  1336. },
  1337. fire : function(type) {
  1338. if (this.length < 1) {
  1339. return this;
  1340. }
  1341. _fire(this[0], type);
  1342. return this;
  1343. },
  1344. hasAttr : function(key) {
  1345. if (this.length < 1) {
  1346. return false;
  1347. }
  1348. return !!_getAttr(this[0], key);
  1349. },
  1350. attr : function(key, val) {
  1351. var self = this;
  1352. if (key === undefined) {
  1353. return _getAttrList(self.outer());
  1354. }
  1355. if (typeof key === 'object') {
  1356. _each(key, function(k, v) {
  1357. self.attr(k, v);
  1358. });
  1359. return self;
  1360. }
  1361. if (val === undefined) {
  1362. val = self.length < 1 ? null : _getAttr(self[0], key);
  1363. return val === null ? '' : val;
  1364. }
  1365. self.each(function() {
  1366. _setAttr(this, key, val);
  1367. });
  1368. return self;
  1369. },
  1370. removeAttr : function(key) {
  1371. this.each(function() {
  1372. _removeAttr(this, key);
  1373. });
  1374. return this;
  1375. },
  1376. get : function(i) {
  1377. if (this.length < 1) {
  1378. return null;
  1379. }
  1380. return this[i || 0];
  1381. },
  1382. eq : function(i) {
  1383. if (this.length < 1) {
  1384. return null;
  1385. }
  1386. return this[i] ? new KNode(this[i]) : null;
  1387. },
  1388. hasClass : function(cls) {
  1389. if (this.length < 1) {
  1390. return false;
  1391. }
  1392. return _hasClass(this[0], cls);
  1393. },
  1394. addClass : function(cls) {
  1395. this.each(function() {
  1396. if (!_hasClass(this, cls)) {
  1397. this.className = _trim(this.className + ' ' + cls);
  1398. }
  1399. });
  1400. return this;
  1401. },
  1402. removeClass : function(cls) {
  1403. this.each(function() {
  1404. if (_hasClass(this, cls)) {
  1405. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1406. }
  1407. });
  1408. return this;
  1409. },
  1410. html : function(val) {
  1411. var self = this;
  1412. if (val === undefined) {
  1413. if (self.length < 1 || self.type != 1) {
  1414. return '';
  1415. }
  1416. return _formatHtml(self[0].innerHTML);
  1417. }
  1418. self.each(function() {
  1419. _setHtml(this, val);
  1420. });
  1421. return self;
  1422. },
  1423. text : function() {
  1424. var self = this;
  1425. if (self.length < 1) {
  1426. return '';
  1427. }
  1428. return _IE ? self[0].innerText : self[0].textContent;
  1429. },
  1430. hasVal : function() {
  1431. if (this.length < 1) {
  1432. return false;
  1433. }
  1434. return _hasVal(this[0]);
  1435. },
  1436. val : function(val) {
  1437. var self = this;
  1438. if (val === undefined) {
  1439. if (self.length < 1) {
  1440. return '';
  1441. }
  1442. return self.hasVal() ? self[0].value : self.attr('value');
  1443. } else {
  1444. self.each(function() {
  1445. if (_hasVal(this)) {
  1446. this.value = val;
  1447. } else {
  1448. _setAttr(this, 'value' , val);
  1449. }
  1450. });
  1451. return self;
  1452. }
  1453. },
  1454. css : function(key, val) {
  1455. var self = this;
  1456. if (key === undefined) {
  1457. return _getCssList(self.attr('style'));
  1458. }
  1459. if (typeof key === 'object') {
  1460. _each(key, function(k, v) {
  1461. self.css(k, v);
  1462. });
  1463. return self;
  1464. }
  1465. if (val === undefined) {
  1466. if (self.length < 1) {
  1467. return '';
  1468. }
  1469. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1470. }
  1471. self.each(function() {
  1472. this.style[_toCamel(key)] = val;
  1473. });
  1474. return self;
  1475. },
  1476. width : function(val) {
  1477. var self = this;
  1478. if (val === undefined) {
  1479. if (self.length < 1) {
  1480. return 0;
  1481. }
  1482. return self[0].offsetWidth;
  1483. }
  1484. return self.css('width', _addUnit(val));
  1485. },
  1486. height : function(val) {
  1487. var self = this;
  1488. if (val === undefined) {
  1489. if (self.length < 1) {
  1490. return 0;
  1491. }
  1492. return self[0].offsetHeight;
  1493. }
  1494. return self.css('height', _addUnit(val));
  1495. },
  1496. opacity : function(val) {
  1497. this.each(function() {
  1498. if (this.style.opacity === undefined) {
  1499. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1500. } else {
  1501. this.style.opacity = val == 1 ? '' : val;
  1502. }
  1503. });
  1504. return this;
  1505. },
  1506. data : function(key, val) {
  1507. var self = this;
  1508. key = 'kindeditor_data_' + key;
  1509. if (val === undefined) {
  1510. if (self.length < 1) {
  1511. return null;
  1512. }
  1513. return self[0][key];
  1514. }
  1515. this.each(function() {
  1516. this[key] = val;
  1517. });
  1518. return self;
  1519. },
  1520. pos : function() {
  1521. var self = this, node = self[0], x = 0, y = 0;
  1522. if (node) {
  1523. if (node.getBoundingClientRect) {
  1524. var box = node.getBoundingClientRect(),
  1525. pos = _getScrollPos(self.doc);
  1526. x = box.left + pos.x;
  1527. y = box.top + pos.y;
  1528. } else {
  1529. while (node) {
  1530. x += node.offsetLeft;
  1531. y += node.offsetTop;
  1532. node = node.offsetParent;
  1533. }
  1534. }
  1535. }
  1536. return {x : _round(x), y : _round(y)};
  1537. },
  1538. clone : function(bool) {
  1539. if (this.length < 1) {
  1540. return new KNode([]);
  1541. }
  1542. return new KNode(this[0].cloneNode(bool));
  1543. },
  1544. append : function(expr) {
  1545. this.each(function() {
  1546. if (this.appendChild) {
  1547. this.appendChild(_get(expr));
  1548. }
  1549. });
  1550. return this;
  1551. },
  1552. appendTo : function(expr) {
  1553. this.each(function() {
  1554. _get(expr).appendChild(this);
  1555. });
  1556. return this;
  1557. },
  1558. before : function(expr) {
  1559. this.each(function() {
  1560. this.parentNode.insertBefore(_get(expr), this);
  1561. });
  1562. return this;
  1563. },
  1564. after : function(expr) {
  1565. this.each(function() {
  1566. if (this.nextSibling) {
  1567. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1568. } else {
  1569. this.parentNode.appendChild(_get(expr));
  1570. }
  1571. });
  1572. return this;
  1573. },
  1574. replaceWith : function(expr) {
  1575. var nodes = [];
  1576. this.each(function(i, node) {
  1577. _unbind(node);
  1578. var newNode = _get(expr);
  1579. node.parentNode.replaceChild(newNode, node);
  1580. nodes.push(newNode);
  1581. });
  1582. return K(nodes);
  1583. },
  1584. empty : function() {
  1585. var self = this;
  1586. self.each(function(i, node) {
  1587. var child = node.firstChild;
  1588. while (child) {
  1589. if (!node.parentNode) {
  1590. return;
  1591. }
  1592. var next = child.nextSibling;
  1593. child.parentNode.removeChild(child);
  1594. child = next;
  1595. }
  1596. });
  1597. return self;
  1598. },
  1599. remove : function(keepChilds) {
  1600. var self = this;
  1601. self.each(function(i, node) {
  1602. if (!node.parentNode) {
  1603. return;
  1604. }
  1605. _unbind(node);
  1606. if (keepChilds) {
  1607. var child = node.firstChild;
  1608. while (child) {
  1609. var next = child.nextSibling;
  1610. node.parentNode.insertBefore(child, node);
  1611. child = next;
  1612. }
  1613. }
  1614. node.parentNode.removeChild(node);
  1615. delete self[i];
  1616. });
  1617. self.length = 0;
  1618. return self;
  1619. },
  1620. show : function(val) {
  1621. var self = this;
  1622. if (val === undefined) {
  1623. val = self._originDisplay || '';
  1624. }
  1625. if (self.css('display') != 'none') {
  1626. return self;
  1627. }
  1628. return self.css('display', val);
  1629. },
  1630. hide : function() {
  1631. var self = this;
  1632. if (self.length < 1) {
  1633. return self;
  1634. }
  1635. self._originDisplay = self[0].style.display;
  1636. return self.css('display', 'none');
  1637. },
  1638. outer : function() {
  1639. var self = this;
  1640. if (self.length < 1) {
  1641. return '';
  1642. }
  1643. var div = self.doc.createElement('div'), html;
  1644. div.appendChild(self[0].cloneNode(true));
  1645. html = _formatHtml(div.innerHTML);
  1646. div = null;
  1647. return html;
  1648. },
  1649. isSingle : function() {
  1650. return !!_SINGLE_TAG_MAP[this.name];
  1651. },
  1652. isInline : function() {
  1653. return !!_INLINE_TAG_MAP[this.name];
  1654. },
  1655. isBlock : function() {
  1656. return !!_BLOCK_TAG_MAP[this.name];
  1657. },
  1658. isStyle : function() {
  1659. return !!_STYLE_TAG_MAP[this.name];
  1660. },
  1661. isControl : function() {
  1662. return !!_CONTROL_TAG_MAP[this.name];
  1663. },
  1664. contains : function(otherNode) {
  1665. if (this.length < 1) {
  1666. return false;
  1667. }
  1668. return _contains(this[0], _get(otherNode));
  1669. },
  1670. parent : function() {
  1671. if (this.length < 1) {
  1672. return null;
  1673. }
  1674. var node = this[0].parentNode;
  1675. return node ? new KNode(node) : null;
  1676. },
  1677. children : function() {
  1678. if (this.length < 1) {
  1679. return new KNode([]);
  1680. }
  1681. var list = [], child = this[0].firstChild;
  1682. while (child) {
  1683. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1684. list.push(child);
  1685. }
  1686. child = child.nextSibling;
  1687. }
  1688. return new KNode(list);
  1689. },
  1690. first : function() {
  1691. var list = this.children();
  1692. return list.length > 0 ? list.eq(0) : null;
  1693. },
  1694. last : function() {
  1695. var list = this.children();
  1696. return list.length > 0 ? list.eq(list.length - 1) : null;
  1697. },
  1698. index : function() {
  1699. if (this.length < 1) {
  1700. return -1;
  1701. }
  1702. var i = -1, sibling = this[0];
  1703. while (sibling) {
  1704. i++;
  1705. sibling = sibling.previousSibling;
  1706. }
  1707. return i;
  1708. },
  1709. prev : function() {
  1710. if (this.length < 1) {
  1711. return null;
  1712. }
  1713. var node = this[0].previousSibling;
  1714. return node ? new KNode(node) : null;
  1715. },
  1716. next : function() {
  1717. if (this.length < 1) {
  1718. return null;
  1719. }
  1720. var node = this[0].nextSibling;
  1721. return node ? new KNode(node) : null;
  1722. },
  1723. scan : function(fn, order) {
  1724. if (this.length < 1) {
  1725. return;
  1726. }
  1727. order = (order === undefined) ? true : order;
  1728. function walk(node) {
  1729. var n = order ? node.firstChild : node.lastChild;
  1730. while (n) {
  1731. var next = order ? n.nextSibling : n.previousSibling;
  1732. if (fn(n) === false) {
  1733. return false;
  1734. }
  1735. if (walk(n) === false) {
  1736. return false;
  1737. }
  1738. n = next;
  1739. }
  1740. }
  1741. walk(this[0]);
  1742. return this;
  1743. }
  1744. });
  1745. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1746. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1747. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1748. KNode.prototype[type] = function(fn) {
  1749. return fn ? this.bind(type, fn) : this.fire(type);
  1750. };
  1751. });
  1752. var _K = K;
  1753. K = function(expr, root) {
  1754. if (expr === undefined || expr === null) {
  1755. return;
  1756. }
  1757. function newNode(node) {
  1758. if (!node[0]) {
  1759. node = [];
  1760. }
  1761. return new KNode(node);
  1762. }
  1763. if (typeof expr === 'string') {
  1764. if (root) {
  1765. root = _get(root);
  1766. }
  1767. var length = expr.length;
  1768. if (expr.charAt(0) === '@') {
  1769. expr = expr.substr(1);
  1770. }
  1771. if (expr.length !== length || /<.+>/.test(expr)) {
  1772. var doc = root ? root.ownerDocument || root : document,
  1773. div = doc.createElement('div'), list = [];
  1774. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1775. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1776. var child = div.childNodes[i];
  1777. if (child.id == '__kindeditor_temp_tag__') {
  1778. continue;
  1779. }
  1780. list.push(child);
  1781. }
  1782. return newNode(list);
  1783. }
  1784. return newNode(_queryAll(expr, root));
  1785. }
  1786. if (expr && expr.constructor === KNode) {
  1787. return expr;
  1788. }
  1789. if (expr.toArray) {
  1790. expr = expr.toArray();
  1791. }
  1792. if (_isArray(expr)) {
  1793. return newNode(expr);
  1794. }
  1795. return newNode(_toArray(arguments));
  1796. };
  1797. _each(_K, function(key, val) {
  1798. K[key] = val;
  1799. });
  1800. K.NodeClass = KNode;
  1801. window.KindEditor = K;
  1802. var _START_TO_START = 0,
  1803. _START_TO_END = 1,
  1804. _END_TO_END = 2,
  1805. _END_TO_START = 3,
  1806. _BOOKMARK_ID = 0;
  1807. function _updateCollapsed(range) {
  1808. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1809. return range;
  1810. }
  1811. function _copyAndDelete(range, isCopy, isDelete) {
  1812. var doc = range.doc, nodeList = [];
  1813. function splitTextNode(node, startOffset, endOffset) {
  1814. var length = node.nodeValue.length, centerNode;
  1815. if (isCopy) {
  1816. var cloneNode = node.cloneNode(true);
  1817. if (startOffset > 0) {
  1818. centerNode = cloneNode.splitText(startOffset);
  1819. } else {
  1820. centerNode = cloneNode;
  1821. }
  1822. if (endOffset < length) {
  1823. centerNode.splitText(endOffset - startOffset);
  1824. }
  1825. }
  1826. if (isDelete) {
  1827. var center = node;
  1828. if (startOffset > 0) {
  1829. center = node.splitText(startOffset);
  1830. range.setStart(node, startOffset);
  1831. }
  1832. if (endOffset < length) {
  1833. var right = center.splitText(endOffset - startOffset);
  1834. range.setEnd(right, 0);
  1835. }
  1836. nodeList.push(center);
  1837. }
  1838. return centerNode;
  1839. }
  1840. function removeNodes() {
  1841. if (isDelete) {
  1842. range.up().collapse(true);
  1843. }
  1844. for (var i = 0, len = nodeList.length; i < len; i++) {
  1845. var node = nodeList[i];
  1846. if (node.parentNode) {
  1847. node.parentNode.removeChild(node);
  1848. }
  1849. }
  1850. }
  1851. var copyRange = range.cloneRange().down();
  1852. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1853. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1854. if (ancestor.nodeType == 3) {
  1855. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1856. if (isCopy) {
  1857. frag.appendChild(textNode);
  1858. }
  1859. removeNodes();
  1860. return isCopy ? frag : range;
  1861. }
  1862. function extractNodes(parent, frag) {
  1863. var node = parent.firstChild, nextNode;
  1864. while (node) {
  1865. var testRange = new KRange(doc).selectNode(node);
  1866. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1867. if (start >= 0 && incStart <= 0) {
  1868. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1869. }
  1870. if (incStart >= 0 && incEnd <= 0) {
  1871. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1872. }
  1873. if (incEnd >= 0 && end <= 0) {
  1874. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1875. }
  1876. if (end >= 0) {
  1877. return false;
  1878. }
  1879. nextNode = node.nextSibling;
  1880. if (start > 0) {
  1881. if (node.nodeType == 1) {
  1882. if (incStart >= 0 && incEnd <= 0) {
  1883. if (isCopy) {
  1884. frag.appendChild(node.cloneNode(true));
  1885. }
  1886. if (isDelete) {
  1887. nodeList.push(node);
  1888. }
  1889. } else {
  1890. var childFlag;
  1891. if (isCopy) {
  1892. childFlag = node.cloneNode(false);
  1893. frag.appendChild(childFlag);
  1894. }
  1895. if (extractNodes(node, childFlag) === false) {
  1896. return false;
  1897. }
  1898. }
  1899. } else if (node.nodeType == 3) {
  1900. var textNode;
  1901. if (node == copyRange.startContainer) {
  1902. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1903. } else if (node == copyRange.endContainer) {
  1904. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1905. } else {
  1906. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1907. }
  1908. if (isCopy) {
  1909. try {
  1910. frag.appendChild(textNode);
  1911. } catch(e) {}
  1912. }
  1913. }
  1914. }
  1915. node = nextNode;
  1916. }
  1917. }
  1918. extractNodes(ancestor, frag);
  1919. if (isDelete) {
  1920. range.up().collapse(true);
  1921. }
  1922. for (var i = 0, len = nodeList.length; i < len; i++) {
  1923. var node = nodeList[i];
  1924. if (node.parentNode) {
  1925. node.parentNode.removeChild(node);
  1926. }
  1927. }
  1928. return isCopy ? frag : range;
  1929. }
  1930. function _moveToElementText(range, el) {
  1931. var node = el;
  1932. while (node) {
  1933. var knode = K(node);
  1934. if (knode.name == 'marquee' || knode.name == 'select') {
  1935. return;
  1936. }
  1937. node = node.parentNode;
  1938. }
  1939. try {
  1940. range.moveToElementText(el);
  1941. } catch(e) {}
  1942. }
  1943. function _getStartEnd(rng, isStart) {
  1944. var doc = rng.parentElement().ownerDocument,
  1945. pointRange = rng.duplicate();
  1946. pointRange.collapse(isStart);
  1947. var parent = pointRange.parentElement(),
  1948. nodes = parent.childNodes;
  1949. if (nodes.length === 0) {
  1950. return {node: parent.parentNode, offset: K(parent).index()};
  1951. }
  1952. var startNode = doc, startPos = 0, cmp = -1;
  1953. var testRange = rng.duplicate();
  1954. _moveToElementText(testRange, parent);
  1955. for (var i = 0, len = nodes.length; i < len; i++) {
  1956. var node = nodes[i];
  1957. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1958. if (cmp === 0) {
  1959. return {node: node.parentNode, offset: i};
  1960. }
  1961. if (node.nodeType == 1) {
  1962. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1963. if (knode.isControl()) {
  1964. dummy = doc.createElement('span');
  1965. knode.after(dummy);
  1966. newNode = dummy;
  1967. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1968. }
  1969. _moveToElementText(nodeRange, newNode);
  1970. testRange.setEndPoint('StartToEnd', nodeRange);
  1971. if (cmp > 0) {
  1972. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1973. } else {
  1974. startPos = 0;
  1975. }
  1976. if (dummy) {
  1977. K(dummy).remove();
  1978. }
  1979. } else if (node.nodeType == 3) {
  1980. testRange.moveStart('character', node.nodeValue.length);
  1981. startPos += node.nodeValue.length;
  1982. }
  1983. if (cmp < 0) {
  1984. startNode = node;
  1985. }
  1986. }
  1987. if (cmp < 0 && startNode.nodeType == 1) {
  1988. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1989. }
  1990. if (cmp > 0) {
  1991. while (startNode.nextSibling && startNode.nodeType == 1) {
  1992. startNode = startNode.nextSibling;
  1993. }
  1994. }
  1995. testRange = rng.duplicate();
  1996. _moveToElementText(testRange, parent);
  1997. testRange.setEndPoint('StartToEnd', pointRange);
  1998. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1999. if (cmp > 0 && startNode.nodeType == 3) {
  2000. var prevNode = startNode.previousSibling;
  2001. while (prevNode && prevNode.nodeType == 3) {
  2002. startPos -= prevNode.nodeValue.length;
  2003. prevNode = prevNode.previousSibling;
  2004. }
  2005. }
  2006. return {node: startNode, offset: startPos};
  2007. }
  2008. function _getEndRange(node, offset) {
  2009. var doc = node.ownerDocument || node,
  2010. range = doc.body.createTextRange();
  2011. if (doc == node) {
  2012. range.collapse(true);
  2013. return range;
  2014. }
  2015. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2016. var children = node.childNodes, isStart, child;
  2017. if (offset === 0) {
  2018. child = children[0];
  2019. isStart = true;
  2020. } else {
  2021. child = children[offset - 1];
  2022. isStart = false;
  2023. }
  2024. if (!child) {
  2025. return range;
  2026. }
  2027. if (K(child).name === 'head') {
  2028. if (offset === 1) {
  2029. isStart = true;
  2030. }
  2031. if (offset === 2) {
  2032. isStart = false;
  2033. }
  2034. range.collapse(isStart);
  2035. return range;
  2036. }
  2037. if (child.nodeType == 1) {
  2038. var kchild = K(child), span;
  2039. if (kchild.isControl()) {
  2040. span = doc.createElement('span');
  2041. if (isStart) {
  2042. kchild.before(span);
  2043. } else {
  2044. kchild.after(span);
  2045. }
  2046. child = span;
  2047. }
  2048. _moveToElementText(range, child);
  2049. range.collapse(isStart);
  2050. if (span) {
  2051. K(span).remove();
  2052. }
  2053. return range;
  2054. }
  2055. node = child;
  2056. offset = isStart ? 0 : child.nodeValue.length;
  2057. }
  2058. var dummy = doc.createElement('span');
  2059. K(node).before(dummy);
  2060. _moveToElementText(range, dummy);
  2061. range.moveStart('character', offset);
  2062. K(dummy).remove();
  2063. return range;
  2064. }
  2065. function _toRange(rng) {
  2066. var doc, range;
  2067. function tr2td(start) {
  2068. if (K(start.node).name == 'tr') {
  2069. start.node = start.node.cells[start.offset];
  2070. start.offset = 0;
  2071. }
  2072. }
  2073. if (_IERANGE) {
  2074. if (rng.item) {
  2075. doc = _getDoc(rng.item(0));
  2076. range = new KRange(doc);
  2077. range.selectNode(rng.item(0));
  2078. return range;
  2079. }
  2080. doc = rng.parentElement().ownerDocument;
  2081. var start = _getStartEnd(rng, true),
  2082. end = _getStartEnd(rng, false);
  2083. tr2td(start);
  2084. tr2td(end);
  2085. range = new KRange(doc);
  2086. range.setStart(start.node, start.offset);
  2087. range.setEnd(end.node, end.offset);
  2088. return range;
  2089. }
  2090. var startContainer = rng.startContainer;
  2091. doc = startContainer.ownerDocument || startContainer;
  2092. range = new KRange(doc);
  2093. range.setStart(startContainer, rng.startOffset);
  2094. range.setEnd(rng.endContainer, rng.endOffset);
  2095. return range;
  2096. }
  2097. function KRange(doc) {
  2098. this.init(doc);
  2099. }
  2100. _extend(KRange, {
  2101. init : function(doc) {
  2102. var self = this;
  2103. self.startContainer = doc;
  2104. self.startOffset = 0;
  2105. self.endContainer = doc;
  2106. self.endOffset = 0;
  2107. self.collapsed = true;
  2108. self.doc = doc;
  2109. },
  2110. commonAncestor : function() {
  2111. function getParents(node) {
  2112. var parents = [];
  2113. while (node) {
  2114. parents.push(node);
  2115. node = node.parentNode;
  2116. }
  2117. return parents;
  2118. }
  2119. var parentsA = getParents(this.startContainer),
  2120. parentsB = getParents(this.endContainer),
  2121. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2122. while (++i) {
  2123. parentA = parentsA[lenA - i];
  2124. parentB = parentsB[lenB - i];
  2125. if (!parentA || !parentB || parentA !== parentB) {
  2126. break;
  2127. }
  2128. }
  2129. return parentsA[lenA - i + 1];
  2130. },
  2131. setStart : function(node, offset) {
  2132. var self = this, doc = self.doc;
  2133. self.startContainer = node;
  2134. self.startOffset = offset;
  2135. if (self.endContainer === doc) {
  2136. self.endContainer = node;
  2137. self.endOffset = offset;
  2138. }
  2139. return _updateCollapsed(this);
  2140. },
  2141. setEnd : function(node, offset) {
  2142. var self = this, doc = self.doc;
  2143. self.endContainer = node;
  2144. self.endOffset = offset;
  2145. if (self.startContainer === doc) {
  2146. self.startContainer = node;
  2147. self.startOffset = offset;
  2148. }
  2149. return _updateCollapsed(this);
  2150. },
  2151. setStartBefore : function(node) {
  2152. return this.setStart(node.parentNode || this.doc, K(node).index());
  2153. },
  2154. setStartAfter : function(node) {
  2155. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2156. },
  2157. setEndBefore : function(node) {
  2158. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2159. },
  2160. setEndAfter : function(node) {
  2161. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2162. },
  2163. selectNode : function(node) {
  2164. return this.setStartBefore(node).setEndAfter(node);
  2165. },
  2166. selectNodeContents : function(node) {
  2167. var knode = K(node);
  2168. if (knode.type == 3 || knode.isSingle()) {
  2169. return this.selectNode(node);
  2170. }
  2171. var children = knode.children();
  2172. if (children.length > 0) {
  2173. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2174. }
  2175. return this.setStart(node, 0).setEnd(node, 0);
  2176. },
  2177. collapse : function(toStart) {
  2178. if (toStart) {
  2179. return this.setEnd(this.startContainer, this.startOffset);
  2180. }
  2181. return this.setStart(this.endContainer, this.endOffset);
  2182. },
  2183. compareBoundaryPoints : function(how, range) {
  2184. var rangeA = this.get(), rangeB = range.get();
  2185. if (_IERANGE) {
  2186. var arr = {};
  2187. arr[_START_TO_START] = 'StartToStart';
  2188. arr[_START_TO_END] = 'EndToStart';
  2189. arr[_END_TO_END] = 'EndToEnd';
  2190. arr[_END_TO_START] = 'StartToEnd';
  2191. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2192. if (cmp !== 0) {
  2193. return cmp;
  2194. }
  2195. var nodeA, nodeB, nodeC, posA, posB;
  2196. if (how === _START_TO_START || how === _END_TO_START) {
  2197. nodeA = this.startContainer;
  2198. posA = this.startOffset;
  2199. }
  2200. if (how === _START_TO_END || how === _END_TO_END) {
  2201. nodeA = this.endContainer;
  2202. posA = this.endOffset;
  2203. }
  2204. if (how === _START_TO_START || how === _START_TO_END) {
  2205. nodeB = range.startContainer;
  2206. posB = range.startOffset;
  2207. }
  2208. if (how === _END_TO_END || how === _END_TO_START) {
  2209. nodeB = range.endContainer;
  2210. posB = range.endOffset;
  2211. }
  2212. if (nodeA === nodeB) {
  2213. var diff = posA - posB;
  2214. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2215. }
  2216. nodeC = nodeB;
  2217. while (nodeC && nodeC.parentNode !== nodeA) {
  2218. nodeC = nodeC.parentNode;
  2219. }
  2220. if (nodeC) {
  2221. return K(nodeC).index() >= posA ? -1 : 1;
  2222. }
  2223. nodeC = nodeA;
  2224. while (nodeC && nodeC.parentNode !== nodeB) {
  2225. nodeC = nodeC.parentNode;
  2226. }
  2227. if (nodeC) {
  2228. return K(nodeC).index() >= posB ? 1 : -1;
  2229. }
  2230. nodeC = K(nodeB).next();
  2231. if (nodeC && nodeC.contains(nodeA)) {
  2232. return 1;
  2233. }
  2234. nodeC = K(nodeA).next();
  2235. if (nodeC && nodeC.contains(nodeB)) {
  2236. return -1;
  2237. }
  2238. } else {
  2239. return rangeA.compareBoundaryPoints(how, rangeB);
  2240. }
  2241. },
  2242. cloneRange : function() {
  2243. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2244. },
  2245. toString : function() {
  2246. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2247. return str.replace(/\r\n|\n|\r/g, '');
  2248. },
  2249. cloneContents : function() {
  2250. return _copyAndDelete(this, true, false);
  2251. },
  2252. deleteContents : function() {
  2253. return _copyAndDelete(this, false, true);
  2254. },
  2255. extractContents : function() {
  2256. return _copyAndDelete(this, true, true);
  2257. },
  2258. insertNode : function(node) {
  2259. var self = this,
  2260. sc = self.startContainer, so = self.startOffset,
  2261. ec = self.endContainer, eo = self.endOffset,
  2262. firstChild, lastChild, c, nodeCount = 1;
  2263. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2264. firstChild = node.firstChild;
  2265. lastChild = node.lastChild;
  2266. nodeCount = node.childNodes.length;
  2267. }
  2268. if (sc.nodeType == 1) {
  2269. c = sc.childNodes[so];
  2270. if (c) {
  2271. sc.insertBefore(node, c);
  2272. if (sc === ec) {
  2273. eo += nodeCount;
  2274. }
  2275. } else {
  2276. sc.appendChild(node);
  2277. }
  2278. } else if (sc.nodeType == 3) {
  2279. if (so === 0) {
  2280. sc.parentNode.insertBefore(node, sc);
  2281. if (sc.parentNode === ec) {
  2282. eo += nodeCount;
  2283. }
  2284. } else if (so >= sc.nodeValue.length) {
  2285. if (sc.nextSibling) {
  2286. sc.parentNode.insertBefore(node, sc.nextSibling);
  2287. } else {
  2288. sc.parentNode.appendChild(node);
  2289. }
  2290. } else {
  2291. if (so > 0) {
  2292. c = sc.splitText(so);
  2293. } else {
  2294. c = sc;
  2295. }
  2296. sc.parentNode.insertBefore(node, c);
  2297. if (sc === ec) {
  2298. ec = c;
  2299. eo -= so;
  2300. }
  2301. }
  2302. }
  2303. if (firstChild) {
  2304. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2305. } else {
  2306. self.selectNode(node);
  2307. }
  2308. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2309. return self;
  2310. }
  2311. return self.setEnd(ec, eo);
  2312. },
  2313. surroundContents : function(node) {
  2314. node.appendChild(this.extractContents());
  2315. return this.insertNode(node).selectNode(node);
  2316. },
  2317. isControl : function() {
  2318. var self = this,
  2319. sc = self.startContainer, so = self.startOffset,
  2320. ec = self.endContainer, eo = self.endOffset, rng;
  2321. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2322. },
  2323. get : function(hasControlRange) {
  2324. var self = this, doc = self.doc, node, rng;
  2325. if (!_IERANGE) {
  2326. rng = doc.createRange();
  2327. try {
  2328. rng.setStart(self.startContainer, self.startOffset);
  2329. rng.setEnd(self.endContainer, self.endOffset);
  2330. } catch (e) {}
  2331. return rng;
  2332. }
  2333. if (hasControlRange && self.isControl()) {
  2334. rng = doc.body.createControlRange();
  2335. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2336. return rng;
  2337. }
  2338. var range = self.cloneRange().down();
  2339. rng = doc.body.createTextRange();
  2340. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2341. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2342. return rng;
  2343. },
  2344. html : function() {
  2345. return K(this.cloneContents()).outer();
  2346. },
  2347. down : function() {
  2348. var self = this;
  2349. function downPos(node, pos, isStart) {
  2350. if (node.nodeType != 1) {
  2351. return;
  2352. }
  2353. var children = K(node).children();
  2354. if (children.length === 0) {
  2355. return;
  2356. }
  2357. var left, right, child, offset;
  2358. if (pos > 0) {
  2359. left = children.eq(pos - 1);
  2360. }
  2361. if (pos < children.length) {
  2362. right = children.eq(pos);
  2363. }
  2364. if (left && left.type == 3) {
  2365. child = left[0];
  2366. offset = child.nodeValue.length;
  2367. }
  2368. if (right && right.type == 3) {
  2369. child = right[0];
  2370. offset = 0;
  2371. }
  2372. if (!child) {
  2373. return;
  2374. }
  2375. if (isStart) {
  2376. self.setStart(child, offset);
  2377. } else {
  2378. self.setEnd(child, offset);
  2379. }
  2380. }
  2381. downPos(self.startContainer, self.startOffset, true);
  2382. downPos(self.endContainer, self.endOffset, false);
  2383. return self;
  2384. },
  2385. up : function() {
  2386. var self = this;
  2387. function upPos(node, pos, isStart) {
  2388. if (node.nodeType != 3) {
  2389. return;
  2390. }
  2391. if (pos === 0) {
  2392. if (isStart) {
  2393. self.setStartBefore(node);
  2394. } else {
  2395. self.setEndBefore(node);
  2396. }
  2397. } else if (pos == node.nodeValue.length) {
  2398. if (isStart) {
  2399. self.setStartAfter(node);
  2400. } else {
  2401. self.setEndAfter(node);
  2402. }
  2403. }
  2404. }
  2405. upPos(self.startContainer, self.startOffset, true);
  2406. upPos(self.endContainer, self.endOffset, false);
  2407. return self;
  2408. },
  2409. enlarge : function(toBlock) {
  2410. var self = this;
  2411. self.up();
  2412. function enlargePos(node, pos, isStart) {
  2413. var knode = K(node), parent;
  2414. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2415. return;
  2416. }
  2417. if (pos === 0) {
  2418. while (!knode.prev()) {
  2419. parent = knode.parent();
  2420. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2421. break;
  2422. }
  2423. knode = parent;
  2424. }
  2425. if (isStart) {
  2426. self.setStartBefore(knode[0]);
  2427. } else {
  2428. self.setEndBefore(knode[0]);
  2429. }
  2430. } else if (pos == knode.children().length) {
  2431. while (!knode.next()) {
  2432. parent = knode.parent();
  2433. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2434. break;
  2435. }
  2436. knode = parent;
  2437. }
  2438. if (isStart) {
  2439. self.setStartAfter(knode[0]);
  2440. } else {
  2441. self.setEndAfter(knode[0]);
  2442. }
  2443. }
  2444. }
  2445. enlargePos(self.startContainer, self.startOffset, true);
  2446. enlargePos(self.endContainer, self.endOffset, false);
  2447. return self;
  2448. },
  2449. shrink : function() {
  2450. var self = this, child, collapsed = self.collapsed;
  2451. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2452. self.setStart(child, 0);
  2453. }
  2454. if (collapsed) {
  2455. return self.collapse(collapsed);
  2456. }
  2457. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2458. self.setEnd(child, child.childNodes.length);
  2459. }
  2460. return self;
  2461. },
  2462. createBookmark : function(serialize) {
  2463. var self = this, doc = self.doc, endNode,
  2464. startNode = K('<span style="display:none;"></span>', doc)[0];
  2465. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2466. if (!self.collapsed) {
  2467. endNode = startNode.cloneNode(true);
  2468. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2469. }
  2470. if (endNode) {
  2471. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2472. }
  2473. self.insertNode(startNode).setStartAfter(startNode);
  2474. return {
  2475. start : serialize ? '#' + startNode.id : startNode,
  2476. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2477. };
  2478. },
  2479. moveToBookmark : function(bookmark) {
  2480. var self = this, doc = self.doc,
  2481. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2482. if (!start || start.length < 1) {
  2483. return self;
  2484. }
  2485. self.setStartBefore(start[0]);
  2486. start.remove();
  2487. if (end && end.length > 0) {
  2488. self.setEndBefore(end[0]);
  2489. end.remove();
  2490. } else {
  2491. self.collapse(true);
  2492. }
  2493. return self;
  2494. },
  2495. dump : function() {
  2496. console.log('--------------------');
  2497. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2498. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2499. }
  2500. });
  2501. function _range(mixed) {
  2502. if (!mixed.nodeName) {
  2503. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2504. }
  2505. return new KRange(mixed);
  2506. }
  2507. K.RangeClass = KRange;
  2508. K.range = _range;
  2509. K.START_TO_START = _START_TO_START;
  2510. K.START_TO_END = _START_TO_END;
  2511. K.END_TO_END = _END_TO_END;
  2512. K.END_TO_START = _END_TO_START;
  2513. function _nativeCommand(doc, key, val) {
  2514. try {
  2515. doc.execCommand(key, false, val);
  2516. } catch(e) {}
  2517. }
  2518. function _nativeCommandValue(doc, key) {
  2519. var val = '';
  2520. try {
  2521. val = doc.queryCommandValue(key);
  2522. } catch (e) {}
  2523. if (typeof val !== 'string') {
  2524. val = '';
  2525. }
  2526. return val;
  2527. }
  2528. function _getSel(doc) {
  2529. var win = _getWin(doc);
  2530. return _IERANGE ? doc.selection : win.getSelection();
  2531. }
  2532. function _getRng(doc) {
  2533. var sel = _getSel(doc), rng;
  2534. try {
  2535. if (sel.rangeCount > 0) {
  2536. rng = sel.getRangeAt(0);
  2537. } else {
  2538. rng = sel.createRange();
  2539. }
  2540. } catch(e) {}
  2541. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2542. return null;
  2543. }
  2544. return rng;
  2545. }
  2546. function _singleKeyMap(map) {
  2547. var newMap = {}, arr, v;
  2548. _each(map, function(key, val) {
  2549. arr = key.split(',');
  2550. for (var i = 0, len = arr.length; i < len; i++) {
  2551. v = arr[i];
  2552. newMap[v] = val;
  2553. }
  2554. });
  2555. return newMap;
  2556. }
  2557. function _hasAttrOrCss(knode, map) {
  2558. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2559. }
  2560. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2561. mapKey = mapKey || knode.name;
  2562. if (knode.type !== 1) {
  2563. return false;
  2564. }
  2565. var newMap = _singleKeyMap(map);
  2566. if (!newMap[mapKey]) {
  2567. return false;
  2568. }
  2569. var arr = newMap[mapKey].split(',');
  2570. for (var i = 0, len = arr.length; i < len; i++) {
  2571. var key = arr[i];
  2572. if (key === '*') {
  2573. return true;
  2574. }
  2575. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2576. var method = match[1] ? 'css' : 'attr';
  2577. key = match[2];
  2578. var val = match[3] || '';
  2579. if (val === '' && knode[method](key) !== '') {
  2580. return true;
  2581. }
  2582. if (val !== '' && knode[method](key) === val) {
  2583. return true;
  2584. }
  2585. }
  2586. return false;
  2587. }
  2588. function _removeAttrOrCss(knode, map) {
  2589. if (knode.type != 1) {
  2590. return;
  2591. }
  2592. _removeAttrOrCssByKey(knode, map, '*');
  2593. _removeAttrOrCssByKey(knode, map);
  2594. }
  2595. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2596. mapKey = mapKey || knode.name;
  2597. if (knode.type !== 1) {
  2598. return;
  2599. }
  2600. var newMap = _singleKeyMap(map);
  2601. if (!newMap[mapKey]) {
  2602. return;
  2603. }
  2604. var arr = newMap[mapKey].split(','), allFlag = false;
  2605. for (var i = 0, len = arr.length; i < len; i++) {
  2606. var key = arr[i];
  2607. if (key === '*') {
  2608. allFlag = true;
  2609. break;
  2610. }
  2611. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2612. key = match[2];
  2613. if (match[1]) {
  2614. key = _toCamel(key);
  2615. if (knode[0].style[key]) {
  2616. knode[0].style[key] = '';
  2617. }
  2618. } else {
  2619. knode.removeAttr(key);
  2620. }
  2621. }
  2622. if (allFlag) {
  2623. knode.remove(true);
  2624. }
  2625. }
  2626. function _getInnerNode(knode) {
  2627. var inner = knode;
  2628. while (inner.first()) {
  2629. inner = inner.first();
  2630. }
  2631. return inner;
  2632. }
  2633. function _isEmptyNode(knode) {
  2634. if (knode.type != 1 || knode.isSingle()) {
  2635. return false;
  2636. }
  2637. return knode.html().replace(/<[^>]+>/g, '') === '';
  2638. }
  2639. function _mergeWrapper(a, b) {
  2640. a = a.clone(true);
  2641. var lastA = _getInnerNode(a), childA = a, merged = false;
  2642. while (b) {
  2643. while (childA) {
  2644. if (childA.name === b.name) {
  2645. _mergeAttrs(childA, b.attr(), b.css());
  2646. merged = true;
  2647. }
  2648. childA = childA.first();
  2649. }
  2650. if (!merged) {
  2651. lastA.append(b.clone(false));
  2652. }
  2653. merged = false;
  2654. b = b.first();
  2655. }
  2656. return a;
  2657. }
  2658. function _wrapNode(knode, wrapper) {
  2659. wrapper = wrapper.clone(true);
  2660. if (knode.type == 3) {
  2661. _getInnerNode(wrapper).append(knode.clone(false));
  2662. knode.replaceWith(wrapper);
  2663. return wrapper;
  2664. }
  2665. var nodeWrapper = knode, child;
  2666. while ((child = knode.first()) && child.children().length == 1) {
  2667. knode = child;
  2668. }
  2669. child = knode.first();
  2670. var frag = knode.doc.createDocumentFragment();
  2671. while (child) {
  2672. frag.appendChild(child[0]);
  2673. child = child.next();
  2674. }
  2675. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2676. if (frag.firstChild) {
  2677. _getInnerNode(wrapper).append(frag);
  2678. }
  2679. nodeWrapper.replaceWith(wrapper);
  2680. return wrapper;
  2681. }
  2682. function _mergeAttrs(knode, attrs, styles) {
  2683. _each(attrs, function(key, val) {
  2684. if (key !== 'style') {
  2685. knode.attr(key, val);
  2686. }
  2687. });
  2688. _each(styles, function(key, val) {
  2689. knode.css(key, val);
  2690. });
  2691. }
  2692. function _inPreElement(knode) {
  2693. while (knode && knode.name != 'body') {
  2694. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2695. return true;
  2696. }
  2697. knode = knode.parent();
  2698. }
  2699. return false;
  2700. }
  2701. function KCmd(range) {
  2702. this.init(range);
  2703. }
  2704. _extend(KCmd, {
  2705. init : function(range) {
  2706. var self = this, doc = range.doc;
  2707. self.doc = doc;
  2708. self.win = _getWin(doc);
  2709. self.sel = _getSel(doc);
  2710. self.range = range;
  2711. },
  2712. selection : function(forceReset) {
  2713. var self = this, doc = self.doc, rng = _getRng(doc);
  2714. self.sel = _getSel(doc);
  2715. if (rng) {
  2716. self.range = _range(rng);
  2717. if (K(self.range.startContainer).name == 'html') {
  2718. self.range.selectNodeContents(doc.body).collapse(false);
  2719. }
  2720. return self;
  2721. }
  2722. if (forceReset) {
  2723. self.range.selectNodeContents(doc.body).collapse(false);
  2724. }
  2725. return self;
  2726. },
  2727. select : function(hasDummy) {
  2728. hasDummy = _undef(hasDummy, true);
  2729. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2730. sc = range.startContainer, so = range.startOffset,
  2731. ec = range.endContainer, eo = range.endOffset,
  2732. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2733. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2734. if (_IERANGE) {
  2735. var dummy = K('<span>&nbsp;</span>', doc);
  2736. range.insertNode(dummy[0]);
  2737. rng = doc.body.createTextRange();
  2738. try {
  2739. rng.moveToElementText(dummy[0]);
  2740. } catch(ex) {}
  2741. rng.collapse(false);
  2742. rng.select();
  2743. dummy.remove();
  2744. win.focus();
  2745. return self;
  2746. }
  2747. if (_WEBKIT) {
  2748. var children = sc.childNodes;
  2749. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2750. range.insertNode(doc.createTextNode('\u200B'));
  2751. hasU200b = true;
  2752. }
  2753. }
  2754. }
  2755. if (_IERANGE) {
  2756. try {
  2757. rng = range.get(true);
  2758. rng.select();
  2759. } catch(e) {}
  2760. } else {
  2761. if (hasU200b) {
  2762. range.collapse(false);
  2763. }
  2764. rng = range.get(true);
  2765. sel.removeAllRanges();
  2766. sel.addRange(rng);
  2767. if (doc !== document) {
  2768. var pos = K(rng.endContainer).pos();
  2769. win.scrollTo(pos.x, pos.y);
  2770. }
  2771. }
  2772. win.focus();
  2773. return self;
  2774. },
  2775. wrap : function(val) {
  2776. var self = this, doc = self.doc, range = self.range, wrapper;
  2777. wrapper = K(val, doc);
  2778. if (range.collapsed) {
  2779. range.shrink();
  2780. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2781. return self;
  2782. }
  2783. if (wrapper.isBlock()) {
  2784. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2785. while (child.first()) {
  2786. child = child.first();
  2787. }
  2788. child.append(range.extractContents());
  2789. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2790. return self;
  2791. }
  2792. range.enlarge();
  2793. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2794. K(ancestor).scan(function(node) {
  2795. if (!isStart && node == bookmark.start) {
  2796. isStart = true;
  2797. return;
  2798. }
  2799. if (isStart) {
  2800. if (node == bookmark.end) {
  2801. return false;
  2802. }
  2803. var knode = K(node);
  2804. if (_inPreElement(knode)) {
  2805. return;
  2806. }
  2807. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2808. var parent;
  2809. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2810. knode = parent;
  2811. }
  2812. _wrapNode(knode, wrapper);
  2813. }
  2814. }
  2815. });
  2816. range.moveToBookmark(bookmark);
  2817. return self;
  2818. },
  2819. split : function(isStart, map) {
  2820. var range = this.range, doc = range.doc;
  2821. var tempRange = range.cloneRange().collapse(isStart);
  2822. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2823. parent = node.nodeType == 3 ? node.parentNode : node,
  2824. needSplit = false, knode;
  2825. while (parent && parent.parentNode) {
  2826. knode = K(parent);
  2827. if (map) {
  2828. if (!knode.isStyle()) {
  2829. break;
  2830. }
  2831. if (!_hasAttrOrCss(knode, map)) {
  2832. break;
  2833. }
  2834. } else {
  2835. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2836. break;
  2837. }
  2838. }
  2839. needSplit = true;
  2840. parent = parent.parentNode;
  2841. }
  2842. if (needSplit) {
  2843. var dummy = doc.createElement('span');
  2844. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2845. if (isStart) {
  2846. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2847. } else {
  2848. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2849. }
  2850. var frag = tempRange.extractContents(),
  2851. first = frag.firstChild, last = frag.lastChild;
  2852. if (isStart) {
  2853. tempRange.insertNode(frag);
  2854. range.setStartAfter(last).setEndBefore(dummy);
  2855. } else {
  2856. parent.appendChild(frag);
  2857. range.setStartBefore(dummy).setEndBefore(first);
  2858. }
  2859. var dummyParent = dummy.parentNode;
  2860. if (dummyParent == range.endContainer) {
  2861. var prev = K(dummy).prev(), next = K(dummy).next();
  2862. if (prev && next && prev.type == 3 && next.type == 3) {
  2863. range.setEnd(prev[0], prev[0].nodeValue.length);
  2864. } else if (!isStart) {
  2865. range.setEnd(range.endContainer, range.endOffset - 1);
  2866. }
  2867. }
  2868. dummyParent.removeChild(dummy);
  2869. }
  2870. return this;
  2871. },
  2872. remove : function(map) {
  2873. var self = this, doc = self.doc, range = self.range;
  2874. range.enlarge();
  2875. if (range.startOffset === 0) {
  2876. var ksc = K(range.startContainer), parent;
  2877. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2878. ksc = parent;
  2879. }
  2880. range.setStart(ksc[0], 0);
  2881. ksc = K(range.startContainer);
  2882. if (ksc.isBlock()) {
  2883. _removeAttrOrCss(ksc, map);
  2884. }
  2885. var kscp = ksc.parent();
  2886. if (kscp && kscp.isBlock()) {
  2887. _removeAttrOrCss(kscp, map);
  2888. }
  2889. }
  2890. var sc, so;
  2891. if (range.collapsed) {
  2892. self.split(true, map);
  2893. sc = range.startContainer;
  2894. so = range.startOffset;
  2895. if (so > 0) {
  2896. var sb = K(sc.childNodes[so - 1]);
  2897. if (sb && _isEmptyNode(sb)) {
  2898. sb.remove();
  2899. range.setStart(sc, so - 1);
  2900. }
  2901. }
  2902. var sa = K(sc.childNodes[so]);
  2903. if (sa && _isEmptyNode(sa)) {
  2904. sa.remove();
  2905. }
  2906. if (_isEmptyNode(sc)) {
  2907. range.startBefore(sc);
  2908. sc.remove();
  2909. }
  2910. range.collapse(true);
  2911. return self;
  2912. }
  2913. self.split(true, map);
  2914. self.split(false, map);
  2915. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2916. range.cloneRange().collapse(false).insertNode(endDummy);
  2917. range.cloneRange().collapse(true).insertNode(startDummy);
  2918. var nodeList = [], cmpStart = false;
  2919. K(range.commonAncestor()).scan(function(node) {
  2920. if (!cmpStart && node == startDummy) {
  2921. cmpStart = true;
  2922. return;
  2923. }
  2924. if (node == endDummy) {
  2925. return false;
  2926. }
  2927. if (cmpStart) {
  2928. nodeList.push(node);
  2929. }
  2930. });
  2931. K(startDummy).remove();
  2932. K(endDummy).remove();
  2933. sc = range.startContainer;
  2934. so = range.startOffset;
  2935. var ec = range.endContainer, eo = range.endOffset;
  2936. if (so > 0) {
  2937. var startBefore = K(sc.childNodes[so - 1]);
  2938. if (startBefore && _isEmptyNode(startBefore)) {
  2939. startBefore.remove();
  2940. range.setStart(sc, so - 1);
  2941. if (sc == ec) {
  2942. range.setEnd(ec, eo - 1);
  2943. }
  2944. }
  2945. var startAfter = K(sc.childNodes[so]);
  2946. if (startAfter && _isEmptyNode(startAfter)) {
  2947. startAfter.remove();
  2948. if (sc == ec) {
  2949. range.setEnd(ec, eo - 1);
  2950. }
  2951. }
  2952. }
  2953. var endAfter = K(ec.childNodes[range.endOffset]);
  2954. if (endAfter && _isEmptyNode(endAfter)) {
  2955. endAfter.remove();
  2956. }
  2957. var bookmark = range.createBookmark(true);
  2958. _each(nodeList, function(i, node) {
  2959. _removeAttrOrCss(K(node), map);
  2960. });
  2961. range.moveToBookmark(bookmark);
  2962. return self;
  2963. },
  2964. commonNode : function(map) {
  2965. var range = this.range;
  2966. var ec = range.endContainer, eo = range.endOffset,
  2967. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2968. function find(node) {
  2969. var child = node, parent = node;
  2970. while (parent) {
  2971. if (_hasAttrOrCss(K(parent), map)) {
  2972. return K(parent);
  2973. }
  2974. parent = parent.parentNode;
  2975. }
  2976. while (child && (child = child.lastChild)) {
  2977. if (_hasAttrOrCss(K(child), map)) {
  2978. return K(child);
  2979. }
  2980. }
  2981. return null;
  2982. }
  2983. var cNode = find(node);
  2984. if (cNode) {
  2985. return cNode;
  2986. }
  2987. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2988. var prev = K(node).prev();
  2989. if (prev) {
  2990. return find(prev);
  2991. }
  2992. }
  2993. return null;
  2994. },
  2995. commonAncestor : function(tagName) {
  2996. var range = this.range,
  2997. sc = range.startContainer, so = range.startOffset,
  2998. ec = range.endContainer, eo = range.endOffset,
  2999. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3000. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3001. function find(node) {
  3002. while (node) {
  3003. if (node.nodeType == 1) {
  3004. if (node.tagName.toLowerCase() === tagName) {
  3005. return node;
  3006. }
  3007. }
  3008. node = node.parentNode;
  3009. }
  3010. return null;
  3011. }
  3012. var start = find(startNode), end = find(endNode);
  3013. if (start && end && start === end) {
  3014. return K(start);
  3015. }
  3016. return null;
  3017. },
  3018. state : function(key) {
  3019. var self = this, doc = self.doc, bool = false;
  3020. try {
  3021. bool = doc.queryCommandState(key);
  3022. } catch (e) {}
  3023. return bool;
  3024. },
  3025. val : function(key) {
  3026. var self = this, doc = self.doc, range = self.range;
  3027. function lc(val) {
  3028. return val.toLowerCase();
  3029. }
  3030. key = lc(key);
  3031. var val = '', knode;
  3032. if (key === 'fontfamily' || key === 'fontname') {
  3033. val = _nativeCommandValue(doc, 'fontname');
  3034. val = val.replace(/['"]/g, '');
  3035. return lc(val);
  3036. }
  3037. if (key === 'formatblock') {
  3038. val = _nativeCommandValue(doc, key);
  3039. if (val === '') {
  3040. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3041. if (knode) {
  3042. val = knode.name;
  3043. }
  3044. }
  3045. if (val === 'Normal') {
  3046. val = 'p';
  3047. }
  3048. return lc(val);
  3049. }
  3050. if (key === 'fontsize') {
  3051. knode = self.commonNode({'*' : '.font-size'});
  3052. if (knode) {
  3053. val = knode.css('font-size');
  3054. }
  3055. return lc(val);
  3056. }
  3057. if (key === 'forecolor') {
  3058. knode = self.commonNode({'*' : '.color'});
  3059. if (knode) {
  3060. val = knode.css('color');
  3061. }
  3062. val = _toHex(val);
  3063. if (val === '') {
  3064. val = 'default';
  3065. }
  3066. return lc(val);
  3067. }
  3068. if (key === 'hilitecolor') {
  3069. knode = self.commonNode({'*' : '.background-color'});
  3070. if (knode) {
  3071. val = knode.css('background-color');
  3072. }
  3073. val = _toHex(val);
  3074. if (val === '') {
  3075. val = 'default';
  3076. }
  3077. return lc(val);
  3078. }
  3079. return val;
  3080. },
  3081. toggle : function(wrapper, map) {
  3082. var self = this;
  3083. if (self.commonNode(map)) {
  3084. self.remove(map);
  3085. } else {
  3086. self.wrap(wrapper);
  3087. }
  3088. return self.select();
  3089. },
  3090. bold : function() {
  3091. return this.toggle('<strong></strong>', {
  3092. span : '.font-weight=bold',
  3093. strong : '*',
  3094. b : '*'
  3095. });
  3096. },
  3097. italic : function() {
  3098. return this.toggle('<em></em>', {
  3099. span : '.font-style=italic',
  3100. em : '*',
  3101. i : '*'
  3102. });
  3103. },
  3104. underline : function() {
  3105. return this.toggle('<u></u>', {
  3106. span : '.text-decoration=underline',
  3107. u : '*'
  3108. });
  3109. },
  3110. strikethrough : function() {
  3111. return this.toggle('<s></s>', {
  3112. span : '.text-decoration=line-through',
  3113. s : '*'
  3114. });
  3115. },
  3116. forecolor : function(val) {
  3117. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3118. },
  3119. hilitecolor : function(val) {
  3120. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3121. },
  3122. fontsize : function(val) {
  3123. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3124. },
  3125. fontname : function(val) {
  3126. return this.fontfamily(val);
  3127. },
  3128. fontfamily : function(val) {
  3129. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3130. },
  3131. removeformat : function() {
  3132. var map = {
  3133. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3134. },
  3135. tags = _STYLE_TAG_MAP;
  3136. _each(tags, function(key, val) {
  3137. map[key] = '*';
  3138. });
  3139. this.remove(map);
  3140. return this.select();
  3141. },
  3142. inserthtml : function(val, quickMode) {
  3143. var self = this, range = self.range;
  3144. if (val === '') {
  3145. return self;
  3146. }
  3147. function pasteHtml(range, val) {
  3148. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3149. var rng = range.get();
  3150. if (rng.item) {
  3151. rng.item(0).outerHTML = val;
  3152. } else {
  3153. rng.pasteHTML(val);
  3154. }
  3155. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3156. temp.parentNode.removeChild(temp);
  3157. var newRange = _toRange(rng);
  3158. range.setEnd(newRange.endContainer, newRange.endOffset);
  3159. range.collapse(false);
  3160. self.select(false);
  3161. }
  3162. function insertHtml(range, val) {
  3163. var doc = range.doc,
  3164. frag = doc.createDocumentFragment();
  3165. K('@' + val, doc).each(function() {
  3166. frag.appendChild(this);
  3167. });
  3168. range.deleteContents();
  3169. range.insertNode(frag);
  3170. range.collapse(false);
  3171. self.select(false);
  3172. }
  3173. if (_IERANGE && quickMode) {
  3174. try {
  3175. pasteHtml(range, val);
  3176. } catch(e) {
  3177. insertHtml(range, val);
  3178. }
  3179. return self;
  3180. }
  3181. insertHtml(range, val);
  3182. return self;
  3183. },
  3184. hr : function() {
  3185. return this.inserthtml('<hr />');
  3186. },
  3187. print : function() {
  3188. this.win.print();
  3189. return this;
  3190. },
  3191. insertimage : function(url, title, width, height, border, align) {
  3192. title = _undef(title, '');
  3193. border = _undef(border, 0);
  3194. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3195. if (width) {
  3196. html += 'width="' + _escape(width) + '" ';
  3197. }
  3198. if (height) {
  3199. html += 'height="' + _escape(height) + '" ';
  3200. }
  3201. if (title) {
  3202. html += 'title="' + _escape(title) + '" ';
  3203. }
  3204. if (align) {
  3205. html += 'align="' + _escape(align) + '" ';
  3206. }
  3207. html += 'alt="' + _escape(title) + '" ';
  3208. html += '/>';
  3209. return this.inserthtml(html);
  3210. },
  3211. createlink : function(url, type) {
  3212. var self = this, doc = self.doc, range = self.range;
  3213. self.select();
  3214. var a = self.commonNode({ a : '*' });
  3215. if (a && !range.isControl()) {
  3216. range.selectNode(a.get());
  3217. self.select();
  3218. }
  3219. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3220. if (type) {
  3221. html += ' target="' + _escape(type) + '"';
  3222. }
  3223. if (range.collapsed) {
  3224. html += '>' + _escape(url) + '</a>';
  3225. return self.inserthtml(html);
  3226. }
  3227. if (range.isControl()) {
  3228. var node = K(range.startContainer.childNodes[range.startOffset]);
  3229. html += '></a>';
  3230. node.after(K(html, doc));
  3231. node.next().append(node);
  3232. range.selectNode(node[0]);
  3233. return self.select();
  3234. }
  3235. function setAttr(node, url, type) {
  3236. K(node).attr('href', url).attr('data-ke-src', url);
  3237. if (type) {
  3238. K(node).attr('target', type);
  3239. } else {
  3240. K(node).removeAttr('target');
  3241. }
  3242. }
  3243. var sc = range.startContainer, so = range.startOffset,
  3244. ec = range.endContainer, eo = range.endOffset;
  3245. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3246. var child = sc.childNodes[so];
  3247. if (child.nodeName.toLowerCase() == 'a') {
  3248. setAttr(child, url, type);
  3249. return self;
  3250. }
  3251. }
  3252. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3253. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3254. setAttr(this, url, type);
  3255. });
  3256. return self;
  3257. },
  3258. unlink : function() {
  3259. var self = this, doc = self.doc, range = self.range;
  3260. self.select();
  3261. if (range.collapsed) {
  3262. var a = self.commonNode({ a : '*' });
  3263. if (a) {
  3264. range.selectNode(a.get());
  3265. self.select();
  3266. }
  3267. _nativeCommand(doc, 'unlink', null);
  3268. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3269. var parent = K(range.startContainer).parent();
  3270. if (parent.name === 'a') {
  3271. parent.remove(true);
  3272. }
  3273. }
  3274. } else {
  3275. _nativeCommand(doc, 'unlink', null);
  3276. }
  3277. return self;
  3278. }
  3279. });
  3280. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3281. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3282. KCmd.prototype[name] = function(val) {
  3283. var self = this;
  3284. self.select();
  3285. _nativeCommand(self.doc, name, val);
  3286. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3287. self.selection();
  3288. }
  3289. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3290. self.selection();
  3291. }
  3292. return self;
  3293. };
  3294. });
  3295. _each('cut,copy,paste'.split(','), function(i, name) {
  3296. KCmd.prototype[name] = function() {
  3297. var self = this;
  3298. if (!self.doc.queryCommandSupported(name)) {
  3299. throw 'not supported';
  3300. }
  3301. self.select();
  3302. _nativeCommand(self.doc, name, null);
  3303. return self;
  3304. };
  3305. });
  3306. function _cmd(mixed) {
  3307. if (mixed.nodeName) {
  3308. var doc = _getDoc(mixed);
  3309. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3310. }
  3311. return new KCmd(mixed);
  3312. }
  3313. K.CmdClass = KCmd;
  3314. K.cmd = _cmd;
  3315. function _drag(options) {
  3316. var moveEl = options.moveEl,
  3317. moveFn = options.moveFn,
  3318. clickEl = options.clickEl || moveEl,
  3319. beforeDrag = options.beforeDrag,
  3320. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3321. var docs = [document];
  3322. if (iframeFix) {
  3323. K('iframe').each(function() {
  3324. var src = _formatUrl(this.src || '', 'absolute');
  3325. if (/^https?:\/\//.test(src)) {
  3326. return;
  3327. }
  3328. var doc;
  3329. try {
  3330. doc = _iframeDoc(this);
  3331. } catch(e) {}
  3332. if (doc) {
  3333. var pos = K(this).pos();
  3334. K(doc).data('pos-x', pos.x);
  3335. K(doc).data('pos-y', pos.y);
  3336. docs.push(doc);
  3337. }
  3338. });
  3339. }
  3340. clickEl.mousedown(function(e) {
  3341. if(e.button !== 0 && e.button !== 1) {
  3342. return;
  3343. }
  3344. e.stopPropagation();
  3345. var self = clickEl.get(),
  3346. x = _removeUnit(moveEl.css('left')),
  3347. y = _removeUnit(moveEl.css('top')),
  3348. width = moveEl.width(),
  3349. height = moveEl.height(),
  3350. pageX = e.pageX,
  3351. pageY = e.pageY;
  3352. if (beforeDrag) {
  3353. beforeDrag();
  3354. }
  3355. function moveListener(e) {
  3356. e.preventDefault();
  3357. var kdoc = K(_getDoc(e.target));
  3358. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3359. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3360. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3361. }
  3362. function selectListener(e) {
  3363. e.preventDefault();
  3364. }
  3365. function upListener(e) {
  3366. e.preventDefault();
  3367. K(docs).unbind('mousemove', moveListener)
  3368. .unbind('mouseup', upListener)
  3369. .unbind('selectstart', selectListener);
  3370. if (self.releaseCapture) {
  3371. self.releaseCapture();
  3372. }
  3373. }
  3374. K(docs).mousemove(moveListener)
  3375. .mouseup(upListener)
  3376. .bind('selectstart', selectListener);
  3377. if (self.setCapture) {
  3378. self.setCapture();
  3379. }
  3380. });
  3381. }
  3382. function KWidget(options) {
  3383. this.init(options);
  3384. }
  3385. _extend(KWidget, {
  3386. init : function(options) {
  3387. var self = this;
  3388. self.name = options.name || '';
  3389. self.doc = options.doc || document;
  3390. self.win = _getWin(self.doc);
  3391. self.x = _addUnit(options.x);
  3392. self.y = _addUnit(options.y);
  3393. self.z = options.z;
  3394. self.width = _addUnit(options.width);
  3395. self.height = _addUnit(options.height);
  3396. self.index = _addUnit(options.index);
  3397. self.div = K('<div style="display:block;"></div>');
  3398. self.options = options;
  3399. self._alignEl = options.alignEl;
  3400. if (self.width) {
  3401. self.div.css('width', self.width);
  3402. }
  3403. if (self.height) {
  3404. self.div.css('height', self.height);
  3405. }
  3406. if (self.z) {
  3407. self.div.css({
  3408. position : 'absolute',
  3409. left : self.x,
  3410. top : self.y,
  3411. 'z-index' : self.z
  3412. });
  3413. }
  3414. if (self.z && (self.x === undefined || self.y === undefined)) {
  3415. self.autoPos(self.width, self.height);
  3416. }
  3417. if (options.cls) {
  3418. self.div.addClass(options.cls);
  3419. }
  3420. if (options.shadowMode) {
  3421. self.div.addClass('ke-shadow');
  3422. }
  3423. if (options.css) {
  3424. self.div.css(options.css);
  3425. }
  3426. if (options.src) {
  3427. K(options.src).replaceWith(self.div);
  3428. } else {
  3429. K(self.doc.body).append(self.div);
  3430. }
  3431. if (options.html) {
  3432. self.div.html(options.html);
  3433. }
  3434. if (options.autoScroll) {
  3435. if (_IE && _V < 7 || _QUIRKS) {
  3436. var scrollPos = _getScrollPos();
  3437. K(self.win).bind('scroll', function(e) {
  3438. var pos = _getScrollPos(),
  3439. diffX = pos.x - scrollPos.x,
  3440. diffY = pos.y - scrollPos.y;
  3441. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3442. });
  3443. } else {
  3444. self.div.css('position', 'fixed');
  3445. }
  3446. }
  3447. },
  3448. pos : function(x, y, updateProp) {
  3449. var self = this;
  3450. updateProp = _undef(updateProp, true);
  3451. if (x !== null) {
  3452. x = x < 0 ? 0 : _addUnit(x);
  3453. self.div.css('left', x);
  3454. if (updateProp) {
  3455. self.x = x;
  3456. }
  3457. }
  3458. if (y !== null) {
  3459. y = y < 0 ? 0 : _addUnit(y);
  3460. self.div.css('top', y);
  3461. if (updateProp) {
  3462. self.y = y;
  3463. }
  3464. }
  3465. return self;
  3466. },
  3467. autoPos : function(width, height) {
  3468. var x, y, self = this,
  3469. w = _removeUnit(width) || 0,
  3470. h = _removeUnit(height) || 0,
  3471. scrollPos = _getScrollPos();
  3472. if (self._alignEl) {
  3473. var knode = K(self._alignEl),
  3474. pos = knode.pos(),
  3475. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3476. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3477. x = diffX < 0 ? pos.x : pos.x + diffX;
  3478. y = diffY < 0 ? pos.y : pos.y + diffY;
  3479. } else {
  3480. var docEl = _docElement(self.doc);
  3481. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3482. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3483. }
  3484. if (!(_IE && _V < 7 || _QUIRKS)) {
  3485. x -= scrollPos.x;
  3486. y -= scrollPos.y;
  3487. }
  3488. return self.pos(x, y);
  3489. },
  3490. remove : function() {
  3491. var self = this;
  3492. if (_IE && _V < 7 || _QUIRKS) {
  3493. K(self.win).unbind('scroll');
  3494. }
  3495. self.div.remove();
  3496. _each(self, function(i) {
  3497. self[i] = null;
  3498. });
  3499. return this;
  3500. },
  3501. show : function() {
  3502. this.div.show();
  3503. return this;
  3504. },
  3505. hide : function() {
  3506. this.div.hide();
  3507. return this;
  3508. },
  3509. draggable : function(options) {
  3510. var self = this;
  3511. options = options || {};
  3512. options.moveEl = self.div;
  3513. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3514. if ((x = x + diffX) < 0) {
  3515. x = 0;
  3516. }
  3517. if ((y = y + diffY) < 0) {
  3518. y = 0;
  3519. }
  3520. self.pos(x, y);
  3521. };
  3522. _drag(options);
  3523. return self;
  3524. }
  3525. });
  3526. function _widget(options) {
  3527. return new KWidget(options);
  3528. }
  3529. K.WidgetClass = KWidget;
  3530. K.widget = _widget;
  3531. function _iframeDoc(iframe) {
  3532. iframe = _get(iframe);
  3533. return iframe.contentDocument || iframe.contentWindow.document;
  3534. }
  3535. var html, _direction = '';
  3536. if ((html = document.getElementsByTagName('html'))) {
  3537. _direction = html[0].dir;
  3538. }
  3539. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3540. var arr = [
  3541. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3542. '<head><meta charset="utf-8" /><title></title>',
  3543. '<style>',
  3544. 'html {margin:0;padding:0;}',
  3545. 'body {margin:0;padding:5px;}',
  3546. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3547. 'body, p, div {word-wrap: break-word;}',
  3548. 'p {margin:5px 0;}',
  3549. 'table {border-collapse:collapse;}',
  3550. 'img {border:0;}',
  3551. 'noscript {display:none;}',
  3552. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3553. 'img.ke-flash {',
  3554. ' border:1px solid #AAA;',
  3555. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3556. ' background-position:center center;',
  3557. ' background-repeat:no-repeat;',
  3558. ' width:100px;',
  3559. ' height:100px;',
  3560. '}',
  3561. 'img.ke-rm {',
  3562. ' border:1px solid #AAA;',
  3563. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3564. ' background-position:center center;',
  3565. ' background-repeat:no-repeat;',
  3566. ' width:100px;',
  3567. ' height:100px;',
  3568. '}',
  3569. 'img.ke-media {',
  3570. ' border:1px solid #AAA;',
  3571. ' background-image:url(' + themesPath + 'common/media.gif);',
  3572. ' background-position:center center;',
  3573. ' background-repeat:no-repeat;',
  3574. ' width:100px;',
  3575. ' height:100px;',
  3576. '}',
  3577. 'img.ke-anchor {',
  3578. ' border:1px dashed #666;',
  3579. ' width:16px;',
  3580. ' height:16px;',
  3581. '}',
  3582. '.ke-script, .ke-noscript, .ke-display-none {',
  3583. ' display:none;',
  3584. ' font-size:0;',
  3585. ' width:0;',
  3586. ' height:0;',
  3587. '}',
  3588. '.ke-pagebreak {',
  3589. ' border:1px dotted #AAA;',
  3590. ' font-size:0;',
  3591. ' height:2px;',
  3592. '}',
  3593. '</style>'
  3594. ];
  3595. if (!_isArray(cssPath)) {
  3596. cssPath = [cssPath];
  3597. }
  3598. _each(cssPath, function(i, path) {
  3599. if (path) {
  3600. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3601. }
  3602. });
  3603. if (cssData) {
  3604. arr.push('<style>' + cssData + '</style>');
  3605. }
  3606. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3607. return arr.join('\n');
  3608. }
  3609. function _elementVal(knode, val) {
  3610. if (knode.hasVal()) {
  3611. if (val === undefined) {
  3612. var html = knode.val();
  3613. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3614. return html;
  3615. }
  3616. return knode.val(val);
  3617. }
  3618. return knode.html(val);
  3619. }
  3620. function KEdit(options) {
  3621. this.init(options);
  3622. }
  3623. _extend(KEdit, KWidget, {
  3624. init : function(options) {
  3625. var self = this;
  3626. KEdit.parent.init.call(self, options);
  3627. self.srcElement = K(options.srcElement);
  3628. self.div.addClass('ke-edit');
  3629. self.designMode = _undef(options.designMode, true);
  3630. self.beforeGetHtml = options.beforeGetHtml;
  3631. self.beforeSetHtml = options.beforeSetHtml;
  3632. self.afterSetHtml = options.afterSetHtml;
  3633. var themesPath = _undef(options.themesPath, ''),
  3634. bodyClass = options.bodyClass,
  3635. cssPath = options.cssPath,
  3636. cssData = options.cssData,
  3637. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3638. srcScript = ('document.open();' +
  3639. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3640. 'document.close();'),
  3641. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3642. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3643. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3644. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3645. self.iframe.attr('tabindex', self.tabIndex);
  3646. self.textarea.attr('tabindex', self.tabIndex);
  3647. if (self.width) {
  3648. self.setWidth(self.width);
  3649. }
  3650. if (self.height) {
  3651. self.setHeight(self.height);
  3652. }
  3653. if (self.designMode) {
  3654. self.textarea.hide();
  3655. } else {
  3656. self.iframe.hide();
  3657. }
  3658. function ready() {
  3659. var doc = _iframeDoc(self.iframe);
  3660. doc.open();
  3661. if (isDocumentDomain) {
  3662. doc.domain = document.domain;
  3663. }
  3664. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3665. doc.close();
  3666. self.win = self.iframe[0].contentWindow;
  3667. self.doc = doc;
  3668. var cmd = _cmd(doc);
  3669. self.afterChange(function(e) {
  3670. cmd.selection();
  3671. });
  3672. if (_WEBKIT) {
  3673. K(doc).click(function(e) {
  3674. if (K(e.target).name === 'img') {
  3675. cmd.selection(true);
  3676. cmd.range.selectNode(e.target);
  3677. cmd.select();
  3678. }
  3679. });
  3680. }
  3681. if (_IE) {
  3682. self._mousedownHandler = function() {
  3683. var newRange = cmd.range.cloneRange();
  3684. newRange.shrink();
  3685. if (newRange.isControl()) {
  3686. self.blur();
  3687. }
  3688. };
  3689. K(document).mousedown(self._mousedownHandler);
  3690. K(doc).keydown(function(e) {
  3691. if (e.which == 8) {
  3692. cmd.selection();
  3693. var rng = cmd.range;
  3694. if (rng.isControl()) {
  3695. rng.collapse(true);
  3696. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3697. e.preventDefault();
  3698. }
  3699. }
  3700. });
  3701. }
  3702. self.cmd = cmd;
  3703. self.html(_elementVal(self.srcElement));
  3704. if (_IE) {
  3705. doc.body.disabled = true;
  3706. doc.body.contentEditable = true;
  3707. doc.body.removeAttribute('disabled');
  3708. } else {
  3709. doc.designMode = 'on';
  3710. }
  3711. if (options.afterCreate) {
  3712. options.afterCreate.call(self);
  3713. }
  3714. }
  3715. if (isDocumentDomain) {
  3716. self.iframe.bind('load', function(e) {
  3717. self.iframe.unbind('load');
  3718. if (_IE) {
  3719. ready();
  3720. } else {
  3721. setTimeout(ready, 0);
  3722. }
  3723. });
  3724. }
  3725. self.div.append(self.iframe);
  3726. self.div.append(self.textarea);
  3727. self.srcElement.hide();
  3728. !isDocumentDomain && ready();
  3729. },
  3730. setWidth : function(val) {
  3731. var self = this;
  3732. val = _addUnit(val);
  3733. self.width = val;
  3734. self.div.css('width', val);
  3735. return self;
  3736. },
  3737. setHeight : function(val) {
  3738. var self = this;
  3739. val = _addUnit(val);
  3740. self.height = val;
  3741. self.div.css('height', val);
  3742. self.iframe.css('height', val);
  3743. if ((_IE && _V < 8) || _QUIRKS) {
  3744. val = _addUnit(_removeUnit(val) - 2);
  3745. }
  3746. self.textarea.css('height', val);
  3747. return self;
  3748. },
  3749. remove : function() {
  3750. var self = this, doc = self.doc;
  3751. K(doc.body).unbind();
  3752. K(doc).unbind();
  3753. K(self.win).unbind();
  3754. if (self._mousedownHandler) {
  3755. K(document).unbind('mousedown', self._mousedownHandler);
  3756. }
  3757. _elementVal(self.srcElement, self.html());
  3758. self.srcElement.show();
  3759. self.iframe.unbind();
  3760. self.textarea.unbind();
  3761. KEdit.parent.remove.call(self);
  3762. },
  3763. html : function(val, isFull) {
  3764. var self = this, doc = self.doc;
  3765. if (self.designMode) {
  3766. var body = doc.body;
  3767. if (val === undefined) {
  3768. if (isFull) {
  3769. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3770. } else {
  3771. val = body.innerHTML;
  3772. }
  3773. if (self.beforeGetHtml) {
  3774. val = self.beforeGetHtml(val);
  3775. }
  3776. if (_GECKO && val == '<br />') {
  3777. val = '';
  3778. }
  3779. return val;
  3780. }
  3781. if (self.beforeSetHtml) {
  3782. val = self.beforeSetHtml(val);
  3783. }
  3784. if (_IE && _V >= 9) {
  3785. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3786. }
  3787. K(body).html(val);
  3788. if (self.afterSetHtml) {
  3789. self.afterSetHtml();
  3790. }
  3791. return self;
  3792. }
  3793. if (val === undefined) {
  3794. return self.textarea.val();
  3795. }
  3796. self.textarea.val(val);
  3797. return self;
  3798. },
  3799. design : function(bool) {
  3800. var self = this, val;
  3801. if (bool === undefined ? !self.designMode : bool) {
  3802. if (!self.designMode) {
  3803. val = self.html();
  3804. self.designMode = true;
  3805. self.textarea.hide();
  3806. self.html(val);
  3807. var iframe = self.iframe;
  3808. var height = _removeUnit(self.height);
  3809. iframe.height(height - 2);
  3810. iframe.show();
  3811. setTimeout(function() {
  3812. iframe.height(height);
  3813. }, 0);
  3814. }
  3815. } else {
  3816. if (self.designMode) {
  3817. val = self.html();
  3818. self.designMode = false;
  3819. self.html(val);
  3820. self.iframe.hide();
  3821. self.textarea.show();
  3822. }
  3823. }
  3824. return self.focus();
  3825. },
  3826. focus : function() {
  3827. var self = this;
  3828. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3829. return self;
  3830. },
  3831. blur : function() {
  3832. var self = this;
  3833. if (_IE) {
  3834. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3835. self.div.append(input);
  3836. input[0].focus();
  3837. input.remove();
  3838. } else {
  3839. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3840. }
  3841. return self;
  3842. },
  3843. afterChange : function(fn) {
  3844. var self = this, doc = self.doc, body = doc.body;
  3845. K(doc).keyup(function(e) {
  3846. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3847. fn(e);
  3848. }
  3849. });
  3850. K(doc).mouseup(fn).contextmenu(fn);
  3851. K(self.win).blur(fn);
  3852. function timeoutHandler(e) {
  3853. setTimeout(function() {
  3854. fn(e);
  3855. }, 1);
  3856. }
  3857. K(body).bind('paste', timeoutHandler);
  3858. K(body).bind('cut', timeoutHandler);
  3859. return self;
  3860. }
  3861. });
  3862. function _edit(options) {
  3863. return new KEdit(options);
  3864. }
  3865. K.EditClass = KEdit;
  3866. K.edit = _edit;
  3867. K.iframeDoc = _iframeDoc;
  3868. function _selectToolbar(name, fn) {
  3869. var self = this,
  3870. knode = self.get(name);
  3871. if (knode) {
  3872. if (knode.hasClass('ke-disabled')) {
  3873. return;
  3874. }
  3875. fn(knode);
  3876. }
  3877. }
  3878. function KToolbar(options) {
  3879. this.init(options);
  3880. }
  3881. _extend(KToolbar, KWidget, {
  3882. init : function(options) {
  3883. var self = this;
  3884. KToolbar.parent.init.call(self, options);
  3885. self.disableMode = _undef(options.disableMode, false);
  3886. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3887. self._itemMap = {};
  3888. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3889. e.preventDefault();
  3890. }).attr('unselectable', 'on');
  3891. function find(target) {
  3892. var knode = K(target);
  3893. if (knode.hasClass('ke-outline')) {
  3894. return knode;
  3895. }
  3896. if (knode.hasClass('ke-toolbar-icon')) {
  3897. return knode.parent();
  3898. }
  3899. }
  3900. function hover(e, method) {
  3901. var knode = find(e.target);
  3902. if (knode) {
  3903. if (knode.hasClass('ke-disabled')) {
  3904. return;
  3905. }
  3906. if (knode.hasClass('ke-selected')) {
  3907. return;
  3908. }
  3909. knode[method]('ke-on');
  3910. }
  3911. }
  3912. self.div.mouseover(function(e) {
  3913. hover(e, 'addClass');
  3914. })
  3915. .mouseout(function(e) {
  3916. hover(e, 'removeClass');
  3917. })
  3918. .click(function(e) {
  3919. var knode = find(e.target);
  3920. if (knode) {
  3921. if (knode.hasClass('ke-disabled')) {
  3922. return;
  3923. }
  3924. self.options.click.call(this, e, knode.attr('data-name'));
  3925. }
  3926. });
  3927. },
  3928. get : function(name) {
  3929. if (this._itemMap[name]) {
  3930. return this._itemMap[name];
  3931. }
  3932. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3933. },
  3934. select : function(name) {
  3935. _selectToolbar.call(this, name, function(knode) {
  3936. knode.addClass('ke-selected');
  3937. });
  3938. return self;
  3939. },
  3940. unselect : function(name) {
  3941. _selectToolbar.call(this, name, function(knode) {
  3942. knode.removeClass('ke-selected').removeClass('ke-on');
  3943. });
  3944. return self;
  3945. },
  3946. enable : function(name) {
  3947. var self = this,
  3948. knode = name.get ? name : self.get(name);
  3949. if (knode) {
  3950. knode.removeClass('ke-disabled');
  3951. knode.opacity(1);
  3952. }
  3953. return self;
  3954. },
  3955. disable : function(name) {
  3956. var self = this,
  3957. knode = name.get ? name : self.get(name);
  3958. if (knode) {
  3959. knode.removeClass('ke-selected').addClass('ke-disabled');
  3960. knode.opacity(0.5);
  3961. }
  3962. return self;
  3963. },
  3964. disableAll : function(bool, noDisableItems) {
  3965. var self = this, map = self.noDisableItemMap, item;
  3966. if (noDisableItems) {
  3967. map = _toMap(noDisableItems);
  3968. }
  3969. if (bool === undefined ? !self.disableMode : bool) {
  3970. K('span.ke-outline', self.div).each(function() {
  3971. var knode = K(this),
  3972. name = knode[0].getAttribute('data-name', 2);
  3973. if (!map[name]) {
  3974. self.disable(knode);
  3975. }
  3976. });
  3977. self.disableMode = true;
  3978. } else {
  3979. K('span.ke-outline', self.div).each(function() {
  3980. var knode = K(this),
  3981. name = knode[0].getAttribute('data-name', 2);
  3982. if (!map[name]) {
  3983. self.enable(knode);
  3984. }
  3985. });
  3986. self.disableMode = false;
  3987. }
  3988. return self;
  3989. }
  3990. });
  3991. function _toolbar(options) {
  3992. return new KToolbar(options);
  3993. }
  3994. K.ToolbarClass = KToolbar;
  3995. K.toolbar = _toolbar;
  3996. function KMenu(options) {
  3997. this.init(options);
  3998. }
  3999. _extend(KMenu, KWidget, {
  4000. init : function(options) {
  4001. var self = this;
  4002. options.z = options.z || 811213;
  4003. KMenu.parent.init.call(self, options);
  4004. self.centerLineMode = _undef(options.centerLineMode, true);
  4005. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4006. e.stopPropagation();
  4007. }).attr('unselectable', 'on');
  4008. },
  4009. addItem : function(item) {
  4010. var self = this;
  4011. if (item.title === '-') {
  4012. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4013. return;
  4014. }
  4015. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4016. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4017. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4018. height = _addUnit(item.height),
  4019. iconClass = _undef(item.iconClass, '');
  4020. self.div.append(itemDiv);
  4021. if (height) {
  4022. itemDiv.css('height', height);
  4023. rightDiv.css('line-height', height);
  4024. }
  4025. var centerDiv;
  4026. if (self.centerLineMode) {
  4027. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4028. if (height) {
  4029. centerDiv.css('height', height);
  4030. }
  4031. }
  4032. itemDiv.mouseover(function(e) {
  4033. K(this).addClass('ke-menu-item-on');
  4034. if (centerDiv) {
  4035. centerDiv.addClass('ke-menu-item-center-on');
  4036. }
  4037. })
  4038. .mouseout(function(e) {
  4039. K(this).removeClass('ke-menu-item-on');
  4040. if (centerDiv) {
  4041. centerDiv.removeClass('ke-menu-item-center-on');
  4042. }
  4043. })
  4044. .click(function(e) {
  4045. item.click.call(K(this));
  4046. e.stopPropagation();
  4047. })
  4048. .append(leftDiv);
  4049. if (centerDiv) {
  4050. itemDiv.append(centerDiv);
  4051. }
  4052. itemDiv.append(rightDiv);
  4053. if (item.checked) {
  4054. iconClass = 'ke-icon-checked';
  4055. }
  4056. if (iconClass !== '') {
  4057. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4058. }
  4059. rightDiv.html(item.title);
  4060. return self;
  4061. },
  4062. remove : function() {
  4063. var self = this;
  4064. if (self.options.beforeRemove) {
  4065. self.options.beforeRemove.call(self);
  4066. }
  4067. K('.ke-menu-item', self.div[0]).unbind();
  4068. KMenu.parent.remove.call(self);
  4069. return self;
  4070. }
  4071. });
  4072. function _menu(options) {
  4073. return new KMenu(options);
  4074. }
  4075. K.MenuClass = KMenu;
  4076. K.menu = _menu;
  4077. function KColorPicker(options) {
  4078. this.init(options);
  4079. }
  4080. _extend(KColorPicker, KWidget, {
  4081. init : function(options) {
  4082. var self = this;
  4083. options.z = options.z || 811213;
  4084. KColorPicker.parent.init.call(self, options);
  4085. var colors = options.colors || [
  4086. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4087. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4088. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4089. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4090. ];
  4091. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4092. self._cells = [];
  4093. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4094. e.stopPropagation();
  4095. }).attr('unselectable', 'on');
  4096. var table = self.doc.createElement('table');
  4097. self.div.append(table);
  4098. table.className = 'ke-colorpicker-table';
  4099. table.cellPadding = 0;
  4100. table.cellSpacing = 0;
  4101. table.border = 0;
  4102. var row = table.insertRow(0), cell = row.insertCell(0);
  4103. cell.colSpan = colors[0].length;
  4104. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4105. for (var i = 0; i < colors.length; i++) {
  4106. row = table.insertRow(i + 1);
  4107. for (var j = 0; j < colors[i].length; j++) {
  4108. cell = row.insertCell(j);
  4109. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4110. }
  4111. }
  4112. },
  4113. _addAttr : function(cell, color, cls) {
  4114. var self = this;
  4115. cell = K(cell).addClass(cls);
  4116. if (self.selectedColor === color.toLowerCase()) {
  4117. cell.addClass('ke-colorpicker-cell-selected');
  4118. }
  4119. cell.attr('title', color || self.options.noColor);
  4120. cell.mouseover(function(e) {
  4121. K(this).addClass('ke-colorpicker-cell-on');
  4122. });
  4123. cell.mouseout(function(e) {
  4124. K(this).removeClass('ke-colorpicker-cell-on');
  4125. });
  4126. cell.click(function(e) {
  4127. e.stop();
  4128. self.options.click.call(K(this), color);
  4129. });
  4130. if (color) {
  4131. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4132. } else {
  4133. cell.html(self.options.noColor);
  4134. }
  4135. K(cell).attr('unselectable', 'on');
  4136. self._cells.push(cell);
  4137. },
  4138. remove : function() {
  4139. var self = this;
  4140. _each(self._cells, function() {
  4141. this.unbind();
  4142. });
  4143. KColorPicker.parent.remove.call(self);
  4144. return self;
  4145. }
  4146. });
  4147. function _colorpicker(options) {
  4148. return new KColorPicker(options);
  4149. }
  4150. K.ColorPickerClass = KColorPicker;
  4151. K.colorpicker = _colorpicker;
  4152. function KUploadButton(options) {
  4153. this.init(options);
  4154. }
  4155. _extend(KUploadButton, {
  4156. init : function(options) {
  4157. var self = this,
  4158. button = K(options.button),
  4159. fieldName = options.fieldName || 'file',
  4160. url = options.url || '',
  4161. title = button.val(),
  4162. extraParams = options.extraParams || {},
  4163. cls = button[0].className || '',
  4164. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4165. options.afterError = options.afterError || function(str) {
  4166. alert(str);
  4167. };
  4168. var hiddenElements = [];
  4169. for(var k in extraParams){
  4170. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4171. }
  4172. var html = [
  4173. '<div class="ke-inline-block ' + cls + '">',
  4174. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4175. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4176. '<span class="ke-button-common">',
  4177. hiddenElements.join(''),
  4178. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4179. '</span>',
  4180. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4181. (options.form ? '</div>' : '</form>'),
  4182. '</div>'].join('');
  4183. var div = K(html, button.doc);
  4184. button.hide();
  4185. button.before(div);
  4186. self.div = div;
  4187. self.button = button;
  4188. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4189. self.form = options.form ? K(options.form) : K('form', div);
  4190. self.fileBox = K('.ke-upload-file', div);
  4191. var width = options.width || K('.ke-button-common', div).width();
  4192. K('.ke-upload-area', div).width(width);
  4193. self.options = options;
  4194. },
  4195. submit : function() {
  4196. var self = this,
  4197. iframe = self.iframe;
  4198. iframe.bind('load', function() {
  4199. iframe.unbind();
  4200. var tempForm = document.createElement('form');
  4201. self.fileBox.before(tempForm);
  4202. K(tempForm).append(self.fileBox);
  4203. tempForm.reset();
  4204. K(tempForm).remove(true);
  4205. var doc = K.iframeDoc(iframe),
  4206. pre = doc.getElementsByTagName('pre')[0],
  4207. str = '', data;
  4208. if (pre) {
  4209. str = pre.innerHTML;
  4210. } else {
  4211. str = doc.body.innerHTML;
  4212. }
  4213. str = _unescape(str);
  4214. iframe[0].src = 'javascript:false';
  4215. try {
  4216. data = K.json(str);
  4217. } catch (e) {
  4218. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4219. }
  4220. if (data) {
  4221. self.options.afterUpload.call(self, data);
  4222. }
  4223. });
  4224. self.form[0].submit();
  4225. return self;
  4226. },
  4227. remove : function() {
  4228. var self = this;
  4229. if (self.fileBox) {
  4230. self.fileBox.unbind();
  4231. }
  4232. self.iframe.remove();
  4233. self.div.remove();
  4234. self.button.show();
  4235. return self;
  4236. }
  4237. });
  4238. function _uploadbutton(options) {
  4239. return new KUploadButton(options);
  4240. }
  4241. K.UploadButtonClass = KUploadButton;
  4242. K.uploadbutton = _uploadbutton;
  4243. function _createButton(arg) {
  4244. arg = arg || {};
  4245. var name = arg.name || '',
  4246. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4247. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4248. if (arg.click) {
  4249. btn.click(arg.click);
  4250. }
  4251. span.append(btn);
  4252. return span;
  4253. }
  4254. function KDialog(options) {
  4255. this.init(options);
  4256. }
  4257. _extend(KDialog, KWidget, {
  4258. init : function(options) {
  4259. var self = this;
  4260. var shadowMode = _undef(options.shadowMode, true);
  4261. options.z = options.z || 811213;
  4262. options.shadowMode = false;
  4263. options.autoScroll = _undef(options.autoScroll, true);
  4264. KDialog.parent.init.call(self, options);
  4265. var title = options.title,
  4266. body = K(options.body, self.doc),
  4267. previewBtn = options.previewBtn,
  4268. yesBtn = options.yesBtn,
  4269. noBtn = options.noBtn,
  4270. closeBtn = options.closeBtn,
  4271. showMask = _undef(options.showMask, true);
  4272. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4273. e.stopPropagation();
  4274. });
  4275. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4276. if (_IE && _V < 7) {
  4277. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4278. } else if (shadowMode) {
  4279. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4280. }
  4281. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4282. contentDiv.append(headerDiv);
  4283. headerDiv.html(title);
  4284. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4285. headerDiv.append(self.closeIcon);
  4286. self.draggable({
  4287. clickEl : headerDiv,
  4288. beforeDrag : options.beforeDrag
  4289. });
  4290. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4291. contentDiv.append(bodyDiv);
  4292. bodyDiv.append(body);
  4293. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4294. if (previewBtn || yesBtn || noBtn) {
  4295. contentDiv.append(footerDiv);
  4296. }
  4297. _each([
  4298. { btn : previewBtn, name : 'preview' },
  4299. { btn : yesBtn, name : 'yes' },
  4300. { btn : noBtn, name : 'no' }
  4301. ], function() {
  4302. if (this.btn) {
  4303. var button = _createButton(this.btn);
  4304. button.addClass('ke-dialog-' + this.name);
  4305. footerDiv.append(button);
  4306. }
  4307. });
  4308. if (self.height) {
  4309. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4310. }
  4311. self.div.width(self.div.width());
  4312. self.div.height(self.div.height());
  4313. self.mask = null;
  4314. if (showMask) {
  4315. var docEl = _docElement(self.doc),
  4316. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4317. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4318. self.mask = _widget({
  4319. x : 0,
  4320. y : 0,
  4321. z : self.z - 1,
  4322. cls : 'ke-dialog-mask',
  4323. width : docWidth,
  4324. height : docHeight
  4325. });
  4326. }
  4327. self.autoPos(self.div.width(), self.div.height());
  4328. self.footerDiv = footerDiv;
  4329. self.bodyDiv = bodyDiv;
  4330. self.headerDiv = headerDiv;
  4331. self.isLoading = false;
  4332. },
  4333. setMaskIndex : function(z) {
  4334. var self = this;
  4335. self.mask.div.css('z-index', z);
  4336. },
  4337. showLoading : function(msg) {
  4338. msg = _undef(msg, '');
  4339. var self = this, body = self.bodyDiv;
  4340. 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>')
  4341. .width(body.width()).height(body.height())
  4342. .css('top', self.headerDiv.height() + 'px');
  4343. body.css('visibility', 'hidden').after(self.loading);
  4344. self.isLoading = true;
  4345. return self;
  4346. },
  4347. hideLoading : function() {
  4348. this.loading && this.loading.remove();
  4349. this.bodyDiv.css('visibility', 'visible');
  4350. this.isLoading = false;
  4351. return this;
  4352. },
  4353. remove : function() {
  4354. var self = this;
  4355. if (self.options.beforeRemove) {
  4356. self.options.beforeRemove.call(self);
  4357. }
  4358. self.mask && self.mask.remove();
  4359. self.iframeMask && self.iframeMask.remove();
  4360. self.closeIcon.unbind();
  4361. K('input', self.div).unbind();
  4362. K('button', self.div).unbind();
  4363. self.footerDiv.unbind();
  4364. self.bodyDiv.unbind();
  4365. self.headerDiv.unbind();
  4366. K('iframe', self.div).each(function() {
  4367. K(this).remove();
  4368. });
  4369. KDialog.parent.remove.call(self);
  4370. return self;
  4371. }
  4372. });
  4373. function _dialog(options) {
  4374. return new KDialog(options);
  4375. }
  4376. K.DialogClass = KDialog;
  4377. K.dialog = _dialog;
  4378. function _tabs(options) {
  4379. var self = _widget(options),
  4380. remove = self.remove,
  4381. afterSelect = options.afterSelect,
  4382. div = self.div,
  4383. liList = [];
  4384. div.addClass('ke-tabs')
  4385. .bind('contextmenu,mousedown,mousemove', function(e) {
  4386. e.preventDefault();
  4387. });
  4388. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4389. div.append(ul);
  4390. self.add = function(tab) {
  4391. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4392. li.data('tab', tab);
  4393. liList.push(li);
  4394. ul.append(li);
  4395. };
  4396. self.selectedIndex = 0;
  4397. self.select = function(index) {
  4398. self.selectedIndex = index;
  4399. _each(liList, function(i, li) {
  4400. li.unbind();
  4401. if (i === index) {
  4402. li.addClass('ke-tabs-li-selected');
  4403. K(li.data('tab').panel).show('');
  4404. } else {
  4405. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4406. .mouseover(function() {
  4407. K(this).addClass('ke-tabs-li-on');
  4408. })
  4409. .mouseout(function() {
  4410. K(this).removeClass('ke-tabs-li-on');
  4411. })
  4412. .click(function() {
  4413. self.select(i);
  4414. });
  4415. K(li.data('tab').panel).hide();
  4416. }
  4417. });
  4418. if (afterSelect) {
  4419. afterSelect.call(self, index);
  4420. }
  4421. };
  4422. self.remove = function() {
  4423. _each(liList, function() {
  4424. this.remove();
  4425. });
  4426. ul.remove();
  4427. remove.call(self);
  4428. };
  4429. return self;
  4430. }
  4431. K.tabs = _tabs;
  4432. function _loadScript(url, fn) {
  4433. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4434. script = document.createElement('script');
  4435. head.appendChild(script);
  4436. script.src = url;
  4437. script.charset = 'utf-8';
  4438. script.onload = script.onreadystatechange = function() {
  4439. if (!this.readyState || this.readyState === 'loaded') {
  4440. if (fn) {
  4441. fn();
  4442. }
  4443. script.onload = script.onreadystatechange = null;
  4444. head.removeChild(script);
  4445. }
  4446. };
  4447. }
  4448. function _chopQuery(url) {
  4449. var index = url.indexOf('?');
  4450. return index > 0 ? url.substr(0, index) : url;
  4451. }
  4452. function _loadStyle(url) {
  4453. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4454. link = document.createElement('link'),
  4455. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4456. var links = K('link[rel="stylesheet"]', head);
  4457. for (var i = 0, len = links.length; i < len; i++) {
  4458. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4459. return;
  4460. }
  4461. }
  4462. head.appendChild(link);
  4463. link.href = url;
  4464. link.rel = 'stylesheet';
  4465. }
  4466. function _ajax(url, fn, method, param, dataType) {
  4467. method = method || 'GET';
  4468. dataType = dataType || 'json';
  4469. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4470. xhr.open(method, url, true);
  4471. xhr.onreadystatechange = function () {
  4472. if (xhr.readyState == 4 && xhr.status == 200) {
  4473. if (fn) {
  4474. var data = _trim(xhr.responseText);
  4475. if (dataType == 'json') {
  4476. data = _json(data);
  4477. }
  4478. fn(data);
  4479. }
  4480. }
  4481. };
  4482. if (method == 'POST') {
  4483. var params = [];
  4484. _each(param, function(key, val) {
  4485. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4486. });
  4487. try {
  4488. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4489. } catch (e) {}
  4490. xhr.send(params.join('&'));
  4491. } else {
  4492. xhr.send(null);
  4493. }
  4494. }
  4495. K.loadScript = _loadScript;
  4496. K.loadStyle = _loadStyle;
  4497. K.ajax = _ajax;
  4498. var _plugins = {};
  4499. function _plugin(name, fn) {
  4500. if (name === undefined) {
  4501. return _plugins;
  4502. }
  4503. if (!fn) {
  4504. return _plugins[name];
  4505. }
  4506. _plugins[name] = fn;
  4507. }
  4508. var _language = {};
  4509. function _parseLangKey(key) {
  4510. var match, ns = 'core';
  4511. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4512. ns = match[1];
  4513. key = match[2];
  4514. }
  4515. return { ns : ns, key : key };
  4516. }
  4517. function _lang(mixed, langType) {
  4518. langType = langType === undefined ? K.options.langType : langType;
  4519. if (typeof mixed === 'string') {
  4520. if (!_language[langType]) {
  4521. return 'no language';
  4522. }
  4523. var pos = mixed.length - 1;
  4524. if (mixed.substr(pos) === '.') {
  4525. return _language[langType][mixed.substr(0, pos)];
  4526. }
  4527. var obj = _parseLangKey(mixed);
  4528. return _language[langType][obj.ns][obj.key];
  4529. }
  4530. _each(mixed, function(key, val) {
  4531. var obj = _parseLangKey(key);
  4532. if (!_language[langType]) {
  4533. _language[langType] = {};
  4534. }
  4535. if (!_language[langType][obj.ns]) {
  4536. _language[langType][obj.ns] = {};
  4537. }
  4538. _language[langType][obj.ns][obj.key] = val;
  4539. });
  4540. }
  4541. function _getImageFromRange(range, fn) {
  4542. if (range.collapsed) {
  4543. return;
  4544. }
  4545. range = range.cloneRange().up();
  4546. var sc = range.startContainer, so = range.startOffset;
  4547. if (!_WEBKIT && !range.isControl()) {
  4548. return;
  4549. }
  4550. var img = K(sc.childNodes[so]);
  4551. if (!img || img.name != 'img') {
  4552. return;
  4553. }
  4554. if (fn(img)) {
  4555. return img;
  4556. }
  4557. }
  4558. function _bindContextmenuEvent() {
  4559. var self = this, doc = self.edit.doc;
  4560. K(doc).contextmenu(function(e) {
  4561. if (self.menu) {
  4562. self.hideMenu();
  4563. }
  4564. if (!self.useContextmenu) {
  4565. e.preventDefault();
  4566. return;
  4567. }
  4568. if (self._contextmenus.length === 0) {
  4569. return;
  4570. }
  4571. var maxWidth = 0, items = [];
  4572. _each(self._contextmenus, function() {
  4573. if (this.title == '-') {
  4574. items.push(this);
  4575. return;
  4576. }
  4577. if (this.cond && this.cond()) {
  4578. items.push(this);
  4579. if (this.width && this.width > maxWidth) {
  4580. maxWidth = this.width;
  4581. }
  4582. }
  4583. });
  4584. while (items.length > 0 && items[0].title == '-') {
  4585. items.shift();
  4586. }
  4587. while (items.length > 0 && items[items.length - 1].title == '-') {
  4588. items.pop();
  4589. }
  4590. var prevItem = null;
  4591. _each(items, function(i) {
  4592. if (this.title == '-' && prevItem.title == '-') {
  4593. delete items[i];
  4594. }
  4595. prevItem = this;
  4596. });
  4597. if (items.length > 0) {
  4598. e.preventDefault();
  4599. var pos = K(self.edit.iframe).pos(),
  4600. menu = _menu({
  4601. x : pos.x + e.clientX,
  4602. y : pos.y + e.clientY,
  4603. width : maxWidth,
  4604. css : { visibility: 'hidden' },
  4605. shadowMode : self.shadowMode
  4606. });
  4607. _each(items, function() {
  4608. if (this.title) {
  4609. menu.addItem(this);
  4610. }
  4611. });
  4612. var docEl = _docElement(menu.doc),
  4613. menuHeight = menu.div.height();
  4614. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4615. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4616. }
  4617. menu.div.css('visibility', 'visible');
  4618. self.menu = menu;
  4619. }
  4620. });
  4621. }
  4622. function _bindNewlineEvent() {
  4623. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4624. if (_IE && newlineTag !== 'br') {
  4625. return;
  4626. }
  4627. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4628. return;
  4629. }
  4630. if (_OPERA && _V < 9) {
  4631. return;
  4632. }
  4633. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4634. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4635. function getAncestorTagName(range) {
  4636. var ancestor = K(range.commonAncestor());
  4637. while (ancestor) {
  4638. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4639. break;
  4640. }
  4641. ancestor = ancestor.parent();
  4642. }
  4643. return ancestor.name;
  4644. }
  4645. K(doc).keydown(function(e) {
  4646. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4647. autoImg(self);
  4648. return;
  4649. }
  4650. self.cmd.selection();
  4651. var tagName = getAncestorTagName(self.cmd.range);
  4652. if (tagName == 'marquee' || tagName == 'select') {
  4653. return;
  4654. }
  4655. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4656. e.preventDefault();
  4657. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4658. return;
  4659. }
  4660. if (!pSkipTagMap[tagName]) {
  4661. _nativeCommand(doc, 'formatblock', '<p>');
  4662. }
  4663. });
  4664. K(doc).keyup(function(e) {
  4665. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4666. return;
  4667. }
  4668. if (newlineTag == 'br') {
  4669. return;
  4670. }
  4671. if (_GECKO) {
  4672. var root = self.cmd.commonAncestor('p');
  4673. var a = self.cmd.commonAncestor('a');
  4674. if (a && a.text() == '') {
  4675. a.remove(true);
  4676. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4677. self.cmd.select();
  4678. }
  4679. return;
  4680. }
  4681. self.cmd.selection();
  4682. var tagName = getAncestorTagName(self.cmd.range);
  4683. if (tagName == 'marquee' || tagName == 'select') {
  4684. return;
  4685. }
  4686. if (!pSkipTagMap[tagName]) {
  4687. _nativeCommand(doc, 'formatblock', '<p>');
  4688. }
  4689. var div = self.cmd.commonAncestor('div');
  4690. if (div) {
  4691. var p = K('<p></p>'),
  4692. child = div[0].firstChild;
  4693. while (child) {
  4694. var next = child.nextSibling;
  4695. p.append(child);
  4696. child = next;
  4697. }
  4698. div.before(p);
  4699. div.remove();
  4700. self.cmd.range.selectNodeContents(p[0]);
  4701. self.cmd.select();
  4702. }
  4703. });
  4704. }
  4705. function _bindTabEvent() {
  4706. var self = this, doc = self.edit.doc;
  4707. K(doc).keydown(function(e) {
  4708. if (e.which == 9) {
  4709. e.preventDefault();
  4710. if (self.afterTab) {
  4711. self.afterTab.call(self, e);
  4712. return;
  4713. }
  4714. var cmd = self.cmd, range = cmd.range;
  4715. range.shrink();
  4716. if (range.collapsed && range.startContainer.nodeType == 1) {
  4717. range.insertNode(K('@&nbsp;', doc)[0]);
  4718. cmd.select();
  4719. }
  4720. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4721. }
  4722. });
  4723. }
  4724. function _bindFocusEvent() {
  4725. var self = this;
  4726. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4727. if (self.afterFocus) {
  4728. self.afterFocus.call(self, e);
  4729. }
  4730. }).blur(function(e) {
  4731. if (self.afterBlur) {
  4732. self.afterBlur.call(self, e);
  4733. }
  4734. });
  4735. }
  4736. function _removeBookmarkTag(html) {
  4737. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4738. }
  4739. function _removeTempTag(html) {
  4740. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4741. }
  4742. function _addBookmarkToStack(stack, bookmark) {
  4743. if (stack.length === 0) {
  4744. stack.push(bookmark);
  4745. return;
  4746. }
  4747. var prev = stack[stack.length - 1];
  4748. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4749. stack.push(bookmark);
  4750. }
  4751. }
  4752. function _undoToRedo(fromStack, toStack) {
  4753. var self = this, edit = self.edit,
  4754. body = edit.doc.body,
  4755. range, bookmark;
  4756. if (fromStack.length === 0) {
  4757. return self;
  4758. }
  4759. if (edit.designMode) {
  4760. range = self.cmd.range;
  4761. bookmark = range.createBookmark(true);
  4762. bookmark.html = body.innerHTML;
  4763. } else {
  4764. bookmark = {
  4765. html : body.innerHTML
  4766. };
  4767. }
  4768. _addBookmarkToStack(toStack, bookmark);
  4769. var prev = fromStack.pop();
  4770. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4771. prev = fromStack.pop();
  4772. }
  4773. if (edit.designMode) {
  4774. edit.html(prev.html);
  4775. if (prev.start) {
  4776. range.moveToBookmark(prev);
  4777. self.select();
  4778. }
  4779. } else {
  4780. K(body).html(_removeBookmarkTag(prev.html));
  4781. }
  4782. return self;
  4783. }
  4784. function KEditor(options) {
  4785. var self = this;
  4786. self.options = {};
  4787. function setOption(key, val) {
  4788. if (KEditor.prototype[key] === undefined) {
  4789. self[key] = val;
  4790. }
  4791. self.options[key] = val;
  4792. }
  4793. _each(options, function(key, val) {
  4794. setOption(key, options[key]);
  4795. });
  4796. _each(K.options, function(key, val) {
  4797. if (self[key] === undefined) {
  4798. setOption(key, val);
  4799. }
  4800. });
  4801. var se = K(self.srcElement || '<textarea/>');
  4802. if (!self.width) {
  4803. self.width = se[0].style.width || se.width();
  4804. }
  4805. if (!self.height) {
  4806. self.height = se[0].style.height || se.height();
  4807. }
  4808. setOption('width', _undef(self.width, self.minWidth));
  4809. setOption('height', _undef(self.height, self.minHeight));
  4810. setOption('width', _addUnit(self.width));
  4811. setOption('height', _addUnit(self.height));
  4812. if (_MOBILE && (!_IOS || _V < 534)) {
  4813. self.designMode = false;
  4814. }
  4815. self.srcElement = se;
  4816. self.initContent = '';
  4817. self.plugin = {};
  4818. self.isCreated = false;
  4819. self._handlers = {};
  4820. self._contextmenus = [];
  4821. self._undoStack = [];
  4822. self._redoStack = [];
  4823. self._firstAddBookmark = true;
  4824. self.menu = self.contextmenu = null;
  4825. self.dialogs = [];
  4826. }
  4827. KEditor.prototype = {
  4828. lang : function(mixed) {
  4829. return _lang(mixed, this.langType);
  4830. },
  4831. loadPlugin : function(name, fn) {
  4832. var self = this;
  4833. var _pluginStatus = this._pluginStatus;
  4834. if (!_pluginStatus) {
  4835. _pluginStatus = this._pluginStatus = {};
  4836. }
  4837. if (_plugins[name]) {
  4838. if (!_isFunction(_plugins[name])) {
  4839. setTimeout(function() {
  4840. self.loadPlugin(name, fn);
  4841. }, 100);
  4842. return self;
  4843. }
  4844. if(!_pluginStatus[name]) {
  4845. _plugins[name].call(self, KindEditor);
  4846. _pluginStatus[name] = 'inited';
  4847. }
  4848. if (fn) {
  4849. fn.call(self);
  4850. }
  4851. return self;
  4852. }
  4853. _plugins[name] = 'loading';
  4854. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4855. setTimeout(function() {
  4856. if (_plugins[name]) {
  4857. self.loadPlugin(name, fn);
  4858. }
  4859. }, 0);
  4860. });
  4861. return self;
  4862. },
  4863. handler : function(key, fn) {
  4864. var self = this;
  4865. if (!self._handlers[key]) {
  4866. self._handlers[key] = [];
  4867. }
  4868. if (_isFunction(fn)) {
  4869. self._handlers[key].push(fn);
  4870. return self;
  4871. }
  4872. _each(self._handlers[key], function() {
  4873. fn = this.call(self, fn);
  4874. });
  4875. return fn;
  4876. },
  4877. clickToolbar : function(name, fn) {
  4878. var self = this, key = 'clickToolbar' + name;
  4879. if (fn === undefined) {
  4880. if (self._handlers[key]) {
  4881. return self.handler(key);
  4882. }
  4883. self.loadPlugin(name, function() {
  4884. self.handler(key);
  4885. });
  4886. return self;
  4887. }
  4888. return self.handler(key, fn);
  4889. },
  4890. updateState : function() {
  4891. var self = this;
  4892. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4893. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4894. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4895. });
  4896. return self;
  4897. },
  4898. addContextmenu : function(item) {
  4899. this._contextmenus.push(item);
  4900. return this;
  4901. },
  4902. afterCreate : function(fn) {
  4903. return this.handler('afterCreate', fn);
  4904. },
  4905. beforeRemove : function(fn) {
  4906. return this.handler('beforeRemove', fn);
  4907. },
  4908. beforeGetHtml : function(fn) {
  4909. return this.handler('beforeGetHtml', fn);
  4910. },
  4911. beforeSetHtml : function(fn) {
  4912. return this.handler('beforeSetHtml', fn);
  4913. },
  4914. afterSetHtml : function(fn) {
  4915. return this.handler('afterSetHtml', fn);
  4916. },
  4917. create : function() {
  4918. var self = this, fullscreenMode = self.fullscreenMode;
  4919. if (self.isCreated) {
  4920. return self;
  4921. }
  4922. if (self.srcElement.data('kindeditor')) {
  4923. return self;
  4924. }
  4925. self.srcElement.data('kindeditor', 'true');
  4926. if (fullscreenMode) {
  4927. _docElement().style.overflow = 'hidden';
  4928. } else {
  4929. _docElement().style.overflow = '';
  4930. }
  4931. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4932. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4933. if ((_IE && _V < 8) || _QUIRKS) {
  4934. height = _addUnit(_removeUnit(height) + 2);
  4935. }
  4936. var container = self.container = K(self.layout);
  4937. if (fullscreenMode) {
  4938. K(document.body).append(container);
  4939. } else {
  4940. self.srcElement.before(container);
  4941. }
  4942. var toolbarDiv = K('.toolbar', container),
  4943. editDiv = K('.edit', container),
  4944. statusbar = self.statusbar = K('.statusbar', container);
  4945. container.removeClass('container')
  4946. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4947. if (fullscreenMode) {
  4948. container.css({
  4949. position : 'absolute',
  4950. left : 0,
  4951. top : 0,
  4952. 'z-index' : 811211
  4953. });
  4954. if (!_GECKO) {
  4955. self._scrollPos = _getScrollPos();
  4956. }
  4957. window.scrollTo(0, 0);
  4958. K(document.body).css({
  4959. 'height' : '1px',
  4960. 'overflow' : 'hidden'
  4961. });
  4962. K(document.body.parentNode).css('overflow', 'hidden');
  4963. self._fullscreenExecuted = true;
  4964. } else {
  4965. if (self._fullscreenExecuted) {
  4966. K(document.body).css({
  4967. 'height' : '',
  4968. 'overflow' : ''
  4969. });
  4970. K(document.body.parentNode).css('overflow', '');
  4971. }
  4972. if (self._scrollPos) {
  4973. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4974. }
  4975. }
  4976. var htmlList = [];
  4977. K.each(self.items, function(i, name) {
  4978. if (name == '|') {
  4979. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4980. } else if (name == '/') {
  4981. htmlList.push('<div class="ke-hr"></div>');
  4982. } else {
  4983. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4984. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4985. }
  4986. });
  4987. var toolbar = self.toolbar = _toolbar({
  4988. src : toolbarDiv,
  4989. html : htmlList.join(''),
  4990. noDisableItems : self.noDisableItems,
  4991. click : function(e, name) {
  4992. e.stop();
  4993. if (self.menu) {
  4994. var menuName = self.menu.name;
  4995. self.hideMenu();
  4996. if (menuName === name) {
  4997. return;
  4998. }
  4999. }
  5000. self.clickToolbar(name);
  5001. }
  5002. });
  5003. var editHeight = _removeUnit(height) - toolbar.div.height();
  5004. var edit = self.edit = _edit({
  5005. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5006. src : editDiv,
  5007. srcElement : self.srcElement,
  5008. designMode : self.designMode,
  5009. themesPath : self.themesPath,
  5010. bodyClass : self.bodyClass,
  5011. cssPath : self.cssPath,
  5012. cssData : self.cssData,
  5013. beforeGetHtml : function(html) {
  5014. html = self.beforeGetHtml(html);
  5015. html = _removeBookmarkTag(_removeTempTag(html));
  5016. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5017. },
  5018. beforeSetHtml : function(html) {
  5019. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5020. return self.beforeSetHtml(html);
  5021. },
  5022. afterSetHtml : function() {
  5023. self.edit = edit = this;
  5024. self.afterSetHtml();
  5025. },
  5026. afterCreate : function() {
  5027. self.edit = edit = this;
  5028. self.cmd = edit.cmd;
  5029. self._docMousedownFn = function(e) {
  5030. if (self.menu) {
  5031. self.hideMenu();
  5032. }
  5033. };
  5034. K(edit.doc, document).mousedown(self._docMousedownFn);
  5035. _bindContextmenuEvent.call(self);
  5036. _bindNewlineEvent.call(self);
  5037. _bindTabEvent.call(self);
  5038. _bindFocusEvent.call(self);
  5039. edit.afterChange(function(e) {
  5040. if (!edit.designMode) {
  5041. return;
  5042. }
  5043. self.updateState();
  5044. self.addBookmark();
  5045. if (self.options.afterChange) {
  5046. self.options.afterChange.call(self);
  5047. }
  5048. });
  5049. edit.textarea.keyup(function(e) {
  5050. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5051. if (self.options.afterChange) {
  5052. self.options.afterChange.call(self);
  5053. }
  5054. }
  5055. });
  5056. if (self.readonlyMode) {
  5057. self.readonly();
  5058. }
  5059. self.isCreated = true;
  5060. if (self.initContent === '') {
  5061. self.initContent = self.html();
  5062. }
  5063. if (self._undoStack.length > 0) {
  5064. var prev = self._undoStack.pop();
  5065. if (prev.start) {
  5066. self.html(prev.html);
  5067. edit.cmd.range.moveToBookmark(prev);
  5068. self.select();
  5069. }
  5070. }
  5071. self.afterCreate();
  5072. if (self.options.afterCreate) {
  5073. self.options.afterCreate.call(self);
  5074. }
  5075. }
  5076. });
  5077. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5078. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5079. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5080. if (self._fullscreenResizeHandler) {
  5081. K(window).unbind('resize', self._fullscreenResizeHandler);
  5082. self._fullscreenResizeHandler = null;
  5083. }
  5084. function initResize() {
  5085. if (statusbar.height() === 0) {
  5086. setTimeout(initResize, 100);
  5087. return;
  5088. }
  5089. self.resize(width, height, false);
  5090. }
  5091. initResize();
  5092. if (fullscreenMode) {
  5093. self._fullscreenResizeHandler = function(e) {
  5094. if (self.isCreated) {
  5095. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5096. }
  5097. };
  5098. K(window).bind('resize', self._fullscreenResizeHandler);
  5099. toolbar.select('fullscreen');
  5100. statusbar.first().css('visibility', 'hidden');
  5101. statusbar.last().css('visibility', 'hidden');
  5102. } else {
  5103. if (_GECKO) {
  5104. K(window).bind('scroll', function(e) {
  5105. self._scrollPos = _getScrollPos();
  5106. });
  5107. }
  5108. if (self.resizeType > 0) {
  5109. _drag({
  5110. moveEl : container,
  5111. clickEl : statusbar,
  5112. moveFn : function(x, y, width, height, diffX, diffY) {
  5113. height += diffY;
  5114. self.resize(null, height);
  5115. }
  5116. });
  5117. } else {
  5118. statusbar.first().css('visibility', 'hidden');
  5119. }
  5120. if (self.resizeType === 2) {
  5121. _drag({
  5122. moveEl : container,
  5123. clickEl : statusbar.last(),
  5124. moveFn : function(x, y, width, height, diffX, diffY) {
  5125. width += diffX;
  5126. height += diffY;
  5127. self.resize(width, height);
  5128. }
  5129. });
  5130. } else {
  5131. statusbar.last().css('visibility', 'hidden');
  5132. }
  5133. }
  5134. return self;
  5135. },
  5136. remove : function() {
  5137. var self = this;
  5138. if (!self.isCreated) {
  5139. return self;
  5140. }
  5141. self.beforeRemove();
  5142. self.srcElement.data('kindeditor', '');
  5143. if (self.menu) {
  5144. self.hideMenu();
  5145. }
  5146. _each(self.dialogs, function() {
  5147. self.hideDialog();
  5148. });
  5149. K(document).unbind('mousedown', self._docMousedownFn);
  5150. self.toolbar.remove();
  5151. self.edit.remove();
  5152. self.statusbar.last().unbind();
  5153. self.statusbar.unbind();
  5154. self.container.remove();
  5155. self.container = self.toolbar = self.edit = self.menu = null;
  5156. self.dialogs = [];
  5157. self.isCreated = false;
  5158. return self;
  5159. },
  5160. resize : function(width, height, updateProp) {
  5161. var self = this;
  5162. updateProp = _undef(updateProp, true);
  5163. if (width) {
  5164. if (!/%/.test(width)) {
  5165. width = _removeUnit(width);
  5166. width = width < self.minWidth ? self.minWidth : width;
  5167. }
  5168. self.container.css('width', _addUnit(width));
  5169. if (updateProp) {
  5170. self.width = _addUnit(width);
  5171. }
  5172. }
  5173. if (height) {
  5174. height = _removeUnit(height);
  5175. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5176. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5177. self.edit.setHeight(editHeight);
  5178. if (updateProp) {
  5179. self.height = _addUnit(height);
  5180. }
  5181. }
  5182. return self;
  5183. },
  5184. select : function() {
  5185. this.isCreated && this.cmd.select();
  5186. return this;
  5187. },
  5188. html : function(val) {
  5189. var self = this;
  5190. if (val === undefined) {
  5191. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5192. }
  5193. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5194. if (self.isCreated) {
  5195. self.cmd.selection();
  5196. }
  5197. return self;
  5198. },
  5199. fullHtml : function() {
  5200. return this.isCreated ? this.edit.html(undefined, true) : '';
  5201. },
  5202. text : function(val) {
  5203. var self = this;
  5204. if (val === undefined) {
  5205. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5206. } else {
  5207. return self.html(_escape(val));
  5208. }
  5209. },
  5210. isEmpty : function() {
  5211. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5212. },
  5213. isDirty : function() {
  5214. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5215. },
  5216. selectedHtml : function() {
  5217. var val = this.isCreated ? this.cmd.range.html() : '';
  5218. val = _removeBookmarkTag(_removeTempTag(val));
  5219. return val;
  5220. },
  5221. count : function(mode) {
  5222. var self = this;
  5223. mode = (mode || 'html').toLowerCase();
  5224. if (mode === 'html') {
  5225. return self.html().length;
  5226. }
  5227. if (mode === 'text') {
  5228. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5229. }
  5230. return 0;
  5231. },
  5232. exec : function(key) {
  5233. key = key.toLowerCase();
  5234. var self = this, cmd = self.cmd,
  5235. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5236. if (changeFlag) {
  5237. self.addBookmark(false);
  5238. }
  5239. cmd[key].apply(cmd, _toArray(arguments, 1));
  5240. if (changeFlag) {
  5241. self.updateState();
  5242. self.addBookmark(false);
  5243. if (self.options.afterChange) {
  5244. self.options.afterChange.call(self);
  5245. }
  5246. }
  5247. return self;
  5248. },
  5249. insertHtml : function(val, quickMode) {
  5250. if (!this.isCreated) {
  5251. return this;
  5252. }
  5253. val = this.beforeSetHtml(val);
  5254. this.exec('inserthtml', val, quickMode);
  5255. return this;
  5256. },
  5257. appendHtml : function(val) {
  5258. this.html(this.html() + val);
  5259. if (this.isCreated) {
  5260. var cmd = this.cmd;
  5261. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5262. cmd.select();
  5263. }
  5264. return this;
  5265. },
  5266. sync : function() {
  5267. _elementVal(this.srcElement, this.html());
  5268. return this;
  5269. },
  5270. focus : function() {
  5271. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5272. return this;
  5273. },
  5274. blur : function() {
  5275. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5276. return this;
  5277. },
  5278. addBookmark : function(checkSize) {
  5279. checkSize = _undef(checkSize, true);
  5280. var self = this, edit = self.edit,
  5281. body = edit.doc.body,
  5282. html = _removeTempTag(body.innerHTML), bookmark;
  5283. if (checkSize && self._undoStack.length > 0) {
  5284. var prev = self._undoStack[self._undoStack.length - 1];
  5285. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5286. return self;
  5287. }
  5288. }
  5289. if (edit.designMode && !self._firstAddBookmark) {
  5290. var range = self.cmd.range;
  5291. bookmark = range.createBookmark(true);
  5292. bookmark.html = _removeTempTag(body.innerHTML);
  5293. range.moveToBookmark(bookmark);
  5294. } else {
  5295. bookmark = {
  5296. html : html
  5297. };
  5298. }
  5299. self._firstAddBookmark = false;
  5300. _addBookmarkToStack(self._undoStack, bookmark);
  5301. return self;
  5302. },
  5303. undo : function() {
  5304. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5305. },
  5306. redo : function() {
  5307. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5308. },
  5309. fullscreen : function(bool) {
  5310. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5311. this.addBookmark(false);
  5312. return this.remove().create();
  5313. },
  5314. readonly : function(isReadonly) {
  5315. isReadonly = _undef(isReadonly, true);
  5316. var self = this, edit = self.edit, doc = edit.doc;
  5317. if (self.designMode) {
  5318. self.toolbar.disableAll(isReadonly, []);
  5319. } else {
  5320. _each(self.noDisableItems, function() {
  5321. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5322. });
  5323. }
  5324. if (_IE) {
  5325. doc.body.contentEditable = !isReadonly;
  5326. } else {
  5327. doc.designMode = isReadonly ? 'off' : 'on';
  5328. }
  5329. edit.textarea[0].disabled = isReadonly;
  5330. },
  5331. createMenu : function(options) {
  5332. var self = this,
  5333. name = options.name,
  5334. knode = self.toolbar.get(name),
  5335. pos = knode.pos();
  5336. options.x = pos.x;
  5337. options.y = pos.y + knode.height();
  5338. options.z = self.options.zIndex;
  5339. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5340. if (options.selectedColor !== undefined) {
  5341. options.cls = 'ke-colorpicker-' + self.themeType;
  5342. options.noColor = self.lang('noColor');
  5343. self.menu = _colorpicker(options);
  5344. } else {
  5345. options.cls = 'ke-menu-' + self.themeType;
  5346. options.centerLineMode = false;
  5347. self.menu = _menu(options);
  5348. }
  5349. return self.menu;
  5350. },
  5351. hideMenu : function() {
  5352. this.menu.remove();
  5353. this.menu = null;
  5354. return this;
  5355. },
  5356. hideContextmenu : function() {
  5357. this.contextmenu.remove();
  5358. this.contextmenu = null;
  5359. return this;
  5360. },
  5361. createDialog : function(options) {
  5362. var self = this, name = options.name;
  5363. options.z = self.options.zIndex;
  5364. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5365. options.closeBtn = _undef(options.closeBtn, {
  5366. name : self.lang('close'),
  5367. click : function(e) {
  5368. self.hideDialog();
  5369. if (_IE && self.cmd) {
  5370. self.cmd.select();
  5371. }
  5372. }
  5373. });
  5374. options.noBtn = _undef(options.noBtn, {
  5375. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5376. click : function(e) {
  5377. self.hideDialog();
  5378. if (_IE && self.cmd) {
  5379. self.cmd.select();
  5380. }
  5381. }
  5382. });
  5383. if (self.dialogAlignType != 'page') {
  5384. options.alignEl = self.container;
  5385. }
  5386. options.cls = 'ke-dialog-' + self.themeType;
  5387. if (self.dialogs.length > 0) {
  5388. var firstDialog = self.dialogs[0],
  5389. parentDialog = self.dialogs[self.dialogs.length - 1];
  5390. firstDialog.setMaskIndex(parentDialog.z + 2);
  5391. options.z = parentDialog.z + 3;
  5392. options.showMask = false;
  5393. }
  5394. var dialog = _dialog(options);
  5395. self.dialogs.push(dialog);
  5396. return dialog;
  5397. },
  5398. hideDialog : function() {
  5399. var self = this;
  5400. if (self.dialogs.length > 0) {
  5401. self.dialogs.pop().remove();
  5402. }
  5403. if (self.dialogs.length > 0) {
  5404. var firstDialog = self.dialogs[0],
  5405. parentDialog = self.dialogs[self.dialogs.length - 1];
  5406. firstDialog.setMaskIndex(parentDialog.z - 1);
  5407. }
  5408. return self;
  5409. },
  5410. errorDialog : function(html) {
  5411. var self = this;
  5412. var dialog = self.createDialog({
  5413. width : 750,
  5414. title : self.lang('uploadError'),
  5415. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5416. });
  5417. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5418. doc.open();
  5419. doc.write(html);
  5420. doc.close();
  5421. K(doc.body).css('background-color', '#FFF');
  5422. iframe[0].contentWindow.focus();
  5423. return self;
  5424. }
  5425. };
  5426. function _editor(options) {
  5427. return new KEditor(options);
  5428. }
  5429. var _instances = [];
  5430. function _create(expr, options) {
  5431. options = options || {};
  5432. options.basePath = _undef(options.basePath, K.basePath);
  5433. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5434. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5435. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5436. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5437. var themeType = _undef(options.themeType, K.options.themeType);
  5438. _loadStyle(options.themesPath + 'default/default.css');
  5439. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5440. }
  5441. function create(editor) {
  5442. _each(_plugins, function(name, fn) {
  5443. if (_isFunction(fn)) {
  5444. fn.call(editor, KindEditor);
  5445. if (!editor._pluginStatus) {
  5446. editor._pluginStatus = {};
  5447. }
  5448. editor._pluginStatus[name] = 'inited';
  5449. }
  5450. });
  5451. return editor.create();
  5452. }
  5453. var knode = K(expr);
  5454. if (!knode || knode.length === 0) {
  5455. return;
  5456. }
  5457. if (knode.length > 1) {
  5458. knode.each(function() {
  5459. _create(this, options);
  5460. });
  5461. return _instances[0];
  5462. }
  5463. options.srcElement = knode[0];
  5464. var editor = new KEditor(options);
  5465. _instances.push(editor);
  5466. if (_language[editor.langType]) {
  5467. return create(editor);
  5468. }
  5469. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5470. create(editor);
  5471. });
  5472. return editor;
  5473. }
  5474. function _eachEditor(expr, fn) {
  5475. K(expr).each(function(i, el) {
  5476. K.each(_instances, function(j, editor) {
  5477. if (editor && editor.srcElement[0] == el) {
  5478. fn.call(editor, j);
  5479. return false;
  5480. }
  5481. });
  5482. });
  5483. }
  5484. K.remove = function(expr) {
  5485. _eachEditor(expr, function(i) {
  5486. this.remove();
  5487. _instances.splice(i, 1);
  5488. });
  5489. };
  5490. K.sync = function(expr) {
  5491. _eachEditor(expr, function() {
  5492. this.sync();
  5493. });
  5494. };
  5495. K.html = function(expr, val) {
  5496. _eachEditor(expr, function() {
  5497. this.html(val);
  5498. });
  5499. };
  5500. K.insertHtml = function(expr, val) {
  5501. _eachEditor(expr, function() {
  5502. this.insertHtml(val);
  5503. });
  5504. };
  5505. K.appendHtml = function(expr, val) {
  5506. _eachEditor(expr, function() {
  5507. this.appendHtml(val);
  5508. });
  5509. };
  5510. if (_IE && _V < 7) {
  5511. _nativeCommand(document, 'BackgroundImageCache', true);
  5512. }
  5513. K.EditorClass = KEditor;
  5514. K.editor = _editor;
  5515. K.create = _create;
  5516. K.instances = _instances;
  5517. K.plugin = _plugin;
  5518. K.lang = _lang;
  5519. _plugin('core', function(K) {
  5520. var self = this,
  5521. shortcutKeys = {
  5522. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5523. };
  5524. self.afterSetHtml(function() {
  5525. if (self.options.afterChange) {
  5526. self.options.afterChange.call(self);
  5527. }
  5528. });
  5529. self.afterCreate(function() {
  5530. if (self.syncType != 'form') {
  5531. return;
  5532. }
  5533. var el = K(self.srcElement), hasForm = false;
  5534. while ((el = el.parent())) {
  5535. if (el.name == 'form') {
  5536. hasForm = true;
  5537. break;
  5538. }
  5539. }
  5540. if (hasForm) {
  5541. el.bind('submit', function(e) {
  5542. self.sync();
  5543. K(window).bind('unload', function() {
  5544. self.edit.textarea.remove();
  5545. });
  5546. });
  5547. var resetBtn = K('[type="reset"]', el);
  5548. resetBtn.click(function() {
  5549. self.html(self.initContent);
  5550. self.cmd.selection();
  5551. });
  5552. self.beforeRemove(function() {
  5553. el.unbind();
  5554. resetBtn.unbind();
  5555. });
  5556. }
  5557. });
  5558. self.clickToolbar('source', function() {
  5559. if (self.edit.designMode) {
  5560. self.toolbar.disableAll(true);
  5561. self.edit.design(false);
  5562. self.toolbar.select('source');
  5563. } else {
  5564. self.toolbar.disableAll(false);
  5565. self.edit.design(true);
  5566. self.toolbar.unselect('source');
  5567. if (_GECKO) {
  5568. setTimeout(function() {
  5569. self.cmd.selection();
  5570. }, 0);
  5571. } else {
  5572. self.cmd.selection();
  5573. }
  5574. }
  5575. self.designMode = self.edit.designMode;
  5576. });
  5577. self.afterCreate(function() {
  5578. if (!self.designMode) {
  5579. self.toolbar.disableAll(true).select('source');
  5580. }
  5581. });
  5582. self.clickToolbar('fullscreen', function() {
  5583. self.fullscreen();
  5584. });
  5585. if (self.fullscreenShortcut) {
  5586. var loaded = false;
  5587. self.afterCreate(function() {
  5588. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5589. if (e.which == 27) {
  5590. setTimeout(function() {
  5591. self.fullscreen();
  5592. }, 0);
  5593. }
  5594. });
  5595. if (loaded) {
  5596. if (_IE && !self.designMode) {
  5597. return;
  5598. }
  5599. self.focus();
  5600. }
  5601. if (!loaded) {
  5602. loaded = true;
  5603. }
  5604. });
  5605. }
  5606. _each('undo,redo'.split(','), function(i, name) {
  5607. if (shortcutKeys[name]) {
  5608. self.afterCreate(function() {
  5609. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5610. self.clickToolbar(name);
  5611. });
  5612. });
  5613. }
  5614. self.clickToolbar(name, function() {
  5615. self[name]();
  5616. });
  5617. });
  5618. self.clickToolbar('formatblock', function() {
  5619. var blocks = self.lang('formatblock.formatBlock'),
  5620. heights = {
  5621. h1 : 28,
  5622. h2 : 24,
  5623. h3 : 18,
  5624. H4 : 14,
  5625. p : 12
  5626. },
  5627. curVal = self.cmd.val('formatblock'),
  5628. menu = self.createMenu({
  5629. name : 'formatblock',
  5630. width : self.langType == 'en' ? 200 : 150
  5631. });
  5632. _each(blocks, function(key, val) {
  5633. var style = 'font-size:' + heights[key] + 'px;';
  5634. if (key.charAt(0) === 'h') {
  5635. style += 'font-weight:bold;';
  5636. }
  5637. menu.addItem({
  5638. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5639. height : heights[key] + 12,
  5640. checked : (curVal === key || curVal === val),
  5641. click : function() {
  5642. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5643. }
  5644. });
  5645. });
  5646. });
  5647. self.clickToolbar('fontname', function() {
  5648. var curVal = self.cmd.val('fontname'),
  5649. menu = self.createMenu({
  5650. name : 'fontname',
  5651. width : 150
  5652. });
  5653. _each(self.lang('fontname.fontName'), function(key, val) {
  5654. menu.addItem({
  5655. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5656. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5657. click : function() {
  5658. self.exec('fontname', key).hideMenu();
  5659. }
  5660. });
  5661. });
  5662. });
  5663. self.clickToolbar('fontsize', function() {
  5664. var curVal = self.cmd.val('fontsize'),
  5665. menu = self.createMenu({
  5666. name : 'fontsize',
  5667. width : 150
  5668. });
  5669. _each(self.fontSizeTable, function(i, val) {
  5670. menu.addItem({
  5671. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5672. height : _removeUnit(val) + 12,
  5673. checked : curVal === val,
  5674. click : function() {
  5675. self.exec('fontsize', val).hideMenu();
  5676. }
  5677. });
  5678. });
  5679. });
  5680. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5681. self.clickToolbar(name, function() {
  5682. self.createMenu({
  5683. name : name,
  5684. selectedColor : self.cmd.val(name) || 'default',
  5685. colors : self.colorTable,
  5686. click : function(color) {
  5687. self.exec(name, color).hideMenu();
  5688. }
  5689. });
  5690. });
  5691. });
  5692. _each(('cut,copy,paste').split(','), function(i, name) {
  5693. self.clickToolbar(name, function() {
  5694. self.focus();
  5695. try {
  5696. self.exec(name, null);
  5697. } catch(e) {
  5698. alert(self.lang(name + 'Error'));
  5699. }
  5700. });
  5701. });
  5702. self.clickToolbar('about', function() {
  5703. var html = '<div style="margin:20px;">' +
  5704. '<div>KindEditor ' + _VERSION + '</div>' +
  5705. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5706. '</div>';
  5707. self.createDialog({
  5708. name : 'about',
  5709. width : 350,
  5710. title : self.lang('about'),
  5711. body : html
  5712. });
  5713. });
  5714. self.plugin.getSelectedLink = function() {
  5715. return self.cmd.commonAncestor('a');
  5716. };
  5717. self.plugin.getSelectedImage = function() {
  5718. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5719. return !/^ke-\w+$/i.test(img[0].className);
  5720. });
  5721. };
  5722. self.plugin.getSelectedFlash = function() {
  5723. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5724. return img[0].className == 'ke-flash';
  5725. });
  5726. };
  5727. self.plugin.getSelectedMedia = function() {
  5728. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5729. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5730. });
  5731. };
  5732. self.plugin.getSelectedAnchor = function() {
  5733. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5734. return img[0].className == 'ke-anchor';
  5735. });
  5736. };
  5737. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5738. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5739. _each('edit,delete'.split(','), function(j, val) {
  5740. self.addContextmenu({
  5741. title : self.lang(val + uName),
  5742. click : function() {
  5743. self.loadPlugin(name, function() {
  5744. self.plugin[name][val]();
  5745. self.hideMenu();
  5746. });
  5747. },
  5748. cond : self.plugin['getSelected' + uName],
  5749. width : 150,
  5750. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5751. });
  5752. });
  5753. self.addContextmenu({ title : '-' });
  5754. });
  5755. self.plugin.getSelectedTable = function() {
  5756. return self.cmd.commonAncestor('table');
  5757. };
  5758. self.plugin.getSelectedRow = function() {
  5759. return self.cmd.commonAncestor('tr');
  5760. };
  5761. self.plugin.getSelectedCell = function() {
  5762. return self.cmd.commonAncestor('td');
  5763. };
  5764. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5765. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5766. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5767. self.addContextmenu({
  5768. title : self.lang('table' + val),
  5769. click : function() {
  5770. self.loadPlugin('table', function() {
  5771. self.plugin.table[val]();
  5772. self.hideMenu();
  5773. });
  5774. },
  5775. cond : cond,
  5776. width : 170,
  5777. iconClass : 'ke-icon-table' + val
  5778. });
  5779. });
  5780. self.addContextmenu({ title : '-' });
  5781. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5782. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5783. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5784. if (shortcutKeys[name]) {
  5785. self.afterCreate(function() {
  5786. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5787. self.cmd.selection();
  5788. self.clickToolbar(name);
  5789. });
  5790. });
  5791. }
  5792. self.clickToolbar(name, function() {
  5793. self.focus().exec(name, null);
  5794. });
  5795. });
  5796. self.afterCreate(function() {
  5797. var doc = self.edit.doc, cmd, bookmark, div,
  5798. cls = '__kindeditor_paste__', pasting = false;
  5799. function movePastedData() {
  5800. cmd.range.moveToBookmark(bookmark);
  5801. cmd.select();
  5802. if (_WEBKIT) {
  5803. K('div.' + cls, div).each(function() {
  5804. K(this).after('<br />').remove(true);
  5805. });
  5806. K('span.Apple-style-span', div).remove(true);
  5807. K('span.Apple-tab-span', div).remove(true);
  5808. K('span[style]', div).each(function() {
  5809. if (K(this).css('white-space') == 'nowrap') {
  5810. K(this).remove(true);
  5811. }
  5812. });
  5813. K('meta', div).remove();
  5814. }
  5815. var html = div[0].innerHTML;
  5816. div.remove();
  5817. if (html === '') {
  5818. return;
  5819. }
  5820. if (_WEBKIT) {
  5821. html = html.replace(/(<br>)\1/ig, '$1');
  5822. }
  5823. if (self.pasteType === 2) {
  5824. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5825. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5826. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5827. } else {
  5828. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5829. html = self.beforeSetHtml(html);
  5830. }
  5831. }
  5832. if (self.pasteType === 1) {
  5833. html = html.replace(/&nbsp;/ig, ' ');
  5834. html = html.replace(/\n\s*\n/g, '\n');
  5835. html = html.replace(/<br[^>]*>/ig, '\n');
  5836. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5837. html = html.replace(/<[^>]+>/g, '');
  5838. html = html.replace(/ {2}/g, ' &nbsp;');
  5839. if (self.newlineTag == 'p') {
  5840. if (/\n/.test(html)) {
  5841. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5842. }
  5843. } else {
  5844. html = html.replace(/\n/g, '<br />$&');
  5845. }
  5846. }
  5847. self.insertHtml(html, true);
  5848. }
  5849. K(doc.body).bind('paste', function(e){
  5850. //处理IE11,Chrome粘贴图片上传
  5851. function dopasteImg() {
  5852. //debugger;
  5853. var file = null;
  5854. if (window.clipboardData) {//ie
  5855. if (clipboardData.files && clipboardData.files.length)//IE11
  5856. file = clipboardData.files[0];
  5857. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5858. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5859. return true;
  5860. }
  5861. } else {
  5862. if (e.event.clipboardData.items)//chrome
  5863. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5864. if (e.event.clipboardData.items[i].kind === "file") {
  5865. file = e.event.clipboardData.items[i];
  5866. break;
  5867. }
  5868. }
  5869. if (file == null) {
  5870. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5871. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5872. return true;
  5873. }
  5874. }
  5875. }
  5876. if (file) {
  5877. if (!K.undef(self.allowImageUpload, true)) {
  5878. alert("编辑器禁止上传图片,请与有关人员联系!");
  5879. return true;
  5880. }
  5881. //获取File Blob
  5882. //debugger;
  5883. var blb;
  5884. if (file.getAsFile) {//Chrome
  5885. blb = file.getAsFile();
  5886. if (blb.size === 0) {
  5887. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5888. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5889. return true;
  5890. }
  5891. sendfile(blb, file.type);
  5892. } else {
  5893. var fr = new FileReader();
  5894. if (fr.readAsArrayBuffer) {//ie
  5895. fr.onloadend = function (evt) {
  5896. blb = evt.target.result;
  5897. sendfile(blb, file.type);
  5898. }
  5899. fr.readAsArrayBuffer(file);
  5900. }
  5901. }
  5902. function sendfile(b, t) {
  5903. var xhr = new XMLHttpRequest();
  5904. var formData = new FormData();
  5905. var isImg = t.indexOf("image/") === 0;
  5906. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5907. //formData.append('imgFile', b);
  5908. var myBlob = new Blob([b], { "type": t });
  5909. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5910. //formData.append('imgFile', b);
  5911. formData.append('dir', isImg ? 'image' : 'file');
  5912. xhr.open('POST', self.uploadJson);
  5913. xhr.onreadystatechange = function () {
  5914. if (xhr.readyState == 4&&xhr.status == 200) {
  5915. // if (fn) {
  5916. var data = _trim(xhr.responseText);
  5917. //if (dataType == 'json') {
  5918. data = _json(data);
  5919. if (data.error) {
  5920. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5921. $.messager.alert('Error', data.message, 'warning');
  5922. } else {
  5923. alert(data.message);
  5924. }
  5925. } else {
  5926. //self.exec('insertimage', url, title, width, height, border, align);
  5927. if(K.undef(self.formatUploadUrl, true))
  5928. data.url =K.formatUrl(data.url, 'absolute');
  5929. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5930. }
  5931. //}
  5932. // fn(data);
  5933. // }
  5934. }
  5935. }
  5936. xhr.send(formData);
  5937. }
  5938. return true;
  5939. }
  5940. }
  5941. //debugger;
  5942. if (dopasteImg())
  5943. e.stop();
  5944. //处理粘贴结束5825
  5945. if (self.pasteType === 0) {
  5946. e.stop();
  5947. return;
  5948. }
  5949. if (pasting) {
  5950. return;
  5951. }
  5952. pasting = true;
  5953. K('div.' + cls, doc).remove();
  5954. cmd = self.cmd.selection();
  5955. bookmark = cmd.range.createBookmark();
  5956. div = K('<div class="' + cls + '"></div>', doc).css({
  5957. position : 'absolute',
  5958. width : '1px',
  5959. height : '1px',
  5960. overflow : 'hidden',
  5961. left : '-1981px',
  5962. top : K(bookmark.start).pos().y + 'px',
  5963. 'white-space' : 'nowrap'
  5964. });
  5965. K(doc.body).append(div);
  5966. if (_IE) {
  5967. var rng = cmd.range.get(true);
  5968. rng.moveToElementText(div[0]);
  5969. rng.select();
  5970. rng.execCommand('paste');
  5971. e.preventDefault();
  5972. } else {
  5973. cmd.range.selectNodeContents(div[0]);
  5974. cmd.select();
  5975. div[0].tabIndex = -1;
  5976. div[0].focus();
  5977. }
  5978. setTimeout(function() {
  5979. movePastedData();
  5980. pasting = false;
  5981. }, 0);
  5982. });
  5983. });
  5984. self.beforeGetHtml(function(html) {
  5985. if (_IE && _V <= 8) {
  5986. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5987. return unescape(tag);
  5988. });
  5989. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5990. if (!/\s+type="[^"]+"/i.test($0)) {
  5991. return $1 + ' type="text"' + $2;
  5992. }
  5993. return $0;
  5994. });
  5995. }
  5996. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5997. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5998. })
  5999. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  6000. var imgAttrs = _getAttrList(full);
  6001. var styles = _getCssList(imgAttrs.style || '');
  6002. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6003. var width = _undef(styles.width, '');
  6004. var height = _undef(styles.height, '');
  6005. if (/px/i.test(width)) {
  6006. width = _removeUnit(width);
  6007. }
  6008. if (/px/i.test(height)) {
  6009. height = _removeUnit(height);
  6010. }
  6011. attrs.width = _undef(imgAttrs.width, width);
  6012. attrs.height = _undef(imgAttrs.height, height);
  6013. return _mediaEmbed(attrs);
  6014. })
  6015. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6016. var imgAttrs = _getAttrList(full);
  6017. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6018. })
  6019. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6020. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6021. })
  6022. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6023. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6024. })
  6025. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6026. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6027. return $1 + _unescape(src) + $2;
  6028. });
  6029. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6030. return full;
  6031. })
  6032. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6033. return start + end;
  6034. });
  6035. });
  6036. self.beforeSetHtml(function(html) {
  6037. if (_IE && _V <= 8) {
  6038. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6039. var attrs = _getAttrList(full);
  6040. var styles = _getCssList(attrs.style || '');
  6041. if (styles.display == 'none') {
  6042. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6043. }
  6044. return full;
  6045. });
  6046. }
  6047. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6048. var attrs = _getAttrList(full);
  6049. attrs.src = _undef(attrs.src, '');
  6050. attrs.width = _undef(attrs.width, 0);
  6051. attrs.height = _undef(attrs.height, 0);
  6052. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6053. })
  6054. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6055. var attrs = _getAttrList(full);
  6056. if (attrs.href !== undefined) {
  6057. return full;
  6058. }
  6059. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6060. })
  6061. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6062. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6063. })
  6064. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6065. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6066. })
  6067. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6068. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6069. return full;
  6070. }
  6071. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6072. return full;
  6073. })
  6074. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6075. return start + 'data-ke-' + end;
  6076. })
  6077. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6078. if (full.indexOf('ke-zeroborder') >= 0) {
  6079. return full;
  6080. }
  6081. return _addClassToTag(full, 'ke-zeroborder');
  6082. });
  6083. });
  6084. });
  6085. })(window);
  6086. /*******************************************************************************
  6087. * KindEditor - WYSIWYG HTML Editor for Internet
  6088. * Copyright (C) 2006-2011 kindsoft.net
  6089. *
  6090. * @author Roddy <luolonghao@gmail.com>
  6091. * @site http://www.kindsoft.net/
  6092. * @licence http://www.kindsoft.net/license.php
  6093. *******************************************************************************/
  6094. KindEditor.lang({
  6095. source : 'HTML代码',
  6096. preview : '预览',
  6097. undo : '后退(Ctrl+Z)',
  6098. redo : '前进(Ctrl+Y)',
  6099. cut : '剪切(Ctrl+X)',
  6100. copy : '复制(Ctrl+C)',
  6101. paste : '粘贴(Ctrl+V)',
  6102. plainpaste : '粘贴为无格式文本',
  6103. wordpaste : '从Word粘贴',
  6104. selectall : '全选(Ctrl+A)',
  6105. justifyleft : '左对齐',
  6106. justifycenter : '居中',
  6107. justifyright : '右对齐',
  6108. justifyfull : '两端对齐',
  6109. insertorderedlist : '编号',
  6110. insertunorderedlist : '项目符号',
  6111. indent : '增加缩进',
  6112. outdent : '减少缩进',
  6113. subscript : '下标',
  6114. superscript : '上标',
  6115. formatblock : '段落',
  6116. fontname : '字体',
  6117. fontsize : '文字大小',
  6118. forecolor : '文字颜色',
  6119. hilitecolor : '文字背景',
  6120. bold : '粗体(Ctrl+B)',
  6121. italic : '斜体(Ctrl+I)',
  6122. underline : '下划线(Ctrl+U)',
  6123. strikethrough : '删除线',
  6124. removeformat : '删除格式',
  6125. image : '图片',
  6126. multiimage : '批量图片上传',
  6127. flash : 'Flash',
  6128. media : '视音频',
  6129. table : '表格',
  6130. tablecell : '单元格',
  6131. hr : '插入横线',
  6132. emoticons : '插入表情',
  6133. link : '超级链接',
  6134. unlink : '取消超级链接',
  6135. fullscreen : '全屏显示',
  6136. about : '关于',
  6137. print : '打印(Ctrl+P)',
  6138. filemanager : '文件空间',
  6139. code : '插入程序代码',
  6140. map : 'Google地图',
  6141. baidumap : '百度地图',
  6142. lineheight : '行距',
  6143. clearhtml : '清理HTML代码',
  6144. pagebreak : '插入分页符',
  6145. quickformat : '一键排版',
  6146. insertfile : '插入文件',
  6147. template : '插入模板',
  6148. anchor : '锚点',
  6149. yes : '确定',
  6150. no : '取消',
  6151. close : '关闭',
  6152. editImage : '图片属性',
  6153. deleteImage : '删除图片',
  6154. editFlash : 'Flash属性',
  6155. deleteFlash : '删除Flash',
  6156. editMedia : '视音频属性',
  6157. deleteMedia : '删除视音频',
  6158. editLink : '超级链接属性',
  6159. deleteLink : '取消超级链接',
  6160. editAnchor : '锚点属性',
  6161. deleteAnchor : '删除锚点',
  6162. tableprop : '表格属性',
  6163. tablecellprop : '单元格属性',
  6164. tableinsert : '插入表格',
  6165. tabledelete : '删除表格',
  6166. tablecolinsertleft : '左侧插入列',
  6167. tablecolinsertright : '右侧插入列',
  6168. tablerowinsertabove : '上方插入行',
  6169. tablerowinsertbelow : '下方插入行',
  6170. tablerowmerge : '向下合并单元格',
  6171. tablecolmerge : '向右合并单元格',
  6172. tablerowsplit : '拆分行',
  6173. tablecolsplit : '拆分列',
  6174. tablecoldelete : '删除列',
  6175. tablerowdelete : '删除行',
  6176. noColor : '无颜色',
  6177. pleaseSelectFile : '请选择文件。',
  6178. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6179. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6180. invalidWidth : "宽度必须为数字。",
  6181. invalidHeight : "高度必须为数字。",
  6182. invalidBorder : "边框必须为数字。",
  6183. invalidUrl : "请输入有效的URL地址。",
  6184. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6185. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6186. invalidPadding : '边距必须为数字。',
  6187. invalidSpacing : '间距必须为数字。',
  6188. invalidJson : '服务器发生故障。',
  6189. uploadSuccess : '上传成功。',
  6190. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6191. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6192. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6193. ajaxLoading : '加载中,请稍候 ...',
  6194. uploadLoading : '上传中,请稍候 ...',
  6195. uploadError : '上传错误',
  6196. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6197. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6198. 'code.pleaseInput' : '请输入程序代码。',
  6199. 'link.url' : 'URL',
  6200. 'link.linkType' : '打开类型',
  6201. 'link.newWindow' : '新窗口',
  6202. 'link.selfWindow' : '当前窗口',
  6203. 'flash.url' : 'URL',
  6204. 'flash.width' : '宽度',
  6205. 'flash.height' : '高度',
  6206. 'flash.upload' : '上传',
  6207. 'flash.viewServer' : '文件空间',
  6208. 'media.url' : 'URL',
  6209. 'media.width' : '宽度',
  6210. 'media.height' : '高度',
  6211. 'media.autostart' : '自动播放',
  6212. 'media.upload' : '上传',
  6213. 'media.viewServer' : '文件空间',
  6214. 'image.remoteImage' : '网络图片',
  6215. 'image.localImage' : '本地上传',
  6216. 'image.remoteUrl' : '图片地址',
  6217. 'image.localUrl' : '上传文件',
  6218. 'image.size' : '图片大小',
  6219. 'image.width' : '宽',
  6220. 'image.height' : '高',
  6221. 'image.resetSize' : '重置大小',
  6222. 'image.align' : '对齐方式',
  6223. 'image.defaultAlign' : '默认方式',
  6224. 'image.leftAlign' : '左对齐',
  6225. 'image.rightAlign' : '右对齐',
  6226. 'image.imgTitle' : '图片说明',
  6227. 'image.upload' : '浏览...',
  6228. 'image.viewServer' : '图片空间',
  6229. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6230. 'multiimage.startUpload' : '开始上传',
  6231. 'multiimage.clearAll' : '全部清空',
  6232. 'multiimage.insertAll' : '全部插入',
  6233. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6234. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6235. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6236. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6237. 'multiimage.unknownError' : '发生异常,无法上传。',
  6238. 'multiimage.pending' : '等待上传',
  6239. 'multiimage.uploadError' : '上传失败',
  6240. 'filemanager.emptyFolder' : '空文件夹',
  6241. 'filemanager.moveup' : '移到上一级文件夹',
  6242. 'filemanager.viewType' : '显示方式:',
  6243. 'filemanager.viewImage' : '缩略图',
  6244. 'filemanager.listImage' : '详细信息',
  6245. 'filemanager.orderType' : '排序方式:',
  6246. 'filemanager.fileName' : '名称',
  6247. 'filemanager.fileSize' : '大小',
  6248. 'filemanager.fileType' : '类型',
  6249. 'insertfile.url' : 'URL',
  6250. 'insertfile.title' : '文件说明',
  6251. 'insertfile.upload' : '上传',
  6252. 'insertfile.viewServer' : '文件空间',
  6253. 'table.cells' : '单元格数',
  6254. 'table.rows' : '行数',
  6255. 'table.cols' : '列数',
  6256. 'table.size' : '大小',
  6257. 'table.width' : '宽度',
  6258. 'table.height' : '高度',
  6259. 'table.percent' : '%',
  6260. 'table.px' : 'px',
  6261. 'table.space' : '边距间距',
  6262. 'table.padding' : '边距',
  6263. 'table.spacing' : '间距',
  6264. 'table.align' : '对齐方式',
  6265. 'table.textAlign' : '水平对齐',
  6266. 'table.verticalAlign' : '垂直对齐',
  6267. 'table.alignDefault' : '默认',
  6268. 'table.alignLeft' : '左对齐',
  6269. 'table.alignCenter' : '居中',
  6270. 'table.alignRight' : '右对齐',
  6271. 'table.alignTop' : '顶部',
  6272. 'table.alignMiddle' : '中部',
  6273. 'table.alignBottom' : '底部',
  6274. 'table.alignBaseline' : '基线',
  6275. 'table.border' : '边框',
  6276. 'table.borderWidth' : '边框',
  6277. 'table.borderColor' : '颜色',
  6278. 'table.backgroundColor' : '背景颜色',
  6279. 'map.address' : '地址: ',
  6280. 'map.search' : '搜索',
  6281. 'baidumap.address' : '地址: ',
  6282. 'baidumap.search' : '搜索',
  6283. 'baidumap.insertDynamicMap' : '插入动态地图',
  6284. 'anchor.name' : '锚点名称',
  6285. 'formatblock.formatBlock' : {
  6286. h1 : '标题 1',
  6287. h2 : '标题 2',
  6288. h3 : '标题 3',
  6289. h4 : '标题 4',
  6290. p : '正 文'
  6291. },
  6292. 'fontname.fontName' : {
  6293. 'SimSun' : '宋体',
  6294. 'NSimSun' : '新宋体',
  6295. 'FangSong_GB2312' : '仿宋_GB2312',
  6296. 'KaiTi_GB2312' : '楷体_GB2312',
  6297. 'SimHei' : '黑体',
  6298. 'Microsoft YaHei' : '微软雅黑',
  6299. 'Arial' : 'Arial',
  6300. 'Arial Black' : 'Arial Black',
  6301. 'Times New Roman' : 'Times New Roman',
  6302. 'Courier New' : 'Courier New',
  6303. 'Tahoma' : 'Tahoma',
  6304. 'Verdana' : 'Verdana'
  6305. },
  6306. 'lineheight.lineHeight' : [
  6307. {'1' : '单倍行距'},
  6308. {'1.5' : '1.5倍行距'},
  6309. {'2' : '2倍行距'},
  6310. {'2.5' : '2.5倍行距'},
  6311. {'3' : '3倍行距'}
  6312. ],
  6313. 'template.selectTemplate' : '可选模板',
  6314. 'template.replaceContent' : '替换当前内容',
  6315. 'template.fileList' : {
  6316. '1.html' : '图片和文字',
  6317. '2.html' : '表格',
  6318. '3.html' : '项目编号'
  6319. }
  6320. }, 'zh-CN');
  6321. KindEditor.options.langType = 'zh-CN';
  6322. /*******************************************************************************
  6323. * KindEditor - WYSIWYG HTML Editor for Internet
  6324. * Copyright (C) 2006-2011 kindsoft.net
  6325. *
  6326. * @author Roddy <luolonghao@gmail.com>
  6327. * @site http://www.kindsoft.net/
  6328. * @licence http://www.kindsoft.net/license.php
  6329. *******************************************************************************/
  6330. KindEditor.plugin('anchor', function(K) {
  6331. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6332. self.plugin.anchor = {
  6333. edit : function() {
  6334. var html = ['<div style="padding:20px;">',
  6335. '<div class="ke-dialog-row">',
  6336. '<label for="keName">' + lang.name + '</label>',
  6337. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6338. '</div>',
  6339. '</div>'].join('');
  6340. var dialog = self.createDialog({
  6341. name : name,
  6342. width : 300,
  6343. title : self.lang(name),
  6344. body : html,
  6345. yesBtn : {
  6346. name : self.lang('yes'),
  6347. click : function(e) {
  6348. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6349. }
  6350. }
  6351. });
  6352. var div = dialog.div,
  6353. nameBox = K('input[name="name"]', div);
  6354. var img = self.plugin.getSelectedAnchor();
  6355. if (img) {
  6356. nameBox.val(unescape(img.attr('data-ke-name')));
  6357. }
  6358. nameBox[0].focus();
  6359. nameBox[0].select();
  6360. },
  6361. 'delete' : function() {
  6362. self.plugin.getSelectedAnchor().remove();
  6363. }
  6364. };
  6365. self.clickToolbar(name, self.plugin.anchor.edit);
  6366. });
  6367. /*******************************************************************************
  6368. * KindEditor - WYSIWYG HTML Editor for Internet
  6369. * Copyright (C) 2006-2011 kindsoft.net
  6370. *
  6371. * @author Roddy <luolonghao@gmail.com>
  6372. * @site http://www.kindsoft.net/
  6373. * @licence http://www.kindsoft.net/license.php
  6374. *******************************************************************************/
  6375. KindEditor.plugin('autoheight', function(K) {
  6376. var self = this;
  6377. if (!self.autoHeightMode) {
  6378. return;
  6379. }
  6380. var minHeight;
  6381. function hideScroll() {
  6382. var edit = self.edit;
  6383. var body = edit.doc.body;
  6384. edit.iframe[0].scroll = 'no';
  6385. body.style.overflowY = 'hidden';
  6386. }
  6387. function resetHeight() {
  6388. if(self.fullscreenMode){
  6389. return;
  6390. }
  6391. var edit = self.edit;
  6392. var body = edit.doc.body;
  6393. edit.iframe.height(minHeight);
  6394. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6395. }
  6396. function init() {
  6397. minHeight = K.removeUnit(self.height);
  6398. self.edit.afterChange(resetHeight);
  6399. if(!self.fullscreenMode){
  6400. hideScroll();
  6401. }
  6402. resetHeight();
  6403. }
  6404. if (self.isCreated) {
  6405. init();
  6406. } else {
  6407. self.afterCreate(init);
  6408. }
  6409. });
  6410. /*
  6411. * 如何实现真正的自动高度?
  6412. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6413. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6414. * 由此就实现了真正的自动高度
  6415. * 测试:chrome、firefox、IE9、IE8
  6416. * */
  6417. /*******************************************************************************
  6418. * KindEditor - WYSIWYG HTML Editor for Internet
  6419. * Copyright (C) 2006-2011 kindsoft.net
  6420. *
  6421. * @author Roddy <luolonghao@gmail.com>
  6422. * @site http://www.kindsoft.net/
  6423. * @licence http://www.kindsoft.net/license.php
  6424. *******************************************************************************/
  6425. KindEditor.plugin('baidumap', function(K) {
  6426. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6427. var mapWidth = K.undef(self.mapWidth, 558);
  6428. var mapHeight = K.undef(self.mapHeight, 360);
  6429. self.clickToolbar(name, function() {
  6430. var html = ['<div style="padding:10px 20px;">',
  6431. '<div class="ke-header">',
  6432. '<div class="ke-left">',
  6433. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6434. '<span class="ke-button-common ke-button-outer">',
  6435. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6436. '</span>',
  6437. '</div>',
  6438. '<div class="ke-right">',
  6439. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6440. '</div>',
  6441. '<div class="ke-clearfix"></div>',
  6442. '</div>',
  6443. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6444. '</div>'].join('');
  6445. var dialog = self.createDialog({
  6446. name : name,
  6447. width : mapWidth + 42,
  6448. title : self.lang(name),
  6449. body : html,
  6450. yesBtn : {
  6451. name : self.lang('yes'),
  6452. click : function(e) {
  6453. var map = win.map;
  6454. var centerObj = map.getCenter();
  6455. var center = centerObj.lng + ',' + centerObj.lat;
  6456. var zoom = map.getZoom();
  6457. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6458. '?center=' + encodeURIComponent(center),
  6459. '&zoom=' + encodeURIComponent(zoom),
  6460. '&width=' + mapWidth,
  6461. '&height=' + mapHeight,
  6462. '&markers=' + encodeURIComponent(center),
  6463. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6464. if (checkbox[0].checked) {
  6465. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6466. } else {
  6467. self.exec('insertimage', url);
  6468. }
  6469. self.hideDialog().focus();
  6470. }
  6471. },
  6472. beforeRemove : function() {
  6473. searchBtn.remove();
  6474. if (doc) {
  6475. doc.write('');
  6476. }
  6477. iframe.remove();
  6478. }
  6479. });
  6480. var div = dialog.div,
  6481. addressBox = K('[name="address"]', div),
  6482. searchBtn = K('[name="searchBtn"]', div),
  6483. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6484. win, doc;
  6485. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6486. function ready() {
  6487. win = iframe[0].contentWindow;
  6488. doc = K.iframeDoc(iframe);
  6489. }
  6490. iframe.bind('load', function() {
  6491. iframe.unbind('load');
  6492. if (K.IE) {
  6493. ready();
  6494. } else {
  6495. setTimeout(ready, 0);
  6496. }
  6497. });
  6498. K('.ke-map', div).replaceWith(iframe);
  6499. searchBtn.click(function() {
  6500. win.search(addressBox.val());
  6501. });
  6502. });
  6503. });
  6504. /*******************************************************************************
  6505. * KindEditor - WYSIWYG HTML Editor for Internet
  6506. * Copyright (C) 2006-2011 kindsoft.net
  6507. *
  6508. * @author Roddy <luolonghao@gmail.com>
  6509. * @site http://www.kindsoft.net/
  6510. * @licence http://www.kindsoft.net/license.php
  6511. *******************************************************************************/
  6512. KindEditor.plugin('map', function(K) {
  6513. var self = this, name = 'map', lang = self.lang(name + '.');
  6514. self.clickToolbar(name, function() {
  6515. var html = ['<div style="padding:10px 20px;">',
  6516. '<div class="ke-dialog-row">',
  6517. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6518. '<span class="ke-button-common ke-button-outer">',
  6519. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6520. '</span>',
  6521. '</div>',
  6522. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6523. '</div>'].join('');
  6524. var dialog = self.createDialog({
  6525. name : name,
  6526. width : 600,
  6527. title : self.lang(name),
  6528. body : html,
  6529. yesBtn : {
  6530. name : self.lang('yes'),
  6531. click : function(e) {
  6532. var geocoder = win.geocoder,
  6533. map = win.map,
  6534. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6535. zoom = map.getZoom(),
  6536. maptype = map.getMapTypeId(),
  6537. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6538. url += '?center=' + encodeURIComponent(center);
  6539. url += '&zoom=' + encodeURIComponent(zoom);
  6540. url += '&size=558x360';
  6541. url += '&maptype=' + encodeURIComponent(maptype);
  6542. url += '&markers=' + encodeURIComponent(center);
  6543. url += '&language=' + self.langType;
  6544. url += '&sensor=false';
  6545. self.exec('insertimage', url).hideDialog().focus();
  6546. }
  6547. },
  6548. beforeRemove : function() {
  6549. searchBtn.remove();
  6550. if (doc) {
  6551. doc.write('');
  6552. }
  6553. iframe.remove();
  6554. }
  6555. });
  6556. var div = dialog.div,
  6557. addressBox = K('[name="address"]', div),
  6558. searchBtn = K('[name="searchBtn"]', div),
  6559. win, doc;
  6560. var iframeHtml = ['<!doctype html><html><head>',
  6561. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6562. '<style>',
  6563. ' html { height: 100% }',
  6564. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6565. ' #map_canvas { height: 100% }',
  6566. '</style>',
  6567. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6568. '<script>',
  6569. 'var map, geocoder;',
  6570. 'function initialize() {',
  6571. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6572. ' var options = {',
  6573. ' zoom: 11,',
  6574. ' center: latlng,',
  6575. ' disableDefaultUI: true,',
  6576. ' panControl: true,',
  6577. ' zoomControl: true,',
  6578. ' mapTypeControl: true,',
  6579. ' scaleControl: true,',
  6580. ' streetViewControl: false,',
  6581. ' overviewMapControl: true,',
  6582. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6583. ' };',
  6584. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6585. ' geocoder = new google.maps.Geocoder();',
  6586. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6587. ' if (status == google.maps.GeocoderStatus.OK) {',
  6588. ' if (results[3]) {',
  6589. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6590. ' }',
  6591. ' }',
  6592. ' });',
  6593. '}',
  6594. 'function search(address) {',
  6595. ' if (!map) return;',
  6596. ' geocoder.geocode({address : address}, function(results, status) {',
  6597. ' if (status == google.maps.GeocoderStatus.OK) {',
  6598. ' map.setZoom(11);',
  6599. ' map.setCenter(results[0].geometry.location);',
  6600. ' var marker = new google.maps.Marker({',
  6601. ' map: map,',
  6602. ' position: results[0].geometry.location',
  6603. ' });',
  6604. ' } else {',
  6605. ' alert("Invalid address: " + address);',
  6606. ' }',
  6607. ' });',
  6608. '}',
  6609. '</script>',
  6610. '</head>',
  6611. '<body onload="initialize();">',
  6612. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6613. '</body></html>'].join('\n');
  6614. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6615. function ready() {
  6616. win = iframe[0].contentWindow;
  6617. doc = K.iframeDoc(iframe);
  6618. }
  6619. iframe.bind('load', function() {
  6620. iframe.unbind('load');
  6621. if (K.IE) {
  6622. ready();
  6623. } else {
  6624. setTimeout(ready, 0);
  6625. }
  6626. });
  6627. K('.ke-map', div).replaceWith(iframe);
  6628. searchBtn.click(function() {
  6629. win.search(addressBox.val());
  6630. });
  6631. });
  6632. });
  6633. /*******************************************************************************
  6634. * KindEditor - WYSIWYG HTML Editor for Internet
  6635. * Copyright (C) 2006-2011 kindsoft.net
  6636. *
  6637. * @author Roddy <luolonghao@gmail.com>
  6638. * @site http://www.kindsoft.net/
  6639. * @licence http://www.kindsoft.net/license.php
  6640. *******************************************************************************/
  6641. KindEditor.plugin('clearhtml', function(K) {
  6642. var self = this, name = 'clearhtml';
  6643. self.clickToolbar(name, function() {
  6644. self.focus();
  6645. var html = self.html();
  6646. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6647. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6648. html = K.formatHtml(html, {
  6649. a : ['href', 'target'],
  6650. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6651. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6652. table : ['border'],
  6653. 'td,th' : ['rowspan', 'colspan'],
  6654. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6655. });
  6656. self.html(html);
  6657. self.cmd.selection(true);
  6658. self.addBookmark();
  6659. });
  6660. });
  6661. /*******************************************************************************
  6662. * KindEditor - WYSIWYG HTML Editor for Internet
  6663. * Copyright (C) 2006-2011 kindsoft.net
  6664. *
  6665. * @author Roddy <luolonghao@gmail.com>
  6666. * @site http://www.kindsoft.net/
  6667. * @licence http://www.kindsoft.net/license.php
  6668. *******************************************************************************/
  6669. KindEditor.plugin('code', function(K) {
  6670. var self = this, name = 'code';
  6671. self.clickToolbar(name, function() {
  6672. var lang = self.lang(name + '.'),
  6673. html = ['<div style="padding:10px 20px;">',
  6674. '<div class="ke-dialog-row">',
  6675. '<select class="ke-code-type">',
  6676. '<option value="js">JavaScript</option>',
  6677. '<option value="html">HTML</option>',
  6678. '<option value="css">CSS</option>',
  6679. '<option value="php">PHP</option>',
  6680. '<option value="pl">Perl</option>',
  6681. '<option value="py">Python</option>',
  6682. '<option value="rb">Ruby</option>',
  6683. '<option value="java">Java</option>',
  6684. '<option value="vb">ASP/VB</option>',
  6685. '<option value="cpp">C/C++</option>',
  6686. '<option value="cs">C#</option>',
  6687. '<option value="xml">XML</option>',
  6688. '<option value="bsh">Shell</option>',
  6689. '<option value="">Other</option>',
  6690. '</select>',
  6691. '</div>',
  6692. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6693. '</div>'].join(''),
  6694. dialog = self.createDialog({
  6695. name : name,
  6696. width : 450,
  6697. title : self.lang(name),
  6698. body : html,
  6699. yesBtn : {
  6700. name : self.lang('yes'),
  6701. click : function(e) {
  6702. var type = K('.ke-code-type', dialog.div).val(),
  6703. code = textarea.val(),
  6704. cls = type === '' ? '' : ' lang-' + type,
  6705. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6706. if (K.trim(code) === '') {
  6707. alert(lang.pleaseInput);
  6708. textarea[0].focus();
  6709. return;
  6710. }
  6711. self.insertHtml(html).hideDialog().focus();
  6712. }
  6713. }
  6714. }),
  6715. textarea = K('textarea', dialog.div);
  6716. textarea[0].focus();
  6717. });
  6718. });
  6719. /*******************************************************************************
  6720. * KindEditor - WYSIWYG HTML Editor for Internet
  6721. * Copyright (C) 2006-2011 kindsoft.net
  6722. *
  6723. * @author Roddy <luolonghao@gmail.com>
  6724. * @site http://www.kindsoft.net/
  6725. * @licence http://www.kindsoft.net/license.php
  6726. *******************************************************************************/
  6727. KindEditor.plugin('emoticons', function(K) {
  6728. var self = this, name = 'emoticons',
  6729. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6730. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6731. currentPageNum = 1;
  6732. self.clickToolbar(name, function() {
  6733. var rows = 5, cols = 9, total = 135, startNum = 0,
  6734. cells = rows * cols, pages = Math.ceil(total / cells),
  6735. colsHalf = Math.floor(cols / 2),
  6736. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6737. elements = [],
  6738. menu = self.createMenu({
  6739. name : name,
  6740. beforeRemove : function() {
  6741. removeEvent();
  6742. }
  6743. });
  6744. menu.div.append(wrapperDiv);
  6745. var previewDiv, previewImg;
  6746. if (allowPreview) {
  6747. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6748. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6749. wrapperDiv.append(previewDiv);
  6750. previewDiv.append(previewImg);
  6751. }
  6752. function bindCellEvent(cell, j, num) {
  6753. if (previewDiv) {
  6754. cell.mouseover(function() {
  6755. if (j > colsHalf) {
  6756. previewDiv.css('left', 0);
  6757. previewDiv.css('right', '');
  6758. } else {
  6759. previewDiv.css('left', '');
  6760. previewDiv.css('right', 0);
  6761. }
  6762. previewImg.attr('src', path + num + '.gif');
  6763. K(this).addClass('ke-on');
  6764. });
  6765. } else {
  6766. cell.mouseover(function() {
  6767. K(this).addClass('ke-on');
  6768. });
  6769. }
  6770. cell.mouseout(function() {
  6771. K(this).removeClass('ke-on');
  6772. });
  6773. cell.click(function(e) {
  6774. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6775. e.stop();
  6776. });
  6777. }
  6778. function createEmoticonsTable(pageNum, parentDiv) {
  6779. var table = document.createElement('table');
  6780. parentDiv.append(table);
  6781. if (previewDiv) {
  6782. K(table).mouseover(function() {
  6783. previewDiv.show('block');
  6784. });
  6785. K(table).mouseout(function() {
  6786. previewDiv.hide();
  6787. });
  6788. elements.push(K(table));
  6789. }
  6790. table.className = 'ke-table';
  6791. table.cellPadding = 0;
  6792. table.cellSpacing = 0;
  6793. table.border = 0;
  6794. var num = (pageNum - 1) * cells + startNum;
  6795. for (var i = 0; i < rows; i++) {
  6796. var row = table.insertRow(i);
  6797. for (var j = 0; j < cols; j++) {
  6798. var cell = K(row.insertCell(j));
  6799. cell.addClass('ke-cell');
  6800. bindCellEvent(cell, j, num);
  6801. var span = K('<span class="ke-img"></span>')
  6802. .css('background-position', '-' + (24 * num) + 'px 0px')
  6803. .css('background-image', 'url(' + path + 'static.gif)');
  6804. cell.append(span);
  6805. elements.push(cell);
  6806. num++;
  6807. }
  6808. }
  6809. return table;
  6810. }
  6811. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6812. function removeEvent() {
  6813. K.each(elements, function() {
  6814. this.unbind();
  6815. });
  6816. }
  6817. var pageDiv;
  6818. function bindPageEvent(el, pageNum) {
  6819. el.click(function(e) {
  6820. removeEvent();
  6821. table.parentNode.removeChild(table);
  6822. pageDiv.remove();
  6823. table = createEmoticonsTable(pageNum, wrapperDiv);
  6824. createPageTable(pageNum);
  6825. currentPageNum = pageNum;
  6826. e.stop();
  6827. });
  6828. }
  6829. function createPageTable(currentPageNum) {
  6830. pageDiv = K('<div class="ke-page"></div>');
  6831. wrapperDiv.append(pageDiv);
  6832. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6833. if (currentPageNum !== pageNum) {
  6834. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6835. bindPageEvent(a, pageNum);
  6836. pageDiv.append(a);
  6837. elements.push(a);
  6838. } else {
  6839. pageDiv.append(K('@[' + pageNum + ']'));
  6840. }
  6841. pageDiv.append(K('@&nbsp;'));
  6842. }
  6843. }
  6844. createPageTable(currentPageNum);
  6845. });
  6846. });
  6847. /*******************************************************************************
  6848. * KindEditor - WYSIWYG HTML Editor for Internet
  6849. * Copyright (C) 2006-2011 kindsoft.net
  6850. *
  6851. * @author Roddy <luolonghao@gmail.com>
  6852. * @site http://www.kindsoft.net/
  6853. * @licence http://www.kindsoft.net/license.php
  6854. *******************************************************************************/
  6855. KindEditor.plugin('filemanager', function(K) {
  6856. var self = this, name = 'filemanager',
  6857. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6858. imgPath = self.pluginsPath + name + '/images/',
  6859. lang = self.lang(name + '.');
  6860. function makeFileTitle(filename, filesize, datetime) {
  6861. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6862. }
  6863. function bindTitle(el, data) {
  6864. if (data.is_dir) {
  6865. el.attr('title', data.filename);
  6866. } else {
  6867. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6868. }
  6869. }
  6870. self.plugin.filemanagerDialog = function(options) {
  6871. var width = K.undef(options.width, 650),
  6872. height = K.undef(options.height, 510),
  6873. dirName = K.undef(options.dirName, ''),
  6874. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6875. clickFn = options.clickFn;
  6876. var html = [
  6877. '<div style="padding:10px 20px;">',
  6878. '<div class="ke-plugin-filemanager-header">',
  6879. '<div class="ke-left">',
  6880. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6881. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6882. '</div>',
  6883. '<div class="ke-right">',
  6884. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6885. '<option value="VIEW">' + lang.viewImage + '</option>',
  6886. '<option value="LIST">' + lang.listImage + '</option>',
  6887. '</select> ',
  6888. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6889. '<option value="NAME">' + lang.fileName + '</option>',
  6890. '<option value="SIZE">' + lang.fileSize + '</option>',
  6891. '<option value="TYPE">' + lang.fileType + '</option>',
  6892. '</select>',
  6893. '</div>',
  6894. '<div class="ke-clearfix"></div>',
  6895. '</div>',
  6896. '<div class="ke-plugin-filemanager-body"></div>',
  6897. '</div>'
  6898. ].join('');
  6899. var dialog = self.createDialog({
  6900. name : name,
  6901. width : width,
  6902. height : height,
  6903. title : self.lang(name),
  6904. body : html
  6905. }),
  6906. div = dialog.div,
  6907. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6908. moveupImg = K('[name="moveupImg"]', div),
  6909. moveupLink = K('[name="moveupLink"]', div),
  6910. viewServerBtn = K('[name="viewServer"]', div),
  6911. viewTypeBox = K('[name="viewType"]', div),
  6912. orderTypeBox = K('[name="orderType"]', div);
  6913. function reloadPage(path, order, func) {
  6914. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6915. dialog.showLoading(self.lang('ajaxLoading'));
  6916. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6917. dialog.hideLoading();
  6918. func(data);
  6919. });
  6920. }
  6921. var elList = [];
  6922. function bindEvent(el, result, data, createFunc) {
  6923. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6924. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6925. if (data.is_dir) {
  6926. el.click(function(e) {
  6927. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6928. });
  6929. } else if (data.is_photo) {
  6930. el.click(function(e) {
  6931. clickFn.call(this, fileUrl, data.filename);
  6932. });
  6933. } else {
  6934. el.click(function(e) {
  6935. clickFn.call(this, fileUrl, data.filename);
  6936. });
  6937. }
  6938. elList.push(el);
  6939. }
  6940. function createCommon(result, createFunc) {
  6941. K.each(elList, function() {
  6942. this.unbind();
  6943. });
  6944. moveupLink.unbind();
  6945. viewTypeBox.unbind();
  6946. orderTypeBox.unbind();
  6947. if (result.current_dir_path) {
  6948. moveupLink.click(function(e) {
  6949. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6950. });
  6951. }
  6952. function changeFunc() {
  6953. if (viewTypeBox.val() == 'VIEW') {
  6954. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6955. } else {
  6956. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6957. }
  6958. }
  6959. viewTypeBox.change(changeFunc);
  6960. orderTypeBox.change(changeFunc);
  6961. bodyDiv.html('');
  6962. }
  6963. function createList(result) {
  6964. createCommon(result, createList);
  6965. var table = document.createElement('table');
  6966. table.className = 'ke-table';
  6967. table.cellPadding = 0;
  6968. table.cellSpacing = 0;
  6969. table.border = 0;
  6970. bodyDiv.append(table);
  6971. var fileList = result.file_list;
  6972. for (var i = 0, len = fileList.length; i < len; i++) {
  6973. var data = fileList[i], row = K(table.insertRow(i));
  6974. row.mouseover(function(e) {
  6975. K(this).addClass('ke-on');
  6976. })
  6977. .mouseout(function(e) {
  6978. K(this).removeClass('ke-on');
  6979. });
  6980. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6981. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6982. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6983. if (!data.is_dir || data.has_file) {
  6984. row.css('cursor', 'pointer');
  6985. cell0.attr('title', data.filename);
  6986. bindEvent(cell0, result, data, createList);
  6987. } else {
  6988. cell0.attr('title', lang.emptyFolder);
  6989. }
  6990. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6991. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6992. }
  6993. }
  6994. function createView(result) {
  6995. createCommon(result, createView);
  6996. var fileList = result.file_list;
  6997. for (var i = 0, len = fileList.length; i < len; i++) {
  6998. var data = fileList[i],
  6999. div = K('<div class="ke-inline-block ke-item"></div>');
  7000. bodyDiv.append(div);
  7001. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7002. .mouseover(function(e) {
  7003. K(this).addClass('ke-on');
  7004. })
  7005. .mouseout(function(e) {
  7006. K(this).removeClass('ke-on');
  7007. });
  7008. div.append(photoDiv);
  7009. var fileUrl = result.current_url + data.filename,
  7010. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7011. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7012. if (!data.is_dir || data.has_file) {
  7013. photoDiv.css('cursor', 'pointer');
  7014. bindTitle(photoDiv, data);
  7015. bindEvent(photoDiv, result, data, createView);
  7016. } else {
  7017. photoDiv.attr('title', lang.emptyFolder);
  7018. }
  7019. photoDiv.append(img);
  7020. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7021. }
  7022. }
  7023. viewTypeBox.val(viewType);
  7024. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7025. return dialog;
  7026. }
  7027. });
  7028. /*******************************************************************************
  7029. * KindEditor - WYSIWYG HTML Editor for Internet
  7030. * Copyright (C) 2006-2011 kindsoft.net
  7031. *
  7032. * @author Roddy <luolonghao@gmail.com>
  7033. * @site http://www.kindsoft.net/
  7034. * @licence http://www.kindsoft.net/license.php
  7035. *******************************************************************************/
  7036. KindEditor.plugin('flash', function(K) {
  7037. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7038. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7039. allowFileManager = K.undef(self.allowFileManager, false),
  7040. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7041. extraParams = K.undef(self.extraFileUploadParams, {}),
  7042. filePostName = K.undef(self.filePostName, 'imgFile'),
  7043. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7044. self.plugin.flash = {
  7045. edit : function() {
  7046. var html = [
  7047. '<div style="padding:20px;">',
  7048. '<div class="ke-dialog-row">',
  7049. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7050. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7051. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7052. '<span class="ke-button-common ke-button-outer">',
  7053. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7054. '</span>',
  7055. '</div>',
  7056. '<div class="ke-dialog-row">',
  7057. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7058. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7059. '</div>',
  7060. '<div class="ke-dialog-row">',
  7061. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7062. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7063. '</div>',
  7064. '</div>'
  7065. ].join('');
  7066. var dialog = self.createDialog({
  7067. name : name,
  7068. width : 450,
  7069. title : self.lang(name),
  7070. body : html,
  7071. yesBtn : {
  7072. name : self.lang('yes'),
  7073. click : function(e) {
  7074. var url = K.trim(urlBox.val()),
  7075. width = widthBox.val(),
  7076. height = heightBox.val();
  7077. if (url == 'http://' || K.invalidUrl(url)) {
  7078. alert(self.lang('invalidUrl'));
  7079. urlBox[0].focus();
  7080. return;
  7081. }
  7082. if (!/^\d*$/.test(width)) {
  7083. alert(self.lang('invalidWidth'));
  7084. widthBox[0].focus();
  7085. return;
  7086. }
  7087. if (!/^\d*$/.test(height)) {
  7088. alert(self.lang('invalidHeight'));
  7089. heightBox[0].focus();
  7090. return;
  7091. }
  7092. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7093. src : url,
  7094. type : K.mediaType('.swf'),
  7095. width : width,
  7096. height : height,
  7097. quality : 'high'
  7098. });
  7099. self.insertHtml(html).hideDialog().focus();
  7100. }
  7101. }
  7102. }),
  7103. div = dialog.div,
  7104. urlBox = K('[name="url"]', div),
  7105. viewServerBtn = K('[name="viewServer"]', div),
  7106. widthBox = K('[name="width"]', div),
  7107. heightBox = K('[name="height"]', div);
  7108. urlBox.val('http://');
  7109. if (allowFlashUpload) {
  7110. var uploadbutton = K.uploadbutton({
  7111. button : K('.ke-upload-button', div)[0],
  7112. fieldName : filePostName,
  7113. extraParams : extraParams,
  7114. url : K.addParam(uploadJson, 'dir=flash'),
  7115. afterUpload : function(data) {
  7116. dialog.hideLoading();
  7117. if (data.error === 0) {
  7118. var url = data.url;
  7119. if (formatUploadUrl) {
  7120. url = K.formatUrl(url, 'absolute');
  7121. }
  7122. urlBox.val(url);
  7123. if (self.afterUpload) {
  7124. self.afterUpload.call(self, url, data, name);
  7125. }
  7126. alert(self.lang('uploadSuccess'));
  7127. } else {
  7128. alert(data.message);
  7129. }
  7130. },
  7131. afterError : function(html) {
  7132. dialog.hideLoading();
  7133. self.errorDialog(html);
  7134. }
  7135. });
  7136. uploadbutton.fileBox.change(function(e) {
  7137. dialog.showLoading(self.lang('uploadLoading'));
  7138. uploadbutton.submit();
  7139. });
  7140. } else {
  7141. K('.ke-upload-button', div).hide();
  7142. }
  7143. if (allowFileManager) {
  7144. viewServerBtn.click(function(e) {
  7145. self.loadPlugin('filemanager', function() {
  7146. self.plugin.filemanagerDialog({
  7147. viewType : 'LIST',
  7148. dirName : 'flash',
  7149. clickFn : function(url, title) {
  7150. if (self.dialogs.length > 1) {
  7151. K('[name="url"]', div).val(url);
  7152. if (self.afterSelectFile) {
  7153. self.afterSelectFile.call(self, url);
  7154. }
  7155. self.hideDialog();
  7156. }
  7157. }
  7158. });
  7159. });
  7160. });
  7161. } else {
  7162. viewServerBtn.hide();
  7163. }
  7164. var img = self.plugin.getSelectedFlash();
  7165. if (img) {
  7166. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7167. urlBox.val(attrs.src);
  7168. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7169. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7170. }
  7171. urlBox[0].focus();
  7172. urlBox[0].select();
  7173. },
  7174. 'delete' : function() {
  7175. self.plugin.getSelectedFlash().remove();
  7176. self.addBookmark();
  7177. }
  7178. };
  7179. self.clickToolbar(name, self.plugin.flash.edit);
  7180. });
  7181. /*******************************************************************************
  7182. * KindEditor - WYSIWYG HTML Editor for Internet
  7183. * Copyright (C) 2006-2011 kindsoft.net
  7184. *
  7185. * @author Roddy <luolonghao@gmail.com>
  7186. * @site http://www.kindsoft.net/
  7187. * @licence http://www.kindsoft.net/license.php
  7188. *******************************************************************************/
  7189. KindEditor.plugin('image', function(K) {
  7190. var self = this, name = 'image',
  7191. allowImageUpload = K.undef(self.allowImageUpload, true),
  7192. allowImageRemote = K.undef(self.allowImageRemote, true),
  7193. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7194. allowFileManager = K.undef(self.allowFileManager, false),
  7195. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7196. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7197. imgPath = self.pluginsPath + 'image/images/',
  7198. extraParams = K.undef(self.extraFileUploadParams, {}),
  7199. filePostName = K.undef(self.filePostName, 'imgFile'),
  7200. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7201. lang = self.lang(name + '.');
  7202. self.plugin.imageDialog = function(options) {
  7203. var imageUrl = options.imageUrl,
  7204. imageWidth = K.undef(options.imageWidth, ''),
  7205. imageHeight = K.undef(options.imageHeight, ''),
  7206. imageTitle = K.undef(options.imageTitle, ''),
  7207. imageAlign = K.undef(options.imageAlign, ''),
  7208. showRemote = K.undef(options.showRemote, true),
  7209. showLocal = K.undef(options.showLocal, true),
  7210. tabIndex = K.undef(options.tabIndex, 0),
  7211. clickFn = options.clickFn;
  7212. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7213. var hiddenElements = [];
  7214. for(var k in extraParams){
  7215. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7216. }
  7217. var html = [
  7218. '<div style="padding:20px;">',
  7219. '<div class="tabs"></div>',
  7220. '<div class="tab1" style="display:none;">',
  7221. '<div class="ke-dialog-row">',
  7222. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7223. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7224. '<span class="ke-button-common ke-button-outer">',
  7225. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7226. '</span>',
  7227. '</div>',
  7228. '<div class="ke-dialog-row">',
  7229. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7230. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7231. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7232. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7233. '</div>',
  7234. '<div class="ke-dialog-row">',
  7235. '<label style="width:60px;">' + lang.align + '</label>',
  7236. '<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="" />',
  7237. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7238. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7239. '</div>',
  7240. '<div class="ke-dialog-row">',
  7241. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7242. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7243. '</div>',
  7244. '</div>',
  7245. '<div class="tab2" style="display:none;">',
  7246. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7247. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7248. '<div class="ke-dialog-row">',
  7249. hiddenElements.join(''),
  7250. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7251. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7252. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7253. '</div>',
  7254. '</form>',
  7255. '</div>',
  7256. '</div>'
  7257. ].join('');
  7258. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7259. dialogHeight = showLocal && showRemote ? 300 : 250;
  7260. var dialog = self.createDialog({
  7261. name : name,
  7262. width : dialogWidth,
  7263. height : dialogHeight,
  7264. title : self.lang(name),
  7265. body : html,
  7266. yesBtn : {
  7267. name : self.lang('yes'),
  7268. click : function(e) {
  7269. if (dialog.isLoading) {
  7270. return;
  7271. }
  7272. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7273. if (uploadbutton.fileBox.val() == '') {
  7274. alert(self.lang('pleaseSelectFile'));
  7275. return;
  7276. }
  7277. dialog.showLoading(self.lang('uploadLoading'));
  7278. uploadbutton.submit();
  7279. localUrlBox.val('');
  7280. return;
  7281. }
  7282. var url = K.trim(urlBox.val()),
  7283. width = widthBox.val(),
  7284. height = heightBox.val(),
  7285. title = titleBox.val(),
  7286. align = '';
  7287. alignBox.each(function() {
  7288. if (this.checked) {
  7289. align = this.value;
  7290. return false;
  7291. }
  7292. });
  7293. if (url == 'http://' || K.invalidUrl(url)) {
  7294. alert(self.lang('invalidUrl'));
  7295. urlBox[0].focus();
  7296. return;
  7297. }
  7298. if (!/^\d*$/.test(width)) {
  7299. alert(self.lang('invalidWidth'));
  7300. widthBox[0].focus();
  7301. return;
  7302. }
  7303. if (!/^\d*$/.test(height)) {
  7304. alert(self.lang('invalidHeight'));
  7305. heightBox[0].focus();
  7306. return;
  7307. }
  7308. clickFn.call(self, url, title, width, height, 0, align);
  7309. }
  7310. },
  7311. beforeRemove : function() {
  7312. viewServerBtn.unbind();
  7313. widthBox.unbind();
  7314. heightBox.unbind();
  7315. refreshBtn.unbind();
  7316. }
  7317. }),
  7318. div = dialog.div;
  7319. var urlBox = K('[name="url"]', div),
  7320. localUrlBox = K('[name="localUrl"]', div),
  7321. viewServerBtn = K('[name="viewServer"]', div),
  7322. widthBox = K('.tab1 [name="width"]', div),
  7323. heightBox = K('.tab1 [name="height"]', div),
  7324. refreshBtn = K('.ke-refresh-btn', div),
  7325. titleBox = K('.tab1 [name="title"]', div),
  7326. alignBox = K('.tab1 [name="align"]', div);
  7327. var tabs;
  7328. if (showRemote && showLocal) {
  7329. tabs = K.tabs({
  7330. src : K('.tabs', div),
  7331. afterSelect : function(i) {}
  7332. });
  7333. tabs.add({
  7334. title : lang.remoteImage,
  7335. panel : K('.tab1', div)
  7336. });
  7337. tabs.add({
  7338. title : lang.localImage,
  7339. panel : K('.tab2', div)
  7340. });
  7341. tabs.select(tabIndex);
  7342. } else if (showRemote) {
  7343. K('.tab1', div).show();
  7344. } else if (showLocal) {
  7345. K('.tab2', div).show();
  7346. }
  7347. var uploadbutton = K.uploadbutton({
  7348. button : K('.ke-upload-button', div)[0],
  7349. fieldName : filePostName,
  7350. form : K('.ke-form', div),
  7351. target : target,
  7352. width: 60,
  7353. afterUpload : function(data) {
  7354. dialog.hideLoading();
  7355. if (data.error === 0) {
  7356. var url = data.url;
  7357. if (formatUploadUrl) {
  7358. url = K.formatUrl(url, 'absolute');
  7359. }
  7360. if (self.afterUpload) {
  7361. self.afterUpload.call(self, url, data, name);
  7362. }
  7363. if (!fillDescAfterUploadImage) {
  7364. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7365. } else {
  7366. K(".ke-dialog-row #remoteUrl", div).val(url);
  7367. K(".ke-tabs-li", div)[0].click();
  7368. K(".ke-refresh-btn", div).click();
  7369. }
  7370. } else {
  7371. alert(data.message);
  7372. }
  7373. },
  7374. afterError : function(html) {
  7375. dialog.hideLoading();
  7376. self.errorDialog(html);
  7377. }
  7378. });
  7379. uploadbutton.fileBox.change(function(e) {
  7380. localUrlBox.val(uploadbutton.fileBox.val());
  7381. });
  7382. if (allowFileManager) {
  7383. viewServerBtn.click(function(e) {
  7384. self.loadPlugin('filemanager', function() {
  7385. self.plugin.filemanagerDialog({
  7386. viewType : 'VIEW',
  7387. dirName : 'image',
  7388. clickFn : function(url, title) {
  7389. if (self.dialogs.length > 1) {
  7390. K('[name="url"]', div).val(url);
  7391. if (self.afterSelectFile) {
  7392. self.afterSelectFile.call(self, url);
  7393. }
  7394. self.hideDialog();
  7395. }
  7396. }
  7397. });
  7398. });
  7399. });
  7400. } else {
  7401. viewServerBtn.hide();
  7402. }
  7403. var originalWidth = 0, originalHeight = 0;
  7404. function setSize(width, height) {
  7405. widthBox.val(width);
  7406. heightBox.val(height);
  7407. originalWidth = width;
  7408. originalHeight = height;
  7409. }
  7410. refreshBtn.click(function(e) {
  7411. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7412. position : 'absolute',
  7413. visibility : 'hidden',
  7414. top : 0,
  7415. left : '-1000px'
  7416. });
  7417. tempImg.bind('load', function() {
  7418. setSize(tempImg.width(), tempImg.height());
  7419. tempImg.remove();
  7420. });
  7421. K(document.body).append(tempImg);
  7422. });
  7423. widthBox.change(function(e) {
  7424. if (originalWidth > 0) {
  7425. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7426. }
  7427. });
  7428. heightBox.change(function(e) {
  7429. if (originalHeight > 0) {
  7430. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7431. }
  7432. });
  7433. urlBox.val(options.imageUrl);
  7434. setSize(options.imageWidth, options.imageHeight);
  7435. titleBox.val(options.imageTitle);
  7436. alignBox.each(function() {
  7437. if (this.value === options.imageAlign) {
  7438. this.checked = true;
  7439. return false;
  7440. }
  7441. });
  7442. if (showRemote && tabIndex === 0) {
  7443. urlBox[0].focus();
  7444. urlBox[0].select();
  7445. }
  7446. return dialog;
  7447. };
  7448. self.plugin.image = {
  7449. edit : function() {
  7450. var img = self.plugin.getSelectedImage();
  7451. self.plugin.imageDialog({
  7452. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7453. imageWidth : img ? img.width() : '',
  7454. imageHeight : img ? img.height() : '',
  7455. imageTitle : img ? img.attr('title') : '',
  7456. imageAlign : img ? img.attr('align') : '',
  7457. showRemote : allowImageRemote,
  7458. showLocal : allowImageUpload,
  7459. tabIndex: img ? 0 : imageTabIndex,
  7460. clickFn : function(url, title, width, height, border, align) {
  7461. if (img) {
  7462. img.attr('src', url);
  7463. img.attr('data-ke-src', url);
  7464. img.attr('width', width);
  7465. img.attr('height', height);
  7466. img.attr('title', title);
  7467. img.attr('align', align);
  7468. img.attr('alt', title);
  7469. } else {
  7470. self.exec('insertimage', url, title, width, height, border, align);
  7471. }
  7472. setTimeout(function() {
  7473. self.hideDialog().focus();
  7474. }, 0);
  7475. }
  7476. });
  7477. },
  7478. 'delete' : function() {
  7479. var target = self.plugin.getSelectedImage();
  7480. if (target.parent().name == 'a') {
  7481. target = target.parent();
  7482. }
  7483. target.remove();
  7484. self.addBookmark();
  7485. }
  7486. };
  7487. self.clickToolbar(name, self.plugin.image.edit);
  7488. });
  7489. /*******************************************************************************
  7490. * KindEditor - WYSIWYG HTML Editor for Internet
  7491. * Copyright (C) 2006-2011 kindsoft.net
  7492. *
  7493. * @author Roddy <luolonghao@gmail.com>
  7494. * @site http://www.kindsoft.net/
  7495. * @licence http://www.kindsoft.net/license.php
  7496. *******************************************************************************/
  7497. KindEditor.plugin('insertfile', function(K) {
  7498. var self = this, name = 'insertfile',
  7499. allowFileUpload = K.undef(self.allowFileUpload, true),
  7500. allowFileManager = K.undef(self.allowFileManager, false),
  7501. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7502. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7503. extraParams = K.undef(self.extraFileUploadParams, {}),
  7504. filePostName = K.undef(self.filePostName, 'imgFile'),
  7505. lang = self.lang(name + '.');
  7506. self.plugin.fileDialog = function(options) {
  7507. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7508. fileTitle = K.undef(options.fileTitle, ''),
  7509. clickFn = options.clickFn;
  7510. var html = [
  7511. '<div style="padding:20px;">',
  7512. '<div class="ke-dialog-row">',
  7513. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7514. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7515. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7516. '<span class="ke-button-common ke-button-outer">',
  7517. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7518. '</span>',
  7519. '</div>',
  7520. '<div class="ke-dialog-row">',
  7521. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7522. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7523. '</div>',
  7524. '</form>',
  7525. '</div>'
  7526. ].join('');
  7527. var dialog = self.createDialog({
  7528. name : name,
  7529. width : 450,
  7530. title : self.lang(name),
  7531. body : html,
  7532. yesBtn : {
  7533. name : self.lang('yes'),
  7534. click : function(e) {
  7535. var url = K.trim(urlBox.val()),
  7536. title = titleBox.val();
  7537. if (url == 'http://' || K.invalidUrl(url)) {
  7538. alert(self.lang('invalidUrl'));
  7539. urlBox[0].focus();
  7540. return;
  7541. }
  7542. if (K.trim(title) === '') {
  7543. title = url;
  7544. }
  7545. clickFn.call(self, url, title);
  7546. }
  7547. }
  7548. }),
  7549. div = dialog.div;
  7550. var urlBox = K('[name="url"]', div),
  7551. viewServerBtn = K('[name="viewServer"]', div),
  7552. titleBox = K('[name="title"]', div);
  7553. if (allowFileUpload) {
  7554. var uploadbutton = K.uploadbutton({
  7555. button : K('.ke-upload-button', div)[0],
  7556. fieldName : filePostName,
  7557. url : K.addParam(uploadJson, 'dir=file'),
  7558. extraParams : extraParams,
  7559. afterUpload : function(data) {
  7560. dialog.hideLoading();
  7561. if (data.error === 0) {
  7562. var url = data.url;
  7563. if (formatUploadUrl) {
  7564. url = K.formatUrl(url, 'absolute');
  7565. }
  7566. urlBox.val(url);
  7567. if (self.afterUpload) {
  7568. self.afterUpload.call(self, url, data, name);
  7569. }
  7570. alert(self.lang('uploadSuccess'));
  7571. } else {
  7572. alert(data.message);
  7573. }
  7574. },
  7575. afterError : function(html) {
  7576. dialog.hideLoading();
  7577. self.errorDialog(html);
  7578. }
  7579. });
  7580. uploadbutton.fileBox.change(function(e) {
  7581. dialog.showLoading(self.lang('uploadLoading'));
  7582. uploadbutton.submit();
  7583. });
  7584. } else {
  7585. K('.ke-upload-button', div).hide();
  7586. }
  7587. if (allowFileManager) {
  7588. viewServerBtn.click(function(e) {
  7589. self.loadPlugin('filemanager', function() {
  7590. self.plugin.filemanagerDialog({
  7591. viewType : 'LIST',
  7592. dirName : 'file',
  7593. clickFn : function(url, title) {
  7594. if (self.dialogs.length > 1) {
  7595. K('[name="url"]', div).val(url);
  7596. if (self.afterSelectFile) {
  7597. self.afterSelectFile.call(self, url);
  7598. }
  7599. self.hideDialog();
  7600. }
  7601. }
  7602. });
  7603. });
  7604. });
  7605. } else {
  7606. viewServerBtn.hide();
  7607. }
  7608. urlBox.val(fileUrl);
  7609. titleBox.val(fileTitle);
  7610. urlBox[0].focus();
  7611. urlBox[0].select();
  7612. };
  7613. self.clickToolbar(name, function() {
  7614. self.plugin.fileDialog({
  7615. clickFn : function(url, title) {
  7616. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7617. self.insertHtml(html).hideDialog().focus();
  7618. }
  7619. });
  7620. });
  7621. });
  7622. /*******************************************************************************
  7623. * KindEditor - WYSIWYG HTML Editor for Internet
  7624. * Copyright (C) 2006-2011 kindsoft.net
  7625. *
  7626. * @author Roddy <luolonghao@gmail.com>
  7627. * @site http://www.kindsoft.net/
  7628. * @licence http://www.kindsoft.net/license.php
  7629. *******************************************************************************/
  7630. KindEditor.plugin('lineheight', function(K) {
  7631. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7632. self.clickToolbar(name, function() {
  7633. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7634. if (commonNode) {
  7635. curVal = commonNode.css('line-height');
  7636. }
  7637. var menu = self.createMenu({
  7638. name : name,
  7639. width : 150
  7640. });
  7641. K.each(lang.lineHeight, function(i, row) {
  7642. K.each(row, function(key, val) {
  7643. menu.addItem({
  7644. title : val,
  7645. checked : curVal === key,
  7646. click : function() {
  7647. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7648. span : '.line-height=' + key
  7649. });
  7650. self.updateState();
  7651. self.addBookmark();
  7652. self.hideMenu();
  7653. }
  7654. });
  7655. });
  7656. });
  7657. });
  7658. });
  7659. /*******************************************************************************
  7660. * KindEditor - WYSIWYG HTML Editor for Internet
  7661. * Copyright (C) 2006-2011 kindsoft.net
  7662. *
  7663. * @author Roddy <luolonghao@gmail.com>
  7664. * @site http://www.kindsoft.net/
  7665. * @licence http://www.kindsoft.net/license.php
  7666. *******************************************************************************/
  7667. KindEditor.plugin('link', function(K) {
  7668. var self = this, name = 'link';
  7669. self.plugin.link = {
  7670. edit : function() {
  7671. var lang = self.lang(name + '.'),
  7672. html = '<div style="padding:20px;">' +
  7673. '<div class="ke-dialog-row">' +
  7674. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7675. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7676. '<div class="ke-dialog-row"">' +
  7677. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7678. '<select id="keType" name="type"></select>' +
  7679. '</div>' +
  7680. '</div>',
  7681. dialog = self.createDialog({
  7682. name : name,
  7683. width : 450,
  7684. title : self.lang(name),
  7685. body : html,
  7686. yesBtn : {
  7687. name : self.lang('yes'),
  7688. click : function(e) {
  7689. var url = K.trim(urlBox.val());
  7690. if (url == 'http://' || K.invalidUrl(url)) {
  7691. alert(self.lang('invalidUrl'));
  7692. urlBox[0].focus();
  7693. return;
  7694. }
  7695. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7696. }
  7697. }
  7698. }),
  7699. div = dialog.div,
  7700. urlBox = K('input[name="url"]', div),
  7701. typeBox = K('select[name="type"]', div);
  7702. urlBox.val('http://');
  7703. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7704. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7705. self.cmd.selection();
  7706. var a = self.plugin.getSelectedLink();
  7707. if (a) {
  7708. self.cmd.range.selectNode(a[0]);
  7709. self.cmd.select();
  7710. urlBox.val(a.attr('data-ke-src'));
  7711. typeBox.val(a.attr('target'));
  7712. }
  7713. urlBox[0].focus();
  7714. urlBox[0].select();
  7715. },
  7716. 'delete' : function() {
  7717. self.exec('unlink', null);
  7718. }
  7719. };
  7720. self.clickToolbar(name, self.plugin.link.edit);
  7721. });
  7722. /*******************************************************************************
  7723. * KindEditor - WYSIWYG HTML Editor for Internet
  7724. * Copyright (C) 2006-2011 kindsoft.net
  7725. *
  7726. * @author Roddy <luolonghao@gmail.com>
  7727. * @site http://www.kindsoft.net/
  7728. * @licence http://www.kindsoft.net/license.php
  7729. *******************************************************************************/
  7730. KindEditor.plugin('media', function(K) {
  7731. var self = this, name = 'media', lang = self.lang(name + '.'),
  7732. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7733. allowFileManager = K.undef(self.allowFileManager, false),
  7734. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7735. extraParams = K.undef(self.extraFileUploadParams, {}),
  7736. filePostName = K.undef(self.filePostName, 'imgFile'),
  7737. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7738. self.plugin.media = {
  7739. edit : function() {
  7740. var html = [
  7741. '<div style="padding:20px;">',
  7742. '<div class="ke-dialog-row">',
  7743. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7744. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7745. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7746. '<span class="ke-button-common ke-button-outer">',
  7747. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7748. '</span>',
  7749. '</div>',
  7750. '<div class="ke-dialog-row">',
  7751. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7752. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7753. '</div>',
  7754. '<div class="ke-dialog-row">',
  7755. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7756. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7757. '</div>',
  7758. '<div class="ke-dialog-row">',
  7759. '<label for="keAutostart">' + lang.autostart + '</label>',
  7760. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7761. '</div>',
  7762. '</div>'
  7763. ].join('');
  7764. var dialog = self.createDialog({
  7765. name : name,
  7766. width : 450,
  7767. height : 230,
  7768. title : self.lang(name),
  7769. body : html,
  7770. yesBtn : {
  7771. name : self.lang('yes'),
  7772. click : function(e) {
  7773. var url = K.trim(urlBox.val()),
  7774. width = widthBox.val(),
  7775. height = heightBox.val();
  7776. if (url == 'http://' || K.invalidUrl(url)) {
  7777. alert(self.lang('invalidUrl'));
  7778. urlBox[0].focus();
  7779. return;
  7780. }
  7781. if (!/^\d*$/.test(width)) {
  7782. alert(self.lang('invalidWidth'));
  7783. widthBox[0].focus();
  7784. return;
  7785. }
  7786. if (!/^\d*$/.test(height)) {
  7787. alert(self.lang('invalidHeight'));
  7788. heightBox[0].focus();
  7789. return;
  7790. }
  7791. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7792. src : url,
  7793. type : K.mediaType(url),
  7794. width : width,
  7795. height : height,
  7796. autostart : autostartBox[0].checked ? 'true' : 'false',
  7797. loop : 'true'
  7798. });
  7799. self.insertHtml(html).hideDialog().focus();
  7800. }
  7801. }
  7802. }),
  7803. div = dialog.div,
  7804. urlBox = K('[name="url"]', div),
  7805. viewServerBtn = K('[name="viewServer"]', div),
  7806. widthBox = K('[name="width"]', div),
  7807. heightBox = K('[name="height"]', div),
  7808. autostartBox = K('[name="autostart"]', div);
  7809. urlBox.val('http://');
  7810. if (allowMediaUpload) {
  7811. var uploadbutton = K.uploadbutton({
  7812. button : K('.ke-upload-button', div)[0],
  7813. fieldName : filePostName,
  7814. extraParams : extraParams,
  7815. url : K.addParam(uploadJson, 'dir=media'),
  7816. afterUpload : function(data) {
  7817. dialog.hideLoading();
  7818. if (data.error === 0) {
  7819. var url = data.url;
  7820. if (formatUploadUrl) {
  7821. url = K.formatUrl(url, 'absolute');
  7822. }
  7823. urlBox.val(url);
  7824. if (self.afterUpload) {
  7825. self.afterUpload.call(self, url, data, name);
  7826. }
  7827. alert(self.lang('uploadSuccess'));
  7828. } else {
  7829. alert(data.message);
  7830. }
  7831. },
  7832. afterError : function(html) {
  7833. dialog.hideLoading();
  7834. self.errorDialog(html);
  7835. }
  7836. });
  7837. uploadbutton.fileBox.change(function(e) {
  7838. dialog.showLoading(self.lang('uploadLoading'));
  7839. uploadbutton.submit();
  7840. });
  7841. } else {
  7842. K('.ke-upload-button', div).hide();
  7843. }
  7844. if (allowFileManager) {
  7845. viewServerBtn.click(function(e) {
  7846. self.loadPlugin('filemanager', function() {
  7847. self.plugin.filemanagerDialog({
  7848. viewType : 'LIST',
  7849. dirName : 'media',
  7850. clickFn : function(url, title) {
  7851. if (self.dialogs.length > 1) {
  7852. K('[name="url"]', div).val(url);
  7853. if (self.afterSelectFile) {
  7854. self.afterSelectFile.call(self, url);
  7855. }
  7856. self.hideDialog();
  7857. }
  7858. }
  7859. });
  7860. });
  7861. });
  7862. } else {
  7863. viewServerBtn.hide();
  7864. }
  7865. var img = self.plugin.getSelectedMedia();
  7866. if (img) {
  7867. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7868. urlBox.val(attrs.src);
  7869. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7870. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7871. autostartBox[0].checked = (attrs.autostart === 'true');
  7872. }
  7873. urlBox[0].focus();
  7874. urlBox[0].select();
  7875. },
  7876. 'delete' : function() {
  7877. self.plugin.getSelectedMedia().remove();
  7878. self.addBookmark();
  7879. }
  7880. };
  7881. self.clickToolbar(name, self.plugin.media.edit);
  7882. });
  7883. /*******************************************************************************
  7884. * KindEditor - WYSIWYG HTML Editor for Internet
  7885. * Copyright (C) 2006-2011 kindsoft.net
  7886. *
  7887. * @author Roddy <luolonghao@gmail.com>
  7888. * @site http://www.kindsoft.net/
  7889. * @licence http://www.kindsoft.net/license.php
  7890. *******************************************************************************/
  7891. (function(K) {
  7892. function KSWFUpload(options) {
  7893. this.init(options);
  7894. }
  7895. K.extend(KSWFUpload, {
  7896. init : function(options) {
  7897. var self = this;
  7898. options.afterError = options.afterError || function(str) {
  7899. alert(str);
  7900. };
  7901. self.options = options;
  7902. self.progressbars = {};
  7903. self.div = K(options.container).html([
  7904. '<div class="ke-swfupload">',
  7905. '<div class="ke-swfupload-top">',
  7906. '<div class="ke-inline-block ke-swfupload-button">',
  7907. '<input type="button" value="Browse" />',
  7908. '</div>',
  7909. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7910. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7911. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7912. '</span>',
  7913. '</div>',
  7914. '<div class="ke-swfupload-body"></div>',
  7915. '</div>'
  7916. ].join(''));
  7917. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7918. function showError(itemDiv, msg) {
  7919. K('.ke-status > div', itemDiv).hide();
  7920. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7921. }
  7922. var settings = {
  7923. debug : false,
  7924. upload_url : options.uploadUrl,
  7925. flash_url : options.flashUrl,
  7926. file_post_name : options.filePostName,
  7927. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7928. button_image_url: options.buttonImageUrl,
  7929. button_width: options.buttonWidth,
  7930. button_height: options.buttonHeight,
  7931. button_cursor : SWFUpload.CURSOR.HAND,
  7932. file_types : options.fileTypes,
  7933. file_types_description : options.fileTypesDesc,
  7934. file_upload_limit : options.fileUploadLimit,
  7935. file_size_limit : options.fileSizeLimit,
  7936. post_params : options.postParams,
  7937. file_queued_handler : function(file) {
  7938. file.url = self.options.fileIconUrl;
  7939. self.appendFile(file);
  7940. },
  7941. file_queue_error_handler : function(file, errorCode, message) {
  7942. var errorName = '';
  7943. switch (errorCode) {
  7944. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7945. errorName = options.queueLimitExceeded;
  7946. break;
  7947. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7948. errorName = options.fileExceedsSizeLimit;
  7949. break;
  7950. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7951. errorName = options.zeroByteFile;
  7952. break;
  7953. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7954. errorName = options.invalidFiletype;
  7955. break;
  7956. default:
  7957. errorName = options.unknownError;
  7958. break;
  7959. }
  7960. K.DEBUG && alert(errorName);
  7961. },
  7962. upload_start_handler : function(file) {
  7963. var self = this;
  7964. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7965. K('.ke-status > div', itemDiv).hide();
  7966. K('.ke-progressbar', itemDiv).show();
  7967. },
  7968. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7969. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7970. var progressbar = self.progressbars[file.id];
  7971. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7972. progressbar.percent.html(percent + '%');
  7973. },
  7974. upload_error_handler : function(file, errorCode, message) {
  7975. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7976. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7977. showError(itemDiv, self.options.errorMessage);
  7978. }
  7979. },
  7980. upload_success_handler : function(file, serverData) {
  7981. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7982. var data = {};
  7983. try {
  7984. data = K.json(serverData);
  7985. } catch (e) {
  7986. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7987. }
  7988. if (data.error !== 0) {
  7989. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7990. return;
  7991. }
  7992. file.url = data.url;
  7993. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7994. K('.ke-status > div', itemDiv).hide();
  7995. }
  7996. };
  7997. self.swfu = new SWFUpload(settings);
  7998. K('.ke-swfupload-startupload input', self.div).click(function() {
  7999. self.swfu.startUpload();
  8000. });
  8001. },
  8002. getUrlList : function() {
  8003. var list = [];
  8004. K('.ke-img', self.bodyDiv).each(function() {
  8005. var img = K(this);
  8006. var status = img.attr('data-status');
  8007. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8008. list.push(img.data('data'));
  8009. }
  8010. });
  8011. return list;
  8012. },
  8013. removeFile : function(fileId) {
  8014. var self = this;
  8015. self.swfu.cancelUpload(fileId);
  8016. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8017. K('.ke-photo', itemDiv).unbind();
  8018. K('.ke-delete', itemDiv).unbind();
  8019. itemDiv.remove();
  8020. },
  8021. removeFiles : function() {
  8022. var self = this;
  8023. K('.ke-item', self.bodyDiv).each(function() {
  8024. self.removeFile(K(this).attr('data-id'));
  8025. });
  8026. },
  8027. appendFile : function(file) {
  8028. var self = this;
  8029. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8030. self.bodyDiv.append(itemDiv);
  8031. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8032. .mouseover(function(e) {
  8033. K(this).addClass('ke-on');
  8034. })
  8035. .mouseout(function(e) {
  8036. K(this).removeClass('ke-on');
  8037. });
  8038. itemDiv.append(photoDiv);
  8039. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8040. photoDiv.append(img);
  8041. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8042. self.removeFile(file.id);
  8043. });
  8044. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8045. K(['<div class="ke-progressbar">',
  8046. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8047. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8048. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8049. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8050. self.progressbars[file.id] = {
  8051. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8052. percent : K('.ke-progressbar-percent', photoDiv)
  8053. };
  8054. },
  8055. remove : function() {
  8056. this.removeFiles();
  8057. this.swfu.destroy();
  8058. this.div.html('');
  8059. }
  8060. });
  8061. K.swfupload = function(element, options) {
  8062. return new KSWFUpload(element, options);
  8063. };
  8064. })(KindEditor);
  8065. KindEditor.plugin('multiimage', function(K) {
  8066. var self = this, name = 'multiimage',
  8067. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8068. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8069. imgPath = self.pluginsPath + 'multiimage/images/',
  8070. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8071. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8072. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8073. filePostName = K.undef(self.filePostName, 'imgFile'),
  8074. lang = self.lang(name + '.');
  8075. self.plugin.multiImageDialog = function(options) {
  8076. var clickFn = options.clickFn,
  8077. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8078. var html = [
  8079. '<div style="padding:20px;">',
  8080. '<div class="swfupload">',
  8081. '</div>',
  8082. '</div>'
  8083. ].join('');
  8084. var dialog = self.createDialog({
  8085. name : name,
  8086. width : 650,
  8087. height : 510,
  8088. title : self.lang(name),
  8089. body : html,
  8090. previewBtn : {
  8091. name : lang.insertAll,
  8092. click : function(e) {
  8093. clickFn.call(self, swfupload.getUrlList());
  8094. }
  8095. },
  8096. yesBtn : {
  8097. name : lang.clearAll,
  8098. click : function(e) {
  8099. swfupload.removeFiles();
  8100. }
  8101. },
  8102. beforeRemove : function() {
  8103. if (!K.IE || K.V <= 8) {
  8104. swfupload.remove();
  8105. }
  8106. }
  8107. }),
  8108. div = dialog.div;
  8109. var swfupload = K.swfupload({
  8110. container : K('.swfupload', div),
  8111. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8112. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8113. buttonHeight : 23,
  8114. fileIconUrl : imgPath + 'image.png',
  8115. uploadDesc : uploadDesc,
  8116. startButtonValue : lang.startUpload,
  8117. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8118. flashUrl : imgPath + 'swfupload.swf',
  8119. filePostName : filePostName,
  8120. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8121. fileTypesDesc : 'Image Files',
  8122. fileUploadLimit : imageUploadLimit,
  8123. fileSizeLimit : imageSizeLimit,
  8124. postParams : K.undef(self.extraFileUploadParams, {}),
  8125. queueLimitExceeded : lang.queueLimitExceeded,
  8126. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8127. zeroByteFile : lang.zeroByteFile,
  8128. invalidFiletype : lang.invalidFiletype,
  8129. unknownError : lang.unknownError,
  8130. pendingMessage : lang.pending,
  8131. errorMessage : lang.uploadError,
  8132. afterError : function(html) {
  8133. self.errorDialog(html);
  8134. }
  8135. });
  8136. return dialog;
  8137. };
  8138. self.clickToolbar(name, function() {
  8139. self.plugin.multiImageDialog({
  8140. clickFn : function (urlList) {
  8141. if (urlList.length === 0) {
  8142. return;
  8143. }
  8144. K.each(urlList, function(i, data) {
  8145. if (self.afterUpload) {
  8146. self.afterUpload.call(self, data.url, data, 'multiimage');
  8147. }
  8148. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8149. });
  8150. setTimeout(function() {
  8151. self.hideDialog().focus();
  8152. }, 0);
  8153. }
  8154. });
  8155. });
  8156. });
  8157. /* ******************* */
  8158. /* Constructor & Init */
  8159. /* ******************* */
  8160. (function() {
  8161. window.SWFUpload = function (settings) {
  8162. this.initSWFUpload(settings);
  8163. };
  8164. SWFUpload.prototype.initSWFUpload = function (settings) {
  8165. try {
  8166. this.customSettings = {};
  8167. this.settings = settings;
  8168. this.eventQueue = [];
  8169. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8170. this.movieElement = null;
  8171. SWFUpload.instances[this.movieName] = this;
  8172. this.initSettings();
  8173. this.loadFlash();
  8174. this.displayDebugInfo();
  8175. } catch (ex) {
  8176. delete SWFUpload.instances[this.movieName];
  8177. throw ex;
  8178. }
  8179. };
  8180. /* *************** */
  8181. /* Static Members */
  8182. /* *************** */
  8183. SWFUpload.instances = {};
  8184. SWFUpload.movieCount = 0;
  8185. SWFUpload.version = "2.2.0 2009-03-25";
  8186. SWFUpload.QUEUE_ERROR = {
  8187. QUEUE_LIMIT_EXCEEDED : -100,
  8188. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8189. ZERO_BYTE_FILE : -120,
  8190. INVALID_FILETYPE : -130
  8191. };
  8192. SWFUpload.UPLOAD_ERROR = {
  8193. HTTP_ERROR : -200,
  8194. MISSING_UPLOAD_URL : -210,
  8195. IO_ERROR : -220,
  8196. SECURITY_ERROR : -230,
  8197. UPLOAD_LIMIT_EXCEEDED : -240,
  8198. UPLOAD_FAILED : -250,
  8199. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8200. FILE_VALIDATION_FAILED : -270,
  8201. FILE_CANCELLED : -280,
  8202. UPLOAD_STOPPED : -290
  8203. };
  8204. SWFUpload.FILE_STATUS = {
  8205. QUEUED : -1,
  8206. IN_PROGRESS : -2,
  8207. ERROR : -3,
  8208. COMPLETE : -4,
  8209. CANCELLED : -5
  8210. };
  8211. SWFUpload.BUTTON_ACTION = {
  8212. SELECT_FILE : -100,
  8213. SELECT_FILES : -110,
  8214. START_UPLOAD : -120
  8215. };
  8216. SWFUpload.CURSOR = {
  8217. ARROW : -1,
  8218. HAND : -2
  8219. };
  8220. SWFUpload.WINDOW_MODE = {
  8221. WINDOW : "window",
  8222. TRANSPARENT : "transparent",
  8223. OPAQUE : "opaque"
  8224. };
  8225. SWFUpload.completeURL = function(url) {
  8226. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8227. return url;
  8228. }
  8229. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8230. var indexSlash = window.location.pathname.lastIndexOf("/");
  8231. var path;
  8232. if (indexSlash <= 0) {
  8233. path = "/";
  8234. } else {
  8235. path = window.location.pathname.substr(0, indexSlash) + "/";
  8236. }
  8237. return /*currentURL +*/ path + url;
  8238. };
  8239. /* ******************** */
  8240. /* Instance Members */
  8241. /* ******************** */
  8242. SWFUpload.prototype.initSettings = function () {
  8243. this.ensureDefault = function (settingName, defaultValue) {
  8244. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8245. };
  8246. this.ensureDefault("upload_url", "");
  8247. this.ensureDefault("preserve_relative_urls", false);
  8248. this.ensureDefault("file_post_name", "Filedata");
  8249. this.ensureDefault("post_params", {});
  8250. this.ensureDefault("use_query_string", false);
  8251. this.ensureDefault("requeue_on_error", false);
  8252. this.ensureDefault("http_success", []);
  8253. this.ensureDefault("assume_success_timeout", 0);
  8254. this.ensureDefault("file_types", "*.*");
  8255. this.ensureDefault("file_types_description", "All Files");
  8256. this.ensureDefault("file_size_limit", 0);
  8257. this.ensureDefault("file_upload_limit", 0);
  8258. this.ensureDefault("file_queue_limit", 0);
  8259. this.ensureDefault("flash_url", "swfupload.swf");
  8260. this.ensureDefault("prevent_swf_caching", true);
  8261. this.ensureDefault("button_image_url", "");
  8262. this.ensureDefault("button_width", 1);
  8263. this.ensureDefault("button_height", 1);
  8264. this.ensureDefault("button_text", "");
  8265. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8266. this.ensureDefault("button_text_top_padding", 0);
  8267. this.ensureDefault("button_text_left_padding", 0);
  8268. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8269. this.ensureDefault("button_disabled", false);
  8270. this.ensureDefault("button_placeholder_id", "");
  8271. this.ensureDefault("button_placeholder", null);
  8272. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8273. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8274. this.ensureDefault("debug", false);
  8275. this.settings.debug_enabled = this.settings.debug;
  8276. this.settings.return_upload_start_handler = this.returnUploadStart;
  8277. this.ensureDefault("swfupload_loaded_handler", null);
  8278. this.ensureDefault("file_dialog_start_handler", null);
  8279. this.ensureDefault("file_queued_handler", null);
  8280. this.ensureDefault("file_queue_error_handler", null);
  8281. this.ensureDefault("file_dialog_complete_handler", null);
  8282. this.ensureDefault("upload_start_handler", null);
  8283. this.ensureDefault("upload_progress_handler", null);
  8284. this.ensureDefault("upload_error_handler", null);
  8285. this.ensureDefault("upload_success_handler", null);
  8286. this.ensureDefault("upload_complete_handler", null);
  8287. this.ensureDefault("debug_handler", this.debugMessage);
  8288. this.ensureDefault("custom_settings", {});
  8289. this.customSettings = this.settings.custom_settings;
  8290. if (!!this.settings.prevent_swf_caching) {
  8291. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8292. }
  8293. if (!this.settings.preserve_relative_urls) {
  8294. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8295. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8296. }
  8297. delete this.ensureDefault;
  8298. };
  8299. SWFUpload.prototype.loadFlash = function () {
  8300. var targetElement, tempParent;
  8301. if (document.getElementById(this.movieName) !== null) {
  8302. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8303. }
  8304. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8305. if (targetElement == undefined) {
  8306. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8307. }
  8308. tempParent = document.createElement("div");
  8309. tempParent.innerHTML = this.getFlashHTML();
  8310. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8311. if (window[this.movieName] == undefined) {
  8312. window[this.movieName] = this.getMovieElement();
  8313. }
  8314. };
  8315. SWFUpload.prototype.getFlashHTML = function () {
  8316. var classid = '';
  8317. if (KindEditor.IE && KindEditor.V > 8) {
  8318. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8319. }
  8320. 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">',
  8321. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8322. '<param name="movie" value="', this.settings.flash_url, '" />',
  8323. '<param name="quality" value="high" />',
  8324. '<param name="menu" value="false" />',
  8325. '<param name="allowScriptAccess" value="always" />',
  8326. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8327. '</object>'].join("");
  8328. };
  8329. SWFUpload.prototype.getFlashVars = function () {
  8330. var paramString = this.buildParamString();
  8331. var httpSuccessString = this.settings.http_success.join(",");
  8332. return ["movieName=", encodeURIComponent(this.movieName),
  8333. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8334. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8335. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8336. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8337. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8338. "&amp;params=", encodeURIComponent(paramString),
  8339. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8340. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8341. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8342. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8343. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8344. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8345. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8346. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8347. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8348. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8349. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8350. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8351. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8352. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8353. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8354. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8355. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8356. ].join("");
  8357. };
  8358. SWFUpload.prototype.getMovieElement = function () {
  8359. if (this.movieElement == undefined) {
  8360. this.movieElement = document.getElementById(this.movieName);
  8361. }
  8362. if (this.movieElement === null) {
  8363. throw "Could not find Flash element";
  8364. }
  8365. return this.movieElement;
  8366. };
  8367. SWFUpload.prototype.buildParamString = function () {
  8368. var postParams = this.settings.post_params;
  8369. var paramStringPairs = [];
  8370. if (typeof(postParams) === "object") {
  8371. for (var name in postParams) {
  8372. if (postParams.hasOwnProperty(name)) {
  8373. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8374. }
  8375. }
  8376. }
  8377. return paramStringPairs.join("&amp;");
  8378. };
  8379. SWFUpload.prototype.destroy = function () {
  8380. try {
  8381. this.cancelUpload(null, false);
  8382. var movieElement = null;
  8383. movieElement = this.getMovieElement();
  8384. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8385. for (var i in movieElement) {
  8386. try {
  8387. if (typeof(movieElement[i]) === "function") {
  8388. movieElement[i] = null;
  8389. }
  8390. } catch (ex1) {}
  8391. }
  8392. try {
  8393. movieElement.parentNode.removeChild(movieElement);
  8394. } catch (ex) {}
  8395. }
  8396. window[this.movieName] = null;
  8397. SWFUpload.instances[this.movieName] = null;
  8398. delete SWFUpload.instances[this.movieName];
  8399. this.movieElement = null;
  8400. this.settings = null;
  8401. this.customSettings = null;
  8402. this.eventQueue = null;
  8403. this.movieName = null;
  8404. return true;
  8405. } catch (ex2) {
  8406. return false;
  8407. }
  8408. };
  8409. SWFUpload.prototype.displayDebugInfo = function () {
  8410. this.debug(
  8411. [
  8412. "---SWFUpload Instance Info---\n",
  8413. "Version: ", SWFUpload.version, "\n",
  8414. "Movie Name: ", this.movieName, "\n",
  8415. "Settings:\n",
  8416. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8417. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8418. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8419. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8420. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8421. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8422. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8423. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8424. "\t", "file_types: ", this.settings.file_types, "\n",
  8425. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8426. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8427. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8428. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8429. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8430. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8431. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8432. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8433. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8434. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8435. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8436. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8437. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8438. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8439. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8440. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8441. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8442. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8443. "Event Handlers:\n",
  8444. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8445. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8446. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8447. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8448. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8449. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8450. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8451. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8452. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8453. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8454. ].join("")
  8455. );
  8456. };
  8457. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8458. the maintain v2 API compatibility
  8459. */
  8460. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8461. if (value == undefined) {
  8462. return (this.settings[name] = default_value);
  8463. } else {
  8464. return (this.settings[name] = value);
  8465. }
  8466. };
  8467. SWFUpload.prototype.getSetting = function (name) {
  8468. if (this.settings[name] != undefined) {
  8469. return this.settings[name];
  8470. }
  8471. return "";
  8472. };
  8473. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8474. argumentArray = argumentArray || [];
  8475. var movieElement = this.getMovieElement();
  8476. var returnValue, returnString;
  8477. try {
  8478. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8479. returnValue = eval(returnString);
  8480. } catch (ex) {
  8481. throw "Call to " + functionName + " failed";
  8482. }
  8483. if (returnValue != undefined && typeof returnValue.post === "object") {
  8484. returnValue = this.unescapeFilePostParams(returnValue);
  8485. }
  8486. return returnValue;
  8487. };
  8488. /* *****************************
  8489. -- Flash control methods --
  8490. Your UI should use these
  8491. to operate SWFUpload
  8492. ***************************** */
  8493. SWFUpload.prototype.selectFile = function () {
  8494. this.callFlash("SelectFile");
  8495. };
  8496. SWFUpload.prototype.selectFiles = function () {
  8497. this.callFlash("SelectFiles");
  8498. };
  8499. SWFUpload.prototype.startUpload = function (fileID) {
  8500. this.callFlash("StartUpload", [fileID]);
  8501. };
  8502. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8503. if (triggerErrorEvent !== false) {
  8504. triggerErrorEvent = true;
  8505. }
  8506. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8507. };
  8508. SWFUpload.prototype.stopUpload = function () {
  8509. this.callFlash("StopUpload");
  8510. };
  8511. /* ************************
  8512. * Settings methods
  8513. * These methods change the SWFUpload settings.
  8514. * SWFUpload settings should not be changed directly on the settings object
  8515. * since many of the settings need to be passed to Flash in order to take
  8516. * effect.
  8517. * *********************** */
  8518. SWFUpload.prototype.getStats = function () {
  8519. return this.callFlash("GetStats");
  8520. };
  8521. SWFUpload.prototype.setStats = function (statsObject) {
  8522. this.callFlash("SetStats", [statsObject]);
  8523. };
  8524. SWFUpload.prototype.getFile = function (fileID) {
  8525. if (typeof(fileID) === "number") {
  8526. return this.callFlash("GetFileByIndex", [fileID]);
  8527. } else {
  8528. return this.callFlash("GetFile", [fileID]);
  8529. }
  8530. };
  8531. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8532. return this.callFlash("AddFileParam", [fileID, name, value]);
  8533. };
  8534. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8535. this.callFlash("RemoveFileParam", [fileID, name]);
  8536. };
  8537. SWFUpload.prototype.setUploadURL = function (url) {
  8538. this.settings.upload_url = url.toString();
  8539. this.callFlash("SetUploadURL", [url]);
  8540. };
  8541. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8542. this.settings.post_params = paramsObject;
  8543. this.callFlash("SetPostParams", [paramsObject]);
  8544. };
  8545. SWFUpload.prototype.addPostParam = function (name, value) {
  8546. this.settings.post_params[name] = value;
  8547. this.callFlash("SetPostParams", [this.settings.post_params]);
  8548. };
  8549. SWFUpload.prototype.removePostParam = function (name) {
  8550. delete this.settings.post_params[name];
  8551. this.callFlash("SetPostParams", [this.settings.post_params]);
  8552. };
  8553. SWFUpload.prototype.setFileTypes = function (types, description) {
  8554. this.settings.file_types = types;
  8555. this.settings.file_types_description = description;
  8556. this.callFlash("SetFileTypes", [types, description]);
  8557. };
  8558. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8559. this.settings.file_size_limit = fileSizeLimit;
  8560. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8561. };
  8562. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8563. this.settings.file_upload_limit = fileUploadLimit;
  8564. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8565. };
  8566. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8567. this.settings.file_queue_limit = fileQueueLimit;
  8568. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8569. };
  8570. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8571. this.settings.file_post_name = filePostName;
  8572. this.callFlash("SetFilePostName", [filePostName]);
  8573. };
  8574. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8575. this.settings.use_query_string = useQueryString;
  8576. this.callFlash("SetUseQueryString", [useQueryString]);
  8577. };
  8578. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8579. this.settings.requeue_on_error = requeueOnError;
  8580. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8581. };
  8582. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8583. if (typeof http_status_codes === "string") {
  8584. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8585. }
  8586. this.settings.http_success = http_status_codes;
  8587. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8588. };
  8589. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8590. this.settings.assume_success_timeout = timeout_seconds;
  8591. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8592. };
  8593. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8594. this.settings.debug_enabled = debugEnabled;
  8595. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8596. };
  8597. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8598. if (buttonImageURL == undefined) {
  8599. buttonImageURL = "";
  8600. }
  8601. this.settings.button_image_url = buttonImageURL;
  8602. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8603. };
  8604. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8605. this.settings.button_width = width;
  8606. this.settings.button_height = height;
  8607. var movie = this.getMovieElement();
  8608. if (movie != undefined) {
  8609. movie.style.width = width + "px";
  8610. movie.style.height = height + "px";
  8611. }
  8612. this.callFlash("SetButtonDimensions", [width, height]);
  8613. };
  8614. SWFUpload.prototype.setButtonText = function (html) {
  8615. this.settings.button_text = html;
  8616. this.callFlash("SetButtonText", [html]);
  8617. };
  8618. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8619. this.settings.button_text_top_padding = top;
  8620. this.settings.button_text_left_padding = left;
  8621. this.callFlash("SetButtonTextPadding", [left, top]);
  8622. };
  8623. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8624. this.settings.button_text_style = css;
  8625. this.callFlash("SetButtonTextStyle", [css]);
  8626. };
  8627. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8628. this.settings.button_disabled = isDisabled;
  8629. this.callFlash("SetButtonDisabled", [isDisabled]);
  8630. };
  8631. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8632. this.settings.button_action = buttonAction;
  8633. this.callFlash("SetButtonAction", [buttonAction]);
  8634. };
  8635. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8636. this.settings.button_cursor = cursor;
  8637. this.callFlash("SetButtonCursor", [cursor]);
  8638. };
  8639. /* *******************************
  8640. Flash Event Interfaces
  8641. These functions are used by Flash to trigger the various
  8642. events.
  8643. All these functions a Private.
  8644. Because the ExternalInterface library is buggy the event calls
  8645. are added to a queue and the queue then executed by a setTimeout.
  8646. This ensures that events are executed in a determinate order and that
  8647. the ExternalInterface bugs are avoided.
  8648. ******************************* */
  8649. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8650. if (argumentArray == undefined) {
  8651. argumentArray = [];
  8652. } else if (!(argumentArray instanceof Array)) {
  8653. argumentArray = [argumentArray];
  8654. }
  8655. var self = this;
  8656. if (typeof this.settings[handlerName] === "function") {
  8657. this.eventQueue.push(function () {
  8658. this.settings[handlerName].apply(this, argumentArray);
  8659. });
  8660. setTimeout(function () {
  8661. self.executeNextEvent();
  8662. }, 0);
  8663. } else if (this.settings[handlerName] !== null) {
  8664. throw "Event handler " + handlerName + " is unknown or is not a function";
  8665. }
  8666. };
  8667. SWFUpload.prototype.executeNextEvent = function () {
  8668. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8669. if (typeof(f) === "function") {
  8670. f.apply(this);
  8671. }
  8672. };
  8673. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8674. var reg = /[$]([0-9a-f]{4})/i;
  8675. var unescapedPost = {};
  8676. var uk;
  8677. if (file != undefined) {
  8678. for (var k in file.post) {
  8679. if (file.post.hasOwnProperty(k)) {
  8680. uk = k;
  8681. var match;
  8682. while ((match = reg.exec(uk)) !== null) {
  8683. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8684. }
  8685. unescapedPost[uk] = file.post[k];
  8686. }
  8687. }
  8688. file.post = unescapedPost;
  8689. }
  8690. return file;
  8691. };
  8692. SWFUpload.prototype.testExternalInterface = function () {
  8693. try {
  8694. return this.callFlash("TestExternalInterface");
  8695. } catch (ex) {
  8696. return false;
  8697. }
  8698. };
  8699. SWFUpload.prototype.flashReady = function () {
  8700. var movieElement = this.getMovieElement();
  8701. if (!movieElement) {
  8702. this.debug("Flash called back ready but the flash movie can't be found.");
  8703. return;
  8704. }
  8705. this.cleanUp(movieElement);
  8706. this.queueEvent("swfupload_loaded_handler");
  8707. };
  8708. SWFUpload.prototype.cleanUp = function (movieElement) {
  8709. try {
  8710. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8711. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8712. for (var key in movieElement) {
  8713. try {
  8714. if (typeof(movieElement[key]) === "function") {
  8715. movieElement[key] = null;
  8716. }
  8717. } catch (ex) {
  8718. }
  8719. }
  8720. }
  8721. } catch (ex1) {
  8722. }
  8723. window["__flash__removeCallback"] = function (instance, name) {
  8724. try {
  8725. if (instance) {
  8726. instance[name] = null;
  8727. }
  8728. } catch (flashEx) {
  8729. }
  8730. };
  8731. };
  8732. /* This is a chance to do something before the browse window opens */
  8733. SWFUpload.prototype.fileDialogStart = function () {
  8734. this.queueEvent("file_dialog_start_handler");
  8735. };
  8736. /* Called when a file is successfully added to the queue. */
  8737. SWFUpload.prototype.fileQueued = function (file) {
  8738. file = this.unescapeFilePostParams(file);
  8739. this.queueEvent("file_queued_handler", file);
  8740. };
  8741. /* Handle errors that occur when an attempt to queue a file fails. */
  8742. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8743. file = this.unescapeFilePostParams(file);
  8744. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8745. };
  8746. /* Called after the file dialog has closed and the selected files have been queued.
  8747. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8748. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8749. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8750. };
  8751. SWFUpload.prototype.uploadStart = function (file) {
  8752. file = this.unescapeFilePostParams(file);
  8753. this.queueEvent("return_upload_start_handler", file);
  8754. };
  8755. SWFUpload.prototype.returnUploadStart = function (file) {
  8756. var returnValue;
  8757. if (typeof this.settings.upload_start_handler === "function") {
  8758. file = this.unescapeFilePostParams(file);
  8759. returnValue = this.settings.upload_start_handler.call(this, file);
  8760. } else if (this.settings.upload_start_handler != undefined) {
  8761. throw "upload_start_handler must be a function";
  8762. }
  8763. if (returnValue === undefined) {
  8764. returnValue = true;
  8765. }
  8766. returnValue = !!returnValue;
  8767. this.callFlash("ReturnUploadStart", [returnValue]);
  8768. };
  8769. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8770. file = this.unescapeFilePostParams(file);
  8771. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8772. };
  8773. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8774. file = this.unescapeFilePostParams(file);
  8775. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8776. };
  8777. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8778. file = this.unescapeFilePostParams(file);
  8779. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8780. };
  8781. SWFUpload.prototype.uploadComplete = function (file) {
  8782. file = this.unescapeFilePostParams(file);
  8783. this.queueEvent("upload_complete_handler", file);
  8784. };
  8785. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8786. internal debug console. You can override this event and have messages written where you want. */
  8787. SWFUpload.prototype.debug = function (message) {
  8788. this.queueEvent("debug_handler", message);
  8789. };
  8790. /* **********************************
  8791. Debug Console
  8792. The debug console is a self contained, in page location
  8793. for debug message to be sent. The Debug Console adds
  8794. itself to the body if necessary.
  8795. The console is automatically scrolled as messages appear.
  8796. If you are using your own debug handler or when you deploy to production and
  8797. have debug disabled you can remove these functions to reduce the file size
  8798. and complexity.
  8799. ********************************** */
  8800. SWFUpload.prototype.debugMessage = function (message) {
  8801. if (this.settings.debug) {
  8802. var exceptionMessage, exceptionValues = [];
  8803. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8804. for (var key in message) {
  8805. if (message.hasOwnProperty(key)) {
  8806. exceptionValues.push(key + ": " + message[key]);
  8807. }
  8808. }
  8809. exceptionMessage = exceptionValues.join("\n") || "";
  8810. exceptionValues = exceptionMessage.split("\n");
  8811. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8812. SWFUpload.Console.writeLine(exceptionMessage);
  8813. } else {
  8814. SWFUpload.Console.writeLine(message);
  8815. }
  8816. }
  8817. };
  8818. SWFUpload.Console = {};
  8819. SWFUpload.Console.writeLine = function (message) {
  8820. var console, documentForm;
  8821. try {
  8822. console = document.getElementById("SWFUpload_Console");
  8823. if (!console) {
  8824. documentForm = document.createElement("form");
  8825. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8826. console = document.createElement("textarea");
  8827. console.id = "SWFUpload_Console";
  8828. console.style.fontFamily = "monospace";
  8829. console.setAttribute("wrap", "off");
  8830. console.wrap = "off";
  8831. console.style.overflow = "auto";
  8832. console.style.width = "700px";
  8833. console.style.height = "350px";
  8834. console.style.margin = "5px";
  8835. documentForm.appendChild(console);
  8836. }
  8837. console.value += message + "\n";
  8838. console.scrollTop = console.scrollHeight - console.clientHeight;
  8839. } catch (ex) {
  8840. alert("Exception: " + ex.name + " Message: " + ex.message);
  8841. }
  8842. };
  8843. })();
  8844. (function() {
  8845. /*
  8846. Queue Plug-in
  8847. Features:
  8848. *Adds a cancelQueue() method for cancelling the entire queue.
  8849. *All queued files are uploaded when startUpload() is called.
  8850. *If false is returned from uploadComplete then the queue upload is stopped.
  8851. If false is not returned (strict comparison) then the queue upload is continued.
  8852. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8853. Set the event handler with the queue_complete_handler setting.
  8854. */
  8855. if (typeof(SWFUpload) === "function") {
  8856. SWFUpload.queue = {};
  8857. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8858. return function () {
  8859. if (typeof(oldInitSettings) === "function") {
  8860. oldInitSettings.call(this);
  8861. }
  8862. this.queueSettings = {};
  8863. this.queueSettings.queue_cancelled_flag = false;
  8864. this.queueSettings.queue_upload_count = 0;
  8865. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8866. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8867. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8868. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8869. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8870. };
  8871. })(SWFUpload.prototype.initSettings);
  8872. SWFUpload.prototype.startUpload = function (fileID) {
  8873. this.queueSettings.queue_cancelled_flag = false;
  8874. this.callFlash("StartUpload", [fileID]);
  8875. };
  8876. SWFUpload.prototype.cancelQueue = function () {
  8877. this.queueSettings.queue_cancelled_flag = true;
  8878. this.stopUpload();
  8879. var stats = this.getStats();
  8880. while (stats.files_queued > 0) {
  8881. this.cancelUpload();
  8882. stats = this.getStats();
  8883. }
  8884. };
  8885. SWFUpload.queue.uploadStartHandler = function (file) {
  8886. var returnValue;
  8887. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8888. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8889. }
  8890. returnValue = (returnValue === false) ? false : true;
  8891. this.queueSettings.queue_cancelled_flag = !returnValue;
  8892. return returnValue;
  8893. };
  8894. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8895. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8896. var continueUpload;
  8897. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8898. this.queueSettings.queue_upload_count++;
  8899. }
  8900. if (typeof(user_upload_complete_handler) === "function") {
  8901. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8902. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8903. continueUpload = false;
  8904. } else {
  8905. continueUpload = true;
  8906. }
  8907. if (continueUpload) {
  8908. var stats = this.getStats();
  8909. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8910. this.startUpload();
  8911. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8912. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8913. this.queueSettings.queue_upload_count = 0;
  8914. } else {
  8915. this.queueSettings.queue_cancelled_flag = false;
  8916. this.queueSettings.queue_upload_count = 0;
  8917. }
  8918. }
  8919. };
  8920. }
  8921. })();
  8922. /*******************************************************************************
  8923. * KindEditor - WYSIWYG HTML Editor for Internet
  8924. * Copyright (C) 2006-2011 kindsoft.net
  8925. *
  8926. * @author Roddy <luolonghao@gmail.com>
  8927. * @site http://www.kindsoft.net/
  8928. * @licence http://www.kindsoft.net/license.php
  8929. *******************************************************************************/
  8930. KindEditor.plugin('pagebreak', function(K) {
  8931. var self = this;
  8932. var name = 'pagebreak';
  8933. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8934. self.clickToolbar(name, function() {
  8935. var cmd = self.cmd, range = cmd.range;
  8936. self.focus();
  8937. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8938. self.insertHtml(pagebreakHtml + tail);
  8939. if (tail !== '') {
  8940. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8941. range.selectNodeContents(p[0]);
  8942. p.removeAttr('id');
  8943. cmd.select();
  8944. }
  8945. });
  8946. });
  8947. /*******************************************************************************
  8948. * KindEditor - WYSIWYG HTML Editor for Internet
  8949. * Copyright (C) 2006-2011 kindsoft.net
  8950. *
  8951. * @author Roddy <luolonghao@gmail.com>
  8952. * @site http://www.kindsoft.net/
  8953. * @licence http://www.kindsoft.net/license.php
  8954. *******************************************************************************/
  8955. KindEditor.plugin('plainpaste', function(K) {
  8956. var self = this, name = 'plainpaste';
  8957. self.clickToolbar(name, function() {
  8958. var lang = self.lang(name + '.'),
  8959. html = '<div style="padding:10px 20px;">' +
  8960. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  8961. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  8962. '</div>',
  8963. dialog = self.createDialog({
  8964. name : name,
  8965. width : 450,
  8966. title : self.lang(name),
  8967. body : html,
  8968. yesBtn : {
  8969. name : self.lang('yes'),
  8970. click : function(e) {
  8971. var html = textarea.val();
  8972. html = K.escape(html);
  8973. html = html.replace(/ {2}/g, ' &nbsp;');
  8974. if (self.newlineTag == 'p') {
  8975. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  8976. } else {
  8977. html = html.replace(/\n/g, '<br />$&');
  8978. }
  8979. self.insertHtml(html).hideDialog().focus();
  8980. }
  8981. }
  8982. }),
  8983. textarea = K('textarea', dialog.div);
  8984. textarea[0].focus();
  8985. });
  8986. });
  8987. /*******************************************************************************
  8988. * KindEditor - WYSIWYG HTML Editor for Internet
  8989. * Copyright (C) 2006-2011 kindsoft.net
  8990. *
  8991. * @author Roddy <luolonghao@gmail.com>
  8992. * @site http://www.kindsoft.net/
  8993. * @licence http://www.kindsoft.net/license.php
  8994. *******************************************************************************/
  8995. KindEditor.plugin('preview', function(K) {
  8996. var self = this, name = 'preview', undefined;
  8997. self.clickToolbar(name, function() {
  8998. var lang = self.lang(name + '.'),
  8999. html = '<div style="padding:10px 20px;">' +
  9000. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9001. '</div>',
  9002. dialog = self.createDialog({
  9003. name : name,
  9004. width : 750,
  9005. title : self.lang(name),
  9006. body : html
  9007. }),
  9008. iframe = K('iframe', dialog.div),
  9009. doc = K.iframeDoc(iframe);
  9010. doc.open();
  9011. doc.write(self.fullHtml());
  9012. doc.close();
  9013. K(doc.body).css('background-color', '#FFF');
  9014. iframe[0].contentWindow.focus();
  9015. });
  9016. });
  9017. /*******************************************************************************
  9018. * KindEditor - WYSIWYG HTML Editor for Internet
  9019. * Copyright (C) 2006-2011 kindsoft.net
  9020. *
  9021. * @author Roddy <luolonghao@gmail.com>
  9022. * @site http://www.kindsoft.net/
  9023. * @licence http://www.kindsoft.net/license.php
  9024. *******************************************************************************/
  9025. KindEditor.plugin('quickformat', function(K) {
  9026. var self = this, name = 'quickformat',
  9027. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9028. function getFirstChild(knode) {
  9029. var child = knode.first();
  9030. while (child && child.first()) {
  9031. child = child.first();
  9032. }
  9033. return child;
  9034. }
  9035. self.clickToolbar(name, function() {
  9036. self.focus();
  9037. var doc = self.edit.doc,
  9038. range = self.cmd.range,
  9039. child = K(doc.body).first(), next,
  9040. nodeList = [], subList = [],
  9041. bookmark = range.createBookmark(true);
  9042. while(child) {
  9043. next = child.next();
  9044. var firstChild = getFirstChild(child);
  9045. if (!firstChild || firstChild.name != 'img') {
  9046. if (blockMap[child.name]) {
  9047. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9048. child.css('text-indent', '2em');
  9049. } else {
  9050. subList.push(child);
  9051. }
  9052. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9053. if (subList.length > 0) {
  9054. nodeList.push(subList);
  9055. }
  9056. subList = [];
  9057. }
  9058. }
  9059. child = next;
  9060. }
  9061. K.each(nodeList, function(i, subList) {
  9062. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9063. subList[0].before(wrapper);
  9064. K.each(subList, function(i, knode) {
  9065. wrapper.append(knode);
  9066. });
  9067. });
  9068. range.moveToBookmark(bookmark);
  9069. self.addBookmark();
  9070. });
  9071. });
  9072. /*******************************************************************************
  9073. * KindEditor - WYSIWYG HTML Editor for Internet
  9074. * Copyright (C) 2006-2011 kindsoft.net
  9075. *
  9076. * @author Roddy <luolonghao@gmail.com>
  9077. * @site http://www.kindsoft.net/
  9078. * @licence http://www.kindsoft.net/license.php
  9079. *******************************************************************************/
  9080. KindEditor.plugin('table', function(K) {
  9081. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9082. function _setColor(box, color) {
  9083. color = color.toUpperCase();
  9084. box.css('background-color', color);
  9085. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9086. box.html(color);
  9087. }
  9088. var pickerList = [];
  9089. function _initColorPicker(dialogDiv, colorBox) {
  9090. colorBox.bind('click,mousedown', function(e){
  9091. e.stopPropagation();
  9092. });
  9093. function removePicker() {
  9094. K.each(pickerList, function() {
  9095. this.remove();
  9096. });
  9097. pickerList = [];
  9098. K(document).unbind('click,mousedown', removePicker);
  9099. dialogDiv.unbind('click,mousedown', removePicker);
  9100. }
  9101. colorBox.click(function(e) {
  9102. removePicker();
  9103. var box = K(this),
  9104. pos = box.pos();
  9105. var picker = K.colorpicker({
  9106. x : pos.x,
  9107. y : pos.y + box.height(),
  9108. z : 811214,
  9109. selectedColor : K(this).html(),
  9110. colors : self.colorTable,
  9111. noColor : self.lang('noColor'),
  9112. shadowMode : self.shadowMode,
  9113. click : function(color) {
  9114. _setColor(box, color);
  9115. removePicker();
  9116. }
  9117. });
  9118. pickerList.push(picker);
  9119. K(document).bind('click,mousedown', removePicker);
  9120. dialogDiv.bind('click,mousedown', removePicker);
  9121. });
  9122. }
  9123. function _getCellIndex(table, row, cell) {
  9124. var rowSpanCount = 0;
  9125. for (var i = 0, len = row.cells.length; i < len; i++) {
  9126. if (row.cells[i] == cell) {
  9127. break;
  9128. }
  9129. rowSpanCount += row.cells[i].rowSpan - 1;
  9130. }
  9131. return cell.cellIndex - rowSpanCount;
  9132. }
  9133. self.plugin.table = {
  9134. prop : function(isInsert) {
  9135. var html = [
  9136. '<div style="padding:20px;">',
  9137. '<div class="ke-dialog-row">',
  9138. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9139. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9140. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9141. '</div>',
  9142. '<div class="ke-dialog-row">',
  9143. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9144. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9145. '<select name="widthType">',
  9146. '<option value="%">' + lang.percent + '</option>',
  9147. '<option value="px">' + lang.px + '</option>',
  9148. '</select> &nbsp; ',
  9149. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9150. '<select name="heightType">',
  9151. '<option value="%">' + lang.percent + '</option>',
  9152. '<option value="px">' + lang.px + '</option>',
  9153. '</select>',
  9154. '</div>',
  9155. '<div class="ke-dialog-row">',
  9156. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9157. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9158. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9159. '</div>',
  9160. '<div class="ke-dialog-row">',
  9161. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9162. '<select id="keAlign" name="align">',
  9163. '<option value="">' + lang.alignDefault + '</option>',
  9164. '<option value="left">' + lang.alignLeft + '</option>',
  9165. '<option value="center">' + lang.alignCenter + '</option>',
  9166. '<option value="right">' + lang.alignRight + '</option>',
  9167. '</select>',
  9168. '</div>',
  9169. '<div class="ke-dialog-row">',
  9170. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9171. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9172. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9173. '</div>',
  9174. '<div class="ke-dialog-row">',
  9175. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9176. '<span class="ke-inline-block ke-input-color"></span>',
  9177. '</div>',
  9178. '</div>'
  9179. ].join('');
  9180. var bookmark = self.cmd.range.createBookmark();
  9181. var dialog = self.createDialog({
  9182. name : name,
  9183. width : 500,
  9184. title : self.lang(name),
  9185. body : html,
  9186. beforeRemove : function() {
  9187. colorBox.unbind();
  9188. },
  9189. yesBtn : {
  9190. name : self.lang('yes'),
  9191. click : function(e) {
  9192. var rows = rowsBox.val(),
  9193. cols = colsBox.val(),
  9194. width = widthBox.val(),
  9195. height = heightBox.val(),
  9196. widthType = widthTypeBox.val(),
  9197. heightType = heightTypeBox.val(),
  9198. padding = paddingBox.val(),
  9199. spacing = spacingBox.val(),
  9200. align = alignBox.val(),
  9201. border = borderBox.val(),
  9202. borderColor = K(colorBox[0]).html() || '',
  9203. bgColor = K(colorBox[1]).html() || '';
  9204. if (rows == 0 || !/^\d+$/.test(rows)) {
  9205. alert(self.lang('invalidRows'));
  9206. rowsBox[0].focus();
  9207. return;
  9208. }
  9209. if (cols == 0 || !/^\d+$/.test(cols)) {
  9210. alert(self.lang('invalidRows'));
  9211. colsBox[0].focus();
  9212. return;
  9213. }
  9214. if (!/^\d*$/.test(width)) {
  9215. alert(self.lang('invalidWidth'));
  9216. widthBox[0].focus();
  9217. return;
  9218. }
  9219. if (!/^\d*$/.test(height)) {
  9220. alert(self.lang('invalidHeight'));
  9221. heightBox[0].focus();
  9222. return;
  9223. }
  9224. if (!/^\d*$/.test(padding)) {
  9225. alert(self.lang('invalidPadding'));
  9226. paddingBox[0].focus();
  9227. return;
  9228. }
  9229. if (!/^\d*$/.test(spacing)) {
  9230. alert(self.lang('invalidSpacing'));
  9231. spacingBox[0].focus();
  9232. return;
  9233. }
  9234. if (!/^\d*$/.test(border)) {
  9235. alert(self.lang('invalidBorder'));
  9236. borderBox[0].focus();
  9237. return;
  9238. }
  9239. if (table) {
  9240. if (width !== '') {
  9241. table.width(width + widthType);
  9242. } else {
  9243. table.css('width', '');
  9244. }
  9245. if (table[0].width !== undefined) {
  9246. table.removeAttr('width');
  9247. }
  9248. if (height !== '') {
  9249. table.height(height + heightType);
  9250. } else {
  9251. table.css('height', '');
  9252. }
  9253. if (table[0].height !== undefined) {
  9254. table.removeAttr('height');
  9255. }
  9256. table.css('background-color', bgColor);
  9257. if (table[0].bgColor !== undefined) {
  9258. table.removeAttr('bgColor');
  9259. }
  9260. if (padding !== '') {
  9261. table[0].cellPadding = padding;
  9262. } else {
  9263. table.removeAttr('cellPadding');
  9264. }
  9265. if (spacing !== '') {
  9266. table[0].cellSpacing = spacing;
  9267. } else {
  9268. table.removeAttr('cellSpacing');
  9269. }
  9270. if (align !== '') {
  9271. table[0].align = align;
  9272. } else {
  9273. table.removeAttr('align');
  9274. }
  9275. if (border !== '') {
  9276. table.attr('border', border);
  9277. } else {
  9278. table.removeAttr('border');
  9279. }
  9280. if (border === '' || border === '0') {
  9281. table.addClass(zeroborder);
  9282. } else {
  9283. table.removeClass(zeroborder);
  9284. }
  9285. if (borderColor !== '') {
  9286. table.attr('borderColor', borderColor);
  9287. } else {
  9288. table.removeAttr('borderColor');
  9289. }
  9290. self.hideDialog().focus();
  9291. self.cmd.range.moveToBookmark(bookmark);
  9292. self.cmd.select();
  9293. self.addBookmark();
  9294. return;
  9295. }
  9296. var style = '';
  9297. if (width !== '') {
  9298. style += 'width:' + width + widthType + ';';
  9299. }
  9300. if (height !== '') {
  9301. style += 'height:' + height + heightType + ';';
  9302. }
  9303. if (bgColor !== '') {
  9304. style += 'background-color:' + bgColor + ';';
  9305. }
  9306. var html = '<table';
  9307. if (style !== '') {
  9308. html += ' style="' + style + '"';
  9309. }
  9310. if (padding !== '') {
  9311. html += ' cellpadding="' + padding + '"';
  9312. }
  9313. if (spacing !== '') {
  9314. html += ' cellspacing="' + spacing + '"';
  9315. }
  9316. if (align !== '') {
  9317. html += ' align="' + align + '"';
  9318. }
  9319. if (border !== '') {
  9320. html += ' border="' + border + '"';
  9321. }
  9322. if (border === '' || border === '0') {
  9323. html += ' class="' + zeroborder + '"';
  9324. }
  9325. if (borderColor !== '') {
  9326. html += ' bordercolor="' + borderColor + '"';
  9327. }
  9328. html += '>';
  9329. for (var i = 0; i < rows; i++) {
  9330. html += '<tr>';
  9331. for (var j = 0; j < cols; j++) {
  9332. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9333. }
  9334. html += '</tr>';
  9335. }
  9336. html += '</table>';
  9337. if (!K.IE) {
  9338. html += '<br />';
  9339. }
  9340. self.insertHtml(html);
  9341. self.select().hideDialog().focus();
  9342. self.addBookmark();
  9343. }
  9344. }
  9345. }),
  9346. div = dialog.div,
  9347. rowsBox = K('[name="rows"]', div).val(3),
  9348. colsBox = K('[name="cols"]', div).val(2),
  9349. widthBox = K('[name="width"]', div).val(100),
  9350. heightBox = K('[name="height"]', div),
  9351. widthTypeBox = K('[name="widthType"]', div),
  9352. heightTypeBox = K('[name="heightType"]', div),
  9353. paddingBox = K('[name="padding"]', div).val(2),
  9354. spacingBox = K('[name="spacing"]', div).val(0),
  9355. alignBox = K('[name="align"]', div),
  9356. borderBox = K('[name="border"]', div).val(1),
  9357. colorBox = K('.ke-input-color', div);
  9358. _initColorPicker(div, colorBox.eq(0));
  9359. _initColorPicker(div, colorBox.eq(1));
  9360. _setColor(colorBox.eq(0), '#000000');
  9361. _setColor(colorBox.eq(1), '');
  9362. rowsBox[0].focus();
  9363. rowsBox[0].select();
  9364. var table;
  9365. if (isInsert) {
  9366. return;
  9367. }
  9368. table = self.plugin.getSelectedTable();
  9369. if (table) {
  9370. rowsBox.val(table[0].rows.length);
  9371. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9372. rowsBox.attr('disabled', true);
  9373. colsBox.attr('disabled', true);
  9374. var match,
  9375. tableWidth = table[0].style.width || table[0].width,
  9376. tableHeight = table[0].style.height || table[0].height;
  9377. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9378. widthBox.val(match[1]);
  9379. widthTypeBox.val(match[2]);
  9380. } else {
  9381. widthBox.val('');
  9382. }
  9383. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9384. heightBox.val(match[1]);
  9385. heightTypeBox.val(match[2]);
  9386. }
  9387. paddingBox.val(table[0].cellPadding || '');
  9388. spacingBox.val(table[0].cellSpacing || '');
  9389. alignBox.val(table[0].align || '');
  9390. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9391. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9392. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9393. widthBox[0].focus();
  9394. widthBox[0].select();
  9395. }
  9396. },
  9397. cellprop : function() {
  9398. var html = [
  9399. '<div style="padding:20px;">',
  9400. '<div class="ke-dialog-row">',
  9401. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9402. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9403. '<select name="widthType">',
  9404. '<option value="%">' + lang.percent + '</option>',
  9405. '<option value="px">' + lang.px + '</option>',
  9406. '</select> &nbsp; ',
  9407. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9408. '<select name="heightType">',
  9409. '<option value="%">' + lang.percent + '</option>',
  9410. '<option value="px">' + lang.px + '</option>',
  9411. '</select>',
  9412. '</div>',
  9413. '<div class="ke-dialog-row">',
  9414. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9415. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9416. '<option value="">' + lang.alignDefault + '</option>',
  9417. '<option value="left">' + lang.alignLeft + '</option>',
  9418. '<option value="center">' + lang.alignCenter + '</option>',
  9419. '<option value="right">' + lang.alignRight + '</option>',
  9420. '</select> ',
  9421. lang.verticalAlign + ' <select name="verticalAlign">',
  9422. '<option value="">' + lang.alignDefault + '</option>',
  9423. '<option value="top">' + lang.alignTop + '</option>',
  9424. '<option value="middle">' + lang.alignMiddle + '</option>',
  9425. '<option value="bottom">' + lang.alignBottom + '</option>',
  9426. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9427. '</select>',
  9428. '</div>',
  9429. '<div class="ke-dialog-row">',
  9430. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9431. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9432. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9433. '</div>',
  9434. '<div class="ke-dialog-row">',
  9435. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9436. '<span class="ke-inline-block ke-input-color"></span>',
  9437. '</div>',
  9438. '</div>'
  9439. ].join('');
  9440. var bookmark = self.cmd.range.createBookmark();
  9441. var dialog = self.createDialog({
  9442. name : name,
  9443. width : 500,
  9444. title : self.lang('tablecell'),
  9445. body : html,
  9446. beforeRemove : function() {
  9447. colorBox.unbind();
  9448. },
  9449. yesBtn : {
  9450. name : self.lang('yes'),
  9451. click : function(e) {
  9452. var width = widthBox.val(),
  9453. height = heightBox.val(),
  9454. widthType = widthTypeBox.val(),
  9455. heightType = heightTypeBox.val(),
  9456. padding = paddingBox.val(),
  9457. spacing = spacingBox.val(),
  9458. textAlign = textAlignBox.val(),
  9459. verticalAlign = verticalAlignBox.val(),
  9460. border = borderBox.val(),
  9461. borderColor = K(colorBox[0]).html() || '',
  9462. bgColor = K(colorBox[1]).html() || '';
  9463. if (!/^\d*$/.test(width)) {
  9464. alert(self.lang('invalidWidth'));
  9465. widthBox[0].focus();
  9466. return;
  9467. }
  9468. if (!/^\d*$/.test(height)) {
  9469. alert(self.lang('invalidHeight'));
  9470. heightBox[0].focus();
  9471. return;
  9472. }
  9473. if (!/^\d*$/.test(border)) {
  9474. alert(self.lang('invalidBorder'));
  9475. borderBox[0].focus();
  9476. return;
  9477. }
  9478. cell.css({
  9479. width : width !== '' ? (width + widthType) : '',
  9480. height : height !== '' ? (height + heightType) : '',
  9481. 'background-color' : bgColor,
  9482. 'text-align' : textAlign,
  9483. 'vertical-align' : verticalAlign,
  9484. 'border-width' : border,
  9485. 'border-style' : border !== '' ? 'solid' : '',
  9486. 'border-color' : borderColor
  9487. });
  9488. self.hideDialog().focus();
  9489. self.cmd.range.moveToBookmark(bookmark);
  9490. self.cmd.select();
  9491. self.addBookmark();
  9492. }
  9493. }
  9494. }),
  9495. div = dialog.div,
  9496. widthBox = K('[name="width"]', div).val(100),
  9497. heightBox = K('[name="height"]', div),
  9498. widthTypeBox = K('[name="widthType"]', div),
  9499. heightTypeBox = K('[name="heightType"]', div),
  9500. paddingBox = K('[name="padding"]', div).val(2),
  9501. spacingBox = K('[name="spacing"]', div).val(0),
  9502. textAlignBox = K('[name="textAlign"]', div),
  9503. verticalAlignBox = K('[name="verticalAlign"]', div),
  9504. borderBox = K('[name="border"]', div).val(1),
  9505. colorBox = K('.ke-input-color', div);
  9506. _initColorPicker(div, colorBox.eq(0));
  9507. _initColorPicker(div, colorBox.eq(1));
  9508. _setColor(colorBox.eq(0), '#000000');
  9509. _setColor(colorBox.eq(1), '');
  9510. widthBox[0].focus();
  9511. widthBox[0].select();
  9512. var cell = self.plugin.getSelectedCell();
  9513. var match,
  9514. cellWidth = cell[0].style.width || cell[0].width || '',
  9515. cellHeight = cell[0].style.height || cell[0].height || '';
  9516. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9517. widthBox.val(match[1]);
  9518. widthTypeBox.val(match[2]);
  9519. } else {
  9520. widthBox.val('');
  9521. }
  9522. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9523. heightBox.val(match[1]);
  9524. heightTypeBox.val(match[2]);
  9525. }
  9526. textAlignBox.val(cell[0].style.textAlign || '');
  9527. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9528. var border = cell[0].style.borderWidth || '';
  9529. if (border) {
  9530. border = parseInt(border);
  9531. }
  9532. borderBox.val(border);
  9533. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9534. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9535. widthBox[0].focus();
  9536. widthBox[0].select();
  9537. },
  9538. insert : function() {
  9539. this.prop(true);
  9540. },
  9541. 'delete' : function() {
  9542. var table = self.plugin.getSelectedTable();
  9543. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9544. self.cmd.select();
  9545. table.remove();
  9546. self.addBookmark();
  9547. },
  9548. colinsert : function(offset) {
  9549. var table = self.plugin.getSelectedTable()[0],
  9550. row = self.plugin.getSelectedRow()[0],
  9551. cell = self.plugin.getSelectedCell()[0],
  9552. index = cell.cellIndex + offset;
  9553. index += table.rows[0].cells.length - row.cells.length;
  9554. for (var i = 0, len = table.rows.length; i < len; i++) {
  9555. var newRow = table.rows[i],
  9556. newCell = newRow.insertCell(index);
  9557. newCell.innerHTML = K.IE ? '' : '<br />';
  9558. index = _getCellIndex(table, newRow, newCell);
  9559. }
  9560. self.cmd.range.selectNodeContents(cell).collapse(true);
  9561. self.cmd.select();
  9562. self.addBookmark();
  9563. },
  9564. colinsertleft : function() {
  9565. this.colinsert(0);
  9566. },
  9567. colinsertright : function() {
  9568. this.colinsert(1);
  9569. },
  9570. rowinsert : function(offset) {
  9571. var table = self.plugin.getSelectedTable()[0],
  9572. row = self.plugin.getSelectedRow()[0],
  9573. cell = self.plugin.getSelectedCell()[0];
  9574. var rowIndex = row.rowIndex;
  9575. if (offset === 1) {
  9576. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9577. }
  9578. var newRow = table.insertRow(rowIndex);
  9579. for (var i = 0, len = row.cells.length; i < len; i++) {
  9580. if (row.cells[i].rowSpan > 1) {
  9581. len -= row.cells[i].rowSpan - 1;
  9582. }
  9583. var newCell = newRow.insertCell(i);
  9584. if (offset === 1 && row.cells[i].colSpan > 1) {
  9585. newCell.colSpan = row.cells[i].colSpan;
  9586. }
  9587. newCell.innerHTML = K.IE ? '' : '<br />';
  9588. }
  9589. for (var j = rowIndex; j >= 0; j--) {
  9590. var cells = table.rows[j].cells;
  9591. if (cells.length > i) {
  9592. for (var k = cell.cellIndex; k >= 0; k--) {
  9593. if (cells[k].rowSpan > 1) {
  9594. cells[k].rowSpan += 1;
  9595. }
  9596. }
  9597. break;
  9598. }
  9599. }
  9600. self.cmd.range.selectNodeContents(cell).collapse(true);
  9601. self.cmd.select();
  9602. self.addBookmark();
  9603. },
  9604. rowinsertabove : function() {
  9605. this.rowinsert(0);
  9606. },
  9607. rowinsertbelow : function() {
  9608. this.rowinsert(1);
  9609. },
  9610. rowmerge : function() {
  9611. var table = self.plugin.getSelectedTable()[0],
  9612. row = self.plugin.getSelectedRow()[0],
  9613. cell = self.plugin.getSelectedCell()[0],
  9614. rowIndex = row.rowIndex,
  9615. nextRowIndex = rowIndex + cell.rowSpan,
  9616. nextRow = table.rows[nextRowIndex];
  9617. if (table.rows.length <= nextRowIndex) {
  9618. return;
  9619. }
  9620. var cellIndex = cell.cellIndex;
  9621. if (nextRow.cells.length <= cellIndex) {
  9622. return;
  9623. }
  9624. var nextCell = nextRow.cells[cellIndex];
  9625. if (cell.colSpan !== nextCell.colSpan) {
  9626. return;
  9627. }
  9628. cell.rowSpan += nextCell.rowSpan;
  9629. nextRow.deleteCell(cellIndex);
  9630. self.cmd.range.selectNodeContents(cell).collapse(true);
  9631. self.cmd.select();
  9632. self.addBookmark();
  9633. },
  9634. colmerge : function() {
  9635. var table = self.plugin.getSelectedTable()[0],
  9636. row = self.plugin.getSelectedRow()[0],
  9637. cell = self.plugin.getSelectedCell()[0],
  9638. rowIndex = row.rowIndex,
  9639. cellIndex = cell.cellIndex,
  9640. nextCellIndex = cellIndex + 1;
  9641. if (row.cells.length <= nextCellIndex) {
  9642. return;
  9643. }
  9644. var nextCell = row.cells[nextCellIndex];
  9645. if (cell.rowSpan !== nextCell.rowSpan) {
  9646. return;
  9647. }
  9648. cell.colSpan += nextCell.colSpan;
  9649. row.deleteCell(nextCellIndex);
  9650. self.cmd.range.selectNodeContents(cell).collapse(true);
  9651. self.cmd.select();
  9652. self.addBookmark();
  9653. },
  9654. rowsplit : function() {
  9655. var table = self.plugin.getSelectedTable()[0],
  9656. row = self.plugin.getSelectedRow()[0],
  9657. cell = self.plugin.getSelectedCell()[0],
  9658. rowIndex = row.rowIndex;
  9659. if (cell.rowSpan === 1) {
  9660. return;
  9661. }
  9662. var cellIndex = _getCellIndex(table, row, cell);
  9663. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9664. var newRow = table.rows[rowIndex + i],
  9665. newCell = newRow.insertCell(cellIndex);
  9666. if (cell.colSpan > 1) {
  9667. newCell.colSpan = cell.colSpan;
  9668. }
  9669. newCell.innerHTML = K.IE ? '' : '<br />';
  9670. cellIndex = _getCellIndex(table, newRow, newCell);
  9671. }
  9672. K(cell).removeAttr('rowSpan');
  9673. self.cmd.range.selectNodeContents(cell).collapse(true);
  9674. self.cmd.select();
  9675. self.addBookmark();
  9676. },
  9677. colsplit : function() {
  9678. var table = self.plugin.getSelectedTable()[0],
  9679. row = self.plugin.getSelectedRow()[0],
  9680. cell = self.plugin.getSelectedCell()[0],
  9681. cellIndex = cell.cellIndex;
  9682. if (cell.colSpan === 1) {
  9683. return;
  9684. }
  9685. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9686. var newCell = row.insertCell(cellIndex + i);
  9687. if (cell.rowSpan > 1) {
  9688. newCell.rowSpan = cell.rowSpan;
  9689. }
  9690. newCell.innerHTML = K.IE ? '' : '<br />';
  9691. }
  9692. K(cell).removeAttr('colSpan');
  9693. self.cmd.range.selectNodeContents(cell).collapse(true);
  9694. self.cmd.select();
  9695. self.addBookmark();
  9696. },
  9697. coldelete : function() {
  9698. var table = self.plugin.getSelectedTable()[0],
  9699. row = self.plugin.getSelectedRow()[0],
  9700. cell = self.plugin.getSelectedCell()[0],
  9701. index = cell.cellIndex;
  9702. for (var i = 0, len = table.rows.length; i < len; i++) {
  9703. var newRow = table.rows[i],
  9704. newCell = newRow.cells[index];
  9705. if (newCell.colSpan > 1) {
  9706. newCell.colSpan -= 1;
  9707. if (newCell.colSpan === 1) {
  9708. K(newCell).removeAttr('colSpan');
  9709. }
  9710. } else {
  9711. newRow.deleteCell(index);
  9712. }
  9713. if (newCell.rowSpan > 1) {
  9714. i += newCell.rowSpan - 1;
  9715. }
  9716. }
  9717. if (row.cells.length === 0) {
  9718. self.cmd.range.setStartBefore(table).collapse(true);
  9719. self.cmd.select();
  9720. K(table).remove();
  9721. } else {
  9722. self.cmd.selection(true);
  9723. }
  9724. self.addBookmark();
  9725. },
  9726. rowdelete : function() {
  9727. var table = self.plugin.getSelectedTable()[0],
  9728. row = self.plugin.getSelectedRow()[0],
  9729. cell = self.plugin.getSelectedCell()[0],
  9730. rowIndex = row.rowIndex;
  9731. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9732. table.deleteRow(rowIndex + i);
  9733. }
  9734. if (table.rows.length === 0) {
  9735. self.cmd.range.setStartBefore(table).collapse(true);
  9736. self.cmd.select();
  9737. K(table).remove();
  9738. } else {
  9739. self.cmd.selection(true);
  9740. }
  9741. self.addBookmark();
  9742. }
  9743. };
  9744. self.clickToolbar(name, self.plugin.table.prop);
  9745. });
  9746. /*******************************************************************************
  9747. * KindEditor - WYSIWYG HTML Editor for Internet
  9748. * Copyright (C) 2006-2011 kindsoft.net
  9749. *
  9750. * @author Roddy <luolonghao@gmail.com>
  9751. * @site http://www.kindsoft.net/
  9752. * @licence http://www.kindsoft.net/license.php
  9753. *******************************************************************************/
  9754. KindEditor.plugin('template', function(K) {
  9755. var self = this, name = 'template', lang = self.lang(name + '.'),
  9756. htmlPath = self.pluginsPath + name + '/html/';
  9757. function getFilePath(fileName) {
  9758. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9759. }
  9760. self.clickToolbar(name, function() {
  9761. var lang = self.lang(name + '.'),
  9762. arr = ['<div style="padding:10px 20px;">',
  9763. '<div class="ke-header">',
  9764. '<div class="ke-left">',
  9765. lang. selectTemplate + ' <select>'];
  9766. K.each(lang.fileList, function(key, val) {
  9767. arr.push('<option value="' + key + '">' + val + '</option>');
  9768. });
  9769. html = [arr.join(''),
  9770. '</select></div>',
  9771. '<div class="ke-right">',
  9772. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9773. '</div>',
  9774. '<div class="ke-clearfix"></div>',
  9775. '</div>',
  9776. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9777. '</div>'].join('');
  9778. var dialog = self.createDialog({
  9779. name : name,
  9780. width : 500,
  9781. title : self.lang(name),
  9782. body : html,
  9783. yesBtn : {
  9784. name : self.lang('yes'),
  9785. click : function(e) {
  9786. var doc = K.iframeDoc(iframe);
  9787. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9788. }
  9789. }
  9790. });
  9791. var selectBox = K('select', dialog.div),
  9792. checkbox = K('[name="replaceFlag"]', dialog.div),
  9793. iframe = K('iframe', dialog.div);
  9794. checkbox[0].checked = true;
  9795. iframe.attr('src', getFilePath(selectBox.val()));
  9796. selectBox.change(function() {
  9797. iframe.attr('src', getFilePath(this.value));
  9798. });
  9799. });
  9800. });
  9801. /*******************************************************************************
  9802. * KindEditor - WYSIWYG HTML Editor for Internet
  9803. * Copyright (C) 2006-2011 kindsoft.net
  9804. *
  9805. * @author Roddy <luolonghao@gmail.com>
  9806. * @site http://www.kindsoft.net/
  9807. * @licence http://www.kindsoft.net/license.php
  9808. *******************************************************************************/
  9809. KindEditor.plugin('wordpaste', function(K) {
  9810. var self = this, name = 'wordpaste';
  9811. self.clickToolbar(name, function() {
  9812. var lang = self.lang(name + '.'),
  9813. html = '<div style="padding:10px 20px;">' +
  9814. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9815. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9816. '</div>',
  9817. dialog = self.createDialog({
  9818. name : name,
  9819. width : 450,
  9820. title : self.lang(name),
  9821. body : html,
  9822. yesBtn : {
  9823. name : self.lang('yes'),
  9824. click : function(e) {
  9825. var str = doc.body.innerHTML;
  9826. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9827. self.insertHtml(str).hideDialog().focus();
  9828. }
  9829. }
  9830. }),
  9831. div = dialog.div,
  9832. iframe = K('iframe', div),
  9833. doc = K.iframeDoc(iframe);
  9834. if (!K.IE) {
  9835. doc.designMode = 'on';
  9836. }
  9837. doc.open();
  9838. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9839. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9840. if (!K.IE) {
  9841. doc.write('<br />');
  9842. }
  9843. doc.write('</body></html>');
  9844. doc.close();
  9845. if (K.IE) {
  9846. doc.body.contentEditable = 'true';
  9847. }
  9848. iframe[0].contentWindow.focus();
  9849. });
  9850. });
  9851. KindEditor.plugin('fixtoolbar', function (K) {
  9852. var self = this;
  9853. if (!self.fixToolBar) {
  9854. return;
  9855. }
  9856. function init() {
  9857. var toolbar = K('.ke-toolbar');
  9858. var originY = toolbar.pos().y;
  9859. K(window).bind('scroll', function () {
  9860. if (toolbar.css('position') == 'fixed') {
  9861. if(document.body.scrollTop - originY < 0){
  9862. toolbar.css('position', 'static');
  9863. toolbar.css('top', 'auto');
  9864. }
  9865. } else {
  9866. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9867. toolbar.css('position', 'fixed');
  9868. toolbar.css('top', 0);
  9869. }
  9870. }
  9871. });
  9872. }
  9873. if (self.isCreated) {
  9874. init();
  9875. } else {
  9876. self.afterCreate(init);
  9877. }
  9878. });
  9879. function autoImg(self) {
  9880. var index = self.index;
  9881. var haspicContainer = document.getElementById("has_pic_" + index);
  9882. if (haspicContainer == null) {
  9883. haspicContainer = document.createElement("div");
  9884. haspicContainer.id = "has_pic_" + index;
  9885. haspicContainer.innerHTML = "<input type='text' id='piclist_"+index+"' value='' style='display:none;'/><div id='upload_"+index+"'><b>您有图片需要上传到服务器</b>&nbsp;&nbsp;<a href='javascript:uploadpic(\""+self.uploadJson+"\", \""+self.filePostName+"\", \""+index+"\");' >上传</a></div><div id='confirm_"+index+"'></div>";
  9886. $(".ke-toolbar").eq(index).after(haspicContainer);
  9887. }
  9888. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  9889. var piccount = 0;
  9890. var sstr = '';
  9891. $(img).each(function (i) {
  9892. var that = $(this);
  9893. var host = gethost(self.uploadJson);
  9894. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  9895. var n = gethost(that.attr("src"));
  9896. if (host != n) {
  9897. piccount++;
  9898. if (i == $(img).length - 1)
  9899. sstr += that.attr("src");
  9900. else
  9901. sstr += that.attr("src") + ",";
  9902. }
  9903. }
  9904. });
  9905. $("#piclist_" + index).val(encodeURIComponent(sstr));
  9906. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  9907. }
  9908. function closeupload(index) {
  9909. $("#has_pic_" + index).hide();
  9910. $("#upload_" + index).show();
  9911. }
  9912. function uploadpic(url, name, index) {
  9913. var piclist = encodeURI($("#piclist_" + index).val());
  9914. if (piclist.length == 0) return false;
  9915. $.ajax({
  9916. url: url.replace('kindeditor', 'copys') + '&json=1',
  9917. data: name + "=" + piclist,
  9918. type: "POST",
  9919. dataType: "json",
  9920. beforeSend: function () {
  9921. $("#upload_" + index).hide();
  9922. $("#confirm_" + index).text("正在上传中...");
  9923. },
  9924. success: function (msg) {
  9925. var url = msg.data;
  9926. if (url !== "") {
  9927. var str = new Array();
  9928. str = url.split(',');
  9929. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  9930. $(img).each(function (i) {
  9931. var that = $(this);
  9932. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  9933. that.attr("src", str[i]);
  9934. that.attr("data-ke-src", str[i]);
  9935. }
  9936. });
  9937. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  9938. }
  9939. else $("#confirm_" + index).text("上传失败!");
  9940. }
  9941. });
  9942. }
  9943. function gethost(url){
  9944. var reg = /^http(s)?:\/\/(.*?)\//;
  9945. return reg.exec(url)[2];
  9946. }