Demo entry 6655089

Javascript

   

Submitted by anonymous on Oct 25, 2017 at 16:25
Language: JavaScript. Code size: 1.6 kB.

/*Code Snippets*/

function debounce(func, wait, immediate) {
  var timeout;
  return function() {
    var context = this,
      args = arguments;
    var later = function() {
      timeout = null;
      if (!immediate) func.apply(context, args);
    };
    var callNow = immediate && !timeout;
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
    if (callNow) func.apply(context, args);
  };
}

function throttle(fn, threshhold, scope) {
  threshhold || (threshhold = 250);
  var last,
      deferTimer;
  return function () {
    var context = scope || this;

    var now = +new Date,
        args = arguments;
    if (last && now < last + threshhold) {
      // hold on to it
      clearTimeout(deferTimer);
      deferTimer = setTimeout(function () {
        last = now;
        fn.apply(context, args);
      }, threshhold);
    } else {
      last = now;
      fn.apply(context, args);
    }
  };
}

$(document).ready(function() {
	$("#commentModalLink").click(function() {
		getCommentsByUserId(userId);
	});
});

function getCommentsByUserId(userId) {
	$("#commentsTable").DataTable().destroy();
	table = $("#commentsTable").DataTable({
		"paging": true,
		"pageLength": 5,				
		"deferRender": true,
		"serverSide": true,
		"sAjaxSource": "/Ajax/GetCommentsByUserId",
		"fnServerParams": function (aoData) {
			$("#loading-div").show();
			aoData.push({ "name": "UserId", "value": userId });
		},
		"fnInitComplete": function () {
			$("#loading-div").hide();
		},
		"aoColumns": [
			{ "sName": "Comment" },
			{ "sName": "CreatedOn" }
		]
	});
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).