summernote.js 258 KB

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