summernote-lite.js 275 KB

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