Changeset 2493

Show
Ignore:
Timestamp:
01/19/10 12:30:17 (2 months ago)
Author:
JensDiemer
Message:

reformat tab->spaces

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/0.9/pylucid_project/media/PyLucid/pylucid_js_tools.js

    r2488 r2493  
    66        try {debug} catch (e) {debug=false}; 
    77    if (debug && window.console && window.console.log) 
    8         window.console.log(Array.prototype.join.call(arguments,'')); 
    9 }; 
     8        window.console.log(Array.prototype.join.call(arguments,'')); 
     9} 
    1010 
    1111 
    1212function OpenInWindow(link) { 
    13         /************************************************************************* 
     13    /************************************************************************* 
    1414        Open link in a new JavaScript window. 
    1515        Usage e.g.: 
     
    1818                <a href="/foobar/" class="openinwindow">foobar</a> 
    1919        *************************************************************************/ 
    20         var url = $(link).attr("href"); 
     20    var url = $(link).attr("href"); 
    2121    win = window.open(url, "", "width=900, height=760, dependent=yes, resizable=yes, scrollbars=yes"); 
    2222    win.focus(); 
     
    2626 
    2727function replace_complete_page(html) { 
    28         // replace the complete page 
    29         document.open() // no append available since it is closed 
    30         document.write(html); 
    31         document.close();  
     28    // replace the complete page 
     29    document.open() // no append available since it is closed 
     30    document.write(html); 
     31    document.close(); 
    3232} 
    3333 
    3434function replace_page_content(data, textStatus) { 
    35         /************************************************************************* 
     35    /************************************************************************* 
    3636        ajax success "handler". 
    3737        replace the "#page_content" with the new html response data 
    3838        *************************************************************************/ 
    39         log("ajax post response success."); 
    40         log("status:" + textStatus); 
    41         if (data.indexOf("</body>") != -1) { 
    42                 // FIXME: We should find a way to handle a  
    43                 // redirect directly. But we always get the 
    44                 // html data of the redirected page. 
    45                  
    46                 log("redirect work-a-round: replace the complete page"); 
    47                 log("</body> index:" + data.indexOf("</body>")); 
    48                 replace_complete_page(data) 
    49         } else { 
    50                 $("#page_content").html(data); 
    51                 $("#page_content").animate({opacity: 1}, 500 ); 
    52         } 
    53         load_normal_link = false; 
     39    log("ajax post response success."); 
     40    log("status:" + textStatus); 
     41    if (data.indexOf("</body>") != -1) { 
     42        // FIXME: We should find a way to handle a 
     43        // redirect directly. But we always get the 
     44        // html data of the redirected page. 
     45                 
     46        log("redirect work-a-round: replace the complete page"); 
     47        log("</body> index:" + data.indexOf("</body>")); 
     48        replace_complete_page(data) 
     49    } else { 
     50        $("#page_content").html(data); 
     51        $("#page_content").animate({ 
     52            opacity: 1 
     53        }, 500 ); 
     54    } 
     55    load_normal_link = false; 
    5456} 
    5557 
    5658 
    5759function ajax_error_handler(XMLHttpRequest, textStatus, errorThrown) { 
    58         /************************************************************************* 
     60    /************************************************************************* 
    5961        ajax error "handler". 
    6062        replace the complete page with the error text (django html traceback page) 
    6163        *************************************************************************/ 
    62         log("ajax get response error!"); 
    63         log(XMLHttpRequest); 
    64         var response_text = XMLHttpRequest.responseText; 
    65         log("response_text: '" + response_text + "'"); 
    66         if (!response_text) { 
    67                 response_text = "<h1>Ajax response error without any response text.</h1>"; 
    68         } 
    69         replace_complete_page(response_text); 
    70         load_normal_link = true; 
     64    log("ajax get response error!"); 
     65    log(XMLHttpRequest); 
     66    var response_text = XMLHttpRequest.responseText; 
     67    log("response_text: '" + response_text + "'"); 
     68    if (!response_text) { 
     69        response_text = "<h1>Ajax response error without any response text.</h1>"; 
     70    } 
     71    replace_complete_page(response_text); 
     72    load_normal_link = true; 
    7173} 
    7274 
     
    9092         
    9193        $("#page_content").html('<h2>send...</h2>'); 
    92         $("#page_content").animate({opacity: 0.3}, 500 ); 
     94        $("#page_content").animate({ 
     95            opacity: 0.3 
     96        }, 500 ); 
    9397 
    9498        var form = $(this); 
     
    102106         
    103107        XMLHttpRequest = $.ajax({ 
    104                 async: false, 
     108            async: false, 
    105109            type: "POST", 
    106110            url: url, 
     
    110114            success: replace_page_content, 
    111115            complete: function(XMLHttpRequest, textStatus){ 
    112                 // Handle redirects 
    113                 log("complete:" + XMLHttpRequest); 
    114                 log("text:" + textStatus); 
    115                 log("complete:" + XMLHttpRequest.status); 
    116                 log("complete:" + XMLHttpRequest.getResponseHeader('Location')); 
     116                // Handle redirects 
     117                log("complete:" + XMLHttpRequest); 
     118                log("text:" + textStatus); 
     119                log("complete:" + XMLHttpRequest.status); 
     120                log("complete:" + XMLHttpRequest.getResponseHeader('Location')); 
    117121                 
    118122                if(XMLHttpRequest.status.toString()[0]=='3'){ 
    119                         top.location.href = XMLHttpRequest.getResponseHeader('Location'); 
     123                    top.location.href = XMLHttpRequest.getResponseHeader('Location'); 
    120124                } 
    121125            }, 
     
    123127        }); 
    124128        log("ajax done:" + XMLHttpRequest); 
    125         log("ajax done:" + XMLHttpRequest.status); 
    126         log("ajax done:" + XMLHttpRequest.getResponseHeader('Location')); 
     129        log("ajax done:" + XMLHttpRequest.status); 
     130        log("ajax done:" + XMLHttpRequest.getResponseHeader('Location')); 
    127131        return load_normal_link; // <-- important: Don't send the form in normal way. 
    128132    });  
     
    152156    *************************************************************************/ 
    153157    $("#page_content").html('<h2>loading...</h2>'); 
    154     $("#page_content").animate({opacity: 0.3}, 500 ); 
     158    $("#page_content").animate({ 
     159        opacity: 0.3 
     160    }, 500 ); 
    155161 
    156162    var url = encodeURI(url); 
     
    160166     
    161167    $.ajax({ 
    162         async: false, 
     168        async: false, 
    163169        type: "GET", 
    164170        url: url, 
     
    169175    }); 
    170176    if (debug) { 
    171         // never fall back in debug mode. 
     177        // never fall back in debug mode. 
    172178        log("return: " + load_normal_link); 
    173         return false; 
     179        return false; 
    174180    } else { 
    175         // fall back to normal view, if ajax request failed. 
    176         return load_normal_link; // The browser follow the link, if true 
     181        // fall back to normal view, if ajax request failed. 
     182        return load_normal_link; // The browser follow the link, if true 
    177183    }     
    178184} 
     
    180186 
    181187function replace_openinwindow_links() { 
    182         /************************************************************************* 
     188    /************************************************************************* 
    183189         * replace the existing links with a "open in new window" link 
    184190         * usage: 
    185191         *              <a href="/foo" class="openinwindow">foo</a> 
    186192         */ 
    187         $('a.openinwindow').each(function(){ 
    188                 var url = $(this).attr("href");          
    189                 var org_title = $(this).attr("title"); 
    190                  
    191                 $(this).attr({ 
    192                         onclick: "return OpenInWindow(this);", 
    193                         title: org_title + " (Opens in a new window)" 
    194             }); 
    195                 //$(this).append(" [^]") 
    196         }); 
     193    $('a.openinwindow').each(function(){ 
     194        var url = $(this).attr("href"); 
     195        var org_title = $(this).attr("title"); 
     196                 
     197        $(this).attr({ 
     198            onclick: "return OpenInWindow(this);", 
     199            title: org_title + " (Opens in a new window)" 
     200        }); 
     201    //$(this).append(" [^]") 
     202    }); 
    197203} 
    198204 
     
    205211RESIZE_FACTOR = 1.3; 
    206212$(document).ready(function(){ 
    207         /************************************************************************* 
     213    /************************************************************************* 
    208214         * textarea resize buttons 
    209215         */ 
    210         $(".resize_textarea" ).click(function () { 
    211                 button_id = $(this).attr('id'); 
    212 //              log("Clicked on: " + button_id); 
    213                 var pos = button_id.indexOf("_"); 
    214                 var action = button_id.slice(0, pos); 
    215                 var textarea_id = button_id.slice(pos+1, button_id.length); 
    216 //              log("action:" + action); 
    217 //              log("textarea id:" + textarea_id); 
    218                 var textarea = $("#"+textarea_id); 
    219                 var old_rows = textarea.attr("rows"); 
    220                  
    221                 var new_rows = false; 
    222                 if (action=="smaller") { 
    223                         if (old_rows<3) { 
    224                                 log("no more smaller ;)") 
    225                                 return; 
    226                         } 
    227                         new_rows = Math.floor(old_rows / RESIZE_FACTOR); 
    228                 } 
    229                 if (action=="bigger") { 
    230                         new_rows = Math.ceil(old_rows * RESIZE_FACTOR); 
    231                 } 
    232                  
    233                 if (new_rows == false) { 
    234                         log("Error: Wrong textarea resize action:" + action); 
    235                         return; 
    236                 } 
    237 //              log("old rows:" + old_rows + " - new rows:" + new_rows); 
    238                 textarea.animate({rows: new_rows}, 100 ); 
    239         }); 
    240          
    241         /************************************************************************* 
     216    $(".resize_textarea" ).click(function () { 
     217        button_id = $(this).attr('id'); 
     218        //              log("Clicked on: " + button_id); 
     219        var pos = button_id.indexOf("_"); 
     220        var action = button_id.slice(0, pos); 
     221        var textarea_id = button_id.slice(pos+1, button_id.length); 
     222        //              log("action:" + action); 
     223        //              log("textarea id:" + textarea_id); 
     224        var textarea = $("#"+textarea_id); 
     225        var old_rows = textarea.attr("rows"); 
     226                 
     227        var new_rows = false; 
     228        if (action=="smaller") { 
     229            if (old_rows<3) { 
     230                log("no more smaller ;)") 
     231                return; 
     232            } 
     233            new_rows = Math.floor(old_rows / RESIZE_FACTOR); 
     234        } 
     235        if (action=="bigger") { 
     236            new_rows = Math.ceil(old_rows * RESIZE_FACTOR); 
     237        } 
     238                 
     239        if (new_rows == false) { 
     240            log("Error: Wrong textarea resize action:" + action); 
     241            return; 
     242        } 
     243        //              log("old rows:" + old_rows + " - new rows:" + new_rows); 
     244        textarea.animate({ 
     245            rows: new_rows 
     246        }, 100 ); 
     247    }); 
     248         
     249    /************************************************************************* 
    242250         * replace the existing links with a "open in new window" link           */ 
    243         replace_openinwindow_links(); 
    244          
    245          
    246         /************************************************************************* 
     251    replace_openinwindow_links(); 
     252         
     253         
     254    /************************************************************************* 
    247255         * Add a "open in new window" link after the existing normal link. 
    248256         * usage: 
    249257         *              <a href="/foo" class="add_openinwindow">foo</a> 
    250258         */ 
    251         $('a.add_openinwindow').each(function(){ 
    252  
    253                 var url = $(this).attr("href"); 
    254                 var org_title = $(this).attr("title"); 
    255                  
    256                 var new_link = ' <a href="'+url+'" onclick="return OpenInWindow(this);" title="'+org_title+' (Opens in a new window)">[^]</a>' 
    257                  
    258                 $(this).after(new_link); 
    259         }) 
    260      
    261         /************************************************************************* 
     259    $('a.add_openinwindow').each(function(){ 
     260 
     261        var url = $(this).attr("href"); 
     262        var org_title = $(this).attr("title"); 
     263                 
     264        var new_link = ' <a href="'+url+'" onclick="return OpenInWindow(this);" title="'+org_title+' (Opens in a new window)">[^]</a>' 
     265                 
     266        $(this).after(new_link); 
     267    }) 
     268     
     269    /************************************************************************* 
    262270         * Resize all textareas 
    263271         */ 
    264         $("textarea").each(function() { 
    265                 rows = this.value.split("\n").length; 
    266                 if (rows > MAX_ROWS) {rows = MAX_ROWS;} 
    267             if (rows < MIN_ROWS) {rows = MIN_ROWS;} 
    268             log("set textarea row to:" + rows) 
    269             this.rows = rows; 
    270         }); 
    271          
    272         /************************************************************************* 
     272    $("textarea").each(function() { 
     273        rows = this.value.split("\n").length; 
     274        if (rows > MAX_ROWS) { 
     275            rows = MAX_ROWS; 
     276        } 
     277        if (rows < MIN_ROWS) { 
     278            rows = MIN_ROWS; 
     279        } 
     280        log("set textarea row to:" + rows) 
     281        this.rows = rows; 
     282    }); 
     283         
     284    /************************************************************************* 
    273285         * resize input fields 
    274286         */ 
    275         $(".pylucid_form input").each(function() { 
    276                 maxlength = $(this).attr("maxlength"); 
    277                 if (maxlength<=0) { 
    278                         return; 
    279                 } 
    280                 if (maxlength > MAX_LENGTH) {maxlength = MAX_LENGTH;} 
    281                 this.size=maxlength; 
    282         }); 
    283  
    284         /************************************************************************* 
     287    $(".pylucid_form input").each(function() { 
     288        maxlength = $(this).attr("maxlength"); 
     289        if (maxlength<=0) { 
     290            return; 
     291        } 
     292        if (maxlength > MAX_LENGTH) { 
     293            maxlength = MAX_LENGTH; 
     294        } 
     295        this.size=maxlength; 
     296    }); 
     297 
     298    /************************************************************************* 
    285299         * hide/unhide form fieldset stuff. 
    286300         */ 
    287         $(".pylucid_form .form_hide").nextAll().hide(); 
    288         $(".pylucid_form .form_collapse").each(function() { 
    289                 $(this).css("cursor","n-resize"); 
    290         }); 
    291         $(".pylucid_form .form_collapse").click(function () { 
    292                 if ($(this).css("cursor") == "n-resize") { 
    293                         $(this).css("cursor","s-resize"); 
    294                 } else { 
    295                         $(this).css("cursor","n-resize"); 
    296                 } 
    297                 $(this).nextAll().slideToggle("fast"); 
    298         }); 
     301    $(".pylucid_form .form_hide").nextAll().hide(); 
     302    $(".pylucid_form .form_collapse").each(function() { 
     303        $(this).css("cursor","n-resize"); 
     304    }); 
     305    $(".pylucid_form .form_collapse").click(function () { 
     306        if ($(this).css("cursor") == "n-resize") { 
     307            $(this).css("cursor","s-resize"); 
     308        } else { 
     309            $(this).css("cursor","n-resize"); 
     310        } 
     311        $(this).nextAll().slideToggle("fast"); 
     312    }); 
    299313         
    300314});