Ajax Layout Wrapper für CRM und LxCars
authorSven Schöling <s.schoeling@linet-services.de>
Tue, 16 Oct 2012 14:35:54 +0000 (16:35 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Wed, 17 Oct 2012 14:04:08 +0000 (16:04 +0200)
js/ajax_layout.js [new file with mode: 0644]

diff --git a/js/ajax_layout.js b/js/ajax_layout.js
new file mode 100644 (file)
index 0000000..694e1c5
--- /dev/null
@@ -0,0 +1,44 @@
+function load_layout(baseURL){
+  $.ajax({
+    url: baseURL + 'controller.pl?action=Layout/empty&format=json',
+    method: 'GET',
+    dataType: 'json',
+    success: function (data) {
+      if (data["stylesheets"]) {
+        $.each(data["stylesheets"], function(i, e){
+          $('head').append('<link rel="stylesheet" href="' + baseURL + e + '" type="text/css" title="Stylesheet">');
+        });
+      }
+      if (data["stylesheets_inline"] && data["stylesheets_inline"].size) {
+        var style = "<style type='text/css'>";
+        $.each(data["stylesheets_inline"], function(i, e){
+          style += e;
+        });
+        style += '</style>';
+        $('head').append(style);
+      }
+      if (data["start_content"]) {
+        $('body').wrapInner(data["start_content"]);
+      }
+      if (data["pre_content"]) {
+        $('body').prepend(data["pre_content"]);
+      }
+      if (data["post_content"]) {
+        $('body').append(data["post_content"]);
+      }
+      if (data["javascripts"]) {
+        $.each(data["javascripts"], function(i, e){
+          $('head').append('<script type="text/javascript" src="' + baseURL + e + '">');
+        });
+      }
+      if (data["javascripts_inline"]) {
+        var script = "<script type='text/javascript'>";
+        $.each(data["javascripts_inline"], function(i, e){
+          script += e;
+        });
+        script += '</script>';
+        $('head').append(script);
+      }
+    }
+  });
+}