Index: iframe-proxy.php
===================================================================
RCS file: iframe-proxy.php
diff -N iframe-proxy.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ iframe-proxy.php 30 Dec 2009 10:08:14 -0000
@@ -0,0 +1,15 @@
+/U', '
', $response);
+}
+
+die($response);
Index: iframe.js
===================================================================
RCS file: iframe.js
diff -N iframe.js
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ iframe.js 30 Dec 2009 10:08:14 -0000
@@ -0,0 +1,10 @@
+Drupal.behaviors.iframe_resize = function() {
+ $('iframe[height=auto]').each(function() {
+ $(this)[0].contentWindow.onload = function() {
+ $(this)[0].frameElement.style.height = ($(this)[0].document.body.scrollHeight) + 'px';
+ $(this)[0].frameElement.scrolling = 'no';
+ };
+ $(this)[0].contentWindow.frameElement.style.height = ($(this)[0].contentWindow.document.body.scrollHeight) + 'px';
+ $(this)[0].contentWindow.frameElement.scrolling = 'no';
+ });
+}
Index: iframe.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/iframe/iframe.module,v
retrieving revision 1.12
diff -u -p -r1.12 iframe.module
--- iframe.module 10 May 2009 00:04:27 -0000 1.12
+++ iframe.module 30 Dec 2009 10:08:15 -0000
@@ -19,6 +19,14 @@ if (!function_exists('dmsg')) {
if ($level <= DEBUG_LEVEL) error_log('iframe('.$level.'): '.$text);
}
}
+
+/**
+ * Implementation of hook_init().
+ */
+function iframe_init() {
+ drupal_add_js(drupal_get_path('module', 'iframe') .'/iframe.js');
+}
+
/**
* Implementation of hook_field_info().
*/
@@ -118,7 +126,7 @@ function iframe_field_settings($op, $fie
$form['attributes']['height'] = array(
'#type' => 'textfield',
'#title' => t('height of the iframe'),
- '#description' => t('iframes need fix width and height, only numbers are allowed.'),
+ '#description' => t("Either a fixed number for pixels or 'auto' for the full height of the iframed content."),
'#default_value' => empty($field['attributes']['height']) ? '700' : $field['attributes']['height'],
'#maxlength' => 4,
'#size' => 4,
@@ -146,7 +154,7 @@ function iframe_field_settings($op, $fie
if (empty($field['attributes']['width']) || (int)$field['attributes']['width']<1) {
form_set_error('width_value', t('A default width and height must be provided.'));
}
- if (empty($field['attributes']['height']) || (int)$field['attributes']['height']<1) {
+ if (empty($field['attributes']['height']) || ((int)$field['attributes']['height'] < 1 && $field['attributes']['height'] != 'auto')) {
form_set_error('height_value', t('A default width and height must be provided.'));
}
break;
@@ -537,6 +545,7 @@ function iframe_process($element, $edit,
'#maxlength' => '4',
'#size' => '4',
'#title' => t('Height'),
+ '#description' => t("Either a fixed number for pixels or 'auto' for the full height of the iframed content."),
'#required' => ($delta == 0 && $field['height'] == 'required') ? $field['required'] : FALSE,
'#default_value' => !empty($element['#value']['attributes']['height'])? $element['#value']['attributes']['height'] : $field['attributes']['height'],
);
@@ -590,6 +599,23 @@ function theme_iframe_formatter_default(
dmsg(3,'func theme_iframe_formatter_default');
// If no url given display nothing.
if (empty($element['#item']['url'])) return '';
+
+ // We can only control an IFRAME's height if it is served from the same
+ // domain, so if it's not then we run it through our proxy.
+ if ($element['#item']['attributes']['height'] == 'auto') {
+ $url_local = parse_url(url('', array('absolute' => TRUE)));
+ $url_iframe = parse_url($element['#item']['url']);
+ if ($url_local['scheme'] != $url_iframe['scheme'] || $url_local['host'] != $url_iframe['host']) {
+ $url_options = array(
+ 'query' => array(
+ 'url' => urlencode($element['#item']['url'] . ($element['#item']['query'] ? '?'. $element['#item']['query'] : '')),
+ ),
+ 'absolute' => TRUE
+ );
+ $element['#item']['url'] = url(drupal_get_path('module', 'iframe') .'/iframe-proxy.php', $url_options);
+ }
+ }
+
// Display all
return iframe_iframe($element['#item']['display_title'], $element['#item']['url'], $element['#item']);
}
@@ -601,6 +627,23 @@ function theme_iframe_formatter_iframeon
dmsg(3,'func theme_iframe_formatter_iframeonly');
// If no url given display nothing.
if (empty($element['#item']['url'])) return '';
+
+ // We can only control an IFRAME's height if it is served from the same
+ // domain, so if it's not then we run it through our proxy.
+ if ($element['#item']['attributes']['height'] == 'auto') {
+ $url_local = parse_url(url('', array('absolute' => TRUE)));
+ $url_iframe = parse_url($element['#item']['url']);
+ if ($url_local['scheme'] != $url_iframe['scheme'] || $url_local['host'] != $url_iframe['host']) {
+ $url_options = array(
+ 'query' => array(
+ 'url' => urlencode($element['#item']['url'] . ($element['#item']['query'] ? '?'. $element['#item']['query'] : '')),
+ ),
+ 'absolute' => TRUE
+ );
+ $element['#item']['url'] = url(drupal_get_path('module', 'iframe') .'/iframe-proxy.php', $url_options);
+ }
+ }
+
// Display all
return iframe_iframe('', $element['#item']['url'], $element['#item']);
}