Hi I'm using the syntax highlighter found here: http://code.google.com/p/syntaxhighlighter/
I have a page wherte it works fine:
<div id="codeArea">
<pre class="brush:csharp">
var customers = new Customer().GetCustomerList().AsEnumerable()
.Where(c => c.CustomerID < 5);
</pre>
However, I'm trying to load different snippets in using jQuery:
$("#sqoList").change(function () {
var toLoad = $("#sqoList").val();
$("#codeArea").load('/SQO/' + toLoad + "Example");
//I tried running again after the load but still no joy.
//SyntaxHighlighter.config.clipboardSwf = '../../Scripts/clipboard.swf';
//SyntaxHighlighter.all();
});
I noticed the first time the form is loaded in using Firebug That a lot of html is added to the 'codeArea' <div> after running the SyntaxHighighter.
This is not rendered when I load using jQuery.
Does anyone know how to force the extra html to render again?
Thanks
http://code.google.com/p/syntaxhighlighter/wiki/Usage
add a Name attribute to the pre tag
<pre name="code" class="brush:csharp">
var customers = new Customer().GetCustomerList().AsEnumerable().Where(c =>
c.CustomerID < 5);
</pre>
and when in JS you write:
dp.SyntaxHighlighter.HighlightAll('code');
it gets transformed.
Related
I'm trying to insert an iframe into a div with the UTM parameters of the parent URL. In order to achieve this, I have a simple trigger based on page URL like this:
and then for the tag, I have this:
The code is the following, I have removed the iframe url:
<script type="text/javascript">
console.log('insert iframe');
var iframeurl = 'xxx';
var params = window.location.search.replace('?','');
var thisScript = document.scripts[document.scripts.length - 1];
var iframe = document.createElement('iframe');
iframe.setAttribute('src', iframeurl +'&'+ params);
iframe.setAttribute('width', '100%');
iframe.setAttribute('height', '700px');
iframe.setAttribute('type', 'text/html');
iframe.setAttribute('frameborder', 0);
iframe.setAttribute('allowTransparency', 'true');
iframe.style.border = '0';
getRef = document.getElementById("contest_iframe");
parentDiv = getRef.parentNode;
parentDiv.insertBefore(iframe, getRef);
</script>
When I execute the code in my browser console, it works. When I execute the Tag Assistant it works but when I try it in production, it doesn't work, the tag is not fired.
This is what I see in the assistant:
Everything seems to be ok, I don't understand why it doesn't work, I probably have missed something somewhere.
Do you have any idea?
Thanks
Laurent
Have you tried making it an anonymous, self-executing function?
(function(){
//your code
})();
I got error message when trying to run existing meteor project.
$meteor
=> Started proxy.
=> Started MongoDB.
=> Errors prevented startup:
While building the application:
client/coinmx.html:169: TRIPLE template tag is not allowed in an HTML attribute
...title="Totals: {{{get...
^
In Meteor 0.8, it's possible to return a Javascript object which is directly rendered into HTML attributes versus earlier versions, where you had to render it yourself.
Old version:
<input name={{name}} title={{title}}>
helpers:
Template.foo.name = "fooName";
Template.foo.title = "fooTitle";
New version:
<input {{attributes}}>
helpers:
Template.foo.attributes = {
name: "fooName",
title: "fooTitle"
};
All of these can be functions, and reactive, etc. Because the object is rendered directly into attributes, there is no need for you to SafeString some manually rendered content as before. This is the recommended way to go if need to render HTML attributes.
See also the following for how conditional attributes work under this scheme:
https://github.com/meteor/meteor/wiki/Using-Blaze#conditional-attributes-with-no-value-eg-checked-selected
The error is pretty much explanatory: you cannot use {{{something}}} inside a HTML attribute, you need to use {{something}} instead. Depending on what the something is (it's not known from your question as you didn't provide the code), that's either all you need to do, or you can achieve similar functionality by returning new Handlebars.SafeString("result") from your helper instead of just "result". However, if you do, you need to be super sure that the thing you'll return won't break the HTML structure.
Hugo's answer above gave me the missing piece I needed for the same issue-- triple stashes in 0.8 no longer supported. Here is an example that hopefully helps.
Where you might have had {{{resolve}}} in your template, you would now do:
<template name='thing'>
<ol>
{{#each all}}
{{resolve}}
{{/each}}
</ol>
<template>
The helper code then makes use of Spacebars.SafeString which looks to be preferred with Blaze:
Template.thing.helpers({
all: function () {
return Things.find();
},
resolve: function () {
var result = "<li>";
for (var i = 0; i < this.arrayOfClassNames.length; ++i)
result += <'div class='" + this.arrayOfClassNames[i] + "'></div>";
result += "</li>";
return new Spacebars.SafeString(result);
}
});
The key here is to return the 'new Spacebars.SafeString(result)' to wrap your HTML (which must be well formed).
Is it possible to render Javascript in nested mustache.js templates as follows?
myApp.mustache:
{{#myapp}}
{{>userApp}}
{{/myapp}}
userApp.mustache:
{{#user}}
<script>
$(function () {
$("a[id='a_popover_{{username}}']").popover()
})
</script>
{{/user}}
The templates render correctly with pystache (Python's mustache library), but mustache.js, handlebars.js, ICanHaz.js, and ICanHandlebarz.js all complain something like #user was not closed properly.
Pretty sure the </script> bit is the problem, the browser sees that and parses it as end of the template script. Try escaping it like so: <\/script>
I was also stuck into similar issue, what ended up was creating a new script element, because even if the javascript code was rendered , is was not executed after appending into the body, it acts like string.
$('script:last').html('alert("ok !")'); // won't work
sample code for my case:
var render = Mustache.to_html(template, data_sources);
var sc = document.createElement('script');
sc.innerHTML = render;
var p_div = document.getElementById('template_wrap_div').parentNode;
p_div.innerHTML = "";
p_div.appendChild(sc);
Hope that gives some idea and help.
I have been asked to extract info by an academic colleague from a website where I need to link the content of a webpage in a table - not too hard with the contents of a text file which is only reacheable (as far as I can tell) by clicking on a javascript link... e.g.
<a id="tk1" href="javascript:__doPostBack('tk1$ContentPlaceHolder1$grid$tk$OpenFileButton','')">
The table is conveniently inside a table with id='tk1' which is nice... but how do I follow the link which pulls the text file.
Ideally I'd like to do this in R... I can grab the relevant table in text format by saying
u <- the url of interest...
library(XML)
tables = readHTMLTable(u)
interestingTable <- tables[grep('tk1', names(tables))]
And this will give the text in the table, but how do I grab the html for that particular table? and how do I "click" on the button and get the text file behind it?
I note that there is a form with massive hidden values - the site appears to be asp.net driven and uses impenetrable URLs.
Many thanks!
This is somewhat tricky, and not fully integrated in R, but some system()-fiddling will get you started.
Download and install phantom javascript: http://code.google.com/p/phantomjs/
Check the short script on http://menne-biomed.de/uni/JavaButton.html, which emulates your case. When you click the javascript anchor, it redirects http://cran.at.r-project.org/ via doPostBack(inaccessibleJavascriptVar).
Save the following script locally as javabutton.js
var page = new WebPage();
page.open('http://www.menne-biomed.de/uni/JavaButton.html', function (status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
var ua = page.evaluate(function () {
var t = document.getElementById('tk1').href;
var re = new RegExp('\((.*)\)');
return eval(re.exec(t)[1]);
});
console.log(ua);// Outputs http://cran.at.r-project.org/
}
phantom.exit();
});
With phantomjs on path, call
phantomjs javabutton.js
The link will be displayed on the console. Use any method to get it into Rcurl.
Not elegant, but maybe someones wraps phantomjs into R one day. In case the link to JaveButton.html should be lost, here it is as code.
<!DOCTYPE html >
<head>
<script>
inaccesibleJavascriptVar = 'http://' + 'cran.at.r-project.org/';
function doPostBack(myref)
{
window.location.href= myref;
return false;
}
</script>
</head>
<body>
<a id="tk1" href="javascript:doPostBack(inaccesibleJavascriptVar)" >Click here</a>
</body>
</html>
Have a look at the RCurl package:
http://www.omegahat.org/RCurl/
Okay I'm trying to add comments and reactions count just like what you would normally see on some wordpress blogs like http://johntwang.com/blog/ where on the left top of each post there is ** comment and * reactions*
(source: windows7hacker.com)
My problem is I can't find the disqus's documentation, where hopefully there is some method I can call to return me the number of reactions and comments. Also if I use the wordpress default method
<?php comments_popup_link ('zero','one','more','CSSclass','none');?>
it only displays "Comments" not even the comment's number count on the main page.
How can I add reaction and comment count with disqus plugin ?
edit:
well my site is http://www.windows7hacker.com/ I don't know how I suppose to add comments count at first place. But right now if I use the wordpress method, it will return me only comments, which is exactlly one of the problem they have described in their help page
(source: windows7hacker.com)
I've tired to check the comment count option still doesn't work :(
I've never used the wordpress plugin. But I have used the JS only version.
You can get JS only Disqus working pretty quickly by doing the following.
Add this JS to your page.
<script type="text/javascript">
//<![CDATA[
(function() {
var links = document.getElementsByTagName('a');
var query = '?';
for(var i = 0; i < links.length; i++) {
if(links[i].href.indexOf('#disqus_thread') >= 0) {
query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
}
}
document.write('<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/ohu/get_num_replies.js' + query + '"></' + 'script>');
})();
//]]>
</script>
Add this code to where you want the comments to display (so probably underneath the post text)
<div id="disqus_thread"></div><script type="text/javascript" src="http://disqus.com/forums/ohu/embed.js"></script><noscript>View the discussion thread.</noscript>blog comments powered by <span class="logo-disqus">Disqus</span>
Finally - to get the comment count to show. All you need to do is append #disqus_thread to your permalink URL in any tag... so for example...
Comments
would become...
Comments
And that will replace "Comments" with x Comments... (x being the number of comments for that post).
I'm a little rusty with wordpress templates so I'm not 100% sure where you would put all of that. But if you have anymore questions I can try to help out.
I know there is a wordpress plugin for disqus. However if you want to set it up just using plain old js, disqus provides a snippet for you to use in their Universal Instructions page
http://disqus.com/comments/universal/YOURDISQUSACCOUNT
This is the comment snippet they provide
<script type="text/javascript">
//<![CDATA[
(function() {
var links = document.getElementsByTagName('a');
var query = '?';
for(var i = 0; i < links.length; i++) {
if(links[i].href.indexOf('#disqus_thread') >= 0) {
query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
}
}
document.write('<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/YOURDISQUSACCOUNT/get_num_replies.js' + query + '"></' + 'script>');
})();
//]]>
</script>
The Instructions default page is here http://disqus.com/comments/install/YOURDISQUSACCOUNT
This page is actually quite hard to get to...