Merge remote branch 'origin/core/1.1.2/maint' into core/master
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 16 Feb 2011 21:17:19 +0000 (22:17 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 16 Feb 2011 21:17:19 +0000 (22:17 +0100)
classes/plpage.php
classes/plsession.php
htdocs/javascript/core.js
templates/plpage.header.tpl

index 516378b..56b0c8a 100644 (file)
@@ -132,7 +132,7 @@ abstract class PlPage extends Smarty
         } elseif ($display == 'raw') {
             $this->_page_type = NO_SKIN;
         } elseif ($display == 'full') {
-            $this->_page_typ = SKINNED;
+            $this->_page_type = SKINNED;
         }
 
         if ($this->_page_type == SIMPLE) {
index f19c457..94665c6 100644 (file)
@@ -52,7 +52,7 @@ abstract class PlSession
 
     /** Build the session structure with system fields.
      */
-    private function fillSession()
+    protected function fillSession()
     {
         S::bootstrap('user', null);
         S::bootstrap('auth', AUTH_PUBLIC);
index bc9463e..ea6ccf7 100644 (file)
@@ -24,7 +24,7 @@
 // {{{ jQuery object extension
 
 (function($) {
-    function assert(condition, text) {
+    var assert = function(condition, text) {
         if ($.isFunction(condition)) {
             condition = condition();
         }
         } else {
             throw "Assertion failed: " + text;
         }
-    }
+    };
 
 
     /* Add new functions to jQuery namesapce */
     $.extend({
+        plURL: (function() {
+            var base;
+            return function(url) {
+                if (url.startsWith('http', true)) {
+                    return url;
+                }
+                if (typeof base === 'undefined') {
+                    base = $('head base');
+                    if (base.length > 0) {
+                        base = base.attr('href');
+                        if (!base.endsWith('/')) {
+                            base += '/';
+                        }
+                    } else {
+                        base = '';
+                    }
+                }
+                return base + url;
+            };
+        }()),
+
         /* The goal of the following functions is to provide an AJAX API that
          * take a different callback in case of HTTP success code (2XX) and in
          * other cases.
                 onSuccess = data;
                 data = null;
             }
-            if (onError != null && !$.isFunction(onError)) {
+            if (onError && !$.isFunction(onError)) {
                 type = type || onError;
                 onError = null;
             }
 
             function ajaxHandler(data, textStatus, xhr) {
-                if (textStatus == 'success') {
+                if (textStatus === 'success') {
                     if (onSuccess) {
                         onSuccess(data, textStatus, xhr);
                     }
-                } else if (textStatus == 'error') {
+                } else if (textStatus === 'error') {
                     if (onError) {
                         onError(data, textStatus, xhr);
                     } else {
@@ -74,7 +95,7 @@
                 }
             }
             return $.ajax({
-                url: source,
+                url: $.plURL(source),
                 type: method,
                 success: ajaxHandler,
                 data : data,
 
         closeOnEsc: function() {
             return $(window).keydown(function (e) {
-                if (e.keyCode == 27) {
+                if (e.keyCode === 27) {
                     window.close();
                 }
             });
 
         dynPost: function(action, key, value) {
             var values;
+            var k;
+            var form;
+
             if (!$.isArray(key)) {
                 values = { };
                 values[key] = value;
             } else {
                 values = key;
             }
-            var form = $('<form>', {
+            form = $('<form>', {
                 action: action,
                 method: 'post'
             });
-            for (var k in values) {
-                $('<input>', {
-                    type: 'hidden',
-                    name: k,
-                    value: values[k]
-                }).appendTo(form);
+            for (k in values) {
+                if (values.hasOwnProperty(k)) {
+                    $('<input>', {
+                        type: 'hidden',
+                        name: k,
+                        value: values[k]
+                    }).appendTo(form);
+                }
             }
             $('body').appendTo(form);
             form.submit();
         },
 
         wiki: function(text, withTitle) {
-            if (text == '') {
+            if (!text) {
                 return this.html('');
             }
             var url = 'wiki_preview';
 
         assertLength: function(len) {
             return this.assert(function() {
-                return $(this).length == len;
+                return $(this).length === len;
             });
         },
 
         assertId: function(id) {
             return this.assert(function() {
-                return $(this).attr('id') == id;
+                return $(this).attr('id') === id;
             });
         },
 
             });
         }
     });
-})(jQuery);
+}(jQuery));
 
 // }}}
 // {{{ function RegExp.escape()
@@ -235,36 +261,93 @@ RegExp.escape = function(text) {
         );
     }
     return text.replace(arguments.callee.sRE, '\\$1');
-}
+};
+
+// }}}
+// {{{ String extension
+
+String.prototype.startsWith = function(str, caseInsensitive) {
+    var cmp = this;
+
+    if (str.length > this.length) {
+        return false;
+    }
+    if (caseInsensitive) {
+        str = str.toLowerCase();
+        cmp = cmp.toLowerCase();
+    }
+    return cmp.substr(0, str.length) === str;
+};
+
+String.prototype.endsWith = function(str, caseInsensitive) {
+    var cmp = this;
+
+    if (str.length > this.length) {
+        return false;
+    }
+    if (caseInsensitive) {
+        str = str.toLowerCase();
+        cmp = cmp.toLowerCase();
+    }
+    return cmp.substr(cmp.length - str.length, str.length) === str;
+};
+
+String.prototype.htmlEntities = function() {
+    return this.replace(/&/g,'&amp;')
+               .replace(new RegExp('<','g'),'&lt;')
+               .replace(/>/g,'&gt;');
+};
+
+String.prototype.contains = function(str, caseInsensitive) {
+    var cmp = this;
+    if (str.length > this.length) {
+        return false;
+    }
+    if (caseInsensitive) {
+        str = str.toLowerCase();
+        cmp = cmp.toLowerCase();
+    }
+    return cmp.indexOf(str) >= 0;
+};
 
 // }}}
 // {{{ PmWiki decoding
 
 Nix = {
     map: null,
+
     convert: function(a) {
-        Nix.init();
         var s = '';
+        Nix.init();
         for (i = 0; i < a.length ; i++) {
             var b = a.charAt(i);
             s += ((b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') ? Nix.map[b] : b);
         }
         return s;
     },
+
     init: function() {
-        if (Nix.map != null)
+        var map;
+        var s;
+
+        if (Nix.map !== null) {
             return;
-        var map = new Array();
-        var s='abcdefghijklmnopqrstuvwxyz';
-        for (i = 0; i < s.length; i++)
-            map[s.charAt(i)] = s.charAt((i+13)%26);
-        for (i=0; i<s.length; i++)map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();
-            Nix.map = map;
+        }
+        map = [ ];
+        s   = 'abcdefghijklmnopqrstuvwxyz';
+        for (i = 0; i < s.length; i++) {
+            map[s.charAt(i)] = s.charAt((i+13) % 26);
+        }
+        for (i=0; i< s.length; i++) {
+            map[s.charAt(i).toUpperCase()] = s.charAt((i+13) % 26).toUpperCase();
+        }
+        Nix.map = map;
     },
+
     decode: function(a) {
         document.write(Nix.convert(a));
     }
-}
+};
 
 // }}}
 // {{{ preview wiki
@@ -272,7 +355,7 @@ Nix = {
 function previewWiki(idFrom, idTo, withTitle, idShow)
 {
     $('#' + idTo).wiki($('#' + idFrom).val(), withTitle);
-    if (idShow != null) {
+    if (idShow) {
         $('#' + idShow).show();
     }
 }
index f1c50ae..0f45653 100644 (file)
@@ -37,9 +37,6 @@
 <link rel="{$link.rel}" href="{$link.href}" />
 {/foreach}
 {/if}
-<script type="text/javascript">
-  var platal_baseurl = "{$globals->baseurl}/";
-</script>
 {if t($pl_js)}
 {foreach from=$pl_js item=js}
 <script type="text/javascript" src="{$js}"></script>