fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-05-12 08:38 am

[dw-free] Make an extract params method available to jQuery files

[commit: http://hg.dwscoalition.org/dw-free/rev/d94858266e5f]

http://bugs.dwscoalition.org/show_bug.cgi?id=3671

Move from jquery.commentmanage.js to dw-core which is available on every
page.

Patch by [personal profile] fu.

Files modified:
  • htdocs/js/dw/dw-core.js
  • htdocs/js/jquery.commentmanage.js
--------------------------------------------------------------------------------
diff -r dcbe47ef354f -r d94858266e5f htdocs/js/dw/dw-core.js
--- a/htdocs/js/dw/dw-core.js	Thu May 12 16:30:21 2011 +0800
+++ b/htdocs/js/dw/dw-core.js	Thu May 12 16:38:51 2011 +0800
@@ -1,13 +1,13 @@
 /*
     js/dw/dw-core.js
    
-    This is the core JavaScript module that gives us the main DW object we use
-    to do most of the site actions.
+    This is the core JavaScript module that gives us utility functions used throughout the site
    
     Authors:
          Mark Smith <mark@dreamwidth.org>
+         Afuna <coder.dw@afunamatata.com>
    
-    Copyright (c) 2009 by Dreamwidth Studios, LLC.
+    Copyright (c) 2009-2011 by Dreamwidth Studios, LLC.
    
     This program is free software; you may redistribute it and/or modify it under
     the same terms as Perl itself.  For a copy of the license, please reference
@@ -15,8 +15,34 @@
    
 */
 
-var DW = new Object();
+$.extractParams = function(url) {
+    if ( ! $.extractParams.cache )
+        $.extractParams.cache = {};
 
-/*****************************************************************************
- * INTERNAL FUNCTIONS BELOW HERE
- *****************************************************************************/
+    if ( url in $.extractParams.cache )
+        return $.extractParams.cache[url];
+
+    var search = url.indexOf( "?" );
+    if ( search == -1 ) {
+        $.extractParams.cache[url] = {};
+        return $.extractParams.cache[url];
+    }
+
+    var params = decodeURI( url.substring( search + 1 ) );
+    if ( ! params ) {
+        $.extractParams.cache[url] = {};
+        return $.extractParams.cache[url];
+    }
+
+    var paramsArray = params.split("&");
+    var params = {};
+    for( var i = 0; i < paramsArray.length; i++ ) {
+        var p = paramsArray[i].split("=");
+        var key = p[0];
+        var value = p.length < 2 ? undefined : p[1];
+        params[key] = value;
+    }
+
+    $.extractParams.cache[url] = params;
+    return params;
+};
diff -r dcbe47ef354f -r d94858266e5f htdocs/js/jquery.commentmanage.js
--- a/htdocs/js/jquery.commentmanage.js	Thu May 12 16:30:21 2011 +0800
+++ b/htdocs/js/jquery.commentmanage.js	Thu May 12 16:38:51 2011 +0800
@@ -1,36 +1,4 @@
 (function($) {
-$.extractParams = function(url) {
-    if ( ! $.extractParams.cache )
-        $.extractParams.cache = {};
-
-    if ( url in $.extractParams.cache )
-        return $.extractParams.cache[url];
-
-    var search = url.indexOf( "?" );
-    if ( search == -1 ) {
-        $.extractParams.cache[url] = {};
-        return $.extractParams.cache[url];
-    }
-
-    var params = decodeURI( url.substring( search + 1 ) );
-    if ( ! params ) {
-        $.extractParams.cache[url] = {};
-        return $.extractParams.cache[url];
-    }
-
-    var paramsArray = params.split("&");
-    var params = {};
-    for( var i = 0; i < paramsArray.length; i++ ) {
-        var p = paramsArray[i].split("=");
-        var key = p[0];
-        var value = p.length < 2 ? undefined : p[1];
-        params[key] = value;
-    }
-
-    $.extractParams.cache[url] = params;
-    return params;
-};
-
 $.widget("dw.moderate", {
     options: {
         journal: undefined,
--------------------------------------------------------------------------------