Last active
July 25, 2016 21:44
-
-
Save witt/9626922 to your computer and use it in GitHub Desktop.
Proof of concept. We can get item var that's not displayed in DOM by accessing Angular scope.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| myscope = angular.element('[ng-app=summonApp]').scope(); | |
| var licenseInfoUrl = "http://queens.scholarsportal.info/licenses/"; | |
| myscope.$watchCollection('feed', function() { | |
| console.log('Scope.feed changed! - loading finished.'); | |
| //delay 1 sec. to wait for DOM to actually finish loading | |
| setTimeout(function() { | |
| //for each content type display, do these | |
| $('li[ng-repeat="item in feed.items"]').each(function(index) { | |
| //console.log(index); | |
| try { | |
| if (myscope.feed.items[index].document.hasOwnProperty('publisher')) { | |
| //console.log(myscope.feed.items[index].document.publisher); | |
| var publisher = myscope.feed.items[index++].document.publisher; | |
| if(publisher.match(/Springer/g)){ | |
| console.log("its Springer "); | |
| licenseInfoUrl = "http://queens.scholarsportal.info/licenses/Springer_eBooks"; | |
| } else if(publisher.match(/Elsevier/g)){ | |
| console.log("its Elsevier"); | |
| licenseInfoUrl = "http://queens.scholarsportal.info/licenses/Elsevier"; | |
| } else { | |
| console.log("no pub license info"); | |
| licenseInfoUrl = "http://queens.scholarsportal.info/licenses/"; | |
| } | |
| } | |
| } catch(err) { | |
| console.log(err); | |
| licenseInfoUrl = "http://queens.scholarsportal.info/licenses/"; | |
| } | |
| //if it's journal article AND hasn't been processed by our custom script | |
| if ($(this).text().indexOf('Journal Article') != -1 && $(this).not('.processed').size() > 0) { | |
| //add a class called processed so we can keep track, then add a custom link | |
| $(this).addClass('processed').find('.contentType').append('Publisher: <a class="mycustomlink" href="' + licenseInfoUrl + '" target="_blank"> [License Information]</a>'); | |
| } | |
| }); | |
| }, 1000); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment