Changeset 40


Ignore:
Timestamp:
10/27/07 16:09:28 (6 years ago)
Author:
Lantash
Message:

Fixed bug in BBCode parsing routine. [Closes #21]

Some more code cleanup.

Location:
trunk/javascript
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/javascript/klassenbuch.comments.js

    r38 r40  
    513513        var comment = this.comment.text.replaceAll("[BR /]", "<br />"); 
    514514         
    515         [["B", "strong"], ["I", "em"], ["U", "u"]].each(function(a) { 
    516             if (comment.count("[" + a[0] + "]") === comment.count("[/" + a[0] + "]")) { 
    517                 comment = comment.replaceAll("[" + a[0] + "]", "<" + a[1] + ">").replaceAll("[/" + a[0] + "]", "</" + a[1] + ">"); 
     515                [["[B]", "[/B]", "<b>", "</b>"], ["[I]", "[/I]", "<i>", "</i>"], ["[U]", "[/U]", "<u>", "</u>"]].each(function(a) { 
     516                        var count1 = comment.count(a[0]); 
     517            if (count1 && count1 === comment.count(a[1])) { 
     518                comment = comment.replaceAll(a[0], a[2]).replaceAll(a[1], a[3]); 
    518519            } 
    519          }); 
     520        }); 
    520521                 
    521522        Comments.Emoticons.each(function(pair) { 
  • trunk/javascript/klassenbuch.controls.js

    r38 r40  
    140140}); 
    141141 
    142 $w("setStyle addClassName removeClassName toggleClassName").each(function(a) { 
     142$w("setStyle addClassName removeClassName toggleClassName centerOnScreen").each(function(a) { 
    143143        Control.prototype[a] = function(val) { 
    144144                this.element[a](val); 
     
    225225Controls.Button = Class.create(Control, { 
    226226        initialize: function($super, caption, action, options) { 
    227                 if (!Object.isString(caption)) { 
    228                         return; 
    229                 } 
    230                  
    231227                // Überschreibt die mit options übergebenen Einstellungen mit den Standardwerten 
    232                 this.setOptions({ enabled: true, 
     228                this.setOptions({ 
     229                        enabled: true, 
    233230                        onlySignedIn: false, 
    234231                        className: "", 
     
    239236                }, options); 
    240237                 
    241                 this.action = action || Prototype.emptyFunction; 
    242                  
    243         $super(new Element(this.options.tag, { className: "unselectable " + this.options.className })); 
     238        $super(new Element(this.options.tag, { 
     239                        className: "unselectable " + this.options.className, 
     240                        title: this.options.title 
     241                })); 
    244242         
     243        this.action = action || Prototype.emptyFunction; 
    245244                this.setCaption(caption); 
    246245                 
     
    251250                this.on("click", action); 
    252251                 
    253                 ["Over", "Down", "Out", "Up"].each(function(a) { 
    254                         this.element.observe(("mouse" + a).toLowerCase(), this["_on" + a].bind(this)); 
     252                $w("over down out up").each(function(a) { 
     253                        this.element.observe("mouse" + a, this._setState.bind(this, a)); 
    255254                }, this); 
    256255                 
     
    261260                 
    262261                this._updateContent(); 
    263                  
    264                 this._onOut(); 
    265262                this.enable(); 
    266263                 
     
    271268                if (!this.options.visible) { 
    272269                        this.hide(); 
    273                 } 
    274                  
    275                 if (this.options.title) { 
    276                         this.element.writeAttribute("title", this.options.title); 
    277270                } 
    278271        }, 
     
    339332        }, 
    340333         
    341         _onOver: function() { 
    342                 this._setBackground(-100); 
    343         }, 
    344          
    345         _onDown: function() { 
    346                 this._setBackground(-200); 
    347         }, 
    348          
    349         _onOut: function() { 
    350                 this._setBackground(0); 
    351         }, 
    352          
    353         _onUp: function() { 
    354                 this._setBackground(-100); 
    355         }, 
    356          
    357334        setButtonClass: function(buttonClass) { 
    358335        if (this.buttonClass) { 
     
    364341        }, 
    365342         
    366         _setBackground: function(position) { 
    367                 if (this.enabled) { 
     343        _setState: function(state) { 
     344                var position = { 
     345                        out: 0, 
     346                        enabled: 0, 
     347                        over: -100, 
     348                        up: -100, 
     349                        down: -200, 
     350                        disabled: -300 
     351                }[state]; 
     352                 
     353                if (this.enabled && Object.isDefined(position)) { 
    368354                        this.leftBoundary.setStyle({ backgroundPosition: "0px " + position + "px" }); 
    369355                        this.rightBoundary.setStyle({ backgroundPosition: "100% " + position + "px" }); 
     
    378364                if (!this.enabled) { 
    379365                        this.enabled = true; 
    380                         this._onOut(); 
     366                        this._setState("enabled"); 
    381367                         
    382368                        this.removeClassName("disabled" + this.options.buttonClass.capitalize()); 
     
    399385        disable: function() { 
    400386                if (this.enabled) { 
    401             this._setBackground(-300); 
     387            this._setState("disabled"); 
    402388            this.enabled = false; 
    403389             
     
    417403Controls.Link = Class.create(Control, { 
    418404        initialize: function($super, caption, action) { 
    419                 $super(new Element("a", { className: "linkControl", href: "javascript:void(null);" })); 
     405                $super(new Element("a", { 
     406                        className: "linkControl", 
     407                        href: "javascript:void(null);" 
     408                })); 
    420409                 
    421410                this.element.innerHTML = caption; 
    422411                this.element.observe("click", this.fireEvent.bind(this, "click")); 
    423412                 
    424                 this.on("click", action); 
     413                this.on("click", action || Prototype.K); 
    425414        } 
    426415}); 
     
    610599                 
    611600                tab.on("activate", this._onTabActivated, this); 
    612                  
    613                 if (!this.activeTab) { 
    614                         tab.activate(); 
    615                 } else { 
    616                         tab.deactivate(); 
    617                 } 
     601                tab[(this.activeTab) ? "deactivate" : "activate"](); 
    618602                 
    619603                this.tabs.splice(index, 0, tab); 
    620                  
    621604                this.fireEvent("addTab", tab); 
    622605                 
     
    676659Controls.TabControl.TabPage = Class.create(Control, App.History.Node.prototype, { 
    677660        initialize: function($super, caption) { 
    678                 if (!caption) { 
    679                         return; 
    680                 } 
    681                  
    682661                $super(new Element("div")); 
    683662                 
     
    711690Controls.TabControl.TabPageWithButtonControl = Class.create(Controls.TabControl.TabPage, { 
    712691        initialize: function($super, caption, icon, buttonClass) { 
    713                 if (!Object.isString(caption)) { 
    714                         return; 
    715                 } 
    716                  
    717692                this.icon = icon; 
    718693                this._buttonClass = buttonClass || "menuItem"; 
     
    738713Controls.View = Class.create(Controls.TabControl.TabPageWithButtonControl, { 
    739714        initialize: function($super, caption, icon, title, options) { 
    740                 if (!Object.isString(caption)) { 
    741                         return; 
    742                 } 
    743                  
    744715                this.setOptions({ hasAdditionalCommands: true }, options); 
    745716        $super(caption, icon); 
     
    847818        setHelpText: function(text) { 
    848819                this.help.innerHTML = text; 
    849         }, 
    850          
    851         getHelpText: function() { 
    852                 return this.help.innerHTML; 
    853820        } 
    854821}); 
     
    937904                 
    938905                this.element.observe("submit", this._onSubmit.bind(this)); 
    939                  
    940906                this.element.observe("keypress", (function(e) { 
    941907                        if (e.keyCode === Event.KEY_RETURN) { 
     
    11441110                        document.observe("mouseup", this.stopDraggingListener); 
    11451111                        document.observe("mousemove", this.moveListener); 
     1112                         
     1113                        this._windowSize = Tools.getWindowSize(); 
    11461114                } 
    11471115        }, 
     
    11561124        }, 
    11571125         
    1158         move: function(e) { 
    1159                 if (this.draging && e) { 
    1160                         var windowSize = Tools.getWindowSize(); 
    1161                          
    1162                         var clientX = e.clientX.limitTo(0, windowSize.width); 
    1163                         var clientY = e.clientY.limitTo(0, windowSize.height); 
    1164                          
    1165                         this.target.setStyle({ left: this.offsetX + clientX - this.x + "px", top: this.offsetY + clientY - this.y + "px" }); 
     1126        move: function(event) { 
     1127                if (this.draging && event) { 
     1128                        var clientX = event.clientX.limitTo(0, this._windowSize.width); 
     1129                        var clientY = event.clientY.limitTo(0, this._windowSize.height); 
     1130                         
     1131                        this.target.setStyle({ 
     1132                                left: this.offsetX + clientX - this.x + "px", 
     1133                                top: this.offsetY + clientY - this.y + "px" 
     1134                        }); 
    11661135                } 
    11671136        }, 
     
    12531222        update: function(content) { 
    12541223        this.content.innerHTML = content; 
    1255         }, 
    1256          
    1257         /** 
    1258          * @method Zentriert das Steuerelement basierend auf seiner Grösse im Browserfenster (Wrapperfunktion). 
    1259          * @return {ExtendedHTMLObject} Das HTML-Element des Steuerelement. 
    1260         */ 
    1261         centerOnScreen: function() { 
    1262                 return this.element.centerOnScreen(); 
    12631224        }, 
    12641225         
Note: See TracChangeset for help on using the changeset viewer.