11863 lines
460 KiB
JavaScript
11863 lines
460 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":34,"./jquery/jquery.fake-input":35,"./jquery/jquery.min":36,"./jquery/jquery.resize":37,"./jquery/jquery.ui":38}],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,false)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
|
||
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()
|
||
}
|
||
|
||
},
|
||
|
||
|
||
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).unbind('keydown.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
|
||
},
|
||
|
||
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()
|
||
|
||
|
||
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?data.path+'||||'+data.preArgs.join('||||'):data.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+'.editor')
|
||
}
|
||
}
|
||
|
||
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+'.editor')
|
||
}
|
||
}
|
||
|
||
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+'.editor')
|
||
}
|
||
}
|
||
|
||
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 = e.offsetY
|
||
newData.left= e.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 = e.offsetY
|
||
newData.left= e.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)
|
||
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
|
||
|
||
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')
|
||
|
||
|
||
if (parentLabel) navtabs.append(`<li class="parent"><a><span>${parentLabel}</span></a></li>`)
|
||
|
||
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: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
|
||
|
||
}
|
||
|
||
},{"./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')
|
||
},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()
|
||
})
|
||
|
||
|
||
})
|
||
$('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).unbind('.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/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/led'),
|
||
plot: require('./widgets/plot'),
|
||
visualizer: require('./widgets/visualizer'),
|
||
meter: require('./widgets/meter'),
|
||
text: require('./widgets/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','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/fader":15,"./widgets/knob":16,"./widgets/led":17,"./widgets/meter":18,"./widgets/multifader":19,"./widgets/multipush":20,"./widgets/multitoggle":21,"./widgets/panel":22,"./widgets/plot":23,"./widgets/push":24,"./widgets/rgb":25,"./widgets/strip":26,"./widgets/switch":27,"./widgets/text":28,"./widgets/toggle":29,"./widgets/visualizer":31,"./widgets/xy":32}],15:[function(require,module,exports){
|
||
var utils = require('./utils'),
|
||
clip = utils.clip,
|
||
mapToScale = utils.mapToScale,
|
||
sendOsc = utils.sendOsc
|
||
|
||
module.exports.options = {
|
||
type:'fader',
|
||
id:'auto',
|
||
linkId:'',
|
||
|
||
separator1:'style',
|
||
|
||
label:'auto',
|
||
unit:'',
|
||
left:'auto',
|
||
top:'auto',
|
||
width:'auto',
|
||
height:'auto',
|
||
align:'center',
|
||
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 widget = $(`
|
||
<div class="fader-wrapper-outer">
|
||
<div class="fader-wrapper">
|
||
<div class="fader">
|
||
<div class="gauge"></div>
|
||
<div class="knob"></div>
|
||
<div class="pips"></div>
|
||
</div>
|
||
</div>
|
||
<div class="input"></div>
|
||
</div>
|
||
`),
|
||
gauge = widget.find('.gauge'),
|
||
knob = widget.find('.knob'),
|
||
wrapper = widget.find('.fader-wrapper'),
|
||
fader = widget.find('.fader'),
|
||
pips = widget.find('.pips'),
|
||
input = widget.find('.input').fakeInput({align:'center'}),
|
||
unit = widgetData.unit?' '+widgetData.unit.trim(): '',
|
||
dimension = widgetData.horizontal?'width':'height',
|
||
snap = widgetData.snap,
|
||
logScale = widgetData.logScale,
|
||
roundFactor = Math.pow(10,widgetData.precision)
|
||
|
||
|
||
if (widgetData.horizontal) {
|
||
container.addClass('horizontal')
|
||
delete widgetData.align
|
||
} else {
|
||
container.addClass('align-'+widgetData.align)
|
||
}
|
||
|
||
if (widgetData.compact) container.addClass('compact')
|
||
if (widgetData.noPip) wrapper.addClass('no-pip')
|
||
|
||
gauge.size = 0
|
||
fader.size = 0
|
||
wrapper.size = 0
|
||
widget.value = undefined
|
||
|
||
if (widgetData.meter) {
|
||
var parsewidgets = require('../parser').widgets
|
||
var data = {
|
||
type:'meter',
|
||
id: widgetData.id + '/meter',
|
||
label:false,
|
||
horizontal:widgetData.horizontal,
|
||
range:widgetData.range,
|
||
logScale:widgetData.logScale,
|
||
path:widgetData.path + '/meter',
|
||
preArgs:widgetData.preArgs,
|
||
color:widgetData.color
|
||
}
|
||
var element = parsewidgets([data],fader)
|
||
element[0].classList.add('not-editable')
|
||
}
|
||
|
||
|
||
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)
|
||
}
|
||
|
||
if (!widgetData.noPip&&!widgetData.compact) {
|
||
var pipTexts = {}
|
||
for (k in rangeKeys) {
|
||
pipTexts[rangeKeys[k]]=rangeLabels[k]
|
||
}
|
||
|
||
var pipsInner = ''
|
||
for (var i=0;i<=100;i++) {
|
||
if (pipTexts[i]==undefined) continue
|
||
|
||
var pos = dimension=='height'?'bottom':'left';
|
||
|
||
var piptext = `<span>${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}</span>`
|
||
|
||
if (dimension=='height') piptext = piptext+ piptext
|
||
|
||
var add = `
|
||
<div class="pip val" style="${pos}:${i}%">${piptext}</div>
|
||
`
|
||
pipsInner = pipsInner + add
|
||
}
|
||
pips[0].innerHTML = pipsInner
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
fader.resize(function(){
|
||
fader.size= dimension=='height'?fader.outerHeight():fader.outerWidth()
|
||
wrapper.size = dimension=='height'?wrapper.outerHeight():wrapper.outerWidth()
|
||
widget.updateUi(gauge.size)
|
||
})
|
||
|
||
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?4:.25
|
||
gauge.size = clip(gauge.size+e.originalEvent.wheelDelta/(fader.size*divider),[0,100])
|
||
|
||
widget.updateUi(gauge.size)
|
||
|
||
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])
|
||
}
|
||
})
|
||
|
||
var off = 0
|
||
wrapper.on('draginit',function(e,data,traversing){
|
||
if (snap || traversing) {
|
||
|
||
var d = (dimension=='height')?
|
||
((fader.size-data.offsetY+(wrapper.size-fader.size)/2) * 100 / fader.size):
|
||
(data.offsetX - (wrapper.size-fader.size)/2) * 100 / fader.size
|
||
d = clip(d,[0,100])
|
||
|
||
widget.updateUi(d)
|
||
gauge.size = d
|
||
|
||
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])
|
||
}
|
||
|
||
}
|
||
|
||
off = gauge.size
|
||
|
||
})
|
||
|
||
|
||
wrapper.on('drag',function(e,data){
|
||
|
||
var d = (dimension=='height')?-data.deltaY:data.deltaX
|
||
d = clip(d*100/fader.size+off,[0,100])
|
||
|
||
widget.updateUi(d)
|
||
|
||
gauge.size = d
|
||
|
||
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(v){
|
||
var s = v/100,
|
||
t = dimension=='height'?
|
||
['1,'+s+',1','0,'+-s*fader.size+'px,0']
|
||
:[s+',1,1',s*fader.size+'px,0,0']
|
||
gauge[0].setAttribute('style','transform:scale3d('+t[0]+')')
|
||
knob[0].setAttribute('style','transform:translate3d('+t[1]+')')
|
||
}
|
||
|
||
widget.getValue = function(){
|
||
var h = clip(gauge.size,[0,100])
|
||
for (var i=0;i<rangeKeys.length-1;i++) {
|
||
if (h <= rangeKeys[i+1] && h >= rangeKeys[i]) {
|
||
return mapToScale(h,[rangeKeys[i],rangeKeys[i+1]],[rangeVals[i],rangeVals[i+1]],widgetData.precision,logScale)
|
||
}
|
||
}
|
||
|
||
}
|
||
widget.setValue = function(v,send,sync) {
|
||
if (typeof v != 'number') return
|
||
|
||
var h,
|
||
v=clip(Math.round(v*roundFactor)/roundFactor,[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]],widgetData.precision,logScale,true)
|
||
break
|
||
}
|
||
}
|
||
|
||
widget.updateUi(h)
|
||
|
||
gauge.size = h
|
||
|
||
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:widgetData.target,
|
||
path:widgetData.path,
|
||
precision:widgetData.precision,
|
||
args:args
|
||
})
|
||
}
|
||
|
||
widget.showValue = function(v) {
|
||
input.val(v+unit)
|
||
}
|
||
|
||
input.change(function(){
|
||
widget.setValue(parseFloat(input.val()),true,true)
|
||
})
|
||
|
||
widget.setValue(rangeVals[0])
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"../parser":10,"./utils":30}],16:[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 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(){
|
||
var w = Math.floor(wrapper[0].offsetWidth*.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 = Math.round(v*roundFactor)/roundFactor,
|
||
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],widgetData.precision,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":30}],17:[function(require,module,exports){
|
||
var utils = require('./utils'),
|
||
mapToScale = utils.mapToScale
|
||
|
||
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":30}],18:[function(require,module,exports){
|
||
var utils = require('./utils'),
|
||
clip = utils.clip,
|
||
mapToScale = utils.mapToScale
|
||
|
||
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) level.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":30}],19:[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}],20:[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}],21:[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}],22:[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}],23:[function(require,module,exports){
|
||
var utils = require('./utils'),
|
||
mapToScale = utils.mapToScale
|
||
|
||
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:[],
|
||
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var widget = $(`
|
||
<div class="plot">
|
||
<canvas></canvas>
|
||
</div>
|
||
`),
|
||
canvas = widget.find('canvas'),
|
||
ctx = canvas[0].getContext('2d')
|
||
|
||
widget.data = []
|
||
widget.height = undefined
|
||
widget.width = undefined
|
||
widget.linkedWidgets = []
|
||
widget.visible = false
|
||
widget.textColor = getComputedStyle(document.documentElement).getPropertyValue('--color-text-fade')
|
||
widget.pips = {
|
||
x : {
|
||
min: Math.abs(widgetData.rangeX.min)>=1000?widgetData.rangeX.min/1000+'k':widgetData.rangeX.min,
|
||
max: Math.abs(widgetData.rangeX.max)>=1000?widgetData.rangeX.max/1000+'k':widgetData.rangeX.max
|
||
},
|
||
y : {
|
||
min: Math.abs(widgetData.rangeY.min)>=1000?widgetData.rangeY.min/1000+'k':widgetData.rangeY.min,
|
||
max: Math.abs(widgetData.rangeY.max)>=1000?widgetData.rangeY.max/1000+'k':widgetData.rangeY.max
|
||
}
|
||
}
|
||
|
||
|
||
|
||
if (typeof widgetData.points=='string') {
|
||
|
||
widget.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') {
|
||
widget.linkedWidgets.push(widgetData.points[i][j])
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
canvas.resize(function(){
|
||
var width = canvas.width(),
|
||
height = canvas.height()
|
||
|
||
if (height==100 && width==100) return
|
||
|
||
if (!self.visible) {
|
||
widget.visible = true
|
||
canvas.addClass('visible')
|
||
widget.lineColor = getComputedStyle(widget[0]).getPropertyValue('--color-accent')
|
||
}
|
||
|
||
|
||
widget.height=height
|
||
widget.width=width
|
||
|
||
canvas[0].setAttribute('width',width)
|
||
canvas[0].setAttribute('height',height)
|
||
|
||
widget.fetchValues()
|
||
requestAnimationFrame(widget.draw)
|
||
|
||
})
|
||
|
||
|
||
widget.handleSync = function(e,id,w) {
|
||
if (widget.linkedWidgets.indexOf(id)==-1 || !WIDGETS[id]) return
|
||
widget.fetchValues()
|
||
requestAnimationFrame(widget.draw)
|
||
}
|
||
|
||
$('body').on('sync',widget.handleSync)
|
||
|
||
widget.draw = function(){
|
||
|
||
|
||
ctx.clearRect(0,0,widget.width,widget.height)
|
||
ctx.beginPath()
|
||
|
||
var first = true
|
||
var point = []
|
||
|
||
for (i in widget.data) {
|
||
var newpoint = widget.data[i].length?
|
||
[
|
||
mapToScale(widget.data[i][0],[widgetData.rangeX.min,widgetData.rangeX.max],[15*PXSCALE,widget.width-15*PXSCALE],0,widgetData.logScaleX,true),
|
||
mapToScale(widget.data[i][1],[widgetData.rangeY.min,widgetData.rangeY.max],[widget.height-15*PXSCALE,15*PXSCALE],0,widgetData.logScaleY,true),
|
||
]
|
||
:
|
||
[
|
||
mapToScale(i,[0,widget.data.length-1],[15*PXSCALE,widget.width-15*PXSCALE],0,widgetData.logScaleX,true),
|
||
mapToScale(widget.data[i],[widgetData.rangeY.min,widgetData.rangeY.max],[widget.height-15*PXSCALE,15*PXSCALE],0,widgetData.logScaleY,true),
|
||
]
|
||
|
||
|
||
|
||
if (first) {
|
||
ctx.moveTo(newpoint[0],newpoint[1])
|
||
first = false
|
||
} else {
|
||
ctx.moveTo(point[0],point[1])
|
||
if (widgetData.logScaleX&&!widgetData.logScaleY) {
|
||
ctx.quadraticCurveTo(point[0], newpoint[1], newpoint[0], newpoint[1])
|
||
} else if (widgetData.logScaleY&&!widgetData.logScaleX) {
|
||
ctx.quadraticCurveTo(newpoint[0], point[1], newpoint[0], newpoint[1])
|
||
} else {
|
||
ctx.lineTo(newpoint[0],newpoint[1])
|
||
}
|
||
|
||
}
|
||
ctx.arc(newpoint[0],newpoint[1],1,0,2*Math.PI)
|
||
point = newpoint
|
||
}
|
||
|
||
ctx.lineWidth = 1.5*PXSCALE
|
||
ctx.strokeStyle= widget.lineColor
|
||
ctx.stroke()
|
||
|
||
ctx.font = PXSCALE * 10 + 'px sans-serif'
|
||
ctx.fillStyle = widget.textColor
|
||
|
||
|
||
ctx.textBaseline = "bottom"
|
||
ctx.textAlign = 'left'
|
||
ctx.fillText(widget.pips.x.min,12*PXSCALE,widget.height)
|
||
ctx.textAlign = 'right'
|
||
ctx.fillText(widget.pips.x.max,widget.width-10,widget.height)
|
||
|
||
ctx.save()
|
||
ctx.translate(0, widget.height)
|
||
ctx.rotate(-Math.PI/2)
|
||
|
||
ctx.textBaseline = "top"
|
||
ctx.textAlign = 'left'
|
||
ctx.fillText(widget.pips.y.min,12*PXSCALE,2*PXSCALE)
|
||
ctx.textAlign = 'right'
|
||
ctx.fillText(widget.pips.y.max,widget.height-10*PXSCALE,2*PXSCALE)
|
||
ctx.rotate(Math.PI/2)
|
||
ctx.restore()
|
||
|
||
}
|
||
|
||
|
||
|
||
widget.fetchValues = 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) widget.data = data
|
||
}
|
||
|
||
widget.setValue = function(v) {
|
||
widget.data = v
|
||
requestAnimationFrame(widget.draw)
|
||
}
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"./utils":30}],24:[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="push toggle">
|
||
<div class="light"</div>
|
||
</div>\
|
||
`),
|
||
$document = $(document),
|
||
light = widget.find('.light')[0]
|
||
|
||
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":30}],25:[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],widgetData.precision),
|
||
h = mapToScale(hsb.b,[0,100],[0,100],widgetData.precision),
|
||
hueW = mapToScale(hsb.h,[0,360],[0,100],widgetData.precision)
|
||
|
||
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":30}],26:[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}],27:[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":30}],28:[function(require,module,exports){
|
||
var utils = require('./utils'),
|
||
mapToScale = utils.mapToScale
|
||
|
||
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'
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
var widget = $(`
|
||
<div class="text">
|
||
</div>
|
||
`),
|
||
label = widgetData.label===false?widgetData.id:widgetData.label=='auto'?widgetData.id:widgetData.label=='auto'
|
||
|
||
|
||
if (widgetData.vertical) widget.addClass('vertical')
|
||
|
||
widget.setValue = function(v,send,sync){
|
||
widget.text(v)
|
||
}
|
||
|
||
widget.setValue(label)
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"./utils":30}],29:[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="toggle">
|
||
<div class="light"></div>
|
||
</div>\
|
||
`),
|
||
$document = $(document),
|
||
light = widget.find('.light')[0]
|
||
|
||
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":30}],30:[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])))
|
||
|
||
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
|
||
}
|
||
}
|
||
|
||
},{}],31:[function(require,module,exports){
|
||
var utils = require('./utils'),
|
||
mapToScale = utils.mapToScale,
|
||
clip = utils.clip
|
||
|
||
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:[],
|
||
}
|
||
module.exports.create = function(widgetData,container) {
|
||
|
||
var widget = $(`
|
||
<div class="plot">
|
||
<canvas></canvas>
|
||
</div>
|
||
`),
|
||
canvas = widget.find('canvas'),
|
||
ctx = canvas[0].getContext('2d')
|
||
|
||
widget.height = 0
|
||
widget.width = 0
|
||
widget.visible = false
|
||
widget.textColor = getComputedStyle(document.documentElement).getPropertyValue('--color-text-fade')
|
||
widget.pips = {
|
||
min: Math.abs(widgetData.range.min)>=1000?widgetData.range.min/1000+'k':widgetData.range.min,
|
||
max: Math.abs(widgetData.range.max)>=1000?widgetData.range.max/1000+'k':widgetData.range.max
|
||
}
|
||
widget.length = Math.round(clip(60*widgetData.duration,[8,4096]))
|
||
widget.data = new Array(widget.length)
|
||
widget.value = widgetData.range.min
|
||
|
||
canvas.resize(function(){
|
||
var width = canvas.width(),
|
||
height = canvas.height()
|
||
|
||
if (height==100 && width==100) return
|
||
|
||
if (!self.visible) {
|
||
widget.visible = true
|
||
canvas.addClass('visible')
|
||
widget.lineColor = getComputedStyle(widget[0]).getPropertyValue('--color-accent')
|
||
}
|
||
|
||
widget.height=height
|
||
widget.width=width
|
||
|
||
canvas[0].setAttribute('width',width)
|
||
canvas[0].setAttribute('height',height)
|
||
|
||
requestAnimationFrame(widget.draw)
|
||
|
||
})
|
||
|
||
|
||
widget.handleSync = function(e,id,w) {
|
||
if (widgetData.widgetId!=id || !WIDGETS[id]) return
|
||
widget.startLoop()
|
||
}
|
||
|
||
$('body').on('sync',widget.handleSync)
|
||
|
||
|
||
widget.cancel = false
|
||
widget.loop = false
|
||
|
||
widget.startLoop = function(){
|
||
|
||
if (widget.cancel) clearTimeout(widget.cancel)
|
||
|
||
widget.cancel = setTimeout(function(){
|
||
clearInterval(widget.loop)
|
||
widget.loop = false
|
||
widget.cancel = false
|
||
},1000*widgetData.duration)
|
||
|
||
if (widget.loop) return
|
||
|
||
widget.loop = setInterval(function(){
|
||
widget.fetchValue()
|
||
widget.draw()
|
||
},1000*widgetData.duration/widget.length)
|
||
}
|
||
|
||
|
||
widget.draw = function(){
|
||
ctx.clearRect(0,0,widget.width,widget.height)
|
||
ctx.beginPath()
|
||
|
||
var first = true
|
||
var point = []
|
||
|
||
for (var i=widget.length-1;i>=0;i=i-1) {
|
||
var newpoint = [
|
||
mapToScale(i,[0,widget.length-1],[15*PXSCALE,widget.width-15*PXSCALE],1),
|
||
mapToScale(widget.data[i],[widgetData.range.min,widgetData.range.max],[widget.height-15*PXSCALE,15*PXSCALE],1,widgetData.logScale,true),
|
||
]
|
||
if (first) {
|
||
ctx.moveTo(newpoint[0],newpoint[1])
|
||
first = false
|
||
} else {
|
||
if (widgetData.logScale) {
|
||
ctx.quadraticCurveTo(newpoint[0], point[1], newpoint[0], newpoint[1])
|
||
} else {
|
||
ctx.lineTo(newpoint[0],newpoint[1])
|
||
}
|
||
|
||
}
|
||
point = newpoint
|
||
}
|
||
|
||
ctx.lineWidth = 1.5*PXSCALE
|
||
ctx.strokeStyle= widget.lineColor
|
||
ctx.stroke()
|
||
|
||
ctx.font = PXSCALE * 10 + 'px sans-serif'
|
||
ctx.fillStyle = widget.textColor
|
||
|
||
|
||
ctx.save()
|
||
ctx.translate(0, widget.height)
|
||
ctx.rotate(-Math.PI/2)
|
||
|
||
ctx.textBaseline = "top"
|
||
ctx.textAlign = 'left'
|
||
ctx.fillText(widget.pips.min,12*PXSCALE,2*PXSCALE)
|
||
ctx.textAlign = 'right'
|
||
ctx.fillText(widget.pips.max,widget.height-10*PXSCALE,2*PXSCALE)
|
||
ctx.rotate(Math.PI/2)
|
||
ctx.restore()
|
||
|
||
}
|
||
|
||
|
||
|
||
widget.fetchValue = function(){
|
||
var id = widgetData.widgetId
|
||
|
||
if (typeof id == 'string' && WIDGETS[id]) {
|
||
var v = WIDGETS[id][WIDGETS[id].length-1].getValue()
|
||
widget.data.push(v)
|
||
widget.value = v
|
||
} else {
|
||
widget.data.push(widget.value)
|
||
}
|
||
|
||
widget.data.splice(0,1)
|
||
|
||
}
|
||
|
||
widget.setValue = function(v) {
|
||
widget.value = v
|
||
widget.startLoop()
|
||
}
|
||
|
||
return widget
|
||
}
|
||
|
||
},{"./utils":30}],32:[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],widgetData.precision,logScaleX,true)
|
||
h = mapToScale(v[1],[range.y.min,range.y.max],[0,100],widgetData.precision,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":30}],33:[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":40}],34:[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.drag',stop:'touchend.drag touchcancel.drag',move:'touchmove.drag',touch:true},
|
||
mouse:{start:'mousedown.drag',stop:'mouseup.drag',move:'mousemove.drag',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,
|
||
isPointerDown = false,
|
||
traversing = false
|
||
|
||
|
||
|
||
|
||
$this.on(events.mouse.start,function(e){
|
||
// e.stopPropagation()
|
||
|
||
// 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,function(e){
|
||
e.stopPropagation()
|
||
|
||
if (!isPointerDown) return
|
||
|
||
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 || TRAVERSING) {
|
||
target = $(e.target)
|
||
e.preventDefault()
|
||
target.triggerHandler('draginit',[e,e.originalEvent.traversing])
|
||
} else {
|
||
target.triggerHandler('drag',[e,e.originalEvent.traversing])
|
||
}
|
||
|
||
previousEvent = e
|
||
})
|
||
|
||
$document.on(events.mouse.stop,function(e){
|
||
e.stopPropagation()
|
||
|
||
// ignore mouse event when fired by a simulated touch event
|
||
if (e.originalEvent.sourceCapabilities.firesTouchEvents) return
|
||
|
||
if (!isPointerDown) 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)
|
||
$document.off(events.mouse.stop)
|
||
$document.off('mouseout')
|
||
})
|
||
|
||
|
||
$document.on('mouseout',function(e){
|
||
if (e.originalEvent.traversing || TRAVERSING) {
|
||
e.stopPropagation()
|
||
|
||
if (!isPointerDown) 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])
|
||
|
||
previousEvent = e
|
||
|
||
}
|
||
})
|
||
|
||
})
|
||
|
||
|
||
// multi touch hanlder
|
||
|
||
var targets = {},
|
||
previousTouches = {}
|
||
|
||
$this.on(events.touch.start,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])
|
||
|
||
}
|
||
|
||
$document.on(events.touch.move,function(e){
|
||
// e.stopPropagation()
|
||
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 || 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 || 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 (this.contains(targets[id][0])) targets[id].triggerHandler('draginit',[touch,e.originalEvent.traversing])
|
||
|
||
} else {
|
||
|
||
targets[id].triggerHandler('drag',[touch,e.originalEvent.traversing])
|
||
|
||
}
|
||
|
||
previousTouches[id] = touch
|
||
|
||
}
|
||
|
||
})
|
||
|
||
$document.on(events.touch.stop,function(e){
|
||
e.stopPropagation()
|
||
|
||
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]
|
||
|
||
}
|
||
|
||
$document.off(events.touch.move)
|
||
$document.off(events.touch.stop)
|
||
|
||
})
|
||
|
||
})
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
var makeEventTraversing = function(e){
|
||
e.traversing=true
|
||
}
|
||
|
||
|
||
$.fn.enableTraversingGestures = function() {
|
||
|
||
var self = this[0]
|
||
|
||
var down = function(){
|
||
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.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(){
|
||
$(e.originalEvent.changedTouches[0].target).trigger('fake-right-click',e.originalEvent.changedTouches[0])
|
||
touchTapTimer = false
|
||
},600)
|
||
} else {
|
||
clearTouchTapTimer()
|
||
}
|
||
})
|
||
|
||
document.addEventListener(events.touch.move,clearTouchTapTimer)
|
||
document.addEventListener(events.touch.stop,clearTouchTapTimer)
|
||
|
||
$document.on('contextmenu',function(){return false})
|
||
|
||
})(jQuery)
|
||
|
||
},{}],35:[function(require,module,exports){
|
||
var startEvent = 'ontouchstart' in window ?'touchstart':'mousedown'
|
||
;(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.visible = false
|
||
|
||
|
||
self.attr('tabindex',"0")
|
||
|
||
canvas.resize(function(e){
|
||
e.stopPropagation()
|
||
|
||
var width = canvas.width(),
|
||
height = canvas.height()
|
||
|
||
if (height==100 && width==100) return
|
||
|
||
if (!self.visible) {
|
||
self.visible = true
|
||
canvas.addClass('visible')
|
||
}
|
||
|
||
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 * 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('click 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(startEvent+'.fakeInput',function(){
|
||
i.blur()
|
||
})
|
||
|
||
})
|
||
|
||
return self
|
||
|
||
}
|
||
})(jQuery)
|
||
|
||
},{}],36:[function(require,module,exports){
|
||
/*! jQuery v2.1.4 | (c) 2005, 2015 jQuery Foundation, Inc. | jquery.org/license */
|
||
!function(a,b){"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){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.4",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.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(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.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||n.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&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)+1>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},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?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.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,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b="length"in a&&a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=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=1<<31,D={}.hasOwnProperty,E=[],F=E.pop,G=E.push,H=E.push,I=E.slice,J=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},K="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",L="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",N=M.replace("w","w#"),O="\\["+L+"*("+M+")(?:"+L+"*([*^$|!~]?=)"+L+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+N+"))|)"+L+"*\\]",P=":("+M+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+O+")*)|.*)\\)|)",Q=new RegExp(L+"+","g"),R=new RegExp("^"+L+"+|((?:^|[^\\\\])(?:\\\\.)*)"+L+"+$","g"),S=new RegExp("^"+L+"*,"+L+"*"),T=new RegExp("^"+L+"*([>+~]|"+L+")"+L+"*"),U=new RegExp("="+L+"*([^\\]'\"]*?)"+L+"*\\]","g"),V=new RegExp(P),W=new RegExp("^"+N+"$"),X={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+O),PSEUDO:new RegExp("^"+P),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+L+"*(even|odd|(([+-]|)(\\d*)n|)"+L+"*(?:([+-]|)"+L+"*(\\d+)|))"+L+"*\\)|)","i"),bool:new RegExp("^(?:"+K+")$","i"),needsContext:new RegExp("^"+L+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+L+"*((?:-\\d)?\\d*)"+L+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,aa=/[+~]/,ba=/'|\\/g,ca=new RegExp("\\\\([\\da-f]{1,6}"+L+"?|("+L+")|.)","ig"),da=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)},ea=function(){m()};try{H.apply(E=I.call(v.childNodes),v.childNodes),E[v.childNodes.length].nodeType}catch(fa){H={apply:E.length?function(a,b){G.apply(a,I.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,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],k=b.nodeType,"string"!=typeof a||!a||1!==k&&9!==k&&11!==k)return d;if(!e&&p){if(11!==k&&(f=_.exec(a)))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return H.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName)return H.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=1!==k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(ba,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+ra(o[l]);w=aa.test(a)&&pa(b.parentNode)||b,x=o.join(",")}if(x)try{return H.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$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("div");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=a.length;while(e--)d.attrHandle[c[e]]=b}function la(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||C)-(~a.sourceIndex||C);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 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 pa(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=g.documentElement,e=g.defaultView,e&&e!==e.top&&(e.addEventListener?e.addEventListener("unload",ea,!1):e.attachEvent&&e.attachEvent("onunload",ea)),p=!f(g),c.attributes=ja(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ja(function(a){return a.appendChild(g.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(g.getElementsByClassName),c.getById=ja(function(a){return o.appendChild(a).id=u,!g.getElementsByName||!g.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.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(ca,da);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(ca,da);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 p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(g.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML="<a id='"+u+"'></a><select id='"+u+"-\f]' msallowcapture=''><option selected=''></option></select>",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+L+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+L+"*(?:value|"+K+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),ja(function(a){var b=g.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+L+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ja(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",P)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.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===g||a.ownerDocument===v&&t(v,a)?-1:b===g||b.ownerDocument===v&&t(v,b)?1:k?J(k,a)-J(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,h=[a],i=[b];if(!e||!f)return a===g?-1:b===g?1:e?-1:f?1:k?J(k,a)-J(k,b):0;if(e===f)return la(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?la(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},g):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(U,"='$1']"),!(!c.matchesSelector||!p||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&&D.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.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:X,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(ca,da),a[3]=(a[3]||a[4]||a[5]||"").replace(ca,da),"~="===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 X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.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(ca,da).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("(^|"+L+")"+a+"("+L+"|$)"))&&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(Q," ")+" ").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;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/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=J(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(R,"$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(ca,da),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ia(function(a){return W.test(a||"")||ga.error("unsupported lang: "+a),a=a.replace(ca,da).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:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!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 Z.test(a.nodeName)},input:function(a){return Y.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:oa(function(){return[0]}),last:oa(function(a,b){return[b-1]}),eq:oa(function(a,b,c){return[0>c?c+b:c]}),even:oa(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:oa(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:oa(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:oa(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 qa(){}qa.prototype=d.filters=d.pseudos,d.setFilters=new qa,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=S.exec(h)))&&(e&&(h=h.slice(e[0].length)||h),i.push(f=[])),c=!1,(e=T.exec(h))&&(c=e.shift(),f.push({value:c,type:e[0].replace(R," ")}),h=h.slice(c.length));for(g in d.filter)!(e=X[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 ra(a){for(var b=0,c=a.length,d="";c>b;b++)d+=a[b].value;return d}function sa(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function ta(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 ua(a,b,c){for(var d=0,e=b.length;e>d;d++)ga(a,b[d],c);return c}function va(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 wa(a,b,c,d,e,f){return d&&!d[u]&&(d=wa(d)),e&&!e[u]&&(e=wa(e,f)),ia(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||ua(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:va(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=va(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?J(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=va(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):H.apply(g,r)})}function xa(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=sa(function(a){return a===b},h,!0),l=sa(function(a){return J(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=[sa(ta(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 wa(i>1&&ta(m),i>1&&ra(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&xa(a.slice(i,e)),f>e&&xa(a=a.slice(e)),f>e&&ra(a))}m.push(c)}return ta(m)}function ya(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=F.call(i));s=va(s)}H.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&ga.uniqueSort(i)}return k&&(w=v,j=t),r};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=xa(b[c]),f[u]?d.push(f):e.push(f);f=A(a,ya(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(ca,da),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.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(ca,da),aa.test(j[0].type)&&pa(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&ra(j),!a)return H.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,aa.test(a)&&pa(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("div"))}),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(K,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);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(a,b||this.context):0;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&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?n.extend(a,d):d}},e={};return d.pipe=d.then,n.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&n.isFunction(a.promise)?e:0,g=1===f?a:n.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&n.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(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};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+K.uid++}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){
|
||
return M.access(a,b,c)},removeData:function(a,b){M.remove(a,b)},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.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=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.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 L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length<c?n.queue(this[0],a):void 0===b?this:this.each(function(){var c=n.queue(this,a,b);n._queueHooks(this,a),"fx"===a&&"inprogress"!==c[0]&&n.dequeue(this,a)})},dequeue:function(a){return this.each(function(){n.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,b){var c,d=1,e=n.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=L.get(f[g],a+"queueHooks"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var Q=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,R=["Top","Right","Bottom","Left"],S=function(a,b){return a=b||a,"none"===n.css(a,"display")||!n.contains(a.ownerDocument,a)},T=/^(?:checkbox|radio)$/i;!function(){var a=l.createDocumentFragment(),b=a.appendChild(l.createElement("div")),c=l.createElement("input");c.setAttribute("type","radio"),c.setAttribute("checked","checked"),c.setAttribute("name","t"),b.appendChild(c),k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML="<textarea>x</textarea>",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),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),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==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,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(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?n(e,this).index(i)>=0:n.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},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){return null==a.which&&(a.which=null!=b.charCode?b.charCode:b.keyCode),a}},mouseHooks:{props:"button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,b){var c,d,e,f=b.button;return null==a.pageX&&null!=b.clientX&&(c=a.target.ownerDocument||l,d=c.documentElement,e=c.body,a.pageX=b.clientX+(d&&d.scrollLeft||e&&e.scrollLeft||0)-(d&&d.clientLeft||e&&e.clientLeft||0),a.pageY=b.clientY+(d&&d.scrollTop||e&&e.scrollTop||0)-(d&&d.clientTop||e&&e.clientTop||0)),a.which||void 0===f||(a.which=1&f?1:2&f?3:4&f?2:0),a}},fix:function(a){if(a[n.expando])return a;var b,c,d,e=a.type,f=a,g=this.fixHooks[e];g||(this.fixHooks[e]=g=W.test(e)?this.mouseHooks:V.test(e)?this.keyHooks:{}),d=g.props?this.props.concat(g.props):this.props,a=new n.Event(f),b=d.length;while(b--)c=d[b],a[c]=f[c];return a.target||(a.target=l),3===a.target.nodeType&&(a.target=a.target.parentNode),g.filter?g.filter(a,f):a},special:{load:{noBubble:!0},focus:{trigger:function(){return this!==_()&&this.focus?(this.focus(),!1):void 0},delegateType:"focusin"},blur:{trigger:function(){return this===_()&&this.blur?(this.blur(),!1):void 0},delegateType:"focusout"},click:{trigger:function(){return"checkbox"===this.type&&this.click&&n.nodeName(this,"input")?(this.click(),!1):void 0},_default:function(a){return n.nodeName(a.target,"a")}},beforeunload:{postDispatch:function(a){void 0!==a.result&&a.originalEvent&&(a.originalEvent.returnValue=a.result)}}},simulate:function(a,b,c,d){var e=n.extend(new n.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?n.event.trigger(e,null,b):n.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},n.removeEvent=function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)},n.Event=function(a,b){return this instanceof n.Event?(a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||void 0===a.defaultPrevented&&a.returnValue===!1?Z:$):this.type=a,b&&n.extend(this,b),this.timeStamp=a&&a.timeStamp||n.now(),void(this[n.expando]=!0)):new n.Event(a,b)},n.Event.prototype={isDefaultPrevented:$,isPropagationStopped:$,isImmediatePropagationStopped:$,preventDefault:function(){var a=this.originalEvent;this.isDefaultPrevented=Z,a&&a.preventDefault&&a.preventDefault()},stopPropagation:function(){var a=this.originalEvent;this.isPropagationStopped=Z,a&&a.stopPropagation&&a.stopPropagation()},stopImmediatePropagation:function(){var a=this.originalEvent;this.isImmediatePropagationStopped=Z,a&&a.stopImmediatePropagation&&a.stopImmediatePropagation(),this.stopPropagation()}},n.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(a,b){n.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj;return(!e||e!==d&&!n.contains(d,e))&&(a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b),c}}}),k.focusinBubbles||n.each({focus:"focusin",blur:"focusout"},function(a,b){var c=function(a){n.event.simulate(b,a.target,n.event.fix(a),!0)};n.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=L.access(d,b);e||d.addEventListener(a,c,!0),L.access(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=L.access(d,b)-1;e?L.access(d,b,e):(d.removeEventListener(a,c,!0),L.remove(d,b))}}}),n.fn.extend({on:function(a,b,c,d,e){var f,g;if("object"==typeof a){"string"!=typeof b&&(c=c||b,b=void 0);for(g in a)this.on(g,b,c,a[g],e);return this}if(null==c&&null==d?(d=b,c=b=void 0):null==d&&("string"==typeof b?(d=c,c=void 0):(d=c,c=b,b=void 0)),d===!1)d=$;else if(!d)return this;return 1===e&&(f=d,d=function(a){return n().off(a),f.apply(this,arguments)},d.guid=f.guid||(f.guid=n.guid++)),this.each(function(){n.event.add(this,a,d,c,b)})},one:function(a,b,c,d){return this.on(a,b,c,d,1)},off:function(a,b,c){var d,e;if(a&&a.preventDefault&&a.handleObj)return d=a.handleObj,n(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=$),this.each(function(){n.event.remove(this,a,c,b)})},trigger:function(a,b){return this.each(function(){n.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];return c?n.event.trigger(a,b,c,!0):void 0}});var aa=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,ba=/<([\w:]+)/,ca=/<|&#?\w+;/,da=/<(?:script|style|link)/i,ea=/checked\s*(?:[^=]|=\s*.checked.)/i,fa=/^$|\/(?:java|ecma)script/i,ga=/^true\/(.*)/,ha=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,ia={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,"",""]};ia.optgroup=ia.option,ia.tbody=ia.tfoot=ia.colgroup=ia.caption=ia.thead,ia.th=ia.td;function ja(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function ka(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function la(a){var b=ga.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function ma(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function na(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.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++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function oa(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pa(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=oa(h),f=oa(a),d=0,e=f.length;e>d;d++)pa(f[d],g[d]);if(b)if(c)for(f=f||oa(a),g=g||oa(h),d=0,e=f.length;e>d;d++)na(f[d],g[d]);else na(a,h);return g=oa(h,"script"),g.length>0&&ma(g,!i&&oa(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(ca.test(e)){f=f||k.appendChild(b.createElement("div")),g=(ba.exec(e)||["",""])[1].toLowerCase(),h=ia[g]||ia._default,f.innerHTML=h[1]+e.replace(aa,"<$1></$2>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=oa(k.appendChild(e),"script"),i&&ma(f),c)){j=0;while(e=f[j++])fa.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.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 this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=ja(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=ja(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(oa(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&ma(oa(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(oa(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 n.clone(this,a,b)})},html:function(a){return J(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&&!da.test(a)&&!ia[(ba.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(aa,"<$1></$2>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(oa(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(oa(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&ea.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(oa(c,"script"),ka),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,oa(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,la),j=0;g>j;j++)h=f[j],fa.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(ha,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qa,ra={};function sa(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function ta(a){var b=l,c=ra[a];return c||(c=sa(a,b),"none"!==c&&c||(qa=(qa||n("<iframe frameborder='0' width='0' height='0'/>")).appendTo(b.documentElement),b=qa[0].contentDocument,b.write(),b.close(),c=sa(a,b),qa.detach()),ra[a]=c),c}var ua=/^margin/,va=new RegExp("^("+Q+")(?!px)[a-z%]+$","i"),wa=function(b){return b.ownerDocument.defaultView.opener?b.ownerDocument.defaultView.getComputedStyle(b,null):a.getComputedStyle(b,null)};function xa(a,b,c){var d,e,f,g,h=a.style;return c=c||wa(a),c&&(g=c.getPropertyValue(b)||c[b]),c&&(""!==g||n.contains(a.ownerDocument,a)||(g=n.style(a,b)),va.test(g)&&ua.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 ya(a,b){return{get:function(){return a()?void delete this.get:(this.get=b).apply(this,arguments)}}}!function(){var b,c,d=l.documentElement,e=l.createElement("div"),f=l.createElement("div");if(f.style){f.style.backgroundClip="content-box",f.cloneNode(!0).style.backgroundClip="",k.clearCloneStyle="content-box"===f.style.backgroundClip,e.style.cssText="border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;position:absolute",e.appendChild(f);function g(){f.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;display:block;margin-top:1%;top:1%;border:1px;padding:1px;width:4px;position:absolute",f.innerHTML="",d.appendChild(e);var g=a.getComputedStyle(f,null);b="1%"!==g.top,c="4px"===g.width,d.removeChild(e)}a.getComputedStyle&&n.extend(k,{pixelPosition:function(){return g(),b},boxSizingReliable:function(){return null==c&&g(),c},reliableMarginRight:function(){var b,c=f.appendChild(l.createElement("div"));return c.style.cssText=f.style.cssText="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;margin:0;border:0;padding:0",c.style.marginRight=c.style.width="0",f.style.width="1px",d.appendChild(e),b=!parseFloat(a.getComputedStyle(c,null).marginRight),d.removeChild(e),f.removeChild(c),b}})}}(),n.swap=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};var za=/^(none|table(?!-c[ea]).+)/,Aa=new RegExp("^("+Q+")(.*)$","i"),Ba=new RegExp("^([+-])=("+Q+")","i"),Ca={position:"absolute",visibility:"hidden",display:"block"},Da={letterSpacing:"0",fontWeight:"400"},Ea=["Webkit","O","Moz","ms"];function Fa(a,b){if(b in a)return b;var c=b[0].toUpperCase()+b.slice(1),d=b,e=Ea.length;while(e--)if(b=Ea[e]+c,b in a)return b;return d}function Ga(a,b,c){var d=Aa.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||"px"):b}function Ha(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+=n.css(a,c+R[f],!0,e)),d?("content"===c&&(g-=n.css(a,"padding"+R[f],!0,e)),"margin"!==c&&(g-=n.css(a,"border"+R[f]+"Width",!0,e))):(g+=n.css(a,"padding"+R[f],!0,e),"padding"!==c&&(g+=n.css(a,"border"+R[f]+"Width",!0,e)));return g}function Ia(a,b,c){var d=!0,e="width"===b?a.offsetWidth:a.offsetHeight,f=wa(a),g="border-box"===n.css(a,"boxSizing",!1,f);if(0>=e||null==e){if(e=xa(a,b,f),(0>e||null==e)&&(e=a.style[b]),va.test(e))return e;d=g&&(k.boxSizingReliable()||e===a.style[b]),e=parseFloat(e)||0}return e+Ha(a,b,c||(g?"border":"content"),d,f)+"px"}function Ja(a,b){for(var c,d,e,f=[],g=0,h=a.length;h>g;g++)d=a[g],d.style&&(f[g]=L.get(d,"olddisplay"),c=d.style.display,b?(f[g]||"none"!==c||(d.style.display=""),""===d.style.display&&S(d)&&(f[g]=L.access(d,"olddisplay",ta(d.nodeName)))):(e=S(d),"none"===c&&e||L.set(d,"olddisplay",e?c:n.css(d,"display"))));for(g=0;h>g;g++)d=a[g],d.style&&(b&&"none"!==d.style.display&&""!==d.style.display||(d.style.display=b?f[g]||"":"none"));return a}n.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=xa(a,"opacity");return""===c?"1":c}}}},cssNumber:{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=n.camelCase(b),i=a.style;return b=n.cssProps[h]||(n.cssProps[h]=Fa(i,h)),g=n.cssHooks[b]||n.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=Ba.exec(c))&&(c=(e[1]+1)*e[2]+parseFloat(n.css(a,b)),f="number"),null!=c&&c===c&&("number"!==f||n.cssNumber[h]||(c+="px"),k.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=n.camelCase(b);return b=n.cssProps[h]||(n.cssProps[h]=Fa(a.style,h)),g=n.cssHooks[b]||n.cssHooks[h],g&&"get"in g&&(e=g.get(a,!0,c)),void 0===e&&(e=xa(a,b,d)),"normal"===e&&b in Da&&(e=Da[b]),""===c||c?(f=parseFloat(e),c===!0||n.isNumeric(f)?f||0:e):e}}),n.each(["height","width"],function(a,b){n.cssHooks[b]={get:function(a,c,d){return c?za.test(n.css(a,"display"))&&0===a.offsetWidth?n.swap(a,Ca,function(){return Ia(a,b,d)}):Ia(a,b,d):void 0},set:function(a,c,d){var e=d&&wa(a);return Ga(a,c,d?Ha(a,b,d,"border-box"===n.css(a,"boxSizing",!1,e),e):0)}}}),n.cssHooks.marginRight=ya(k.reliableMarginRight,function(a,b){return b?n.swap(a,{display:"inline-block"},xa,[a,"marginRight"]):void 0}),n.each({margin:"",padding:"",border:"Width"},function(a,b){n.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f="string"==typeof c?c.split(" "):[c];4>d;d++)e[a+R[d]+b]=f[d]||f[d-2]||f[0];return e}},ua.test(a)||(n.cssHooks[a+b].set=Ga)}),n.fn.extend({css:function(a,b){return J(this,function(a,b,c){var d,e,f={},g=0;if(n.isArray(b)){for(d=wa(a),e=b.length;e>g;g++)f[b[g]]=n.css(a,b[g],!1,d);return f}return void 0!==c?n.style(a,b,c):n.css(a,b)},a,b,arguments.length>1)},show:function(){return Ja(this,!0)},hide:function(){return Ja(this)},toggle:function(a){return"boolean"==typeof a?a?this.show():this.hide():this.each(function(){S(this)?n(this).show():n(this).hide()})}});function Ka(a,b,c,d,e){return new Ka.prototype.init(a,b,c,d,e)}n.Tween=Ka,Ka.prototype={constructor:Ka,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||"swing",this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(n.cssNumber[c]?"":"px")},cur:function(){var a=Ka.propHooks[this.prop];return a&&a.get?a.get(this):Ka.propHooks._default.get(this)},run:function(a){var b,c=Ka.propHooks[this.prop];return this.options.duration?this.pos=b=n.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):this.pos=b=a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):Ka.propHooks._default.set(this),this}},Ka.prototype.init.prototype=Ka.prototype,Ka.propHooks={_default:{get:function(a){var b;return null==a.elem[a.prop]||a.elem.style&&null!=a.elem.style[a.prop]?(b=n.css(a.elem,a.prop,""),b&&"auto"!==b?b:0):a.elem[a.prop]},set:function(a){n.fx.step[a.prop]?n.fx.step[a.prop](a):a.elem.style&&(null!=a.elem.style[n.cssProps[a.prop]]||n.cssHooks[a.prop])?n.style(a.elem,a.prop,a.now+a.unit):a.elem[a.prop]=a.now}}},Ka.propHooks.scrollTop=Ka.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},n.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2}},n.fx=Ka.prototype.init,n.fx.step={};var La,Ma,Na=/^(?:toggle|show|hide)$/,Oa=new RegExp("^(?:([+-])=|)("+Q+")([a-z%]*)$","i"),Pa=/queueHooks$/,Qa=[Va],Ra={"*":[function(a,b){var c=this.createTween(a,b),d=c.cur(),e=Oa.exec(b),f=e&&e[3]||(n.cssNumber[a]?"":"px"),g=(n.cssNumber[a]||"px"!==f&&+d)&&Oa.exec(n.css(c.elem,a)),h=1,i=20;if(g&&g[3]!==f){f=f||g[3],e=e||[],g=+d||1;do h=h||".5",g/=h,n.style(c.elem,a,g+f);while(h!==(h=c.cur()/d)&&1!==h&&--i)}return e&&(g=c.start=+g||+d||0,c.unit=f,c.end=e[1]?g+(e[1]+1)*e[2]:+e[2]),c}]};function Sa(){return setTimeout(function(){La=void 0}),La=n.now()}function Ta(a,b){var c,d=0,e={height:a};for(b=b?1:0;4>d;d+=2-b)c=R[d],e["margin"+c]=e["padding"+c]=a;return b&&(e.opacity=e.width=a),e}function Ua(a,b,c){for(var d,e=(Ra[b]||[]).concat(Ra["*"]),f=0,g=e.length;g>f;f++)if(d=e[f].call(c,b,a))return d}function Va(a,b,c){var d,e,f,g,h,i,j,k,l=this,m={},o=a.style,p=a.nodeType&&S(a),q=L.get(a,"fxshow");c.queue||(h=n._queueHooks(a,"fx"),null==h.unqueued&&(h.unqueued=0,i=h.empty.fire,h.empty.fire=function(){h.unqueued||i()}),h.unqueued++,l.always(function(){l.always(function(){h.unqueued--,n.queue(a,"fx").length||h.empty.fire()})})),1===a.nodeType&&("height"in b||"width"in b)&&(c.overflow=[o.overflow,o.overflowX,o.overflowY],j=n.css(a,"display"),k="none"===j?L.get(a,"olddisplay")||ta(a.nodeName):j,"inline"===k&&"none"===n.css(a,"float")&&(o.display="inline-block")),c.overflow&&(o.overflow="hidden",l.always(function(){o.overflow=c.overflow[0],o.overflowX=c.overflow[1],o.overflowY=c.overflow[2]}));for(d in b)if(e=b[d],Na.exec(e)){if(delete b[d],f=f||"toggle"===e,e===(p?"hide":"show")){if("show"!==e||!q||void 0===q[d])continue;p=!0}m[d]=q&&q[d]||n.style(a,d)}else j=void 0;if(n.isEmptyObject(m))"inline"===("none"===j?ta(a.nodeName):j)&&(o.display=j);else{q?"hidden"in q&&(p=q.hidden):q=L.access(a,"fxshow",{}),f&&(q.hidden=!p),p?n(a).show():l.done(function(){n(a).hide()}),l.done(function(){var b;L.remove(a,"fxshow");for(b in m)n.style(a,b,m[b])});for(d in m)g=Ua(p?q[d]:0,d,l),d in q||(q[d]=g.start,p&&(g.end=g.start,g.start="width"===d||"height"===d?1:0))}}function Wa(a,b){var c,d,e,f,g;for(c in a)if(d=n.camelCase(c),e=b[d],f=a[c],n.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=n.cssHooks[d],g&&"expand"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}function Xa(a,b,c){var d,e,f=0,g=Qa.length,h=n.Deferred().always(function(){delete i.elem}),i=function(){if(e)return!1;for(var b=La||Sa(),c=Math.max(0,j.startTime+j.duration-b),d=c/j.duration||0,f=1-d,g=0,i=j.tweens.length;i>g;g++)j.tweens[g].run(f);return h.notifyWith(a,[j,f,c]),1>f&&i?c:(h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:n.extend({},b),opts:n.extend(!0,{specialEasing:{}},c),originalProperties:b,originalOptions:c,startTime:La||Sa(),duration:c.duration,tweens:[],createTween:function(b,c){var d=n.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(d),d},stop:function(b){var c=0,d=b?j.tweens.length:0;if(e)return this;for(e=!0;d>c;c++)j.tweens[c].run(1);return b?h.resolveWith(a,[j,b]):h.rejectWith(a,[j,b]),this}}),k=j.props;for(Wa(k,j.opts.specialEasing);g>f;f++)if(d=Qa[f].call(j,a,k,j.opts))return d;return n.map(k,Ua,j),n.isFunction(j.opts.start)&&j.opts.start.call(a,j),n.fx.timer(n.extend(i,{elem:a,anim:j,queue:j.opts.queue})),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always)}n.Animation=n.extend(Xa,{tweener:function(a,b){n.isFunction(a)?(b=a,a=["*"]):a=a.split(" ");for(var c,d=0,e=a.length;e>d;d++)c=a[d],Ra[c]=Ra[c]||[],Ra[c].unshift(b)},prefilter:function(a,b){b?Qa.unshift(a):Qa.push(a)}}),n.speed=function(a,b,c){var d=a&&"object"==typeof a?n.extend({},a):{complete:c||!c&&b||n.isFunction(a)&&a,duration:a,easing:c&&b||b&&!n.isFunction(b)&&b};return d.duration=n.fx.off?0:"number"==typeof d.duration?d.duration:d.duration in n.fx.speeds?n.fx.speeds[d.duration]:n.fx.speeds._default,(null==d.queue||d.queue===!0)&&(d.queue="fx"),d.old=d.complete,d.complete=function(){n.isFunction(d.old)&&d.old.call(this),d.queue&&n.dequeue(this,d.queue)},d},n.fn.extend({fadeTo:function(a,b,c,d){return this.filter(S).css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=n.isEmptyObject(a),f=n.speed(b,c,d),g=function(){var b=Xa(this,n.extend({},a),f);(e||L.get(this,"finish"))&&b.stop(!0)};return g.finish=g,e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,b,c){var d=function(a){var b=a.stop;delete a.stop,b(c)};return"string"!=typeof a&&(c=b,b=a,a=void 0),b&&a!==!1&&this.queue(a||"fx",[]),this.each(function(){var b=!0,e=null!=a&&a+"queueHooks",f=n.timers,g=L.get(this);if(e)g[e]&&g[e].stop&&d(g[e]);else for(e in g)g[e]&&g[e].stop&&Pa.test(e)&&d(g[e]);for(e=f.length;e--;)f[e].elem!==this||null!=a&&f[e].queue!==a||(f[e].anim.stop(c),b=!1,f.splice(e,1));(b||!c)&&n.dequeue(this,a)})},finish:function(a){return a!==!1&&(a=a||"fx"),this.each(function(){var b,c=L.get(this),d=c[a+"queue"],e=c[a+"queueHooks"],f=n.timers,g=d?d.length:0;for(c.finish=!0,n.queue(this,a,[]),e&&e.stop&&e.stop.call(this,!0),b=f.length;b--;)f[b].elem===this&&f[b].queue===a&&(f[b].anim.stop(!0),f.splice(b,1));for(b=0;g>b;b++)d[b]&&d[b].finish&&d[b].finish.call(this);delete c.finish})}}),n.each(["toggle","show","hide"],function(a,b){var c=n.fn[b];n.fn[b]=function(a,d,e){return null==a||"boolean"==typeof a?c.apply(this,arguments):this.animate(Ta(b,!0),a,d,e)}}),n.each({slideDown:Ta("show"),slideUp:Ta("hide"),slideToggle:Ta("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){n.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),n.timers=[],n.fx.tick=function(){var a,b=0,c=n.timers;for(La=n.now();b<c.length;b++)a=c[b],a()||c[b]!==a||c.splice(b--,1);c.length||n.fx.stop(),La=void 0},n.fx.timer=function(a){n.timers.push(a),a()?n.fx.start():n.timers.pop()},n.fx.interval=13,n.fx.start=function(){Ma||(Ma=setInterval(n.fx.tick,n.fx.interval))},n.fx.stop=function(){clearInterval(Ma),Ma=null},n.fx.speeds={slow:600,fast:200,_default:400},n.fn.delay=function(a,b){return a=n.fx?n.fx.speeds[a]||a:a,b=b||"fx",this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},function(){var a=l.createElement("input"),b=l.createElement("select"),c=b.appendChild(l.createElement("option"));a.type="checkbox",k.checkOn=""!==a.value,k.optSelected=c.selected,b.disabled=!0,k.optDisabled=!c.disabled,a=l.createElement("input"),a.value="t",a.type="radio",k.radioValue="t"===a.value}();var Ya,Za,$a=n.expr.attrHandle;n.fn.extend({attr:function(a,b){return J(this,n.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){n.removeAttr(this,a)})}}),n.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(a&&3!==f&&8!==f&&2!==f)return typeof a.getAttribute===U?n.prop(a,b,c):(1===f&&n.isXMLDoc(a)||(b=b.toLowerCase(),d=n.attrHooks[b]||(n.expr.match.bool.test(b)?Za:Ya)),
|
||
void 0===c?d&&"get"in d&&null!==(e=d.get(a,b))?e:(e=n.find.attr(a,b),null==e?void 0:e):null!==c?d&&"set"in d&&void 0!==(e=d.set(a,c,b))?e:(a.setAttribute(b,c+""),c):void n.removeAttr(a,b))},removeAttr:function(a,b){var c,d,e=0,f=b&&b.match(E);if(f&&1===a.nodeType)while(c=f[e++])d=n.propFix[c]||c,n.expr.match.bool.test(c)&&(a[d]=!1),a.removeAttribute(c)},attrHooks:{type:{set:function(a,b){if(!k.radioValue&&"radio"===b&&n.nodeName(a,"input")){var c=a.value;return a.setAttribute("type",b),c&&(a.value=c),b}}}}}),Za={set:function(a,b,c){return b===!1?n.removeAttr(a,c):a.setAttribute(c,c),c}},n.each(n.expr.match.bool.source.match(/\w+/g),function(a,b){var c=$a[b]||n.find.attr;$a[b]=function(a,b,d){var e,f;return d||(f=$a[b],$a[b]=e,e=null!=c(a,b,d)?b.toLowerCase():null,$a[b]=f),e}});var _a=/^(?:input|select|textarea|button)$/i;n.fn.extend({prop:function(a,b){return J(this,n.prop,a,b,arguments.length>1)},removeProp:function(a){return this.each(function(){delete this[n.propFix[a]||a]})}}),n.extend({propFix:{"for":"htmlFor","class":"className"},prop:function(a,b,c){var d,e,f,g=a.nodeType;if(a&&3!==g&&8!==g&&2!==g)return f=1!==g||!n.isXMLDoc(a),f&&(b=n.propFix[b]||b,e=n.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){return a.hasAttribute("tabindex")||_a.test(a.nodeName)||a.href?a.tabIndex:-1}}}}),k.optSelected||(n.propHooks.selected={get:function(a){var b=a.parentNode;return b&&b.parentNode&&b.parentNode.selectedIndex,null}}),n.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){n.propFix[this.toLowerCase()]=this});var ab=/[\t\r\n\f]/g;n.fn.extend({addClass:function(a){var b,c,d,e,f,g,h="string"==typeof a&&a,i=0,j=this.length;if(n.isFunction(a))return this.each(function(b){n(this).addClass(a.call(this,b,this.className))});if(h)for(b=(a||"").match(E)||[];j>i;i++)if(c=this[i],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(ab," "):" ")){f=0;while(e=b[f++])d.indexOf(" "+e+" ")<0&&(d+=e+" ");g=n.trim(d),c.className!==g&&(c.className=g)}return this},removeClass:function(a){var b,c,d,e,f,g,h=0===arguments.length||"string"==typeof a&&a,i=0,j=this.length;if(n.isFunction(a))return this.each(function(b){n(this).removeClass(a.call(this,b,this.className))});if(h)for(b=(a||"").match(E)||[];j>i;i++)if(c=this[i],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(ab," "):"")){f=0;while(e=b[f++])while(d.indexOf(" "+e+" ")>=0)d=d.replace(" "+e+" "," ");g=a?n.trim(d):"",c.className!==g&&(c.className=g)}return this},toggleClass:function(a,b){var c=typeof a;return"boolean"==typeof b&&"string"===c?b?this.addClass(a):this.removeClass(a):this.each(n.isFunction(a)?function(c){n(this).toggleClass(a.call(this,c,this.className,b),b)}:function(){if("string"===c){var b,d=0,e=n(this),f=a.match(E)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else(c===U||"boolean"===c)&&(this.className&&L.set(this,"__className__",this.className),this.className=this.className||a===!1?"":L.get(this,"__className__")||"")})},hasClass:function(a){for(var b=" "+a+" ",c=0,d=this.length;d>c;c++)if(1===this[c].nodeType&&(" "+this[c].className+" ").replace(ab," ").indexOf(b)>=0)return!0;return!1}});var bb=/\r/g;n.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=n.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,n(this).val()):a,null==e?e="":"number"==typeof e?e+="":n.isArray(e)&&(e=n.map(e,function(a){return null==a?"":a+""})),b=n.valHooks[this.type]||n.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=n.valHooks[e.type]||n.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)}}}),n.extend({valHooks:{option:{get:function(a){var b=n.find.attr(a,"value");return null!=b?b:n.trim(n.text(a))}},select:{get:function(a){for(var b,c,d=a.options,e=a.selectedIndex,f="select-one"===a.type||0>e,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||(k.optDisabled?c.disabled:null!==c.getAttribute("disabled"))||c.parentNode.disabled&&n.nodeName(c.parentNode,"optgroup"))){if(b=n(c).val(),f)return b;g.push(b)}return g},set:function(a,b){var c,d,e=a.options,f=n.makeArray(b),g=e.length;while(g--)d=e[g],(d.selected=n.inArray(d.value,f)>=0)&&(c=!0);return c||(a.selectedIndex=-1),f}}}}),n.each(["radio","checkbox"],function(){n.valHooks[this]={set:function(a,b){return n.isArray(b)?a.checked=n.inArray(n(a).val(),b)>=0:void 0}},k.checkOn||(n.valHooks[this].get=function(a){return null===a.getAttribute("value")?"on":a.value})}),n.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(a,b){n.fn[b]=function(a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}}),n.fn.extend({hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return 1===arguments.length?this.off(a,"**"):this.off(b,a||"**",c)}});var cb=n.now(),db=/\?/;n.parseJSON=function(a){return JSON.parse(a+"")},n.parseXML=function(a){var b,c;if(!a||"string"!=typeof a)return null;try{c=new DOMParser,b=c.parseFromString(a,"text/xml")}catch(d){b=void 0}return(!b||b.getElementsByTagName("parsererror").length)&&n.error("Invalid XML: "+a),b};var eb=/#.*$/,fb=/([?&])_=[^&]*/,gb=/^(.*?):[ \t]*([^\r\n]*)$/gm,hb=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,ib=/^(?:GET|HEAD)$/,jb=/^\/\//,kb=/^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,lb={},mb={},nb="*/".concat("*"),ob=a.location.href,pb=kb.exec(ob.toLowerCase())||[];function qb(a){return function(b,c){"string"!=typeof b&&(c=b,b="*");var d,e=0,f=b.toLowerCase().match(E)||[];if(n.isFunction(c))while(d=f[e++])"+"===d[0]?(d=d.slice(1)||"*",(a[d]=a[d]||[]).unshift(c)):(a[d]=a[d]||[]).push(c)}}function rb(a,b,c,d){var e={},f=a===mb;function g(h){var i;return e[h]=!0,n.each(a[h]||[],function(a,h){var j=h(b,c,d);return"string"!=typeof j||f||e[j]?f?!(i=j):void 0:(b.dataTypes.unshift(j),g(j),!1)}),i}return g(b.dataTypes[0])||!e["*"]&&g("*")}function sb(a,b){var c,d,e=n.ajaxSettings.flatOptions||{};for(c in b)void 0!==b[c]&&((e[c]?a:d||(d={}))[c]=b[c]);return d&&n.extend(!0,a,d),a}function tb(a,b,c){var d,e,f,g,h=a.contents,i=a.dataTypes;while("*"===i[0])i.shift(),void 0===d&&(d=a.mimeType||b.getResponseHeader("Content-Type"));if(d)for(e in h)if(h[e]&&h[e].test(d)){i.unshift(e);break}if(i[0]in c)f=i[0];else{for(e in c){if(!i[0]||a.converters[e+" "+i[0]]){f=e;break}g||(g=e)}f=f||g}return f?(f!==i[0]&&i.unshift(f),c[f]):void 0}function ub(a,b,c,d){var e,f,g,h,i,j={},k=a.dataTypes.slice();if(k[1])for(g in a.converters)j[g.toLowerCase()]=a.converters[g];f=k.shift();while(f)if(a.responseFields[f]&&(c[a.responseFields[f]]=b),!i&&d&&a.dataFilter&&(b=a.dataFilter(b,a.dataType)),i=f,f=k.shift())if("*"===f)f=i;else if("*"!==i&&i!==f){if(g=j[i+" "+f]||j["* "+f],!g)for(e in j)if(h=e.split(" "),h[1]===f&&(g=j[i+" "+h[0]]||j["* "+h[0]])){g===!0?g=j[e]:j[e]!==!0&&(f=h[0],k.unshift(h[1]));break}if(g!==!0)if(g&&a["throws"])b=g(b);else try{b=g(b)}catch(l){return{state:"parsererror",error:g?l:"No conversion from "+i+" to "+f}}}return{state:"success",data:b}}n.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:ob,type:"GET",isLocal:hb.test(pb[1]),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":nb,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":n.parseJSON,"text xml":n.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(a,b){return b?sb(sb(a,n.ajaxSettings),b):sb(n.ajaxSettings,a)},ajaxPrefilter:qb(lb),ajaxTransport:qb(mb),ajax:function(a,b){"object"==typeof a&&(b=a,a=void 0),b=b||{};var c,d,e,f,g,h,i,j,k=n.ajaxSetup({},b),l=k.context||k,m=k.context&&(l.nodeType||l.jquery)?n(l):n.event,o=n.Deferred(),p=n.Callbacks("once memory"),q=k.statusCode||{},r={},s={},t=0,u="canceled",v={readyState:0,getResponseHeader:function(a){var b;if(2===t){if(!f){f={};while(b=gb.exec(e))f[b[1].toLowerCase()]=b[2]}b=f[a.toLowerCase()]}return null==b?null:b},getAllResponseHeaders:function(){return 2===t?e:null},setRequestHeader:function(a,b){var c=a.toLowerCase();return t||(a=s[c]=s[c]||a,r[a]=b),this},overrideMimeType:function(a){return t||(k.mimeType=a),this},statusCode:function(a){var b;if(a)if(2>t)for(b in a)q[b]=[q[b],a[b]];else v.always(a[v.status]);return this},abort:function(a){var b=a||u;return c&&c.abort(b),x(0,b),this}};if(o.promise(v).complete=p.add,v.success=v.done,v.error=v.fail,k.url=((a||k.url||ob)+"").replace(eb,"").replace(jb,pb[1]+"//"),k.type=b.method||b.type||k.method||k.type,k.dataTypes=n.trim(k.dataType||"*").toLowerCase().match(E)||[""],null==k.crossDomain&&(h=kb.exec(k.url.toLowerCase()),k.crossDomain=!(!h||h[1]===pb[1]&&h[2]===pb[2]&&(h[3]||("http:"===h[1]?"80":"443"))===(pb[3]||("http:"===pb[1]?"80":"443")))),k.data&&k.processData&&"string"!=typeof k.data&&(k.data=n.param(k.data,k.traditional)),rb(lb,k,b,v),2===t)return v;i=n.event&&k.global,i&&0===n.active++&&n.event.trigger("ajaxStart"),k.type=k.type.toUpperCase(),k.hasContent=!ib.test(k.type),d=k.url,k.hasContent||(k.data&&(d=k.url+=(db.test(d)?"&":"?")+k.data,delete k.data),k.cache===!1&&(k.url=fb.test(d)?d.replace(fb,"$1_="+cb++):d+(db.test(d)?"&":"?")+"_="+cb++)),k.ifModified&&(n.lastModified[d]&&v.setRequestHeader("If-Modified-Since",n.lastModified[d]),n.etag[d]&&v.setRequestHeader("If-None-Match",n.etag[d])),(k.data&&k.hasContent&&k.contentType!==!1||b.contentType)&&v.setRequestHeader("Content-Type",k.contentType),v.setRequestHeader("Accept",k.dataTypes[0]&&k.accepts[k.dataTypes[0]]?k.accepts[k.dataTypes[0]]+("*"!==k.dataTypes[0]?", "+nb+"; q=0.01":""):k.accepts["*"]);for(j in k.headers)v.setRequestHeader(j,k.headers[j]);if(k.beforeSend&&(k.beforeSend.call(l,v,k)===!1||2===t))return v.abort();u="abort";for(j in{success:1,error:1,complete:1})v[j](k[j]);if(c=rb(mb,k,b,v)){v.readyState=1,i&&m.trigger("ajaxSend",[v,k]),k.async&&k.timeout>0&&(g=setTimeout(function(){v.abort("timeout")},k.timeout));try{t=1,c.send(r,x)}catch(w){if(!(2>t))throw w;x(-1,w)}}else x(-1,"No Transport");function x(a,b,f,h){var j,r,s,u,w,x=b;2!==t&&(t=2,g&&clearTimeout(g),c=void 0,e=h||"",v.readyState=a>0?4:0,j=a>=200&&300>a||304===a,f&&(u=tb(k,v,f)),u=ub(k,u,v,j),j?(k.ifModified&&(w=v.getResponseHeader("Last-Modified"),w&&(n.lastModified[d]=w),w=v.getResponseHeader("etag"),w&&(n.etag[d]=w)),204===a||"HEAD"===k.type?x="nocontent":304===a?x="notmodified":(x=u.state,r=u.data,s=u.error,j=!s)):(s=x,(a||!x)&&(x="error",0>a&&(a=0))),v.status=a,v.statusText=(b||x)+"",j?o.resolveWith(l,[r,x,v]):o.rejectWith(l,[v,x,s]),v.statusCode(q),q=void 0,i&&m.trigger(j?"ajaxSuccess":"ajaxError",[v,k,j?r:s]),p.fireWith(l,[v,x]),i&&(m.trigger("ajaxComplete",[v,k]),--n.active||n.event.trigger("ajaxStop")))}return v},getJSON:function(a,b,c){return n.get(a,b,c,"json")},getScript:function(a,b){return n.get(a,void 0,b,"script")}}),n.each(["get","post"],function(a,b){n[b]=function(a,c,d,e){return n.isFunction(c)&&(e=e||d,d=c,c=void 0),n.ajax({url:a,type:b,dataType:e,data:c,success:d})}}),n._evalUrl=function(a){return n.ajax({url:a,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})},n.fn.extend({wrapAll:function(a){var b;return n.isFunction(a)?this.each(function(b){n(this).wrapAll(a.call(this,b))}):(this[0]&&(b=n(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 this.each(n.isFunction(a)?function(b){n(this).wrapInner(a.call(this,b))}:function(){var b=n(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=n.isFunction(a);return this.each(function(c){n(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){n.nodeName(this,"body")||n(this).replaceWith(this.childNodes)}).end()}}),n.expr.filters.hidden=function(a){return a.offsetWidth<=0&&a.offsetHeight<=0},n.expr.filters.visible=function(a){return!n.expr.filters.hidden(a)};var vb=/%20/g,wb=/\[\]$/,xb=/\r?\n/g,yb=/^(?:submit|button|image|reset|file)$/i,zb=/^(?:input|select|textarea|keygen)/i;function Ab(a,b,c,d){var e;if(n.isArray(b))n.each(b,function(b,e){c||wb.test(a)?d(a,e):Ab(a+"["+("object"==typeof e?b:"")+"]",e,c,d)});else if(c||"object"!==n.type(b))d(a,b);else for(e in b)Ab(a+"["+e+"]",b[e],c,d)}n.param=function(a,b){var c,d=[],e=function(a,b){b=n.isFunction(b)?b():null==b?"":b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};if(void 0===b&&(b=n.ajaxSettings&&n.ajaxSettings.traditional),n.isArray(a)||a.jquery&&!n.isPlainObject(a))n.each(a,function(){e(this.name,this.value)});else for(c in a)Ab(c,a[c],b,e);return d.join("&").replace(vb,"+")},n.fn.extend({serialize:function(){return n.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=n.prop(this,"elements");return a?n.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!n(this).is(":disabled")&&zb.test(this.nodeName)&&!yb.test(a)&&(this.checked||!T.test(a))}).map(function(a,b){var c=n(this).val();return null==c?null:n.isArray(c)?n.map(c,function(a){return{name:b.name,value:a.replace(xb,"\r\n")}}):{name:b.name,value:c.replace(xb,"\r\n")}}).get()}}),n.ajaxSettings.xhr=function(){try{return new XMLHttpRequest}catch(a){}};var Bb=0,Cb={},Db={0:200,1223:204},Eb=n.ajaxSettings.xhr();a.attachEvent&&a.attachEvent("onunload",function(){for(var a in Cb)Cb[a]()}),k.cors=!!Eb&&"withCredentials"in Eb,k.ajax=Eb=!!Eb,n.ajaxTransport(function(a){var b;return k.cors||Eb&&!a.crossDomain?{send:function(c,d){var e,f=a.xhr(),g=++Bb;if(f.open(a.type,a.url,a.async,a.username,a.password),a.xhrFields)for(e in a.xhrFields)f[e]=a.xhrFields[e];a.mimeType&&f.overrideMimeType&&f.overrideMimeType(a.mimeType),a.crossDomain||c["X-Requested-With"]||(c["X-Requested-With"]="XMLHttpRequest");for(e in c)f.setRequestHeader(e,c[e]);b=function(a){return function(){b&&(delete Cb[g],b=f.onload=f.onerror=null,"abort"===a?f.abort():"error"===a?d(f.status,f.statusText):d(Db[f.status]||f.status,f.statusText,"string"==typeof f.responseText?{text:f.responseText}:void 0,f.getAllResponseHeaders()))}},f.onload=b(),f.onerror=b("error"),b=Cb[g]=b("abort");try{f.send(a.hasContent&&a.data||null)}catch(h){if(b)throw h}},abort:function(){b&&b()}}:void 0}),n.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(a){return n.globalEval(a),a}}}),n.ajaxPrefilter("script",function(a){void 0===a.cache&&(a.cache=!1),a.crossDomain&&(a.type="GET")}),n.ajaxTransport("script",function(a){if(a.crossDomain){var b,c;return{send:function(d,e){b=n("<script>").prop({async:!0,charset:a.scriptCharset,src:a.url}).on("load error",c=function(a){b.remove(),c=null,a&&e("error"===a.type?404:200,a.type)}),l.head.appendChild(b[0])},abort:function(){c&&c()}}}});var Fb=[],Gb=/(=)\?(?=&|$)|\?\?/;n.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var a=Fb.pop()||n.expando+"_"+cb++;return this[a]=!0,a}}),n.ajaxPrefilter("json jsonp",function(b,c,d){var e,f,g,h=b.jsonp!==!1&&(Gb.test(b.url)?"url":"string"==typeof b.data&&!(b.contentType||"").indexOf("application/x-www-form-urlencoded")&&Gb.test(b.data)&&"data");return h||"jsonp"===b.dataTypes[0]?(e=b.jsonpCallback=n.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,h?b[h]=b[h].replace(Gb,"$1"+e):b.jsonp!==!1&&(b.url+=(db.test(b.url)?"&":"?")+b.jsonp+"="+e),b.converters["script json"]=function(){return g||n.error(e+" was not called"),g[0]},b.dataTypes[0]="json",f=a[e],a[e]=function(){g=arguments},d.always(function(){a[e]=f,b[e]&&(b.jsonpCallback=c.jsonpCallback,Fb.push(e)),g&&n.isFunction(f)&&f(g[0]),g=f=void 0}),"script"):void 0}),n.parseHTML=function(a,b,c){if(!a||"string"!=typeof a)return null;"boolean"==typeof b&&(c=b,b=!1),b=b||l;var d=v.exec(a),e=!c&&[];return d?[b.createElement(d[1])]:(d=n.buildFragment([a],b,e),e&&e.length&&n(e).remove(),n.merge([],d.childNodes))};var Hb=n.fn.load;n.fn.load=function(a,b,c){if("string"!=typeof a&&Hb)return Hb.apply(this,arguments);var d,e,f,g=this,h=a.indexOf(" ");return h>=0&&(d=n.trim(a.slice(h)),a=a.slice(0,h)),n.isFunction(b)?(c=b,b=void 0):b&&"object"==typeof b&&(e="POST"),g.length>0&&n.ajax({url:a,type:e,dataType:"html",data:b}).done(function(a){f=arguments,g.html(d?n("<div>").append(n.parseHTML(a)).find(d):a)}).complete(c&&function(a,b){g.each(c,f||[a.responseText,b,a])}),this},n.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(a,b){n.fn[b]=function(a){return this.on(b,a)}}),n.expr.filters.animated=function(a){return n.grep(n.timers,function(b){return a===b.elem}).length};var Ib=a.document.documentElement;function Jb(a){return n.isWindow(a)?a:9===a.nodeType&&a.defaultView}n.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=n.css(a,"position"),l=n(a),m={};"static"===k&&(a.style.position="relative"),h=l.offset(),f=n.css(a,"top"),i=n.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),n.isFunction(b)&&(b=b.call(a,c,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)}},n.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){n.offset.setOffset(this,a,b)});var b,c,d=this[0],e={top:0,left:0},f=d&&d.ownerDocument;if(f)return b=f.documentElement,n.contains(b,d)?(typeof d.getBoundingClientRect!==U&&(e=d.getBoundingClientRect()),c=Jb(f),{top:e.top+c.pageYOffset-b.clientTop,left:e.left+c.pageXOffset-b.clientLeft}):e},position:function(){if(this[0]){var a,b,c=this[0],d={top:0,left:0};return"fixed"===n.css(c,"position")?b=c.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),n.nodeName(a[0],"html")||(d=a.offset()),d.top+=n.css(a[0],"borderTopWidth",!0),d.left+=n.css(a[0],"borderLeftWidth",!0)),{top:b.top-d.top-n.css(c,"marginTop",!0),left:b.left-d.left-n.css(c,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||Ib;while(a&&!n.nodeName(a,"html")&&"static"===n.css(a,"position"))a=a.offsetParent;return a||Ib})}}),n.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(b,c){var d="pageYOffset"===c;n.fn[b]=function(e){return J(this,function(b,e,f){var g=Jb(b);return void 0===f?g?g[c]:b[e]:void(g?g.scrollTo(d?a.pageXOffset:f,d?f:a.pageYOffset):b[e]=f)},b,e,arguments.length,null)}}),n.each(["top","left"],function(a,b){n.cssHooks[b]=ya(k.pixelPosition,function(a,c){return c?(c=xa(a,b),va.test(c)?n(a).position()[b]+"px":c):void 0})}),n.each({Height:"height",Width:"width"},function(a,b){n.each({padding:"inner"+a,content:b,"":"outer"+a},function(c,d){n.fn[d]=function(d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return J(this,function(b,c,d){var e;return n.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?n.css(b,c,g):n.style(b,c,d,g)},b,f?d:void 0,f,null)}})}),n.fn.size=function(){return this.length},n.fn.andSelf=n.fn.addBack,"function"==typeof define&&define.amd&&define("jquery",[],function(){return n});var Kb=a.jQuery,Lb=a.$;return n.noConflict=function(b){return a.$===n&&(a.$=Lb),b&&a.jQuery===n&&(a.jQuery=Kb),n},typeof b===U&&(a.jQuery=a.$=n),n});
|
||
|
||
},{}],37:[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 resizePollingLoop() {
|
||
|
||
// yep, setTimeout, 'cuz requestAnimation doesn't seem to perform that well
|
||
resizeTimeout = window.setTimeout(function(){
|
||
// 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).trigger('resize',[width,height])
|
||
}
|
||
|
||
}
|
||
|
||
// Loop.
|
||
resizePollingLoop()
|
||
|
||
}, pollInterval )
|
||
|
||
}
|
||
|
||
})(jQuery)
|
||
|
||
},{}],38:[function(require,module,exports){
|
||
/*! jQuery UI - v1.12.0-beta.1 - 2016-02-28
|
||
* 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(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)})(function(e){e.ui=e.ui||{},e.ui.version="1.12.0-beta.1";var t=0,i=Array.prototype.slice;e.cleanData=function(t){return function(i){var s,n,a;for(a=0;null!=(n=i[a]);a++)try{s=e._data(n,"events"),s&&s.remove&&e(n).triggerHandler("remove")}catch(o){}t(i)}}(e.cleanData),e.widget=function(t,i,s){var n,a,o,r={},h=t.split(".")[0];t=t.split(".")[1];var l=h+"-"+t;return s||(s=i,i=e.Widget),e.isArray(s)&&(s=e.extend.apply(null,[{}].concat(s))),e.expr[":"][l.toLowerCase()]=function(t){return!!e.data(t,l)},e[h]=e[h]||{},n=e[h][t],a=e[h][t]=function(e,t){return this._createWidget?(arguments.length&&this._createWidget(e,t),void 0):new a(e,t)},e.extend(a,n,{version:s.version,_proto:e.extend({},s),_childConstructors:[]}),o=new i,o.options=e.widget.extend({},o.options),e.each(s,function(t,s){return e.isFunction(s)?(r[t]=function(){function e(){return i.prototype[t].apply(this,arguments)}function n(e){return i.prototype[t].apply(this,e)}return function(){var t,i=this._super,a=this._superApply;return this._super=e,this._superApply=n,t=s.apply(this,arguments),this._super=i,this._superApply=a,t}}(),void 0):(r[t]=s,void 0)}),a.prototype=e.widget.extend(o,{widgetEventPrefix:n?o.widgetEventPrefix||t:t},r,{constructor:a,namespace:h,widgetName:t,widgetFullName:l}),n?(e.each(n._childConstructors,function(t,i){var s=i.prototype;e.widget(s.namespace+"."+s.widgetName,a,i._proto)}),delete n._childConstructors):i._childConstructors.push(a),e.widget.bridge(t,a),a},e.widget.extend=function(t){for(var s,n,a=i.call(arguments,1),o=0,r=a.length;r>o;o++)for(s in a[o])n=a[o][s],a[o].hasOwnProperty(s)&&void 0!==n&&(t[s]=e.isPlainObject(n)?e.isPlainObject(t[s])?e.widget.extend({},t[s],n):e.widget.extend({},n):n);return t},e.widget.bridge=function(t,s){var n=s.prototype.widgetFullName||t;e.fn[t]=function(a){var o="string"==typeof a,r=i.call(arguments,1),h=this;return o?this.each(function(){var i,s=e.data(this,n);return"instance"===a?(h=s,!1):s?e.isFunction(s[a])&&"_"!==a.charAt(0)?(i=s[a].apply(s,r),i!==s&&void 0!==i?(h=i&&i.jquery?h.pushStack(i.get()):i,!1):void 0):e.error("no such method '"+a+"' for "+t+" widget instance"):e.error("cannot call methods on "+t+" prior to initialization; "+"attempted to call method '"+a+"'")}):(r.length&&(a=e.widget.extend.apply(null,[a].concat(r))),this.each(function(){var t=e.data(this,n);t?(t.option(a||{}),t._init&&t._init()):e.data(this,n,new s(a,this))})),h}},e.Widget=function(){},e.Widget._childConstructors=[],e.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",defaultElement:"<div>",options:{classes:{},disabled:!1,create:null},_createWidget:function(i,s){s=e(s||this.defaultElement||this)[0],this.element=e(s),this.uuid=t++,this.eventNamespace="."+this.widgetName+this.uuid,this.bindings=e(),this.hoverable=e(),this.focusable=e(),this.classesElementLookup={},s!==this&&(e.data(s,this.widgetFullName,this),this._on(!0,this.element,{remove:function(e){e.target===s&&this.destroy()}}),this.document=e(s.style?s.ownerDocument:s.document||s),this.window=e(this.document[0].defaultView||this.document[0].parentWindow)),this.options=e.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:e.noop,_create:e.noop,_init:e.noop,destroy:function(){var t=this;this._destroy(),e.each(this.classesElementLookup,function(e,i){t._removeClass(i,e)}),this.element.off(this.eventNamespace).removeData(this.widgetFullName),this.widget().off(this.eventNamespace).removeAttr("aria-disabled"),this.bindings.off(this.eventNamespace)},_destroy:e.noop,widget:function(){return this.element},option:function(t,i){var s,n,a,o=t;if(0===arguments.length)return e.widget.extend({},this.options);if("string"==typeof t)if(o={},s=t.split("."),t=s.shift(),s.length){for(n=o[t]=e.widget.extend({},this.options[t]),a=0;s.length-1>a;a++)n[s[a]]=n[s[a]]||{},n=n[s[a]];if(t=s.pop(),1===arguments.length)return void 0===n[t]?null:n[t];n[t]=i}else{if(1===arguments.length)return void 0===this.options[t]?null:this.options[t];o[t]=i}return this._setOptions(o),this},_setOptions:function(e){var t;for(t in e)this._setOption(t,e[t]);return this},_setOption:function(e,t){return"classes"===e&&this._setOptionClasses(t),this.options[e]=t,"disabled"===e&&this._setOptionDisabled(t),this},_setOptionClasses:function(t){var i,s,n;for(i in t)n=this.classesElementLookup[i],t[i]!==this.options.classes[i]&&n&&n.length&&(s=e(n.get()),this._removeClass(n,i),s.addClass(this._classes({element:s,keys:i,classes:t,add:!0})))},_setOptionDisabled:function(e){this._toggleClass(this.widget(),this.widgetFullName+"-disabled",null,!!e),e&&(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(t){function i(i,a){var o,r;for(r=0;i.length>r;r++)o=n.classesElementLookup[i[r]]||e(),o=t.add?e(e.unique(o.get().concat(t.element.get()))):e(o.not(t.element).get()),n.classesElementLookup[i[r]]=o,s.push(i[r]),a&&t.classes[i[r]]&&s.push(t.classes[i[r]])}var s=[],n=this;return t=e.extend({element:this.element,classes:this.options.classes||{}},t),t.keys&&i(t.keys.match(/\S+/g)||[],!0),t.extra&&i(t.extra.match(/\S+/g)||[]),s.join(" ")},_removeClass:function(e,t,i){return this._toggleClass(e,t,i,!1)},_addClass:function(e,t,i){return this._toggleClass(e,t,i,!0)},_toggleClass:function(e,t,i,s){s="boolean"==typeof s?s:i;var n="string"==typeof e||null===e,a={extra:n?t:i,keys:n?e:t,element:n?this.element:e,add:s};return a.element.toggleClass(this._classes(a),s),this},_on:function(t,i,s){var n,a=this;"boolean"!=typeof t&&(s=i,i=t,t=!1),s?(i=n=e(i),this.bindings=this.bindings.add(i)):(s=i,i=this.element,n=this.widget()),e.each(s,function(s,o){function r(){return t||a.options.disabled!==!0&&!e(this).hasClass("ui-state-disabled")?("string"==typeof o?a[o]:o).apply(a,arguments):void 0}"string"!=typeof o&&(r.guid=o.guid=o.guid||r.guid||e.guid++);var h=s.match(/^([\w:-]*)\s*(.*)$/),l=h[1]+a.eventNamespace,u=h[2];u?n.on(l,u,r):i.on(l,r)})},_off:function(t,i){i=(i||"").split(" ").join(this.eventNamespace+" ")+this.eventNamespace,t.off(i).off(i),this.bindings=e(this.bindings.not(t).get()),this.focusable=e(this.focusable.not(t).get()),this.hoverable=e(this.hoverable.not(t).get())},_delay:function(e,t){function i(){return("string"==typeof e?s[e]:e).apply(s,arguments)}var s=this;return setTimeout(i,t||0)},_hoverable:function(t){this.hoverable=this.hoverable.add(t),this._on(t,{mouseenter:function(t){this._addClass(e(t.currentTarget),null,"ui-state-hover")},mouseleave:function(t){this._removeClass(e(t.currentTarget),null,"ui-state-hover")}})},_focusable:function(t){this.focusable=this.focusable.add(t),this._on(t,{focusin:function(t){this._addClass(e(t.currentTarget),null,"ui-state-focus")},focusout:function(t){this._removeClass(e(t.currentTarget),null,"ui-state-focus")}})},_trigger:function(t,i,s){var n,a,o=this.options[t];if(s=s||{},i=e.Event(i),i.type=(t===this.widgetEventPrefix?t:this.widgetEventPrefix+t).toLowerCase(),i.target=this.element[0],a=i.originalEvent)for(n in a)n in i||(i[n]=a[n]);return this.element.trigger(i,s),!(e.isFunction(o)&&o.apply(this.element[0],[i].concat(s))===!1||i.isDefaultPrevented())}},e.each({show:"fadeIn",hide:"fadeOut"},function(t,i){e.Widget.prototype["_"+t]=function(s,n,a){"string"==typeof n&&(n={effect:n});var o,r=n?n===!0||"number"==typeof n?i:n.effect||i:t;n=n||{},"number"==typeof n&&(n={duration:n}),o=!e.isEmptyObject(n),n.complete=a,n.delay&&s.delay(n.delay),o&&e.effects&&e.effects.effect[r]?s[t](n):r!==t&&s[r]?s[r](n.duration,n.easing,a):s.queue(function(i){e(this)[t](),a&&a.call(s[0]),i()})}}),e.widget,e.extend(e.expr[":"],{data:e.expr.createPseudo?e.expr.createPseudo(function(t){return function(i){return!!e.data(i,t)}}):function(t,i,s){return!!e.data(t,s[3])}}),e.fn.extend({disableSelection:function(){var e="onselectstart"in document.createElement("div")?"selectstart":"mousedown";return function(){return this.on(e+".ui-disableSelection",function(e){e.preventDefault()})}}(),enableSelection:function(){return this.off(".ui-disableSelection")}}),e.fn.scrollParent=function(t){var i=this.css("position"),s="absolute"===i,n=t?/(auto|scroll|hidden)/:/(auto|scroll)/,a=this.parents().filter(function(){var t=e(this);return s&&"static"===t.css("position")?!1:n.test(t.css("overflow")+t.css("overflow-y")+t.css("overflow-x"))}).eq(0);return"fixed"!==i&&a.length?a:e(this[0].ownerDocument||document)},e.ui.ie=!!/msie [\w.]+/.exec(navigator.userAgent.toLowerCase());var s=!1;e(document).on("mouseup",function(){s=!1}),e.widget("ui.mouse",{version:"1.12.0-beta.1",options:{cancel:"input, textarea, button, select, option",distance:1,delay:0},_mouseInit:function(){var t=this;this.element.on("mousedown."+this.widgetName,function(e){return t._mouseDown(e)}).on("click."+this.widgetName,function(i){return!0===e.data(i.target,t.widgetName+".preventClickEvent")?(e.removeData(i.target,t.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(t){if(!s){this._mouseMoved=!1,this._mouseStarted&&this._mouseUp(t),this._mouseDownEvent=t;var i=this,n=1===t.which,a="string"==typeof this.options.cancel&&t.target.nodeName?e(t.target).closest(this.options.cancel).length:!1;return n&&!a&&this._mouseCapture(t)?(this.mouseDelayMet=!this.options.delay,this.mouseDelayMet||(this._mouseDelayTimer=setTimeout(function(){i.mouseDelayMet=!0},this.options.delay)),this._mouseDistanceMet(t)&&this._mouseDelayMet(t)&&(this._mouseStarted=this._mouseStart(t)!==!1,!this._mouseStarted)?(t.preventDefault(),!0):(!0===e.data(t.target,this.widgetName+".preventClickEvent")&&e.removeData(t.target,this.widgetName+".preventClickEvent"),this._mouseMoveDelegate=function(e){return i._mouseMove(e)},this._mouseUpDelegate=function(e){return i._mouseUp(e)},this.document.on("mousemove."+this.widgetName,this._mouseMoveDelegate).on("mouseup."+this.widgetName,this._mouseUpDelegate),t.preventDefault(),s=!0,!0)):!0}},_mouseMove:function(t){if(this._mouseMoved){if(e.ui.ie&&(!document.documentMode||9>document.documentMode)&&!t.button)return this._mouseUp(t);if(!t.which)if(t.originalEvent.altKey||t.originalEvent.ctrlKey||t.originalEvent.metaKey||t.originalEvent.shiftKey)this.ignoreMissingWhich=!0;else if(!this.ignoreMissingWhich)return this._mouseUp(t)}return(t.which||t.button)&&(this._mouseMoved=!0),this._mouseStarted?(this._mouseDrag(t),t.preventDefault()):(this._mouseDistanceMet(t)&&this._mouseDelayMet(t)&&(this._mouseStarted=this._mouseStart(this._mouseDownEvent,t)!==!1,this._mouseStarted?this._mouseDrag(t):this._mouseUp(t)),!this._mouseStarted)},_mouseUp:function(t){this.document.off("mousemove."+this.widgetName,this._mouseMoveDelegate).off("mouseup."+this.widgetName,this._mouseUpDelegate),this._mouseStarted&&(this._mouseStarted=!1,t.target===this._mouseDownEvent.target&&e.data(t.target,this.widgetName+".preventClickEvent",!0),this._mouseStop(t)),this._mouseDelayTimer&&(clearTimeout(this._mouseDelayTimer),delete this._mouseDelayTimer),this.ignoreMissingWhich=!1,s=!1,t.preventDefault()},_mouseDistanceMet:function(e){return Math.max(Math.abs(this._mouseDownEvent.pageX-e.pageX),Math.abs(this._mouseDownEvent.pageY-e.pageY))>=this.options.distance},_mouseDelayMet:function(){return this.mouseDelayMet},_mouseStart:function(){},_mouseDrag:function(){},_mouseStop:function(){},_mouseCapture:function(){return!0}}),e.ui.plugin={add:function(t,i,s){var n,a=e.ui[t].prototype;for(n in s)a.plugins[n]=a.plugins[n]||[],a.plugins[n].push([i,s[n]])},call:function(e,t,i,s){var n,a=e.plugins[t];if(a&&(s||e.element[0].parentNode&&11!==e.element[0].parentNode.nodeType))for(n=0;a.length>n;n++)e.options[a[n][0]]&&a[n][1].apply(e.element,i)}},e.ui.safeActiveElement=function(e){var t;try{t=e.activeElement}catch(i){t=e.body}return t||(t=e.body),t.nodeName||(t=e.body),t},e.ui.safeBlur=function(t){t&&"body"!==t.nodeName.toLowerCase()&&e(t).trigger("blur")},e.widget("ui.draggable",e.ui.mouse,{version:"1.12.0-beta.1",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(e,t){this._super(e,t),"handle"===e&&(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(t){var i=this.options;return this._blurActiveElement(t),this.helper||i.disabled||e(t.target).closest(".ui-resizable-handle").length>0?!1:(this.handle=this._getHandle(t),this.handle?(this._blockFrames(i.iframeFix===!0?"iframe":i.iframeFix),!0):!1)},_blockFrames:function(t){this.iframeBlocks=this.document.find(t).map(function(){var t=e(this);return e("<div>").css("position","absolute").appendTo(t.parent()).outerWidth(t.outerWidth()).outerHeight(t.outerHeight()).offset(t.offset())[0]})},_unblockFrames:function(){this.iframeBlocks&&(this.iframeBlocks.remove(),delete this.iframeBlocks)},_blurActiveElement:function(t){this.handleElement.is(t.target)&&e.ui.safeBlur(e.ui.safeActiveElement(this.document[0]))},_mouseStart:function(t){var i=this.options;return this.helper=this._createHelper(t),this._addClass(this.helper,"ui-draggable-dragging"),this._cacheHelperProportions(),e.ui.ddmanager&&(e.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"===e(this).css("position")}).length>0,this.positionAbs=this.element.offset(),this._refreshOffsets(t),this.originalPosition=this.position=this._generatePosition(t,!1),this.originalPageX=t.pageX,this.originalPageY=t.pageY,i.cursorAt&&this._adjustOffsetFromHelper(i.cursorAt),this._setContainment(),this._trigger("start",t)===!1?(this._clear(),!1):(this._cacheHelperProportions(),e.ui.ddmanager&&!i.dropBehaviour&&e.ui.ddmanager.prepareOffsets(this,t),this._mouseDrag(t,!0),e.ui.ddmanager&&e.ui.ddmanager.dragStart(this,t),!0)},_refreshOffsets:function(e){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:e.pageX-this.offset.left,top:e.pageY-this.offset.top}},_mouseDrag:function(t,i){if(this.hasFixedAncestor&&(this.offset.parent=this._getParentOffset()),this.position=this._generatePosition(t,!0),this.positionAbs=this._convertPositionTo("absolute"),!i){var s=this._uiHash();if(this._trigger("drag",t,s)===!1)return this._mouseUp(new e.Event("mouseup",t)),!1;this.position=s.position}return this.helper[0].style.left=this.position.left+"px",this.helper[0].style.top=this.position.top+"px",e.ui.ddmanager&&e.ui.ddmanager.drag(this,t),!1},_mouseStop:function(t){var i=this,s=!1;return e.ui.ddmanager&&!this.options.dropBehaviour&&(s=e.ui.ddmanager.drop(this,t)),this.dropped&&(s=this.dropped,this.dropped=!1),"invalid"===this.options.revert&&!s||"valid"===this.options.revert&&s||this.options.revert===!0||e.isFunction(this.options.revert)&&this.options.revert.call(this.element,s)?e(this.helper).animate(this.originalPosition,parseInt(this.options.revertDuration,10),function(){i._trigger("stop",t)!==!1&&i._clear()}):this._trigger("stop",t)!==!1&&this._clear(),!1},_mouseUp:function(t){return this._unblockFrames(),e.ui.ddmanager&&e.ui.ddmanager.dragStop(this,t),this.handleElement.is(t.target)&&this.element.trigger("focus"),e.ui.mouse.prototype._mouseUp.call(this,t)},cancel:function(){return this.helper.is(".ui-draggable-dragging")?this._mouseUp(new e.Event("mouseup",{target:this.element[0]})):this._clear(),this},_getHandle:function(t){return this.options.handle?!!e(t.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(t){var i=this.options,s=e.isFunction(i.helper),n=s?e(i.helper.apply(this.element[0],[t])):"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(t){"string"==typeof t&&(t=t.split(" ")),e.isArray(t)&&(t={left:+t[0],top:+t[1]||0}),"left"in t&&(this.offset.click.left=t.left+this.margins.left),"right"in t&&(this.offset.click.left=this.helperProportions.width-t.right+this.margins.left),"top"in t&&(this.offset.click.top=t.top+this.margins.top),"bottom"in t&&(this.offset.click.top=this.helperProportions.height-t.bottom+this.margins.top)},_isRootNode:function(e){return/(html|body)/i.test(e.tagName)||e===this.document[0]},_getParentOffset:function(){var t=this.offsetParent.offset(),i=this.document[0];return"absolute"===this.cssPosition&&this.scrollParent[0]!==i&&e.contains(this.scrollParent[0],this.offsetParent[0])&&(t.left+=this.scrollParent.scrollLeft(),t.top+=this.scrollParent.scrollTop()),this._isRootNode(this.offsetParent[0])&&(t={top:0,left:0}),{top:t.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:t.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if("relative"!==this.cssPosition)return{top:0,left:0};var e=this.element.position(),t=this._isRootNode(this.scrollParent[0]);return{top:e.top-(parseInt(this.helper.css("top"),10)||0)+(t?0:this.scrollParent.scrollTop()),left:e.left-(parseInt(this.helper.css("left"),10)||0)+(t?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 t,i,s,n=this.options,a=this.document[0];return this.relativeContainer=null,n.containment?"window"===n.containment?(this.containment=[e(window).scrollLeft()-this.offset.relative.left-this.offset.parent.left,e(window).scrollTop()-this.offset.relative.top-this.offset.parent.top,e(window).scrollLeft()+e(window).width()-this.helperProportions.width-this.margins.left,e(window).scrollTop()+(e(window).height()||a.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top],void 0):"document"===n.containment?(this.containment=[0,0,e(a).width()-this.helperProportions.width-this.margins.left,(e(a).height()||a.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=e(n.containment),s=i[0],s&&(t=/(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),(t?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,(t?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(e,t){t||(t=this.position);var i="absolute"===e?1:-1,s=this._isRootNode(this.scrollParent[0]);return{top:t.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:t.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(e,t){var i,s,n,a,o=this.options,r=this._isRootNode(this.scrollParent[0]),h=e.pageX,l=e.pageY;return r&&this.offset.scroll||(this.offset.scroll={top:this.scrollParent.scrollTop(),left:this.scrollParent.scrollLeft()}),t&&(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,e.pageX-this.offset.click.left<i[0]&&(h=i[0]+this.offset.click.left),e.pageY-this.offset.click.top<i[1]&&(l=i[1]+this.offset.click.top),e.pageX-this.offset.click.left>i[2]&&(h=i[2]+this.offset.click.left),e.pageY-this.offset.click.top>i[3]&&(l=i[3]+this.offset.click.top)),o.grid&&(n=o.grid[1]?this.originalPageY+Math.round((l-this.originalPageY)/o.grid[1])*o.grid[1]:this.originalPageY,l=i?n-this.offset.click.top>=i[1]||n-this.offset.click.top>i[3]?n:n-this.offset.click.top>=i[1]?n-o.grid[1]:n+o.grid[1]:n,a=o.grid[0]?this.originalPageX+Math.round((h-this.originalPageX)/o.grid[0])*o.grid[0]:this.originalPageX,h=i?a-this.offset.click.left>=i[0]||a-this.offset.click.left>i[2]?a:a-this.offset.click.left>=i[0]?a-o.grid[0]:a+o.grid[0]:a),"y"===o.axis&&(h=this.originalPageX),"x"===o.axis&&(l=this.originalPageY)),{top:l-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:h-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(t,i,s){return s=s||this._uiHash(),e.ui.plugin.call(this,t,[i,s,this],!0),/^(drag|start|stop)/.test(t)&&(this.positionAbs=this._convertPositionTo("absolute"),s.offset=this.positionAbs),e.Widget.prototype._trigger.call(this,t,i,s)},plugins:{},_uiHash:function(){return{helper:this.helper,position:this.position,originalPosition:this.originalPosition,offset:this.positionAbs}}}),e.ui.plugin.add("draggable","connectToSortable",{start:function(t,i,s){var n=e.extend({},i,{item:s.element});s.sortables=[],e(s.options.connectToSortable).each(function(){var i=e(this).sortable("instance");i&&!i.options.disabled&&(s.sortables.push(i),i.refreshPositions(),i._trigger("activate",t,n))})},stop:function(t,i,s){var n=e.extend({},i,{item:s.element});s.cancelHelperRemoval=!1,e.each(s.sortables,function(){var e=this;e.isOver?(e.isOver=0,s.cancelHelperRemoval=!0,e.cancelHelperRemoval=!1,e._storedCSS={position:e.placeholder.css("position"),top:e.placeholder.css("top"),left:e.placeholder.css("left")},e._mouseStop(t),e.options.helper=e.options._helper):(e.cancelHelperRemoval=!0,e._trigger("deactivate",t,n))})},drag:function(t,i,s){e.each(s.sortables,function(){var n=!1,a=this;a.positionAbs=s.positionAbs,a.helperProportions=s.helperProportions,a.offset.click=s.offset.click,a._intersectsWith(a.containerCache)&&(n=!0,e.each(s.sortables,function(){return this.positionAbs=s.positionAbs,this.helperProportions=s.helperProportions,this.offset.click=s.offset.click,this!==a&&this._intersectsWith(this.containerCache)&&e.contains(a.element[0],this.element[0])&&(n=!1),n})),n?(a.isOver||(a.isOver=1,s._parent=i.helper.parent(),a.currentItem=i.helper.appendTo(a.element).data("ui-sortable-item",!0),a.options._helper=a.options.helper,a.options.helper=function(){return i.helper[0]},t.target=a.currentItem[0],a._mouseCapture(t,!0),a._mouseStart(t,!0,!0),a.offset.click.top=s.offset.click.top,a.offset.click.left=s.offset.click.left,a.offset.parent.left-=s.offset.parent.left-a.offset.parent.left,a.offset.parent.top-=s.offset.parent.top-a.offset.parent.top,s._trigger("toSortable",t),s.dropped=a.element,e.each(s.sortables,function(){this.refreshPositions()}),s.currentItem=s.element,a.fromOutside=s),a.currentItem&&(a._mouseDrag(t),i.position=a.position)):a.isOver&&(a.isOver=0,a.cancelHelperRemoval=!0,a.options._revert=a.options.revert,a.options.revert=!1,a._trigger("out",t,a._uiHash(a)),a._mouseStop(t,!0),a.options.revert=a.options._revert,a.options.helper=a.options._helper,a.placeholder&&a.placeholder.remove(),i.helper.appendTo(s._parent),s._refreshOffsets(t),i.position=s._generatePosition(t,!0),s._trigger("fromSortable",t),s.dropped=!1,e.each(s.sortables,function(){this.refreshPositions()}))})}}),e.ui.plugin.add("draggable","cursor",{start:function(t,i,s){var n=e("body"),a=s.options;n.css("cursor")&&(a._cursor=n.css("cursor")),n.css("cursor",a.cursor)},stop:function(t,i,s){var n=s.options;n._cursor&&e("body").css("cursor",n._cursor)}}),e.ui.plugin.add("draggable","opacity",{start:function(t,i,s){var n=e(i.helper),a=s.options;n.css("opacity")&&(a._opacity=n.css("opacity")),n.css("opacity",a.opacity)},stop:function(t,i,s){var n=s.options;n._opacity&&e(i.helper).css("opacity",n._opacity)}}),e.ui.plugin.add("draggable","scroll",{start:function(e,t,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(t,i,s){var n=s.options,a=!1,o=s.scrollParentNotHidden[0],r=s.document[0];o!==r&&"HTML"!==o.tagName?(n.axis&&"x"===n.axis||(s.overflowOffset.top+o.offsetHeight-t.pageY<n.scrollSensitivity?o.scrollTop=a=o.scrollTop+n.scrollSpeed:t.pageY-s.overflowOffset.top<n.scrollSensitivity&&(o.scrollTop=a=o.scrollTop-n.scrollSpeed)),n.axis&&"y"===n.axis||(s.overflowOffset.left+o.offsetWidth-t.pageX<n.scrollSensitivity?o.scrollLeft=a=o.scrollLeft+n.scrollSpeed:t.pageX-s.overflowOffset.left<n.scrollSensitivity&&(o.scrollLeft=a=o.scrollLeft-n.scrollSpeed))):(n.axis&&"x"===n.axis||(t.pageY-e(r).scrollTop()<n.scrollSensitivity?a=e(r).scrollTop(e(r).scrollTop()-n.scrollSpeed):e(window).height()-(t.pageY-e(r).scrollTop())<n.scrollSensitivity&&(a=e(r).scrollTop(e(r).scrollTop()+n.scrollSpeed))),n.axis&&"y"===n.axis||(t.pageX-e(r).scrollLeft()<n.scrollSensitivity?a=e(r).scrollLeft(e(r).scrollLeft()-n.scrollSpeed):e(window).width()-(t.pageX-e(r).scrollLeft())<n.scrollSensitivity&&(a=e(r).scrollLeft(e(r).scrollLeft()+n.scrollSpeed)))),a!==!1&&e.ui.ddmanager&&!n.dropBehaviour&&e.ui.ddmanager.prepareOffsets(s,t)}}),e.ui.plugin.add("draggable","snap",{start:function(t,i,s){var n=s.options;s.snapElements=[],e(n.snap.constructor!==String?n.snap.items||":data(ui-draggable)":n.snap).each(function(){var t=e(this),i=t.offset();this!==s.element[0]&&s.snapElements.push({item:this,width:t.outerWidth(),height:t.outerHeight(),top:i.top,left:i.left})})},drag:function(t,i,s){var n,a,o,r,h,l,u,c,d,p,f=s.options,m=f.snapTolerance,g=i.offset.left,v=g+s.helperProportions.width,_=i.offset.top,b=_+s.helperProportions.height;for(d=s.snapElements.length-1;d>=0;d--)h=s.snapElements[d].left-s.margins.left,l=h+s.snapElements[d].width,u=s.snapElements[d].top-s.margins.top,c=u+s.snapElements[d].height,h-m>v||g>l+m||u-m>b||_>c+m||!e.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,t,e.extend(s._uiHash(),{snapItem:s.snapElements[d].item})),s.snapElements[d].snapping=!1):("inner"!==f.snapMode&&(n=m>=Math.abs(u-b),a=m>=Math.abs(c-_),o=m>=Math.abs(h-v),r=m>=Math.abs(l-g),n&&(i.position.top=s._convertPositionTo("relative",{top:u-s.helperProportions.height,left:0}).top),a&&(i.position.top=s._convertPositionTo("relative",{top:c,left:0}).top),o&&(i.position.left=s._convertPositionTo("relative",{top:0,left:h-s.helperProportions.width}).left),r&&(i.position.left=s._convertPositionTo("relative",{top:0,left:l}).left)),p=n||a||o||r,"outer"!==f.snapMode&&(n=m>=Math.abs(u-_),a=m>=Math.abs(c-b),o=m>=Math.abs(h-g),r=m>=Math.abs(l-v),n&&(i.position.top=s._convertPositionTo("relative",{top:u,left:0}).top),a&&(i.position.top=s._convertPositionTo("relative",{top:c-s.helperProportions.height,left:0}).top),o&&(i.position.left=s._convertPositionTo("relative",{top:0,left:h}).left),r&&(i.position.left=s._convertPositionTo("relative",{top:0,left:l-s.helperProportions.width}).left)),!s.snapElements[d].snapping&&(n||a||o||r||p)&&s.options.snap.snap&&s.options.snap.snap.call(s.element,t,e.extend(s._uiHash(),{snapItem:s.snapElements[d].item})),s.snapElements[d].snapping=n||a||o||r||p)}}),e.ui.plugin.add("draggable","stack",{start:function(t,i,s){var n,a=s.options,o=e.makeArray(e(a.stack)).sort(function(t,i){return(parseInt(e(t).css("zIndex"),10)||0)-(parseInt(e(i).css("zIndex"),10)||0)});o.length&&(n=parseInt(e(o[0]).css("zIndex"),10)||0,e(o).each(function(t){e(this).css("zIndex",n+t)}),this.css("zIndex",n+o.length))}}),e.ui.plugin.add("draggable","zIndex",{start:function(t,i,s){var n=e(i.helper),a=s.options;n.css("zIndex")&&(a._zIndex=n.css("zIndex")),n.css("zIndex",a.zIndex)},stop:function(t,i,s){var n=s.options;n._zIndex&&e(i.helper).css("zIndex",n._zIndex)}}),e.ui.draggable,e.widget("ui.resizable",e.ui.mouse,{version:"1.12.0-beta.1",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(e){return parseFloat(e)||0},_isNumber:function(e){return!isNaN(parseFloat(e))},_hasScroll:function(t,i){if("hidden"===e(t).css("overflow"))return!1;var s=i&&"left"===i?"scrollLeft":"scrollTop",n=!1;return t[s]>0?!0:(t[s]=1,n=t[s]>0,t[s]=0,n)},_create:function(){var t,i,s,n,a,o,r=this,h=this.options;if(this._addClass("ui-resizable"),e.extend(this,{_aspectRatio:!!h.aspectRatio,aspectRatio:h.aspectRatio,originalElement:this.element,_proportionallyResizeElements:[],_helper:h.helper||h.ghost||h.animate?h.helper||"ui-resizable-helper":null}),this.element[0].nodeName.match(/^(canvas|textarea|input|select|button|img)$/i)&&(this.element.wrap(e("<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,o={marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom"),marginLeft:this.originalElement.css("marginLeft")},this.element.css(o),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(o),this._proportionallyResize()),this.handles=h.handles||(e(".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=e(),this.handles.constructor===String)for("all"===this.handles&&(this.handles="n,e,s,w,se,sw,ne,nw"),t=this.handles.split(","),this.handles={},i=0;t.length>i;i++)s=e.trim(t[i]),a="ui-resizable-"+s,n=e("<div>"),this._addClass(n,"ui-resizable-handle "+a),n.css({zIndex:h.zIndex}),this.handles[s]=".ui-resizable-"+s,this.element.append(n);
|
||
this._renderAxis=function(t){var i,s,n,a;t=t||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]=e(this.handles[i]),this._on(this.handles[i],{mousedown:r._mouseDown})),this.elementIsWrapper&&this.originalElement[0].nodeName.match(/^(textarea|input|select|button)$/i)&&(s=e(this.handles[i],this.element),a=/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(""),t.css(n,a),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&&(n=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i)),r.axis=n&&n[1]?n[1]:"se")}),h.autoHide&&(this._handles.hide(),this._addClass("ui-resizable-autohide"),e(this.element).on("mouseenter",function(){h.disabled||(r._removeClass("ui-resizable-autohide"),r._handles.show())}).on("mouseleave",function(){h.disabled||r.resizing||(r._addClass("ui-resizable-autohide"),r._handles.hide())})),this._mouseInit()},_destroy:function(){this._mouseDestroy();var t,i=function(t){e(t).removeData("resizable").removeData("ui-resizable").off(".resizable").find(".ui-resizable-handle").remove()};return this.elementIsWrapper&&(i(this.element),t=this.element,this.originalElement.css({position:t.css("position"),width:t.outerWidth(),height:t.outerHeight(),top:t.css("top"),left:t.css("left")}).insertAfter(t),t.remove()),this.originalElement.css("resize",this.originalResizeStyle),i(this.originalElement),this},_mouseCapture:function(t){var i,s,n=!1;for(i in this.handles)s=e(this.handles[i])[0],(s===t.target||e.contains(s,t.target))&&(n=!0);return!this.options.disabled&&n},_mouseStart:function(t){var i,s,n,a=this.options,o=this.element;return this.resizing=!0,this._renderProxy(),i=this._num(this.helper.css("left")),s=this._num(this.helper.css("top")),a.containment&&(i+=e(a.containment).scrollLeft()||0,s+=e(a.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:o.width(),height:o.height()},this.originalSize=this._helper?{width:o.outerWidth(),height:o.outerHeight()}:{width:o.width(),height:o.height()},this.sizeDiff={width:o.outerWidth()-o.width(),height:o.outerHeight()-o.height()},this.originalPosition={left:i,top:s},this.originalMousePosition={left:t.pageX,top:t.pageY},this.aspectRatio="number"==typeof a.aspectRatio?a.aspectRatio:this.originalSize.width/this.originalSize.height||1,n=e(".ui-resizable-"+this.axis).css("cursor"),e("body").css("cursor","auto"===n?this.axis+"-resize":n),this._addClass("ui-resizable-resizing"),this._propagate("start",t),!0},_mouseDrag:function(t){var i,s,n=this.originalMousePosition,a=this.axis,o=t.pageX-n.left||0,r=t.pageY-n.top||0,h=this._change[a];return this._updatePrevProperties(),h?(i=h.apply(this,[t,o,r]),this._updateVirtualBoundaries(t.shiftKey),(this._aspectRatio||t.shiftKey)&&(i=this._updateRatio(i,t)),i=this._respectSize(i,t),this._updateCache(i),this._propagate("resize",t),s=this._applyChanges(),!this._helper&&this._proportionallyResizeElements.length&&this._proportionallyResize(),e.isEmptyObject(s)||(this._updatePrevProperties(),this._trigger("resize",t,this.ui()),this._applyChanges()),!1):!1},_mouseStop:function(t){this.resizing=!1;var i,s,n,a,o,r,h,l=this.options,u=this;return this._helper&&(i=this._proportionallyResizeElements,s=i.length&&/textarea/i.test(i[0].nodeName),n=s&&this._hasScroll(i[0],"left")?0:u.sizeDiff.height,a=s?0:u.sizeDiff.width,o={width:u.helper.width()-a,height:u.helper.height()-n},r=parseFloat(u.element.css("left"))+(u.position.left-u.originalPosition.left)||null,h=parseFloat(u.element.css("top"))+(u.position.top-u.originalPosition.top)||null,l.animate||this.element.css(e.extend(o,{top:h,left:r})),u.helper.height(u.size.height),u.helper.width(u.size.width),this._helper&&!l.animate&&this._proportionallyResize()),e("body").css("cursor","auto"),this._removeClass("ui-resizable-resizing"),this._propagate("stop",t),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 e={};return this.position.top!==this.prevPosition.top&&(e.top=this.position.top+"px"),this.position.left!==this.prevPosition.left&&(e.left=this.position.left+"px"),this.size.width!==this.prevSize.width&&(e.width=this.size.width+"px"),this.size.height!==this.prevSize.height&&(e.height=this.size.height+"px"),this.helper.css(e),e},_updateVirtualBoundaries:function(e){var t,i,s,n,a,o=this.options;a={minWidth:this._isNumber(o.minWidth)?o.minWidth:0,maxWidth:this._isNumber(o.maxWidth)?o.maxWidth:1/0,minHeight:this._isNumber(o.minHeight)?o.minHeight:0,maxHeight:this._isNumber(o.maxHeight)?o.maxHeight:1/0},(this._aspectRatio||e)&&(t=a.minHeight*this.aspectRatio,s=a.minWidth/this.aspectRatio,i=a.maxHeight*this.aspectRatio,n=a.maxWidth/this.aspectRatio,t>a.minWidth&&(a.minWidth=t),s>a.minHeight&&(a.minHeight=s),a.maxWidth>i&&(a.maxWidth=i),a.maxHeight>n&&(a.maxHeight=n)),this._vBoundaries=a},_updateCache:function(e){this.offset=this.helper.offset(),this._isNumber(e.left)&&(this.position.left=e.left),this._isNumber(e.top)&&(this.position.top=e.top),this._isNumber(e.height)&&(this.size.height=e.height),this._isNumber(e.width)&&(this.size.width=e.width)},_updateRatio:function(e){var t=this.position,i=this.size,s=this.axis;return this._isNumber(e.height)?e.width=e.height*this.aspectRatio:this._isNumber(e.width)&&(e.height=e.width/this.aspectRatio),"sw"===s&&(e.left=t.left+(i.width-e.width),e.top=null),"nw"===s&&(e.top=t.top+(i.height-e.height),e.left=t.left+(i.width-e.width)),e},_respectSize:function(e){var t=this._vBoundaries,i=this.axis,s=this._isNumber(e.width)&&t.maxWidth&&t.maxWidth<e.width,n=this._isNumber(e.height)&&t.maxHeight&&t.maxHeight<e.height,a=this._isNumber(e.width)&&t.minWidth&&t.minWidth>e.width,o=this._isNumber(e.height)&&t.minHeight&&t.minHeight>e.height,r=this.originalPosition.left+this.originalSize.width,h=this.position.top+this.size.height,l=/sw|nw|w/.test(i),u=/nw|ne|n/.test(i);return a&&(e.width=t.minWidth),o&&(e.height=t.minHeight),s&&(e.width=t.maxWidth),n&&(e.height=t.maxHeight),a&&l&&(e.left=r-t.minWidth),s&&l&&(e.left=r-t.maxWidth),o&&u&&(e.top=h-t.minHeight),n&&u&&(e.top=h-t.maxHeight),e.width||e.height||e.left||!e.top?e.width||e.height||e.top||!e.left||(e.left=null):e.top=null,e},_getPaddingPlusBorderDimensions:function(e){for(var t=0,i=[],s=[e.css("borderTopWidth"),e.css("borderRightWidth"),e.css("borderBottomWidth"),e.css("borderLeftWidth")],n=[e.css("paddingTop"),e.css("paddingRight"),e.css("paddingBottom"),e.css("paddingLeft")];4>t;t++)i[t]=parseFloat(s[t])||0,i[t]+=parseFloat(n[t])||0;return{height:i[0]+i[2],width:i[1]+i[3]}},_proportionallyResize:function(){if(this._proportionallyResizeElements.length)for(var e,t=0,i=this.helper||this.element;this._proportionallyResizeElements.length>t;t++)e=this._proportionallyResizeElements[t],this.outerDimensions||(this.outerDimensions=this._getPaddingPlusBorderDimensions(e)),e.css({height:i.height()-this.outerDimensions.height||0,width:i.width()-this.outerDimensions.width||0})},_renderProxy:function(){var t=this.element,i=this.options;this.elementOffset=t.offset(),this._helper?(this.helper=this.helper||e("<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(e,t){return{width:this.originalSize.width+t}},w:function(e,t){var i=this.originalSize,s=this.originalPosition;return{left:s.left+t,width:i.width-t}},n:function(e,t,i){var s=this.originalSize,n=this.originalPosition;return{top:n.top+i,height:s.height-i}},s:function(e,t,i){return{height:this.originalSize.height+i}},se:function(t,i,s){return e.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[t,i,s]))},sw:function(t,i,s){return e.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[t,i,s]))},ne:function(t,i,s){return e.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[t,i,s]))},nw:function(t,i,s){return e.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[t,i,s]))}},_propagate:function(t,i){e.ui.plugin.call(this,t,[i,this.ui()]),"resize"!==t&&this._trigger(t,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}}}),e.ui.plugin.add("resizable","animate",{stop:function(t){var i=e(this).resizable("instance"),s=i.options,n=i._proportionallyResizeElements,a=n.length&&/textarea/i.test(n[0].nodeName),o=a&&i._hasScroll(n[0],"left")?0:i.sizeDiff.height,r=a?0:i.sizeDiff.width,h={width:i.size.width-r,height:i.size.height-o},l=parseFloat(i.element.css("left"))+(i.position.left-i.originalPosition.left)||null,u=parseFloat(i.element.css("top"))+(i.position.top-i.originalPosition.top)||null;i.element.animate(e.extend(h,u&&l?{top:u,left:l}:{}),{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&&e(n[0]).css({width:s.width,height:s.height}),i._updateCache(s),i._propagate("resize",t)}})}}),e.ui.plugin.add("resizable","containment",{start:function(){var t,i,s,n,a,o,r,h=e(this).resizable("instance"),l=h.options,u=h.element,c=l.containment,d=c instanceof e?c.get(0):/parent/.test(c)?u.parent().get(0):c;d&&(h.containerElement=e(d),/document/.test(c)||c===document?(h.containerOffset={left:0,top:0},h.containerPosition={left:0,top:0},h.parentData={element:e(document),left:0,top:0,width:e(document).width(),height:e(document).height()||document.body.parentNode.scrollHeight}):(t=e(d),i=[],e(["Top","Right","Left","Bottom"]).each(function(e,s){i[e]=h._num(t.css("padding"+s))}),h.containerOffset=t.offset(),h.containerPosition=t.position(),h.containerSize={height:t.innerHeight()-i[3],width:t.innerWidth()-i[1]},s=h.containerOffset,n=h.containerSize.height,a=h.containerSize.width,o=h._hasScroll(d,"left")?d.scrollWidth:a,r=h._hasScroll(d)?d.scrollHeight:n,h.parentData={element:d,left:s.left,top:s.top,width:o,height:r}))},resize:function(t){var i,s,n,a,o=e(this).resizable("instance"),r=o.options,h=o.containerOffset,l=o.position,u=o._aspectRatio||t.shiftKey,c={top:0,left:0},d=o.containerElement,p=!0;d[0]!==document&&/static/.test(d.css("position"))&&(c=h),l.left<(o._helper?h.left:0)&&(o.size.width=o.size.width+(o._helper?o.position.left-h.left:o.position.left-c.left),u&&(o.size.height=o.size.width/o.aspectRatio,p=!1),o.position.left=r.helper?h.left:0),l.top<(o._helper?h.top:0)&&(o.size.height=o.size.height+(o._helper?o.position.top-h.top:o.position.top),u&&(o.size.width=o.size.height*o.aspectRatio,p=!1),o.position.top=o._helper?h.top:0),n=o.containerElement.get(0)===o.element.parent().get(0),a=/relative|absolute/.test(o.containerElement.css("position")),n&&a?(o.offset.left=o.parentData.left+o.position.left,o.offset.top=o.parentData.top+o.position.top):(o.offset.left=o.element.offset().left,o.offset.top=o.element.offset().top),i=Math.abs(o.sizeDiff.width+(o._helper?o.offset.left-c.left:o.offset.left-h.left)),s=Math.abs(o.sizeDiff.height+(o._helper?o.offset.top-c.top:o.offset.top-h.top)),i+o.size.width>=o.parentData.width&&(o.size.width=o.parentData.width-i,u&&(o.size.height=o.size.width/o.aspectRatio,p=!1)),s+o.size.height>=o.parentData.height&&(o.size.height=o.parentData.height-s,u&&(o.size.width=o.size.height*o.aspectRatio,p=!1)),p||(o.position.left=o.prevPosition.left,o.position.top=o.prevPosition.top,o.size.width=o.prevSize.width,o.size.height=o.prevSize.height)},stop:function(){var t=e(this).resizable("instance"),i=t.options,s=t.containerOffset,n=t.containerPosition,a=t.containerElement,o=e(t.helper),r=o.offset(),h=o.outerWidth()-t.sizeDiff.width,l=o.outerHeight()-t.sizeDiff.height;t._helper&&!i.animate&&/relative/.test(a.css("position"))&&e(this).css({left:r.left-n.left-s.left,width:h,height:l}),t._helper&&!i.animate&&/static/.test(a.css("position"))&&e(this).css({left:r.left-n.left-s.left,width:h,height:l})}}),e.ui.plugin.add("resizable","alsoResize",{start:function(){var t=e(this).resizable("instance"),i=t.options;e(i.alsoResize).each(function(){var t=e(this);t.data("ui-resizable-alsoresize",{width:parseFloat(t.width()),height:parseFloat(t.height()),left:parseFloat(t.css("left")),top:parseFloat(t.css("top"))})})},resize:function(t,i){var s=e(this).resizable("instance"),n=s.options,a=s.originalSize,o=s.originalPosition,r={height:s.size.height-a.height||0,width:s.size.width-a.width||0,top:s.position.top-o.top||0,left:s.position.left-o.left||0};e(n.alsoResize).each(function(){var t=e(this),s=e(this).data("ui-resizable-alsoresize"),n={},a=t.parents(i.originalElement[0]).length?["width","height"]:["width","height","top","left"];e.each(a,function(e,t){var i=(s[t]||0)+(r[t]||0);i&&i>=0&&(n[t]=i||null)}),t.css(n)})},stop:function(){e(this).removeData("ui-resizable-alsoresize")}}),e.ui.plugin.add("resizable","ghost",{start:function(){var t=e(this).resizable("instance"),i=t.size;t.ghost=t.originalElement.clone(),t.ghost.css({opacity:.25,display:"block",position:"relative",height:i.height,width:i.width,margin:0,left:0,top:0}),t._addClass(t.ghost,"ui-resizable-ghost"),e.uiBackCompat!==!1&&"string"==typeof t.options.ghost&&t.ghost.addClass(this.options.ghost),t.ghost.appendTo(t.helper)},resize:function(){var t=e(this).resizable("instance");t.ghost&&t.ghost.css({position:"relative",height:t.size.height,width:t.size.width})},stop:function(){var t=e(this).resizable("instance");t.ghost&&t.helper&&t.helper.get(0).removeChild(t.ghost.get(0))}}),e.ui.plugin.add("resizable","grid",{resize:function(){var t,i=e(this).resizable("instance"),s=i.options,n=i.size,a=i.originalSize,o=i.originalPosition,r=i.axis,h="number"==typeof s.grid?[s.grid,s.grid]:s.grid,l=h[0]||1,u=h[1]||1,c=Math.round((n.width-a.width)/l)*l,d=Math.round((n.height-a.height)/u)*u,p=a.width+c,f=a.height+d,m=s.maxWidth&&p>s.maxWidth,g=s.maxHeight&&f>s.maxHeight,v=s.minWidth&&s.minWidth>p,_=s.minHeight&&s.minHeight>f;s.grid=h,v&&(p+=l),_&&(f+=u),m&&(p-=l),g&&(f-=u),/^(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=o.top-d):/^(sw)$/.test(r)?(i.size.width=p,i.size.height=f,i.position.left=o.left-c):((0>=f-u||0>=p-l)&&(t=i._getPaddingPlusBorderDimensions(this)),f-u>0?(i.size.height=f,i.position.top=o.top-d):(f=u-t.height,i.size.height=f,i.position.top=o.top+a.height-f),p-l>0?(i.size.width=p,i.position.left=o.left-c):(p=l-t.width,i.size.width=p,i.position.left=o.left+a.width-p))}}),e.ui.resizable,e.widget("ui.sortable",e.ui.mouse,{version:"1.12.0-beta.1",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(e,t,i){return e>=t&&t+i>e},_isFloating:function(e){return/left|right/.test(e.css("float"))||/inline|table-cell/.test(e.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(e,t){this._super(e,t),"handle"===e&&this._setHandleClassName()},_setHandleClassName:function(){var t=this;this._removeClass(this.element.find(".ui-sortable-handle"),"ui-sortable-handle"),e.each(this.items,function(){t._addClass(this.instance.options.handle?this.item.find(this.instance.options.handle):this.item,"ui-sortable-handle")})},_destroy:function(){this._mouseDestroy();for(var e=this.items.length-1;e>=0;e--)this.items[e].item.removeData(this.widgetName+"-item");return this},_mouseCapture:function(t,i){var s=null,n=!1,a=this;return this.reverting?!1:this.options.disabled||"static"===this.options.type?!1:(this._refreshItems(t),e(t.target).parents().each(function(){return e.data(this,a.widgetName+"-item")===a?(s=e(this),!1):void 0}),e.data(t.target,a.widgetName+"-item")===a&&(s=e(t.target)),s?!this.options.handle||i||(e(this.options.handle,s).find("*").addBack().each(function(){this===t.target&&(n=!0)}),n)?(this.currentItem=s,this._removeCurrentsFromItems(),!0):!1:!1)},_mouseStart:function(t,i,s){var n,a,o=this.options;if(this.currentContainer=this,this.refreshPositions(),this.helper=this._createHelper(t),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},e.extend(this.offset,{click:{left:t.pageX-this.offset.left,top:t.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(t),this.originalPageX=t.pageX,this.originalPageY=t.pageY,o.cursorAt&&this._adjustOffsetFromHelper(o.cursorAt),this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]},this.helper[0]!==this.currentItem[0]&&this.currentItem.hide(),this._createPlaceholder(),o.containment&&this._setContainment(),o.cursor&&"auto"!==o.cursor&&(a=this.document.find("body"),this.storedCursor=a.css("cursor"),a.css("cursor",o.cursor),this.storedStylesheet=e("<style>*{ cursor: "+o.cursor+" !important; }</style>").appendTo(a)),o.opacity&&(this.helper.css("opacity")&&(this._storedOpacity=this.helper.css("opacity")),this.helper.css("opacity",o.opacity)),o.zIndex&&(this.helper.css("zIndex")&&(this._storedZIndex=this.helper.css("zIndex")),this.helper.css("zIndex",o.zIndex)),this.scrollParent[0]!==this.document[0]&&"HTML"!==this.scrollParent[0].tagName&&(this.overflowOffset=this.scrollParent.offset()),this._trigger("start",t,this._uiHash()),this._preserveHelperProportions||this._cacheHelperProportions(),!s)for(n=this.containers.length-1;n>=0;n--)this.containers[n]._trigger("activate",t,this._uiHash(this));return e.ui.ddmanager&&(e.ui.ddmanager.current=this),e.ui.ddmanager&&!o.dropBehaviour&&e.ui.ddmanager.prepareOffsets(this,t),this.dragging=!0,this._addClass(this.helper,"ui-sortable-helper"),this._mouseDrag(t),!0},_mouseDrag:function(t){var i,s,n,a,o=this.options,r=!1;for(this.position=this._generatePosition(t),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-t.pageY<o.scrollSensitivity?this.scrollParent[0].scrollTop=r=this.scrollParent[0].scrollTop+o.scrollSpeed:t.pageY-this.overflowOffset.top<o.scrollSensitivity&&(this.scrollParent[0].scrollTop=r=this.scrollParent[0].scrollTop-o.scrollSpeed),this.overflowOffset.left+this.scrollParent[0].offsetWidth-t.pageX<o.scrollSensitivity?this.scrollParent[0].scrollLeft=r=this.scrollParent[0].scrollLeft+o.scrollSpeed:t.pageX-this.overflowOffset.left<o.scrollSensitivity&&(this.scrollParent[0].scrollLeft=r=this.scrollParent[0].scrollLeft-o.scrollSpeed)):(t.pageY-this.document.scrollTop()<o.scrollSensitivity?r=this.document.scrollTop(this.document.scrollTop()-o.scrollSpeed):this.window.height()-(t.pageY-this.document.scrollTop())<o.scrollSensitivity&&(r=this.document.scrollTop(this.document.scrollTop()+o.scrollSpeed)),t.pageX-this.document.scrollLeft()<o.scrollSensitivity?r=this.document.scrollLeft(this.document.scrollLeft()-o.scrollSpeed):this.window.width()-(t.pageX-this.document.scrollLeft())<o.scrollSensitivity&&(r=this.document.scrollLeft(this.document.scrollLeft()+o.scrollSpeed))),r!==!1&&e.ui.ddmanager&&!o.dropBehaviour&&e.ui.ddmanager.prepareOffsets(this,t)),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],a=this._intersectsWithPointer(s),a&&s.instance===this.currentContainer&&n!==this.currentItem[0]&&this.placeholder[1===a?"next":"prev"]()[0]!==n&&!e.contains(this.placeholder[0],n)&&("semi-dynamic"===this.options.type?!e.contains(this.element[0],n):!0)){if(this.direction=1===a?"down":"up","pointer"!==this.options.tolerance&&!this._intersectsWithSides(s))break;this._rearrange(t,s),this._trigger("change",t,this._uiHash());break}return this._contactContainers(t),e.ui.ddmanager&&e.ui.ddmanager.drag(this,t),this._trigger("sort",t,this._uiHash()),this.lastPositionAbs=this.positionAbs,!1},_mouseStop:function(t,i){if(t){if(e.ui.ddmanager&&!this.options.dropBehaviour&&e.ui.ddmanager.drop(this,t),this.options.revert){var s=this,n=this.placeholder.offset(),a=this.options.axis,o={};a&&"x"!==a||(o.left=n.left-this.offset.parent.left-this.margins.left+(this.offsetParent[0]===this.document[0].body?0:this.offsetParent[0].scrollLeft)),a&&"y"!==a||(o.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,e(this.helper).animate(o,parseInt(this.options.revert,10)||500,function(){s._clear(t)})}else this._clear(t,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 t=this.containers.length-1;t>=0;t--)this.containers[t]._trigger("deactivate",null,this._uiHash(this)),this.containers[t].containerCache.over&&(this.containers[t]._trigger("out",null,this._uiHash(this)),this.containers[t].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(),e.extend(this,{helper:null,dragging:!1,reverting:!1,_noFinalSort:null}),this.domPosition.prev?e(this.domPosition.prev).after(this.currentItem):e(this.domPosition.parent).prepend(this.currentItem)),this},serialize:function(t){var i=this._getItemsAsjQuery(t&&t.connected),s=[];return t=t||{},e(i).each(function(){var i=(e(t.item||this).attr(t.attribute||"id")||"").match(t.expression||/(.+)[\-=_](.+)/);i&&s.push((t.key||i[1]+"[]")+"="+(t.key&&t.expression?i[1]:i[2]))}),!s.length&&t.key&&s.push(t.key+"="),s.join("&")},toArray:function(t){var i=this._getItemsAsjQuery(t&&t.connected),s=[];return t=t||{},i.each(function(){s.push(e(t.item||this).attr(t.attribute||"id")||"")}),s},_intersectsWith:function(e){var t=this.positionAbs.left,i=t+this.helperProportions.width,s=this.positionAbs.top,n=s+this.helperProportions.height,a=e.left,o=a+e.width,r=e.top,h=r+e.height,l=this.offset.click.top,u=this.offset.click.left,c="x"===this.options.axis||s+l>r&&h>s+l,d="y"===this.options.axis||t+u>a&&o>t+u,p=c&&d;return"pointer"===this.options.tolerance||this.options.forcePointerForContainers||"pointer"!==this.options.tolerance&&this.helperProportions[this.floating?"width":"height"]>e[this.floating?"width":"height"]?p:t+this.helperProportions.width/2>a&&o>i-this.helperProportions.width/2&&s+this.helperProportions.height/2>r&&h>n-this.helperProportions.height/2},_intersectsWithPointer:function(e){var t,i,s="x"===this.options.axis||this._isOverAxis(this.positionAbs.top+this.offset.click.top,e.top,e.height),n="y"===this.options.axis||this._isOverAxis(this.positionAbs.left+this.offset.click.left,e.left,e.width),a=s&&n;return a?(t=this._getDragVerticalDirection(),i=this._getDragHorizontalDirection(),this.floating?"right"===i||"down"===t?2:1:t&&("down"===t?2:1)):!1},_intersectsWithSides:function(e){var t=this._isOverAxis(this.positionAbs.top+this.offset.click.top,e.top+e.height/2,e.height),i=this._isOverAxis(this.positionAbs.left+this.offset.click.left,e.left+e.width/2,e.width),s=this._getDragVerticalDirection(),n=this._getDragHorizontalDirection();return this.floating&&n?"right"===n&&i||"left"===n&&!i:s&&("down"===s&&t||"up"===s&&!t)},_getDragVerticalDirection:function(){var e=this.positionAbs.top-this.lastPositionAbs.top;return 0!==e&&(e>0?"down":"up")},_getDragHorizontalDirection:function(){var e=this.positionAbs.left-this.lastPositionAbs.left;return 0!==e&&(e>0?"right":"left")},refresh:function(e){return this._refreshItems(e),this._setHandleClassName(),this.refreshPositions(),this},_connectWith:function(){var e=this.options;return e.connectWith.constructor===String?[e.connectWith]:e.connectWith},_getItemsAsjQuery:function(t){function i(){r.push(this)}var s,n,a,o,r=[],h=[],l=this._connectWith();if(l&&t)for(s=l.length-1;s>=0;s--)for(a=e(l[s],this.document[0]),n=a.length-1;n>=0;n--)o=e.data(a[n],this.widgetFullName),o&&o!==this&&!o.options.disabled&&h.push([e.isFunction(o.options.items)?o.options.items.call(o.element):e(o.options.items,o.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),o]);for(h.push([e.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):e(this.options.items,this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),this]),s=h.length-1;s>=0;s--)h[s][0].each(i);return e(r)},_removeCurrentsFromItems:function(){var t=this.currentItem.find(":data("+this.widgetName+"-item)");this.items=e.grep(this.items,function(e){for(var i=0;t.length>i;i++)if(t[i]===e.item[0])return!1;return!0})},_refreshItems:function(t){this.items=[],this.containers=[this];var i,s,n,a,o,r,h,l,u=this.items,c=[[e.isFunction(this.options.items)?this.options.items.call(this.element[0],t,{item:this.currentItem}):e(this.options.items,this.element),this]],d=this._connectWith();if(d&&this.ready)for(i=d.length-1;i>=0;i--)for(n=e(d[i],this.document[0]),s=n.length-1;s>=0;s--)a=e.data(n[s],this.widgetFullName),a&&a!==this&&!a.options.disabled&&(c.push([e.isFunction(a.options.items)?a.options.items.call(a.element[0],t,{item:this.currentItem}):e(a.options.items,a.element),a]),this.containers.push(a));for(i=c.length-1;i>=0;i--)for(o=c[i][1],r=c[i][0],s=0,l=r.length;l>s;s++)h=e(r[s]),h.data(this.widgetName+"-item",o),u.push({item:h,instance:o,width:0,height:0,left:0,top:0})},refreshPositions:function(t){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,a;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?e(this.options.toleranceElement,s.item):s.item,t||(s.width=n.outerWidth(),s.height=n.outerHeight()),a=n.offset(),s.left=a.left,s.top=a.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--)a=this.containers[i].element.offset(),this.containers[i].containerCache.left=a.left,this.containers[i].containerCache.top=a.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(t){t=t||this;var i,s=t.options;s.placeholder&&s.placeholder.constructor!==String||(i=s.placeholder,s.placeholder={element:function(){var s=t.currentItem[0].nodeName.toLowerCase(),n=e("<"+s+">",t.document[0]);return t._addClass(n,"ui-sortable-placeholder",i||t.currentItem[0].className)._removeClass(n,"ui-sortable-helper"),"tbody"===s?t._createTrPlaceholder(t.currentItem.find("tr").eq(0),e("<tr>",t.document[0]).appendTo(n)):"tr"===s?t._createTrPlaceholder(t.currentItem,n):"img"===s&&n.attr("src",t.currentItem.attr("src")),i||n.css("visibility","hidden"),n},update:function(e,n){(!i||s.forcePlaceholderSize)&&(n.height()||n.height(t.currentItem.innerHeight()-parseInt(t.currentItem.css("paddingTop")||0,10)-parseInt(t.currentItem.css("paddingBottom")||0,10)),n.width()||n.width(t.currentItem.innerWidth()-parseInt(t.currentItem.css("paddingLeft")||0,10)-parseInt(t.currentItem.css("paddingRight")||0,10)))}}),t.placeholder=e(s.placeholder.element.call(t.element,t.currentItem)),t.currentItem.after(t.placeholder),s.placeholder.update(t,t.placeholder)},_createTrPlaceholder:function(t,i){var s=this;t.children().each(function(){e("<td> </td>",s.document[0]).attr("colspan",e(this).attr("colspan")||1).appendTo(i)})},_contactContainers:function(t){var i,s,n,a,o,r,h,l,u,c,d=null,p=null;for(i=this.containers.length-1;i>=0;i--)if(!e.contains(this.currentItem[0],this.containers[i].element[0]))if(this._intersectsWith(this.containers[i].containerCache)){if(d&&e.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",t,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",t,this._uiHash(this)),this.containers[p].containerCache.over=1);else{for(n=1e4,a=null,u=d.floating||this._isFloating(this.currentItem),o=u?"left":"top",r=u?"width":"height",c=u?"clientX":"clientY",s=this.items.length-1;s>=0;s--)e.contains(this.containers[p].element[0],this.items[s].item[0])&&this.items[s].item[0]!==this.currentItem[0]&&(h=this.items[s].item.offset()[o],l=!1,t[c]-h>this.items[s][r]/2&&(l=!0),n>Math.abs(t[c]-h)&&(n=Math.abs(t[c]-h),a=this.items[s],this.direction=l?"up":"down"));if(!a&&!this.options.dropOnEmpty)return;if(this.currentContainer===this.containers[p])return this.currentContainer.containerCache.over||(this.containers[p]._trigger("over",t,this._uiHash()),this.currentContainer.containerCache.over=1),void 0;a?this._rearrange(t,a,null,!0):this._rearrange(t,null,this.containers[p].element,!0),this._trigger("change",t,this._uiHash()),this.containers[p]._trigger("change",t,this._uiHash(this)),this.currentContainer=this.containers[p],this.options.placeholder.update(this.currentContainer,this.placeholder),this.containers[p]._trigger("over",t,this._uiHash(this)),this.containers[p].containerCache.over=1}},_createHelper:function(t){var i=this.options,s=e.isFunction(i.helper)?e(i.helper.apply(this.element[0],[t,this.currentItem])):"clone"===i.helper?this.currentItem.clone():this.currentItem;return s.parents("body").length||e("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(t){"string"==typeof t&&(t=t.split(" ")),e.isArray(t)&&(t={left:+t[0],top:+t[1]||0}),"left"in t&&(this.offset.click.left=t.left+this.margins.left),"right"in t&&(this.offset.click.left=this.helperProportions.width-t.right+this.margins.left),"top"in t&&(this.offset.click.top=t.top+this.margins.top),"bottom"in t&&(this.offset.click.top=this.helperProportions.height-t.bottom+this.margins.top)},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var t=this.offsetParent.offset();return"absolute"===this.cssPosition&&this.scrollParent[0]!==this.document[0]&&e.contains(this.scrollParent[0],this.offsetParent[0])&&(t.left+=this.scrollParent.scrollLeft(),t.top+=this.scrollParent.scrollTop()),(this.offsetParent[0]===this.document[0].body||this.offsetParent[0].tagName&&"html"===this.offsetParent[0].tagName.toLowerCase()&&e.ui.ie)&&(t={top:0,left:0}),{top:t.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:t.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if("relative"===this.cssPosition){var e=this.currentItem.position();return{top:e.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:e.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 t,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.width():this.window.height()||this.document[0].body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top]),/^(document|window|parent)$/.test(n.containment)||(t=e(n.containment)[0],i=e(n.containment).offset(),s="hidden"!==e(t).css("overflow"),this.containment=[i.left+(parseInt(e(t).css("borderLeftWidth"),10)||0)+(parseInt(e(t).css("paddingLeft"),10)||0)-this.margins.left,i.top+(parseInt(e(t).css("borderTopWidth"),10)||0)+(parseInt(e(t).css("paddingTop"),10)||0)-this.margins.top,i.left+(s?Math.max(t.scrollWidth,t.offsetWidth):t.offsetWidth)-(parseInt(e(t).css("borderLeftWidth"),10)||0)-(parseInt(e(t).css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left,i.top+(s?Math.max(t.scrollHeight,t.offsetHeight):t.offsetHeight)-(parseInt(e(t).css("borderTopWidth"),10)||0)-(parseInt(e(t).css("paddingBottom"),10)||0)-this.helperProportions.height-this.margins.top])},_convertPositionTo:function(t,i){i||(i=this.position);var s="absolute"===t?1:-1,n="absolute"!==this.cssPosition||this.scrollParent[0]!==this.document[0]&&e.contains(this.scrollParent[0],this.offsetParent[0])?this.scrollParent:this.offsetParent,a=/(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():a?0:n.scrollTop())*s,left:i.left+this.offset.relative.left*s+this.offset.parent.left*s-("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():a?0:n.scrollLeft())*s}},_generatePosition:function(t){var i,s,n=this.options,a=t.pageX,o=t.pageY,r="absolute"!==this.cssPosition||this.scrollParent[0]!==this.document[0]&&e.contains(this.scrollParent[0],this.offsetParent[0])?this.scrollParent:this.offsetParent,h=/(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&&(t.pageX-this.offset.click.left<this.containment[0]&&(a=this.containment[0]+this.offset.click.left),t.pageY-this.offset.click.top<this.containment[1]&&(o=this.containment[1]+this.offset.click.top),t.pageX-this.offset.click.left>this.containment[2]&&(a=this.containment[2]+this.offset.click.left),t.pageY-this.offset.click.top>this.containment[3]&&(o=this.containment[3]+this.offset.click.top)),n.grid&&(i=this.originalPageY+Math.round((o-this.originalPageY)/n.grid[1])*n.grid[1],o=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((a-this.originalPageX)/n.grid[0])*n.grid[0],a=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:o-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+("fixed"===this.cssPosition?-this.scrollParent.scrollTop():h?0:r.scrollTop()),left:a-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():h?0:r.scrollLeft())}},_rearrange:function(e,t,i,s){i?i[0].appendChild(this.placeholder[0]):t.item[0].parentNode.insertBefore(this.placeholder[0],"down"===this.direction?t.item[0]:t.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(e,t){function i(e,t,i){return function(s){i._trigger(e,s,t._uiHash(t))}}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&&!t&&n.push(function(e){this._trigger("receive",e,this._uiHash(this.fromOutside))}),!this.fromOutside&&this.domPosition.prev===this.currentItem.prev().not(".ui-sortable-helper")[0]&&this.domPosition.parent===this.currentItem.parent()[0]||t||n.push(function(e){this._trigger("update",e,this._uiHash())}),this!==this.currentContainer&&(t||(n.push(function(e){this._trigger("remove",e,this._uiHash())}),n.push(function(e){return function(t){e._trigger("receive",t,this._uiHash(this))}}.call(this,this.currentContainer)),n.push(function(e){return function(t){e._trigger("update",t,this._uiHash(this))}}.call(this,this.currentContainer)))),s=this.containers.length-1;s>=0;s--)t||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,t||this._trigger("beforeStop",e,this._uiHash()),this.placeholder[0].parentNode.removeChild(this.placeholder[0]),this.cancelHelperRemoval||(this.helper[0]!==this.currentItem[0]&&this.helper.remove(),this.helper=null),!t){for(s=0;n.length>s;s++)n[s].call(this,e);this._trigger("stop",e,this._uiHash())}return this.fromOutside=!1,!this.cancelHelperRemoval},_trigger:function(){e.Widget.prototype._trigger.apply(this,arguments)===!1&&this.cancel()},_uiHash:function(t){var i=t||this;return{helper:i.helper,placeholder:i.placeholder||e([]),position:i.position,originalPosition:i.originalPosition,offset:i.positionAbs,item:i.currentItem,sender:t?t.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.bind({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.unbind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery);
|
||
|
||
},{}],39:[function(require,module,exports){
|
||
|
||
},{}],40:[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":41,"./socket":43,"./url":44,"debug":48,"socket.io-parser":81}],41:[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":42,"./socket":43,"backo2":45,"component-bind":46,"component-emitter":47,"debug":48,"engine.io-client":51,"indexof":78,"socket.io-parser":81}],42:[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);
|
||
}
|
||
};
|
||
}
|
||
|
||
},{}],43:[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":42,"component-bind":46,"component-emitter":47,"debug":48,"has-binary":76,"socket.io-parser":81,"to-array":86}],44:[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":48,"parseuri":79}],45:[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;
|
||
};
|
||
|
||
|
||
},{}],46:[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)));
|
||
}
|
||
};
|
||
|
||
},{}],47:[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;
|
||
};
|
||
|
||
},{}],48:[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":49}],49:[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":50}],50:[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';
|
||
}
|
||
|
||
},{}],51:[function(require,module,exports){
|
||
|
||
module.exports = require('./lib/');
|
||
|
||
},{"./lib/":52}],52:[function(require,module,exports){
|
||
|
||
module.exports = require('./socket');
|
||
|
||
/**
|
||
* Exports parser
|
||
*
|
||
* @api public
|
||
*
|
||
*/
|
||
module.exports.parser = require('engine.io-parser');
|
||
|
||
},{"./socket":53,"engine.io-parser":63}],53:[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 ? null : 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":54,"./transports":55,"component-emitter":61,"debug":48,"engine.io-parser":63,"indexof":78,"parsejson":73,"parseqs":74,"parseuri":79}],54:[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":61,"engine.io-parser":63}],55:[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":56,"./polling-xhr":57,"./websocket":59,"xmlhttprequest-ssl":60}],56:[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":58,"component-inherit":62}],57:[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":58,"component-emitter":61,"component-inherit":62,"debug":48,"xmlhttprequest-ssl":60}],58:[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":54,"component-inherit":62,"debug":48,"engine.io-parser":63,"parseqs":74,"xmlhttprequest-ssl":60,"yeast":75}],59:[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":54,"component-inherit":62,"debug":48,"engine.io-parser":63,"parseqs":74,"ws":39,"yeast":75}],60:[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":72}],61:[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;
|
||
};
|
||
|
||
},{}],62:[function(require,module,exports){
|
||
|
||
module.exports = function(a, b){
|
||
var fn = function(){};
|
||
fn.prototype = b.prototype;
|
||
a.prototype = new fn;
|
||
a.prototype.constructor = a;
|
||
};
|
||
},{}],63:[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":64,"after":65,"arraybuffer.slice":66,"base64-arraybuffer":67,"blob":68,"has-binary":69,"utf8":71}],64:[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;
|
||
};
|
||
|
||
},{}],65:[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() {}
|
||
|
||
},{}],66:[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;
|
||
};
|
||
|
||
},{}],67:[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+/");
|
||
|
||
},{}],68:[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 : {})
|
||
},{}],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(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":70}],70:[function(require,module,exports){
|
||
module.exports = Array.isArray || function (arr) {
|
||
return Object.prototype.toString.call(arr) == '[object Array]';
|
||
};
|
||
|
||
},{}],71:[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 : {})
|
||
},{}],72:[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;
|
||
}
|
||
|
||
},{}],73:[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 : {})
|
||
},{}],74:[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;
|
||
};
|
||
|
||
},{}],75:[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;
|
||
|
||
},{}],76:[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":77}],77:[function(require,module,exports){
|
||
arguments[4][70][0].apply(exports,arguments)
|
||
},{"dup":70}],78:[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;
|
||
};
|
||
},{}],79:[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;
|
||
};
|
||
|
||
},{}],80:[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":82,"isarray":84}],81:[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":80,"./is-buffer":82,"component-emitter":83,"debug":48,"isarray":84,"json3":85}],82:[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 : {})
|
||
},{}],83:[function(require,module,exports){
|
||
arguments[4][61][0].apply(exports,arguments)
|
||
},{"dup":61}],84:[function(require,module,exports){
|
||
arguments[4][70][0].apply(exports,arguments)
|
||
},{"dup":70}],85:[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 : {})
|
||
},{}],86:[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
|
||
}
|
||
|
||
},{}]},{},[33]);
|