summernote.js 302 KB

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