Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Fix Bug 964091, precompile nunjucks templates always, remove pointers…
Browse files Browse the repository at this point in the history
… bit as it is strangely having the opposite effect
  • Loading branch information
ossreleasefeed committed Jan 31, 2014
1 parent a5a8271 commit 5318f83
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 4,205 deletions.
40 changes: 38 additions & 2 deletions Gruntfile.js
Expand Up @@ -17,13 +17,49 @@ module.exports = function(grunt) {
}
}
},
nunjucks: {
precompile: {
baseDir: 'dxr/static/templates/',
src: [
'dxr/static/templates/partial/results.html',
'dxr/static/templates/partial/switch_tree.html',
'dxr/static/templates/context_menu.html',
'dxr/static/templates/path_line.html',
'dxr/static/templates/results_container.html'
],
dest: 'dxr/static/js/templates.js',
options: {
name: function(filename) {
var re = /(partial\/)?(|\w+.\w{4})$/g;
return re.exec(filename)[0];
}
}
}
},
jshint: {
all: ['Gruntfile.js', 'dxr/static/js/*.js']
},
watch: {
nunjucks: {
files: [
'dxr/static/templates/partial/results.html',
'dxr/static/templates/partial/switch_tree.html',
'dxr/static/templates/context_menu.html',
'dxr/static/templates/path_line.html',
'dxr/static/templates/results_container.html'
],
tasks: ['nunjucks']
}
}
});

grunt.loadNpmTasks('grunt-uncss');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-uncss');
grunt.loadNpmTasks('grunt-nunjucks');

grunt.registerTask('dev', ['nunjucks', 'watch']);
grunt.registerTask('lint', ['jshint', 'uncss:dev']);

grunt.registerTask('dev', ['jshint', 'uncss:dev']);
grunt.registerTask('precompile', ['nunjucks']);
};
12 changes: 4 additions & 8 deletions dxr/static/js/context_menu.js
@@ -1,17 +1,13 @@
/* jshint devel:true, esnext: true */
/* globals nunjucks: true, $ */

$(function() {
'use strict';
// Get the file content container
var fileContainer = $('#file'),
queryField = $('#query'),
contentContainer = $('#content');

if (!nunjucks.env) {
nunjucks.env = new nunjucks.Environment(new nunjucks.HttpLoader(dxr.views));
}

var env = nunjucks.env,
tmpl = env.getTemplate('context_menu.html');

/**
* Highlight, or remove highlighting from, all symbols with the same class
* as the current node.
Expand Down Expand Up @@ -49,7 +45,7 @@ $(function() {
top += window.scrollY;
}

target.append(tmpl.render(contextMenu));
target.append(nunjucks.render('context_menu.html', contextMenu));
var currentContextMenu = $('#context-menu');

// Immediately after appending the context menu, position it.
Expand Down
42 changes: 8 additions & 34 deletions dxr/static/js/dxr.js
Expand Up @@ -6,7 +6,8 @@ $(function() {

var constants = $('#data');
var stateConstants = $('#state');
var dxr = {};
var dxr = {},
docElem = document.documentElement;

dxr.wwwroot = constants.data('root');
dxr.baseUrl = location.protocol + '//' + location.host;
Expand All @@ -15,26 +16,8 @@ $(function() {
dxr.searchUrl = constants.data('search');
dxr.tree = constants.data('tree');

/**
* Disable and enable pointer events on scroll begin and scroll end to
* avoid unnecessary paints and recalcs caused by hover effets.
* @see http://www.thecssninja.com/javascript/pointer-events-60fps
*/
var docElem = document.documentElement,
timer;

window.addEventListener('scroll', function() {
// User scrolling so stop the timeout
clearTimeout(timer);
// Pointer events has not already been disabled.
if (!docElem.style.pointerEvents) {
docElem.style.pointerEvents = 'none';
}

timer = setTimeout(function() {
docElem.style.pointerEvents = '';
}, 500);
}, false);
// Tell nunjucks our base location for template files.
nunjucks.configure('dxr/static/templates/');

/**
* Presents the user with a notification message
Expand Down Expand Up @@ -81,15 +64,6 @@ $(function() {
}
}

if (!nunjucks.env) {
nunjucks.env = new nunjucks.Environment(new nunjucks.HttpLoader(dxr.views));
}

var env = nunjucks.env,
resultsContainerTmpl = env.getTemplate('results_container.html'),
resultsTmpl = env.getTemplate('partial/results.html'),
pathLineTmpl = env.getTemplate('path_line.html');

/**
* Represents the path line displayed next to the file path label on individual document pages.
* Also handles population of the path lines template in the correct format.
Expand All @@ -113,7 +87,7 @@ $(function() {

dataPath.push(paths[pathIndex]);

pathLines += pathLineTmpl.render({
pathLines += nunjucks.render('path_line.html', {
'data_path': dataPath.join('/'),
'display_path': paths[pathIndex],
'icon_class': isFirstOrOnly ? iconClass : '',
Expand Down Expand Up @@ -275,7 +249,7 @@ $(function() {
// Update result count
resultCount = data.results.length;
// Use the results.html partial so we do not inject the entire container again.
populateResults(resultsTmpl, data, true);
populateResults('partial/results.html', data, true);
// update URL with new offset
setHistoryState(dataOffset);
// start the scrolling poller
Expand Down Expand Up @@ -339,7 +313,7 @@ $(function() {
}

var container = append ? contentContainer : contentContainer.empty();
container.append(tmpl.render(data));
container.append(nunjucks.render(tmpl, data));
}
}

Expand All @@ -361,7 +335,7 @@ $(function() {
// New results, overwrite
if (myRequestNumber > displayedRequestNumber) {
displayedRequestNumber = myRequestNumber;
populateResults(resultsContainerTmpl, data, false);
populateResults('results_container.html', data, false);
}
})
.fail(function(jqxhr, textStatus, error) {
Expand Down

0 comments on commit 5318f83

Please sign in to comment.