Skip to content

Commit

Permalink
Fix tinymce autoresize bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
issackelly committed Apr 5, 2011
1 parent c40067d commit 66e5051
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 175 deletions.
2 changes: 1 addition & 1 deletion servee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION = (0, 6, 0, "a", 1) # following PEP 386
DEV_N = "15"
DEV_N = "18"


# cribbed from pinax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"
{% block extrahead %}{{ block.super }}
{% url 'admin:jsi18n' as jsi18nurl %}
<script type="text/javascript" src="{{ jsi18nurl|default:"../../../../jsi18n/" }}"></script>
<script type="text/javascript" src="{{ jsi18nurl|default:"/admin/jsi18n/" }}"></script>
{% endblock %}
{% block extrastyle %}{{ block.super }}{% comment %}<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />{% endcomment %}{% endblock %}
{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion servee/frontendadmin/templates/servee/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE|default:"en-us" }}" xml:lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head>
<title>{% block title %}{% endblock %}</title>
Expand Down
5 changes: 2 additions & 3 deletions servee/frontendadmin/templates/servee/change_form.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{% extends "servee/base_site.html" %}
{% load i18n admin_modify servee_admin_modify adminmedia %}
"

{% block extrahead %}{{ block.super }}
{% url 'admin:jsi18n' as jsi18nurl %}
<script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>
<script type="text/javascript" src="{{ jsi18nurl|default:"/admin/jsi18n/" }}"></script>
{{ media }}
{% endblock %}

Expand All @@ -27,7 +26,7 @@
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ request.path }}" method="post" id="{{ opts.module_name }}_form" class="frontendadmin">{% csrf_token %}{% block form_top %}{% endblock %}
<div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if save_on_top %}{% submit_row %}{% endif %}
{% if save_on_top %}{% submit_row_frontendadmin %}{% endif %}
{% if errors %}
<p class="errornote">
{% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
Expand Down
4 changes: 2 additions & 2 deletions servee/frontendadmin/templates/servee/change_list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "servee/base_site.html" %}
{% load adminmedia admin_list servee_admin_list i18n %}
"

{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelists.css" />
Expand All @@ -9,7 +9,7 @@
{% endif %}
{% if cl.formset or action_form %}
{% url 'admin:jsi18n' as jsi18nurl %}
<script type="text/javascript" src="{{ jsi18nurl|default:'../../jsi18n/' }}"></script>
<script type="text/javascript" src="{{ jsi18nurl|default:'/admin/jsi18n/' }}"></script>
{% endif %}
{{ media.css }}
{% if not actions_on_top and not actions_on_bottom %}
Expand Down
24 changes: 22 additions & 2 deletions servee/frontendadmin/templatetags/servee_admin_modify.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
from django import template
from django.contrib.admin.templatetags.admin_modify import submit_row

register = template.Library()

submit_row = register.inclusion_tag('servee/_submit_line.html', takes_context=True)(submit_row)
def submit_row_frontendadmin(context):
"""
Displays the row of buttons for delete and save.
"""
opts = context['opts']
change = context['change']
is_popup = context['is_popup']
save_as = context['save_as']
return {
'onclick_attrib': (opts.get_ordered_objects() and change
and 'onclick="submitOrderForm();"' or ''),
'show_delete_link': (not is_popup and context['has_delete_permission']
and (change or context['show_delete'])),
'show_save_as_new': not is_popup and change and save_as,
'show_save_and_add_another': context['has_add_permission'] and
not is_popup and (not save_as or context['add']),
'show_save_and_continue': not is_popup and context['has_change_permission'],
'is_popup': is_popup,
'show_save': True
}
register.inclusion_tag('servee/_submit_line.html', takes_context=True)(submit_row_frontendadmin)
1 change: 1 addition & 0 deletions servee/wysiwyg/tinymce/static/servee/wysiwyg/js/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function load_wysiwyg($par){
$par.find("input, textarea").focus(function(e) {
$('#srv_wysiwyg_tools, .srv_adminBox').removeClass('out');
});
a = ed;
});
}
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,165 +1,119 @@
/**
* editor_plugin_src.js
*
* Copyright 2009, Moxiecode Systems AB
* Released under LGPL License.
*
* License: http://tinymce.moxiecode.com/license
* Contributing: http://tinymce.moxiecode.com/contributing
*/

(function() {
/**
* Auto Resize
*
* This plugin automatically resizes the content area to fit its content height.
* It will retain a minimum height, which is the height of the content area when
* it's initialized.
*/
tinymce.create('tinymce.plugins.AutoResizePlugin', {
/**
* Initializes the plugin, this will be executed after the plugin has been created.
* This call is done before the editor instance has finished it's initialization so use the onInit event
* of the editor instance to intercept that event.
*
* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
* @param {string} url Absolute URL to where the plugin is located.
*/
init : function(ed, url) {
var t = this;

if (ed.getParam('fullscreen_is_enabled'))
return;

/**
* This method gets executed each time the editor needs to resize.
*/
function resize() {
var d = ed.getDoc(), b = d.body, de = d.documentElement, DOM = tinymce.DOM, resizeHeight = t.autoresize_min_height, myHeight;

// Get height differently depending on the browser used
myHeight = (tinymce.isIE || tinymce.isWebKit || tinymce.isGecko) ? b.scrollHeight : de.offsetHeight;

// Don't make it smaller than the minimum height
if (myHeight > t.autoresize_min_height)
resizeHeight = myHeight;

// Resize content element, set scroll
DOM.setStyle(DOM.get(ed.id + '_ifr'), 'height', resizeHeight + 'px');

// if we're throbbing, we'll re-throb to match the new size
if (t.throbbing) {
ed.setProgressState(false);
ed.setProgressState(true);
}
};

t.editor = ed;

// Define minimum height
t.autoresize_min_height = ed.getElement().offsetHeight;

// Add appropriate listeners for resizing content area
ed.onChange.add(resize);
ed.onSetContent.add(resize);
ed.onPaste.add(resize);
ed.onKeyUp.add(resize);
ed.onPostRender.add(resize);

if (ed.getParam('autoresize_on_init', true)) {
// Things to do when the editor is ready
ed.onInit.add(function(ed, l) {
// Show throbber until content area is resized properly
ed.setProgressState(true);
t.throbbing = true;

// Hide scrollbars
ed.getBody().style.overflowY = "hidden";
});

ed.onLoadContent.add(function(ed, l) {
resize();

// Because the content area resizes when its content CSS loads,
// and we can't easily add a listener to its onload event,
// we'll just trigger a resize after a short loading period
setTimeout(function() {
resize();

// Disable throbber
ed.setProgressState(false);
t.throbbing = false;
}, 1250);
});
}

// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
ed.addCommand('mceAutoResize', resize);
},

/**
* Returns information about the plugin as a name/value array.
* The current keys are longname, author, authorurl, infourl and version.
*
* @return {Object} Name/value array containing information about the plugin.
*/
getInfo : function() {
return {
longname : 'Auto Resize',
author : 'Moxiecode Systems AB',
authorurl : 'http://tinymce.moxiecode.com',
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/autoresize',
version : tinymce.majorVersion + "." + tinymce.minorVersion
};
}
});

/**
* Auto Resize
*
* This plugin automatically resizes the content area to fit its content height.
* It will retain a minimum height, which is the height of the content area when
* it's initialized.
*
* Tested in: IE6, IE7, IE8 as IE7, IE8 as IE8, Safari 3, Firefox 3, Opera 9, Chrome 1
*
* Known issues: None
*
* Change log:
* - 1.2: Changed hiding all scrollbars to just hiding the vertical one, so you can still
* have a horizontal scrollbar for wide content. Also added an onload handler to the
* iframe, so that the area resizes after all of the iframe's content has loaded.
* - 1.1: Added throbber and disabled editor until we're pretty sure that all CSS has loaded.
* This should fix an issue where the content area would not resize properly on load
* for people on slower connections.
* - 1.0: Initial release
*
* Not tested with Advanced Theme "theme_advanced_resizing_min_height" and
* "theme_advanced_resizing_max_height" options.
*
* @author Springload
* @version 1.1
* @requires TinyMCE 3+
*/
tinymce.create('tinymce.plugins.AutoResizePlugin', {
/**
* Initializes the plugin, this will be executed after the plugin has been created.
* This call is done before the editor instance has finished it's initialization so use the onInit event
* of the editor instance to intercept that event.
*
* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
* @param {string} url Absolute URL to where the plugin is located.
*/
init : function(ed, url) {

// Create namespace for variables on the editor instance
tinymce.createNS('springload',ed);

// Backup TinyMCE default focus function, to prevent jumping in IE
ed.springload.defaultFocus = ed.focus;
ed.focus = function(){}

// Define minimum height in the namespace
ed.springload.autoresize_min_height = ed.getElement().offsetHeight;

// Things to do before the editor is ready
ed.onPreInit.add(function(ed) {

// Get content element, store it in the namespace
ed.springload.content_container = ed.getContentAreaContainer().firstChild;

// Add onload listener to IFRAME
if(ed.springload.content_container.tagName == 'IFRAME'){

tinymce.dom.Event.add(ed.springload.content_container, 'load', function(e) {
tinymce.EditorManager.get(ed.id).execCommand('mceAutoResize');
});

}

});

// Things to do when the editor is ready
ed.onInit.add(function(ed, l) {

// Show throbber until content area is resized properly
ed.setProgressState(true);
ed.springload.throbbing = true;

// Hide scrollbars
ed.getBody().style.overflowY = "hidden";

});

// Add appropriate listeners for resizing content area
ed.onChange.add(function(ed, l) {
ed.execCommand('mceAutoResize');
});
ed.onSetContent.add(function(ed, l) {
ed.execCommand('mceAutoResize');
});
ed.onPaste.add(function(ed, l) {
ed.execCommand('mceAutoResize');
});
ed.onKeyUp.add(function(ed, l) {
ed.execCommand('mceAutoResize');
});
ed.onPostRender.add(function(ed, l) {
ed.execCommand('mceAutoResize');
});
ed.onLoadContent.add(function(ed, l) {
ed.execCommand('mceAutoResize');
// Because the content area resizes when its content CSS loads,
// and we can't easily add a listener to its onload event,
// we'll just trigger a resize after a short loading period
setTimeout("tinymce.EditorManager.get('" + ed.id + "').execCommand('mceAutoResizeTimeout');",1250);
});

// Interval resize trigger function
ed.addCommand('mceAutoResizeTimeout', function() {
// Resize
this.execCommand('mceAutoResize');
// Disable throbber
this.setProgressState(false);
this.springload.throbbing = false;
// Restore TinyMCE default focus function
if(typeof(this.springload.defaultFocus) == "function"){
this.focus = this.springload.defaultFocus;
this.springload.defaultFocus = false;
}
});

// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
ed.addCommand('mceAutoResize', function() {
// Variables
var d = this.getDoc(), b = d.body, de = d.documentElement, DOM=tinymce.DOM, resizeHeight=this.springload.autoresize_min_height;

// Get height differently depending on the browser used
(tinymce.isIE) ? myHeight = b.scrollHeight : myHeight = de.offsetHeight;

// Don't make it smaller than the minimum height
if(myHeight > this.springload.autoresize_min_height){
resizeHeight = myHeight;
}

// Resize content element
DOM.setStyle(this.springload.content_container, 'height', resizeHeight + 'px');

// if we're throbbing, we'll re-throb to match the new size
if(this.springload.throbbing){
this.setProgressState(false);
this.setProgressState(true);
}

});


},

/**
* Returns information about the plugin as a name/value array.
* The current keys are longname, author, authorurl, infourl and version.
*
* @return {Object} Name/value array containing information about the plugin.
*/
getInfo : function() {
return {
longname : 'Auto Resize',
author : 'Springload',
authorurl : 'http://www.springload.co.nz',
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins',
version : "1.2"
};
}

});

// Register plugin
tinymce.PluginManager.add('autoresize', tinymce.plugins.AutoResizePlugin);
// Register plugin
tinymce.PluginManager.add('autoresize', tinymce.plugins.AutoResizePlugin);
})();

0 comments on commit 66e5051

Please sign in to comment.