I am trying to integrate the ThebeLab javascript library with my web application. Now so far, using their example code, I am able to integrate successfully. ThebeLab uses a Codemirror editor for its input field. And as per ThebeLab's official documentation, we can even customize the Codemirror editor using the configuration settings provided by Codemirror itself.
Now, when I am trying to customize the Codemirror editor using the example provided by ThebeLab, it is not working. It doesn't even throw any kind of error in console either. Even, the example provided by the ThebeLab on their official web page is itself doesn't work.
Now, this issue is already raised and closed on their official GitHub repository. And as per them, the solution is already provided with the newer version(0.5.1) of ThebeLab javascript. And I am also using the newer version which is 0.5.1, but still, it is not working.
This is my code:
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<title>Thebe Lab examples</title>
<!-- Configure and load Thebe !-->
<script type="text/x-thebe-config">
{
bootstrap: true,
requestKernel: true,
kernelOptions: {
name: "python3",
serverSettings: {
"baseUrl": "http://127.0.0.1:8888",
"token": "test-secret"
}
},
codeMirrorConfig: {
theme: "abcdef"
},
}
</script>
<script type="text/javascript" src="https://unpkg.com/thebelab#latest" ></script>
</head>
<body>
<h1>Thebe Lab: using a local server</h1>
<p>This page illustrates how to setup Thebe Lab, using a local Jupyter server as kernel provider. This assumes that you have started the local server as:
<pre>
jupyter notebook --NotebookApp.token=test-secret --NotebookApp.allow_origin='<span id="origin">*</span>'
</pre>
and that it's running on port 8888
</p>
<pre data-executable="true" data-language="python">print("Hello!")</pre>
<script type="text/javascript">
document.getElementById('origin').innerHTML = location.origin;
</script>
</body>
</html>
Kindly help me out here soon. Thank you.
Related
I need to build a cross platform app with multiple windows. So I would like to know how to use html templates in electron.
Based on a similar question and what I've seen, there's no built in html template language in Electron, which is actually great because it allows you to use any other template language.
I'm currently playing with ejs in Electron.
Below is my index.ejs template file:
<html lang="en">
<head>
<title>The Index Page</title>
</head>
<body>
<h1>Welcome, this is the Index page.</h1>
<% if (user) { %>
<h3>Hello there <%= user.name %></h3>
<% } %>
</body>
</html>
And below is a section of my main.js file where the above template is rendered and loaded onto the BrowserWindow. Note that I've left out most of the boilerplate code:
const ejs = require('ejs');
//... Other code
let win = new BrowserWindow({width: 800, height: 600});
//... Other code
// send the data and options to the ejs template
let data = {user: {name: "Jeff"}};
let options = {root: __dirname};
ejs.renderFile('index.ejs', data, options, function (err, str) {
if (err) {
console.log(err);
}
// Load the rendered HTML to the BrowserWindow.
win.loadURL('data:text/html;charset=utf-8,' + encodeURI(str));
});
I'll give some credit to this gist for helping me find the data:text/html;charset=utf-8 part of the url that can be used to load dynamic content.
UPDATE
I'm actually not using this anymore. It's faster to just load the default html and use the native DOM methods. The Electron Quickstart program shows how to do this nicely.
Another option is to do the templating during your build. Here is a simple example using gulp to add nonces to the CSP meta tag and the inline script.
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'nonce-<%= scriptNonce %>';">
<title>Basic Electron App</title>
</head>
<body>
<div id="app"></div>
<script type="application/javascript" nonce=<%= scriptNonce %>>
require('./index.js');
</script>
</body>
</html>
and in gulfile.js add the following to what you already have and make sure this task is included in your pipeline. You can also just update your current html task with the code below.
const template = require('gulp-template');
const uuidv4 = require('uuid/v4');
gulp.task('copy-html', () => {
// Create nonces during the build and pass them to the template for use with inline scripts and styles
const nonceData = {
scriptNonce: new Buffer(uuidv4()).toString('base64'),
styleNonce: new Buffer(uuidv4()).toString('base64')
};
return gulp.src('src/*.html')
.pipe(template(nonceData))
.pipe(gulp.dest('dist/'));
});
This is a very stripped down example. I have a more complete example at https://github.com/NFabrizio/data-entry-electron-app if anyone is interested, though there is still one warning when running the application because one of the packages I am using pulls in react-beautiful-dnd, which adds inline styles but does not currently accept nonces.
I need to initialize the VSS.SDK from a .ts class (outside the html page). I have analyzed some examples from Microsoft and all are initialize under html page.Is it possible to do this outside html page?
You can refer to this link for details: Visual Studio Services Web Extension SDK.
Types
Types of VSS.SDK.js, controls and client services are available in typings/vss.d.ts.
REST Client types for VSTS are available in typings/tfs.d.ts
REST Client and extensibility types for Release Management are available in typings/rmo.d.ts
Using tsd
Although TypeScript declare files do not exist at DefinitelyTyped repo, they can still be used through tsd.
First, make sure that the dependencies are loaded using below
command:
tsd install jquery knockout q --save
Next, run below command to get
vss-web-extension-sdk types added to tsd.d.ts:
tsd link
Finally, add only reference to typings/tsd.d.ts in your
TypeScript files.
Yes, you could to do it outside the html and put it in the JavaScript file or other (e.g. ts), then add the reference to corresponding JS file to the html page.
For example:
VSS.init();
$(document).ready(function () {
VSS.notifyLoadSucceeded();
});
<!DOCTYPE html>
<html>
<head>
<title>Hello word</title>
<meta charset="utf-8" />
<script src="node_modules/vss-web-extension-sdk/lib/VSS.SDK.js"></script>
<script src="Scripts/VSSInit.js"></script>
</head>
<body>
<!--<script type="text/javascript">
VSS.init();
</script>-->
<h1>Hello word</h1>
<!--<script type="text/javascript">
VSS.notifyLoadSucceeded();
</script>-->
</body>
</html>
I have tried several different methods to accomplish this and none have been successful. Ive tried jruby, the rest api for activiti (this does not update the UI and is thus not suited for my purposes), and the mechanize gem. The mechanize gem did not work because of the VAADIN UI that activiti explorer ships with or so I think. I currently have activiti hosted in an iframe in my rails app, and am trying to find a way to communicate between the two. I used the gem like this:
agent= Mechanize.new
agent.redirection_limit= 10
//page is used three times to illustrate different routes taken.
page= agent.get('http://127.0.0.1:8080/activiti-webapp-explorer2-5.18.0/)
page= agent.post('http://127.0.0.1:8080/activiti-webapp-explorer2-5.18.0/ui/APP/2/login',{'username'=>'kermit', 'password'=>'kermit'} )
page=agent.put('http://127.0.0.1:8080/activiti-webapp-explorer2-5.18.0/ui/1/loginHandler',{'username'=>'kermit', 'password'=>'kermit'})
here is a sample response from activiti explorer when mechanize is used:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">html, body {height:100%;margin:0;}</style><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti/favicon.ico" /><link rel="icon" type="image/vnd.microsoft.icon" href="/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti/favicon.ico" /><title>Activiti Explorer</title>
</head>
<body scroll="auto" class="v-generated-body">
<script type="text/javascript">
//<![CDATA[
if(!vaadin || !vaadin.vaadinConfigurations) {
if(!vaadin) { var vaadin = {}}
vaadin.vaadinConfigurations = {};
if (!vaadin.themesLoaded) { vaadin.themesLoaded = {}; }
}
vaadin.vaadinConfigurations["activitiwebappexplorer25180ui-1091631569"] = {appUri:'/activiti-webapp-explorer2-5.18.0/ui', standalone: true, themeUri:"/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti", versionInfo : {vaadinVersion:"6.8.8",applicationVersion:"NONVERSIONED"},"comErrMsg": {"caption":"Communication problem","message" : "Take note of any unsaved data, and <u>click here<\/u> to continue.","url" : null},"authErrMsg": {"caption":"Authentication problem","message" : "Take note of any unsaved data, and <u>click here<\/u> to continue.","url" : null}};
//]]>
</script>
<iframe tabIndex='-1' id='__gwt_historyFrame' style='position:absolute;width:0;height:0;border:0;overflow:hidden;' src='javascript:false'></iframe>
<script language='javascript' src='/activiti-webapp-explorer2-5.18.0/VAADIN/widgetsets/org.activiti.explorer.CustomWidgetset/org.activiti.explorer.CustomWidgetset.nocache.js?1444407987049'></script>
<script type="text/javascript">
//<![CDATA[
if(!vaadin.themesLoaded['activiti']) {
var stylesheet = document.createElement('link');
stylesheet.setAttribute('rel', 'stylesheet');
stylesheet.setAttribute('type', 'text/css');
stylesheet.setAttribute('href', '/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti/styles.css');
document.getElementsByTagName('head')[0].appendChild(stylesheet);
vaadin.themesLoaded['activiti'] = true;
}
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
setTimeout('if (typeof org_activiti_explorer_CustomWidgetset == "undefined") {alert("Failed to load the widgetset: /activiti-webapp-explorer2-5.18.0/VAADIN/widgetsets/org.activiti.explorer.CustomWidgetset/org.activiti.explorer.CustomWidgetset.nocache.js?1444407987049")};',15000);
//]]>
</script>
<div id="activitiwebappexplorer25180ui-1091631569" class="v-app v-theme-activiti v-app-ExplorerApp" ><div class="v-app-loading"></div></div>
<noscript>You have to enable javascript in your browser to use an application built with Vaadin.</noscript></body>
</html>
I have tried all of the possible url's I could see on the UI, but none of them work. I have tried all of post, get, and put with each of these three urls .I found these URL's by looking at the loaded page, and noticing that they are nested iframes. Any help in seeing the feasiblity of the mechanize gem would be great, as feel as if this would be an easy fix to my problem. As a side note, I have changed the tomcat properties to allow for CORS requests. Also, http requests from rails to activiti explorer do not work either, so that form of communication is also out.
Also if you are familiar with activiti- I have edited the authenticate method in default login handler to try and parse http requests to get the username and password to login automatically. This however returns the same html code as printed above. Any help would be greatly appreciated. Here is a sample of the http requests I make from rails:
auth = {:userid=> "kermit", :password => "kermit"}
puts HTTParty.get("http://activiti.testing.com:8080/activiti-webapp-explorer2-5.18.0/", :content_type => "application/json",
:basic_auth => auth)
I think integrating Activiti Explorer in iframe is not a good idea. Since your username and password are exposed! And the requirements of the frontend are various.
I like Activiti Explorer at first, Modeler is really awesone! But I use Rails and find it hard to customize and integrate Activiti Explorer later. I tried integrate with Activiti REST, while I prefer Activiti Java API for the following reasons:
Activiti REST is a subset of Activiti Java API. eg: SetProcessDefinitionVersionCmd is not availiable in Activiti REST.
Performance concerns. I develop a task web page, but it needs over 10 http requests.
I like Acitivi Modeler and Diagram Viewer. I need Activiti Explorer running and make them work together.
So I develop a gem named jruby_activiti, integrating Activiti Engine, Modeler and Diagram Viewer. All these are availiable in JRuby on Rails! Hope my experiences could help you.
It's been a nightmare to me before I came to know that in order to get jquery ui working in ASP.NET MVC I need to add #Scripts.Render("~/bundles/jqueryui"). Before doing so I kept getting Uncaught error: Undefined is not a function. What I did not understand was why on earth this would happen when I could see the jquery ui file in the sources when inspecting the html source. This is the _Layout.cshtml file:
<!DOCTYPE html>
<html>
<head>
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery.plugins.js"></script>
<script src="~/Scripts/Helpers.js"></script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>#ViewBag.Title</title>
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
</head>
<body>
#RenderBody()
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/jqueryui")//Added later to get it working
#RenderSection("scripts", required: false)
</body>
</html>
In my Helper.js file I have some helper functions that I usually use. One of them is applyDatetimePickerAndFormat that is called on $(document).ready(). Inside that function I have the following code:
$('.txt-date').datepicker({
showAnim: "drop",
changeMonth: true,
changeYear: true,
dateFormat: "dd.mm.yy"
});
If I omit #Scripts.Render("~/bundles/jqueryui") in the _Layout.cshtml I will get the aforementioned error. This code works perfectly with any plain html or web form. So it seems that somehow the document can't see the contents of the jquery-ui file. To make my question concrete:
When I look at the Sources of the the web page I can see jquery-ui-1.8.24.js and it's referenced in the html source. Then why can't the code find jquery-ui functions?
If every java script file has to be specified in the #Scripts.Render then why isn't there any problem with my Helper.js file?
And finally where does this ~/bundles/jqueryui path refer to?
jquery-ui depends on jquery (i.e. it must be defined after jquery) but you have duplicated your files. In the head you have included <script src="~/Scripts/jquery-1.8.2.js"></script> followed by jquery-ui. You then reload jquery at the end of the file using #Scripts.Render("~/bundles/jquery") (Its now after jquery-ui).
Delete the script in the head and it should work. I addition, I recommend you delete jquery.validate and jquery.validate.unobtrusive from the head and use #Scripts.Render("~/bundles/jqueryval") at the end of the file (before #RenderSection..). You can examine these bundles in App_Start\BundleConfig.cs file. There are numerous advantages to using bundles (see Bundling and Minification).
If you are using all these files in every page based on _Layout, you can define your own bundle to includes all files.
You need to define the strategy for your js. I recomend you ot organize your js first and after that separate it to smaller parts. One should be common for all the pages(jQuery in your case) and other scripts for validation should be included only on pages that have some editing fileds etc.
Use DRY principle and read some information about how js works. It helps me a lot some time ago and won't take a lot of time.
I am implementing omniture tags in one of my projects. The omniture tags are being provided by a client. The problem is the web application loads a and the omniture tag is inside that . Now, for some reason the omniture tags are not being fired. I opened the omniture debugger and there are no tags being tracked. For testing purpose I remove the and the omniture tag started working.
Here is the sample of the problem HTML:
<frameset>
<frame id="pageFrame">
#document
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="somediv">
<script type="text/javascript" language="javascript" src="tracking.JS"></script>
<script type="text/javascript">
<!--
console.log("Testing");
s.channel="test";
s.prop50=s.channel+":INTERNET";
s.pageName=s.prop50+":User name";
//-->
</script>
<script type="text/javascript" language="javascript" src="morescript.JS"></script>
</div>
</body>
</html>
</frame>
</frameset>
Are there any known inherent issues with Omniture inside ? Any ideas?
Thanks.
The debugger often does not display image requests in frames. I would recommend in this instance to use a packet monitor, such as Chrome's Network tab in Developer Tools or HTTPFox.
The latest version of the debugger may prove useful as well, however your mileage may vary in respect to frames.