-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split common.js and rename to main (#994)
* Split common.js into multiple core source files * Rename common.js to main.js (entry and output) * Rename qtranslate-admin-common PHP to qtranslate-admin-main * qTranslateX class definition no longer exposed
- Loading branch information
Showing
13 changed files
with
158 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* DOM manipulation | ||
*/ | ||
export var qtranxj_ce = function (tagName, props, pNode, isFirst) { | ||
var el = document.createElement(tagName); | ||
if (props) { | ||
for (var prop in props) { | ||
el[prop] = props[prop]; | ||
} | ||
} | ||
if (pNode) { | ||
if (isFirst && pNode.firstChild) { | ||
pNode.insertBefore(el, pNode.firstChild); | ||
} else { | ||
pNode.appendChild(el); | ||
} | ||
} | ||
return el; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Shared core functionalities and setup | ||
*/ | ||
import './qtranslatex'; | ||
|
||
export * from './dom'; | ||
export * from './qblocks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* Utilities for qTranslate blocks | ||
*/ | ||
var qTranslateConfig = window.qTranslateConfig; | ||
|
||
export var qtranxj_get_split_blocks = function (text) { | ||
var regex = '(<!--:lang-->|<!--:-->|\\[:lang]|\\[:]|{:lang}|{:})'.replace(/lang/g, qTranslateConfig.lang_code_format); | ||
var split_regex = new RegExp(regex, "gi"); | ||
|
||
// Most browsers support RegExp.prototype[@@split]()... except IE | ||
if ('a~b'.split(/(~)/).length === 3) { | ||
return text.split(split_regex); | ||
} | ||
|
||
// compatibility for unsupported engines | ||
var start = 0, arr = []; | ||
var result; | ||
while ((result = split_regex.exec(text)) != null) { | ||
arr.push(text.slice(start, result.index)); | ||
if (result.length > 1) | ||
arr.push(result[1]); | ||
start = split_regex.lastIndex; | ||
} | ||
if (start < text.length) | ||
arr.push(text.slice(start)); | ||
if (start === text.length) | ||
arr.push(''); // delimiter at the end | ||
return arr; | ||
}; | ||
|
||
export var qtranxj_split = function (text) { | ||
var blocks = qtranxj_get_split_blocks(text); | ||
return qtranxj_split_blocks(blocks); | ||
}; | ||
|
||
export var qtranxj_split_blocks = function (blocks) { | ||
var result = new Object; | ||
for (var lang in qTranslateConfig.language_config) { | ||
result[lang] = ''; | ||
} | ||
if (!blocks || !blocks.length) | ||
return result; | ||
if (blocks.length === 1) { | ||
// no language separator found, enter it to all languages | ||
var b = blocks[0]; | ||
for (var lang in qTranslateConfig.language_config) { | ||
result[lang] += b; | ||
} | ||
return result; | ||
} | ||
var clang_regex = new RegExp('<!--:(lang)-->'.replace(/lang/g, qTranslateConfig.lang_code_format), 'gi'); | ||
var blang_regex = new RegExp('\\[:(lang)]'.replace(/lang/g, qTranslateConfig.lang_code_format), 'gi'); | ||
var slang_regex = new RegExp('{:(lang)}'.replace(/lang/g, qTranslateConfig.lang_code_format), 'gi'); | ||
var lang = false; | ||
var matches; | ||
for (var i = 0; i < blocks.length; ++i) { | ||
var b = blocks[i]; | ||
if (!b.length) | ||
continue; | ||
matches = clang_regex.exec(b); | ||
clang_regex.lastIndex = 0; | ||
if (matches != null) { | ||
lang = matches[1]; | ||
continue; | ||
} | ||
matches = blang_regex.exec(b); | ||
blang_regex.lastIndex = 0; | ||
if (matches != null) { | ||
lang = matches[1]; | ||
continue; | ||
} | ||
matches = slang_regex.exec(b); | ||
slang_regex.lastIndex = 0; | ||
if (matches != null) { | ||
lang = matches[1]; | ||
continue; | ||
} | ||
if (b === '<!--:-->' || b === '[:]' || b === '{:}') { | ||
lang = false; | ||
continue; | ||
} | ||
if (lang) { | ||
if (!result[lang]) result[lang] = b; | ||
else result[lang] += b; | ||
lang = false; | ||
} else { | ||
// keep neutral text | ||
for (var key in result) { | ||
result[key] += b; | ||
} | ||
} | ||
} | ||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Storage for admin edit language | ||
*/ | ||
|
||
// the edit language corresponds to the current LSB selection or the main admin language for single mode | ||
var keyEditLanguage = 'qtranslate-xt-admin-edit-language'; | ||
|
||
export var getStoredEditLanguage = function () { | ||
return sessionStorage.getItem(keyEditLanguage); | ||
}; | ||
|
||
export var storeEditLanguage = function (lang) { | ||
try { | ||
sessionStorage.setItem(keyEditLanguage, lang); | ||
} catch (e) { | ||
// no big deal if this can't be stored | ||
console.log('Failed to store "' + keyEditLanguage + '" with sessionStorage', e); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Common API and core functionalities for qTranslate-XT | ||
*/ | ||
export * from './core'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters