Monday, 9 July 2012

left:-99999999px

*.accessibilityHeader {
   left:-99999999px;
   position:absolute;
}
I put the above in a style sheet the other day and only just noticed that there where no horizontal scroll bars appearing in FireFox.  Fortunately, it didn't take too long to find, apparently it's too big a number, what's up with that!??!

Monday, 20 February 2012

Escaping quotes in XSLT for text used in JavaScript or JSON

XSLT template for formatting javascript safe strings by escaping double quote char " i.e. " or " with escaped version \"

Tuesday, 31 January 2012

IE7 and hasLayout


All these years I've assumed that {zoom:100%;} and {height:1%;} where essentially the same, forcing an element to have layout (hasLayout property). After a very unproductive morning, being made to look foolish by IE7, I finally in desperation changed the zoom directive to height and my clear float hack started working. Note to self, go round the country and personally upgrade all IE6/7 versions to IE9!

Sunday, 8 May 2011

Dynamcially adding style

Dynamically add style to a page...

var style = "body{color:#666;}";
var s = document.createElement('style');
s.setAttribute("type", "text/css");
if (s.styleSheet) { // IE
s.styleSheet.cssText = style;
} else {
var stxt = document.createTextNode(style);
s.appendChild( stxt );
}
document.getElementsByTagName('head')[0].appendChild(s);

Remember to minify the style text using something like http://refresh-sf.com/yui/

Monday, 4 April 2011

'require': no such file to load -- sqlite3/sqlite3_native (LoadError)

When running "rails server" I was getting the following error...
'require': no such file to load -- sqlite3/sqlite3_native (LoadError)


Banging my head on the desk for ages with this one. Then realised the default Aptana workspace name contained white space chars! Remove these and all is fine.

Shame on me!

Friday, 27 August 2010

Chrome extension, accessing extension variables from scripts

chrome logo
Just went all around the houses trying to access variables from a script running within a web page. In actual fact it's quite easy. You need two things, a background pages and an options page to administer your options. So the first thing you need to do is make sure you have a reference to background and options in your extention manifest...

...
"background_page": "background.html",
"options_page": "options.html",
...


From within your script you can then access variables using...

chrome.extension.sendRequest({action:"getItem",item:"somekey"}, function(response) {
var myvar = response.value
console.log("somekey:"+myvar);
});


Background page should look something like this...

<html>
<head><title>background</title>
<script type="text/javascript">
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
switch(request.action){
case "clear" :
localStorage.clear();
sendResponse({message:"Thanks, localStorage has been cleared"});
break;
case "getItem" :
var value = localStorage.getItem(request.item);
sendResponse({value:value,message:"value returned from background.html"});
break;
case "getItems" :
var value = {};
for (var i=0;i value[request.items[i]] = localStorage.getItem(request.items[i])
}
sendResponse({value:value,message:"value returned from background.html"});
break;
case "setItem" :
localStorage.setItem(request.item,request.value);
sendResponse({message:"Thanks, your update has been saved"});
break;
case "setItems" :
for (name in request.items){
localStorage.setItem(name,request.items[name]);
}
sendResponse({message:"Thanks, your updates have been saved"});
break;
}
});
</script>
</head>
</html>


The above will give you a simple way to store variables.

Your options page needs to use the background.html to save variables to
<html> 
<head>
<title>Extention options</title>
<script type="text/javascript">
window.myOptions = {
init:function(){

chrome.extension.sendRequest({action:"getItem",item:"optionOne"}, function(response) {
console.log("!responce.value"+response.value);
document.getElementById("optionOne").checked = (response.value=="off") ? false : true;
});
chrome.extension.sendRequest({action:"getItem",item:"optionTwo"}, function(response) {
console.log("!responce.value"+response.value);
document.getElementById("optionTwo").checked = (response.value=="off") ? false : true;
});

document.getElementById("optionOne").addEventListener("click",function(){
myOptions.change("optionOne");
},false)
document.getElementById("optionTwo").addEventListener("click",function(){
myOptions.change("optionTwo");
},false)
document.getElementById("resetButton").addEventListener("click",function(){
myOptions.reset();
},false)
}
,change:function(key){
var value = document.getElementById(key).checked ? "on" : "off";
chrome.extension.sendRequest({action:"setItem",item:key,value:value}, function(response) {
console.log("!responce.message"+response.message);
var m = (value == "off")? "disabled" : "enabled"
document.getElementById("settings").innerHTML = key + " has been "+ m;
});
}
,reset:function(){
chrome.extension.sendRequest({action:"clear"}, function(response) {
location.reload();
});
}
}
window.addEventListener("load", window.myOptions.init, false)
</script>

</head>
<body>
<form>
<h1>Options</h1>
<p>
Intro text
</p>
<p>
<span class="option">
<input type="checkbox" name="optionOne" id="optionOne" value="on" />
</span>
<label for="optionOne" class="wiki">Enable option one</label>
</p>
<p>
<span class="option">
<input type="checkbox" name="optionTwo" id="optionTwo" value="on" />
</span>
<label for="optionTwo" class="wiki">Enable option two</label>
</p>
<p style="height:1.3em;color:red" class="alert">
<span id="settings"></span>
</p>
<p>
<input type="button" id="resetButton" value="Reset default options"/>
</p>
</form>

</body>

</html>

Thursday, 12 August 2010

Math.random()

Note to self... for a three number 100 - 999



var min = 100
var max = 1000
Math.floor(Math.random()*(max-min)+min)
 

Note: the opinions on this page don't represent that of my employer in anyway. And, actually only vaguely represent my opinions on the date of publication. (Unlike Ms T, I am very much for turning)