No Dojo in added content JS user/dbs/nodojo_acjs
authorDan Scott <dscott@laurentian.ca>
Tue, 18 Apr 2017 01:50:03 +0000 (21:50 -0400)
committerDan Scott <dscott@laurentian.ca>
Tue, 18 Apr 2017 04:43:22 +0000 (00:43 -0400)
Dojo snuck into our added content JS as well.
Quick stab at replacing it with vanilla JS.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/templates/opac/parts/acjs.tt2
Open-ILS/src/templates/opac/parts/js.tt2

index 9d4eaa2..0167f0d 100644 (file)
@@ -1,23 +1,21 @@
-
 <script type="text/javascript">
-
+;(function() {
     /* Checks to see if a given type of added content has data to show.
      * The first arg to callback() is boolean indicating the presence of data */
     function acIsAvailable(bre_id, type, callback) {
         var url = '/opac/extras/ac/' + type + '/html/r/' + bre_id;
-        dojo.xhr('HEAD', {
-            url : url,
-            failOk : true, // http://bugs.dojotoolkit.org/ticket/11568
-            error : function(err) { callback(false, bre_id, type); },
-            load : function(result) { callback(true, bre_id, type); }
-        });
+        var req = new XMLHttpRequest();
+        req.addEventListener('load', callback(true, bre_id, type));
+        req.addEventListener('abort', callback(false, bre_id, type));
+        req.addEventListener('error', callback(false, bre_id, type));
+        req.open('HEAD', url);
     }
 
     [%-
         FOR type IN ctx.added_content.keys;
             IF ctx.added_content.$type.status == '3' # status unknown %]
 
-                dojo.addOnLoad(function() {
+                window.addEventListener('load', function() {
                     var bre_id = '[% ctx.bre_id %]';
                     var type = '[% type %]';
 
                             [% IF CGI.param('expand') == 'addedcontent' %]
 
                                 // if the content is available, un-hide the tab
-                                dojo.removeClass(dojo.byId('ac:' + type), 'hidden');
+                                var actype = document.elementById('ac:' + type);
+                                actype.class = actype.class.replace(/hidden/, '');
 
                             [% ELSE %]
                                 // if no default type is selected on the main tab link
                                 // set one here, since we have available content
 
-                                var link = dojo.query('[name=addedcontent]')[0];
+                                var link = document.querySelectorAll('[name="addedcontent"]')[0];
                                 var href = link.getAttribute('href');
                                 if (!href.match('[\&;]ac=')) {
                                     href = href.replace('#addedcontent', ';ac=' + type + '#addedcontent');
-                                    dojo.attr(link, 'href', href);
-                                    dojo.attr(dojo.query('[name=addedcontent_lbl]')[0], 'href', href);
+                                    link.href = href;
+                                    document.querySelectorAll('[name="addedcontent_lbl"]')[0].href = href;
                                 }
 
                             [% END %]
                 function(d){
                     // note if d.length == 0, there is no content to display
                     // hide the Loading... text
-                    dojo.byId('novelist-loading').innerHTML = '';
+                    document.getElementById('novelist-loading').innerHTML = '';
                 }
             )}, 100);
 [%- END; # Novelist -%]
 
         [% END; # IF ident
     %]
+})()
 </script>
index 4d5b400..534083e 100644 (file)
@@ -59,6 +59,7 @@
     IF CGI.https; url = url.replace('^http:', 'https:'); END; %]
 <script type='text/javascript' id='EIT' src='[% url %]'></script>
 [%- END %]
+[% INCLUDE "opac/parts/acjs.tt2" IF ctx.page == 'record' %]
 [%- IF want_dojo; -%]
 <script type="text/javascript">
      var djConfig = {
 </script>
 [% END; # use_autosuggest %]
 
-[% INCLUDE "opac/parts/acjs.tt2" IF ctx.page == 'record' %]
 [% INCLUDE "opac/parts/ac_google_books.tt2" IF ctx.page == 'record' AND ctx.google_books_preview %]
 [% IF ctx.page == 'advanced' %]
 <script type="text/javascript"