mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2025-09-24 16:40:55 -06:00
Add extend and _mergeProperties function, to be able to merge a given option with a default
This commit is contained in:
parent
0e6e466346
commit
fee8a87c06
@ -604,6 +604,50 @@ function _toggleBlock(editor, type, start_chars, end_chars) {
|
|||||||
cm.focus();
|
cm.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge the properties of one object into another.
|
||||||
|
*
|
||||||
|
* @param {Object} target The object where the properties will be copied
|
||||||
|
* @param {Object} source The object whose properties will be copied
|
||||||
|
*
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
function _mergeProperties(target, source) {
|
||||||
|
for(var property in source) {
|
||||||
|
if (source.hasOwnProperty(property)) {
|
||||||
|
if (source[property] instanceof Array) {
|
||||||
|
target[property] = source[property].concat(target[property] instanceof Array ? target[property] : []);
|
||||||
|
} else if (
|
||||||
|
source[property] !== null &&
|
||||||
|
typeof source[property] === 'object' &&
|
||||||
|
source[property].constructor === Object
|
||||||
|
) {
|
||||||
|
target[property] = mergeProperties(target[property] || {}, source[property]);
|
||||||
|
} else {
|
||||||
|
target[property] = source[property];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge an arbitrary number of objects into one.
|
||||||
|
* This function modifies the <code>target</code> object but also returns it.
|
||||||
|
*
|
||||||
|
* @param {Object} target The target object of the merge
|
||||||
|
*
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
function extend(target) {
|
||||||
|
for(var i = 1; i < arguments.length; i++) {
|
||||||
|
target = _mergeProperties(target, arguments[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The right word count in respect for CJK. */
|
/* The right word count in respect for CJK. */
|
||||||
function wordCount(data) {
|
function wordCount(data) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user