]> wagnertech.de Git - mfinanz.git/blobdiff - js/kivi.js
CKEditor: config Hack bei inline initialisierung
[mfinanz.git] / js / kivi.js
index e17294a128fd95773b5bba74826615008a982bc5..b4608c9f0f9e6d129abc8abbdede45c71cc620e5 100644 (file)
@@ -61,8 +61,16 @@ namespace("kivi", function(ns) {
 
     amount = amount.replace(/[\',]/g, "")
 
+    // Make sure no code wich is not a math expression ends up in eval().
+    if (!amount.match(/^[0-9 ()\-+*/.]*$/))
+      return 0;
+
     /* jshint -W061 */
-    return eval(amount);
+    try {
+      return eval(amount);
+    } catch (err) {
+      return 0;
+    }
   };
 
   ns.round_amount = function(amount, places) {
@@ -214,17 +222,17 @@ namespace("kivi", function(ns) {
       entities:      false,
       language:      'de',
       removePlugins: 'resize',
-      toolbar:       buttons
-    }
+      extraPlugins:  'inline_resize',
+      toolbar:       buttons,
+      disableAutoInline: true,
+      title:         false
+    };
 
-    var style = $e.prop('style');
-    $(['width', 'height']).each(function(idx, prop) {
-      var matches = (style[prop] || '').match(/(\d+)px/);
-      if (matches && (matches.length > 1))
-        config[prop] = matches[1];
-    });
+   config.height = $e.height();
+   config.width  = $e.width();
 
-    $e.ckeditor(config);
+    var editor = CKEDITOR.inline($e.get(0), config);
+    $e.data('editor', editor);
 
     if ($e.hasClass('texteditor-autofocus'))
       $e.ckeditor(function() { ns.focus_ckeditor($e); });
@@ -235,10 +243,7 @@ namespace("kivi", function(ns) {
       $(elt).datepicker();
     });
 
-    if (ns.PartPicker)
-      ns.run_once_for('input.part_autocomplete', 'part_picker', function(elt) {
-        kivi.PartPicker($(elt));
-      });
+    if (ns.Part) ns.Part.reinit_widgets();
 
     if (ns.ProjectPicker)
       ns.run_once_for('input.project_autocomplete', 'project_picker', function(elt) {
@@ -352,13 +357,13 @@ namespace("kivi", function(ns) {
       params.dialog || { },
       { // Options that must not be changed:
         close: function(event, ui) {
+          dialog.dialog('close');
+
           if (custom_close)
             custom_close();
 
           if (params.url || params.html)
             dialog.remove();
-          else
-            dialog.dialog('close');
         }
       });
 
@@ -438,7 +443,7 @@ namespace("kivi", function(ns) {
   ns.run = function(function_name, args) {
     var fn = ns.get_function_by_name(function_name);
     if (fn)
-      return fn.apply({}, args);
+      return fn.apply({}, args || []);
 
     console.error('kivi.run("' + function_name + '"): No function by that name found');
     return undefined;
@@ -530,6 +535,23 @@ namespace("kivi", function(ns) {
 
     return true;
   };
+
+  ns.switch_areainput_to_textarea = function(id) {
+    var $input = $('#' + id);
+    if (!$input.length)
+      return;
+
+    var $area = $('<textarea></textarea>');
+
+    $area.prop('rows', 3);
+    $area.prop('cols', $input.prop('size') || 40);
+    $area.prop('name', $input.prop('name'));
+    $area.prop('id',   $input.prop('id'));
+    $area.val($input.val());
+
+    $input.parent().replaceWith($area);
+    $area.focus();
+  };
 });
 
 kivi = namespace('kivi');