Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value ShowDegrade Collection (separate keys) #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 32 additions & 17 deletions dist/enquire.js
Expand Up @@ -229,22 +229,29 @@ MediaQuery.prototype = {
* @param {boolean} [shouldDegrade=false] whether this particular media query should always run on incapable browsers
*/
register : function(q, options, shouldDegrade) {
var queries = this.queries,
var key = q,
queries = this.queries,
isUnconditional = shouldDegrade && this.browserIsIncapable;

if(!queries[q]) {
queries[q] = new MediaQuery(q, isUnconditional);
//The collection that kept track of event handlers did not take in account the value "showDegrade".
//We are now storing event handlers on separate keys according to the value of this parameter.
if(isUnconditional){
key = key + '-isUnconditional';
}

//normalise to object in an array
if(isFunction(options)) {
options = { match : options };
if (!queries[key]) {
queries[key] = new MediaQuery(key, isUnconditional);
}
if(!isArray(options)) {

//normalise to object in an array
if (isFunction(options)) {
options = { match: options };
}
if (!isArray(options)) {
options = [options];
}
each(options, function(handler) {
queries[q].addHandler(handler);
each(options, function (handler) {
queries[key].addHandler(handler);
});

return this;
Expand All @@ -257,18 +264,26 @@ MediaQuery.prototype = {
* @param {object || function} [handler] specific handler to unregister
*/
unregister : function(q, handler) {
var query = this.queries[q];

if(query) {
if(handler) {
query.removeHandler(handler);
}
else {
query.clear();
delete this.queries[q];
var self = this;

function _unregister(q, handler) {
var query = self.queries[q];

if (query) {
if (handler) {
query.removeHandler(handler);
}
else {
query.clear();
delete self.queries[q];
}
}
}

_unregister(q, handler);
_unregister(q + '-isUnconditional', handler);

return this;
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/enquire.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 32 additions & 17 deletions src/MediaQueryDispatch.js
Expand Up @@ -27,22 +27,29 @@
* @param {boolean} [shouldDegrade=false] whether this particular media query should always run on incapable browsers
*/
register : function(q, options, shouldDegrade) {
var queries = this.queries,
var key = q,
queries = this.queries,
isUnconditional = shouldDegrade && this.browserIsIncapable;

if(!queries[q]) {
queries[q] = new MediaQuery(q, isUnconditional);
//The collection that kept track of event handlers did not take in account the value "showDegrade".
//We are now storing event handlers on separate keys according to the value of this parameter.
if(isUnconditional){
key = key + '-isUnconditional';
}

//normalise to object in an array
if(isFunction(options)) {
options = { match : options };
if (!queries[key]) {
queries[key] = new MediaQuery(key, isUnconditional);
}
if(!isArray(options)) {

//normalise to object in an array
if (isFunction(options)) {
options = { match: options };
}
if (!isArray(options)) {
options = [options];
}
each(options, function(handler) {
queries[q].addHandler(handler);
each(options, function (handler) {
queries[key].addHandler(handler);
});

return this;
Expand All @@ -55,18 +62,26 @@
* @param {object || function} [handler] specific handler to unregister
*/
unregister : function(q, handler) {
var query = this.queries[q];

if(query) {
if(handler) {
query.removeHandler(handler);
}
else {
query.clear();
delete this.queries[q];
var self = this;

function _unregister(q, handler) {
var query = self.queries[q];

if (query) {
if (handler) {
query.removeHandler(handler);
}
else {
query.clear();
delete self.queries[q];
}
}
}

_unregister(q, handler);
_unregister(q + '-isUnconditional', handler);

return this;
}
};