From de551634c676831a1c0c9b2acd23f86230683d58 Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Mon, 20 May 2013 00:18:48 -0400
Subject: initial implentation of preview frame, add semi-fade fragment style,
data-full-height support
---
js/reveal.js | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 136 insertions(+), 6 deletions(-)
(limited to 'js/reveal.js')
diff --git a/js/reveal.js b/js/reveal.js
index 4ff34c9..d4532ac 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -70,6 +70,9 @@ var Reveal = (function(){
// Apply a 3D roll to links on hover
rollingLinks: true,
+ // Opens links in an iframe preview overlay
+ previewLinks: false,
+
// Theme (see /css/theme)
theme: null,
@@ -380,12 +383,21 @@ var Reveal = (function(){
document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
}
- // 3D links
+ // Rolling 3D links
if( config.rollingLinks ) {
- enable3DLinks();
+ enableRollingLinks();
+ }
+ else {
+ disableRollingLinks();
+ }
+
+ // Iframe link previews
+ if( config.previewLinks ) {
+ enablePreviewLinks();
}
else {
- disable3DLinks();
+ disablePreviewLinks();
+ enablePreviewLinks( '[data-preview-link]' );
}
// Load the theme in the config, if it's not already loaded
@@ -560,7 +572,7 @@ var Reveal = (function(){
/**
* Wrap all links in 3D goodness.
*/
- function enable3DLinks() {
+ function enableRollingLinks() {
if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
@@ -585,7 +597,7 @@ var Reveal = (function(){
/**
* Unwrap all 3D links.
*/
- function disable3DLinks() {
+ function disableRollingLinks() {
var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
@@ -601,6 +613,110 @@ var Reveal = (function(){
}
+ /**
+ * Retrieves the height of the given element by looking
+ * at the position and height of its immediate children.
+ */
+ function getAbsoluteHeight( element ) {
+
+ var height = 0;
+
+ if( element ) {
+
+ toArray( element.childNodes ).forEach( function( child ) {
+ height = Math.max( height, child.offsetTop + child.offsetHeight );
+ } );
+
+ }
+
+ return height;
+
+ }
+
+ /**
+ * Bind preview frame links.
+ */
+ function enablePreviewLinks( selector ) {
+
+ var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) );
+
+ anchors.forEach( function( element ) {
+ if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
+ element.addEventListener( 'click', onPreviewLinkClicked, false );
+ }
+ } );
+
+ }
+
+ /**
+ * Unbind preview frame links.
+ */
+ function disablePreviewLinks() {
+
+ var anchors = toArray( document.querySelectorAll( 'a' ) );
+
+ anchors.forEach( function( element ) {
+ if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
+ element.removeEventListener( 'click', onPreviewLinkClicked, false );
+ }
+ } );
+
+ }
+
+ /**
+ * Opens a preview window for the target URL.
+ */
+ function openPreview( url ) {
+
+ closePreview();
+
+ dom.preview = document.createElement( 'div' );
+ dom.preview.classList.add( 'preview-link-overlay' );
+ dom.wrapper.appendChild( dom.preview );
+
+ dom.preview.innerHTML = [
+ '