I copied the JS from the webpage but when i look at it in dreamweaver it shows half of it commented out and highlights a line as having an error which is probably to do with parts being commented out and i also don’t recognise the beginning tags. Does this look correct? i am not very good with JS so it’s a steep learning curve at the moment. any help appreciated
[sourcecode language='javascript' padlinenumbers='true' htmlscript='false' gutter='true']
(function () { document.write('<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
<\/script>');
document.write('<script src="/Style%20Library/CriticalNews/js/homepage_message.js"><\/script>');
document.write('<link rel="stylesheet" type="text/css" href="/Style%20Library/CriticalNews/css/homepage_message.css" />');
// Load our custom CSS
/*
var cssId = 'myCss';
// you could encode the css path itself to generate id..
if (!document.getElementById(cssId)) { var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = cssId; link.rel = 'stylesheet'; link.type = 'text/css';
link.href = '/Style Library/CriticalNews/css/homepage_message.css';
link.media = 'all'; head.appendChild(link); }*/
/* * Initialize the variable that store the overrides objects. */
var overrideCtx = {}; overrideCtx.Templates = {};
// Assign functions or plain html strings to the templateset objects:
// header, footer and item.
overrideCtx.Templates.Header = "<div class='center'>";
overrideCtx.Templates.Footer = "</div>";
// This template is assigned to the CustomItem function. overrideCtx.Templates.Item = CustomItem;
//overrideCtx.BaseViewID = 1;
overrideCtx.ListTemplateType = 104;
// Register the template overrides. SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx); })();
/* * This function builds the output for the item template. * Uses the Context object to access announcement data. */
function CustomItem(ctx) { // Build a listitem entry for every announcement in the list.
/* <div class="notification fail canhide"><span>ERROR!</span> This is an error message.</div>
<div class="notification info canhide"><span>INFORMATION:</span> This is an information.</div>
<div class="notification warning canhide"><span>WARNING!</span> This is a warning message.</div> */
//var ret = "<li>This is a " + ctx.CurrentItem.MoreText + "</li>";
if (ctx.CurrentItem["MessageType"] == "Informational (blue)") {
var ret = "<div class='notification info'>" + ctx.CurrentItem["Body"].replace("<p>","").replace("</p>","") + "</div>";
}
else if (ctx.CurrentItem["MessageType"] == "Warning (yellow)") {
var ret = "<div class='notification warning'>" + ctx.CurrentItem["Body"].replace("<p>","").replace("</p>","") + "</div>";
}
else if (ctx.CurrentItem["MessageType"] == "Critical (red)") {
var ret = "<div class='notification fail'>" + ctx.CurrentItem["Body"].replace("<p>","").replace("</p>","") + "</div>"; }
return ret;
}
[/source-code]
(function () {
document.write("<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'>;<\/script>;");
document.write("<script src='/Style%20Library/CriticalNews/js/homepage_message.js'>;<\/script>;");
document.write("<link rel='stylesheet' type='text/css' href='/Style%20Library/CriticalNews/css/homepage_message.css' />;");
// Load our custom CSS
/*var cssId = "myCss"; // you could encode the css path itself to generate id..
if (!document.getElementById(cssId))
{
var head = document.getElementsByTagName("head")[0];
var link = document.createElement("link");
link.id = cssId;
link.rel = "stylesheet";
link.type = "text/css";
link.href = "/Style Library/CriticalNews/css/homepage_message.css";
link.media = "all";
head.appendChild(link);
}*/
/*
* Initialize the variable that store the overrides objects.
*/
var overrideCtx = {};
overrideCtx.Templates = {};
// Assign functions or plain html strings to the templateset objects:
// header, footer and item.
overrideCtx.Templates.Header = "<div class='center'>;";
overrideCtx.Templates.Footer = "</div>;";
// This template is assigned to the CustomItem function.
overrideCtx.Templates.Item = CustomItem;
//overrideCtx.BaseViewID = 1;
overrideCtx.ListTemplateType = 104;
// Register the template overrides.
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
}());
/*
* This function builds the output for the item template.
* Uses the Context object to access announcement data.
*/
function CustomItem(ctx) {
// Build a listitem entry for every announcement in the list.
/*
<div class="notification fail canhide">;<span>;ERROR!</span>; This is an error message.</div>;
<div class="notification info canhide">;<span>;INFORMATION:</span>; This is an information.</div>;
<div class="notification warning canhide">;<span>;WARNING!</span>; This is a warning message.</div>;
*/
//var ret = "<li>;This is a " + ctx.CurrentItem.MoreText + "</li>;";
var ret = "";
if (ctx.CurrentItem.MessageType === "Informational (blue)") {
ret = "<div class='notification info'>;" + ctx.CurrentItem.Body.replace("<p>;", "").replace("</p>;", "") + "</div>;";
} else if (ctx.CurrentItem.MessageType === "Warning (yellow)") {
ret = "<div class='notification warning'>;" + ctx.CurrentItem.Body.replace("<p>;", "").replace("</p>;", "") + "</div>;";
} else if (ctx.CurrentItem.MessageType === "Critical (red)") {
ret = "<div class='notification fail'>;" + ctx.CurrentItem.Body.replace("<p>;", "").replace("</p>;", "") + "</div>;";
}
return ret;
}
I’ve taken the liberty of running the code through JsBeautifier, and using JSLint to help me remove the most egregious problems with the code.
ok so i’ve tried implementing that and nothing happened so i checked the links in the code and there is an error message of
<?xml version="1.0" encoding="utf-8"?><Error><Code>BlobNotFound</Code><Message>The specified blob does not exist. RequestId:e0a529b8-001e-002c-1e2c-5d518b000000 Time:2017-11-14T09:36:51.0420864Z</Message></Error>
I’ve tested all 3 links within the code and they all return ok. (my links are absolute in the final code i just removed my domain etc for displaying here). Any ideas what the BlobNotFound would refer to?