Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

summernote.js 283KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243
  1. /**
  2. * Super simple wysiwyg editor v0.8.9
  3. * https://summernote.org
  4. *
  5. * Copyright 2013- Alan Hong. and other contributors
  6. * summernote may be freely distributed under the MIT license.
  7. *
  8. * Date: 2017-12-25T06:39Z
  9. */
  10. (function (global, factory) {
  11. typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) :
  12. typeof define === 'function' && define.amd ? define(['jquery'], factory) :
  13. (factory(global.jQuery));
  14. }(this, (function ($$1) {
  15. 'use strict';
  16. $$1 = $$1 && $$1.hasOwnProperty('default') ? $$1['default'] : $$1;
  17. var Renderer = /** @class */ (function () {
  18. function Renderer(markup, children, options, callback) {
  19. this.markup = markup;
  20. this.children = children;
  21. this.options = options;
  22. this.callback = callback;
  23. }
  24. Renderer.prototype.render = function ($parent) {
  25. var $node = $$1(this.markup);
  26. if (this.options && this.options.contents) {
  27. $node.html(this.options.contents);
  28. }
  29. if (this.options && this.options.className) {
  30. $node.addClass(this.options.className);
  31. }
  32. if (this.options && this.options.data) {
  33. $$1.each(this.options.data, function (k, v) {
  34. $node.attr('data-' + k, v);
  35. });
  36. }
  37. if (this.options && this.options.click) {
  38. $node.on('click', this.options.click);
  39. }
  40. if (this.children) {
  41. var $container_1 = $node.find('.note-children-container');
  42. this.children.forEach(function (child) {
  43. child.render($container_1.length ? $container_1 : $node);
  44. });
  45. }
  46. if (this.callback) {
  47. this.callback($node, this.options);
  48. }
  49. if (this.options && this.options.callback) {
  50. this.options.callback($node);
  51. }
  52. if ($parent) {
  53. $parent.append($node);
  54. }
  55. return $node;
  56. };
  57. return Renderer;
  58. }());
  59. var renderer = {
  60. create: function (markup, callback) {
  61. return function () {
  62. var options = typeof arguments[1] === 'object' ? arguments[1] : arguments[0];
  63. var children = $$1.isArray(arguments[0]) ? arguments[0] : [];
  64. if (options && options.children) {
  65. children = options.children;
  66. }
  67. return new Renderer(markup, children, options, callback);
  68. };
  69. }
  70. };
  71. var editor = renderer.create('<div class="note-editor note-frame panel"/>');
  72. var toolbar = renderer.create('<div class="note-toolbar-wrapper panel-default"><div class="note-toolbar panel-heading"></div></div>');
  73. var editingArea = renderer.create('<div class="note-editing-area"/>');
  74. var codable = renderer.create('<textarea class="note-codable"/>');
  75. var editable = renderer.create('<div class="note-editable" contentEditable="true"/>');
  76. var statusbar = renderer.create([
  77. '<div class="note-statusbar">',
  78. ' <div class="note-resizebar">',
  79. ' <div class="note-icon-bar"/>',
  80. ' <div class="note-icon-bar"/>',
  81. ' <div class="note-icon-bar"/>',
  82. ' </div>',
  83. '</div>'
  84. ].join(''));
  85. var airEditor = renderer.create('<div class="note-editor"/>');
  86. var airEditable = renderer.create('<div class="note-editable" contentEditable="true"/>');
  87. var buttonGroup = renderer.create('<div class="note-btn-group btn-group">');
  88. var dropdown = renderer.create('<div class="dropdown-menu">', function ($node, options) {
  89. var markup = $$1.isArray(options.items) ? options.items.map(function (item) {
  90. var value = (typeof item === 'string') ? item : (item.value || '');
  91. var content = options.template ? options.template(item) : item;
  92. var option = (typeof item === 'object') ? item.option : undefined;
  93. var dataValue = 'data-value="' + value + '"';
  94. var dataOption = (option !== undefined) ? ' data-option="' + option + '"' : '';
  95. return '<li><a href="#" ' + (dataValue + dataOption) + '>' + content + '</a></li>';
  96. }).join('') : options.items;
  97. $node.html(markup);
  98. });
  99. var dropdownButtonContents = function (contents, options) {
  100. return contents + ' ' + icon(options.icons.caret, 'span');
  101. };
  102. var dropdownCheck = renderer.create('<div class="dropdown-menu note-check">', function ($node, options) {
  103. var markup = $$1.isArray(options.items) ? options.items.map(function (item) {
  104. var value = (typeof item === 'string') ? item : (item.value || '');
  105. var content = options.template ? options.template(item) : item;
  106. return '<li><a href="#" data-value="' + value + '">' + icon(options.checkClassName) + ' ' + content + '</a></li>';
  107. }).join('') : options.items;
  108. $node.html(markup);
  109. });
  110. var palette = renderer.create('<div class="note-color-palette"/>', function ($node, options) {
  111. var contents = [];
  112. for (var row = 0, rowSize = options.colors.length; row < rowSize; row++) {
  113. var eventName = options.eventName;
  114. var colors = options.colors[row];
  115. var buttons = [];
  116. for (var col = 0, colSize = colors.length; col < colSize; col++) {
  117. var color = colors[col];
  118. buttons.push([
  119. '<button type="button" class="note-color-btn"',
  120. 'style="background-color:', color, '" ',
  121. 'data-event="', eventName, '" ',
  122. 'data-value="', color, '" ',
  123. 'title="', color, '" ',
  124. 'data-toggle="button" tabindex="-1"></button>'
  125. ].join(''));
  126. }
  127. contents.push('<div class="note-color-row">' + buttons.join('') + '</div>');
  128. }
  129. $node.html(contents.join(''));
  130. if (options.tooltip) {
  131. $node.find('.note-color-btn').tooltip({
  132. container: options.container,
  133. trigger: 'hover',
  134. placement: 'bottom'
  135. });
  136. }
  137. });
  138. var dialog = renderer.create('<div class="modal" aria-hidden="false" tabindex="-1"/>', function ($node, options) {
  139. if (options.fade) {
  140. $node.addClass('fade');
  141. }
  142. $node.html([
  143. '<div class="modal-dialog">',
  144. ' <div class="modal-content">',
  145. (options.title ?
  146. ' <div class="modal-header">' +
  147. ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
  148. ' <h4 class="modal-title">' + options.title + '</h4>' +
  149. ' </div>' : ''),
  150. ' <div class="modal-body">' + options.body + '</div>',
  151. (options.footer ?
  152. ' <div class="modal-footer">' + options.footer + '</div>' : ''),
  153. ' </div>',
  154. '</div>'
  155. ].join(''));
  156. });
  157. var popover = renderer.create([
  158. '<div class="note-popover popover in">',
  159. ' <div class="arrow"/>',
  160. ' <div class="popover-content note-children-container"/>',
  161. '</div>'
  162. ].join(''), function ($node, options) {
  163. var direction = typeof options.direction !== 'undefined' ? options.direction : 'bottom';
  164. $node.addClass(direction);
  165. if (options.hideArrow) {
  166. $node.find('.arrow').hide();
  167. }
  168. });
  169. var checkbox = renderer.create('<div class="checkbox"></div>', function ($node, options) {
  170. $node.html([
  171. ' <label' + (options.id ? ' for="' + options.id + '"' : '') + '>',
  172. ' <input type="checkbox"' + (options.id ? ' id="' + options.id + '"' : ''),
  173. (options.checked ? ' checked' : '') + '/>',
  174. (options.text ? options.text : ''),
  175. '</label>'
  176. ].join(''));
  177. });
  178. var icon = function (iconClassName, tagName) {
  179. tagName = tagName || 'i';
  180. return '<' + tagName + ' class="' + iconClassName + '"/>';
  181. };
  182. var ui = {
  183. editor: editor,
  184. toolbar: toolbar,
  185. editingArea: editingArea,
  186. codable: codable,
  187. editable: editable,
  188. statusbar: statusbar,
  189. airEditor: airEditor,
  190. airEditable: airEditable,
  191. buttonGroup: buttonGroup,
  192. dropdown: dropdown,
  193. dropdownButtonContents: dropdownButtonContents,
  194. dropdownCheck: dropdownCheck,
  195. palette: palette,
  196. dialog: dialog,
  197. popover: popover,
  198. checkbox: checkbox,
  199. icon: icon,
  200. options: {},
  201. button: function ($node, options) {
  202. return renderer.create('<button type="button" class="note-btn btn btn-default btn-sm" tabindex="-1">', function ($node, options) {
  203. if (options && options.tooltip) {
  204. $node.attr({
  205. title: options.tooltip
  206. }).tooltip({
  207. container: options.container,
  208. trigger: 'hover',
  209. placement: 'bottom'
  210. });
  211. }
  212. })($node, options);
  213. },
  214. toggleBtn: function ($btn, isEnable) {
  215. $btn.toggleClass('disabled', !isEnable);
  216. $btn.attr('disabled', !isEnable);
  217. },
  218. toggleBtnActive: function ($btn, isActive) {
  219. $btn.toggleClass('active', isActive);
  220. },
  221. onDialogShown: function ($dialog, handler) {
  222. $dialog.one('shown.bs.modal', handler);
  223. },
  224. onDialogHidden: function ($dialog, handler) {
  225. $dialog.one('hidden.bs.modal', handler);
  226. },
  227. showDialog: function ($dialog) {
  228. $dialog.modal('show');
  229. },
  230. hideDialog: function ($dialog) {
  231. $dialog.modal('hide');
  232. },
  233. createLayout: function ($note, options) {
  234. var $editor = (options.airMode ? ui.airEditor([
  235. ui.editingArea([
  236. ui.airEditable()
  237. ])
  238. ]) : ui.editor([
  239. ui.toolbar(),
  240. ui.editingArea([
  241. ui.codable(),
  242. ui.editable()
  243. ]),
  244. ui.statusbar()
  245. ])).render();
  246. $editor.insertAfter($note);
  247. return {
  248. note: $note,
  249. editor: $editor,
  250. toolbar: $editor.find('.note-toolbar'),
  251. editingArea: $editor.find('.note-editing-area'),
  252. editable: $editor.find('.note-editable'),
  253. codable: $editor.find('.note-codable'),
  254. statusbar: $editor.find('.note-statusbar')
  255. };
  256. },
  257. removeLayout: function ($note, layoutInfo) {
  258. $note.html(layoutInfo.editable.html());
  259. layoutInfo.editor.remove();
  260. $note.show();
  261. }
  262. };
  263. /**
  264. * @class core.func
  265. *
  266. * func utils (for high-order func's arg)
  267. *
  268. * @singleton
  269. * @alternateClassName func
  270. */
  271. function eq(itemA) {
  272. return function (itemB) {
  273. return itemA === itemB;
  274. };
  275. }
  276. function eq2(itemA, itemB) {
  277. return itemA === itemB;
  278. }
  279. function peq2(propName) {
  280. return function (itemA, itemB) {
  281. return itemA[propName] === itemB[propName];
  282. };
  283. }
  284. function ok() {
  285. return true;
  286. }
  287. function fail() {
  288. return false;
  289. }
  290. function not(f) {
  291. return function () {
  292. return !f.apply(f, arguments);
  293. };
  294. }
  295. function and(fA, fB) {
  296. return function (item) {
  297. return fA(item) && fB(item);
  298. };
  299. }
  300. function self(a) {
  301. return a;
  302. }
  303. function invoke(obj, method) {
  304. return function () {
  305. return obj[method].apply(obj, arguments);
  306. };
  307. }
  308. var idCounter = 0;
  309. /**
  310. * generate a globally-unique id
  311. *
  312. * @param {String} [prefix]
  313. */
  314. function uniqueId(prefix) {
  315. var id = ++idCounter + '';
  316. return prefix ? prefix + id : id;
  317. }
  318. /**
  319. * returns bnd (bounds) from rect
  320. *
  321. * - IE Compatibility Issue: http://goo.gl/sRLOAo
  322. * - Scroll Issue: http://goo.gl/sNjUc
  323. *
  324. * @param {Rect} rect
  325. * @return {Object} bounds
  326. * @return {Number} bounds.top
  327. * @return {Number} bounds.left
  328. * @return {Number} bounds.width
  329. * @return {Number} bounds.height
  330. */
  331. function rect2bnd(rect) {
  332. var $document = $(document);
  333. return {
  334. top: rect.top + $document.scrollTop(),
  335. left: rect.left + $document.scrollLeft(),
  336. width: rect.right - rect.left,
  337. height: rect.bottom - rect.top
  338. };
  339. }
  340. /**
  341. * returns a copy of the object where the keys have become the values and the values the keys.
  342. * @param {Object} obj
  343. * @return {Object}
  344. */
  345. function invertObject(obj) {
  346. var inverted = {};
  347. for (var key in obj) {
  348. if (obj.hasOwnProperty(key)) {
  349. inverted[obj[key]] = key;
  350. }
  351. }
  352. return inverted;
  353. }
  354. /**
  355. * @param {String} namespace
  356. * @param {String} [prefix]
  357. * @return {String}
  358. */
  359. function namespaceToCamel(namespace, prefix) {
  360. prefix = prefix || '';
  361. return prefix + namespace.split('.').map(function (name) {
  362. return name.substring(0, 1).toUpperCase() + name.substring(1);
  363. }).join('');
  364. }
  365. /**
  366. * Returns a function, that, as long as it continues to be invoked, will not
  367. * be triggered. The function will be called after it stops being called for
  368. * N milliseconds. If `immediate` is passed, trigger the function on the
  369. * leading edge, instead of the trailing.
  370. * @param {Function} func
  371. * @param {Number} wait
  372. * @param {Boolean} immediate
  373. * @return {Function}
  374. */
  375. function debounce(func, wait, immediate) {
  376. var _this = this;
  377. var timeout;
  378. return function () {
  379. var context = _this;
  380. var args = arguments;
  381. var later = function () {
  382. timeout = null;
  383. if (!immediate) {
  384. func.apply(context, args);
  385. }
  386. };
  387. var callNow = immediate && !timeout;
  388. clearTimeout(timeout);
  389. timeout = setTimeout(later, wait);
  390. if (callNow) {
  391. func.apply(context, args);
  392. }
  393. };
  394. }
  395. var func = {
  396. eq: eq,
  397. eq2: eq2,
  398. peq2: peq2,
  399. ok: ok,
  400. fail: fail,
  401. self: self,
  402. not: not,
  403. and: and,
  404. invoke: invoke,
  405. uniqueId: uniqueId,
  406. rect2bnd: rect2bnd,
  407. invertObject: invertObject,
  408. namespaceToCamel: namespaceToCamel,
  409. debounce: debounce
  410. };
  411. /**
  412. * returns the first item of an array.
  413. *
  414. * @param {Array} array
  415. */
  416. function head(array) {
  417. return array[0];
  418. }
  419. /**
  420. * returns the last item of an array.
  421. *
  422. * @param {Array} array
  423. */
  424. function last(array) {
  425. return array[array.length - 1];
  426. }
  427. /**
  428. * returns everything but the last entry of the array.
  429. *
  430. * @param {Array} array
  431. */
  432. function initial(array) {
  433. return array.slice(0, array.length - 1);
  434. }
  435. /**
  436. * returns the rest of the items in an array.
  437. *
  438. * @param {Array} array
  439. */
  440. function tail(array) {
  441. return array.slice(1);
  442. }
  443. /**
  444. * returns item of array
  445. */
  446. function find(array, pred) {
  447. for (var idx = 0, len = array.length; idx < len; idx++) {
  448. var item = array[idx];
  449. if (pred(item)) {
  450. return item;
  451. }
  452. }
  453. }
  454. /**
  455. * returns true if all of the values in the array pass the predicate truth test.
  456. */
  457. function all(array, pred) {
  458. for (var idx = 0, len = array.length; idx < len; idx++) {
  459. if (!pred(array[idx])) {
  460. return false;
  461. }
  462. }
  463. return true;
  464. }
  465. /**
  466. * returns index of item
  467. */
  468. function indexOf(array, item) {
  469. return $$1.inArray(item, array);
  470. }
  471. /**
  472. * returns true if the value is present in the list.
  473. */
  474. function contains(array, item) {
  475. return indexOf(array, item) !== -1;
  476. }
  477. /**
  478. * get sum from a list
  479. *
  480. * @param {Array} array - array
  481. * @param {Function} fn - iterator
  482. */
  483. function sum(array, fn) {
  484. fn = fn || func.self;
  485. return array.reduce(function (memo, v) {
  486. return memo + fn(v);
  487. }, 0);
  488. }
  489. /**
  490. * returns a copy of the collection with array type.
  491. * @param {Collection} collection - collection eg) node.childNodes, ...
  492. */
  493. function from(collection) {
  494. var result = [];
  495. var length = collection.length;
  496. var idx = -1;
  497. while (++idx < length) {
  498. result[idx] = collection[idx];
  499. }
  500. return result;
  501. }
  502. /**
  503. * returns whether list is empty or not
  504. */
  505. function isEmpty$1(array) {
  506. return !array || !array.length;
  507. }
  508. /**
  509. * cluster elements by predicate function.
  510. *
  511. * @param {Array} array - array
  512. * @param {Function} fn - predicate function for cluster rule
  513. * @param {Array[]}
  514. */
  515. function clusterBy(array, fn) {
  516. if (!array.length) {
  517. return [];
  518. }
  519. var aTail = tail(array);
  520. return aTail.reduce(function (memo, v) {
  521. var aLast = last(memo);
  522. if (fn(last(aLast), v)) {
  523. aLast[aLast.length] = v;
  524. } else {
  525. memo[memo.length] = [v];
  526. }
  527. return memo;
  528. }, [
  529. [head(array)]
  530. ]);
  531. }
  532. /**
  533. * returns a copy of the array with all false values removed
  534. *
  535. * @param {Array} array - array
  536. * @param {Function} fn - predicate function for cluster rule
  537. */
  538. function compact(array) {
  539. var aResult = [];
  540. for (var idx = 0, len = array.length; idx < len; idx++) {
  541. if (array[idx]) {
  542. aResult.push(array[idx]);
  543. }
  544. }
  545. return aResult;
  546. }
  547. /**
  548. * produces a duplicate-free version of the array
  549. *
  550. * @param {Array} array
  551. */
  552. function unique(array) {
  553. var results = [];
  554. for (var idx = 0, len = array.length; idx < len; idx++) {
  555. if (!contains(results, array[idx])) {
  556. results.push(array[idx]);
  557. }
  558. }
  559. return results;
  560. }
  561. /**
  562. * returns next item.
  563. * @param {Array} array
  564. */
  565. function next(array, item) {
  566. var idx = indexOf(array, item);
  567. if (idx === -1) {
  568. return null;
  569. }
  570. return array[idx + 1];
  571. }
  572. /**
  573. * returns prev item.
  574. * @param {Array} array
  575. */
  576. function prev(array, item) {
  577. var idx = indexOf(array, item);
  578. if (idx === -1) {
  579. return null;
  580. }
  581. return array[idx - 1];
  582. }
  583. /**
  584. * @class core.list
  585. *
  586. * list utils
  587. *
  588. * @singleton
  589. * @alternateClassName list
  590. */
  591. var lists = {
  592. head: head,
  593. last: last,
  594. initial: initial,
  595. tail: tail,
  596. prev: prev,
  597. next: next,
  598. find: find,
  599. contains: contains,
  600. all: all,
  601. sum: sum,
  602. from: from,
  603. isEmpty: isEmpty$1,
  604. clusterBy: clusterBy,
  605. compact: compact,
  606. unique: unique
  607. };
  608. var isSupportAmd = typeof define === 'function' && define.amd; // eslint-disable-line
  609. /**
  610. * returns whether font is installed or not.
  611. *
  612. * @param {String} fontName
  613. * @return {Boolean}
  614. */
  615. function isFontInstalled(fontName) {
  616. var testFontName = fontName === 'Comic Sans MS' ? 'Courier New' : 'Comic Sans MS';
  617. var $tester = $$1('<div>').css({
  618. position: 'absolute',
  619. left: '-9999px',
  620. top: '-9999px',
  621. fontSize: '200px'
  622. }).text('mmmmmmmmmwwwwwww').appendTo(document.body);
  623. var originalWidth = $tester.css('fontFamily', testFontName).width();
  624. var width = $tester.css('fontFamily', fontName + ',' + testFontName).width();
  625. $tester.remove();
  626. return originalWidth !== width;
  627. }
  628. var userAgent = navigator.userAgent;
  629. var isMSIE = /MSIE|Trident/i.test(userAgent);
  630. var browserVersion;
  631. if (isMSIE) {
  632. var matches = /MSIE (\d+[.]\d+)/.exec(userAgent);
  633. if (matches) {
  634. browserVersion = parseFloat(matches[1]);
  635. }
  636. matches = /Trident\/.*rv:([0-9]{1,}[.0-9]{0,})/.exec(userAgent);
  637. if (matches) {
  638. browserVersion = parseFloat(matches[1]);
  639. }
  640. }
  641. var isEdge = /Edge\/\d+/.test(userAgent);
  642. var hasCodeMirror = !!window.CodeMirror;
  643. if (!hasCodeMirror && isSupportAmd) {
  644. // Webpack
  645. if (typeof __webpack_require__ === 'function') {
  646. try {
  647. // If CodeMirror can't be resolved, `require.resolve` will throw an
  648. // exception and `hasCodeMirror` won't be set to `true`.
  649. require.resolve('codemirror');
  650. hasCodeMirror = true;
  651. } catch (e) {
  652. // do nothing
  653. }
  654. } else if (typeof require !== 'undefined') {
  655. // Browserify
  656. if (typeof require.resolve !== 'undefined') {
  657. try {
  658. // If CodeMirror can't be resolved, `require.resolve` will throw an
  659. // exception and `hasCodeMirror` won't be set to `true`.
  660. require.resolve('codemirror');
  661. hasCodeMirror = true;
  662. } catch (e) {
  663. // do nothing
  664. }
  665. // Almond/Require
  666. } else if (typeof require.specified !== 'undefined') {
  667. hasCodeMirror = require.specified('codemirror');
  668. }
  669. }
  670. }
  671. var isSupportTouch = (('ontouchstart' in window) ||
  672. (navigator.MaxTouchPoints > 0) ||
  673. (navigator.msMaxTouchPoints > 0));
  674. // [workaround] IE doesn't have input events for contentEditable
  675. // - see: https://goo.gl/4bfIvA
  676. var inputEventName = (isMSIE || isEdge) ? 'DOMCharacterDataModified DOMSubtreeModified DOMNodeInserted' : 'input';
  677. /**
  678. * @class core.env
  679. *
  680. * Object which check platform and agent
  681. *
  682. * @singleton
  683. * @alternateClassName env
  684. */
  685. var env = {
  686. isMac: navigator.appVersion.indexOf('Mac') > -1,
  687. isMSIE: isMSIE,
  688. isEdge: isEdge,
  689. isFF: !isEdge && /firefox/i.test(userAgent),
  690. isPhantom: /PhantomJS/i.test(userAgent),
  691. isWebkit: !isEdge && /webkit/i.test(userAgent),
  692. isChrome: !isEdge && /chrome/i.test(userAgent),
  693. isSafari: !isEdge && /safari/i.test(userAgent),
  694. browserVersion: browserVersion,
  695. jqueryVersion: parseFloat($$1.fn.jquery),
  696. isSupportAmd: isSupportAmd,
  697. isSupportTouch: isSupportTouch,
  698. hasCodeMirror: hasCodeMirror,
  699. isFontInstalled: isFontInstalled,
  700. isW3CRangeSupport: !!document.createRange,
  701. inputEventName: inputEventName
  702. };
  703. var NBSP_CHAR = String.fromCharCode(160);
  704. var ZERO_WIDTH_NBSP_CHAR = '\ufeff';
  705. /**
  706. * @method isEditable
  707. *
  708. * returns whether node is `note-editable` or not.
  709. *
  710. * @param {Node} node
  711. * @return {Boolean}
  712. */
  713. function isEditable(node) {
  714. return node && $$1(node).hasClass('note-editable');
  715. }
  716. /**
  717. * @method isControlSizing
  718. *
  719. * returns whether node is `note-control-sizing` or not.
  720. *
  721. * @param {Node} node
  722. * @return {Boolean}
  723. */
  724. function isControlSizing(node) {
  725. return node && $$1(node).hasClass('note-control-sizing');
  726. }
  727. /**
  728. * @method makePredByNodeName
  729. *
  730. * returns predicate which judge whether nodeName is same
  731. *
  732. * @param {String} nodeName
  733. * @return {Function}
  734. */
  735. function makePredByNodeName(nodeName) {
  736. nodeName = nodeName.toUpperCase();
  737. return function (node) {
  738. return node && node.nodeName.toUpperCase() === nodeName;
  739. };
  740. }
  741. /**
  742. * @method isText
  743. *
  744. *
  745. *
  746. * @param {Node} node
  747. * @return {Boolean} true if node's type is text(3)
  748. */
  749. function isText(node) {
  750. return node && node.nodeType === 3;
  751. }
  752. /**
  753. * @method isElement
  754. *
  755. *
  756. *
  757. * @param {Node} node
  758. * @return {Boolean} true if node's type is element(1)
  759. */
  760. function isElement(node) {
  761. return node && node.nodeType === 1;
  762. }
  763. /**
  764. * ex) br, col, embed, hr, img, input, ...
  765. * @see http://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
  766. */
  767. function isVoid(node) {
  768. return node && /^BR|^IMG|^HR|^IFRAME|^BUTTON|^INPUT/.test(node.nodeName.toUpperCase());
  769. }
  770. function isPara(node) {
  771. if (isEditable(node)) {
  772. return false;
  773. }
  774. // Chrome(v31.0), FF(v25.0.1) use DIV for paragraph
  775. return node && /^DIV|^P|^LI|^H[1-7]/.test(node.nodeName.toUpperCase());
  776. }
  777. function isHeading(node) {
  778. return node && /^H[1-7]/.test(node.nodeName.toUpperCase());
  779. }
  780. var isPre = makePredByNodeName('PRE');
  781. var isLi = makePredByNodeName('LI');
  782. function isPurePara(node) {
  783. return isPara(node) && !isLi(node);
  784. }
  785. var isTable = makePredByNodeName('TABLE');
  786. var isData = makePredByNodeName('DATA');
  787. function isInline(node) {
  788. return !isBodyContainer(node) &&
  789. !isList(node) &&
  790. !isHr(node) &&
  791. !isPara(node) &&
  792. !isTable(node) &&
  793. !isBlockquote(node) &&
  794. !isData(node);
  795. }
  796. function isList(node) {
  797. return node && /^UL|^OL/.test(node.nodeName.toUpperCase());
  798. }
  799. var isHr = makePredByNodeName('HR');
  800. function isCell(node) {
  801. return node && /^TD|^TH/.test(node.nodeName.toUpperCase());
  802. }
  803. var isBlockquote = makePredByNodeName('BLOCKQUOTE');
  804. function isBodyContainer(node) {
  805. return isCell(node) || isBlockquote(node) || isEditable(node);
  806. }
  807. var isAnchor = makePredByNodeName('A');
  808. function isParaInline(node) {
  809. return isInline(node) && !!ancestor(node, isPara);
  810. }
  811. function isBodyInline(node) {
  812. return isInline(node) && !ancestor(node, isPara);
  813. }
  814. var isBody = makePredByNodeName('BODY');
  815. /**
  816. * returns whether nodeB is closest sibling of nodeA
  817. *
  818. * @param {Node} nodeA
  819. * @param {Node} nodeB
  820. * @return {Boolean}
  821. */
  822. function isClosestSibling(nodeA, nodeB) {
  823. return nodeA.nextSibling === nodeB ||
  824. nodeA.previousSibling === nodeB;
  825. }
  826. /**
  827. * returns array of closest siblings with node
  828. *
  829. * @param {Node} node
  830. * @param {function} [pred] - predicate function
  831. * @return {Node[]}
  832. */
  833. function withClosestSiblings(node, pred) {
  834. pred = pred || func.ok;
  835. var siblings = [];
  836. if (node.previousSibling && pred(node.previousSibling)) {
  837. siblings.push(node.previousSibling);
  838. }
  839. siblings.push(node);
  840. if (node.nextSibling && pred(node.nextSibling)) {
  841. siblings.push(node.nextSibling);
  842. }
  843. return siblings;
  844. }
  845. /**
  846. * blank HTML for cursor position
  847. * - [workaround] old IE only works with &nbsp;
  848. * - [workaround] IE11 and other browser works with bogus br
  849. */
  850. var blankHTML = env.isMSIE && env.browserVersion < 11 ? '&nbsp;' : '<br>';
  851. /**
  852. * @method nodeLength
  853. *
  854. * returns #text's text size or element's childNodes size
  855. *
  856. * @param {Node} node
  857. */
  858. function nodeLength(node) {
  859. if (isText(node)) {
  860. return node.nodeValue.length;
  861. }
  862. if (node) {
  863. return node.childNodes.length;
  864. }
  865. return 0;
  866. }
  867. /**
  868. * returns whether node is empty or not.
  869. *
  870. * @param {Node} node
  871. * @return {Boolean}
  872. */
  873. function isEmpty(node) {
  874. var len = nodeLength(node);
  875. if (len === 0) {
  876. return true;
  877. } else if (!isText(node) && len === 1 && node.innerHTML === blankHTML) {
  878. // ex) <p><br></p>, <span><br></span>
  879. return true;
  880. } else if (lists.all(node.childNodes, isText) && node.innerHTML === '') {
  881. // ex) <p></p>, <span></span>
  882. return true;
  883. }
  884. return false;
  885. }
  886. /**
  887. * padding blankHTML if node is empty (for cursor position)
  888. */
  889. function paddingBlankHTML(node) {
  890. if (!isVoid(node) && !nodeLength(node)) {
  891. node.innerHTML = blankHTML;
  892. }
  893. }
  894. /**
  895. * find nearest ancestor predicate hit
  896. *
  897. * @param {Node} node
  898. * @param {Function} pred - predicate function
  899. */
  900. function ancestor(node, pred) {
  901. while (node) {
  902. if (pred(node)) {
  903. return node;
  904. }
  905. if (isEditable(node)) {
  906. break;
  907. }
  908. node = node.parentNode;
  909. }
  910. return null;
  911. }
  912. /**
  913. * find nearest ancestor only single child blood line and predicate hit
  914. *
  915. * @param {Node} node
  916. * @param {Function} pred - predicate function
  917. */
  918. function singleChildAncestor(node, pred) {
  919. node = node.parentNode;
  920. while (node) {
  921. if (nodeLength(node) !== 1) {
  922. break;
  923. }
  924. if (pred(node)) {
  925. return node;
  926. }
  927. if (isEditable(node)) {
  928. break;
  929. }
  930. node = node.parentNode;
  931. }
  932. return null;
  933. }
  934. /**
  935. * returns new array of ancestor nodes (until predicate hit).
  936. *
  937. * @param {Node} node
  938. * @param {Function} [optional] pred - predicate function
  939. */
  940. function listAncestor(node, pred) {
  941. pred = pred || func.fail;
  942. var ancestors = [];
  943. ancestor(node, function (el) {
  944. if (!isEditable(el)) {
  945. ancestors.push(el);
  946. }
  947. return pred(el);
  948. });
  949. return ancestors;
  950. }
  951. /**
  952. * find farthest ancestor predicate hit
  953. */
  954. function lastAncestor(node, pred) {
  955. var ancestors = listAncestor(node);
  956. return lists.last(ancestors.filter(pred));
  957. }
  958. /**
  959. * returns common ancestor node between two nodes.
  960. *
  961. * @param {Node} nodeA
  962. * @param {Node} nodeB
  963. */
  964. function commonAncestor(nodeA, nodeB) {
  965. var ancestors = listAncestor(nodeA);
  966. for (var n = nodeB; n; n = n.parentNode) {
  967. if ($$1.inArray(n, ancestors) > -1) {
  968. return n;
  969. }
  970. }
  971. return null; // difference document area
  972. }
  973. /**
  974. * listing all previous siblings (until predicate hit).
  975. *
  976. * @param {Node} node
  977. * @param {Function} [optional] pred - predicate function
  978. */
  979. function listPrev(node, pred) {
  980. pred = pred || func.fail;
  981. var nodes = [];
  982. while (node) {
  983. if (pred(node)) {
  984. break;
  985. }
  986. nodes.push(node);
  987. node = node.previousSibling;
  988. }
  989. return nodes;
  990. }
  991. /**
  992. * listing next siblings (until predicate hit).
  993. *
  994. * @param {Node} node
  995. * @param {Function} [pred] - predicate function
  996. */
  997. function listNext(node, pred) {
  998. pred = pred || func.fail;
  999. var nodes = [];
  1000. while (node) {
  1001. if (pred(node)) {
  1002. break;
  1003. }
  1004. nodes.push(node);
  1005. node = node.nextSibling;
  1006. }
  1007. return nodes;
  1008. }
  1009. /**
  1010. * listing descendant nodes
  1011. *
  1012. * @param {Node} node
  1013. * @param {Function} [pred] - predicate function
  1014. */
  1015. function listDescendant(node, pred) {
  1016. var descendants = [];
  1017. pred = pred || func.ok;
  1018. // start DFS(depth first search) with node
  1019. (function fnWalk(current) {
  1020. if (node !== current && pred(current)) {
  1021. descendants.push(current);
  1022. }
  1023. for (var idx = 0, len = current.childNodes.length; idx < len; idx++) {
  1024. fnWalk(current.childNodes[idx]);
  1025. }
  1026. })(node);
  1027. return descendants;
  1028. }
  1029. /**
  1030. * wrap node with new tag.
  1031. *
  1032. * @param {Node} node
  1033. * @param {Node} tagName of wrapper
  1034. * @return {Node} - wrapper
  1035. */
  1036. function wrap(node, wrapperName) {
  1037. var parent = node.parentNode;
  1038. var wrapper = $$1('<' + wrapperName + '>')[0];
  1039. parent.insertBefore(wrapper, node);
  1040. wrapper.appendChild(node);
  1041. return wrapper;
  1042. }
  1043. /**
  1044. * insert node after preceding
  1045. *
  1046. * @param {Node} node
  1047. * @param {Node} preceding - predicate function
  1048. */
  1049. function insertAfter(node, preceding) {
  1050. var next = preceding.nextSibling;
  1051. var parent = preceding.parentNode;
  1052. if (next) {
  1053. parent.insertBefore(node, next);
  1054. } else {
  1055. parent.appendChild(node);
  1056. }
  1057. return node;
  1058. }
  1059. /**
  1060. * append elements.
  1061. *
  1062. * @param {Node} node
  1063. * @param {Collection} aChild
  1064. */
  1065. function appendChildNodes(node, aChild) {
  1066. $$1.each(aChild, function (idx, child) {
  1067. node.appendChild(child);
  1068. });
  1069. return node;
  1070. }
  1071. /**
  1072. * returns whether boundaryPoint is left edge or not.
  1073. *
  1074. * @param {BoundaryPoint} point
  1075. * @return {Boolean}
  1076. */
  1077. function isLeftEdgePoint(point) {
  1078. return point.offset === 0;
  1079. }
  1080. /**
  1081. * returns whether boundaryPoint is right edge or not.
  1082. *
  1083. * @param {BoundaryPoint} point
  1084. * @return {Boolean}
  1085. */
  1086. function isRightEdgePoint(point) {
  1087. return point.offset === nodeLength(point.node);
  1088. }
  1089. /**
  1090. * returns whether boundaryPoint is edge or not.
  1091. *
  1092. * @param {BoundaryPoint} point
  1093. * @return {Boolean}
  1094. */
  1095. function isEdgePoint(point) {
  1096. return isLeftEdgePoint(point) || isRightEdgePoint(point);
  1097. }
  1098. /**
  1099. * returns whether node is left edge of ancestor or not.
  1100. *
  1101. * @param {Node} node
  1102. * @param {Node} ancestor
  1103. * @return {Boolean}
  1104. */
  1105. function isLeftEdgeOf(node, ancestor) {
  1106. while (node && node !== ancestor) {
  1107. if (position(node) !== 0) {
  1108. return false;
  1109. }
  1110. node = node.parentNode;
  1111. }
  1112. return true;
  1113. }
  1114. /**
  1115. * returns whether node is right edge of ancestor or not.
  1116. *
  1117. * @param {Node} node
  1118. * @param {Node} ancestor
  1119. * @return {Boolean}
  1120. */
  1121. function isRightEdgeOf(node, ancestor) {
  1122. if (!ancestor) {
  1123. return false;
  1124. }
  1125. while (node && node !== ancestor) {
  1126. if (position(node) !== nodeLength(node.parentNode) - 1) {
  1127. return false;
  1128. }
  1129. node = node.parentNode;
  1130. }
  1131. return true;
  1132. }
  1133. /**
  1134. * returns whether point is left edge of ancestor or not.
  1135. * @param {BoundaryPoint} point
  1136. * @param {Node} ancestor
  1137. * @return {Boolean}
  1138. */
  1139. function isLeftEdgePointOf(point, ancestor) {
  1140. return isLeftEdgePoint(point) && isLeftEdgeOf(point.node, ancestor);
  1141. }
  1142. /**
  1143. * returns whether point is right edge of ancestor or not.
  1144. * @param {BoundaryPoint} point
  1145. * @param {Node} ancestor
  1146. * @return {Boolean}
  1147. */
  1148. function isRightEdgePointOf(point, ancestor) {
  1149. return isRightEdgePoint(point) && isRightEdgeOf(point.node, ancestor);
  1150. }
  1151. /**
  1152. * returns offset from parent.
  1153. *
  1154. * @param {Node} node
  1155. */
  1156. function position(node) {
  1157. var offset = 0;
  1158. while ((node = node.previousSibling)) {
  1159. offset += 1;
  1160. }
  1161. return offset;
  1162. }
  1163. function hasChildren(node) {
  1164. return !!(node && node.childNodes && node.childNodes.length);
  1165. }
  1166. /**
  1167. * returns previous boundaryPoint
  1168. *
  1169. * @param {BoundaryPoint} point
  1170. * @param {Boolean} isSkipInnerOffset
  1171. * @return {BoundaryPoint}
  1172. */
  1173. function prevPoint(point, isSkipInnerOffset) {
  1174. var node;
  1175. var offset;
  1176. if (point.offset === 0) {
  1177. if (isEditable(point.node)) {
  1178. return null;
  1179. }
  1180. node = point.node.parentNode;
  1181. offset = position(point.node);
  1182. } else if (hasChildren(point.node)) {
  1183. node = point.node.childNodes[point.offset - 1];
  1184. offset = nodeLength(node);
  1185. } else {
  1186. node = point.node;
  1187. offset = isSkipInnerOffset ? 0 : point.offset - 1;
  1188. }
  1189. return {
  1190. node: node,
  1191. offset: offset
  1192. };
  1193. }
  1194. /**
  1195. * returns next boundaryPoint
  1196. *
  1197. * @param {BoundaryPoint} point
  1198. * @param {Boolean} isSkipInnerOffset
  1199. * @return {BoundaryPoint}
  1200. */
  1201. function nextPoint(point, isSkipInnerOffset) {
  1202. var node, offset;
  1203. if (nodeLength(point.node) === point.offset) {
  1204. if (isEditable(point.node)) {
  1205. return null;
  1206. }
  1207. node = point.node.parentNode;
  1208. offset = position(point.node) + 1;
  1209. } else if (hasChildren(point.node)) {
  1210. node = point.node.childNodes[point.offset];
  1211. offset = 0;
  1212. } else {
  1213. node = point.node;
  1214. offset = isSkipInnerOffset ? nodeLength(point.node) : point.offset + 1;
  1215. }
  1216. return {
  1217. node: node,
  1218. offset: offset
  1219. };
  1220. }
  1221. /**
  1222. * returns whether pointA and pointB is same or not.
  1223. *
  1224. * @param {BoundaryPoint} pointA
  1225. * @param {BoundaryPoint} pointB
  1226. * @return {Boolean}
  1227. */
  1228. function isSamePoint(pointA, pointB) {
  1229. return pointA.node === pointB.node && pointA.offset === pointB.offset;
  1230. }
  1231. /**
  1232. * returns whether point is visible (can set cursor) or not.
  1233. *
  1234. * @param {BoundaryPoint} point
  1235. * @return {Boolean}
  1236. */
  1237. function isVisiblePoint(point) {
  1238. if (isText(point.node) || !hasChildren(point.node) || isEmpty(point.node)) {
  1239. return true;
  1240. }
  1241. var leftNode = point.node.childNodes[point.offset - 1];
  1242. var rightNode = point.node.childNodes[point.offset];
  1243. if ((!leftNode || isVoid(leftNode)) && (!rightNode || isVoid(rightNode))) {
  1244. return true;
  1245. }
  1246. return false;
  1247. }
  1248. /**
  1249. * @method prevPointUtil
  1250. *
  1251. * @param {BoundaryPoint} point
  1252. * @param {Function} pred
  1253. * @return {BoundaryPoint}
  1254. */
  1255. function prevPointUntil(point, pred) {
  1256. while (point) {
  1257. if (pred(point)) {
  1258. return point;
  1259. }
  1260. point = prevPoint(point);
  1261. }
  1262. return null;
  1263. }
  1264. /**
  1265. * @method nextPointUntil
  1266. *
  1267. * @param {BoundaryPoint} point
  1268. * @param {Function} pred
  1269. * @return {BoundaryPoint}
  1270. */
  1271. function nextPointUntil(point, pred) {
  1272. while (point) {
  1273. if (pred(point)) {
  1274. return point;
  1275. }
  1276. point = nextPoint(point);
  1277. }
  1278. return null;
  1279. }
  1280. /**
  1281. * returns whether point has character or not.
  1282. *
  1283. * @param {Point} point
  1284. * @return {Boolean}
  1285. */
  1286. function isCharPoint(point) {
  1287. if (!isText(point.node)) {
  1288. return false;
  1289. }
  1290. var ch = point.node.nodeValue.charAt(point.offset - 1);
  1291. return ch && (ch !== ' ' && ch !== NBSP_CHAR);
  1292. }
  1293. /**
  1294. * @method walkPoint
  1295. *
  1296. * @param {BoundaryPoint} startPoint
  1297. * @param {BoundaryPoint} endPoint
  1298. * @param {Function} handler
  1299. * @param {Boolean} isSkipInnerOffset
  1300. */
  1301. function walkPoint(startPoint, endPoint, handler, isSkipInnerOffset) {
  1302. var point = startPoint;
  1303. while (point) {
  1304. handler(point);
  1305. if (isSamePoint(point, endPoint)) {
  1306. break;
  1307. }
  1308. var isSkipOffset = isSkipInnerOffset &&
  1309. startPoint.node !== point.node &&
  1310. endPoint.node !== point.node;
  1311. point = nextPoint(point, isSkipOffset);
  1312. }
  1313. }
  1314. /**
  1315. * @method makeOffsetPath
  1316. *
  1317. * return offsetPath(array of offset) from ancestor
  1318. *
  1319. * @param {Node} ancestor - ancestor node
  1320. * @param {Node} node
  1321. */
  1322. function makeOffsetPath(ancestor, node) {
  1323. var ancestors = listAncestor(node, func.eq(ancestor));
  1324. return ancestors.map(position).reverse();
  1325. }
  1326. /**
  1327. * @method fromOffsetPath
  1328. *
  1329. * return element from offsetPath(array of offset)
  1330. *
  1331. * @param {Node} ancestor - ancestor node
  1332. * @param {array} offsets - offsetPath
  1333. */
  1334. function fromOffsetPath(ancestor, offsets) {
  1335. var current = ancestor;
  1336. for (var i = 0, len = offsets.length; i < len; i++) {
  1337. if (current.childNodes.length <= offsets[i]) {
  1338. current = current.childNodes[current.childNodes.length - 1];
  1339. } else {
  1340. current = current.childNodes[offsets[i]];
  1341. }
  1342. }
  1343. return current;
  1344. }
  1345. /**
  1346. * @method splitNode
  1347. *
  1348. * split element or #text
  1349. *
  1350. * @param {BoundaryPoint} point
  1351. * @param {Object} [options]
  1352. * @param {Boolean} [options.isSkipPaddingBlankHTML] - default: false
  1353. * @param {Boolean} [options.isNotSplitEdgePoint] - default: false
  1354. * @return {Node} right node of boundaryPoint
  1355. */
  1356. function splitNode(point, options) {
  1357. var isSkipPaddingBlankHTML = options && options.isSkipPaddingBlankHTML;
  1358. var isNotSplitEdgePoint = options && options.isNotSplitEdgePoint;
  1359. // edge case
  1360. if (isEdgePoint(point) && (isText(point.node) || isNotSplitEdgePoint)) {
  1361. if (isLeftEdgePoint(point)) {
  1362. return point.node;
  1363. } else if (isRightEdgePoint(point)) {
  1364. return point.node.nextSibling;
  1365. }
  1366. }
  1367. // split #text
  1368. if (isText(point.node)) {
  1369. return point.node.splitText(point.offset);
  1370. } else {
  1371. var childNode = point.node.childNodes[point.offset];
  1372. var clone = insertAfter(point.node.cloneNode(false), point.node);
  1373. appendChildNodes(clone, listNext(childNode));
  1374. if (!isSkipPaddingBlankHTML) {
  1375. paddingBlankHTML(point.node);
  1376. paddingBlankHTML(clone);
  1377. }
  1378. return clone;
  1379. }
  1380. }
  1381. /**
  1382. * @method splitTree
  1383. *
  1384. * split tree by point
  1385. *
  1386. * @param {Node} root - split root
  1387. * @param {BoundaryPoint} point
  1388. * @param {Object} [options]
  1389. * @param {Boolean} [options.isSkipPaddingBlankHTML] - default: false
  1390. * @param {Boolean} [options.isNotSplitEdgePoint] - default: false
  1391. * @return {Node} right node of boundaryPoint
  1392. */
  1393. function splitTree(root, point, options) {
  1394. // ex) [#text, <span>, <p>]
  1395. var ancestors = listAncestor(point.node, func.eq(root));
  1396. if (!ancestors.length) {
  1397. return null;
  1398. } else if (ancestors.length === 1) {
  1399. return splitNode(point, options);
  1400. }
  1401. return ancestors.reduce(function (node, parent) {
  1402. if (node === point.node) {
  1403. node = splitNode(point, options);
  1404. }
  1405. return splitNode({
  1406. node: parent,
  1407. offset: node ? position(node) : nodeLength(parent)
  1408. }, options);
  1409. });
  1410. }
  1411. /**
  1412. * split point
  1413. *
  1414. * @param {Point} point
  1415. * @param {Boolean} isInline
  1416. * @return {Object}
  1417. */
  1418. function splitPoint(point, isInline) {
  1419. // find splitRoot, container
  1420. // - inline: splitRoot is a child of paragraph
  1421. // - block: splitRoot is a child of bodyContainer
  1422. var pred = isInline ? isPara : isBodyContainer;
  1423. var ancestors = listAncestor(point.node, pred);
  1424. var topAncestor = lists.last(ancestors) || point.node;
  1425. var splitRoot, container;
  1426. if (pred(topAncestor)) {
  1427. splitRoot = ancestors[ancestors.length - 2];
  1428. container = topAncestor;
  1429. } else {
  1430. splitRoot = topAncestor;
  1431. container = splitRoot.parentNode;
  1432. }
  1433. // if splitRoot is exists, split with splitTree
  1434. var pivot = splitRoot && splitTree(splitRoot, point, {
  1435. isSkipPaddingBlankHTML: isInline,
  1436. isNotSplitEdgePoint: isInline
  1437. });
  1438. // if container is point.node, find pivot with point.offset
  1439. if (!pivot && container === point.node) {
  1440. pivot = point.node.childNodes[point.offset];
  1441. }
  1442. return {
  1443. rightNode: pivot,
  1444. container: container
  1445. };
  1446. }
  1447. function create(nodeName) {
  1448. return document.createElement(nodeName);
  1449. }
  1450. function createText(text) {
  1451. return document.createTextNode(text);
  1452. }
  1453. /**
  1454. * @method remove
  1455. *
  1456. * remove node, (isRemoveChild: remove child or not)
  1457. *
  1458. * @param {Node} node
  1459. * @param {Boolean} isRemoveChild
  1460. */
  1461. function remove(node, isRemoveChild) {
  1462. if (!node || !node.parentNode) {
  1463. return;
  1464. }
  1465. if (node.removeNode) {
  1466. return node.removeNode(isRemoveChild);
  1467. }
  1468. var parent = node.parentNode;
  1469. if (!isRemoveChild) {
  1470. var nodes = [];
  1471. for (var i = 0, len = node.childNodes.length; i < len; i++) {
  1472. nodes.push(node.childNodes[i]);
  1473. }
  1474. for (var i = 0, len = nodes.length; i < len; i++) {
  1475. parent.insertBefore(nodes[i], node);
  1476. }
  1477. }
  1478. parent.removeChild(node);
  1479. }
  1480. /**
  1481. * @method removeWhile
  1482. *
  1483. * @param {Node} node
  1484. * @param {Function} pred
  1485. */
  1486. function removeWhile(node, pred) {
  1487. while (node) {
  1488. if (isEditable(node) || !pred(node)) {
  1489. break;
  1490. }
  1491. var parent = node.parentNode;
  1492. remove(node);
  1493. node = parent;
  1494. }
  1495. }
  1496. /**
  1497. * @method replace
  1498. *
  1499. * replace node with provided nodeName
  1500. *
  1501. * @param {Node} node
  1502. * @param {String} nodeName
  1503. * @return {Node} - new node
  1504. */
  1505. function replace(node, nodeName) {
  1506. if (node.nodeName.toUpperCase() === nodeName.toUpperCase()) {
  1507. return node;
  1508. }
  1509. var newNode = create(nodeName);
  1510. if (node.style.cssText) {
  1511. newNode.style.cssText = node.style.cssText;
  1512. }
  1513. appendChildNodes(newNode, lists.from(node.childNodes));
  1514. insertAfter(newNode, node);
  1515. remove(node);
  1516. return newNode;
  1517. }
  1518. var isTextarea = makePredByNodeName('TEXTAREA');
  1519. /**
  1520. * @param {jQuery} $node
  1521. * @param {Boolean} [stripLinebreaks] - default: false
  1522. */
  1523. function value($node, stripLinebreaks) {
  1524. var val = isTextarea($node[0]) ? $node.val() : $node.html();
  1525. if (stripLinebreaks) {
  1526. return val.replace(/[\n\r]/g, '');
  1527. }
  1528. return val;
  1529. }
  1530. /**
  1531. * @method html
  1532. *
  1533. * get the HTML contents of node
  1534. *
  1535. * @param {jQuery} $node
  1536. * @param {Boolean} [isNewlineOnBlock]
  1537. */
  1538. function html($node, isNewlineOnBlock) {
  1539. var markup = value($node);
  1540. if (isNewlineOnBlock) {
  1541. var regexTag = /<(\/?)(\b(?!!)[^>\s]*)(.*?)(\s*\/?>)/g;
  1542. markup = markup.replace(regexTag, function (match, endSlash, name) {
  1543. name = name.toUpperCase();
  1544. var isEndOfInlineContainer = /^DIV|^TD|^TH|^P|^LI|^H[1-7]/.test(name) &&
  1545. !!endSlash;
  1546. var isBlockNode = /^BLOCKQUOTE|^TABLE|^TBODY|^TR|^HR|^UL|^OL/.test(name);
  1547. return match + ((isEndOfInlineContainer || isBlockNode) ? '\n' : '');
  1548. });
  1549. markup = $$1.trim(markup);
  1550. }
  1551. return markup;
  1552. }
  1553. function posFromPlaceholder(placeholder) {
  1554. var $placeholder = $$1(placeholder);
  1555. var pos = $placeholder.offset();
  1556. var height = $placeholder.outerHeight(true); // include margin
  1557. return {
  1558. left: pos.left,
  1559. top: pos.top + height
  1560. };
  1561. }
  1562. function attachEvents($node, events) {
  1563. Object.keys(events).forEach(function (key) {
  1564. $node.on(key, events[key]);
  1565. });
  1566. }
  1567. function detachEvents($node, events) {
  1568. Object.keys(events).forEach(function (key) {
  1569. $node.off(key, events[key]);
  1570. });
  1571. }
  1572. /**
  1573. * @method isCustomStyleTag
  1574. *
  1575. * assert if a node contains a "note-styletag" class,
  1576. * which implies that's a custom-made style tag node
  1577. *
  1578. * @param {Node} an HTML DOM node
  1579. */
  1580. function isCustomStyleTag(node) {
  1581. return node && !isText(node) && lists.contains(node.classList, 'note-styletag');
  1582. }
  1583. var dom = {
  1584. /** @property {String} NBSP_CHAR */
  1585. NBSP_CHAR: NBSP_CHAR,
  1586. /** @property {String} ZERO_WIDTH_NBSP_CHAR */
  1587. ZERO_WIDTH_NBSP_CHAR: ZERO_WIDTH_NBSP_CHAR,
  1588. /** @property {String} blank */
  1589. blank: blankHTML,
  1590. /** @property {String} emptyPara */
  1591. emptyPara: "<p>" + blankHTML + "</p>",
  1592. makePredByNodeName: makePredByNodeName,
  1593. isEditable: isEditable,
  1594. isControlSizing: isControlSizing,
  1595. isText: isText,
  1596. isElement: isElement,
  1597. isVoid: isVoid,
  1598. isPara: isPara,
  1599. isPurePara: isPurePara,
  1600. isHeading: isHeading,
  1601. isInline: isInline,
  1602. isBlock: func.not(isInline),
  1603. isBodyInline: isBodyInline,
  1604. isBody: isBody,
  1605. isParaInline: isParaInline,
  1606. isPre: isPre,
  1607. isList: isList,
  1608. isTable: isTable,
  1609. isData: isData,
  1610. isCell: isCell,
  1611. isBlockquote: isBlockquote,
  1612. isBodyContainer: isBodyContainer,
  1613. isAnchor: isAnchor,
  1614. isDiv: makePredByNodeName('DIV'),
  1615. isLi: isLi,
  1616. isBR: makePredByNodeName('BR'),
  1617. isSpan: makePredByNodeName('SPAN'),
  1618. isB: makePredByNodeName('B'),
  1619. isU: makePredByNodeName('U'),
  1620. isS: makePredByNodeName('S'),
  1621. isI: makePredByNodeName('I'),
  1622. isImg: makePredByNodeName('IMG'),
  1623. isTextarea: isTextarea,
  1624. isEmpty: isEmpty,
  1625. isEmptyAnchor: func.and(isAnchor, isEmpty),
  1626. isClosestSibling: isClosestSibling,
  1627. withClosestSiblings: withClosestSiblings,
  1628. nodeLength: nodeLength,
  1629. isLeftEdgePoint: isLeftEdgePoint,
  1630. isRightEdgePoint: isRightEdgePoint,
  1631. isEdgePoint: isEdgePoint,
  1632. isLeftEdgeOf: isLeftEdgeOf,
  1633. isRightEdgeOf: isRightEdgeOf,
  1634. isLeftEdgePointOf: isLeftEdgePointOf,
  1635. isRightEdgePointOf: isRightEdgePointOf,
  1636. prevPoint: prevPoint,
  1637. nextPoint: nextPoint,
  1638. isSamePoint: isSamePoint,
  1639. isVisiblePoint: isVisiblePoint,
  1640. prevPointUntil: prevPointUntil,
  1641. nextPointUntil: nextPointUntil,
  1642. isCharPoint: isCharPoint,
  1643. walkPoint: walkPoint,
  1644. ancestor: ancestor,
  1645. singleChildAncestor: singleChildAncestor,
  1646. listAncestor: listAncestor,
  1647. lastAncestor: lastAncestor,
  1648. listNext: listNext,
  1649. listPrev: listPrev,
  1650. listDescendant: listDescendant,
  1651. commonAncestor: commonAncestor,
  1652. wrap: wrap,
  1653. insertAfter: insertAfter,
  1654. appendChildNodes: appendChildNodes,
  1655. position: position,
  1656. hasChildren: hasChildren,
  1657. makeOffsetPath: makeOffsetPath,
  1658. fromOffsetPath: fromOffsetPath,
  1659. splitTree: splitTree,
  1660. splitPoint: splitPoint,
  1661. create: create,
  1662. createText: createText,
  1663. remove: remove,
  1664. removeWhile: removeWhile,
  1665. replace: replace,
  1666. html: html,
  1667. value: value,
  1668. posFromPlaceholder: posFromPlaceholder,
  1669. attachEvents: attachEvents,
  1670. detachEvents: detachEvents,
  1671. isCustomStyleTag: isCustomStyleTag
  1672. };
  1673. $$1.summernote = $$1.summernote || {
  1674. lang: {}
  1675. };
  1676. $$1.extend($$1.summernote.lang, {
  1677. 'en-US': {
  1678. font: {
  1679. bold: 'Bold',
  1680. italic: 'Italic',
  1681. underline: 'Underline',
  1682. clear: 'Remove Font Style',
  1683. height: 'Line Height',
  1684. name: 'Font Family',
  1685. strikethrough: 'Strikethrough',
  1686. subscript: 'Subscript',
  1687. superscript: 'Superscript',
  1688. size: 'Font Size'
  1689. },
  1690. image: {
  1691. image: 'Picture',
  1692. insert: 'Insert Image',
  1693. resizeFull: 'Resize Full',
  1694. resizeHalf: 'Resize Half',
  1695. resizeQuarter: 'Resize Quarter',
  1696. floatLeft: 'Float Left',
  1697. floatRight: 'Float Right',
  1698. floatNone: 'Float None',
  1699. shapeRounded: 'Shape: Rounded',
  1700. shapeCircle: 'Shape: Circle',
  1701. shapeThumbnail: 'Shape: Thumbnail',
  1702. shapeNone: 'Shape: None',
  1703. dragImageHere: 'Drag image or text here',
  1704. dropImage: 'Drop image or Text',
  1705. selectFromFiles: 'Select from files',
  1706. maximumFileSize: 'Maximum file size',
  1707. maximumFileSizeError: 'Maximum file size exceeded.',
  1708. url: 'Image URL',
  1709. remove: 'Remove Image',
  1710. original: 'Original'
  1711. },
  1712. video: {
  1713. video: 'Video',
  1714. videoLink: 'Video Link',
  1715. insert: 'Insert Video',
  1716. url: 'Video URL',
  1717. providers: '(YouTube, Vimeo, Vine, Instagram, DailyMotion or Youku)'
  1718. },
  1719. link: {
  1720. link: 'Link',
  1721. insert: 'Insert Link',
  1722. unlink: 'Unlink',
  1723. edit: 'Edit',
  1724. textToDisplay: 'Text to display',
  1725. url: 'To what URL should this link go?',
  1726. openInNewWindow: 'Open in new window'
  1727. },
  1728. table: {
  1729. table: 'Table',
  1730. addRowAbove: 'Add row above',
  1731. addRowBelow: 'Add row below',
  1732. addColLeft: 'Add column left',
  1733. addColRight: 'Add column right',
  1734. delRow: 'Delete row',
  1735. delCol: 'Delete column',
  1736. delTable: 'Delete table'
  1737. },
  1738. hr: {
  1739. insert: 'Insert Horizontal Rule'
  1740. },
  1741. style: {
  1742. style: 'Style',
  1743. p: 'Normal',
  1744. blockquote: 'Quote',
  1745. pre: 'Code',
  1746. h1: 'Header 1',
  1747. h2: 'Header 2',
  1748. h3: 'Header 3',
  1749. h4: 'Header 4',
  1750. h5: 'Header 5',
  1751. h6: 'Header 6'
  1752. },
  1753. lists: {
  1754. unordered: 'Unordered list',
  1755. ordered: 'Ordered list'
  1756. },
  1757. options: {
  1758. help: 'Help',
  1759. fullscreen: 'Full Screen',
  1760. codeview: 'Code View'
  1761. },
  1762. paragraph: {
  1763. paragraph: 'Paragraph',
  1764. outdent: 'Outdent',
  1765. indent: 'Indent',
  1766. left: 'Align left',
  1767. center: 'Align center',
  1768. right: 'Align right',
  1769. justify: 'Justify full'
  1770. },
  1771. color: {
  1772. recent: 'Recent Color',
  1773. more: 'More Color',
  1774. background: 'Background Color',
  1775. foreground: 'Foreground Color',
  1776. transparent: 'Transparent',
  1777. setTransparent: 'Set transparent',
  1778. reset: 'Reset',
  1779. resetToDefault: 'Reset to default'
  1780. },
  1781. shortcut: {
  1782. shortcuts: 'Keyboard shortcuts',
  1783. close: 'Close',
  1784. textFormatting: 'Text formatting',
  1785. action: 'Action',
  1786. paragraphFormatting: 'Paragraph formatting',
  1787. documentStyle: 'Document Style',
  1788. extraKeys: 'Extra keys'
  1789. },
  1790. help: {
  1791. 'insertParagraph': 'Insert Paragraph',
  1792. 'undo': 'Undoes the last command',
  1793. 'redo': 'Redoes the last command',
  1794. 'tab': 'Tab',
  1795. 'untab': 'Untab',
  1796. 'bold': 'Set a bold style',
  1797. 'italic': 'Set a italic style',
  1798. 'underline': 'Set a underline style',
  1799. 'strikethrough': 'Set a strikethrough style',
  1800. 'removeFormat': 'Clean a style',
  1801. 'justifyLeft': 'Set left align',
  1802. 'justifyCenter': 'Set center align',
  1803. 'justifyRight': 'Set right align',
  1804. 'justifyFull': 'Set full align',
  1805. 'insertUnorderedList': 'Toggle unordered list',
  1806. 'insertOrderedList': 'Toggle ordered list',
  1807. 'outdent': 'Outdent on current paragraph',
  1808. 'indent': 'Indent on current paragraph',
  1809. 'formatPara': 'Change current block\'s format as a paragraph(P tag)',
  1810. 'formatH1': 'Change current block\'s format as H1',
  1811. 'formatH2': 'Change current block\'s format as H2',
  1812. 'formatH3': 'Change current block\'s format as H3',
  1813. 'formatH4': 'Change current block\'s format as H4',
  1814. 'formatH5': 'Change current block\'s format as H5',
  1815. 'formatH6': 'Change current block\'s format as H6',
  1816. 'insertHorizontalRule': 'Insert horizontal rule',
  1817. 'linkDialog.show': 'Show Link Dialog'
  1818. },
  1819. history: {
  1820. undo: 'Undo',
  1821. redo: 'Redo'
  1822. },
  1823. specialChar: {
  1824. specialChar: 'SPECIAL CHARACTERS',
  1825. select: 'Select Special characters'
  1826. }
  1827. }
  1828. });
  1829. var KEY_MAP = {
  1830. 'BACKSPACE': 8,
  1831. 'TAB': 9,
  1832. 'ENTER': 13,
  1833. 'SPACE': 32,
  1834. 'DELETE': 46,
  1835. // Arrow
  1836. 'LEFT': 37,
  1837. 'UP': 38,
  1838. 'RIGHT': 39,
  1839. 'DOWN': 40,
  1840. // Number: 0-9
  1841. 'NUM0': 48,
  1842. 'NUM1': 49,
  1843. 'NUM2': 50,
  1844. 'NUM3': 51,
  1845. 'NUM4': 52,
  1846. 'NUM5': 53,
  1847. 'NUM6': 54,
  1848. 'NUM7': 55,
  1849. 'NUM8': 56,
  1850. // Alphabet: a-z
  1851. 'B': 66,
  1852. 'E': 69,
  1853. 'I': 73,
  1854. 'J': 74,
  1855. 'K': 75,
  1856. 'L': 76,
  1857. 'R': 82,
  1858. 'S': 83,
  1859. 'U': 85,
  1860. 'V': 86,
  1861. 'Y': 89,
  1862. 'Z': 90,
  1863. 'SLASH': 191,
  1864. 'LEFTBRACKET': 219,
  1865. 'BACKSLASH': 220,
  1866. 'RIGHTBRACKET': 221
  1867. };
  1868. /**
  1869. * @class core.key
  1870. *
  1871. * Object for keycodes.
  1872. *
  1873. * @singleton
  1874. * @alternateClassName key
  1875. */
  1876. var key = {
  1877. /**
  1878. * @method isEdit
  1879. *
  1880. * @param {Number} keyCode
  1881. * @return {Boolean}
  1882. */
  1883. isEdit: function (keyCode) {
  1884. return lists.contains([
  1885. KEY_MAP.BACKSPACE,
  1886. KEY_MAP.TAB,
  1887. KEY_MAP.ENTER,
  1888. KEY_MAP.SPACE,
  1889. KEY_MAP.DELETE
  1890. ], keyCode);
  1891. },
  1892. /**
  1893. * @method isMove
  1894. *
  1895. * @param {Number} keyCode
  1896. * @return {Boolean}
  1897. */
  1898. isMove: function (keyCode) {
  1899. return lists.contains([
  1900. KEY_MAP.LEFT,
  1901. KEY_MAP.UP,
  1902. KEY_MAP.RIGHT,
  1903. KEY_MAP.DOWN
  1904. ], keyCode);
  1905. },
  1906. /**
  1907. * @property {Object} nameFromCode
  1908. * @property {String} nameFromCode.8 "BACKSPACE"
  1909. */
  1910. nameFromCode: func.invertObject(KEY_MAP),
  1911. code: KEY_MAP
  1912. };
  1913. /**
  1914. * return boundaryPoint from TextRange, inspired by Andy Na's HuskyRange.js
  1915. *
  1916. * @param {TextRange} textRange
  1917. * @param {Boolean} isStart
  1918. * @return {BoundaryPoint}
  1919. *
  1920. * @see http://msdn.microsoft.com/en-us/library/ie/ms535872(v=vs.85).aspx
  1921. */
  1922. function textRangeToPoint(textRange, isStart) {
  1923. var container = textRange.parentElement();
  1924. var offset;
  1925. var tester = document.body.createTextRange();
  1926. var prevContainer;
  1927. var childNodes = lists.from(container.childNodes);
  1928. for (offset = 0; offset < childNodes.length; offset++) {
  1929. if (dom.isText(childNodes[offset])) {
  1930. continue;
  1931. }
  1932. tester.moveToElementText(childNodes[offset]);
  1933. if (tester.compareEndPoints('StartToStart', textRange) >= 0) {
  1934. break;
  1935. }
  1936. prevContainer = childNodes[offset];
  1937. }
  1938. if (offset !== 0 && dom.isText(childNodes[offset - 1])) {
  1939. var textRangeStart = document.body.createTextRange();
  1940. var curTextNode = null;
  1941. textRangeStart.moveToElementText(prevContainer || container);
  1942. textRangeStart.collapse(!prevContainer);
  1943. curTextNode = prevContainer ? prevContainer.nextSibling : container.firstChild;
  1944. var pointTester = textRange.duplicate();
  1945. pointTester.setEndPoint('StartToStart', textRangeStart);
  1946. var textCount = pointTester.text.replace(/[\r\n]/g, '').length;
  1947. while (textCount > curTextNode.nodeValue.length && curTextNode.nextSibling) {
  1948. textCount -= curTextNode.nodeValue.length;
  1949. curTextNode = curTextNode.nextSibling;
  1950. }
  1951. // [workaround] enforce IE to re-reference curTextNode, hack
  1952. var dummy = curTextNode.nodeValue; // eslint-disable-line
  1953. if (isStart && curTextNode.nextSibling && dom.isText(curTextNode.nextSibling) &&
  1954. textCount === curTextNode.nodeValue.length) {
  1955. textCount -= curTextNode.nodeValue.length;
  1956. curTextNode = curTextNode.nextSibling;
  1957. }
  1958. container = curTextNode;
  1959. offset = textCount;
  1960. }
  1961. return {
  1962. cont: container,
  1963. offset: offset
  1964. };
  1965. }
  1966. /**
  1967. * return TextRange from boundary point (inspired by google closure-library)
  1968. * @param {BoundaryPoint} point
  1969. * @return {TextRange}
  1970. */
  1971. function pointToTextRange(point) {
  1972. var textRangeInfo = function (container, offset) {
  1973. var node, isCollapseToStart;
  1974. if (dom.isText(container)) {
  1975. var prevTextNodes = dom.listPrev(container, func.not(dom.isText));
  1976. var prevContainer = lists.last(prevTextNodes).previousSibling;
  1977. node = prevContainer || container.parentNode;
  1978. offset += lists.sum(lists.tail(prevTextNodes), dom.nodeLength);
  1979. isCollapseToStart = !prevContainer;
  1980. } else {
  1981. node = container.childNodes[offset] || container;
  1982. if (dom.isText(node)) {
  1983. return textRangeInfo(node, 0);
  1984. }
  1985. offset = 0;
  1986. isCollapseToStart = false;
  1987. }
  1988. return {
  1989. node: node,
  1990. collapseToStart: isCollapseToStart,
  1991. offset: offset
  1992. };
  1993. };
  1994. var textRange = document.body.createTextRange();
  1995. var info = textRangeInfo(point.node, point.offset);
  1996. textRange.moveToElementText(info.node);
  1997. textRange.collapse(info.collapseToStart);
  1998. textRange.moveStart('character', info.offset);
  1999. return textRange;
  2000. }
  2001. /**
  2002. * Wrapped Range
  2003. *
  2004. * @constructor
  2005. * @param {Node} sc - start container
  2006. * @param {Number} so - start offset
  2007. * @param {Node} ec - end container
  2008. * @param {Number} eo - end offset
  2009. */
  2010. var WrappedRange = /** @class */ (function () {
  2011. function WrappedRange(sc, so, ec, eo) {
  2012. this.sc = sc;
  2013. this.so = so;
  2014. this.ec = ec;
  2015. this.eo = eo;
  2016. // isOnEditable: judge whether range is on editable or not
  2017. this.isOnEditable = this.makeIsOn(dom.isEditable);
  2018. // isOnList: judge whether range is on list node or not
  2019. this.isOnList = this.makeIsOn(dom.isList);
  2020. // isOnAnchor: judge whether range is on anchor node or not
  2021. this.isOnAnchor = this.makeIsOn(dom.isAnchor);
  2022. // isOnCell: judge whether range is on cell node or not
  2023. this.isOnCell = this.makeIsOn(dom.isCell);
  2024. // isOnData: judge whether range is on data node or not
  2025. this.isOnData = this.makeIsOn(dom.isData);
  2026. }
  2027. // nativeRange: get nativeRange from sc, so, ec, eo
  2028. WrappedRange.prototype.nativeRange = function () {
  2029. if (env.isW3CRangeSupport) {
  2030. var w3cRange = document.createRange();
  2031. w3cRange.setStart(this.sc, this.so);
  2032. w3cRange.setEnd(this.ec, this.eo);
  2033. return w3cRange;
  2034. } else {
  2035. var textRange = pointToTextRange({
  2036. node: this.sc,
  2037. offset: this.so
  2038. });
  2039. textRange.setEndPoint('EndToEnd', pointToTextRange({
  2040. node: this.ec,
  2041. offset: this.eo
  2042. }));
  2043. return textRange;
  2044. }
  2045. };
  2046. WrappedRange.prototype.getPoints = function () {
  2047. return {
  2048. sc: this.sc,
  2049. so: this.so,
  2050. ec: this.ec,
  2051. eo: this.eo
  2052. };
  2053. };
  2054. WrappedRange.prototype.getStartPoint = function () {
  2055. return {
  2056. node: this.sc,
  2057. offset: this.so
  2058. };
  2059. };
  2060. WrappedRange.prototype.getEndPoint = function () {
  2061. return {
  2062. node: this.ec,
  2063. offset: this.eo
  2064. };
  2065. };
  2066. /**
  2067. * select update visible range
  2068. */
  2069. WrappedRange.prototype.select = function () {
  2070. var nativeRng = this.nativeRange();
  2071. if (env.isW3CRangeSupport) {
  2072. var selection = document.getSelection();
  2073. if (selection.rangeCount > 0) {
  2074. selection.removeAllRanges();
  2075. }
  2076. selection.addRange(nativeRng);
  2077. } else {
  2078. nativeRng.select();
  2079. }
  2080. return this;
  2081. };
  2082. /**
  2083. * Moves the scrollbar to start container(sc) of current range
  2084. *
  2085. * @return {WrappedRange}
  2086. */
  2087. WrappedRange.prototype.scrollIntoView = function (container) {
  2088. var height = $$1(container).height();
  2089. if (container.scrollTop + height < this.sc.offsetTop) {
  2090. container.scrollTop += Math.abs(container.scrollTop + height - this.sc.offsetTop);
  2091. }
  2092. return this;
  2093. };
  2094. /**
  2095. * @return {WrappedRange}
  2096. */
  2097. WrappedRange.prototype.normalize = function () {
  2098. /**
  2099. * @param {BoundaryPoint} point
  2100. * @param {Boolean} isLeftToRight
  2101. * @return {BoundaryPoint}
  2102. */
  2103. var getVisiblePoint = function (point, isLeftToRight) {
  2104. if ((dom.isVisiblePoint(point) && !dom.isEdgePoint(point)) ||
  2105. (dom.isVisiblePoint(point) && dom.isRightEdgePoint(point) && !isLeftToRight) ||
  2106. (dom.isVisiblePoint(point) && dom.isLeftEdgePoint(point) && isLeftToRight) ||
  2107. (dom.isVisiblePoint(point) && dom.isBlock(point.node) && dom.isEmpty(point.node))) {
  2108. return point;
  2109. }
  2110. // point on block's edge
  2111. var block = dom.ancestor(point.node, dom.isBlock);
  2112. if (((dom.isLeftEdgePointOf(point, block) || dom.isVoid(dom.prevPoint(point).node)) && !isLeftToRight) ||
  2113. ((dom.isRightEdgePointOf(point, block) || dom.isVoid(dom.nextPoint(point).node)) && isLeftToRight)) {
  2114. // returns point already on visible point
  2115. if (dom.isVisiblePoint(point)) {
  2116. return point;
  2117. }
  2118. // reverse direction
  2119. isLeftToRight = !isLeftToRight;
  2120. }
  2121. var nextPoint = isLeftToRight ? dom.nextPointUntil(dom.nextPoint(point), dom.isVisiblePoint) :
  2122. dom.prevPointUntil(dom.prevPoint(point), dom.isVisiblePoint);
  2123. return nextPoint || point;
  2124. };
  2125. var endPoint = getVisiblePoint(this.getEndPoint(), false);
  2126. var startPoint = this.isCollapsed() ? endPoint : getVisiblePoint(this.getStartPoint(), true);
  2127. return new WrappedRange(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset);
  2128. };
  2129. /**
  2130. * returns matched nodes on range
  2131. *
  2132. * @param {Function} [pred] - predicate function
  2133. * @param {Object} [options]
  2134. * @param {Boolean} [options.includeAncestor]
  2135. * @param {Boolean} [options.fullyContains]
  2136. * @return {Node[]}
  2137. */
  2138. WrappedRange.prototype.nodes = function (pred, options) {
  2139. pred = pred || func.ok;
  2140. var includeAncestor = options && options.includeAncestor;
  2141. var fullyContains = options && options.fullyContains;
  2142. // TODO compare points and sort
  2143. var startPoint = this.getStartPoint();
  2144. var endPoint = this.getEndPoint();
  2145. var nodes = [];
  2146. var leftEdgeNodes = [];
  2147. dom.walkPoint(startPoint, endPoint, function (point) {
  2148. if (dom.isEditable(point.node)) {
  2149. return;
  2150. }
  2151. var node;
  2152. if (fullyContains) {
  2153. if (dom.isLeftEdgePoint(point)) {
  2154. leftEdgeNodes.push(point.node);
  2155. }
  2156. if (dom.isRightEdgePoint(point) && lists.contains(leftEdgeNodes, point.node)) {
  2157. node = point.node;
  2158. }
  2159. } else if (includeAncestor) {
  2160. node = dom.ancestor(point.node, pred);
  2161. } else {
  2162. node = point.node;
  2163. }
  2164. if (node && pred(node)) {
  2165. nodes.push(node);
  2166. }
  2167. }, true);
  2168. return lists.unique(nodes);
  2169. };
  2170. /**
  2171. * returns commonAncestor of range
  2172. * @return {Element} - commonAncestor
  2173. */
  2174. WrappedRange.prototype.commonAncestor = function () {
  2175. return dom.commonAncestor(this.sc, this.ec);
  2176. };
  2177. /**
  2178. * returns expanded range by pred
  2179. *
  2180. * @param {Function} pred - predicate function
  2181. * @return {WrappedRange}
  2182. */
  2183. WrappedRange.prototype.expand = function (pred) {
  2184. var startAncestor = dom.ancestor(this.sc, pred);
  2185. var endAncestor = dom.ancestor(this.ec, pred);
  2186. if (!startAncestor && !endAncestor) {
  2187. return new WrappedRange(this.sc, this.so, this.ec, this.eo);
  2188. }
  2189. var boundaryPoints = this.getPoints();
  2190. if (startAncestor) {
  2191. boundaryPoints.sc = startAncestor;
  2192. boundaryPoints.so = 0;
  2193. }
  2194. if (endAncestor) {
  2195. boundaryPoints.ec = endAncestor;
  2196. boundaryPoints.eo = dom.nodeLength(endAncestor);
  2197. }
  2198. return new WrappedRange(boundaryPoints.sc, boundaryPoints.so, boundaryPoints.ec, boundaryPoints.eo);
  2199. };
  2200. /**
  2201. * @param {Boolean} isCollapseToStart
  2202. * @return {WrappedRange}
  2203. */
  2204. WrappedRange.prototype.collapse = function (isCollapseToStart) {
  2205. if (isCollapseToStart) {
  2206. return new WrappedRange(this.sc, this.so, this.sc, this.so);
  2207. } else {
  2208. return new WrappedRange(this.ec, this.eo, this.ec, this.eo);
  2209. }
  2210. };
  2211. /**
  2212. * splitText on range
  2213. */
  2214. WrappedRange.prototype.splitText = function () {
  2215. var isSameContainer = this.sc === this.ec;
  2216. var boundaryPoints = this.getPoints();
  2217. if (dom.isText(this.ec) && !dom.isEdgePoint(this.getEndPoint())) {
  2218. this.ec.splitText(this.eo);
  2219. }
  2220. if (dom.isText(this.sc) && !dom.isEdgePoint(this.getStartPoint())) {
  2221. boundaryPoints.sc = this.sc.splitText(this.so);
  2222. boundaryPoints.so = 0;
  2223. if (isSameContainer) {
  2224. boundaryPoints.ec = boundaryPoints.sc;
  2225. boundaryPoints.eo = this.eo - this.so;
  2226. }
  2227. }
  2228. return new WrappedRange(boundaryPoints.sc, boundaryPoints.so, boundaryPoints.ec, boundaryPoints.eo);
  2229. };
  2230. /**
  2231. * delete contents on range
  2232. * @return {WrappedRange}
  2233. */
  2234. WrappedRange.prototype.deleteContents = function () {
  2235. if (this.isCollapsed()) {
  2236. return this;
  2237. }
  2238. var rng = this.splitText();
  2239. var nodes = rng.nodes(null, {
  2240. fullyContains: true
  2241. });
  2242. // find new cursor point
  2243. var point = dom.prevPointUntil(rng.getStartPoint(), function (point) {
  2244. return !lists.contains(nodes, point.node);
  2245. });
  2246. var emptyParents = [];
  2247. $$1.each(nodes, function (idx, node) {
  2248. // find empty parents
  2249. var parent = node.parentNode;
  2250. if (point.node !== parent && dom.nodeLength(parent) === 1) {
  2251. emptyParents.push(parent);
  2252. }
  2253. dom.remove(node, false);
  2254. });
  2255. // remove empty parents
  2256. $$1.each(emptyParents, function (idx, node) {
  2257. dom.remove(node, false);
  2258. });
  2259. return new WrappedRange(point.node, point.offset, point.node, point.offset).normalize();
  2260. };
  2261. /**
  2262. * makeIsOn: return isOn(pred) function
  2263. */
  2264. WrappedRange.prototype.makeIsOn = function (pred) {
  2265. return function () {
  2266. var ancestor = dom.ancestor(this.sc, pred);
  2267. return !!ancestor && (ancestor === dom.ancestor(this.ec, pred));
  2268. };
  2269. };
  2270. /**
  2271. * @param {Function} pred
  2272. * @return {Boolean}
  2273. */
  2274. WrappedRange.prototype.isLeftEdgeOf = function (pred) {
  2275. if (!dom.isLeftEdgePoint(this.getStartPoint())) {
  2276. return false;
  2277. }
  2278. var node = dom.ancestor(this.sc, pred);
  2279. return node && dom.isLeftEdgeOf(this.sc, node);
  2280. };
  2281. /**
  2282. * returns whether range was collapsed or not
  2283. */
  2284. WrappedRange.prototype.isCollapsed = function () {
  2285. return this.sc === this.ec && this.so === this.eo;
  2286. };
  2287. /**
  2288. * wrap inline nodes which children of body with paragraph
  2289. *
  2290. * @return {WrappedRange}
  2291. */
  2292. WrappedRange.prototype.wrapBodyInlineWithPara = function () {
  2293. if (dom.isBodyContainer(this.sc) && dom.isEmpty(this.sc)) {
  2294. this.sc.innerHTML = dom.emptyPara;
  2295. return new WrappedRange(this.sc.firstChild, 0, this.sc.firstChild, 0);
  2296. }
  2297. /**
  2298. * [workaround] firefox often create range on not visible point. so normalize here.
  2299. * - firefox: |<p>text</p>|
  2300. * - chrome: <p>|text|</p>
  2301. */
  2302. var rng = this.normalize();
  2303. if (dom.isParaInline(this.sc) || dom.isPara(this.sc)) {
  2304. return rng;
  2305. }
  2306. // find inline top ancestor
  2307. var topAncestor;
  2308. if (dom.isInline(rng.sc)) {
  2309. var ancestors = dom.listAncestor(rng.sc, func.not(dom.isInline));
  2310. topAncestor = lists.last(ancestors);
  2311. if (!dom.isInline(topAncestor)) {
  2312. topAncestor = ancestors[ancestors.length - 2] || rng.sc.childNodes[rng.so];
  2313. }
  2314. } else {
  2315. topAncestor = rng.sc.childNodes[rng.so > 0 ? rng.so - 1 : 0];
  2316. }
  2317. // siblings not in paragraph
  2318. var inlineSiblings = dom.listPrev(topAncestor, dom.isParaInline).reverse();
  2319. inlineSiblings = inlineSiblings.concat(dom.listNext(topAncestor.nextSibling, dom.isParaInline));
  2320. // wrap with paragraph
  2321. if (inlineSiblings.length) {
  2322. var para = dom.wrap(lists.head(inlineSiblings), 'p');
  2323. dom.appendChildNodes(para, lists.tail(inlineSiblings));
  2324. }
  2325. return this.normalize();
  2326. };
  2327. /**
  2328. * insert node at current cursor
  2329. *
  2330. * @param {Node} node
  2331. * @return {Node}
  2332. */
  2333. WrappedRange.prototype.insertNode = function (node) {
  2334. var rng = this.wrapBodyInlineWithPara().deleteContents();
  2335. var info = dom.splitPoint(rng.getStartPoint(), dom.isInline(node));
  2336. if (info.rightNode) {
  2337. info.rightNode.parentNode.insertBefore(node, info.rightNode);
  2338. } else {
  2339. info.container.appendChild(node);
  2340. }
  2341. return node;
  2342. };
  2343. /**
  2344. * insert html at current cursor
  2345. */
  2346. WrappedRange.prototype.pasteHTML = function (markup) {
  2347. var contentsContainer = $$1('<div></div>').html(markup)[0];
  2348. var childNodes = lists.from(contentsContainer.childNodes);
  2349. var rng = this.wrapBodyInlineWithPara().deleteContents();
  2350. return childNodes.reverse().map(function (childNode) {
  2351. return rng.insertNode(childNode);
  2352. }).reverse();
  2353. };
  2354. /**
  2355. * returns text in range
  2356. *
  2357. * @return {String}
  2358. */
  2359. WrappedRange.prototype.toString = function () {
  2360. var nativeRng = this.nativeRange();
  2361. return env.isW3CRangeSupport ? nativeRng.toString() : nativeRng.text;
  2362. };
  2363. /**
  2364. * returns range for word before cursor
  2365. *
  2366. * @param {Boolean} [findAfter] - find after cursor, default: false
  2367. * @return {WrappedRange}
  2368. */
  2369. WrappedRange.prototype.getWordRange = function (findAfter) {
  2370. var endPoint = this.getEndPoint();
  2371. if (!dom.isCharPoint(endPoint)) {
  2372. return this;
  2373. }
  2374. var startPoint = dom.prevPointUntil(endPoint, function (point) {
  2375. return !dom.isCharPoint(point);
  2376. });
  2377. if (findAfter) {
  2378. endPoint = dom.nextPointUntil(endPoint, function (point) {
  2379. return !dom.isCharPoint(point);
  2380. });
  2381. }
  2382. return new WrappedRange(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset);
  2383. };
  2384. /**
  2385. * create offsetPath bookmark
  2386. *
  2387. * @param {Node} editable
  2388. */
  2389. WrappedRange.prototype.bookmark = function (editable) {
  2390. return {
  2391. s: {
  2392. path: dom.makeOffsetPath(editable, this.sc),
  2393. offset: this.so
  2394. },
  2395. e: {
  2396. path: dom.makeOffsetPath(editable, this.ec),
  2397. offset: this.eo
  2398. }
  2399. };
  2400. };
  2401. /**
  2402. * create offsetPath bookmark base on paragraph
  2403. *
  2404. * @param {Node[]} paras
  2405. */
  2406. WrappedRange.prototype.paraBookmark = function (paras) {
  2407. return {
  2408. s: {
  2409. path: lists.tail(dom.makeOffsetPath(lists.head(paras), this.sc)),
  2410. offset: this.so
  2411. },
  2412. e: {
  2413. path: lists.tail(dom.makeOffsetPath(lists.last(paras), this.ec)),
  2414. offset: this.eo
  2415. }
  2416. };
  2417. };
  2418. /**
  2419. * getClientRects
  2420. * @return {Rect[]}
  2421. */
  2422. WrappedRange.prototype.getClientRects = function () {
  2423. var nativeRng = this.nativeRange();
  2424. return nativeRng.getClientRects();
  2425. };
  2426. return WrappedRange;
  2427. }());
  2428. /**
  2429. * Data structure
  2430. * * BoundaryPoint: a point of dom tree
  2431. * * BoundaryPoints: two boundaryPoints corresponding to the start and the end of the Range
  2432. *
  2433. * See to http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-Position
  2434. */
  2435. var range = {
  2436. /**
  2437. * create Range Object From arguments or Browser Selection
  2438. *
  2439. * @param {Node} sc - start container
  2440. * @param {Number} so - start offset
  2441. * @param {Node} ec - end container
  2442. * @param {Number} eo - end offset
  2443. * @return {WrappedRange}
  2444. */
  2445. create: function (sc, so, ec, eo) {
  2446. if (arguments.length === 4) {
  2447. return new WrappedRange(sc, so, ec, eo);
  2448. } else if (arguments.length === 2) {
  2449. ec = sc;
  2450. eo = so;
  2451. return new WrappedRange(sc, so, ec, eo);
  2452. } else {
  2453. var wrappedRange = this.createFromSelection();
  2454. if (!wrappedRange && arguments.length === 1) {
  2455. wrappedRange = this.createFromNode(arguments[0]);
  2456. return wrappedRange.collapse(dom.emptyPara === arguments[0].innerHTML);
  2457. }
  2458. return wrappedRange;
  2459. }
  2460. },
  2461. createFromSelection: function () {
  2462. var sc, so, ec, eo;
  2463. if (env.isW3CRangeSupport) {
  2464. var selection = document.getSelection();
  2465. if (!selection || selection.rangeCount === 0) {
  2466. return null;
  2467. } else if (dom.isBody(selection.anchorNode)) {
  2468. // Firefox: returns entire body as range on initialization.
  2469. // We won't never need it.
  2470. return null;
  2471. }
  2472. var nativeRng = selection.getRangeAt(0);
  2473. sc = nativeRng.startContainer;
  2474. so = nativeRng.startOffset;
  2475. ec = nativeRng.endContainer;
  2476. eo = nativeRng.endOffset;
  2477. } else {
  2478. var textRange = document.selection.createRange();
  2479. var textRangeEnd = textRange.duplicate();
  2480. textRangeEnd.collapse(false);
  2481. var textRangeStart = textRange;
  2482. textRangeStart.collapse(true);
  2483. var startPoint = textRangeToPoint(textRangeStart, true);
  2484. var endPoint = textRangeToPoint(textRangeEnd, false);
  2485. // same visible point case: range was collapsed.
  2486. if (dom.isText(startPoint.node) && dom.isLeftEdgePoint(startPoint) &&
  2487. dom.isTextNode(endPoint.node) && dom.isRightEdgePoint(endPoint) &&
  2488. endPoint.node.nextSibling === startPoint.node) {
  2489. startPoint = endPoint;
  2490. }
  2491. sc = startPoint.cont;
  2492. so = startPoint.offset;
  2493. ec = endPoint.cont;
  2494. eo = endPoint.offset;
  2495. }
  2496. return new WrappedRange(sc, so, ec, eo);
  2497. },
  2498. /**
  2499. * @method
  2500. *
  2501. * create WrappedRange from node
  2502. *
  2503. * @param {Node} node
  2504. * @return {WrappedRange}
  2505. */
  2506. createFromNode: function (node) {
  2507. var sc = node;
  2508. var so = 0;
  2509. var ec = node;
  2510. var eo = dom.nodeLength(ec);
  2511. // browsers can't target a picture or void node
  2512. if (dom.isVoid(sc)) {
  2513. so = dom.listPrev(sc).length - 1;
  2514. sc = sc.parentNode;
  2515. }
  2516. if (dom.isBR(ec)) {
  2517. eo = dom.listPrev(ec).length - 1;
  2518. ec = ec.parentNode;
  2519. } else if (dom.isVoid(ec)) {
  2520. eo = dom.listPrev(ec).length;
  2521. ec = ec.parentNode;
  2522. }
  2523. return this.create(sc, so, ec, eo);
  2524. },
  2525. /**
  2526. * create WrappedRange from node after position
  2527. *
  2528. * @param {Node} node
  2529. * @return {WrappedRange}
  2530. */
  2531. createFromNodeBefore: function (node) {
  2532. return this.createFromNode(node).collapse(true);
  2533. },
  2534. /**
  2535. * create WrappedRange from node after position
  2536. *
  2537. * @param {Node} node
  2538. * @return {WrappedRange}
  2539. */
  2540. createFromNodeAfter: function (node) {
  2541. return this.createFromNode(node).collapse();
  2542. },
  2543. /**
  2544. * @method
  2545. *
  2546. * create WrappedRange from bookmark
  2547. *
  2548. * @param {Node} editable
  2549. * @param {Object} bookmark
  2550. * @return {WrappedRange}
  2551. */
  2552. createFromBookmark: function (editable, bookmark) {
  2553. var sc = dom.fromOffsetPath(editable, bookmark.s.path);
  2554. var so = bookmark.s.offset;
  2555. var ec = dom.fromOffsetPath(editable, bookmark.e.path);
  2556. var eo = bookmark.e.offset;
  2557. return new WrappedRange(sc, so, ec, eo);
  2558. },
  2559. /**
  2560. * @method
  2561. *
  2562. * create WrappedRange from paraBookmark
  2563. *
  2564. * @param {Object} bookmark
  2565. * @param {Node[]} paras
  2566. * @return {WrappedRange}
  2567. */
  2568. createFromParaBookmark: function (bookmark, paras) {
  2569. var so = bookmark.s.offset;
  2570. var eo = bookmark.e.offset;
  2571. var sc = dom.fromOffsetPath(lists.head(paras), bookmark.s.path);
  2572. var ec = dom.fromOffsetPath(lists.last(paras), bookmark.e.path);
  2573. return new WrappedRange(sc, so, ec, eo);
  2574. }
  2575. };
  2576. /**
  2577. * @method readFileAsDataURL
  2578. *
  2579. * read contents of file as representing URL
  2580. *
  2581. * @param {File} file
  2582. * @return {Promise} - then: dataUrl
  2583. */
  2584. function readFileAsDataURL(file) {
  2585. return $$1.Deferred(function (deferred) {
  2586. $$1.extend(new FileReader(), {
  2587. onload: function (e) {
  2588. var dataURL = e.target.result;
  2589. deferred.resolve(dataURL);
  2590. },
  2591. onerror: function (err) {
  2592. deferred.reject(err);
  2593. }
  2594. }).readAsDataURL(file);
  2595. }).promise();
  2596. }
  2597. /**
  2598. * @method createImage
  2599. *
  2600. * create `<image>` from url string
  2601. *
  2602. * @param {String} url
  2603. * @return {Promise} - then: $image
  2604. */
  2605. function createImage(url) {
  2606. return $$1.Deferred(function (deferred) {
  2607. var $img = $$1('<img>');
  2608. $img.one('load', function () {
  2609. $img.off('error abort');
  2610. deferred.resolve($img);
  2611. }).one('error abort', function () {
  2612. $img.off('load').detach();
  2613. deferred.reject($img);
  2614. }).css({
  2615. display: 'none'
  2616. }).appendTo(document.body).attr('src', url);
  2617. }).promise();
  2618. }
  2619. var History = /** @class */ (function () {
  2620. function History($editable) {
  2621. this.stack = [];
  2622. this.stackOffset = -1;
  2623. this.$editable = $editable;
  2624. this.editable = $editable[0];
  2625. }
  2626. History.prototype.makeSnapshot = function () {
  2627. var rng = range.create(this.editable);
  2628. var emptyBookmark = {
  2629. s: {
  2630. path: [],
  2631. offset: 0
  2632. },
  2633. e: {
  2634. path: [],
  2635. offset: 0
  2636. }
  2637. };
  2638. return {
  2639. contents: this.$editable.html(),
  2640. bookmark: (rng ? rng.bookmark(this.editable) : emptyBookmark)
  2641. };
  2642. };
  2643. History.prototype.applySnapshot = function (snapshot) {
  2644. if (snapshot.contents !== null) {
  2645. this.$editable.html(snapshot.contents);
  2646. }
  2647. if (snapshot.bookmark !== null) {
  2648. range.createFromBookmark(this.editable, snapshot.bookmark).select();
  2649. }
  2650. };
  2651. /**
  2652. * @method rewind
  2653. * Rewinds the history stack back to the first snapshot taken.
  2654. * Leaves the stack intact, so that "Redo" can still be used.
  2655. */
  2656. History.prototype.rewind = function () {
  2657. // Create snap shot if not yet recorded
  2658. if (this.$editable.html() !== this.stack[this.stackOffset].contents) {
  2659. this.recordUndo();
  2660. }
  2661. // Return to the first available snapshot.
  2662. this.stackOffset = 0;
  2663. // Apply that snapshot.
  2664. this.applySnapshot(this.stack[this.stackOffset]);
  2665. };
  2666. /**
  2667. * @method reset
  2668. * Resets the history stack completely; reverting to an empty editor.
  2669. */
  2670. History.prototype.reset = function () {
  2671. // Clear the stack.
  2672. this.stack = [];
  2673. // Restore stackOffset to its original value.
  2674. this.stackOffset = -1;
  2675. // Clear the editable area.
  2676. this.$editable.html('');
  2677. // Record our first snapshot (of nothing).
  2678. this.recordUndo();
  2679. };
  2680. /**
  2681. * undo
  2682. */
  2683. History.prototype.undo = function () {
  2684. // Create snap shot if not yet recorded
  2685. if (this.$editable.html() !== this.stack[this.stackOffset].contents) {
  2686. this.recordUndo();
  2687. }
  2688. if (this.stackOffset > 0) {
  2689. this.stackOffset--;
  2690. this.applySnapshot(this.stack[this.stackOffset]);
  2691. }
  2692. };
  2693. /**
  2694. * redo
  2695. */
  2696. History.prototype.redo = function () {
  2697. if (this.stack.length - 1 > this.stackOffset) {
  2698. this.stackOffset++;
  2699. this.applySnapshot(this.stack[this.stackOffset]);
  2700. }
  2701. };
  2702. /**
  2703. * recorded undo
  2704. */
  2705. History.prototype.recordUndo = function () {
  2706. this.stackOffset++;
  2707. // Wash out stack after stackOffset
  2708. if (this.stack.length > this.stackOffset) {
  2709. this.stack = this.stack.slice(0, this.stackOffset);
  2710. }
  2711. // Create new snapshot and push it to the end
  2712. this.stack.push(this.makeSnapshot());
  2713. };
  2714. return History;
  2715. }());
  2716. var Style = /** @class */ (function () {
  2717. function Style() {}
  2718. /**
  2719. * @method jQueryCSS
  2720. *
  2721. * [workaround] for old jQuery
  2722. * passing an array of style properties to .css()
  2723. * will result in an object of property-value pairs.
  2724. * (compability with version < 1.9)
  2725. *
  2726. * @private
  2727. * @param {jQuery} $obj
  2728. * @param {Array} propertyNames - An array of one or more CSS properties.
  2729. * @return {Object}
  2730. */
  2731. Style.prototype.jQueryCSS = function ($obj, propertyNames) {
  2732. if (env.jqueryVersion < 1.9) {
  2733. var result_1 = {};
  2734. $$1.each(propertyNames, function (idx, propertyName) {
  2735. result_1[propertyName] = $obj.css(propertyName);
  2736. });
  2737. return result_1;
  2738. }
  2739. return $obj.css(propertyNames);
  2740. };
  2741. /**
  2742. * returns style object from node
  2743. *
  2744. * @param {jQuery} $node
  2745. * @return {Object}
  2746. */
  2747. Style.prototype.fromNode = function ($node) {
  2748. var properties = ['font-family', 'font-size', 'text-align', 'list-style-type', 'line-height'];
  2749. var styleInfo = this.jQueryCSS($node, properties) || {};
  2750. styleInfo['font-size'] = parseInt(styleInfo['font-size'], 10);
  2751. return styleInfo;
  2752. };
  2753. /**
  2754. * paragraph level style
  2755. *
  2756. * @param {WrappedRange} rng
  2757. * @param {Object} styleInfo
  2758. */
  2759. Style.prototype.stylePara = function (rng, styleInfo) {
  2760. $$1.each(rng.nodes(dom.isPara, {
  2761. includeAncestor: true
  2762. }), function (idx, para) {
  2763. $$1(para).css(styleInfo);
  2764. });
  2765. };
  2766. /**
  2767. * insert and returns styleNodes on range.
  2768. *
  2769. * @param {WrappedRange} rng
  2770. * @param {Object} [options] - options for styleNodes
  2771. * @param {String} [options.nodeName] - default: `SPAN`
  2772. * @param {Boolean} [options.expandClosestSibling] - default: `false`
  2773. * @param {Boolean} [options.onlyPartialContains] - default: `false`
  2774. * @return {Node[]}
  2775. */
  2776. Style.prototype.styleNodes = function (rng, options) {
  2777. rng = rng.splitText();
  2778. var nodeName = (options && options.nodeName) || 'SPAN';
  2779. var expandClosestSibling = !!(options && options.expandClosestSibling);
  2780. var onlyPartialContains = !!(options && options.onlyPartialContains);
  2781. if (rng.isCollapsed()) {
  2782. return [rng.insertNode(dom.create(nodeName))];
  2783. }
  2784. var pred = dom.makePredByNodeName(nodeName);
  2785. var nodes = rng.nodes(dom.isText, {
  2786. fullyContains: true
  2787. }).map(function (text) {
  2788. return dom.singleChildAncestor(text, pred) || dom.wrap(text, nodeName);
  2789. });
  2790. if (expandClosestSibling) {
  2791. if (onlyPartialContains) {
  2792. var nodesInRange_1 = rng.nodes();
  2793. // compose with partial contains predication
  2794. pred = func.and(pred, function (node) {
  2795. return lists.contains(nodesInRange_1, node);
  2796. });
  2797. }
  2798. return nodes.map(function (node) {
  2799. var siblings = dom.withClosestSiblings(node, pred);
  2800. var head = lists.head(siblings);
  2801. var tails = lists.tail(siblings);
  2802. $$1.each(tails, function (idx, elem) {
  2803. dom.appendChildNodes(head, elem.childNodes);
  2804. dom.remove(elem);
  2805. });
  2806. return lists.head(siblings);
  2807. });
  2808. } else {
  2809. return nodes;
  2810. }
  2811. };
  2812. /**
  2813. * get current style on cursor
  2814. *
  2815. * @param {WrappedRange} rng
  2816. * @return {Object} - object contains style properties.
  2817. */
  2818. Style.prototype.current = function (rng) {
  2819. var $cont = $$1(!dom.isElement(rng.sc) ? rng.sc.parentNode : rng.sc);
  2820. var styleInfo = this.fromNode($cont);
  2821. // document.queryCommandState for toggle state
  2822. // [workaround] prevent Firefox nsresult: "0x80004005 (NS_ERROR_FAILURE)"
  2823. try {
  2824. styleInfo = $$1.extend(styleInfo, {
  2825. 'font-bold': document.queryCommandState('bold') ? 'bold' : 'normal',
  2826. 'font-italic': document.queryCommandState('italic') ? 'italic' : 'normal',
  2827. 'font-underline': document.queryCommandState('underline') ? 'underline' : 'normal',
  2828. 'font-subscript': document.queryCommandState('subscript') ? 'subscript' : 'normal',
  2829. 'font-superscript': document.queryCommandState('superscript') ? 'superscript' : 'normal',
  2830. 'font-strikethrough': document.queryCommandState('strikethrough') ? 'strikethrough' : 'normal',
  2831. 'font-family': document.queryCommandValue('fontname') || styleInfo['font-family']
  2832. });
  2833. } catch (e) {}
  2834. // list-style-type to list-style(unordered, ordered)
  2835. if (!rng.isOnList()) {
  2836. styleInfo['list-style'] = 'none';
  2837. } else {
  2838. var orderedTypes = ['circle', 'disc', 'disc-leading-zero', 'square'];
  2839. var isUnordered = $$1.inArray(styleInfo['list-style-type'], orderedTypes) > -1;
  2840. styleInfo['list-style'] = isUnordered ? 'unordered' : 'ordered';
  2841. }
  2842. var para = dom.ancestor(rng.sc, dom.isPara);
  2843. if (para && para.style['line-height']) {
  2844. styleInfo['line-height'] = para.style.lineHeight;
  2845. } else {
  2846. var lineHeight = parseInt(styleInfo['line-height'], 10) / parseInt(styleInfo['font-size'], 10);
  2847. styleInfo['line-height'] = lineHeight.toFixed(1);
  2848. }
  2849. styleInfo.anchor = rng.isOnAnchor() && dom.ancestor(rng.sc, dom.isAnchor);
  2850. styleInfo.ancestors = dom.listAncestor(rng.sc, dom.isEditable);
  2851. styleInfo.range = rng;
  2852. return styleInfo;
  2853. };
  2854. return Style;
  2855. }());
  2856. var Bullet = /** @class */ (function () {
  2857. function Bullet() {}
  2858. /**
  2859. * toggle ordered list
  2860. */
  2861. Bullet.prototype.insertOrderedList = function (editable) {
  2862. this.toggleList('OL', editable);
  2863. };
  2864. /**
  2865. * toggle unordered list
  2866. */
  2867. Bullet.prototype.insertUnorderedList = function (editable) {
  2868. this.toggleList('UL', editable);
  2869. };
  2870. /**
  2871. * indent
  2872. */
  2873. Bullet.prototype.indent = function (editable) {
  2874. var _this = this;
  2875. var rng = range.create(editable).wrapBodyInlineWithPara();
  2876. var paras = rng.nodes(dom.isPara, {
  2877. includeAncestor: true
  2878. });
  2879. var clustereds = lists.clusterBy(paras, func.peq2('parentNode'));
  2880. $$1.each(clustereds, function (idx, paras) {
  2881. var head = lists.head(paras);
  2882. if (dom.isLi(head)) {
  2883. _this.wrapList(paras, head.parentNode.nodeName);
  2884. } else {
  2885. $$1.each(paras, function (idx, para) {
  2886. $$1(para).css('marginLeft', function (idx, val) {
  2887. return (parseInt(val, 10) || 0) + 25;
  2888. });
  2889. });
  2890. }
  2891. });
  2892. rng.select();
  2893. };
  2894. /**
  2895. * outdent
  2896. */
  2897. Bullet.prototype.outdent = function (editable) {
  2898. var _this = this;
  2899. var rng = range.create(editable).wrapBodyInlineWithPara();
  2900. var paras = rng.nodes(dom.isPara, {
  2901. includeAncestor: true
  2902. });
  2903. var clustereds = lists.clusterBy(paras, func.peq2('parentNode'));
  2904. $$1.each(clustereds, function (idx, paras) {
  2905. var head = lists.head(paras);
  2906. if (dom.isLi(head)) {
  2907. _this.releaseList([paras]);
  2908. } else {
  2909. $$1.each(paras, function (idx, para) {
  2910. $$1(para).css('marginLeft', function (idx, val) {
  2911. val = (parseInt(val, 10) || 0);
  2912. return val > 25 ? val - 25 : '';
  2913. });
  2914. });
  2915. }
  2916. });
  2917. rng.select();
  2918. };
  2919. /**
  2920. * toggle list
  2921. *
  2922. * @param {String} listName - OL or UL
  2923. */
  2924. Bullet.prototype.toggleList = function (listName, editable) {
  2925. var _this = this;
  2926. var rng = range.create(editable).wrapBodyInlineWithPara();
  2927. var paras = rng.nodes(dom.isPara, {
  2928. includeAncestor: true
  2929. });
  2930. var bookmark = rng.paraBookmark(paras);
  2931. var clustereds = lists.clusterBy(paras, func.peq2('parentNode'));
  2932. // paragraph to list
  2933. if (lists.find(paras, dom.isPurePara)) {
  2934. var wrappedParas_1 = [];
  2935. $$1.each(clustereds, function (idx, paras) {
  2936. wrappedParas_1 = wrappedParas_1.concat(_this.wrapList(paras, listName));
  2937. });
  2938. paras = wrappedParas_1;
  2939. // list to paragraph or change list style
  2940. } else {
  2941. var diffLists = rng.nodes(dom.isList, {
  2942. includeAncestor: true
  2943. }).filter(function (listNode) {
  2944. return !$$1.nodeName(listNode, listName);
  2945. });
  2946. if (diffLists.length) {
  2947. $$1.each(diffLists, function (idx, listNode) {
  2948. dom.replace(listNode, listName);
  2949. });
  2950. } else {
  2951. paras = this.releaseList(clustereds, true);
  2952. }
  2953. }
  2954. range.createFromParaBookmark(bookmark, paras).select();
  2955. };
  2956. /**
  2957. * @param {Node[]} paras
  2958. * @param {String} listName
  2959. * @return {Node[]}
  2960. */
  2961. Bullet.prototype.wrapList = function (paras, listName) {
  2962. var head = lists.head(paras);
  2963. var last = lists.last(paras);
  2964. var prevList = dom.isList(head.previousSibling) && head.previousSibling;
  2965. var nextList = dom.isList(last.nextSibling) && last.nextSibling;
  2966. var listNode = prevList || dom.insertAfter(dom.create(listName || 'UL'), last);
  2967. // P to LI
  2968. paras = paras.map(function (para) {
  2969. return dom.isPurePara(para) ? dom.replace(para, 'LI') : para;
  2970. });
  2971. // append to list(<ul>, <ol>)
  2972. dom.appendChildNodes(listNode, paras);
  2973. if (nextList) {
  2974. dom.appendChildNodes(listNode, lists.from(nextList.childNodes));
  2975. dom.remove(nextList);
  2976. }
  2977. return paras;
  2978. };
  2979. /**
  2980. * @method releaseList
  2981. *
  2982. * @param {Array[]} clustereds
  2983. * @param {Boolean} isEscapseToBody
  2984. * @return {Node[]}
  2985. */
  2986. Bullet.prototype.releaseList = function (clustereds, isEscapseToBody) {
  2987. var releasedParas = [];
  2988. $$1.each(clustereds, function (idx, paras) {
  2989. var head = lists.head(paras);
  2990. var last = lists.last(paras);
  2991. var headList = isEscapseToBody ? dom.lastAncestor(head, dom.isList) : head.parentNode;
  2992. var lastList = headList.childNodes.length > 1 ? dom.splitTree(headList, {
  2993. node: last.parentNode,
  2994. offset: dom.position(last) + 1
  2995. }, {
  2996. isSkipPaddingBlankHTML: true
  2997. }) : null;
  2998. var middleList = dom.splitTree(headList, {
  2999. node: head.parentNode,
  3000. offset: dom.position(head)
  3001. }, {
  3002. isSkipPaddingBlankHTML: true
  3003. });
  3004. paras = isEscapseToBody ? dom.listDescendant(middleList, dom.isLi) :
  3005. lists.from(middleList.childNodes).filter(dom.isLi);
  3006. // LI to P
  3007. if (isEscapseToBody || !dom.isList(headList.parentNode)) {
  3008. paras = paras.map(function (para) {
  3009. return dom.replace(para, 'P');
  3010. });
  3011. }
  3012. $$1.each(lists.from(paras).reverse(), function (idx, para) {
  3013. dom.insertAfter(para, headList);
  3014. });
  3015. // remove empty lists
  3016. var rootLists = lists.compact([headList, middleList, lastList]);
  3017. $$1.each(rootLists, function (idx, rootList) {
  3018. var listNodes = [rootList].concat(dom.listDescendant(rootList, dom.isList));
  3019. $$1.each(listNodes.reverse(), function (idx, listNode) {
  3020. if (!dom.nodeLength(listNode)) {
  3021. dom.remove(listNode, true);
  3022. }
  3023. });
  3024. });
  3025. releasedParas = releasedParas.concat(paras);
  3026. });
  3027. return releasedParas;
  3028. };
  3029. return Bullet;
  3030. }());
  3031. /**
  3032. * @class editing.Typing
  3033. *
  3034. * Typing
  3035. *
  3036. */
  3037. var Typing = /** @class */ (function () {
  3038. function Typing() {
  3039. // a Bullet instance to toggle lists off
  3040. this.bullet = new Bullet();
  3041. }
  3042. /**
  3043. * insert tab
  3044. *
  3045. * @param {WrappedRange} rng
  3046. * @param {Number} tabsize
  3047. */
  3048. Typing.prototype.insertTab = function (rng, tabsize) {
  3049. var tab = dom.createText(new Array(tabsize + 1).join(dom.NBSP_CHAR));
  3050. rng = rng.deleteContents();
  3051. rng.insertNode(tab, true);
  3052. rng = range.create(tab, tabsize);
  3053. rng.select();
  3054. };
  3055. /**
  3056. * insert paragraph
  3057. */
  3058. Typing.prototype.insertParagraph = function (editable) {
  3059. var rng = range.create(editable);
  3060. // deleteContents on range.
  3061. rng = rng.deleteContents();
  3062. // Wrap range if it needs to be wrapped by paragraph
  3063. rng = rng.wrapBodyInlineWithPara();
  3064. // finding paragraph
  3065. var splitRoot = dom.ancestor(rng.sc, dom.isPara);
  3066. var nextPara;
  3067. // on paragraph: split paragraph
  3068. if (splitRoot) {
  3069. // if it is an empty line with li
  3070. if (dom.isEmpty(splitRoot) && dom.isLi(splitRoot)) {
  3071. // toogle UL/OL and escape
  3072. this.bullet.toggleList(splitRoot.parentNode.nodeName);
  3073. return;
  3074. // if it is an empty line with para on blockquote
  3075. } else if (dom.isEmpty(splitRoot) && dom.isPara(splitRoot) && dom.isBlockquote(splitRoot.parentNode)) {
  3076. // escape blockquote
  3077. dom.insertAfter(splitRoot, splitRoot.parentNode);
  3078. nextPara = splitRoot;
  3079. // if new line has content (not a line break)
  3080. } else {
  3081. nextPara = dom.splitTree(splitRoot, rng.getStartPoint());
  3082. var emptyAnchors = dom.listDescendant(splitRoot, dom.isEmptyAnchor);
  3083. emptyAnchors = emptyAnchors.concat(dom.listDescendant(nextPara, dom.isEmptyAnchor));
  3084. $$1.each(emptyAnchors, function (idx, anchor) {
  3085. dom.remove(anchor);
  3086. });
  3087. // replace empty heading, pre or custom-made styleTag with P tag
  3088. if ((dom.isHeading(nextPara) || dom.isPre(nextPara) || dom.isCustomStyleTag(nextPara)) && dom.isEmpty(nextPara)) {
  3089. nextPara = dom.replace(nextPara, 'p');
  3090. }
  3091. }
  3092. // no paragraph: insert empty paragraph
  3093. } else {
  3094. var next = rng.sc.childNodes[rng.so];
  3095. nextPara = $$1(dom.emptyPara)[0];
  3096. if (next) {
  3097. rng.sc.insertBefore(nextPara, next);
  3098. } else {
  3099. rng.sc.appendChild(nextPara);
  3100. }
  3101. }
  3102. range.create(nextPara, 0).normalize().select().scrollIntoView(editable);
  3103. };
  3104. return Typing;
  3105. }());
  3106. /**
  3107. * @class Create a virtual table to create what actions to do in change.
  3108. * @param {object} startPoint Cell selected to apply change.
  3109. * @param {enum} where Where change will be applied Row or Col. Use enum: TableResultAction.where
  3110. * @param {enum} action Action to be applied. Use enum: TableResultAction.requestAction
  3111. * @param {object} domTable Dom element of table to make changes.
  3112. */
  3113. var TableResultAction = function (startPoint, where, action, domTable) {
  3114. var _startPoint = {
  3115. 'colPos': 0,
  3116. 'rowPos': 0
  3117. };
  3118. var _virtualTable = [];
  3119. var _actionCellList = [];
  3120. /// ///////////////////////////////////////////
  3121. // Private functions
  3122. /// ///////////////////////////////////////////
  3123. /**
  3124. * Set the startPoint of action.
  3125. */
  3126. function setStartPoint() {
  3127. if (!startPoint || !startPoint.tagName || (startPoint.tagName.toLowerCase() !== 'td' && startPoint.tagName.toLowerCase() !== 'th')) {
  3128. console.error('Impossible to identify start Cell point.', startPoint);
  3129. return;
  3130. }
  3131. _startPoint.colPos = startPoint.cellIndex;
  3132. if (!startPoint.parentElement || !startPoint.parentElement.tagName || startPoint.parentElement.tagName.toLowerCase() !== 'tr') {
  3133. console.error('Impossible to identify start Row point.', startPoint);
  3134. return;
  3135. }
  3136. _startPoint.rowPos = startPoint.parentElement.rowIndex;
  3137. }
  3138. /**
  3139. * Define virtual table position info object.
  3140. *
  3141. * @param {int} rowIndex Index position in line of virtual table.
  3142. * @param {int} cellIndex Index position in column of virtual table.
  3143. * @param {object} baseRow Row affected by this position.
  3144. * @param {object} baseCell Cell affected by this position.
  3145. * @param {bool} isSpan Inform if it is an span cell/row.
  3146. */
  3147. function setVirtualTablePosition(rowIndex, cellIndex, baseRow, baseCell, isRowSpan, isColSpan, isVirtualCell) {
  3148. var objPosition = {
  3149. 'baseRow': baseRow,
  3150. 'baseCell': baseCell,
  3151. 'isRowSpan': isRowSpan,
  3152. 'isColSpan': isColSpan,
  3153. 'isVirtual': isVirtualCell
  3154. };
  3155. if (!_virtualTable[rowIndex]) {
  3156. _virtualTable[rowIndex] = [];
  3157. }
  3158. _virtualTable[rowIndex][cellIndex] = objPosition;
  3159. }
  3160. /**
  3161. * Create action cell object.
  3162. *
  3163. * @param {object} virtualTableCellObj Object of specific position on virtual table.
  3164. * @param {enum} resultAction Action to be applied in that item.
  3165. */
  3166. function getActionCell(virtualTableCellObj, resultAction, virtualRowPosition, virtualColPosition) {
  3167. return {
  3168. 'baseCell': virtualTableCellObj.baseCell,
  3169. 'action': resultAction,
  3170. 'virtualTable': {
  3171. 'rowIndex': virtualRowPosition,
  3172. 'cellIndex': virtualColPosition
  3173. }
  3174. };
  3175. }
  3176. /**
  3177. * Recover free index of row to append Cell.
  3178. *
  3179. * @param {int} rowIndex Index of row to find free space.
  3180. * @param {int} cellIndex Index of cell to find free space in table.
  3181. */
  3182. function recoverCellIndex(rowIndex, cellIndex) {
  3183. if (!_virtualTable[rowIndex]) {
  3184. return cellIndex;
  3185. }
  3186. if (!_virtualTable[rowIndex][cellIndex]) {
  3187. return cellIndex;
  3188. }
  3189. var newCellIndex = cellIndex;
  3190. while (_virtualTable[rowIndex][newCellIndex]) {
  3191. newCellIndex++;
  3192. if (!_virtualTable[rowIndex][newCellIndex]) {
  3193. return newCellIndex;
  3194. }
  3195. }
  3196. }
  3197. /**
  3198. * Recover info about row and cell and add information to virtual table.
  3199. *
  3200. * @param {object} row Row to recover information.
  3201. * @param {object} cell Cell to recover information.
  3202. */
  3203. function addCellInfoToVirtual(row, cell) {
  3204. var cellIndex = recoverCellIndex(row.rowIndex, cell.cellIndex);
  3205. var cellHasColspan = (cell.colSpan > 1);
  3206. var cellHasRowspan = (cell.rowSpan > 1);
  3207. var isThisSelectedCell = (row.rowIndex === _startPoint.rowPos && cell.cellIndex === _startPoint.colPos);
  3208. setVirtualTablePosition(row.rowIndex, cellIndex, row, cell, cellHasRowspan, cellHasColspan, false);
  3209. // Add span rows to virtual Table.
  3210. var rowspanNumber = cell.attributes.rowSpan ? parseInt(cell.attributes.rowSpan.value, 10) : 0;
  3211. if (rowspanNumber > 1) {
  3212. for (var rp = 1; rp < rowspanNumber; rp++) {
  3213. var rowspanIndex = row.rowIndex + rp;
  3214. adjustStartPoint(rowspanIndex, cellIndex, cell, isThisSelectedCell);
  3215. setVirtualTablePosition(rowspanIndex, cellIndex, row, cell, true, cellHasColspan, true);
  3216. }
  3217. }
  3218. // Add span cols to virtual table.
  3219. var colspanNumber = cell.attributes.colSpan ? parseInt(cell.attributes.colSpan.value, 10) : 0;
  3220. if (colspanNumber > 1) {
  3221. for (var cp = 1; cp < colspanNumber; cp++) {
  3222. var cellspanIndex = recoverCellIndex(row.rowIndex, (cellIndex + cp));
  3223. adjustStartPoint(row.rowIndex, cellspanIndex, cell, isThisSelectedCell);
  3224. setVirtualTablePosition(row.rowIndex, cellspanIndex, row, cell, cellHasRowspan, true, true);
  3225. }
  3226. }
  3227. }
  3228. /**
  3229. * Process validation and adjust of start point if needed
  3230. *
  3231. * @param {int} rowIndex
  3232. * @param {int} cellIndex
  3233. * @param {object} cell
  3234. * @param {bool} isSelectedCell
  3235. */
  3236. function adjustStartPoint(rowIndex, cellIndex, cell, isSelectedCell) {
  3237. if (rowIndex === _startPoint.rowPos && _startPoint.colPos >= cell.cellIndex && cell.cellIndex <= cellIndex && !isSelectedCell) {
  3238. _startPoint.colPos++;
  3239. }
  3240. }
  3241. /**
  3242. * Create virtual table of cells with all cells, including span cells.
  3243. */
  3244. function createVirtualTable() {
  3245. var rows = domTable.rows;
  3246. for (var rowIndex = 0; rowIndex < rows.length; rowIndex++) {
  3247. var cells = rows[rowIndex].cells;
  3248. for (var cellIndex = 0; cellIndex < cells.length; cellIndex++) {
  3249. addCellInfoToVirtual(rows[rowIndex], cells[cellIndex]);
  3250. }
  3251. }
  3252. }
  3253. /**
  3254. * Get action to be applied on the cell.
  3255. *
  3256. * @param {object} cell virtual table cell to apply action
  3257. */
  3258. function getDeleteResultActionToCell(cell) {
  3259. switch (where) {
  3260. case TableResultAction.where.Column:
  3261. if (cell.isColSpan) {
  3262. return TableResultAction.resultAction.SubtractSpanCount;
  3263. }
  3264. break;
  3265. case TableResultAction.where.Row:
  3266. if (!cell.isVirtual && cell.isRowSpan) {
  3267. return TableResultAction.resultAction.AddCell;
  3268. } else if (cell.isRowSpan) {
  3269. return TableResultAction.resultAction.SubtractSpanCount;
  3270. }
  3271. break;
  3272. }
  3273. return TableResultAction.resultAction.RemoveCell;
  3274. }
  3275. /**
  3276. * Get action to be applied on the cell.
  3277. *
  3278. * @param {object} cell virtual table cell to apply action
  3279. */
  3280. function getAddResultActionToCell(cell) {
  3281. switch (where) {
  3282. case TableResultAction.where.Column:
  3283. if (cell.isColSpan) {
  3284. return TableResultAction.resultAction.SumSpanCount;
  3285. } else if (cell.isRowSpan && cell.isVirtual) {
  3286. return TableResultAction.resultAction.Ignore;
  3287. }
  3288. break;
  3289. case TableResultAction.where.Row:
  3290. if (cell.isRowSpan) {
  3291. return TableResultAction.resultAction.SumSpanCount;
  3292. } else if (cell.isColSpan && cell.isVirtual) {
  3293. return TableResultAction.resultAction.Ignore;
  3294. }
  3295. break;
  3296. }
  3297. return TableResultAction.resultAction.AddCell;
  3298. }
  3299. function init() {
  3300. setStartPoint();
  3301. createVirtualTable();
  3302. }
  3303. /// ///////////////////////////////////////////
  3304. // Public functions
  3305. /// ///////////////////////////////////////////
  3306. /**
  3307. * Recover array os what to do in table.
  3308. */
  3309. this.getActionList = function () {
  3310. var fixedRow = (where === TableResultAction.where.Row) ? _startPoint.rowPos : -1;
  3311. var fixedCol = (where === TableResultAction.where.Column) ? _startPoint.colPos : -1;
  3312. var actualPosition = 0;
  3313. var canContinue = true;
  3314. while (canContinue) {
  3315. var rowPosition = (fixedRow >= 0) ? fixedRow : actualPosition;
  3316. var colPosition = (fixedCol >= 0) ? fixedCol : actualPosition;
  3317. var row = _virtualTable[rowPosition];
  3318. if (!row) {
  3319. canContinue = false;
  3320. return _actionCellList;
  3321. }
  3322. var cell = row[colPosition];
  3323. if (!cell) {
  3324. canContinue = false;
  3325. return _actionCellList;
  3326. }
  3327. // Define action to be applied in this cell
  3328. var resultAction = TableResultAction.resultAction.Ignore;
  3329. switch (action) {
  3330. case TableResultAction.requestAction.Add:
  3331. resultAction = getAddResultActionToCell(cell);
  3332. break;
  3333. case TableResultAction.requestAction.Delete:
  3334. resultAction = getDeleteResultActionToCell(cell);
  3335. break;
  3336. }
  3337. _actionCellList.push(getActionCell(cell, resultAction, rowPosition, colPosition));
  3338. actualPosition++;
  3339. }
  3340. return _actionCellList;
  3341. };
  3342. init();
  3343. };
  3344. /**
  3345. *
  3346. * Where action occours enum.
  3347. */
  3348. TableResultAction.where = {
  3349. 'Row': 0,
  3350. 'Column': 1
  3351. };
  3352. /**
  3353. *
  3354. * Requested action to apply enum.
  3355. */
  3356. TableResultAction.requestAction = {
  3357. 'Add': 0,
  3358. 'Delete': 1
  3359. };
  3360. /**
  3361. *
  3362. * Result action to be executed enum.
  3363. */
  3364. TableResultAction.resultAction = {
  3365. 'Ignore': 0,
  3366. 'SubtractSpanCount': 1,
  3367. 'RemoveCell': 2,
  3368. 'AddCell': 3,
  3369. 'SumSpanCount': 4
  3370. };
  3371. /**
  3372. *
  3373. * @class editing.Table
  3374. *
  3375. * Table
  3376. *
  3377. */
  3378. var Table = /** @class */ (function () {
  3379. function Table() {}
  3380. /**
  3381. * handle tab key
  3382. *
  3383. * @param {WrappedRange} rng
  3384. * @param {Boolean} isShift
  3385. */
  3386. Table.prototype.tab = function (rng, isShift) {
  3387. var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
  3388. var table = dom.ancestor(cell, dom.isTable);
  3389. var cells = dom.listDescendant(table, dom.isCell);
  3390. var nextCell = lists[isShift ? 'prev' : 'next'](cells, cell);
  3391. if (nextCell) {
  3392. range.create(nextCell, 0).select();
  3393. }
  3394. };
  3395. /**
  3396. * Add a new row
  3397. *
  3398. * @param {WrappedRange} rng
  3399. * @param {String} position (top/bottom)
  3400. * @return {Node}
  3401. */
  3402. Table.prototype.addRow = function (rng, position) {
  3403. var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
  3404. var currentTr = $$1(cell).closest('tr');
  3405. var trAttributes = this.recoverAttributes(currentTr);
  3406. var html = $$1('<tr' + trAttributes + '></tr>');
  3407. var vTable = new TableResultAction(cell, TableResultAction.where.Row, TableResultAction.requestAction.Add, $$1(currentTr).closest('table')[0]);
  3408. var actions = vTable.getActionList();
  3409. for (var idCell = 0; idCell < actions.length; idCell++) {
  3410. var currentCell = actions[idCell];
  3411. var tdAttributes = this.recoverAttributes(currentCell.baseCell);
  3412. switch (currentCell.action) {
  3413. case TableResultAction.resultAction.AddCell:
  3414. html.append('<td' + tdAttributes + '>' + dom.blank + '</td>');
  3415. break;
  3416. case TableResultAction.resultAction.SumSpanCount:
  3417. if (position === 'top') {
  3418. var baseCellTr = currentCell.baseCell.parent;
  3419. var isTopFromRowSpan = (!baseCellTr ? 0 : currentCell.baseCell.closest('tr').rowIndex) <= currentTr[0].rowIndex;
  3420. if (isTopFromRowSpan) {
  3421. var newTd = $$1('<div></div>').append($$1('<td' + tdAttributes + '>' + dom.blank + '</td>').removeAttr('rowspan')).html();
  3422. html.append(newTd);
  3423. break;
  3424. }
  3425. }
  3426. var rowspanNumber = parseInt(currentCell.baseCell.rowSpan, 10);
  3427. rowspanNumber++;
  3428. currentCell.baseCell.setAttribute('rowSpan', rowspanNumber);
  3429. break;
  3430. }
  3431. }
  3432. if (position === 'top') {
  3433. currentTr.before(html);
  3434. } else {
  3435. var cellHasRowspan = (cell.rowSpan > 1);
  3436. if (cellHasRowspan) {
  3437. var lastTrIndex = currentTr[0].rowIndex + (cell.rowSpan - 2);
  3438. $$1($$1(currentTr).parent().find('tr')[lastTrIndex]).after($$1(html));
  3439. return;
  3440. }
  3441. currentTr.after(html);
  3442. }
  3443. };
  3444. /**
  3445. * Add a new col
  3446. *
  3447. * @param {WrappedRange} rng
  3448. * @param {String} position (left/right)
  3449. * @return {Node}
  3450. */
  3451. Table.prototype.addCol = function (rng, position) {
  3452. var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
  3453. var row = $$1(cell).closest('tr');
  3454. var rowsGroup = $$1(row).siblings();
  3455. rowsGroup.push(row);
  3456. var vTable = new TableResultAction(cell, TableResultAction.where.Column, TableResultAction.requestAction.Add, $$1(row).closest('table')[0]);
  3457. var actions = vTable.getActionList();
  3458. for (var actionIndex = 0; actionIndex < actions.length; actionIndex++) {
  3459. var currentCell = actions[actionIndex];
  3460. var tdAttributes = this.recoverAttributes(currentCell.baseCell);
  3461. switch (currentCell.action) {
  3462. case TableResultAction.resultAction.AddCell:
  3463. if (position === 'right') {
  3464. $$1(currentCell.baseCell).after('<td' + tdAttributes + '>' + dom.blank + '</td>');
  3465. } else {
  3466. $$1(currentCell.baseCell).before('<td' + tdAttributes + '>' + dom.blank + '</td>');
  3467. }
  3468. break;
  3469. case TableResultAction.resultAction.SumSpanCount:
  3470. if (position === 'right') {
  3471. var colspanNumber = parseInt(currentCell.baseCell.colSpan, 10);
  3472. colspanNumber++;
  3473. currentCell.baseCell.setAttribute('colSpan', colspanNumber);
  3474. } else {
  3475. $$1(currentCell.baseCell).before('<td' + tdAttributes + '>' + dom.blank + '</td>');
  3476. }
  3477. break;
  3478. }
  3479. }
  3480. };
  3481. /*
  3482. * Copy attributes from element.
  3483. *
  3484. * @param {object} Element to recover attributes.
  3485. * @return {string} Copied string elements.
  3486. */
  3487. Table.prototype.recoverAttributes = function (el) {
  3488. var resultStr = '';
  3489. if (!el) {
  3490. return resultStr;
  3491. }
  3492. var attrList = el.attributes || [];
  3493. for (var i = 0; i < attrList.length; i++) {
  3494. if (attrList[i].name.toLowerCase() === 'id') {
  3495. continue;
  3496. }
  3497. if (attrList[i].specified) {
  3498. resultStr += ' ' + attrList[i].name + '=\'' + attrList[i].value + '\'';
  3499. }
  3500. }
  3501. return resultStr;
  3502. };
  3503. /**
  3504. * Delete current row
  3505. *
  3506. * @param {WrappedRange} rng
  3507. * @return {Node}
  3508. */
  3509. Table.prototype.deleteRow = function (rng) {
  3510. var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
  3511. var row = $$1(cell).closest('tr');
  3512. var cellPos = row.children('td, th').index($$1(cell));
  3513. var rowPos = row[0].rowIndex;
  3514. var vTable = new TableResultAction(cell, TableResultAction.where.Row, TableResultAction.requestAction.Delete, $$1(row).closest('table')[0]);
  3515. var actions = vTable.getActionList();
  3516. for (var actionIndex = 0; actionIndex < actions.length; actionIndex++) {
  3517. if (!actions[actionIndex]) {
  3518. continue;
  3519. }
  3520. var baseCell = actions[actionIndex].baseCell;
  3521. var virtualPosition = actions[actionIndex].virtualTable;
  3522. var hasRowspan = (baseCell.rowSpan && baseCell.rowSpan > 1);
  3523. var rowspanNumber = (hasRowspan) ? parseInt(baseCell.rowSpan, 10) : 0;
  3524. switch (actions[actionIndex].action) {
  3525. case TableResultAction.resultAction.Ignore:
  3526. continue;
  3527. case TableResultAction.resultAction.AddCell:
  3528. var nextRow = row.next('tr')[0];
  3529. if (!nextRow) {
  3530. continue;
  3531. }
  3532. var cloneRow = row[0].cells[cellPos];
  3533. if (hasRowspan) {
  3534. if (rowspanNumber > 2) {
  3535. rowspanNumber--;
  3536. nextRow.insertBefore(cloneRow, nextRow.cells[cellPos]);
  3537. nextRow.cells[cellPos].setAttribute('rowSpan', rowspanNumber);
  3538. nextRow.cells[cellPos].innerHTML = '';
  3539. } else if (rowspanNumber === 2) {
  3540. nextRow.insertBefore(cloneRow, nextRow.cells[cellPos]);
  3541. nextRow.cells[cellPos].removeAttribute('rowSpan');
  3542. nextRow.cells[cellPos].innerHTML = '';
  3543. }
  3544. }
  3545. continue;
  3546. case TableResultAction.resultAction.SubtractSpanCount:
  3547. if (hasRowspan) {
  3548. if (rowspanNumber > 2) {
  3549. rowspanNumber--;
  3550. baseCell.setAttribute('rowSpan', rowspanNumber);
  3551. if (virtualPosition.rowIndex !== rowPos && baseCell.cellIndex === cellPos) {
  3552. baseCell.innerHTML = '';
  3553. }
  3554. } else if (rowspanNumber === 2) {
  3555. baseCell.removeAttribute('rowSpan');
  3556. if (virtualPosition.rowIndex !== rowPos && baseCell.cellIndex === cellPos) {
  3557. baseCell.innerHTML = '';
  3558. }
  3559. }
  3560. }
  3561. continue;
  3562. case TableResultAction.resultAction.RemoveCell:
  3563. // Do not need remove cell because row will be deleted.
  3564. continue;
  3565. }
  3566. }
  3567. row.remove();
  3568. };
  3569. /**
  3570. * Delete current col
  3571. *
  3572. * @param {WrappedRange} rng
  3573. * @return {Node}
  3574. */
  3575. Table.prototype.deleteCol = function (rng) {
  3576. var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
  3577. var row = $$1(cell).closest('tr');
  3578. var cellPos = row.children('td, th').index($$1(cell));
  3579. var vTable = new TableResultAction(cell, TableResultAction.where.Column, TableResultAction.requestAction.Delete, $$1(row).closest('table')[0]);
  3580. var actions = vTable.getActionList();
  3581. for (var actionIndex = 0; actionIndex < actions.length; actionIndex++) {
  3582. if (!actions[actionIndex]) {
  3583. continue;
  3584. }
  3585. switch (actions[actionIndex].action) {
  3586. case TableResultAction.resultAction.Ignore:
  3587. continue;
  3588. case TableResultAction.resultAction.SubtractSpanCount:
  3589. var baseCell = actions[actionIndex].baseCell;
  3590. var hasColspan = (baseCell.colSpan && baseCell.colSpan > 1);
  3591. if (hasColspan) {
  3592. var colspanNumber = (baseCell.colSpan) ? parseInt(baseCell.colSpan, 10) : 0;
  3593. if (colspanNumber > 2) {
  3594. colspanNumber--;
  3595. baseCell.setAttribute('colSpan', colspanNumber);
  3596. if (baseCell.cellIndex === cellPos) {
  3597. baseCell.innerHTML = '';
  3598. }
  3599. } else if (colspanNumber === 2) {
  3600. baseCell.removeAttribute('colSpan');
  3601. if (baseCell.cellIndex === cellPos) {
  3602. baseCell.innerHTML = '';
  3603. }
  3604. }
  3605. }
  3606. continue;
  3607. case TableResultAction.resultAction.RemoveCell:
  3608. dom.remove(actions[actionIndex].baseCell, true);
  3609. continue;
  3610. }
  3611. }
  3612. };
  3613. /**
  3614. * create empty table element
  3615. *
  3616. * @param {Number} rowCount
  3617. * @param {Number} colCount
  3618. * @return {Node}
  3619. */
  3620. Table.prototype.createTable = function (colCount, rowCount, options) {
  3621. var tds = [];
  3622. var tdHTML;
  3623. for (var idxCol = 0; idxCol < colCount; idxCol++) {
  3624. tds.push('<td>' + dom.blank + '</td>');
  3625. }
  3626. tdHTML = tds.join('');
  3627. var trs = [];
  3628. var trHTML;
  3629. for (var idxRow = 0; idxRow < rowCount; idxRow++) {
  3630. trs.push('<tr>' + tdHTML + '</tr>');
  3631. }
  3632. trHTML = trs.join('');
  3633. var $table = $$1('<table>' + trHTML + '</table>');
  3634. if (options && options.tableClassName) {
  3635. $table.addClass(options.tableClassName);
  3636. }
  3637. return $table[0];
  3638. };
  3639. /**
  3640. * Delete current table
  3641. *
  3642. * @param {WrappedRange} rng
  3643. * @return {Node}
  3644. */
  3645. Table.prototype.deleteTable = function (rng) {
  3646. var cell = dom.ancestor(rng.commonAncestor(), dom.isCell);
  3647. $$1(cell).closest('table').remove();
  3648. };
  3649. return Table;
  3650. }());
  3651. var KEY_BOGUS = 'bogus';
  3652. /**
  3653. * @class Editor
  3654. */
  3655. var Editor = /** @class */ (function () {
  3656. function Editor(context) {
  3657. var _this = this;
  3658. this.context = context;
  3659. this.$note = context.layoutInfo.note;
  3660. this.$editor = context.layoutInfo.editor;
  3661. this.$editable = context.layoutInfo.editable;
  3662. this.options = context.options;
  3663. this.lang = this.options.langInfo;
  3664. this.editable = this.$editable[0];
  3665. this.lastRange = null;
  3666. this.style = new Style();
  3667. this.table = new Table();
  3668. this.typing = new Typing();
  3669. this.bullet = new Bullet();
  3670. this.history = new History(this.$editable);
  3671. this.context.memo('help.undo', this.lang.help.undo);
  3672. this.context.memo('help.redo', this.lang.help.redo);
  3673. this.context.memo('help.tab', this.lang.help.tab);
  3674. this.context.memo('help.untab', this.lang.help.untab);
  3675. this.context.memo('help.insertParagraph', this.lang.help.insertParagraph);
  3676. this.context.memo('help.insertOrderedList', this.lang.help.insertOrderedList);
  3677. this.context.memo('help.insertUnorderedList', this.lang.help.insertUnorderedList);
  3678. this.context.memo('help.indent', this.lang.help.indent);
  3679. this.context.memo('help.outdent', this.lang.help.outdent);
  3680. this.context.memo('help.formatPara', this.lang.help.formatPara);
  3681. this.context.memo('help.insertHorizontalRule', this.lang.help.insertHorizontalRule);
  3682. this.context.memo('help.fontName', this.lang.help.fontName);
  3683. // native commands(with execCommand), generate function for execCommand
  3684. var commands = [
  3685. 'bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript',
  3686. 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull',
  3687. 'formatBlock', 'removeFormat', 'backColor'
  3688. ];
  3689. for (var idx = 0, len = commands.length; idx < len; idx++) {
  3690. this[commands[idx]] = (function (sCmd) {
  3691. return function (value) {
  3692. _this.beforeCommand();
  3693. document.execCommand(sCmd, false, value);
  3694. _this.afterCommand(true);
  3695. };
  3696. })(commands[idx]);
  3697. this.context.memo('help.' + commands[idx], this.lang.help[commands[idx]]);
  3698. }
  3699. this.fontName = this.wrapCommand(function (value) {
  3700. return _this.fontStyling('font-family', "\'" + value + "\'");
  3701. });
  3702. this.fontSize = this.wrapCommand(function (value) {
  3703. return _this.fontStyling('font-size', value + 'px');
  3704. });
  3705. for (var idx = 1; idx <= 6; idx++) {
  3706. this['formatH' + idx] = (function (idx) {
  3707. return function () {
  3708. _this.formatBlock('H' + idx);
  3709. };
  3710. })(idx);
  3711. this.context.memo('help.formatH' + idx, this.lang.help['formatH' + idx]);
  3712. }
  3713. this.insertParagraph = this.wrapCommand(function () {
  3714. _this.typing.insertParagraph(_this.editable);
  3715. });
  3716. this.insertOrderedList = this.wrapCommand(function () {
  3717. _this.bullet.insertOrderedList(_this.editable);
  3718. });
  3719. this.insertUnorderedList = this.wrapCommand(function () {
  3720. _this.bullet.insertUnorderedList(_this.editable);
  3721. });
  3722. this.indent = this.wrapCommand(function () {
  3723. _this.bullet.indent(_this.editable);
  3724. });
  3725. this.outdent = this.wrapCommand(function () {
  3726. _this.bullet.outdent(_this.editable);
  3727. });
  3728. /**
  3729. * insertNode
  3730. * insert node
  3731. * @param {Node} node
  3732. */
  3733. this.insertNode = this.wrapCommand(function (node) {
  3734. if (_this.isLimited($$1(node).text().length)) {
  3735. return;
  3736. }
  3737. var rng = _this.createRange();
  3738. rng.insertNode(node);
  3739. range.createFromNodeAfter(node).select();
  3740. });
  3741. /**
  3742. * insert text
  3743. * @param {String} text
  3744. */
  3745. this.insertText = this.wrapCommand(function (text) {
  3746. if (_this.isLimited(text.length)) {
  3747. return;
  3748. }
  3749. var rng = _this.createRange();
  3750. var textNode = rng.insertNode(dom.createText(text));
  3751. range.create(textNode, dom.nodeLength(textNode)).select();
  3752. });
  3753. /**
  3754. * paste HTML
  3755. * @param {String} markup
  3756. */
  3757. this.pasteHTML = this.wrapCommand(function (markup) {
  3758. if (_this.isLimited(markup.length)) {
  3759. return;
  3760. }
  3761. var contents = _this.createRange().pasteHTML(markup);
  3762. range.createFromNodeAfter(lists.last(contents)).select();
  3763. });
  3764. /**
  3765. * formatBlock
  3766. *
  3767. * @param {String} tagName
  3768. */
  3769. this.formatBlock = this.wrapCommand(function (tagName, $target) {
  3770. var onApplyCustomStyle = _this.options.callbacks.onApplyCustomStyle;
  3771. if (onApplyCustomStyle) {
  3772. onApplyCustomStyle.call(_this, $target, _this.context, _this.onFormatBlock);
  3773. } else {
  3774. _this.onFormatBlock(tagName, $target);
  3775. }
  3776. });
  3777. /**
  3778. * insert horizontal rule
  3779. */
  3780. this.insertHorizontalRule = this.wrapCommand(function () {
  3781. var hrNode = _this.createRange().insertNode(dom.create('HR'));
  3782. if (hrNode.nextSibling) {
  3783. range.create(hrNode.nextSibling, 0).normalize().select();
  3784. }
  3785. });
  3786. /**
  3787. * lineHeight
  3788. * @param {String} value
  3789. */
  3790. this.lineHeight = this.wrapCommand(function (value) {
  3791. _this.style.stylePara(_this.createRange(), {
  3792. lineHeight: value
  3793. });
  3794. });
  3795. /**
  3796. * create link (command)
  3797. *
  3798. * @param {Object} linkInfo
  3799. */
  3800. this.createLink = this.wrapCommand(function (linkInfo) {
  3801. var linkUrl = linkInfo.url;
  3802. var linkText = linkInfo.text;
  3803. var isNewWindow = linkInfo.isNewWindow;
  3804. var rng = linkInfo.range || _this.createRange();
  3805. var isTextChanged = rng.toString() !== linkText;
  3806. // handle spaced urls from input
  3807. if (typeof linkUrl === 'string') {
  3808. linkUrl = linkUrl.trim();
  3809. }
  3810. if (_this.options.onCreateLink) {
  3811. linkUrl = _this.options.onCreateLink(linkUrl);
  3812. } else {
  3813. // if url doesn't match an URL schema, set http:// as default
  3814. linkUrl = /^[A-Za-z][A-Za-z0-9+-.]*\:[\/\/]?/.test(linkUrl) ?
  3815. linkUrl : 'http://' + linkUrl;
  3816. }
  3817. var anchors = [];
  3818. if (isTextChanged) {
  3819. rng = rng.deleteContents();
  3820. var anchor = rng.insertNode($$1('<A>' + linkText + '</A>')[0]);
  3821. anchors.push(anchor);
  3822. } else {
  3823. anchors = _this.style.styleNodes(rng, {
  3824. nodeName: 'A',
  3825. expandClosestSibling: true,
  3826. onlyPartialContains: true
  3827. });
  3828. }
  3829. $$1.each(anchors, function (idx, anchor) {
  3830. $$1(anchor).attr('href', linkUrl);
  3831. if (isNewWindow) {
  3832. $$1(anchor).attr('target', '_blank');
  3833. } else {
  3834. $$1(anchor).removeAttr('target');
  3835. }
  3836. });
  3837. var startRange = range.createFromNodeBefore(lists.head(anchors));
  3838. var startPoint = startRange.getStartPoint();
  3839. var endRange = range.createFromNodeAfter(lists.last(anchors));
  3840. var endPoint = endRange.getEndPoint();
  3841. range.create(startPoint.node, startPoint.offset, endPoint.node, endPoint.offset).select();
  3842. });
  3843. /**
  3844. * setting color
  3845. *
  3846. * @param {Object} sObjColor color code
  3847. * @param {String} sObjColor.foreColor foreground color
  3848. * @param {String} sObjColor.backColor background color
  3849. */
  3850. this.color = this.wrapCommand(function (colorInfo) {
  3851. var foreColor = colorInfo.foreColor;
  3852. var backColor = colorInfo.backColor;
  3853. if (foreColor) {
  3854. document.execCommand('foreColor', false, foreColor);
  3855. }
  3856. if (backColor) {
  3857. document.execCommand('backColor', false, backColor);
  3858. }
  3859. });
  3860. /**
  3861. * Set foreground color
  3862. *
  3863. * @param {String} colorCode foreground color code
  3864. */
  3865. this.foreColor = this.wrapCommand(function (colorInfo) {
  3866. document.execCommand('styleWithCSS', false, true);
  3867. document.execCommand('foreColor', false, colorInfo);
  3868. });
  3869. /**
  3870. * insert Table
  3871. *
  3872. * @param {String} dimension of table (ex : "5x5")
  3873. */
  3874. this.insertTable = this.wrapCommand(function (dim) {
  3875. var dimension = dim.split('x');
  3876. var rng = _this.createRange().deleteContents();
  3877. rng.insertNode(_this.table.createTable(dimension[0], dimension[1], _this.options));
  3878. });
  3879. /**
  3880. * remove media object and Figure Elements if media object is img with Figure.
  3881. */
  3882. this.removeMedia = this.wrapCommand(function () {
  3883. var $target = $$1(_this.restoreTarget()).parent();
  3884. if ($target.parent('figure').length) {
  3885. $target.parent('figure').remove();
  3886. } else {
  3887. $target = $$1(_this.restoreTarget()).detach();
  3888. }
  3889. _this.context.triggerEvent('media.delete', $target, _this.$editable);
  3890. });
  3891. /**
  3892. * float me
  3893. *
  3894. * @param {String} value
  3895. */
  3896. this.floatMe = this.wrapCommand(function (value) {
  3897. var $target = $$1(_this.restoreTarget());
  3898. $target.toggleClass('note-float-left', value === 'left');
  3899. $target.toggleClass('note-float-right', value === 'right');
  3900. $target.css('float', value);
  3901. });
  3902. /**
  3903. * resize overlay element
  3904. * @param {String} value
  3905. */
  3906. this.resize = this.wrapCommand(function (value) {
  3907. var $target = $$1(_this.restoreTarget());
  3908. $target.css({
  3909. width: value * 100 + '%',
  3910. height: ''
  3911. });
  3912. });
  3913. }
  3914. Editor.prototype.initialize = function () {
  3915. var _this = this;
  3916. // bind custom events
  3917. this.$editable.on('keydown', function (event) {
  3918. if (event.keyCode === key.code.ENTER) {
  3919. _this.context.triggerEvent('enter', event);
  3920. }
  3921. _this.context.triggerEvent('keydown', event);
  3922. if (!event.isDefaultPrevented()) {
  3923. if (_this.options.shortcuts) {
  3924. _this.handleKeyMap(event);
  3925. } else {
  3926. _this.preventDefaultEditableShortCuts(event);
  3927. }
  3928. }
  3929. if (_this.isLimited(1, event)) {
  3930. return false;
  3931. }
  3932. }).on('keyup', function (event) {
  3933. _this.context.triggerEvent('keyup', event);
  3934. }).on('focus', function (event) {
  3935. _this.context.triggerEvent('focus', event);
  3936. }).on('blur', function (event) {
  3937. _this.context.triggerEvent('blur', event);
  3938. }).on('mousedown', function (event) {
  3939. _this.context.triggerEvent('mousedown', event);
  3940. }).on('mouseup', function (event) {
  3941. _this.context.triggerEvent('mouseup', event);
  3942. }).on('scroll', function (event) {
  3943. _this.context.triggerEvent('scroll', event);
  3944. }).on('paste', function (event) {
  3945. _this.context.triggerEvent('paste', event);
  3946. });
  3947. // init content before set event
  3948. this.$editable.html(dom.html(this.$note) || dom.emptyPara);
  3949. this.$editable.on(env.inputEventName, func.debounce(function () {
  3950. _this.context.triggerEvent('change', _this.$editable.html());
  3951. }, 100));
  3952. this.$editor.on('focusin', function (event) {
  3953. _this.context.triggerEvent('focusin', event);
  3954. }).on('focusout', function (event) {
  3955. _this.context.triggerEvent('focusout', event);
  3956. });
  3957. if (!this.options.airMode) {
  3958. if (this.options.width) {
  3959. this.$editor.outerWidth(this.options.width);
  3960. }
  3961. if (this.options.height) {
  3962. this.$editable.outerHeight(this.options.height);
  3963. }
  3964. if (this.options.maxHeight) {
  3965. this.$editable.css('max-height', this.options.maxHeight);
  3966. }
  3967. if (this.options.minHeight) {
  3968. this.$editable.css('min-height', this.options.minHeight);
  3969. }
  3970. }
  3971. this.history.recordUndo();
  3972. };
  3973. Editor.prototype.destroy = function () {
  3974. this.$editable.off();
  3975. };
  3976. Editor.prototype.handleKeyMap = function (event) {
  3977. var keyMap = this.options.keyMap[env.isMac ? 'mac' : 'pc'];
  3978. var keys = [];
  3979. if (event.metaKey) {
  3980. keys.push('CMD');
  3981. }
  3982. if (event.ctrlKey && !event.altKey) {
  3983. keys.push('CTRL');
  3984. }
  3985. if (event.shiftKey) {
  3986. keys.push('SHIFT');
  3987. }
  3988. var keyName = key.nameFromCode[event.keyCode];
  3989. if (keyName) {
  3990. keys.push(keyName);
  3991. }
  3992. var eventName = keyMap[keys.join('+')];
  3993. if (eventName) {
  3994. if (this.context.invoke(eventName) !== false) {
  3995. event.preventDefault();
  3996. }
  3997. } else if (key.isEdit(event.keyCode)) {
  3998. this.afterCommand();
  3999. }
  4000. };
  4001. Editor.prototype.preventDefaultEditableShortCuts = function (event) {
  4002. // B(Bold, 66) / I(Italic, 73) / U(Underline, 85)
  4003. if ((event.ctrlKey || event.metaKey) &&
  4004. lists.contains([66, 73, 85], event.keyCode)) {
  4005. event.preventDefault();
  4006. }
  4007. };
  4008. Editor.prototype.isLimited = function (pad, event) {
  4009. pad = pad || 0;
  4010. if (typeof event !== 'undefined') {
  4011. if (key.isMove(event.keyCode) ||
  4012. (event.ctrlKey || event.metaKey) ||
  4013. lists.contains([key.code.BACKSPACE, key.code.DELETE], event.keyCode)) {
  4014. return false;
  4015. }
  4016. }
  4017. if (this.options.maxTextLength > 0) {
  4018. if ((this.$editable.text().length + pad) >= this.options.maxTextLength) {
  4019. return true;
  4020. }
  4021. }
  4022. return false;
  4023. };
  4024. /**
  4025. * create range
  4026. * @return {WrappedRange}
  4027. */
  4028. Editor.prototype.createRange = function () {
  4029. this.focus();
  4030. return range.create(this.editable);
  4031. };
  4032. /**
  4033. * saveRange
  4034. *
  4035. * save current range
  4036. *
  4037. * @param {Boolean} [thenCollapse=false]
  4038. */
  4039. Editor.prototype.saveRange = function (thenCollapse) {
  4040. this.lastRange = this.createRange();
  4041. if (thenCollapse) {
  4042. this.lastRange.collapse().select();
  4043. }
  4044. };
  4045. /**
  4046. * restoreRange
  4047. *
  4048. * restore lately range
  4049. */
  4050. Editor.prototype.restoreRange = function () {
  4051. if (this.lastRange) {
  4052. this.lastRange.select();
  4053. this.focus();
  4054. }
  4055. };
  4056. Editor.prototype.saveTarget = function (node) {
  4057. this.$editable.data('target', node);
  4058. };
  4059. Editor.prototype.clearTarget = function () {
  4060. this.$editable.removeData('target');
  4061. };
  4062. Editor.prototype.restoreTarget = function () {
  4063. return this.$editable.data('target');
  4064. };
  4065. /**
  4066. * currentStyle
  4067. *
  4068. * current style
  4069. * @return {Object|Boolean} unfocus
  4070. */
  4071. Editor.prototype.currentStyle = function () {
  4072. var rng = range.create();
  4073. if (rng) {
  4074. rng = rng.normalize();
  4075. }
  4076. return rng ? this.style.current(rng) : this.style.fromNode(this.$editable);
  4077. };
  4078. /**
  4079. * style from node
  4080. *
  4081. * @param {jQuery} $node
  4082. * @return {Object}
  4083. */
  4084. Editor.prototype.styleFromNode = function ($node) {
  4085. return this.style.fromNode($node);
  4086. };
  4087. /**
  4088. * undo
  4089. */
  4090. Editor.prototype.undo = function () {
  4091. this.context.triggerEvent('before.command', this.$editable.html());
  4092. this.history.undo();
  4093. this.context.triggerEvent('change', this.$editable.html());
  4094. };
  4095. /**
  4096. * redo
  4097. */
  4098. Editor.prototype.redo = function () {
  4099. this.context.triggerEvent('before.command', this.$editable.html());
  4100. this.history.redo();
  4101. this.context.triggerEvent('change', this.$editable.html());
  4102. };
  4103. /**
  4104. * before command
  4105. */
  4106. Editor.prototype.beforeCommand = function () {
  4107. this.context.triggerEvent('before.command', this.$editable.html());
  4108. // keep focus on editable before command execution
  4109. this.focus();
  4110. };
  4111. /**
  4112. * after command
  4113. * @param {Boolean} isPreventTrigger
  4114. */
  4115. Editor.prototype.afterCommand = function (isPreventTrigger) {
  4116. this.history.recordUndo();
  4117. if (!isPreventTrigger) {
  4118. this.context.triggerEvent('change', this.$editable.html());
  4119. }
  4120. };
  4121. /**
  4122. * handle tab key
  4123. */
  4124. Editor.prototype.tab = function () {
  4125. var rng = this.createRange();
  4126. if (rng.isCollapsed() && rng.isOnCell()) {
  4127. this.table.tab(rng);
  4128. } else {
  4129. if (this.options.tabSize === 0) {
  4130. return false;
  4131. }
  4132. if (!this.isLimited(this.options.tabSize)) {
  4133. this.beforeCommand();
  4134. this.typing.insertTab(rng, this.options.tabSize);
  4135. this.afterCommand();
  4136. }
  4137. }
  4138. };
  4139. /**
  4140. * handle shift+tab key
  4141. */
  4142. Editor.prototype.untab = function () {
  4143. var rng = this.createRange();
  4144. if (rng.isCollapsed() && rng.isOnCell()) {
  4145. this.table.tab(rng, true);
  4146. } else {
  4147. if (this.options.tabSize === 0) {
  4148. return false;
  4149. }
  4150. }
  4151. };
  4152. /**
  4153. * run given function between beforeCommand and afterCommand
  4154. */
  4155. Editor.prototype.wrapCommand = function (fn) {
  4156. var _this = this;
  4157. return function () {
  4158. _this.beforeCommand();
  4159. fn.apply(_this, arguments);
  4160. _this.afterCommand();
  4161. };
  4162. };
  4163. /**
  4164. * insert image
  4165. *
  4166. * @param {String} src
  4167. * @param {String|Function} param
  4168. * @return {Promise}
  4169. */
  4170. Editor.prototype.insertImage = function (src, param) {
  4171. var _this = this;
  4172. return createImage(src, param).then(function ($image) {
  4173. _this.beforeCommand();
  4174. if (typeof param === 'function') {
  4175. param($image);
  4176. } else {
  4177. if (typeof param === 'string') {
  4178. $image.attr('data-filename', param);
  4179. }
  4180. $image.css('width', Math.min(_this.$editable.width(), $image.width()));
  4181. }
  4182. $image.show();
  4183. range.create(_this.editable).insertNode($image[0]);
  4184. range.createFromNodeAfter($image[0]).select();
  4185. _this.afterCommand();
  4186. }).fail(function (e) {
  4187. _this.context.triggerEvent('image.upload.error', e);
  4188. });
  4189. };
  4190. /**
  4191. * insertImages
  4192. * @param {File[]} files
  4193. */
  4194. Editor.prototype.insertImages = function (files) {
  4195. var _this = this;
  4196. $$1.each(files, function (idx, file) {
  4197. var filename = file.name;
  4198. if (_this.options.maximumImageFileSize && _this.options.maximumImageFileSize < file.size) {
  4199. _this.context.triggerEvent('image.upload.error', _this.lang.image.maximumFileSizeError);
  4200. } else {
  4201. readFileAsDataURL(file).then(function (dataURL) {
  4202. return _this.insertImage(dataURL, filename);
  4203. }).fail(function () {
  4204. _this.context.triggerEvent('image.upload.error');
  4205. });
  4206. }
  4207. });
  4208. };
  4209. /**
  4210. * insertImagesOrCallback
  4211. * @param {File[]} files
  4212. */
  4213. Editor.prototype.insertImagesOrCallback = function (files) {
  4214. var callbacks = this.options.callbacks;
  4215. // If onImageUpload this.options setted
  4216. if (callbacks.onImageUpload) {
  4217. this.context.triggerEvent('image.upload', files);
  4218. // else insert Image as dataURL
  4219. } else {
  4220. this.insertImages(files);
  4221. }
  4222. };
  4223. /**
  4224. * return selected plain text
  4225. * @return {String} text
  4226. */
  4227. Editor.prototype.getSelectedText = function () {
  4228. var rng = this.createRange();
  4229. // if range on anchor, expand range with anchor
  4230. if (rng.isOnAnchor()) {
  4231. rng = range.createFromNode(dom.ancestor(rng.sc, dom.isAnchor));
  4232. }
  4233. return rng.toString();
  4234. };
  4235. Editor.prototype.onFormatBlock = function (tagName, $target) {
  4236. // [workaround] for MSIE, IE need `<`
  4237. tagName = env.isMSIE ? '<' + tagName + '>' : tagName;
  4238. document.execCommand('FormatBlock', false, tagName);
  4239. // support custom class
  4240. if ($target && $target.length) {
  4241. var className = $target[0].className || '';
  4242. if (className) {
  4243. var currentRange = this.createRange();
  4244. var $parent = $$1([currentRange.sc, currentRange.ec]).closest(tagName);
  4245. $parent.addClass(className);
  4246. }
  4247. }
  4248. };
  4249. Editor.prototype.formatPara = function () {
  4250. this.formatBlock('P');
  4251. };
  4252. Editor.prototype.fontStyling = function (target, value) {
  4253. var rng = this.createRange();
  4254. if (rng) {
  4255. var spans = this.style.styleNodes(rng);
  4256. $$1(spans).css(target, value);
  4257. // [workaround] added styled bogus span for style
  4258. // - also bogus character needed for cursor position
  4259. if (rng.isCollapsed()) {
  4260. var firstSpan = lists.head(spans);
  4261. if (firstSpan && !dom.nodeLength(firstSpan)) {
  4262. firstSpan.innerHTML = dom.ZERO_WIDTH_NBSP_CHAR;
  4263. range.createFromNodeAfter(firstSpan.firstChild).select();
  4264. this.$editable.data(KEY_BOGUS, firstSpan);
  4265. }
  4266. }
  4267. }
  4268. };
  4269. /**
  4270. * unlink
  4271. *
  4272. * @type command
  4273. */
  4274. Editor.prototype.unlink = function () {
  4275. var rng = this.createRange();
  4276. if (rng.isOnAnchor()) {
  4277. var anchor = dom.ancestor(rng.sc, dom.isAnchor);
  4278. rng = range.createFromNode(anchor);
  4279. rng.select();
  4280. this.beforeCommand();
  4281. document.execCommand('unlink');
  4282. this.afterCommand();
  4283. }
  4284. };
  4285. /**
  4286. * returns link info
  4287. *
  4288. * @return {Object}
  4289. * @return {WrappedRange} return.range
  4290. * @return {String} return.text
  4291. * @return {Boolean} [return.isNewWindow=true]
  4292. * @return {String} [return.url=""]
  4293. */
  4294. Editor.prototype.getLinkInfo = function () {
  4295. var rng = this.createRange().expand(dom.isAnchor);
  4296. // Get the first anchor on range(for edit).
  4297. var $anchor = $$1(lists.head(rng.nodes(dom.isAnchor)));
  4298. var linkInfo = {
  4299. range: rng,
  4300. text: rng.toString(),
  4301. url: $anchor.length ? $anchor.attr('href') : ''
  4302. };
  4303. // Define isNewWindow when anchor exists.
  4304. if ($anchor.length) {
  4305. linkInfo.isNewWindow = $anchor.attr('target') === '_blank';
  4306. }
  4307. return linkInfo;
  4308. };
  4309. Editor.prototype.addRow = function (position) {
  4310. var rng = this.createRange(this.$editable);
  4311. if (rng.isCollapsed() && rng.isOnCell()) {
  4312. this.beforeCommand();
  4313. this.table.addRow(rng, position);
  4314. this.afterCommand();
  4315. }
  4316. };
  4317. Editor.prototype.addCol = function (position) {
  4318. var rng = this.createRange(this.$editable);
  4319. if (rng.isCollapsed() && rng.isOnCell()) {
  4320. this.beforeCommand();
  4321. this.table.addCol(rng, position);
  4322. this.afterCommand();
  4323. }
  4324. };
  4325. Editor.prototype.deleteRow = function () {
  4326. var rng = this.createRange(this.$editable);
  4327. if (rng.isCollapsed() && rng.isOnCell()) {
  4328. this.beforeCommand();
  4329. this.table.deleteRow(rng);
  4330. this.afterCommand();
  4331. }
  4332. };
  4333. Editor.prototype.deleteCol = function () {
  4334. var rng = this.createRange(this.$editable);
  4335. if (rng.isCollapsed() && rng.isOnCell()) {
  4336. this.beforeCommand();
  4337. this.table.deleteCol(rng);
  4338. this.afterCommand();
  4339. }
  4340. };
  4341. Editor.prototype.deleteTable = function () {
  4342. var rng = this.createRange(this.$editable);
  4343. if (rng.isCollapsed() && rng.isOnCell()) {
  4344. this.beforeCommand();
  4345. this.table.deleteTable(rng);
  4346. this.afterCommand();
  4347. }
  4348. };
  4349. /**
  4350. * @param {Position} pos
  4351. * @param {jQuery} $target - target element
  4352. * @param {Boolean} [bKeepRatio] - keep ratio
  4353. */
  4354. Editor.prototype.resizeTo = function (pos, $target, bKeepRatio) {
  4355. var imageSize;
  4356. if (bKeepRatio) {
  4357. var newRatio = pos.y / pos.x;
  4358. var ratio = $target.data('ratio');
  4359. imageSize = {
  4360. width: ratio > newRatio ? pos.x : pos.y / ratio,
  4361. height: ratio > newRatio ? pos.x * ratio : pos.y
  4362. };
  4363. } else {
  4364. imageSize = {
  4365. width: pos.x,
  4366. height: pos.y
  4367. };
  4368. }
  4369. $target.css(imageSize);
  4370. };
  4371. /**
  4372. * returns whether editable area has focus or not.
  4373. */
  4374. Editor.prototype.hasFocus = function () {
  4375. return this.$editable.is(':focus');
  4376. };
  4377. /**
  4378. * set focus
  4379. */
  4380. Editor.prototype.focus = function () {
  4381. // [workaround] Screen will move when page is scolled in IE.
  4382. // - do focus when not focused
  4383. if (!this.hasFocus()) {
  4384. this.$editable.focus();
  4385. }
  4386. };
  4387. /**
  4388. * returns whether contents is empty or not.
  4389. * @return {Boolean}
  4390. */
  4391. Editor.prototype.isEmpty = function () {
  4392. return dom.isEmpty(this.$editable[0]) || dom.emptyPara === this.$editable.html();
  4393. };
  4394. /**
  4395. * Removes all contents and restores the editable instance to an _emptyPara_.
  4396. */
  4397. Editor.prototype.empty = function () {
  4398. this.context.invoke('code', dom.emptyPara);
  4399. };
  4400. return Editor;
  4401. }());
  4402. var Clipboard = /** @class */ (function () {
  4403. function Clipboard(context) {
  4404. this.context = context;
  4405. this.$editable = context.layoutInfo.editable;
  4406. }
  4407. Clipboard.prototype.initialize = function () {
  4408. this.$editable.on('paste', this.pasteByEvent.bind(this));
  4409. };
  4410. /**
  4411. * paste by clipboard event
  4412. *
  4413. * @param {Event} event
  4414. */
  4415. Clipboard.prototype.pasteByEvent = function (event) {
  4416. var clipboardData = event.originalEvent.clipboardData;
  4417. if (clipboardData && clipboardData.items && clipboardData.items.length) {
  4418. var item = lists.head(clipboardData.items);
  4419. if (item.kind === 'file' && item.type.indexOf('image/') !== -1) {
  4420. this.context.invoke('editor.insertImagesOrCallback', [item.getAsFile()]);
  4421. }
  4422. this.context.invoke('editor.afterCommand');
  4423. }
  4424. };
  4425. return Clipboard;
  4426. }());
  4427. var Dropzone = /** @class */ (function () {
  4428. function Dropzone(context) {
  4429. this.context = context;
  4430. this.$eventListener = $$1(document);
  4431. this.$editor = context.layoutInfo.editor;
  4432. this.$editable = context.layoutInfo.editable;
  4433. this.options = context.options;
  4434. this.lang = this.options.langInfo;
  4435. this.documentEventHandlers = {};
  4436. this.$dropzone = $$1([
  4437. '<div class="note-dropzone">',
  4438. ' <div class="note-dropzone-message"/>',
  4439. '</div>'
  4440. ].join('')).prependTo(this.$editor);
  4441. }
  4442. /**
  4443. * attach Drag and Drop Events
  4444. */
  4445. Dropzone.prototype.initialize = function () {
  4446. if (this.options.disableDragAndDrop) {
  4447. // prevent default drop event
  4448. this.documentEventHandlers.onDrop = function (e) {
  4449. e.preventDefault();
  4450. };
  4451. // do not consider outside of dropzone
  4452. this.$eventListener = this.$dropzone;
  4453. this.$eventListener.on('drop', this.documentEventHandlers.onDrop);
  4454. } else {
  4455. this.attachDragAndDropEvent();
  4456. }
  4457. };
  4458. /**
  4459. * attach Drag and Drop Events
  4460. */
  4461. Dropzone.prototype.attachDragAndDropEvent = function () {
  4462. var _this = this;
  4463. var collection = $$1();
  4464. var $dropzoneMessage = this.$dropzone.find('.note-dropzone-message');
  4465. this.documentEventHandlers.onDragenter = function (e) {
  4466. var isCodeview = _this.context.invoke('codeview.isActivated');
  4467. var hasEditorSize = _this.$editor.width() > 0 && _this.$editor.height() > 0;
  4468. if (!isCodeview && !collection.length && hasEditorSize) {
  4469. _this.$editor.addClass('dragover');
  4470. _this.$dropzone.width(_this.$editor.width());
  4471. _this.$dropzone.height(_this.$editor.height());
  4472. $dropzoneMessage.text(_this.lang.image.dragImageHere);
  4473. }
  4474. collection = collection.add(e.target);
  4475. };
  4476. this.documentEventHandlers.onDragleave = function (e) {
  4477. collection = collection.not(e.target);
  4478. if (!collection.length) {
  4479. _this.$editor.removeClass('dragover');
  4480. }
  4481. };
  4482. this.documentEventHandlers.onDrop = function () {
  4483. collection = $$1();
  4484. _this.$editor.removeClass('dragover');
  4485. };
  4486. // show dropzone on dragenter when dragging a object to document
  4487. // -but only if the editor is visible, i.e. has a positive width and height
  4488. this.$eventListener.on('dragenter', this.documentEventHandlers.onDragenter)
  4489. .on('dragleave', this.documentEventHandlers.onDragleave)
  4490. .on('drop', this.documentEventHandlers.onDrop);
  4491. // change dropzone's message on hover.
  4492. this.$dropzone.on('dragenter', function () {
  4493. _this.$dropzone.addClass('hover');
  4494. $dropzoneMessage.text(_this.lang.image.dropImage);
  4495. }).on('dragleave', function () {
  4496. _this.$dropzone.removeClass('hover');
  4497. $dropzoneMessage.text(_this.lang.image.dragImageHere);
  4498. });
  4499. // attach dropImage
  4500. this.$dropzone.on('drop', function (event) {
  4501. var dataTransfer = event.originalEvent.dataTransfer;
  4502. // stop the browser from opening the dropped content
  4503. event.preventDefault();
  4504. if (dataTransfer && dataTransfer.files && dataTransfer.files.length) {
  4505. _this.$editable.focus();
  4506. _this.context.invoke('editor.insertImagesOrCallback', dataTransfer.files);
  4507. } else {
  4508. $$1.each(dataTransfer.types, function (idx, type) {
  4509. var content = dataTransfer.getData(type);
  4510. if (type.toLowerCase().indexOf('text') > -1) {
  4511. _this.context.invoke('editor.pasteHTML', content);
  4512. } else {
  4513. $$1(content).each(function (idx, item) {
  4514. _this.context.invoke('editor.insertNode', item);
  4515. });
  4516. }
  4517. });
  4518. }
  4519. }).on('dragover', false); // prevent default dragover event
  4520. };
  4521. Dropzone.prototype.destroy = function () {
  4522. var _this = this;
  4523. Object.keys(this.documentEventHandlers).forEach(function (key) {
  4524. _this.$eventListener.off(key.substr(2).toLowerCase(), _this.documentEventHandlers[key]);
  4525. });
  4526. this.documentEventHandlers = {};
  4527. };
  4528. return Dropzone;
  4529. }());
  4530. var CodeMirror;
  4531. if (env.hasCodeMirror) {
  4532. if (env.isSupportAmd) {
  4533. require(['codemirror'], function (cm) {
  4534. CodeMirror = cm;
  4535. });
  4536. } else {
  4537. CodeMirror = window.CodeMirror;
  4538. }
  4539. }
  4540. /**
  4541. * @class Codeview
  4542. */
  4543. var CodeView = /** @class */ (function () {
  4544. function CodeView(context) {
  4545. this.context = context;
  4546. this.$editor = context.layoutInfo.editor;
  4547. this.$editable = context.layoutInfo.editable;
  4548. this.$codable = context.layoutInfo.codable;
  4549. this.options = context.options;
  4550. }
  4551. CodeView.prototype.sync = function () {
  4552. var isCodeview = this.isActivated();
  4553. if (isCodeview && env.hasCodeMirror) {
  4554. this.$codable.data('cmEditor').save();
  4555. }
  4556. };
  4557. /**
  4558. * @return {Boolean}
  4559. */
  4560. CodeView.prototype.isActivated = function () {
  4561. return this.$editor.hasClass('codeview');
  4562. };
  4563. /**
  4564. * toggle codeview
  4565. */
  4566. CodeView.prototype.toggle = function () {
  4567. if (this.isActivated()) {
  4568. this.deactivate();
  4569. } else {
  4570. this.activate();
  4571. }
  4572. this.context.triggerEvent('codeview.toggled');
  4573. };
  4574. /**
  4575. * activate code view
  4576. */
  4577. CodeView.prototype.activate = function () {
  4578. var _this = this;
  4579. this.$codable.val(dom.html(this.$editable, this.options.prettifyHtml));
  4580. this.$codable.height(this.$editable.height());
  4581. this.context.invoke('toolbar.updateCodeview', true);
  4582. this.$editor.addClass('codeview');
  4583. this.$codable.focus();
  4584. // activate CodeMirror as codable
  4585. if (env.hasCodeMirror) {
  4586. var cmEditor_1 = CodeMirror.fromTextArea(this.$codable[0], this.options.codemirror);
  4587. // CodeMirror TernServer
  4588. if (this.options.codemirror.tern) {
  4589. var server_1 = new CodeMirror.TernServer(this.options.codemirror.tern);
  4590. cmEditor_1.ternServer = server_1;
  4591. cmEditor_1.on('cursorActivity', function (cm) {
  4592. server_1.updateArgHints(cm);
  4593. });
  4594. }
  4595. cmEditor_1.on('blur', function (event) {
  4596. _this.context.triggerEvent('blur.codeview', cmEditor_1.getValue(), event);
  4597. });
  4598. // CodeMirror hasn't Padding.
  4599. cmEditor_1.setSize(null, this.$editable.outerHeight());
  4600. this.$codable.data('cmEditor', cmEditor_1);
  4601. } else {
  4602. this.$codable.on('blur', function (event) {
  4603. _this.context.triggerEvent('blur.codeview', _this.$codable.val(), event);
  4604. });
  4605. }
  4606. };
  4607. /**
  4608. * deactivate code view
  4609. */
  4610. CodeView.prototype.deactivate = function () {
  4611. // deactivate CodeMirror as codable
  4612. if (env.hasCodeMirror) {
  4613. var cmEditor = this.$codable.data('cmEditor');
  4614. this.$codable.val(cmEditor.getValue());
  4615. cmEditor.toTextArea();
  4616. }
  4617. var value = dom.value(this.$codable, this.options.prettifyHtml) || dom.emptyPara;
  4618. var isChange = this.$editable.html() !== value;
  4619. this.$editable.html(value);
  4620. this.$editable.height(this.options.height ? this.$codable.height() : 'auto');
  4621. this.$editor.removeClass('codeview');
  4622. if (isChange) {
  4623. this.context.triggerEvent('change', this.$editable.html(), this.$editable);
  4624. }
  4625. this.$editable.focus();
  4626. this.context.invoke('toolbar.updateCodeview', false);
  4627. };
  4628. CodeView.prototype.destroy = function () {
  4629. if (this.isActivated()) {
  4630. this.deactivate();
  4631. }
  4632. };
  4633. return CodeView;
  4634. }());
  4635. var EDITABLE_PADDING = 24;
  4636. var Statusbar = /** @class */ (function () {
  4637. function Statusbar(context) {
  4638. this.$document = $$1(document);
  4639. this.$statusbar = context.layoutInfo.statusbar;
  4640. this.$editable = context.layoutInfo.editable;
  4641. this.options = context.options;
  4642. }
  4643. Statusbar.prototype.initialize = function () {
  4644. var _this = this;
  4645. if (this.options.airMode || this.options.disableResizeEditor) {
  4646. this.destroy();
  4647. return;
  4648. }
  4649. this.$statusbar.on('mousedown', function (event) {
  4650. event.preventDefault();
  4651. event.stopPropagation();
  4652. var editableTop = _this.$editable.offset().top - _this.$document.scrollTop();
  4653. var onMouseMove = function (event) {
  4654. var height = event.clientY - (editableTop + EDITABLE_PADDING);
  4655. height = (_this.options.minheight > 0) ? Math.max(height, _this.options.minheight) : height;
  4656. height = (_this.options.maxHeight > 0) ? Math.min(height, _this.options.maxHeight) : height;
  4657. _this.$editable.height(height);
  4658. };
  4659. _this.$document.on('mousemove', onMouseMove).one('mouseup', function () {
  4660. _this.$document.off('mousemove', onMouseMove);
  4661. });
  4662. });
  4663. };
  4664. Statusbar.prototype.destroy = function () {
  4665. this.$statusbar.off();
  4666. };
  4667. return Statusbar;
  4668. }());
  4669. var Fullscreen = /** @class */ (function () {
  4670. function Fullscreen(context) {
  4671. var _this = this;
  4672. this.context = context;
  4673. this.$editor = context.layoutInfo.editor;
  4674. this.$toolbar = context.layoutInfo.toolbar;
  4675. this.$editable = context.layoutInfo.editable;
  4676. this.$codable = context.layoutInfo.codable;
  4677. this.$window = $$1(window);
  4678. this.$scrollbar = $$1('html, body');
  4679. this.onResize = function () {
  4680. _this.resizeTo({
  4681. h: _this.$window.height() - _this.$toolbar.outerHeight()
  4682. });
  4683. };
  4684. }
  4685. Fullscreen.prototype.resizeTo = function (size) {
  4686. this.$editable.css('height', size.h);
  4687. this.$codable.css('height', size.h);
  4688. if (this.$codable.data('cmeditor')) {
  4689. this.$codable.data('cmeditor').setsize(null, size.h);
  4690. }
  4691. };
  4692. /**
  4693. * toggle fullscreen
  4694. */
  4695. Fullscreen.prototype.toggle = function () {
  4696. this.$editor.toggleClass('fullscreen');
  4697. if (this.isFullscreen()) {
  4698. this.$editable.data('orgHeight', this.$editable.css('height'));
  4699. this.$window.on('resize', this.onResize).trigger('resize');
  4700. this.$scrollbar.css('overflow', 'hidden');
  4701. } else {
  4702. this.$window.off('resize', this.onResize);
  4703. this.resizeTo({
  4704. h: this.$editable.data('orgHeight')
  4705. });
  4706. this.$scrollbar.css('overflow', 'visible');
  4707. }
  4708. this.context.invoke('toolbar.updateFullscreen', this.isFullscreen());
  4709. };
  4710. Fullscreen.prototype.isFullscreen = function () {
  4711. return this.$editor.hasClass('fullscreen');
  4712. };
  4713. return Fullscreen;
  4714. }());
  4715. var Handle = /** @class */ (function () {
  4716. function Handle(context) {
  4717. var _this = this;
  4718. this.context = context;
  4719. this.$document = $$1(document);
  4720. this.$editingArea = context.layoutInfo.editingArea;
  4721. this.options = context.options;
  4722. this.lang = this.options.langInfo;
  4723. this.events = {
  4724. 'summernote.mousedown': function (we, e) {
  4725. if (_this.update(e.target)) {
  4726. e.preventDefault();
  4727. }
  4728. },
  4729. 'summernote.keyup summernote.scroll summernote.change summernote.dialog.shown': function () {
  4730. _this.update();
  4731. },
  4732. 'summernote.disable': function () {
  4733. _this.hide();
  4734. },
  4735. 'summernote.codeview.toggled': function () {
  4736. _this.update();
  4737. }
  4738. };
  4739. }
  4740. Handle.prototype.initialize = function () {
  4741. var _this = this;
  4742. this.$handle = $$1([
  4743. '<div class="note-handle">',
  4744. '<div class="note-control-selection">',
  4745. '<div class="note-control-selection-bg"></div>',
  4746. '<div class="note-control-holder note-control-nw"></div>',
  4747. '<div class="note-control-holder note-control-ne"></div>',
  4748. '<div class="note-control-holder note-control-sw"></div>',
  4749. '<div class="',
  4750. (this.options.disableResizeImage ? 'note-control-holder' : 'note-control-sizing'),
  4751. ' note-control-se"></div>',
  4752. (this.options.disableResizeImage ? '' : '<div class="note-control-selection-info"></div>'),
  4753. '</div>',
  4754. '</div>'
  4755. ].join('')).prependTo(this.$editingArea);
  4756. this.$handle.on('mousedown', function (event) {
  4757. if (dom.isControlSizing(event.target)) {
  4758. event.preventDefault();
  4759. event.stopPropagation();
  4760. var $target_1 = _this.$handle.find('.note-control-selection').data('target');
  4761. var posStart_1 = $target_1.offset();
  4762. var scrollTop_1 = _this.$document.scrollTop();
  4763. var onMouseMove_1 = function (event) {
  4764. _this.context.invoke('editor.resizeTo', {
  4765. x: event.clientX - posStart_1.left,
  4766. y: event.clientY - (posStart_1.top - scrollTop_1)
  4767. }, $target_1, !event.shiftKey);
  4768. _this.update($target_1[0]);
  4769. };
  4770. _this.$document
  4771. .on('mousemove', onMouseMove_1)
  4772. .one('mouseup', function (e) {
  4773. e.preventDefault();
  4774. _this.$document.off('mousemove', onMouseMove_1);
  4775. _this.context.invoke('editor.afterCommand');
  4776. });
  4777. if (!$target_1.data('ratio')) {
  4778. $target_1.data('ratio', $target_1.height() / $target_1.width());
  4779. }
  4780. }
  4781. });
  4782. // Listen for scrolling on the handle overlay.
  4783. this.$handle.on('wheel', function (e) {
  4784. e.preventDefault();
  4785. _this.update();
  4786. });
  4787. };
  4788. Handle.prototype.destroy = function () {
  4789. this.$handle.remove();
  4790. };
  4791. Handle.prototype.update = function (target) {
  4792. if (this.context.isDisabled()) {
  4793. return false;
  4794. }
  4795. var isImage = dom.isImg(target);
  4796. var $selection = this.$handle.find('.note-control-selection');
  4797. this.context.invoke('imagePopover.update', target);
  4798. if (isImage) {
  4799. var $image = $$1(target);
  4800. var position = $image.position();
  4801. var pos = {
  4802. left: position.left + parseInt($image.css('marginLeft'), 10),
  4803. top: position.top + parseInt($image.css('marginTop'), 10)
  4804. };
  4805. // exclude margin
  4806. var imageSize = {
  4807. w: $image.outerWidth(false),
  4808. h: $image.outerHeight(false)
  4809. };
  4810. $selection.css({
  4811. display: 'block',
  4812. left: pos.left,
  4813. top: pos.top,
  4814. width: imageSize.w,
  4815. height: imageSize.h
  4816. }).data('target', $image); // save current image element.
  4817. var origImageObj = new Image();
  4818. origImageObj.src = $image.attr('src');
  4819. var sizingText = imageSize.w + 'x' + imageSize.h + ' (' + this.lang.image.original + ': ' + origImageObj.width + 'x' + origImageObj.height + ')';
  4820. $selection.find('.note-control-selection-info').text(sizingText);
  4821. this.context.invoke('editor.saveTarget', target);
  4822. } else {
  4823. this.hide();
  4824. }
  4825. return isImage;
  4826. };
  4827. /**
  4828. * hide
  4829. *
  4830. * @param {jQuery} $handle
  4831. */
  4832. Handle.prototype.hide = function () {
  4833. this.context.invoke('editor.clearTarget');
  4834. this.$handle.children().hide();
  4835. };
  4836. return Handle;
  4837. }());
  4838. var defaultScheme = 'http://';
  4839. var linkPattern = /^([A-Za-z][A-Za-z0-9+-.]*\:[\/\/]?|mailto:[A-Z0-9._%+-]+@)?(www\.)?(.+)$/i;
  4840. var AutoLink = /** @class */ (function () {
  4841. function AutoLink(context) {
  4842. var _this = this;
  4843. this.context = context;
  4844. this.events = {
  4845. 'summernote.keyup': function (we, e) {
  4846. if (!e.isDefaultPrevented()) {
  4847. _this.handleKeyup(e);
  4848. }
  4849. },
  4850. 'summernote.keydown': function (we, e) {
  4851. _this.handleKeydown(e);
  4852. }
  4853. };
  4854. }
  4855. AutoLink.prototype.initialize = function () {
  4856. this.lastWordRange = null;
  4857. };
  4858. AutoLink.prototype.destroy = function () {
  4859. this.lastWordRange = null;
  4860. };
  4861. AutoLink.prototype.replace = function () {
  4862. if (!this.lastWordRange) {
  4863. return;
  4864. }
  4865. var keyword = this.lastWordRange.toString();
  4866. var match = keyword.match(linkPattern);
  4867. if (match && (match[1] || match[2])) {
  4868. var link = match[1] ? keyword : defaultScheme + keyword;
  4869. var node = $$1('<a />').html(keyword).attr('href', link)[0];
  4870. this.lastWordRange.insertNode(node);
  4871. this.lastWordRange = null;
  4872. this.context.invoke('editor.focus');
  4873. }
  4874. };
  4875. AutoLink.prototype.handleKeydown = function (e) {
  4876. if (lists.contains([key.code.ENTER, key.code.SPACE], e.keyCode)) {
  4877. var wordRange = this.context.invoke('editor.createRange').getWordRange();
  4878. this.lastWordRange = wordRange;
  4879. }
  4880. };
  4881. AutoLink.prototype.handleKeyup = function (e) {
  4882. if (lists.contains([key.code.ENTER, key.code.SPACE], e.keyCode)) {
  4883. this.replace();
  4884. }
  4885. };
  4886. return AutoLink;
  4887. }());
  4888. /**
  4889. * textarea auto sync.
  4890. */
  4891. var AutoSync = /** @class */ (function () {
  4892. function AutoSync(context) {
  4893. var _this = this;
  4894. this.$note = context.layoutInfo.note;
  4895. this.events = {
  4896. 'summernote.change': function () {
  4897. _this.$note.val(context.invoke('code'));
  4898. }
  4899. };
  4900. }
  4901. AutoSync.prototype.shouldInitialize = function () {
  4902. return dom.isTextarea(this.$note[0]);
  4903. };
  4904. return AutoSync;
  4905. }());
  4906. var Placeholder = /** @class */ (function () {
  4907. function Placeholder(context) {
  4908. var _this = this;
  4909. this.context = context;
  4910. this.$editingArea = context.layoutInfo.editingArea;
  4911. this.options = context.options;
  4912. this.events = {
  4913. 'summernote.init summernote.change': function () {
  4914. _this.update();
  4915. },
  4916. 'summernote.codeview.toggled': function () {
  4917. _this.update();
  4918. }
  4919. };
  4920. }
  4921. Placeholder.prototype.shouldInitialize = function () {
  4922. return !!this.options.placeholder;
  4923. };
  4924. Placeholder.prototype.initialize = function () {
  4925. var _this = this;
  4926. this.$placeholder = $$1('<div class="note-placeholder">');
  4927. this.$placeholder.on('click', function () {
  4928. _this.context.invoke('focus');
  4929. }).text(this.options.placeholder).prependTo(this.$editingArea);
  4930. this.update();
  4931. };
  4932. Placeholder.prototype.destroy = function () {
  4933. this.$placeholder.remove();
  4934. };
  4935. Placeholder.prototype.update = function () {
  4936. var isShow = !this.context.invoke('codeview.isActivated') && this.context.invoke('editor.isEmpty');
  4937. this.$placeholder.toggle(isShow);
  4938. };
  4939. return Placeholder;
  4940. }());
  4941. var Buttons = /** @class */ (function () {
  4942. function Buttons(context) {
  4943. this.ui = $$1.summernote.ui;
  4944. this.context = context;
  4945. this.$toolbar = context.layoutInfo.toolbar;
  4946. this.options = context.options;
  4947. this.lang = this.options.langInfo;
  4948. this.invertedKeyMap = func.invertObject(this.options.keyMap[env.isMac ? 'mac' : 'pc']);
  4949. }
  4950. Buttons.prototype.representShortcut = function (editorMethod) {
  4951. var shortcut = this.invertedKeyMap[editorMethod];
  4952. if (!this.options.shortcuts || !shortcut) {
  4953. return '';
  4954. }
  4955. if (env.isMac) {
  4956. shortcut = shortcut.replace('CMD', '⌘').replace('SHIFT', '⇧');
  4957. }
  4958. shortcut = shortcut.replace('BACKSLASH', '\\')
  4959. .replace('SLASH', '/')
  4960. .replace('LEFTBRACKET', '[')
  4961. .replace('RIGHTBRACKET', ']');
  4962. return ' (' + shortcut + ')';
  4963. };
  4964. Buttons.prototype.button = function (o) {
  4965. if (!this.options.tooltip && o.tooltip) {
  4966. delete o.tooltip;
  4967. }
  4968. o.container = this.options.container;
  4969. return this.ui.button(o);
  4970. };
  4971. Buttons.prototype.initialize = function () {
  4972. this.addToolbarButtons();
  4973. this.addImagePopoverButtons();
  4974. this.addLinkPopoverButtons();
  4975. this.addTablePopoverButtons();
  4976. this.fontInstalledMap = {};
  4977. };
  4978. Buttons.prototype.destroy = function () {
  4979. delete this.fontInstalledMap;
  4980. };
  4981. Buttons.prototype.isFontInstalled = function (name) {
  4982. if (!this.fontInstalledMap.hasOwnProperty(name)) {
  4983. this.fontInstalledMap[name] = env.isFontInstalled(name) ||
  4984. lists.contains(this.options.fontNamesIgnoreCheck, name);
  4985. }
  4986. return this.fontInstalledMap[name];
  4987. };
  4988. Buttons.prototype.isFontDeservedToAdd = function (name) {
  4989. var genericFamilies = ['sans-serif', 'serif', 'monospace', 'cursive', 'fantasy'];
  4990. name = name.toLowerCase();
  4991. return ((name !== '') && this.isFontInstalled(name) && ($$1.inArray(name, genericFamilies) === -1));
  4992. };
  4993. Buttons.prototype.addToolbarButtons = function () {
  4994. var _this = this;
  4995. this.context.memo('button.style', function () {
  4996. return _this.ui.buttonGroup([
  4997. _this.button({
  4998. className: 'dropdown-toggle',
  4999. contents: _this.ui.dropdownButtonContents(_this.ui.icon(_this.options.icons.magic), _this.options),
  5000. tooltip: _this.lang.style.style,
  5001. data: {
  5002. toggle: 'dropdown'
  5003. }
  5004. }),
  5005. _this.ui.dropdown({
  5006. className: 'dropdown-style',
  5007. items: _this.options.styleTags,
  5008. template: function (item) {
  5009. if (typeof item === 'string') {
  5010. item = {
  5011. tag: item,
  5012. title: (_this.lang.style.hasOwnProperty(item) ? _this.lang.style[item] : item)
  5013. };
  5014. }
  5015. var tag = item.tag;
  5016. var title = item.title;
  5017. var style = item.style ? ' style="' + item.style + '" ' : '';
  5018. var className = item.className ? ' class="' + item.className + '"' : '';
  5019. return '<' + tag + style + className + '>' + title + '</' + tag + '>';
  5020. },
  5021. click: _this.context.createInvokeHandler('editor.formatBlock')
  5022. })
  5023. ]).render();
  5024. });
  5025. var _loop_1 = function (styleIdx, styleLen) {
  5026. var item = this_1.options.styleTags[styleIdx];
  5027. this_1.context.memo('button.style.' + item, function () {
  5028. return _this.button({
  5029. className: 'note-btn-style-' + item,
  5030. contents: '<div data-value="' + item + '">' + item.toUpperCase() + '</div>',
  5031. tooltip: item.toUpperCase(),
  5032. click: _this.context.createInvokeHandler('editor.formatBlock')
  5033. }).render();
  5034. });
  5035. };
  5036. var this_1 = this;
  5037. for (var styleIdx = 0, styleLen = this.options.styleTags.length; styleIdx < styleLen; styleIdx++) {
  5038. _loop_1(styleIdx, styleLen);
  5039. }
  5040. this.context.memo('button.bold', function () {
  5041. return _this.button({
  5042. className: 'note-btn-bold',
  5043. contents: _this.ui.icon(_this.options.icons.bold),
  5044. tooltip: _this.lang.font.bold + _this.representShortcut('bold'),
  5045. click: _this.context.createInvokeHandlerAndUpdateState('editor.bold')
  5046. }).render();
  5047. });
  5048. this.context.memo('button.italic', function () {
  5049. return _this.button({
  5050. className: 'note-btn-italic',
  5051. contents: _this.ui.icon(_this.options.icons.italic),
  5052. tooltip: _this.lang.font.italic + _this.representShortcut('italic'),
  5053. click: _this.context.createInvokeHandlerAndUpdateState('editor.italic')
  5054. }).render();
  5055. });
  5056. this.context.memo('button.underline', function () {
  5057. return _this.button({
  5058. className: 'note-btn-underline',
  5059. contents: _this.ui.icon(_this.options.icons.underline),
  5060. tooltip: _this.lang.font.underline + _this.representShortcut('underline'),
  5061. click: _this.context.createInvokeHandlerAndUpdateState('editor.underline')
  5062. }).render();
  5063. });
  5064. this.context.memo('button.clear', function () {
  5065. return _this.button({
  5066. contents: _this.ui.icon(_this.options.icons.eraser),
  5067. tooltip: _this.lang.font.clear + _this.representShortcut('removeFormat'),
  5068. click: _this.context.createInvokeHandler('editor.removeFormat')
  5069. }).render();
  5070. });
  5071. this.context.memo('button.strikethrough', function () {
  5072. return _this.button({
  5073. className: 'note-btn-strikethrough',
  5074. contents: _this.ui.icon(_this.options.icons.strikethrough),
  5075. tooltip: _this.lang.font.strikethrough + _this.representShortcut('strikethrough'),
  5076. click: _this.context.createInvokeHandlerAndUpdateState('editor.strikethrough')
  5077. }).render();
  5078. });
  5079. this.context.memo('button.superscript', function () {
  5080. return _this.button({
  5081. className: 'note-btn-superscript',
  5082. contents: _this.ui.icon(_this.options.icons.superscript),
  5083. tooltip: _this.lang.font.superscript,
  5084. click: _this.context.createInvokeHandlerAndUpdateState('editor.superscript')
  5085. }).render();
  5086. });
  5087. this.context.memo('button.subscript', function () {
  5088. return _this.button({
  5089. className: 'note-btn-subscript',
  5090. contents: _this.ui.icon(_this.options.icons.subscript),
  5091. tooltip: _this.lang.font.subscript,
  5092. click: _this.context.createInvokeHandlerAndUpdateState('editor.subscript')
  5093. }).render();
  5094. });
  5095. this.context.memo('button.fontname', function () {
  5096. var styleInfo = _this.context.invoke('editor.currentStyle');
  5097. // Add 'default' fonts into the fontnames array if not exist
  5098. $$1.each(styleInfo['font-family'].split(','), function (idx, fontname) {
  5099. fontname = fontname.trim().replace(/['"]+/g, '');
  5100. if (_this.isFontDeservedToAdd(fontname)) {
  5101. if ($$1.inArray(fontname, _this.options.fontNames) === -1) {
  5102. _this.options.fontNames.push(fontname);
  5103. }
  5104. }
  5105. });
  5106. return _this.ui.buttonGroup([
  5107. _this.button({
  5108. className: 'dropdown-toggle',
  5109. contents: _this.ui.dropdownButtonContents('<span class="note-current-fontname"/>', _this.options),
  5110. tooltip: _this.lang.font.name,
  5111. data: {
  5112. toggle: 'dropdown'
  5113. }
  5114. }),
  5115. _this.ui.dropdownCheck({
  5116. className: 'dropdown-fontname',
  5117. checkClassName: _this.options.icons.menuCheck,
  5118. items: _this.options.fontNames.filter(_this.isFontInstalled.bind(_this)),
  5119. template: function (item) {
  5120. return '<span style="font-family: \'' + item + '\'">' + item + '</span>';
  5121. },
  5122. click: _this.context.createInvokeHandlerAndUpdateState('editor.fontName')
  5123. })
  5124. ]).render();
  5125. });
  5126. this.context.memo('button.fontsize', function () {
  5127. return _this.ui.buttonGroup([
  5128. _this.button({
  5129. className: 'dropdown-toggle',
  5130. contents: _this.ui.dropdownButtonContents('<span class="note-current-fontsize"/>', _this.options),
  5131. tooltip: _this.lang.font.size,
  5132. data: {
  5133. toggle: 'dropdown'
  5134. }
  5135. }),
  5136. _this.ui.dropdownCheck({
  5137. className: 'dropdown-fontsize',
  5138. checkClassName: _this.options.icons.menuCheck,
  5139. items: _this.options.fontSizes,
  5140. click: _this.context.createInvokeHandlerAndUpdateState('editor.fontSize')
  5141. })
  5142. ]).render();
  5143. });
  5144. this.context.memo('button.color', function () {
  5145. return _this.ui.buttonGroup({
  5146. className: 'note-color',
  5147. children: [
  5148. _this.button({
  5149. className: 'note-current-color-button',
  5150. contents: _this.ui.icon(_this.options.icons.font + ' note-recent-color'),
  5151. tooltip: _this.lang.color.recent,
  5152. click: function (e) {
  5153. var $button = $$1(e.currentTarget);
  5154. _this.context.invoke('editor.color', {
  5155. backColor: $button.attr('data-backColor'),
  5156. foreColor: $button.attr('data-foreColor')
  5157. });
  5158. },
  5159. callback: function ($button) {
  5160. var $recentColor = $button.find('.note-recent-color');
  5161. $recentColor.css('background-color', '#FFFF00');
  5162. $button.attr('data-backColor', '#FFFF00');
  5163. }
  5164. }),
  5165. _this.button({
  5166. className: 'dropdown-toggle',
  5167. contents: _this.ui.dropdownButtonContents('', _this.options),
  5168. tooltip: _this.lang.color.more,
  5169. data: {
  5170. toggle: 'dropdown'
  5171. }
  5172. }),
  5173. _this.ui.dropdown({
  5174. items: [
  5175. '<div class="note-palette">',
  5176. ' <div class="note-palette-title">' + _this.lang.color.background + '</div>',
  5177. ' <div>',
  5178. ' <button type="button" class="note-color-reset btn btn-light" data-event="backColor" data-value="inherit">',
  5179. _this.lang.color.transparent,
  5180. ' </button>',
  5181. ' </div>',
  5182. ' <div class="note-holder" data-event="backColor"/>',
  5183. '</div>',
  5184. '<div class="note-palette">',
  5185. ' <div class="note-palette-title">' + _this.lang.color.foreground + '</div>',
  5186. ' <div>',
  5187. ' <button type="button" class="note-color-reset btn btn-light" data-event="removeFormat" data-value="foreColor">',
  5188. _this.lang.color.resetToDefault,
  5189. ' </button>',
  5190. ' </div>',
  5191. ' <div class="note-holder" data-event="foreColor"/>',
  5192. '</div>'
  5193. ].join(''),
  5194. callback: function ($dropdown) {
  5195. $dropdown.find('.note-holder').each(function (idx, item) {
  5196. var $holder = $$1(item);
  5197. $holder.append(_this.ui.palette({
  5198. colors: _this.options.colors,
  5199. eventName: $holder.data('event'),
  5200. container: _this.options.container,
  5201. tooltip: _this.options.tooltip
  5202. }).render());
  5203. });
  5204. },
  5205. click: function (event) {
  5206. var $button = $$1(event.target);
  5207. var eventName = $button.data('event');
  5208. var value = $button.data('value');
  5209. if (eventName && value) {
  5210. var key = eventName === 'backColor' ? 'background-color' : 'color';
  5211. var $color = $button.closest('.note-color').find('.note-recent-color');
  5212. var $currentButton = $button.closest('.note-color').find('.note-current-color-button');
  5213. $color.css(key, value);
  5214. $currentButton.attr('data-' + eventName, value);
  5215. _this.context.invoke('editor.' + eventName, value);
  5216. }
  5217. }
  5218. })
  5219. ]
  5220. }).render();
  5221. });
  5222. this.context.memo('button.ul', function () {
  5223. return _this.button({
  5224. contents: _this.ui.icon(_this.options.icons.unorderedlist),
  5225. tooltip: _this.lang.lists.unordered + _this.representShortcut('insertUnorderedList'),
  5226. click: _this.context.createInvokeHandler('editor.insertUnorderedList')
  5227. }).render();
  5228. });
  5229. this.context.memo('button.ol', function () {
  5230. return _this.button({
  5231. contents: _this.ui.icon(_this.options.icons.orderedlist),
  5232. tooltip: _this.lang.lists.ordered + _this.representShortcut('insertOrderedList'),
  5233. click: _this.context.createInvokeHandler('editor.insertOrderedList')
  5234. }).render();
  5235. });
  5236. var justifyLeft = this.button({
  5237. contents: this.ui.icon(this.options.icons.alignLeft),
  5238. tooltip: this.lang.paragraph.left + this.representShortcut('justifyLeft'),
  5239. click: this.context.createInvokeHandler('editor.justifyLeft')
  5240. });
  5241. var justifyCenter = this.button({
  5242. contents: this.ui.icon(this.options.icons.alignCenter),
  5243. tooltip: this.lang.paragraph.center + this.representShortcut('justifyCenter'),
  5244. click: this.context.createInvokeHandler('editor.justifyCenter')
  5245. });
  5246. var justifyRight = this.button({
  5247. contents: this.ui.icon(this.options.icons.alignRight),
  5248. tooltip: this.lang.paragraph.right + this.representShortcut('justifyRight'),
  5249. click: this.context.createInvokeHandler('editor.justifyRight')
  5250. });
  5251. var justifyFull = this.button({
  5252. contents: this.ui.icon(this.options.icons.alignJustify),
  5253. tooltip: this.lang.paragraph.justify + this.representShortcut('justifyFull'),
  5254. click: this.context.createInvokeHandler('editor.justifyFull')
  5255. });
  5256. var outdent = this.button({
  5257. contents: this.ui.icon(this.options.icons.outdent),
  5258. tooltip: this.lang.paragraph.outdent + this.representShortcut('outdent'),
  5259. click: this.context.createInvokeHandler('editor.outdent')
  5260. });
  5261. var indent = this.button({
  5262. contents: this.ui.icon(this.options.icons.indent),
  5263. tooltip: this.lang.paragraph.indent + this.representShortcut('indent'),
  5264. click: this.context.createInvokeHandler('editor.indent')
  5265. });
  5266. this.context.memo('button.justifyLeft', func.invoke(justifyLeft, 'render'));
  5267. this.context.memo('button.justifyCenter', func.invoke(justifyCenter, 'render'));
  5268. this.context.memo('button.justifyRight', func.invoke(justifyRight, 'render'));
  5269. this.context.memo('button.justifyFull', func.invoke(justifyFull, 'render'));
  5270. this.context.memo('button.outdent', func.invoke(outdent, 'render'));
  5271. this.context.memo('button.indent', func.invoke(indent, 'render'));
  5272. this.context.memo('button.paragraph', function () {
  5273. return _this.ui.buttonGroup([
  5274. _this.button({
  5275. className: 'dropdown-toggle',
  5276. contents: _this.ui.dropdownButtonContents(_this.ui.icon(_this.options.icons.alignLeft), _this.options),
  5277. tooltip: _this.lang.paragraph.paragraph,
  5278. data: {
  5279. toggle: 'dropdown'
  5280. }
  5281. }),
  5282. _this.ui.dropdown([
  5283. _this.ui.buttonGroup({
  5284. className: 'note-align',
  5285. children: [justifyLeft, justifyCenter, justifyRight, justifyFull]
  5286. }),
  5287. _this.ui.buttonGroup({
  5288. className: 'note-list',
  5289. children: [outdent, indent]
  5290. })
  5291. ])
  5292. ]).render();
  5293. });
  5294. this.context.memo('button.height', function () {
  5295. return _this.ui.buttonGroup([
  5296. _this.button({
  5297. className: 'dropdown-toggle',
  5298. contents: _this.ui.dropdownButtonContents(_this.ui.icon(_this.options.icons.textHeight), _this.options),
  5299. tooltip: _this.lang.font.height,
  5300. data: {
  5301. toggle: 'dropdown'
  5302. }
  5303. }),
  5304. _this.ui.dropdownCheck({
  5305. items: _this.options.lineHeights,
  5306. checkClassName: _this.options.icons.menuCheck,
  5307. className: 'dropdown-line-height',
  5308. click: _this.context.createInvokeHandler('editor.lineHeight')
  5309. })
  5310. ]).render();
  5311. });
  5312. this.context.memo('button.table', function () {
  5313. return _this.ui.buttonGroup([
  5314. _this.button({
  5315. className: 'dropdown-toggle',
  5316. contents: _this.ui.dropdownButtonContents(_this.ui.icon(_this.options.icons.table), _this.options),
  5317. tooltip: _this.lang.table.table,
  5318. data: {
  5319. toggle: 'dropdown'
  5320. }
  5321. }),
  5322. _this.ui.dropdown({
  5323. className: 'note-table',
  5324. items: [
  5325. '<div class="note-dimension-picker">',
  5326. ' <div class="note-dimension-picker-mousecatcher" data-event="insertTable" data-value="1x1"/>',
  5327. ' <div class="note-dimension-picker-highlighted"/>',
  5328. ' <div class="note-dimension-picker-unhighlighted"/>',
  5329. '</div>',
  5330. '<div class="note-dimension-display">1 x 1</div>'
  5331. ].join('')
  5332. })
  5333. ], {
  5334. callback: function ($node) {
  5335. var $catcher = $node.find('.note-dimension-picker-mousecatcher');
  5336. $catcher.css({
  5337. width: _this.options.insertTableMaxSize.col + 'em',
  5338. height: _this.options.insertTableMaxSize.row + 'em'
  5339. }).mousedown(_this.context.createInvokeHandler('editor.insertTable'))
  5340. .on('mousemove', _this.tableMoveHandler.bind(_this));
  5341. }
  5342. }).render();
  5343. });
  5344. this.context.memo('button.link', function () {
  5345. return _this.button({
  5346. contents: _this.ui.icon(_this.options.icons.link),
  5347. tooltip: _this.lang.link.link + _this.representShortcut('linkDialog.show'),
  5348. click: _this.context.createInvokeHandler('linkDialog.show')
  5349. }).render();
  5350. });
  5351. this.context.memo('button.picture', function () {
  5352. return _this.button({
  5353. contents: _this.ui.icon(_this.options.icons.picture),
  5354. tooltip: _this.lang.image.image,
  5355. click: _this.context.createInvokeHandler('imageDialog.show')
  5356. }).render();
  5357. });
  5358. this.context.memo('button.video', function () {
  5359. return _this.button({
  5360. contents: _this.ui.icon(_this.options.icons.video),
  5361. tooltip: _this.lang.video.video,
  5362. click: _this.context.createInvokeHandler('videoDialog.show')
  5363. }).render();
  5364. });
  5365. this.context.memo('button.hr', function () {
  5366. return _this.button({
  5367. contents: _this.ui.icon(_this.options.icons.minus),
  5368. tooltip: _this.lang.hr.insert + _this.representShortcut('insertHorizontalRule'),
  5369. click: _this.context.createInvokeHandler('editor.insertHorizontalRule')
  5370. }).render();
  5371. });
  5372. this.context.memo('button.fullscreen', function () {
  5373. return _this.button({
  5374. className: 'btn-fullscreen',
  5375. contents: _this.ui.icon(_this.options.icons.arrowsAlt),
  5376. tooltip: _this.options.fullscreen,
  5377. click: _this.context.createInvokeHandler('fullscreen.toggle')
  5378. }).render();
  5379. });
  5380. this.context.memo('button.codeview', function () {
  5381. return _this.button({
  5382. className: 'btn-codeview',
  5383. contents: _this.ui.icon(_this.options.icons.code),
  5384. tooltip: _this.options.codeview,
  5385. click: _this.context.createInvokeHandler('codeview.toggle')
  5386. }).render();
  5387. });
  5388. this.context.memo('button.redo', function () {
  5389. return _this.button({
  5390. contents: _this.ui.icon(_this.options.icons.redo),
  5391. tooltip: _this.lang.history.redo + _this.representShortcut('redo'),
  5392. click: _this.context.createInvokeHandler('editor.redo')
  5393. }).render();
  5394. });
  5395. this.context.memo('button.undo', function () {
  5396. return _this.button({
  5397. contents: _this.ui.icon(_this.options.icons.undo),
  5398. tooltip: _this.lang.history.undo + _this.representShortcut('undo'),
  5399. click: _this.context.createInvokeHandler('editor.undo')
  5400. }).render();
  5401. });
  5402. this.context.memo('button.help', function () {
  5403. return _this.button({
  5404. contents: _this.ui.icon(_this.options.icons.question),
  5405. tooltip: _this.options.help,
  5406. click: _this.context.createInvokeHandler('helpDialog.show')
  5407. }).render();
  5408. });
  5409. };
  5410. /**
  5411. * image : [
  5412. * ['imagesize', ['imageSize100', 'imageSize50', 'imageSize25']],
  5413. * ['float', ['floatLeft', 'floatRight', 'floatNone' ]],
  5414. * ['remove', ['removeMedia']]
  5415. * ],
  5416. */
  5417. Buttons.prototype.addImagePopoverButtons = function () {
  5418. var _this = this;
  5419. // Image Size Buttons
  5420. this.context.memo('button.imageSize100', function () {
  5421. return _this.button({
  5422. contents: '<span class="note-fontsize-10">100%</span>',
  5423. tooltip: _this.lang.image.resizeFull,
  5424. click: _this.context.createInvokeHandler('editor.resize', '1')
  5425. }).render();
  5426. });
  5427. this.context.memo('button.imageSize50', function () {
  5428. return _this.button({
  5429. contents: '<span class="note-fontsize-10">50%</span>',
  5430. tooltip: _this.lang.image.resizeHalf,
  5431. click: _this.context.createInvokeHandler('editor.resize', '0.5')
  5432. }).render();
  5433. });
  5434. this.context.memo('button.imageSize25', function () {
  5435. return _this.button({
  5436. contents: '<span class="note-fontsize-10">25%</span>',
  5437. tooltip: _this.lang.image.resizeQuarter,
  5438. click: _this.context.createInvokeHandler('editor.resize', '0.25')
  5439. }).render();
  5440. });
  5441. // Float Buttons
  5442. this.context.memo('button.floatLeft', function () {
  5443. return _this.button({
  5444. contents: _this.ui.icon(_this.options.icons.alignLeft),
  5445. tooltip: _this.lang.image.floatLeft,
  5446. click: _this.context.createInvokeHandler('editor.floatMe', 'left')
  5447. }).render();
  5448. });
  5449. this.context.memo('button.floatRight', function () {
  5450. return _this.button({
  5451. contents: _this.ui.icon(_this.options.icons.alignRight),
  5452. tooltip: _this.lang.image.floatRight,
  5453. click: _this.context.createInvokeHandler('editor.floatMe', 'right')
  5454. }).render();
  5455. });
  5456. this.context.memo('button.floatNone', function () {
  5457. return _this.button({
  5458. contents: _this.ui.icon(_this.options.icons.alignJustify),
  5459. tooltip: _this.lang.image.floatNone,
  5460. click: _this.context.createInvokeHandler('editor.floatMe', 'none')
  5461. }).render();
  5462. });
  5463. // Remove Buttons
  5464. this.context.memo('button.removeMedia', function () {
  5465. return _this.button({
  5466. contents: _this.ui.icon(_this.options.icons.trash),
  5467. tooltip: _this.lang.image.remove,
  5468. click: _this.context.createInvokeHandler('editor.removeMedia')
  5469. }).render();
  5470. });
  5471. };
  5472. Buttons.prototype.addLinkPopoverButtons = function () {
  5473. var _this = this;
  5474. this.context.memo('button.linkDialogShow', function () {
  5475. return _this.button({
  5476. contents: _this.ui.icon(_this.options.icons.link),
  5477. tooltip: _this.lang.link.edit,
  5478. click: _this.context.createInvokeHandler('linkDialog.show')
  5479. }).render();
  5480. });
  5481. this.context.memo('button.unlink', function () {
  5482. return _this.button({
  5483. contents: _this.ui.icon(_this.options.icons.unlink),
  5484. tooltip: _this.lang.link.unlink,
  5485. click: _this.context.createInvokeHandler('editor.unlink')
  5486. }).render();
  5487. });
  5488. };
  5489. /**
  5490. * table : [
  5491. * ['add', ['addRowDown', 'addRowUp', 'addColLeft', 'addColRight']],
  5492. * ['delete', ['deleteRow', 'deleteCol', 'deleteTable']]
  5493. * ],
  5494. */
  5495. Buttons.prototype.addTablePopoverButtons = function () {
  5496. var _this = this;
  5497. this.context.memo('button.addRowUp', function () {
  5498. return _this.button({
  5499. className: 'btn-md',
  5500. contents: _this.ui.icon(_this.options.icons.rowAbove),
  5501. tooltip: _this.lang.table.addRowAbove,
  5502. click: _this.context.createInvokeHandler('editor.addRow', 'top')
  5503. }).render();
  5504. });
  5505. this.context.memo('button.addRowDown', function () {
  5506. return _this.button({
  5507. className: 'btn-md',
  5508. contents: _this.ui.icon(_this.options.icons.rowBelow),
  5509. tooltip: _this.lang.table.addRowBelow,
  5510. click: _this.context.createInvokeHandler('editor.addRow', 'bottom')
  5511. }).render();
  5512. });
  5513. this.context.memo('button.addColLeft', function () {
  5514. return _this.button({
  5515. className: 'btn-md',
  5516. contents: _this.ui.icon(_this.options.icons.colBefore),
  5517. tooltip: _this.lang.table.addColLeft,
  5518. click: _this.context.createInvokeHandler('editor.addCol', 'left')
  5519. }).render();
  5520. });
  5521. this.context.memo('button.addColRight', function () {
  5522. return _this.button({
  5523. className: 'btn-md',
  5524. contents: _this.ui.icon(_this.options.icons.colAfter),
  5525. tooltip: _this.lang.table.addColRight,
  5526. click: _this.context.createInvokeHandler('editor.addCol', 'right')
  5527. }).render();
  5528. });
  5529. this.context.memo('button.deleteRow', function () {
  5530. return _this.button({
  5531. className: 'btn-md',
  5532. contents: _this.ui.icon(_this.options.icons.rowRemove),
  5533. tooltip: _this.lang.table.delRow,
  5534. click: _this.context.createInvokeHandler('editor.deleteRow')
  5535. }).render();
  5536. });
  5537. this.context.memo('button.deleteCol', function () {
  5538. return _this.button({
  5539. className: 'btn-md',
  5540. contents: _this.ui.icon(_this.options.icons.colRemove),
  5541. tooltip: _this.lang.table.delCol,
  5542. click: _this.context.createInvokeHandler('editor.deleteCol')
  5543. }).render();
  5544. });
  5545. this.context.memo('button.deleteTable', function () {
  5546. return _this.button({
  5547. className: 'btn-md',
  5548. contents: _this.ui.icon(_this.options.icons.trash),
  5549. tooltip: _this.lang.table.delTable,
  5550. click: _this.context.createInvokeHandler('editor.deleteTable')
  5551. }).render();
  5552. });
  5553. };
  5554. Buttons.prototype.build = function ($container, groups) {
  5555. for (var groupIdx = 0, groupLen = groups.length; groupIdx < groupLen; groupIdx++) {
  5556. var group = groups[groupIdx];
  5557. var groupName = $$1.isArray(group) ? group[0] : group;
  5558. var buttons = $$1.isArray(group) ? ((group.length === 1) ? [group[0]] : group[1]) : [group];
  5559. var $group = this.ui.buttonGroup({
  5560. className: 'note-' + groupName
  5561. }).render();
  5562. for (var idx = 0, len = buttons.length; idx < len; idx++) {
  5563. var btn = this.context.memo('button.' + buttons[idx]);
  5564. if (btn) {
  5565. $group.append(typeof btn === 'function' ? btn(this.context) : btn);
  5566. }
  5567. }
  5568. $group.appendTo($container);
  5569. }
  5570. };
  5571. /**
  5572. * @param {jQuery} [$container]
  5573. */
  5574. Buttons.prototype.updateCurrentStyle = function ($container) {
  5575. var _this = this;
  5576. var $cont = $container || this.$toolbar;
  5577. var styleInfo = this.context.invoke('editor.currentStyle');
  5578. this.updateBtnStates($cont, {
  5579. '.note-btn-bold': function () {
  5580. return styleInfo['font-bold'] === 'bold';
  5581. },
  5582. '.note-btn-italic': function () {
  5583. return styleInfo['font-italic'] === 'italic';
  5584. },
  5585. '.note-btn-underline': function () {
  5586. return styleInfo['font-underline'] === 'underline';
  5587. },
  5588. '.note-btn-subscript': function () {
  5589. return styleInfo['font-subscript'] === 'subscript';
  5590. },
  5591. '.note-btn-superscript': function () {
  5592. return styleInfo['font-superscript'] === 'superscript';
  5593. },
  5594. '.note-btn-strikethrough': function () {
  5595. return styleInfo['font-strikethrough'] === 'strikethrough';
  5596. }
  5597. });
  5598. if (styleInfo['font-family']) {
  5599. var fontNames = styleInfo['font-family'].split(',').map(function (name) {
  5600. return name.replace(/[\'\"]/g, '')
  5601. .replace(/\s+$/, '')
  5602. .replace(/^\s+/, '');
  5603. });
  5604. var fontName_1 = lists.find(fontNames, this.isFontInstalled.bind(this));
  5605. $cont.find('.dropdown-fontname a').each(function (idx, item) {
  5606. var $item = $$1(item);
  5607. // always compare string to avoid creating another func.
  5608. var isChecked = ($item.data('value') + '') === (fontName_1 + '');
  5609. $item.toggleClass('checked', isChecked);
  5610. });
  5611. $cont.find('.note-current-fontname').text(fontName_1).css('font-family', fontName_1);
  5612. }
  5613. if (styleInfo['font-size']) {
  5614. var fontSize_1 = styleInfo['font-size'];
  5615. $cont.find('.dropdown-fontsize a').each(function (idx, item) {
  5616. var $item = $$1(item);
  5617. // always compare with string to avoid creating another func.
  5618. var isChecked = ($item.data('value') + '') === (fontSize_1 + '');
  5619. $item.toggleClass('checked', isChecked);
  5620. });
  5621. $cont.find('.note-current-fontsize').text(fontSize_1);
  5622. }
  5623. if (styleInfo['line-height']) {
  5624. var lineHeight_1 = styleInfo['line-height'];
  5625. $cont.find('.dropdown-line-height li a').each(function (idx, item) {
  5626. // always compare with string to avoid creating another func.
  5627. var isChecked = ($$1(item).data('value') + '') === (lineHeight_1 + '');
  5628. _this.className = isChecked ? 'checked' : '';
  5629. });
  5630. }
  5631. };
  5632. Buttons.prototype.updateBtnStates = function ($container, infos) {
  5633. var _this = this;
  5634. $$1.each(infos, function (selector, pred) {
  5635. _this.ui.toggleBtnActive($container.find(selector), pred());
  5636. });
  5637. };
  5638. Buttons.prototype.tableMoveHandler = function (event) {
  5639. var PX_PER_EM = 18;
  5640. var $picker = $$1(event.target.parentNode); // target is mousecatcher
  5641. var $dimensionDisplay = $picker.next();
  5642. var $catcher = $picker.find('.note-dimension-picker-mousecatcher');
  5643. var $highlighted = $picker.find('.note-dimension-picker-highlighted');
  5644. var $unhighlighted = $picker.find('.note-dimension-picker-unhighlighted');
  5645. var posOffset;
  5646. // HTML5 with jQuery - e.offsetX is undefined in Firefox
  5647. if (event.offsetX === undefined) {
  5648. var posCatcher = $$1(event.target).offset();
  5649. posOffset = {
  5650. x: event.pageX - posCatcher.left,
  5651. y: event.pageY - posCatcher.top
  5652. };
  5653. } else {
  5654. posOffset = {
  5655. x: event.offsetX,
  5656. y: event.offsetY
  5657. };
  5658. }
  5659. var dim = {
  5660. c: Math.ceil(posOffset.x / PX_PER_EM) || 1,
  5661. r: Math.ceil(posOffset.y / PX_PER_EM) || 1
  5662. };
  5663. $highlighted.css({
  5664. width: dim.c + 'em',
  5665. height: dim.r + 'em'
  5666. });
  5667. $catcher.data('value', dim.c + 'x' + dim.r);
  5668. if (dim.c > 3 && dim.c < this.options.insertTableMaxSize.col) {
  5669. $unhighlighted.css({
  5670. width: dim.c + 1 + 'em'
  5671. });
  5672. }
  5673. if (dim.r > 3 && dim.r < this.options.insertTableMaxSize.row) {
  5674. $unhighlighted.css({
  5675. height: dim.r + 1 + 'em'
  5676. });
  5677. }
  5678. $dimensionDisplay.html(dim.c + ' x ' + dim.r);
  5679. };
  5680. return Buttons;
  5681. }());
  5682. var Toolbar = /** @class */ (function () {
  5683. function Toolbar(context) {
  5684. this.context = context;
  5685. this.$window = $$1(window);
  5686. this.$document = $$1(document);
  5687. this.ui = $$1.summernote.ui;
  5688. this.$note = context.layoutInfo.note;
  5689. this.$editor = context.layoutInfo.editor;
  5690. this.$toolbar = context.layoutInfo.toolbar;
  5691. this.options = context.options;
  5692. this.followScroll = this.followScroll.bind(this);
  5693. }
  5694. Toolbar.prototype.shouldInitialize = function () {
  5695. return !this.options.airMode;
  5696. };
  5697. Toolbar.prototype.initialize = function () {
  5698. var _this = this;
  5699. this.options.toolbar = this.options.toolbar || [];
  5700. if (!this.options.toolbar.length) {
  5701. this.$toolbar.hide();
  5702. } else {
  5703. this.context.invoke('buttons.build', this.$toolbar, this.options.toolbar);
  5704. }
  5705. if (this.options.toolbarContainer) {
  5706. this.$toolbar.appendTo(this.options.toolbarContainer);
  5707. }
  5708. this.changeContainer(false);
  5709. this.$note.on('summernote.keyup summernote.mouseup summernote.change', function () {
  5710. _this.context.invoke('buttons.updateCurrentStyle');
  5711. });
  5712. this.context.invoke('buttons.updateCurrentStyle');
  5713. if (this.options.followingToolbar) {
  5714. this.$window.on('scroll resize', this.followScroll);
  5715. }
  5716. };
  5717. Toolbar.prototype.destroy = function () {
  5718. this.$toolbar.children().remove();
  5719. if (this.options.followingToolbar) {
  5720. this.$window.off('scroll resize', this.followScroll);
  5721. }
  5722. };
  5723. Toolbar.prototype.followScroll = function () {
  5724. if (this.$editor.hasClass('fullscreen')) {
  5725. return false;
  5726. }
  5727. var $toolbarWrapper = this.$toolbar.parent('.note-toolbar-wrapper');
  5728. var editorHeight = this.$editor.outerHeight();
  5729. var editorWidth = this.$editor.width();
  5730. var toolbarHeight = this.$toolbar.height();
  5731. $toolbarWrapper.css({
  5732. height: toolbarHeight
  5733. });
  5734. // check if the web app is currently using another static bar
  5735. var otherBarHeight = 0;
  5736. if (this.options.otherStaticBar) {
  5737. otherBarHeight = $$1(this.options.otherStaticBar).outerHeight();
  5738. }
  5739. var currentOffset = this.$document.scrollTop();
  5740. var editorOffsetTop = this.$editor.offset().top;
  5741. var editorOffsetBottom = editorOffsetTop + editorHeight;
  5742. var activateOffset = editorOffsetTop - otherBarHeight;
  5743. var deactivateOffsetBottom = editorOffsetBottom - otherBarHeight - toolbarHeight;
  5744. if ((currentOffset > activateOffset) && (currentOffset < deactivateOffsetBottom)) {
  5745. this.$toolbar.css({
  5746. position: 'fixed',
  5747. top: otherBarHeight,
  5748. width: editorWidth
  5749. });
  5750. } else {
  5751. this.$toolbar.css({
  5752. position: 'relative',
  5753. top: 0,
  5754. width: '100%'
  5755. });
  5756. }
  5757. };
  5758. Toolbar.prototype.changeContainer = function (isFullscreen) {
  5759. if (isFullscreen) {
  5760. this.$toolbar.prependTo(this.$editor);
  5761. } else {
  5762. if (this.options.toolbarContainer) {
  5763. this.$toolbar.appendTo(this.options.toolbarContainer);
  5764. }
  5765. }
  5766. };
  5767. Toolbar.prototype.updateFullscreen = function (isFullscreen) {
  5768. this.ui.toggleBtnActive(this.$toolbar.find('.btn-fullscreen'), isFullscreen);
  5769. this.changeContainer(isFullscreen);
  5770. };
  5771. Toolbar.prototype.updateCodeview = function (isCodeview) {
  5772. this.ui.toggleBtnActive(this.$toolbar.find('.btn-codeview'), isCodeview);
  5773. if (isCodeview) {
  5774. this.deactivate();
  5775. } else {
  5776. this.activate();
  5777. }
  5778. };
  5779. Toolbar.prototype.activate = function (isIncludeCodeview) {
  5780. var $btn = this.$toolbar.find('button');
  5781. if (!isIncludeCodeview) {
  5782. $btn = $btn.not('.btn-codeview');
  5783. }
  5784. this.ui.toggleBtn($btn, true);
  5785. };
  5786. Toolbar.prototype.deactivate = function (isIncludeCodeview) {
  5787. var $btn = this.$toolbar.find('button');
  5788. if (!isIncludeCodeview) {
  5789. $btn = $btn.not('.btn-codeview');
  5790. }
  5791. this.ui.toggleBtn($btn, false);
  5792. };
  5793. return Toolbar;
  5794. }());
  5795. var LinkDialog = /** @class */ (function () {
  5796. function LinkDialog(context) {
  5797. this.context = context;
  5798. this.ui = $$1.summernote.ui;
  5799. this.$body = $$1(document.body);
  5800. this.$editor = context.layoutInfo.editor;
  5801. this.options = context.options;
  5802. this.lang = this.options.langInfo;
  5803. context.memo('help.linkDialog.show', this.options.langInfo.help['linkDialog.show']);
  5804. }
  5805. LinkDialog.prototype.initialize = function () {
  5806. var $container = this.options.dialogsInBody ? this.$body : this.$editor;
  5807. var body = [
  5808. '<div class="form-group note-form-group">',
  5809. "<label class=\"note-form-label\">" + this.lang.link.textToDisplay + "</label>",
  5810. '<input class="note-link-text form-control note-form-control note-input" type="text" />',
  5811. '</div>',
  5812. '<div class="form-group note-form-group">',
  5813. "<label class=\"note-form-label\">" + this.lang.link.url + "</label>",
  5814. '<input class="note-link-url form-control note-form-control note-input" type="text" value="http://" />',
  5815. '</div>',
  5816. !this.options.disableLinkTarget ?
  5817. $$1('<div/>').append(this.ui.checkbox({
  5818. id: 'sn-checkbox-open-in-new-window',
  5819. text: this.lang.link.openInNewWindow,
  5820. checked: true
  5821. }).render()).html() :
  5822. ''
  5823. ].join('');
  5824. var buttonClass = 'btn btn-primary note-btn note-btn-primary note-link-btn';
  5825. var footer = "<button type=\"submit\" href=\"#\" class=\"" + buttonClass + "\" disabled>" + this.lang.link.insert + "</button>";
  5826. this.$dialog = this.ui.dialog({
  5827. className: 'link-dialog',
  5828. title: this.lang.link.insert,
  5829. fade: this.options.dialogsFade,
  5830. body: body,
  5831. footer: footer
  5832. }).render().appendTo($container);
  5833. };
  5834. LinkDialog.prototype.destroy = function () {
  5835. this.ui.hideDialog(this.$dialog);
  5836. this.$dialog.remove();
  5837. };
  5838. LinkDialog.prototype.bindEnterKey = function ($input, $btn) {
  5839. $input.on('keypress', function (event) {
  5840. if (event.keyCode === key.code.ENTER) {
  5841. event.preventDefault();
  5842. $btn.trigger('click');
  5843. }
  5844. });
  5845. };
  5846. /**
  5847. * toggle update button
  5848. */
  5849. LinkDialog.prototype.toggleLinkBtn = function ($linkBtn, $linkText, $linkUrl) {
  5850. this.ui.toggleBtn($linkBtn, $linkText.val() && $linkUrl.val());
  5851. };
  5852. /**
  5853. * Show link dialog and set event handlers on dialog controls.
  5854. *
  5855. * @param {Object} linkInfo
  5856. * @return {Promise}
  5857. */
  5858. LinkDialog.prototype.showLinkDialog = function (linkInfo) {
  5859. var _this = this;
  5860. return $$1.Deferred(function (deferred) {
  5861. var $linkText = _this.$dialog.find('.note-link-text');
  5862. var $linkUrl = _this.$dialog.find('.note-link-url');
  5863. var $linkBtn = _this.$dialog.find('.note-link-btn');
  5864. var $openInNewWindow = _this.$dialog.find('input[type=checkbox]');
  5865. _this.ui.onDialogShown(_this.$dialog, function () {
  5866. _this.context.triggerEvent('dialog.shown');
  5867. // if no url was given, copy text to url
  5868. if (!linkInfo.url) {
  5869. linkInfo.url = linkInfo.text;
  5870. }
  5871. $linkText.val(linkInfo.text);
  5872. var handleLinkTextUpdate = function () {
  5873. _this.toggleLinkBtn($linkBtn, $linkText, $linkUrl);
  5874. // if linktext was modified by keyup,
  5875. // stop cloning text from linkUrl
  5876. linkInfo.text = $linkText.val();
  5877. };
  5878. $linkText.on('input', handleLinkTextUpdate).on('paste', function () {
  5879. setTimeout(handleLinkTextUpdate, 0);
  5880. });
  5881. var handleLinkUrlUpdate = function () {
  5882. _this.toggleLinkBtn($linkBtn, $linkText, $linkUrl);
  5883. // display same link on `Text to display` input
  5884. // when create a new link
  5885. if (!linkInfo.text) {
  5886. $linkText.val($linkUrl.val());
  5887. }
  5888. };
  5889. $linkUrl.on('input', handleLinkUrlUpdate).on('paste', function () {
  5890. setTimeout(handleLinkUrlUpdate, 0);
  5891. }).val(linkInfo.url);
  5892. if (!env.isSupportTouch) {
  5893. $linkUrl.trigger('focus');
  5894. }
  5895. _this.toggleLinkBtn($linkBtn, $linkText, $linkUrl);
  5896. _this.bindEnterKey($linkUrl, $linkBtn);
  5897. _this.bindEnterKey($linkText, $linkBtn);
  5898. var isChecked = linkInfo.isNewWindow !== undefined ?
  5899. linkInfo.isNewWindow : _this.context.options.linkTargetBlank;
  5900. $openInNewWindow.prop('checked', isChecked);
  5901. $linkBtn.one('click', function (event) {
  5902. event.preventDefault();
  5903. deferred.resolve({
  5904. range: linkInfo.range,
  5905. url: $linkUrl.val(),
  5906. text: $linkText.val(),
  5907. isNewWindow: $openInNewWindow.is(':checked')
  5908. });
  5909. _this.ui.hideDialog(_this.$dialog);
  5910. });
  5911. });
  5912. _this.ui.onDialogHidden(_this.$dialog, function () {
  5913. // detach events
  5914. $linkText.off('input paste keypress');
  5915. $linkUrl.off('input paste keypress');
  5916. $linkBtn.off('click');
  5917. if (deferred.state() === 'pending') {
  5918. deferred.reject();
  5919. }
  5920. });
  5921. _this.ui.showDialog(_this.$dialog);
  5922. }).promise();
  5923. };
  5924. /**
  5925. * @param {Object} layoutInfo
  5926. */
  5927. LinkDialog.prototype.show = function () {
  5928. var _this = this;
  5929. var linkInfo = this.context.invoke('editor.getLinkInfo');
  5930. this.context.invoke('editor.saveRange');
  5931. this.showLinkDialog(linkInfo).then(function (linkInfo) {
  5932. _this.context.invoke('editor.restoreRange');
  5933. _this.context.invoke('editor.createLink', linkInfo);
  5934. }).fail(function () {
  5935. _this.context.invoke('editor.restoreRange');
  5936. });
  5937. };
  5938. return LinkDialog;
  5939. }());
  5940. var LinkPopover = /** @class */ (function () {
  5941. function LinkPopover(context) {
  5942. var _this = this;
  5943. this.context = context;
  5944. this.ui = $$1.summernote.ui;
  5945. this.options = context.options;
  5946. this.events = {
  5947. 'summernote.keyup summernote.mouseup summernote.change summernote.scroll': function () {
  5948. _this.update();
  5949. },
  5950. 'summernote.disable summernote.dialog.shown': function () {
  5951. _this.hide();
  5952. }
  5953. };
  5954. }
  5955. LinkPopover.prototype.shouldInitialize = function () {
  5956. return !lists.isEmpty(this.options.popover.link);
  5957. };
  5958. LinkPopover.prototype.initialize = function () {
  5959. this.$popover = this.ui.popover({
  5960. className: 'note-link-popover',
  5961. callback: function ($node) {
  5962. var $content = $node.find('.popover-content,.note-popover-content');
  5963. $content.prepend('<span><a target="_blank"></a>&nbsp;</span>');
  5964. }
  5965. }).render().appendTo(this.options.container);
  5966. var $content = this.$popover.find('.popover-content,.note-popover-content');
  5967. this.context.invoke('buttons.build', $content, this.options.popover.link);
  5968. };
  5969. LinkPopover.prototype.destroy = function () {
  5970. this.$popover.remove();
  5971. };
  5972. LinkPopover.prototype.update = function () {
  5973. // Prevent focusing on editable when invoke('code') is executed
  5974. if (!this.context.invoke('editor.hasFocus')) {
  5975. this.hide();
  5976. return;
  5977. }
  5978. var rng = this.context.invoke('editor.createRange');
  5979. if (rng.isCollapsed() && rng.isOnAnchor()) {
  5980. var anchor = dom.ancestor(rng.sc, dom.isAnchor);
  5981. var href = $$1(anchor).attr('href');
  5982. this.$popover.find('a').attr('href', href).html(href);
  5983. var pos = dom.posFromPlaceholder(anchor);
  5984. this.$popover.css({
  5985. display: 'block',
  5986. left: pos.left,
  5987. top: pos.top
  5988. });
  5989. } else {
  5990. this.hide();
  5991. }
  5992. };
  5993. LinkPopover.prototype.hide = function () {
  5994. this.$popover.hide();
  5995. };
  5996. return LinkPopover;
  5997. }());
  5998. var ImageDialog = /** @class */ (function () {
  5999. function ImageDialog(context) {
  6000. this.context = context;
  6001. this.ui = $$1.summernote.ui;
  6002. this.$body = $$1(document.body);
  6003. this.$editor = context.layoutInfo.editor;
  6004. this.options = context.options;
  6005. this.lang = this.options.langInfo;
  6006. }
  6007. ImageDialog.prototype.initialize = function () {
  6008. var $container = this.options.dialogsInBody ? this.$body : this.$editor;
  6009. var imageLimitation = '';
  6010. if (this.options.maximumImageFileSize) {
  6011. var unit = Math.floor(Math.log(this.options.maximumImageFileSize) / Math.log(1024));
  6012. var readableSize = (this.options.maximumImageFileSize / Math.pow(1024, unit)).toFixed(2) * 1 +
  6013. ' ' + ' KMGTP' [unit] + 'B';
  6014. imageLimitation = "<small>" + (this.lang.image.maximumFileSize + ' : ' + readableSize) + "</small>";
  6015. }
  6016. var body = [
  6017. '<div class="form-group note-form-group note-group-select-from-files">',
  6018. '<label class="note-form-label">' + this.lang.image.selectFromFiles + '</label>',
  6019. '<input class="note-image-input note-form-control note-input" ',
  6020. ' type="file" name="files" accept="image/*" multiple="multiple" />',
  6021. imageLimitation,
  6022. '</div>',
  6023. '<div class="form-group note-group-image-url" style="overflow:auto;">',
  6024. '<label class="note-form-label">' + this.lang.image.url + '</label>',
  6025. '<input class="note-image-url form-control note-form-control note-input ',
  6026. ' col-md-12" type="text" />',
  6027. '</div>'
  6028. ].join('');
  6029. var buttonClass = 'btn btn-primary note-btn note-btn-primary note-image-btn';
  6030. var footer = "<button type=\"submit\" href=\"#\" class=\"" + buttonClass + "\" disabled>" + this.lang.image.insert + "</button>";
  6031. this.$dialog = this.ui.dialog({
  6032. title: this.lang.image.insert,
  6033. fade: this.options.dialogsFade,
  6034. body: body,
  6035. footer: footer
  6036. }).render().appendTo($container);
  6037. };
  6038. ImageDialog.prototype.destroy = function () {
  6039. this.ui.hideDialog(this.$dialog);
  6040. this.$dialog.remove();
  6041. };
  6042. ImageDialog.prototype.bindEnterKey = function ($input, $btn) {
  6043. $input.on('keypress', function (event) {
  6044. if (event.keyCode === key.code.ENTER) {
  6045. event.preventDefault();
  6046. $btn.trigger('click');
  6047. }
  6048. });
  6049. };
  6050. ImageDialog.prototype.show = function () {
  6051. var _this = this;
  6052. this.context.invoke('editor.saveRange');
  6053. this.showImageDialog().then(function (data) {
  6054. // [workaround] hide dialog before restore range for IE range focus
  6055. _this.ui.hideDialog(_this.$dialog);
  6056. _this.context.invoke('editor.restoreRange');
  6057. if (typeof data === 'string') {
  6058. _this.context.invoke('editor.insertImage', data);
  6059. } else {
  6060. _this.context.invoke('editor.insertImagesOrCallback', data);
  6061. }
  6062. }).fail(function () {
  6063. _this.context.invoke('editor.restoreRange');
  6064. });
  6065. };
  6066. /**
  6067. * show image dialog
  6068. *
  6069. * @param {jQuery} $dialog
  6070. * @return {Promise}
  6071. */
  6072. ImageDialog.prototype.showImageDialog = function () {
  6073. var _this = this;
  6074. return $$1.Deferred(function (deferred) {
  6075. var $imageInput = _this.$dialog.find('.note-image-input');
  6076. var $imageUrl = _this.$dialog.find('.note-image-url');
  6077. var $imageBtn = _this.$dialog.find('.note-image-btn');
  6078. _this.ui.onDialogShown(_this.$dialog, function () {
  6079. _this.context.triggerEvent('dialog.shown');
  6080. // Cloning imageInput to clear element.
  6081. $imageInput.replaceWith($imageInput.clone().on('change', function (event) {
  6082. deferred.resolve(event.target.files || event.target.value);
  6083. }).val(''));
  6084. $imageBtn.click(function (event) {
  6085. event.preventDefault();
  6086. deferred.resolve($imageUrl.val());
  6087. });
  6088. $imageUrl.on('keyup paste', function () {
  6089. var url = $imageUrl.val();
  6090. _this.ui.toggleBtn($imageBtn, url);
  6091. }).val('');
  6092. if (!env.isSupportTouch) {
  6093. $imageUrl.trigger('focus');
  6094. }
  6095. _this.bindEnterKey($imageUrl, $imageBtn);
  6096. });
  6097. _this.ui.onDialogHidden(_this.$dialog, function () {
  6098. $imageInput.off('change');
  6099. $imageUrl.off('keyup paste keypress');
  6100. $imageBtn.off('click');
  6101. if (deferred.state() === 'pending') {
  6102. deferred.reject();
  6103. }
  6104. });
  6105. _this.ui.showDialog(_this.$dialog);
  6106. });
  6107. };
  6108. return ImageDialog;
  6109. }());
  6110. /**
  6111. * Image popover module
  6112. * mouse events that show/hide popover will be handled by Handle.js.
  6113. * Handle.js will receive the events and invoke 'imagePopover.update'.
  6114. */
  6115. var ImagePopover = /** @class */ (function () {
  6116. function ImagePopover(context) {
  6117. var _this = this;
  6118. this.context = context;
  6119. this.ui = $$1.summernote.ui;
  6120. this.editable = context.layoutInfo.editable[0];
  6121. this.options = context.options;
  6122. this.events = {
  6123. 'summernote.disable': function () {
  6124. _this.hide();
  6125. }
  6126. };
  6127. }
  6128. ImagePopover.prototype.shouldInitialize = function () {
  6129. return !lists.isEmpty(this.options.popover.image);
  6130. };
  6131. ImagePopover.prototype.initialize = function () {
  6132. this.$popover = this.ui.popover({
  6133. className: 'note-image-popover'
  6134. }).render().appendTo(this.options.container);
  6135. var $content = this.$popover.find('.popover-content,.note-popover-content');
  6136. this.context.invoke('buttons.build', $content, this.options.popover.image);
  6137. };
  6138. ImagePopover.prototype.destroy = function () {
  6139. this.$popover.remove();
  6140. };
  6141. ImagePopover.prototype.update = function (target) {
  6142. if (dom.isImg(target)) {
  6143. var pos = dom.posFromPlaceholder(target);
  6144. var posEditor = dom.posFromPlaceholder(this.editable);
  6145. this.$popover.css({
  6146. display: 'block',
  6147. left: this.options.popatmouse ? event.pageX - 20 : pos.left,
  6148. top: this.options.popatmouse ? event.pageY : Math.min(pos.top, posEditor.top)
  6149. });
  6150. } else {
  6151. this.hide();
  6152. }
  6153. };
  6154. ImagePopover.prototype.hide = function () {
  6155. this.$popover.hide();
  6156. };
  6157. return ImagePopover;
  6158. }());
  6159. var TablePopover = /** @class */ (function () {
  6160. function TablePopover(context) {
  6161. var _this = this;
  6162. this.context = context;
  6163. this.ui = $$1.summernote.ui;
  6164. this.options = context.options;
  6165. this.events = {
  6166. 'summernote.mousedown': function (we, e) {
  6167. _this.update(e.target);
  6168. },
  6169. 'summernote.keyup summernote.scroll summernote.change': function () {
  6170. _this.update();
  6171. },
  6172. 'summernote.disable': function () {
  6173. _this.hide();
  6174. }
  6175. };
  6176. }
  6177. TablePopover.prototype.shouldInitialize = function () {
  6178. return !lists.isEmpty(this.options.popover.table);
  6179. };
  6180. TablePopover.prototype.initialize = function () {
  6181. this.$popover = this.ui.popover({
  6182. className: 'note-table-popover'
  6183. }).render().appendTo(this.options.container);
  6184. var $content = this.$popover.find('.popover-content,.note-popover-content');
  6185. this.context.invoke('buttons.build', $content, this.options.popover.table);
  6186. // [workaround] Disable Firefox's default table editor
  6187. if (env.isFF) {
  6188. document.execCommand('enableInlineTableEditing', false, false);
  6189. }
  6190. };
  6191. TablePopover.prototype.destroy = function () {
  6192. this.$popover.remove();
  6193. };
  6194. TablePopover.prototype.update = function (target) {
  6195. if (this.context.isDisabled()) {
  6196. return false;
  6197. }
  6198. var isCell = dom.isCell(target);
  6199. if (isCell) {
  6200. var pos = dom.posFromPlaceholder(target);
  6201. this.$popover.css({
  6202. display: 'block',
  6203. left: pos.left,
  6204. top: pos.top
  6205. });
  6206. } else {
  6207. this.hide();
  6208. }
  6209. return isCell;
  6210. };
  6211. TablePopover.prototype.hide = function () {
  6212. this.$popover.hide();
  6213. };
  6214. return TablePopover;
  6215. }());
  6216. var VideoDialog = /** @class */ (function () {
  6217. function VideoDialog(context) {
  6218. this.context = context;
  6219. this.ui = $$1.summernote.ui;
  6220. this.$body = $$1(document.body);
  6221. this.$editor = context.layoutInfo.editor;
  6222. this.options = context.options;
  6223. this.lang = this.options.langInfo;
  6224. }
  6225. VideoDialog.prototype.initialize = function () {
  6226. var $container = this.options.dialogsInBody ? this.$body : this.$editor;
  6227. var body = [
  6228. '<div class="form-group note-form-group row-fluid">',
  6229. "<label class=\"note-form-label\">" + this.lang.video.url + " <small class=\"text-muted\">" + this.lang.video.providers + "</small></label>",
  6230. '<input class="note-video-url form-control note-form-control note-input" type="text" />',
  6231. '</div>'
  6232. ].join('');
  6233. var buttonClass = 'btn btn-primary note-btn note-btn-primary note-video-btn';
  6234. var footer = "<button type=\"submit\" href=\"#\" class=\"" + buttonClass + "\" disabled>" + this.lang.video.insert + "</button>";
  6235. this.$dialog = this.ui.dialog({
  6236. title: this.lang.video.insert,
  6237. fade: this.options.dialogsFade,
  6238. body: body,
  6239. footer: footer
  6240. }).render().appendTo($container);
  6241. };
  6242. VideoDialog.prototype.destroy = function () {
  6243. this.ui.hideDialog(this.$dialog);
  6244. this.$dialog.remove();
  6245. };
  6246. VideoDialog.prototype.bindEnterKey = function ($input, $btn) {
  6247. $input.on('keypress', function (event) {
  6248. if (event.keyCode === key.code.ENTER) {
  6249. event.preventDefault();
  6250. $btn.trigger('click');
  6251. }
  6252. });
  6253. };
  6254. VideoDialog.prototype.createVideoNode = function (url) {
  6255. // video url patterns(youtube, instagram, vimeo, dailymotion, youku, mp4, ogg, webm)
  6256. var ytRegExp = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
  6257. var ytMatch = url.match(ytRegExp);
  6258. var igRegExp = /(?:www\.|\/\/)instagram\.com\/p\/(.[a-zA-Z0-9_-]*)/;
  6259. var igMatch = url.match(igRegExp);
  6260. var vRegExp = /\/\/vine\.co\/v\/([a-zA-Z0-9]+)/;
  6261. var vMatch = url.match(vRegExp);
  6262. var vimRegExp = /\/\/(player\.)?vimeo\.com\/([a-z]*\/)*(\d+)[?]?.*/;
  6263. var vimMatch = url.match(vimRegExp);
  6264. var dmRegExp = /.+dailymotion.com\/(video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/;
  6265. var dmMatch = url.match(dmRegExp);
  6266. var youkuRegExp = /\/\/v\.youku\.com\/v_show\/id_(\w+)=*\.html/;
  6267. var youkuMatch = url.match(youkuRegExp);
  6268. var qqRegExp = /\/\/v\.qq\.com.*?vid=(.+)/;
  6269. var qqMatch = url.match(qqRegExp);
  6270. var qqRegExp2 = /\/\/v\.qq\.com\/x?\/?(page|cover).*?\/([^\/]+)\.html\??.*/;
  6271. var qqMatch2 = url.match(qqRegExp2);
  6272. var mp4RegExp = /^.+.(mp4|m4v)$/;
  6273. var mp4Match = url.match(mp4RegExp);
  6274. var oggRegExp = /^.+.(ogg|ogv)$/;
  6275. var oggMatch = url.match(oggRegExp);
  6276. var webmRegExp = /^.+.(webm)$/;
  6277. var webmMatch = url.match(webmRegExp);
  6278. var $video;
  6279. if (ytMatch && ytMatch[1].length === 11) {
  6280. var youtubeId = ytMatch[1];
  6281. $video = $$1('<iframe>')
  6282. .attr('frameborder', 0)
  6283. .attr('src', '//www.youtube.com/embed/' + youtubeId)
  6284. .attr('width', '640').attr('height', '360');
  6285. } else if (igMatch && igMatch[0].length) {
  6286. $video = $$1('<iframe>')
  6287. .attr('frameborder', 0)
  6288. .attr('src', 'https://instagram.com/p/' + igMatch[1] + '/embed/')
  6289. .attr('width', '612').attr('height', '710')
  6290. .attr('scrolling', 'no')
  6291. .attr('allowtransparency', 'true');
  6292. } else if (vMatch && vMatch[0].length) {
  6293. $video = $$1('<iframe>')
  6294. .attr('frameborder', 0)
  6295. .attr('src', vMatch[0] + '/embed/simple')
  6296. .attr('width', '600').attr('height', '600')
  6297. .attr('class', 'vine-embed');
  6298. } else if (vimMatch && vimMatch[3].length) {
  6299. $video = $$1('<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen>')
  6300. .attr('frameborder', 0)
  6301. .attr('src', '//player.vimeo.com/video/' + vimMatch[3])
  6302. .attr('width', '640').attr('height', '360');
  6303. } else if (dmMatch && dmMatch[2].length) {
  6304. $video = $$1('<iframe>')
  6305. .attr('frameborder', 0)
  6306. .attr('src', '//www.dailymotion.com/embed/video/' + dmMatch[2])
  6307. .attr('width', '640').attr('height', '360');
  6308. } else if (youkuMatch && youkuMatch[1].length) {
  6309. $video = $$1('<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen>')
  6310. .attr('frameborder', 0)
  6311. .attr('height', '498')
  6312. .attr('width', '510')
  6313. .attr('src', '//player.youku.com/embed/' + youkuMatch[1]);
  6314. } else if ((qqMatch && qqMatch[1].length) || (qqMatch2 && qqMatch2[2].length)) {
  6315. var vid = ((qqMatch && qqMatch[1].length) ? qqMatch[1] : qqMatch2[2]);
  6316. $video = $$1('<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen>')
  6317. .attr('frameborder', 0)
  6318. .attr('height', '310')
  6319. .attr('width', '500')
  6320. .attr('src', 'http://v.qq.com/iframe/player.html?vid=' + vid + '&amp;auto=0');
  6321. } else if (mp4Match || oggMatch || webmMatch) {
  6322. $video = $$1('<video controls>')
  6323. .attr('src', url)
  6324. .attr('width', '640').attr('height', '360');
  6325. } else {
  6326. // this is not a known video link. Now what, Cat? Now what?
  6327. return false;
  6328. }
  6329. $video.addClass('note-video-clip');
  6330. return $video[0];
  6331. };
  6332. VideoDialog.prototype.show = function () {
  6333. var _this = this;
  6334. var text = this.context.invoke('editor.getSelectedText');
  6335. this.context.invoke('editor.saveRange');
  6336. this.showVideoDialog(text).then(function (url) {
  6337. // [workaround] hide dialog before restore range for IE range focus
  6338. _this.ui.hideDialog(_this.$dialog);
  6339. _this.context.invoke('editor.restoreRange');
  6340. // build node
  6341. var $node = _this.createVideoNode(url);
  6342. if ($node) {
  6343. // insert video node
  6344. _this.context.invoke('editor.insertNode', $node);
  6345. }
  6346. }).fail(function () {
  6347. _this.context.invoke('editor.restoreRange');
  6348. });
  6349. };
  6350. /**
  6351. * show image dialog
  6352. *
  6353. * @param {jQuery} $dialog
  6354. * @return {Promise}
  6355. */
  6356. VideoDialog.prototype.showVideoDialog = function (text) {
  6357. var _this = this;
  6358. return $$1.Deferred(function (deferred) {
  6359. var $videoUrl = _this.$dialog.find('.note-video-url');
  6360. var $videoBtn = _this.$dialog.find('.note-video-btn');
  6361. _this.ui.onDialogShown(_this.$dialog, function () {
  6362. _this.context.triggerEvent('dialog.shown');
  6363. $videoUrl.val(text).on('input', function () {
  6364. _this.ui.toggleBtn($videoBtn, $videoUrl.val());
  6365. });
  6366. if (!env.isSupportTouch) {
  6367. $videoUrl.trigger('focus');
  6368. }
  6369. $videoBtn.click(function (event) {
  6370. event.preventDefault();
  6371. deferred.resolve($videoUrl.val());
  6372. });
  6373. _this.bindEnterKey($videoUrl, $videoBtn);
  6374. });
  6375. _this.ui.onDialogHidden(_this.$dialog, function () {
  6376. $videoUrl.off('input');
  6377. $videoBtn.off('click');
  6378. if (deferred.state() === 'pending') {
  6379. deferred.reject();
  6380. }
  6381. });
  6382. _this.ui.showDialog(_this.$dialog);
  6383. });
  6384. };
  6385. return VideoDialog;
  6386. }());
  6387. var HelpDialog = /** @class */ (function () {
  6388. function HelpDialog(context) {
  6389. this.context = context;
  6390. this.ui = $$1.summernote.ui;
  6391. this.$body = $$1(document.body);
  6392. this.$editor = context.layoutInfo.editor;
  6393. this.options = context.options;
  6394. this.lang = this.options.langInfo;
  6395. }
  6396. HelpDialog.prototype.initialize = function () {
  6397. var $container = this.options.dialogsInBody ? this.$body : this.$editor;
  6398. var body = [
  6399. '<p class="text-center">',
  6400. '<a href="http://summernote.org/" target="_blank">Summernote 0.8.9</a> · ',
  6401. '<a href="https://github.com/summernote/summernote" target="_blank">Project</a> · ',
  6402. '<a href="https://github.com/summernote/summernote/issues" target="_blank">Issues</a>',
  6403. '</p>'
  6404. ].join('');
  6405. this.$dialog = this.ui.dialog({
  6406. title: this.lang.options.help,
  6407. fade: this.options.dialogsFade,
  6408. body: this.createShortcutList(),
  6409. footer: body,
  6410. callback: function ($node) {
  6411. $node.find('.modal-body,.note-modal-body').css({
  6412. 'max-height': 300,
  6413. 'overflow': 'scroll'
  6414. });
  6415. }
  6416. }).render().appendTo($container);
  6417. };
  6418. HelpDialog.prototype.destroy = function () {
  6419. this.ui.hideDialog(this.$dialog);
  6420. this.$dialog.remove();
  6421. };
  6422. HelpDialog.prototype.createShortcutList = function () {
  6423. var _this = this;
  6424. var keyMap = this.options.keyMap[env.isMac ? 'mac' : 'pc'];
  6425. return Object.keys(keyMap).map(function (key) {
  6426. var command = keyMap[key];
  6427. var $row = $$1('<div><div class="help-list-item"/></div>');
  6428. $row.append($$1('<label><kbd>' + key + '</kdb></label>').css({
  6429. 'width': 180,
  6430. 'margin-right': 10
  6431. })).append($$1('<span/>').html(_this.context.memo('help.' + command) || command));
  6432. return $row.html();
  6433. }).join('');
  6434. };
  6435. /**
  6436. * show help dialog
  6437. *
  6438. * @return {Promise}
  6439. */
  6440. HelpDialog.prototype.showHelpDialog = function () {
  6441. var _this = this;
  6442. return $$1.Deferred(function (deferred) {
  6443. _this.ui.onDialogShown(_this.$dialog, function () {
  6444. _this.context.triggerEvent('dialog.shown');
  6445. deferred.resolve();
  6446. });
  6447. _this.ui.showDialog(_this.$dialog);
  6448. }).promise();
  6449. };
  6450. HelpDialog.prototype.show = function () {
  6451. var _this = this;
  6452. this.context.invoke('editor.saveRange');
  6453. this.showHelpDialog().then(function () {
  6454. _this.context.invoke('editor.restoreRange');
  6455. });
  6456. };
  6457. return HelpDialog;
  6458. }());
  6459. var AIR_MODE_POPOVER_X_OFFSET = 20;
  6460. var AirPopover = /** @class */ (function () {
  6461. function AirPopover(context) {
  6462. var _this = this;
  6463. this.context = context;
  6464. this.ui = $$1.summernote.ui;
  6465. this.options = context.options;
  6466. this.events = {
  6467. 'summernote.keyup summernote.mouseup summernote.scroll': function () {
  6468. _this.update();
  6469. },
  6470. 'summernote.disable summernote.change summernote.dialog.shown': function () {
  6471. _this.hide();
  6472. },
  6473. 'summernote.focusout': function (we, e) {
  6474. // [workaround] Firefox doesn't support relatedTarget on focusout
  6475. // - Ignore hide action on focus out in FF.
  6476. if (env.isFF) {
  6477. return;
  6478. }
  6479. if (!e.relatedTarget || !dom.ancestor(e.relatedTarget, func.eq(_this.$popover[0]))) {
  6480. _this.hide();
  6481. }
  6482. }
  6483. };
  6484. }
  6485. AirPopover.prototype.shouldInitialize = function () {
  6486. return this.options.airMode && !lists.isEmpty(this.options.popover.air);
  6487. };
  6488. AirPopover.prototype.initialize = function () {
  6489. this.$popover = this.ui.popover({
  6490. className: 'note-air-popover'
  6491. }).render().appendTo(this.options.container);
  6492. var $content = this.$popover.find('.popover-content');
  6493. this.context.invoke('buttons.build', $content, this.options.popover.air);
  6494. };
  6495. AirPopover.prototype.destroy = function () {
  6496. this.$popover.remove();
  6497. };
  6498. AirPopover.prototype.update = function () {
  6499. var styleInfo = this.context.invoke('editor.currentStyle');
  6500. if (styleInfo.range && !styleInfo.range.isCollapsed()) {
  6501. var rect = lists.last(styleInfo.range.getClientRects());
  6502. if (rect) {
  6503. var bnd = func.rect2bnd(rect);
  6504. this.$popover.css({
  6505. display: 'block',
  6506. left: Math.max(bnd.left + bnd.width / 2, 0) - AIR_MODE_POPOVER_X_OFFSET,
  6507. top: bnd.top + bnd.height
  6508. });
  6509. this.context.invoke('buttons.updateCurrentStyle', this.$popover);
  6510. }
  6511. } else {
  6512. this.hide();
  6513. }
  6514. };
  6515. AirPopover.prototype.hide = function () {
  6516. this.$popover.hide();
  6517. };
  6518. return AirPopover;
  6519. }());
  6520. var POPOVER_DIST = 5;
  6521. var HintPopover = /** @class */ (function () {
  6522. function HintPopover(context) {
  6523. var _this = this;
  6524. this.context = context;
  6525. this.ui = $$1.summernote.ui;
  6526. this.$editable = context.layoutInfo.editable;
  6527. this.options = context.options;
  6528. this.hint = this.options.hint || [];
  6529. this.direction = this.options.hintDirection || 'bottom';
  6530. this.hints = $$1.isArray(this.hint) ? this.hint : [this.hint];
  6531. this.events = {
  6532. 'summernote.keyup': function (we, e) {
  6533. if (!e.isDefaultPrevented()) {
  6534. _this.handleKeyup(e);
  6535. }
  6536. },
  6537. 'summernote.keydown': function (we, e) {
  6538. _this.handleKeydown(e);
  6539. },
  6540. 'summernote.disable summernote.dialog.shown': function () {
  6541. _this.hide();
  6542. }
  6543. };
  6544. }
  6545. HintPopover.prototype.shouldInitialize = function () {
  6546. return this.hints.length > 0;
  6547. };
  6548. HintPopover.prototype.initialize = function () {
  6549. var _this = this;
  6550. this.lastWordRange = null;
  6551. this.$popover = this.ui.popover({
  6552. className: 'note-hint-popover',
  6553. hideArrow: true,
  6554. direction: ''
  6555. }).render().appendTo(this.options.container);
  6556. this.$popover.hide();
  6557. this.$content = this.$popover.find('.popover-content,.note-popover-content');
  6558. this.$content.on('click', '.note-hint-item', function () {
  6559. _this.$content.find('.active').removeClass('active');
  6560. $$1(_this).addClass('active');
  6561. _this.replace();
  6562. });
  6563. };
  6564. HintPopover.prototype.destroy = function () {
  6565. this.$popover.remove();
  6566. };
  6567. HintPopover.prototype.selectItem = function ($item) {
  6568. this.$content.find('.active').removeClass('active');
  6569. $item.addClass('active');
  6570. this.$content[0].scrollTop = $item[0].offsetTop - (this.$content.innerHeight() / 2);
  6571. };
  6572. HintPopover.prototype.moveDown = function () {
  6573. var $current = this.$content.find('.note-hint-item.active');
  6574. var $next = $current.next();
  6575. if ($next.length) {
  6576. this.selectItem($next);
  6577. } else {
  6578. var $nextGroup = $current.parent().next();
  6579. if (!$nextGroup.length) {
  6580. $nextGroup = this.$content.find('.note-hint-group').first();
  6581. }
  6582. this.selectItem($nextGroup.find('.note-hint-item').first());
  6583. }
  6584. };
  6585. HintPopover.prototype.moveUp = function () {
  6586. var $current = this.$content.find('.note-hint-item.active');
  6587. var $prev = $current.prev();
  6588. if ($prev.length) {
  6589. this.selectItem($prev);
  6590. } else {
  6591. var $prevGroup = $current.parent().prev();
  6592. if (!$prevGroup.length) {
  6593. $prevGroup = this.$content.find('.note-hint-group').last();
  6594. }
  6595. this.selectItem($prevGroup.find('.note-hint-item').last());
  6596. }
  6597. };
  6598. HintPopover.prototype.replace = function () {
  6599. var $item = this.$content.find('.note-hint-item.active');
  6600. if ($item.length) {
  6601. var node = this.nodeFromItem($item);
  6602. // XXX: consider to move codes to editor for recording redo/undo.
  6603. this.lastWordRange.insertNode(node);
  6604. range.createFromNode(node).collapse().select();
  6605. this.lastWordRange = null;
  6606. this.hide();
  6607. this.context.triggerEvent('change', this.$editable.html(), this.$editable[0]);
  6608. this.context.invoke('editor.focus');
  6609. }
  6610. };
  6611. HintPopover.prototype.nodeFromItem = function ($item) {
  6612. var hint = this.hints[$item.data('index')];
  6613. var item = $item.data('item');
  6614. var node = hint.content ? hint.content(item) : item;
  6615. if (typeof node === 'string') {
  6616. node = dom.createText(node);
  6617. }
  6618. return node;
  6619. };
  6620. HintPopover.prototype.createItemTemplates = function (hintIdx, items) {
  6621. var hint = this.hints[hintIdx];
  6622. return items.map(function (item, idx) {
  6623. var $item = $$1('<div class="note-hint-item"/>');
  6624. $item.append(hint.template ? hint.template(item) : item + '');
  6625. $item.data({
  6626. 'index': hintIdx,
  6627. 'item': item
  6628. });
  6629. return $item;
  6630. });
  6631. };
  6632. HintPopover.prototype.handleKeydown = function (e) {
  6633. if (!this.$popover.is(':visible')) {
  6634. return;
  6635. }
  6636. if (e.keyCode === key.code.ENTER) {
  6637. e.preventDefault();
  6638. this.replace();
  6639. } else if (e.keyCode === key.code.UP) {
  6640. e.preventDefault();
  6641. this.moveUp();
  6642. } else if (e.keyCode === key.code.DOWN) {
  6643. e.preventDefault();
  6644. this.moveDown();
  6645. }
  6646. };
  6647. HintPopover.prototype.searchKeyword = function (index, keyword, callback) {
  6648. var hint = this.hints[index];
  6649. if (hint && hint.match.test(keyword) && hint.search) {
  6650. var matches = hint.match.exec(keyword);
  6651. hint.search(matches[1], callback);
  6652. } else {
  6653. callback();
  6654. }
  6655. };
  6656. HintPopover.prototype.createGroup = function (idx, keyword) {
  6657. var _this = this;
  6658. var $group = $$1('<div class="note-hint-group note-hint-group-' + idx + '"/>');
  6659. this.searchKeyword(idx, keyword, function (items) {
  6660. items = items || [];
  6661. if (items.length) {
  6662. $group.html(_this.createItemTemplates(idx, items));
  6663. _this.show();
  6664. }
  6665. });
  6666. return $group;
  6667. };
  6668. HintPopover.prototype.handleKeyup = function (e) {
  6669. var _this = this;
  6670. if (!lists.contains([key.code.ENTER, key.code.UP, key.code.DOWN], e.keyCode)) {
  6671. var wordRange = this.context.invoke('editor.createRange').getWordRange();
  6672. var keyword_1 = wordRange.toString();
  6673. if (this.hints.length && keyword_1) {
  6674. this.$content.empty();
  6675. var bnd = func.rect2bnd(lists.last(wordRange.getClientRects()));
  6676. if (bnd) {
  6677. this.$popover.hide();
  6678. this.lastWordRange = wordRange;
  6679. this.hints.forEach(function (hint, idx) {
  6680. if (hint.match.test(keyword_1)) {
  6681. _this.createGroup(idx, keyword_1).appendTo(_this.$content);
  6682. }
  6683. });
  6684. // select first .note-hint-item
  6685. this.$content.find('.note-hint-item:first').addClass('active');
  6686. // set position for popover after group is created
  6687. if (this.direction === 'top') {
  6688. this.$popover.css({
  6689. left: bnd.left,
  6690. top: bnd.top - this.$popover.outerHeight() - POPOVER_DIST
  6691. });
  6692. } else {
  6693. this.$popover.css({
  6694. left: bnd.left,
  6695. top: bnd.top + bnd.height + POPOVER_DIST
  6696. });
  6697. }
  6698. }
  6699. } else {
  6700. this.hide();
  6701. }
  6702. }
  6703. };
  6704. HintPopover.prototype.show = function () {
  6705. this.$popover.show();
  6706. };
  6707. HintPopover.prototype.hide = function () {
  6708. this.$popover.hide();
  6709. };
  6710. return HintPopover;
  6711. }());
  6712. var Context = /** @class */ (function () {
  6713. /**
  6714. * @param {jQuery} $note
  6715. * @param {Object} options
  6716. */
  6717. function Context($note, options) {
  6718. this.ui = $$1.summernote.ui;
  6719. this.$note = $note;
  6720. this.memos = {};
  6721. this.modules = {};
  6722. this.layoutInfo = {};
  6723. this.options = options;
  6724. this.initialize();
  6725. }
  6726. /**
  6727. * create layout and initialize modules and other resources
  6728. */
  6729. Context.prototype.initialize = function () {
  6730. this.layoutInfo = this.ui.createLayout(this.$note, this.options);
  6731. this._initialize();
  6732. this.$note.hide();
  6733. return this;
  6734. };
  6735. /**
  6736. * destroy modules and other resources and remove layout
  6737. */
  6738. Context.prototype.destroy = function () {
  6739. this._destroy();
  6740. this.$note.removeData('summernote');
  6741. this.ui.removeLayout(this.$note, this.layoutInfo);
  6742. };
  6743. /**
  6744. * destory modules and other resources and initialize it again
  6745. */
  6746. Context.prototype.reset = function () {
  6747. var disabled = this.isDisabled();
  6748. this.code(dom.emptyPara);
  6749. this._destroy();
  6750. this._initialize();
  6751. if (disabled) {
  6752. this.disable();
  6753. }
  6754. };
  6755. Context.prototype._initialize = function () {
  6756. var _this = this;
  6757. // add optional buttons
  6758. var buttons = $$1.extend({}, this.options.buttons);
  6759. Object.keys(buttons).forEach(function (key) {
  6760. _this.memo('button.' + key, buttons[key]);
  6761. });
  6762. var modules = $$1.extend({}, this.options.modules, $$1.summernote.plugins || {});
  6763. // add and initialize modules
  6764. Object.keys(modules).forEach(function (key) {
  6765. _this.module(key, modules[key], true);
  6766. });
  6767. Object.keys(this.modules).forEach(function (key) {
  6768. _this.initializeModule(key);
  6769. });
  6770. };
  6771. Context.prototype._destroy = function () {
  6772. var _this = this;
  6773. // destroy modules with reversed order
  6774. Object.keys(this.modules).reverse().forEach(function (key) {
  6775. _this.removeModule(key);
  6776. });
  6777. Object.keys(this.memos).forEach(function (key) {
  6778. _this.removeMemo(key);
  6779. });
  6780. // trigger custom onDestroy callback
  6781. this.triggerEvent('destroy', this);
  6782. };
  6783. Context.prototype.code = function (html) {
  6784. var isActivated = this.invoke('codeview.isActivated');
  6785. if (html === undefined) {
  6786. this.invoke('codeview.sync');
  6787. return isActivated ? this.layoutInfo.codable.val() : this.layoutInfo.editable.html();
  6788. } else {
  6789. if (isActivated) {
  6790. this.layoutInfo.codable.val(html);
  6791. } else {
  6792. this.layoutInfo.editable.html(html);
  6793. }
  6794. this.$note.val(html);
  6795. this.triggerEvent('change', html);
  6796. }
  6797. };
  6798. Context.prototype.isDisabled = function () {
  6799. return this.layoutInfo.editable.attr('contenteditable') === 'false';
  6800. };
  6801. Context.prototype.enable = function () {
  6802. this.layoutInfo.editable.attr('contenteditable', true);
  6803. this.invoke('toolbar.activate', true);
  6804. this.triggerEvent('disable', false);
  6805. };
  6806. Context.prototype.disable = function () {
  6807. // close codeview if codeview is opend
  6808. if (this.invoke('codeview.isActivated')) {
  6809. this.invoke('codeview.deactivate');
  6810. }
  6811. this.layoutInfo.editable.attr('contenteditable', false);
  6812. this.invoke('toolbar.deactivate', true);
  6813. this.triggerEvent('disable', true);
  6814. };
  6815. Context.prototype.triggerEvent = function () {
  6816. var namespace = lists.head(arguments);
  6817. var args = lists.tail(lists.from(arguments));
  6818. var callback = this.options.callbacks[func.namespaceToCamel(namespace, 'on')];
  6819. if (callback) {
  6820. callback.apply(this.$note[0], args);
  6821. }
  6822. this.$note.trigger('summernote.' + namespace, args);
  6823. };
  6824. Context.prototype.initializeModule = function (key) {
  6825. var module = this.modules[key];
  6826. module.shouldInitialize = module.shouldInitialize || func.ok;
  6827. if (!module.shouldInitialize()) {
  6828. return;
  6829. }
  6830. // initialize module
  6831. if (module.initialize) {
  6832. module.initialize();
  6833. }
  6834. // attach events
  6835. if (module.events) {
  6836. dom.attachEvents(this.$note, module.events);
  6837. }
  6838. };
  6839. Context.prototype.module = function (key, ModuleClass, withoutIntialize) {
  6840. if (arguments.length === 1) {
  6841. return this.modules[key];
  6842. }
  6843. this.modules[key] = new ModuleClass(this);
  6844. if (!withoutIntialize) {
  6845. this.initializeModule(key);
  6846. }
  6847. };
  6848. Context.prototype.removeModule = function (key) {
  6849. var module = this.modules[key];
  6850. if (module.shouldInitialize()) {
  6851. if (module.events) {
  6852. dom.detachEvents(this.$note, module.events);
  6853. }
  6854. if (module.destroy) {
  6855. module.destroy();
  6856. }
  6857. }
  6858. delete this.modules[key];
  6859. };
  6860. Context.prototype.memo = function (key, obj) {
  6861. if (arguments.length === 1) {
  6862. return this.memos[key];
  6863. }
  6864. this.memos[key] = obj;
  6865. };
  6866. Context.prototype.removeMemo = function (key) {
  6867. if (this.memos[key] && this.memos[key].destroy) {
  6868. this.memos[key].destroy();
  6869. }
  6870. delete this.memos[key];
  6871. };
  6872. /**
  6873. * Some buttons need to change their visual style immediately once they get pressed
  6874. */
  6875. Context.prototype.createInvokeHandlerAndUpdateState = function (namespace, value) {
  6876. var _this = this;
  6877. return function (event) {
  6878. _this.createInvokeHandler(namespace, value)(event);
  6879. _this.invoke('buttons.updateCurrentStyle');
  6880. };
  6881. };
  6882. Context.prototype.createInvokeHandler = function (namespace, value) {
  6883. var _this = this;
  6884. return function (event) {
  6885. event.preventDefault();
  6886. var $target = $$1(event.target);
  6887. _this.invoke(namespace, value || $target.closest('[data-value]').data('value'), $target);
  6888. };
  6889. };
  6890. Context.prototype.invoke = function () {
  6891. var namespace = lists.head(arguments);
  6892. var args = lists.tail(lists.from(arguments));
  6893. var splits = namespace.split('.');
  6894. var hasSeparator = splits.length > 1;
  6895. var moduleName = hasSeparator && lists.head(splits);
  6896. var methodName = hasSeparator ? lists.last(splits) : lists.head(splits);
  6897. var module = this.modules[moduleName || 'editor'];
  6898. if (!moduleName && this[methodName]) {
  6899. return this[methodName].apply(this, args);
  6900. } else if (module && module[methodName] && module.shouldInitialize()) {
  6901. return module[methodName].apply(module, args);
  6902. }
  6903. };
  6904. return Context;
  6905. }());
  6906. $$1.fn.extend({
  6907. /**
  6908. * Summernote API
  6909. *
  6910. * @param {Object|String}
  6911. * @return {this}
  6912. */
  6913. summernote: function () {
  6914. var type = $$1.type(lists.head(arguments));
  6915. var isExternalAPICalled = type === 'string';
  6916. var hasInitOptions = type === 'object';
  6917. var options = $$1.extend({}, $$1.summernote.options, hasInitOptions ? lists.head(arguments) : {});
  6918. // Update options
  6919. options.langInfo = $$1.extend(true, {}, $$1.summernote.lang['en-US'], $$1.summernote.lang[options.lang]);
  6920. options.icons = $$1.extend(true, {}, $$1.summernote.options.icons, options.icons);
  6921. options.tooltip = options.tooltip === 'auto' ? !env.isSupportTouch : options.tooltip;
  6922. this.each(function (idx, note) {
  6923. var $note = $$1(note);
  6924. if (!$note.data('summernote')) {
  6925. var context = new Context($note, options);
  6926. $note.data('summernote', context);
  6927. $note.data('summernote').triggerEvent('init', context.layoutInfo);
  6928. }
  6929. });
  6930. var $note = this.first();
  6931. if ($note.length) {
  6932. var context = $note.data('summernote');
  6933. if (isExternalAPICalled) {
  6934. return context.invoke.apply(context, lists.from(arguments));
  6935. } else if (options.focus) {
  6936. context.invoke('editor.focus');
  6937. }
  6938. }
  6939. return this;
  6940. }
  6941. });
  6942. $$1.summernote = $$1.extend($$1.summernote, {
  6943. version: '0.8.9',
  6944. ui: ui,
  6945. dom: dom,
  6946. plugins: {},
  6947. options: {
  6948. modules: {
  6949. 'editor': Editor,
  6950. 'clipboard': Clipboard,
  6951. 'dropzone': Dropzone,
  6952. 'codeview': CodeView,
  6953. 'statusbar': Statusbar,
  6954. 'fullscreen': Fullscreen,
  6955. 'handle': Handle,
  6956. // FIXME: HintPopover must be front of autolink
  6957. // - Script error about range when Enter key is pressed on hint popover
  6958. 'hintPopover': HintPopover,
  6959. 'autoLink': AutoLink,
  6960. 'autoSync': AutoSync,
  6961. 'placeholder': Placeholder,
  6962. 'buttons': Buttons,
  6963. 'toolbar': Toolbar,
  6964. 'linkDialog': LinkDialog,
  6965. 'linkPopover': LinkPopover,
  6966. 'imageDialog': ImageDialog,
  6967. 'imagePopover': ImagePopover,
  6968. 'tablePopover': TablePopover,
  6969. 'videoDialog': VideoDialog,
  6970. 'helpDialog': HelpDialog,
  6971. 'airPopover': AirPopover
  6972. },
  6973. buttons: {},
  6974. lang: 'en-US',
  6975. followingToolbar: true,
  6976. otherStaticBar: '',
  6977. // toolbar
  6978. toolbar: [
  6979. ['style', ['style']],
  6980. ['font', ['bold', 'underline', 'clear']],
  6981. ['fontname', ['fontname']],
  6982. ['color', ['color']],
  6983. ['para', ['ul', 'ol', 'paragraph']],
  6984. ['table', ['table']],
  6985. ['insert', ['link', 'picture', 'video']],
  6986. ['view', ['fullscreen', 'codeview', 'help']]
  6987. ],
  6988. // popover
  6989. popatmouse: true,
  6990. popover: {
  6991. image: [
  6992. ['imagesize', ['imageSize100', 'imageSize50', 'imageSize25']],
  6993. ['float', ['floatLeft', 'floatRight', 'floatNone']],
  6994. ['remove', ['removeMedia']]
  6995. ],
  6996. link: [
  6997. ['link', ['linkDialogShow', 'unlink']]
  6998. ],
  6999. table: [
  7000. ['add', ['addRowDown', 'addRowUp', 'addColLeft', 'addColRight']],
  7001. ['delete', ['deleteRow', 'deleteCol', 'deleteTable']]
  7002. ],
  7003. air: [
  7004. ['color', ['color']],
  7005. ['font', ['bold', 'underline', 'clear']],
  7006. ['para', ['ul', 'paragraph']],
  7007. ['table', ['table']],
  7008. ['insert', ['link', 'picture']]
  7009. ]
  7010. },
  7011. // air mode: inline editor
  7012. airMode: false,
  7013. width: null,
  7014. height: null,
  7015. linkTargetBlank: true,
  7016. focus: false,
  7017. tabSize: 4,
  7018. styleWithSpan: true,
  7019. shortcuts: true,
  7020. textareaAutoSync: true,
  7021. hintDirection: 'bottom',
  7022. tooltip: 'auto',
  7023. container: 'body',
  7024. maxTextLength: 0,
  7025. styleTags: ['p', 'blockquote', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
  7026. fontNames: [
  7027. 'Arial', 'Arial Black', 'Comic Sans MS', 'Courier New',
  7028. 'Helvetica Neue', 'Helvetica', 'Impact', 'Lucida Grande',
  7029. 'Tahoma', 'Times New Roman', 'Verdana'
  7030. ],
  7031. fontSizes: ['8', '9', '10', '11', '12', '14', '18', '24', '36'],
  7032. // pallete colors(n x n)
  7033. colors: [
  7034. ['#000000', '#424242', '#636363', '#9C9C94', '#CEC6CE', '#EFEFEF', '#F7F7F7', '#FFFFFF'],
  7035. ['#FF0000', '#FF9C00', '#FFFF00', '#00FF00', '#00FFFF', '#0000FF', '#9C00FF', '#FF00FF'],
  7036. ['#F7C6CE', '#FFE7CE', '#FFEFC6', '#D6EFD6', '#CEDEE7', '#CEE7F7', '#D6D6E7', '#E7D6DE'],
  7037. ['#E79C9C', '#FFC69C', '#FFE79C', '#B5D6A5', '#A5C6CE', '#9CC6EF', '#B5A5D6', '#D6A5BD'],
  7038. ['#E76363', '#F7AD6B', '#FFD663', '#94BD7B', '#73A5AD', '#6BADDE', '#8C7BC6', '#C67BA5'],
  7039. ['#CE0000', '#E79439', '#EFC631', '#6BA54A', '#4A7B8C', '#3984C6', '#634AA5', '#A54A7B'],
  7040. ['#9C0000', '#B56308', '#BD9400', '#397B21', '#104A5A', '#085294', '#311873', '#731842'],
  7041. ['#630000', '#7B3900', '#846300', '#295218', '#083139', '#003163', '#21104A', '#4A1031']
  7042. ],
  7043. lineHeights: ['1.0', '1.2', '1.4', '1.5', '1.6', '1.8', '2.0', '3.0'],
  7044. tableClassName: 'table table-bordered',
  7045. insertTableMaxSize: {
  7046. col: 10,
  7047. row: 10
  7048. },
  7049. dialogsInBody: false,
  7050. dialogsFade: false,
  7051. maximumImageFileSize: null,
  7052. callbacks: {
  7053. onInit: null,
  7054. onFocus: null,
  7055. onBlur: null,
  7056. onBlurCodeview: null,
  7057. onEnter: null,
  7058. onKeyup: null,
  7059. onKeydown: null,
  7060. onImageUpload: null,
  7061. onImageUploadError: null
  7062. },
  7063. codemirror: {
  7064. mode: 'text/html',
  7065. htmlMode: true,
  7066. lineNumbers: true
  7067. },
  7068. keyMap: {
  7069. pc: {
  7070. 'ENTER': 'insertParagraph',
  7071. 'CTRL+Z': 'undo',
  7072. 'CTRL+Y': 'redo',
  7073. 'TAB': 'tab',
  7074. 'SHIFT+TAB': 'untab',
  7075. 'CTRL+B': 'bold',
  7076. 'CTRL+I': 'italic',
  7077. 'CTRL+U': 'underline',
  7078. 'CTRL+SHIFT+S': 'strikethrough',
  7079. 'CTRL+BACKSLASH': 'removeFormat',
  7080. 'CTRL+SHIFT+L': 'justifyLeft',
  7081. 'CTRL+SHIFT+E': 'justifyCenter',
  7082. 'CTRL+SHIFT+R': 'justifyRight',
  7083. 'CTRL+SHIFT+J': 'justifyFull',
  7084. 'CTRL+SHIFT+NUM7': 'insertUnorderedList',
  7085. 'CTRL+SHIFT+NUM8': 'insertOrderedList',
  7086. 'CTRL+LEFTBRACKET': 'outdent',
  7087. 'CTRL+RIGHTBRACKET': 'indent',
  7088. 'CTRL+NUM0': 'formatPara',
  7089. 'CTRL+NUM1': 'formatH1',
  7090. 'CTRL+NUM2': 'formatH2',
  7091. 'CTRL+NUM3': 'formatH3',
  7092. 'CTRL+NUM4': 'formatH4',
  7093. 'CTRL+NUM5': 'formatH5',
  7094. 'CTRL+NUM6': 'formatH6',
  7095. 'CTRL+ENTER': 'insertHorizontalRule',
  7096. 'CTRL+K': 'linkDialog.show'
  7097. },
  7098. mac: {
  7099. 'ENTER': 'insertParagraph',
  7100. 'CMD+Z': 'undo',
  7101. 'CMD+SHIFT+Z': 'redo',
  7102. 'TAB': 'tab',
  7103. 'SHIFT+TAB': 'untab',
  7104. 'CMD+B': 'bold',
  7105. 'CMD+I': 'italic',
  7106. 'CMD+U': 'underline',
  7107. 'CMD+SHIFT+S': 'strikethrough',
  7108. 'CMD+BACKSLASH': 'removeFormat',
  7109. 'CMD+SHIFT+L': 'justifyLeft',
  7110. 'CMD+SHIFT+E': 'justifyCenter',
  7111. 'CMD+SHIFT+R': 'justifyRight',
  7112. 'CMD+SHIFT+J': 'justifyFull',
  7113. 'CMD+SHIFT+NUM7': 'insertUnorderedList',
  7114. 'CMD+SHIFT+NUM8': 'insertOrderedList',
  7115. 'CMD+LEFTBRACKET': 'outdent',
  7116. 'CMD+RIGHTBRACKET': 'indent',
  7117. 'CMD+NUM0': 'formatPara',
  7118. 'CMD+NUM1': 'formatH1',
  7119. 'CMD+NUM2': 'formatH2',
  7120. 'CMD+NUM3': 'formatH3',
  7121. 'CMD+NUM4': 'formatH4',
  7122. 'CMD+NUM5': 'formatH5',
  7123. 'CMD+NUM6': 'formatH6',
  7124. 'CMD+ENTER': 'insertHorizontalRule',
  7125. 'CMD+K': 'linkDialog.show'
  7126. }
  7127. },
  7128. icons: {
  7129. 'align': 'note-icon-align',
  7130. 'alignCenter': 'note-icon-align-center',
  7131. 'alignJustify': 'note-icon-align-justify',
  7132. 'alignLeft': 'note-icon-align-left',
  7133. 'alignRight': 'note-icon-align-right',
  7134. 'rowBelow': 'note-icon-row-below',
  7135. 'colBefore': 'note-icon-col-before',
  7136. 'colAfter': 'note-icon-col-after',
  7137. 'rowAbove': 'note-icon-row-above',
  7138. 'rowRemove': 'note-icon-row-remove',
  7139. 'colRemove': 'note-icon-col-remove',
  7140. 'indent': 'note-icon-align-indent',
  7141. 'outdent': 'note-icon-align-outdent',
  7142. 'arrowsAlt': 'note-icon-arrows-alt',
  7143. 'bold': 'note-icon-bold',
  7144. 'caret': 'note-icon-caret',
  7145. 'circle': 'note-icon-circle',
  7146. 'close': 'note-icon-close',
  7147. 'code': 'note-icon-code',
  7148. 'eraser': 'note-icon-eraser',
  7149. 'font': 'note-icon-font',
  7150. 'frame': 'note-icon-frame',
  7151. 'italic': 'note-icon-italic',
  7152. 'link': 'note-icon-link',
  7153. 'unlink': 'note-icon-chain-broken',
  7154. 'magic': 'note-icon-magic',
  7155. 'menuCheck': 'note-icon-menu-check',
  7156. 'minus': 'note-icon-minus',
  7157. 'orderedlist': 'note-icon-orderedlist',
  7158. 'pencil': 'note-icon-pencil',
  7159. 'picture': 'note-icon-picture',
  7160. 'question': 'note-icon-question',
  7161. 'redo': 'note-icon-redo',
  7162. 'square': 'note-icon-square',
  7163. 'strikethrough': 'note-icon-strikethrough',
  7164. 'subscript': 'note-icon-subscript',
  7165. 'superscript': 'note-icon-superscript',
  7166. 'table': 'note-icon-table',
  7167. 'textHeight': 'note-icon-text-height',
  7168. 'trash': 'note-icon-trash',
  7169. 'underline': 'note-icon-underline',
  7170. 'undo': 'note-icon-undo',
  7171. 'unorderedlist': 'note-icon-unorderedlist',
  7172. 'video': 'note-icon-video'
  7173. }
  7174. }
  7175. });
  7176. })));
  7177. //# sourceMappingURL=summernote.js.map