/*! Kernel CI Dashboard | Licensed under the GNU GPL v3 (or later) */
define([
    'jquery'
], function($) {
    'use strict';
    var get,
        post,
        request,
        settings,
        token = null;

    if (document.querySelector('meta[name=csrf-token]') !== null) {
        token = document.querySelector('meta[name=csrf-token]').content;
    }

    settings = {
        traditional: true,
        cache: true,
        dataType: 'json',
        timeout: 35000,
        beforeSend: function(jqXHR) {
            jqXHR.setRequestHeader('X-CSRFToken', token);
        }
    };

    get = function(url, data) {
        return request('GET', url, data);
    };

    post = function(url, data) {
        return request('POST', url, data);
    };

    request = function(method, url, data) {
        settings.headers = {'Content-Type': 'application/json'};
        settings.type = method;

        if (data === null || data === undefined) {
            data = {};
        }
        settings.data = data;

        return $.ajax(url, settings);
    };

    return {
        get: get,
        post: post
    };
});

@@ -132,232 +132,53 @@
 var 
-get,%0A        post,%0A        request,%0A        settings,%0A        token = null;%0A%0A    if (document.querySelector('meta%5Bname=csrf-token%5D') !== null) %7B%0A        token = document.querySelector('meta%5Bname=csrf-token%5D').content;%0A    %7D%0A
+request,%0A        settings;%0A%0A    request = %7B%7D;
 %0A   
@@ -381,13 +381,19 @@
 n', 
-t
+_getT
 oken
+()
 );%0A 
@@ -416,14 +416,8 @@
 %0A   
- get =
  fun
@@ -417,34 +417,35 @@
     function
-(url, data
+ _getToken(
 ) %7B%0A        
@@ -448,156 +448,255 @@
     
-return request('GET', url, data);%0A    %7D;%0A%0A    post = function(url, data) %7B%0A        return request('POST', url, data);%0A    %7D;%0A%0A    request = function
+var token;%0A%0A        token = null;%0A        if (document.querySelector('meta%5Bname=csrf-token%5D') !== null) %7B%0A            token = document.querySelector('meta%5Bname=csrf-token%5D').content;%0A        %7D%0A        return token;%0A    %7D%0A%0A    function _makeRequest
 (met
@@ -827,43 +827,13 @@
 if (
+!
 data
- === null %7C%7C data === undefined
 ) %7B%0A
@@ -939,25 +939,24 @@
 );%0A    %7D
-;
 %0A%0A    re
 turn %7B%0A 
@@ -947,20 +947,47 @@
 %0A%0A    re
-turn
+quest.get = function(url, data)
  %7B%0A     
@@ -993,42 +993,170 @@
     
-get: get,%0A        post: post%0A    %7D
+return _makeRequest('GET', url, data);%0A    %7D;%0A%0A    request.post = function(url, data) %7B%0A        return _makeRequest('POST', url, data);%0A    %7D;%0A%0A    return request
 ;%0A%7D)

Clean up code on request creation