Retrobrown.js
From Sonic Retro
Revision as of 22:45, 21 June 2015 by Scarred Sun (talk | contribs) (Created page with "var retro_menu_objs = []; jQuery(window).unbind('resize').resize(function(){ for (var i = 0; i < retro_menu_objs.length; i++) if (typeof(retro_menu_objs[i]) == "objec...")
Revision as of 22:45, 21 June 2015 by Scarred Sun (talk | contribs) (Created page with "var retro_menu_objs = []; jQuery(window).unbind('resize').resize(function(){ for (var i = 0; i < retro_menu_objs.length; i++) if (typeof(retro_menu_objs[i]) == "objec...")
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
var retro_menu_objs = [];
jQuery(window).unbind('resize').resize(function(){
for (var i = 0; i < retro_menu_objs.length; i++)
if (typeof(retro_menu_objs[i]) == "object")
if (typeof(retro_menu_objs[i].resize) == "function")
retro_menu_objs[i].resize();
});
var retro_menu_obj = function(e, limit, outerlimit) {
var that = this;
this.e = e;
this.original_width = e.children('div').outerWidth();
this.limit = limit;
this.outerlimit = outerlimit;
this.resize = function() {
if (this.original_width == 0) return;
if (jQuery(window).width() >= this.original_width + this.limit) {
this.e.children('div').children('a').each(function(){
jQuery(this).show();
});
this.e.children('div').children('div').children('a').hide();
this.e.children('div').children('div').children('ul').children('li').each(function(){
jQuery(this).hide();
});
} else {
var els = [];
this.e.children('div').children('a').each(function(){
els.push(jQuery(this));
jQuery(this).show();
});
this.e.children('div').children('div').children('a').show();
var num = 0, current;
while (els.length > 0) {
current = els.pop();
current.hide();
num++;
if (jQuery(window).width() >= this.e.children('div').outerWidth() + this.outerlimit) els = [];
}
if (num > 0) {
this.e.children('div').children('div').children('ul').children('li').each(function(){
els.push(jQuery(this));
});
while (els.length > 0) {
current = els.pop();
if (num > 0) current.show(); else current.hide();
num--;
}
}
}
};
this.dropdown_out = -1;
this.dropdown_interval = null;
this.dropdown_interval_func = function(){
if (that.dropdown_out < 0) return;
else if (that.dropdown_out == 0) {
that.e.children('div').children('div').children('ul').hide();
that.e.children('div').children('div').children('a').removeAttr('style');
}
that.dropdown_out--;
};
if (this.e.children('div').children('div').length > 0) this.e.children('div').children('div').remove();
var link_html = this.e.children('div').html().split('</a>'); link_html.pop();
for (var i = 0; i < link_html.length; i++) {
link_html[i] = "<li>" + link_html[i] + "</a></li>";
if (link_html[i].indexOf('class="current"') != -1) {
link_html[i] = link_html[i].replace('class="current"','').replace('<li>','<li class="current">');
}
}
this.e.children('div').append('<div><a href="#">▼</a><ul style="display:none">' + link_html.join("") + '</ul></div>');
this.e.children('div').children('div').children('a').unbind('click').click(function(e){
e.preventDefault();
jQuery(this).next().toggle();
if (jQuery(this).next().is(':visible')) {
jQuery(this).attr('style','color:rgba(255,255,255,1)');
} else {
jQuery(this).removeAttr('style');
}
this.dropdown_out = -1;
clearInterval(that.dropdown_interval);
that.dropdown_interval = null;
});
this.e.children('div').children('div').children('ul').unbind('mouseenter').unbind('mouseleave').hover(function(){
that.dropdown_out = -1;
clearInterval(that.dropdown_interval);
that.dropdown_interval = null;
},function(){
that.dropdown_out = 10;
clearInterval(that.dropdown_interval);
that.dropdown_interval = setInterval(function(){ that.dropdown_interval_func(); },100);
});
this.resize();
};