kindeditor-all.js 391 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2016 kindeditor.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindeditor.net/
  7. * @licence http://www.kindeditor.net/license.php
  8. * @version 4.1.11 (2016-03-31)
  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. }
  21. var _VERSION = '4.1.11 (2016-03-31)',
  22. _ua = navigator.userAgent.toLowerCase(),
  23. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  24. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  25. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  26. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  27. _OPERA = _ua.indexOf('opera') > -1,
  28. _MOBILE = _ua.indexOf('mobile') > -1,
  29. _IOS = /ipad|iphone|ipod/.test(_ua),
  30. _QUIRKS = document.compatMode != 'CSS1Compat',
  31. _IERANGE = !window.getSelection,
  32. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  33. _V = _matches ? _matches[1] : '0',
  34. _TIME = new Date().getTime();
  35. function _isArray(val) {
  36. if (!val) {
  37. return false;
  38. }
  39. return Object.prototype.toString.call(val) === '[object Array]';
  40. }
  41. function _isFunction(val) {
  42. if (!val) {
  43. return false;
  44. }
  45. return Object.prototype.toString.call(val) === '[object Function]';
  46. }
  47. function _inArray(val, arr) {
  48. for (var i = 0, len = arr.length; i < len; i++) {
  49. if (val === arr[i]) {
  50. return i;
  51. }
  52. }
  53. return -1;
  54. }
  55. function _each(obj, fn) {
  56. if (_isArray(obj)) {
  57. for (var i = 0, len = obj.length; i < len; i++) {
  58. if (fn.call(obj[i], i, obj[i]) === false) {
  59. break;
  60. }
  61. }
  62. } else {
  63. for (var key in obj) {
  64. if (obj.hasOwnProperty(key)) {
  65. if (fn.call(obj[key], key, obj[key]) === false) {
  66. break;
  67. }
  68. }
  69. }
  70. }
  71. }
  72. function _trim(str) {
  73. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  74. }
  75. function _inString(val, str, delimiter) {
  76. delimiter = delimiter === undefined ? ',' : delimiter;
  77. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  78. }
  79. function _addUnit(val, unit) {
  80. unit = unit || 'px';
  81. return val && /^-?\d+(?:\.\d+)?$/.test(val) ? val + unit : val;
  82. }
  83. function _removeUnit(val) {
  84. var match;
  85. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  86. }
  87. function _escape(val) {
  88. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  89. }
  90. function _unescape(val) {
  91. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  92. }
  93. function _toCamel(str) {
  94. var arr = str.split('-');
  95. str = '';
  96. _each(arr, function (key, val) {
  97. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  98. });
  99. return str;
  100. }
  101. function _toHex(val) {
  102. function hex(d) {
  103. var s = parseInt(d, 10).toString(16).toUpperCase();
  104. return s.length > 1 ? s : '0' + s;
  105. }
  106. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  107. function ($0, $1, $2, $3) {
  108. return '#' + hex($1) + hex($2) + hex($3);
  109. }
  110. );
  111. }
  112. function _toMap(val, delimiter) {
  113. delimiter = delimiter === undefined ? ',' : delimiter;
  114. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  115. _each(arr, function (key, val) {
  116. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  117. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  118. map[i.toString()] = true;
  119. }
  120. } else {
  121. map[val] = true;
  122. }
  123. });
  124. return map;
  125. }
  126. function _toArray(obj, offset) {
  127. return Array.prototype.slice.call(obj, offset || 0);
  128. }
  129. function _undef(val, defaultVal) {
  130. return val === undefined ? defaultVal : val;
  131. }
  132. function _invalidUrl(url) {
  133. return !url || /[<>"]/.test(url);
  134. }
  135. function _addParam(url, param) {
  136. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  137. }
  138. function _extend(child, parent, proto) {
  139. if (!proto) {
  140. proto = parent;
  141. parent = null;
  142. }
  143. var childProto;
  144. if (parent) {
  145. var fn = function () {
  146. };
  147. fn.prototype = parent.prototype;
  148. childProto = new fn();
  149. _each(proto, function (key, val) {
  150. childProto[key] = val;
  151. });
  152. } else {
  153. childProto = proto;
  154. }
  155. childProto.constructor = child;
  156. child.prototype = childProto;
  157. child.parent = parent ? parent.prototype : null;
  158. }
  159. function _json(text) {
  160. var match;
  161. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  162. text = match[0];
  163. }
  164. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  165. cx.lastIndex = 0;
  166. if (cx.test(text)) {
  167. text = text.replace(cx, function (a) {
  168. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  169. });
  170. }
  171. if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  172. return eval('(' + text + ')');
  173. }
  174. throw 'JSON parse error';
  175. }
  176. var _round = Math.round;
  177. var K = {
  178. DEBUG: false,
  179. VERSION: _VERSION,
  180. IE: _IE,
  181. GECKO: _GECKO,
  182. WEBKIT: _WEBKIT,
  183. OPERA: _OPERA,
  184. V: _V,
  185. TIME: _TIME,
  186. each: _each,
  187. isArray: _isArray,
  188. isFunction: _isFunction,
  189. inArray: _inArray,
  190. inString: _inString,
  191. trim: _trim,
  192. addUnit: _addUnit,
  193. removeUnit: _removeUnit,
  194. escape: _escape,
  195. unescape: _unescape,
  196. toCamel: _toCamel,
  197. toHex: _toHex,
  198. toMap: _toMap,
  199. toArray: _toArray,
  200. undef: _undef,
  201. invalidUrl: _invalidUrl,
  202. addParam: _addParam,
  203. extend: _extend,
  204. json: _json
  205. };
  206. 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'),
  207. _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'),
  208. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  209. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  210. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  211. _PRE_TAG_MAP = _toMap('pre,style,script'),
  212. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  213. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  214. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  215. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  216. function _getBasePath() {
  217. var els = document.getElementsByTagName('script'), src;
  218. for (var i = 0, len = els.length; i < len; i++) {
  219. src = els[i].src || '';
  220. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  221. return src.substring(0, src.lastIndexOf('/') + 1);
  222. }
  223. }
  224. return '';
  225. }
  226. K.basePath = _getBasePath();
  227. K.options = {
  228. designMode: true,
  229. fullscreenMode: false,
  230. filterMode: true,
  231. wellFormatMode: true,
  232. shadowMode: true,
  233. loadStyleMode: true,
  234. basePath: K.basePath,
  235. themesPath: K.basePath + 'themes/',
  236. langPath: K.basePath + 'lang/',
  237. pluginsPath: K.basePath + 'plugins/',
  238. themeType: 'default',
  239. langType: 'zh-CN',
  240. urlType: '',
  241. newlineTag: 'p',
  242. resizeType: 2,
  243. syncType: 'form',
  244. pasteType: 2,
  245. dialogAlignType: 'page',
  246. useContextmenu: true,
  247. fullscreenShortcut: false,
  248. bodyClass: 'ke-content',
  249. indentChar: '\t',
  250. cssPath: '',
  251. cssData: '',
  252. minWidth: 650,
  253. minHeight: 100,
  254. minChangeSize: 50,
  255. zIndex: 811213,
  256. items: [
  257. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  258. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  259. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  260. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  261. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  262. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  263. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  264. 'anchor', 'link', 'unlink', '|', 'about'
  265. ],
  266. noDisableItems: ['source', 'fullscreen'],
  267. colorTable: [
  268. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  269. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  270. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  271. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  272. ],
  273. fontSizeTable: ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  274. htmlTags: {
  275. font: ['id', 'class', 'color', 'size', 'face', '.background-color'],
  276. span: [
  277. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  278. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  279. ],
  280. div: [
  281. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  282. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  283. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  284. ],
  285. table: [
  286. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  287. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  288. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  289. '.width', '.height', '.border-collapse'
  290. ],
  291. 'td,th': [
  292. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  293. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  294. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  295. ],
  296. a: ['id', 'class', 'href', 'target', 'name'],
  297. embed: ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  298. img: ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  299. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6': [
  300. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  301. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  302. ],
  303. pre: ['id', 'class'],
  304. hr: ['id', 'class', '.page-break-after'],
  305. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del': ['id', 'class'],
  306. iframe: ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  307. },
  308. layout: '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  309. };
  310. var _useCapture = false;
  311. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  312. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  313. var _CHANGE_KEY_MAP = {};
  314. _each(_INPUT_KEY_MAP, function (key, val) {
  315. _CHANGE_KEY_MAP[key] = val;
  316. });
  317. _each(_CURSORMOVE_KEY_MAP, function (key, val) {
  318. _CHANGE_KEY_MAP[key] = val;
  319. });
  320. function _bindEvent(el, type, fn) {
  321. if (el.addEventListener) {
  322. el.addEventListener(type, fn, _useCapture);
  323. } else if (el.attachEvent) {
  324. el.attachEvent('on' + type, fn);
  325. }
  326. }
  327. function _unbindEvent(el, type, fn) {
  328. if (el.removeEventListener) {
  329. el.removeEventListener(type, fn, _useCapture);
  330. } else if (el.detachEvent) {
  331. el.detachEvent('on' + type, fn);
  332. }
  333. }
  334. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  335. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  336. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  337. function KEvent(el, event) {
  338. this.init(el, event);
  339. }
  340. _extend(KEvent, {
  341. init: function (el, event) {
  342. var self = this, doc = el.ownerDocument || el.document || el;
  343. self.event = event;
  344. _each(_EVENT_PROPS, function (key, val) {
  345. self[val] = event[val];
  346. });
  347. if (!self.target) {
  348. self.target = self.srcElement || doc;
  349. }
  350. if (self.target.nodeType === 3) {
  351. self.target = self.target.parentNode;
  352. }
  353. if (!self.relatedTarget && self.fromElement) {
  354. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  355. }
  356. if (self.pageX == null && self.clientX != null) {
  357. var d = doc.documentElement, body = doc.body;
  358. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  359. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  360. }
  361. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  362. self.which = self.charCode || self.keyCode;
  363. }
  364. if (!self.metaKey && self.ctrlKey) {
  365. self.metaKey = self.ctrlKey;
  366. }
  367. if (!self.which && self.button !== undefined) {
  368. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  369. }
  370. switch (self.which) {
  371. case 186 :
  372. self.which = 59;
  373. break;
  374. case 187 :
  375. case 107 :
  376. case 43 :
  377. self.which = 61;
  378. break;
  379. case 189 :
  380. case 45 :
  381. self.which = 109;
  382. break;
  383. case 42 :
  384. self.which = 106;
  385. break;
  386. case 47 :
  387. self.which = 111;
  388. break;
  389. case 78 :
  390. self.which = 110;
  391. break;
  392. }
  393. if (self.which >= 96 && self.which <= 105) {
  394. self.which -= 48;
  395. }
  396. },
  397. preventDefault: function () {
  398. var ev = this.event;
  399. if (ev.preventDefault) {
  400. ev.preventDefault();
  401. } else {
  402. ev.returnValue = false;
  403. }
  404. },
  405. stopPropagation: function () {
  406. var ev = this.event;
  407. if (ev.stopPropagation) {
  408. ev.stopPropagation();
  409. } else {
  410. ev.cancelBubble = true;
  411. }
  412. },
  413. stop: function () {
  414. this.preventDefault();
  415. this.stopPropagation();
  416. }
  417. });
  418. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  419. function _getId(el) {
  420. return el[_eventExpendo] || null;
  421. }
  422. function _setId(el) {
  423. el[_eventExpendo] = ++_eventId;
  424. return _eventId;
  425. }
  426. function _removeId(el) {
  427. try {
  428. delete el[_eventExpendo];
  429. } catch (e) {
  430. if (el.removeAttribute) {
  431. el.removeAttribute(_eventExpendo);
  432. }
  433. }
  434. }
  435. function _bind(el, type, fn) {
  436. if (type.indexOf(',') >= 0) {
  437. _each(type.split(','), function () {
  438. _bind(el, this, fn);
  439. });
  440. return;
  441. }
  442. var id = _getId(el);
  443. if (!id) {
  444. id = _setId(el);
  445. }
  446. if (_eventData[id] === undefined) {
  447. _eventData[id] = {};
  448. }
  449. var events = _eventData[id][type];
  450. if (events && events.length > 0) {
  451. _unbindEvent(el, type, events[0]);
  452. } else {
  453. _eventData[id][type] = [];
  454. _eventData[id].el = el;
  455. }
  456. events = _eventData[id][type];
  457. if (events.length === 0) {
  458. events[0] = function (e) {
  459. var kevent = e ? new KEvent(el, e) : undefined;
  460. _each(events, function (i, event) {
  461. if (i > 0 && event) {
  462. event.call(el, kevent);
  463. }
  464. });
  465. };
  466. }
  467. if (_inArray(fn, events) < 0) {
  468. events.push(fn);
  469. }
  470. _bindEvent(el, type, events[0]);
  471. }
  472. function _unbind(el, type, fn) {
  473. if (type && type.indexOf(',') >= 0) {
  474. _each(type.split(','), function () {
  475. _unbind(el, this, fn);
  476. });
  477. return;
  478. }
  479. var id = _getId(el);
  480. if (!id) {
  481. return;
  482. }
  483. if (type === undefined) {
  484. if (id in _eventData) {
  485. _each(_eventData[id], function (key, events) {
  486. if (key != 'el' && events.length > 0) {
  487. _unbindEvent(el, key, events[0]);
  488. }
  489. });
  490. delete _eventData[id];
  491. _removeId(el);
  492. }
  493. return;
  494. }
  495. if (!_eventData[id]) {
  496. return;
  497. }
  498. var events = _eventData[id][type];
  499. if (events && events.length > 0) {
  500. if (fn === undefined) {
  501. _unbindEvent(el, type, events[0]);
  502. delete _eventData[id][type];
  503. } else {
  504. _each(events, function (i, event) {
  505. if (i > 0 && event === fn) {
  506. events.splice(i, 1);
  507. }
  508. });
  509. if (events.length == 1) {
  510. _unbindEvent(el, type, events[0]);
  511. delete _eventData[id][type];
  512. }
  513. }
  514. var count = 0;
  515. _each(_eventData[id], function () {
  516. count++;
  517. });
  518. if (count < 2) {
  519. delete _eventData[id];
  520. _removeId(el);
  521. }
  522. }
  523. }
  524. function _fire(el, type) {
  525. if (type.indexOf(',') >= 0) {
  526. _each(type.split(','), function () {
  527. _fire(el, this);
  528. });
  529. return;
  530. }
  531. var id = _getId(el);
  532. if (!id) {
  533. return;
  534. }
  535. var events = _eventData[id][type];
  536. if (_eventData[id] && events && events.length > 0) {
  537. events[0]();
  538. }
  539. }
  540. function _ctrl(el, key, fn) {
  541. var self = this;
  542. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  543. _bind(el, 'keydown', function (e) {
  544. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  545. fn.call(el);
  546. e.stop();
  547. }
  548. });
  549. }
  550. var _readyFinished = false;
  551. function _ready(fn) {
  552. if (_readyFinished) {
  553. fn(KindEditor);
  554. return;
  555. }
  556. var loaded = false;
  557. function readyFunc() {
  558. if (!loaded) {
  559. loaded = true;
  560. fn(KindEditor);
  561. _readyFinished = true;
  562. }
  563. }
  564. function ieReadyFunc() {
  565. if (!loaded) {
  566. try {
  567. document.documentElement.doScroll('left');
  568. } catch (e) {
  569. setTimeout(ieReadyFunc, 100);
  570. return;
  571. }
  572. readyFunc();
  573. }
  574. }
  575. function ieReadyStateFunc() {
  576. if (document.readyState === 'complete') {
  577. readyFunc();
  578. }
  579. }
  580. if (document.addEventListener) {
  581. _bind(document, 'DOMContentLoaded', readyFunc);
  582. } else if (document.attachEvent) {
  583. _bind(document, 'readystatechange', ieReadyStateFunc);
  584. var toplevel = false;
  585. try {
  586. toplevel = window.frameElement == null;
  587. } catch (e) {
  588. }
  589. if (document.documentElement.doScroll && toplevel) {
  590. ieReadyFunc();
  591. }
  592. }
  593. _bind(window, 'load', readyFunc);
  594. }
  595. if (window.attachEvent) {
  596. window.attachEvent('onunload', function () {
  597. _each(_eventData, function (key, events) {
  598. if (events.el) {
  599. _unbind(events.el);
  600. }
  601. });
  602. });
  603. }
  604. K.ctrl = _ctrl;
  605. K.ready = _ready;
  606. function _getCssList(css) {
  607. var list = {},
  608. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  609. match;
  610. while ((match = reg.exec(css))) {
  611. var key = _trim(match[1].toLowerCase()),
  612. val = _trim(_toHex(match[2]));
  613. list[key] = val;
  614. }
  615. return list;
  616. }
  617. function _getAttrList(tag) {
  618. var list = {},
  619. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  620. match;
  621. while ((match = reg.exec(tag))) {
  622. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  623. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  624. list[key] = val;
  625. }
  626. return list;
  627. }
  628. function _addClassToTag(tag, className) {
  629. if (/\s+class\s*=/.test(tag)) {
  630. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function ($0, $1, $2, $3) {
  631. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  632. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  633. } else {
  634. return $0;
  635. }
  636. });
  637. } else {
  638. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  639. }
  640. return tag;
  641. }
  642. function _formatCss(css) {
  643. var str = '';
  644. _each(_getCssList(css), function (key, val) {
  645. str += key + ':' + val + ';';
  646. });
  647. return str;
  648. }
  649. function _formatUrl(url, mode, host, pathname) {
  650. mode = _undef(mode, '').toLowerCase();
  651. if (url.substr(0, 5) != 'data:') {
  652. url = url.replace(/([^:])\/\//g, '$1/');
  653. }
  654. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  655. return url;
  656. }
  657. host = host || location.protocol + '//' + location.host;
  658. if (pathname === undefined) {
  659. var m = location.pathname.match(/^(\/.*)\//);
  660. pathname = m ? m[1] : '';
  661. }
  662. var match;
  663. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  664. if (match[1] !== host) {
  665. return url;
  666. }
  667. } else if (/^\w+:/.test(url)) {
  668. return url;
  669. }
  670. function getRealPath(path) {
  671. var parts = path.split('/'), paths = [];
  672. for (var i = 0, len = parts.length; i < len; i++) {
  673. var part = parts[i];
  674. if (part == '..') {
  675. if (paths.length > 0) {
  676. paths.pop();
  677. }
  678. } else if (part !== '' && part != '.') {
  679. paths.push(part);
  680. }
  681. }
  682. return '/' + paths.join('/');
  683. }
  684. if (/^\//.test(url)) {
  685. url = host + getRealPath(url.substr(1));
  686. } else if (!/^\w+:\/\//.test(url)) {
  687. url = host + getRealPath(pathname + '/' + url);
  688. }
  689. function getRelativePath(path, depth) {
  690. if (url.substr(0, path.length) === path) {
  691. var arr = [];
  692. for (var i = 0; i < depth; i++) {
  693. arr.push('..');
  694. }
  695. var prefix = '.';
  696. if (arr.length > 0) {
  697. prefix += '/' + arr.join('/');
  698. }
  699. if (pathname == '/') {
  700. prefix += '/';
  701. }
  702. return prefix + url.substr(path.length);
  703. } else {
  704. if ((match = /^(.*)\//.exec(path))) {
  705. return getRelativePath(match[1], ++depth);
  706. }
  707. }
  708. }
  709. if (mode === 'relative') {
  710. url = getRelativePath(host + pathname, 0).substr(2);
  711. } else if (mode === 'absolute') {
  712. if (url.substr(0, host.length) === host) {
  713. url = url.substr(host.length);
  714. }
  715. }
  716. return url;
  717. }
  718. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  719. if (html == null) {
  720. html = '';
  721. }
  722. urlType = urlType || '';
  723. wellFormatted = _undef(wellFormatted, false);
  724. indentChar = _undef(indentChar, '\t');
  725. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  726. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function ($0, $1, $2, $3) {
  727. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  728. });
  729. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  730. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  731. html = html.replace(/\u200B/g, '');
  732. html = html.replace(/\u00A9/g, '&copy;');
  733. html = html.replace(/\u00AE/g, '&reg;');
  734. html = html.replace(/\u2003/g, '&emsp;');
  735. html = html.replace(/\u3000/g, '&emsp;');
  736. html = html.replace(/<[^>]+/g, function ($0) {
  737. return $0.replace(/\s+/g, ' ');
  738. });
  739. var htmlTagMap = {};
  740. if (htmlTags) {
  741. _each(htmlTags, function (key, val) {
  742. var arr = key.split(',');
  743. for (var i = 0, len = arr.length; i < len; i++) {
  744. htmlTagMap[arr[i]] = _toMap(val);
  745. }
  746. });
  747. if (!htmlTagMap.script) {
  748. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  749. }
  750. if (!htmlTagMap.style) {
  751. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  752. }
  753. }
  754. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  755. var tagStack = [];
  756. html = html.replace(re, function ($0, $1, $2, $3, $4, $5, $6) {
  757. var full = $0,
  758. startNewline = $1 || '',
  759. startSlash = $2 || '',
  760. tagName = $3.toLowerCase(),
  761. attr = $4 || '',
  762. endSlash = $5 ? ' ' + $5 : '',
  763. endNewline = $6 || '';
  764. if (htmlTags && !htmlTagMap[tagName]) {
  765. return '';
  766. }
  767. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  768. endSlash = ' /';
  769. }
  770. if (_INLINE_TAG_MAP[tagName]) {
  771. if (startNewline) {
  772. startNewline = ' ';
  773. }
  774. if (endNewline) {
  775. endNewline = ' ';
  776. }
  777. }
  778. if (_PRE_TAG_MAP[tagName]) {
  779. if (startSlash) {
  780. endNewline = '\n';
  781. } else {
  782. startNewline = '\n';
  783. }
  784. }
  785. if (wellFormatted && tagName == 'br') {
  786. endNewline = '\n';
  787. }
  788. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  789. if (wellFormatted) {
  790. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  791. tagStack.pop();
  792. } else {
  793. tagStack.push(tagName);
  794. }
  795. startNewline = '\n';
  796. endNewline = '\n';
  797. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  798. startNewline += indentChar;
  799. if (!startSlash) {
  800. endNewline += indentChar;
  801. }
  802. }
  803. if (endSlash) {
  804. tagStack.pop();
  805. } else if (!startSlash) {
  806. endNewline += indentChar;
  807. }
  808. } else {
  809. startNewline = endNewline = '';
  810. }
  811. }
  812. if (attr !== '') {
  813. var attrMap = _getAttrList(full);
  814. if (tagName === 'font') {
  815. var fontStyleMap = {}, fontStyle = '';
  816. _each(attrMap, function (key, val) {
  817. if (key === 'color') {
  818. fontStyleMap.color = val;
  819. delete attrMap[key];
  820. }
  821. if (key === 'size') {
  822. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  823. delete attrMap[key];
  824. }
  825. if (key === 'face') {
  826. fontStyleMap['font-family'] = val;
  827. delete attrMap[key];
  828. }
  829. if (key === 'style') {
  830. fontStyle = val;
  831. }
  832. });
  833. if (fontStyle && !/;$/.test(fontStyle)) {
  834. fontStyle += ';';
  835. }
  836. _each(fontStyleMap, function (key, val) {
  837. if (val === '') {
  838. return;
  839. }
  840. if (/\s/.test(val)) {
  841. val = "'" + val + "'";
  842. }
  843. fontStyle += key + ':' + val + ';';
  844. });
  845. attrMap.style = fontStyle;
  846. }
  847. _each(attrMap, function (key, val) {
  848. if (_FILL_ATTR_MAP[key]) {
  849. attrMap[key] = key;
  850. }
  851. if (_inArray(key, ['src', 'href']) >= 0) {
  852. attrMap[key] = _formatUrl(val, urlType);
  853. }
  854. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  855. tagName === 'body' && key === 'contenteditable' ||
  856. /^kindeditor_\d+$/.test(key)) {
  857. delete attrMap[key];
  858. }
  859. if (key === 'style' && val !== '') {
  860. var styleMap = _getCssList(val);
  861. _each(styleMap, function (k, v) {
  862. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  863. delete styleMap[k];
  864. }
  865. });
  866. var style = '';
  867. _each(styleMap, function (k, v) {
  868. style += k + ':' + v + ';';
  869. });
  870. attrMap.style = style;
  871. }
  872. });
  873. attr = '';
  874. _each(attrMap, function (key, val) {
  875. if (key === 'style' && val === '') {
  876. return;
  877. }
  878. val = val.replace(/"/g, '&quot;');
  879. attr += ' ' + key + '="' + val + '"';
  880. });
  881. }
  882. if (tagName === 'font') {
  883. tagName = 'span';
  884. }
  885. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  886. });
  887. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function ($0, $1, $2, $3) {
  888. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  889. });
  890. html = html.replace(/\n\s*\n/g, '\n');
  891. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  892. return _trim(html);
  893. }
  894. function _clearMsWord(html, htmlTags) {
  895. html = html.replace(/<meta[\s\S]*?>/ig, '')
  896. .replace(/<![\s\S]*?>/ig, '')
  897. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  898. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  899. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  900. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  901. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  902. .replace(/<(?:table|td)[^>]*>/ig, function (full) {
  903. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  904. });
  905. return _formatHtml(html, htmlTags);
  906. }
  907. function _mediaType(src) {
  908. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  909. return 'audio/x-pn-realaudio-plugin';
  910. }
  911. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  912. return 'application/x-shockwave-flash';
  913. }
  914. return 'video/x-ms-asf-plugin';
  915. }
  916. function _mediaClass(type) {
  917. if (/realaudio/i.test(type)) {
  918. return 'ke-rm';
  919. }
  920. if (/flash/i.test(type)) {
  921. return 'ke-flash';
  922. }
  923. return 'ke-media';
  924. }
  925. function _mediaAttrs(srcTag) {
  926. return _getAttrList(unescape(srcTag));
  927. }
  928. function _mediaEmbed(attrs) {
  929. var html = '<embed ';
  930. _each(attrs, function (key, val) {
  931. html += key + '="' + val + '" ';
  932. });
  933. html += '/>';
  934. return html;
  935. }
  936. function _mediaImg(blankPath, attrs) {
  937. var width = attrs.width,
  938. height = attrs.height,
  939. type = attrs.type || _mediaType(attrs.src),
  940. srcTag = _mediaEmbed(attrs),
  941. style = '';
  942. if (/\D/.test(width)) {
  943. style += 'width:' + width + ';';
  944. } else if (width > 0) {
  945. style += 'width:' + width + 'px;';
  946. }
  947. if (/\D/.test(height)) {
  948. style += 'height:' + height + ';';
  949. } else if (height > 0) {
  950. style += 'height:' + height + 'px;';
  951. }
  952. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  953. if (style !== '') {
  954. html += 'style="' + style + '" ';
  955. }
  956. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  957. return html;
  958. }
  959. function _tmpl(str, data) {
  960. var fn = new Function("obj",
  961. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  962. "with(obj){p.push('" +
  963. str.replace(/[\r\t\n]/g, " ")
  964. .split("<%").join("\t")
  965. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  966. .replace(/\t=(.*?)%>/g, "',$1,'")
  967. .split("\t").join("');")
  968. .split("%>").join("p.push('")
  969. .split("\r").join("\\'") + "');}return p.join('');");
  970. return data ? fn(data) : fn;
  971. }
  972. K.formatUrl = _formatUrl;
  973. K.formatHtml = _formatHtml;
  974. K.getCssList = _getCssList;
  975. K.getAttrList = _getAttrList;
  976. K.mediaType = _mediaType;
  977. K.mediaAttrs = _mediaAttrs;
  978. K.mediaEmbed = _mediaEmbed;
  979. K.mediaImg = _mediaImg;
  980. K.clearMsWord = _clearMsWord;
  981. K.tmpl = _tmpl;
  982. function _contains(nodeA, nodeB) {
  983. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  984. return true;
  985. }
  986. while ((nodeB = nodeB.parentNode)) {
  987. if (nodeB == nodeA) {
  988. return true;
  989. }
  990. }
  991. return false;
  992. }
  993. var _getSetAttrDiv = document.createElement('div');
  994. _getSetAttrDiv.setAttribute('className', 't');
  995. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  996. function _getAttr(el, key) {
  997. key = key.toLowerCase();
  998. var val = null;
  999. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1000. var div = el.ownerDocument.createElement('div');
  1001. div.appendChild(el.cloneNode(false));
  1002. var list = _getAttrList(_unescape(div.innerHTML));
  1003. if (key in list) {
  1004. val = list[key];
  1005. }
  1006. } else {
  1007. try {
  1008. val = el.getAttribute(key, 2);
  1009. } catch (e) {
  1010. val = el.getAttribute(key, 1);
  1011. }
  1012. }
  1013. if (key === 'style' && val !== null) {
  1014. val = _formatCss(val);
  1015. }
  1016. return val;
  1017. }
  1018. function _queryAll(expr, root) {
  1019. var exprList = expr.split(',');
  1020. if (exprList.length > 1) {
  1021. var mergedResults = [];
  1022. _each(exprList, function () {
  1023. _each(_queryAll(this, root), function () {
  1024. if (_inArray(this, mergedResults) < 0) {
  1025. mergedResults.push(this);
  1026. }
  1027. });
  1028. });
  1029. return mergedResults;
  1030. }
  1031. root = root || document;
  1032. function escape(str) {
  1033. if (typeof str != 'string') {
  1034. return str;
  1035. }
  1036. return str.replace(/([^\w\-])/g, '\\$1');
  1037. }
  1038. function stripslashes(str) {
  1039. return str.replace(/\\/g, '');
  1040. }
  1041. function cmpTag(tagA, tagB) {
  1042. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1043. }
  1044. function byId(id, tag, root) {
  1045. var arr = [],
  1046. doc = root.ownerDocument || root,
  1047. el = doc.getElementById(stripslashes(id));
  1048. if (el) {
  1049. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1050. arr.push(el);
  1051. }
  1052. }
  1053. return arr;
  1054. }
  1055. function byClass(className, tag, root) {
  1056. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1057. if (root.getElementsByClassName) {
  1058. els = root.getElementsByClassName(stripslashes(className));
  1059. for (i = 0, len = els.length; i < len; i++) {
  1060. el = els[i];
  1061. if (cmpTag(tag, el.nodeName)) {
  1062. arr.push(el);
  1063. }
  1064. }
  1065. } else if (doc.querySelectorAll) {
  1066. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1067. for (i = 0, len = els.length; i < len; i++) {
  1068. el = els[i];
  1069. if (_contains(root, el)) {
  1070. arr.push(el);
  1071. }
  1072. }
  1073. } else {
  1074. els = root.getElementsByTagName(tag);
  1075. className = ' ' + className + ' ';
  1076. for (i = 0, len = els.length; i < len; i++) {
  1077. el = els[i];
  1078. if (el.nodeType == 1) {
  1079. var cls = el.className;
  1080. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1081. arr.push(el);
  1082. }
  1083. }
  1084. }
  1085. }
  1086. return arr;
  1087. }
  1088. function byName(name, tag, root) {
  1089. var arr = [], doc = root.ownerDocument || root,
  1090. els = doc.getElementsByName(stripslashes(name)), el;
  1091. for (var i = 0, len = els.length; i < len; i++) {
  1092. el = els[i];
  1093. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1094. if (el.getAttribute('name') !== null) {
  1095. arr.push(el);
  1096. }
  1097. }
  1098. }
  1099. return arr;
  1100. }
  1101. function byAttr(key, val, tag, root) {
  1102. var arr = [], els = root.getElementsByTagName(tag), el;
  1103. for (var i = 0, len = els.length; i < len; i++) {
  1104. el = els[i];
  1105. if (el.nodeType == 1) {
  1106. if (val === null) {
  1107. if (_getAttr(el, key) !== null) {
  1108. arr.push(el);
  1109. }
  1110. } else {
  1111. if (val === escape(_getAttr(el, key))) {
  1112. arr.push(el);
  1113. }
  1114. }
  1115. }
  1116. }
  1117. return arr;
  1118. }
  1119. function select(expr, root) {
  1120. var arr = [], matches;
  1121. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1122. var tag = matches ? matches[1] : '*';
  1123. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1124. arr = byId(matches[1], tag, root);
  1125. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1126. arr = byClass(matches[1], tag, root);
  1127. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1128. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1129. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1130. var key = matches[1].toLowerCase(), val = matches[2];
  1131. if (key === 'id') {
  1132. arr = byId(val, tag, root);
  1133. } else if (key === 'class') {
  1134. arr = byClass(val, tag, root);
  1135. } else if (key === 'name') {
  1136. arr = byName(val, tag, root);
  1137. } else {
  1138. arr = byAttr(key, val, tag, root);
  1139. }
  1140. } else {
  1141. var els = root.getElementsByTagName(tag), el;
  1142. for (var i = 0, len = els.length; i < len; i++) {
  1143. el = els[i];
  1144. if (el.nodeType == 1) {
  1145. arr.push(el);
  1146. }
  1147. }
  1148. }
  1149. return arr;
  1150. }
  1151. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1152. while ((arr = re.exec(expr))) {
  1153. if (arr[1] !== ' ') {
  1154. parts.push(arr[1]);
  1155. }
  1156. }
  1157. var results = [];
  1158. if (parts.length == 1) {
  1159. return select(parts[0], root);
  1160. }
  1161. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1162. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1163. part = parts[i];
  1164. if (part === '>') {
  1165. isChild = true;
  1166. continue;
  1167. }
  1168. if (i > 0) {
  1169. els = [];
  1170. for (j = 0, len = results.length; j < len; j++) {
  1171. val = results[j];
  1172. subResults = select(part, val);
  1173. for (k = 0, l = subResults.length; k < l; k++) {
  1174. v = subResults[k];
  1175. if (isChild) {
  1176. if (val === v.parentNode) {
  1177. els.push(v);
  1178. }
  1179. } else {
  1180. els.push(v);
  1181. }
  1182. }
  1183. }
  1184. results = els;
  1185. } else {
  1186. results = select(part, root);
  1187. }
  1188. if (results.length === 0) {
  1189. return [];
  1190. }
  1191. }
  1192. return results;
  1193. }
  1194. function _query(expr, root) {
  1195. var arr = _queryAll(expr, root);
  1196. return arr.length > 0 ? arr[0] : null;
  1197. }
  1198. K.query = _query;
  1199. K.queryAll = _queryAll;
  1200. function _get(val) {
  1201. return K(val)[0];
  1202. }
  1203. function _getDoc(node) {
  1204. if (!node) {
  1205. return document;
  1206. }
  1207. return node.ownerDocument || node.document || node;
  1208. }
  1209. function _getWin(node) {
  1210. if (!node) {
  1211. return window;
  1212. }
  1213. var doc = _getDoc(node);
  1214. return doc.parentWindow || doc.defaultView;
  1215. }
  1216. function _setHtml(el, html) {
  1217. if (el.nodeType != 1) {
  1218. return;
  1219. }
  1220. var doc = _getDoc(el);
  1221. try {
  1222. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1223. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1224. temp.parentNode.removeChild(temp);
  1225. } catch (e) {
  1226. K(el).empty();
  1227. K('@' + html, doc).each(function () {
  1228. el.appendChild(this);
  1229. });
  1230. }
  1231. }
  1232. function _hasClass(el, cls) {
  1233. return _inString(cls, el.className, ' ');
  1234. }
  1235. function _setAttr(el, key, val) {
  1236. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1237. key = 'className';
  1238. }
  1239. el.setAttribute(key, '' + val);
  1240. }
  1241. function _removeAttr(el, key) {
  1242. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1243. key = 'className';
  1244. }
  1245. _setAttr(el, key, '');
  1246. el.removeAttribute(key);
  1247. }
  1248. function _getNodeName(node) {
  1249. if (!node || !node.nodeName) {
  1250. return '';
  1251. }
  1252. return node.nodeName.toLowerCase();
  1253. }
  1254. function _computedCss(el, key) {
  1255. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1256. if (win.getComputedStyle) {
  1257. var style = win.getComputedStyle(el, null);
  1258. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1259. } else if (el.currentStyle) {
  1260. val = el.currentStyle[camelKey] || el.style[camelKey];
  1261. }
  1262. return val;
  1263. }
  1264. function _hasVal(node) {
  1265. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1266. }
  1267. function _docElement(doc) {
  1268. doc = doc || document;
  1269. return _QUIRKS ? doc.body : doc.documentElement;
  1270. }
  1271. function _docHeight(doc) {
  1272. var el = _docElement(doc);
  1273. return Math.max(el.scrollHeight, el.clientHeight);
  1274. }
  1275. function _docWidth(doc) {
  1276. var el = _docElement(doc);
  1277. return Math.max(el.scrollWidth, el.clientWidth);
  1278. }
  1279. function _getScrollPos(doc) {
  1280. doc = doc || document;
  1281. var x, y;
  1282. if (_IE || _NEWIE || _OPERA) {
  1283. x = _docElement(doc).scrollLeft;
  1284. y = _docElement(doc).scrollTop;
  1285. } else {
  1286. x = _getWin(doc).scrollX;
  1287. y = _getWin(doc).scrollY;
  1288. }
  1289. return {x: x, y: y};
  1290. }
  1291. function KNode(node) {
  1292. this.init(node);
  1293. }
  1294. _extend(KNode, {
  1295. init: function (node) {
  1296. var self = this;
  1297. node = _isArray(node) ? node : [node];
  1298. var length = 0;
  1299. for (var i = 0, len = node.length; i < len; i++) {
  1300. if (node[i]) {
  1301. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1302. length++;
  1303. }
  1304. }
  1305. self.length = length;
  1306. self.doc = _getDoc(self[0]);
  1307. self.name = _getNodeName(self[0]);
  1308. self.type = self.length > 0 ? self[0].nodeType : null;
  1309. self.win = _getWin(self[0]);
  1310. },
  1311. each: function (fn) {
  1312. var self = this;
  1313. for (var i = 0; i < self.length; i++) {
  1314. if (fn.call(self[i], i, self[i]) === false) {
  1315. return self;
  1316. }
  1317. }
  1318. return self;
  1319. },
  1320. bind: function (type, fn) {
  1321. this.each(function () {
  1322. _bind(this, type, fn);
  1323. });
  1324. return this;
  1325. },
  1326. unbind: function (type, fn) {
  1327. this.each(function () {
  1328. _unbind(this, type, fn);
  1329. });
  1330. return this;
  1331. },
  1332. fire: function (type) {
  1333. if (this.length < 1) {
  1334. return this;
  1335. }
  1336. _fire(this[0], type);
  1337. return this;
  1338. },
  1339. hasAttr: function (key) {
  1340. if (this.length < 1) {
  1341. return false;
  1342. }
  1343. return !!_getAttr(this[0], key);
  1344. },
  1345. attr: function (key, val) {
  1346. var self = this;
  1347. if (key === undefined) {
  1348. return _getAttrList(self.outer());
  1349. }
  1350. if (typeof key === 'object') {
  1351. _each(key, function (k, v) {
  1352. self.attr(k, v);
  1353. });
  1354. return self;
  1355. }
  1356. if (val === undefined) {
  1357. val = self.length < 1 ? null : _getAttr(self[0], key);
  1358. return val === null ? '' : val;
  1359. }
  1360. self.each(function () {
  1361. _setAttr(this, key, val);
  1362. });
  1363. return self;
  1364. },
  1365. removeAttr: function (key) {
  1366. this.each(function () {
  1367. _removeAttr(this, key);
  1368. });
  1369. return this;
  1370. },
  1371. get: function (i) {
  1372. if (this.length < 1) {
  1373. return null;
  1374. }
  1375. return this[i || 0];
  1376. },
  1377. eq: function (i) {
  1378. if (this.length < 1) {
  1379. return null;
  1380. }
  1381. return this[i] ? new KNode(this[i]) : null;
  1382. },
  1383. hasClass: function (cls) {
  1384. if (this.length < 1) {
  1385. return false;
  1386. }
  1387. return _hasClass(this[0], cls);
  1388. },
  1389. addClass: function (cls) {
  1390. this.each(function () {
  1391. if (!_hasClass(this, cls)) {
  1392. this.className = _trim(this.className + ' ' + cls);
  1393. }
  1394. });
  1395. return this;
  1396. },
  1397. removeClass: function (cls) {
  1398. this.each(function () {
  1399. if (_hasClass(this, cls)) {
  1400. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1401. }
  1402. });
  1403. return this;
  1404. },
  1405. html: function (val) {
  1406. var self = this;
  1407. if (val === undefined) {
  1408. if (self.length < 1 || self.type != 1) {
  1409. return '';
  1410. }
  1411. return _formatHtml(self[0].innerHTML);
  1412. }
  1413. self.each(function () {
  1414. _setHtml(this, val);
  1415. });
  1416. return self;
  1417. },
  1418. text: function () {
  1419. var self = this;
  1420. if (self.length < 1) {
  1421. return '';
  1422. }
  1423. return _IE ? self[0].innerText : self[0].textContent;
  1424. },
  1425. hasVal: function () {
  1426. if (this.length < 1) {
  1427. return false;
  1428. }
  1429. return _hasVal(this[0]);
  1430. },
  1431. val: function (val) {
  1432. var self = this;
  1433. if (val === undefined) {
  1434. if (self.length < 1) {
  1435. return '';
  1436. }
  1437. return self.hasVal() ? self[0].value : self.attr('value');
  1438. } else {
  1439. self.each(function () {
  1440. if (_hasVal(this)) {
  1441. this.value = val;
  1442. } else {
  1443. _setAttr(this, 'value', val);
  1444. }
  1445. });
  1446. return self;
  1447. }
  1448. },
  1449. css: function (key, val) {
  1450. var self = this;
  1451. if (key === undefined) {
  1452. return _getCssList(self.attr('style'));
  1453. }
  1454. if (typeof key === 'object') {
  1455. _each(key, function (k, v) {
  1456. self.css(k, v);
  1457. });
  1458. return self;
  1459. }
  1460. if (val === undefined) {
  1461. if (self.length < 1) {
  1462. return '';
  1463. }
  1464. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1465. }
  1466. self.each(function () {
  1467. this.style[_toCamel(key)] = val;
  1468. });
  1469. return self;
  1470. },
  1471. width: function (val) {
  1472. var self = this;
  1473. if (val === undefined) {
  1474. if (self.length < 1) {
  1475. return 0;
  1476. }
  1477. return self[0].offsetWidth;
  1478. }
  1479. return self.css('width', _addUnit(val));
  1480. },
  1481. height: function (val) {
  1482. var self = this;
  1483. if (val === undefined) {
  1484. if (self.length < 1) {
  1485. return 0;
  1486. }
  1487. return self[0].offsetHeight;
  1488. }
  1489. return self.css('height', _addUnit(val));
  1490. },
  1491. opacity: function (val) {
  1492. this.each(function () {
  1493. if (this.style.opacity === undefined) {
  1494. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1495. } else {
  1496. this.style.opacity = val == 1 ? '' : val;
  1497. }
  1498. });
  1499. return this;
  1500. },
  1501. data: function (key, val) {
  1502. var self = this;
  1503. key = 'kindeditor_data_' + key;
  1504. if (val === undefined) {
  1505. if (self.length < 1) {
  1506. return null;
  1507. }
  1508. return self[0][key];
  1509. }
  1510. this.each(function () {
  1511. this[key] = val;
  1512. });
  1513. return self;
  1514. },
  1515. pos: function () {
  1516. var self = this, node = self[0], x = 0, y = 0;
  1517. if (node) {
  1518. if (node.getBoundingClientRect) {
  1519. var box = node.getBoundingClientRect(),
  1520. pos = _getScrollPos(self.doc);
  1521. x = box.left + pos.x;
  1522. y = box.top + pos.y;
  1523. } else {
  1524. while (node) {
  1525. x += node.offsetLeft;
  1526. y += node.offsetTop;
  1527. node = node.offsetParent;
  1528. }
  1529. }
  1530. }
  1531. return {x: _round(x), y: _round(y)};
  1532. },
  1533. clone: function (bool) {
  1534. if (this.length < 1) {
  1535. return new KNode([]);
  1536. }
  1537. return new KNode(this[0].cloneNode(bool));
  1538. },
  1539. append: function (expr) {
  1540. this.each(function () {
  1541. if (this.appendChild) {
  1542. this.appendChild(_get(expr));
  1543. }
  1544. });
  1545. return this;
  1546. },
  1547. appendTo: function (expr) {
  1548. this.each(function () {
  1549. _get(expr).appendChild(this);
  1550. });
  1551. return this;
  1552. },
  1553. before: function (expr) {
  1554. this.each(function () {
  1555. this.parentNode.insertBefore(_get(expr), this);
  1556. });
  1557. return this;
  1558. },
  1559. after: function (expr) {
  1560. this.each(function () {
  1561. if (this.nextSibling) {
  1562. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1563. } else {
  1564. this.parentNode.appendChild(_get(expr));
  1565. }
  1566. });
  1567. return this;
  1568. },
  1569. replaceWith: function (expr) {
  1570. var nodes = [];
  1571. this.each(function (i, node) {
  1572. _unbind(node);
  1573. var newNode = _get(expr);
  1574. node.parentNode.replaceChild(newNode, node);
  1575. nodes.push(newNode);
  1576. });
  1577. return K(nodes);
  1578. },
  1579. empty: function () {
  1580. var self = this;
  1581. self.each(function (i, node) {
  1582. var child = node.firstChild;
  1583. while (child) {
  1584. if (!node.parentNode) {
  1585. return;
  1586. }
  1587. var next = child.nextSibling;
  1588. child.parentNode.removeChild(child);
  1589. child = next;
  1590. }
  1591. });
  1592. return self;
  1593. },
  1594. remove: function (keepChilds) {
  1595. var self = this;
  1596. self.each(function (i, node) {
  1597. if (!node.parentNode) {
  1598. return;
  1599. }
  1600. _unbind(node);
  1601. if (keepChilds) {
  1602. var child = node.firstChild;
  1603. while (child) {
  1604. var next = child.nextSibling;
  1605. node.parentNode.insertBefore(child, node);
  1606. child = next;
  1607. }
  1608. }
  1609. node.parentNode.removeChild(node);
  1610. delete self[i];
  1611. });
  1612. self.length = 0;
  1613. return self;
  1614. },
  1615. show: function (val) {
  1616. var self = this;
  1617. if (val === undefined) {
  1618. val = self._originDisplay || '';
  1619. }
  1620. if (self.css('display') != 'none') {
  1621. return self;
  1622. }
  1623. return self.css('display', val);
  1624. },
  1625. hide: function () {
  1626. var self = this;
  1627. if (self.length < 1) {
  1628. return self;
  1629. }
  1630. self._originDisplay = self[0].style.display;
  1631. return self.css('display', 'none');
  1632. },
  1633. outer: function () {
  1634. var self = this;
  1635. if (self.length < 1) {
  1636. return '';
  1637. }
  1638. var div = self.doc.createElement('div'), html;
  1639. div.appendChild(self[0].cloneNode(true));
  1640. html = _formatHtml(div.innerHTML);
  1641. div = null;
  1642. return html;
  1643. },
  1644. isSingle: function () {
  1645. return !!_SINGLE_TAG_MAP[this.name];
  1646. },
  1647. isInline: function () {
  1648. return !!_INLINE_TAG_MAP[this.name];
  1649. },
  1650. isBlock: function () {
  1651. return !!_BLOCK_TAG_MAP[this.name];
  1652. },
  1653. isStyle: function () {
  1654. return !!_STYLE_TAG_MAP[this.name];
  1655. },
  1656. isControl: function () {
  1657. return !!_CONTROL_TAG_MAP[this.name];
  1658. },
  1659. contains: function (otherNode) {
  1660. if (this.length < 1) {
  1661. return false;
  1662. }
  1663. return _contains(this[0], _get(otherNode));
  1664. },
  1665. parent: function () {
  1666. if (this.length < 1) {
  1667. return null;
  1668. }
  1669. var node = this[0].parentNode;
  1670. return node ? new KNode(node) : null;
  1671. },
  1672. children: function () {
  1673. if (this.length < 1) {
  1674. return new KNode([]);
  1675. }
  1676. var list = [], child = this[0].firstChild;
  1677. while (child) {
  1678. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1679. list.push(child);
  1680. }
  1681. child = child.nextSibling;
  1682. }
  1683. return new KNode(list);
  1684. },
  1685. first: function () {
  1686. var list = this.children();
  1687. return list.length > 0 ? list.eq(0) : null;
  1688. },
  1689. last: function () {
  1690. var list = this.children();
  1691. return list.length > 0 ? list.eq(list.length - 1) : null;
  1692. },
  1693. index: function () {
  1694. if (this.length < 1) {
  1695. return -1;
  1696. }
  1697. var i = -1, sibling = this[0];
  1698. while (sibling) {
  1699. i++;
  1700. sibling = sibling.previousSibling;
  1701. }
  1702. return i;
  1703. },
  1704. prev: function () {
  1705. if (this.length < 1) {
  1706. return null;
  1707. }
  1708. var node = this[0].previousSibling;
  1709. return node ? new KNode(node) : null;
  1710. },
  1711. next: function () {
  1712. if (this.length < 1) {
  1713. return null;
  1714. }
  1715. var node = this[0].nextSibling;
  1716. return node ? new KNode(node) : null;
  1717. },
  1718. scan: function (fn, order) {
  1719. if (this.length < 1) {
  1720. return;
  1721. }
  1722. order = (order === undefined) ? true : order;
  1723. function walk(node) {
  1724. var n = order ? node.firstChild : node.lastChild;
  1725. while (n) {
  1726. var next = order ? n.nextSibling : n.previousSibling;
  1727. if (fn(n) === false) {
  1728. return false;
  1729. }
  1730. if (walk(n) === false) {
  1731. return false;
  1732. }
  1733. n = next;
  1734. }
  1735. }
  1736. walk(this[0]);
  1737. return this;
  1738. }
  1739. });
  1740. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1741. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1742. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function (i, type) {
  1743. KNode.prototype[type] = function (fn) {
  1744. return fn ? this.bind(type, fn) : this.fire(type);
  1745. };
  1746. });
  1747. var _K = K;
  1748. K = function (expr, root) {
  1749. if (expr === undefined || expr === null) {
  1750. return;
  1751. }
  1752. function newNode(node) {
  1753. if (!node[0]) {
  1754. node = [];
  1755. }
  1756. return new KNode(node);
  1757. }
  1758. if (typeof expr === 'string') {
  1759. if (root) {
  1760. root = _get(root);
  1761. }
  1762. var length = expr.length;
  1763. if (expr.charAt(0) === '@') {
  1764. expr = expr.substr(1);
  1765. }
  1766. if (expr.length !== length || /<.+>/.test(expr)) {
  1767. var doc = root ? root.ownerDocument || root : document,
  1768. div = doc.createElement('div'), list = [];
  1769. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1770. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1771. var child = div.childNodes[i];
  1772. if (child.id == '__kindeditor_temp_tag__') {
  1773. continue;
  1774. }
  1775. list.push(child);
  1776. }
  1777. return newNode(list);
  1778. }
  1779. return newNode(_queryAll(expr, root));
  1780. }
  1781. if (expr && expr.constructor === KNode) {
  1782. return expr;
  1783. }
  1784. if (expr.toArray) {
  1785. expr = expr.toArray();
  1786. }
  1787. if (_isArray(expr)) {
  1788. return newNode(expr);
  1789. }
  1790. return newNode(_toArray(arguments));
  1791. };
  1792. _each(_K, function (key, val) {
  1793. K[key] = val;
  1794. });
  1795. K.NodeClass = KNode;
  1796. window.KindEditor = K;
  1797. var _START_TO_START = 0,
  1798. _START_TO_END = 1,
  1799. _END_TO_END = 2,
  1800. _END_TO_START = 3,
  1801. _BOOKMARK_ID = 0;
  1802. function _updateCollapsed(range) {
  1803. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1804. return range;
  1805. }
  1806. function _copyAndDelete(range, isCopy, isDelete) {
  1807. var doc = range.doc, nodeList = [];
  1808. function splitTextNode(node, startOffset, endOffset) {
  1809. var length = node.nodeValue.length, centerNode;
  1810. if (isCopy) {
  1811. var cloneNode = node.cloneNode(true);
  1812. if (startOffset > 0) {
  1813. centerNode = cloneNode.splitText(startOffset);
  1814. } else {
  1815. centerNode = cloneNode;
  1816. }
  1817. if (endOffset < length) {
  1818. centerNode.splitText(endOffset - startOffset);
  1819. }
  1820. }
  1821. if (isDelete) {
  1822. var center = node;
  1823. if (startOffset > 0) {
  1824. center = node.splitText(startOffset);
  1825. range.setStart(node, startOffset);
  1826. }
  1827. if (endOffset < length) {
  1828. var right = center.splitText(endOffset - startOffset);
  1829. range.setEnd(right, 0);
  1830. }
  1831. nodeList.push(center);
  1832. }
  1833. return centerNode;
  1834. }
  1835. function removeNodes() {
  1836. if (isDelete) {
  1837. range.up().collapse(true);
  1838. }
  1839. for (var i = 0, len = nodeList.length; i < len; i++) {
  1840. var node = nodeList[i];
  1841. if (node.parentNode) {
  1842. node.parentNode.removeChild(node);
  1843. }
  1844. }
  1845. }
  1846. var copyRange = range.cloneRange().down();
  1847. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1848. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1849. if (ancestor.nodeType == 3) {
  1850. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1851. if (isCopy) {
  1852. frag.appendChild(textNode);
  1853. }
  1854. removeNodes();
  1855. return isCopy ? frag : range;
  1856. }
  1857. function extractNodes(parent, frag) {
  1858. var node = parent.firstChild, nextNode;
  1859. while (node) {
  1860. var testRange = new KRange(doc).selectNode(node);
  1861. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1862. if (start >= 0 && incStart <= 0) {
  1863. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1864. }
  1865. if (incStart >= 0 && incEnd <= 0) {
  1866. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1867. }
  1868. if (incEnd >= 0 && end <= 0) {
  1869. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1870. }
  1871. if (end >= 0) {
  1872. return false;
  1873. }
  1874. nextNode = node.nextSibling;
  1875. if (start > 0) {
  1876. if (node.nodeType == 1) {
  1877. if (incStart >= 0 && incEnd <= 0) {
  1878. if (isCopy) {
  1879. frag.appendChild(node.cloneNode(true));
  1880. }
  1881. if (isDelete) {
  1882. nodeList.push(node);
  1883. }
  1884. } else {
  1885. var childFlag;
  1886. if (isCopy) {
  1887. childFlag = node.cloneNode(false);
  1888. frag.appendChild(childFlag);
  1889. }
  1890. if (extractNodes(node, childFlag) === false) {
  1891. return false;
  1892. }
  1893. }
  1894. } else if (node.nodeType == 3) {
  1895. var textNode;
  1896. if (node == copyRange.startContainer) {
  1897. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1898. } else if (node == copyRange.endContainer) {
  1899. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1900. } else {
  1901. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1902. }
  1903. if (isCopy) {
  1904. try {
  1905. frag.appendChild(textNode);
  1906. } catch (e) {
  1907. }
  1908. }
  1909. }
  1910. }
  1911. node = nextNode;
  1912. }
  1913. }
  1914. extractNodes(ancestor, frag);
  1915. if (isDelete) {
  1916. range.up().collapse(true);
  1917. }
  1918. for (var i = 0, len = nodeList.length; i < len; i++) {
  1919. var node = nodeList[i];
  1920. if (node.parentNode) {
  1921. node.parentNode.removeChild(node);
  1922. }
  1923. }
  1924. return isCopy ? frag : range;
  1925. }
  1926. function _moveToElementText(range, el) {
  1927. var node = el;
  1928. while (node) {
  1929. var knode = K(node);
  1930. if (knode.name == 'marquee' || knode.name == 'select') {
  1931. return;
  1932. }
  1933. node = node.parentNode;
  1934. }
  1935. try {
  1936. range.moveToElementText(el);
  1937. } catch (e) {
  1938. }
  1939. }
  1940. function _getStartEnd(rng, isStart) {
  1941. var doc = rng.parentElement().ownerDocument,
  1942. pointRange = rng.duplicate();
  1943. pointRange.collapse(isStart);
  1944. var parent = pointRange.parentElement(),
  1945. nodes = parent.childNodes;
  1946. if (nodes.length === 0) {
  1947. return {node: parent.parentNode, offset: K(parent).index()};
  1948. }
  1949. var startNode = doc, startPos = 0, cmp = -1;
  1950. var testRange = rng.duplicate();
  1951. _moveToElementText(testRange, parent);
  1952. for (var i = 0, len = nodes.length; i < len; i++) {
  1953. var node = nodes[i];
  1954. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1955. if (cmp === 0) {
  1956. return {node: node.parentNode, offset: i};
  1957. }
  1958. if (node.nodeType == 1) {
  1959. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1960. if (knode.isControl()) {
  1961. dummy = doc.createElement('span');
  1962. knode.after(dummy);
  1963. newNode = dummy;
  1964. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1965. }
  1966. _moveToElementText(nodeRange, newNode);
  1967. testRange.setEndPoint('StartToEnd', nodeRange);
  1968. if (cmp > 0) {
  1969. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1970. } else {
  1971. startPos = 0;
  1972. }
  1973. if (dummy) {
  1974. K(dummy).remove();
  1975. }
  1976. } else if (node.nodeType == 3) {
  1977. testRange.moveStart('character', node.nodeValue.length);
  1978. startPos += node.nodeValue.length;
  1979. }
  1980. if (cmp < 0) {
  1981. startNode = node;
  1982. }
  1983. }
  1984. if (cmp < 0 && startNode.nodeType == 1) {
  1985. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1986. }
  1987. if (cmp > 0) {
  1988. while (startNode.nextSibling && startNode.nodeType == 1) {
  1989. startNode = startNode.nextSibling;
  1990. }
  1991. }
  1992. testRange = rng.duplicate();
  1993. _moveToElementText(testRange, parent);
  1994. testRange.setEndPoint('StartToEnd', pointRange);
  1995. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1996. if (cmp > 0 && startNode.nodeType == 3) {
  1997. var prevNode = startNode.previousSibling;
  1998. while (prevNode && prevNode.nodeType == 3) {
  1999. startPos -= prevNode.nodeValue.length;
  2000. prevNode = prevNode.previousSibling;
  2001. }
  2002. }
  2003. return {node: startNode, offset: startPos};
  2004. }
  2005. function _getEndRange(node, offset) {
  2006. var doc = node.ownerDocument || node,
  2007. range = doc.body.createTextRange();
  2008. if (doc == node) {
  2009. range.collapse(true);
  2010. return range;
  2011. }
  2012. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2013. var children = node.childNodes, isStart, child;
  2014. if (offset === 0) {
  2015. child = children[0];
  2016. isStart = true;
  2017. } else {
  2018. child = children[offset - 1];
  2019. isStart = false;
  2020. }
  2021. if (!child) {
  2022. return range;
  2023. }
  2024. if (K(child).name === 'head') {
  2025. if (offset === 1) {
  2026. isStart = true;
  2027. }
  2028. if (offset === 2) {
  2029. isStart = false;
  2030. }
  2031. range.collapse(isStart);
  2032. return range;
  2033. }
  2034. if (child.nodeType == 1) {
  2035. var kchild = K(child), span;
  2036. if (kchild.isControl()) {
  2037. span = doc.createElement('span');
  2038. if (isStart) {
  2039. kchild.before(span);
  2040. } else {
  2041. kchild.after(span);
  2042. }
  2043. child = span;
  2044. }
  2045. _moveToElementText(range, child);
  2046. range.collapse(isStart);
  2047. if (span) {
  2048. K(span).remove();
  2049. }
  2050. return range;
  2051. }
  2052. node = child;
  2053. offset = isStart ? 0 : child.nodeValue.length;
  2054. }
  2055. var dummy = doc.createElement('span');
  2056. K(node).before(dummy);
  2057. _moveToElementText(range, dummy);
  2058. range.moveStart('character', offset);
  2059. K(dummy).remove();
  2060. return range;
  2061. }
  2062. function _toRange(rng) {
  2063. var doc, range;
  2064. function tr2td(start) {
  2065. if (K(start.node).name == 'tr') {
  2066. start.node = start.node.cells[start.offset];
  2067. start.offset = 0;
  2068. }
  2069. }
  2070. if (_IERANGE) {
  2071. if (rng.item) {
  2072. doc = _getDoc(rng.item(0));
  2073. range = new KRange(doc);
  2074. range.selectNode(rng.item(0));
  2075. return range;
  2076. }
  2077. doc = rng.parentElement().ownerDocument;
  2078. var start = _getStartEnd(rng, true),
  2079. end = _getStartEnd(rng, false);
  2080. tr2td(start);
  2081. tr2td(end);
  2082. range = new KRange(doc);
  2083. range.setStart(start.node, start.offset);
  2084. range.setEnd(end.node, end.offset);
  2085. return range;
  2086. }
  2087. var startContainer = rng.startContainer;
  2088. doc = startContainer.ownerDocument || startContainer;
  2089. range = new KRange(doc);
  2090. range.setStart(startContainer, rng.startOffset);
  2091. range.setEnd(rng.endContainer, rng.endOffset);
  2092. return range;
  2093. }
  2094. function KRange(doc) {
  2095. this.init(doc);
  2096. }
  2097. _extend(KRange, {
  2098. init: function (doc) {
  2099. var self = this;
  2100. self.startContainer = doc;
  2101. self.startOffset = 0;
  2102. self.endContainer = doc;
  2103. self.endOffset = 0;
  2104. self.collapsed = true;
  2105. self.doc = doc;
  2106. },
  2107. commonAncestor: function () {
  2108. function getParents(node) {
  2109. var parents = [];
  2110. while (node) {
  2111. parents.push(node);
  2112. node = node.parentNode;
  2113. }
  2114. return parents;
  2115. }
  2116. var parentsA = getParents(this.startContainer),
  2117. parentsB = getParents(this.endContainer),
  2118. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2119. while (++i) {
  2120. parentA = parentsA[lenA - i];
  2121. parentB = parentsB[lenB - i];
  2122. if (!parentA || !parentB || parentA !== parentB) {
  2123. break;
  2124. }
  2125. }
  2126. return parentsA[lenA - i + 1];
  2127. },
  2128. setStart: function (node, offset) {
  2129. var self = this, doc = self.doc;
  2130. self.startContainer = node;
  2131. self.startOffset = offset;
  2132. if (self.endContainer === doc) {
  2133. self.endContainer = node;
  2134. self.endOffset = offset;
  2135. }
  2136. return _updateCollapsed(this);
  2137. },
  2138. setEnd: function (node, offset) {
  2139. var self = this, doc = self.doc;
  2140. self.endContainer = node;
  2141. self.endOffset = offset;
  2142. if (self.startContainer === doc) {
  2143. self.startContainer = node;
  2144. self.startOffset = offset;
  2145. }
  2146. return _updateCollapsed(this);
  2147. },
  2148. setStartBefore: function (node) {
  2149. return this.setStart(node.parentNode || this.doc, K(node).index());
  2150. },
  2151. setStartAfter: function (node) {
  2152. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2153. },
  2154. setEndBefore: function (node) {
  2155. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2156. },
  2157. setEndAfter: function (node) {
  2158. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2159. },
  2160. selectNode: function (node) {
  2161. return this.setStartBefore(node).setEndAfter(node);
  2162. },
  2163. selectNodeContents: function (node) {
  2164. var knode = K(node);
  2165. if (knode.type == 3 || knode.isSingle()) {
  2166. return this.selectNode(node);
  2167. }
  2168. var children = knode.children();
  2169. if (children.length > 0) {
  2170. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2171. }
  2172. return this.setStart(node, 0).setEnd(node, 0);
  2173. },
  2174. collapse: function (toStart) {
  2175. if (toStart) {
  2176. return this.setEnd(this.startContainer, this.startOffset);
  2177. }
  2178. return this.setStart(this.endContainer, this.endOffset);
  2179. },
  2180. compareBoundaryPoints: function (how, range) {
  2181. var rangeA = this.get(), rangeB = range.get();
  2182. if (_IERANGE) {
  2183. var arr = {};
  2184. arr[_START_TO_START] = 'StartToStart';
  2185. arr[_START_TO_END] = 'EndToStart';
  2186. arr[_END_TO_END] = 'EndToEnd';
  2187. arr[_END_TO_START] = 'StartToEnd';
  2188. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2189. if (cmp !== 0) {
  2190. return cmp;
  2191. }
  2192. var nodeA, nodeB, nodeC, posA, posB;
  2193. if (how === _START_TO_START || how === _END_TO_START) {
  2194. nodeA = this.startContainer;
  2195. posA = this.startOffset;
  2196. }
  2197. if (how === _START_TO_END || how === _END_TO_END) {
  2198. nodeA = this.endContainer;
  2199. posA = this.endOffset;
  2200. }
  2201. if (how === _START_TO_START || how === _START_TO_END) {
  2202. nodeB = range.startContainer;
  2203. posB = range.startOffset;
  2204. }
  2205. if (how === _END_TO_END || how === _END_TO_START) {
  2206. nodeB = range.endContainer;
  2207. posB = range.endOffset;
  2208. }
  2209. if (nodeA === nodeB) {
  2210. var diff = posA - posB;
  2211. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2212. }
  2213. nodeC = nodeB;
  2214. while (nodeC && nodeC.parentNode !== nodeA) {
  2215. nodeC = nodeC.parentNode;
  2216. }
  2217. if (nodeC) {
  2218. return K(nodeC).index() >= posA ? -1 : 1;
  2219. }
  2220. nodeC = nodeA;
  2221. while (nodeC && nodeC.parentNode !== nodeB) {
  2222. nodeC = nodeC.parentNode;
  2223. }
  2224. if (nodeC) {
  2225. return K(nodeC).index() >= posB ? 1 : -1;
  2226. }
  2227. nodeC = K(nodeB).next();
  2228. if (nodeC && nodeC.contains(nodeA)) {
  2229. return 1;
  2230. }
  2231. nodeC = K(nodeA).next();
  2232. if (nodeC && nodeC.contains(nodeB)) {
  2233. return -1;
  2234. }
  2235. } else {
  2236. return rangeA.compareBoundaryPoints(how, rangeB);
  2237. }
  2238. },
  2239. cloneRange: function () {
  2240. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2241. },
  2242. toString: function () {
  2243. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2244. return str.replace(/\r\n|\n|\r/g, '');
  2245. },
  2246. cloneContents: function () {
  2247. return _copyAndDelete(this, true, false);
  2248. },
  2249. deleteContents: function () {
  2250. return _copyAndDelete(this, false, true);
  2251. },
  2252. extractContents: function () {
  2253. return _copyAndDelete(this, true, true);
  2254. },
  2255. insertNode: function (node) {
  2256. var self = this,
  2257. sc = self.startContainer, so = self.startOffset,
  2258. ec = self.endContainer, eo = self.endOffset,
  2259. firstChild, lastChild, c, nodeCount = 1;
  2260. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2261. firstChild = node.firstChild;
  2262. lastChild = node.lastChild;
  2263. nodeCount = node.childNodes.length;
  2264. }
  2265. if (sc.nodeType == 1) {
  2266. c = sc.childNodes[so];
  2267. if (c) {
  2268. sc.insertBefore(node, c);
  2269. if (sc === ec) {
  2270. eo += nodeCount;
  2271. }
  2272. } else {
  2273. sc.appendChild(node);
  2274. }
  2275. } else if (sc.nodeType == 3) {
  2276. if (so === 0) {
  2277. sc.parentNode.insertBefore(node, sc);
  2278. if (sc.parentNode === ec) {
  2279. eo += nodeCount;
  2280. }
  2281. } else if (so >= sc.nodeValue.length) {
  2282. if (sc.nextSibling) {
  2283. sc.parentNode.insertBefore(node, sc.nextSibling);
  2284. } else {
  2285. sc.parentNode.appendChild(node);
  2286. }
  2287. } else {
  2288. if (so > 0) {
  2289. c = sc.splitText(so);
  2290. } else {
  2291. c = sc;
  2292. }
  2293. sc.parentNode.insertBefore(node, c);
  2294. if (sc === ec) {
  2295. ec = c;
  2296. eo -= so;
  2297. }
  2298. }
  2299. }
  2300. if (firstChild) {
  2301. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2302. } else {
  2303. self.selectNode(node);
  2304. }
  2305. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2306. return self;
  2307. }
  2308. return self.setEnd(ec, eo);
  2309. },
  2310. surroundContents: function (node) {
  2311. node.appendChild(this.extractContents());
  2312. return this.insertNode(node).selectNode(node);
  2313. },
  2314. isControl: function () {
  2315. var self = this,
  2316. sc = self.startContainer, so = self.startOffset,
  2317. ec = self.endContainer, eo = self.endOffset, rng;
  2318. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2319. },
  2320. get: function (hasControlRange) {
  2321. var self = this, doc = self.doc, node, rng;
  2322. if (!_IERANGE) {
  2323. rng = doc.createRange();
  2324. try {
  2325. rng.setStart(self.startContainer, self.startOffset);
  2326. rng.setEnd(self.endContainer, self.endOffset);
  2327. } catch (e) {
  2328. }
  2329. return rng;
  2330. }
  2331. if (hasControlRange && self.isControl()) {
  2332. rng = doc.body.createControlRange();
  2333. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2334. return rng;
  2335. }
  2336. var range = self.cloneRange().down();
  2337. rng = doc.body.createTextRange();
  2338. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2339. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2340. return rng;
  2341. },
  2342. html: function () {
  2343. return K(this.cloneContents()).outer();
  2344. },
  2345. down: function () {
  2346. var self = this;
  2347. function downPos(node, pos, isStart) {
  2348. if (node.nodeType != 1) {
  2349. return;
  2350. }
  2351. var children = K(node).children();
  2352. if (children.length === 0) {
  2353. return;
  2354. }
  2355. var left, right, child, offset;
  2356. if (pos > 0) {
  2357. left = children.eq(pos - 1);
  2358. }
  2359. if (pos < children.length) {
  2360. right = children.eq(pos);
  2361. }
  2362. if (left && left.type == 3) {
  2363. child = left[0];
  2364. offset = child.nodeValue.length;
  2365. }
  2366. if (right && right.type == 3) {
  2367. child = right[0];
  2368. offset = 0;
  2369. }
  2370. if (!child) {
  2371. return;
  2372. }
  2373. if (isStart) {
  2374. self.setStart(child, offset);
  2375. } else {
  2376. self.setEnd(child, offset);
  2377. }
  2378. }
  2379. downPos(self.startContainer, self.startOffset, true);
  2380. downPos(self.endContainer, self.endOffset, false);
  2381. return self;
  2382. },
  2383. up: function () {
  2384. var self = this;
  2385. function upPos(node, pos, isStart) {
  2386. if (node.nodeType != 3) {
  2387. return;
  2388. }
  2389. if (pos === 0) {
  2390. if (isStart) {
  2391. self.setStartBefore(node);
  2392. } else {
  2393. self.setEndBefore(node);
  2394. }
  2395. } else if (pos == node.nodeValue.length) {
  2396. if (isStart) {
  2397. self.setStartAfter(node);
  2398. } else {
  2399. self.setEndAfter(node);
  2400. }
  2401. }
  2402. }
  2403. upPos(self.startContainer, self.startOffset, true);
  2404. upPos(self.endContainer, self.endOffset, false);
  2405. return self;
  2406. },
  2407. enlarge: function (toBlock) {
  2408. var self = this;
  2409. self.up();
  2410. function enlargePos(node, pos, isStart) {
  2411. var knode = K(node), parent;
  2412. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2413. return;
  2414. }
  2415. if (pos === 0) {
  2416. while (!knode.prev()) {
  2417. parent = knode.parent();
  2418. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2419. break;
  2420. }
  2421. knode = parent;
  2422. }
  2423. if (isStart) {
  2424. self.setStartBefore(knode[0]);
  2425. } else {
  2426. self.setEndBefore(knode[0]);
  2427. }
  2428. } else if (pos == knode.children().length) {
  2429. while (!knode.next()) {
  2430. parent = knode.parent();
  2431. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2432. break;
  2433. }
  2434. knode = parent;
  2435. }
  2436. if (isStart) {
  2437. self.setStartAfter(knode[0]);
  2438. } else {
  2439. self.setEndAfter(knode[0]);
  2440. }
  2441. }
  2442. }
  2443. enlargePos(self.startContainer, self.startOffset, true);
  2444. enlargePos(self.endContainer, self.endOffset, false);
  2445. return self;
  2446. },
  2447. shrink: function () {
  2448. var self = this, child, collapsed = self.collapsed;
  2449. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2450. self.setStart(child, 0);
  2451. }
  2452. if (collapsed) {
  2453. return self.collapse(collapsed);
  2454. }
  2455. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2456. self.setEnd(child, child.childNodes.length);
  2457. }
  2458. return self;
  2459. },
  2460. createBookmark: function (serialize) {
  2461. var self = this, doc = self.doc, endNode,
  2462. startNode = K('<span style="display:none;"></span>', doc)[0];
  2463. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2464. if (!self.collapsed) {
  2465. endNode = startNode.cloneNode(true);
  2466. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2467. }
  2468. if (endNode) {
  2469. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2470. }
  2471. self.insertNode(startNode).setStartAfter(startNode);
  2472. return {
  2473. start: serialize ? '#' + startNode.id : startNode,
  2474. end: endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2475. };
  2476. },
  2477. moveToBookmark: function (bookmark) {
  2478. var self = this, doc = self.doc,
  2479. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2480. if (!start || start.length < 1) {
  2481. return self;
  2482. }
  2483. self.setStartBefore(start[0]);
  2484. start.remove();
  2485. if (end && end.length > 0) {
  2486. self.setEndBefore(end[0]);
  2487. end.remove();
  2488. } else {
  2489. self.collapse(true);
  2490. }
  2491. return self;
  2492. },
  2493. dump: function () {
  2494. console.log('--------------------');
  2495. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2496. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2497. }
  2498. });
  2499. function _range(mixed) {
  2500. if (!mixed.nodeName) {
  2501. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2502. }
  2503. return new KRange(mixed);
  2504. }
  2505. K.RangeClass = KRange;
  2506. K.range = _range;
  2507. K.START_TO_START = _START_TO_START;
  2508. K.START_TO_END = _START_TO_END;
  2509. K.END_TO_END = _END_TO_END;
  2510. K.END_TO_START = _END_TO_START;
  2511. function _nativeCommand(doc, key, val) {
  2512. try {
  2513. doc.execCommand(key, false, val);
  2514. } catch (e) {
  2515. }
  2516. }
  2517. function _nativeCommandValue(doc, key) {
  2518. var val = '';
  2519. try {
  2520. val = doc.queryCommandValue(key);
  2521. } catch (e) {
  2522. }
  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. }
  2542. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2543. return null;
  2544. }
  2545. return rng;
  2546. }
  2547. function _singleKeyMap(map) {
  2548. var newMap = {}, arr, v;
  2549. _each(map, function (key, val) {
  2550. arr = key.split(',');
  2551. for (var i = 0, len = arr.length; i < len; i++) {
  2552. v = arr[i];
  2553. newMap[v] = val;
  2554. }
  2555. });
  2556. return newMap;
  2557. }
  2558. function _hasAttrOrCss(knode, map) {
  2559. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2560. }
  2561. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2562. mapKey = mapKey || knode.name;
  2563. if (knode.type !== 1) {
  2564. return false;
  2565. }
  2566. var newMap = _singleKeyMap(map);
  2567. if (!newMap[mapKey]) {
  2568. return false;
  2569. }
  2570. var arr = newMap[mapKey].split(',');
  2571. for (var i = 0, len = arr.length; i < len; i++) {
  2572. var key = arr[i];
  2573. if (key === '*') {
  2574. return true;
  2575. }
  2576. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2577. var method = match[1] ? 'css' : 'attr';
  2578. key = match[2];
  2579. var val = match[3] || '';
  2580. if (val === '' && knode[method](key) !== '') {
  2581. return true;
  2582. }
  2583. if (val !== '' && knode[method](key) === val) {
  2584. return true;
  2585. }
  2586. }
  2587. return false;
  2588. }
  2589. function _removeAttrOrCss(knode, map) {
  2590. if (knode.type != 1) {
  2591. return;
  2592. }
  2593. _removeAttrOrCssByKey(knode, map, '*');
  2594. _removeAttrOrCssByKey(knode, map);
  2595. }
  2596. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2597. mapKey = mapKey || knode.name;
  2598. if (knode.type !== 1) {
  2599. return;
  2600. }
  2601. var newMap = _singleKeyMap(map);
  2602. if (!newMap[mapKey]) {
  2603. return;
  2604. }
  2605. var arr = newMap[mapKey].split(','), allFlag = false;
  2606. for (var i = 0, len = arr.length; i < len; i++) {
  2607. var key = arr[i];
  2608. if (key === '*') {
  2609. allFlag = true;
  2610. break;
  2611. }
  2612. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2613. key = match[2];
  2614. if (match[1]) {
  2615. key = _toCamel(key);
  2616. if (knode[0].style[key]) {
  2617. knode[0].style[key] = '';
  2618. }
  2619. } else {
  2620. knode.removeAttr(key);
  2621. }
  2622. }
  2623. if (allFlag) {
  2624. knode.remove(true);
  2625. }
  2626. }
  2627. function _getInnerNode(knode) {
  2628. var inner = knode;
  2629. while (inner.first()) {
  2630. inner = inner.first();
  2631. }
  2632. return inner;
  2633. }
  2634. function _isEmptyNode(knode) {
  2635. if (knode.type != 1 || knode.isSingle()) {
  2636. return false;
  2637. }
  2638. return knode.html().replace(/<[^>]+>/g, '') === '';
  2639. }
  2640. function _mergeWrapper(a, b) {
  2641. a = a.clone(true);
  2642. var lastA = _getInnerNode(a), childA = a, merged = false;
  2643. while (b) {
  2644. while (childA) {
  2645. if (childA.name === b.name) {
  2646. _mergeAttrs(childA, b.attr(), b.css());
  2647. merged = true;
  2648. }
  2649. childA = childA.first();
  2650. }
  2651. if (!merged) {
  2652. lastA.append(b.clone(false));
  2653. }
  2654. merged = false;
  2655. b = b.first();
  2656. }
  2657. return a;
  2658. }
  2659. function _wrapNode(knode, wrapper) {
  2660. wrapper = wrapper.clone(true);
  2661. if (knode.type == 3) {
  2662. _getInnerNode(wrapper).append(knode.clone(false));
  2663. knode.replaceWith(wrapper);
  2664. return wrapper;
  2665. }
  2666. var nodeWrapper = knode, child;
  2667. while ((child = knode.first()) && child.children().length == 1) {
  2668. knode = child;
  2669. }
  2670. child = knode.first();
  2671. var frag = knode.doc.createDocumentFragment();
  2672. while (child) {
  2673. frag.appendChild(child[0]);
  2674. child = child.next();
  2675. }
  2676. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2677. if (frag.firstChild) {
  2678. _getInnerNode(wrapper).append(frag);
  2679. }
  2680. nodeWrapper.replaceWith(wrapper);
  2681. return wrapper;
  2682. }
  2683. function _mergeAttrs(knode, attrs, styles) {
  2684. _each(attrs, function (key, val) {
  2685. if (key !== 'style') {
  2686. knode.attr(key, val);
  2687. }
  2688. });
  2689. _each(styles, function (key, val) {
  2690. knode.css(key, val);
  2691. });
  2692. }
  2693. function _inPreElement(knode) {
  2694. while (knode && knode.name != 'body') {
  2695. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2696. return true;
  2697. }
  2698. knode = knode.parent();
  2699. }
  2700. return false;
  2701. }
  2702. function KCmd(range) {
  2703. this.init(range);
  2704. }
  2705. _extend(KCmd, {
  2706. init: function (range) {
  2707. var self = this, doc = range.doc;
  2708. self.doc = doc;
  2709. self.win = _getWin(doc);
  2710. self.sel = _getSel(doc);
  2711. self.range = range;
  2712. },
  2713. selection: function (forceReset) {
  2714. var self = this, doc = self.doc, rng = _getRng(doc);
  2715. self.sel = _getSel(doc);
  2716. if (rng) {
  2717. self.range = _range(rng);
  2718. if (K(self.range.startContainer).name == 'html') {
  2719. self.range.selectNodeContents(doc.body).collapse(false);
  2720. }
  2721. return self;
  2722. }
  2723. if (forceReset) {
  2724. self.range.selectNodeContents(doc.body).collapse(false);
  2725. }
  2726. return self;
  2727. },
  2728. select: function (hasDummy) {
  2729. hasDummy = _undef(hasDummy, true);
  2730. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2731. sc = range.startContainer, so = range.startOffset,
  2732. ec = range.endContainer, eo = range.endOffset,
  2733. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2734. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2735. if (_IERANGE) {
  2736. var dummy = K('<span>&nbsp;</span>', doc);
  2737. range.insertNode(dummy[0]);
  2738. rng = doc.body.createTextRange();
  2739. try {
  2740. rng.moveToElementText(dummy[0]);
  2741. } catch (ex) {
  2742. }
  2743. rng.collapse(false);
  2744. rng.select();
  2745. dummy.remove();
  2746. win.focus();
  2747. return self;
  2748. }
  2749. if (_WEBKIT) {
  2750. var children = sc.childNodes;
  2751. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2752. range.insertNode(doc.createTextNode('\u200B'));
  2753. hasU200b = true;
  2754. }
  2755. }
  2756. }
  2757. if (_IERANGE) {
  2758. try {
  2759. rng = range.get(true);
  2760. rng.select();
  2761. } catch (e) {
  2762. }
  2763. } else {
  2764. if (hasU200b) {
  2765. range.collapse(false);
  2766. }
  2767. rng = range.get(true);
  2768. sel.removeAllRanges();
  2769. sel.addRange(rng);
  2770. if (doc !== document) {
  2771. var pos = K(rng.endContainer).pos();
  2772. win.scrollTo(pos.x, pos.y);
  2773. }
  2774. }
  2775. win.focus();
  2776. return self;
  2777. },
  2778. wrap: function (val) {
  2779. var self = this, doc = self.doc, range = self.range, wrapper;
  2780. wrapper = K(val, doc);
  2781. if (range.collapsed) {
  2782. range.shrink();
  2783. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2784. return self;
  2785. }
  2786. if (wrapper.isBlock()) {
  2787. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2788. while (child.first()) {
  2789. child = child.first();
  2790. }
  2791. child.append(range.extractContents());
  2792. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2793. return self;
  2794. }
  2795. range.enlarge();
  2796. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2797. K(ancestor).scan(function (node) {
  2798. if (!isStart && node == bookmark.start) {
  2799. isStart = true;
  2800. return;
  2801. }
  2802. if (isStart) {
  2803. if (node == bookmark.end) {
  2804. return false;
  2805. }
  2806. var knode = K(node);
  2807. if (_inPreElement(knode)) {
  2808. return;
  2809. }
  2810. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2811. var parent;
  2812. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2813. knode = parent;
  2814. }
  2815. _wrapNode(knode, wrapper);
  2816. }
  2817. }
  2818. });
  2819. range.moveToBookmark(bookmark);
  2820. return self;
  2821. },
  2822. split: function (isStart, map) {
  2823. var range = this.range, doc = range.doc;
  2824. var tempRange = range.cloneRange().collapse(isStart);
  2825. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2826. parent = node.nodeType == 3 ? node.parentNode : node,
  2827. needSplit = false, knode;
  2828. while (parent && parent.parentNode) {
  2829. knode = K(parent);
  2830. if (map) {
  2831. if (!knode.isStyle()) {
  2832. break;
  2833. }
  2834. if (!_hasAttrOrCss(knode, map)) {
  2835. break;
  2836. }
  2837. } else {
  2838. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2839. break;
  2840. }
  2841. }
  2842. needSplit = true;
  2843. parent = parent.parentNode;
  2844. }
  2845. if (needSplit) {
  2846. var dummy = doc.createElement('span');
  2847. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2848. if (isStart) {
  2849. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2850. } else {
  2851. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2852. }
  2853. var frag = tempRange.extractContents(),
  2854. first = frag.firstChild, last = frag.lastChild;
  2855. if (isStart) {
  2856. tempRange.insertNode(frag);
  2857. range.setStartAfter(last).setEndBefore(dummy);
  2858. } else {
  2859. parent.appendChild(frag);
  2860. range.setStartBefore(dummy).setEndBefore(first);
  2861. }
  2862. var dummyParent = dummy.parentNode;
  2863. if (dummyParent == range.endContainer) {
  2864. var prev = K(dummy).prev(), next = K(dummy).next();
  2865. if (prev && next && prev.type == 3 && next.type == 3) {
  2866. range.setEnd(prev[0], prev[0].nodeValue.length);
  2867. } else if (!isStart) {
  2868. range.setEnd(range.endContainer, range.endOffset - 1);
  2869. }
  2870. }
  2871. dummyParent.removeChild(dummy);
  2872. }
  2873. return this;
  2874. },
  2875. remove: function (map) {
  2876. var self = this, doc = self.doc, range = self.range;
  2877. range.enlarge();
  2878. if (range.startOffset === 0) {
  2879. var ksc = K(range.startContainer), parent;
  2880. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2881. ksc = parent;
  2882. }
  2883. range.setStart(ksc[0], 0);
  2884. ksc = K(range.startContainer);
  2885. if (ksc.isBlock()) {
  2886. _removeAttrOrCss(ksc, map);
  2887. }
  2888. var kscp = ksc.parent();
  2889. if (kscp && kscp.isBlock()) {
  2890. _removeAttrOrCss(kscp, map);
  2891. }
  2892. }
  2893. var sc, so;
  2894. if (range.collapsed) {
  2895. self.split(true, map);
  2896. sc = range.startContainer;
  2897. so = range.startOffset;
  2898. if (so > 0) {
  2899. var sb = K(sc.childNodes[so - 1]);
  2900. if (sb && _isEmptyNode(sb)) {
  2901. sb.remove();
  2902. range.setStart(sc, so - 1);
  2903. }
  2904. }
  2905. var sa = K(sc.childNodes[so]);
  2906. if (sa && _isEmptyNode(sa)) {
  2907. sa.remove();
  2908. }
  2909. if (_isEmptyNode(sc)) {
  2910. range.startBefore(sc);
  2911. sc.remove();
  2912. }
  2913. range.collapse(true);
  2914. return self;
  2915. }
  2916. self.split(true, map);
  2917. self.split(false, map);
  2918. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2919. range.cloneRange().collapse(false).insertNode(endDummy);
  2920. range.cloneRange().collapse(true).insertNode(startDummy);
  2921. var nodeList = [], cmpStart = false;
  2922. K(range.commonAncestor()).scan(function (node) {
  2923. if (!cmpStart && node == startDummy) {
  2924. cmpStart = true;
  2925. return;
  2926. }
  2927. if (node == endDummy) {
  2928. return false;
  2929. }
  2930. if (cmpStart) {
  2931. nodeList.push(node);
  2932. }
  2933. });
  2934. K(startDummy).remove();
  2935. K(endDummy).remove();
  2936. sc = range.startContainer;
  2937. so = range.startOffset;
  2938. var ec = range.endContainer, eo = range.endOffset;
  2939. if (so > 0) {
  2940. var startBefore = K(sc.childNodes[so - 1]);
  2941. if (startBefore && _isEmptyNode(startBefore)) {
  2942. startBefore.remove();
  2943. range.setStart(sc, so - 1);
  2944. if (sc == ec) {
  2945. range.setEnd(ec, eo - 1);
  2946. }
  2947. }
  2948. var startAfter = K(sc.childNodes[so]);
  2949. if (startAfter && _isEmptyNode(startAfter)) {
  2950. startAfter.remove();
  2951. if (sc == ec) {
  2952. range.setEnd(ec, eo - 1);
  2953. }
  2954. }
  2955. }
  2956. var endAfter = K(ec.childNodes[range.endOffset]);
  2957. if (endAfter && _isEmptyNode(endAfter)) {
  2958. endAfter.remove();
  2959. }
  2960. var bookmark = range.createBookmark(true);
  2961. _each(nodeList, function (i, node) {
  2962. _removeAttrOrCss(K(node), map);
  2963. });
  2964. range.moveToBookmark(bookmark);
  2965. return self;
  2966. },
  2967. commonNode: function (map) {
  2968. var range = this.range;
  2969. var ec = range.endContainer, eo = range.endOffset,
  2970. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2971. function find(node) {
  2972. var child = node, parent = node;
  2973. while (parent) {
  2974. if (_hasAttrOrCss(K(parent), map)) {
  2975. return K(parent);
  2976. }
  2977. parent = parent.parentNode;
  2978. }
  2979. while (child && (child = child.lastChild)) {
  2980. if (_hasAttrOrCss(K(child), map)) {
  2981. return K(child);
  2982. }
  2983. }
  2984. return null;
  2985. }
  2986. var cNode = find(node);
  2987. if (cNode) {
  2988. return cNode;
  2989. }
  2990. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2991. var prev = K(node).prev();
  2992. if (prev) {
  2993. return find(prev);
  2994. }
  2995. }
  2996. return null;
  2997. },
  2998. commonAncestor: function (tagName) {
  2999. var range = this.range,
  3000. sc = range.startContainer, so = range.startOffset,
  3001. ec = range.endContainer, eo = range.endOffset,
  3002. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3003. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3004. function find(node) {
  3005. while (node) {
  3006. if (node.nodeType == 1) {
  3007. if (node.tagName.toLowerCase() === tagName) {
  3008. return node;
  3009. }
  3010. }
  3011. node = node.parentNode;
  3012. }
  3013. return null;
  3014. }
  3015. var start = find(startNode), end = find(endNode);
  3016. if (start && end && start === end) {
  3017. return K(start);
  3018. }
  3019. return null;
  3020. },
  3021. state: function (key) {
  3022. var self = this, doc = self.doc, bool = false;
  3023. try {
  3024. bool = doc.queryCommandState(key);
  3025. } catch (e) {
  3026. }
  3027. return bool;
  3028. },
  3029. val: function (key) {
  3030. var self = this, doc = self.doc, range = self.range;
  3031. function lc(val) {
  3032. return val.toLowerCase();
  3033. }
  3034. key = lc(key);
  3035. var val = '', knode;
  3036. if (key === 'fontfamily' || key === 'fontname') {
  3037. val = _nativeCommandValue(doc, 'fontname');
  3038. val = val.replace(/['"]/g, '');
  3039. return lc(val);
  3040. }
  3041. if (key === 'formatblock') {
  3042. val = _nativeCommandValue(doc, key);
  3043. if (val === '') {
  3044. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address': '*'});
  3045. if (knode) {
  3046. val = knode.name;
  3047. }
  3048. }
  3049. if (val === 'Normal') {
  3050. val = 'p';
  3051. }
  3052. return lc(val);
  3053. }
  3054. if (key === 'fontsize') {
  3055. knode = self.commonNode({'*': '.font-size'});
  3056. if (knode) {
  3057. val = knode.css('font-size');
  3058. }
  3059. return lc(val);
  3060. }
  3061. if (key === 'forecolor') {
  3062. knode = self.commonNode({'*': '.color'});
  3063. if (knode) {
  3064. val = knode.css('color');
  3065. }
  3066. val = _toHex(val);
  3067. if (val === '') {
  3068. val = 'default';
  3069. }
  3070. return lc(val);
  3071. }
  3072. if (key === 'hilitecolor') {
  3073. knode = self.commonNode({'*': '.background-color'});
  3074. if (knode) {
  3075. val = knode.css('background-color');
  3076. }
  3077. val = _toHex(val);
  3078. if (val === '') {
  3079. val = 'default';
  3080. }
  3081. return lc(val);
  3082. }
  3083. return val;
  3084. },
  3085. toggle: function (wrapper, map) {
  3086. var self = this;
  3087. if (self.commonNode(map)) {
  3088. self.remove(map);
  3089. } else {
  3090. self.wrap(wrapper);
  3091. }
  3092. return self.select();
  3093. },
  3094. bold: function () {
  3095. return this.toggle('<strong></strong>', {
  3096. span: '.font-weight=bold',
  3097. strong: '*',
  3098. b: '*'
  3099. });
  3100. },
  3101. italic: function () {
  3102. return this.toggle('<em></em>', {
  3103. span: '.font-style=italic',
  3104. em: '*',
  3105. i: '*'
  3106. });
  3107. },
  3108. underline: function () {
  3109. return this.toggle('<u></u>', {
  3110. span: '.text-decoration=underline',
  3111. u: '*'
  3112. });
  3113. },
  3114. strikethrough: function () {
  3115. return this.toggle('<s></s>', {
  3116. span: '.text-decoration=line-through',
  3117. s: '*'
  3118. });
  3119. },
  3120. forecolor: function (val) {
  3121. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3122. },
  3123. hilitecolor: function (val) {
  3124. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3125. },
  3126. fontsize: function (val) {
  3127. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3128. },
  3129. fontname: function (val) {
  3130. return this.fontfamily(val);
  3131. },
  3132. fontfamily: function (val) {
  3133. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3134. },
  3135. removeformat: function () {
  3136. var map = {
  3137. '*': '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3138. },
  3139. tags = _STYLE_TAG_MAP;
  3140. _each(tags, function (key, val) {
  3141. map[key] = '*';
  3142. });
  3143. this.remove(map);
  3144. return this.select();
  3145. },
  3146. inserthtml: function (val, quickMode) {
  3147. var self = this, range = self.range;
  3148. if (val === '') {
  3149. return self;
  3150. }
  3151. function pasteHtml(range, val) {
  3152. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3153. var rng = range.get();
  3154. if (rng.item) {
  3155. rng.item(0).outerHTML = val;
  3156. } else {
  3157. rng.pasteHTML(val);
  3158. }
  3159. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3160. temp.parentNode.removeChild(temp);
  3161. var newRange = _toRange(rng);
  3162. range.setEnd(newRange.endContainer, newRange.endOffset);
  3163. range.collapse(false);
  3164. self.select(false);
  3165. }
  3166. function insertHtml(range, val) {
  3167. var doc = range.doc,
  3168. frag = doc.createDocumentFragment();
  3169. K('@' + val, doc).each(function () {
  3170. frag.appendChild(this);
  3171. });
  3172. range.deleteContents();
  3173. range.insertNode(frag);
  3174. range.collapse(false);
  3175. self.select(false);
  3176. }
  3177. if (_IERANGE && quickMode) {
  3178. try {
  3179. pasteHtml(range, val);
  3180. } catch (e) {
  3181. insertHtml(range, val);
  3182. }
  3183. return self;
  3184. }
  3185. insertHtml(range, val);
  3186. return self;
  3187. },
  3188. hr: function () {
  3189. return this.inserthtml('<hr />');
  3190. },
  3191. print: function () {
  3192. this.win.print();
  3193. return this;
  3194. },
  3195. insertimage: function (url, title, width, height, border, align) {
  3196. title = _undef(title, '');
  3197. border = _undef(border, 0);
  3198. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3199. if (width) {
  3200. html += 'width="' + _escape(width) + '" ';
  3201. }
  3202. if (height) {
  3203. html += 'height="' + _escape(height) + '" ';
  3204. }
  3205. if (title) {
  3206. html += 'title="' + _escape(title) + '" ';
  3207. }
  3208. if (align) {
  3209. html += 'align="' + _escape(align) + '" ';
  3210. }
  3211. html += 'alt="' + _escape(title) + '" ';
  3212. html += '/>';
  3213. return this.inserthtml(html);
  3214. },
  3215. createlink: function (url, type) {
  3216. var self = this, doc = self.doc, range = self.range;
  3217. self.select();
  3218. var a = self.commonNode({a: '*'});
  3219. if (a && !range.isControl()) {
  3220. range.selectNode(a.get());
  3221. self.select();
  3222. }
  3223. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3224. if (type) {
  3225. html += ' target="' + _escape(type) + '"';
  3226. }
  3227. if (range.collapsed) {
  3228. html += '>' + _escape(url) + '</a>';
  3229. return self.inserthtml(html);
  3230. }
  3231. if (range.isControl()) {
  3232. var node = K(range.startContainer.childNodes[range.startOffset]);
  3233. html += '></a>';
  3234. node.after(K(html, doc));
  3235. node.next().append(node);
  3236. range.selectNode(node[0]);
  3237. return self.select();
  3238. }
  3239. function setAttr(node, url, type) {
  3240. K(node).attr('href', url).attr('data-ke-src', url);
  3241. if (type) {
  3242. K(node).attr('target', type);
  3243. } else {
  3244. K(node).removeAttr('target');
  3245. }
  3246. }
  3247. var sc = range.startContainer, so = range.startOffset,
  3248. ec = range.endContainer, eo = range.endOffset;
  3249. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3250. var child = sc.childNodes[so];
  3251. if (child.nodeName.toLowerCase() == 'a') {
  3252. setAttr(child, url, type);
  3253. return self;
  3254. }
  3255. }
  3256. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3257. K('a[href="__kindeditor_temp_url__"]', doc).each(function () {
  3258. setAttr(this, url, type);
  3259. });
  3260. return self;
  3261. },
  3262. unlink: function () {
  3263. var self = this, doc = self.doc, range = self.range;
  3264. self.select();
  3265. if (range.collapsed) {
  3266. var a = self.commonNode({a: '*'});
  3267. if (a) {
  3268. range.selectNode(a.get());
  3269. self.select();
  3270. }
  3271. _nativeCommand(doc, 'unlink', null);
  3272. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3273. var parent = K(range.startContainer).parent();
  3274. if (parent.name === 'a') {
  3275. parent.remove(true);
  3276. }
  3277. }
  3278. } else {
  3279. _nativeCommand(doc, 'unlink', null);
  3280. }
  3281. return self;
  3282. }
  3283. });
  3284. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3285. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function (i, name) {
  3286. KCmd.prototype[name] = function (val) {
  3287. var self = this;
  3288. self.select();
  3289. _nativeCommand(self.doc, name, val);
  3290. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3291. self.selection();
  3292. }
  3293. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3294. self.selection();
  3295. }
  3296. return self;
  3297. };
  3298. });
  3299. _each('cut,copy,paste'.split(','), function (i, name) {
  3300. KCmd.prototype[name] = function () {
  3301. var self = this;
  3302. if (!self.doc.queryCommandSupported(name)) {
  3303. throw 'not supported';
  3304. }
  3305. self.select();
  3306. _nativeCommand(self.doc, name, null);
  3307. return self;
  3308. };
  3309. });
  3310. function _cmd(mixed) {
  3311. if (mixed.nodeName) {
  3312. var doc = _getDoc(mixed);
  3313. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3314. }
  3315. return new KCmd(mixed);
  3316. }
  3317. K.CmdClass = KCmd;
  3318. K.cmd = _cmd;
  3319. function _drag(options) {
  3320. var moveEl = options.moveEl,
  3321. moveFn = options.moveFn,
  3322. clickEl = options.clickEl || moveEl,
  3323. beforeDrag = options.beforeDrag,
  3324. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3325. var docs = [document];
  3326. if (iframeFix) {
  3327. K('iframe').each(function () {
  3328. var src = _formatUrl(this.src || '', 'absolute');
  3329. if (/^https?:\/\//.test(src)) {
  3330. return;
  3331. }
  3332. var doc;
  3333. try {
  3334. doc = _iframeDoc(this);
  3335. } catch (e) {
  3336. }
  3337. if (doc) {
  3338. var pos = K(this).pos();
  3339. K(doc).data('pos-x', pos.x);
  3340. K(doc).data('pos-y', pos.y);
  3341. docs.push(doc);
  3342. }
  3343. });
  3344. }
  3345. clickEl.mousedown(function (e) {
  3346. if (e.button !== 0 && e.button !== 1) {
  3347. return;
  3348. }
  3349. e.stopPropagation();
  3350. var self = clickEl.get(),
  3351. x = _removeUnit(moveEl.css('left')),
  3352. y = _removeUnit(moveEl.css('top')),
  3353. width = moveEl.width(),
  3354. height = moveEl.height(),
  3355. pageX = e.pageX,
  3356. pageY = e.pageY;
  3357. if (beforeDrag) {
  3358. beforeDrag();
  3359. }
  3360. function moveListener(e) {
  3361. e.preventDefault();
  3362. var kdoc = K(_getDoc(e.target));
  3363. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3364. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3365. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3366. }
  3367. function selectListener(e) {
  3368. e.preventDefault();
  3369. }
  3370. function upListener(e) {
  3371. e.preventDefault();
  3372. K(docs).unbind('mousemove', moveListener)
  3373. .unbind('mouseup', upListener)
  3374. .unbind('selectstart', selectListener);
  3375. if (self.releaseCapture) {
  3376. self.releaseCapture();
  3377. }
  3378. }
  3379. K(docs).mousemove(moveListener)
  3380. .mouseup(upListener)
  3381. .bind('selectstart', selectListener);
  3382. if (self.setCapture) {
  3383. self.setCapture();
  3384. }
  3385. });
  3386. }
  3387. function KWidget(options) {
  3388. this.init(options);
  3389. }
  3390. _extend(KWidget, {
  3391. init: function (options) {
  3392. var self = this;
  3393. self.name = options.name || '';
  3394. self.doc = options.doc || document;
  3395. self.win = _getWin(self.doc);
  3396. self.x = _addUnit(options.x);
  3397. self.y = _addUnit(options.y);
  3398. self.z = options.z;
  3399. self.width = _addUnit(options.width);
  3400. self.height = _addUnit(options.height);
  3401. self.div = K('<div style="display:block;"></div>');
  3402. self.options = options;
  3403. self._alignEl = options.alignEl;
  3404. if (self.width) {
  3405. self.div.css('width', self.width);
  3406. }
  3407. if (self.height) {
  3408. self.div.css('height', self.height);
  3409. }
  3410. if (self.z) {
  3411. self.div.css({
  3412. position: 'absolute',
  3413. left: self.x,
  3414. top: self.y,
  3415. 'z-index': self.z
  3416. });
  3417. }
  3418. if (self.z && (self.x === undefined || self.y === undefined)) {
  3419. self.autoPos(self.width, self.height);
  3420. }
  3421. if (options.cls) {
  3422. self.div.addClass(options.cls);
  3423. }
  3424. if (options.shadowMode) {
  3425. self.div.addClass('ke-shadow');
  3426. }
  3427. if (options.css) {
  3428. self.div.css(options.css);
  3429. }
  3430. if (options.src) {
  3431. K(options.src).replaceWith(self.div);
  3432. } else {
  3433. K(self.doc.body).append(self.div);
  3434. }
  3435. if (options.html) {
  3436. self.div.html(options.html);
  3437. }
  3438. if (options.autoScroll) {
  3439. if (_IE && _V < 7 || _QUIRKS) {
  3440. var scrollPos = _getScrollPos();
  3441. K(self.win).bind('scroll', function (e) {
  3442. var pos = _getScrollPos(),
  3443. diffX = pos.x - scrollPos.x,
  3444. diffY = pos.y - scrollPos.y;
  3445. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3446. });
  3447. } else {
  3448. self.div.css('position', 'fixed');
  3449. }
  3450. }
  3451. },
  3452. pos: function (x, y, updateProp) {
  3453. var self = this;
  3454. updateProp = _undef(updateProp, true);
  3455. if (x !== null) {
  3456. x = x < 0 ? 0 : _addUnit(x);
  3457. self.div.css('left', x);
  3458. if (updateProp) {
  3459. self.x = x;
  3460. }
  3461. }
  3462. if (y !== null) {
  3463. y = y < 0 ? 0 : _addUnit(y);
  3464. self.div.css('top', y);
  3465. if (updateProp) {
  3466. self.y = y;
  3467. }
  3468. }
  3469. return self;
  3470. },
  3471. autoPos: function (width, height) {
  3472. var self = this,
  3473. w = _removeUnit(width) || 0,
  3474. h = _removeUnit(height) || 0,
  3475. scrollPos = _getScrollPos();
  3476. if (self._alignEl) {
  3477. var knode = K(self._alignEl),
  3478. pos = knode.pos(),
  3479. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3480. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3481. x = diffX < 0 ? pos.x : pos.x + diffX;
  3482. y = diffY < 0 ? pos.y : pos.y + diffY;
  3483. } else {
  3484. var docEl = _docElement(self.doc);
  3485. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3486. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3487. }
  3488. if (!(_IE && _V < 7 || _QUIRKS)) {
  3489. x -= scrollPos.x;
  3490. y -= scrollPos.y;
  3491. }
  3492. return self.pos(x, y);
  3493. },
  3494. remove: function () {
  3495. var self = this;
  3496. if (_IE && _V < 7 || _QUIRKS) {
  3497. K(self.win).unbind('scroll');
  3498. }
  3499. self.div.remove();
  3500. _each(self, function (i) {
  3501. self[i] = null;
  3502. });
  3503. return this;
  3504. },
  3505. show: function () {
  3506. this.div.show();
  3507. return this;
  3508. },
  3509. hide: function () {
  3510. this.div.hide();
  3511. return this;
  3512. },
  3513. draggable: function (options) {
  3514. var self = this;
  3515. options = options || {};
  3516. options.moveEl = self.div;
  3517. options.moveFn = function (x, y, width, height, diffX, diffY) {
  3518. if ((x = x + diffX) < 0) {
  3519. x = 0;
  3520. }
  3521. if ((y = y + diffY) < 0) {
  3522. y = 0;
  3523. }
  3524. self.pos(x, y);
  3525. };
  3526. _drag(options);
  3527. return self;
  3528. }
  3529. });
  3530. function _widget(options) {
  3531. return new KWidget(options);
  3532. }
  3533. K.WidgetClass = KWidget;
  3534. K.widget = _widget;
  3535. function _iframeDoc(iframe) {
  3536. iframe = _get(iframe);
  3537. return iframe.contentDocument || iframe.contentWindow.document;
  3538. }
  3539. var html, _direction = '';
  3540. if ((html = document.getElementsByTagName('html'))) {
  3541. _direction = html[0].dir;
  3542. }
  3543. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3544. var arr = [
  3545. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3546. '<head><meta charset="utf-8" /><title></title>',
  3547. '<style>',
  3548. 'html {margin:0;padding:0;}',
  3549. 'body {margin:0;padding:5px;}',
  3550. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3551. 'body, p, div {word-wrap: break-word;}',
  3552. 'p {margin:5px 0;}',
  3553. 'table {border-collapse:collapse;}',
  3554. 'img {border:0;}',
  3555. 'noscript {display:none;}',
  3556. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3557. 'img.ke-flash {',
  3558. ' border:1px solid #AAA;',
  3559. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3560. ' background-position:center center;',
  3561. ' background-repeat:no-repeat;',
  3562. ' width:100px;',
  3563. ' height:100px;',
  3564. '}',
  3565. 'img.ke-rm {',
  3566. ' border:1px solid #AAA;',
  3567. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3568. ' background-position:center center;',
  3569. ' background-repeat:no-repeat;',
  3570. ' width:100px;',
  3571. ' height:100px;',
  3572. '}',
  3573. 'img.ke-media {',
  3574. ' border:1px solid #AAA;',
  3575. ' background-image:url(' + themesPath + 'common/media.gif);',
  3576. ' background-position:center center;',
  3577. ' background-repeat:no-repeat;',
  3578. ' width:100px;',
  3579. ' height:100px;',
  3580. '}',
  3581. 'img.ke-anchor {',
  3582. ' border:1px dashed #666;',
  3583. ' width:16px;',
  3584. ' height:16px;',
  3585. '}',
  3586. '.ke-script, .ke-noscript, .ke-display-none {',
  3587. ' display:none;',
  3588. ' font-size:0;',
  3589. ' width:0;',
  3590. ' height:0;',
  3591. '}',
  3592. '.ke-pagebreak {',
  3593. ' border:1px dotted #AAA;',
  3594. ' font-size:0;',
  3595. ' height:2px;',
  3596. '}',
  3597. '</style>'
  3598. ];
  3599. if (!_isArray(cssPath)) {
  3600. cssPath = [cssPath];
  3601. }
  3602. _each(cssPath, function (i, path) {
  3603. if (path) {
  3604. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3605. }
  3606. });
  3607. if (cssData) {
  3608. arr.push('<style>' + cssData + '</style>');
  3609. }
  3610. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3611. return arr.join('\n');
  3612. }
  3613. function _elementVal(knode, val) {
  3614. if (knode.hasVal()) {
  3615. if (val === undefined) {
  3616. var html = knode.val();
  3617. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3618. return html;
  3619. }
  3620. return knode.val(val);
  3621. }
  3622. return knode.html(val);
  3623. }
  3624. function KEdit(options) {
  3625. this.init(options);
  3626. }
  3627. _extend(KEdit, KWidget, {
  3628. init: function (options) {
  3629. var self = this;
  3630. KEdit.parent.init.call(self, options);
  3631. self.srcElement = K(options.srcElement);
  3632. self.div.addClass('ke-edit');
  3633. self.designMode = _undef(options.designMode, true);
  3634. self.beforeGetHtml = options.beforeGetHtml;
  3635. self.beforeSetHtml = options.beforeSetHtml;
  3636. self.afterSetHtml = options.afterSetHtml;
  3637. var themesPath = _undef(options.themesPath, ''),
  3638. bodyClass = options.bodyClass,
  3639. cssPath = options.cssPath,
  3640. cssData = options.cssData,
  3641. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3642. srcScript = ('document.open();' +
  3643. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3644. 'document.close();'),
  3645. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3646. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3647. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3648. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3649. self.iframe.attr('tabindex', self.tabIndex);
  3650. self.textarea.attr('tabindex', self.tabIndex);
  3651. if (self.width) {
  3652. self.setWidth(self.width);
  3653. }
  3654. if (self.height) {
  3655. self.setHeight(self.height);
  3656. }
  3657. if (self.designMode) {
  3658. self.textarea.hide();
  3659. } else {
  3660. self.iframe.hide();
  3661. }
  3662. function ready() {
  3663. var doc = _iframeDoc(self.iframe);
  3664. doc.open();
  3665. if (isDocumentDomain) {
  3666. doc.domain = document.domain;
  3667. }
  3668. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3669. doc.close();
  3670. self.win = self.iframe[0].contentWindow;
  3671. self.doc = doc;
  3672. var cmd = _cmd(doc);
  3673. self.afterChange(function (e) {
  3674. cmd.selection();
  3675. });
  3676. if (_WEBKIT) {
  3677. K(doc).click(function (e) {
  3678. if (K(e.target).name === 'img') {
  3679. cmd.selection(true);
  3680. cmd.range.selectNode(e.target);
  3681. cmd.select();
  3682. }
  3683. });
  3684. }
  3685. if (_IE) {
  3686. self._mousedownHandler = function () {
  3687. var newRange = cmd.range.cloneRange();
  3688. newRange.shrink();
  3689. if (newRange.isControl()) {
  3690. self.blur();
  3691. }
  3692. };
  3693. K(document).mousedown(self._mousedownHandler);
  3694. K(doc).keydown(function (e) {
  3695. if (e.which == 8) {
  3696. cmd.selection();
  3697. var rng = cmd.range;
  3698. if (rng.isControl()) {
  3699. rng.collapse(true);
  3700. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3701. e.preventDefault();
  3702. }
  3703. }
  3704. });
  3705. }
  3706. self.cmd = cmd;
  3707. self.html(_elementVal(self.srcElement));
  3708. if (_IE) {
  3709. doc.body.disabled = true;
  3710. doc.body.contentEditable = true;
  3711. doc.body.removeAttribute('disabled');
  3712. } else {
  3713. doc.designMode = 'on';
  3714. }
  3715. if (options.afterCreate) {
  3716. options.afterCreate.call(self);
  3717. }
  3718. }
  3719. if (isDocumentDomain) {
  3720. self.iframe.bind('load', function (e) {
  3721. self.iframe.unbind('load');
  3722. if (_IE) {
  3723. ready();
  3724. } else {
  3725. setTimeout(ready, 0);
  3726. }
  3727. });
  3728. }
  3729. self.div.append(self.iframe);
  3730. self.div.append(self.textarea);
  3731. self.srcElement.hide();
  3732. !isDocumentDomain && ready();
  3733. },
  3734. setWidth: function (val) {
  3735. var self = this;
  3736. val = _addUnit(val);
  3737. self.width = val;
  3738. self.div.css('width', val);
  3739. return self;
  3740. },
  3741. setHeight: function (val) {
  3742. var self = this;
  3743. val = _addUnit(val);
  3744. self.height = val;
  3745. self.div.css('height', val);
  3746. self.iframe.css('height', val);
  3747. if ((_IE && _V < 8) || _QUIRKS) {
  3748. val = _addUnit(_removeUnit(val) - 2);
  3749. }
  3750. self.textarea.css('height', val);
  3751. return self;
  3752. },
  3753. remove: function () {
  3754. var self = this, doc = self.doc;
  3755. K(doc.body).unbind();
  3756. K(doc).unbind();
  3757. K(self.win).unbind();
  3758. if (self._mousedownHandler) {
  3759. K(document).unbind('mousedown', self._mousedownHandler);
  3760. }
  3761. _elementVal(self.srcElement, self.html());
  3762. self.srcElement.show();
  3763. self.iframe.unbind();
  3764. self.textarea.unbind();
  3765. KEdit.parent.remove.call(self);
  3766. },
  3767. html: function (val, isFull) {
  3768. var self = this, doc = self.doc;
  3769. if (self.designMode) {
  3770. var body = doc.body;
  3771. if (val === undefined) {
  3772. if (isFull) {
  3773. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3774. } else {
  3775. val = body.innerHTML;
  3776. }
  3777. if (self.beforeGetHtml) {
  3778. val = self.beforeGetHtml(val);
  3779. }
  3780. if (_GECKO && val == '<br />') {
  3781. val = '';
  3782. }
  3783. return val;
  3784. }
  3785. if (self.beforeSetHtml) {
  3786. val = self.beforeSetHtml(val);
  3787. }
  3788. if (_IE && _V >= 9) {
  3789. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3790. }
  3791. K(body).html(val);
  3792. if (self.afterSetHtml) {
  3793. self.afterSetHtml();
  3794. }
  3795. return self;
  3796. }
  3797. if (val === undefined) {
  3798. return self.textarea.val();
  3799. }
  3800. self.textarea.val(val);
  3801. return self;
  3802. },
  3803. design: function (bool) {
  3804. var self = this, val;
  3805. if (bool === undefined ? !self.designMode : bool) {
  3806. if (!self.designMode) {
  3807. val = self.html();
  3808. self.designMode = true;
  3809. self.textarea.hide();
  3810. self.html(val);
  3811. var iframe = self.iframe;
  3812. var height = _removeUnit(self.height);
  3813. iframe.height(height - 2);
  3814. iframe.show();
  3815. setTimeout(function () {
  3816. iframe.height(height);
  3817. }, 0);
  3818. }
  3819. } else {
  3820. if (self.designMode) {
  3821. val = self.html();
  3822. self.designMode = false;
  3823. self.html(val);
  3824. self.iframe.hide();
  3825. self.textarea.show();
  3826. }
  3827. }
  3828. return self.focus();
  3829. },
  3830. focus: function () {
  3831. var self = this;
  3832. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3833. return self;
  3834. },
  3835. blur: function () {
  3836. var self = this;
  3837. if (_IE) {
  3838. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3839. self.div.append(input);
  3840. input[0].focus();
  3841. input.remove();
  3842. } else {
  3843. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3844. }
  3845. return self;
  3846. },
  3847. afterChange: function (fn) {
  3848. var self = this, doc = self.doc, body = doc.body;
  3849. K(doc).keyup(function (e) {
  3850. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3851. fn(e);
  3852. }
  3853. });
  3854. K(doc).mouseup(fn).contextmenu(fn);
  3855. K(self.win).blur(fn);
  3856. function timeoutHandler(e) {
  3857. setTimeout(function () {
  3858. fn(e);
  3859. }, 1);
  3860. }
  3861. K(body).bind('paste', timeoutHandler);
  3862. K(body).bind('cut', timeoutHandler);
  3863. return self;
  3864. }
  3865. });
  3866. function _edit(options) {
  3867. return new KEdit(options);
  3868. }
  3869. K.EditClass = KEdit;
  3870. K.edit = _edit;
  3871. K.iframeDoc = _iframeDoc;
  3872. function _selectToolbar(name, fn) {
  3873. var self = this,
  3874. knode = self.get(name);
  3875. if (knode) {
  3876. if (knode.hasClass('ke-disabled')) {
  3877. return;
  3878. }
  3879. fn(knode);
  3880. }
  3881. }
  3882. function KToolbar(options) {
  3883. this.init(options);
  3884. }
  3885. _extend(KToolbar, KWidget, {
  3886. init: function (options) {
  3887. var self = this;
  3888. KToolbar.parent.init.call(self, options);
  3889. self.disableMode = _undef(options.disableMode, false);
  3890. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3891. self._itemMap = {};
  3892. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function (e) {
  3893. e.preventDefault();
  3894. }).attr('unselectable', 'on');
  3895. function find(target) {
  3896. var knode = K(target);
  3897. if (knode.hasClass('ke-outline')) {
  3898. return knode;
  3899. }
  3900. if (knode.hasClass('ke-toolbar-icon')) {
  3901. return knode.parent();
  3902. }
  3903. }
  3904. function hover(e, method) {
  3905. var knode = find(e.target);
  3906. if (knode) {
  3907. if (knode.hasClass('ke-disabled')) {
  3908. return;
  3909. }
  3910. if (knode.hasClass('ke-selected')) {
  3911. return;
  3912. }
  3913. knode[method]('ke-on');
  3914. }
  3915. }
  3916. self.div.mouseover(function (e) {
  3917. hover(e, 'addClass');
  3918. })
  3919. .mouseout(function (e) {
  3920. hover(e, 'removeClass');
  3921. })
  3922. .click(function (e) {
  3923. var knode = find(e.target);
  3924. if (knode) {
  3925. if (knode.hasClass('ke-disabled')) {
  3926. return;
  3927. }
  3928. self.options.click.call(this, e, knode.attr('data-name'));
  3929. }
  3930. });
  3931. },
  3932. get: function (name) {
  3933. if (this._itemMap[name]) {
  3934. return this._itemMap[name];
  3935. }
  3936. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3937. },
  3938. select: function (name) {
  3939. _selectToolbar.call(this, name, function (knode) {
  3940. knode.addClass('ke-selected');
  3941. });
  3942. return self;
  3943. },
  3944. unselect: function (name) {
  3945. _selectToolbar.call(this, name, function (knode) {
  3946. knode.removeClass('ke-selected').removeClass('ke-on');
  3947. });
  3948. return self;
  3949. },
  3950. enable: function (name) {
  3951. var self = this,
  3952. knode = name.get ? name : self.get(name);
  3953. if (knode) {
  3954. knode.removeClass('ke-disabled');
  3955. knode.opacity(1);
  3956. }
  3957. return self;
  3958. },
  3959. disable: function (name) {
  3960. var self = this,
  3961. knode = name.get ? name : self.get(name);
  3962. if (knode) {
  3963. knode.removeClass('ke-selected').addClass('ke-disabled');
  3964. knode.opacity(0.5);
  3965. }
  3966. return self;
  3967. },
  3968. disableAll: function (bool, noDisableItems) {
  3969. var self = this, map = self.noDisableItemMap, item;
  3970. if (noDisableItems) {
  3971. map = _toMap(noDisableItems);
  3972. }
  3973. if (bool === undefined ? !self.disableMode : bool) {
  3974. K('span.ke-outline', self.div).each(function () {
  3975. var knode = K(this),
  3976. name = knode[0].getAttribute('data-name', 2);
  3977. if (!map[name]) {
  3978. self.disable(knode);
  3979. }
  3980. });
  3981. self.disableMode = true;
  3982. } else {
  3983. K('span.ke-outline', self.div).each(function () {
  3984. var knode = K(this),
  3985. name = knode[0].getAttribute('data-name', 2);
  3986. if (!map[name]) {
  3987. self.enable(knode);
  3988. }
  3989. });
  3990. self.disableMode = false;
  3991. }
  3992. return self;
  3993. }
  3994. });
  3995. function _toolbar(options) {
  3996. return new KToolbar(options);
  3997. }
  3998. K.ToolbarClass = KToolbar;
  3999. K.toolbar = _toolbar;
  4000. function KMenu(options) {
  4001. this.init(options);
  4002. }
  4003. _extend(KMenu, KWidget, {
  4004. init: function (options) {
  4005. var self = this;
  4006. options.z = options.z || 811213;
  4007. KMenu.parent.init.call(self, options);
  4008. self.centerLineMode = _undef(options.centerLineMode, true);
  4009. self.div.addClass('ke-menu').bind('click,mousedown', function (e) {
  4010. e.stopPropagation();
  4011. }).attr('unselectable', 'on');
  4012. },
  4013. addItem: function (item) {
  4014. var self = this;
  4015. if (item.title === '-') {
  4016. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4017. return;
  4018. }
  4019. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4020. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4021. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4022. height = _addUnit(item.height),
  4023. iconClass = _undef(item.iconClass, '');
  4024. self.div.append(itemDiv);
  4025. if (height) {
  4026. itemDiv.css('height', height);
  4027. rightDiv.css('line-height', height);
  4028. }
  4029. var centerDiv;
  4030. if (self.centerLineMode) {
  4031. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4032. if (height) {
  4033. centerDiv.css('height', height);
  4034. }
  4035. }
  4036. itemDiv.mouseover(function (e) {
  4037. K(this).addClass('ke-menu-item-on');
  4038. if (centerDiv) {
  4039. centerDiv.addClass('ke-menu-item-center-on');
  4040. }
  4041. })
  4042. .mouseout(function (e) {
  4043. K(this).removeClass('ke-menu-item-on');
  4044. if (centerDiv) {
  4045. centerDiv.removeClass('ke-menu-item-center-on');
  4046. }
  4047. })
  4048. .click(function (e) {
  4049. item.click.call(K(this));
  4050. e.stopPropagation();
  4051. })
  4052. .append(leftDiv);
  4053. if (centerDiv) {
  4054. itemDiv.append(centerDiv);
  4055. }
  4056. itemDiv.append(rightDiv);
  4057. if (item.checked) {
  4058. iconClass = 'ke-icon-checked';
  4059. }
  4060. if (iconClass !== '') {
  4061. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4062. }
  4063. rightDiv.html(item.title);
  4064. return self;
  4065. },
  4066. remove: function () {
  4067. var self = this;
  4068. if (self.options.beforeRemove) {
  4069. self.options.beforeRemove.call(self);
  4070. }
  4071. K('.ke-menu-item', self.div[0]).unbind();
  4072. KMenu.parent.remove.call(self);
  4073. return self;
  4074. }
  4075. });
  4076. function _menu(options) {
  4077. return new KMenu(options);
  4078. }
  4079. K.MenuClass = KMenu;
  4080. K.menu = _menu;
  4081. function KColorPicker(options) {
  4082. this.init(options);
  4083. }
  4084. _extend(KColorPicker, KWidget, {
  4085. init: function (options) {
  4086. var self = this;
  4087. options.z = options.z || 811213;
  4088. KColorPicker.parent.init.call(self, options);
  4089. var colors = options.colors || [
  4090. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4091. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4092. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4093. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4094. ];
  4095. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4096. self._cells = [];
  4097. self.div.addClass('ke-colorpicker').bind('click,mousedown', function (e) {
  4098. e.stopPropagation();
  4099. }).attr('unselectable', 'on');
  4100. var table = self.doc.createElement('table');
  4101. self.div.append(table);
  4102. table.className = 'ke-colorpicker-table';
  4103. table.cellPadding = 0;
  4104. table.cellSpacing = 0;
  4105. table.border = 0;
  4106. var row = table.insertRow(0), cell = row.insertCell(0);
  4107. cell.colSpan = colors[0].length;
  4108. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4109. for (var i = 0; i < colors.length; i++) {
  4110. row = table.insertRow(i + 1);
  4111. for (var j = 0; j < colors[i].length; j++) {
  4112. cell = row.insertCell(j);
  4113. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4114. }
  4115. }
  4116. },
  4117. _addAttr: function (cell, color, cls) {
  4118. var self = this;
  4119. cell = K(cell).addClass(cls);
  4120. if (self.selectedColor === color.toLowerCase()) {
  4121. cell.addClass('ke-colorpicker-cell-selected');
  4122. }
  4123. cell.attr('title', color || self.options.noColor);
  4124. cell.mouseover(function (e) {
  4125. K(this).addClass('ke-colorpicker-cell-on');
  4126. });
  4127. cell.mouseout(function (e) {
  4128. K(this).removeClass('ke-colorpicker-cell-on');
  4129. });
  4130. cell.click(function (e) {
  4131. e.stop();
  4132. self.options.click.call(K(this), color);
  4133. });
  4134. if (color) {
  4135. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4136. } else {
  4137. cell.html(self.options.noColor);
  4138. }
  4139. K(cell).attr('unselectable', 'on');
  4140. self._cells.push(cell);
  4141. },
  4142. remove: function () {
  4143. var self = this;
  4144. _each(self._cells, function () {
  4145. this.unbind();
  4146. });
  4147. KColorPicker.parent.remove.call(self);
  4148. return self;
  4149. }
  4150. });
  4151. function _colorpicker(options) {
  4152. return new KColorPicker(options);
  4153. }
  4154. K.ColorPickerClass = KColorPicker;
  4155. K.colorpicker = _colorpicker;
  4156. function KUploadButton(options) {
  4157. this.init(options);
  4158. }
  4159. _extend(KUploadButton, {
  4160. init: function (options) {
  4161. var self = this,
  4162. button = K(options.button),
  4163. fieldName = options.fieldName || 'file',
  4164. url = options.url || '',
  4165. title = button.val(),
  4166. extraParams = options.extraParams || {},
  4167. cls = button[0].className || '',
  4168. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4169. options.afterError = options.afterError || function (str) {
  4170. alert(str);
  4171. };
  4172. var hiddenElements = [];
  4173. for (var k in extraParams) {
  4174. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4175. }
  4176. var html = [
  4177. '<div class="ke-inline-block ' + cls + '">',
  4178. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4179. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4180. '<span class="ke-button-common">',
  4181. hiddenElements.join(''),
  4182. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4183. '</span>',
  4184. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4185. (options.form ? '</div>' : '</form>'),
  4186. '</div>'].join('');
  4187. var div = K(html, button.doc);
  4188. button.hide();
  4189. button.before(div);
  4190. self.div = div;
  4191. self.button = button;
  4192. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4193. self.form = options.form ? K(options.form) : K('form', div);
  4194. self.fileBox = K('.ke-upload-file', div);
  4195. var width = options.width || K('.ke-button-common', div).width();
  4196. K('.ke-upload-area', div).width(width);
  4197. self.options = options;
  4198. },
  4199. submit: function () {
  4200. var self = this,
  4201. iframe = self.iframe;
  4202. iframe.bind('load', function () {
  4203. iframe.unbind();
  4204. var tempForm = document.createElement('form');
  4205. self.fileBox.before(tempForm);
  4206. K(tempForm).append(self.fileBox);
  4207. tempForm.reset();
  4208. K(tempForm).remove(true);
  4209. var doc = K.iframeDoc(iframe),
  4210. pre = doc.getElementsByTagName('pre')[0],
  4211. str = '', data;
  4212. if (pre) {
  4213. str = pre.innerHTML;
  4214. } else {
  4215. str = doc.body.innerHTML;
  4216. }
  4217. str = _unescape(str);
  4218. iframe[0].src = 'javascript:false';
  4219. try {
  4220. data = K.json(str);
  4221. } catch (e) {
  4222. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4223. }
  4224. if (data) {
  4225. self.options.afterUpload.call(self, data);
  4226. }
  4227. });
  4228. self.form[0].submit();
  4229. return self;
  4230. },
  4231. remove: function () {
  4232. var self = this;
  4233. if (self.fileBox) {
  4234. self.fileBox.unbind();
  4235. }
  4236. self.iframe.remove();
  4237. self.div.remove();
  4238. self.button.show();
  4239. return self;
  4240. }
  4241. });
  4242. function _uploadbutton(options) {
  4243. return new KUploadButton(options);
  4244. }
  4245. K.UploadButtonClass = KUploadButton;
  4246. K.uploadbutton = _uploadbutton;
  4247. function _createButton(arg) {
  4248. arg = arg || {};
  4249. var name = arg.name || '',
  4250. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4251. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4252. if (arg.click) {
  4253. btn.click(arg.click);
  4254. }
  4255. span.append(btn);
  4256. return span;
  4257. }
  4258. function KDialog(options) {
  4259. this.init(options);
  4260. }
  4261. _extend(KDialog, KWidget, {
  4262. init: function (options) {
  4263. var self = this;
  4264. var shadowMode = _undef(options.shadowMode, true);
  4265. options.z = options.z || 811213;
  4266. options.shadowMode = false;
  4267. options.autoScroll = _undef(options.autoScroll, true);
  4268. KDialog.parent.init.call(self, options);
  4269. var title = options.title,
  4270. body = K(options.body, self.doc),
  4271. previewBtn = options.previewBtn,
  4272. yesBtn = options.yesBtn,
  4273. noBtn = options.noBtn,
  4274. closeBtn = options.closeBtn,
  4275. showMask = _undef(options.showMask, true);
  4276. self.div.addClass('ke-dialog').bind('click,mousedown', function (e) {
  4277. e.stopPropagation();
  4278. });
  4279. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4280. if (_IE && _V < 7) {
  4281. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4282. } else if (shadowMode) {
  4283. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4284. }
  4285. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4286. contentDiv.append(headerDiv);
  4287. headerDiv.html(title);
  4288. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4289. headerDiv.append(self.closeIcon);
  4290. self.draggable({
  4291. clickEl: headerDiv,
  4292. beforeDrag: options.beforeDrag
  4293. });
  4294. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4295. contentDiv.append(bodyDiv);
  4296. bodyDiv.append(body);
  4297. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4298. if (previewBtn || yesBtn || noBtn) {
  4299. contentDiv.append(footerDiv);
  4300. }
  4301. _each([
  4302. {btn: previewBtn, name: 'preview'},
  4303. {btn: yesBtn, name: 'yes'},
  4304. {btn: noBtn, name: 'no'}
  4305. ], function () {
  4306. if (this.btn) {
  4307. var button = _createButton(this.btn);
  4308. button.addClass('ke-dialog-' + this.name);
  4309. footerDiv.append(button);
  4310. }
  4311. });
  4312. if (self.height) {
  4313. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4314. }
  4315. self.div.width(self.div.width());
  4316. self.div.height(self.div.height());
  4317. self.mask = null;
  4318. if (showMask) {
  4319. var docEl = _docElement(self.doc),
  4320. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4321. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4322. self.mask = _widget({
  4323. x: 0,
  4324. y: 0,
  4325. z: self.z - 1,
  4326. cls: 'ke-dialog-mask',
  4327. width: docWidth,
  4328. height: docHeight
  4329. });
  4330. }
  4331. self.autoPos(self.div.width(), self.div.height());
  4332. self.footerDiv = footerDiv;
  4333. self.bodyDiv = bodyDiv;
  4334. self.headerDiv = headerDiv;
  4335. self.isLoading = false;
  4336. },
  4337. setMaskIndex: function (z) {
  4338. var self = this;
  4339. self.mask.div.css('z-index', z);
  4340. },
  4341. showLoading: function (msg) {
  4342. msg = _undef(msg, '');
  4343. var self = this, body = self.bodyDiv;
  4344. 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>')
  4345. .width(body.width()).height(body.height())
  4346. .css('top', self.headerDiv.height() + 'px');
  4347. body.css('visibility', 'hidden').after(self.loading);
  4348. self.isLoading = true;
  4349. return self;
  4350. },
  4351. hideLoading: function () {
  4352. this.loading && this.loading.remove();
  4353. this.bodyDiv.css('visibility', 'visible');
  4354. this.isLoading = false;
  4355. return this;
  4356. },
  4357. remove: function () {
  4358. var self = this;
  4359. if (self.options.beforeRemove) {
  4360. self.options.beforeRemove.call(self);
  4361. }
  4362. self.mask && self.mask.remove();
  4363. self.iframeMask && self.iframeMask.remove();
  4364. self.closeIcon.unbind();
  4365. K('input', self.div).unbind();
  4366. K('button', self.div).unbind();
  4367. self.footerDiv.unbind();
  4368. self.bodyDiv.unbind();
  4369. self.headerDiv.unbind();
  4370. K('iframe', self.div).each(function () {
  4371. K(this).remove();
  4372. });
  4373. KDialog.parent.remove.call(self);
  4374. return self;
  4375. }
  4376. });
  4377. function _dialog(options) {
  4378. return new KDialog(options);
  4379. }
  4380. K.DialogClass = KDialog;
  4381. K.dialog = _dialog;
  4382. function _tabs(options) {
  4383. var self = _widget(options),
  4384. remove = self.remove,
  4385. afterSelect = options.afterSelect,
  4386. div = self.div,
  4387. liList = [];
  4388. div.addClass('ke-tabs')
  4389. .bind('contextmenu,mousedown,mousemove', function (e) {
  4390. e.preventDefault();
  4391. });
  4392. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4393. div.append(ul);
  4394. self.add = function (tab) {
  4395. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4396. li.data('tab', tab);
  4397. liList.push(li);
  4398. ul.append(li);
  4399. };
  4400. self.selectedIndex = 0;
  4401. self.select = function (index) {
  4402. self.selectedIndex = index;
  4403. _each(liList, function (i, li) {
  4404. li.unbind();
  4405. if (i === index) {
  4406. li.addClass('ke-tabs-li-selected');
  4407. K(li.data('tab').panel).show('');
  4408. } else {
  4409. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4410. .mouseover(function () {
  4411. K(this).addClass('ke-tabs-li-on');
  4412. })
  4413. .mouseout(function () {
  4414. K(this).removeClass('ke-tabs-li-on');
  4415. })
  4416. .click(function () {
  4417. self.select(i);
  4418. });
  4419. K(li.data('tab').panel).hide();
  4420. }
  4421. });
  4422. if (afterSelect) {
  4423. afterSelect.call(self, index);
  4424. }
  4425. };
  4426. self.remove = function () {
  4427. _each(liList, function () {
  4428. this.remove();
  4429. });
  4430. ul.remove();
  4431. remove.call(self);
  4432. };
  4433. return self;
  4434. }
  4435. K.tabs = _tabs;
  4436. function _loadScript(url, fn) {
  4437. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4438. script = document.createElement('script');
  4439. head.appendChild(script);
  4440. script.src = url;
  4441. script.charset = 'utf-8';
  4442. script.onload = script.onreadystatechange = function () {
  4443. if (!this.readyState || this.readyState === 'loaded') {
  4444. if (fn) {
  4445. fn();
  4446. }
  4447. script.onload = script.onreadystatechange = null;
  4448. head.removeChild(script);
  4449. }
  4450. };
  4451. }
  4452. function _chopQuery(url) {
  4453. var index = url.indexOf('?');
  4454. return index > 0 ? url.substr(0, index) : url;
  4455. }
  4456. function _loadStyle(url) {
  4457. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4458. link = document.createElement('link'),
  4459. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4460. var links = K('link[rel="stylesheet"]', head);
  4461. for (var i = 0, len = links.length; i < len; i++) {
  4462. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4463. return;
  4464. }
  4465. }
  4466. head.appendChild(link);
  4467. link.href = url;
  4468. link.rel = 'stylesheet';
  4469. }
  4470. function _ajax(url, fn, method, param, dataType) {
  4471. method = method || 'GET';
  4472. dataType = dataType || 'json';
  4473. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4474. xhr.open(method, url, true);
  4475. xhr.onreadystatechange = function () {
  4476. if (xhr.readyState == 4 && xhr.status == 200) {
  4477. if (fn) {
  4478. var data = _trim(xhr.responseText);
  4479. if (dataType == 'json') {
  4480. data = _json(data);
  4481. }
  4482. fn(data);
  4483. }
  4484. }
  4485. };
  4486. if (method == 'POST') {
  4487. var params = [];
  4488. _each(param, function (key, val) {
  4489. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4490. });
  4491. try {
  4492. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4493. } catch (e) {
  4494. }
  4495. xhr.send(params.join('&'));
  4496. } else {
  4497. xhr.send(null);
  4498. }
  4499. }
  4500. K.loadScript = _loadScript;
  4501. K.loadStyle = _loadStyle;
  4502. K.ajax = _ajax;
  4503. var _plugins = {};
  4504. function _plugin(name, fn) {
  4505. if (name === undefined) {
  4506. return _plugins;
  4507. }
  4508. if (!fn) {
  4509. return _plugins[name];
  4510. }
  4511. _plugins[name] = fn;
  4512. }
  4513. var _language = {};
  4514. function _parseLangKey(key) {
  4515. var match, ns = 'core';
  4516. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4517. ns = match[1];
  4518. key = match[2];
  4519. }
  4520. return {ns: ns, key: key};
  4521. }
  4522. function _lang(mixed, langType) {
  4523. langType = langType === undefined ? K.options.langType : langType;
  4524. if (typeof mixed === 'string') {
  4525. if (!_language[langType]) {
  4526. return 'no language';
  4527. }
  4528. var pos = mixed.length - 1;
  4529. if (mixed.substr(pos) === '.') {
  4530. return _language[langType][mixed.substr(0, pos)];
  4531. }
  4532. var obj = _parseLangKey(mixed);
  4533. return _language[langType][obj.ns][obj.key];
  4534. }
  4535. _each(mixed, function (key, val) {
  4536. var obj = _parseLangKey(key);
  4537. if (!_language[langType]) {
  4538. _language[langType] = {};
  4539. }
  4540. if (!_language[langType][obj.ns]) {
  4541. _language[langType][obj.ns] = {};
  4542. }
  4543. _language[langType][obj.ns][obj.key] = val;
  4544. });
  4545. }
  4546. function _getImageFromRange(range, fn) {
  4547. if (range.collapsed) {
  4548. return;
  4549. }
  4550. range = range.cloneRange().up();
  4551. var sc = range.startContainer, so = range.startOffset;
  4552. if (!_WEBKIT && !range.isControl()) {
  4553. return;
  4554. }
  4555. var img = K(sc.childNodes[so]);
  4556. if (!img || img.name != 'img') {
  4557. return;
  4558. }
  4559. if (fn(img)) {
  4560. return img;
  4561. }
  4562. }
  4563. function _bindContextmenuEvent() {
  4564. var self = this, doc = self.edit.doc;
  4565. K(doc).contextmenu(function (e) {
  4566. if (self.menu) {
  4567. self.hideMenu();
  4568. }
  4569. if (!self.useContextmenu) {
  4570. e.preventDefault();
  4571. return;
  4572. }
  4573. if (self._contextmenus.length === 0) {
  4574. return;
  4575. }
  4576. var maxWidth = 0, items = [];
  4577. _each(self._contextmenus, function () {
  4578. if (this.title == '-') {
  4579. items.push(this);
  4580. return;
  4581. }
  4582. if (this.cond && this.cond()) {
  4583. items.push(this);
  4584. if (this.width && this.width > maxWidth) {
  4585. maxWidth = this.width;
  4586. }
  4587. }
  4588. });
  4589. while (items.length > 0 && items[0].title == '-') {
  4590. items.shift();
  4591. }
  4592. while (items.length > 0 && items[items.length - 1].title == '-') {
  4593. items.pop();
  4594. }
  4595. var prevItem = null;
  4596. _each(items, function (i) {
  4597. if (this.title == '-' && prevItem.title == '-') {
  4598. delete items[i];
  4599. }
  4600. prevItem = this;
  4601. });
  4602. if (items.length > 0) {
  4603. e.preventDefault();
  4604. var pos = K(self.edit.iframe).pos(),
  4605. menu = _menu({
  4606. x: pos.x + e.clientX,
  4607. y: pos.y + e.clientY,
  4608. width: maxWidth,
  4609. css: {visibility: 'hidden'},
  4610. shadowMode: self.shadowMode
  4611. });
  4612. _each(items, function () {
  4613. if (this.title) {
  4614. menu.addItem(this);
  4615. }
  4616. });
  4617. var docEl = _docElement(menu.doc),
  4618. menuHeight = menu.div.height();
  4619. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4620. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4621. }
  4622. menu.div.css('visibility', 'visible');
  4623. self.menu = menu;
  4624. }
  4625. });
  4626. }
  4627. function _bindNewlineEvent() {
  4628. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4629. if (_IE && newlineTag !== 'br') {
  4630. return;
  4631. }
  4632. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4633. return;
  4634. }
  4635. if (_OPERA && _V < 9) {
  4636. return;
  4637. }
  4638. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4639. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4640. function getAncestorTagName(range) {
  4641. var ancestor = K(range.commonAncestor());
  4642. while (ancestor) {
  4643. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4644. break;
  4645. }
  4646. ancestor = ancestor.parent();
  4647. }
  4648. return ancestor.name;
  4649. }
  4650. K(doc).keydown(function (e) {
  4651. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4652. return;
  4653. }
  4654. self.cmd.selection();
  4655. var tagName = getAncestorTagName(self.cmd.range);
  4656. if (tagName == 'marquee' || tagName == 'select') {
  4657. return;
  4658. }
  4659. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4660. e.preventDefault();
  4661. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4662. return;
  4663. }
  4664. if (!pSkipTagMap[tagName]) {
  4665. _nativeCommand(doc, 'formatblock', '<p>');
  4666. }
  4667. });
  4668. K(doc).keyup(function (e) {
  4669. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4670. return;
  4671. }
  4672. if (newlineTag == 'br') {
  4673. return;
  4674. }
  4675. if (_GECKO) {
  4676. var root = self.cmd.commonAncestor('p');
  4677. var a = self.cmd.commonAncestor('a');
  4678. if (a && a.text() == '') {
  4679. a.remove(true);
  4680. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4681. self.cmd.select();
  4682. }
  4683. return;
  4684. }
  4685. self.cmd.selection();
  4686. var tagName = getAncestorTagName(self.cmd.range);
  4687. if (tagName == 'marquee' || tagName == 'select') {
  4688. return;
  4689. }
  4690. if (!pSkipTagMap[tagName]) {
  4691. _nativeCommand(doc, 'formatblock', '<p>');
  4692. }
  4693. var div = self.cmd.commonAncestor('div');
  4694. if (div) {
  4695. var p = K('<p></p>'),
  4696. child = div[0].firstChild;
  4697. while (child) {
  4698. var next = child.nextSibling;
  4699. p.append(child);
  4700. child = next;
  4701. }
  4702. div.before(p);
  4703. div.remove();
  4704. self.cmd.range.selectNodeContents(p[0]);
  4705. self.cmd.select();
  4706. }
  4707. });
  4708. }
  4709. function _bindTabEvent() {
  4710. var self = this, doc = self.edit.doc;
  4711. K(doc).keydown(function (e) {
  4712. if (e.which == 9) {
  4713. e.preventDefault();
  4714. if (self.afterTab) {
  4715. self.afterTab.call(self, e);
  4716. return;
  4717. }
  4718. var cmd = self.cmd, range = cmd.range;
  4719. range.shrink();
  4720. if (range.collapsed && range.startContainer.nodeType == 1) {
  4721. range.insertNode(K('@&nbsp;', doc)[0]);
  4722. cmd.select();
  4723. }
  4724. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4725. }
  4726. });
  4727. }
  4728. function _bindFocusEvent() {
  4729. var self = this;
  4730. K(self.edit.textarea[0], self.edit.win).focus(function (e) {
  4731. if (self.afterFocus) {
  4732. self.afterFocus.call(self, e);
  4733. }
  4734. }).blur(function (e) {
  4735. if (self.afterBlur) {
  4736. self.afterBlur.call(self, e);
  4737. }
  4738. });
  4739. }
  4740. function _removeBookmarkTag(html) {
  4741. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4742. }
  4743. function _removeTempTag(html) {
  4744. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4745. }
  4746. function _addBookmarkToStack(stack, bookmark) {
  4747. if (stack.length === 0) {
  4748. stack.push(bookmark);
  4749. return;
  4750. }
  4751. var prev = stack[stack.length - 1];
  4752. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4753. stack.push(bookmark);
  4754. }
  4755. }
  4756. function _undoToRedo(fromStack, toStack) {
  4757. var self = this, edit = self.edit,
  4758. body = edit.doc.body,
  4759. range, bookmark;
  4760. if (fromStack.length === 0) {
  4761. return self;
  4762. }
  4763. if (edit.designMode) {
  4764. range = self.cmd.range;
  4765. bookmark = range.createBookmark(true);
  4766. bookmark.html = body.innerHTML;
  4767. } else {
  4768. bookmark = {
  4769. html: body.innerHTML
  4770. };
  4771. }
  4772. _addBookmarkToStack(toStack, bookmark);
  4773. var prev = fromStack.pop();
  4774. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4775. prev = fromStack.pop();
  4776. }
  4777. if (edit.designMode) {
  4778. edit.html(prev.html);
  4779. if (prev.start) {
  4780. range.moveToBookmark(prev);
  4781. self.select();
  4782. }
  4783. } else {
  4784. K(body).html(_removeBookmarkTag(prev.html));
  4785. }
  4786. return self;
  4787. }
  4788. function KEditor(options) {
  4789. var self = this;
  4790. self.options = {};
  4791. function setOption(key, val) {
  4792. if (KEditor.prototype[key] === undefined) {
  4793. self[key] = val;
  4794. }
  4795. self.options[key] = val;
  4796. }
  4797. _each(options, function (key, val) {
  4798. setOption(key, options[key]);
  4799. });
  4800. _each(K.options, function (key, val) {
  4801. if (self[key] === undefined) {
  4802. setOption(key, val);
  4803. }
  4804. });
  4805. var se = K(self.srcElement || '<textarea/>');
  4806. if (!self.width) {
  4807. self.width = se[0].style.width || se.width();
  4808. }
  4809. if (!self.height) {
  4810. self.height = se[0].style.height || se.height();
  4811. }
  4812. setOption('width', _undef(self.width, self.minWidth));
  4813. setOption('height', _undef(self.height, self.minHeight));
  4814. setOption('width', _addUnit(self.width));
  4815. setOption('height', _addUnit(self.height));
  4816. if (_MOBILE && (!_IOS || _V < 534)) {
  4817. self.designMode = false;
  4818. }
  4819. self.srcElement = se;
  4820. self.initContent = '';
  4821. self.plugin = {};
  4822. self.isCreated = false;
  4823. self._handlers = {};
  4824. self._contextmenus = [];
  4825. self._undoStack = [];
  4826. self._redoStack = [];
  4827. self._firstAddBookmark = true;
  4828. self.menu = self.contextmenu = null;
  4829. self.dialogs = [];
  4830. }
  4831. KEditor.prototype = {
  4832. lang: function (mixed) {
  4833. return _lang(mixed, this.langType);
  4834. },
  4835. loadPlugin: function (name, fn) {
  4836. var self = this;
  4837. var _pluginStatus = this._pluginStatus;
  4838. if (!_pluginStatus) {
  4839. _pluginStatus = this._pluginStatus = {};
  4840. }
  4841. if (_plugins[name]) {
  4842. if (!_isFunction(_plugins[name])) {
  4843. setTimeout(function () {
  4844. self.loadPlugin(name, fn);
  4845. }, 100);
  4846. return self;
  4847. }
  4848. if (!_pluginStatus[name]) {
  4849. _plugins[name].call(self, KindEditor);
  4850. _pluginStatus[name] = 'inited';
  4851. }
  4852. if (fn) {
  4853. fn.call(self);
  4854. }
  4855. return self;
  4856. }
  4857. _plugins[name] = 'loading';
  4858. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function () {
  4859. setTimeout(function () {
  4860. if (_plugins[name]) {
  4861. self.loadPlugin(name, fn);
  4862. }
  4863. }, 0);
  4864. });
  4865. return self;
  4866. },
  4867. handler: function (key, fn) {
  4868. var self = this;
  4869. if (!self._handlers[key]) {
  4870. self._handlers[key] = [];
  4871. }
  4872. if (_isFunction(fn)) {
  4873. self._handlers[key].push(fn);
  4874. return self;
  4875. }
  4876. _each(self._handlers[key], function () {
  4877. fn = this.call(self, fn);
  4878. });
  4879. return fn;
  4880. },
  4881. clickToolbar: function (name, fn) {
  4882. var self = this, key = 'clickToolbar' + name;
  4883. if (fn === undefined) {
  4884. if (self._handlers[key]) {
  4885. return self.handler(key);
  4886. }
  4887. self.loadPlugin(name, function () {
  4888. self.handler(key);
  4889. });
  4890. return self;
  4891. }
  4892. return self.handler(key, fn);
  4893. },
  4894. updateState: function () {
  4895. var self = this;
  4896. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4897. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function (i, name) {
  4898. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4899. });
  4900. return self;
  4901. },
  4902. addContextmenu: function (item) {
  4903. this._contextmenus.push(item);
  4904. return this;
  4905. },
  4906. afterCreate: function (fn) {
  4907. return this.handler('afterCreate', fn);
  4908. },
  4909. beforeRemove: function (fn) {
  4910. return this.handler('beforeRemove', fn);
  4911. },
  4912. beforeGetHtml: function (fn) {
  4913. return this.handler('beforeGetHtml', fn);
  4914. },
  4915. beforeSetHtml: function (fn) {
  4916. return this.handler('beforeSetHtml', fn);
  4917. },
  4918. afterSetHtml: function (fn) {
  4919. return this.handler('afterSetHtml', fn);
  4920. },
  4921. create: function () {
  4922. var self = this, fullscreenMode = self.fullscreenMode;
  4923. if (self.isCreated) {
  4924. return self;
  4925. }
  4926. if (self.srcElement.data('kindeditor')) {
  4927. return self;
  4928. }
  4929. self.srcElement.data('kindeditor', 'true');
  4930. if (fullscreenMode) {
  4931. _docElement().style.overflow = 'hidden';
  4932. } else {
  4933. _docElement().style.overflow = '';
  4934. }
  4935. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4936. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4937. if ((_IE && _V < 8) || _QUIRKS) {
  4938. height = _addUnit(_removeUnit(height) + 2);
  4939. }
  4940. var container = self.container = K(self.layout);
  4941. if (fullscreenMode) {
  4942. K(document.body).append(container);
  4943. } else {
  4944. self.srcElement.before(container);
  4945. }
  4946. var toolbarDiv = K('.toolbar', container),
  4947. editDiv = K('.edit', container),
  4948. statusbar = self.statusbar = K('.statusbar', container);
  4949. container.removeClass('container')
  4950. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4951. if (fullscreenMode) {
  4952. container.css({
  4953. position: 'absolute',
  4954. left: 0,
  4955. top: 0,
  4956. 'z-index': 811211
  4957. });
  4958. if (!_GECKO) {
  4959. self._scrollPos = _getScrollPos();
  4960. }
  4961. window.scrollTo(0, 0);
  4962. K(document.body).css({
  4963. 'height': '1px',
  4964. 'overflow': 'hidden'
  4965. });
  4966. K(document.body.parentNode).css('overflow', 'hidden');
  4967. self._fullscreenExecuted = true;
  4968. } else {
  4969. if (self._fullscreenExecuted) {
  4970. K(document.body).css({
  4971. 'height': '',
  4972. 'overflow': ''
  4973. });
  4974. K(document.body.parentNode).css('overflow', '');
  4975. }
  4976. if (self._scrollPos) {
  4977. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4978. }
  4979. }
  4980. var htmlList = [];
  4981. K.each(self.items, function (i, name) {
  4982. if (name == '|') {
  4983. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4984. } else if (name == '/') {
  4985. htmlList.push('<div class="ke-hr"></div>');
  4986. } else {
  4987. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4988. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4989. }
  4990. });
  4991. var toolbar = self.toolbar = _toolbar({
  4992. src: toolbarDiv,
  4993. html: htmlList.join(''),
  4994. noDisableItems: self.noDisableItems,
  4995. click: function (e, name) {
  4996. e.stop();
  4997. if (self.menu) {
  4998. var menuName = self.menu.name;
  4999. self.hideMenu();
  5000. if (menuName === name) {
  5001. return;
  5002. }
  5003. }
  5004. self.clickToolbar(name);
  5005. }
  5006. });
  5007. var editHeight = _removeUnit(height) - toolbar.div.height();
  5008. var edit = self.edit = _edit({
  5009. height: editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5010. src: editDiv,
  5011. srcElement: self.srcElement,
  5012. designMode: self.designMode,
  5013. themesPath: self.themesPath,
  5014. bodyClass: self.bodyClass,
  5015. cssPath: self.cssPath,
  5016. cssData: self.cssData,
  5017. beforeGetHtml: function (html) {
  5018. html = self.beforeGetHtml(html);
  5019. html = _removeBookmarkTag(_removeTempTag(html));
  5020. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5021. },
  5022. beforeSetHtml: function (html) {
  5023. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5024. return self.beforeSetHtml(html);
  5025. },
  5026. afterSetHtml: function () {
  5027. self.edit = edit = this;
  5028. self.afterSetHtml();
  5029. },
  5030. afterCreate: function () {
  5031. self.edit = edit = this;
  5032. self.cmd = edit.cmd;
  5033. self._docMousedownFn = function (e) {
  5034. if (self.menu) {
  5035. self.hideMenu();
  5036. }
  5037. };
  5038. K(edit.doc, document).mousedown(self._docMousedownFn);
  5039. _bindContextmenuEvent.call(self);
  5040. _bindNewlineEvent.call(self);
  5041. _bindTabEvent.call(self);
  5042. _bindFocusEvent.call(self);
  5043. edit.afterChange(function (e) {
  5044. if (!edit.designMode) {
  5045. return;
  5046. }
  5047. self.updateState();
  5048. self.addBookmark();
  5049. if (self.options.afterChange) {
  5050. self.options.afterChange.call(self);
  5051. }
  5052. });
  5053. edit.textarea.keyup(function (e) {
  5054. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5055. if (self.options.afterChange) {
  5056. self.options.afterChange.call(self);
  5057. }
  5058. }
  5059. });
  5060. if (self.readonlyMode) {
  5061. self.readonly();
  5062. }
  5063. self.isCreated = true;
  5064. if (self.initContent === '') {
  5065. self.initContent = self.html();
  5066. }
  5067. if (self._undoStack.length > 0) {
  5068. var prev = self._undoStack.pop();
  5069. if (prev.start) {
  5070. self.html(prev.html);
  5071. edit.cmd.range.moveToBookmark(prev);
  5072. self.select();
  5073. }
  5074. }
  5075. self.afterCreate();
  5076. if (self.options.afterCreate) {
  5077. self.options.afterCreate.call(self);
  5078. }
  5079. }
  5080. });
  5081. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5082. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5083. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5084. if (self._fullscreenResizeHandler) {
  5085. K(window).unbind('resize', self._fullscreenResizeHandler);
  5086. self._fullscreenResizeHandler = null;
  5087. }
  5088. function initResize() {
  5089. if (statusbar.height() === 0) {
  5090. setTimeout(initResize, 100);
  5091. return;
  5092. }
  5093. self.resize(width, height, false);
  5094. }
  5095. initResize();
  5096. if (fullscreenMode) {
  5097. self._fullscreenResizeHandler = function (e) {
  5098. if (self.isCreated) {
  5099. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5100. }
  5101. };
  5102. K(window).bind('resize', self._fullscreenResizeHandler);
  5103. toolbar.select('fullscreen');
  5104. statusbar.first().css('visibility', 'hidden');
  5105. statusbar.last().css('visibility', 'hidden');
  5106. } else {
  5107. if (_GECKO) {
  5108. K(window).bind('scroll', function (e) {
  5109. self._scrollPos = _getScrollPos();
  5110. });
  5111. }
  5112. if (self.resizeType > 0) {
  5113. _drag({
  5114. moveEl: container,
  5115. clickEl: statusbar,
  5116. moveFn: function (x, y, width, height, diffX, diffY) {
  5117. height += diffY;
  5118. self.resize(null, height);
  5119. }
  5120. });
  5121. } else {
  5122. statusbar.first().css('visibility', 'hidden');
  5123. }
  5124. if (self.resizeType === 2) {
  5125. _drag({
  5126. moveEl: container,
  5127. clickEl: statusbar.last(),
  5128. moveFn: function (x, y, width, height, diffX, diffY) {
  5129. width += diffX;
  5130. height += diffY;
  5131. self.resize(width, height);
  5132. }
  5133. });
  5134. } else {
  5135. statusbar.last().css('visibility', 'hidden');
  5136. }
  5137. }
  5138. return self;
  5139. },
  5140. remove: function () {
  5141. var self = this;
  5142. if (!self.isCreated) {
  5143. return self;
  5144. }
  5145. self.beforeRemove();
  5146. self.srcElement.data('kindeditor', '');
  5147. if (self.menu) {
  5148. self.hideMenu();
  5149. }
  5150. _each(self.dialogs, function () {
  5151. self.hideDialog();
  5152. });
  5153. K(document).unbind('mousedown', self._docMousedownFn);
  5154. self.toolbar.remove();
  5155. self.edit.remove();
  5156. self.statusbar.last().unbind();
  5157. self.statusbar.unbind();
  5158. self.container.remove();
  5159. self.container = self.toolbar = self.edit = self.menu = null;
  5160. self.dialogs = [];
  5161. self.isCreated = false;
  5162. return self;
  5163. },
  5164. resize: function (width, height, updateProp) {
  5165. var self = this;
  5166. updateProp = _undef(updateProp, true);
  5167. if (width) {
  5168. if (!/%/.test(width)) {
  5169. width = _removeUnit(width);
  5170. width = width < self.minWidth ? self.minWidth : width;
  5171. }
  5172. self.container.css('width', _addUnit(width));
  5173. if (updateProp) {
  5174. self.width = _addUnit(width);
  5175. }
  5176. }
  5177. if (height) {
  5178. height = _removeUnit(height);
  5179. editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5180. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5181. self.edit.setHeight(editHeight);
  5182. if (updateProp) {
  5183. self.height = _addUnit(height);
  5184. }
  5185. }
  5186. return self;
  5187. },
  5188. select: function () {
  5189. this.isCreated && this.cmd.select();
  5190. return this;
  5191. },
  5192. html: function (val) {
  5193. var self = this;
  5194. if (val === undefined) {
  5195. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5196. }
  5197. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5198. if (self.isCreated) {
  5199. self.cmd.selection();
  5200. }
  5201. return self;
  5202. },
  5203. fullHtml: function () {
  5204. return this.isCreated ? this.edit.html(undefined, true) : '';
  5205. },
  5206. text: function (val) {
  5207. var self = this;
  5208. if (val === undefined) {
  5209. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5210. } else {
  5211. return self.html(_escape(val));
  5212. }
  5213. },
  5214. isEmpty: function () {
  5215. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5216. },
  5217. isDirty: function () {
  5218. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5219. },
  5220. selectedHtml: function () {
  5221. var val = this.isCreated ? this.cmd.range.html() : '';
  5222. val = _removeBookmarkTag(_removeTempTag(val));
  5223. return val;
  5224. },
  5225. count: function (mode) {
  5226. var self = this;
  5227. mode = (mode || 'html').toLowerCase();
  5228. if (mode === 'html') {
  5229. return self.html().length;
  5230. }
  5231. if (mode === 'text') {
  5232. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5233. }
  5234. return 0;
  5235. },
  5236. exec: function (key) {
  5237. key = key.toLowerCase();
  5238. var self = this, cmd = self.cmd,
  5239. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5240. if (changeFlag) {
  5241. self.addBookmark(false);
  5242. }
  5243. cmd[key].apply(cmd, _toArray(arguments, 1));
  5244. if (changeFlag) {
  5245. self.updateState();
  5246. self.addBookmark(false);
  5247. if (self.options.afterChange) {
  5248. self.options.afterChange.call(self);
  5249. }
  5250. }
  5251. return self;
  5252. },
  5253. insertHtml: function (val, quickMode) {
  5254. if (!this.isCreated) {
  5255. return this;
  5256. }
  5257. val = this.beforeSetHtml(val);
  5258. this.exec('inserthtml', val, quickMode);
  5259. return this;
  5260. },
  5261. appendHtml: function (val) {
  5262. this.html(this.html() + val);
  5263. if (this.isCreated) {
  5264. var cmd = this.cmd;
  5265. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5266. cmd.select();
  5267. }
  5268. return this;
  5269. },
  5270. sync: function () {
  5271. _elementVal(this.srcElement, this.html());
  5272. return this;
  5273. },
  5274. focus: function () {
  5275. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5276. return this;
  5277. },
  5278. blur: function () {
  5279. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5280. return this;
  5281. },
  5282. addBookmark: function (checkSize) {
  5283. checkSize = _undef(checkSize, true);
  5284. var self = this, edit = self.edit,
  5285. body = edit.doc.body,
  5286. html = _removeTempTag(body.innerHTML), bookmark;
  5287. if (checkSize && self._undoStack.length > 0) {
  5288. var prev = self._undoStack[self._undoStack.length - 1];
  5289. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5290. return self;
  5291. }
  5292. }
  5293. if (edit.designMode && !self._firstAddBookmark) {
  5294. var range = self.cmd.range;
  5295. bookmark = range.createBookmark(true);
  5296. bookmark.html = _removeTempTag(body.innerHTML);
  5297. range.moveToBookmark(bookmark);
  5298. } else {
  5299. bookmark = {
  5300. html: html
  5301. };
  5302. }
  5303. self._firstAddBookmark = false;
  5304. _addBookmarkToStack(self._undoStack, bookmark);
  5305. return self;
  5306. },
  5307. undo: function () {
  5308. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5309. },
  5310. redo: function () {
  5311. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5312. },
  5313. fullscreen: function (bool) {
  5314. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5315. this.addBookmark(false);
  5316. return this.remove().create();
  5317. },
  5318. readonly: function (isReadonly) {
  5319. isReadonly = _undef(isReadonly, true);
  5320. var self = this, edit = self.edit, doc = edit.doc;
  5321. if (self.designMode) {
  5322. self.toolbar.disableAll(isReadonly, []);
  5323. } else {
  5324. _each(self.noDisableItems, function () {
  5325. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5326. });
  5327. }
  5328. if (_IE) {
  5329. doc.body.contentEditable = !isReadonly;
  5330. } else {
  5331. doc.designMode = isReadonly ? 'off' : 'on';
  5332. }
  5333. edit.textarea[0].disabled = isReadonly;
  5334. },
  5335. createMenu: function (options) {
  5336. var self = this,
  5337. name = options.name,
  5338. knode = self.toolbar.get(name),
  5339. pos = knode.pos();
  5340. options.x = pos.x;
  5341. options.y = pos.y + knode.height();
  5342. options.z = self.options.zIndex;
  5343. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5344. if (options.selectedColor !== undefined) {
  5345. options.cls = 'ke-colorpicker-' + self.themeType;
  5346. options.noColor = self.lang('noColor');
  5347. self.menu = _colorpicker(options);
  5348. } else {
  5349. options.cls = 'ke-menu-' + self.themeType;
  5350. options.centerLineMode = false;
  5351. self.menu = _menu(options);
  5352. }
  5353. return self.menu;
  5354. },
  5355. hideMenu: function () {
  5356. this.menu.remove();
  5357. this.menu = null;
  5358. return this;
  5359. },
  5360. hideContextmenu: function () {
  5361. this.contextmenu.remove();
  5362. this.contextmenu = null;
  5363. return this;
  5364. },
  5365. createDialog: function (options) {
  5366. var self = this, name = options.name;
  5367. options.z = self.options.zIndex;
  5368. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5369. options.closeBtn = _undef(options.closeBtn, {
  5370. name: self.lang('close'),
  5371. click: function (e) {
  5372. self.hideDialog();
  5373. if (_IE && self.cmd) {
  5374. self.cmd.select();
  5375. }
  5376. }
  5377. });
  5378. options.noBtn = _undef(options.noBtn, {
  5379. name: self.lang(options.yesBtn ? 'no' : 'close'),
  5380. click: function (e) {
  5381. self.hideDialog();
  5382. if (_IE && self.cmd) {
  5383. self.cmd.select();
  5384. }
  5385. }
  5386. });
  5387. if (self.dialogAlignType != 'page') {
  5388. options.alignEl = self.container;
  5389. }
  5390. options.cls = 'ke-dialog-' + self.themeType;
  5391. if (self.dialogs.length > 0) {
  5392. var firstDialog = self.dialogs[0],
  5393. parentDialog = self.dialogs[self.dialogs.length - 1];
  5394. firstDialog.setMaskIndex(parentDialog.z + 2);
  5395. options.z = parentDialog.z + 3;
  5396. options.showMask = false;
  5397. }
  5398. var dialog = _dialog(options);
  5399. self.dialogs.push(dialog);
  5400. return dialog;
  5401. },
  5402. hideDialog: function () {
  5403. var self = this;
  5404. if (self.dialogs.length > 0) {
  5405. self.dialogs.pop().remove();
  5406. }
  5407. if (self.dialogs.length > 0) {
  5408. var firstDialog = self.dialogs[0],
  5409. parentDialog = self.dialogs[self.dialogs.length - 1];
  5410. firstDialog.setMaskIndex(parentDialog.z - 1);
  5411. }
  5412. return self;
  5413. },
  5414. errorDialog: function (html) {
  5415. var self = this;
  5416. var dialog = self.createDialog({
  5417. width: 750,
  5418. title: self.lang('uploadError'),
  5419. body: '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5420. });
  5421. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5422. doc.open();
  5423. doc.write(html);
  5424. doc.close();
  5425. K(doc.body).css('background-color', '#FFF');
  5426. iframe[0].contentWindow.focus();
  5427. return self;
  5428. }
  5429. };
  5430. function _editor(options) {
  5431. return new KEditor(options);
  5432. }
  5433. _instances = [];
  5434. function _create(expr, options) {
  5435. options = options || {};
  5436. options.basePath = _undef(options.basePath, K.basePath);
  5437. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5438. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5439. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5440. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5441. var themeType = _undef(options.themeType, K.options.themeType);
  5442. _loadStyle(options.themesPath + 'default/default.css');
  5443. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5444. }
  5445. function create(editor) {
  5446. _each(_plugins, function (name, fn) {
  5447. if (_isFunction(fn)) {
  5448. fn.call(editor, KindEditor);
  5449. if (!editor._pluginStatus) {
  5450. editor._pluginStatus = {};
  5451. }
  5452. editor._pluginStatus[name] = 'inited';
  5453. }
  5454. });
  5455. return editor.create();
  5456. }
  5457. var knode = K(expr);
  5458. if (!knode || knode.length === 0) {
  5459. return;
  5460. }
  5461. if (knode.length > 1) {
  5462. knode.each(function () {
  5463. _create(this, options);
  5464. });
  5465. return _instances[0];
  5466. }
  5467. options.srcElement = knode[0];
  5468. var editor = new KEditor(options);
  5469. _instances.push(editor);
  5470. if (_language[editor.langType]) {
  5471. return create(editor);
  5472. }
  5473. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function () {
  5474. create(editor);
  5475. });
  5476. return editor;
  5477. }
  5478. function _eachEditor(expr, fn) {
  5479. K(expr).each(function (i, el) {
  5480. K.each(_instances, function (j, editor) {
  5481. if (editor && editor.srcElement[0] == el) {
  5482. fn.call(editor, j);
  5483. return false;
  5484. }
  5485. });
  5486. });
  5487. }
  5488. K.remove = function (expr) {
  5489. _eachEditor(expr, function (i) {
  5490. this.remove();
  5491. _instances.splice(i, 1);
  5492. });
  5493. };
  5494. K.sync = function (expr) {
  5495. _eachEditor(expr, function () {
  5496. this.sync();
  5497. });
  5498. };
  5499. K.html = function (expr, val) {
  5500. _eachEditor(expr, function () {
  5501. this.html(val);
  5502. });
  5503. };
  5504. K.insertHtml = function (expr, val) {
  5505. _eachEditor(expr, function () {
  5506. this.insertHtml(val);
  5507. });
  5508. };
  5509. K.appendHtml = function (expr, val) {
  5510. _eachEditor(expr, function () {
  5511. this.appendHtml(val);
  5512. });
  5513. };
  5514. if (_IE && _V < 7) {
  5515. _nativeCommand(document, 'BackgroundImageCache', true);
  5516. }
  5517. K.EditorClass = KEditor;
  5518. K.editor = _editor;
  5519. K.create = _create;
  5520. K.instances = _instances;
  5521. K.plugin = _plugin;
  5522. K.lang = _lang;
  5523. _plugin('core', function (K) {
  5524. var self = this,
  5525. shortcutKeys = {
  5526. undo: 'Z', redo: 'Y', bold: 'B', italic: 'I', underline: 'U', print: 'P', selectall: 'A'
  5527. };
  5528. self.afterSetHtml(function () {
  5529. if (self.options.afterChange) {
  5530. self.options.afterChange.call(self);
  5531. }
  5532. });
  5533. self.afterCreate(function () {
  5534. if (self.syncType != 'form') {
  5535. return;
  5536. }
  5537. var el = K(self.srcElement), hasForm = false;
  5538. while ((el = el.parent())) {
  5539. if (el.name == 'form') {
  5540. hasForm = true;
  5541. break;
  5542. }
  5543. }
  5544. if (hasForm) {
  5545. el.bind('submit', function (e) {
  5546. self.sync();
  5547. K(window).bind('unload', function () {
  5548. self.edit.textarea.remove();
  5549. });
  5550. });
  5551. var resetBtn = K('[type="reset"]', el);
  5552. resetBtn.click(function () {
  5553. self.html(self.initContent);
  5554. self.cmd.selection();
  5555. });
  5556. self.beforeRemove(function () {
  5557. el.unbind();
  5558. resetBtn.unbind();
  5559. });
  5560. }
  5561. });
  5562. self.clickToolbar('source', function () {
  5563. if (self.edit.designMode) {
  5564. self.toolbar.disableAll(true);
  5565. self.edit.design(false);
  5566. self.toolbar.select('source');
  5567. } else {
  5568. self.toolbar.disableAll(false);
  5569. self.edit.design(true);
  5570. self.toolbar.unselect('source');
  5571. if (_GECKO) {
  5572. setTimeout(function () {
  5573. self.cmd.selection();
  5574. }, 0);
  5575. } else {
  5576. self.cmd.selection();
  5577. }
  5578. }
  5579. self.designMode = self.edit.designMode;
  5580. });
  5581. self.afterCreate(function () {
  5582. if (!self.designMode) {
  5583. self.toolbar.disableAll(true).select('source');
  5584. }
  5585. });
  5586. self.clickToolbar('fullscreen', function () {
  5587. self.fullscreen();
  5588. });
  5589. if (self.fullscreenShortcut) {
  5590. var loaded = false;
  5591. self.afterCreate(function () {
  5592. K(self.edit.doc, self.edit.textarea).keyup(function (e) {
  5593. if (e.which == 27) {
  5594. setTimeout(function () {
  5595. self.fullscreen();
  5596. }, 0);
  5597. }
  5598. });
  5599. if (loaded) {
  5600. if (_IE && !self.designMode) {
  5601. return;
  5602. }
  5603. self.focus();
  5604. }
  5605. if (!loaded) {
  5606. loaded = true;
  5607. }
  5608. });
  5609. }
  5610. _each('undo,redo'.split(','), function (i, name) {
  5611. if (shortcutKeys[name]) {
  5612. self.afterCreate(function () {
  5613. _ctrl(this.edit.doc, shortcutKeys[name], function () {
  5614. self.clickToolbar(name);
  5615. });
  5616. });
  5617. }
  5618. self.clickToolbar(name, function () {
  5619. self[name]();
  5620. });
  5621. });
  5622. self.clickToolbar('formatblock', function () {
  5623. var blocks = self.lang('formatblock.formatBlock'),
  5624. heights = {
  5625. h1: 28,
  5626. h2: 24,
  5627. h3: 18,
  5628. H4: 14,
  5629. p: 12
  5630. },
  5631. curVal = self.cmd.val('formatblock'),
  5632. menu = self.createMenu({
  5633. name: 'formatblock',
  5634. width: self.langType == 'en' ? 200 : 150
  5635. });
  5636. _each(blocks, function (key, val) {
  5637. var style = 'font-size:' + heights[key] + 'px;';
  5638. if (key.charAt(0) === 'h') {
  5639. style += 'font-weight:bold;';
  5640. }
  5641. menu.addItem({
  5642. title: '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5643. height: heights[key] + 12,
  5644. checked: (curVal === key || curVal === val),
  5645. click: function () {
  5646. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5647. }
  5648. });
  5649. });
  5650. });
  5651. self.clickToolbar('fontname', function () {
  5652. var curVal = self.cmd.val('fontname'),
  5653. menu = self.createMenu({
  5654. name: 'fontname',
  5655. width: 150
  5656. });
  5657. _each(self.lang('fontname.fontName'), function (key, val) {
  5658. menu.addItem({
  5659. title: '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5660. checked: (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5661. click: function () {
  5662. self.exec('fontname', key).hideMenu();
  5663. }
  5664. });
  5665. });
  5666. });
  5667. self.clickToolbar('fontsize', function () {
  5668. var curVal = self.cmd.val('fontsize'),
  5669. menu = self.createMenu({
  5670. name: 'fontsize',
  5671. width: 150
  5672. });
  5673. _each(self.fontSizeTable, function (i, val) {
  5674. menu.addItem({
  5675. title: '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5676. height: _removeUnit(val) + 12,
  5677. checked: curVal === val,
  5678. click: function () {
  5679. self.exec('fontsize', val).hideMenu();
  5680. }
  5681. });
  5682. });
  5683. });
  5684. _each('forecolor,hilitecolor'.split(','), function (i, name) {
  5685. self.clickToolbar(name, function () {
  5686. self.createMenu({
  5687. name: name,
  5688. selectedColor: self.cmd.val(name) || 'default',
  5689. colors: self.colorTable,
  5690. click: function (color) {
  5691. self.exec(name, color).hideMenu();
  5692. }
  5693. });
  5694. });
  5695. });
  5696. _each(('cut,copy,paste').split(','), function (i, name) {
  5697. self.clickToolbar(name, function () {
  5698. self.focus();
  5699. try {
  5700. self.exec(name, null);
  5701. } catch (e) {
  5702. alert(self.lang(name + 'Error'));
  5703. }
  5704. });
  5705. });
  5706. self.clickToolbar('about', function () {
  5707. var html = '<div style="margin:20px;">' +
  5708. '<div>KindEditor ' + _VERSION + '</div>' +
  5709. '<div>Copyright &copy; <a href="http://www.kindeditor.net/" target="_blank">kindeditor.net</a> All rights reserved.</div>' +
  5710. '</div>';
  5711. self.createDialog({
  5712. name: 'about',
  5713. width: 350,
  5714. title: self.lang('about'),
  5715. body: html
  5716. });
  5717. });
  5718. self.plugin.getSelectedLink = function () {
  5719. return self.cmd.commonAncestor('a');
  5720. };
  5721. self.plugin.getSelectedImage = function () {
  5722. return _getImageFromRange(self.edit.cmd.range, function (img) {
  5723. return !/^ke-\w+$/i.test(img[0].className);
  5724. });
  5725. };
  5726. self.plugin.getSelectedFlash = function () {
  5727. return _getImageFromRange(self.edit.cmd.range, function (img) {
  5728. return img[0].className == 'ke-flash';
  5729. });
  5730. };
  5731. self.plugin.getSelectedMedia = function () {
  5732. return _getImageFromRange(self.edit.cmd.range, function (img) {
  5733. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5734. });
  5735. };
  5736. self.plugin.getSelectedAnchor = function () {
  5737. return _getImageFromRange(self.edit.cmd.range, function (img) {
  5738. return img[0].className == 'ke-anchor';
  5739. });
  5740. };
  5741. _each('link,image,flash,media,anchor'.split(','), function (i, name) {
  5742. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5743. _each('edit,delete'.split(','), function (j, val) {
  5744. self.addContextmenu({
  5745. title: self.lang(val + uName),
  5746. click: function () {
  5747. self.loadPlugin(name, function () {
  5748. self.plugin[name][val]();
  5749. self.hideMenu();
  5750. });
  5751. },
  5752. cond: self.plugin['getSelected' + uName],
  5753. width: 150,
  5754. iconClass: val == 'edit' ? 'ke-icon-' + name : undefined
  5755. });
  5756. });
  5757. self.addContextmenu({title: '-'});
  5758. });
  5759. self.plugin.getSelectedTable = function () {
  5760. return self.cmd.commonAncestor('table');
  5761. };
  5762. self.plugin.getSelectedRow = function () {
  5763. return self.cmd.commonAncestor('tr');
  5764. };
  5765. self.plugin.getSelectedCell = function () {
  5766. return self.cmd.commonAncestor('td');
  5767. };
  5768. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5769. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function (i, val) {
  5770. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5771. self.addContextmenu({
  5772. title: self.lang('table' + val),
  5773. click: function () {
  5774. self.loadPlugin('table', function () {
  5775. self.plugin.table[val]();
  5776. self.hideMenu();
  5777. });
  5778. },
  5779. cond: cond,
  5780. width: 170,
  5781. iconClass: 'ke-icon-table' + val
  5782. });
  5783. });
  5784. self.addContextmenu({title: '-'});
  5785. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5786. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5787. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function (i, name) {
  5788. if (shortcutKeys[name]) {
  5789. self.afterCreate(function () {
  5790. _ctrl(this.edit.doc, shortcutKeys[name], function () {
  5791. self.cmd.selection();
  5792. self.clickToolbar(name);
  5793. });
  5794. });
  5795. }
  5796. self.clickToolbar(name, function () {
  5797. self.focus().exec(name, null);
  5798. });
  5799. });
  5800. self.afterCreate(function () {
  5801. var doc = self.edit.doc, cmd, bookmark, div,
  5802. cls = '__kindeditor_paste__', pasting = false;
  5803. function movePastedData() {
  5804. cmd.range.moveToBookmark(bookmark);
  5805. cmd.select();
  5806. if (_WEBKIT) {
  5807. K('div.' + cls, div).each(function () {
  5808. K(this).after('<br />').remove(true);
  5809. });
  5810. K('span.Apple-style-span', div).remove(true);
  5811. K('span.Apple-tab-span', div).remove(true);
  5812. K('span[style]', div).each(function () {
  5813. if (K(this).css('white-space') == 'nowrap') {
  5814. K(this).remove(true);
  5815. }
  5816. });
  5817. K('meta', div).remove();
  5818. }
  5819. var html = div[0].innerHTML;
  5820. div.remove();
  5821. if (html === '') {
  5822. return;
  5823. }
  5824. if (_WEBKIT) {
  5825. html = html.replace(/(<br>)\1/ig, '$1');
  5826. }
  5827. if (self.pasteType === 2) {
  5828. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5829. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5830. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5831. } else {
  5832. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5833. html = self.beforeSetHtml(html);
  5834. }
  5835. }
  5836. if (self.pasteType === 1) {
  5837. html = html.replace(/&nbsp;/ig, ' ');
  5838. html = html.replace(/\n\s*\n/g, '\n');
  5839. html = html.replace(/<br[^>]*>/ig, '\n');
  5840. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5841. html = html.replace(/<[^>]+>/g, '');
  5842. html = html.replace(/ {2}/g, ' &nbsp;');
  5843. if (self.newlineTag == 'p') {
  5844. if (/\n/.test(html)) {
  5845. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5846. }
  5847. } else {
  5848. html = html.replace(/\n/g, '<br />$&');
  5849. }
  5850. }
  5851. self.insertHtml(html, true);
  5852. }
  5853. K(doc.body).bind('paste', function (e) {
  5854. if (self.pasteType === 0) {
  5855. e.stop();
  5856. return;
  5857. }
  5858. if (pasting) {
  5859. return;
  5860. }
  5861. pasting = true;
  5862. K('div.' + cls, doc).remove();
  5863. cmd = self.cmd.selection();
  5864. bookmark = cmd.range.createBookmark();
  5865. div = K('<div class="' + cls + '"></div>', doc).css({
  5866. position: 'absolute',
  5867. width: '1px',
  5868. height: '1px',
  5869. overflow: 'hidden',
  5870. left: '-1981px',
  5871. top: K(bookmark.start).pos().y + 'px',
  5872. 'white-space': 'nowrap'
  5873. });
  5874. K(doc.body).append(div);
  5875. if (_IE) {
  5876. var rng = cmd.range.get(true);
  5877. rng.moveToElementText(div[0]);
  5878. rng.select();
  5879. rng.execCommand('paste');
  5880. e.preventDefault();
  5881. } else {
  5882. cmd.range.selectNodeContents(div[0]);
  5883. cmd.select();
  5884. div[0].tabIndex = -1;
  5885. div[0].focus();
  5886. }
  5887. setTimeout(function () {
  5888. movePastedData();
  5889. pasting = false;
  5890. }, 0);
  5891. });
  5892. });
  5893. self.beforeGetHtml(function (html) {
  5894. if (_IE && _V <= 8) {
  5895. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function (full, tag) {
  5896. return unescape(tag);
  5897. });
  5898. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function ($0, $1, $2) {
  5899. if (!/\s+type="[^"]+"/i.test($0)) {
  5900. return $1 + ' type="text"' + $2;
  5901. }
  5902. return $0;
  5903. });
  5904. }
  5905. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function ($0, $1, $2, $3) {
  5906. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5907. })
  5908. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function (full) {
  5909. var imgAttrs = _getAttrList(full);
  5910. var styles = _getCssList(imgAttrs.style || '');
  5911. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5912. var width = _undef(styles.width, '');
  5913. var height = _undef(styles.height, '');
  5914. if (/px/i.test(width)) {
  5915. width = _removeUnit(width);
  5916. }
  5917. if (/px/i.test(height)) {
  5918. height = _removeUnit(height);
  5919. }
  5920. attrs.width = _undef(imgAttrs.width, width);
  5921. attrs.height = _undef(imgAttrs.height, height);
  5922. return _mediaEmbed(attrs);
  5923. })
  5924. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function (full) {
  5925. var imgAttrs = _getAttrList(full);
  5926. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5927. })
  5928. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function (full, attr, code) {
  5929. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5930. })
  5931. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function (full, attr, code) {
  5932. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5933. })
  5934. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function (full, start, src, end) {
  5935. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function ($0, $1, $2) {
  5936. return $1 + _unescape(src) + $2;
  5937. });
  5938. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5939. return full;
  5940. })
  5941. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function (full, start, end) {
  5942. return start + end;
  5943. });
  5944. });
  5945. self.beforeSetHtml(function (html) {
  5946. if (_IE && _V <= 8) {
  5947. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function (full) {
  5948. var attrs = _getAttrList(full);
  5949. var styles = _getCssList(attrs.style || '');
  5950. if (styles.display == 'none') {
  5951. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5952. }
  5953. return full;
  5954. });
  5955. }
  5956. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function (full) {
  5957. var attrs = _getAttrList(full);
  5958. attrs.src = _undef(attrs.src, '');
  5959. attrs.width = _undef(attrs.width, 0);
  5960. attrs.height = _undef(attrs.height, 0);
  5961. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5962. })
  5963. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function (full) {
  5964. var attrs = _getAttrList(full);
  5965. if (attrs.href !== undefined) {
  5966. return full;
  5967. }
  5968. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5969. })
  5970. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function (full, attr, code) {
  5971. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5972. })
  5973. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function (full, attr, code) {
  5974. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5975. })
  5976. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function (full, start, key, src, end) {
  5977. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5978. return full;
  5979. }
  5980. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5981. return full;
  5982. })
  5983. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function (full, start, end) {
  5984. return start + 'data-ke-' + end;
  5985. })
  5986. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function (full) {
  5987. if (full.indexOf('ke-zeroborder') >= 0) {
  5988. return full;
  5989. }
  5990. return _addClassToTag(full, 'ke-zeroborder');
  5991. });
  5992. });
  5993. });
  5994. })(window);
  5995. /*******************************************************************************
  5996. * KindEditor - WYSIWYG HTML Editor for Internet
  5997. * Copyright (C) 2006-2011 kindeditor.net
  5998. *
  5999. * @author Roddy <luolonghao@gmail.com>
  6000. * @site http://www.kindeditor.net/
  6001. * @licence http://www.kindeditor.net/license.php
  6002. *******************************************************************************/
  6003. KindEditor.lang({
  6004. source: 'HTML代码',
  6005. preview: '预览',
  6006. undo: '后退(Ctrl+Z)',
  6007. redo: '前进(Ctrl+Y)',
  6008. cut: '剪切(Ctrl+X)',
  6009. copy: '复制(Ctrl+C)',
  6010. paste: '粘贴(Ctrl+V)',
  6011. plainpaste: '粘贴为无格式文本',
  6012. wordpaste: '从Word粘贴',
  6013. selectall: '全选(Ctrl+A)',
  6014. justifyleft: '左对齐',
  6015. justifycenter: '居中',
  6016. justifyright: '右对齐',
  6017. justifyfull: '两端对齐',
  6018. insertorderedlist: '编号',
  6019. insertunorderedlist: '项目符号',
  6020. indent: '增加缩进',
  6021. outdent: '减少缩进',
  6022. subscript: '下标',
  6023. superscript: '上标',
  6024. formatblock: '段落',
  6025. fontname: '字体',
  6026. fontsize: '文字大小',
  6027. forecolor: '文字颜色',
  6028. hilitecolor: '文字背景',
  6029. bold: '粗体(Ctrl+B)',
  6030. italic: '斜体(Ctrl+I)',
  6031. underline: '下划线(Ctrl+U)',
  6032. strikethrough: '删除线',
  6033. removeformat: '删除格式',
  6034. image: '图片',
  6035. multiimage: '批量图片上传',
  6036. flash: 'Flash',
  6037. media: '视音频',
  6038. table: '表格',
  6039. tablecell: '单元格',
  6040. hr: '插入横线',
  6041. emoticons: '插入表情',
  6042. link: '超级链接',
  6043. unlink: '取消超级链接',
  6044. fullscreen: '全屏显示',
  6045. about: '关于',
  6046. print: '打印(Ctrl+P)',
  6047. filemanager: '文件空间',
  6048. code: '插入程序代码',
  6049. map: 'Google地图',
  6050. baidumap: '百度地图',
  6051. lineheight: '行距',
  6052. clearhtml: '清理HTML代码',
  6053. pagebreak: '插入分页符',
  6054. quickformat: '一键排版',
  6055. insertfile: '插入文件',
  6056. template: '插入模板',
  6057. anchor: '锚点',
  6058. yes: '确定',
  6059. no: '取消',
  6060. close: '关闭',
  6061. editImage: '图片属性',
  6062. deleteImage: '删除图片',
  6063. editFlash: 'Flash属性',
  6064. deleteFlash: '删除Flash',
  6065. editMedia: '视音频属性',
  6066. deleteMedia: '删除视音频',
  6067. editLink: '超级链接属性',
  6068. deleteLink: '取消超级链接',
  6069. editAnchor: '锚点属性',
  6070. deleteAnchor: '删除锚点',
  6071. tableprop: '表格属性',
  6072. tablecellprop: '单元格属性',
  6073. tableinsert: '插入表格',
  6074. tabledelete: '删除表格',
  6075. tablecolinsertleft: '左侧插入列',
  6076. tablecolinsertright: '右侧插入列',
  6077. tablerowinsertabove: '上方插入行',
  6078. tablerowinsertbelow: '下方插入行',
  6079. tablerowmerge: '向下合并单元格',
  6080. tablecolmerge: '向右合并单元格',
  6081. tablerowsplit: '拆分行',
  6082. tablecolsplit: '拆分列',
  6083. tablecoldelete: '删除列',
  6084. tablerowdelete: '删除行',
  6085. noColor: '无颜色',
  6086. pleaseSelectFile: '请选择文件。',
  6087. invalidImg: "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6088. invalidMedia: "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6089. invalidWidth: "宽度必须为数字。",
  6090. invalidHeight: "高度必须为数字。",
  6091. invalidBorder: "边框必须为数字。",
  6092. invalidUrl: "请输入有效的URL地址。",
  6093. invalidRows: '行数为必选项,只允许输入大于0的数字。',
  6094. invalidCols: '列数为必选项,只允许输入大于0的数字。',
  6095. invalidPadding: '边距必须为数字。',
  6096. invalidSpacing: '间距必须为数字。',
  6097. invalidJson: '服务器发生故障。',
  6098. uploadSuccess: '上传成功。',
  6099. cutError: '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6100. copyError: '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6101. pasteError: '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6102. ajaxLoading: '加载中,请稍候 ...',
  6103. uploadLoading: '上传中,请稍候 ...',
  6104. uploadError: '上传错误',
  6105. 'plainpaste.comment': '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6106. 'wordpaste.comment': '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6107. 'code.pleaseInput': '请输入程序代码。',
  6108. 'link.url': 'URL',
  6109. 'link.linkType': '打开类型',
  6110. 'link.newWindow': '新窗口',
  6111. 'link.selfWindow': '当前窗口',
  6112. 'flash.url': 'URL',
  6113. 'flash.width': '宽度',
  6114. 'flash.height': '高度',
  6115. 'flash.upload': '上传',
  6116. 'flash.viewServer': '文件空间',
  6117. 'media.url': 'URL',
  6118. 'media.width': '宽度',
  6119. 'media.height': '高度',
  6120. 'media.autostart': '自动播放',
  6121. 'media.upload': '上传',
  6122. 'media.viewServer': '文件空间',
  6123. 'image.remoteImage': '网络图片',
  6124. 'image.localImage': '本地上传',
  6125. 'image.remoteUrl': '图片地址',
  6126. 'image.localUrl': '上传文件',
  6127. 'image.size': '图片大小',
  6128. 'image.width': '宽',
  6129. 'image.height': '高',
  6130. 'image.resetSize': '重置大小',
  6131. 'image.align': '对齐方式',
  6132. 'image.defaultAlign': '默认方式',
  6133. 'image.leftAlign': '左对齐',
  6134. 'image.rightAlign': '右对齐',
  6135. 'image.imgTitle': '图片说明',
  6136. 'image.upload': '浏览...',
  6137. 'image.viewServer': '图片空间',
  6138. 'multiimage.uploadDesc': '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6139. 'multiimage.startUpload': '开始上传',
  6140. 'multiimage.clearAll': '全部清空',
  6141. 'multiimage.insertAll': '全部插入',
  6142. 'multiimage.queueLimitExceeded': '文件数量超过限制。',
  6143. 'multiimage.fileExceedsSizeLimit': '文件大小超过限制。',
  6144. 'multiimage.zeroByteFile': '无法上传空文件。',
  6145. 'multiimage.invalidFiletype': '文件类型不正确。',
  6146. 'multiimage.unknownError': '发生异常,无法上传。',
  6147. 'multiimage.pending': '等待上传',
  6148. 'multiimage.uploadError': '上传失败',
  6149. 'filemanager.emptyFolder': '空文件夹',
  6150. 'filemanager.moveup': '移到上一级文件夹',
  6151. 'filemanager.viewType': '显示方式:',
  6152. 'filemanager.viewImage': '缩略图',
  6153. 'filemanager.listImage': '详细信息',
  6154. 'filemanager.orderType': '排序方式:',
  6155. 'filemanager.fileName': '名称',
  6156. 'filemanager.fileSize': '大小',
  6157. 'filemanager.fileType': '类型',
  6158. 'insertfile.url': 'URL',
  6159. 'insertfile.title': '文件说明',
  6160. 'insertfile.upload': '上传',
  6161. 'insertfile.viewServer': '文件空间',
  6162. 'table.cells': '单元格数',
  6163. 'table.rows': '行数',
  6164. 'table.cols': '列数',
  6165. 'table.size': '大小',
  6166. 'table.width': '宽度',
  6167. 'table.height': '高度',
  6168. 'table.percent': '%',
  6169. 'table.px': 'px',
  6170. 'table.space': '边距间距',
  6171. 'table.padding': '边距',
  6172. 'table.spacing': '间距',
  6173. 'table.align': '对齐方式',
  6174. 'table.textAlign': '水平对齐',
  6175. 'table.verticalAlign': '垂直对齐',
  6176. 'table.alignDefault': '默认',
  6177. 'table.alignLeft': '左对齐',
  6178. 'table.alignCenter': '居中',
  6179. 'table.alignRight': '右对齐',
  6180. 'table.alignTop': '顶部',
  6181. 'table.alignMiddle': '中部',
  6182. 'table.alignBottom': '底部',
  6183. 'table.alignBaseline': '基线',
  6184. 'table.border': '边框',
  6185. 'table.borderWidth': '边框',
  6186. 'table.borderColor': '颜色',
  6187. 'table.backgroundColor': '背景颜色',
  6188. 'map.address': '地址: ',
  6189. 'map.search': '搜索',
  6190. 'baidumap.address': '地址: ',
  6191. 'baidumap.search': '搜索',
  6192. 'baidumap.insertDynamicMap': '插入动态地图',
  6193. 'anchor.name': '锚点名称',
  6194. 'formatblock.formatBlock': {
  6195. h1: '标题 1',
  6196. h2: '标题 2',
  6197. h3: '标题 3',
  6198. h4: '标题 4',
  6199. p: '正 文'
  6200. },
  6201. 'fontname.fontName': {
  6202. 'SimSun': '宋体',
  6203. 'NSimSun': '新宋体',
  6204. 'FangSong_GB2312': '仿宋_GB2312',
  6205. 'KaiTi_GB2312': '楷体_GB2312',
  6206. 'SimHei': '黑体',
  6207. 'Microsoft YaHei': '微软雅黑',
  6208. 'Arial': 'Arial',
  6209. 'Arial Black': 'Arial Black',
  6210. 'Times New Roman': 'Times New Roman',
  6211. 'Courier New': 'Courier New',
  6212. 'Tahoma': 'Tahoma',
  6213. 'Verdana': 'Verdana'
  6214. },
  6215. 'lineheight.lineHeight': [
  6216. {'1': '单倍行距'},
  6217. {'1.5': '1.5倍行距'},
  6218. {'2': '2倍行距'},
  6219. {'2.5': '2.5倍行距'},
  6220. {'3': '3倍行距'}
  6221. ],
  6222. 'template.selectTemplate': '可选模板',
  6223. 'template.replaceContent': '替换当前内容',
  6224. 'template.fileList': {
  6225. '1.html': '图片和文字',
  6226. '2.html': '表格',
  6227. '3.html': '项目编号'
  6228. }
  6229. }, 'zh-CN');
  6230. KindEditor.options.langType = 'zh-CN';
  6231. /*******************************************************************************
  6232. * KindEditor - WYSIWYG HTML Editor for Internet
  6233. * Copyright (C) 2006-2011 kindeditor.net
  6234. *
  6235. * @author Roddy <luolonghao@gmail.com>
  6236. * @site http://www.kindeditor.net/
  6237. * @licence http://www.kindeditor.net/license.php
  6238. *******************************************************************************/
  6239. KindEditor.plugin('anchor', function (K) {
  6240. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6241. self.plugin.anchor = {
  6242. edit: function () {
  6243. var html = ['<div style="padding:20px;">',
  6244. '<div class="ke-dialog-row">',
  6245. '<label for="keName">' + lang.name + '</label>',
  6246. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6247. '</div>',
  6248. '</div>'].join('');
  6249. var dialog = self.createDialog({
  6250. name: name,
  6251. width: 300,
  6252. title: self.lang(name),
  6253. body: html,
  6254. yesBtn: {
  6255. name: self.lang('yes'),
  6256. click: function (e) {
  6257. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6258. }
  6259. }
  6260. });
  6261. var div = dialog.div,
  6262. nameBox = K('input[name="name"]', div);
  6263. var img = self.plugin.getSelectedAnchor();
  6264. if (img) {
  6265. nameBox.val(unescape(img.attr('data-ke-name')));
  6266. }
  6267. nameBox[0].focus();
  6268. nameBox[0].select();
  6269. },
  6270. 'delete': function () {
  6271. self.plugin.getSelectedAnchor().remove();
  6272. }
  6273. };
  6274. self.clickToolbar(name, self.plugin.anchor.edit);
  6275. });
  6276. /*******************************************************************************
  6277. * KindEditor - WYSIWYG HTML Editor for Internet
  6278. * Copyright (C) 2006-2011 kindeditor.net
  6279. *
  6280. * @author Roddy <luolonghao@gmail.com>
  6281. * @site http://www.kindeditor.net/
  6282. * @licence http://www.kindeditor.net/license.php
  6283. *******************************************************************************/
  6284. KindEditor.plugin('autoheight', function (K) {
  6285. var self = this;
  6286. if (!self.autoHeightMode) {
  6287. return;
  6288. }
  6289. var minHeight;
  6290. function hideScroll() {
  6291. var edit = self.edit;
  6292. var body = edit.doc.body;
  6293. edit.iframe[0].scroll = 'no';
  6294. body.style.overflowY = 'hidden';
  6295. }
  6296. function resetHeight() {
  6297. var edit = self.edit;
  6298. var body = edit.doc.body;
  6299. edit.iframe.height(minHeight);
  6300. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6301. }
  6302. function init() {
  6303. minHeight = K.removeUnit(self.height);
  6304. self.edit.afterChange(resetHeight);
  6305. hideScroll();
  6306. resetHeight();
  6307. }
  6308. if (self.isCreated) {
  6309. init();
  6310. } else {
  6311. self.afterCreate(init);
  6312. }
  6313. });
  6314. /*
  6315. * 如何实现真正的自动高度?
  6316. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6317. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6318. * 由此就实现了真正的自动高度
  6319. * 测试:chrome、firefox、IE9、IE8
  6320. * */
  6321. /*******************************************************************************
  6322. * KindEditor - WYSIWYG HTML Editor for Internet
  6323. * Copyright (C) 2006-2011 kindeditor.net
  6324. *
  6325. * @author Roddy <luolonghao@gmail.com>
  6326. * @site http://www.kindeditor.net/
  6327. * @licence http://www.kindeditor.net/license.php
  6328. *******************************************************************************/
  6329. KindEditor.plugin('baidumap', function (K) {
  6330. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6331. var mapWidth = K.undef(self.mapWidth, 558);
  6332. var mapHeight = K.undef(self.mapHeight, 360);
  6333. self.clickToolbar(name, function () {
  6334. var html = ['<div style="padding:10px 20px;">',
  6335. '<div class="ke-header">',
  6336. '<div class="ke-left">',
  6337. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6338. '<span class="ke-button-common ke-button-outer">',
  6339. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6340. '</span>',
  6341. '</div>',
  6342. '<div class="ke-right">',
  6343. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6344. '</div>',
  6345. '<div class="ke-clearfix"></div>',
  6346. '</div>',
  6347. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6348. '</div>'].join('');
  6349. var dialog = self.createDialog({
  6350. name: name,
  6351. width: mapWidth + 42,
  6352. title: self.lang(name),
  6353. body: html,
  6354. yesBtn: {
  6355. name: self.lang('yes'),
  6356. click: function (e) {
  6357. var map = win.map;
  6358. var centerObj = map.getCenter();
  6359. var center = centerObj.lng + ',' + centerObj.lat;
  6360. var zoom = map.getZoom();
  6361. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6362. '?center=' + encodeURIComponent(center),
  6363. '&zoom=' + encodeURIComponent(zoom),
  6364. '&width=' + mapWidth,
  6365. '&height=' + mapHeight,
  6366. '&markers=' + encodeURIComponent(center),
  6367. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6368. if (checkbox[0].checked) {
  6369. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6370. } else {
  6371. self.exec('insertimage', url);
  6372. }
  6373. self.hideDialog().focus();
  6374. }
  6375. },
  6376. beforeRemove: function () {
  6377. searchBtn.remove();
  6378. if (doc) {
  6379. doc.write('');
  6380. }
  6381. iframe.remove();
  6382. }
  6383. });
  6384. var div = dialog.div,
  6385. addressBox = K('[name="address"]', div),
  6386. searchBtn = K('[name="searchBtn"]', div),
  6387. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6388. win, doc;
  6389. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6390. function ready() {
  6391. win = iframe[0].contentWindow;
  6392. doc = K.iframeDoc(iframe);
  6393. }
  6394. iframe.bind('load', function () {
  6395. iframe.unbind('load');
  6396. if (K.IE) {
  6397. ready();
  6398. } else {
  6399. setTimeout(ready, 0);
  6400. }
  6401. });
  6402. K('.ke-map', div).replaceWith(iframe);
  6403. searchBtn.click(function () {
  6404. win.search(addressBox.val());
  6405. });
  6406. });
  6407. });
  6408. /*******************************************************************************
  6409. * KindEditor - WYSIWYG HTML Editor for Internet
  6410. * Copyright (C) 2006-2011 kindeditor.net
  6411. *
  6412. * @author Roddy <luolonghao@gmail.com>
  6413. * @site http://www.kindeditor.net/
  6414. * @licence http://www.kindeditor.net/license.php
  6415. *******************************************************************************/
  6416. KindEditor.plugin('map', function (K) {
  6417. var self = this, name = 'map', lang = self.lang(name + '.');
  6418. self.clickToolbar(name, function () {
  6419. var html = ['<div style="padding:10px 20px;">',
  6420. '<div class="ke-dialog-row">',
  6421. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6422. '<span class="ke-button-common ke-button-outer">',
  6423. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6424. '</span>',
  6425. '</div>',
  6426. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6427. '</div>'].join('');
  6428. var dialog = self.createDialog({
  6429. name: name,
  6430. width: 600,
  6431. title: self.lang(name),
  6432. body: html,
  6433. yesBtn: {
  6434. name: self.lang('yes'),
  6435. click: function (e) {
  6436. var geocoder = win.geocoder,
  6437. map = win.map,
  6438. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6439. zoom = map.getZoom(),
  6440. maptype = map.getMapTypeId(),
  6441. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6442. url += '?center=' + encodeURIComponent(center);
  6443. url += '&zoom=' + encodeURIComponent(zoom);
  6444. url += '&size=558x360';
  6445. url += '&maptype=' + encodeURIComponent(maptype);
  6446. url += '&markers=' + encodeURIComponent(center);
  6447. url += '&language=' + self.langType;
  6448. url += '&sensor=false';
  6449. self.exec('insertimage', url).hideDialog().focus();
  6450. }
  6451. },
  6452. beforeRemove: function () {
  6453. searchBtn.remove();
  6454. if (doc) {
  6455. doc.write('');
  6456. }
  6457. iframe.remove();
  6458. }
  6459. });
  6460. var div = dialog.div,
  6461. addressBox = K('[name="address"]', div),
  6462. searchBtn = K('[name="searchBtn"]', div),
  6463. win, doc;
  6464. var iframeHtml = ['<!doctype html><html><head>',
  6465. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6466. '<style>',
  6467. ' html { height: 100% }',
  6468. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6469. ' #map_canvas { height: 100% }',
  6470. '</style>',
  6471. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6472. '<script>',
  6473. 'var map, geocoder;',
  6474. 'function initialize() {',
  6475. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6476. ' var options = {',
  6477. ' zoom: 11,',
  6478. ' center: latlng,',
  6479. ' disableDefaultUI: true,',
  6480. ' panControl: true,',
  6481. ' zoomControl: true,',
  6482. ' mapTypeControl: true,',
  6483. ' scaleControl: true,',
  6484. ' streetViewControl: false,',
  6485. ' overviewMapControl: true,',
  6486. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6487. ' };',
  6488. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6489. ' geocoder = new google.maps.Geocoder();',
  6490. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6491. ' if (status == google.maps.GeocoderStatus.OK) {',
  6492. ' if (results[3]) {',
  6493. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6494. ' }',
  6495. ' }',
  6496. ' });',
  6497. '}',
  6498. 'function search(address) {',
  6499. ' if (!map) return;',
  6500. ' geocoder.geocode({address : address}, function(results, status) {',
  6501. ' if (status == google.maps.GeocoderStatus.OK) {',
  6502. ' map.setZoom(11);',
  6503. ' map.setCenter(results[0].geometry.location);',
  6504. ' var marker = new google.maps.Marker({',
  6505. ' map: map,',
  6506. ' position: results[0].geometry.location',
  6507. ' });',
  6508. ' } else {',
  6509. ' alert("Invalid address: " + address);',
  6510. ' }',
  6511. ' });',
  6512. '}',
  6513. '</script>',
  6514. '</head>',
  6515. '<body onload="initialize();">',
  6516. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6517. '</body></html>'].join('\n');
  6518. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6519. function ready() {
  6520. win = iframe[0].contentWindow;
  6521. doc = K.iframeDoc(iframe);
  6522. }
  6523. iframe.bind('load', function () {
  6524. iframe.unbind('load');
  6525. if (K.IE) {
  6526. ready();
  6527. } else {
  6528. setTimeout(ready, 0);
  6529. }
  6530. });
  6531. K('.ke-map', div).replaceWith(iframe);
  6532. searchBtn.click(function () {
  6533. win.search(addressBox.val());
  6534. });
  6535. });
  6536. });
  6537. /*******************************************************************************
  6538. * KindEditor - WYSIWYG HTML Editor for Internet
  6539. * Copyright (C) 2006-2011 kindeditor.net
  6540. *
  6541. * @author Roddy <luolonghao@gmail.com>
  6542. * @site http://www.kindeditor.net/
  6543. * @licence http://www.kindeditor.net/license.php
  6544. *******************************************************************************/
  6545. KindEditor.plugin('clearhtml', function (K) {
  6546. var self = this, name = 'clearhtml';
  6547. self.clickToolbar(name, function () {
  6548. self.focus();
  6549. var html = self.html();
  6550. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6551. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6552. html = K.formatHtml(html, {
  6553. a: ['href', 'target'],
  6554. embed: ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6555. img: ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6556. table: ['border'],
  6557. 'td,th': ['rowspan', 'colspan'],
  6558. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6': []
  6559. });
  6560. self.html(html);
  6561. self.cmd.selection(true);
  6562. self.addBookmark();
  6563. });
  6564. });
  6565. /*******************************************************************************
  6566. * KindEditor - WYSIWYG HTML Editor for Internet
  6567. * Copyright (C) 2006-2011 kindeditor.net
  6568. *
  6569. * @author Roddy <luolonghao@gmail.com>
  6570. * @site http://www.kindeditor.net/
  6571. * @licence http://www.kindeditor.net/license.php
  6572. *******************************************************************************/
  6573. KindEditor.plugin('code', function (K) {
  6574. var self = this, name = 'code';
  6575. self.clickToolbar(name, function () {
  6576. var lang = self.lang(name + '.'),
  6577. html = ['<div style="padding:10px 20px;">',
  6578. '<div class="ke-dialog-row">',
  6579. '<select class="ke-code-type">',
  6580. '<option value="js">JavaScript</option>',
  6581. '<option value="html">HTML</option>',
  6582. '<option value="css">CSS</option>',
  6583. '<option value="php">PHP</option>',
  6584. '<option value="pl">Perl</option>',
  6585. '<option value="py">Python</option>',
  6586. '<option value="rb">Ruby</option>',
  6587. '<option value="java">Java</option>',
  6588. '<option value="vb">ASP/VB</option>',
  6589. '<option value="cpp">C/C++</option>',
  6590. '<option value="cs">C#</option>',
  6591. '<option value="xml">XML</option>',
  6592. '<option value="bsh">Shell</option>',
  6593. '<option value="">Other</option>',
  6594. '</select>',
  6595. '</div>',
  6596. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6597. '</div>'].join(''),
  6598. dialog = self.createDialog({
  6599. name: name,
  6600. width: 450,
  6601. title: self.lang(name),
  6602. body: html,
  6603. yesBtn: {
  6604. name: self.lang('yes'),
  6605. click: function (e) {
  6606. var type = K('.ke-code-type', dialog.div).val(),
  6607. code = textarea.val(),
  6608. cls = type === '' ? '' : ' lang-' + type,
  6609. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6610. if (K.trim(code) === '') {
  6611. alert(lang.pleaseInput);
  6612. textarea[0].focus();
  6613. return;
  6614. }
  6615. self.insertHtml(html).hideDialog().focus();
  6616. }
  6617. }
  6618. }),
  6619. textarea = K('textarea', dialog.div);
  6620. textarea[0].focus();
  6621. });
  6622. });
  6623. /*******************************************************************************
  6624. * KindEditor - WYSIWYG HTML Editor for Internet
  6625. * Copyright (C) 2006-2011 kindeditor.net
  6626. *
  6627. * @author Roddy <luolonghao@gmail.com>
  6628. * @site http://www.kindeditor.net/
  6629. * @licence http://www.kindeditor.net/license.php
  6630. *******************************************************************************/
  6631. KindEditor.plugin('emoticons', function (K) {
  6632. var self = this, name = 'emoticons',
  6633. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6634. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6635. currentPageNum = 1;
  6636. self.clickToolbar(name, function () {
  6637. var rows = 5, cols = 9, total = 135, startNum = 0,
  6638. cells = rows * cols, pages = Math.ceil(total / cells),
  6639. colsHalf = Math.floor(cols / 2),
  6640. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6641. elements = [],
  6642. menu = self.createMenu({
  6643. name: name,
  6644. beforeRemove: function () {
  6645. removeEvent();
  6646. }
  6647. });
  6648. menu.div.append(wrapperDiv);
  6649. var previewDiv, previewImg;
  6650. if (allowPreview) {
  6651. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6652. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6653. wrapperDiv.append(previewDiv);
  6654. previewDiv.append(previewImg);
  6655. }
  6656. function bindCellEvent(cell, j, num) {
  6657. if (previewDiv) {
  6658. cell.mouseover(function () {
  6659. if (j > colsHalf) {
  6660. previewDiv.css('left', 0);
  6661. previewDiv.css('right', '');
  6662. } else {
  6663. previewDiv.css('left', '');
  6664. previewDiv.css('right', 0);
  6665. }
  6666. previewImg.attr('src', path + num + '.gif');
  6667. K(this).addClass('ke-on');
  6668. });
  6669. } else {
  6670. cell.mouseover(function () {
  6671. K(this).addClass('ke-on');
  6672. });
  6673. }
  6674. cell.mouseout(function () {
  6675. K(this).removeClass('ke-on');
  6676. });
  6677. cell.click(function (e) {
  6678. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6679. e.stop();
  6680. });
  6681. }
  6682. function createEmoticonsTable(pageNum, parentDiv) {
  6683. var table = document.createElement('table');
  6684. parentDiv.append(table);
  6685. if (previewDiv) {
  6686. K(table).mouseover(function () {
  6687. previewDiv.show('block');
  6688. });
  6689. K(table).mouseout(function () {
  6690. previewDiv.hide();
  6691. });
  6692. elements.push(K(table));
  6693. }
  6694. table.className = 'ke-table';
  6695. table.cellPadding = 0;
  6696. table.cellSpacing = 0;
  6697. table.border = 0;
  6698. var num = (pageNum - 1) * cells + startNum;
  6699. for (var i = 0; i < rows; i++) {
  6700. var row = table.insertRow(i);
  6701. for (var j = 0; j < cols; j++) {
  6702. var cell = K(row.insertCell(j));
  6703. cell.addClass('ke-cell');
  6704. bindCellEvent(cell, j, num);
  6705. var span = K('<span class="ke-img"></span>')
  6706. .css('background-position', '-' + (24 * num) + 'px 0px')
  6707. .css('background-image', 'url(' + path + 'static.gif)');
  6708. cell.append(span);
  6709. elements.push(cell);
  6710. num++;
  6711. }
  6712. }
  6713. return table;
  6714. }
  6715. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6716. function removeEvent() {
  6717. K.each(elements, function () {
  6718. this.unbind();
  6719. });
  6720. }
  6721. var pageDiv;
  6722. function bindPageEvent(el, pageNum) {
  6723. el.click(function (e) {
  6724. removeEvent();
  6725. table.parentNode.removeChild(table);
  6726. pageDiv.remove();
  6727. table = createEmoticonsTable(pageNum, wrapperDiv);
  6728. createPageTable(pageNum);
  6729. currentPageNum = pageNum;
  6730. e.stop();
  6731. });
  6732. }
  6733. function createPageTable(currentPageNum) {
  6734. pageDiv = K('<div class="ke-page"></div>');
  6735. wrapperDiv.append(pageDiv);
  6736. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6737. if (currentPageNum !== pageNum) {
  6738. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6739. bindPageEvent(a, pageNum);
  6740. pageDiv.append(a);
  6741. elements.push(a);
  6742. } else {
  6743. pageDiv.append(K('@[' + pageNum + ']'));
  6744. }
  6745. pageDiv.append(K('@&nbsp;'));
  6746. }
  6747. }
  6748. createPageTable(currentPageNum);
  6749. });
  6750. });
  6751. /*******************************************************************************
  6752. * KindEditor - WYSIWYG HTML Editor for Internet
  6753. * Copyright (C) 2006-2011 kindeditor.net
  6754. *
  6755. * @author Roddy <luolonghao@gmail.com>
  6756. * @site http://www.kindeditor.net/
  6757. * @licence http://www.kindeditor.net/license.php
  6758. *******************************************************************************/
  6759. KindEditor.plugin('filemanager', function (K) {
  6760. var self = this, name = 'filemanager',
  6761. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6762. imgPath = self.pluginsPath + name + '/images/',
  6763. lang = self.lang(name + '.');
  6764. function makeFileTitle(filename, filesize, datetime) {
  6765. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6766. }
  6767. function bindTitle(el, data) {
  6768. if (data.is_dir) {
  6769. el.attr('title', data.filename);
  6770. } else {
  6771. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6772. }
  6773. }
  6774. self.plugin.filemanagerDialog = function (options) {
  6775. var width = K.undef(options.width, 650),
  6776. height = K.undef(options.height, 510),
  6777. dirName = K.undef(options.dirName, ''),
  6778. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6779. clickFn = options.clickFn;
  6780. var html = [
  6781. '<div style="padding:10px 20px;">',
  6782. '<div class="ke-plugin-filemanager-header">',
  6783. '<div class="ke-left">',
  6784. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6785. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6786. '</div>',
  6787. '<div class="ke-right">',
  6788. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6789. '<option value="VIEW">' + lang.viewImage + '</option>',
  6790. '<option value="LIST">' + lang.listImage + '</option>',
  6791. '</select> ',
  6792. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6793. '<option value="NAME">' + lang.fileName + '</option>',
  6794. '<option value="SIZE">' + lang.fileSize + '</option>',
  6795. '<option value="TYPE">' + lang.fileType + '</option>',
  6796. '</select>',
  6797. '</div>',
  6798. '<div class="ke-clearfix"></div>',
  6799. '</div>',
  6800. '<div class="ke-plugin-filemanager-body"></div>',
  6801. '</div>'
  6802. ].join('');
  6803. var dialog = self.createDialog({
  6804. name: name,
  6805. width: width,
  6806. height: height,
  6807. title: self.lang(name),
  6808. body: html
  6809. }),
  6810. div = dialog.div,
  6811. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6812. moveupImg = K('[name="moveupImg"]', div),
  6813. moveupLink = K('[name="moveupLink"]', div),
  6814. viewServerBtn = K('[name="viewServer"]', div),
  6815. viewTypeBox = K('[name="viewType"]', div),
  6816. orderTypeBox = K('[name="orderType"]', div);
  6817. function reloadPage(path, order, func) {
  6818. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6819. dialog.showLoading(self.lang('ajaxLoading'));
  6820. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function (data) {
  6821. dialog.hideLoading();
  6822. func(data);
  6823. });
  6824. }
  6825. var elList = [];
  6826. function bindEvent(el, result, data, createFunc) {
  6827. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6828. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6829. if (data.is_dir) {
  6830. el.click(function (e) {
  6831. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6832. });
  6833. } else if (data.is_photo) {
  6834. el.click(function (e) {
  6835. clickFn.call(this, fileUrl, data.filename);
  6836. });
  6837. } else {
  6838. el.click(function (e) {
  6839. clickFn.call(this, fileUrl, data.filename);
  6840. });
  6841. }
  6842. elList.push(el);
  6843. }
  6844. function createCommon(result, createFunc) {
  6845. K.each(elList, function () {
  6846. this.unbind();
  6847. });
  6848. moveupLink.unbind();
  6849. viewTypeBox.unbind();
  6850. orderTypeBox.unbind();
  6851. if (result.current_dir_path) {
  6852. moveupLink.click(function (e) {
  6853. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6854. });
  6855. }
  6856. function changeFunc() {
  6857. if (viewTypeBox.val() == 'VIEW') {
  6858. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6859. } else {
  6860. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6861. }
  6862. }
  6863. viewTypeBox.change(changeFunc);
  6864. orderTypeBox.change(changeFunc);
  6865. bodyDiv.html('');
  6866. }
  6867. function createList(result) {
  6868. createCommon(result, createList);
  6869. var table = document.createElement('table');
  6870. table.className = 'ke-table';
  6871. table.cellPadding = 0;
  6872. table.cellSpacing = 0;
  6873. table.border = 0;
  6874. bodyDiv.append(table);
  6875. var fileList = result.file_list;
  6876. for (var i = 0, len = fileList.length; i < len; i++) {
  6877. var data = fileList[i], row = K(table.insertRow(i));
  6878. row.mouseover(function (e) {
  6879. K(this).addClass('ke-on');
  6880. })
  6881. .mouseout(function (e) {
  6882. K(this).removeClass('ke-on');
  6883. });
  6884. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6885. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6886. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6887. if (!data.is_dir || data.has_file) {
  6888. row.css('cursor', 'pointer');
  6889. cell0.attr('title', data.filename);
  6890. bindEvent(cell0, result, data, createList);
  6891. } else {
  6892. cell0.attr('title', lang.emptyFolder);
  6893. }
  6894. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6895. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6896. }
  6897. }
  6898. function createView(result) {
  6899. createCommon(result, createView);
  6900. var fileList = result.file_list;
  6901. for (var i = 0, len = fileList.length; i < len; i++) {
  6902. var data = fileList[i],
  6903. div = K('<div class="ke-inline-block ke-item"></div>');
  6904. bodyDiv.append(div);
  6905. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6906. .mouseover(function (e) {
  6907. K(this).addClass('ke-on');
  6908. })
  6909. .mouseout(function (e) {
  6910. K(this).removeClass('ke-on');
  6911. });
  6912. div.append(photoDiv);
  6913. var fileUrl = result.current_url + data.filename,
  6914. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6915. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6916. if (!data.is_dir || data.has_file) {
  6917. photoDiv.css('cursor', 'pointer');
  6918. bindTitle(photoDiv, data);
  6919. bindEvent(photoDiv, result, data, createView);
  6920. } else {
  6921. photoDiv.attr('title', lang.emptyFolder);
  6922. }
  6923. photoDiv.append(img);
  6924. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6925. }
  6926. }
  6927. viewTypeBox.val(viewType);
  6928. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6929. return dialog;
  6930. }
  6931. });
  6932. /*******************************************************************************
  6933. * KindEditor - WYSIWYG HTML Editor for Internet
  6934. * Copyright (C) 2006-2011 kindeditor.net
  6935. *
  6936. * @author Roddy <luolonghao@gmail.com>
  6937. * @site http://www.kindeditor.net/
  6938. * @licence http://www.kindeditor.net/license.php
  6939. *******************************************************************************/
  6940. KindEditor.plugin('flash', function (K) {
  6941. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6942. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6943. allowFileManager = K.undef(self.allowFileManager, false),
  6944. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6945. extraParams = K.undef(self.extraFileUploadParams, {}),
  6946. filePostName = K.undef(self.filePostName, 'imgFile'),
  6947. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  6948. self.plugin.flash = {
  6949. edit: function () {
  6950. var html = [
  6951. '<div style="padding:20px;">',
  6952. '<div class="ke-dialog-row">',
  6953. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6954. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6955. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6956. '<span class="ke-button-common ke-button-outer">',
  6957. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6958. '</span>',
  6959. '</div>',
  6960. '<div class="ke-dialog-row">',
  6961. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6962. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6963. '</div>',
  6964. '<div class="ke-dialog-row">',
  6965. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6966. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6967. '</div>',
  6968. '</div>'
  6969. ].join('');
  6970. var dialog = self.createDialog({
  6971. name: name,
  6972. width: 450,
  6973. title: self.lang(name),
  6974. body: html,
  6975. yesBtn: {
  6976. name: self.lang('yes'),
  6977. click: function (e) {
  6978. var url = K.trim(urlBox.val()),
  6979. width = widthBox.val(),
  6980. height = heightBox.val();
  6981. if (url == 'http://' || K.invalidUrl(url)) {
  6982. alert(self.lang('invalidUrl'));
  6983. urlBox[0].focus();
  6984. return;
  6985. }
  6986. if (!/^\d*$/.test(width)) {
  6987. alert(self.lang('invalidWidth'));
  6988. widthBox[0].focus();
  6989. return;
  6990. }
  6991. if (!/^\d*$/.test(height)) {
  6992. alert(self.lang('invalidHeight'));
  6993. heightBox[0].focus();
  6994. return;
  6995. }
  6996. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6997. src: url,
  6998. type: K.mediaType('.swf'),
  6999. width: width,
  7000. height: height,
  7001. quality: 'high'
  7002. });
  7003. self.insertHtml(html).hideDialog().focus();
  7004. }
  7005. }
  7006. }),
  7007. div = dialog.div,
  7008. urlBox = K('[name="url"]', div),
  7009. viewServerBtn = K('[name="viewServer"]', div),
  7010. widthBox = K('[name="width"]', div),
  7011. heightBox = K('[name="height"]', div);
  7012. urlBox.val('http://');
  7013. if (allowFlashUpload) {
  7014. var uploadbutton = K.uploadbutton({
  7015. button: K('.ke-upload-button', div)[0],
  7016. fieldName: filePostName,
  7017. extraParams: extraParams,
  7018. url: K.addParam(uploadJson, 'dir=flash'),
  7019. afterUpload: function (data) {
  7020. dialog.hideLoading();
  7021. if (data.error === 0) {
  7022. var url = data.url;
  7023. if (formatUploadUrl) {
  7024. url = K.formatUrl(url, 'absolute');
  7025. }
  7026. urlBox.val(url);
  7027. if (self.afterUpload) {
  7028. self.afterUpload.call(self, url, data, name);
  7029. }
  7030. alert(self.lang('uploadSuccess'));
  7031. } else {
  7032. alert(data.message);
  7033. }
  7034. },
  7035. afterError: function (html) {
  7036. dialog.hideLoading();
  7037. self.errorDialog(html);
  7038. }
  7039. });
  7040. uploadbutton.fileBox.change(function (e) {
  7041. dialog.showLoading(self.lang('uploadLoading'));
  7042. uploadbutton.submit();
  7043. });
  7044. } else {
  7045. K('.ke-upload-button', div).hide();
  7046. }
  7047. if (allowFileManager) {
  7048. viewServerBtn.click(function (e) {
  7049. self.loadPlugin('filemanager', function () {
  7050. self.plugin.filemanagerDialog({
  7051. viewType: 'LIST',
  7052. dirName: 'flash',
  7053. clickFn: function (url, title) {
  7054. if (self.dialogs.length > 1) {
  7055. K('[name="url"]', div).val(url);
  7056. if (self.afterSelectFile) {
  7057. self.afterSelectFile.call(self, url);
  7058. }
  7059. self.hideDialog();
  7060. }
  7061. }
  7062. });
  7063. });
  7064. });
  7065. } else {
  7066. viewServerBtn.hide();
  7067. }
  7068. var img = self.plugin.getSelectedFlash();
  7069. if (img) {
  7070. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7071. urlBox.val(attrs.src);
  7072. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7073. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7074. }
  7075. urlBox[0].focus();
  7076. urlBox[0].select();
  7077. },
  7078. 'delete': function () {
  7079. self.plugin.getSelectedFlash().remove();
  7080. self.addBookmark();
  7081. }
  7082. };
  7083. self.clickToolbar(name, self.plugin.flash.edit);
  7084. });
  7085. /*******************************************************************************
  7086. * KindEditor - WYSIWYG HTML Editor for Internet
  7087. * Copyright (C) 2006-2011 kindeditor.net
  7088. *
  7089. * @author Roddy <luolonghao@gmail.com>
  7090. * @site http://www.kindeditor.net/
  7091. * @licence http://www.kindeditor.net/license.php
  7092. *******************************************************************************/
  7093. KindEditor.plugin('image', function (K) {
  7094. var self = this, name = 'image',
  7095. allowImageUpload = K.undef(self.allowImageUpload, true),
  7096. allowImageRemote = K.undef(self.allowImageRemote, true),
  7097. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7098. allowFileManager = K.undef(self.allowFileManager, false),
  7099. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7100. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7101. imgPath = self.pluginsPath + 'image/images/',
  7102. extraParams = K.undef(self.extraFileUploadParams, {}),
  7103. filePostName = K.undef(self.filePostName, 'imgFile'),
  7104. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7105. lang = self.lang(name + '.');
  7106. self.plugin.imageDialog = function (options) {
  7107. var imageUrl = options.imageUrl,
  7108. imageWidth = K.undef(options.imageWidth, ''),
  7109. imageHeight = K.undef(options.imageHeight, ''),
  7110. imageTitle = K.undef(options.imageTitle, ''),
  7111. imageAlign = K.undef(options.imageAlign, ''),
  7112. showRemote = K.undef(options.showRemote, true),
  7113. showLocal = K.undef(options.showLocal, true),
  7114. tabIndex = K.undef(options.tabIndex, 0),
  7115. clickFn = options.clickFn;
  7116. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7117. var hiddenElements = [];
  7118. for (var k in extraParams) {
  7119. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7120. }
  7121. var html = [
  7122. '<div style="padding:20px;">',
  7123. '<div class="tabs"></div>',
  7124. '<div class="tab1" style="display:none;">',
  7125. '<div class="ke-dialog-row">',
  7126. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7127. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7128. '<span class="ke-button-common ke-button-outer">',
  7129. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7130. '</span>',
  7131. '</div>',
  7132. '<div class="ke-dialog-row">',
  7133. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7134. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7135. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7136. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7137. '</div>',
  7138. '<div class="ke-dialog-row">',
  7139. '<label style="width:60px;">' + lang.align + '</label>',
  7140. '<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="" />',
  7141. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7142. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7143. '</div>',
  7144. '<div class="ke-dialog-row">',
  7145. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7146. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7147. '</div>',
  7148. '</div>',
  7149. '<div class="tab2" style="display:none;">',
  7150. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7151. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7152. '<div class="ke-dialog-row">',
  7153. hiddenElements.join(''),
  7154. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7155. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7156. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7157. '</div>',
  7158. '</form>',
  7159. '</div>',
  7160. '</div>'
  7161. ].join('');
  7162. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7163. dialogHeight = showLocal && showRemote ? 300 : 250;
  7164. var dialog = self.createDialog({
  7165. name: name,
  7166. width: dialogWidth,
  7167. height: dialogHeight,
  7168. title: self.lang(name),
  7169. body: html,
  7170. yesBtn: {
  7171. name: self.lang('yes'),
  7172. click: function (e) {
  7173. if (dialog.isLoading) {
  7174. return;
  7175. }
  7176. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7177. if (uploadbutton.fileBox.val() == '') {
  7178. alert(self.lang('pleaseSelectFile'));
  7179. return;
  7180. }
  7181. dialog.showLoading(self.lang('uploadLoading'));
  7182. uploadbutton.submit();
  7183. localUrlBox.val('');
  7184. return;
  7185. }
  7186. var url = K.trim(urlBox.val()),
  7187. width = widthBox.val(),
  7188. height = heightBox.val(),
  7189. title = titleBox.val(),
  7190. align = '';
  7191. alignBox.each(function () {
  7192. if (this.checked) {
  7193. align = this.value;
  7194. return false;
  7195. }
  7196. });
  7197. if (url == 'http://' || K.invalidUrl(url)) {
  7198. alert(self.lang('invalidUrl'));
  7199. urlBox[0].focus();
  7200. return;
  7201. }
  7202. if (!/^\d*$/.test(width)) {
  7203. alert(self.lang('invalidWidth'));
  7204. widthBox[0].focus();
  7205. return;
  7206. }
  7207. if (!/^\d*$/.test(height)) {
  7208. alert(self.lang('invalidHeight'));
  7209. heightBox[0].focus();
  7210. return;
  7211. }
  7212. clickFn.call(self, url, title, width, height, 0, align);
  7213. }
  7214. },
  7215. beforeRemove: function () {
  7216. viewServerBtn.unbind();
  7217. widthBox.unbind();
  7218. heightBox.unbind();
  7219. refreshBtn.unbind();
  7220. }
  7221. }),
  7222. div = dialog.div;
  7223. var urlBox = K('[name="url"]', div),
  7224. localUrlBox = K('[name="localUrl"]', div),
  7225. viewServerBtn = K('[name="viewServer"]', div),
  7226. widthBox = K('.tab1 [name="width"]', div),
  7227. heightBox = K('.tab1 [name="height"]', div),
  7228. refreshBtn = K('.ke-refresh-btn', div),
  7229. titleBox = K('.tab1 [name="title"]', div),
  7230. alignBox = K('.tab1 [name="align"]', div);
  7231. var tabs;
  7232. if (showRemote && showLocal) {
  7233. tabs = K.tabs({
  7234. src: K('.tabs', div),
  7235. afterSelect: function (i) {
  7236. }
  7237. });
  7238. tabs.add({
  7239. title: lang.remoteImage,
  7240. panel: K('.tab1', div)
  7241. });
  7242. tabs.add({
  7243. title: lang.localImage,
  7244. panel: K('.tab2', div)
  7245. });
  7246. tabs.select(tabIndex);
  7247. } else if (showRemote) {
  7248. K('.tab1', div).show();
  7249. } else if (showLocal) {
  7250. K('.tab2', div).show();
  7251. }
  7252. var uploadbutton = K.uploadbutton({
  7253. button: K('.ke-upload-button', div)[0],
  7254. fieldName: filePostName,
  7255. form: K('.ke-form', div),
  7256. target: target,
  7257. width: 60,
  7258. afterUpload: function (data) {
  7259. dialog.hideLoading();
  7260. if (data.error === 0) {
  7261. var url = data.url;
  7262. if (formatUploadUrl) {
  7263. url = K.formatUrl(url, 'absolute');
  7264. }
  7265. if (self.afterUpload) {
  7266. self.afterUpload.call(self, url, data, name);
  7267. }
  7268. if (!fillDescAfterUploadImage) {
  7269. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7270. } else {
  7271. K(".ke-dialog-row #remoteUrl", div).val(url);
  7272. K(".ke-tabs-li", div)[0].click();
  7273. K(".ke-refresh-btn", div).click();
  7274. }
  7275. } else {
  7276. alert(data.message);
  7277. }
  7278. },
  7279. afterError: function (html) {
  7280. dialog.hideLoading();
  7281. self.errorDialog(html);
  7282. }
  7283. });
  7284. uploadbutton.fileBox.change(function (e) {
  7285. localUrlBox.val(uploadbutton.fileBox.val());
  7286. });
  7287. if (allowFileManager) {
  7288. viewServerBtn.click(function (e) {
  7289. self.loadPlugin('filemanager', function () {
  7290. self.plugin.filemanagerDialog({
  7291. viewType: 'VIEW',
  7292. dirName: 'image',
  7293. clickFn: function (url, title) {
  7294. if (self.dialogs.length > 1) {
  7295. K('[name="url"]', div).val(url);
  7296. if (self.afterSelectFile) {
  7297. self.afterSelectFile.call(self, url);
  7298. }
  7299. self.hideDialog();
  7300. }
  7301. }
  7302. });
  7303. });
  7304. });
  7305. } else {
  7306. viewServerBtn.hide();
  7307. }
  7308. var originalWidth = 0, originalHeight = 0;
  7309. function setSize(width, height) {
  7310. widthBox.val(width);
  7311. heightBox.val(height);
  7312. originalWidth = width;
  7313. originalHeight = height;
  7314. }
  7315. refreshBtn.click(function (e) {
  7316. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7317. position: 'absolute',
  7318. visibility: 'hidden',
  7319. top: 0,
  7320. left: '-1000px'
  7321. });
  7322. tempImg.bind('load', function () {
  7323. setSize(tempImg.width(), tempImg.height());
  7324. tempImg.remove();
  7325. });
  7326. K(document.body).append(tempImg);
  7327. });
  7328. widthBox.change(function (e) {
  7329. if (originalWidth > 0) {
  7330. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7331. }
  7332. });
  7333. heightBox.change(function (e) {
  7334. if (originalHeight > 0) {
  7335. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7336. }
  7337. });
  7338. urlBox.val(options.imageUrl);
  7339. setSize(options.imageWidth, options.imageHeight);
  7340. titleBox.val(options.imageTitle);
  7341. alignBox.each(function () {
  7342. if (this.value === options.imageAlign) {
  7343. this.checked = true;
  7344. return false;
  7345. }
  7346. });
  7347. if (showRemote && tabIndex === 0) {
  7348. urlBox[0].focus();
  7349. urlBox[0].select();
  7350. }
  7351. return dialog;
  7352. };
  7353. self.plugin.image = {
  7354. edit: function () {
  7355. var img = self.plugin.getSelectedImage();
  7356. self.plugin.imageDialog({
  7357. imageUrl: img ? img.attr('data-ke-src') : 'http://',
  7358. imageWidth: img ? img.width() : '',
  7359. imageHeight: img ? img.height() : '',
  7360. imageTitle: img ? img.attr('title') : '',
  7361. imageAlign: img ? img.attr('align') : '',
  7362. showRemote: allowImageRemote,
  7363. showLocal: allowImageUpload,
  7364. tabIndex: img ? 0 : imageTabIndex,
  7365. clickFn: function (url, title, width, height, border, align) {
  7366. if (img) {
  7367. img.attr('src', url);
  7368. img.attr('data-ke-src', url);
  7369. img.attr('width', width);
  7370. img.attr('height', height);
  7371. img.attr('title', title);
  7372. img.attr('align', align);
  7373. img.attr('alt', title);
  7374. } else {
  7375. self.exec('insertimage', url, title, width, height, border, align);
  7376. }
  7377. setTimeout(function () {
  7378. self.hideDialog().focus();
  7379. }, 0);
  7380. }
  7381. });
  7382. },
  7383. 'delete': function () {
  7384. var target = self.plugin.getSelectedImage();
  7385. if (target.parent().name == 'a') {
  7386. target = target.parent();
  7387. }
  7388. target.remove();
  7389. self.addBookmark();
  7390. }
  7391. };
  7392. self.clickToolbar(name, self.plugin.image.edit);
  7393. });
  7394. /*******************************************************************************
  7395. * KindEditor - WYSIWYG HTML Editor for Internet
  7396. * Copyright (C) 2006-2011 kindeditor.net
  7397. *
  7398. * @author Roddy <luolonghao@gmail.com>
  7399. * @site http://www.kindeditor.net/
  7400. * @licence http://www.kindeditor.net/license.php
  7401. *******************************************************************************/
  7402. KindEditor.plugin('insertfile', function (K) {
  7403. var self = this, name = 'insertfile',
  7404. allowFileUpload = K.undef(self.allowFileUpload, true),
  7405. allowFileManager = K.undef(self.allowFileManager, false),
  7406. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7407. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7408. extraParams = K.undef(self.extraFileUploadParams, {}),
  7409. filePostName = K.undef(self.filePostName, 'imgFile'),
  7410. lang = self.lang(name + '.');
  7411. self.plugin.fileDialog = function (options) {
  7412. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7413. fileTitle = K.undef(options.fileTitle, ''),
  7414. clickFn = options.clickFn;
  7415. var html = [
  7416. '<div style="padding:20px;">',
  7417. '<div class="ke-dialog-row">',
  7418. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7419. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7420. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7421. '<span class="ke-button-common ke-button-outer">',
  7422. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7423. '</span>',
  7424. '</div>',
  7425. '<div class="ke-dialog-row">',
  7426. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7427. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7428. '</div>',
  7429. '</form>',
  7430. '</div>'
  7431. ].join('');
  7432. var dialog = self.createDialog({
  7433. name: name,
  7434. width: 450,
  7435. title: self.lang(name),
  7436. body: html,
  7437. yesBtn: {
  7438. name: self.lang('yes'),
  7439. click: function (e) {
  7440. var url = K.trim(urlBox.val()),
  7441. title = titleBox.val();
  7442. if (url == 'http://' || K.invalidUrl(url)) {
  7443. alert(self.lang('invalidUrl'));
  7444. urlBox[0].focus();
  7445. return;
  7446. }
  7447. if (K.trim(title) === '') {
  7448. title = url;
  7449. }
  7450. clickFn.call(self, url, title);
  7451. }
  7452. }
  7453. }),
  7454. div = dialog.div;
  7455. var urlBox = K('[name="url"]', div),
  7456. viewServerBtn = K('[name="viewServer"]', div),
  7457. titleBox = K('[name="title"]', div);
  7458. if (allowFileUpload) {
  7459. var uploadbutton = K.uploadbutton({
  7460. button: K('.ke-upload-button', div)[0],
  7461. fieldName: filePostName,
  7462. url: K.addParam(uploadJson, 'dir=file'),
  7463. extraParams: extraParams,
  7464. afterUpload: function (data) {
  7465. dialog.hideLoading();
  7466. if (data.error === 0) {
  7467. var url = data.url;
  7468. if (formatUploadUrl) {
  7469. url = K.formatUrl(url, 'absolute');
  7470. }
  7471. urlBox.val(url);
  7472. if (self.afterUpload) {
  7473. self.afterUpload.call(self, url, data, name);
  7474. }
  7475. alert(self.lang('uploadSuccess'));
  7476. } else {
  7477. alert(data.message);
  7478. }
  7479. },
  7480. afterError: function (html) {
  7481. dialog.hideLoading();
  7482. self.errorDialog(html);
  7483. }
  7484. });
  7485. uploadbutton.fileBox.change(function (e) {
  7486. dialog.showLoading(self.lang('uploadLoading'));
  7487. uploadbutton.submit();
  7488. });
  7489. } else {
  7490. K('.ke-upload-button', div).hide();
  7491. }
  7492. if (allowFileManager) {
  7493. viewServerBtn.click(function (e) {
  7494. self.loadPlugin('filemanager', function () {
  7495. self.plugin.filemanagerDialog({
  7496. viewType: 'LIST',
  7497. dirName: 'file',
  7498. clickFn: function (url, title) {
  7499. if (self.dialogs.length > 1) {
  7500. K('[name="url"]', div).val(url);
  7501. if (self.afterSelectFile) {
  7502. self.afterSelectFile.call(self, url);
  7503. }
  7504. self.hideDialog();
  7505. }
  7506. }
  7507. });
  7508. });
  7509. });
  7510. } else {
  7511. viewServerBtn.hide();
  7512. }
  7513. urlBox.val(fileUrl);
  7514. titleBox.val(fileTitle);
  7515. urlBox[0].focus();
  7516. urlBox[0].select();
  7517. };
  7518. self.clickToolbar(name, function () {
  7519. self.plugin.fileDialog({
  7520. clickFn: function (url, title) {
  7521. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7522. self.insertHtml(html).hideDialog().focus();
  7523. }
  7524. });
  7525. });
  7526. });
  7527. /*******************************************************************************
  7528. * KindEditor - WYSIWYG HTML Editor for Internet
  7529. * Copyright (C) 2006-2011 kindeditor.net
  7530. *
  7531. * @author Roddy <luolonghao@gmail.com>
  7532. * @site http://www.kindeditor.net/
  7533. * @licence http://www.kindeditor.net/license.php
  7534. *******************************************************************************/
  7535. KindEditor.plugin('lineheight', function (K) {
  7536. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7537. self.clickToolbar(name, function () {
  7538. var curVal = '', commonNode = self.cmd.commonNode({'*': '.line-height'});
  7539. if (commonNode) {
  7540. curVal = commonNode.css('line-height');
  7541. }
  7542. var menu = self.createMenu({
  7543. name: name,
  7544. width: 150
  7545. });
  7546. K.each(lang.lineHeight, function (i, row) {
  7547. K.each(row, function (key, val) {
  7548. menu.addItem({
  7549. title: val,
  7550. checked: curVal === key,
  7551. click: function () {
  7552. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7553. span: '.line-height=' + key
  7554. });
  7555. self.updateState();
  7556. self.addBookmark();
  7557. self.hideMenu();
  7558. }
  7559. });
  7560. });
  7561. });
  7562. });
  7563. });
  7564. /*******************************************************************************
  7565. * KindEditor - WYSIWYG HTML Editor for Internet
  7566. * Copyright (C) 2006-2011 kindeditor.net
  7567. *
  7568. * @author Roddy <luolonghao@gmail.com>
  7569. * @site http://www.kindeditor.net/
  7570. * @licence http://www.kindeditor.net/license.php
  7571. *******************************************************************************/
  7572. KindEditor.plugin('link', function (K) {
  7573. var self = this, name = 'link';
  7574. self.plugin.link = {
  7575. edit: function () {
  7576. var lang = self.lang(name + '.'),
  7577. html = '<div style="padding:20px;">' +
  7578. '<div class="ke-dialog-row">' +
  7579. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7580. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7581. '<div class="ke-dialog-row"">' +
  7582. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7583. '<select id="keType" name="type"></select>' +
  7584. '</div>' +
  7585. '</div>',
  7586. dialog = self.createDialog({
  7587. name: name,
  7588. width: 450,
  7589. title: self.lang(name),
  7590. body: html,
  7591. yesBtn: {
  7592. name: self.lang('yes'),
  7593. click: function (e) {
  7594. var url = K.trim(urlBox.val());
  7595. if (url == 'http://' || K.invalidUrl(url)) {
  7596. alert(self.lang('invalidUrl'));
  7597. urlBox[0].focus();
  7598. return;
  7599. }
  7600. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7601. }
  7602. }
  7603. }),
  7604. div = dialog.div,
  7605. urlBox = K('input[name="url"]', div),
  7606. typeBox = K('select[name="type"]', div);
  7607. urlBox.val('http://');
  7608. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7609. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7610. self.cmd.selection();
  7611. var a = self.plugin.getSelectedLink();
  7612. if (a) {
  7613. self.cmd.range.selectNode(a[0]);
  7614. self.cmd.select();
  7615. urlBox.val(a.attr('data-ke-src'));
  7616. typeBox.val(a.attr('target'));
  7617. }
  7618. urlBox[0].focus();
  7619. urlBox[0].select();
  7620. },
  7621. 'delete': function () {
  7622. self.exec('unlink', null);
  7623. }
  7624. };
  7625. self.clickToolbar(name, self.plugin.link.edit);
  7626. });
  7627. /*******************************************************************************
  7628. * KindEditor - WYSIWYG HTML Editor for Internet
  7629. * Copyright (C) 2006-2011 kindeditor.net
  7630. *
  7631. * @author Roddy <luolonghao@gmail.com>
  7632. * @site http://www.kindeditor.net/
  7633. * @licence http://www.kindeditor.net/license.php
  7634. *******************************************************************************/
  7635. KindEditor.plugin('media', function (K) {
  7636. var self = this, name = 'media', lang = self.lang(name + '.'),
  7637. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7638. allowFileManager = K.undef(self.allowFileManager, false),
  7639. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7640. extraParams = K.undef(self.extraFileUploadParams, {}),
  7641. filePostName = K.undef(self.filePostName, 'imgFile'),
  7642. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7643. self.plugin.media = {
  7644. edit: function () {
  7645. var html = [
  7646. '<div style="padding:20px;">',
  7647. '<div class="ke-dialog-row">',
  7648. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7649. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7650. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7651. '<span class="ke-button-common ke-button-outer">',
  7652. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7653. '</span>',
  7654. '</div>',
  7655. '<div class="ke-dialog-row">',
  7656. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7657. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7658. '</div>',
  7659. '<div class="ke-dialog-row">',
  7660. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7661. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7662. '</div>',
  7663. '<div class="ke-dialog-row">',
  7664. '<label for="keAutostart">' + lang.autostart + '</label>',
  7665. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7666. '</div>',
  7667. '</div>'
  7668. ].join('');
  7669. var dialog = self.createDialog({
  7670. name: name,
  7671. width: 450,
  7672. height: 230,
  7673. title: self.lang(name),
  7674. body: html,
  7675. yesBtn: {
  7676. name: self.lang('yes'),
  7677. click: function (e) {
  7678. var url = K.trim(urlBox.val()),
  7679. width = widthBox.val(),
  7680. height = heightBox.val();
  7681. if (url == 'http://' || K.invalidUrl(url)) {
  7682. alert(self.lang('invalidUrl'));
  7683. urlBox[0].focus();
  7684. return;
  7685. }
  7686. if (!/^\d*$/.test(width)) {
  7687. alert(self.lang('invalidWidth'));
  7688. widthBox[0].focus();
  7689. return;
  7690. }
  7691. if (!/^\d*$/.test(height)) {
  7692. alert(self.lang('invalidHeight'));
  7693. heightBox[0].focus();
  7694. return;
  7695. }
  7696. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7697. src: url,
  7698. type: K.mediaType(url),
  7699. width: width,
  7700. height: height,
  7701. autostart: autostartBox[0].checked ? 'true' : 'false',
  7702. loop: 'true'
  7703. });
  7704. self.insertHtml(html).hideDialog().focus();
  7705. }
  7706. }
  7707. }),
  7708. div = dialog.div,
  7709. urlBox = K('[name="url"]', div),
  7710. viewServerBtn = K('[name="viewServer"]', div),
  7711. widthBox = K('[name="width"]', div),
  7712. heightBox = K('[name="height"]', div),
  7713. autostartBox = K('[name="autostart"]', div);
  7714. urlBox.val('http://');
  7715. if (allowMediaUpload) {
  7716. var uploadbutton = K.uploadbutton({
  7717. button: K('.ke-upload-button', div)[0],
  7718. fieldName: filePostName,
  7719. extraParams: extraParams,
  7720. url: K.addParam(uploadJson, 'dir=media'),
  7721. afterUpload: function (data) {
  7722. dialog.hideLoading();
  7723. if (data.error === 0) {
  7724. var url = data.url;
  7725. if (formatUploadUrl) {
  7726. url = K.formatUrl(url, 'absolute');
  7727. }
  7728. urlBox.val(url);
  7729. if (self.afterUpload) {
  7730. self.afterUpload.call(self, url, data, name);
  7731. }
  7732. alert(self.lang('uploadSuccess'));
  7733. } else {
  7734. alert(data.message);
  7735. }
  7736. },
  7737. afterError: function (html) {
  7738. dialog.hideLoading();
  7739. self.errorDialog(html);
  7740. }
  7741. });
  7742. uploadbutton.fileBox.change(function (e) {
  7743. dialog.showLoading(self.lang('uploadLoading'));
  7744. uploadbutton.submit();
  7745. });
  7746. } else {
  7747. K('.ke-upload-button', div).hide();
  7748. }
  7749. if (allowFileManager) {
  7750. viewServerBtn.click(function (e) {
  7751. self.loadPlugin('filemanager', function () {
  7752. self.plugin.filemanagerDialog({
  7753. viewType: 'LIST',
  7754. dirName: 'media',
  7755. clickFn: function (url, title) {
  7756. if (self.dialogs.length > 1) {
  7757. K('[name="url"]', div).val(url);
  7758. if (self.afterSelectFile) {
  7759. self.afterSelectFile.call(self, url);
  7760. }
  7761. self.hideDialog();
  7762. }
  7763. }
  7764. });
  7765. });
  7766. });
  7767. } else {
  7768. viewServerBtn.hide();
  7769. }
  7770. var img = self.plugin.getSelectedMedia();
  7771. if (img) {
  7772. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7773. urlBox.val(attrs.src);
  7774. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7775. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7776. autostartBox[0].checked = (attrs.autostart === 'true');
  7777. }
  7778. urlBox[0].focus();
  7779. urlBox[0].select();
  7780. },
  7781. 'delete': function () {
  7782. self.plugin.getSelectedMedia().remove();
  7783. self.addBookmark();
  7784. }
  7785. };
  7786. self.clickToolbar(name, self.plugin.media.edit);
  7787. });
  7788. /*******************************************************************************
  7789. * KindEditor - WYSIWYG HTML Editor for Internet
  7790. * Copyright (C) 2006-2011 kindeditor.net
  7791. *
  7792. * @author Roddy <luolonghao@gmail.com>
  7793. * @site http://www.kindeditor.net/
  7794. * @licence http://www.kindeditor.net/license.php
  7795. *******************************************************************************/
  7796. (function (K) {
  7797. function KSWFUpload(options) {
  7798. this.init(options);
  7799. }
  7800. K.extend(KSWFUpload, {
  7801. init: function (options) {
  7802. var self = this;
  7803. options.afterError = options.afterError || function (str) {
  7804. alert(str);
  7805. };
  7806. self.options = options;
  7807. self.progressbars = {};
  7808. self.div = K(options.container).html([
  7809. '<div class="ke-swfupload">',
  7810. '<div class="ke-swfupload-top">',
  7811. '<div class="ke-inline-block ke-swfupload-button">',
  7812. '<input type="button" value="Browse" />',
  7813. '</div>',
  7814. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7815. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7816. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7817. '</span>',
  7818. '</div>',
  7819. '<div class="ke-swfupload-body"></div>',
  7820. '</div>'
  7821. ].join(''));
  7822. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7823. function showError(itemDiv, msg) {
  7824. K('.ke-status > div', itemDiv).hide();
  7825. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7826. }
  7827. var settings = {
  7828. debug: false,
  7829. upload_url: options.uploadUrl,
  7830. flash_url: options.flashUrl,
  7831. file_post_name: options.filePostName,
  7832. button_placeholder: K('.ke-swfupload-button > input', self.div)[0],
  7833. button_image_url: options.buttonImageUrl,
  7834. button_width: options.buttonWidth,
  7835. button_height: options.buttonHeight,
  7836. button_cursor: SWFUpload.CURSOR.HAND,
  7837. file_types: options.fileTypes,
  7838. file_types_description: options.fileTypesDesc,
  7839. file_upload_limit: options.fileUploadLimit,
  7840. file_size_limit: options.fileSizeLimit,
  7841. post_params: options.postParams,
  7842. file_queued_handler: function (file) {
  7843. file.url = self.options.fileIconUrl;
  7844. self.appendFile(file);
  7845. },
  7846. file_queue_error_handler: function (file, errorCode, message) {
  7847. var errorName = '';
  7848. switch (errorCode) {
  7849. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7850. errorName = options.queueLimitExceeded;
  7851. break;
  7852. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7853. errorName = options.fileExceedsSizeLimit;
  7854. break;
  7855. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7856. errorName = options.zeroByteFile;
  7857. break;
  7858. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7859. errorName = options.invalidFiletype;
  7860. break;
  7861. default:
  7862. errorName = options.unknownError;
  7863. break;
  7864. }
  7865. K.DEBUG && alert(errorName);
  7866. },
  7867. upload_start_handler: function (file) {
  7868. var self = this;
  7869. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7870. K('.ke-status > div', itemDiv).hide();
  7871. K('.ke-progressbar', itemDiv).show();
  7872. },
  7873. upload_progress_handler: function (file, bytesLoaded, bytesTotal) {
  7874. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7875. var progressbar = self.progressbars[file.id];
  7876. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7877. progressbar.percent.html(percent + '%');
  7878. },
  7879. upload_error_handler: function (file, errorCode, message) {
  7880. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7881. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7882. showError(itemDiv, self.options.errorMessage);
  7883. }
  7884. },
  7885. upload_success_handler: function (file, serverData) {
  7886. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7887. var data = {};
  7888. try {
  7889. data = K.json(serverData);
  7890. } catch (e) {
  7891. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7892. }
  7893. if (data.error !== 0) {
  7894. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7895. return;
  7896. }
  7897. file.url = data.url;
  7898. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7899. K('.ke-status > div', itemDiv).hide();
  7900. }
  7901. };
  7902. self.swfu = new SWFUpload(settings);
  7903. K('.ke-swfupload-startupload input', self.div).click(function () {
  7904. self.swfu.startUpload();
  7905. });
  7906. },
  7907. getUrlList: function () {
  7908. var list = [];
  7909. K('.ke-img', self.bodyDiv).each(function () {
  7910. var img = K(this);
  7911. var status = img.attr('data-status');
  7912. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7913. list.push(img.data('data'));
  7914. }
  7915. });
  7916. return list;
  7917. },
  7918. removeFile: function (fileId) {
  7919. var self = this;
  7920. self.swfu.cancelUpload(fileId);
  7921. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7922. K('.ke-photo', itemDiv).unbind();
  7923. K('.ke-delete', itemDiv).unbind();
  7924. itemDiv.remove();
  7925. },
  7926. removeFiles: function () {
  7927. var self = this;
  7928. K('.ke-item', self.bodyDiv).each(function () {
  7929. self.removeFile(K(this).attr('data-id'));
  7930. });
  7931. },
  7932. appendFile: function (file) {
  7933. var self = this;
  7934. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7935. self.bodyDiv.append(itemDiv);
  7936. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7937. .mouseover(function (e) {
  7938. K(this).addClass('ke-on');
  7939. })
  7940. .mouseout(function (e) {
  7941. K(this).removeClass('ke-on');
  7942. });
  7943. itemDiv.append(photoDiv);
  7944. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7945. photoDiv.append(img);
  7946. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function () {
  7947. self.removeFile(file.id);
  7948. });
  7949. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7950. K(['<div class="ke-progressbar">',
  7951. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7952. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7953. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7954. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7955. self.progressbars[file.id] = {
  7956. bar: K('.ke-progressbar-bar-inner', photoDiv),
  7957. percent: K('.ke-progressbar-percent', photoDiv)
  7958. };
  7959. },
  7960. remove: function () {
  7961. this.removeFiles();
  7962. this.swfu.destroy();
  7963. this.div.html('');
  7964. }
  7965. });
  7966. K.swfupload = function (element, options) {
  7967. return new KSWFUpload(element, options);
  7968. };
  7969. })(KindEditor);
  7970. KindEditor.plugin('multiimage', function (K) {
  7971. var self = this, name = 'multiimage',
  7972. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7973. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7974. imgPath = self.pluginsPath + 'multiimage/images/',
  7975. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  7976. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  7977. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  7978. filePostName = K.undef(self.filePostName, 'imgFile'),
  7979. lang = self.lang(name + '.');
  7980. self.plugin.multiImageDialog = function (options) {
  7981. var clickFn = options.clickFn,
  7982. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit: imageUploadLimit, sizeLimit: imageSizeLimit});
  7983. var html = [
  7984. '<div style="padding:20px;">',
  7985. '<div class="swfupload">',
  7986. '</div>',
  7987. '</div>'
  7988. ].join('');
  7989. var dialog = self.createDialog({
  7990. name: name,
  7991. width: 650,
  7992. height: 510,
  7993. title: self.lang(name),
  7994. body: html,
  7995. previewBtn: {
  7996. name: lang.insertAll,
  7997. click: function (e) {
  7998. clickFn.call(self, swfupload.getUrlList());
  7999. }
  8000. },
  8001. yesBtn: {
  8002. name: lang.clearAll,
  8003. click: function (e) {
  8004. swfupload.removeFiles();
  8005. }
  8006. },
  8007. beforeRemove: function () {
  8008. if (!K.IE || K.V <= 8) {
  8009. swfupload.remove();
  8010. }
  8011. }
  8012. }),
  8013. div = dialog.div;
  8014. var swfupload = K.swfupload({
  8015. container: K('.swfupload', div),
  8016. buttonImageUrl: imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8017. buttonWidth: self.langType == 'zh-CN' ? 72 : 88,
  8018. buttonHeight: 23,
  8019. fileIconUrl: imgPath + 'image.png',
  8020. uploadDesc: uploadDesc,
  8021. startButtonValue: lang.startUpload,
  8022. uploadUrl: K.addParam(uploadJson, 'dir=image'),
  8023. flashUrl: imgPath + 'swfupload.swf',
  8024. filePostName: filePostName,
  8025. fileTypes: '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8026. fileTypesDesc: 'Image Files',
  8027. fileUploadLimit: imageUploadLimit,
  8028. fileSizeLimit: imageSizeLimit,
  8029. postParams: K.undef(self.extraFileUploadParams, {}),
  8030. queueLimitExceeded: lang.queueLimitExceeded,
  8031. fileExceedsSizeLimit: lang.fileExceedsSizeLimit,
  8032. zeroByteFile: lang.zeroByteFile,
  8033. invalidFiletype: lang.invalidFiletype,
  8034. unknownError: lang.unknownError,
  8035. pendingMessage: lang.pending,
  8036. errorMessage: lang.uploadError,
  8037. afterError: function (html) {
  8038. self.errorDialog(html);
  8039. }
  8040. });
  8041. return dialog;
  8042. };
  8043. self.clickToolbar(name, function () {
  8044. self.plugin.multiImageDialog({
  8045. clickFn: function (urlList) {
  8046. if (urlList.length === 0) {
  8047. return;
  8048. }
  8049. K.each(urlList, function (i, data) {
  8050. if (self.afterUpload) {
  8051. self.afterUpload.call(self, data.url, data, 'multiimage');
  8052. }
  8053. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8054. });
  8055. setTimeout(function () {
  8056. self.hideDialog().focus();
  8057. }, 0);
  8058. }
  8059. });
  8060. });
  8061. });
  8062. /* ******************* */
  8063. /* Constructor & Init */
  8064. /* ******************* */
  8065. (function () {
  8066. window.SWFUpload = function (settings) {
  8067. this.initSWFUpload(settings);
  8068. };
  8069. SWFUpload.prototype.initSWFUpload = function (settings) {
  8070. try {
  8071. this.customSettings = {};
  8072. this.settings = settings;
  8073. this.eventQueue = [];
  8074. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8075. this.movieElement = null;
  8076. SWFUpload.instances[this.movieName] = this;
  8077. this.initSettings();
  8078. this.loadFlash();
  8079. this.displayDebugInfo();
  8080. } catch (ex) {
  8081. delete SWFUpload.instances[this.movieName];
  8082. throw ex;
  8083. }
  8084. };
  8085. /* *************** */
  8086. /* Static Members */
  8087. /* *************** */
  8088. SWFUpload.instances = {};
  8089. SWFUpload.movieCount = 0;
  8090. SWFUpload.version = "2.2.0 2009-03-25";
  8091. SWFUpload.QUEUE_ERROR = {
  8092. QUEUE_LIMIT_EXCEEDED: -100,
  8093. FILE_EXCEEDS_SIZE_LIMIT: -110,
  8094. ZERO_BYTE_FILE: -120,
  8095. INVALID_FILETYPE: -130
  8096. };
  8097. SWFUpload.UPLOAD_ERROR = {
  8098. HTTP_ERROR: -200,
  8099. MISSING_UPLOAD_URL: -210,
  8100. IO_ERROR: -220,
  8101. SECURITY_ERROR: -230,
  8102. UPLOAD_LIMIT_EXCEEDED: -240,
  8103. UPLOAD_FAILED: -250,
  8104. SPECIFIED_FILE_ID_NOT_FOUND: -260,
  8105. FILE_VALIDATION_FAILED: -270,
  8106. FILE_CANCELLED: -280,
  8107. UPLOAD_STOPPED: -290
  8108. };
  8109. SWFUpload.FILE_STATUS = {
  8110. QUEUED: -1,
  8111. IN_PROGRESS: -2,
  8112. ERROR: -3,
  8113. COMPLETE: -4,
  8114. CANCELLED: -5
  8115. };
  8116. SWFUpload.BUTTON_ACTION = {
  8117. SELECT_FILE: -100,
  8118. SELECT_FILES: -110,
  8119. START_UPLOAD: -120
  8120. };
  8121. SWFUpload.CURSOR = {
  8122. ARROW: -1,
  8123. HAND: -2
  8124. };
  8125. SWFUpload.WINDOW_MODE = {
  8126. WINDOW: "window",
  8127. TRANSPARENT: "transparent",
  8128. OPAQUE: "opaque"
  8129. };
  8130. SWFUpload.completeURL = function (url) {
  8131. if (typeof (url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8132. return url;
  8133. }
  8134. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8135. var indexSlash = window.location.pathname.lastIndexOf("/");
  8136. if (indexSlash <= 0) {
  8137. path = "/";
  8138. } else {
  8139. path = window.location.pathname.substr(0, indexSlash) + "/";
  8140. }
  8141. return /*currentURL +*/ path + url;
  8142. };
  8143. /* ******************** */
  8144. /* Instance Members */
  8145. /* ******************** */
  8146. SWFUpload.prototype.initSettings = function () {
  8147. this.ensureDefault = function (settingName, defaultValue) {
  8148. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8149. };
  8150. this.ensureDefault("upload_url", "");
  8151. this.ensureDefault("preserve_relative_urls", false);
  8152. this.ensureDefault("file_post_name", "Filedata");
  8153. this.ensureDefault("post_params", {});
  8154. this.ensureDefault("use_query_string", false);
  8155. this.ensureDefault("requeue_on_error", false);
  8156. this.ensureDefault("http_success", []);
  8157. this.ensureDefault("assume_success_timeout", 0);
  8158. this.ensureDefault("file_types", "*.*");
  8159. this.ensureDefault("file_types_description", "All Files");
  8160. this.ensureDefault("file_size_limit", 0);
  8161. this.ensureDefault("file_upload_limit", 0);
  8162. this.ensureDefault("file_queue_limit", 0);
  8163. this.ensureDefault("flash_url", "swfupload.swf");
  8164. this.ensureDefault("prevent_swf_caching", true);
  8165. this.ensureDefault("button_image_url", "");
  8166. this.ensureDefault("button_width", 1);
  8167. this.ensureDefault("button_height", 1);
  8168. this.ensureDefault("button_text", "");
  8169. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8170. this.ensureDefault("button_text_top_padding", 0);
  8171. this.ensureDefault("button_text_left_padding", 0);
  8172. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8173. this.ensureDefault("button_disabled", false);
  8174. this.ensureDefault("button_placeholder_id", "");
  8175. this.ensureDefault("button_placeholder", null);
  8176. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8177. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8178. this.ensureDefault("debug", false);
  8179. this.settings.debug_enabled = this.settings.debug;
  8180. this.settings.return_upload_start_handler = this.returnUploadStart;
  8181. this.ensureDefault("swfupload_loaded_handler", null);
  8182. this.ensureDefault("file_dialog_start_handler", null);
  8183. this.ensureDefault("file_queued_handler", null);
  8184. this.ensureDefault("file_queue_error_handler", null);
  8185. this.ensureDefault("file_dialog_complete_handler", null);
  8186. this.ensureDefault("upload_start_handler", null);
  8187. this.ensureDefault("upload_progress_handler", null);
  8188. this.ensureDefault("upload_error_handler", null);
  8189. this.ensureDefault("upload_success_handler", null);
  8190. this.ensureDefault("upload_complete_handler", null);
  8191. this.ensureDefault("debug_handler", this.debugMessage);
  8192. this.ensureDefault("custom_settings", {});
  8193. this.customSettings = this.settings.custom_settings;
  8194. if (!!this.settings.prevent_swf_caching) {
  8195. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8196. }
  8197. if (!this.settings.preserve_relative_urls) {
  8198. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8199. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8200. }
  8201. delete this.ensureDefault;
  8202. };
  8203. SWFUpload.prototype.loadFlash = function () {
  8204. var targetElement, tempParent;
  8205. if (document.getElementById(this.movieName) !== null) {
  8206. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8207. }
  8208. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8209. if (targetElement == undefined) {
  8210. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8211. }
  8212. tempParent = document.createElement("div");
  8213. tempParent.innerHTML = this.getFlashHTML();
  8214. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8215. if (window[this.movieName] == undefined) {
  8216. window[this.movieName] = this.getMovieElement();
  8217. }
  8218. };
  8219. SWFUpload.prototype.getFlashHTML = function () {
  8220. var classid = '';
  8221. if (KindEditor.IE && KindEditor.V > 8) {
  8222. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8223. }
  8224. 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">',
  8225. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8226. '<param name="movie" value="', this.settings.flash_url, '" />',
  8227. '<param name="quality" value="high" />',
  8228. '<param name="menu" value="false" />',
  8229. '<param name="allowScriptAccess" value="always" />',
  8230. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8231. '</object>'].join("");
  8232. };
  8233. SWFUpload.prototype.getFlashVars = function () {
  8234. var paramString = this.buildParamString();
  8235. var httpSuccessString = this.settings.http_success.join(",");
  8236. return ["movieName=", encodeURIComponent(this.movieName),
  8237. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8238. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8239. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8240. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8241. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8242. "&amp;params=", encodeURIComponent(paramString),
  8243. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8244. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8245. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8246. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8247. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8248. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8249. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8250. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8251. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8252. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8253. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8254. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8255. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8256. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8257. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8258. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8259. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8260. ].join("");
  8261. };
  8262. SWFUpload.prototype.getMovieElement = function () {
  8263. if (this.movieElement == undefined) {
  8264. this.movieElement = document.getElementById(this.movieName);
  8265. }
  8266. if (this.movieElement === null) {
  8267. throw "Could not find Flash element";
  8268. }
  8269. return this.movieElement;
  8270. };
  8271. SWFUpload.prototype.buildParamString = function () {
  8272. var postParams = this.settings.post_params;
  8273. var paramStringPairs = [];
  8274. if (typeof (postParams) === "object") {
  8275. for (var name in postParams) {
  8276. if (postParams.hasOwnProperty(name)) {
  8277. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8278. }
  8279. }
  8280. }
  8281. return paramStringPairs.join("&amp;");
  8282. };
  8283. SWFUpload.prototype.destroy = function () {
  8284. try {
  8285. this.cancelUpload(null, false);
  8286. var movieElement = null;
  8287. movieElement = this.getMovieElement();
  8288. if (movieElement && typeof (movieElement.CallFunction) === "unknown") {
  8289. for (var i in movieElement) {
  8290. try {
  8291. if (typeof (movieElement[i]) === "function") {
  8292. movieElement[i] = null;
  8293. }
  8294. } catch (ex1) {
  8295. }
  8296. }
  8297. try {
  8298. movieElement.parentNode.removeChild(movieElement);
  8299. } catch (ex) {
  8300. }
  8301. }
  8302. window[this.movieName] = null;
  8303. SWFUpload.instances[this.movieName] = null;
  8304. delete SWFUpload.instances[this.movieName];
  8305. this.movieElement = null;
  8306. this.settings = null;
  8307. this.customSettings = null;
  8308. this.eventQueue = null;
  8309. this.movieName = null;
  8310. return true;
  8311. } catch (ex2) {
  8312. return false;
  8313. }
  8314. };
  8315. SWFUpload.prototype.displayDebugInfo = function () {
  8316. this.debug(
  8317. [
  8318. "---SWFUpload Instance Info---\n",
  8319. "Version: ", SWFUpload.version, "\n",
  8320. "Movie Name: ", this.movieName, "\n",
  8321. "Settings:\n",
  8322. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8323. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8324. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8325. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8326. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8327. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8328. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8329. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8330. "\t", "file_types: ", this.settings.file_types, "\n",
  8331. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8332. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8333. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8334. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8335. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8336. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8337. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8338. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8339. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8340. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8341. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8342. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8343. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8344. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8345. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8346. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8347. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8348. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8349. "Event Handlers:\n",
  8350. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8351. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8352. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8353. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8354. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8355. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8356. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8357. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8358. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8359. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8360. ].join("")
  8361. );
  8362. };
  8363. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8364. the maintain v2 API compatibility
  8365. */
  8366. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8367. if (value == undefined) {
  8368. return (this.settings[name] = default_value);
  8369. } else {
  8370. return (this.settings[name] = value);
  8371. }
  8372. };
  8373. SWFUpload.prototype.getSetting = function (name) {
  8374. if (this.settings[name] != undefined) {
  8375. return this.settings[name];
  8376. }
  8377. return "";
  8378. };
  8379. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8380. argumentArray = argumentArray || [];
  8381. var movieElement = this.getMovieElement();
  8382. var returnValue, returnString;
  8383. try {
  8384. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8385. returnValue = eval(returnString);
  8386. } catch (ex) {
  8387. throw "Call to " + functionName + " failed";
  8388. }
  8389. if (returnValue != undefined && typeof returnValue.post === "object") {
  8390. returnValue = this.unescapeFilePostParams(returnValue);
  8391. }
  8392. return returnValue;
  8393. };
  8394. /* *****************************
  8395. -- Flash control methods --
  8396. Your UI should use these
  8397. to operate SWFUpload
  8398. ***************************** */
  8399. SWFUpload.prototype.selectFile = function () {
  8400. this.callFlash("SelectFile");
  8401. };
  8402. SWFUpload.prototype.selectFiles = function () {
  8403. this.callFlash("SelectFiles");
  8404. };
  8405. SWFUpload.prototype.startUpload = function (fileID) {
  8406. this.callFlash("StartUpload", [fileID]);
  8407. };
  8408. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8409. if (triggerErrorEvent !== false) {
  8410. triggerErrorEvent = true;
  8411. }
  8412. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8413. };
  8414. SWFUpload.prototype.stopUpload = function () {
  8415. this.callFlash("StopUpload");
  8416. };
  8417. /* ************************
  8418. * Settings methods
  8419. * These methods change the SWFUpload settings.
  8420. * SWFUpload settings should not be changed directly on the settings object
  8421. * since many of the settings need to be passed to Flash in order to take
  8422. * effect.
  8423. * *********************** */
  8424. SWFUpload.prototype.getStats = function () {
  8425. return this.callFlash("GetStats");
  8426. };
  8427. SWFUpload.prototype.setStats = function (statsObject) {
  8428. this.callFlash("SetStats", [statsObject]);
  8429. };
  8430. SWFUpload.prototype.getFile = function (fileID) {
  8431. if (typeof (fileID) === "number") {
  8432. return this.callFlash("GetFileByIndex", [fileID]);
  8433. } else {
  8434. return this.callFlash("GetFile", [fileID]);
  8435. }
  8436. };
  8437. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8438. return this.callFlash("AddFileParam", [fileID, name, value]);
  8439. };
  8440. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8441. this.callFlash("RemoveFileParam", [fileID, name]);
  8442. };
  8443. SWFUpload.prototype.setUploadURL = function (url) {
  8444. this.settings.upload_url = url.toString();
  8445. this.callFlash("SetUploadURL", [url]);
  8446. };
  8447. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8448. this.settings.post_params = paramsObject;
  8449. this.callFlash("SetPostParams", [paramsObject]);
  8450. };
  8451. SWFUpload.prototype.addPostParam = function (name, value) {
  8452. this.settings.post_params[name] = value;
  8453. this.callFlash("SetPostParams", [this.settings.post_params]);
  8454. };
  8455. SWFUpload.prototype.removePostParam = function (name) {
  8456. delete this.settings.post_params[name];
  8457. this.callFlash("SetPostParams", [this.settings.post_params]);
  8458. };
  8459. SWFUpload.prototype.setFileTypes = function (types, description) {
  8460. this.settings.file_types = types;
  8461. this.settings.file_types_description = description;
  8462. this.callFlash("SetFileTypes", [types, description]);
  8463. };
  8464. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8465. this.settings.file_size_limit = fileSizeLimit;
  8466. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8467. };
  8468. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8469. this.settings.file_upload_limit = fileUploadLimit;
  8470. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8471. };
  8472. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8473. this.settings.file_queue_limit = fileQueueLimit;
  8474. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8475. };
  8476. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8477. this.settings.file_post_name = filePostName;
  8478. this.callFlash("SetFilePostName", [filePostName]);
  8479. };
  8480. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8481. this.settings.use_query_string = useQueryString;
  8482. this.callFlash("SetUseQueryString", [useQueryString]);
  8483. };
  8484. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8485. this.settings.requeue_on_error = requeueOnError;
  8486. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8487. };
  8488. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8489. if (typeof http_status_codes === "string") {
  8490. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8491. }
  8492. this.settings.http_success = http_status_codes;
  8493. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8494. };
  8495. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8496. this.settings.assume_success_timeout = timeout_seconds;
  8497. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8498. };
  8499. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8500. this.settings.debug_enabled = debugEnabled;
  8501. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8502. };
  8503. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8504. if (buttonImageURL == undefined) {
  8505. buttonImageURL = "";
  8506. }
  8507. this.settings.button_image_url = buttonImageURL;
  8508. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8509. };
  8510. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8511. this.settings.button_width = width;
  8512. this.settings.button_height = height;
  8513. var movie = this.getMovieElement();
  8514. if (movie != undefined) {
  8515. movie.style.width = width + "px";
  8516. movie.style.height = height + "px";
  8517. }
  8518. this.callFlash("SetButtonDimensions", [width, height]);
  8519. };
  8520. SWFUpload.prototype.setButtonText = function (html) {
  8521. this.settings.button_text = html;
  8522. this.callFlash("SetButtonText", [html]);
  8523. };
  8524. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8525. this.settings.button_text_top_padding = top;
  8526. this.settings.button_text_left_padding = left;
  8527. this.callFlash("SetButtonTextPadding", [left, top]);
  8528. };
  8529. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8530. this.settings.button_text_style = css;
  8531. this.callFlash("SetButtonTextStyle", [css]);
  8532. };
  8533. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8534. this.settings.button_disabled = isDisabled;
  8535. this.callFlash("SetButtonDisabled", [isDisabled]);
  8536. };
  8537. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8538. this.settings.button_action = buttonAction;
  8539. this.callFlash("SetButtonAction", [buttonAction]);
  8540. };
  8541. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8542. this.settings.button_cursor = cursor;
  8543. this.callFlash("SetButtonCursor", [cursor]);
  8544. };
  8545. /* *******************************
  8546. Flash Event Interfaces
  8547. These functions are used by Flash to trigger the various
  8548. events.
  8549. All these functions a Private.
  8550. Because the ExternalInterface library is buggy the event calls
  8551. are added to a queue and the queue then executed by a setTimeout.
  8552. This ensures that events are executed in a determinate order and that
  8553. the ExternalInterface bugs are avoided.
  8554. ******************************* */
  8555. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8556. if (argumentArray == undefined) {
  8557. argumentArray = [];
  8558. } else if (!(argumentArray instanceof Array)) {
  8559. argumentArray = [argumentArray];
  8560. }
  8561. var self = this;
  8562. if (typeof this.settings[handlerName] === "function") {
  8563. this.eventQueue.push(function () {
  8564. this.settings[handlerName].apply(this, argumentArray);
  8565. });
  8566. setTimeout(function () {
  8567. self.executeNextEvent();
  8568. }, 0);
  8569. } else if (this.settings[handlerName] !== null) {
  8570. throw "Event handler " + handlerName + " is unknown or is not a function";
  8571. }
  8572. };
  8573. SWFUpload.prototype.executeNextEvent = function () {
  8574. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8575. if (typeof (f) === "function") {
  8576. f.apply(this);
  8577. }
  8578. };
  8579. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8580. var reg = /[$]([0-9a-f]{4})/i;
  8581. var unescapedPost = {};
  8582. var uk;
  8583. if (file != undefined) {
  8584. for (var k in file.post) {
  8585. if (file.post.hasOwnProperty(k)) {
  8586. uk = k;
  8587. var match;
  8588. while ((match = reg.exec(uk)) !== null) {
  8589. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8590. }
  8591. unescapedPost[uk] = file.post[k];
  8592. }
  8593. }
  8594. file.post = unescapedPost;
  8595. }
  8596. return file;
  8597. };
  8598. SWFUpload.prototype.testExternalInterface = function () {
  8599. try {
  8600. return this.callFlash("TestExternalInterface");
  8601. } catch (ex) {
  8602. return false;
  8603. }
  8604. };
  8605. SWFUpload.prototype.flashReady = function () {
  8606. var movieElement = this.getMovieElement();
  8607. if (!movieElement) {
  8608. this.debug("Flash called back ready but the flash movie can't be found.");
  8609. return;
  8610. }
  8611. this.cleanUp(movieElement);
  8612. this.queueEvent("swfupload_loaded_handler");
  8613. };
  8614. SWFUpload.prototype.cleanUp = function (movieElement) {
  8615. try {
  8616. if (this.movieElement && typeof (movieElement.CallFunction) === "unknown") {
  8617. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8618. for (var key in movieElement) {
  8619. try {
  8620. if (typeof (movieElement[key]) === "function") {
  8621. movieElement[key] = null;
  8622. }
  8623. } catch (ex) {
  8624. }
  8625. }
  8626. }
  8627. } catch (ex1) {
  8628. }
  8629. window["__flash__removeCallback"] = function (instance, name) {
  8630. try {
  8631. if (instance) {
  8632. instance[name] = null;
  8633. }
  8634. } catch (flashEx) {
  8635. }
  8636. };
  8637. };
  8638. /* This is a chance to do something before the browse window opens */
  8639. SWFUpload.prototype.fileDialogStart = function () {
  8640. this.queueEvent("file_dialog_start_handler");
  8641. };
  8642. /* Called when a file is successfully added to the queue. */
  8643. SWFUpload.prototype.fileQueued = function (file) {
  8644. file = this.unescapeFilePostParams(file);
  8645. this.queueEvent("file_queued_handler", file);
  8646. };
  8647. /* Handle errors that occur when an attempt to queue a file fails. */
  8648. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8649. file = this.unescapeFilePostParams(file);
  8650. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8651. };
  8652. /* Called after the file dialog has closed and the selected files have been queued.
  8653. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8654. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8655. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8656. };
  8657. SWFUpload.prototype.uploadStart = function (file) {
  8658. file = this.unescapeFilePostParams(file);
  8659. this.queueEvent("return_upload_start_handler", file);
  8660. };
  8661. SWFUpload.prototype.returnUploadStart = function (file) {
  8662. var returnValue;
  8663. if (typeof this.settings.upload_start_handler === "function") {
  8664. file = this.unescapeFilePostParams(file);
  8665. returnValue = this.settings.upload_start_handler.call(this, file);
  8666. } else if (this.settings.upload_start_handler != undefined) {
  8667. throw "upload_start_handler must be a function";
  8668. }
  8669. if (returnValue === undefined) {
  8670. returnValue = true;
  8671. }
  8672. returnValue = !!returnValue;
  8673. this.callFlash("ReturnUploadStart", [returnValue]);
  8674. };
  8675. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8676. file = this.unescapeFilePostParams(file);
  8677. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8678. };
  8679. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8680. file = this.unescapeFilePostParams(file);
  8681. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8682. };
  8683. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8684. file = this.unescapeFilePostParams(file);
  8685. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8686. };
  8687. SWFUpload.prototype.uploadComplete = function (file) {
  8688. file = this.unescapeFilePostParams(file);
  8689. this.queueEvent("upload_complete_handler", file);
  8690. };
  8691. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8692. internal debug console. You can override this event and have messages written where you want. */
  8693. SWFUpload.prototype.debug = function (message) {
  8694. this.queueEvent("debug_handler", message);
  8695. };
  8696. /* **********************************
  8697. Debug Console
  8698. The debug console is a self contained, in page location
  8699. for debug message to be sent. The Debug Console adds
  8700. itself to the body if necessary.
  8701. The console is automatically scrolled as messages appear.
  8702. If you are using your own debug handler or when you deploy to production and
  8703. have debug disabled you can remove these functions to reduce the file size
  8704. and complexity.
  8705. ********************************** */
  8706. SWFUpload.prototype.debugMessage = function (message) {
  8707. if (this.settings.debug) {
  8708. var exceptionMessage, exceptionValues = [];
  8709. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8710. for (var key in message) {
  8711. if (message.hasOwnProperty(key)) {
  8712. exceptionValues.push(key + ": " + message[key]);
  8713. }
  8714. }
  8715. exceptionMessage = exceptionValues.join("\n") || "";
  8716. exceptionValues = exceptionMessage.split("\n");
  8717. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8718. SWFUpload.Console.writeLine(exceptionMessage);
  8719. } else {
  8720. SWFUpload.Console.writeLine(message);
  8721. }
  8722. }
  8723. };
  8724. SWFUpload.Console = {};
  8725. SWFUpload.Console.writeLine = function (message) {
  8726. var console, documentForm;
  8727. try {
  8728. console = document.getElementById("SWFUpload_Console");
  8729. if (!console) {
  8730. documentForm = document.createElement("form");
  8731. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8732. console = document.createElement("textarea");
  8733. console.id = "SWFUpload_Console";
  8734. console.style.fontFamily = "monospace";
  8735. console.setAttribute("wrap", "off");
  8736. console.wrap = "off";
  8737. console.style.overflow = "auto";
  8738. console.style.width = "700px";
  8739. console.style.height = "350px";
  8740. console.style.margin = "5px";
  8741. documentForm.appendChild(console);
  8742. }
  8743. console.value += message + "\n";
  8744. console.scrollTop = console.scrollHeight - console.clientHeight;
  8745. } catch (ex) {
  8746. alert("Exception: " + ex.name + " Message: " + ex.message);
  8747. }
  8748. };
  8749. })();
  8750. (function () {
  8751. /*
  8752. Queue Plug-in
  8753. Features:
  8754. *Adds a cancelQueue() method for cancelling the entire queue.
  8755. *All queued files are uploaded when startUpload() is called.
  8756. *If false is returned from uploadComplete then the queue upload is stopped.
  8757. If false is not returned (strict comparison) then the queue upload is continued.
  8758. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8759. Set the event handler with the queue_complete_handler setting.
  8760. */
  8761. if (typeof (SWFUpload) === "function") {
  8762. SWFUpload.queue = {};
  8763. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8764. return function () {
  8765. if (typeof (oldInitSettings) === "function") {
  8766. oldInitSettings.call(this);
  8767. }
  8768. this.queueSettings = {};
  8769. this.queueSettings.queue_cancelled_flag = false;
  8770. this.queueSettings.queue_upload_count = 0;
  8771. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8772. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8773. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8774. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8775. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8776. };
  8777. })(SWFUpload.prototype.initSettings);
  8778. SWFUpload.prototype.startUpload = function (fileID) {
  8779. this.queueSettings.queue_cancelled_flag = false;
  8780. this.callFlash("StartUpload", [fileID]);
  8781. };
  8782. SWFUpload.prototype.cancelQueue = function () {
  8783. this.queueSettings.queue_cancelled_flag = true;
  8784. this.stopUpload();
  8785. var stats = this.getStats();
  8786. while (stats.files_queued > 0) {
  8787. this.cancelUpload();
  8788. stats = this.getStats();
  8789. }
  8790. };
  8791. SWFUpload.queue.uploadStartHandler = function (file) {
  8792. var returnValue;
  8793. if (typeof (this.queueSettings.user_upload_start_handler) === "function") {
  8794. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8795. }
  8796. returnValue = (returnValue === false) ? false : true;
  8797. this.queueSettings.queue_cancelled_flag = !returnValue;
  8798. return returnValue;
  8799. };
  8800. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8801. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8802. var continueUpload;
  8803. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8804. this.queueSettings.queue_upload_count++;
  8805. }
  8806. if (typeof (user_upload_complete_handler) === "function") {
  8807. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8808. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8809. continueUpload = false;
  8810. } else {
  8811. continueUpload = true;
  8812. }
  8813. if (continueUpload) {
  8814. var stats = this.getStats();
  8815. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8816. this.startUpload();
  8817. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8818. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8819. this.queueSettings.queue_upload_count = 0;
  8820. } else {
  8821. this.queueSettings.queue_cancelled_flag = false;
  8822. this.queueSettings.queue_upload_count = 0;
  8823. }
  8824. }
  8825. };
  8826. }
  8827. })();
  8828. /*******************************************************************************
  8829. * KindEditor - WYSIWYG HTML Editor for Internet
  8830. * Copyright (C) 2006-2011 kindeditor.net
  8831. *
  8832. * @author Roddy <luolonghao@gmail.com>
  8833. * @site http://www.kindeditor.net/
  8834. * @licence http://www.kindeditor.net/license.php
  8835. *******************************************************************************/
  8836. KindEditor.plugin('pagebreak', function (K) {
  8837. var self = this;
  8838. var name = 'pagebreak';
  8839. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8840. self.clickToolbar(name, function () {
  8841. var cmd = self.cmd, range = cmd.range;
  8842. self.focus();
  8843. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8844. self.insertHtml(pagebreakHtml + tail);
  8845. if (tail !== '') {
  8846. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8847. range.selectNodeContents(p[0]);
  8848. p.removeAttr('id');
  8849. cmd.select();
  8850. }
  8851. });
  8852. });
  8853. /*******************************************************************************
  8854. * KindEditor - WYSIWYG HTML Editor for Internet
  8855. * Copyright (C) 2006-2011 kindeditor.net
  8856. *
  8857. * @author Roddy <luolonghao@gmail.com>
  8858. * @site http://www.kindeditor.net/
  8859. * @licence http://www.kindeditor.net/license.php
  8860. *******************************************************************************/
  8861. KindEditor.plugin('plainpaste', function (K) {
  8862. var self = this, name = 'plainpaste';
  8863. self.clickToolbar(name, function () {
  8864. var lang = self.lang(name + '.'),
  8865. html = '<div style="padding:10px 20px;">' +
  8866. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  8867. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  8868. '</div>',
  8869. dialog = self.createDialog({
  8870. name: name,
  8871. width: 450,
  8872. title: self.lang(name),
  8873. body: html,
  8874. yesBtn: {
  8875. name: self.lang('yes'),
  8876. click: function (e) {
  8877. var html = textarea.val();
  8878. html = K.escape(html);
  8879. html = html.replace(/ {2}/g, ' &nbsp;');
  8880. if (self.newlineTag == 'p') {
  8881. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  8882. } else {
  8883. html = html.replace(/\n/g, '<br />$&');
  8884. }
  8885. self.insertHtml(html).hideDialog().focus();
  8886. }
  8887. }
  8888. }),
  8889. textarea = K('textarea', dialog.div);
  8890. textarea[0].focus();
  8891. });
  8892. });
  8893. /*******************************************************************************
  8894. * KindEditor - WYSIWYG HTML Editor for Internet
  8895. * Copyright (C) 2006-2011 kindeditor.net
  8896. *
  8897. * @author Roddy <luolonghao@gmail.com>
  8898. * @site http://www.kindeditor.net/
  8899. * @licence http://www.kindeditor.net/license.php
  8900. *******************************************************************************/
  8901. KindEditor.plugin('preview', function (K) {
  8902. var self = this, name = 'preview', undefined;
  8903. self.clickToolbar(name, function () {
  8904. var lang = self.lang(name + '.'),
  8905. html = '<div style="padding:10px 20px;">' +
  8906. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  8907. '</div>',
  8908. dialog = self.createDialog({
  8909. name: name,
  8910. width: 750,
  8911. title: self.lang(name),
  8912. body: html
  8913. }),
  8914. iframe = K('iframe', dialog.div),
  8915. doc = K.iframeDoc(iframe);
  8916. doc.open();
  8917. doc.write(self.fullHtml());
  8918. doc.close();
  8919. K(doc.body).css('background-color', '#FFF');
  8920. iframe[0].contentWindow.focus();
  8921. });
  8922. });
  8923. /*******************************************************************************
  8924. * KindEditor - WYSIWYG HTML Editor for Internet
  8925. * Copyright (C) 2006-2011 kindeditor.net
  8926. *
  8927. * @author Roddy <luolonghao@gmail.com>
  8928. * @site http://www.kindeditor.net/
  8929. * @licence http://www.kindeditor.net/license.php
  8930. *******************************************************************************/
  8931. KindEditor.plugin('quickformat', function (K) {
  8932. var self = this, name = 'quickformat',
  8933. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  8934. function getFirstChild(knode) {
  8935. var child = knode.first();
  8936. while (child && child.first()) {
  8937. child = child.first();
  8938. }
  8939. return child;
  8940. }
  8941. self.clickToolbar(name, function () {
  8942. self.focus();
  8943. var doc = self.edit.doc,
  8944. range = self.cmd.range,
  8945. child = K(doc.body).first(), next,
  8946. nodeList = [], subList = [],
  8947. bookmark = range.createBookmark(true);
  8948. while (child) {
  8949. next = child.next();
  8950. var firstChild = getFirstChild(child);
  8951. if (!firstChild || firstChild.name != 'img') {
  8952. if (blockMap[child.name]) {
  8953. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  8954. child.css('text-indent', '2em');
  8955. } else {
  8956. subList.push(child);
  8957. }
  8958. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  8959. if (subList.length > 0) {
  8960. nodeList.push(subList);
  8961. }
  8962. subList = [];
  8963. }
  8964. }
  8965. child = next;
  8966. }
  8967. K.each(nodeList, function (i, subList) {
  8968. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  8969. subList[0].before(wrapper);
  8970. K.each(subList, function (i, knode) {
  8971. wrapper.append(knode);
  8972. });
  8973. });
  8974. range.moveToBookmark(bookmark);
  8975. self.addBookmark();
  8976. });
  8977. });
  8978. /*******************************************************************************
  8979. * KindEditor - WYSIWYG HTML Editor for Internet
  8980. * Copyright (C) 2006-2011 kindeditor.net
  8981. *
  8982. * @author Roddy <luolonghao@gmail.com>
  8983. * @site http://www.kindeditor.net/
  8984. * @licence http://www.kindeditor.net/license.php
  8985. *******************************************************************************/
  8986. KindEditor.plugin('table', function (K) {
  8987. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  8988. function _setColor(box, color) {
  8989. color = color.toUpperCase();
  8990. box.css('background-color', color);
  8991. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  8992. box.html(color);
  8993. }
  8994. var pickerList = [];
  8995. function _initColorPicker(dialogDiv, colorBox) {
  8996. colorBox.bind('click,mousedown', function (e) {
  8997. e.stopPropagation();
  8998. });
  8999. function removePicker() {
  9000. K.each(pickerList, function () {
  9001. this.remove();
  9002. });
  9003. pickerList = [];
  9004. K(document).unbind('click,mousedown', removePicker);
  9005. dialogDiv.unbind('click,mousedown', removePicker);
  9006. }
  9007. colorBox.click(function (e) {
  9008. removePicker();
  9009. var box = K(this),
  9010. pos = box.pos();
  9011. var picker = K.colorpicker({
  9012. x: pos.x,
  9013. y: pos.y + box.height(),
  9014. z: 811214,
  9015. selectedColor: K(this).html(),
  9016. colors: self.colorTable,
  9017. noColor: self.lang('noColor'),
  9018. shadowMode: self.shadowMode,
  9019. click: function (color) {
  9020. _setColor(box, color);
  9021. removePicker();
  9022. }
  9023. });
  9024. pickerList.push(picker);
  9025. K(document).bind('click,mousedown', removePicker);
  9026. dialogDiv.bind('click,mousedown', removePicker);
  9027. });
  9028. }
  9029. function _getCellIndex(table, row, cell) {
  9030. var rowSpanCount = 0;
  9031. for (var i = 0, len = row.cells.length; i < len; i++) {
  9032. if (row.cells[i] == cell) {
  9033. break;
  9034. }
  9035. rowSpanCount += row.cells[i].rowSpan - 1;
  9036. }
  9037. return cell.cellIndex - rowSpanCount;
  9038. }
  9039. self.plugin.table = {
  9040. prop: function (isInsert) {
  9041. var html = [
  9042. '<div style="padding:20px;">',
  9043. '<div class="ke-dialog-row">',
  9044. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9045. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9046. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9047. '</div>',
  9048. '<div class="ke-dialog-row">',
  9049. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9050. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9051. '<select name="widthType">',
  9052. '<option value="%">' + lang.percent + '</option>',
  9053. '<option value="px">' + lang.px + '</option>',
  9054. '</select> &nbsp; ',
  9055. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9056. '<select name="heightType">',
  9057. '<option value="%">' + lang.percent + '</option>',
  9058. '<option value="px">' + lang.px + '</option>',
  9059. '</select>',
  9060. '</div>',
  9061. '<div class="ke-dialog-row">',
  9062. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9063. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9064. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9065. '</div>',
  9066. '<div class="ke-dialog-row">',
  9067. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9068. '<select id="keAlign" name="align">',
  9069. '<option value="">' + lang.alignDefault + '</option>',
  9070. '<option value="left">' + lang.alignLeft + '</option>',
  9071. '<option value="center">' + lang.alignCenter + '</option>',
  9072. '<option value="right">' + lang.alignRight + '</option>',
  9073. '</select>',
  9074. '</div>',
  9075. '<div class="ke-dialog-row">',
  9076. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9077. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9078. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9079. '</div>',
  9080. '<div class="ke-dialog-row">',
  9081. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9082. '<span class="ke-inline-block ke-input-color"></span>',
  9083. '</div>',
  9084. '</div>'
  9085. ].join('');
  9086. var bookmark = self.cmd.range.createBookmark();
  9087. var dialog = self.createDialog({
  9088. name: name,
  9089. width: 500,
  9090. title: self.lang(name),
  9091. body: html,
  9092. beforeRemove: function () {
  9093. colorBox.unbind();
  9094. },
  9095. yesBtn: {
  9096. name: self.lang('yes'),
  9097. click: function (e) {
  9098. var rows = rowsBox.val(),
  9099. cols = colsBox.val(),
  9100. width = widthBox.val(),
  9101. height = heightBox.val(),
  9102. widthType = widthTypeBox.val(),
  9103. heightType = heightTypeBox.val(),
  9104. padding = paddingBox.val(),
  9105. spacing = spacingBox.val(),
  9106. align = alignBox.val(),
  9107. border = borderBox.val(),
  9108. borderColor = K(colorBox[0]).html() || '',
  9109. bgColor = K(colorBox[1]).html() || '';
  9110. if (rows == 0 || !/^\d+$/.test(rows)) {
  9111. alert(self.lang('invalidRows'));
  9112. rowsBox[0].focus();
  9113. return;
  9114. }
  9115. if (cols == 0 || !/^\d+$/.test(cols)) {
  9116. alert(self.lang('invalidRows'));
  9117. colsBox[0].focus();
  9118. return;
  9119. }
  9120. if (!/^\d*$/.test(width)) {
  9121. alert(self.lang('invalidWidth'));
  9122. widthBox[0].focus();
  9123. return;
  9124. }
  9125. if (!/^\d*$/.test(height)) {
  9126. alert(self.lang('invalidHeight'));
  9127. heightBox[0].focus();
  9128. return;
  9129. }
  9130. if (!/^\d*$/.test(padding)) {
  9131. alert(self.lang('invalidPadding'));
  9132. paddingBox[0].focus();
  9133. return;
  9134. }
  9135. if (!/^\d*$/.test(spacing)) {
  9136. alert(self.lang('invalidSpacing'));
  9137. spacingBox[0].focus();
  9138. return;
  9139. }
  9140. if (!/^\d*$/.test(border)) {
  9141. alert(self.lang('invalidBorder'));
  9142. borderBox[0].focus();
  9143. return;
  9144. }
  9145. if (table) {
  9146. if (width !== '') {
  9147. table.width(width + widthType);
  9148. } else {
  9149. table.css('width', '');
  9150. }
  9151. if (table[0].width !== undefined) {
  9152. table.removeAttr('width');
  9153. }
  9154. if (height !== '') {
  9155. table.height(height + heightType);
  9156. } else {
  9157. table.css('height', '');
  9158. }
  9159. if (table[0].height !== undefined) {
  9160. table.removeAttr('height');
  9161. }
  9162. table.css('background-color', bgColor);
  9163. if (table[0].bgColor !== undefined) {
  9164. table.removeAttr('bgColor');
  9165. }
  9166. if (padding !== '') {
  9167. table[0].cellPadding = padding;
  9168. } else {
  9169. table.removeAttr('cellPadding');
  9170. }
  9171. if (spacing !== '') {
  9172. table[0].cellSpacing = spacing;
  9173. } else {
  9174. table.removeAttr('cellSpacing');
  9175. }
  9176. if (align !== '') {
  9177. table[0].align = align;
  9178. } else {
  9179. table.removeAttr('align');
  9180. }
  9181. if (border !== '') {
  9182. table.attr('border', border);
  9183. } else {
  9184. table.removeAttr('border');
  9185. }
  9186. if (border === '' || border === '0') {
  9187. table.addClass(zeroborder);
  9188. } else {
  9189. table.removeClass(zeroborder);
  9190. }
  9191. if (borderColor !== '') {
  9192. table.attr('borderColor', borderColor);
  9193. } else {
  9194. table.removeAttr('borderColor');
  9195. }
  9196. self.hideDialog().focus();
  9197. self.cmd.range.moveToBookmark(bookmark);
  9198. self.cmd.select();
  9199. self.addBookmark();
  9200. return;
  9201. }
  9202. var style = '';
  9203. if (width !== '') {
  9204. style += 'width:' + width + widthType + ';';
  9205. }
  9206. if (height !== '') {
  9207. style += 'height:' + height + heightType + ';';
  9208. }
  9209. if (bgColor !== '') {
  9210. style += 'background-color:' + bgColor + ';';
  9211. }
  9212. var html = '<table';
  9213. if (style !== '') {
  9214. html += ' style="' + style + '"';
  9215. }
  9216. if (padding !== '') {
  9217. html += ' cellpadding="' + padding + '"';
  9218. }
  9219. if (spacing !== '') {
  9220. html += ' cellspacing="' + spacing + '"';
  9221. }
  9222. if (align !== '') {
  9223. html += ' align="' + align + '"';
  9224. }
  9225. if (border !== '') {
  9226. html += ' border="' + border + '"';
  9227. }
  9228. if (border === '' || border === '0') {
  9229. html += ' class="' + zeroborder + '"';
  9230. }
  9231. if (borderColor !== '') {
  9232. html += ' bordercolor="' + borderColor + '"';
  9233. }
  9234. html += '>';
  9235. for (var i = 0; i < rows; i++) {
  9236. html += '<tr>';
  9237. for (var j = 0; j < cols; j++) {
  9238. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9239. }
  9240. html += '</tr>';
  9241. }
  9242. html += '</table>';
  9243. if (!K.IE) {
  9244. html += '<br />';
  9245. }
  9246. self.insertHtml(html);
  9247. self.select().hideDialog().focus();
  9248. self.addBookmark();
  9249. }
  9250. }
  9251. }),
  9252. div = dialog.div,
  9253. rowsBox = K('[name="rows"]', div).val(3),
  9254. colsBox = K('[name="cols"]', div).val(2),
  9255. widthBox = K('[name="width"]', div).val(100),
  9256. heightBox = K('[name="height"]', div),
  9257. widthTypeBox = K('[name="widthType"]', div),
  9258. heightTypeBox = K('[name="heightType"]', div),
  9259. paddingBox = K('[name="padding"]', div).val(2),
  9260. spacingBox = K('[name="spacing"]', div).val(0),
  9261. alignBox = K('[name="align"]', div),
  9262. borderBox = K('[name="border"]', div).val(1),
  9263. colorBox = K('.ke-input-color', div);
  9264. _initColorPicker(div, colorBox.eq(0));
  9265. _initColorPicker(div, colorBox.eq(1));
  9266. _setColor(colorBox.eq(0), '#000000');
  9267. _setColor(colorBox.eq(1), '');
  9268. rowsBox[0].focus();
  9269. rowsBox[0].select();
  9270. var table;
  9271. if (isInsert) {
  9272. return;
  9273. }
  9274. table = self.plugin.getSelectedTable();
  9275. if (table) {
  9276. rowsBox.val(table[0].rows.length);
  9277. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9278. rowsBox.attr('disabled', true);
  9279. colsBox.attr('disabled', true);
  9280. var match,
  9281. tableWidth = table[0].style.width || table[0].width,
  9282. tableHeight = table[0].style.height || table[0].height;
  9283. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9284. widthBox.val(match[1]);
  9285. widthTypeBox.val(match[2]);
  9286. } else {
  9287. widthBox.val('');
  9288. }
  9289. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9290. heightBox.val(match[1]);
  9291. heightTypeBox.val(match[2]);
  9292. }
  9293. paddingBox.val(table[0].cellPadding || '');
  9294. spacingBox.val(table[0].cellSpacing || '');
  9295. alignBox.val(table[0].align || '');
  9296. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9297. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9298. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9299. widthBox[0].focus();
  9300. widthBox[0].select();
  9301. }
  9302. },
  9303. cellprop: function () {
  9304. var html = [
  9305. '<div style="padding:20px;">',
  9306. '<div class="ke-dialog-row">',
  9307. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9308. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9309. '<select name="widthType">',
  9310. '<option value="%">' + lang.percent + '</option>',
  9311. '<option value="px">' + lang.px + '</option>',
  9312. '</select> &nbsp; ',
  9313. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9314. '<select name="heightType">',
  9315. '<option value="%">' + lang.percent + '</option>',
  9316. '<option value="px">' + lang.px + '</option>',
  9317. '</select>',
  9318. '</div>',
  9319. '<div class="ke-dialog-row">',
  9320. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9321. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9322. '<option value="">' + lang.alignDefault + '</option>',
  9323. '<option value="left">' + lang.alignLeft + '</option>',
  9324. '<option value="center">' + lang.alignCenter + '</option>',
  9325. '<option value="right">' + lang.alignRight + '</option>',
  9326. '</select> ',
  9327. lang.verticalAlign + ' <select name="verticalAlign">',
  9328. '<option value="">' + lang.alignDefault + '</option>',
  9329. '<option value="top">' + lang.alignTop + '</option>',
  9330. '<option value="middle">' + lang.alignMiddle + '</option>',
  9331. '<option value="bottom">' + lang.alignBottom + '</option>',
  9332. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9333. '</select>',
  9334. '</div>',
  9335. '<div class="ke-dialog-row">',
  9336. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9337. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9338. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9339. '</div>',
  9340. '<div class="ke-dialog-row">',
  9341. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9342. '<span class="ke-inline-block ke-input-color"></span>',
  9343. '</div>',
  9344. '</div>'
  9345. ].join('');
  9346. var bookmark = self.cmd.range.createBookmark();
  9347. var dialog = self.createDialog({
  9348. name: name,
  9349. width: 500,
  9350. title: self.lang('tablecell'),
  9351. body: html,
  9352. beforeRemove: function () {
  9353. colorBox.unbind();
  9354. },
  9355. yesBtn: {
  9356. name: self.lang('yes'),
  9357. click: function (e) {
  9358. var width = widthBox.val(),
  9359. height = heightBox.val(),
  9360. widthType = widthTypeBox.val(),
  9361. heightType = heightTypeBox.val(),
  9362. padding = paddingBox.val(),
  9363. spacing = spacingBox.val(),
  9364. textAlign = textAlignBox.val(),
  9365. verticalAlign = verticalAlignBox.val(),
  9366. border = borderBox.val(),
  9367. borderColor = K(colorBox[0]).html() || '',
  9368. bgColor = K(colorBox[1]).html() || '';
  9369. if (!/^\d*$/.test(width)) {
  9370. alert(self.lang('invalidWidth'));
  9371. widthBox[0].focus();
  9372. return;
  9373. }
  9374. if (!/^\d*$/.test(height)) {
  9375. alert(self.lang('invalidHeight'));
  9376. heightBox[0].focus();
  9377. return;
  9378. }
  9379. if (!/^\d*$/.test(border)) {
  9380. alert(self.lang('invalidBorder'));
  9381. borderBox[0].focus();
  9382. return;
  9383. }
  9384. cell.css({
  9385. width: width !== '' ? (width + widthType) : '',
  9386. height: height !== '' ? (height + heightType) : '',
  9387. 'background-color': bgColor,
  9388. 'text-align': textAlign,
  9389. 'vertical-align': verticalAlign,
  9390. 'border-width': border,
  9391. 'border-style': border !== '' ? 'solid' : '',
  9392. 'border-color': borderColor
  9393. });
  9394. self.hideDialog().focus();
  9395. self.cmd.range.moveToBookmark(bookmark);
  9396. self.cmd.select();
  9397. self.addBookmark();
  9398. }
  9399. }
  9400. }),
  9401. div = dialog.div,
  9402. widthBox = K('[name="width"]', div).val(100),
  9403. heightBox = K('[name="height"]', div),
  9404. widthTypeBox = K('[name="widthType"]', div),
  9405. heightTypeBox = K('[name="heightType"]', div),
  9406. paddingBox = K('[name="padding"]', div).val(2),
  9407. spacingBox = K('[name="spacing"]', div).val(0),
  9408. textAlignBox = K('[name="textAlign"]', div),
  9409. verticalAlignBox = K('[name="verticalAlign"]', div),
  9410. borderBox = K('[name="border"]', div).val(1),
  9411. colorBox = K('.ke-input-color', div);
  9412. _initColorPicker(div, colorBox.eq(0));
  9413. _initColorPicker(div, colorBox.eq(1));
  9414. _setColor(colorBox.eq(0), '#000000');
  9415. _setColor(colorBox.eq(1), '');
  9416. widthBox[0].focus();
  9417. widthBox[0].select();
  9418. var cell = self.plugin.getSelectedCell();
  9419. var match,
  9420. cellWidth = cell[0].style.width || cell[0].width || '',
  9421. cellHeight = cell[0].style.height || cell[0].height || '';
  9422. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9423. widthBox.val(match[1]);
  9424. widthTypeBox.val(match[2]);
  9425. } else {
  9426. widthBox.val('');
  9427. }
  9428. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9429. heightBox.val(match[1]);
  9430. heightTypeBox.val(match[2]);
  9431. }
  9432. textAlignBox.val(cell[0].style.textAlign || '');
  9433. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9434. var border = cell[0].style.borderWidth || '';
  9435. if (border) {
  9436. border = parseInt(border);
  9437. }
  9438. borderBox.val(border);
  9439. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9440. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9441. widthBox[0].focus();
  9442. widthBox[0].select();
  9443. },
  9444. insert: function () {
  9445. this.prop(true);
  9446. },
  9447. 'delete': function () {
  9448. var table = self.plugin.getSelectedTable();
  9449. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9450. self.cmd.select();
  9451. table.remove();
  9452. self.addBookmark();
  9453. },
  9454. colinsert: function (offset) {
  9455. var table = self.plugin.getSelectedTable()[0],
  9456. row = self.plugin.getSelectedRow()[0],
  9457. cell = self.plugin.getSelectedCell()[0],
  9458. index = cell.cellIndex + offset;
  9459. index += table.rows[0].cells.length - row.cells.length;
  9460. for (var i = 0, len = table.rows.length; i < len; i++) {
  9461. var newRow = table.rows[i],
  9462. newCell = newRow.insertCell(index);
  9463. newCell.innerHTML = K.IE ? '' : '<br />';
  9464. index = _getCellIndex(table, newRow, newCell);
  9465. }
  9466. self.cmd.range.selectNodeContents(cell).collapse(true);
  9467. self.cmd.select();
  9468. self.addBookmark();
  9469. },
  9470. colinsertleft: function () {
  9471. this.colinsert(0);
  9472. },
  9473. colinsertright: function () {
  9474. this.colinsert(1);
  9475. },
  9476. rowinsert: function (offset) {
  9477. var table = self.plugin.getSelectedTable()[0],
  9478. row = self.plugin.getSelectedRow()[0],
  9479. cell = self.plugin.getSelectedCell()[0];
  9480. var rowIndex = row.rowIndex;
  9481. if (offset === 1) {
  9482. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9483. }
  9484. var newRow = table.insertRow(rowIndex);
  9485. for (var i = 0, len = row.cells.length; i < len; i++) {
  9486. if (row.cells[i].rowSpan > 1) {
  9487. len -= row.cells[i].rowSpan - 1;
  9488. }
  9489. var newCell = newRow.insertCell(i);
  9490. if (offset === 1 && row.cells[i].colSpan > 1) {
  9491. newCell.colSpan = row.cells[i].colSpan;
  9492. }
  9493. newCell.innerHTML = K.IE ? '' : '<br />';
  9494. }
  9495. for (var j = rowIndex; j >= 0; j--) {
  9496. var cells = table.rows[j].cells;
  9497. if (cells.length > i) {
  9498. for (var k = cell.cellIndex; k >= 0; k--) {
  9499. if (cells[k].rowSpan > 1) {
  9500. cells[k].rowSpan += 1;
  9501. }
  9502. }
  9503. break;
  9504. }
  9505. }
  9506. self.cmd.range.selectNodeContents(cell).collapse(true);
  9507. self.cmd.select();
  9508. self.addBookmark();
  9509. },
  9510. rowinsertabove: function () {
  9511. this.rowinsert(0);
  9512. },
  9513. rowinsertbelow: function () {
  9514. this.rowinsert(1);
  9515. },
  9516. rowmerge: function () {
  9517. var table = self.plugin.getSelectedTable()[0],
  9518. row = self.plugin.getSelectedRow()[0],
  9519. cell = self.plugin.getSelectedCell()[0],
  9520. rowIndex = row.rowIndex,
  9521. nextRowIndex = rowIndex + cell.rowSpan,
  9522. nextRow = table.rows[nextRowIndex];
  9523. if (table.rows.length <= nextRowIndex) {
  9524. return;
  9525. }
  9526. var cellIndex = cell.cellIndex;
  9527. if (nextRow.cells.length <= cellIndex) {
  9528. return;
  9529. }
  9530. var nextCell = nextRow.cells[cellIndex];
  9531. if (cell.colSpan !== nextCell.colSpan) {
  9532. return;
  9533. }
  9534. cell.rowSpan += nextCell.rowSpan;
  9535. nextRow.deleteCell(cellIndex);
  9536. self.cmd.range.selectNodeContents(cell).collapse(true);
  9537. self.cmd.select();
  9538. self.addBookmark();
  9539. },
  9540. colmerge: function () {
  9541. var table = self.plugin.getSelectedTable()[0],
  9542. row = self.plugin.getSelectedRow()[0],
  9543. cell = self.plugin.getSelectedCell()[0],
  9544. rowIndex = row.rowIndex,
  9545. cellIndex = cell.cellIndex,
  9546. nextCellIndex = cellIndex + 1;
  9547. if (row.cells.length <= nextCellIndex) {
  9548. return;
  9549. }
  9550. var nextCell = row.cells[nextCellIndex];
  9551. if (cell.rowSpan !== nextCell.rowSpan) {
  9552. return;
  9553. }
  9554. cell.colSpan += nextCell.colSpan;
  9555. row.deleteCell(nextCellIndex);
  9556. self.cmd.range.selectNodeContents(cell).collapse(true);
  9557. self.cmd.select();
  9558. self.addBookmark();
  9559. },
  9560. rowsplit: function () {
  9561. var table = self.plugin.getSelectedTable()[0],
  9562. row = self.plugin.getSelectedRow()[0],
  9563. cell = self.plugin.getSelectedCell()[0],
  9564. rowIndex = row.rowIndex;
  9565. if (cell.rowSpan === 1) {
  9566. return;
  9567. }
  9568. var cellIndex = _getCellIndex(table, row, cell);
  9569. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9570. var newRow = table.rows[rowIndex + i],
  9571. newCell = newRow.insertCell(cellIndex);
  9572. if (cell.colSpan > 1) {
  9573. newCell.colSpan = cell.colSpan;
  9574. }
  9575. newCell.innerHTML = K.IE ? '' : '<br />';
  9576. cellIndex = _getCellIndex(table, newRow, newCell);
  9577. }
  9578. K(cell).removeAttr('rowSpan');
  9579. self.cmd.range.selectNodeContents(cell).collapse(true);
  9580. self.cmd.select();
  9581. self.addBookmark();
  9582. },
  9583. colsplit: function () {
  9584. var table = self.plugin.getSelectedTable()[0],
  9585. row = self.plugin.getSelectedRow()[0],
  9586. cell = self.plugin.getSelectedCell()[0],
  9587. cellIndex = cell.cellIndex;
  9588. if (cell.colSpan === 1) {
  9589. return;
  9590. }
  9591. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9592. var newCell = row.insertCell(cellIndex + i);
  9593. if (cell.rowSpan > 1) {
  9594. newCell.rowSpan = cell.rowSpan;
  9595. }
  9596. newCell.innerHTML = K.IE ? '' : '<br />';
  9597. }
  9598. K(cell).removeAttr('colSpan');
  9599. self.cmd.range.selectNodeContents(cell).collapse(true);
  9600. self.cmd.select();
  9601. self.addBookmark();
  9602. },
  9603. coldelete: function () {
  9604. var table = self.plugin.getSelectedTable()[0],
  9605. row = self.plugin.getSelectedRow()[0],
  9606. cell = self.plugin.getSelectedCell()[0],
  9607. index = cell.cellIndex;
  9608. for (var i = 0, len = table.rows.length; i < len; i++) {
  9609. var newRow = table.rows[i],
  9610. newCell = newRow.cells[index];
  9611. if (newCell.colSpan > 1) {
  9612. newCell.colSpan -= 1;
  9613. if (newCell.colSpan === 1) {
  9614. K(newCell).removeAttr('colSpan');
  9615. }
  9616. } else {
  9617. newRow.deleteCell(index);
  9618. }
  9619. if (newCell.rowSpan > 1) {
  9620. i += newCell.rowSpan - 1;
  9621. }
  9622. }
  9623. if (row.cells.length === 0) {
  9624. self.cmd.range.setStartBefore(table).collapse(true);
  9625. self.cmd.select();
  9626. K(table).remove();
  9627. } else {
  9628. self.cmd.selection(true);
  9629. }
  9630. self.addBookmark();
  9631. },
  9632. rowdelete: function () {
  9633. var table = self.plugin.getSelectedTable()[0],
  9634. row = self.plugin.getSelectedRow()[0],
  9635. cell = self.plugin.getSelectedCell()[0],
  9636. rowIndex = row.rowIndex;
  9637. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9638. table.deleteRow(rowIndex + i);
  9639. }
  9640. if (table.rows.length === 0) {
  9641. self.cmd.range.setStartBefore(table).collapse(true);
  9642. self.cmd.select();
  9643. K(table).remove();
  9644. } else {
  9645. self.cmd.selection(true);
  9646. }
  9647. self.addBookmark();
  9648. }
  9649. };
  9650. self.clickToolbar(name, self.plugin.table.prop);
  9651. });
  9652. /*******************************************************************************
  9653. * KindEditor - WYSIWYG HTML Editor for Internet
  9654. * Copyright (C) 2006-2011 kindeditor.net
  9655. *
  9656. * @author Roddy <luolonghao@gmail.com>
  9657. * @site http://www.kindeditor.net/
  9658. * @licence http://www.kindeditor.net/license.php
  9659. *******************************************************************************/
  9660. KindEditor.plugin('template', function (K) {
  9661. var self = this, name = 'template', lang = self.lang(name + '.'),
  9662. htmlPath = self.pluginsPath + name + '/html/';
  9663. function getFilePath(fileName) {
  9664. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9665. }
  9666. self.clickToolbar(name, function () {
  9667. var lang = self.lang(name + '.'),
  9668. arr = ['<div style="padding:10px 20px;">',
  9669. '<div class="ke-header">',
  9670. '<div class="ke-left">',
  9671. lang.selectTemplate + ' <select>'];
  9672. K.each(lang.fileList, function (key, val) {
  9673. arr.push('<option value="' + key + '">' + val + '</option>');
  9674. });
  9675. html = [arr.join(''),
  9676. '</select></div>',
  9677. '<div class="ke-right">',
  9678. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9679. '</div>',
  9680. '<div class="ke-clearfix"></div>',
  9681. '</div>',
  9682. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9683. '</div>'].join('');
  9684. var dialog = self.createDialog({
  9685. name: name,
  9686. width: 500,
  9687. title: self.lang(name),
  9688. body: html,
  9689. yesBtn: {
  9690. name: self.lang('yes'),
  9691. click: function (e) {
  9692. var doc = K.iframeDoc(iframe);
  9693. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9694. }
  9695. }
  9696. });
  9697. var selectBox = K('select', dialog.div),
  9698. checkbox = K('[name="replaceFlag"]', dialog.div),
  9699. iframe = K('iframe', dialog.div);
  9700. checkbox[0].checked = true;
  9701. iframe.attr('src', getFilePath(selectBox.val()));
  9702. selectBox.change(function () {
  9703. iframe.attr('src', getFilePath(this.value));
  9704. });
  9705. });
  9706. });
  9707. /*******************************************************************************
  9708. * KindEditor - WYSIWYG HTML Editor for Internet
  9709. * Copyright (C) 2006-2011 kindeditor.net
  9710. *
  9711. * @author Roddy <luolonghao@gmail.com>
  9712. * @site http://www.kindeditor.net/
  9713. * @licence http://www.kindeditor.net/license.php
  9714. *******************************************************************************/
  9715. KindEditor.plugin('wordpaste', function (K) {
  9716. var self = this, name = 'wordpaste';
  9717. self.clickToolbar(name, function () {
  9718. var lang = self.lang(name + '.'),
  9719. html = '<div style="padding:10px 20px;">' +
  9720. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9721. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9722. '</div>',
  9723. dialog = self.createDialog({
  9724. name: name,
  9725. width: 450,
  9726. title: self.lang(name),
  9727. body: html,
  9728. yesBtn: {
  9729. name: self.lang('yes'),
  9730. click: function (e) {
  9731. var str = doc.body.innerHTML;
  9732. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9733. self.insertHtml(str).hideDialog().focus();
  9734. }
  9735. }
  9736. }),
  9737. div = dialog.div,
  9738. iframe = K('iframe', div),
  9739. doc = K.iframeDoc(iframe);
  9740. if (!K.IE) {
  9741. doc.designMode = 'on';
  9742. }
  9743. doc.open();
  9744. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9745. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9746. if (!K.IE) {
  9747. doc.write('<br />');
  9748. }
  9749. doc.write('</body></html>');
  9750. doc.close();
  9751. if (K.IE) {
  9752. doc.body.contentEditable = 'true';
  9753. }
  9754. iframe[0].contentWindow.focus();
  9755. });
  9756. });
  9757. KindEditor.plugin('fixtoolbar', function (K) {
  9758. var self = this;
  9759. if (!self.fixToolBar) {
  9760. return;
  9761. }
  9762. function init() {
  9763. var toolbar = K('.ke-toolbar');
  9764. var originY = toolbar.pos().y;
  9765. K(window).bind('scroll', function () {
  9766. if (toolbar.css('position') == 'fixed') {
  9767. if (document.body.scrollTop - originY < 0) {
  9768. toolbar.css('position', 'static');
  9769. toolbar.css('top', 'auto');
  9770. }
  9771. } else {
  9772. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9773. toolbar.css('position', 'fixed');
  9774. toolbar.css('top', 0);
  9775. }
  9776. }
  9777. });
  9778. }
  9779. if (self.isCreated) {
  9780. init();
  9781. } else {
  9782. self.afterCreate(init);
  9783. }
  9784. });