Skip to content

Commit

Permalink
Try to fix issue #21
Browse files Browse the repository at this point in the history
Try multiple times to put it in the right place, since some times
it's moved to the end of the page
See #21
  • Loading branch information
costas-basdekis committed May 20, 2022
1 parent 3fac48f commit af22c90
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,36 @@ $(function() {

self.gcodeParser = new GcodeParser();

// Try multiple times to put it in the right place, since some times
// it's moved to the end of the page
// See https://github.com/costas-basdekis/MarlinGcodeDocumentation/issues/21
let moveTemplateToPositionAttemptCount = 0;
self.moveTemplateToPosition = () => {
if (moveTemplateToPositionAttemptCount >= 5) {
console.error(
`Could not find anchor for Marlin GCode documentation ` +
`- aborting after ` +
`${moveTemplateToPositionAttemptCount} attempts`);
return;
}
moveTemplateToPositionAttemptCount += 1;
const $element = $("#terminal-marlin-gcode-documentation");
let $anchor;
if (self.mySettings.documentation_position() === "above_settings") {
$("#terminal-marlin-gcode-documentation")
.insertAfter("#terminal-sendpanel");
$anchor = $("#terminal-sendpanel");
$element.insertAfter($anchor);
} else {
$("#term")
.append($("#terminal-marlin-gcode-documentation"));
$anchor = $("#term");
$anchor.append($element);
}
if (!$anchor.length) {
console.warn(
`Anchor for Marlin GCode documentation was not ` +
`present, will try again in 1s - tried ` +
`${moveTemplateToPositionAttemptCount} times`);
setTimeout(() => {
self.moveTemplateToPosition();
}, 1000);
}
};

Expand Down Expand Up @@ -578,7 +601,12 @@ $(function() {
self.loadSettings();
self.onDocumentationPositionChange = ko.computed(() => {
self.mySettings.documentation_position();
self.moveTemplateToPosition();
// Add a delay, since some times it's moved to the end of the
// page
// See https://github.com/costas-basdekis/MarlinGcodeDocumentation/issues/21
setTimeout(() => {
self.moveTemplateToPosition();
}, 0);
});
self.onExplainSentCommandsChanged = ko.computed(() => {
$("#terminal-output").toggleClass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,35 @@ $(function () {

self.settingsViewModel = _parameters[0];
self.settingsViewModel.marlinGcodeDocumentation = self;
self.gcodeParser = new GcodeParser();
self.gcodeParser = new GcodeParser(); // Try multiple times to put it in the right place, since some times
// it's moved to the end of the page
// See https://github.com/costas-basdekis/MarlinGcodeDocumentation/issues/21

var moveTemplateToPositionAttemptCount = 0;

self.moveTemplateToPosition = function () {
if (moveTemplateToPositionAttemptCount >= 5) {
console.error("Could not find anchor for Marlin GCode documentation " + "- aborting after " + "".concat(moveTemplateToPositionAttemptCount, " attempts"));
return;
}

moveTemplateToPositionAttemptCount += 1;
var $element = $("#terminal-marlin-gcode-documentation");
var $anchor;

if (self.mySettings.documentation_position() === "above_settings") {
$("#terminal-marlin-gcode-documentation").insertAfter("#terminal-sendpanel");
$anchor = $("#terminal-sendpanel");
$element.insertAfter($anchor);
} else {
$("#term").append($("#terminal-marlin-gcode-documentation"));
$anchor = $("#term");
$anchor.append($element);
}

if (!$anchor.length) {
console.warn("Anchor for Marlin GCode documentation was not " + "present, will try again in 1s - tried " + "".concat(moveTemplateToPositionAttemptCount, " times"));
setTimeout(function () {
self.moveTemplateToPosition();
}, 1000);
}
}; // Since the terminal VM is bound on `value`, we would only get an
// update on blur, not after the user types. With this, we get it when
Expand Down Expand Up @@ -770,8 +792,13 @@ $(function () {
self.onBeforeBinding = function () {
self.loadSettings();
self.onDocumentationPositionChange = ko.computed(function () {
self.mySettings.documentation_position();
self.moveTemplateToPosition();
self.mySettings.documentation_position(); // Add a delay, since some times it's moved to the end of the
// page
// See https://github.com/costas-basdekis/MarlinGcodeDocumentation/issues/21

setTimeout(function () {
self.moveTemplateToPosition();
}, 0);
});
self.onExplainSentCommandsChanged = ko.computed(function () {
$("#terminal-output").toggleClass("explain-sent-commands", self.mySettings.explain_sent_commands());
Expand Down

0 comments on commit af22c90

Please sign in to comment.