Skip to content
Snippets Groups Projects
Commit 26882c4e authored by Brian Weaver's avatar Brian Weaver
Browse files

Update buckeye-alert module to be more 'polite'

parent 2c8423f2
No related branches found
No related tags found
No related merge requests found
.idea
.DS_Store
......@@ -3,6 +3,37 @@ Drupal 8 Buckeye Alerts
This module adds [BuckeyeAlerts](code.osu.edu/ucom/buckeye-alert) to the top of your Drupal 8 pages. The JavaScript and CSS was pulled directly from the BuckeyeAlert code.
Inclusion via Composer
------------
To add this to your composer project, you'll need to add a reference in the
repositories section and then include the project under require.
```
{
"repositories": [
{
"type": "git",
"url": "git@code.osu.edu:fcob-internal/buckeye-alert.git"
}
],
"require": {
"fcob-internal/buckeye_alert": "master",
}
}
```
Installation
------------
* Add the module code into your `modules` folder. This can be done via `composer` using the `repositories` section of `composer.json` ([documentation](https://getcomposer.org/doc/05-repositories.md))
* Add the following to your theme's info.yml
```
libraries:
- buckeye_alert/buckeye_alert
```
Usage Notes
-----------
......@@ -16,12 +47,5 @@ The settings page can be found under configuration->system->buckeye alerts. From
* **Responsive styles** -- Use the included responsive style sheet.
* **Breakpoints** -- Responsive CSS tablet and phone breakpoints.
To add the module to your site add the following to your theme's info.yml
libraries:
- buckeye_alert/buckeye_alert
Add the "Administer Buckeye Alerts" permission to any necessary roles.
......@@ -4,7 +4,7 @@
function buckeye_alert_preprocess_node(&$variables) {
function buckeye_alert_preprocess_page(&$variables) {
$config = \Drupal::config('buckeye_alert.buckeye_alert_config');
$buckeye_alert_url = $config->get('buckeye_alert_url');
......
{
"name": "fcob-internal/buckeye_alert",
"type": "drupal-module"
}
......@@ -11,6 +11,9 @@ function buckeyeAlert(settings) {
if(typeof(settings.callback)==='undefined') settings.callback = function () { };
if(typeof(settings.displayType)==='undefined') settings.display = "block";
var container = document.getElementById(settings.element_id);
container.setAttribute("aria-live", "polite");
if(window.XDomainRequest){ // For IE
var xdr = new XDomainRequest();
......@@ -66,15 +69,15 @@ function buckeyeAlert(settings) {
}
var container = document.getElementById(settings.element_id);
container.style.display = settings.display;
container.removeAttribute("hidden");
if (container.childNodes[0]) {
container.insertBefore(message, container.childNodes[0]);
} else {
container.appendChild(message);
}
container.insertBefore(heading, container.childNodes[0]);
container.setAttribute("role", "alert");
container.removeAttribute("hidden");
container.style.display = settings.display;
settings.callback();
}
......
function buckeyeAlert(a){function d(b){var c=b.getElementsByTagName("item");if(c.length){var d=document.createElement("h2");d.className="osu-semantic",d.innerHTML="Emergency alert message";var e=document.createElement("div");e.className=a.messageClass,e.setAttribute("id","buckeye_alert_msg");for(var f=0;f<c.length;f++){var g=c[f].getElementsByTagName("description")[0],h=g.textContent||g.text;"undefined"!=h&&(e.innerHTML+=h)}var i=document.getElementById(a.element_id);i.childNodes[0]?i.insertBefore(e,i.childNodes[0]):i.appendChild(e),i.insertBefore(d,i.childNodes[0]),i.setAttribute("role","alert"),i.removeAttribute("hidden"),i.style.display=a.display,a.callback()}}if("undefined"==typeof a&&(a=new Object),"undefined"==typeof a.element_id&&(a.element_id="buckeye_alert"),"undefined"==typeof a.url&&(a.url="//www.osu.edu/feeds/emergency-alert.rss"),"undefined"==typeof a.callback&&(a.callback=function(){}),"undefined"==typeof a.displayType&&(a.display="block"),window.XDomainRequest){var b=new XDomainRequest;b.open("GET",a.url),b.onprogress=function(){},b.ontimeout=function(){},b.onerror=function(){},b.onload=function(){var a;if(window.DOMParser){var c=new window.DOMParser;a=c.parseFromString(b.responseText,"text/xml")}else a=new ActiveXObject("Microsoft.XMLDOM"),a.async=!1,a.loadXML(b.responseText);d(a)},setTimeout(function(){b.send()},0)}else{var c=new XMLHttpRequest;c.onreadystatechange=function(){4==c.readyState&&200==c.status&&d(c.responseXML)},c.open("GET",a.url,!0),c.send()}}
\ No newline at end of file
function buckeyeAlert(d){if(typeof d==="undefined")d=new Object;if(typeof d.element_id==="undefined")d.element_id="buckeye_alert";if(typeof d.url==="undefined")d.url="//www.osu.edu/feeds/emergency-alert.rss";if(typeof d.callback==="undefined")d.callback=function(){};if(typeof d.displayType==="undefined")d.display="block";var e=document.getElementById(d.element_id);e.setAttribute("aria-live","polite");if(window.XDomainRequest){var n=new XDomainRequest;n.open("GET",d.url);n.onprogress=function(){};n.ontimeout=function(){};n.onerror=function(){};n.onload=function(){var e;if(window.DOMParser){var t=new window.DOMParser;e=t.parseFromString(n.responseText,"text/xml")}else{e=new ActiveXObject("Microsoft.XMLDOM");e.async=false;e.loadXML(n.responseText)}i(e)};setTimeout(function(){n.send()},0)}else{var t=new XMLHttpRequest;t.onreadystatechange=function(){if(t.readyState==4&&t.status==200){i(t.responseXML)}};t.open("GET",d.url,true);t.send()}function i(e){var t=e.getElementsByTagName("item");if(t.length){var n=document.createElement("h2");n.className="osu-semantic";n.innerHTML="Emergency alert message";var i=document.createElement("div");i.className=d.messageClass;i.setAttribute("id","buckeye_alert_msg");for(var a=0;a<t.length;a++){var r=t[a].getElementsByTagName("description")[0];var s=r.textContent||r.text;if(s!="undefined"){i.innerHTML+=s}}var o=document.getElementById(d.element_id);o.style.display=d.display;o.removeAttribute("hidden");if(o.childNodes[0]){o.insertBefore(i,o.childNodes[0])}else{o.appendChild(i)}o.insertBefore(n,o.childNodes[0]);d.callback()}}}
!function(a){a.fn.buckeyeAlert=function(b){var c=a.extend({url:"//www.osu.edu/feeds/emergency-alert.rss",callback:function(){},messageClass:null,animate:!0},b);return this.each(function(){var b=a(this);a.get(c.url,function(d){var e=a(d).find("item");if(e.length){var f=a('<div id="buckeye_alert_msg"></div>').addClass(c.messageClass);e.each(function(){f.append(a(this).find("description").text())}),b.prepend(f).prepend('<h2 class="osu-semantic">Emergency alert message</h2>').attr("role","alert").removeAttr("hidden"),c.animate?b.slideDown("fast"):b.show(),c.callback()}})})}}(jQuery),function(a){if(!a.support.cors&&a.ajaxTransport&&window.XDomainRequest){var b=/^https?:\/\//i,c=/^get|post$/i,d=new RegExp("^"+location.protocol,"i"),e=/text\/html/i,f=/\/json/i,g=/\/xml/i;a.ajaxTransport("+*",function(h,i){if(h.crossDomain&&h.async&&c.test(h.type)&&b.test(h.url)&&d.test(h.url)){var k=null,l=(i.dataType||"").toLowerCase();return{send:function(b,c){k=new XDomainRequest,/^\d+$/.test(i.timeout)&&(k.timeout=i.timeout),k.ontimeout=function(){c(500,"timeout")},k.onload=function(){var b="Content-Length: "+k.responseText.length+"\r\nContent-Type: "+k.contentType,d={code:200,message:"success"},h={text:k.responseText};try{if("html"===l||e.test(k.contentType))h.html=k.responseText;else if("json"===l||"text"!==l&&f.test(k.contentType))try{h.json=a.parseJSON(k.responseText)}catch(i){d.code=500,d.message="parseerror"}else if("xml"===l||"text"!==l&&g.test(k.contentType)){var j=new ActiveXObject("Microsoft.XMLDOM");j.async=!1;try{j.loadXML(k.responseText)}catch(i){j=void 0}if(!j||!j.documentElement||j.getElementsByTagName("parsererror").length)throw d.code=500,d.message="parseerror","Invalid XML: "+k.responseText;h.xml=j}}catch(m){throw m}finally{c(d.code,d.message,h,b)}},k.onprogress=function(){},k.onerror=function(){c(500,"error",{text:k.responseText})};var d="";i.data&&(d="string"===a.type(i.data)?i.data:a.param(i.data)),k.open(h.type,h.url),k.send(d)},abort:function(){k&&k.abort()}}}})}}(jQuery);
\ No newline at end of file
(function(a){a.fn.buckeyeAlert=function(e){var s=a.extend({url:"//www.osu.edu/feeds/emergency-alert.rss",callback:function(){},messageClass:null,animate:true},e);return this.each(function(){var r=a(this);r.attr("aria-live","polite");a.get(s.url,function(e){var t=a(e).find("item");if(t.length){var n=a('<div id="buckeye_alert_msg"></div>').addClass(s.messageClass);t.each(function(){n.append(a(this).find("description").text())});r.removeAttr("hidden").prepend(n).prepend('<h2 class="osu-semantic">Emergency alert message</h2>');if(s.animate){r.slideDown("fast")}else{r.show()}s.callback()}})})}})(jQuery);(function(l){if(!l.support.cors&&l.ajaxTransport&&window.XDomainRequest){var t=/^https?:\/\//i;var s=/^get|post$/i;var a=new RegExp("^"+location.protocol,"i");var u=/text\/html/i;var p=/\/json/i;var d=/\/xml/i;l.ajaxTransport("+*",function(n,r,e){if(n.crossDomain&&n.async&&s.test(n.type)&&t.test(n.url)&&a.test(n.url)){var i=null;var c=(r.dataType||"").toLowerCase();return{send:function(e,o){i=new XDomainRequest;if(/^\d+$/.test(r.timeout)){i.timeout=r.timeout}i.ontimeout=function(){o(500,"timeout")};i.onload=function(){var e="Content-Length: "+i.responseText.length+"\r\nContent-Type: "+i.contentType;var t={code:200,message:"success"};var n={text:i.responseText};try{if(c==="html"||u.test(i.contentType)){n.html=i.responseText}else if(c==="json"||c!=="text"&&p.test(i.contentType)){try{n.json=l.parseJSON(i.responseText)}catch(s){t.code=500;t.message="parseerror"}}else if(c==="xml"||c!=="text"&&d.test(i.contentType)){var r=new ActiveXObject("Microsoft.XMLDOM");r.async=false;try{r.loadXML(i.responseText)}catch(s){r=undefined}if(!r||!r.documentElement||r.getElementsByTagName("parsererror").length){t.code=500;t.message="parseerror";throw"Invalid XML: "+i.responseText}n.xml=r}}catch(a){throw a}finally{o(t.code,t.message,n,e)}};i.onprogress=function(){};i.onerror=function(){o(500,"error",{text:i.responseText})};var t="";if(r.data){t=l.type(r.data)==="string"?r.data:l.param(r.data)}i.open(n.type,n.url);i.send(t)},abort:function(){if(i){i.abort()}}}}})}})(jQuery);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment