@@ -54,13 +54,13 @@ function basisVis() {
editableElementsFun ( ) ;
let basis3 = document . getElementById ( 'basis3' ) ;
let sideFloatClass = basis3 ? basis3 . querySelectorAll ( '[style*="visibility: visible;"]' ) : null ;
if ( ! basis3 || ! sideFloatClass || ! editableElements || editableElements . length === 0 ) return ;
elementsС hecked = [ basis3 , ... sideFloatClass , ... editableElements ] ;
if ( ! basis3 || ! sideFloatClass || ! window . editableElements || window . editableElements . length === 0 ) return ;
let elementsС hecked = [ basis3 , ... sideFloatClass , ... window . editableElements ] ;
if ( basis3 . style . visibility === "visible" ) {
basis3 . style . visibility = "hidden" ;
sessionStorage . setItem ( 'basis3_visibility' , 'hidden' ) ;
editableElements . forEach ( function ( element ) {
window . editableElements . forEach ( function ( element ) {
if ( element ) {
element . setAttribute ( "contenteditable" , false ) ;
}
@@ -69,18 +69,18 @@ function basisVis() {
sideFloatClass . forEach ( function ( element ) {
element . style . visibility = "hidden" ;
} ) ;
for ( let i = 0 ; i < editId . length ; i ++ ) {
for ( let i = 0 ; i < editId . length ; i ++ ) {
editMode = - 1 ;
if ( document . getElementById ( editId [ i ] ) ) {
document . getElementById ( editId [ i ] ) . classList . remove ( 'active' ) ;
}
}
document . getElementById ( 'bcbody' ) . style . top = '0px' ;
document . querySelectorAll ( '.bfloat' ) . forEach ( e => e . style . fontSize = '' )
document . querySelectorAll ( '.bfloat' ) . forEach ( e => e . style . fontSize = '' )
} else {
basis3 . style . visibility = "visible" ;
sessionStorage . setItem ( 'basis3_visibility' , 'visible' ) ;
editableElements . forEach ( function ( element ) {
window . editableElements . forEach ( function ( element ) {
if ( element ) {
element . setAttribute ( "contenteditable" , true ) ;
}
@@ -90,20 +90,20 @@ function basisVis() {
basis3 . style . top = '20%' ;
basis3 . style . transform = 'translate(0%, -20%)' ;
document . getElementById ( 'bcbody' ) . style . top = '30px' ;
document . querySelectorAll ( '.bfloat' ) . forEach ( e => e . style . fontSize = '1em' )
document . querySelectorAll ( '.bfloat' ) . forEach ( e => e . style . fontSize = '1em' )
}
}
window . basisVis = basisVis ;
/** @brief С б о р всех редактируемых элементов */
function editableElementsFun ( ) {
let content = document . getElementById ( 'content' ) ;
editableElem ents = document . querySelectorAll ( '.pluginEditable ' ) ;
editableElements = Array . from ( editableElements ) ;
editableElements . push ( content ) ;
window . editableElements = [ ] ;
let cont ents = document . querySelectorAll ( '.content ' ) ;
let pluginEls = document . querySelectorAll ( '.pluginEditable' ) ;
pluginEls = Array . from ( pluginEls ) ;
window . editableElements . push ( ... pluginEls , ... contents ) ;
editableElements . forEach ( function ( element ) {
window . editableElements . forEach ( function ( element ) {
if ( ! element ) {
console . log ( "Element " + element + " not found." ) ;
return ;
@@ -111,31 +111,28 @@ function editableElementsFun() {
} ) ;
}
addEventListener ( "LoadeditorJs" , function ( )
{
let te = document . getElementById ( "tex" ) ; // Ссылка на текстовое поле
let tex = document . getElementById ( "tex" ) ; // Ссылка на стили текстового поля
if ( document . getElementById ( "content" ) == "" ) {
te . value = document . getElementById ( " content" ) . innerHTML ; // Передача данных из области контента в текстовое поле
}
// Передаём содержимое пустых блоков в поле
document . querySelectorAll ( '. content' ) . forEach ( el => {
if ( ! el . innerHTML ) te . value = el . innerHTML ;
} ) ;
// Символы клавиш с о знаками препинания или перевода строки
let symb = [ "Enter" , "!" , "?" , ";" , ":" , "," , "." , " " , "-" , "'" , "\"" , "(" , ")" , "{" , "}" , "[" , "]" , "_" , "&" , "/" , "\\" , "*" ] ;
// Запись в память введенного текста при нажатии клавиши с о знаком препинания или перевода строки
if ( document . getElementById ( " content" ) ) {
document . getElementById ( "content" ) . addEventListener ( " keyup" , function ( ev )
{
for ( let i = 0 ; i < symb . length ; i++ )
{
if ( symb [ i ] == ev . key )
inter ( ) ;
}
} ) ;
}
document . querySelectorAll ( '. content' ) . forEach ( el => {
el . addEventListener ( ' keyup' , ev => {
for ( let i = 0 ; i < symb . length ; i ++ ) {
if ( symb [ i ] == ev . key ) inter ( ) ;
}
} ) ;
} ) ;
let sel = document . getSelection ( ) ;
function selInContenteditable ( insertType ) {
@@ -497,69 +494,74 @@ document.getElementById("newPage").addEventListener("click", newPageFun);
function newPageFun ( ) {
document . getElementById ( "right-float" ) . innerHTML = "" ;
document . getElementById ( "left-float" ) . innerHTML = "" ;
document . getElementById ( " content" ) . innerHTML = "" ;
document . querySelectorAll ( '. content' ) . forEach ( el => el . innerHTML = "" ) ;
document . getElementById ( "mainTitle" ) . innerHTML = "<i>{{new_file}}!</i>" ;
window . newPageFunValue = "newPage" ;
document . getElementById ( "settingsMain_d" ) . style . visibility = "hidden" ;
}
// Сохранение выделение
document . addEventListener ( 'selectionchange' , ( ) => {
const content = document . getElementById ( 'content' ) ;
const contents = document . querySelectorAll ( '. content' ) ;
if ( ! contents || contents . length === 0 ) return ;
const sel = window . getSelection ( ) ;
if ( ! sel . rangeCount ) return ;
const range = sel . getRangeAt ( 0 ) ;
const startNode = range . startContainer ;
i f ( content . contains ( startNode ) ) {
saveSelection ( ) ;
for ( let content of contents ) {
if ( content . contains ( startNode ) ) {
saveSelection ( ) ;
break ;
}
}
} ) ;
let savedSel = null ;
function saveSelection ( ) {
const content = document . getElementById ( 'content' ) ;
const contents = document . querySelectorAll ( '. content' ) ;
const sel = window . getSelection ( ) ;
if ( ! sel . rangeCount ) return ;
const range = sel . getRangeAt ( 0 ) ;
i f ( ! content . contains ( range . commonAncestorContainer ) ) return ;
const pre = range . cloneRange ( ) ;
pre . selectNodeContents ( content ) ;
pre . setEnd ( range . startContainer , range . startOffse t) ;
const start = pre . toString ( ) . length ;
const end = start + rang e . toString ( ) . length ;
savedSel = { start , end } ;
for ( let content of contents ) {
if ( content . contains ( range . commonAncestorContainer ) ) {
const pre = range . cl oneRange ( ) ;
pre . selectNodeContents ( conten t) ;
pre . setEnd ( range . startContainer , range . startOffset ) ;
const start = p re. toString ( ) . length ;
const end = start + range . toString ( ) . length ;
savedSel = { start , end } ;
break ;
}
}
}
function restoreSelection ( ) {
if ( ! savedSel ) return ;
const content = document . getElementById ( 'content' ) ;
const { start , end } = savedSel ;
let charIndex = 0 ;
const range = document . createRange ( ) ;
range . setStart ( content , 0 ) ;
range . collapse ( true ) ;
try {
( function traver se ( nod e) {
if ( node . nodeType === Node . TEXT _NODE ) {
const next = charIndex + n ode. length ;
if ( charInd ex < = start && next >= start ) {
range . setStart ( node , start - charIndex ) ;
}
if ( charIndex <= end && next >= end ) {
range . setEnd ( node , end - charIndex ) ;
throw 'done' ;
}
charIndex = next ;
} else {
node . childNodes . forEach ( traverse ) ;
}
} ) ( content ) ;
} catch ( e ) { }
const sel = window . getSelection ( ) ;
sel . removeAllRanges ( ) ;
sel . addRange ( range ) ;
if ( ! savedSel ) return ;
const contents = document . querySelectorAll ( '. content' ) ;
const { start , end } = savedSel ;
let charIndex = 0 ;
const range = document . createRange ( ) ;
try {
for ( const content of contents ) {
range . setStart ( content , 0 ) ;
range . collap se ( tru e) ;
( function traverse ( node ) {
if ( node . nodeType === N ode. TEXT _NODE ) {
const n ext = charIndex + node . length ;
if ( charIndex <= start && next >= start ) range . setStart ( node , start - charIndex ) ;
if ( charIndex <= end && next >= end ) {
range . setEnd ( node , end - charIndex ) ;
throw 'done' ;
}
charIndex = next ;
} else node . childNodes . forEach ( traverse ) ;
} ) ( content ) ;
}
} catch ( e ) { }
const sel = window . getSelection ( ) ;
sel . removeAllRanges ( ) ;
sel . addRange ( range ) ;
}
// Взаимодействие с плагинами
@@ -1457,14 +1459,14 @@ const singleFormats = [
const specialFormats = [ 'butlink' , 'linkdel' , 'forma' , 'col' , 'backgr' ] ;
addEventListener ( "LoadeditorJs" , function ( ) {
const content = document . getElementById ( 'content' ) ;
const content = document . querySelectorAll ( '. content' ) ;
simpleFormats . forEach ( f => {
document . getElementById ( f . id ) . addEventListener ( 'click' , ( ) => {
const sel = window . getSelection ( ) ;
if ( ! sel . rangeCount ) return ;
const range = sel . getRangeAt ( 0 ) ;
if ( ! content . contains ( range . commonAncestorContainer ) ) return ;
if ( ! [ ... document . querySelectorAll ( '.content' ) ] . some ( c => c . contains ( range . commonAncestorContainer ) ) ) return ;
let all = true ;
const it = document . createNodeIterator (
range . commonAncestorContainer ,
@@ -1495,7 +1497,7 @@ divFormats.forEach(f => {
const sel = window . getSelection ( ) ;
if ( ! sel . rangeCount ) return ;
const range = sel . getRangeAt ( 0 ) ;
if ( ! content . contains ( range . commonAncestorContainer ) ) return ;
if ( ! [ ... document . querySelectorAll ( '.content' ) ] . some ( c => c . contains ( range . commonAncestorContainer ) ) ) return ;
divApplyformat ( range , f ) ;
inter ( ) ;
} ) ;
@@ -1506,7 +1508,7 @@ listFormats.forEach(f => {
const sel = window . getSelection ( ) ;
if ( ! sel . rangeCount ) return ;
const range = sel . getRangeAt ( 0 ) ;
if ( ! content . contains ( range . commonAncestorContainer ) ) return ;
if ( ! [ ... document . querySelectorAll ( '.content' ) ] . some ( c => c . contains ( range . commonAncestorContainer ) ) ) return ;
listApplyformat ( range , f ) ;
inter ( ) ;
} ) ;
@@ -1523,7 +1525,7 @@ singleFormats.forEach(f => {
const sel = window . getSelection ( )
if ( ! sel . rangeCount ) return
const range = sel . getRangeAt ( 0 )
if ( ! content . contains ( range . commonAncestorContainer ) ) return
if ( ! [ ... document . querySelectorAll ( '.content' ) ] . some ( c => c . contains ( range . commonAncestorContainer ) ) ) return ;
singleApplyformat ( range , f )
inter ( )
} )
@@ -1534,7 +1536,7 @@ specialFormats.forEach(f => {
const sel = window . getSelection ( ) ;
if ( ! sel . rangeCount ) return ;
const range = sel . getRangeAt ( 0 ) ;
if ( ! content . contains ( range . commonAncestorContainer ) ) return ;
if ( ! [ ... content ] . some ( c => c . contains ( range . commonAncestorContainer ) ) ) return ;
if ( typeof document [ f + 'Fun' ] === 'function' ) document [ f + 'Fun' ] ( range ) ;
else window [ f + 'Fun' ] ( range ) ;
inter ( ) ;
@@ -1543,10 +1545,13 @@ specialFormats.forEach(f => {
const events = [ 'pointerup' , 'keyup' , 'input' , 'focus' , 'blur' , 'click' ] ;
events . forEach ( evt => {
if ( ! content ) return ;
content . addEventListener ( evt , ( ) => {
updateToolbarStyles ( ) ;
updateSingleSelectors ( ) ;
const contents = document . querySelectorAll ( '.content' ) ;
if ( ! contents || contents . length === 0 ) return ;
contents . forEach ( content => {
content . addEventListener ( evt , ( ) => {
updateToolbarStyles ( ) ;
updateSingleSelectors ( ) ;
} ) ;
} ) ;
} ) ;
@@ -1561,36 +1566,42 @@ let currentIndex = 0
/** @brief Сохраняет текущее состояние контента, если оно изменилось */
function inter ( ) {
const editable = document . getElementById ( "content" )
if ( editable ) {
let currentContent = editable . innerHTML
if ( currentContent != = arr [ currentIndex ] ) {
currentIndex ++
arr = arr . slice ( 0 , currentIndex )
arr . push ( currentContent )
const editables = document . querySelectorAll ( ". content" )
editables . forEach ( editable => {
if ( editable ) {
let currentContent = editable . innerHTML
if ( currentContent !== arr [ currentIndex ] ) {
currentIndex ++
arr = arr . slice ( 0 , currentIndex )
arr . push ( currentContent )
}
}
}
} )
}
if ( document . getElementById ( "content" ) ) {
arr [ 0 ] = document . getElementById ( "content" ) . innerHTML
}
document . querySelectorAll ( ". content" ) . forEach ( ( editable , i ) => {
if ( i === 0 ) arr [ 0 ] = editable . innerHTML
} )
document . getElementById ( "forw" ) . addEventListener ( "click" , function ( ) {
if ( currentIndex < arr . length - 1 ) {
currentIndex ++
const editable = document . getElementById ( "content" )
editable . innerHTML = arr [ currentIndex ]
editable . setAttribute ( "contenteditable" , "true" )
const editables = document . querySelectorAll ( ". content" )
editables . forEach ( editable => {
editable . innerHTML = arr [ currentIndex ]
editable . setAttribute ( "contenteditable" , "true" )
} )
}
} )
document . getElementById ( "bac" ) . addEventListener ( "click" , function ( ) {
if ( currentIndex > 0 ) {
currentIndex --
const editable = document . getElementById ( "content" )
editable . innerHTML = arr [ currentIndex ]
editable . setAttribute ( "contenteditable" , "true" )
const editables = document . querySelectorAll ( ". content" )
editables . forEach ( editable => {
editable . innerHTML = arr [ currentIndex ]
editable . setAttribute ( "contenteditable" , "true" )
} )
}
} )
@@ -1785,8 +1796,10 @@ function divApplyformat(range, format) {
range . compareBoundaryPoints ( Range . START _TO _END , er ) > 0 ;
} ;
Array . from ( cont ent. children ) . forEach ( child => {
if ( i ntersects ( child ) ) externals . add ( child ) ;
Array . from ( docum ent. querySelectorAll ( '.content' ) ) .forEach ( content => {
Array . from ( co ntent . children ) . forEach ( child => {
if ( intersects ( child ) ) externals . add ( child ) ;
} ) ;
} ) ;
externals . forEach ( div => {
@@ -1811,8 +1824,10 @@ function listApplyformat(range, format) {
if ( type === 'listNone' ) {
const lists = new Set ( ) ;
Array . from ( cont ent. querySelectorAll ( 'li ' ) ) . forEach ( li => {
if ( i ntersects ( li) ) lists . add ( li . parentNode ) ;
Array . from ( docum ent. querySelectorAll ( '.content ' ) ) . forEach ( content => {
Array . from ( co ntent . querySelectorAll ( ' li' ) ) . forEach ( li => {
if ( intersects ( li ) ) lists . add ( li . parentNode ) ;
} ) ;
} ) ;
lists . forEach ( list => {
@@ -1849,31 +1864,33 @@ function listApplyformat(range, format) {
parent . removeChild ( list ) ;
} ) ;
} else {
const items = Array . from ( cont ent. children ) . filter ( child => intersects ( child ) ) ;
if ( ! items . length ) return ;
Array . from ( docum ent. querySelectorAll ( '.content' ) ) . forEach ( content => {
const items = Array . from ( content . children ) . filter ( child => intersects ( child ) ) ;
if ( ! items . length ) return ;
let listEl ;
if ( type === 'listNumbers' || type === 'listLetters' ) {
listEl = document . createElement ( 'ol' ) ;
listEl . style . listStyleType = format . style . listStyleType ;
} else {
listEl = document . createElement ( 'ul' ) ;
listEl . style . listStyleType = format . style . listStyleType ;
}
content . insertBefore ( listEl , items [ 0 ] ) ;
items . forEach ( node => {
if ( node . tagName === 'UL' || node . tagName === 'OL' ) {
Array . from ( node . children ) . forEach ( li => {
listEl . appendChild ( li ) ;
} ) ;
content . removeChild ( node ) ;
let listEl ;
if ( type === 'listNumbers' || type === 'listLetters' ) {
listEl = document . createElement ( 'ol' ) ;
listEl . style . listStyleType = format . style . listStyleType ;
} else {
const li = document . createElement ( 'li ' ) ;
content . removeChild ( node ) ;
li . appendChild ( node ) ;
listEl . appendChild ( li ) ;
listEl = document . createElement ( 'u l' ) ;
listEl . style . listStyleType = format . style . listStyleType ;
}
content . insertBefore ( listEl , items [ 0 ] ) ;
items . forEach ( node => {
if ( node . tagName === 'UL' || node . tagName === 'OL' ) {
Array . from ( node . children ) . forEach ( li => {
listEl . appendChild ( li ) ;
} ) ;
content . removeChild ( node ) ;
} else {
const li = document . createElement ( 'li' ) ;
content . removeChild ( node ) ;
li . appendChild ( node ) ;
listEl . appendChild ( li ) ;
}
} ) ;
} ) ;
}
}
@@ -1959,32 +1976,36 @@ function formaFun(range) {
return range . compareBoundaryPoints ( Range . END _TO _START , er ) < 0
&& range . compareBoundaryPoints ( Range . START _TO _END , er ) > 0 ;
} ;
Array . from ( cont ent. children ) . forEach ( child => {
if ( i ntersects ( child ) ) externals . add ( child ) ;
Array . from ( docum ent. querySelectorAll ( '.content' ) ) .forEach ( content => {
Array . from ( co ntent . children ) . forEach ( child => {
if ( intersects ( child ) ) externals . add ( child ) ;
} ) ;
} ) ;
externals . forEach ( el => {
el . style . textAlign = '' ;
} ) ;
const itList = document . createNodeIterator (
content ,
NodeFilter . SHOW _ELEMENT ,
{
acceptNode : n =>
( n . tagName === 'UL' || n . tagName === 'OL' ) &&
range . intersectsNode ( n )
? NodeFilter . FILTER _ACCEPT
: NodeFilter . FILTER _REJEC T
Array . from ( document . querySelectorAll ( '.content' ) ) . forEach ( content => {
const itList = document . createNodeIterator (
content ,
NodeFilter . SHOW _ELEMENT ,
{
acceptNode : n =>
( n . tagName === 'UL' || n . tagName === 'OL' ) &&
range . intersectsNode ( n )
? NodeFilter . FILTER _ACCEP T
: NodeFilter . FILTER _REJECT
}
) ;
let listEl ;
while ( listEl = itList . nextNode ( ) ) {
const parent = listEl . parentNode ;
Array . from ( listEl . children ) . forEach ( li => {
while ( li . firstChild ) parent . insertBefore ( li . firstChild , listEl ) ;
} ) ;
parent . removeChild ( listEl ) ;
}
) ;
let listEl ;
while ( listEl = itList . nextNode ( ) ) {
const parent = listEl . parentNode ;
Array . from ( listEl . children ) . forEach ( li => {
while ( li . firstChild ) parent . insertBefore ( li . firstChild , listEl ) ;
} ) ;
parent . removeChild ( listEl ) ;
}
} );
function unwrapAllSpansAndLinks ( node ) {
const frag = document . createDocumentFragment ( ) ;
@@ -2079,7 +2100,7 @@ function detectFormatState(format) {
const sel = window . getSelection ( ) ;
if ( ! sel . rangeCount ) return 'none' ;
const range = sel . getRangeAt ( 0 ) ;
if ( ! content . contains ( range . commonAncestorContainer ) ) return 'none' ;
if ( ! [ ... document . querySelectorAll ( '.content' ) ] . some ( c => c . contains ( range . commonAncestorContainer ) ) ) return 'none' ;
const it = document . createNodeIterator (
range . commonAncestorContainer ,
NodeFilter . SHOW _TEXT ,
@@ -2091,7 +2112,7 @@ function detectFormatState(format) {
if ( ! text ) continue ;
total ++ ;
let cur = node . parentElement , ok = false ;
while ( cur && cur !== content ) {
while ( cur && ! [ ... document . querySelectorAll ( '.content' ) ] . includes ( cur ) ) {
const fmt = simpleFormats . find ( f => f . id === format ) ;
const v = fmt ? getComputedStyle ( cur ) [ fmt . prop ] || '' : '' ;
if ( fmt && fmt . test ( v ) ) { ok = true ; break ; }
@@ -2128,7 +2149,7 @@ function detectSingleState(format) {
const sel = window . getSelection ( ) ;
if ( ! sel . rangeCount ) return '' ;
const range = sel . getRangeAt ( 0 ) ;
if ( ! content . contains ( range . commonAncestorContainer ) ) return '' ;
if ( ! [ ... document . querySelectorAll ( '.content' ) ] . some ( c => c . contains ( range . commonAncestorContainer ) ) ) return '' ;
const it = document . createNodeIterator (
range . commonAncestorContainer ,
NodeFilter . SHOW _TEXT ,
@@ -2263,7 +2284,7 @@ document.querySelectorAll('.align-dropdown-text').forEach(dropdown => {
const sel = window . getSelection ( )
if ( sel . rangeCount ) {
const range = sel . getRangeAt ( 0 )
if ( content . contains ( range . commonAncestorContainer ) ) {
if ( [ ... document . querySelectorAll ( '.content' ) ] . some ( c => c . contains ( range . commonAncestorContainer ) ) ) {
singleApplyformat ( range , f )
inter ( )
}