12219 lines
456 KiB
JavaScript
12219 lines
456 KiB
JavaScript
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||
///////////////////////
|
||
|
||
WIDGETS = {}
|
||
WIDGETS_LINKED = {}
|
||
WIDGETS_BY_PATH = {}
|
||
SESSION = []
|
||
STATE = []
|
||
|
||
CLIPBOARD = null
|
||
EDITING = false
|
||
|
||
TRAVERSING = false
|
||
|
||
TABS = {}
|
||
|
||
|
||
MISC = {
|
||
iterators: {
|
||
widget:{},
|
||
tab:{}
|
||
}
|
||
}
|
||
|
||
|
||
PXSCALE = getComputedStyle(document.documentElement).getPropertyValue("--pixel-scale")
|
||
INITIALZOOM = PXSCALE
|
||
|
||
|
||
///////////////////////
|
||
|
||
$ = jQuery = require('./jquery/jquery.min')
|
||
require('./jquery/jquery.ui')
|
||
require('./jquery/jquery.drag')
|
||
require('./jquery/jquery.resize')
|
||
require('./jquery/jquery.fake-input')
|
||
|
||
///////////////////////
|
||
|
||
var callbacks = require('./app/callbacks')
|
||
|
||
var bindCallback = function(i) {
|
||
IPC.on(i,function(event,data){
|
||
callbacks[i](event,data)
|
||
})
|
||
}
|
||
|
||
for (i in callbacks) {
|
||
bindCallback(i)
|
||
}
|
||
|
||
///////////////////////
|
||
|
||
|
||
IPC.send('ready')
|
||
|
||
},{"./app/callbacks":3,"./jquery/jquery.drag":40,"./jquery/jquery.fake-input":41,"./jquery/jquery.min":42,"./jquery/jquery.resize":43,"./jquery/jquery.ui":44}],2:[function(require,module,exports){
|
||
module.exports = {
|
||
|
||
stateQuickSave: function(preset){
|
||
if (preset) {
|
||
STATE = preset
|
||
} else {
|
||
STATE = module.exports.stateGet()
|
||
}
|
||
$('.quickload').removeClass('disabled')
|
||
},
|
||
|
||
stateQuickLoad: function(){
|
||
module.exports.stateSet(STATE,true)
|
||
},
|
||
|
||
stateSave: function() {
|
||
state = JSON.stringify(module.exports.stateGet(),null,' ')
|
||
if (WEBFRAME) {
|
||
IPC.send('stateSave',state)
|
||
} else {
|
||
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.preset"></a>')
|
||
var blob = new Blob([state],{type : 'text/plain'});
|
||
down.attr('href', window.URL.createObjectURL(blob))
|
||
down[0].click()
|
||
}
|
||
|
||
},
|
||
|
||
stateGet: function (){
|
||
var data = []
|
||
for (i in WIDGETS) {
|
||
var widget = WIDGETS[i]
|
||
for (var j=widget.length-1;j>=0;j--) {
|
||
if (widget[j].setValue && widget[j].getValue) {
|
||
var v = widget[j].getValue()
|
||
if (v!=undefined) data.push([i,v])
|
||
break
|
||
}
|
||
}
|
||
}
|
||
return data
|
||
},
|
||
|
||
stateLoad: function() {
|
||
if (WEBFRAME) {
|
||
IPC.send('stateLoad')
|
||
} else {
|
||
var prompt = $('<input type="file" accept=".preset"/>')
|
||
prompt.click()
|
||
prompt.on('change',function(e){
|
||
var reader = new FileReader();
|
||
reader.onloadend = function(e) {
|
||
var preset = e.target.result
|
||
module.exports.stateSet(JSON.parse(preset),true)
|
||
STATE = preset
|
||
}
|
||
reader.readAsText(e.target.files[0],'utf-8');
|
||
})
|
||
}
|
||
},
|
||
|
||
stateSend: function(){
|
||
var data = module.exports.stateGet()
|
||
module.exports.stateSet(data,true)
|
||
|
||
},
|
||
|
||
stateSet: function(preset,send){
|
||
|
||
for (i in preset) {
|
||
var data = preset[i]
|
||
if (WIDGETS[data[0]]!=undefined) {
|
||
for (var i=WIDGETS[data[0]].length-1;i>=0;i--) {
|
||
if (WIDGETS[data[0]][i].setValue) {
|
||
WIDGETS[data[0]][i].setValue(data[1],send,true)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
|
||
toggleFullscreen: function(){
|
||
|
||
if (WEBFRAME) {
|
||
IPC.send('fullscreen')
|
||
} else {
|
||
var isInFullScreen = document.webkitIsFullScreen
|
||
|
||
if (isInFullScreen) {
|
||
document.webkitExitFullscreen()
|
||
} else {
|
||
document.documentElement.webkitRequestFullScreen()
|
||
}
|
||
}
|
||
},
|
||
|
||
sessionBrowse: function(){
|
||
|
||
if (WEBFRAME) {
|
||
IPC.send('sessionBrowse')
|
||
} else {
|
||
var prompt = $('<input type="file" accept=".js"/>')
|
||
prompt.click()
|
||
prompt.on('change',function(e){
|
||
var reader = new FileReader();
|
||
reader.onloadend = function(e) {
|
||
var session = e.target.result
|
||
IPC.send('sessionOpen',{file:session})
|
||
}
|
||
reader.readAsText(e.target.files[0],'utf-8');
|
||
})
|
||
}
|
||
},
|
||
|
||
sessionSave: function() {
|
||
var sessionfile = JSON.stringify(SESSION,null,' ')
|
||
if (WEBFRAME) {
|
||
IPC.send('sessionSave',sessionfile)
|
||
} else {
|
||
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.js"></a>')
|
||
var blob = new Blob([sessionfile],{type : 'text/plain'});
|
||
down.attr('href', window.URL.createObjectURL(blob))
|
||
down[0].click()
|
||
}
|
||
|
||
},
|
||
|
||
editorEnable: function(){
|
||
$('.editor-root').attr('data-tab','#container').removeClass('disabled')
|
||
$('.enable-editor').addClass('on')
|
||
$('.disable-editor').removeClass('on')
|
||
|
||
EDITING = true
|
||
},
|
||
editorDisable: function(){
|
||
$('.widget.ui-resizable').resizable('destroy')
|
||
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
|
||
$('.editing').removeClass('editing')
|
||
$('.editor-root').addClass('disabled')
|
||
$('.editor-container').remove()
|
||
$('.disable-editor').addClass('on')
|
||
$('.enable-editor').removeClass('on')
|
||
|
||
EDITING = false
|
||
},
|
||
|
||
traversingDisable: function(){
|
||
$('.traversingEnable, .traversingDisable').toggleClass('on')
|
||
$(document).trigger('disableTraversingGestures')
|
||
},
|
||
traversingEnable: function(){
|
||
$('.traversingEnable, .traversingDisable').toggleClass('on')
|
||
$(document).enableTraversingGestures()
|
||
}
|
||
|
||
}
|
||
|
||
},{}],3:[function(require,module,exports){
|
||
var init = require('./init'),
|
||
actions = require('./actions'),
|
||
utils = require('./utils'),
|
||
icon = utils.icon
|
||
|
||
module.exports = {
|
||
|
||
receiveOsc: function(event,data){
|
||
var data = data || event
|
||
|
||
// fetch ids corresponding to the osc path
|
||
var path = data.path,
|
||
pathref = path,
|
||
args = data.args
|
||
|
||
if (typeof data.args == 'object') {
|
||
for (var i=data.args.length-1;i>=0;i--) {
|
||
var ref = path+'||||'+data.args.slice(0,i).join('||||')
|
||
if (WIDGETS_BY_PATH[ref]) {
|
||
pathref = ref
|
||
args = data.args.slice(i,data.args.length)
|
||
args = args.length==1?args[0]:args
|
||
continue
|
||
}
|
||
}
|
||
} else {
|
||
args = data.args
|
||
}
|
||
for (i in WIDGETS_BY_PATH[pathref]) {
|
||
if (WIDGETS_BY_PATH[pathref][i]) WIDGETS_BY_PATH[pathref][i].setValue(args,false,true)
|
||
}
|
||
|
||
|
||
},
|
||
|
||
stateLoad: function(event,data){
|
||
var data = data || event
|
||
data = JSON.parse(data)
|
||
actions.stateSet(data,true)
|
||
actions.stateQuickSave(data)
|
||
},
|
||
|
||
sessionList: function(event,data){
|
||
var data = data || event
|
||
$('#lobby').append(`
|
||
<div class="main">
|
||
<div class="header">
|
||
Open Stage Control
|
||
</div>
|
||
<div class="list"></div>
|
||
<div class="footer"></div>
|
||
</div>`)
|
||
|
||
for (i in data) {
|
||
$('#lobby .list').append('<a class="btn load" data-session="'+data[i]+'">'+data[i]+'<span>'+icon('remove')+'</span></a>')
|
||
}
|
||
$('#lobby .footer').append('<a class="btn browse">'+icon('folder-open')+' Browse</a>')
|
||
$('#lobby .footer').append('<a class="btn new">'+icon('file-o')+' New</a>')
|
||
$('#lobby .load').click(function(e){
|
||
e.stopPropagation()
|
||
IPC.send('sessionOpen',{path:$(this).data('session')})
|
||
})
|
||
$('#lobby a span').click(function(e){
|
||
e.stopPropagation()
|
||
IPC.send('sessionRemoveFromHistory',$(this).parent().data('session'))
|
||
$(this).parents('a').remove()
|
||
})
|
||
$('#lobby .browse').click(function(e){
|
||
e.stopPropagation()
|
||
actions.sessionBrowse()
|
||
})
|
||
$('#lobby .new').click(function(e){
|
||
e.stopPropagation()
|
||
init([{}],function(){$('#open-toggle, .enable-editor').click();$('.editor-root').trigger('mousedown.editor')})
|
||
})
|
||
},
|
||
|
||
sessionOpen: function(event,data){
|
||
var data = data || event
|
||
var session = JSON.parse(data)
|
||
init(session)
|
||
|
||
},
|
||
|
||
error: function(event,data){
|
||
var data = data || event
|
||
|
||
utils.createPopup(icon('warning')+' '+data.title,data.text)
|
||
},
|
||
|
||
applyStyle: function(event,data){
|
||
var data = data || event
|
||
var style = document.createElement('style');
|
||
style.innerHTML = data.join('');
|
||
document.body.appendChild(style);
|
||
if (data.indexOf('--pixel-scale')!=-1) {
|
||
PXSCALE = data.match(/--pixel-scale\s*:\s*([^;]*)/)[1]
|
||
INITIALZOOM = PXSCALE
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
},{"./actions":2,"./init":9,"./utils":13}],4:[function(require,module,exports){
|
||
var correctPosition = function (m, parent){
|
||
var pos = m.offset(),
|
||
width = m.outerWidth(),
|
||
height = m.outerHeight(),
|
||
totalWidth = $('body').outerWidth(),
|
||
totalHeight = $('body').outerHeight(),
|
||
leftAdjust = parent=='body'?0:parent.outerWidth()-2
|
||
|
||
if (width + pos.left > totalWidth) {
|
||
m.css({'margin-left':totalWidth-(width + pos.left + leftAdjust)})
|
||
}
|
||
if (height + pos.top > totalHeight) {
|
||
m.css({'margin-top':totalHeight-(height + pos.top)})
|
||
}
|
||
}
|
||
|
||
var ev = 'fake-click'
|
||
|
||
|
||
var menu = function(e,actions,parent){
|
||
|
||
var m = $('<div class="context-menu"></div>')
|
||
if (parent=='body') {
|
||
m.css({top:e.pageY+'px',left:e.pageX+'px'})
|
||
}
|
||
|
||
for (label in actions) {
|
||
|
||
if (typeof actions[label] == 'object') {
|
||
|
||
var item = $(`<div class="item has-sub" tabIndex="1">${label}</div>`).appendTo(m).on(ev,function(e){e.stopPropagation()})
|
||
menu(e,actions[label],item)
|
||
|
||
|
||
} else {
|
||
|
||
$(`<div class="item">${label}</div>`).on(ev + '.editor',function(){
|
||
var callback = actions[label]
|
||
return function(e){
|
||
callback()
|
||
$('.context-menu').remove()
|
||
}
|
||
}()).appendTo(m)
|
||
}
|
||
}
|
||
|
||
m.appendTo(parent)
|
||
|
||
|
||
|
||
if (parent=='body') {
|
||
correctPosition(m,parent)
|
||
} else {
|
||
parent.hover(function(){correctPosition(m,parent)})
|
||
}
|
||
|
||
}
|
||
|
||
module.exports = menu
|
||
|
||
},{}],5:[function(require,module,exports){
|
||
var widgets = require('../widgets'),
|
||
widgetOptions = widgets.widgetOptions,
|
||
sync = widgets.sync,
|
||
parser = require('../parser')
|
||
parsewidgets = parser.widgets,
|
||
parsetabs = parser.tabs,
|
||
ui = require('../ui'),
|
||
actions = require('../actions'),
|
||
sidepanelCreateToggle = require('../sidepanel').createToggle,
|
||
editObject = function(a,b){require('./edit-objects').editObject(a,b,true)},
|
||
editSession = function(a,b){require('./edit-objects').editSession(a,b,true)},
|
||
purgeStores = require('./purge')
|
||
|
||
|
||
var getObjectData = function(obj){
|
||
var path = []
|
||
|
||
if (obj.hasClass('tab')) {
|
||
return TABS['#'+obj.attr('id')].data
|
||
}
|
||
|
||
if (obj.is('#container')) {
|
||
return SESSION
|
||
}
|
||
|
||
while(true) {
|
||
if (obj.hasClass('widget')) {
|
||
path.unshift(obj.index())
|
||
path.unshift('widgets')
|
||
} else if (obj.hasClass('tab')){
|
||
path.unshift(obj.data('index'))
|
||
path.unshift('tabs')
|
||
} else if (obj.is('#container')) {
|
||
break
|
||
}
|
||
|
||
obj = obj.parent()
|
||
}
|
||
|
||
path.splice(0,1)
|
||
|
||
for (var i=0,data=SESSION, path=path, len=path.length; i<len; i++){
|
||
data = data[path[i]]
|
||
}
|
||
|
||
return data
|
||
|
||
}
|
||
|
||
var updateDom = function(container,data) {
|
||
|
||
// save state
|
||
var scroll = $('#sidepanel').scrollTop(),
|
||
state = actions.stateGet(),
|
||
purgetabs = data.tabs?true:false
|
||
|
||
|
||
|
||
if (container.hasClass('widget')) {
|
||
// widget
|
||
var newContainer = parsewidgets([data],container.parent())
|
||
container.replaceWith(newContainer)
|
||
|
||
editObject(newContainer,data)
|
||
|
||
} else if (container.hasClass('tab')) {
|
||
// tab
|
||
var newContainer = container.empty()
|
||
|
||
if (data.widgets && data.widgets.length) parsewidgets(data.widgets,container)
|
||
if (data.tabs && data.tabs.length) {
|
||
parsetabs(data.tabs,container,false,data.label)
|
||
container.addClass('has-tabs')
|
||
} else {
|
||
container.removeClass('has-tabs')
|
||
}
|
||
|
||
$(`[data-tab="#${container.attr('id')}"]`).html(`<a><span>${data.label}</span></a>`)
|
||
|
||
editObject(newContainer,data)
|
||
|
||
} else if (container.attr('id')=='container') {
|
||
// session
|
||
var newContainer = $('#container')
|
||
container.empty()
|
||
parsetabs(data,container,true)
|
||
|
||
editSession(newContainer,data)
|
||
sidepanelCreateToggle()
|
||
|
||
}
|
||
|
||
newContainer.find('[data-tab]:first-child').click()
|
||
|
||
$(window).resize()
|
||
|
||
purgeStores(purgetabs)
|
||
|
||
// restore state
|
||
actions.stateSet(state,false)
|
||
sync()
|
||
ui.scrolls()
|
||
$('#sidepanel').scrollTop(scroll)
|
||
|
||
|
||
// return updated node
|
||
return newContainer
|
||
|
||
}
|
||
|
||
|
||
var incrementWidget = function(data){
|
||
|
||
if (!data) return
|
||
|
||
delete data.linkId
|
||
|
||
var id = data.id,
|
||
label = data.label,
|
||
path = data.path
|
||
|
||
if (id && id==label) {
|
||
data.label = 'auto'
|
||
}
|
||
if (id && path == '/'+id) {
|
||
|
||
data.path = 'auto'
|
||
|
||
} else if (path){
|
||
var pathref
|
||
while (WIDGETS_BY_PATH[pathref]) {
|
||
path = path.replace(/([0-9]*)$/,function(m){
|
||
var n = parseInt(m)+1
|
||
n = isNaN(n)?1:n
|
||
return n
|
||
})
|
||
pathref = data.preArgs&&data.preArgs.length?path+'||||'+data.preArgs.join('||||'):path
|
||
}
|
||
WIDGETS_BY_PATH[pathref] = []
|
||
data.path = path
|
||
|
||
}
|
||
|
||
if (id) {
|
||
while (WIDGETS[id]) {
|
||
id = id.replace(/([0-9]*)$/,function(m){
|
||
var n = parseInt(m)+1
|
||
n = isNaN(n)?1:n
|
||
return n
|
||
})
|
||
}
|
||
WIDGETS[id] = []
|
||
data.id = id
|
||
|
||
}
|
||
|
||
|
||
for (i in data) {
|
||
if (typeof data[i] == 'object') data[i] = incrementWidget(data[i])
|
||
}
|
||
|
||
return data
|
||
|
||
}
|
||
|
||
module.exports = {
|
||
updateDom:updateDom,
|
||
getObjectData:getObjectData,
|
||
incrementWidget:incrementWidget
|
||
}
|
||
|
||
},{"../actions":2,"../parser":10,"../sidepanel":11,"../ui":12,"../widgets":14,"./edit-objects":6,"./purge":8}],6:[function(require,module,exports){
|
||
var updateDom = require('./data-workers').updateDom,
|
||
widgetOptions = require('../widgets').widgetOptions
|
||
|
||
var ev = 'fake-click'
|
||
|
||
|
||
var editObject = function(container, data, refresh){
|
||
|
||
if (!refresh && (container.hasClass('editing') || $(`a[data-tab="#${container.attr('id')}"]`).hasClass('editing'))) return
|
||
|
||
var isWidget = container.hasClass('widget')
|
||
|
||
$('.editing').removeClass('editing')
|
||
$('.widget.ui-resizable').resizable('destroy')
|
||
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
|
||
|
||
|
||
if (isWidget) {
|
||
$(container).addClass('editing')
|
||
} else {
|
||
$(`[data-tab="#${container.attr('id')}"]`).addClass('editing').click()
|
||
$(container).parent().addClass('editing')
|
||
}
|
||
|
||
|
||
|
||
$('.editor-container').remove()
|
||
$('.editor').append('<div class="editor-container"></div>')
|
||
var form = $('<div class="form"></div>').appendTo('.editor-container')
|
||
|
||
|
||
var params = isWidget?widgetOptions[data.type]:{label:''}
|
||
|
||
for (i in params) {
|
||
|
||
if (i.indexOf('separator')!=-1) {
|
||
$(`<div class="separator"><span>${params[i]}</span></div>`).appendTo(form)
|
||
continue
|
||
} else if (data[i]===undefined) {
|
||
continue
|
||
}
|
||
|
||
// Common options edit
|
||
if (i!='widgets' && i!='tabs') {
|
||
|
||
var type = typeof data[i],
|
||
value = type == 'object'?JSON.stringify(data[i]):data[i],
|
||
wrapper = $('<div class="input-wrapper"></div>').appendTo(form),
|
||
label = $(`<label>${i}</label>`).appendTo(wrapper),
|
||
input
|
||
|
||
if (i=='type') {
|
||
|
||
input = $(`<select class="input" data-type="${type}" title="${i}"/>`)
|
||
|
||
for (t in widgetOptions) {
|
||
input.append(`<option ${t==value?'selected=':''} value="${t}">${t}</option>`)
|
||
}
|
||
select = $('<div class="select-wrapper"></div>').append(input)
|
||
select.appendTo(wrapper)
|
||
|
||
} else if (typeof params[i]=='boolean') {
|
||
|
||
input = $(`<input class="checkbox" data-type="${type}" value='${value}' title="${i}"/>`)
|
||
input.click(function(){
|
||
$(this).val(!eval($(this).val())).trigger('change')
|
||
})
|
||
input.appendTo(wrapper)
|
||
|
||
} else {
|
||
|
||
input = $(`<input data-type="${type}" value='${value}' title="${i}"/>`)
|
||
input.appendTo(wrapper)
|
||
|
||
}
|
||
|
||
|
||
input.on('change',function(){
|
||
// var v = $(this).val()!= '' && $(this).data('type') == 'object'?JSON.parse($(this).val()):$(this).val()
|
||
var v
|
||
try {
|
||
eval(`v=${$(this).val()}`)
|
||
} catch(err) {
|
||
v = $(this).val()
|
||
}
|
||
|
||
data[$(this).attr('title')] = v
|
||
if (v==='') delete data[$(this).attr('title')]
|
||
updateDom(container,data)
|
||
})
|
||
|
||
}
|
||
|
||
}
|
||
|
||
// widget list edit
|
||
if (((isWidget&&widgetOptions[data.type].widgets) || (container.hasClass('tab'))) && (!data.tabs||!data.tabs.length)) {
|
||
|
||
var list = $('<ul class="input"></ul>'),
|
||
wrapper = $('<div class="input-wrapper column"></div>').appendTo(form)
|
||
|
||
var editItem = function(i) {
|
||
return function(){
|
||
container.find('.widget').first().siblings().addBack().eq(i).trigger(ev)
|
||
}
|
||
}
|
||
|
||
for (i in data.widgets) {
|
||
|
||
|
||
var item = $(`<li data-index="${i}" class="sortables" data-id="${data.widgets[i].id}"><a class="btn small">${data.widgets[i].id||data.widgets[i].label}</a></li>`)
|
||
.appendTo(list)
|
||
.click(editItem(i))
|
||
|
||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||
.appendTo(item)
|
||
.click(function(e){
|
||
e.stopPropagation()
|
||
data.widgets.splice($(this).parent().attr('data-index'),1)
|
||
updateDom(container,data)
|
||
})
|
||
}
|
||
|
||
list.sortable({
|
||
forcePlaceholderSize: true,
|
||
items: '.sortables',
|
||
start:function(){$(this).sortable( "refreshPositions" )},
|
||
update: function(e,ui){
|
||
var prevIndex = $(ui.item).attr('data-index')
|
||
var newIndex = $(ui.item).index()
|
||
|
||
data.widgets.splice(newIndex, 0, data.widgets.splice(prevIndex, 1)[0])
|
||
|
||
updateDom(container,data)
|
||
}
|
||
})
|
||
|
||
var add = $(`<li><a class="btn small">+</a></li>`).appendTo(list).click(function(){
|
||
data.widgets = data.widgets || []
|
||
data.widgets.push({})
|
||
|
||
updateDom(container,data)
|
||
})
|
||
|
||
$('<label>widgets</label>').appendTo(wrapper)
|
||
list.appendTo(wrapper)
|
||
|
||
}
|
||
|
||
// tab list edit
|
||
if (((isWidget&&widgetOptions[data.type].tabs) || (container.hasClass('tab'))) && (!data.widgets||!data.widgets.length)) {
|
||
//tabs
|
||
var list = $('<ul class="input"></ul>'),
|
||
wrapper = $('<div class="input-wrapper column"></div>').appendTo(form)
|
||
|
||
|
||
var editItem = function(i) {
|
||
return function(){
|
||
container.find('.tab').first().siblings().addBack().eq(i).trigger(ev)
|
||
}
|
||
}
|
||
|
||
for (i in data.tabs) {
|
||
var item = $(`<li data-index="${i}" class="sortables"><a class="btn small">${data.tabs[i].label}</a></li>`)
|
||
.appendTo(list)
|
||
.click(editItem(i))
|
||
|
||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||
.appendTo(item)
|
||
.click(function(e){
|
||
e.stopPropagation()
|
||
data.tabs.splice($(this).parent().attr('data-index'),1)
|
||
updateDom(container,data)
|
||
})
|
||
}
|
||
|
||
list.sortable({
|
||
start:function(){$(this).sortable( "refreshPositions" )},
|
||
forcePlaceholderSize: true,
|
||
items: '.sortables',
|
||
update: function(e,ui){
|
||
var prevIndex = $(ui.item).attr('data-index')
|
||
var newIndex = $(ui.item).index()
|
||
|
||
data.tabs.splice(newIndex, 0, data.tabs.splice(prevIndex, 1)[0])
|
||
|
||
updateDom(container,data)
|
||
}
|
||
})
|
||
|
||
var add = $(`<li><a class="btn small">+</a></li>`).appendTo(list).click(function(){
|
||
data.tabs = data.tabs || []
|
||
data.tabs.push({})
|
||
|
||
updateDom(container,data)
|
||
})
|
||
|
||
$('<label>tabs</label>').appendTo(wrapper)
|
||
list.appendTo(wrapper)
|
||
}
|
||
|
||
if (data.hasOwnProperty('width')) {
|
||
var handleTarget
|
||
container.resizable({
|
||
handles:'s, e, se',
|
||
helper: "ui-helper",
|
||
start: function(event, ui){
|
||
handleTarget = $(event.originalEvent.target)
|
||
},
|
||
stop: function( event, ui ) {
|
||
if (handleTarget.hasClass('ui-resizable-se') || handleTarget.hasClass('ui-resizable-s')) data.height = Math.max(ui.size.height,30)/PXSCALE
|
||
if (handleTarget.hasClass('ui-resizable-se') || handleTarget.hasClass('ui-resizable-e')) data.width = Math.max(ui.size.width,30)/PXSCALE
|
||
updateDom(container,data)
|
||
}
|
||
})
|
||
}
|
||
|
||
if (data.hasOwnProperty('top')) {
|
||
container.draggable({
|
||
cursor:'-webkit-grabbing',
|
||
stop: function( event, ui ) {
|
||
event.preventDefault()
|
||
data.top = (ui.helper.position().top + container.parent().scrollTop())/PXSCALE
|
||
data.left = (ui.helper.position().left + container.parent().scrollLeft())/PXSCALE
|
||
ui.helper.remove()
|
||
updateDom(container,data)
|
||
},
|
||
handle:'.ui-draggable-handle, > .label',
|
||
snap:'.widget',
|
||
snapTolerance:5,
|
||
helper:function(){return $('<div class="ui-helper"></div>').css({height:container.outerHeight(),width:container.outerWidth()})}
|
||
}).append('<div class="ui-draggable-handle"></div>')
|
||
}
|
||
|
||
}
|
||
|
||
var editSession = function(container,data,refresh){
|
||
|
||
if (!refresh && $('.editor-root').hasClass('editing')) return
|
||
|
||
$('.widget.ui-resizable').resizable('destroy')
|
||
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
|
||
|
||
|
||
$('.editing').removeClass('editing')
|
||
$('.editor-root, #container').addClass('editing')
|
||
|
||
$('.editor-container').remove()
|
||
$('.editor').append('<div class="editor-container"></div>')
|
||
|
||
|
||
var form = $('<div class="form"></div>').appendTo('.editor-container'),
|
||
list = $('<ul class="input"></ul>'),
|
||
wrapper = $('<div class="input-wrapper column"></div>').appendTo(form)
|
||
|
||
|
||
var editItem = function(i) {
|
||
return function(){
|
||
container.find('.tab').first().siblings().addBack().eq(i).trigger(ev)
|
||
}
|
||
}
|
||
|
||
for (i in data) {
|
||
var item = $(`<li data-index="${i}" class="sortables"><a class="btn small">${data[i].label}</a></li>`)
|
||
.appendTo(list)
|
||
.click(editItem(i))
|
||
|
||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||
.appendTo(item)
|
||
.click(function(e){
|
||
e.stopPropagation()
|
||
data.splice($(this).parent().attr('data-index'),1)
|
||
updateDom(container,data)
|
||
})
|
||
}
|
||
|
||
|
||
list.sortable({
|
||
start:function(){$(this).sortable( "refreshPositions" )},
|
||
forcePlaceholderSize: true,
|
||
items: '.sortables',
|
||
update: function(e,ui){
|
||
var prevIndex = $(ui.item).attr('data-index')
|
||
var newIndex = $(ui.item).index()
|
||
|
||
data.splice(newIndex, 0, data.splice(prevIndex, 1)[0])
|
||
|
||
updateDom(container,data)
|
||
}
|
||
})
|
||
|
||
var add = $(`<li><a class="btn small">+</a></li>`).appendTo(list).click(function(){
|
||
data = data || []
|
||
data.push({})
|
||
|
||
updateDom(container,data)
|
||
})
|
||
|
||
$('<label>tabs</label>').appendTo(wrapper)
|
||
list.appendTo(wrapper)
|
||
|
||
|
||
$('.editor-container').append(form)
|
||
|
||
}
|
||
|
||
module.exports = {
|
||
editObject:editObject,
|
||
editSession:editSession
|
||
}
|
||
|
||
},{"../widgets":14,"./data-workers":5}],7:[function(require,module,exports){
|
||
var data = require('./data-workers'),
|
||
getObjectData = data.getObjectData,
|
||
updateDom = data.updateDom,
|
||
incrementWidget = data.incrementWidget,
|
||
edit = require('./edit-objects'),
|
||
editObject = edit.editObject,
|
||
editSession = edit.editSession,
|
||
createPopup = require('../utils').createPopup,
|
||
widgetOptions = require('../widgets').widgetOptions,
|
||
widgetCategories = require('../widgets').categories,
|
||
menu = require('./context-menu')
|
||
|
||
|
||
|
||
var init = function(){
|
||
|
||
$('body').off('.editor').on('fake-click fake-right-click',function(e,d){
|
||
|
||
if (!EDITING) return
|
||
|
||
// ignore mouse event when fired by a simulated touch event
|
||
if (e.type=='mousedown' && e.originalEvent.sourceCapabilities.firesTouchEvents) return
|
||
|
||
$('.context-menu').remove()
|
||
|
||
var target = $(e.target).is('.widget:not(.not-editable), .tab, [data-tab], #container')?
|
||
$(e.target):
|
||
$(e.target).closest('.widget:not(.not-editable), .tab, [data-tab], #container')
|
||
|
||
if (!target.length) return
|
||
|
||
var container = target.attr('data-tab')?TABS[target.attr('data-tab')].tab:target,
|
||
type = target.hasClass('widget')?'widget':'tab',
|
||
parent = container.parent(),
|
||
index = container.index(),
|
||
data = getObjectData(container)
|
||
|
||
if (container.attr('id')=='container') {
|
||
editSession(container,SESSION)
|
||
} else {
|
||
editObject(container,data)
|
||
}
|
||
|
||
|
||
if (e.type!='fake-right-click') return
|
||
|
||
if (container.attr('id')=='container') {
|
||
menu(d,{
|
||
'<i class="fa fa-plus"></i> Add tab': function(){
|
||
data.push({})
|
||
updateDom(container,data)
|
||
}
|
||
},'body')
|
||
|
||
return
|
||
}
|
||
|
||
|
||
var actions = {}
|
||
|
||
// actions['<i class="fa fa-edit"></i> Edit'] = function(){editObject(container,data)}
|
||
|
||
if (type=='widget') actions['<i class="fa fa-copy"></i> Copy'] = function(){CLIPBOARD=data}
|
||
|
||
if (type=='widget') actions['<i class="fa fa-cut"></i> Cut'] = function(){
|
||
CLIPBOARD=JSON.parse(JSON.stringify(data))
|
||
var parentContainer = container.parents('.widget, .tab, #container').first()
|
||
parentData = getObjectData(parentContainer)
|
||
|
||
parentData.widgets.splice(container.index(),1)
|
||
updateDom(parentContainer,parentData)
|
||
}
|
||
|
||
if (((type=='widget'&&widgetOptions[data.type].widgets) || (type=='tab')) && (!data.tabs||!data.tabs.length)) {
|
||
|
||
if (CLIPBOARD!=null) {
|
||
actions['<i class="fa fa-paste"></i> Paste'] = {
|
||
'<i class="fa fa-plus-circle"></i> ID + 1':function(){
|
||
data.widgets = data.widgets || []
|
||
var newData = incrementWidget(JSON.parse(JSON.stringify(CLIPBOARD)))
|
||
|
||
|
||
if (!target.attr('data-tab')) {
|
||
newData.top = d.offsetY
|
||
newData.left= d.offsetX
|
||
} else {
|
||
delete newData.top
|
||
delete newData.left
|
||
}
|
||
|
||
data.widgets.push(newData)
|
||
updateDom(container,data)
|
||
},
|
||
'<i class="fa fa-clone"></i> Clone':function(){
|
||
data.widgets = data.widgets || []
|
||
var newData = JSON.parse(JSON.stringify(CLIPBOARD))
|
||
if (!target.attr('data-tab')) {
|
||
newData.top = d.offsetY
|
||
newData.left= d.offsetX
|
||
} else {
|
||
delete newData.top
|
||
delete newData.left
|
||
}
|
||
data.widgets.push(newData)
|
||
updateDom(container,data)
|
||
}
|
||
}
|
||
}
|
||
|
||
actions['<i class="fa fa-plus"></i> Add widget'] = {}
|
||
var createFunction = function(widgetType,container,data){
|
||
return function() {
|
||
data.widgets = data.widgets || []
|
||
var newData = {type:widgetType}
|
||
if (!target.attr('data-tab')) {
|
||
newData.top = d.offsetY
|
||
newData.left= d.offsetX
|
||
}
|
||
data.widgets.push(newData)
|
||
updateDom(container,data)
|
||
}
|
||
}
|
||
for (category in widgetCategories) {
|
||
actions['<i class="fa fa-plus"></i> Add widget'][category] = {}
|
||
for (t in widgetCategories[category]) {
|
||
var wtype = widgetCategories[category][t]
|
||
actions['<i class="fa fa-plus"></i> Add widget'][category][wtype] = createFunction(wtype,container,data)
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
if (((type=='widget'&&widgetOptions[data.type].tabs) || (type=='tab')) && (!data.widgets||!data.widgets.length)) {
|
||
|
||
actions['<i class="fa fa-plus"></i> Add tab'] = function(){
|
||
data.tabs = data.tabs || []
|
||
data.tabs.push({})
|
||
updateDom(container,data)
|
||
}
|
||
|
||
}
|
||
|
||
actions['<i class="fa fa-trash"></i> Delete'] = function(){
|
||
var popup = createPopup('Are you sure ?',`
|
||
<div class="actions">
|
||
<div class="btn warning confirm-delete">DELETE</div>
|
||
<div class="btn cancel-delete">CANCEL</div>
|
||
</div>
|
||
`)
|
||
$('.confirm-delete').click(function(){
|
||
popup.close()
|
||
var parentContainer = container.parents('.widget, .tab, #container').first()
|
||
parentData = getObjectData(parentContainer)
|
||
|
||
|
||
if (type=='widget') {
|
||
parentData.widgets.splice(container.index(),1)
|
||
} else if (type=='tab' && parentContainer.attr('id')!='container') {
|
||
parentData.tabs.splice(container.data('index'),1)
|
||
} else {
|
||
parentData.splice(container.data('index'),1)
|
||
}
|
||
|
||
updateDom(parentContainer,parentData)
|
||
})
|
||
$('.cancel-delete').click(function(){
|
||
popup.close()
|
||
})
|
||
$(document).on('keydown.popup', function(e){
|
||
if (e.keyCode==13) $('.confirm-delete').click()
|
||
})
|
||
|
||
|
||
}
|
||
|
||
menu(d,actions,'body')
|
||
|
||
})
|
||
|
||
}
|
||
|
||
module.exports = init
|
||
|
||
},{"../utils":13,"../widgets":14,"./context-menu":4,"./data-workers":5,"./edit-objects":6}],8:[function(require,module,exports){
|
||
module.exports = function(purgetabs) {
|
||
|
||
// prune tabs store
|
||
var count, newcount, formerBuffuredTabs, bufferedTabs
|
||
|
||
if (purgetabs) {
|
||
while (true) {
|
||
// we need to do that several times since tabs are referenced in each of their parents
|
||
|
||
// get all buffered tabs
|
||
formerBuffuredTabs = []
|
||
for (i in TABS) {
|
||
formerBuffuredTabs.push(TABS[i].tab[0])
|
||
}
|
||
|
||
// remove deleted tabs that are not referenced (have no navigation link pointing to them)
|
||
var $f = $(formerBuffuredTabs)
|
||
for (i in TABS) {
|
||
if (!($f.find(`[data-tab="${i}"]`).length || i== '#container')) {
|
||
delete TABS[i]
|
||
}
|
||
}
|
||
|
||
newcount = Object.keys(TABS).length
|
||
if (count == newcount) break
|
||
count = newcount
|
||
|
||
}
|
||
}
|
||
|
||
|
||
bufferedTabs = []
|
||
for (i in TABS) {
|
||
bufferedTabs.push(TABS[i].tab[0])
|
||
}
|
||
|
||
// prune widget stores
|
||
// if widgets cannot be found in buffered tabs, it must be unreferenced
|
||
var $b = $(bufferedTabs)
|
||
for (i in WIDGETS) {
|
||
for (var j=WIDGETS[i].length-1;j>=0;j--) {
|
||
if (!$b.find(WIDGETS[i][j]).length) {
|
||
WIDGETS[i].splice(j,1)
|
||
}
|
||
}
|
||
if (!WIDGETS[i].length) {
|
||
delete WIDGETS[i]
|
||
}
|
||
}
|
||
for (i in WIDGETS_LINKED) {
|
||
for (var j=WIDGETS_LINKED[i].length-1;j>=0;j--) {
|
||
if (!$b.find(WIDGETS_LINKED[i][j]).length) {
|
||
WIDGETS_LINKED[i].splice(j,1)
|
||
}
|
||
}
|
||
if (!WIDGETS_LINKED[i].length) {
|
||
delete WIDGETS_LINKED[i]
|
||
}
|
||
}
|
||
for (i in WIDGETS_BY_PATH) {
|
||
for (var j=WIDGETS_BY_PATH[i].length-1;j>=0;j--) {
|
||
if (!$b.find(WIDGETS_BY_PATH[i][j]).length) {
|
||
WIDGETS_BY_PATH[i].splice(j,1)
|
||
}
|
||
}
|
||
if (!WIDGETS_BY_PATH[i].length) {
|
||
delete WIDGETS_BY_PATH[i]
|
||
}
|
||
}
|
||
}
|
||
|
||
},{}],9:[function(require,module,exports){
|
||
var parsetabs = require('./parser').tabs,
|
||
ui = require('./ui'),
|
||
sync = require('./widgets').sync,
|
||
editorDisable = require('./actions').editorDisable,
|
||
editorInit = require('./editor/init')
|
||
|
||
module.exports = function(session,callback) {
|
||
|
||
$('#lobby').remove()
|
||
$('#container').empty()
|
||
var spinner = $('<div id="loading"><div class="spinner"></div></div>').appendTo('#container')
|
||
|
||
setTimeout(function(){
|
||
parsetabs(session,$('#container'),true)
|
||
|
||
// var t = $('<div></div>').appendTo('body')
|
||
// for (id in TABS) {
|
||
// if (id!='#container') {
|
||
// t[0].appendChild(TABS[id].tab[0])
|
||
// }
|
||
// }
|
||
// setTimeout(function(){
|
||
// t.detach()
|
||
// },250)
|
||
|
||
|
||
ui.init()
|
||
editorDisable()
|
||
editorInit()
|
||
sync()
|
||
|
||
|
||
setTimeout(function(){
|
||
spinner.remove()
|
||
if (!callback) return
|
||
setTimeout(function(){
|
||
callback()
|
||
},25)
|
||
},25)
|
||
},25)
|
||
|
||
}
|
||
|
||
},{"./actions":2,"./editor/init":7,"./parser":10,"./ui":12,"./widgets":14}],10:[function(require,module,exports){
|
||
var widgets = require('./widgets'),
|
||
widgetOptions = widgets.widgetOptions,
|
||
createWidget = widgets.createWidget,
|
||
icon = require('./utils').icon
|
||
|
||
var getIterator = function(id,type){
|
||
var iterator = MISC.iterators[type]
|
||
if (iterator[id]==undefined) iterator[id] = 0
|
||
iterator[id] += 1
|
||
return iterator[id]
|
||
}
|
||
|
||
var hashCode = function(s){
|
||
return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
|
||
}
|
||
|
||
module.exports.tabs = function(data,parent,main,parentLabel){
|
||
|
||
if (main) {
|
||
// Reset Globals
|
||
WIDGETS = {}
|
||
WIDGETS_LINKED = {}
|
||
WIDGETS_BY_PATH = {}
|
||
SESSION = data
|
||
for (i in TABS) {
|
||
if (i!='#container') {
|
||
TABS[i].parent.remove()
|
||
TABS[i].tab.remove()
|
||
}
|
||
}
|
||
TABS['#container'] = {
|
||
tab:$('#container')
|
||
}
|
||
|
||
MISC.iterators.tab = {}
|
||
}
|
||
|
||
var main = main?'main ':'',
|
||
nav = $(document.createElement('div')).addClass(main + 'navigation'),
|
||
navtabs = $(document.createElement('ul')).addClass('tablist'),
|
||
content = $(document.createElement('div')).addClass('content')
|
||
|
||
|
||
for (i in data) {
|
||
var tabData = data[i]
|
||
|
||
|
||
var label = tabData.label||tabData.id||'Unnamed',
|
||
hash = hashCode(label),
|
||
id = 'tab_'+hash+'_'+getIterator('tab'+hash,'tab')
|
||
|
||
tabData.label = label
|
||
delete tabData.id
|
||
|
||
navtabs.append(`<li data-tab="#${id}"><a><span>${label}</span></a></li>`)
|
||
|
||
var tabContent = $(`<div class="tab ${tabData.tabs&&tabData.tabs.length?'has-tabs':''}" id="${id}" data-index="${i}"></div>`)
|
||
tabContent.data(tabData)
|
||
|
||
|
||
if (tabData.tabs && tabData.tabs.length) {
|
||
module.exports.tabs(tabData.tabs,tabContent,false,label)
|
||
} else if (tabData.widgets && tabData.widgets.length) {
|
||
module.exports.widgets(tabData.widgets,tabContent)
|
||
}
|
||
|
||
// content.append(tabContent)
|
||
TABS['#'+id]= {
|
||
parent:content,
|
||
tab:tabContent,
|
||
data:tabData
|
||
}
|
||
|
||
}
|
||
|
||
nav[0].appendChild(navtabs[0])
|
||
parent[0].appendChild(nav[0])
|
||
parent[0].appendChild(content[0])
|
||
}
|
||
|
||
|
||
|
||
module.exports.widgets = function(data,parent) {
|
||
|
||
for (i in data) {
|
||
var widgetData = data[i]
|
||
|
||
widgetData.type = widgetData.type || 'fader'
|
||
|
||
var tmpWidgetOptions = JSON.parse(JSON.stringify(widgetOptions))
|
||
|
||
for (i in tmpWidgetOptions[widgetData.type]) {
|
||
if (i.indexOf('separator')==-1 && widgetData[i]===undefined) widgetData[i] = tmpWidgetOptions[widgetData.type][i]
|
||
}
|
||
|
||
if (widgetData.id=='auto') {
|
||
var id
|
||
while (!id || WIDGETS[id]) {
|
||
id=widgetData.type+'_'+getIterator(widgetData.type,'widget')
|
||
}
|
||
widgetData.id = id
|
||
}
|
||
|
||
widgetData.path = widgetData.path=='auto'?'/' + widgetData.id:widgetData.path
|
||
widgetData.target = widgetData.target?(Array.isArray(widgetData.target)?widgetData.target:[widgetData.target]):false
|
||
|
||
for (i in widgetData) {
|
||
if (widgetOptions[widgetData.type][i]===undefined && i!='type') {delete widgetData[i]}
|
||
}
|
||
|
||
|
||
for (t in {width:'',height:'',top:'',left:''}) {
|
||
widgetData[t] = `${widgetData[t]}`.indexOf('-')!=-1?0:widgetData[t]
|
||
}
|
||
|
||
if (parent.hasClass('strip')) {
|
||
delete widgetData.top
|
||
delete widgetData.left
|
||
}
|
||
|
||
if (widgetData.preArgs!=undefined) {
|
||
widgetData.preArgs = Array.isArray(widgetData.preArgs)?widgetData.preArgs:[widgetData.preArgs]
|
||
}
|
||
if (widgetData.target!=undefined) {
|
||
widgetData.target = Array.isArray(widgetData.target)?widgetData.target:[widgetData.target]
|
||
}
|
||
|
||
var width = parseFloat(widgetData.width)==widgetData.width?parseFloat(widgetData.width)+'rem' : widgetData.width,
|
||
height = parseFloat(widgetData.height)==widgetData.height?parseFloat(widgetData.height)+'rem' : widgetData.height,
|
||
left = parseFloat(widgetData.left)==widgetData.left?parseFloat(widgetData.left)+'rem' : widgetData.left,
|
||
top = parseFloat(widgetData.top)==widgetData.top?parseFloat(widgetData.top)+'rem' : widgetData.top
|
||
|
||
|
||
var styleW = widgetData.width&&widgetData.width!='auto'?`width:${width};min-width:auto;`:'',
|
||
styleH = widgetData.height&&widgetData.height!='auto'?`height:${height};min-height:auto;`:'',
|
||
styleL = widgetData.left&&widgetData.left!='auto'||widgetData.left==0?`left:${left};`:'',
|
||
styleT = widgetData.top&&widgetData.top!='auto'||widgetData.top==0?`top:${top};`:''
|
||
|
||
var label = widgetData.label == 'auto'?
|
||
widgetData.id:
|
||
typeof widgetData.label == 'string' && widgetData.label.indexOf('icon:')!=-1?
|
||
icon(widgetData.label.split(':')[1].trim().replace('fa-','')):
|
||
widgetData.label
|
||
|
||
var widgetContainer = $(`
|
||
<div class="widget ${widgetData.type}-container ${styleL.length || styleT.length?'absolute-position':''}" style="${styleW + styleH + styleL + styleT + widgetData.css}">
|
||
<div class="label"><span>${label}</span></div>
|
||
</div>
|
||
`)
|
||
|
||
if (widgetData.color && widgetData.color!='auto') widgetContainer[0].style.setProperty('--color-custom',widgetData.color)
|
||
|
||
if (widgetData.label===false) widgetContainer.addClass('nolabel')
|
||
|
||
// create widget
|
||
var widgetInner = createWidget[widgetData.type](widgetData,widgetContainer)
|
||
|
||
|
||
widgetContainer[0].appendChild(widgetInner[0])
|
||
|
||
// store widget reference for cross widget sync
|
||
if (WIDGETS[widgetData.id]==undefined) WIDGETS[widgetData.id] = []
|
||
WIDGETS[widgetData.id].push(widgetInner)
|
||
|
||
// store widget with linkId for widgte linking
|
||
if (widgetData.linkId && widgetData.linkId.length) {
|
||
if (WIDGETS_LINKED[widgetData.linkId]==undefined) WIDGETS_LINKED[widgetData.linkId] = []
|
||
WIDGETS_LINKED[widgetData.linkId].push(widgetInner)
|
||
}
|
||
|
||
// store widget by path and encode preArgs for perfect cross-app sync
|
||
if (widgetData.path) {
|
||
var pathref = widgetData.preArgs&&widgetData.preArgs.length?widgetData.path+'||||'+widgetData.preArgs.join('||||'):widgetData.path
|
||
if (WIDGETS_BY_PATH[pathref]==undefined) WIDGETS_BY_PATH[pathref] = []
|
||
WIDGETS_BY_PATH[pathref].push(widgetInner)
|
||
}
|
||
|
||
parent[0].appendChild(widgetContainer[0])
|
||
}
|
||
|
||
// Editor needs to get the container object
|
||
if (data && data.length==1) return widgetContainer
|
||
|
||
}
|
||
|
||
},{"./utils":13,"./widgets":14}],11:[function(require,module,exports){
|
||
var actions = require('./actions'),
|
||
icon = require('./utils').icon
|
||
|
||
var data = [
|
||
{
|
||
actions: [
|
||
{
|
||
title:'Fullscreen (F11)',
|
||
action:actions.toggleFullscreen
|
||
}
|
||
|
||
]
|
||
},
|
||
{
|
||
title: icon('sliders') + ' State',
|
||
actions: [
|
||
{
|
||
title:'Store',
|
||
action:actions.stateQuickSave
|
||
},
|
||
{
|
||
title:'Recall',
|
||
action:actions.stateQuickLoad,
|
||
class:'disabled quickload'
|
||
},
|
||
{
|
||
title:'Send All',
|
||
action:actions.stateSend
|
||
},
|
||
{
|
||
title:'Import',
|
||
action:actions.stateLoad
|
||
},
|
||
{
|
||
title:'Export',
|
||
action:actions.stateSave
|
||
}
|
||
]
|
||
},
|
||
{
|
||
title: icon('magic') + ' Traversing gestures',
|
||
actions: [
|
||
{
|
||
title:'On',
|
||
action:actions.traversingEnable,
|
||
class:'traversingEnable'
|
||
},
|
||
{
|
||
title:'Off',
|
||
action:actions.traversingDisable,
|
||
class:'traversingDisable on'
|
||
}
|
||
]
|
||
},
|
||
{
|
||
title: icon('edit') + ' Editor',
|
||
class:'editor',
|
||
actions: [
|
||
{
|
||
title:'On',
|
||
action:actions.editorEnable,
|
||
class:'enable-editor'
|
||
},
|
||
{
|
||
title:'Off',
|
||
action:actions.editorDisable,
|
||
class:'on disable-editor'
|
||
},
|
||
{
|
||
title:'Root',
|
||
class:'editor-root disabled'
|
||
},
|
||
{
|
||
title:'Load',
|
||
action:actions.sessionBrowse
|
||
},
|
||
{
|
||
title:'Save',
|
||
action:actions.sessionSave
|
||
}
|
||
]
|
||
},
|
||
]
|
||
|
||
var sidepanel = function(data){
|
||
|
||
var bindAction = function(el,callback) {
|
||
el.click(function(){callback()})
|
||
}
|
||
|
||
var html = $('<ul id="options"></ul>')
|
||
|
||
for (i in data) {
|
||
var itemData = data[i]
|
||
|
||
var item = $('<li></li>'),
|
||
inner = $('<div></div>').appendTo(item)
|
||
wrapper = $('<div class="actions"></div>').appendTo(inner)
|
||
|
||
if (itemData.title) $('<div class="title">'+itemData.title+'</div>').prependTo(wrapper)
|
||
if (itemData.class) inner.attr('class',itemData.class)
|
||
|
||
for (j in itemData.actions) {
|
||
var actionData = itemData.actions[j]
|
||
var el = $('<a class="btn">'+actionData.title+'</a>').appendTo(wrapper)
|
||
if (actionData.action) bindAction(el, actionData.action)
|
||
|
||
if (actionData.class) el.addClass(actionData.class)
|
||
|
||
}
|
||
item.appendTo(html)
|
||
|
||
}
|
||
|
||
return html
|
||
|
||
}(data)
|
||
|
||
var toggle = function(){
|
||
$(`<li><a id="open-toggle">${icon('navicon')}</a></li>`).appendTo('.navigation.main ul').click(function(e){
|
||
var t = 0
|
||
if (!$('#sidepanel').hasClass('sidepanel-open')) t = 250
|
||
|
||
$('#open-toggle, #sidepanel').toggleClass('sidepanel-open')
|
||
setTimeout(function(){
|
||
$('#container').toggleClass('sidepanel-open')
|
||
$(window).resize()
|
||
},t)
|
||
}).on('mousedown touchstart',function(e){e.stopPropagation()})
|
||
|
||
// in case where are hot loading a session
|
||
if ($('#sidepanel').hasClass('sidepanel-open')) {
|
||
$('#open-toggle, #container').addClass('sidepanel-open')
|
||
}
|
||
}
|
||
|
||
module.exports = {
|
||
init:function(){
|
||
$('#sidepanel').append(sidepanel)
|
||
toggle()
|
||
},
|
||
createToggle:toggle
|
||
}
|
||
|
||
},{"./actions":2,"./utils":13}],12:[function(require,module,exports){
|
||
var actions = require('./actions'),
|
||
icon = require('./utils').icon
|
||
|
||
var sidepanel = require('./sidepanel').init
|
||
|
||
// Tabs...
|
||
var tabs = function() {
|
||
$('#container').click(function(e){
|
||
var link = e.target
|
||
|
||
if (!link.hasAttribute('data-tab') || link.classList.contains('on')) return
|
||
|
||
var id = link.getAttribute('data-tab')
|
||
|
||
link.classList.add('on')
|
||
|
||
var previous = $(link).siblings('.on').removeClass('on').data('tab')
|
||
|
||
// TABS[id].tab.appendTo(TABS[id].parent)
|
||
TABS[id].parent[0].appendChild(TABS[id].tab[0])
|
||
$(previous).detach()
|
||
|
||
|
||
$(id).find('li[data-tab]:first-child, li.parent + li[data-tab]').each(function(){
|
||
if (!$(this).siblings('.on').length) $(this).click()
|
||
})
|
||
|
||
$(window).resize()
|
||
|
||
})
|
||
$('li[data-tab]').first().click()
|
||
}
|
||
|
||
// horizontal scrolling & zoom with mousewheel
|
||
// if shift is pressed (native), or if there is no vertical scrollbar,
|
||
// or if mouse is on h-scrollbar
|
||
var scrollbarHeight = 20
|
||
var scrolls = function(){
|
||
$('html').on('mousewheel.zoom',function(e) {
|
||
// console.log(e)
|
||
if (e.ctrlKey) {
|
||
e.preventDefault()
|
||
if (e.originalEvent.deltaY==0) return
|
||
var d = -e.originalEvent.deltaY/(10*Math.abs(e.originalEvent.deltaY))
|
||
|
||
PXSCALE = parseFloat(d)+parseFloat(PXSCALE)
|
||
document.documentElement.style.setProperty("--pixel-scale",'')
|
||
document.documentElement.style.setProperty("--pixel-scale",PXSCALE)
|
||
|
||
}
|
||
})
|
||
$(document).on('keydown.resetzoom', function(e){
|
||
if (e.keyCode==96||e.keyCode==48) {
|
||
PXSCALE = INITIALZOOM
|
||
document.documentElement.style.setProperty("--pixel-scale",'')
|
||
document.documentElement.style.setProperty("--pixel-scale",PXSCALE)
|
||
}
|
||
})
|
||
|
||
}
|
||
|
||
|
||
module.exports = {
|
||
init: function(){
|
||
sidepanel()
|
||
tabs()
|
||
scrolls()
|
||
},
|
||
tabs:tabs,
|
||
scrolls:scrolls
|
||
}
|
||
|
||
},{"./actions":2,"./sidepanel":11,"./utils":13}],13:[function(require,module,exports){
|
||
module.exports = {
|
||
|
||
createPopup: function(title,content) {
|
||
|
||
var popup = $(`
|
||
<div class="popup">
|
||
<div class="popup-wrapper">
|
||
<div class="popup-title">${title}<span class="closer">${module.exports.icon('remove')}</span></div>
|
||
<div class="popup-content"></div>
|
||
</div>
|
||
</div>`),
|
||
closer = popup.find('.popup-title .closer')
|
||
|
||
closer.click(function(){
|
||
popup.close()
|
||
})
|
||
|
||
|
||
popup.close = function(){
|
||
$(document).off('.popup')
|
||
popup.remove()
|
||
}
|
||
|
||
popup.find('.popup-content').append(content)
|
||
$('body').append(popup)
|
||
|
||
$(document).on('keydown.popup', function(e){
|
||
if (e.keyCode==27) popup.close()
|
||
})
|
||
|
||
|
||
|
||
return popup
|
||
},
|
||
icon: function(i) {
|
||
return `<i class="fa fa-fw fa-${i}"></i>`
|
||
}
|
||
|
||
}
|
||
|
||
},{}],14:[function(require,module,exports){
|
||
var widgets = {
|
||
// sliders
|
||
fader: require('./widgets/sliders/fader'),
|
||
knob: require('./widgets/knob'),
|
||
|
||
// buttons
|
||
toggle: require('./widgets/toggle'),
|
||
switch: require('./widgets/switch'),
|
||
push: require('./widgets/push'),
|
||
|
||
// pads
|
||
xy: require('./widgets/xy'),
|
||
rgb: require('./widgets/rgb'),
|
||
|
||
// matrices
|
||
multitoggle: require('./widgets/multitoggle'),
|
||
multipush: require('./widgets/multipush'),
|
||
multifader: require('./widgets/multifader'),
|
||
|
||
// plots
|
||
led: require('./widgets/plots/led'),
|
||
plot: require('./widgets/plots/plot'),
|
||
eq: require('./widgets/plots/eq'),
|
||
visualizer: require('./widgets/plots/visualizer'),
|
||
meter: require('./widgets/plots/meter'),
|
||
text: require('./widgets/plots/text'),
|
||
|
||
// containers
|
||
strip: require('./widgets/strip'),
|
||
panel: require('./widgets/panel'),
|
||
}
|
||
|
||
module.exports.categories = {
|
||
'Sliders':['fader','knob'],
|
||
'Buttons':['toggle','push','switch'],
|
||
'Pads':['xy','rgb'],
|
||
'Matrices':['multifader','multitoggle','multipush'],
|
||
'Plots':['plot','eq','visualizer','led','meter','text'],
|
||
'Containers':['panel','strip']
|
||
}
|
||
|
||
module.exports.widgetOptions = function(){
|
||
var r = {}
|
||
for (i in widgets) {
|
||
r[i] = widgets[i].options
|
||
}
|
||
return r
|
||
}()
|
||
|
||
module.exports.createWidget = function(){
|
||
var r = {}
|
||
for (i in widgets) {
|
||
r[i] = widgets[i].create
|
||
}
|
||
return r
|
||
}()
|
||
|
||
module.exports.sync = function() {
|
||
$('body').off('sync.global').on('sync.global',function(e,id,widget,linkId){
|
||
// Widget that share the same id will update each other
|
||
// without sending any extra osc message
|
||
if (WIDGETS[id] && WIDGETS[id].length>1) {
|
||
var v = widget.getValue()
|
||
for (i in WIDGETS[id]) {
|
||
if (!WIDGETS[id][i].is(widget) && WIDGETS[id][i].setValue) {
|
||
WIDGETS[id][i].setValue(v,false,false)
|
||
}
|
||
}
|
||
}
|
||
// widgets that share the same linkId will update each other.
|
||
// Updated widgets will send osc messages normally
|
||
if (WIDGETS_LINKED[linkId] && WIDGETS_LINKED[linkId].length>1) {
|
||
var v = widget.getValue()
|
||
for (i in WIDGETS_LINKED[linkId]) {
|
||
if (!WIDGETS_LINKED[linkId][i].is(widget) && WIDGETS_LINKED[linkId][i].setValue) {
|
||
WIDGETS_LINKED[linkId][i].setValue(v,true,false)
|
||
}
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|
||
},{"./widgets/knob":17,"./widgets/multifader":18,"./widgets/multipush":19,"./widgets/multitoggle":20,"./widgets/panel":21,"./widgets/plots/eq":24,"./widgets/plots/led":25,"./widgets/plots/meter":26,"./widgets/plots/plot":27,"./widgets/plots/text":28,"./widgets/plots/visualizer":29,"./widgets/push":30,"./widgets/rgb":31,"./widgets/sliders/fader":33,"./widgets/strip":34,"./widgets/switch":35,"./widgets/toggle":36,"./widgets/xy":38}],15:[function(require,module,exports){
|
||
var _widgets_base = require('./_widgets_base')
|
||
|
||
var _canvas_base = module.exports = function() {
|
||
|
||
_widgets_base.apply(this,arguments)
|
||
|
||
this.canvas = this.widget.find('canvas')
|
||
this.ctx = this.canvas[0].getContext('2d')
|
||
|
||
this.height = undefined
|
||
this.width = undefined
|
||
|
||
this.visible = false
|
||
|
||
this.colors = {}
|
||
this.textColor = getComputedStyle(document.documentElement).getPropertyValue('--color-text-fade')
|
||
|
||
|
||
this.canvas.resize(this.resizeHandleProxy.bind(this))
|
||
|
||
|
||
}
|
||
|
||
|
||
_canvas_base.prototype = Object.create(_widgets_base.prototype)
|
||
|
||
_canvas_base.prototype.constructor = _canvas_base
|
||
|
||
_canvas_base.prototype.resizeHandleProxy = function() {
|
||
this.resizeHandle.apply(this,arguments)
|
||
}
|
||
|
||
_canvas_base.prototype.resizeHandle = function(){
|
||
|
||
var width = this.canvas.width(),
|
||
height = this.canvas.height()
|
||
|
||
if (height==100 && width==100) return
|
||
|
||
|
||
this.height=height
|
||
this.width=width
|
||
|
||
this.canvas[0].setAttribute('width',width)
|
||
this.canvas[0].setAttribute('height',height)
|
||
|
||
if (!self.visible) {
|
||
this.visible = true
|
||
this.colors.accent = getComputedStyle(this.widget[0]).getPropertyValue('--color-custom')
|
||
this.colors.text = getComputedStyle(this.widget[0]).getPropertyValue('--color-text')
|
||
this.colors.raised = getComputedStyle(this.widget[0]).getPropertyValue('--color-raised')
|
||
this.colors.bg = getComputedStyle(this.widget[0]).getPropertyValue('--color-bg')
|
||
this.colors.fg = getComputedStyle(this.widget[0]).getPropertyValue('--color-fg')
|
||
this.colors.faded = getComputedStyle(this.widget[0]).getPropertyValue('--color-faded')
|
||
}
|
||
|
||
requestAnimationFrame(this.draw.bind(this))
|
||
|
||
}
|
||
|
||
_canvas_base.prototype.draw = function(){
|
||
//
|
||
}
|
||
|
||
},{"./_widgets_base":16}],16:[function(require,module,exports){
|
||
var _widget_base = module.exports = function(widgetData) {
|
||
this.widgetData = widgetData
|
||
}
|
||
|
||
},{}],17:[function(require,module,exports){
|
||
var utils = require('./utils'),
|
||
clip = utils.clip,
|
||
mapToScale = utils.mapToScale,
|
||
sendOsc = utils.sendOsc
|
||
|
||
module.exports.options = {
|
||
type:'knob',
|
||
id:'auto',
|
||
linkId:'',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
unit:'',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
noPip:false,
|
||
compact:false,
|
||
css:'',
|
||
|
||
separator2:'behaviour',
|
||
|
||
snap:false,
|
||
|
||
separator3:'osc',
|
||
|
||
range:{min:0,max:1},
|
||
logScale:false,
|
||
precision:2,
|
||
path:'auto',
|
||
preArgs:[],
|
||
target:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
var widget = $(`
|
||
<div class="knob-wrapper-outer">
|
||
<div class="knob-wrapper">
|
||
<div class="knob-mask">
|
||
<div class="knob"><span></span></div>
|
||
<div class="handle"></div>
|
||
</div>
|
||
<div class="pips">
|
||
<div class="pip min"></div>
|
||
<div class="pip max"></div>
|
||
</div>
|
||
</div>
|
||
<div class="input"></div>
|
||
</div>
|
||
`),
|
||
wrapper = widget.find('.knob-wrapper'),
|
||
mask = widget.find('.knob-mask'),
|
||
knob = widget.find('.knob'),
|
||
handle = widget.find('.handle'),
|
||
input = widget.find('.input').fakeInput({align:'center'}),
|
||
range = widgetData.range,
|
||
unit = widgetData.unit?' '+widgetData.unit.trim(): '',
|
||
snap = widgetData.snap,
|
||
logScale = widgetData.logScale,
|
||
roundFactor = Math.pow(10,widgetData.precision)
|
||
|
||
if (widgetData.noPip) wrapper.addClass('no-pip')
|
||
if (widgetData.compact) container.addClass('compact')
|
||
|
||
|
||
var rangeKeys = [],
|
||
rangeVals = [],
|
||
rangeLabels = []
|
||
|
||
for (k in widgetData.range) {
|
||
var key = k=='min'?0:k=='max'?100:parseInt(k),
|
||
val = typeof widgetData.range[k] == 'object'?
|
||
widgetData.range[k][Object.keys(widgetData.range[k])[0]]:
|
||
widgetData.range[k],
|
||
label = typeof widgetData.range[k] == 'object'?
|
||
Object.keys(widgetData.range[k])[0]:
|
||
val
|
||
|
||
rangeKeys.push(key)
|
||
rangeVals.push(val)
|
||
rangeLabels.push(label)
|
||
}
|
||
|
||
var rangeValsMax = Math.max.apply(Math, rangeVals),
|
||
rangeValsMin = Math.min.apply(Math, rangeVals)
|
||
|
||
|
||
var pipmin = Math.abs(rangeLabels[0])>=1000?rangeLabels[0]/1000+'k':rangeLabels[0],
|
||
pipmax = Math.abs(rangeLabels[rangeLabels.length-1])>=1000?rangeLabels[rangeLabels.length-1]/1000+'k':rangeLabels[rangeLabels.length-1]
|
||
|
||
|
||
|
||
widget.find('.pip.min').text(pipmin)
|
||
widget.find('.pip.max').text(pipmax)
|
||
|
||
mask.size = 0
|
||
widget.value = undefined
|
||
|
||
wrapper.resize(function(e,width,height){
|
||
|
||
var w = Math.floor(Math.min(height,width)*.58)
|
||
|
||
if (!w || mask.size==w) return
|
||
mask.size=w
|
||
mask[0].setAttribute('style',`height:${w}px;width:${w}px;padding-bottom:0`)
|
||
wrapper.size = {width:wrapper[0].clientWidth,height:wrapper[0].clientHeight}
|
||
})
|
||
|
||
wrapper.on('fake-right-click',function(e){
|
||
if (!EDITING) {
|
||
e.stopPropagation()
|
||
e.preventDefault()
|
||
input.focus()
|
||
}
|
||
})
|
||
|
||
wrapper.on('mousewheel',function(e){
|
||
if (e.originalEvent.wheelDeltaX) return
|
||
|
||
e.preventDefault()
|
||
e.stopPropagation()
|
||
|
||
var divider = e.ctrlKey?48:8
|
||
knob.rotation = clip(knob.rotation+e.originalEvent.wheelDeltaY/divider,[0,270])
|
||
|
||
widget.updateUi(knob.rotation)
|
||
|
||
var v = widget.getValue()
|
||
|
||
if (v!=widget.value) {
|
||
widget.value = v
|
||
|
||
widget.sendValue(v)
|
||
widget.showValue(v)
|
||
|
||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
})
|
||
|
||
|
||
knob.rotation = 0
|
||
|
||
var offR = 0,
|
||
offX = 0,
|
||
offY = 0
|
||
wrapper.on('draginit',function(e,data,traversing){
|
||
|
||
if (snap || traversing) {
|
||
|
||
var w = wrapper.size.width,
|
||
h = wrapper.size.height,
|
||
x = data.offsetX-w/2,
|
||
y = data.offsetY-h/2,
|
||
angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
|
||
r = angle<-90?angle+360:angle
|
||
r = (angle>=-90 && angle<-45)?270:r
|
||
r = clip(r,[0,270])
|
||
|
||
offX = x
|
||
offY = y
|
||
|
||
widget.updateUi(r)
|
||
|
||
knob.rotation = r
|
||
|
||
var v = widget.getValue()
|
||
|
||
if (v!=widget.value) {
|
||
widget.value = v
|
||
|
||
widget.sendValue(v)
|
||
widget.showValue(v)
|
||
|
||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
|
||
}
|
||
|
||
offR = knob.rotation
|
||
})
|
||
|
||
wrapper.on('drag',function(e,data){
|
||
|
||
var r = clip(-data.deltaY*2+offR,[0,270])
|
||
|
||
if (snap || data.ctrlKey || data.shiftKey) {
|
||
var w = data.target.clientWidth,
|
||
h = data.target.clientHeight,
|
||
x = data.deltaX + offX,
|
||
y = data.deltaY + offY,
|
||
angle = Math.atan2(-y, -x) * 180 / Math.PI +45,
|
||
r = angle<-90?angle+360:angle
|
||
r = (angle>=-90 && angle<-45)?270:r
|
||
r = clip(r,[0,270])
|
||
}
|
||
|
||
widget.updateUi(r)
|
||
|
||
knob.rotation = r
|
||
|
||
var v = widget.getValue()
|
||
|
||
if (v!=widget.value) {
|
||
widget.value = v
|
||
|
||
widget.sendValue(v)
|
||
widget.showValue(v)
|
||
|
||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
})
|
||
|
||
widget.updateUi = function(r) {
|
||
knob[0].setAttribute('style','transform:rotateZ('+r+'deg)')
|
||
handle[0].setAttribute('style','transform:rotateZ('+(r-45)+'deg)')
|
||
|
||
if (r>180) {knob.addClass('d3')}
|
||
else if (r>90) {knob.removeClass('d3').addClass('d2')}
|
||
else {knob.removeClass('d3 d2')}
|
||
}
|
||
|
||
widget.getValue = function() {
|
||
var h = knob.rotation
|
||
for (var i=0;i<rangeKeys.length-1;i++) {
|
||
if (h <= rangeKeys[i+1]*2.7 && h >= rangeKeys[i]*2.7) {
|
||
return mapToScale(h,[rangeKeys[i]*2.7,rangeKeys[i+1]*2.7],[rangeVals[i],rangeVals[i+1]],widgetData.precision,logScale)
|
||
}
|
||
}
|
||
}
|
||
widget.showValue = function(v) {
|
||
input.val(v+unit)
|
||
}
|
||
widget.sendValue = function(v) {
|
||
var args = widgetData.preArgs.concat(v)
|
||
|
||
sendOsc({
|
||
target:widgetData.target,
|
||
path:widgetData.path,
|
||
precision:widgetData.precision,
|
||
args:args
|
||
})
|
||
}
|
||
widget.setValue = function(v,send,sync) {
|
||
if (typeof v != 'number') return
|
||
|
||
var v = clip(Math.round(v*roundFactor)/roundFactor,[rangeValsMin,rangeValsMax]),
|
||
r
|
||
|
||
for (var i=0;i<rangeVals.length-1;i++) {
|
||
if (v <= rangeVals[i+1] && v >= rangeVals[i]) {
|
||
r = mapToScale(v,[rangeVals[i],rangeVals[i+1]],[rangeKeys[i]*2.7,rangeKeys[i+1]*2.7],false,logScale,true)
|
||
break
|
||
}
|
||
}
|
||
|
||
knob.rotation = r
|
||
|
||
widget.updateUi(r)
|
||
|
||
var v = widget.getValue()
|
||
widget.value = v
|
||
|
||
widget.showValue(v)
|
||
|
||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
if (send) widget.sendValue(v)
|
||
}
|
||
input.change(function(){
|
||
widget.setValue(parseFloat(input.val()),true,true)
|
||
})
|
||
|
||
widget.setValue(rangeVals[0])
|
||
return widget
|
||
}
|
||
|
||
},{"./utils":37}],18:[function(require,module,exports){
|
||
module.exports.options = {
|
||
type:'multifader',
|
||
id:'auto',
|
||
|
||
separator0:'Matrix',
|
||
|
||
strips:2,
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
unit:'',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
compact:false,
|
||
css:'',
|
||
|
||
|
||
separator2:'osc',
|
||
|
||
range:{min:0,max:1},
|
||
logScale:false,
|
||
precision:2,
|
||
path:'auto',
|
||
preArgs:[],
|
||
target:[]
|
||
}
|
||
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var parsewidgets = require('../parser').widgets
|
||
|
||
var widget = $(`
|
||
<div class="matrix">
|
||
</div>\
|
||
`),
|
||
$document = $(document)
|
||
|
||
widget.value = []
|
||
|
||
for (var i=0;i<widgetData.strips;i++) {
|
||
var data = {
|
||
type:'fader',
|
||
id: widgetData.id + '/' + i,
|
||
label:i,
|
||
horizontal:false,
|
||
snap:true,
|
||
range:widgetData.range,
|
||
logScale:widgetData.logScale,
|
||
precision:widgetData.precision,
|
||
path:widgetData.path + '/' + i,
|
||
preArgs:widgetData.preArgs,
|
||
target:widgetData.target,
|
||
noPip:true,
|
||
compact:widgetData.compact
|
||
}
|
||
var element = parsewidgets([data],widget)
|
||
element[0].setAttribute('style',`width:${100/widgetData.strips}%`)
|
||
element[0].classList.add('not-editable')
|
||
element.find('.fader-wrapper').off('drag')
|
||
|
||
widget.value[i] = widgetData.range.min
|
||
|
||
}
|
||
|
||
|
||
|
||
widget.on('sync',function(e,id,w){
|
||
if (id==widgetData.id) return
|
||
widget.value[w.parent().index()] = w.getValue()
|
||
widget.trigger('sync',[widgetData.id,widget])
|
||
})
|
||
|
||
|
||
widget.getValue = function(){
|
||
return widget.value
|
||
}
|
||
|
||
widget.enableTraversingGestures()
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"../parser":10}],19:[function(require,module,exports){
|
||
module.exports.options = {
|
||
type:'multipush',
|
||
id:'auto',
|
||
|
||
separator0: 'Matrix',
|
||
|
||
matrix: [2,2],
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'osc',
|
||
|
||
on:1,
|
||
off:0,
|
||
precision:2,
|
||
path:'auto',
|
||
preArgs:[],
|
||
target:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var parsewidgets = require('../parser').widgets
|
||
|
||
var widget = $(`
|
||
<div class="matrix">
|
||
</div>\
|
||
`),
|
||
$document = $(document)
|
||
|
||
widget.value = []
|
||
|
||
for (var i=0;i<widgetData.matrix[0]*widgetData.matrix[1];i++) {
|
||
var data = {
|
||
type:'push',
|
||
id: widgetData.id + '/' + i,
|
||
label:i,
|
||
on:widgetData.on,
|
||
off:widgetData.off,
|
||
precision:widgetData.precision,
|
||
path:widgetData.path + '/' + i,
|
||
preArgs:widgetData.preArgs,
|
||
target:widgetData.target
|
||
}
|
||
var element = parsewidgets([data],widget)
|
||
element[0].setAttribute('style',`width:${100/widgetData.matrix[0]}%`)
|
||
element[0].classList.add('not-editable')
|
||
|
||
widget.value[i] = widgetData.off
|
||
|
||
}
|
||
|
||
|
||
|
||
widget.on('sync',function(e,id,w){
|
||
if (id==widgetData.id) return
|
||
widget.value[w.parent().index()] = w.getValue()
|
||
widget.trigger('sync',[widgetData.id,widget])
|
||
})
|
||
|
||
|
||
widget.getValue = function(){
|
||
return widget.value
|
||
}
|
||
|
||
widget.enableTraversingGestures()
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"../parser":10}],20:[function(require,module,exports){
|
||
module.exports.options = {
|
||
type:'multitoggle',
|
||
id:'auto',
|
||
|
||
separator0: 'Matrix',
|
||
|
||
matrix: [2,2],
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'osc',
|
||
|
||
on:1,
|
||
off:0,
|
||
precision:2,
|
||
path:'auto',
|
||
preArgs:[],
|
||
target:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var parsewidgets = require('../parser').widgets
|
||
|
||
var widget = $(`
|
||
<div class="matrix">
|
||
</div>\
|
||
`),
|
||
$document = $(document)
|
||
|
||
widget.value = []
|
||
|
||
for (var i=0;i<widgetData.matrix[0]*widgetData.matrix[1];i++) {
|
||
var data = {
|
||
type:'toggle',
|
||
id: widgetData.id + '/' + i,
|
||
label:i,
|
||
on:widgetData.on,
|
||
off:widgetData.off,
|
||
precision:widgetData.precision,
|
||
path:widgetData.path + '/' + i,
|
||
preArgs:widgetData.preArgs,
|
||
target:widgetData.target
|
||
}
|
||
var element = parsewidgets([data],widget)
|
||
element[0].setAttribute('style',`width:${100/widgetData.matrix[0]}%`)
|
||
element[0].classList.add('not-editable')
|
||
|
||
widget.value[i] = widgetData.off
|
||
|
||
}
|
||
|
||
|
||
|
||
widget.on('sync',function(e,id,w){
|
||
if (id==widgetData.id) return
|
||
widget.value[w.parent().index()] = w.getValue()
|
||
widget.trigger('sync',[widgetData.id,widget])
|
||
})
|
||
|
||
|
||
widget.getValue = function(){
|
||
return widget.value
|
||
}
|
||
|
||
widget.enableTraversingGestures()
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"../parser":10}],21:[function(require,module,exports){
|
||
module.exports.options = {
|
||
type:'panel',
|
||
id:'auto',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
scroll:true,
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'chilren',
|
||
|
||
widgets:[],
|
||
tabs:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var parser = require('../parser'),
|
||
parsewidgets = parser.widgets,
|
||
parsetabs = parser.tabs
|
||
|
||
var widget = $(`
|
||
<div class="panel">
|
||
</div>
|
||
`)
|
||
|
||
if (!widgetData.scroll) widget.addClass('noscroll')
|
||
|
||
if (widgetData.tabs.length) {
|
||
parsetabs(widgetData.tabs,widget)
|
||
widget.addClass('has-tabs')
|
||
} else {
|
||
parsewidgets(widgetData.widgets,widget)
|
||
}
|
||
return widget
|
||
}
|
||
|
||
},{"../parser":10}],22:[function(require,module,exports){
|
||
//
|
||
// calcBiquad
|
||
//
|
||
// Dec 14, 2010 njr
|
||
// original @ Nigel Redmon
|
||
|
||
module.exports = function(options,linear,resolution) {
|
||
var {type, freq, q, gain} = options,
|
||
Fs = 44100,
|
||
a0,a1,a2,b1,b2,norm,
|
||
ymin, ymax, minVal, maxVal,
|
||
len = resolution
|
||
|
||
var V = Math.pow(10, Math.abs(gain) / 20)
|
||
var K = Math.tan(Math.PI * freq / Fs)
|
||
switch (type) {
|
||
case "lowpass":
|
||
norm = 1 / (1 + K / q + K * K)
|
||
a0 = K * K * norm
|
||
a1 = 2 * a0
|
||
a2 = a0
|
||
b1 = 2 * (K * K - 1) * norm
|
||
b2 = (1 - K / q + K * K) * norm
|
||
break
|
||
|
||
case "highpass":
|
||
norm = 1 / (1 + K / q + K * K)
|
||
a0 = 1 * norm
|
||
a1 = -2 * a0
|
||
a2 = a0
|
||
b1 = 2 * (K * K - 1) * norm
|
||
b2 = (1 - K / q + K * K) * norm
|
||
break
|
||
|
||
case "bandpass":
|
||
norm = 1 / (1 + K / q + K * K)
|
||
a0 = K / q * norm
|
||
a1 = 0
|
||
a2 = -a0
|
||
b1 = 2 * (K * K - 1) * norm
|
||
b2 = (1 - K / q + K * K) * norm
|
||
break
|
||
|
||
case "notch":
|
||
norm = 1 / (1 + K / q + K * K)
|
||
a0 = (1 + K * K) * norm
|
||
a1 = 2 * (K * K - 1) * norm
|
||
a2 = a0
|
||
b1 = a1
|
||
b2 = (1 - K / q + K * K) * norm
|
||
break
|
||
|
||
case "peak":
|
||
if (gain >= 0) {
|
||
norm = 1 / (1 + 1/q * K + K * K)
|
||
a0 = (1 + V/q * K + K * K) * norm
|
||
a1 = 2 * (K * K - 1) * norm
|
||
a2 = (1 - V/q * K + K * K) * norm
|
||
b1 = a1
|
||
b2 = (1 - 1/q * K + K * K) * norm
|
||
}
|
||
else {
|
||
norm = 1 / (1 + V/q * K + K * K)
|
||
a0 = (1 + 1/q * K + K * K) * norm
|
||
a1 = 2 * (K * K - 1) * norm
|
||
a2 = (1 - 1/q * K + K * K) * norm
|
||
b1 = a1
|
||
b2 = (1 - V/q * K + K * K) * norm
|
||
}
|
||
break
|
||
case "lowshelf":
|
||
if (gain >= 0) {
|
||
norm = 1 / (1 + Math.SQRT2 * K + K * K)
|
||
a0 = (1 + Math.sqrt(2*V) * K + V * K * K) * norm
|
||
a1 = 2 * (V * K * K - 1) * norm
|
||
a2 = (1 - Math.sqrt(2*V) * K + V * K * K) * norm
|
||
b1 = 2 * (K * K - 1) * norm
|
||
b2 = (1 - Math.SQRT2 * K + K * K) * norm
|
||
}
|
||
else {
|
||
norm = 1 / (1 + Math.sqrt(2*V) * K + V * K * K)
|
||
a0 = (1 + Math.SQRT2 * K + K * K) * norm
|
||
a1 = 2 * (K * K - 1) * norm
|
||
a2 = (1 - Math.SQRT2 * K + K * K) * norm
|
||
b1 = 2 * (V * K * K - 1) * norm
|
||
b2 = (1 - Math.sqrt(2*V) * K + V * K * K) * norm
|
||
}
|
||
break
|
||
case "highshelf":
|
||
if (gain >= 0) {
|
||
norm = 1 / (1 + Math.SQRT2 * K + K * K)
|
||
a0 = (V + Math.sqrt(2*V) * K + K * K) * norm
|
||
a1 = 2 * (K * K - V) * norm
|
||
a2 = (V - Math.sqrt(2*V) * K + K * K) * norm
|
||
b1 = 2 * (K * K - 1) * norm
|
||
b2 = (1 - Math.SQRT2 * K + K * K) * norm
|
||
}
|
||
else {
|
||
norm = 1 / (V + Math.sqrt(2*V) * K + K * K)
|
||
a0 = (1 + Math.SQRT2 * K + K * K) * norm
|
||
a1 = 2 * (K * K - 1) * norm
|
||
a2 = (1 - Math.SQRT2 * K + K * K) * norm
|
||
b1 = 2 * (K * K - V) * norm
|
||
b2 = (V - Math.sqrt(2*V) * K + K * K) * norm
|
||
}
|
||
break
|
||
}
|
||
|
||
var magPlot = []
|
||
for (var i = 0; i < len; i++) {
|
||
var w, phi, y
|
||
if (linear)
|
||
w = i / (len - 1) * Math.PI; // 0 to pi, linear scale
|
||
else
|
||
w = Math.exp(Math.log(1 / 0.001) * i / (len - 1)) * 0.001 * Math.PI; // 0.001 to 1, times pi, log scale
|
||
|
||
phi = Math.pow(Math.sin(w/2), 2)
|
||
|
||
y = Math.log(Math.pow(a0+a1+a2, 2) - 4*(a0*a1 + 4*a0*a2 + a1*a2)*phi + 16*a0*a2*phi*phi) - Math.log(Math.pow(1+b1+b2, 2) - 4*(b1 + 4*b2 + b1*b2)*phi + 16*b2*phi*phi)
|
||
y = y * 10 / Math.LN10
|
||
if (y == -Infinity) y = -200
|
||
|
||
if (linear)
|
||
magPlot.push([i / (len - 1) * Fs / 2, y])
|
||
else
|
||
magPlot.push([i / (len - 1) * Fs / 2, y])
|
||
|
||
if (i == 0)
|
||
minVal = maxVal = y
|
||
else if (y < minVal)
|
||
minVal = y
|
||
else if (y > maxVal)
|
||
maxVal = y
|
||
}
|
||
|
||
return magPlot
|
||
}
|
||
|
||
},{}],23:[function(require,module,exports){
|
||
var {mapToScale} = require('../utils'),
|
||
_canvas_base = require('../common/_canvas_base')
|
||
|
||
var _plots_base = module.exports = function(){
|
||
|
||
this.widget = $(`
|
||
<div class="plot">
|
||
<canvas></canvas>
|
||
</div>
|
||
`)
|
||
|
||
_canvas_base.apply(this,arguments)
|
||
|
||
this.data = []
|
||
this.linkedWidgets = []
|
||
this.rangeX = this.widgetData.rangeX || {min:0,max:1}
|
||
this.rangeY = this.widgetData.rangeY || {min:0,max:1}
|
||
this.pips = {
|
||
x : {
|
||
min: Math.abs(this.rangeX.min)>=1000?this.rangeY.min/1000+'k':this.rangeX.min,
|
||
max: Math.abs(this.rangeX.max)>=1000?this.rangeY.max/1000+'k':this.rangeX.max
|
||
},
|
||
y : {
|
||
min: Math.abs(this.rangeY.min)>=1000?this.rangeY.min/1000+'k':this.rangeY.min,
|
||
max: Math.abs(this.rangeY.max)>=1000?this.rangeY.max/1000+'k':this.rangeY.max
|
||
}
|
||
}
|
||
|
||
|
||
$('body').on('sync',this.syncHandleProxy.bind(this))
|
||
|
||
}
|
||
|
||
_plots_base.prototype = Object.create(_canvas_base.prototype)
|
||
|
||
_plots_base.prototype.constructor = _plots_base
|
||
|
||
_plots_base.prototype.syncHandleProxy = function() {
|
||
this.syncHandle.apply(this,arguments)
|
||
}
|
||
|
||
_plots_base.prototype.syncHandle = function(e,id,w) {
|
||
if (this.linkedWidgets.indexOf(id)==-1 || !WIDGETS[id]) return
|
||
this.updateData()
|
||
requestAnimationFrame(this.draw.bind(this))
|
||
}
|
||
|
||
_plots_base.prototype.resizeHandle = function(){
|
||
this.updateData()
|
||
_canvas_base.prototype.resizeHandle.call(this)
|
||
}
|
||
|
||
_plots_base.prototype.draw = function() {
|
||
|
||
this.ctx.clearRect(0,0,this.width,this.height)
|
||
this.ctx.beginPath()
|
||
|
||
this.draw_data()
|
||
|
||
this.ctx.lineWidth = 1*PXSCALE
|
||
this.ctx.strokeStyle = this.colors.accent
|
||
this.ctx.stroke()
|
||
|
||
this.ctx.font = PXSCALE * 10 + 'px sans-serif'
|
||
this.ctx.fillStyle = this.colors.text
|
||
|
||
|
||
this.ctx.textBaseline = "bottom"
|
||
this.ctx.textAlign = 'left'
|
||
this.ctx.fillText(this.pips.x.min,12*PXSCALE,this.height)
|
||
this.ctx.textAlign = 'right'
|
||
this.ctx.fillText(this.pips.x.max,this.width-10,this.height)
|
||
|
||
this.ctx.save()
|
||
this.ctx.translate(0, this.height)
|
||
this.ctx.rotate(-Math.PI/2)
|
||
|
||
this.ctx.textBaseline = "top"
|
||
this.ctx.textAlign = 'left'
|
||
this.ctx.fillText(this.pips.y.min,12*PXSCALE,2*PXSCALE)
|
||
this.ctx.textAlign = 'right'
|
||
this.ctx.fillText(this.pips.y.max,this.height-10*PXSCALE,2*PXSCALE)
|
||
this.ctx.rotate(Math.PI/2)
|
||
this.ctx.restore()
|
||
|
||
}
|
||
|
||
_plots_base.prototype.draw_data = function() {
|
||
var first = true
|
||
var point = []
|
||
for (i in this.data) {
|
||
|
||
if (this.data[i][1]>this.rangeY.max || this.data[i][1]<this.rangeY.min ||
|
||
this.data[i][0]>this.rangeX.max || this.data[i][0]<this.rangeX.min) continue
|
||
|
||
var newpoint = this.data[i].length?
|
||
[
|
||
mapToScale(this.data[i][0],[this.rangeX.min,this.rangeX.max],[15*PXSCALE,this.width-15*PXSCALE],0,this.widgetData.logScaleX,true),
|
||
mapToScale(this.data[i][1],[this.rangeY.min,this.rangeY.max],[this.height-15*PXSCALE,15*PXSCALE],0,this.widgetData.logScaleY,true),
|
||
]
|
||
:
|
||
[
|
||
mapToScale(i,[0,this.data.length-1],[15*PXSCALE,this.width-15*PXSCALE],0,this.widgetData.logScaleX,true),
|
||
mapToScale(this.data[i],[this.rangeY.min,this.rangeY.max],[this.height-15*PXSCALE,15*PXSCALE],0,this.widgetData.logScaleY,true),
|
||
]
|
||
|
||
|
||
if (first) {
|
||
this.ctx.moveTo(newpoint[0],newpoint[1])
|
||
first = false
|
||
} else {
|
||
this.ctx.moveTo(point[0],point[1])
|
||
this.ctx.lineTo(newpoint[0],newpoint[1])
|
||
}
|
||
point = newpoint
|
||
}
|
||
}
|
||
|
||
_plots_base.prototype.setValue = function(v) {
|
||
this.data = v
|
||
requestAnimationFrame(this.draw.bind(this))
|
||
}
|
||
|
||
_plots_base.prototype.updateData = function(){
|
||
// update the coordinates to draw
|
||
}
|
||
|
||
},{"../common/_canvas_base":15,"../utils":37}],24:[function(require,module,exports){
|
||
var {mapToScale, clip} = require('../utils'),
|
||
_biquad_response = require('./_biquad_response'),
|
||
_plots_base = require('./_plots_base')
|
||
|
||
module.exports.options = {
|
||
type:'eq',
|
||
id:'auto',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'plot',
|
||
|
||
filters:[],
|
||
resolution:128,
|
||
rangeY: {min:-20,max:20},
|
||
logScaleX: false,
|
||
|
||
separator3:'osc',
|
||
|
||
path:'auto',
|
||
preArgs:[],
|
||
|
||
}
|
||
|
||
var Eq = function(widgetData) {
|
||
|
||
_plots_base.call(this,widgetData)
|
||
|
||
this.rangeX = {min:20,max:22050}
|
||
this.pips.x.min = '20'
|
||
this.pips.x.max = '22k'
|
||
|
||
widgetData.resolution = clip(widgetData.resolution,[64,1024])
|
||
|
||
for (i in widgetData.filters) {
|
||
|
||
for (j in widgetData.filters[i]) {
|
||
if (typeof widgetData.filters[i][j]=='string' && !(j=='type' && widgetData.filters[i][j].match(/peak|notch|highpass|highshelf|lowpass|lowshelf/))) {
|
||
this.linkedWidgets.push(widgetData.filters[i][j])
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
Eq.prototype = Object.create(_plots_base.prototype)
|
||
|
||
Eq.prototype.constructor = Eq
|
||
|
||
|
||
Eq.prototype.updateData = function(){
|
||
var filters = [],
|
||
eqResponse = []
|
||
|
||
|
||
for (i in this.widgetData.filters) {
|
||
var filter = this.widgetData.filters[i]
|
||
|
||
filters[i] = {}
|
||
|
||
for (j in filter) {
|
||
|
||
if (typeof filter[j]=='string' && WIDGETS[filter[j]]) {
|
||
|
||
filters[i][j] = WIDGETS[filter[j]][WIDGETS[filter[j]].length-1].getValue()
|
||
|
||
} else {
|
||
|
||
filters[i][j] = filter[j]
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
for (i in filters) {
|
||
|
||
var filterResponse
|
||
|
||
if (!filters[i].type) filters[i].type = "peak"
|
||
|
||
if (!filters[i].on) {
|
||
filterResponse = _biquad_response({type:"peak",freq:1,gain:0,q:1},!this.widgetData.logScaleX,this.widgetData.resolution)
|
||
} else {
|
||
filterResponse = _biquad_response(filters[i],!this.widgetData.logScaleX,this.widgetData.resolution)
|
||
}
|
||
for (k in filterResponse) {
|
||
if (eqResponse[k]===undefined) {
|
||
eqResponse[k]=[0,0]
|
||
}
|
||
|
||
eqResponse[k] = [filterResponse[k][0], eqResponse[k][1]+filterResponse[k][1]]
|
||
}
|
||
}
|
||
if (eqResponse.length) this.data = eqResponse
|
||
|
||
}
|
||
|
||
module.exports.create = function(widgetData) {
|
||
var eq = new Eq(widgetData)
|
||
return eq.widget
|
||
}
|
||
|
||
},{"../utils":37,"./_biquad_response":22,"./_plots_base":23}],25:[function(require,module,exports){
|
||
var {mapToScale} = require('../utils')
|
||
|
||
module.exports.options = {
|
||
type:'led',
|
||
id:'auto',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'osc',
|
||
|
||
range:{min:0,max:1},
|
||
logScale:false,
|
||
preArgs:[],
|
||
path:'auto'
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
var widget = $(`
|
||
<div class="led">
|
||
<div><span></span></div>
|
||
</div>
|
||
`),
|
||
led = widget.find('span'),
|
||
range = widgetData.range
|
||
|
||
widget.setValue = function(v,send,sync){
|
||
if (typeof v != 'number') return
|
||
led.css('opacity',mapToScale(v,[range.min,range.max],[0,1],widgetData.precision,widgetData.logScale,true))
|
||
}
|
||
|
||
widget.setValue(range.min)
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"../utils":37}],26:[function(require,module,exports){
|
||
var {mapToScale, clip} = require('../utils')
|
||
|
||
module.exports.options = {
|
||
type:'fader',
|
||
id:'auto',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
unit:'',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
horizontal:false,
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator3:'osc',
|
||
|
||
range:{min:0,max:1},
|
||
logScale:false,
|
||
path:'auto',
|
||
preArgs:[]
|
||
}
|
||
|
||
module.exports.create = function(widgetData,container) {
|
||
var widget = $(`
|
||
<div class="meter">
|
||
<div class="level"></div>
|
||
</div>
|
||
`),
|
||
level = widget.find('.level'),
|
||
logScale = widgetData.logScale,
|
||
dimension = widgetData.horizontal?'width':'height',
|
||
axe = dimension=='height'?'X':'Y'
|
||
|
||
|
||
if (widgetData.horizontal) widget.addClass('horizontal')
|
||
|
||
|
||
var rangeKeys = [],
|
||
rangeVals = []
|
||
|
||
for (k in widgetData.range) {
|
||
var key = k=='min'?0:k=='max'?100:parseInt(k),
|
||
val = typeof widgetData.range[k] == 'object'?
|
||
widgetData.range[k][Object.keys(widgetData.range[k])[0]]:
|
||
widgetData.range[k]
|
||
|
||
rangeKeys.push(key)
|
||
rangeVals.push(val)
|
||
}
|
||
|
||
|
||
|
||
widget.updateUi = function(v){
|
||
var s = v/100,
|
||
t = dimension=='height'?
|
||
'1,'+s+',1'
|
||
:s+',1,1'
|
||
level[0].setAttribute('style','transform:scale3d('+t+')')
|
||
}
|
||
|
||
|
||
widget.setValue = function(v) {
|
||
if (typeof v != 'number') return
|
||
|
||
var h,
|
||
v=clip(v,[rangeVals[0],rangeVals.slice(-1)[0]])
|
||
for (var i=0;i<rangeVals.length-1;i++) {
|
||
if (v <= rangeVals[i+1] && v >= rangeVals[i]) {
|
||
h = mapToScale(v,[rangeVals[i],rangeVals[i+1]],[rangeKeys[i],rangeKeys[i+1]],2,logScale,true)
|
||
break
|
||
}
|
||
}
|
||
|
||
widget.updateUi(h)
|
||
|
||
}
|
||
|
||
widget.setValue(rangeVals[0])
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"../utils":37}],27:[function(require,module,exports){
|
||
var {mapToScale} = require('../utils'),
|
||
_plots_base = require('./_plots_base')
|
||
|
||
module.exports.options = {
|
||
type:'plot',
|
||
id:'auto',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'plot',
|
||
|
||
points:[],
|
||
rangeX: {min:0,max:1},
|
||
rangeY: {min:0,max:1},
|
||
logScaleX: false,
|
||
logScaleY: false,
|
||
|
||
separator3:'osc',
|
||
|
||
path:'auto',
|
||
preArgs:[],
|
||
|
||
}
|
||
|
||
var Plot = function(widgetData) {
|
||
|
||
_plots_base.call(this,widgetData)
|
||
|
||
if (typeof widgetData.points=='string') {
|
||
|
||
this.linkedWidgets.push(widgetData.points)
|
||
|
||
} else if (typeof widgetData.points=='object') {
|
||
|
||
for (i in widgetData.points) {
|
||
for (j in widgetData.points[i]) {
|
||
if (typeof widgetData.points[i][j] == 'string') {
|
||
this.linkedWidgets.push(widgetData.points[i][j])
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
this.updateData = function(){
|
||
var data = [],
|
||
points = widgetData.points
|
||
|
||
if (typeof points=='string' && WIDGETS[points]) {
|
||
|
||
data = WIDGETS[points][WIDGETS[points].length-1].getValue()
|
||
|
||
} else if (typeof points=='object') {
|
||
|
||
for (i in points) {
|
||
|
||
data[i] = []
|
||
for (k in [0,1]) {
|
||
if (typeof points[i][k] == 'string' && WIDGETS[points[i][k]]) {
|
||
data[i][k] = WIDGETS[points[i][k]][WIDGETS[points[i][k]].length-1].getValue()
|
||
} else {
|
||
data[i][k] = points[i][k]
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
if (data.length) this.data = data
|
||
}
|
||
}
|
||
|
||
Plot.prototype = Object.create(_plots_base.prototype)
|
||
|
||
Plot.prototype.constructor = Plot
|
||
|
||
module.exports.create = function(widgetData) {
|
||
var plot = new Plot(widgetData)
|
||
return plot.widget
|
||
}
|
||
|
||
},{"../utils":37,"./_plots_base":23}],28:[function(require,module,exports){
|
||
module.exports.options = {
|
||
type:'text',
|
||
id:'auto',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
vertical:false,
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'osc',
|
||
|
||
preArgs:[],
|
||
path:'auto',
|
||
defaultText:''
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
var widget = $(`
|
||
<div class="text">
|
||
</div>
|
||
`),
|
||
label = widgetData.defaultText!==''?
|
||
widgetData.defaultText:
|
||
widgetData.label===false?
|
||
widgetData.id:
|
||
widgetData.label=='auto'?
|
||
widgetData.id:
|
||
widgetData.label,
|
||
text = label
|
||
|
||
|
||
if (widgetData.vertical) widget.addClass('vertical')
|
||
|
||
widget.setValue = function(v,send,sync){
|
||
text = typeof v=='object' && !v.length?label:v
|
||
widget.text(text)
|
||
}
|
||
|
||
widget.getValue = function(){
|
||
return text
|
||
}
|
||
|
||
widget.setValue(label)
|
||
|
||
return widget
|
||
}
|
||
|
||
},{}],29:[function(require,module,exports){
|
||
var {mapToScale, clip} = require('../utils'),
|
||
_plots_base = require('./_plots_base')
|
||
|
||
module.exports.options = {
|
||
type:'visualizer',
|
||
id:'auto',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'plot',
|
||
|
||
widgetId:'',
|
||
duration:1,
|
||
range: {min:0,max:1},
|
||
logScale: false,
|
||
|
||
separator3:'osc',
|
||
|
||
path:'auto',
|
||
preArgs:[],
|
||
}
|
||
|
||
var Visualizer = function(widgetData) {
|
||
|
||
_plots_base.call(this,widgetData)
|
||
|
||
this.pips.y.min = Math.abs(widgetData.range.min)>=1000?widgetData.range.min/1000+'k':widgetData.range.min
|
||
this.pips.y.max = Math.abs(widgetData.range.max)>=1000?widgetData.range.max/1000+'k':widgetData.range.max
|
||
this.pips.x.min = ''
|
||
this.pips.x.max = ''
|
||
this.length = Math.round(clip(60*widgetData.duration,[8,4096]))
|
||
this.data = new Array(this.length)
|
||
this.value = widgetData.range.min
|
||
this.cancel = false
|
||
this.loop = false
|
||
|
||
}
|
||
|
||
Visualizer.prototype = Object.create(_plots_base.prototype)
|
||
|
||
Visualizer.prototype.constructor = Visualizer
|
||
|
||
Visualizer.prototype.syncHandle = function(e,id,w) {
|
||
if (this.widgetData.widgetId!=id || !WIDGETS[id]) return
|
||
this.startLoop()
|
||
}
|
||
|
||
Visualizer.prototype.startLoop = function(){
|
||
|
||
if (this.cancel) clearTimeout(this.cancel)
|
||
|
||
this.cancel = setTimeout(function(){
|
||
clearInterval(this.loop)
|
||
this.loop = false
|
||
this.cancel = false
|
||
},1000*this.widgetData.duration)
|
||
|
||
if (this.loop) return
|
||
|
||
this.loop = setInterval(function(){
|
||
this.updateData()
|
||
this.draw()
|
||
}.bind(this),1000*this.widgetData.duration/this.length)
|
||
}
|
||
|
||
|
||
Visualizer.prototype.draw_data = function(){
|
||
|
||
var first = true
|
||
var point = []
|
||
|
||
for (var i=this.length-1;i>=0;i=i-1) {
|
||
var newpoint = [
|
||
mapToScale(i,[0,this.length-1],[15*PXSCALE,this.width-15*PXSCALE],1),
|
||
mapToScale(this.data[i],[this.widgetData.range.min,this.widgetData.range.max],[this.height-15*PXSCALE,15*PXSCALE],1,this.widgetData.logScale,true),
|
||
]
|
||
if (first) {
|
||
this.ctx.moveTo(newpoint[0],newpoint[1])
|
||
first = false
|
||
} else {
|
||
if (this.widgetData.logScale) {
|
||
this.ctx.quadraticCurveTo(newpoint[0], point[1], newpoint[0], newpoint[1])
|
||
} else {
|
||
this.ctx.lineTo(newpoint[0],newpoint[1])
|
||
}
|
||
|
||
}
|
||
point = newpoint
|
||
}
|
||
|
||
}
|
||
|
||
|
||
Visualizer.prototype.updateData = function(){
|
||
var id = this.widgetData.widgetId
|
||
|
||
if (typeof id == 'string' && WIDGETS[id]) {
|
||
var v = WIDGETS[id][WIDGETS[id].length-1].getValue()
|
||
this.data.push(v)
|
||
this.value = v
|
||
} else {
|
||
this.data.push(this.value)
|
||
}
|
||
|
||
this.data.splice(0,1)
|
||
|
||
}
|
||
|
||
Visualizer.prototype.setValue = function(v) {
|
||
this.value = v
|
||
this.startLoop()
|
||
}
|
||
|
||
|
||
module.exports.create = function(widgetData,container) {
|
||
var visualizer = new Visualizer(widgetData)
|
||
return visualizer.widget
|
||
}
|
||
|
||
},{"../utils":37,"./_plots_base":23}],30:[function(require,module,exports){
|
||
var sendOsc = require('./utils').sendOsc
|
||
|
||
module.exports.options = {
|
||
type:'push',
|
||
id:'auto',
|
||
linkId:'',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'osc',
|
||
|
||
on:1,
|
||
off:0,
|
||
precision:2,
|
||
path:'auto',
|
||
preArgs:[],
|
||
target:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
|
||
var widget = $(`
|
||
<div class="light">
|
||
</div>\
|
||
`),
|
||
$document = $(document)
|
||
|
||
widget.value = widget.find('span')
|
||
widget.state = 0
|
||
widget.active = 0
|
||
widget.lastChanged = 'state'
|
||
|
||
widget.on('drag',function(e){e.stopPropagation()})
|
||
widget.on('draginit.push',function(){
|
||
widget.off('draginit.push')
|
||
widget.fakeclick()
|
||
})
|
||
|
||
widget.fakeclick = function(){
|
||
if (!widget.active) widget.setValuePrivate(widgetData.on,true,true)
|
||
$document.on('dragend.push',function(){
|
||
widget.setValuePrivate(widgetData.off,true,true)
|
||
$document.off('dragend.push')
|
||
widget.on('draginit.push',function(){
|
||
widget.off('draginit.push')
|
||
widget.fakeclick()
|
||
})
|
||
})
|
||
}
|
||
|
||
widget.getValue = function() {
|
||
return widget[widget.lastChanged]?widgetData.on:widgetData.off
|
||
}
|
||
|
||
widget.setValuePrivate = function(v,send,sync) {
|
||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||
widget.addClass('active')
|
||
widget.active = 1
|
||
if (send) widget.sendValue(v)
|
||
widget.lastChanged = 'active'
|
||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
|
||
widget.removeClass('active')
|
||
widget.active = 0
|
||
if (send) widget.sendValue(v)
|
||
widget.lastChanged = 'active'
|
||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
}
|
||
|
||
widget.setValue = function(v,send,sync) {
|
||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||
widget.addClass('on')
|
||
widget.state = 1
|
||
if (send) widget.sendValue(v)
|
||
widget.lastChanged = 'state'
|
||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
|
||
widget.removeClass('on')
|
||
widget.state = 0
|
||
if (send) widget.sendValue(v)
|
||
widget.lastChanged = 'state'
|
||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
}
|
||
|
||
widget.sendValue = function(v) {
|
||
if (v===false) return
|
||
var args = widgetData.preArgs.concat(v)
|
||
sendOsc({
|
||
target:widgetData.target,
|
||
path:widgetData.path,
|
||
precision:widgetData.precision,
|
||
args:args
|
||
})
|
||
}
|
||
widget.setValue()
|
||
return widget
|
||
}
|
||
|
||
},{"./utils":37}],31:[function(require,module,exports){
|
||
var utils = require('./utils'),
|
||
clip = utils.clip,
|
||
mapToScale = utils.mapToScale,
|
||
hsbToRgb = utils.hsbToRgb,
|
||
rgbToHsb = utils.rgbToHsb,
|
||
sendOsc = utils.sendOsc
|
||
|
||
module.exports.options = {
|
||
type:'rgb',
|
||
id:'auto',
|
||
linkId:'',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
css:'',
|
||
|
||
separator2:'behaviour',
|
||
|
||
snap:false,
|
||
|
||
separator3:'osc',
|
||
|
||
precision:0,
|
||
path:'auto',
|
||
preArgs:[],
|
||
split:false,
|
||
target:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var widget = $(`
|
||
<div class="xy-wrapper rgb-wrapper">
|
||
<div class="xy rgb">
|
||
<div class="bg"></div>
|
||
<div class="handle"></div>
|
||
</div>
|
||
<div class="hue">
|
||
<div class="bg"></div>
|
||
<div class="handle"></div>
|
||
</div>
|
||
<div class="value">
|
||
<div class="input disabled">R</div><div class="input disabled">G</div><div class="input disabled">B</div>
|
||
<div class="input r"></div><div class="input g"></div><div class="input b"></div>
|
||
</div>
|
||
</div>`),
|
||
rgbHandle = widget.find('.rgb .handle'),
|
||
hueHandle = widget.find('.hue .handle'),
|
||
pad = widget.find('.xy'),
|
||
huePad = widget.find('.hue'),
|
||
rgbBg = pad.find('.bg')[0],
|
||
value = {r:widget.find('.r').fakeInput({align:'center'}),g:widget.find('.g').fakeInput({align:'center'}),b:widget.find('.b').fakeInput({align:'center'})},
|
||
snap = widgetData.snap,
|
||
split = widgetData.split?
|
||
typeof widgetData.split == 'object'?
|
||
widgetData.split:{r:widgetData.path+'/r',g:widgetData.path+'/g',b:widgetData.path+'/b'}
|
||
:false
|
||
|
||
|
||
pad.width = 0
|
||
pad.height = 0
|
||
rgbHandle.height = 0
|
||
rgbHandle.width = 0
|
||
hueHandle.width = 0
|
||
widget.value = undefined
|
||
|
||
pad.resize(function(){
|
||
var width = pad.innerWidth(),
|
||
height = pad.innerHeight()
|
||
if (!width || (pad.height==height && pad.width==width)) return
|
||
pad.width = width
|
||
pad.height = height
|
||
rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*rgbHandle.width/100}px, -${pad.height*rgbHandle.height/100}px,0)`)
|
||
|
||
})
|
||
|
||
|
||
var rgbOff = {x:0,y:0}
|
||
pad.on('draginit',function(e,data,traversing){
|
||
if (snap || traversing) {
|
||
|
||
var h = ((pad.height-data.offsetY) * 100 / pad.height),
|
||
w = (data.offsetX * 100 / pad.width)
|
||
|
||
rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
|
||
rgbHandle.height = h
|
||
rgbHandle.width = w
|
||
|
||
var v = widget.getValue()
|
||
|
||
if (v<widget.value||v>widget.value) {
|
||
widget.value = v
|
||
|
||
widget.sendValue(v)
|
||
widget.showValue(v)
|
||
|
||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
|
||
}
|
||
|
||
rgbOff = {x:rgbHandle.width,y:rgbHandle.height}
|
||
|
||
})
|
||
pad.on('drag',function(e,data){
|
||
|
||
var h = clip((-data.deltaY)*100/pad.height+rgbOff.y,[0,100]),
|
||
w = clip(data.deltaX*100/pad.width+rgbOff.x,[0,100])
|
||
|
||
rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
|
||
rgbHandle.height = h
|
||
rgbHandle.width = w
|
||
|
||
var v = widget.getValue()
|
||
|
||
if (v<widget.value||v>widget.value) {
|
||
widget.value = v
|
||
|
||
widget.sendValue(v)
|
||
widget.showValue(v)
|
||
|
||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
|
||
})
|
||
|
||
|
||
var hueOff = 0
|
||
huePad.on('draginit',function(e,data,traversing){
|
||
if (snap || traversing) {
|
||
|
||
var d = (data.offsetX * 100 / pad.width)
|
||
hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*d/100}px,0,0)`)
|
||
hueHandle.width = d
|
||
|
||
|
||
var h = clip(hueHandle.width*3.6,[0,360]),
|
||
rgb = hsbToRgb({h:h,s:100,b:100})
|
||
|
||
rgbBg.setAttribute('style','background-color:rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
|
||
|
||
var v = widget.getValue()
|
||
|
||
if (v<widget.value||v>widget.value) {
|
||
widget.value = v
|
||
|
||
widget.sendValue(v)
|
||
widget.showValue(v)
|
||
|
||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
|
||
}
|
||
|
||
hueOff = hueHandle.width
|
||
|
||
})
|
||
|
||
|
||
huePad.on('drag',function(e,data){
|
||
|
||
var w = clip(data.deltaX*100/pad.width+hueOff,[0,100])
|
||
hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px,0,0)`)
|
||
hueHandle.width = w
|
||
|
||
var h = clip(hueHandle.width*3.6,[0,360]),
|
||
rgb = hsbToRgb({h:h,s:100,b:100})
|
||
|
||
rgbBg.setAttribute('style','background-color:rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
|
||
|
||
var v = widget.getValue()
|
||
|
||
if (v<widget.value||v>widget.value) {
|
||
widget.value = v
|
||
|
||
widget.sendValue(v)
|
||
widget.showValue(v)
|
||
|
||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
|
||
})
|
||
|
||
|
||
|
||
|
||
|
||
widget.getValue = function() {
|
||
var s = clip(rgbHandle.width,[0,100]),
|
||
l = clip(rgbHandle.height,[0,100]),
|
||
h = mapToScale(hueHandle.width,[0,100],[0,360],widgetData.precision),
|
||
rgb = hsbToRgb({h:h,s:s,b:l})
|
||
return [rgb.r,rgb.g,rgb.b]
|
||
}
|
||
widget.setValue = function(v,send,sync) {
|
||
if (!v || v.length!=3) return
|
||
|
||
for (i in [0,1,2]) {
|
||
v[i] = clip(v[i],[0,255])
|
||
}
|
||
|
||
|
||
var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]})
|
||
|
||
var w = mapToScale(hsb.s,[0,100],[0,100],false),
|
||
h = mapToScale(hsb.b,[0,100],[0,100],false),
|
||
hueW = mapToScale(hsb.h,[0,360],[0,100],false)
|
||
|
||
rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
|
||
hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*hueW/100}px,0,0)`)
|
||
|
||
rgbHandle.height = h
|
||
rgbHandle.width = w
|
||
hueHandle.width = hueW
|
||
widget.value = v
|
||
|
||
|
||
var rgb = hsbToRgb({h:hsb.h,s:100,b:100})
|
||
rgbBg.setAttribute('style','background-color:rgb('+rgb.r+','+rgb.g+','+rgb.b+')')
|
||
|
||
widget.showValue(v)
|
||
|
||
|
||
|
||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
if (send) widget.sendValue(v)
|
||
}
|
||
widget.sendValue = function(v) {
|
||
var args = widgetData.preArgs.concat(v)
|
||
|
||
sendOsc({
|
||
target:split?false:widgetData.target,
|
||
path:widgetData.path,
|
||
args:args,
|
||
precision:widgetData.precision,
|
||
})
|
||
if (split) {
|
||
sendOsc({
|
||
target:widgetData.target,
|
||
path:split.r,
|
||
args:widgetData.preArgs.concat(v[0]),
|
||
precision:widgetData.precision,
|
||
sync:false
|
||
})
|
||
sendOsc({
|
||
target:widgetData.target,
|
||
path:split.g,
|
||
args:widgetData.preArgs.concat(v[1]),
|
||
precision:widgetData.precision,
|
||
sync:false
|
||
})
|
||
sendOsc({
|
||
target:widgetData.target,
|
||
path:split.b,
|
||
args:widgetData.preArgs.concat(v[2]),
|
||
precision:widgetData.precision,
|
||
sync:false
|
||
})
|
||
}
|
||
}
|
||
|
||
|
||
|
||
widget.showValue = function(v) {
|
||
value.r.val(v[0])
|
||
value.g.val(v[1])
|
||
value.b.val(v[2])
|
||
}
|
||
value.r.change(function(){
|
||
var r = clip(value.r.val(),[0,255])
|
||
var v = widget.getValue()
|
||
widget.setValue([r,v[1],v[2]],true,true)
|
||
})
|
||
value.g.change(function(){
|
||
var g = clip(value.g.val(),[0,255])
|
||
var v = widget.getValue()
|
||
widget.setValue([v[0],g,v[2]],true,true)
|
||
})
|
||
value.b.change(function(){
|
||
var b = clip(value.b.val(),[0,255])
|
||
var v = widget.getValue()
|
||
widget.setValue([v[0],v[1],b],true,true)
|
||
})
|
||
|
||
widget.setValue([0,0,0])
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"./utils":37}],32:[function(require,module,exports){
|
||
var {clip, mapToScale, sendOsc} = require('../utils')
|
||
var _canvas_base = require('../common/_canvas_base')
|
||
|
||
var _sliders_base = module.exports = function(){
|
||
|
||
this.widget = $(`
|
||
<div class="slider">
|
||
<div class="wrapper">
|
||
<canvas></canvas>
|
||
</div>
|
||
<div class="input"></div>
|
||
</div>
|
||
`)
|
||
|
||
_canvas_base.apply(this, arguments)
|
||
|
||
this.input = this.widget.find('.input').fakeInput({align:'center'})
|
||
this.roundFactor = Math.pow(10,this.widgetData.precision)
|
||
this.value = undefined
|
||
this.gaugeSize = 0
|
||
|
||
|
||
this.rangeKeys = []
|
||
this.rangeVals = []
|
||
this.rangeLabels = []
|
||
|
||
for (k in this.widgetData.range) {
|
||
var key = k=='min'?0:k=='max'?100:parseInt(k),
|
||
val = typeof this.widgetData.range[k] == 'object'?
|
||
this.widgetData.range[k][Object.keys(this.widgetData.range[k])[0]]:
|
||
this.widgetData.range[k],
|
||
label = typeof this.widgetData.range[k] == 'object'?
|
||
Object.keys(this.widgetData.range[k])[0]:
|
||
val
|
||
|
||
this.rangeKeys.push(key)
|
||
this.rangeVals.push(val)
|
||
this.rangeLabels.push(label)
|
||
}
|
||
this.rangeValsMax = Math.max.apply(Math, this.rangeVals),
|
||
this.rangeValsMin = Math.min.apply(Math, this.rangeVals)
|
||
|
||
|
||
|
||
this.widget.on('fake-right-click',function(e){
|
||
if (!EDITING) {
|
||
e.stopPropagation()
|
||
e.preventDefault()
|
||
this.input.focus()
|
||
}
|
||
}.bind(this))
|
||
|
||
this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this))
|
||
this.canvas.on('draginit',this.draginitHandleProxy.bind(this))
|
||
this.canvas.on('drag',this.dragHandleProxy.bind(this))
|
||
|
||
this.input.change(function(){
|
||
this.widget.setValue(parseFloat(this.input.val()),true,true)
|
||
}.bind(this))
|
||
|
||
this.widget.getValue = function(){
|
||
return this.value
|
||
}.bind(this)
|
||
|
||
this.widget.setValue = this.setValue.bind(this)
|
||
|
||
}
|
||
|
||
_sliders_base.prototype = Object.create(_canvas_base.prototype)
|
||
|
||
_sliders_base.prototype.constructor = _sliders_base
|
||
|
||
|
||
_sliders_base.prototype.mousewheelHandleProxy = function() {
|
||
this.mousewheelHandle.apply(this,arguments)
|
||
}
|
||
|
||
_sliders_base.prototype.draginitHandleProxy = function() {
|
||
this.draginitHandle.apply(this,arguments)
|
||
}
|
||
|
||
_sliders_base.prototype.dragHandleProxy = function() {
|
||
this.dragHandle.apply(this,arguments)
|
||
}
|
||
|
||
|
||
_sliders_base.prototype.mousewheelHandle = function(e, data, traversing) {
|
||
if (e.originalEvent.wheelDeltaX) return
|
||
|
||
e.preventDefault()
|
||
e.stopPropagation()
|
||
|
||
var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta),
|
||
increment = e.ctrlKey?0.005:0.01
|
||
console.log(this.gaugeSize, increment, direction)
|
||
|
||
this.gaugeSize = clip(this.gaugeSize + increment * direction ,[0,1])
|
||
|
||
this.setValue(this.mapGaugeSizeToRange(this.gaugeSize), true, true)
|
||
|
||
|
||
}
|
||
|
||
_sliders_base.prototype.draginitHandle = function(e, data, traversing) {
|
||
|
||
}
|
||
|
||
_sliders_base.prototype.dragHandle = function(e, data, traversing) {
|
||
|
||
}
|
||
|
||
|
||
_sliders_base.prototype.resizeHandle = function() {
|
||
if (!self.visible) {
|
||
this.colors.track = getComputedStyle(this.widget[0]).getPropertyValue('--color-track')
|
||
this.colors.gauge = getComputedStyle(this.widget[0]).getPropertyValue('--color-gauge')
|
||
this.colors.knob = getComputedStyle(this.widget[0]).getPropertyValue('--color-knob')
|
||
}
|
||
_canvas_base.prototype.resizeHandle.call(this)
|
||
}
|
||
|
||
|
||
_sliders_base.prototype.mapGaugeSizeToRange = function() {
|
||
var h = clip(this.gaugeSize*100,[0,100])
|
||
for (var i=0;i<this.rangeKeys.length-1;i++) {
|
||
if (h <= this.rangeKeys[i+1] && h >= this.rangeKeys[i]) {
|
||
return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],this.widgetData.precision,this.widgetData.logScale)
|
||
}
|
||
}
|
||
}
|
||
_sliders_base.prototype.mapValueToGaugeSize = function() {
|
||
var v = this.value
|
||
|
||
for (var i=0;i<this.rangeVals.length-1;i++) {
|
||
if (v <= this.rangeVals[i+1] && v >= this.rangeVals[i]) {
|
||
return mapToScale(v,[this.rangeVals[i],this.rangeVals[i+1]],[this.rangeKeys[i],this.rangeKeys[i+1]],false,this.widgetData.logScale,true) / 100
|
||
}
|
||
}
|
||
}
|
||
|
||
_sliders_base.prototype.setValue = function(v,send,sync, dragged) {
|
||
if (typeof v != 'number') return
|
||
|
||
this.value = clip(Math.round(v*this.roundFactor)/this.roundFactor,[this.rangeValsMin,this.rangeValsMax])
|
||
|
||
if (!dragged) this.gaugeSize = this.mapValueToGaugeSize()
|
||
|
||
this.draw()
|
||
|
||
this.showValue()
|
||
|
||
if (sync) this.widget.trigger('sync',[this.widgetData.id,this.widget,this.widgetData.linkId])
|
||
if (send) this.sendValue(v)
|
||
}
|
||
|
||
_sliders_base.prototype.sendValue = function(value) {
|
||
var args = this.widgetData.preArgs.concat(value)
|
||
|
||
sendOsc({
|
||
target:this.widgetData.target,
|
||
path:this.widgetData.path,
|
||
precision:this.widgetData.precision,
|
||
args:args
|
||
})
|
||
|
||
}
|
||
|
||
_sliders_base.prototype.showValue = function() {
|
||
this.input.val(this.value + ' ' + this.widgetData.unit)
|
||
}
|
||
|
||
},{"../common/_canvas_base":15,"../utils":37}],33:[function(require,module,exports){
|
||
var {clip, mapToScale, sendOsc} = require('../utils'),
|
||
_sliders_base = require('./_sliders_base')
|
||
|
||
var Fader = function(widgetData){
|
||
|
||
_sliders_base.apply(this,arguments)
|
||
this.widget.addClass('fader-v2')
|
||
this.margin = 20
|
||
|
||
|
||
if (widgetData.horizontal) {
|
||
this.widget.addClass('horizontal')
|
||
}
|
||
|
||
if (widgetData.compact) {
|
||
this.widget.addClass('compact')
|
||
this.margin = 0
|
||
}
|
||
|
||
if (widgetData.alignRight) {
|
||
this.widget.addClass('align-right')
|
||
}
|
||
|
||
if (!widgetData.noPip&&!widgetData.compact) {
|
||
|
||
this.widget.addClass('has-pips')
|
||
|
||
var pips = $('<div class="pips"></div>').appendTo(this.widget.find('.wrapper'))
|
||
var pipTexts = {}
|
||
for (k in this.rangeKeys) {
|
||
pipTexts[this.rangeKeys[k]]=this.rangeLabels[k]
|
||
}
|
||
|
||
var pipsInner = ''
|
||
for (var i=0;i<=100;i++) {
|
||
if (pipTexts[i]==undefined) continue
|
||
|
||
var pos = widgetData.horizontal?'left':'bottom';
|
||
|
||
var piptext = `<span>${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}</span>`
|
||
|
||
var add = `
|
||
<div class="pip val" style="${pos}:${i}%">${piptext}</div>
|
||
`
|
||
pipsInner = pipsInner + add
|
||
}
|
||
pips[0].innerHTML = pipsInner
|
||
}
|
||
|
||
this.setValue(this.rangeVals[0])
|
||
|
||
|
||
}
|
||
|
||
Fader.prototype = Object.create(_sliders_base.prototype)
|
||
|
||
Fader.prototype.constructor = Fader
|
||
|
||
Fader.prototype.draginitHandle = function(e, data, traversing){
|
||
|
||
if (!(traversing || this.widgetData.snap)) return
|
||
|
||
this.gaugeSize = this.widgetData.horizontal?
|
||
(data.offsetX - this.margin * PXSCALE) / (this.width - (this.margin * PXSCALE * 2)):
|
||
(this.height - data.offsetY - this.margin * PXSCALE) / (this.height - (this.margin * PXSCALE * 2))
|
||
|
||
this.gaugeSize = clip(this.gaugeSize,[0,1])
|
||
|
||
this.setValue(this.mapGaugeSizeToRange(this.gaugeSize), true, true, true)
|
||
|
||
}
|
||
|
||
Fader.prototype.dragHandle = function(e, data) {
|
||
|
||
this.gaugeSize = this.widgetData.horizontal?
|
||
this.gaugeSize + ( data.speedX/(this.width - this.margin * PXSCALE * 2)):
|
||
this.gaugeSize + (-data.speedY/(this.height - this.margin * PXSCALE * 2))
|
||
|
||
this.gaugeSize = this.gaugeSize,[0,1]
|
||
|
||
this.setValue(this.mapGaugeSizeToRange(this.gaugeSize), true, true, true)
|
||
|
||
}
|
||
|
||
|
||
Fader.prototype.draw = function(){
|
||
|
||
var px = PXSCALE
|
||
d = this.widgetData.horizontal?
|
||
clip(this.gaugeSize,[0,1]) * (this.width - 2 * px * this.margin):
|
||
(this.height - this.margin * px) - clip(this.gaugeSize, [0,1]) * (this.height - 2 * px * this.margin)
|
||
|
||
this.ctx.clearRect(0,0,this.width,this.height)
|
||
|
||
if (this.widgetData.horizontal) {
|
||
if (this.widgetData.compact) {
|
||
|
||
this.ctx.fillStyle = this.colors.accent
|
||
|
||
this.ctx.save()
|
||
this.ctx.globalAlpha = 0.3
|
||
this.ctx.beginPath()
|
||
this.ctx.rect(0, 0, d, this.height)
|
||
this.ctx.fill()
|
||
this.ctx.restore()
|
||
|
||
this.ctx.beginPath()
|
||
this.ctx.rect(Math.min(d,this.width-px), 0, px, this.height)
|
||
this.ctx.fill()
|
||
|
||
|
||
} else {
|
||
|
||
this.ctx.beginPath()
|
||
this.ctx.fillStyle = this.colors.track
|
||
this.ctx.rect(this.margin * px, this.height / 2 - 1 * px, this.width - this.margin * 2 * px, 2 * px)
|
||
this.ctx.fill()
|
||
|
||
this.ctx.fillStyle = this.colors.accent
|
||
this.ctx.beginPath()
|
||
this.ctx.rect(this.margin * px, this.height / 2 - 1 * px, d, 2 * px)
|
||
this.ctx.fill()
|
||
|
||
this.ctx.save()
|
||
this.ctx.globalAlpha = 0.3
|
||
this.ctx.arc(d + this.margin * px, this.height / 2, 10 *px, Math.PI * 2,false)
|
||
this.ctx.fill()
|
||
this.ctx.restore()
|
||
|
||
this.ctx.beginPath()
|
||
this.ctx.arc(d + this.margin * px, this.height / 2, 4 * px, Math.PI * 2,false)
|
||
this.ctx.fill()
|
||
}
|
||
|
||
|
||
} else {
|
||
|
||
if (this.widgetData.compact) {
|
||
|
||
this.ctx.fillStyle = this.colors.accent
|
||
|
||
this.ctx.save()
|
||
this.ctx.globalAlpha = 0.3
|
||
this.ctx.beginPath()
|
||
this.ctx.rect(0, d, this.width, (this.height - this.margin * px) - d)
|
||
this.ctx.fill()
|
||
this.ctx.restore()
|
||
|
||
this.ctx.beginPath()
|
||
this.ctx.rect(0, Math.min(d,this.height-px), this.width, px)
|
||
this.ctx.fill()
|
||
|
||
|
||
} else {
|
||
|
||
this.ctx.beginPath()
|
||
this.ctx.fillStyle = this.colors.track
|
||
this.ctx.rect(this.width / 2 - 1 * px, this.margin * px, 2 * px, this.height - this.margin *2 * px)
|
||
this.ctx.fill()
|
||
|
||
this.ctx.fillStyle = this.colors.accent
|
||
this.ctx.beginPath()
|
||
this.ctx.rect(this.width / 2 - 1 * px, d, 2 * px, (this.height - this.margin * px) - d)
|
||
this.ctx.fill()
|
||
|
||
this.ctx.save()
|
||
this.ctx.globalAlpha = 0.3
|
||
this.ctx.arc(this.width / 2, d, 10 *px, Math.PI * 2,false)
|
||
this.ctx.fill()
|
||
this.ctx.restore()
|
||
|
||
this.ctx.beginPath()
|
||
this.ctx.arc(this.width / 2, d, 4 *px, Math.PI * 2,false)
|
||
this.ctx.fill()
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
module.exports.options = {
|
||
type:'fader',
|
||
id:'auto',
|
||
linkId:'',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
unit:'',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
alignRight:false,
|
||
horizontal:false,
|
||
noPip:false,
|
||
compact:false,
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'behaviour',
|
||
|
||
snap:false,
|
||
|
||
separator3:'osc',
|
||
|
||
range:{min:0,max:1},
|
||
logScale:false,
|
||
precision:2,
|
||
meter:false,
|
||
path:'auto',
|
||
preArgs:[],
|
||
target:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var fader = new Fader(widgetData, container)
|
||
return fader.widget
|
||
}
|
||
|
||
},{"../utils":37,"./_sliders_base":32}],34:[function(require,module,exports){
|
||
|
||
module.exports.options = {
|
||
type:'strip',
|
||
id:'auto',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
horizontal:false,
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'children',
|
||
|
||
widgets:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var parsewidgets = require('../parser').widgets
|
||
|
||
var widget = $(`
|
||
<div class="strip">
|
||
</div>
|
||
`)
|
||
if (widgetData.horizontal) {
|
||
container.addClass('horizontal')
|
||
} else {
|
||
container.addClass('vertical')
|
||
}
|
||
|
||
parsewidgets(widgetData.widgets,widget)
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"../parser":10}],35:[function(require,module,exports){
|
||
var sendOsc = require('./utils').sendOsc
|
||
|
||
module.exports.options = {
|
||
type:'switch',
|
||
id:'auto',
|
||
linkId:'',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
horizontal:false,
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'osc',
|
||
|
||
values:{"Value 1":1,"Value 2":2},
|
||
precision:2,
|
||
path:'auto',
|
||
preArgs:[],
|
||
target:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var widget = $(`
|
||
<div class="switch">
|
||
</div>
|
||
`),
|
||
$document = $(document)
|
||
|
||
if (widgetData.horizontal) {
|
||
widget.addClass('horizontal')
|
||
}
|
||
|
||
widget.values = []
|
||
|
||
for (k in widgetData.values) {
|
||
widget.values.push(widgetData.values[k])
|
||
$('<div class="value">'+k+'</div>').data({value:widgetData.values[k]}).appendTo(widget)
|
||
}
|
||
|
||
widget.value = undefined
|
||
|
||
widget.find('.value').on('draginit',function(e,dd){
|
||
var data = $(this).data()
|
||
if (data.value!=widget.value || widget.value===undefined) widget.setValue(data.value,true,true)
|
||
})
|
||
|
||
|
||
|
||
widget.getValue = function() {
|
||
return widget.value
|
||
}
|
||
widget.setValue = function(v,send,sync) {
|
||
var i = widget.values.indexOf(v)
|
||
if (i!=-1) {
|
||
widget.value = widget.values[i]
|
||
widget.find('.on').removeClass('on')
|
||
widget.find('.value').eq(i).addClass('on').removeClass('ripple').addClass('ripple').delay(250).queue(function(next){
|
||
$(this).removeClass('ripple')
|
||
next()
|
||
})
|
||
if (send) widget.sendValue(widget.value)
|
||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
|
||
}
|
||
widget.sendValue = function(v) {
|
||
var args = widgetData.preArgs.concat(v)
|
||
|
||
sendOsc({
|
||
target:widgetData.target,
|
||
path:widgetData.path,
|
||
precision:widgetData.precision,
|
||
args:args
|
||
})
|
||
}
|
||
return widget
|
||
}
|
||
|
||
},{"./utils":37}],36:[function(require,module,exports){
|
||
var sendOsc = require('./utils').sendOsc
|
||
|
||
module.exports.options = {
|
||
type:'toggle',
|
||
id:'auto',
|
||
linkId:'',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'osc',
|
||
|
||
on:1,
|
||
off:0,
|
||
precision:2,
|
||
path:'auto',
|
||
preArgs:[],
|
||
target:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var widget = $(`
|
||
<div class="light">
|
||
</div>\
|
||
`),
|
||
$document = $(document)
|
||
|
||
widget.value = widget.find('span')
|
||
widget.state = 0
|
||
|
||
widget.on('drag',function(e){e.stopPropagation()})
|
||
widget.on('draginit.toggle',function(){
|
||
widget.off('draginit.toggle')
|
||
widget.fakeclick()
|
||
})
|
||
|
||
widget.fakeclick = function(){
|
||
var newVal = widget.state?widgetData.off:widgetData.on
|
||
widget.setValue(newVal,true,true)
|
||
$document.on('dragend.toggle',function(){
|
||
$document.off('dragend.toggle')
|
||
widget.on('draginit.toggle',function(){
|
||
widget.off('draginit.toggle')
|
||
widget.fakeclick()
|
||
})
|
||
})
|
||
}
|
||
|
||
|
||
widget.getValue = function() {
|
||
return widget.state?widgetData.on:widgetData.off
|
||
}
|
||
widget.setValue = function(v,send,sync) {
|
||
if (v===widgetData.on || (v=='false'&&widgetData.on===false)) {
|
||
widget.addClass('on')
|
||
widget.state = 1
|
||
if (send) widget.sendValue(widgetData.on)
|
||
} else if (v===widgetData.off || (v=='false'&&widgetData.off===false)) {
|
||
widget.removeClass('on')
|
||
widget.state = 0
|
||
if (send) widget.sendValue(widgetData.off)
|
||
}
|
||
|
||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
|
||
}
|
||
widget.sendValue = function(v) {
|
||
if (v===false) return
|
||
var args = widgetData.preArgs.concat(v)
|
||
|
||
sendOsc({
|
||
target:widgetData.target,
|
||
path:widgetData.path,
|
||
precision:widgetData.precision,
|
||
args:args
|
||
})
|
||
}
|
||
widget.setValue()
|
||
return widget
|
||
}
|
||
|
||
},{"./utils":37}],37:[function(require,module,exports){
|
||
module.exports = {
|
||
|
||
sendOsc: function(data){
|
||
IPC.send('sendOsc', data)
|
||
},
|
||
|
||
clip: function(value,range) {
|
||
var value = parseFloat(value)
|
||
|
||
if (isNaN(value)) value = range[0]
|
||
return Math.max(Math.min(range[0],range[1]),Math.min(value,Math.max(range[0],range[1])))
|
||
|
||
},
|
||
|
||
// map a value from a scale to another input and output must be range arrays
|
||
mapToScale: function(value,rangeIn,rangeOut,precision,log,revertlog) {
|
||
|
||
var value = module.exports.clip(value,[rangeIn[0],rangeIn[1]]),
|
||
roundFactor = precision!=undefined?Math.pow(10,precision):100,
|
||
|
||
|
||
value = log?
|
||
revertlog?
|
||
(Math.pow(10,((value-rangeIn[0])/(rangeIn[1]-rangeIn[0])))/9-1/9) * (rangeOut[1]-rangeOut[0]) + rangeOut[0]
|
||
:Math.log10(((value-rangeIn[0])/(rangeIn[1]-rangeIn[0]))*9+1) * (rangeOut[1]-rangeOut[0]) + rangeOut[0]
|
||
:((value-rangeIn[0])/(rangeIn[1]-rangeIn[0])) * (rangeOut[1]-rangeOut[0]) + rangeOut[0]
|
||
|
||
value = Math.max(Math.min(rangeOut[0],rangeOut[1]),Math.min(value,Math.max(rangeOut[0],rangeOut[1])))
|
||
|
||
if (precision!==false) value = Math.round(value*roundFactor)/roundFactor
|
||
|
||
|
||
return value
|
||
|
||
},
|
||
|
||
hsbToRgb: function (hsb) {
|
||
var rgb = {}
|
||
var h = hsb.h
|
||
var s = hsb.s*255/100
|
||
var v = hsb.b*255/100
|
||
if(s == 0) {
|
||
rgb.r = rgb.g = rgb.b = v
|
||
} else {
|
||
var t1 = v
|
||
var t2 = (255-s)*v/255
|
||
var t3 = (t1-t2)*(h%60)/60
|
||
if(h==360) h = 0
|
||
if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
|
||
else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
|
||
else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
|
||
else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
|
||
else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
|
||
else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
|
||
else {rgb.r=0; rgb.g=0; rgb.b=0}
|
||
}
|
||
return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)}
|
||
},
|
||
|
||
rgbToHsb: function (rgb) {
|
||
var hsb = {h: 0, s: 0, b: 0}
|
||
var min = Math.min(rgb.r, rgb.g, rgb.b)
|
||
var max = Math.max(rgb.r, rgb.g, rgb.b)
|
||
var delta = max - min
|
||
hsb.b = max
|
||
hsb.s = max != 0 ? 255 * delta / max : 0
|
||
if (hsb.s != 0) {
|
||
if (rgb.r == max) hsb.h = (rgb.g - rgb.b) / delta
|
||
else if (rgb.g == max) hsb.h = 2 + (rgb.b - rgb.r) / delta
|
||
else hsb.h = 4 + (rgb.r - rgb.g) / delta
|
||
} else hsb.h = 0
|
||
hsb.h *= 60
|
||
if (hsb.h < 0) hsb.h += 360
|
||
hsb.s *= 100/255
|
||
hsb.b *= 100/255
|
||
return hsb
|
||
}
|
||
}
|
||
|
||
},{}],38:[function(require,module,exports){
|
||
var utils = require('./utils'),
|
||
clip = utils.clip,
|
||
mapToScale = utils.mapToScale,
|
||
sendOsc = utils.sendOsc
|
||
|
||
module.exports.options = {
|
||
type:'xy',
|
||
id:'auto',
|
||
linkId:'',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
color:'auto',
|
||
css:'',
|
||
|
||
separator2:'behaviour',
|
||
|
||
snap:false,
|
||
|
||
separator3:'osc',
|
||
|
||
rangeX:{min:0,max:1},
|
||
rangeY:{min:0,max:1},
|
||
logScaleX:false,
|
||
logScaleY:false,
|
||
precision:2,
|
||
path:'auto',
|
||
preArgs:[],
|
||
split:false,
|
||
target:[]
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
var widget = $(`
|
||
<div class="xy-wrapper">
|
||
<div class="xy">
|
||
<div class="handle"></div>
|
||
</div>
|
||
<div class="value">
|
||
<div class="input disabled">X</div><div class="input disabled">Y</div>
|
||
<div class="input x"></div><div class="input y"></div>
|
||
</div>
|
||
</div>
|
||
`),
|
||
handle = widget.find('.handle'),
|
||
pad = widget.find('.xy'),
|
||
value = {x:widget.find('.x').fakeInput({align:'center'}),y:widget.find('.y').fakeInput({align:'center'})},
|
||
range = {x:widgetData.rangeX,y:widgetData.rangeY},
|
||
snap = widgetData.snap,
|
||
split = widgetData.split?
|
||
typeof widgetData.split == 'object'?
|
||
widgetData.split:{x:widgetData.path+'/x',y:widgetData.path+'/y'}
|
||
:false;
|
||
logScaleX = widgetData.logScaleX,
|
||
logScaleY = widgetData.logScaleY,
|
||
roundFactor = Math.pow(10,widgetData.precision)
|
||
|
||
|
||
if (widgetData.height!='auto') widget.addClass('manual-height')
|
||
|
||
pad.width = 0
|
||
pad.height = 0
|
||
handle.height = 0
|
||
handle.width = 0
|
||
widget.value = undefined
|
||
|
||
pad.resize(function(){
|
||
var width = pad.innerWidth(),
|
||
height = pad.innerHeight()
|
||
if (!width || (pad.height==height && pad.width==width)) return
|
||
pad.width = width
|
||
pad.height = height
|
||
|
||
widget.updateUi(handle.width,handle.height)
|
||
})
|
||
|
||
var off = {x:0,y:0}
|
||
pad.on('draginit',function(e,data,traversing){
|
||
|
||
if (snap || traversing) {
|
||
var h = ((pad.height-data.offsetY) * 100 / pad.height),
|
||
w = (data.offsetX * 100 / pad.width)
|
||
|
||
widget.updateUi(w,h)
|
||
|
||
handle.height = h
|
||
handle.width = w
|
||
|
||
var v = widget.getValue()
|
||
|
||
if (v<widget.value||v>widget.value) {
|
||
widget.value = v
|
||
|
||
widget.sendValue(v)
|
||
widget.showValue(v)
|
||
|
||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
|
||
}
|
||
|
||
off = {x:handle.width,y:handle.height}
|
||
|
||
})
|
||
pad.on('drag',function(e,data){
|
||
|
||
var h = clip((-data.deltaY)*100/pad.height+off.y,[0,100]),
|
||
w = clip((data.deltaX)*100/pad.width+off.x,[0,100])
|
||
|
||
widget.updateUi(w,h)
|
||
|
||
handle.height = h
|
||
handle.width = w
|
||
|
||
var v = widget.getValue()
|
||
|
||
if (v<widget.value||v>widget.value) {
|
||
widget.value = v
|
||
|
||
widget.sendValue(v)
|
||
widget.showValue(v)
|
||
|
||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
}
|
||
|
||
})
|
||
|
||
|
||
widget.updateUi = function(w,h) {
|
||
handle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
|
||
}
|
||
|
||
widget.getValue = function() {
|
||
var x = mapToScale(handle.width,[0,100],[range.x.min,range.x.max],widgetData.precision,logScaleX),
|
||
y = mapToScale(handle.height,[0,100],[range.y.min,range.y.max],widgetData.precision,logScaleY)
|
||
|
||
return [x,y]
|
||
}
|
||
widget.setValue = function(v,send,sync) {
|
||
if (!v || v.length!=2) return
|
||
|
||
for (i in [0,1]) {
|
||
v[i] = clip(Math.round(v[i]*roundFactor)/roundFactor,[range[['x','y'][i]].min,range[['x','y'][i]].max])
|
||
}
|
||
|
||
var w = mapToScale(v[0],[range.x.min,range.x.max],[0,100],false,logScaleX,true)
|
||
h = mapToScale(v[1],[range.y.min,range.y.max],[0,100],false,logScaleY,true),
|
||
|
||
|
||
widget.updateUi(w,h)
|
||
|
||
handle.height = h
|
||
handle.width = w
|
||
widget.value = v
|
||
|
||
widget.showValue(v)
|
||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||
if (send) widget.sendValue(v)
|
||
}
|
||
widget.sendValue = function(v) {
|
||
var args = widgetData.preArgs.concat(v)
|
||
|
||
sendOsc({
|
||
target:split?false:widgetData.target,
|
||
path:widgetData.path,
|
||
args:args,
|
||
precision:widgetData.precision,
|
||
})
|
||
if (split) {
|
||
sendOsc({
|
||
target:widgetData.target,
|
||
path:split.x,
|
||
args:widgetData.preArgs.concat(v[0]),
|
||
precision:widgetData.precision,
|
||
sync:false
|
||
})
|
||
sendOsc({
|
||
target:widgetData.target,
|
||
path:split.y,
|
||
args:widgetData.preArgs.concat(v[1]),
|
||
precision:widgetData.precision,
|
||
sync:false
|
||
})
|
||
}
|
||
}
|
||
|
||
widget.showValue = function(v) {
|
||
value.x.val(v[0])
|
||
value.y.val(v[1])
|
||
}
|
||
|
||
value.x.change(function(){
|
||
var v = widget.getValue()
|
||
v[0] = clip(value.x.val(),[range.x.min,range.x.max])
|
||
widget.setValue(v,true,true)
|
||
})
|
||
value.y.change(function(){
|
||
var v = widget.getValue()
|
||
v[1] = clip(value.y.val(),[range.y.min,range.y.max])
|
||
widget.setValue(v,true,true)
|
||
})
|
||
|
||
widget.setValue([range.x.min,range.y.min])
|
||
return widget
|
||
}
|
||
|
||
},{"./utils":37}],39:[function(require,module,exports){
|
||
WEBFRAME = false
|
||
|
||
// mainProcess & renderProcess communication engine
|
||
// electron's ipc module is not available here, we use socket.io as a replacement
|
||
var socket = require('socket.io-client')
|
||
|
||
IPC = socket.connect()
|
||
IPC.send = IPC.emit
|
||
|
||
|
||
require('./app')
|
||
|
||
},{"./app":1,"socket.io-client":77}],40:[function(require,module,exports){
|
||
// jQuery drag event handler
|
||
// note: triggerHandler() is used instead of trigger() when event bubblig is not
|
||
// necessary, this increases performances a lot.
|
||
;(function($){
|
||
var events = {
|
||
touch:{start:'touchstart',stop:'touchend touchcancel',move:'touchmove',touch:true},
|
||
mouse:{start:'mousedown',stop:'mouseup',move:'mousemove',out:'mouseout',touch:false}
|
||
},
|
||
|
||
|
||
$document = $(document),
|
||
getOffset = function(obj) {
|
||
var offsetLeft = 0
|
||
var offsetTop = 0
|
||
if (obj) {
|
||
do {
|
||
if (!isNaN(obj.offsetLeft)) {
|
||
offsetLeft += obj.offsetLeft - obj.scrollLeft
|
||
}
|
||
if (!isNaN(obj.offsetTop)) {
|
||
offsetTop += obj.offsetTop - obj.scrollTop
|
||
}
|
||
} while(obj = obj.offsetParent )
|
||
}
|
||
|
||
return {left: offsetLeft, top: offsetTop}
|
||
}
|
||
|
||
|
||
$.event.special.draginit = $.event.special.drag = {
|
||
setup:function(){
|
||
|
||
var $this = $(this)
|
||
|
||
if ($this.data('dragSetup')) return
|
||
$this.data('dragSetup','true')
|
||
|
||
|
||
// mouse single touch handler
|
||
var previousEvent = null,
|
||
target = null,
|
||
traversing = false,
|
||
mouseStartHandler = function(e){
|
||
|
||
// ignore mouse event when fired by a simulated touch event
|
||
if (e.originalEvent.sourceCapabilities.firesTouchEvents) return
|
||
|
||
isPointerDown = true
|
||
target = $this
|
||
previousEvent = e
|
||
|
||
e.speedX = 0
|
||
e.speedY = 0
|
||
e.deltaX = 0
|
||
e.deltaY = 0
|
||
|
||
target.triggerHandler('draginit',[e,e.originalEvent.traversing])
|
||
|
||
$document.on(events.mouse.move,mouseMoveHandler)
|
||
$document.on(events.mouse.stop,mouseStopHandler)
|
||
$document.on(events.mouse.out,mouseOutHandler)
|
||
|
||
},
|
||
mouseMoveHandler = function(e){
|
||
e.stopPropagation()
|
||
|
||
e.speedX = e.pageX - previousEvent.pageX
|
||
e.speedY = e.pageY - previousEvent.pageY
|
||
e.deltaX = e.speedX + previousEvent.deltaX
|
||
e.deltaY = e.speedY + previousEvent.deltaY
|
||
|
||
|
||
if (e.originalEvent.traversing) {
|
||
target = $(e.target)
|
||
e.preventDefault()
|
||
target.triggerHandler('draginit',[e,e.originalEvent.traversing])
|
||
} else {
|
||
target.triggerHandler('drag',[e,e.originalEvent.traversing])
|
||
}
|
||
|
||
previousEvent = e
|
||
},
|
||
mouseStopHandler = function(e){
|
||
e.stopPropagation()
|
||
|
||
// ignore mouse event when fired by a simulated touch event
|
||
if (e.originalEvent.sourceCapabilities.firesTouchEvents) return
|
||
|
||
e.speedX = e.pageX - previousEvent.pageX
|
||
e.speedY = e.pageY - previousEvent.pageY
|
||
e.deltaX = e.deltaX + previousEvent.deltaX
|
||
e.deltaY = e.deltaY + previousEvent.deltaY
|
||
|
||
|
||
target.trigger('dragend',[e,e.originalEvent.traversing])
|
||
isPointerDown = false
|
||
$document.off(events.mouse.move,mouseMoveHandler)
|
||
$document.off(events.mouse.stop,mouseStopHandler)
|
||
$document.off(events.mouse.out,mouseOutHandler)
|
||
},
|
||
mouseOutHandler = function(e){
|
||
if (e.originalEvent.traversing) {
|
||
e.stopPropagation()
|
||
|
||
e.speedX = e.pageX - previousEvent.pageX
|
||
e.speedY = e.pageY - previousEvent.pageY
|
||
e.deltaX = e.deltaX + previousEvent.deltaX
|
||
e.deltaY = e.deltaY + previousEvent.deltaY
|
||
|
||
target.trigger('dragend',[e,e.originalEvent.traversing])
|
||
|
||
previousEvent = e
|
||
|
||
}
|
||
}
|
||
|
||
|
||
$this.on(events.mouse.start,mouseStartHandler)
|
||
|
||
|
||
// multi touch hanlder
|
||
window.targets = window.targets || {}
|
||
window.previousTouches = window.previousTouches || {}
|
||
window.touchActive = window.touchActive || false
|
||
|
||
var self = this,
|
||
touchStartHandler = function(e){
|
||
e.preventDefault()
|
||
|
||
var oE = e.originalEvent
|
||
|
||
for (i in oE.changedTouches) {
|
||
if (isNaN(i)) continue
|
||
|
||
var touch = oE.changedTouches[i],
|
||
id = touch.identifier
|
||
|
||
targets[id] = $(touch.target)
|
||
previousTouches[id] = touch
|
||
|
||
touch.speedX = 0
|
||
touch.speedY = 0
|
||
|
||
touch.deltaX = 0
|
||
touch.deltaY = 0
|
||
|
||
var off = getOffset(touch.target)
|
||
touch.offsetX = touch.pageX-off.left
|
||
touch.offsetY = touch.pageY-off.top
|
||
|
||
targets[id].triggerHandler('draginit',[touch,e.originalEvent.traversing])
|
||
|
||
}
|
||
|
||
if (!touchActive) {
|
||
$document.on(events.touch.move,touchMoveHandler)
|
||
$document.on(events.touch.stop,touchStopHandler)
|
||
touchActive = true
|
||
}
|
||
|
||
},
|
||
touchMoveHandler = function(e){
|
||
|
||
var oE = e.originalEvent
|
||
|
||
for (i in oE.changedTouches) {
|
||
if (isNaN(i)) continue
|
||
|
||
|
||
var touch = oE.changedTouches[i],
|
||
id = touch.identifier
|
||
|
||
if (e.originalEvent.traversing) {
|
||
targets[id] = $(document.elementFromPoint(touch.clientX, touch.clientY))
|
||
}
|
||
|
||
// touched[targets[id]] = touched[targets[id]]?touched[targets[id]]+1:1
|
||
|
||
touch.speedX = touch.pageX - previousTouches[id].pageX
|
||
touch.speedY = touch.pageY - previousTouches[id].pageY
|
||
|
||
touch.deltaX = touch.speedX + previousTouches[id].deltaX
|
||
touch.deltaY = touch.speedY + previousTouches[id].deltaY
|
||
|
||
touch.offsetX = previousTouches[id].offsetX+touch.speedX
|
||
touch.offsetY = previousTouches[id].offsetY+touch.speedY
|
||
|
||
if (e.originalEvent.traversing) {
|
||
touch.traversing = true
|
||
var previousTarget = document.elementFromPoint(previousTouches[id].clientX, previousTouches[id].clientY)
|
||
if (targets[id][0]!=previousTarget) {
|
||
var off = getOffset(targets[id][0])
|
||
touch.offsetX = touch.pageX-off.left
|
||
touch.offsetY = touch.pageY-off.top
|
||
$(previousTarget).trigger('dragend',[touch,e.originalEvent.traversing])
|
||
}
|
||
e.preventDefault()
|
||
if (oE.traversingContainer.contains(targets[id][0])) targets[id].triggerHandler('draginit',[touch,e.originalEvent.traversing])
|
||
|
||
} else {
|
||
|
||
targets[id].triggerHandler('drag',[touch,e.originalEvent.traversing])
|
||
|
||
}
|
||
|
||
previousTouches[id] = touch
|
||
|
||
}
|
||
|
||
},
|
||
touchStopHandler = function(e){
|
||
|
||
var oE = e.originalEvent
|
||
|
||
for (i in oE.changedTouches) {
|
||
|
||
if (isNaN(i)) continue
|
||
|
||
var touch = oE.changedTouches[i],
|
||
id = touch.identifier
|
||
|
||
$(oE.changedTouches[i].target).trigger('dragend',[touch,e.originalEvent.traversing])
|
||
|
||
delete previousTouches[id]
|
||
delete targets[id]
|
||
|
||
}
|
||
|
||
if (oE.touches.length==0) {
|
||
$document.off(events.touch.move,touchMoveHandler)
|
||
$document.off(events.touch.stop,touchStopHandler)
|
||
touchActive = false
|
||
}
|
||
|
||
}
|
||
|
||
$this.on(events.touch.start,touchStartHandler)
|
||
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
var makeEventTraversing = function(e){
|
||
e.traversing=true
|
||
if (!e.traversingContainer) e.traversingContainer=this
|
||
}
|
||
|
||
|
||
$.fn.enableTraversingGestures = function() {
|
||
|
||
var self = this[0]
|
||
|
||
var down = function(e){
|
||
makeEventTraversing(e)
|
||
self.addEventListener("mousemove", makeEventTraversing, true)
|
||
self.addEventListener("touchmove", makeEventTraversing, true)
|
||
self.addEventListener("mouseout", makeEventTraversing, true)
|
||
document.addEventListener("mouseup",up,true)
|
||
document.addEventListener("touchend",up,true)
|
||
},
|
||
up = function(){
|
||
self.removeEventListener("mousemove", makeEventTraversing, true)
|
||
self.removeEventListener("touchmove", makeEventTraversing, true)
|
||
self.removeEventListener("mouseout", makeEventTraversing, true)
|
||
document.removeEventListener("mouseup",up,true)
|
||
document.removeEventListener("touchend",up,true)
|
||
}
|
||
|
||
self.addEventListener("mousedown", down, true)
|
||
self.addEventListener("touchstart", down, true)
|
||
|
||
|
||
this.on('disableTraversingGestures',function() {
|
||
self.removeEventListener("mousedown", down, true)
|
||
self.removeEventListener("touchstart", down, true)
|
||
})
|
||
|
||
|
||
return this
|
||
|
||
}
|
||
|
||
|
||
$document.on('mousedown',function(e){
|
||
|
||
if (e.originalEvent.sourceCapabilities && e.originalEvent.sourceCapabilities.firesTouchEvents) return
|
||
|
||
$(e.target).trigger('fake-click')
|
||
|
||
if (e.button==2) {
|
||
e.preventDefault()
|
||
$(e.target).trigger('fake-right-click',e)
|
||
}
|
||
|
||
})
|
||
|
||
var touchTapTimer = false,
|
||
clearTouchTapTimer = function() {
|
||
clearTimeout(touchTapTimer)
|
||
touchTapTimer = false
|
||
}
|
||
|
||
$document.on(events.touch.start,function(e){
|
||
$(e.target).trigger('fake-click')
|
||
|
||
if (!touchTapTimer&&e.originalEvent.touches.length==1) {
|
||
touchTapTimer = setTimeout(function(){
|
||
if (touchTapTimer) {
|
||
var touch = e.originalEvent.changedTouches[0],
|
||
off = getOffset(touch.target)
|
||
|
||
touch.offsetX = touch.pageX-off.left
|
||
touch.offsetY = touch.pageY-off.top
|
||
$(e.originalEvent.changedTouches[0].target).trigger('fake-right-click',touch)
|
||
}
|
||
touchTapTimer = false
|
||
},600)
|
||
} else {
|
||
clearTouchTapTimer()
|
||
}
|
||
})
|
||
|
||
$document.on(events.touch.stop + ' ' + events.touch.move,function(e){
|
||
clearTouchTapTimer()
|
||
})
|
||
|
||
$document.on('contextmenu',function(){return false})
|
||
|
||
})(jQuery)
|
||
|
||
},{}],41:[function(require,module,exports){
|
||
;(function ($) {
|
||
$.fn.fakeInput = function(options) {
|
||
|
||
var settings = $.extend({
|
||
align:'left'
|
||
}, options );
|
||
|
||
var self= this,
|
||
canvas = $('<canvas></canvas>').appendTo(self),
|
||
ctx = canvas[0].getContext('2d')
|
||
|
||
self.value = undefined
|
||
self.height = undefined
|
||
self.width = undefined
|
||
self.color = undefined
|
||
self.center = settings.align == 'center'
|
||
|
||
self.attr('tabindex',"0")
|
||
|
||
canvas.resize(function(e,width,height){
|
||
e.stopPropagation()
|
||
|
||
var width = width*2,
|
||
height = height*2
|
||
|
||
if (height==100 && width==100) return
|
||
|
||
self.color = getComputedStyle(document.documentElement).getPropertyValue("--color-text")
|
||
self.height=height
|
||
self.width=width
|
||
|
||
canvas[0].setAttribute('width',width)
|
||
canvas[0].setAttribute('height',height)
|
||
|
||
self.val(self.value)
|
||
})
|
||
|
||
self.val = function(newVal) {
|
||
if (newVal==undefined) return self.value
|
||
|
||
self.value = newVal
|
||
|
||
if (!self.height || !self.width || (self.height==100 && self.width==100)) return
|
||
|
||
ctx.clearRect(0,0,self.width,self.height)
|
||
ctx.font = PXSCALE * 2 * 13 + 'px Droid Sans'
|
||
ctx.textBaseline = "top"
|
||
ctx.fillStyle = self.color
|
||
|
||
if (self.center) {
|
||
ctx.textAlign = settings.align
|
||
ctx.fillText(newVal,self.width/2,0)
|
||
} else {
|
||
ctx.fillText(newVal,0,0)
|
||
}
|
||
|
||
|
||
}
|
||
|
||
self.on('focus',function(){
|
||
self.attr('tabindex','-1')
|
||
var i = $('<input></input>')
|
||
.prependTo(self)
|
||
.val(self.value)
|
||
.focus()
|
||
.change(function(){
|
||
self.val($(this).val())
|
||
i.blur()
|
||
setTimeout(function(){self.focus()},1)
|
||
})
|
||
i.blur(function(){
|
||
self.attr('tabindex','0')
|
||
i.remove()
|
||
$(document).off('.fakeInput')
|
||
})
|
||
$(document).on('touchstart.fakeInput mousedown.fakeInput',function(e){
|
||
if (e.originalEvent.target!=i[0]) {
|
||
i.blur()
|
||
}
|
||
})
|
||
|
||
})
|
||
|
||
return self
|
||
|
||
}
|
||
})(jQuery)
|
||
|
||
},{}],42:[function(require,module,exports){
|
||
/*! jQuery v3.0.0 -ajax,-ajax/jsonp,-ajax/load,-ajax/parseXML,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-event/ajax,-effects,-effects/Tween,-effects/animatedSelector,-deprecated | (c) jQuery Foundation | jquery.org/license */
|
||
!function(a,b){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){"use strict";var c=[],d=a.document,e=Object.getPrototypeOf,f=c.slice,g=c.concat,h=c.push,i=c.indexOf,j={},k=j.toString,l=j.hasOwnProperty,m=l.toString,n=m.call(Object),o={};function p(a,b){b=b||d;var c=b.createElement("script");c.text=a,b.head.appendChild(c).parentNode.removeChild(c)}var q="3.0.0 -ajax,-ajax/jsonp,-ajax/load,-ajax/parseXML,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-event/ajax,-effects,-effects/Tween,-effects/animatedSelector,-deprecated",r=function(a,b){return new r.fn.init(a,b)},s=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,t=/^-ms-/,u=/-([a-z])/g,v=function(a,b){return b.toUpperCase()};r.fn=r.prototype={jquery:q,constructor:r,length:0,toArray:function(){return f.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:f.call(this)},pushStack:function(a){var b=r.merge(this.constructor(),a);return b.prevObject=this,b},each:function(a){return r.each(this,a)},map:function(a){return this.pushStack(r.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(f.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor()},push:h,sort:c.sort,splice:c.splice},r.extend=r.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||r.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(r.isPlainObject(d)||(e=r.isArray(d)))?(e?(e=!1,f=c&&r.isArray(c)?c:[]):f=c&&r.isPlainObject(c)?c:{},g[b]=r.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},r.extend({expando:"jQuery"+(q+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===r.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){var b=r.type(a);return("number"===b||"string"===b)&&!isNaN(a-parseFloat(a))},isPlainObject:function(a){var b,c;return a&&"[object Object]"===k.call(a)?(b=e(a))?(c=l.call(b,"constructor")&&b.constructor,"function"==typeof c&&m.call(c)===n):!0:!1},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?j[k.call(a)]||"object":typeof a},globalEval:function(a){p(a)},camelCase:function(a){return a.replace(t,"ms-").replace(u,v)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b){var c,d=0;if(w(a)){for(c=a.length;c>d;d++)if(b.call(a[d],d,a[d])===!1)break}else for(d in a)if(b.call(a[d],d,a[d])===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(s,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(w(Object(a))?r.merge(c,"string"==typeof a?[a]:a):h.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:i.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,e,f=0,h=[];if(w(a))for(d=a.length;d>f;f++)e=b(a[f],f,c),null!=e&&h.push(e);else for(f in a)e=b(a[f],f,c),null!=e&&h.push(e);return g.apply([],h)},guid:1,proxy:function(a,b){var c,d,e;return"string"==typeof b&&(c=a[b],b=a,a=c),r.isFunction(a)?(d=f.call(arguments,2),e=function(){return a.apply(b||this,d.concat(f.call(arguments)))},e.guid=a.guid=a.guid||r.guid++,e):void 0},now:Date.now,support:o}),"function"==typeof Symbol&&(r.fn[Symbol.iterator]=c[Symbol.iterator]),r.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "),function(a,b){j["[object "+b+"]"]=b.toLowerCase()});function w(a){var b=!!a&&"length"in a&&a.length,c=r.type(a);return"function"===c||r.isWindow(a)?!1:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var x=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=ha(),z=ha(),A=ha(),B=function(a,b){return a===b&&(l=!0),0},C={}.hasOwnProperty,D=[],E=D.pop,F=D.push,G=D.push,H=D.slice,I=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},J="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",K="[\\x20\\t\\r\\n\\f]",L="(?:\\\\.|[\\w-]|[^\x00-\\xa0])+",M="\\["+K+"*("+L+")(?:"+K+"*([*^$|!~]?=)"+K+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+L+"))|)"+K+"*\\]",N=":("+L+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+M+")*)|.*)\\)|)",O=new RegExp(K+"+","g"),P=new RegExp("^"+K+"+|((?:^|[^\\\\])(?:\\\\.)*)"+K+"+$","g"),Q=new RegExp("^"+K+"*,"+K+"*"),R=new RegExp("^"+K+"*([>+~]|"+K+")"+K+"*"),S=new RegExp("="+K+"*([^\\]'\"]*?)"+K+"*\\]","g"),T=new RegExp(N),U=new RegExp("^"+L+"$"),V={ID:new RegExp("^#("+L+")"),CLASS:new RegExp("^\\.("+L+")"),TAG:new RegExp("^("+L+"|[*])"),ATTR:new RegExp("^"+M),PSEUDO:new RegExp("^"+N),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+K+"*(even|odd|(([+-]|)(\\d*)n|)"+K+"*(?:([+-]|)"+K+"*(\\d+)|))"+K+"*\\)|)","i"),bool:new RegExp("^(?:"+J+")$","i"),needsContext:new RegExp("^"+K+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+K+"*((?:-\\d)?\\d*)"+K+"*\\)|)(?=[^-]|$)","i")},W=/^(?:input|select|textarea|button)$/i,X=/^h\d$/i,Y=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,$=/[+~]/,_=new RegExp("\\\\([\\da-f]{1,6}"+K+"?|("+K+")|.)","ig"),aa=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},ba=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g,ca=function(a,b){return b?"\x00"===a?"\ufffd":a.slice(0,-1)+"\\"+a.charCodeAt(a.length-1).toString(16)+" ":"\\"+a},da=function(){m()},ea=ta(function(a){return a.disabled===!0},{dir:"parentNode",next:"legend"});try{G.apply(D=H.call(v.childNodes),v.childNodes),D[v.childNodes.length].nodeType}catch(fa){G={apply:D.length?function(a,b){F.apply(a,H.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function ga(a,b,d,e){var f,h,j,k,l,o,r,s=b&&b.ownerDocument,w=b?b.nodeType:9;if(d=d||[],"string"!=typeof a||!a||1!==w&&9!==w&&11!==w)return d;if(!e&&((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,p)){if(11!==w&&(l=Z.exec(a)))if(f=l[1]){if(9===w){if(!(j=b.getElementById(f)))return d;if(j.id===f)return d.push(j),d}else if(s&&(j=s.getElementById(f))&&t(b,j)&&j.id===f)return d.push(j),d}else{if(l[2])return G.apply(d,b.getElementsByTagName(a)),d;if((f=l[3])&&c.getElementsByClassName&&b.getElementsByClassName)return G.apply(d,b.getElementsByClassName(f)),d}if(c.qsa&&!A[a+" "]&&(!q||!q.test(a))){if(1!==w)s=b,r=a;else if("object"!==b.nodeName.toLowerCase()){(k=b.getAttribute("id"))?k=k.replace(ba,ca):b.setAttribute("id",k=u),o=g(a),h=o.length;while(h--)o[h]="#"+k+" "+sa(o[h]);r=o.join(","),s=$.test(a)&&qa(b.parentNode)||b}if(r)try{return G.apply(d,s.querySelectorAll(r)),d}catch(x){}finally{k===u&&b.removeAttribute("id")}}}return i(a.replace(P,"$1"),b,d,e)}function ha(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ia(a){return a[u]=!0,a}function ja(a){var b=n.createElement("fieldset");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function ka(a,b){var c=a.split("|"),e=c.length;while(e--)d.attrHandle[c[e]]=b}function la(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&a.sourceIndex-b.sourceIndex;if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function ma(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function na(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function oa(a){return function(b){return"label"in b&&b.disabled===a||"form"in b&&b.disabled===a||"form"in b&&b.disabled===!1&&(b.isDisabled===a||b.isDisabled!==!a&&("label"in b||!ea(b))!==a)}}function pa(a){return ia(function(b){return b=+b,ia(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function qa(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=ga.support={},f=ga.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=ga.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=n.documentElement,p=!f(n),v!==n&&(e=n.defaultView)&&e.top!==e&&(e.addEventListener?e.addEventListener("unload",da,!1):e.attachEvent&&e.attachEvent("onunload",da)),c.attributes=ja(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ja(function(a){return a.appendChild(n.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=Y.test(n.getElementsByClassName),c.getById=ja(function(a){return o.appendChild(a).id=u,!n.getElementsByName||!n.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c?[c]:[]}},d.filter.ID=function(a){var b=a.replace(_,aa);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(_,aa);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return"undefined"!=typeof b.getElementsByClassName&&p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=Y.test(n.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML="<a id='"+u+"'></a><select id='"+u+"-\r\\' msallowcapture=''><option selected=''></option></select>",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+K+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+K+"*(?:value|"+J+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),ja(function(a){a.innerHTML="<a href='' disabled='disabled'></a><select disabled='disabled'><option/></select>";var b=n.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+K+"*[*^$|!~]?="),2!==a.querySelectorAll(":enabled").length&&q.push(":enabled",":disabled"),o.appendChild(a).disabled=!0,2!==a.querySelectorAll(":disabled").length&&q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=Y.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ja(function(a){c.disconnectedMatch=s.call(a,"*"),s.call(a,"[s!='']:x"),r.push("!=",N)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=Y.test(o.compareDocumentPosition),t=b||Y.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===n||a.ownerDocument===v&&t(v,a)?-1:b===n||b.ownerDocument===v&&t(v,b)?1:k?I(k,a)-I(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,g=[a],h=[b];if(!e||!f)return a===n?-1:b===n?1:e?-1:f?1:k?I(k,a)-I(k,b):0;if(e===f)return la(a,b);c=a;while(c=c.parentNode)g.unshift(c);c=b;while(c=c.parentNode)h.unshift(c);while(g[d]===h[d])d++;return d?la(g[d],h[d]):g[d]===v?-1:h[d]===v?1:0},n):n},ga.matches=function(a,b){return ga(a,null,null,b)},ga.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(S,"='$1']"),c.matchesSelector&&p&&!A[b+" "]&&(!r||!r.test(b))&&(!q||!q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return ga(b,n,null,[a]).length>0},ga.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},ga.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&C.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},ga.escape=function(a){return(a+"").replace(ba,ca)},ga.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},ga.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=ga.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=ga.selectors={cacheLength:50,createPseudo:ia,match:V,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(_,aa),a[3]=(a[3]||a[4]||a[5]||"").replace(_,aa),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||ga.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&ga.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return V.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&T.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(_,aa).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+K+")"+a+"("+K+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=ga.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e.replace(O," ")+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h,t=!1;if(q){if(f){while(p){m=b;while(m=m[p])if(h?m.nodeName.toLowerCase()===r:1===m.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){m=q,l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),j=k[a]||[],n=j[0]===w&&j[1],t=n&&j[2],m=n&&q.childNodes[n];while(m=++n&&m&&m[p]||(t=n=0)||o.pop())if(1===m.nodeType&&++t&&m===b){k[a]=[w,n,t];break}}else if(s&&(m=b,l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),j=k[a]||[],n=j[0]===w&&j[1],t=n),t===!1)while(m=++n&&m&&m[p]||(t=n=0)||o.pop())if((h?m.nodeName.toLowerCase()===r:1===m.nodeType)&&++t&&(s&&(l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),k[a]=[w,t]),m===b))break;return t-=e,t===d||t%d===0&&t/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||ga.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ia(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=I(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ia(function(a){var b=[],c=[],d=h(a.replace(P,"$1"));return d[u]?ia(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ia(function(a){return function(b){return ga(a,b).length>0}}),contains:ia(function(a){return a=a.replace(_,aa),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ia(function(a){return U.test(a||"")||ga.error("unsupported lang: "+a),a=a.replace(_,aa).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:oa(!1),disabled:oa(!0),checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return X.test(a.nodeName)},input:function(a){return W.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:pa(function(){return[0]}),last:pa(function(a,b){return[b-1]}),eq:pa(function(a,b,c){return[0>c?c+b:c]}),even:pa(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:pa(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:pa(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:pa(function(a,b,c){for(var d=0>c?c+b:c;++d<b;)a.push(d);return a})}},d.pseudos.nth=d.pseudos.eq;for(b in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})d.pseudos[b]=ma(b);for(b in{submit:!0,reset:!0})d.pseudos[b]=na(b);function ra(){}ra.prototype=d.filters=d.pseudos,d.setFilters=new ra,g=ga.tokenize=function(a,b){var c,e,f,g,h,i,j,k=z[a+" "];if(k)return b?0:k.slice(0);h=a,i=[],j=d.preFilter;while(h){c&&!(e=Q.exec(h))||(e&&(h=h.slice(e[0].length)||h),i.push(f=[])),c=!1,(e=R.exec(h))&&(c=e.shift(),f.push({value:c,type:e[0].replace(P," ")}),h=h.slice(c.length));for(g in d.filter)!(e=V[g].exec(h))||j[g]&&!(e=j[g](e))||(c=e.shift(),f.push({value:c,type:g,matches:e}),h=h.slice(c.length));if(!c)break}return b?h.length:h?ga.error(a):z(a,i).slice(0)};function sa(a){for(var b=0,c=a.length,d="";c>b;b++)d+=a[b].value;return d}function ta(a,b,c){var d=b.dir,e=b.next,f=e||d,g=c&&"parentNode"===f,h=x++;return b.first?function(b,c,e){while(b=b[d])if(1===b.nodeType||g)return a(b,c,e)}:function(b,c,i){var j,k,l,m=[w,h];if(i){while(b=b[d])if((1===b.nodeType||g)&&a(b,c,i))return!0}else while(b=b[d])if(1===b.nodeType||g)if(l=b[u]||(b[u]={}),k=l[b.uniqueID]||(l[b.uniqueID]={}),e&&e===b.nodeName.toLowerCase())b=b[d]||b;else{if((j=k[f])&&j[0]===w&&j[1]===h)return m[2]=j[2];if(k[f]=m,m[2]=a(b,c,i))return!0}}}function ua(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function va(a,b,c){for(var d=0,e=b.length;e>d;d++)ga(a,b[d],c);return c}function wa(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(c&&!c(f,d,e)||(g.push(f),j&&b.push(h)));return g}function xa(a,b,c,d,e,f){return d&&!d[u]&&(d=xa(d)),e&&!e[u]&&(e=xa(e,f)),ia(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||va(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:wa(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=wa(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?I(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=wa(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):G.apply(g,r)})}function ya(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=ta(function(a){return a===b},h,!0),l=ta(function(a){return I(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];f>i;i++)if(c=d.relative[a[i].type])m=[ta(ua(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return xa(i>1&&ua(m),i>1&&sa(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(P,"$1"),c,e>i&&ya(a.slice(i,e)),f>e&&ya(a=a.slice(e)),f>e&&sa(a))}m.push(c)}return ua(m)}function za(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,o,q,r=0,s="0",t=f&&[],u=[],v=j,x=f||e&&d.find.TAG("*",k),y=w+=null==v?1:Math.random()||.1,z=x.length;for(k&&(j=g===n||g||k);s!==z&&null!=(l=x[s]);s++){if(e&&l){o=0,g||l.ownerDocument===n||(m(l),h=!p);while(q=a[o++])if(q(l,g||n,h)){i.push(l);break}k&&(w=y)}c&&((l=!q&&l)&&r--,f&&t.push(l))}if(r+=s,c&&s!==r){o=0;while(q=b[o++])q(t,u,g,h);if(f){if(r>0)while(s--)t[s]||u[s]||(u[s]=E.call(i));u=wa(u)}G.apply(i,u),k&&!f&&u.length>0&&r+b.length>1&&ga.uniqueSort(i)}return k&&(w=y,j=v),t};return c?ia(f):f}return h=ga.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=ya(b[c]),f[u]?d.push(f):e.push(f);f=A(a,za(e,d)),f.selector=a}return f},i=ga.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(_,aa),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=V.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(_,aa),$.test(j[0].type)&&qa(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&sa(j),!a)return G.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,!b||$.test(a)&&qa(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ja(function(a){return 1&a.compareDocumentPosition(n.createElement("fieldset"))}),ja(function(a){return a.innerHTML="<a href='#'></a>","#"===a.firstChild.getAttribute("href")})||ka("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ja(function(a){return a.innerHTML="<input/>",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||ka("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ja(function(a){return null==a.getAttribute("disabled")})||ka(J,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),ga}(a);r.find=x,r.expr=x.selectors,r.expr[":"]=r.expr.pseudos,r.uniqueSort=r.unique=x.uniqueSort,r.text=x.getText,r.isXMLDoc=x.isXML,r.contains=x.contains,r.escapeSelector=x.escape;var y=function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&r(a).is(c))break;d.push(a)}return d},z=function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c},A=r.expr.match.needsContext,B=/^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i,C=/^.[^:#\[\.,]*$/;function D(a,b,c){if(r.isFunction(b))return r.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return r.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(C.test(b))return r.filter(b,a,c);b=r.filter(b,a)}return r.grep(a,function(a){return i.call(b,a)>-1!==c&&1===a.nodeType})}r.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?r.find.matchesSelector(d,a)?[d]:[]:r.find.matches(a,r.grep(b,function(a){return 1===a.nodeType}))},r.fn.extend({find:function(a){var b,c,d=this.length,e=this;if("string"!=typeof a)return this.pushStack(r(a).filter(function(){for(b=0;d>b;b++)if(r.contains(e[b],this))return!0}));for(c=this.pushStack([]),b=0;d>b;b++)r.find(a,e[b],c);return d>1?r.uniqueSort(c):c},filter:function(a){return this.pushStack(D(this,a||[],!1))},not:function(a){return this.pushStack(D(this,a||[],!0))},is:function(a){return!!D(this,"string"==typeof a&&A.test(a)?r(a):a||[],!1).length}});var E,F=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,G=r.fn.init=function(a,b,c){var e,f;if(!a)return this;if(c=c||E,"string"==typeof a){if(e="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:F.exec(a),!e||!e[1]&&b)return!b||b.jquery?(b||c).find(a):this.constructor(b).find(a);if(e[1]){if(b=b instanceof r?b[0]:b,r.merge(this,r.parseHTML(e[1],b&&b.nodeType?b.ownerDocument||b:d,!0)),B.test(e[1])&&r.isPlainObject(b))for(e in b)r.isFunction(this[e])?this[e](b[e]):this.attr(e,b[e]);return this}return f=d.getElementById(e[2]),f&&(this[0]=f,this.length=1),this}return a.nodeType?(this[0]=a,this.length=1,this):r.isFunction(a)?void 0!==c.ready?c.ready(a):a(r):r.makeArray(a,this)};G.prototype=r.fn,E=r(d);var H=/^(?:parents|prev(?:Until|All))/,I={children:!0,contents:!0,next:!0,prev:!0};r.fn.extend({has:function(a){var b=r(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(r.contains(this,b[a]))return!0})},closest:function(a,b){var c,d=0,e=this.length,f=[],g="string"!=typeof a&&r(a);if(!A.test(a))for(;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&r.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?r.uniqueSort(f):f)},index:function(a){return a?"string"==typeof a?i.call(r(a),this[0]):i.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(r.uniqueSort(r.merge(this.get(),r(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function J(a,b){while((a=a[b])&&1!==a.nodeType);return a}r.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return y(a,"parentNode")},parentsUntil:function(a,b,c){return y(a,"parentNode",c)},next:function(a){return J(a,"nextSibling")},prev:function(a){return J(a,"previousSibling")},nextAll:function(a){return y(a,"nextSibling")},prevAll:function(a){return y(a,"previousSibling")},nextUntil:function(a,b,c){return y(a,"nextSibling",c)},prevUntil:function(a,b,c){return y(a,"previousSibling",c)},siblings:function(a){return z((a.parentNode||{}).firstChild,a)},children:function(a){return z(a.firstChild)},contents:function(a){return a.contentDocument||r.merge([],a.childNodes)}},function(a,b){r.fn[a]=function(c,d){var e=r.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=r.filter(d,e)),this.length>1&&(I[a]||r.uniqueSort(e),H.test(a)&&e.reverse()),this.pushStack(e)}});var K=/\S+/g;function L(a){var b={};return r.each(a.match(K)||[],function(a,c){b[c]=!0}),b}r.Callbacks=function(a){a="string"==typeof a?L(a):r.extend({},a);var b,c,d,e,f=[],g=[],h=-1,i=function(){for(e=a.once,d=b=!0;g.length;h=-1){c=g.shift();while(++h<f.length)f[h].apply(c[0],c[1])===!1&&a.stopOnFalse&&(h=f.length,c=!1)}a.memory||(c=!1),b=!1,e&&(f=c?[]:"")},j={add:function(){return f&&(c&&!b&&(h=f.length-1,g.push(c)),function d(b){r.each(b,function(b,c){r.isFunction(c)?a.unique&&j.has(c)||f.push(c):c&&c.length&&"string"!==r.type(c)&&d(c)})}(arguments),c&&!b&&i()),this},remove:function(){return r.each(arguments,function(a,b){var c;while((c=r.inArray(b,f,c))>-1)f.splice(c,1),h>=c&&h--}),this},has:function(a){return a?r.inArray(a,f)>-1:f.length>0},empty:function(){return f&&(f=[]),this},disable:function(){return e=g=[],f=c="",this},disabled:function(){return!f},lock:function(){return e=g=[],c||b||(f=c=""),this},locked:function(){return!!e},fireWith:function(a,c){return e||(c=c||[],c=[a,c.slice?c.slice():c],g.push(c),b||i()),this},fire:function(){return j.fireWith(this,arguments),this},fired:function(){return!!d}};return j};function M(a){return a}function N(a){throw a}function O(a,b,c){var d;try{a&&r.isFunction(d=a.promise)?d.call(a).done(b).fail(c):a&&r.isFunction(d=a.then)?d.call(a,b,c):b.call(void 0,a)}catch(a){c.call(void 0,a)}}r.extend({Deferred:function(b){var c=[["notify","progress",r.Callbacks("memory"),r.Callbacks("memory"),2],["resolve","done",r.Callbacks("once memory"),r.Callbacks("once memory"),0,"resolved"],["reject","fail",r.Callbacks("once memory"),r.Callbacks("once memory"),1,"rejected"]],d="pending",e={state:function(){return d},always:function(){return f.done(arguments).fail(arguments),this},"catch":function(a){return e.then(null,a)},pipe:function(){var a=arguments;return r.Deferred(function(b){r.each(c,function(c,d){var e=r.isFunction(a[d[4]])&&a[d[4]];f[d[1]](function(){var a=e&&e.apply(this,arguments);a&&r.isFunction(a.promise)?a.promise().progress(b.notify).done(b.resolve).fail(b.reject):b[d[0]+"With"](this,e?[a]:arguments)})}),a=null}).promise()},then:function(b,d,e){var f=0;function g(b,c,d,e){return function(){var h=this,i=arguments,j=function(){var a,j;if(!(f>b)){if(a=d.apply(h,i),a===c.promise())throw new TypeError("Thenable self-resolution");j=a&&("object"==typeof a||"function"==typeof a)&&a.then,r.isFunction(j)?e?j.call(a,g(f,c,M,e),g(f,c,N,e)):(f++,j.call(a,g(f,c,M,e),g(f,c,N,e),g(f,c,M,c.notifyWith))):(d!==M&&(h=void 0,i=[a]),(e||c.resolveWith)(h,i))}},k=e?j:function(){try{j()}catch(a){r.Deferred.exceptionHook&&r.Deferred.exceptionHook(a,k.stackTrace),b+1>=f&&(d!==N&&(h=void 0,i=[a]),c.rejectWith(h,i))}};b?k():(r.Deferred.getStackHook&&(k.stackTrace=r.Deferred.getStackHook()),a.setTimeout(k))}}return r.Deferred(function(a){c[0][3].add(g(0,a,r.isFunction(e)?e:M,a.notifyWith)),c[1][3].add(g(0,a,r.isFunction(b)?b:M)),c[2][3].add(g(0,a,r.isFunction(d)?d:N))}).promise()},promise:function(a){return null!=a?r.extend(a,e):e}},f={};return r.each(c,function(a,b){var g=b[2],h=b[5];e[b[1]]=g.add,h&&g.add(function(){d=h},c[3-a][2].disable,c[0][2].lock),g.add(b[3].fire),f[b[0]]=function(){return f[b[0]+"With"](this===f?void 0:this,arguments),this},f[b[0]+"With"]=g.fireWith}),e.promise(f),b&&b.call(f,f),f},when:function(a){var b=arguments.length,c=b,d=Array(c),e=f.call(arguments),g=r.Deferred(),h=function(a){return function(c){d[a]=this,e[a]=arguments.length>1?f.call(arguments):c,--b||g.resolveWith(d,e)}};if(1>=b&&(O(a,g.done(h(c)).resolve,g.reject),"pending"===g.state()||r.isFunction(e[c]&&e[c].then)))return g.then();while(c--)O(e[c],h(c),g.reject);return g.promise()}});var P=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;r.Deferred.exceptionHook=function(b,c){a.console&&a.console.warn&&b&&P.test(b.name)&&a.console.warn("jQuery.Deferred exception: "+b.message,b.stack,c)};var Q=r.Deferred();r.fn.ready=function(a){return Q.then(a),this},r.extend({isReady:!1,readyWait:1,holdReady:function(a){a?r.readyWait++:r.ready(!0)},ready:function(a){(a===!0?--r.readyWait:r.isReady)||(r.isReady=!0,a!==!0&&--r.readyWait>0||Q.resolveWith(d,[r]))}}),r.ready.then=Q.then;function R(){d.removeEventListener("DOMContentLoaded",R),a.removeEventListener("load",R),r.ready()}"complete"===d.readyState||"loading"!==d.readyState&&!d.documentElement.doScroll?a.setTimeout(r.ready):(d.addEventListener("DOMContentLoaded",R),a.addEventListener("load",R));var S=function(a,b,c,d,e,f,g){
|
||
var h=0,i=a.length,j=null==c;if("object"===r.type(c)){e=!0;for(h in c)S(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,r.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(r(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f},T=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function U(){this.expando=r.expando+U.uid++}U.uid=1,U.prototype={cache:function(a){var b=a[this.expando];return b||(b={},T(a)&&(a.nodeType?a[this.expando]=b:Object.defineProperty(a,this.expando,{value:b,configurable:!0}))),b},set:function(a,b,c){var d,e=this.cache(a);if("string"==typeof b)e[r.camelCase(b)]=c;else for(d in b)e[r.camelCase(d)]=b[d];return e},get:function(a,b){return void 0===b?this.cache(a):a[this.expando]&&a[this.expando][r.camelCase(b)]},access:function(a,b,c){return void 0===b||b&&"string"==typeof b&&void 0===c?this.get(a,b):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d=a[this.expando];if(void 0!==d){if(void 0!==b){r.isArray(b)?b=b.map(r.camelCase):(b=r.camelCase(b),b=b in d?[b]:b.match(K)||[]),c=b.length;while(c--)delete d[b[c]]}(void 0===b||r.isEmptyObject(d))&&(a.nodeType?a[this.expando]=void 0:delete a[this.expando])}},hasData:function(a){var b=a[this.expando];return void 0!==b&&!r.isEmptyObject(b)}};var V=new U,W=new U,X=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,Y=/[A-Z]/g;function Z(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(Y,"-$&").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:X.test(c)?JSON.parse(c):c}catch(e){}W.set(a,b,c)}else c=void 0;return c}r.extend({hasData:function(a){return W.hasData(a)||V.hasData(a)},data:function(a,b,c){return W.access(a,b,c)},removeData:function(a,b){W.remove(a,b)},_data:function(a,b,c){return V.access(a,b,c)},_removeData:function(a,b){V.remove(a,b)}}),r.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=W.get(f),1===f.nodeType&&!V.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=r.camelCase(d.slice(5)),Z(f,d,e[d])));V.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){W.set(this,a)}):S(this,function(b){var c;if(f&&void 0===b){if(c=W.get(f,a),void 0!==c)return c;if(c=Z(f,a),void 0!==c)return c}else this.each(function(){W.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){W.remove(this,a)})}}),r.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=V.get(a,b),c&&(!d||r.isArray(c)?d=V.access(a,b,r.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=r.queue(a,b),d=c.length,e=c.shift(),f=r._queueHooks(a,b),g=function(){r.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return V.get(a,c)||V.access(a,c,{empty:r.Callbacks("once memory").add(function(){V.remove(a,[b+"queue",c])})})}}),r.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length<c?r.queue(this[0],a):void 0===b?this:this.each(function(){var c=r.queue(this,a,b);r._queueHooks(this,a),"fx"===a&&"inprogress"!==c[0]&&r.dequeue(this,a)})},dequeue:function(a){return this.each(function(){r.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,b){var c,d=1,e=r.Deferred(),f=this,g=this.length,h=function(){--d||e.resolveWith(f,[f])};"string"!=typeof a&&(b=a,a=void 0),a=a||"fx";while(g--)c=V.get(f[g],a+"queueHooks"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var $=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,_=new RegExp("^(?:([+-])=|)("+$+")([a-z%]*)$","i"),aa=["Top","Right","Bottom","Left"],ba=function(a,b){return a=b||a,"none"===a.style.display||""===a.style.display&&r.contains(a.ownerDocument,a)&&"none"===r.css(a,"display")},ca=function(a,b,c,d){var e,f,g={};for(f in b)g[f]=a.style[f],a.style[f]=b[f];e=c.apply(a,d||[]);for(f in b)a.style[f]=g[f];return e};function da(a,b,c,d){var e,f=1,g=20,h=d?function(){return d.cur()}:function(){return r.css(a,b,"")},i=h(),j=c&&c[3]||(r.cssNumber[b]?"":"px"),k=(r.cssNumber[b]||"px"!==j&&+i)&&_.exec(r.css(a,b));if(k&&k[3]!==j){j=j||k[3],c=c||[],k=+i||1;do f=f||".5",k/=f,r.style(a,b,k+j);while(f!==(f=h()/i)&&1!==f&&--g)}return c&&(k=+k||+i||0,e=c[1]?k+(c[1]+1)*c[2]:+c[2],d&&(d.unit=j,d.start=k,d.end=e)),e}var ea={};function fa(a){var b,c=a.ownerDocument,d=a.nodeName,e=ea[d];return e?e:(b=c.body.appendChild(c.createElement(d)),e=r.css(b,"display"),b.parentNode.removeChild(b),"none"===e&&(e="block"),ea[d]=e,e)}function ga(a,b){for(var c,d,e=[],f=0,g=a.length;g>f;f++)d=a[f],d.style&&(c=d.style.display,b?("none"===c&&(e[f]=V.get(d,"display")||null,e[f]||(d.style.display="")),""===d.style.display&&ba(d)&&(e[f]=fa(d))):"none"!==c&&(e[f]="none",V.set(d,"display",c)));for(f=0;g>f;f++)null!=e[f]&&(a[f].style.display=e[f]);return a}r.fn.extend({show:function(){return ga(this,!0)},hide:function(){return ga(this)},toggle:function(a){return"boolean"==typeof a?a?this.show():this.hide():this.each(function(){ba(this)?r(this).show():r(this).hide()})}});var ha=/^(?:checkbox|radio)$/i,ia=/<([a-z][^\/\0>\x20\t\r\n\f]+)/i,ja=/^$|\/(?:java|ecma)script/i,ka={option:[1,"<select multiple='multiple'>","</select>"],thead:[1,"<table>","</table>"],col:[2,"<table><colgroup>","</colgroup></table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[0,"",""]};ka.optgroup=ka.option,ka.tbody=ka.tfoot=ka.colgroup=ka.caption=ka.thead,ka.th=ka.td;function la(a,b){var c="undefined"!=typeof a.getElementsByTagName?a.getElementsByTagName(b||"*"):"undefined"!=typeof a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&r.nodeName(a,b)?r.merge([a],c):c}function ma(a,b){for(var c=0,d=a.length;d>c;c++)V.set(a[c],"globalEval",!b||V.get(b[c],"globalEval"))}var na=/<|&#?\w+;/;function oa(a,b,c,d,e){for(var f,g,h,i,j,k,l=b.createDocumentFragment(),m=[],n=0,o=a.length;o>n;n++)if(f=a[n],f||0===f)if("object"===r.type(f))r.merge(m,f.nodeType?[f]:f);else if(na.test(f)){g=g||l.appendChild(b.createElement("div")),h=(ia.exec(f)||["",""])[1].toLowerCase(),i=ka[h]||ka._default,g.innerHTML=i[1]+r.htmlPrefilter(f)+i[2],k=i[0];while(k--)g=g.lastChild;r.merge(m,g.childNodes),g=l.firstChild,g.textContent=""}else m.push(b.createTextNode(f));l.textContent="",n=0;while(f=m[n++])if(d&&r.inArray(f,d)>-1)e&&e.push(f);else if(j=r.contains(f.ownerDocument,f),g=la(l.appendChild(f),"script"),j&&ma(g),c){k=0;while(f=g[k++])ja.test(f.type||"")&&c.push(f)}return l}!function(){var a=d.createDocumentFragment(),b=a.appendChild(d.createElement("div")),c=d.createElement("input");c.setAttribute("type","radio"),c.setAttribute("checked","checked"),c.setAttribute("name","t"),b.appendChild(c),o.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML="<textarea>x</textarea>",o.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var pa=d.documentElement,qa=/^key/,ra=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,sa=/^([^.]*)(?:\.(.+)|)/;function ta(){return!0}function ua(){return!1}function va(){try{return d.activeElement}catch(a){}}function wa(a,b,c,d,e,f){var g,h;if("object"==typeof b){"string"!=typeof c&&(d=d||c,c=void 0);for(h in b)wa(a,h,c,d,b[h],f);return a}if(null==d&&null==e?(e=c,d=c=void 0):null==e&&("string"==typeof c?(e=d,d=void 0):(e=d,d=c,c=void 0)),e===!1)e=ua;else if(!e)return a;return 1===f&&(g=e,e=function(a){return r().off(a),g.apply(this,arguments)},e.guid=g.guid||(g.guid=r.guid++)),a.each(function(){r.event.add(this,b,e,d,c)})}r.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q=V.get(a);if(q){c.handler&&(f=c,c=f.handler,e=f.selector),e&&r.find.matchesSelector(pa,e),c.guid||(c.guid=r.guid++),(i=q.events)||(i=q.events={}),(g=q.handle)||(g=q.handle=function(b){return"undefined"!=typeof r&&r.event.triggered!==b.type?r.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(K)||[""],j=b.length;while(j--)h=sa.exec(b[j])||[],n=p=h[1],o=(h[2]||"").split(".").sort(),n&&(l=r.event.special[n]||{},n=(e?l.delegateType:l.bindType)||n,l=r.event.special[n]||{},k=r.extend({type:n,origType:p,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&r.expr.match.needsContext.test(e),namespace:o.join(".")},f),(m=i[n])||(m=i[n]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,o,g)!==!1||a.addEventListener&&a.addEventListener(n,g)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),r.event.global[n]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q=V.hasData(a)&&V.get(a);if(q&&(i=q.events)){b=(b||"").match(K)||[""],j=b.length;while(j--)if(h=sa.exec(b[j])||[],n=p=h[1],o=(h[2]||"").split(".").sort(),n){l=r.event.special[n]||{},n=(d?l.delegateType:l.bindType)||n,m=i[n]||[],h=h[2]&&new RegExp("(^|\\.)"+o.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&p!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,o,q.handle)!==!1||r.removeEvent(a,n,q.handle),delete i[n])}else for(n in i)r.event.remove(a,n+b[j],c,d,!0);r.isEmptyObject(i)&&V.remove(a,"handle events")}},dispatch:function(a){var b=r.event.fix(a),c,d,e,f,g,h,i=new Array(arguments.length),j=(V.get(this,"events")||{})[b.type]||[],k=r.event.special[b.type]||{};for(i[0]=b,c=1;c<arguments.length;c++)i[c]=arguments[c];if(b.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,b)!==!1){h=r.event.handlers.call(this,b,j),c=0;while((f=h[c++])&&!b.isPropagationStopped()){b.currentTarget=f.elem,d=0;while((g=f.handlers[d++])&&!b.isImmediatePropagationStopped())b.rnamespace&&!b.rnamespace.test(g.namespace)||(b.handleObj=g,b.data=g.data,e=((r.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(b.result=e)===!1&&(b.preventDefault(),b.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,b),b.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&("click"!==a.type||isNaN(a.button)||a.button<1))for(;i!==this;i=i.parentNode||this)if(1===i.nodeType&&(i.disabled!==!0||"click"!==a.type)){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?r(e,this).index(i)>-1:r.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h<b.length&&g.push({elem:this,handlers:b.slice(h)}),g},addProp:function(a,b){Object.defineProperty(r.Event.prototype,a,{enumerable:!0,configurable:!0,get:r.isFunction(b)?function(){return this.originalEvent?b(this.originalEvent):void 0}:function(){return this.originalEvent?this.originalEvent[a]:void 0},set:function(b){Object.defineProperty(this,a,{enumerable:!0,configurable:!0,writable:!0,value:b})}})},fix:function(a){return a[r.expando]?a:new r.Event(a)},special:{load:{noBubble:!0},focus:{trigger:function(){return this!==va()&&this.focus?(this.focus(),!1):void 0},delegateType:"focusin"},blur:{trigger:function(){return this===va()&&this.blur?(this.blur(),!1):void 0},delegateType:"focusout"},click:{trigger:function(){return"checkbox"===this.type&&this.click&&r.nodeName(this,"input")?(this.click(),!1):void 0},_default:function(a){return r.nodeName(a.target,"a")}},beforeunload:{postDispatch:function(a){void 0!==a.result&&a.originalEvent&&(a.originalEvent.returnValue=a.result)}}}},r.removeEvent=function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c)},r.Event=function(a,b){return this instanceof r.Event?(a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||void 0===a.defaultPrevented&&a.returnValue===!1?ta:ua,this.target=a.target&&3===a.target.nodeType?a.target.parentNode:a.target,this.currentTarget=a.currentTarget,this.relatedTarget=a.relatedTarget):this.type=a,b&&r.extend(this,b),this.timeStamp=a&&a.timeStamp||r.now(),void(this[r.expando]=!0)):new r.Event(a,b)},r.Event.prototype={constructor:r.Event,isDefaultPrevented:ua,isPropagationStopped:ua,isImmediatePropagationStopped:ua,isSimulated:!1,preventDefault:function(){var a=this.originalEvent;this.isDefaultPrevented=ta,a&&!this.isSimulated&&a.preventDefault()},stopPropagation:function(){var a=this.originalEvent;this.isPropagationStopped=ta,a&&!this.isSimulated&&a.stopPropagation()},stopImmediatePropagation:function(){var a=this.originalEvent;this.isImmediatePropagationStopped=ta,a&&!this.isSimulated&&a.stopImmediatePropagation(),this.stopPropagation()}},r.each({altKey:!0,bubbles:!0,cancelable:!0,changedTouches:!0,ctrlKey:!0,detail:!0,eventPhase:!0,metaKey:!0,pageX:!0,pageY:!0,shiftKey:!0,view:!0,"char":!0,charCode:!0,key:!0,keyCode:!0,button:!0,buttons:!0,clientX:!0,clientY:!0,offsetX:!0,offsetY:!0,pointerId:!0,pointerType:!0,screenX:!0,screenY:!0,targetTouches:!0,toElement:!0,touches:!0,which:function(a){var b=a.button;return null==a.which&&qa.test(a.type)?null!=a.charCode?a.charCode:a.keyCode:!a.which&&void 0!==b&&ra.test(a.type)?1&b?1:2&b?3:4&b?2:0:a.which}},r.event.addProp),r.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(a,b){r.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj;return e&&(e===d||r.contains(d,e))||(a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b),c}}}),r.fn.extend({on:function(a,b,c,d){return wa(this,a,b,c,d)},one:function(a,b,c,d){return wa(this,a,b,c,d,1)},off:function(a,b,c){var d,e;if(a&&a.preventDefault&&a.handleObj)return d=a.handleObj,r(a.delegateTarget).off(d.namespace?d.origType+"."+d.namespace:d.origType,d.selector,d.handler),this;if("object"==typeof a){for(e in a)this.off(e,b,a[e]);return this}return b!==!1&&"function"!=typeof b||(c=b,b=void 0),c===!1&&(c=ua),this.each(function(){r.event.remove(this,a,c,b)})}});var xa=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,ya=/<script|<style|<link/i,za=/checked\s*(?:[^=]|=\s*.checked.)/i,Aa=/^true\/(.*)/,Ba=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;function Ca(a,b){return r.nodeName(a,"table")&&r.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a:a}function Da(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function Ea(a){var b=Aa.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function Fa(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(V.hasData(a)&&(f=V.access(a),g=V.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)r.event.add(b,e,j[e][c])}W.hasData(a)&&(h=W.access(a),i=r.extend({},h),W.set(b,i))}}function Ga(a,b){var c=b.nodeName.toLowerCase();"input"===c&&ha.test(a.type)?b.checked=a.checked:"input"!==c&&"textarea"!==c||(b.defaultValue=a.defaultValue)}function Ha(a,b,c,d){b=g.apply([],b);var e,f,h,i,j,k,l=0,m=a.length,n=m-1,q=b[0],s=r.isFunction(q);if(s||m>1&&"string"==typeof q&&!o.checkClone&&za.test(q))return a.each(function(e){var f=a.eq(e);s&&(b[0]=q.call(this,e,f.html())),Ha(f,b,c,d)});if(m&&(e=oa(b,a[0].ownerDocument,!1,a,d),f=e.firstChild,1===e.childNodes.length&&(e=f),f||d)){for(h=r.map(la(e,"script"),Da),i=h.length;m>l;l++)j=e,l!==n&&(j=r.clone(j,!0,!0),i&&r.merge(h,la(j,"script"))),c.call(a[l],j,l);if(i)for(k=h[h.length-1].ownerDocument,r.map(h,Ea),l=0;i>l;l++)j=h[l],ja.test(j.type||"")&&!V.access(j,"globalEval")&&r.contains(k,j)&&(j.src?r._evalUrl&&r._evalUrl(j.src):p(j.textContent.replace(Ba,""),k))}return a}function Ia(a,b,c){for(var d,e=b?r.filter(b,a):a,f=0;null!=(d=e[f]);f++)c||1!==d.nodeType||r.cleanData(la(d)),d.parentNode&&(c&&r.contains(d.ownerDocument,d)&&ma(la(d,"script")),d.parentNode.removeChild(d));return a}r.extend({htmlPrefilter:function(a){return a.replace(xa,"<$1></$2>")},clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=r.contains(a.ownerDocument,a);if(!(o.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||r.isXMLDoc(a)))for(g=la(h),f=la(a),d=0,e=f.length;e>d;d++)Ga(f[d],g[d]);if(b)if(c)for(f=f||la(a),g=g||la(h),d=0,e=f.length;e>d;d++)Fa(f[d],g[d]);else Fa(a,h);return g=la(h,"script"),g.length>0&&ma(g,!i&&la(a,"script")),h},cleanData:function(a){for(var b,c,d,e=r.event.special,f=0;void 0!==(c=a[f]);f++)if(T(c)){if(b=c[V.expando]){if(b.events)for(d in b.events)e[d]?r.event.remove(c,d):r.removeEvent(c,d,b.handle);c[V.expando]=void 0}c[W.expando]&&(c[W.expando]=void 0)}}}),r.fn.extend({detach:function(a){return Ia(this,a,!0)},remove:function(a){return Ia(this,a)},text:function(a){return S(this,function(a){return void 0===a?r.text(this):this.empty().each(function(){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||(this.textContent=a)})},null,a,arguments.length)},append:function(){return Ha(this,arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=Ca(this,a);b.appendChild(a)}})},prepend:function(){return Ha(this,arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=Ca(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return Ha(this,arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return Ha(this,arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(r.cleanData(la(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return r.clone(this,a,b)})},html:function(a){return S(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!ya.test(a)&&!ka[(ia.exec(a)||["",""])[1].toLowerCase()]){a=r.htmlPrefilter(a);try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(r.cleanData(la(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=[];return Ha(this,arguments,function(b){var c=this.parentNode;r.inArray(this,a)<0&&(r.cleanData(la(this)),c&&c.replaceChild(b,this))},a)}}),r.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){r.fn[a]=function(a){for(var c,d=[],e=r(a),f=e.length-1,g=0;f>=g;g++)c=g===f?this:this.clone(!0),r(e[g])[b](c),h.apply(d,c.get());return this.pushStack(d)}});var Ja=/^margin/,Ka=new RegExp("^("+$+")(?!px)[a-z%]+$","i"),La=function(b){var c=b.ownerDocument.defaultView;return c&&c.opener||(c=a),c.getComputedStyle(b)};!function(){function b(){if(i){i.style.cssText="box-sizing:border-box;position:relative;display:block;margin:auto;border:1px;padding:1px;top:1%;width:50%",i.innerHTML="",pa.appendChild(h);var b=a.getComputedStyle(i);c="1%"!==b.top,g="2px"===b.marginLeft,e="4px"===b.width,i.style.marginRight="50%",f="4px"===b.marginRight,pa.removeChild(h),i=null}}var c,e,f,g,h=d.createElement("div"),i=d.createElement("div");i.style&&(i.style.backgroundClip="content-box",i.cloneNode(!0).style.backgroundClip="",o.clearCloneStyle="content-box"===i.style.backgroundClip,h.style.cssText="border:0;width:8px;height:0;top:0;left:-9999px;padding:0;margin-top:1px;position:absolute",h.appendChild(i),r.extend(o,{pixelPosition:function(){return b(),c},boxSizingReliable:function(){return b(),e},pixelMarginRight:function(){return b(),f},reliableMarginLeft:function(){return b(),g}}))}();function Ma(a,b,c){var d,e,f,g,h=a.style;return c=c||La(a),c&&(g=c.getPropertyValue(b)||c[b],""!==g||r.contains(a.ownerDocument,a)||(g=r.style(a,b)),!o.pixelMarginRight()&&Ka.test(g)&&Ja.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=g,g=c.width,h.width=d,h.minWidth=e,h.maxWidth=f)),void 0!==g?g+"":g}function Na(a,b){return{get:function(){return a()?void delete this.get:(this.get=b).apply(this,arguments)}}}var Oa=/^(none|table(?!-c[ea]).+)/,Pa={position:"absolute",visibility:"hidden",display:"block"},Qa={letterSpacing:"0",fontWeight:"400"},Ra=["Webkit","Moz","ms"],Sa=d.createElement("div").style;function Ta(a){if(a in Sa)return a;var b=a[0].toUpperCase()+a.slice(1),c=Ra.length;while(c--)if(a=Ra[c]+b,a in Sa)return a}function Ua(a,b,c){var d=_.exec(b);return d?Math.max(0,d[2]-(c||0))+(d[3]||"px"):b}function Va(a,b,c,d,e){for(var f=c===(d?"border":"content")?4:"width"===b?1:0,g=0;4>f;f+=2)"margin"===c&&(g+=r.css(a,c+aa[f],!0,e)),d?("content"===c&&(g-=r.css(a,"padding"+aa[f],!0,e)),"margin"!==c&&(g-=r.css(a,"border"+aa[f]+"Width",!0,e))):(g+=r.css(a,"padding"+aa[f],!0,e),"padding"!==c&&(g+=r.css(a,"border"+aa[f]+"Width",!0,e)));return g}function Wa(a,b,c){var d,e=!0,f=La(a),g="border-box"===r.css(a,"boxSizing",!1,f);if(a.getClientRects().length&&(d=a.getBoundingClientRect()[b]),0>=d||null==d){if(d=Ma(a,b,f),(0>d||null==d)&&(d=a.style[b]),Ka.test(d))return d;e=g&&(o.boxSizingReliable()||d===a.style[b]),d=parseFloat(d)||0}return d+Va(a,b,c||(g?"border":"content"),e,f)+"px"}r.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=Ma(a,"opacity");return""===c?"1":c}}}},cssNumber:{animationIterationCount:!0,columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":"cssFloat"},style:function(a,b,c,d){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var e,f,g,h=r.camelCase(b),i=a.style;return b=r.cssProps[h]||(r.cssProps[h]=Ta(h)||h),g=r.cssHooks[b]||r.cssHooks[h],void 0===c?g&&"get"in g&&void 0!==(e=g.get(a,!1,d))?e:i[b]:(f=typeof c,"string"===f&&(e=_.exec(c))&&e[1]&&(c=da(a,b,e),f="number"),null!=c&&c===c&&("number"===f&&(c+=e&&e[3]||(r.cssNumber[h]?"":"px")),o.clearCloneStyle||""!==c||0!==b.indexOf("background")||(i[b]="inherit"),g&&"set"in g&&void 0===(c=g.set(a,c,d))||(i[b]=c)),void 0)}},css:function(a,b,c,d){var e,f,g,h=r.camelCase(b);return b=r.cssProps[h]||(r.cssProps[h]=Ta(h)||h),g=r.cssHooks[b]||r.cssHooks[h],g&&"get"in g&&(e=g.get(a,!0,c)),void 0===e&&(e=Ma(a,b,d)),"normal"===e&&b in Qa&&(e=Qa[b]),""===c||c?(f=parseFloat(e),c===!0||isFinite(f)?f||0:e):e}}),r.each(["height","width"],function(a,b){r.cssHooks[b]={get:function(a,c,d){return c?!Oa.test(r.css(a,"display"))||a.getClientRects().length&&a.getBoundingClientRect().width?Wa(a,b,d):ca(a,Pa,function(){return Wa(a,b,d)}):void 0},set:function(a,c,d){var e,f=d&&La(a),g=d&&Va(a,b,d,"border-box"===r.css(a,"boxSizing",!1,f),f);return g&&(e=_.exec(c))&&"px"!==(e[3]||"px")&&(a.style[b]=c,c=r.css(a,b)),Ua(a,c,g)}}}),r.cssHooks.marginLeft=Na(o.reliableMarginLeft,function(a,b){return b?(parseFloat(Ma(a,"marginLeft"))||a.getBoundingClientRect().left-ca(a,{marginLeft:0},function(){return a.getBoundingClientRect().left}))+"px":void 0}),r.each({margin:"",padding:"",border:"Width"},function(a,b){r.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f="string"==typeof c?c.split(" "):[c];4>d;d++)e[a+aa[d]+b]=f[d]||f[d-2]||f[0];return e}},Ja.test(a)||(r.cssHooks[a+b].set=Ua)}),r.fn.extend({css:function(a,b){return S(this,function(a,b,c){var d,e,f={},g=0;if(r.isArray(b)){for(d=La(a),e=b.length;e>g;g++)f[b[g]]=r.css(a,b[g],!1,d);return f}return void 0!==c?r.style(a,b,c):r.css(a,b)},a,b,arguments.length>1)}}),r.fn.delay=function(b,c){return b=r.fx?r.fx.speeds[b]||b:b,c=c||"fx",this.queue(c,function(c,d){var e=a.setTimeout(c,b);d.stop=function(){a.clearTimeout(e)}})},function(){var a=d.createElement("input"),b=d.createElement("select"),c=b.appendChild(d.createElement("option"));a.type="checkbox",o.checkOn=""!==a.value,o.optSelected=c.selected,a=d.createElement("input"),a.value="t",a.type="radio",o.radioValue="t"===a.value}();var Xa,Ya=r.expr.attrHandle;r.fn.extend({attr:function(a,b){return S(this,r.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){r.removeAttr(this,a)})}}),r.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(3!==f&&8!==f&&2!==f)return"undefined"==typeof a.getAttribute?r.prop(a,b,c):(1===f&&r.isXMLDoc(a)||(e=r.attrHooks[b.toLowerCase()]||(r.expr.match.bool.test(b)?Xa:void 0)),void 0!==c?null===c?void r.removeAttr(a,b):e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:(a.setAttribute(b,c+""),c):e&&"get"in e&&null!==(d=e.get(a,b))?d:(d=r.find.attr(a,b),null==d?void 0:d))},attrHooks:{type:{set:function(a,b){if(!o.radioValue&&"radio"===b&&r.nodeName(a,"input")){var c=a.value;return a.setAttribute("type",b),c&&(a.value=c),b}}}},removeAttr:function(a,b){var c,d=0,e=b&&b.match(K);if(e&&1===a.nodeType)while(c=e[d++])a.removeAttribute(c)}}),Xa={set:function(a,b,c){return b===!1?r.removeAttr(a,c):a.setAttribute(c,c),c}},r.each(r.expr.match.bool.source.match(/\w+/g),function(a,b){var c=Ya[b]||r.find.attr;Ya[b]=function(a,b,d){var e,f,g=b.toLowerCase();return d||(f=Ya[g],Ya[g]=e,e=null!=c(a,b,d)?g:null,Ya[g]=f),e}});var Za=/^(?:input|select|textarea|button)$/i,$a=/^(?:a|area)$/i;r.fn.extend({prop:function(a,b){return S(this,r.prop,a,b,arguments.length>1)},removeProp:function(a){return this.each(function(){delete this[r.propFix[a]||a]})}}),r.extend({prop:function(a,b,c){var d,e,f=a.nodeType;if(3!==f&&8!==f&&2!==f)return 1===f&&r.isXMLDoc(a)||(b=r.propFix[b]||b,e=r.propHooks[b]),void 0!==c?e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:a[b]=c:e&&"get"in e&&null!==(d=e.get(a,b))?d:a[b]},propHooks:{tabIndex:{get:function(a){var b=r.find.attr(a,"tabindex");return b?parseInt(b,10):Za.test(a.nodeName)||$a.test(a.nodeName)&&a.href?0:-1}}},propFix:{"for":"htmlFor","class":"className"}}),o.optSelected||(r.propHooks.selected={get:function(a){var b=a.parentNode;return b&&b.parentNode&&b.parentNode.selectedIndex,null},set:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex)}}),r.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){r.propFix[this.toLowerCase()]=this});var _a=/[\t\r\n\f]/g;function ab(a){return a.getAttribute&&a.getAttribute("class")||""}r.fn.extend({addClass:function(a){var b,c,d,e,f,g,h,i=0;if(r.isFunction(a))return this.each(function(b){r(this).addClass(a.call(this,b,ab(this)))});if("string"==typeof a&&a){b=a.match(K)||[];while(c=this[i++])if(e=ab(c),d=1===c.nodeType&&(" "+e+" ").replace(_a," ")){g=0;while(f=b[g++])d.indexOf(" "+f+" ")<0&&(d+=f+" ");h=r.trim(d),e!==h&&c.setAttribute("class",h)}}return this},removeClass:function(a){var b,c,d,e,f,g,h,i=0;if(r.isFunction(a))return this.each(function(b){r(this).removeClass(a.call(this,b,ab(this)))});if(!arguments.length)return this.attr("class","");if("string"==typeof a&&a){b=a.match(K)||[];while(c=this[i++])if(e=ab(c),d=1===c.nodeType&&(" "+e+" ").replace(_a," ")){g=0;while(f=b[g++])while(d.indexOf(" "+f+" ")>-1)d=d.replace(" "+f+" "," ");h=r.trim(d),e!==h&&c.setAttribute("class",h)}}return this},toggleClass:function(a,b){var c=typeof a;return"boolean"==typeof b&&"string"===c?b?this.addClass(a):this.removeClass(a):r.isFunction(a)?this.each(function(c){r(this).toggleClass(a.call(this,c,ab(this),b),b)}):this.each(function(){var b,d,e,f;if("string"===c){d=0,e=r(this),f=a.match(K)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else void 0!==a&&"boolean"!==c||(b=ab(this),b&&V.set(this,"__className__",b),this.setAttribute&&this.setAttribute("class",b||a===!1?"":V.get(this,"__className__")||""))})},hasClass:function(a){var b,c,d=0;b=" "+a+" ";while(c=this[d++])if(1===c.nodeType&&(" "+ab(c)+" ").replace(_a," ").indexOf(b)>-1)return!0;return!1}});var bb=/\r/g,cb=/[\x20\t\r\n\f]+/g;r.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=r.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,r(this).val()):a,null==e?e="":"number"==typeof e?e+="":r.isArray(e)&&(e=r.map(e,function(a){return null==a?"":a+""})),b=r.valHooks[this.type]||r.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=r.valHooks[e.type]||r.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&void 0!==(c=b.get(e,"value"))?c:(c=e.value,"string"==typeof c?c.replace(bb,""):null==c?"":c)}}}),r.extend({valHooks:{option:{get:function(a){var b=r.find.attr(a,"value");return null!=b?b:r.trim(r.text(a)).replace(cb," ")}},select:{get:function(a){for(var b,c,d=a.options,e=a.selectedIndex,f="select-one"===a.type,g=f?null:[],h=f?e+1:d.length,i=0>e?h:f?e:0;h>i;i++)if(c=d[i],(c.selected||i===e)&&!c.disabled&&(!c.parentNode.disabled||!r.nodeName(c.parentNode,"optgroup"))){if(b=r(c).val(),f)return b;g.push(b)}return g},set:function(a,b){var c,d,e=a.options,f=r.makeArray(b),g=e.length;while(g--)d=e[g],(d.selected=r.inArray(r.valHooks.option.get(d),f)>-1)&&(c=!0);return c||(a.selectedIndex=-1),f}}}}),r.each(["radio","checkbox"],function(){r.valHooks[this]={set:function(a,b){return r.isArray(b)?a.checked=r.inArray(r(a).val(),b)>-1:void 0}},o.checkOn||(r.valHooks[this].get=function(a){return null===a.getAttribute("value")?"on":a.value})});var db=/^(?:focusinfocus|focusoutblur)$/;r.extend(r.event,{trigger:function(b,c,e,f){var g,h,i,j,k,m,n,o=[e||d],p=l.call(b,"type")?b.type:b,q=l.call(b,"namespace")?b.namespace.split("."):[];if(h=i=e=e||d,3!==e.nodeType&&8!==e.nodeType&&!db.test(p+r.event.triggered)&&(p.indexOf(".")>-1&&(q=p.split("."),p=q.shift(),q.sort()),k=p.indexOf(":")<0&&"on"+p,b=b[r.expando]?b:new r.Event(p,"object"==typeof b&&b),b.isTrigger=f?2:3,b.namespace=q.join("."),b.rnamespace=b.namespace?new RegExp("(^|\\.)"+q.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=e),c=null==c?[b]:r.makeArray(c,[b]),n=r.event.special[p]||{},f||!n.trigger||n.trigger.apply(e,c)!==!1)){if(!f&&!n.noBubble&&!r.isWindow(e)){for(j=n.delegateType||p,db.test(j+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),i=h;i===(e.ownerDocument||d)&&o.push(i.defaultView||i.parentWindow||a)}g=0;while((h=o[g++])&&!b.isPropagationStopped())b.type=g>1?j:n.bindType||p,m=(V.get(h,"events")||{})[b.type]&&V.get(h,"handle"),m&&m.apply(h,c),m=k&&h[k],m&&m.apply&&T(h)&&(b.result=m.apply(h,c),b.result===!1&&b.preventDefault());return b.type=p,f||b.isDefaultPrevented()||n._default&&n._default.apply(o.pop(),c)!==!1||!T(e)||k&&r.isFunction(e[p])&&!r.isWindow(e)&&(i=e[k],i&&(e[k]=null),r.event.triggered=p,e[p](),r.event.triggered=void 0,i&&(e[k]=i)),b.result}},simulate:function(a,b,c){var d=r.extend(new r.Event,c,{type:a,isSimulated:!0});r.event.trigger(d,null,b)}}),r.fn.extend({trigger:function(a,b){return this.each(function(){r.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];return c?r.event.trigger(a,b,c,!0):void 0}}),r.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(a,b){r.fn[b]=function(a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}}),r.fn.extend({hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),o.focusin="onfocusin"in a,o.focusin||r.each({focus:"focusin",blur:"focusout"},function(a,b){var c=function(a){r.event.simulate(b,a.target,r.event.fix(a))};r.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=V.access(d,b);e||d.addEventListener(a,c,!0),V.access(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=V.access(d,b)-1;e?V.access(d,b,e):(d.removeEventListener(a,c,!0),V.remove(d,b))}}});var eb=/\[\]$/,fb=/\r?\n/g,gb=/^(?:submit|button|image|reset|file)$/i,hb=/^(?:input|select|textarea|keygen)/i;function ib(a,b,c,d){var e;if(r.isArray(b))r.each(b,function(b,e){c||eb.test(a)?d(a,e):ib(a+"["+("object"==typeof e&&null!=e?b:"")+"]",e,c,d)});else if(c||"object"!==r.type(b))d(a,b);else for(e in b)ib(a+"["+e+"]",b[e],c,d)}r.param=function(a,b){var c,d=[],e=function(a,b){var c=r.isFunction(b)?b():b;d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(null==c?"":c)};if(r.isArray(a)||a.jquery&&!r.isPlainObject(a))r.each(a,function(){e(this.name,this.value)});else for(c in a)ib(c,a[c],b,e);
|
||
return d.join("&")},r.fn.extend({serialize:function(){return r.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=r.prop(this,"elements");return a?r.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!r(this).is(":disabled")&&hb.test(this.nodeName)&&!gb.test(a)&&(this.checked||!ha.test(a))}).map(function(a,b){var c=r(this).val();return null==c?null:r.isArray(c)?r.map(c,function(a){return{name:b.name,value:a.replace(fb,"\r\n")}}):{name:b.name,value:c.replace(fb,"\r\n")}}).get()}}),r.fn.extend({wrapAll:function(a){var b;return this[0]&&(r.isFunction(a)&&(a=a.call(this[0])),b=r(a,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstElementChild)a=a.firstElementChild;return a}).append(this)),this},wrapInner:function(a){return r.isFunction(a)?this.each(function(b){r(this).wrapInner(a.call(this,b))}):this.each(function(){var b=r(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=r.isFunction(a);return this.each(function(c){r(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(a){return this.parent(a).not("body").each(function(){r(this).replaceWith(this.childNodes)}),this}}),r.expr.pseudos.hidden=function(a){return!r.expr.pseudos.visible(a)},r.expr.pseudos.visible=function(a){return!!(a.offsetWidth||a.offsetHeight||a.getClientRects().length)},o.createHTMLDocument=function(){var a=d.implementation.createHTMLDocument("").body;return a.innerHTML="<form></form><form></form>",2===a.childNodes.length}(),r.parseHTML=function(a,b,c){if("string"!=typeof a)return[];"boolean"==typeof b&&(c=b,b=!1);var e,f,g;return b||(o.createHTMLDocument?(b=d.implementation.createHTMLDocument(""),e=b.createElement("base"),e.href=d.location.href,b.head.appendChild(e)):b=d),f=B.exec(a),g=!c&&[],f?[b.createElement(f[1])]:(f=oa([a],b,g),g&&g.length&&r(g).remove(),r.merge([],f.childNodes))};function jb(a){return r.isWindow(a)?a:9===a.nodeType&&a.defaultView}r.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=r.css(a,"position"),l=r(a),m={};"static"===k&&(a.style.position="relative"),h=l.offset(),f=r.css(a,"top"),i=r.css(a,"left"),j=("absolute"===k||"fixed"===k)&&(f+i).indexOf("auto")>-1,j?(d=l.position(),g=d.top,e=d.left):(g=parseFloat(f)||0,e=parseFloat(i)||0),r.isFunction(b)&&(b=b.call(a,c,r.extend({},h))),null!=b.top&&(m.top=b.top-h.top+g),null!=b.left&&(m.left=b.left-h.left+e),"using"in b?b.using.call(a,m):l.css(m)}},r.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){r.offset.setOffset(this,a,b)});var b,c,d,e,f=this[0];if(f)return f.getClientRects().length?(d=f.getBoundingClientRect(),d.width||d.height?(e=f.ownerDocument,c=jb(e),b=e.documentElement,{top:d.top+c.pageYOffset-b.clientTop,left:d.left+c.pageXOffset-b.clientLeft}):d):{top:0,left:0}},position:function(){if(this[0]){var a,b,c=this[0],d={top:0,left:0};return"fixed"===r.css(c,"position")?b=c.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),r.nodeName(a[0],"html")||(d=a.offset()),d={top:d.top+r.css(a[0],"borderTopWidth",!0),left:d.left+r.css(a[0],"borderLeftWidth",!0)}),{top:b.top-d.top-r.css(c,"marginTop",!0),left:b.left-d.left-r.css(c,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent;while(a&&"static"===r.css(a,"position"))a=a.offsetParent;return a||pa})}}),r.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,b){var c="pageYOffset"===b;r.fn[a]=function(d){return S(this,function(a,d,e){var f=jb(a);return void 0===e?f?f[b]:a[d]:void(f?f.scrollTo(c?f.pageXOffset:e,c?e:f.pageYOffset):a[d]=e)},a,d,arguments.length)}}),r.each(["top","left"],function(a,b){r.cssHooks[b]=Na(o.pixelPosition,function(a,c){return c?(c=Ma(a,b),Ka.test(c)?r(a).position()[b]+"px":c):void 0})}),r.each({Height:"height",Width:"width"},function(a,b){r.each({padding:"inner"+a,content:b,"":"outer"+a},function(c,d){r.fn[d]=function(e,f){var g=arguments.length&&(c||"boolean"!=typeof e),h=c||(e===!0||f===!0?"margin":"border");return S(this,function(b,c,e){var f;return r.isWindow(b)?0===d.indexOf("outer")?b["inner"+a]:b.document.documentElement["client"+a]:9===b.nodeType?(f=b.documentElement,Math.max(b.body["scroll"+a],f["scroll"+a],b.body["offset"+a],f["offset"+a],f["client"+a])):void 0===e?r.css(b,c,h):r.style(b,c,e,h)},b,g?e:void 0,g)}})}),"function"==typeof define&&define.amd&&define("jquery",[],function(){return r});var kb=a.jQuery,lb=a.$;return r.noConflict=function(b){return a.$===r&&(a.$=lb),b&&a.jQuery===r&&(a.jQuery=kb),r},b||(a.jQuery=a.$=r),r});
|
||
|
||
},{}],43:[function(require,module,exports){
|
||
/* jquery.resize
|
||
* based on jQuery resize event (@ "Cowboy" Ben Alman http://benalman.com/projects/jquery-resize-plugin/)
|
||
* just lighter and faster
|
||
*/
|
||
(function($){
|
||
|
||
var elems = [],
|
||
pollInterval = 250,
|
||
resizeTimeout
|
||
|
||
$.event.special.resize = {
|
||
setup: function() {
|
||
|
||
if (this===window) return false
|
||
|
||
var elem = this
|
||
|
||
// Add this element to the list of internal elements to monitor.
|
||
elems.push( elem )
|
||
|
||
// If this is the first element added, start the polling loop.
|
||
if ( elems.length === 1 ) {
|
||
resizePollingLoop()
|
||
}
|
||
},
|
||
teardown: function() {
|
||
|
||
if (this===window) return false
|
||
|
||
var elem = this
|
||
|
||
// Remove this element from the list of internal elements to monitor.
|
||
for (var i = elems.length - 1; i >= 0; i--) {
|
||
if(elems[i] == this){
|
||
elems.splice(i, 1)
|
||
break
|
||
}
|
||
}
|
||
|
||
if ( !elems.length ) {
|
||
clearTimeout(resizeTimeout)
|
||
}
|
||
|
||
},
|
||
add: function(handleObj) {
|
||
|
||
if (this===window) return false
|
||
|
||
// Save a reference to the bound event handler.
|
||
var old_handler = handleObj.handler
|
||
|
||
handleObj.handler = function(event,data) {
|
||
// Call the originally-bound event handler and return its result.
|
||
return old_handler.apply(this, arguments)
|
||
}
|
||
}
|
||
}
|
||
|
||
function checkResizes(){
|
||
// Iterate over all elements to which the 'resize' event is bound.
|
||
for (var i = elems.length - 1; i >= 0; i--) {
|
||
var elem = elems[i],
|
||
width = elem.offsetWidth,
|
||
height = elem.offsetHeight
|
||
|
||
if (!width) continue
|
||
|
||
var data = {
|
||
w:elem.resizedataw,
|
||
h:elem.resizedatah
|
||
}
|
||
|
||
// If element size has changed since the last time, update the element
|
||
// data store and trigger the 'resize' event.
|
||
if ( width != data.w || height != data.h ) {
|
||
elem.resizedataw = width
|
||
elem.resizedatah = height
|
||
$(elem).triggerHandler('resize',[width,height])
|
||
}
|
||
|
||
}
|
||
|
||
// Loop.
|
||
resizePollingLoop()
|
||
}
|
||
|
||
function resizePollingLoop() {
|
||
// yep, setTimeout, 'cuz requestAnimation doesn't seem to perform that well
|
||
resizeTimeout = window.setTimeout(checkResizes, pollInterval)
|
||
|
||
}
|
||
|
||
$(window).resize(checkResizes)
|
||
|
||
})(jQuery)
|
||
|
||
},{}],44:[function(require,module,exports){
|
||
/*! jQuery UI - v1.12.0 - 2016-07-29
|
||
* http://jqueryui.com
|
||
* Includes: widget.js, data.js, disable-selection.js, scroll-parent.js, widgets/draggable.js, widgets/resizable.js, widgets/sortable.js, widgets/mouse.js
|
||
* Copyright jQuery Foundation and other contributors; Licensed MIT */
|
||
|
||
(function(t){"function"==typeof define&&define.amd?define(["jquery"],t):t(jQuery)})(function(t){t.ui=t.ui||{},t.ui.version="1.12.0";var e=0,i=Array.prototype.slice;t.cleanData=function(e){return function(i){var s,n,o;for(o=0;null!=(n=i[o]);o++)try{s=t._data(n,"events"),s&&s.remove&&t(n).triggerHandler("remove")}catch(a){}e(i)}}(t.cleanData),t.widget=function(e,i,s){var n,o,a,r={},l=e.split(".")[0];e=e.split(".")[1];var h=l+"-"+e;return s||(s=i,i=t.Widget),t.isArray(s)&&(s=t.extend.apply(null,[{}].concat(s))),t.expr[":"][h.toLowerCase()]=function(e){return!!t.data(e,h)},t[l]=t[l]||{},n=t[l][e],o=t[l][e]=function(t,e){return this._createWidget?(arguments.length&&this._createWidget(t,e),void 0):new o(t,e)},t.extend(o,n,{version:s.version,_proto:t.extend({},s),_childConstructors:[]}),a=new i,a.options=t.widget.extend({},a.options),t.each(s,function(e,s){return t.isFunction(s)?(r[e]=function(){function t(){return i.prototype[e].apply(this,arguments)}function n(t){return i.prototype[e].apply(this,t)}return function(){var e,i=this._super,o=this._superApply;return this._super=t,this._superApply=n,e=s.apply(this,arguments),this._super=i,this._superApply=o,e}}(),void 0):(r[e]=s,void 0)}),o.prototype=t.widget.extend(a,{widgetEventPrefix:n?a.widgetEventPrefix||e:e},r,{constructor:o,namespace:l,widgetName:e,widgetFullName:h}),n?(t.each(n._childConstructors,function(e,i){var s=i.prototype;t.widget(s.namespace+"."+s.widgetName,o,i._proto)}),delete n._childConstructors):i._childConstructors.push(o),t.widget.bridge(e,o),o},t.widget.extend=function(e){for(var s,n,o=i.call(arguments,1),a=0,r=o.length;r>a;a++)for(s in o[a])n=o[a][s],o[a].hasOwnProperty(s)&&void 0!==n&&(e[s]=t.isPlainObject(n)?t.isPlainObject(e[s])?t.widget.extend({},e[s],n):t.widget.extend({},n):n);return e},t.widget.bridge=function(e,s){var n=s.prototype.widgetFullName||e;t.fn[e]=function(o){var a="string"==typeof o,r=i.call(arguments,1),l=this;return a?this.each(function(){var i,s=t.data(this,n);return"instance"===o?(l=s,!1):s?t.isFunction(s[o])&&"_"!==o.charAt(0)?(i=s[o].apply(s,r),i!==s&&void 0!==i?(l=i&&i.jquery?l.pushStack(i.get()):i,!1):void 0):t.error("no such method '"+o+"' for "+e+" widget instance"):t.error("cannot call methods on "+e+" prior to initialization; "+"attempted to call method '"+o+"'")}):(r.length&&(o=t.widget.extend.apply(null,[o].concat(r))),this.each(function(){var e=t.data(this,n);e?(e.option(o||{}),e._init&&e._init()):t.data(this,n,new s(o,this))})),l}},t.Widget=function(){},t.Widget._childConstructors=[],t.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",defaultElement:"<div>",options:{classes:{},disabled:!1,create:null},_createWidget:function(i,s){s=t(s||this.defaultElement||this)[0],this.element=t(s),this.uuid=e++,this.eventNamespace="."+this.widgetName+this.uuid,this.bindings=t(),this.hoverable=t(),this.focusable=t(),this.classesElementLookup={},s!==this&&(t.data(s,this.widgetFullName,this),this._on(!0,this.element,{remove:function(t){t.target===s&&this.destroy()}}),this.document=t(s.style?s.ownerDocument:s.document||s),this.window=t(this.document[0].defaultView||this.document[0].parentWindow)),this.options=t.widget.extend({},this.options,this._getCreateOptions(),i),this._create(),this.options.disabled&&this._setOptionDisabled(this.options.disabled),this._trigger("create",null,this._getCreateEventData()),this._init()},_getCreateOptions:function(){return{}},_getCreateEventData:t.noop,_create:t.noop,_init:t.noop,destroy:function(){var e=this;this._destroy(),t.each(this.classesElementLookup,function(t,i){e._removeClass(i,t)}),this.element.off(this.eventNamespace).removeData(this.widgetFullName),this.widget().off(this.eventNamespace).removeAttr("aria-disabled"),this.bindings.off(this.eventNamespace)},_destroy:t.noop,widget:function(){return this.element},option:function(e,i){var s,n,o,a=e;if(0===arguments.length)return t.widget.extend({},this.options);if("string"==typeof e)if(a={},s=e.split("."),e=s.shift(),s.length){for(n=a[e]=t.widget.extend({},this.options[e]),o=0;s.length-1>o;o++)n[s[o]]=n[s[o]]||{},n=n[s[o]];if(e=s.pop(),1===arguments.length)return void 0===n[e]?null:n[e];n[e]=i}else{if(1===arguments.length)return void 0===this.options[e]?null:this.options[e];a[e]=i}return this._setOptions(a),this},_setOptions:function(t){var e;for(e in t)this._setOption(e,t[e]);return this},_setOption:function(t,e){return"classes"===t&&this._setOptionClasses(e),this.options[t]=e,"disabled"===t&&this._setOptionDisabled(e),this},_setOptionClasses:function(e){var i,s,n;for(i in e)n=this.classesElementLookup[i],e[i]!==this.options.classes[i]&&n&&n.length&&(s=t(n.get()),this._removeClass(n,i),s.addClass(this._classes({element:s,keys:i,classes:e,add:!0})))},_setOptionDisabled:function(t){this._toggleClass(this.widget(),this.widgetFullName+"-disabled",null,!!t),t&&(this._removeClass(this.hoverable,null,"ui-state-hover"),this._removeClass(this.focusable,null,"ui-state-focus"))},enable:function(){return this._setOptions({disabled:!1})},disable:function(){return this._setOptions({disabled:!0})},_classes:function(e){function i(i,o){var a,r;for(r=0;i.length>r;r++)a=n.classesElementLookup[i[r]]||t(),a=e.add?t(t.unique(a.get().concat(e.element.get()))):t(a.not(e.element).get()),n.classesElementLookup[i[r]]=a,s.push(i[r]),o&&e.classes[i[r]]&&s.push(e.classes[i[r]])}var s=[],n=this;return e=t.extend({element:this.element,classes:this.options.classes||{}},e),e.keys&&i(e.keys.match(/\S+/g)||[],!0),e.extra&&i(e.extra.match(/\S+/g)||[]),s.join(" ")},_removeClass:function(t,e,i){return this._toggleClass(t,e,i,!1)},_addClass:function(t,e,i){return this._toggleClass(t,e,i,!0)},_toggleClass:function(t,e,i,s){s="boolean"==typeof s?s:i;var n="string"==typeof t||null===t,o={extra:n?e:i,keys:n?t:e,element:n?this.element:t,add:s};return o.element.toggleClass(this._classes(o),s),this},_on:function(e,i,s){var n,o=this;"boolean"!=typeof e&&(s=i,i=e,e=!1),s?(i=n=t(i),this.bindings=this.bindings.add(i)):(s=i,i=this.element,n=this.widget()),t.each(s,function(s,a){function r(){return e||o.options.disabled!==!0&&!t(this).hasClass("ui-state-disabled")?("string"==typeof a?o[a]:a).apply(o,arguments):void 0}"string"!=typeof a&&(r.guid=a.guid=a.guid||r.guid||t.guid++);var l=s.match(/^([\w:-]*)\s*(.*)$/),h=l[1]+o.eventNamespace,c=l[2];c?n.on(h,c,r):i.on(h,r)})},_off:function(e,i){i=(i||"").split(" ").join(this.eventNamespace+" ")+this.eventNamespace,e.off(i).off(i),this.bindings=t(this.bindings.not(e).get()),this.focusable=t(this.focusable.not(e).get()),this.hoverable=t(this.hoverable.not(e).get())},_delay:function(t,e){function i(){return("string"==typeof t?s[t]:t).apply(s,arguments)}var s=this;return setTimeout(i,e||0)},_hoverable:function(e){this.hoverable=this.hoverable.add(e),this._on(e,{mouseenter:function(e){this._addClass(t(e.currentTarget),null,"ui-state-hover")},mouseleave:function(e){this._removeClass(t(e.currentTarget),null,"ui-state-hover")}})},_focusable:function(e){this.focusable=this.focusable.add(e),this._on(e,{focusin:function(e){this._addClass(t(e.currentTarget),null,"ui-state-focus")},focusout:function(e){this._removeClass(t(e.currentTarget),null,"ui-state-focus")}})},_trigger:function(e,i,s){var n,o,a=this.options[e];if(s=s||{},i=t.Event(i),i.type=(e===this.widgetEventPrefix?e:this.widgetEventPrefix+e).toLowerCase(),i.target=this.element[0],o=i.originalEvent)for(n in o)n in i||(i[n]=o[n]);return this.element.trigger(i,s),!(t.isFunction(a)&&a.apply(this.element[0],[i].concat(s))===!1||i.isDefaultPrevented())}},t.each({show:"fadeIn",hide:"fadeOut"},function(e,i){t.Widget.prototype["_"+e]=function(s,n,o){"string"==typeof n&&(n={effect:n});var a,r=n?n===!0||"number"==typeof n?i:n.effect||i:e;n=n||{},"number"==typeof n&&(n={duration:n}),a=!t.isEmptyObject(n),n.complete=o,n.delay&&s.delay(n.delay),a&&t.effects&&t.effects.effect[r]?s[e](n):r!==e&&s[r]?s[r](n.duration,n.easing,o):s.queue(function(i){t(this)[e](),o&&o.call(s[0]),i()})}}),t.widget,t.extend(t.expr[":"],{data:t.expr.createPseudo?t.expr.createPseudo(function(e){return function(i){return!!t.data(i,e)}}):function(e,i,s){return!!t.data(e,s[3])}}),t.fn.extend({disableSelection:function(){var t="onselectstart"in document.createElement("div")?"selectstart":"mousedown";return function(){return this.on(t+".ui-disableSelection",function(t){t.preventDefault()})}}(),enableSelection:function(){return this.off(".ui-disableSelection")}}),t.fn.scrollParent=function(e){var i=this.css("position"),s="absolute"===i,n=e?/(auto|scroll|hidden)/:/(auto|scroll)/,o=this.parents().filter(function(){var e=t(this);return s&&"static"===e.css("position")?!1:n.test(e.css("overflow")+e.css("overflow-y")+e.css("overflow-x"))}).eq(0);return"fixed"!==i&&o.length?o:t(this[0].ownerDocument||document)},t.ui.ie=!!/msie [\w.]+/.exec(navigator.userAgent.toLowerCase());var s=!1;t(document).on("mouseup",function(){s=!1}),t.widget("ui.mouse",{version:"1.12.0",options:{cancel:"input, textarea, button, select, option",distance:1,delay:0},_mouseInit:function(){var e=this;this.element.on("mousedown."+this.widgetName,function(t){return e._mouseDown(t)}).on("click."+this.widgetName,function(i){return!0===t.data(i.target,e.widgetName+".preventClickEvent")?(t.removeData(i.target,e.widgetName+".preventClickEvent"),i.stopImmediatePropagation(),!1):void 0}),this.started=!1},_mouseDestroy:function(){this.element.off("."+this.widgetName),this._mouseMoveDelegate&&this.document.off("mousemove."+this.widgetName,this._mouseMoveDelegate).off("mouseup."+this.widgetName,this._mouseUpDelegate)},_mouseDown:function(e){if(!s){this._mouseMoved=!1,this._mouseStarted&&this._mouseUp(e),this._mouseDownEvent=e;var i=this,n=1===e.which,o="string"==typeof this.options.cancel&&e.target.nodeName?t(e.target).closest(this.options.cancel).length:!1;return n&&!o&&this._mouseCapture(e)?(this.mouseDelayMet=!this.options.delay,this.mouseDelayMet||(this._mouseDelayTimer=setTimeout(function(){i.mouseDelayMet=!0},this.options.delay)),this._mouseDistanceMet(e)&&this._mouseDelayMet(e)&&(this._mouseStarted=this._mouseStart(e)!==!1,!this._mouseStarted)?(e.preventDefault(),!0):(!0===t.data(e.target,this.widgetName+".preventClickEvent")&&t.removeData(e.target,this.widgetName+".preventClickEvent"),this._mouseMoveDelegate=function(t){return i._mouseMove(t)},this._mouseUpDelegate=function(t){return i._mouseUp(t)},this.document.on("mousemove."+this.widgetName,this._mouseMoveDelegate).on("mouseup."+this.widgetName,this._mouseUpDelegate),e.preventDefault(),s=!0,!0)):!0}},_mouseMove:function(e){if(this._mouseMoved){if(t.ui.ie&&(!document.documentMode||9>document.documentMode)&&!e.button)return this._mouseUp(e);if(!e.which)if(e.originalEvent.altKey||e.originalEvent.ctrlKey||e.originalEvent.metaKey||e.originalEvent.shiftKey)this.ignoreMissingWhich=!0;else if(!this.ignoreMissingWhich)return this._mouseUp(e)}return(e.which||e.button)&&(this._mouseMoved=!0),this._mouseStarted?(this._mouseDrag(e),e.preventDefault()):(this._mouseDistanceMet(e)&&this._mouseDelayMet(e)&&(this._mouseStarted=this._mouseStart(this._mouseDownEvent,e)!==!1,this._mouseStarted?this._mouseDrag(e):this._mouseUp(e)),!this._mouseStarted)},_mouseUp:function(e){this.document.off("mousemove."+this.widgetName,this._mouseMoveDelegate).off("mouseup."+this.widgetName,this._mouseUpDelegate),this._mouseStarted&&(this._mouseStarted=!1,e.target===this._mouseDownEvent.target&&t.data(e.target,this.widgetName+".preventClickEvent",!0),this._mouseStop(e)),this._mouseDelayTimer&&(clearTimeout(this._mouseDelayTimer),delete this._mouseDelayTimer),this.ignoreMissingWhich=!1,s=!1,e.preventDefault()},_mouseDistanceMet:function(t){return Math.max(Math.abs(this._mouseDownEvent.pageX-t.pageX),Math.abs(this._mouseDownEvent.pageY-t.pageY))>=this.options.distance},_mouseDelayMet:function(){return this.mouseDelayMet},_mouseStart:function(){},_mouseDrag:function(){},_mouseStop:function(){},_mouseCapture:function(){return!0}}),t.ui.plugin={add:function(e,i,s){var n,o=t.ui[e].prototype;for(n in s)o.plugins[n]=o.plugins[n]||[],o.plugins[n].push([i,s[n]])},call:function(t,e,i,s){var n,o=t.plugins[e];if(o&&(s||t.element[0].parentNode&&11!==t.element[0].parentNode.nodeType))for(n=0;o.length>n;n++)t.options[o[n][0]]&&o[n][1].apply(t.element,i)}},t.ui.safeActiveElement=function(t){var e;try{e=t.activeElement}catch(i){e=t.body}return e||(e=t.body),e.nodeName||(e=t.body),e},t.ui.safeBlur=function(e){e&&"body"!==e.nodeName.toLowerCase()&&t(e).trigger("blur")},t.widget("ui.draggable",t.ui.mouse,{version:"1.12.0",widgetEventPrefix:"drag",options:{addClasses:!0,appendTo:"parent",axis:!1,connectToSortable:!1,containment:!1,cursor:"auto",cursorAt:!1,grid:!1,handle:!1,helper:"original",iframeFix:!1,opacity:!1,refreshPositions:!1,revert:!1,revertDuration:500,scope:"default",scroll:!0,scrollSensitivity:20,scrollSpeed:20,snap:!1,snapMode:"both",snapTolerance:20,stack:!1,zIndex:!1,drag:null,start:null,stop:null},_create:function(){"original"===this.options.helper&&this._setPositionRelative(),this.options.addClasses&&this._addClass("ui-draggable"),this._setHandleClassName(),this._mouseInit()},_setOption:function(t,e){this._super(t,e),"handle"===t&&(this._removeHandleClassName(),this._setHandleClassName())},_destroy:function(){return(this.helper||this.element).is(".ui-draggable-dragging")?(this.destroyOnClear=!0,void 0):(this._removeHandleClassName(),this._mouseDestroy(),void 0)},_mouseCapture:function(e){var i=this.options;return this._blurActiveElement(e),this.helper||i.disabled||t(e.target).closest(".ui-resizable-handle").length>0?!1:(this.handle=this._getHandle(e),this.handle?(this._blockFrames(i.iframeFix===!0?"iframe":i.iframeFix),!0):!1)},_blockFrames:function(e){this.iframeBlocks=this.document.find(e).map(function(){var e=t(this);return t("<div>").css("position","absolute").appendTo(e.parent()).outerWidth(e.outerWidth()).outerHeight(e.outerHeight()).offset(e.offset())[0]})},_unblockFrames:function(){this.iframeBlocks&&(this.iframeBlocks.remove(),delete this.iframeBlocks)},_blurActiveElement:function(e){var i=t.ui.safeActiveElement(this.document[0]),s=t(e.target);this._getHandle(e)&&s.closest(i).length||t.ui.safeBlur(i)},_mouseStart:function(e){var i=this.options;return this.helper=this._createHelper(e),this._addClass(this.helper,"ui-draggable-dragging"),this._cacheHelperProportions(),t.ui.ddmanager&&(t.ui.ddmanager.current=this),this._cacheMargins(),this.cssPosition=this.helper.css("position"),this.scrollParent=this.helper.scrollParent(!0),this.offsetParent=this.helper.offsetParent(),this.hasFixedAncestor=this.helper.parents().filter(function(){return"fixed"===t(this).css("position")}).length>0,this.positionAbs=this.element.offset(),this._refreshOffsets(e),this.originalPosition=this.position=this._generatePosition(e,!1),this.originalPageX=e.pageX,this.originalPageY=e.pageY,i.cursorAt&&this._adjustOffsetFromHelper(i.cursorAt),this._setContainment(),this._trigger("start",e)===!1?(this._clear(),!1):(this._cacheHelperProportions(),t.ui.ddmanager&&!i.dropBehaviour&&t.ui.ddmanager.prepareOffsets(this,e),this._mouseDrag(e,!0),t.ui.ddmanager&&t.ui.ddmanager.dragStart(this,e),!0)},_refreshOffsets:function(t){this.offset={top:this.positionAbs.top-this.margins.top,left:this.positionAbs.left-this.margins.left,scroll:!1,parent:this._getParentOffset(),relative:this._getRelativeOffset()},this.offset.click={left:t.pageX-this.offset.left,top:t.pageY-this.offset.top}},_mouseDrag:function(e,i){if(this.hasFixedAncestor&&(this.offset.parent=this._getParentOffset()),this.position=this._generatePosition(e,!0),this.positionAbs=this._convertPositionTo("absolute"),!i){var s=this._uiHash();if(this._trigger("drag",e,s)===!1)return this._mouseUp(new t.Event("mouseup",e)),!1;this.position=s.position}return this.helper[0].style.left=this.position.left+"px",this.helper[0].style.top=this.position.top+"px",t.ui.ddmanager&&t.ui.ddmanager.drag(this,e),!1},_mouseStop:function(e){var i=this,s=!1;return t.ui.ddmanager&&!this.options.dropBehaviour&&(s=t.ui.ddmanager.drop(this,e)),this.dropped&&(s=this.dropped,this.dropped=!1),"invalid"===this.options.revert&&!s||"valid"===this.options.revert&&s||this.options.revert===!0||t.isFunction(this.options.revert)&&this.options.revert.call(this.element,s)?t(this.helper).animate(this.originalPosition,parseInt(this.options.revertDuration,10),function(){i._trigger("stop",e)!==!1&&i._clear()}):this._trigger("stop",e)!==!1&&this._clear(),!1},_mouseUp:function(e){return this._unblockFrames(),t.ui.ddmanager&&t.ui.ddmanager.dragStop(this,e),this.handleElement.is(e.target)&&this.element.trigger("focus"),t.ui.mouse.prototype._mouseUp.call(this,e)},cancel:function(){return this.helper.is(".ui-draggable-dragging")?this._mouseUp(new t.Event("mouseup",{target:this.element[0]})):this._clear(),this},_getHandle:function(e){return this.options.handle?!!t(e.target).closest(this.element.find(this.options.handle)).length:!0},_setHandleClassName:function(){this.handleElement=this.options.handle?this.element.find(this.options.handle):this.element,this._addClass(this.handleElement,"ui-draggable-handle")},_removeHandleClassName:function(){this._removeClass(this.handleElement,"ui-draggable-handle")},_createHelper:function(e){var i=this.options,s=t.isFunction(i.helper),n=s?t(i.helper.apply(this.element[0],[e])):"clone"===i.helper?this.element.clone().removeAttr("id"):this.element;return n.parents("body").length||n.appendTo("parent"===i.appendTo?this.element[0].parentNode:i.appendTo),s&&n[0]===this.element[0]&&this._setPositionRelative(),n[0]===this.element[0]||/(fixed|absolute)/.test(n.css("position"))||n.css("position","absolute"),n},_setPositionRelative:function(){/^(?:r|a|f)/.test(this.element.css("position"))||(this.element[0].style.position="relative")},_adjustOffsetFromHelper:function(e){"string"==typeof e&&(e=e.split(" ")),t.isArray(e)&&(e={left:+e[0],top:+e[1]||0}),"left"in e&&(this.offset.click.left=e.left+this.margins.left),"right"in e&&(this.offset.click.left=this.helperProportions.width-e.right+this.margins.left),"top"in e&&(this.offset.click.top=e.top+this.margins.top),"bottom"in e&&(this.offset.click.top=this.helperProportions.height-e.bottom+this.margins.top)},_isRootNode:function(t){return/(html|body)/i.test(t.tagName)||t===this.document[0]},_getParentOffset:function(){var e=this.offsetParent.offset(),i=this.document[0];return"absolute"===this.cssPosition&&this.scrollParent[0]!==i&&t.contains(this.scrollParent[0],this.offsetParent[0])&&(e.left+=this.scrollParent.scrollLeft(),e.top+=this.scrollParent.scrollTop()),this._isRootNode(this.offsetParent[0])&&(e={top:0,left:0}),{top:e.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:e.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if("relative"!==this.cssPosition)return{top:0,left:0};var t=this.element.position(),e=this._isRootNode(this.scrollParent[0]);return{top:t.top-(parseInt(this.helper.css("top"),10)||0)+(e?0:this.scrollParent.scrollTop()),left:t.left-(parseInt(this.helper.css("left"),10)||0)+(e?0:this.scrollParent.scrollLeft())}},_cacheMargins:function(){this.margins={left:parseInt(this.element.css("marginLeft"),10)||0,top:parseInt(this.element.css("marginTop"),10)||0,right:parseInt(this.element.css("marginRight"),10)||0,bottom:parseInt(this.element.css("marginBottom"),10)||0}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var e,i,s,n=this.options,o=this.document[0];return this.relativeContainer=null,n.containment?"window"===n.containment?(this.containment=[t(window).scrollLeft()-this.offset.relative.left-this.offset.parent.left,t(window).scrollTop()-this.offset.relative.top-this.offset.parent.top,t(window).scrollLeft()+t(window).width()-this.helperProportions.width-this.margins.left,t(window).scrollTop()+(t(window).height()||o.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top],void 0):"document"===n.containment?(this.containment=[0,0,t(o).width()-this.helperProportions.width-this.margins.left,(t(o).height()||o.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top],void 0):n.containment.constructor===Array?(this.containment=n.containment,void 0):("parent"===n.containment&&(n.containment=this.helper[0].parentNode),i=t(n.containment),s=i[0],s&&(e=/(scroll|auto)/.test(i.css("overflow")),this.containment=[(parseInt(i.css("borderLeftWidth"),10)||0)+(parseInt(i.css("paddingLeft"),10)||0),(parseInt(i.css("borderTopWidth"),10)||0)+(parseInt(i.css("paddingTop"),10)||0),(e?Math.max(s.scrollWidth,s.offsetWidth):s.offsetWidth)-(parseInt(i.css("borderRightWidth"),10)||0)-(parseInt(i.css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left-this.margins.right,(e?Math.max(s.scrollHeight,s.offsetHeight):s.offsetHeight)-(parseInt(i.css("borderBottomWidth"),10)||0)-(parseInt(i.css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top-this.margins.bottom],this.relativeContainer=i),void 0):(this.containment=null,void 0)},_convertPositionTo:function(t,e){e||(e=this.position);var i="absolute"===t?1:-1,s=this._isRootNode(this.scrollParent[0]);return{top:e.top+this.offset.relative.top*i+this.offset.parent.top*i-("fixed"===this.cssPosition?-this.offset.scroll.top:s?0:this.offset.scroll.top)*i,left:e.left+this.offset.relative.left*i+this.offset.parent.left*i-("fixed"===this.cssPosition?-this.offset.scroll.left:s?0:this.offset.scroll.left)*i}},_generatePosition:function(t,e){var i,s,n,o,a=this.options,r=this._isRootNode(this.scrollParent[0]),l=t.pageX,h=t.pageY;return r&&this.offset.scroll||(this.offset.scroll={top:this.scrollParent.scrollTop(),left:this.scrollParent.scrollLeft()}),e&&(this.containment&&(this.relativeContainer?(s=this.relativeContainer.offset(),i=[this.containment[0]+s.left,this.containment[1]+s.top,this.containment[2]+s.left,this.containment[3]+s.top]):i=this.containment,t.pageX-this.offset.click.left<i[0]&&(l=i[0]+this.offset.click.left),t.pageY-this.offset.click.top<i[1]&&(h=i[1]+this.offset.click.top),t.pageX-this.offset.click.left>i[2]&&(l=i[2]+this.offset.click.left),t.pageY-this.offset.click.top>i[3]&&(h=i[3]+this.offset.click.top)),a.grid&&(n=a.grid[1]?this.originalPageY+Math.round((h-this.originalPageY)/a.grid[1])*a.grid[1]:this.originalPageY,h=i?n-this.offset.click.top>=i[1]||n-this.offset.click.top>i[3]?n:n-this.offset.click.top>=i[1]?n-a.grid[1]:n+a.grid[1]:n,o=a.grid[0]?this.originalPageX+Math.round((l-this.originalPageX)/a.grid[0])*a.grid[0]:this.originalPageX,l=i?o-this.offset.click.left>=i[0]||o-this.offset.click.left>i[2]?o:o-this.offset.click.left>=i[0]?o-a.grid[0]:o+a.grid[0]:o),"y"===a.axis&&(l=this.originalPageX),"x"===a.axis&&(h=this.originalPageY)),{top:h-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+("fixed"===this.cssPosition?-this.offset.scroll.top:r?0:this.offset.scroll.top),left:l-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+("fixed"===this.cssPosition?-this.offset.scroll.left:r?0:this.offset.scroll.left)}},_clear:function(){this._removeClass(this.helper,"ui-draggable-dragging"),this.helper[0]===this.element[0]||this.cancelHelperRemoval||this.helper.remove(),this.helper=null,this.cancelHelperRemoval=!1,this.destroyOnClear&&this.destroy()},_trigger:function(e,i,s){return s=s||this._uiHash(),t.ui.plugin.call(this,e,[i,s,this],!0),/^(drag|start|stop)/.test(e)&&(this.positionAbs=this._convertPositionTo("absolute"),s.offset=this.positionAbs),t.Widget.prototype._trigger.call(this,e,i,s)},plugins:{},_uiHash:function(){return{helper:this.helper,position:this.position,originalPosition:this.originalPosition,offset:this.positionAbs}}}),t.ui.plugin.add("draggable","connectToSortable",{start:function(e,i,s){var n=t.extend({},i,{item:s.element});s.sortables=[],t(s.options.connectToSortable).each(function(){var i=t(this).sortable("instance");i&&!i.options.disabled&&(s.sortables.push(i),i.refreshPositions(),i._trigger("activate",e,n))})},stop:function(e,i,s){var n=t.extend({},i,{item:s.element});s.cancelHelperRemoval=!1,t.each(s.sortables,function(){var t=this;t.isOver?(t.isOver=0,s.cancelHelperRemoval=!0,t.cancelHelperRemoval=!1,t._storedCSS={position:t.placeholder.css("position"),top:t.placeholder.css("top"),left:t.placeholder.css("left")},t._mouseStop(e),t.options.helper=t.options._helper):(t.cancelHelperRemoval=!0,t._trigger("deactivate",e,n))})},drag:function(e,i,s){t.each(s.sortables,function(){var n=!1,o=this;o.positionAbs=s.positionAbs,o.helperProportions=s.helperProportions,o.offset.click=s.offset.click,o._intersectsWith(o.containerCache)&&(n=!0,t.each(s.sortables,function(){return this.positionAbs=s.positionAbs,this.helperProportions=s.helperProportions,this.offset.click=s.offset.click,this!==o&&this._intersectsWith(this.containerCache)&&t.contains(o.element[0],this.element[0])&&(n=!1),n})),n?(o.isOver||(o.isOver=1,s._parent=i.helper.parent(),o.currentItem=i.helper.appendTo(o.element).data("ui-sortable-item",!0),o.options._helper=o.options.helper,o.options.helper=function(){return i.helper[0]},e.target=o.currentItem[0],o._mouseCapture(e,!0),o._mouseStart(e,!0,!0),o.offset.click.top=s.offset.click.top,o.offset.click.left=s.offset.click.left,o.offset.parent.left-=s.offset.parent.left-o.offset.parent.left,o.offset.parent.top-=s.offset.parent.top-o.offset.parent.top,s._trigger("toSortable",e),s.dropped=o.element,t.each(s.sortables,function(){this.refreshPositions()}),s.currentItem=s.element,o.fromOutside=s),o.currentItem&&(o._mouseDrag(e),i.position=o.position)):o.isOver&&(o.isOver=0,o.cancelHelperRemoval=!0,o.options._revert=o.options.revert,o.options.revert=!1,o._trigger("out",e,o._uiHash(o)),o._mouseStop(e,!0),o.options.revert=o.options._revert,o.options.helper=o.options._helper,o.placeholder&&o.placeholder.remove(),i.helper.appendTo(s._parent),s._refreshOffsets(e),i.position=s._generatePosition(e,!0),s._trigger("fromSortable",e),s.dropped=!1,t.each(s.sortables,function(){this.refreshPositions()}))})}}),t.ui.plugin.add("draggable","cursor",{start:function(e,i,s){var n=t("body"),o=s.options;n.css("cursor")&&(o._cursor=n.css("cursor")),n.css("cursor",o.cursor)},stop:function(e,i,s){var n=s.options;n._cursor&&t("body").css("cursor",n._cursor)}}),t.ui.plugin.add("draggable","opacity",{start:function(e,i,s){var n=t(i.helper),o=s.options;n.css("opacity")&&(o._opacity=n.css("opacity")),n.css("opacity",o.opacity)},stop:function(e,i,s){var n=s.options;n._opacity&&t(i.helper).css("opacity",n._opacity)}}),t.ui.plugin.add("draggable","scroll",{start:function(t,e,i){i.scrollParentNotHidden||(i.scrollParentNotHidden=i.helper.scrollParent(!1)),i.scrollParentNotHidden[0]!==i.document[0]&&"HTML"!==i.scrollParentNotHidden[0].tagName&&(i.overflowOffset=i.scrollParentNotHidden.offset())},drag:function(e,i,s){var n=s.options,o=!1,a=s.scrollParentNotHidden[0],r=s.document[0];a!==r&&"HTML"!==a.tagName?(n.axis&&"x"===n.axis||(s.overflowOffset.top+a.offsetHeight-e.pageY<n.scrollSensitivity?a.scrollTop=o=a.scrollTop+n.scrollSpeed:e.pageY-s.overflowOffset.top<n.scrollSensitivity&&(a.scrollTop=o=a.scrollTop-n.scrollSpeed)),n.axis&&"y"===n.axis||(s.overflowOffset.left+a.offsetWidth-e.pageX<n.scrollSensitivity?a.scrollLeft=o=a.scrollLeft+n.scrollSpeed:e.pageX-s.overflowOffset.left<n.scrollSensitivity&&(a.scrollLeft=o=a.scrollLeft-n.scrollSpeed))):(n.axis&&"x"===n.axis||(e.pageY-t(r).scrollTop()<n.scrollSensitivity?o=t(r).scrollTop(t(r).scrollTop()-n.scrollSpeed):t(window).height()-(e.pageY-t(r).scrollTop())<n.scrollSensitivity&&(o=t(r).scrollTop(t(r).scrollTop()+n.scrollSpeed))),n.axis&&"y"===n.axis||(e.pageX-t(r).scrollLeft()<n.scrollSensitivity?o=t(r).scrollLeft(t(r).scrollLeft()-n.scrollSpeed):t(window).width()-(e.pageX-t(r).scrollLeft())<n.scrollSensitivity&&(o=t(r).scrollLeft(t(r).scrollLeft()+n.scrollSpeed)))),o!==!1&&t.ui.ddmanager&&!n.dropBehaviour&&t.ui.ddmanager.prepareOffsets(s,e)}}),t.ui.plugin.add("draggable","snap",{start:function(e,i,s){var n=s.options;s.snapElements=[],t(n.snap.constructor!==String?n.snap.items||":data(ui-draggable)":n.snap).each(function(){var e=t(this),i=e.offset();this!==s.element[0]&&s.snapElements.push({item:this,width:e.outerWidth(),height:e.outerHeight(),top:i.top,left:i.left})})},drag:function(e,i,s){var n,o,a,r,l,h,c,u,d,p,f=s.options,g=f.snapTolerance,m=i.offset.left,_=m+s.helperProportions.width,v=i.offset.top,b=v+s.helperProportions.height;for(d=s.snapElements.length-1;d>=0;d--)l=s.snapElements[d].left-s.margins.left,h=l+s.snapElements[d].width,c=s.snapElements[d].top-s.margins.top,u=c+s.snapElements[d].height,l-g>_||m>h+g||c-g>b||v>u+g||!t.contains(s.snapElements[d].item.ownerDocument,s.snapElements[d].item)?(s.snapElements[d].snapping&&s.options.snap.release&&s.options.snap.release.call(s.element,e,t.extend(s._uiHash(),{snapItem:s.snapElements[d].item})),s.snapElements[d].snapping=!1):("inner"!==f.snapMode&&(n=g>=Math.abs(c-b),o=g>=Math.abs(u-v),a=g>=Math.abs(l-_),r=g>=Math.abs(h-m),n&&(i.position.top=s._convertPositionTo("relative",{top:c-s.helperProportions.height,left:0}).top),o&&(i.position.top=s._convertPositionTo("relative",{top:u,left:0}).top),a&&(i.position.left=s._convertPositionTo("relative",{top:0,left:l-s.helperProportions.width}).left),r&&(i.position.left=s._convertPositionTo("relative",{top:0,left:h}).left)),p=n||o||a||r,"outer"!==f.snapMode&&(n=g>=Math.abs(c-v),o=g>=Math.abs(u-b),a=g>=Math.abs(l-m),r=g>=Math.abs(h-_),n&&(i.position.top=s._convertPositionTo("relative",{top:c,left:0}).top),o&&(i.position.top=s._convertPositionTo("relative",{top:u-s.helperProportions.height,left:0}).top),a&&(i.position.left=s._convertPositionTo("relative",{top:0,left:l}).left),r&&(i.position.left=s._convertPositionTo("relative",{top:0,left:h-s.helperProportions.width}).left)),!s.snapElements[d].snapping&&(n||o||a||r||p)&&s.options.snap.snap&&s.options.snap.snap.call(s.element,e,t.extend(s._uiHash(),{snapItem:s.snapElements[d].item})),s.snapElements[d].snapping=n||o||a||r||p)}}),t.ui.plugin.add("draggable","stack",{start:function(e,i,s){var n,o=s.options,a=t.makeArray(t(o.stack)).sort(function(e,i){return(parseInt(t(e).css("zIndex"),10)||0)-(parseInt(t(i).css("zIndex"),10)||0)});a.length&&(n=parseInt(t(a[0]).css("zIndex"),10)||0,t(a).each(function(e){t(this).css("zIndex",n+e)}),this.css("zIndex",n+a.length))}}),t.ui.plugin.add("draggable","zIndex",{start:function(e,i,s){var n=t(i.helper),o=s.options;n.css("zIndex")&&(o._zIndex=n.css("zIndex")),n.css("zIndex",o.zIndex)},stop:function(e,i,s){var n=s.options;n._zIndex&&t(i.helper).css("zIndex",n._zIndex)}}),t.ui.draggable,t.widget("ui.resizable",t.ui.mouse,{version:"1.12.0",widgetEventPrefix:"resize",options:{alsoResize:!1,animate:!1,animateDuration:"slow",animateEasing:"swing",aspectRatio:!1,autoHide:!1,classes:{"ui-resizable-se":"ui-icon ui-icon-gripsmall-diagonal-se"},containment:!1,ghost:!1,grid:!1,handles:"e,s,se",helper:!1,maxHeight:null,maxWidth:null,minHeight:10,minWidth:10,zIndex:90,resize:null,start:null,stop:null},_num:function(t){return parseFloat(t)||0},_isNumber:function(t){return!isNaN(parseFloat(t))},_hasScroll:function(e,i){if("hidden"===t(e).css("overflow"))return!1;var s=i&&"left"===i?"scrollLeft":"scrollTop",n=!1;return e[s]>0?!0:(e[s]=1,n=e[s]>0,e[s]=0,n)},_create:function(){var e,i=this.options,s=this;this._addClass("ui-resizable"),t.extend(this,{_aspectRatio:!!i.aspectRatio,aspectRatio:i.aspectRatio,originalElement:this.element,_proportionallyResizeElements:[],_helper:i.helper||i.ghost||i.animate?i.helper||"ui-resizable-helper":null}),this.element[0].nodeName.match(/^(canvas|textarea|input|select|button|img)$/i)&&(this.element.wrap(t("<div class='ui-wrapper' style='overflow: hidden;'></div>").css({position:this.element.css("position"),width:this.element.outerWidth(),height:this.element.outerHeight(),top:this.element.css("top"),left:this.element.css("left")})),this.element=this.element.parent().data("ui-resizable",this.element.resizable("instance")),this.elementIsWrapper=!0,e={marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom"),marginLeft:this.originalElement.css("marginLeft")},this.element.css(e),this.originalElement.css("margin",0),this.originalResizeStyle=this.originalElement.css("resize"),this.originalElement.css("resize","none"),this._proportionallyResizeElements.push(this.originalElement.css({position:"static",zoom:1,display:"block"})),this.originalElement.css(e),this._proportionallyResize()),this._setupHandles(),i.autoHide&&t(this.element).on("mouseenter",function(){i.disabled||(s._removeClass("ui-resizable-autohide"),s._handles.show())
|
||
}).on("mouseleave",function(){i.disabled||s.resizing||(s._addClass("ui-resizable-autohide"),s._handles.hide())}),this._mouseInit()},_destroy:function(){this._mouseDestroy();var e,i=function(e){t(e).removeData("resizable").removeData("ui-resizable").off(".resizable").find(".ui-resizable-handle").remove()};return this.elementIsWrapper&&(i(this.element),e=this.element,this.originalElement.css({position:e.css("position"),width:e.outerWidth(),height:e.outerHeight(),top:e.css("top"),left:e.css("left")}).insertAfter(e),e.remove()),this.originalElement.css("resize",this.originalResizeStyle),i(this.originalElement),this},_setOption:function(t,e){switch(this._super(t,e),t){case"handles":this._removeHandles(),this._setupHandles();break;default:}},_setupHandles:function(){var e,i,s,n,o,a=this.options,r=this;if(this.handles=a.handles||(t(".ui-resizable-handle",this.element).length?{n:".ui-resizable-n",e:".ui-resizable-e",s:".ui-resizable-s",w:".ui-resizable-w",se:".ui-resizable-se",sw:".ui-resizable-sw",ne:".ui-resizable-ne",nw:".ui-resizable-nw"}:"e,s,se"),this._handles=t(),this.handles.constructor===String)for("all"===this.handles&&(this.handles="n,e,s,w,se,sw,ne,nw"),s=this.handles.split(","),this.handles={},i=0;s.length>i;i++)e=t.trim(s[i]),n="ui-resizable-"+e,o=t("<div>"),this._addClass(o,"ui-resizable-handle "+n),o.css({zIndex:a.zIndex}),this.handles[e]=".ui-resizable-"+e,this.element.append(o);this._renderAxis=function(e){var i,s,n,o;e=e||this.element;for(i in this.handles)this.handles[i].constructor===String?this.handles[i]=this.element.children(this.handles[i]).first().show():(this.handles[i].jquery||this.handles[i].nodeType)&&(this.handles[i]=t(this.handles[i]),this._on(this.handles[i],{mousedown:r._mouseDown})),this.elementIsWrapper&&this.originalElement[0].nodeName.match(/^(textarea|input|select|button)$/i)&&(s=t(this.handles[i],this.element),o=/sw|ne|nw|se|n|s/.test(i)?s.outerHeight():s.outerWidth(),n=["padding",/ne|nw|n/.test(i)?"Top":/se|sw|s/.test(i)?"Bottom":/^e$/.test(i)?"Right":"Left"].join(""),e.css(n,o),this._proportionallyResize()),this._handles=this._handles.add(this.handles[i])},this._renderAxis(this.element),this._handles=this._handles.add(this.element.find(".ui-resizable-handle")),this._handles.disableSelection(),this._handles.on("mouseover",function(){r.resizing||(this.className&&(o=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i)),r.axis=o&&o[1]?o[1]:"se")}),a.autoHide&&(this._handles.hide(),this._addClass("ui-resizable-autohide"))},_removeHandles:function(){this._handles.remove()},_mouseCapture:function(e){var i,s,n=!1;for(i in this.handles)s=t(this.handles[i])[0],(s===e.target||t.contains(s,e.target))&&(n=!0);return!this.options.disabled&&n},_mouseStart:function(e){var i,s,n,o=this.options,a=this.element;return this.resizing=!0,this._renderProxy(),i=this._num(this.helper.css("left")),s=this._num(this.helper.css("top")),o.containment&&(i+=t(o.containment).scrollLeft()||0,s+=t(o.containment).scrollTop()||0),this.offset=this.helper.offset(),this.position={left:i,top:s},this.size=this._helper?{width:this.helper.width(),height:this.helper.height()}:{width:a.width(),height:a.height()},this.originalSize=this._helper?{width:a.outerWidth(),height:a.outerHeight()}:{width:a.width(),height:a.height()},this.sizeDiff={width:a.outerWidth()-a.width(),height:a.outerHeight()-a.height()},this.originalPosition={left:i,top:s},this.originalMousePosition={left:e.pageX,top:e.pageY},this.aspectRatio="number"==typeof o.aspectRatio?o.aspectRatio:this.originalSize.width/this.originalSize.height||1,n=t(".ui-resizable-"+this.axis).css("cursor"),t("body").css("cursor","auto"===n?this.axis+"-resize":n),this._addClass("ui-resizable-resizing"),this._propagate("start",e),!0},_mouseDrag:function(e){var i,s,n=this.originalMousePosition,o=this.axis,a=e.pageX-n.left||0,r=e.pageY-n.top||0,l=this._change[o];return this._updatePrevProperties(),l?(i=l.apply(this,[e,a,r]),this._updateVirtualBoundaries(e.shiftKey),(this._aspectRatio||e.shiftKey)&&(i=this._updateRatio(i,e)),i=this._respectSize(i,e),this._updateCache(i),this._propagate("resize",e),s=this._applyChanges(),!this._helper&&this._proportionallyResizeElements.length&&this._proportionallyResize(),t.isEmptyObject(s)||(this._updatePrevProperties(),this._trigger("resize",e,this.ui()),this._applyChanges()),!1):!1},_mouseStop:function(e){this.resizing=!1;var i,s,n,o,a,r,l,h=this.options,c=this;return this._helper&&(i=this._proportionallyResizeElements,s=i.length&&/textarea/i.test(i[0].nodeName),n=s&&this._hasScroll(i[0],"left")?0:c.sizeDiff.height,o=s?0:c.sizeDiff.width,a={width:c.helper.width()-o,height:c.helper.height()-n},r=parseFloat(c.element.css("left"))+(c.position.left-c.originalPosition.left)||null,l=parseFloat(c.element.css("top"))+(c.position.top-c.originalPosition.top)||null,h.animate||this.element.css(t.extend(a,{top:l,left:r})),c.helper.height(c.size.height),c.helper.width(c.size.width),this._helper&&!h.animate&&this._proportionallyResize()),t("body").css("cursor","auto"),this._removeClass("ui-resizable-resizing"),this._propagate("stop",e),this._helper&&this.helper.remove(),!1},_updatePrevProperties:function(){this.prevPosition={top:this.position.top,left:this.position.left},this.prevSize={width:this.size.width,height:this.size.height}},_applyChanges:function(){var t={};return this.position.top!==this.prevPosition.top&&(t.top=this.position.top+"px"),this.position.left!==this.prevPosition.left&&(t.left=this.position.left+"px"),this.size.width!==this.prevSize.width&&(t.width=this.size.width+"px"),this.size.height!==this.prevSize.height&&(t.height=this.size.height+"px"),this.helper.css(t),t},_updateVirtualBoundaries:function(t){var e,i,s,n,o,a=this.options;o={minWidth:this._isNumber(a.minWidth)?a.minWidth:0,maxWidth:this._isNumber(a.maxWidth)?a.maxWidth:1/0,minHeight:this._isNumber(a.minHeight)?a.minHeight:0,maxHeight:this._isNumber(a.maxHeight)?a.maxHeight:1/0},(this._aspectRatio||t)&&(e=o.minHeight*this.aspectRatio,s=o.minWidth/this.aspectRatio,i=o.maxHeight*this.aspectRatio,n=o.maxWidth/this.aspectRatio,e>o.minWidth&&(o.minWidth=e),s>o.minHeight&&(o.minHeight=s),o.maxWidth>i&&(o.maxWidth=i),o.maxHeight>n&&(o.maxHeight=n)),this._vBoundaries=o},_updateCache:function(t){this.offset=this.helper.offset(),this._isNumber(t.left)&&(this.position.left=t.left),this._isNumber(t.top)&&(this.position.top=t.top),this._isNumber(t.height)&&(this.size.height=t.height),this._isNumber(t.width)&&(this.size.width=t.width)},_updateRatio:function(t){var e=this.position,i=this.size,s=this.axis;return this._isNumber(t.height)?t.width=t.height*this.aspectRatio:this._isNumber(t.width)&&(t.height=t.width/this.aspectRatio),"sw"===s&&(t.left=e.left+(i.width-t.width),t.top=null),"nw"===s&&(t.top=e.top+(i.height-t.height),t.left=e.left+(i.width-t.width)),t},_respectSize:function(t){var e=this._vBoundaries,i=this.axis,s=this._isNumber(t.width)&&e.maxWidth&&e.maxWidth<t.width,n=this._isNumber(t.height)&&e.maxHeight&&e.maxHeight<t.height,o=this._isNumber(t.width)&&e.minWidth&&e.minWidth>t.width,a=this._isNumber(t.height)&&e.minHeight&&e.minHeight>t.height,r=this.originalPosition.left+this.originalSize.width,l=this.originalPosition.top+this.originalSize.height,h=/sw|nw|w/.test(i),c=/nw|ne|n/.test(i);return o&&(t.width=e.minWidth),a&&(t.height=e.minHeight),s&&(t.width=e.maxWidth),n&&(t.height=e.maxHeight),o&&h&&(t.left=r-e.minWidth),s&&h&&(t.left=r-e.maxWidth),a&&c&&(t.top=l-e.minHeight),n&&c&&(t.top=l-e.maxHeight),t.width||t.height||t.left||!t.top?t.width||t.height||t.top||!t.left||(t.left=null):t.top=null,t},_getPaddingPlusBorderDimensions:function(t){for(var e=0,i=[],s=[t.css("borderTopWidth"),t.css("borderRightWidth"),t.css("borderBottomWidth"),t.css("borderLeftWidth")],n=[t.css("paddingTop"),t.css("paddingRight"),t.css("paddingBottom"),t.css("paddingLeft")];4>e;e++)i[e]=parseFloat(s[e])||0,i[e]+=parseFloat(n[e])||0;return{height:i[0]+i[2],width:i[1]+i[3]}},_proportionallyResize:function(){if(this._proportionallyResizeElements.length)for(var t,e=0,i=this.helper||this.element;this._proportionallyResizeElements.length>e;e++)t=this._proportionallyResizeElements[e],this.outerDimensions||(this.outerDimensions=this._getPaddingPlusBorderDimensions(t)),t.css({height:i.height()-this.outerDimensions.height||0,width:i.width()-this.outerDimensions.width||0})},_renderProxy:function(){var e=this.element,i=this.options;this.elementOffset=e.offset(),this._helper?(this.helper=this.helper||t("<div style='overflow:hidden;'></div>"),this._addClass(this.helper,this._helper),this.helper.css({width:this.element.outerWidth(),height:this.element.outerHeight(),position:"absolute",left:this.elementOffset.left+"px",top:this.elementOffset.top+"px",zIndex:++i.zIndex}),this.helper.appendTo("body").disableSelection()):this.helper=this.element},_change:{e:function(t,e){return{width:this.originalSize.width+e}},w:function(t,e){var i=this.originalSize,s=this.originalPosition;return{left:s.left+e,width:i.width-e}},n:function(t,e,i){var s=this.originalSize,n=this.originalPosition;return{top:n.top+i,height:s.height-i}},s:function(t,e,i){return{height:this.originalSize.height+i}},se:function(e,i,s){return t.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[e,i,s]))},sw:function(e,i,s){return t.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[e,i,s]))},ne:function(e,i,s){return t.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[e,i,s]))},nw:function(e,i,s){return t.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[e,i,s]))}},_propagate:function(e,i){t.ui.plugin.call(this,e,[i,this.ui()]),"resize"!==e&&this._trigger(e,i,this.ui())},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}}),t.ui.plugin.add("resizable","animate",{stop:function(e){var i=t(this).resizable("instance"),s=i.options,n=i._proportionallyResizeElements,o=n.length&&/textarea/i.test(n[0].nodeName),a=o&&i._hasScroll(n[0],"left")?0:i.sizeDiff.height,r=o?0:i.sizeDiff.width,l={width:i.size.width-r,height:i.size.height-a},h=parseFloat(i.element.css("left"))+(i.position.left-i.originalPosition.left)||null,c=parseFloat(i.element.css("top"))+(i.position.top-i.originalPosition.top)||null;i.element.animate(t.extend(l,c&&h?{top:c,left:h}:{}),{duration:s.animateDuration,easing:s.animateEasing,step:function(){var s={width:parseFloat(i.element.css("width")),height:parseFloat(i.element.css("height")),top:parseFloat(i.element.css("top")),left:parseFloat(i.element.css("left"))};n&&n.length&&t(n[0]).css({width:s.width,height:s.height}),i._updateCache(s),i._propagate("resize",e)}})}}),t.ui.plugin.add("resizable","containment",{start:function(){var e,i,s,n,o,a,r,l=t(this).resizable("instance"),h=l.options,c=l.element,u=h.containment,d=u instanceof t?u.get(0):/parent/.test(u)?c.parent().get(0):u;d&&(l.containerElement=t(d),/document/.test(u)||u===document?(l.containerOffset={left:0,top:0},l.containerPosition={left:0,top:0},l.parentData={element:t(document),left:0,top:0,width:t(document).width(),height:t(document).height()||document.body.parentNode.scrollHeight}):(e=t(d),i=[],t(["Top","Right","Left","Bottom"]).each(function(t,s){i[t]=l._num(e.css("padding"+s))}),l.containerOffset=e.offset(),l.containerPosition=e.position(),l.containerSize={height:e.innerHeight()-i[3],width:e.innerWidth()-i[1]},s=l.containerOffset,n=l.containerSize.height,o=l.containerSize.width,a=l._hasScroll(d,"left")?d.scrollWidth:o,r=l._hasScroll(d)?d.scrollHeight:n,l.parentData={element:d,left:s.left,top:s.top,width:a,height:r}))},resize:function(e){var i,s,n,o,a=t(this).resizable("instance"),r=a.options,l=a.containerOffset,h=a.position,c=a._aspectRatio||e.shiftKey,u={top:0,left:0},d=a.containerElement,p=!0;d[0]!==document&&/static/.test(d.css("position"))&&(u=l),h.left<(a._helper?l.left:0)&&(a.size.width=a.size.width+(a._helper?a.position.left-l.left:a.position.left-u.left),c&&(a.size.height=a.size.width/a.aspectRatio,p=!1),a.position.left=r.helper?l.left:0),h.top<(a._helper?l.top:0)&&(a.size.height=a.size.height+(a._helper?a.position.top-l.top:a.position.top),c&&(a.size.width=a.size.height*a.aspectRatio,p=!1),a.position.top=a._helper?l.top:0),n=a.containerElement.get(0)===a.element.parent().get(0),o=/relative|absolute/.test(a.containerElement.css("position")),n&&o?(a.offset.left=a.parentData.left+a.position.left,a.offset.top=a.parentData.top+a.position.top):(a.offset.left=a.element.offset().left,a.offset.top=a.element.offset().top),i=Math.abs(a.sizeDiff.width+(a._helper?a.offset.left-u.left:a.offset.left-l.left)),s=Math.abs(a.sizeDiff.height+(a._helper?a.offset.top-u.top:a.offset.top-l.top)),i+a.size.width>=a.parentData.width&&(a.size.width=a.parentData.width-i,c&&(a.size.height=a.size.width/a.aspectRatio,p=!1)),s+a.size.height>=a.parentData.height&&(a.size.height=a.parentData.height-s,c&&(a.size.width=a.size.height*a.aspectRatio,p=!1)),p||(a.position.left=a.prevPosition.left,a.position.top=a.prevPosition.top,a.size.width=a.prevSize.width,a.size.height=a.prevSize.height)},stop:function(){var e=t(this).resizable("instance"),i=e.options,s=e.containerOffset,n=e.containerPosition,o=e.containerElement,a=t(e.helper),r=a.offset(),l=a.outerWidth()-e.sizeDiff.width,h=a.outerHeight()-e.sizeDiff.height;e._helper&&!i.animate&&/relative/.test(o.css("position"))&&t(this).css({left:r.left-n.left-s.left,width:l,height:h}),e._helper&&!i.animate&&/static/.test(o.css("position"))&&t(this).css({left:r.left-n.left-s.left,width:l,height:h})}}),t.ui.plugin.add("resizable","alsoResize",{start:function(){var e=t(this).resizable("instance"),i=e.options;t(i.alsoResize).each(function(){var e=t(this);e.data("ui-resizable-alsoresize",{width:parseFloat(e.width()),height:parseFloat(e.height()),left:parseFloat(e.css("left")),top:parseFloat(e.css("top"))})})},resize:function(e,i){var s=t(this).resizable("instance"),n=s.options,o=s.originalSize,a=s.originalPosition,r={height:s.size.height-o.height||0,width:s.size.width-o.width||0,top:s.position.top-a.top||0,left:s.position.left-a.left||0};t(n.alsoResize).each(function(){var e=t(this),s=t(this).data("ui-resizable-alsoresize"),n={},o=e.parents(i.originalElement[0]).length?["width","height"]:["width","height","top","left"];t.each(o,function(t,e){var i=(s[e]||0)+(r[e]||0);i&&i>=0&&(n[e]=i||null)}),e.css(n)})},stop:function(){t(this).removeData("ui-resizable-alsoresize")}}),t.ui.plugin.add("resizable","ghost",{start:function(){var e=t(this).resizable("instance"),i=e.size;e.ghost=e.originalElement.clone(),e.ghost.css({opacity:.25,display:"block",position:"relative",height:i.height,width:i.width,margin:0,left:0,top:0}),e._addClass(e.ghost,"ui-resizable-ghost"),t.uiBackCompat!==!1&&"string"==typeof e.options.ghost&&e.ghost.addClass(this.options.ghost),e.ghost.appendTo(e.helper)},resize:function(){var e=t(this).resizable("instance");e.ghost&&e.ghost.css({position:"relative",height:e.size.height,width:e.size.width})},stop:function(){var e=t(this).resizable("instance");e.ghost&&e.helper&&e.helper.get(0).removeChild(e.ghost.get(0))}}),t.ui.plugin.add("resizable","grid",{resize:function(){var e,i=t(this).resizable("instance"),s=i.options,n=i.size,o=i.originalSize,a=i.originalPosition,r=i.axis,l="number"==typeof s.grid?[s.grid,s.grid]:s.grid,h=l[0]||1,c=l[1]||1,u=Math.round((n.width-o.width)/h)*h,d=Math.round((n.height-o.height)/c)*c,p=o.width+u,f=o.height+d,g=s.maxWidth&&p>s.maxWidth,m=s.maxHeight&&f>s.maxHeight,_=s.minWidth&&s.minWidth>p,v=s.minHeight&&s.minHeight>f;s.grid=l,_&&(p+=h),v&&(f+=c),g&&(p-=h),m&&(f-=c),/^(se|s|e)$/.test(r)?(i.size.width=p,i.size.height=f):/^(ne)$/.test(r)?(i.size.width=p,i.size.height=f,i.position.top=a.top-d):/^(sw)$/.test(r)?(i.size.width=p,i.size.height=f,i.position.left=a.left-u):((0>=f-c||0>=p-h)&&(e=i._getPaddingPlusBorderDimensions(this)),f-c>0?(i.size.height=f,i.position.top=a.top-d):(f=c-e.height,i.size.height=f,i.position.top=a.top+o.height-f),p-h>0?(i.size.width=p,i.position.left=a.left-u):(p=h-e.width,i.size.width=p,i.position.left=a.left+o.width-p))}}),t.ui.resizable,t.widget("ui.sortable",t.ui.mouse,{version:"1.12.0",widgetEventPrefix:"sort",ready:!1,options:{appendTo:"parent",axis:!1,connectWith:!1,containment:!1,cursor:"auto",cursorAt:!1,dropOnEmpty:!0,forcePlaceholderSize:!1,forceHelperSize:!1,grid:!1,handle:!1,helper:"original",items:"> *",opacity:!1,placeholder:!1,revert:!1,scroll:!0,scrollSensitivity:20,scrollSpeed:20,scope:"default",tolerance:"intersect",zIndex:1e3,activate:null,beforeStop:null,change:null,deactivate:null,out:null,over:null,receive:null,remove:null,sort:null,start:null,stop:null,update:null},_isOverAxis:function(t,e,i){return t>=e&&e+i>t},_isFloating:function(t){return/left|right/.test(t.css("float"))||/inline|table-cell/.test(t.css("display"))},_create:function(){this.containerCache={},this._addClass("ui-sortable"),this.refresh(),this.offset=this.element.offset(),this._mouseInit(),this._setHandleClassName(),this.ready=!0},_setOption:function(t,e){this._super(t,e),"handle"===t&&this._setHandleClassName()},_setHandleClassName:function(){var e=this;this._removeClass(this.element.find(".ui-sortable-handle"),"ui-sortable-handle"),t.each(this.items,function(){e._addClass(this.instance.options.handle?this.item.find(this.instance.options.handle):this.item,"ui-sortable-handle")})},_destroy:function(){this._mouseDestroy();for(var t=this.items.length-1;t>=0;t--)this.items[t].item.removeData(this.widgetName+"-item");return this},_mouseCapture:function(e,i){var s=null,n=!1,o=this;return this.reverting?!1:this.options.disabled||"static"===this.options.type?!1:(this._refreshItems(e),t(e.target).parents().each(function(){return t.data(this,o.widgetName+"-item")===o?(s=t(this),!1):void 0}),t.data(e.target,o.widgetName+"-item")===o&&(s=t(e.target)),s?!this.options.handle||i||(t(this.options.handle,s).find("*").addBack().each(function(){this===e.target&&(n=!0)}),n)?(this.currentItem=s,this._removeCurrentsFromItems(),!0):!1:!1)},_mouseStart:function(e,i,s){var n,o,a=this.options;if(this.currentContainer=this,this.refreshPositions(),this.helper=this._createHelper(e),this._cacheHelperProportions(),this._cacheMargins(),this.scrollParent=this.helper.scrollParent(),this.offset=this.currentItem.offset(),this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left},t.extend(this.offset,{click:{left:e.pageX-this.offset.left,top:e.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()}),this.helper.css("position","absolute"),this.cssPosition=this.helper.css("position"),this.originalPosition=this._generatePosition(e),this.originalPageX=e.pageX,this.originalPageY=e.pageY,a.cursorAt&&this._adjustOffsetFromHelper(a.cursorAt),this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]},this.helper[0]!==this.currentItem[0]&&this.currentItem.hide(),this._createPlaceholder(),a.containment&&this._setContainment(),a.cursor&&"auto"!==a.cursor&&(o=this.document.find("body"),this.storedCursor=o.css("cursor"),o.css("cursor",a.cursor),this.storedStylesheet=t("<style>*{ cursor: "+a.cursor+" !important; }</style>").appendTo(o)),a.opacity&&(this.helper.css("opacity")&&(this._storedOpacity=this.helper.css("opacity")),this.helper.css("opacity",a.opacity)),a.zIndex&&(this.helper.css("zIndex")&&(this._storedZIndex=this.helper.css("zIndex")),this.helper.css("zIndex",a.zIndex)),this.scrollParent[0]!==this.document[0]&&"HTML"!==this.scrollParent[0].tagName&&(this.overflowOffset=this.scrollParent.offset()),this._trigger("start",e,this._uiHash()),this._preserveHelperProportions||this._cacheHelperProportions(),!s)for(n=this.containers.length-1;n>=0;n--)this.containers[n]._trigger("activate",e,this._uiHash(this));return t.ui.ddmanager&&(t.ui.ddmanager.current=this),t.ui.ddmanager&&!a.dropBehaviour&&t.ui.ddmanager.prepareOffsets(this,e),this.dragging=!0,this._addClass(this.helper,"ui-sortable-helper"),this._mouseDrag(e),!0},_mouseDrag:function(e){var i,s,n,o,a=this.options,r=!1;for(this.position=this._generatePosition(e),this.positionAbs=this._convertPositionTo("absolute"),this.lastPositionAbs||(this.lastPositionAbs=this.positionAbs),this.options.scroll&&(this.scrollParent[0]!==this.document[0]&&"HTML"!==this.scrollParent[0].tagName?(this.overflowOffset.top+this.scrollParent[0].offsetHeight-e.pageY<a.scrollSensitivity?this.scrollParent[0].scrollTop=r=this.scrollParent[0].scrollTop+a.scrollSpeed:e.pageY-this.overflowOffset.top<a.scrollSensitivity&&(this.scrollParent[0].scrollTop=r=this.scrollParent[0].scrollTop-a.scrollSpeed),this.overflowOffset.left+this.scrollParent[0].offsetWidth-e.pageX<a.scrollSensitivity?this.scrollParent[0].scrollLeft=r=this.scrollParent[0].scrollLeft+a.scrollSpeed:e.pageX-this.overflowOffset.left<a.scrollSensitivity&&(this.scrollParent[0].scrollLeft=r=this.scrollParent[0].scrollLeft-a.scrollSpeed)):(e.pageY-this.document.scrollTop()<a.scrollSensitivity?r=this.document.scrollTop(this.document.scrollTop()-a.scrollSpeed):this.window.height()-(e.pageY-this.document.scrollTop())<a.scrollSensitivity&&(r=this.document.scrollTop(this.document.scrollTop()+a.scrollSpeed)),e.pageX-this.document.scrollLeft()<a.scrollSensitivity?r=this.document.scrollLeft(this.document.scrollLeft()-a.scrollSpeed):this.window.width()-(e.pageX-this.document.scrollLeft())<a.scrollSensitivity&&(r=this.document.scrollLeft(this.document.scrollLeft()+a.scrollSpeed))),r!==!1&&t.ui.ddmanager&&!a.dropBehaviour&&t.ui.ddmanager.prepareOffsets(this,e)),this.positionAbs=this._convertPositionTo("absolute"),this.options.axis&&"y"===this.options.axis||(this.helper[0].style.left=this.position.left+"px"),this.options.axis&&"x"===this.options.axis||(this.helper[0].style.top=this.position.top+"px"),i=this.items.length-1;i>=0;i--)if(s=this.items[i],n=s.item[0],o=this._intersectsWithPointer(s),o&&s.instance===this.currentContainer&&n!==this.currentItem[0]&&this.placeholder[1===o?"next":"prev"]()[0]!==n&&!t.contains(this.placeholder[0],n)&&("semi-dynamic"===this.options.type?!t.contains(this.element[0],n):!0)){if(this.direction=1===o?"down":"up","pointer"!==this.options.tolerance&&!this._intersectsWithSides(s))break;this._rearrange(e,s),this._trigger("change",e,this._uiHash());break}return this._contactContainers(e),t.ui.ddmanager&&t.ui.ddmanager.drag(this,e),this._trigger("sort",e,this._uiHash()),this.lastPositionAbs=this.positionAbs,!1},_mouseStop:function(e,i){if(e){if(t.ui.ddmanager&&!this.options.dropBehaviour&&t.ui.ddmanager.drop(this,e),this.options.revert){var s=this,n=this.placeholder.offset(),o=this.options.axis,a={};o&&"x"!==o||(a.left=n.left-this.offset.parent.left-this.margins.left+(this.offsetParent[0]===this.document[0].body?0:this.offsetParent[0].scrollLeft)),o&&"y"!==o||(a.top=n.top-this.offset.parent.top-this.margins.top+(this.offsetParent[0]===this.document[0].body?0:this.offsetParent[0].scrollTop)),this.reverting=!0,t(this.helper).animate(a,parseInt(this.options.revert,10)||500,function(){s._clear(e)})}else this._clear(e,i);return!1}},cancel:function(){if(this.dragging){this._mouseUp({target:null}),"original"===this.options.helper?(this.currentItem.css(this._storedCSS),this._removeClass(this.currentItem,"ui-sortable-helper")):this.currentItem.show();for(var e=this.containers.length-1;e>=0;e--)this.containers[e]._trigger("deactivate",null,this._uiHash(this)),this.containers[e].containerCache.over&&(this.containers[e]._trigger("out",null,this._uiHash(this)),this.containers[e].containerCache.over=0)}return this.placeholder&&(this.placeholder[0].parentNode&&this.placeholder[0].parentNode.removeChild(this.placeholder[0]),"original"!==this.options.helper&&this.helper&&this.helper[0].parentNode&&this.helper.remove(),t.extend(this,{helper:null,dragging:!1,reverting:!1,_noFinalSort:null}),this.domPosition.prev?t(this.domPosition.prev).after(this.currentItem):t(this.domPosition.parent).prepend(this.currentItem)),this},serialize:function(e){var i=this._getItemsAsjQuery(e&&e.connected),s=[];return e=e||{},t(i).each(function(){var i=(t(e.item||this).attr(e.attribute||"id")||"").match(e.expression||/(.+)[\-=_](.+)/);i&&s.push((e.key||i[1]+"[]")+"="+(e.key&&e.expression?i[1]:i[2]))}),!s.length&&e.key&&s.push(e.key+"="),s.join("&")},toArray:function(e){var i=this._getItemsAsjQuery(e&&e.connected),s=[];return e=e||{},i.each(function(){s.push(t(e.item||this).attr(e.attribute||"id")||"")}),s},_intersectsWith:function(t){var e=this.positionAbs.left,i=e+this.helperProportions.width,s=this.positionAbs.top,n=s+this.helperProportions.height,o=t.left,a=o+t.width,r=t.top,l=r+t.height,h=this.offset.click.top,c=this.offset.click.left,u="x"===this.options.axis||s+h>r&&l>s+h,d="y"===this.options.axis||e+c>o&&a>e+c,p=u&&d;return"pointer"===this.options.tolerance||this.options.forcePointerForContainers||"pointer"!==this.options.tolerance&&this.helperProportions[this.floating?"width":"height"]>t[this.floating?"width":"height"]?p:e+this.helperProportions.width/2>o&&a>i-this.helperProportions.width/2&&s+this.helperProportions.height/2>r&&l>n-this.helperProportions.height/2},_intersectsWithPointer:function(t){var e,i,s="x"===this.options.axis||this._isOverAxis(this.positionAbs.top+this.offset.click.top,t.top,t.height),n="y"===this.options.axis||this._isOverAxis(this.positionAbs.left+this.offset.click.left,t.left,t.width),o=s&&n;return o?(e=this._getDragVerticalDirection(),i=this._getDragHorizontalDirection(),this.floating?"right"===i||"down"===e?2:1:e&&("down"===e?2:1)):!1},_intersectsWithSides:function(t){var e=this._isOverAxis(this.positionAbs.top+this.offset.click.top,t.top+t.height/2,t.height),i=this._isOverAxis(this.positionAbs.left+this.offset.click.left,t.left+t.width/2,t.width),s=this._getDragVerticalDirection(),n=this._getDragHorizontalDirection();return this.floating&&n?"right"===n&&i||"left"===n&&!i:s&&("down"===s&&e||"up"===s&&!e)},_getDragVerticalDirection:function(){var t=this.positionAbs.top-this.lastPositionAbs.top;return 0!==t&&(t>0?"down":"up")},_getDragHorizontalDirection:function(){var t=this.positionAbs.left-this.lastPositionAbs.left;return 0!==t&&(t>0?"right":"left")},refresh:function(t){return this._refreshItems(t),this._setHandleClassName(),this.refreshPositions(),this},_connectWith:function(){var t=this.options;return t.connectWith.constructor===String?[t.connectWith]:t.connectWith},_getItemsAsjQuery:function(e){function i(){r.push(this)}var s,n,o,a,r=[],l=[],h=this._connectWith();if(h&&e)for(s=h.length-1;s>=0;s--)for(o=t(h[s],this.document[0]),n=o.length-1;n>=0;n--)a=t.data(o[n],this.widgetFullName),a&&a!==this&&!a.options.disabled&&l.push([t.isFunction(a.options.items)?a.options.items.call(a.element):t(a.options.items,a.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),a]);for(l.push([t.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):t(this.options.items,this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),this]),s=l.length-1;s>=0;s--)l[s][0].each(i);return t(r)},_removeCurrentsFromItems:function(){var e=this.currentItem.find(":data("+this.widgetName+"-item)");this.items=t.grep(this.items,function(t){for(var i=0;e.length>i;i++)if(e[i]===t.item[0])return!1;return!0})},_refreshItems:function(e){this.items=[],this.containers=[this];var i,s,n,o,a,r,l,h,c=this.items,u=[[t.isFunction(this.options.items)?this.options.items.call(this.element[0],e,{item:this.currentItem}):t(this.options.items,this.element),this]],d=this._connectWith();if(d&&this.ready)for(i=d.length-1;i>=0;i--)for(n=t(d[i],this.document[0]),s=n.length-1;s>=0;s--)o=t.data(n[s],this.widgetFullName),o&&o!==this&&!o.options.disabled&&(u.push([t.isFunction(o.options.items)?o.options.items.call(o.element[0],e,{item:this.currentItem}):t(o.options.items,o.element),o]),this.containers.push(o));for(i=u.length-1;i>=0;i--)for(a=u[i][1],r=u[i][0],s=0,h=r.length;h>s;s++)l=t(r[s]),l.data(this.widgetName+"-item",a),c.push({item:l,instance:a,width:0,height:0,left:0,top:0})},refreshPositions:function(e){this.floating=this.items.length?"x"===this.options.axis||this._isFloating(this.items[0].item):!1,this.offsetParent&&this.helper&&(this.offset.parent=this._getParentOffset());var i,s,n,o;for(i=this.items.length-1;i>=0;i--)s=this.items[i],s.instance!==this.currentContainer&&this.currentContainer&&s.item[0]!==this.currentItem[0]||(n=this.options.toleranceElement?t(this.options.toleranceElement,s.item):s.item,e||(s.width=n.outerWidth(),s.height=n.outerHeight()),o=n.offset(),s.left=o.left,s.top=o.top);if(this.options.custom&&this.options.custom.refreshContainers)this.options.custom.refreshContainers.call(this);else for(i=this.containers.length-1;i>=0;i--)o=this.containers[i].element.offset(),this.containers[i].containerCache.left=o.left,this.containers[i].containerCache.top=o.top,this.containers[i].containerCache.width=this.containers[i].element.outerWidth(),this.containers[i].containerCache.height=this.containers[i].element.outerHeight();return this},_createPlaceholder:function(e){e=e||this;var i,s=e.options;s.placeholder&&s.placeholder.constructor!==String||(i=s.placeholder,s.placeholder={element:function(){var s=e.currentItem[0].nodeName.toLowerCase(),n=t("<"+s+">",e.document[0]);return e._addClass(n,"ui-sortable-placeholder",i||e.currentItem[0].className)._removeClass(n,"ui-sortable-helper"),"tbody"===s?e._createTrPlaceholder(e.currentItem.find("tr").eq(0),t("<tr>",e.document[0]).appendTo(n)):"tr"===s?e._createTrPlaceholder(e.currentItem,n):"img"===s&&n.attr("src",e.currentItem.attr("src")),i||n.css("visibility","hidden"),n},update:function(t,n){(!i||s.forcePlaceholderSize)&&(n.height()||n.height(e.currentItem.innerHeight()-parseInt(e.currentItem.css("paddingTop")||0,10)-parseInt(e.currentItem.css("paddingBottom")||0,10)),n.width()||n.width(e.currentItem.innerWidth()-parseInt(e.currentItem.css("paddingLeft")||0,10)-parseInt(e.currentItem.css("paddingRight")||0,10)))}}),e.placeholder=t(s.placeholder.element.call(e.element,e.currentItem)),e.currentItem.after(e.placeholder),s.placeholder.update(e,e.placeholder)},_createTrPlaceholder:function(e,i){var s=this;e.children().each(function(){t("<td> </td>",s.document[0]).attr("colspan",t(this).attr("colspan")||1).appendTo(i)})},_contactContainers:function(e){var i,s,n,o,a,r,l,h,c,u,d=null,p=null;for(i=this.containers.length-1;i>=0;i--)if(!t.contains(this.currentItem[0],this.containers[i].element[0]))if(this._intersectsWith(this.containers[i].containerCache)){if(d&&t.contains(this.containers[i].element[0],d.element[0]))continue;d=this.containers[i],p=i}else this.containers[i].containerCache.over&&(this.containers[i]._trigger("out",e,this._uiHash(this)),this.containers[i].containerCache.over=0);if(d)if(1===this.containers.length)this.containers[p].containerCache.over||(this.containers[p]._trigger("over",e,this._uiHash(this)),this.containers[p].containerCache.over=1);else{for(n=1e4,o=null,c=d.floating||this._isFloating(this.currentItem),a=c?"left":"top",r=c?"width":"height",u=c?"pageX":"pageY",s=this.items.length-1;s>=0;s--)t.contains(this.containers[p].element[0],this.items[s].item[0])&&this.items[s].item[0]!==this.currentItem[0]&&(l=this.items[s].item.offset()[a],h=!1,e[u]-l>this.items[s][r]/2&&(h=!0),n>Math.abs(e[u]-l)&&(n=Math.abs(e[u]-l),o=this.items[s],this.direction=h?"up":"down"));if(!o&&!this.options.dropOnEmpty)return;if(this.currentContainer===this.containers[p])return this.currentContainer.containerCache.over||(this.containers[p]._trigger("over",e,this._uiHash()),this.currentContainer.containerCache.over=1),void 0;o?this._rearrange(e,o,null,!0):this._rearrange(e,null,this.containers[p].element,!0),this._trigger("change",e,this._uiHash()),this.containers[p]._trigger("change",e,this._uiHash(this)),this.currentContainer=this.containers[p],this.options.placeholder.update(this.currentContainer,this.placeholder),this.containers[p]._trigger("over",e,this._uiHash(this)),this.containers[p].containerCache.over=1
|
||
}},_createHelper:function(e){var i=this.options,s=t.isFunction(i.helper)?t(i.helper.apply(this.element[0],[e,this.currentItem])):"clone"===i.helper?this.currentItem.clone():this.currentItem;return s.parents("body").length||t("parent"!==i.appendTo?i.appendTo:this.currentItem[0].parentNode)[0].appendChild(s[0]),s[0]===this.currentItem[0]&&(this._storedCSS={width:this.currentItem[0].style.width,height:this.currentItem[0].style.height,position:this.currentItem.css("position"),top:this.currentItem.css("top"),left:this.currentItem.css("left")}),(!s[0].style.width||i.forceHelperSize)&&s.width(this.currentItem.width()),(!s[0].style.height||i.forceHelperSize)&&s.height(this.currentItem.height()),s},_adjustOffsetFromHelper:function(e){"string"==typeof e&&(e=e.split(" ")),t.isArray(e)&&(e={left:+e[0],top:+e[1]||0}),"left"in e&&(this.offset.click.left=e.left+this.margins.left),"right"in e&&(this.offset.click.left=this.helperProportions.width-e.right+this.margins.left),"top"in e&&(this.offset.click.top=e.top+this.margins.top),"bottom"in e&&(this.offset.click.top=this.helperProportions.height-e.bottom+this.margins.top)},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var e=this.offsetParent.offset();return"absolute"===this.cssPosition&&this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0])&&(e.left+=this.scrollParent.scrollLeft(),e.top+=this.scrollParent.scrollTop()),(this.offsetParent[0]===this.document[0].body||this.offsetParent[0].tagName&&"html"===this.offsetParent[0].tagName.toLowerCase()&&t.ui.ie)&&(e={top:0,left:0}),{top:e.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:e.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if("relative"===this.cssPosition){var t=this.currentItem.position();return{top:t.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:t.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}}return{top:0,left:0}},_cacheMargins:function(){this.margins={left:parseInt(this.currentItem.css("marginLeft"),10)||0,top:parseInt(this.currentItem.css("marginTop"),10)||0}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var e,i,s,n=this.options;"parent"===n.containment&&(n.containment=this.helper[0].parentNode),("document"===n.containment||"window"===n.containment)&&(this.containment=[0-this.offset.relative.left-this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,"document"===n.containment?this.document.width():this.window.width()-this.helperProportions.width-this.margins.left,("document"===n.containment?this.document.height()||document.body.parentNode.scrollHeight:this.window.height()||this.document[0].body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top]),/^(document|window|parent)$/.test(n.containment)||(e=t(n.containment)[0],i=t(n.containment).offset(),s="hidden"!==t(e).css("overflow"),this.containment=[i.left+(parseInt(t(e).css("borderLeftWidth"),10)||0)+(parseInt(t(e).css("paddingLeft"),10)||0)-this.margins.left,i.top+(parseInt(t(e).css("borderTopWidth"),10)||0)+(parseInt(t(e).css("paddingTop"),10)||0)-this.margins.top,i.left+(s?Math.max(e.scrollWidth,e.offsetWidth):e.offsetWidth)-(parseInt(t(e).css("borderLeftWidth"),10)||0)-(parseInt(t(e).css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left,i.top+(s?Math.max(e.scrollHeight,e.offsetHeight):e.offsetHeight)-(parseInt(t(e).css("borderTopWidth"),10)||0)-(parseInt(t(e).css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top])},_convertPositionTo:function(e,i){i||(i=this.position);var s="absolute"===e?1:-1,n="absolute"!==this.cssPosition||this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0])?this.scrollParent:this.offsetParent,o=/(html|body)/i.test(n[0].tagName);return{top:i.top+this.offset.relative.top*s+this.offset.parent.top*s-("fixed"===this.cssPosition?-this.scrollParent.scrollTop():o?0:n.scrollTop())*s,left:i.left+this.offset.relative.left*s+this.offset.parent.left*s-("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():o?0:n.scrollLeft())*s}},_generatePosition:function(e){var i,s,n=this.options,o=e.pageX,a=e.pageY,r="absolute"!==this.cssPosition||this.scrollParent[0]!==this.document[0]&&t.contains(this.scrollParent[0],this.offsetParent[0])?this.scrollParent:this.offsetParent,l=/(html|body)/i.test(r[0].tagName);return"relative"!==this.cssPosition||this.scrollParent[0]!==this.document[0]&&this.scrollParent[0]!==this.offsetParent[0]||(this.offset.relative=this._getRelativeOffset()),this.originalPosition&&(this.containment&&(e.pageX-this.offset.click.left<this.containment[0]&&(o=this.containment[0]+this.offset.click.left),e.pageY-this.offset.click.top<this.containment[1]&&(a=this.containment[1]+this.offset.click.top),e.pageX-this.offset.click.left>this.containment[2]&&(o=this.containment[2]+this.offset.click.left),e.pageY-this.offset.click.top>this.containment[3]&&(a=this.containment[3]+this.offset.click.top)),n.grid&&(i=this.originalPageY+Math.round((a-this.originalPageY)/n.grid[1])*n.grid[1],a=this.containment?i-this.offset.click.top>=this.containment[1]&&i-this.offset.click.top<=this.containment[3]?i:i-this.offset.click.top>=this.containment[1]?i-n.grid[1]:i+n.grid[1]:i,s=this.originalPageX+Math.round((o-this.originalPageX)/n.grid[0])*n.grid[0],o=this.containment?s-this.offset.click.left>=this.containment[0]&&s-this.offset.click.left<=this.containment[2]?s:s-this.offset.click.left>=this.containment[0]?s-n.grid[0]:s+n.grid[0]:s)),{top:a-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+("fixed"===this.cssPosition?-this.scrollParent.scrollTop():l?0:r.scrollTop()),left:o-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():l?0:r.scrollLeft())}},_rearrange:function(t,e,i,s){i?i[0].appendChild(this.placeholder[0]):e.item[0].parentNode.insertBefore(this.placeholder[0],"down"===this.direction?e.item[0]:e.item[0].nextSibling),this.counter=this.counter?++this.counter:1;var n=this.counter;this._delay(function(){n===this.counter&&this.refreshPositions(!s)})},_clear:function(t,e){function i(t,e,i){return function(s){i._trigger(t,s,e._uiHash(e))}}this.reverting=!1;var s,n=[];if(!this._noFinalSort&&this.currentItem.parent().length&&this.placeholder.before(this.currentItem),this._noFinalSort=null,this.helper[0]===this.currentItem[0]){for(s in this._storedCSS)("auto"===this._storedCSS[s]||"static"===this._storedCSS[s])&&(this._storedCSS[s]="");this.currentItem.css(this._storedCSS),this._removeClass(this.currentItem,"ui-sortable-helper")}else this.currentItem.show();for(this.fromOutside&&!e&&n.push(function(t){this._trigger("receive",t,this._uiHash(this.fromOutside))}),!this.fromOutside&&this.domPosition.prev===this.currentItem.prev().not(".ui-sortable-helper")[0]&&this.domPosition.parent===this.currentItem.parent()[0]||e||n.push(function(t){this._trigger("update",t,this._uiHash())}),this!==this.currentContainer&&(e||(n.push(function(t){this._trigger("remove",t,this._uiHash())}),n.push(function(t){return function(e){t._trigger("receive",e,this._uiHash(this))}}.call(this,this.currentContainer)),n.push(function(t){return function(e){t._trigger("update",e,this._uiHash(this))}}.call(this,this.currentContainer)))),s=this.containers.length-1;s>=0;s--)e||n.push(i("deactivate",this,this.containers[s])),this.containers[s].containerCache.over&&(n.push(i("out",this,this.containers[s])),this.containers[s].containerCache.over=0);if(this.storedCursor&&(this.document.find("body").css("cursor",this.storedCursor),this.storedStylesheet.remove()),this._storedOpacity&&this.helper.css("opacity",this._storedOpacity),this._storedZIndex&&this.helper.css("zIndex","auto"===this._storedZIndex?"":this._storedZIndex),this.dragging=!1,e||this._trigger("beforeStop",t,this._uiHash()),this.placeholder[0].parentNode.removeChild(this.placeholder[0]),this.cancelHelperRemoval||(this.helper[0]!==this.currentItem[0]&&this.helper.remove(),this.helper=null),!e){for(s=0;n.length>s;s++)n[s].call(this,t);this._trigger("stop",t,this._uiHash())}return this.fromOutside=!1,!this.cancelHelperRemoval},_trigger:function(){t.Widget.prototype._trigger.apply(this,arguments)===!1&&this.cancel()},_uiHash:function(e){var i=e||this;return{helper:i.helper,placeholder:i.placeholder||t([]),position:i.position,originalPosition:i.originalPosition,offset:i.positionAbs,item:i.currentItem,sender:e?e.element:null}}})});
|
||
|
||
/*!
|
||
* jQuery UI Touch Punch 0.2.3
|
||
*
|
||
* Copyright 2011–2014, Dave Furfero
|
||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||
*
|
||
* Depends:
|
||
* jquery.ui.widget.js
|
||
* jquery.ui.mouse.js
|
||
*/
|
||
!function(a){function f(a,b){if(!(a.originalEvent.touches.length>1)){a.preventDefault();var c=a.originalEvent.changedTouches[0],d=document.createEvent("MouseEvents");d.initMouseEvent(b,!0,!0,window,1,c.screenX,c.screenY,c.clientX,c.clientY,!1,!1,!1,!1,0,null),a.target.dispatchEvent(d)}}if(a.support.touch="ontouchend"in document,a.support.touch){var e,b=a.ui.mouse.prototype,c=b._mouseInit,d=b._mouseDestroy;b._touchStart=function(a){var b=this;!e&&b._mouseCapture(a.originalEvent.changedTouches[0])&&(e=!0,b._touchMoved=!1,f(a,"mouseover"),f(a,"mousemove"),f(a,"mousedown"))},b._touchMove=function(a){e&&(this._touchMoved=!0,f(a,"mousemove"))},b._touchEnd=function(a){e&&(f(a,"mouseup"),f(a,"mouseout"),this._touchMoved||f(a,"click"),e=!1)},b._mouseInit=function(){var b=this;b.element.on({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),c.call(b)},b._mouseDestroy=function(){var b=this;b.element.off({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery);
|
||
|
||
},{}],45:[function(require,module,exports){
|
||
module.exports = after
|
||
|
||
function after(count, callback, err_cb) {
|
||
var bail = false
|
||
err_cb = err_cb || noop
|
||
proxy.count = count
|
||
|
||
return (count === 0) ? callback() : proxy
|
||
|
||
function proxy(err, result) {
|
||
if (proxy.count <= 0) {
|
||
throw new Error('after called too many times')
|
||
}
|
||
--proxy.count
|
||
|
||
// after first error, rest are passed to err_cb
|
||
if (err) {
|
||
bail = true
|
||
callback(err)
|
||
// future error callbacks will go to error handler
|
||
callback = err_cb
|
||
} else if (proxy.count === 0 && !bail) {
|
||
callback(null, result)
|
||
}
|
||
}
|
||
}
|
||
|
||
function noop() {}
|
||
|
||
},{}],46:[function(require,module,exports){
|
||
/**
|
||
* An abstraction for slicing an arraybuffer even when
|
||
* ArrayBuffer.prototype.slice is not supported
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
module.exports = function(arraybuffer, start, end) {
|
||
var bytes = arraybuffer.byteLength;
|
||
start = start || 0;
|
||
end = end || bytes;
|
||
|
||
if (arraybuffer.slice) { return arraybuffer.slice(start, end); }
|
||
|
||
if (start < 0) { start += bytes; }
|
||
if (end < 0) { end += bytes; }
|
||
if (end > bytes) { end = bytes; }
|
||
|
||
if (start >= bytes || start >= end || bytes === 0) {
|
||
return new ArrayBuffer(0);
|
||
}
|
||
|
||
var abv = new Uint8Array(arraybuffer);
|
||
var result = new Uint8Array(end - start);
|
||
for (var i = start, ii = 0; i < end; i++, ii++) {
|
||
result[ii] = abv[i];
|
||
}
|
||
return result.buffer;
|
||
};
|
||
|
||
},{}],47:[function(require,module,exports){
|
||
|
||
/**
|
||
* Expose `Backoff`.
|
||
*/
|
||
|
||
module.exports = Backoff;
|
||
|
||
/**
|
||
* Initialize backoff timer with `opts`.
|
||
*
|
||
* - `min` initial timeout in milliseconds [100]
|
||
* - `max` max timeout [10000]
|
||
* - `jitter` [0]
|
||
* - `factor` [2]
|
||
*
|
||
* @param {Object} opts
|
||
* @api public
|
||
*/
|
||
|
||
function Backoff(opts) {
|
||
opts = opts || {};
|
||
this.ms = opts.min || 100;
|
||
this.max = opts.max || 10000;
|
||
this.factor = opts.factor || 2;
|
||
this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
|
||
this.attempts = 0;
|
||
}
|
||
|
||
/**
|
||
* Return the backoff duration.
|
||
*
|
||
* @return {Number}
|
||
* @api public
|
||
*/
|
||
|
||
Backoff.prototype.duration = function(){
|
||
var ms = this.ms * Math.pow(this.factor, this.attempts++);
|
||
if (this.jitter) {
|
||
var rand = Math.random();
|
||
var deviation = Math.floor(rand * this.jitter * ms);
|
||
ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
|
||
}
|
||
return Math.min(ms, this.max) | 0;
|
||
};
|
||
|
||
/**
|
||
* Reset the number of attempts.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Backoff.prototype.reset = function(){
|
||
this.attempts = 0;
|
||
};
|
||
|
||
/**
|
||
* Set the minimum duration
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Backoff.prototype.setMin = function(min){
|
||
this.ms = min;
|
||
};
|
||
|
||
/**
|
||
* Set the maximum duration
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Backoff.prototype.setMax = function(max){
|
||
this.max = max;
|
||
};
|
||
|
||
/**
|
||
* Set the jitter
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Backoff.prototype.setJitter = function(jitter){
|
||
this.jitter = jitter;
|
||
};
|
||
|
||
|
||
},{}],48:[function(require,module,exports){
|
||
/*
|
||
* base64-arraybuffer
|
||
* https://github.com/niklasvh/base64-arraybuffer
|
||
*
|
||
* Copyright (c) 2012 Niklas von Hertzen
|
||
* Licensed under the MIT license.
|
||
*/
|
||
(function(chars){
|
||
"use strict";
|
||
|
||
exports.encode = function(arraybuffer) {
|
||
var bytes = new Uint8Array(arraybuffer),
|
||
i, len = bytes.length, base64 = "";
|
||
|
||
for (i = 0; i < len; i+=3) {
|
||
base64 += chars[bytes[i] >> 2];
|
||
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
|
||
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
|
||
base64 += chars[bytes[i + 2] & 63];
|
||
}
|
||
|
||
if ((len % 3) === 2) {
|
||
base64 = base64.substring(0, base64.length - 1) + "=";
|
||
} else if (len % 3 === 1) {
|
||
base64 = base64.substring(0, base64.length - 2) + "==";
|
||
}
|
||
|
||
return base64;
|
||
};
|
||
|
||
exports.decode = function(base64) {
|
||
var bufferLength = base64.length * 0.75,
|
||
len = base64.length, i, p = 0,
|
||
encoded1, encoded2, encoded3, encoded4;
|
||
|
||
if (base64[base64.length - 1] === "=") {
|
||
bufferLength--;
|
||
if (base64[base64.length - 2] === "=") {
|
||
bufferLength--;
|
||
}
|
||
}
|
||
|
||
var arraybuffer = new ArrayBuffer(bufferLength),
|
||
bytes = new Uint8Array(arraybuffer);
|
||
|
||
for (i = 0; i < len; i+=4) {
|
||
encoded1 = chars.indexOf(base64[i]);
|
||
encoded2 = chars.indexOf(base64[i+1]);
|
||
encoded3 = chars.indexOf(base64[i+2]);
|
||
encoded4 = chars.indexOf(base64[i+3]);
|
||
|
||
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
||
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
||
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
||
}
|
||
|
||
return arraybuffer;
|
||
};
|
||
})("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
|
||
|
||
},{}],49:[function(require,module,exports){
|
||
(function (global){
|
||
/**
|
||
* Create a blob builder even when vendor prefixes exist
|
||
*/
|
||
|
||
var BlobBuilder = global.BlobBuilder
|
||
|| global.WebKitBlobBuilder
|
||
|| global.MSBlobBuilder
|
||
|| global.MozBlobBuilder;
|
||
|
||
/**
|
||
* Check if Blob constructor is supported
|
||
*/
|
||
|
||
var blobSupported = (function() {
|
||
try {
|
||
var a = new Blob(['hi']);
|
||
return a.size === 2;
|
||
} catch(e) {
|
||
return false;
|
||
}
|
||
})();
|
||
|
||
/**
|
||
* Check if Blob constructor supports ArrayBufferViews
|
||
* Fails in Safari 6, so we need to map to ArrayBuffers there.
|
||
*/
|
||
|
||
var blobSupportsArrayBufferView = blobSupported && (function() {
|
||
try {
|
||
var b = new Blob([new Uint8Array([1,2])]);
|
||
return b.size === 2;
|
||
} catch(e) {
|
||
return false;
|
||
}
|
||
})();
|
||
|
||
/**
|
||
* Check if BlobBuilder is supported
|
||
*/
|
||
|
||
var blobBuilderSupported = BlobBuilder
|
||
&& BlobBuilder.prototype.append
|
||
&& BlobBuilder.prototype.getBlob;
|
||
|
||
/**
|
||
* Helper function that maps ArrayBufferViews to ArrayBuffers
|
||
* Used by BlobBuilder constructor and old browsers that didn't
|
||
* support it in the Blob constructor.
|
||
*/
|
||
|
||
function mapArrayBufferViews(ary) {
|
||
for (var i = 0; i < ary.length; i++) {
|
||
var chunk = ary[i];
|
||
if (chunk.buffer instanceof ArrayBuffer) {
|
||
var buf = chunk.buffer;
|
||
|
||
// if this is a subarray, make a copy so we only
|
||
// include the subarray region from the underlying buffer
|
||
if (chunk.byteLength !== buf.byteLength) {
|
||
var copy = new Uint8Array(chunk.byteLength);
|
||
copy.set(new Uint8Array(buf, chunk.byteOffset, chunk.byteLength));
|
||
buf = copy.buffer;
|
||
}
|
||
|
||
ary[i] = buf;
|
||
}
|
||
}
|
||
}
|
||
|
||
function BlobBuilderConstructor(ary, options) {
|
||
options = options || {};
|
||
|
||
var bb = new BlobBuilder();
|
||
mapArrayBufferViews(ary);
|
||
|
||
for (var i = 0; i < ary.length; i++) {
|
||
bb.append(ary[i]);
|
||
}
|
||
|
||
return (options.type) ? bb.getBlob(options.type) : bb.getBlob();
|
||
};
|
||
|
||
function BlobConstructor(ary, options) {
|
||
mapArrayBufferViews(ary);
|
||
return new Blob(ary, options || {});
|
||
};
|
||
|
||
module.exports = (function() {
|
||
if (blobSupported) {
|
||
return blobSupportsArrayBufferView ? global.Blob : BlobConstructor;
|
||
} else if (blobBuilderSupported) {
|
||
return BlobBuilderConstructor;
|
||
} else {
|
||
return undefined;
|
||
}
|
||
})();
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{}],50:[function(require,module,exports){
|
||
|
||
},{}],51:[function(require,module,exports){
|
||
/**
|
||
* Slice reference.
|
||
*/
|
||
|
||
var slice = [].slice;
|
||
|
||
/**
|
||
* Bind `obj` to `fn`.
|
||
*
|
||
* @param {Object} obj
|
||
* @param {Function|String} fn or string
|
||
* @return {Function}
|
||
* @api public
|
||
*/
|
||
|
||
module.exports = function(obj, fn){
|
||
if ('string' == typeof fn) fn = obj[fn];
|
||
if ('function' != typeof fn) throw new Error('bind() requires a function');
|
||
var args = slice.call(arguments, 2);
|
||
return function(){
|
||
return fn.apply(obj, args.concat(slice.call(arguments)));
|
||
}
|
||
};
|
||
|
||
},{}],52:[function(require,module,exports){
|
||
|
||
/**
|
||
* Expose `Emitter`.
|
||
*/
|
||
|
||
module.exports = Emitter;
|
||
|
||
/**
|
||
* Initialize a new `Emitter`.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
function Emitter(obj) {
|
||
if (obj) return mixin(obj);
|
||
};
|
||
|
||
/**
|
||
* Mixin the emitter properties.
|
||
*
|
||
* @param {Object} obj
|
||
* @return {Object}
|
||
* @api private
|
||
*/
|
||
|
||
function mixin(obj) {
|
||
for (var key in Emitter.prototype) {
|
||
obj[key] = Emitter.prototype[key];
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
/**
|
||
* Listen on the given `event` with `fn`.
|
||
*
|
||
* @param {String} event
|
||
* @param {Function} fn
|
||
* @return {Emitter}
|
||
* @api public
|
||
*/
|
||
|
||
Emitter.prototype.on =
|
||
Emitter.prototype.addEventListener = function(event, fn){
|
||
this._callbacks = this._callbacks || {};
|
||
(this._callbacks[event] = this._callbacks[event] || [])
|
||
.push(fn);
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Adds an `event` listener that will be invoked a single
|
||
* time then automatically removed.
|
||
*
|
||
* @param {String} event
|
||
* @param {Function} fn
|
||
* @return {Emitter}
|
||
* @api public
|
||
*/
|
||
|
||
Emitter.prototype.once = function(event, fn){
|
||
var self = this;
|
||
this._callbacks = this._callbacks || {};
|
||
|
||
function on() {
|
||
self.off(event, on);
|
||
fn.apply(this, arguments);
|
||
}
|
||
|
||
on.fn = fn;
|
||
this.on(event, on);
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Remove the given callback for `event` or all
|
||
* registered callbacks.
|
||
*
|
||
* @param {String} event
|
||
* @param {Function} fn
|
||
* @return {Emitter}
|
||
* @api public
|
||
*/
|
||
|
||
Emitter.prototype.off =
|
||
Emitter.prototype.removeListener =
|
||
Emitter.prototype.removeAllListeners =
|
||
Emitter.prototype.removeEventListener = function(event, fn){
|
||
this._callbacks = this._callbacks || {};
|
||
|
||
// all
|
||
if (0 == arguments.length) {
|
||
this._callbacks = {};
|
||
return this;
|
||
}
|
||
|
||
// specific event
|
||
var callbacks = this._callbacks[event];
|
||
if (!callbacks) return this;
|
||
|
||
// remove all handlers
|
||
if (1 == arguments.length) {
|
||
delete this._callbacks[event];
|
||
return this;
|
||
}
|
||
|
||
// remove specific handler
|
||
var cb;
|
||
for (var i = 0; i < callbacks.length; i++) {
|
||
cb = callbacks[i];
|
||
if (cb === fn || cb.fn === fn) {
|
||
callbacks.splice(i, 1);
|
||
break;
|
||
}
|
||
}
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Emit `event` with the given args.
|
||
*
|
||
* @param {String} event
|
||
* @param {Mixed} ...
|
||
* @return {Emitter}
|
||
*/
|
||
|
||
Emitter.prototype.emit = function(event){
|
||
this._callbacks = this._callbacks || {};
|
||
var args = [].slice.call(arguments, 1)
|
||
, callbacks = this._callbacks[event];
|
||
|
||
if (callbacks) {
|
||
callbacks = callbacks.slice(0);
|
||
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
||
callbacks[i].apply(this, args);
|
||
}
|
||
}
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Return array of callbacks for `event`.
|
||
*
|
||
* @param {String} event
|
||
* @return {Array}
|
||
* @api public
|
||
*/
|
||
|
||
Emitter.prototype.listeners = function(event){
|
||
this._callbacks = this._callbacks || {};
|
||
return this._callbacks[event] || [];
|
||
};
|
||
|
||
/**
|
||
* Check if this emitter has `event` handlers.
|
||
*
|
||
* @param {String} event
|
||
* @return {Boolean}
|
||
* @api public
|
||
*/
|
||
|
||
Emitter.prototype.hasListeners = function(event){
|
||
return !! this.listeners(event).length;
|
||
};
|
||
|
||
},{}],53:[function(require,module,exports){
|
||
|
||
module.exports = function(a, b){
|
||
var fn = function(){};
|
||
fn.prototype = b.prototype;
|
||
a.prototype = new fn;
|
||
a.prototype.constructor = a;
|
||
};
|
||
},{}],54:[function(require,module,exports){
|
||
|
||
/**
|
||
* This is the web browser implementation of `debug()`.
|
||
*
|
||
* Expose `debug()` as the module.
|
||
*/
|
||
|
||
exports = module.exports = require('./debug');
|
||
exports.log = log;
|
||
exports.formatArgs = formatArgs;
|
||
exports.save = save;
|
||
exports.load = load;
|
||
exports.useColors = useColors;
|
||
exports.storage = 'undefined' != typeof chrome
|
||
&& 'undefined' != typeof chrome.storage
|
||
? chrome.storage.local
|
||
: localstorage();
|
||
|
||
/**
|
||
* Colors.
|
||
*/
|
||
|
||
exports.colors = [
|
||
'lightseagreen',
|
||
'forestgreen',
|
||
'goldenrod',
|
||
'dodgerblue',
|
||
'darkorchid',
|
||
'crimson'
|
||
];
|
||
|
||
/**
|
||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
||
* and the Firebug extension (any Firefox version) are known
|
||
* to support "%c" CSS customizations.
|
||
*
|
||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
||
*/
|
||
|
||
function useColors() {
|
||
// is webkit? http://stackoverflow.com/a/16459606/376773
|
||
return ('WebkitAppearance' in document.documentElement.style) ||
|
||
// is firebug? http://stackoverflow.com/a/398120/376773
|
||
(window.console && (console.firebug || (console.exception && console.table))) ||
|
||
// is firefox >= v31?
|
||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
||
(navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31);
|
||
}
|
||
|
||
/**
|
||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
||
*/
|
||
|
||
exports.formatters.j = function(v) {
|
||
return JSON.stringify(v);
|
||
};
|
||
|
||
|
||
/**
|
||
* Colorize log arguments if enabled.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
function formatArgs() {
|
||
var args = arguments;
|
||
var useColors = this.useColors;
|
||
|
||
args[0] = (useColors ? '%c' : '')
|
||
+ this.namespace
|
||
+ (useColors ? ' %c' : ' ')
|
||
+ args[0]
|
||
+ (useColors ? '%c ' : ' ')
|
||
+ '+' + exports.humanize(this.diff);
|
||
|
||
if (!useColors) return args;
|
||
|
||
var c = 'color: ' + this.color;
|
||
args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1));
|
||
|
||
// the final "%c" is somewhat tricky, because there could be other
|
||
// arguments passed either before or after the %c, so we need to
|
||
// figure out the correct index to insert the CSS into
|
||
var index = 0;
|
||
var lastC = 0;
|
||
args[0].replace(/%[a-z%]/g, function(match) {
|
||
if ('%%' === match) return;
|
||
index++;
|
||
if ('%c' === match) {
|
||
// we only are interested in the *last* %c
|
||
// (the user may have provided their own)
|
||
lastC = index;
|
||
}
|
||
});
|
||
|
||
args.splice(lastC, 0, c);
|
||
return args;
|
||
}
|
||
|
||
/**
|
||
* Invokes `console.log()` when available.
|
||
* No-op when `console.log` is not a "function".
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
function log() {
|
||
// this hackery is required for IE8/9, where
|
||
// the `console.log` function doesn't have 'apply'
|
||
return 'object' === typeof console
|
||
&& console.log
|
||
&& Function.prototype.apply.call(console.log, console, arguments);
|
||
}
|
||
|
||
/**
|
||
* Save `namespaces`.
|
||
*
|
||
* @param {String} namespaces
|
||
* @api private
|
||
*/
|
||
|
||
function save(namespaces) {
|
||
try {
|
||
if (null == namespaces) {
|
||
exports.storage.removeItem('debug');
|
||
} else {
|
||
exports.storage.debug = namespaces;
|
||
}
|
||
} catch(e) {}
|
||
}
|
||
|
||
/**
|
||
* Load `namespaces`.
|
||
*
|
||
* @return {String} returns the previously persisted debug modes
|
||
* @api private
|
||
*/
|
||
|
||
function load() {
|
||
var r;
|
||
try {
|
||
r = exports.storage.debug;
|
||
} catch(e) {}
|
||
return r;
|
||
}
|
||
|
||
/**
|
||
* Enable namespaces listed in `localStorage.debug` initially.
|
||
*/
|
||
|
||
exports.enable(load());
|
||
|
||
/**
|
||
* Localstorage attempts to return the localstorage.
|
||
*
|
||
* This is necessary because safari throws
|
||
* when a user disables cookies/localstorage
|
||
* and you attempt to access it.
|
||
*
|
||
* @return {LocalStorage}
|
||
* @api private
|
||
*/
|
||
|
||
function localstorage(){
|
||
try {
|
||
return window.localStorage;
|
||
} catch (e) {}
|
||
}
|
||
|
||
},{"./debug":55}],55:[function(require,module,exports){
|
||
|
||
/**
|
||
* This is the common logic for both the Node.js and web browser
|
||
* implementations of `debug()`.
|
||
*
|
||
* Expose `debug()` as the module.
|
||
*/
|
||
|
||
exports = module.exports = debug;
|
||
exports.coerce = coerce;
|
||
exports.disable = disable;
|
||
exports.enable = enable;
|
||
exports.enabled = enabled;
|
||
exports.humanize = require('ms');
|
||
|
||
/**
|
||
* The currently active debug mode names, and names to skip.
|
||
*/
|
||
|
||
exports.names = [];
|
||
exports.skips = [];
|
||
|
||
/**
|
||
* Map of special "%n" handling functions, for the debug "format" argument.
|
||
*
|
||
* Valid key names are a single, lowercased letter, i.e. "n".
|
||
*/
|
||
|
||
exports.formatters = {};
|
||
|
||
/**
|
||
* Previously assigned color.
|
||
*/
|
||
|
||
var prevColor = 0;
|
||
|
||
/**
|
||
* Previous log timestamp.
|
||
*/
|
||
|
||
var prevTime;
|
||
|
||
/**
|
||
* Select a color.
|
||
*
|
||
* @return {Number}
|
||
* @api private
|
||
*/
|
||
|
||
function selectColor() {
|
||
return exports.colors[prevColor++ % exports.colors.length];
|
||
}
|
||
|
||
/**
|
||
* Create a debugger with the given `namespace`.
|
||
*
|
||
* @param {String} namespace
|
||
* @return {Function}
|
||
* @api public
|
||
*/
|
||
|
||
function debug(namespace) {
|
||
|
||
// define the `disabled` version
|
||
function disabled() {
|
||
}
|
||
disabled.enabled = false;
|
||
|
||
// define the `enabled` version
|
||
function enabled() {
|
||
|
||
var self = enabled;
|
||
|
||
// set `diff` timestamp
|
||
var curr = +new Date();
|
||
var ms = curr - (prevTime || curr);
|
||
self.diff = ms;
|
||
self.prev = prevTime;
|
||
self.curr = curr;
|
||
prevTime = curr;
|
||
|
||
// add the `color` if not set
|
||
if (null == self.useColors) self.useColors = exports.useColors();
|
||
if (null == self.color && self.useColors) self.color = selectColor();
|
||
|
||
var args = Array.prototype.slice.call(arguments);
|
||
|
||
args[0] = exports.coerce(args[0]);
|
||
|
||
if ('string' !== typeof args[0]) {
|
||
// anything else let's inspect with %o
|
||
args = ['%o'].concat(args);
|
||
}
|
||
|
||
// apply any `formatters` transformations
|
||
var index = 0;
|
||
args[0] = args[0].replace(/%([a-z%])/g, function(match, format) {
|
||
// if we encounter an escaped % then don't increase the array index
|
||
if (match === '%%') return match;
|
||
index++;
|
||
var formatter = exports.formatters[format];
|
||
if ('function' === typeof formatter) {
|
||
var val = args[index];
|
||
match = formatter.call(self, val);
|
||
|
||
// now we need to remove `args[index]` since it's inlined in the `format`
|
||
args.splice(index, 1);
|
||
index--;
|
||
}
|
||
return match;
|
||
});
|
||
|
||
if ('function' === typeof exports.formatArgs) {
|
||
args = exports.formatArgs.apply(self, args);
|
||
}
|
||
var logFn = enabled.log || exports.log || console.log.bind(console);
|
||
logFn.apply(self, args);
|
||
}
|
||
enabled.enabled = true;
|
||
|
||
var fn = exports.enabled(namespace) ? enabled : disabled;
|
||
|
||
fn.namespace = namespace;
|
||
|
||
return fn;
|
||
}
|
||
|
||
/**
|
||
* Enables a debug mode by namespaces. This can include modes
|
||
* separated by a colon and wildcards.
|
||
*
|
||
* @param {String} namespaces
|
||
* @api public
|
||
*/
|
||
|
||
function enable(namespaces) {
|
||
exports.save(namespaces);
|
||
|
||
var split = (namespaces || '').split(/[\s,]+/);
|
||
var len = split.length;
|
||
|
||
for (var i = 0; i < len; i++) {
|
||
if (!split[i]) continue; // ignore empty strings
|
||
namespaces = split[i].replace(/\*/g, '.*?');
|
||
if (namespaces[0] === '-') {
|
||
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
||
} else {
|
||
exports.names.push(new RegExp('^' + namespaces + '$'));
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Disable debug output.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
function disable() {
|
||
exports.enable('');
|
||
}
|
||
|
||
/**
|
||
* Returns true if the given mode name is enabled, false otherwise.
|
||
*
|
||
* @param {String} name
|
||
* @return {Boolean}
|
||
* @api public
|
||
*/
|
||
|
||
function enabled(name) {
|
||
var i, len;
|
||
for (i = 0, len = exports.skips.length; i < len; i++) {
|
||
if (exports.skips[i].test(name)) {
|
||
return false;
|
||
}
|
||
}
|
||
for (i = 0, len = exports.names.length; i < len; i++) {
|
||
if (exports.names[i].test(name)) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/**
|
||
* Coerce `val`.
|
||
*
|
||
* @param {Mixed} val
|
||
* @return {Mixed}
|
||
* @api private
|
||
*/
|
||
|
||
function coerce(val) {
|
||
if (val instanceof Error) return val.stack || val.message;
|
||
return val;
|
||
}
|
||
|
||
},{"ms":73}],56:[function(require,module,exports){
|
||
|
||
module.exports = require('./lib/');
|
||
|
||
},{"./lib/":57}],57:[function(require,module,exports){
|
||
|
||
module.exports = require('./socket');
|
||
|
||
/**
|
||
* Exports parser
|
||
*
|
||
* @api public
|
||
*
|
||
*/
|
||
module.exports.parser = require('engine.io-parser');
|
||
|
||
},{"./socket":58,"engine.io-parser":66}],58:[function(require,module,exports){
|
||
(function (global){
|
||
/**
|
||
* Module dependencies.
|
||
*/
|
||
|
||
var transports = require('./transports');
|
||
var Emitter = require('component-emitter');
|
||
var debug = require('debug')('engine.io-client:socket');
|
||
var index = require('indexof');
|
||
var parser = require('engine.io-parser');
|
||
var parseuri = require('parseuri');
|
||
var parsejson = require('parsejson');
|
||
var parseqs = require('parseqs');
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = Socket;
|
||
|
||
/**
|
||
* Noop function.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
function noop(){}
|
||
|
||
/**
|
||
* Socket constructor.
|
||
*
|
||
* @param {String|Object} uri or options
|
||
* @param {Object} options
|
||
* @api public
|
||
*/
|
||
|
||
function Socket(uri, opts){
|
||
if (!(this instanceof Socket)) return new Socket(uri, opts);
|
||
|
||
opts = opts || {};
|
||
|
||
if (uri && 'object' == typeof uri) {
|
||
opts = uri;
|
||
uri = null;
|
||
}
|
||
|
||
if (uri) {
|
||
uri = parseuri(uri);
|
||
opts.hostname = uri.host;
|
||
opts.secure = uri.protocol == 'https' || uri.protocol == 'wss';
|
||
opts.port = uri.port;
|
||
if (uri.query) opts.query = uri.query;
|
||
} else if (opts.host) {
|
||
opts.hostname = parseuri(opts.host).host;
|
||
}
|
||
|
||
this.secure = null != opts.secure ? opts.secure :
|
||
(global.location && 'https:' == location.protocol);
|
||
|
||
if (opts.hostname && !opts.port) {
|
||
// if no port is specified manually, use the protocol default
|
||
opts.port = this.secure ? '443' : '80';
|
||
}
|
||
|
||
this.agent = opts.agent || false;
|
||
this.hostname = opts.hostname ||
|
||
(global.location ? location.hostname : 'localhost');
|
||
this.port = opts.port || (global.location && location.port ?
|
||
location.port :
|
||
(this.secure ? 443 : 80));
|
||
this.query = opts.query || {};
|
||
if ('string' == typeof this.query) this.query = parseqs.decode(this.query);
|
||
this.upgrade = false !== opts.upgrade;
|
||
this.path = (opts.path || '/engine.io').replace(/\/$/, '') + '/';
|
||
this.forceJSONP = !!opts.forceJSONP;
|
||
this.jsonp = false !== opts.jsonp;
|
||
this.forceBase64 = !!opts.forceBase64;
|
||
this.enablesXDR = !!opts.enablesXDR;
|
||
this.timestampParam = opts.timestampParam || 't';
|
||
this.timestampRequests = opts.timestampRequests;
|
||
this.transports = opts.transports || ['polling', 'websocket'];
|
||
this.readyState = '';
|
||
this.writeBuffer = [];
|
||
this.policyPort = opts.policyPort || 843;
|
||
this.rememberUpgrade = opts.rememberUpgrade || false;
|
||
this.binaryType = null;
|
||
this.onlyBinaryUpgrades = opts.onlyBinaryUpgrades;
|
||
this.perMessageDeflate = false !== opts.perMessageDeflate ? (opts.perMessageDeflate || {}) : false;
|
||
|
||
if (true === this.perMessageDeflate) this.perMessageDeflate = {};
|
||
if (this.perMessageDeflate && null == this.perMessageDeflate.threshold) {
|
||
this.perMessageDeflate.threshold = 1024;
|
||
}
|
||
|
||
// SSL options for Node.js client
|
||
this.pfx = opts.pfx || null;
|
||
this.key = opts.key || null;
|
||
this.passphrase = opts.passphrase || null;
|
||
this.cert = opts.cert || null;
|
||
this.ca = opts.ca || null;
|
||
this.ciphers = opts.ciphers || null;
|
||
this.rejectUnauthorized = opts.rejectUnauthorized === undefined ? true : opts.rejectUnauthorized;
|
||
|
||
// other options for Node.js client
|
||
var freeGlobal = typeof global == 'object' && global;
|
||
if (freeGlobal.global === freeGlobal) {
|
||
if (opts.extraHeaders && Object.keys(opts.extraHeaders).length > 0) {
|
||
this.extraHeaders = opts.extraHeaders;
|
||
}
|
||
}
|
||
|
||
this.open();
|
||
}
|
||
|
||
Socket.priorWebsocketSuccess = false;
|
||
|
||
/**
|
||
* Mix in `Emitter`.
|
||
*/
|
||
|
||
Emitter(Socket.prototype);
|
||
|
||
/**
|
||
* Protocol version.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Socket.protocol = parser.protocol; // this is an int
|
||
|
||
/**
|
||
* Expose deps for legacy compatibility
|
||
* and standalone browser access.
|
||
*/
|
||
|
||
Socket.Socket = Socket;
|
||
Socket.Transport = require('./transport');
|
||
Socket.transports = require('./transports');
|
||
Socket.parser = require('engine.io-parser');
|
||
|
||
/**
|
||
* Creates transport of the given type.
|
||
*
|
||
* @param {String} transport name
|
||
* @return {Transport}
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.createTransport = function (name) {
|
||
debug('creating transport "%s"', name);
|
||
var query = clone(this.query);
|
||
|
||
// append engine.io protocol identifier
|
||
query.EIO = parser.protocol;
|
||
|
||
// transport name
|
||
query.transport = name;
|
||
|
||
// session id if we already have one
|
||
if (this.id) query.sid = this.id;
|
||
|
||
var transport = new transports[name]({
|
||
agent: this.agent,
|
||
hostname: this.hostname,
|
||
port: this.port,
|
||
secure: this.secure,
|
||
path: this.path,
|
||
query: query,
|
||
forceJSONP: this.forceJSONP,
|
||
jsonp: this.jsonp,
|
||
forceBase64: this.forceBase64,
|
||
enablesXDR: this.enablesXDR,
|
||
timestampRequests: this.timestampRequests,
|
||
timestampParam: this.timestampParam,
|
||
policyPort: this.policyPort,
|
||
socket: this,
|
||
pfx: this.pfx,
|
||
key: this.key,
|
||
passphrase: this.passphrase,
|
||
cert: this.cert,
|
||
ca: this.ca,
|
||
ciphers: this.ciphers,
|
||
rejectUnauthorized: this.rejectUnauthorized,
|
||
perMessageDeflate: this.perMessageDeflate,
|
||
extraHeaders: this.extraHeaders
|
||
});
|
||
|
||
return transport;
|
||
};
|
||
|
||
function clone (obj) {
|
||
var o = {};
|
||
for (var i in obj) {
|
||
if (obj.hasOwnProperty(i)) {
|
||
o[i] = obj[i];
|
||
}
|
||
}
|
||
return o;
|
||
}
|
||
|
||
/**
|
||
* Initializes transport to use and starts probe.
|
||
*
|
||
* @api private
|
||
*/
|
||
Socket.prototype.open = function () {
|
||
var transport;
|
||
if (this.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf('websocket') != -1) {
|
||
transport = 'websocket';
|
||
} else if (0 === this.transports.length) {
|
||
// Emit error on next tick so it can be listened to
|
||
var self = this;
|
||
setTimeout(function() {
|
||
self.emit('error', 'No transports available');
|
||
}, 0);
|
||
return;
|
||
} else {
|
||
transport = this.transports[0];
|
||
}
|
||
this.readyState = 'opening';
|
||
|
||
// Retry with the next transport if the transport is disabled (jsonp: false)
|
||
try {
|
||
transport = this.createTransport(transport);
|
||
} catch (e) {
|
||
this.transports.shift();
|
||
this.open();
|
||
return;
|
||
}
|
||
|
||
transport.open();
|
||
this.setTransport(transport);
|
||
};
|
||
|
||
/**
|
||
* Sets the current transport. Disables the existing one (if any).
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.setTransport = function(transport){
|
||
debug('setting transport %s', transport.name);
|
||
var self = this;
|
||
|
||
if (this.transport) {
|
||
debug('clearing existing transport %s', this.transport.name);
|
||
this.transport.removeAllListeners();
|
||
}
|
||
|
||
// set up transport
|
||
this.transport = transport;
|
||
|
||
// set up transport listeners
|
||
transport
|
||
.on('drain', function(){
|
||
self.onDrain();
|
||
})
|
||
.on('packet', function(packet){
|
||
self.onPacket(packet);
|
||
})
|
||
.on('error', function(e){
|
||
self.onError(e);
|
||
})
|
||
.on('close', function(){
|
||
self.onClose('transport close');
|
||
});
|
||
};
|
||
|
||
/**
|
||
* Probes a transport.
|
||
*
|
||
* @param {String} transport name
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.probe = function (name) {
|
||
debug('probing transport "%s"', name);
|
||
var transport = this.createTransport(name, { probe: 1 })
|
||
, failed = false
|
||
, self = this;
|
||
|
||
Socket.priorWebsocketSuccess = false;
|
||
|
||
function onTransportOpen(){
|
||
if (self.onlyBinaryUpgrades) {
|
||
var upgradeLosesBinary = !this.supportsBinary && self.transport.supportsBinary;
|
||
failed = failed || upgradeLosesBinary;
|
||
}
|
||
if (failed) return;
|
||
|
||
debug('probe transport "%s" opened', name);
|
||
transport.send([{ type: 'ping', data: 'probe' }]);
|
||
transport.once('packet', function (msg) {
|
||
if (failed) return;
|
||
if ('pong' == msg.type && 'probe' == msg.data) {
|
||
debug('probe transport "%s" pong', name);
|
||
self.upgrading = true;
|
||
self.emit('upgrading', transport);
|
||
if (!transport) return;
|
||
Socket.priorWebsocketSuccess = 'websocket' == transport.name;
|
||
|
||
debug('pausing current transport "%s"', self.transport.name);
|
||
self.transport.pause(function () {
|
||
if (failed) return;
|
||
if ('closed' == self.readyState) return;
|
||
debug('changing transport and sending upgrade packet');
|
||
|
||
cleanup();
|
||
|
||
self.setTransport(transport);
|
||
transport.send([{ type: 'upgrade' }]);
|
||
self.emit('upgrade', transport);
|
||
transport = null;
|
||
self.upgrading = false;
|
||
self.flush();
|
||
});
|
||
} else {
|
||
debug('probe transport "%s" failed', name);
|
||
var err = new Error('probe error');
|
||
err.transport = transport.name;
|
||
self.emit('upgradeError', err);
|
||
}
|
||
});
|
||
}
|
||
|
||
function freezeTransport() {
|
||
if (failed) return;
|
||
|
||
// Any callback called by transport should be ignored since now
|
||
failed = true;
|
||
|
||
cleanup();
|
||
|
||
transport.close();
|
||
transport = null;
|
||
}
|
||
|
||
//Handle any error that happens while probing
|
||
function onerror(err) {
|
||
var error = new Error('probe error: ' + err);
|
||
error.transport = transport.name;
|
||
|
||
freezeTransport();
|
||
|
||
debug('probe transport "%s" failed because of error: %s', name, err);
|
||
|
||
self.emit('upgradeError', error);
|
||
}
|
||
|
||
function onTransportClose(){
|
||
onerror("transport closed");
|
||
}
|
||
|
||
//When the socket is closed while we're probing
|
||
function onclose(){
|
||
onerror("socket closed");
|
||
}
|
||
|
||
//When the socket is upgraded while we're probing
|
||
function onupgrade(to){
|
||
if (transport && to.name != transport.name) {
|
||
debug('"%s" works - aborting "%s"', to.name, transport.name);
|
||
freezeTransport();
|
||
}
|
||
}
|
||
|
||
//Remove all listeners on the transport and on self
|
||
function cleanup(){
|
||
transport.removeListener('open', onTransportOpen);
|
||
transport.removeListener('error', onerror);
|
||
transport.removeListener('close', onTransportClose);
|
||
self.removeListener('close', onclose);
|
||
self.removeListener('upgrading', onupgrade);
|
||
}
|
||
|
||
transport.once('open', onTransportOpen);
|
||
transport.once('error', onerror);
|
||
transport.once('close', onTransportClose);
|
||
|
||
this.once('close', onclose);
|
||
this.once('upgrading', onupgrade);
|
||
|
||
transport.open();
|
||
|
||
};
|
||
|
||
/**
|
||
* Called when connection is deemed open.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Socket.prototype.onOpen = function () {
|
||
debug('socket open');
|
||
this.readyState = 'open';
|
||
Socket.priorWebsocketSuccess = 'websocket' == this.transport.name;
|
||
this.emit('open');
|
||
this.flush();
|
||
|
||
// we check for `readyState` in case an `open`
|
||
// listener already closed the socket
|
||
if ('open' == this.readyState && this.upgrade && this.transport.pause) {
|
||
debug('starting upgrade probes');
|
||
for (var i = 0, l = this.upgrades.length; i < l; i++) {
|
||
this.probe(this.upgrades[i]);
|
||
}
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Handles a packet.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onPacket = function (packet) {
|
||
if ('opening' == this.readyState || 'open' == this.readyState) {
|
||
debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
|
||
|
||
this.emit('packet', packet);
|
||
|
||
// Socket is live - any packet counts
|
||
this.emit('heartbeat');
|
||
|
||
switch (packet.type) {
|
||
case 'open':
|
||
this.onHandshake(parsejson(packet.data));
|
||
break;
|
||
|
||
case 'pong':
|
||
this.setPing();
|
||
this.emit('pong');
|
||
break;
|
||
|
||
case 'error':
|
||
var err = new Error('server error');
|
||
err.code = packet.data;
|
||
this.onError(err);
|
||
break;
|
||
|
||
case 'message':
|
||
this.emit('data', packet.data);
|
||
this.emit('message', packet.data);
|
||
break;
|
||
}
|
||
} else {
|
||
debug('packet received with socket readyState "%s"', this.readyState);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Called upon handshake completion.
|
||
*
|
||
* @param {Object} handshake obj
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onHandshake = function (data) {
|
||
this.emit('handshake', data);
|
||
this.id = data.sid;
|
||
this.transport.query.sid = data.sid;
|
||
this.upgrades = this.filterUpgrades(data.upgrades);
|
||
this.pingInterval = data.pingInterval;
|
||
this.pingTimeout = data.pingTimeout;
|
||
this.onOpen();
|
||
// In case open handler closes socket
|
||
if ('closed' == this.readyState) return;
|
||
this.setPing();
|
||
|
||
// Prolong liveness of socket on heartbeat
|
||
this.removeListener('heartbeat', this.onHeartbeat);
|
||
this.on('heartbeat', this.onHeartbeat);
|
||
};
|
||
|
||
/**
|
||
* Resets ping timeout.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onHeartbeat = function (timeout) {
|
||
clearTimeout(this.pingTimeoutTimer);
|
||
var self = this;
|
||
self.pingTimeoutTimer = setTimeout(function () {
|
||
if ('closed' == self.readyState) return;
|
||
self.onClose('ping timeout');
|
||
}, timeout || (self.pingInterval + self.pingTimeout));
|
||
};
|
||
|
||
/**
|
||
* Pings server every `this.pingInterval` and expects response
|
||
* within `this.pingTimeout` or closes connection.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.setPing = function () {
|
||
var self = this;
|
||
clearTimeout(self.pingIntervalTimer);
|
||
self.pingIntervalTimer = setTimeout(function () {
|
||
debug('writing ping packet - expecting pong within %sms', self.pingTimeout);
|
||
self.ping();
|
||
self.onHeartbeat(self.pingTimeout);
|
||
}, self.pingInterval);
|
||
};
|
||
|
||
/**
|
||
* Sends a ping packet.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.ping = function () {
|
||
var self = this;
|
||
this.sendPacket('ping', function(){
|
||
self.emit('ping');
|
||
});
|
||
};
|
||
|
||
/**
|
||
* Called on `drain` event
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onDrain = function() {
|
||
this.writeBuffer.splice(0, this.prevBufferLen);
|
||
|
||
// setting prevBufferLen = 0 is very important
|
||
// for example, when upgrading, upgrade packet is sent over,
|
||
// and a nonzero prevBufferLen could cause problems on `drain`
|
||
this.prevBufferLen = 0;
|
||
|
||
if (0 === this.writeBuffer.length) {
|
||
this.emit('drain');
|
||
} else {
|
||
this.flush();
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Flush write buffers.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.flush = function () {
|
||
if ('closed' != this.readyState && this.transport.writable &&
|
||
!this.upgrading && this.writeBuffer.length) {
|
||
debug('flushing %d packets in socket', this.writeBuffer.length);
|
||
this.transport.send(this.writeBuffer);
|
||
// keep track of current length of writeBuffer
|
||
// splice writeBuffer and callbackBuffer on `drain`
|
||
this.prevBufferLen = this.writeBuffer.length;
|
||
this.emit('flush');
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Sends a message.
|
||
*
|
||
* @param {String} message.
|
||
* @param {Function} callback function.
|
||
* @param {Object} options.
|
||
* @return {Socket} for chaining.
|
||
* @api public
|
||
*/
|
||
|
||
Socket.prototype.write =
|
||
Socket.prototype.send = function (msg, options, fn) {
|
||
this.sendPacket('message', msg, options, fn);
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Sends a packet.
|
||
*
|
||
* @param {String} packet type.
|
||
* @param {String} data.
|
||
* @param {Object} options.
|
||
* @param {Function} callback function.
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.sendPacket = function (type, data, options, fn) {
|
||
if('function' == typeof data) {
|
||
fn = data;
|
||
data = undefined;
|
||
}
|
||
|
||
if ('function' == typeof options) {
|
||
fn = options;
|
||
options = null;
|
||
}
|
||
|
||
if ('closing' == this.readyState || 'closed' == this.readyState) {
|
||
return;
|
||
}
|
||
|
||
options = options || {};
|
||
options.compress = false !== options.compress;
|
||
|
||
var packet = {
|
||
type: type,
|
||
data: data,
|
||
options: options
|
||
};
|
||
this.emit('packetCreate', packet);
|
||
this.writeBuffer.push(packet);
|
||
if (fn) this.once('flush', fn);
|
||
this.flush();
|
||
};
|
||
|
||
/**
|
||
* Closes the connection.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.close = function () {
|
||
if ('opening' == this.readyState || 'open' == this.readyState) {
|
||
this.readyState = 'closing';
|
||
|
||
var self = this;
|
||
|
||
if (this.writeBuffer.length) {
|
||
this.once('drain', function() {
|
||
if (this.upgrading) {
|
||
waitForUpgrade();
|
||
} else {
|
||
close();
|
||
}
|
||
});
|
||
} else if (this.upgrading) {
|
||
waitForUpgrade();
|
||
} else {
|
||
close();
|
||
}
|
||
}
|
||
|
||
function close() {
|
||
self.onClose('forced close');
|
||
debug('socket closing - telling transport to close');
|
||
self.transport.close();
|
||
}
|
||
|
||
function cleanupAndClose() {
|
||
self.removeListener('upgrade', cleanupAndClose);
|
||
self.removeListener('upgradeError', cleanupAndClose);
|
||
close();
|
||
}
|
||
|
||
function waitForUpgrade() {
|
||
// wait for upgrade to finish since we can't send packets while pausing a transport
|
||
self.once('upgrade', cleanupAndClose);
|
||
self.once('upgradeError', cleanupAndClose);
|
||
}
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Called upon transport error
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onError = function (err) {
|
||
debug('socket error %j', err);
|
||
Socket.priorWebsocketSuccess = false;
|
||
this.emit('error', err);
|
||
this.onClose('transport error', err);
|
||
};
|
||
|
||
/**
|
||
* Called upon transport close.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onClose = function (reason, desc) {
|
||
if ('opening' == this.readyState || 'open' == this.readyState || 'closing' == this.readyState) {
|
||
debug('socket close with reason: "%s"', reason);
|
||
var self = this;
|
||
|
||
// clear timers
|
||
clearTimeout(this.pingIntervalTimer);
|
||
clearTimeout(this.pingTimeoutTimer);
|
||
|
||
// stop event from firing again for transport
|
||
this.transport.removeAllListeners('close');
|
||
|
||
// ensure transport won't stay open
|
||
this.transport.close();
|
||
|
||
// ignore further transport communication
|
||
this.transport.removeAllListeners();
|
||
|
||
// set ready state
|
||
this.readyState = 'closed';
|
||
|
||
// clear session id
|
||
this.id = null;
|
||
|
||
// emit close event
|
||
this.emit('close', reason, desc);
|
||
|
||
// clean buffers after, so users can still
|
||
// grab the buffers on `close` event
|
||
self.writeBuffer = [];
|
||
self.prevBufferLen = 0;
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Filters upgrades, returning only those matching client transports.
|
||
*
|
||
* @param {Array} server upgrades
|
||
* @api private
|
||
*
|
||
*/
|
||
|
||
Socket.prototype.filterUpgrades = function (upgrades) {
|
||
var filteredUpgrades = [];
|
||
for (var i = 0, j = upgrades.length; i<j; i++) {
|
||
if (~index(this.transports, upgrades[i])) filteredUpgrades.push(upgrades[i]);
|
||
}
|
||
return filteredUpgrades;
|
||
};
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{"./transport":59,"./transports":60,"component-emitter":52,"debug":54,"engine.io-parser":66,"indexof":71,"parsejson":74,"parseqs":75,"parseuri":76}],59:[function(require,module,exports){
|
||
/**
|
||
* Module dependencies.
|
||
*/
|
||
|
||
var parser = require('engine.io-parser');
|
||
var Emitter = require('component-emitter');
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = Transport;
|
||
|
||
/**
|
||
* Transport abstract constructor.
|
||
*
|
||
* @param {Object} options.
|
||
* @api private
|
||
*/
|
||
|
||
function Transport (opts) {
|
||
this.path = opts.path;
|
||
this.hostname = opts.hostname;
|
||
this.port = opts.port;
|
||
this.secure = opts.secure;
|
||
this.query = opts.query;
|
||
this.timestampParam = opts.timestampParam;
|
||
this.timestampRequests = opts.timestampRequests;
|
||
this.readyState = '';
|
||
this.agent = opts.agent || false;
|
||
this.socket = opts.socket;
|
||
this.enablesXDR = opts.enablesXDR;
|
||
|
||
// SSL options for Node.js client
|
||
this.pfx = opts.pfx;
|
||
this.key = opts.key;
|
||
this.passphrase = opts.passphrase;
|
||
this.cert = opts.cert;
|
||
this.ca = opts.ca;
|
||
this.ciphers = opts.ciphers;
|
||
this.rejectUnauthorized = opts.rejectUnauthorized;
|
||
|
||
// other options for Node.js client
|
||
this.extraHeaders = opts.extraHeaders;
|
||
}
|
||
|
||
/**
|
||
* Mix in `Emitter`.
|
||
*/
|
||
|
||
Emitter(Transport.prototype);
|
||
|
||
/**
|
||
* Emits an error.
|
||
*
|
||
* @param {String} str
|
||
* @return {Transport} for chaining
|
||
* @api public
|
||
*/
|
||
|
||
Transport.prototype.onError = function (msg, desc) {
|
||
var err = new Error(msg);
|
||
err.type = 'TransportError';
|
||
err.description = desc;
|
||
this.emit('error', err);
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Opens the transport.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Transport.prototype.open = function () {
|
||
if ('closed' == this.readyState || '' == this.readyState) {
|
||
this.readyState = 'opening';
|
||
this.doOpen();
|
||
}
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Closes the transport.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Transport.prototype.close = function () {
|
||
if ('opening' == this.readyState || 'open' == this.readyState) {
|
||
this.doClose();
|
||
this.onClose();
|
||
}
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Sends multiple packets.
|
||
*
|
||
* @param {Array} packets
|
||
* @api private
|
||
*/
|
||
|
||
Transport.prototype.send = function(packets){
|
||
if ('open' == this.readyState) {
|
||
this.write(packets);
|
||
} else {
|
||
throw new Error('Transport not open');
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Called upon open
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Transport.prototype.onOpen = function () {
|
||
this.readyState = 'open';
|
||
this.writable = true;
|
||
this.emit('open');
|
||
};
|
||
|
||
/**
|
||
* Called with data.
|
||
*
|
||
* @param {String} data
|
||
* @api private
|
||
*/
|
||
|
||
Transport.prototype.onData = function(data){
|
||
var packet = parser.decodePacket(data, this.socket.binaryType);
|
||
this.onPacket(packet);
|
||
};
|
||
|
||
/**
|
||
* Called with a decoded packet.
|
||
*/
|
||
|
||
Transport.prototype.onPacket = function (packet) {
|
||
this.emit('packet', packet);
|
||
};
|
||
|
||
/**
|
||
* Called upon close.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Transport.prototype.onClose = function () {
|
||
this.readyState = 'closed';
|
||
this.emit('close');
|
||
};
|
||
|
||
},{"component-emitter":52,"engine.io-parser":66}],60:[function(require,module,exports){
|
||
(function (global){
|
||
/**
|
||
* Module dependencies
|
||
*/
|
||
|
||
var XMLHttpRequest = require('xmlhttprequest-ssl');
|
||
var XHR = require('./polling-xhr');
|
||
var JSONP = require('./polling-jsonp');
|
||
var websocket = require('./websocket');
|
||
|
||
/**
|
||
* Export transports.
|
||
*/
|
||
|
||
exports.polling = polling;
|
||
exports.websocket = websocket;
|
||
|
||
/**
|
||
* Polling transport polymorphic constructor.
|
||
* Decides on xhr vs jsonp based on feature detection.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
function polling(opts){
|
||
var xhr;
|
||
var xd = false;
|
||
var xs = false;
|
||
var jsonp = false !== opts.jsonp;
|
||
|
||
if (global.location) {
|
||
var isSSL = 'https:' == location.protocol;
|
||
var port = location.port;
|
||
|
||
// some user agents have empty `location.port`
|
||
if (!port) {
|
||
port = isSSL ? 443 : 80;
|
||
}
|
||
|
||
xd = opts.hostname != location.hostname || port != opts.port;
|
||
xs = opts.secure != isSSL;
|
||
}
|
||
|
||
opts.xdomain = xd;
|
||
opts.xscheme = xs;
|
||
xhr = new XMLHttpRequest(opts);
|
||
|
||
if ('open' in xhr && !opts.forceJSONP) {
|
||
return new XHR(opts);
|
||
} else {
|
||
if (!jsonp) throw new Error('JSONP disabled');
|
||
return new JSONP(opts);
|
||
}
|
||
}
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{"./polling-jsonp":61,"./polling-xhr":62,"./websocket":64,"xmlhttprequest-ssl":65}],61:[function(require,module,exports){
|
||
(function (global){
|
||
|
||
/**
|
||
* Module requirements.
|
||
*/
|
||
|
||
var Polling = require('./polling');
|
||
var inherit = require('component-inherit');
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = JSONPPolling;
|
||
|
||
/**
|
||
* Cached regular expressions.
|
||
*/
|
||
|
||
var rNewline = /\n/g;
|
||
var rEscapedNewline = /\\n/g;
|
||
|
||
/**
|
||
* Global JSONP callbacks.
|
||
*/
|
||
|
||
var callbacks;
|
||
|
||
/**
|
||
* Callbacks count.
|
||
*/
|
||
|
||
var index = 0;
|
||
|
||
/**
|
||
* Noop.
|
||
*/
|
||
|
||
function empty () { }
|
||
|
||
/**
|
||
* JSONP Polling constructor.
|
||
*
|
||
* @param {Object} opts.
|
||
* @api public
|
||
*/
|
||
|
||
function JSONPPolling (opts) {
|
||
Polling.call(this, opts);
|
||
|
||
this.query = this.query || {};
|
||
|
||
// define global callbacks array if not present
|
||
// we do this here (lazily) to avoid unneeded global pollution
|
||
if (!callbacks) {
|
||
// we need to consider multiple engines in the same page
|
||
if (!global.___eio) global.___eio = [];
|
||
callbacks = global.___eio;
|
||
}
|
||
|
||
// callback identifier
|
||
this.index = callbacks.length;
|
||
|
||
// add callback to jsonp global
|
||
var self = this;
|
||
callbacks.push(function (msg) {
|
||
self.onData(msg);
|
||
});
|
||
|
||
// append to query string
|
||
this.query.j = this.index;
|
||
|
||
// prevent spurious errors from being emitted when the window is unloaded
|
||
if (global.document && global.addEventListener) {
|
||
global.addEventListener('beforeunload', function () {
|
||
if (self.script) self.script.onerror = empty;
|
||
}, false);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Inherits from Polling.
|
||
*/
|
||
|
||
inherit(JSONPPolling, Polling);
|
||
|
||
/*
|
||
* JSONP only supports binary as base64 encoded strings
|
||
*/
|
||
|
||
JSONPPolling.prototype.supportsBinary = false;
|
||
|
||
/**
|
||
* Closes the socket.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
JSONPPolling.prototype.doClose = function () {
|
||
if (this.script) {
|
||
this.script.parentNode.removeChild(this.script);
|
||
this.script = null;
|
||
}
|
||
|
||
if (this.form) {
|
||
this.form.parentNode.removeChild(this.form);
|
||
this.form = null;
|
||
this.iframe = null;
|
||
}
|
||
|
||
Polling.prototype.doClose.call(this);
|
||
};
|
||
|
||
/**
|
||
* Starts a poll cycle.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
JSONPPolling.prototype.doPoll = function () {
|
||
var self = this;
|
||
var script = document.createElement('script');
|
||
|
||
if (this.script) {
|
||
this.script.parentNode.removeChild(this.script);
|
||
this.script = null;
|
||
}
|
||
|
||
script.async = true;
|
||
script.src = this.uri();
|
||
script.onerror = function(e){
|
||
self.onError('jsonp poll error',e);
|
||
};
|
||
|
||
var insertAt = document.getElementsByTagName('script')[0];
|
||
if (insertAt) {
|
||
insertAt.parentNode.insertBefore(script, insertAt);
|
||
}
|
||
else {
|
||
(document.head || document.body).appendChild(script);
|
||
}
|
||
this.script = script;
|
||
|
||
var isUAgecko = 'undefined' != typeof navigator && /gecko/i.test(navigator.userAgent);
|
||
|
||
if (isUAgecko) {
|
||
setTimeout(function () {
|
||
var iframe = document.createElement('iframe');
|
||
document.body.appendChild(iframe);
|
||
document.body.removeChild(iframe);
|
||
}, 100);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Writes with a hidden iframe.
|
||
*
|
||
* @param {String} data to send
|
||
* @param {Function} called upon flush.
|
||
* @api private
|
||
*/
|
||
|
||
JSONPPolling.prototype.doWrite = function (data, fn) {
|
||
var self = this;
|
||
|
||
if (!this.form) {
|
||
var form = document.createElement('form');
|
||
var area = document.createElement('textarea');
|
||
var id = this.iframeId = 'eio_iframe_' + this.index;
|
||
var iframe;
|
||
|
||
form.className = 'socketio';
|
||
form.style.position = 'absolute';
|
||
form.style.top = '-1000px';
|
||
form.style.left = '-1000px';
|
||
form.target = id;
|
||
form.method = 'POST';
|
||
form.setAttribute('accept-charset', 'utf-8');
|
||
area.name = 'd';
|
||
form.appendChild(area);
|
||
document.body.appendChild(form);
|
||
|
||
this.form = form;
|
||
this.area = area;
|
||
}
|
||
|
||
this.form.action = this.uri();
|
||
|
||
function complete () {
|
||
initIframe();
|
||
fn();
|
||
}
|
||
|
||
function initIframe () {
|
||
if (self.iframe) {
|
||
try {
|
||
self.form.removeChild(self.iframe);
|
||
} catch (e) {
|
||
self.onError('jsonp polling iframe removal error', e);
|
||
}
|
||
}
|
||
|
||
try {
|
||
// ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
|
||
var html = '<iframe src="javascript:0" name="'+ self.iframeId +'">';
|
||
iframe = document.createElement(html);
|
||
} catch (e) {
|
||
iframe = document.createElement('iframe');
|
||
iframe.name = self.iframeId;
|
||
iframe.src = 'javascript:0';
|
||
}
|
||
|
||
iframe.id = self.iframeId;
|
||
|
||
self.form.appendChild(iframe);
|
||
self.iframe = iframe;
|
||
}
|
||
|
||
initIframe();
|
||
|
||
// escape \n to prevent it from being converted into \r\n by some UAs
|
||
// double escaping is required for escaped new lines because unescaping of new lines can be done safely on server-side
|
||
data = data.replace(rEscapedNewline, '\\\n');
|
||
this.area.value = data.replace(rNewline, '\\n');
|
||
|
||
try {
|
||
this.form.submit();
|
||
} catch(e) {}
|
||
|
||
if (this.iframe.attachEvent) {
|
||
this.iframe.onreadystatechange = function(){
|
||
if (self.iframe.readyState == 'complete') {
|
||
complete();
|
||
}
|
||
};
|
||
} else {
|
||
this.iframe.onload = complete;
|
||
}
|
||
};
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{"./polling":63,"component-inherit":53}],62:[function(require,module,exports){
|
||
(function (global){
|
||
/**
|
||
* Module requirements.
|
||
*/
|
||
|
||
var XMLHttpRequest = require('xmlhttprequest-ssl');
|
||
var Polling = require('./polling');
|
||
var Emitter = require('component-emitter');
|
||
var inherit = require('component-inherit');
|
||
var debug = require('debug')('engine.io-client:polling-xhr');
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = XHR;
|
||
module.exports.Request = Request;
|
||
|
||
/**
|
||
* Empty function
|
||
*/
|
||
|
||
function empty(){}
|
||
|
||
/**
|
||
* XHR Polling constructor.
|
||
*
|
||
* @param {Object} opts
|
||
* @api public
|
||
*/
|
||
|
||
function XHR(opts){
|
||
Polling.call(this, opts);
|
||
|
||
if (global.location) {
|
||
var isSSL = 'https:' == location.protocol;
|
||
var port = location.port;
|
||
|
||
// some user agents have empty `location.port`
|
||
if (!port) {
|
||
port = isSSL ? 443 : 80;
|
||
}
|
||
|
||
this.xd = opts.hostname != global.location.hostname ||
|
||
port != opts.port;
|
||
this.xs = opts.secure != isSSL;
|
||
} else {
|
||
this.extraHeaders = opts.extraHeaders;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Inherits from Polling.
|
||
*/
|
||
|
||
inherit(XHR, Polling);
|
||
|
||
/**
|
||
* XHR supports binary
|
||
*/
|
||
|
||
XHR.prototype.supportsBinary = true;
|
||
|
||
/**
|
||
* Creates a request.
|
||
*
|
||
* @param {String} method
|
||
* @api private
|
||
*/
|
||
|
||
XHR.prototype.request = function(opts){
|
||
opts = opts || {};
|
||
opts.uri = this.uri();
|
||
opts.xd = this.xd;
|
||
opts.xs = this.xs;
|
||
opts.agent = this.agent || false;
|
||
opts.supportsBinary = this.supportsBinary;
|
||
opts.enablesXDR = this.enablesXDR;
|
||
|
||
// SSL options for Node.js client
|
||
opts.pfx = this.pfx;
|
||
opts.key = this.key;
|
||
opts.passphrase = this.passphrase;
|
||
opts.cert = this.cert;
|
||
opts.ca = this.ca;
|
||
opts.ciphers = this.ciphers;
|
||
opts.rejectUnauthorized = this.rejectUnauthorized;
|
||
|
||
// other options for Node.js client
|
||
opts.extraHeaders = this.extraHeaders;
|
||
|
||
return new Request(opts);
|
||
};
|
||
|
||
/**
|
||
* Sends data.
|
||
*
|
||
* @param {String} data to send.
|
||
* @param {Function} called upon flush.
|
||
* @api private
|
||
*/
|
||
|
||
XHR.prototype.doWrite = function(data, fn){
|
||
var isBinary = typeof data !== 'string' && data !== undefined;
|
||
var req = this.request({ method: 'POST', data: data, isBinary: isBinary });
|
||
var self = this;
|
||
req.on('success', fn);
|
||
req.on('error', function(err){
|
||
self.onError('xhr post error', err);
|
||
});
|
||
this.sendXhr = req;
|
||
};
|
||
|
||
/**
|
||
* Starts a poll cycle.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
XHR.prototype.doPoll = function(){
|
||
debug('xhr poll');
|
||
var req = this.request();
|
||
var self = this;
|
||
req.on('data', function(data){
|
||
self.onData(data);
|
||
});
|
||
req.on('error', function(err){
|
||
self.onError('xhr poll error', err);
|
||
});
|
||
this.pollXhr = req;
|
||
};
|
||
|
||
/**
|
||
* Request constructor
|
||
*
|
||
* @param {Object} options
|
||
* @api public
|
||
*/
|
||
|
||
function Request(opts){
|
||
this.method = opts.method || 'GET';
|
||
this.uri = opts.uri;
|
||
this.xd = !!opts.xd;
|
||
this.xs = !!opts.xs;
|
||
this.async = false !== opts.async;
|
||
this.data = undefined != opts.data ? opts.data : null;
|
||
this.agent = opts.agent;
|
||
this.isBinary = opts.isBinary;
|
||
this.supportsBinary = opts.supportsBinary;
|
||
this.enablesXDR = opts.enablesXDR;
|
||
|
||
// SSL options for Node.js client
|
||
this.pfx = opts.pfx;
|
||
this.key = opts.key;
|
||
this.passphrase = opts.passphrase;
|
||
this.cert = opts.cert;
|
||
this.ca = opts.ca;
|
||
this.ciphers = opts.ciphers;
|
||
this.rejectUnauthorized = opts.rejectUnauthorized;
|
||
|
||
// other options for Node.js client
|
||
this.extraHeaders = opts.extraHeaders;
|
||
|
||
this.create();
|
||
}
|
||
|
||
/**
|
||
* Mix in `Emitter`.
|
||
*/
|
||
|
||
Emitter(Request.prototype);
|
||
|
||
/**
|
||
* Creates the XHR object and sends the request.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Request.prototype.create = function(){
|
||
var opts = { agent: this.agent, xdomain: this.xd, xscheme: this.xs, enablesXDR: this.enablesXDR };
|
||
|
||
// SSL options for Node.js client
|
||
opts.pfx = this.pfx;
|
||
opts.key = this.key;
|
||
opts.passphrase = this.passphrase;
|
||
opts.cert = this.cert;
|
||
opts.ca = this.ca;
|
||
opts.ciphers = this.ciphers;
|
||
opts.rejectUnauthorized = this.rejectUnauthorized;
|
||
|
||
var xhr = this.xhr = new XMLHttpRequest(opts);
|
||
var self = this;
|
||
|
||
try {
|
||
debug('xhr open %s: %s', this.method, this.uri);
|
||
xhr.open(this.method, this.uri, this.async);
|
||
try {
|
||
if (this.extraHeaders) {
|
||
xhr.setDisableHeaderCheck(true);
|
||
for (var i in this.extraHeaders) {
|
||
if (this.extraHeaders.hasOwnProperty(i)) {
|
||
xhr.setRequestHeader(i, this.extraHeaders[i]);
|
||
}
|
||
}
|
||
}
|
||
} catch (e) {}
|
||
if (this.supportsBinary) {
|
||
// This has to be done after open because Firefox is stupid
|
||
// http://stackoverflow.com/questions/13216903/get-binary-data-with-xmlhttprequest-in-a-firefox-extension
|
||
xhr.responseType = 'arraybuffer';
|
||
}
|
||
|
||
if ('POST' == this.method) {
|
||
try {
|
||
if (this.isBinary) {
|
||
xhr.setRequestHeader('Content-type', 'application/octet-stream');
|
||
} else {
|
||
xhr.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
|
||
}
|
||
} catch (e) {}
|
||
}
|
||
|
||
// ie6 check
|
||
if ('withCredentials' in xhr) {
|
||
xhr.withCredentials = true;
|
||
}
|
||
|
||
if (this.hasXDR()) {
|
||
xhr.onload = function(){
|
||
self.onLoad();
|
||
};
|
||
xhr.onerror = function(){
|
||
self.onError(xhr.responseText);
|
||
};
|
||
} else {
|
||
xhr.onreadystatechange = function(){
|
||
if (4 != xhr.readyState) return;
|
||
if (200 == xhr.status || 1223 == xhr.status) {
|
||
self.onLoad();
|
||
} else {
|
||
// make sure the `error` event handler that's user-set
|
||
// does not throw in the same tick and gets caught here
|
||
setTimeout(function(){
|
||
self.onError(xhr.status);
|
||
}, 0);
|
||
}
|
||
};
|
||
}
|
||
|
||
debug('xhr data %s', this.data);
|
||
xhr.send(this.data);
|
||
} catch (e) {
|
||
// Need to defer since .create() is called directly fhrom the constructor
|
||
// and thus the 'error' event can only be only bound *after* this exception
|
||
// occurs. Therefore, also, we cannot throw here at all.
|
||
setTimeout(function() {
|
||
self.onError(e);
|
||
}, 0);
|
||
return;
|
||
}
|
||
|
||
if (global.document) {
|
||
this.index = Request.requestsCount++;
|
||
Request.requests[this.index] = this;
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Called upon successful response.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Request.prototype.onSuccess = function(){
|
||
this.emit('success');
|
||
this.cleanup();
|
||
};
|
||
|
||
/**
|
||
* Called if we have data.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Request.prototype.onData = function(data){
|
||
this.emit('data', data);
|
||
this.onSuccess();
|
||
};
|
||
|
||
/**
|
||
* Called upon error.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Request.prototype.onError = function(err){
|
||
this.emit('error', err);
|
||
this.cleanup(true);
|
||
};
|
||
|
||
/**
|
||
* Cleans up house.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Request.prototype.cleanup = function(fromError){
|
||
if ('undefined' == typeof this.xhr || null === this.xhr) {
|
||
return;
|
||
}
|
||
// xmlhttprequest
|
||
if (this.hasXDR()) {
|
||
this.xhr.onload = this.xhr.onerror = empty;
|
||
} else {
|
||
this.xhr.onreadystatechange = empty;
|
||
}
|
||
|
||
if (fromError) {
|
||
try {
|
||
this.xhr.abort();
|
||
} catch(e) {}
|
||
}
|
||
|
||
if (global.document) {
|
||
delete Request.requests[this.index];
|
||
}
|
||
|
||
this.xhr = null;
|
||
};
|
||
|
||
/**
|
||
* Called upon load.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Request.prototype.onLoad = function(){
|
||
var data;
|
||
try {
|
||
var contentType;
|
||
try {
|
||
contentType = this.xhr.getResponseHeader('Content-Type').split(';')[0];
|
||
} catch (e) {}
|
||
if (contentType === 'application/octet-stream') {
|
||
data = this.xhr.response;
|
||
} else {
|
||
if (!this.supportsBinary) {
|
||
data = this.xhr.responseText;
|
||
} else {
|
||
try {
|
||
data = String.fromCharCode.apply(null, new Uint8Array(this.xhr.response));
|
||
} catch (e) {
|
||
var ui8Arr = new Uint8Array(this.xhr.response);
|
||
var dataArray = [];
|
||
for (var idx = 0, length = ui8Arr.length; idx < length; idx++) {
|
||
dataArray.push(ui8Arr[idx]);
|
||
}
|
||
|
||
data = String.fromCharCode.apply(null, dataArray);
|
||
}
|
||
}
|
||
}
|
||
} catch (e) {
|
||
this.onError(e);
|
||
}
|
||
if (null != data) {
|
||
this.onData(data);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Check if it has XDomainRequest.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Request.prototype.hasXDR = function(){
|
||
return 'undefined' !== typeof global.XDomainRequest && !this.xs && this.enablesXDR;
|
||
};
|
||
|
||
/**
|
||
* Aborts the request.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Request.prototype.abort = function(){
|
||
this.cleanup();
|
||
};
|
||
|
||
/**
|
||
* Aborts pending requests when unloading the window. This is needed to prevent
|
||
* memory leaks (e.g. when using IE) and to ensure that no spurious error is
|
||
* emitted.
|
||
*/
|
||
|
||
if (global.document) {
|
||
Request.requestsCount = 0;
|
||
Request.requests = {};
|
||
if (global.attachEvent) {
|
||
global.attachEvent('onunload', unloadHandler);
|
||
} else if (global.addEventListener) {
|
||
global.addEventListener('beforeunload', unloadHandler, false);
|
||
}
|
||
}
|
||
|
||
function unloadHandler() {
|
||
for (var i in Request.requests) {
|
||
if (Request.requests.hasOwnProperty(i)) {
|
||
Request.requests[i].abort();
|
||
}
|
||
}
|
||
}
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{"./polling":63,"component-emitter":52,"component-inherit":53,"debug":54,"xmlhttprequest-ssl":65}],63:[function(require,module,exports){
|
||
/**
|
||
* Module dependencies.
|
||
*/
|
||
|
||
var Transport = require('../transport');
|
||
var parseqs = require('parseqs');
|
||
var parser = require('engine.io-parser');
|
||
var inherit = require('component-inherit');
|
||
var yeast = require('yeast');
|
||
var debug = require('debug')('engine.io-client:polling');
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = Polling;
|
||
|
||
/**
|
||
* Is XHR2 supported?
|
||
*/
|
||
|
||
var hasXHR2 = (function() {
|
||
var XMLHttpRequest = require('xmlhttprequest-ssl');
|
||
var xhr = new XMLHttpRequest({ xdomain: false });
|
||
return null != xhr.responseType;
|
||
})();
|
||
|
||
/**
|
||
* Polling interface.
|
||
*
|
||
* @param {Object} opts
|
||
* @api private
|
||
*/
|
||
|
||
function Polling(opts){
|
||
var forceBase64 = (opts && opts.forceBase64);
|
||
if (!hasXHR2 || forceBase64) {
|
||
this.supportsBinary = false;
|
||
}
|
||
Transport.call(this, opts);
|
||
}
|
||
|
||
/**
|
||
* Inherits from Transport.
|
||
*/
|
||
|
||
inherit(Polling, Transport);
|
||
|
||
/**
|
||
* Transport name.
|
||
*/
|
||
|
||
Polling.prototype.name = 'polling';
|
||
|
||
/**
|
||
* Opens the socket (triggers polling). We write a PING message to determine
|
||
* when the transport is open.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Polling.prototype.doOpen = function(){
|
||
this.poll();
|
||
};
|
||
|
||
/**
|
||
* Pauses polling.
|
||
*
|
||
* @param {Function} callback upon buffers are flushed and transport is paused
|
||
* @api private
|
||
*/
|
||
|
||
Polling.prototype.pause = function(onPause){
|
||
var pending = 0;
|
||
var self = this;
|
||
|
||
this.readyState = 'pausing';
|
||
|
||
function pause(){
|
||
debug('paused');
|
||
self.readyState = 'paused';
|
||
onPause();
|
||
}
|
||
|
||
if (this.polling || !this.writable) {
|
||
var total = 0;
|
||
|
||
if (this.polling) {
|
||
debug('we are currently polling - waiting to pause');
|
||
total++;
|
||
this.once('pollComplete', function(){
|
||
debug('pre-pause polling complete');
|
||
--total || pause();
|
||
});
|
||
}
|
||
|
||
if (!this.writable) {
|
||
debug('we are currently writing - waiting to pause');
|
||
total++;
|
||
this.once('drain', function(){
|
||
debug('pre-pause writing complete');
|
||
--total || pause();
|
||
});
|
||
}
|
||
} else {
|
||
pause();
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Starts polling cycle.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Polling.prototype.poll = function(){
|
||
debug('polling');
|
||
this.polling = true;
|
||
this.doPoll();
|
||
this.emit('poll');
|
||
};
|
||
|
||
/**
|
||
* Overloads onData to detect payloads.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Polling.prototype.onData = function(data){
|
||
var self = this;
|
||
debug('polling got data %s', data);
|
||
var callback = function(packet, index, total) {
|
||
// if its the first message we consider the transport open
|
||
if ('opening' == self.readyState) {
|
||
self.onOpen();
|
||
}
|
||
|
||
// if its a close packet, we close the ongoing requests
|
||
if ('close' == packet.type) {
|
||
self.onClose();
|
||
return false;
|
||
}
|
||
|
||
// otherwise bypass onData and handle the message
|
||
self.onPacket(packet);
|
||
};
|
||
|
||
// decode payload
|
||
parser.decodePayload(data, this.socket.binaryType, callback);
|
||
|
||
// if an event did not trigger closing
|
||
if ('closed' != this.readyState) {
|
||
// if we got data we're not polling
|
||
this.polling = false;
|
||
this.emit('pollComplete');
|
||
|
||
if ('open' == this.readyState) {
|
||
this.poll();
|
||
} else {
|
||
debug('ignoring poll - transport state "%s"', this.readyState);
|
||
}
|
||
}
|
||
};
|
||
|
||
/**
|
||
* For polling, send a close packet.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Polling.prototype.doClose = function(){
|
||
var self = this;
|
||
|
||
function close(){
|
||
debug('writing close packet');
|
||
self.write([{ type: 'close' }]);
|
||
}
|
||
|
||
if ('open' == this.readyState) {
|
||
debug('transport open - closing');
|
||
close();
|
||
} else {
|
||
// in case we're trying to close while
|
||
// handshaking is in progress (GH-164)
|
||
debug('transport not open - deferring close');
|
||
this.once('open', close);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Writes a packets payload.
|
||
*
|
||
* @param {Array} data packets
|
||
* @param {Function} drain callback
|
||
* @api private
|
||
*/
|
||
|
||
Polling.prototype.write = function(packets){
|
||
var self = this;
|
||
this.writable = false;
|
||
var callbackfn = function() {
|
||
self.writable = true;
|
||
self.emit('drain');
|
||
};
|
||
|
||
var self = this;
|
||
parser.encodePayload(packets, this.supportsBinary, function(data) {
|
||
self.doWrite(data, callbackfn);
|
||
});
|
||
};
|
||
|
||
/**
|
||
* Generates uri for connection.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Polling.prototype.uri = function(){
|
||
var query = this.query || {};
|
||
var schema = this.secure ? 'https' : 'http';
|
||
var port = '';
|
||
|
||
// cache busting is forced
|
||
if (false !== this.timestampRequests) {
|
||
query[this.timestampParam] = yeast();
|
||
}
|
||
|
||
if (!this.supportsBinary && !query.sid) {
|
||
query.b64 = 1;
|
||
}
|
||
|
||
query = parseqs.encode(query);
|
||
|
||
// avoid port if default for schema
|
||
if (this.port && (('https' == schema && this.port != 443) ||
|
||
('http' == schema && this.port != 80))) {
|
||
port = ':' + this.port;
|
||
}
|
||
|
||
// prepend ? to query
|
||
if (query.length) {
|
||
query = '?' + query;
|
||
}
|
||
|
||
var ipv6 = this.hostname.indexOf(':') !== -1;
|
||
return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
|
||
};
|
||
|
||
},{"../transport":59,"component-inherit":53,"debug":54,"engine.io-parser":66,"parseqs":75,"xmlhttprequest-ssl":65,"yeast":89}],64:[function(require,module,exports){
|
||
(function (global){
|
||
/**
|
||
* Module dependencies.
|
||
*/
|
||
|
||
var Transport = require('../transport');
|
||
var parser = require('engine.io-parser');
|
||
var parseqs = require('parseqs');
|
||
var inherit = require('component-inherit');
|
||
var yeast = require('yeast');
|
||
var debug = require('debug')('engine.io-client:websocket');
|
||
var BrowserWebSocket = global.WebSocket || global.MozWebSocket;
|
||
|
||
/**
|
||
* Get either the `WebSocket` or `MozWebSocket` globals
|
||
* in the browser or try to resolve WebSocket-compatible
|
||
* interface exposed by `ws` for Node-like environment.
|
||
*/
|
||
|
||
var WebSocket = BrowserWebSocket;
|
||
if (!WebSocket && typeof window === 'undefined') {
|
||
try {
|
||
WebSocket = require('ws');
|
||
} catch (e) { }
|
||
}
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = WS;
|
||
|
||
/**
|
||
* WebSocket transport constructor.
|
||
*
|
||
* @api {Object} connection options
|
||
* @api public
|
||
*/
|
||
|
||
function WS(opts){
|
||
var forceBase64 = (opts && opts.forceBase64);
|
||
if (forceBase64) {
|
||
this.supportsBinary = false;
|
||
}
|
||
this.perMessageDeflate = opts.perMessageDeflate;
|
||
Transport.call(this, opts);
|
||
}
|
||
|
||
/**
|
||
* Inherits from Transport.
|
||
*/
|
||
|
||
inherit(WS, Transport);
|
||
|
||
/**
|
||
* Transport name.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
WS.prototype.name = 'websocket';
|
||
|
||
/*
|
||
* WebSockets support binary
|
||
*/
|
||
|
||
WS.prototype.supportsBinary = true;
|
||
|
||
/**
|
||
* Opens socket.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
WS.prototype.doOpen = function(){
|
||
if (!this.check()) {
|
||
// let probe timeout
|
||
return;
|
||
}
|
||
|
||
var self = this;
|
||
var uri = this.uri();
|
||
var protocols = void(0);
|
||
var opts = {
|
||
agent: this.agent,
|
||
perMessageDeflate: this.perMessageDeflate
|
||
};
|
||
|
||
// SSL options for Node.js client
|
||
opts.pfx = this.pfx;
|
||
opts.key = this.key;
|
||
opts.passphrase = this.passphrase;
|
||
opts.cert = this.cert;
|
||
opts.ca = this.ca;
|
||
opts.ciphers = this.ciphers;
|
||
opts.rejectUnauthorized = this.rejectUnauthorized;
|
||
if (this.extraHeaders) {
|
||
opts.headers = this.extraHeaders;
|
||
}
|
||
|
||
this.ws = BrowserWebSocket ? new WebSocket(uri) : new WebSocket(uri, protocols, opts);
|
||
|
||
if (this.ws.binaryType === undefined) {
|
||
this.supportsBinary = false;
|
||
}
|
||
|
||
if (this.ws.supports && this.ws.supports.binary) {
|
||
this.supportsBinary = true;
|
||
this.ws.binaryType = 'buffer';
|
||
} else {
|
||
this.ws.binaryType = 'arraybuffer';
|
||
}
|
||
|
||
this.addEventListeners();
|
||
};
|
||
|
||
/**
|
||
* Adds event listeners to the socket
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
WS.prototype.addEventListeners = function(){
|
||
var self = this;
|
||
|
||
this.ws.onopen = function(){
|
||
self.onOpen();
|
||
};
|
||
this.ws.onclose = function(){
|
||
self.onClose();
|
||
};
|
||
this.ws.onmessage = function(ev){
|
||
self.onData(ev.data);
|
||
};
|
||
this.ws.onerror = function(e){
|
||
self.onError('websocket error', e);
|
||
};
|
||
};
|
||
|
||
/**
|
||
* Override `onData` to use a timer on iOS.
|
||
* See: https://gist.github.com/mloughran/2052006
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
if ('undefined' != typeof navigator
|
||
&& /iPad|iPhone|iPod/i.test(navigator.userAgent)) {
|
||
WS.prototype.onData = function(data){
|
||
var self = this;
|
||
setTimeout(function(){
|
||
Transport.prototype.onData.call(self, data);
|
||
}, 0);
|
||
};
|
||
}
|
||
|
||
/**
|
||
* Writes data to socket.
|
||
*
|
||
* @param {Array} array of packets.
|
||
* @api private
|
||
*/
|
||
|
||
WS.prototype.write = function(packets){
|
||
var self = this;
|
||
this.writable = false;
|
||
|
||
// encodePacket efficient as it uses WS framing
|
||
// no need for encodePayload
|
||
var total = packets.length;
|
||
for (var i = 0, l = total; i < l; i++) {
|
||
(function(packet) {
|
||
parser.encodePacket(packet, self.supportsBinary, function(data) {
|
||
if (!BrowserWebSocket) {
|
||
// always create a new object (GH-437)
|
||
var opts = {};
|
||
if (packet.options) {
|
||
opts.compress = packet.options.compress;
|
||
}
|
||
|
||
if (self.perMessageDeflate) {
|
||
var len = 'string' == typeof data ? global.Buffer.byteLength(data) : data.length;
|
||
if (len < self.perMessageDeflate.threshold) {
|
||
opts.compress = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
//Sometimes the websocket has already been closed but the browser didn't
|
||
//have a chance of informing us about it yet, in that case send will
|
||
//throw an error
|
||
try {
|
||
if (BrowserWebSocket) {
|
||
// TypeError is thrown when passing the second argument on Safari
|
||
self.ws.send(data);
|
||
} else {
|
||
self.ws.send(data, opts);
|
||
}
|
||
} catch (e){
|
||
debug('websocket closed before onclose event');
|
||
}
|
||
|
||
--total || done();
|
||
});
|
||
})(packets[i]);
|
||
}
|
||
|
||
function done(){
|
||
self.emit('flush');
|
||
|
||
// fake drain
|
||
// defer to next tick to allow Socket to clear writeBuffer
|
||
setTimeout(function(){
|
||
self.writable = true;
|
||
self.emit('drain');
|
||
}, 0);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Called upon close
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
WS.prototype.onClose = function(){
|
||
Transport.prototype.onClose.call(this);
|
||
};
|
||
|
||
/**
|
||
* Closes socket.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
WS.prototype.doClose = function(){
|
||
if (typeof this.ws !== 'undefined') {
|
||
this.ws.close();
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Generates uri for connection.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
WS.prototype.uri = function(){
|
||
var query = this.query || {};
|
||
var schema = this.secure ? 'wss' : 'ws';
|
||
var port = '';
|
||
|
||
// avoid port if default for schema
|
||
if (this.port && (('wss' == schema && this.port != 443)
|
||
|| ('ws' == schema && this.port != 80))) {
|
||
port = ':' + this.port;
|
||
}
|
||
|
||
// append timestamp to URI
|
||
if (this.timestampRequests) {
|
||
query[this.timestampParam] = yeast();
|
||
}
|
||
|
||
// communicate binary support capabilities
|
||
if (!this.supportsBinary) {
|
||
query.b64 = 1;
|
||
}
|
||
|
||
query = parseqs.encode(query);
|
||
|
||
// prepend ? to query
|
||
if (query.length) {
|
||
query = '?' + query;
|
||
}
|
||
|
||
var ipv6 = this.hostname.indexOf(':') !== -1;
|
||
return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
|
||
};
|
||
|
||
/**
|
||
* Feature detection for WebSocket.
|
||
*
|
||
* @return {Boolean} whether this transport is available.
|
||
* @api public
|
||
*/
|
||
|
||
WS.prototype.check = function(){
|
||
return !!WebSocket && !('__initialize' in WebSocket && this.name === WS.prototype.name);
|
||
};
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{"../transport":59,"component-inherit":53,"debug":54,"engine.io-parser":66,"parseqs":75,"ws":50,"yeast":89}],65:[function(require,module,exports){
|
||
// browser shim for xmlhttprequest module
|
||
var hasCORS = require('has-cors');
|
||
|
||
module.exports = function(opts) {
|
||
var xdomain = opts.xdomain;
|
||
|
||
// scheme must be same when usign XDomainRequest
|
||
// http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
|
||
var xscheme = opts.xscheme;
|
||
|
||
// XDomainRequest has a flow of not sending cookie, therefore it should be disabled as a default.
|
||
// https://github.com/Automattic/engine.io-client/pull/217
|
||
var enablesXDR = opts.enablesXDR;
|
||
|
||
// XMLHttpRequest can be disabled on IE
|
||
try {
|
||
if ('undefined' != typeof XMLHttpRequest && (!xdomain || hasCORS)) {
|
||
return new XMLHttpRequest();
|
||
}
|
||
} catch (e) { }
|
||
|
||
// Use XDomainRequest for IE8 if enablesXDR is true
|
||
// because loading bar keeps flashing when using jsonp-polling
|
||
// https://github.com/yujiosaka/socke.io-ie8-loading-example
|
||
try {
|
||
if ('undefined' != typeof XDomainRequest && !xscheme && enablesXDR) {
|
||
return new XDomainRequest();
|
||
}
|
||
} catch (e) { }
|
||
|
||
if (!xdomain) {
|
||
try {
|
||
return new ActiveXObject('Microsoft.XMLHTTP');
|
||
} catch(e) { }
|
||
}
|
||
}
|
||
|
||
},{"has-cors":70}],66:[function(require,module,exports){
|
||
(function (global){
|
||
/**
|
||
* Module dependencies.
|
||
*/
|
||
|
||
var keys = require('./keys');
|
||
var hasBinary = require('has-binary');
|
||
var sliceBuffer = require('arraybuffer.slice');
|
||
var base64encoder = require('base64-arraybuffer');
|
||
var after = require('after');
|
||
var utf8 = require('utf8');
|
||
|
||
/**
|
||
* Check if we are running an android browser. That requires us to use
|
||
* ArrayBuffer with polling transports...
|
||
*
|
||
* http://ghinda.net/jpeg-blob-ajax-android/
|
||
*/
|
||
|
||
var isAndroid = navigator.userAgent.match(/Android/i);
|
||
|
||
/**
|
||
* Check if we are running in PhantomJS.
|
||
* Uploading a Blob with PhantomJS does not work correctly, as reported here:
|
||
* https://github.com/ariya/phantomjs/issues/11395
|
||
* @type boolean
|
||
*/
|
||
var isPhantomJS = /PhantomJS/i.test(navigator.userAgent);
|
||
|
||
/**
|
||
* When true, avoids using Blobs to encode payloads.
|
||
* @type boolean
|
||
*/
|
||
var dontSendBlobs = isAndroid || isPhantomJS;
|
||
|
||
/**
|
||
* Current protocol version.
|
||
*/
|
||
|
||
exports.protocol = 3;
|
||
|
||
/**
|
||
* Packet types.
|
||
*/
|
||
|
||
var packets = exports.packets = {
|
||
open: 0 // non-ws
|
||
, close: 1 // non-ws
|
||
, ping: 2
|
||
, pong: 3
|
||
, message: 4
|
||
, upgrade: 5
|
||
, noop: 6
|
||
};
|
||
|
||
var packetslist = keys(packets);
|
||
|
||
/**
|
||
* Premade error packet.
|
||
*/
|
||
|
||
var err = { type: 'error', data: 'parser error' };
|
||
|
||
/**
|
||
* Create a blob api even for blob builder when vendor prefixes exist
|
||
*/
|
||
|
||
var Blob = require('blob');
|
||
|
||
/**
|
||
* Encodes a packet.
|
||
*
|
||
* <packet type id> [ <data> ]
|
||
*
|
||
* Example:
|
||
*
|
||
* 5hello world
|
||
* 3
|
||
* 4
|
||
*
|
||
* Binary is encoded in an identical principle
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
exports.encodePacket = function (packet, supportsBinary, utf8encode, callback) {
|
||
if ('function' == typeof supportsBinary) {
|
||
callback = supportsBinary;
|
||
supportsBinary = false;
|
||
}
|
||
|
||
if ('function' == typeof utf8encode) {
|
||
callback = utf8encode;
|
||
utf8encode = null;
|
||
}
|
||
|
||
var data = (packet.data === undefined)
|
||
? undefined
|
||
: packet.data.buffer || packet.data;
|
||
|
||
if (global.ArrayBuffer && data instanceof ArrayBuffer) {
|
||
return encodeArrayBuffer(packet, supportsBinary, callback);
|
||
} else if (Blob && data instanceof global.Blob) {
|
||
return encodeBlob(packet, supportsBinary, callback);
|
||
}
|
||
|
||
// might be an object with { base64: true, data: dataAsBase64String }
|
||
if (data && data.base64) {
|
||
return encodeBase64Object(packet, callback);
|
||
}
|
||
|
||
// Sending data as a utf-8 string
|
||
var encoded = packets[packet.type];
|
||
|
||
// data fragment is optional
|
||
if (undefined !== packet.data) {
|
||
encoded += utf8encode ? utf8.encode(String(packet.data)) : String(packet.data);
|
||
}
|
||
|
||
return callback('' + encoded);
|
||
|
||
};
|
||
|
||
function encodeBase64Object(packet, callback) {
|
||
// packet data is an object { base64: true, data: dataAsBase64String }
|
||
var message = 'b' + exports.packets[packet.type] + packet.data.data;
|
||
return callback(message);
|
||
}
|
||
|
||
/**
|
||
* Encode packet helpers for binary types
|
||
*/
|
||
|
||
function encodeArrayBuffer(packet, supportsBinary, callback) {
|
||
if (!supportsBinary) {
|
||
return exports.encodeBase64Packet(packet, callback);
|
||
}
|
||
|
||
var data = packet.data;
|
||
var contentArray = new Uint8Array(data);
|
||
var resultBuffer = new Uint8Array(1 + data.byteLength);
|
||
|
||
resultBuffer[0] = packets[packet.type];
|
||
for (var i = 0; i < contentArray.length; i++) {
|
||
resultBuffer[i+1] = contentArray[i];
|
||
}
|
||
|
||
return callback(resultBuffer.buffer);
|
||
}
|
||
|
||
function encodeBlobAsArrayBuffer(packet, supportsBinary, callback) {
|
||
if (!supportsBinary) {
|
||
return exports.encodeBase64Packet(packet, callback);
|
||
}
|
||
|
||
var fr = new FileReader();
|
||
fr.onload = function() {
|
||
packet.data = fr.result;
|
||
exports.encodePacket(packet, supportsBinary, true, callback);
|
||
};
|
||
return fr.readAsArrayBuffer(packet.data);
|
||
}
|
||
|
||
function encodeBlob(packet, supportsBinary, callback) {
|
||
if (!supportsBinary) {
|
||
return exports.encodeBase64Packet(packet, callback);
|
||
}
|
||
|
||
if (dontSendBlobs) {
|
||
return encodeBlobAsArrayBuffer(packet, supportsBinary, callback);
|
||
}
|
||
|
||
var length = new Uint8Array(1);
|
||
length[0] = packets[packet.type];
|
||
var blob = new Blob([length.buffer, packet.data]);
|
||
|
||
return callback(blob);
|
||
}
|
||
|
||
/**
|
||
* Encodes a packet with binary data in a base64 string
|
||
*
|
||
* @param {Object} packet, has `type` and `data`
|
||
* @return {String} base64 encoded message
|
||
*/
|
||
|
||
exports.encodeBase64Packet = function(packet, callback) {
|
||
var message = 'b' + exports.packets[packet.type];
|
||
if (Blob && packet.data instanceof global.Blob) {
|
||
var fr = new FileReader();
|
||
fr.onload = function() {
|
||
var b64 = fr.result.split(',')[1];
|
||
callback(message + b64);
|
||
};
|
||
return fr.readAsDataURL(packet.data);
|
||
}
|
||
|
||
var b64data;
|
||
try {
|
||
b64data = String.fromCharCode.apply(null, new Uint8Array(packet.data));
|
||
} catch (e) {
|
||
// iPhone Safari doesn't let you apply with typed arrays
|
||
var typed = new Uint8Array(packet.data);
|
||
var basic = new Array(typed.length);
|
||
for (var i = 0; i < typed.length; i++) {
|
||
basic[i] = typed[i];
|
||
}
|
||
b64data = String.fromCharCode.apply(null, basic);
|
||
}
|
||
message += global.btoa(b64data);
|
||
return callback(message);
|
||
};
|
||
|
||
/**
|
||
* Decodes a packet. Changes format to Blob if requested.
|
||
*
|
||
* @return {Object} with `type` and `data` (if any)
|
||
* @api private
|
||
*/
|
||
|
||
exports.decodePacket = function (data, binaryType, utf8decode) {
|
||
// String data
|
||
if (typeof data == 'string' || data === undefined) {
|
||
if (data.charAt(0) == 'b') {
|
||
return exports.decodeBase64Packet(data.substr(1), binaryType);
|
||
}
|
||
|
||
if (utf8decode) {
|
||
try {
|
||
data = utf8.decode(data);
|
||
} catch (e) {
|
||
return err;
|
||
}
|
||
}
|
||
var type = data.charAt(0);
|
||
|
||
if (Number(type) != type || !packetslist[type]) {
|
||
return err;
|
||
}
|
||
|
||
if (data.length > 1) {
|
||
return { type: packetslist[type], data: data.substring(1) };
|
||
} else {
|
||
return { type: packetslist[type] };
|
||
}
|
||
}
|
||
|
||
var asArray = new Uint8Array(data);
|
||
var type = asArray[0];
|
||
var rest = sliceBuffer(data, 1);
|
||
if (Blob && binaryType === 'blob') {
|
||
rest = new Blob([rest]);
|
||
}
|
||
return { type: packetslist[type], data: rest };
|
||
};
|
||
|
||
/**
|
||
* Decodes a packet encoded in a base64 string
|
||
*
|
||
* @param {String} base64 encoded message
|
||
* @return {Object} with `type` and `data` (if any)
|
||
*/
|
||
|
||
exports.decodeBase64Packet = function(msg, binaryType) {
|
||
var type = packetslist[msg.charAt(0)];
|
||
if (!global.ArrayBuffer) {
|
||
return { type: type, data: { base64: true, data: msg.substr(1) } };
|
||
}
|
||
|
||
var data = base64encoder.decode(msg.substr(1));
|
||
|
||
if (binaryType === 'blob' && Blob) {
|
||
data = new Blob([data]);
|
||
}
|
||
|
||
return { type: type, data: data };
|
||
};
|
||
|
||
/**
|
||
* Encodes multiple messages (payload).
|
||
*
|
||
* <length>:data
|
||
*
|
||
* Example:
|
||
*
|
||
* 11:hello world2:hi
|
||
*
|
||
* If any contents are binary, they will be encoded as base64 strings. Base64
|
||
* encoded strings are marked with a b before the length specifier
|
||
*
|
||
* @param {Array} packets
|
||
* @api private
|
||
*/
|
||
|
||
exports.encodePayload = function (packets, supportsBinary, callback) {
|
||
if (typeof supportsBinary == 'function') {
|
||
callback = supportsBinary;
|
||
supportsBinary = null;
|
||
}
|
||
|
||
var isBinary = hasBinary(packets);
|
||
|
||
if (supportsBinary && isBinary) {
|
||
if (Blob && !dontSendBlobs) {
|
||
return exports.encodePayloadAsBlob(packets, callback);
|
||
}
|
||
|
||
return exports.encodePayloadAsArrayBuffer(packets, callback);
|
||
}
|
||
|
||
if (!packets.length) {
|
||
return callback('0:');
|
||
}
|
||
|
||
function setLengthHeader(message) {
|
||
return message.length + ':' + message;
|
||
}
|
||
|
||
function encodeOne(packet, doneCallback) {
|
||
exports.encodePacket(packet, !isBinary ? false : supportsBinary, true, function(message) {
|
||
doneCallback(null, setLengthHeader(message));
|
||
});
|
||
}
|
||
|
||
map(packets, encodeOne, function(err, results) {
|
||
return callback(results.join(''));
|
||
});
|
||
};
|
||
|
||
/**
|
||
* Async array map using after
|
||
*/
|
||
|
||
function map(ary, each, done) {
|
||
var result = new Array(ary.length);
|
||
var next = after(ary.length, done);
|
||
|
||
var eachWithIndex = function(i, el, cb) {
|
||
each(el, function(error, msg) {
|
||
result[i] = msg;
|
||
cb(error, result);
|
||
});
|
||
};
|
||
|
||
for (var i = 0; i < ary.length; i++) {
|
||
eachWithIndex(i, ary[i], next);
|
||
}
|
||
}
|
||
|
||
/*
|
||
* Decodes data when a payload is maybe expected. Possible binary contents are
|
||
* decoded from their base64 representation
|
||
*
|
||
* @param {String} data, callback method
|
||
* @api public
|
||
*/
|
||
|
||
exports.decodePayload = function (data, binaryType, callback) {
|
||
if (typeof data != 'string') {
|
||
return exports.decodePayloadAsBinary(data, binaryType, callback);
|
||
}
|
||
|
||
if (typeof binaryType === 'function') {
|
||
callback = binaryType;
|
||
binaryType = null;
|
||
}
|
||
|
||
var packet;
|
||
if (data == '') {
|
||
// parser error - ignoring payload
|
||
return callback(err, 0, 1);
|
||
}
|
||
|
||
var length = ''
|
||
, n, msg;
|
||
|
||
for (var i = 0, l = data.length; i < l; i++) {
|
||
var chr = data.charAt(i);
|
||
|
||
if (':' != chr) {
|
||
length += chr;
|
||
} else {
|
||
if ('' == length || (length != (n = Number(length)))) {
|
||
// parser error - ignoring payload
|
||
return callback(err, 0, 1);
|
||
}
|
||
|
||
msg = data.substr(i + 1, n);
|
||
|
||
if (length != msg.length) {
|
||
// parser error - ignoring payload
|
||
return callback(err, 0, 1);
|
||
}
|
||
|
||
if (msg.length) {
|
||
packet = exports.decodePacket(msg, binaryType, true);
|
||
|
||
if (err.type == packet.type && err.data == packet.data) {
|
||
// parser error in individual packet - ignoring payload
|
||
return callback(err, 0, 1);
|
||
}
|
||
|
||
var ret = callback(packet, i + n, l);
|
||
if (false === ret) return;
|
||
}
|
||
|
||
// advance cursor
|
||
i += n;
|
||
length = '';
|
||
}
|
||
}
|
||
|
||
if (length != '') {
|
||
// parser error - ignoring payload
|
||
return callback(err, 0, 1);
|
||
}
|
||
|
||
};
|
||
|
||
/**
|
||
* Encodes multiple messages (payload) as binary.
|
||
*
|
||
* <1 = binary, 0 = string><number from 0-9><number from 0-9>[...]<number
|
||
* 255><data>
|
||
*
|
||
* Example:
|
||
* 1 3 255 1 2 3, if the binary contents are interpreted as 8 bit integers
|
||
*
|
||
* @param {Array} packets
|
||
* @return {ArrayBuffer} encoded payload
|
||
* @api private
|
||
*/
|
||
|
||
exports.encodePayloadAsArrayBuffer = function(packets, callback) {
|
||
if (!packets.length) {
|
||
return callback(new ArrayBuffer(0));
|
||
}
|
||
|
||
function encodeOne(packet, doneCallback) {
|
||
exports.encodePacket(packet, true, true, function(data) {
|
||
return doneCallback(null, data);
|
||
});
|
||
}
|
||
|
||
map(packets, encodeOne, function(err, encodedPackets) {
|
||
var totalLength = encodedPackets.reduce(function(acc, p) {
|
||
var len;
|
||
if (typeof p === 'string'){
|
||
len = p.length;
|
||
} else {
|
||
len = p.byteLength;
|
||
}
|
||
return acc + len.toString().length + len + 2; // string/binary identifier + separator = 2
|
||
}, 0);
|
||
|
||
var resultArray = new Uint8Array(totalLength);
|
||
|
||
var bufferIndex = 0;
|
||
encodedPackets.forEach(function(p) {
|
||
var isString = typeof p === 'string';
|
||
var ab = p;
|
||
if (isString) {
|
||
var view = new Uint8Array(p.length);
|
||
for (var i = 0; i < p.length; i++) {
|
||
view[i] = p.charCodeAt(i);
|
||
}
|
||
ab = view.buffer;
|
||
}
|
||
|
||
if (isString) { // not true binary
|
||
resultArray[bufferIndex++] = 0;
|
||
} else { // true binary
|
||
resultArray[bufferIndex++] = 1;
|
||
}
|
||
|
||
var lenStr = ab.byteLength.toString();
|
||
for (var i = 0; i < lenStr.length; i++) {
|
||
resultArray[bufferIndex++] = parseInt(lenStr[i]);
|
||
}
|
||
resultArray[bufferIndex++] = 255;
|
||
|
||
var view = new Uint8Array(ab);
|
||
for (var i = 0; i < view.length; i++) {
|
||
resultArray[bufferIndex++] = view[i];
|
||
}
|
||
});
|
||
|
||
return callback(resultArray.buffer);
|
||
});
|
||
};
|
||
|
||
/**
|
||
* Encode as Blob
|
||
*/
|
||
|
||
exports.encodePayloadAsBlob = function(packets, callback) {
|
||
function encodeOne(packet, doneCallback) {
|
||
exports.encodePacket(packet, true, true, function(encoded) {
|
||
var binaryIdentifier = new Uint8Array(1);
|
||
binaryIdentifier[0] = 1;
|
||
if (typeof encoded === 'string') {
|
||
var view = new Uint8Array(encoded.length);
|
||
for (var i = 0; i < encoded.length; i++) {
|
||
view[i] = encoded.charCodeAt(i);
|
||
}
|
||
encoded = view.buffer;
|
||
binaryIdentifier[0] = 0;
|
||
}
|
||
|
||
var len = (encoded instanceof ArrayBuffer)
|
||
? encoded.byteLength
|
||
: encoded.size;
|
||
|
||
var lenStr = len.toString();
|
||
var lengthAry = new Uint8Array(lenStr.length + 1);
|
||
for (var i = 0; i < lenStr.length; i++) {
|
||
lengthAry[i] = parseInt(lenStr[i]);
|
||
}
|
||
lengthAry[lenStr.length] = 255;
|
||
|
||
if (Blob) {
|
||
var blob = new Blob([binaryIdentifier.buffer, lengthAry.buffer, encoded]);
|
||
doneCallback(null, blob);
|
||
}
|
||
});
|
||
}
|
||
|
||
map(packets, encodeOne, function(err, results) {
|
||
return callback(new Blob(results));
|
||
});
|
||
};
|
||
|
||
/*
|
||
* Decodes data when a payload is maybe expected. Strings are decoded by
|
||
* interpreting each byte as a key code for entries marked to start with 0. See
|
||
* description of encodePayloadAsBinary
|
||
*
|
||
* @param {ArrayBuffer} data, callback method
|
||
* @api public
|
||
*/
|
||
|
||
exports.decodePayloadAsBinary = function (data, binaryType, callback) {
|
||
if (typeof binaryType === 'function') {
|
||
callback = binaryType;
|
||
binaryType = null;
|
||
}
|
||
|
||
var bufferTail = data;
|
||
var buffers = [];
|
||
|
||
var numberTooLong = false;
|
||
while (bufferTail.byteLength > 0) {
|
||
var tailArray = new Uint8Array(bufferTail);
|
||
var isString = tailArray[0] === 0;
|
||
var msgLength = '';
|
||
|
||
for (var i = 1; ; i++) {
|
||
if (tailArray[i] == 255) break;
|
||
|
||
if (msgLength.length > 310) {
|
||
numberTooLong = true;
|
||
break;
|
||
}
|
||
|
||
msgLength += tailArray[i];
|
||
}
|
||
|
||
if(numberTooLong) return callback(err, 0, 1);
|
||
|
||
bufferTail = sliceBuffer(bufferTail, 2 + msgLength.length);
|
||
msgLength = parseInt(msgLength);
|
||
|
||
var msg = sliceBuffer(bufferTail, 0, msgLength);
|
||
if (isString) {
|
||
try {
|
||
msg = String.fromCharCode.apply(null, new Uint8Array(msg));
|
||
} catch (e) {
|
||
// iPhone Safari doesn't let you apply to typed arrays
|
||
var typed = new Uint8Array(msg);
|
||
msg = '';
|
||
for (var i = 0; i < typed.length; i++) {
|
||
msg += String.fromCharCode(typed[i]);
|
||
}
|
||
}
|
||
}
|
||
|
||
buffers.push(msg);
|
||
bufferTail = sliceBuffer(bufferTail, msgLength);
|
||
}
|
||
|
||
var total = buffers.length;
|
||
buffers.forEach(function(buffer, i) {
|
||
callback(exports.decodePacket(buffer, binaryType, true), i, total);
|
||
});
|
||
};
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{"./keys":67,"after":45,"arraybuffer.slice":46,"base64-arraybuffer":48,"blob":49,"has-binary":68,"utf8":88}],67:[function(require,module,exports){
|
||
|
||
/**
|
||
* Gets the keys for an object.
|
||
*
|
||
* @return {Array} keys
|
||
* @api private
|
||
*/
|
||
|
||
module.exports = Object.keys || function keys (obj){
|
||
var arr = [];
|
||
var has = Object.prototype.hasOwnProperty;
|
||
|
||
for (var i in obj) {
|
||
if (has.call(obj, i)) {
|
||
arr.push(i);
|
||
}
|
||
}
|
||
return arr;
|
||
};
|
||
|
||
},{}],68:[function(require,module,exports){
|
||
(function (global){
|
||
|
||
/*
|
||
* Module requirements.
|
||
*/
|
||
|
||
var isArray = require('isarray');
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = hasBinary;
|
||
|
||
/**
|
||
* Checks for binary data.
|
||
*
|
||
* Right now only Buffer and ArrayBuffer are supported..
|
||
*
|
||
* @param {Object} anything
|
||
* @api public
|
||
*/
|
||
|
||
function hasBinary(data) {
|
||
|
||
function _hasBinary(obj) {
|
||
if (!obj) return false;
|
||
|
||
if ( (global.Buffer && global.Buffer.isBuffer(obj)) ||
|
||
(global.ArrayBuffer && obj instanceof ArrayBuffer) ||
|
||
(global.Blob && obj instanceof Blob) ||
|
||
(global.File && obj instanceof File)
|
||
) {
|
||
return true;
|
||
}
|
||
|
||
if (isArray(obj)) {
|
||
for (var i = 0; i < obj.length; i++) {
|
||
if (_hasBinary(obj[i])) {
|
||
return true;
|
||
}
|
||
}
|
||
} else if (obj && 'object' == typeof obj) {
|
||
if (obj.toJSON) {
|
||
obj = obj.toJSON();
|
||
}
|
||
|
||
for (var key in obj) {
|
||
if (Object.prototype.hasOwnProperty.call(obj, key) && _hasBinary(obj[key])) {
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
return _hasBinary(data);
|
||
}
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{"isarray":72}],69:[function(require,module,exports){
|
||
(function (global){
|
||
|
||
/*
|
||
* Module requirements.
|
||
*/
|
||
|
||
var isArray = require('isarray');
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = hasBinary;
|
||
|
||
/**
|
||
* Checks for binary data.
|
||
*
|
||
* Right now only Buffer and ArrayBuffer are supported..
|
||
*
|
||
* @param {Object} anything
|
||
* @api public
|
||
*/
|
||
|
||
function hasBinary(data) {
|
||
|
||
function _hasBinary(obj) {
|
||
if (!obj) return false;
|
||
|
||
if ( (global.Buffer && global.Buffer.isBuffer && global.Buffer.isBuffer(obj)) ||
|
||
(global.ArrayBuffer && obj instanceof ArrayBuffer) ||
|
||
(global.Blob && obj instanceof Blob) ||
|
||
(global.File && obj instanceof File)
|
||
) {
|
||
return true;
|
||
}
|
||
|
||
if (isArray(obj)) {
|
||
for (var i = 0; i < obj.length; i++) {
|
||
if (_hasBinary(obj[i])) {
|
||
return true;
|
||
}
|
||
}
|
||
} else if (obj && 'object' == typeof obj) {
|
||
// see: https://github.com/Automattic/has-binary/pull/4
|
||
if (obj.toJSON && 'function' == typeof obj.toJSON) {
|
||
obj = obj.toJSON();
|
||
}
|
||
|
||
for (var key in obj) {
|
||
if (Object.prototype.hasOwnProperty.call(obj, key) && _hasBinary(obj[key])) {
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
return _hasBinary(data);
|
||
}
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{"isarray":72}],70:[function(require,module,exports){
|
||
|
||
/**
|
||
* Module exports.
|
||
*
|
||
* Logic borrowed from Modernizr:
|
||
*
|
||
* - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cors.js
|
||
*/
|
||
|
||
try {
|
||
module.exports = typeof XMLHttpRequest !== 'undefined' &&
|
||
'withCredentials' in new XMLHttpRequest();
|
||
} catch (err) {
|
||
// if XMLHttp support is disabled in IE then it will throw
|
||
// when trying to create
|
||
module.exports = false;
|
||
}
|
||
|
||
},{}],71:[function(require,module,exports){
|
||
|
||
var indexOf = [].indexOf;
|
||
|
||
module.exports = function(arr, obj){
|
||
if (indexOf) return arr.indexOf(obj);
|
||
for (var i = 0; i < arr.length; ++i) {
|
||
if (arr[i] === obj) return i;
|
||
}
|
||
return -1;
|
||
};
|
||
},{}],72:[function(require,module,exports){
|
||
module.exports = Array.isArray || function (arr) {
|
||
return Object.prototype.toString.call(arr) == '[object Array]';
|
||
};
|
||
|
||
},{}],73:[function(require,module,exports){
|
||
/**
|
||
* Helpers.
|
||
*/
|
||
|
||
var s = 1000;
|
||
var m = s * 60;
|
||
var h = m * 60;
|
||
var d = h * 24;
|
||
var y = d * 365.25;
|
||
|
||
/**
|
||
* Parse or format the given `val`.
|
||
*
|
||
* Options:
|
||
*
|
||
* - `long` verbose formatting [false]
|
||
*
|
||
* @param {String|Number} val
|
||
* @param {Object} options
|
||
* @return {String|Number}
|
||
* @api public
|
||
*/
|
||
|
||
module.exports = function(val, options){
|
||
options = options || {};
|
||
if ('string' == typeof val) return parse(val);
|
||
return options.long
|
||
? long(val)
|
||
: short(val);
|
||
};
|
||
|
||
/**
|
||
* Parse the given `str` and return milliseconds.
|
||
*
|
||
* @param {String} str
|
||
* @return {Number}
|
||
* @api private
|
||
*/
|
||
|
||
function parse(str) {
|
||
str = '' + str;
|
||
if (str.length > 10000) return;
|
||
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
|
||
if (!match) return;
|
||
var n = parseFloat(match[1]);
|
||
var type = (match[2] || 'ms').toLowerCase();
|
||
switch (type) {
|
||
case 'years':
|
||
case 'year':
|
||
case 'yrs':
|
||
case 'yr':
|
||
case 'y':
|
||
return n * y;
|
||
case 'days':
|
||
case 'day':
|
||
case 'd':
|
||
return n * d;
|
||
case 'hours':
|
||
case 'hour':
|
||
case 'hrs':
|
||
case 'hr':
|
||
case 'h':
|
||
return n * h;
|
||
case 'minutes':
|
||
case 'minute':
|
||
case 'mins':
|
||
case 'min':
|
||
case 'm':
|
||
return n * m;
|
||
case 'seconds':
|
||
case 'second':
|
||
case 'secs':
|
||
case 'sec':
|
||
case 's':
|
||
return n * s;
|
||
case 'milliseconds':
|
||
case 'millisecond':
|
||
case 'msecs':
|
||
case 'msec':
|
||
case 'ms':
|
||
return n;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Short format for `ms`.
|
||
*
|
||
* @param {Number} ms
|
||
* @return {String}
|
||
* @api private
|
||
*/
|
||
|
||
function short(ms) {
|
||
if (ms >= d) return Math.round(ms / d) + 'd';
|
||
if (ms >= h) return Math.round(ms / h) + 'h';
|
||
if (ms >= m) return Math.round(ms / m) + 'm';
|
||
if (ms >= s) return Math.round(ms / s) + 's';
|
||
return ms + 'ms';
|
||
}
|
||
|
||
/**
|
||
* Long format for `ms`.
|
||
*
|
||
* @param {Number} ms
|
||
* @return {String}
|
||
* @api private
|
||
*/
|
||
|
||
function long(ms) {
|
||
return plural(ms, d, 'day')
|
||
|| plural(ms, h, 'hour')
|
||
|| plural(ms, m, 'minute')
|
||
|| plural(ms, s, 'second')
|
||
|| ms + ' ms';
|
||
}
|
||
|
||
/**
|
||
* Pluralization helper.
|
||
*/
|
||
|
||
function plural(ms, n, name) {
|
||
if (ms < n) return;
|
||
if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
|
||
return Math.ceil(ms / n) + ' ' + name + 's';
|
||
}
|
||
|
||
},{}],74:[function(require,module,exports){
|
||
(function (global){
|
||
/**
|
||
* JSON parse.
|
||
*
|
||
* @see Based on jQuery#parseJSON (MIT) and JSON2
|
||
* @api private
|
||
*/
|
||
|
||
var rvalidchars = /^[\],:{}\s]*$/;
|
||
var rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
|
||
var rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
|
||
var rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g;
|
||
var rtrimLeft = /^\s+/;
|
||
var rtrimRight = /\s+$/;
|
||
|
||
module.exports = function parsejson(data) {
|
||
if ('string' != typeof data || !data) {
|
||
return null;
|
||
}
|
||
|
||
data = data.replace(rtrimLeft, '').replace(rtrimRight, '');
|
||
|
||
// Attempt to parse using the native JSON parser first
|
||
if (global.JSON && JSON.parse) {
|
||
return JSON.parse(data);
|
||
}
|
||
|
||
if (rvalidchars.test(data.replace(rvalidescape, '@')
|
||
.replace(rvalidtokens, ']')
|
||
.replace(rvalidbraces, ''))) {
|
||
return (new Function('return ' + data))();
|
||
}
|
||
};
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{}],75:[function(require,module,exports){
|
||
/**
|
||
* Compiles a querystring
|
||
* Returns string representation of the object
|
||
*
|
||
* @param {Object}
|
||
* @api private
|
||
*/
|
||
|
||
exports.encode = function (obj) {
|
||
var str = '';
|
||
|
||
for (var i in obj) {
|
||
if (obj.hasOwnProperty(i)) {
|
||
if (str.length) str += '&';
|
||
str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
|
||
}
|
||
}
|
||
|
||
return str;
|
||
};
|
||
|
||
/**
|
||
* Parses a simple querystring into an object
|
||
*
|
||
* @param {String} qs
|
||
* @api private
|
||
*/
|
||
|
||
exports.decode = function(qs){
|
||
var qry = {};
|
||
var pairs = qs.split('&');
|
||
for (var i = 0, l = pairs.length; i < l; i++) {
|
||
var pair = pairs[i].split('=');
|
||
qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
|
||
}
|
||
return qry;
|
||
};
|
||
|
||
},{}],76:[function(require,module,exports){
|
||
/**
|
||
* Parses an URI
|
||
*
|
||
* @author Steven Levithan <stevenlevithan.com> (MIT license)
|
||
* @api private
|
||
*/
|
||
|
||
var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
||
|
||
var parts = [
|
||
'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
|
||
];
|
||
|
||
module.exports = function parseuri(str) {
|
||
var src = str,
|
||
b = str.indexOf('['),
|
||
e = str.indexOf(']');
|
||
|
||
if (b != -1 && e != -1) {
|
||
str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
|
||
}
|
||
|
||
var m = re.exec(str || ''),
|
||
uri = {},
|
||
i = 14;
|
||
|
||
while (i--) {
|
||
uri[parts[i]] = m[i] || '';
|
||
}
|
||
|
||
if (b != -1 && e != -1) {
|
||
uri.source = src;
|
||
uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
|
||
uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
|
||
uri.ipv6uri = true;
|
||
}
|
||
|
||
return uri;
|
||
};
|
||
|
||
},{}],77:[function(require,module,exports){
|
||
|
||
/**
|
||
* Module dependencies.
|
||
*/
|
||
|
||
var url = require('./url');
|
||
var parser = require('socket.io-parser');
|
||
var Manager = require('./manager');
|
||
var debug = require('debug')('socket.io-client');
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = exports = lookup;
|
||
|
||
/**
|
||
* Managers cache.
|
||
*/
|
||
|
||
var cache = exports.managers = {};
|
||
|
||
/**
|
||
* Looks up an existing `Manager` for multiplexing.
|
||
* If the user summons:
|
||
*
|
||
* `io('http://localhost/a');`
|
||
* `io('http://localhost/b');`
|
||
*
|
||
* We reuse the existing instance based on same scheme/port/host,
|
||
* and we initialize sockets for each namespace.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
function lookup(uri, opts) {
|
||
if (typeof uri == 'object') {
|
||
opts = uri;
|
||
uri = undefined;
|
||
}
|
||
|
||
opts = opts || {};
|
||
|
||
var parsed = url(uri);
|
||
var source = parsed.source;
|
||
var id = parsed.id;
|
||
var path = parsed.path;
|
||
var sameNamespace = cache[id] && path in cache[id].nsps;
|
||
var newConnection = opts.forceNew || opts['force new connection'] ||
|
||
false === opts.multiplex || sameNamespace;
|
||
|
||
var io;
|
||
|
||
if (newConnection) {
|
||
debug('ignoring socket cache for %s', source);
|
||
io = Manager(source, opts);
|
||
} else {
|
||
if (!cache[id]) {
|
||
debug('new io instance for %s', source);
|
||
cache[id] = Manager(source, opts);
|
||
}
|
||
io = cache[id];
|
||
}
|
||
|
||
return io.socket(parsed.path);
|
||
}
|
||
|
||
/**
|
||
* Protocol version.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.protocol = parser.protocol;
|
||
|
||
/**
|
||
* `connect`.
|
||
*
|
||
* @param {String} uri
|
||
* @api public
|
||
*/
|
||
|
||
exports.connect = lookup;
|
||
|
||
/**
|
||
* Expose constructors for standalone build.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.Manager = require('./manager');
|
||
exports.Socket = require('./socket');
|
||
|
||
},{"./manager":78,"./socket":80,"./url":81,"debug":54,"socket.io-parser":84}],78:[function(require,module,exports){
|
||
|
||
/**
|
||
* Module dependencies.
|
||
*/
|
||
|
||
var eio = require('engine.io-client');
|
||
var Socket = require('./socket');
|
||
var Emitter = require('component-emitter');
|
||
var parser = require('socket.io-parser');
|
||
var on = require('./on');
|
||
var bind = require('component-bind');
|
||
var debug = require('debug')('socket.io-client:manager');
|
||
var indexOf = require('indexof');
|
||
var Backoff = require('backo2');
|
||
|
||
/**
|
||
* IE6+ hasOwnProperty
|
||
*/
|
||
|
||
var has = Object.prototype.hasOwnProperty;
|
||
|
||
/**
|
||
* Module exports
|
||
*/
|
||
|
||
module.exports = Manager;
|
||
|
||
/**
|
||
* `Manager` constructor.
|
||
*
|
||
* @param {String} engine instance or engine uri/opts
|
||
* @param {Object} options
|
||
* @api public
|
||
*/
|
||
|
||
function Manager(uri, opts){
|
||
if (!(this instanceof Manager)) return new Manager(uri, opts);
|
||
if (uri && ('object' == typeof uri)) {
|
||
opts = uri;
|
||
uri = undefined;
|
||
}
|
||
opts = opts || {};
|
||
|
||
opts.path = opts.path || '/socket.io';
|
||
this.nsps = {};
|
||
this.subs = [];
|
||
this.opts = opts;
|
||
this.reconnection(opts.reconnection !== false);
|
||
this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
|
||
this.reconnectionDelay(opts.reconnectionDelay || 1000);
|
||
this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
|
||
this.randomizationFactor(opts.randomizationFactor || 0.5);
|
||
this.backoff = new Backoff({
|
||
min: this.reconnectionDelay(),
|
||
max: this.reconnectionDelayMax(),
|
||
jitter: this.randomizationFactor()
|
||
});
|
||
this.timeout(null == opts.timeout ? 20000 : opts.timeout);
|
||
this.readyState = 'closed';
|
||
this.uri = uri;
|
||
this.connecting = [];
|
||
this.lastPing = null;
|
||
this.encoding = false;
|
||
this.packetBuffer = [];
|
||
this.encoder = new parser.Encoder();
|
||
this.decoder = new parser.Decoder();
|
||
this.autoConnect = opts.autoConnect !== false;
|
||
if (this.autoConnect) this.open();
|
||
}
|
||
|
||
/**
|
||
* Propagate given event to sockets and emit on `this`
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.emitAll = function() {
|
||
this.emit.apply(this, arguments);
|
||
for (var nsp in this.nsps) {
|
||
if (has.call(this.nsps, nsp)) {
|
||
this.nsps[nsp].emit.apply(this.nsps[nsp], arguments);
|
||
}
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Update `socket.id` of all sockets
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.updateSocketIds = function(){
|
||
for (var nsp in this.nsps) {
|
||
if (has.call(this.nsps, nsp)) {
|
||
this.nsps[nsp].id = this.engine.id;
|
||
}
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Mix in `Emitter`.
|
||
*/
|
||
|
||
Emitter(Manager.prototype);
|
||
|
||
/**
|
||
* Sets the `reconnection` config.
|
||
*
|
||
* @param {Boolean} true/false if it should automatically reconnect
|
||
* @return {Manager} self or value
|
||
* @api public
|
||
*/
|
||
|
||
Manager.prototype.reconnection = function(v){
|
||
if (!arguments.length) return this._reconnection;
|
||
this._reconnection = !!v;
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Sets the reconnection attempts config.
|
||
*
|
||
* @param {Number} max reconnection attempts before giving up
|
||
* @return {Manager} self or value
|
||
* @api public
|
||
*/
|
||
|
||
Manager.prototype.reconnectionAttempts = function(v){
|
||
if (!arguments.length) return this._reconnectionAttempts;
|
||
this._reconnectionAttempts = v;
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Sets the delay between reconnections.
|
||
*
|
||
* @param {Number} delay
|
||
* @return {Manager} self or value
|
||
* @api public
|
||
*/
|
||
|
||
Manager.prototype.reconnectionDelay = function(v){
|
||
if (!arguments.length) return this._reconnectionDelay;
|
||
this._reconnectionDelay = v;
|
||
this.backoff && this.backoff.setMin(v);
|
||
return this;
|
||
};
|
||
|
||
Manager.prototype.randomizationFactor = function(v){
|
||
if (!arguments.length) return this._randomizationFactor;
|
||
this._randomizationFactor = v;
|
||
this.backoff && this.backoff.setJitter(v);
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Sets the maximum delay between reconnections.
|
||
*
|
||
* @param {Number} delay
|
||
* @return {Manager} self or value
|
||
* @api public
|
||
*/
|
||
|
||
Manager.prototype.reconnectionDelayMax = function(v){
|
||
if (!arguments.length) return this._reconnectionDelayMax;
|
||
this._reconnectionDelayMax = v;
|
||
this.backoff && this.backoff.setMax(v);
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Sets the connection timeout. `false` to disable
|
||
*
|
||
* @return {Manager} self or value
|
||
* @api public
|
||
*/
|
||
|
||
Manager.prototype.timeout = function(v){
|
||
if (!arguments.length) return this._timeout;
|
||
this._timeout = v;
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Starts trying to reconnect if reconnection is enabled and we have not
|
||
* started reconnecting yet
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.maybeReconnectOnOpen = function() {
|
||
// Only try to reconnect if it's the first time we're connecting
|
||
if (!this.reconnecting && this._reconnection && this.backoff.attempts === 0) {
|
||
// keeps reconnection from firing twice for the same reconnection loop
|
||
this.reconnect();
|
||
}
|
||
};
|
||
|
||
|
||
/**
|
||
* Sets the current transport `socket`.
|
||
*
|
||
* @param {Function} optional, callback
|
||
* @return {Manager} self
|
||
* @api public
|
||
*/
|
||
|
||
Manager.prototype.open =
|
||
Manager.prototype.connect = function(fn){
|
||
debug('readyState %s', this.readyState);
|
||
if (~this.readyState.indexOf('open')) return this;
|
||
|
||
debug('opening %s', this.uri);
|
||
this.engine = eio(this.uri, this.opts);
|
||
var socket = this.engine;
|
||
var self = this;
|
||
this.readyState = 'opening';
|
||
this.skipReconnect = false;
|
||
|
||
// emit `open`
|
||
var openSub = on(socket, 'open', function() {
|
||
self.onopen();
|
||
fn && fn();
|
||
});
|
||
|
||
// emit `connect_error`
|
||
var errorSub = on(socket, 'error', function(data){
|
||
debug('connect_error');
|
||
self.cleanup();
|
||
self.readyState = 'closed';
|
||
self.emitAll('connect_error', data);
|
||
if (fn) {
|
||
var err = new Error('Connection error');
|
||
err.data = data;
|
||
fn(err);
|
||
} else {
|
||
// Only do this if there is no fn to handle the error
|
||
self.maybeReconnectOnOpen();
|
||
}
|
||
});
|
||
|
||
// emit `connect_timeout`
|
||
if (false !== this._timeout) {
|
||
var timeout = this._timeout;
|
||
debug('connect attempt will timeout after %d', timeout);
|
||
|
||
// set timer
|
||
var timer = setTimeout(function(){
|
||
debug('connect attempt timed out after %d', timeout);
|
||
openSub.destroy();
|
||
socket.close();
|
||
socket.emit('error', 'timeout');
|
||
self.emitAll('connect_timeout', timeout);
|
||
}, timeout);
|
||
|
||
this.subs.push({
|
||
destroy: function(){
|
||
clearTimeout(timer);
|
||
}
|
||
});
|
||
}
|
||
|
||
this.subs.push(openSub);
|
||
this.subs.push(errorSub);
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Called upon transport open.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.onopen = function(){
|
||
debug('open');
|
||
|
||
// clear old subs
|
||
this.cleanup();
|
||
|
||
// mark as open
|
||
this.readyState = 'open';
|
||
this.emit('open');
|
||
|
||
// add new subs
|
||
var socket = this.engine;
|
||
this.subs.push(on(socket, 'data', bind(this, 'ondata')));
|
||
this.subs.push(on(socket, 'ping', bind(this, 'onping')));
|
||
this.subs.push(on(socket, 'pong', bind(this, 'onpong')));
|
||
this.subs.push(on(socket, 'error', bind(this, 'onerror')));
|
||
this.subs.push(on(socket, 'close', bind(this, 'onclose')));
|
||
this.subs.push(on(this.decoder, 'decoded', bind(this, 'ondecoded')));
|
||
};
|
||
|
||
/**
|
||
* Called upon a ping.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.onping = function(){
|
||
this.lastPing = new Date;
|
||
this.emitAll('ping');
|
||
};
|
||
|
||
/**
|
||
* Called upon a packet.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.onpong = function(){
|
||
this.emitAll('pong', new Date - this.lastPing);
|
||
};
|
||
|
||
/**
|
||
* Called with data.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.ondata = function(data){
|
||
this.decoder.add(data);
|
||
};
|
||
|
||
/**
|
||
* Called when parser fully decodes a packet.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.ondecoded = function(packet) {
|
||
this.emit('packet', packet);
|
||
};
|
||
|
||
/**
|
||
* Called upon socket error.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.onerror = function(err){
|
||
debug('error', err);
|
||
this.emitAll('error', err);
|
||
};
|
||
|
||
/**
|
||
* Creates a new socket for the given `nsp`.
|
||
*
|
||
* @return {Socket}
|
||
* @api public
|
||
*/
|
||
|
||
Manager.prototype.socket = function(nsp){
|
||
var socket = this.nsps[nsp];
|
||
if (!socket) {
|
||
socket = new Socket(this, nsp);
|
||
this.nsps[nsp] = socket;
|
||
var self = this;
|
||
socket.on('connecting', onConnecting);
|
||
socket.on('connect', function(){
|
||
socket.id = self.engine.id;
|
||
});
|
||
|
||
if (this.autoConnect) {
|
||
// manually call here since connecting evnet is fired before listening
|
||
onConnecting();
|
||
}
|
||
}
|
||
|
||
function onConnecting() {
|
||
if (!~indexOf(self.connecting, socket)) {
|
||
self.connecting.push(socket);
|
||
}
|
||
}
|
||
|
||
return socket;
|
||
};
|
||
|
||
/**
|
||
* Called upon a socket close.
|
||
*
|
||
* @param {Socket} socket
|
||
*/
|
||
|
||
Manager.prototype.destroy = function(socket){
|
||
var index = indexOf(this.connecting, socket);
|
||
if (~index) this.connecting.splice(index, 1);
|
||
if (this.connecting.length) return;
|
||
|
||
this.close();
|
||
};
|
||
|
||
/**
|
||
* Writes a packet.
|
||
*
|
||
* @param {Object} packet
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.packet = function(packet){
|
||
debug('writing packet %j', packet);
|
||
var self = this;
|
||
|
||
if (!self.encoding) {
|
||
// encode, then write to engine with result
|
||
self.encoding = true;
|
||
this.encoder.encode(packet, function(encodedPackets) {
|
||
for (var i = 0; i < encodedPackets.length; i++) {
|
||
self.engine.write(encodedPackets[i], packet.options);
|
||
}
|
||
self.encoding = false;
|
||
self.processPacketQueue();
|
||
});
|
||
} else { // add packet to the queue
|
||
self.packetBuffer.push(packet);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* If packet buffer is non-empty, begins encoding the
|
||
* next packet in line.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.processPacketQueue = function() {
|
||
if (this.packetBuffer.length > 0 && !this.encoding) {
|
||
var pack = this.packetBuffer.shift();
|
||
this.packet(pack);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Clean up transport subscriptions and packet buffer.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.cleanup = function(){
|
||
debug('cleanup');
|
||
|
||
var sub;
|
||
while (sub = this.subs.shift()) sub.destroy();
|
||
|
||
this.packetBuffer = [];
|
||
this.encoding = false;
|
||
this.lastPing = null;
|
||
|
||
this.decoder.destroy();
|
||
};
|
||
|
||
/**
|
||
* Close the current socket.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.close =
|
||
Manager.prototype.disconnect = function(){
|
||
debug('disconnect');
|
||
this.skipReconnect = true;
|
||
this.reconnecting = false;
|
||
if ('opening' == this.readyState) {
|
||
// `onclose` will not fire because
|
||
// an open event never happened
|
||
this.cleanup();
|
||
}
|
||
this.backoff.reset();
|
||
this.readyState = 'closed';
|
||
if (this.engine) this.engine.close();
|
||
};
|
||
|
||
/**
|
||
* Called upon engine close.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.onclose = function(reason){
|
||
debug('onclose');
|
||
|
||
this.cleanup();
|
||
this.backoff.reset();
|
||
this.readyState = 'closed';
|
||
this.emit('close', reason);
|
||
|
||
if (this._reconnection && !this.skipReconnect) {
|
||
this.reconnect();
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Attempt a reconnection.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.reconnect = function(){
|
||
if (this.reconnecting || this.skipReconnect) return this;
|
||
|
||
var self = this;
|
||
|
||
if (this.backoff.attempts >= this._reconnectionAttempts) {
|
||
debug('reconnect failed');
|
||
this.backoff.reset();
|
||
this.emitAll('reconnect_failed');
|
||
this.reconnecting = false;
|
||
} else {
|
||
var delay = this.backoff.duration();
|
||
debug('will wait %dms before reconnect attempt', delay);
|
||
|
||
this.reconnecting = true;
|
||
var timer = setTimeout(function(){
|
||
if (self.skipReconnect) return;
|
||
|
||
debug('attempting reconnect');
|
||
self.emitAll('reconnect_attempt', self.backoff.attempts);
|
||
self.emitAll('reconnecting', self.backoff.attempts);
|
||
|
||
// check again for the case socket closed in above events
|
||
if (self.skipReconnect) return;
|
||
|
||
self.open(function(err){
|
||
if (err) {
|
||
debug('reconnect attempt error');
|
||
self.reconnecting = false;
|
||
self.reconnect();
|
||
self.emitAll('reconnect_error', err.data);
|
||
} else {
|
||
debug('reconnect success');
|
||
self.onreconnect();
|
||
}
|
||
});
|
||
}, delay);
|
||
|
||
this.subs.push({
|
||
destroy: function(){
|
||
clearTimeout(timer);
|
||
}
|
||
});
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Called upon successful reconnect.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Manager.prototype.onreconnect = function(){
|
||
var attempt = this.backoff.attempts;
|
||
this.reconnecting = false;
|
||
this.backoff.reset();
|
||
this.updateSocketIds();
|
||
this.emitAll('reconnect', attempt);
|
||
};
|
||
|
||
},{"./on":79,"./socket":80,"backo2":47,"component-bind":51,"component-emitter":82,"debug":54,"engine.io-client":56,"indexof":71,"socket.io-parser":84}],79:[function(require,module,exports){
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = on;
|
||
|
||
/**
|
||
* Helper for subscriptions.
|
||
*
|
||
* @param {Object|EventEmitter} obj with `Emitter` mixin or `EventEmitter`
|
||
* @param {String} event name
|
||
* @param {Function} callback
|
||
* @api public
|
||
*/
|
||
|
||
function on(obj, ev, fn) {
|
||
obj.on(ev, fn);
|
||
return {
|
||
destroy: function(){
|
||
obj.removeListener(ev, fn);
|
||
}
|
||
};
|
||
}
|
||
|
||
},{}],80:[function(require,module,exports){
|
||
|
||
/**
|
||
* Module dependencies.
|
||
*/
|
||
|
||
var parser = require('socket.io-parser');
|
||
var Emitter = require('component-emitter');
|
||
var toArray = require('to-array');
|
||
var on = require('./on');
|
||
var bind = require('component-bind');
|
||
var debug = require('debug')('socket.io-client:socket');
|
||
var hasBin = require('has-binary');
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = exports = Socket;
|
||
|
||
/**
|
||
* Internal events (blacklisted).
|
||
* These events can't be emitted by the user.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
var events = {
|
||
connect: 1,
|
||
connect_error: 1,
|
||
connect_timeout: 1,
|
||
connecting: 1,
|
||
disconnect: 1,
|
||
error: 1,
|
||
reconnect: 1,
|
||
reconnect_attempt: 1,
|
||
reconnect_failed: 1,
|
||
reconnect_error: 1,
|
||
reconnecting: 1,
|
||
ping: 1,
|
||
pong: 1
|
||
};
|
||
|
||
/**
|
||
* Shortcut to `Emitter#emit`.
|
||
*/
|
||
|
||
var emit = Emitter.prototype.emit;
|
||
|
||
/**
|
||
* `Socket` constructor.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
function Socket(io, nsp){
|
||
this.io = io;
|
||
this.nsp = nsp;
|
||
this.json = this; // compat
|
||
this.ids = 0;
|
||
this.acks = {};
|
||
this.receiveBuffer = [];
|
||
this.sendBuffer = [];
|
||
this.connected = false;
|
||
this.disconnected = true;
|
||
if (this.io.autoConnect) this.open();
|
||
}
|
||
|
||
/**
|
||
* Mix in `Emitter`.
|
||
*/
|
||
|
||
Emitter(Socket.prototype);
|
||
|
||
/**
|
||
* Subscribe to open, close and packet events
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.subEvents = function() {
|
||
if (this.subs) return;
|
||
|
||
var io = this.io;
|
||
this.subs = [
|
||
on(io, 'open', bind(this, 'onopen')),
|
||
on(io, 'packet', bind(this, 'onpacket')),
|
||
on(io, 'close', bind(this, 'onclose'))
|
||
];
|
||
};
|
||
|
||
/**
|
||
* "Opens" the socket.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Socket.prototype.open =
|
||
Socket.prototype.connect = function(){
|
||
if (this.connected) return this;
|
||
|
||
this.subEvents();
|
||
this.io.open(); // ensure open
|
||
if ('open' == this.io.readyState) this.onopen();
|
||
this.emit('connecting');
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Sends a `message` event.
|
||
*
|
||
* @return {Socket} self
|
||
* @api public
|
||
*/
|
||
|
||
Socket.prototype.send = function(){
|
||
var args = toArray(arguments);
|
||
args.unshift('message');
|
||
this.emit.apply(this, args);
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Override `emit`.
|
||
* If the event is in `events`, it's emitted normally.
|
||
*
|
||
* @param {String} event name
|
||
* @return {Socket} self
|
||
* @api public
|
||
*/
|
||
|
||
Socket.prototype.emit = function(ev){
|
||
if (events.hasOwnProperty(ev)) {
|
||
emit.apply(this, arguments);
|
||
return this;
|
||
}
|
||
|
||
var args = toArray(arguments);
|
||
var parserType = parser.EVENT; // default
|
||
if (hasBin(args)) { parserType = parser.BINARY_EVENT; } // binary
|
||
var packet = { type: parserType, data: args };
|
||
|
||
packet.options = {};
|
||
packet.options.compress = !this.flags || false !== this.flags.compress;
|
||
|
||
// event ack callback
|
||
if ('function' == typeof args[args.length - 1]) {
|
||
debug('emitting packet with ack id %d', this.ids);
|
||
this.acks[this.ids] = args.pop();
|
||
packet.id = this.ids++;
|
||
}
|
||
|
||
if (this.connected) {
|
||
this.packet(packet);
|
||
} else {
|
||
this.sendBuffer.push(packet);
|
||
}
|
||
|
||
delete this.flags;
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Sends a packet.
|
||
*
|
||
* @param {Object} packet
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.packet = function(packet){
|
||
packet.nsp = this.nsp;
|
||
this.io.packet(packet);
|
||
};
|
||
|
||
/**
|
||
* Called upon engine `open`.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onopen = function(){
|
||
debug('transport is open - connecting');
|
||
|
||
// write connect packet if necessary
|
||
if ('/' != this.nsp) {
|
||
this.packet({ type: parser.CONNECT });
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Called upon engine `close`.
|
||
*
|
||
* @param {String} reason
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onclose = function(reason){
|
||
debug('close (%s)', reason);
|
||
this.connected = false;
|
||
this.disconnected = true;
|
||
delete this.id;
|
||
this.emit('disconnect', reason);
|
||
};
|
||
|
||
/**
|
||
* Called with socket packet.
|
||
*
|
||
* @param {Object} packet
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onpacket = function(packet){
|
||
if (packet.nsp != this.nsp) return;
|
||
|
||
switch (packet.type) {
|
||
case parser.CONNECT:
|
||
this.onconnect();
|
||
break;
|
||
|
||
case parser.EVENT:
|
||
this.onevent(packet);
|
||
break;
|
||
|
||
case parser.BINARY_EVENT:
|
||
this.onevent(packet);
|
||
break;
|
||
|
||
case parser.ACK:
|
||
this.onack(packet);
|
||
break;
|
||
|
||
case parser.BINARY_ACK:
|
||
this.onack(packet);
|
||
break;
|
||
|
||
case parser.DISCONNECT:
|
||
this.ondisconnect();
|
||
break;
|
||
|
||
case parser.ERROR:
|
||
this.emit('error', packet.data);
|
||
break;
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Called upon a server event.
|
||
*
|
||
* @param {Object} packet
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onevent = function(packet){
|
||
var args = packet.data || [];
|
||
debug('emitting event %j', args);
|
||
|
||
if (null != packet.id) {
|
||
debug('attaching ack callback to event');
|
||
args.push(this.ack(packet.id));
|
||
}
|
||
|
||
if (this.connected) {
|
||
emit.apply(this, args);
|
||
} else {
|
||
this.receiveBuffer.push(args);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Produces an ack callback to emit with an event.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.ack = function(id){
|
||
var self = this;
|
||
var sent = false;
|
||
return function(){
|
||
// prevent double callbacks
|
||
if (sent) return;
|
||
sent = true;
|
||
var args = toArray(arguments);
|
||
debug('sending ack %j', args);
|
||
|
||
var type = hasBin(args) ? parser.BINARY_ACK : parser.ACK;
|
||
self.packet({
|
||
type: type,
|
||
id: id,
|
||
data: args
|
||
});
|
||
};
|
||
};
|
||
|
||
/**
|
||
* Called upon a server acknowlegement.
|
||
*
|
||
* @param {Object} packet
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onack = function(packet){
|
||
var ack = this.acks[packet.id];
|
||
if ('function' == typeof ack) {
|
||
debug('calling ack %s with %j', packet.id, packet.data);
|
||
ack.apply(this, packet.data);
|
||
delete this.acks[packet.id];
|
||
} else {
|
||
debug('bad ack %s', packet.id);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Called upon server connect.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.onconnect = function(){
|
||
this.connected = true;
|
||
this.disconnected = false;
|
||
this.emit('connect');
|
||
this.emitBuffered();
|
||
};
|
||
|
||
/**
|
||
* Emit buffered events (received and emitted).
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.emitBuffered = function(){
|
||
var i;
|
||
for (i = 0; i < this.receiveBuffer.length; i++) {
|
||
emit.apply(this, this.receiveBuffer[i]);
|
||
}
|
||
this.receiveBuffer = [];
|
||
|
||
for (i = 0; i < this.sendBuffer.length; i++) {
|
||
this.packet(this.sendBuffer[i]);
|
||
}
|
||
this.sendBuffer = [];
|
||
};
|
||
|
||
/**
|
||
* Called upon server disconnect.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
Socket.prototype.ondisconnect = function(){
|
||
debug('server disconnect (%s)', this.nsp);
|
||
this.destroy();
|
||
this.onclose('io server disconnect');
|
||
};
|
||
|
||
/**
|
||
* Called upon forced client/server side disconnections,
|
||
* this method ensures the manager stops tracking us and
|
||
* that reconnections don't get triggered for this.
|
||
*
|
||
* @api private.
|
||
*/
|
||
|
||
Socket.prototype.destroy = function(){
|
||
if (this.subs) {
|
||
// clean subscriptions to avoid reconnections
|
||
for (var i = 0; i < this.subs.length; i++) {
|
||
this.subs[i].destroy();
|
||
}
|
||
this.subs = null;
|
||
}
|
||
|
||
this.io.destroy(this);
|
||
};
|
||
|
||
/**
|
||
* Disconnects the socket manually.
|
||
*
|
||
* @return {Socket} self
|
||
* @api public
|
||
*/
|
||
|
||
Socket.prototype.close =
|
||
Socket.prototype.disconnect = function(){
|
||
if (this.connected) {
|
||
debug('performing disconnect (%s)', this.nsp);
|
||
this.packet({ type: parser.DISCONNECT });
|
||
}
|
||
|
||
// remove socket from pool
|
||
this.destroy();
|
||
|
||
if (this.connected) {
|
||
// fire events
|
||
this.onclose('io client disconnect');
|
||
}
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Sets the compress flag.
|
||
*
|
||
* @param {Boolean} if `true`, compresses the sending data
|
||
* @return {Socket} self
|
||
* @api public
|
||
*/
|
||
|
||
Socket.prototype.compress = function(compress){
|
||
this.flags = this.flags || {};
|
||
this.flags.compress = compress;
|
||
return this;
|
||
};
|
||
|
||
},{"./on":79,"component-bind":51,"component-emitter":82,"debug":54,"has-binary":69,"socket.io-parser":84,"to-array":87}],81:[function(require,module,exports){
|
||
(function (global){
|
||
|
||
/**
|
||
* Module dependencies.
|
||
*/
|
||
|
||
var parseuri = require('parseuri');
|
||
var debug = require('debug')('socket.io-client:url');
|
||
|
||
/**
|
||
* Module exports.
|
||
*/
|
||
|
||
module.exports = url;
|
||
|
||
/**
|
||
* URL parser.
|
||
*
|
||
* @param {String} url
|
||
* @param {Object} An object meant to mimic window.location.
|
||
* Defaults to window.location.
|
||
* @api public
|
||
*/
|
||
|
||
function url(uri, loc){
|
||
var obj = uri;
|
||
|
||
// default to window.location
|
||
var loc = loc || global.location;
|
||
if (null == uri) uri = loc.protocol + '//' + loc.host;
|
||
|
||
// relative path support
|
||
if ('string' == typeof uri) {
|
||
if ('/' == uri.charAt(0)) {
|
||
if ('/' == uri.charAt(1)) {
|
||
uri = loc.protocol + uri;
|
||
} else {
|
||
uri = loc.host + uri;
|
||
}
|
||
}
|
||
|
||
if (!/^(https?|wss?):\/\//.test(uri)) {
|
||
debug('protocol-less url %s', uri);
|
||
if ('undefined' != typeof loc) {
|
||
uri = loc.protocol + '//' + uri;
|
||
} else {
|
||
uri = 'https://' + uri;
|
||
}
|
||
}
|
||
|
||
// parse
|
||
debug('parse %s', uri);
|
||
obj = parseuri(uri);
|
||
}
|
||
|
||
// make sure we treat `localhost:80` and `localhost` equally
|
||
if (!obj.port) {
|
||
if (/^(http|ws)$/.test(obj.protocol)) {
|
||
obj.port = '80';
|
||
}
|
||
else if (/^(http|ws)s$/.test(obj.protocol)) {
|
||
obj.port = '443';
|
||
}
|
||
}
|
||
|
||
obj.path = obj.path || '/';
|
||
|
||
var ipv6 = obj.host.indexOf(':') !== -1;
|
||
var host = ipv6 ? '[' + obj.host + ']' : obj.host;
|
||
|
||
// define unique id
|
||
obj.id = obj.protocol + '://' + host + ':' + obj.port;
|
||
// define href
|
||
obj.href = obj.protocol + '://' + host + (loc && loc.port == obj.port ? '' : (':' + obj.port));
|
||
|
||
return obj;
|
||
}
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{"debug":54,"parseuri":76}],82:[function(require,module,exports){
|
||
|
||
/**
|
||
* Expose `Emitter`.
|
||
*/
|
||
|
||
module.exports = Emitter;
|
||
|
||
/**
|
||
* Initialize a new `Emitter`.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
function Emitter(obj) {
|
||
if (obj) return mixin(obj);
|
||
};
|
||
|
||
/**
|
||
* Mixin the emitter properties.
|
||
*
|
||
* @param {Object} obj
|
||
* @return {Object}
|
||
* @api private
|
||
*/
|
||
|
||
function mixin(obj) {
|
||
for (var key in Emitter.prototype) {
|
||
obj[key] = Emitter.prototype[key];
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
/**
|
||
* Listen on the given `event` with `fn`.
|
||
*
|
||
* @param {String} event
|
||
* @param {Function} fn
|
||
* @return {Emitter}
|
||
* @api public
|
||
*/
|
||
|
||
Emitter.prototype.on =
|
||
Emitter.prototype.addEventListener = function(event, fn){
|
||
this._callbacks = this._callbacks || {};
|
||
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
||
.push(fn);
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Adds an `event` listener that will be invoked a single
|
||
* time then automatically removed.
|
||
*
|
||
* @param {String} event
|
||
* @param {Function} fn
|
||
* @return {Emitter}
|
||
* @api public
|
||
*/
|
||
|
||
Emitter.prototype.once = function(event, fn){
|
||
function on() {
|
||
this.off(event, on);
|
||
fn.apply(this, arguments);
|
||
}
|
||
|
||
on.fn = fn;
|
||
this.on(event, on);
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Remove the given callback for `event` or all
|
||
* registered callbacks.
|
||
*
|
||
* @param {String} event
|
||
* @param {Function} fn
|
||
* @return {Emitter}
|
||
* @api public
|
||
*/
|
||
|
||
Emitter.prototype.off =
|
||
Emitter.prototype.removeListener =
|
||
Emitter.prototype.removeAllListeners =
|
||
Emitter.prototype.removeEventListener = function(event, fn){
|
||
this._callbacks = this._callbacks || {};
|
||
|
||
// all
|
||
if (0 == arguments.length) {
|
||
this._callbacks = {};
|
||
return this;
|
||
}
|
||
|
||
// specific event
|
||
var callbacks = this._callbacks['$' + event];
|
||
if (!callbacks) return this;
|
||
|
||
// remove all handlers
|
||
if (1 == arguments.length) {
|
||
delete this._callbacks['$' + event];
|
||
return this;
|
||
}
|
||
|
||
// remove specific handler
|
||
var cb;
|
||
for (var i = 0; i < callbacks.length; i++) {
|
||
cb = callbacks[i];
|
||
if (cb === fn || cb.fn === fn) {
|
||
callbacks.splice(i, 1);
|
||
break;
|
||
}
|
||
}
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Emit `event` with the given args.
|
||
*
|
||
* @param {String} event
|
||
* @param {Mixed} ...
|
||
* @return {Emitter}
|
||
*/
|
||
|
||
Emitter.prototype.emit = function(event){
|
||
this._callbacks = this._callbacks || {};
|
||
var args = [].slice.call(arguments, 1)
|
||
, callbacks = this._callbacks['$' + event];
|
||
|
||
if (callbacks) {
|
||
callbacks = callbacks.slice(0);
|
||
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
||
callbacks[i].apply(this, args);
|
||
}
|
||
}
|
||
|
||
return this;
|
||
};
|
||
|
||
/**
|
||
* Return array of callbacks for `event`.
|
||
*
|
||
* @param {String} event
|
||
* @return {Array}
|
||
* @api public
|
||
*/
|
||
|
||
Emitter.prototype.listeners = function(event){
|
||
this._callbacks = this._callbacks || {};
|
||
return this._callbacks['$' + event] || [];
|
||
};
|
||
|
||
/**
|
||
* Check if this emitter has `event` handlers.
|
||
*
|
||
* @param {String} event
|
||
* @return {Boolean}
|
||
* @api public
|
||
*/
|
||
|
||
Emitter.prototype.hasListeners = function(event){
|
||
return !! this.listeners(event).length;
|
||
};
|
||
|
||
},{}],83:[function(require,module,exports){
|
||
(function (global){
|
||
/*global Blob,File*/
|
||
|
||
/**
|
||
* Module requirements
|
||
*/
|
||
|
||
var isArray = require('isarray');
|
||
var isBuf = require('./is-buffer');
|
||
|
||
/**
|
||
* Replaces every Buffer | ArrayBuffer in packet with a numbered placeholder.
|
||
* Anything with blobs or files should be fed through removeBlobs before coming
|
||
* here.
|
||
*
|
||
* @param {Object} packet - socket.io event packet
|
||
* @return {Object} with deconstructed packet and list of buffers
|
||
* @api public
|
||
*/
|
||
|
||
exports.deconstructPacket = function(packet){
|
||
var buffers = [];
|
||
var packetData = packet.data;
|
||
|
||
function _deconstructPacket(data) {
|
||
if (!data) return data;
|
||
|
||
if (isBuf(data)) {
|
||
var placeholder = { _placeholder: true, num: buffers.length };
|
||
buffers.push(data);
|
||
return placeholder;
|
||
} else if (isArray(data)) {
|
||
var newData = new Array(data.length);
|
||
for (var i = 0; i < data.length; i++) {
|
||
newData[i] = _deconstructPacket(data[i]);
|
||
}
|
||
return newData;
|
||
} else if ('object' == typeof data && !(data instanceof Date)) {
|
||
var newData = {};
|
||
for (var key in data) {
|
||
newData[key] = _deconstructPacket(data[key]);
|
||
}
|
||
return newData;
|
||
}
|
||
return data;
|
||
}
|
||
|
||
var pack = packet;
|
||
pack.data = _deconstructPacket(packetData);
|
||
pack.attachments = buffers.length; // number of binary 'attachments'
|
||
return {packet: pack, buffers: buffers};
|
||
};
|
||
|
||
/**
|
||
* Reconstructs a binary packet from its placeholder packet and buffers
|
||
*
|
||
* @param {Object} packet - event packet with placeholders
|
||
* @param {Array} buffers - binary buffers to put in placeholder positions
|
||
* @return {Object} reconstructed packet
|
||
* @api public
|
||
*/
|
||
|
||
exports.reconstructPacket = function(packet, buffers) {
|
||
var curPlaceHolder = 0;
|
||
|
||
function _reconstructPacket(data) {
|
||
if (data && data._placeholder) {
|
||
var buf = buffers[data.num]; // appropriate buffer (should be natural order anyway)
|
||
return buf;
|
||
} else if (isArray(data)) {
|
||
for (var i = 0; i < data.length; i++) {
|
||
data[i] = _reconstructPacket(data[i]);
|
||
}
|
||
return data;
|
||
} else if (data && 'object' == typeof data) {
|
||
for (var key in data) {
|
||
data[key] = _reconstructPacket(data[key]);
|
||
}
|
||
return data;
|
||
}
|
||
return data;
|
||
}
|
||
|
||
packet.data = _reconstructPacket(packet.data);
|
||
packet.attachments = undefined; // no longer useful
|
||
return packet;
|
||
};
|
||
|
||
/**
|
||
* Asynchronously removes Blobs or Files from data via
|
||
* FileReader's readAsArrayBuffer method. Used before encoding
|
||
* data as msgpack. Calls callback with the blobless data.
|
||
*
|
||
* @param {Object} data
|
||
* @param {Function} callback
|
||
* @api private
|
||
*/
|
||
|
||
exports.removeBlobs = function(data, callback) {
|
||
function _removeBlobs(obj, curKey, containingObject) {
|
||
if (!obj) return obj;
|
||
|
||
// convert any blob
|
||
if ((global.Blob && obj instanceof Blob) ||
|
||
(global.File && obj instanceof File)) {
|
||
pendingBlobs++;
|
||
|
||
// async filereader
|
||
var fileReader = new FileReader();
|
||
fileReader.onload = function() { // this.result == arraybuffer
|
||
if (containingObject) {
|
||
containingObject[curKey] = this.result;
|
||
}
|
||
else {
|
||
bloblessData = this.result;
|
||
}
|
||
|
||
// if nothing pending its callback time
|
||
if(! --pendingBlobs) {
|
||
callback(bloblessData);
|
||
}
|
||
};
|
||
|
||
fileReader.readAsArrayBuffer(obj); // blob -> arraybuffer
|
||
} else if (isArray(obj)) { // handle array
|
||
for (var i = 0; i < obj.length; i++) {
|
||
_removeBlobs(obj[i], i, obj);
|
||
}
|
||
} else if (obj && 'object' == typeof obj && !isBuf(obj)) { // and object
|
||
for (var key in obj) {
|
||
_removeBlobs(obj[key], key, obj);
|
||
}
|
||
}
|
||
}
|
||
|
||
var pendingBlobs = 0;
|
||
var bloblessData = data;
|
||
_removeBlobs(bloblessData);
|
||
if (!pendingBlobs) {
|
||
callback(bloblessData);
|
||
}
|
||
};
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{"./is-buffer":85,"isarray":72}],84:[function(require,module,exports){
|
||
|
||
/**
|
||
* Module dependencies.
|
||
*/
|
||
|
||
var debug = require('debug')('socket.io-parser');
|
||
var json = require('json3');
|
||
var isArray = require('isarray');
|
||
var Emitter = require('component-emitter');
|
||
var binary = require('./binary');
|
||
var isBuf = require('./is-buffer');
|
||
|
||
/**
|
||
* Protocol version.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.protocol = 4;
|
||
|
||
/**
|
||
* Packet types.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.types = [
|
||
'CONNECT',
|
||
'DISCONNECT',
|
||
'EVENT',
|
||
'ACK',
|
||
'ERROR',
|
||
'BINARY_EVENT',
|
||
'BINARY_ACK'
|
||
];
|
||
|
||
/**
|
||
* Packet type `connect`.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.CONNECT = 0;
|
||
|
||
/**
|
||
* Packet type `disconnect`.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.DISCONNECT = 1;
|
||
|
||
/**
|
||
* Packet type `event`.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.EVENT = 2;
|
||
|
||
/**
|
||
* Packet type `ack`.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.ACK = 3;
|
||
|
||
/**
|
||
* Packet type `error`.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.ERROR = 4;
|
||
|
||
/**
|
||
* Packet type 'binary event'
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.BINARY_EVENT = 5;
|
||
|
||
/**
|
||
* Packet type `binary ack`. For acks with binary arguments.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.BINARY_ACK = 6;
|
||
|
||
/**
|
||
* Encoder constructor.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.Encoder = Encoder;
|
||
|
||
/**
|
||
* Decoder constructor.
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
exports.Decoder = Decoder;
|
||
|
||
/**
|
||
* A socket.io Encoder instance
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
function Encoder() {}
|
||
|
||
/**
|
||
* Encode a packet as a single string if non-binary, or as a
|
||
* buffer sequence, depending on packet type.
|
||
*
|
||
* @param {Object} obj - packet object
|
||
* @param {Function} callback - function to handle encodings (likely engine.write)
|
||
* @return Calls callback with Array of encodings
|
||
* @api public
|
||
*/
|
||
|
||
Encoder.prototype.encode = function(obj, callback){
|
||
debug('encoding packet %j', obj);
|
||
|
||
if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
|
||
encodeAsBinary(obj, callback);
|
||
}
|
||
else {
|
||
var encoding = encodeAsString(obj);
|
||
callback([encoding]);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Encode packet as string.
|
||
*
|
||
* @param {Object} packet
|
||
* @return {String} encoded
|
||
* @api private
|
||
*/
|
||
|
||
function encodeAsString(obj) {
|
||
var str = '';
|
||
var nsp = false;
|
||
|
||
// first is type
|
||
str += obj.type;
|
||
|
||
// attachments if we have them
|
||
if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
|
||
str += obj.attachments;
|
||
str += '-';
|
||
}
|
||
|
||
// if we have a namespace other than `/`
|
||
// we append it followed by a comma `,`
|
||
if (obj.nsp && '/' != obj.nsp) {
|
||
nsp = true;
|
||
str += obj.nsp;
|
||
}
|
||
|
||
// immediately followed by the id
|
||
if (null != obj.id) {
|
||
if (nsp) {
|
||
str += ',';
|
||
nsp = false;
|
||
}
|
||
str += obj.id;
|
||
}
|
||
|
||
// json data
|
||
if (null != obj.data) {
|
||
if (nsp) str += ',';
|
||
str += json.stringify(obj.data);
|
||
}
|
||
|
||
debug('encoded %j as %s', obj, str);
|
||
return str;
|
||
}
|
||
|
||
/**
|
||
* Encode packet as 'buffer sequence' by removing blobs, and
|
||
* deconstructing packet into object with placeholders and
|
||
* a list of buffers.
|
||
*
|
||
* @param {Object} packet
|
||
* @return {Buffer} encoded
|
||
* @api private
|
||
*/
|
||
|
||
function encodeAsBinary(obj, callback) {
|
||
|
||
function writeEncoding(bloblessData) {
|
||
var deconstruction = binary.deconstructPacket(bloblessData);
|
||
var pack = encodeAsString(deconstruction.packet);
|
||
var buffers = deconstruction.buffers;
|
||
|
||
buffers.unshift(pack); // add packet info to beginning of data list
|
||
callback(buffers); // write all the buffers
|
||
}
|
||
|
||
binary.removeBlobs(obj, writeEncoding);
|
||
}
|
||
|
||
/**
|
||
* A socket.io Decoder instance
|
||
*
|
||
* @return {Object} decoder
|
||
* @api public
|
||
*/
|
||
|
||
function Decoder() {
|
||
this.reconstructor = null;
|
||
}
|
||
|
||
/**
|
||
* Mix in `Emitter` with Decoder.
|
||
*/
|
||
|
||
Emitter(Decoder.prototype);
|
||
|
||
/**
|
||
* Decodes an ecoded packet string into packet JSON.
|
||
*
|
||
* @param {String} obj - encoded packet
|
||
* @return {Object} packet
|
||
* @api public
|
||
*/
|
||
|
||
Decoder.prototype.add = function(obj) {
|
||
var packet;
|
||
if ('string' == typeof obj) {
|
||
packet = decodeString(obj);
|
||
if (exports.BINARY_EVENT == packet.type || exports.BINARY_ACK == packet.type) { // binary packet's json
|
||
this.reconstructor = new BinaryReconstructor(packet);
|
||
|
||
// no attachments, labeled binary but no binary data to follow
|
||
if (this.reconstructor.reconPack.attachments === 0) {
|
||
this.emit('decoded', packet);
|
||
}
|
||
} else { // non-binary full packet
|
||
this.emit('decoded', packet);
|
||
}
|
||
}
|
||
else if (isBuf(obj) || obj.base64) { // raw binary data
|
||
if (!this.reconstructor) {
|
||
throw new Error('got binary data when not reconstructing a packet');
|
||
} else {
|
||
packet = this.reconstructor.takeBinaryData(obj);
|
||
if (packet) { // received final buffer
|
||
this.reconstructor = null;
|
||
this.emit('decoded', packet);
|
||
}
|
||
}
|
||
}
|
||
else {
|
||
throw new Error('Unknown type: ' + obj);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Decode a packet String (JSON data)
|
||
*
|
||
* @param {String} str
|
||
* @return {Object} packet
|
||
* @api private
|
||
*/
|
||
|
||
function decodeString(str) {
|
||
var p = {};
|
||
var i = 0;
|
||
|
||
// look up type
|
||
p.type = Number(str.charAt(0));
|
||
if (null == exports.types[p.type]) return error();
|
||
|
||
// look up attachments if type binary
|
||
if (exports.BINARY_EVENT == p.type || exports.BINARY_ACK == p.type) {
|
||
var buf = '';
|
||
while (str.charAt(++i) != '-') {
|
||
buf += str.charAt(i);
|
||
if (i == str.length) break;
|
||
}
|
||
if (buf != Number(buf) || str.charAt(i) != '-') {
|
||
throw new Error('Illegal attachments');
|
||
}
|
||
p.attachments = Number(buf);
|
||
}
|
||
|
||
// look up namespace (if any)
|
||
if ('/' == str.charAt(i + 1)) {
|
||
p.nsp = '';
|
||
while (++i) {
|
||
var c = str.charAt(i);
|
||
if (',' == c) break;
|
||
p.nsp += c;
|
||
if (i == str.length) break;
|
||
}
|
||
} else {
|
||
p.nsp = '/';
|
||
}
|
||
|
||
// look up id
|
||
var next = str.charAt(i + 1);
|
||
if ('' !== next && Number(next) == next) {
|
||
p.id = '';
|
||
while (++i) {
|
||
var c = str.charAt(i);
|
||
if (null == c || Number(c) != c) {
|
||
--i;
|
||
break;
|
||
}
|
||
p.id += str.charAt(i);
|
||
if (i == str.length) break;
|
||
}
|
||
p.id = Number(p.id);
|
||
}
|
||
|
||
// look up json data
|
||
if (str.charAt(++i)) {
|
||
try {
|
||
p.data = json.parse(str.substr(i));
|
||
} catch(e){
|
||
return error();
|
||
}
|
||
}
|
||
|
||
debug('decoded %s as %j', str, p);
|
||
return p;
|
||
}
|
||
|
||
/**
|
||
* Deallocates a parser's resources
|
||
*
|
||
* @api public
|
||
*/
|
||
|
||
Decoder.prototype.destroy = function() {
|
||
if (this.reconstructor) {
|
||
this.reconstructor.finishedReconstruction();
|
||
}
|
||
};
|
||
|
||
/**
|
||
* A manager of a binary event's 'buffer sequence'. Should
|
||
* be constructed whenever a packet of type BINARY_EVENT is
|
||
* decoded.
|
||
*
|
||
* @param {Object} packet
|
||
* @return {BinaryReconstructor} initialized reconstructor
|
||
* @api private
|
||
*/
|
||
|
||
function BinaryReconstructor(packet) {
|
||
this.reconPack = packet;
|
||
this.buffers = [];
|
||
}
|
||
|
||
/**
|
||
* Method to be called when binary data received from connection
|
||
* after a BINARY_EVENT packet.
|
||
*
|
||
* @param {Buffer | ArrayBuffer} binData - the raw binary data received
|
||
* @return {null | Object} returns null if more binary data is expected or
|
||
* a reconstructed packet object if all buffers have been received.
|
||
* @api private
|
||
*/
|
||
|
||
BinaryReconstructor.prototype.takeBinaryData = function(binData) {
|
||
this.buffers.push(binData);
|
||
if (this.buffers.length == this.reconPack.attachments) { // done with buffer list
|
||
var packet = binary.reconstructPacket(this.reconPack, this.buffers);
|
||
this.finishedReconstruction();
|
||
return packet;
|
||
}
|
||
return null;
|
||
};
|
||
|
||
/**
|
||
* Cleans up binary packet reconstruction variables.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
BinaryReconstructor.prototype.finishedReconstruction = function() {
|
||
this.reconPack = null;
|
||
this.buffers = [];
|
||
};
|
||
|
||
function error(data){
|
||
return {
|
||
type: exports.ERROR,
|
||
data: 'parser error'
|
||
};
|
||
}
|
||
|
||
},{"./binary":83,"./is-buffer":85,"component-emitter":52,"debug":54,"isarray":72,"json3":86}],85:[function(require,module,exports){
|
||
(function (global){
|
||
|
||
module.exports = isBuf;
|
||
|
||
/**
|
||
* Returns true if obj is a buffer or an arraybuffer.
|
||
*
|
||
* @api private
|
||
*/
|
||
|
||
function isBuf(obj) {
|
||
return (global.Buffer && global.Buffer.isBuffer(obj)) ||
|
||
(global.ArrayBuffer && obj instanceof ArrayBuffer);
|
||
}
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{}],86:[function(require,module,exports){
|
||
(function (global){
|
||
/*! JSON v3.3.2 | http://bestiejs.github.io/json3 | Copyright 2012-2014, Kit Cambridge | http://kit.mit-license.org */
|
||
;(function () {
|
||
// Detect the `define` function exposed by asynchronous module loaders. The
|
||
// strict `define` check is necessary for compatibility with `r.js`.
|
||
var isLoader = typeof define === "function" && define.amd;
|
||
|
||
// A set of types used to distinguish objects from primitives.
|
||
var objectTypes = {
|
||
"function": true,
|
||
"object": true
|
||
};
|
||
|
||
// Detect the `exports` object exposed by CommonJS implementations.
|
||
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
|
||
|
||
// Use the `global` object exposed by Node (including Browserify via
|
||
// `insert-module-globals`), Narwhal, and Ringo as the default context,
|
||
// and the `window` object in browsers. Rhino exports a `global` function
|
||
// instead.
|
||
var root = objectTypes[typeof window] && window || this,
|
||
freeGlobal = freeExports && objectTypes[typeof module] && module && !module.nodeType && typeof global == "object" && global;
|
||
|
||
if (freeGlobal && (freeGlobal["global"] === freeGlobal || freeGlobal["window"] === freeGlobal || freeGlobal["self"] === freeGlobal)) {
|
||
root = freeGlobal;
|
||
}
|
||
|
||
// Public: Initializes JSON 3 using the given `context` object, attaching the
|
||
// `stringify` and `parse` functions to the specified `exports` object.
|
||
function runInContext(context, exports) {
|
||
context || (context = root["Object"]());
|
||
exports || (exports = root["Object"]());
|
||
|
||
// Native constructor aliases.
|
||
var Number = context["Number"] || root["Number"],
|
||
String = context["String"] || root["String"],
|
||
Object = context["Object"] || root["Object"],
|
||
Date = context["Date"] || root["Date"],
|
||
SyntaxError = context["SyntaxError"] || root["SyntaxError"],
|
||
TypeError = context["TypeError"] || root["TypeError"],
|
||
Math = context["Math"] || root["Math"],
|
||
nativeJSON = context["JSON"] || root["JSON"];
|
||
|
||
// Delegate to the native `stringify` and `parse` implementations.
|
||
if (typeof nativeJSON == "object" && nativeJSON) {
|
||
exports.stringify = nativeJSON.stringify;
|
||
exports.parse = nativeJSON.parse;
|
||
}
|
||
|
||
// Convenience aliases.
|
||
var objectProto = Object.prototype,
|
||
getClass = objectProto.toString,
|
||
isProperty, forEach, undef;
|
||
|
||
// Test the `Date#getUTC*` methods. Based on work by @Yaffle.
|
||
var isExtended = new Date(-3509827334573292);
|
||
try {
|
||
// The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical
|
||
// results for certain dates in Opera >= 10.53.
|
||
isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 &&
|
||
// Safari < 2.0.2 stores the internal millisecond time value correctly,
|
||
// but clips the values returned by the date methods to the range of
|
||
// signed 32-bit integers ([-2 ** 31, 2 ** 31 - 1]).
|
||
isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708;
|
||
} catch (exception) {}
|
||
|
||
// Internal: Determines whether the native `JSON.stringify` and `parse`
|
||
// implementations are spec-compliant. Based on work by Ken Snyder.
|
||
function has(name) {
|
||
if (has[name] !== undef) {
|
||
// Return cached feature test result.
|
||
return has[name];
|
||
}
|
||
var isSupported;
|
||
if (name == "bug-string-char-index") {
|
||
// IE <= 7 doesn't support accessing string characters using square
|
||
// bracket notation. IE 8 only supports this for primitives.
|
||
isSupported = "a"[0] != "a";
|
||
} else if (name == "json") {
|
||
// Indicates whether both `JSON.stringify` and `JSON.parse` are
|
||
// supported.
|
||
isSupported = has("json-stringify") && has("json-parse");
|
||
} else {
|
||
var value, serialized = '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}';
|
||
// Test `JSON.stringify`.
|
||
if (name == "json-stringify") {
|
||
var stringify = exports.stringify, stringifySupported = typeof stringify == "function" && isExtended;
|
||
if (stringifySupported) {
|
||
// A test function object with a custom `toJSON` method.
|
||
(value = function () {
|
||
return 1;
|
||
}).toJSON = value;
|
||
try {
|
||
stringifySupported =
|
||
// Firefox 3.1b1 and b2 serialize string, number, and boolean
|
||
// primitives as object literals.
|
||
stringify(0) === "0" &&
|
||
// FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object
|
||
// literals.
|
||
stringify(new Number()) === "0" &&
|
||
stringify(new String()) == '""' &&
|
||
// FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or
|
||
// does not define a canonical JSON representation (this applies to
|
||
// objects with `toJSON` properties as well, *unless* they are nested
|
||
// within an object or array).
|
||
stringify(getClass) === undef &&
|
||
// IE 8 serializes `undefined` as `"undefined"`. Safari <= 5.1.7 and
|
||
// FF 3.1b3 pass this test.
|
||
stringify(undef) === undef &&
|
||
// Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s,
|
||
// respectively, if the value is omitted entirely.
|
||
stringify() === undef &&
|
||
// FF 3.1b1, 2 throw an error if the given value is not a number,
|
||
// string, array, object, Boolean, or `null` literal. This applies to
|
||
// objects with custom `toJSON` methods as well, unless they are nested
|
||
// inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON`
|
||
// methods entirely.
|
||
stringify(value) === "1" &&
|
||
stringify([value]) == "[1]" &&
|
||
// Prototype <= 1.6.1 serializes `[undefined]` as `"[]"` instead of
|
||
// `"[null]"`.
|
||
stringify([undef]) == "[null]" &&
|
||
// YUI 3.0.0b1 fails to serialize `null` literals.
|
||
stringify(null) == "null" &&
|
||
// FF 3.1b1, 2 halts serialization if an array contains a function:
|
||
// `[1, true, getClass, 1]` serializes as "[1,true,],". FF 3.1b3
|
||
// elides non-JSON values from objects and arrays, unless they
|
||
// define custom `toJSON` methods.
|
||
stringify([undef, getClass, null]) == "[null,null,null]" &&
|
||
// Simple serialization test. FF 3.1b1 uses Unicode escape sequences
|
||
// where character escape codes are expected (e.g., `\b` => `\u0008`).
|
||
stringify({ "a": [value, true, false, null, "\x00\b\n\f\r\t"] }) == serialized &&
|
||
// FF 3.1b1 and b2 ignore the `filter` and `width` arguments.
|
||
stringify(null, value) === "1" &&
|
||
stringify([1, 2], null, 1) == "[\n 1,\n 2\n]" &&
|
||
// JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly
|
||
// serialize extended years.
|
||
stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' &&
|
||
// The milliseconds are optional in ES 5, but required in 5.1.
|
||
stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' &&
|
||
// Firefox <= 11.0 incorrectly serializes years prior to 0 as negative
|
||
// four-digit years instead of six-digit years. Credits: @Yaffle.
|
||
stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' &&
|
||
// Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond
|
||
// values less than 1000. Credits: @Yaffle.
|
||
stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"';
|
||
} catch (exception) {
|
||
stringifySupported = false;
|
||
}
|
||
}
|
||
isSupported = stringifySupported;
|
||
}
|
||
// Test `JSON.parse`.
|
||
if (name == "json-parse") {
|
||
var parse = exports.parse;
|
||
if (typeof parse == "function") {
|
||
try {
|
||
// FF 3.1b1, b2 will throw an exception if a bare literal is provided.
|
||
// Conforming implementations should also coerce the initial argument to
|
||
// a string prior to parsing.
|
||
if (parse("0") === 0 && !parse(false)) {
|
||
// Simple parsing test.
|
||
value = parse(serialized);
|
||
var parseSupported = value["a"].length == 5 && value["a"][0] === 1;
|
||
if (parseSupported) {
|
||
try {
|
||
// Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings.
|
||
parseSupported = !parse('"\t"');
|
||
} catch (exception) {}
|
||
if (parseSupported) {
|
||
try {
|
||
// FF 4.0 and 4.0.1 allow leading `+` signs and leading
|
||
// decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow
|
||
// certain octal literals.
|
||
parseSupported = parse("01") !== 1;
|
||
} catch (exception) {}
|
||
}
|
||
if (parseSupported) {
|
||
try {
|
||
// FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal
|
||
// points. These environments, along with FF 3.1b1 and 2,
|
||
// also allow trailing commas in JSON objects and arrays.
|
||
parseSupported = parse("1.") !== 1;
|
||
} catch (exception) {}
|
||
}
|
||
}
|
||
}
|
||
} catch (exception) {
|
||
parseSupported = false;
|
||
}
|
||
}
|
||
isSupported = parseSupported;
|
||
}
|
||
}
|
||
return has[name] = !!isSupported;
|
||
}
|
||
|
||
if (!has("json")) {
|
||
// Common `[[Class]]` name aliases.
|
||
var functionClass = "[object Function]",
|
||
dateClass = "[object Date]",
|
||
numberClass = "[object Number]",
|
||
stringClass = "[object String]",
|
||
arrayClass = "[object Array]",
|
||
booleanClass = "[object Boolean]";
|
||
|
||
// Detect incomplete support for accessing string characters by index.
|
||
var charIndexBuggy = has("bug-string-char-index");
|
||
|
||
// Define additional utility methods if the `Date` methods are buggy.
|
||
if (!isExtended) {
|
||
var floor = Math.floor;
|
||
// A mapping between the months of the year and the number of days between
|
||
// January 1st and the first of the respective month.
|
||
var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
|
||
// Internal: Calculates the number of days between the Unix epoch and the
|
||
// first day of the given month.
|
||
var getDay = function (year, month) {
|
||
return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400);
|
||
};
|
||
}
|
||
|
||
// Internal: Determines if a property is a direct property of the given
|
||
// object. Delegates to the native `Object#hasOwnProperty` method.
|
||
if (!(isProperty = objectProto.hasOwnProperty)) {
|
||
isProperty = function (property) {
|
||
var members = {}, constructor;
|
||
if ((members.__proto__ = null, members.__proto__ = {
|
||
// The *proto* property cannot be set multiple times in recent
|
||
// versions of Firefox and SeaMonkey.
|
||
"toString": 1
|
||
}, members).toString != getClass) {
|
||
// Safari <= 2.0.3 doesn't implement `Object#hasOwnProperty`, but
|
||
// supports the mutable *proto* property.
|
||
isProperty = function (property) {
|
||
// Capture and break the object's prototype chain (see section 8.6.2
|
||
// of the ES 5.1 spec). The parenthesized expression prevents an
|
||
// unsafe transformation by the Closure Compiler.
|
||
var original = this.__proto__, result = property in (this.__proto__ = null, this);
|
||
// Restore the original prototype chain.
|
||
this.__proto__ = original;
|
||
return result;
|
||
};
|
||
} else {
|
||
// Capture a reference to the top-level `Object` constructor.
|
||
constructor = members.constructor;
|
||
// Use the `constructor` property to simulate `Object#hasOwnProperty` in
|
||
// other environments.
|
||
isProperty = function (property) {
|
||
var parent = (this.constructor || constructor).prototype;
|
||
return property in this && !(property in parent && this[property] === parent[property]);
|
||
};
|
||
}
|
||
members = null;
|
||
return isProperty.call(this, property);
|
||
};
|
||
}
|
||
|
||
// Internal: Normalizes the `for...in` iteration algorithm across
|
||
// environments. Each enumerated key is yielded to a `callback` function.
|
||
forEach = function (object, callback) {
|
||
var size = 0, Properties, members, property;
|
||
|
||
// Tests for bugs in the current environment's `for...in` algorithm. The
|
||
// `valueOf` property inherits the non-enumerable flag from
|
||
// `Object.prototype` in older versions of IE, Netscape, and Mozilla.
|
||
(Properties = function () {
|
||
this.valueOf = 0;
|
||
}).prototype.valueOf = 0;
|
||
|
||
// Iterate over a new instance of the `Properties` class.
|
||
members = new Properties();
|
||
for (property in members) {
|
||
// Ignore all properties inherited from `Object.prototype`.
|
||
if (isProperty.call(members, property)) {
|
||
size++;
|
||
}
|
||
}
|
||
Properties = members = null;
|
||
|
||
// Normalize the iteration algorithm.
|
||
if (!size) {
|
||
// A list of non-enumerable properties inherited from `Object.prototype`.
|
||
members = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"];
|
||
// IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable
|
||
// properties.
|
||
forEach = function (object, callback) {
|
||
var isFunction = getClass.call(object) == functionClass, property, length;
|
||
var hasProperty = !isFunction && typeof object.constructor != "function" && objectTypes[typeof object.hasOwnProperty] && object.hasOwnProperty || isProperty;
|
||
for (property in object) {
|
||
// Gecko <= 1.0 enumerates the `prototype` property of functions under
|
||
// certain conditions; IE does not.
|
||
if (!(isFunction && property == "prototype") && hasProperty.call(object, property)) {
|
||
callback(property);
|
||
}
|
||
}
|
||
// Manually invoke the callback for each non-enumerable property.
|
||
for (length = members.length; property = members[--length]; hasProperty.call(object, property) && callback(property));
|
||
};
|
||
} else if (size == 2) {
|
||
// Safari <= 2.0.4 enumerates shadowed properties twice.
|
||
forEach = function (object, callback) {
|
||
// Create a set of iterated properties.
|
||
var members = {}, isFunction = getClass.call(object) == functionClass, property;
|
||
for (property in object) {
|
||
// Store each property name to prevent double enumeration. The
|
||
// `prototype` property of functions is not enumerated due to cross-
|
||
// environment inconsistencies.
|
||
if (!(isFunction && property == "prototype") && !isProperty.call(members, property) && (members[property] = 1) && isProperty.call(object, property)) {
|
||
callback(property);
|
||
}
|
||
}
|
||
};
|
||
} else {
|
||
// No bugs detected; use the standard `for...in` algorithm.
|
||
forEach = function (object, callback) {
|
||
var isFunction = getClass.call(object) == functionClass, property, isConstructor;
|
||
for (property in object) {
|
||
if (!(isFunction && property == "prototype") && isProperty.call(object, property) && !(isConstructor = property === "constructor")) {
|
||
callback(property);
|
||
}
|
||
}
|
||
// Manually invoke the callback for the `constructor` property due to
|
||
// cross-environment inconsistencies.
|
||
if (isConstructor || isProperty.call(object, (property = "constructor"))) {
|
||
callback(property);
|
||
}
|
||
};
|
||
}
|
||
return forEach(object, callback);
|
||
};
|
||
|
||
// Public: Serializes a JavaScript `value` as a JSON string. The optional
|
||
// `filter` argument may specify either a function that alters how object and
|
||
// array members are serialized, or an array of strings and numbers that
|
||
// indicates which properties should be serialized. The optional `width`
|
||
// argument may be either a string or number that specifies the indentation
|
||
// level of the output.
|
||
if (!has("json-stringify")) {
|
||
// Internal: A map of control characters and their escaped equivalents.
|
||
var Escapes = {
|
||
92: "\\\\",
|
||
34: '\\"',
|
||
8: "\\b",
|
||
12: "\\f",
|
||
10: "\\n",
|
||
13: "\\r",
|
||
9: "\\t"
|
||
};
|
||
|
||
// Internal: Converts `value` into a zero-padded string such that its
|
||
// length is at least equal to `width`. The `width` must be <= 6.
|
||
var leadingZeroes = "000000";
|
||
var toPaddedString = function (width, value) {
|
||
// The `|| 0` expression is necessary to work around a bug in
|
||
// Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== "0"`.
|
||
return (leadingZeroes + (value || 0)).slice(-width);
|
||
};
|
||
|
||
// Internal: Double-quotes a string `value`, replacing all ASCII control
|
||
// characters (characters with code unit values between 0 and 31) with
|
||
// their escaped equivalents. This is an implementation of the
|
||
// `Quote(value)` operation defined in ES 5.1 section 15.12.3.
|
||
var unicodePrefix = "\\u00";
|
||
var quote = function (value) {
|
||
var result = '"', index = 0, length = value.length, useCharIndex = !charIndexBuggy || length > 10;
|
||
var symbols = useCharIndex && (charIndexBuggy ? value.split("") : value);
|
||
for (; index < length; index++) {
|
||
var charCode = value.charCodeAt(index);
|
||
// If the character is a control character, append its Unicode or
|
||
// shorthand escape sequence; otherwise, append the character as-is.
|
||
switch (charCode) {
|
||
case 8: case 9: case 10: case 12: case 13: case 34: case 92:
|
||
result += Escapes[charCode];
|
||
break;
|
||
default:
|
||
if (charCode < 32) {
|
||
result += unicodePrefix + toPaddedString(2, charCode.toString(16));
|
||
break;
|
||
}
|
||
result += useCharIndex ? symbols[index] : value.charAt(index);
|
||
}
|
||
}
|
||
return result + '"';
|
||
};
|
||
|
||
// Internal: Recursively serializes an object. Implements the
|
||
// `Str(key, holder)`, `JO(value)`, and `JA(value)` operations.
|
||
var serialize = function (property, object, callback, properties, whitespace, indentation, stack) {
|
||
var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result;
|
||
try {
|
||
// Necessary for host object support.
|
||
value = object[property];
|
||
} catch (exception) {}
|
||
if (typeof value == "object" && value) {
|
||
className = getClass.call(value);
|
||
if (className == dateClass && !isProperty.call(value, "toJSON")) {
|
||
if (value > -1 / 0 && value < 1 / 0) {
|
||
// Dates are serialized according to the `Date#toJSON` method
|
||
// specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15
|
||
// for the ISO 8601 date time string format.
|
||
if (getDay) {
|
||
// Manually compute the year, month, date, hours, minutes,
|
||
// seconds, and milliseconds if the `getUTC*` methods are
|
||
// buggy. Adapted from @Yaffle's `date-shim` project.
|
||
date = floor(value / 864e5);
|
||
for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++);
|
||
for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++);
|
||
date = 1 + date - getDay(year, month);
|
||
// The `time` value specifies the time within the day (see ES
|
||
// 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used
|
||
// to compute `A modulo B`, as the `%` operator does not
|
||
// correspond to the `modulo` operation for negative numbers.
|
||
time = (value % 864e5 + 864e5) % 864e5;
|
||
// The hours, minutes, seconds, and milliseconds are obtained by
|
||
// decomposing the time within the day. See section 15.9.1.10.
|
||
hours = floor(time / 36e5) % 24;
|
||
minutes = floor(time / 6e4) % 60;
|
||
seconds = floor(time / 1e3) % 60;
|
||
milliseconds = time % 1e3;
|
||
} else {
|
||
year = value.getUTCFullYear();
|
||
month = value.getUTCMonth();
|
||
date = value.getUTCDate();
|
||
hours = value.getUTCHours();
|
||
minutes = value.getUTCMinutes();
|
||
seconds = value.getUTCSeconds();
|
||
milliseconds = value.getUTCMilliseconds();
|
||
}
|
||
// Serialize extended years correctly.
|
||
value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) +
|
||
"-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) +
|
||
// Months, dates, hours, minutes, and seconds should have two
|
||
// digits; milliseconds should have three.
|
||
"T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) +
|
||
// Milliseconds are optional in ES 5.0, but required in 5.1.
|
||
"." + toPaddedString(3, milliseconds) + "Z";
|
||
} else {
|
||
value = null;
|
||
}
|
||
} else if (typeof value.toJSON == "function" && ((className != numberClass && className != stringClass && className != arrayClass) || isProperty.call(value, "toJSON"))) {
|
||
// Prototype <= 1.6.1 adds non-standard `toJSON` methods to the
|
||
// `Number`, `String`, `Date`, and `Array` prototypes. JSON 3
|
||
// ignores all `toJSON` methods on these objects unless they are
|
||
// defined directly on an instance.
|
||
value = value.toJSON(property);
|
||
}
|
||
}
|
||
if (callback) {
|
||
// If a replacement function was provided, call it to obtain the value
|
||
// for serialization.
|
||
value = callback.call(object, property, value);
|
||
}
|
||
if (value === null) {
|
||
return "null";
|
||
}
|
||
className = getClass.call(value);
|
||
if (className == booleanClass) {
|
||
// Booleans are represented literally.
|
||
return "" + value;
|
||
} else if (className == numberClass) {
|
||
// JSON numbers must be finite. `Infinity` and `NaN` are serialized as
|
||
// `"null"`.
|
||
return value > -1 / 0 && value < 1 / 0 ? "" + value : "null";
|
||
} else if (className == stringClass) {
|
||
// Strings are double-quoted and escaped.
|
||
return quote("" + value);
|
||
}
|
||
// Recursively serialize objects and arrays.
|
||
if (typeof value == "object") {
|
||
// Check for cyclic structures. This is a linear search; performance
|
||
// is inversely proportional to the number of unique nested objects.
|
||
for (length = stack.length; length--;) {
|
||
if (stack[length] === value) {
|
||
// Cyclic structures cannot be serialized by `JSON.stringify`.
|
||
throw TypeError();
|
||
}
|
||
}
|
||
// Add the object to the stack of traversed objects.
|
||
stack.push(value);
|
||
results = [];
|
||
// Save the current indentation level and indent one additional level.
|
||
prefix = indentation;
|
||
indentation += whitespace;
|
||
if (className == arrayClass) {
|
||
// Recursively serialize array elements.
|
||
for (index = 0, length = value.length; index < length; index++) {
|
||
element = serialize(index, value, callback, properties, whitespace, indentation, stack);
|
||
results.push(element === undef ? "null" : element);
|
||
}
|
||
result = results.length ? (whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : ("[" + results.join(",") + "]")) : "[]";
|
||
} else {
|
||
// Recursively serialize object members. Members are selected from
|
||
// either a user-specified list of property names, or the object
|
||
// itself.
|
||
forEach(properties || value, function (property) {
|
||
var element = serialize(property, value, callback, properties, whitespace, indentation, stack);
|
||
if (element !== undef) {
|
||
// According to ES 5.1 section 15.12.3: "If `gap` {whitespace}
|
||
// is not the empty string, let `member` {quote(property) + ":"}
|
||
// be the concatenation of `member` and the `space` character."
|
||
// The "`space` character" refers to the literal space
|
||
// character, not the `space` {width} argument provided to
|
||
// `JSON.stringify`.
|
||
results.push(quote(property) + ":" + (whitespace ? " " : "") + element);
|
||
}
|
||
});
|
||
result = results.length ? (whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : ("{" + results.join(",") + "}")) : "{}";
|
||
}
|
||
// Remove the object from the traversed object stack.
|
||
stack.pop();
|
||
return result;
|
||
}
|
||
};
|
||
|
||
// Public: `JSON.stringify`. See ES 5.1 section 15.12.3.
|
||
exports.stringify = function (source, filter, width) {
|
||
var whitespace, callback, properties, className;
|
||
if (objectTypes[typeof filter] && filter) {
|
||
if ((className = getClass.call(filter)) == functionClass) {
|
||
callback = filter;
|
||
} else if (className == arrayClass) {
|
||
// Convert the property names array into a makeshift set.
|
||
properties = {};
|
||
for (var index = 0, length = filter.length, value; index < length; value = filter[index++], ((className = getClass.call(value)), className == stringClass || className == numberClass) && (properties[value] = 1));
|
||
}
|
||
}
|
||
if (width) {
|
||
if ((className = getClass.call(width)) == numberClass) {
|
||
// Convert the `width` to an integer and create a string containing
|
||
// `width` number of space characters.
|
||
if ((width -= width % 1) > 0) {
|
||
for (whitespace = "", width > 10 && (width = 10); whitespace.length < width; whitespace += " ");
|
||
}
|
||
} else if (className == stringClass) {
|
||
whitespace = width.length <= 10 ? width : width.slice(0, 10);
|
||
}
|
||
}
|
||
// Opera <= 7.54u2 discards the values associated with empty string keys
|
||
// (`""`) only if they are used directly within an object member list
|
||
// (e.g., `!("" in { "": 1})`).
|
||
return serialize("", (value = {}, value[""] = source, value), callback, properties, whitespace, "", []);
|
||
};
|
||
}
|
||
|
||
// Public: Parses a JSON source string.
|
||
if (!has("json-parse")) {
|
||
var fromCharCode = String.fromCharCode;
|
||
|
||
// Internal: A map of escaped control characters and their unescaped
|
||
// equivalents.
|
||
var Unescapes = {
|
||
92: "\\",
|
||
34: '"',
|
||
47: "/",
|
||
98: "\b",
|
||
116: "\t",
|
||
110: "\n",
|
||
102: "\f",
|
||
114: "\r"
|
||
};
|
||
|
||
// Internal: Stores the parser state.
|
||
var Index, Source;
|
||
|
||
// Internal: Resets the parser state and throws a `SyntaxError`.
|
||
var abort = function () {
|
||
Index = Source = null;
|
||
throw SyntaxError();
|
||
};
|
||
|
||
// Internal: Returns the next token, or `"$"` if the parser has reached
|
||
// the end of the source string. A token may be a string, number, `null`
|
||
// literal, or Boolean literal.
|
||
var lex = function () {
|
||
var source = Source, length = source.length, value, begin, position, isSigned, charCode;
|
||
while (Index < length) {
|
||
charCode = source.charCodeAt(Index);
|
||
switch (charCode) {
|
||
case 9: case 10: case 13: case 32:
|
||
// Skip whitespace tokens, including tabs, carriage returns, line
|
||
// feeds, and space characters.
|
||
Index++;
|
||
break;
|
||
case 123: case 125: case 91: case 93: case 58: case 44:
|
||
// Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at
|
||
// the current position.
|
||
value = charIndexBuggy ? source.charAt(Index) : source[Index];
|
||
Index++;
|
||
return value;
|
||
case 34:
|
||
// `"` delimits a JSON string; advance to the next character and
|
||
// begin parsing the string. String tokens are prefixed with the
|
||
// sentinel `@` character to distinguish them from punctuators and
|
||
// end-of-string tokens.
|
||
for (value = "@", Index++; Index < length;) {
|
||
charCode = source.charCodeAt(Index);
|
||
if (charCode < 32) {
|
||
// Unescaped ASCII control characters (those with a code unit
|
||
// less than the space character) are not permitted.
|
||
abort();
|
||
} else if (charCode == 92) {
|
||
// A reverse solidus (`\`) marks the beginning of an escaped
|
||
// control character (including `"`, `\`, and `/`) or Unicode
|
||
// escape sequence.
|
||
charCode = source.charCodeAt(++Index);
|
||
switch (charCode) {
|
||
case 92: case 34: case 47: case 98: case 116: case 110: case 102: case 114:
|
||
// Revive escaped control characters.
|
||
value += Unescapes[charCode];
|
||
Index++;
|
||
break;
|
||
case 117:
|
||
// `\u` marks the beginning of a Unicode escape sequence.
|
||
// Advance to the first character and validate the
|
||
// four-digit code point.
|
||
begin = ++Index;
|
||
for (position = Index + 4; Index < position; Index++) {
|
||
charCode = source.charCodeAt(Index);
|
||
// A valid sequence comprises four hexdigits (case-
|
||
// insensitive) that form a single hexadecimal value.
|
||
if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) {
|
||
// Invalid Unicode escape sequence.
|
||
abort();
|
||
}
|
||
}
|
||
// Revive the escaped character.
|
||
value += fromCharCode("0x" + source.slice(begin, Index));
|
||
break;
|
||
default:
|
||
// Invalid escape sequence.
|
||
abort();
|
||
}
|
||
} else {
|
||
if (charCode == 34) {
|
||
// An unescaped double-quote character marks the end of the
|
||
// string.
|
||
break;
|
||
}
|
||
charCode = source.charCodeAt(Index);
|
||
begin = Index;
|
||
// Optimize for the common case where a string is valid.
|
||
while (charCode >= 32 && charCode != 92 && charCode != 34) {
|
||
charCode = source.charCodeAt(++Index);
|
||
}
|
||
// Append the string as-is.
|
||
value += source.slice(begin, Index);
|
||
}
|
||
}
|
||
if (source.charCodeAt(Index) == 34) {
|
||
// Advance to the next character and return the revived string.
|
||
Index++;
|
||
return value;
|
||
}
|
||
// Unterminated string.
|
||
abort();
|
||
default:
|
||
// Parse numbers and literals.
|
||
begin = Index;
|
||
// Advance past the negative sign, if one is specified.
|
||
if (charCode == 45) {
|
||
isSigned = true;
|
||
charCode = source.charCodeAt(++Index);
|
||
}
|
||
// Parse an integer or floating-point value.
|
||
if (charCode >= 48 && charCode <= 57) {
|
||
// Leading zeroes are interpreted as octal literals.
|
||
if (charCode == 48 && ((charCode = source.charCodeAt(Index + 1)), charCode >= 48 && charCode <= 57)) {
|
||
// Illegal octal literal.
|
||
abort();
|
||
}
|
||
isSigned = false;
|
||
// Parse the integer component.
|
||
for (; Index < length && ((charCode = source.charCodeAt(Index)), charCode >= 48 && charCode <= 57); Index++);
|
||
// Floats cannot contain a leading decimal point; however, this
|
||
// case is already accounted for by the parser.
|
||
if (source.charCodeAt(Index) == 46) {
|
||
position = ++Index;
|
||
// Parse the decimal component.
|
||
for (; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
|
||
if (position == Index) {
|
||
// Illegal trailing decimal.
|
||
abort();
|
||
}
|
||
Index = position;
|
||
}
|
||
// Parse exponents. The `e` denoting the exponent is
|
||
// case-insensitive.
|
||
charCode = source.charCodeAt(Index);
|
||
if (charCode == 101 || charCode == 69) {
|
||
charCode = source.charCodeAt(++Index);
|
||
// Skip past the sign following the exponent, if one is
|
||
// specified.
|
||
if (charCode == 43 || charCode == 45) {
|
||
Index++;
|
||
}
|
||
// Parse the exponential component.
|
||
for (position = Index; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
|
||
if (position == Index) {
|
||
// Illegal empty exponent.
|
||
abort();
|
||
}
|
||
Index = position;
|
||
}
|
||
// Coerce the parsed value to a JavaScript number.
|
||
return +source.slice(begin, Index);
|
||
}
|
||
// A negative sign may only precede numbers.
|
||
if (isSigned) {
|
||
abort();
|
||
}
|
||
// `true`, `false`, and `null` literals.
|
||
if (source.slice(Index, Index + 4) == "true") {
|
||
Index += 4;
|
||
return true;
|
||
} else if (source.slice(Index, Index + 5) == "false") {
|
||
Index += 5;
|
||
return false;
|
||
} else if (source.slice(Index, Index + 4) == "null") {
|
||
Index += 4;
|
||
return null;
|
||
}
|
||
// Unrecognized token.
|
||
abort();
|
||
}
|
||
}
|
||
// Return the sentinel `$` character if the parser has reached the end
|
||
// of the source string.
|
||
return "$";
|
||
};
|
||
|
||
// Internal: Parses a JSON `value` token.
|
||
var get = function (value) {
|
||
var results, hasMembers;
|
||
if (value == "$") {
|
||
// Unexpected end of input.
|
||
abort();
|
||
}
|
||
if (typeof value == "string") {
|
||
if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") {
|
||
// Remove the sentinel `@` character.
|
||
return value.slice(1);
|
||
}
|
||
// Parse object and array literals.
|
||
if (value == "[") {
|
||
// Parses a JSON array, returning a new JavaScript array.
|
||
results = [];
|
||
for (;; hasMembers || (hasMembers = true)) {
|
||
value = lex();
|
||
// A closing square bracket marks the end of the array literal.
|
||
if (value == "]") {
|
||
break;
|
||
}
|
||
// If the array literal contains elements, the current token
|
||
// should be a comma separating the previous element from the
|
||
// next.
|
||
if (hasMembers) {
|
||
if (value == ",") {
|
||
value = lex();
|
||
if (value == "]") {
|
||
// Unexpected trailing `,` in array literal.
|
||
abort();
|
||
}
|
||
} else {
|
||
// A `,` must separate each array element.
|
||
abort();
|
||
}
|
||
}
|
||
// Elisions and leading commas are not permitted.
|
||
if (value == ",") {
|
||
abort();
|
||
}
|
||
results.push(get(value));
|
||
}
|
||
return results;
|
||
} else if (value == "{") {
|
||
// Parses a JSON object, returning a new JavaScript object.
|
||
results = {};
|
||
for (;; hasMembers || (hasMembers = true)) {
|
||
value = lex();
|
||
// A closing curly brace marks the end of the object literal.
|
||
if (value == "}") {
|
||
break;
|
||
}
|
||
// If the object literal contains members, the current token
|
||
// should be a comma separator.
|
||
if (hasMembers) {
|
||
if (value == ",") {
|
||
value = lex();
|
||
if (value == "}") {
|
||
// Unexpected trailing `,` in object literal.
|
||
abort();
|
||
}
|
||
} else {
|
||
// A `,` must separate each object member.
|
||
abort();
|
||
}
|
||
}
|
||
// Leading commas are not permitted, object property names must be
|
||
// double-quoted strings, and a `:` must separate each property
|
||
// name and value.
|
||
if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") {
|
||
abort();
|
||
}
|
||
results[value.slice(1)] = get(lex());
|
||
}
|
||
return results;
|
||
}
|
||
// Unexpected token encountered.
|
||
abort();
|
||
}
|
||
return value;
|
||
};
|
||
|
||
// Internal: Updates a traversed object member.
|
||
var update = function (source, property, callback) {
|
||
var element = walk(source, property, callback);
|
||
if (element === undef) {
|
||
delete source[property];
|
||
} else {
|
||
source[property] = element;
|
||
}
|
||
};
|
||
|
||
// Internal: Recursively traverses a parsed JSON object, invoking the
|
||
// `callback` function for each value. This is an implementation of the
|
||
// `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2.
|
||
var walk = function (source, property, callback) {
|
||
var value = source[property], length;
|
||
if (typeof value == "object" && value) {
|
||
// `forEach` can't be used to traverse an array in Opera <= 8.54
|
||
// because its `Object#hasOwnProperty` implementation returns `false`
|
||
// for array indices (e.g., `![1, 2, 3].hasOwnProperty("0")`).
|
||
if (getClass.call(value) == arrayClass) {
|
||
for (length = value.length; length--;) {
|
||
update(value, length, callback);
|
||
}
|
||
} else {
|
||
forEach(value, function (property) {
|
||
update(value, property, callback);
|
||
});
|
||
}
|
||
}
|
||
return callback.call(source, property, value);
|
||
};
|
||
|
||
// Public: `JSON.parse`. See ES 5.1 section 15.12.2.
|
||
exports.parse = function (source, callback) {
|
||
var result, value;
|
||
Index = 0;
|
||
Source = "" + source;
|
||
result = get(lex());
|
||
// If a JSON string contains multiple tokens, it is invalid.
|
||
if (lex() != "$") {
|
||
abort();
|
||
}
|
||
// Reset the parser state.
|
||
Index = Source = null;
|
||
return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result;
|
||
};
|
||
}
|
||
}
|
||
|
||
exports["runInContext"] = runInContext;
|
||
return exports;
|
||
}
|
||
|
||
if (freeExports && !isLoader) {
|
||
// Export for CommonJS environments.
|
||
runInContext(root, freeExports);
|
||
} else {
|
||
// Export for web browsers and JavaScript engines.
|
||
var nativeJSON = root.JSON,
|
||
previousJSON = root["JSON3"],
|
||
isRestored = false;
|
||
|
||
var JSON3 = runInContext(root, (root["JSON3"] = {
|
||
// Public: Restores the original value of the global `JSON` object and
|
||
// returns a reference to the `JSON3` object.
|
||
"noConflict": function () {
|
||
if (!isRestored) {
|
||
isRestored = true;
|
||
root.JSON = nativeJSON;
|
||
root["JSON3"] = previousJSON;
|
||
nativeJSON = previousJSON = null;
|
||
}
|
||
return JSON3;
|
||
}
|
||
}));
|
||
|
||
root.JSON = {
|
||
"parse": JSON3.parse,
|
||
"stringify": JSON3.stringify
|
||
};
|
||
}
|
||
|
||
// Export for asynchronous module loaders.
|
||
if (isLoader) {
|
||
define(function () {
|
||
return JSON3;
|
||
});
|
||
}
|
||
}).call(this);
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{}],87:[function(require,module,exports){
|
||
module.exports = toArray
|
||
|
||
function toArray(list, index) {
|
||
var array = []
|
||
|
||
index = index || 0
|
||
|
||
for (var i = index || 0; i < list.length; i++) {
|
||
array[i - index] = list[i]
|
||
}
|
||
|
||
return array
|
||
}
|
||
|
||
},{}],88:[function(require,module,exports){
|
||
(function (global){
|
||
/*! https://mths.be/utf8js v2.0.0 by @mathias */
|
||
;(function(root) {
|
||
|
||
// Detect free variables `exports`
|
||
var freeExports = typeof exports == 'object' && exports;
|
||
|
||
// Detect free variable `module`
|
||
var freeModule = typeof module == 'object' && module &&
|
||
module.exports == freeExports && module;
|
||
|
||
// Detect free variable `global`, from Node.js or Browserified code,
|
||
// and use it as `root`
|
||
var freeGlobal = typeof global == 'object' && global;
|
||
if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
|
||
root = freeGlobal;
|
||
}
|
||
|
||
/*--------------------------------------------------------------------------*/
|
||
|
||
var stringFromCharCode = String.fromCharCode;
|
||
|
||
// Taken from https://mths.be/punycode
|
||
function ucs2decode(string) {
|
||
var output = [];
|
||
var counter = 0;
|
||
var length = string.length;
|
||
var value;
|
||
var extra;
|
||
while (counter < length) {
|
||
value = string.charCodeAt(counter++);
|
||
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
|
||
// high surrogate, and there is a next character
|
||
extra = string.charCodeAt(counter++);
|
||
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
|
||
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
||
} else {
|
||
// unmatched surrogate; only append this code unit, in case the next
|
||
// code unit is the high surrogate of a surrogate pair
|
||
output.push(value);
|
||
counter--;
|
||
}
|
||
} else {
|
||
output.push(value);
|
||
}
|
||
}
|
||
return output;
|
||
}
|
||
|
||
// Taken from https://mths.be/punycode
|
||
function ucs2encode(array) {
|
||
var length = array.length;
|
||
var index = -1;
|
||
var value;
|
||
var output = '';
|
||
while (++index < length) {
|
||
value = array[index];
|
||
if (value > 0xFFFF) {
|
||
value -= 0x10000;
|
||
output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
|
||
value = 0xDC00 | value & 0x3FF;
|
||
}
|
||
output += stringFromCharCode(value);
|
||
}
|
||
return output;
|
||
}
|
||
|
||
function checkScalarValue(codePoint) {
|
||
if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
|
||
throw Error(
|
||
'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
|
||
' is not a scalar value'
|
||
);
|
||
}
|
||
}
|
||
/*--------------------------------------------------------------------------*/
|
||
|
||
function createByte(codePoint, shift) {
|
||
return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
|
||
}
|
||
|
||
function encodeCodePoint(codePoint) {
|
||
if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
|
||
return stringFromCharCode(codePoint);
|
||
}
|
||
var symbol = '';
|
||
if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
|
||
symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
|
||
}
|
||
else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
|
||
checkScalarValue(codePoint);
|
||
symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
|
||
symbol += createByte(codePoint, 6);
|
||
}
|
||
else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
|
||
symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
|
||
symbol += createByte(codePoint, 12);
|
||
symbol += createByte(codePoint, 6);
|
||
}
|
||
symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
|
||
return symbol;
|
||
}
|
||
|
||
function utf8encode(string) {
|
||
var codePoints = ucs2decode(string);
|
||
var length = codePoints.length;
|
||
var index = -1;
|
||
var codePoint;
|
||
var byteString = '';
|
||
while (++index < length) {
|
||
codePoint = codePoints[index];
|
||
byteString += encodeCodePoint(codePoint);
|
||
}
|
||
return byteString;
|
||
}
|
||
|
||
/*--------------------------------------------------------------------------*/
|
||
|
||
function readContinuationByte() {
|
||
if (byteIndex >= byteCount) {
|
||
throw Error('Invalid byte index');
|
||
}
|
||
|
||
var continuationByte = byteArray[byteIndex] & 0xFF;
|
||
byteIndex++;
|
||
|
||
if ((continuationByte & 0xC0) == 0x80) {
|
||
return continuationByte & 0x3F;
|
||
}
|
||
|
||
// If we end up here, it’s not a continuation byte
|
||
throw Error('Invalid continuation byte');
|
||
}
|
||
|
||
function decodeSymbol() {
|
||
var byte1;
|
||
var byte2;
|
||
var byte3;
|
||
var byte4;
|
||
var codePoint;
|
||
|
||
if (byteIndex > byteCount) {
|
||
throw Error('Invalid byte index');
|
||
}
|
||
|
||
if (byteIndex == byteCount) {
|
||
return false;
|
||
}
|
||
|
||
// Read first byte
|
||
byte1 = byteArray[byteIndex] & 0xFF;
|
||
byteIndex++;
|
||
|
||
// 1-byte sequence (no continuation bytes)
|
||
if ((byte1 & 0x80) == 0) {
|
||
return byte1;
|
||
}
|
||
|
||
// 2-byte sequence
|
||
if ((byte1 & 0xE0) == 0xC0) {
|
||
var byte2 = readContinuationByte();
|
||
codePoint = ((byte1 & 0x1F) << 6) | byte2;
|
||
if (codePoint >= 0x80) {
|
||
return codePoint;
|
||
} else {
|
||
throw Error('Invalid continuation byte');
|
||
}
|
||
}
|
||
|
||
// 3-byte sequence (may include unpaired surrogates)
|
||
if ((byte1 & 0xF0) == 0xE0) {
|
||
byte2 = readContinuationByte();
|
||
byte3 = readContinuationByte();
|
||
codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
|
||
if (codePoint >= 0x0800) {
|
||
checkScalarValue(codePoint);
|
||
return codePoint;
|
||
} else {
|
||
throw Error('Invalid continuation byte');
|
||
}
|
||
}
|
||
|
||
// 4-byte sequence
|
||
if ((byte1 & 0xF8) == 0xF0) {
|
||
byte2 = readContinuationByte();
|
||
byte3 = readContinuationByte();
|
||
byte4 = readContinuationByte();
|
||
codePoint = ((byte1 & 0x0F) << 0x12) | (byte2 << 0x0C) |
|
||
(byte3 << 0x06) | byte4;
|
||
if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
|
||
return codePoint;
|
||
}
|
||
}
|
||
|
||
throw Error('Invalid UTF-8 detected');
|
||
}
|
||
|
||
var byteArray;
|
||
var byteCount;
|
||
var byteIndex;
|
||
function utf8decode(byteString) {
|
||
byteArray = ucs2decode(byteString);
|
||
byteCount = byteArray.length;
|
||
byteIndex = 0;
|
||
var codePoints = [];
|
||
var tmp;
|
||
while ((tmp = decodeSymbol()) !== false) {
|
||
codePoints.push(tmp);
|
||
}
|
||
return ucs2encode(codePoints);
|
||
}
|
||
|
||
/*--------------------------------------------------------------------------*/
|
||
|
||
var utf8 = {
|
||
'version': '2.0.0',
|
||
'encode': utf8encode,
|
||
'decode': utf8decode
|
||
};
|
||
|
||
// Some AMD build optimizers, like r.js, check for specific condition patterns
|
||
// like the following:
|
||
if (
|
||
typeof define == 'function' &&
|
||
typeof define.amd == 'object' &&
|
||
define.amd
|
||
) {
|
||
define(function() {
|
||
return utf8;
|
||
});
|
||
} else if (freeExports && !freeExports.nodeType) {
|
||
if (freeModule) { // in Node.js or RingoJS v0.8.0+
|
||
freeModule.exports = utf8;
|
||
} else { // in Narwhal or RingoJS v0.7.0-
|
||
var object = {};
|
||
var hasOwnProperty = object.hasOwnProperty;
|
||
for (var key in utf8) {
|
||
hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]);
|
||
}
|
||
}
|
||
} else { // in Rhino or a web browser
|
||
root.utf8 = utf8;
|
||
}
|
||
|
||
}(this));
|
||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||
},{}],89:[function(require,module,exports){
|
||
'use strict';
|
||
|
||
var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split('')
|
||
, length = 64
|
||
, map = {}
|
||
, seed = 0
|
||
, i = 0
|
||
, prev;
|
||
|
||
/**
|
||
* Return a string representing the specified number.
|
||
*
|
||
* @param {Number} num The number to convert.
|
||
* @returns {String} The string representation of the number.
|
||
* @api public
|
||
*/
|
||
function encode(num) {
|
||
var encoded = '';
|
||
|
||
do {
|
||
encoded = alphabet[num % length] + encoded;
|
||
num = Math.floor(num / length);
|
||
} while (num > 0);
|
||
|
||
return encoded;
|
||
}
|
||
|
||
/**
|
||
* Return the integer value specified by the given string.
|
||
*
|
||
* @param {String} str The string to convert.
|
||
* @returns {Number} The integer value represented by the string.
|
||
* @api public
|
||
*/
|
||
function decode(str) {
|
||
var decoded = 0;
|
||
|
||
for (i = 0; i < str.length; i++) {
|
||
decoded = decoded * length + map[str.charAt(i)];
|
||
}
|
||
|
||
return decoded;
|
||
}
|
||
|
||
/**
|
||
* Yeast: A tiny growing id generator.
|
||
*
|
||
* @returns {String} A unique id.
|
||
* @api public
|
||
*/
|
||
function yeast() {
|
||
var now = encode(+new Date());
|
||
|
||
if (now !== prev) return seed = 0, prev = now;
|
||
return now +'.'+ encode(seed++);
|
||
}
|
||
|
||
//
|
||
// Map each character to its index.
|
||
//
|
||
for (; i < length; i++) map[alphabet[i]] = i;
|
||
|
||
//
|
||
// Expose the `yeast`, `encode` and `decode` functions.
|
||
//
|
||
yeast.encode = encode;
|
||
yeast.decode = decode;
|
||
module.exports = yeast;
|
||
|
||
},{}]},{},[39]);
|