kindeditor-all.js 310 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2013 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.10 (2013-11-23)
  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.10 (2013-11-23)',
  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+$/.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'],
  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 (_IE) {
  596. window.attachEvent('onunload', function() {
  597. _each(_eventData, function(key, events) {
  598. if (events.el) {
  599. _unbind(events.el);
  600. }
  601. });
  602. });
  603. }
  604. K.ctrl = _ctrl;
  605. K.ready = _ready;
  606. function _getCssList(css) {
  607. var list = {},
  608. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  609. match;
  610. while ((match = reg.exec(css))) {
  611. var key = _trim(match[1].toLowerCase()),
  612. val = _trim(_toHex(match[2]));
  613. list[key] = val;
  614. }
  615. return list;
  616. }
  617. function _getAttrList(tag) {
  618. var list = {},
  619. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  620. match;
  621. while ((match = reg.exec(tag))) {
  622. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  623. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  624. list[key] = val;
  625. }
  626. return list;
  627. }
  628. function _addClassToTag(tag, className) {
  629. if (/\s+class\s*=/.test(tag)) {
  630. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  631. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  632. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  633. } else {
  634. return $0;
  635. }
  636. });
  637. } else {
  638. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  639. }
  640. return tag;
  641. }
  642. function _formatCss(css) {
  643. var str = '';
  644. _each(_getCssList(css), function(key, val) {
  645. str += key + ':' + val + ';';
  646. });
  647. return str;
  648. }
  649. function _formatUrl(url, mode, host, pathname) {
  650. mode = _undef(mode, '').toLowerCase();
  651. if (url.substr(0, 5) != 'data:') {
  652. url = url.replace(/([^:])\/\//g, '$1/');
  653. }
  654. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  655. return url;
  656. }
  657. host = host || location.protocol + '//' + location.host;
  658. if (pathname === undefined) {
  659. var m = location.pathname.match(/^(\/.*)\//);
  660. pathname = m ? m[1] : '';
  661. }
  662. var match;
  663. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  664. if (match[1] !== host) {
  665. return url;
  666. }
  667. } else if (/^\w+:/.test(url)) {
  668. return url;
  669. }
  670. function getRealPath(path) {
  671. var parts = path.split('/'), paths = [];
  672. for (var i = 0, len = parts.length; i < len; i++) {
  673. var part = parts[i];
  674. if (part == '..') {
  675. if (paths.length > 0) {
  676. paths.pop();
  677. }
  678. } else if (part !== '' && part != '.') {
  679. paths.push(part);
  680. }
  681. }
  682. return '/' + paths.join('/');
  683. }
  684. if (/^\//.test(url)) {
  685. url = host + getRealPath(url.substr(1));
  686. } else if (!/^\w+:\/\//.test(url)) {
  687. url = host + getRealPath(pathname + '/' + url);
  688. }
  689. function getRelativePath(path, depth) {
  690. if (url.substr(0, path.length) === path) {
  691. var arr = [];
  692. for (var i = 0; i < depth; i++) {
  693. arr.push('..');
  694. }
  695. var prefix = '.';
  696. if (arr.length > 0) {
  697. prefix += '/' + arr.join('/');
  698. }
  699. if (pathname == '/') {
  700. prefix += '/';
  701. }
  702. return prefix + url.substr(path.length);
  703. } else {
  704. if ((match = /^(.*)\//.exec(path))) {
  705. return getRelativePath(match[1], ++depth);
  706. }
  707. }
  708. }
  709. if (mode === 'relative') {
  710. url = getRelativePath(host + pathname, 0).substr(2);
  711. } else if (mode === 'absolute') {
  712. if (url.substr(0, host.length) === host) {
  713. url = url.substr(host.length);
  714. }
  715. }
  716. return url;
  717. }
  718. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  719. if (html == null) {
  720. html = '';
  721. }
  722. urlType = urlType || '';
  723. wellFormatted = _undef(wellFormatted, false);
  724. indentChar = _undef(indentChar, '\t');
  725. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  726. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  727. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  728. });
  729. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  730. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  731. html = html.replace(/\u200B/g, '');
  732. html = html.replace(/\u00A9/g, '&copy;');
  733. html = html.replace(/\u00AE/g, '&reg;');
  734. html = html.replace(/<[^>]+/g, function($0) {
  735. return $0.replace(/\s+/g, ' ');
  736. });
  737. var htmlTagMap = {};
  738. if (htmlTags) {
  739. _each(htmlTags, function(key, val) {
  740. var arr = key.split(',');
  741. for (var i = 0, len = arr.length; i < len; i++) {
  742. htmlTagMap[arr[i]] = _toMap(val);
  743. }
  744. });
  745. if (!htmlTagMap.script) {
  746. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  747. }
  748. if (!htmlTagMap.style) {
  749. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  750. }
  751. }
  752. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  753. var tagStack = [];
  754. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  755. var full = $0,
  756. startNewline = $1 || '',
  757. startSlash = $2 || '',
  758. tagName = $3.toLowerCase(),
  759. attr = $4 || '',
  760. endSlash = $5 ? ' ' + $5 : '',
  761. endNewline = $6 || '';
  762. if (htmlTags && !htmlTagMap[tagName]) {
  763. return '';
  764. }
  765. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  766. endSlash = ' /';
  767. }
  768. if (_INLINE_TAG_MAP[tagName]) {
  769. if (startNewline) {
  770. startNewline = ' ';
  771. }
  772. if (endNewline) {
  773. endNewline = ' ';
  774. }
  775. }
  776. if (_PRE_TAG_MAP[tagName]) {
  777. if (startSlash) {
  778. endNewline = '\n';
  779. } else {
  780. startNewline = '\n';
  781. }
  782. }
  783. if (wellFormatted && tagName == 'br') {
  784. endNewline = '\n';
  785. }
  786. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  787. if (wellFormatted) {
  788. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  789. tagStack.pop();
  790. } else {
  791. tagStack.push(tagName);
  792. }
  793. startNewline = '\n';
  794. endNewline = '\n';
  795. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  796. startNewline += indentChar;
  797. if (!startSlash) {
  798. endNewline += indentChar;
  799. }
  800. }
  801. if (endSlash) {
  802. tagStack.pop();
  803. } else if (!startSlash) {
  804. endNewline += indentChar;
  805. }
  806. } else {
  807. startNewline = endNewline = '';
  808. }
  809. }
  810. if (attr !== '') {
  811. var attrMap = _getAttrList(full);
  812. if (tagName === 'font') {
  813. var fontStyleMap = {}, fontStyle = '';
  814. _each(attrMap, function(key, val) {
  815. if (key === 'color') {
  816. fontStyleMap.color = val;
  817. delete attrMap[key];
  818. }
  819. if (key === 'size') {
  820. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  821. delete attrMap[key];
  822. }
  823. if (key === 'face') {
  824. fontStyleMap['font-family'] = val;
  825. delete attrMap[key];
  826. }
  827. if (key === 'style') {
  828. fontStyle = val;
  829. }
  830. });
  831. if (fontStyle && !/;$/.test(fontStyle)) {
  832. fontStyle += ';';
  833. }
  834. _each(fontStyleMap, function(key, val) {
  835. if (val === '') {
  836. return;
  837. }
  838. if (/\s/.test(val)) {
  839. val = "'" + val + "'";
  840. }
  841. fontStyle += key + ':' + val + ';';
  842. });
  843. attrMap.style = fontStyle;
  844. }
  845. _each(attrMap, function(key, val) {
  846. if (_FILL_ATTR_MAP[key]) {
  847. attrMap[key] = key;
  848. }
  849. if (_inArray(key, ['src', 'href']) >= 0) {
  850. attrMap[key] = _formatUrl(val, urlType);
  851. }
  852. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  853. tagName === 'body' && key === 'contenteditable' ||
  854. /^kindeditor_\d+$/.test(key)) {
  855. delete attrMap[key];
  856. }
  857. if (key === 'style' && val !== '') {
  858. var styleMap = _getCssList(val);
  859. _each(styleMap, function(k, v) {
  860. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  861. delete styleMap[k];
  862. }
  863. });
  864. var style = '';
  865. _each(styleMap, function(k, v) {
  866. style += k + ':' + v + ';';
  867. });
  868. attrMap.style = style;
  869. }
  870. });
  871. attr = '';
  872. _each(attrMap, function(key, val) {
  873. if (key === 'style' && val === '') {
  874. return;
  875. }
  876. val = val.replace(/"/g, '&quot;');
  877. attr += ' ' + key + '="' + val + '"';
  878. });
  879. }
  880. if (tagName === 'font') {
  881. tagName = 'span';
  882. }
  883. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  884. });
  885. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  886. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  887. });
  888. html = html.replace(/\n\s*\n/g, '\n');
  889. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  890. return _trim(html);
  891. }
  892. function _clearMsWord(html, htmlTags) {
  893. html = html.replace(/<meta[\s\S]*?>/ig, '')
  894. .replace(/<![\s\S]*?>/ig, '')
  895. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  896. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  897. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  898. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  899. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  900. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  901. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  902. });
  903. return _formatHtml(html, htmlTags);
  904. }
  905. function _mediaType(src) {
  906. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  907. return 'audio/x-pn-realaudio-plugin';
  908. }
  909. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  910. return 'application/x-shockwave-flash';
  911. }
  912. return 'video/x-ms-asf-plugin';
  913. }
  914. function _mediaClass(type) {
  915. if (/realaudio/i.test(type)) {
  916. return 'ke-rm';
  917. }
  918. if (/flash/i.test(type)) {
  919. return 'ke-flash';
  920. }
  921. return 'ke-media';
  922. }
  923. function _mediaAttrs(srcTag) {
  924. return _getAttrList(unescape(srcTag));
  925. }
  926. function _mediaEmbed(attrs) {
  927. var html = '<embed ';
  928. _each(attrs, function(key, val) {
  929. html += key + '="' + val + '" ';
  930. });
  931. html += '/>';
  932. return html;
  933. }
  934. function _mediaImg(blankPath, attrs) {
  935. var width = attrs.width,
  936. height = attrs.height,
  937. type = attrs.type || _mediaType(attrs.src),
  938. srcTag = _mediaEmbed(attrs),
  939. style = '';
  940. if (/\D/.test(width)) {
  941. style += 'width:' + width + ';';
  942. } else if (width > 0) {
  943. style += 'width:' + width + 'px;';
  944. }
  945. if (/\D/.test(height)) {
  946. style += 'height:' + height + ';';
  947. } else if (height > 0) {
  948. style += 'height:' + height + 'px;';
  949. }
  950. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  951. if (style !== '') {
  952. html += 'style="' + style + '" ';
  953. }
  954. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  955. return html;
  956. }
  957. function _tmpl(str, data) {
  958. var fn = new Function("obj",
  959. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  960. "with(obj){p.push('" +
  961. str.replace(/[\r\t\n]/g, " ")
  962. .split("<%").join("\t")
  963. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  964. .replace(/\t=(.*?)%>/g, "',$1,'")
  965. .split("\t").join("');")
  966. .split("%>").join("p.push('")
  967. .split("\r").join("\\'") + "');}return p.join('');");
  968. return data ? fn(data) : fn;
  969. }
  970. K.formatUrl = _formatUrl;
  971. K.formatHtml = _formatHtml;
  972. K.getCssList = _getCssList;
  973. K.getAttrList = _getAttrList;
  974. K.mediaType = _mediaType;
  975. K.mediaAttrs = _mediaAttrs;
  976. K.mediaEmbed = _mediaEmbed;
  977. K.mediaImg = _mediaImg;
  978. K.clearMsWord = _clearMsWord;
  979. K.tmpl = _tmpl;
  980. function _contains(nodeA, nodeB) {
  981. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  982. return true;
  983. }
  984. while ((nodeB = nodeB.parentNode)) {
  985. if (nodeB == nodeA) {
  986. return true;
  987. }
  988. }
  989. return false;
  990. }
  991. var _getSetAttrDiv = document.createElement('div');
  992. _getSetAttrDiv.setAttribute('className', 't');
  993. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  994. function _getAttr(el, key) {
  995. key = key.toLowerCase();
  996. var val = null;
  997. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  998. var div = el.ownerDocument.createElement('div');
  999. div.appendChild(el.cloneNode(false));
  1000. var list = _getAttrList(_unescape(div.innerHTML));
  1001. if (key in list) {
  1002. val = list[key];
  1003. }
  1004. } else {
  1005. try {
  1006. val = el.getAttribute(key, 2);
  1007. } catch(e) {
  1008. val = el.getAttribute(key, 1);
  1009. }
  1010. }
  1011. if (key === 'style' && val !== null) {
  1012. val = _formatCss(val);
  1013. }
  1014. return val;
  1015. }
  1016. function _queryAll(expr, root) {
  1017. var exprList = expr.split(',');
  1018. if (exprList.length > 1) {
  1019. var mergedResults = [];
  1020. _each(exprList, function() {
  1021. _each(_queryAll(this, root), function() {
  1022. if (_inArray(this, mergedResults) < 0) {
  1023. mergedResults.push(this);
  1024. }
  1025. });
  1026. });
  1027. return mergedResults;
  1028. }
  1029. root = root || document;
  1030. function escape(str) {
  1031. if (typeof str != 'string') {
  1032. return str;
  1033. }
  1034. return str.replace(/([^\w\-])/g, '\\$1');
  1035. }
  1036. function stripslashes(str) {
  1037. return str.replace(/\\/g, '');
  1038. }
  1039. function cmpTag(tagA, tagB) {
  1040. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1041. }
  1042. function byId(id, tag, root) {
  1043. var arr = [],
  1044. doc = root.ownerDocument || root,
  1045. el = doc.getElementById(stripslashes(id));
  1046. if (el) {
  1047. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1048. arr.push(el);
  1049. }
  1050. }
  1051. return arr;
  1052. }
  1053. function byClass(className, tag, root) {
  1054. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1055. if (root.getElementsByClassName) {
  1056. els = root.getElementsByClassName(stripslashes(className));
  1057. for (i = 0, len = els.length; i < len; i++) {
  1058. el = els[i];
  1059. if (cmpTag(tag, el.nodeName)) {
  1060. arr.push(el);
  1061. }
  1062. }
  1063. } else if (doc.querySelectorAll) {
  1064. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1065. for (i = 0, len = els.length; i < len; i++) {
  1066. el = els[i];
  1067. if (_contains(root, el)) {
  1068. arr.push(el);
  1069. }
  1070. }
  1071. } else {
  1072. els = root.getElementsByTagName(tag);
  1073. className = ' ' + className + ' ';
  1074. for (i = 0, len = els.length; i < len; i++) {
  1075. el = els[i];
  1076. if (el.nodeType == 1) {
  1077. var cls = el.className;
  1078. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1079. arr.push(el);
  1080. }
  1081. }
  1082. }
  1083. }
  1084. return arr;
  1085. }
  1086. function byName(name, tag, root) {
  1087. var arr = [], doc = root.ownerDocument || root,
  1088. els = doc.getElementsByName(stripslashes(name)), el;
  1089. for (var i = 0, len = els.length; i < len; i++) {
  1090. el = els[i];
  1091. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1092. if (el.getAttribute('name') !== null) {
  1093. arr.push(el);
  1094. }
  1095. }
  1096. }
  1097. return arr;
  1098. }
  1099. function byAttr(key, val, tag, root) {
  1100. var arr = [], els = root.getElementsByTagName(tag), el;
  1101. for (var i = 0, len = els.length; i < len; i++) {
  1102. el = els[i];
  1103. if (el.nodeType == 1) {
  1104. if (val === null) {
  1105. if (_getAttr(el, key) !== null) {
  1106. arr.push(el);
  1107. }
  1108. } else {
  1109. if (val === escape(_getAttr(el, key))) {
  1110. arr.push(el);
  1111. }
  1112. }
  1113. }
  1114. }
  1115. return arr;
  1116. }
  1117. function select(expr, root) {
  1118. var arr = [], matches;
  1119. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1120. var tag = matches ? matches[1] : '*';
  1121. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1122. arr = byId(matches[1], tag, root);
  1123. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1124. arr = byClass(matches[1], tag, root);
  1125. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1126. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1127. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1128. var key = matches[1].toLowerCase(), val = matches[2];
  1129. if (key === 'id') {
  1130. arr = byId(val, tag, root);
  1131. } else if (key === 'class') {
  1132. arr = byClass(val, tag, root);
  1133. } else if (key === 'name') {
  1134. arr = byName(val, tag, root);
  1135. } else {
  1136. arr = byAttr(key, val, tag, root);
  1137. }
  1138. } else {
  1139. var els = root.getElementsByTagName(tag), el;
  1140. for (var i = 0, len = els.length; i < len; i++) {
  1141. el = els[i];
  1142. if (el.nodeType == 1) {
  1143. arr.push(el);
  1144. }
  1145. }
  1146. }
  1147. return arr;
  1148. }
  1149. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1150. while ((arr = re.exec(expr))) {
  1151. if (arr[1] !== ' ') {
  1152. parts.push(arr[1]);
  1153. }
  1154. }
  1155. var results = [];
  1156. if (parts.length == 1) {
  1157. return select(parts[0], root);
  1158. }
  1159. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1160. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1161. part = parts[i];
  1162. if (part === '>') {
  1163. isChild = true;
  1164. continue;
  1165. }
  1166. if (i > 0) {
  1167. els = [];
  1168. for (j = 0, len = results.length; j < len; j++) {
  1169. val = results[j];
  1170. subResults = select(part, val);
  1171. for (k = 0, l = subResults.length; k < l; k++) {
  1172. v = subResults[k];
  1173. if (isChild) {
  1174. if (val === v.parentNode) {
  1175. els.push(v);
  1176. }
  1177. } else {
  1178. els.push(v);
  1179. }
  1180. }
  1181. }
  1182. results = els;
  1183. } else {
  1184. results = select(part, root);
  1185. }
  1186. if (results.length === 0) {
  1187. return [];
  1188. }
  1189. }
  1190. return results;
  1191. }
  1192. function _query(expr, root) {
  1193. var arr = _queryAll(expr, root);
  1194. return arr.length > 0 ? arr[0] : null;
  1195. }
  1196. K.query = _query;
  1197. K.queryAll = _queryAll;
  1198. function _get(val) {
  1199. return K(val)[0];
  1200. }
  1201. function _getDoc(node) {
  1202. if (!node) {
  1203. return document;
  1204. }
  1205. return node.ownerDocument || node.document || node;
  1206. }
  1207. function _getWin(node) {
  1208. if (!node) {
  1209. return window;
  1210. }
  1211. var doc = _getDoc(node);
  1212. return doc.parentWindow || doc.defaultView;
  1213. }
  1214. function _setHtml(el, html) {
  1215. if (el.nodeType != 1) {
  1216. return;
  1217. }
  1218. var doc = _getDoc(el);
  1219. try {
  1220. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1221. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1222. temp.parentNode.removeChild(temp);
  1223. } catch(e) {
  1224. K(el).empty();
  1225. K('@' + html, doc).each(function() {
  1226. el.appendChild(this);
  1227. });
  1228. }
  1229. }
  1230. function _hasClass(el, cls) {
  1231. return _inString(cls, el.className, ' ');
  1232. }
  1233. function _setAttr(el, key, val) {
  1234. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1235. key = 'className';
  1236. }
  1237. el.setAttribute(key, '' + val);
  1238. }
  1239. function _removeAttr(el, key) {
  1240. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1241. key = 'className';
  1242. }
  1243. _setAttr(el, key, '');
  1244. el.removeAttribute(key);
  1245. }
  1246. function _getNodeName(node) {
  1247. if (!node || !node.nodeName) {
  1248. return '';
  1249. }
  1250. return node.nodeName.toLowerCase();
  1251. }
  1252. function _computedCss(el, key) {
  1253. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1254. if (win.getComputedStyle) {
  1255. var style = win.getComputedStyle(el, null);
  1256. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1257. } else if (el.currentStyle) {
  1258. val = el.currentStyle[camelKey] || el.style[camelKey];
  1259. }
  1260. return val;
  1261. }
  1262. function _hasVal(node) {
  1263. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1264. }
  1265. function _docElement(doc) {
  1266. doc = doc || document;
  1267. return _QUIRKS ? doc.body : doc.documentElement;
  1268. }
  1269. function _docHeight(doc) {
  1270. var el = _docElement(doc);
  1271. return Math.max(el.scrollHeight, el.clientHeight);
  1272. }
  1273. function _docWidth(doc) {
  1274. var el = _docElement(doc);
  1275. return Math.max(el.scrollWidth, el.clientWidth);
  1276. }
  1277. function _getScrollPos(doc) {
  1278. doc = doc || document;
  1279. var x, y;
  1280. if (_IE || _NEWIE || _OPERA) {
  1281. x = _docElement(doc).scrollLeft;
  1282. y = _docElement(doc).scrollTop;
  1283. } else {
  1284. x = _getWin(doc).scrollX;
  1285. y = _getWin(doc).scrollY;
  1286. }
  1287. return {x : x, y : y};
  1288. }
  1289. function KNode(node) {
  1290. this.init(node);
  1291. }
  1292. _extend(KNode, {
  1293. init : function(node) {
  1294. var self = this;
  1295. node = _isArray(node) ? node : [node];
  1296. var length = 0;
  1297. for (var i = 0, len = node.length; i < len; i++) {
  1298. if (node[i]) {
  1299. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1300. length++;
  1301. }
  1302. }
  1303. self.length = length;
  1304. self.doc = _getDoc(self[0]);
  1305. self.name = _getNodeName(self[0]);
  1306. self.type = self.length > 0 ? self[0].nodeType : null;
  1307. self.win = _getWin(self[0]);
  1308. },
  1309. each : function(fn) {
  1310. var self = this;
  1311. for (var i = 0; i < self.length; i++) {
  1312. if (fn.call(self[i], i, self[i]) === false) {
  1313. return self;
  1314. }
  1315. }
  1316. return self;
  1317. },
  1318. bind : function(type, fn) {
  1319. this.each(function() {
  1320. _bind(this, type, fn);
  1321. });
  1322. return this;
  1323. },
  1324. unbind : function(type, fn) {
  1325. this.each(function() {
  1326. _unbind(this, type, fn);
  1327. });
  1328. return this;
  1329. },
  1330. fire : function(type) {
  1331. if (this.length < 1) {
  1332. return this;
  1333. }
  1334. _fire(this[0], type);
  1335. return this;
  1336. },
  1337. hasAttr : function(key) {
  1338. if (this.length < 1) {
  1339. return false;
  1340. }
  1341. return !!_getAttr(this[0], key);
  1342. },
  1343. attr : function(key, val) {
  1344. var self = this;
  1345. if (key === undefined) {
  1346. return _getAttrList(self.outer());
  1347. }
  1348. if (typeof key === 'object') {
  1349. _each(key, function(k, v) {
  1350. self.attr(k, v);
  1351. });
  1352. return self;
  1353. }
  1354. if (val === undefined) {
  1355. val = self.length < 1 ? null : _getAttr(self[0], key);
  1356. return val === null ? '' : val;
  1357. }
  1358. self.each(function() {
  1359. _setAttr(this, key, val);
  1360. });
  1361. return self;
  1362. },
  1363. removeAttr : function(key) {
  1364. this.each(function() {
  1365. _removeAttr(this, key);
  1366. });
  1367. return this;
  1368. },
  1369. get : function(i) {
  1370. if (this.length < 1) {
  1371. return null;
  1372. }
  1373. return this[i || 0];
  1374. },
  1375. eq : function(i) {
  1376. if (this.length < 1) {
  1377. return null;
  1378. }
  1379. return this[i] ? new KNode(this[i]) : null;
  1380. },
  1381. hasClass : function(cls) {
  1382. if (this.length < 1) {
  1383. return false;
  1384. }
  1385. return _hasClass(this[0], cls);
  1386. },
  1387. addClass : function(cls) {
  1388. this.each(function() {
  1389. if (!_hasClass(this, cls)) {
  1390. this.className = _trim(this.className + ' ' + cls);
  1391. }
  1392. });
  1393. return this;
  1394. },
  1395. removeClass : function(cls) {
  1396. this.each(function() {
  1397. if (_hasClass(this, cls)) {
  1398. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1399. }
  1400. });
  1401. return this;
  1402. },
  1403. html : function(val) {
  1404. var self = this;
  1405. if (val === undefined) {
  1406. if (self.length < 1 || self.type != 1) {
  1407. return '';
  1408. }
  1409. return _formatHtml(self[0].innerHTML);
  1410. }
  1411. self.each(function() {
  1412. _setHtml(this, val);
  1413. });
  1414. return self;
  1415. },
  1416. text : function() {
  1417. var self = this;
  1418. if (self.length < 1) {
  1419. return '';
  1420. }
  1421. return _IE ? self[0].innerText : self[0].textContent;
  1422. },
  1423. hasVal : function() {
  1424. if (this.length < 1) {
  1425. return false;
  1426. }
  1427. return _hasVal(this[0]);
  1428. },
  1429. val : function(val) {
  1430. var self = this;
  1431. if (val === undefined) {
  1432. if (self.length < 1) {
  1433. return '';
  1434. }
  1435. return self.hasVal() ? self[0].value : self.attr('value');
  1436. } else {
  1437. self.each(function() {
  1438. if (_hasVal(this)) {
  1439. this.value = val;
  1440. } else {
  1441. _setAttr(this, 'value' , val);
  1442. }
  1443. });
  1444. return self;
  1445. }
  1446. },
  1447. css : function(key, val) {
  1448. var self = this;
  1449. if (key === undefined) {
  1450. return _getCssList(self.attr('style'));
  1451. }
  1452. if (typeof key === 'object') {
  1453. _each(key, function(k, v) {
  1454. self.css(k, v);
  1455. });
  1456. return self;
  1457. }
  1458. if (val === undefined) {
  1459. if (self.length < 1) {
  1460. return '';
  1461. }
  1462. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1463. }
  1464. self.each(function() {
  1465. this.style[_toCamel(key)] = val;
  1466. });
  1467. return self;
  1468. },
  1469. width : function(val) {
  1470. var self = this;
  1471. if (val === undefined) {
  1472. if (self.length < 1) {
  1473. return 0;
  1474. }
  1475. return self[0].offsetWidth;
  1476. }
  1477. return self.css('width', _addUnit(val));
  1478. },
  1479. height : function(val) {
  1480. var self = this;
  1481. if (val === undefined) {
  1482. if (self.length < 1) {
  1483. return 0;
  1484. }
  1485. return self[0].offsetHeight;
  1486. }
  1487. return self.css('height', _addUnit(val));
  1488. },
  1489. opacity : function(val) {
  1490. this.each(function() {
  1491. if (this.style.opacity === undefined) {
  1492. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1493. } else {
  1494. this.style.opacity = val == 1 ? '' : val;
  1495. }
  1496. });
  1497. return this;
  1498. },
  1499. data : function(key, val) {
  1500. var self = this;
  1501. key = 'kindeditor_data_' + key;
  1502. if (val === undefined) {
  1503. if (self.length < 1) {
  1504. return null;
  1505. }
  1506. return self[0][key];
  1507. }
  1508. this.each(function() {
  1509. this[key] = val;
  1510. });
  1511. return self;
  1512. },
  1513. pos : function() {
  1514. var self = this, node = self[0], x = 0, y = 0;
  1515. if (node) {
  1516. if (node.getBoundingClientRect) {
  1517. var box = node.getBoundingClientRect(),
  1518. pos = _getScrollPos(self.doc);
  1519. x = box.left + pos.x;
  1520. y = box.top + pos.y;
  1521. } else {
  1522. while (node) {
  1523. x += node.offsetLeft;
  1524. y += node.offsetTop;
  1525. node = node.offsetParent;
  1526. }
  1527. }
  1528. }
  1529. return {x : _round(x), y : _round(y)};
  1530. },
  1531. clone : function(bool) {
  1532. if (this.length < 1) {
  1533. return new KNode([]);
  1534. }
  1535. return new KNode(this[0].cloneNode(bool));
  1536. },
  1537. append : function(expr) {
  1538. this.each(function() {
  1539. if (this.appendChild) {
  1540. this.appendChild(_get(expr));
  1541. }
  1542. });
  1543. return this;
  1544. },
  1545. appendTo : function(expr) {
  1546. this.each(function() {
  1547. _get(expr).appendChild(this);
  1548. });
  1549. return this;
  1550. },
  1551. before : function(expr) {
  1552. this.each(function() {
  1553. this.parentNode.insertBefore(_get(expr), this);
  1554. });
  1555. return this;
  1556. },
  1557. after : function(expr) {
  1558. this.each(function() {
  1559. if (this.nextSibling) {
  1560. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1561. } else {
  1562. this.parentNode.appendChild(_get(expr));
  1563. }
  1564. });
  1565. return this;
  1566. },
  1567. replaceWith : function(expr) {
  1568. var nodes = [];
  1569. this.each(function(i, node) {
  1570. _unbind(node);
  1571. var newNode = _get(expr);
  1572. node.parentNode.replaceChild(newNode, node);
  1573. nodes.push(newNode);
  1574. });
  1575. return K(nodes);
  1576. },
  1577. empty : function() {
  1578. var self = this;
  1579. self.each(function(i, node) {
  1580. var child = node.firstChild;
  1581. while (child) {
  1582. if (!node.parentNode) {
  1583. return;
  1584. }
  1585. var next = child.nextSibling;
  1586. child.parentNode.removeChild(child);
  1587. child = next;
  1588. }
  1589. });
  1590. return self;
  1591. },
  1592. remove : function(keepChilds) {
  1593. var self = this;
  1594. self.each(function(i, node) {
  1595. if (!node.parentNode) {
  1596. return;
  1597. }
  1598. _unbind(node);
  1599. if (keepChilds) {
  1600. var child = node.firstChild;
  1601. while (child) {
  1602. var next = child.nextSibling;
  1603. node.parentNode.insertBefore(child, node);
  1604. child = next;
  1605. }
  1606. }
  1607. node.parentNode.removeChild(node);
  1608. delete self[i];
  1609. });
  1610. self.length = 0;
  1611. return self;
  1612. },
  1613. show : function(val) {
  1614. var self = this;
  1615. if (val === undefined) {
  1616. val = self._originDisplay || '';
  1617. }
  1618. if (self.css('display') != 'none') {
  1619. return self;
  1620. }
  1621. return self.css('display', val);
  1622. },
  1623. hide : function() {
  1624. var self = this;
  1625. if (self.length < 1) {
  1626. return self;
  1627. }
  1628. self._originDisplay = self[0].style.display;
  1629. return self.css('display', 'none');
  1630. },
  1631. outer : function() {
  1632. var self = this;
  1633. if (self.length < 1) {
  1634. return '';
  1635. }
  1636. var div = self.doc.createElement('div'), html;
  1637. div.appendChild(self[0].cloneNode(true));
  1638. html = _formatHtml(div.innerHTML);
  1639. div = null;
  1640. return html;
  1641. },
  1642. isSingle : function() {
  1643. return !!_SINGLE_TAG_MAP[this.name];
  1644. },
  1645. isInline : function() {
  1646. return !!_INLINE_TAG_MAP[this.name];
  1647. },
  1648. isBlock : function() {
  1649. return !!_BLOCK_TAG_MAP[this.name];
  1650. },
  1651. isStyle : function() {
  1652. return !!_STYLE_TAG_MAP[this.name];
  1653. },
  1654. isControl : function() {
  1655. return !!_CONTROL_TAG_MAP[this.name];
  1656. },
  1657. contains : function(otherNode) {
  1658. if (this.length < 1) {
  1659. return false;
  1660. }
  1661. return _contains(this[0], _get(otherNode));
  1662. },
  1663. parent : function() {
  1664. if (this.length < 1) {
  1665. return null;
  1666. }
  1667. var node = this[0].parentNode;
  1668. return node ? new KNode(node) : null;
  1669. },
  1670. children : function() {
  1671. if (this.length < 1) {
  1672. return new KNode([]);
  1673. }
  1674. var list = [], child = this[0].firstChild;
  1675. while (child) {
  1676. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1677. list.push(child);
  1678. }
  1679. child = child.nextSibling;
  1680. }
  1681. return new KNode(list);
  1682. },
  1683. first : function() {
  1684. var list = this.children();
  1685. return list.length > 0 ? list.eq(0) : null;
  1686. },
  1687. last : function() {
  1688. var list = this.children();
  1689. return list.length > 0 ? list.eq(list.length - 1) : null;
  1690. },
  1691. index : function() {
  1692. if (this.length < 1) {
  1693. return -1;
  1694. }
  1695. var i = -1, sibling = this[0];
  1696. while (sibling) {
  1697. i++;
  1698. sibling = sibling.previousSibling;
  1699. }
  1700. return i;
  1701. },
  1702. prev : function() {
  1703. if (this.length < 1) {
  1704. return null;
  1705. }
  1706. var node = this[0].previousSibling;
  1707. return node ? new KNode(node) : null;
  1708. },
  1709. next : function() {
  1710. if (this.length < 1) {
  1711. return null;
  1712. }
  1713. var node = this[0].nextSibling;
  1714. return node ? new KNode(node) : null;
  1715. },
  1716. scan : function(fn, order) {
  1717. if (this.length < 1) {
  1718. return;
  1719. }
  1720. order = (order === undefined) ? true : order;
  1721. function walk(node) {
  1722. var n = order ? node.firstChild : node.lastChild;
  1723. while (n) {
  1724. var next = order ? n.nextSibling : n.previousSibling;
  1725. if (fn(n) === false) {
  1726. return false;
  1727. }
  1728. if (walk(n) === false) {
  1729. return false;
  1730. }
  1731. n = next;
  1732. }
  1733. }
  1734. walk(this[0]);
  1735. return this;
  1736. }
  1737. });
  1738. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1739. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1740. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1741. KNode.prototype[type] = function(fn) {
  1742. return fn ? this.bind(type, fn) : this.fire(type);
  1743. };
  1744. });
  1745. var _K = K;
  1746. K = function(expr, root) {
  1747. if (expr === undefined || expr === null) {
  1748. return;
  1749. }
  1750. function newNode(node) {
  1751. if (!node[0]) {
  1752. node = [];
  1753. }
  1754. return new KNode(node);
  1755. }
  1756. if (typeof expr === 'string') {
  1757. if (root) {
  1758. root = _get(root);
  1759. }
  1760. var length = expr.length;
  1761. if (expr.charAt(0) === '@') {
  1762. expr = expr.substr(1);
  1763. }
  1764. if (expr.length !== length || /<.+>/.test(expr)) {
  1765. var doc = root ? root.ownerDocument || root : document,
  1766. div = doc.createElement('div'), list = [];
  1767. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1768. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1769. var child = div.childNodes[i];
  1770. if (child.id == '__kindeditor_temp_tag__') {
  1771. continue;
  1772. }
  1773. list.push(child);
  1774. }
  1775. return newNode(list);
  1776. }
  1777. return newNode(_queryAll(expr, root));
  1778. }
  1779. if (expr && expr.constructor === KNode) {
  1780. return expr;
  1781. }
  1782. if (expr.toArray) {
  1783. expr = expr.toArray();
  1784. }
  1785. if (_isArray(expr)) {
  1786. return newNode(expr);
  1787. }
  1788. return newNode(_toArray(arguments));
  1789. };
  1790. _each(_K, function(key, val) {
  1791. K[key] = val;
  1792. });
  1793. K.NodeClass = KNode;
  1794. window.KindEditor = K;
  1795. var _START_TO_START = 0,
  1796. _START_TO_END = 1,
  1797. _END_TO_END = 2,
  1798. _END_TO_START = 3,
  1799. _BOOKMARK_ID = 0;
  1800. function _updateCollapsed(range) {
  1801. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1802. return range;
  1803. }
  1804. function _copyAndDelete(range, isCopy, isDelete) {
  1805. var doc = range.doc, nodeList = [];
  1806. function splitTextNode(node, startOffset, endOffset) {
  1807. var length = node.nodeValue.length, centerNode;
  1808. if (isCopy) {
  1809. var cloneNode = node.cloneNode(true);
  1810. if (startOffset > 0) {
  1811. centerNode = cloneNode.splitText(startOffset);
  1812. } else {
  1813. centerNode = cloneNode;
  1814. }
  1815. if (endOffset < length) {
  1816. centerNode.splitText(endOffset - startOffset);
  1817. }
  1818. }
  1819. if (isDelete) {
  1820. var center = node;
  1821. if (startOffset > 0) {
  1822. center = node.splitText(startOffset);
  1823. range.setStart(node, startOffset);
  1824. }
  1825. if (endOffset < length) {
  1826. var right = center.splitText(endOffset - startOffset);
  1827. range.setEnd(right, 0);
  1828. }
  1829. nodeList.push(center);
  1830. }
  1831. return centerNode;
  1832. }
  1833. function removeNodes() {
  1834. if (isDelete) {
  1835. range.up().collapse(true);
  1836. }
  1837. for (var i = 0, len = nodeList.length; i < len; i++) {
  1838. var node = nodeList[i];
  1839. if (node.parentNode) {
  1840. node.parentNode.removeChild(node);
  1841. }
  1842. }
  1843. }
  1844. var copyRange = range.cloneRange().down();
  1845. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1846. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1847. if (ancestor.nodeType == 3) {
  1848. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1849. if (isCopy) {
  1850. frag.appendChild(textNode);
  1851. }
  1852. removeNodes();
  1853. return isCopy ? frag : range;
  1854. }
  1855. function extractNodes(parent, frag) {
  1856. var node = parent.firstChild, nextNode;
  1857. while (node) {
  1858. var testRange = new KRange(doc).selectNode(node);
  1859. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1860. if (start >= 0 && incStart <= 0) {
  1861. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1862. }
  1863. if (incStart >= 0 && incEnd <= 0) {
  1864. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1865. }
  1866. if (incEnd >= 0 && end <= 0) {
  1867. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1868. }
  1869. if (end >= 0) {
  1870. return false;
  1871. }
  1872. nextNode = node.nextSibling;
  1873. if (start > 0) {
  1874. if (node.nodeType == 1) {
  1875. if (incStart >= 0 && incEnd <= 0) {
  1876. if (isCopy) {
  1877. frag.appendChild(node.cloneNode(true));
  1878. }
  1879. if (isDelete) {
  1880. nodeList.push(node);
  1881. }
  1882. } else {
  1883. var childFlag;
  1884. if (isCopy) {
  1885. childFlag = node.cloneNode(false);
  1886. frag.appendChild(childFlag);
  1887. }
  1888. if (extractNodes(node, childFlag) === false) {
  1889. return false;
  1890. }
  1891. }
  1892. } else if (node.nodeType == 3) {
  1893. var textNode;
  1894. if (node == copyRange.startContainer) {
  1895. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1896. } else if (node == copyRange.endContainer) {
  1897. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1898. } else {
  1899. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1900. }
  1901. if (isCopy) {
  1902. try {
  1903. frag.appendChild(textNode);
  1904. } catch(e) {}
  1905. }
  1906. }
  1907. }
  1908. node = nextNode;
  1909. }
  1910. }
  1911. extractNodes(ancestor, frag);
  1912. if (isDelete) {
  1913. range.up().collapse(true);
  1914. }
  1915. for (var i = 0, len = nodeList.length; i < len; i++) {
  1916. var node = nodeList[i];
  1917. if (node.parentNode) {
  1918. node.parentNode.removeChild(node);
  1919. }
  1920. }
  1921. return isCopy ? frag : range;
  1922. }
  1923. function _moveToElementText(range, el) {
  1924. var node = el;
  1925. while (node) {
  1926. var knode = K(node);
  1927. if (knode.name == 'marquee' || knode.name == 'select') {
  1928. return;
  1929. }
  1930. node = node.parentNode;
  1931. }
  1932. try {
  1933. range.moveToElementText(el);
  1934. } catch(e) {}
  1935. }
  1936. function _getStartEnd(rng, isStart) {
  1937. var doc = rng.parentElement().ownerDocument,
  1938. pointRange = rng.duplicate();
  1939. pointRange.collapse(isStart);
  1940. var parent = pointRange.parentElement(),
  1941. nodes = parent.childNodes;
  1942. if (nodes.length === 0) {
  1943. return {node: parent.parentNode, offset: K(parent).index()};
  1944. }
  1945. var startNode = doc, startPos = 0, cmp = -1;
  1946. var testRange = rng.duplicate();
  1947. _moveToElementText(testRange, parent);
  1948. for (var i = 0, len = nodes.length; i < len; i++) {
  1949. var node = nodes[i];
  1950. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1951. if (cmp === 0) {
  1952. return {node: node.parentNode, offset: i};
  1953. }
  1954. if (node.nodeType == 1) {
  1955. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1956. if (knode.isControl()) {
  1957. dummy = doc.createElement('span');
  1958. knode.after(dummy);
  1959. newNode = dummy;
  1960. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1961. }
  1962. _moveToElementText(nodeRange, newNode);
  1963. testRange.setEndPoint('StartToEnd', nodeRange);
  1964. if (cmp > 0) {
  1965. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1966. } else {
  1967. startPos = 0;
  1968. }
  1969. if (dummy) {
  1970. K(dummy).remove();
  1971. }
  1972. } else if (node.nodeType == 3) {
  1973. testRange.moveStart('character', node.nodeValue.length);
  1974. startPos += node.nodeValue.length;
  1975. }
  1976. if (cmp < 0) {
  1977. startNode = node;
  1978. }
  1979. }
  1980. if (cmp < 0 && startNode.nodeType == 1) {
  1981. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1982. }
  1983. if (cmp > 0) {
  1984. while (startNode.nextSibling && startNode.nodeType == 1) {
  1985. startNode = startNode.nextSibling;
  1986. }
  1987. }
  1988. testRange = rng.duplicate();
  1989. _moveToElementText(testRange, parent);
  1990. testRange.setEndPoint('StartToEnd', pointRange);
  1991. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1992. if (cmp > 0 && startNode.nodeType == 3) {
  1993. var prevNode = startNode.previousSibling;
  1994. while (prevNode && prevNode.nodeType == 3) {
  1995. startPos -= prevNode.nodeValue.length;
  1996. prevNode = prevNode.previousSibling;
  1997. }
  1998. }
  1999. return {node: startNode, offset: startPos};
  2000. }
  2001. function _getEndRange(node, offset) {
  2002. var doc = node.ownerDocument || node,
  2003. range = doc.body.createTextRange();
  2004. if (doc == node) {
  2005. range.collapse(true);
  2006. return range;
  2007. }
  2008. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2009. var children = node.childNodes, isStart, child;
  2010. if (offset === 0) {
  2011. child = children[0];
  2012. isStart = true;
  2013. } else {
  2014. child = children[offset - 1];
  2015. isStart = false;
  2016. }
  2017. if (!child) {
  2018. return range;
  2019. }
  2020. if (K(child).name === 'head') {
  2021. if (offset === 1) {
  2022. isStart = true;
  2023. }
  2024. if (offset === 2) {
  2025. isStart = false;
  2026. }
  2027. range.collapse(isStart);
  2028. return range;
  2029. }
  2030. if (child.nodeType == 1) {
  2031. var kchild = K(child), span;
  2032. if (kchild.isControl()) {
  2033. span = doc.createElement('span');
  2034. if (isStart) {
  2035. kchild.before(span);
  2036. } else {
  2037. kchild.after(span);
  2038. }
  2039. child = span;
  2040. }
  2041. _moveToElementText(range, child);
  2042. range.collapse(isStart);
  2043. if (span) {
  2044. K(span).remove();
  2045. }
  2046. return range;
  2047. }
  2048. node = child;
  2049. offset = isStart ? 0 : child.nodeValue.length;
  2050. }
  2051. var dummy = doc.createElement('span');
  2052. K(node).before(dummy);
  2053. _moveToElementText(range, dummy);
  2054. range.moveStart('character', offset);
  2055. K(dummy).remove();
  2056. return range;
  2057. }
  2058. function _toRange(rng) {
  2059. var doc, range;
  2060. function tr2td(start) {
  2061. if (K(start.node).name == 'tr') {
  2062. start.node = start.node.cells[start.offset];
  2063. start.offset = 0;
  2064. }
  2065. }
  2066. if (_IERANGE) {
  2067. if (rng.item) {
  2068. doc = _getDoc(rng.item(0));
  2069. range = new KRange(doc);
  2070. range.selectNode(rng.item(0));
  2071. return range;
  2072. }
  2073. doc = rng.parentElement().ownerDocument;
  2074. var start = _getStartEnd(rng, true),
  2075. end = _getStartEnd(rng, false);
  2076. tr2td(start);
  2077. tr2td(end);
  2078. range = new KRange(doc);
  2079. range.setStart(start.node, start.offset);
  2080. range.setEnd(end.node, end.offset);
  2081. return range;
  2082. }
  2083. var startContainer = rng.startContainer;
  2084. doc = startContainer.ownerDocument || startContainer;
  2085. range = new KRange(doc);
  2086. range.setStart(startContainer, rng.startOffset);
  2087. range.setEnd(rng.endContainer, rng.endOffset);
  2088. return range;
  2089. }
  2090. function KRange(doc) {
  2091. this.init(doc);
  2092. }
  2093. _extend(KRange, {
  2094. init : function(doc) {
  2095. var self = this;
  2096. self.startContainer = doc;
  2097. self.startOffset = 0;
  2098. self.endContainer = doc;
  2099. self.endOffset = 0;
  2100. self.collapsed = true;
  2101. self.doc = doc;
  2102. },
  2103. commonAncestor : function() {
  2104. function getParents(node) {
  2105. var parents = [];
  2106. while (node) {
  2107. parents.push(node);
  2108. node = node.parentNode;
  2109. }
  2110. return parents;
  2111. }
  2112. var parentsA = getParents(this.startContainer),
  2113. parentsB = getParents(this.endContainer),
  2114. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2115. while (++i) {
  2116. parentA = parentsA[lenA - i];
  2117. parentB = parentsB[lenB - i];
  2118. if (!parentA || !parentB || parentA !== parentB) {
  2119. break;
  2120. }
  2121. }
  2122. return parentsA[lenA - i + 1];
  2123. },
  2124. setStart : function(node, offset) {
  2125. var self = this, doc = self.doc;
  2126. self.startContainer = node;
  2127. self.startOffset = offset;
  2128. if (self.endContainer === doc) {
  2129. self.endContainer = node;
  2130. self.endOffset = offset;
  2131. }
  2132. return _updateCollapsed(this);
  2133. },
  2134. setEnd : function(node, offset) {
  2135. var self = this, doc = self.doc;
  2136. self.endContainer = node;
  2137. self.endOffset = offset;
  2138. if (self.startContainer === doc) {
  2139. self.startContainer = node;
  2140. self.startOffset = offset;
  2141. }
  2142. return _updateCollapsed(this);
  2143. },
  2144. setStartBefore : function(node) {
  2145. return this.setStart(node.parentNode || this.doc, K(node).index());
  2146. },
  2147. setStartAfter : function(node) {
  2148. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2149. },
  2150. setEndBefore : function(node) {
  2151. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2152. },
  2153. setEndAfter : function(node) {
  2154. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2155. },
  2156. selectNode : function(node) {
  2157. return this.setStartBefore(node).setEndAfter(node);
  2158. },
  2159. selectNodeContents : function(node) {
  2160. var knode = K(node);
  2161. if (knode.type == 3 || knode.isSingle()) {
  2162. return this.selectNode(node);
  2163. }
  2164. var children = knode.children();
  2165. if (children.length > 0) {
  2166. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2167. }
  2168. return this.setStart(node, 0).setEnd(node, 0);
  2169. },
  2170. collapse : function(toStart) {
  2171. if (toStart) {
  2172. return this.setEnd(this.startContainer, this.startOffset);
  2173. }
  2174. return this.setStart(this.endContainer, this.endOffset);
  2175. },
  2176. compareBoundaryPoints : function(how, range) {
  2177. var rangeA = this.get(), rangeB = range.get();
  2178. if (_IERANGE) {
  2179. var arr = {};
  2180. arr[_START_TO_START] = 'StartToStart';
  2181. arr[_START_TO_END] = 'EndToStart';
  2182. arr[_END_TO_END] = 'EndToEnd';
  2183. arr[_END_TO_START] = 'StartToEnd';
  2184. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2185. if (cmp !== 0) {
  2186. return cmp;
  2187. }
  2188. var nodeA, nodeB, nodeC, posA, posB;
  2189. if (how === _START_TO_START || how === _END_TO_START) {
  2190. nodeA = this.startContainer;
  2191. posA = this.startOffset;
  2192. }
  2193. if (how === _START_TO_END || how === _END_TO_END) {
  2194. nodeA = this.endContainer;
  2195. posA = this.endOffset;
  2196. }
  2197. if (how === _START_TO_START || how === _START_TO_END) {
  2198. nodeB = range.startContainer;
  2199. posB = range.startOffset;
  2200. }
  2201. if (how === _END_TO_END || how === _END_TO_START) {
  2202. nodeB = range.endContainer;
  2203. posB = range.endOffset;
  2204. }
  2205. if (nodeA === nodeB) {
  2206. var diff = posA - posB;
  2207. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2208. }
  2209. nodeC = nodeB;
  2210. while (nodeC && nodeC.parentNode !== nodeA) {
  2211. nodeC = nodeC.parentNode;
  2212. }
  2213. if (nodeC) {
  2214. return K(nodeC).index() >= posA ? -1 : 1;
  2215. }
  2216. nodeC = nodeA;
  2217. while (nodeC && nodeC.parentNode !== nodeB) {
  2218. nodeC = nodeC.parentNode;
  2219. }
  2220. if (nodeC) {
  2221. return K(nodeC).index() >= posB ? 1 : -1;
  2222. }
  2223. nodeC = K(nodeB).next();
  2224. if (nodeC && nodeC.contains(nodeA)) {
  2225. return 1;
  2226. }
  2227. nodeC = K(nodeA).next();
  2228. if (nodeC && nodeC.contains(nodeB)) {
  2229. return -1;
  2230. }
  2231. } else {
  2232. return rangeA.compareBoundaryPoints(how, rangeB);
  2233. }
  2234. },
  2235. cloneRange : function() {
  2236. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2237. },
  2238. toString : function() {
  2239. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2240. return str.replace(/\r\n|\n|\r/g, '');
  2241. },
  2242. cloneContents : function() {
  2243. return _copyAndDelete(this, true, false);
  2244. },
  2245. deleteContents : function() {
  2246. return _copyAndDelete(this, false, true);
  2247. },
  2248. extractContents : function() {
  2249. return _copyAndDelete(this, true, true);
  2250. },
  2251. insertNode : function(node) {
  2252. var self = this,
  2253. sc = self.startContainer, so = self.startOffset,
  2254. ec = self.endContainer, eo = self.endOffset,
  2255. firstChild, lastChild, c, nodeCount = 1;
  2256. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2257. firstChild = node.firstChild;
  2258. lastChild = node.lastChild;
  2259. nodeCount = node.childNodes.length;
  2260. }
  2261. if (sc.nodeType == 1) {
  2262. c = sc.childNodes[so];
  2263. if (c) {
  2264. sc.insertBefore(node, c);
  2265. if (sc === ec) {
  2266. eo += nodeCount;
  2267. }
  2268. } else {
  2269. sc.appendChild(node);
  2270. }
  2271. } else if (sc.nodeType == 3) {
  2272. if (so === 0) {
  2273. sc.parentNode.insertBefore(node, sc);
  2274. if (sc.parentNode === ec) {
  2275. eo += nodeCount;
  2276. }
  2277. } else if (so >= sc.nodeValue.length) {
  2278. if (sc.nextSibling) {
  2279. sc.parentNode.insertBefore(node, sc.nextSibling);
  2280. } else {
  2281. sc.parentNode.appendChild(node);
  2282. }
  2283. } else {
  2284. if (so > 0) {
  2285. c = sc.splitText(so);
  2286. } else {
  2287. c = sc;
  2288. }
  2289. sc.parentNode.insertBefore(node, c);
  2290. if (sc === ec) {
  2291. ec = c;
  2292. eo -= so;
  2293. }
  2294. }
  2295. }
  2296. if (firstChild) {
  2297. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2298. } else {
  2299. self.selectNode(node);
  2300. }
  2301. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2302. return self;
  2303. }
  2304. return self.setEnd(ec, eo);
  2305. },
  2306. surroundContents : function(node) {
  2307. node.appendChild(this.extractContents());
  2308. return this.insertNode(node).selectNode(node);
  2309. },
  2310. isControl : function() {
  2311. var self = this,
  2312. sc = self.startContainer, so = self.startOffset,
  2313. ec = self.endContainer, eo = self.endOffset, rng;
  2314. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2315. },
  2316. get : function(hasControlRange) {
  2317. var self = this, doc = self.doc, node, rng;
  2318. if (!_IERANGE) {
  2319. rng = doc.createRange();
  2320. try {
  2321. rng.setStart(self.startContainer, self.startOffset);
  2322. rng.setEnd(self.endContainer, self.endOffset);
  2323. } catch (e) {}
  2324. return rng;
  2325. }
  2326. if (hasControlRange && self.isControl()) {
  2327. rng = doc.body.createControlRange();
  2328. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2329. return rng;
  2330. }
  2331. var range = self.cloneRange().down();
  2332. rng = doc.body.createTextRange();
  2333. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2334. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2335. return rng;
  2336. },
  2337. html : function() {
  2338. return K(this.cloneContents()).outer();
  2339. },
  2340. down : function() {
  2341. var self = this;
  2342. function downPos(node, pos, isStart) {
  2343. if (node.nodeType != 1) {
  2344. return;
  2345. }
  2346. var children = K(node).children();
  2347. if (children.length === 0) {
  2348. return;
  2349. }
  2350. var left, right, child, offset;
  2351. if (pos > 0) {
  2352. left = children.eq(pos - 1);
  2353. }
  2354. if (pos < children.length) {
  2355. right = children.eq(pos);
  2356. }
  2357. if (left && left.type == 3) {
  2358. child = left[0];
  2359. offset = child.nodeValue.length;
  2360. }
  2361. if (right && right.type == 3) {
  2362. child = right[0];
  2363. offset = 0;
  2364. }
  2365. if (!child) {
  2366. return;
  2367. }
  2368. if (isStart) {
  2369. self.setStart(child, offset);
  2370. } else {
  2371. self.setEnd(child, offset);
  2372. }
  2373. }
  2374. downPos(self.startContainer, self.startOffset, true);
  2375. downPos(self.endContainer, self.endOffset, false);
  2376. return self;
  2377. },
  2378. up : function() {
  2379. var self = this;
  2380. function upPos(node, pos, isStart) {
  2381. if (node.nodeType != 3) {
  2382. return;
  2383. }
  2384. if (pos === 0) {
  2385. if (isStart) {
  2386. self.setStartBefore(node);
  2387. } else {
  2388. self.setEndBefore(node);
  2389. }
  2390. } else if (pos == node.nodeValue.length) {
  2391. if (isStart) {
  2392. self.setStartAfter(node);
  2393. } else {
  2394. self.setEndAfter(node);
  2395. }
  2396. }
  2397. }
  2398. upPos(self.startContainer, self.startOffset, true);
  2399. upPos(self.endContainer, self.endOffset, false);
  2400. return self;
  2401. },
  2402. enlarge : function(toBlock) {
  2403. var self = this;
  2404. self.up();
  2405. function enlargePos(node, pos, isStart) {
  2406. var knode = K(node), parent;
  2407. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2408. return;
  2409. }
  2410. if (pos === 0) {
  2411. while (!knode.prev()) {
  2412. parent = knode.parent();
  2413. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2414. break;
  2415. }
  2416. knode = parent;
  2417. }
  2418. if (isStart) {
  2419. self.setStartBefore(knode[0]);
  2420. } else {
  2421. self.setEndBefore(knode[0]);
  2422. }
  2423. } else if (pos == knode.children().length) {
  2424. while (!knode.next()) {
  2425. parent = knode.parent();
  2426. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2427. break;
  2428. }
  2429. knode = parent;
  2430. }
  2431. if (isStart) {
  2432. self.setStartAfter(knode[0]);
  2433. } else {
  2434. self.setEndAfter(knode[0]);
  2435. }
  2436. }
  2437. }
  2438. enlargePos(self.startContainer, self.startOffset, true);
  2439. enlargePos(self.endContainer, self.endOffset, false);
  2440. return self;
  2441. },
  2442. shrink : function() {
  2443. var self = this, child, collapsed = self.collapsed;
  2444. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2445. self.setStart(child, 0);
  2446. }
  2447. if (collapsed) {
  2448. return self.collapse(collapsed);
  2449. }
  2450. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2451. self.setEnd(child, child.childNodes.length);
  2452. }
  2453. return self;
  2454. },
  2455. createBookmark : function(serialize) {
  2456. var self = this, doc = self.doc, endNode,
  2457. startNode = K('<span style="display:none;"></span>', doc)[0];
  2458. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2459. if (!self.collapsed) {
  2460. endNode = startNode.cloneNode(true);
  2461. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2462. }
  2463. if (endNode) {
  2464. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2465. }
  2466. self.insertNode(startNode).setStartAfter(startNode);
  2467. return {
  2468. start : serialize ? '#' + startNode.id : startNode,
  2469. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2470. };
  2471. },
  2472. moveToBookmark : function(bookmark) {
  2473. var self = this, doc = self.doc,
  2474. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2475. if (!start || start.length < 1) {
  2476. return self;
  2477. }
  2478. self.setStartBefore(start[0]);
  2479. start.remove();
  2480. if (end && end.length > 0) {
  2481. self.setEndBefore(end[0]);
  2482. end.remove();
  2483. } else {
  2484. self.collapse(true);
  2485. }
  2486. return self;
  2487. },
  2488. dump : function() {
  2489. console.log('--------------------');
  2490. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2491. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2492. }
  2493. });
  2494. function _range(mixed) {
  2495. if (!mixed.nodeName) {
  2496. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2497. }
  2498. return new KRange(mixed);
  2499. }
  2500. K.RangeClass = KRange;
  2501. K.range = _range;
  2502. K.START_TO_START = _START_TO_START;
  2503. K.START_TO_END = _START_TO_END;
  2504. K.END_TO_END = _END_TO_END;
  2505. K.END_TO_START = _END_TO_START;
  2506. function _nativeCommand(doc, key, val) {
  2507. try {
  2508. doc.execCommand(key, false, val);
  2509. } catch(e) {}
  2510. }
  2511. function _nativeCommandValue(doc, key) {
  2512. var val = '';
  2513. try {
  2514. val = doc.queryCommandValue(key);
  2515. } catch (e) {}
  2516. if (typeof val !== 'string') {
  2517. val = '';
  2518. }
  2519. return val;
  2520. }
  2521. function _getSel(doc) {
  2522. var win = _getWin(doc);
  2523. return _IERANGE ? doc.selection : win.getSelection();
  2524. }
  2525. function _getRng(doc) {
  2526. var sel = _getSel(doc), rng;
  2527. try {
  2528. if (sel.rangeCount > 0) {
  2529. rng = sel.getRangeAt(0);
  2530. } else {
  2531. rng = sel.createRange();
  2532. }
  2533. } catch(e) {}
  2534. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2535. return null;
  2536. }
  2537. return rng;
  2538. }
  2539. function _singleKeyMap(map) {
  2540. var newMap = {}, arr, v;
  2541. _each(map, function(key, val) {
  2542. arr = key.split(',');
  2543. for (var i = 0, len = arr.length; i < len; i++) {
  2544. v = arr[i];
  2545. newMap[v] = val;
  2546. }
  2547. });
  2548. return newMap;
  2549. }
  2550. function _hasAttrOrCss(knode, map) {
  2551. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2552. }
  2553. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2554. mapKey = mapKey || knode.name;
  2555. if (knode.type !== 1) {
  2556. return false;
  2557. }
  2558. var newMap = _singleKeyMap(map);
  2559. if (!newMap[mapKey]) {
  2560. return false;
  2561. }
  2562. var arr = newMap[mapKey].split(',');
  2563. for (var i = 0, len = arr.length; i < len; i++) {
  2564. var key = arr[i];
  2565. if (key === '*') {
  2566. return true;
  2567. }
  2568. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2569. var method = match[1] ? 'css' : 'attr';
  2570. key = match[2];
  2571. var val = match[3] || '';
  2572. if (val === '' && knode[method](key) !== '') {
  2573. return true;
  2574. }
  2575. if (val !== '' && knode[method](key) === val) {
  2576. return true;
  2577. }
  2578. }
  2579. return false;
  2580. }
  2581. function _removeAttrOrCss(knode, map) {
  2582. if (knode.type != 1) {
  2583. return;
  2584. }
  2585. _removeAttrOrCssByKey(knode, map, '*');
  2586. _removeAttrOrCssByKey(knode, map);
  2587. }
  2588. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2589. mapKey = mapKey || knode.name;
  2590. if (knode.type !== 1) {
  2591. return;
  2592. }
  2593. var newMap = _singleKeyMap(map);
  2594. if (!newMap[mapKey]) {
  2595. return;
  2596. }
  2597. var arr = newMap[mapKey].split(','), allFlag = false;
  2598. for (var i = 0, len = arr.length; i < len; i++) {
  2599. var key = arr[i];
  2600. if (key === '*') {
  2601. allFlag = true;
  2602. break;
  2603. }
  2604. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2605. key = match[2];
  2606. if (match[1]) {
  2607. key = _toCamel(key);
  2608. if (knode[0].style[key]) {
  2609. knode[0].style[key] = '';
  2610. }
  2611. } else {
  2612. knode.removeAttr(key);
  2613. }
  2614. }
  2615. if (allFlag) {
  2616. knode.remove(true);
  2617. }
  2618. }
  2619. function _getInnerNode(knode) {
  2620. var inner = knode;
  2621. while (inner.first()) {
  2622. inner = inner.first();
  2623. }
  2624. return inner;
  2625. }
  2626. function _isEmptyNode(knode) {
  2627. if (knode.type != 1 || knode.isSingle()) {
  2628. return false;
  2629. }
  2630. return knode.html().replace(/<[^>]+>/g, '') === '';
  2631. }
  2632. function _mergeWrapper(a, b) {
  2633. a = a.clone(true);
  2634. var lastA = _getInnerNode(a), childA = a, merged = false;
  2635. while (b) {
  2636. while (childA) {
  2637. if (childA.name === b.name) {
  2638. _mergeAttrs(childA, b.attr(), b.css());
  2639. merged = true;
  2640. }
  2641. childA = childA.first();
  2642. }
  2643. if (!merged) {
  2644. lastA.append(b.clone(false));
  2645. }
  2646. merged = false;
  2647. b = b.first();
  2648. }
  2649. return a;
  2650. }
  2651. function _wrapNode(knode, wrapper) {
  2652. wrapper = wrapper.clone(true);
  2653. if (knode.type == 3) {
  2654. _getInnerNode(wrapper).append(knode.clone(false));
  2655. knode.replaceWith(wrapper);
  2656. return wrapper;
  2657. }
  2658. var nodeWrapper = knode, child;
  2659. while ((child = knode.first()) && child.children().length == 1) {
  2660. knode = child;
  2661. }
  2662. child = knode.first();
  2663. var frag = knode.doc.createDocumentFragment();
  2664. while (child) {
  2665. frag.appendChild(child[0]);
  2666. child = child.next();
  2667. }
  2668. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2669. if (frag.firstChild) {
  2670. _getInnerNode(wrapper).append(frag);
  2671. }
  2672. nodeWrapper.replaceWith(wrapper);
  2673. return wrapper;
  2674. }
  2675. function _mergeAttrs(knode, attrs, styles) {
  2676. _each(attrs, function(key, val) {
  2677. if (key !== 'style') {
  2678. knode.attr(key, val);
  2679. }
  2680. });
  2681. _each(styles, function(key, val) {
  2682. knode.css(key, val);
  2683. });
  2684. }
  2685. function _inPreElement(knode) {
  2686. while (knode && knode.name != 'body') {
  2687. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2688. return true;
  2689. }
  2690. knode = knode.parent();
  2691. }
  2692. return false;
  2693. }
  2694. function KCmd(range) {
  2695. this.init(range);
  2696. }
  2697. _extend(KCmd, {
  2698. init : function(range) {
  2699. var self = this, doc = range.doc;
  2700. self.doc = doc;
  2701. self.win = _getWin(doc);
  2702. self.sel = _getSel(doc);
  2703. self.range = range;
  2704. },
  2705. selection : function(forceReset) {
  2706. var self = this, doc = self.doc, rng = _getRng(doc);
  2707. self.sel = _getSel(doc);
  2708. if (rng) {
  2709. self.range = _range(rng);
  2710. if (K(self.range.startContainer).name == 'html') {
  2711. self.range.selectNodeContents(doc.body).collapse(false);
  2712. }
  2713. return self;
  2714. }
  2715. if (forceReset) {
  2716. self.range.selectNodeContents(doc.body).collapse(false);
  2717. }
  2718. return self;
  2719. },
  2720. select : function(hasDummy) {
  2721. hasDummy = _undef(hasDummy, true);
  2722. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2723. sc = range.startContainer, so = range.startOffset,
  2724. ec = range.endContainer, eo = range.endOffset,
  2725. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2726. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2727. if (_IERANGE) {
  2728. var dummy = K('<span>&nbsp;</span>', doc);
  2729. range.insertNode(dummy[0]);
  2730. rng = doc.body.createTextRange();
  2731. try {
  2732. rng.moveToElementText(dummy[0]);
  2733. } catch(ex) {}
  2734. rng.collapse(false);
  2735. rng.select();
  2736. dummy.remove();
  2737. win.focus();
  2738. return self;
  2739. }
  2740. if (_WEBKIT) {
  2741. var children = sc.childNodes;
  2742. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2743. range.insertNode(doc.createTextNode('\u200B'));
  2744. hasU200b = true;
  2745. }
  2746. }
  2747. }
  2748. if (_IERANGE) {
  2749. try {
  2750. rng = range.get(true);
  2751. rng.select();
  2752. } catch(e) {}
  2753. } else {
  2754. if (hasU200b) {
  2755. range.collapse(false);
  2756. }
  2757. rng = range.get(true);
  2758. sel.removeAllRanges();
  2759. sel.addRange(rng);
  2760. if (doc !== document) {
  2761. var pos = K(rng.endContainer).pos();
  2762. win.scrollTo(pos.x, pos.y);
  2763. }
  2764. }
  2765. win.focus();
  2766. return self;
  2767. },
  2768. wrap : function(val) {
  2769. var self = this, doc = self.doc, range = self.range, wrapper;
  2770. wrapper = K(val, doc);
  2771. if (range.collapsed) {
  2772. range.shrink();
  2773. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2774. return self;
  2775. }
  2776. if (wrapper.isBlock()) {
  2777. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2778. while (child.first()) {
  2779. child = child.first();
  2780. }
  2781. child.append(range.extractContents());
  2782. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2783. return self;
  2784. }
  2785. range.enlarge();
  2786. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2787. K(ancestor).scan(function(node) {
  2788. if (!isStart && node == bookmark.start) {
  2789. isStart = true;
  2790. return;
  2791. }
  2792. if (isStart) {
  2793. if (node == bookmark.end) {
  2794. return false;
  2795. }
  2796. var knode = K(node);
  2797. if (_inPreElement(knode)) {
  2798. return;
  2799. }
  2800. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2801. var parent;
  2802. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2803. knode = parent;
  2804. }
  2805. _wrapNode(knode, wrapper);
  2806. }
  2807. }
  2808. });
  2809. range.moveToBookmark(bookmark);
  2810. return self;
  2811. },
  2812. split : function(isStart, map) {
  2813. var range = this.range, doc = range.doc;
  2814. var tempRange = range.cloneRange().collapse(isStart);
  2815. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2816. parent = node.nodeType == 3 ? node.parentNode : node,
  2817. needSplit = false, knode;
  2818. while (parent && parent.parentNode) {
  2819. knode = K(parent);
  2820. if (map) {
  2821. if (!knode.isStyle()) {
  2822. break;
  2823. }
  2824. if (!_hasAttrOrCss(knode, map)) {
  2825. break;
  2826. }
  2827. } else {
  2828. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2829. break;
  2830. }
  2831. }
  2832. needSplit = true;
  2833. parent = parent.parentNode;
  2834. }
  2835. if (needSplit) {
  2836. var dummy = doc.createElement('span');
  2837. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2838. if (isStart) {
  2839. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2840. } else {
  2841. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2842. }
  2843. var frag = tempRange.extractContents(),
  2844. first = frag.firstChild, last = frag.lastChild;
  2845. if (isStart) {
  2846. tempRange.insertNode(frag);
  2847. range.setStartAfter(last).setEndBefore(dummy);
  2848. } else {
  2849. parent.appendChild(frag);
  2850. range.setStartBefore(dummy).setEndBefore(first);
  2851. }
  2852. var dummyParent = dummy.parentNode;
  2853. if (dummyParent == range.endContainer) {
  2854. var prev = K(dummy).prev(), next = K(dummy).next();
  2855. if (prev && next && prev.type == 3 && next.type == 3) {
  2856. range.setEnd(prev[0], prev[0].nodeValue.length);
  2857. } else if (!isStart) {
  2858. range.setEnd(range.endContainer, range.endOffset - 1);
  2859. }
  2860. }
  2861. dummyParent.removeChild(dummy);
  2862. }
  2863. return this;
  2864. },
  2865. remove : function(map) {
  2866. var self = this, doc = self.doc, range = self.range;
  2867. range.enlarge();
  2868. if (range.startOffset === 0) {
  2869. var ksc = K(range.startContainer), parent;
  2870. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2871. ksc = parent;
  2872. }
  2873. range.setStart(ksc[0], 0);
  2874. ksc = K(range.startContainer);
  2875. if (ksc.isBlock()) {
  2876. _removeAttrOrCss(ksc, map);
  2877. }
  2878. var kscp = ksc.parent();
  2879. if (kscp && kscp.isBlock()) {
  2880. _removeAttrOrCss(kscp, map);
  2881. }
  2882. }
  2883. var sc, so;
  2884. if (range.collapsed) {
  2885. self.split(true, map);
  2886. sc = range.startContainer;
  2887. so = range.startOffset;
  2888. if (so > 0) {
  2889. var sb = K(sc.childNodes[so - 1]);
  2890. if (sb && _isEmptyNode(sb)) {
  2891. sb.remove();
  2892. range.setStart(sc, so - 1);
  2893. }
  2894. }
  2895. var sa = K(sc.childNodes[so]);
  2896. if (sa && _isEmptyNode(sa)) {
  2897. sa.remove();
  2898. }
  2899. if (_isEmptyNode(sc)) {
  2900. range.startBefore(sc);
  2901. sc.remove();
  2902. }
  2903. range.collapse(true);
  2904. return self;
  2905. }
  2906. self.split(true, map);
  2907. self.split(false, map);
  2908. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2909. range.cloneRange().collapse(false).insertNode(endDummy);
  2910. range.cloneRange().collapse(true).insertNode(startDummy);
  2911. var nodeList = [], cmpStart = false;
  2912. K(range.commonAncestor()).scan(function(node) {
  2913. if (!cmpStart && node == startDummy) {
  2914. cmpStart = true;
  2915. return;
  2916. }
  2917. if (node == endDummy) {
  2918. return false;
  2919. }
  2920. if (cmpStart) {
  2921. nodeList.push(node);
  2922. }
  2923. });
  2924. K(startDummy).remove();
  2925. K(endDummy).remove();
  2926. sc = range.startContainer;
  2927. so = range.startOffset;
  2928. var ec = range.endContainer, eo = range.endOffset;
  2929. if (so > 0) {
  2930. var startBefore = K(sc.childNodes[so - 1]);
  2931. if (startBefore && _isEmptyNode(startBefore)) {
  2932. startBefore.remove();
  2933. range.setStart(sc, so - 1);
  2934. if (sc == ec) {
  2935. range.setEnd(ec, eo - 1);
  2936. }
  2937. }
  2938. var startAfter = K(sc.childNodes[so]);
  2939. if (startAfter && _isEmptyNode(startAfter)) {
  2940. startAfter.remove();
  2941. if (sc == ec) {
  2942. range.setEnd(ec, eo - 1);
  2943. }
  2944. }
  2945. }
  2946. var endAfter = K(ec.childNodes[range.endOffset]);
  2947. if (endAfter && _isEmptyNode(endAfter)) {
  2948. endAfter.remove();
  2949. }
  2950. var bookmark = range.createBookmark(true);
  2951. _each(nodeList, function(i, node) {
  2952. _removeAttrOrCss(K(node), map);
  2953. });
  2954. range.moveToBookmark(bookmark);
  2955. return self;
  2956. },
  2957. commonNode : function(map) {
  2958. var range = this.range;
  2959. var ec = range.endContainer, eo = range.endOffset,
  2960. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2961. function find(node) {
  2962. var child = node, parent = node;
  2963. while (parent) {
  2964. if (_hasAttrOrCss(K(parent), map)) {
  2965. return K(parent);
  2966. }
  2967. parent = parent.parentNode;
  2968. }
  2969. while (child && (child = child.lastChild)) {
  2970. if (_hasAttrOrCss(K(child), map)) {
  2971. return K(child);
  2972. }
  2973. }
  2974. return null;
  2975. }
  2976. var cNode = find(node);
  2977. if (cNode) {
  2978. return cNode;
  2979. }
  2980. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2981. var prev = K(node).prev();
  2982. if (prev) {
  2983. return find(prev);
  2984. }
  2985. }
  2986. return null;
  2987. },
  2988. commonAncestor : function(tagName) {
  2989. var range = this.range,
  2990. sc = range.startContainer, so = range.startOffset,
  2991. ec = range.endContainer, eo = range.endOffset,
  2992. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2993. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2994. function find(node) {
  2995. while (node) {
  2996. if (node.nodeType == 1) {
  2997. if (node.tagName.toLowerCase() === tagName) {
  2998. return node;
  2999. }
  3000. }
  3001. node = node.parentNode;
  3002. }
  3003. return null;
  3004. }
  3005. var start = find(startNode), end = find(endNode);
  3006. if (start && end && start === end) {
  3007. return K(start);
  3008. }
  3009. return null;
  3010. },
  3011. state : function(key) {
  3012. var self = this, doc = self.doc, bool = false;
  3013. try {
  3014. bool = doc.queryCommandState(key);
  3015. } catch (e) {}
  3016. return bool;
  3017. },
  3018. val : function(key) {
  3019. var self = this, doc = self.doc, range = self.range;
  3020. function lc(val) {
  3021. return val.toLowerCase();
  3022. }
  3023. key = lc(key);
  3024. var val = '', knode;
  3025. if (key === 'fontfamily' || key === 'fontname') {
  3026. val = _nativeCommandValue(doc, 'fontname');
  3027. val = val.replace(/['"]/g, '');
  3028. return lc(val);
  3029. }
  3030. if (key === 'formatblock') {
  3031. val = _nativeCommandValue(doc, key);
  3032. if (val === '') {
  3033. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3034. if (knode) {
  3035. val = knode.name;
  3036. }
  3037. }
  3038. if (val === 'Normal') {
  3039. val = 'p';
  3040. }
  3041. return lc(val);
  3042. }
  3043. if (key === 'fontsize') {
  3044. knode = self.commonNode({'*' : '.font-size'});
  3045. if (knode) {
  3046. val = knode.css('font-size');
  3047. }
  3048. return lc(val);
  3049. }
  3050. if (key === 'forecolor') {
  3051. knode = self.commonNode({'*' : '.color'});
  3052. if (knode) {
  3053. val = knode.css('color');
  3054. }
  3055. val = _toHex(val);
  3056. if (val === '') {
  3057. val = 'default';
  3058. }
  3059. return lc(val);
  3060. }
  3061. if (key === 'hilitecolor') {
  3062. knode = self.commonNode({'*' : '.background-color'});
  3063. if (knode) {
  3064. val = knode.css('background-color');
  3065. }
  3066. val = _toHex(val);
  3067. if (val === '') {
  3068. val = 'default';
  3069. }
  3070. return lc(val);
  3071. }
  3072. return val;
  3073. },
  3074. toggle : function(wrapper, map) {
  3075. var self = this;
  3076. if (self.commonNode(map)) {
  3077. self.remove(map);
  3078. } else {
  3079. self.wrap(wrapper);
  3080. }
  3081. return self.select();
  3082. },
  3083. bold : function() {
  3084. return this.toggle('<strong></strong>', {
  3085. span : '.font-weight=bold',
  3086. strong : '*',
  3087. b : '*'
  3088. });
  3089. },
  3090. italic : function() {
  3091. return this.toggle('<em></em>', {
  3092. span : '.font-style=italic',
  3093. em : '*',
  3094. i : '*'
  3095. });
  3096. },
  3097. underline : function() {
  3098. return this.toggle('<u></u>', {
  3099. span : '.text-decoration=underline',
  3100. u : '*'
  3101. });
  3102. },
  3103. strikethrough : function() {
  3104. return this.toggle('<s></s>', {
  3105. span : '.text-decoration=line-through',
  3106. s : '*'
  3107. });
  3108. },
  3109. forecolor : function(val) {
  3110. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3111. },
  3112. hilitecolor : function(val) {
  3113. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3114. },
  3115. fontsize : function(val) {
  3116. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3117. },
  3118. fontname : function(val) {
  3119. return this.fontfamily(val);
  3120. },
  3121. fontfamily : function(val) {
  3122. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3123. },
  3124. removeformat : function() {
  3125. var map = {
  3126. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3127. },
  3128. tags = _STYLE_TAG_MAP;
  3129. _each(tags, function(key, val) {
  3130. map[key] = '*';
  3131. });
  3132. this.remove(map);
  3133. return this.select();
  3134. },
  3135. inserthtml : function(val, quickMode) {
  3136. var self = this, range = self.range;
  3137. if (val === '') {
  3138. return self;
  3139. }
  3140. function pasteHtml(range, val) {
  3141. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3142. var rng = range.get();
  3143. if (rng.item) {
  3144. rng.item(0).outerHTML = val;
  3145. } else {
  3146. rng.pasteHTML(val);
  3147. }
  3148. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3149. temp.parentNode.removeChild(temp);
  3150. var newRange = _toRange(rng);
  3151. range.setEnd(newRange.endContainer, newRange.endOffset);
  3152. range.collapse(false);
  3153. self.select(false);
  3154. }
  3155. function insertHtml(range, val) {
  3156. var doc = range.doc,
  3157. frag = doc.createDocumentFragment();
  3158. K('@' + val, doc).each(function() {
  3159. frag.appendChild(this);
  3160. });
  3161. range.deleteContents();
  3162. range.insertNode(frag);
  3163. range.collapse(false);
  3164. self.select(false);
  3165. }
  3166. if (_IERANGE && quickMode) {
  3167. try {
  3168. pasteHtml(range, val);
  3169. } catch(e) {
  3170. insertHtml(range, val);
  3171. }
  3172. return self;
  3173. }
  3174. insertHtml(range, val);
  3175. return self;
  3176. },
  3177. hr : function() {
  3178. return this.inserthtml('<hr />');
  3179. },
  3180. print : function() {
  3181. this.win.print();
  3182. return this;
  3183. },
  3184. insertimage : function(url, title, width, height, border, align) {
  3185. title = _undef(title, '');
  3186. border = _undef(border, 0);
  3187. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3188. if (width) {
  3189. html += 'width="' + _escape(width) + '" ';
  3190. }
  3191. if (height) {
  3192. html += 'height="' + _escape(height) + '" ';
  3193. }
  3194. if (title) {
  3195. html += 'title="' + _escape(title) + '" ';
  3196. }
  3197. if (align) {
  3198. html += 'align="' + _escape(align) + '" ';
  3199. }
  3200. html += 'alt="' + _escape(title) + '" ';
  3201. html += '/>';
  3202. return this.inserthtml(html);
  3203. },
  3204. createlink : function(url, type) {
  3205. var self = this, doc = self.doc, range = self.range;
  3206. self.select();
  3207. var a = self.commonNode({ a : '*' });
  3208. if (a && !range.isControl()) {
  3209. range.selectNode(a.get());
  3210. self.select();
  3211. }
  3212. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3213. if (type) {
  3214. html += ' target="' + _escape(type) + '"';
  3215. }
  3216. if (range.collapsed) {
  3217. html += '>' + _escape(url) + '</a>';
  3218. return self.inserthtml(html);
  3219. }
  3220. if (range.isControl()) {
  3221. var node = K(range.startContainer.childNodes[range.startOffset]);
  3222. html += '></a>';
  3223. node.after(K(html, doc));
  3224. node.next().append(node);
  3225. range.selectNode(node[0]);
  3226. return self.select();
  3227. }
  3228. function setAttr(node, url, type) {
  3229. K(node).attr('href', url).attr('data-ke-src', url);
  3230. if (type) {
  3231. K(node).attr('target', type);
  3232. } else {
  3233. K(node).removeAttr('target');
  3234. }
  3235. }
  3236. var sc = range.startContainer, so = range.startOffset,
  3237. ec = range.endContainer, eo = range.endOffset;
  3238. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3239. var child = sc.childNodes[so];
  3240. if (child.nodeName.toLowerCase() == 'a') {
  3241. setAttr(child, url, type);
  3242. return self;
  3243. }
  3244. }
  3245. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3246. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3247. setAttr(this, url, type);
  3248. });
  3249. return self;
  3250. },
  3251. unlink : function() {
  3252. var self = this, doc = self.doc, range = self.range;
  3253. self.select();
  3254. if (range.collapsed) {
  3255. var a = self.commonNode({ a : '*' });
  3256. if (a) {
  3257. range.selectNode(a.get());
  3258. self.select();
  3259. }
  3260. _nativeCommand(doc, 'unlink', null);
  3261. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3262. var parent = K(range.startContainer).parent();
  3263. if (parent.name === 'a') {
  3264. parent.remove(true);
  3265. }
  3266. }
  3267. } else {
  3268. _nativeCommand(doc, 'unlink', null);
  3269. }
  3270. return self;
  3271. }
  3272. });
  3273. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3274. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3275. KCmd.prototype[name] = function(val) {
  3276. var self = this;
  3277. self.select();
  3278. _nativeCommand(self.doc, name, val);
  3279. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3280. self.selection();
  3281. }
  3282. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3283. self.selection();
  3284. }
  3285. return self;
  3286. };
  3287. });
  3288. _each('cut,copy,paste'.split(','), function(i, name) {
  3289. KCmd.prototype[name] = function() {
  3290. var self = this;
  3291. if (!self.doc.queryCommandSupported(name)) {
  3292. throw 'not supported';
  3293. }
  3294. self.select();
  3295. _nativeCommand(self.doc, name, null);
  3296. return self;
  3297. };
  3298. });
  3299. function _cmd(mixed) {
  3300. if (mixed.nodeName) {
  3301. var doc = _getDoc(mixed);
  3302. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3303. }
  3304. return new KCmd(mixed);
  3305. }
  3306. K.CmdClass = KCmd;
  3307. K.cmd = _cmd;
  3308. function _drag(options) {
  3309. var moveEl = options.moveEl,
  3310. moveFn = options.moveFn,
  3311. clickEl = options.clickEl || moveEl,
  3312. beforeDrag = options.beforeDrag,
  3313. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3314. var docs = [document];
  3315. if (iframeFix) {
  3316. K('iframe').each(function() {
  3317. var src = _formatUrl(this.src || '', 'absolute');
  3318. if (/^https?:\/\//.test(src)) {
  3319. return;
  3320. }
  3321. var doc;
  3322. try {
  3323. doc = _iframeDoc(this);
  3324. } catch(e) {}
  3325. if (doc) {
  3326. var pos = K(this).pos();
  3327. K(doc).data('pos-x', pos.x);
  3328. K(doc).data('pos-y', pos.y);
  3329. docs.push(doc);
  3330. }
  3331. });
  3332. }
  3333. clickEl.mousedown(function(e) {
  3334. e.stopPropagation();
  3335. var self = clickEl.get(),
  3336. x = _removeUnit(moveEl.css('left')),
  3337. y = _removeUnit(moveEl.css('top')),
  3338. width = moveEl.width(),
  3339. height = moveEl.height(),
  3340. pageX = e.pageX,
  3341. pageY = e.pageY;
  3342. if (beforeDrag) {
  3343. beforeDrag();
  3344. }
  3345. function moveListener(e) {
  3346. e.preventDefault();
  3347. var kdoc = K(_getDoc(e.target));
  3348. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3349. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3350. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3351. }
  3352. function selectListener(e) {
  3353. e.preventDefault();
  3354. }
  3355. function upListener(e) {
  3356. e.preventDefault();
  3357. K(docs).unbind('mousemove', moveListener)
  3358. .unbind('mouseup', upListener)
  3359. .unbind('selectstart', selectListener);
  3360. if (self.releaseCapture) {
  3361. self.releaseCapture();
  3362. }
  3363. }
  3364. K(docs).mousemove(moveListener)
  3365. .mouseup(upListener)
  3366. .bind('selectstart', selectListener);
  3367. if (self.setCapture) {
  3368. self.setCapture();
  3369. }
  3370. });
  3371. }
  3372. function KWidget(options) {
  3373. this.init(options);
  3374. }
  3375. _extend(KWidget, {
  3376. init : function(options) {
  3377. var self = this;
  3378. self.name = options.name || '';
  3379. self.doc = options.doc || document;
  3380. self.win = _getWin(self.doc);
  3381. self.x = _addUnit(options.x);
  3382. self.y = _addUnit(options.y);
  3383. self.z = options.z;
  3384. self.width = _addUnit(options.width);
  3385. self.height = _addUnit(options.height);
  3386. self.div = K('<div style="display:block;"></div>');
  3387. self.options = options;
  3388. self._alignEl = options.alignEl;
  3389. if (self.width) {
  3390. self.div.css('width', self.width);
  3391. }
  3392. if (self.height) {
  3393. self.div.css('height', self.height);
  3394. }
  3395. if (self.z) {
  3396. self.div.css({
  3397. position : 'absolute',
  3398. left : self.x,
  3399. top : self.y,
  3400. 'z-index' : self.z
  3401. });
  3402. }
  3403. if (self.z && (self.x === undefined || self.y === undefined)) {
  3404. self.autoPos(self.width, self.height);
  3405. }
  3406. if (options.cls) {
  3407. self.div.addClass(options.cls);
  3408. }
  3409. if (options.shadowMode) {
  3410. self.div.addClass('ke-shadow');
  3411. }
  3412. if (options.css) {
  3413. self.div.css(options.css);
  3414. }
  3415. if (options.src) {
  3416. K(options.src).replaceWith(self.div);
  3417. } else {
  3418. K(self.doc.body).append(self.div);
  3419. }
  3420. if (options.html) {
  3421. self.div.html(options.html);
  3422. }
  3423. if (options.autoScroll) {
  3424. if (_IE && _V < 7 || _QUIRKS) {
  3425. var scrollPos = _getScrollPos();
  3426. K(self.win).bind('scroll', function(e) {
  3427. var pos = _getScrollPos(),
  3428. diffX = pos.x - scrollPos.x,
  3429. diffY = pos.y - scrollPos.y;
  3430. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3431. });
  3432. } else {
  3433. self.div.css('position', 'fixed');
  3434. }
  3435. }
  3436. },
  3437. pos : function(x, y, updateProp) {
  3438. var self = this;
  3439. updateProp = _undef(updateProp, true);
  3440. if (x !== null) {
  3441. x = x < 0 ? 0 : _addUnit(x);
  3442. self.div.css('left', x);
  3443. if (updateProp) {
  3444. self.x = x;
  3445. }
  3446. }
  3447. if (y !== null) {
  3448. y = y < 0 ? 0 : _addUnit(y);
  3449. self.div.css('top', y);
  3450. if (updateProp) {
  3451. self.y = y;
  3452. }
  3453. }
  3454. return self;
  3455. },
  3456. autoPos : function(width, height) {
  3457. var self = this,
  3458. w = _removeUnit(width) || 0,
  3459. h = _removeUnit(height) || 0,
  3460. scrollPos = _getScrollPos();
  3461. if (self._alignEl) {
  3462. var knode = K(self._alignEl),
  3463. pos = knode.pos(),
  3464. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3465. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3466. x = diffX < 0 ? pos.x : pos.x + diffX;
  3467. y = diffY < 0 ? pos.y : pos.y + diffY;
  3468. } else {
  3469. var docEl = _docElement(self.doc);
  3470. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3471. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3472. }
  3473. if (!(_IE && _V < 7 || _QUIRKS)) {
  3474. x -= scrollPos.x;
  3475. y -= scrollPos.y;
  3476. }
  3477. return self.pos(x, y);
  3478. },
  3479. remove : function() {
  3480. var self = this;
  3481. if (_IE && _V < 7 || _QUIRKS) {
  3482. K(self.win).unbind('scroll');
  3483. }
  3484. self.div.remove();
  3485. _each(self, function(i) {
  3486. self[i] = null;
  3487. });
  3488. return this;
  3489. },
  3490. show : function() {
  3491. this.div.show();
  3492. return this;
  3493. },
  3494. hide : function() {
  3495. this.div.hide();
  3496. return this;
  3497. },
  3498. draggable : function(options) {
  3499. var self = this;
  3500. options = options || {};
  3501. options.moveEl = self.div;
  3502. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3503. if ((x = x + diffX) < 0) {
  3504. x = 0;
  3505. }
  3506. if ((y = y + diffY) < 0) {
  3507. y = 0;
  3508. }
  3509. self.pos(x, y);
  3510. };
  3511. _drag(options);
  3512. return self;
  3513. }
  3514. });
  3515. function _widget(options) {
  3516. return new KWidget(options);
  3517. }
  3518. K.WidgetClass = KWidget;
  3519. K.widget = _widget;
  3520. function _iframeDoc(iframe) {
  3521. iframe = _get(iframe);
  3522. return iframe.contentDocument || iframe.contentWindow.document;
  3523. }
  3524. var html, _direction = '';
  3525. if ((html = document.getElementsByTagName('html'))) {
  3526. _direction = html[0].dir;
  3527. }
  3528. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3529. var arr = [
  3530. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3531. '<head><meta charset="utf-8" /><title></title>',
  3532. '<style>',
  3533. 'html {margin:0;padding:0;}',
  3534. 'body {margin:0;padding:5px;}',
  3535. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3536. 'body, p, div {word-wrap: break-word;}',
  3537. 'p {margin:5px 0;}',
  3538. 'table {border-collapse:collapse;}',
  3539. 'img {border:0;}',
  3540. 'noscript {display:none;}',
  3541. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3542. 'img.ke-flash {',
  3543. ' border:1px solid #AAA;',
  3544. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3545. ' background-position:center center;',
  3546. ' background-repeat:no-repeat;',
  3547. ' width:100px;',
  3548. ' height:100px;',
  3549. '}',
  3550. 'img.ke-rm {',
  3551. ' border:1px solid #AAA;',
  3552. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3553. ' background-position:center center;',
  3554. ' background-repeat:no-repeat;',
  3555. ' width:100px;',
  3556. ' height:100px;',
  3557. '}',
  3558. 'img.ke-media {',
  3559. ' border:1px solid #AAA;',
  3560. ' background-image:url(' + themesPath + 'common/media.gif);',
  3561. ' background-position:center center;',
  3562. ' background-repeat:no-repeat;',
  3563. ' width:100px;',
  3564. ' height:100px;',
  3565. '}',
  3566. 'img.ke-anchor {',
  3567. ' border:1px dashed #666;',
  3568. ' width:16px;',
  3569. ' height:16px;',
  3570. '}',
  3571. '.ke-script, .ke-noscript, .ke-display-none {',
  3572. ' display:none;',
  3573. ' font-size:0;',
  3574. ' width:0;',
  3575. ' height:0;',
  3576. '}',
  3577. '.ke-pagebreak {',
  3578. ' border:1px dotted #AAA;',
  3579. ' font-size:0;',
  3580. ' height:2px;',
  3581. '}',
  3582. '</style>'
  3583. ];
  3584. if (!_isArray(cssPath)) {
  3585. cssPath = [cssPath];
  3586. }
  3587. _each(cssPath, function(i, path) {
  3588. if (path) {
  3589. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3590. }
  3591. });
  3592. if (cssData) {
  3593. arr.push('<style>' + cssData + '</style>');
  3594. }
  3595. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3596. return arr.join('\n');
  3597. }
  3598. function _elementVal(knode, val) {
  3599. if (knode.hasVal()) {
  3600. if (val === undefined) {
  3601. var html = knode.val();
  3602. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3603. return html;
  3604. }
  3605. return knode.val(val);
  3606. }
  3607. return knode.html(val);
  3608. }
  3609. function KEdit(options) {
  3610. this.init(options);
  3611. }
  3612. _extend(KEdit, KWidget, {
  3613. init : function(options) {
  3614. var self = this;
  3615. KEdit.parent.init.call(self, options);
  3616. self.srcElement = K(options.srcElement);
  3617. self.div.addClass('ke-edit');
  3618. self.designMode = _undef(options.designMode, true);
  3619. self.beforeGetHtml = options.beforeGetHtml;
  3620. self.beforeSetHtml = options.beforeSetHtml;
  3621. self.afterSetHtml = options.afterSetHtml;
  3622. var themesPath = _undef(options.themesPath, ''),
  3623. bodyClass = options.bodyClass,
  3624. cssPath = options.cssPath,
  3625. cssData = options.cssData,
  3626. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3627. srcScript = ('document.open();' +
  3628. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3629. 'document.close();'),
  3630. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3631. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3632. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3633. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3634. self.iframe.attr('tabindex', self.tabIndex);
  3635. self.textarea.attr('tabindex', self.tabIndex);
  3636. if (self.width) {
  3637. self.setWidth(self.width);
  3638. }
  3639. if (self.height) {
  3640. self.setHeight(self.height);
  3641. }
  3642. if (self.designMode) {
  3643. self.textarea.hide();
  3644. } else {
  3645. self.iframe.hide();
  3646. }
  3647. function ready() {
  3648. var doc = _iframeDoc(self.iframe);
  3649. doc.open();
  3650. if (isDocumentDomain) {
  3651. doc.domain = document.domain;
  3652. }
  3653. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3654. doc.close();
  3655. self.win = self.iframe[0].contentWindow;
  3656. self.doc = doc;
  3657. var cmd = _cmd(doc);
  3658. self.afterChange(function(e) {
  3659. cmd.selection();
  3660. });
  3661. if (_WEBKIT) {
  3662. K(doc).click(function(e) {
  3663. if (K(e.target).name === 'img') {
  3664. cmd.selection(true);
  3665. cmd.range.selectNode(e.target);
  3666. cmd.select();
  3667. }
  3668. });
  3669. }
  3670. if (_IE) {
  3671. self._mousedownHandler = function() {
  3672. var newRange = cmd.range.cloneRange();
  3673. newRange.shrink();
  3674. if (newRange.isControl()) {
  3675. self.blur();
  3676. }
  3677. };
  3678. K(document).mousedown(self._mousedownHandler);
  3679. K(doc).keydown(function(e) {
  3680. if (e.which == 8) {
  3681. cmd.selection();
  3682. var rng = cmd.range;
  3683. if (rng.isControl()) {
  3684. rng.collapse(true);
  3685. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3686. e.preventDefault();
  3687. }
  3688. }
  3689. });
  3690. }
  3691. self.cmd = cmd;
  3692. self.html(_elementVal(self.srcElement));
  3693. if (_IE) {
  3694. doc.body.disabled = true;
  3695. doc.body.contentEditable = true;
  3696. doc.body.removeAttribute('disabled');
  3697. } else {
  3698. doc.designMode = 'on';
  3699. }
  3700. if (options.afterCreate) {
  3701. options.afterCreate.call(self);
  3702. }
  3703. }
  3704. if (isDocumentDomain) {
  3705. self.iframe.bind('load', function(e) {
  3706. self.iframe.unbind('load');
  3707. if (_IE) {
  3708. ready();
  3709. } else {
  3710. setTimeout(ready, 0);
  3711. }
  3712. });
  3713. }
  3714. self.div.append(self.iframe);
  3715. self.div.append(self.textarea);
  3716. self.srcElement.hide();
  3717. !isDocumentDomain && ready();
  3718. },
  3719. setWidth : function(val) {
  3720. var self = this;
  3721. val = _addUnit(val);
  3722. self.width = val;
  3723. self.div.css('width', val);
  3724. return self;
  3725. },
  3726. setHeight : function(val) {
  3727. var self = this;
  3728. val = _addUnit(val);
  3729. self.height = val;
  3730. self.div.css('height', val);
  3731. self.iframe.css('height', val);
  3732. if ((_IE && _V < 8) || _QUIRKS) {
  3733. val = _addUnit(_removeUnit(val) - 2);
  3734. }
  3735. self.textarea.css('height', val);
  3736. return self;
  3737. },
  3738. remove : function() {
  3739. var self = this, doc = self.doc;
  3740. K(doc.body).unbind();
  3741. K(doc).unbind();
  3742. K(self.win).unbind();
  3743. if (self._mousedownHandler) {
  3744. K(document).unbind('mousedown', self._mousedownHandler);
  3745. }
  3746. _elementVal(self.srcElement, self.html());
  3747. self.srcElement.show();
  3748. doc.write('');
  3749. self.iframe.unbind();
  3750. self.textarea.unbind();
  3751. KEdit.parent.remove.call(self);
  3752. },
  3753. html : function(val, isFull) {
  3754. var self = this, doc = self.doc;
  3755. if (self.designMode) {
  3756. var body = doc.body;
  3757. if (val === undefined) {
  3758. if (isFull) {
  3759. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3760. } else {
  3761. val = body.innerHTML;
  3762. }
  3763. if (self.beforeGetHtml) {
  3764. val = self.beforeGetHtml(val);
  3765. }
  3766. if (_GECKO && val == '<br />') {
  3767. val = '';
  3768. }
  3769. return val;
  3770. }
  3771. if (self.beforeSetHtml) {
  3772. val = self.beforeSetHtml(val);
  3773. }
  3774. if (_IE && _V >= 9) {
  3775. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3776. }
  3777. K(body).html(val);
  3778. if (self.afterSetHtml) {
  3779. self.afterSetHtml();
  3780. }
  3781. return self;
  3782. }
  3783. if (val === undefined) {
  3784. return self.textarea.val();
  3785. }
  3786. self.textarea.val(val);
  3787. return self;
  3788. },
  3789. design : function(bool) {
  3790. var self = this, val;
  3791. if (bool === undefined ? !self.designMode : bool) {
  3792. if (!self.designMode) {
  3793. val = self.html();
  3794. self.designMode = true;
  3795. self.html(val);
  3796. self.textarea.hide();
  3797. self.iframe.show();
  3798. }
  3799. } else {
  3800. if (self.designMode) {
  3801. val = self.html();
  3802. self.designMode = false;
  3803. self.html(val);
  3804. self.iframe.hide();
  3805. self.textarea.show();
  3806. }
  3807. }
  3808. return self.focus();
  3809. },
  3810. focus : function() {
  3811. var self = this;
  3812. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3813. return self;
  3814. },
  3815. blur : function() {
  3816. var self = this;
  3817. if (_IE) {
  3818. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3819. self.div.append(input);
  3820. input[0].focus();
  3821. input.remove();
  3822. } else {
  3823. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3824. }
  3825. return self;
  3826. },
  3827. afterChange : function(fn) {
  3828. var self = this, doc = self.doc, body = doc.body;
  3829. K(doc).keyup(function(e) {
  3830. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3831. fn(e);
  3832. }
  3833. });
  3834. K(doc).mouseup(fn).contextmenu(fn);
  3835. K(self.win).blur(fn);
  3836. function timeoutHandler(e) {
  3837. setTimeout(function() {
  3838. fn(e);
  3839. }, 1);
  3840. }
  3841. K(body).bind('paste', timeoutHandler);
  3842. K(body).bind('cut', timeoutHandler);
  3843. return self;
  3844. }
  3845. });
  3846. function _edit(options) {
  3847. return new KEdit(options);
  3848. }
  3849. K.EditClass = KEdit;
  3850. K.edit = _edit;
  3851. K.iframeDoc = _iframeDoc;
  3852. function _selectToolbar(name, fn) {
  3853. var self = this,
  3854. knode = self.get(name);
  3855. if (knode) {
  3856. if (knode.hasClass('ke-disabled')) {
  3857. return;
  3858. }
  3859. fn(knode);
  3860. }
  3861. }
  3862. function KToolbar(options) {
  3863. this.init(options);
  3864. }
  3865. _extend(KToolbar, KWidget, {
  3866. init : function(options) {
  3867. var self = this;
  3868. KToolbar.parent.init.call(self, options);
  3869. self.disableMode = _undef(options.disableMode, false);
  3870. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3871. self._itemMap = {};
  3872. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3873. e.preventDefault();
  3874. }).attr('unselectable', 'on');
  3875. function find(target) {
  3876. var knode = K(target);
  3877. if (knode.hasClass('ke-outline')) {
  3878. return knode;
  3879. }
  3880. if (knode.hasClass('ke-toolbar-icon')) {
  3881. return knode.parent();
  3882. }
  3883. }
  3884. function hover(e, method) {
  3885. var knode = find(e.target);
  3886. if (knode) {
  3887. if (knode.hasClass('ke-disabled')) {
  3888. return;
  3889. }
  3890. if (knode.hasClass('ke-selected')) {
  3891. return;
  3892. }
  3893. knode[method]('ke-on');
  3894. }
  3895. }
  3896. self.div.mouseover(function(e) {
  3897. hover(e, 'addClass');
  3898. })
  3899. .mouseout(function(e) {
  3900. hover(e, 'removeClass');
  3901. })
  3902. .click(function(e) {
  3903. var knode = find(e.target);
  3904. if (knode) {
  3905. if (knode.hasClass('ke-disabled')) {
  3906. return;
  3907. }
  3908. self.options.click.call(this, e, knode.attr('data-name'));
  3909. }
  3910. });
  3911. },
  3912. get : function(name) {
  3913. if (this._itemMap[name]) {
  3914. return this._itemMap[name];
  3915. }
  3916. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3917. },
  3918. select : function(name) {
  3919. _selectToolbar.call(this, name, function(knode) {
  3920. knode.addClass('ke-selected');
  3921. });
  3922. return self;
  3923. },
  3924. unselect : function(name) {
  3925. _selectToolbar.call(this, name, function(knode) {
  3926. knode.removeClass('ke-selected').removeClass('ke-on');
  3927. });
  3928. return self;
  3929. },
  3930. enable : function(name) {
  3931. var self = this,
  3932. knode = name.get ? name : self.get(name);
  3933. if (knode) {
  3934. knode.removeClass('ke-disabled');
  3935. knode.opacity(1);
  3936. }
  3937. return self;
  3938. },
  3939. disable : function(name) {
  3940. var self = this,
  3941. knode = name.get ? name : self.get(name);
  3942. if (knode) {
  3943. knode.removeClass('ke-selected').addClass('ke-disabled');
  3944. knode.opacity(0.5);
  3945. }
  3946. return self;
  3947. },
  3948. disableAll : function(bool, noDisableItems) {
  3949. var self = this, map = self.noDisableItemMap, item;
  3950. if (noDisableItems) {
  3951. map = _toMap(noDisableItems);
  3952. }
  3953. if (bool === undefined ? !self.disableMode : bool) {
  3954. K('span.ke-outline', self.div).each(function() {
  3955. var knode = K(this),
  3956. name = knode[0].getAttribute('data-name', 2);
  3957. if (!map[name]) {
  3958. self.disable(knode);
  3959. }
  3960. });
  3961. self.disableMode = true;
  3962. } else {
  3963. K('span.ke-outline', self.div).each(function() {
  3964. var knode = K(this),
  3965. name = knode[0].getAttribute('data-name', 2);
  3966. if (!map[name]) {
  3967. self.enable(knode);
  3968. }
  3969. });
  3970. self.disableMode = false;
  3971. }
  3972. return self;
  3973. }
  3974. });
  3975. function _toolbar(options) {
  3976. return new KToolbar(options);
  3977. }
  3978. K.ToolbarClass = KToolbar;
  3979. K.toolbar = _toolbar;
  3980. function KMenu(options) {
  3981. this.init(options);
  3982. }
  3983. _extend(KMenu, KWidget, {
  3984. init : function(options) {
  3985. var self = this;
  3986. options.z = options.z || 811213;
  3987. KMenu.parent.init.call(self, options);
  3988. self.centerLineMode = _undef(options.centerLineMode, true);
  3989. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  3990. e.stopPropagation();
  3991. }).attr('unselectable', 'on');
  3992. },
  3993. addItem : function(item) {
  3994. var self = this;
  3995. if (item.title === '-') {
  3996. self.div.append(K('<div class="ke-menu-separator"></div>'));
  3997. return;
  3998. }
  3999. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4000. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4001. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4002. height = _addUnit(item.height),
  4003. iconClass = _undef(item.iconClass, '');
  4004. self.div.append(itemDiv);
  4005. if (height) {
  4006. itemDiv.css('height', height);
  4007. rightDiv.css('line-height', height);
  4008. }
  4009. var centerDiv;
  4010. if (self.centerLineMode) {
  4011. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4012. if (height) {
  4013. centerDiv.css('height', height);
  4014. }
  4015. }
  4016. itemDiv.mouseover(function(e) {
  4017. K(this).addClass('ke-menu-item-on');
  4018. if (centerDiv) {
  4019. centerDiv.addClass('ke-menu-item-center-on');
  4020. }
  4021. })
  4022. .mouseout(function(e) {
  4023. K(this).removeClass('ke-menu-item-on');
  4024. if (centerDiv) {
  4025. centerDiv.removeClass('ke-menu-item-center-on');
  4026. }
  4027. })
  4028. .click(function(e) {
  4029. item.click.call(K(this));
  4030. e.stopPropagation();
  4031. })
  4032. .append(leftDiv);
  4033. if (centerDiv) {
  4034. itemDiv.append(centerDiv);
  4035. }
  4036. itemDiv.append(rightDiv);
  4037. if (item.checked) {
  4038. iconClass = 'ke-icon-checked';
  4039. }
  4040. if (iconClass !== '') {
  4041. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4042. }
  4043. rightDiv.html(item.title);
  4044. return self;
  4045. },
  4046. remove : function() {
  4047. var self = this;
  4048. if (self.options.beforeRemove) {
  4049. self.options.beforeRemove.call(self);
  4050. }
  4051. K('.ke-menu-item', self.div[0]).unbind();
  4052. KMenu.parent.remove.call(self);
  4053. return self;
  4054. }
  4055. });
  4056. function _menu(options) {
  4057. return new KMenu(options);
  4058. }
  4059. K.MenuClass = KMenu;
  4060. K.menu = _menu;
  4061. function KColorPicker(options) {
  4062. this.init(options);
  4063. }
  4064. _extend(KColorPicker, KWidget, {
  4065. init : function(options) {
  4066. var self = this;
  4067. options.z = options.z || 811213;
  4068. KColorPicker.parent.init.call(self, options);
  4069. var colors = options.colors || [
  4070. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4071. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4072. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4073. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4074. ];
  4075. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4076. self._cells = [];
  4077. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4078. e.stopPropagation();
  4079. }).attr('unselectable', 'on');
  4080. var table = self.doc.createElement('table');
  4081. self.div.append(table);
  4082. table.className = 'ke-colorpicker-table';
  4083. table.cellPadding = 0;
  4084. table.cellSpacing = 0;
  4085. table.border = 0;
  4086. var row = table.insertRow(0), cell = row.insertCell(0);
  4087. cell.colSpan = colors[0].length;
  4088. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4089. for (var i = 0; i < colors.length; i++) {
  4090. row = table.insertRow(i + 1);
  4091. for (var j = 0; j < colors[i].length; j++) {
  4092. cell = row.insertCell(j);
  4093. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4094. }
  4095. }
  4096. },
  4097. _addAttr : function(cell, color, cls) {
  4098. var self = this;
  4099. cell = K(cell).addClass(cls);
  4100. if (self.selectedColor === color.toLowerCase()) {
  4101. cell.addClass('ke-colorpicker-cell-selected');
  4102. }
  4103. cell.attr('title', color || self.options.noColor);
  4104. cell.mouseover(function(e) {
  4105. K(this).addClass('ke-colorpicker-cell-on');
  4106. });
  4107. cell.mouseout(function(e) {
  4108. K(this).removeClass('ke-colorpicker-cell-on');
  4109. });
  4110. cell.click(function(e) {
  4111. e.stop();
  4112. self.options.click.call(K(this), color);
  4113. });
  4114. if (color) {
  4115. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4116. } else {
  4117. cell.html(self.options.noColor);
  4118. }
  4119. K(cell).attr('unselectable', 'on');
  4120. self._cells.push(cell);
  4121. },
  4122. remove : function() {
  4123. var self = this;
  4124. _each(self._cells, function() {
  4125. this.unbind();
  4126. });
  4127. KColorPicker.parent.remove.call(self);
  4128. return self;
  4129. }
  4130. });
  4131. function _colorpicker(options) {
  4132. return new KColorPicker(options);
  4133. }
  4134. K.ColorPickerClass = KColorPicker;
  4135. K.colorpicker = _colorpicker;
  4136. function KUploadButton(options) {
  4137. this.init(options);
  4138. }
  4139. _extend(KUploadButton, {
  4140. init : function(options) {
  4141. var self = this,
  4142. button = K(options.button),
  4143. fieldName = options.fieldName || 'file',
  4144. url = options.url || '',
  4145. title = button.val(),
  4146. extraParams = options.extraParams || {},
  4147. cls = button[0].className || '',
  4148. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4149. options.afterError = options.afterError || function(str) {
  4150. alert(str);
  4151. };
  4152. var hiddenElements = [];
  4153. for(var k in extraParams){
  4154. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4155. }
  4156. var html = [
  4157. '<div class="ke-inline-block ' + cls + '">',
  4158. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4159. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4160. '<span class="ke-button-common">',
  4161. hiddenElements.join(''),
  4162. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4163. '</span>',
  4164. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4165. (options.form ? '</div>' : '</form>'),
  4166. '</div>'].join('');
  4167. var div = K(html, button.doc);
  4168. button.hide();
  4169. button.before(div);
  4170. self.div = div;
  4171. self.button = button;
  4172. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4173. self.form = options.form ? K(options.form) : K('form', div);
  4174. self.fileBox = K('.ke-upload-file', div);
  4175. var width = options.width || K('.ke-button-common', div).width();
  4176. K('.ke-upload-area', div).width(width);
  4177. self.options = options;
  4178. },
  4179. submit : function() {
  4180. var self = this,
  4181. iframe = self.iframe;
  4182. iframe.bind('load', function() {
  4183. iframe.unbind();
  4184. var tempForm = document.createElement('form');
  4185. self.fileBox.before(tempForm);
  4186. K(tempForm).append(self.fileBox);
  4187. tempForm.reset();
  4188. K(tempForm).remove(true);
  4189. var doc = K.iframeDoc(iframe),
  4190. pre = doc.getElementsByTagName('pre')[0],
  4191. str = '', data;
  4192. if (pre) {
  4193. str = pre.innerHTML;
  4194. } else {
  4195. str = doc.body.innerHTML;
  4196. }
  4197. str = _unescape(str);
  4198. iframe[0].src = 'javascript:false';
  4199. try {
  4200. data = K.json(str);
  4201. } catch (e) {
  4202. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4203. }
  4204. if (data) {
  4205. self.options.afterUpload.call(self, data);
  4206. }
  4207. });
  4208. self.form[0].submit();
  4209. return self;
  4210. },
  4211. remove : function() {
  4212. var self = this;
  4213. if (self.fileBox) {
  4214. self.fileBox.unbind();
  4215. }
  4216. self.iframe.remove();
  4217. self.div.remove();
  4218. self.button.show();
  4219. return self;
  4220. }
  4221. });
  4222. function _uploadbutton(options) {
  4223. return new KUploadButton(options);
  4224. }
  4225. K.UploadButtonClass = KUploadButton;
  4226. K.uploadbutton = _uploadbutton;
  4227. function _createButton(arg) {
  4228. arg = arg || {};
  4229. var name = arg.name || '',
  4230. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4231. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4232. if (arg.click) {
  4233. btn.click(arg.click);
  4234. }
  4235. span.append(btn);
  4236. return span;
  4237. }
  4238. function KDialog(options) {
  4239. this.init(options);
  4240. }
  4241. _extend(KDialog, KWidget, {
  4242. init : function(options) {
  4243. var self = this;
  4244. var shadowMode = _undef(options.shadowMode, true);
  4245. options.z = options.z || 811213;
  4246. options.shadowMode = false;
  4247. options.autoScroll = _undef(options.autoScroll, true);
  4248. KDialog.parent.init.call(self, options);
  4249. var title = options.title,
  4250. body = K(options.body, self.doc),
  4251. previewBtn = options.previewBtn,
  4252. yesBtn = options.yesBtn,
  4253. noBtn = options.noBtn,
  4254. closeBtn = options.closeBtn,
  4255. showMask = _undef(options.showMask, true);
  4256. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4257. e.stopPropagation();
  4258. });
  4259. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4260. if (_IE && _V < 7) {
  4261. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4262. } else if (shadowMode) {
  4263. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4264. }
  4265. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4266. contentDiv.append(headerDiv);
  4267. headerDiv.html(title);
  4268. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4269. headerDiv.append(self.closeIcon);
  4270. self.draggable({
  4271. clickEl : headerDiv,
  4272. beforeDrag : options.beforeDrag
  4273. });
  4274. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4275. contentDiv.append(bodyDiv);
  4276. bodyDiv.append(body);
  4277. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4278. if (previewBtn || yesBtn || noBtn) {
  4279. contentDiv.append(footerDiv);
  4280. }
  4281. _each([
  4282. { btn : previewBtn, name : 'preview' },
  4283. { btn : yesBtn, name : 'yes' },
  4284. { btn : noBtn, name : 'no' }
  4285. ], function() {
  4286. if (this.btn) {
  4287. var button = _createButton(this.btn);
  4288. button.addClass('ke-dialog-' + this.name);
  4289. footerDiv.append(button);
  4290. }
  4291. });
  4292. if (self.height) {
  4293. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4294. }
  4295. self.div.width(self.div.width());
  4296. self.div.height(self.div.height());
  4297. self.mask = null;
  4298. if (showMask) {
  4299. var docEl = _docElement(self.doc),
  4300. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4301. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4302. self.mask = _widget({
  4303. x : 0,
  4304. y : 0,
  4305. z : self.z - 1,
  4306. cls : 'ke-dialog-mask',
  4307. width : docWidth,
  4308. height : docHeight
  4309. });
  4310. }
  4311. self.autoPos(self.div.width(), self.div.height());
  4312. self.footerDiv = footerDiv;
  4313. self.bodyDiv = bodyDiv;
  4314. self.headerDiv = headerDiv;
  4315. self.isLoading = false;
  4316. },
  4317. setMaskIndex : function(z) {
  4318. var self = this;
  4319. self.mask.div.css('z-index', z);
  4320. },
  4321. showLoading : function(msg) {
  4322. msg = _undef(msg, '');
  4323. var self = this, body = self.bodyDiv;
  4324. 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>')
  4325. .width(body.width()).height(body.height())
  4326. .css('top', self.headerDiv.height() + 'px');
  4327. body.css('visibility', 'hidden').after(self.loading);
  4328. self.isLoading = true;
  4329. return self;
  4330. },
  4331. hideLoading : function() {
  4332. this.loading && this.loading.remove();
  4333. this.bodyDiv.css('visibility', 'visible');
  4334. this.isLoading = false;
  4335. return this;
  4336. },
  4337. remove : function() {
  4338. var self = this;
  4339. if (self.options.beforeRemove) {
  4340. self.options.beforeRemove.call(self);
  4341. }
  4342. self.mask && self.mask.remove();
  4343. self.iframeMask && self.iframeMask.remove();
  4344. self.closeIcon.unbind();
  4345. K('input', self.div).unbind();
  4346. K('button', self.div).unbind();
  4347. self.footerDiv.unbind();
  4348. self.bodyDiv.unbind();
  4349. self.headerDiv.unbind();
  4350. K('iframe', self.div).each(function() {
  4351. K(this).remove();
  4352. });
  4353. KDialog.parent.remove.call(self);
  4354. return self;
  4355. }
  4356. });
  4357. function _dialog(options) {
  4358. return new KDialog(options);
  4359. }
  4360. K.DialogClass = KDialog;
  4361. K.dialog = _dialog;
  4362. function _tabs(options) {
  4363. var self = _widget(options),
  4364. remove = self.remove,
  4365. afterSelect = options.afterSelect,
  4366. div = self.div,
  4367. liList = [];
  4368. div.addClass('ke-tabs')
  4369. .bind('contextmenu,mousedown,mousemove', function(e) {
  4370. e.preventDefault();
  4371. });
  4372. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4373. div.append(ul);
  4374. self.add = function(tab) {
  4375. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4376. li.data('tab', tab);
  4377. liList.push(li);
  4378. ul.append(li);
  4379. };
  4380. self.selectedIndex = 0;
  4381. self.select = function(index) {
  4382. self.selectedIndex = index;
  4383. _each(liList, function(i, li) {
  4384. li.unbind();
  4385. if (i === index) {
  4386. li.addClass('ke-tabs-li-selected');
  4387. K(li.data('tab').panel).show('');
  4388. } else {
  4389. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4390. .mouseover(function() {
  4391. K(this).addClass('ke-tabs-li-on');
  4392. })
  4393. .mouseout(function() {
  4394. K(this).removeClass('ke-tabs-li-on');
  4395. })
  4396. .click(function() {
  4397. self.select(i);
  4398. });
  4399. K(li.data('tab').panel).hide();
  4400. }
  4401. });
  4402. if (afterSelect) {
  4403. afterSelect.call(self, index);
  4404. }
  4405. };
  4406. self.remove = function() {
  4407. _each(liList, function() {
  4408. this.remove();
  4409. });
  4410. ul.remove();
  4411. remove.call(self);
  4412. };
  4413. return self;
  4414. }
  4415. K.tabs = _tabs;
  4416. function _loadScript(url, fn) {
  4417. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4418. script = document.createElement('script');
  4419. head.appendChild(script);
  4420. script.src = url;
  4421. script.charset = 'utf-8';
  4422. script.onload = script.onreadystatechange = function() {
  4423. if (!this.readyState || this.readyState === 'loaded') {
  4424. if (fn) {
  4425. fn();
  4426. }
  4427. script.onload = script.onreadystatechange = null;
  4428. head.removeChild(script);
  4429. }
  4430. };
  4431. }
  4432. function _chopQuery(url) {
  4433. var index = url.indexOf('?');
  4434. return index > 0 ? url.substr(0, index) : url;
  4435. }
  4436. function _loadStyle(url) {
  4437. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4438. link = document.createElement('link'),
  4439. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4440. var links = K('link[rel="stylesheet"]', head);
  4441. for (var i = 0, len = links.length; i < len; i++) {
  4442. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4443. return;
  4444. }
  4445. }
  4446. head.appendChild(link);
  4447. link.href = url;
  4448. link.rel = 'stylesheet';
  4449. }
  4450. function _ajax(url, fn, method, param, dataType) {
  4451. method = method || 'GET';
  4452. dataType = dataType || 'json';
  4453. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4454. xhr.open(method, url, true);
  4455. xhr.onreadystatechange = function () {
  4456. if (xhr.readyState == 4 && xhr.status == 200) {
  4457. if (fn) {
  4458. var data = _trim(xhr.responseText);
  4459. if (dataType == 'json') {
  4460. data = _json(data);
  4461. }
  4462. fn(data);
  4463. }
  4464. }
  4465. };
  4466. if (method == 'POST') {
  4467. var params = [];
  4468. _each(param, function(key, val) {
  4469. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4470. });
  4471. try {
  4472. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4473. } catch (e) {}
  4474. xhr.send(params.join('&'));
  4475. } else {
  4476. xhr.send(null);
  4477. }
  4478. }
  4479. K.loadScript = _loadScript;
  4480. K.loadStyle = _loadStyle;
  4481. K.ajax = _ajax;
  4482. var _plugins = {};
  4483. function _plugin(name, fn) {
  4484. if (name === undefined) {
  4485. return _plugins;
  4486. }
  4487. if (!fn) {
  4488. return _plugins[name];
  4489. }
  4490. _plugins[name] = fn;
  4491. }
  4492. var _language = {};
  4493. function _parseLangKey(key) {
  4494. var match, ns = 'core';
  4495. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4496. ns = match[1];
  4497. key = match[2];
  4498. }
  4499. return { ns : ns, key : key };
  4500. }
  4501. function _lang(mixed, langType) {
  4502. langType = langType === undefined ? K.options.langType : langType;
  4503. if (typeof mixed === 'string') {
  4504. if (!_language[langType]) {
  4505. return 'no language';
  4506. }
  4507. var pos = mixed.length - 1;
  4508. if (mixed.substr(pos) === '.') {
  4509. return _language[langType][mixed.substr(0, pos)];
  4510. }
  4511. var obj = _parseLangKey(mixed);
  4512. return _language[langType][obj.ns][obj.key];
  4513. }
  4514. _each(mixed, function(key, val) {
  4515. var obj = _parseLangKey(key);
  4516. if (!_language[langType]) {
  4517. _language[langType] = {};
  4518. }
  4519. if (!_language[langType][obj.ns]) {
  4520. _language[langType][obj.ns] = {};
  4521. }
  4522. _language[langType][obj.ns][obj.key] = val;
  4523. });
  4524. }
  4525. function _getImageFromRange(range, fn) {
  4526. if (range.collapsed) {
  4527. return;
  4528. }
  4529. range = range.cloneRange().up();
  4530. var sc = range.startContainer, so = range.startOffset;
  4531. if (!_WEBKIT && !range.isControl()) {
  4532. return;
  4533. }
  4534. var img = K(sc.childNodes[so]);
  4535. if (!img || img.name != 'img') {
  4536. return;
  4537. }
  4538. if (fn(img)) {
  4539. return img;
  4540. }
  4541. }
  4542. function _bindContextmenuEvent() {
  4543. var self = this, doc = self.edit.doc;
  4544. K(doc).contextmenu(function(e) {
  4545. if (self.menu) {
  4546. self.hideMenu();
  4547. }
  4548. if (!self.useContextmenu) {
  4549. e.preventDefault();
  4550. return;
  4551. }
  4552. if (self._contextmenus.length === 0) {
  4553. return;
  4554. }
  4555. var maxWidth = 0, items = [];
  4556. _each(self._contextmenus, function() {
  4557. if (this.title == '-') {
  4558. items.push(this);
  4559. return;
  4560. }
  4561. if (this.cond && this.cond()) {
  4562. items.push(this);
  4563. if (this.width && this.width > maxWidth) {
  4564. maxWidth = this.width;
  4565. }
  4566. }
  4567. });
  4568. while (items.length > 0 && items[0].title == '-') {
  4569. items.shift();
  4570. }
  4571. while (items.length > 0 && items[items.length - 1].title == '-') {
  4572. items.pop();
  4573. }
  4574. var prevItem = null;
  4575. _each(items, function(i) {
  4576. if (this.title == '-' && prevItem.title == '-') {
  4577. delete items[i];
  4578. }
  4579. prevItem = this;
  4580. });
  4581. if (items.length > 0) {
  4582. e.preventDefault();
  4583. var pos = K(self.edit.iframe).pos(),
  4584. menu = _menu({
  4585. x : pos.x + e.clientX,
  4586. y : pos.y + e.clientY,
  4587. width : maxWidth,
  4588. css : { visibility: 'hidden' },
  4589. shadowMode : self.shadowMode
  4590. });
  4591. _each(items, function() {
  4592. if (this.title) {
  4593. menu.addItem(this);
  4594. }
  4595. });
  4596. var docEl = _docElement(menu.doc),
  4597. menuHeight = menu.div.height();
  4598. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4599. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4600. }
  4601. menu.div.css('visibility', 'visible');
  4602. self.menu = menu;
  4603. }
  4604. });
  4605. }
  4606. function _bindNewlineEvent() {
  4607. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4608. if (_IE && newlineTag !== 'br') {
  4609. return;
  4610. }
  4611. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4612. return;
  4613. }
  4614. if (_OPERA && _V < 9) {
  4615. return;
  4616. }
  4617. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4618. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4619. function getAncestorTagName(range) {
  4620. var ancestor = K(range.commonAncestor());
  4621. while (ancestor) {
  4622. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4623. break;
  4624. }
  4625. ancestor = ancestor.parent();
  4626. }
  4627. return ancestor.name;
  4628. }
  4629. K(doc).keydown(function(e) {
  4630. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4631. return;
  4632. }
  4633. self.cmd.selection();
  4634. var tagName = getAncestorTagName(self.cmd.range);
  4635. if (tagName == 'marquee' || tagName == 'select') {
  4636. return;
  4637. }
  4638. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4639. e.preventDefault();
  4640. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4641. return;
  4642. }
  4643. if (!pSkipTagMap[tagName]) {
  4644. _nativeCommand(doc, 'formatblock', '<p>');
  4645. }
  4646. });
  4647. K(doc).keyup(function(e) {
  4648. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4649. return;
  4650. }
  4651. if (newlineTag == 'br') {
  4652. return;
  4653. }
  4654. if (_GECKO) {
  4655. var root = self.cmd.commonAncestor('p');
  4656. var a = self.cmd.commonAncestor('a');
  4657. if (a && a.text() == '') {
  4658. a.remove(true);
  4659. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4660. self.cmd.select();
  4661. }
  4662. return;
  4663. }
  4664. self.cmd.selection();
  4665. var tagName = getAncestorTagName(self.cmd.range);
  4666. if (tagName == 'marquee' || tagName == 'select') {
  4667. return;
  4668. }
  4669. if (!pSkipTagMap[tagName]) {
  4670. _nativeCommand(doc, 'formatblock', '<p>');
  4671. }
  4672. var div = self.cmd.commonAncestor('div');
  4673. if (div) {
  4674. var p = K('<p></p>'),
  4675. child = div[0].firstChild;
  4676. while (child) {
  4677. var next = child.nextSibling;
  4678. p.append(child);
  4679. child = next;
  4680. }
  4681. div.before(p);
  4682. div.remove();
  4683. self.cmd.range.selectNodeContents(p[0]);
  4684. self.cmd.select();
  4685. }
  4686. });
  4687. }
  4688. function _bindTabEvent() {
  4689. var self = this, doc = self.edit.doc;
  4690. K(doc).keydown(function(e) {
  4691. if (e.which == 9) {
  4692. e.preventDefault();
  4693. if (self.afterTab) {
  4694. self.afterTab.call(self, e);
  4695. return;
  4696. }
  4697. var cmd = self.cmd, range = cmd.range;
  4698. range.shrink();
  4699. if (range.collapsed && range.startContainer.nodeType == 1) {
  4700. range.insertNode(K('@&nbsp;', doc)[0]);
  4701. cmd.select();
  4702. }
  4703. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4704. }
  4705. });
  4706. }
  4707. function _bindFocusEvent() {
  4708. var self = this;
  4709. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4710. if (self.afterFocus) {
  4711. self.afterFocus.call(self, e);
  4712. }
  4713. }).blur(function(e) {
  4714. if (self.afterBlur) {
  4715. self.afterBlur.call(self, e);
  4716. }
  4717. });
  4718. }
  4719. function _removeBookmarkTag(html) {
  4720. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4721. }
  4722. function _removeTempTag(html) {
  4723. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4724. }
  4725. function _addBookmarkToStack(stack, bookmark) {
  4726. if (stack.length === 0) {
  4727. stack.push(bookmark);
  4728. return;
  4729. }
  4730. var prev = stack[stack.length - 1];
  4731. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4732. stack.push(bookmark);
  4733. }
  4734. }
  4735. function _undoToRedo(fromStack, toStack) {
  4736. var self = this, edit = self.edit,
  4737. body = edit.doc.body,
  4738. range, bookmark;
  4739. if (fromStack.length === 0) {
  4740. return self;
  4741. }
  4742. if (edit.designMode) {
  4743. range = self.cmd.range;
  4744. bookmark = range.createBookmark(true);
  4745. bookmark.html = body.innerHTML;
  4746. } else {
  4747. bookmark = {
  4748. html : body.innerHTML
  4749. };
  4750. }
  4751. _addBookmarkToStack(toStack, bookmark);
  4752. var prev = fromStack.pop();
  4753. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4754. prev = fromStack.pop();
  4755. }
  4756. if (edit.designMode) {
  4757. edit.html(prev.html);
  4758. if (prev.start) {
  4759. range.moveToBookmark(prev);
  4760. self.select();
  4761. }
  4762. } else {
  4763. K(body).html(_removeBookmarkTag(prev.html));
  4764. }
  4765. return self;
  4766. }
  4767. function KEditor(options) {
  4768. var self = this;
  4769. self.options = {};
  4770. function setOption(key, val) {
  4771. if (KEditor.prototype[key] === undefined) {
  4772. self[key] = val;
  4773. }
  4774. self.options[key] = val;
  4775. }
  4776. _each(options, function(key, val) {
  4777. setOption(key, options[key]);
  4778. });
  4779. _each(K.options, function(key, val) {
  4780. if (self[key] === undefined) {
  4781. setOption(key, val);
  4782. }
  4783. });
  4784. var se = K(self.srcElement || '<textarea/>');
  4785. if (!self.width) {
  4786. self.width = se[0].style.width || se.width();
  4787. }
  4788. if (!self.height) {
  4789. self.height = se[0].style.height || se.height();
  4790. }
  4791. setOption('width', _undef(self.width, self.minWidth));
  4792. setOption('height', _undef(self.height, self.minHeight));
  4793. setOption('width', _addUnit(self.width));
  4794. setOption('height', _addUnit(self.height));
  4795. if (_MOBILE && (!_IOS || _V < 534)) {
  4796. self.designMode = false;
  4797. }
  4798. self.srcElement = se;
  4799. self.initContent = '';
  4800. self.plugin = {};
  4801. self.isCreated = false;
  4802. self._handlers = {};
  4803. self._contextmenus = [];
  4804. self._undoStack = [];
  4805. self._redoStack = [];
  4806. self._firstAddBookmark = true;
  4807. self.menu = self.contextmenu = null;
  4808. self.dialogs = [];
  4809. }
  4810. KEditor.prototype = {
  4811. lang : function(mixed) {
  4812. return _lang(mixed, this.langType);
  4813. },
  4814. loadPlugin : function(name, fn) {
  4815. var self = this;
  4816. if (_plugins[name]) {
  4817. if (!_isFunction(_plugins[name])) {
  4818. setTimeout(function() {
  4819. self.loadPlugin(name, fn);
  4820. }, 100);
  4821. return self;
  4822. }
  4823. _plugins[name].call(self, KindEditor);
  4824. if (fn) {
  4825. fn.call(self);
  4826. }
  4827. return self;
  4828. }
  4829. _plugins[name] = 'loading';
  4830. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4831. setTimeout(function() {
  4832. if (_plugins[name]) {
  4833. self.loadPlugin(name, fn);
  4834. }
  4835. }, 0);
  4836. });
  4837. return self;
  4838. },
  4839. handler : function(key, fn) {
  4840. var self = this;
  4841. if (!self._handlers[key]) {
  4842. self._handlers[key] = [];
  4843. }
  4844. if (_isFunction(fn)) {
  4845. self._handlers[key].push(fn);
  4846. return self;
  4847. }
  4848. _each(self._handlers[key], function() {
  4849. fn = this.call(self, fn);
  4850. });
  4851. return fn;
  4852. },
  4853. clickToolbar : function(name, fn) {
  4854. var self = this, key = 'clickToolbar' + name;
  4855. if (fn === undefined) {
  4856. if (self._handlers[key]) {
  4857. return self.handler(key);
  4858. }
  4859. self.loadPlugin(name, function() {
  4860. self.handler(key);
  4861. });
  4862. return self;
  4863. }
  4864. return self.handler(key, fn);
  4865. },
  4866. updateState : function() {
  4867. var self = this;
  4868. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4869. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4870. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4871. });
  4872. return self;
  4873. },
  4874. addContextmenu : function(item) {
  4875. this._contextmenus.push(item);
  4876. return this;
  4877. },
  4878. afterCreate : function(fn) {
  4879. return this.handler('afterCreate', fn);
  4880. },
  4881. beforeRemove : function(fn) {
  4882. return this.handler('beforeRemove', fn);
  4883. },
  4884. beforeGetHtml : function(fn) {
  4885. return this.handler('beforeGetHtml', fn);
  4886. },
  4887. beforeSetHtml : function(fn) {
  4888. return this.handler('beforeSetHtml', fn);
  4889. },
  4890. afterSetHtml : function(fn) {
  4891. return this.handler('afterSetHtml', fn);
  4892. },
  4893. create : function() {
  4894. var self = this, fullscreenMode = self.fullscreenMode;
  4895. if (self.isCreated) {
  4896. return self;
  4897. }
  4898. if (self.srcElement.data('kindeditor')) {
  4899. return self;
  4900. }
  4901. self.srcElement.data('kindeditor', 'true');
  4902. if (fullscreenMode) {
  4903. _docElement().style.overflow = 'hidden';
  4904. } else {
  4905. _docElement().style.overflow = '';
  4906. }
  4907. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4908. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4909. if ((_IE && _V < 8) || _QUIRKS) {
  4910. height = _addUnit(_removeUnit(height) + 2);
  4911. }
  4912. var container = self.container = K(self.layout);
  4913. if (fullscreenMode) {
  4914. K(document.body).append(container);
  4915. } else {
  4916. self.srcElement.before(container);
  4917. }
  4918. var toolbarDiv = K('.toolbar', container),
  4919. editDiv = K('.edit', container),
  4920. statusbar = self.statusbar = K('.statusbar', container);
  4921. container.removeClass('container')
  4922. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4923. if (fullscreenMode) {
  4924. container.css({
  4925. position : 'absolute',
  4926. left : 0,
  4927. top : 0,
  4928. 'z-index' : 811211
  4929. });
  4930. if (!_GECKO) {
  4931. self._scrollPos = _getScrollPos();
  4932. }
  4933. window.scrollTo(0, 0);
  4934. K(document.body).css({
  4935. 'height' : '1px',
  4936. 'overflow' : 'hidden'
  4937. });
  4938. K(document.body.parentNode).css('overflow', 'hidden');
  4939. self._fullscreenExecuted = true;
  4940. } else {
  4941. if (self._fullscreenExecuted) {
  4942. K(document.body).css({
  4943. 'height' : '',
  4944. 'overflow' : ''
  4945. });
  4946. K(document.body.parentNode).css('overflow', '');
  4947. }
  4948. if (self._scrollPos) {
  4949. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4950. }
  4951. }
  4952. var htmlList = [];
  4953. K.each(self.items, function(i, name) {
  4954. if (name == '|') {
  4955. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4956. } else if (name == '/') {
  4957. htmlList.push('<div class="ke-hr"></div>');
  4958. } else {
  4959. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4960. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4961. }
  4962. });
  4963. var toolbar = self.toolbar = _toolbar({
  4964. src : toolbarDiv,
  4965. html : htmlList.join(''),
  4966. noDisableItems : self.noDisableItems,
  4967. click : function(e, name) {
  4968. e.stop();
  4969. if (self.menu) {
  4970. var menuName = self.menu.name;
  4971. self.hideMenu();
  4972. if (menuName === name) {
  4973. return;
  4974. }
  4975. }
  4976. self.clickToolbar(name);
  4977. }
  4978. });
  4979. var editHeight = _removeUnit(height) - toolbar.div.height();
  4980. var edit = self.edit = _edit({
  4981. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  4982. src : editDiv,
  4983. srcElement : self.srcElement,
  4984. designMode : self.designMode,
  4985. themesPath : self.themesPath,
  4986. bodyClass : self.bodyClass,
  4987. cssPath : self.cssPath,
  4988. cssData : self.cssData,
  4989. beforeGetHtml : function(html) {
  4990. html = self.beforeGetHtml(html);
  4991. html = _removeBookmarkTag(_removeTempTag(html));
  4992. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  4993. },
  4994. beforeSetHtml : function(html) {
  4995. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  4996. return self.beforeSetHtml(html);
  4997. },
  4998. afterSetHtml : function() {
  4999. self.edit = edit = this;
  5000. self.afterSetHtml();
  5001. },
  5002. afterCreate : function() {
  5003. self.edit = edit = this;
  5004. self.cmd = edit.cmd;
  5005. self._docMousedownFn = function(e) {
  5006. if (self.menu) {
  5007. self.hideMenu();
  5008. }
  5009. };
  5010. K(edit.doc, document).mousedown(self._docMousedownFn);
  5011. _bindContextmenuEvent.call(self);
  5012. _bindNewlineEvent.call(self);
  5013. _bindTabEvent.call(self);
  5014. _bindFocusEvent.call(self);
  5015. edit.afterChange(function(e) {
  5016. if (!edit.designMode) {
  5017. return;
  5018. }
  5019. self.updateState();
  5020. self.addBookmark();
  5021. if (self.options.afterChange) {
  5022. self.options.afterChange.call(self);
  5023. }
  5024. });
  5025. edit.textarea.keyup(function(e) {
  5026. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5027. if (self.options.afterChange) {
  5028. self.options.afterChange.call(self);
  5029. }
  5030. }
  5031. });
  5032. if (self.readonlyMode) {
  5033. self.readonly();
  5034. }
  5035. self.isCreated = true;
  5036. if (self.initContent === '') {
  5037. self.initContent = self.html();
  5038. }
  5039. if (self._undoStack.length > 0) {
  5040. var prev = self._undoStack.pop();
  5041. if (prev.start) {
  5042. self.html(prev.html);
  5043. edit.cmd.range.moveToBookmark(prev);
  5044. self.select();
  5045. }
  5046. }
  5047. self.afterCreate();
  5048. if (self.options.afterCreate) {
  5049. self.options.afterCreate.call(self);
  5050. }
  5051. }
  5052. });
  5053. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5054. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5055. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5056. if (self._fullscreenResizeHandler) {
  5057. K(window).unbind('resize', self._fullscreenResizeHandler);
  5058. self._fullscreenResizeHandler = null;
  5059. }
  5060. function initResize() {
  5061. if (statusbar.height() === 0) {
  5062. setTimeout(initResize, 100);
  5063. return;
  5064. }
  5065. self.resize(width, height, false);
  5066. }
  5067. initResize();
  5068. if (fullscreenMode) {
  5069. self._fullscreenResizeHandler = function(e) {
  5070. if (self.isCreated) {
  5071. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5072. }
  5073. };
  5074. K(window).bind('resize', self._fullscreenResizeHandler);
  5075. toolbar.select('fullscreen');
  5076. statusbar.first().css('visibility', 'hidden');
  5077. statusbar.last().css('visibility', 'hidden');
  5078. } else {
  5079. if (_GECKO) {
  5080. K(window).bind('scroll', function(e) {
  5081. self._scrollPos = _getScrollPos();
  5082. });
  5083. }
  5084. if (self.resizeType > 0) {
  5085. _drag({
  5086. moveEl : container,
  5087. clickEl : statusbar,
  5088. moveFn : function(x, y, width, height, diffX, diffY) {
  5089. height += diffY;
  5090. self.resize(null, height);
  5091. }
  5092. });
  5093. } else {
  5094. statusbar.first().css('visibility', 'hidden');
  5095. }
  5096. if (self.resizeType === 2) {
  5097. _drag({
  5098. moveEl : container,
  5099. clickEl : statusbar.last(),
  5100. moveFn : function(x, y, width, height, diffX, diffY) {
  5101. width += diffX;
  5102. height += diffY;
  5103. self.resize(width, height);
  5104. }
  5105. });
  5106. } else {
  5107. statusbar.last().css('visibility', 'hidden');
  5108. }
  5109. }
  5110. return self;
  5111. },
  5112. remove : function() {
  5113. var self = this;
  5114. if (!self.isCreated) {
  5115. return self;
  5116. }
  5117. self.beforeRemove();
  5118. self.srcElement.data('kindeditor', '');
  5119. if (self.menu) {
  5120. self.hideMenu();
  5121. }
  5122. _each(self.dialogs, function() {
  5123. self.hideDialog();
  5124. });
  5125. K(document).unbind('mousedown', self._docMousedownFn);
  5126. self.toolbar.remove();
  5127. self.edit.remove();
  5128. self.statusbar.last().unbind();
  5129. self.statusbar.unbind();
  5130. self.container.remove();
  5131. self.container = self.toolbar = self.edit = self.menu = null;
  5132. self.dialogs = [];
  5133. self.isCreated = false;
  5134. return self;
  5135. },
  5136. resize : function(width, height, updateProp) {
  5137. var self = this;
  5138. updateProp = _undef(updateProp, true);
  5139. if (width) {
  5140. if (!/%/.test(width)) {
  5141. width = _removeUnit(width);
  5142. width = width < self.minWidth ? self.minWidth : width;
  5143. }
  5144. self.container.css('width', _addUnit(width));
  5145. if (updateProp) {
  5146. self.width = _addUnit(width);
  5147. }
  5148. }
  5149. if (height) {
  5150. height = _removeUnit(height);
  5151. editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5152. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5153. self.edit.setHeight(editHeight);
  5154. if (updateProp) {
  5155. self.height = _addUnit(height);
  5156. }
  5157. }
  5158. return self;
  5159. },
  5160. select : function() {
  5161. this.isCreated && this.cmd.select();
  5162. return this;
  5163. },
  5164. html : function(val) {
  5165. var self = this;
  5166. if (val === undefined) {
  5167. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5168. }
  5169. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5170. if (self.isCreated) {
  5171. self.cmd.selection();
  5172. }
  5173. return self;
  5174. },
  5175. fullHtml : function() {
  5176. return this.isCreated ? this.edit.html(undefined, true) : '';
  5177. },
  5178. text : function(val) {
  5179. var self = this;
  5180. if (val === undefined) {
  5181. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5182. } else {
  5183. return self.html(_escape(val));
  5184. }
  5185. },
  5186. isEmpty : function() {
  5187. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5188. },
  5189. isDirty : function() {
  5190. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5191. },
  5192. selectedHtml : function() {
  5193. var val = this.isCreated ? this.cmd.range.html() : '';
  5194. val = _removeBookmarkTag(_removeTempTag(val));
  5195. return val;
  5196. },
  5197. count : function(mode) {
  5198. var self = this;
  5199. mode = (mode || 'html').toLowerCase();
  5200. if (mode === 'html') {
  5201. return self.html().length;
  5202. }
  5203. if (mode === 'text') {
  5204. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5205. }
  5206. return 0;
  5207. },
  5208. exec : function(key) {
  5209. key = key.toLowerCase();
  5210. var self = this, cmd = self.cmd,
  5211. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5212. if (changeFlag) {
  5213. self.addBookmark(false);
  5214. }
  5215. cmd[key].apply(cmd, _toArray(arguments, 1));
  5216. if (changeFlag) {
  5217. self.updateState();
  5218. self.addBookmark(false);
  5219. if (self.options.afterChange) {
  5220. self.options.afterChange.call(self);
  5221. }
  5222. }
  5223. return self;
  5224. },
  5225. insertHtml : function(val, quickMode) {
  5226. if (!this.isCreated) {
  5227. return this;
  5228. }
  5229. val = this.beforeSetHtml(val);
  5230. this.exec('inserthtml', val, quickMode);
  5231. return this;
  5232. },
  5233. appendHtml : function(val) {
  5234. this.html(this.html() + val);
  5235. if (this.isCreated) {
  5236. var cmd = this.cmd;
  5237. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5238. cmd.select();
  5239. }
  5240. return this;
  5241. },
  5242. sync : function() {
  5243. _elementVal(this.srcElement, this.html());
  5244. return this;
  5245. },
  5246. focus : function() {
  5247. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5248. return this;
  5249. },
  5250. blur : function() {
  5251. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5252. return this;
  5253. },
  5254. addBookmark : function(checkSize) {
  5255. checkSize = _undef(checkSize, true);
  5256. var self = this, edit = self.edit,
  5257. body = edit.doc.body,
  5258. html = _removeTempTag(body.innerHTML), bookmark;
  5259. if (checkSize && self._undoStack.length > 0) {
  5260. var prev = self._undoStack[self._undoStack.length - 1];
  5261. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5262. return self;
  5263. }
  5264. }
  5265. if (edit.designMode && !self._firstAddBookmark) {
  5266. var range = self.cmd.range;
  5267. bookmark = range.createBookmark(true);
  5268. bookmark.html = _removeTempTag(body.innerHTML);
  5269. range.moveToBookmark(bookmark);
  5270. } else {
  5271. bookmark = {
  5272. html : html
  5273. };
  5274. }
  5275. self._firstAddBookmark = false;
  5276. _addBookmarkToStack(self._undoStack, bookmark);
  5277. return self;
  5278. },
  5279. undo : function() {
  5280. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5281. },
  5282. redo : function() {
  5283. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5284. },
  5285. fullscreen : function(bool) {
  5286. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5287. this.addBookmark(false);
  5288. return this.remove().create();
  5289. },
  5290. readonly : function(isReadonly) {
  5291. isReadonly = _undef(isReadonly, true);
  5292. var self = this, edit = self.edit, doc = edit.doc;
  5293. if (self.designMode) {
  5294. self.toolbar.disableAll(isReadonly, []);
  5295. } else {
  5296. _each(self.noDisableItems, function() {
  5297. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5298. });
  5299. }
  5300. if (_IE) {
  5301. doc.body.contentEditable = !isReadonly;
  5302. } else {
  5303. doc.designMode = isReadonly ? 'off' : 'on';
  5304. }
  5305. edit.textarea[0].disabled = isReadonly;
  5306. },
  5307. createMenu : function(options) {
  5308. var self = this,
  5309. name = options.name,
  5310. knode = self.toolbar.get(name),
  5311. pos = knode.pos();
  5312. options.x = pos.x;
  5313. options.y = pos.y + knode.height();
  5314. options.z = self.options.zIndex;
  5315. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5316. if (options.selectedColor !== undefined) {
  5317. options.cls = 'ke-colorpicker-' + self.themeType;
  5318. options.noColor = self.lang('noColor');
  5319. self.menu = _colorpicker(options);
  5320. } else {
  5321. options.cls = 'ke-menu-' + self.themeType;
  5322. options.centerLineMode = false;
  5323. self.menu = _menu(options);
  5324. }
  5325. return self.menu;
  5326. },
  5327. hideMenu : function() {
  5328. this.menu.remove();
  5329. this.menu = null;
  5330. return this;
  5331. },
  5332. hideContextmenu : function() {
  5333. this.contextmenu.remove();
  5334. this.contextmenu = null;
  5335. return this;
  5336. },
  5337. createDialog : function(options) {
  5338. var self = this, name = options.name;
  5339. options.z = self.options.zIndex;
  5340. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5341. options.closeBtn = _undef(options.closeBtn, {
  5342. name : self.lang('close'),
  5343. click : function(e) {
  5344. self.hideDialog();
  5345. if (_IE && self.cmd) {
  5346. self.cmd.select();
  5347. }
  5348. }
  5349. });
  5350. options.noBtn = _undef(options.noBtn, {
  5351. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5352. click : function(e) {
  5353. self.hideDialog();
  5354. if (_IE && self.cmd) {
  5355. self.cmd.select();
  5356. }
  5357. }
  5358. });
  5359. if (self.dialogAlignType != 'page') {
  5360. options.alignEl = self.container;
  5361. }
  5362. options.cls = 'ke-dialog-' + self.themeType;
  5363. if (self.dialogs.length > 0) {
  5364. var firstDialog = self.dialogs[0],
  5365. parentDialog = self.dialogs[self.dialogs.length - 1];
  5366. firstDialog.setMaskIndex(parentDialog.z + 2);
  5367. options.z = parentDialog.z + 3;
  5368. options.showMask = false;
  5369. }
  5370. var dialog = _dialog(options);
  5371. self.dialogs.push(dialog);
  5372. return dialog;
  5373. },
  5374. hideDialog : function() {
  5375. var self = this;
  5376. if (self.dialogs.length > 0) {
  5377. self.dialogs.pop().remove();
  5378. }
  5379. if (self.dialogs.length > 0) {
  5380. var firstDialog = self.dialogs[0],
  5381. parentDialog = self.dialogs[self.dialogs.length - 1];
  5382. firstDialog.setMaskIndex(parentDialog.z - 1);
  5383. }
  5384. return self;
  5385. },
  5386. errorDialog : function(html) {
  5387. var self = this;
  5388. var dialog = self.createDialog({
  5389. width : 750,
  5390. title : self.lang('uploadError'),
  5391. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5392. });
  5393. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5394. doc.open();
  5395. doc.write(html);
  5396. doc.close();
  5397. K(doc.body).css('background-color', '#FFF');
  5398. iframe[0].contentWindow.focus();
  5399. return self;
  5400. }
  5401. };
  5402. function _editor(options) {
  5403. return new KEditor(options);
  5404. }
  5405. _instances = [];
  5406. function _create(expr, options) {
  5407. options = options || {};
  5408. options.basePath = _undef(options.basePath, K.basePath);
  5409. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5410. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5411. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5412. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5413. var themeType = _undef(options.themeType, K.options.themeType);
  5414. _loadStyle(options.themesPath + 'default/default.css');
  5415. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5416. }
  5417. function create(editor) {
  5418. _each(_plugins, function(name, fn) {
  5419. if (_isFunction(fn)) {
  5420. fn.call(editor, KindEditor);
  5421. }
  5422. });
  5423. return editor.create();
  5424. }
  5425. var knode = K(expr);
  5426. if (!knode || knode.length === 0) {
  5427. return;
  5428. }
  5429. if (knode.length > 1) {
  5430. knode.each(function() {
  5431. _create(this, options);
  5432. });
  5433. return _instances[0];
  5434. }
  5435. options.srcElement = knode[0];
  5436. var editor = new KEditor(options);
  5437. _instances.push(editor);
  5438. if (_language[editor.langType]) {
  5439. return create(editor);
  5440. }
  5441. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5442. create(editor);
  5443. });
  5444. return editor;
  5445. }
  5446. function _eachEditor(expr, fn) {
  5447. K(expr).each(function(i, el) {
  5448. K.each(_instances, function(j, editor) {
  5449. if (editor && editor.srcElement[0] == el) {
  5450. fn.call(editor, j);
  5451. return false;
  5452. }
  5453. });
  5454. });
  5455. }
  5456. K.remove = function(expr) {
  5457. _eachEditor(expr, function(i) {
  5458. this.remove();
  5459. _instances.splice(i, 1);
  5460. });
  5461. };
  5462. K.sync = function(expr) {
  5463. _eachEditor(expr, function() {
  5464. this.sync();
  5465. });
  5466. };
  5467. K.html = function(expr, val) {
  5468. _eachEditor(expr, function() {
  5469. this.html(val);
  5470. });
  5471. };
  5472. K.insertHtml = function(expr, val) {
  5473. _eachEditor(expr, function() {
  5474. this.insertHtml(val);
  5475. });
  5476. };
  5477. K.appendHtml = function(expr, val) {
  5478. _eachEditor(expr, function() {
  5479. this.appendHtml(val);
  5480. });
  5481. };
  5482. if (_IE && _V < 7) {
  5483. _nativeCommand(document, 'BackgroundImageCache', true);
  5484. }
  5485. K.EditorClass = KEditor;
  5486. K.editor = _editor;
  5487. K.create = _create;
  5488. K.instances = _instances;
  5489. K.plugin = _plugin;
  5490. K.lang = _lang;
  5491. _plugin('core', function(K) {
  5492. var self = this,
  5493. shortcutKeys = {
  5494. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5495. };
  5496. self.afterSetHtml(function() {
  5497. if (self.options.afterChange) {
  5498. self.options.afterChange.call(self);
  5499. }
  5500. });
  5501. self.afterCreate(function() {
  5502. if (self.syncType != 'form') {
  5503. return;
  5504. }
  5505. var el = K(self.srcElement), hasForm = false;
  5506. while ((el = el.parent())) {
  5507. if (el.name == 'form') {
  5508. hasForm = true;
  5509. break;
  5510. }
  5511. }
  5512. if (hasForm) {
  5513. el.bind('submit', function(e) {
  5514. self.sync();
  5515. K(window).bind('unload', function() {
  5516. self.edit.textarea.remove();
  5517. });
  5518. });
  5519. var resetBtn = K('[type="reset"]', el);
  5520. resetBtn.click(function() {
  5521. self.html(self.initContent);
  5522. self.cmd.selection();
  5523. });
  5524. self.beforeRemove(function() {
  5525. el.unbind();
  5526. resetBtn.unbind();
  5527. });
  5528. }
  5529. });
  5530. self.clickToolbar('source', function() {
  5531. if (self.edit.designMode) {
  5532. self.toolbar.disableAll(true);
  5533. self.edit.design(false);
  5534. self.toolbar.select('source');
  5535. } else {
  5536. self.toolbar.disableAll(false);
  5537. self.edit.design(true);
  5538. self.toolbar.unselect('source');
  5539. if (_GECKO) {
  5540. setTimeout(function() {
  5541. self.cmd.selection();
  5542. }, 0);
  5543. } else {
  5544. self.cmd.selection();
  5545. }
  5546. }
  5547. self.designMode = self.edit.designMode;
  5548. });
  5549. self.afterCreate(function() {
  5550. if (!self.designMode) {
  5551. self.toolbar.disableAll(true).select('source');
  5552. }
  5553. });
  5554. self.clickToolbar('fullscreen', function() {
  5555. self.fullscreen();
  5556. });
  5557. if (self.fullscreenShortcut) {
  5558. var loaded = false;
  5559. self.afterCreate(function() {
  5560. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5561. if (e.which == 27) {
  5562. setTimeout(function() {
  5563. self.fullscreen();
  5564. }, 0);
  5565. }
  5566. });
  5567. if (loaded) {
  5568. if (_IE && !self.designMode) {
  5569. return;
  5570. }
  5571. self.focus();
  5572. }
  5573. if (!loaded) {
  5574. loaded = true;
  5575. }
  5576. });
  5577. }
  5578. _each('undo,redo'.split(','), function(i, name) {
  5579. if (shortcutKeys[name]) {
  5580. self.afterCreate(function() {
  5581. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5582. self.clickToolbar(name);
  5583. });
  5584. });
  5585. }
  5586. self.clickToolbar(name, function() {
  5587. self[name]();
  5588. });
  5589. });
  5590. self.clickToolbar('formatblock', function() {
  5591. var blocks = self.lang('formatblock.formatBlock'),
  5592. heights = {
  5593. h1 : 28,
  5594. h2 : 24,
  5595. h3 : 18,
  5596. H4 : 14,
  5597. p : 12
  5598. },
  5599. curVal = self.cmd.val('formatblock'),
  5600. menu = self.createMenu({
  5601. name : 'formatblock',
  5602. width : self.langType == 'en' ? 200 : 150
  5603. });
  5604. _each(blocks, function(key, val) {
  5605. var style = 'font-size:' + heights[key] + 'px;';
  5606. if (key.charAt(0) === 'h') {
  5607. style += 'font-weight:bold;';
  5608. }
  5609. menu.addItem({
  5610. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5611. height : heights[key] + 12,
  5612. checked : (curVal === key || curVal === val),
  5613. click : function() {
  5614. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5615. }
  5616. });
  5617. });
  5618. });
  5619. self.clickToolbar('fontname', function() {
  5620. var curVal = self.cmd.val('fontname'),
  5621. menu = self.createMenu({
  5622. name : 'fontname',
  5623. width : 150
  5624. });
  5625. _each(self.lang('fontname.fontName'), function(key, val) {
  5626. menu.addItem({
  5627. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5628. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5629. click : function() {
  5630. self.exec('fontname', key).hideMenu();
  5631. }
  5632. });
  5633. });
  5634. });
  5635. self.clickToolbar('fontsize', function() {
  5636. var curVal = self.cmd.val('fontsize'),
  5637. menu = self.createMenu({
  5638. name : 'fontsize',
  5639. width : 150
  5640. });
  5641. _each(self.fontSizeTable, function(i, val) {
  5642. menu.addItem({
  5643. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5644. height : _removeUnit(val) + 12,
  5645. checked : curVal === val,
  5646. click : function() {
  5647. self.exec('fontsize', val).hideMenu();
  5648. }
  5649. });
  5650. });
  5651. });
  5652. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5653. self.clickToolbar(name, function() {
  5654. self.createMenu({
  5655. name : name,
  5656. selectedColor : self.cmd.val(name) || 'default',
  5657. colors : self.colorTable,
  5658. click : function(color) {
  5659. self.exec(name, color).hideMenu();
  5660. }
  5661. });
  5662. });
  5663. });
  5664. _each(('cut,copy,paste').split(','), function(i, name) {
  5665. self.clickToolbar(name, function() {
  5666. self.focus();
  5667. try {
  5668. self.exec(name, null);
  5669. } catch(e) {
  5670. alert(self.lang(name + 'Error'));
  5671. }
  5672. });
  5673. });
  5674. self.clickToolbar('about', function() {
  5675. var html = '<div style="margin:20px;">' +
  5676. '<div>KindEditor ' + _VERSION + '</div>' +
  5677. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5678. '</div>';
  5679. self.createDialog({
  5680. name : 'about',
  5681. width : 350,
  5682. title : self.lang('about'),
  5683. body : html
  5684. });
  5685. });
  5686. self.plugin.getSelectedLink = function() {
  5687. return self.cmd.commonAncestor('a');
  5688. };
  5689. self.plugin.getSelectedImage = function() {
  5690. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5691. return !/^ke-\w+$/i.test(img[0].className);
  5692. });
  5693. };
  5694. self.plugin.getSelectedFlash = function() {
  5695. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5696. return img[0].className == 'ke-flash';
  5697. });
  5698. };
  5699. self.plugin.getSelectedMedia = function() {
  5700. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5701. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5702. });
  5703. };
  5704. self.plugin.getSelectedAnchor = function() {
  5705. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5706. return img[0].className == 'ke-anchor';
  5707. });
  5708. };
  5709. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5710. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5711. _each('edit,delete'.split(','), function(j, val) {
  5712. self.addContextmenu({
  5713. title : self.lang(val + uName),
  5714. click : function() {
  5715. self.loadPlugin(name, function() {
  5716. self.plugin[name][val]();
  5717. self.hideMenu();
  5718. });
  5719. },
  5720. cond : self.plugin['getSelected' + uName],
  5721. width : 150,
  5722. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5723. });
  5724. });
  5725. self.addContextmenu({ title : '-' });
  5726. });
  5727. self.plugin.getSelectedTable = function() {
  5728. return self.cmd.commonAncestor('table');
  5729. };
  5730. self.plugin.getSelectedRow = function() {
  5731. return self.cmd.commonAncestor('tr');
  5732. };
  5733. self.plugin.getSelectedCell = function() {
  5734. return self.cmd.commonAncestor('td');
  5735. };
  5736. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5737. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5738. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5739. self.addContextmenu({
  5740. title : self.lang('table' + val),
  5741. click : function() {
  5742. self.loadPlugin('table', function() {
  5743. self.plugin.table[val]();
  5744. self.hideMenu();
  5745. });
  5746. },
  5747. cond : cond,
  5748. width : 170,
  5749. iconClass : 'ke-icon-table' + val
  5750. });
  5751. });
  5752. self.addContextmenu({ title : '-' });
  5753. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5754. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5755. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5756. if (shortcutKeys[name]) {
  5757. self.afterCreate(function() {
  5758. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5759. self.cmd.selection();
  5760. self.clickToolbar(name);
  5761. });
  5762. });
  5763. }
  5764. self.clickToolbar(name, function() {
  5765. self.focus().exec(name, null);
  5766. });
  5767. });
  5768. self.afterCreate(function() {
  5769. var doc = self.edit.doc, cmd, bookmark, div,
  5770. cls = '__kindeditor_paste__', pasting = false;
  5771. function movePastedData() {
  5772. cmd.range.moveToBookmark(bookmark);
  5773. cmd.select();
  5774. if (_WEBKIT) {
  5775. K('div.' + cls, div).each(function() {
  5776. K(this).after('<br />').remove(true);
  5777. });
  5778. K('span.Apple-style-span', div).remove(true);
  5779. K('span.Apple-tab-span', div).remove(true);
  5780. K('span[style]', div).each(function() {
  5781. if (K(this).css('white-space') == 'nowrap') {
  5782. K(this).remove(true);
  5783. }
  5784. });
  5785. K('meta', div).remove();
  5786. }
  5787. var html = div[0].innerHTML;
  5788. div.remove();
  5789. if (html === '') {
  5790. return;
  5791. }
  5792. if (_WEBKIT) {
  5793. html = html.replace(/(<br>)\1/ig, '$1');
  5794. }
  5795. if (self.pasteType === 2) {
  5796. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5797. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5798. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5799. } else {
  5800. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5801. html = self.beforeSetHtml(html);
  5802. }
  5803. }
  5804. if (self.pasteType === 1) {
  5805. html = html.replace(/&nbsp;/ig, ' ');
  5806. html = html.replace(/\n\s*\n/g, '\n');
  5807. html = html.replace(/<br[^>]*>/ig, '\n');
  5808. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5809. html = html.replace(/<[^>]+>/g, '');
  5810. html = html.replace(/ {2}/g, ' &nbsp;');
  5811. if (self.newlineTag == 'p') {
  5812. if (/\n/.test(html)) {
  5813. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5814. }
  5815. } else {
  5816. html = html.replace(/\n/g, '<br />$&');
  5817. }
  5818. }
  5819. self.insertHtml(html, true);
  5820. }
  5821. K(doc.body).bind('paste', function(e){
  5822. if (self.pasteType === 0) {
  5823. e.stop();
  5824. return;
  5825. }
  5826. if (pasting) {
  5827. return;
  5828. }
  5829. pasting = true;
  5830. K('div.' + cls, doc).remove();
  5831. cmd = self.cmd.selection();
  5832. bookmark = cmd.range.createBookmark();
  5833. div = K('<div class="' + cls + '"></div>', doc).css({
  5834. position : 'absolute',
  5835. width : '1px',
  5836. height : '1px',
  5837. overflow : 'hidden',
  5838. left : '-1981px',
  5839. top : K(bookmark.start).pos().y + 'px',
  5840. 'white-space' : 'nowrap'
  5841. });
  5842. K(doc.body).append(div);
  5843. if (_IE) {
  5844. var rng = cmd.range.get(true);
  5845. rng.moveToElementText(div[0]);
  5846. rng.select();
  5847. rng.execCommand('paste');
  5848. e.preventDefault();
  5849. } else {
  5850. cmd.range.selectNodeContents(div[0]);
  5851. cmd.select();
  5852. }
  5853. setTimeout(function() {
  5854. movePastedData();
  5855. pasting = false;
  5856. }, 0);
  5857. });
  5858. });
  5859. self.beforeGetHtml(function(html) {
  5860. if (_IE && _V <= 8) {
  5861. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5862. return unescape(tag);
  5863. });
  5864. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5865. if (!/\s+type="[^"]+"/i.test($0)) {
  5866. return $1 + ' type="text"' + $2;
  5867. }
  5868. return $0;
  5869. });
  5870. }
  5871. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5872. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5873. })
  5874. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5875. var imgAttrs = _getAttrList(full);
  5876. var styles = _getCssList(imgAttrs.style || '');
  5877. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5878. var width = _undef(styles.width, '');
  5879. var height = _undef(styles.height, '');
  5880. if (/px/i.test(width)) {
  5881. width = _removeUnit(width);
  5882. }
  5883. if (/px/i.test(height)) {
  5884. height = _removeUnit(height);
  5885. }
  5886. attrs.width = _undef(imgAttrs.width, width);
  5887. attrs.height = _undef(imgAttrs.height, height);
  5888. return _mediaEmbed(attrs);
  5889. })
  5890. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  5891. var imgAttrs = _getAttrList(full);
  5892. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5893. })
  5894. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5895. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5896. })
  5897. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5898. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5899. })
  5900. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  5901. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  5902. return $1 + _unescape(src) + $2;
  5903. });
  5904. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5905. return full;
  5906. })
  5907. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5908. return start + end;
  5909. });
  5910. });
  5911. self.beforeSetHtml(function(html) {
  5912. if (_IE && _V <= 8) {
  5913. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  5914. var attrs = _getAttrList(full);
  5915. var styles = _getCssList(attrs.style || '');
  5916. if (styles.display == 'none') {
  5917. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5918. }
  5919. return full;
  5920. });
  5921. }
  5922. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  5923. var attrs = _getAttrList(full);
  5924. attrs.src = _undef(attrs.src, '');
  5925. attrs.width = _undef(attrs.width, 0);
  5926. attrs.height = _undef(attrs.height, 0);
  5927. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5928. })
  5929. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  5930. var attrs = _getAttrList(full);
  5931. if (attrs.href !== undefined) {
  5932. return full;
  5933. }
  5934. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5935. })
  5936. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  5937. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5938. })
  5939. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  5940. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5941. })
  5942. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  5943. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5944. return full;
  5945. }
  5946. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5947. return full;
  5948. })
  5949. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5950. return start + 'data-ke-' + end;
  5951. })
  5952. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  5953. if (full.indexOf('ke-zeroborder') >= 0) {
  5954. return full;
  5955. }
  5956. return _addClassToTag(full, 'ke-zeroborder');
  5957. });
  5958. });
  5959. });
  5960. })(window);
  5961. /*******************************************************************************
  5962. * KindEditor - WYSIWYG HTML Editor for Internet
  5963. * Copyright (C) 2006-2011 kindsoft.net
  5964. *
  5965. * @author Roddy <luolonghao@gmail.com>
  5966. * @site http://www.kindsoft.net/
  5967. * @licence http://www.kindsoft.net/license.php
  5968. *******************************************************************************/
  5969. KindEditor.lang({
  5970. source : 'HTML代码',
  5971. preview : '预览',
  5972. undo : '后退(Ctrl+Z)',
  5973. redo : '前进(Ctrl+Y)',
  5974. cut : '剪切(Ctrl+X)',
  5975. copy : '复制(Ctrl+C)',
  5976. paste : '粘贴(Ctrl+V)',
  5977. plainpaste : '粘贴为无格式文本',
  5978. wordpaste : '从Word粘贴',
  5979. selectall : '全选(Ctrl+A)',
  5980. justifyleft : '左对齐',
  5981. justifycenter : '居中',
  5982. justifyright : '右对齐',
  5983. justifyfull : '两端对齐',
  5984. insertorderedlist : '编号',
  5985. insertunorderedlist : '项目符号',
  5986. indent : '增加缩进',
  5987. outdent : '减少缩进',
  5988. subscript : '下标',
  5989. superscript : '上标',
  5990. formatblock : '段落',
  5991. fontname : '字体',
  5992. fontsize : '文字大小',
  5993. forecolor : '文字颜色',
  5994. hilitecolor : '文字背景',
  5995. bold : '粗体(Ctrl+B)',
  5996. italic : '斜体(Ctrl+I)',
  5997. underline : '下划线(Ctrl+U)',
  5998. strikethrough : '删除线',
  5999. removeformat : '删除格式',
  6000. image : '图片',
  6001. multiimage : '批量图片上传',
  6002. flash : 'Flash',
  6003. media : '视音频',
  6004. table : '表格',
  6005. tablecell : '单元格',
  6006. hr : '插入横线',
  6007. emoticons : '插入表情',
  6008. link : '超级链接',
  6009. unlink : '取消超级链接',
  6010. fullscreen : '全屏显示',
  6011. about : '关于',
  6012. print : '打印(Ctrl+P)',
  6013. filemanager : '文件空间',
  6014. code : '插入程序代码',
  6015. map : 'Google地图',
  6016. baidumap : '百度地图',
  6017. lineheight : '行距',
  6018. clearhtml : '清理HTML代码',
  6019. pagebreak : '插入分页符',
  6020. quickformat : '一键排版',
  6021. insertfile : '插入文件',
  6022. template : '插入模板',
  6023. anchor : '锚点',
  6024. yes : '确定',
  6025. no : '取消',
  6026. close : '关闭',
  6027. editImage : '图片属性',
  6028. deleteImage : '删除图片',
  6029. editFlash : 'Flash属性',
  6030. deleteFlash : '删除Flash',
  6031. editMedia : '视音频属性',
  6032. deleteMedia : '删除视音频',
  6033. editLink : '超级链接属性',
  6034. deleteLink : '取消超级链接',
  6035. editAnchor : '锚点属性',
  6036. deleteAnchor : '删除锚点',
  6037. tableprop : '表格属性',
  6038. tablecellprop : '单元格属性',
  6039. tableinsert : '插入表格',
  6040. tabledelete : '删除表格',
  6041. tablecolinsertleft : '左侧插入列',
  6042. tablecolinsertright : '右侧插入列',
  6043. tablerowinsertabove : '上方插入行',
  6044. tablerowinsertbelow : '下方插入行',
  6045. tablerowmerge : '向下合并单元格',
  6046. tablecolmerge : '向右合并单元格',
  6047. tablerowsplit : '拆分行',
  6048. tablecolsplit : '拆分列',
  6049. tablecoldelete : '删除列',
  6050. tablerowdelete : '删除行',
  6051. noColor : '无颜色',
  6052. pleaseSelectFile : '请选择文件。',
  6053. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6054. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6055. invalidWidth : "宽度必须为数字。",
  6056. invalidHeight : "高度必须为数字。",
  6057. invalidBorder : "边框必须为数字。",
  6058. invalidUrl : "请输入有效的URL地址。",
  6059. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6060. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6061. invalidPadding : '边距必须为数字。',
  6062. invalidSpacing : '间距必须为数字。',
  6063. invalidJson : '服务器发生故障。',
  6064. uploadSuccess : '上传成功。',
  6065. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6066. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6067. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6068. ajaxLoading : '加载中,请稍候 ...',
  6069. uploadLoading : '上传中,请稍候 ...',
  6070. uploadError : '上传错误',
  6071. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6072. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6073. 'code.pleaseInput' : '请输入程序代码。',
  6074. 'link.url' : 'URL',
  6075. 'link.linkType' : '打开类型',
  6076. 'link.newWindow' : '新窗口',
  6077. 'link.selfWindow' : '当前窗口',
  6078. 'flash.url' : 'URL',
  6079. 'flash.width' : '宽度',
  6080. 'flash.height' : '高度',
  6081. 'flash.upload' : '上传',
  6082. 'flash.viewServer' : '文件空间',
  6083. 'media.url' : 'URL',
  6084. 'media.width' : '宽度',
  6085. 'media.height' : '高度',
  6086. 'media.autostart' : '自动播放',
  6087. 'media.upload' : '上传',
  6088. 'media.viewServer' : '文件空间',
  6089. 'image.remoteImage' : '网络图片',
  6090. 'image.localImage' : '本地上传',
  6091. 'image.remoteUrl' : '图片地址',
  6092. 'image.localUrl' : '上传文件',
  6093. 'image.size' : '图片大小',
  6094. 'image.width' : '宽',
  6095. 'image.height' : '高',
  6096. 'image.resetSize' : '重置大小',
  6097. 'image.align' : '对齐方式',
  6098. 'image.defaultAlign' : '默认方式',
  6099. 'image.leftAlign' : '左对齐',
  6100. 'image.rightAlign' : '右对齐',
  6101. 'image.imgTitle' : '图片说明',
  6102. 'image.upload' : '浏览...',
  6103. 'image.viewServer' : '图片空间',
  6104. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6105. 'multiimage.startUpload' : '开始上传',
  6106. 'multiimage.clearAll' : '全部清空',
  6107. 'multiimage.insertAll' : '全部插入',
  6108. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6109. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6110. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6111. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6112. 'multiimage.unknownError' : '发生异常,无法上传。',
  6113. 'multiimage.pending' : '等待上传',
  6114. 'multiimage.uploadError' : '上传失败',
  6115. 'filemanager.emptyFolder' : '空文件夹',
  6116. 'filemanager.moveup' : '移到上一级文件夹',
  6117. 'filemanager.viewType' : '显示方式:',
  6118. 'filemanager.viewImage' : '缩略图',
  6119. 'filemanager.listImage' : '详细信息',
  6120. 'filemanager.orderType' : '排序方式:',
  6121. 'filemanager.fileName' : '名称',
  6122. 'filemanager.fileSize' : '大小',
  6123. 'filemanager.fileType' : '类型',
  6124. 'insertfile.url' : 'URL',
  6125. 'insertfile.title' : '文件说明',
  6126. 'insertfile.upload' : '上传',
  6127. 'insertfile.viewServer' : '文件空间',
  6128. 'table.cells' : '单元格数',
  6129. 'table.rows' : '行数',
  6130. 'table.cols' : '列数',
  6131. 'table.size' : '大小',
  6132. 'table.width' : '宽度',
  6133. 'table.height' : '高度',
  6134. 'table.percent' : '%',
  6135. 'table.px' : 'px',
  6136. 'table.space' : '边距间距',
  6137. 'table.padding' : '边距',
  6138. 'table.spacing' : '间距',
  6139. 'table.align' : '对齐方式',
  6140. 'table.textAlign' : '水平对齐',
  6141. 'table.verticalAlign' : '垂直对齐',
  6142. 'table.alignDefault' : '默认',
  6143. 'table.alignLeft' : '左对齐',
  6144. 'table.alignCenter' : '居中',
  6145. 'table.alignRight' : '右对齐',
  6146. 'table.alignTop' : '顶部',
  6147. 'table.alignMiddle' : '中部',
  6148. 'table.alignBottom' : '底部',
  6149. 'table.alignBaseline' : '基线',
  6150. 'table.border' : '边框',
  6151. 'table.borderWidth' : '边框',
  6152. 'table.borderColor' : '颜色',
  6153. 'table.backgroundColor' : '背景颜色',
  6154. 'map.address' : '地址: ',
  6155. 'map.search' : '搜索',
  6156. 'baidumap.address' : '地址: ',
  6157. 'baidumap.search' : '搜索',
  6158. 'baidumap.insertDynamicMap' : '插入动态地图',
  6159. 'anchor.name' : '锚点名称',
  6160. 'formatblock.formatBlock' : {
  6161. h1 : '标题 1',
  6162. h2 : '标题 2',
  6163. h3 : '标题 3',
  6164. h4 : '标题 4',
  6165. p : '正 文'
  6166. },
  6167. 'fontname.fontName' : {
  6168. 'SimSun' : '宋体',
  6169. 'NSimSun' : '新宋体',
  6170. 'FangSong_GB2312' : '仿宋_GB2312',
  6171. 'KaiTi_GB2312' : '楷体_GB2312',
  6172. 'SimHei' : '黑体',
  6173. 'Microsoft YaHei' : '微软雅黑',
  6174. 'Arial' : 'Arial',
  6175. 'Arial Black' : 'Arial Black',
  6176. 'Times New Roman' : 'Times New Roman',
  6177. 'Courier New' : 'Courier New',
  6178. 'Tahoma' : 'Tahoma',
  6179. 'Verdana' : 'Verdana'
  6180. },
  6181. 'lineheight.lineHeight' : [
  6182. {'1' : '单倍行距'},
  6183. {'1.5' : '1.5倍行距'},
  6184. {'2' : '2倍行距'},
  6185. {'2.5' : '2.5倍行距'},
  6186. {'3' : '3倍行距'}
  6187. ],
  6188. 'template.selectTemplate' : '可选模板',
  6189. 'template.replaceContent' : '替换当前内容',
  6190. 'template.fileList' : {
  6191. '1.html' : '图片和文字',
  6192. '2.html' : '表格',
  6193. '3.html' : '项目编号'
  6194. }
  6195. }, 'zh_CN');
  6196. /*******************************************************************************
  6197. * KindEditor - WYSIWYG HTML Editor for Internet
  6198. * Copyright (C) 2006-2011 kindsoft.net
  6199. *
  6200. * @author Roddy <luolonghao@gmail.com>
  6201. * @site http://www.kindsoft.net/
  6202. * @licence http://www.kindsoft.net/license.php
  6203. *******************************************************************************/
  6204. KindEditor.plugin('anchor', function(K) {
  6205. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6206. self.plugin.anchor = {
  6207. edit : function() {
  6208. var html = ['<div style="padding:20px;">',
  6209. '<div class="ke-dialog-row">',
  6210. '<label for="keName">' + lang.name + '</label>',
  6211. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6212. '</div>',
  6213. '</div>'].join('');
  6214. var dialog = self.createDialog({
  6215. name : name,
  6216. width : 300,
  6217. title : self.lang(name),
  6218. body : html,
  6219. yesBtn : {
  6220. name : self.lang('yes'),
  6221. click : function(e) {
  6222. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6223. }
  6224. }
  6225. });
  6226. var div = dialog.div,
  6227. nameBox = K('input[name="name"]', div);
  6228. var img = self.plugin.getSelectedAnchor();
  6229. if (img) {
  6230. nameBox.val(unescape(img.attr('data-ke-name')));
  6231. }
  6232. nameBox[0].focus();
  6233. nameBox[0].select();
  6234. },
  6235. 'delete' : function() {
  6236. self.plugin.getSelectedAnchor().remove();
  6237. }
  6238. };
  6239. self.clickToolbar(name, self.plugin.anchor.edit);
  6240. });
  6241. /*******************************************************************************
  6242. * KindEditor - WYSIWYG HTML Editor for Internet
  6243. * Copyright (C) 2006-2011 kindsoft.net
  6244. *
  6245. * @author Roddy <luolonghao@gmail.com>
  6246. * @site http://www.kindsoft.net/
  6247. * @licence http://www.kindsoft.net/license.php
  6248. *******************************************************************************/
  6249. KindEditor.plugin('autoheight', function(K) {
  6250. var self = this;
  6251. if (!self.autoHeightMode) {
  6252. return;
  6253. }
  6254. var minHeight;
  6255. function hideScroll() {
  6256. var edit = self.edit;
  6257. var body = edit.doc.body;
  6258. edit.iframe[0].scroll = 'no';
  6259. body.style.overflowY = 'hidden';
  6260. }
  6261. function resetHeight() {
  6262. var edit = self.edit;
  6263. var body = edit.doc.body;
  6264. edit.iframe.height(minHeight);
  6265. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6266. }
  6267. function init() {
  6268. minHeight = K.removeUnit(self.height);
  6269. self.edit.afterChange(resetHeight);
  6270. hideScroll();
  6271. resetHeight();
  6272. }
  6273. if (self.isCreated) {
  6274. init();
  6275. } else {
  6276. self.afterCreate(init);
  6277. }
  6278. });
  6279. /*
  6280. * 如何实现真正的自动高度?
  6281. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6282. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6283. * 由此就实现了真正的自动高度
  6284. * 测试:chrome、firefox、IE9、IE8
  6285. * */
  6286. /*******************************************************************************
  6287. * KindEditor - WYSIWYG HTML Editor for Internet
  6288. * Copyright (C) 2006-2011 kindsoft.net
  6289. *
  6290. * @author Roddy <luolonghao@gmail.com>
  6291. * @site http://www.kindsoft.net/
  6292. * @licence http://www.kindsoft.net/license.php
  6293. *******************************************************************************/
  6294. // Baidu Maps: http://dev.baidu.com/wiki/map/index.php?title=%E9%A6%96%E9%A1%B5
  6295. KindEditor.plugin('baidumap', function(K) {
  6296. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6297. var mapWidth = K.undef(self.mapWidth, 558);
  6298. var mapHeight = K.undef(self.mapHeight, 360);
  6299. self.clickToolbar(name, function() {
  6300. var html = ['<div style="padding:10px 20px;">',
  6301. '<div class="ke-header">',
  6302. // left start
  6303. '<div class="ke-left">',
  6304. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6305. '<span class="ke-button-common ke-button-outer">',
  6306. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6307. '</span>',
  6308. '</div>',
  6309. // right start
  6310. '<div class="ke-right">',
  6311. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6312. '</div>',
  6313. '<div class="ke-clearfix"></div>',
  6314. '</div>',
  6315. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6316. '</div>'].join('');
  6317. var dialog = self.createDialog({
  6318. name : name,
  6319. width : mapWidth + 42,
  6320. title : self.lang(name),
  6321. body : html,
  6322. yesBtn : {
  6323. name : self.lang('yes'),
  6324. click : function(e) {
  6325. var map = win.map;
  6326. var centerObj = map.getCenter();
  6327. var center = centerObj.lng + ',' + centerObj.lat;
  6328. var zoom = map.getZoom();
  6329. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6330. '?center=' + encodeURIComponent(center),
  6331. '&zoom=' + encodeURIComponent(zoom),
  6332. '&width=' + mapWidth,
  6333. '&height=' + mapHeight,
  6334. '&markers=' + encodeURIComponent(center),
  6335. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6336. if (checkbox[0].checked) {
  6337. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6338. } else {
  6339. self.exec('insertimage', url);
  6340. }
  6341. self.hideDialog().focus();
  6342. }
  6343. },
  6344. beforeRemove : function() {
  6345. searchBtn.remove();
  6346. if (doc) {
  6347. doc.write('');
  6348. }
  6349. iframe.remove();
  6350. }
  6351. });
  6352. var div = dialog.div,
  6353. addressBox = K('[name="address"]', div),
  6354. searchBtn = K('[name="searchBtn"]', div),
  6355. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6356. win, doc;
  6357. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6358. function ready() {
  6359. win = iframe[0].contentWindow;
  6360. doc = K.iframeDoc(iframe);
  6361. }
  6362. iframe.bind('load', function() {
  6363. iframe.unbind('load');
  6364. if (K.IE) {
  6365. ready();
  6366. } else {
  6367. setTimeout(ready, 0);
  6368. }
  6369. });
  6370. K('.ke-map', div).replaceWith(iframe);
  6371. // search map
  6372. searchBtn.click(function() {
  6373. win.search(addressBox.val());
  6374. });
  6375. });
  6376. });
  6377. /*******************************************************************************
  6378. * KindEditor - WYSIWYG HTML Editor for Internet
  6379. * Copyright (C) 2006-2011 kindsoft.net
  6380. *
  6381. * @author Roddy <luolonghao@gmail.com>
  6382. * @site http://www.kindsoft.net/
  6383. * @licence http://www.kindsoft.net/license.php
  6384. *******************************************************************************/
  6385. KindEditor.plugin('clearhtml', function(K) {
  6386. var self = this, name = 'clearhtml';
  6387. self.clickToolbar(name, function() {
  6388. self.focus();
  6389. var html = self.html();
  6390. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6391. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6392. html = K.formatHtml(html, {
  6393. a : ['href', 'target'],
  6394. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6395. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6396. table : ['border'],
  6397. 'td,th' : ['rowspan', 'colspan'],
  6398. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6399. });
  6400. self.html(html);
  6401. self.cmd.selection(true);
  6402. self.addBookmark();
  6403. });
  6404. });
  6405. /*******************************************************************************
  6406. * KindEditor - WYSIWYG HTML Editor for Internet
  6407. * Copyright (C) 2006-2011 kindsoft.net
  6408. *
  6409. * @author Roddy <luolonghao@gmail.com>
  6410. * @site http://www.kindsoft.net/
  6411. * @licence http://www.kindsoft.net/license.php
  6412. *******************************************************************************/
  6413. // google code prettify: http://google-code-prettify.googlecode.com/
  6414. // http://google-code-prettify.googlecode.com/
  6415. KindEditor.plugin('code', function(K) {
  6416. var self = this, name = 'code';
  6417. self.clickToolbar(name, function() {
  6418. var lang = self.lang(name + '.'),
  6419. html = ['<div style="padding:10px 20px;">',
  6420. '<div class="ke-dialog-row">',
  6421. '<select class="ke-code-type">',
  6422. '<option value="js">JavaScript</option>',
  6423. '<option value="html">HTML</option>',
  6424. '<option value="css">CSS</option>',
  6425. '<option value="php">PHP</option>',
  6426. '<option value="pl">Perl</option>',
  6427. '<option value="py">Python</option>',
  6428. '<option value="rb">Ruby</option>',
  6429. '<option value="java">Java</option>',
  6430. '<option value="vb">ASP/VB</option>',
  6431. '<option value="cpp">C/C++</option>',
  6432. '<option value="cs">C#</option>',
  6433. '<option value="xml">XML</option>',
  6434. '<option value="bsh">Shell</option>',
  6435. '<option value="">Other</option>',
  6436. '</select>',
  6437. '</div>',
  6438. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6439. '</div>'].join(''),
  6440. dialog = self.createDialog({
  6441. name : name,
  6442. width : 450,
  6443. title : self.lang(name),
  6444. body : html,
  6445. yesBtn : {
  6446. name : self.lang('yes'),
  6447. click : function(e) {
  6448. var type = K('.ke-code-type', dialog.div).val(),
  6449. code = textarea.val(),
  6450. cls = type === '' ? '' : ' lang-' + type,
  6451. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6452. if (K.trim(code) === '') {
  6453. alert(lang.pleaseInput);
  6454. textarea[0].focus();
  6455. return;
  6456. }
  6457. self.insertHtml(html).hideDialog().focus();
  6458. }
  6459. }
  6460. }),
  6461. textarea = K('textarea', dialog.div);
  6462. textarea[0].focus();
  6463. });
  6464. });
  6465. /*******************************************************************************
  6466. * KindEditor - WYSIWYG HTML Editor for Internet
  6467. * Copyright (C) 2006-2011 kindsoft.net
  6468. *
  6469. * @author Roddy <luolonghao@gmail.com>
  6470. * @site http://www.kindsoft.net/
  6471. * @licence http://www.kindsoft.net/license.php
  6472. *******************************************************************************/
  6473. KindEditor.plugin('emoticons', function(K) {
  6474. var self = this, name = 'emoticons',
  6475. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6476. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6477. currentPageNum = 1;
  6478. self.clickToolbar(name, function() {
  6479. var rows = 5, cols = 9, total = 135, startNum = 0,
  6480. cells = rows * cols, pages = Math.ceil(total / cells),
  6481. colsHalf = Math.floor(cols / 2),
  6482. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6483. elements = [],
  6484. menu = self.createMenu({
  6485. name : name,
  6486. beforeRemove : function() {
  6487. removeEvent();
  6488. }
  6489. });
  6490. menu.div.append(wrapperDiv);
  6491. var previewDiv, previewImg;
  6492. if (allowPreview) {
  6493. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6494. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6495. wrapperDiv.append(previewDiv);
  6496. previewDiv.append(previewImg);
  6497. }
  6498. function bindCellEvent(cell, j, num) {
  6499. if (previewDiv) {
  6500. cell.mouseover(function() {
  6501. if (j > colsHalf) {
  6502. previewDiv.css('left', 0);
  6503. previewDiv.css('right', '');
  6504. } else {
  6505. previewDiv.css('left', '');
  6506. previewDiv.css('right', 0);
  6507. }
  6508. previewImg.attr('src', path + num + '.gif');
  6509. K(this).addClass('ke-on');
  6510. });
  6511. } else {
  6512. cell.mouseover(function() {
  6513. K(this).addClass('ke-on');
  6514. });
  6515. }
  6516. cell.mouseout(function() {
  6517. K(this).removeClass('ke-on');
  6518. });
  6519. cell.click(function(e) {
  6520. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6521. e.stop();
  6522. });
  6523. }
  6524. function createEmoticonsTable(pageNum, parentDiv) {
  6525. var table = document.createElement('table');
  6526. parentDiv.append(table);
  6527. if (previewDiv) {
  6528. K(table).mouseover(function() {
  6529. previewDiv.show('block');
  6530. });
  6531. K(table).mouseout(function() {
  6532. previewDiv.hide();
  6533. });
  6534. elements.push(K(table));
  6535. }
  6536. table.className = 'ke-table';
  6537. table.cellPadding = 0;
  6538. table.cellSpacing = 0;
  6539. table.border = 0;
  6540. var num = (pageNum - 1) * cells + startNum;
  6541. for (var i = 0; i < rows; i++) {
  6542. var row = table.insertRow(i);
  6543. for (var j = 0; j < cols; j++) {
  6544. var cell = K(row.insertCell(j));
  6545. cell.addClass('ke-cell');
  6546. bindCellEvent(cell, j, num);
  6547. var span = K('<span class="ke-img"></span>')
  6548. .css('background-position', '-' + (24 * num) + 'px 0px')
  6549. .css('background-image', 'url(' + path + 'static.gif)');
  6550. cell.append(span);
  6551. elements.push(cell);
  6552. num++;
  6553. }
  6554. }
  6555. return table;
  6556. }
  6557. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6558. function removeEvent() {
  6559. K.each(elements, function() {
  6560. this.unbind();
  6561. });
  6562. }
  6563. var pageDiv;
  6564. function bindPageEvent(el, pageNum) {
  6565. el.click(function(e) {
  6566. removeEvent();
  6567. table.parentNode.removeChild(table);
  6568. pageDiv.remove();
  6569. table = createEmoticonsTable(pageNum, wrapperDiv);
  6570. createPageTable(pageNum);
  6571. currentPageNum = pageNum;
  6572. e.stop();
  6573. });
  6574. }
  6575. function createPageTable(currentPageNum) {
  6576. pageDiv = K('<div class="ke-page"></div>');
  6577. wrapperDiv.append(pageDiv);
  6578. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6579. if (currentPageNum !== pageNum) {
  6580. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6581. bindPageEvent(a, pageNum);
  6582. pageDiv.append(a);
  6583. elements.push(a);
  6584. } else {
  6585. pageDiv.append(K('@[' + pageNum + ']'));
  6586. }
  6587. pageDiv.append(K('@&nbsp;'));
  6588. }
  6589. }
  6590. createPageTable(currentPageNum);
  6591. });
  6592. });
  6593. /*******************************************************************************
  6594. * KindEditor - WYSIWYG HTML Editor for Internet
  6595. * Copyright (C) 2006-2011 kindsoft.net
  6596. *
  6597. * @author Roddy <luolonghao@gmail.com>
  6598. * @site http://www.kindsoft.net/
  6599. * @licence http://www.kindsoft.net/license.php
  6600. *******************************************************************************/
  6601. KindEditor.plugin('filemanager', function(K) {
  6602. var self = this, name = 'filemanager',
  6603. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6604. imgPath = self.pluginsPath + name + '/images/',
  6605. lang = self.lang(name + '.');
  6606. function makeFileTitle(filename, filesize, datetime) {
  6607. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6608. }
  6609. function bindTitle(el, data) {
  6610. if (data.is_dir) {
  6611. el.attr('title', data.filename);
  6612. } else {
  6613. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6614. }
  6615. }
  6616. self.plugin.filemanagerDialog = function(options) {
  6617. var width = K.undef(options.width, 650),
  6618. height = K.undef(options.height, 510),
  6619. dirName = K.undef(options.dirName, ''),
  6620. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(), // "LIST" or "VIEW"
  6621. clickFn = options.clickFn;
  6622. var html = [
  6623. '<div style="padding:10px 20px;">',
  6624. // header start
  6625. '<div class="ke-plugin-filemanager-header">',
  6626. // left start
  6627. '<div class="ke-left">',
  6628. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6629. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6630. '</div>',
  6631. // right start
  6632. '<div class="ke-right">',
  6633. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6634. '<option value="VIEW">' + lang.viewImage + '</option>',
  6635. '<option value="LIST">' + lang.listImage + '</option>',
  6636. '</select> ',
  6637. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6638. '<option value="NAME">' + lang.fileName + '</option>',
  6639. '<option value="SIZE">' + lang.fileSize + '</option>',
  6640. '<option value="TYPE">' + lang.fileType + '</option>',
  6641. '</select>',
  6642. '</div>',
  6643. '<div class="ke-clearfix"></div>',
  6644. '</div>',
  6645. // body start
  6646. '<div class="ke-plugin-filemanager-body"></div>',
  6647. '</div>'
  6648. ].join('');
  6649. var dialog = self.createDialog({
  6650. name : name,
  6651. width : width,
  6652. height : height,
  6653. title : self.lang(name),
  6654. body : html
  6655. }),
  6656. div = dialog.div,
  6657. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6658. moveupImg = K('[name="moveupImg"]', div),
  6659. moveupLink = K('[name="moveupLink"]', div),
  6660. viewServerBtn = K('[name="viewServer"]', div),
  6661. viewTypeBox = K('[name="viewType"]', div),
  6662. orderTypeBox = K('[name="orderType"]', div);
  6663. function reloadPage(path, order, func) {
  6664. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6665. dialog.showLoading(self.lang('ajaxLoading'));
  6666. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6667. dialog.hideLoading();
  6668. func(data);
  6669. });
  6670. }
  6671. var elList = [];
  6672. function bindEvent(el, result, data, createFunc) {
  6673. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6674. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6675. if (data.is_dir) {
  6676. el.click(function(e) {
  6677. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6678. });
  6679. } else if (data.is_photo) {
  6680. el.click(function(e) {
  6681. clickFn.call(this, fileUrl, data.filename);
  6682. });
  6683. } else {
  6684. el.click(function(e) {
  6685. clickFn.call(this, fileUrl, data.filename);
  6686. });
  6687. }
  6688. elList.push(el);
  6689. }
  6690. function createCommon(result, createFunc) {
  6691. // remove events
  6692. K.each(elList, function() {
  6693. this.unbind();
  6694. });
  6695. moveupLink.unbind();
  6696. viewTypeBox.unbind();
  6697. orderTypeBox.unbind();
  6698. // add events
  6699. if (result.current_dir_path) {
  6700. moveupLink.click(function(e) {
  6701. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6702. });
  6703. }
  6704. function changeFunc() {
  6705. if (viewTypeBox.val() == 'VIEW') {
  6706. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6707. } else {
  6708. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6709. }
  6710. }
  6711. viewTypeBox.change(changeFunc);
  6712. orderTypeBox.change(changeFunc);
  6713. bodyDiv.html('');
  6714. }
  6715. function createList(result) {
  6716. createCommon(result, createList);
  6717. var table = document.createElement('table');
  6718. table.className = 'ke-table';
  6719. table.cellPadding = 0;
  6720. table.cellSpacing = 0;
  6721. table.border = 0;
  6722. bodyDiv.append(table);
  6723. var fileList = result.file_list;
  6724. for (var i = 0, len = fileList.length; i < len; i++) {
  6725. var data = fileList[i], row = K(table.insertRow(i));
  6726. row.mouseover(function(e) {
  6727. K(this).addClass('ke-on');
  6728. })
  6729. .mouseout(function(e) {
  6730. K(this).removeClass('ke-on');
  6731. });
  6732. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6733. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6734. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6735. if (!data.is_dir || data.has_file) {
  6736. row.css('cursor', 'pointer');
  6737. cell0.attr('title', data.filename);
  6738. bindEvent(cell0, result, data, createList);
  6739. } else {
  6740. cell0.attr('title', lang.emptyFolder);
  6741. }
  6742. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6743. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6744. }
  6745. }
  6746. function createView(result) {
  6747. createCommon(result, createView);
  6748. var fileList = result.file_list;
  6749. for (var i = 0, len = fileList.length; i < len; i++) {
  6750. var data = fileList[i],
  6751. div = K('<div class="ke-inline-block ke-item"></div>');
  6752. bodyDiv.append(div);
  6753. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6754. .mouseover(function(e) {
  6755. K(this).addClass('ke-on');
  6756. })
  6757. .mouseout(function(e) {
  6758. K(this).removeClass('ke-on');
  6759. });
  6760. div.append(photoDiv);
  6761. var fileUrl = result.current_url + data.filename,
  6762. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6763. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6764. if (!data.is_dir || data.has_file) {
  6765. photoDiv.css('cursor', 'pointer');
  6766. bindTitle(photoDiv, data);
  6767. bindEvent(photoDiv, result, data, createView);
  6768. } else {
  6769. photoDiv.attr('title', lang.emptyFolder);
  6770. }
  6771. photoDiv.append(img);
  6772. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6773. }
  6774. }
  6775. viewTypeBox.val(viewType);
  6776. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6777. return dialog;
  6778. }
  6779. });
  6780. /*******************************************************************************
  6781. * KindEditor - WYSIWYG HTML Editor for Internet
  6782. * Copyright (C) 2006-2011 kindsoft.net
  6783. *
  6784. * @author Roddy <luolonghao@gmail.com>
  6785. * @site http://www.kindsoft.net/
  6786. * @licence http://www.kindsoft.net/license.php
  6787. *******************************************************************************/
  6788. KindEditor.plugin('flash', function(K) {
  6789. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6790. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6791. allowFileManager = K.undef(self.allowFileManager, false),
  6792. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6793. extraParams = K.undef(self.extraFileUploadParams, {}),
  6794. filePostName = K.undef(self.filePostName, 'imgFile'),
  6795. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  6796. self.plugin.flash = {
  6797. edit : function() {
  6798. var html = [
  6799. '<div style="padding:20px;">',
  6800. //url
  6801. '<div class="ke-dialog-row">',
  6802. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6803. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6804. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6805. '<span class="ke-button-common ke-button-outer">',
  6806. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6807. '</span>',
  6808. '</div>',
  6809. //width
  6810. '<div class="ke-dialog-row">',
  6811. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6812. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6813. '</div>',
  6814. //height
  6815. '<div class="ke-dialog-row">',
  6816. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6817. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6818. '</div>',
  6819. '</div>'
  6820. ].join('');
  6821. var dialog = self.createDialog({
  6822. name : name,
  6823. width : 450,
  6824. title : self.lang(name),
  6825. body : html,
  6826. yesBtn : {
  6827. name : self.lang('yes'),
  6828. click : function(e) {
  6829. var url = K.trim(urlBox.val()),
  6830. width = widthBox.val(),
  6831. height = heightBox.val();
  6832. if (url == 'http://' || K.invalidUrl(url)) {
  6833. alert(self.lang('invalidUrl'));
  6834. urlBox[0].focus();
  6835. return;
  6836. }
  6837. if (!/^\d*$/.test(width)) {
  6838. alert(self.lang('invalidWidth'));
  6839. widthBox[0].focus();
  6840. return;
  6841. }
  6842. if (!/^\d*$/.test(height)) {
  6843. alert(self.lang('invalidHeight'));
  6844. heightBox[0].focus();
  6845. return;
  6846. }
  6847. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6848. src : url,
  6849. type : K.mediaType('.swf'),
  6850. width : width,
  6851. height : height,
  6852. quality : 'high'
  6853. });
  6854. self.insertHtml(html).hideDialog().focus();
  6855. }
  6856. }
  6857. }),
  6858. div = dialog.div,
  6859. urlBox = K('[name="url"]', div),
  6860. viewServerBtn = K('[name="viewServer"]', div),
  6861. widthBox = K('[name="width"]', div),
  6862. heightBox = K('[name="height"]', div);
  6863. urlBox.val('http://');
  6864. if (allowFlashUpload) {
  6865. var uploadbutton = K.uploadbutton({
  6866. button : K('.ke-upload-button', div)[0],
  6867. fieldName : filePostName,
  6868. extraParams : extraParams,
  6869. url : K.addParam(uploadJson, 'dir=flash'),
  6870. afterUpload : function(data) {
  6871. dialog.hideLoading();
  6872. if (data.error === 0) {
  6873. var url = data.url;
  6874. if (formatUploadUrl) {
  6875. url = K.formatUrl(url, 'absolute');
  6876. }
  6877. urlBox.val(url);
  6878. if (self.afterUpload) {
  6879. self.afterUpload.call(self, url, data, name);
  6880. }
  6881. alert(self.lang('uploadSuccess'));
  6882. } else {
  6883. alert(data.message);
  6884. }
  6885. },
  6886. afterError : function(html) {
  6887. dialog.hideLoading();
  6888. self.errorDialog(html);
  6889. }
  6890. });
  6891. uploadbutton.fileBox.change(function(e) {
  6892. dialog.showLoading(self.lang('uploadLoading'));
  6893. uploadbutton.submit();
  6894. });
  6895. } else {
  6896. K('.ke-upload-button', div).hide();
  6897. }
  6898. if (allowFileManager) {
  6899. viewServerBtn.click(function(e) {
  6900. self.loadPlugin('filemanager', function() {
  6901. self.plugin.filemanagerDialog({
  6902. viewType : 'LIST',
  6903. dirName : 'flash',
  6904. clickFn : function(url, title) {
  6905. if (self.dialogs.length > 1) {
  6906. K('[name="url"]', div).val(url);
  6907. if (self.afterSelectFile) {
  6908. self.afterSelectFile.call(self, url);
  6909. }
  6910. self.hideDialog();
  6911. }
  6912. }
  6913. });
  6914. });
  6915. });
  6916. } else {
  6917. viewServerBtn.hide();
  6918. }
  6919. var img = self.plugin.getSelectedFlash();
  6920. if (img) {
  6921. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  6922. urlBox.val(attrs.src);
  6923. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  6924. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  6925. }
  6926. urlBox[0].focus();
  6927. urlBox[0].select();
  6928. },
  6929. 'delete' : function() {
  6930. self.plugin.getSelectedFlash().remove();
  6931. // [IE] 删除图片后立即点击图片按钮出错
  6932. self.addBookmark();
  6933. }
  6934. };
  6935. self.clickToolbar(name, self.plugin.flash.edit);
  6936. });
  6937. /*******************************************************************************
  6938. * KindEditor - WYSIWYG HTML Editor for Internet
  6939. * Copyright (C) 2006-2011 kindsoft.net
  6940. *
  6941. * @author Roddy <luolonghao@gmail.com>
  6942. * @site http://www.kindsoft.net/
  6943. * @licence http://www.kindsoft.net/license.php
  6944. *******************************************************************************/
  6945. KindEditor.plugin('image', function(K) {
  6946. var self = this, name = 'image',
  6947. allowImageUpload = K.undef(self.allowImageUpload, true),
  6948. allowImageRemote = K.undef(self.allowImageRemote, true),
  6949. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6950. allowFileManager = K.undef(self.allowFileManager, false),
  6951. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  6952. imageTabIndex = K.undef(self.imageTabIndex, 0),
  6953. imgPath = self.pluginsPath + 'image/images/',
  6954. extraParams = K.undef(self.extraFileUploadParams, {}),
  6955. filePostName = K.undef(self.filePostName, 'imgFile'),
  6956. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  6957. lang = self.lang(name + '.');
  6958. self.plugin.imageDialog = function(options) {
  6959. var imageUrl = options.imageUrl,
  6960. imageWidth = K.undef(options.imageWidth, ''),
  6961. imageHeight = K.undef(options.imageHeight, ''),
  6962. imageTitle = K.undef(options.imageTitle, ''),
  6963. imageAlign = K.undef(options.imageAlign, ''),
  6964. showRemote = K.undef(options.showRemote, true),
  6965. showLocal = K.undef(options.showLocal, true),
  6966. tabIndex = K.undef(options.tabIndex, 0),
  6967. clickFn = options.clickFn;
  6968. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  6969. var hiddenElements = [];
  6970. for(var k in extraParams){
  6971. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  6972. }
  6973. var html = [
  6974. '<div style="padding:20px;">',
  6975. //tabs
  6976. '<div class="tabs"></div>',
  6977. //remote image - start
  6978. '<div class="tab1" style="display:none;">',
  6979. //url
  6980. '<div class="ke-dialog-row">',
  6981. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  6982. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  6983. '<span class="ke-button-common ke-button-outer">',
  6984. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6985. '</span>',
  6986. '</div>',
  6987. //size
  6988. '<div class="ke-dialog-row">',
  6989. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  6990. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  6991. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  6992. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  6993. '</div>',
  6994. //align
  6995. '<div class="ke-dialog-row">',
  6996. '<label style="width:60px;">' + lang.align + '</label>',
  6997. '<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="" />',
  6998. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  6999. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7000. '</div>',
  7001. //title
  7002. '<div class="ke-dialog-row">',
  7003. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7004. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7005. '</div>',
  7006. '</div>',
  7007. //remote image - end
  7008. //local upload - start
  7009. '<div class="tab2" style="display:none;">',
  7010. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7011. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7012. //file
  7013. '<div class="ke-dialog-row">',
  7014. hiddenElements.join(''),
  7015. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7016. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7017. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7018. '</div>',
  7019. '</form>',
  7020. '</div>',
  7021. //local upload - end
  7022. '</div>'
  7023. ].join('');
  7024. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7025. dialogHeight = showLocal && showRemote ? 300 : 250;
  7026. var dialog = self.createDialog({
  7027. name : name,
  7028. width : dialogWidth,
  7029. height : dialogHeight,
  7030. title : self.lang(name),
  7031. body : html,
  7032. yesBtn : {
  7033. name : self.lang('yes'),
  7034. click : function(e) {
  7035. // Bugfix: http://code.google.com/p/kindeditor/issues/detail?id=319
  7036. if (dialog.isLoading) {
  7037. return;
  7038. }
  7039. // insert local image
  7040. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7041. if (uploadbutton.fileBox.val() == '') {
  7042. alert(self.lang('pleaseSelectFile'));
  7043. return;
  7044. }
  7045. dialog.showLoading(self.lang('uploadLoading'));
  7046. uploadbutton.submit();
  7047. localUrlBox.val('');
  7048. return;
  7049. }
  7050. // insert remote image
  7051. var url = K.trim(urlBox.val()),
  7052. width = widthBox.val(),
  7053. height = heightBox.val(),
  7054. title = titleBox.val(),
  7055. align = '';
  7056. alignBox.each(function() {
  7057. if (this.checked) {
  7058. align = this.value;
  7059. return false;
  7060. }
  7061. });
  7062. if (url == 'http://' || K.invalidUrl(url)) {
  7063. alert(self.lang('invalidUrl'));
  7064. urlBox[0].focus();
  7065. return;
  7066. }
  7067. if (!/^\d*$/.test(width)) {
  7068. alert(self.lang('invalidWidth'));
  7069. widthBox[0].focus();
  7070. return;
  7071. }
  7072. if (!/^\d*$/.test(height)) {
  7073. alert(self.lang('invalidHeight'));
  7074. heightBox[0].focus();
  7075. return;
  7076. }
  7077. clickFn.call(self, url, title, width, height, 0, align);
  7078. }
  7079. },
  7080. beforeRemove : function() {
  7081. viewServerBtn.unbind();
  7082. widthBox.unbind();
  7083. heightBox.unbind();
  7084. refreshBtn.unbind();
  7085. }
  7086. }),
  7087. div = dialog.div;
  7088. var urlBox = K('[name="url"]', div),
  7089. localUrlBox = K('[name="localUrl"]', div),
  7090. viewServerBtn = K('[name="viewServer"]', div),
  7091. widthBox = K('.tab1 [name="width"]', div),
  7092. heightBox = K('.tab1 [name="height"]', div),
  7093. refreshBtn = K('.ke-refresh-btn', div),
  7094. titleBox = K('.tab1 [name="title"]', div),
  7095. alignBox = K('.tab1 [name="align"]', div);
  7096. var tabs;
  7097. if (showRemote && showLocal) {
  7098. tabs = K.tabs({
  7099. src : K('.tabs', div),
  7100. afterSelect : function(i) {}
  7101. });
  7102. tabs.add({
  7103. title : lang.remoteImage,
  7104. panel : K('.tab1', div)
  7105. });
  7106. tabs.add({
  7107. title : lang.localImage,
  7108. panel : K('.tab2', div)
  7109. });
  7110. tabs.select(tabIndex);
  7111. } else if (showRemote) {
  7112. K('.tab1', div).show();
  7113. } else if (showLocal) {
  7114. K('.tab2', div).show();
  7115. }
  7116. var uploadbutton = K.uploadbutton({
  7117. button : K('.ke-upload-button', div)[0],
  7118. fieldName : filePostName,
  7119. form : K('.ke-form', div),
  7120. target : target,
  7121. width: 60,
  7122. afterUpload : function(data) {
  7123. dialog.hideLoading();
  7124. if (data.error === 0) {
  7125. var url = data.url;
  7126. if (formatUploadUrl) {
  7127. url = K.formatUrl(url, 'absolute');
  7128. }
  7129. if (self.afterUpload) {
  7130. self.afterUpload.call(self, url, data, name);
  7131. }
  7132. if (!fillDescAfterUploadImage) {
  7133. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7134. } else {
  7135. K(".ke-dialog-row #remoteUrl", div).val(url);
  7136. K(".ke-tabs-li", div)[0].click();
  7137. K(".ke-refresh-btn", div).click();
  7138. }
  7139. } else {
  7140. alert(data.message);
  7141. }
  7142. },
  7143. afterError : function(html) {
  7144. dialog.hideLoading();
  7145. self.errorDialog(html);
  7146. }
  7147. });
  7148. uploadbutton.fileBox.change(function(e) {
  7149. localUrlBox.val(uploadbutton.fileBox.val());
  7150. });
  7151. if (allowFileManager) {
  7152. viewServerBtn.click(function(e) {
  7153. self.loadPlugin('filemanager', function() {
  7154. self.plugin.filemanagerDialog({
  7155. viewType : 'VIEW',
  7156. dirName : 'image',
  7157. clickFn : function(url, title) {
  7158. if (self.dialogs.length > 1) {
  7159. K('[name="url"]', div).val(url);
  7160. if (self.afterSelectFile) {
  7161. self.afterSelectFile.call(self, url);
  7162. }
  7163. self.hideDialog();
  7164. }
  7165. }
  7166. });
  7167. });
  7168. });
  7169. } else {
  7170. viewServerBtn.hide();
  7171. }
  7172. var originalWidth = 0, originalHeight = 0;
  7173. function setSize(width, height) {
  7174. widthBox.val(width);
  7175. heightBox.val(height);
  7176. originalWidth = width;
  7177. originalHeight = height;
  7178. }
  7179. refreshBtn.click(function(e) {
  7180. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7181. position : 'absolute',
  7182. visibility : 'hidden',
  7183. top : 0,
  7184. left : '-1000px'
  7185. });
  7186. tempImg.bind('load', function() {
  7187. setSize(tempImg.width(), tempImg.height());
  7188. tempImg.remove();
  7189. });
  7190. K(document.body).append(tempImg);
  7191. });
  7192. widthBox.change(function(e) {
  7193. if (originalWidth > 0) {
  7194. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7195. }
  7196. });
  7197. heightBox.change(function(e) {
  7198. if (originalHeight > 0) {
  7199. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7200. }
  7201. });
  7202. urlBox.val(options.imageUrl);
  7203. setSize(options.imageWidth, options.imageHeight);
  7204. titleBox.val(options.imageTitle);
  7205. alignBox.each(function() {
  7206. if (this.value === options.imageAlign) {
  7207. this.checked = true;
  7208. return false;
  7209. }
  7210. });
  7211. if (showRemote && tabIndex === 0) {
  7212. urlBox[0].focus();
  7213. urlBox[0].select();
  7214. }
  7215. return dialog;
  7216. };
  7217. self.plugin.image = {
  7218. edit : function() {
  7219. var img = self.plugin.getSelectedImage();
  7220. self.plugin.imageDialog({
  7221. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7222. imageWidth : img ? img.width() : '',
  7223. imageHeight : img ? img.height() : '',
  7224. imageTitle : img ? img.attr('title') : '',
  7225. imageAlign : img ? img.attr('align') : '',
  7226. showRemote : allowImageRemote,
  7227. showLocal : allowImageUpload,
  7228. tabIndex: img ? 0 : imageTabIndex,
  7229. clickFn : function(url, title, width, height, border, align) {
  7230. if (img) {
  7231. img.attr('src', url);
  7232. img.attr('data-ke-src', url);
  7233. img.attr('width', width);
  7234. img.attr('height', height);
  7235. img.attr('title', title);
  7236. img.attr('align', align);
  7237. img.attr('alt', title);
  7238. } else {
  7239. self.exec('insertimage', url, title, width, height, border, align);
  7240. }
  7241. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  7242. setTimeout(function() {
  7243. self.hideDialog().focus();
  7244. }, 0);
  7245. }
  7246. });
  7247. },
  7248. 'delete' : function() {
  7249. var target = self.plugin.getSelectedImage();
  7250. if (target.parent().name == 'a') {
  7251. target = target.parent();
  7252. }
  7253. target.remove();
  7254. // [IE] 删除图片后立即点击图片按钮出错
  7255. self.addBookmark();
  7256. }
  7257. };
  7258. self.clickToolbar(name, self.plugin.image.edit);
  7259. });
  7260. /*******************************************************************************
  7261. * KindEditor - WYSIWYG HTML Editor for Internet
  7262. * Copyright (C) 2006-2011 kindsoft.net
  7263. *
  7264. * @author Roddy <luolonghao@gmail.com>
  7265. * @site http://www.kindsoft.net/
  7266. * @licence http://www.kindsoft.net/license.php
  7267. *******************************************************************************/
  7268. KindEditor.plugin('insertfile', function(K) {
  7269. var self = this, name = 'insertfile',
  7270. allowFileUpload = K.undef(self.allowFileUpload, true),
  7271. allowFileManager = K.undef(self.allowFileManager, false),
  7272. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7273. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7274. extraParams = K.undef(self.extraFileUploadParams, {}),
  7275. filePostName = K.undef(self.filePostName, 'imgFile'),
  7276. lang = self.lang(name + '.');
  7277. self.plugin.fileDialog = function(options) {
  7278. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7279. fileTitle = K.undef(options.fileTitle, ''),
  7280. clickFn = options.clickFn;
  7281. var html = [
  7282. '<div style="padding:20px;">',
  7283. '<div class="ke-dialog-row">',
  7284. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7285. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7286. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7287. '<span class="ke-button-common ke-button-outer">',
  7288. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7289. '</span>',
  7290. '</div>',
  7291. //title
  7292. '<div class="ke-dialog-row">',
  7293. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7294. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7295. '</div>',
  7296. //form end
  7297. '</form>',
  7298. '</div>'
  7299. ].join('');
  7300. var dialog = self.createDialog({
  7301. name : name,
  7302. width : 450,
  7303. title : self.lang(name),
  7304. body : html,
  7305. yesBtn : {
  7306. name : self.lang('yes'),
  7307. click : function(e) {
  7308. var url = K.trim(urlBox.val()),
  7309. title = titleBox.val();
  7310. if (url == 'http://' || K.invalidUrl(url)) {
  7311. alert(self.lang('invalidUrl'));
  7312. urlBox[0].focus();
  7313. return;
  7314. }
  7315. if (K.trim(title) === '') {
  7316. title = url;
  7317. }
  7318. clickFn.call(self, url, title);
  7319. }
  7320. }
  7321. }),
  7322. div = dialog.div;
  7323. var urlBox = K('[name="url"]', div),
  7324. viewServerBtn = K('[name="viewServer"]', div),
  7325. titleBox = K('[name="title"]', div);
  7326. if (allowFileUpload) {
  7327. var uploadbutton = K.uploadbutton({
  7328. button : K('.ke-upload-button', div)[0],
  7329. fieldName : filePostName,
  7330. url : K.addParam(uploadJson, 'dir=file'),
  7331. extraParams : extraParams,
  7332. afterUpload : function(data) {
  7333. dialog.hideLoading();
  7334. if (data.error === 0) {
  7335. var url = data.url;
  7336. if (formatUploadUrl) {
  7337. url = K.formatUrl(url, 'absolute');
  7338. }
  7339. urlBox.val(url);
  7340. if (self.afterUpload) {
  7341. self.afterUpload.call(self, url, data, name);
  7342. }
  7343. alert(self.lang('uploadSuccess'));
  7344. } else {
  7345. alert(data.message);
  7346. }
  7347. },
  7348. afterError : function(html) {
  7349. dialog.hideLoading();
  7350. self.errorDialog(html);
  7351. }
  7352. });
  7353. uploadbutton.fileBox.change(function(e) {
  7354. dialog.showLoading(self.lang('uploadLoading'));
  7355. uploadbutton.submit();
  7356. });
  7357. } else {
  7358. K('.ke-upload-button', div).hide();
  7359. }
  7360. if (allowFileManager) {
  7361. viewServerBtn.click(function(e) {
  7362. self.loadPlugin('filemanager', function() {
  7363. self.plugin.filemanagerDialog({
  7364. viewType : 'LIST',
  7365. dirName : 'file',
  7366. clickFn : function(url, title) {
  7367. if (self.dialogs.length > 1) {
  7368. K('[name="url"]', div).val(url);
  7369. if (self.afterSelectFile) {
  7370. self.afterSelectFile.call(self, url);
  7371. }
  7372. self.hideDialog();
  7373. }
  7374. }
  7375. });
  7376. });
  7377. });
  7378. } else {
  7379. viewServerBtn.hide();
  7380. }
  7381. urlBox.val(fileUrl);
  7382. titleBox.val(fileTitle);
  7383. urlBox[0].focus();
  7384. urlBox[0].select();
  7385. };
  7386. self.clickToolbar(name, function() {
  7387. self.plugin.fileDialog({
  7388. clickFn : function(url, title) {
  7389. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7390. self.insertHtml(html).hideDialog().focus();
  7391. }
  7392. });
  7393. });
  7394. });
  7395. /*******************************************************************************
  7396. * KindEditor - WYSIWYG HTML Editor for Internet
  7397. * Copyright (C) 2006-2011 kindsoft.net
  7398. *
  7399. * @author Roddy <luolonghao@gmail.com>
  7400. * @site http://www.kindsoft.net/
  7401. * @licence http://www.kindsoft.net/license.php
  7402. *******************************************************************************/
  7403. KindEditor.plugin('lineheight', function(K) {
  7404. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7405. self.clickToolbar(name, function() {
  7406. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7407. if (commonNode) {
  7408. curVal = commonNode.css('line-height');
  7409. }
  7410. var menu = self.createMenu({
  7411. name : name,
  7412. width : 150
  7413. });
  7414. K.each(lang.lineHeight, function(i, row) {
  7415. K.each(row, function(key, val) {
  7416. menu.addItem({
  7417. title : val,
  7418. checked : curVal === key,
  7419. click : function() {
  7420. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7421. span : '.line-height=' + key
  7422. });
  7423. self.updateState();
  7424. self.addBookmark();
  7425. self.hideMenu();
  7426. }
  7427. });
  7428. });
  7429. });
  7430. });
  7431. });
  7432. /*******************************************************************************
  7433. * KindEditor - WYSIWYG HTML Editor for Internet
  7434. * Copyright (C) 2006-2011 kindsoft.net
  7435. *
  7436. * @author Roddy <luolonghao@gmail.com>
  7437. * @site http://www.kindsoft.net/
  7438. * @licence http://www.kindsoft.net/license.php
  7439. *******************************************************************************/
  7440. KindEditor.plugin('link', function(K) {
  7441. var self = this, name = 'link';
  7442. self.plugin.link = {
  7443. edit : function() {
  7444. var lang = self.lang(name + '.'),
  7445. html = '<div style="padding:20px;">' +
  7446. //url
  7447. '<div class="ke-dialog-row">' +
  7448. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7449. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7450. //type
  7451. '<div class="ke-dialog-row"">' +
  7452. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7453. '<select id="keType" name="type"></select>' +
  7454. '</div>' +
  7455. '</div>',
  7456. dialog = self.createDialog({
  7457. name : name,
  7458. width : 450,
  7459. title : self.lang(name),
  7460. body : html,
  7461. yesBtn : {
  7462. name : self.lang('yes'),
  7463. click : function(e) {
  7464. var url = K.trim(urlBox.val());
  7465. if (url == 'http://' || K.invalidUrl(url)) {
  7466. alert(self.lang('invalidUrl'));
  7467. urlBox[0].focus();
  7468. return;
  7469. }
  7470. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7471. }
  7472. }
  7473. }),
  7474. div = dialog.div,
  7475. urlBox = K('input[name="url"]', div),
  7476. typeBox = K('select[name="type"]', div);
  7477. urlBox.val('http://');
  7478. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7479. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7480. self.cmd.selection();
  7481. var a = self.plugin.getSelectedLink();
  7482. if (a) {
  7483. self.cmd.range.selectNode(a[0]);
  7484. self.cmd.select();
  7485. urlBox.val(a.attr('data-ke-src'));
  7486. typeBox.val(a.attr('target'));
  7487. }
  7488. urlBox[0].focus();
  7489. urlBox[0].select();
  7490. },
  7491. 'delete' : function() {
  7492. self.exec('unlink', null);
  7493. }
  7494. };
  7495. self.clickToolbar(name, self.plugin.link.edit);
  7496. });
  7497. /*******************************************************************************
  7498. * KindEditor - WYSIWYG HTML Editor for Internet
  7499. * Copyright (C) 2006-2011 kindsoft.net
  7500. *
  7501. * @author Roddy <luolonghao@gmail.com>
  7502. * @site http://www.kindsoft.net/
  7503. * @licence http://www.kindsoft.net/license.php
  7504. *******************************************************************************/
  7505. // Google Maps: http://code.google.com/apis/maps/index.html
  7506. KindEditor.plugin('map', function(K) {
  7507. var self = this, name = 'map', lang = self.lang(name + '.');
  7508. self.clickToolbar(name, function() {
  7509. var html = ['<div style="padding:10px 20px;">',
  7510. '<div class="ke-dialog-row">',
  7511. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  7512. '<span class="ke-button-common ke-button-outer">',
  7513. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  7514. '</span>',
  7515. '</div>',
  7516. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  7517. '</div>'].join('');
  7518. var dialog = self.createDialog({
  7519. name : name,
  7520. width : 600,
  7521. title : self.lang(name),
  7522. body : html,
  7523. yesBtn : {
  7524. name : self.lang('yes'),
  7525. click : function(e) {
  7526. var geocoder = win.geocoder,
  7527. map = win.map,
  7528. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  7529. zoom = map.getZoom(),
  7530. maptype = map.getMapTypeId(),
  7531. url = 'http://maps.googleapis.com/maps/api/staticmap';
  7532. url += '?center=' + encodeURIComponent(center);
  7533. url += '&zoom=' + encodeURIComponent(zoom);
  7534. url += '&size=558x360';
  7535. url += '&maptype=' + encodeURIComponent(maptype);
  7536. url += '&markers=' + encodeURIComponent(center);
  7537. url += '&language=' + self.langType;
  7538. url += '&sensor=false';
  7539. self.exec('insertimage', url).hideDialog().focus();
  7540. }
  7541. },
  7542. beforeRemove : function() {
  7543. searchBtn.remove();
  7544. if (doc) {
  7545. doc.write('');
  7546. }
  7547. iframe.remove();
  7548. }
  7549. });
  7550. var div = dialog.div,
  7551. addressBox = K('[name="address"]', div),
  7552. searchBtn = K('[name="searchBtn"]', div),
  7553. win, doc;
  7554. var iframeHtml = ['<!doctype html><html><head>',
  7555. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  7556. '<style>',
  7557. ' html { height: 100% }',
  7558. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  7559. ' #map_canvas { height: 100% }',
  7560. '</style>',
  7561. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  7562. '<script>',
  7563. 'var map, geocoder;',
  7564. 'function initialize() {',
  7565. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  7566. ' var options = {',
  7567. ' zoom: 11,',
  7568. ' center: latlng,',
  7569. ' disableDefaultUI: true,',
  7570. ' panControl: true,',
  7571. ' zoomControl: true,',
  7572. ' mapTypeControl: true,',
  7573. ' scaleControl: true,',
  7574. ' streetViewControl: false,',
  7575. ' overviewMapControl: true,',
  7576. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  7577. ' };',
  7578. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  7579. ' geocoder = new google.maps.Geocoder();',
  7580. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  7581. ' if (status == google.maps.GeocoderStatus.OK) {',
  7582. ' if (results[3]) {',
  7583. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  7584. ' }',
  7585. ' }',
  7586. ' });',
  7587. '}',
  7588. 'function search(address) {',
  7589. ' if (!map) return;',
  7590. ' geocoder.geocode({address : address}, function(results, status) {',
  7591. ' if (status == google.maps.GeocoderStatus.OK) {',
  7592. ' map.setZoom(11);',
  7593. ' map.setCenter(results[0].geometry.location);',
  7594. ' var marker = new google.maps.Marker({',
  7595. ' map: map,',
  7596. ' position: results[0].geometry.location',
  7597. ' });',
  7598. ' } else {',
  7599. ' alert("Invalid address: " + address);',
  7600. ' }',
  7601. ' });',
  7602. '}',
  7603. '</script>',
  7604. '</head>',
  7605. '<body onload="initialize();">',
  7606. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  7607. '</body></html>'].join('\n');
  7608. // TODO:用doc.write(iframeHtml)方式加载时,在IE6上第一次加载报错,暂时使用src方式
  7609. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  7610. function ready() {
  7611. win = iframe[0].contentWindow;
  7612. doc = K.iframeDoc(iframe);
  7613. //doc.open();
  7614. //doc.write(iframeHtml);
  7615. //doc.close();
  7616. }
  7617. iframe.bind('load', function() {
  7618. iframe.unbind('load');
  7619. if (K.IE) {
  7620. ready();
  7621. } else {
  7622. setTimeout(ready, 0);
  7623. }
  7624. });
  7625. K('.ke-map', div).replaceWith(iframe);
  7626. // search map
  7627. searchBtn.click(function() {
  7628. win.search(addressBox.val());
  7629. });
  7630. });
  7631. });
  7632. /*******************************************************************************
  7633. * KindEditor - WYSIWYG HTML Editor for Internet
  7634. * Copyright (C) 2006-2011 kindsoft.net
  7635. *
  7636. * @author Roddy <luolonghao@gmail.com>
  7637. * @site http://www.kindsoft.net/
  7638. * @licence http://www.kindsoft.net/license.php
  7639. *******************************************************************************/
  7640. KindEditor.plugin('media', function(K) {
  7641. var self = this, name = 'media', lang = self.lang(name + '.'),
  7642. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7643. allowFileManager = K.undef(self.allowFileManager, false),
  7644. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7645. extraParams = K.undef(self.extraFileUploadParams, {}),
  7646. filePostName = K.undef(self.filePostName, 'imgFile'),
  7647. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7648. self.plugin.media = {
  7649. edit : function() {
  7650. var html = [
  7651. '<div style="padding:20px;">',
  7652. //url
  7653. '<div class="ke-dialog-row">',
  7654. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7655. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7656. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7657. '<span class="ke-button-common ke-button-outer">',
  7658. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7659. '</span>',
  7660. '</div>',
  7661. //width
  7662. '<div class="ke-dialog-row">',
  7663. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7664. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7665. '</div>',
  7666. //height
  7667. '<div class="ke-dialog-row">',
  7668. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7669. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7670. '</div>',
  7671. //autostart
  7672. '<div class="ke-dialog-row">',
  7673. '<label for="keAutostart">' + lang.autostart + '</label>',
  7674. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7675. '</div>',
  7676. '</div>'
  7677. ].join('');
  7678. var dialog = self.createDialog({
  7679. name : name,
  7680. width : 450,
  7681. height : 230,
  7682. title : self.lang(name),
  7683. body : html,
  7684. yesBtn : {
  7685. name : self.lang('yes'),
  7686. click : function(e) {
  7687. var url = K.trim(urlBox.val()),
  7688. width = widthBox.val(),
  7689. height = heightBox.val();
  7690. if (url == 'http://' || K.invalidUrl(url)) {
  7691. alert(self.lang('invalidUrl'));
  7692. urlBox[0].focus();
  7693. return;
  7694. }
  7695. if (!/^\d*$/.test(width)) {
  7696. alert(self.lang('invalidWidth'));
  7697. widthBox[0].focus();
  7698. return;
  7699. }
  7700. if (!/^\d*$/.test(height)) {
  7701. alert(self.lang('invalidHeight'));
  7702. heightBox[0].focus();
  7703. return;
  7704. }
  7705. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7706. src : url,
  7707. type : K.mediaType(url),
  7708. width : width,
  7709. height : height,
  7710. autostart : autostartBox[0].checked ? 'true' : 'false',
  7711. loop : 'true'
  7712. });
  7713. self.insertHtml(html).hideDialog().focus();
  7714. }
  7715. }
  7716. }),
  7717. div = dialog.div,
  7718. urlBox = K('[name="url"]', div),
  7719. viewServerBtn = K('[name="viewServer"]', div),
  7720. widthBox = K('[name="width"]', div),
  7721. heightBox = K('[name="height"]', div),
  7722. autostartBox = K('[name="autostart"]', div);
  7723. urlBox.val('http://');
  7724. if (allowMediaUpload) {
  7725. var uploadbutton = K.uploadbutton({
  7726. button : K('.ke-upload-button', div)[0],
  7727. fieldName : filePostName,
  7728. extraParams : extraParams,
  7729. url : K.addParam(uploadJson, 'dir=media'),
  7730. afterUpload : function(data) {
  7731. dialog.hideLoading();
  7732. if (data.error === 0) {
  7733. var url = data.url;
  7734. if (formatUploadUrl) {
  7735. url = K.formatUrl(url, 'absolute');
  7736. }
  7737. urlBox.val(url);
  7738. if (self.afterUpload) {
  7739. self.afterUpload.call(self, url, data, name);
  7740. }
  7741. alert(self.lang('uploadSuccess'));
  7742. } else {
  7743. alert(data.message);
  7744. }
  7745. },
  7746. afterError : function(html) {
  7747. dialog.hideLoading();
  7748. self.errorDialog(html);
  7749. }
  7750. });
  7751. uploadbutton.fileBox.change(function(e) {
  7752. dialog.showLoading(self.lang('uploadLoading'));
  7753. uploadbutton.submit();
  7754. });
  7755. } else {
  7756. K('.ke-upload-button', div).hide();
  7757. }
  7758. if (allowFileManager) {
  7759. viewServerBtn.click(function(e) {
  7760. self.loadPlugin('filemanager', function() {
  7761. self.plugin.filemanagerDialog({
  7762. viewType : 'LIST',
  7763. dirName : 'media',
  7764. clickFn : function(url, title) {
  7765. if (self.dialogs.length > 1) {
  7766. K('[name="url"]', div).val(url);
  7767. if (self.afterSelectFile) {
  7768. self.afterSelectFile.call(self, url);
  7769. }
  7770. self.hideDialog();
  7771. }
  7772. }
  7773. });
  7774. });
  7775. });
  7776. } else {
  7777. viewServerBtn.hide();
  7778. }
  7779. var img = self.plugin.getSelectedMedia();
  7780. if (img) {
  7781. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7782. urlBox.val(attrs.src);
  7783. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7784. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7785. autostartBox[0].checked = (attrs.autostart === 'true');
  7786. }
  7787. urlBox[0].focus();
  7788. urlBox[0].select();
  7789. },
  7790. 'delete' : function() {
  7791. self.plugin.getSelectedMedia().remove();
  7792. // [IE] 删除图片后立即点击图片按钮出错
  7793. self.addBookmark();
  7794. }
  7795. };
  7796. self.clickToolbar(name, self.plugin.media.edit);
  7797. });
  7798. /*******************************************************************************
  7799. * KindEditor - WYSIWYG HTML Editor for Internet
  7800. * Copyright (C) 2006-2011 kindsoft.net
  7801. *
  7802. * @author Roddy <luolonghao@gmail.com>
  7803. * @site http://www.kindsoft.net/
  7804. * @licence http://www.kindsoft.net/license.php
  7805. *******************************************************************************/
  7806. (function(K) {
  7807. function KSWFUpload(options) {
  7808. this.init(options);
  7809. }
  7810. K.extend(KSWFUpload, {
  7811. init : function(options) {
  7812. var self = this;
  7813. options.afterError = options.afterError || function(str) {
  7814. alert(str);
  7815. };
  7816. self.options = options;
  7817. self.progressbars = {};
  7818. // template
  7819. self.div = K(options.container).html([
  7820. '<div class="ke-swfupload">',
  7821. '<div class="ke-swfupload-top">',
  7822. '<div class="ke-inline-block ke-swfupload-button">',
  7823. '<input type="button" value="Browse" />',
  7824. '</div>',
  7825. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7826. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7827. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7828. '</span>',
  7829. '</div>',
  7830. '<div class="ke-swfupload-body"></div>',
  7831. '</div>'
  7832. ].join(''));
  7833. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7834. function showError(itemDiv, msg) {
  7835. K('.ke-status > div', itemDiv).hide();
  7836. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7837. }
  7838. var settings = {
  7839. debug : false,
  7840. upload_url : options.uploadUrl,
  7841. flash_url : options.flashUrl,
  7842. file_post_name : options.filePostName,
  7843. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7844. button_image_url: options.buttonImageUrl,
  7845. button_width: options.buttonWidth,
  7846. button_height: options.buttonHeight,
  7847. button_cursor : SWFUpload.CURSOR.HAND,
  7848. file_types : options.fileTypes,
  7849. file_types_description : options.fileTypesDesc,
  7850. file_upload_limit : options.fileUploadLimit,
  7851. file_size_limit : options.fileSizeLimit,
  7852. post_params : options.postParams,
  7853. file_queued_handler : function(file) {
  7854. file.url = self.options.fileIconUrl;
  7855. self.appendFile(file);
  7856. },
  7857. file_queue_error_handler : function(file, errorCode, message) {
  7858. var errorName = '';
  7859. switch (errorCode) {
  7860. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7861. errorName = options.queueLimitExceeded;
  7862. break;
  7863. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7864. errorName = options.fileExceedsSizeLimit;
  7865. break;
  7866. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7867. errorName = options.zeroByteFile;
  7868. break;
  7869. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7870. errorName = options.invalidFiletype;
  7871. break;
  7872. default:
  7873. errorName = options.unknownError;
  7874. break;
  7875. }
  7876. K.DEBUG && alert(errorName);
  7877. },
  7878. upload_start_handler : function(file) {
  7879. var self = this;
  7880. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7881. K('.ke-status > div', itemDiv).hide();
  7882. K('.ke-progressbar', itemDiv).show();
  7883. },
  7884. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7885. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7886. var progressbar = self.progressbars[file.id];
  7887. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7888. progressbar.percent.html(percent + '%');
  7889. },
  7890. upload_error_handler : function(file, errorCode, message) {
  7891. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7892. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7893. showError(itemDiv, self.options.errorMessage);
  7894. }
  7895. },
  7896. upload_success_handler : function(file, serverData) {
  7897. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7898. var data = {};
  7899. try {
  7900. data = K.json(serverData);
  7901. } catch (e) {
  7902. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7903. }
  7904. if (data.error !== 0) {
  7905. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7906. return;
  7907. }
  7908. file.url = data.url;
  7909. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7910. K('.ke-status > div', itemDiv).hide();
  7911. }
  7912. };
  7913. self.swfu = new SWFUpload(settings);
  7914. K('.ke-swfupload-startupload input', self.div).click(function() {
  7915. self.swfu.startUpload();
  7916. });
  7917. },
  7918. getUrlList : function() {
  7919. var list = [];
  7920. K('.ke-img', self.bodyDiv).each(function() {
  7921. var img = K(this);
  7922. var status = img.attr('data-status');
  7923. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7924. list.push(img.data('data'));
  7925. }
  7926. });
  7927. return list;
  7928. },
  7929. removeFile : function(fileId) {
  7930. var self = this;
  7931. self.swfu.cancelUpload(fileId);
  7932. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7933. K('.ke-photo', itemDiv).unbind();
  7934. K('.ke-delete', itemDiv).unbind();
  7935. itemDiv.remove();
  7936. },
  7937. removeFiles : function() {
  7938. var self = this;
  7939. K('.ke-item', self.bodyDiv).each(function() {
  7940. self.removeFile(K(this).attr('data-id'));
  7941. });
  7942. },
  7943. appendFile : function(file) {
  7944. var self = this;
  7945. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7946. self.bodyDiv.append(itemDiv);
  7947. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7948. .mouseover(function(e) {
  7949. K(this).addClass('ke-on');
  7950. })
  7951. .mouseout(function(e) {
  7952. K(this).removeClass('ke-on');
  7953. });
  7954. itemDiv.append(photoDiv);
  7955. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7956. photoDiv.append(img);
  7957. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  7958. self.removeFile(file.id);
  7959. });
  7960. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7961. // progressbar
  7962. K(['<div class="ke-progressbar">',
  7963. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7964. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7965. // message
  7966. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7967. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7968. self.progressbars[file.id] = {
  7969. bar : K('.ke-progressbar-bar-inner', photoDiv),
  7970. percent : K('.ke-progressbar-percent', photoDiv)
  7971. };
  7972. },
  7973. remove : function() {
  7974. this.removeFiles();
  7975. this.swfu.destroy();
  7976. this.div.html('');
  7977. }
  7978. });
  7979. K.swfupload = function(element, options) {
  7980. return new KSWFUpload(element, options);
  7981. };
  7982. })(KindEditor);
  7983. KindEditor.plugin('multiimage', function(K) {
  7984. var self = this, name = 'multiimage',
  7985. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7986. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7987. imgPath = self.pluginsPath + 'multiimage/images/',
  7988. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  7989. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  7990. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  7991. filePostName = K.undef(self.filePostName, 'imgFile'),
  7992. lang = self.lang(name + '.');
  7993. self.plugin.multiImageDialog = function(options) {
  7994. var clickFn = options.clickFn,
  7995. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  7996. var html = [
  7997. '<div style="padding:20px;">',
  7998. '<div class="swfupload">',
  7999. '</div>',
  8000. '</div>'
  8001. ].join('');
  8002. var dialog = self.createDialog({
  8003. name : name,
  8004. width : 650,
  8005. height : 510,
  8006. title : self.lang(name),
  8007. body : html,
  8008. previewBtn : {
  8009. name : lang.insertAll,
  8010. click : function(e) {
  8011. clickFn.call(self, swfupload.getUrlList());
  8012. }
  8013. },
  8014. yesBtn : {
  8015. name : lang.clearAll,
  8016. click : function(e) {
  8017. swfupload.removeFiles();
  8018. }
  8019. },
  8020. beforeRemove : function() {
  8021. // IE9 bugfix: https://github.com/kindsoft/kindeditor/issues/72
  8022. if (!K.IE || K.V <= 8) {
  8023. swfupload.remove();
  8024. }
  8025. }
  8026. }),
  8027. div = dialog.div;
  8028. var swfupload = K.swfupload({
  8029. container : K('.swfupload', div),
  8030. buttonImageUrl : imgPath + (self.langType == 'zh_CN' ? 'select-files-zh_CN.png' : 'select-files-en.png'),
  8031. buttonWidth : self.langType == 'zh_CN' ? 72 : 88,
  8032. buttonHeight : 23,
  8033. fileIconUrl : imgPath + 'image.png',
  8034. uploadDesc : uploadDesc,
  8035. startButtonValue : lang.startUpload,
  8036. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8037. flashUrl : imgPath + 'swfupload.swf',
  8038. filePostName : filePostName,
  8039. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8040. fileTypesDesc : 'Image Files',
  8041. fileUploadLimit : imageUploadLimit,
  8042. fileSizeLimit : imageSizeLimit,
  8043. postParams : K.undef(self.extraFileUploadParams, {}),
  8044. queueLimitExceeded : lang.queueLimitExceeded,
  8045. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8046. zeroByteFile : lang.zeroByteFile,
  8047. invalidFiletype : lang.invalidFiletype,
  8048. unknownError : lang.unknownError,
  8049. pendingMessage : lang.pending,
  8050. errorMessage : lang.uploadError,
  8051. afterError : function(html) {
  8052. self.errorDialog(html);
  8053. }
  8054. });
  8055. return dialog;
  8056. };
  8057. self.clickToolbar(name, function() {
  8058. self.plugin.multiImageDialog({
  8059. clickFn : function (urlList) {
  8060. if (urlList.length === 0) {
  8061. return;
  8062. }
  8063. K.each(urlList, function(i, data) {
  8064. if (self.afterUpload) {
  8065. self.afterUpload.call(self, data.url, data, 'multiimage');
  8066. }
  8067. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8068. });
  8069. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  8070. setTimeout(function() {
  8071. self.hideDialog().focus();
  8072. }, 0);
  8073. }
  8074. });
  8075. });
  8076. });
  8077. /**
  8078. * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
  8079. *
  8080. * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
  8081. *
  8082. * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz閚 and Mammon Media and is released under the MIT License:
  8083. * http://www.opensource.org/licenses/mit-license.php
  8084. *
  8085. * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
  8086. * http://www.opensource.org/licenses/mit-license.php
  8087. *
  8088. */
  8089. /* ******************* */
  8090. /* Constructor & Init */
  8091. /* ******************* */
  8092. (function() {
  8093. window.SWFUpload = function (settings) {
  8094. this.initSWFUpload(settings);
  8095. };
  8096. SWFUpload.prototype.initSWFUpload = function (settings) {
  8097. try {
  8098. this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
  8099. this.settings = settings;
  8100. this.eventQueue = [];
  8101. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8102. this.movieElement = null;
  8103. // Setup global control tracking
  8104. SWFUpload.instances[this.movieName] = this;
  8105. // Load the settings. Load the Flash movie.
  8106. this.initSettings();
  8107. this.loadFlash();
  8108. this.displayDebugInfo();
  8109. } catch (ex) {
  8110. delete SWFUpload.instances[this.movieName];
  8111. throw ex;
  8112. }
  8113. };
  8114. /* *************** */
  8115. /* Static Members */
  8116. /* *************** */
  8117. SWFUpload.instances = {};
  8118. SWFUpload.movieCount = 0;
  8119. SWFUpload.version = "2.2.0 2009-03-25";
  8120. SWFUpload.QUEUE_ERROR = {
  8121. QUEUE_LIMIT_EXCEEDED : -100,
  8122. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8123. ZERO_BYTE_FILE : -120,
  8124. INVALID_FILETYPE : -130
  8125. };
  8126. SWFUpload.UPLOAD_ERROR = {
  8127. HTTP_ERROR : -200,
  8128. MISSING_UPLOAD_URL : -210,
  8129. IO_ERROR : -220,
  8130. SECURITY_ERROR : -230,
  8131. UPLOAD_LIMIT_EXCEEDED : -240,
  8132. UPLOAD_FAILED : -250,
  8133. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8134. FILE_VALIDATION_FAILED : -270,
  8135. FILE_CANCELLED : -280,
  8136. UPLOAD_STOPPED : -290
  8137. };
  8138. SWFUpload.FILE_STATUS = {
  8139. QUEUED : -1,
  8140. IN_PROGRESS : -2,
  8141. ERROR : -3,
  8142. COMPLETE : -4,
  8143. CANCELLED : -5
  8144. };
  8145. SWFUpload.BUTTON_ACTION = {
  8146. SELECT_FILE : -100,
  8147. SELECT_FILES : -110,
  8148. START_UPLOAD : -120
  8149. };
  8150. SWFUpload.CURSOR = {
  8151. ARROW : -1,
  8152. HAND : -2
  8153. };
  8154. SWFUpload.WINDOW_MODE = {
  8155. WINDOW : "window",
  8156. TRANSPARENT : "transparent",
  8157. OPAQUE : "opaque"
  8158. };
  8159. // Private: takes a URL, determines if it is relative and converts to an absolute URL
  8160. // using the current site. Only processes the URL if it can, otherwise returns the URL untouched
  8161. SWFUpload.completeURL = function(url) {
  8162. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8163. return url;
  8164. }
  8165. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8166. var indexSlash = window.location.pathname.lastIndexOf("/");
  8167. if (indexSlash <= 0) {
  8168. path = "/";
  8169. } else {
  8170. path = window.location.pathname.substr(0, indexSlash) + "/";
  8171. }
  8172. return /*currentURL +*/ path + url;
  8173. };
  8174. /* ******************** */
  8175. /* Instance Members */
  8176. /* ******************** */
  8177. // Private: initSettings ensures that all the
  8178. // settings are set, getting a default value if one was not assigned.
  8179. SWFUpload.prototype.initSettings = function () {
  8180. this.ensureDefault = function (settingName, defaultValue) {
  8181. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8182. };
  8183. // Upload backend settings
  8184. this.ensureDefault("upload_url", "");
  8185. this.ensureDefault("preserve_relative_urls", false);
  8186. this.ensureDefault("file_post_name", "Filedata");
  8187. this.ensureDefault("post_params", {});
  8188. this.ensureDefault("use_query_string", false);
  8189. this.ensureDefault("requeue_on_error", false);
  8190. this.ensureDefault("http_success", []);
  8191. this.ensureDefault("assume_success_timeout", 0);
  8192. // File Settings
  8193. this.ensureDefault("file_types", "*.*");
  8194. this.ensureDefault("file_types_description", "All Files");
  8195. this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
  8196. this.ensureDefault("file_upload_limit", 0);
  8197. this.ensureDefault("file_queue_limit", 0);
  8198. // Flash Settings
  8199. this.ensureDefault("flash_url", "swfupload.swf");
  8200. this.ensureDefault("prevent_swf_caching", true);
  8201. // Button Settings
  8202. this.ensureDefault("button_image_url", "");
  8203. this.ensureDefault("button_width", 1);
  8204. this.ensureDefault("button_height", 1);
  8205. this.ensureDefault("button_text", "");
  8206. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8207. this.ensureDefault("button_text_top_padding", 0);
  8208. this.ensureDefault("button_text_left_padding", 0);
  8209. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8210. this.ensureDefault("button_disabled", false);
  8211. this.ensureDefault("button_placeholder_id", "");
  8212. this.ensureDefault("button_placeholder", null);
  8213. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8214. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8215. // Debug Settings
  8216. this.ensureDefault("debug", false);
  8217. this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
  8218. // Event Handlers
  8219. this.settings.return_upload_start_handler = this.returnUploadStart;
  8220. this.ensureDefault("swfupload_loaded_handler", null);
  8221. this.ensureDefault("file_dialog_start_handler", null);
  8222. this.ensureDefault("file_queued_handler", null);
  8223. this.ensureDefault("file_queue_error_handler", null);
  8224. this.ensureDefault("file_dialog_complete_handler", null);
  8225. this.ensureDefault("upload_start_handler", null);
  8226. this.ensureDefault("upload_progress_handler", null);
  8227. this.ensureDefault("upload_error_handler", null);
  8228. this.ensureDefault("upload_success_handler", null);
  8229. this.ensureDefault("upload_complete_handler", null);
  8230. this.ensureDefault("debug_handler", this.debugMessage);
  8231. this.ensureDefault("custom_settings", {});
  8232. // Other settings
  8233. this.customSettings = this.settings.custom_settings;
  8234. // Update the flash url if needed
  8235. if (!!this.settings.prevent_swf_caching) {
  8236. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8237. }
  8238. if (!this.settings.preserve_relative_urls) {
  8239. //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it
  8240. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8241. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8242. }
  8243. delete this.ensureDefault;
  8244. };
  8245. // Private: loadFlash replaces the button_placeholder element with the flash movie.
  8246. SWFUpload.prototype.loadFlash = function () {
  8247. var targetElement, tempParent;
  8248. // Make sure an element with the ID we are going to use doesn't already exist
  8249. if (document.getElementById(this.movieName) !== null) {
  8250. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8251. }
  8252. // Get the element where we will be placing the flash movie
  8253. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8254. if (targetElement == undefined) {
  8255. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8256. }
  8257. // Append the container and load the flash
  8258. tempParent = document.createElement("div");
  8259. tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
  8260. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8261. // Fix IE Flash/Form bug
  8262. if (window[this.movieName] == undefined) {
  8263. window[this.movieName] = this.getMovieElement();
  8264. }
  8265. };
  8266. // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
  8267. SWFUpload.prototype.getFlashHTML = function () {
  8268. // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  8269. // Fix bug for IE9
  8270. // http://www.kindsoft.net/view.php?bbsid=7&postid=5825&pagenum=1
  8271. var classid = '';
  8272. if (KindEditor.IE && KindEditor.V > 8) {
  8273. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8274. }
  8275. 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">',
  8276. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8277. '<param name="movie" value="', this.settings.flash_url, '" />',
  8278. '<param name="quality" value="high" />',
  8279. '<param name="menu" value="false" />',
  8280. '<param name="allowScriptAccess" value="always" />',
  8281. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8282. '</object>'].join("");
  8283. };
  8284. // Private: getFlashVars builds the parameter string that will be passed
  8285. // to flash in the flashvars param.
  8286. SWFUpload.prototype.getFlashVars = function () {
  8287. // Build a string from the post param object
  8288. var paramString = this.buildParamString();
  8289. var httpSuccessString = this.settings.http_success.join(",");
  8290. // Build the parameter string
  8291. return ["movieName=", encodeURIComponent(this.movieName),
  8292. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8293. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8294. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8295. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8296. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8297. "&amp;params=", encodeURIComponent(paramString),
  8298. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8299. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8300. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8301. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8302. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8303. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8304. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8305. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8306. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8307. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8308. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8309. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8310. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8311. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8312. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8313. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8314. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8315. ].join("");
  8316. };
  8317. // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
  8318. // The element is cached after the first lookup
  8319. SWFUpload.prototype.getMovieElement = function () {
  8320. if (this.movieElement == undefined) {
  8321. this.movieElement = document.getElementById(this.movieName);
  8322. }
  8323. if (this.movieElement === null) {
  8324. throw "Could not find Flash element";
  8325. }
  8326. return this.movieElement;
  8327. };
  8328. // Private: buildParamString takes the name/value pairs in the post_params setting object
  8329. // and joins them up in to a string formatted "name=value&amp;name=value"
  8330. SWFUpload.prototype.buildParamString = function () {
  8331. var postParams = this.settings.post_params;
  8332. var paramStringPairs = [];
  8333. if (typeof(postParams) === "object") {
  8334. for (var name in postParams) {
  8335. if (postParams.hasOwnProperty(name)) {
  8336. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8337. }
  8338. }
  8339. }
  8340. return paramStringPairs.join("&amp;");
  8341. };
  8342. // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
  8343. // all references to the SWF, and other objects so memory is properly freed.
  8344. // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
  8345. // Credits: Major improvements provided by steffen
  8346. SWFUpload.prototype.destroy = function () {
  8347. try {
  8348. // Make sure Flash is done before we try to remove it
  8349. this.cancelUpload(null, false);
  8350. // Remove the SWFUpload DOM nodes
  8351. var movieElement = null;
  8352. movieElement = this.getMovieElement();
  8353. if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8354. // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
  8355. for (var i in movieElement) {
  8356. try {
  8357. if (typeof(movieElement[i]) === "function") {
  8358. movieElement[i] = null;
  8359. }
  8360. } catch (ex1) {}
  8361. }
  8362. // Remove the Movie Element from the page
  8363. try {
  8364. movieElement.parentNode.removeChild(movieElement);
  8365. } catch (ex) {}
  8366. }
  8367. // Remove IE form fix reference
  8368. window[this.movieName] = null;
  8369. // Destroy other references
  8370. SWFUpload.instances[this.movieName] = null;
  8371. delete SWFUpload.instances[this.movieName];
  8372. this.movieElement = null;
  8373. this.settings = null;
  8374. this.customSettings = null;
  8375. this.eventQueue = null;
  8376. this.movieName = null;
  8377. return true;
  8378. } catch (ex2) {
  8379. return false;
  8380. }
  8381. };
  8382. // Public: displayDebugInfo prints out settings and configuration
  8383. // information about this SWFUpload instance.
  8384. // This function (and any references to it) can be deleted when placing
  8385. // SWFUpload in production.
  8386. SWFUpload.prototype.displayDebugInfo = function () {
  8387. this.debug(
  8388. [
  8389. "---SWFUpload Instance Info---\n",
  8390. "Version: ", SWFUpload.version, "\n",
  8391. "Movie Name: ", this.movieName, "\n",
  8392. "Settings:\n",
  8393. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8394. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8395. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8396. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8397. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8398. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8399. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8400. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8401. "\t", "file_types: ", this.settings.file_types, "\n",
  8402. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8403. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8404. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8405. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8406. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8407. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8408. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8409. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8410. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8411. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8412. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8413. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8414. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8415. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8416. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8417. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8418. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8419. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8420. "Event Handlers:\n",
  8421. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8422. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8423. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8424. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8425. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8426. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8427. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8428. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8429. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8430. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8431. ].join("")
  8432. );
  8433. };
  8434. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8435. the maintain v2 API compatibility
  8436. */
  8437. // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
  8438. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8439. if (value == undefined) {
  8440. return (this.settings[name] = default_value);
  8441. } else {
  8442. return (this.settings[name] = value);
  8443. }
  8444. };
  8445. // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
  8446. SWFUpload.prototype.getSetting = function (name) {
  8447. if (this.settings[name] != undefined) {
  8448. return this.settings[name];
  8449. }
  8450. return "";
  8451. };
  8452. // Private: callFlash handles function calls made to the Flash element.
  8453. // Calls are made with a setTimeout for some functions to work around
  8454. // bugs in the ExternalInterface library.
  8455. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8456. argumentArray = argumentArray || [];
  8457. var movieElement = this.getMovieElement();
  8458. var returnValue, returnString;
  8459. // Flash's method if calling ExternalInterface methods (code adapted from MooTools).
  8460. try {
  8461. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8462. returnValue = eval(returnString);
  8463. } catch (ex) {
  8464. throw "Call to " + functionName + " failed";
  8465. }
  8466. // Unescape file post param values
  8467. if (returnValue != undefined && typeof returnValue.post === "object") {
  8468. returnValue = this.unescapeFilePostParams(returnValue);
  8469. }
  8470. return returnValue;
  8471. };
  8472. /* *****************************
  8473. -- Flash control methods --
  8474. Your UI should use these
  8475. to operate SWFUpload
  8476. ***************************** */
  8477. // WARNING: this function does not work in Flash Player 10
  8478. // Public: selectFile causes a File Selection Dialog window to appear. This
  8479. // dialog only allows 1 file to be selected.
  8480. SWFUpload.prototype.selectFile = function () {
  8481. this.callFlash("SelectFile");
  8482. };
  8483. // WARNING: this function does not work in Flash Player 10
  8484. // Public: selectFiles causes a File Selection Dialog window to appear/ This
  8485. // dialog allows the user to select any number of files
  8486. // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
  8487. // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
  8488. // for this bug.
  8489. SWFUpload.prototype.selectFiles = function () {
  8490. this.callFlash("SelectFiles");
  8491. };
  8492. // Public: startUpload starts uploading the first file in the queue unless
  8493. // the optional parameter 'fileID' specifies the ID
  8494. SWFUpload.prototype.startUpload = function (fileID) {
  8495. this.callFlash("StartUpload", [fileID]);
  8496. };
  8497. // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
  8498. // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
  8499. // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
  8500. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8501. if (triggerErrorEvent !== false) {
  8502. triggerErrorEvent = true;
  8503. }
  8504. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8505. };
  8506. // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
  8507. // If nothing is currently uploading then nothing happens.
  8508. SWFUpload.prototype.stopUpload = function () {
  8509. this.callFlash("StopUpload");
  8510. };
  8511. /* ************************
  8512. * Settings methods
  8513. * These methods change the SWFUpload settings.
  8514. * SWFUpload settings should not be changed directly on the settings object
  8515. * since many of the settings need to be passed to Flash in order to take
  8516. * effect.
  8517. * *********************** */
  8518. // Public: getStats gets the file statistics object.
  8519. SWFUpload.prototype.getStats = function () {
  8520. return this.callFlash("GetStats");
  8521. };
  8522. // Public: setStats changes the SWFUpload statistics. You shouldn't need to
  8523. // change the statistics but you can. Changing the statistics does not
  8524. // affect SWFUpload accept for the successful_uploads count which is used
  8525. // by the upload_limit setting to determine how many files the user may upload.
  8526. SWFUpload.prototype.setStats = function (statsObject) {
  8527. this.callFlash("SetStats", [statsObject]);
  8528. };
  8529. // Public: getFile retrieves a File object by ID or Index. If the file is
  8530. // not found then 'null' is returned.
  8531. SWFUpload.prototype.getFile = function (fileID) {
  8532. if (typeof(fileID) === "number") {
  8533. return this.callFlash("GetFileByIndex", [fileID]);
  8534. } else {
  8535. return this.callFlash("GetFile", [fileID]);
  8536. }
  8537. };
  8538. // Public: addFileParam sets a name/value pair that will be posted with the
  8539. // file specified by the Files ID. If the name already exists then the
  8540. // exiting value will be overwritten.
  8541. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8542. return this.callFlash("AddFileParam", [fileID, name, value]);
  8543. };
  8544. // Public: removeFileParam removes a previously set (by addFileParam) name/value
  8545. // pair from the specified file.
  8546. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8547. this.callFlash("RemoveFileParam", [fileID, name]);
  8548. };
  8549. // Public: setUploadUrl changes the upload_url setting.
  8550. SWFUpload.prototype.setUploadURL = function (url) {
  8551. this.settings.upload_url = url.toString();
  8552. this.callFlash("SetUploadURL", [url]);
  8553. };
  8554. // Public: setPostParams changes the post_params setting
  8555. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8556. this.settings.post_params = paramsObject;
  8557. this.callFlash("SetPostParams", [paramsObject]);
  8558. };
  8559. // Public: addPostParam adds post name/value pair. Each name can have only one value.
  8560. SWFUpload.prototype.addPostParam = function (name, value) {
  8561. this.settings.post_params[name] = value;
  8562. this.callFlash("SetPostParams", [this.settings.post_params]);
  8563. };
  8564. // Public: removePostParam deletes post name/value pair.
  8565. SWFUpload.prototype.removePostParam = function (name) {
  8566. delete this.settings.post_params[name];
  8567. this.callFlash("SetPostParams", [this.settings.post_params]);
  8568. };
  8569. // Public: setFileTypes changes the file_types setting and the file_types_description setting
  8570. SWFUpload.prototype.setFileTypes = function (types, description) {
  8571. this.settings.file_types = types;
  8572. this.settings.file_types_description = description;
  8573. this.callFlash("SetFileTypes", [types, description]);
  8574. };
  8575. // Public: setFileSizeLimit changes the file_size_limit setting
  8576. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8577. this.settings.file_size_limit = fileSizeLimit;
  8578. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8579. };
  8580. // Public: setFileUploadLimit changes the file_upload_limit setting
  8581. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8582. this.settings.file_upload_limit = fileUploadLimit;
  8583. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8584. };
  8585. // Public: setFileQueueLimit changes the file_queue_limit setting
  8586. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8587. this.settings.file_queue_limit = fileQueueLimit;
  8588. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8589. };
  8590. // Public: setFilePostName changes the file_post_name setting
  8591. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8592. this.settings.file_post_name = filePostName;
  8593. this.callFlash("SetFilePostName", [filePostName]);
  8594. };
  8595. // Public: setUseQueryString changes the use_query_string setting
  8596. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8597. this.settings.use_query_string = useQueryString;
  8598. this.callFlash("SetUseQueryString", [useQueryString]);
  8599. };
  8600. // Public: setRequeueOnError changes the requeue_on_error setting
  8601. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8602. this.settings.requeue_on_error = requeueOnError;
  8603. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8604. };
  8605. // Public: setHTTPSuccess changes the http_success setting
  8606. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8607. if (typeof http_status_codes === "string") {
  8608. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8609. }
  8610. this.settings.http_success = http_status_codes;
  8611. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8612. };
  8613. // Public: setHTTPSuccess changes the http_success setting
  8614. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8615. this.settings.assume_success_timeout = timeout_seconds;
  8616. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8617. };
  8618. // Public: setDebugEnabled changes the debug_enabled setting
  8619. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8620. this.settings.debug_enabled = debugEnabled;
  8621. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8622. };
  8623. // Public: setButtonImageURL loads a button image sprite
  8624. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8625. if (buttonImageURL == undefined) {
  8626. buttonImageURL = "";
  8627. }
  8628. this.settings.button_image_url = buttonImageURL;
  8629. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8630. };
  8631. // Public: setButtonDimensions resizes the Flash Movie and button
  8632. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8633. this.settings.button_width = width;
  8634. this.settings.button_height = height;
  8635. var movie = this.getMovieElement();
  8636. if (movie != undefined) {
  8637. movie.style.width = width + "px";
  8638. movie.style.height = height + "px";
  8639. }
  8640. this.callFlash("SetButtonDimensions", [width, height]);
  8641. };
  8642. // Public: setButtonText Changes the text overlaid on the button
  8643. SWFUpload.prototype.setButtonText = function (html) {
  8644. this.settings.button_text = html;
  8645. this.callFlash("SetButtonText", [html]);
  8646. };
  8647. // Public: setButtonTextPadding changes the top and left padding of the text overlay
  8648. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8649. this.settings.button_text_top_padding = top;
  8650. this.settings.button_text_left_padding = left;
  8651. this.callFlash("SetButtonTextPadding", [left, top]);
  8652. };
  8653. // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
  8654. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8655. this.settings.button_text_style = css;
  8656. this.callFlash("SetButtonTextStyle", [css]);
  8657. };
  8658. // Public: setButtonDisabled disables/enables the button
  8659. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8660. this.settings.button_disabled = isDisabled;
  8661. this.callFlash("SetButtonDisabled", [isDisabled]);
  8662. };
  8663. // Public: setButtonAction sets the action that occurs when the button is clicked
  8664. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8665. this.settings.button_action = buttonAction;
  8666. this.callFlash("SetButtonAction", [buttonAction]);
  8667. };
  8668. // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
  8669. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8670. this.settings.button_cursor = cursor;
  8671. this.callFlash("SetButtonCursor", [cursor]);
  8672. };
  8673. /* *******************************
  8674. Flash Event Interfaces
  8675. These functions are used by Flash to trigger the various
  8676. events.
  8677. All these functions a Private.
  8678. Because the ExternalInterface library is buggy the event calls
  8679. are added to a queue and the queue then executed by a setTimeout.
  8680. This ensures that events are executed in a determinate order and that
  8681. the ExternalInterface bugs are avoided.
  8682. ******************************* */
  8683. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8684. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8685. if (argumentArray == undefined) {
  8686. argumentArray = [];
  8687. } else if (!(argumentArray instanceof Array)) {
  8688. argumentArray = [argumentArray];
  8689. }
  8690. var self = this;
  8691. if (typeof this.settings[handlerName] === "function") {
  8692. // Queue the event
  8693. this.eventQueue.push(function () {
  8694. this.settings[handlerName].apply(this, argumentArray);
  8695. });
  8696. // Execute the next queued event
  8697. setTimeout(function () {
  8698. self.executeNextEvent();
  8699. }, 0);
  8700. } else if (this.settings[handlerName] !== null) {
  8701. throw "Event handler " + handlerName + " is unknown or is not a function";
  8702. }
  8703. };
  8704. // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
  8705. // we must queue them in order to garentee that they are executed in order.
  8706. SWFUpload.prototype.executeNextEvent = function () {
  8707. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  8708. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8709. if (typeof(f) === "function") {
  8710. f.apply(this);
  8711. }
  8712. };
  8713. // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
  8714. // properties that contain characters that are not valid for JavaScript identifiers. To work around this
  8715. // the Flash Component escapes the parameter names and we must unescape again before passing them along.
  8716. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8717. var reg = /[$]([0-9a-f]{4})/i;
  8718. var unescapedPost = {};
  8719. var uk;
  8720. if (file != undefined) {
  8721. for (var k in file.post) {
  8722. if (file.post.hasOwnProperty(k)) {
  8723. uk = k;
  8724. var match;
  8725. while ((match = reg.exec(uk)) !== null) {
  8726. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8727. }
  8728. unescapedPost[uk] = file.post[k];
  8729. }
  8730. }
  8731. file.post = unescapedPost;
  8732. }
  8733. return file;
  8734. };
  8735. // Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working)
  8736. SWFUpload.prototype.testExternalInterface = function () {
  8737. try {
  8738. return this.callFlash("TestExternalInterface");
  8739. } catch (ex) {
  8740. return false;
  8741. }
  8742. };
  8743. // Private: This event is called by Flash when it has finished loading. Don't modify this.
  8744. // Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded.
  8745. SWFUpload.prototype.flashReady = function () {
  8746. // Check that the movie element is loaded correctly with its ExternalInterface methods defined
  8747. var movieElement = this.getMovieElement();
  8748. if (!movieElement) {
  8749. this.debug("Flash called back ready but the flash movie can't be found.");
  8750. return;
  8751. }
  8752. this.cleanUp(movieElement);
  8753. this.queueEvent("swfupload_loaded_handler");
  8754. };
  8755. // Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
  8756. // This function is called by Flash each time the ExternalInterface functions are created.
  8757. SWFUpload.prototype.cleanUp = function (movieElement) {
  8758. // Pro-actively unhook all the Flash functions
  8759. try {
  8760. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  8761. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8762. for (var key in movieElement) {
  8763. try {
  8764. if (typeof(movieElement[key]) === "function") {
  8765. movieElement[key] = null;
  8766. }
  8767. } catch (ex) {
  8768. }
  8769. }
  8770. }
  8771. } catch (ex1) {
  8772. }
  8773. // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
  8774. // it doesn't display errors.
  8775. window["__flash__removeCallback"] = function (instance, name) {
  8776. try {
  8777. if (instance) {
  8778. instance[name] = null;
  8779. }
  8780. } catch (flashEx) {
  8781. }
  8782. };
  8783. };
  8784. /* This is a chance to do something before the browse window opens */
  8785. SWFUpload.prototype.fileDialogStart = function () {
  8786. this.queueEvent("file_dialog_start_handler");
  8787. };
  8788. /* Called when a file is successfully added to the queue. */
  8789. SWFUpload.prototype.fileQueued = function (file) {
  8790. file = this.unescapeFilePostParams(file);
  8791. this.queueEvent("file_queued_handler", file);
  8792. };
  8793. /* Handle errors that occur when an attempt to queue a file fails. */
  8794. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8795. file = this.unescapeFilePostParams(file);
  8796. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8797. };
  8798. /* Called after the file dialog has closed and the selected files have been queued.
  8799. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8800. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8801. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8802. };
  8803. SWFUpload.prototype.uploadStart = function (file) {
  8804. file = this.unescapeFilePostParams(file);
  8805. this.queueEvent("return_upload_start_handler", file);
  8806. };
  8807. SWFUpload.prototype.returnUploadStart = function (file) {
  8808. var returnValue;
  8809. if (typeof this.settings.upload_start_handler === "function") {
  8810. file = this.unescapeFilePostParams(file);
  8811. returnValue = this.settings.upload_start_handler.call(this, file);
  8812. } else if (this.settings.upload_start_handler != undefined) {
  8813. throw "upload_start_handler must be a function";
  8814. }
  8815. // Convert undefined to true so if nothing is returned from the upload_start_handler it is
  8816. // interpretted as 'true'.
  8817. if (returnValue === undefined) {
  8818. returnValue = true;
  8819. }
  8820. returnValue = !!returnValue;
  8821. this.callFlash("ReturnUploadStart", [returnValue]);
  8822. };
  8823. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8824. file = this.unescapeFilePostParams(file);
  8825. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8826. };
  8827. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8828. file = this.unescapeFilePostParams(file);
  8829. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8830. };
  8831. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8832. file = this.unescapeFilePostParams(file);
  8833. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8834. };
  8835. SWFUpload.prototype.uploadComplete = function (file) {
  8836. file = this.unescapeFilePostParams(file);
  8837. this.queueEvent("upload_complete_handler", file);
  8838. };
  8839. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8840. internal debug console. You can override this event and have messages written where you want. */
  8841. SWFUpload.prototype.debug = function (message) {
  8842. this.queueEvent("debug_handler", message);
  8843. };
  8844. /* **********************************
  8845. Debug Console
  8846. The debug console is a self contained, in page location
  8847. for debug message to be sent. The Debug Console adds
  8848. itself to the body if necessary.
  8849. The console is automatically scrolled as messages appear.
  8850. If you are using your own debug handler or when you deploy to production and
  8851. have debug disabled you can remove these functions to reduce the file size
  8852. and complexity.
  8853. ********************************** */
  8854. // Private: debugMessage is the default debug_handler. If you want to print debug messages
  8855. // call the debug() function. When overriding the function your own function should
  8856. // check to see if the debug setting is true before outputting debug information.
  8857. SWFUpload.prototype.debugMessage = function (message) {
  8858. if (this.settings.debug) {
  8859. var exceptionMessage, exceptionValues = [];
  8860. // Check for an exception object and print it nicely
  8861. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8862. for (var key in message) {
  8863. if (message.hasOwnProperty(key)) {
  8864. exceptionValues.push(key + ": " + message[key]);
  8865. }
  8866. }
  8867. exceptionMessage = exceptionValues.join("\n") || "";
  8868. exceptionValues = exceptionMessage.split("\n");
  8869. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8870. SWFUpload.Console.writeLine(exceptionMessage);
  8871. } else {
  8872. SWFUpload.Console.writeLine(message);
  8873. }
  8874. }
  8875. };
  8876. SWFUpload.Console = {};
  8877. SWFUpload.Console.writeLine = function (message) {
  8878. var console, documentForm;
  8879. try {
  8880. console = document.getElementById("SWFUpload_Console");
  8881. if (!console) {
  8882. documentForm = document.createElement("form");
  8883. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8884. console = document.createElement("textarea");
  8885. console.id = "SWFUpload_Console";
  8886. console.style.fontFamily = "monospace";
  8887. console.setAttribute("wrap", "off");
  8888. console.wrap = "off";
  8889. console.style.overflow = "auto";
  8890. console.style.width = "700px";
  8891. console.style.height = "350px";
  8892. console.style.margin = "5px";
  8893. documentForm.appendChild(console);
  8894. }
  8895. console.value += message + "\n";
  8896. console.scrollTop = console.scrollHeight - console.clientHeight;
  8897. } catch (ex) {
  8898. alert("Exception: " + ex.name + " Message: " + ex.message);
  8899. }
  8900. };
  8901. })();
  8902. (function() {
  8903. /*
  8904. Queue Plug-in
  8905. Features:
  8906. *Adds a cancelQueue() method for cancelling the entire queue.
  8907. *All queued files are uploaded when startUpload() is called.
  8908. *If false is returned from uploadComplete then the queue upload is stopped.
  8909. If false is not returned (strict comparison) then the queue upload is continued.
  8910. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8911. Set the event handler with the queue_complete_handler setting.
  8912. */
  8913. if (typeof(SWFUpload) === "function") {
  8914. SWFUpload.queue = {};
  8915. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8916. return function () {
  8917. if (typeof(oldInitSettings) === "function") {
  8918. oldInitSettings.call(this);
  8919. }
  8920. this.queueSettings = {};
  8921. this.queueSettings.queue_cancelled_flag = false;
  8922. this.queueSettings.queue_upload_count = 0;
  8923. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8924. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8925. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8926. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8927. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8928. };
  8929. })(SWFUpload.prototype.initSettings);
  8930. SWFUpload.prototype.startUpload = function (fileID) {
  8931. this.queueSettings.queue_cancelled_flag = false;
  8932. this.callFlash("StartUpload", [fileID]);
  8933. };
  8934. SWFUpload.prototype.cancelQueue = function () {
  8935. this.queueSettings.queue_cancelled_flag = true;
  8936. this.stopUpload();
  8937. var stats = this.getStats();
  8938. while (stats.files_queued > 0) {
  8939. this.cancelUpload();
  8940. stats = this.getStats();
  8941. }
  8942. };
  8943. SWFUpload.queue.uploadStartHandler = function (file) {
  8944. var returnValue;
  8945. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8946. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8947. }
  8948. // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
  8949. returnValue = (returnValue === false) ? false : true;
  8950. this.queueSettings.queue_cancelled_flag = !returnValue;
  8951. return returnValue;
  8952. };
  8953. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8954. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8955. var continueUpload;
  8956. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8957. this.queueSettings.queue_upload_count++;
  8958. }
  8959. if (typeof(user_upload_complete_handler) === "function") {
  8960. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8961. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8962. // If the file was stopped and re-queued don't restart the upload
  8963. continueUpload = false;
  8964. } else {
  8965. continueUpload = true;
  8966. }
  8967. if (continueUpload) {
  8968. var stats = this.getStats();
  8969. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8970. this.startUpload();
  8971. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8972. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8973. this.queueSettings.queue_upload_count = 0;
  8974. } else {
  8975. this.queueSettings.queue_cancelled_flag = false;
  8976. this.queueSettings.queue_upload_count = 0;
  8977. }
  8978. }
  8979. };
  8980. }
  8981. })();
  8982. /*******************************************************************************
  8983. * KindEditor - WYSIWYG HTML Editor for Internet
  8984. * Copyright (C) 2006-2011 kindsoft.net
  8985. *
  8986. * @author Roddy <luolonghao@gmail.com>
  8987. * @site http://www.kindsoft.net/
  8988. * @licence http://www.kindsoft.net/license.php
  8989. *******************************************************************************/
  8990. KindEditor.plugin('pagebreak', function(K) {
  8991. var self = this;
  8992. var name = 'pagebreak';
  8993. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8994. self.clickToolbar(name, function() {
  8995. var cmd = self.cmd, range = cmd.range;
  8996. self.focus();
  8997. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8998. self.insertHtml(pagebreakHtml + tail);
  8999. if (tail !== '') {
  9000. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9001. range.selectNodeContents(p[0]);
  9002. p.removeAttr('id');
  9003. cmd.select();
  9004. }
  9005. });
  9006. });
  9007. /*******************************************************************************
  9008. * KindEditor - WYSIWYG HTML Editor for Internet
  9009. * Copyright (C) 2006-2011 kindsoft.net
  9010. *
  9011. * @author Roddy <luolonghao@gmail.com>
  9012. * @site http://www.kindsoft.net/
  9013. * @licence http://www.kindsoft.net/license.php
  9014. *******************************************************************************/
  9015. KindEditor.plugin('plainpaste', function(K) {
  9016. var self = this, name = 'plainpaste';
  9017. self.clickToolbar(name, function() {
  9018. var lang = self.lang(name + '.'),
  9019. html = '<div style="padding:10px 20px;">' +
  9020. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9021. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9022. '</div>',
  9023. dialog = self.createDialog({
  9024. name : name,
  9025. width : 450,
  9026. title : self.lang(name),
  9027. body : html,
  9028. yesBtn : {
  9029. name : self.lang('yes'),
  9030. click : function(e) {
  9031. var html = textarea.val();
  9032. html = K.escape(html);
  9033. html = html.replace(/ {2}/g, ' &nbsp;');
  9034. if (self.newlineTag == 'p') {
  9035. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9036. } else {
  9037. html = html.replace(/\n/g, '<br />$&');
  9038. }
  9039. self.insertHtml(html).hideDialog().focus();
  9040. }
  9041. }
  9042. }),
  9043. textarea = K('textarea', dialog.div);
  9044. textarea[0].focus();
  9045. });
  9046. });
  9047. /*******************************************************************************
  9048. * KindEditor - WYSIWYG HTML Editor for Internet
  9049. * Copyright (C) 2006-2011 kindsoft.net
  9050. *
  9051. * @author Roddy <luolonghao@gmail.com>
  9052. * @site http://www.kindsoft.net/
  9053. * @licence http://www.kindsoft.net/license.php
  9054. *******************************************************************************/
  9055. KindEditor.plugin('preview', function(K) {
  9056. var self = this, name = 'preview', undefined;
  9057. self.clickToolbar(name, function() {
  9058. var lang = self.lang(name + '.'),
  9059. html = '<div style="padding:10px 20px;">' +
  9060. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9061. '</div>',
  9062. dialog = self.createDialog({
  9063. name : name,
  9064. width : 750,
  9065. title : self.lang(name),
  9066. body : html
  9067. }),
  9068. iframe = K('iframe', dialog.div),
  9069. doc = K.iframeDoc(iframe);
  9070. doc.open();
  9071. doc.write(self.fullHtml());
  9072. doc.close();
  9073. K(doc.body).css('background-color', '#FFF');
  9074. iframe[0].contentWindow.focus();
  9075. });
  9076. });
  9077. /*******************************************************************************
  9078. * KindEditor - WYSIWYG HTML Editor for Internet
  9079. * Copyright (C) 2006-2011 kindsoft.net
  9080. *
  9081. * @author Roddy <luolonghao@gmail.com>
  9082. * @site http://www.kindsoft.net/
  9083. * @licence http://www.kindsoft.net/license.php
  9084. *******************************************************************************/
  9085. KindEditor.plugin('quickformat', function(K) {
  9086. var self = this, name = 'quickformat',
  9087. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9088. function getFirstChild(knode) {
  9089. var child = knode.first();
  9090. while (child && child.first()) {
  9091. child = child.first();
  9092. }
  9093. return child;
  9094. }
  9095. self.clickToolbar(name, function() {
  9096. self.focus();
  9097. var doc = self.edit.doc,
  9098. range = self.cmd.range,
  9099. child = K(doc.body).first(), next,
  9100. nodeList = [], subList = [],
  9101. bookmark = range.createBookmark(true);
  9102. while(child) {
  9103. next = child.next();
  9104. var firstChild = getFirstChild(child);
  9105. if (!firstChild || firstChild.name != 'img') {
  9106. if (blockMap[child.name]) {
  9107. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9108. child.css('text-indent', '2em');
  9109. } else {
  9110. subList.push(child);
  9111. }
  9112. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9113. if (subList.length > 0) {
  9114. nodeList.push(subList);
  9115. }
  9116. subList = [];
  9117. }
  9118. }
  9119. child = next;
  9120. }
  9121. K.each(nodeList, function(i, subList) {
  9122. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9123. subList[0].before(wrapper);
  9124. K.each(subList, function(i, knode) {
  9125. wrapper.append(knode);
  9126. });
  9127. });
  9128. range.moveToBookmark(bookmark);
  9129. self.addBookmark();
  9130. });
  9131. });
  9132. /**
  9133. --------------------------
  9134. abcd<br />
  9135. 1234<br />
  9136. to
  9137. <p style="text-indent:2em;">
  9138. abcd<br />
  9139. 1234<br />
  9140. </p>
  9141. --------------------------
  9142. &nbsp; abcd<img>1233
  9143. <p>1234</p>
  9144. to
  9145. <p style="text-indent:2em;">abcd<img>1233</p>
  9146. <p style="text-indent:2em;">1234</p>
  9147. --------------------------
  9148. *//*******************************************************************************
  9149. * KindEditor - WYSIWYG HTML Editor for Internet
  9150. * Copyright (C) 2006-2011 kindsoft.net
  9151. *
  9152. * @author Roddy <luolonghao@gmail.com>
  9153. * @site http://www.kindsoft.net/
  9154. * @licence http://www.kindsoft.net/license.php
  9155. *******************************************************************************/
  9156. KindEditor.plugin('table', function(K) {
  9157. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9158. // 设置颜色
  9159. function _setColor(box, color) {
  9160. color = color.toUpperCase();
  9161. box.css('background-color', color);
  9162. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9163. box.html(color);
  9164. }
  9165. // 初始化取色器
  9166. var pickerList = [];
  9167. function _initColorPicker(dialogDiv, colorBox) {
  9168. colorBox.bind('click,mousedown', function(e){
  9169. e.stopPropagation();
  9170. });
  9171. function removePicker() {
  9172. K.each(pickerList, function() {
  9173. this.remove();
  9174. });
  9175. pickerList = [];
  9176. K(document).unbind('click,mousedown', removePicker);
  9177. dialogDiv.unbind('click,mousedown', removePicker);
  9178. }
  9179. colorBox.click(function(e) {
  9180. removePicker();
  9181. var box = K(this),
  9182. pos = box.pos();
  9183. var picker = K.colorpicker({
  9184. x : pos.x,
  9185. y : pos.y + box.height(),
  9186. z : 811214,
  9187. selectedColor : K(this).html(),
  9188. colors : self.colorTable,
  9189. noColor : self.lang('noColor'),
  9190. shadowMode : self.shadowMode,
  9191. click : function(color) {
  9192. _setColor(box, color);
  9193. removePicker();
  9194. }
  9195. });
  9196. pickerList.push(picker);
  9197. K(document).bind('click,mousedown', removePicker);
  9198. dialogDiv.bind('click,mousedown', removePicker);
  9199. });
  9200. }
  9201. // 取得下一行cell的index
  9202. function _getCellIndex(table, row, cell) {
  9203. var rowSpanCount = 0;
  9204. for (var i = 0, len = row.cells.length; i < len; i++) {
  9205. if (row.cells[i] == cell) {
  9206. break;
  9207. }
  9208. rowSpanCount += row.cells[i].rowSpan - 1;
  9209. }
  9210. return cell.cellIndex - rowSpanCount;
  9211. }
  9212. self.plugin.table = {
  9213. //insert or modify table
  9214. prop : function(isInsert) {
  9215. var html = [
  9216. '<div style="padding:20px;">',
  9217. //rows, cols
  9218. '<div class="ke-dialog-row">',
  9219. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9220. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9221. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9222. '</div>',
  9223. //width, height
  9224. '<div class="ke-dialog-row">',
  9225. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9226. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9227. '<select name="widthType">',
  9228. '<option value="%">' + lang.percent + '</option>',
  9229. '<option value="px">' + lang.px + '</option>',
  9230. '</select> &nbsp; ',
  9231. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9232. '<select name="heightType">',
  9233. '<option value="%">' + lang.percent + '</option>',
  9234. '<option value="px">' + lang.px + '</option>',
  9235. '</select>',
  9236. '</div>',
  9237. //space, padding
  9238. '<div class="ke-dialog-row">',
  9239. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9240. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9241. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9242. '</div>',
  9243. //align
  9244. '<div class="ke-dialog-row">',
  9245. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9246. '<select id="keAlign" name="align">',
  9247. '<option value="">' + lang.alignDefault + '</option>',
  9248. '<option value="left">' + lang.alignLeft + '</option>',
  9249. '<option value="center">' + lang.alignCenter + '</option>',
  9250. '<option value="right">' + lang.alignRight + '</option>',
  9251. '</select>',
  9252. '</div>',
  9253. //border
  9254. '<div class="ke-dialog-row">',
  9255. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9256. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9257. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9258. '</div>',
  9259. //background color
  9260. '<div class="ke-dialog-row">',
  9261. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9262. '<span class="ke-inline-block ke-input-color"></span>',
  9263. '</div>',
  9264. '</div>'
  9265. ].join('');
  9266. var bookmark = self.cmd.range.createBookmark();
  9267. var dialog = self.createDialog({
  9268. name : name,
  9269. width : 500,
  9270. title : self.lang(name),
  9271. body : html,
  9272. beforeRemove : function() {
  9273. colorBox.unbind();
  9274. },
  9275. yesBtn : {
  9276. name : self.lang('yes'),
  9277. click : function(e) {
  9278. var rows = rowsBox.val(),
  9279. cols = colsBox.val(),
  9280. width = widthBox.val(),
  9281. height = heightBox.val(),
  9282. widthType = widthTypeBox.val(),
  9283. heightType = heightTypeBox.val(),
  9284. padding = paddingBox.val(),
  9285. spacing = spacingBox.val(),
  9286. align = alignBox.val(),
  9287. border = borderBox.val(),
  9288. borderColor = K(colorBox[0]).html() || '',
  9289. bgColor = K(colorBox[1]).html() || '';
  9290. if (rows == 0 || !/^\d+$/.test(rows)) {
  9291. alert(self.lang('invalidRows'));
  9292. rowsBox[0].focus();
  9293. return;
  9294. }
  9295. if (cols == 0 || !/^\d+$/.test(cols)) {
  9296. alert(self.lang('invalidRows'));
  9297. colsBox[0].focus();
  9298. return;
  9299. }
  9300. if (!/^\d*$/.test(width)) {
  9301. alert(self.lang('invalidWidth'));
  9302. widthBox[0].focus();
  9303. return;
  9304. }
  9305. if (!/^\d*$/.test(height)) {
  9306. alert(self.lang('invalidHeight'));
  9307. heightBox[0].focus();
  9308. return;
  9309. }
  9310. if (!/^\d*$/.test(padding)) {
  9311. alert(self.lang('invalidPadding'));
  9312. paddingBox[0].focus();
  9313. return;
  9314. }
  9315. if (!/^\d*$/.test(spacing)) {
  9316. alert(self.lang('invalidSpacing'));
  9317. spacingBox[0].focus();
  9318. return;
  9319. }
  9320. if (!/^\d*$/.test(border)) {
  9321. alert(self.lang('invalidBorder'));
  9322. borderBox[0].focus();
  9323. return;
  9324. }
  9325. //modify table
  9326. if (table) {
  9327. if (width !== '') {
  9328. table.width(width + widthType);
  9329. } else {
  9330. table.css('width', '');
  9331. }
  9332. if (table[0].width !== undefined) {
  9333. table.removeAttr('width');
  9334. }
  9335. if (height !== '') {
  9336. table.height(height + heightType);
  9337. } else {
  9338. table.css('height', '');
  9339. }
  9340. if (table[0].height !== undefined) {
  9341. table.removeAttr('height');
  9342. }
  9343. table.css('background-color', bgColor);
  9344. if (table[0].bgColor !== undefined) {
  9345. table.removeAttr('bgColor');
  9346. }
  9347. if (padding !== '') {
  9348. table[0].cellPadding = padding;
  9349. } else {
  9350. table.removeAttr('cellPadding');
  9351. }
  9352. if (spacing !== '') {
  9353. table[0].cellSpacing = spacing;
  9354. } else {
  9355. table.removeAttr('cellSpacing');
  9356. }
  9357. if (align !== '') {
  9358. table[0].align = align;
  9359. } else {
  9360. table.removeAttr('align');
  9361. }
  9362. if (border !== '') {
  9363. table.attr('border', border);
  9364. } else {
  9365. table.removeAttr('border');
  9366. }
  9367. if (border === '' || border === '0') {
  9368. table.addClass(zeroborder);
  9369. } else {
  9370. table.removeClass(zeroborder);
  9371. }
  9372. if (borderColor !== '') {
  9373. table.attr('borderColor', borderColor);
  9374. } else {
  9375. table.removeAttr('borderColor');
  9376. }
  9377. self.hideDialog().focus();
  9378. self.cmd.range.moveToBookmark(bookmark);
  9379. self.cmd.select();
  9380. self.addBookmark();
  9381. return;
  9382. }
  9383. //insert new table
  9384. var style = '';
  9385. if (width !== '') {
  9386. style += 'width:' + width + widthType + ';';
  9387. }
  9388. if (height !== '') {
  9389. style += 'height:' + height + heightType + ';';
  9390. }
  9391. if (bgColor !== '') {
  9392. style += 'background-color:' + bgColor + ';';
  9393. }
  9394. var html = '<table';
  9395. if (style !== '') {
  9396. html += ' style="' + style + '"';
  9397. }
  9398. if (padding !== '') {
  9399. html += ' cellpadding="' + padding + '"';
  9400. }
  9401. if (spacing !== '') {
  9402. html += ' cellspacing="' + spacing + '"';
  9403. }
  9404. if (align !== '') {
  9405. html += ' align="' + align + '"';
  9406. }
  9407. if (border !== '') {
  9408. html += ' border="' + border + '"';
  9409. }
  9410. if (border === '' || border === '0') {
  9411. html += ' class="' + zeroborder + '"';
  9412. }
  9413. if (borderColor !== '') {
  9414. html += ' bordercolor="' + borderColor + '"';
  9415. }
  9416. html += '>';
  9417. for (var i = 0; i < rows; i++) {
  9418. html += '<tr>';
  9419. for (var j = 0; j < cols; j++) {
  9420. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9421. }
  9422. html += '</tr>';
  9423. }
  9424. html += '</table>';
  9425. if (!K.IE) {
  9426. html += '<br />';
  9427. }
  9428. self.insertHtml(html);
  9429. self.select().hideDialog().focus();
  9430. self.addBookmark();
  9431. }
  9432. }
  9433. }),
  9434. div = dialog.div,
  9435. rowsBox = K('[name="rows"]', div).val(3),
  9436. colsBox = K('[name="cols"]', div).val(2),
  9437. widthBox = K('[name="width"]', div).val(100),
  9438. heightBox = K('[name="height"]', div),
  9439. widthTypeBox = K('[name="widthType"]', div),
  9440. heightTypeBox = K('[name="heightType"]', div),
  9441. paddingBox = K('[name="padding"]', div).val(2),
  9442. spacingBox = K('[name="spacing"]', div).val(0),
  9443. alignBox = K('[name="align"]', div),
  9444. borderBox = K('[name="border"]', div).val(1),
  9445. colorBox = K('.ke-input-color', div);
  9446. _initColorPicker(div, colorBox.eq(0));
  9447. _initColorPicker(div, colorBox.eq(1));
  9448. _setColor(colorBox.eq(0), '#000000');
  9449. _setColor(colorBox.eq(1), '');
  9450. // foucs and select
  9451. rowsBox[0].focus();
  9452. rowsBox[0].select();
  9453. var table;
  9454. if (isInsert) {
  9455. return;
  9456. }
  9457. //get selected table node
  9458. table = self.plugin.getSelectedTable();
  9459. if (table) {
  9460. rowsBox.val(table[0].rows.length);
  9461. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9462. rowsBox.attr('disabled', true);
  9463. colsBox.attr('disabled', true);
  9464. var match,
  9465. tableWidth = table[0].style.width || table[0].width,
  9466. tableHeight = table[0].style.height || table[0].height;
  9467. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9468. widthBox.val(match[1]);
  9469. widthTypeBox.val(match[2]);
  9470. } else {
  9471. widthBox.val('');
  9472. }
  9473. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9474. heightBox.val(match[1]);
  9475. heightTypeBox.val(match[2]);
  9476. }
  9477. paddingBox.val(table[0].cellPadding || '');
  9478. spacingBox.val(table[0].cellSpacing || '');
  9479. alignBox.val(table[0].align || '');
  9480. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9481. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9482. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9483. widthBox[0].focus();
  9484. widthBox[0].select();
  9485. }
  9486. },
  9487. //modify cell
  9488. cellprop : function() {
  9489. var html = [
  9490. '<div style="padding:20px;">',
  9491. //width, height
  9492. '<div class="ke-dialog-row">',
  9493. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9494. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9495. '<select name="widthType">',
  9496. '<option value="%">' + lang.percent + '</option>',
  9497. '<option value="px">' + lang.px + '</option>',
  9498. '</select> &nbsp; ',
  9499. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9500. '<select name="heightType">',
  9501. '<option value="%">' + lang.percent + '</option>',
  9502. '<option value="px">' + lang.px + '</option>',
  9503. '</select>',
  9504. '</div>',
  9505. //align
  9506. '<div class="ke-dialog-row">',
  9507. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9508. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9509. '<option value="">' + lang.alignDefault + '</option>',
  9510. '<option value="left">' + lang.alignLeft + '</option>',
  9511. '<option value="center">' + lang.alignCenter + '</option>',
  9512. '<option value="right">' + lang.alignRight + '</option>',
  9513. '</select> ',
  9514. lang.verticalAlign + ' <select name="verticalAlign">',
  9515. '<option value="">' + lang.alignDefault + '</option>',
  9516. '<option value="top">' + lang.alignTop + '</option>',
  9517. '<option value="middle">' + lang.alignMiddle + '</option>',
  9518. '<option value="bottom">' + lang.alignBottom + '</option>',
  9519. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9520. '</select>',
  9521. '</div>',
  9522. //border
  9523. '<div class="ke-dialog-row">',
  9524. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9525. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9526. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9527. '</div>',
  9528. //background color
  9529. '<div class="ke-dialog-row">',
  9530. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9531. '<span class="ke-inline-block ke-input-color"></span>',
  9532. '</div>',
  9533. '</div>'
  9534. ].join('');
  9535. var bookmark = self.cmd.range.createBookmark();
  9536. var dialog = self.createDialog({
  9537. name : name,
  9538. width : 500,
  9539. title : self.lang('tablecell'),
  9540. body : html,
  9541. beforeRemove : function() {
  9542. colorBox.unbind();
  9543. },
  9544. yesBtn : {
  9545. name : self.lang('yes'),
  9546. click : function(e) {
  9547. var width = widthBox.val(),
  9548. height = heightBox.val(),
  9549. widthType = widthTypeBox.val(),
  9550. heightType = heightTypeBox.val(),
  9551. padding = paddingBox.val(),
  9552. spacing = spacingBox.val(),
  9553. textAlign = textAlignBox.val(),
  9554. verticalAlign = verticalAlignBox.val(),
  9555. border = borderBox.val(),
  9556. borderColor = K(colorBox[0]).html() || '',
  9557. bgColor = K(colorBox[1]).html() || '';
  9558. if (!/^\d*$/.test(width)) {
  9559. alert(self.lang('invalidWidth'));
  9560. widthBox[0].focus();
  9561. return;
  9562. }
  9563. if (!/^\d*$/.test(height)) {
  9564. alert(self.lang('invalidHeight'));
  9565. heightBox[0].focus();
  9566. return;
  9567. }
  9568. if (!/^\d*$/.test(border)) {
  9569. alert(self.lang('invalidBorder'));
  9570. borderBox[0].focus();
  9571. return;
  9572. }
  9573. cell.css({
  9574. width : width !== '' ? (width + widthType) : '',
  9575. height : height !== '' ? (height + heightType) : '',
  9576. 'background-color' : bgColor,
  9577. 'text-align' : textAlign,
  9578. 'vertical-align' : verticalAlign,
  9579. 'border-width' : border,
  9580. 'border-style' : border !== '' ? 'solid' : '',
  9581. 'border-color' : borderColor
  9582. });
  9583. self.hideDialog().focus();
  9584. self.cmd.range.moveToBookmark(bookmark);
  9585. self.cmd.select();
  9586. self.addBookmark();
  9587. }
  9588. }
  9589. }),
  9590. div = dialog.div,
  9591. widthBox = K('[name="width"]', div).val(100),
  9592. heightBox = K('[name="height"]', div),
  9593. widthTypeBox = K('[name="widthType"]', div),
  9594. heightTypeBox = K('[name="heightType"]', div),
  9595. paddingBox = K('[name="padding"]', div).val(2),
  9596. spacingBox = K('[name="spacing"]', div).val(0),
  9597. textAlignBox = K('[name="textAlign"]', div),
  9598. verticalAlignBox = K('[name="verticalAlign"]', div),
  9599. borderBox = K('[name="border"]', div).val(1),
  9600. colorBox = K('.ke-input-color', div);
  9601. _initColorPicker(div, colorBox.eq(0));
  9602. _initColorPicker(div, colorBox.eq(1));
  9603. _setColor(colorBox.eq(0), '#000000');
  9604. _setColor(colorBox.eq(1), '');
  9605. // foucs and select
  9606. widthBox[0].focus();
  9607. widthBox[0].select();
  9608. // get selected cell
  9609. var cell = self.plugin.getSelectedCell();
  9610. var match,
  9611. cellWidth = cell[0].style.width || cell[0].width || '',
  9612. cellHeight = cell[0].style.height || cell[0].height || '';
  9613. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9614. widthBox.val(match[1]);
  9615. widthTypeBox.val(match[2]);
  9616. } else {
  9617. widthBox.val('');
  9618. }
  9619. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9620. heightBox.val(match[1]);
  9621. heightTypeBox.val(match[2]);
  9622. }
  9623. textAlignBox.val(cell[0].style.textAlign || '');
  9624. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9625. var border = cell[0].style.borderWidth || '';
  9626. if (border) {
  9627. border = parseInt(border);
  9628. }
  9629. borderBox.val(border);
  9630. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9631. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9632. widthBox[0].focus();
  9633. widthBox[0].select();
  9634. },
  9635. insert : function() {
  9636. this.prop(true);
  9637. },
  9638. 'delete' : function() {
  9639. var table = self.plugin.getSelectedTable();
  9640. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9641. self.cmd.select();
  9642. table.remove();
  9643. self.addBookmark();
  9644. },
  9645. colinsert : function(offset) {
  9646. var table = self.plugin.getSelectedTable()[0],
  9647. row = self.plugin.getSelectedRow()[0],
  9648. cell = self.plugin.getSelectedCell()[0],
  9649. index = cell.cellIndex + offset;
  9650. // 取得第一行的index
  9651. index += table.rows[0].cells.length - row.cells.length;
  9652. for (var i = 0, len = table.rows.length; i < len; i++) {
  9653. var newRow = table.rows[i],
  9654. newCell = newRow.insertCell(index);
  9655. newCell.innerHTML = K.IE ? '' : '<br />';
  9656. // 调整下一行的单元格index
  9657. index = _getCellIndex(table, newRow, newCell);
  9658. }
  9659. self.cmd.range.selectNodeContents(cell).collapse(true);
  9660. self.cmd.select();
  9661. self.addBookmark();
  9662. },
  9663. colinsertleft : function() {
  9664. this.colinsert(0);
  9665. },
  9666. colinsertright : function() {
  9667. this.colinsert(1);
  9668. },
  9669. rowinsert : function(offset) {
  9670. var table = self.plugin.getSelectedTable()[0],
  9671. row = self.plugin.getSelectedRow()[0],
  9672. cell = self.plugin.getSelectedCell()[0];
  9673. var rowIndex = row.rowIndex;
  9674. if (offset === 1) {
  9675. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9676. }
  9677. var newRow = table.insertRow(rowIndex);
  9678. for (var i = 0, len = row.cells.length; i < len; i++) {
  9679. // 调整cell个数
  9680. if (row.cells[i].rowSpan > 1) {
  9681. len -= row.cells[i].rowSpan - 1;
  9682. }
  9683. var newCell = newRow.insertCell(i);
  9684. // copy colspan
  9685. if (offset === 1 && row.cells[i].colSpan > 1) {
  9686. newCell.colSpan = row.cells[i].colSpan;
  9687. }
  9688. newCell.innerHTML = K.IE ? '' : '<br />';
  9689. }
  9690. // 调整rowspan
  9691. for (var j = rowIndex; j >= 0; j--) {
  9692. var cells = table.rows[j].cells;
  9693. if (cells.length > i) {
  9694. for (var k = cell.cellIndex; k >= 0; k--) {
  9695. if (cells[k].rowSpan > 1) {
  9696. cells[k].rowSpan += 1;
  9697. }
  9698. }
  9699. break;
  9700. }
  9701. }
  9702. self.cmd.range.selectNodeContents(cell).collapse(true);
  9703. self.cmd.select();
  9704. self.addBookmark();
  9705. },
  9706. rowinsertabove : function() {
  9707. this.rowinsert(0);
  9708. },
  9709. rowinsertbelow : function() {
  9710. this.rowinsert(1);
  9711. },
  9712. rowmerge : function() {
  9713. var table = self.plugin.getSelectedTable()[0],
  9714. row = self.plugin.getSelectedRow()[0],
  9715. cell = self.plugin.getSelectedCell()[0],
  9716. rowIndex = row.rowIndex, // 当前行的index
  9717. nextRowIndex = rowIndex + cell.rowSpan, // 下一行的index
  9718. nextRow = table.rows[nextRowIndex]; // 下一行
  9719. // 最后一行不能合并
  9720. if (table.rows.length <= nextRowIndex) {
  9721. return;
  9722. }
  9723. var cellIndex = cell.cellIndex; // 下一行单元格的index
  9724. if (nextRow.cells.length <= cellIndex) {
  9725. return;
  9726. }
  9727. var nextCell = nextRow.cells[cellIndex]; // 下一行单元格
  9728. // 上下行的colspan不一致时不能合并
  9729. if (cell.colSpan !== nextCell.colSpan) {
  9730. return;
  9731. }
  9732. cell.rowSpan += nextCell.rowSpan;
  9733. nextRow.deleteCell(cellIndex);
  9734. self.cmd.range.selectNodeContents(cell).collapse(true);
  9735. self.cmd.select();
  9736. self.addBookmark();
  9737. },
  9738. colmerge : function() {
  9739. var table = self.plugin.getSelectedTable()[0],
  9740. row = self.plugin.getSelectedRow()[0],
  9741. cell = self.plugin.getSelectedCell()[0],
  9742. rowIndex = row.rowIndex, // 当前行的index
  9743. cellIndex = cell.cellIndex,
  9744. nextCellIndex = cellIndex + 1;
  9745. // 最后一列不能合并
  9746. if (row.cells.length <= nextCellIndex) {
  9747. return;
  9748. }
  9749. var nextCell = row.cells[nextCellIndex];
  9750. // 左右列的rowspan不一致时不能合并
  9751. if (cell.rowSpan !== nextCell.rowSpan) {
  9752. return;
  9753. }
  9754. cell.colSpan += nextCell.colSpan;
  9755. row.deleteCell(nextCellIndex);
  9756. self.cmd.range.selectNodeContents(cell).collapse(true);
  9757. self.cmd.select();
  9758. self.addBookmark();
  9759. },
  9760. rowsplit : function() {
  9761. var table = self.plugin.getSelectedTable()[0],
  9762. row = self.plugin.getSelectedRow()[0],
  9763. cell = self.plugin.getSelectedCell()[0],
  9764. rowIndex = row.rowIndex;
  9765. // 不是可分割单元格
  9766. if (cell.rowSpan === 1) {
  9767. return;
  9768. }
  9769. var cellIndex = _getCellIndex(table, row, cell);
  9770. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9771. var newRow = table.rows[rowIndex + i],
  9772. newCell = newRow.insertCell(cellIndex);
  9773. if (cell.colSpan > 1) {
  9774. newCell.colSpan = cell.colSpan;
  9775. }
  9776. newCell.innerHTML = K.IE ? '' : '<br />';
  9777. // 调整下一行的单元格index
  9778. cellIndex = _getCellIndex(table, newRow, newCell);
  9779. }
  9780. K(cell).removeAttr('rowSpan');
  9781. self.cmd.range.selectNodeContents(cell).collapse(true);
  9782. self.cmd.select();
  9783. self.addBookmark();
  9784. },
  9785. colsplit : function() {
  9786. var table = self.plugin.getSelectedTable()[0],
  9787. row = self.plugin.getSelectedRow()[0],
  9788. cell = self.plugin.getSelectedCell()[0],
  9789. cellIndex = cell.cellIndex;
  9790. // 不是可分割单元格
  9791. if (cell.colSpan === 1) {
  9792. return;
  9793. }
  9794. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9795. var newCell = row.insertCell(cellIndex + i);
  9796. if (cell.rowSpan > 1) {
  9797. newCell.rowSpan = cell.rowSpan;
  9798. }
  9799. newCell.innerHTML = K.IE ? '' : '<br />';
  9800. }
  9801. K(cell).removeAttr('colSpan');
  9802. self.cmd.range.selectNodeContents(cell).collapse(true);
  9803. self.cmd.select();
  9804. self.addBookmark();
  9805. },
  9806. coldelete : function() {
  9807. var table = self.plugin.getSelectedTable()[0],
  9808. row = self.plugin.getSelectedRow()[0],
  9809. cell = self.plugin.getSelectedCell()[0],
  9810. index = cell.cellIndex;
  9811. for (var i = 0, len = table.rows.length; i < len; i++) {
  9812. var newRow = table.rows[i],
  9813. newCell = newRow.cells[index];
  9814. if (newCell.colSpan > 1) {
  9815. newCell.colSpan -= 1;
  9816. if (newCell.colSpan === 1) {
  9817. K(newCell).removeAttr('colSpan');
  9818. }
  9819. } else {
  9820. newRow.deleteCell(index);
  9821. }
  9822. // 跳过不需要删除的行
  9823. if (newCell.rowSpan > 1) {
  9824. i += newCell.rowSpan - 1;
  9825. }
  9826. }
  9827. if (row.cells.length === 0) {
  9828. self.cmd.range.setStartBefore(table).collapse(true);
  9829. self.cmd.select();
  9830. K(table).remove();
  9831. } else {
  9832. self.cmd.selection(true);
  9833. }
  9834. self.addBookmark();
  9835. },
  9836. rowdelete : function() {
  9837. var table = self.plugin.getSelectedTable()[0],
  9838. row = self.plugin.getSelectedRow()[0],
  9839. cell = self.plugin.getSelectedCell()[0],
  9840. rowIndex = row.rowIndex;
  9841. // 从下到上删除
  9842. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9843. table.deleteRow(rowIndex + i);
  9844. }
  9845. if (table.rows.length === 0) {
  9846. self.cmd.range.setStartBefore(table).collapse(true);
  9847. self.cmd.select();
  9848. K(table).remove();
  9849. } else {
  9850. self.cmd.selection(true);
  9851. }
  9852. self.addBookmark();
  9853. }
  9854. };
  9855. self.clickToolbar(name, self.plugin.table.prop);
  9856. });
  9857. /*******************************************************************************
  9858. * KindEditor - WYSIWYG HTML Editor for Internet
  9859. * Copyright (C) 2006-2011 kindsoft.net
  9860. *
  9861. * @author Roddy <luolonghao@gmail.com>
  9862. * @site http://www.kindsoft.net/
  9863. * @licence http://www.kindsoft.net/license.php
  9864. *******************************************************************************/
  9865. KindEditor.plugin('template', function(K) {
  9866. var self = this, name = 'template', lang = self.lang(name + '.'),
  9867. htmlPath = self.pluginsPath + name + '/html/';
  9868. function getFilePath(fileName) {
  9869. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9870. }
  9871. self.clickToolbar(name, function() {
  9872. var lang = self.lang(name + '.'),
  9873. arr = ['<div style="padding:10px 20px;">',
  9874. '<div class="ke-header">',
  9875. // left start
  9876. '<div class="ke-left">',
  9877. lang. selectTemplate + ' <select>'];
  9878. K.each(lang.fileList, function(key, val) {
  9879. arr.push('<option value="' + key + '">' + val + '</option>');
  9880. });
  9881. html = [arr.join(''),
  9882. '</select></div>',
  9883. // right start
  9884. '<div class="ke-right">',
  9885. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9886. '</div>',
  9887. '<div class="ke-clearfix"></div>',
  9888. '</div>',
  9889. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9890. '</div>'].join('');
  9891. var dialog = self.createDialog({
  9892. name : name,
  9893. width : 500,
  9894. title : self.lang(name),
  9895. body : html,
  9896. yesBtn : {
  9897. name : self.lang('yes'),
  9898. click : function(e) {
  9899. var doc = K.iframeDoc(iframe);
  9900. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9901. }
  9902. }
  9903. });
  9904. var selectBox = K('select', dialog.div),
  9905. checkbox = K('[name="replaceFlag"]', dialog.div),
  9906. iframe = K('iframe', dialog.div);
  9907. checkbox[0].checked = true;
  9908. iframe.attr('src', getFilePath(selectBox.val()));
  9909. selectBox.change(function() {
  9910. iframe.attr('src', getFilePath(this.value));
  9911. });
  9912. });
  9913. });
  9914. /*******************************************************************************
  9915. * KindEditor - WYSIWYG HTML Editor for Internet
  9916. * Copyright (C) 2006-2011 kindsoft.net
  9917. *
  9918. * @author Roddy <luolonghao@gmail.com>
  9919. * @site http://www.kindsoft.net/
  9920. * @licence http://www.kindsoft.net/license.php
  9921. *******************************************************************************/
  9922. KindEditor.plugin('wordpaste', function(K) {
  9923. var self = this, name = 'wordpaste';
  9924. self.clickToolbar(name, function() {
  9925. var lang = self.lang(name + '.'),
  9926. html = '<div style="padding:10px 20px;">' +
  9927. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9928. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9929. '</div>',
  9930. dialog = self.createDialog({
  9931. name : name,
  9932. width : 450,
  9933. title : self.lang(name),
  9934. body : html,
  9935. yesBtn : {
  9936. name : self.lang('yes'),
  9937. click : function(e) {
  9938. var str = doc.body.innerHTML;
  9939. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9940. self.insertHtml(str).hideDialog().focus();
  9941. }
  9942. }
  9943. }),
  9944. div = dialog.div,
  9945. iframe = K('iframe', div),
  9946. doc = K.iframeDoc(iframe);
  9947. if (!K.IE) {
  9948. doc.designMode = 'on';
  9949. }
  9950. doc.open();
  9951. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9952. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9953. if (!K.IE) {
  9954. doc.write('<br />');
  9955. }
  9956. doc.write('</body></html>');
  9957. doc.close();
  9958. if (K.IE) {
  9959. doc.body.contentEditable = 'true';
  9960. }
  9961. iframe[0].contentWindow.focus();
  9962. });
  9963. });