Tuesday 19 April 2016

Another tip from Australian Islamic Library - Easiest Popup Option for Weebly users (free)

Dear readers,

We have recently implemented a popup functionality in some of our websites.
It is a really handy feature for online libraries and research repositories.

The simple steps for weebly users to include a pop-up functionality are as follows:

1. Go to 'themes' in the weebly editor and select the 'edit html/css' option.
2. Click on main_style.css and add the css code provided below. Add this code at the very bottom.
3. Click on custom.js and add the code provided below at the bottom of content.
4. Save the theme.
5. Where-ever a popup is required for inline text, add the code provided below. Don't forget to update the contents.


Now here are the codes:

CSS:

#dialogoverlay{ display: none; opacity: .8; position: fixed; top: 0px; left: 0px; background: #ff9900 width: 100%; z-index: 10; } #dialogbox{ display: none; position: fixed; background: #000; border-radius:7px; width:550px; z-index: 10; } #dialogbox > div{ background:#ff9900; margin:8px; } #dialogbox > div > #dialogboxhead{ background: #666; font-size:19px; padding:10px; color:#CCC; } #dialogbox > div > #dialogboxbody{ background: #333; padding:20px; color:#ff9900; } #dialogbox > div > #dialogboxfoot{ background: #666; padding:10px; text-align:right; }


JS:
(Update what is highlighted in red. It will be the heading of popup box)

function CustomAlert(){ this.render = function(dialog){ var winW = window.innerWidth; var winH = window.innerHeight; var dialogoverlay = document.getElementById('dialogoverlay'); var dialogbox = document.getElementById('dialogbox'); dialogoverlay.style.display = "block"; dialogoverlay.style.height = winH+"px"; dialogbox.style.left = (winW/2) - (550 * .5)+"px"; dialogbox.style.top = "100px"; dialogbox.style.display = "block"; document.getElementById('dialogboxhead').innerHTML = "Abstract"; document.getElementById('dialogboxbody').innerHTML = dialog; document.getElementById('dialogboxfoot').innerHTML = '<button onclick="Alert.ok()">OK</button>'; } this.ok = function(){ document.getElementById('dialogbox').style.display = "none"; document.getElementById('dialogoverlay').style.display = "none"; } } var Alert = new CustomAlert(); function deletePost(id){ var db_id = id.replace("post_", ""); // Run Ajax request here to delete post from database document.body.removeChild(document.getElementById(id)); } function CustomConfirm(){ this.render = function(dialog,op,id){ var winW = window.innerWidth; var winH = window.innerHeight; var dialogoverlay = document.getElementById('dialogoverlay'); var dialogbox = document.getElementById('dialogbox'); dialogoverlay.style.display = "block"; dialogoverlay.style.height = winH+"px"; dialogbox.style.left = (winW/2) - (550 * .5)+"px"; dialogbox.style.top = "100px"; dialogbox.style.display = "block"; document.getElementById('dialogboxhead').innerHTML = "Confirm that action"; document.getElementById('dialogboxbody').innerHTML = dialog; document.getElementById('dialogboxfoot').innerHTML = '<button onclick="Confirm.yes(\''+op+'\',\''+id+'\')">Yes</button> <button onclick="Confirm.no()">No</button>'; } this.no = function(){ document.getElementById('dialogbox').style.display = "none"; document.getElementById('dialogoverlay').style.display = "none"; } this.yes = function(op,id){ if(op == "delete_post"){ deletePost(id); } document.getElementById('dialogbox').style.display = "none"; document.getElementById('dialogoverlay').style.display = "none"; } } var Confirm = new CustomConfirm();



HTML CODE FOR PLACEMENT WHERE THE LINK IS REQUIRED:
(Update what is highlighted in red. This will be your content in the popup box)


<div id="dialogoverlay"></div> <div id="dialogbox"> <div> <div id="dialogboxhead"></div> <div id="dialogboxbody"></div> <div id="dialogboxfoot"></div> </div> </div> <button onclick="Alert.render('Hello World')">Custom Alert</button>