diff options
author | Ivan Kohler <ivan@freeside.biz> | 2013-09-03 22:52:26 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2013-09-03 22:52:26 -0700 |
commit | 36ad5e538cb56de33c779e34baf9abdf63c4312e (patch) | |
tree | de42d922496c881b69643656f055b68e64e96d72 /httemplate | |
parent | 04c1a98c9bcf2b6f0da8f18b627eec703dbafd49 (diff) | |
parent | aae697565c071b2880d0106b00a4a01d0ddab7bf (diff) |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/edit/elements/edit.html | 2 | ||||
-rw-r--r-- | httemplate/edit/msg_template.html | 7 | ||||
-rw-r--r-- | httemplate/elements/ckeditor/plugins/blockprotect/plugin.js | 128 | ||||
-rw-r--r-- | httemplate/elements/htmlarea.html | 24 | ||||
-rw-r--r-- | httemplate/elements/onload.js | 13 | ||||
-rwxr-xr-x | httemplate/search/477partIA.html | 6 | ||||
-rwxr-xr-x | httemplate/search/477partIIA.html | 2 | ||||
-rwxr-xr-x | httemplate/search/477partIIB.html | 2 | ||||
-rwxr-xr-x | httemplate/search/477partVI_census.html | 2 |
9 files changed, 160 insertions, 26 deletions
diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 08408297b..ed677d7ab 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -328,7 +328,7 @@ Example: % qw( hashref agent_virt agent_null agent_null_right ),#*-table % qw( formatted_value ), #fixed % qw( country ), #select-country -% qw( width height ), #htmlarea +% qw( width height config ), #htmlarea % qw( alt_format ), #select-cust_location % qw( classnum ), # select-inventory_item % ; diff --git a/httemplate/edit/msg_template.html b/httemplate/edit/msg_template.html index 7205ba844..06cac440e 100644 --- a/httemplate/edit/msg_template.html +++ b/httemplate/edit/msg_template.html @@ -67,7 +67,8 @@ if ( $curuser->access_right('Edit global templates') { field => 'subject', size=>60, }, { field => 'body', type => 'htmlarea', - width => 763 + width => 763, + config=> { extraPlugins => 'blockprotect' }, }, ; } else { #readonly @@ -328,8 +329,8 @@ my $widget = new HTML::Widgets::SelectLayers( my $sidebar = ' <SCRIPT TYPE="text/javascript"> function insertHtml(what) { - var oEditor = FCKeditorAPI.GetInstance("body"); - oEditor.InsertHtml(what); + var oEditor = CKEDITOR.instances["body"]; + oEditor.insertHtml(what); }; function areyousure(url, message) { diff --git a/httemplate/elements/ckeditor/plugins/blockprotect/plugin.js b/httemplate/elements/ckeditor/plugins/blockprotect/plugin.js new file mode 100644 index 000000000..61c993a9f --- /dev/null +++ b/httemplate/elements/ckeditor/plugins/blockprotect/plugin.js @@ -0,0 +1,128 @@ +/** + * The "blockprotect" plugin. Adapted from the "placeholder" plugin. + */ + +(function() { + var delim_o = '{'; + var delim_c = '}'; + + var create_block = function(content) { + // fix nbsp's + content = content.replace(/ /gi, ' '); + // escape the content + var el = document.createElement('SPAN'); + // IE8 compat + if( typeof(el.textContent) != 'undefined' ) { + el.textContent = content; + } else if( typeof(el.innerText) != 'undefined' ) { + el.innerText = content; + } + el.setAttribute('class', 'cke_blockprotect'); + return el.outerHTML; + }; + var block_writeHtml = function( element ) { + // to unescape the element contents, write it out as HTML, + // stick that into a SPAN element, and then extract the text + // content of that. + var inner_writer = new CKEDITOR.htmlParser.basicWriter; + element.writeChildrenHtml(inner_writer); + + var el = document.createElement('SPAN'); + el.innerHTML = inner_writer.getHtml(); + if( typeof(el.textContent) != 'undefined' ) { + return el.textContent; + } else if( typeof(el.innerText) != 'undefined' ) { + return el.innerText; + } + }; + var to_protected_html = function(data) { + var depth = 0; + var chunk = ''; + var out = ''; + var p = 0; // position in the string + while( 1 ) { + // find the next delimiter of either kind + var i = data.indexOf(delim_o, p); + var j = data.indexOf(delim_c, p); + if (i == -1 && j == -1) { + // then there are no more delimiters + break; + } else if ((i < j || j == -1) && i != -1) { + // next delimiter is an open + // push everything from current position to + // the delimiter + if ( i > p ) chunk += data.substr(p, i - p); + p = i + 1; + if ( depth == 0 ) { + // start of a protected block + out += chunk; + chunk = ''; + } + chunk += delim_o; + depth++; + } else if ((j < i || i == -1) && j != -1) { + // next delimiter is a close + if ( j > p ) chunk += data.substr(p, j - p); + p = j + 1; + depth--; + chunk += delim_c + if ( depth == 0 ) { + // end of a protected block + out += create_block(chunk); + chunk = ''; + } else if ( depth < 0 ) { + depth = 0; + } + } else { + // can't happen + } + } + // append any text after the last delimiter + if ( depth ) { + out += create_block(data.substr(p)); + } else { + out += data.substr(p); + } + return out; + }; + + CKEDITOR.plugins.add( 'blockprotect', { + afterInit: function( editor ) { + CKEDITOR.addCss( '.cke_blockprotect' + + '{' + + 'background-color: #ffff88;' + + ( CKEDITOR.env.gecko ? 'cursor: default;' : '' ) + + '}' + ); + + // keep these from getting stripped out + editor.filter.allow('span(cke_blockprotect)', + 'blockprotect', true); + + // add filter at the front of toHtml + editor.on( 'toHtml', + function( evt ) { + evt.data.dataValue = + to_protected_html(evt.data.dataValue); + return evt; + }, + this, null, 0 + ); + + editor.dataProcessor.htmlFilter.addRules({ + elements: { + span: function( element ) { + if ( element.className = 'cke_blockprotect' ) { + // defeat HTML escaping + var content = block_writeHtml(element); + element.writeHtml = function(writer, filter) { + writer.text(content); + } + } + } // span function + } // elements + }); + } + }); // plugins.add +}) (); + diff --git a/httemplate/elements/htmlarea.html b/httemplate/elements/htmlarea.html index f9dcffd3f..c98993d40 100644 --- a/httemplate/elements/htmlarea.html +++ b/httemplate/elements/htmlarea.html @@ -6,6 +6,7 @@ Example: 'field' => 'fieldname', 'curr_value' => $curr_value, 'height' => 800, + 'config' => { extraPlugins => 'blockprotect' }, ); </%doc> @@ -19,21 +20,24 @@ Example: <SCRIPT TYPE="text/javascript"> - CKEDITOR.replace('<% $opt{'field'} %>', { -% if ( $opt{'width'} ) { - width: <% $opt{'width'} %>, -% } - height: <% $opt{'height'} || 420 %>, - startupFocus: true, - toolbarCanCollapse: true, - basePath: '<% $p %>elements/ckeditor/', - enterMode: 2 - }); + CKEDITOR.replace('<% $opt{'field'} %>', + <% encode_json($config) %> + ); </SCRIPT> <%init> my %opt = @_; +my $config = { + 'height' => ($opt{height} || 420), + 'startupFocus' => JSON::true, + 'skin' => 'kama', + 'toolbarCanCollapse' => JSON::true, + 'basePath' => $p.'elements/ckeditor/', + 'enterMode' => 2, + %{ $opt{config} || {} }, +}; +$config->{width} = $opt{width} if defined($opt{width}); </%init> diff --git a/httemplate/elements/onload.js b/httemplate/elements/onload.js index bfa7eef94..c7bbbb283 100644 --- a/httemplate/elements/onload.js +++ b/httemplate/elements/onload.js @@ -12,11 +12,12 @@ Usage: </%doc> (function() { - var tmp = window.onload; - window.onload = function() { - if (typeof(tmp)== 'function') { - tmp(); - } + var myonload = function() { <% $m->content %> - }; + } + if ( window.addEventListener ) { + window.addEventListener('load', myonload); + } else if ( window.attachEvent ) { + window.attachEvent('onload', myonload); + } })(); diff --git a/httemplate/search/477partIA.html b/httemplate/search/477partIA.html index 1cd0b70e0..5ee44dad5 100755 --- a/httemplate/search/477partIA.html +++ b/httemplate/search/477partIA.html @@ -139,7 +139,7 @@ for ( my $row = 0; $row < scalar @upload_option; $row++ ) { my $count = FS::Record->scalar_sql($this_count_query); my $residential = FS::Record->scalar_sql($this_count_query . $is_residential); - my $percent = sprintf('%.2f', $count ? 100 * $residential / $count : 0); + my $percent = sprintf('%.3f', $count ? 100 * $residential / $count : 0); $data[$col][$row] = [ $count, $percent ]; $total_count += $count; @@ -149,10 +149,10 @@ for ( my $row = 0; $row < scalar @upload_option; $row++ ) { } my $total_percentage = - sprintf("%.2f", $total_count ? 100*$total_residential/$total_count : 0); + sprintf("%.3f", $total_count ? 100*$total_residential/$total_count : 0); my $above_200_percentage = - sprintf("%.2f", $total_count ? 100*$above_200/$total_count : 0); + sprintf("%.3f", $total_count ? 100*$above_200/$total_count : 0); my @summary_row = ( $total_count, diff --git a/httemplate/search/477partIIA.html b/httemplate/search/477partIIA.html index 95c00a3e0..907a176e5 100755 --- a/httemplate/search/477partIIA.html +++ b/httemplate/search/477partIIA.html @@ -104,7 +104,7 @@ if ( $total_lines > 0 ) { foreach (@row_conds) { my $sql = $query_ds0 . $_; my $lines = FS::Record->scalar_sql($sql); - my $percent = sprintf('%.2f', 100 * $lines / $total_lines); + my $percent = sprintf('%.3f', 100 * $lines / $total_lines); push @{ $data[0] }, $percent; } } diff --git a/httemplate/search/477partIIB.html b/httemplate/search/477partIIB.html index 5b9b30769..cb181f4fd 100755 --- a/httemplate/search/477partIIB.html +++ b/httemplate/search/477partIIB.html @@ -120,7 +120,7 @@ foreach (@col_conds) { if ( $col_data[0] == 0 ) { $col_data[$row] = ''; # show nothing in this row, then } else { - $col_data[$row] = sprintf('%.2f', 100 * $count / $col_data[0]) . '%'; + $col_data[$row] = sprintf('%.3f', 100 * $count / $col_data[0]) . '%'; } } #if $row == 0 $row++; diff --git a/httemplate/search/477partVI_census.html b/httemplate/search/477partVI_census.html index 59a6fb50d..0dafc6b21 100755 --- a/httemplate/search/477partVI_census.html +++ b/httemplate/search/477partVI_census.html @@ -75,7 +75,7 @@ push @fields, $state_pkgcount{$state} += $row->quantity; $row->quantity; }, - sub { my $row = shift; sprintf "%.2f", $row->residential }, + sub { my $row = shift; sprintf "%.3f", $row->residential }, ; my %search_hash = (); |