Using jQueries detach method to move the webcam stream

No template file is required anymore
This commit is contained in:
malnvenshorn 2018-01-13 14:09:23 +01:00
parent 030b270a33
commit d27517218f
3 changed files with 9 additions and 44 deletions

View File

@ -22,7 +22,7 @@ class WebcamTabPlugin(octoprint.plugin.AssetPlugin,
def get_template_configs(self):
return [
dict(type="tab", name="Webcam")
dict(type="tab", name="Webcam", template=None)
]
# Softwareupdate hook

View File

@ -51,14 +51,15 @@ $(function() {
}
};
self.onStartup = function() {
var container = $("#control #webcam_container");
if (container.length) {
var hint = container.next();
if (hint.attr("data-bind") === "visible: keycontrolPossible") {
hint.remove();
self.onAfterBinding = function() {
var tab = $("#tab_plugin_webcamtab");
var webcam = $("#webcam_container");
if (webcam) {
var hint = webcam.next();
tab.append(webcam.detach());
if (hint && hint.attr("data-bind") === "visible: keycontrolPossible") {
tab.append(hint.detach());
}
container.remove();
}
};
};

View File

@ -1,36 +0,0 @@
<div id="webcam_container" tabindex="0" data-bind="event: { keydown: control.onKeyDown, mouseover: control.onMouseOver, mouseout: control.onMouseOut, focus: control.onFocus }">
<div class="nowebcam" data-bind="visible: !control.webcamLoaded()">
<div class="text webcam_loading" data-bind="visible: !control.webcamLoaded() && !control.webcamError()">
<p><strong>{{ _('Webcam stream loading...') }}</strong></p>
</div>
<div class="text webcam_error" data-bind="visible: !control.webcamLoaded() && control.webcamError()">
<p><strong>{{ _('Webcam stream not loaded') }}</strong></p>
<p><small>{{ _('It might not be correctly configured. You can change the URL of the stream under "Settings" > "Webcam & Timelapse" > "Stream URL". If you don\'t have a webcam just set the URL to an empty value.') }}</small></p>
</div>
</div>
<div id="webcam_rotator" data-bind="css: { webcam_rotated: control.settings.webcam_rotate90(), webcam_unrotated: !control.settings.webcam_rotate90() }">
<div class="webcam_fixed_ratio" data-bind="css: control.webcamRatioClass">
<div class="webcam_fixed_ratio_inner">
<img id="webcam_image" data-bind="css: { flipH: control.settings.webcam_flipH(), flipV: control.settings.webcam_flipV() }, event: { load: control.onWebcamLoaded, error: control.onWebcamErrored }, visible: !control.webcamError()">
</div>
</div>
</div>
<div class="keycontrol_overlay" data-bind="visible: control.showKeycontrols">
<div class="keycontrol_overlay_heading">{{ _("Keyboard controls active") }} <a href="#" data-bind="click: control.toggleKeycontrolHelp"><i data-bind="css: { 'icon-chevron-down': !control.keycontrolHelpActive(), 'icon-chevron-up': control.keycontrolHelpActive() }"></i></a></div>
<div data-bind="visible: control.keycontrolHelpActive">
<div class="keycontrol_overlay_column">
<kbd>&rarr;</kbd> / <kbd>&larr;</kbd>: {{ _("X Axis") }} +/-<br>
<kbd>&uarr;</kbd> / <kbd>&darr;</kbd>: {{ _("Y Axis") }} +/-<br>
<kbd>W</kbd>, <kbd>{{ _("Page&uarr;") }}</kbd> / <kbd>S</kbd>, <kbd>{{ _("Page&darr;") }}</kbd>: {{ _("Z Axis") }} +/-
</div>
<div class="keycontrol_overlay_column">
<kbd>Home</kbd>: {{ _("Home X/Y") }}<br>
<kbd>End</kbd>: {{ _("Home Z") }}<br>
<kbd>1</kbd>, <kbd>2</kbd>, <kbd>3</kbd>, <kbd>4</kbd>: {{ _("Stepsize") }} 0.1, 1, 10, 100mm
</div>
</div>
</div>
</div>
<div data-bind="visible: control.keycontrolPossible">
<small class="muted">{{ _("Hint: If you move your mouse over the picture, you enter keyboard control mode.") }}</small>
</div>