summernote-bs4.js 259 KB

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