9 changed files with 0 additions and 3035 deletions
Split View
Diff Options
-
274dist/components/colorize.js
-
11dist/components/colorize.min.js
-
708dist/components/state.js
-
1dist/components/state.min.js
-
517dist/components/visit.js
-
11dist/components/visit.min.js
-
280src/definitions/behaviors/colorize.js
-
708src/definitions/behaviors/state.js
-
525src/definitions/behaviors/visit.js
@ -1,274 +0,0 @@ |
|||
/*! |
|||
* # Semantic UI 2.0.0 - 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, |
|||
|
|||
// shortcuts
|
|||
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 ); |
@ -1,11 +0,0 @@ |
|||
/*! |
|||
* # Semantic UI 2.0.0 - Colorize |
|||
* http://github.com/semantic-org/semantic-ui/
|
|||
* |
|||
* |
|||
* Copyright 2015 Contributors |
|||
* Released under the MIT license |
|||
* http://opensource.org/licenses/MIT
|
|||
* |
|||
*/ |
|||
!function(e,n,i,t){"use strict";e.fn.colorize=function(n){var i=e.isPlainObject(n)?e.extend(!0,{},e.fn.colorize.settings,n):e.extend({},e.fn.colorize.settings),o=arguments||!1;return e(this).each(function(n){var a,r,c,s,d,g,u,l,m=e(this),f=e("<canvas />")[0],h=e("<canvas />")[0],p=e("<canvas />")[0],v=new Image,w=i.colors,b=(i.paths,i.namespace),y=i.error,C=m.data("module-"+b);return l={checkPreconditions:function(){return l.debug("Checking pre-conditions"),!e.isPlainObject(w)||e.isEmptyObject(w)?(l.error(y.undefinedColors),!1):!0},async:function(e){i.async?setTimeout(e,0):e()},getMetadata:function(){l.debug("Grabbing metadata"),s=m.data("image")||i.image||t,d=m.data("name")||i.name||n,g=i.width||m.width(),u=i.height||m.height(),(0===g||0===u)&&l.error(y.undefinedSize)},initialize:function(){l.debug("Initializing with colors",w),l.checkPreconditions()&&l.async(function(){l.getMetadata(),l.canvas.create(),l.draw.image(function(){l.draw.colors(),l.canvas.merge()}),m.data("module-"+b,l)})},redraw:function(){l.debug("Redrawing image"),l.async(function(){l.canvas.clear(),l.draw.colors(),l.canvas.merge()})},change:{color:function(e,n){return l.debug("Changing color",e),w[e]===t?(l.error(y.missingColor),!1):(w[e]=n,void l.redraw())}},canvas:{create:function(){l.debug("Creating canvases"),f.width=g,f.height=u,h.width=g,h.height=u,p.width=g,p.height=u,a=f.getContext("2d"),r=h.getContext("2d"),c=p.getContext("2d"),m.append(f),a=m.children("canvas")[0].getContext("2d")},clear:function(e){l.debug("Clearing canvas"),c.fillStyle="#FFFFFF",c.fillRect(0,0,g,u)},merge:function(){return e.isFunction(a.blendOnto)?(a.putImageData(r.getImageData(0,0,g,u),0,0),void c.blendOnto(a,"multiply")):void l.error(y.missingPlugin)}},draw:{image:function(e){l.debug("Drawing image"),e=e||function(){},s?(v.src=s,v.onload=function(){r.drawImage(v,0,0),e()}):(l.error(y.noImage),e())},colors:function(){l.debug("Drawing color overlays",w),e.each(w,function(e,n){i.onDraw(c,d,e,n)})}},debug:function(e,n){i.debug&&(n!==t?console.info(i.name+": "+e,n):console.info(i.name+": "+e))},error:function(e){console.warn(i.name+": "+e)},invoke:function(n,o,a){var r;return a=a||Array.prototype.slice.call(arguments,2),"string"==typeof n&&C!==t&&(n=n.split("."),e.each(n,function(n,t){return e.isPlainObject(C[t])?(C=C[t],!0):e.isFunction(C[t])?(r=C[t],!0):(l.error(i.error.method),!1)})),e.isFunction(r)?r.apply(o,a):!1}},C!==t&&o?("invoke"==o[0]&&(o=Array.prototype.slice.call(o,1)),l.invoke(o[0],this,Array.prototype.slice.call(o,1))):void l.initialize()}),this},e.fn.colorize.settings={name:"Image Colorizer",debug:!0,namespace:"colorize",onDraw:function(e,n,i,t){},async:!0,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); |
@ -1,708 +0,0 @@ |
|||
/*! |
|||
* # Semantic UI 2.3.0 - State |
|||
* http://github.com/semantic-org/semantic-ui/
|
|||
* |
|||
* |
|||
* Released under the MIT license |
|||
* http://opensource.org/licenses/MIT
|
|||
* |
|||
*/ |
|||
|
|||
;(function ($, window, document, undefined) { |
|||
|
|||
"use strict"; |
|||
|
|||
window = (typeof window != 'undefined' && window.Math == Math) |
|||
? window |
|||
: (typeof self != 'undefined' && self.Math == Math) |
|||
? self |
|||
: Function('return this')() |
|||
; |
|||
|
|||
$.fn.state = function(parameters) { |
|||
var |
|||
$allModules = $(this), |
|||
|
|||
moduleSelector = $allModules.selector || '', |
|||
|
|||
hasTouch = ('ontouchstart' in document.documentElement), |
|||
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.state.settings, parameters) |
|||
: $.extend({}, $.fn.state.settings), |
|||
|
|||
error = settings.error, |
|||
metadata = settings.metadata, |
|||
className = settings.className, |
|||
namespace = settings.namespace, |
|||
states = settings.states, |
|||
text = settings.text, |
|||
|
|||
eventNamespace = '.' + namespace, |
|||
moduleNamespace = namespace + '-module', |
|||
|
|||
$module = $(this), |
|||
|
|||
element = this, |
|||
instance = $module.data(moduleNamespace), |
|||
|
|||
module |
|||
; |
|||
module = { |
|||
|
|||
initialize: function() { |
|||
module.verbose('Initializing module'); |
|||
|
|||
// allow module to guess desired state based on element
|
|||
if(settings.automatic) { |
|||
module.add.defaults(); |
|||
} |
|||
|
|||
// bind events with delegated events
|
|||
if(settings.context && moduleSelector !== '') { |
|||
$(settings.context) |
|||
.on(moduleSelector, 'mouseenter' + eventNamespace, module.change.text) |
|||
.on(moduleSelector, 'mouseleave' + eventNamespace, module.reset.text) |
|||
.on(moduleSelector, 'click' + eventNamespace, module.toggle.state) |
|||
; |
|||
} |
|||
else { |
|||
$module |
|||
.on('mouseenter' + eventNamespace, module.change.text) |
|||
.on('mouseleave' + eventNamespace, module.reset.text) |
|||
.on('click' + eventNamespace, module.toggle.state) |
|||
; |
|||
} |
|||
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 |
|||
.off(eventNamespace) |
|||
.removeData(moduleNamespace) |
|||
; |
|||
}, |
|||
|
|||
refresh: function() { |
|||
module.verbose('Refreshing selector cache'); |
|||
$module = $(element); |
|||
}, |
|||
|
|||
add: { |
|||
defaults: function() { |
|||
var |
|||
userStates = parameters && $.isPlainObject(parameters.states) |
|||
? parameters.states |
|||
: {} |
|||
; |
|||
$.each(settings.defaults, function(type, typeStates) { |
|||
if( module.is[type] !== undefined && module.is[type]() ) { |
|||
module.verbose('Adding default states', type, element); |
|||
$.extend(settings.states, typeStates, userStates); |
|||
} |
|||
}); |
|||
} |
|||
}, |
|||
|
|||
is: { |
|||
|
|||
active: function() { |
|||
return $module.hasClass(className.active); |
|||
}, |
|||
loading: function() { |
|||
return $module.hasClass(className.loading); |
|||
}, |
|||
inactive: function() { |
|||
return !( $module.hasClass(className.active) ); |
|||
}, |
|||
state: function(state) { |
|||
if(className[state] === undefined) { |
|||
return false; |
|||
} |
|||
return $module.hasClass( className[state] ); |
|||
}, |
|||
|
|||
enabled: function() { |
|||
return !( $module.is(settings.filter.active) ); |
|||
}, |
|||
disabled: function() { |
|||
return ( $module.is(settings.filter.active) ); |
|||
}, |
|||
textEnabled: function() { |
|||
return !( $module.is(settings.filter.text) ); |
|||
}, |
|||
|
|||
// definitions for automatic type detection
|
|||
button: function() { |
|||
return $module.is('.button:not(a, .submit)'); |
|||
}, |
|||
input: function() { |
|||
return $module.is('input'); |
|||
}, |
|||
progress: function() { |
|||
return $module.is('.ui.progress'); |
|||
} |
|||
}, |
|||
|
|||
allow: function(state) { |
|||
module.debug('Now allowing state', state); |
|||
states[state] = true; |
|||
}, |
|||
disallow: function(state) { |
|||
module.debug('No longer allowing', state); |
|||
states[state] = false; |
|||
}, |
|||
|
|||
allows: function(state) { |
|||
return states[state] || false; |
|||
}, |
|||
|
|||
enable: function() { |
|||
$module.removeClass(className.disabled); |
|||
}, |
|||
|
|||
disable: function() { |
|||
$module.addClass(className.disabled); |
|||
}, |
|||
|
|||
setState: function(state) { |
|||
if(module.allows(state)) { |
|||
$module.addClass( className[state] ); |
|||
} |
|||
}, |
|||
|
|||
removeState: function(state) { |
|||
if(module.allows(state)) { |
|||
$module.removeClass( className[state] ); |
|||
} |
|||
}, |
|||
|
|||
toggle: { |
|||
state: function() { |
|||
var |
|||
apiRequest, |
|||
requestCancelled |
|||
; |
|||
if( module.allows('active') && module.is.enabled() ) { |
|||
module.refresh(); |
|||
if($.fn.api !== undefined) { |
|||
apiRequest = $module.api('get request'); |
|||
requestCancelled = $module.api('was cancelled'); |
|||
if( requestCancelled ) { |
|||
module.debug('API Request cancelled by beforesend'); |
|||
settings.activateTest = function(){ return false; }; |
|||
settings.deactivateTest = function(){ return false; }; |
|||
} |
|||
else if(apiRequest) { |
|||
module.listenTo(apiRequest); |
|||
return; |
|||
} |
|||
} |
|||
module.change.state(); |
|||
} |
|||
} |
|||
}, |
|||
|
|||
listenTo: function(apiRequest) { |
|||
module.debug('API request detected, waiting for state signal', apiRequest); |
|||
if(apiRequest) { |
|||
if(text.loading) { |
|||
module.update.text(text.loading); |
|||
} |
|||
$.when(apiRequest) |
|||
.then(function() { |
|||
if(apiRequest.state() == 'resolved') { |
|||
module.debug('API request succeeded'); |
|||
settings.activateTest = function(){ return true; }; |
|||
settings.deactivateTest = function(){ return true; }; |
|||
} |
|||
else { |
|||
module.debug('API request failed'); |
|||
settings.activateTest = function(){ return false; }; |
|||
settings.deactivateTest = function(){ return false; }; |
|||
} |
|||
module.change.state(); |
|||
}) |
|||
; |
|||
} |
|||
}, |
|||
|
|||
// checks whether active/inactive state can be given
|
|||
change: { |
|||
|
|||
state: function() { |
|||
module.debug('Determining state change direction'); |
|||
// inactive to active change
|
|||
if( module.is.inactive() ) { |
|||
module.activate(); |
|||
} |
|||
else { |
|||
module.deactivate(); |
|||
} |
|||
if(settings.sync) { |
|||
module.sync(); |
|||
} |
|||
settings.onChange.call(element); |
|||
}, |
|||
|
|||
text: function() { |
|||
if( module.is.textEnabled() ) { |
|||
if(module.is.disabled() ) { |
|||
module.verbose('Changing text to disabled text', text.hover); |
|||
module.update.text(text.disabled); |
|||
} |
|||
else if( module.is.active() ) { |
|||
if(text.hover) { |
|||
module.verbose('Changing text to hover text', text.hover); |
|||
module.update.text(text.hover); |
|||
} |
|||
else if(text.deactivate) { |
|||
module.verbose('Changing text to deactivating text', text.deactivate); |
|||
module.update.text(text.deactivate); |
|||
} |
|||
} |
|||
else { |
|||
if(text.hover) { |
|||
module.verbose('Changing text to hover text', text.hover); |
|||
module.update.text(text.hover); |
|||
} |
|||
else if(text.activate){ |
|||
module.verbose('Changing text to activating text', text.activate); |
|||
module.update.text(text.activate); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
}, |
|||
|
|||
activate: function() { |
|||
if( settings.activateTest.call(element) ) { |
|||
module.debug('Setting state to active'); |
|||
$module |
|||
.addClass(className.active) |
|||
; |
|||
module.update.text(text.active); |
|||
settings.onActivate.call(element); |
|||
} |
|||
}, |
|||
|
|||
deactivate: function() { |
|||
if( settings.deactivateTest.call(element) ) { |
|||
module.debug('Setting state to inactive'); |
|||
$module |
|||
.removeClass(className.active) |
|||
; |
|||
module.update.text(text.inactive); |
|||
settings.onDeactivate.call(element); |
|||
} |
|||
}, |
|||
|
|||
sync: function() { |
|||
module.verbose('Syncing other buttons to current state'); |
|||
if( module.is.active() ) { |
|||
$allModules |
|||
.not($module) |
|||
.state('activate'); |
|||
} |
|||
else { |
|||
$allModules |
|||
.not($module) |
|||
.state('deactivate') |
|||
; |
|||
} |
|||
}, |
|||
|
|||
get: { |
|||
text: function() { |
|||
return (settings.selector.text) |
|||
? $module.find(settings.selector.text).text() |
|||
: $module.html() |
|||
; |
|||
}, |
|||
textFor: function(state) { |
|||
return text[state] || false; |
|||
} |
|||
}, |
|||
|
|||
flash: { |
|||
text: function(text, duration, callback) { |
|||
var |
|||
previousText = module.get.text() |
|||
; |
|||
module.debug('Flashing text message', text, duration); |
|||
text = text || settings.text.flash; |
|||
duration = duration || settings.flashDuration; |
|||
callback = callback || function() {}; |
|||
module.update.text(text); |
|||
setTimeout(function(){ |
|||
module.update.text(previousText); |
|||
callback.call(element); |
|||
}, duration); |
|||
} |
|||
}, |
|||
|
|||
reset: { |
|||
// on mouseout sets text to previous value
|
|||
text: function() { |
|||
var |
|||
activeText = text.active || $module.data(metadata.storedText), |
|||
inactiveText = text.inactive || $module.data(metadata.storedText) |
|||
; |
|||
if( module.is.textEnabled() ) { |
|||
if( module.is.active() && activeText) { |
|||
module.verbose('Resetting active text', activeText); |
|||
module.update.text(activeText); |
|||
} |
|||
else if(inactiveText) { |
|||
module.verbose('Resetting inactive text', activeText); |
|||
module.update.text(inactiveText); |
|||
} |
|||
} |
|||
} |
|||
}, |
|||
|
|||
update: { |
|||
text: function(text) { |
|||
var |
|||
currentText = module.get.text() |
|||
; |
|||
if(text && text !== currentText) { |
|||
module.debug('Updating text', text); |
|||
if(settings.selector.text) { |
|||
$module |
|||
.data(metadata.storedText, text) |
|||
.find(settings.selector.text) |
|||
.text(text) |
|||
; |
|||
} |
|||
else { |
|||
$module |
|||
.data(metadata.storedText, text) |
|||
.html(text) |
|||
; |
|||
} |
|||
} |
|||
else { |
|||
module.debug('Text is already set, ignoring update', text); |
|||
} |
|||
} |
|||
}, |
|||
|
|||
setting: function(name, value) { |
|||
module.debug('Changing setting', name, value); |
|||
if( $.isPlainObject(name) ) { |
|||
$.extend(true, settings, name); |
|||
} |
|||
else if(value !== undefined) { |
|||
if($.isPlainObject(settings[name])) { |
|||
$.extend(true, settings[name], value); |
|||
} |
|||
else { |
|||
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.silent && 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.silent && 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() { |
|||
if(!settings.silent) { |
|||
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 |
|||
; |
|||
}; |
|||
|
|||
$.fn.state.settings = { |
|||
|
|||
// module info
|
|||
name : 'State', |
|||
|
|||
// debug output
|
|||
debug : false, |
|||
|
|||
// verbose debug output
|
|||
verbose : false, |
|||
|
|||
// namespace for events
|
|||
namespace : 'state', |
|||
|
|||
// debug data includes performance
|
|||
performance : true, |
|||
|
|||
// callback occurs on state change
|
|||
onActivate : function() {}, |
|||
onDeactivate : function() {}, |
|||
onChange : function() {}, |
|||
|
|||
// state test functions
|
|||
activateTest : function() { return true; }, |
|||
deactivateTest : function() { return true; }, |
|||
|
|||
// whether to automatically map default states
|
|||
automatic : true, |
|||
|
|||
// activate / deactivate changes all elements instantiated at same time
|
|||
sync : false, |
|||
|
|||
// default flash text duration, used for temporarily changing text of an element
|
|||
flashDuration : 1000, |
|||
|
|||
// selector filter
|
|||
filter : { |
|||
text : '.loading, .disabled', |
|||
active : '.disabled' |
|||
}, |
|||
|
|||
context : false, |
|||
|
|||
// error
|
|||
error: { |
|||
beforeSend : 'The before send function has cancelled state change', |
|||
method : 'The method you called is not defined.' |
|||
}, |
|||
|
|||
// metadata
|
|||
metadata: { |
|||
promise : 'promise', |
|||
storedText : 'stored-text' |
|||
}, |
|||
|
|||
// change class on state
|
|||
className: { |
|||
active : 'active', |
|||
disabled : 'disabled', |
|||
error : 'error', |
|||
loading : 'loading', |
|||
success : 'success', |
|||
warning : 'warning' |
|||
}, |
|||
|
|||
selector: { |
|||
// selector for text node
|
|||
text: false |
|||
}, |
|||
|
|||
defaults : { |
|||
input: { |
|||
disabled : true, |
|||
loading : true, |
|||
active : true |
|||
}, |
|||
button: { |
|||
disabled : true, |
|||
loading : true, |
|||
active : true, |
|||
}, |
|||
progress: { |
|||
active : true, |
|||
success : true, |
|||
warning : true, |
|||
error : true |
|||
} |
|||
}, |
|||
|
|||
states : { |
|||
active : true, |
|||
disabled : true, |
|||
error : true, |
|||
loading : true, |
|||
success : true, |
|||
warning : true |
|||
}, |
|||
|
|||
text : { |
|||
disabled : false, |
|||
flash : false, |
|||
hover : false, |
|||
active : false, |
|||
inactive : false, |
|||
activate : false, |
|||
deactivate : false |
|||
} |
|||
|
|||
}; |
|||
|
|||
|
|||
|
|||
})( jQuery, window, document ); |
1
dist/components/state.min.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,517 +0,0 @@ |
|||
/*! |
|||
* # Semantic UI 2.0.0 - Visit |
|||
* 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"; |
|||
|
|||
$.visit = $.fn.visit = function(parameters) { |
|||
var |
|||
$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.visit.settings, parameters) |
|||
: $.extend({}, $.fn.visit.settings), |
|||
|
|||
error = settings.error, |
|||
namespace = settings.namespace, |
|||
|
|||
eventNamespace = '.' + namespace, |
|||
moduleNamespace = namespace + '-module', |
|||
|
|||
$module = $(this), |
|||
$displays = $(), |
|||
|
|||
element = this, |
|||
instance = $module.data(moduleNamespace), |
|||
module |
|||
; |
|||
module = { |
|||
|
|||
initialize: function() { |
|||
if(settings.count) { |
|||
module.store(settings.key.count, settings.count); |
|||
} |
|||
else if(settings.id) { |
|||
module.add.id(settings.id); |
|||
} |
|||
else if(settings.increment && methodInvoked !== 'increment') { |
|||
module.increment(); |
|||
} |
|||
module.add.display($module); |
|||
module.instantiate(); |
|||
}, |
|||
|
|||
instantiate: function() { |
|||
module.verbose('Storing instance of visit module', module); |
|||
instance = module; |
|||
$module |
|||
.data(moduleNamespace, module) |
|||
; |
|||
}, |
|||
|
|||
destroy: function() { |
|||
module.verbose('Destroying instance'); |
|||
$module |
|||
.removeData(moduleNamespace) |
|||
; |
|||
}, |
|||
|
|||
increment: function(id) { |
|||
var |
|||
currentValue = module.get.count(), |
|||
newValue = +(currentValue) + 1 |
|||
; |
|||
if(id) { |
|||
module.add.id(id); |
|||
} |
|||
else { |
|||
if(newValue > settings.limit && !settings.surpass) { |
|||
newValue = settings.limit; |
|||
} |
|||
module.debug('Incrementing visits', newValue); |
|||
module.store(settings.key.count, newValue); |
|||
} |
|||
}, |
|||
|
|||
decrement: function(id) { |
|||
var |
|||
currentValue = module.get.count(), |
|||
newValue = +(currentValue) - 1 |
|||
; |
|||
if(id) { |
|||
module.remove.id(id); |
|||
} |
|||
else { |
|||
module.debug('Removing visit'); |
|||
module.store(settings.key.count, newValue); |
|||
} |
|||
}, |
|||
|
|||
get: { |
|||
count: function() { |
|||
return +(module.retrieve(settings.key.count)) || 0; |
|||
}, |
|||
idCount: function(ids) { |
|||
ids = ids || module.get.ids(); |
|||
return ids.length; |
|||
}, |
|||
ids: function(delimitedIDs) { |
|||
var |
|||
idArray = [] |
|||
; |
|||
delimitedIDs = delimitedIDs || module.retrieve(settings.key.ids); |
|||
if(typeof delimitedIDs === 'string') { |
|||
idArray = delimitedIDs.split(settings.delimiter); |
|||
} |
|||
module.verbose('Found visited ID list', idArray); |
|||
return idArray; |
|||
}, |
|||
storageOptions: function(data) { |
|||
var |
|||
options = {} |
|||
; |
|||
if(settings.expires) { |
|||
options.expires = settings.expires; |
|||
} |
|||
if(settings.domain) { |
|||
options.domain = settings.domain; |
|||
} |
|||
if(settings.path) { |
|||
options.path = settings.path; |
|||
} |
|||
return options; |
|||
} |
|||
}, |
|||
|
|||
has: { |
|||
visited: function(id, ids) { |
|||
var |
|||
visited = false |
|||
; |
|||
ids = ids || module.get.ids(); |
|||
if(id !== undefined && ids) { |
|||
$.each(ids, function(index, value){ |
|||
if(value == id) { |
|||
visited = true; |
|||
} |
|||
}); |
|||
} |
|||
return visited; |
|||
} |
|||
}, |
|||
|
|||
set: { |
|||
count: function(value) { |
|||
module.store(settings.key.count, value); |
|||
}, |
|||
ids: function(value) { |
|||
module.store(settings.key.ids, value); |
|||
} |
|||
}, |
|||
|
|||
reset: function() { |
|||
module.store(settings.key.count, 0); |
|||
module.store(settings.key.ids, null); |
|||
}, |
|||
|
|||
add: { |
|||
id: function(id) { |
|||
var |
|||
currentIDs = module.retrieve(settings.key.ids), |
|||
newIDs = (currentIDs === undefined || currentIDs === '') |
|||
? id |
|||
: currentIDs + settings.delimiter + id |
|||
; |
|||
if( module.has.visited(id) ) { |
|||
module.debug('Unique content already visited, not adding visit', id, currentIDs); |
|||
} |
|||
else if(id === undefined) { |
|||
module.debug('ID is not defined'); |
|||
} |
|||
else { |
|||
module.debug('Adding visit to unique content', id); |
|||
module.store(settings.key.ids, newIDs); |
|||
} |
|||
module.set.count( module.get.idCount() ); |
|||
}, |
|||
display: function(selector) { |
|||
var |
|||
$element = $(selector) |
|||
; |
|||
if($element.length > 0 && !$.isWindow($element[0])) { |
|||
module.debug('Updating visit count for element', $element); |
|||
$displays = ($displays.length > 0) |
|||
? $displays.add($element) |
|||
: $element |
|||
; |
|||
} |
|||
} |
|||
}, |
|||
|
|||
remove: { |
|||
id: function(id) { |
|||
var |
|||
currentIDs = module.get.ids(), |
|||
newIDs = [] |
|||
; |
|||
if(id !== undefined && currentIDs !== undefined) { |
|||
module.debug('Removing visit to unique content', id, currentIDs); |
|||
$.each(currentIDs, function(index, value){ |
|||
if(value !== id) { |
|||
newIDs.push(value); |
|||
} |
|||
}); |
|||
newIDs = newIDs.join(settings.delimiter); |
|||
module.store(settings.key.ids, newIDs ); |
|||
} |
|||
module.set.count( module.get.idCount() ); |
|||
} |
|||
}, |
|||
|
|||
check: { |
|||
limit: function(value) { |
|||
value = value || module.get.count(); |
|||
if(settings.limit) { |
|||
if(value >= settings.limit) { |
|||
module.debug('Pages viewed exceeded limit, firing callback', value, settings.limit); |
|||
settings.onLimit.call(element, value); |
|||
} |
|||
module.debug('Limit not reached', value, settings.limit); |
|||
settings.onChange.call(element, value); |
|||
} |
|||
module.update.display(value); |
|||
} |
|||
}, |
|||
|
|||
update: { |
|||
display: function(value) { |
|||
value = value || module.get.count(); |
|||
if($displays.length > 0) { |
|||
module.debug('Updating displayed view count', $displays); |
|||
$displays.html(value); |
|||
} |
|||
} |
|||
}, |
|||
|
|||
store: function(key, value) { |
|||
var |
|||
options = module.get.storageOptions(value) |
|||
; |
|||
if(settings.storageMethod == 'localstorage' && window.localStorage !== undefined) { |
|||
window.localStorage.setItem(key, value); |
|||
module.debug('Value stored using local storage', key, value); |
|||
} |
|||
else if($.cookie !== undefined) { |
|||
$.cookie(key, value, options); |
|||
module.debug('Value stored using cookie', key, value, options); |
|||
} |
|||
else { |
|||
module.error(error.noCookieStorage); |
|||
return; |
|||
} |
|||
if(key == settings.key.count) { |
|||
module.check.limit(value); |
|||
} |
|||
}, |
|||
retrieve: function(key, value) { |
|||
var |
|||
storedValue |
|||
; |
|||
if(settings.storageMethod == 'localstorage' && window.localStorage !== undefined) { |
|||
storedValue = window.localStorage.getItem(key); |
|||
} |
|||
// get by cookie
|
|||
else if($.cookie !== undefined) { |
|||
storedValue = $.cookie(key); |
|||
} |
|||
else { |
|||
module.error(error.noCookieStorage); |
|||
} |
|||
if(storedValue == 'undefined' || storedValue == 'null' || storedValue === undefined || storedValue === null) { |
|||
storedValue = undefined; |
|||
} |
|||
return storedValue; |
|||
}, |
|||
|
|||
setting: function(name, value) { |
|||
if( $.isPlainObject(name) ) { |
|||
$.extend(true, settings, name); |
|||
} |
|||
else if(value !== undefined) { |
|||
settings[name] = value; |
|||
} |
|||
else { |
|||
return settings[name]; |
|||
} |
|||
}, |
|||
internal: function(name, value) { |
|||
module.debug('Changing internal', name, value); |
|||
if(value !== undefined) { |
|||
if( $.isPlainObject(name) ) { |
|||
$.extend(true, module, name); |
|||
} |
|||
else { |
|||
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($allModules.length > 1) { |
|||
title += ' ' + '(' + $allModules.length + ')'; |
|||
} |
|||
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 { |
|||
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 |
|||
; |
|||
}; |
|||
|
|||
$.fn.visit.settings = { |
|||
|
|||
name : 'Visit', |
|||
|
|||
debug : false, |
|||
verbose : false, |
|||
performance : true, |
|||
|
|||
namespace : 'visit', |
|||
|
|||
increment : false, |
|||
surpass : false, |
|||
count : false, |
|||
limit : false, |
|||
|
|||
delimiter : '&', |
|||
storageMethod : 'localstorage', |
|||
|
|||
key : { |
|||
count : 'visit-count', |
|||
ids : 'visit-ids' |
|||
}, |
|||
|
|||
expires : 30, |
|||
domain : false, |
|||
path : '/', |
|||
|
|||
onLimit : function() {}, |
|||
onChange : function() {}, |
|||
|
|||
error : { |
|||
method : 'The method you called is not defined', |
|||
missingPersist : 'Using the persist setting requires the inclusion of PersistJS', |
|||
noCookieStorage : 'The default storage cookie requires $.cookie to be included.' |
|||
} |
|||
|
|||
}; |
|||
|
|||
})( jQuery, window , document ); |
11
dist/components/visit.min.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,280 +0,0 @@ |
|||
/*! |
|||
* # Semantic UI - Colorize |
|||
* http://github.com/semantic-org/semantic-ui/
|
|||
* |
|||
* |
|||
* Released under the MIT license |
|||
* http://opensource.org/licenses/MIT
|
|||
* |
|||
*/ |
|||
|
|||
;(function ($, window, document, undefined) { |
|||
|
|||
"use strict"; |
|||
|
|||
window = (typeof window != 'undefined' && window.Math == Math) |
|||
? window |
|||
: (typeof self != 'undefined' && self.Math == Math) |
|||
? self |
|||
: Function('return this')() |
|||
; |
|||
|
|||
$.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, |
|||
|
|||
// shortcuts
|
|||
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 ); |
@ -1,708 +0,0 @@ |
|||
/*! |
|||
* # Semantic UI - State |
|||
* http://github.com/semantic-org/semantic-ui/
|
|||
* |
|||
* |
|||
* Released under the MIT license |
|||
* http://opensource.org/licenses/MIT
|
|||
* |
|||
*/ |
|||
|
|||
;(function ($, window, document, undefined) { |
|||
|
|||
"use strict"; |
|||
|
|||
window = (typeof window != 'undefined' && window.Math == Math) |
|||
? window |
|||
: (typeof self != 'undefined' && self.Math == Math) |
|||
? self |
|||
: Function('return this')() |
|||
; |
|||
|
|||
$.fn.state = function(parameters) { |
|||
var |
|||
$allModules = $(this), |
|||
|
|||
moduleSelector = $allModules.selector || '', |
|||
|
|||
hasTouch = ('ontouchstart' in document.documentElement), |
|||
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.state.settings, parameters) |
|||
: $.extend({}, $.fn.state.settings), |
|||
|
|||
error = settings.error, |
|||
metadata = settings.metadata, |
|||
className = settings.className, |
|||
namespace = settings.namespace, |
|||
states = settings.states, |
|||
text = settings.text, |
|||
|
|||
eventNamespace = '.' + namespace, |
|||
moduleNamespace = namespace + '-module', |
|||
|
|||
$module = $(this), |
|||
|
|||
element = this, |
|||
instance = $module.data(moduleNamespace), |
|||
|
|||
module |
|||
; |
|||
module = { |
|||
|
|||
initialize: function() { |
|||
module.verbose('Initializing module'); |
|||
|
|||
// allow module to guess desired state based on element
|
|||
if(settings.automatic) { |
|||
module.add.defaults(); |
|||
} |
|||
|
|||
// bind events with delegated events
|
|||
if(settings.context && moduleSelector !== '') { |
|||
$(settings.context) |
|||
.on(moduleSelector, 'mouseenter' + eventNamespace, module.change.text) |
|||
.on(moduleSelector, 'mouseleave' + eventNamespace, module.reset.text) |
|||
.on(moduleSelector, 'click' + eventNamespace, module.toggle.state) |
|||
; |
|||
} |
|||
else { |
|||
$module |
|||
.on('mouseenter' + eventNamespace, module.change.text) |
|||
.on('mouseleave' + eventNamespace, module.reset.text) |
|||
.on('click' + eventNamespace, module.toggle.state) |
|||
; |
|||
} |
|||
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 |
|||
.off(eventNamespace) |
|||
.removeData(moduleNamespace) |
|||
; |
|||
}, |
|||
|
|||
refresh: function() { |
|||
module.verbose('Refreshing selector cache'); |
|||
$module = $(element); |
|||
}, |
|||
|
|||
add: { |
|||
defaults: function() { |
|||
var |
|||
userStates = parameters && $.isPlainObject(parameters.states) |
|||
? parameters.states |
|||
: {} |
|||
; |
|||
$.each(settings.defaults, function(type, typeStates) { |
|||
if( module.is[type] !== undefined && module.is[type]() ) { |
|||
module.verbose('Adding default states', type, element); |
|||
$.extend(settings.states, typeStates, userStates); |
|||
} |
|||
}); |
|||
} |
|||
}, |
|||
|
|||
is: { |
|||
|
|||
active: function() { |
|||
return $module.hasClass(className.active); |
|||
}, |
|||
loading: function() { |
|||
return $module.hasClass(className.loading); |
|||
}, |
|||
inactive: function() { |
|||
return !( $module.hasClass(className.active) ); |
|||
}, |
|||
state: function(state) { |
|||
if(className[state] === undefined) { |
|||
return false; |
|||
} |
|||
return $module.hasClass( className[state] ); |
|||
}, |
|||
|
|||
enabled: function() { |
|||
return !( $module.is(settings.filter.active) ); |
|||
}, |
|||
disabled: function() { |
|||
return ( $module.is(settings.filter.active) ); |
|||
}, |
|||
textEnabled: function() { |
|||
return !( $module.is(settings.filter.text) ); |
|||
}, |
|||
|
|||
// definitions for automatic type detection
|
|||
button: function() { |
|||
return $module.is('.button:not(a, .submit)'); |
|||
}, |
|||
input: function() { |
|||
return $module.is('input'); |
|||
}, |
|||
progress: function() { |
|||
return $module.is('.ui.progress'); |
|||
} |
|||
}, |
|||
|
|||
allow: function(state) { |
|||
module.debug('Now allowing state', state); |
|||
states[state] = true; |
|||
}, |
|||
disallow: function(state) { |
|||
module.debug('No longer allowing', state); |
|||
states[state] = false; |
|||
}, |
|||
|
|||
allows: function(state) { |
|||
return states[state] || false; |
|||
}, |
|||
|
|||
enable: function() { |
|||
$module.removeClass(className.disabled); |
|||
}, |
|||
|
|||
disable: function() { |
|||
$module.addClass(className.disabled); |
|||
}, |
|||
|
|||
setState: function(state) { |
|||
if(module.allows(state)) { |
|||
$module.addClass( className[state] ); |
|||
} |
|||
}, |
|||
|
|||
removeState: function(state) { |
|||
if(module.allows(state)) { |
|||
$module.removeClass( className[state] ); |
|||
} |
|||
}, |
|||
|
|||
toggle: { |
|||
state: function() { |
|||
var |
|||
apiRequest, |
|||
requestCancelled |
|||
; |
|||
if( module.allows('active') && module.is.enabled() ) { |
|||
module.refresh(); |
|||
if($.fn.api !== undefined) { |
|||
apiRequest = $module.api('get request'); |
|||
requestCancelled = $module.api('was cancelled'); |
|||
if( requestCancelled ) { |
|||
module.debug('API Request cancelled by beforesend'); |
|||
settings.activateTest = function(){ return false; }; |
|||
settings.deactivateTest = function(){ return false; }; |
|||
} |
|||
else if(apiRequest) { |
|||
module.listenTo(apiRequest); |
|||
return; |
|||
} |
|||
} |
|||
module.change.state(); |
|||
} |
|||
} |
|||
}, |
|||
|
|||
listenTo: function(apiRequest) { |
|||
module.debug('API request detected, waiting for state signal', apiRequest); |
|||
if(apiRequest) { |
|||
if(text.loading) { |
|||
module.update.text(text.loading); |
|||
} |
|||
$.when(apiRequest) |
|||
.then(function() { |
|||
if(apiRequest.state() == 'resolved') { |
|||
module.debug('API request succeeded'); |
|||
settings.activateTest = function(){ return true; }; |
|||
settings.deactivateTest = function(){ return true; }; |
|||
} |
|||
else { |
|||
module.debug('API request failed'); |
|||
settings.activateTest = function(){ return false; }; |
|||
settings.deactivateTest = function(){ return false; }; |
|||
} |
|||
module.change.state(); |
|||
}) |
|||
; |
|||
} |
|||
}, |
|||
|
|||
// checks whether active/inactive state can be given
|
|||
change: { |
|||
|
|||
state: function() { |
|||
module.debug('Determining state change direction'); |
|||
// inactive to active change
|
|||
if( module.is.inactive() ) { |
|||
module.activate(); |
|||
} |
|||
else { |
|||
module.deactivate(); |
|||
} |
|||
if(settings.sync) { |
|||
module.sync(); |
|||
} |
|||
settings.onChange.call(element); |
|||
}, |
|||
|
|||
text: function() { |
|||
if( module.is.textEnabled() ) { |
|||
if(module.is.disabled() ) { |
|||
module.verbose('Changing text to disabled text', text.hover); |
|||
module.update.text(text.disabled); |
|||
} |
|||
else if( module.is.active() ) { |
|||
if(text.hover) { |
|||
module.verbose('Changing text to hover text', text.hover); |
|||
module.update.text(text.hover); |
|||
} |
|||
else if(text.deactivate) { |
|||
module.verbose('Changing text to deactivating text', text.deactivate); |
|||
module.update.text(text.deactivate); |
|||
} |
|||
} |
|||
else { |
|||
if(text.hover) { |
|||
module.verbose('Changing text to hover text', text.hover); |
|||
module.update.text(text.hover); |
|||
} |
|||
else if(text.activate){ |
|||
module.verbose('Changing text to activating text', text.activate); |
|||
module.update.text(text.activate); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
}, |
|||
|
|||
activate: function() { |
|||
if( settings.activateTest.call(element) ) { |
|||
module.debug('Setting state to active'); |
|||
$module |
|||
.addClass(className.active) |
|||
; |
|||
module.update.text(text.active); |
|||
settings.onActivate.call(element); |
|||
} |
|||
}, |
|||
|
|||
deactivate: function() { |
|||
if( settings.deactivateTest.call(element) ) { |
|||
module.debug('Setting state to inactive'); |
|||
$module |
|||
.removeClass(className.active) |
|||
; |
|||
module.update.text(text.inactive); |
|||
settings.onDeactivate.call(element); |
|||
} |
|||
}, |
|||
|
|||
sync: function() { |
|||
module.verbose('Syncing other buttons to current state'); |
|||
if( module.is.active() ) { |
|||
$allModules |
|||
.not($module) |
|||
.state('activate'); |
|||
} |
|||
else { |
|||
$allModules |
|||
.not($module) |
|||
.state('deactivate') |
|||
; |
|||
} |
|||
}, |
|||
|
|||
get: { |
|||
text: function() { |
|||
return (settings.selector.text) |
|||
? $module.find(settings.selector.text).text() |
|||
: $module.html() |
|||
; |
|||
}, |
|||
textFor: function(state) { |
|||
return text[state] || false; |
|||
} |
|||
}, |
|||
|
|||
flash: { |
|||
text: function(text, duration, callback) { |
|||
var |
|||
previousText = module.get.text() |
|||
; |
|||
module.debug('Flashing text message', text, duration); |
|||
text = text || settings.text.flash; |
|||
duration = duration || settings.flashDuration; |
|||
callback = callback || function() {}; |
|||
module.update.text(text); |
|||
setTimeout(function(){ |
|||
module.update.text(previousText); |
|||
callback.call(element); |
|||
}, duration); |
|||
} |
|||
}, |
|||
|
|||
reset: { |
|||
// on mouseout sets text to previous value
|
|||
text: function() { |
|||
var |
|||
activeText = text.active || $module.data(metadata.storedText), |
|||
inactiveText = text.inactive || $module.data(metadata.storedText) |
|||
; |
|||
if( module.is.textEnabled() ) { |
|||
if( module.is.active() && activeText) { |
|||
module.verbose('Resetting active text', activeText); |
|||
module.update.text(activeText); |
|||
} |
|||
else if(inactiveText) { |
|||
module.verbose('Resetting inactive text', activeText); |
|||
module.update.text(inactiveText); |
|||
} |
|||
} |
|||
} |
|||
}, |
|||
|
|||
update: { |
|||
text: function(text) { |
|||
var |
|||
currentText = module.get.text() |
|||
; |
|||
if(text && text !== currentText) { |
|||
module.debug('Updating text', text); |
|||
if(settings.selector.text) { |
|||
$module |
|||
.data(metadata.storedText, text) |
|||
.find(settings.selector.text) |
|||
.text(text) |
|||
; |
|||
} |
|||
else { |
|||
$module |
|||
.data(metadata.storedText, text) |
|||
.html(text) |
|||
; |
|||
} |
|||
} |
|||
else { |
|||
module.debug('Text is already set, ignoring update', text); |
|||
} |
|||
} |
|||
}, |
|||
|
|||
setting: function(name, value) { |
|||
module.debug('Changing setting', name, value); |
|||
if( $.isPlainObject(name) ) { |
|||
$.extend(true, settings, name); |
|||
} |
|||
else if(value !== undefined) { |
|||
if($.isPlainObject(settings[name])) { |
|||
$.extend(true, settings[name], value); |
|||
} |
|||
else { |
|||
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.silent && 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.silent && 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() { |
|||
if(!settings.silent) { |
|||
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 |
|||
; |
|||
}; |
|||
|
|||
$.fn.state.settings = { |
|||
|
|||
// module info
|
|||
name : 'State', |
|||
|
|||
// debug output
|
|||
debug : false, |
|||
|
|||
// verbose debug output
|
|||
verbose : false, |
|||
|
|||
// namespace for events
|
|||
namespace : 'state', |
|||
|
|||
// debug data includes performance
|
|||
performance : true, |
|||
|
|||
// callback occurs on state change
|
|||
onActivate : function() {}, |
|||
onDeactivate : function() {}, |
|||
onChange : function() {}, |
|||
|
|||
// state test functions
|
|||
activateTest : function() { return true; }, |
|||
deactivateTest : function() { return true; }, |
|||
|
|||
// whether to automatically map default states
|
|||
automatic : true, |
|||
|
|||
// activate / deactivate changes all elements instantiated at same time
|
|||
sync : false, |
|||
|
|||
// default flash text duration, used for temporarily changing text of an element
|
|||
flashDuration : 1000, |
|||
|
|||
// selector filter
|
|||
filter : { |
|||
text : '.loading, .disabled', |
|||
active : '.disabled' |
|||
}, |
|||
|
|||
context : false, |
|||
|
|||
// error
|
|||
error: { |
|||
beforeSend : 'The before send function has cancelled state change', |
|||
method : 'The method you called is not defined.' |
|||
}, |
|||
|
|||
// metadata
|
|||
metadata: { |
|||
promise : 'promise', |
|||
storedText : 'stored-text' |
|||
}, |
|||
|
|||
// change class on state
|
|||
className: { |
|||
active : 'active', |
|||
disabled : 'disabled', |
|||
error : 'error', |
|||
loading : 'loading', |
|||
success : 'success', |
|||
warning : 'warning' |
|||
}, |
|||
|
|||
selector: { |
|||
// selector for text node
|
|||
text: false |
|||
}, |
|||
|
|||
defaults : { |
|||
input: { |
|||
disabled : true, |
|||
loading : true, |
|||
active : true |
|||
}, |
|||
button: { |
|||
disabled : true, |
|||
loading : true, |
|||
active : true, |
|||
}, |
|||
progress: { |
|||
active : true, |
|||
success : true, |
|||
warning : true, |
|||
error : true |
|||
} |
|||
}, |
|||
|
|||
states : { |
|||
active : true, |
|||
disabled : true, |
|||
error : true, |
|||
loading : true, |
|||
success : true, |
|||
warning : true |
|||
}, |
|||
|
|||
text : { |
|||
disabled : false, |
|||
flash : false, |
|||
hover : false, |
|||
active : false, |
|||
inactive : false, |
|||
activate : false, |
|||
deactivate : false |
|||
} |
|||
|
|||
}; |
|||
|
|||
|
|||
|
|||
})( jQuery, window, document ); |
@ -1,525 +0,0 @@ |
|||
/*! |
|||
* # Semantic UI - Visit |
|||
* http://github.com/semantic-org/semantic-ui/
|
|||
* |
|||
* |
|||
* Released under the MIT license |
|||
* http://opensource.org/licenses/MIT
|
|||
* |
|||
*/ |
|||
|
|||
;(function ($, window, document, undefined) { |
|||
|
|||
"use strict"; |
|||
|
|||
window = (typeof window != 'undefined' && window.Math == Math) |
|||
? window |
|||
: (typeof self != 'undefined' && self.Math == Math) |
|||
? self |
|||
: Function('return this')() |
|||
; |
|||
|
|||
$.visit = $.fn.visit = function(parameters) { |
|||
var |
|||
$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.visit.settings, parameters) |
|||
: $.extend({}, $.fn.visit.settings), |
|||
|
|||
error = settings.error, |
|||
namespace = settings.namespace, |
|||
|
|||
eventNamespace = '.' + namespace, |
|||
moduleNamespace = namespace + '-module', |
|||
|
|||
$module = $(this), |
|||
$displays = $(), |
|||
|
|||
element = this, |
|||
instance = $module.data(moduleNamespace), |
|||
module |
|||
; |
|||
module = { |
|||
|
|||
initialize: function() { |
|||
if(settings.count) { |
|||
module.store(settings.key.count, settings.count); |
|||
} |
|||
else if(settings.id) { |
|||
module.add.id(settings.id); |
|||
} |
|||
else if(settings.increment && methodInvoked !== 'increment') { |
|||
module.increment(); |
|||
} |
|||
module.add.display($module); |
|||
module.instantiate(); |
|||
}, |
|||
|
|||
instantiate: function() { |
|||
module.verbose('Storing instance of visit module', module); |
|||
instance = module; |
|||
$module |
|||
.data(moduleNamespace, module) |
|||
; |
|||
}, |
|||
|
|||
destroy: function() { |
|||
module.verbose('Destroying instance'); |
|||
$module |
|||
.removeData(moduleNamespace) |
|||
; |
|||
}, |
|||
|
|||
increment: function(id) { |
|||
var |
|||
currentValue = module.get.count(), |
|||
newValue = +(currentValue) + 1 |
|||
; |
|||
if(id) { |
|||
module.add.id(id); |
|||
} |
|||
else { |
|||
if(newValue > settings.limit && !settings.surpass) { |
|||
newValue = settings.limit; |
|||
} |
|||
module.debug('Incrementing visits', newValue); |
|||
module.store(settings.key.count, newValue); |
|||
} |
|||
}, |
|||
|
|||
decrement: function(id) { |
|||
var |
|||
currentValue = module.get.count(), |
|||
newValue = +(currentValue) - 1 |
|||
; |
|||
if(id) { |
|||
module.remove.id(id); |
|||
} |
|||
else { |
|||
module.debug('Removing visit'); |
|||
module.store(settings.key.count, newValue); |
|||
} |
|||
}, |
|||
|
|||
get: { |
|||
count: function() { |
|||
return +(module.retrieve(settings.key.count)) || 0; |
|||
}, |
|||
idCount: function(ids) { |
|||
ids = ids || module.get.ids(); |
|||
return ids.length; |
|||
}, |
|||
ids: function(delimitedIDs) { |
|||
var |
|||
idArray = [] |
|||
; |
|||
delimitedIDs = delimitedIDs || module.retrieve(settings.key.ids); |
|||
if(typeof delimitedIDs === 'string') { |
|||
idArray = delimitedIDs.split(settings.delimiter); |
|||
} |
|||
module.verbose('Found visited ID list', idArray); |
|||
return idArray; |
|||
}, |
|||
storageOptions: function(data) { |
|||
var |
|||
options = {} |
|||
; |
|||
if(settings.expires) { |
|||
options.expires = settings.expires; |
|||
} |
|||
if(settings.domain) { |
|||
options.domain = settings.domain; |
|||
} |
|||
if(settings.path) { |
|||
options.path = settings.path; |
|||
} |
|||
return options; |
|||
} |
|||
}, |
|||
|
|||
has: { |
|||
visited: function(id, ids) { |
|||
var |
|||
visited = false |
|||
; |
|||
ids = ids || module.get.ids(); |
|||
if(id !== undefined && ids) { |
|||
$.each(ids, function(index, value){ |
|||
if(value == id) { |
|||
visited = true; |
|||
} |
|||
}); |
|||
} |
|||
return visited; |
|||
} |
|||
}, |
|||
|
|||
set: { |
|||
count: function(value) { |
|||
module.store(settings.key.count, value); |
|||
}, |
|||
ids: function(value) { |
|||
module.store(settings.key.ids, value); |
|||
} |
|||
}, |
|||
|
|||
reset: function() { |
|||
module.store(settings.key.count, 0); |
|||
module.store(settings.key.ids, null); |
|||
}, |
|||
|
|||
add: { |
|||
id: function(id) { |
|||
var |
|||
currentIDs = module.retrieve(settings.key.ids), |
|||
newIDs = (currentIDs === undefined || currentIDs === '') |
|||
? id |
|||
: currentIDs + settings.delimiter + id |
|||
; |
|||
if( module.has.visited(id) ) { |
|||
module.debug('Unique content already visited, not adding visit', id, currentIDs); |
|||
} |
|||
else if(id === undefined) { |
|||
module.debug('ID is not defined'); |
|||
} |
|||
else { |
|||
module.debug('Adding visit to unique content', id); |
|||
module.store(settings.key.ids, newIDs); |
|||
} |
|||
module.set.count( module.get.idCount() ); |
|||
}, |
|||
display: function(selector) { |
|||
var |
|||
$element = $(selector) |
|||
; |
|||
if($element.length > 0 && !$.isWindow($element[0])) { |
|||
module.debug('Updating visit count for element', $element); |
|||
$displays = ($displays.length > 0) |
|||
? $displays.add($element) |
|||
: $element |
|||
; |
|||
} |
|||
} |
|||
}, |
|||
|
|||
remove: { |
|||
id: function(id) { |
|||
var |
|||
currentIDs = module.get.ids(), |
|||
newIDs = [] |
|||
; |
|||
if(id !== undefined && currentIDs !== undefined) { |
|||
module.debug('Removing visit to unique content', id, currentIDs); |
|||
$.each(currentIDs, function(index, value){ |
|||
if(value !== id) { |
|||
newIDs.push(value); |
|||
} |
|||
}); |
|||
newIDs = newIDs.join(settings.delimiter); |
|||
module.store(settings.key.ids, newIDs ); |
|||
} |
|||
module.set.count( module.get.idCount() ); |
|||
} |
|||
}, |
|||
|
|||
check: { |
|||
limit: function(value) { |
|||
value = value || module.get.count(); |
|||
if(settings.limit) { |
|||
if(value >= settings.limit) { |
|||
module.debug('Pages viewed exceeded limit, firing callback', value, settings.limit); |
|||
settings.onLimit.call(element, value); |
|||
} |
|||
module.debug('Limit not reached', value, settings.limit); |
|||
settings.onChange.call(element, value); |
|||
} |
|||
module.update.display(value); |
|||
} |
|||
}, |
|||
|
|||
update: { |
|||
display: function(value) { |
|||
value = value || module.get.count(); |
|||
if($displays.length > 0) { |
|||
module.debug('Updating displayed view count', $displays); |
|||
$displays.html(value); |
|||
} |
|||
} |
|||
}, |
|||
|
|||
store: function(key, value) { |
|||
var |
|||
options = module.get.storageOptions(value) |
|||
; |
|||
if(settings.storageMethod == 'localstorage' && window.localStorage !== undefined) { |
|||
window.localStorage.setItem(key, value); |
|||
module.debug('Value stored using local storage', key, value); |
|||
} |
|||
else if($.cookie !== undefined) { |
|||
$.cookie(key, value, options); |
|||
module.debug('Value stored using cookie', key, value, options); |
|||
} |
|||
else { |
|||
module.error(error.noCookieStorage); |
|||
return; |
|||
} |
|||
if(key == settings.key.count) { |
|||
module.check.limit(value); |
|||
} |
|||
}, |
|||
retrieve: function(key, value) { |
|||
var |
|||
storedValue |
|||
; |
|||
if(settings.storageMethod == 'localstorage' && window.localStorage !== undefined) { |
|||
storedValue = window.localStorage.getItem(key); |
|||
} |
|||
// get by cookie
|
|||
else if($.cookie !== undefined) { |
|||
storedValue = $.cookie(key); |
|||
} |
|||
else { |
|||
module.error(error.noCookieStorage); |
|||
} |
|||
if(storedValue == 'undefined' || storedValue == 'null' || storedValue === undefined || storedValue === null) { |
|||
storedValue = undefined; |
|||
} |
|||
return storedValue; |
|||
}, |
|||
|
|||
setting: function(name, value) { |
|||
if( $.isPlainObject(name) ) { |
|||
$.extend(true, settings, name); |
|||
} |
|||
else if(value !== undefined) { |
|||
settings[name] = value; |
|||
} |
|||
else { |
|||
return settings[name]; |
|||
} |
|||
}, |
|||
internal: function(name, value) { |
|||
module.debug('Changing internal', name, value); |
|||
if(value !== undefined) { |
|||
if( $.isPlainObject(name) ) { |
|||
$.extend(true, module, name); |
|||
} |
|||
else { |
|||
module[name] = value; |
|||
} |
|||
} |
|||
else { |
|||
return module[name]; |
|||
} |
|||
}, |
|||
debug: function() { |
|||
if(!settings.silent && 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.silent && 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() { |
|||
if(!settings.silent) { |
|||
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($allModules.length > 1) { |
|||
title += ' ' + '(' + $allModules.length + ')'; |
|||
} |
|||
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 { |
|||
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 |
|||
; |
|||
}; |
|||
|
|||
$.fn.visit.settings = { |
|||
|
|||
name : 'Visit', |
|||
|
|||
debug : false, |
|||
verbose : false, |
|||
performance : true, |
|||
|
|||
namespace : 'visit', |
|||
|
|||
increment : false, |
|||
surpass : false, |
|||
count : false, |
|||
limit : false, |
|||
|
|||
delimiter : '&', |
|||
storageMethod : 'localstorage', |
|||
|
|||
key : { |
|||
count : 'visit-count', |
|||
ids : 'visit-ids' |
|||
}, |
|||
|
|||
expires : 30, |
|||
domain : false, |
|||
path : '/', |
|||
|
|||
onLimit : function() {}, |
|||
onChange : function() {}, |
|||
|
|||
error : { |
|||
method : 'The method you called is not defined', |
|||
missingPersist : 'Using the persist setting requires the inclusion of PersistJS', |
|||
noCookieStorage : 'The default storage cookie requires $.cookie to be included.' |
|||
} |
|||
|
|||
}; |
|||
|
|||
})( jQuery, window, document ); |
Write
Preview
Loading…
Cancel
Save