Skip to content

Commit

Permalink
Bump version 2.0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
doabit committed Aug 10, 2015
1 parent 67e7791 commit 867150f
Show file tree
Hide file tree
Showing 51 changed files with 296 additions and 161 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.7.0

* Update Semantic UI to 2.0.7

## 2.0.4.0

* Update Semantic UI to 2.0.4
Expand Down
109 changes: 75 additions & 34 deletions app/assets/javascripts/semantic-ui/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ $.api = $.fn.api = function(parameters) {
}
},

decode: {
json: function(response) {
if(response !== undefined && typeof response == 'string') {
try {
response = JSON.parse(response);
}
catch(e) {
// isnt json string
}
}
return response;
}
},

read: {
cachedResponse: function(url) {
var
Expand All @@ -126,15 +140,7 @@ $.api = $.fn.api = function(parameters) {
}
response = sessionStorage.getItem(url);
module.debug('Using cached response', url, response);
if(response !== undefined) {
try {
response = JSON.parse(response);
}
catch(e) {
// didnt store object
}
return response;
}
response = module.decode.json(response);
return false;
}
},
Expand Down Expand Up @@ -287,7 +293,7 @@ $.api = $.fn.api = function(parameters) {
}
},
validResponse: function(response) {
if( settings.dataType !== 'json' || !$.isFunction(settings.successTest) ) {
if( (settings.dataType !== 'json' && settings.dataType !== 'jsonp') || !$.isFunction(settings.successTest) ) {
module.verbose('Response is not JSON, skipping validation', settings.successTest, response);
return true;
}
Expand Down Expand Up @@ -352,7 +358,7 @@ $.api = $.fn.api = function(parameters) {
}
else {
module.verbose('Found required variable', variable, value);
url = url.replace(templatedString, value);
url = url.replace(templatedString, module.get.urlEncodedValue(value));
}
});
}
Expand Down Expand Up @@ -445,13 +451,13 @@ $.api = $.fn.api = function(parameters) {
},
xhr: {
always: function() {
// calculate if loading time was below minimum threshold
// nothing special
},
done: function(response, textStatus, xhr) {
var
context = this,
elapsedTime = (new Date().getTime() - requestStartTime),
timeLeft = (settings.loadingDuration - elapsedTime),
context = this,
elapsedTime = (new Date().getTime() - requestStartTime),
timeLeft = (settings.loadingDuration - elapsedTime),
translatedResponse = ( $.isFunction(settings.onResponse) )
? settings.onResponse.call(context, $.extend(true, {}, response))
: false
Expand All @@ -469,7 +475,7 @@ $.api = $.fn.api = function(parameters) {
}
setTimeout(function() {
if( module.is.validResponse(response) ) {
module.request.resolveWith(context, [response]);
module.request.resolveWith(context, [response, xhr]);
}
else {
module.request.rejectWith(context, [xhr, 'invalid']);
Expand Down Expand Up @@ -500,46 +506,52 @@ $.api = $.fn.api = function(parameters) {
}
},
request: {
complete: function(response) {
module.remove.loading();
settings.onComplete.call(context, response, $module);
},
done: function(response) {
done: function(response, xhr) {
module.debug('Successful API Response', response);
if(settings.cache === 'local' && url) {
module.write.cachedResponse(url, response);
module.debug('Saving server response locally', module.cache);
}
settings.onSuccess.call(context, response, $module);
settings.onSuccess.call(context, response, $module, xhr);
},
complete: function(firstParameter, secondParameter) {
var
xhr,
response
;
// have to guess callback parameters based on request success
if( module.was.succesful() ) {
response = firstParameter;
xhr = secondParameter;
}
else {
xhr = firstParameter;
response = module.get.responseFromXHR(xhr);
}
module.remove.loading();
settings.onComplete.call(context, response, $module, xhr);
},
fail: function(xhr, status, httpMessage) {
var
// pull response from xhr if available
response = $.isPlainObject(xhr)
? (xhr.responseText)
: false,
errorMessage = ($.isPlainObject(response) && response.error !== undefined)
? response.error // use json error message
: (settings.error[status] !== undefined) // use server error message
? settings.error[status]
: httpMessage
response = module.get.responseFromXHR(xhr),
errorMessage = module.get.errorFromRequest(response, status, httpMessage)
;
if(status == 'aborted') {
module.debug('XHR Aborted (Most likely caused by page navigation or CORS Policy)', status, httpMessage);
settings.onAbort.call(context, status, $module);
settings.onAbort.call(context, status, $module, xhr);
}
else if(status == 'invalid') {
module.debug('JSON did not pass success test. A server-side error has most likely occurred', response);
}
else if(status == 'error') {

if(xhr !== undefined) {
module.debug('XHR produced a server error', status, httpMessage);
// make sure we have an error to display to console
if( xhr.status != 200 && httpMessage !== undefined && httpMessage !== '') {
module.error(error.statusMessage + httpMessage, ajaxSettings.url);
}
settings.onError.call(context, errorMessage, $module);
settings.onError.call(context, errorMessage, $module, xhr);
}
}

Expand All @@ -549,7 +561,7 @@ $.api = $.fn.api = function(parameters) {
setTimeout(module.remove.error, settings.errorDuration);
}
module.debug('API Request failed', errorMessage, xhr);
settings.onFailure.call(context, response, $module);
settings.onFailure.call(context, response, $module, xhr);
}
}
},
Expand Down Expand Up @@ -650,6 +662,22 @@ $.api = $.fn.api = function(parameters) {
},

get: {
responseFromXHR: function(xhr) {
return $.isPlainObject(xhr)
? (settings.dataType == 'json' || settings.dataType == 'jsonp')
? module.decode.json(xhr.responseText)
: xhr.responseText
: false
;
},
errorFromRequest: function(response, status, httpMessage) {
return ($.isPlainObject(response) && response.error !== undefined)
? response.error // use json error message
: (settings.error[status] !== undefined) // use server error message
? settings.error[status]
: httpMessage
;
},
request: function() {
return module.request || false;
},
Expand Down Expand Up @@ -686,6 +714,19 @@ $.api = $.fn.api = function(parameters) {
: settings
;
},
urlEncodedValue: function(value) {
var
decodedValue = window.decodeURIComponent(value),
encodedValue = window.encodeURIComponent(value),
alreadyEncoded = (decodedValue !== value)
;
if(alreadyEncoded) {
module.debug('URL value is already encoded, avoiding double encoding', value);
return value;
}
module.verbose('Encoding value for url', value, encodedValue);
return encodedValue;
},
defaultData: function() {
var
data = {}
Expand Down
17 changes: 14 additions & 3 deletions app/assets/javascripts/semantic-ui/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ $.fn.checkbox = function(parameters) {
$label = $(this).children(selector.label),
$input = $(this).children(selector.input),

shortcutPressed = false,

instance = $module.data(moduleNamespace),

observer,
Expand Down Expand Up @@ -192,11 +194,19 @@ $.fn.checkbox = function(parameters) {
if(key == keyCode.escape) {
module.verbose('Escape key pressed blurring field');
$input.blur();
event.preventDefault();
shortcutPressed = true;
}
if(!event.ctrlKey && (key == keyCode.enter)) {
module.verbose('Enter key pressed, toggling checkbox');
else if(!event.ctrlKey && ( key == keyCode.space || key == keyCode.enter) ) {
module.verbose('Enter/space key pressed, toggling checkbox');
module.toggle();
shortcutPressed = true;
}
else {
shortcutPressed = false;
}
},
keyup: function(event) {
if(shortcutPressed) {
event.preventDefault();
}
}
Expand Down Expand Up @@ -455,6 +465,7 @@ $.fn.checkbox = function(parameters) {
$module
.on('click' + eventNamespace, module.event.click)
.on('keydown' + eventNamespace, selector.input, module.event.keydown)
.on('keyup' + eventNamespace, selector.input, module.event.keyup)
;
}
},
Expand Down
Loading

0 comments on commit 867150f

Please sign in to comment.