From cddd833c65cdd8092588bd3bdfe2b9153848302f Mon Sep 17 00:00:00 2001 From: pho Date: Fri, 11 Jul 2008 17:05:08 +0900 Subject: [PATCH] isValidBaseURI darcs-hash:20080711080508-62b54-d2d667916bd73acce66191a2bc33d17feb4f7a03.gz --- Rakka.cabal | 1 + js/Makefile | 1 + js/base.js | 4 +++- js/editPage.js | 13 ++++--------- js/parseuri.js | 34 ++++++++++++++++++++++++++++++++++ js/systemConfig.js | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 js/parseuri.js diff --git a/Rakka.cabal b/Rakka.cabal index 930cc76..6652e96 100644 --- a/Rakka.cabal +++ b/Rakka.cabal @@ -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 diff --git a/js/Makefile b/js/Makefile index 6db118d..e1e6b0c 100644 --- a/js/Makefile +++ b/js/Makefile @@ -10,6 +10,7 @@ SOURCES = \ localFile.js \ login.js \ redirection.js \ + parseuri.js \ screen.js \ search.js \ systemConfig.js \ diff --git a/js/base.js b/js/base.js index a3dc7be..a46d8ee 100644 --- a/js/base.js +++ b/js/base.js @@ -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.|#\[\]][^ .|#\[\]]*$/; diff --git a/js/editPage.js b/js/editPage.js index 5d782de..406b7e3 100644 --- a/js/editPage.js +++ b/js/editPage.js @@ -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; }; @@ -416,18 +413,18 @@ 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; } } @@ -466,8 +463,6 @@ 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 index 0000000..f772a15 --- /dev/null +++ b/js/parseuri.js @@ -0,0 +1,34 @@ +/* + parseUri 1.2.1 + (c) 2007 Steven Levithan + 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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ + } +}; diff --git a/js/systemConfig.js b/js/systemConfig.js index e9254e3..5ea6393 100644 --- a/js/systemConfig.js +++ b/js/systemConfig.js @@ -59,6 +59,18 @@ 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; @@ -159,6 +171,32 @@ ) ); + 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); }; -- 2.40.0