(function($){

$.fn.limitedInput = function() {
    return this.each(function() {
        var area = $(this);
        var container = area.closest('.widget');
        var limit = area.attr('cms:maxlength');
        var count = area.val().length || 0;
        var suffix = '/' + limit;
        var label = count + suffix;
        var span = $('<span />').addClass('charlimit').html(label);
        container.append(span);
        area.bind("keyup focus blur onload", function (e) {
            var count = $(e.target).val().length;
            var label = count + suffix;
            if ((limit - count) < 0) {
                span.css("color", "#900").html(label);
            } else {
                span.css("color", "#000").html(label);
            }
        });
    });
};

$.fn.countedInput = function() {
    var self = $(this);
    var count = function() {
        var l = self.find('.editable').children().text().length || 0;
        var container = self.parent();
        container.find('.charcount').html(l + " Zeichen");
        if(l > 5000) {
          container.find('.charcount').addClass('charalert');
        } else {
          container.find('.charcount').removeClass('charalert');
        }
    };
    self.bind('keyup', count);
    count();
};


MochiKit.Signal.connect(window, 'cp-editor-loaded', function() {

    MochiKit.Signal.connect(zeit.edit.editor, 'after-reload', function() {
        $('#article-editor-text').countedInput();
    });

});

$(document).bind('fragment-ready', function(event) {
    $('[cms\\:maxlength]', event.__target).limitedInput();
});

}(jQuery));

@@ -1263,78 +1263,8 @@
 ;%0A%0A%0A
-MochiKit.Signal.connect(window, 'cp-editor-loaded', function() %7B%0A%0A    
 Moch
@@ -1334,20 +1334,16 @@
 ) %7B%0A    
-  
-  
 $('#arti
@@ -1380,20 +1380,12 @@
 ();%0A
-    %7D);%0A%0A
 %7D);
+%0A
 %0A%0A$(

Fix event handler ordering so the character counter shows up on initial load, too