kindeditor-all.js 298 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2017 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.12 (2017-04-12)
  9. *******************************************************************************/
  10. (function (window, undefined) {
  11. if (window.KindEditor) {
  12. return;
  13. }
  14. if (!window.console) {
  15. window.console = {};
  16. }
  17. if (!console.log) {
  18. console.log = function () {};
  19. }
  20. var _VERSION = '4.1.12 (2017-04-12)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  24. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  25. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  26. _OPERA = _ua.indexOf('opera') > -1,
  27. _MOBILE = _ua.indexOf('mobile') > -1,
  28. _IOS = /ipad|iphone|ipod/.test(_ua),
  29. _QUIRKS = document.compatMode != 'CSS1Compat',
  30. _IERANGE = !window.getSelection,
  31. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  32. _V = _matches ? _matches[1] : '0',
  33. _TIME = new Date().getTime();
  34. function _isArray(val) {
  35. if (!val) {
  36. return false;
  37. }
  38. return Object.prototype.toString.call(val) === '[object Array]';
  39. }
  40. function _isFunction(val) {
  41. if (!val) {
  42. return false;
  43. }
  44. return Object.prototype.toString.call(val) === '[object Function]';
  45. }
  46. function _inArray(val, arr) {
  47. for (var i = 0, len = arr.length; i < len; i++) {
  48. if (val === arr[i]) {
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. function _each(obj, fn) {
  55. if (_isArray(obj)) {
  56. for (var i = 0, len = obj.length; i < len; i++) {
  57. if (fn.call(obj[i], i, obj[i]) === false) {
  58. break;
  59. }
  60. }
  61. } else {
  62. for (var key in obj) {
  63. if (obj.hasOwnProperty(key)) {
  64. if (fn.call(obj[key], key, obj[key]) === false) {
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. function _trim(str) {
  72. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  73. }
  74. function _inString(val, str, delimiter) {
  75. delimiter = delimiter === undefined ? ',' : delimiter;
  76. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  77. }
  78. function _addUnit(val, unit) {
  79. unit = unit || 'px';
  80. return val && /^-?\d+(?:\.\d+)?$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function(key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function(key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () {};
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function(key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG : false,
  180. VERSION : _VERSION,
  181. IE : _IE,
  182. GECKO : _GECKO,
  183. WEBKIT : _WEBKIT,
  184. OPERA : _OPERA,
  185. V : _V,
  186. TIME : _TIME,
  187. each : _each,
  188. isArray : _isArray,
  189. isFunction : _isFunction,
  190. inArray : _inArray,
  191. inString : _inString,
  192. trim : _trim,
  193. addUnit : _addUnit,
  194. removeUnit : _removeUnit,
  195. escape : _escape,
  196. unescape : _unescape,
  197. toCamel : _toCamel,
  198. toHex : _toHex,
  199. toMap : _toMap,
  200. toArray : _toArray,
  201. undef : _undef,
  202. invalidUrl : _invalidUrl,
  203. addParam : _addParam,
  204. extend : _extend,
  205. json : _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. designMode : true,
  230. fullscreenMode : false,
  231. filterMode : true,
  232. wellFormatMode : true,
  233. shadowMode : true,
  234. loadStyleMode : true,
  235. basePath : K.basePath,
  236. themesPath : K.basePath + 'themes/',
  237. langPath : K.basePath + 'lang/',
  238. pluginsPath : K.basePath + 'plugins/',
  239. themeType : 'default',
  240. langType : 'zh-CN',
  241. urlType : '',
  242. newlineTag : 'p',
  243. resizeType : 2,
  244. syncType : 'form',
  245. pasteType : 2,
  246. dialogAlignType : 'page',
  247. useContextmenu : true,
  248. fullscreenShortcut : false,
  249. bodyClass : 'ke-content',
  250. indentChar : '\t',
  251. cssPath : '',
  252. cssData : '',
  253. minWidth : 650,
  254. minHeight : 100,
  255. minChangeSize : 50,
  256. zIndex : 811213,
  257. items : [
  258. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  259. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  260. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  261. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  262. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  263. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  264. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  265. 'anchor', 'link', 'unlink', '|', 'about'
  266. ],
  267. noDisableItems : ['source', 'fullscreen'],
  268. colorTable : [
  269. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  270. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  271. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  272. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  273. ],
  274. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  275. htmlTags : {
  276. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  277. span : [
  278. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  279. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  280. ],
  281. div : [
  282. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  283. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  284. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  285. ],
  286. table: [
  287. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  288. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  289. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  290. '.width', '.height', '.border-collapse'
  291. ],
  292. 'td,th': [
  293. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  294. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  295. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  296. ],
  297. a : ['id', 'class', 'href', 'target', 'name'],
  298. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  299. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  300. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  301. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  302. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  303. ],
  304. pre : ['id', 'class'],
  305. hr : ['id', 'class', '.page-break-after'],
  306. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  307. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  308. },
  309. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  310. };
  311. var _useCapture = false;
  312. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  313. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  314. var _CHANGE_KEY_MAP = {};
  315. _each(_INPUT_KEY_MAP, function(key, val) {
  316. _CHANGE_KEY_MAP[key] = val;
  317. });
  318. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  319. _CHANGE_KEY_MAP[key] = val;
  320. });
  321. function _bindEvent(el, type, fn) {
  322. if (el.addEventListener){
  323. el.addEventListener(type, fn, _useCapture);
  324. } else if (el.attachEvent){
  325. el.attachEvent('on' + type, fn);
  326. }
  327. }
  328. function _unbindEvent(el, type, fn) {
  329. if (el.removeEventListener){
  330. el.removeEventListener(type, fn, _useCapture);
  331. } else if (el.detachEvent){
  332. el.detachEvent('on' + type, fn);
  333. }
  334. }
  335. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  336. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  337. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  338. function KEvent(el, event) {
  339. this.init(el, event);
  340. }
  341. _extend(KEvent, {
  342. init : function(el, event) {
  343. var self = this, doc = el.ownerDocument || el.document || el;
  344. self.event = event;
  345. _each(_EVENT_PROPS, function(key, val) {
  346. self[val] = event[val];
  347. });
  348. if (!self.target) {
  349. self.target = self.srcElement || doc;
  350. }
  351. if (self.target.nodeType === 3) {
  352. self.target = self.target.parentNode;
  353. }
  354. if (!self.relatedTarget && self.fromElement) {
  355. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  356. }
  357. if (self.pageX == null && self.clientX != null) {
  358. var d = doc.documentElement, body = doc.body;
  359. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  360. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  361. }
  362. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  363. self.which = self.charCode || self.keyCode;
  364. }
  365. if (!self.metaKey && self.ctrlKey) {
  366. self.metaKey = self.ctrlKey;
  367. }
  368. if (!self.which && self.button !== undefined) {
  369. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  370. }
  371. switch (self.which) {
  372. case 186 :
  373. self.which = 59;
  374. break;
  375. case 187 :
  376. case 107 :
  377. case 43 :
  378. self.which = 61;
  379. break;
  380. case 189 :
  381. case 45 :
  382. self.which = 109;
  383. break;
  384. case 42 :
  385. self.which = 106;
  386. break;
  387. case 47 :
  388. self.which = 111;
  389. break;
  390. case 78 :
  391. self.which = 110;
  392. break;
  393. }
  394. if (self.which >= 96 && self.which <= 105) {
  395. self.which -= 48;
  396. }
  397. },
  398. preventDefault : function() {
  399. var ev = this.event;
  400. if (ev.preventDefault) {
  401. ev.preventDefault();
  402. } else {
  403. ev.returnValue = false;
  404. }
  405. },
  406. stopPropagation : function() {
  407. var ev = this.event;
  408. if (ev.stopPropagation) {
  409. ev.stopPropagation();
  410. } else {
  411. ev.cancelBubble = true;
  412. }
  413. },
  414. stop : function() {
  415. this.preventDefault();
  416. this.stopPropagation();
  417. }
  418. });
  419. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  420. function _getId(el) {
  421. return el[_eventExpendo] || null;
  422. }
  423. function _setId(el) {
  424. el[_eventExpendo] = ++_eventId;
  425. return _eventId;
  426. }
  427. function _removeId(el) {
  428. try {
  429. delete el[_eventExpendo];
  430. } catch(e) {
  431. if (el.removeAttribute) {
  432. el.removeAttribute(_eventExpendo);
  433. }
  434. }
  435. }
  436. function _bind(el, type, fn) {
  437. if (type.indexOf(',') >= 0) {
  438. _each(type.split(','), function() {
  439. _bind(el, this, fn);
  440. });
  441. return;
  442. }
  443. var id = _getId(el);
  444. if (!id) {
  445. id = _setId(el);
  446. }
  447. if (_eventData[id] === undefined) {
  448. _eventData[id] = {};
  449. }
  450. var events = _eventData[id][type];
  451. if (events && events.length > 0) {
  452. _unbindEvent(el, type, events[0]);
  453. } else {
  454. _eventData[id][type] = [];
  455. _eventData[id].el = el;
  456. }
  457. events = _eventData[id][type];
  458. if (events.length === 0) {
  459. events[0] = function(e) {
  460. var kevent = e ? new KEvent(el, e) : undefined;
  461. _each(events, function(i, event) {
  462. if (i > 0 && event) {
  463. event.call(el, kevent);
  464. }
  465. });
  466. };
  467. }
  468. if (_inArray(fn, events) < 0) {
  469. events.push(fn);
  470. }
  471. _bindEvent(el, type, events[0]);
  472. }
  473. function _unbind(el, type, fn) {
  474. if (type && type.indexOf(',') >= 0) {
  475. _each(type.split(','), function() {
  476. _unbind(el, this, fn);
  477. });
  478. return;
  479. }
  480. var id = _getId(el);
  481. if (!id) {
  482. return;
  483. }
  484. if (type === undefined) {
  485. if (id in _eventData) {
  486. _each(_eventData[id], function(key, events) {
  487. if (key != 'el' && events.length > 0) {
  488. _unbindEvent(el, key, events[0]);
  489. }
  490. });
  491. delete _eventData[id];
  492. _removeId(el);
  493. }
  494. return;
  495. }
  496. if (!_eventData[id]) {
  497. return;
  498. }
  499. var events = _eventData[id][type];
  500. if (events && events.length > 0) {
  501. if (fn === undefined) {
  502. _unbindEvent(el, type, events[0]);
  503. delete _eventData[id][type];
  504. } else {
  505. _each(events, function(i, event) {
  506. if (i > 0 && event === fn) {
  507. events.splice(i, 1);
  508. }
  509. });
  510. if (events.length == 1) {
  511. _unbindEvent(el, type, events[0]);
  512. delete _eventData[id][type];
  513. }
  514. }
  515. var count = 0;
  516. _each(_eventData[id], function() {
  517. count++;
  518. });
  519. if (count < 2) {
  520. delete _eventData[id];
  521. _removeId(el);
  522. }
  523. }
  524. }
  525. function _fire(el, type) {
  526. if (type.indexOf(',') >= 0) {
  527. _each(type.split(','), function() {
  528. _fire(el, this);
  529. });
  530. return;
  531. }
  532. var id = _getId(el);
  533. if (!id) {
  534. return;
  535. }
  536. var events = _eventData[id][type];
  537. if (_eventData[id] && events && events.length > 0) {
  538. events[0]();
  539. }
  540. }
  541. function _ctrl(el, key, fn) {
  542. var self = this;
  543. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  544. _bind(el, 'keydown', function(e) {
  545. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  546. fn.call(el);
  547. e.stop();
  548. }
  549. });
  550. }
  551. var _readyFinished = false;
  552. function _ready(fn) {
  553. if (_readyFinished) {
  554. fn(KindEditor);
  555. return;
  556. }
  557. var loaded = false;
  558. function readyFunc() {
  559. if (!loaded) {
  560. loaded = true;
  561. fn(KindEditor);
  562. _readyFinished = true;
  563. }
  564. }
  565. function ieReadyFunc() {
  566. if (!loaded) {
  567. try {
  568. document.documentElement.doScroll('left');
  569. } catch(e) {
  570. setTimeout(ieReadyFunc, 100);
  571. return;
  572. }
  573. readyFunc();
  574. }
  575. }
  576. function ieReadyStateFunc() {
  577. if (document.readyState === 'complete') {
  578. readyFunc();
  579. }
  580. }
  581. if (document.addEventListener) {
  582. _bind(document, 'DOMContentLoaded', readyFunc);
  583. } else if (document.attachEvent) {
  584. _bind(document, 'readystatechange', ieReadyStateFunc);
  585. var toplevel = false;
  586. try {
  587. toplevel = window.frameElement == null;
  588. } catch(e) {}
  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. css = css.replace(/&quot;/g, '"');
  608. var list = {},
  609. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  610. match;
  611. while ((match = reg.exec(css))) {
  612. var key = _trim(match[1].toLowerCase()),
  613. val = _trim(_toHex(match[2]));
  614. list[key] = val;
  615. }
  616. return list;
  617. }
  618. function _getAttrList(tag) {
  619. var list = {},
  620. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  621. match;
  622. while ((match = reg.exec(tag))) {
  623. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  624. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  625. list[key] = val;
  626. }
  627. return list;
  628. }
  629. function _addClassToTag(tag, className) {
  630. if (/\s+class\s*=/.test(tag)) {
  631. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  632. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  633. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  634. } else {
  635. return $0;
  636. }
  637. });
  638. } else {
  639. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  640. }
  641. return tag;
  642. }
  643. function _formatCss(css) {
  644. var str = '';
  645. _each(_getCssList(css), function(key, val) {
  646. str += key + ':' + val + ';';
  647. });
  648. return str;
  649. }
  650. function _formatUrl(url, mode, host, pathname) {
  651. mode = _undef(mode, '').toLowerCase();
  652. if (url.substr(0, 5) != 'data:') {
  653. url = url.replace(/([^:])\/\//g, '$1/');
  654. }
  655. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  656. return url;
  657. }
  658. host = host || location.protocol + '//' + location.host;
  659. if (pathname === undefined) {
  660. var m = location.pathname.match(/^(\/.*)\//);
  661. pathname = m ? m[1] : '';
  662. }
  663. var match;
  664. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  665. if (match[1] !== host) {
  666. return url;
  667. }
  668. } else if (/^\w+:/.test(url)) {
  669. return url;
  670. }
  671. function getRealPath(path) {
  672. var parts = path.split('/'), paths = [];
  673. for (var i = 0, len = parts.length; i < len; i++) {
  674. var part = parts[i];
  675. if (part == '..') {
  676. if (paths.length > 0) {
  677. paths.pop();
  678. }
  679. } else if (part !== '' && part != '.') {
  680. paths.push(part);
  681. }
  682. }
  683. return '/' + paths.join('/');
  684. }
  685. if (/^\//.test(url)) {
  686. url = host + getRealPath(url.substr(1));
  687. } else if (!/^\w+:\/\//.test(url)) {
  688. url = host + getRealPath(pathname + '/' + url);
  689. }
  690. function getRelativePath(path, depth) {
  691. if (url.substr(0, path.length) === path) {
  692. var arr = [];
  693. for (var i = 0; i < depth; i++) {
  694. arr.push('..');
  695. }
  696. var prefix = '.';
  697. if (arr.length > 0) {
  698. prefix += '/' + arr.join('/');
  699. }
  700. if (pathname == '/') {
  701. prefix += '/';
  702. }
  703. return prefix + url.substr(path.length);
  704. } else {
  705. if ((match = /^(.*)\//.exec(path))) {
  706. return getRelativePath(match[1], ++depth);
  707. }
  708. }
  709. }
  710. if (mode === 'relative') {
  711. url = getRelativePath(host + pathname, 0).substr(2);
  712. } else if (mode === 'absolute') {
  713. if (url.substr(0, host.length) === host) {
  714. url = url.substr(host.length);
  715. }
  716. }
  717. return url;
  718. }
  719. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  720. if (html == null) {
  721. html = '';
  722. }
  723. urlType = urlType || '';
  724. wellFormatted = _undef(wellFormatted, false);
  725. indentChar = _undef(indentChar, '\t');
  726. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  727. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  728. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  729. });
  730. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  731. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  732. html = html.replace(/\u200B/g, '');
  733. html = html.replace(/\u00A9/g, '&copy;');
  734. html = html.replace(/\u00AE/g, '&reg;');
  735. html = html.replace(/\u2003/g, '&emsp;');
  736. html = html.replace(/\u3000/g, '&emsp;');
  737. html = html.replace(/<[^>]+/g, function($0) {
  738. return $0.replace(/\s+/g, ' ');
  739. });
  740. var htmlTagMap = {};
  741. if (htmlTags) {
  742. _each(htmlTags, function(key, val) {
  743. var arr = key.split(',');
  744. for (var i = 0, len = arr.length; i < len; i++) {
  745. htmlTagMap[arr[i]] = _toMap(val);
  746. }
  747. });
  748. if (!htmlTagMap.script) {
  749. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  750. }
  751. if (!htmlTagMap.style) {
  752. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  753. }
  754. }
  755. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  756. var tagStack = [];
  757. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  758. var full = $0,
  759. startNewline = $1 || '',
  760. startSlash = $2 || '',
  761. tagName = $3.toLowerCase(),
  762. attr = $4 || '',
  763. endSlash = $5 ? ' ' + $5 : '',
  764. endNewline = $6 || '';
  765. if (htmlTags && !htmlTagMap[tagName]) {
  766. return '';
  767. }
  768. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  769. endSlash = ' /';
  770. }
  771. if (_INLINE_TAG_MAP[tagName]) {
  772. if (startNewline) {
  773. startNewline = ' ';
  774. }
  775. if (endNewline) {
  776. endNewline = ' ';
  777. }
  778. }
  779. if (_PRE_TAG_MAP[tagName]) {
  780. if (startSlash) {
  781. endNewline = '\n';
  782. } else {
  783. startNewline = '\n';
  784. }
  785. }
  786. if (wellFormatted && tagName == 'br') {
  787. endNewline = '\n';
  788. }
  789. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  790. if (wellFormatted) {
  791. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  792. tagStack.pop();
  793. } else {
  794. tagStack.push(tagName);
  795. }
  796. startNewline = '\n';
  797. endNewline = '\n';
  798. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  799. startNewline += indentChar;
  800. if (!startSlash) {
  801. endNewline += indentChar;
  802. }
  803. }
  804. if (endSlash) {
  805. tagStack.pop();
  806. } else if (!startSlash) {
  807. endNewline += indentChar;
  808. }
  809. } else {
  810. startNewline = endNewline = '';
  811. }
  812. }
  813. if (attr !== '') {
  814. var attrMap = _getAttrList(full);
  815. if (tagName === 'font') {
  816. var fontStyleMap = {}, fontStyle = '';
  817. _each(attrMap, function(key, val) {
  818. if (key === 'color') {
  819. fontStyleMap.color = val;
  820. delete attrMap[key];
  821. }
  822. if (key === 'size') {
  823. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  824. delete attrMap[key];
  825. }
  826. if (key === 'face') {
  827. fontStyleMap['font-family'] = val;
  828. delete attrMap[key];
  829. }
  830. if (key === 'style') {
  831. fontStyle = val;
  832. }
  833. });
  834. if (fontStyle && !/;$/.test(fontStyle)) {
  835. fontStyle += ';';
  836. }
  837. _each(fontStyleMap, function(key, val) {
  838. if (val === '') {
  839. return;
  840. }
  841. if (/\s/.test(val)) {
  842. val = "'" + val + "'";
  843. }
  844. fontStyle += key + ':' + val + ';';
  845. });
  846. attrMap.style = fontStyle;
  847. }
  848. _each(attrMap, function(key, val) {
  849. if (_FILL_ATTR_MAP[key]) {
  850. attrMap[key] = key;
  851. }
  852. if (_inArray(key, ['src', 'href']) >= 0) {
  853. attrMap[key] = _formatUrl(val, urlType);
  854. }
  855. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  856. tagName === 'body' && key === 'contenteditable' ||
  857. /^kindeditor_\d+$/.test(key)) {
  858. delete attrMap[key];
  859. }
  860. if (key === 'style' && val !== '') {
  861. var styleMap = _getCssList(val);
  862. _each(styleMap, function(k, v) {
  863. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  864. delete styleMap[k];
  865. }
  866. });
  867. var style = '';
  868. _each(styleMap, function(k, v) {
  869. style += k + ':' + v + ';';
  870. });
  871. attrMap.style = style;
  872. }
  873. });
  874. attr = '';
  875. _each(attrMap, function(key, val) {
  876. if (key === 'style' && val === '') {
  877. return;
  878. }
  879. val = val.replace(/"/g, '&quot;');
  880. attr += ' ' + key + '="' + val + '"';
  881. });
  882. }
  883. if (tagName === 'font') {
  884. tagName = 'span';
  885. }
  886. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  887. });
  888. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  889. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  890. });
  891. html = html.replace(/\n\s*\n/g, '\n');
  892. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  893. return _trim(html);
  894. }
  895. function _clearMsWord(html, htmlTags) {
  896. html = html.replace(/<meta[\s\S]*?>/ig, '')
  897. .replace(/<![\s\S]*?>/ig, '')
  898. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  899. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  900. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  901. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  902. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  903. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  904. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  905. });
  906. return _formatHtml(html, htmlTags);
  907. }
  908. function _mediaType(src) {
  909. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  910. return 'audio/x-pn-realaudio-plugin';
  911. }
  912. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  913. return 'application/x-shockwave-flash';
  914. }
  915. return 'video/x-ms-asf-plugin';
  916. }
  917. function _mediaClass(type) {
  918. if (/realaudio/i.test(type)) {
  919. return 'ke-rm';
  920. }
  921. if (/flash/i.test(type)) {
  922. return 'ke-flash';
  923. }
  924. return 'ke-media';
  925. }
  926. function _mediaAttrs(srcTag) {
  927. return _getAttrList(unescape(srcTag));
  928. }
  929. function _mediaEmbed(attrs) {
  930. var html = '<embed ';
  931. _each(attrs, function(key, val) {
  932. html += key + '="' + val + '" ';
  933. });
  934. html += '/>';
  935. return html;
  936. }
  937. function _mediaImg(blankPath, attrs) {
  938. var width = attrs.width,
  939. height = attrs.height,
  940. type = attrs.type || _mediaType(attrs.src),
  941. srcTag = _mediaEmbed(attrs),
  942. style = '';
  943. if (/\D/.test(width)) {
  944. style += 'width:' + width + ';';
  945. } else if (width > 0) {
  946. style += 'width:' + width + 'px;';
  947. }
  948. if (/\D/.test(height)) {
  949. style += 'height:' + height + ';';
  950. } else if (height > 0) {
  951. style += 'height:' + height + 'px;';
  952. }
  953. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  954. if (style !== '') {
  955. html += 'style="' + style + '" ';
  956. }
  957. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  958. return html;
  959. }
  960. function _tmpl(str, data) {
  961. var fn = new Function("obj",
  962. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  963. "with(obj){p.push('" +
  964. str.replace(/[\r\t\n]/g, " ")
  965. .split("<%").join("\t")
  966. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  967. .replace(/\t=(.*?)%>/g, "',$1,'")
  968. .split("\t").join("');")
  969. .split("%>").join("p.push('")
  970. .split("\r").join("\\'") + "');}return p.join('');");
  971. return data ? fn(data) : fn;
  972. }
  973. K.formatUrl = _formatUrl;
  974. K.formatHtml = _formatHtml;
  975. K.getCssList = _getCssList;
  976. K.getAttrList = _getAttrList;
  977. K.mediaType = _mediaType;
  978. K.mediaAttrs = _mediaAttrs;
  979. K.mediaEmbed = _mediaEmbed;
  980. K.mediaImg = _mediaImg;
  981. K.clearMsWord = _clearMsWord;
  982. K.tmpl = _tmpl;
  983. function _contains(nodeA, nodeB) {
  984. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  985. return true;
  986. }
  987. while ((nodeB = nodeB.parentNode)) {
  988. if (nodeB == nodeA) {
  989. return true;
  990. }
  991. }
  992. return false;
  993. }
  994. var _getSetAttrDiv = document.createElement('div');
  995. _getSetAttrDiv.setAttribute('className', 't');
  996. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  997. function _getAttr(el, key) {
  998. key = key.toLowerCase();
  999. var val = null;
  1000. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1001. var div = el.ownerDocument.createElement('div');
  1002. div.appendChild(el.cloneNode(false));
  1003. var list = _getAttrList(_unescape(div.innerHTML));
  1004. if (key in list) {
  1005. val = list[key];
  1006. }
  1007. } else {
  1008. try {
  1009. val = el.getAttribute(key, 2);
  1010. } catch(e) {
  1011. val = el.getAttribute(key, 1);
  1012. }
  1013. }
  1014. if (key === 'style' && val !== null) {
  1015. val = _formatCss(val);
  1016. }
  1017. return val;
  1018. }
  1019. function _queryAll(expr, root) {
  1020. var exprList = expr.split(',');
  1021. if (exprList.length > 1) {
  1022. var mergedResults = [];
  1023. _each(exprList, function() {
  1024. _each(_queryAll(this, root), function() {
  1025. if (_inArray(this, mergedResults) < 0) {
  1026. mergedResults.push(this);
  1027. }
  1028. });
  1029. });
  1030. return mergedResults;
  1031. }
  1032. root = root || document;
  1033. function escape(str) {
  1034. if (typeof str != 'string') {
  1035. return str;
  1036. }
  1037. return str.replace(/([^\w\-])/g, '\\$1');
  1038. }
  1039. function stripslashes(str) {
  1040. return str.replace(/\\/g, '');
  1041. }
  1042. function cmpTag(tagA, tagB) {
  1043. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1044. }
  1045. function byId(id, tag, root) {
  1046. var arr = [],
  1047. doc = root.ownerDocument || root,
  1048. el = doc.getElementById(stripslashes(id));
  1049. if (el) {
  1050. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1051. arr.push(el);
  1052. }
  1053. }
  1054. return arr;
  1055. }
  1056. function byClass(className, tag, root) {
  1057. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1058. if (root.getElementsByClassName) {
  1059. els = root.getElementsByClassName(stripslashes(className));
  1060. for (i = 0, len = els.length; i < len; i++) {
  1061. el = els[i];
  1062. if (cmpTag(tag, el.nodeName)) {
  1063. arr.push(el);
  1064. }
  1065. }
  1066. } else if (doc.querySelectorAll) {
  1067. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1068. for (i = 0, len = els.length; i < len; i++) {
  1069. el = els[i];
  1070. if (_contains(root, el)) {
  1071. arr.push(el);
  1072. }
  1073. }
  1074. } else {
  1075. els = root.getElementsByTagName(tag);
  1076. className = ' ' + className + ' ';
  1077. for (i = 0, len = els.length; i < len; i++) {
  1078. el = els[i];
  1079. if (el.nodeType == 1) {
  1080. var cls = el.className;
  1081. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1082. arr.push(el);
  1083. }
  1084. }
  1085. }
  1086. }
  1087. return arr;
  1088. }
  1089. function byName(name, tag, root) {
  1090. var arr = [], doc = root.ownerDocument || root,
  1091. els = doc.getElementsByName(stripslashes(name)), el;
  1092. for (var i = 0, len = els.length; i < len; i++) {
  1093. el = els[i];
  1094. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1095. if (el.getAttribute('name') !== null) {
  1096. arr.push(el);
  1097. }
  1098. }
  1099. }
  1100. return arr;
  1101. }
  1102. function byAttr(key, val, tag, root) {
  1103. var arr = [], els = root.getElementsByTagName(tag), el;
  1104. for (var i = 0, len = els.length; i < len; i++) {
  1105. el = els[i];
  1106. if (el.nodeType == 1) {
  1107. if (val === null) {
  1108. if (_getAttr(el, key) !== null) {
  1109. arr.push(el);
  1110. }
  1111. } else {
  1112. if (val === escape(_getAttr(el, key))) {
  1113. arr.push(el);
  1114. }
  1115. }
  1116. }
  1117. }
  1118. return arr;
  1119. }
  1120. function select(expr, root) {
  1121. var arr = [], matches;
  1122. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1123. var tag = matches ? matches[1] : '*';
  1124. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1125. arr = byId(matches[1], tag, root);
  1126. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1127. arr = byClass(matches[1], tag, root);
  1128. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1129. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1130. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1131. var key = matches[1].toLowerCase(), val = matches[2];
  1132. if (key === 'id') {
  1133. arr = byId(val, tag, root);
  1134. } else if (key === 'class') {
  1135. arr = byClass(val, tag, root);
  1136. } else if (key === 'name') {
  1137. arr = byName(val, tag, root);
  1138. } else {
  1139. arr = byAttr(key, val, tag, root);
  1140. }
  1141. } else {
  1142. var els = root.getElementsByTagName(tag), el;
  1143. for (var i = 0, len = els.length; i < len; i++) {
  1144. el = els[i];
  1145. if (el.nodeType == 1) {
  1146. arr.push(el);
  1147. }
  1148. }
  1149. }
  1150. return arr;
  1151. }
  1152. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1153. while ((arr = re.exec(expr))) {
  1154. if (arr[1] !== ' ') {
  1155. parts.push(arr[1]);
  1156. }
  1157. }
  1158. var results = [];
  1159. if (parts.length == 1) {
  1160. return select(parts[0], root);
  1161. }
  1162. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1163. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1164. part = parts[i];
  1165. if (part === '>') {
  1166. isChild = true;
  1167. continue;
  1168. }
  1169. if (i > 0) {
  1170. els = [];
  1171. for (j = 0, len = results.length; j < len; j++) {
  1172. val = results[j];
  1173. subResults = select(part, val);
  1174. for (k = 0, l = subResults.length; k < l; k++) {
  1175. v = subResults[k];
  1176. if (isChild) {
  1177. if (val === v.parentNode) {
  1178. els.push(v);
  1179. }
  1180. } else {
  1181. els.push(v);
  1182. }
  1183. }
  1184. }
  1185. results = els;
  1186. } else {
  1187. results = select(part, root);
  1188. }
  1189. if (results.length === 0) {
  1190. return [];
  1191. }
  1192. }
  1193. return results;
  1194. }
  1195. function _query(expr, root) {
  1196. var arr = _queryAll(expr, root);
  1197. return arr.length > 0 ? arr[0] : null;
  1198. }
  1199. K.query = _query;
  1200. K.queryAll = _queryAll;
  1201. function _get(val) {
  1202. return K(val)[0];
  1203. }
  1204. function _getDoc(node) {
  1205. if (!node) {
  1206. return document;
  1207. }
  1208. return node.ownerDocument || node.document || node;
  1209. }
  1210. function _getWin(node) {
  1211. if (!node) {
  1212. return window;
  1213. }
  1214. var doc = _getDoc(node);
  1215. return doc.parentWindow || doc.defaultView;
  1216. }
  1217. function _setHtml(el, html) {
  1218. if (el.nodeType != 1) {
  1219. return;
  1220. }
  1221. var doc = _getDoc(el);
  1222. try {
  1223. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1224. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1225. temp.parentNode.removeChild(temp);
  1226. } catch(e) {
  1227. K(el).empty();
  1228. K('@' + html, doc).each(function() {
  1229. el.appendChild(this);
  1230. });
  1231. }
  1232. }
  1233. function _hasClass(el, cls) {
  1234. return _inString(cls, el.className, ' ');
  1235. }
  1236. function _setAttr(el, key, val) {
  1237. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1238. key = 'className';
  1239. }
  1240. el.setAttribute(key, '' + val);
  1241. }
  1242. function _removeAttr(el, key) {
  1243. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1244. key = 'className';
  1245. }
  1246. _setAttr(el, key, '');
  1247. el.removeAttribute(key);
  1248. }
  1249. function _getNodeName(node) {
  1250. if (!node || !node.nodeName) {
  1251. return '';
  1252. }
  1253. return node.nodeName.toLowerCase();
  1254. }
  1255. function _computedCss(el, key) {
  1256. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1257. if (win.getComputedStyle) {
  1258. var style = win.getComputedStyle(el, null);
  1259. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1260. } else if (el.currentStyle) {
  1261. val = el.currentStyle[camelKey] || el.style[camelKey];
  1262. }
  1263. return val;
  1264. }
  1265. function _hasVal(node) {
  1266. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1267. }
  1268. function _docElement(doc) {
  1269. doc = doc || document;
  1270. return _QUIRKS ? doc.body : doc.documentElement;
  1271. }
  1272. function _docHeight(doc) {
  1273. var el = _docElement(doc);
  1274. return Math.max(el.scrollHeight, el.clientHeight);
  1275. }
  1276. function _docWidth(doc) {
  1277. var el = _docElement(doc);
  1278. return Math.max(el.scrollWidth, el.clientWidth);
  1279. }
  1280. function _getScrollPos(doc) {
  1281. doc = doc || document;
  1282. var x, y;
  1283. if (_IE || _NEWIE || _OPERA) {
  1284. x = _docElement(doc).scrollLeft;
  1285. y = _docElement(doc).scrollTop;
  1286. } else {
  1287. x = _getWin(doc).scrollX;
  1288. y = _getWin(doc).scrollY;
  1289. }
  1290. return {x : x, y : y};
  1291. }
  1292. function KNode(node) {
  1293. this.init(node);
  1294. }
  1295. _extend(KNode, {
  1296. init : function(node) {
  1297. var self = this;
  1298. node = _isArray(node) ? node : [node];
  1299. var length = 0;
  1300. for (var i = 0, len = node.length; i < len; i++) {
  1301. if (node[i]) {
  1302. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1303. length++;
  1304. }
  1305. }
  1306. self.length = length;
  1307. self.doc = _getDoc(self[0]);
  1308. self.name = _getNodeName(self[0]);
  1309. self.type = self.length > 0 ? self[0].nodeType : null;
  1310. self.win = _getWin(self[0]);
  1311. },
  1312. each : function(fn) {
  1313. var self = this;
  1314. for (var i = 0; i < self.length; i++) {
  1315. if (fn.call(self[i], i, self[i]) === false) {
  1316. return self;
  1317. }
  1318. }
  1319. return self;
  1320. },
  1321. bind : function(type, fn) {
  1322. this.each(function() {
  1323. _bind(this, type, fn);
  1324. });
  1325. return this;
  1326. },
  1327. unbind : function(type, fn) {
  1328. this.each(function() {
  1329. _unbind(this, type, fn);
  1330. });
  1331. return this;
  1332. },
  1333. fire : function(type) {
  1334. if (this.length < 1) {
  1335. return this;
  1336. }
  1337. _fire(this[0], type);
  1338. return this;
  1339. },
  1340. hasAttr : function(key) {
  1341. if (this.length < 1) {
  1342. return false;
  1343. }
  1344. return !!_getAttr(this[0], key);
  1345. },
  1346. attr : function(key, val) {
  1347. var self = this;
  1348. if (key === undefined) {
  1349. return _getAttrList(self.outer());
  1350. }
  1351. if (typeof key === 'object') {
  1352. _each(key, function(k, v) {
  1353. self.attr(k, v);
  1354. });
  1355. return self;
  1356. }
  1357. if (val === undefined) {
  1358. val = self.length < 1 ? null : _getAttr(self[0], key);
  1359. return val === null ? '' : val;
  1360. }
  1361. self.each(function() {
  1362. _setAttr(this, key, val);
  1363. });
  1364. return self;
  1365. },
  1366. removeAttr : function(key) {
  1367. this.each(function() {
  1368. _removeAttr(this, key);
  1369. });
  1370. return this;
  1371. },
  1372. get : function(i) {
  1373. if (this.length < 1) {
  1374. return null;
  1375. }
  1376. return this[i || 0];
  1377. },
  1378. eq : function(i) {
  1379. if (this.length < 1) {
  1380. return null;
  1381. }
  1382. return this[i] ? new KNode(this[i]) : null;
  1383. },
  1384. hasClass : function(cls) {
  1385. if (this.length < 1) {
  1386. return false;
  1387. }
  1388. return _hasClass(this[0], cls);
  1389. },
  1390. addClass : function(cls) {
  1391. this.each(function() {
  1392. if (!_hasClass(this, cls)) {
  1393. this.className = _trim(this.className + ' ' + cls);
  1394. }
  1395. });
  1396. return this;
  1397. },
  1398. removeClass : function(cls) {
  1399. this.each(function() {
  1400. if (_hasClass(this, cls)) {
  1401. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1402. }
  1403. });
  1404. return this;
  1405. },
  1406. html : function(val) {
  1407. var self = this;
  1408. if (val === undefined) {
  1409. if (self.length < 1 || self.type != 1) {
  1410. return '';
  1411. }
  1412. return _formatHtml(self[0].innerHTML);
  1413. }
  1414. self.each(function() {
  1415. _setHtml(this, val);
  1416. });
  1417. return self;
  1418. },
  1419. text : function() {
  1420. var self = this;
  1421. if (self.length < 1) {
  1422. return '';
  1423. }
  1424. return _IE ? self[0].innerText : self[0].textContent;
  1425. },
  1426. hasVal : function() {
  1427. if (this.length < 1) {
  1428. return false;
  1429. }
  1430. return _hasVal(this[0]);
  1431. },
  1432. val : function(val) {
  1433. var self = this;
  1434. if (val === undefined) {
  1435. if (self.length < 1) {
  1436. return '';
  1437. }
  1438. return self.hasVal() ? self[0].value : self.attr('value');
  1439. } else {
  1440. self.each(function() {
  1441. if (_hasVal(this)) {
  1442. this.value = val;
  1443. } else {
  1444. _setAttr(this, 'value' , val);
  1445. }
  1446. });
  1447. return self;
  1448. }
  1449. },
  1450. css : function(key, val) {
  1451. var self = this;
  1452. if (key === undefined) {
  1453. return _getCssList(self.attr('style'));
  1454. }
  1455. if (typeof key === 'object') {
  1456. _each(key, function(k, v) {
  1457. self.css(k, v);
  1458. });
  1459. return self;
  1460. }
  1461. if (val === undefined) {
  1462. if (self.length < 1) {
  1463. return '';
  1464. }
  1465. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1466. }
  1467. self.each(function() {
  1468. this.style[_toCamel(key)] = val;
  1469. });
  1470. return self;
  1471. },
  1472. width : function(val) {
  1473. var self = this;
  1474. if (val === undefined) {
  1475. if (self.length < 1) {
  1476. return 0;
  1477. }
  1478. return self[0].offsetWidth;
  1479. }
  1480. return self.css('width', _addUnit(val));
  1481. },
  1482. height : function(val) {
  1483. var self = this;
  1484. if (val === undefined) {
  1485. if (self.length < 1) {
  1486. return 0;
  1487. }
  1488. return self[0].offsetHeight;
  1489. }
  1490. return self.css('height', _addUnit(val));
  1491. },
  1492. opacity : function(val) {
  1493. this.each(function() {
  1494. if (this.style.opacity === undefined) {
  1495. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1496. } else {
  1497. this.style.opacity = val == 1 ? '' : val;
  1498. }
  1499. });
  1500. return this;
  1501. },
  1502. data : function(key, val) {
  1503. var self = this;
  1504. key = 'kindeditor_data_' + key;
  1505. if (val === undefined) {
  1506. if (self.length < 1) {
  1507. return null;
  1508. }
  1509. return self[0][key];
  1510. }
  1511. this.each(function() {
  1512. this[key] = val;
  1513. });
  1514. return self;
  1515. },
  1516. pos : function() {
  1517. var self = this, node = self[0], x = 0, y = 0;
  1518. if (node) {
  1519. if (node.getBoundingClientRect) {
  1520. var box = node.getBoundingClientRect(),
  1521. pos = _getScrollPos(self.doc);
  1522. x = box.left + pos.x;
  1523. y = box.top + pos.y;
  1524. } else {
  1525. while (node) {
  1526. x += node.offsetLeft;
  1527. y += node.offsetTop;
  1528. node = node.offsetParent;
  1529. }
  1530. }
  1531. }
  1532. return {x : _round(x), y : _round(y)};
  1533. },
  1534. clone : function(bool) {
  1535. if (this.length < 1) {
  1536. return new KNode([]);
  1537. }
  1538. return new KNode(this[0].cloneNode(bool));
  1539. },
  1540. append : function(expr) {
  1541. this.each(function() {
  1542. if (this.appendChild) {
  1543. this.appendChild(_get(expr));
  1544. }
  1545. });
  1546. return this;
  1547. },
  1548. appendTo : function(expr) {
  1549. this.each(function() {
  1550. _get(expr).appendChild(this);
  1551. });
  1552. return this;
  1553. },
  1554. before : function(expr) {
  1555. this.each(function() {
  1556. this.parentNode.insertBefore(_get(expr), this);
  1557. });
  1558. return this;
  1559. },
  1560. after : function(expr) {
  1561. this.each(function() {
  1562. if (this.nextSibling) {
  1563. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1564. } else {
  1565. this.parentNode.appendChild(_get(expr));
  1566. }
  1567. });
  1568. return this;
  1569. },
  1570. replaceWith : function(expr) {
  1571. var nodes = [];
  1572. this.each(function(i, node) {
  1573. _unbind(node);
  1574. var newNode = _get(expr);
  1575. node.parentNode.replaceChild(newNode, node);
  1576. nodes.push(newNode);
  1577. });
  1578. return K(nodes);
  1579. },
  1580. empty : function() {
  1581. var self = this;
  1582. self.each(function(i, node) {
  1583. var child = node.firstChild;
  1584. while (child) {
  1585. if (!node.parentNode) {
  1586. return;
  1587. }
  1588. var next = child.nextSibling;
  1589. child.parentNode.removeChild(child);
  1590. child = next;
  1591. }
  1592. });
  1593. return self;
  1594. },
  1595. remove : function(keepChilds) {
  1596. var self = this;
  1597. self.each(function(i, node) {
  1598. if (!node.parentNode) {
  1599. return;
  1600. }
  1601. _unbind(node);
  1602. if (keepChilds) {
  1603. var child = node.firstChild;
  1604. while (child) {
  1605. var next = child.nextSibling;
  1606. node.parentNode.insertBefore(child, node);
  1607. child = next;
  1608. }
  1609. }
  1610. node.parentNode.removeChild(node);
  1611. delete self[i];
  1612. });
  1613. self.length = 0;
  1614. return self;
  1615. },
  1616. show : function(val) {
  1617. var self = this;
  1618. if (val === undefined) {
  1619. val = self._originDisplay || '';
  1620. }
  1621. if (self.css('display') != 'none') {
  1622. return self;
  1623. }
  1624. return self.css('display', val);
  1625. },
  1626. hide : function() {
  1627. var self = this;
  1628. if (self.length < 1) {
  1629. return self;
  1630. }
  1631. self._originDisplay = self[0].style.display;
  1632. return self.css('display', 'none');
  1633. },
  1634. outer : function() {
  1635. var self = this;
  1636. if (self.length < 1) {
  1637. return '';
  1638. }
  1639. var div = self.doc.createElement('div'), html;
  1640. div.appendChild(self[0].cloneNode(true));
  1641. html = _formatHtml(div.innerHTML);
  1642. div = null;
  1643. return html;
  1644. },
  1645. isSingle : function() {
  1646. return !!_SINGLE_TAG_MAP[this.name];
  1647. },
  1648. isInline : function() {
  1649. return !!_INLINE_TAG_MAP[this.name];
  1650. },
  1651. isBlock : function() {
  1652. return !!_BLOCK_TAG_MAP[this.name];
  1653. },
  1654. isStyle : function() {
  1655. return !!_STYLE_TAG_MAP[this.name];
  1656. },
  1657. isControl : function() {
  1658. return !!_CONTROL_TAG_MAP[this.name];
  1659. },
  1660. contains : function(otherNode) {
  1661. if (this.length < 1) {
  1662. return false;
  1663. }
  1664. return _contains(this[0], _get(otherNode));
  1665. },
  1666. parent : function() {
  1667. if (this.length < 1) {
  1668. return null;
  1669. }
  1670. var node = this[0].parentNode;
  1671. return node ? new KNode(node) : null;
  1672. },
  1673. children : function() {
  1674. if (this.length < 1) {
  1675. return new KNode([]);
  1676. }
  1677. var list = [], child = this[0].firstChild;
  1678. while (child) {
  1679. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1680. list.push(child);
  1681. }
  1682. child = child.nextSibling;
  1683. }
  1684. return new KNode(list);
  1685. },
  1686. first : function() {
  1687. var list = this.children();
  1688. return list.length > 0 ? list.eq(0) : null;
  1689. },
  1690. last : function() {
  1691. var list = this.children();
  1692. return list.length > 0 ? list.eq(list.length - 1) : null;
  1693. },
  1694. index : function() {
  1695. if (this.length < 1) {
  1696. return -1;
  1697. }
  1698. var i = -1, sibling = this[0];
  1699. while (sibling) {
  1700. i++;
  1701. sibling = sibling.previousSibling;
  1702. }
  1703. return i;
  1704. },
  1705. prev : function() {
  1706. if (this.length < 1) {
  1707. return null;
  1708. }
  1709. var node = this[0].previousSibling;
  1710. return node ? new KNode(node) : null;
  1711. },
  1712. next : function() {
  1713. if (this.length < 1) {
  1714. return null;
  1715. }
  1716. var node = this[0].nextSibling;
  1717. return node ? new KNode(node) : null;
  1718. },
  1719. scan : function(fn, order) {
  1720. if (this.length < 1) {
  1721. return;
  1722. }
  1723. order = (order === undefined) ? true : order;
  1724. function walk(node) {
  1725. var n = order ? node.firstChild : node.lastChild;
  1726. while (n) {
  1727. var next = order ? n.nextSibling : n.previousSibling;
  1728. if (fn(n) === false) {
  1729. return false;
  1730. }
  1731. if (walk(n) === false) {
  1732. return false;
  1733. }
  1734. n = next;
  1735. }
  1736. }
  1737. walk(this[0]);
  1738. return this;
  1739. }
  1740. });
  1741. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1742. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1743. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1744. KNode.prototype[type] = function(fn) {
  1745. return fn ? this.bind(type, fn) : this.fire(type);
  1746. };
  1747. });
  1748. var _K = K;
  1749. K = function(expr, root) {
  1750. if (expr === undefined || expr === null) {
  1751. return;
  1752. }
  1753. function newNode(node) {
  1754. if (!node[0]) {
  1755. node = [];
  1756. }
  1757. return new KNode(node);
  1758. }
  1759. if (typeof expr === 'string') {
  1760. if (root) {
  1761. root = _get(root);
  1762. }
  1763. var length = expr.length;
  1764. if (expr.charAt(0) === '@') {
  1765. expr = expr.substr(1);
  1766. }
  1767. if (expr.length !== length || /<.+>/.test(expr)) {
  1768. var doc = root ? root.ownerDocument || root : document,
  1769. div = doc.createElement('div'), list = [];
  1770. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1771. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1772. var child = div.childNodes[i];
  1773. if (child.id == '__kindeditor_temp_tag__') {
  1774. continue;
  1775. }
  1776. list.push(child);
  1777. }
  1778. return newNode(list);
  1779. }
  1780. return newNode(_queryAll(expr, root));
  1781. }
  1782. if (expr && expr.constructor === KNode) {
  1783. return expr;
  1784. }
  1785. if (expr.toArray) {
  1786. expr = expr.toArray();
  1787. }
  1788. if (_isArray(expr)) {
  1789. return newNode(expr);
  1790. }
  1791. return newNode(_toArray(arguments));
  1792. };
  1793. _each(_K, function(key, val) {
  1794. K[key] = val;
  1795. });
  1796. K.NodeClass = KNode;
  1797. window.KindEditor = K;
  1798. var _START_TO_START = 0,
  1799. _START_TO_END = 1,
  1800. _END_TO_END = 2,
  1801. _END_TO_START = 3,
  1802. _BOOKMARK_ID = 0;
  1803. function _updateCollapsed(range) {
  1804. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1805. return range;
  1806. }
  1807. function _copyAndDelete(range, isCopy, isDelete) {
  1808. var doc = range.doc, nodeList = [];
  1809. function splitTextNode(node, startOffset, endOffset) {
  1810. var length = node.nodeValue.length, centerNode;
  1811. if (isCopy) {
  1812. var cloneNode = node.cloneNode(true);
  1813. if (startOffset > 0) {
  1814. centerNode = cloneNode.splitText(startOffset);
  1815. } else {
  1816. centerNode = cloneNode;
  1817. }
  1818. if (endOffset < length) {
  1819. centerNode.splitText(endOffset - startOffset);
  1820. }
  1821. }
  1822. if (isDelete) {
  1823. var center = node;
  1824. if (startOffset > 0) {
  1825. center = node.splitText(startOffset);
  1826. range.setStart(node, startOffset);
  1827. }
  1828. if (endOffset < length) {
  1829. var right = center.splitText(endOffset - startOffset);
  1830. range.setEnd(right, 0);
  1831. }
  1832. nodeList.push(center);
  1833. }
  1834. return centerNode;
  1835. }
  1836. function removeNodes() {
  1837. if (isDelete) {
  1838. range.up().collapse(true);
  1839. }
  1840. for (var i = 0, len = nodeList.length; i < len; i++) {
  1841. var node = nodeList[i];
  1842. if (node.parentNode) {
  1843. node.parentNode.removeChild(node);
  1844. }
  1845. }
  1846. }
  1847. var copyRange = range.cloneRange().down();
  1848. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1849. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1850. if (ancestor.nodeType == 3) {
  1851. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1852. if (isCopy) {
  1853. frag.appendChild(textNode);
  1854. }
  1855. removeNodes();
  1856. return isCopy ? frag : range;
  1857. }
  1858. function extractNodes(parent, frag) {
  1859. var node = parent.firstChild, nextNode;
  1860. while (node) {
  1861. var testRange = new KRange(doc).selectNode(node);
  1862. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1863. if (start >= 0 && incStart <= 0) {
  1864. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1865. }
  1866. if (incStart >= 0 && incEnd <= 0) {
  1867. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1868. }
  1869. if (incEnd >= 0 && end <= 0) {
  1870. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1871. }
  1872. if (end >= 0) {
  1873. return false;
  1874. }
  1875. nextNode = node.nextSibling;
  1876. if (start > 0) {
  1877. if (node.nodeType == 1) {
  1878. if (incStart >= 0 && incEnd <= 0) {
  1879. if (isCopy) {
  1880. frag.appendChild(node.cloneNode(true));
  1881. }
  1882. if (isDelete) {
  1883. nodeList.push(node);
  1884. }
  1885. } else {
  1886. var childFlag;
  1887. if (isCopy) {
  1888. childFlag = node.cloneNode(false);
  1889. frag.appendChild(childFlag);
  1890. }
  1891. if (extractNodes(node, childFlag) === false) {
  1892. return false;
  1893. }
  1894. }
  1895. } else if (node.nodeType == 3) {
  1896. var textNode;
  1897. if (node == copyRange.startContainer) {
  1898. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1899. } else if (node == copyRange.endContainer) {
  1900. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1901. } else {
  1902. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1903. }
  1904. if (isCopy) {
  1905. try {
  1906. frag.appendChild(textNode);
  1907. } catch(e) {}
  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. function _getStartEnd(rng, isStart) {
  1940. var doc = rng.parentElement().ownerDocument,
  1941. pointRange = rng.duplicate();
  1942. pointRange.collapse(isStart);
  1943. var parent = pointRange.parentElement(),
  1944. nodes = parent.childNodes;
  1945. if (nodes.length === 0) {
  1946. return {node: parent.parentNode, offset: K(parent).index()};
  1947. }
  1948. var startNode = doc, startPos = 0, cmp = -1;
  1949. var testRange = rng.duplicate();
  1950. _moveToElementText(testRange, parent);
  1951. for (var i = 0, len = nodes.length; i < len; i++) {
  1952. var node = nodes[i];
  1953. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1954. if (cmp === 0) {
  1955. return {node: node.parentNode, offset: i};
  1956. }
  1957. if (node.nodeType == 1) {
  1958. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1959. if (knode.isControl()) {
  1960. dummy = doc.createElement('span');
  1961. knode.after(dummy);
  1962. newNode = dummy;
  1963. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1964. }
  1965. _moveToElementText(nodeRange, newNode);
  1966. testRange.setEndPoint('StartToEnd', nodeRange);
  1967. if (cmp > 0) {
  1968. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1969. } else {
  1970. startPos = 0;
  1971. }
  1972. if (dummy) {
  1973. K(dummy).remove();
  1974. }
  1975. } else if (node.nodeType == 3) {
  1976. testRange.moveStart('character', node.nodeValue.length);
  1977. startPos += node.nodeValue.length;
  1978. }
  1979. if (cmp < 0) {
  1980. startNode = node;
  1981. }
  1982. }
  1983. if (cmp < 0 && startNode.nodeType == 1) {
  1984. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1985. }
  1986. if (cmp > 0) {
  1987. while (startNode.nextSibling && startNode.nodeType == 1) {
  1988. startNode = startNode.nextSibling;
  1989. }
  1990. }
  1991. testRange = rng.duplicate();
  1992. _moveToElementText(testRange, parent);
  1993. testRange.setEndPoint('StartToEnd', pointRange);
  1994. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1995. if (cmp > 0 && startNode.nodeType == 3) {
  1996. var prevNode = startNode.previousSibling;
  1997. while (prevNode && prevNode.nodeType == 3) {
  1998. startPos -= prevNode.nodeValue.length;
  1999. prevNode = prevNode.previousSibling;
  2000. }
  2001. }
  2002. return {node: startNode, offset: startPos};
  2003. }
  2004. function _getEndRange(node, offset) {
  2005. var doc = node.ownerDocument || node,
  2006. range = doc.body.createTextRange();
  2007. if (doc == node) {
  2008. range.collapse(true);
  2009. return range;
  2010. }
  2011. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2012. var children = node.childNodes, isStart, child;
  2013. if (offset === 0) {
  2014. child = children[0];
  2015. isStart = true;
  2016. } else {
  2017. child = children[offset - 1];
  2018. isStart = false;
  2019. }
  2020. if (!child) {
  2021. return range;
  2022. }
  2023. if (K(child).name === 'head') {
  2024. if (offset === 1) {
  2025. isStart = true;
  2026. }
  2027. if (offset === 2) {
  2028. isStart = false;
  2029. }
  2030. range.collapse(isStart);
  2031. return range;
  2032. }
  2033. if (child.nodeType == 1) {
  2034. var kchild = K(child), span;
  2035. if (kchild.isControl()) {
  2036. span = doc.createElement('span');
  2037. if (isStart) {
  2038. kchild.before(span);
  2039. } else {
  2040. kchild.after(span);
  2041. }
  2042. child = span;
  2043. }
  2044. _moveToElementText(range, child);
  2045. range.collapse(isStart);
  2046. if (span) {
  2047. K(span).remove();
  2048. }
  2049. return range;
  2050. }
  2051. node = child;
  2052. offset = isStart ? 0 : child.nodeValue.length;
  2053. }
  2054. var dummy = doc.createElement('span');
  2055. K(node).before(dummy);
  2056. _moveToElementText(range, dummy);
  2057. range.moveStart('character', offset);
  2058. K(dummy).remove();
  2059. return range;
  2060. }
  2061. function _toRange(rng) {
  2062. var doc, range;
  2063. function tr2td(start) {
  2064. if (K(start.node).name == 'tr') {
  2065. start.node = start.node.cells[start.offset];
  2066. start.offset = 0;
  2067. }
  2068. }
  2069. if (_IERANGE) {
  2070. if (rng.item) {
  2071. doc = _getDoc(rng.item(0));
  2072. range = new KRange(doc);
  2073. range.selectNode(rng.item(0));
  2074. return range;
  2075. }
  2076. doc = rng.parentElement().ownerDocument;
  2077. var start = _getStartEnd(rng, true),
  2078. end = _getStartEnd(rng, false);
  2079. tr2td(start);
  2080. tr2td(end);
  2081. range = new KRange(doc);
  2082. range.setStart(start.node, start.offset);
  2083. range.setEnd(end.node, end.offset);
  2084. return range;
  2085. }
  2086. var startContainer = rng.startContainer;
  2087. doc = startContainer.ownerDocument || startContainer;
  2088. range = new KRange(doc);
  2089. range.setStart(startContainer, rng.startOffset);
  2090. range.setEnd(rng.endContainer, rng.endOffset);
  2091. return range;
  2092. }
  2093. function KRange(doc) {
  2094. this.init(doc);
  2095. }
  2096. _extend(KRange, {
  2097. init : function(doc) {
  2098. var self = this;
  2099. self.startContainer = doc;
  2100. self.startOffset = 0;
  2101. self.endContainer = doc;
  2102. self.endOffset = 0;
  2103. self.collapsed = true;
  2104. self.doc = doc;
  2105. },
  2106. commonAncestor : function() {
  2107. function getParents(node) {
  2108. var parents = [];
  2109. while (node) {
  2110. parents.push(node);
  2111. node = node.parentNode;
  2112. }
  2113. return parents;
  2114. }
  2115. var parentsA = getParents(this.startContainer),
  2116. parentsB = getParents(this.endContainer),
  2117. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2118. while (++i) {
  2119. parentA = parentsA[lenA - i];
  2120. parentB = parentsB[lenB - i];
  2121. if (!parentA || !parentB || parentA !== parentB) {
  2122. break;
  2123. }
  2124. }
  2125. return parentsA[lenA - i + 1];
  2126. },
  2127. setStart : function(node, offset) {
  2128. var self = this, doc = self.doc;
  2129. self.startContainer = node;
  2130. self.startOffset = offset;
  2131. if (self.endContainer === doc) {
  2132. self.endContainer = node;
  2133. self.endOffset = offset;
  2134. }
  2135. return _updateCollapsed(this);
  2136. },
  2137. setEnd : function(node, offset) {
  2138. var self = this, doc = self.doc;
  2139. self.endContainer = node;
  2140. self.endOffset = offset;
  2141. if (self.startContainer === doc) {
  2142. self.startContainer = node;
  2143. self.startOffset = offset;
  2144. }
  2145. return _updateCollapsed(this);
  2146. },
  2147. setStartBefore : function(node) {
  2148. return this.setStart(node.parentNode || this.doc, K(node).index());
  2149. },
  2150. setStartAfter : function(node) {
  2151. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2152. },
  2153. setEndBefore : function(node) {
  2154. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2155. },
  2156. setEndAfter : function(node) {
  2157. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2158. },
  2159. selectNode : function(node) {
  2160. return this.setStartBefore(node).setEndAfter(node);
  2161. },
  2162. selectNodeContents : function(node) {
  2163. var knode = K(node);
  2164. if (knode.type == 3 || knode.isSingle()) {
  2165. return this.selectNode(node);
  2166. }
  2167. var children = knode.children();
  2168. if (children.length > 0) {
  2169. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2170. }
  2171. return this.setStart(node, 0).setEnd(node, 0);
  2172. },
  2173. collapse : function(toStart) {
  2174. if (toStart) {
  2175. return this.setEnd(this.startContainer, this.startOffset);
  2176. }
  2177. return this.setStart(this.endContainer, this.endOffset);
  2178. },
  2179. compareBoundaryPoints : function(how, range) {
  2180. var rangeA = this.get(), rangeB = range.get();
  2181. if (_IERANGE) {
  2182. var arr = {};
  2183. arr[_START_TO_START] = 'StartToStart';
  2184. arr[_START_TO_END] = 'EndToStart';
  2185. arr[_END_TO_END] = 'EndToEnd';
  2186. arr[_END_TO_START] = 'StartToEnd';
  2187. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2188. if (cmp !== 0) {
  2189. return cmp;
  2190. }
  2191. var nodeA, nodeB, nodeC, posA, posB;
  2192. if (how === _START_TO_START || how === _END_TO_START) {
  2193. nodeA = this.startContainer;
  2194. posA = this.startOffset;
  2195. }
  2196. if (how === _START_TO_END || how === _END_TO_END) {
  2197. nodeA = this.endContainer;
  2198. posA = this.endOffset;
  2199. }
  2200. if (how === _START_TO_START || how === _START_TO_END) {
  2201. nodeB = range.startContainer;
  2202. posB = range.startOffset;
  2203. }
  2204. if (how === _END_TO_END || how === _END_TO_START) {
  2205. nodeB = range.endContainer;
  2206. posB = range.endOffset;
  2207. }
  2208. if (nodeA === nodeB) {
  2209. var diff = posA - posB;
  2210. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2211. }
  2212. nodeC = nodeB;
  2213. while (nodeC && nodeC.parentNode !== nodeA) {
  2214. nodeC = nodeC.parentNode;
  2215. }
  2216. if (nodeC) {
  2217. return K(nodeC).index() >= posA ? -1 : 1;
  2218. }
  2219. nodeC = nodeA;
  2220. while (nodeC && nodeC.parentNode !== nodeB) {
  2221. nodeC = nodeC.parentNode;
  2222. }
  2223. if (nodeC) {
  2224. return K(nodeC).index() >= posB ? 1 : -1;
  2225. }
  2226. nodeC = K(nodeB).next();
  2227. if (nodeC && nodeC.contains(nodeA)) {
  2228. return 1;
  2229. }
  2230. nodeC = K(nodeA).next();
  2231. if (nodeC && nodeC.contains(nodeB)) {
  2232. return -1;
  2233. }
  2234. } else {
  2235. return rangeA.compareBoundaryPoints(how, rangeB);
  2236. }
  2237. },
  2238. cloneRange : function() {
  2239. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2240. },
  2241. toString : function() {
  2242. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2243. return str.replace(/\r\n|\n|\r/g, '');
  2244. },
  2245. cloneContents : function() {
  2246. return _copyAndDelete(this, true, false);
  2247. },
  2248. deleteContents : function() {
  2249. return _copyAndDelete(this, false, true);
  2250. },
  2251. extractContents : function() {
  2252. return _copyAndDelete(this, true, true);
  2253. },
  2254. insertNode : function(node) {
  2255. var self = this,
  2256. sc = self.startContainer, so = self.startOffset,
  2257. ec = self.endContainer, eo = self.endOffset,
  2258. firstChild, lastChild, c, nodeCount = 1;
  2259. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2260. firstChild = node.firstChild;
  2261. lastChild = node.lastChild;
  2262. nodeCount = node.childNodes.length;
  2263. }
  2264. if (sc.nodeType == 1) {
  2265. c = sc.childNodes[so];
  2266. if (c) {
  2267. sc.insertBefore(node, c);
  2268. if (sc === ec) {
  2269. eo += nodeCount;
  2270. }
  2271. } else {
  2272. sc.appendChild(node);
  2273. }
  2274. } else if (sc.nodeType == 3) {
  2275. if (so === 0) {
  2276. sc.parentNode.insertBefore(node, sc);
  2277. if (sc.parentNode === ec) {
  2278. eo += nodeCount;
  2279. }
  2280. } else if (so >= sc.nodeValue.length) {
  2281. if (sc.nextSibling) {
  2282. sc.parentNode.insertBefore(node, sc.nextSibling);
  2283. } else {
  2284. sc.parentNode.appendChild(node);
  2285. }
  2286. } else {
  2287. if (so > 0) {
  2288. c = sc.splitText(so);
  2289. } else {
  2290. c = sc;
  2291. }
  2292. sc.parentNode.insertBefore(node, c);
  2293. if (sc === ec) {
  2294. ec = c;
  2295. eo -= so;
  2296. }
  2297. }
  2298. }
  2299. if (firstChild) {
  2300. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2301. } else {
  2302. self.selectNode(node);
  2303. }
  2304. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2305. return self;
  2306. }
  2307. return self.setEnd(ec, eo);
  2308. },
  2309. surroundContents : function(node) {
  2310. node.appendChild(this.extractContents());
  2311. return this.insertNode(node).selectNode(node);
  2312. },
  2313. isControl : function() {
  2314. var self = this,
  2315. sc = self.startContainer, so = self.startOffset,
  2316. ec = self.endContainer, eo = self.endOffset, rng;
  2317. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2318. },
  2319. get : function(hasControlRange) {
  2320. var self = this, doc = self.doc, node, rng;
  2321. if (!_IERANGE) {
  2322. rng = doc.createRange();
  2323. try {
  2324. rng.setStart(self.startContainer, self.startOffset);
  2325. rng.setEnd(self.endContainer, self.endOffset);
  2326. } catch (e) {}
  2327. return rng;
  2328. }
  2329. if (hasControlRange && self.isControl()) {
  2330. rng = doc.body.createControlRange();
  2331. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2332. return rng;
  2333. }
  2334. var range = self.cloneRange().down();
  2335. rng = doc.body.createTextRange();
  2336. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2337. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2338. return rng;
  2339. },
  2340. html : function() {
  2341. return K(this.cloneContents()).outer();
  2342. },
  2343. down : function() {
  2344. var self = this;
  2345. function downPos(node, pos, isStart) {
  2346. if (node.nodeType != 1) {
  2347. return;
  2348. }
  2349. var children = K(node).children();
  2350. if (children.length === 0) {
  2351. return;
  2352. }
  2353. var left, right, child, offset;
  2354. if (pos > 0) {
  2355. left = children.eq(pos - 1);
  2356. }
  2357. if (pos < children.length) {
  2358. right = children.eq(pos);
  2359. }
  2360. if (left && left.type == 3) {
  2361. child = left[0];
  2362. offset = child.nodeValue.length;
  2363. }
  2364. if (right && right.type == 3) {
  2365. child = right[0];
  2366. offset = 0;
  2367. }
  2368. if (!child) {
  2369. return;
  2370. }
  2371. if (isStart) {
  2372. self.setStart(child, offset);
  2373. } else {
  2374. self.setEnd(child, offset);
  2375. }
  2376. }
  2377. downPos(self.startContainer, self.startOffset, true);
  2378. downPos(self.endContainer, self.endOffset, false);
  2379. return self;
  2380. },
  2381. up : function() {
  2382. var self = this;
  2383. function upPos(node, pos, isStart) {
  2384. if (node.nodeType != 3) {
  2385. return;
  2386. }
  2387. if (pos === 0) {
  2388. if (isStart) {
  2389. self.setStartBefore(node);
  2390. } else {
  2391. self.setEndBefore(node);
  2392. }
  2393. } else if (pos == node.nodeValue.length) {
  2394. if (isStart) {
  2395. self.setStartAfter(node);
  2396. } else {
  2397. self.setEndAfter(node);
  2398. }
  2399. }
  2400. }
  2401. upPos(self.startContainer, self.startOffset, true);
  2402. upPos(self.endContainer, self.endOffset, false);
  2403. return self;
  2404. },
  2405. enlarge : function(toBlock) {
  2406. var self = this;
  2407. self.up();
  2408. function enlargePos(node, pos, isStart) {
  2409. var knode = K(node), parent;
  2410. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2411. return;
  2412. }
  2413. if (pos === 0) {
  2414. while (!knode.prev()) {
  2415. parent = knode.parent();
  2416. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2417. break;
  2418. }
  2419. knode = parent;
  2420. }
  2421. if (isStart) {
  2422. self.setStartBefore(knode[0]);
  2423. } else {
  2424. self.setEndBefore(knode[0]);
  2425. }
  2426. } else if (pos == knode.children().length) {
  2427. while (!knode.next()) {
  2428. parent = knode.parent();
  2429. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2430. break;
  2431. }
  2432. knode = parent;
  2433. }
  2434. if (isStart) {
  2435. self.setStartAfter(knode[0]);
  2436. } else {
  2437. self.setEndAfter(knode[0]);
  2438. }
  2439. }
  2440. }
  2441. enlargePos(self.startContainer, self.startOffset, true);
  2442. enlargePos(self.endContainer, self.endOffset, false);
  2443. return self;
  2444. },
  2445. shrink : function() {
  2446. var self = this, child, collapsed = self.collapsed;
  2447. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2448. self.setStart(child, 0);
  2449. }
  2450. if (collapsed) {
  2451. return self.collapse(collapsed);
  2452. }
  2453. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2454. self.setEnd(child, child.childNodes.length);
  2455. }
  2456. return self;
  2457. },
  2458. createBookmark : function(serialize) {
  2459. var self = this, doc = self.doc, endNode,
  2460. startNode = K('<span style="display:none;"></span>', doc)[0];
  2461. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2462. if (!self.collapsed) {
  2463. endNode = startNode.cloneNode(true);
  2464. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2465. }
  2466. if (endNode) {
  2467. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2468. }
  2469. self.insertNode(startNode).setStartAfter(startNode);
  2470. return {
  2471. start : serialize ? '#' + startNode.id : startNode,
  2472. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2473. };
  2474. },
  2475. moveToBookmark : function(bookmark) {
  2476. var self = this, doc = self.doc,
  2477. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2478. if (!start || start.length < 1) {
  2479. return self;
  2480. }
  2481. self.setStartBefore(start[0]);
  2482. start.remove();
  2483. if (end && end.length > 0) {
  2484. self.setEndBefore(end[0]);
  2485. end.remove();
  2486. } else {
  2487. self.collapse(true);
  2488. }
  2489. return self;
  2490. },
  2491. dump : function() {
  2492. console.log('--------------------');
  2493. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2494. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2495. }
  2496. });
  2497. function _range(mixed) {
  2498. if (!mixed.nodeName) {
  2499. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2500. }
  2501. return new KRange(mixed);
  2502. }
  2503. K.RangeClass = KRange;
  2504. K.range = _range;
  2505. K.START_TO_START = _START_TO_START;
  2506. K.START_TO_END = _START_TO_END;
  2507. K.END_TO_END = _END_TO_END;
  2508. K.END_TO_START = _END_TO_START;
  2509. function _nativeCommand(doc, key, val) {
  2510. try {
  2511. doc.execCommand(key, false, val);
  2512. } catch(e) {}
  2513. }
  2514. function _nativeCommandValue(doc, key) {
  2515. var val = '';
  2516. try {
  2517. val = doc.queryCommandValue(key);
  2518. } catch (e) {}
  2519. if (typeof val !== 'string') {
  2520. val = '';
  2521. }
  2522. return val;
  2523. }
  2524. function _getSel(doc) {
  2525. var win = _getWin(doc);
  2526. return _IERANGE ? doc.selection : win.getSelection();
  2527. }
  2528. function _getRng(doc) {
  2529. var sel = _getSel(doc), rng;
  2530. try {
  2531. if (sel.rangeCount > 0) {
  2532. rng = sel.getRangeAt(0);
  2533. } else {
  2534. rng = sel.createRange();
  2535. }
  2536. } catch(e) {}
  2537. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2538. return null;
  2539. }
  2540. return rng;
  2541. }
  2542. function _singleKeyMap(map) {
  2543. var newMap = {}, arr, v;
  2544. _each(map, function(key, val) {
  2545. arr = key.split(',');
  2546. for (var i = 0, len = arr.length; i < len; i++) {
  2547. v = arr[i];
  2548. newMap[v] = val;
  2549. }
  2550. });
  2551. return newMap;
  2552. }
  2553. function _hasAttrOrCss(knode, map) {
  2554. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2555. }
  2556. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2557. mapKey = mapKey || knode.name;
  2558. if (knode.type !== 1) {
  2559. return false;
  2560. }
  2561. var newMap = _singleKeyMap(map);
  2562. if (!newMap[mapKey]) {
  2563. return false;
  2564. }
  2565. var arr = newMap[mapKey].split(',');
  2566. for (var i = 0, len = arr.length; i < len; i++) {
  2567. var key = arr[i];
  2568. if (key === '*') {
  2569. return true;
  2570. }
  2571. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2572. var method = match[1] ? 'css' : 'attr';
  2573. key = match[2];
  2574. var val = match[3] || '';
  2575. if (val === '' && knode[method](key) !== '') {
  2576. return true;
  2577. }
  2578. if (val !== '' && knode[method](key) === val) {
  2579. return true;
  2580. }
  2581. }
  2582. return false;
  2583. }
  2584. function _removeAttrOrCss(knode, map) {
  2585. if (knode.type != 1) {
  2586. return;
  2587. }
  2588. _removeAttrOrCssByKey(knode, map, '*');
  2589. _removeAttrOrCssByKey(knode, map);
  2590. }
  2591. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2592. mapKey = mapKey || knode.name;
  2593. if (knode.type !== 1) {
  2594. return;
  2595. }
  2596. var newMap = _singleKeyMap(map);
  2597. if (!newMap[mapKey]) {
  2598. return;
  2599. }
  2600. var arr = newMap[mapKey].split(','), allFlag = false;
  2601. for (var i = 0, len = arr.length; i < len; i++) {
  2602. var key = arr[i];
  2603. if (key === '*') {
  2604. allFlag = true;
  2605. break;
  2606. }
  2607. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2608. key = match[2];
  2609. if (match[1]) {
  2610. key = _toCamel(key);
  2611. if (knode[0].style[key]) {
  2612. knode[0].style[key] = '';
  2613. }
  2614. } else {
  2615. knode.removeAttr(key);
  2616. }
  2617. }
  2618. if (allFlag) {
  2619. knode.remove(true);
  2620. }
  2621. }
  2622. function _getInnerNode(knode) {
  2623. var inner = knode;
  2624. while (inner.first()) {
  2625. inner = inner.first();
  2626. }
  2627. return inner;
  2628. }
  2629. function _isEmptyNode(knode) {
  2630. if (knode.type != 1 || knode.isSingle()) {
  2631. return false;
  2632. }
  2633. return knode.html().replace(/<[^>]+>/g, '') === '';
  2634. }
  2635. function _mergeWrapper(a, b) {
  2636. a = a.clone(true);
  2637. var lastA = _getInnerNode(a), childA = a, merged = false;
  2638. while (b) {
  2639. while (childA) {
  2640. if (childA.name === b.name) {
  2641. _mergeAttrs(childA, b.attr(), b.css());
  2642. merged = true;
  2643. }
  2644. childA = childA.first();
  2645. }
  2646. if (!merged) {
  2647. lastA.append(b.clone(false));
  2648. }
  2649. merged = false;
  2650. b = b.first();
  2651. }
  2652. return a;
  2653. }
  2654. function _wrapNode(knode, wrapper) {
  2655. wrapper = wrapper.clone(true);
  2656. if (knode.type == 3) {
  2657. _getInnerNode(wrapper).append(knode.clone(false));
  2658. knode.replaceWith(wrapper);
  2659. return wrapper;
  2660. }
  2661. var nodeWrapper = knode, child;
  2662. while ((child = knode.first()) && child.children().length == 1) {
  2663. knode = child;
  2664. }
  2665. child = knode.first();
  2666. var frag = knode.doc.createDocumentFragment();
  2667. while (child) {
  2668. frag.appendChild(child[0]);
  2669. child = child.next();
  2670. }
  2671. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2672. if (frag.firstChild) {
  2673. _getInnerNode(wrapper).append(frag);
  2674. }
  2675. nodeWrapper.replaceWith(wrapper);
  2676. return wrapper;
  2677. }
  2678. function _mergeAttrs(knode, attrs, styles) {
  2679. _each(attrs, function(key, val) {
  2680. if (key !== 'style') {
  2681. knode.attr(key, val);
  2682. }
  2683. });
  2684. _each(styles, function(key, val) {
  2685. knode.css(key, val);
  2686. });
  2687. }
  2688. function _inPreElement(knode) {
  2689. while (knode && knode.name != 'body') {
  2690. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2691. return true;
  2692. }
  2693. knode = knode.parent();
  2694. }
  2695. return false;
  2696. }
  2697. function KCmd(range) {
  2698. this.init(range);
  2699. }
  2700. _extend(KCmd, {
  2701. init : function(range) {
  2702. var self = this, doc = range.doc;
  2703. self.doc = doc;
  2704. self.win = _getWin(doc);
  2705. self.sel = _getSel(doc);
  2706. self.range = range;
  2707. },
  2708. selection : function(forceReset) {
  2709. var self = this, doc = self.doc, rng = _getRng(doc);
  2710. self.sel = _getSel(doc);
  2711. if (rng) {
  2712. self.range = _range(rng);
  2713. if (K(self.range.startContainer).name == 'html') {
  2714. self.range.selectNodeContents(doc.body).collapse(false);
  2715. }
  2716. return self;
  2717. }
  2718. if (forceReset) {
  2719. self.range.selectNodeContents(doc.body).collapse(false);
  2720. }
  2721. return self;
  2722. },
  2723. select : function(hasDummy) {
  2724. hasDummy = _undef(hasDummy, true);
  2725. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2726. sc = range.startContainer, so = range.startOffset,
  2727. ec = range.endContainer, eo = range.endOffset,
  2728. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2729. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2730. if (_IERANGE) {
  2731. var dummy = K('<span>&nbsp;</span>', doc);
  2732. range.insertNode(dummy[0]);
  2733. rng = doc.body.createTextRange();
  2734. try {
  2735. rng.moveToElementText(dummy[0]);
  2736. } catch(ex) {}
  2737. rng.collapse(false);
  2738. rng.select();
  2739. dummy.remove();
  2740. win.focus();
  2741. return self;
  2742. }
  2743. if (_WEBKIT) {
  2744. var children = sc.childNodes;
  2745. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2746. range.insertNode(doc.createTextNode('\u200B'));
  2747. hasU200b = true;
  2748. }
  2749. }
  2750. }
  2751. if (_IERANGE) {
  2752. try {
  2753. rng = range.get(true);
  2754. rng.select();
  2755. } catch(e) {}
  2756. } else {
  2757. if (hasU200b) {
  2758. range.collapse(false);
  2759. }
  2760. rng = range.get(true);
  2761. sel.removeAllRanges();
  2762. sel.addRange(rng);
  2763. if (doc !== document) {
  2764. var pos = K(rng.endContainer).pos();
  2765. win.scrollTo(pos.x, pos.y);
  2766. }
  2767. }
  2768. win.focus();
  2769. return self;
  2770. },
  2771. wrap : function(val) {
  2772. var self = this, doc = self.doc, range = self.range, wrapper;
  2773. wrapper = K(val, doc);
  2774. if (range.collapsed) {
  2775. range.shrink();
  2776. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2777. return self;
  2778. }
  2779. if (wrapper.isBlock()) {
  2780. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2781. while (child.first()) {
  2782. child = child.first();
  2783. }
  2784. child.append(range.extractContents());
  2785. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2786. return self;
  2787. }
  2788. range.enlarge();
  2789. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2790. K(ancestor).scan(function(node) {
  2791. if (!isStart && node == bookmark.start) {
  2792. isStart = true;
  2793. return;
  2794. }
  2795. if (isStart) {
  2796. if (node == bookmark.end) {
  2797. return false;
  2798. }
  2799. var knode = K(node);
  2800. if (_inPreElement(knode)) {
  2801. return;
  2802. }
  2803. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2804. var parent;
  2805. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2806. knode = parent;
  2807. }
  2808. _wrapNode(knode, wrapper);
  2809. }
  2810. }
  2811. });
  2812. range.moveToBookmark(bookmark);
  2813. return self;
  2814. },
  2815. split : function(isStart, map) {
  2816. var range = this.range, doc = range.doc;
  2817. var tempRange = range.cloneRange().collapse(isStart);
  2818. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2819. parent = node.nodeType == 3 ? node.parentNode : node,
  2820. needSplit = false, knode;
  2821. while (parent && parent.parentNode) {
  2822. knode = K(parent);
  2823. if (map) {
  2824. if (!knode.isStyle()) {
  2825. break;
  2826. }
  2827. if (!_hasAttrOrCss(knode, map)) {
  2828. break;
  2829. }
  2830. } else {
  2831. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2832. break;
  2833. }
  2834. }
  2835. needSplit = true;
  2836. parent = parent.parentNode;
  2837. }
  2838. if (needSplit) {
  2839. var dummy = doc.createElement('span');
  2840. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2841. if (isStart) {
  2842. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2843. } else {
  2844. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2845. }
  2846. var frag = tempRange.extractContents(),
  2847. first = frag.firstChild, last = frag.lastChild;
  2848. if (isStart) {
  2849. tempRange.insertNode(frag);
  2850. range.setStartAfter(last).setEndBefore(dummy);
  2851. } else {
  2852. parent.appendChild(frag);
  2853. range.setStartBefore(dummy).setEndBefore(first);
  2854. }
  2855. var dummyParent = dummy.parentNode;
  2856. if (dummyParent == range.endContainer) {
  2857. var prev = K(dummy).prev(), next = K(dummy).next();
  2858. if (prev && next && prev.type == 3 && next.type == 3) {
  2859. range.setEnd(prev[0], prev[0].nodeValue.length);
  2860. } else if (!isStart) {
  2861. range.setEnd(range.endContainer, range.endOffset - 1);
  2862. }
  2863. }
  2864. dummyParent.removeChild(dummy);
  2865. }
  2866. return this;
  2867. },
  2868. remove : function(map) {
  2869. var self = this, doc = self.doc, range = self.range;
  2870. range.enlarge();
  2871. if (range.startOffset === 0) {
  2872. var ksc = K(range.startContainer), parent;
  2873. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2874. ksc = parent;
  2875. }
  2876. range.setStart(ksc[0], 0);
  2877. ksc = K(range.startContainer);
  2878. if (ksc.isBlock()) {
  2879. _removeAttrOrCss(ksc, map);
  2880. }
  2881. var kscp = ksc.parent();
  2882. if (kscp && kscp.isBlock()) {
  2883. _removeAttrOrCss(kscp, map);
  2884. }
  2885. }
  2886. var sc, so;
  2887. if (range.collapsed) {
  2888. self.split(true, map);
  2889. sc = range.startContainer;
  2890. so = range.startOffset;
  2891. if (so > 0) {
  2892. var sb = K(sc.childNodes[so - 1]);
  2893. if (sb && _isEmptyNode(sb)) {
  2894. sb.remove();
  2895. range.setStart(sc, so - 1);
  2896. }
  2897. }
  2898. var sa = K(sc.childNodes[so]);
  2899. if (sa && _isEmptyNode(sa)) {
  2900. sa.remove();
  2901. }
  2902. if (_isEmptyNode(sc)) {
  2903. range.startBefore(sc);
  2904. sc.remove();
  2905. }
  2906. range.collapse(true);
  2907. return self;
  2908. }
  2909. self.split(true, map);
  2910. self.split(false, map);
  2911. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2912. range.cloneRange().collapse(false).insertNode(endDummy);
  2913. range.cloneRange().collapse(true).insertNode(startDummy);
  2914. var nodeList = [], cmpStart = false;
  2915. K(range.commonAncestor()).scan(function(node) {
  2916. if (!cmpStart && node == startDummy) {
  2917. cmpStart = true;
  2918. return;
  2919. }
  2920. if (node == endDummy) {
  2921. return false;
  2922. }
  2923. if (cmpStart) {
  2924. nodeList.push(node);
  2925. }
  2926. });
  2927. K(startDummy).remove();
  2928. K(endDummy).remove();
  2929. sc = range.startContainer;
  2930. so = range.startOffset;
  2931. var ec = range.endContainer, eo = range.endOffset;
  2932. if (so > 0) {
  2933. var startBefore = K(sc.childNodes[so - 1]);
  2934. if (startBefore && _isEmptyNode(startBefore)) {
  2935. startBefore.remove();
  2936. range.setStart(sc, so - 1);
  2937. if (sc == ec) {
  2938. range.setEnd(ec, eo - 1);
  2939. }
  2940. }
  2941. var startAfter = K(sc.childNodes[so]);
  2942. if (startAfter && _isEmptyNode(startAfter)) {
  2943. startAfter.remove();
  2944. if (sc == ec) {
  2945. range.setEnd(ec, eo - 1);
  2946. }
  2947. }
  2948. }
  2949. var endAfter = K(ec.childNodes[range.endOffset]);
  2950. if (endAfter && _isEmptyNode(endAfter)) {
  2951. endAfter.remove();
  2952. }
  2953. var bookmark = range.createBookmark(true);
  2954. _each(nodeList, function(i, node) {
  2955. _removeAttrOrCss(K(node), map);
  2956. });
  2957. range.moveToBookmark(bookmark);
  2958. return self;
  2959. },
  2960. commonNode : function(map) {
  2961. var range = this.range;
  2962. var ec = range.endContainer, eo = range.endOffset,
  2963. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2964. function find(node) {
  2965. var child = node, parent = node;
  2966. while (parent) {
  2967. if (_hasAttrOrCss(K(parent), map)) {
  2968. return K(parent);
  2969. }
  2970. parent = parent.parentNode;
  2971. }
  2972. while (child && (child = child.lastChild)) {
  2973. if (_hasAttrOrCss(K(child), map)) {
  2974. return K(child);
  2975. }
  2976. }
  2977. return null;
  2978. }
  2979. var cNode = find(node);
  2980. if (cNode) {
  2981. return cNode;
  2982. }
  2983. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2984. var prev = K(node).prev();
  2985. if (prev) {
  2986. return find(prev);
  2987. }
  2988. }
  2989. return null;
  2990. },
  2991. commonAncestor : function(tagName) {
  2992. var range = this.range,
  2993. sc = range.startContainer, so = range.startOffset,
  2994. ec = range.endContainer, eo = range.endOffset,
  2995. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2996. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2997. function find(node) {
  2998. while (node) {
  2999. if (node.nodeType == 1) {
  3000. if (node.tagName.toLowerCase() === tagName) {
  3001. return node;
  3002. }
  3003. }
  3004. node = node.parentNode;
  3005. }
  3006. return null;
  3007. }
  3008. var start = find(startNode), end = find(endNode);
  3009. if (start && end && start === end) {
  3010. return K(start);
  3011. }
  3012. return null;
  3013. },
  3014. state : function(key) {
  3015. var self = this, doc = self.doc, bool = false;
  3016. try {
  3017. bool = doc.queryCommandState(key);
  3018. } catch (e) {}
  3019. return bool;
  3020. },
  3021. val : function(key) {
  3022. var self = this, doc = self.doc, range = self.range;
  3023. function lc(val) {
  3024. return val.toLowerCase();
  3025. }
  3026. key = lc(key);
  3027. var val = '', knode;
  3028. if (key === 'fontfamily' || key === 'fontname') {
  3029. val = _nativeCommandValue(doc, 'fontname');
  3030. val = val.replace(/['"]/g, '');
  3031. return lc(val);
  3032. }
  3033. if (key === 'formatblock') {
  3034. val = _nativeCommandValue(doc, key);
  3035. if (val === '') {
  3036. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3037. if (knode) {
  3038. val = knode.name;
  3039. }
  3040. }
  3041. if (val === 'Normal') {
  3042. val = 'p';
  3043. }
  3044. return lc(val);
  3045. }
  3046. if (key === 'fontsize') {
  3047. knode = self.commonNode({'*' : '.font-size'});
  3048. if (knode) {
  3049. val = knode.css('font-size');
  3050. }
  3051. return lc(val);
  3052. }
  3053. if (key === 'forecolor') {
  3054. knode = self.commonNode({'*' : '.color'});
  3055. if (knode) {
  3056. val = knode.css('color');
  3057. }
  3058. val = _toHex(val);
  3059. if (val === '') {
  3060. val = 'default';
  3061. }
  3062. return lc(val);
  3063. }
  3064. if (key === 'hilitecolor') {
  3065. knode = self.commonNode({'*' : '.background-color'});
  3066. if (knode) {
  3067. val = knode.css('background-color');
  3068. }
  3069. val = _toHex(val);
  3070. if (val === '') {
  3071. val = 'default';
  3072. }
  3073. return lc(val);
  3074. }
  3075. return val;
  3076. },
  3077. toggle : function(wrapper, map) {
  3078. var self = this;
  3079. if (self.commonNode(map)) {
  3080. self.remove(map);
  3081. } else {
  3082. self.wrap(wrapper);
  3083. }
  3084. return self.select();
  3085. },
  3086. bold : function() {
  3087. return this.toggle('<strong></strong>', {
  3088. span : '.font-weight=bold',
  3089. strong : '*',
  3090. b : '*'
  3091. });
  3092. },
  3093. italic : function() {
  3094. return this.toggle('<em></em>', {
  3095. span : '.font-style=italic',
  3096. em : '*',
  3097. i : '*'
  3098. });
  3099. },
  3100. underline : function() {
  3101. return this.toggle('<u></u>', {
  3102. span : '.text-decoration=underline',
  3103. u : '*'
  3104. });
  3105. },
  3106. strikethrough : function() {
  3107. return this.toggle('<s></s>', {
  3108. span : '.text-decoration=line-through',
  3109. s : '*'
  3110. });
  3111. },
  3112. forecolor : function(val) {
  3113. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3114. },
  3115. hilitecolor : function(val) {
  3116. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3117. },
  3118. fontsize : function(val) {
  3119. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3120. },
  3121. fontname : function(val) {
  3122. return this.fontfamily(val);
  3123. },
  3124. fontfamily : function(val) {
  3125. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3126. },
  3127. removeformat : function() {
  3128. var map = {
  3129. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3130. },
  3131. tags = _STYLE_TAG_MAP;
  3132. _each(tags, function(key, val) {
  3133. map[key] = '*';
  3134. });
  3135. this.remove(map);
  3136. return this.select();
  3137. },
  3138. inserthtml : function(val, quickMode) {
  3139. var self = this, range = self.range;
  3140. if (val === '') {
  3141. return self;
  3142. }
  3143. function pasteHtml(range, val) {
  3144. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3145. var rng = range.get();
  3146. if (rng.item) {
  3147. rng.item(0).outerHTML = val;
  3148. } else {
  3149. rng.pasteHTML(val);
  3150. }
  3151. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3152. temp.parentNode.removeChild(temp);
  3153. var newRange = _toRange(rng);
  3154. range.setEnd(newRange.endContainer, newRange.endOffset);
  3155. range.collapse(false);
  3156. self.select(false);
  3157. }
  3158. function insertHtml(range, val) {
  3159. var doc = range.doc,
  3160. frag = doc.createDocumentFragment();
  3161. K('@' + val, doc).each(function() {
  3162. frag.appendChild(this);
  3163. });
  3164. range.deleteContents();
  3165. range.insertNode(frag);
  3166. range.collapse(false);
  3167. self.select(false);
  3168. }
  3169. if (_IERANGE && quickMode) {
  3170. try {
  3171. pasteHtml(range, val);
  3172. } catch(e) {
  3173. insertHtml(range, val);
  3174. }
  3175. return self;
  3176. }
  3177. insertHtml(range, val);
  3178. return self;
  3179. },
  3180. hr : function() {
  3181. return this.inserthtml('<hr />');
  3182. },
  3183. print : function() {
  3184. this.win.print();
  3185. return this;
  3186. },
  3187. insertimage : function(url, title, width, height, border, align) {
  3188. title = _undef(title, '');
  3189. border = _undef(border, 0);
  3190. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3191. if (width) {
  3192. html += 'width="' + _escape(width) + '" ';
  3193. }
  3194. if (height) {
  3195. html += 'height="' + _escape(height) + '" ';
  3196. }
  3197. if (title) {
  3198. html += 'title="' + _escape(title) + '" ';
  3199. }
  3200. if (align) {
  3201. html += 'align="' + _escape(align) + '" ';
  3202. }
  3203. html += 'alt="' + _escape(title) + '" ';
  3204. html += '/>';
  3205. return this.inserthtml(html);
  3206. },
  3207. createlink : function(url, type) {
  3208. var self = this, doc = self.doc, range = self.range;
  3209. self.select();
  3210. var a = self.commonNode({ a : '*' });
  3211. if (a && !range.isControl()) {
  3212. range.selectNode(a.get());
  3213. self.select();
  3214. }
  3215. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3216. if (type) {
  3217. html += ' target="' + _escape(type) + '"';
  3218. }
  3219. if (range.collapsed) {
  3220. html += '>' + _escape(url) + '</a>';
  3221. return self.inserthtml(html);
  3222. }
  3223. if (range.isControl()) {
  3224. var node = K(range.startContainer.childNodes[range.startOffset]);
  3225. html += '></a>';
  3226. node.after(K(html, doc));
  3227. node.next().append(node);
  3228. range.selectNode(node[0]);
  3229. return self.select();
  3230. }
  3231. function setAttr(node, url, type) {
  3232. K(node).attr('href', url).attr('data-ke-src', url);
  3233. if (type) {
  3234. K(node).attr('target', type);
  3235. } else {
  3236. K(node).removeAttr('target');
  3237. }
  3238. }
  3239. var sc = range.startContainer, so = range.startOffset,
  3240. ec = range.endContainer, eo = range.endOffset;
  3241. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3242. var child = sc.childNodes[so];
  3243. if (child.nodeName.toLowerCase() == 'a') {
  3244. setAttr(child, url, type);
  3245. return self;
  3246. }
  3247. }
  3248. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3249. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3250. setAttr(this, url, type);
  3251. });
  3252. return self;
  3253. },
  3254. unlink : function() {
  3255. var self = this, doc = self.doc, range = self.range;
  3256. self.select();
  3257. if (range.collapsed) {
  3258. var a = self.commonNode({ a : '*' });
  3259. if (a) {
  3260. range.selectNode(a.get());
  3261. self.select();
  3262. }
  3263. _nativeCommand(doc, 'unlink', null);
  3264. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3265. var parent = K(range.startContainer).parent();
  3266. if (parent.name === 'a') {
  3267. parent.remove(true);
  3268. }
  3269. }
  3270. } else {
  3271. _nativeCommand(doc, 'unlink', null);
  3272. }
  3273. return self;
  3274. }
  3275. });
  3276. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3277. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3278. KCmd.prototype[name] = function(val) {
  3279. var self = this;
  3280. self.select();
  3281. _nativeCommand(self.doc, name, val);
  3282. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3283. self.selection();
  3284. }
  3285. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3286. self.selection();
  3287. }
  3288. return self;
  3289. };
  3290. });
  3291. _each('cut,copy,paste'.split(','), function(i, name) {
  3292. KCmd.prototype[name] = function() {
  3293. var self = this;
  3294. if (!self.doc.queryCommandSupported(name)) {
  3295. throw 'not supported';
  3296. }
  3297. self.select();
  3298. _nativeCommand(self.doc, name, null);
  3299. return self;
  3300. };
  3301. });
  3302. function _cmd(mixed) {
  3303. if (mixed.nodeName) {
  3304. var doc = _getDoc(mixed);
  3305. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3306. }
  3307. return new KCmd(mixed);
  3308. }
  3309. K.CmdClass = KCmd;
  3310. K.cmd = _cmd;
  3311. function _drag(options) {
  3312. var moveEl = options.moveEl,
  3313. moveFn = options.moveFn,
  3314. clickEl = options.clickEl || moveEl,
  3315. beforeDrag = options.beforeDrag,
  3316. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3317. var docs = [document];
  3318. if (iframeFix) {
  3319. K('iframe').each(function() {
  3320. var src = _formatUrl(this.src || '', 'absolute');
  3321. if (/^https?:\/\//.test(src)) {
  3322. return;
  3323. }
  3324. var doc;
  3325. try {
  3326. doc = _iframeDoc(this);
  3327. } catch(e) {}
  3328. if (doc) {
  3329. var pos = K(this).pos();
  3330. K(doc).data('pos-x', pos.x);
  3331. K(doc).data('pos-y', pos.y);
  3332. docs.push(doc);
  3333. }
  3334. });
  3335. }
  3336. clickEl.mousedown(function(e) {
  3337. if(e.button !== 0 && e.button !== 1) {
  3338. return;
  3339. }
  3340. e.stopPropagation();
  3341. var self = clickEl.get(),
  3342. x = _removeUnit(moveEl.css('left')),
  3343. y = _removeUnit(moveEl.css('top')),
  3344. width = moveEl.width(),
  3345. height = moveEl.height(),
  3346. pageX = e.pageX,
  3347. pageY = e.pageY;
  3348. if (beforeDrag) {
  3349. beforeDrag();
  3350. }
  3351. function moveListener(e) {
  3352. e.preventDefault();
  3353. var kdoc = K(_getDoc(e.target));
  3354. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3355. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3356. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3357. }
  3358. function selectListener(e) {
  3359. e.preventDefault();
  3360. }
  3361. function upListener(e) {
  3362. e.preventDefault();
  3363. K(docs).unbind('mousemove', moveListener)
  3364. .unbind('mouseup', upListener)
  3365. .unbind('selectstart', selectListener);
  3366. if (self.releaseCapture) {
  3367. self.releaseCapture();
  3368. }
  3369. }
  3370. K(docs).mousemove(moveListener)
  3371. .mouseup(upListener)
  3372. .bind('selectstart', selectListener);
  3373. if (self.setCapture) {
  3374. self.setCapture();
  3375. }
  3376. });
  3377. }
  3378. function KWidget(options) {
  3379. this.init(options);
  3380. }
  3381. _extend(KWidget, {
  3382. init : function(options) {
  3383. var self = this;
  3384. self.name = options.name || '';
  3385. self.doc = options.doc || document;
  3386. self.win = _getWin(self.doc);
  3387. self.x = _addUnit(options.x);
  3388. self.y = _addUnit(options.y);
  3389. self.z = options.z;
  3390. self.width = _addUnit(options.width);
  3391. self.height = _addUnit(options.height);
  3392. self.div = K('<div style="display:block;"></div>');
  3393. self.options = options;
  3394. self._alignEl = options.alignEl;
  3395. if (self.width) {
  3396. self.div.css('width', self.width);
  3397. }
  3398. if (self.height) {
  3399. self.div.css('height', self.height);
  3400. }
  3401. if (self.z) {
  3402. self.div.css({
  3403. position : 'absolute',
  3404. left : self.x,
  3405. top : self.y,
  3406. 'z-index' : self.z
  3407. });
  3408. }
  3409. if (self.z && (self.x === undefined || self.y === undefined)) {
  3410. self.autoPos(self.width, self.height);
  3411. }
  3412. if (options.cls) {
  3413. self.div.addClass(options.cls);
  3414. }
  3415. if (options.shadowMode) {
  3416. self.div.addClass('ke-shadow');
  3417. }
  3418. if (options.css) {
  3419. self.div.css(options.css);
  3420. }
  3421. if (options.src) {
  3422. K(options.src).replaceWith(self.div);
  3423. } else {
  3424. K(self.doc.body).append(self.div);
  3425. }
  3426. if (options.html) {
  3427. self.div.html(options.html);
  3428. }
  3429. if (options.autoScroll) {
  3430. if (_IE && _V < 7 || _QUIRKS) {
  3431. var scrollPos = _getScrollPos();
  3432. K(self.win).bind('scroll', function(e) {
  3433. var pos = _getScrollPos(),
  3434. diffX = pos.x - scrollPos.x,
  3435. diffY = pos.y - scrollPos.y;
  3436. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3437. });
  3438. } else {
  3439. self.div.css('position', 'fixed');
  3440. }
  3441. }
  3442. },
  3443. pos : function(x, y, updateProp) {
  3444. var self = this;
  3445. updateProp = _undef(updateProp, true);
  3446. if (x !== null) {
  3447. x = x < 0 ? 0 : _addUnit(x);
  3448. self.div.css('left', x);
  3449. if (updateProp) {
  3450. self.x = x;
  3451. }
  3452. }
  3453. if (y !== null) {
  3454. y = y < 0 ? 0 : _addUnit(y);
  3455. self.div.css('top', y);
  3456. if (updateProp) {
  3457. self.y = y;
  3458. }
  3459. }
  3460. return self;
  3461. },
  3462. autoPos : function(width, height) {
  3463. var x, y, self = this,
  3464. w = _removeUnit(width) || 0,
  3465. h = _removeUnit(height) || 0,
  3466. scrollPos = _getScrollPos();
  3467. if (self._alignEl) {
  3468. var knode = K(self._alignEl),
  3469. pos = knode.pos(),
  3470. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3471. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3472. x = diffX < 0 ? pos.x : pos.x + diffX;
  3473. y = diffY < 0 ? pos.y : pos.y + diffY;
  3474. } else {
  3475. var docEl = _docElement(self.doc);
  3476. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3477. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3478. }
  3479. if (!(_IE && _V < 7 || _QUIRKS)) {
  3480. x -= scrollPos.x;
  3481. y -= scrollPos.y;
  3482. }
  3483. return self.pos(x, y);
  3484. },
  3485. remove : function() {
  3486. var self = this;
  3487. if (_IE && _V < 7 || _QUIRKS) {
  3488. K(self.win).unbind('scroll');
  3489. }
  3490. self.div.remove();
  3491. _each(self, function(i) {
  3492. self[i] = null;
  3493. });
  3494. return this;
  3495. },
  3496. show : function() {
  3497. this.div.show();
  3498. return this;
  3499. },
  3500. hide : function() {
  3501. this.div.hide();
  3502. return this;
  3503. },
  3504. draggable : function(options) {
  3505. var self = this;
  3506. options = options || {};
  3507. options.moveEl = self.div;
  3508. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3509. if ((x = x + diffX) < 0) {
  3510. x = 0;
  3511. }
  3512. if ((y = y + diffY) < 0) {
  3513. y = 0;
  3514. }
  3515. self.pos(x, y);
  3516. };
  3517. _drag(options);
  3518. return self;
  3519. }
  3520. });
  3521. function _widget(options) {
  3522. return new KWidget(options);
  3523. }
  3524. K.WidgetClass = KWidget;
  3525. K.widget = _widget;
  3526. function _iframeDoc(iframe) {
  3527. iframe = _get(iframe);
  3528. return iframe.contentDocument || iframe.contentWindow.document;
  3529. }
  3530. var html, _direction = '';
  3531. if ((html = document.getElementsByTagName('html'))) {
  3532. _direction = html[0].dir;
  3533. }
  3534. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3535. var arr = [
  3536. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3537. '<head><meta charset="utf-8" /><title></title>',
  3538. '<style>',
  3539. 'html {margin:0;padding:0;}',
  3540. 'body {margin:0;padding:5px;}',
  3541. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3542. 'body, p, div {word-wrap: break-word;}',
  3543. 'p {margin:5px 0;}',
  3544. 'table {border-collapse:collapse;}',
  3545. 'img {border:0;}',
  3546. 'noscript {display:none;}',
  3547. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3548. 'img.ke-flash {',
  3549. ' border:1px solid #AAA;',
  3550. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3551. ' background-position:center center;',
  3552. ' background-repeat:no-repeat;',
  3553. ' width:100px;',
  3554. ' height:100px;',
  3555. '}',
  3556. 'img.ke-rm {',
  3557. ' border:1px solid #AAA;',
  3558. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3559. ' background-position:center center;',
  3560. ' background-repeat:no-repeat;',
  3561. ' width:100px;',
  3562. ' height:100px;',
  3563. '}',
  3564. 'img.ke-media {',
  3565. ' border:1px solid #AAA;',
  3566. ' background-image:url(' + themesPath + 'common/media.gif);',
  3567. ' background-position:center center;',
  3568. ' background-repeat:no-repeat;',
  3569. ' width:100px;',
  3570. ' height:100px;',
  3571. '}',
  3572. 'img.ke-anchor {',
  3573. ' border:1px dashed #666;',
  3574. ' width:16px;',
  3575. ' height:16px;',
  3576. '}',
  3577. '.ke-script, .ke-noscript, .ke-display-none {',
  3578. ' display:none;',
  3579. ' font-size:0;',
  3580. ' width:0;',
  3581. ' height:0;',
  3582. '}',
  3583. '.ke-pagebreak {',
  3584. ' border:1px dotted #AAA;',
  3585. ' font-size:0;',
  3586. ' height:2px;',
  3587. '}',
  3588. '</style>'
  3589. ];
  3590. if (!_isArray(cssPath)) {
  3591. cssPath = [cssPath];
  3592. }
  3593. _each(cssPath, function(i, path) {
  3594. if (path) {
  3595. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3596. }
  3597. });
  3598. if (cssData) {
  3599. arr.push('<style>' + cssData + '</style>');
  3600. }
  3601. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3602. return arr.join('\n');
  3603. }
  3604. function _elementVal(knode, val) {
  3605. if (knode.hasVal()) {
  3606. if (val === undefined) {
  3607. var html = knode.val();
  3608. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3609. return html;
  3610. }
  3611. return knode.val(val);
  3612. }
  3613. return knode.html(val);
  3614. }
  3615. function KEdit(options) {
  3616. this.init(options);
  3617. }
  3618. _extend(KEdit, KWidget, {
  3619. init : function(options) {
  3620. var self = this;
  3621. KEdit.parent.init.call(self, options);
  3622. self.srcElement = K(options.srcElement);
  3623. self.div.addClass('ke-edit');
  3624. self.designMode = _undef(options.designMode, true);
  3625. self.beforeGetHtml = options.beforeGetHtml;
  3626. self.beforeSetHtml = options.beforeSetHtml;
  3627. self.afterSetHtml = options.afterSetHtml;
  3628. var themesPath = _undef(options.themesPath, ''),
  3629. bodyClass = options.bodyClass,
  3630. cssPath = options.cssPath,
  3631. cssData = options.cssData,
  3632. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3633. srcScript = ('document.open();' +
  3634. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3635. 'document.close();'),
  3636. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3637. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3638. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3639. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3640. self.iframe.attr('tabindex', self.tabIndex);
  3641. self.textarea.attr('tabindex', self.tabIndex);
  3642. if (self.width) {
  3643. self.setWidth(self.width);
  3644. }
  3645. if (self.height) {
  3646. self.setHeight(self.height);
  3647. }
  3648. if (self.designMode) {
  3649. self.textarea.hide();
  3650. } else {
  3651. self.iframe.hide();
  3652. }
  3653. function ready() {
  3654. var doc = _iframeDoc(self.iframe);
  3655. doc.open();
  3656. if (isDocumentDomain) {
  3657. doc.domain = document.domain;
  3658. }
  3659. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3660. doc.close();
  3661. self.win = self.iframe[0].contentWindow;
  3662. self.doc = doc;
  3663. var cmd = _cmd(doc);
  3664. self.afterChange(function(e) {
  3665. cmd.selection();
  3666. });
  3667. if (_WEBKIT) {
  3668. K(doc).click(function(e) {
  3669. if (K(e.target).name === 'img') {
  3670. cmd.selection(true);
  3671. cmd.range.selectNode(e.target);
  3672. cmd.select();
  3673. }
  3674. });
  3675. }
  3676. if (_IE) {
  3677. self._mousedownHandler = function() {
  3678. var newRange = cmd.range.cloneRange();
  3679. newRange.shrink();
  3680. if (newRange.isControl()) {
  3681. self.blur();
  3682. }
  3683. };
  3684. K(document).mousedown(self._mousedownHandler);
  3685. K(doc).keydown(function(e) {
  3686. if (e.which == 8) {
  3687. cmd.selection();
  3688. var rng = cmd.range;
  3689. if (rng.isControl()) {
  3690. rng.collapse(true);
  3691. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3692. e.preventDefault();
  3693. }
  3694. }
  3695. });
  3696. }
  3697. self.cmd = cmd;
  3698. self.html(_elementVal(self.srcElement));
  3699. if (_IE) {
  3700. doc.body.disabled = true;
  3701. doc.body.contentEditable = true;
  3702. doc.body.removeAttribute('disabled');
  3703. } else {
  3704. doc.designMode = 'on';
  3705. }
  3706. if (options.afterCreate) {
  3707. options.afterCreate.call(self);
  3708. }
  3709. }
  3710. if (isDocumentDomain) {
  3711. self.iframe.bind('load', function(e) {
  3712. self.iframe.unbind('load');
  3713. if (_IE) {
  3714. ready();
  3715. } else {
  3716. setTimeout(ready, 0);
  3717. }
  3718. });
  3719. }
  3720. self.div.append(self.iframe);
  3721. self.div.append(self.textarea);
  3722. self.srcElement.hide();
  3723. !isDocumentDomain && ready();
  3724. },
  3725. setWidth : function(val) {
  3726. var self = this;
  3727. val = _addUnit(val);
  3728. self.width = val;
  3729. self.div.css('width', val);
  3730. return self;
  3731. },
  3732. setHeight : function(val) {
  3733. var self = this;
  3734. val = _addUnit(val);
  3735. self.height = val;
  3736. self.div.css('height', val);
  3737. self.iframe.css('height', val);
  3738. if ((_IE && _V < 8) || _QUIRKS) {
  3739. val = _addUnit(_removeUnit(val) - 2);
  3740. }
  3741. self.textarea.css('height', val);
  3742. return self;
  3743. },
  3744. remove : function() {
  3745. var self = this, doc = self.doc;
  3746. K(doc.body).unbind();
  3747. K(doc).unbind();
  3748. K(self.win).unbind();
  3749. if (self._mousedownHandler) {
  3750. K(document).unbind('mousedown', self._mousedownHandler);
  3751. }
  3752. _elementVal(self.srcElement, self.html());
  3753. self.srcElement.show();
  3754. self.iframe.unbind();
  3755. self.textarea.unbind();
  3756. KEdit.parent.remove.call(self);
  3757. },
  3758. html : function(val, isFull) {
  3759. var self = this, doc = self.doc;
  3760. if (self.designMode) {
  3761. var body = doc.body;
  3762. if (val === undefined) {
  3763. if (isFull) {
  3764. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3765. } else {
  3766. val = body.innerHTML;
  3767. }
  3768. if (self.beforeGetHtml) {
  3769. val = self.beforeGetHtml(val);
  3770. }
  3771. if (_GECKO && val == '<br />') {
  3772. val = '';
  3773. }
  3774. return val;
  3775. }
  3776. if (self.beforeSetHtml) {
  3777. val = self.beforeSetHtml(val);
  3778. }
  3779. if (_IE && _V >= 9) {
  3780. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3781. }
  3782. K(body).html(val);
  3783. if (self.afterSetHtml) {
  3784. self.afterSetHtml();
  3785. }
  3786. return self;
  3787. }
  3788. if (val === undefined) {
  3789. return self.textarea.val();
  3790. }
  3791. self.textarea.val(val);
  3792. return self;
  3793. },
  3794. design : function(bool) {
  3795. var self = this, val;
  3796. if (bool === undefined ? !self.designMode : bool) {
  3797. if (!self.designMode) {
  3798. val = self.html();
  3799. self.designMode = true;
  3800. self.textarea.hide();
  3801. self.html(val);
  3802. var iframe = self.iframe;
  3803. var height = _removeUnit(self.height);
  3804. iframe.height(height - 2);
  3805. iframe.show();
  3806. setTimeout(function() {
  3807. iframe.height(height);
  3808. }, 0);
  3809. }
  3810. } else {
  3811. if (self.designMode) {
  3812. val = self.html();
  3813. self.designMode = false;
  3814. self.html(val);
  3815. self.iframe.hide();
  3816. self.textarea.show();
  3817. }
  3818. }
  3819. return self.focus();
  3820. },
  3821. focus : function() {
  3822. var self = this;
  3823. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3824. return self;
  3825. },
  3826. blur : function() {
  3827. var self = this;
  3828. if (_IE) {
  3829. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3830. self.div.append(input);
  3831. input[0].focus();
  3832. input.remove();
  3833. } else {
  3834. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3835. }
  3836. return self;
  3837. },
  3838. afterChange : function(fn) {
  3839. var self = this, doc = self.doc, body = doc.body;
  3840. K(doc).keyup(function(e) {
  3841. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3842. fn(e);
  3843. }
  3844. });
  3845. K(doc).mouseup(fn).contextmenu(fn);
  3846. K(self.win).blur(fn);
  3847. function timeoutHandler(e) {
  3848. setTimeout(function() {
  3849. fn(e);
  3850. }, 1);
  3851. }
  3852. K(body).bind('paste', timeoutHandler);
  3853. K(body).bind('cut', timeoutHandler);
  3854. return self;
  3855. }
  3856. });
  3857. function _edit(options) {
  3858. return new KEdit(options);
  3859. }
  3860. K.EditClass = KEdit;
  3861. K.edit = _edit;
  3862. K.iframeDoc = _iframeDoc;
  3863. function _selectToolbar(name, fn) {
  3864. var self = this,
  3865. knode = self.get(name);
  3866. if (knode) {
  3867. if (knode.hasClass('ke-disabled')) {
  3868. return;
  3869. }
  3870. fn(knode);
  3871. }
  3872. }
  3873. function KToolbar(options) {
  3874. this.init(options);
  3875. }
  3876. _extend(KToolbar, KWidget, {
  3877. init : function(options) {
  3878. var self = this;
  3879. KToolbar.parent.init.call(self, options);
  3880. self.disableMode = _undef(options.disableMode, false);
  3881. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3882. self._itemMap = {};
  3883. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3884. e.preventDefault();
  3885. }).attr('unselectable', 'on');
  3886. function find(target) {
  3887. var knode = K(target);
  3888. if (knode.hasClass('ke-outline')) {
  3889. return knode;
  3890. }
  3891. if (knode.hasClass('ke-toolbar-icon')) {
  3892. return knode.parent();
  3893. }
  3894. }
  3895. function hover(e, method) {
  3896. var knode = find(e.target);
  3897. if (knode) {
  3898. if (knode.hasClass('ke-disabled')) {
  3899. return;
  3900. }
  3901. if (knode.hasClass('ke-selected')) {
  3902. return;
  3903. }
  3904. knode[method]('ke-on');
  3905. }
  3906. }
  3907. self.div.mouseover(function(e) {
  3908. hover(e, 'addClass');
  3909. })
  3910. .mouseout(function(e) {
  3911. hover(e, 'removeClass');
  3912. })
  3913. .click(function(e) {
  3914. var knode = find(e.target);
  3915. if (knode) {
  3916. if (knode.hasClass('ke-disabled')) {
  3917. return;
  3918. }
  3919. self.options.click.call(this, e, knode.attr('data-name'));
  3920. }
  3921. });
  3922. },
  3923. get : function(name) {
  3924. if (this._itemMap[name]) {
  3925. return this._itemMap[name];
  3926. }
  3927. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3928. },
  3929. select : function(name) {
  3930. _selectToolbar.call(this, name, function(knode) {
  3931. knode.addClass('ke-selected');
  3932. });
  3933. return self;
  3934. },
  3935. unselect : function(name) {
  3936. _selectToolbar.call(this, name, function(knode) {
  3937. knode.removeClass('ke-selected').removeClass('ke-on');
  3938. });
  3939. return self;
  3940. },
  3941. enable : function(name) {
  3942. var self = this,
  3943. knode = name.get ? name : self.get(name);
  3944. if (knode) {
  3945. knode.removeClass('ke-disabled');
  3946. knode.opacity(1);
  3947. }
  3948. return self;
  3949. },
  3950. disable : function(name) {
  3951. var self = this,
  3952. knode = name.get ? name : self.get(name);
  3953. if (knode) {
  3954. knode.removeClass('ke-selected').addClass('ke-disabled');
  3955. knode.opacity(0.5);
  3956. }
  3957. return self;
  3958. },
  3959. disableAll : function(bool, noDisableItems) {
  3960. var self = this, map = self.noDisableItemMap, item;
  3961. if (noDisableItems) {
  3962. map = _toMap(noDisableItems);
  3963. }
  3964. if (bool === undefined ? !self.disableMode : bool) {
  3965. K('span.ke-outline', self.div).each(function() {
  3966. var knode = K(this),
  3967. name = knode[0].getAttribute('data-name', 2);
  3968. if (!map[name]) {
  3969. self.disable(knode);
  3970. }
  3971. });
  3972. self.disableMode = true;
  3973. } else {
  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.enable(knode);
  3979. }
  3980. });
  3981. self.disableMode = false;
  3982. }
  3983. return self;
  3984. }
  3985. });
  3986. function _toolbar(options) {
  3987. return new KToolbar(options);
  3988. }
  3989. K.ToolbarClass = KToolbar;
  3990. K.toolbar = _toolbar;
  3991. function KMenu(options) {
  3992. this.init(options);
  3993. }
  3994. _extend(KMenu, KWidget, {
  3995. init : function(options) {
  3996. var self = this;
  3997. options.z = options.z || 811213;
  3998. KMenu.parent.init.call(self, options);
  3999. self.centerLineMode = _undef(options.centerLineMode, true);
  4000. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4001. e.stopPropagation();
  4002. }).attr('unselectable', 'on');
  4003. },
  4004. addItem : function(item) {
  4005. var self = this;
  4006. if (item.title === '-') {
  4007. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4008. return;
  4009. }
  4010. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4011. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4012. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4013. height = _addUnit(item.height),
  4014. iconClass = _undef(item.iconClass, '');
  4015. self.div.append(itemDiv);
  4016. if (height) {
  4017. itemDiv.css('height', height);
  4018. rightDiv.css('line-height', height);
  4019. }
  4020. var centerDiv;
  4021. if (self.centerLineMode) {
  4022. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4023. if (height) {
  4024. centerDiv.css('height', height);
  4025. }
  4026. }
  4027. itemDiv.mouseover(function(e) {
  4028. K(this).addClass('ke-menu-item-on');
  4029. if (centerDiv) {
  4030. centerDiv.addClass('ke-menu-item-center-on');
  4031. }
  4032. })
  4033. .mouseout(function(e) {
  4034. K(this).removeClass('ke-menu-item-on');
  4035. if (centerDiv) {
  4036. centerDiv.removeClass('ke-menu-item-center-on');
  4037. }
  4038. })
  4039. .click(function(e) {
  4040. item.click.call(K(this));
  4041. e.stopPropagation();
  4042. })
  4043. .append(leftDiv);
  4044. if (centerDiv) {
  4045. itemDiv.append(centerDiv);
  4046. }
  4047. itemDiv.append(rightDiv);
  4048. if (item.checked) {
  4049. iconClass = 'ke-icon-checked';
  4050. }
  4051. if (iconClass !== '') {
  4052. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4053. }
  4054. rightDiv.html(item.title);
  4055. return self;
  4056. },
  4057. remove : function() {
  4058. var self = this;
  4059. if (self.options.beforeRemove) {
  4060. self.options.beforeRemove.call(self);
  4061. }
  4062. K('.ke-menu-item', self.div[0]).unbind();
  4063. KMenu.parent.remove.call(self);
  4064. return self;
  4065. }
  4066. });
  4067. function _menu(options) {
  4068. return new KMenu(options);
  4069. }
  4070. K.MenuClass = KMenu;
  4071. K.menu = _menu;
  4072. function KColorPicker(options) {
  4073. this.init(options);
  4074. }
  4075. _extend(KColorPicker, KWidget, {
  4076. init : function(options) {
  4077. var self = this;
  4078. options.z = options.z || 811213;
  4079. KColorPicker.parent.init.call(self, options);
  4080. var colors = options.colors || [
  4081. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4082. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4083. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4084. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4085. ];
  4086. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4087. self._cells = [];
  4088. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4089. e.stopPropagation();
  4090. }).attr('unselectable', 'on');
  4091. var table = self.doc.createElement('table');
  4092. self.div.append(table);
  4093. table.className = 'ke-colorpicker-table';
  4094. table.cellPadding = 0;
  4095. table.cellSpacing = 0;
  4096. table.border = 0;
  4097. var row = table.insertRow(0), cell = row.insertCell(0);
  4098. cell.colSpan = colors[0].length;
  4099. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4100. for (var i = 0; i < colors.length; i++) {
  4101. row = table.insertRow(i + 1);
  4102. for (var j = 0; j < colors[i].length; j++) {
  4103. cell = row.insertCell(j);
  4104. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4105. }
  4106. }
  4107. },
  4108. _addAttr : function(cell, color, cls) {
  4109. var self = this;
  4110. cell = K(cell).addClass(cls);
  4111. if (self.selectedColor === color.toLowerCase()) {
  4112. cell.addClass('ke-colorpicker-cell-selected');
  4113. }
  4114. cell.attr('title', color || self.options.noColor);
  4115. cell.mouseover(function(e) {
  4116. K(this).addClass('ke-colorpicker-cell-on');
  4117. });
  4118. cell.mouseout(function(e) {
  4119. K(this).removeClass('ke-colorpicker-cell-on');
  4120. });
  4121. cell.click(function(e) {
  4122. e.stop();
  4123. self.options.click.call(K(this), color);
  4124. });
  4125. if (color) {
  4126. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4127. } else {
  4128. cell.html(self.options.noColor);
  4129. }
  4130. K(cell).attr('unselectable', 'on');
  4131. self._cells.push(cell);
  4132. },
  4133. remove : function() {
  4134. var self = this;
  4135. _each(self._cells, function() {
  4136. this.unbind();
  4137. });
  4138. KColorPicker.parent.remove.call(self);
  4139. return self;
  4140. }
  4141. });
  4142. function _colorpicker(options) {
  4143. return new KColorPicker(options);
  4144. }
  4145. K.ColorPickerClass = KColorPicker;
  4146. K.colorpicker = _colorpicker;
  4147. function KUploadButton(options) {
  4148. this.init(options);
  4149. }
  4150. _extend(KUploadButton, {
  4151. init : function(options) {
  4152. var self = this,
  4153. button = K(options.button),
  4154. fieldName = options.fieldName || 'file',
  4155. url = options.url || '',
  4156. title = button.val(),
  4157. extraParams = options.extraParams || {},
  4158. cls = button[0].className || '',
  4159. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4160. options.afterError = options.afterError || function(str) {
  4161. alert(str);
  4162. };
  4163. var hiddenElements = [];
  4164. for(var k in extraParams){
  4165. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4166. }
  4167. var html = [
  4168. '<div class="ke-inline-block ' + cls + '">',
  4169. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4170. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4171. '<span class="ke-button-common">',
  4172. hiddenElements.join(''),
  4173. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4174. '</span>',
  4175. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4176. (options.form ? '</div>' : '</form>'),
  4177. '</div>'].join('');
  4178. var div = K(html, button.doc);
  4179. button.hide();
  4180. button.before(div);
  4181. self.div = div;
  4182. self.button = button;
  4183. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4184. self.form = options.form ? K(options.form) : K('form', div);
  4185. self.fileBox = K('.ke-upload-file', div);
  4186. var width = options.width || K('.ke-button-common', div).width();
  4187. K('.ke-upload-area', div).width(width);
  4188. self.options = options;
  4189. },
  4190. submit : function() {
  4191. var self = this,
  4192. iframe = self.iframe;
  4193. iframe.bind('load', function() {
  4194. iframe.unbind();
  4195. var tempForm = document.createElement('form');
  4196. self.fileBox.before(tempForm);
  4197. K(tempForm).append(self.fileBox);
  4198. tempForm.reset();
  4199. K(tempForm).remove(true);
  4200. var doc = K.iframeDoc(iframe),
  4201. pre = doc.getElementsByTagName('pre')[0],
  4202. str = '', data;
  4203. if (pre) {
  4204. str = pre.innerHTML;
  4205. } else {
  4206. str = doc.body.innerHTML;
  4207. }
  4208. str = _unescape(str);
  4209. iframe[0].src = 'javascript:false';
  4210. try {
  4211. data = K.json(str);
  4212. } catch (e) {
  4213. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4214. }
  4215. if (data) {
  4216. self.options.afterUpload.call(self, data);
  4217. }
  4218. });
  4219. self.form[0].submit();
  4220. return self;
  4221. },
  4222. remove : function() {
  4223. var self = this;
  4224. if (self.fileBox) {
  4225. self.fileBox.unbind();
  4226. }
  4227. self.iframe.remove();
  4228. self.div.remove();
  4229. self.button.show();
  4230. return self;
  4231. }
  4232. });
  4233. function _uploadbutton(options) {
  4234. return new KUploadButton(options);
  4235. }
  4236. K.UploadButtonClass = KUploadButton;
  4237. K.uploadbutton = _uploadbutton;
  4238. function _createButton(arg) {
  4239. arg = arg || {};
  4240. var name = arg.name || '',
  4241. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4242. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4243. if (arg.click) {
  4244. btn.click(arg.click);
  4245. }
  4246. span.append(btn);
  4247. return span;
  4248. }
  4249. function KDialog(options) {
  4250. this.init(options);
  4251. }
  4252. _extend(KDialog, KWidget, {
  4253. init : function(options) {
  4254. var self = this;
  4255. var shadowMode = _undef(options.shadowMode, true);
  4256. options.z = options.z || 811213;
  4257. options.shadowMode = false;
  4258. options.autoScroll = _undef(options.autoScroll, true);
  4259. KDialog.parent.init.call(self, options);
  4260. var title = options.title,
  4261. body = K(options.body, self.doc),
  4262. previewBtn = options.previewBtn,
  4263. yesBtn = options.yesBtn,
  4264. noBtn = options.noBtn,
  4265. closeBtn = options.closeBtn,
  4266. showMask = _undef(options.showMask, true);
  4267. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4268. e.stopPropagation();
  4269. });
  4270. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4271. if (_IE && _V < 7) {
  4272. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4273. } else if (shadowMode) {
  4274. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4275. }
  4276. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4277. contentDiv.append(headerDiv);
  4278. headerDiv.html(title);
  4279. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4280. headerDiv.append(self.closeIcon);
  4281. self.draggable({
  4282. clickEl : headerDiv,
  4283. beforeDrag : options.beforeDrag
  4284. });
  4285. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4286. contentDiv.append(bodyDiv);
  4287. bodyDiv.append(body);
  4288. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4289. if (previewBtn || yesBtn || noBtn) {
  4290. contentDiv.append(footerDiv);
  4291. }
  4292. _each([
  4293. { btn : previewBtn, name : 'preview' },
  4294. { btn : yesBtn, name : 'yes' },
  4295. { btn : noBtn, name : 'no' }
  4296. ], function() {
  4297. if (this.btn) {
  4298. var button = _createButton(this.btn);
  4299. button.addClass('ke-dialog-' + this.name);
  4300. footerDiv.append(button);
  4301. }
  4302. });
  4303. if (self.height) {
  4304. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4305. }
  4306. self.div.width(self.div.width());
  4307. self.div.height(self.div.height());
  4308. self.mask = null;
  4309. if (showMask) {
  4310. var docEl = _docElement(self.doc),
  4311. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4312. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4313. self.mask = _widget({
  4314. x : 0,
  4315. y : 0,
  4316. z : self.z - 1,
  4317. cls : 'ke-dialog-mask',
  4318. width : docWidth,
  4319. height : docHeight
  4320. });
  4321. }
  4322. self.autoPos(self.div.width(), self.div.height());
  4323. self.footerDiv = footerDiv;
  4324. self.bodyDiv = bodyDiv;
  4325. self.headerDiv = headerDiv;
  4326. self.isLoading = false;
  4327. },
  4328. setMaskIndex : function(z) {
  4329. var self = this;
  4330. self.mask.div.css('z-index', z);
  4331. },
  4332. showLoading : function(msg) {
  4333. msg = _undef(msg, '');
  4334. var self = this, body = self.bodyDiv;
  4335. 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>')
  4336. .width(body.width()).height(body.height())
  4337. .css('top', self.headerDiv.height() + 'px');
  4338. body.css('visibility', 'hidden').after(self.loading);
  4339. self.isLoading = true;
  4340. return self;
  4341. },
  4342. hideLoading : function() {
  4343. this.loading && this.loading.remove();
  4344. this.bodyDiv.css('visibility', 'visible');
  4345. this.isLoading = false;
  4346. return this;
  4347. },
  4348. remove : function() {
  4349. var self = this;
  4350. if (self.options.beforeRemove) {
  4351. self.options.beforeRemove.call(self);
  4352. }
  4353. self.mask && self.mask.remove();
  4354. self.iframeMask && self.iframeMask.remove();
  4355. self.closeIcon.unbind();
  4356. K('input', self.div).unbind();
  4357. K('button', self.div).unbind();
  4358. self.footerDiv.unbind();
  4359. self.bodyDiv.unbind();
  4360. self.headerDiv.unbind();
  4361. K('iframe', self.div).each(function() {
  4362. K(this).remove();
  4363. });
  4364. KDialog.parent.remove.call(self);
  4365. return self;
  4366. }
  4367. });
  4368. function _dialog(options) {
  4369. return new KDialog(options);
  4370. }
  4371. K.DialogClass = KDialog;
  4372. K.dialog = _dialog;
  4373. function _tabs(options) {
  4374. var self = _widget(options),
  4375. remove = self.remove,
  4376. afterSelect = options.afterSelect,
  4377. div = self.div,
  4378. liList = [];
  4379. div.addClass('ke-tabs')
  4380. .bind('contextmenu,mousedown,mousemove', function(e) {
  4381. e.preventDefault();
  4382. });
  4383. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4384. div.append(ul);
  4385. self.add = function(tab) {
  4386. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4387. li.data('tab', tab);
  4388. liList.push(li);
  4389. ul.append(li);
  4390. };
  4391. self.selectedIndex = 0;
  4392. self.select = function(index) {
  4393. self.selectedIndex = index;
  4394. _each(liList, function(i, li) {
  4395. li.unbind();
  4396. if (i === index) {
  4397. li.addClass('ke-tabs-li-selected');
  4398. K(li.data('tab').panel).show('');
  4399. } else {
  4400. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4401. .mouseover(function() {
  4402. K(this).addClass('ke-tabs-li-on');
  4403. })
  4404. .mouseout(function() {
  4405. K(this).removeClass('ke-tabs-li-on');
  4406. })
  4407. .click(function() {
  4408. self.select(i);
  4409. });
  4410. K(li.data('tab').panel).hide();
  4411. }
  4412. });
  4413. if (afterSelect) {
  4414. afterSelect.call(self, index);
  4415. }
  4416. };
  4417. self.remove = function() {
  4418. _each(liList, function() {
  4419. this.remove();
  4420. });
  4421. ul.remove();
  4422. remove.call(self);
  4423. };
  4424. return self;
  4425. }
  4426. K.tabs = _tabs;
  4427. function _loadScript(url, fn) {
  4428. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4429. script = document.createElement('script');
  4430. head.appendChild(script);
  4431. script.src = url;
  4432. script.charset = 'utf-8';
  4433. script.onload = script.onreadystatechange = function() {
  4434. if (!this.readyState || this.readyState === 'loaded') {
  4435. if (fn) {
  4436. fn();
  4437. }
  4438. script.onload = script.onreadystatechange = null;
  4439. head.removeChild(script);
  4440. }
  4441. };
  4442. }
  4443. function _chopQuery(url) {
  4444. var index = url.indexOf('?');
  4445. return index > 0 ? url.substr(0, index) : url;
  4446. }
  4447. function _loadStyle(url) {
  4448. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4449. link = document.createElement('link'),
  4450. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4451. var links = K('link[rel="stylesheet"]', head);
  4452. for (var i = 0, len = links.length; i < len; i++) {
  4453. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4454. return;
  4455. }
  4456. }
  4457. head.appendChild(link);
  4458. link.href = url;
  4459. link.rel = 'stylesheet';
  4460. }
  4461. function _ajax(url, fn, method, param, dataType) {
  4462. method = method || 'GET';
  4463. dataType = dataType || 'json';
  4464. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4465. xhr.open(method, url, true);
  4466. xhr.onreadystatechange = function () {
  4467. if (xhr.readyState == 4 && xhr.status == 200) {
  4468. if (fn) {
  4469. var data = _trim(xhr.responseText);
  4470. if (dataType == 'json') {
  4471. data = _json(data);
  4472. }
  4473. fn(data);
  4474. }
  4475. }
  4476. };
  4477. if (method == 'POST') {
  4478. var params = [];
  4479. _each(param, function(key, val) {
  4480. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4481. });
  4482. try {
  4483. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4484. } catch (e) {}
  4485. xhr.send(params.join('&'));
  4486. } else {
  4487. xhr.send(null);
  4488. }
  4489. }
  4490. K.loadScript = _loadScript;
  4491. K.loadStyle = _loadStyle;
  4492. K.ajax = _ajax;
  4493. var _plugins = {};
  4494. function _plugin(name, fn) {
  4495. if (name === undefined) {
  4496. return _plugins;
  4497. }
  4498. if (!fn) {
  4499. return _plugins[name];
  4500. }
  4501. _plugins[name] = fn;
  4502. }
  4503. var _language = {};
  4504. function _parseLangKey(key) {
  4505. var match, ns = 'core';
  4506. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4507. ns = match[1];
  4508. key = match[2];
  4509. }
  4510. return { ns : ns, key : key };
  4511. }
  4512. function _lang(mixed, langType) {
  4513. langType = langType === undefined ? K.options.langType : langType;
  4514. if (typeof mixed === 'string') {
  4515. if (!_language[langType]) {
  4516. return 'no language';
  4517. }
  4518. var pos = mixed.length - 1;
  4519. if (mixed.substr(pos) === '.') {
  4520. return _language[langType][mixed.substr(0, pos)];
  4521. }
  4522. var obj = _parseLangKey(mixed);
  4523. return _language[langType][obj.ns][obj.key];
  4524. }
  4525. _each(mixed, function(key, val) {
  4526. var obj = _parseLangKey(key);
  4527. if (!_language[langType]) {
  4528. _language[langType] = {};
  4529. }
  4530. if (!_language[langType][obj.ns]) {
  4531. _language[langType][obj.ns] = {};
  4532. }
  4533. _language[langType][obj.ns][obj.key] = val;
  4534. });
  4535. }
  4536. function _getImageFromRange(range, fn) {
  4537. if (range.collapsed) {
  4538. return;
  4539. }
  4540. range = range.cloneRange().up();
  4541. var sc = range.startContainer, so = range.startOffset;
  4542. if (!_WEBKIT && !range.isControl()) {
  4543. return;
  4544. }
  4545. var img = K(sc.childNodes[so]);
  4546. if (!img || img.name != 'img') {
  4547. return;
  4548. }
  4549. if (fn(img)) {
  4550. return img;
  4551. }
  4552. }
  4553. function _bindContextmenuEvent() {
  4554. var self = this, doc = self.edit.doc;
  4555. K(doc).contextmenu(function(e) {
  4556. if (self.menu) {
  4557. self.hideMenu();
  4558. }
  4559. if (!self.useContextmenu) {
  4560. e.preventDefault();
  4561. return;
  4562. }
  4563. if (self._contextmenus.length === 0) {
  4564. return;
  4565. }
  4566. var maxWidth = 0, items = [];
  4567. _each(self._contextmenus, function() {
  4568. if (this.title == '-') {
  4569. items.push(this);
  4570. return;
  4571. }
  4572. if (this.cond && this.cond()) {
  4573. items.push(this);
  4574. if (this.width && this.width > maxWidth) {
  4575. maxWidth = this.width;
  4576. }
  4577. }
  4578. });
  4579. while (items.length > 0 && items[0].title == '-') {
  4580. items.shift();
  4581. }
  4582. while (items.length > 0 && items[items.length - 1].title == '-') {
  4583. items.pop();
  4584. }
  4585. var prevItem = null;
  4586. _each(items, function(i) {
  4587. if (this.title == '-' && prevItem.title == '-') {
  4588. delete items[i];
  4589. }
  4590. prevItem = this;
  4591. });
  4592. if (items.length > 0) {
  4593. e.preventDefault();
  4594. var pos = K(self.edit.iframe).pos(),
  4595. menu = _menu({
  4596. x : pos.x + e.clientX,
  4597. y : pos.y + e.clientY,
  4598. width : maxWidth,
  4599. css : { visibility: 'hidden' },
  4600. shadowMode : self.shadowMode
  4601. });
  4602. _each(items, function() {
  4603. if (this.title) {
  4604. menu.addItem(this);
  4605. }
  4606. });
  4607. var docEl = _docElement(menu.doc),
  4608. menuHeight = menu.div.height();
  4609. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4610. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4611. }
  4612. menu.div.css('visibility', 'visible');
  4613. self.menu = menu;
  4614. }
  4615. });
  4616. }
  4617. function _bindNewlineEvent() {
  4618. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4619. if (_IE && newlineTag !== 'br') {
  4620. return;
  4621. }
  4622. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4623. return;
  4624. }
  4625. if (_OPERA && _V < 9) {
  4626. return;
  4627. }
  4628. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4629. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4630. function getAncestorTagName(range) {
  4631. var ancestor = K(range.commonAncestor());
  4632. while (ancestor) {
  4633. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4634. break;
  4635. }
  4636. ancestor = ancestor.parent();
  4637. }
  4638. return ancestor.name;
  4639. }
  4640. K(doc).keydown(function(e) {
  4641. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4642. return;
  4643. }
  4644. self.cmd.selection();
  4645. var tagName = getAncestorTagName(self.cmd.range);
  4646. if (tagName == 'marquee' || tagName == 'select') {
  4647. return;
  4648. }
  4649. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4650. e.preventDefault();
  4651. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4652. return;
  4653. }
  4654. if (!pSkipTagMap[tagName]) {
  4655. _nativeCommand(doc, 'formatblock', '<p>');
  4656. }
  4657. });
  4658. K(doc).keyup(function(e) {
  4659. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4660. return;
  4661. }
  4662. if (newlineTag == 'br') {
  4663. return;
  4664. }
  4665. if (_GECKO) {
  4666. var root = self.cmd.commonAncestor('p');
  4667. var a = self.cmd.commonAncestor('a');
  4668. if (a && a.text() == '') {
  4669. a.remove(true);
  4670. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4671. self.cmd.select();
  4672. }
  4673. return;
  4674. }
  4675. self.cmd.selection();
  4676. var tagName = getAncestorTagName(self.cmd.range);
  4677. if (tagName == 'marquee' || tagName == 'select') {
  4678. return;
  4679. }
  4680. if (!pSkipTagMap[tagName]) {
  4681. _nativeCommand(doc, 'formatblock', '<p>');
  4682. }
  4683. var div = self.cmd.commonAncestor('div');
  4684. if (div) {
  4685. var p = K('<p></p>'),
  4686. child = div[0].firstChild;
  4687. while (child) {
  4688. var next = child.nextSibling;
  4689. p.append(child);
  4690. child = next;
  4691. }
  4692. div.before(p);
  4693. div.remove();
  4694. self.cmd.range.selectNodeContents(p[0]);
  4695. self.cmd.select();
  4696. }
  4697. });
  4698. }
  4699. function _bindTabEvent() {
  4700. var self = this, doc = self.edit.doc;
  4701. K(doc).keydown(function(e) {
  4702. if (e.which == 9) {
  4703. e.preventDefault();
  4704. if (self.afterTab) {
  4705. self.afterTab.call(self, e);
  4706. return;
  4707. }
  4708. var cmd = self.cmd, range = cmd.range;
  4709. range.shrink();
  4710. if (range.collapsed && range.startContainer.nodeType == 1) {
  4711. range.insertNode(K('@&nbsp;', doc)[0]);
  4712. cmd.select();
  4713. }
  4714. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4715. }
  4716. });
  4717. }
  4718. function _bindFocusEvent() {
  4719. var self = this;
  4720. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4721. if (self.afterFocus) {
  4722. self.afterFocus.call(self, e);
  4723. }
  4724. }).blur(function(e) {
  4725. if (self.afterBlur) {
  4726. self.afterBlur.call(self, e);
  4727. }
  4728. });
  4729. }
  4730. function _removeBookmarkTag(html) {
  4731. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4732. }
  4733. function _removeTempTag(html) {
  4734. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4735. }
  4736. function _addBookmarkToStack(stack, bookmark) {
  4737. if (stack.length === 0) {
  4738. stack.push(bookmark);
  4739. return;
  4740. }
  4741. var prev = stack[stack.length - 1];
  4742. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4743. stack.push(bookmark);
  4744. }
  4745. }
  4746. function _undoToRedo(fromStack, toStack) {
  4747. var self = this, edit = self.edit,
  4748. body = edit.doc.body,
  4749. range, bookmark;
  4750. if (fromStack.length === 0) {
  4751. return self;
  4752. }
  4753. if (edit.designMode) {
  4754. range = self.cmd.range;
  4755. bookmark = range.createBookmark(true);
  4756. bookmark.html = body.innerHTML;
  4757. } else {
  4758. bookmark = {
  4759. html : body.innerHTML
  4760. };
  4761. }
  4762. _addBookmarkToStack(toStack, bookmark);
  4763. var prev = fromStack.pop();
  4764. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4765. prev = fromStack.pop();
  4766. }
  4767. if (edit.designMode) {
  4768. edit.html(prev.html);
  4769. if (prev.start) {
  4770. range.moveToBookmark(prev);
  4771. self.select();
  4772. }
  4773. } else {
  4774. K(body).html(_removeBookmarkTag(prev.html));
  4775. }
  4776. return self;
  4777. }
  4778. function KEditor(options) {
  4779. var self = this;
  4780. self.options = {};
  4781. function setOption(key, val) {
  4782. if (KEditor.prototype[key] === undefined) {
  4783. self[key] = val;
  4784. }
  4785. self.options[key] = val;
  4786. }
  4787. _each(options, function(key, val) {
  4788. setOption(key, options[key]);
  4789. });
  4790. _each(K.options, function(key, val) {
  4791. if (self[key] === undefined) {
  4792. setOption(key, val);
  4793. }
  4794. });
  4795. var se = K(self.srcElement || '<textarea/>');
  4796. if (!self.width) {
  4797. self.width = se[0].style.width || se.width();
  4798. }
  4799. if (!self.height) {
  4800. self.height = se[0].style.height || se.height();
  4801. }
  4802. setOption('width', _undef(self.width, self.minWidth));
  4803. setOption('height', _undef(self.height, self.minHeight));
  4804. setOption('width', _addUnit(self.width));
  4805. setOption('height', _addUnit(self.height));
  4806. if (_MOBILE && (!_IOS || _V < 534)) {
  4807. self.designMode = false;
  4808. }
  4809. self.srcElement = se;
  4810. self.initContent = '';
  4811. self.plugin = {};
  4812. self.isCreated = false;
  4813. self._handlers = {};
  4814. self._contextmenus = [];
  4815. self._undoStack = [];
  4816. self._redoStack = [];
  4817. self._firstAddBookmark = true;
  4818. self.menu = self.contextmenu = null;
  4819. self.dialogs = [];
  4820. }
  4821. KEditor.prototype = {
  4822. lang : function(mixed) {
  4823. return _lang(mixed, this.langType);
  4824. },
  4825. loadPlugin : function(name, fn) {
  4826. var self = this;
  4827. var _pluginStatus = this._pluginStatus;
  4828. if (!_pluginStatus) {
  4829. _pluginStatus = this._pluginStatus = {};
  4830. }
  4831. if (_plugins[name]) {
  4832. if (!_isFunction(_plugins[name])) {
  4833. setTimeout(function() {
  4834. self.loadPlugin(name, fn);
  4835. }, 100);
  4836. return self;
  4837. }
  4838. if(!_pluginStatus[name]) {
  4839. _plugins[name].call(self, KindEditor);
  4840. _pluginStatus[name] = 'inited';
  4841. }
  4842. if (fn) {
  4843. fn.call(self);
  4844. }
  4845. return self;
  4846. }
  4847. _plugins[name] = 'loading';
  4848. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4849. setTimeout(function() {
  4850. if (_plugins[name]) {
  4851. self.loadPlugin(name, fn);
  4852. }
  4853. }, 0);
  4854. });
  4855. return self;
  4856. },
  4857. handler : function(key, fn) {
  4858. var self = this;
  4859. if (!self._handlers[key]) {
  4860. self._handlers[key] = [];
  4861. }
  4862. if (_isFunction(fn)) {
  4863. self._handlers[key].push(fn);
  4864. return self;
  4865. }
  4866. _each(self._handlers[key], function() {
  4867. fn = this.call(self, fn);
  4868. });
  4869. return fn;
  4870. },
  4871. clickToolbar : function(name, fn) {
  4872. var self = this, key = 'clickToolbar' + name;
  4873. if (fn === undefined) {
  4874. if (self._handlers[key]) {
  4875. return self.handler(key);
  4876. }
  4877. self.loadPlugin(name, function() {
  4878. self.handler(key);
  4879. });
  4880. return self;
  4881. }
  4882. return self.handler(key, fn);
  4883. },
  4884. updateState : function() {
  4885. var self = this;
  4886. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4887. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4888. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4889. });
  4890. return self;
  4891. },
  4892. addContextmenu : function(item) {
  4893. this._contextmenus.push(item);
  4894. return this;
  4895. },
  4896. afterCreate : function(fn) {
  4897. return this.handler('afterCreate', fn);
  4898. },
  4899. beforeRemove : function(fn) {
  4900. return this.handler('beforeRemove', fn);
  4901. },
  4902. beforeGetHtml : function(fn) {
  4903. return this.handler('beforeGetHtml', fn);
  4904. },
  4905. beforeSetHtml : function(fn) {
  4906. return this.handler('beforeSetHtml', fn);
  4907. },
  4908. afterSetHtml : function(fn) {
  4909. return this.handler('afterSetHtml', fn);
  4910. },
  4911. create : function() {
  4912. var self = this, fullscreenMode = self.fullscreenMode;
  4913. if (self.isCreated) {
  4914. return self;
  4915. }
  4916. if (self.srcElement.data('kindeditor')) {
  4917. return self;
  4918. }
  4919. self.srcElement.data('kindeditor', 'true');
  4920. if (fullscreenMode) {
  4921. _docElement().style.overflow = 'hidden';
  4922. } else {
  4923. _docElement().style.overflow = '';
  4924. }
  4925. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4926. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4927. if ((_IE && _V < 8) || _QUIRKS) {
  4928. height = _addUnit(_removeUnit(height) + 2);
  4929. }
  4930. var container = self.container = K(self.layout);
  4931. if (fullscreenMode) {
  4932. K(document.body).append(container);
  4933. } else {
  4934. self.srcElement.before(container);
  4935. }
  4936. var toolbarDiv = K('.toolbar', container),
  4937. editDiv = K('.edit', container),
  4938. statusbar = self.statusbar = K('.statusbar', container);
  4939. container.removeClass('container')
  4940. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4941. if (fullscreenMode) {
  4942. container.css({
  4943. position : 'absolute',
  4944. left : 0,
  4945. top : 0,
  4946. 'z-index' : 811211
  4947. });
  4948. if (!_GECKO) {
  4949. self._scrollPos = _getScrollPos();
  4950. }
  4951. window.scrollTo(0, 0);
  4952. K(document.body).css({
  4953. 'height' : '1px',
  4954. 'overflow' : 'hidden'
  4955. });
  4956. K(document.body.parentNode).css('overflow', 'hidden');
  4957. self._fullscreenExecuted = true;
  4958. } else {
  4959. if (self._fullscreenExecuted) {
  4960. K(document.body).css({
  4961. 'height' : '',
  4962. 'overflow' : ''
  4963. });
  4964. K(document.body.parentNode).css('overflow', '');
  4965. }
  4966. if (self._scrollPos) {
  4967. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4968. }
  4969. }
  4970. var htmlList = [];
  4971. K.each(self.items, function(i, name) {
  4972. if (name == '|') {
  4973. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4974. } else if (name == '/') {
  4975. htmlList.push('<div class="ke-hr"></div>');
  4976. } else {
  4977. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4978. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4979. }
  4980. });
  4981. var toolbar = self.toolbar = _toolbar({
  4982. src : toolbarDiv,
  4983. html : htmlList.join(''),
  4984. noDisableItems : self.noDisableItems,
  4985. click : function(e, name) {
  4986. e.stop();
  4987. if (self.menu) {
  4988. var menuName = self.menu.name;
  4989. self.hideMenu();
  4990. if (menuName === name) {
  4991. return;
  4992. }
  4993. }
  4994. self.clickToolbar(name);
  4995. }
  4996. });
  4997. var editHeight = _removeUnit(height) - toolbar.div.height();
  4998. var edit = self.edit = _edit({
  4999. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5000. src : editDiv,
  5001. srcElement : self.srcElement,
  5002. designMode : self.designMode,
  5003. themesPath : self.themesPath,
  5004. bodyClass : self.bodyClass,
  5005. cssPath : self.cssPath,
  5006. cssData : self.cssData,
  5007. beforeGetHtml : function(html) {
  5008. html = self.beforeGetHtml(html);
  5009. html = _removeBookmarkTag(_removeTempTag(html));
  5010. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5011. },
  5012. beforeSetHtml : function(html) {
  5013. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5014. return self.beforeSetHtml(html);
  5015. },
  5016. afterSetHtml : function() {
  5017. self.edit = edit = this;
  5018. self.afterSetHtml();
  5019. },
  5020. afterCreate : function() {
  5021. self.edit = edit = this;
  5022. self.cmd = edit.cmd;
  5023. self._docMousedownFn = function(e) {
  5024. if (self.menu) {
  5025. self.hideMenu();
  5026. }
  5027. };
  5028. K(edit.doc, document).mousedown(self._docMousedownFn);
  5029. _bindContextmenuEvent.call(self);
  5030. _bindNewlineEvent.call(self);
  5031. _bindTabEvent.call(self);
  5032. _bindFocusEvent.call(self);
  5033. edit.afterChange(function(e) {
  5034. if (!edit.designMode) {
  5035. return;
  5036. }
  5037. self.updateState();
  5038. self.addBookmark();
  5039. if (self.options.afterChange) {
  5040. self.options.afterChange.call(self);
  5041. }
  5042. });
  5043. edit.textarea.keyup(function(e) {
  5044. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5045. if (self.options.afterChange) {
  5046. self.options.afterChange.call(self);
  5047. }
  5048. }
  5049. });
  5050. if (self.readonlyMode) {
  5051. self.readonly();
  5052. }
  5053. self.isCreated = true;
  5054. if (self.initContent === '') {
  5055. self.initContent = self.html();
  5056. }
  5057. if (self._undoStack.length > 0) {
  5058. var prev = self._undoStack.pop();
  5059. if (prev.start) {
  5060. self.html(prev.html);
  5061. edit.cmd.range.moveToBookmark(prev);
  5062. self.select();
  5063. }
  5064. }
  5065. self.afterCreate();
  5066. if (self.options.afterCreate) {
  5067. self.options.afterCreate.call(self);
  5068. }
  5069. }
  5070. });
  5071. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5072. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5073. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5074. if (self._fullscreenResizeHandler) {
  5075. K(window).unbind('resize', self._fullscreenResizeHandler);
  5076. self._fullscreenResizeHandler = null;
  5077. }
  5078. function initResize() {
  5079. if (statusbar.height() === 0) {
  5080. setTimeout(initResize, 100);
  5081. return;
  5082. }
  5083. self.resize(width, height, false);
  5084. }
  5085. initResize();
  5086. if (fullscreenMode) {
  5087. self._fullscreenResizeHandler = function(e) {
  5088. if (self.isCreated) {
  5089. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5090. }
  5091. };
  5092. K(window).bind('resize', self._fullscreenResizeHandler);
  5093. toolbar.select('fullscreen');
  5094. statusbar.first().css('visibility', 'hidden');
  5095. statusbar.last().css('visibility', 'hidden');
  5096. } else {
  5097. if (_GECKO) {
  5098. K(window).bind('scroll', function(e) {
  5099. self._scrollPos = _getScrollPos();
  5100. });
  5101. }
  5102. if (self.resizeType > 0) {
  5103. _drag({
  5104. moveEl : container,
  5105. clickEl : statusbar,
  5106. moveFn : function(x, y, width, height, diffX, diffY) {
  5107. height += diffY;
  5108. self.resize(null, height);
  5109. }
  5110. });
  5111. } else {
  5112. statusbar.first().css('visibility', 'hidden');
  5113. }
  5114. if (self.resizeType === 2) {
  5115. _drag({
  5116. moveEl : container,
  5117. clickEl : statusbar.last(),
  5118. moveFn : function(x, y, width, height, diffX, diffY) {
  5119. width += diffX;
  5120. height += diffY;
  5121. self.resize(width, height);
  5122. }
  5123. });
  5124. } else {
  5125. statusbar.last().css('visibility', 'hidden');
  5126. }
  5127. }
  5128. return self;
  5129. },
  5130. remove : function() {
  5131. var self = this;
  5132. if (!self.isCreated) {
  5133. return self;
  5134. }
  5135. self.beforeRemove();
  5136. self.srcElement.data('kindeditor', '');
  5137. if (self.menu) {
  5138. self.hideMenu();
  5139. }
  5140. _each(self.dialogs, function() {
  5141. self.hideDialog();
  5142. });
  5143. K(document).unbind('mousedown', self._docMousedownFn);
  5144. self.toolbar.remove();
  5145. self.edit.remove();
  5146. self.statusbar.last().unbind();
  5147. self.statusbar.unbind();
  5148. self.container.remove();
  5149. self.container = self.toolbar = self.edit = self.menu = null;
  5150. self.dialogs = [];
  5151. self.isCreated = false;
  5152. return self;
  5153. },
  5154. resize : function(width, height, updateProp) {
  5155. var self = this;
  5156. updateProp = _undef(updateProp, true);
  5157. if (width) {
  5158. if (!/%/.test(width)) {
  5159. width = _removeUnit(width);
  5160. width = width < self.minWidth ? self.minWidth : width;
  5161. }
  5162. self.container.css('width', _addUnit(width));
  5163. if (updateProp) {
  5164. self.width = _addUnit(width);
  5165. }
  5166. }
  5167. if (height) {
  5168. height = _removeUnit(height);
  5169. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5170. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5171. self.edit.setHeight(editHeight);
  5172. if (updateProp) {
  5173. self.height = _addUnit(height);
  5174. }
  5175. }
  5176. return self;
  5177. },
  5178. select : function() {
  5179. this.isCreated && this.cmd.select();
  5180. return this;
  5181. },
  5182. html : function(val) {
  5183. var self = this;
  5184. if (val === undefined) {
  5185. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5186. }
  5187. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5188. if (self.isCreated) {
  5189. self.cmd.selection();
  5190. }
  5191. return self;
  5192. },
  5193. fullHtml : function() {
  5194. return this.isCreated ? this.edit.html(undefined, true) : '';
  5195. },
  5196. text : function(val) {
  5197. var self = this;
  5198. if (val === undefined) {
  5199. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5200. } else {
  5201. return self.html(_escape(val));
  5202. }
  5203. },
  5204. isEmpty : function() {
  5205. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5206. },
  5207. isDirty : function() {
  5208. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5209. },
  5210. selectedHtml : function() {
  5211. var val = this.isCreated ? this.cmd.range.html() : '';
  5212. val = _removeBookmarkTag(_removeTempTag(val));
  5213. return val;
  5214. },
  5215. count : function(mode) {
  5216. var self = this;
  5217. mode = (mode || 'html').toLowerCase();
  5218. if (mode === 'html') {
  5219. return self.html().length;
  5220. }
  5221. if (mode === 'text') {
  5222. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5223. }
  5224. return 0;
  5225. },
  5226. exec : function(key) {
  5227. key = key.toLowerCase();
  5228. var self = this, cmd = self.cmd,
  5229. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5230. if (changeFlag) {
  5231. self.addBookmark(false);
  5232. }
  5233. cmd[key].apply(cmd, _toArray(arguments, 1));
  5234. if (changeFlag) {
  5235. self.updateState();
  5236. self.addBookmark(false);
  5237. if (self.options.afterChange) {
  5238. self.options.afterChange.call(self);
  5239. }
  5240. }
  5241. return self;
  5242. },
  5243. insertHtml : function(val, quickMode) {
  5244. if (!this.isCreated) {
  5245. return this;
  5246. }
  5247. val = this.beforeSetHtml(val);
  5248. this.exec('inserthtml', val, quickMode);
  5249. return this;
  5250. },
  5251. appendHtml : function(val) {
  5252. this.html(this.html() + val);
  5253. if (this.isCreated) {
  5254. var cmd = this.cmd;
  5255. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5256. cmd.select();
  5257. }
  5258. return this;
  5259. },
  5260. sync : function() {
  5261. _elementVal(this.srcElement, this.html());
  5262. return this;
  5263. },
  5264. focus : function() {
  5265. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5266. return this;
  5267. },
  5268. blur : function() {
  5269. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5270. return this;
  5271. },
  5272. addBookmark : function(checkSize) {
  5273. checkSize = _undef(checkSize, true);
  5274. var self = this, edit = self.edit,
  5275. body = edit.doc.body,
  5276. html = _removeTempTag(body.innerHTML), bookmark;
  5277. if (checkSize && self._undoStack.length > 0) {
  5278. var prev = self._undoStack[self._undoStack.length - 1];
  5279. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5280. return self;
  5281. }
  5282. }
  5283. if (edit.designMode && !self._firstAddBookmark) {
  5284. var range = self.cmd.range;
  5285. bookmark = range.createBookmark(true);
  5286. bookmark.html = _removeTempTag(body.innerHTML);
  5287. range.moveToBookmark(bookmark);
  5288. } else {
  5289. bookmark = {
  5290. html : html
  5291. };
  5292. }
  5293. self._firstAddBookmark = false;
  5294. _addBookmarkToStack(self._undoStack, bookmark);
  5295. return self;
  5296. },
  5297. undo : function() {
  5298. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5299. },
  5300. redo : function() {
  5301. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5302. },
  5303. fullscreen : function(bool) {
  5304. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5305. this.addBookmark(false);
  5306. return this.remove().create();
  5307. },
  5308. readonly : function(isReadonly) {
  5309. isReadonly = _undef(isReadonly, true);
  5310. var self = this, edit = self.edit, doc = edit.doc;
  5311. if (self.designMode) {
  5312. self.toolbar.disableAll(isReadonly, []);
  5313. } else {
  5314. _each(self.noDisableItems, function() {
  5315. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5316. });
  5317. }
  5318. if (_IE) {
  5319. doc.body.contentEditable = !isReadonly;
  5320. } else {
  5321. doc.designMode = isReadonly ? 'off' : 'on';
  5322. }
  5323. edit.textarea[0].disabled = isReadonly;
  5324. },
  5325. createMenu : function(options) {
  5326. var self = this,
  5327. name = options.name,
  5328. knode = self.toolbar.get(name),
  5329. pos = knode.pos();
  5330. options.x = pos.x;
  5331. options.y = pos.y + knode.height();
  5332. options.z = self.options.zIndex;
  5333. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5334. if (options.selectedColor !== undefined) {
  5335. options.cls = 'ke-colorpicker-' + self.themeType;
  5336. options.noColor = self.lang('noColor');
  5337. self.menu = _colorpicker(options);
  5338. } else {
  5339. options.cls = 'ke-menu-' + self.themeType;
  5340. options.centerLineMode = false;
  5341. self.menu = _menu(options);
  5342. }
  5343. return self.menu;
  5344. },
  5345. hideMenu : function() {
  5346. this.menu.remove();
  5347. this.menu = null;
  5348. return this;
  5349. },
  5350. hideContextmenu : function() {
  5351. this.contextmenu.remove();
  5352. this.contextmenu = null;
  5353. return this;
  5354. },
  5355. createDialog : function(options) {
  5356. var self = this, name = options.name;
  5357. options.z = self.options.zIndex;
  5358. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5359. options.closeBtn = _undef(options.closeBtn, {
  5360. name : self.lang('close'),
  5361. click : function(e) {
  5362. self.hideDialog();
  5363. if (_IE && self.cmd) {
  5364. self.cmd.select();
  5365. }
  5366. }
  5367. });
  5368. options.noBtn = _undef(options.noBtn, {
  5369. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5370. click : function(e) {
  5371. self.hideDialog();
  5372. if (_IE && self.cmd) {
  5373. self.cmd.select();
  5374. }
  5375. }
  5376. });
  5377. if (self.dialogAlignType != 'page') {
  5378. options.alignEl = self.container;
  5379. }
  5380. options.cls = 'ke-dialog-' + self.themeType;
  5381. if (self.dialogs.length > 0) {
  5382. var firstDialog = self.dialogs[0],
  5383. parentDialog = self.dialogs[self.dialogs.length - 1];
  5384. firstDialog.setMaskIndex(parentDialog.z + 2);
  5385. options.z = parentDialog.z + 3;
  5386. options.showMask = false;
  5387. }
  5388. var dialog = _dialog(options);
  5389. self.dialogs.push(dialog);
  5390. return dialog;
  5391. },
  5392. hideDialog : function() {
  5393. var self = this;
  5394. if (self.dialogs.length > 0) {
  5395. self.dialogs.pop().remove();
  5396. }
  5397. if (self.dialogs.length > 0) {
  5398. var firstDialog = self.dialogs[0],
  5399. parentDialog = self.dialogs[self.dialogs.length - 1];
  5400. firstDialog.setMaskIndex(parentDialog.z - 1);
  5401. }
  5402. return self;
  5403. },
  5404. errorDialog : function(html) {
  5405. var self = this;
  5406. var dialog = self.createDialog({
  5407. width : 750,
  5408. title : self.lang('uploadError'),
  5409. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5410. });
  5411. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5412. doc.open();
  5413. doc.write(html);
  5414. doc.close();
  5415. K(doc.body).css('background-color', '#FFF');
  5416. iframe[0].contentWindow.focus();
  5417. return self;
  5418. }
  5419. };
  5420. function _editor(options) {
  5421. return new KEditor(options);
  5422. }
  5423. var _instances = [];
  5424. function _create(expr, options) {
  5425. options = options || {};
  5426. options.basePath = _undef(options.basePath, K.basePath);
  5427. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5428. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5429. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5430. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5431. var themeType = _undef(options.themeType, K.options.themeType);
  5432. _loadStyle(options.themesPath + 'default/default.css');
  5433. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5434. }
  5435. function create(editor) {
  5436. _each(_plugins, function(name, fn) {
  5437. if (_isFunction(fn)) {
  5438. fn.call(editor, KindEditor);
  5439. if (!editor._pluginStatus) {
  5440. editor._pluginStatus = {};
  5441. }
  5442. editor._pluginStatus[name] = 'inited';
  5443. }
  5444. });
  5445. return editor.create();
  5446. }
  5447. var knode = K(expr);
  5448. if (!knode || knode.length === 0) {
  5449. return;
  5450. }
  5451. if (knode.length > 1) {
  5452. knode.each(function() {
  5453. _create(this, options);
  5454. });
  5455. return _instances[0];
  5456. }
  5457. options.srcElement = knode[0];
  5458. var editor = new KEditor(options);
  5459. _instances.push(editor);
  5460. if (_language[editor.langType]) {
  5461. return create(editor);
  5462. }
  5463. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5464. create(editor);
  5465. });
  5466. return editor;
  5467. }
  5468. function _eachEditor(expr, fn) {
  5469. K(expr).each(function(i, el) {
  5470. K.each(_instances, function(j, editor) {
  5471. if (editor && editor.srcElement[0] == el) {
  5472. fn.call(editor, j);
  5473. return false;
  5474. }
  5475. });
  5476. });
  5477. }
  5478. K.remove = function(expr) {
  5479. _eachEditor(expr, function(i) {
  5480. this.remove();
  5481. _instances.splice(i, 1);
  5482. });
  5483. };
  5484. K.sync = function(expr) {
  5485. _eachEditor(expr, function() {
  5486. this.sync();
  5487. });
  5488. };
  5489. K.html = function(expr, val) {
  5490. _eachEditor(expr, function() {
  5491. this.html(val);
  5492. });
  5493. };
  5494. K.insertHtml = function(expr, val) {
  5495. _eachEditor(expr, function() {
  5496. this.insertHtml(val);
  5497. });
  5498. };
  5499. K.appendHtml = function(expr, val) {
  5500. _eachEditor(expr, function() {
  5501. this.appendHtml(val);
  5502. });
  5503. };
  5504. if (_IE && _V < 7) {
  5505. _nativeCommand(document, 'BackgroundImageCache', true);
  5506. }
  5507. K.EditorClass = KEditor;
  5508. K.editor = _editor;
  5509. K.create = _create;
  5510. K.instances = _instances;
  5511. K.plugin = _plugin;
  5512. K.lang = _lang;
  5513. _plugin('core', function(K) {
  5514. var self = this,
  5515. shortcutKeys = {
  5516. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5517. };
  5518. self.afterSetHtml(function() {
  5519. if (self.options.afterChange) {
  5520. self.options.afterChange.call(self);
  5521. }
  5522. });
  5523. self.afterCreate(function() {
  5524. if (self.syncType != 'form') {
  5525. return;
  5526. }
  5527. var el = K(self.srcElement), hasForm = false;
  5528. while ((el = el.parent())) {
  5529. if (el.name == 'form') {
  5530. hasForm = true;
  5531. break;
  5532. }
  5533. }
  5534. if (hasForm) {
  5535. el.bind('submit', function(e) {
  5536. self.sync();
  5537. K(window).bind('unload', function() {
  5538. self.edit.textarea.remove();
  5539. });
  5540. });
  5541. var resetBtn = K('[type="reset"]', el);
  5542. resetBtn.click(function() {
  5543. self.html(self.initContent);
  5544. self.cmd.selection();
  5545. });
  5546. self.beforeRemove(function() {
  5547. el.unbind();
  5548. resetBtn.unbind();
  5549. });
  5550. }
  5551. });
  5552. self.clickToolbar('source', function() {
  5553. if (self.edit.designMode) {
  5554. self.toolbar.disableAll(true);
  5555. self.edit.design(false);
  5556. self.toolbar.select('source');
  5557. } else {
  5558. self.toolbar.disableAll(false);
  5559. self.edit.design(true);
  5560. self.toolbar.unselect('source');
  5561. if (_GECKO) {
  5562. setTimeout(function() {
  5563. self.cmd.selection();
  5564. }, 0);
  5565. } else {
  5566. self.cmd.selection();
  5567. }
  5568. }
  5569. self.designMode = self.edit.designMode;
  5570. });
  5571. self.afterCreate(function() {
  5572. if (!self.designMode) {
  5573. self.toolbar.disableAll(true).select('source');
  5574. }
  5575. });
  5576. self.clickToolbar('fullscreen', function() {
  5577. self.fullscreen();
  5578. });
  5579. if (self.fullscreenShortcut) {
  5580. var loaded = false;
  5581. self.afterCreate(function() {
  5582. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5583. if (e.which == 27) {
  5584. setTimeout(function() {
  5585. self.fullscreen();
  5586. }, 0);
  5587. }
  5588. });
  5589. if (loaded) {
  5590. if (_IE && !self.designMode) {
  5591. return;
  5592. }
  5593. self.focus();
  5594. }
  5595. if (!loaded) {
  5596. loaded = true;
  5597. }
  5598. });
  5599. }
  5600. _each('undo,redo'.split(','), function(i, name) {
  5601. if (shortcutKeys[name]) {
  5602. self.afterCreate(function() {
  5603. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5604. self.clickToolbar(name);
  5605. });
  5606. });
  5607. }
  5608. self.clickToolbar(name, function() {
  5609. self[name]();
  5610. });
  5611. });
  5612. self.clickToolbar('formatblock', function() {
  5613. var blocks = self.lang('formatblock.formatBlock'),
  5614. heights = {
  5615. h1 : 28,
  5616. h2 : 24,
  5617. h3 : 18,
  5618. H4 : 14,
  5619. p : 12
  5620. },
  5621. curVal = self.cmd.val('formatblock'),
  5622. menu = self.createMenu({
  5623. name : 'formatblock',
  5624. width : self.langType == 'en' ? 200 : 150
  5625. });
  5626. _each(blocks, function(key, val) {
  5627. var style = 'font-size:' + heights[key] + 'px;';
  5628. if (key.charAt(0) === 'h') {
  5629. style += 'font-weight:bold;';
  5630. }
  5631. menu.addItem({
  5632. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5633. height : heights[key] + 12,
  5634. checked : (curVal === key || curVal === val),
  5635. click : function() {
  5636. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5637. }
  5638. });
  5639. });
  5640. });
  5641. self.clickToolbar('fontname', function() {
  5642. var curVal = self.cmd.val('fontname'),
  5643. menu = self.createMenu({
  5644. name : 'fontname',
  5645. width : 150
  5646. });
  5647. _each(self.lang('fontname.fontName'), function(key, val) {
  5648. menu.addItem({
  5649. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5650. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5651. click : function() {
  5652. self.exec('fontname', key).hideMenu();
  5653. }
  5654. });
  5655. });
  5656. });
  5657. self.clickToolbar('fontsize', function() {
  5658. var curVal = self.cmd.val('fontsize'),
  5659. menu = self.createMenu({
  5660. name : 'fontsize',
  5661. width : 150
  5662. });
  5663. _each(self.fontSizeTable, function(i, val) {
  5664. menu.addItem({
  5665. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5666. height : _removeUnit(val) + 12,
  5667. checked : curVal === val,
  5668. click : function() {
  5669. self.exec('fontsize', val).hideMenu();
  5670. }
  5671. });
  5672. });
  5673. });
  5674. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5675. self.clickToolbar(name, function() {
  5676. self.createMenu({
  5677. name : name,
  5678. selectedColor : self.cmd.val(name) || 'default',
  5679. colors : self.colorTable,
  5680. click : function(color) {
  5681. self.exec(name, color).hideMenu();
  5682. }
  5683. });
  5684. });
  5685. });
  5686. _each(('cut,copy,paste').split(','), function(i, name) {
  5687. self.clickToolbar(name, function() {
  5688. self.focus();
  5689. try {
  5690. self.exec(name, null);
  5691. } catch(e) {
  5692. alert(self.lang(name + 'Error'));
  5693. }
  5694. });
  5695. });
  5696. self.clickToolbar('about', function() {
  5697. var html = '<div style="margin:20px;">' +
  5698. '<div>KindEditor ' + _VERSION + '</div>' +
  5699. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5700. '</div>';
  5701. self.createDialog({
  5702. name : 'about',
  5703. width : 350,
  5704. title : self.lang('about'),
  5705. body : html
  5706. });
  5707. });
  5708. self.plugin.getSelectedLink = function() {
  5709. return self.cmd.commonAncestor('a');
  5710. };
  5711. self.plugin.getSelectedImage = function() {
  5712. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5713. return !/^ke-\w+$/i.test(img[0].className);
  5714. });
  5715. };
  5716. self.plugin.getSelectedFlash = function() {
  5717. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5718. return img[0].className == 'ke-flash';
  5719. });
  5720. };
  5721. self.plugin.getSelectedMedia = function() {
  5722. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5723. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5724. });
  5725. };
  5726. self.plugin.getSelectedAnchor = function() {
  5727. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5728. return img[0].className == 'ke-anchor';
  5729. });
  5730. };
  5731. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5732. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5733. _each('edit,delete'.split(','), function(j, val) {
  5734. self.addContextmenu({
  5735. title : self.lang(val + uName),
  5736. click : function() {
  5737. self.loadPlugin(name, function() {
  5738. self.plugin[name][val]();
  5739. self.hideMenu();
  5740. });
  5741. },
  5742. cond : self.plugin['getSelected' + uName],
  5743. width : 150,
  5744. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5745. });
  5746. });
  5747. self.addContextmenu({ title : '-' });
  5748. });
  5749. self.plugin.getSelectedTable = function() {
  5750. return self.cmd.commonAncestor('table');
  5751. };
  5752. self.plugin.getSelectedRow = function() {
  5753. return self.cmd.commonAncestor('tr');
  5754. };
  5755. self.plugin.getSelectedCell = function() {
  5756. return self.cmd.commonAncestor('td');
  5757. };
  5758. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5759. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5760. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5761. self.addContextmenu({
  5762. title : self.lang('table' + val),
  5763. click : function() {
  5764. self.loadPlugin('table', function() {
  5765. self.plugin.table[val]();
  5766. self.hideMenu();
  5767. });
  5768. },
  5769. cond : cond,
  5770. width : 170,
  5771. iconClass : 'ke-icon-table' + val
  5772. });
  5773. });
  5774. self.addContextmenu({ title : '-' });
  5775. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5776. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5777. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5778. if (shortcutKeys[name]) {
  5779. self.afterCreate(function() {
  5780. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5781. self.cmd.selection();
  5782. self.clickToolbar(name);
  5783. });
  5784. });
  5785. }
  5786. self.clickToolbar(name, function() {
  5787. self.focus().exec(name, null);
  5788. });
  5789. });
  5790. self.afterCreate(function() {
  5791. var doc = self.edit.doc, cmd, bookmark, div,
  5792. cls = '__kindeditor_paste__', pasting = false;
  5793. function movePastedData() {
  5794. cmd.range.moveToBookmark(bookmark);
  5795. cmd.select();
  5796. if (_WEBKIT) {
  5797. K('div.' + cls, div).each(function() {
  5798. K(this).after('<br />').remove(true);
  5799. });
  5800. K('span.Apple-style-span', div).remove(true);
  5801. K('span.Apple-tab-span', div).remove(true);
  5802. K('span[style]', div).each(function() {
  5803. if (K(this).css('white-space') == 'nowrap') {
  5804. K(this).remove(true);
  5805. }
  5806. });
  5807. K('meta', div).remove();
  5808. }
  5809. var html = div[0].innerHTML;
  5810. div.remove();
  5811. if (html === '') {
  5812. return;
  5813. }
  5814. if (_WEBKIT) {
  5815. html = html.replace(/(<br>)\1/ig, '$1');
  5816. }
  5817. if (self.pasteType === 2) {
  5818. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5819. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5820. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5821. } else {
  5822. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5823. html = self.beforeSetHtml(html);
  5824. }
  5825. }
  5826. if (self.pasteType === 1) {
  5827. html = html.replace(/&nbsp;/ig, ' ');
  5828. html = html.replace(/\n\s*\n/g, '\n');
  5829. html = html.replace(/<br[^>]*>/ig, '\n');
  5830. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5831. html = html.replace(/<[^>]+>/g, '');
  5832. html = html.replace(/ {2}/g, ' &nbsp;');
  5833. if (self.newlineTag == 'p') {
  5834. if (/\n/.test(html)) {
  5835. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5836. }
  5837. } else {
  5838. html = html.replace(/\n/g, '<br />$&');
  5839. }
  5840. }
  5841. self.insertHtml(html, true);
  5842. }
  5843. K(doc.body).bind('paste', function(e){
  5844. if (self.pasteType === 0) {
  5845. e.stop();
  5846. return;
  5847. }
  5848. if (pasting) {
  5849. return;
  5850. }
  5851. pasting = true;
  5852. K('div.' + cls, doc).remove();
  5853. cmd = self.cmd.selection();
  5854. bookmark = cmd.range.createBookmark();
  5855. div = K('<div class="' + cls + '"></div>', doc).css({
  5856. position : 'absolute',
  5857. width : '1px',
  5858. height : '1px',
  5859. overflow : 'hidden',
  5860. left : '-1981px',
  5861. top : K(bookmark.start).pos().y + 'px',
  5862. 'white-space' : 'nowrap'
  5863. });
  5864. K(doc.body).append(div);
  5865. if (_IE) {
  5866. var rng = cmd.range.get(true);
  5867. rng.moveToElementText(div[0]);
  5868. rng.select();
  5869. rng.execCommand('paste');
  5870. e.preventDefault();
  5871. } else {
  5872. cmd.range.selectNodeContents(div[0]);
  5873. cmd.select();
  5874. div[0].tabIndex = -1;
  5875. div[0].focus();
  5876. }
  5877. setTimeout(function() {
  5878. movePastedData();
  5879. pasting = false;
  5880. }, 0);
  5881. });
  5882. });
  5883. self.beforeGetHtml(function(html) {
  5884. if (_IE && _V <= 8) {
  5885. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5886. return unescape(tag);
  5887. });
  5888. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5889. if (!/\s+type="[^"]+"/i.test($0)) {
  5890. return $1 + ' type="text"' + $2;
  5891. }
  5892. return $0;
  5893. });
  5894. }
  5895. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5896. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5897. })
  5898. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5899. var imgAttrs = _getAttrList(full);
  5900. var styles = _getCssList(imgAttrs.style || '');
  5901. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5902. var width = _undef(styles.width, '');
  5903. var height = _undef(styles.height, '');
  5904. if (/px/i.test(width)) {
  5905. width = _removeUnit(width);
  5906. }
  5907. if (/px/i.test(height)) {
  5908. height = _removeUnit(height);
  5909. }
  5910. attrs.width = _undef(imgAttrs.width, width);
  5911. attrs.height = _undef(imgAttrs.height, height);
  5912. return _mediaEmbed(attrs);
  5913. })
  5914. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  5915. var imgAttrs = _getAttrList(full);
  5916. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5917. })
  5918. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5919. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5920. })
  5921. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5922. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5923. })
  5924. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  5925. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  5926. return $1 + _unescape(src) + $2;
  5927. });
  5928. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5929. return full;
  5930. })
  5931. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5932. return start + end;
  5933. });
  5934. });
  5935. self.beforeSetHtml(function(html) {
  5936. if (_IE && _V <= 8) {
  5937. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  5938. var attrs = _getAttrList(full);
  5939. var styles = _getCssList(attrs.style || '');
  5940. if (styles.display == 'none') {
  5941. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5942. }
  5943. return full;
  5944. });
  5945. }
  5946. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  5947. var attrs = _getAttrList(full);
  5948. attrs.src = _undef(attrs.src, '');
  5949. attrs.width = _undef(attrs.width, 0);
  5950. attrs.height = _undef(attrs.height, 0);
  5951. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5952. })
  5953. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  5954. var attrs = _getAttrList(full);
  5955. if (attrs.href !== undefined) {
  5956. return full;
  5957. }
  5958. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5959. })
  5960. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  5961. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5962. })
  5963. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  5964. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5965. })
  5966. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  5967. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5968. return full;
  5969. }
  5970. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5971. return full;
  5972. })
  5973. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5974. return start + 'data-ke-' + end;
  5975. })
  5976. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  5977. if (full.indexOf('ke-zeroborder') >= 0) {
  5978. return full;
  5979. }
  5980. return _addClassToTag(full, 'ke-zeroborder');
  5981. });
  5982. });
  5983. });
  5984. })(window);
  5985. /*******************************************************************************
  5986. * KindEditor - WYSIWYG HTML Editor for Internet
  5987. * Copyright (C) 2006-2011 kindsoft.net
  5988. *
  5989. * @author Roddy <luolonghao@gmail.com>
  5990. * @site http://www.kindsoft.net/
  5991. * @licence http://www.kindsoft.net/license.php
  5992. *******************************************************************************/
  5993. KindEditor.lang({
  5994. source : 'HTML代码',
  5995. preview : '预览',
  5996. undo : '后退(Ctrl+Z)',
  5997. redo : '前进(Ctrl+Y)',
  5998. cut : '剪切(Ctrl+X)',
  5999. copy : '复制(Ctrl+C)',
  6000. paste : '粘贴(Ctrl+V)',
  6001. plainpaste : '粘贴为无格式文本',
  6002. wordpaste : '从Word粘贴',
  6003. selectall : '全选(Ctrl+A)',
  6004. justifyleft : '左对齐',
  6005. justifycenter : '居中',
  6006. justifyright : '右对齐',
  6007. justifyfull : '两端对齐',
  6008. insertorderedlist : '编号',
  6009. insertunorderedlist : '项目符号',
  6010. indent : '增加缩进',
  6011. outdent : '减少缩进',
  6012. subscript : '下标',
  6013. superscript : '上标',
  6014. formatblock : '段落',
  6015. fontname : '字体',
  6016. fontsize : '文字大小',
  6017. forecolor : '文字颜色',
  6018. hilitecolor : '文字背景',
  6019. bold : '粗体(Ctrl+B)',
  6020. italic : '斜体(Ctrl+I)',
  6021. underline : '下划线(Ctrl+U)',
  6022. strikethrough : '删除线',
  6023. removeformat : '删除格式',
  6024. image : '图片',
  6025. multiimage : '批量图片上传',
  6026. flash : 'Flash',
  6027. media : '视音频',
  6028. table : '表格',
  6029. tablecell : '单元格',
  6030. hr : '插入横线',
  6031. emoticons : '插入表情',
  6032. link : '超级链接',
  6033. unlink : '取消超级链接',
  6034. fullscreen : '全屏显示',
  6035. about : '关于',
  6036. print : '打印(Ctrl+P)',
  6037. filemanager : '文件空间',
  6038. code : '插入程序代码',
  6039. map : 'Google地图',
  6040. baidumap : '百度地图',
  6041. lineheight : '行距',
  6042. clearhtml : '清理HTML代码',
  6043. pagebreak : '插入分页符',
  6044. quickformat : '一键排版',
  6045. insertfile : '插入文件',
  6046. template : '插入模板',
  6047. anchor : '锚点',
  6048. yes : '确定',
  6049. no : '取消',
  6050. close : '关闭',
  6051. editImage : '图片属性',
  6052. deleteImage : '删除图片',
  6053. editFlash : 'Flash属性',
  6054. deleteFlash : '删除Flash',
  6055. editMedia : '视音频属性',
  6056. deleteMedia : '删除视音频',
  6057. editLink : '超级链接属性',
  6058. deleteLink : '取消超级链接',
  6059. editAnchor : '锚点属性',
  6060. deleteAnchor : '删除锚点',
  6061. tableprop : '表格属性',
  6062. tablecellprop : '单元格属性',
  6063. tableinsert : '插入表格',
  6064. tabledelete : '删除表格',
  6065. tablecolinsertleft : '左侧插入列',
  6066. tablecolinsertright : '右侧插入列',
  6067. tablerowinsertabove : '上方插入行',
  6068. tablerowinsertbelow : '下方插入行',
  6069. tablerowmerge : '向下合并单元格',
  6070. tablecolmerge : '向右合并单元格',
  6071. tablerowsplit : '拆分行',
  6072. tablecolsplit : '拆分列',
  6073. tablecoldelete : '删除列',
  6074. tablerowdelete : '删除行',
  6075. noColor : '无颜色',
  6076. pleaseSelectFile : '请选择文件。',
  6077. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6078. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6079. invalidWidth : "宽度必须为数字。",
  6080. invalidHeight : "高度必须为数字。",
  6081. invalidBorder : "边框必须为数字。",
  6082. invalidUrl : "请输入有效的URL地址。",
  6083. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6084. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6085. invalidPadding : '边距必须为数字。',
  6086. invalidSpacing : '间距必须为数字。',
  6087. invalidJson : '服务器发生故障。',
  6088. uploadSuccess : '上传成功。',
  6089. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6090. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6091. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6092. ajaxLoading : '加载中,请稍候 ...',
  6093. uploadLoading : '上传中,请稍候 ...',
  6094. uploadError : '上传错误',
  6095. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6096. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6097. 'code.pleaseInput' : '请输入程序代码。',
  6098. 'link.url' : 'URL',
  6099. 'link.linkType' : '打开类型',
  6100. 'link.newWindow' : '新窗口',
  6101. 'link.selfWindow' : '当前窗口',
  6102. 'flash.url' : 'URL',
  6103. 'flash.width' : '宽度',
  6104. 'flash.height' : '高度',
  6105. 'flash.upload' : '上传',
  6106. 'flash.viewServer' : '文件空间',
  6107. 'media.url' : 'URL',
  6108. 'media.width' : '宽度',
  6109. 'media.height' : '高度',
  6110. 'media.autostart' : '自动播放',
  6111. 'media.upload' : '上传',
  6112. 'media.viewServer' : '文件空间',
  6113. 'image.remoteImage' : '网络图片',
  6114. 'image.localImage' : '本地上传',
  6115. 'image.remoteUrl' : '图片地址',
  6116. 'image.localUrl' : '上传文件',
  6117. 'image.size' : '图片大小',
  6118. 'image.width' : '宽',
  6119. 'image.height' : '高',
  6120. 'image.resetSize' : '重置大小',
  6121. 'image.align' : '对齐方式',
  6122. 'image.defaultAlign' : '默认方式',
  6123. 'image.leftAlign' : '左对齐',
  6124. 'image.rightAlign' : '右对齐',
  6125. 'image.imgTitle' : '图片说明',
  6126. 'image.upload' : '浏览...',
  6127. 'image.viewServer' : '图片空间',
  6128. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6129. 'multiimage.startUpload' : '开始上传',
  6130. 'multiimage.clearAll' : '全部清空',
  6131. 'multiimage.insertAll' : '全部插入',
  6132. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6133. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6134. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6135. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6136. 'multiimage.unknownError' : '发生异常,无法上传。',
  6137. 'multiimage.pending' : '等待上传',
  6138. 'multiimage.uploadError' : '上传失败',
  6139. 'filemanager.emptyFolder' : '空文件夹',
  6140. 'filemanager.moveup' : '移到上一级文件夹',
  6141. 'filemanager.viewType' : '显示方式:',
  6142. 'filemanager.viewImage' : '缩略图',
  6143. 'filemanager.listImage' : '详细信息',
  6144. 'filemanager.orderType' : '排序方式:',
  6145. 'filemanager.fileName' : '名称',
  6146. 'filemanager.fileSize' : '大小',
  6147. 'filemanager.fileType' : '类型',
  6148. 'insertfile.url' : 'URL',
  6149. 'insertfile.title' : '文件说明',
  6150. 'insertfile.upload' : '上传',
  6151. 'insertfile.viewServer' : '文件空间',
  6152. 'table.cells' : '单元格数',
  6153. 'table.rows' : '行数',
  6154. 'table.cols' : '列数',
  6155. 'table.size' : '大小',
  6156. 'table.width' : '宽度',
  6157. 'table.height' : '高度',
  6158. 'table.percent' : '%',
  6159. 'table.px' : 'px',
  6160. 'table.space' : '边距间距',
  6161. 'table.padding' : '边距',
  6162. 'table.spacing' : '间距',
  6163. 'table.align' : '对齐方式',
  6164. 'table.textAlign' : '水平对齐',
  6165. 'table.verticalAlign' : '垂直对齐',
  6166. 'table.alignDefault' : '默认',
  6167. 'table.alignLeft' : '左对齐',
  6168. 'table.alignCenter' : '居中',
  6169. 'table.alignRight' : '右对齐',
  6170. 'table.alignTop' : '顶部',
  6171. 'table.alignMiddle' : '中部',
  6172. 'table.alignBottom' : '底部',
  6173. 'table.alignBaseline' : '基线',
  6174. 'table.border' : '边框',
  6175. 'table.borderWidth' : '边框',
  6176. 'table.borderColor' : '颜色',
  6177. 'table.backgroundColor' : '背景颜色',
  6178. 'map.address' : '地址: ',
  6179. 'map.search' : '搜索',
  6180. 'baidumap.address' : '地址: ',
  6181. 'baidumap.search' : '搜索',
  6182. 'baidumap.insertDynamicMap' : '插入动态地图',
  6183. 'anchor.name' : '锚点名称',
  6184. 'formatblock.formatBlock' : {
  6185. h1 : '标题 1',
  6186. h2 : '标题 2',
  6187. h3 : '标题 3',
  6188. h4 : '标题 4',
  6189. p : '正 文'
  6190. },
  6191. 'fontname.fontName' : {
  6192. 'SimSun' : '宋体',
  6193. 'NSimSun' : '新宋体',
  6194. 'FangSong_GB2312' : '仿宋_GB2312',
  6195. 'KaiTi_GB2312' : '楷体_GB2312',
  6196. 'SimHei' : '黑体',
  6197. 'Microsoft YaHei' : '微软雅黑',
  6198. 'Arial' : 'Arial',
  6199. 'Arial Black' : 'Arial Black',
  6200. 'Times New Roman' : 'Times New Roman',
  6201. 'Courier New' : 'Courier New',
  6202. 'Tahoma' : 'Tahoma',
  6203. 'Verdana' : 'Verdana'
  6204. },
  6205. 'lineheight.lineHeight' : [
  6206. {'1' : '单倍行距'},
  6207. {'1.5' : '1.5倍行距'},
  6208. {'2' : '2倍行距'},
  6209. {'2.5' : '2.5倍行距'},
  6210. {'3' : '3倍行距'}
  6211. ],
  6212. 'template.selectTemplate' : '可选模板',
  6213. 'template.replaceContent' : '替换当前内容',
  6214. 'template.fileList' : {
  6215. '1.html' : '图片和文字',
  6216. '2.html' : '表格',
  6217. '3.html' : '项目编号'
  6218. }
  6219. }, 'zh-CN');
  6220. KindEditor.options.langType = 'zh-CN';
  6221. /*******************************************************************************
  6222. * KindEditor - WYSIWYG HTML Editor for Internet
  6223. * Copyright (C) 2006-2011 kindsoft.net
  6224. *
  6225. * @author Roddy <luolonghao@gmail.com>
  6226. * @site http://www.kindsoft.net/
  6227. * @licence http://www.kindsoft.net/license.php
  6228. *******************************************************************************/
  6229. KindEditor.plugin('anchor', function(K) {
  6230. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6231. self.plugin.anchor = {
  6232. edit : function() {
  6233. var html = ['<div style="padding:20px;">',
  6234. '<div class="ke-dialog-row">',
  6235. '<label for="keName">' + lang.name + '</label>',
  6236. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6237. '</div>',
  6238. '</div>'].join('');
  6239. var dialog = self.createDialog({
  6240. name : name,
  6241. width : 300,
  6242. title : self.lang(name),
  6243. body : html,
  6244. yesBtn : {
  6245. name : self.lang('yes'),
  6246. click : function(e) {
  6247. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6248. }
  6249. }
  6250. });
  6251. var div = dialog.div,
  6252. nameBox = K('input[name="name"]', div);
  6253. var img = self.plugin.getSelectedAnchor();
  6254. if (img) {
  6255. nameBox.val(unescape(img.attr('data-ke-name')));
  6256. }
  6257. nameBox[0].focus();
  6258. nameBox[0].select();
  6259. },
  6260. 'delete' : function() {
  6261. self.plugin.getSelectedAnchor().remove();
  6262. }
  6263. };
  6264. self.clickToolbar(name, self.plugin.anchor.edit);
  6265. });
  6266. /*******************************************************************************
  6267. * KindEditor - WYSIWYG HTML Editor for Internet
  6268. * Copyright (C) 2006-2011 kindsoft.net
  6269. *
  6270. * @author Roddy <luolonghao@gmail.com>
  6271. * @site http://www.kindsoft.net/
  6272. * @licence http://www.kindsoft.net/license.php
  6273. *******************************************************************************/
  6274. KindEditor.plugin('autoheight', function(K) {
  6275. var self = this;
  6276. if (!self.autoHeightMode) {
  6277. return;
  6278. }
  6279. var minHeight;
  6280. function hideScroll() {
  6281. var edit = self.edit;
  6282. var body = edit.doc.body;
  6283. edit.iframe[0].scroll = 'no';
  6284. body.style.overflowY = 'hidden';
  6285. }
  6286. function resetHeight() {
  6287. if(self.fullscreenMode){
  6288. return;
  6289. }
  6290. var edit = self.edit;
  6291. var body = edit.doc.body;
  6292. edit.iframe.height(minHeight);
  6293. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6294. }
  6295. function init() {
  6296. minHeight = K.removeUnit(self.height);
  6297. self.edit.afterChange(resetHeight);
  6298. if(!self.fullscreenMode){
  6299. hideScroll();
  6300. }
  6301. resetHeight();
  6302. }
  6303. if (self.isCreated) {
  6304. init();
  6305. } else {
  6306. self.afterCreate(init);
  6307. }
  6308. });
  6309. /*
  6310. * 如何实现真正的自动高度?
  6311. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6312. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6313. * 由此就实现了真正的自动高度
  6314. * 测试:chrome、firefox、IE9、IE8
  6315. * */
  6316. /*******************************************************************************
  6317. * KindEditor - WYSIWYG HTML Editor for Internet
  6318. * Copyright (C) 2006-2011 kindsoft.net
  6319. *
  6320. * @author Roddy <luolonghao@gmail.com>
  6321. * @site http://www.kindsoft.net/
  6322. * @licence http://www.kindsoft.net/license.php
  6323. *******************************************************************************/
  6324. KindEditor.plugin('baidumap', function(K) {
  6325. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6326. var mapWidth = K.undef(self.mapWidth, 558);
  6327. var mapHeight = K.undef(self.mapHeight, 360);
  6328. self.clickToolbar(name, function() {
  6329. var html = ['<div style="padding:10px 20px;">',
  6330. '<div class="ke-header">',
  6331. '<div class="ke-left">',
  6332. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6333. '<span class="ke-button-common ke-button-outer">',
  6334. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6335. '</span>',
  6336. '</div>',
  6337. '<div class="ke-right">',
  6338. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6339. '</div>',
  6340. '<div class="ke-clearfix"></div>',
  6341. '</div>',
  6342. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6343. '</div>'].join('');
  6344. var dialog = self.createDialog({
  6345. name : name,
  6346. width : mapWidth + 42,
  6347. title : self.lang(name),
  6348. body : html,
  6349. yesBtn : {
  6350. name : self.lang('yes'),
  6351. click : function(e) {
  6352. var map = win.map;
  6353. var centerObj = map.getCenter();
  6354. var center = centerObj.lng + ',' + centerObj.lat;
  6355. var zoom = map.getZoom();
  6356. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6357. '?center=' + encodeURIComponent(center),
  6358. '&zoom=' + encodeURIComponent(zoom),
  6359. '&width=' + mapWidth,
  6360. '&height=' + mapHeight,
  6361. '&markers=' + encodeURIComponent(center),
  6362. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6363. if (checkbox[0].checked) {
  6364. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6365. } else {
  6366. self.exec('insertimage', url);
  6367. }
  6368. self.hideDialog().focus();
  6369. }
  6370. },
  6371. beforeRemove : function() {
  6372. searchBtn.remove();
  6373. if (doc) {
  6374. doc.write('');
  6375. }
  6376. iframe.remove();
  6377. }
  6378. });
  6379. var div = dialog.div,
  6380. addressBox = K('[name="address"]', div),
  6381. searchBtn = K('[name="searchBtn"]', div),
  6382. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6383. win, doc;
  6384. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6385. function ready() {
  6386. win = iframe[0].contentWindow;
  6387. doc = K.iframeDoc(iframe);
  6388. }
  6389. iframe.bind('load', function() {
  6390. iframe.unbind('load');
  6391. if (K.IE) {
  6392. ready();
  6393. } else {
  6394. setTimeout(ready, 0);
  6395. }
  6396. });
  6397. K('.ke-map', div).replaceWith(iframe);
  6398. searchBtn.click(function() {
  6399. win.search(addressBox.val());
  6400. });
  6401. });
  6402. });
  6403. /*******************************************************************************
  6404. * KindEditor - WYSIWYG HTML Editor for Internet
  6405. * Copyright (C) 2006-2011 kindsoft.net
  6406. *
  6407. * @author Roddy <luolonghao@gmail.com>
  6408. * @site http://www.kindsoft.net/
  6409. * @licence http://www.kindsoft.net/license.php
  6410. *******************************************************************************/
  6411. KindEditor.plugin('map', function(K) {
  6412. var self = this, name = 'map', lang = self.lang(name + '.');
  6413. self.clickToolbar(name, function() {
  6414. var html = ['<div style="padding:10px 20px;">',
  6415. '<div class="ke-dialog-row">',
  6416. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6417. '<span class="ke-button-common ke-button-outer">',
  6418. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6419. '</span>',
  6420. '</div>',
  6421. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6422. '</div>'].join('');
  6423. var dialog = self.createDialog({
  6424. name : name,
  6425. width : 600,
  6426. title : self.lang(name),
  6427. body : html,
  6428. yesBtn : {
  6429. name : self.lang('yes'),
  6430. click : function(e) {
  6431. var geocoder = win.geocoder,
  6432. map = win.map,
  6433. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6434. zoom = map.getZoom(),
  6435. maptype = map.getMapTypeId(),
  6436. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6437. url += '?center=' + encodeURIComponent(center);
  6438. url += '&zoom=' + encodeURIComponent(zoom);
  6439. url += '&size=558x360';
  6440. url += '&maptype=' + encodeURIComponent(maptype);
  6441. url += '&markers=' + encodeURIComponent(center);
  6442. url += '&language=' + self.langType;
  6443. url += '&sensor=false';
  6444. self.exec('insertimage', url).hideDialog().focus();
  6445. }
  6446. },
  6447. beforeRemove : function() {
  6448. searchBtn.remove();
  6449. if (doc) {
  6450. doc.write('');
  6451. }
  6452. iframe.remove();
  6453. }
  6454. });
  6455. var div = dialog.div,
  6456. addressBox = K('[name="address"]', div),
  6457. searchBtn = K('[name="searchBtn"]', div),
  6458. win, doc;
  6459. var iframeHtml = ['<!doctype html><html><head>',
  6460. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6461. '<style>',
  6462. ' html { height: 100% }',
  6463. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6464. ' #map_canvas { height: 100% }',
  6465. '</style>',
  6466. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6467. '<script>',
  6468. 'var map, geocoder;',
  6469. 'function initialize() {',
  6470. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6471. ' var options = {',
  6472. ' zoom: 11,',
  6473. ' center: latlng,',
  6474. ' disableDefaultUI: true,',
  6475. ' panControl: true,',
  6476. ' zoomControl: true,',
  6477. ' mapTypeControl: true,',
  6478. ' scaleControl: true,',
  6479. ' streetViewControl: false,',
  6480. ' overviewMapControl: true,',
  6481. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6482. ' };',
  6483. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6484. ' geocoder = new google.maps.Geocoder();',
  6485. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6486. ' if (status == google.maps.GeocoderStatus.OK) {',
  6487. ' if (results[3]) {',
  6488. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6489. ' }',
  6490. ' }',
  6491. ' });',
  6492. '}',
  6493. 'function search(address) {',
  6494. ' if (!map) return;',
  6495. ' geocoder.geocode({address : address}, function(results, status) {',
  6496. ' if (status == google.maps.GeocoderStatus.OK) {',
  6497. ' map.setZoom(11);',
  6498. ' map.setCenter(results[0].geometry.location);',
  6499. ' var marker = new google.maps.Marker({',
  6500. ' map: map,',
  6501. ' position: results[0].geometry.location',
  6502. ' });',
  6503. ' } else {',
  6504. ' alert("Invalid address: " + address);',
  6505. ' }',
  6506. ' });',
  6507. '}',
  6508. '</script>',
  6509. '</head>',
  6510. '<body onload="initialize();">',
  6511. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6512. '</body></html>'].join('\n');
  6513. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6514. function ready() {
  6515. win = iframe[0].contentWindow;
  6516. doc = K.iframeDoc(iframe);
  6517. }
  6518. iframe.bind('load', function() {
  6519. iframe.unbind('load');
  6520. if (K.IE) {
  6521. ready();
  6522. } else {
  6523. setTimeout(ready, 0);
  6524. }
  6525. });
  6526. K('.ke-map', div).replaceWith(iframe);
  6527. searchBtn.click(function() {
  6528. win.search(addressBox.val());
  6529. });
  6530. });
  6531. });
  6532. /*******************************************************************************
  6533. * KindEditor - WYSIWYG HTML Editor for Internet
  6534. * Copyright (C) 2006-2011 kindsoft.net
  6535. *
  6536. * @author Roddy <luolonghao@gmail.com>
  6537. * @site http://www.kindsoft.net/
  6538. * @licence http://www.kindsoft.net/license.php
  6539. *******************************************************************************/
  6540. KindEditor.plugin('clearhtml', function(K) {
  6541. var self = this, name = 'clearhtml';
  6542. self.clickToolbar(name, function() {
  6543. self.focus();
  6544. var html = self.html();
  6545. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6546. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6547. html = K.formatHtml(html, {
  6548. a : ['href', 'target'],
  6549. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6550. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6551. table : ['border'],
  6552. 'td,th' : ['rowspan', 'colspan'],
  6553. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6554. });
  6555. self.html(html);
  6556. self.cmd.selection(true);
  6557. self.addBookmark();
  6558. });
  6559. });
  6560. /*******************************************************************************
  6561. * KindEditor - WYSIWYG HTML Editor for Internet
  6562. * Copyright (C) 2006-2011 kindsoft.net
  6563. *
  6564. * @author Roddy <luolonghao@gmail.com>
  6565. * @site http://www.kindsoft.net/
  6566. * @licence http://www.kindsoft.net/license.php
  6567. *******************************************************************************/
  6568. KindEditor.plugin('code', function(K) {
  6569. var self = this, name = 'code';
  6570. self.clickToolbar(name, function() {
  6571. var lang = self.lang(name + '.'),
  6572. html = ['<div style="padding:10px 20px;">',
  6573. '<div class="ke-dialog-row">',
  6574. '<select class="ke-code-type">',
  6575. '<option value="js">JavaScript</option>',
  6576. '<option value="html">HTML</option>',
  6577. '<option value="css">CSS</option>',
  6578. '<option value="php">PHP</option>',
  6579. '<option value="pl">Perl</option>',
  6580. '<option value="py">Python</option>',
  6581. '<option value="rb">Ruby</option>',
  6582. '<option value="java">Java</option>',
  6583. '<option value="vb">ASP/VB</option>',
  6584. '<option value="cpp">C/C++</option>',
  6585. '<option value="cs">C#</option>',
  6586. '<option value="xml">XML</option>',
  6587. '<option value="bsh">Shell</option>',
  6588. '<option value="">Other</option>',
  6589. '</select>',
  6590. '</div>',
  6591. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6592. '</div>'].join(''),
  6593. dialog = self.createDialog({
  6594. name : name,
  6595. width : 450,
  6596. title : self.lang(name),
  6597. body : html,
  6598. yesBtn : {
  6599. name : self.lang('yes'),
  6600. click : function(e) {
  6601. var type = K('.ke-code-type', dialog.div).val(),
  6602. code = textarea.val(),
  6603. cls = type === '' ? '' : ' lang-' + type,
  6604. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6605. if (K.trim(code) === '') {
  6606. alert(lang.pleaseInput);
  6607. textarea[0].focus();
  6608. return;
  6609. }
  6610. self.insertHtml(html).hideDialog().focus();
  6611. }
  6612. }
  6613. }),
  6614. textarea = K('textarea', dialog.div);
  6615. textarea[0].focus();
  6616. });
  6617. });
  6618. /*******************************************************************************
  6619. * KindEditor - WYSIWYG HTML Editor for Internet
  6620. * Copyright (C) 2006-2011 kindsoft.net
  6621. *
  6622. * @author Roddy <luolonghao@gmail.com>
  6623. * @site http://www.kindsoft.net/
  6624. * @licence http://www.kindsoft.net/license.php
  6625. *******************************************************************************/
  6626. KindEditor.plugin('emoticons', function(K) {
  6627. var self = this, name = 'emoticons',
  6628. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6629. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6630. currentPageNum = 1;
  6631. self.clickToolbar(name, function() {
  6632. var rows = 5, cols = 9, total = 135, startNum = 0,
  6633. cells = rows * cols, pages = Math.ceil(total / cells),
  6634. colsHalf = Math.floor(cols / 2),
  6635. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6636. elements = [],
  6637. menu = self.createMenu({
  6638. name : name,
  6639. beforeRemove : function() {
  6640. removeEvent();
  6641. }
  6642. });
  6643. menu.div.append(wrapperDiv);
  6644. var previewDiv, previewImg;
  6645. if (allowPreview) {
  6646. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6647. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6648. wrapperDiv.append(previewDiv);
  6649. previewDiv.append(previewImg);
  6650. }
  6651. function bindCellEvent(cell, j, num) {
  6652. if (previewDiv) {
  6653. cell.mouseover(function() {
  6654. if (j > colsHalf) {
  6655. previewDiv.css('left', 0);
  6656. previewDiv.css('right', '');
  6657. } else {
  6658. previewDiv.css('left', '');
  6659. previewDiv.css('right', 0);
  6660. }
  6661. previewImg.attr('src', path + num + '.gif');
  6662. K(this).addClass('ke-on');
  6663. });
  6664. } else {
  6665. cell.mouseover(function() {
  6666. K(this).addClass('ke-on');
  6667. });
  6668. }
  6669. cell.mouseout(function() {
  6670. K(this).removeClass('ke-on');
  6671. });
  6672. cell.click(function(e) {
  6673. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6674. e.stop();
  6675. });
  6676. }
  6677. function createEmoticonsTable(pageNum, parentDiv) {
  6678. var table = document.createElement('table');
  6679. parentDiv.append(table);
  6680. if (previewDiv) {
  6681. K(table).mouseover(function() {
  6682. previewDiv.show('block');
  6683. });
  6684. K(table).mouseout(function() {
  6685. previewDiv.hide();
  6686. });
  6687. elements.push(K(table));
  6688. }
  6689. table.className = 'ke-table';
  6690. table.cellPadding = 0;
  6691. table.cellSpacing = 0;
  6692. table.border = 0;
  6693. var num = (pageNum - 1) * cells + startNum;
  6694. for (var i = 0; i < rows; i++) {
  6695. var row = table.insertRow(i);
  6696. for (var j = 0; j < cols; j++) {
  6697. var cell = K(row.insertCell(j));
  6698. cell.addClass('ke-cell');
  6699. bindCellEvent(cell, j, num);
  6700. var span = K('<span class="ke-img"></span>')
  6701. .css('background-position', '-' + (24 * num) + 'px 0px')
  6702. .css('background-image', 'url(' + path + 'static.gif)');
  6703. cell.append(span);
  6704. elements.push(cell);
  6705. num++;
  6706. }
  6707. }
  6708. return table;
  6709. }
  6710. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6711. function removeEvent() {
  6712. K.each(elements, function() {
  6713. this.unbind();
  6714. });
  6715. }
  6716. var pageDiv;
  6717. function bindPageEvent(el, pageNum) {
  6718. el.click(function(e) {
  6719. removeEvent();
  6720. table.parentNode.removeChild(table);
  6721. pageDiv.remove();
  6722. table = createEmoticonsTable(pageNum, wrapperDiv);
  6723. createPageTable(pageNum);
  6724. currentPageNum = pageNum;
  6725. e.stop();
  6726. });
  6727. }
  6728. function createPageTable(currentPageNum) {
  6729. pageDiv = K('<div class="ke-page"></div>');
  6730. wrapperDiv.append(pageDiv);
  6731. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6732. if (currentPageNum !== pageNum) {
  6733. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6734. bindPageEvent(a, pageNum);
  6735. pageDiv.append(a);
  6736. elements.push(a);
  6737. } else {
  6738. pageDiv.append(K('@[' + pageNum + ']'));
  6739. }
  6740. pageDiv.append(K('@&nbsp;'));
  6741. }
  6742. }
  6743. createPageTable(currentPageNum);
  6744. });
  6745. });
  6746. /*******************************************************************************
  6747. * KindEditor - WYSIWYG HTML Editor for Internet
  6748. * Copyright (C) 2006-2011 kindsoft.net
  6749. *
  6750. * @author Roddy <luolonghao@gmail.com>
  6751. * @site http://www.kindsoft.net/
  6752. * @licence http://www.kindsoft.net/license.php
  6753. *******************************************************************************/
  6754. KindEditor.plugin('filemanager', function(K) {
  6755. var self = this, name = 'filemanager',
  6756. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6757. imgPath = self.pluginsPath + name + '/images/',
  6758. lang = self.lang(name + '.');
  6759. function makeFileTitle(filename, filesize, datetime) {
  6760. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6761. }
  6762. function bindTitle(el, data) {
  6763. if (data.is_dir) {
  6764. el.attr('title', data.filename);
  6765. } else {
  6766. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6767. }
  6768. }
  6769. self.plugin.filemanagerDialog = function(options) {
  6770. var width = K.undef(options.width, 650),
  6771. height = K.undef(options.height, 510),
  6772. dirName = K.undef(options.dirName, ''),
  6773. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6774. clickFn = options.clickFn;
  6775. var html = [
  6776. '<div style="padding:10px 20px;">',
  6777. '<div class="ke-plugin-filemanager-header">',
  6778. '<div class="ke-left">',
  6779. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6780. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6781. '</div>',
  6782. '<div class="ke-right">',
  6783. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6784. '<option value="VIEW">' + lang.viewImage + '</option>',
  6785. '<option value="LIST">' + lang.listImage + '</option>',
  6786. '</select> ',
  6787. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6788. '<option value="NAME">' + lang.fileName + '</option>',
  6789. '<option value="SIZE">' + lang.fileSize + '</option>',
  6790. '<option value="TYPE">' + lang.fileType + '</option>',
  6791. '</select>',
  6792. '</div>',
  6793. '<div class="ke-clearfix"></div>',
  6794. '</div>',
  6795. '<div class="ke-plugin-filemanager-body"></div>',
  6796. '</div>'
  6797. ].join('');
  6798. var dialog = self.createDialog({
  6799. name : name,
  6800. width : width,
  6801. height : height,
  6802. title : self.lang(name),
  6803. body : html
  6804. }),
  6805. div = dialog.div,
  6806. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6807. moveupImg = K('[name="moveupImg"]', div),
  6808. moveupLink = K('[name="moveupLink"]', div),
  6809. viewServerBtn = K('[name="viewServer"]', div),
  6810. viewTypeBox = K('[name="viewType"]', div),
  6811. orderTypeBox = K('[name="orderType"]', div);
  6812. function reloadPage(path, order, func) {
  6813. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6814. dialog.showLoading(self.lang('ajaxLoading'));
  6815. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6816. dialog.hideLoading();
  6817. func(data);
  6818. });
  6819. }
  6820. var elList = [];
  6821. function bindEvent(el, result, data, createFunc) {
  6822. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6823. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6824. if (data.is_dir) {
  6825. el.click(function(e) {
  6826. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6827. });
  6828. } else if (data.is_photo) {
  6829. el.click(function(e) {
  6830. clickFn.call(this, fileUrl, data.filename);
  6831. });
  6832. } else {
  6833. el.click(function(e) {
  6834. clickFn.call(this, fileUrl, data.filename);
  6835. });
  6836. }
  6837. elList.push(el);
  6838. }
  6839. function createCommon(result, createFunc) {
  6840. K.each(elList, function() {
  6841. this.unbind();
  6842. });
  6843. moveupLink.unbind();
  6844. viewTypeBox.unbind();
  6845. orderTypeBox.unbind();
  6846. if (result.current_dir_path) {
  6847. moveupLink.click(function(e) {
  6848. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6849. });
  6850. }
  6851. function changeFunc() {
  6852. if (viewTypeBox.val() == 'VIEW') {
  6853. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6854. } else {
  6855. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6856. }
  6857. }
  6858. viewTypeBox.change(changeFunc);
  6859. orderTypeBox.change(changeFunc);
  6860. bodyDiv.html('');
  6861. }
  6862. function createList(result) {
  6863. createCommon(result, createList);
  6864. var table = document.createElement('table');
  6865. table.className = 'ke-table';
  6866. table.cellPadding = 0;
  6867. table.cellSpacing = 0;
  6868. table.border = 0;
  6869. bodyDiv.append(table);
  6870. var fileList = result.file_list;
  6871. for (var i = 0, len = fileList.length; i < len; i++) {
  6872. var data = fileList[i], row = K(table.insertRow(i));
  6873. row.mouseover(function(e) {
  6874. K(this).addClass('ke-on');
  6875. })
  6876. .mouseout(function(e) {
  6877. K(this).removeClass('ke-on');
  6878. });
  6879. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6880. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6881. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6882. if (!data.is_dir || data.has_file) {
  6883. row.css('cursor', 'pointer');
  6884. cell0.attr('title', data.filename);
  6885. bindEvent(cell0, result, data, createList);
  6886. } else {
  6887. cell0.attr('title', lang.emptyFolder);
  6888. }
  6889. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6890. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6891. }
  6892. }
  6893. function createView(result) {
  6894. createCommon(result, createView);
  6895. var fileList = result.file_list;
  6896. for (var i = 0, len = fileList.length; i < len; i++) {
  6897. var data = fileList[i],
  6898. div = K('<div class="ke-inline-block ke-item"></div>');
  6899. bodyDiv.append(div);
  6900. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6901. .mouseover(function(e) {
  6902. K(this).addClass('ke-on');
  6903. })
  6904. .mouseout(function(e) {
  6905. K(this).removeClass('ke-on');
  6906. });
  6907. div.append(photoDiv);
  6908. var fileUrl = result.current_url + data.filename,
  6909. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6910. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6911. if (!data.is_dir || data.has_file) {
  6912. photoDiv.css('cursor', 'pointer');
  6913. bindTitle(photoDiv, data);
  6914. bindEvent(photoDiv, result, data, createView);
  6915. } else {
  6916. photoDiv.attr('title', lang.emptyFolder);
  6917. }
  6918. photoDiv.append(img);
  6919. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6920. }
  6921. }
  6922. viewTypeBox.val(viewType);
  6923. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6924. return dialog;
  6925. }
  6926. });
  6927. /*******************************************************************************
  6928. * KindEditor - WYSIWYG HTML Editor for Internet
  6929. * Copyright (C) 2006-2011 kindsoft.net
  6930. *
  6931. * @author Roddy <luolonghao@gmail.com>
  6932. * @site http://www.kindsoft.net/
  6933. * @licence http://www.kindsoft.net/license.php
  6934. *******************************************************************************/
  6935. KindEditor.plugin('flash', function(K) {
  6936. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6937. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6938. allowFileManager = K.undef(self.allowFileManager, false),
  6939. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6940. extraParams = K.undef(self.extraFileUploadParams, {}),
  6941. filePostName = K.undef(self.filePostName, 'imgFile'),
  6942. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  6943. self.plugin.flash = {
  6944. edit : function() {
  6945. var html = [
  6946. '<div style="padding:20px;">',
  6947. '<div class="ke-dialog-row">',
  6948. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6949. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6950. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6951. '<span class="ke-button-common ke-button-outer">',
  6952. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6953. '</span>',
  6954. '</div>',
  6955. '<div class="ke-dialog-row">',
  6956. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6957. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6958. '</div>',
  6959. '<div class="ke-dialog-row">',
  6960. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6961. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6962. '</div>',
  6963. '</div>'
  6964. ].join('');
  6965. var dialog = self.createDialog({
  6966. name : name,
  6967. width : 450,
  6968. title : self.lang(name),
  6969. body : html,
  6970. yesBtn : {
  6971. name : self.lang('yes'),
  6972. click : function(e) {
  6973. var url = K.trim(urlBox.val()),
  6974. width = widthBox.val(),
  6975. height = heightBox.val();
  6976. if (url == 'http://' || K.invalidUrl(url)) {
  6977. alert(self.lang('invalidUrl'));
  6978. urlBox[0].focus();
  6979. return;
  6980. }
  6981. if (!/^\d*$/.test(width)) {
  6982. alert(self.lang('invalidWidth'));
  6983. widthBox[0].focus();
  6984. return;
  6985. }
  6986. if (!/^\d*$/.test(height)) {
  6987. alert(self.lang('invalidHeight'));
  6988. heightBox[0].focus();
  6989. return;
  6990. }
  6991. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6992. src : url,
  6993. type : K.mediaType('.swf'),
  6994. width : width,
  6995. height : height,
  6996. quality : 'high'
  6997. });
  6998. self.insertHtml(html).hideDialog().focus();
  6999. }
  7000. }
  7001. }),
  7002. div = dialog.div,
  7003. urlBox = K('[name="url"]', div),
  7004. viewServerBtn = K('[name="viewServer"]', div),
  7005. widthBox = K('[name="width"]', div),
  7006. heightBox = K('[name="height"]', div);
  7007. urlBox.val('http://');
  7008. if (allowFlashUpload) {
  7009. var uploadbutton = K.uploadbutton({
  7010. button : K('.ke-upload-button', div)[0],
  7011. fieldName : filePostName,
  7012. extraParams : extraParams,
  7013. url : K.addParam(uploadJson, 'dir=flash'),
  7014. afterUpload : function(data) {
  7015. dialog.hideLoading();
  7016. if (data.error === 0) {
  7017. var url = data.url;
  7018. if (formatUploadUrl) {
  7019. url = K.formatUrl(url, 'absolute');
  7020. }
  7021. urlBox.val(url);
  7022. if (self.afterUpload) {
  7023. self.afterUpload.call(self, url, data, name);
  7024. }
  7025. alert(self.lang('uploadSuccess'));
  7026. } else {
  7027. alert(data.message);
  7028. }
  7029. },
  7030. afterError : function(html) {
  7031. dialog.hideLoading();
  7032. self.errorDialog(html);
  7033. }
  7034. });
  7035. uploadbutton.fileBox.change(function(e) {
  7036. dialog.showLoading(self.lang('uploadLoading'));
  7037. uploadbutton.submit();
  7038. });
  7039. } else {
  7040. K('.ke-upload-button', div).hide();
  7041. }
  7042. if (allowFileManager) {
  7043. viewServerBtn.click(function(e) {
  7044. self.loadPlugin('filemanager', function() {
  7045. self.plugin.filemanagerDialog({
  7046. viewType : 'LIST',
  7047. dirName : 'flash',
  7048. clickFn : function(url, title) {
  7049. if (self.dialogs.length > 1) {
  7050. K('[name="url"]', div).val(url);
  7051. if (self.afterSelectFile) {
  7052. self.afterSelectFile.call(self, url);
  7053. }
  7054. self.hideDialog();
  7055. }
  7056. }
  7057. });
  7058. });
  7059. });
  7060. } else {
  7061. viewServerBtn.hide();
  7062. }
  7063. var img = self.plugin.getSelectedFlash();
  7064. if (img) {
  7065. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7066. urlBox.val(attrs.src);
  7067. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7068. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7069. }
  7070. urlBox[0].focus();
  7071. urlBox[0].select();
  7072. },
  7073. 'delete' : function() {
  7074. self.plugin.getSelectedFlash().remove();
  7075. self.addBookmark();
  7076. }
  7077. };
  7078. self.clickToolbar(name, self.plugin.flash.edit);
  7079. });
  7080. /*******************************************************************************
  7081. * KindEditor - WYSIWYG HTML Editor for Internet
  7082. * Copyright (C) 2006-2011 kindsoft.net
  7083. *
  7084. * @author Roddy <luolonghao@gmail.com>
  7085. * @site http://www.kindsoft.net/
  7086. * @licence http://www.kindsoft.net/license.php
  7087. *******************************************************************************/
  7088. KindEditor.plugin('image', function(K) {
  7089. var self = this, name = 'image',
  7090. allowImageUpload = K.undef(self.allowImageUpload, true),
  7091. allowImageRemote = K.undef(self.allowImageRemote, true),
  7092. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7093. allowFileManager = K.undef(self.allowFileManager, false),
  7094. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7095. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7096. imgPath = self.pluginsPath + 'image/images/',
  7097. extraParams = K.undef(self.extraFileUploadParams, {}),
  7098. filePostName = K.undef(self.filePostName, 'imgFile'),
  7099. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7100. lang = self.lang(name + '.');
  7101. self.plugin.imageDialog = function(options) {
  7102. var imageUrl = options.imageUrl,
  7103. imageWidth = K.undef(options.imageWidth, ''),
  7104. imageHeight = K.undef(options.imageHeight, ''),
  7105. imageTitle = K.undef(options.imageTitle, ''),
  7106. imageAlign = K.undef(options.imageAlign, ''),
  7107. showRemote = K.undef(options.showRemote, true),
  7108. showLocal = K.undef(options.showLocal, true),
  7109. tabIndex = K.undef(options.tabIndex, 0),
  7110. clickFn = options.clickFn;
  7111. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7112. var hiddenElements = [];
  7113. for(var k in extraParams){
  7114. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7115. }
  7116. var html = [
  7117. '<div style="padding:20px;">',
  7118. '<div class="tabs"></div>',
  7119. '<div class="tab1" style="display:none;">',
  7120. '<div class="ke-dialog-row">',
  7121. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7122. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7123. '<span class="ke-button-common ke-button-outer">',
  7124. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7125. '</span>',
  7126. '</div>',
  7127. '<div class="ke-dialog-row">',
  7128. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7129. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7130. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7131. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7132. '</div>',
  7133. '<div class="ke-dialog-row">',
  7134. '<label style="width:60px;">' + lang.align + '</label>',
  7135. '<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="" />',
  7136. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7137. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7138. '</div>',
  7139. '<div class="ke-dialog-row">',
  7140. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7141. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7142. '</div>',
  7143. '</div>',
  7144. '<div class="tab2" style="display:none;">',
  7145. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7146. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7147. '<div class="ke-dialog-row">',
  7148. hiddenElements.join(''),
  7149. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7150. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7151. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7152. '</div>',
  7153. '</form>',
  7154. '</div>',
  7155. '</div>'
  7156. ].join('');
  7157. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7158. dialogHeight = showLocal && showRemote ? 300 : 250;
  7159. var dialog = self.createDialog({
  7160. name : name,
  7161. width : dialogWidth,
  7162. height : dialogHeight,
  7163. title : self.lang(name),
  7164. body : html,
  7165. yesBtn : {
  7166. name : self.lang('yes'),
  7167. click : function(e) {
  7168. if (dialog.isLoading) {
  7169. return;
  7170. }
  7171. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7172. if (uploadbutton.fileBox.val() == '') {
  7173. alert(self.lang('pleaseSelectFile'));
  7174. return;
  7175. }
  7176. dialog.showLoading(self.lang('uploadLoading'));
  7177. uploadbutton.submit();
  7178. localUrlBox.val('');
  7179. return;
  7180. }
  7181. var url = K.trim(urlBox.val()),
  7182. width = widthBox.val(),
  7183. height = heightBox.val(),
  7184. title = titleBox.val(),
  7185. align = '';
  7186. alignBox.each(function() {
  7187. if (this.checked) {
  7188. align = this.value;
  7189. return false;
  7190. }
  7191. });
  7192. if (url == 'http://' || K.invalidUrl(url)) {
  7193. alert(self.lang('invalidUrl'));
  7194. urlBox[0].focus();
  7195. return;
  7196. }
  7197. if (!/^\d*$/.test(width)) {
  7198. alert(self.lang('invalidWidth'));
  7199. widthBox[0].focus();
  7200. return;
  7201. }
  7202. if (!/^\d*$/.test(height)) {
  7203. alert(self.lang('invalidHeight'));
  7204. heightBox[0].focus();
  7205. return;
  7206. }
  7207. clickFn.call(self, url, title, width, height, 0, align);
  7208. }
  7209. },
  7210. beforeRemove : function() {
  7211. viewServerBtn.unbind();
  7212. widthBox.unbind();
  7213. heightBox.unbind();
  7214. refreshBtn.unbind();
  7215. }
  7216. }),
  7217. div = dialog.div;
  7218. var urlBox = K('[name="url"]', div),
  7219. localUrlBox = K('[name="localUrl"]', div),
  7220. viewServerBtn = K('[name="viewServer"]', div),
  7221. widthBox = K('.tab1 [name="width"]', div),
  7222. heightBox = K('.tab1 [name="height"]', div),
  7223. refreshBtn = K('.ke-refresh-btn', div),
  7224. titleBox = K('.tab1 [name="title"]', div),
  7225. alignBox = K('.tab1 [name="align"]', div);
  7226. var tabs;
  7227. if (showRemote && showLocal) {
  7228. tabs = K.tabs({
  7229. src : K('.tabs', div),
  7230. afterSelect : function(i) {}
  7231. });
  7232. tabs.add({
  7233. title : lang.remoteImage,
  7234. panel : K('.tab1', div)
  7235. });
  7236. tabs.add({
  7237. title : lang.localImage,
  7238. panel : K('.tab2', div)
  7239. });
  7240. tabs.select(tabIndex);
  7241. } else if (showRemote) {
  7242. K('.tab1', div).show();
  7243. } else if (showLocal) {
  7244. K('.tab2', div).show();
  7245. }
  7246. var uploadbutton = K.uploadbutton({
  7247. button : K('.ke-upload-button', div)[0],
  7248. fieldName : filePostName,
  7249. form : K('.ke-form', div),
  7250. target : target,
  7251. width: 60,
  7252. afterUpload : function(data) {
  7253. dialog.hideLoading();
  7254. if (data.error === 0) {
  7255. var url = data.url;
  7256. if (formatUploadUrl) {
  7257. url = K.formatUrl(url, 'absolute');
  7258. }
  7259. if (self.afterUpload) {
  7260. self.afterUpload.call(self, url, data, name);
  7261. }
  7262. if (!fillDescAfterUploadImage) {
  7263. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7264. } else {
  7265. K(".ke-dialog-row #remoteUrl", div).val(url);
  7266. K(".ke-tabs-li", div)[0].click();
  7267. K(".ke-refresh-btn", div).click();
  7268. }
  7269. } else {
  7270. alert(data.message);
  7271. }
  7272. },
  7273. afterError : function(html) {
  7274. dialog.hideLoading();
  7275. self.errorDialog(html);
  7276. }
  7277. });
  7278. uploadbutton.fileBox.change(function(e) {
  7279. localUrlBox.val(uploadbutton.fileBox.val());
  7280. });
  7281. if (allowFileManager) {
  7282. viewServerBtn.click(function(e) {
  7283. self.loadPlugin('filemanager', function() {
  7284. self.plugin.filemanagerDialog({
  7285. viewType : 'VIEW',
  7286. dirName : 'image',
  7287. clickFn : function(url, title) {
  7288. if (self.dialogs.length > 1) {
  7289. K('[name="url"]', div).val(url);
  7290. if (self.afterSelectFile) {
  7291. self.afterSelectFile.call(self, url);
  7292. }
  7293. self.hideDialog();
  7294. }
  7295. }
  7296. });
  7297. });
  7298. });
  7299. } else {
  7300. viewServerBtn.hide();
  7301. }
  7302. var originalWidth = 0, originalHeight = 0;
  7303. function setSize(width, height) {
  7304. widthBox.val(width);
  7305. heightBox.val(height);
  7306. originalWidth = width;
  7307. originalHeight = height;
  7308. }
  7309. refreshBtn.click(function(e) {
  7310. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7311. position : 'absolute',
  7312. visibility : 'hidden',
  7313. top : 0,
  7314. left : '-1000px'
  7315. });
  7316. tempImg.bind('load', function() {
  7317. setSize(tempImg.width(), tempImg.height());
  7318. tempImg.remove();
  7319. });
  7320. K(document.body).append(tempImg);
  7321. });
  7322. widthBox.change(function(e) {
  7323. if (originalWidth > 0) {
  7324. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7325. }
  7326. });
  7327. heightBox.change(function(e) {
  7328. if (originalHeight > 0) {
  7329. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7330. }
  7331. });
  7332. urlBox.val(options.imageUrl);
  7333. setSize(options.imageWidth, options.imageHeight);
  7334. titleBox.val(options.imageTitle);
  7335. alignBox.each(function() {
  7336. if (this.value === options.imageAlign) {
  7337. this.checked = true;
  7338. return false;
  7339. }
  7340. });
  7341. if (showRemote && tabIndex === 0) {
  7342. urlBox[0].focus();
  7343. urlBox[0].select();
  7344. }
  7345. return dialog;
  7346. };
  7347. self.plugin.image = {
  7348. edit : function() {
  7349. var img = self.plugin.getSelectedImage();
  7350. self.plugin.imageDialog({
  7351. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7352. imageWidth : img ? img.width() : '',
  7353. imageHeight : img ? img.height() : '',
  7354. imageTitle : img ? img.attr('title') : '',
  7355. imageAlign : img ? img.attr('align') : '',
  7356. showRemote : allowImageRemote,
  7357. showLocal : allowImageUpload,
  7358. tabIndex: img ? 0 : imageTabIndex,
  7359. clickFn : function(url, title, width, height, border, align) {
  7360. if (img) {
  7361. img.attr('src', url);
  7362. img.attr('data-ke-src', url);
  7363. img.attr('width', width);
  7364. img.attr('height', height);
  7365. img.attr('title', title);
  7366. img.attr('align', align);
  7367. img.attr('alt', title);
  7368. } else {
  7369. self.exec('insertimage', url, title, width, height, border, align);
  7370. }
  7371. setTimeout(function() {
  7372. self.hideDialog().focus();
  7373. }, 0);
  7374. }
  7375. });
  7376. },
  7377. 'delete' : function() {
  7378. var target = self.plugin.getSelectedImage();
  7379. if (target.parent().name == 'a') {
  7380. target = target.parent();
  7381. }
  7382. target.remove();
  7383. self.addBookmark();
  7384. }
  7385. };
  7386. self.clickToolbar(name, self.plugin.image.edit);
  7387. });
  7388. /*******************************************************************************
  7389. * KindEditor - WYSIWYG HTML Editor for Internet
  7390. * Copyright (C) 2006-2011 kindsoft.net
  7391. *
  7392. * @author Roddy <luolonghao@gmail.com>
  7393. * @site http://www.kindsoft.net/
  7394. * @licence http://www.kindsoft.net/license.php
  7395. *******************************************************************************/
  7396. KindEditor.plugin('insertfile', function(K) {
  7397. var self = this, name = 'insertfile',
  7398. allowFileUpload = K.undef(self.allowFileUpload, true),
  7399. allowFileManager = K.undef(self.allowFileManager, false),
  7400. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7401. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7402. extraParams = K.undef(self.extraFileUploadParams, {}),
  7403. filePostName = K.undef(self.filePostName, 'imgFile'),
  7404. lang = self.lang(name + '.');
  7405. self.plugin.fileDialog = function(options) {
  7406. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7407. fileTitle = K.undef(options.fileTitle, ''),
  7408. clickFn = options.clickFn;
  7409. var html = [
  7410. '<div style="padding:20px;">',
  7411. '<div class="ke-dialog-row">',
  7412. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7413. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7414. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7415. '<span class="ke-button-common ke-button-outer">',
  7416. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7417. '</span>',
  7418. '</div>',
  7419. '<div class="ke-dialog-row">',
  7420. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7421. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7422. '</div>',
  7423. '</form>',
  7424. '</div>'
  7425. ].join('');
  7426. var dialog = self.createDialog({
  7427. name : name,
  7428. width : 450,
  7429. title : self.lang(name),
  7430. body : html,
  7431. yesBtn : {
  7432. name : self.lang('yes'),
  7433. click : function(e) {
  7434. var url = K.trim(urlBox.val()),
  7435. title = titleBox.val();
  7436. if (url == 'http://' || K.invalidUrl(url)) {
  7437. alert(self.lang('invalidUrl'));
  7438. urlBox[0].focus();
  7439. return;
  7440. }
  7441. if (K.trim(title) === '') {
  7442. title = url;
  7443. }
  7444. clickFn.call(self, url, title);
  7445. }
  7446. }
  7447. }),
  7448. div = dialog.div;
  7449. var urlBox = K('[name="url"]', div),
  7450. viewServerBtn = K('[name="viewServer"]', div),
  7451. titleBox = K('[name="title"]', div);
  7452. if (allowFileUpload) {
  7453. var uploadbutton = K.uploadbutton({
  7454. button : K('.ke-upload-button', div)[0],
  7455. fieldName : filePostName,
  7456. url : K.addParam(uploadJson, 'dir=file'),
  7457. extraParams : extraParams,
  7458. afterUpload : function(data) {
  7459. dialog.hideLoading();
  7460. if (data.error === 0) {
  7461. var url = data.url;
  7462. if (formatUploadUrl) {
  7463. url = K.formatUrl(url, 'absolute');
  7464. }
  7465. urlBox.val(url);
  7466. if (self.afterUpload) {
  7467. self.afterUpload.call(self, url, data, name);
  7468. }
  7469. alert(self.lang('uploadSuccess'));
  7470. } else {
  7471. alert(data.message);
  7472. }
  7473. },
  7474. afterError : function(html) {
  7475. dialog.hideLoading();
  7476. self.errorDialog(html);
  7477. }
  7478. });
  7479. uploadbutton.fileBox.change(function(e) {
  7480. dialog.showLoading(self.lang('uploadLoading'));
  7481. uploadbutton.submit();
  7482. });
  7483. } else {
  7484. K('.ke-upload-button', div).hide();
  7485. }
  7486. if (allowFileManager) {
  7487. viewServerBtn.click(function(e) {
  7488. self.loadPlugin('filemanager', function() {
  7489. self.plugin.filemanagerDialog({
  7490. viewType : 'LIST',
  7491. dirName : 'file',
  7492. clickFn : function(url, title) {
  7493. if (self.dialogs.length > 1) {
  7494. K('[name="url"]', div).val(url);
  7495. if (self.afterSelectFile) {
  7496. self.afterSelectFile.call(self, url);
  7497. }
  7498. self.hideDialog();
  7499. }
  7500. }
  7501. });
  7502. });
  7503. });
  7504. } else {
  7505. viewServerBtn.hide();
  7506. }
  7507. urlBox.val(fileUrl);
  7508. titleBox.val(fileTitle);
  7509. urlBox[0].focus();
  7510. urlBox[0].select();
  7511. };
  7512. self.clickToolbar(name, function() {
  7513. self.plugin.fileDialog({
  7514. clickFn : function(url, title) {
  7515. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7516. self.insertHtml(html).hideDialog().focus();
  7517. }
  7518. });
  7519. });
  7520. });
  7521. /*******************************************************************************
  7522. * KindEditor - WYSIWYG HTML Editor for Internet
  7523. * Copyright (C) 2006-2011 kindsoft.net
  7524. *
  7525. * @author Roddy <luolonghao@gmail.com>
  7526. * @site http://www.kindsoft.net/
  7527. * @licence http://www.kindsoft.net/license.php
  7528. *******************************************************************************/
  7529. KindEditor.plugin('lineheight', function(K) {
  7530. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7531. self.clickToolbar(name, function() {
  7532. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7533. if (commonNode) {
  7534. curVal = commonNode.css('line-height');
  7535. }
  7536. var menu = self.createMenu({
  7537. name : name,
  7538. width : 150
  7539. });
  7540. K.each(lang.lineHeight, function(i, row) {
  7541. K.each(row, function(key, val) {
  7542. menu.addItem({
  7543. title : val,
  7544. checked : curVal === key,
  7545. click : function() {
  7546. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7547. span : '.line-height=' + key
  7548. });
  7549. self.updateState();
  7550. self.addBookmark();
  7551. self.hideMenu();
  7552. }
  7553. });
  7554. });
  7555. });
  7556. });
  7557. });
  7558. /*******************************************************************************
  7559. * KindEditor - WYSIWYG HTML Editor for Internet
  7560. * Copyright (C) 2006-2011 kindsoft.net
  7561. *
  7562. * @author Roddy <luolonghao@gmail.com>
  7563. * @site http://www.kindsoft.net/
  7564. * @licence http://www.kindsoft.net/license.php
  7565. *******************************************************************************/
  7566. KindEditor.plugin('link', function(K) {
  7567. var self = this, name = 'link';
  7568. self.plugin.link = {
  7569. edit : function() {
  7570. var lang = self.lang(name + '.'),
  7571. html = '<div style="padding:20px;">' +
  7572. '<div class="ke-dialog-row">' +
  7573. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7574. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7575. '<div class="ke-dialog-row"">' +
  7576. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7577. '<select id="keType" name="type"></select>' +
  7578. '</div>' +
  7579. '</div>',
  7580. dialog = self.createDialog({
  7581. name : name,
  7582. width : 450,
  7583. title : self.lang(name),
  7584. body : html,
  7585. yesBtn : {
  7586. name : self.lang('yes'),
  7587. click : function(e) {
  7588. var url = K.trim(urlBox.val());
  7589. if (url == 'http://' || K.invalidUrl(url)) {
  7590. alert(self.lang('invalidUrl'));
  7591. urlBox[0].focus();
  7592. return;
  7593. }
  7594. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7595. }
  7596. }
  7597. }),
  7598. div = dialog.div,
  7599. urlBox = K('input[name="url"]', div),
  7600. typeBox = K('select[name="type"]', div);
  7601. urlBox.val('http://');
  7602. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7603. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7604. self.cmd.selection();
  7605. var a = self.plugin.getSelectedLink();
  7606. if (a) {
  7607. self.cmd.range.selectNode(a[0]);
  7608. self.cmd.select();
  7609. urlBox.val(a.attr('data-ke-src'));
  7610. typeBox.val(a.attr('target'));
  7611. }
  7612. urlBox[0].focus();
  7613. urlBox[0].select();
  7614. },
  7615. 'delete' : function() {
  7616. self.exec('unlink', null);
  7617. }
  7618. };
  7619. self.clickToolbar(name, self.plugin.link.edit);
  7620. });
  7621. /*******************************************************************************
  7622. * KindEditor - WYSIWYG HTML Editor for Internet
  7623. * Copyright (C) 2006-2011 kindsoft.net
  7624. *
  7625. * @author Roddy <luolonghao@gmail.com>
  7626. * @site http://www.kindsoft.net/
  7627. * @licence http://www.kindsoft.net/license.php
  7628. *******************************************************************************/
  7629. KindEditor.plugin('media', function(K) {
  7630. var self = this, name = 'media', lang = self.lang(name + '.'),
  7631. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7632. allowFileManager = K.undef(self.allowFileManager, false),
  7633. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7634. extraParams = K.undef(self.extraFileUploadParams, {}),
  7635. filePostName = K.undef(self.filePostName, 'imgFile'),
  7636. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7637. self.plugin.media = {
  7638. edit : function() {
  7639. var html = [
  7640. '<div style="padding:20px;">',
  7641. '<div class="ke-dialog-row">',
  7642. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7643. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7644. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7645. '<span class="ke-button-common ke-button-outer">',
  7646. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7647. '</span>',
  7648. '</div>',
  7649. '<div class="ke-dialog-row">',
  7650. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7651. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7652. '</div>',
  7653. '<div class="ke-dialog-row">',
  7654. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7655. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7656. '</div>',
  7657. '<div class="ke-dialog-row">',
  7658. '<label for="keAutostart">' + lang.autostart + '</label>',
  7659. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7660. '</div>',
  7661. '</div>'
  7662. ].join('');
  7663. var dialog = self.createDialog({
  7664. name : name,
  7665. width : 450,
  7666. height : 230,
  7667. title : self.lang(name),
  7668. body : html,
  7669. yesBtn : {
  7670. name : self.lang('yes'),
  7671. click : function(e) {
  7672. var url = K.trim(urlBox.val()),
  7673. width = widthBox.val(),
  7674. height = heightBox.val();
  7675. if (url == 'http://' || K.invalidUrl(url)) {
  7676. alert(self.lang('invalidUrl'));
  7677. urlBox[0].focus();
  7678. return;
  7679. }
  7680. if (!/^\d*$/.test(width)) {
  7681. alert(self.lang('invalidWidth'));
  7682. widthBox[0].focus();
  7683. return;
  7684. }
  7685. if (!/^\d*$/.test(height)) {
  7686. alert(self.lang('invalidHeight'));
  7687. heightBox[0].focus();
  7688. return;
  7689. }
  7690. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7691. src : url,
  7692. type : K.mediaType(url),
  7693. width : width,
  7694. height : height,
  7695. autostart : autostartBox[0].checked ? 'true' : 'false',
  7696. loop : 'true'
  7697. });
  7698. self.insertHtml(html).hideDialog().focus();
  7699. }
  7700. }
  7701. }),
  7702. div = dialog.div,
  7703. urlBox = K('[name="url"]', div),
  7704. viewServerBtn = K('[name="viewServer"]', div),
  7705. widthBox = K('[name="width"]', div),
  7706. heightBox = K('[name="height"]', div),
  7707. autostartBox = K('[name="autostart"]', div);
  7708. urlBox.val('http://');
  7709. if (allowMediaUpload) {
  7710. var uploadbutton = K.uploadbutton({
  7711. button : K('.ke-upload-button', div)[0],
  7712. fieldName : filePostName,
  7713. extraParams : extraParams,
  7714. url : K.addParam(uploadJson, 'dir=media'),
  7715. afterUpload : function(data) {
  7716. dialog.hideLoading();
  7717. if (data.error === 0) {
  7718. var url = data.url;
  7719. if (formatUploadUrl) {
  7720. url = K.formatUrl(url, 'absolute');
  7721. }
  7722. urlBox.val(url);
  7723. if (self.afterUpload) {
  7724. self.afterUpload.call(self, url, data, name);
  7725. }
  7726. alert(self.lang('uploadSuccess'));
  7727. } else {
  7728. alert(data.message);
  7729. }
  7730. },
  7731. afterError : function(html) {
  7732. dialog.hideLoading();
  7733. self.errorDialog(html);
  7734. }
  7735. });
  7736. uploadbutton.fileBox.change(function(e) {
  7737. dialog.showLoading(self.lang('uploadLoading'));
  7738. uploadbutton.submit();
  7739. });
  7740. } else {
  7741. K('.ke-upload-button', div).hide();
  7742. }
  7743. if (allowFileManager) {
  7744. viewServerBtn.click(function(e) {
  7745. self.loadPlugin('filemanager', function() {
  7746. self.plugin.filemanagerDialog({
  7747. viewType : 'LIST',
  7748. dirName : 'media',
  7749. clickFn : function(url, title) {
  7750. if (self.dialogs.length > 1) {
  7751. K('[name="url"]', div).val(url);
  7752. if (self.afterSelectFile) {
  7753. self.afterSelectFile.call(self, url);
  7754. }
  7755. self.hideDialog();
  7756. }
  7757. }
  7758. });
  7759. });
  7760. });
  7761. } else {
  7762. viewServerBtn.hide();
  7763. }
  7764. var img = self.plugin.getSelectedMedia();
  7765. if (img) {
  7766. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7767. urlBox.val(attrs.src);
  7768. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7769. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7770. autostartBox[0].checked = (attrs.autostart === 'true');
  7771. }
  7772. urlBox[0].focus();
  7773. urlBox[0].select();
  7774. },
  7775. 'delete' : function() {
  7776. self.plugin.getSelectedMedia().remove();
  7777. self.addBookmark();
  7778. }
  7779. };
  7780. self.clickToolbar(name, self.plugin.media.edit);
  7781. });
  7782. /*******************************************************************************
  7783. * KindEditor - WYSIWYG HTML Editor for Internet
  7784. * Copyright (C) 2006-2011 kindsoft.net
  7785. *
  7786. * @author Roddy <luolonghao@gmail.com>
  7787. * @site http://www.kindsoft.net/
  7788. * @licence http://www.kindsoft.net/license.php
  7789. *******************************************************************************/
  7790. (function(K) {
  7791. function KSWFUpload(options) {
  7792. this.init(options);
  7793. }
  7794. K.extend(KSWFUpload, {
  7795. init : function(options) {
  7796. var self = this;
  7797. options.afterError = options.afterError || function(str) {
  7798. alert(str);
  7799. };
  7800. self.options = options;
  7801. self.progressbars = {};
  7802. self.div = K(options.container).html([
  7803. '<div class="ke-swfupload">',
  7804. '<div class="ke-swfupload-top">',
  7805. '<div class="ke-inline-block ke-swfupload-button">',
  7806. '<input type="button" value="Browse" />',
  7807. '</div>',
  7808. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7809. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7810. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7811. '</span>',
  7812. '</div>',
  7813. '<div class="ke-swfupload-body"></div>',
  7814. '</div>'
  7815. ].join(''));
  7816. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7817. function showError(itemDiv, msg) {
  7818. K('.ke-status > div', itemDiv).hide();
  7819. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7820. }
  7821. var settings = {
  7822. debug : false,
  7823. upload_url : options.uploadUrl,
  7824. flash_url : options.flashUrl,
  7825. file_post_name : options.filePostName,
  7826. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7827. button_image_url: options.buttonImageUrl,
  7828. button_width: options.buttonWidth,
  7829. button_height: options.buttonHeight,
  7830. button_cursor : SWFUpload.CURSOR.HAND,
  7831. file_types : options.fileTypes,
  7832. file_types_description : options.fileTypesDesc,
  7833. file_upload_limit : options.fileUploadLimit,
  7834. file_size_limit : options.fileSizeLimit,
  7835. post_params : options.postParams,
  7836. file_queued_handler : function(file) {
  7837. file.url = self.options.fileIconUrl;
  7838. self.appendFile(file);
  7839. },
  7840. file_queue_error_handler : function(file, errorCode, message) {
  7841. var errorName = '';
  7842. switch (errorCode) {
  7843. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7844. errorName = options.queueLimitExceeded;
  7845. break;
  7846. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7847. errorName = options.fileExceedsSizeLimit;
  7848. break;
  7849. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7850. errorName = options.zeroByteFile;
  7851. break;
  7852. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7853. errorName = options.invalidFiletype;
  7854. break;
  7855. default:
  7856. errorName = options.unknownError;
  7857. break;
  7858. }
  7859. K.DEBUG && alert(errorName);
  7860. },
  7861. upload_start_handler : function(file) {
  7862. var self = this;
  7863. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7864. K('.ke-status > div', itemDiv).hide();
  7865. K('.ke-progressbar', itemDiv).show();
  7866. },
  7867. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7868. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7869. var progressbar = self.progressbars[file.id];
  7870. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7871. progressbar.percent.html(percent + '%');
  7872. },
  7873. upload_error_handler : function(file, errorCode, message) {
  7874. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7875. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7876. showError(itemDiv, self.options.errorMessage);
  7877. }
  7878. },
  7879. upload_success_handler : function(file, serverData) {
  7880. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7881. var data = {};
  7882. try {
  7883. data = K.json(serverData);
  7884. } catch (e) {
  7885. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7886. }
  7887. if (data.error !== 0) {
  7888. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7889. return;
  7890. }
  7891. file.url = data.url;
  7892. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7893. K('.ke-status > div', itemDiv).hide();
  7894. }
  7895. };
  7896. self.swfu = new SWFUpload(settings);
  7897. K('.ke-swfupload-startupload input', self.div).click(function() {
  7898. self.swfu.startUpload();
  7899. });
  7900. },
  7901. getUrlList : function() {
  7902. var list = [];
  7903. K('.ke-img', self.bodyDiv).each(function() {
  7904. var img = K(this);
  7905. var status = img.attr('data-status');
  7906. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7907. list.push(img.data('data'));
  7908. }
  7909. });
  7910. return list;
  7911. },
  7912. removeFile : function(fileId) {
  7913. var self = this;
  7914. self.swfu.cancelUpload(fileId);
  7915. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7916. K('.ke-photo', itemDiv).unbind();
  7917. K('.ke-delete', itemDiv).unbind();
  7918. itemDiv.remove();
  7919. },
  7920. removeFiles : function() {
  7921. var self = this;
  7922. K('.ke-item', self.bodyDiv).each(function() {
  7923. self.removeFile(K(this).attr('data-id'));
  7924. });
  7925. },
  7926. appendFile : function(file) {
  7927. var self = this;
  7928. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7929. self.bodyDiv.append(itemDiv);
  7930. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7931. .mouseover(function(e) {
  7932. K(this).addClass('ke-on');
  7933. })
  7934. .mouseout(function(e) {
  7935. K(this).removeClass('ke-on');
  7936. });
  7937. itemDiv.append(photoDiv);
  7938. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7939. photoDiv.append(img);
  7940. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  7941. self.removeFile(file.id);
  7942. });
  7943. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7944. K(['<div class="ke-progressbar">',
  7945. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7946. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7947. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7948. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7949. self.progressbars[file.id] = {
  7950. bar : K('.ke-progressbar-bar-inner', photoDiv),
  7951. percent : K('.ke-progressbar-percent', photoDiv)
  7952. };
  7953. },
  7954. remove : function() {
  7955. this.removeFiles();
  7956. this.swfu.destroy();
  7957. this.div.html('');
  7958. }
  7959. });
  7960. K.swfupload = function(element, options) {
  7961. return new KSWFUpload(element, options);
  7962. };
  7963. })(KindEditor);
  7964. KindEditor.plugin('multiimage', function(K) {
  7965. var self = this, name = 'multiimage',
  7966. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7967. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7968. imgPath = self.pluginsPath + 'multiimage/images/',
  7969. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  7970. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  7971. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  7972. filePostName = K.undef(self.filePostName, 'imgFile'),
  7973. lang = self.lang(name + '.');
  7974. self.plugin.multiImageDialog = function(options) {
  7975. var clickFn = options.clickFn,
  7976. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  7977. var html = [
  7978. '<div style="padding:20px;">',
  7979. '<div class="swfupload">',
  7980. '</div>',
  7981. '</div>'
  7982. ].join('');
  7983. var dialog = self.createDialog({
  7984. name : name,
  7985. width : 650,
  7986. height : 510,
  7987. title : self.lang(name),
  7988. body : html,
  7989. previewBtn : {
  7990. name : lang.insertAll,
  7991. click : function(e) {
  7992. clickFn.call(self, swfupload.getUrlList());
  7993. }
  7994. },
  7995. yesBtn : {
  7996. name : lang.clearAll,
  7997. click : function(e) {
  7998. swfupload.removeFiles();
  7999. }
  8000. },
  8001. beforeRemove : function() {
  8002. if (!K.IE || K.V <= 8) {
  8003. swfupload.remove();
  8004. }
  8005. }
  8006. }),
  8007. div = dialog.div;
  8008. var swfupload = K.swfupload({
  8009. container : K('.swfupload', div),
  8010. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8011. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8012. buttonHeight : 23,
  8013. fileIconUrl : imgPath + 'image.png',
  8014. uploadDesc : uploadDesc,
  8015. startButtonValue : lang.startUpload,
  8016. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8017. flashUrl : imgPath + 'swfupload.swf',
  8018. filePostName : filePostName,
  8019. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8020. fileTypesDesc : 'Image Files',
  8021. fileUploadLimit : imageUploadLimit,
  8022. fileSizeLimit : imageSizeLimit,
  8023. postParams : K.undef(self.extraFileUploadParams, {}),
  8024. queueLimitExceeded : lang.queueLimitExceeded,
  8025. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8026. zeroByteFile : lang.zeroByteFile,
  8027. invalidFiletype : lang.invalidFiletype,
  8028. unknownError : lang.unknownError,
  8029. pendingMessage : lang.pending,
  8030. errorMessage : lang.uploadError,
  8031. afterError : function(html) {
  8032. self.errorDialog(html);
  8033. }
  8034. });
  8035. return dialog;
  8036. };
  8037. self.clickToolbar(name, function() {
  8038. self.plugin.multiImageDialog({
  8039. clickFn : function (urlList) {
  8040. if (urlList.length === 0) {
  8041. return;
  8042. }
  8043. K.each(urlList, function(i, data) {
  8044. if (self.afterUpload) {
  8045. self.afterUpload.call(self, data.url, data, 'multiimage');
  8046. }
  8047. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8048. });
  8049. setTimeout(function() {
  8050. self.hideDialog().focus();
  8051. }, 0);
  8052. }
  8053. });
  8054. });
  8055. });
  8056. /* ******************* */
  8057. /* Constructor & Init */
  8058. /* ******************* */
  8059. (function() {
  8060. window.SWFUpload = function (settings) {
  8061. this.initSWFUpload(settings);
  8062. };
  8063. SWFUpload.prototype.initSWFUpload = function (settings) {
  8064. try {
  8065. this.customSettings = {};
  8066. this.settings = settings;
  8067. this.eventQueue = [];
  8068. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8069. this.movieElement = null;
  8070. SWFUpload.instances[this.movieName] = this;
  8071. this.initSettings();
  8072. this.loadFlash();
  8073. this.displayDebugInfo();
  8074. } catch (ex) {
  8075. delete SWFUpload.instances[this.movieName];
  8076. throw ex;
  8077. }
  8078. };
  8079. /* *************** */
  8080. /* Static Members */
  8081. /* *************** */
  8082. SWFUpload.instances = {};
  8083. SWFUpload.movieCount = 0;
  8084. SWFUpload.version = "2.2.0 2009-03-25";
  8085. SWFUpload.QUEUE_ERROR = {
  8086. QUEUE_LIMIT_EXCEEDED : -100,
  8087. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8088. ZERO_BYTE_FILE : -120,
  8089. INVALID_FILETYPE : -130
  8090. };
  8091. SWFUpload.UPLOAD_ERROR = {
  8092. HTTP_ERROR : -200,
  8093. MISSING_UPLOAD_URL : -210,
  8094. IO_ERROR : -220,
  8095. SECURITY_ERROR : -230,
  8096. UPLOAD_LIMIT_EXCEEDED : -240,
  8097. UPLOAD_FAILED : -250,
  8098. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8099. FILE_VALIDATION_FAILED : -270,
  8100. FILE_CANCELLED : -280,
  8101. UPLOAD_STOPPED : -290
  8102. };
  8103. SWFUpload.FILE_STATUS = {
  8104. QUEUED : -1,
  8105. IN_PROGRESS : -2,
  8106. ERROR : -3,
  8107. COMPLETE : -4,
  8108. CANCELLED : -5
  8109. };
  8110. SWFUpload.BUTTON_ACTION = {
  8111. SELECT_FILE : -100,
  8112. SELECT_FILES : -110,
  8113. START_UPLOAD : -120
  8114. };
  8115. SWFUpload.CURSOR = {
  8116. ARROW : -1,
  8117. HAND : -2
  8118. };
  8119. SWFUpload.WINDOW_MODE = {
  8120. WINDOW : "window",
  8121. TRANSPARENT : "transparent",
  8122. OPAQUE : "opaque"
  8123. };
  8124. SWFUpload.completeURL = function(url) {
  8125. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8126. return url;
  8127. }
  8128. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8129. var indexSlash = window.location.pathname.lastIndexOf("/");
  8130. var path;
  8131. if (indexSlash <= 0) {
  8132. path = "/";
  8133. } else {
  8134. path = window.location.pathname.substr(0, indexSlash) + "/";
  8135. }
  8136. return /*currentURL +*/ path + url;
  8137. };
  8138. /* ******************** */
  8139. /* Instance Members */
  8140. /* ******************** */
  8141. SWFUpload.prototype.initSettings = function () {
  8142. this.ensureDefault = function (settingName, defaultValue) {
  8143. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8144. };
  8145. this.ensureDefault("upload_url", "");
  8146. this.ensureDefault("preserve_relative_urls", false);
  8147. this.ensureDefault("file_post_name", "Filedata");
  8148. this.ensureDefault("post_params", {});
  8149. this.ensureDefault("use_query_string", false);
  8150. this.ensureDefault("requeue_on_error", false);
  8151. this.ensureDefault("http_success", []);
  8152. this.ensureDefault("assume_success_timeout", 0);
  8153. this.ensureDefault("file_types", "*.*");
  8154. this.ensureDefault("file_types_description", "All Files");
  8155. this.ensureDefault("file_size_limit", 0);
  8156. this.ensureDefault("file_upload_limit", 0);
  8157. this.ensureDefault("file_queue_limit", 0);
  8158. this.ensureDefault("flash_url", "swfupload.swf");
  8159. this.ensureDefault("prevent_swf_caching", true);
  8160. this.ensureDefault("button_image_url", "");
  8161. this.ensureDefault("button_width", 1);
  8162. this.ensureDefault("button_height", 1);
  8163. this.ensureDefault("button_text", "");
  8164. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8165. this.ensureDefault("button_text_top_padding", 0);
  8166. this.ensureDefault("button_text_left_padding", 0);
  8167. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8168. this.ensureDefault("button_disabled", false);
  8169. this.ensureDefault("button_placeholder_id", "");
  8170. this.ensureDefault("button_placeholder", null);
  8171. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8172. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8173. this.ensureDefault("debug", false);
  8174. this.settings.debug_enabled = this.settings.debug;
  8175. this.settings.return_upload_start_handler = this.returnUploadStart;
  8176. this.ensureDefault("swfupload_loaded_handler", null);
  8177. this.ensureDefault("file_dialog_start_handler", null);
  8178. this.ensureDefault("file_queued_handler", null);
  8179. this.ensureDefault("file_queue_error_handler", null);
  8180. this.ensureDefault("file_dialog_complete_handler", null);
  8181. this.ensureDefault("upload_start_handler", null);
  8182. this.ensureDefault("upload_progress_handler", null);
  8183. this.ensureDefault("upload_error_handler", null);
  8184. this.ensureDefault("upload_success_handler", null);
  8185. this.ensureDefault("upload_complete_handler", null);
  8186. this.ensureDefault("debug_handler", this.debugMessage);
  8187. this.ensureDefault("custom_settings", {});
  8188. this.customSettings = this.settings.custom_settings;
  8189. if (!!this.settings.prevent_swf_caching) {
  8190. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8191. }
  8192. if (!this.settings.preserve_relative_urls) {
  8193. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8194. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8195. }
  8196. delete this.ensureDefault;
  8197. };
  8198. SWFUpload.prototype.loadFlash = function () {
  8199. var targetElement, tempParent;
  8200. if (document.getElementById(this.movieName) !== null) {
  8201. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8202. }
  8203. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8204. if (targetElement == undefined) {
  8205. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8206. }
  8207. tempParent = document.createElement("div");
  8208. tempParent.innerHTML = this.getFlashHTML();
  8209. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8210. if (window[this.movieName] == undefined) {
  8211. window[this.movieName] = this.getMovieElement();
  8212. }
  8213. };
  8214. SWFUpload.prototype.getFlashHTML = function () {
  8215. var classid = '';
  8216. if (KindEditor.IE && KindEditor.V > 8) {
  8217. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8218. }
  8219. 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">',
  8220. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8221. '<param name="movie" value="', this.settings.flash_url, '" />',
  8222. '<param name="quality" value="high" />',
  8223. '<param name="menu" value="false" />',
  8224. '<param name="allowScriptAccess" value="always" />',
  8225. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8226. '</object>'].join("");
  8227. };
  8228. SWFUpload.prototype.getFlashVars = function () {
  8229. var paramString = this.buildParamString();
  8230. var httpSuccessString = this.settings.http_success.join(",");
  8231. return ["movieName=", encodeURIComponent(this.movieName),
  8232. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8233. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8234. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8235. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8236. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8237. "&amp;params=", encodeURIComponent(paramString),
  8238. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8239. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8240. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8241. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8242. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8243. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8244. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8245. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8246. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8247. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8248. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8249. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8250. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8251. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8252. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8253. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8254. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8255. ].join("");
  8256. };
  8257. SWFUpload.prototype.getMovieElement = function () {
  8258. if (this.movieElement == undefined) {
  8259. this.movieElement = document.getElementById(this.movieName);
  8260. }
  8261. if (this.movieElement === null) {
  8262. throw "Could not find Flash element";
  8263. }
  8264. return this.movieElement;
  8265. };
  8266. SWFUpload.prototype.buildParamString = function () {
  8267. var postParams = this.settings.post_params;
  8268. var paramStringPairs = [];
  8269. if (typeof(postParams) === "object") {
  8270. for (var name in postParams) {
  8271. if (postParams.hasOwnProperty(name)) {
  8272. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8273. }
  8274. }
  8275. }
  8276. return paramStringPairs.join("&amp;");
  8277. };
  8278. SWFUpload.prototype.destroy = function () {
  8279. try {
  8280. this.cancelUpload(null, false);
  8281. var movieElement = null;
  8282. movieElement = this.getMovieElement();
  8283. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8284. for (var i in movieElement) {
  8285. try {
  8286. if (typeof(movieElement[i]) === "function") {
  8287. movieElement[i] = null;
  8288. }
  8289. } catch (ex1) {}
  8290. }
  8291. try {
  8292. movieElement.parentNode.removeChild(movieElement);
  8293. } catch (ex) {}
  8294. }
  8295. window[this.movieName] = null;
  8296. SWFUpload.instances[this.movieName] = null;
  8297. delete SWFUpload.instances[this.movieName];
  8298. this.movieElement = null;
  8299. this.settings = null;
  8300. this.customSettings = null;
  8301. this.eventQueue = null;
  8302. this.movieName = null;
  8303. return true;
  8304. } catch (ex2) {
  8305. return false;
  8306. }
  8307. };
  8308. SWFUpload.prototype.displayDebugInfo = function () {
  8309. this.debug(
  8310. [
  8311. "---SWFUpload Instance Info---\n",
  8312. "Version: ", SWFUpload.version, "\n",
  8313. "Movie Name: ", this.movieName, "\n",
  8314. "Settings:\n",
  8315. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8316. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8317. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8318. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8319. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8320. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8321. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8322. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8323. "\t", "file_types: ", this.settings.file_types, "\n",
  8324. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8325. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8326. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8327. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8328. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8329. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8330. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8331. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8332. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8333. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8334. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8335. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8336. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8337. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8338. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8339. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8340. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8341. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8342. "Event Handlers:\n",
  8343. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8344. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8345. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8346. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8347. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8348. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8349. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8350. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8351. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8352. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8353. ].join("")
  8354. );
  8355. };
  8356. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8357. the maintain v2 API compatibility
  8358. */
  8359. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8360. if (value == undefined) {
  8361. return (this.settings[name] = default_value);
  8362. } else {
  8363. return (this.settings[name] = value);
  8364. }
  8365. };
  8366. SWFUpload.prototype.getSetting = function (name) {
  8367. if (this.settings[name] != undefined) {
  8368. return this.settings[name];
  8369. }
  8370. return "";
  8371. };
  8372. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8373. argumentArray = argumentArray || [];
  8374. var movieElement = this.getMovieElement();
  8375. var returnValue, returnString;
  8376. try {
  8377. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8378. returnValue = eval(returnString);
  8379. } catch (ex) {
  8380. throw "Call to " + functionName + " failed";
  8381. }
  8382. if (returnValue != undefined && typeof returnValue.post === "object") {
  8383. returnValue = this.unescapeFilePostParams(returnValue);
  8384. }
  8385. return returnValue;
  8386. };
  8387. /* *****************************
  8388. -- Flash control methods --
  8389. Your UI should use these
  8390. to operate SWFUpload
  8391. ***************************** */
  8392. SWFUpload.prototype.selectFile = function () {
  8393. this.callFlash("SelectFile");
  8394. };
  8395. SWFUpload.prototype.selectFiles = function () {
  8396. this.callFlash("SelectFiles");
  8397. };
  8398. SWFUpload.prototype.startUpload = function (fileID) {
  8399. this.callFlash("StartUpload", [fileID]);
  8400. };
  8401. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8402. if (triggerErrorEvent !== false) {
  8403. triggerErrorEvent = true;
  8404. }
  8405. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8406. };
  8407. SWFUpload.prototype.stopUpload = function () {
  8408. this.callFlash("StopUpload");
  8409. };
  8410. /* ************************
  8411. * Settings methods
  8412. * These methods change the SWFUpload settings.
  8413. * SWFUpload settings should not be changed directly on the settings object
  8414. * since many of the settings need to be passed to Flash in order to take
  8415. * effect.
  8416. * *********************** */
  8417. SWFUpload.prototype.getStats = function () {
  8418. return this.callFlash("GetStats");
  8419. };
  8420. SWFUpload.prototype.setStats = function (statsObject) {
  8421. this.callFlash("SetStats", [statsObject]);
  8422. };
  8423. SWFUpload.prototype.getFile = function (fileID) {
  8424. if (typeof(fileID) === "number") {
  8425. return this.callFlash("GetFileByIndex", [fileID]);
  8426. } else {
  8427. return this.callFlash("GetFile", [fileID]);
  8428. }
  8429. };
  8430. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8431. return this.callFlash("AddFileParam", [fileID, name, value]);
  8432. };
  8433. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8434. this.callFlash("RemoveFileParam", [fileID, name]);
  8435. };
  8436. SWFUpload.prototype.setUploadURL = function (url) {
  8437. this.settings.upload_url = url.toString();
  8438. this.callFlash("SetUploadURL", [url]);
  8439. };
  8440. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8441. this.settings.post_params = paramsObject;
  8442. this.callFlash("SetPostParams", [paramsObject]);
  8443. };
  8444. SWFUpload.prototype.addPostParam = function (name, value) {
  8445. this.settings.post_params[name] = value;
  8446. this.callFlash("SetPostParams", [this.settings.post_params]);
  8447. };
  8448. SWFUpload.prototype.removePostParam = function (name) {
  8449. delete this.settings.post_params[name];
  8450. this.callFlash("SetPostParams", [this.settings.post_params]);
  8451. };
  8452. SWFUpload.prototype.setFileTypes = function (types, description) {
  8453. this.settings.file_types = types;
  8454. this.settings.file_types_description = description;
  8455. this.callFlash("SetFileTypes", [types, description]);
  8456. };
  8457. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8458. this.settings.file_size_limit = fileSizeLimit;
  8459. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8460. };
  8461. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8462. this.settings.file_upload_limit = fileUploadLimit;
  8463. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8464. };
  8465. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8466. this.settings.file_queue_limit = fileQueueLimit;
  8467. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8468. };
  8469. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8470. this.settings.file_post_name = filePostName;
  8471. this.callFlash("SetFilePostName", [filePostName]);
  8472. };
  8473. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8474. this.settings.use_query_string = useQueryString;
  8475. this.callFlash("SetUseQueryString", [useQueryString]);
  8476. };
  8477. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8478. this.settings.requeue_on_error = requeueOnError;
  8479. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8480. };
  8481. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8482. if (typeof http_status_codes === "string") {
  8483. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8484. }
  8485. this.settings.http_success = http_status_codes;
  8486. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8487. };
  8488. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8489. this.settings.assume_success_timeout = timeout_seconds;
  8490. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8491. };
  8492. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8493. this.settings.debug_enabled = debugEnabled;
  8494. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8495. };
  8496. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8497. if (buttonImageURL == undefined) {
  8498. buttonImageURL = "";
  8499. }
  8500. this.settings.button_image_url = buttonImageURL;
  8501. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8502. };
  8503. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8504. this.settings.button_width = width;
  8505. this.settings.button_height = height;
  8506. var movie = this.getMovieElement();
  8507. if (movie != undefined) {
  8508. movie.style.width = width + "px";
  8509. movie.style.height = height + "px";
  8510. }
  8511. this.callFlash("SetButtonDimensions", [width, height]);
  8512. };
  8513. SWFUpload.prototype.setButtonText = function (html) {
  8514. this.settings.button_text = html;
  8515. this.callFlash("SetButtonText", [html]);
  8516. };
  8517. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8518. this.settings.button_text_top_padding = top;
  8519. this.settings.button_text_left_padding = left;
  8520. this.callFlash("SetButtonTextPadding", [left, top]);
  8521. };
  8522. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8523. this.settings.button_text_style = css;
  8524. this.callFlash("SetButtonTextStyle", [css]);
  8525. };
  8526. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8527. this.settings.button_disabled = isDisabled;
  8528. this.callFlash("SetButtonDisabled", [isDisabled]);
  8529. };
  8530. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8531. this.settings.button_action = buttonAction;
  8532. this.callFlash("SetButtonAction", [buttonAction]);
  8533. };
  8534. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8535. this.settings.button_cursor = cursor;
  8536. this.callFlash("SetButtonCursor", [cursor]);
  8537. };
  8538. /* *******************************
  8539. Flash Event Interfaces
  8540. These functions are used by Flash to trigger the various
  8541. events.
  8542. All these functions a Private.
  8543. Because the ExternalInterface library is buggy the event calls
  8544. are added to a queue and the queue then executed by a setTimeout.
  8545. This ensures that events are executed in a determinate order and that
  8546. the ExternalInterface bugs are avoided.
  8547. ******************************* */
  8548. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8549. if (argumentArray == undefined) {
  8550. argumentArray = [];
  8551. } else if (!(argumentArray instanceof Array)) {
  8552. argumentArray = [argumentArray];
  8553. }
  8554. var self = this;
  8555. if (typeof this.settings[handlerName] === "function") {
  8556. this.eventQueue.push(function () {
  8557. this.settings[handlerName].apply(this, argumentArray);
  8558. });
  8559. setTimeout(function () {
  8560. self.executeNextEvent();
  8561. }, 0);
  8562. } else if (this.settings[handlerName] !== null) {
  8563. throw "Event handler " + handlerName + " is unknown or is not a function";
  8564. }
  8565. };
  8566. SWFUpload.prototype.executeNextEvent = function () {
  8567. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8568. if (typeof(f) === "function") {
  8569. f.apply(this);
  8570. }
  8571. };
  8572. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8573. var reg = /[$]([0-9a-f]{4})/i;
  8574. var unescapedPost = {};
  8575. var uk;
  8576. if (file != undefined) {
  8577. for (var k in file.post) {
  8578. if (file.post.hasOwnProperty(k)) {
  8579. uk = k;
  8580. var match;
  8581. while ((match = reg.exec(uk)) !== null) {
  8582. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8583. }
  8584. unescapedPost[uk] = file.post[k];
  8585. }
  8586. }
  8587. file.post = unescapedPost;
  8588. }
  8589. return file;
  8590. };
  8591. SWFUpload.prototype.testExternalInterface = function () {
  8592. try {
  8593. return this.callFlash("TestExternalInterface");
  8594. } catch (ex) {
  8595. return false;
  8596. }
  8597. };
  8598. SWFUpload.prototype.flashReady = function () {
  8599. var movieElement = this.getMovieElement();
  8600. if (!movieElement) {
  8601. this.debug("Flash called back ready but the flash movie can't be found.");
  8602. return;
  8603. }
  8604. this.cleanUp(movieElement);
  8605. this.queueEvent("swfupload_loaded_handler");
  8606. };
  8607. SWFUpload.prototype.cleanUp = function (movieElement) {
  8608. try {
  8609. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8610. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8611. for (var key in movieElement) {
  8612. try {
  8613. if (typeof(movieElement[key]) === "function") {
  8614. movieElement[key] = null;
  8615. }
  8616. } catch (ex) {
  8617. }
  8618. }
  8619. }
  8620. } catch (ex1) {
  8621. }
  8622. window["__flash__removeCallback"] = function (instance, name) {
  8623. try {
  8624. if (instance) {
  8625. instance[name] = null;
  8626. }
  8627. } catch (flashEx) {
  8628. }
  8629. };
  8630. };
  8631. /* This is a chance to do something before the browse window opens */
  8632. SWFUpload.prototype.fileDialogStart = function () {
  8633. this.queueEvent("file_dialog_start_handler");
  8634. };
  8635. /* Called when a file is successfully added to the queue. */
  8636. SWFUpload.prototype.fileQueued = function (file) {
  8637. file = this.unescapeFilePostParams(file);
  8638. this.queueEvent("file_queued_handler", file);
  8639. };
  8640. /* Handle errors that occur when an attempt to queue a file fails. */
  8641. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8642. file = this.unescapeFilePostParams(file);
  8643. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8644. };
  8645. /* Called after the file dialog has closed and the selected files have been queued.
  8646. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8647. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8648. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8649. };
  8650. SWFUpload.prototype.uploadStart = function (file) {
  8651. file = this.unescapeFilePostParams(file);
  8652. this.queueEvent("return_upload_start_handler", file);
  8653. };
  8654. SWFUpload.prototype.returnUploadStart = function (file) {
  8655. var returnValue;
  8656. if (typeof this.settings.upload_start_handler === "function") {
  8657. file = this.unescapeFilePostParams(file);
  8658. returnValue = this.settings.upload_start_handler.call(this, file);
  8659. } else if (this.settings.upload_start_handler != undefined) {
  8660. throw "upload_start_handler must be a function";
  8661. }
  8662. if (returnValue === undefined) {
  8663. returnValue = true;
  8664. }
  8665. returnValue = !!returnValue;
  8666. this.callFlash("ReturnUploadStart", [returnValue]);
  8667. };
  8668. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8669. file = this.unescapeFilePostParams(file);
  8670. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8671. };
  8672. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8673. file = this.unescapeFilePostParams(file);
  8674. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8675. };
  8676. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8677. file = this.unescapeFilePostParams(file);
  8678. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8679. };
  8680. SWFUpload.prototype.uploadComplete = function (file) {
  8681. file = this.unescapeFilePostParams(file);
  8682. this.queueEvent("upload_complete_handler", file);
  8683. };
  8684. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8685. internal debug console. You can override this event and have messages written where you want. */
  8686. SWFUpload.prototype.debug = function (message) {
  8687. this.queueEvent("debug_handler", message);
  8688. };
  8689. /* **********************************
  8690. Debug Console
  8691. The debug console is a self contained, in page location
  8692. for debug message to be sent. The Debug Console adds
  8693. itself to the body if necessary.
  8694. The console is automatically scrolled as messages appear.
  8695. If you are using your own debug handler or when you deploy to production and
  8696. have debug disabled you can remove these functions to reduce the file size
  8697. and complexity.
  8698. ********************************** */
  8699. SWFUpload.prototype.debugMessage = function (message) {
  8700. if (this.settings.debug) {
  8701. var exceptionMessage, exceptionValues = [];
  8702. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8703. for (var key in message) {
  8704. if (message.hasOwnProperty(key)) {
  8705. exceptionValues.push(key + ": " + message[key]);
  8706. }
  8707. }
  8708. exceptionMessage = exceptionValues.join("\n") || "";
  8709. exceptionValues = exceptionMessage.split("\n");
  8710. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8711. SWFUpload.Console.writeLine(exceptionMessage);
  8712. } else {
  8713. SWFUpload.Console.writeLine(message);
  8714. }
  8715. }
  8716. };
  8717. SWFUpload.Console = {};
  8718. SWFUpload.Console.writeLine = function (message) {
  8719. var console, documentForm;
  8720. try {
  8721. console = document.getElementById("SWFUpload_Console");
  8722. if (!console) {
  8723. documentForm = document.createElement("form");
  8724. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8725. console = document.createElement("textarea");
  8726. console.id = "SWFUpload_Console";
  8727. console.style.fontFamily = "monospace";
  8728. console.setAttribute("wrap", "off");
  8729. console.wrap = "off";
  8730. console.style.overflow = "auto";
  8731. console.style.width = "700px";
  8732. console.style.height = "350px";
  8733. console.style.margin = "5px";
  8734. documentForm.appendChild(console);
  8735. }
  8736. console.value += message + "\n";
  8737. console.scrollTop = console.scrollHeight - console.clientHeight;
  8738. } catch (ex) {
  8739. alert("Exception: " + ex.name + " Message: " + ex.message);
  8740. }
  8741. };
  8742. })();
  8743. (function() {
  8744. /*
  8745. Queue Plug-in
  8746. Features:
  8747. *Adds a cancelQueue() method for cancelling the entire queue.
  8748. *All queued files are uploaded when startUpload() is called.
  8749. *If false is returned from uploadComplete then the queue upload is stopped.
  8750. If false is not returned (strict comparison) then the queue upload is continued.
  8751. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8752. Set the event handler with the queue_complete_handler setting.
  8753. */
  8754. if (typeof(SWFUpload) === "function") {
  8755. SWFUpload.queue = {};
  8756. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8757. return function () {
  8758. if (typeof(oldInitSettings) === "function") {
  8759. oldInitSettings.call(this);
  8760. }
  8761. this.queueSettings = {};
  8762. this.queueSettings.queue_cancelled_flag = false;
  8763. this.queueSettings.queue_upload_count = 0;
  8764. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8765. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8766. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8767. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8768. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8769. };
  8770. })(SWFUpload.prototype.initSettings);
  8771. SWFUpload.prototype.startUpload = function (fileID) {
  8772. this.queueSettings.queue_cancelled_flag = false;
  8773. this.callFlash("StartUpload", [fileID]);
  8774. };
  8775. SWFUpload.prototype.cancelQueue = function () {
  8776. this.queueSettings.queue_cancelled_flag = true;
  8777. this.stopUpload();
  8778. var stats = this.getStats();
  8779. while (stats.files_queued > 0) {
  8780. this.cancelUpload();
  8781. stats = this.getStats();
  8782. }
  8783. };
  8784. SWFUpload.queue.uploadStartHandler = function (file) {
  8785. var returnValue;
  8786. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8787. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8788. }
  8789. returnValue = (returnValue === false) ? false : true;
  8790. this.queueSettings.queue_cancelled_flag = !returnValue;
  8791. return returnValue;
  8792. };
  8793. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8794. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8795. var continueUpload;
  8796. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8797. this.queueSettings.queue_upload_count++;
  8798. }
  8799. if (typeof(user_upload_complete_handler) === "function") {
  8800. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8801. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8802. continueUpload = false;
  8803. } else {
  8804. continueUpload = true;
  8805. }
  8806. if (continueUpload) {
  8807. var stats = this.getStats();
  8808. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8809. this.startUpload();
  8810. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8811. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8812. this.queueSettings.queue_upload_count = 0;
  8813. } else {
  8814. this.queueSettings.queue_cancelled_flag = false;
  8815. this.queueSettings.queue_upload_count = 0;
  8816. }
  8817. }
  8818. };
  8819. }
  8820. })();
  8821. /*******************************************************************************
  8822. * KindEditor - WYSIWYG HTML Editor for Internet
  8823. * Copyright (C) 2006-2011 kindsoft.net
  8824. *
  8825. * @author Roddy <luolonghao@gmail.com>
  8826. * @site http://www.kindsoft.net/
  8827. * @licence http://www.kindsoft.net/license.php
  8828. *******************************************************************************/
  8829. KindEditor.plugin('pagebreak', function(K) {
  8830. var self = this;
  8831. var name = 'pagebreak';
  8832. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8833. self.clickToolbar(name, function() {
  8834. var cmd = self.cmd, range = cmd.range;
  8835. self.focus();
  8836. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8837. self.insertHtml(pagebreakHtml + tail);
  8838. if (tail !== '') {
  8839. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8840. range.selectNodeContents(p[0]);
  8841. p.removeAttr('id');
  8842. cmd.select();
  8843. }
  8844. });
  8845. });
  8846. /*******************************************************************************
  8847. * KindEditor - WYSIWYG HTML Editor for Internet
  8848. * Copyright (C) 2006-2011 kindsoft.net
  8849. *
  8850. * @author Roddy <luolonghao@gmail.com>
  8851. * @site http://www.kindsoft.net/
  8852. * @licence http://www.kindsoft.net/license.php
  8853. *******************************************************************************/
  8854. KindEditor.plugin('plainpaste', function(K) {
  8855. var self = this, name = 'plainpaste';
  8856. self.clickToolbar(name, function() {
  8857. var lang = self.lang(name + '.'),
  8858. html = '<div style="padding:10px 20px;">' +
  8859. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  8860. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  8861. '</div>',
  8862. dialog = self.createDialog({
  8863. name : name,
  8864. width : 450,
  8865. title : self.lang(name),
  8866. body : html,
  8867. yesBtn : {
  8868. name : self.lang('yes'),
  8869. click : function(e) {
  8870. var html = textarea.val();
  8871. html = K.escape(html);
  8872. html = html.replace(/ {2}/g, ' &nbsp;');
  8873. if (self.newlineTag == 'p') {
  8874. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  8875. } else {
  8876. html = html.replace(/\n/g, '<br />$&');
  8877. }
  8878. self.insertHtml(html).hideDialog().focus();
  8879. }
  8880. }
  8881. }),
  8882. textarea = K('textarea', dialog.div);
  8883. textarea[0].focus();
  8884. });
  8885. });
  8886. /*******************************************************************************
  8887. * KindEditor - WYSIWYG HTML Editor for Internet
  8888. * Copyright (C) 2006-2011 kindsoft.net
  8889. *
  8890. * @author Roddy <luolonghao@gmail.com>
  8891. * @site http://www.kindsoft.net/
  8892. * @licence http://www.kindsoft.net/license.php
  8893. *******************************************************************************/
  8894. KindEditor.plugin('preview', function(K) {
  8895. var self = this, name = 'preview', undefined;
  8896. self.clickToolbar(name, function() {
  8897. var lang = self.lang(name + '.'),
  8898. html = '<div style="padding:10px 20px;">' +
  8899. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  8900. '</div>',
  8901. dialog = self.createDialog({
  8902. name : name,
  8903. width : 750,
  8904. title : self.lang(name),
  8905. body : html
  8906. }),
  8907. iframe = K('iframe', dialog.div),
  8908. doc = K.iframeDoc(iframe);
  8909. doc.open();
  8910. doc.write(self.fullHtml());
  8911. doc.close();
  8912. K(doc.body).css('background-color', '#FFF');
  8913. iframe[0].contentWindow.focus();
  8914. });
  8915. });
  8916. /*******************************************************************************
  8917. * KindEditor - WYSIWYG HTML Editor for Internet
  8918. * Copyright (C) 2006-2011 kindsoft.net
  8919. *
  8920. * @author Roddy <luolonghao@gmail.com>
  8921. * @site http://www.kindsoft.net/
  8922. * @licence http://www.kindsoft.net/license.php
  8923. *******************************************************************************/
  8924. KindEditor.plugin('quickformat', function(K) {
  8925. var self = this, name = 'quickformat',
  8926. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  8927. function getFirstChild(knode) {
  8928. var child = knode.first();
  8929. while (child && child.first()) {
  8930. child = child.first();
  8931. }
  8932. return child;
  8933. }
  8934. self.clickToolbar(name, function() {
  8935. self.focus();
  8936. var doc = self.edit.doc,
  8937. range = self.cmd.range,
  8938. child = K(doc.body).first(), next,
  8939. nodeList = [], subList = [],
  8940. bookmark = range.createBookmark(true);
  8941. while(child) {
  8942. next = child.next();
  8943. var firstChild = getFirstChild(child);
  8944. if (!firstChild || firstChild.name != 'img') {
  8945. if (blockMap[child.name]) {
  8946. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  8947. child.css('text-indent', '2em');
  8948. } else {
  8949. subList.push(child);
  8950. }
  8951. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  8952. if (subList.length > 0) {
  8953. nodeList.push(subList);
  8954. }
  8955. subList = [];
  8956. }
  8957. }
  8958. child = next;
  8959. }
  8960. K.each(nodeList, function(i, subList) {
  8961. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  8962. subList[0].before(wrapper);
  8963. K.each(subList, function(i, knode) {
  8964. wrapper.append(knode);
  8965. });
  8966. });
  8967. range.moveToBookmark(bookmark);
  8968. self.addBookmark();
  8969. });
  8970. });
  8971. /*******************************************************************************
  8972. * KindEditor - WYSIWYG HTML Editor for Internet
  8973. * Copyright (C) 2006-2011 kindsoft.net
  8974. *
  8975. * @author Roddy <luolonghao@gmail.com>
  8976. * @site http://www.kindsoft.net/
  8977. * @licence http://www.kindsoft.net/license.php
  8978. *******************************************************************************/
  8979. KindEditor.plugin('table', function(K) {
  8980. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  8981. function _setColor(box, color) {
  8982. color = color.toUpperCase();
  8983. box.css('background-color', color);
  8984. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  8985. box.html(color);
  8986. }
  8987. var pickerList = [];
  8988. function _initColorPicker(dialogDiv, colorBox) {
  8989. colorBox.bind('click,mousedown', function(e){
  8990. e.stopPropagation();
  8991. });
  8992. function removePicker() {
  8993. K.each(pickerList, function() {
  8994. this.remove();
  8995. });
  8996. pickerList = [];
  8997. K(document).unbind('click,mousedown', removePicker);
  8998. dialogDiv.unbind('click,mousedown', removePicker);
  8999. }
  9000. colorBox.click(function(e) {
  9001. removePicker();
  9002. var box = K(this),
  9003. pos = box.pos();
  9004. var picker = K.colorpicker({
  9005. x : pos.x,
  9006. y : pos.y + box.height(),
  9007. z : 811214,
  9008. selectedColor : K(this).html(),
  9009. colors : self.colorTable,
  9010. noColor : self.lang('noColor'),
  9011. shadowMode : self.shadowMode,
  9012. click : function(color) {
  9013. _setColor(box, color);
  9014. removePicker();
  9015. }
  9016. });
  9017. pickerList.push(picker);
  9018. K(document).bind('click,mousedown', removePicker);
  9019. dialogDiv.bind('click,mousedown', removePicker);
  9020. });
  9021. }
  9022. function _getCellIndex(table, row, cell) {
  9023. var rowSpanCount = 0;
  9024. for (var i = 0, len = row.cells.length; i < len; i++) {
  9025. if (row.cells[i] == cell) {
  9026. break;
  9027. }
  9028. rowSpanCount += row.cells[i].rowSpan - 1;
  9029. }
  9030. return cell.cellIndex - rowSpanCount;
  9031. }
  9032. self.plugin.table = {
  9033. prop : function(isInsert) {
  9034. var html = [
  9035. '<div style="padding:20px;">',
  9036. '<div class="ke-dialog-row">',
  9037. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9038. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9039. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9040. '</div>',
  9041. '<div class="ke-dialog-row">',
  9042. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9043. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9044. '<select name="widthType">',
  9045. '<option value="%">' + lang.percent + '</option>',
  9046. '<option value="px">' + lang.px + '</option>',
  9047. '</select> &nbsp; ',
  9048. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9049. '<select name="heightType">',
  9050. '<option value="%">' + lang.percent + '</option>',
  9051. '<option value="px">' + lang.px + '</option>',
  9052. '</select>',
  9053. '</div>',
  9054. '<div class="ke-dialog-row">',
  9055. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9056. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9057. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9058. '</div>',
  9059. '<div class="ke-dialog-row">',
  9060. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9061. '<select id="keAlign" name="align">',
  9062. '<option value="">' + lang.alignDefault + '</option>',
  9063. '<option value="left">' + lang.alignLeft + '</option>',
  9064. '<option value="center">' + lang.alignCenter + '</option>',
  9065. '<option value="right">' + lang.alignRight + '</option>',
  9066. '</select>',
  9067. '</div>',
  9068. '<div class="ke-dialog-row">',
  9069. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9070. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9071. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9072. '</div>',
  9073. '<div class="ke-dialog-row">',
  9074. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9075. '<span class="ke-inline-block ke-input-color"></span>',
  9076. '</div>',
  9077. '</div>'
  9078. ].join('');
  9079. var bookmark = self.cmd.range.createBookmark();
  9080. var dialog = self.createDialog({
  9081. name : name,
  9082. width : 500,
  9083. title : self.lang(name),
  9084. body : html,
  9085. beforeRemove : function() {
  9086. colorBox.unbind();
  9087. },
  9088. yesBtn : {
  9089. name : self.lang('yes'),
  9090. click : function(e) {
  9091. var rows = rowsBox.val(),
  9092. cols = colsBox.val(),
  9093. width = widthBox.val(),
  9094. height = heightBox.val(),
  9095. widthType = widthTypeBox.val(),
  9096. heightType = heightTypeBox.val(),
  9097. padding = paddingBox.val(),
  9098. spacing = spacingBox.val(),
  9099. align = alignBox.val(),
  9100. border = borderBox.val(),
  9101. borderColor = K(colorBox[0]).html() || '',
  9102. bgColor = K(colorBox[1]).html() || '';
  9103. if (rows == 0 || !/^\d+$/.test(rows)) {
  9104. alert(self.lang('invalidRows'));
  9105. rowsBox[0].focus();
  9106. return;
  9107. }
  9108. if (cols == 0 || !/^\d+$/.test(cols)) {
  9109. alert(self.lang('invalidRows'));
  9110. colsBox[0].focus();
  9111. return;
  9112. }
  9113. if (!/^\d*$/.test(width)) {
  9114. alert(self.lang('invalidWidth'));
  9115. widthBox[0].focus();
  9116. return;
  9117. }
  9118. if (!/^\d*$/.test(height)) {
  9119. alert(self.lang('invalidHeight'));
  9120. heightBox[0].focus();
  9121. return;
  9122. }
  9123. if (!/^\d*$/.test(padding)) {
  9124. alert(self.lang('invalidPadding'));
  9125. paddingBox[0].focus();
  9126. return;
  9127. }
  9128. if (!/^\d*$/.test(spacing)) {
  9129. alert(self.lang('invalidSpacing'));
  9130. spacingBox[0].focus();
  9131. return;
  9132. }
  9133. if (!/^\d*$/.test(border)) {
  9134. alert(self.lang('invalidBorder'));
  9135. borderBox[0].focus();
  9136. return;
  9137. }
  9138. if (table) {
  9139. if (width !== '') {
  9140. table.width(width + widthType);
  9141. } else {
  9142. table.css('width', '');
  9143. }
  9144. if (table[0].width !== undefined) {
  9145. table.removeAttr('width');
  9146. }
  9147. if (height !== '') {
  9148. table.height(height + heightType);
  9149. } else {
  9150. table.css('height', '');
  9151. }
  9152. if (table[0].height !== undefined) {
  9153. table.removeAttr('height');
  9154. }
  9155. table.css('background-color', bgColor);
  9156. if (table[0].bgColor !== undefined) {
  9157. table.removeAttr('bgColor');
  9158. }
  9159. if (padding !== '') {
  9160. table[0].cellPadding = padding;
  9161. } else {
  9162. table.removeAttr('cellPadding');
  9163. }
  9164. if (spacing !== '') {
  9165. table[0].cellSpacing = spacing;
  9166. } else {
  9167. table.removeAttr('cellSpacing');
  9168. }
  9169. if (align !== '') {
  9170. table[0].align = align;
  9171. } else {
  9172. table.removeAttr('align');
  9173. }
  9174. if (border !== '') {
  9175. table.attr('border', border);
  9176. } else {
  9177. table.removeAttr('border');
  9178. }
  9179. if (border === '' || border === '0') {
  9180. table.addClass(zeroborder);
  9181. } else {
  9182. table.removeClass(zeroborder);
  9183. }
  9184. if (borderColor !== '') {
  9185. table.attr('borderColor', borderColor);
  9186. } else {
  9187. table.removeAttr('borderColor');
  9188. }
  9189. self.hideDialog().focus();
  9190. self.cmd.range.moveToBookmark(bookmark);
  9191. self.cmd.select();
  9192. self.addBookmark();
  9193. return;
  9194. }
  9195. var style = '';
  9196. if (width !== '') {
  9197. style += 'width:' + width + widthType + ';';
  9198. }
  9199. if (height !== '') {
  9200. style += 'height:' + height + heightType + ';';
  9201. }
  9202. if (bgColor !== '') {
  9203. style += 'background-color:' + bgColor + ';';
  9204. }
  9205. var html = '<table';
  9206. if (style !== '') {
  9207. html += ' style="' + style + '"';
  9208. }
  9209. if (padding !== '') {
  9210. html += ' cellpadding="' + padding + '"';
  9211. }
  9212. if (spacing !== '') {
  9213. html += ' cellspacing="' + spacing + '"';
  9214. }
  9215. if (align !== '') {
  9216. html += ' align="' + align + '"';
  9217. }
  9218. if (border !== '') {
  9219. html += ' border="' + border + '"';
  9220. }
  9221. if (border === '' || border === '0') {
  9222. html += ' class="' + zeroborder + '"';
  9223. }
  9224. if (borderColor !== '') {
  9225. html += ' bordercolor="' + borderColor + '"';
  9226. }
  9227. html += '>';
  9228. for (var i = 0; i < rows; i++) {
  9229. html += '<tr>';
  9230. for (var j = 0; j < cols; j++) {
  9231. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9232. }
  9233. html += '</tr>';
  9234. }
  9235. html += '</table>';
  9236. if (!K.IE) {
  9237. html += '<br />';
  9238. }
  9239. self.insertHtml(html);
  9240. self.select().hideDialog().focus();
  9241. self.addBookmark();
  9242. }
  9243. }
  9244. }),
  9245. div = dialog.div,
  9246. rowsBox = K('[name="rows"]', div).val(3),
  9247. colsBox = K('[name="cols"]', div).val(2),
  9248. widthBox = K('[name="width"]', div).val(100),
  9249. heightBox = K('[name="height"]', div),
  9250. widthTypeBox = K('[name="widthType"]', div),
  9251. heightTypeBox = K('[name="heightType"]', div),
  9252. paddingBox = K('[name="padding"]', div).val(2),
  9253. spacingBox = K('[name="spacing"]', div).val(0),
  9254. alignBox = K('[name="align"]', div),
  9255. borderBox = K('[name="border"]', div).val(1),
  9256. colorBox = K('.ke-input-color', div);
  9257. _initColorPicker(div, colorBox.eq(0));
  9258. _initColorPicker(div, colorBox.eq(1));
  9259. _setColor(colorBox.eq(0), '#000000');
  9260. _setColor(colorBox.eq(1), '');
  9261. rowsBox[0].focus();
  9262. rowsBox[0].select();
  9263. var table;
  9264. if (isInsert) {
  9265. return;
  9266. }
  9267. table = self.plugin.getSelectedTable();
  9268. if (table) {
  9269. rowsBox.val(table[0].rows.length);
  9270. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9271. rowsBox.attr('disabled', true);
  9272. colsBox.attr('disabled', true);
  9273. var match,
  9274. tableWidth = table[0].style.width || table[0].width,
  9275. tableHeight = table[0].style.height || table[0].height;
  9276. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9277. widthBox.val(match[1]);
  9278. widthTypeBox.val(match[2]);
  9279. } else {
  9280. widthBox.val('');
  9281. }
  9282. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9283. heightBox.val(match[1]);
  9284. heightTypeBox.val(match[2]);
  9285. }
  9286. paddingBox.val(table[0].cellPadding || '');
  9287. spacingBox.val(table[0].cellSpacing || '');
  9288. alignBox.val(table[0].align || '');
  9289. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9290. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9291. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9292. widthBox[0].focus();
  9293. widthBox[0].select();
  9294. }
  9295. },
  9296. cellprop : function() {
  9297. var html = [
  9298. '<div style="padding:20px;">',
  9299. '<div class="ke-dialog-row">',
  9300. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9301. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9302. '<select name="widthType">',
  9303. '<option value="%">' + lang.percent + '</option>',
  9304. '<option value="px">' + lang.px + '</option>',
  9305. '</select> &nbsp; ',
  9306. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9307. '<select name="heightType">',
  9308. '<option value="%">' + lang.percent + '</option>',
  9309. '<option value="px">' + lang.px + '</option>',
  9310. '</select>',
  9311. '</div>',
  9312. '<div class="ke-dialog-row">',
  9313. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9314. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9315. '<option value="">' + lang.alignDefault + '</option>',
  9316. '<option value="left">' + lang.alignLeft + '</option>',
  9317. '<option value="center">' + lang.alignCenter + '</option>',
  9318. '<option value="right">' + lang.alignRight + '</option>',
  9319. '</select> ',
  9320. lang.verticalAlign + ' <select name="verticalAlign">',
  9321. '<option value="">' + lang.alignDefault + '</option>',
  9322. '<option value="top">' + lang.alignTop + '</option>',
  9323. '<option value="middle">' + lang.alignMiddle + '</option>',
  9324. '<option value="bottom">' + lang.alignBottom + '</option>',
  9325. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9326. '</select>',
  9327. '</div>',
  9328. '<div class="ke-dialog-row">',
  9329. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9330. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9331. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9332. '</div>',
  9333. '<div class="ke-dialog-row">',
  9334. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9335. '<span class="ke-inline-block ke-input-color"></span>',
  9336. '</div>',
  9337. '</div>'
  9338. ].join('');
  9339. var bookmark = self.cmd.range.createBookmark();
  9340. var dialog = self.createDialog({
  9341. name : name,
  9342. width : 500,
  9343. title : self.lang('tablecell'),
  9344. body : html,
  9345. beforeRemove : function() {
  9346. colorBox.unbind();
  9347. },
  9348. yesBtn : {
  9349. name : self.lang('yes'),
  9350. click : function(e) {
  9351. var width = widthBox.val(),
  9352. height = heightBox.val(),
  9353. widthType = widthTypeBox.val(),
  9354. heightType = heightTypeBox.val(),
  9355. padding = paddingBox.val(),
  9356. spacing = spacingBox.val(),
  9357. textAlign = textAlignBox.val(),
  9358. verticalAlign = verticalAlignBox.val(),
  9359. border = borderBox.val(),
  9360. borderColor = K(colorBox[0]).html() || '',
  9361. bgColor = K(colorBox[1]).html() || '';
  9362. if (!/^\d*$/.test(width)) {
  9363. alert(self.lang('invalidWidth'));
  9364. widthBox[0].focus();
  9365. return;
  9366. }
  9367. if (!/^\d*$/.test(height)) {
  9368. alert(self.lang('invalidHeight'));
  9369. heightBox[0].focus();
  9370. return;
  9371. }
  9372. if (!/^\d*$/.test(border)) {
  9373. alert(self.lang('invalidBorder'));
  9374. borderBox[0].focus();
  9375. return;
  9376. }
  9377. cell.css({
  9378. width : width !== '' ? (width + widthType) : '',
  9379. height : height !== '' ? (height + heightType) : '',
  9380. 'background-color' : bgColor,
  9381. 'text-align' : textAlign,
  9382. 'vertical-align' : verticalAlign,
  9383. 'border-width' : border,
  9384. 'border-style' : border !== '' ? 'solid' : '',
  9385. 'border-color' : borderColor
  9386. });
  9387. self.hideDialog().focus();
  9388. self.cmd.range.moveToBookmark(bookmark);
  9389. self.cmd.select();
  9390. self.addBookmark();
  9391. }
  9392. }
  9393. }),
  9394. div = dialog.div,
  9395. widthBox = K('[name="width"]', div).val(100),
  9396. heightBox = K('[name="height"]', div),
  9397. widthTypeBox = K('[name="widthType"]', div),
  9398. heightTypeBox = K('[name="heightType"]', div),
  9399. paddingBox = K('[name="padding"]', div).val(2),
  9400. spacingBox = K('[name="spacing"]', div).val(0),
  9401. textAlignBox = K('[name="textAlign"]', div),
  9402. verticalAlignBox = K('[name="verticalAlign"]', div),
  9403. borderBox = K('[name="border"]', div).val(1),
  9404. colorBox = K('.ke-input-color', div);
  9405. _initColorPicker(div, colorBox.eq(0));
  9406. _initColorPicker(div, colorBox.eq(1));
  9407. _setColor(colorBox.eq(0), '#000000');
  9408. _setColor(colorBox.eq(1), '');
  9409. widthBox[0].focus();
  9410. widthBox[0].select();
  9411. var cell = self.plugin.getSelectedCell();
  9412. var match,
  9413. cellWidth = cell[0].style.width || cell[0].width || '',
  9414. cellHeight = cell[0].style.height || cell[0].height || '';
  9415. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9416. widthBox.val(match[1]);
  9417. widthTypeBox.val(match[2]);
  9418. } else {
  9419. widthBox.val('');
  9420. }
  9421. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9422. heightBox.val(match[1]);
  9423. heightTypeBox.val(match[2]);
  9424. }
  9425. textAlignBox.val(cell[0].style.textAlign || '');
  9426. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9427. var border = cell[0].style.borderWidth || '';
  9428. if (border) {
  9429. border = parseInt(border);
  9430. }
  9431. borderBox.val(border);
  9432. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9433. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9434. widthBox[0].focus();
  9435. widthBox[0].select();
  9436. },
  9437. insert : function() {
  9438. this.prop(true);
  9439. },
  9440. 'delete' : function() {
  9441. var table = self.plugin.getSelectedTable();
  9442. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9443. self.cmd.select();
  9444. table.remove();
  9445. self.addBookmark();
  9446. },
  9447. colinsert : function(offset) {
  9448. var table = self.plugin.getSelectedTable()[0],
  9449. row = self.plugin.getSelectedRow()[0],
  9450. cell = self.plugin.getSelectedCell()[0],
  9451. index = cell.cellIndex + offset;
  9452. index += table.rows[0].cells.length - row.cells.length;
  9453. for (var i = 0, len = table.rows.length; i < len; i++) {
  9454. var newRow = table.rows[i],
  9455. newCell = newRow.insertCell(index);
  9456. newCell.innerHTML = K.IE ? '' : '<br />';
  9457. index = _getCellIndex(table, newRow, newCell);
  9458. }
  9459. self.cmd.range.selectNodeContents(cell).collapse(true);
  9460. self.cmd.select();
  9461. self.addBookmark();
  9462. },
  9463. colinsertleft : function() {
  9464. this.colinsert(0);
  9465. },
  9466. colinsertright : function() {
  9467. this.colinsert(1);
  9468. },
  9469. rowinsert : function(offset) {
  9470. var table = self.plugin.getSelectedTable()[0],
  9471. row = self.plugin.getSelectedRow()[0],
  9472. cell = self.plugin.getSelectedCell()[0];
  9473. var rowIndex = row.rowIndex;
  9474. if (offset === 1) {
  9475. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9476. }
  9477. var newRow = table.insertRow(rowIndex);
  9478. for (var i = 0, len = row.cells.length; i < len; i++) {
  9479. if (row.cells[i].rowSpan > 1) {
  9480. len -= row.cells[i].rowSpan - 1;
  9481. }
  9482. var newCell = newRow.insertCell(i);
  9483. if (offset === 1 && row.cells[i].colSpan > 1) {
  9484. newCell.colSpan = row.cells[i].colSpan;
  9485. }
  9486. newCell.innerHTML = K.IE ? '' : '<br />';
  9487. }
  9488. for (var j = rowIndex; j >= 0; j--) {
  9489. var cells = table.rows[j].cells;
  9490. if (cells.length > i) {
  9491. for (var k = cell.cellIndex; k >= 0; k--) {
  9492. if (cells[k].rowSpan > 1) {
  9493. cells[k].rowSpan += 1;
  9494. }
  9495. }
  9496. break;
  9497. }
  9498. }
  9499. self.cmd.range.selectNodeContents(cell).collapse(true);
  9500. self.cmd.select();
  9501. self.addBookmark();
  9502. },
  9503. rowinsertabove : function() {
  9504. this.rowinsert(0);
  9505. },
  9506. rowinsertbelow : function() {
  9507. this.rowinsert(1);
  9508. },
  9509. rowmerge : function() {
  9510. var table = self.plugin.getSelectedTable()[0],
  9511. row = self.plugin.getSelectedRow()[0],
  9512. cell = self.plugin.getSelectedCell()[0],
  9513. rowIndex = row.rowIndex,
  9514. nextRowIndex = rowIndex + cell.rowSpan,
  9515. nextRow = table.rows[nextRowIndex];
  9516. if (table.rows.length <= nextRowIndex) {
  9517. return;
  9518. }
  9519. var cellIndex = cell.cellIndex;
  9520. if (nextRow.cells.length <= cellIndex) {
  9521. return;
  9522. }
  9523. var nextCell = nextRow.cells[cellIndex];
  9524. if (cell.colSpan !== nextCell.colSpan) {
  9525. return;
  9526. }
  9527. cell.rowSpan += nextCell.rowSpan;
  9528. nextRow.deleteCell(cellIndex);
  9529. self.cmd.range.selectNodeContents(cell).collapse(true);
  9530. self.cmd.select();
  9531. self.addBookmark();
  9532. },
  9533. colmerge : function() {
  9534. var table = self.plugin.getSelectedTable()[0],
  9535. row = self.plugin.getSelectedRow()[0],
  9536. cell = self.plugin.getSelectedCell()[0],
  9537. rowIndex = row.rowIndex,
  9538. cellIndex = cell.cellIndex,
  9539. nextCellIndex = cellIndex + 1;
  9540. if (row.cells.length <= nextCellIndex) {
  9541. return;
  9542. }
  9543. var nextCell = row.cells[nextCellIndex];
  9544. if (cell.rowSpan !== nextCell.rowSpan) {
  9545. return;
  9546. }
  9547. cell.colSpan += nextCell.colSpan;
  9548. row.deleteCell(nextCellIndex);
  9549. self.cmd.range.selectNodeContents(cell).collapse(true);
  9550. self.cmd.select();
  9551. self.addBookmark();
  9552. },
  9553. rowsplit : function() {
  9554. var table = self.plugin.getSelectedTable()[0],
  9555. row = self.plugin.getSelectedRow()[0],
  9556. cell = self.plugin.getSelectedCell()[0],
  9557. rowIndex = row.rowIndex;
  9558. if (cell.rowSpan === 1) {
  9559. return;
  9560. }
  9561. var cellIndex = _getCellIndex(table, row, cell);
  9562. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9563. var newRow = table.rows[rowIndex + i],
  9564. newCell = newRow.insertCell(cellIndex);
  9565. if (cell.colSpan > 1) {
  9566. newCell.colSpan = cell.colSpan;
  9567. }
  9568. newCell.innerHTML = K.IE ? '' : '<br />';
  9569. cellIndex = _getCellIndex(table, newRow, newCell);
  9570. }
  9571. K(cell).removeAttr('rowSpan');
  9572. self.cmd.range.selectNodeContents(cell).collapse(true);
  9573. self.cmd.select();
  9574. self.addBookmark();
  9575. },
  9576. colsplit : function() {
  9577. var table = self.plugin.getSelectedTable()[0],
  9578. row = self.plugin.getSelectedRow()[0],
  9579. cell = self.plugin.getSelectedCell()[0],
  9580. cellIndex = cell.cellIndex;
  9581. if (cell.colSpan === 1) {
  9582. return;
  9583. }
  9584. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9585. var newCell = row.insertCell(cellIndex + i);
  9586. if (cell.rowSpan > 1) {
  9587. newCell.rowSpan = cell.rowSpan;
  9588. }
  9589. newCell.innerHTML = K.IE ? '' : '<br />';
  9590. }
  9591. K(cell).removeAttr('colSpan');
  9592. self.cmd.range.selectNodeContents(cell).collapse(true);
  9593. self.cmd.select();
  9594. self.addBookmark();
  9595. },
  9596. coldelete : function() {
  9597. var table = self.plugin.getSelectedTable()[0],
  9598. row = self.plugin.getSelectedRow()[0],
  9599. cell = self.plugin.getSelectedCell()[0],
  9600. index = cell.cellIndex;
  9601. for (var i = 0, len = table.rows.length; i < len; i++) {
  9602. var newRow = table.rows[i],
  9603. newCell = newRow.cells[index];
  9604. if (newCell.colSpan > 1) {
  9605. newCell.colSpan -= 1;
  9606. if (newCell.colSpan === 1) {
  9607. K(newCell).removeAttr('colSpan');
  9608. }
  9609. } else {
  9610. newRow.deleteCell(index);
  9611. }
  9612. if (newCell.rowSpan > 1) {
  9613. i += newCell.rowSpan - 1;
  9614. }
  9615. }
  9616. if (row.cells.length === 0) {
  9617. self.cmd.range.setStartBefore(table).collapse(true);
  9618. self.cmd.select();
  9619. K(table).remove();
  9620. } else {
  9621. self.cmd.selection(true);
  9622. }
  9623. self.addBookmark();
  9624. },
  9625. rowdelete : function() {
  9626. var table = self.plugin.getSelectedTable()[0],
  9627. row = self.plugin.getSelectedRow()[0],
  9628. cell = self.plugin.getSelectedCell()[0],
  9629. rowIndex = row.rowIndex;
  9630. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9631. table.deleteRow(rowIndex + i);
  9632. }
  9633. if (table.rows.length === 0) {
  9634. self.cmd.range.setStartBefore(table).collapse(true);
  9635. self.cmd.select();
  9636. K(table).remove();
  9637. } else {
  9638. self.cmd.selection(true);
  9639. }
  9640. self.addBookmark();
  9641. }
  9642. };
  9643. self.clickToolbar(name, self.plugin.table.prop);
  9644. });
  9645. /*******************************************************************************
  9646. * KindEditor - WYSIWYG HTML Editor for Internet
  9647. * Copyright (C) 2006-2011 kindsoft.net
  9648. *
  9649. * @author Roddy <luolonghao@gmail.com>
  9650. * @site http://www.kindsoft.net/
  9651. * @licence http://www.kindsoft.net/license.php
  9652. *******************************************************************************/
  9653. KindEditor.plugin('template', function(K) {
  9654. var self = this, name = 'template', lang = self.lang(name + '.'),
  9655. htmlPath = self.pluginsPath + name + '/html/';
  9656. function getFilePath(fileName) {
  9657. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9658. }
  9659. self.clickToolbar(name, function() {
  9660. var lang = self.lang(name + '.'),
  9661. arr = ['<div style="padding:10px 20px;">',
  9662. '<div class="ke-header">',
  9663. '<div class="ke-left">',
  9664. lang. selectTemplate + ' <select>'];
  9665. K.each(lang.fileList, function(key, val) {
  9666. arr.push('<option value="' + key + '">' + val + '</option>');
  9667. });
  9668. html = [arr.join(''),
  9669. '</select></div>',
  9670. '<div class="ke-right">',
  9671. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9672. '</div>',
  9673. '<div class="ke-clearfix"></div>',
  9674. '</div>',
  9675. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9676. '</div>'].join('');
  9677. var dialog = self.createDialog({
  9678. name : name,
  9679. width : 500,
  9680. title : self.lang(name),
  9681. body : html,
  9682. yesBtn : {
  9683. name : self.lang('yes'),
  9684. click : function(e) {
  9685. var doc = K.iframeDoc(iframe);
  9686. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9687. }
  9688. }
  9689. });
  9690. var selectBox = K('select', dialog.div),
  9691. checkbox = K('[name="replaceFlag"]', dialog.div),
  9692. iframe = K('iframe', dialog.div);
  9693. checkbox[0].checked = true;
  9694. iframe.attr('src', getFilePath(selectBox.val()));
  9695. selectBox.change(function() {
  9696. iframe.attr('src', getFilePath(this.value));
  9697. });
  9698. });
  9699. });
  9700. /*******************************************************************************
  9701. * KindEditor - WYSIWYG HTML Editor for Internet
  9702. * Copyright (C) 2006-2011 kindsoft.net
  9703. *
  9704. * @author Roddy <luolonghao@gmail.com>
  9705. * @site http://www.kindsoft.net/
  9706. * @licence http://www.kindsoft.net/license.php
  9707. *******************************************************************************/
  9708. KindEditor.plugin('wordpaste', function(K) {
  9709. var self = this, name = 'wordpaste';
  9710. self.clickToolbar(name, function() {
  9711. var lang = self.lang(name + '.'),
  9712. html = '<div style="padding:10px 20px;">' +
  9713. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9714. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9715. '</div>',
  9716. dialog = self.createDialog({
  9717. name : name,
  9718. width : 450,
  9719. title : self.lang(name),
  9720. body : html,
  9721. yesBtn : {
  9722. name : self.lang('yes'),
  9723. click : function(e) {
  9724. var str = doc.body.innerHTML;
  9725. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9726. self.insertHtml(str).hideDialog().focus();
  9727. }
  9728. }
  9729. }),
  9730. div = dialog.div,
  9731. iframe = K('iframe', div),
  9732. doc = K.iframeDoc(iframe);
  9733. if (!K.IE) {
  9734. doc.designMode = 'on';
  9735. }
  9736. doc.open();
  9737. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9738. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9739. if (!K.IE) {
  9740. doc.write('<br />');
  9741. }
  9742. doc.write('</body></html>');
  9743. doc.close();
  9744. if (K.IE) {
  9745. doc.body.contentEditable = 'true';
  9746. }
  9747. iframe[0].contentWindow.focus();
  9748. });
  9749. });
  9750. KindEditor.plugin('fixtoolbar', function (K) {
  9751. var self = this;
  9752. if (!self.fixToolBar) {
  9753. return;
  9754. }
  9755. function init() {
  9756. var toolbar = K('.ke-toolbar');
  9757. var originY = toolbar.pos().y;
  9758. K(window).bind('scroll', function () {
  9759. if (toolbar.css('position') == 'fixed') {
  9760. if(document.body.scrollTop - originY < 0){
  9761. toolbar.css('position', 'static');
  9762. toolbar.css('top', 'auto');
  9763. }
  9764. } else {
  9765. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9766. toolbar.css('position', 'fixed');
  9767. toolbar.css('top', 0);
  9768. }
  9769. }
  9770. });
  9771. }
  9772. if (self.isCreated) {
  9773. init();
  9774. } else {
  9775. self.afterCreate(init);
  9776. }
  9777. });