// add here the end of the url which shall not be displayed
var blacklist=
[
'home.html',
'someOtherURL'
];
var useCustomHighlight=false; //true or false
var defaultLinks=
[
{
title: 'Get Started',
address: "start.html"
},
{
title: 'Connect to Web',
address: "connect.html"
},
{
title: 'Keypad Shortcuts',
address: "keypad.html"
},
{
title: 'Opera Help',
address: "index.html"
}
];
(function()
{
if (!navigator.globalhistory)
{
navigator.globalhistory = new Array(10);
for (var i = 0; i<navigator.globalhistory.length; i++)
{
var item = new Object();
item.popularity = Math.round(Math.random()*1000000);
item.address = 'http://www.opera.com';
item.title = 'item ' + i;
item.accessed = Math.round(Math.random()*1000000);
navigator.globalhistory[i] = item;
}
navigator.globalhistory[navigator.globalhistory.length]=
{
popularity : 0.00001,
address : 'home.html',
title : 'home page help',
accessed : Math.round(Math.random()*1000000)
}
}
})()
var Highlighter=function()
{
var styleRules={};
var styleStates=['basic', 'highlighted'];
var defaultClasses=arguments[0].classes;
var propertiesToChange=arguments[0].styleRules;
var propertiesToChangeJS=[];
var container=null;
var cssToJs=function(string)
{
return string.replace(/-[a-z]/, function(match){return match.slice(1).toUpperCase()});
}
var createJSProperties=function()
{
var pointer='', i=0;
propertiesToChangeJS=[];
for(; pointer=propertiesToChange[i]; i++)
{
propertiesToChangeJS[i]=cssToJs(pointer);
}
}
var readOutStyle=function(classNameElement, classNameState)
{
var li=container.appendChild(document.createElement('li'));
li.appendChild(document.createTextNode('text'));
li.className=classNameElement+(classNameState=='basic'?'':' '+classNameState);
var styles=window.getComputedStyle(li, null), styleProp='', i=0;
var stylePointer=styleRules[classNameElement][classNameState]={};
for( ; styleProp=propertiesToChange[i]; i++)
{
stylePointer[styleProp]=styles.getPropertyValue(styleProp);
}
}
this.readStyleRules=function()
{
styleRules={};
container=document.createElement('ul');
var className='', i=0;
for( ; className=defaultClasses[i]; i++)
{
container.innerHTML='';
styleRules[className]={};
readOutStyle(className, styleStates[0]);
readOutStyle(className, styleStates[1]);
}
container=null;
}
this.onfocus=function()
{
var style=this.parentNode.style;
var _styleRules=styleRules[this.parentNode.className].highlighted;
var pointer='', i=0;
for(i=0; pointer=propertiesToChange[i]; i++)
{
style[cssToJs(pointer)]=_styleRules[pointer];
}
}
this.onblur=function()
{
var style=this.parentNode.style;
var _styleRules=styleRules[this.parentNode.className].basic;
var pointer='', i=0;
for(i=0; pointer=propertiesToChange[i]; i++)
{
style[cssToJs(pointer)]=_styleRules[pointer];
}
}
createJSProperties();
}
var createLink=function(pointer)
{
var li=document.createElement('li'), a=null, b=null;
li.className='default';
a=li.appendChild(document.createElement('a'));
a.className='snc';
a.href=pointer.address;
if(useCustomHighlight)
{
a.addEventListener('focus', highlighter.onfocus, false);
a.addEventListener('blur', highlighter.onblur, false);
li.appendChild(document.createTextNode(getLocalizedString(pointer.title)));
}
else
{
a.appendChild(document.createTextNode(getLocalizedString(pointer.title)));
}
return li;
}
var initDocument=function()
{
setLanguageStrings();
if(useCustomHighlight)
{
window['highlighter']=new Highlighter
(
{
classes:['default'],
styleRules:['background', 'color', 'border-bottom']
}
);
highlighter.readStyleRules();
}
// cache reference to the globalhistory object
// NOTE: It is only possible to access globalhistory from localhost!
// globalhistory looks like an array, but is not derived from the Array class, therefore it is
// necessary to copy its contents to a true array to manipulate them. Note that it is more
// efficient to cache the value of globalhistory.length, although this can potentially change
// during the for loop. If the length increases then this could lead to history items being skipped
// from the final list, but this is acceptable in this use case.
var _history_rough=navigator.globalhistory, _history=[], pointer=null, i=0;
var re_blacklist=[], k=0, blackURL='';
for ( ; blackURL=blacklist[k]; k++)
{
re_blacklist[re_blacklist.length]=
new RegExp(blackURL.replace(/\//g,'\\/').replace(/\./g,'\\.')+'$','');
}
outer: for( ; pointer=_history_rough[i]; i++)
{
for(k=0;blackURL=re_blacklist[k];k++)
{
if(blackURL.test(pointer.address)) continue outer;
}
_history[_history.length]=
{
title: pointer.title,
address: pointer.address,
accessed: pointer.accessed,
popularity: pointer.popularity
}
}
// Note that 'popularity' is based on a running average of the times between accesses so
// the lower it is the higher the item should be on the list!
_history.sort(function(a,b){return a.popularity- b.popularity});
var ol=document.getElementById('topTen'), li=null, a=null, b=null;
for( i=0; (pointer=_history[i]) && i<10; i++)
{
ol.appendChild(createLink(pointer));
}
ol=document.getElementById('list');
for( i=0; pointer=defaultLinks[i]; i++)
{
ol.appendChild(createLink(pointer));
}
document.getElementsByTagName('input')[0].focus();
fixDocWidth();
}
onload=function()
{
getLanguageStrings(navigator.browserLanguage, initDocument);
}
function fixDocWidth() {
var b = document.body;
if (b.scrollWidth > b.clientWidth) {
b.style.width = (b.clientWidth) + 'px';
}
}
function gotoForm( form )
{
var url = form.a.value;
if( !url.match( /^[a-z]+:/gi ) )
url = 'http://'+url;
location.href = url;
return false;
}
