# Copyright (c) 1999-2010 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: JavaScript.pm,v 2.9 2011/05/09 23:05:53 moeller Exp $ package Bivio::UI::HTML::Widget::JavaScript; use strict; use Bivio::Base 'Bivio::UI::Widget'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.9 $ =~ /\d+/g); my($_COMMON_CODE) = __PACKAGE__ . '.common_code'; my($_ID) = 0; sub BASE_VAR_NAME { return 'window.bivio'; } sub escape_string { my($self, $text) = @_; # Converts a text string into something safely escaped. # Returns its first argument. $$text =~ s/\\/\\\\/g; $$text =~ s/'/\\'/g; $$text =~ s/\n/\\n/g; $$text =~ s#/#\\/#g; return $text; } sub has_been_rendered { my(undef, $source, $module_tag) = @_; # returns true if common code has been rendered. return exists(($source->get_request->unsafe_get($_COMMON_CODE) || {}) ->{$module_tag}); } sub render { my($self, $source, $buffer, $module_tag, $common_code, # Render the JavaScript version tag if not already rendered. # Renders the I for I if not already # rendered. Renders I"; } # Render noscript $$buffer .= '' if defined($no_script_html); return; } sub strip { my(undef, $code) = @_; # Strips leading blanks and comments. # Strip leading blanks and blank lines $code =~ s/^\s+//sg; $code =~ s/\n\s+/\n/g; $code =~ s{^\s*//.*\n}{}mg; return $code; } sub unique_html_id { return 'b_js' . ++$_ID; } sub var_name { my($self, $suffix) = @_; return $self->BASE_VAR_NAME . ".$suffix"; } sub _render_script_in_head { my($self, $req, $buffer) = @_; # render the common code in "; return; } 1;