"None"-Layout: alle JavaScript-Setup-Funktionen in einer Funktion zusammengefasst
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 5 Mar 2013 09:30:37 +0000 (10:30 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 5 Mar 2013 09:31:37 +0000 (10:31 +0100)
SL/Layout/None.pm
templates/webpages/layout/ajax_spinner_setup.js [deleted file]
templates/webpages/layout/focus_setup.html [deleted file]
templates/webpages/layout/javascript_setup.html [deleted file]
templates/webpages/layout/javascript_setup.js [new file with mode: 0644]

index ffd5bb5..c3708bf 100644 (file)
@@ -6,9 +6,21 @@ use parent qw(SL::Layout::Base);
 use List::MoreUtils qw(apply);
 
 sub javascripts_inline {
-  _setup_formats(),
-  _setup_focus(),
-  _setup_ajax_spinner(),
+  my ($self)  = @_;
+
+  my $datefmt = apply {
+    s/d+/dd/gi;
+    s/m+/mm/gi;
+    s/y+/yy/gi;
+  } $::myconfig{dateformat};
+
+  return $self->render(
+    'layout/javascript_setup',
+    { type => 'js', output => 0, },
+    datefmt      => $datefmt,
+    focus        => $::request->layout->focus,
+    ajax_spinner => 1,
+  );
 }
 
 sub use_javascript {
@@ -29,28 +41,4 @@ sub use_stylesheet {
   $self->SUPER::use_stylesheet(@_);
 }
 
-sub _setup_formats {
-  my $datefmt = apply {
-    s/d+/dd/gi;
-    s/m+/mm/gi;
-    s/y+/yy/gi;
-  } $::myconfig{dateformat};
-
-  $::form->parse_html_template('layout/javascript_setup', { datefmt => $datefmt });
-}
-
-sub _setup_focus {
-  if ($::request->{layout}->focus) {
-    return $::form->parse_html_template('layout/focus_setup', {
-      focus => $::request->{layout}->focus,
-    })
-  } else {
-    return ();
-  }
-}
-
-sub _setup_ajax_spinner {
-  return SL::Presenter->get->render('layout/ajax_spinner_setup', { type => 'js' });
-}
-
 1;
diff --git a/templates/webpages/layout/ajax_spinner_setup.js b/templates/webpages/layout/ajax_spinner_setup.js
deleted file mode 100644 (file)
index 675c7e6..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-$(function() {
-  $(document).ajaxSend(function() {
-    $('#ajax-spinner').show();
-  }).ajaxStop(function() {
-    $('#ajax-spinner').hide();
-  });
-});
diff --git a/templates/webpages/layout/focus_setup.html b/templates/webpages/layout/focus_setup.html
deleted file mode 100644 (file)
index e97fb69..0000000
+++ /dev/null
@@ -1 +0,0 @@
-function fokus(){ [% IF focus %]$('[% focus %]').focus()[% END %] }
diff --git a/templates/webpages/layout/javascript_setup.html b/templates/webpages/layout/javascript_setup.html
deleted file mode 100644 (file)
index 3508ef8..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-[%- USE T8 %]
-$(function() {
-  setupPoints('[% myconfig.numberformat %]', '[% 'wrongformat' | $T8 %]');
-  setupDateFormat('[% myconfig.dateformat %]', '[% 'Falsches Datumsformat!' | $T8 %]');
-
-  $.datepicker.setDefaults(
-    $.extend({}, $.datepicker.regional["[% myconfig.countrycode %]"], {
-      dateFormat: "[% datefmt %]",
-      showOn: "button",
-      showButtonPanel: true,
-      changeMonth: true,
-      changeYear: true,
-      buttonImage: "image/calendar.png",
-      buttonImageOnly: true
-  }));
-
-  $('.datepicker').each(function() {
-    $(this).datepicker();
-  });
-})
diff --git a/templates/webpages/layout/javascript_setup.js b/templates/webpages/layout/javascript_setup.js
new file mode 100644 (file)
index 0000000..dc51634
--- /dev/null
@@ -0,0 +1,36 @@
+[%- USE T8 %]
+$(function() {
+[% IF datefmt %]
+  setupPoints('[% MYCONFIG.numberformat %]', '[% 'wrongformat' | $T8 %]');
+  setupDateFormat('[% MYCONFIG.dateformat %]', '[% 'Falsches Datumsformat!' | $T8 %]');
+
+  $.datepicker.setDefaults(
+    $.extend({}, $.datepicker.regional["[% MYCONFIG.countrycode %]"], {
+      dateFormat: "[% datefmt %]",
+      showOn: "button",
+      showButtonPanel: true,
+      changeMonth: true,
+      changeYear: true,
+      buttonImage: "image/calendar.png",
+      buttonImageOnly: true
+  }));
+
+  $('.datepicker').each(function() {
+    $(this).datepicker();
+  });
+[% END %]
+
+[% IF ajax_spinner %]
+  $(document).ajaxSend(function() {
+    $('#ajax-spinner').show();
+  }).ajaxStop(function() {
+    $('#ajax-spinner').hide();
+  });
+[% END %]
+});
+
+function fokus() {
+[%- IF focus -%]
+  $('[% focus %]').focus();
+[%- END -%]
+}