81 lines
1.6 KiB
JavaScript
81 lines
1.6 KiB
JavaScript
/*
|
|
|
|
Copyright (c) 2020, 2023, The Unified Company.
|
|
|
|
This code is part of Unify.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE,
|
|
as published by the Free Software Foundation.
|
|
See the GNU AFFERO GENERAL PUBLIC LICENSE, for more details.
|
|
|
|
https://unifyjs.org
|
|
|
|
*/
|
|
|
|
export default class codePreview{
|
|
|
|
constructor( application ) {
|
|
|
|
return this.createPreviewApplication( application );
|
|
|
|
}
|
|
|
|
createPreviewApplication( app ) {
|
|
|
|
// Create those light blue preview applications on the right side of the code blocks
|
|
var id = app.selector;
|
|
var element = document.querySelector( id );
|
|
|
|
if( element && element.children.length == 0 ) {
|
|
|
|
this.stylePreviewApplication( element, id );
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
stylePreviewApplication( element, id ) {
|
|
|
|
var examplePre = element.previousElementSibling;
|
|
|
|
if( examplePre && examplePre.firstChild ) {
|
|
|
|
var codeElement = examplePre.firstChild;
|
|
|
|
codeElement.className = codeElement.className + " halfCodeElement";
|
|
|
|
examplePre.className = "examplePre";
|
|
|
|
element.remove();
|
|
|
|
var examplePanel = document.createElement("div");
|
|
|
|
examplePanel.className = "examplePanel";
|
|
|
|
examplePanel.id = id.replace("#", "").replace(".", "");
|
|
|
|
|
|
examplePre.appendChild( examplePanel );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
createPreviewLabel( element ) {
|
|
|
|
var previewLabel = document.createElement("div");
|
|
|
|
previewLabel.className = "previewLabel";
|
|
|
|
previewLabel.innerHTML = "preview";
|
|
|
|
element.appendChild( previewLabel );
|
|
|
|
}
|
|
|
|
}
|
|
|