Browse Source

Import semantic

tags/v0.2.0b
Morgan Bazalgette 4 years ago
commit
feae62ecf7
100 changed files with 47631 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -0
      main.go
  3. +70
    -0
      semantic.json
  4. +72
    -0
      semantic/gulpfile.js
  5. +1142
    -0
      semantic/src/definitions/behaviors/api.js
  6. +274
    -0
      semantic/src/definitions/behaviors/colorize.js
  7. +1517
    -0
      semantic/src/definitions/behaviors/form.js
  8. +695
    -0
      semantic/src/definitions/behaviors/state.js
  9. +1216
    -0
      semantic/src/definitions/behaviors/visibility.js
  10. +517
    -0
      semantic/src/definitions/behaviors/visit.js
  11. +123
    -0
      semantic/src/definitions/collections/breadcrumb.less
  12. +1039
    -0
      semantic/src/definitions/collections/form.less
  13. +1913
    -0
      semantic/src/definitions/collections/grid.less
  14. +1928
    -0
      semantic/src/definitions/collections/menu.less
  15. +459
    -0
      semantic/src/definitions/collections/message.less
  16. +1101
    -0
      semantic/src/definitions/collections/table.less
  17. +3288
    -0
      semantic/src/definitions/elements/button.less
  18. +144
    -0
      semantic/src/definitions/elements/container.less
  19. +257
    -0
      semantic/src/definitions/elements/divider.less
  20. +53
    -0
      semantic/src/definitions/elements/flag.less
  21. +708
    -0
      semantic/src/definitions/elements/header.less
  22. +478
    -0
      semantic/src/definitions/elements/icon.less
  23. +319
    -0
      semantic/src/definitions/elements/image.less
  24. +507
    -0
      semantic/src/definitions/elements/input.less
  25. +1257
    -0
      semantic/src/definitions/elements/label.less
  26. +938
    -0
      semantic/src/definitions/elements/list.less
  27. +269
    -0
      semantic/src/definitions/elements/loader.less
  28. +135
    -0
      semantic/src/definitions/elements/rail.less
  29. +266
    -0
      semantic/src/definitions/elements/reveal.less
  30. +727
    -0
      semantic/src/definitions/elements/segment.less
  31. +542
    -0
      semantic/src/definitions/elements/step.less
  32. +41
    -0
      semantic/src/definitions/globals/reset.less
  33. +487
    -0
      semantic/src/definitions/globals/site.js
  34. +167
    -0
      semantic/src/definitions/globals/site.less
  35. +596
    -0
      semantic/src/definitions/modules/accordion.js
  36. +220
    -0
      semantic/src/definitions/modules/accordion.less
  37. +809
    -0
      semantic/src/definitions/modules/checkbox.js
  38. +596
    -0
      semantic/src/definitions/modules/checkbox.less
  39. +693
    -0
      semantic/src/definitions/modules/dimmer.js
  40. +190
    -0
      semantic/src/definitions/modules/dimmer.less
  41. +3442
    -0
      semantic/src/definitions/modules/dropdown.js
  42. +1334
    -0
      semantic/src/definitions/modules/dropdown.less
  43. +659
    -0
      semantic/src/definitions/modules/embed.js
  44. +164
    -0
      semantic/src/definitions/modules/embed.less
  45. +892
    -0
      semantic/src/definitions/modules/modal.js
  46. +485
    -0
      semantic/src/definitions/modules/modal.less
  47. +486
    -0
      semantic/src/definitions/modules/nag.js
  48. +159
    -0
      semantic/src/definitions/modules/nag.less
  49. +1413
    -0
      semantic/src/definitions/modules/popup.js
  50. +370
    -0
      semantic/src/definitions/modules/popup.less
  51. +795
    -0
      semantic/src/definitions/modules/progress.js
  52. +504
    -0
      semantic/src/definitions/modules/progress.less
  53. +475
    -0
      semantic/src/definitions/modules/rating.js
  54. +192
    -0
      semantic/src/definitions/modules/rating.less
  55. +1345
    -0
      semantic/src/definitions/modules/search.js
  56. +417
    -0
      semantic/src/definitions/modules/search.less
  57. +876
    -0
      semantic/src/definitions/modules/shape.js
  58. +151
    -0
      semantic/src/definitions/modules/shape.less
  59. +1022
    -0
      semantic/src/definitions/modules/sidebar.js
  60. +553
    -0
      semantic/src/definitions/modules/sidebar.less
  61. +907
    -0
      semantic/src/definitions/modules/sticky.js
  62. +75
    -0
      semantic/src/definitions/modules/sticky.less
  63. +898
    -0
      semantic/src/definitions/modules/tab.js
  64. +95
    -0
      semantic/src/definitions/modules/tab.less
  65. +1074
    -0
      semantic/src/definitions/modules/transition.js
  66. +79
    -0
      semantic/src/definitions/modules/transition.less
  67. +268
    -0
      semantic/src/definitions/views/ad.less
  68. +1041
    -0
      semantic/src/definitions/views/card.less
  69. +256
    -0
      semantic/src/definitions/views/comment.less
  70. +279
    -0
      semantic/src/definitions/views/feed.less
  71. +465
    -0
      semantic/src/definitions/views/item.less
  72. +558
    -0
      semantic/src/definitions/views/statistic.less
  73. +66
    -0
      semantic/src/semantic.less
  74. +3
    -0
      semantic/src/site/collections/breadcrumb.overrides
  75. +3
    -0
      semantic/src/site/collections/breadcrumb.variables
  76. +3
    -0
      semantic/src/site/collections/form.overrides
  77. +3
    -0
      semantic/src/site/collections/form.variables
  78. +3
    -0
      semantic/src/site/collections/grid.overrides
  79. +3
    -0
      semantic/src/site/collections/grid.variables
  80. +3
    -0
      semantic/src/site/collections/menu.overrides
  81. +3
    -0
      semantic/src/site/collections/menu.variables
  82. +3
    -0
      semantic/src/site/collections/message.overrides
  83. +3
    -0
      semantic/src/site/collections/message.variables
  84. +3
    -0
      semantic/src/site/collections/table.overrides
  85. +3
    -0
      semantic/src/site/collections/table.variables
  86. +3
    -0
      semantic/src/site/elements/button.overrides
  87. +3
    -0
      semantic/src/site/elements/button.variables
  88. +3
    -0
      semantic/src/site/elements/container.overrides
  89. +3
    -0
      semantic/src/site/elements/container.variables
  90. +3
    -0
      semantic/src/site/elements/divider.overrides
  91. +3
    -0
      semantic/src/site/elements/divider.variables
  92. +3
    -0
      semantic/src/site/elements/flag.overrides
  93. +3
    -0
      semantic/src/site/elements/flag.variables
  94. +3
    -0
      semantic/src/site/elements/header.overrides
  95. +3
    -0
      semantic/src/site/elements/header.variables
  96. +3
    -0
      semantic/src/site/elements/icon.overrides
  97. +3
    -0
      semantic/src/site/elements/icon.variables
  98. +3
    -0
      semantic/src/site/elements/image.overrides
  99. +3
    -0
      semantic/src/site/elements/image.variables
  100. +3
    -0
      semantic/src/site/elements/input.overrides

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
node_modules

+ 1
- 0
main.go View File

@@ -0,0 +1 @@
package main

+ 70
- 0
semantic.json View File

@@ -0,0 +1,70 @@
{
"base": "semantic/",
"paths": {
"source": {
"config": "src/theme.config",
"definitions": "src/definitions/",
"site": "src/site/",
"themes": "src/themes/"
},
"output": {
"packaged": "../static/",
"uncompressed": "../static/components/",
"compressed": "../static/components/",
"themes": "../static/themes/"
},
"clean": "dist/"
},
"permission": false,
"rtl": "No",
"components": [
"reset",
"site",
"button",
"container",
"divider",
"flag",
"header",
"icon",
"image",
"input",
"label",
"list",
"loader",
"rail",
"reveal",
"segment",
"step",
"breadcrumb",
"form",
"grid",
"menu",
"message",
"table",
"card",
"comment",
"feed",
"item",
"statistic",
"accordion",
"checkbox",
"dimmer",
"dropdown",
"embed",
"modal",
"nag",
"popup",
"progress",
"rating",
"search",
"sidebar",
"sticky",
"tab",
"transition",
"api",
"form",
"state",
"visibility"
],
"version": "2.1.8"
}

+ 72
- 0
semantic/gulpfile.js View File

@@ -0,0 +1,72 @@
/*******************************
Set-up
*******************************/

var
gulp = require('gulp-help')(require('gulp')),

// read user config to know what task to load
config = require('./tasks/config/user'),

// watch changes
watch = require('./tasks/watch'),

// build all files
build = require('./tasks/build'),
buildJS = require('./tasks/build/javascript'),
buildCSS = require('./tasks/build/css'),
buildAssets = require('./tasks/build/assets'),

// utility
clean = require('./tasks/clean'),
version = require('./tasks/version'),

// docs tasks
serveDocs = require('./tasks/docs/serve'),
buildDocs = require('./tasks/docs/build'),

// rtl
buildRTL = require('./tasks/rtl/build'),
watchRTL = require('./tasks/rtl/watch')
;


/*******************************
Tasks
*******************************/

gulp.task('default', false, [
'watch'
]);

gulp.task('watch', 'Watch for site/theme changes', watch);

gulp.task('build', 'Builds all files from source', build);
gulp.task('build-javascript', 'Builds all javascript from source', buildJS);
gulp.task('build-css', 'Builds all css from source', buildCSS);
gulp.task('build-assets', 'Copies all assets from source', buildAssets);

gulp.task('clean', 'Clean dist folder', clean);
gulp.task('version', 'Displays current version of Semantic', version);

/*--------------
Docs
---------------*/

/*
Lets you serve files to a local documentation instance
https://github.com/Semantic-Org/Semantic-UI-Docs/
*/

gulp.task('serve-docs', 'Serve file changes to SUI Docs', serveDocs);
gulp.task('build-docs', 'Build all files and add to SUI Docs', buildDocs);


/*--------------
RTL
---------------*/

if(config.rtl) {
gulp.task('watch-rtl', 'Build all files as RTL', watchRTL);
gulp.task('build-rtl', 'Watch files as RTL ', buildRTL);
}

+ 1142
- 0
semantic/src/definitions/behaviors/api.js View File

@@ -0,0 +1,1142 @@
/*!
* # Semantic UI - API
* http://github.com/semantic-org/semantic-ui/
*
*
* Copyright 2015 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/

;(function ( $, window, document, undefined ) {

"use strict";

$.api = $.fn.api = function(parameters) {

var
// use window context if none specified
$allModules = $.isFunction(this)
? $(window)
: $(this),
moduleSelector = $allModules.selector || '',
time = new Date().getTime(),
performance = [],

query = arguments[0],
methodInvoked = (typeof query == 'string'),
queryArguments = [].slice.call(arguments, 1),

returnedValue
;

$allModules
.each(function() {
var
settings = ( $.isPlainObject(parameters) )
? $.extend(true, {}, $.fn.api.settings, parameters)
: $.extend({}, $.fn.api.settings),

// internal aliases
namespace = settings.namespace,
metadata = settings.metadata,
selector = settings.selector,
error = settings.error,
className = settings.className,

// define namespaces for modules
eventNamespace = '.' + namespace,
moduleNamespace = 'module-' + namespace,

// element that creates request
$module = $(this),
$form = $module.closest(selector.form),

// context used for state
$context = (settings.stateContext)
? $(settings.stateContext)
: $module,

// request details
ajaxSettings,
requestSettings,
url,
data,
requestStartTime,

// standard module
element = this,
context = $context[0],
instance = $module.data(moduleNamespace),
module
;

module = {

initialize: function() {
if(!methodInvoked) {
module.bind.events();
}
module.instantiate();
},

instantiate: function() {
module.verbose('Storing instance of module', module);
instance = module;
$module
.data(moduleNamespace, instance)
;
},

destroy: function() {
module.verbose('Destroying previous module for', element);
$module
.removeData(moduleNamespace)
.off(eventNamespace)
;
},

bind: {
events: function() {
var
triggerEvent = module.get.event()
;
if( triggerEvent ) {
module.verbose('Attaching API events to element', triggerEvent);
$module
.on(triggerEvent + eventNamespace, module.event.trigger)
;
}
else if(settings.on == 'now') {
module.debug('Querying API endpoint immediately');
module.query();
}
}
},

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
response
;
if(window.Storage === undefined) {
module.error(error.noStorage);
return;
}
response = sessionStorage.getItem(url);
module.debug('Using cached response', url, response);
response = module.decode.json(response);
return false;
}
},
write: {
cachedResponse: function(url, response) {
if(response && response === '') {
module.debug('Response empty, not caching', response);
return;
}
if(window.Storage === undefined) {
module.error(error.noStorage);
return;
}
if( $.isPlainObject(response) ) {
response = JSON.stringify(response);
}
sessionStorage.setItem(url, response);
module.verbose('Storing cached response for url', url, response);
}
},

query: function() {

if(module.is.disabled()) {
module.debug('Element is disabled API request aborted');
return;
}

if(module.is.loading()) {
if(settings.interruptRequests) {
module.debug('Interrupting previous request');
module.abort();
}
else {
module.debug('Cancelling request, previous request is still pending');
return;
}
}

// pass element metadata to url (value, text)
if(settings.defaultData) {
$.extend(true, settings.urlData, module.get.defaultData());
}

// Add form content
if(settings.serializeForm) {
settings.data = module.add.formData(settings.data);
}

// call beforesend and get any settings changes
requestSettings = module.get.settings();

// check if before send cancelled request
if(requestSettings === false) {
module.cancelled = true;
module.error(error.beforeSend);
return;
}
else {
module.cancelled = false;
}

// get url
url = module.get.templatedURL();

if(!url && !module.is.mocked()) {
module.error(error.missingURL);
return;
}

// replace variables
url = module.add.urlData( url );
// missing url parameters
if( !url && !module.is.mocked()) {
return;
}

requestSettings.url = settings.base + url;

// look for jQuery ajax parameters in settings
ajaxSettings = $.extend(true, {}, settings, {
type : settings.method || settings.type,
data : data,
url : settings.base + url,
beforeSend : settings.beforeXHR,
success : function() {},
failure : function() {},
complete : function() {}
});

module.debug('Querying URL', ajaxSettings.url);
module.verbose('Using AJAX settings', ajaxSettings);

if(settings.cache === 'local' && module.read.cachedResponse(url)) {
module.debug('Response returned from local cache');
module.request = module.create.request();
module.request.resolveWith(context, [ module.read.cachedResponse(url) ]);
return;
}

if( !settings.throttle ) {
module.debug('Sending request', data, ajaxSettings.method);
module.send.request();
}
else {
if(!settings.throttleFirstRequest && !module.timer) {
module.debug('Sending request', data, ajaxSettings.method);
module.send.request();
module.timer = setTimeout(function(){}, settings.throttle);
}
else {
module.debug('Throttling request', settings.throttle);
clearTimeout(module.timer);
module.timer = setTimeout(function() {
if(module.timer) {
delete module.timer;
}
module.debug('Sending throttled request', data, ajaxSettings.method);
module.send.request();
}, settings.throttle);
}
}

},

should: {
removeError: function() {
return ( settings.hideError === true || (settings.hideError === 'auto' && !module.is.form()) );
}
},

is: {
disabled: function() {
return ($module.filter(selector.disabled).length > 0);
},
form: function() {
return $module.is('form') || $context.is('form');
},
mocked: function() {
return (settings.mockResponse || settings.mockResponseAsync || settings.response || settings.responseAsync);
},
input: function() {
return $module.is('input');
},
loading: function() {
return (module.request && module.request.state() == 'pending');
},
abortedRequest: function(xhr) {
if(xhr && xhr.readyState !== undefined && xhr.readyState === 0) {
module.verbose('XHR request determined to be aborted');
return true;
}
else {
module.verbose('XHR request was not aborted');
return false;
}
},
validResponse: function(response) {
if( (settings.dataType !== 'json' && settings.dataType !== 'jsonp') || !$.isFunction(settings.successTest) ) {
module.verbose('Response is not JSON, skipping validation', settings.successTest, response);
return true;
}
module.debug('Checking JSON returned success', settings.successTest, response);
if( settings.successTest(response) ) {
module.debug('Response passed success test', response);
return true;
}
else {
module.debug('Response failed success test', response);
return false;
}
}
},

was: {
cancelled: function() {
return (module.cancelled || false);
},
succesful: function() {
return (module.request && module.request.state() == 'resolved');
},
failure: function() {
return (module.request && module.request.state() == 'rejected');
},
complete: function() {
return (module.request && (module.request.state() == 'resolved' || module.request.state() == 'rejected') );
}
},

add: {
urlData: function(url, urlData) {
var
requiredVariables,
optionalVariables
;
if(url) {
requiredVariables = url.match(settings.regExp.required);
optionalVariables = url.match(settings.regExp.optional);
urlData = urlData || settings.urlData;
if(requiredVariables) {
module.debug('Looking for required URL variables', requiredVariables);
$.each(requiredVariables, function(index, templatedString) {
var
// allow legacy {$var} style
variable = (templatedString.indexOf('$') !== -1)
? templatedString.substr(2, templatedString.length - 3)
: templatedString.substr(1, templatedString.length - 2),
value = ($.isPlainObject(urlData) && urlData[variable] !== undefined)
? urlData[variable]
: ($module.data(variable) !== undefined)
? $module.data(variable)
: ($context.data(variable) !== undefined)
? $context.data(variable)
: urlData[variable]
;
// remove value
if(value === undefined) {
module.error(error.requiredParameter, variable, url);
url = false;
return false;
}
else {
module.verbose('Found required variable', variable, value);
value = (settings.encodeParameters)
? module.get.urlEncodedValue(value)
: value
;
url = url.replace(templatedString, value);
}
});
}
if(optionalVariables) {
module.debug('Looking for optional URL variables', requiredVariables);
$.each(optionalVariables, function(index, templatedString) {
var
// allow legacy {/$var} style
variable = (templatedString.indexOf('$') !== -1)
? templatedString.substr(3, templatedString.length - 4)
: templatedString.substr(2, templatedString.length - 3),
value = ($.isPlainObject(urlData) && urlData[variable] !== undefined)
? urlData[variable]
: ($module.data(variable) !== undefined)
? $module.data(variable)
: ($context.data(variable) !== undefined)
? $context.data(variable)
: urlData[variable]
;
// optional replacement
if(value !== undefined) {
module.verbose('Optional variable Found', variable, value);
url = url.replace(templatedString, value);
}
else {
module.verbose('Optional variable not found', variable);
// remove preceding slash if set
if(url.indexOf('/' + templatedString) !== -1) {
url = url.replace('/' + templatedString, '');
}
else {
url = url.replace(templatedString, '');
}
}
});
}
}
return url;
},
formData: function(data) {
var
canSerialize = ($.fn.serializeObject !== undefined),
formData = (canSerialize)
? $form.serializeObject()
: $form.serialize(),
hasOtherData
;
data = data || settings.data;
hasOtherData = $.isPlainObject(data);

if(hasOtherData) {
if(canSerialize) {
module.debug('Extending existing data with form data', data, formData);
data = $.extend(true, {}, data, formData);
}
else {
module.error(error.missingSerialize);
module.debug('Cant extend data. Replacing data with form data', data, formData);
data = formData;
}
}
else {
module.debug('Adding form data', formData);
data = formData;
}
return data;
}
},

send: {
request: function() {
module.set.loading();
module.request = module.create.request();
if( module.is.mocked() ) {
module.mockedXHR = module.create.mockedXHR();
}
else {
module.xhr = module.create.xhr();
}
settings.onRequest.call(context, module.request, module.xhr);
}
},

event: {
trigger: function(event) {
module.query();
if(event.type == 'submit' || event.type == 'click') {
event.preventDefault();
}
},
xhr: {
always: function() {
// nothing special
},
done: function(response, textStatus, xhr) {
var
context = this,
elapsedTime = (new Date().getTime() - requestStartTime),
timeLeft = (settings.loadingDuration - elapsedTime),
translatedResponse = ( $.isFunction(settings.onResponse) )
? settings.onResponse.call(context, $.extend(true, {}, response))
: false
;
timeLeft = (timeLeft > 0)
? timeLeft
: 0
;
if(translatedResponse) {
module.debug('Modified API response in onResponse callback', settings.onResponse, translatedResponse, response);
response = translatedResponse;
}
if(timeLeft > 0) {
module.debug('Response completed early delaying state change by', timeLeft);
}
setTimeout(function() {
if( module.is.validResponse(response) ) {
module.request.resolveWith(context, [response, xhr]);
}
else {
module.request.rejectWith(context, [xhr, 'invalid']);
}
}, timeLeft);
},
fail: function(xhr, status, httpMessage) {
var
context = this,
elapsedTime = (new Date().getTime() - requestStartTime),
timeLeft = (settings.loadingDuration - elapsedTime)
;
timeLeft = (timeLeft > 0)
? timeLeft
: 0
;
if(timeLeft > 0) {
module.debug('Response completed early delaying state change by', timeLeft);
}
setTimeout(function() {
if( module.is.abortedRequest(xhr) ) {
module.request.rejectWith(context, [xhr, 'aborted', httpMessage]);
}
else {
module.request.rejectWith(context, [xhr, 'error', status, httpMessage]);
}
}, timeLeft);
}
},
request: {
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, 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 = 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, 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, xhr);
}
}

if(settings.errorDuration && status !== 'aborted') {
module.debug('Adding error state');
module.set.error();
if( module.should.removeError() ) {
setTimeout(module.remove.error, settings.errorDuration);
}
}
module.debug('API Request failed', errorMessage, xhr);
settings.onFailure.call(context, response, $module, xhr);
}
}
},

create: {

request: function() {
// api request promise
return $.Deferred()
.always(module.event.request.complete)
.done(module.event.request.done)
.fail(module.event.request.fail)
;
},

mockedXHR: function () {
var
// xhr does not simulate these properties of xhr but must return them
textStatus = false,
status = false,
httpMessage = false,
responder = settings.mockResponse || settings.response,
asyncResponder = settings.mockResponseAsync || settings.responseAsync,
asyncCallback,
response,
mockedXHR
;

mockedXHR = $.Deferred()
.always(module.event.xhr.complete)
.done(module.event.xhr.done)
.fail(module.event.xhr.fail)
;

if(responder) {
if( $.isFunction(responder) ) {
module.debug('Using specified synchronous callback', responder);
response = responder.call(context, requestSettings);
}
else {
module.debug('Using settings specified response', responder);
response = responder;
}
// simulating response
mockedXHR.resolveWith(context, [ response, textStatus, { responseText: response }]);
}
else if( $.isFunction(asyncResponder) ) {
asyncCallback = function(response) {
module.debug('Async callback returned response', response);

if(response) {
mockedXHR.resolveWith(context, [ response, textStatus, { responseText: response }]);
}
else {
mockedXHR.rejectWith(context, [{ responseText: response }, status, httpMessage]);
}
};
module.debug('Using specified async response callback', asyncResponder);
asyncResponder.call(context, requestSettings, asyncCallback);
}
return mockedXHR;
},

xhr: function() {
var
xhr
;
// ajax request promise
xhr = $.ajax(ajaxSettings)
.always(module.event.xhr.always)
.done(module.event.xhr.done)
.fail(module.event.xhr.fail)
;
module.verbose('Created server request', xhr);
return xhr;
}
},

set: {
error: function() {
module.verbose('Adding error state to element', $context);
$context.addClass(className.error);
},
loading: function() {
module.verbose('Adding loading state to element', $context);
$context.addClass(className.loading);
requestStartTime = new Date().getTime();
}
},

remove: {
error: function() {
module.verbose('Removing error state from element', $context);
$context.removeClass(className.error);
},
loading: function() {
module.verbose('Removing loading state from element', $context);
$context.removeClass(className.loading);
}
},

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;
},
xhr: function() {
return module.xhr || false;
},
settings: function() {
var
runSettings
;
runSettings = settings.beforeSend.call(context, settings);
if(runSettings) {
if(runSettings.success !== undefined) {
module.debug('Legacy success callback detected', runSettings);
module.error(error.legacyParameters, runSettings.success);
runSettings.onSuccess = runSettings.success;
}
if(runSettings.failure !== undefined) {
module.debug('Legacy failure callback detected', runSettings);
module.error(error.legacyParameters, runSettings.failure);
runSettings.onFailure = runSettings.failure;
}
if(runSettings.complete !== undefined) {
module.debug('Legacy complete callback detected', runSettings);
module.error(error.legacyParameters, runSettings.complete);
runSettings.onComplete = runSettings.complete;
}
}
if(runSettings === undefined) {
module.error(error.noReturnedValue);
}
return (runSettings !== undefined)
? $.extend(true, {}, runSettings)
: $.extend(true, {}, 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 using encodeURIComponent', value, encodedValue);
return encodedValue;
},
defaultData: function() {
var
data = {}
;
if( !$.isWindow(element) ) {
if( module.is.input() ) {
data.value = $module.val();
}
else if( !module.is.form() ) {

}
else {
data.text = $module.text();
}
}
return data;
},
event: function() {
if( $.isWindow(element) || settings.on == 'now' ) {
module.debug('API called without element, no events attached');
return false;
}
else if(settings.on == 'auto') {
if( $module.is('input') ) {
return (element.oninput !== undefined)
? 'input'
: (element.onpropertychange !== undefined)
? 'propertychange'
: 'keyup'
;
}
else if( $module.is('form') ) {
return 'submit';
}
else {
return 'click';
}
}
else {
return settings.on;
}
},
templatedURL: function(action) {
action = action || $module.data(metadata.action) || settings.action || false;
url = $module.data(metadata.url) || settings.url || false;
if(url) {
module.debug('Using specified url', url);
return url;
}
if(action) {
module.debug('Looking up url for action', action, settings.api);
if(settings.api[action] === undefined && !module.is.mocked()) {
module.error(error.missingAction, settings.action, settings.api);
return;
}
url = settings.api[action];
}
else if( module.is.form() ) {
url = $module.attr('action') || $context.attr('action') || false;
module.debug('No url or action specified, defaulting to form action', url);
}
return url;
}
},

abort: function() {
var
xhr = module.get.xhr()
;
if( xhr && xhr.state() !== 'resolved') {
module.debug('Cancelling API request');
xhr.abort();
}
},

// reset state
reset: function() {
module.remove.error();
module.remove.loading();
},

setting: function(name, value) {
module.debug('Changing setting', name, value);
if( $.isPlainObject(name) ) {
$.extend(true, settings, name);
}
else if(value !== undefined) {
settings[name] = value;
}
else {
return settings[name];
}
},
internal: function(name, value) {
if( $.isPlainObject(name) ) {
$.extend(true, module, name);
}
else if(value !== undefined) {
module[name] = value;
}
else {
return module[name];
}
},
debug: function() {
if(settings.debug) {
if(settings.performance) {
module.performance.log(arguments);
}
else {
module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
module.debug.apply(console, arguments);
}
}
},
verbose: function() {
if(settings.verbose && settings.debug) {
if(settings.performance) {
module.performance.log(arguments);
}
else {
module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
module.verbose.apply(console, arguments);
}
}
},
error: function() {
module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
module.error.apply(console, arguments);
},
performance: {
log: function(message) {
var
currentTime,
executionTime,
previousTime
;
if(settings.performance) {
currentTime = new Date().getTime();
previousTime = time || currentTime;
executionTime = currentTime - previousTime;
time = currentTime;
performance.push({
'Name' : message[0],
'Arguments' : [].slice.call(message, 1) || '',
//'Element' : element,
'Execution Time' : executionTime
});
}
clearTimeout(module.performance.timer);
module.performance.timer = setTimeout(module.performance.display, 500);
},
display: function() {
var
title = settings.name + ':',
totalTime = 0
;
time = false;
clearTimeout(module.performance.timer);
$.each(performance, function(index, data) {
totalTime += data['Execution Time'];
});
title += ' ' + totalTime + 'ms';
if(moduleSelector) {
title += ' \'' + moduleSelector + '\'';
}
if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
console.groupCollapsed(title);
if(console.table) {
console.table(performance);
}
else {
$.each(performance, function(index, data) {
console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
});
}
console.groupEnd();
}
performance = [];
}
},
invoke: function(query, passedArguments, context) {
var
object = instance,
maxDepth,
found,
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
$.each(query, function(depth, value) {
var camelCaseValue = (depth != maxDepth)
? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
: query
;
if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
object = object[camelCaseValue];
}
else if( object[camelCaseValue] !== undefined ) {
found = object[camelCaseValue];
return false;
}
else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
object = object[value];
}
else if( object[value] !== undefined ) {
found = object[value];
return false;
}
else {
module.error(error.method, query);
return false;
}
});
}
if ( $.isFunction( found ) ) {
response = found.apply(context, passedArguments);
}
else if(found !== undefined) {
response = found;
}
if($.isArray(returnedValue)) {
returnedValue.push(response);
}
else if(returnedValue !== undefined) {
returnedValue = [returnedValue, response];
}
else if(response !== undefined) {
returnedValue = response;
}
return found;
}
};

if(methodInvoked) {
if(instance === undefined) {
module.initialize();
}
module.invoke(query);
}
else {
if(instance !== undefined) {
instance.invoke('destroy');
}
module.initialize();
}
})
;

return (returnedValue !== undefined)
? returnedValue
: this
;
};

$.api.settings = {

name : 'API',
namespace : 'api',

debug : false,
verbose : false,
performance : true,

// object containing all templates endpoints
api : {},

// whether to cache responses
cache : true,

// whether new requests should abort previous requests
interruptRequests : true,

// event binding
on : 'auto',

// context for applying state classes
stateContext : false,

// duration for loading state
loadingDuration : 0,

// whether to hide errors after a period of time
hideError : 'auto',

// duration for error state
errorDuration : 2000,

// whether parameters should be encoded with encodeURIComponent
encodeParameters : true,

// API action to use
action : false,

// templated URL to use
url : false,

// base URL to apply to all endpoints
base : '',

// data that will
urlData : {},

// whether to add default data to url data
defaultData : true,

// whether to serialize closest form
serializeForm : false,

// how long to wait before request should occur
throttle : 0,

// whether to throttle first request or only repeated
throttleFirstRequest : true,

// standard ajax settings
method : 'get',
data : {},
dataType : 'json',

// mock response
mockResponse : false,
mockResponseAsync : false,

// aliases for mock
response : false,
responseAsync : false,

// callbacks before request
beforeSend : function(settings) { return settings; },
beforeXHR : function(xhr) {},
onRequest : function(promise, xhr) {},

// after request
onResponse : false, // function(response) { },

// response was successful, if JSON passed validation
onSuccess : function(response, $module) {},

// request finished without aborting
onComplete : function(response, $module) {},

// failed JSON success test
onFailure : function(response, $module) {},

// server error
onError : function(errorMessage, $module) {},

// request aborted
onAbort : function(errorMessage, $module) {},

successTest : false,

// errors
error : {
beforeSend : 'The before send function has aborted the request',
error : 'There was an error with your request',
exitConditions : 'API Request Aborted. Exit conditions met',
JSONParse : 'JSON could not be parsed during error handling',
legacyParameters : 'You are using legacy API success callback names',
method : 'The method you called is not defined',
missingAction : 'API action used but no url was defined',
missingSerialize : 'jquery-serialize-object is required to add form data to an existing data object',
missingURL : 'No URL specified for api event',
noReturnedValue : 'The beforeSend callback must return a settings object, beforeSend ignored.',
noStorage : 'Caching responses locally requires session storage',
parseError : 'There was an error parsing your request',
requiredParameter : 'Missing a required URL parameter: ',
statusMessage : 'Server gave an error: ',
timeout : 'Your request timed out'
},

regExp : {
required : /\{\$*[A-z0-9]+\}/g,
optional : /\{\/\$*[A-z0-9]+\}/g,
},

className: {
loading : 'loading',
error : 'error'
},

selector: {
disabled : '.disabled',
form : 'form'
},

metadata: {
action : 'action',
url : 'url'
}
};



})( jQuery, window, document );

+ 274
- 0
semantic/src/definitions/behaviors/colorize.js View File

@@ -0,0 +1,274 @@
/*!
* # Semantic UI - Colorize
* http://github.com/semantic-org/semantic-ui/
*
*
* Copyright 2015 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/

;(function ( $, window, document, undefined ) {

"use strict";

$.fn.colorize = function(parameters) {
var
settings = ( $.isPlainObject(parameters) )
? $.extend(true, {}, $.fn.colorize.settings, parameters)
: $.extend({}, $.fn.colorize.settings),
// hoist arguments
moduleArguments = arguments || false
;
$(this)
.each(function(instanceIndex) {

var
$module = $(this),

mainCanvas = $('<canvas />')[0],
imageCanvas = $('<canvas />')[0],
overlayCanvas = $('<canvas />')[0],

backgroundImage = new Image(),

// defs
mainContext,
imageContext,
overlayContext,

image,
imageName,

width,
height,

// shortucts
colors = settings.colors,
paths = settings.paths,
namespace = settings.namespace,
error = settings.error,

// boilerplate
instance = $module.data('module-' + namespace),
module
;

module = {

checkPreconditions: function() {
module.debug('Checking pre-conditions');

if( !$.isPlainObject(colors) || $.isEmptyObject(colors) ) {
module.error(error.undefinedColors);
return false;
}
return true;
},

async: function(callback) {
if(settings.async) {
setTimeout(callback, 0);
}
else {
callback();
}
},

getMetadata: function() {
module.debug('Grabbing metadata');
image = $module.data('image') || settings.image || undefined;
imageName = $module.data('name') || settings.name || instanceIndex;
width = settings.width || $module.width();
height = settings.height || $module.height();
if(width === 0 || height === 0) {
module.error(error.undefinedSize);
}
},

initialize: function() {
module.debug('Initializing with colors', colors);
if( module.checkPreconditions() ) {

module.async(function() {
module.getMetadata();
module.canvas.create();

module.draw.image(function() {
module.draw.colors();
module.canvas.merge();
});
$module
.data('module-' + namespace, module)
;
});
}
},

redraw: function() {
module.debug('Redrawing image');
module.async(function() {
module.canvas.clear();
module.draw.colors();
module.canvas.merge();
});
},

change: {
color: function(colorName, color) {
module.debug('Changing color', colorName);
if(colors[colorName] === undefined) {
module.error(error.missingColor);
return false;
}
colors[colorName] = color;
module.redraw();
}
},

canvas: {
create: function() {
module.debug('Creating canvases');

mainCanvas.width = width;
mainCanvas.height = height;
imageCanvas.width = width;
imageCanvas.height = height;
overlayCanvas.width = width;
overlayCanvas.height = height;

mainContext = mainCanvas.getContext('2d');
imageContext = imageCanvas.getContext('2d');
overlayContext = overlayCanvas.getContext('2d');

$module
.append( mainCanvas )
;
mainContext = $module.children('canvas')[0].getContext('2d');
},
clear: function(context) {
module.debug('Clearing canvas');
overlayContext.fillStyle = '#FFFFFF';
overlayContext.fillRect(0, 0, width, height);
},
merge: function() {
if( !$.isFunction(mainContext.blendOnto) ) {
module.error(error.missingPlugin);
return;
}
mainContext.putImageData( imageContext.getImageData(0, 0, width, height), 0, 0);
overlayContext.blendOnto(mainContext, 'multiply');
}
},

draw: {

image: function(callback) {
module.debug('Drawing image');
callback = callback || function(){};
if(image) {
backgroundImage.src = image;
backgroundImage.onload = function() {
imageContext.drawImage(backgroundImage, 0, 0);
callback();
};
}
else {
module.error(error.noImage);
callback();
}
},

colors: function() {
module.debug('Drawing color overlays', colors);
$.each(colors, function(colorName, color) {
settings.onDraw(overlayContext, imageName, colorName, color);
});
}

},

debug: function(message, variableName) {
if(settings.debug) {
if(variableName !== undefined) {
console.info(settings.name + ': ' + message, variableName);
}
else {
console.info(settings.name + ': ' + message);
}
}
},
error: function(errorMessage) {
console.warn(settings.name + ': ' + errorMessage);
},
invoke: function(methodName, context, methodArguments) {
var
method
;
methodArguments = methodArguments || Array.prototype.slice.call( arguments, 2 );

if(typeof methodName == 'string' && instance !== undefined) {
methodName = methodName.split('.');
$.each(methodName, function(index, name) {
if( $.isPlainObject( instance[name] ) ) {
instance = instance[name];
return true;
}
else if( $.isFunction( instance[name] ) ) {
method = instance[name];
return true;
}
module.error(settings.error.method);
return false;
});
}
return ( $.isFunction( method ) )
? method.apply(context, methodArguments)
: false
;
}

};
if(instance !== undefined && moduleArguments) {
// simpler than invoke realizing to invoke itself (and losing scope due prototype.call()
if(moduleArguments[0] == 'invoke') {
moduleArguments = Array.prototype.slice.call( moduleArguments, 1 );
}
return module.invoke(moduleArguments[0], this, Array.prototype.slice.call( moduleArguments, 1 ) );
}
// initializing
module.initialize();
})
;
return this;
};

$.fn.colorize.settings = {
name : 'Image Colorizer',
debug : true,
namespace : 'colorize',

onDraw : function(overlayContext, imageName, colorName, color) {},

// whether to block execution while updating canvas
async : true,
// object containing names and default values of color regions
colors : {},

metadata: {
image : 'image',
name : 'name'
},

error: {
noImage : 'No tracing image specified',
undefinedColors : 'No default colors specified.',
missingColor : 'Attempted to change color that does not exist',
missingPlugin : 'Blend onto plug-in must be included',
undefinedHeight : 'The width or height of image canvas could not be automatically determined. Please specify a height.'
}

};

})( jQuery, window, document );

+ 1517
- 0
semantic/src/definitions/behaviors/form.js View File

@@ -0,0 +1,1517 @@
/*!
* # Semantic UI - Form Validation
* http://github.com/semantic-org/semantic-ui/
*
*
* Copyright 2015 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/

;(function ( $, window, document, undefined ) {

"use strict";

$.fn.form = function(parameters) {
var
$allModules = $(this),
moduleSelector = $allModules.selector || '',

time = new Date().getTime(),
performance = [],

query = arguments[0],
legacyParameters = arguments[1],
methodInvoked = (typeof query == 'string'),
queryArguments = [].slice.call(arguments, 1),
returnedValue
;
$allModules
.each(function() {
var
$module = $(this),
element = this,

formErrors = [],
keyHeldDown = false,

// set at run-time
$field,
$group,
$message,
$prompt,
$submit,
$clear,
$reset,

settings,
validation,

metadata,
selector,
className,
error,

namespace,
moduleNamespace,
eventNamespace,

instance,
module
;

module = {

initialize: function() {

// settings grabbed at run time
module.get.settings();
if(methodInvoked) {
if(instance === undefined) {
module.instantiate();
}
module.invoke(query);
}
else {
module.verbose('Initializing form validation', $module, settings);
module.bindEvents();
module.set.defaults();
module.instantiate();
}
},

instantiate: function() {
module.verbose('Storing instance of module', module);
instance = module;
$module
.data(moduleNamespace, module)
;
},

destroy: function() {
module.verbose('Destroying previous module', instance);
module.removeEvents();
$module
.removeData(moduleNamespace)
;
},

refresh: function() {
module.verbose('Refreshing selector cache');
$field = $module.find(selector.field);
$group = $module.find(selector.group);
$message = $module.find(selector.message);
$prompt = $module.find(selector.prompt);

$submit = $module.find(selector.submit);
$clear = $module.find(selector.clear);
$reset = $module.find(selector.reset);
},

submit: function() {
module.verbose('Submitting form', $module);
$module
.submit()
;
},

attachEvents: function(selector, action) {
action = action || 'submit';
$(selector)
.on('click' + eventNamespace, function(event) {
module[action]();
event.preventDefault();
})
;
},

bindEvents: function() {
module.verbose('Attaching form events');
$module
.on('submit' + eventNamespace, module.validate.form)
.on('blur' + eventNamespace, selector.field, module.event.field.blur)
.on('click' + eventNamespace, selector.submit, module.submit)
.on('click' + eventNamespace, selector.reset, module.reset)
.on('click' + eventNamespace, selector.clear, module.clear)
;
if(settings.keyboardShortcuts) {
$module
.on('keydown' + eventNamespace, selector.field, module.event.field.keydown)
;
}
$field
.each(function() {
var
$input = $(this),
type = $input.prop('type'),
inputEvent = module.get.changeEvent(type, $input)
;
$(this)
.on(inputEvent + eventNamespace, module.event.field.change)
;
})
;
},

clear: function() {
$field
.each(function () {
var
$field = $(this),
$element = $field.parent(),
$fieldGroup = $field.closest($group),
$prompt = $fieldGroup.find(selector.prompt),
defaultValue = $field.data(metadata.defaultValue) || '',
isCheckbox = $element.is(selector.uiCheckbox),
isDropdown = $element.is(selector.uiDropdown),
isErrored = $fieldGroup.hasClass(className.error)
;
if(isErrored) {
module.verbose('Resetting error on field', $fieldGroup);
$fieldGroup.removeClass(className.error);
$prompt.remove();
}
if(isDropdown) {
module.verbose('Resetting dropdown value', $element, defaultValue);
$element.dropdown('clear');
}
else if(isCheckbox) {
$field.prop('checked', false);
}
else {
module.verbose('Resetting field value', $field, defaultValue);
$field.val('');
}
})
;
},

reset: function() {
$field
.each(function () {
var
$field = $(this),
$element = $field.parent(),
$fieldGroup = $field.closest($group),
$prompt = $fieldGroup.find(selector.prompt),
defaultValue = $field.data(metadata.defaultValue),
isCheckbox = $element.is(selector.uiCheckbox),
isDropdown = $element.is(selector.uiDropdown),
isErrored = $fieldGroup.hasClass(className.error)
;
if(defaultValue === undefined) {
return;
}
if(isErrored) {
module.verbose('Resetting error on field', $fieldGroup);
$fieldGroup.removeClass(className.error);
$prompt.remove();
}
if(isDropdown) {
module.verbose('Resetting dropdown value', $element, defaultValue);
$element.dropdown('restore defaults');
}
else if(isCheckbox) {
module.verbose('Resetting checkbox value', $element, defaultValue);
$field.prop('checked', defaultValue);
}
else {
module.verbose('Resetting field value', $field, defaultValue);
$field.val(defaultValue);
}
})
;
},

is: {
bracketedRule: function(rule) {
return (rule.type && rule.type.match(settings.regExp.bracket));
},
valid: function() {
var
allValid = true
;
module.verbose('Checking if form is valid');
$.each(validation, function(fieldName, field) {
if( !( module.validate.field(field, fieldName) ) ) {
allValid = false;
}
});
return allValid;
}
},

removeEvents: function() {
$module
.off(eventNamespace)
;
$field
.off(eventNamespace)
;
$submit
.off(eventNamespace)
;
$field
.off(eventNamespace)
;
},

event: {
field: {
keydown: function(event) {
var
$field = $(this),
key = event.which,
keyCode = {
enter : 13,
escape : 27
}
;
if( key == keyCode.escape) {
module.verbose('Escape key pressed blurring field');
$field
.blur()
;
}
if(!event.ctrlKey && key == keyCode.enter && $field.is(selector.input) && $field.not(selector.checkbox).length > 0 ) {
if(!keyHeldDown) {
$field
.one('keyup' + eventNamespace, module.event.field.keyup)
;
module.submit();
module.debug('Enter pressed on input submitting form');
}
keyHeldDown = true;
}
},
keyup: function() {
keyHeldDown = false;
},
blur: function(event) {
var
$field = $(this),
$fieldGroup = $field.closest($group),
validationRules = module.get.validation($field)
;
if( $fieldGroup.hasClass(className.error) ) {
module.debug('Revalidating field', $field, validationRules);
module.validate.form.call(module, event, true);
}
else if(settings.on == 'blur' || settings.on == 'change') {
if(validationRules) {
module.validate.field( validationRules );
}
}
},
change: function(event) {
var
$field = $(this),
$fieldGroup = $field.closest($group)
;
if(settings.on == 'change' || ( $fieldGroup.hasClass(className.error) && settings.revalidate) ) {
clearTimeout(module.timer);
module.timer = setTimeout(function() {
module.debug('Revalidating field', $field, module.get.validation($field));
module.validate.form.call(module, event, true);
}, settings.delay);
}
}
}

},

get: {
ancillaryValue: function(rule) {
if(!rule.type || !module.is.bracketedRule(rule)) {
return false;
}
return rule.type.match(settings.regExp.bracket)[1] + '';
},
ruleName: function(rule) {
if( module.is.bracketedRule(rule) ) {
return rule.type.replace(rule.type.match(settings.regExp.bracket)[0], '');
}
return rule.type;
},
changeEvent: function(type, $input) {
if(type == 'checkbox' || type == 'radio' || type == 'hidden' || $input.is('select')) {
return 'change';
}
else {
return module.get.inputEvent();
}
},
inputEvent: function() {
return (document.createElement('input').oninput !== undefined)
? 'input'
: (document.createElement('input').onpropertychange !== undefined)
? 'propertychange'
: 'keyup'
;
},
prompt: function(rule, field) {
var
ruleName = module.get.ruleName(rule),
ancillary = module.get.ancillaryValue(rule),
prompt = rule.prompt || settings.prompt[ruleName] || settings.text.unspecifiedRule,
requiresValue = (prompt.search('{value}') !== -1),
requiresName = (prompt.search('{name}') !== -1),
$label,
$field,
name
;
if(requiresName || requiresValue) {
$field = module.get.field(field.identifier);
}
if(requiresValue) {
prompt = prompt.replace('{value}', $field.val());
}
if(requiresName) {
$label = $field.closest(selector.group).find('label').eq(0);
name = ($label.size() == 1)
? $label.text()
: $field.prop('placeholder') || settings.text.unspecifiedField
;
prompt = prompt.replace('{name}', name);
}
prompt = prompt.replace('{identifier}', field.identifier);
prompt = prompt.replace('{ruleValue}', ancillary);
if(!rule.prompt) {
module.verbose('Using default validation prompt for type', prompt, ruleName);
}
return prompt;
},
settings: function() {
if($.isPlainObject(parameters)) {
var
keys = Object.keys(parameters),
isLegacySettings = (keys.length > 0)
? (parameters[keys[0]].identifier !== undefined && parameters[keys[0]].rules !== undefined)
: false,
ruleKeys
;
if(isLegacySettings) {
// 1.x (ducktyped)
settings = $.extend(true, {}, $.fn.form.settings, legacyParameters);
validation = $.extend({}, $.fn.form.settings.defaults, parameters);
module.error(settings.error.oldSyntax, element);
module.verbose('Extending settings from legacy parameters', validation, settings);
}
else {
// 2.x
if(parameters.fields) {
ruleKeys = Object.keys(parameters.fields);
if( typeof parameters.fields[ruleKeys[0]] == 'string' || $.isArray(parameters.fields[ruleKeys[0]]) ) {
$.each(parameters.fields, function(name, rules) {
if(typeof rules == 'string') {
rules = [rules];
}
parameters.fields[name] = {
rules: []
};
$.each(rules, function(index, rule) {
parameters.fields[name].rules.push({ type: rule });
});
});
}
}

settings = $.extend(true, {}, $.fn.form.settings, parameters);
validation = $.extend({}, $.fn.form.settings.defaults, settings.fields);
module.verbose('Extending settings', validation, settings);
}
}
else {
settings = $.fn.form.settings;
validation = $.fn.form.settings.defaults;
module.verbose('Using default form validation', validation, settings);
}

// shorthand
namespace = settings.namespace;
metadata = settings.metadata;
selector = settings.selector;
className = settings.className;
error = settings.error;
moduleNamespace = 'module-' + namespace;
eventNamespace = '.' + namespace;

// grab instance
instance = $module.data(moduleNamespace);

// refresh selector cache
module.refresh();
},
field: function(identifier) {
module.verbose('Finding field with identifier', identifier);
if( $field.filter('#' + identifier).length > 0 ) {
return $field.filter('#' + identifier);
}
else if( $field.filter('[name="' + identifier +'"]').length > 0 ) {
return $field.filter('[name="' + identifier +'"]');
}
else if( $field.filter('[name="' + identifier +'[]"]').length > 0 ) {
return $field.filter('[name="' + identifier +'[]"]');
}
else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').length > 0 ) {
return $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]');
}
return $('<input/>');
},
fields: function(fields) {
var