fix jshint complaints in common directory
This commit is contained in:
parent
4a05a859e6
commit
a600ece5c5
@ -140,12 +140,17 @@ define([
|
|||||||
log("No element provided!");
|
log("No element provided!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var el2,
|
||||||
|
adjusted,
|
||||||
|
initialLength;
|
||||||
|
|
||||||
log("Seeking to offset");
|
log("Seeking to offset");
|
||||||
// FIXME better debugging
|
// FIXME better debugging
|
||||||
// console.log(el, offset);
|
// console.log(el, offset);
|
||||||
if (!el.textContent) {
|
if (!el.textContent) {
|
||||||
// FIXME wat
|
// FIXME wat
|
||||||
var el2 = Tree.previousNode(el, inner);
|
el2 = Tree.previousNode(el, inner);
|
||||||
log("No text content available!");
|
log("No text content available!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -157,19 +162,20 @@ define([
|
|||||||
}
|
}
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
// seek backwards
|
// seek backwards
|
||||||
var el2 = Tree.previousNode(el, inner);
|
el2 = Tree.previousNode(el, inner);
|
||||||
if (!el2) { return null; }
|
if (!el2) { return null; }
|
||||||
var adjusted = el2.textContent.length;
|
adjusted = el2.textContent.length;
|
||||||
// FIXME TypeError: el.textContent is undefined
|
// FIXME TypeError: el.textContent is undefined
|
||||||
return seekToOffset(el2, (l - 1) - el.textContent.length);
|
return seekToOffset(el2, (l - 1) - el.textContent.length);
|
||||||
} else {
|
} else {
|
||||||
var l = el.textContent.length;
|
initialLength = el.textContent.length;
|
||||||
if (offset > l) {
|
if (offset > l) {
|
||||||
var el2 = Tree.nextNode(el, inner);
|
el2 = Tree.nextNode(el, inner);
|
||||||
if (!el2) { return null; }
|
if (!el2) { return null; }
|
||||||
var adjusted = el2.textContent.length;
|
adjusted = el2.textContent.length;
|
||||||
|
|
||||||
// FIXME TypeError: el.textContent is undefined
|
// FIXME TypeError: el.textContent is undefined
|
||||||
return seekToOffset(el2, (l - 1) - el.textContent.length);
|
return seekToOffset(el2, (initialLength - 1) - el.textContent.length);
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
el: el,
|
el: el,
|
||||||
|
|||||||
@ -47,7 +47,9 @@ define([], function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var attributes = {};
|
var attributes = {};
|
||||||
for(var i = 0; i < el.attributes.length; i++){
|
|
||||||
|
var i = 0;
|
||||||
|
for(;i < el.attributes.length; i++){
|
||||||
var attr = el.attributes[i];
|
var attr = el.attributes[i];
|
||||||
if(attr.name && attr.value){
|
if(attr.name && attr.value){
|
||||||
if(attr.name == "style"){
|
if(attr.name == "style"){
|
||||||
@ -81,7 +83,9 @@ define([], function () {
|
|||||||
|
|
||||||
// third element of the array is an array of child nodes
|
// third element of the array is an array of child nodes
|
||||||
var children = [];
|
var children = [];
|
||||||
var i = 0;
|
|
||||||
|
// js hint complains if we use 'var' here
|
||||||
|
i = 0;
|
||||||
for(; i < el.childNodes.length; i++){
|
for(; i < el.childNodes.length; i++){
|
||||||
children.push(DOM2HyperJSON(el.childNodes[i]));
|
children.push(DOM2HyperJSON(el.childNodes[i]));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,19 +51,19 @@ define(function () {
|
|||||||
* This algorithm is O(N). I suspect you could speed it up somehow using regular expressions.
|
* This algorithm is O(N). I suspect you could speed it up somehow using regular expressions.
|
||||||
*/
|
*/
|
||||||
var applyChange = function(ctx, oldval, newval) {
|
var applyChange = function(ctx, oldval, newval) {
|
||||||
// Strings are immutable and have reference equality. I think this test is O(1), so its worth doing.
|
// Strings are immutable and have reference equality. I think this test is O(1), so its worth doing.
|
||||||
if (oldval === newval) return;
|
if (oldval === newval) return;
|
||||||
|
|
||||||
var commonStart = 0;
|
var commonStart = 0;
|
||||||
while (oldval.charAt(commonStart) === newval.charAt(commonStart)) {
|
while (oldval.charAt(commonStart) === newval.charAt(commonStart)) {
|
||||||
commonStart++;
|
commonStart++;
|
||||||
}
|
}
|
||||||
|
|
||||||
var commonEnd = 0;
|
var commonEnd = 0;
|
||||||
while (oldval.charAt(oldval.length - 1 - commonEnd) === newval.charAt(newval.length - 1 - commonEnd) &&
|
while (oldval.charAt(oldval.length - 1 - commonEnd) === newval.charAt(newval.length - 1 - commonEnd) &&
|
||||||
commonEnd + commonStart < oldval.length && commonEnd + commonStart < newval.length) {
|
commonEnd + commonStart < oldval.length && commonEnd + commonStart < newval.length) {
|
||||||
commonEnd++;
|
commonEnd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bugz = {
|
var bugz = {
|
||||||
commonStart:commonStart,
|
commonStart:commonStart,
|
||||||
@ -71,14 +71,14 @@ var applyChange = function(ctx, oldval, newval) {
|
|||||||
oldvalLength: oldval.length,
|
oldvalLength: oldval.length,
|
||||||
newvalLength: newval.length
|
newvalLength: newval.length
|
||||||
};
|
};
|
||||||
if (oldval.length !== commonStart + commonEnd) {
|
if (oldval.length !== commonStart + commonEnd) {
|
||||||
ctx.localChange && ctx.localChange(true);
|
if (ctx.localChange) { ctx.localChange(true); }
|
||||||
ctx.remove(commonStart, oldval.length - commonStart - commonEnd);
|
ctx.remove(commonStart, oldval.length - commonStart - commonEnd);
|
||||||
}
|
}
|
||||||
if (newval.length !== commonStart + commonEnd) {
|
if (newval.length !== commonStart + commonEnd) {
|
||||||
ctx.localChange && ctx.localChange(true);
|
if (ctx.localChange) { ctx.localChange(true); }
|
||||||
ctx.insert(commonStart, newval.slice(commonStart, newval.length - commonEnd));
|
ctx.insert(commonStart, newval.slice(commonStart, newval.length - commonEnd));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,31 +95,32 @@ var cannonicalize = function (content) {
|
|||||||
// specified.
|
// specified.
|
||||||
var attachTextarea = function(elem, ctx) {
|
var attachTextarea = function(elem, ctx) {
|
||||||
|
|
||||||
// initial state will always fail the !== check in genop.
|
// initial state will always fail the !== check in genop.
|
||||||
var content = {};
|
var content = {};
|
||||||
|
var newSelection;
|
||||||
|
|
||||||
// Replace the content of the text area with newText, and transform the
|
// Replace the content of the text area with newText, and transform the
|
||||||
// current cursor by the specified function.
|
// current cursor by the specified function.
|
||||||
var replaceText = function(newText, transformCursor) {
|
var replaceText = function(newText, transformCursor) {
|
||||||
if (transformCursor) {
|
if (transformCursor) {
|
||||||
var newSelection = [transformCursor(elem.selectionStart), transformCursor(elem.selectionEnd)];
|
newSelection = [transformCursor(elem.selectionStart), transformCursor(elem.selectionEnd)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fixate the window's scroll while we set the element's value. Otherwise
|
// Fixate the window's scroll while we set the element's value. Otherwise
|
||||||
// the browser scrolls to the element.
|
// the browser scrolls to the element.
|
||||||
var scrollTop = elem.scrollTop;
|
var scrollTop = elem.scrollTop;
|
||||||
elem.value = newText;
|
elem.value = newText;
|
||||||
content = elem.value; // Not done on one line so the browser can do newline conversion.
|
content = elem.value; // Not done on one line so the browser can do newline conversion.
|
||||||
if (elem.scrollTop !== scrollTop) elem.scrollTop = scrollTop;
|
if (elem.scrollTop !== scrollTop) elem.scrollTop = scrollTop;
|
||||||
|
|
||||||
// Setting the selection moves the cursor. We'll just have to let your
|
// Setting the selection moves the cursor. We'll just have to let your
|
||||||
// cursor drift if the element isn't active, though usually users don't
|
// cursor drift if the element isn't active, though usually users don't
|
||||||
// care.
|
// care.
|
||||||
if (newSelection && window.document.activeElement === elem) {
|
if (newSelection && window.document.activeElement === elem) {
|
||||||
elem.selectionStart = newSelection[0];
|
elem.selectionStart = newSelection[0];
|
||||||
elem.selectionEnd = newSelection[1];
|
elem.selectionEnd = newSelection[1];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//replaceText(ctx.get());
|
//replaceText(ctx.get());
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user