]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
isValidBaseURI
authorpho <pho@cielonegro.org>
Fri, 11 Jul 2008 08:05:08 +0000 (17:05 +0900)
committerpho <pho@cielonegro.org>
Fri, 11 Jul 2008 08:05:08 +0000 (17:05 +0900)
darcs-hash:20080711080508-62b54-d2d667916bd73acce66191a2bc33d17feb4f7a03.gz

Rakka.cabal
js/Makefile
js/base.js
js/editPage.js
js/parseuri.js [new file with mode: 0644]
js/systemConfig.js

index 930cc7604f903073f4d72df664984bc0cbb457d0..6652e9673595b0c4dc00759f80d97229f2c1b20f 100644 (file)
@@ -41,6 +41,7 @@ Extra-Source-Files:
     js/jquery-dom.js
     js/localFile.js
     js/login.js
+    js/parseuri.js
     js/screen.js
     js/search.js
     js/uri.js
index 6db118db7acea0fd9eb4bfe5a436caae7908e773..e1e6b0cd3fa1c310315a71faddb1994dab80aba6 100644 (file)
@@ -10,6 +10,7 @@ SOURCES = \
        localFile.js \
        login.js \
        redirection.js \
+       parseuri.js \
        screen.js \
        search.js \
        systemConfig.js \
index a3dc7be69fc96c5c771b375f68e24c98dd118ef2..a46d8ee7bc3d0a0640510e5a0a7f05243b6cd122 100644 (file)
@@ -4,4 +4,6 @@ var Rakka = {};
 Rakka.baseURI        = null;
 Rakka.isLocked       = false;
 Rakka.isGlobalLocked = false;
-Rakka.isSpecialPage  = false;
\ No newline at end of file
+Rakka.isSpecialPage  = false;
+
+Rakka.rePageName = /^[^ a-z.|#\[\]][^ .|#\[\]]*$/;
index 5d782de880484ded293528371a31f042cb25d3a9..406b7e3561603a5b083cf35e6870ad8f48b7bed2 100644 (file)
@@ -3,10 +3,6 @@
     var $previewHeader = null;
     var $previewArea   = null;
 
-    var isDirty = null;
-
-    var rePageName = /^[^ a-z.|#\[\]][^ .|#\[\]]*$/;
-
     Rakka.editPage = function (pageName) {
         var $area = Rakka.switchScreen();
 
@@ -79,6 +75,7 @@
 
         $area.append($.H1({}, pageName == "" ? "Create page" : "Edit page"));
 
+        var isDirty = null;
         var makeDirty = function () {
             isDirty = true;
         };
 
         var validate = function () {
             var isValid = (function () {
-                if (fldPageName.value.match(rePageName) == null) {
+                if (fldPageName.value.match(Rakka.rePageName) == null) {
                     return false;
                 }
 
                 if (btnTypeRedirect.checked) {
-                    if (fldRedirect.value.match(rePageName) == null) {
+                    if (fldRedirect.value.match(Rakka.rePageName) == null) {
                         return false;
                     }
                 }
                 else {
                     for (var tag in otherLangs) {
-                        if (otherLangs[tag].match(rePageName) == null) {
+                        if (otherLangs[tag].match(Rakka.rePageName) == null) {
                             return false;
                         }
                     }
         if (!Rakka.isLoggedIn() || Rakka.isGlobalLocked) {
             $(trIsLocked).hide();
         }
-
-        isDirty = false;
     };
 
     var previewRakkaPage = function (pageName, source) {
diff --git a/js/parseuri.js b/js/parseuri.js
new file mode 100644 (file)
index 0000000..f772a15
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+       parseUri 1.2.1
+       (c) 2007 Steven Levithan <stevenlevithan.com>
+       MIT License
+*/
+
+function parseUri (str) {
+       var     o   = parseUri.options,
+               m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
+               uri = {},
+               i   = 14;
+
+       while (i--) uri[o.key[i]] = m[i] || "";
+
+       uri[o.q.name] = {};
+       uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
+               if ($1) uri[o.q.name][$1] = $2;
+       });
+
+       return uri;
+};
+
+parseUri.options = {
+       strictMode: false,
+       key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
+       q:   {
+               name:   "queryKey",
+               parser: /(?:^|&)([^&=]*)=?([^&]*)/g
+       },
+       parser: {
+               strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
+               loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
+       }
+};
index e9254e3837d867236cc4645eb0a28ca28917af54..5ea6393aa40b54ea7df2f9afb5c7d0cd68a781be 100644 (file)
 
      var cachedConf = null;
 
+     var isValidBaseURI = function (str) {
+         parseUri.options.strictMode = true;
+         var uri = parseUri(str);
+
+         return (uri.protocol != "" &&
+                 uri.authority != "" &&
+                 uri.path != "" &&
+                 uri.path.match(/\/$/) &&
+                 uri.query == "" &&
+                 uri.anchor == "");
+     };
+
     Rakka.getSystemConfig = function () {
         if (cachedConf != null) {
             return cachedConf;
                               )
                       );
 
+         var validate = function () {
+             var isValid = (function () {
+                                if (!isValidBaseURI(fldBaseURI.value)) {
+                                    return false;
+                                }
+
+                                return true;
+                            })();
+
+             $(btnSave).attr({disabled: (isValid ? "" : "disabled")});
+         };
+
+         var isDirty = null;
+         var makeDirty = function () {
+             isDirty = true;
+         };
+
+         $(fldSiteName)
+             .add(fldBaseURI)
+             .add(fldDefaultPage)
+             .add(fldStyleSheet)
+             .add(fldLanguages)
+             .change(validate)
+             .keyup(validate)
+             .change(makeDirty);
+
          $area.append(configPanel);
      };