summernote.js 294 KB

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