提交 09db0823 编写于 作者: C Catouse

* format javascript code.

上级 a7aeb428
......@@ -12,17 +12,17 @@
/// Add jquery object to namespace
/// (function(){ // Old code
(function($){
(function($) {
/// ----- ZUI change end -----
"use strict";
/// ----- ZUI change begin -----
/// Change root to zui shared object
///
/// var root = this, // old code
var root = $ && $.zui ? $.zui : this,
/// ----- ZUI change end -----
/// ----- ZUI change begin -----
/// Change root to zui shared object
///
/// var root = this, // old code
var root = $ && $.zui ? $.zui : this,
/// ----- ZUI change end -----
Chart = root.Chart,
helpers = Chart.helpers;
......@@ -46,22 +46,22 @@
//Boolean - Whether to show vertical lines (except Y axis)
scaleShowVerticalLines: true,
/// ZUI change begin
/// ZUI change begin
//Boolean - Whether to show beyond lines
scaleShowBeyondLine: true,
/// ZUI change end
///
/// ZUI change end
///
//Boolean - If there is a stroke on each bar
barShowStroke: true,
//Number - Pixel width of the bar stroke
/// ZUI change begin
/// barStrokeWidth: 2,
/// ZUI change begin
/// barStrokeWidth: 2,
barStrokeWidth: 1,
// String - Sacle value labels placement
scaleValuePlacement: 'auto', // none, auto, outside, inside-top, inside-middle, inside-bottom
/// ZUI change end
/// ZUI change end
//Number - Spacing between each of the X value sets
barValueSpacing: 5,
......@@ -74,21 +74,17 @@
};
Chart.Type.extend(
{
Chart.Type.extend({
name: "Bar",
defaults: defaultConfig,
initialize: function(data)
{
initialize: function(data) {
//Expose options as a scope variable here so we can access it in the ScaleClass
var options = this.options;
this.ScaleClass = Chart.Scale.extend(
{
this.ScaleClass = Chart.Scale.extend({
offsetGridLines: true,
calculateBarX: function(datasetCount, datasetIndex, barIndex)
{
calculateBarX: function(datasetCount, datasetIndex, barIndex) {
//Reusable method for calculating the xPosition of a given bar based on datasetIndex & width of the bar
var xWidth = this.calculateBaseWidth(),
xAbsolute = this.calculateX(barIndex) - (xWidth / 2),
......@@ -96,34 +92,28 @@
return xAbsolute + (barWidth * datasetIndex) + (datasetIndex * options.barDatasetSpacing) + barWidth / 2;
},
calculateBaseWidth: function()
{
return (this.calculateX(1) - this.calculateX(0)) - (2 * options.barValueSpacing);
calculateBaseWidth: function() {
return(this.calculateX(1) - this.calculateX(0)) - (2 * options.barValueSpacing);
},
calculateBarWidth: function(datasetCount)
{
calculateBarWidth: function(datasetCount) {
//The padding between datasets is to the right of each bar, providing that there are more than 1 dataset
var baseWidth = this.calculateBaseWidth() - ((datasetCount - 1) * options.barDatasetSpacing);
return (baseWidth / datasetCount);
return(baseWidth / datasetCount);
}
});
this.datasets = [];
//Set up tooltip events on the chart
if (this.options.showTooltips)
{
helpers.bindEvents(this, this.options.tooltipEvents, function(evt)
{
if(this.options.showTooltips) {
helpers.bindEvents(this, this.options.tooltipEvents, function(evt) {
var activeBars = (evt.type !== 'mouseout') ? this.getBarsAtEvent(evt) : [];
this.eachBars(function(bar)
{
this.eachBars(function(bar) {
bar.restore(['fillColor', 'strokeColor']);
});
helpers.each(activeBars, function(activeBar)
{
helpers.each(activeBars, function(activeBar) {
activeBar.fillColor = activeBar.highlightFill;
activeBar.strokeColor = activeBar.highlightStroke;
});
......@@ -132,27 +122,24 @@
}
//Declare the extension of the default point, to cater for the options passed in to the constructor
this.BarClass = Chart.Rectangle.extend(
{
this.BarClass = Chart.Rectangle.extend({
strokeWidth: this.options.barStrokeWidth,
showStroke: this.options.barShowStroke,
ctx: this.chart.ctx
});
//Iterate through each of the datasets, and build this into a property of the chart
helpers.each(data.datasets, function(dataset, datasetIndex)
{
/// ----- ZUI change begin -----
// add color theme
if($.zui && $.zui.Color && $.zui.Color.get)
{
helpers.each(data.datasets, function(dataset, datasetIndex) {
/// ----- ZUI change begin -----
// add color theme
if($.zui && $.zui.Color && $.zui.Color.get) {
var accentColor = $.zui.Color.get(dataset.color);
var accentColorValue = accentColor.toCssStr();
if(!dataset.fillColor) dataset.fillColor = accentColor.clone().fade(50).toCssStr();
if(!dataset.strokeColor) dataset.strokeColor = accentColorValue;
}
/// ----- ZUI change begin -----
/// ----- ZUI change begin -----
var datasetObject = {
label: dataset.label || null,
......@@ -163,11 +150,9 @@
this.datasets.push(datasetObject);
helpers.each(dataset.data, function(dataPoint, index)
{
helpers.each(dataset.data, function(dataPoint, index) {
//Add a new point for each piece of data, passing any required data to draw.
datasetObject.bars.push(new this.BarClass(
{
datasetObject.bars.push(new this.BarClass({
value: dataPoint,
label: data.labels[index],
datasetLabel: dataset.label,
......@@ -184,10 +169,8 @@
this.BarClass.prototype.base = this.scale.endPoint;
this.eachBars(function(bar, index, datasetIndex)
{
helpers.extend(bar,
{
this.eachBars(function(bar, index, datasetIndex) {
helpers.extend(bar, {
width: this.scale.calculateBarWidth(this.datasets.length),
x: this.scale.calculateBarX(this.datasets.length, datasetIndex, index),
y: this.scale.endPoint
......@@ -197,44 +180,34 @@
this.render();
},
update: function()
{
update: function() {
this.scale.update();
// Reset any highlight colours before updating.
helpers.each(this.activeElements, function(activeElement)
{
helpers.each(this.activeElements, function(activeElement) {
activeElement.restore(['fillColor', 'strokeColor']);
});
this.eachBars(function(bar)
{
this.eachBars(function(bar) {
bar.save();
});
this.render();
},
eachBars: function(callback)
{
helpers.each(this.datasets, function(dataset, datasetIndex)
{
eachBars: function(callback) {
helpers.each(this.datasets, function(dataset, datasetIndex) {
helpers.each(dataset.bars, callback, this, datasetIndex);
}, this);
},
getBarsAtEvent: function(e)
{
getBarsAtEvent: function(e) {
var barsArray = [],
eventPosition = helpers.getRelativePosition(e),
datasetIterator = function(dataset)
{
datasetIterator = function(dataset) {
barsArray.push(dataset.bars[barIndex]);
},
barIndex;
for (var datasetIndex = 0; datasetIndex < this.datasets.length; datasetIndex++)
{
for (barIndex = 0; barIndex < this.datasets[datasetIndex].bars.length; barIndex++)
{
if (this.datasets[datasetIndex].bars[barIndex].inRange(eventPosition.x, eventPosition.y))
{
for(var datasetIndex = 0; datasetIndex < this.datasets.length; datasetIndex++) {
for(barIndex = 0; barIndex < this.datasets[datasetIndex].bars.length; barIndex++) {
if(this.datasets[datasetIndex].bars[barIndex].inRange(eventPosition.x, eventPosition.y)) {
helpers.each(this.datasets, datasetIterator);
return barsArray;
}
......@@ -243,15 +216,12 @@
return barsArray;
},
buildScale: function(labels)
{
buildScale: function(labels) {
var self = this;
var dataTotal = function()
{
var dataTotal = function() {
var values = [];
self.eachBars(function(bar)
{
self.eachBars(function(bar) {
values.push(bar.value);
});
return values;
......@@ -269,8 +239,7 @@
valuesCount: labels.length,
beginAtZero: this.options.scaleBeginAtZero,
integersOnly: this.options.scaleIntegersOnly,
calculateYRange: function(currentHeight)
{
calculateYRange: function(currentHeight) {
var updatedRanges = helpers.calculateScaleRange(
dataTotal(),
currentHeight,
......@@ -286,9 +255,9 @@
lineColor: this.options.scaleLineColor,
showHorizontalLines: this.options.scaleShowHorizontalLines,
showVerticalLines: this.options.scaleShowVerticalLines,
/// ZUI change begin
/// ZUI change begin
showBeyondLine: this.options.scaleShowBeyondLine,
/// ZUI change end
/// ZUI change end
gridLineWidth: (this.options.scaleShowGridLines) ? this.options.scaleGridLineWidth : 0,
gridLineColor: (this.options.scaleShowGridLines) ? this.options.scaleGridLineColor : "rgba(0,0,0,0)",
padding: (this.options.showScale) ? 0 : (this.options.barShowStroke) ? this.options.barStrokeWidth : 0,
......@@ -296,10 +265,8 @@
display: this.options.showScale
};
if (this.options.scaleOverride)
{
helpers.extend(scaleOptions,
{
if(this.options.scaleOverride) {
helpers.extend(scaleOptions, {
calculateYRange: helpers.noop,
steps: this.options.scaleSteps,
stepValue: this.options.scaleStepWidth,
......@@ -310,14 +277,11 @@
this.scale = new this.ScaleClass(scaleOptions);
},
addData: function(valuesArray, label)
{
addData: function(valuesArray, label) {
//Map the values array for each of the datasets
helpers.each(valuesArray, function(value, datasetIndex)
{
helpers.each(valuesArray, function(value, datasetIndex) {
//Add a new point for each piece of data, passing any required data to draw.
this.datasets[datasetIndex].bars.push(new this.BarClass(
{
this.datasets[datasetIndex].bars.push(new this.BarClass({
value: value,
label: label,
x: this.scale.calculateBarX(this.datasets.length, datasetIndex, this.scale.valuesCount + 1),
......@@ -333,38 +297,31 @@
//Then re-render the chart.
this.update();
},
removeData: function()
{
removeData: function() {
this.scale.removeXLabel();
//Then re-render the chart.
helpers.each(this.datasets, function(dataset)
{
helpers.each(this.datasets, function(dataset) {
dataset.bars.shift();
}, this);
this.update();
},
reflow: function()
{
helpers.extend(this.BarClass.prototype,
{
reflow: function() {
helpers.extend(this.BarClass.prototype, {
y: this.scale.endPoint,
base: this.scale.endPoint
});
var newScaleProps = helpers.extend(
{
var newScaleProps = helpers.extend({
height: this.chart.height,
width: this.chart.width
});
this.scale.update(newScaleProps);
},
/// ZUI change begin
drawLabel: function(bar, placement)
{
/// ZUI change begin
drawLabel: function(bar, placement) {
var options = this.options;
placement = placement || options.scaleValuePlacement;
placement = placement ? placement.toLowerCase() : 'auto';
if(placement === 'auto')
{
if(placement === 'auto') {
placement = bar.y < 15 ? 'insdie' : 'outside';
}
......@@ -376,9 +333,8 @@
ctx.fillStyle = options.scaleFontColor;
ctx.fillText(bar.value, bar.x, y);
},
/// ZUI change end
draw: function(ease)
{
/// ZUI change end
draw: function(ease) {
var easingDecimal = ease || 1;
this.clear();
......@@ -386,31 +342,26 @@
this.scale.draw(easingDecimal);
/// ZUI change begin
/// ZUI change begin
var showScaleValue = this.options.scaleShowLabels && this.options.scaleValuePlacement;
/// ZUI change end
/// ZUI change end
//Draw all the bars for each dataset
helpers.each(this.datasets, function(dataset, datasetIndex)
{
helpers.each(dataset.bars, function(bar, index)
{
if (bar.hasValue())
{
helpers.each(this.datasets, function(dataset, datasetIndex) {
helpers.each(dataset.bars, function(bar, index) {
if(bar.hasValue()) {
bar.base = this.scale.endPoint;
//Transition then draw
bar.transition(
{
bar.transition({
x: this.scale.calculateBarX(this.datasets.length, datasetIndex, index),
y: this.scale.calculateY(bar.value),
width: this.scale.calculateBarWidth(this.datasets.length)
}, easingDecimal).draw();
}
/// ZUI change begin
if(showScaleValue)
{
/// ZUI change begin
if(showScaleValue) {
this.drawLabel(bar);
}
/// ZUI change end
/// ZUI change end
}, this);
}, this);
......@@ -419,11 +370,9 @@
/// ----- ZUI change begin -----
/// Use jquery object to create Chart object
$.fn.barChart = function(data, options)
{
$.fn.barChart = function(data, options) {
var barCharts = [];
this.each(function()
{
this.each(function() {
var $this = $(this);
barCharts.push(new Chart(this.getContext("2d")).Bar(data, $.extend($this.data(), options)));
});
......@@ -439,3 +388,4 @@
}).call(this, jQuery);
/// ----- ZUI change end -----
此差异已折叠。
......@@ -12,17 +12,17 @@
/// Add jquery object to namespace
/// (function(){ // Old code
(function($){
(function($) {
/// ----- ZUI change end -----
/// ----- ZUI change end -----
"use strict";
/// ----- ZUI change begin -----
/// Change root to zui shared object
///
/// var root = this, // old code
var root = $ && $.zui ? $.zui : this,
/// ----- ZUI change end -----
/// ----- ZUI change begin -----
/// Change root to zui shared object
///
/// var root = this, // old code
var root = $ && $.zui ? $.zui : this,
/// ----- ZUI change end -----
Chart = root.Chart,
//Cache a local reference to Chart.helpers
helpers = Chart.helpers;
......@@ -35,15 +35,15 @@
segmentStrokeColor: "#fff",
//Number - The width of each segment stroke
/// ZUI change begin
/// segmentStrokeWidth: 2, // old code
/// ZUI change begin
/// segmentStrokeWidth: 2, // old code
segmentStrokeWidth: 1,
/// ZUI change end
/// ZUI change end
//The percentage of the chart that we cut out of the middle.
percentageInnerCutout: 50,
/// ZUI change begin
/// ZUI change begin
// Boolean - Whether to show labels on the scale
scaleShowLabels: false,
......@@ -53,10 +53,10 @@
// String - Scale label position
scaleLabelPlacement: 'auto',
/// Number - Amount of animation steps // old code
/// animationSteps: 100, // old code
/// Number - Amount of animation steps // old code
/// animationSteps: 100, // old code
animationSteps: 60,
/// ZUI change end
/// ZUI change end
//String - Animation easing effect
animationEasing: "easeOutBounce",
......@@ -73,41 +73,34 @@
};
Chart.Type.extend(
{
Chart.Type.extend({
//Passing in a name registers this chart in the Chart namespace
name: "Doughnut",
//Providing a defaults will also register the deafults in the chart namespace
defaults: defaultConfig,
//Initialize is fired when the chart is initialized - Data is passed in as a parameter
//Config is automatically merged by the core of Chart.js, and is available at this.options
initialize: function(data)
{
initialize: function(data) {
//Declare segments as a static property to prevent inheriting across the Chart type prototype
this.segments = [];
this.outerRadius = (helpers.min([this.chart.width, this.chart.height]) - this.options.segmentStrokeWidth / 2) / 2;
this.SegmentArc = Chart.Arc.extend(
{
this.SegmentArc = Chart.Arc.extend({
ctx: this.chart.ctx,
x: this.chart.width / 2,
y: this.chart.height / 2
});
//Set up tooltip events on the chart
if (this.options.showTooltips)
{
helpers.bindEvents(this, this.options.tooltipEvents, function(evt)
{
if(this.options.showTooltips) {
helpers.bindEvents(this, this.options.tooltipEvents, function(evt) {
var activeSegments = (evt.type !== 'mouseout') ? this.getSegmentsAtEvent(evt) : [];
helpers.each(this.segments, function(segment)
{
helpers.each(this.segments, function(segment) {
segment.restore(["fillColor"]);
});
helpers.each(activeSegments, function(activeSegment)
{
helpers.each(activeSegments, function(activeSegment) {
activeSegment.fillColor = activeSegment.highlightColor;
});
this.showTooltip(activeSegments);
......@@ -115,40 +108,34 @@
}
this.calculateTotal(data);
helpers.each(data, function(datapoint, index)
{
helpers.each(data, function(datapoint, index) {
this.addData(datapoint, index, true);
}, this);
this.render();
},
getSegmentsAtEvent: function(e)
{
getSegmentsAtEvent: function(e) {
var segmentsArray = [];
var location = helpers.getRelativePosition(e);
helpers.each(this.segments, function(segment)
{
if (segment.inRange(location.x, location.y)) segmentsArray.push(segment);
helpers.each(this.segments, function(segment) {
if(segment.inRange(location.x, location.y)) segmentsArray.push(segment);
}, this);
return segmentsArray;
},
addData: function(segment, atIndex, silent)
{
/// ----- ZUI change begin -----
/// Init segment color
if($.zui && $.zui.Color && $.zui.Color.get)
{
addData: function(segment, atIndex, silent) {
/// ----- ZUI change begin -----
/// Init segment color
if($.zui && $.zui.Color && $.zui.Color.get) {
var color = new $.zui.Color.get(segment.color);
segment.color = color.toCssStr();
if(!segment.highlight) segment.highlight = color.lighten(5).toCssStr();
}
/// ----- ZUI change begin -----
/// ----- ZUI change begin -----
var index = atIndex || this.segments.length;
this.segments.splice(index, 0, new this.SegmentArc(
{
id: typeof segment.id === 'undefined' ? index : segment.id,
this.segments.splice(index, 0, new this.SegmentArc({
id: typeof segment.id === 'undefined' ? index : segment.id,
value: segment.value,
outerRadius: (this.options.animateScale) ? 0 : this.outerRadius,
innerRadius: (this.options.animateScale) ? 0 : (this.outerRadius / 100) * this.options.percentageInnerCutout,
......@@ -159,74 +146,61 @@
strokeColor: this.options.segmentStrokeColor,
startAngle: Math.PI * 1.5,
circumference: (this.options.animateRotate) ? 0 : this.calculateCircumference(segment.value),
/// ----- ZUI change begin -----
/// ----- ZUI change begin -----
showLabel: segment.showLabel !== false,
/// ----- ZUI change begin -----
/// ----- ZUI change begin -----
label: segment.label
}));
if (!silent)
{
if(!silent) {
this.reflow();
this.update();
}
},
calculateCircumference: function(value)
{
return (Math.PI * 2) * (Math.abs(value) / this.total);
calculateCircumference: function(value) {
return(Math.PI * 2) * (Math.abs(value) / this.total);
},
calculateTotal: function(data)
{
calculateTotal: function(data) {
this.total = 0;
helpers.each(data, function(segment)
{
helpers.each(data, function(segment) {
this.total += Math.abs(segment.value);
}, this);
},
update: function()
{
update: function() {
this.calculateTotal(this.segments);
// Reset any highlight colours before updating.
helpers.each(this.activeElements, function(activeElement)
{
helpers.each(this.activeElements, function(activeElement) {
activeElement.restore(['fillColor']);
});
helpers.each(this.segments, function(segment)
{
helpers.each(this.segments, function(segment) {
segment.save();
});
this.render();
},
removeData: function(atIndex)
{
removeData: function(atIndex) {
var indexToDelete = (helpers.isNumber(atIndex)) ? atIndex : this.segments.length - 1;
this.segments.splice(indexToDelete, 1);
this.reflow();
this.update();
},
reflow: function()
{
helpers.extend(this.SegmentArc.prototype,
{
reflow: function() {
helpers.extend(this.SegmentArc.prototype, {
x: this.chart.width / 2,
y: this.chart.height / 2
});
this.outerRadius = (helpers.min([this.chart.width, this.chart.height]) - this.options.segmentStrokeWidth / 2) / 2;
helpers.each(this.segments, function(segment)
{
segment.update(
{
helpers.each(this.segments, function(segment) {
segment.update({
outerRadius: this.outerRadius,
innerRadius: (this.outerRadius / 100) * this.options.percentageInnerCutout
});
}, this);
},
/// ZUI change begin
drawLabel: function(segment, easeDecimal, labelPosMap)
{
/// ZUI change begin
drawLabel: function(segment, easeDecimal, labelPosMap) {
var options = this.options;
var middleAngle = (segment.endAngle + segment.startAngle) / 2;
var placement = options.scaleLabelPlacement;
......@@ -240,7 +214,10 @@
var x = Math.cos(middleAngle) * segment.outerRadius,
y = Math.sin(middleAngle) * segment.outerRadius,
text = helpers.template(options.scaleLabel, {value: typeof easeDecimal === 'undefined' ? segment.value : Math.round(easeDecimal * segment.value), label: segment.label});
text = helpers.template(options.scaleLabel, {
value: typeof easeDecimal === 'undefined' ? segment.value : Math.round(easeDecimal * segment.value),
label: segment.label
});
var ctx = this.chart.ctx;
ctx.font = helpers.fontString(options.scaleFontSize, options.scaleFontStyle, options.scaleFontFamily);
......@@ -257,13 +234,12 @@
var lineY = y + chartHeightHalf;
ctx.textAlign = isRight ? 'left' : 'right';
ctx.measureText(text).width;
if(isRight)
{
if(isRight) {
x = Math.max(chartWidthHalf + segment.outerRadius + 10, x + 30 + chartWidthHalf);
} else {
x = Math.min(chartWidthHalf - segment.outerRadius - 10, x - 30 + chartWidthHalf);
}
var textHeight = options.scaleFontSize;
var labelPos = Math.round((y * 0.8 + chartHeightHalf) / textHeight) + 1;
var maxPos = Math.floor(this.chart.width / textHeight) + 1;
......@@ -293,18 +269,15 @@
ctx.fillText(text, x, y);
},
// ZUI change end
draw: function(easeDecimal)
{
// ZUI change end
draw: function(easeDecimal) {
var animDecimal = (easeDecimal) ? easeDecimal : 1;
this.clear();
// ZUI change begin
// ZUI change begin
var labelPositionMap;
// ZUI change end
helpers.each(this.segments, function(segment, index)
{
segment.transition(
{
// ZUI change end
helpers.each(this.segments, function(segment, index) {
segment.transition({
circumference: this.calculateCircumference(segment.value),
outerRadius: this.outerRadius,
innerRadius: (this.outerRadius / 100) * this.options.percentageInnerCutout
......@@ -313,64 +286,58 @@
segment.endAngle = segment.startAngle + segment.circumference;
segment.draw();
if (index === 0)
{
if(index === 0) {
segment.startAngle = Math.PI * 1.5;
}
//Check to see if it's the last segment, if not get the next and update the start angle
if (index < this.segments.length - 1)
{
if(index < this.segments.length - 1) {
this.segments[index + 1].startAngle = segment.endAngle;
}
/// ZUI change begin
if(this.options.scaleShowLabels && segment.showLabel)
{
/// ZUI change begin
if(this.options.scaleShowLabels && segment.showLabel) {
if(!labelPositionMap) labelPositionMap = {};
this.drawLabel(segment, easeDecimal, labelPositionMap);
}
/// ZUI change end
/// ZUI change end
}, this);
}
});
Chart.types.Doughnut.extend(
{
Chart.types.Doughnut.extend({
name: "Pie",
defaults: helpers.merge(defaultConfig,
{
defaults: helpers.merge(defaultConfig, {
percentageInnerCutout: 0
})
});
/// ----- ZUI change begin -----
/// Use jquery object to create Chart object
$.fn.pieChart = function(data, options)
{
/// ----- ZUI change begin -----
/// Use jquery object to create Chart object
$.fn.pieChart = function(data, options) {
var pieCharts = [];
this.each(function(){
this.each(function() {
var $this = $(this);
pieCharts.push(new Chart(this.getContext("2d")).Pie(data, $.extend($this.data(), options)));
});
return pieCharts.length === 1 ? pieCharts[0] : pieCharts;
}
$.fn.doughnutChart = function(data, options)
{
$.fn.doughnutChart = function(data, options) {
var doughnutCharts = [];
this.each(function(){
this.each(function() {
var $this = $(this);
doughnutCharts.push(new Chart(this.getContext("2d")).Doughnut(data, $.extend($this.data(), options)));
});
return doughnutCharts.length === 1 ? doughnutCharts[0] : doughnutCharts;
}
/// ----- ZUI change end -----
/// ----- ZUI change end -----
/// ----- ZUI change begin -----
/// Add jquery object to namespace
/// ----- ZUI change begin -----
/// Add jquery object to namespace
/// }).call(this); // Old code
/// }).call(this); // Old code
}).call(this, jQuery);
/// ----- ZUI change end -----
......@@ -18,7 +18,7 @@
* ======================================================================== */
+ function($){
+ function($) {
'use strict';
// ALERT CLASS DEFINITION
......@@ -27,39 +27,34 @@
var dismiss = '[data-dismiss="alert"]'
var zuiname = 'zui.alert';
var Alert = function(el)
{
var Alert = function(el) {
$(el).on('click', dismiss, this.close)
}
Alert.prototype.close = function(e)
{
Alert.prototype.close = function(e) {
var $this = $(this)
var selector = $this.attr('data-target')
if (!selector)
{
if(!selector) {
selector = $this.attr('href')
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
}
var $parent = $(selector)
if (e) e.preventDefault()
if(e) e.preventDefault()
if (!$parent.length)
{
if(!$parent.length) {
$parent = $this.hasClass('alert') ? $this : $this.parent()
}
$parent.trigger(e = $.Event('close.' + zuiname))
if (e.isDefaultPrevented()) return
if(e.isDefaultPrevented()) return
$parent.removeClass('in')
function removeElement()
{
function removeElement() {
$parent.trigger('closed.' + zuiname).remove()
}
......@@ -76,15 +71,13 @@
var old = $.fn.alert
$.fn.alert = function(option)
{
return this.each(function()
{
$.fn.alert = function(option) {
return this.each(function() {
var $this = $(this)
var data = $this.data(zuiname)
if (!data) $this.data(zuiname, (data = new Alert(this)))
if (typeof option == 'string') data[option].call($this)
if(!data) $this.data(zuiname, (data = new Alert(this)))
if(typeof option == 'string') data[option].call($this)
})
}
......@@ -94,8 +87,7 @@
// ALERT NO CONFLICT
// =================
$.fn.alert.noConflict = function()
{
$.fn.alert.noConflict = function() {
$.fn.alert = old
return this
}
......@@ -107,3 +99,4 @@
$(document).on('click.' + zuiname + '.data-api', dismiss, Alert.prototype.close)
}(window.jQuery);
/* ========================================================================
* ZUI: array.js
* ZUI: Array polyfills
* Array Polyfill.
* http://zui.sexy
* ========================================================================
* Copyright (c) 2014 cnezsoft.com; Licensed MIT
* ======================================================================== */
// Some polyfills copy from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
(function(){
(function() {
'use strict';
var STR_FUNCTION = 'function';
......@@ -15,19 +16,15 @@
/**
* Calls a function for each element in the array.
*/
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisp*/ )
{
if(!Array.prototype.forEach) {
Array.prototype.forEach = function(fun /*, thisp*/ ) {
var len = this.length;
if (typeof fun != STR_FUNCTION)
if(typeof fun != STR_FUNCTION)
throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
{
for(var i = 0; i < len; i++) {
if(i in this) {
fun.call(thisp, this[i], i, this);
}
}
......@@ -37,10 +34,8 @@
/**
* Judge an object is an real array
*/
if (!Array.isArray)
{
Array.isArray = function(obj)
{
if(!Array.isArray) {
Array.isArray = function(obj) {
return Object.toString.call(obj) === '[object Array]';
};
}
......@@ -48,29 +43,23 @@
/**
* Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.
*/
if (!Array.prototype.lastIndexOf)
{
Array.prototype.lastIndexOf = function(elt /*, from*/ )
{
if(!Array.prototype.lastIndexOf) {
Array.prototype.lastIndexOf = function(elt /*, from*/ ) {
var len = this.length;
var from = Number(arguments[1]);
if (isNaN(from))
{
if(isNaN(from)) {
from = len - 1;
}
else
{
} else {
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0)
if(from < 0)
from += len;
else if (from >= len)
else if(from >= len)
from = len - 1;
}
for (; from > -1; from--)
{
if (from in this &&
for(; from > -1; from--) {
if(from in this &&
this[from] === elt)
return from;
}
......@@ -81,18 +70,15 @@
/**
* Returns true if every element in this array satisfies the provided testing function.
*/
if (!Array.prototype.every)
{
Array.prototype.every = function(fun /*, thisp*/ )
{
if(!Array.prototype.every) {
Array.prototype.every = function(fun /*, thisp*/ ) {
var len = this.length;
if (typeof fun != STR_FUNCTION)
if(typeof fun != STR_FUNCTION)
throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this &&
for(var i = 0; i < len; i++) {
if(i in this &&
!fun.call(thisp, this[i], i, this))
return false;
}
......@@ -104,22 +90,18 @@
/**
* Creates a new array with all of the elements of this array for which the provided filtering function returns true.
*/
if (!Array.prototype.filter)
{
Array.prototype.filter = function(fun /*, thisp*/ )
{
if(!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp*/ ) {
var len = this.length;
if (typeof fun != STR_FUNCTION)
if(typeof fun != STR_FUNCTION)
throw new TypeError();
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
{
for(var i = 0; i < len; i++) {
if(i in this) {
var val = this[i]; // in case fun mutates this
if (fun.call(thisp, val, i, this))
if(fun.call(thisp, val, i, this))
res.push(val);
}
}
......@@ -131,20 +113,17 @@
/**
* Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.
*/
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/ )
{
if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(elt /*, from*/ ) {
var len = this.length;
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0)
if(from < 0)
from += len;
for (; from < len; from++)
{
if (from in this &&
for(; from < len; from++) {
if(from in this &&
this[from] === elt)
return from;
}
......@@ -155,19 +134,16 @@
/**
* Creates a new array with the results of calling a provided function on every element in this array.
*/
if (!Array.prototype.map)
{
Array.prototype.map = function(fun /*, thisp*/ )
{
if(!Array.prototype.map) {
Array.prototype.map = function(fun /*, thisp*/ ) {
var len = this.length;
if (typeof fun != STR_FUNCTION)
if(typeof fun != STR_FUNCTION)
throw new TypeError();
var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
for(var i = 0; i < len; i++) {
if(i in this)
res[i] = fun.call(thisp, this[i], i, this);
}
......@@ -181,30 +157,23 @@
* @param {array} result
* @return {array}
*/
if (!Array.prototype.mawherep)
{
Array.prototype.where = function(conditions, result)
{
if(!Array.prototype.mawherep) {
Array.prototype.where = function(conditions, result) {
result = result || [];
var cdt, ok, objVal;
this.forEach(function(val)
{
this.forEach(function(val) {
ok = true;
for (var key in conditions)
{
for(var key in conditions) {
cdt = conditions[key];
if (typeof cdt === STR_FUNCTION)
{
if(typeof cdt === STR_FUNCTION) {
ok = cdt(val);
}
else
{
} else {
objVal = val[key];
ok = (objVal && objVal === cdt);
}
if (!ok) break;
if(!ok) break;
}
if (ok) result.push(val);
if(ok) result.push(val);
});
return result;
......@@ -216,21 +185,16 @@
* @param {string} key
* @return {Object}
*/
if (!Array.prototype.groupBy)
{
Array.prototype.groupBy = function(key)
{
if(!Array.prototype.groupBy) {
Array.prototype.groupBy = function(key) {
var result = {};
this.forEach(function(val)
{
this.forEach(function(val) {
var keyName = val[key];
if (!keyName)
{
if(!keyName) {
keyName = 'unkown';
}
if (!result[keyName])
{
if(!result[keyName]) {
result[keyName] = [];
}
result[keyName].push(val);
......@@ -244,31 +208,23 @@
* @param {function or plain object} conditions
* @return {Boolean}
*/
if (!Array.prototype.has)
{
Array.prototype.has = function(conditions)
{
if(!Array.prototype.has) {
Array.prototype.has = function(conditions) {
var result = false,
cdt, ok, objVal;
this.forEach(function(val)
{
this.forEach(function(val) {
ok = true;
for (var key in conditions)
{
for(var key in conditions) {
cdt = conditions[key];
if (typeof cdt === STR_FUNCTION)
{
if(typeof cdt === STR_FUNCTION) {
ok = cdt(val);
}
else
{
} else {
objVal = val[key];
ok = (objVal && objVal === cdt);
}
if (!ok) break;
if(!ok) break;
}
if (ok)
{
if(ok) {
result = true;
return false;
}
......@@ -278,3 +234,4 @@
};
}
}());
......@@ -5,12 +5,12 @@
* Copyright (c) 2014 cnezsoft.com; Licensed MIT
* ======================================================================== */
// Deprecated: Use jquery way instead.
(function($){
(function($) {
'use strict';
var AutoTrigger = function(element, options)
{
var AutoTrigger = function(element, options) {
this.$ = $(element);
this.options = this.getOptions(options);
......@@ -31,57 +31,44 @@
//,after:
}; // default options
AutoTrigger.prototype.getOptions = function(options)
{
options = $.extend(
{}, AutoTrigger.DEFAULTS, this.$.data(), options);
AutoTrigger.prototype.getOptions = function(options) {
options = $.extend({}, AutoTrigger.DEFAULTS, this.$.data(), options);
return options;
};
AutoTrigger.prototype.init = function()
{
AutoTrigger.prototype.init = function() {
this.bindEvents();
};
AutoTrigger.prototype.bindEvents = function()
{
AutoTrigger.prototype.bindEvents = function() {
var options = this.options,
i;
this.bindTrigger(options);
if ($.isArray(options.triggers))
{
for (i in options.triggers)
{
this.bindTrigger($.extend(
{}, options, options.triggers[i]));
if($.isArray(options.triggers)) {
for(i in options.triggers) {
this.bindTrigger($.extend({}, options, options.triggers[i]));
}
}
else if (typeof options.triggers === 'string')
{
} else if(typeof options.triggers === 'string') {
/* events,trigger,target,data */
var triggers = options.triggers.split('|');
for (i in triggers)
{
for(i in triggers) {
var ops = triggers[i].split(',', 4);
if (ops.length < 2) continue;
if(ops.length < 2) continue;
var option = {};
if (ops[0]) option.events = ops[0];
if (ops[1]) option.trigger = ops[1];
if (ops[2]) option.target = ops[2];
if (ops[3]) option.data = ops[3];
if(ops[0]) option.events = ops[0];
if(ops[1]) option.trigger = ops[1];
if(ops[2]) option.target = ops[2];
if(ops[3]) option.data = ops[3];
this.bindTrigger($.extend(
{}, options, option));
this.bindTrigger($.extend({}, options, option));
}
}
};
AutoTrigger.prototype.bindTrigger = function(options)
{
AutoTrigger.prototype.bindTrigger = function(options) {
var that = this;
that.$.on(options.events, options.selector, function(event)
{
that.$.on(options.events, options.selector, function(event) {
var target = (!options.target) || options.target == 'self' ? that.$ : $(options.target);
var data = {
event: event,
......@@ -89,22 +76,17 @@
target: target,
options: options
};
if (!$.zui.callEvent(options.before, data, that)) return;
if(!$.zui.callEvent(options.before, data, that)) return;
if ($.isFunction(options.trigger))
{
if($.isFunction(options.trigger)) {
$.zui.callEvent(options.trigger, data, that);
}
else
{
} else {
var type = options.trigger;
if (type === 'toggle')
{
if(type === 'toggle') {
type = target.hasClass('hide') ? 'show' : 'hide';
}
var params;
switch (type)
{
switch(type) {
case 'toggle':
target.toggle();
break;
......@@ -115,16 +97,11 @@
};
target.removeClass('hide');
if (options.animate === 'slide')
{
if(options.animate === 'slide') {
target.slideDown(params);
}
else if (options.animate === 'fade')
{
} else if(options.animate === 'fade') {
target.fadeIn(params);
}
else
{
} else {
target.show(params);
}
break;
......@@ -132,21 +109,15 @@
params = {
duration: options.animateSpeed,
easing: options.easing,
complete: function()
{
complete: function() {
target.addClass('hide');
}
};
if (options.animate === 'slide')
{
if(options.animate === 'slide') {
target.slideUp(params);
}
else if (options.animate === 'fade')
{
} else if(options.animate === 'fade') {
target.fadeOut(params);
}
else
{
} else {
target.hide(params);
}
break;
......@@ -160,50 +131,43 @@
$.zui.callEvent(options.after, data, that);
if (options.preventDefault) event.preventDefault();
if (options.cancelBubble) event.stopPropagation();
if(options.preventDefault) event.preventDefault();
if(options.cancelBubble) event.stopPropagation();
});
};
$.fn.autoTrigger = function(option)
{
return this.each(function()
{
$.fn.autoTrigger = function(option) {
return this.each(function() {
var $this = $(this);
var data = $this.data('zui.autoTrigger');
var options = typeof option == 'object' && option;
if (!data) $this.data('zui.autoTrigger', (data = new AutoTrigger(this, options)));
if(!data) $this.data('zui.autoTrigger', (data = new AutoTrigger(this, options)));
if (typeof option == 'string') data[option]();
if(typeof option == 'string') data[option]();
});
};
$.fn.autoTrigger.Constructor = AutoTrigger;
$(function()
{
$(function() {
$('[data-toggle="autoTrigger"]').autoTrigger();
$('[data-toggle="toggle"]').autoTrigger();
$('[data-toggle="show"]').autoTrigger(
{
$('[data-toggle="show"]').autoTrigger({
trigger: 'show'
});
$('[data-toggle="hide"]').autoTrigger(
{
$('[data-toggle="hide"]').autoTrigger({
trigger: 'hide'
});
$('[data-toggle="addClass"]').autoTrigger(
{
$('[data-toggle="addClass"]').autoTrigger({
trigger: 'addClass'
});
$('[data-toggle="removeClass"]').autoTrigger(
{
$('[data-toggle="removeClass"]').autoTrigger({
trigger: 'removeClass'
});
$('[data-toggle="toggleClass"]').autoTrigger(
{
$('[data-toggle="toggleClass"]').autoTrigger({
trigger: 'toggleClass'
});
});
}(jQuery));
......@@ -6,13 +6,12 @@
* ======================================================================== */
(function($){
(function($) {
'use strict';
if (!$.fn.droppable) throw new Error('droppable requires for boards');
if(!$.fn.droppable) throw new Error('Droppable requires for boards');
var Boards = function(element, options)
{
var Boards = function(element, options) {
this.$ = $(element);
this.options = this.getOptions(options);
......@@ -22,41 +21,30 @@
Boards.DEFAULTS = {
lang: 'zh-cn',
langs:
{
'zh-cn':
{
langs: {
'zh-cn': {
append2end: '移动到末尾'
},
'zh-tw':
{
'zh-tw': {
append2end: '移动到末尾'
},
'en':
{
'en': {
append2end: 'Move to the end.'
}
}
}; // default options
Boards.prototype.getOptions = function(options)
{
options = $.extend(
{}, Boards.DEFAULTS, this.$.data(), options);
Boards.prototype.getOptions = function(options) {
options = $.extend({}, Boards.DEFAULTS, this.$.data(), options);
return options;
};
Boards.prototype.getLang = function()
{
Boards.prototype.getLang = function() {
var config = window.config;
if (!this.options.lang)
{
if (typeof(config) != 'undefined' && config.clientLang)
{
if(!this.options.lang) {
if(typeof(config) != 'undefined' && config.clientLang) {
this.options.lang = config.clientLang;
}
else
{
} else {
var hl = $('html').attr('lang');
this.options.lang = hl ? hl : 'en';
}
......@@ -65,24 +53,18 @@
this.lang = this.options.langs[this.options.lang] || this.options.langs[Boards.DEFAULTS.lang];
};
Boards.prototype.init = function()
{
Boards.prototype.init = function() {
var idSeed = 1;
var lang = this.lang;
this.$.find('.board-item:not(".disable-drop"), .board:not(".disable-drop")').each(function()
{
this.$.find('.board-item:not(".disable-drop"), .board:not(".disable-drop")').each(function() {
var $this = $(this);
if ($this.attr('id'))
{
if($this.attr('id')) {
$this.attr('data-id', $this.attr('id'));
}
else if (!$this.attr('data-id'))
{
} else if(!$this.attr('data-id')) {
$this.attr('data-id', 'board' + (idSeed++));
}
if ($this.hasClass('board'))
{
if($this.hasClass('board')) {
$this.find('.board-list').append('<div class="board-item board-item-empty"><i class="icon-plus"></i> {append2end}</div>'.format(lang))
.append('<div class="board-item board-item-shadow"></div>'.format(lang));
}
......@@ -91,29 +73,23 @@
this.bind();
};
Boards.prototype.bind = function(items)
{
Boards.prototype.bind = function(items) {
var $boards = this.$,
setting = this.options;
if (typeof(items) == 'undefined')
{
if(typeof(items) == 'undefined') {
items = $boards.find('.board-item:not(".disable-drop, .board-item-shadow")');
}
items.droppable(
{
items.droppable({
before: setting.before,
target: '.board-item:not(".disable-drop, .board-item-shadow")',
flex: true,
start: function(e)
{
start: function(e) {
$boards.addClass('dragging').find('.board-item-shadow').height(e.element.outerHeight());
},
drag: function(e)
{
drag: function(e) {
$boards.find('.board.drop-in-empty').removeClass('drop-in-empty');
if (e.isIn)
{
if(e.isIn) {
var board = e.target.closest('.board').addClass('drop-in');
var shadow = board.find('.board-item-shadow');
var target = e.target;
......@@ -125,44 +101,38 @@
board.toggleClass('drop-in-empty', target.hasClass('board-item-empty'));
}
},
drop: function(e)
{
if (e.isNew)
{
drop: function(e) {
if(e.isNew) {
var DROP = 'drop';
var result;
if (setting.hasOwnProperty(DROP) && $.isFunction(setting[DROP]))
{
if(setting.hasOwnProperty(DROP) && $.isFunction(setting[DROP])) {
result = setting[DROP](e);
}
if (result !== false) e.element.insertBefore(e.target);
if(result !== false) e.element.insertBefore(e.target);
}
},
finish: function()
{
finish: function() {
$boards.removeClass('dragging').removeClass('drop-in').find('.board.drop-in').removeClass('drop-in');
}
});
};
$.fn.boards = function(option)
{
return this.each(function()
{
$.fn.boards = function(option) {
return this.each(function() {
var $this = $(this);
var data = $this.data('zui.boards');
var options = typeof option == 'object' && option;
if (!data) $this.data('zui.boards', (data = new Boards(this, options)));
if(!data) $this.data('zui.boards', (data = new Boards(this, options)));
if (typeof option == 'string') data[option]();
if(typeof option == 'string') data[option]();
});
};
$.fn.boards.Constructor = Boards;
$(function()
{
$(function() {
$('[data-toggle="boards"]').boards();
});
}(jQuery));
此差异已折叠。
......@@ -6,8 +6,7 @@
* ======================================================================== */
(function($)
{
(function($) {
'use strict';
var browseHappyTip = {
......@@ -17,16 +16,12 @@
};
// The browser modal class
var Browser = function()
{
var Browser = function() {
var isIE = this.isIE;
var ie = isIE();
if (ie)
{
for (var i = 10; i > 5; i--)
{
if (isIE(i))
{
if(ie) {
for(var i = 10; i > 5; i--) {
if(isIE(i)) {
ie = i;
break;
}
......@@ -39,14 +34,12 @@
};
// Append CSS class to html tag
Browser.prototype.cssHelper = function()
{
Browser.prototype.cssHelper = function() {
var ie = this.ie,
$html = $('html');
$html.toggleClass('ie', ie)
.removeClass('ie-6 ie-7 ie-8 ie-9 ie-10');
if (ie)
{
if(ie) {
$html.addClass('ie-' + ie)
.toggleClass('gt-ie-7 gte-ie-8 support-ie', ie >= 8)
.toggleClass('lte-ie-7 lt-ie-8 outdated-ie', ie < 8)
......@@ -58,13 +51,10 @@
};
// Show browse happy tip
Browser.prototype.tip = function()
{
if (this.ie && this.ie < 8)
{
Browser.prototype.tip = function() {
if(this.ie && this.ie < 8) {
var $browseHappy = $('#browseHappyTip');
if (!$browseHappy.length)
{
if(!$browseHappy.length) {
$browseHappy = $('<div id="browseHappyTip" class="alert alert-dismissable alert-danger alert-block" style="position: relative; z-index: 99999"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><div class="container"><div class="content text-center"></div></div></div>');
$browseHappy.prependTo('body');
}
......@@ -74,8 +64,7 @@
};
// Detect it is IE, can given a version
Browser.prototype.isIE = function(version)
{
Browser.prototype.isIE = function(version) {
// var ie = /*@cc_on !@*/false;
var b = document.createElement('b');
b.innerHTML = '<!--[if IE ' + (version || '') + ']><i></i><![endif]-->';
......@@ -83,18 +72,18 @@
};
// Detect ie 10 with hack
Browser.prototype.isIE10 = function()
{
return ( /*@cc_on!@*/ false);
Browser.prototype.isIE10 = function() {
return( /*@cc_on!@*/ false);
};
$.zui({browser: new Browser()});
$.zui({
browser: new Browser()
});
$(function()
{
if (!$('body').hasClass('disabled-browser-tip'))
{
$(function() {
if(!$('body').hasClass('disabled-browser-tip')) {
$.zui.browser.tip();
}
});
}(jQuery));
......@@ -7,17 +7,15 @@
* ======================================================================== */
+ function($){
+ function($) {
'use strict';
// BUTTON PUBLIC CLASS DEFINITION
// ==============================
var Button = function(element, options)
{
var Button = function(element, options) {
this.$element = $(element)
this.options = $.extend(
{}, Button.DEFAULTS, options)
this.options = $.extend({}, Button.DEFAULTS, options)
this.isLoading = false
}
......@@ -25,8 +23,7 @@
loadingText: 'loading...'
}
Button.prototype.setState = function(state)
{
Button.prototype.setState = function(state) {
var d = 'disabled'
var $el = this.$element
var val = $el.is('input') ? 'val' : 'html'
......@@ -34,43 +31,36 @@
state = state + 'Text'
if (!data.resetText) $el.data('resetText', $el[val]())
if(!data.resetText) $el.data('resetText', $el[val]())
$el[val](data[state] || this.options[state])
// push to event loop to allow forms to submit
setTimeout($.proxy(function()
{
if (state == 'loadingText')
{
setTimeout($.proxy(function() {
if(state == 'loadingText') {
this.isLoading = true
$el.addClass(d).attr(d, d)
}
else if (this.isLoading)
{
} else if(this.isLoading) {
this.isLoading = false
$el.removeClass(d).removeAttr(d)
}
}, this), 0)
}
Button.prototype.toggle = function()
{
Button.prototype.toggle = function() {
var changed = true
var $parent = this.$element.closest('[data-toggle="buttons"]')
if ($parent.length)
{
if($parent.length) {
var $input = this.$element.find('input')
if ($input.prop('type') == 'radio')
{
if ($input.prop('checked') && this.$element.hasClass('active')) changed = false
if($input.prop('type') == 'radio') {
if($input.prop('checked') && this.$element.hasClass('active')) changed = false
else $parent.find('.active').removeClass('active')
}
if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change')
if(changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change')
}
if (changed) this.$element.toggleClass('active')
if(changed) this.$element.toggleClass('active')
}
......@@ -79,18 +69,16 @@
var old = $.fn.button
$.fn.button = function(option)
{
return this.each(function()
{
$.fn.button = function(option) {
return this.each(function() {
var $this = $(this)
var data = $this.data('zui.button')
var options = typeof option == 'object' && option
if (!data) $this.data('zui.button', (data = new Button(this, options)))
if(!data) $this.data('zui.button', (data = new Button(this, options)))
if (option == 'toggle') data.toggle()
else if (option) data.setState(option)
if(option == 'toggle') data.toggle()
else if(option) data.setState(option)
})
}
......@@ -100,8 +88,7 @@
// BUTTON NO CONFLICT
// ==================
$.fn.button.noConflict = function()
{
$.fn.button.noConflict = function() {
$.fn.button = old
return this
}
......@@ -110,12 +97,12 @@
// BUTTON DATA-API
// ===============
$(document).on('click.zui.button.data-api', '[data-toggle^=button]', function(e)
{
$(document).on('click.zui.button.data-api', '[data-toggle^=button]', function(e) {
var $btn = $(e.target)
if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
if(!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
$btn.button('toggle')
e.preventDefault()
})
}(jQuery);
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -6,12 +6,10 @@
* ======================================================================== */
+ function($)
{
+ function($) {
'use strict';
var ChosenIcons = function(element, options)
{
var ChosenIcons = function(element, options) {
this.$ = $(element);
this.options = this.getOptions(options);
this.lang = ChosenIcons.LANGS[this.options.lang];
......@@ -56,21 +54,17 @@
otherIcons: '其他圖標'
};
ChosenIcons.prototype.getOptions = function(options)
{
options = $.extend(
{}, ChosenIcons.DEFAULTS, this.$.data(), options);
ChosenIcons.prototype.getOptions = function(options) {
options = $.extend({}, ChosenIcons.DEFAULTS, this.$.data(), options);
return options;
};
ChosenIcons.prototype.init = function()
{
ChosenIcons.prototype.init = function() {
var $this = this.$.addClass('chosen-icons').addClass(this.id);
$this.empty();
if (this.options.canEmpty)
{
if(this.options.canEmpty) {
$this.append(this.getOptionHtml());
}
......@@ -82,8 +76,7 @@
$this.append(this.getgroupHtml('directionalIcons'));
$this.append(this.getgroupHtml('otherIcons'));
$this.chosen(
{
$this.chosen({
placeholder_text: ' ',
disable_search: true,
width: '100%',
......@@ -92,74 +85,63 @@
var chosenSelector = '.chosen-container.' + this.id;
$this.on('chosen:showing_dropdown', function()
{
$(chosenSelector + ' .chosen-results .group-option').each(function()
{
$this.on('chosen:showing_dropdown', function() {
$(chosenSelector + ' .chosen-results .group-option').each(function() {
var $this = $(this).addClass('icon');
var text = $(this).text();
$this.html('<i class="icon-' + text + '" title="' + text + '"></i>');
});
}).change(function()
{
}).change(function() {
var span = $(chosenSelector + ' .chosen-single > span');
var text = $(this).val();
if (text && text.length > 0)
if(text && text.length > 0)
span.html('<i class="' + text + '"></i> &nbsp; <span class="text-muted">' + text.substr(5).replace(/-/g, ' ') + '</span>');
else span.html('<span class="text-muted">' + lang.emptyIcon + '</span>')
});
var val = $this.data('value');
if (val)
{
if(val) {
$this.val(val).change();
}
}
ChosenIcons.prototype.getgroupHtml = function(name)
{
ChosenIcons.prototype.getgroupHtml = function(name) {
var icons = this.options[name];
var html = '<optgroup label="' + this.lang[name] + '">';
for (var i in icons)
{
for(var i in icons) {
html += this.getOptionHtml(icons[i]);
}
return html + '</optgroup>';
}
ChosenIcons.prototype.getOptionHtml = function(value)
{
ChosenIcons.prototype.getOptionHtml = function(value) {
var name = value;
if (value && value.length > 0)
{
if(value && value.length > 0) {
value = 'icon-' + value;
}
else
{
} else {
value = '';
name = this.lang.emptyIcon;
}
return '<option value="' + value + '">' + name + '</option>';
}
$.fn.chosenIcons = function(option)
{
return this.each(function()
{
$.fn.chosenIcons = function(option) {
return this.each(function() {
var $this = $(this);
var data = $this.data('zui.chosenIcons');
var options = typeof option == 'object' && option;
if (!data) $this.data('zui.chosenIcons', (data = new ChosenIcons(this, options)));
if(!data) $this.data('zui.chosenIcons', (data = new ChosenIcons(this, options)));
if (typeof option == 'string') data[option]();
if(typeof option == 'string') data[option]();
})
};
$.fn.chosenIcons.Constructor = ChosenIcons;
}(jQuery);
此差异已折叠。
此差异已折叠。
......@@ -8,14 +8,12 @@
/* This file generated by grunt automatically. Do not edit it. */
(function($)
{
(function($) {
'use strict';
var nextColorIndex = 0;
var presetColors = ['primary', 'red', 'yellow', 'green', 'blue', 'purple', 'brown', 'dark'];
var colorset =
{
var colorset = {
theme: 'light',
primary: '#3280fc',
secondary: '#145ccd',
......@@ -57,9 +55,8 @@
importantPale: '#f7ebe1',
specialPale: '#f5eeff'
};
colorset.get = function(colorName)
{
colorset.get = function(colorName) {
if(typeof colorName === 'undefined' || colorName === 'random') {
colorName = presetColors[(nextColorIndex++) % presetColors.length];
}
......@@ -67,6 +64,9 @@
return new $.zui.Color(colorset[colorName] ? colorset[colorName] : colorName);
}
$.zui({colorset: colorset});
$.zui({
colorset: colorset
});
if($.zui.Color) $.extend($.zui.Color, colorset);
}(jQuery));
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -425,7 +425,7 @@
if(this.component) {
offset = this.component.offset();
left = offset.left;
if(this.pickerPosition === 'bottom-left' || this.pickerPosition === 'top-left' || this.pickerPosition === 'auto-left') {
if(this.pickerPosition === 'bottom-left' || this.pickerPosition === 'top-left' || this.pickerPosition === 'auto-left') {
left += this.component.outerWidth() - this.picker.outerWidth();
}
} else {
......
......@@ -5,19 +5,17 @@
* Copyright (c) 2014 cnezsoft.com; Licensed MIT
* ======================================================================== */
(function($, window, document)
{
(function($, window, document) {
'use strict';
$(function()
{
$(function() {
$('body').append('<style>#zuiDebug{display:none; position: fixed;left: 2%;top: 30%;}#zuiDebug .icon{width: 180px;height: 180px;padding: 20px;border-radius: 100px;background-color: #333;color: #fff;transition:all 0.4s;}#zuiDebug .icon.visible-xs{background-color: #39B3D7;}#zuiDebug .icon.visible-sm{background-color: #47A447;}#zuiDebug .icon.visible-md{background-color: #ED9C28;}#zuiDebug .icon.visible-lg{background-color: #D2322D;}#zuiDebug .icon:hover{opacity: 0.01;}#zuiDebug .icon > i{display: block;font-size: 60px;}#zuiDebug .icon small{display: inline-block;height: 24px;opacity: 0.7;font-size: 12px;background-color: rgba(0,0,0,0.5);border-radius:12px; line-height: 24px;margin-top: 10px;padding: 0 10px;}</style><div id="zuiDebug"><div class="icon text-center visible-xs"><i class="icon-mobile-phone"></i><strong>Phone</strong><div class="text-center"><small>XS <span class="screen-size"></span></small></div></div><div class="icon text-center visible-sm"><i class="icon-tablet"></i><strong>Tablet</strong><div class="text-center"><small>SM <span class="screen-size"></span></small></div></div><div class="icon text-center visible-md"><i class="icon-desktop"></i><strong>Desktop</strong><div class="text-center"><small>MD <span class="screen-size"></span></small></div></div><div class="icon text-center visible-lg"><i class="icon-desktop"></i><strong>Widescreen</strong><div class="text-center"><small>LG <span class="screen-size"></span></small></div></div></div>');
displayScreenSize();
$('#zuiDebug').fadeIn();
$(window).resize(displayScreenSize);
function displayScreenSize()
{
function displayScreenSize() {
$('#zuiDebug .screen-size').text($(document).width() + ' x ' + $(document).height());
}
});
}(jQuery, window, document));
......@@ -6,8 +6,7 @@
* ======================================================================== */
(function(window, $)
{
(function(window, $) {
'use strict';
var desktopLg = 1200,
desktop = 992,
......@@ -23,8 +22,7 @@
var $window = $(window);
var resetCssClass = function()
{
var resetCssClass = function() {
var width = $window.width();
$('html').toggleClass(cssNames.desktop, width >= desktop && width < desktopLg)
.toggleClass(cssNames.desktopLg, width >= desktopLg)
......@@ -37,3 +35,4 @@
$window.resize(resetCssClass);
resetCssClass();
}(window, jQuery));
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -37,3 +37,4 @@
"img-cutter.js",
"auto-trigger.js"
]
......@@ -17,3 +17,4 @@
"tab.js",
"messager.js"
]
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册