annotate test_create/test_core.js @ 2912:7b6cdd27f3ee

Completed #222
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Tue, 01 Aug 2017 14:07:10 +0100
parents bcb741f60298
children b7347521a226
rev   line source
nicholas@2885 1 /* globals document, angular, window, Promise, XMLHttpRequest, Specification, XMLSerializer, Blob, DOMParser, FileReader, $*/
nicholas@2851 2 function get(url) {
nicholas@2851 3 // Return a new promise.
nicholas@2851 4 return new Promise(function (resolve, reject) {
nicholas@2851 5 // Do the usual XHR stuff
nicholas@2851 6 var req = new XMLHttpRequest();
nicholas@2851 7 req.open('GET', url);
nickjillings@1370 8
nicholas@2851 9 req.onload = function () {
nicholas@2851 10 // This is called even on 404 etc
nicholas@2851 11 // so check the status
nicholas@2851 12 if (req.status == 200) {
nicholas@2851 13 // Resolve the promise with the response text
nicholas@2851 14 resolve(req.response);
nicholas@2851 15 } else {
nicholas@2851 16 // Otherwise reject with the status text
nicholas@2851 17 // which will hopefully be a meaningful error
nicholas@2851 18 reject(Error(req.statusText));
nicholas@2851 19 }
nicholas@2851 20 };
nicholas@2851 21
nicholas@2851 22 // Handle network errors
nicholas@2851 23 req.onerror = function () {
nicholas@2851 24 reject(Error("Network Error"));
nicholas@2851 25 };
nicholas@2851 26
nicholas@2851 27 // Make the request
nicholas@2851 28 req.send();
nicholas@2851 29 });
nickjillings@1370 30 }
nickjillings@1370 31
nicholas@2851 32 var AngularInterface = angular.module("creator", []);
nickjillings@1370 33
nicholas@2851 34 var specification = new Specification();
nickjillings@1370 35
nicholas@2535 36 window.onload = function () {
nicholas@2851 37 // Get the test interface specifications
n@2911 38 toggleDropdowns();
n@2911 39 };
n@2911 40
n@2911 41 function toggleDropdowns() {
nicholas@2884 42 $(function () {
nicholas@2884 43 $('[data-toggle="popover"]').popover();
nicholas@2884 44 });
n@2911 45 }
nicholas@2535 46
nicholas@2861 47 function handleFiles(event) {
nicholas@2861 48 var s = angular.element(event.currentTarget).scope();
nicholas@2861 49 s.handleFiles(event);
nicholas@2861 50 s.$apply();
nicholas@2861 51 }
nicholas@2861 52
nicholas@2851 53 AngularInterface.controller("view", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 54 $s.popupVisible = true;
nicholas@2864 55 $s.testSpecifications = {};
nicholas@2864 56
nicholas@2864 57 (function () {
nicholas@2864 58 new Promise(function (resolve, reject) {
nicholas@2864 59 var xml = new XMLHttpRequest();
nicholas@2864 60 xml.open("GET", "test_create/interfaces/specifications.json");
nicholas@2864 61 xml.onload = function () {
nicholas@2864 62 if (xml.status === 200) {
nicholas@2864 63 resolve(xml.responseText);
nicholas@2864 64 return;
nicholas@2864 65 }
nicholas@2864 66 reject(xml.status);
nicholas@2864 67 };
nicholas@2864 68 xml.onerror = function () {
nicholas@2864 69 reject(new Error("Network Error"));
nicholas@2864 70 };
nicholas@2864 71 xml.send();
nicholas@2864 72 }).then(JSON.parse).then(function (data) {
nicholas@2864 73 $s.testSpecifications = data;
nicholas@2864 74 $s.$apply();
nicholas@2865 75 });
nicholas@2864 76 })();
nickjillings@1370 77
nicholas@2851 78 $s.showPopup = function () {
nicholas@2851 79 $s.popupVisible = true;
nicholas@2851 80 };
nicholas@2851 81 $s.hidePopup = function () {
nicholas@2851 82 $s.popupVisible = false;
nicholas@2851 83 };
nicholas@2851 84 $s.globalSchema = undefined;
nicholas@2851 85 get("xml/test-schema.xsd").then(function (text) {
nicholas@2851 86 specification.processSchema(text);
nicholas@2851 87 $s.globalSchema = specification.getSchema();
nicholas@2851 88 });
n@2912 89 $s.availableInterfaceModules = [];
n@2912 90 get("interfaces/interfaces.json").then(JSON.parse).then(function (d) {
n@2912 91 $s.availableInterfaceModules = d.interfaces;
n@2912 92 $s.$apply();
n@2912 93 });
nicholas@2851 94 $s.specification = specification;
nicholas@2886 95 $s.selectedTestPrototype = undefined;
nicholas@2886 96 $s.setTestPrototype = function (obj) {
nicholas@2886 97 $s.selectedTestPrototype = obj;
nicholas@2886 98 $w.specification.interface = obj.interface;
nicholas@2886 99 }
nicholas@2857 100
nicholas@2857 101 $s.addPage = function () {
nicholas@2857 102 $s.specification.createNewPage();
nicholas@2859 103 };
nicholas@2860 104
nicholas@2862 105 $s.removePage = function (page) {
nicholas@2862 106 var index = $s.specification.pages.findIndex(function (a) {
nicholas@2862 107 return a == page;
nicholas@2862 108 });
nicholas@2862 109 if (index === -1) {
nicholas@2862 110 throw ("Invalid Page");
nicholas@2862 111 }
nicholas@2862 112 $s.specification.pages.splice(index, 1);
nicholas@2862 113 };
nicholas@2862 114
nicholas@2860 115 $s.exportXML = function () {
nicholas@2860 116 var s = new XMLSerializer();
nicholas@2860 117 var doc = specification.encode();
nicholas@2891 118 var xmlstr = s.serializeToString(doc);
nicholas@2860 119 var bb = new Blob([s.serializeToString(doc)], {
nicholas@2860 120 type: 'application/xml'
nicholas@2860 121 });
nicholas@2860 122 var dnlk = window.URL.createObjectURL(bb);
nicholas@2891 123 var a = document.createElement("a");
nicholas@2891 124 a.href = dnlk;
nicholas@2891 125 a.download = "test.xml";
nicholas@2891 126 a.click();
nicholas@2891 127 window.URL.revokeObjectURL(dnlk);
nicholas@2861 128 };
nicholas@2887 129 $s.validated = false;
nicholas@2887 130 $s.showValidationMessages = false;
nicholas@2887 131 $s.validate = function () {
nicholas@2887 132 var s = new XMLSerializer();
nicholas@2887 133 var Module = {
nicholas@2887 134 xml: s.serializeToString(specification.encode()),
nicholas@2887 135 schema: specification.getSchemaString(),
nicholas@2887 136 arguments: ["--noout", "--schema", 'test-schema.xsd', 'document.xml']
nicholas@2887 137 };
nicholas@2887 138 var xmllint = validateXML(Module);
nicholas@2887 139 console.log(xmllint);
nicholas@2887 140 if (xmllint != 'document.xml validates\n') {
nicholas@2887 141 $s.validated = false;
nicholas@2887 142 var list = $e[0].querySelector("#validation-error-list");
nicholas@2887 143 while (list.firstChild) {
nicholas@2887 144 list.removeChild(list.firstChild);
nicholas@2887 145 }
nicholas@2887 146 var errors = xmllint.split('\n');
nicholas@2887 147 errors = errors.slice(0, errors.length - 2);
nicholas@2887 148 errors.forEach(function (str) {
nicholas@2887 149 var li = document.createElement("li");
nicholas@2887 150 li.textContent = str;
nicholas@2887 151 list.appendChild(li);
nicholas@2887 152 });
nicholas@2887 153 } else {
nicholas@2887 154 $s.validated = true;
nicholas@2887 155 }
nicholas@2887 156 $s.showValidationMessages = true;
nicholas@2887 157 }
nicholas@2887 158 $s.hideValidationMessages = function () {
nicholas@2887 159 $s.showValidationMessages = false;
nicholas@2887 160 }
n@2911 161 $s.$watch(function () {
n@2911 162 return document.querySelectorAll("div.pageNode").length;
n@2911 163 }, $w.toggleDropdowns);
n@2911 164 $s.$watch(function () {
n@2911 165 return document.querySelectorAll("div.surveyentry").length;
n@2911 166 }, $w.toggleDropdowns);
n@2911 167 $s.$watch(function () {
n@2911 168 return document.querySelectorAll("div.interface").length;
n@2911 169 }, $w.toggleDropdowns);
n@2911 170 $s.$watch(function () {
n@2911 171 return document.querySelectorAll("div.audioelement").length;
n@2911 172 }, $w.toggleDropdowns);
nicholas@2851 173 }]);
nickjillings@1370 174
nicholas@2851 175 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 176 $s.state = 0;
n@2908 177 $s.selected = undefined;
nicholas@2851 178 $s.next = function () {
nicholas@2851 179 $s.state++;
nicholas@2861 180 if ($s.state > 1 || $s.file) {
nicholas@2851 181 $s.hidePopup();
n@2908 182 $s.initialise($s.selected);
nicholas@2851 183 }
nicholas@2851 184 };
nicholas@2851 185 $s.back = function () {
nicholas@2851 186 $s.state--;
nicholas@2851 187 };
nicholas@2851 188 $s.mouseover = function (name) {
nicholas@2864 189 var obj = $s.testSpecifications.interfaces.find(function (i) {
nicholas@2851 190 return i.name == name;
nicholas@2851 191 });
nicholas@2851 192 if (obj) {
nicholas@2851 193 $s.description = obj.description.en;
nicholas@2851 194 }
nicholas@2851 195 };
nicholas@2851 196 $s.initialise = function (name) {
nicholas@2885 197 var obj = $s.testSpecifications.interfaces.find(function (i) {
nicholas@2851 198 return i.name == name;
nicholas@2851 199 });
nicholas@2886 200 if (obj === undefined) {
nicholas@2886 201 throw ("Cannot find specification");
nicholas@2886 202 }
n@2908 203 if (typeof obj.template === "string") {
n@2908 204 get(obj.template).then(function (data) {
n@2908 205 $s.parseFile(data);
n@2908 206 }, function (err) {})
n@2908 207 } else {
n@2908 208 $s.setTestPrototype(obj);
n@2908 209 }
nicholas@2851 210 };
n@2908 211 $s.select = function (name) {
n@2908 212 $s.selected = name;
n@2908 213 }
n@2908 214 // Get the test interface specifications
nicholas@2861 215 $s.file = undefined;
nicholas@2851 216 $s.description = "";
nicholas@2861 217
n@2908 218 $s.parseFile = function (f) {
n@2908 219 var p = new DOMParser();
n@2908 220 specification.decode(p.parseFromString(f, "text/xml"));
n@2908 221 $s.$apply();
n@2908 222 }
n@2908 223
nicholas@2861 224 $s.handleFiles = function ($event) {
nicholas@2861 225 $s.file = $event.currentTarget.files[0];
nicholas@2861 226 var r = new FileReader();
nicholas@2861 227 r.onload = function () {
n@2908 228 $s.parseFile(r.result);
nicholas@2862 229 };
nicholas@2861 230 r.readAsText($s.file);
nicholas@2861 231 };
nicholas@2851 232 }]);
nickjillings@1370 233
nicholas@2851 234 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 235 function initialise() {
nicholas@2851 236 if ($s.globalSchema) {
nicholas@2851 237 $s.schema = $s.globalSchema.querySelector("[name=setup]");
nickjillings@1385 238 }
nickjillings@1370 239 }
nicholas@2851 240 $s.schema = undefined;
nicholas@2851 241 $s.attributes = [];
nickjillings@1370 242
nicholas@2851 243 $s.$watch("globalSchema", initialise);
nicholas@2853 244 $s.$watch("specification.metrics.enabled.length", function () {
nicholas@2853 245 var metricsNode = document.getElementById("metricsNode");
nicholas@2853 246 if (!$s.specification.metrics) {
nicholas@2853 247 return;
nicholas@2853 248 }
nicholas@2853 249 metricsNode.querySelectorAll("input").forEach(function (DOM) {
nicholas@2853 250 DOM.checked = false;
nicholas@2853 251 });
nicholas@2853 252 $s.specification.metrics.enabled.forEach(function (metric) {
nicholas@2853 253 var DOM = metricsNode.querySelector("[value=" + metric + "]");
nicholas@2853 254 if (DOM) {
nicholas@2853 255 DOM.checked = true;
nicholas@2853 256 }
nicholas@2853 257 });
nicholas@2855 258 });
nicholas@2853 259
nicholas@2853 260 $s.enableMetric = function ($event) {
nicholas@2853 261 var metric = $event.currentTarget.value;
nicholas@2853 262 var index = specification.metrics.enabled.findIndex(function (a) {
nicholas@2853 263 return a == metric;
nicholas@2853 264 });
nicholas@2853 265 if ($event.currentTarget.checked) {
nicholas@2853 266 if (index == -1) {
nicholas@2853 267 specification.metrics.enabled.push(metric);
nicholas@2853 268 }
nicholas@2853 269 } else {
nicholas@2853 270 if (index >= 0) {
nicholas@2853 271 specification.metrics.enabled.splice(index, 1);
nicholas@2853 272 }
nicholas@2853 273 }
nicholas@2855 274 };
nicholas@2886 275
nicholas@2886 276 $s.configure = function () {}
nicholas@2886 277
nicholas@2886 278 $s.$watch("selectedTestPrototype", $s.configure);
n@2907 279
n@2907 280 $s.placeholder = function (name) {
n@2908 281 if ($s.schema) {
n@2908 282 var spec = $s.schema.querySelector("attribute[name=\"" + name + "\"]") || $w.specification.schema.querySelector("attribute[name=\"" + name + "\"]");
n@2908 283 var attr = spec.getAttribute("default");
n@2912 284 if (attr === null) {
n@2912 285 return "Not set";
n@2908 286 }
n@2908 287 return attr;
n@2907 288 }
n@2907 289 }
nicholas@2851 290 }]);
nicholas@2853 291
nicholas@2858 292 AngularInterface.controller("survey", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2858 293 $s.addSurveyEntry = function () {
nicholas@2858 294 $s.survey.addOption();
nicholas@2858 295 };
nicholas@2858 296 $s.removeSurveyEntry = function (entry) {
nicholas@2858 297 var index = $s.survey.options.findIndex(function (a) {
nicholas@2858 298 return a == entry;
nicholas@2858 299 });
nicholas@2858 300 if (index === -1) {
nicholas@2858 301 throw ("Invalid Entry");
nicholas@2858 302 }
nicholas@2858 303 $s.survey.options.splice(index, 1);
nicholas@2858 304 };
nicholas@2858 305 }]);
nicholas@2858 306
nicholas@2853 307 AngularInterface.controller("surveyOption", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2853 308
nicholas@2853 309 $s.removeOption = function (option) {
nicholas@2853 310 var index = $s.opt.options.findIndex(function (a) {
nicholas@2853 311 return a == option;
nicholas@2853 312 });
nicholas@2853 313 if (index === -1) {
nicholas@2853 314 throw ("Invalid option");
nicholas@2853 315 }
nicholas@2853 316 $s.opt.options.splice(index, 1);
nicholas@2853 317 };
nicholas@2853 318 $s.addOption = function () {
nicholas@2853 319 $s.opt.options.push({
nicholas@2853 320 name: "",
nicholas@2853 321 text: ""
nicholas@2853 322 });
nicholas@2855 323 };
nicholas@2857 324
nicholas@2857 325 $s.addCondition = function () {
nicholas@2857 326 $s.opt.conditions.push({
nicholas@2857 327 check: "equals",
nicholas@2857 328 value: "",
nicholas@2857 329 jumpToOnPass: undefined,
nicholas@2857 330 jumpToOnFail: undefined
nicholas@2857 331 });
nicholas@2857 332 };
nicholas@2857 333
nicholas@2857 334 $s.removeCondition = function (condition) {
nicholas@2857 335 var index = $s.opt.conditions.findIndex(function (c) {
nicholas@2857 336 return c == condition;
nicholas@2857 337 });
nicholas@2857 338 if (index === -1) {
nicholas@2857 339 throw ("Invalid Condition");
nicholas@2857 340 }
nicholas@2857 341 $s.opt.conditions.splice(index, 1);
nicholas@2857 342 };
nicholas@2855 343 }]);
nicholas@2855 344
nicholas@2855 345 AngularInterface.controller("interfaceNode", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2855 346 $s.$watch("interface.options.length", function () {
nicholas@2855 347 if (!$s.interface || !$s.interface.options) {
nicholas@2855 348 return;
nicholas@2855 349 }
nicholas@2855 350 var options = $e[0].querySelector(".interfaceOptions").querySelectorAll(".attribute");
nicholas@2855 351 options.forEach(function (option) {
nicholas@2855 352 var name = option.getAttribute("name");
nicholas@2855 353 var index = $s.interface.options.findIndex(function (io) {
nicholas@2855 354 return io.name == name;
nicholas@2855 355 });
nicholas@2855 356 option.querySelector("input").checked = (index >= 0);
nicholas@2855 357 if (name == "scalerange" && index >= 0) {
nicholas@2855 358 option.querySelector("[name=min]").value = $s.interface.options[index].min;
nicholas@2855 359 option.querySelector("[name=max]").value = $s.interface.options[index].max;
nicholas@2855 360 }
nicholas@2855 361 });
nicholas@2855 362 });
nicholas@2855 363 $s.enableInterfaceOption = function ($event) {
nicholas@2855 364 var name = $event.currentTarget.parentElement.getAttribute("name");
nicholas@2855 365 var type = $event.currentTarget.parentElement.getAttribute("type");
nicholas@2855 366 var index = $s.interface.options.findIndex(function (io) {
nicholas@2855 367 return io.name == name;
nicholas@2855 368 });
nicholas@2855 369 if (index == -1 && $event.currentTarget.checked) {
nicholas@2855 370 var obj = $s.interface.options.push({
nicholas@2855 371 name: name,
nicholas@2855 372 type: type
nicholas@2855 373 });
nicholas@2855 374 if (name == "scalerange") {
nicholas@2855 375 obj.min = $event.currentTarget.parentElement.querySelector("[name=min]").value;
nicholas@2855 376 obj.max = $event.currentTarget.parentElement.querySelector("[name=max]").value;
nicholas@2855 377 }
nicholas@2855 378 } else if (index >= 0 && !$event.currentTarget.checked) {
nicholas@2855 379 $s.interface.options.splice(index, 1);
nicholas@2855 380 }
nicholas@2857 381 };
nicholas@2886 382 $s.scales = [];
nicholas@2857 383 $s.removeScale = function (scale) {
nicholas@2857 384 var index = $s.interface.scales.findIndex(function (s) {
nicholas@2857 385 return s == scale;
nicholas@2857 386 });
nicholas@2857 387 if (index >= 0) {
nicholas@2857 388 $s.interface.scales.splice(index, 1);
nicholas@2857 389 }
nicholas@2857 390 };
nicholas@2857 391 $s.addScale = function () {
nicholas@2857 392 $s.interface.scales.push({
nicholas@2857 393 position: undefined,
nicholas@2857 394 text: undefined
nicholas@2857 395 });
nicholas@2857 396 };
nicholas@2864 397 $s.clearScales = function () {
nicholas@2864 398 $s.interface.scales = [];
nicholas@2864 399 };
nicholas@2876 400 $s.useScales = function (scale) {
nicholas@2864 401 $s.clearScales();
nicholas@2876 402 scale.scales.forEach(function (s) {
nicholas@2864 403 $s.interface.scales.push(s);
nicholas@2864 404 });
nicholas@2886 405 $s.selectedScale = scale.name;
nicholas@2864 406 };
nicholas@2886 407 $s.selectedScale = undefined;
nicholas@2886 408
nicholas@2886 409 $s.configure = function () {
nicholas@2886 410 if ($s.selectedTestPrototype === undefined) {
nicholas@2886 411 return;
nicholas@2886 412 }
nicholas@2886 413 if ($s.selectedTestPrototype.checks && $s.selectedTestPrototype.checks.length >= 1) {
nicholas@2886 414 $s.selectedTestPrototype.checks.forEach(function (entry) {
nicholas@2886 415 var dom = $e[0].querySelector("[name=\"" + entry.name + "\"] input");
nicholas@2886 416 if (entry.support == "none") {
nicholas@2886 417 dom.checked = false;
nicholas@2886 418 dom.disabled = true;
nicholas@2886 419 }
nicholas@2886 420 });
nicholas@2886 421 }
nicholas@2886 422 if ($s.selectedTestPrototype.show && $s.selectedTestPrototype.show.length >= 1) {
nicholas@2886 423 $s.selectedTestPrototype.show.forEach(function (entry) {
nicholas@2886 424 var dom = $e[0].querySelector("[name=\"" + entry.name + "\"] input");
nicholas@2886 425 if (entry.support == "none") {
nicholas@2886 426 dom.checked = false;
nicholas@2886 427 dom.disabled = true;
nicholas@2886 428 }
nicholas@2886 429 });
nicholas@2886 430 }
nicholas@2886 431 if ($s.interface !== specification.interfaces) {
nicholas@2886 432 // Page specific interface nodes
nicholas@2886 433 if ($s.selectedTestPrototype.hasScales !== undefined && ($s.selectedTestPrototype.hasScales == "false" || $s.selectedTestPrototype.hasScales == false)) {
nicholas@2886 434 var elem = $e[0].querySelector("[name=\"scale-selection\"]")
nicholas@2886 435 elem.style.visibility = "hidden";
nicholas@2886 436 elem.style.height = "0px";
nicholas@2886 437 }
nicholas@2886 438 if ($s.selectedTestPrototype.scales && $s.selectedTestPrototype.show.length >= 1) {
nicholas@2886 439 $s.scales = [];
nicholas@2886 440 $s.selectedTestPrototype.scales.forEach(function (scalename) {
nicholas@2886 441 var obj = $s.testSpecifications.scales.find(function (a) {
nicholas@2886 442 return a.name == scalename;
nicholas@2886 443 });
nicholas@2886 444 $s.scales.push(obj);
nicholas@2886 445 });
nicholas@2886 446 if ($s.selectedTestPrototype.scales.includes($s.selectedScale) == false) {
nicholas@2886 447 $s.clearScales();
nicholas@2886 448 }
nicholas@2886 449 if ($s.scales.length == 1) {
nicholas@2886 450 $s.clearScales();
nicholas@2886 451 $s.useScales($s.scales[0]);
nicholas@2886 452 }
nicholas@2886 453 } else {
nicholas@2886 454 $s.scales = $s.testSpecifications.scales;
nicholas@2886 455 }
nicholas@2886 456 }
nicholas@2886 457 };
nicholas@2886 458
nicholas@2886 459 $s.$watch("selectedTestPrototype", $s.configure);
nicholas@2886 460 $s.configure();
nicholas@2853 461 }]);
nicholas@2859 462 AngularInterface.controller("page", ['$scope', '$element', '$window', function ($s, $e, $w) {
n@2907 463 $s.schema = $w.specification.schema.querySelector("element[name=\"page\"]");
n@2909 464 $s.page.label = $s.page.label || "default";
nicholas@2859 465 $s.addInterface = function () {
nicholas@2859 466 $s.page.addInterface();
nicholas@2859 467 };
nicholas@2859 468 $s.removeInterface = function (node) {
nicholas@2859 469 var index = $s.page.interfaces.findIndex(function (a) {
nicholas@2859 470 return a == node;
nicholas@2859 471 });
nicholas@2859 472 if (index === -1) {
nicholas@2859 473 throw ("Invalid node");
nicholas@2859 474 }
nicholas@2859 475 $s.page.interfaces.splice(index, 1);
nicholas@2859 476 };
nicholas@2859 477
nicholas@2859 478 $s.addCommentQuestion = function () {
nicholas@2859 479 $s.page.addCommentQuestion();
nicholas@2859 480 };
nicholas@2859 481 $s.removeCommentQuestion = function (node) {
nicholas@2859 482 var index = $s.page.commentQuestions.findIndex(function (a) {
nicholas@2859 483 return a == node;
nicholas@2859 484 });
nicholas@2859 485 if (index === -1) {
nicholas@2859 486 throw ("Invalid node");
nicholas@2859 487 }
nicholas@2859 488 $s.page.commentQuestions.splice(index, 1);
nicholas@2859 489 };
nicholas@2859 490 $s.addAudioElement = function () {
nicholas@2859 491 $s.page.addAudioElement();
nicholas@2859 492 };
nicholas@2859 493 $s.removeAudioElement = function (element) {
nicholas@2859 494 var index = $s.page.audioElements.findIndex(function (a) {
nicholas@2859 495 return a == element;
nicholas@2859 496 });
nicholas@2859 497 if (index === -1) {
nicholas@2859 498 throw ("Invalid node");
nicholas@2859 499 }
nicholas@2859 500 $s.page.audioElements.splice(index, 1);
nicholas@2859 501 };
n@2907 502
n@2907 503 $s.placeholder = function (name) {
n@2907 504 var spec = $s.schema.querySelector("attribute[name=\"" + name + "\"]") || $w.specification.schema.querySelector("attribute[name=\"" + name + "\"]");
n@2907 505 var attr = spec.getAttribute("default");
n@2912 506 if (attr === null) {
n@2912 507 return "Not set";
n@2907 508 }
n@2907 509 return attr;
n@2907 510 }
nicholas@2859 511 }]);