Building a custom JavaScript recipe for CONTENTdm

15
Ask the Experts – March 4, 2020 Building a custom JavaScript recipe for CONTENTdm Shane Huddleston Product Manager, OCLC

Transcript of Building a custom JavaScript recipe for CONTENTdm

Page 1: Building a custom JavaScript recipe for CONTENTdm

Ask the Experts – March 4, 2020

Building a custom JavaScript recipe for CONTENTdm

Shane HuddlestonProduct Manager, OCLC

Page 2: Building a custom JavaScript recipe for CONTENTdm

• Some background resources

• Anatomy of a JavaScript recipe

• Let’s building a recipe!

• Questions

The plan for today

Page 3: Building a custom JavaScript recipe for CONTENTdm

Helpful links

https://tinyurl.com/js-recipe-workshop

Page 4: Building a custom JavaScript recipe for CONTENTdm

Resourceshelp.oclc.org

(search for “website customization”)

CONTENTdm Cookbook

Demo sitecdmdemo.contentdm.oclc.org

Page 5: Building a custom JavaScript recipe for CONTENTdm

• Function wrapper(IIFE: Immediately Invoked Function Expression)

• Doing the thing you want to do

• Timing the action within the page lifecycle

Anatomy of a JS recipe

Page 6: Building a custom JavaScript recipe for CONTENTdm

(function() {

// do stuff here

})();

Page 7: Building a custom JavaScript recipe for CONTENTdm

(function() {

function logger(text) {console.log("msg: ", text);}

})();

Page 8: Building a custom JavaScript recipe for CONTENTdm

CONTENTdm event lifecyclestartup / load JS file(s)

cdm-app:ready

cdm-page:enter

cdm-page:ready

cdm-page:leave

Page 9: Building a custom JavaScript recipe for CONTENTdm

The “update” eventstartup / load JS file(s)

cdm-app:ready

cdm-page:enter

cdm-page:ready

cdm-page:leave

cdm-page:update

Page 10: Building a custom JavaScript recipe for CONTENTdm

(function() {

function logger(text) {console.log('msg: ', text);}

document.addEventListener('cdm-app:ready', function() {

logger('hello, world');

});})();

Page 11: Building a custom JavaScript recipe for CONTENTdm

• Insert “Follow” button in page footers

• Adhere to Twitter’s development guide

• Use Twitter’s helper library

• Make sure button doesn’t get duplicated

Build Twitter “Follow” button

Page 12: Building a custom JavaScript recipe for CONTENTdm

Looking at the code

https://tinyurl.com/js-recipe-workshop

Page 13: Building a custom JavaScript recipe for CONTENTdm

• Load Twitter’s official helper script

• Insert HTML button into page footer

• Event lifecycle timing is crucial

How the recipe works

Page 14: Building a custom JavaScript recipe for CONTENTdm

• Website Configuration Tool

• Global > Custom > Custom Scripts

• Browse to twitter-follow-button.js file

• Save & Publish

Loading the recipe

Page 15: Building a custom JavaScript recipe for CONTENTdm

Questions?