Browse Source

JS Refact

omassot 7 năm trước cách đây
mục cha
commit
dcb98206e1
3 tập tin đã thay đổi với 40 bổ sung39 xóa
  1. 39 0
      main/static/js/common.js
  2. 0 39
      main/static/js/custom.js
  3. 1 0
      main/templates/_layout.html

+ 39 - 0
main/static/js/common.js

@@ -0,0 +1,39 @@
+
+var loc_uri = URI.parse(window.location.href);
+var loc_qry = URI.parseQuery(loc_uri.query)
+
+var getUrlParameter = function getUrlParameter(sParam) {
+    var sPageURL = window.location.search.substring(1),
+        sURLVariables = sPageURL.split('&'),
+        sParameterName,
+        i;
+
+    for (i = 0; i < sURLVariables.length; i++) {
+        sParameterName = sURLVariables[i].split('=');
+
+        if (sParameterName[0] === sParam) {
+            return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
+        }
+    }
+};
+
+function csrfSafeMethod(method) {
+    // these HTTP methods do not require CSRF protection
+    return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
+}
+function getCookie(name) {
+    var cookieValue = null;
+    if (document.cookie && document.cookie !== '') {
+        var cookies = document.cookie.split(';');
+        for (var i = 0; i < cookies.length; i++) {
+            var cookie = jQuery.trim(cookies[i]);
+            // Does this cookie string begin with the name we want?
+            if (cookie.substring(0, name.length + 1) === (name + '=')) {
+                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+                break;
+            }
+        }
+    }
+    return cookieValue;
+}
+var csrftoken = getCookie('csrftoken');

+ 0 - 39
main/static/js/custom.js

@@ -12,9 +12,6 @@ $(document).ready( function () {
 		}
 	});
 	
-	var loc_uri = URI.parse(window.location.href);
-	var loc_qry = URI.parseQuery(loc_uri.query)
-	
 	$('.filters-bar').children('select[data-filter]').each(function () {
 		var filter_name = $(this).data('filter');
 		if(filter_name in loc_qry) {
@@ -84,21 +81,6 @@ $(document).ready( function () {
 		window.location.href = target;
 	});
 	
-	var getUrlParameter = function getUrlParameter(sParam) {
-	    var sPageURL = window.location.search.substring(1),
-	        sURLVariables = sPageURL.split('&'),
-	        sParameterName,
-	        i;
-
-	    for (i = 0; i < sURLVariables.length; i++) {
-	        sParameterName = sURLVariables[i].split('=');
-
-	        if (sParameterName[0] === sParam) {
-	            return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
-	        }
-	    }
-	};
-	
 	$('#id_epic').val([getUrlParameter('epic')])
 	$('#id_name').val([getUrlParameter('name')])
 	$('#id_weight').val([getUrlParameter('weight')])
@@ -138,27 +120,6 @@ $(document).ready( function () {
 		}
 	});
 	
-	function csrfSafeMethod(method) {
-	    // these HTTP methods do not require CSRF protection
-	    return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
-	}
-	function getCookie(name) {
-	    var cookieValue = null;
-	    if (document.cookie && document.cookie !== '') {
-	        var cookies = document.cookie.split(';');
-	        for (var i = 0; i < cookies.length; i++) {
-	            var cookie = jQuery.trim(cookies[i]);
-	            // Does this cookie string begin with the name we want?
-	            if (cookie.substring(0, name.length + 1) === (name + '=')) {
-	                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
-	                break;
-	            }
-	        }
-	    }
-	    return cookieValue;
-	}
-	var csrftoken = getCookie('csrftoken');
-	
 	$(".notif-seen").click(function(event) {
 		event.preventDefault();
 		var notif = $(this).closest('.notif');

+ 1 - 0
main/templates/_layout.html

@@ -39,6 +39,7 @@
 		<script type="text/javascript" src="{% static 'plugins/js/emojis.min.js' %}"></script>
 		<script type="text/javascript" src="{% static 'martor/js/martor.min.js' %}"></script>
 		<script type="text/javascript" src="{% static 'js/Chart.bundle.js' %}"></script>
+		<script type="text/javascript" src="{% static 'js/common.js' %}"></script>
 		<script type="text/javascript" src="{% static 'js/custom.js' %}"></script>
 		
 	</head>