From 8fcb07eb0a9958915845bfbd82f655cb69e01c18 Mon Sep 17 00:00:00 2001 From: Micky Hulse Date: Wed, 24 Oct 2012 15:01:48 -0700 Subject: [PATCH] A few more tweaks... --- demo/index.html | 48 ++++++++++++++++++------------------ onmediaquery/onmediaquery.js | 45 ++++++++++++++++----------------- 2 files changed, 45 insertions(+), 48 deletions(-) diff --git a/demo/index.html b/demo/index.html index b277965..ec19dc5 100644 --- a/demo/index.html +++ b/demo/index.html @@ -57,54 +57,54 @@

Delta

queries = [ { - context : 'alpha', + context : 'alpha', match : function() { - msg('MATCH: alpha, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('MATCH: alpha, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); }, - unmatch: function () { + unmatch : function() { - msg('UNMATCH: alpha, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('UNMATCH: alpha, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); } }, { - context : 'bravo', + context : 'bravo', match : function() { - msg('MATCH: bravo, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('MATCH: bravo, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); }, - unmatch: function () { + unmatch : function() { - msg('UNMATCH: bravo, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('UNMATCH: bravo, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); } }, { - context : 'charlie', + context : 'charlie', match : function() { - msg('MATCH: charlie, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('MATCH: charlie, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); }, - unmatch: function () { + unmatch : function() { - msg('UNMATCH: charlie, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('UNMATCH: charlie, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); } }, { - context : 'delta', + context : 'delta', callback : function() { - msg('MATCH: delta, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('MATCH: delta, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); }, - unmatch: function () { + unmatch : function() { - msg('UNMATCH: delta, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('UNMATCH: delta, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); } } @@ -119,14 +119,14 @@

Delta

var my_query = oMQ.addQuery({ context: 'large', - match: function() { + match : function() { - msg('MATCH: large, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('MATCH: large, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); }, - unmatch: function () { + unmatch : function() { - msg('UNMATCH: large, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('UNMATCH: large, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); } }); @@ -134,14 +134,14 @@

Delta

var my_other_query = oMQ.addQuery({ context: ['charlie', 'large', 'delta'], call_for_each_context: false, - match: function() { + match : function() { - msg('MATCH: charlie/large/delta, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('MATCH: charlie/large/delta, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); }, - unmatch: function () { + unmatch : function() { - msg('UNMATCH: charlie/large/delta, CURRENT CONTEXT: ' + oMQ.getCurrentContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); + msg('UNMATCH: charlie/large/delta, CURRENT CONTEXT: ' + oMQ.getContext() + ', LAST CONTEXT: ' + oMQ.getLastContext()); } }); diff --git a/onmediaquery/onmediaquery.js b/onmediaquery/onmediaquery.js index ed45753..b181f99 100644 --- a/onmediaquery/onmediaquery.js +++ b/onmediaquery/onmediaquery.js @@ -80,10 +80,7 @@ if ((this.last_context !== '') && _inArray(this.last_context, query_object.context)) { - console.log(query_object); - // Fire the added callback if it matches the current context: - //query_object.callback(); query_object.match(); } @@ -120,24 +117,6 @@ //-------------------------------------------------------------------- - /** - * Get the current context. - * - * @return { string } The currently defined media query. - */ - - omq.getContext = function() { - - // Returns the first value that is "truth-like", or the last value, if no values are "truth-like": - var context = _contentAfter(document.body) || _fontFamily(document.documentElement); - - // Android browsers place a "," after an item in the font family list; most browsers either single or double quote the string: - return context.replace(/['",]/g, ''); - - }; - - //-------------------------------------------------------------------- - /** * Getter that returns the media query's last context. * @@ -157,9 +136,9 @@ * @return { string } Returns the current media query's context. */ - omq.getCurrentContext = function() { + omq.getContext = function() { - return this.context; + return (this.context) ? this.context : _pickContext(); }; @@ -178,7 +157,7 @@ function _listenForChange() { // Get the value of :after or font-family from the chosen element style: - var query_string = this.getContext(); + var query_string = _pickContext(); // Do we have a context? Note that Opera doesn't jive with font-family on the element... if (query_string !== null) { @@ -279,6 +258,24 @@ //-------------------------------------------------------------------- + /** + * Get the current context. + * + * @return { string } The currently defined media query. + */ + + function _pickContext() { + + // Returns the first value that is "truth-like", or the last value, if no values are "truth-like": + var context = _contentAfter(document.body) || _fontFamily(document.documentElement); + + // Android browsers place a "," after an item in the font family list; most browsers either single or double quote the string: + return context.replace(/['",]/g, ''); + + } + + //-------------------------------------------------------------------- + /** * Checks if "needle" occurs in "haystack". *