diff --git a/proj9/assets/js/script.js b/proj9/assets/js/script.js index cc49c67..8546f09 100644 --- a/proj9/assets/js/script.js +++ b/proj9/assets/js/script.js @@ -1,3 +1,59 @@ (function($) { - + var doc = $(document), + // General storage container for session + clickStats = { + url: document.location.href, + clicks: [] + }, + // Store objects representing each layout for the document + layouts = []; + + // Set AJAX options + $.ajaxSetup({ + type: 'POST', + contentType: 'application/json', + dataType: 'json' + }); + + // Parse any stylesheet attached to document via elements + // x = index + // ss = current stylesheet object + $.each(doc[0].styleSheets, function(x, ss) { + // Iterate through rules of stylesheet + // y = index + // rule = current rule + $.each(ss.rules, function(y, rule) { + // Is this a valid `CSSMediaRule` rule? + if (rule.media && rule.media.length) { + // We have a media query! + + var jq = $, + // store the media query definition + current = rule.media[0], + // store the breakpoints of said media query + mq = { + min: (current.indexOf('min') !== -1) ? jq.trim(current.split('min-width:')[1].split('px')[0]) : 0, + max: (current.indexOf('max') !== -1) ? jq.trim(current.split('max-width:')[1].split('px')[0]) : 'none' + }; + + // Save whatcha got + layouts.push(mq); + } + }); + }); + + // Sort in ascending order + // Makes breakpoint detection much more efficient + layouts.sort(function(a, b) { + return a.min - b.min; + }); + + // Send to server so it can be saved + $.ajax({ + url: 'heat-map.asmx/saveLayouts', + data: JSON.stringify({ + url: url, + layouts: layouts + }); + }) })(jQuery); \ No newline at end of file diff --git a/proj9/heat-map.asmx b/proj9/heat-map.asmx new file mode 100755 index 0000000..8e517ac --- /dev/null +++ b/proj9/heat-map.asmx @@ -0,0 +1 @@ +<%@ WebService Language="C#" CodeBehind="~/App_Code/heat-map.cs" Class="heat_map" %>