(function (w, d, u) {
/* Variable Conventions _*VAR*_ is html or class text*/
var wl = '^\\/t\\d+',
ps = '^\\/post',
pv = '\\/privmsg\\?.+(post|reply){1}(.*)?',
_GROUP_ = null,
i,
_CLASS_ = "sceditor-button sceditor-button-",
_COMMAND_ = "data-sceditor-command",
_TOOLBAR_ = "sceditor-toolbar",
_MESSAGE_ = "message",
_IFRAME_ = ".sceditor-container iframe",
_BUTTON_ = "sceditor-button",
_GROUPT_ = "sceditor-group",
_TEXTAREA_ = "text_editor_textarea",
options,
interval,
awe_debug = false;
var awe = function (opts) {
var target = document.querySelector('#textarea_content');
if (target) {
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
var added = mutation.addedNodes;
for (var i = 0; i < added.length; i++) {
if ((/sceditor-container/g).test(added[i].className)) {
return new AWE(opts);
} else easyDebug("info", "AW Editor::\n No mutation on object, so there was nothing to observe.");
}
observer.disconnect();
});
});
var config = { addedNodes: true, attributes: true, childList: true, characterData: true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
} else return false;
};
var AWE = function (opts) {
this.instantiate = false;
this.debug = false;
this.commandList = {};
this.pathname = w.location.href.replace(w.location.origin, '');
var runAt = [];
if (opts && opts.location) {
for (i = 0; i < 3; i++) {
var loca = opts.location[i];
switch (loca) {
case 0:runAt.push(wl); break;
case 1: runAt.push(ps); break;
case 2: runAt.push(pv); break;
case 3: runAt = [wl, ps, pv]; break;
}
}
} else runAt = [wl, ps, pv];
windowLocation = new RegExp(runAt.join("|"), 'gi');
if (windowLocation.test(this.pathname)) {
this.toolbar = getElement('class', _TOOLBAR_)[0];
this.textarea = getElement('input', _MESSAGE_)[0];
this.iframe = getElement('query', _IFRAME_)[0];
this.instantiate = true;
this.groups = getElement('class', _GROUPT_);
var btns = getElement('class', _BUTTON_);
for (i = 0; i < btns.length; i++) {
this.commandList[btns[i].getAttribute(_COMMAND_)] = btns[i];
}
/*
*
*
* HERE IS THE ISSUE IT WON'T RETURN THIS!
* IF I DO return (window.extendAWE = extendAWE);
* It works but after a second
*/
return this;
} else easyDebug('info', "AW Editor::\n We couldn't instantiate AWE 3.4 please try again.");
};
awe.fn = AWE.prototype = {
add: function (cmd, opts) {
},
remove: "",
rearrange: "",
id: "",
destroy: "",
insert: "",
ajaxify: ""
};
/*
* Next codes are functions to make awe faster and easier without using jQuery
* When editing ensure to use the debugger
*/
function easyDebug(t, m) {
if (awe_debug === true) return console[t](m);
}
return (window.editor = awe);
})(this, document);
我上面的代码,在AWE
函数中它不会返回这个!我已经将我的代码缩小为用于链接的基本模板并且可以正常工作,但由于某种原因它不会返回原来的样子。我已经尝试了一切,现在变得很麻烦。我想知道它是否可能是我的开关盒?有人可以向我解释为什么它不会返回任何东西,我什至尝试过试用,return true
我可以console.log
直接在它上面但它不会返回任何东西。
var newEditor = editor({
debug:true,
defaultText:"How is going today?",
removeWYSIWYG:true
});
//now that newEditor caches the returned object
newEditor.add('newButton',{
//new button options
});
新的观察者迭代
var awe = function (opts) {
var target = document.querySelector('#textarea_content');
if (target) {
var observer = new MutationObserver(function(mutations) {
var mutate = mutations[0].addedNodes;
var ret;
for(i=0;i<mutate.length;i++){
if((/sceditor-container/g).test(mutate[i].className)){
ret = new AWE(opts);
break;
}
}
return ret;
});
var config = {
addedNodes: true,
attributes: true,
childList: true,
characterData: true
};
// pass in the target node, as well as the observer options
observer.observe(target, config);
} else return false;
};