Browse Source

bootstrip js

master
Odilitime 2 years ago
parent
commit
fa64b836e8

+ 24
- 0
src/interfaces/components/DocumentComponent.cpp View File

@@ -53,6 +53,8 @@ size_t getNumberOfLines(std::string text) {
return lines;
}

#include <fstream>

DocumentComponent::DocumentComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight) : MultiComponent(rawX, rawY, rawWidth, rawHeight, passedWindowWidth, passedWindowHeight) {
//std::cout << "DocumentComponent::DocumentComponent" << std::endl;

@@ -73,6 +75,21 @@ DocumentComponent::DocumentComponent(const float rawX, const float rawY, const f
height = 0;
}

std::ifstream fin("res/ntr_bootstrap.js");
std::stringstream buffer;
buffer << fin.rdbuf();
std::string bootstrap_js = buffer.str();
if (bootstrap_js == "") {
std::cout << "DocumentComponent::DocumentComponent - ERROR: Could not load res/ntr_bootstrap.js" << std::endl;
} else {
//std::cout << "DocumentComponent::DocumentComponent - Loaded [" << bootstrap_js << "] ntr_bootstrap.js\n";
JSParser jsparser;
this->bootstrapScript = std::make_shared<JavaScript>();
this->bootstrapScript->tokens = jsparser.getTokens(bootstrap_js);
jsparser.parseTokens(this->bootstrapScript->tokens, &this->bootstrapScript->rootScope);
//this->bootstrapScript = jsparser.parse(bootstrap_js);
}

//std::cout << "DocumentComponent::DocumentComponent - our size" << static_cast<int>(width) << "x" << static_cast<int>(height) << std::endl;
onMousemove=[this](int passedX, int passedY) {
// set hover component
@@ -405,6 +422,13 @@ void DocumentComponent::setDOM(const std::shared_ptr<Node> rootNode) {
//mainScript.clear();
mainScript = std::make_shared<JavaScript>();

if (this->bootstrapScript) {
JSParser jsparser;
jsparser.append(mainScript, this->bootstrapScript);
} else {
std::cout << "DocumentComponent::setDOM - no bootstrap JS loaded\n";
}

// reset scroll position
//transformMatrix[13] = 2;
//transformMatrixDirty = true;

+ 1
- 0
src/interfaces/components/DocumentComponent.h View File

@@ -49,6 +49,7 @@ public:
bool transformMatrixDirty = true;
std::function<void(std::string url)> onBeforeLoad = nullptr;
std::shared_ptr<JavaScript> mainScript = nullptr;
std::shared_ptr<JavaScript> bootstrapScript = nullptr;
};



Loading…
Cancel
Save