summernote.js 285 KB

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