[Jifty-commit] r3347 - in jifty/trunk/plugins/CodePress: lib/Jifty/Plugin/CodePress share/web/static/js

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon Jun 4 06:56:12 EDT 2007


Author: dpavlin
Date: Mon Jun  4 06:56:10 2007
New Revision: 3347

Modified:
   jifty/trunk/plugins/CodePress/lib/Jifty/Plugin/CodePress.pm
   jifty/trunk/plugins/CodePress/lib/Jifty/Plugin/CodePress/Textarea.pm
   jifty/trunk/plugins/CodePress/share/web/static/js/codepress.js

Log:
add language accessor to select syntax highlight language (instead of default generic),
example of usage, replace onload with DOM.Events

Modified: jifty/trunk/plugins/CodePress/lib/Jifty/Plugin/CodePress.pm
==============================================================================
--- jifty/trunk/plugins/CodePress/lib/Jifty/Plugin/CodePress.pm	(original)
+++ jifty/trunk/plugins/CodePress/lib/Jifty/Plugin/CodePress.pm	Mon Jun  4 06:56:10 2007
@@ -27,7 +27,9 @@
 
   render_as 'Jifty::Plugin::CodePress::Textarea';
 
-In your View replace submit button with
+In your View do something like:
+
+
 
   Jifty->web->submit( 
 	label   => _("Save"), 
@@ -39,6 +41,8 @@
 
 or if you are using L<Template::Declare>
 
+  render_param( $action => 'source', cols => 80, rows => 25, language => 'perl' );
+
   form_submit(
 	label => _("Save"),
 	onclick => [
@@ -64,7 +68,7 @@
 
 =head1 BUGS
 
-Use original CodePress onload event handler which might affect Jifty
+There seems to strange interaction between CodePress and Jifty fragments.
 
 =head1 SEE ALSO
 

Modified: jifty/trunk/plugins/CodePress/lib/Jifty/Plugin/CodePress/Textarea.pm
==============================================================================
--- jifty/trunk/plugins/CodePress/lib/Jifty/Plugin/CodePress/Textarea.pm	(original)
+++ jifty/trunk/plugins/CodePress/lib/Jifty/Plugin/CodePress/Textarea.pm	Mon Jun  4 06:56:10 2007
@@ -1,6 +1,26 @@
+use warnings;
+use strict;
+
 package Jifty::Plugin::CodePress::Textarea;
 use base qw(Jifty::Web::Form::Field::Textarea);
 
+__PACKAGE__->mk_accessors(qw(language));
+
+=head2 accessors
+
+Provide C<language> accessor, in addition to
+L<Jifty::Web::Form::Field::Textarea>'s default accessors.
+
+=cut
+
+sub accessors { shift->SUPER::accessors(), 'language' }
+
+=head2 render_widget
+
+Renders the textarea widget.
+
+=cut
+
 sub render_widget {
     my $self  = shift;
     my $field;
@@ -9,7 +29,7 @@
     $field .= qq! id="@{[ $self->element_id ]}"!;
     $field .= qq! rows="@{[$self->rows || 25]}"!;
     $field .= qq! cols="@{[$self->cols || 80]}"!;
-    $field .= $self->_widget_class( 'codepress' );
+    $field .= $self->_widget_class( 'codepress', $self->language );
     $field .= qq! >!;
     $field .= Jifty->web->escape($self->current_value) if $self->current_value;
     $field .= qq!</textarea>\n!;
@@ -18,5 +38,4 @@
     '';
 }
 
-
 1;

Modified: jifty/trunk/plugins/CodePress/share/web/static/js/codepress.js
==============================================================================
--- jifty/trunk/plugins/CodePress/share/web/static/js/codepress.js	(original)
+++ jifty/trunk/plugins/CodePress/share/web/static/js/codepress.js	Mon Jun  4 06:56:10 2007
@@ -13,7 +13,6 @@
 
 CodePress = function(obj) {
 	var self = document.createElement('iframe');
-
 	self.textarea = obj;
 	self.textarea.disabled = true;
 	self.textarea.style.overflow = 'hidden';
@@ -51,10 +50,10 @@
 	self.getLanguage = function() {
 		for (language in CodePress.languages) 
 			if(self.options.match('\\b'+language+'\\b')) 
-				return CodePress.languages[language];
+				return CodePress.languages[language] ? language : 'generic';
 		return 'generic';
 	}
-
+	
 	self.setOptions = function() {
 		if(self.options.match('autocomplete-off')) self.toggleAutoComplete();
 		if(self.options.match('readonly-on')) self.toggleReadOnly();
@@ -137,8 +136,6 @@
 	for (instance in CodePress.instances)  {
 		//CodePress.instances[ instance ].toggleEditor();
 		var i = CodePress.instances[ instance ];
-		//alert( instance + ' -- ' + i );
-
 		i.textarea.value = i.getCode();
 		i.textarea.disabled = false;
 		i.style.display = 'none';
@@ -146,5 +143,6 @@
 	}
 }
 
-if(window.attachEvent) window.attachEvent('onload',CodePress.run);
-else window.addEventListener('DOMContentLoaded',CodePress.run,false);
+//if(window.attachEvent) window.attachEvent('onload',CodePress.run);
+//else window.addEventListener('DOMContentLoaded',CodePress.run,false);
+DOM.Events.addListener(window, "load", CodePress.run);


More information about the Jifty-commit mailing list