summernote-bs4.js 256 KB

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