comparison js/core.js @ 2595:4fdaed765674

Format APE. Added getLabel for global interface handler
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Thu, 10 Nov 2016 16:31:01 +0000
parents 9bb878bf41d8
children 2d820b7413a7
comparison
equal deleted inserted replaced
2594:9d20649c3580 2595:4fdaed765674
3236 var node = storage.document.createElement('error'); 3236 var node = storage.document.createElement('error');
3237 node.setAttribute('time', time); 3237 node.setAttribute('time', time);
3238 node.textContent = errorMessage; 3238 node.textContent = errorMessage;
3239 testState.currentStore.XMLDOM.appendChild(node); 3239 testState.currentStore.XMLDOM.appendChild(node);
3240 }; 3240 };
3241
3242 this.getLabel = function (labelType, index, labelStart) {
3243 /*
3244 Get the correct label based on type, index and offset
3245 */
3246
3247 function calculateLabel(labelType, index, offset) {
3248 if (labelType == "none") {
3249 return "";
3250 }
3251 switch (labelType) {
3252 case "letter":
3253 return String.fromCharCode((index + offset) % 26 + 96);
3254 case "capital":
3255 return String.fromCharCode((index + offset) % 26 + 65);
3256 case "number":
3257 return String(index + offset);
3258 default:
3259 return "";
3260 }
3261 }
3262
3263 if (typeof labelStart !== "string") {
3264 labelStart = String.fromCharCode(0);
3265 }
3266
3267 switch (labelType) {
3268 case "letter":
3269 labelStart = labelStart.charCodeAt(0);
3270 if (labelStart.charCodeAt(0) < 97 || label.charCodeAt(0) > 122) {
3271 labelStart = 97;
3272 }
3273 labelStart -= 97;
3274 break;
3275 case "capital":
3276 labelStart = labelStart.charCodeAt(0);
3277 if (labelStart.charCodeAt(0) < 65 || label.charCodeAt(0) > 90) {
3278 labelStart = 65;
3279 }
3280 labelStart -= 65;
3281 break;
3282 case "number":
3283 if (!isFinite(Number(label))) {
3284 labelStart = 1;
3285 }
3286 break;
3287 case "none":
3288 default:
3289 labelStart = "";
3290 }
3291 if (typeof index == "number") {
3292 return calculateLabel(labelType, index, labelStart);
3293 } else if (index.length && index.length > 0) {
3294 var a = [],
3295 l = index.length,
3296 i;
3297 for (i = 0; i < l; i++) {
3298 a[i] = calculateLabel(labelType, index[i], labelStart);
3299 }
3300 return a;
3301 } else {
3302 throw ("Invalid arguments");
3303 }
3304 }
3241 } 3305 }
3242 3306
3243 function Storage() { 3307 function Storage() {
3244 // Holds results in XML format until ready for collection 3308 // Holds results in XML format until ready for collection
3245 this.globalPreTest = null; 3309 this.globalPreTest = null;