]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
jsLinted ajax.js, removed experimental functions
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 6 Nov 2010 03:16:17 +0000 (03:16 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 6 Nov 2010 03:16:17 +0000 (03:16 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7241 36083f99-b078-4883-b0ff-0f9b5a30f544

js/lib/ajax.js

index 184fd0da3868736f4f82bd27f776658fc8e4624f..95ec7948e4908b04224c449bca7e8373d74c4b07 100644 (file)
@@ -1,3 +1,4 @@
+/*globals elgg, $*/\r
 elgg.provide('elgg.ajax');\r
 \r
 /**\r
@@ -15,7 +16,7 @@ elgg.provide('elgg.ajax');
  * @param {Object} options Optional. {@see jQuery#ajax}\r
  * @return {XmlHttpRequest}\r
  */\r
-elgg.ajax = function(url, options) {\r
+elgg.ajax = function (url, options) {\r
        options = elgg.ajax.handleOptions(url, options);\r
        \r
        options.url = elgg.normalize_url(options.url);\r
@@ -39,9 +40,13 @@ elgg.ajax.ERROR = -1;
  * @return {Object}\r
  * @private\r
  */\r
-elgg.ajax.handleOptions = function(url, options) {\r
+elgg.ajax.handleOptions = function (url, options) {\r
+       var data_only = true,\r
+               data,\r
+               member;\r
+       \r
        //elgg.ajax('example/file.php', {...});\r
-       if(typeof url == 'string') {\r
+       if (typeof url === 'string') {\r
                options = options || {};\r
        \r
        //elgg.ajax({...});\r
@@ -50,21 +55,19 @@ elgg.ajax.handleOptions = function(url, options) {
                url = options.url;\r
        }\r
        \r
-       var data_only = true;\r
-\r
        //elgg.ajax('example/file.php', function() {...});\r
-       if (typeof options == 'function') {\r
+       if (typeof options === 'function') {\r
                data_only = false;\r
                options = {success: options};\r
        }\r
        \r
        //elgg.ajax('example/file.php', {data:{...}});\r
-       if(options.data) {\r
+       if (options.data) {\r
                data_only = false;\r
        } else {\r
-               for (var member in options) {\r
+               for (member in options) {\r
                        //elgg.ajax('example/file.php', {callback:function(){...}});\r
-                       if(typeof options[member] == 'function') {\r
+                       if (typeof options[member] === 'function') {\r
                                data_only = false;\r
                        }\r
                }\r
@@ -72,7 +75,7 @@ elgg.ajax.handleOptions = function(url, options) {
 \r
        //elgg.ajax('example/file.php', {notdata:notfunc});\r
        if (data_only) {\r
-               var data = options;\r
+               data = options;\r
                options = {data: data};\r
        }\r
        \r
@@ -90,7 +93,7 @@ elgg.ajax.handleOptions = function(url, options) {
  * @param {Object} options {@see jQuery#ajax}\r
  * @return {XmlHttpRequest}\r
  */\r
-elgg.get = function(url, options) {\r
+elgg.get = function (url, options) {\r
        options = elgg.ajax.handleOptions(url, options);\r
        \r
        options.type = 'get';\r
@@ -104,7 +107,7 @@ elgg.get = function(url, options) {
  * @param {Object} options {@see jQuery#ajax}\r
  * @return {XmlHttpRequest}\r
  */\r
-elgg.getJSON = function(url, options) {\r
+elgg.getJSON = function (url, options) {\r
        options = elgg.ajax.handleOptions(url, options);\r
        \r
        options.dataType = 'json';\r
@@ -118,7 +121,7 @@ elgg.getJSON = function(url, options) {
  * @param {Object} options {@see jQuery#ajax}\r
  * @return {XmlHttpRequest}\r
  */\r
-elgg.post = function(url, options) {\r
+elgg.post = function (url, options) {\r
        options = elgg.ajax.handleOptions(url, options);\r
        \r
        options.type = 'post';\r
@@ -167,12 +170,8 @@ elgg.post = function(url, options) {
  * @param {Object} options {@see jQuery#ajax}\r
  * @return {XMLHttpRequest}\r
  */\r
-elgg.action = function(action, options) {\r
-       if(!action) {\r
-               throw new TypeError("action must be specified");\r
-       } else if (typeof action != 'string') {\r
-               throw new TypeError("action must be a string");\r
-       }\r
+elgg.action = function (action, options) {\r
+       elgg.assertTypeOf('string', action);\r
        \r
        options = elgg.ajax.handleOptions('action/' + action, options);\r
        \r
@@ -180,12 +179,13 @@ elgg.action = function(action, options) {
        options.dataType = 'json';\r
        \r
        //Always display system messages after actions\r
-       var custom_success = options.success || function(){};\r
-       options.success = function(json, two, three, four) {\r
+       var custom_success = options.success || function () {};\r
+       options.success = function (json, two, three, four) {\r
                if (json.system_messages) {\r
                        elgg.register_error(json.system_messages.errors);\r
                        elgg.system_message(json.system_messages.messages);\r
                }\r
+               \r
                custom_success(json, two, three, four);\r
        };\r
        \r
@@ -208,12 +208,8 @@ elgg.action = function(action, options) {
  * @param {Object} options {@see jQuery#ajax}\r
  * @return {XmlHttpRequest}\r
  */\r
-elgg.api = function(method, options) {\r
-       if (!method) {\r
-               throw new TypeError("method must be specified");\r
-       } else if (typeof method != 'string') {\r
-               throw new TypeError("method must be a string");\r
-       }\r
+elgg.api = function (method, options) {\r
+       elgg.assertTypeOf('string', method);\r
        \r
        var defaults = {\r
                dataType: 'json',\r
@@ -227,26 +223,4 @@ elgg.api = function(method, options) {
        options.data.method = method;\r
        \r
        return elgg.ajax(options);\r
-};\r
-\r
-/**\r
- * @param {string} selector a jQuery selector\r
- * @param {Function} complete A function to execute when the refresh is done\r
- * @return {XMLHttpRequest}\r
- */\r
-elgg.refresh = function(selector, complete) {\r
-       $(selector).html('<div align="center" class="ajax_loader"></div>');\r
-       return $(selector).load(location.href + ' ' + selector + ' > *', complete);\r
-};\r
-\r
-/**\r
- * @param {string} selector a jQuery selector (usually an #id)\r
- * @param {number} interval The refresh interval in seconds\r
- * @param {Function} complete A function to execute when the refresh is done\r
- * @return {number} The interval identifier\r
- */\r
-elgg.feed = function(selector, interval, complete) {\r
-       return setInterval(function() {\r
-               elgg.refresh(selector, complete);\r
-       }, interval);\r
 };
\ No newline at end of file