First Initial

This commit is contained in:
Nakorn Rientrakrunchai
2020-02-20 15:02:39 +07:00
commit 8b98125e49
3048 changed files with 760804 additions and 0 deletions

View File

@@ -0,0 +1,207 @@
/*
* Fuel UX Spinner
* https://github.com/ExactTarget/fuelux
*
* Copyright (c) 2012 ExactTarget
* Licensed under the MIT license.
*/
!function ($) {
// SPINNER CONSTRUCTOR AND PROTOTYPE
var Spinner = function (element, options) {
this.$element = $(element);
this.options = $.extend({}, $.fn.spinner.defaults, options);
this.$input = this.$element.find('.spinner-input');
this.$element.on('keyup', this.$input, $.proxy(this.change, this));
if (this.options.hold) {
this.$element.on('mousedown', '.spinner-up', $.proxy(function() { this.startSpin(true); } , this));
this.$element.on('mouseup', '.spinner-up, .spinner-down', $.proxy(this.stopSpin, this));
this.$element.on('mouseout', '.spinner-up, .spinner-down', $.proxy(this.stopSpin, this));
this.$element.on('mousedown', '.spinner-down', $.proxy(function() {this.startSpin(false);} , this));
} else {
this.$element.on('click', '.spinner-up', $.proxy(function() { this.step(true); } , this));
this.$element.on('click', '.spinner-down', $.proxy(function() { this.step(false); }, this));
}
this.switches = {
count: 1,
enabled: true
};
if (this.options.speed === 'medium') {
this.switches.speed = 300;
} else if (this.options.speed === 'fast') {
this.switches.speed = 100;
} else {
this.switches.speed = 500;
}
this.lastValue = null;
this.render();
if (this.options.disabled) {
this.disable();
}
};
Spinner.prototype = {
constructor: Spinner,
render: function () {
var inputValue = this.$input.val();
if (inputValue) {
this.value(inputValue);
} else {
this.$input.val(this.options.value);
}
this.$input.attr('maxlength', (this.options.max + '').split('').length);
},
change: function () {
var newVal = this.$input.val();
if(newVal/1){
this.options.value = newVal/1;
}else{
newVal = newVal.replace(/[^0-9]/g,'');
this.$input.val(newVal);
this.options.value = newVal/1;
}
this.triggerChangedEvent();
},
stopSpin: function () {
clearTimeout(this.switches.timeout);
this.switches.count = 1;
this.triggerChangedEvent();
},
triggerChangedEvent: function () {
var currentValue = this.value();
if (currentValue === this.lastValue) return;
this.lastValue = currentValue;
// Primary changed event
this.$element.trigger('changed', currentValue);
// Undocumented, kept for backward compatibility
this.$element.trigger('change');
},
startSpin: function (type) {
if (!this.options.disabled) {
var divisor = this.switches.count;
if (divisor === 1) {
this.step(type);
divisor = 1;
} else if (divisor < 3){
divisor = 1.5;
} else if (divisor < 8){
divisor = 2.5;
} else {
divisor = 4;
}
this.switches.timeout = setTimeout($.proxy(function() {this.iterator(type);} ,this),this.switches.speed/divisor);
this.switches.count++;
}
},
iterator: function (type) {
this.step(type);
this.startSpin(type);
},
step: function (dir) {
var curValue = this.options.value;
var limValue = dir ? this.options.max : this.options.min;
if ((dir ? curValue < limValue : curValue > limValue)) {
var newVal = curValue + (dir ? 1 : -1) * this.options.step;
if (dir ? newVal > limValue : newVal < limValue) {
this.value(limValue);
} else {
this.value(newVal);
}
} else if (this.options.cycle) {
var cycleVal = dir ? this.options.min : this.options.max;
this.value(cycleVal);
}
},
value: function (value) {
if (!isNaN(parseFloat(value)) && isFinite(value)) {
value = parseFloat(value);
this.options.value = value;
this.$input.val(value);
return this;
} else {
return this.options.value;
}
},
disable: function () {
this.options.disabled = true;
this.$input.attr('disabled','');
this.$element.find('button').addClass('disabled');
},
enable: function () {
this.options.disabled = false;
this.$input.removeAttr("disabled");
this.$element.find('button').removeClass('disabled');
}
};
// SPINNER PLUGIN DEFINITION
$.fn.spinner = function (option,value) {
var methodReturn;
var $set = this.each(function () {
var $this = $(this);
var data = $this.data('spinner');
var options = typeof option === 'object' && option;
if (!data) $this.data('spinner', (data = new Spinner(this, options)));
if (typeof option === 'string') methodReturn = data[option](value);
});
return (methodReturn === undefined) ? $set : methodReturn;
};
$.fn.spinner.defaults = {
value: 1,
min: 1,
max: 999,
step: 1,
hold: true,
speed: 'medium',
disabled: false
};
$.fn.spinner.Constructor = Spinner;
// SPINNER DATA-API
$(function () {
$('body').on('mousedown.spinner.data-api', '.spinner', function () {
var $this = $(this);
if ($this.data('spinner')) return;
$this.spinner($this.data());
});
});
}(window.jQuery);

View File

@@ -0,0 +1,9 @@
/*
* Fuel UX Spinner
* https://github.com/ExactTarget/fuelux
*
* Copyright (c) 2012 ExactTarget
* Licensed under the MIT license.
*/
!function(e){var t=function(t,i){this.$element=e(t),this.options=e.extend({},e.fn.spinner.defaults,i),this.$input=this.$element.find(".spinner-input"),this.$element.on("keyup",this.$input,e.proxy(this.change,this)),this.options.hold?(this.$element.on("mousedown",".spinner-up",e.proxy(function(){this.startSpin(!0)},this)),this.$element.on("mouseup",".spinner-up, .spinner-down",e.proxy(this.stopSpin,this)),this.$element.on("mouseout",".spinner-up, .spinner-down",e.proxy(this.stopSpin,this)),this.$element.on("mousedown",".spinner-down",e.proxy(function(){this.startSpin(!1)},this))):(this.$element.on("click",".spinner-up",e.proxy(function(){this.step(!0)},this)),this.$element.on("click",".spinner-down",e.proxy(function(){this.step(!1)},this))),this.switches={count:1,enabled:!0},this.switches.speed="medium"===this.options.speed?300:"fast"===this.options.speed?100:500,this.lastValue=null,this.render(),this.options.disabled&&this.disable()};t.prototype={constructor:t,render:function(){var e=this.$input.val();e?this.value(e):this.$input.val(this.options.value),this.$input.attr("maxlength",(this.options.max+"").split("").length)},change:function(){var e=this.$input.val();e/1?this.options.value=e/1:(e=e.replace(/[^0-9]/g,""),this.$input.val(e),this.options.value=e/1),this.triggerChangedEvent()},stopSpin:function(){clearTimeout(this.switches.timeout),this.switches.count=1,this.triggerChangedEvent()},triggerChangedEvent:function(){var e=this.value();e!==this.lastValue&&(this.lastValue=e,this.$element.trigger("changed",e),this.$element.trigger("change"))},startSpin:function(t){if(!this.options.disabled){var i=this.switches.count;1===i?(this.step(t),i=1):i=3>i?1.5:8>i?2.5:4,this.switches.timeout=setTimeout(e.proxy(function(){this.iterator(t)},this),this.switches.speed/i),this.switches.count++}},iterator:function(e){this.step(e),this.startSpin(e)},step:function(e){var t=this.options.value,i=e?this.options.max:this.options.min;if(e?i>t:t>i){var s=t+(e?1:-1)*this.options.step;(e?s>i:i>s)?this.value(i):this.value(s)}else if(this.options.cycle){var n=e?this.options.min:this.options.max;this.value(n)}},value:function(e){return!isNaN(parseFloat(e))&&isFinite(e)?(e=parseFloat(e),this.options.value=e,this.$input.val(e),this):this.options.value},disable:function(){this.options.disabled=!0,this.$input.attr("disabled",""),this.$element.find("button").addClass("disabled")},enable:function(){this.options.disabled=!1,this.$input.removeAttr("disabled"),this.$element.find("button").removeClass("disabled")}},e.fn.spinner=function(i,s){var n,a=this.each(function(){var a=e(this),o=a.data("spinner"),r="object"==typeof i&&i;o||a.data("spinner",o=new t(this,r)),"string"==typeof i&&(n=o[i](s))});return void 0===n?a:n},e.fn.spinner.defaults={value:1,min:1,max:999,step:1,hold:!0,speed:"medium",disabled:!1},e.fn.spinner.Constructor=t,e(function(){e("body").on("mousedown.spinner.data-api",".spinner",function(){var t=e(this);t.data("spinner")||t.spinner(t.data())})})}(window.jQuery);

View File

@@ -0,0 +1,232 @@
/*
* Fuel UX Spinner
* https://github.com/ExactTarget/fuelux
* Copyright (c) 2012 ExactTarget
* Licensed under the MIT license.
*/
!function ($) {
var Tree = function (element, options) {
this.$element = $(element);
this.options = $.extend({}, $.fn.tree.defaults, options);
this.$element.on('click', '.tree-item', $.proxy( function(ev) { this.selectItem(ev.currentTarget); } ,this));
this.$element.on('click', '.tree-folder-header', $.proxy( function(ev) { this.selectFolder(ev.currentTarget); }, this));
this.render();
};
Tree.prototype = {
constructor: Tree,
render: function () {
this.populate(this.$element);
},
populate: function ($el) {
var self = this;
var $parent = $el.parent();
var loader = $parent.find('.tree-loader:eq(0)');
loader.show();
this.options.dataSource.data($el.data(), function (items) {
loader.hide();
$.each( items.data, function(index, value) {
var $entity;
if(value.type === "folder") {
$entity = self.$element.find('.tree-folder:eq(0)').clone().show();
$entity.find('.tree-folder-name').html(value.name);
$entity.find('.tree-loader').html(self.options.loadingHTML);
$entity.find('.tree-folder-header').data(value);
} else if (value.type === "item") {
$entity = self.$element.find('.tree-item:eq(0)').clone().show();
$entity.find('.tree-item-name').html(value.name);
$entity.data(value);
}
// Decorate $entity with data making the element
// easily accessable with libraries like jQuery.
//
// Values are contained within the object returned
// for folders and items as dataAttributes:
//
// {
// name: "An Item",
// type: 'item',
// dataAttributes = {
// 'classes': 'required-item red-text',
// 'data-parent': parentId,
// 'guid': guid
// }
// };
var dataAttributes = value.dataAttributes || [];
$.each(dataAttributes, function(key, value) {
switch (key) {
case 'class':
case 'classes':
case 'className':
$entity.addClass(value);
break;
// id, style, data-*
default:
$entity.attr(key, value);
break;
}
});
if($el.hasClass('tree-folder-header')) {
$parent.find('.tree-folder-content:eq(0)').append($entity);
} else {
$el.append($entity);
}
});
// return newly populated folder
self.$element.trigger('loaded', $parent);
});
},
selectItem: function (el) {
var $el = $(el);
var $all = this.$element.find('.tree-selected');
var data = [];
if (this.options.multiSelect) {
$.each($all, function(index, value) {
var $val = $(value);
if($val[0] !== $el[0]) {
data.push( $(value).data() );
}
});
} else if ($all[0] !== $el[0]) {
$all.removeClass('tree-selected')
.find('i').removeClass('icon-ok').addClass('tree-dot');
data.push($el.data());
}
if (this.options.selectable) {
var eventType = 'selected';
if($el.hasClass('tree-selected')) {
eventType = 'unselected';
$el.removeClass('tree-selected');
$el.find('i').removeClass('icon-ok').addClass('tree-dot');
} else {
$el.addClass ('tree-selected');
$el.find('i').removeClass('tree-dot').addClass('icon-ok');
if (this.options.multiSelect) {
data.push( $el.data() );
}
}
}
if(data.length) {
this.$element.trigger('selected', {info: data});
}
// Return new list of selected items, the item
// clicked, and the type of event:
$el.trigger('updated', {
info: data,
item: $el,
eventType: eventType
});
},
selectFolder: function (el) {
var $el = $(el);
var $parent = $el.parent();
var $treeFolderContent = $parent.find('.tree-folder-content');
var $treeFolderContentFirstChild = $treeFolderContent.eq(0);
var eventType, classToTarget, classToAdd;
if ($el.find('.icon-folder-close').length) {
eventType = 'opened';
classToTarget = '.icon-folder-close';
classToAdd = 'icon-folder-open';
$treeFolderContentFirstChild.show();
if (!$treeFolderContent.children().length) {
this.populate($el);
}
} else {
eventType = 'closed';
classToTarget = '.icon-folder-open';
classToAdd = 'icon-folder-close';
$treeFolderContentFirstChild.hide();
if (!this.options.cacheItems) {
$treeFolderContentFirstChild.empty();
}
}
$parent.find(classToTarget).eq(0)
.removeClass('icon-folder-close icon-folder-open')
.addClass(classToAdd);
this.$element.trigger(eventType, $el.data());
},
selectedItems: function () {
var $sel = this.$element.find('.tree-selected');
var data = [];
$.each($sel, function (index, value) {
data.push($(value).data());
});
return data;
},
// collapses open folders
collapse: function () {
var cacheItems = this.options.cacheItems;
// find open folders
this.$element.find('.icon-folder-open').each(function () {
// update icon class
var $this = $(this)
.removeClass('icon-folder-close icon-folder-open')
.addClass('icon-folder-close');
// "close" or empty folder contents
var $parent = $this.parent().parent();
var $folder = $parent.children('.tree-folder-content');
$folder.hide();
if (!cacheItems) {
$folder.empty();
}
});
}
};
// TREE PLUGIN DEFINITION
$.fn.tree = function (option, value) {
var methodReturn;
var $set = this.each(function () {
var $this = $(this);
var data = $this.data('tree');
var options = typeof option === 'object' && option;
if (!data) $this.data('tree', (data = new Tree(this, options)));
if (typeof option === 'string') methodReturn = data[option](value);
});
return (methodReturn === undefined) ? $set : methodReturn;
};
$.fn.tree.defaults = {
selectable: true,
multiSelect: false,
loadingHTML: '<div>Loading...</div>',
cacheItems: true
};
$.fn.tree.Constructor = Tree;
}(window.jQuery);

View File

@@ -0,0 +1,8 @@
/*
* Fuel UX Spinner
* https://github.com/ExactTarget/fuelux
* Copyright (c) 2012 ExactTarget
* Licensed under the MIT license.
*/
!function(t){var e=function(e,i){this.$element=t(e),this.options=t.extend({},t.fn.tree.defaults,i),this.$element.on("click",".tree-item",t.proxy(function(t){this.selectItem(t.currentTarget)},this)),this.$element.on("click",".tree-folder-header",t.proxy(function(t){this.selectFolder(t.currentTarget)},this)),this.render()};e.prototype={constructor:e,render:function(){this.populate(this.$element)},populate:function(e){var i=this,n=e.parent(),r=n.find(".tree-loader:eq(0)");r.show(),this.options.dataSource.data(e.data(),function(o){r.hide(),t.each(o.data,function(r,o){var s;"folder"===o.type?(s=i.$element.find(".tree-folder:eq(0)").clone().show(),s.find(".tree-folder-name").html(o.name),s.find(".tree-loader").html(i.options.loadingHTML),s.find(".tree-folder-header").data(o)):"item"===o.type&&(s=i.$element.find(".tree-item:eq(0)").clone().show(),s.find(".tree-item-name").html(o.name),s.data(o));var a=o.dataAttributes||[];t.each(a,function(t,e){switch(t){case"class":case"classes":case"className":s.addClass(e);break;default:s.attr(t,e)}}),e.hasClass("tree-folder-header")?n.find(".tree-folder-content:eq(0)").append(s):e.append(s)}),i.$element.trigger("loaded",n)})},selectItem:function(e){var i=t(e),n=this.$element.find(".tree-selected"),r=[];if(this.options.multiSelect?t.each(n,function(e,n){var o=t(n);o[0]!==i[0]&&r.push(t(n).data())}):n[0]!==i[0]&&(n.removeClass("tree-selected").find("i").removeClass("fa fa-check").addClass("tree-dot"),r.push(i.data())),this.options.selectable){var o="selected";i.hasClass("tree-selected")?(o="unselected",i.removeClass("tree-selected"),i.find("i").removeClass("fa fa-check").addClass("tree-dot")):(i.addClass("tree-selected"),i.find("i").removeClass("tree-dot").addClass("fa fa-check"),this.options.multiSelect&&r.push(i.data()))}r.length&&this.$element.trigger("selected",{info:r}),i.trigger("updated",{info:r,item:i,eventType:o})},selectFolder:function(e){var i,n,r,o=t(e),s=o.parent(),a=s.find(".tree-folder-content"),l=a.eq(0);o.find(".fa.fa-folder").length?(i="opened",n=".fa.fa-folder",r="fa fa-folder-open",l.show(),a.children().length||this.populate(o)):(i="closed",n=".fa.fa-folder-open",r="fa fa-folder",l.hide(),this.options.cacheItems||l.empty()),s.find(n).eq(0).removeClass("fa fa-folder fa-folder-open").addClass(r),this.$element.trigger(i,o.data())},selectedItems:function(){var e=this.$element.find(".tree-selected"),i=[];return t.each(e,function(e,n){i.push(t(n).data())}),i},collapse:function(){var e=this.options.cacheItems;this.$element.find(".fa.fa-folder-open").each(function(){var i=t(this).removeClass("fa fa-folder fa-folder-open").addClass("fa fa-folder"),n=i.parent().parent(),r=n.children(".tree-folder-content");r.hide(),e||r.empty()})}},t.fn.tree=function(i,n){var r,o=this.each(function(){var o=t(this),s=o.data("tree"),a="object"==typeof i&&i;s||o.data("tree",s=new e(this,a)),"string"==typeof i&&(r=s[i](n))});return void 0===r?o:r},t.fn.tree.defaults={selectable:!0,multiSelect:!1,loadingHTML:"<div>Loading...</div>",cacheItems:!0},t.fn.tree.Constructor=e}(window.jQuery);