summernote-bs4.js 256 KB

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