utils.js revision 236b13257200c0b0237413dc605ca540ff3b9622
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*
* Portions Copyright 2011 Jens Elkner.
*/
/**
* Spaces plugin.
*
* Inserts a dummy space between line number and the text so that on copy-paste
* the white space is preserved.
*
* Internally listens on scroll events and autofills the spaces only for the visible
* elements.
*
* IMPORTANT: This plugin is strictly dependent on ascending order of lines
* and on their attribute "name". It performs a binary search which boosts performance
* of this plugin for really long files.
*
* @author Krystof Tulinger
*/
(function (w, $) {
var spaces = function () {
var inner = {
defaults: {
interval: 750,
selector: "a.l, a.hl",
$parent: null,
callback: function () {
if (!$(this).hasClass("selected")) {
$(this).addClass("selected");
}
}
},
options: {},
$collection: $(),
initialized: false,
lock: false,
var lo = 0,
mid,
cmp;
if (cmp === 0) {
return mid;
} else if (cmp < 0) {
} else {
}
}
return -1;
},
handleScrollEvent: function () {
var expectations = {
// the first element in viewport
Math.abs(
) / myHeight
),
// the last element in viewport
(Math.abs(
) + parentHeight
) / myHeight
),
};
var indices = {
start: 0,
};
};
/** cutoffs */
/** calling callback for every element in the viewport */
}
},
init: function () {
if (inner.initialized) {
return;
}
return;
}
var scrollHandler = function (e) {
return;
}
};
.scroll() // fire the event if user has not scrolled
inner.initialized = true;
}
};
return this;
}
};
(function(window, $) {
var hash = function () {
var inner = {
self: this,
initialized: false,
highlighted: [],
defaults: {
highlightedClass: 'target',
linkSelectorTemplate: '{parent} a[name={n}]',
clickSelector: '{parent} a.l, {parent} a.hl',
parent: 'div#src',
autoScroll: true,
autoScrollDuration: 500,
tooltip: true
},
options: {},
$tooltip: null,
bindClickHandler: function() {
if(e.shiftKey) {
// shift pressed
if(!val){
return false
}
if(l.length == 2) {
} else if ( l.length == 1){
}
return false
}
return true
})
},
getHashParts: function (hash) {
return hash;
},
getLinesParts: function ( hashPart ) {
return hashPart;
return []
},
if(p.length == 2) {
var l = [];
l.push(i);
return l;
} else if (p.length == 1){
return [ p[0] ]
}
return [];
},
reload: function(e){
// remove color
}
inner.highlighted = []
// not a case of line highlighting
return
}
// color
"n": lines[i] } );
}
},
: match
;
});
},
},
scroll: function (){
return
$("#content").animate({
n: line
}
},
tooltip: function() {
return
$("<div>Did you know? You can select a range of lines<br /> by clicking on the other while holding shift key.</div>")
.appendTo($("body"))
.hide()
.addClass("tooltip")
.addClass("diff_navigation_style")
.click(function(e) {
return
// show box
var $el = $(this)
setTimeout(function () {
.show()
.stop()
.fadeIn()
.fadeOut( 5000 )
.offset({
});
}, 300);
})
}
} // inner
if ( inner.initialized ) {
return this;
}
inner.initialized = true
return this;
}
}
/**
* General on-demand script downloader
*/
var script = function () {
var self = this
this.scriptsDownloaded = {};
this.defaults = {
}
this.loadScript = function (url) {
if (!/^[a-z]{3,5}:\/\//.test(url)) { // dummy test for remote prefix
}
if (url in this.scriptsDownloaded) {
return this.scriptsDownloaded[url]
}
dataType: 'script',
cache: true,
timeout: 10000
}).fail(function () {
});
}
};
/**
* General window
*/
var window = function () {
var self = this
// private
this.initialized = false
this.active = false
this.clientX = 0
this.clientY = 0
// public
this.defaults = {
title: 'Window',
appendDraggable: '#content',
draggable: true,
}
// private
this.determinePosition = function () {
var position = {}
} else {
}
} else {
}
return position;
}
this.makeMeDraggable = function () {
helper: 'clone',
start: function () {
$(this).hide();
},
},
}
});
});
}
this.registerHandlers = function () {
//console.log(self.clientX, self.clientY)
})
switch (key) {
case 27: // esc
break;
default:
}
return true;
});
}
this.createWindow = function () {
$controls = $('<div>')
.addClass('clearfix')
$window = $("<div>")
.addClass('window')
.addClass('diff_navigation_style')
.hide()
.append($("<hr>"))
return false;
});
return $window;
}
// main
this.registerHandlers()
this.makeMeDraggable()
}
});
}
};
this.$window.toggleAndMove = function () {
}
}
return this.$window;
};
}
};
/**
* Intelligence window plugin.
*
* Reworked to use Jquery in 2016
*/
var intelliWindow = function () {
var inner = {
// private
initialized: false,
// public
defaults: {
title: 'Intelligence window',
draggable: true,
selector: 'a.intelliWindow-symbol',
},
options: {},
// private
changeSymbol: function ($el) {
inner.$last_highlighted_current = $el.hasClass("symbol-highlighted") ? $el : inner.$last_highlighted_current
inner.modifyLinks();
},
modifyLinks: function () {
},
getSearchLink: function (query) {
return inner.options.contextPath + '/search?' + query + '=' + inner.symbol + '&project=' + inner.project;
},
getSymbolDescription: function (place) {
switch (place) {
case "def":
return "A declaration or definition.";
case "defined-in-file":
return "A symbol declared or defined in this file.";
case "undefined-in-file":
return "A symbol declared or defined elsewhere.";
default:
// should not happen
return "Something I have no idea about.";
}
},
getSymbols: function () {
},
}
}).addClass('symbol-highlighted')
},
unhighlight: function (symbol) {
if (inner.$last_highlighted_current &&
}
}).removeClass('symbol-highlighted')
},
unhighlightAll: function () {
},
} else {
}, 500);
}
},
scrollToNextElement: function (direction) {
var UP = -1;
var DOWN = 1;
switch (direction) {
case DOWN:
if ($highlighted.length) {
}
return;
}
break;
case UP:
if ($highlighted.length) {
}
return;
}
break;
default:
return;
}
},
toggle: function () {
},
hide: function () {
},
show: function () {
},
registerHandlers: function () {
switch (key) {
case 49: // 1
}
break;
case 50: // 2
}
break;
case 51: // 3
break;
case 110: // n
break;
case 98: // b
break;
default:
}
return true;
});
inner.changeSymbol($(this));
});
},
e.preventDefault()
return false;
})
},
var $firstList = $("<ul>")
$highlight = $("<a href=\"#\" title=\"Highlight\">" +
"<span>Highlight</span> <b class=\"symbol-name\"></b></a>")))
$unhighlight = $("<a href=\"#\" title=\"Unhighlight\">" +
"<span>Unhighlight</span> <b class=\"symbol-name\"></b></a>")))
$unhighlighAll = $("<a href=\"#\" title=\"Unhighlight all\">" +
"<span>Unhighlight all</span></a>")))
var $secondList = $("<ul>")
$("<a class=\"search-defs\" href=\"#\" target=\"_blank\">" +
"<span>Search for definitions of</span> <b class=\"symbol-name\"></b></a>")))
$("<a class=\"search-refs\" href=\"#\" target=\"_blank\">" +
"<span>Search for references of</span> <b class=\"symbol-name\"></b></a>")))
$("<a class=\"search-full\" href=\"#\" target=\"_blank\">" +
"<span>Do a full search with</span> <b class=\"symbol-name\"></b></a>")))
$("<a class=\"search-files\" href=\"#\" target=\"_blank\">" +
"<span>Search for file names that contain</span> <b class=\"symbol-name\"></b></a>")))
var $thirdList = $("<ul>")
$("<a class=\"search-google\" href=\"#\" target=\"_blank\">" +
"<span>Google</span> <b class=\"symbol-name\"></b></a>")))
var $controls = $("<div class=\"pull-right\">")
.append("<span class=\"pull-right\"> | </span>")
.append($("<div class=\"clearfix\">"))
return $window
.addClass('intelli-window')
.append($("<hr>"))
},
init: function () {
if (inner.initialized) {
return
}
inner.initialized = true
}
};
}
};
/**
* Messages window plugin.
*
* @author Kryštof Tulinger
*/
var messagesWindow = function () {
var inner = {
// private
initialized: false,
$messages: $(),
// public
defaults: {
title: 'Messages Window',
draggable: false,
},
options: {},
// private
registerHandlers: function () {
}).mouseleave(function () {
})
},
return $window
.addClass('messages-window')
.addClass('diff_navigation_style')
//.append($("<h5>").text("System messages"))
},
init: function () {
if (inner.initialized) {
return
}
inner.initialized = true
}
};
this.toggle = function () {
}
this.hide = function () {
}
$('<li>')
.addClass('message-group-item')
)
}
}
this.show = function () {
}
}
};
function init_results_autohide() {
$("#sbox input[type='submit']").click(function (e) {
})
}
function init_searchable_option_list() {
var searchableOptionListOptions = {
maxHeight: '300px',
showSelectionBelowList: false,
showSelectAll: false,
maxShow: 30,
resultsContainer: $("#ltbl"),
events: {
onInitialized: function () {
$.messagesWindow.show()
}).mouseleave(function (e) {
$.messagesWindow.hide()
})
},
// override the default onScroll positioning event if neccessary
onScroll: function () {
var posY = this.$input.offset().top - this.config.scrollTarget.scrollTop() + this.$input.outerHeight(),
selectionContainerWidth = this.$innerContainer.outerWidth(false) - parseInt(this.$selectionContainer.css('border-left-width'), 10) - parseInt(this.$selectionContainer.css('border-right-width'), 10);
// container has a certain width
// make selection container a bit wider
} else {
// no border radius on top
this.$selectionContainer
if (this.$actionButtons) {
this.$actionButtons
}
}
this.$selectionContainer
}
}
};
}
function init_history_input() {
$('input[data-revision-path]').click(function () {
var $this = $(this)
$("a.more").each(function () {
})
var $revisions = $('input[data-revision-path]'),
index = -1;
// change the correct revision on every element
// (every element keeps a track which revision is selected)
// set the correct revision for the form submittion
// enable all input
// uncheck all input in my column
$revisions.filter('[data-diff-revision=\'' + $this.data('diff-revision') + '\']').prop('checked', false)
// set me as checked
// disable from top to r2
index = Math.max($revisions.index($('input[data-revision-path][data-diff-revision=\'r2\']:checked')), 0)
// disable from bottom to r1
index = Math.max($revisions.index($('input[data-revision-path][data-diff-revision=\'r1\']:checked')), index)
})
}
function init_tablesorter() {
$("#dirlist").tablesorter({
cancelSelection: true,
headers: {
1: {
sorter: 'text'
},
3: {
sorter: 'dates'
},
4: {
sorter: 'groksizes'
}
}
});
}
/**
* Initialize scope scroll event to display scope information correctly when
* the element comes into the viewport.
*/
/**
* Initialize table sorter on every directory listing.
*/
/**
* Initialize inteligence window plugin. Presence of #contextpath indicates
* that we use the code view.
*/
$("#contextpath").each(function () {
$.intelliWindow.init();
return false
})
/**
* Initialize the messages plugin to display
* message onhover on every affected element.
*/
$.messagesWindow.init();
/**
* Attaches a onhover listener to display messages for affected elements.
*/
$("[data-messages]").mouseenter(function () {
$.messagesWindow.show()
}).mouseleave(function (e) {
$.messagesWindow.hide()
})
/**
* Initialize spaces plugin which automaticaly inserts a single space between
* the line number and the following text. It strongly relies on the fact
* that the line numbers are stored in 'name' attribute on each line link.
*/
/**
* Initialize the window hash management. Mainly this allows users to select
* multiple lines of code and use that url to send it to somebody else.
*/
/**
* After hitting the search button, the results or projects are temporarily hidden
* until the new page is loaded. That helps to distinguish if search is being in process.
*
*/
/**
* Initialize the new project picker
*/
/**
* Initialize the history input picker.
* Checkboxes are automaticaly covered with a click event and automaticaly
* colored as disabled or checked.
*
* Also works for paging where it stores the actual selected revision range in the
* pagination links.
*/
});
}
}
for(var i in this.domReady) {
}
});
/**
* Resize the element with the ID 'content' so that it fills the whole browser
* window (i.e. the space between the header and the bottom of the window) and
* thus get rid off the scrollbar in the page header.
*/
function resizeContent() {
}
}
/**
* Get a parameter value from the URL.
*
* @param p the name of the parameter
* @return the decoded value of parameter p
*/
function getParameter(p) {
// First split up the parameter list. That is, transform from
// ?a=b&c=d
// to
// [ ["a", "b"], ["c","d"] ]
function (x) { return x.split("="); });
}
// Then look for the parameter.
for (var i in params) {
}
}
return undefined;
}
/**
* Set parameter in the given url.
* @param string url
* @param string p parameter name
* @param string v parameter value
* @returns string the modified url
*/
function setParameter(url, p, v) {
function (x) {
return x.split("=");
});
var found = false;
for (var i in params) {
found = true
}
}
if (!found) {
}
return x[0] + '=' + x[1];
}).join('&');
}
function domReadyMast() {
var h = getParameter("h");
if (h && h !== "") {
} else {
$("#content")
.focus()
}
}
$('a.r').tooltip({
content: function () {
var element = $(this);
return "";
var $el = $("<dl>");
continue;
var $dd = $("<dd>");
});
}
return $el;
},
})
//$('a.r').tooltip({ left: 5, showURL: false });
}
// When we move to a version of XHTML that supports the onscroll
// attribute in the div element, we should add an onscroll attribute
// in the generated XHTML in mast.jsp. For now, set it with jQuery.
}
function pageReadyMast() {
if ($('#whole_header') != null && $('#content') != null) {
}
function() {
}
);
}
function domReadyMenu() {
/*
$("#project").autocomplete(projects, {
minChars: 0,
multiple: true,
multipleSeparator: ",",
//mustMatch: true,
matchContains: "word",
max: 200,
cacheLength:20,
//autoFill: false,
formatItem: function(row, i, max) {
return (row != null) ? i + "/" + max + ": " + row[0] : "";
},
formatMatch: function(row, i, max) {
return (row != null) ? row[0] : "";
},
formatResult: function(row) {
return (row != null) ? row[0] : "";
},
width: "300px"
});
*/
// TODO Bug 11749
// var p = document.getElementById('project');
// p.setAttribute("autocomplete", "off");
}
function domReadyHistory() {
// start state should ALWAYS be: first row: r1 hidden, r2 checked ;
// second row: r1 clicked, (r2 hidden)(optionally)
// I cannot say what will happen if they are not like that, togglediffs
// will go mad !
togglerevs();
}
function get_annotations() {
}
// If a line is highlighted when "annotate" is clicked, we want to
// preserve the highlighting, but we don't want the page to scroll
// to the highlighted line. So put the line number in a URL parameter
// instead of in the hash.
link += "&h=";
}
}
function toggle_annotations() {
}
/** list.jsp */
/**
* Initialize defaults for list.jsp
*/
function pageReadyList() {
}
});
}
/* ------ Navigation window for definitions ------ */
/**
* Create the Navigation toggle link as well as its contents.
*/
function get_sym_list_contents() {
// var contents = "<input id=\"input_highlight\" name=\"input_highlight\"
// class=\"q\"/>";
// contents += " ";
// contents += "<b><a href=\"#\" onclick=\"javascript:add_highlight();return
// false;\" title=\"Add highlight\">Highlight</a></b><br/>";
var contents =
"<a href=\"#\" onclick=\"javascript:lsttoggle();\">[Close]</a><br/>"
if (typeof get_sym_list != 'function') {
return contents;
}
var symbol_classes = get_sym_list();
if (i > 0) {
contents += "<br/>";
}
var symbol_class = symbol_classes[i];
contents += "<a href=\"#" + line + "\" class=\"" + class_name + "\" onclick=\"lnshow(); return true;\">"
}
}
return contents;
}
function escape_html(string) {
}
function get_sym_div_left() {
return document.sym_div_left;
}
function get_sym_div_height() {
}
return document.sym_div_height;
}
function get_sym_div_top() {
return document.sym_div_top;
}
function get_sym_div_width() {
return document.sym_div_width;
}
/**
* Toggle the display of the 'Navigation' window used to highlight definitions.
*/
function lsttoggle() {
} else {
}
}
/**
* Toggle the display of line numbers.
*/
function lntoggle() {
}
function lnshow() {
}
/* ------ Highlighting ------ */
/**
* An expensive Highlighter:
* Note: It will replace link's href contents as well, be careful.
*/
/* Not used.
function HighlightKeywordsFullText(keywords) {
var el = $("body");
$(keywords).each(
function() {
var pattern = new RegExp("("+this+")", ["gi"]);
var rs = "<span style='background-color:#FFFF00;font-weight:bold;'"
+ ">$1</span>";
}
);
// HighlightKeywordsFullText(["nfstcpsock"]);
}
*/
/**
* Highlight keywords by changeing the style of matching tags.
*/
function HighlightKeyword(keyword) {
'text-decoration' : 'underline',
% high_colors.length],
'font-weight' : 'bold'
});
}
//Test: HighlightKeyword('timeval');
/**
* Highlight the text given as value of the element with the ID "input_highlight" .
* @see HighlightKeyword
*/
function add_highlight() {
}
function toggle_filelist() {
$("div").each(
function() {
if (this.className == "filelist") {
this.className = "filelist-hidden";
} else if (this.className == "filelist-hidden") {
this.className = "filelist";
}
}
);
}
function toggle_revtags() {
$("tr").each(
function() {
if (this.className == "revtags") {
this.className = "revtags-hidden";
} else if (this.className == "revtags-hidden") {
this.className = "revtags";
}
}
);
$("span").each(
function() {
if (this.className == "revtags") {
this.className = "revtags-hidden";
} else if (this.className == "revtags-hidden") {
this.className = "revtags";
}
}
);
}
/**
* Function to toggle revision message length for long revision messages
*/
function togglerevs() {
$(".rev-toggle-a").click(function() {
if (toggleState == "less") {
$(this).html("... show less");
}
else if (toggleState == "more") {
$(this).html("show more ...");
}
return false;
});
}
function selectAllProjects() {
}
function invertAllProjects() {
}
function deselectAllProjects(){
}
function clearSearchFrom() {
$("#sbox input[type='text']").each(function () {
$(this).val("");
});
}
var scope_visible = 0;
var scope_text = '';
/**
* Fold or unfold a function definition.
*/
.children()
.first()
.toggleClass('unfold-icon')
.toggleClass('fold-icon')
}
/**
* Function that is called when the #content div element is scrolled. Checks
* if the top of the page is inside a function scope. If so, update the
* scope element to show the name of the function and a link to its definition.
*/
function scope_on_scroll() {
var $scope_cnt_el = $('#scope_content');
if ($(c).is('.l, .hl')) {
return;
}
}
}