Skip to content

Commit

Permalink
A few more tweaks...
Browse files Browse the repository at this point in the history
  • Loading branch information
Micky Hulse committed Oct 24, 2012
1 parent b74e97b commit 8fcb07e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 48 deletions.
48 changes: 24 additions & 24 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,54 +57,54 @@ <h2 class="delta">Delta</h2>
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());

}
}
Expand All @@ -119,29 +119,29 @@ <h2 class="delta">Delta</h2>

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());

}
});

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());

}
});
Expand Down
45 changes: 21 additions & 24 deletions onmediaquery/onmediaquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
Expand Down Expand Up @@ -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.
*
Expand All @@ -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();

};

Expand All @@ -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 <html> element...
if (query_string !== null) {
Expand Down Expand Up @@ -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".
*
Expand Down

0 comments on commit 8fcb07e

Please sign in to comment.