McLighting/clients/pebble/configuration_page/public/js/slate.js

347 lines
47 KiB
JavaScript
Raw Normal View History

2016-06-04 23:26:30 +02:00
/*! Sortable 1.2.0 - MIT | git://github.com/rubaxa/Sortable.git */
!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=q({},b),a[H]=this;var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ";for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){t&&t.state!==a&&(i(t,"display",a?"none":""),!a&&t.state&&u.insertBefore(t,r),t.state=a)}function c(a,b){var c=P.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(P.call(arguments)))}}function d(a,b,c){if(a){c=c||J,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(G," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(G," ")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return J.defaultView&&J.defaultView.getComputedStyle?c=J.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){M=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function q(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var r,s,t,u,v,w,x,y,z,A,B,C,D,E,F={},G=/\s+/g,H="Sortable"+(new Date).getTime(),I=window,J=I.document,K=I.parseInt,L=!!("draggable"in J.createElement("div")),M=!1,N=function(a,b,c,d,e,f,g){var h=J.createEvent("Event"),i=(a||b[H]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.item=d||b,h.from=e||b,h.clone=t,h.oldIndex=f,h.newIndex=g,i[j]&&i[j].call(a,h),b.dispatchEvent(h)},O=Math.abs,P=[].slice,Q=[],R=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(x!==c&&(w=b.scroll,x=c,w===!0)){w=c;do if(w.offsetWidth<w.scrollWidth||w.offsetHeight<w.scrollHeight)break;while(w=w.parentNode)}w&&(d=w,e=w.getBoundingClientRect(),f=(O(e.right-j)<=h)-(O(e.left-j)<=h),g=(O(e.bottom-k)<=h)-(O(e.top-k)<=h)),f||g||(f=(h>=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=I)),(F.vx!==f||F.vy!==g||F.el!==d)&&(F.el=d,F.vx=f,F.vy=g,clearInterval(F.pid),d&&(F.pid=setInterval(function(){d===I?I.scrollTo(I.pageXOffset+f*i,I.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollL
/* Zepto v1.1.6 - zepto event ajax form ie - zeptojs.com/license */
var Zepto=function(){function L(t){return null==t?String(t):j[S.call(t)]||"object"}function Z(t){return"function"==L(t)}function _(t){return null!=t&&t==t.window}function $(t){return null!=t&&t.nodeType==t.DOCUMENT_NODE}function D(t){return"object"==L(t)}function M(t){return D(t)&&!_(t)&&Object.getPrototypeOf(t)==Object.prototype}function R(t){return"number"==typeof t.length}function k(t){return s.call(t,function(t){return null!=t})}function z(t){return t.length>0?n.fn.concat.apply([],t):t}function F(t){return t.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()}function q(t){return t in f?f[t]:f[t]=new RegExp("(^|\\s)"+t+"(\\s|$)")}function H(t,e){return"number"!=typeof e||c[F(t)]?e:e+"px"}function I(t){var e,n;return u[t]||(e=a.createElement(t),a.body.appendChild(e),n=getComputedStyle(e,"").getPropertyValue("display"),e.parentNode.removeChild(e),"none"==n&&(n="block"),u[t]=n),u[t]}function V(t){return"children"in t?o.call(t.children):n.map(t.childNodes,function(t){return 1==t.nodeType?t:void 0})}function B(n,i,r){for(e in i)r&&(M(i[e])||A(i[e]))?(M(i[e])&&!M(n[e])&&(n[e]={}),A(i[e])&&!A(n[e])&&(n[e]=[]),B(n[e],i[e],r)):i[e]!==t&&(n[e]=i[e])}function U(t,e){return null==e?n(t):n(t).filter(e)}function J(t,e,n,i){return Z(e)?e.call(t,n,i):e}function X(t,e,n){null==n?t.removeAttribute(e):t.setAttribute(e,n)}function W(e,n){var i=e.className||"",r=i&&i.baseVal!==t;return n===t?r?i.baseVal:i:void(r?i.baseVal=n:e.className=n)}function Y(t){try{return t?"true"==t||("false"==t?!1:"null"==t?null:+t+""==t?+t:/^[\[\{]/.test(t)?n.parseJSON(t):t):t}catch(e){return t}}function G(t,e){e(t);for(var n=0,i=t.childNodes.length;i>n;n++)G(t.childNodes[n],e)}var t,e,n,i,C,N,r=[],o=r.slice,s=r.filter,a=window.document,u={},f={},c={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},l=/^\s*<(\w+|!)[^>]*>/,h=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,p=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,d=/^(?:body|html)$/i,m=/([A-Z])/g,g=["val","css","html","text","data","width","height","offset"],v=["after","prepend","before","append"],y=a.createElement("table"),x=a.createElement("tr"),b={tr:a.createElement("tbody"),tbody:y,thead:y,tfoot:y,td:x,th:x,"*":a.createElement("div")},w=/complete|loaded|interactive/,E=/^[\w-]*$/,j={},S=j.toString,T={},O=a.createElement("div"),P={tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},A=Array.isArray||function(t){return t instanceof Array};return T.matches=function(t,e){if(!e||!t||1!==t.nodeType)return!1;var n=t.webkitMatchesSelector||t.mozMatchesSelector||t.oMatchesSelector||t.matchesSelector;if(n)return n.call(t,e);var i,r=t.parentNode,o=!r;return o&&(r=O).appendChild(t),i=~T.qsa(r,e).indexOf(t),o&&O.removeChild(t),i},C=function(t){return t.replace(/-+(.)?/g,function(t,e){return e?e.toUpperCase():""})},N=function(t){return s.call(t,function(e,n){return t.indexOf(e)==n})},T.fragment=function(e,i,r){var s,u,f;return h.test(e)&&(s=n(a.createElement(RegExp.$1))),s||(e.replace&&(e=e.replace(p,"<$1></$2>")),i===t&&(i=l.test(e)&&RegExp.$1),i in b||(i="*"),f=b[i],f.innerHTML=""+e,s=n.each(o.call(f.childNodes),function(){f.removeChild(this)})),M(r)&&(u=n(s),n.each(r,function(t,e){g.indexOf(t)>-1?u[t](e):u.attr(t,e)})),s},T.Z=function(t,e){return t=t||[],t.__proto__=n.fn,t.selector=e||"",t},T.isZ=function(t){return t instanceof T.Z},T.init=function(e,i){var r;if(!e)return T.Z();if("string"==typeof e)if(e=e.trim(),"<"==e[0]&&l.test(e))r=T.fragment(e,RegExp.$1,i),e=null;else{if(i!==t)return n(i).find(e);r=T.qsa(a,e)}else{if(Z(e))return n(a).ready(e);if(T.isZ(e))return e;if(A(e))r=k(e);else if(D(e))r=[e],e=null;else if(l.test(e))r=T.fragment(e.trim(),RegExp.$1,i),e=null;else{if(i!==t)return n(i).find(e);r=T.qsa(a,e)}}return T.Z(r,e)},n=function(t,e){return T.init(t,e)},n.extend=function(
'use strict';
(function($, Sortable) {
var ENUMS = {
COLOR : {
EMPTY: 'transparent'
}
}
$.extend($.fn, {
itemToggle: function() {
this.each(function() {
var $checkbox = $(this);
var item = $checkbox.parent();
var $injectedCheckbox = $('<div class="item-styled-toggle-wrapper">'
+ '<div class="item-styled-toggle">'
+ '<div class="item-styled-toggle-bar"></div>'
+ '<div class="item-styled-toggle-bar"></div>'
+ '<div class="item-styled-toggle-bar"></div>'
+ '</div>'
+ '</div>');
item.append($injectedCheckbox);
});
},
itemCheckbox: function() {
this.each(function() {
var $checkbox = $(this);
var item = $checkbox.parent();
var $injectedCheckbox = $('<div class="item-styled-checkbox"></div>');
item.append($injectedCheckbox);
});
},
itemSelect: function() {
this.each(function() {
var $select = $(this);
var $item = $select.parent();
$item.append('<div class="select-triangle"></div>');
});
},
itemDate: function() {
this.each(function() {
var $date = $(this);
var $item = $date.parent();
var $injectedDate = $('<div class="item-styled-date"></div>');
updateDate();
$item.append($injectedDate);
$date.change(function() {
updateDate();
});
function updateDate() {
$injectedDate.text($date.val());
}
});
},
itemTime: function() {
this.each(function() {
var $time = $(this);
var $item = $time.parent();
var $injectedTime = $('<div class="item-styled-time"></div>');
updateTime();
$item.append($injectedTime);
$time.change(function() {
updateTime();
});
function updateTime() {
$injectedTime.text($time.val());
}
});
},
itemRadio: function() {
this.each(function() {
var $radio = $(this);
var $item = $radio.parent();
var $injectedRadio = $('<div class="item-styled-radio"></div>');
$item.append($injectedRadio);
});
},
itemColor: function(options){
var options = $.extend({}, {
sunny: false
}, options || {});
var layout = [
[false , false , '#55FF00', '#AAFF55', false , '#FFFF55', '#FFFFAA', false , false ],
[false , '#AAFFAA', '#55FF55', '#00FF00', '#AAFF00', '#FFFF00', '#FFAA55', '#FFAAAA', false ],
['#55FFAA', '#00FF55', '#00AA00', '#55AA00', '#AAAA55', '#AAAA00', '#FFAA00', '#FF5500', '#FF5555'],
['#AAFFFF', '#00FFAA', '#00AA55', '#55AA55', '#005500', '#555500', '#AA5500', '#FF0000', '#FF0055'],
[false , '#55AAAA', '#00AAAA', '#005555', '#FFFFFF', '#000000', '#AA5555', '#AA0000', false ],
['#55FFFF', '#00FFFF', '#00AAFF', '#0055AA', '#AAAAAA', '#555555', '#550000', '#AA0055', '#FF55AA'],
['#55AAFF', '#0055FF', '#0000FF', '#0000AA', '#000055', '#550055', '#AA00AA', '#FF00AA', '#FFAAFF'],
[false , '#5555AA', '#5555FF', '#5500FF', '#5500AA', '#AA00FF', '#FF00FF', '#FF55FF', false ],
[false , false , false , '#AAAAFF', '#AA55FF', '#AA55AA', false , false , false ],
];
var mappingSunny = {'000000': '000000','000055': '001e41','0000aa': '004387',
'0000ff': '0068ca','005500': '2b4a2c','005555': '27514f',
'0055aa': '16638d','0055ff': '007dce','00aa00': '5e9860',
'00aa55': '5c9b72','00aaaa': '57a5a2','00aaff': '4cb4db',
'00ff00': '8ee391','00ff55': '8ee69e','00ffaa': '8aebc0',
'00ffff': '84f5f1','550000': '4a161b','550055': '482748',
'5500aa': '40488a','5500ff': '2f6bcc','555500': '564e36',
'555555': '545454','5555aa': '4f6790','5555ff': '4180d0',
'55aa00': '759a64','55aa55': '759d76','55aaaa': '71a6a4',
'55aaff': '69b5dd','55ff00': '9ee594','55ff55': '9de7a0',
'55ffaa': '9becc2','55ffff': '95f6f2','aa0000': '99353f',
'aa0055': '983e5a','aa00aa': '955694','aa00ff': '8f74d2',
'aa5500': '9d5b4d','aa5555': '9d6064','aa55aa': '9a7099',
'aa55ff': '9587d5','aaaa00': 'afa072','aaaa55': 'aea382',
'aaaaaa': 'ababab','ffffff': 'ffffff','aaaaff': 'a7bae2',
'aaff00': 'c9e89d','aaff55': 'c9eaa7','aaffaa': 'c7f0c8',
'aaffff': 'c3f9f7','ff0000': 'e35462','ff0055': 'e25874',
'ff00aa': 'e16aa3','ff00ff': 'de83dc','ff5500': 'e66e6b',
'ff5555': 'e6727c','ff55aa': 'e37fa7','ff55ff': 'e194df',
'ffaa00': 'f1aa86','ffaa55': 'f1ad93','ffaaaa': 'efb5b8',
'ffaaff': 'ecc3eb','ffff00': 'ffeeab','ffff55': 'fff1b5',
'ffffaa': 'fff6d3'};
this.each(function() {
var $color = $(this);
var $item = $color.parent();
var grid = '';
var itemWidth = 100 / layout[0].length;
var itemHeight = 100 / layout.length;
var boxHeight = itemWidth * layout.length;
for(var i = 0; i < layout.length; i++) {
for(var j = 0; j < layout[i].length; j++) {
var color = layout[i][j] || ENUMS.COLOR.EMPTY;
var selectable = (color !== ENUMS.COLOR.EMPTY ? ' selectable' : '');
var roundedTL = (i === 0 && j === 0)
|| i === 0 && !layout[i][j - 1]
|| !layout[i][j - 1] && !layout[i -1][j]
? ' rounded-tl' : '';
var roundedTR = i === 0 && !layout[i][j + 1]
|| !layout[i][j + 1] && !layout[i -1][j]
? ' rounded-tr ' : '';
var roundedBL = (i === layout.length - 1 && j === 0)
|| i === layout.length - 1 && !layout[i][j - 1]
|| !layout[i][j - 1] && !layout[i + 1][j]
? ' rounded-bl' : '';
var roundedBR = i === layout.length - 1 && !layout[i][j + 1]
|| !layout[i][j + 1] && !layout[i + 1][j]
? ' rounded-br' : '';
if(options.sunny && color !== ENUMS.COLOR.EMPTY) {
color = '#' + mappingSunny[color.replace('#', '').toLowerCase()];
}
grid += '<i ' +
'class="color-box ' + selectable + roundedTL +
roundedTR + roundedBL + roundedBR + '" ' +
'data-value="' + color.replace(/^#/, '0x') + '" ' +
'style="' +
'width:' + itemWidth + '%; ' +
'height:' + itemHeight + '%; ' +
'background:' + color + ';">' +
'</i>';
}
}
var $injectedColor = $('<div class="item-styled-color">' +
'<span class="value" style="background:' + $color.val().replace(/^0x/, '#') + '"></span>' +
'<div ' +
'style="padding-bottom:' + boxHeight + '%"' +
'class="color-box-wrap">' +
'<div class="color-box-container">' +
grid +
'</div>' +
'</div>' +
'</div>');
$item.append($injectedColor);
var $valueDisplay = $injectedColor.find('.value');
$color.on('click', function(ev) {
$item.find('.color-box-wrap').toggleClass('show');
});
$item.find('.color-box.selectable').on('click', function(ev) {
ev.preventDefault();
var value = $(this).data('value');
$color.val(value);
$valueDisplay.css('background-color', value.replace(/^0x/, '#'));
$item.find('.color-box-wrap').removeClass('show');
})
});
},
tab: function() {
this.each(function() {
var $tab = $(this);
$tab.click(function() {
var $current = $(this);
var name = $current.attr('name');
$('a[name=' + name + ']').each(function(){
$(this).removeClass('active');
});
$current.addClass('active');
});
});
},
itemSlider: function() {
this.each(function() {
var $slider = $(this);
var name = $slider.attr('name');
var $input = $('input[name=' + name + '][class=item-input]');
$slider.on('input', function() {
var $current = $(this);
$input.val($current.val());
});
$input.change(function() {
var $current = $(this);
$slider.val($current.val());
});
});
},
itemDraggableList: function() {
this.each(function() {
var $handlebar = '<div class="item-draggable-handle">'
+ '<div class="item-draggable-handle-bar"></div>'
+ '<div class="item-draggable-handle-bar"></div>'
+ '<div class="item-draggable-handle-bar"></div>'
+ '</div>';
$(this).children('label').append($handlebar);
Sortable.create(this, {
handle: '.item-draggable-handle'
});
});
},
itemDynamicList: function() {
this.each(function() {
var $list = $(this);
$list.children('label').each(function() {
var $deleteButton = $('<div class="delete-item"></div>');
$deleteButton.click(function() {
$(this).parent().remove();
});
$(this).append($deleteButton);
});
var $addButton = $('<div class="item add-item">Add one more...</div>');
$list.append($addButton);
$addButton.click(function() {
var $inbox = $('<div class="item">'
+ '<div class="item-input-wrapper">'
+ '<input class="item-input" type="text" name="focus-box">'
+ '</div>'
+ '</div>');
$inbox.insertBefore($list.children().last());
var $input = $inbox.find('input');
$input.focus();
$input.keypress(function(e) {
var key = e.which;
if (key === 13) {
stopEditing($input, $inbox);
}
});
$input.focusout(function() {
stopEditing($input, $inbox);
});
function stopEditing(input, inbox) {
var text = input.val();
inbox.text(text);
var deletebutton = $('<div class="delete-item"></div>');
deletebutton.click(function(){
$(this).parent().remove();
});
inbox.append(deletebutton);
}
});
});
}
});
$(function() {
$('.item-toggle').itemToggle();
$('.item-checkbox').itemCheckbox();
$('.item-select').itemSelect();
$('.item-date').itemDate();
$('.item-time').itemTime();
$('.item-radio').itemRadio();
$('.item-color-normal').itemColor({sunny: false});
$('.item-color-sunny').itemColor({sunny: true});
$('.tab-button').tab();
$('.item-slider').itemSlider();
$('.item-draggable-list').itemDraggableList();
$('.item-dynamic-list').itemDynamicList();
});
}(Zepto, Sortable));