Re-organised and migrated id to class
Instead of IDs being used this has been changed to HTML classes to allow for multiple items to arise from the same property. Along side this CasparCG.js now checks if the entity is an img tag and replace src as opposed to innerHTML.
This commit is contained in:
parent
744b52541e
commit
fdb9ff8992
@ -1,28 +1,17 @@
|
||||
/*
|
||||
* Data sent from CasparCG Client as templateData
|
||||
* is pushed into corresponding HTML id element
|
||||
*
|
||||
* Usage:
|
||||
* insert a script reference in the HTML template header.
|
||||
* ex: <script type="text/javascript" src="CasparCG.js"></script>
|
||||
* Make sure that the id that you refer to is the innermost tag.
|
||||
* Everything within that tag id will be replaced by the value sent from CasparCG
|
||||
*
|
||||
* put together by Tomas Linden
|
||||
* modified by Øjvind Søgaard Andersen
|
||||
*
|
||||
Structure of data sent from CasparCG:
|
||||
<templateData>
|
||||
<componentData id="#idCaspar#">
|
||||
<data id="text" value="#valCaspar#" />
|
||||
</componentData>
|
||||
:
|
||||
:
|
||||
<componentData id="#idCaspar#">
|
||||
<data id="text" value="#valCaspar#" />
|
||||
</componentData>
|
||||
</templateData>
|
||||
*/
|
||||
* Usage:
|
||||
* insert a script reference in the HTML header.
|
||||
* ex: <script type="text/javascript" src="CasparCG.js"></script>
|
||||
* Make sure that the class that you refer to is the innermost tag.
|
||||
* Either the item will have it's content replace or src updated if an image
|
||||
*
|
||||
* Items with classes 'CasparCG-XXX' will be replaced
|
||||
* So f0 would have the class 'CasparCG-f0'
|
||||
*
|
||||
* put together by Tomas Linden
|
||||
* modified by Mark Rapson
|
||||
*/
|
||||
|
||||
// Global variable for data from CasparCG
|
||||
var dataCaspar = {};
|
||||
|
||||
@ -58,9 +47,19 @@ function XML2JSON(node) {
|
||||
// Main function to insert data
|
||||
function dataInsert(dataCaspar) {
|
||||
for (var idCaspar in dataCaspar) {
|
||||
var idTemplate = document.getElementById(idCaspar);
|
||||
if (idTemplate != undefined) {
|
||||
idTemplate.innerHTML = escapeHtml(dataCaspar[idCaspar]);
|
||||
var applicableElements = document.getElementsByClassName('CasparCG-' + idCaspar);
|
||||
if (applicableElements) {
|
||||
// Loop through Applicable DIVs
|
||||
[].slice.call(applicableElements).forEach(function(currentElement) {
|
||||
console.log(currentElement.tagName);
|
||||
if (currentElement.tagName == 'img') {
|
||||
//Set Image if img item
|
||||
currentElement.src = dataCaspar[idCaspar];
|
||||
} else {
|
||||
//Set InnerHTML otherwise
|
||||
currentElement.innerHTML = escapeHtml(dataCaspar[idCaspar]);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
87
Example Project/CasparCG0.js
Normal file
87
Example Project/CasparCG0.js
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Usage:
|
||||
* insert a script reference in the HTML header.
|
||||
* ex: <script type="text/javascript" src="CasparCG.js"></script>
|
||||
* Make sure that the class that you refer to is the innermost tag.
|
||||
* Either the item will have it's content replace or src updated if an image
|
||||
*
|
||||
* Items with classes 'CasparCG-XXX' will be replaced
|
||||
* So f0 would have the class 'CasparCG-f0'
|
||||
*
|
||||
* put together by Tomas Linden
|
||||
* modified by Mark Rapson
|
||||
*/
|
||||
|
||||
// Global variable for data from CasparCG
|
||||
var dataCaspar = {};
|
||||
|
||||
// Replace characters that could become a problem if left as is
|
||||
function escapeHtml(unsafe) {
|
||||
return unsafe.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
||||
}
|
||||
|
||||
// Parse templateData into an XML object
|
||||
function parseCaspar(str) {
|
||||
var xmlDoc;
|
||||
if (window.DOMParser) {
|
||||
parser = new DOMParser();
|
||||
xmlDoc = parser.parseFromString(str, "text/xml");
|
||||
}
|
||||
dataCaspar = XML2JSON(xmlDoc.documentElement.childNodes);
|
||||
}
|
||||
|
||||
|
||||
// Make the XML templateData message into a more simple key:value object
|
||||
function XML2JSON(node) {
|
||||
var data = {}; // resulting object
|
||||
for (k = 0; k < node.length; k++) {
|
||||
var idCaspar = node[k].getAttribute("id");
|
||||
var valCaspar = node[k].childNodes[0].getAttribute("value");
|
||||
if (idCaspar != undefined && valCaspar != undefined) {
|
||||
data[idCaspar] = valCaspar;
|
||||
};
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// Main function to insert data
|
||||
function dataInsert(dataCaspar) {
|
||||
for (var idCaspar in dataCaspar) {
|
||||
var applicableElements = document.getElementsByClassName('CasparCG-' + idCaspar);
|
||||
if (applicableElements) {
|
||||
// Loop through Applicable DIVs
|
||||
[].slice.call(applicableElements).forEach(function(currentElement) {
|
||||
console.log(currentElement.tagName);
|
||||
if (currentElement.tagName == 'img') {
|
||||
//Set Image if img item
|
||||
currentElement.src = dataCaspar[idCaspar];
|
||||
} else {
|
||||
//Set InnerHTML otherwise
|
||||
currentElement.innerHTML = escapeHtml(dataCaspar[idCaspar]);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call for a update of data from CasparCG client
|
||||
function update(str) {
|
||||
parseCaspar(str); // Parse templateData into an XML object
|
||||
dataInsert(dataCaspar); // Insert data
|
||||
}
|
||||
|
||||
// insert data from CasparCg client when activated
|
||||
function play(str) {
|
||||
parseCaspar(str); // Parse templateData into an XML object
|
||||
dataInsert(dataCaspar); // Insert data
|
||||
}
|
||||
|
||||
// Call for a next from CasparCG client
|
||||
function next() {
|
||||
gwd.actions.timeline.play('document.body');
|
||||
}
|
||||
|
||||
// Call for a stop from CasparCG client
|
||||
function stop() {
|
||||
gwd.actions.timeline.gotoAndPlay('document.body', 'stop');
|
||||
}
|
@ -276,8 +276,8 @@
|
||||
<body class="htmlNoPages" data-gwd-animation-labels="stop,4500">
|
||||
<svg data-gwd-shape="rectangle" class="gwd-rect-157e gwd-gen-lz8mgwdanimation gwd-svg-40l0"></svg>
|
||||
<svg data-gwd-shape="rectangle" class="gwd-rect-157e gwd-gen-eb0kgwdanimation gwd-rect-ptf0"></svg>
|
||||
<p class="gwd-p-hxjo gwd-gen-1hvogwdanimation gwd-p-1hcy" id="f0">This is f0</p>
|
||||
<p class="gwd-p-hxjo gwd-gen-1gmrgwdanimation gwd-p-1i4z" id="f1">This is f1</p>
|
||||
<p class="gwd-p-hxjo gwd-gen-1hvogwdanimation gwd-p-1hcy CasparCG-f0">This is f0</p>
|
||||
<p class="gwd-p-hxjo gwd-gen-1gmrgwdanimation gwd-p-1i4z CasparCG-f1">This is f1</p>
|
||||
<div class="gwd-animation-event event-1-animation" data-event-name="event-1" data-event-time="1500"></div>
|
||||
<div class="gwd-animation-event event-2-animation" data-event-name="event-2" data-event-time="2000"></div>
|
||||
<div class="gwd-animation-event event-3-animation" data-event-name="event-3" data-event-time="2500"></div>
|
@ -1,28 +1,17 @@
|
||||
/*
|
||||
* Data sent from CasparCG Client as templateData
|
||||
* is pushed into corresponding HTML id element
|
||||
*
|
||||
* Usage:
|
||||
* insert a script reference in the HTML template header.
|
||||
* ex: <script type="text/javascript" src="CasparCG.js"></script>
|
||||
* Make sure that the id that you refer to is the innermost tag.
|
||||
* Everything within that tag id will be replaced by the value sent from CasparCG
|
||||
*
|
||||
* put together by Tomas Linden
|
||||
* modified by Øjvind Søgaard Andersen
|
||||
*
|
||||
Structure of data sent from CasparCG:
|
||||
<templateData>
|
||||
<componentData id="#idCaspar#">
|
||||
<data id="text" value="#valCaspar#" />
|
||||
</componentData>
|
||||
:
|
||||
:
|
||||
<componentData id="#idCaspar#">
|
||||
<data id="text" value="#valCaspar#" />
|
||||
</componentData>
|
||||
</templateData>
|
||||
*/
|
||||
* Usage:
|
||||
* insert a script reference in the HTML header.
|
||||
* ex: <script type="text/javascript" src="CasparCG.js"></script>
|
||||
* Make sure that the class that you refer to is the innermost tag.
|
||||
* Either the item will have it's content replace or src updated if an image
|
||||
*
|
||||
* Items with classes 'CasparCG-XXX' will be replaced
|
||||
* So f0 would have the class 'CasparCG-f0'
|
||||
*
|
||||
* put together by Tomas Linden
|
||||
* modified by Mark Rapson
|
||||
*/
|
||||
|
||||
// Global variable for data from CasparCG
|
||||
var dataCaspar = {};
|
||||
|
||||
@ -58,9 +47,19 @@ function XML2JSON(node) {
|
||||
// Main function to insert data
|
||||
function dataInsert(dataCaspar) {
|
||||
for (var idCaspar in dataCaspar) {
|
||||
var idTemplate = document.getElementById(idCaspar);
|
||||
if (idTemplate != undefined) {
|
||||
idTemplate.innerHTML = escapeHtml(dataCaspar[idCaspar]);
|
||||
var applicableElements = document.getElementsByClassName('CasparCG-' + idCaspar);
|
||||
if (applicableElements) {
|
||||
// Loop through Applicable DIVs
|
||||
[].slice.call(applicableElements).forEach(function(currentElement) {
|
||||
console.log(currentElement.tagName);
|
||||
if (currentElement.tagName == 'img') {
|
||||
//Set Image if img item
|
||||
currentElement.src = dataCaspar[idCaspar];
|
||||
} else {
|
||||
//Set InnerHTML otherwise
|
||||
currentElement.innerHTML = escapeHtml(dataCaspar[idCaspar]);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
@ -1250,8 +1250,8 @@ body {
|
||||
<body class="htmlNoPages">
|
||||
<svg data-gwd-shape="rectangle" class="gwd-rect-157e gwd-gen-lz8mgwdanimation gwd-svg-40l0"></svg>
|
||||
<svg data-gwd-shape="rectangle" class="gwd-rect-157e gwd-gen-eb0kgwdanimation gwd-rect-ptf0"></svg>
|
||||
<p class="gwd-p-hxjo gwd-gen-1hvogwdanimation gwd-p-1hcy" id="f0">This is f0</p>
|
||||
<p class="gwd-p-hxjo gwd-gen-1gmrgwdanimation gwd-p-1i4z" id="f1">This is f1</p>
|
||||
<p class="gwd-p-hxjo gwd-gen-1hvogwdanimation gwd-p-1hcy CasparCG-f0">This is f0</p>
|
||||
<p class="gwd-p-hxjo gwd-gen-1gmrgwdanimation gwd-p-1i4z CasparCG-f1">This is f1</p>
|
||||
<div class="gwd-animation-event event-1-animation" data-event-name="event-1" data-event-time="1500"></div>
|
||||
<div class="gwd-animation-event event-2-animation" data-event-name="event-2" data-event-time="2000"></div>
|
||||
<div class="gwd-animation-event event-3-animation" data-event-name="event-3" data-event-time="2500"></div>
|
Loading…
x
Reference in New Issue
Block a user