added possibility to add JS functions directly to page

This commit is contained in:
Peter Schojer 2008-06-30 07:10:08 +00:00
parent b1f895eed8
commit 7ad83b7d4d
2 changed files with 28 additions and 0 deletions

View File

@ -120,6 +120,13 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext
//start inline javascript block
ostr << "<script type=\"text/javascript\">";
ostr << "var global={};"; //global var to store values!
const std::vector<std::string>& fcts = pPage->dynamicFunctions();
std::vector<std::string>::const_iterator itF = fcts.begin();
for (; itF != fcts.end(); ++itF)
{
ostr << *itF << std::endl;
}
ostr << "Ext.onReady(function() {";
ostr << "var " << VAR_LOCALTMP << ";"; // tmp variable needed for table renderer
ostr << "Ext.QuickTips.init();";

View File

@ -93,6 +93,14 @@ public:
void handleForm(const std::string& field, const std::string& value);
/// Dummy implementation
void addDynamicFunction(const std::string& jsCode);
/// Adds a JavaScript function to the page. Static functions should be written to a JS file
/// and included via the ResourceManager, only dynamic fucntions (ie. functions that are generated
/// during run-time) should be included here
const std::vector<std::string>& dynamicFunctions() const;
/// Returns all dynamic functions
protected:
Page(const std::string& name, const std::type_info& type);
@ -107,6 +115,7 @@ protected:
private:
std::string _text;
ResourceManager _rm;
std::vector<std::string> _jsCode;
};
@ -131,6 +140,18 @@ inline void Page::handleForm(const std::string& , const std::string& )
}
inline void Page::addDynamicFunction(const std::string& jsCode)
{
_jsCode.push_back(jsCode);
}
inline const std::vector<std::string>& Page::dynamicFunctions() const
{
return _jsCode;
}
} } // namespace Poco::WebWidgets