Skip to content

Commit

Permalink
Added jenkins-backcompat bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
tfennelly committed Jul 25, 2015
1 parent 9828e29 commit 3c0f363
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 41 deletions.
1 change: 1 addition & 0 deletions core/src/main/resources/lib/layout/layout.jelly
Expand Up @@ -126,6 +126,7 @@ ${h.initPageVariables(context)}
<l:yui module="storage" />
<!--l:yui module="editor" suffix="-beta" /-->

<script src="${resURL}/bundles/jenkins-backcompat.js" type="text/javascript"/>
<script src="${resURL}/bundles/jenkins.js" type="text/javascript"/>
<script src="${resURL}/scripts/hudson-behavior.js" type="text/javascript"></script>
<script src="${resURL}/scripts/sortable.js" type="text/javascript"/>
Expand Down
8 changes: 8 additions & 0 deletions war/gulpfile.js
Expand Up @@ -18,4 +18,12 @@ builder.bundle('src/main/js/jenkins.js')
.withExternalModuleMapping('jquery-detached-2.1.4', 'jquery-detached:jquery2')
.withExternalModuleMapping('bootstrap-detached-3.3', 'bootstrap:bootstrap3')
.withExternalModuleMapping('moment', 'momentjs:momentjs2')
.inDir('src/main/webapp/bundles');

//
// Create the Backward Compatibility module to globalize some modularized functions
// that existing non-modularized code will expect to be in the global scope, and
// expect them to be there immediately (i.e. no async waiting for other modules to load).
//
builder.bundle('src/main/js/jenkins-backcompat.js')
.inDir('src/main/webapp/bundles');
7 changes: 0 additions & 7 deletions war/src/main/js/find/index.js
Expand Up @@ -170,10 +170,3 @@ function findFormItem(src,name,directionF) {
var name2 = "_."+name; // handles <textbox field="..." /> notation silently
return directionF(src,function(e){ return (e.tagName=="INPUT" || e.tagName=="TEXTAREA" || e.tagName=="SELECT") && (e.name==name || e.name==name2); });
};

// Hack to offer backward compatibility for callers of the
// global version that used to be defined in hudson-behavior.js
require('../backcompatib')
.globalize(module, ['findAncestor', 'findAncestorClass', 'findFollowingTR',
'findPreviousFormItem', 'findNextFormItem',
'findFormParent', 'findNearBy']);
38 changes: 18 additions & 20 deletions war/src/main/js/formsub/index.js
Expand Up @@ -4,21 +4,23 @@ var finder = require('../find');
exports.init = function() {
var $ = jquery.getJQuery();

$('form').each(function() {
var form = this;

crumb.appendToForm(form);
if(Element.hasClassName(form, "no-json"))
return;
// add the hidden 'json' input field, which receives the form structure in JSON
$(form).append("<div><input type='hidden' name='json' value='init'></div>");

var oldOnsubmit = form.onsubmit;
if (typeof oldOnsubmit == "function") {
form.onsubmit = function() { return buildFormTree(this) && oldOnsubmit.call(this); }
} else {
form.onsubmit = function() { return buildFormTree(this); };
}
$(document).ready(function() {
$('form').each(function() {
var form = this;

crumb.appendToForm(form);
if(Element.hasClassName(form, "no-json"))
return;
// add the hidden 'json' input field, which receives the form structure in JSON
$(form).append("<div><input type='hidden' name='json' value='init'></div>");

var oldOnsubmit = form.onsubmit;
if (typeof oldOnsubmit == "function") {
form.onsubmit = function() { return exports.buildFormTree(this) && oldOnsubmit.call(this); }
} else {
form.onsubmit = function() { return exports.buildFormTree(this); };
}
});
});
};

Expand Down Expand Up @@ -173,8 +175,4 @@ function shortenName(name) {
var idx = name.lastIndexOf('.');
if(idx>=0) name = name.substring(idx+1);
return name;
}

// Hack to offer backward compatibility for callers of the
// global version that used to be defined in hudson-behavior.js
require('../backcompatib').globalize(module, ['buildFormTree']);
}
@@ -1,11 +1,13 @@

/**
* A backward compatibility hack to expose functions that
/*
* A backward compatibility hack to expose modularized functions that
* existing JS code may look for in the global scope.
* @param module The module containing functions to be exported.
* @param functions An array of function names.
* <p>
* This module should have no external dependencies (i.e. that need to be loaded before it).
* The functions need to be loaded immediately because the non-modularized .js code that
* they are servicing (e.g. adjuncts) will be loaded immediately.
*/
exports.globalize = function(module, functions) {

function globalize(module, functions) {
if (typeof window !== 'undefined') {
function apply(funcNum) {
var functionInfo = functions[funcNum];
Expand All @@ -22,11 +24,20 @@ exports.globalize = function(module, functions) {

window[globalFuncName] = function () {
// TODO: Come up with a way of gather this info so we can track code using non modularized code.
return module.exports[moduleFuncName].apply(window, arguments);
return module[moduleFuncName].apply(window, arguments);
};
}
for (var i = 0; i < functions.length; i++) {
apply(i);
}
}
};
};

// Need to globalize some functions from the 'find' module.
globalize(require('./find'), ['findAncestor', 'findAncestorClass', 'findFollowingTR',
'findPreviousFormItem', 'findNextFormItem',
'findFormParent', 'findNearBy']);

// Need to globalize some functions from the 'formsub' module.
globalize(require('./formsub'), ['buildFormTree']);

7 changes: 1 addition & 6 deletions war/src/main/js/jenkins.js
@@ -1,12 +1,7 @@

// Initialise all modules by requiring them. Also makes sure they get bundled (see gulpfile.js).

var jquery = require('jquery-detached-2.1.4');
var $ = jquery.getJQuery();

$(document).ready(function() {
require('./formsub').init();
});
require('./formsub').init();

//// Example of using bootstrap.
//// NB: Don't use it here though, Gus!!!
Expand Down

0 comments on commit 3c0f363

Please sign in to comment.