summernote-bs4.js 294 KB

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