summernote-lite.js 315 KB

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