summernote-lite.js 277 KB

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